/** * 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 delete_metadata($locationid, $metadataid) { $sp = explode("-", $metadataid); if (count($sp) != 2) { EgoLib::exit_invalid("invalid metadata id "); } $mlocid = $sp[0]; $mtype = $sp[1]; //locationid and metadatait should be the same if ($mlocid != $locationid) { EgoLib::exit_invalid("invalid location/metadata id {$mlocid} / {$locationid}"); } switch ($mtype) { case "imagelink": $this->update_single_field($locationid, "s", "imagelink", null); break; case "icon": $this->update_single_field($locationid, "s", "icontype", null); break; case "txt": $this->update_single_field($locationid, "s", "textmessage", null); break; } }