Copybara bot | be50d49 | 2023-11-30 00:16:42 +0100 | [diff] [blame^] | 1 | <?php |
| 2 | require_once("core.php"); |
| 3 | security::checkType(security::ADMIN); |
| 4 | |
| 5 | if (!security::checkParams("POST", [ |
| 6 | ["id", security::PARAM_NEMPTY], |
| 7 | ["type", security::PARAM_ISSET], |
| 8 | ["begins", security::PARAM_ISDATE], |
| 9 | ["ends", security::PARAM_ISDATE] |
| 10 | ])) { |
| 11 | security::go("calendars.php?msg=unexpected"); |
| 12 | } |
| 13 | |
| 14 | $id = (int)$_POST["id"]; |
| 15 | |
| 16 | if (!categories::exists($id)) { |
| 17 | security::go("calendars.php?msg=unexpected"); |
| 18 | } |
| 19 | |
| 20 | $calendar_response = calendars::parseFormCalendar($_POST["type"], $_POST["begins"], $_POST["ends"]); |
| 21 | |
| 22 | if ($calendar_response === false) { |
| 23 | security::go("calendars.php?msg=unexpected"); |
| 24 | } |
| 25 | |
| 26 | $return = calendars::add($id, $calendar_response["begins"], $calendar_response["ends"], $calendar_response["calendar"]); |
| 27 | |
| 28 | switch ($return) { |
| 29 | case 0: |
| 30 | security::go("calendars.php?msg=added"); |
| 31 | |
| 32 | case -1: |
| 33 | security::go("calendars.php?msg=overlap"); |
| 34 | |
| 35 | default: |
| 36 | security::go("calendars.php?msg=unexpected"); |
| 37 | } |