Ejemplo n.º 1
0
 public function put()
 {
     //check that the entry does already exist
     global $auth;
     //TODO: need to get the user details form the phone
     $db = new dbConnection();
     $res = $db->beginTransaction();
     if ($res !== true) {
         return $res;
     }
     //check that the entry does already exist
     $qry = "SELECT * FROM EntryValue WHERE projectName = '{$this->projectName}' AND formName = '{$this->formName}' AND fieldName = '{$this->form->keyField}' AND value = '{$this->values[$this->form->keyField]}'";
     //echo $qry;
     $num = 0;
     $res = $db->do_query($qry);
     if ($res !== true) {
         $db->rollbackTransaction();
         return $res;
     }
     while ($db->get_row_array()) {
         $num++;
     }
     if ($num == 0) {
         return "Entry does not exist";
     }
     $qry = "UPDATE ENTRY SET lastEdited = Now() where idEntry = {$this->id}";
     $res = $db->do_query($qry);
     if ($res !== true) {
         $db->rollbackTransaction();
         return $res;
     }
     foreach ($this->values as $key => $value) {
         $qry = "UPDATE EntryValue SET value = '{$value}' WHERE projectName = '{$this->projectName}' AND formName = '{$this->formName}' AND fieldName = '{$key}' AND entry = {$this->id}";
         $res = $db->do_query($qry);
         if ($res !== true) {
             $db->rollbackTransaction();
             return $res;
         }
         if ($db->affectedRows() == 0) {
             $qry = "INSERT INTO EntryValue (field, projectName, formName, fieldName, value, entry) VALUES  {$this->form->fields[$key]->id},'{$this->projectName}','{$this->formName}','{$key}','{$value}',{$this->id}";
             $res = $db->do_query($qry);
             if ($res !== true) {
                 $db->rollbackTransaction();
                 return $res;
             }
         }
     }
     if ($res === true) {
         $res = $db->commitTransaction();
     } else {
         $db->rollbackTransaction();
     }
     return $res;
 }