* span (decimal) * reason (string) * */ header('Content-type: application/json'); $expectations = ['author_id', 'for_id', 'date', 'span', 'reason']; if (!\Utilities\Requests::HasRequest($expectations)) { die(ModelResponse::InvalidRequest()); } $raw_data = []; foreach ($_REQUEST as $key => $value) { if (in_array($key, $expectations)) { $raw_data[$key] = $value; } } $newSickleave = new \Models\Sickleave(); $newSickleave->Absorb($raw_data); if (!$newSickleave->SaveAll()) { die(ModelResponse::DataSaveFailed()); } // Otherwise, success // Notify via email $isNotificationEnabled = Utilities\Config::get('email_notification', CONFIG_PATH . 'application.ini'); if ($isNotificationEnabled == 1) { try { Utilities\Email::NotifyAdmins($newSickleave); } catch (phpmailerException $ex) { $newSickleave->SetState(new ModelResponse(false, 'Failure on notifying admins: ' . $ex->getMessage())); } } die(new ModelResponse(true, "Sick leave entry has been successfully added!", $newSickleave));