blob: 085ebab50d3532ab87be74cc916b2950947e5189 [file] [log] [blame]
Copybara botbe50d492023-11-30 00:16:42 +01001<?php
2require_once("core.php");
3security::checkType(security::ADMIN);
4
5if (!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
16if (!categories::exists($id)) {
17 security::go("calendars.php?msg=unexpected");
18}
19
20$calendar_response = calendars::parseFormCalendar($_POST["type"], $_POST["begins"], $_POST["ends"]);
21
22if ($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
28switch ($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}