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.

75 lines
3.2 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
3 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
3 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
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. $IZOOM = intval( $_POST['map_maxz'] );
  44. $INZOOM = intval( $_POST['map_maxz'] );
  45. $MA_WI = floatval( $_POST['map_width'] );
  46. $MA_HE = floatval( $_POST['map_height'] );
  47. $TB = intval( $_POST['map_tpb'] );
  48. $LB = intval( $_POST['map_lpb'] );
  49. $RB = intval( $_POST['map_rpb'] );
  50. $BB = intval( $_POST['map_bpb'] );
  51. $BM = intval( $_POST['bounds_mode'] );
  52. $K_X = $MA_WI / ( $width - $LB - $RB );
  53. $K_Y = $MA_HE / ( $height - $TB - $BB );
  54. if( $BM ){
  55. $THW = (($width + $RB + $LB) * $K_X ) / 2.0;
  56. $THH = (($height + $BB + $TB) * $K_Y ) / 2.0;
  57. $IBLX = -$THW;
  58. $IBLY = -$THH;
  59. $IBRX = $THW;
  60. $IBRY = $THH;
  61. } else {
  62. $IBLX = (-$LB)*$K_X;
  63. $IBLY = (-$TB)*$K_Y;
  64. $IBRX = ( $width + $RB ) * $K_X;
  65. $IBRY = ( $height + $BB ) * $K_Y;
  66. };
  67. $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(2,'{$ENAME}','{$FNAME}','{$EDESC}',{$INZOOM},{$IZOOM},'{$EATTR}',{$IBLX},{$IBLY},{$IBRX},{$IBRY},{$BM},{$width},{$height},{$MA_WI},{$MA_HE},{$LB},{$TB},{$RB},{$BB})";
  68. $DATABASE->Query( $QS );
  69. verbose( 1, "ALL IS OK" );
  70. };
  71. };
  72. } else {
  73. verbose( 0, 'Access Denied!' );
  74. };
  75. ?>