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.

114 lines
4.5 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
3 years ago
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 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. if( $width > 1000 && $height > 1000 ){
  41. $ENAME = $DATABASE->escape($_POST['map_name']);
  42. $EDESC = $DATABASE->escape($_POST['map_desc']);
  43. $EATTR = $DATABASE->escape($_POST['map_attr']);
  44. $TB = intval( $_POST['map_tpb'] );
  45. $LB = intval( $_POST['map_lpb'] );
  46. $RB = intval( $_POST['map_rpb'] );
  47. $BB = intval( $_POST['map_bpb'] );
  48. $CSYS = 2 + intval( $_POST['map_corsys'] );
  49. if( $CSYS == 2 ){
  50. $INZOOM = intval( $_POST['map_maxnz'] );
  51. $IZOOM = intval( $_POST['map_maxz'] );
  52. $MA_WI = floatval( $_POST['map_width'] );
  53. $MA_HE = floatval( $_POST['map_height'] );
  54. $BM = intval( $_POST['bounds_mode'] );
  55. $K_X = $MA_WI / ( $width - $LB - $RB );
  56. $K_Y = $MA_HE / ( $height - $TB - $BB );
  57. if( $BM ){
  58. $THW = (($width + $RB + $LB) * $K_X ) / 2.0;
  59. $THH = (($height + $BB + $TB) * $K_Y ) / 2.0;
  60. $IBLX = -$THW;
  61. $IBLY = -$THH;
  62. $IBRX = $THW;
  63. $IBRY = $THH;
  64. } else {
  65. $IBLX = (-$LB)*$K_X;
  66. $IBLY = (-$TB)*$K_Y;
  67. $IBRX = ( $width + $RB ) * $K_X;
  68. $IBRY = ( $height + $BB ) * $K_Y;
  69. };
  70. } else {
  71. $BM = 0;
  72. $LTLAT = floatval( $_POST['map_lcclat'] );
  73. $LTLON = floatval( $_POST['map_lcclon'] );
  74. $RBLAT = floatval( $_POST['map_rcclat'] );
  75. $RBLON = floatval( $_POST['map_rcclon'] );
  76. if( $TB+$LB+$RB+$BB ){
  77. $KX = ( $RBLON - $LTLON )/( $width - $LB - $RB );
  78. $KY = ( $RBLAT - $LTLAT )/( $height - $TB - $BB );
  79. $LTLON = $LTLON - $KX * $LB;
  80. $LTLAT = $LTLAT + $KY * $TB;
  81. $RBLON = $RBLON + $KX * $RB;
  82. $RBLAT = $RBLAT - $KY * $BB;
  83. };
  84. $INZOOM = intval( $_POST['map_maxnz'] );
  85. $IZOOM = intval( $_POST['map_maxz'] );
  86. $IBLX = $LTLON;
  87. $IBLY = $LTLAT;
  88. $IBRX = $RBLON;
  89. $IBRY = $RBLAT;
  90. $MA_WI = $IBRX - $IBLX;
  91. $MA_HE = $IBLY - $IBRY;
  92. // zoom 180.0 --> 0
  93. $SANV = 360.0;
  94. for( $i = 0; $i< 32; $i++ ){
  95. $CANV = $SANV /(1<< $i);
  96. if( $CANV < $MA_WI ){
  97. $INZOOM = $i+5;
  98. $IZOOM = $INZOOM;
  99. break;
  100. };
  101. };
  102. };
  103. $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})";
  104. $DATABASE->Query( $QS );
  105. verbose( 1, "ALL IS OK" );
  106. } else {
  107. verbose( 0, 'Image is too Small!' );
  108. };
  109. };
  110. };
  111. } else {
  112. verbose( 0, 'Access Denied!' );
  113. };
  114. ?>