Project import generated by Copybara.
GitOrigin-RevId: 63746295f1a5ab5a619056791995793d65529e62
diff --git a/src/doaddcalendar.php b/src/doaddcalendar.php
new file mode 100644
index 0000000..085ebab
--- /dev/null
+++ b/src/doaddcalendar.php
@@ -0,0 +1,37 @@
+<?php
+require_once("core.php");
+security::checkType(security::ADMIN);
+
+if (!security::checkParams("POST", [
+ ["id", security::PARAM_NEMPTY],
+ ["type", security::PARAM_ISSET],
+ ["begins", security::PARAM_ISDATE],
+ ["ends", security::PARAM_ISDATE]
+])) {
+ security::go("calendars.php?msg=unexpected");
+}
+
+$id = (int)$_POST["id"];
+
+if (!categories::exists($id)) {
+ security::go("calendars.php?msg=unexpected");
+}
+
+$calendar_response = calendars::parseFormCalendar($_POST["type"], $_POST["begins"], $_POST["ends"]);
+
+if ($calendar_response === false) {
+ security::go("calendars.php?msg=unexpected");
+}
+
+$return = calendars::add($id, $calendar_response["begins"], $calendar_response["ends"], $calendar_response["calendar"]);
+
+switch ($return) {
+ case 0:
+ security::go("calendars.php?msg=added");
+
+ case -1:
+ security::go("calendars.php?msg=overlap");
+
+ default:
+ security::go("calendars.php?msg=unexpected");
+}