blob: 645a9f99e24725bbfe66f3ef3c29fc619a6b3ac4 [file] [log] [blame]
Copybara botbe50d492023-11-30 00:16:42 +01001<?php
2require_once("core.php");
3security::checkType(security::WORKER);
4
5$url = (security::isAllowed(security::ADMIN) ? "incidents.php" : "userincidents.php?id=".(int)$_SESSION["id"]);
6
7if (!security::checkParams("POST", [
8 ["type", security::PARAM_ISINT],
9 ["worker", security::PARAM_ISINT],
10 ["day", security::PARAM_ISDATE]
11])) {
12 security::go(visual::getContinueUrl($url, "empty", "POST"));
13}
14
15$type = (int)$_POST["type"];
16$worker = (int)$_POST["worker"];
17$day = $_POST["day"];
18$details = ((isset($_POST["details"]) && is_string($_POST["details"])) ? $_POST["details"] : "");
19
20if (isset($_POST["allday"]) && $_POST["allday"] == 1) {
21 $begins = incidents::STARTOFDAY;
22 $ends = incidents::ENDOFDAY;
23} else {
24 if (!security::checkParams("POST", [
25 ["begins", security::PARAM_ISTIME],
26 ["ends", security::PARAM_ISTIME]
27 ])) {
28 security::go(visual::getContinueUrl($url, "empty", "POST"));
29 }
30
31 $begins = schedules::time2sec($_POST["begins"]);
32 $ends = schedules::time2sec($_POST["ends"]);
33}
34
35$verified = ((isset($_POST["autoverify"]) && $_POST["autoverify"] == 1 && security::isAllowed(security::ADMIN)) ? 1 : 0);
36$isAdminView = security::isAdminView();
37
38$incidentPerson = people::workerData("id", $worker);
39
40$status = incidents::add($worker, $type, $details, $day, $begins, $ends, "ME", $verified, false, !$isAdminView, true, ($incidentPerson == people::userData("id")));
41
42switch ($status) {
43 case 0:
44 security::go(visual::getContinueUrl($url, "added", "POST"));
45 break;
46
47 case 2:
48 security::go(visual::getContinueUrl($url, "overlap", "POST"));
49 break;
50
51 case 3:
52 security::go(visual::getContinueUrl($url, "order", "POST"));
53 break;
54
55 case 4:
56 security::go(visual::getContinueUrl($url, "addedemailnotsent", "POST"));
57 break;
58
59 case 5:
60 security::go(visual::getContinueUrl($url, "addednotautovalidated", "POST"));
61 break;
62
63 default:
64 security::go(visual::getContinueUrl($url, "unexpected", "POST"));
65}