コード例 #1
0
 public function test_get_val()
 {
     $arr = array();
     $this->isNull(getValIfExists($arr, 'foo'));
     $arr["foo"] = "bar";
     $this->assertEquals(getValIfExists($arr, 'foo'), 'bar');
 }
コード例 #2
0
 public function toXML()
 {
     global $SITE_ROOT, $XML_VERSION;
     $protocol = 'http';
     if (getValIfExists($_SERVER, "HTTPS") == 'on') {
         $protocol = 'https';
     }
     $xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n\n<ecml version=\"{$XML_VERSION}\">\n\t<model>\n\t\t<submission id=\"{$this->submission_id}\" projectName=\"{$this->name}\" allowDownloadEdits=\"" . ($this->allowDownloadEdits ? "true" : "false") . "\" versionNumber=\"{$this->ecVersionNumber}\" />\n\t\t<uploadToServer>{$protocol}://{$_SERVER["HTTP_HOST"]}{$SITE_ROOT}/{$this->name}/upload</uploadToServer>\n\t\t<downloadFromServer>{$protocol}://{$_SERVER["HTTP_HOST"]}{$SITE_ROOT}/{$this->name}/download</downloadFromServer>";
     if ($this->uploadToLocalServer) {
         $xml .= "\n\t\t<uploadToLocalServer>{$this->uploadToLocalServer}</uploadToLocalServer>";
     }
     if ($this->downloadFromLocalServer) {
         $xml .= "\n\t\t<downloadFromLocalServer>{$this->downloadFromLocalServer}</downloadFromLocalServer>";
     }
     $xml .= "\n\t</model>\n";
     foreach ($this->tables as $tbl) {
         $xml .= $tbl->toXML();
     }
     $xml .= "\n</ecml>";
     return $xml;
 }
コード例 #3
0
 public function parseEntriesCSV($fp)
 {
     //$lines = explode("\r\n", $txt);
     // assumes that the first line is the header
     //$lines[0] = trim($lines[0], ',');
     try {
         $headers = fgetcsv($fp);
         //$this->parseCSVLine($lines[0]);
     } catch (Exception $err) {
         throw new Exception(str_replace('xx', '0', $err->getMessage()));
     }
     $vals = array();
     $ents = array();
     $fields = array_keys($this->fields);
     $x = 0;
     while ($vals = fgetcsv($fp)) {
         $entry = new EcEntry($this);
         $vars = array_keys(get_object_vars($entry));
         $varLen = count($vars);
         $ent = array_combine($headers, $vals);
         for ($v = 0; $v < $varLen; ++$v) {
             if (array_key_exists($vars[$v], $ent)) {
                 $entry->{$vars}[$v] = $ent[$vars[$v]];
             }
         }
         $ttl = count($fields);
         for ($f = 0; $f < $ttl; ++$f) {
             if ($this->fields[$fields[$f]]->type == 'location' || $this->fields[$fields[$f]]->type == 'gps') {
                 $lat = sprintf('%s_lattitude', $fields[$f]);
                 $lon = sprintf('%s_longitude', $fields[$f]);
                 $alt = sprintf('%s_alttitude', $fields[$f]);
                 $acc = sprintf('%s_accuarcy', $fields[$f]);
                 $src = sprintf('%s_provider', $fields[$f]);
                 $bearing = sprintf('%s_bearing', $fields[$f]);
                 $entry->values[$fields[$f]] = array('latitude' => getValIfExists($ent, $lat), 'longitude' => getValIfExists($ent, $lon), 'altitude' => getValIfExists($ent, $alt), 'accuracy' => getValIfExists($ent, $acc), 'provider' => getValIfExists($ent, $src), 'bearing' => getValIfExists($ent, $bearing));
             } elseif (($this->fields[$fields[$f]]->type == "photo" || $this->fields[$fields[$f]]->type == "video" || $this->fields[$fields[$f]]->type == "audio") && preg_match('/^https?:\\/\\//', $ent[$fields[$f]])) {
                 $newfn = sprintf('%s_%s_%s', $this->projectName, $this->name, $ent[$this->key]);
                 $entry->values[$fields[$f]] = str_replace('~tn', '', $newfn);
                 /*$mqueue->writeMessage('getFile', array($ent[$fields[$f]], $newfn));*/
             } else {
                 if (array_key_exists($fields[$f], $ent)) {
                     $entry->values[$fields[$f]] = Encoding::toUTF8($ent[$fields[$f]]);
                 }
             }
         }
         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();
         }
         $entry->deviceId = 'web upload';
         array_push($ents, $entry);
         if (++$x % 100 == 0) {
             $entry->postEntries($ents);
             unset($ents);
             $ents = array();
         }
     }
     if (count($ents) > 0) {
         $entry->postEntries($ents);
     }
     return true;
 }
コード例 #4
0
ファイル: main.php プロジェクト: rohantakhar/EpiCollectplus
function resetPassword()
{
    global $auth;
    $user = getValIfExists($_POST, "user");
    if ($auth->isLoggedIn() && $auth->isServerManager() && $_SERVER["REQUEST_METHOD"] == "POST" && $user && preg_match("/[0-9]+/", $user)) {
        $res = $auth->resetPassword($user);
        header("Cache-Control: no-cache, must-revalidate");
        header("Content-Type: application/json");
        echo "{\"result\" : \"{$res}\"}";
    } else {
        header("HTTP/1.1 403 Access Denied", null, 403);
    }
}