/** * handle request and call callback */ function handle_request() { //get request if (empty($_REQUEST["cmd"])) { EgoLib::exit_invalid("missing command attribute"); } $cmd = strtolower($_REQUEST["cmd"]); //check if all arguments are syntactically ok EgoLib::check_arguments(); //extract locationinfo $locationinfo = EgoLib::extract_locationinfo(); //make sure we have a (dummy) callback if ($this->callback == null) { $this->callback = new EgoCallback(); } switch ($cmd) { case "addlocation": $required = array("installationid", "timestamp", "lat", "lng"); EgoLib::check_required($required); $serverid = $this->callback->add_location($locationinfo); if (empty($serverid)) { $serverid = "script_did_not_return_a_serverid"; } EgoLib::exit_ok($serverid); case "updatelocation": $required = array("installationid", "locationid"); EgoLib::check_required($required); $this->callback->update_location($locationinfo); if (empty($serverid)) { $serverid = ""; } EgoLib::exit_ok($serverid); case "deletelocation": $required = array("installationid", "locationid"); EgoLib::check_required($required); $this->callback->delete_location($locationinfo); EgoLib::exit_ok("deleted"); case "addmetadata": $required = array("installationid", "mdatatype", "locationid", "mdatacontent"); EgoLib::check_required($required); $serverid = $this->callback->add_metadata($locationinfo["locationid"], $_REQUEST["mdatatype"], $_REQUEST["mdatacontent"]); if (empty($serverid)) { $serverid = "script_did_not_return_a_serverid"; } EgoLib::exit_ok($serverid); case "deletemetadata": $required = array("installationid", "mdataid", "locationid"); EgoLib::check_required($required); $this->callback->delete_metadata($locationinfo["locationid"], $_REQUEST["mdataid"]); EgoLib::exit_ok("deleted"); case "uploadfile": $required = array("installationid"); EgoLib::check_required($required); if (!array_key_exists("uploadedfile", $_FILES)) { EgoLib::exit_invalid("missing uploadedfile"); } $filename = $_FILES["uploadedfile"]["tmp_name"]; $serverid = $this->callback->upload_file($filename); if (empty($serverid)) { $serverid = "script_did_not_return_a_serverid"; } EgoLib::exit_ok($serverid); default: EgoLib::exit_notsupported("unknown command {$cmd}"); } }
function add_metadata($locationid, $type, $content) { switch ($type) { case EgoLib::$METADATA_IMAGE: $this->update_single_field($locationid, "s", "imagelink", $content); return $locationid . "-imagelink"; case EgoLib::$METADATA_ICON: $this->update_single_field($locationid, "s", "icontype", $content); return $locationid . "-icon"; case EgoLib::$METADATA_TEXT: $this->update_single_field($locationid, "s", "textmessage", $content); return $locationid . "-txt"; default: EgoLib::exit_notsupported("unknown metadatatype: {$type}"); } }