public function main() { $name = Utility::cleanString($_POST["name"]); $notes = Utility::cleanString($_POST["notes"]); $is_chapter = Utility::cleanBoolean($_POST["is_chapter"]); $all_day_event = !$is_chapter && Utility::cleanBoolean($_POST["is_all_day"]); $start = Utility::getDateTimeFromDateYmdHis(Utility::cleanString($_POST["time_start"])); $end = Utility::getDateTimeFromDateYmdHis(Utility::cleanString($_POST["time_end"])); $is_repeating = !$is_chapter && Utility::cleanBoolean($_POST["is_repeating"]); $n_times = Utility::cleanInt($_POST["n_times"], 2); $repeat_type = Utility::cleanInt($_POST["repeat_type"], Group::TYPE_DAYS, Group::TYPE_YEARS); if ($name == "") { $this->setError(self::$E_INVALID_NAME); } else { if (!$all_day_event && !$start) { $this->setError(self::$E_INVALID_DATE_START); } else { if (!$all_day_event && !$is_chapter && !$end) { $this->setError(self::$E_INVALID_DATE_END); } else { if (!$all_day_event && $end <= $start) { $this->setError(self::$E_INVALID_DATE_END_BEFORE_START); } else { if ($is_repeating) { if ($n_times === false) { $this->setError(self::$E_INVALID_REPEAT_TIME); } else { if ($repeat_type === false) { $this->setError(self::$E_INVALID_REPEAT_TYPE); } } } } } } } if ($this->hasError()) { return []; } $_events = []; if ($all_day_event) { $start = $start ?: null; $end = $end ?: null; } if (!$is_repeating) { $_event = new Event($this->_pdo); $_event->create($name, $notes, $all_day_event, $is_chapter, $this->_auth->getUser(), $end, $start); $_events[] = $_event; } else { $_group = new Group($this->_pdo); $_group->create($name, $notes, $all_day_event, $is_chapter, $n_times, $this->_auth->getUser(), $repeat_type, $start, $end); $_events = $_group->generateEvents(); } return $_events; }
<?php require_once __DIR__ . "/../../FMA/autoload.php"; header("Content-Type: application/json"); $_pdo = new \FMA\PDO\MySQL_PDO(); $_auth = new \FMA\Auth\SessionAuth($_pdo); $router = new AltoRouter([], "/service"); $router->map("POST", "/login/", function () use($_pdo, $_auth) { $_auth->authenticate($_POST["email"] ?: "", $_POST["password"] ?: ""); $user = null; if (!$_auth->hasError() && $_auth->getUser()) { $user = $_auth->getUser(); if (\FMA\Utility::cleanBoolean($_POST["remember"])) { $_auth->remember(); } $user = $user ? $user->toArray() : $user; } return ["err" => $_auth->hasError(), "msg" => $_auth->getErrorMessage(), "user" => $user]; }); $match = $router->match(); if ($match && !is_callable($match["target"])) { throw new TypeError("Target is not callable."); } else { if ($match && is_callable($match["target"])) { $page_title = $match["name"]; $arr = call_user_func_array($match["target"], $match["params"]); echo json_encode($arr, JSON_PRETTY_PRINT); } else { $page_title = "404"; header($_SERVER["SERVER_PROTOCOL"] . " 404 Not Found"); echo json_encode(["err" => true, "msg" => "Invalid Request URI"], JSON_PRETTY_PRINT);