public function parseEntries($xml) { $res = true; for ($i = 0; $i < count($xml->entry); ++$i) { $ent = $xml->entry[$i]; $entry = new EcEntry($this); $entry->deviceId = (string) $ent->ecPhoneID; $entry->created = (string) $ent->ecTimeCreated; $entry->project = $this->project; $entry->values = array(); foreach ($this->fields as $key => $fld) { if ($fld->type == 'gps' || $fld->type == 'location') { $lat = "{$key}_lat"; $lon = "{$key}_lon"; $alt = "{$key}_alt"; $acc = "{$key}_acc"; $src = "{$key}_provider"; $bearing = "{$key}_bearing"; $entry->values[$key] = array('latitude' => (string) $ent->{$lat}, 'longitude' => (string) $ent->{$lon}, 'altitude' => (string) $ent->{$alt}, 'accuracy' => (string) $ent->{$acc}, 'provider' => (string) $ent->{$src}, 'bearing' => (string) $ent->{$bearing}); } else { $entry->values[$key] = (string) $ent->{$key}; } } if (!preg_match('/^[0-9]+$/', $entry->created)) { $date = false; try { $date = new DateTime($entry->created, new DateTimeZone('UTC')); } catch (Exception $ex) { $date = new DateTime('now', new DateTimeZone('UTC')); } $entry->created = $date->getTimestamp(); } //TODO: need to check field names in the xml against fields in the form, and possibly //alert users to form version errors. $res = $entry->post(); if ($res !== true) { return $res; } } return $res; }
public function parseEntries($xml) { $res = true; for ($i = 0; $i < count($xml->entry); $i++) { $ent = $xml->entry[$i]; $entry = new EcEntry($this); $entry->deviceId = (string) $ent->ecPhoneID; $entry->created = (string) $ent->ecTimeCreated; //$entry->form = $this->id; $entry->project = $this->project; $entry->values = array(); foreach ($this->fields as $key => $fld) { //if($val->getName() != "ecPhoneID" && $val->getName() != "ecTimeCreated" && $this->fields[$val->getName()]->type != 'gps') // $entry->values[$val->getName()] = (string)$val; //elseif($this->fields[$val->getName()]->type != 'gps') //{} if ($fld->type == 'gps') { $lat = "{$key}_lat"; $lon = "{$key}_lon"; $alt = "{$key}_alt"; $acc = "{$key}_acc"; $src = "{$key}_provider"; $entry->values[$key] = array('latitude' => (string) $ent->{$lat}, 'longitude' => (string) $ent->{$lon}, 'altitude' => (string) $ent->{$alt}, 'accuracy' => (string) $ent->{$acc}, 'provider' => (string) $ent->{$src}); } else { $entry->values[$key] = (string) $ent->{$key}; } } //TODO: need to check field names in the xml against fields in the form, and possibly //alert users to form version errors. $res = $entry->post(); if ($res !== true) { return $res; } } return $res; }
function entryHandler() { global $auth, $url, $log, $SITE_ROOT; header("Cache-Control: no-cache, must-revalidate"); $prjEnd = strpos($url, "/"); $frmEnd = strpos($url, "/", $prjEnd + 1); $prjName = substr($url, 0, $prjEnd); $frmName = substr($url, $prjEnd + 1, $frmEnd - $prjEnd - 1); $entId = urldecode(substr($url, $frmEnd + 1)); $prj = new EcProject(); $prj->name = $prjName; $prj->fetch(); $permissionLevel = 0; $loggedIn = $auth->isLoggedIn(); if ($loggedIn) { $permissionLevel = $prj->checkPermission($auth->getEcUserId()); } $ent = new EcEntry($prj->tables[$frmName]); $ent->key = $entId; $r = $ent->fetch(); if ($_SERVER["REQUEST_METHOD"] == "DELETE") { if ($permissionLevel < 2) { flash('You do not have permission to delete entries on this project'); header('HTTP/1.1 403 Forbidden', 403); return; } if ($r === true) { try { $ent->delete(); } catch (Exception $e) { if (preg_match("/^Message\\s?:/", $e->getMessage())) { header("HTTP/1.1 409 Conflict", 409); } else { header("HTTP/1.1 500 Internal Server Error", 500); } echo $e->getMessage(); } } else { echo $r; } } else { if ($_SERVER["REQUEST_METHOD"] == "PUT") { if ($permissionLevel < 2) { flash('You do not have permission to edit entries on this project'); header('HTTP/1.1 403 Forbidden', 403); return; } if ($r === true) { $request_vars = array(); parse_str(file_get_contents("php://input"), $request_vars); foreach ($request_vars as $key => $value) { if (array_key_exists($key, $prj->tables[$frmName]->fields)) { $ent->values[$key] = $value; } } $r = $ent->put(); if ($r !== true) { echo "{ \"false\" : true, \"msg\" : \"{$r}\"}"; } else { echo "{ \"success\" : true, \"msg\" : \"\"}"; } } else { echo "{ \"success\" : false, \"msg\" : \"{$r}\""; } } else { if ($_SERVER["REQUEST_METHOD"] == "GET") { $val = getValIfExists($_GET, 'term'); $do = getValIfExists($_GET, 'validate'); $key_from = getValIfExists($_GET, 'key_from'); $secondary_field = getValIfExists($_GET, 'secondary_field'); $secondary_value = getValIfExists($_GET, 'secondary_value'); ini_set('max_execution_time', 60); if ($do) { echo json_encode($prj->tables[$frmName]->validateTitle($entId, $val)); } else { echo $prj->tables[$frmName]->autoComplete($entId, $val); } } } } }