Copybara bot | be50d49 | 2023-11-30 00:16:42 +0100 | [diff] [blame] | 1 | <?php |
Adrià Vilanova Martínez | 5af8651 | 2023-12-02 20:44:16 +0100 | [diff] [blame] | 2 | /* |
| 3 | * hores |
| 4 | * Copyright (c) 2023 Adrià Vilanova Martínez |
| 5 | * |
| 6 | * This program is free software: you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU Affero General Public License as |
| 8 | * published by the Free Software Foundation, either version 3 of the |
| 9 | * License, or (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU Affero General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU Affero General Public |
| 17 | * License along with this program. |
| 18 | * If not, see http://www.gnu.org/licenses/. |
| 19 | */ |
| 20 | |
Copybara bot | be50d49 | 2023-11-30 00:16:42 +0100 | [diff] [blame] | 21 | require_once("core.php"); |
| 22 | security::checkType(security::WORKER); |
| 23 | |
| 24 | $url = (security::isAllowed(security::ADMIN) ? "incidents.php" : "userincidents.php?id=".(int)$_SESSION["id"]); |
| 25 | |
| 26 | if (!security::checkParams("POST", [ |
| 27 | ["type", security::PARAM_ISINT], |
| 28 | ["worker", security::PARAM_ISINT], |
| 29 | ["day", security::PARAM_ISDATE] |
| 30 | ])) { |
| 31 | security::go(visual::getContinueUrl($url, "empty", "POST")); |
| 32 | } |
| 33 | |
| 34 | $type = (int)$_POST["type"]; |
| 35 | $worker = (int)$_POST["worker"]; |
| 36 | $day = $_POST["day"]; |
| 37 | $details = ((isset($_POST["details"]) && is_string($_POST["details"])) ? $_POST["details"] : ""); |
| 38 | |
| 39 | if (isset($_POST["allday"]) && $_POST["allday"] == 1) { |
| 40 | $begins = incidents::STARTOFDAY; |
| 41 | $ends = incidents::ENDOFDAY; |
| 42 | } else { |
| 43 | if (!security::checkParams("POST", [ |
| 44 | ["begins", security::PARAM_ISTIME], |
| 45 | ["ends", security::PARAM_ISTIME] |
| 46 | ])) { |
| 47 | security::go(visual::getContinueUrl($url, "empty", "POST")); |
| 48 | } |
| 49 | |
| 50 | $begins = schedules::time2sec($_POST["begins"]); |
| 51 | $ends = schedules::time2sec($_POST["ends"]); |
| 52 | } |
| 53 | |
| 54 | $verified = ((isset($_POST["autoverify"]) && $_POST["autoverify"] == 1 && security::isAllowed(security::ADMIN)) ? 1 : 0); |
| 55 | $isAdminView = security::isAdminView(); |
| 56 | |
| 57 | $incidentPerson = people::workerData("id", $worker); |
| 58 | |
| 59 | $status = incidents::add($worker, $type, $details, $day, $begins, $ends, "ME", $verified, false, !$isAdminView, true, ($incidentPerson == people::userData("id"))); |
| 60 | |
| 61 | switch ($status) { |
| 62 | case 0: |
| 63 | security::go(visual::getContinueUrl($url, "added", "POST")); |
| 64 | break; |
| 65 | |
| 66 | case 2: |
| 67 | security::go(visual::getContinueUrl($url, "overlap", "POST")); |
| 68 | break; |
| 69 | |
| 70 | case 3: |
| 71 | security::go(visual::getContinueUrl($url, "order", "POST")); |
| 72 | break; |
| 73 | |
| 74 | case 4: |
| 75 | security::go(visual::getContinueUrl($url, "addedemailnotsent", "POST")); |
| 76 | break; |
| 77 | |
| 78 | case 5: |
| 79 | security::go(visual::getContinueUrl($url, "addednotautovalidated", "POST")); |
| 80 | break; |
| 81 | |
| 82 | default: |
| 83 | security::go(visual::getContinueUrl($url, "unexpected", "POST")); |
| 84 | } |