Esempio n. 1
0
 public function Execute($db, $params)
 {
     if (isset($params["NameQuery"])) {
         log_message('debug', 'Searching by name - "' . $params["NameQuery"] . '"');
         $sql = "SELECT ID, Name, Address, Enabled, ExtraData,\n                    CONCAT('<', MinX, ',', MinY, ',', MinZ, '>') AS MinPosition,  \n                    CONCAT('<', MaxX, ',', MaxY, ',', MaxZ, '>') AS MaxPosition\n                    FROM Scenes WHERE Name LIKE :NameQuery";
         $nameQuery = '%' . $params["NameQuery"] . '%';
         if (isset($params["Enabled"]) && $params["Enabled"]) {
             log_message('debug', "Restricting to Enabled scenes");
             $sql .= " AND Enabled=1";
         }
         if (isset($params["MaxNumber"])) {
             log_message('debug', "Limiting to " . $params["MaxNumber"] . " scenes");
             $sql .= " LIMIT " . intval($params["MaxNumber"]);
         }
         log_message('debug', "SQL {$sql}");
         $sth = $db->prepare($sql);
         if ($sth->execute(array(':NameQuery' => $nameQuery))) {
             $this->HandleQueryResponse($sth);
         } else {
             log_message('error', sprintf("Error occurred during query: %d %s", $sth->errorCode(), print_r($sth->errorInfo(), true)));
             log_message('debug', sprintf("Query: %s", $sql));
             header("Content-Type: application/json", true);
             echo '{ "Message": "Database query error" }';
             exit;
         }
     } else {
         if (isset($params["MinPosition"]) && isset($params["MaxPosition"]) && Vector3::TryParse($params["MinPosition"], $this->MinPosition) && Vector3::TryParse($params["MaxPosition"], $this->MaxPosition)) {
             $sql = "SELECT ID, Name, Address, Enabled, ExtraData,\n                    CONCAT('<', MinX, ',', MinY, ',', MinZ, '>') AS MinPosition,\n                    CONCAT('<', MaxX, ',', MaxY, ',', MaxZ, '>') AS MaxPosition\n                    FROM Scenes WHERE MBRIntersects(GeomFromText(:XY), XYPlane)";
             log_message("debug", "Searching by position - " . $this->MinPosition . "-" . $this->MaxPosition);
             if (isset($params["Enabled"]) && $params["Enabled"]) {
                 log_message('debug', "Restricting to Enabled scenes");
                 $sql .= " AND Enabled=1";
             }
             if (isset($params["MaxNumber"])) {
                 log_message('debug', "Limiting to " . $params["MaxNumber"] . " scenes");
                 $sql .= " LIMIT " . intval($params["MaxNumber"]);
             }
             $sth = $db->prepare($sql);
             if ($sth->execute(array(':XY' => sprintf("POLYGON((%d %d, %d %d, %d %d, %d %d, %d %d))", $this->MinPosition->X, $this->MinPosition->Y, $this->MaxPosition->X, $this->MinPosition->Y, $this->MaxPosition->X, $this->MaxPosition->Y, $this->MinPosition->X, $this->MaxPosition->Y, $this->MinPosition->X, $this->MinPosition->Y)))) {
                 $this->HandleQueryResponse($sth);
             } else {
                 log_message('error', sprintf("Error occurred during query: %d %s", $sth->errorCode(), print_r($sth->errorInfo(), true)));
                 log_message('debug', sprintf("Query: %s", $sql));
                 header("Content-Type: application/json", true);
                 echo '{ "Message": "Database query error" }';
                 exit;
             }
         } else {
             header("Content-Type: application/json", true);
             echo '{ "Message": "Invalid parameters" }';
         }
     }
 }
function handle_vector_parameter($paramName, $params, &$sql, &$dbValues, &$addComma)
{
    $vector = null;
    if (isset($params[$paramName]) && Vector3::TryParse($params[$paramName], $vector)) {
        if ($addComma) {
            $sql .= ",";
        } else {
            $addComma = TRUE;
        }
        $sql .= " {$paramName}=:{$paramName}";
        $dbValues[$paramName] = (string) $vector;
    }
}
 public static function fromOSD($osd)
 {
     if (!isset($osd)) {
         return NULL;
     }
     if (!is_array($osd)) {
         $osd = json_decode($osd, true);
     }
     if (!isset($osd, $osd['SceneID'], $osd['Position'], $osd['LookAt'])) {
         return NULL;
     }
     $location = new SceneLocation();
     $location->SceneID = $osd['SceneID'];
     if (Vector3::TryParse($osd['Position'], $location->Position) && Vector3::TryParse($osd['LookAt'], $location->LookAt)) {
         return $location;
     }
     return null;
 }
 public function Execute($db, $params)
 {
     $this->Scene = new Scene();
     // Scene enabling
     if (!isset($params["SceneID"], $params["Name"], $params["MinPosition"], $params["MaxPosition"], $params["Address"], $params["Enabled"]) || !UUID::TryParse($params["SceneID"], $this->Scene->ID) || !Vector3::TryParse($params["MinPosition"], $this->Scene->MinPosition) || !Vector3::TryParse($params["MaxPosition"], $this->Scene->MaxPosition)) {
         // This clause should be removed at some point. It is superceded by the EnableScene
         // API and is only provided for backward compatibility with older OpenSim versions
         if (isset($params["SceneID"], $params["Enabled"]) && UUID::TryParse($params["SceneID"], $this->Scene->ID)) {
             // Scene enable/disable
             $sql = "UPDATE Scenes SET Enabled=:Enabled WHERE ID=:ID";
             $sth = $db->prepare($sql);
             if ($sth->execute(array(':ID' => $this->Scene->ID, ':Enabled' => $params["Enabled"]))) {
                 if ($sth->rowCount() > 0) {
                     header("Content-Type: application/json", true);
                     echo '{ "Success": true }';
                     exit;
                 } else {
                     log_message('error', "Failed updating the database (enabling)");
                     header("Content-Type: application/json", true);
                     echo '{ "Message": "Database update failed", "Success":false }';
                     exit;
                 }
             } else {
                 log_message('error', sprintf("Error occurred during query: %d %s", $sth->errorCode(), print_r($sth->errorInfo(), true)));
                 header("Content-Type: application/json", true);
                 echo '{ "Message": "Database query error", "Success":false }';
                 exit;
             }
         }
         // End of what needs to be removed
         log_message('error', sprintf("AddScene: Unable to parse passed parameters or parameter missing: '%s'", print_r($params, true)));
         header("Content-Type: application/json", true);
         echo '{ "Message": "Invalid parameters", "Success":false }';
         exit;
     }
     $this->Scene->Address = trim($params["Address"]);
     $this->Scene->Name = trim($params["Name"]);
     $this->Scene->Enabled = $params["Enabled"];
     if (isset($params["ExtraData"])) {
         $this->Scene->ExtraData = $params["ExtraData"];
     } else {
         $this->Scene->ExtraData = NULL;
     }
     $sql = "REPLACE INTO Scenes (ID, Name, MinX, MinY, MinZ, MaxX, MaxY, MaxZ, Address, Enabled, ExtraData, XYPlane) \n                    VALUES (:ID, :Name, :MinX, :MinY,  :MinZ, :MaxX, :MaxY, :MaxZ, :Address, :Enabled, :ExtraData, GeomFromText(:XY))";
     $sth = $db->prepare($sql);
     if ($sth->execute(array(':ID' => $this->Scene->ID, ':Name' => $this->Scene->Name, ':MinX' => $this->Scene->MinPosition->X, ':MinY' => $this->Scene->MinPosition->Y, ':MinZ' => $this->Scene->MinPosition->Z, ':MaxX' => $this->Scene->MaxPosition->X, ':MaxY' => $this->Scene->MaxPosition->Y, ':MaxZ' => $this->Scene->MaxPosition->Z, ':Address' => $this->Scene->Address, ':Enabled' => $this->Scene->Enabled, ':ExtraData' => $this->Scene->ExtraData, ':XY' => sprintf("POLYGON((%d %d, %d %d, %d %d, %d %d, %d %d))", $this->Scene->MinPosition->X, $this->Scene->MinPosition->Y, $this->Scene->MaxPosition->X, $this->Scene->MinPosition->Y, $this->Scene->MaxPosition->X, $this->Scene->MaxPosition->Y, $this->Scene->MinPosition->X, $this->Scene->MaxPosition->Y, $this->Scene->MinPosition->X, $this->Scene->MinPosition->Y)))) {
         if ($sth->rowCount() > 0) {
             header("Content-Type: application/json", true);
             echo '{ "Success": true }';
             exit;
         } else {
             log_message('error', "Failed updating the database (replace)");
             header("Content-Type: application/json", true);
             echo '{ "Message": "Database update failed", "Success":false }';
             exit;
         }
     } else {
         log_message('error', sprintf("Error occurred during query: %d %s", $sth->errorCode(), print_r($sth->errorInfo(), true)));
         log_message('debug', sprintf("Query: %s", $sql));
         header("Content-Type: application/json", true);
         echo '{ "Message": "Database query error", "Success":false }';
         exit;
     }
 }
 public function Execute($db, $params)
 {
     $sql = "";
     if (isset($params["SceneID"]) && UUID::TryParse($params["SceneID"], $this->SceneID)) {
         log_message('debug', "GetScene by SceneID " . $params["SceneID"]);
         $sql = "SELECT ID, Name, Address, Enabled, ExtraData, LastUpdate,\n                    CONCAT('<', MinX, ',', MinY, ',', MinZ, '>') AS MinPosition,  \n                    CONCAT('<', MaxX, ',', MaxY, ',', MaxZ, '>') AS MaxPosition\n                    FROM Scenes WHERE ID='" . $this->SceneID . "'";
         if (isset($params["Enabled"]) && $params["Enabled"]) {
             $sql .= " AND Enabled=1";
         }
     } else {
         if (isset($params["Name"])) {
             log_message('debug', "GetScene by Name " . $params["Name"]);
             $sql = "SELECT ID, Name, Address, Enabled, ExtraData, LastUpdate,\n                    CONCAT('<', MinX, ',', MinY, ',', MinZ, '>') AS MinPosition,  \n                    CONCAT('<', MaxX, ',', MaxY, ',', MaxZ, '>') AS MaxPosition\n                    FROM Scenes WHERE Name='" . $params["Name"] . "'";
             if (isset($params["Enabled"]) && $params["Enabled"]) {
                 $sql .= " AND Enabled=1";
             }
         } else {
             if (isset($params["Position"]) && Vector3::TryParse($params["Position"], $this->Position)) {
                 if (isset($params["FindClosest"]) && $params["FindClosest"]) {
                     log_message('debug', "GetScene (closest) by position " . $this->Position);
                     $sql = "SELECT ID, Name, Address, Enabled, ExtraData, LastUpdate,\n                        CONCAT('<', MinX, ',', MinY, ',', MinZ, '>') AS MinPosition,  \n                        CONCAT('<', MaxX, ',', MaxY, ',', MaxZ, '>') AS MaxPosition,\n                        GLength(LineString(GeomFromText('POINT(" . $this->Position->X . " " . $this->Position->Y . ")'), Centroid(XYPlane)))\n                        AS dist FROM Scenes";
                     $sql .= " WHERE ExtraData NOT REGEXP :RegExp";
                     if (isset($params["Enabled"]) && $params["Enabled"]) {
                         $sql .= " AND Enabled=1";
                     }
                     $sql .= " ORDER BY dist LIMIT 1";
                 } else {
                     log_message('debug', "GetScene by position " . $this->Position);
                     $sql = "SELECT ID, Name, Address, Enabled, ExtraData, LastUpdate,\n                        CONCAT('<', MinX, ',', MinY, ',', MinZ, '>') AS MinPosition,  \n                        CONCAT('<', MaxX, ',', MaxY, ',', MaxZ, '>') AS MaxPosition\n                        FROM Scenes WHERE MBRContains(XYPlane, GeomFromText('POINT(" . $this->Position->X . " " . $this->Position->Y . ")'))";
                     if (isset($params["Enabled"]) && $params["Enabled"]) {
                         $sql .= " AND Enabled=1";
                     }
                     $sql .= " LIMIT 1";
                 }
             } else {
                 header("Content-Type: application/json", true);
                 echo '{ "Message": "Invalid parameters" }';
                 exit;
             }
         }
     }
     log_message('debug', "what {$sql}");
     $sth = $db->prepare($sql);
     if (isset($params["FindClosest"]) && $params["FindClosest"]) {
         $sth->bindValue(':RegExp', '.+\\"HyperGrid\\":true.+');
     }
     if ($sth->execute()) {
         if ($sth->rowCount() > 0) {
             $obj = $sth->fetchObject();
             $scene = new Scene();
             $scene->SceneID = $obj->ID;
             $scene->Name = $obj->Name;
             $scene->Enabled = $obj->Enabled;
             $scene->MinPosition = Vector3::Parse($obj->MinPosition);
             $scene->MaxPosition = Vector3::Parse($obj->MaxPosition);
             $scene->Address = $obj->Address;
             $scene->LastUpdate = $obj->LastUpdate;
             if (!is_null($obj->ExtraData)) {
                 $scene->ExtraData = $obj->ExtraData;
             } else {
                 $scene->ExtraData = "{}";
             }
             $out = $scene->toOSD();
             $out = substr($out, 0, -1);
             $out .= ',"Success":true}';
             log_message('debug', "Found scene " . $scene->Name);
             header("Content-Type: application/json", true);
             echo $out;
             exit;
         } else {
             header("Content-Type: application/json", true);
             echo '{ "Message": "No matching scene found" }';
             exit;
         }
     } else {
         log_message('error', sprintf("Error occurred during query: %d %s", $sth->errorCode(), print_r($sth->errorInfo(), true)));
         log_message('debug', sprintf("Query: %s", $sql));
         header("Content-Type: application/json", true);
         echo '{ "Message": "Database query error" }';
         exit;
     }
 }
Esempio n. 6
0
 public function Execute($db, $params)
 {
     $this->Scene = new Scene();
     if (isset($params["SceneID"], $params["Enabled"]) && !$params["Enabled"] && UUID::TryParse($params["SceneID"], $this->Scene->ID)) {
         // Scene disabling
         $sql = "UPDATE Scenes SET Enabled=0 WHERE ID=:ID";
         $sth = $db->prepare($sql);
         if ($sth->execute(array(':ID' => $this->Scene->ID))) {
             if ($sth->rowCount() > 0) {
                 header("Content-Type: application/json", true);
                 echo '{ "Success": true }';
                 exit;
             } else {
                 log_message('error', "Failed updating the database");
                 header("Content-Type: application/json", true);
                 echo '{ "Message": "Database update failed" }';
                 exit;
             }
         } else {
             log_message('error', sprintf("Error occurred during query: %d %s", $sth->errorCode(), print_r($sth->errorInfo(), true)));
             header("Content-Type: application/json", true);
             echo '{ "Message": "Database query error" }';
             exit;
         }
     } else {
         // Scene enabling
         if (!isset($params["SceneID"], $params["Name"], $params["MinPosition"], $params["MaxPosition"], $params["Address"], $params["Enabled"]) || !UUID::TryParse($params["SceneID"], $this->Scene->ID) || !Vector3::TryParse($params["MinPosition"], $this->Scene->MinPosition) || !Vector3::TryParse($params["MaxPosition"], $this->Scene->MaxPosition)) {
             log_message('error', sprintf("AddScene: Unable to parse passed parameters or parameter missing: '%s'", print_r($params, true)));
             header("Content-Type: application/json", true);
             echo '{ "Message": "Invalid parameters" }';
             exit;
         }
         $this->Scene->Address = trim($params["Address"]);
         $this->Scene->Name = trim($params["Name"]);
         $this->Scene->Enabled = $params["Enabled"];
         if (isset($params["ExtraData"])) {
             $this->Scene->ExtraData = $params["ExtraData"];
         } else {
             $this->Scene->ExtraData = NULL;
         }
         $sql = "REPLACE INTO Scenes (ID, Name, MinX, MinY, MinZ, MaxX, MaxY, MaxZ, Address, Enabled, ExtraData, XYPlane) \n                    VALUES (:ID, :Name, :MinX, :MinY,  :MinZ, :MaxX, :MaxY, :MaxZ, :Address, :Enabled, :ExtraData, GeomFromText(:XY))";
         $sth = $db->prepare($sql);
         if ($sth->execute(array(':ID' => $this->Scene->ID, ':Name' => $this->Scene->Name, ':MinX' => $this->Scene->MinPosition->X, ':MinY' => $this->Scene->MinPosition->Y, ':MinZ' => $this->Scene->MinPosition->Z, ':MaxX' => $this->Scene->MaxPosition->X, ':MaxY' => $this->Scene->MaxPosition->Y, ':MaxZ' => $this->Scene->MaxPosition->Z, ':Address' => $this->Scene->Address, ':Enabled' => $this->Scene->Enabled, ':ExtraData' => $this->Scene->ExtraData, ':XY' => sprintf("POLYGON((%d %d, %d %d, %d %d, %d %d, %d %d))", $this->Scene->MinPosition->X, $this->Scene->MinPosition->Y, $this->Scene->MaxPosition->X, $this->Scene->MinPosition->Y, $this->Scene->MaxPosition->X, $this->Scene->MaxPosition->Y, $this->Scene->MinPosition->X, $this->Scene->MaxPosition->Y, $this->Scene->MinPosition->X, $this->Scene->MinPosition->Y)))) {
             if ($sth->rowCount() > 0) {
                 header("Content-Type: application/json", true);
                 echo '{ "Success": true }';
                 exit;
             } else {
                 log_message('error', "Failed updating the database");
                 header("Content-Type: application/json", true);
                 echo '{ "Message": "Database update failed" }';
                 exit;
             }
         } else {
             log_message('error', sprintf("Error occurred during query: %d %s", $sth->errorCode(), print_r($sth->errorInfo(), true)));
             header("Content-Type: application/json", true);
             echo '{ "Message": "Database query error" }';
             exit;
         }
     }
 }