示例#1
0
 public function fetch()
 {
     $db = new dbConnection();
     $qry = "SELECT * from Form WHERE";
     if (is_numeric($this->id)) {
         $qry = "{$qry} idForm = {$this->id}";
     } else {
         $qry = "{$qry} projectName = '{$this->survey->name}' AND name = '{$this->name}'";
     }
     $res = $db->do_query($qry);
     if ($res === true) {
         while ($arr = $db->get_row_array()) {
             $this->id = $arr["idForm"];
             $this->key = $arr["keyField"];
             $this->name = $arr["name"];
             $this->number = $arr["table_num"];
             $this->version = $arr["version"];
         }
     }
     $qry = "SELECT f.idField as idField, f.key, f.name, f.label, ft.name as type, f.required, f.jump, f.isinteger as isInt, f.isDouble, f.title, f.regex, f.doubleEntry, f.search, f.group_form, f.branch_form, f.display, f.genkey, f.date, f.time, f.setDate, f.setTime FROM field f LEFT JOIN fieldType ft on ft.idFieldType = f.type WHERE ";
     if (is_numeric($this->id)) {
         $qry = "{$qry} f.form = {$this->id} ORDER BY f.position";
     } else {
         $qry = "{$qry} f.projectName = '{$this->survey->name}' AND f.formname = '{$this->name}' ORDER BY f.position";
     }
     $res = $db->do_query($qry);
     if ($res === true) {
         while ($arr = $db->get_row_array()) {
             if (!array_key_exists($arr["name"], $this->fields)) {
                 $fld = new EcField();
             } else {
                 $fld = $this->fields[$arr["name"]];
             }
             $fld->form = $this;
             $fld->fromArray($arr);
             $this->fields[$fld->name] = $fld;
             if ($fld->key) {
                 $this->key = $fld->name;
             }
         }
         foreach ($this->fields as $fld) {
             $db = new dbConnection();
             $res = $db->exec_sp("getOptions", array($fld->idField));
             while ($res === true && ($arr = $db->get_row_array())) {
                 $opt = new EcOption();
                 $opt->fromArray($arr);
                 $opt->idx = $arr["index"];
                 $fld->options[$opt->value] = $opt;
             }
         }
         return true;
     } else {
         return $res;
     }
 }
示例#2
0
 public function fetch()
 {
     $db = new dbConnection();
     //global $db;
     $this->titleFields = array();
     $qry = "SELECT * from form WHERE";
     if (is_numeric($this->id)) {
         $qry = "{$qry} idForm = {$this->id}";
     } else {
         $qry = "{$qry} projectName = '{$this->survey->name}' AND name = '{$this->name}'";
     }
     $res = $db->do_query($qry);
     if ($res === true) {
         while ($arr = $db->get_row_array()) {
             $this->id = $arr["idForm"];
             $this->key = $arr["keyField"];
             $this->name = $arr["name"];
             $this->number = $arr["table_num"];
             $this->version = $arr["version"];
             $this->group = $arr["group"];
             $this->isMain = $arr["isMain"] == "1";
         }
     }
     $qry = "SELECT f.idField as idField, f.key, f.name, f.label, ft.name as type, f.required, f.jump, f.isinteger as isInt, f.isDouble, f.title, f.regex, f.doubleEntry, f.search, f.group_form, f.branch_form, f.display, f.genkey, f.date, f.time, f.setDate, f.setTime, f.min, f.max, f.crumb, f.`match`, f.active, f.defaultValue, f.otherFieldProperties, f.upperCase, f.position FROM field f LEFT JOIN fieldtype ft on ft.idFieldType = f.type WHERE ";
     if (is_numeric($this->id)) {
         $qry = "{$qry} f.form = {$this->id} ORDER BY f.position";
     } else {
         $qry = "{$qry} f.projectName = '{$this->survey->name}' AND f.formname = '{$this->name}' ORDER BY f.position";
     }
     $res = $db->do_query($qry);
     if ($res === true) {
         while ($arr = $db->get_row_array()) {
             if (!array_key_exists($arr["name"], $this->fields)) {
                 $fld = new EcField();
             } else {
                 $fld = $this->fields[$arr["name"]];
             }
             $fld->form = $this;
             $fld->fromArray($arr);
             $fld->name = preg_replace('/[^0-9a-z]/i', '_', $fld->name);
             $fld->otherAttributes = json_decode($arr['otherFieldProperties']);
             $this->fields[$fld->name] = $fld;
             if ($fld->key) {
                 $this->key = $fld->name;
             }
             if ($fld->title && $fld->active) {
                 array_push($this->titleFields, $fld->name);
             }
         }
         foreach ($this->fields as $fld) {
             //$db = new dbConnection();
             if (!$fld->idField) {
                 continue;
             }
             $res = $db->do_query("SELECT `index`, `label`, `value` FROM `option` WHERE `field` = {$fld->idField}");
             //$db2->exec_sp("getOptions", array($fld->idField));
             if ($res !== true) {
                 die($res);
             }
             while ($arr = $db->get_row_array()) {
                 $opt = new EcOption();
                 $opt->fromArray($arr);
                 $opt->idx = $arr["index"];
                 array_push($fld->options, $opt);
             }
             if ($fld->type == "branch") {
                 array_push($this->branches, $fld->branch_form);
                 array_push($this->branchfields, $fld->name);
             }
         }
         return true;
     } else {
         return $res;
     }
 }