Esempio n. 1
0
 public function fetch()
 {
     $db = new dbConnection();
     if ($this->name != "") {
         //$res = $db->exec_sp("getProject", array($this->name));
         $res = $db->do_query("SELECT * FROM project WHERE name = '{$this->name}'");
         if ($res !== true) {
             return $res;
         }
         while ($arr = $db->get_row_array()) {
             $this->fromArr($arr);
         }
         if (preg_match('/^ec_ade::/', $this->submission_id)) {
             $this->submission_id = str_replace('ec_ade::', '', $this->submission_id);
             $this->allowDownloadEdits = true;
         }
         $db = new dbConnection();
         //get forms
         $res = $db->exec_sp("getForms", array($this->name));
         if ($res === true) {
             while ($arr = $db->get_row_array()) {
                 $frm = new EcTable($this);
                 $frm->fromArray($arr);
                 //get fields
                 $frm->fetch();
                 //get options
                 if ($frm->number > 0) {
                     $this->tables[$frm->name] = $frm;
                 }
             }
             foreach ($this->tables as $tname => $tbl) {
                 foreach ($tbl->branches as $branch) {
                     $this->tables[$branch]->branchOf = $tname;
                 }
             }
         } else {
             return false;
         }
     }
 }
Esempio n. 2
0
 public function addToDb()
 {
     global $db;
     if (!$db) {
         $db = new dbConnection();
     }
     $qry = "SELECT idFieldType FROM FieldType where name = '{$this->type}'";
     $db->do_query($qry);
     while ($arr = $db->get_row_array()) {
         $fieldType = $arr["idFieldType"];
     }
     $lbl = mysql_escape_string($this->label);
     $qry = "INSERT INTO Field (form, projectName, formName, type, name, label, language, regex, title, `key`, isinteger, isdouble, active, doubleentry, jump, required, search, group_form, branch_form, display, genkey, date, time, setdate, settime, position) VALUES\n\t\t\t\t\t\t\t\t ({$this->form->id}, '{$this->form->survey->name}', '{$this->form->name}', {$fieldType}, '{$this->name}','{$lbl}', '{$this->language}',";
     $qry .= $this->regex != "" ? "'{$this->regex}'," : "NULL,";
     $qry .= $this->title ? "1," : "0,";
     $qry .= $this->key ? "1," : "0,";
     $qry .= $this->isInt ? "1," : "0,";
     $qry .= $this->isDouble ? "1," : "0,";
     $qry .= "1,";
     $qry .= $this->doubleEntry ? "1," : "0,";
     $qry .= $this->jump ? "'{$this->jump}'," : "NULL,";
     $qry .= $this->required ? "1," : "0,";
     $qry .= $this->search ? "1," : "0,";
     $qry .= $this->group_form ? "'{$this->group_form}'," : "NULL,";
     $qry .= $this->branch_form ? "'{$this->branch_form}'," : "NULL,";
     $qry .= $this->display ? "1," : "0,";
     $qry .= $this->genkey ? "1," : "0,";
     $qry .= $this->date ? "'{$this->date}'," : "NULL,";
     $qry .= $this->time ? "'{$this->time}'," : "NULL,";
     $qry .= $this->setDate ? "'{$this->setDate}'," : "NULL,";
     $qry .= $this->setTime ? "'{$this->setTime}'," : "NULL,";
     $qry .= "{$this->position})";
     $res = $db->do_query($qry);
     if ($res === true) {
         foreach ($this->options as $opt) {
             $res = $db->exec_sp("addOption", array($this->form->survey->name, $this->form->name, $this->name, $opt->idx, $opt->label, $opt->value));
             if ($res !== true) {
                 return $res;
             }
         }
     }
     return $res;
 }