Web Interface For Lite Argus Control modules
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

110 lines
4.3 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
3 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. <?php
  2. require_once('../ajax_asm.php');
  3. function verbose( $ok=1,$info=""){
  4. // failure to upload throws 400 error
  5. if( $ok==0 ){
  6. http_response_code(400);
  7. };
  8. die(json_encode(["ok"=>$ok, "info"=>$info]));
  9. };
  10. if( $CUser->Data['id'] > 1 ){
  11. if( intval( $_POST['ctype'] ) == 1 ){
  12. $EURL = $DATABASE->escape($_POST['map_url']);
  13. $ENAME = $DATABASE->escape($_POST['map_name']);
  14. $EDESC = $DATABASE->escape($_POST['map_desc']);
  15. $EATTR = $DATABASE->escape($_POST['map_attr']);
  16. $IZOOM = intval( $_POST['map_maxz'] );
  17. $INZOOM = intval( $_POST['map_maxnz'] );
  18. $QS = "INSERT INTO `location_maps`(`type`,`name`,`layer_url`,`desc`,`maxNativeZoom`,`maxZoom`,`attribution`) values(1,'{$ENAME}','{$EURL}','{$EDESC}',{$INZOOM},{$IZOOM},'{$EATTR}')";
  19. $DATABASE->Query( $QS );
  20. } else {
  21. if( empty( $_FILES ) || $_FILES['map_image']['error'] ){
  22. verbose( 0, "Failed to move uploaded file.[" . $_FILES['map_image']['error'] . "]" );
  23. };
  24. // upload destination
  25. //$filePath = __DIR__ . DIRECTORY_SEPARATOR . "../../vault/working_dir/uploads";
  26. $filePath = $SYSPath . 'lib/controller/data/assets/images';
  27. if( !file_exists( $filePath ) ){
  28. if( !mkdir($filePath, 0777, true ) ){
  29. verbose( 0, "Failed to create $filePath" );
  30. };
  31. };
  32. if( file_exists( $_FILES['map_image']['tmp_name'] ) ){
  33. $MD5 = md5_file( $_FILES['map_image']['tmp_name'] );
  34. $TArr = explode( '.', $_FILES['map_image']['name'] );
  35. $EXT = $TArr[ count($TArr) - 1 ];
  36. $FNAME = $MD5 . '.' . $EXT;
  37. copy( $_FILES['map_image']['tmp_name'], $filePath . '/' . $FNAME );
  38. @unlink( $_FILES['map_image']['tmp_name'] );
  39. list( $width, $height, $type, $attr ) = getimagesize( $filePath . '/' . $FNAME );
  40. $ENAME = $DATABASE->escape($_POST['map_name']);
  41. $EDESC = $DATABASE->escape($_POST['map_desc']);
  42. $EATTR = $DATABASE->escape($_POST['map_attr']);
  43. $TB = intval( $_POST['map_tpb'] );
  44. $LB = intval( $_POST['map_lpb'] );
  45. $RB = intval( $_POST['map_rpb'] );
  46. $BB = intval( $_POST['map_bpb'] );
  47. $CSYS = 2 + intval( $_POST['map_corsys'] );
  48. if( $CSYS == 2 ){
  49. $INZOOM = intval( $_POST['map_maxnz'] );
  50. $IZOOM = intval( $_POST['map_maxz'] );
  51. $MA_WI = floatval( $_POST['map_width'] );
  52. $MA_HE = floatval( $_POST['map_height'] );
  53. $BM = intval( $_POST['bounds_mode'] );
  54. $K_X = $MA_WI / ( $width - $LB - $RB );
  55. $K_Y = $MA_HE / ( $height - $TB - $BB );
  56. if( $BM ){
  57. $THW = (($width + $RB + $LB) * $K_X ) / 2.0;
  58. $THH = (($height + $BB + $TB) * $K_Y ) / 2.0;
  59. $IBLX = -$THW;
  60. $IBLY = -$THH;
  61. $IBRX = $THW;
  62. $IBRY = $THH;
  63. } else {
  64. $IBLX = (-$LB)*$K_X;
  65. $IBLY = (-$TB)*$K_Y;
  66. $IBRX = ( $width + $RB ) * $K_X;
  67. $IBRY = ( $height + $BB ) * $K_Y;
  68. };
  69. } else {
  70. $BM = 0;
  71. $LTLAT = floatval( $_POST['map_lcclat'] );
  72. $LTLON = floatval( $_POST['map_lcclon'] );
  73. $RBLAT = floatval( $_POST['map_rcclat'] );
  74. $RBLON = floatval( $_POST['map_rcclon'] );
  75. if( $TB+$LB+$RB+$BB ){
  76. $KX = ( $RBLON - $LTLON )/( $width - $LB - $RB );
  77. $KY = ( $RBLAT - $LTLAT )/( $height - $TB - $BB );
  78. $LTLON = $LTLON - $KX * $LB;
  79. $LTLAT = $LTLAT + $KY * $TB;
  80. $RBLON = $RBLON + $KX * $RB;
  81. $RBLAT = $RBLAT - $KY * $BB;
  82. };
  83. $INZOOM = intval( $_POST['map_maxnz'] );
  84. $IZOOM = intval( $_POST['map_maxz'] );
  85. $IBLX = $LTLON;
  86. $IBLY = $LTLAT;
  87. $IBRX = $RBLON;
  88. $IBRY = $RBLAT;
  89. $MA_WI = $IBRX - $IBLX;
  90. $MA_HE = $IBLY - $IBRY;
  91. // zoom 180.0 --> 0
  92. $SANV = 360.0;
  93. for( $i = 0; $i< 32; $i++ ){
  94. $CANV = $SANV /(1<< $i);
  95. if( $CANV < $MA_WI ){
  96. $INZOOM = $i+5;
  97. $IZOOM = $INZOOM;
  98. break;
  99. };
  100. };
  101. };
  102. $QS = "INSERT INTO `location_maps`(`type`,`name`,`layer_url`,`desc`,`maxNativeZoom`,`maxZoom`,`attribution`,`bounds_lx`,`bounds_ly`,`bounds_rx`,`bounds_ry`,`bounds_mode`,`img_w`,`img_h`,`img_map_w`,`img_map_h`,`img_lb`,`img_tb`,`img_rb`,`img_bb`) values({$CSYS},'{$ENAME}','{$FNAME}','{$EDESC}',{$INZOOM},{$IZOOM},'{$EATTR}',{$IBLX},{$IBLY},{$IBRX},{$IBRY},{$BM},{$width},{$height},{$MA_WI},{$MA_HE},{$LB},{$TB},{$RB},{$BB})";
  103. $DATABASE->Query( $QS );
  104. verbose( 1, "ALL IS OK" );
  105. };
  106. };
  107. } else {
  108. verbose( 0, 'Access Denied!' );
  109. };
  110. ?>