public function savepart() { try { if (Check::digits($_POST['study_id'], $empty = false)) { $study_id = $_POST['study_id']; } else { throw new Exception("bad study id!"); } if (Check::digits($_POST['participant_id'])) { $part_id = $_POST['participant_id']; } else { throw new Exception("bad participant id!"); } if (!Check::isemail($_POST['email'])) { throw new Exception("need a valid email!"); } if (empty($_POST['firstname'])) { throw new Exception("need a first name!"); } unset($_POST['participant_id']); unset($_POST['study_id']); $p = new Participant(); if ($part_id) { if ($p->upd($part_id, $_POST) === false) { throw new Exception($p->err()); } } else { if ($p->ins($_POST) === false) { throw new Exception($p->err()); } $part_id = $p->getid(); $e = new Enrollment(); if ($e->ins(array('study_id' => $study_id, 'participant_id' => $part_id, 'enrolled' => date('Y-m-d H:i:s'))) === false) { throw new Exception($e->err()); } } View::assign('study_id', $study_id); View::assign('part_id', $part_id); return 'participant.tpl'; } catch (Exception $e) { $this->err($e); View::assign('error', $this->error); return 'error.tpl'; } }