Beispiel #1
0
 public function push()
 {
     global $auth, $log, $db;
     //$log = new Logger('Ec2');
     $log->write('info', 'Starting project update');
     $db = new dbConnection();
     if ($this->checkPermission($auth->getEcUserId()) >= 2) {
         $log->write('info', 'User has permission');
         $res = $db->beginTransaction();
         if ($res !== true) {
             return $res;
         }
         $log->write('info', 'transaction started');
         $res = $db->do_query("UPDATE Project SET description = " . $db->stringVal($this->description) . ", image = " . $db->stringVal($this->image) . ",\n\t\t\t\t\t\t\t\t\t isPublic  = " . $db->boolVal($this->isPublic) . ", isListed = " . $db->boolVal($this->isListed) . ",\n\t\t\t\t\t\t\t\t\tpublicSubmission = " . $db->boolVal($this->publicSubmission) . "\tWHERE id = {$this->id} AND name = '{$this->name}'");
         if ($res !== true) {
             return $res;
         }
         $log->write('info', 'Project details updated');
         foreach ($this->tables as $tbl) {
             $log->write('info', "Updating form {$tbl->name}");
             $res = $tbl->update();
             if ($res !== true) {
                 $log->write('error', "Updating form {$tbl->name} failed {$res}");
                 $db->rollbackTransaction();
                 return $res;
             }
             $log->write('info', "Updated form {$tbl->name}");
         }
         $db->commitTransaction();
         $log->write('info', "Update done");
         return true;
     } else {
         return "You do not have permission to update this project";
     }
 }
Beispiel #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 = $db->escapeArg($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, upperCase, date, time, setdate, settime, `min`, `max`, `match`, crumb, defaultValue, position, otherFieldProperties) 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 != "" ? $db->stringVal($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->upperCase ? "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->min || $this->min === '0' ? "{$this->min}," : "NULL,";
     $qry .= $this->max || $this->max === '0' ? "{$this->max}," : "NULL,";
     $qry .= $this->match ? $db->stringVal($this->match) . ',' : "NULL,";
     $qry .= $this->crumb ? "'{$this->crumb}'," : "NULL,";
     $qry .= $this->defaultValue || $this->defaultValue === '0' ? $db->stringVal($this->defaultValue) . "," : "NULL,";
     $qry .= "{$this->position},";
     $qry .= $db->stringVal(json_encode($this->otherAttributes)) . ")";
     $res = $db->do_query($qry);
     if ($res === true) {
         $this->idField = $db->last_id();
         $optcount = count($this->options);
         if ($optcount > 0) {
             $optqry = 'INSERT INTO `option` (`index`, `label`, `value`, `field`) VALUES';
             //print_r($this->options);
             for ($x = 0; $x < $optcount; ++$x) {
                 $lab = $db->stringVal($this->options[$x]->label);
                 $val = $db->stringVal($this->options[$x]->value);
                 if ($lab == 'NULL') {
                     throw new Exception(sprintf('The label for option %d of field %s cannot be null.', $x, $this->name));
                 }
                 if ($val == 'NULL') {
                     throw new Exception(sprintf('The value of option %d of field %s cannot be null.', $x, $this->name));
                 }
                 $optqry = sprintf('%s%s (%s, %s, %s, %s)', $optqry, $x > 0 ? ',' : '', intval($this->options[$x]->idx), $lab, $val, intval($this->idField));
                 //$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;
             }
             $res = $db->do_query($optqry);
             if ($res !== true) {
                 return $res;
             }
         }
     }
     //echo "$qry\n";
     return $res;
 }