Example #1
0
 public static function _CreateNewQuarterlyForUser($uid = -1)
 {
     include_once __DIR__ . DS . 'RWAForm.php';
     $data = RWAForm::ValidateAddendumData(json_decode(UrlVar('json')));
     /* @var $db ScheduleDatabase */
     include_once dirname(__DIR__) . DS . 'database' . DS . 'ScheduleDatabase.php';
     $db = ScheduleDatabase::GetInstance();
     $entry = array('code' => $data->{'participant-id'}, 'formDate' => RWAForm::GetFormDate($data));
     if ($uid >= 0) {
         $entry['uid'] = $uid;
     }
     $update = false;
     if (key_exists('id', $data)) {
         if ($data->id > 0) {
             $entry['id'] = $data->id;
             $id = $data->id;
             $update = true;
         }
         unset($data->id);
     }
     $entry['formData'] = json_encode($data, JSON_PRETTY_PRINT);
     if ($update) {
         $db->updateQuarterly($entry);
     } else {
         $date = date('Y-m-d H:i:s');
         $entry['submitDate'] = $date;
         $entry['uid'] = Core::Client()->getUserId();
         $id = $db->createQuarterly($entry);
     }
     echo json_encode(array('success' => true, 'result' => array('id' => $id)), JSON_PRETTY_PRINT);
 }