blob: c0c8097d11d63e2e1d74ebd6fdd9d6d5019686bb [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])) {
8 security::go("scheduletemplates.php?msg=unexpected");
9}
10
11$id = (int)$_POST["id"];
12
13if (!security::checkParams("POST", [
14 ["day", security::PARAM_ISARRAY],
15 ["type", security::PARAM_ISARRAY]
16])) {
17 security::go("scheduletemplate.php?id=".$id."&msg=empty");
18}
19
20$dates = ["beginswork", "endswork", "beginsbreakfast", "endsbreakfast", "beginslunch", "endslunch"];
21$time = [];
22foreach ($dates as $date) {
23 if (isset($_POST[$date]) && !empty($_POST[$date])) {
24 if (!security::checkParam($_POST[$date], security::PARAM_ISTIME)) {
25 security::go("scheduletemplate.php?id=".$id."&msg=unexpected");
26 }
27 $time[$date] = schedules::time2sec($_POST[$date]);
28 } else {
29 $time[$date] = 0;
30 }
31}
32
33$status = schedules::checkAddDayGeneric($time["beginswork"], $time["endswork"], $time["beginsbreakfast"], $time["endsbreakfast"], $time["beginslunch"], $time["endslunch"]);
34
35if ($status != 0) {
36 security::go("scheduletemplate.php?id=".$id."&msg=errorcheck".(int)$status);
37}
38
39$flag = false;
40
41foreach ($_POST["day"] as $rawday) {
42 $day = (int)$rawday;
43 if ($day < 0 || $day > 6) continue;
44
45 foreach ($_POST["type"] as $rawtype) {
46 $type = (int)$rawtype;
47 if (!in_array($type, array_keys(calendars::$types))) continue;
48
49 if (!schedules::checkAddDay2TemplateParticular($id, $day, $type)) {
50 $flag = true;
51 continue;
52 }
53
54 if (!schedules::addDay2Template($id, $day, $type, $time["beginswork"], $time["endswork"], $time["beginsbreakfast"], $time["endsbreakfast"], $time["beginslunch"], $time["endslunch"])) {
55 security::go("scheduletemplate.php?id=".$id."&msg=unexpected");
56 }
57 }
58}
59
60if ($flag) {
61 security::go("scheduletemplate.php?id=".$id."&msg=existing");
62} else {
63 security::go("scheduletemplate.php?id=".$id."&msg=added");
64}