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.
115 lines
4.5 KiB
115 lines
4.5 KiB
<?php
|
|
require_once('../ajax_asm.php');
|
|
|
|
function verbose( $ok=1,$info=""){
|
|
// failure to upload throws 400 error
|
|
if( $ok==0 ){
|
|
http_response_code(400);
|
|
};
|
|
die(json_encode(["ok"=>$ok, "info"=>$info]));
|
|
};
|
|
if( $CUser->Data['id'] > 1 ){
|
|
if( intval( $_POST['ctype'] ) == 1 ){
|
|
$EURL = $DATABASE->escape($_POST['map_url']);
|
|
$ENAME = $DATABASE->escape($_POST['map_name']);
|
|
$EDESC = $DATABASE->escape($_POST['map_desc']);
|
|
$EATTR = $DATABASE->escape($_POST['map_attr']);
|
|
$IZOOM = intval( $_POST['map_maxz'] );
|
|
$INZOOM = intval( $_POST['map_maxnz'] );
|
|
$QS = "INSERT INTO `location_maps`(`type`,`name`,`layer_url`,`desc`,`maxNativeZoom`,`maxZoom`,`attribution`) values(1,'{$ENAME}','{$EURL}','{$EDESC}',{$INZOOM},{$IZOOM},'{$EATTR}')";
|
|
$DATABASE->Query( $QS );
|
|
} else {
|
|
if( empty( $_FILES ) || $_FILES['map_image']['error'] ){
|
|
verbose( 0, "Failed to move uploaded file.[" . $_FILES['map_image']['error'] . "]" );
|
|
};
|
|
// upload destination
|
|
//$filePath = __DIR__ . DIRECTORY_SEPARATOR . "../../vault/working_dir/uploads";
|
|
$filePath = $SYSPath . 'lib/controller/data/assets/images';
|
|
if( !file_exists( $filePath ) ){
|
|
if( !mkdir($filePath, 0777, true ) ){
|
|
verbose( 0, "Failed to create $filePath" );
|
|
};
|
|
};
|
|
if( file_exists( $_FILES['map_image']['tmp_name'] ) ){
|
|
$MD5 = md5_file( $_FILES['map_image']['tmp_name'] );
|
|
$TArr = explode( '.', $_FILES['map_image']['name'] );
|
|
$EXT = $TArr[ count($TArr) - 1 ];
|
|
$FNAME = $MD5 . '.' . $EXT;
|
|
copy( $_FILES['map_image']['tmp_name'], $filePath . '/' . $FNAME );
|
|
@unlink( $_FILES['map_image']['tmp_name'] );
|
|
list( $width, $height, $type, $attr ) = getimagesize( $filePath . '/' . $FNAME );
|
|
if( $width > 1000 && $height > 1000 ){
|
|
$ENAME = $DATABASE->escape($_POST['map_name']);
|
|
$EDESC = $DATABASE->escape($_POST['map_desc']);
|
|
$EATTR = $DATABASE->escape($_POST['map_attr']);
|
|
$TB = intval( $_POST['map_tpb'] );
|
|
$LB = intval( $_POST['map_lpb'] );
|
|
$RB = intval( $_POST['map_rpb'] );
|
|
$BB = intval( $_POST['map_bpb'] );
|
|
$CSYS = 2 + intval( $_POST['map_corsys'] );
|
|
if( $CSYS == 2 ){
|
|
$INZOOM = intval( $_POST['map_maxnz'] );
|
|
$IZOOM = intval( $_POST['map_maxz'] );
|
|
$MA_WI = floatval( $_POST['map_width'] );
|
|
$MA_HE = floatval( $_POST['map_height'] );
|
|
$BM = intval( $_POST['bounds_mode'] );
|
|
$K_X = $MA_WI / ( $width - $LB - $RB );
|
|
$K_Y = $MA_HE / ( $height - $TB - $BB );
|
|
if( $BM ){
|
|
$THW = (($width + $RB + $LB) * $K_X ) / 2.0;
|
|
$THH = (($height + $BB + $TB) * $K_Y ) / 2.0;
|
|
$IBLX = -$THW;
|
|
$IBLY = -$THH;
|
|
$IBRX = $THW;
|
|
$IBRY = $THH;
|
|
} else {
|
|
$IBLX = (-$LB)*$K_X;
|
|
$IBLY = (-$TB)*$K_Y;
|
|
$IBRX = ( $width + $RB ) * $K_X;
|
|
$IBRY = ( $height + $BB ) * $K_Y;
|
|
};
|
|
} else {
|
|
$BM = 0;
|
|
$LTLAT = floatval( $_POST['map_lcclat'] );
|
|
$LTLON = floatval( $_POST['map_lcclon'] );
|
|
$RBLAT = floatval( $_POST['map_rcclat'] );
|
|
$RBLON = floatval( $_POST['map_rcclon'] );
|
|
if( $TB+$LB+$RB+$BB ){
|
|
$KX = ( $RBLON - $LTLON )/( $width - $LB - $RB );
|
|
$KY = ( $RBLAT - $LTLAT )/( $height - $TB - $BB );
|
|
$LTLON = $LTLON - $KX * $LB;
|
|
$LTLAT = $LTLAT + $KY * $TB;
|
|
$RBLON = $RBLON + $KX * $RB;
|
|
$RBLAT = $RBLAT - $KY * $BB;
|
|
};
|
|
$INZOOM = intval( $_POST['map_maxnz'] );
|
|
$IZOOM = intval( $_POST['map_maxz'] );
|
|
$IBLX = $LTLON;
|
|
$IBLY = $LTLAT;
|
|
$IBRX = $RBLON;
|
|
$IBRY = $RBLAT;
|
|
$MA_WI = $IBRX - $IBLX;
|
|
$MA_HE = $IBLY - $IBRY;
|
|
// zoom 180.0 --> 0
|
|
$SANV = 360.0;
|
|
for( $i = 0; $i< 32; $i++ ){
|
|
$CANV = $SANV /(1<< $i);
|
|
if( $CANV < $MA_WI ){
|
|
$INZOOM = $i+5;
|
|
$IZOOM = $INZOOM;
|
|
break;
|
|
};
|
|
};
|
|
};
|
|
$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})";
|
|
$DATABASE->Query( $QS );
|
|
verbose( 1, "ALL IS OK" );
|
|
} else {
|
|
verbose( 0, 'Image is too Small!' );
|
|
};
|
|
};
|
|
};
|
|
} else {
|
|
verbose( 0, 'Access Denied!' );
|
|
};
|
|
?>
|