getMethod()) { case "changeEpsg" : $epsgArray = $ajaxResponse->getParameter("srs"); $newSrs = $ajaxResponse->getParameter("newSrs"); for($i=0; $i < count($epsgArray); $i++){ // check if parameters are valid geometries to // avoid SQL injections $currentEpsg = $epsgArray[$i]; $oldEPSG = preg_replace("/EPSG:/","", $currentEpsg->epsg); $newEPSG = preg_replace("/EPSG:/","", $newSrs); $extArray = explode(",", $currentEpsg->extent); if (is_numeric($extArray[0]) && is_numeric($extArray[1]) && is_numeric($extArray[2]) && is_numeric($extArray[3]) && is_numeric($oldEPSG) && is_numeric($newEPSG)) { if(SYS_DBTYPE=='pgsql'){ $con = db_connect($DBSERVER,$OWNER,$PW); $sqlMinx = "SELECT X(transform(GeometryFromText('POINT(".$extArray[0]." ".$extArray[1].")',".$oldEPSG."),".$newEPSG.")) as minx"; $resMinx = db_query($sqlMinx); $minx = floatval(db_result($resMinx,0,"minx")); $sqlMiny = "SELECT Y(transform(GeometryFromText('POINT(".$extArray[0]." ".$extArray[1].")',".$oldEPSG."),".$newEPSG.")) as miny"; $resMiny = db_query($sqlMiny); $miny = floatval(db_result($resMiny,0,"miny")); $sqlMaxx = "SELECT X(transform(GeometryFromText('POINT(".$extArray[2]." ".$extArray[3].")',".$oldEPSG."),".$newEPSG.")) as maxx"; $resMaxx = db_query($sqlMaxx); $maxx = floatval(db_result($resMaxx,0,"maxx")); $sqlMaxy = "SELECT Y(transform(GeometryFromText('POINT(".$extArray[2]." ".$extArray[3].")',".$oldEPSG."),".$newEPSG.")) as maxy"; $resMaxy = db_query($sqlMaxy); $maxy = floatval(db_result($resMaxy,0,"maxy")); }else{ $con_string = "host=$GEOS_DBSERVER port=$GEOS_PORT dbname=$GEOS_DB user=$GEOS_OWNER password=$GEOS_PW"; $con = pg_connect($con_string) or die ("Error while connecting database"); /* * @security_patch sqli open */ $sqlMinx = "SELECT X(transform(GeometryFromText('POINT(".$extArray[0]." ".$extArray[1].")',".$oldEPSG."),".$newEPSG.")) as minx"; $resMinx = pg_query($con,$sqlMinx); $minx = floatval(pg_fetch_result($resMinx,0,"minx")); $sqlMiny = "SELECT Y(transform(GeometryFromText('POINT(".$extArray[0]." ".$extArray[1].")',".$oldEPSG."),".$newEPSG.")) as miny"; $resMiny = pg_query($con,$sqlMiny); $miny = floatval(pg_fetch_result($resMiny,0,"miny")); $sqlMaxx = "SELECT X(transform(GeometryFromText('POINT(".$extArray[2]." ".$extArray[3].")',".$oldEPSG."),".$newEPSG.")) as maxx"; $resMaxx = pg_query($con,$sqlMaxx); $maxx = floatval(pg_fetch_result($resMaxx,0,"maxx")); $sqlMaxy = "SELECT Y(transform(GeometryFromText('POINT(".$extArray[2]." ".$extArray[3].")',".$oldEPSG."),".$newEPSG.")) as maxy"; $resMaxy = pg_query($con,$sqlMaxy); $maxy = floatval(pg_fetch_result($resMaxy,0,"maxy")); } $extenty = $maxy - $miny; $extentx = $maxx - $minx; $relation_px_x = $currentEpsg->width / $currentEpsg->height; $relation_px_y = $currentEpsg->height / $currentEpsg->width; $relation_bbox_x = $extentx / $extenty; if($relation_bbox_x <= $relation_px_x){ $centerx = $minx + ($extentx/2); $minx = $centerx - $relation_px_x * $extenty / 2; $maxx = $centerx + $relation_px_x * $extenty / 2; } if($relation_bbox_x > $relation_px_x){ $centery = $miny + ($extenty/2); $miny = $centery - $relation_px_y * $extentx / 2; $maxy = $centery + $relation_px_y * $extentx / 2; } if ($currentEpsg->frameName) { $epsgObj[$i] = array( "frameName" => $currentEpsg->frameName, "newSrs" => $newSrs, "minx" => $minx, "miny" => $miny, "maxx" => $maxx, "maxy" => $maxy ); } else { $epsgObj[$i] = array( "wms" => $currentEpsg->wms, "newSrs" => $newSrs, "minx" => $minx, "miny" => $miny, "maxx" => $maxx, "maxy" => $maxy ); } } else { $ajaxResponse->setSuccess(false); $ajaxResponse->setMessage(_mb("An unknown error occured.")); $ajaxResponse->send(); } } $ajaxResponse->setSuccess(true); $ajaxResponse->setResult($epsgObj); break; default : $ajaxResponse->setSuccess(false); $ajaxResponse->setMessage(_mb("An unknown error occured.")); break; } $ajaxResponse->send(); ?>