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::ADMIN); |
| 23 | |
| 24 | if (!security::checkParams("POST", [ |
| 25 | ["type", security::PARAM_ISINT], |
| 26 | ["workers", security::PARAM_ISARRAY], |
| 27 | ["day", security::PARAM_ISDATE] |
| 28 | ])) { |
| 29 | security::go("incidents.php?msg=empty"); |
| 30 | } |
| 31 | |
| 32 | $type = (int)$_POST["type"]; |
| 33 | $day = $_POST["day"]; |
| 34 | $details = ((isset($_POST["details"]) && is_string($_POST["details"])) ? $_POST["details"] : ""); |
| 35 | |
| 36 | if (isset($_POST["allday"]) && $_POST["allday"] == 1) { |
| 37 | $begins = 0; |
| 38 | $ends = incidents::ENDOFDAY; |
| 39 | } else { |
| 40 | if (!security::checkParams("POST", [ |
| 41 | ["begins", security::PARAM_ISTIME], |
| 42 | ["ends", security::PARAM_ISTIME] |
| 43 | ])) { |
| 44 | security::go("incidents.php?msg=empty"); |
| 45 | } |
| 46 | |
| 47 | $begins = schedules::time2sec($_POST["begins"]); |
| 48 | $ends = schedules::time2sec($_POST["ends"]); |
| 49 | } |
| 50 | |
| 51 | $mdHeaderRowBefore = visual::backBtn("workers.php"); |
| 52 | ?> |
| 53 | <!DOCTYPE html> |
| 54 | <html> |
| 55 | <head> |
| 56 | <title><?php echo $conf["appName"]; ?></title> |
| 57 | <?php visual::includeHead(); ?> |
| 58 | <link rel="stylesheet" href="css/dashboard.css"> |
| 59 | </head> |
| 60 | <?php visual::printBodyTag(); ?> |
| 61 | <div class="mdl-layout mdl-js-layout mdl-layout--fixed-header mdl-layout--fixed-drawer"> |
| 62 | <?php visual::includeNav(); ?> |
| 63 | |
| 64 | <main class="mdl-layout__content"> |
| 65 | <div class="page-content"> |
| 66 | <div class="main mdl-shadow--4dp"> |
| 67 | <h2>Resultado de la creación de incidencias</h2> |
| 68 | |
| 69 | <?php |
| 70 | foreach ($_POST["workers"] as $workerid) { |
| 71 | $worker = workers::get($workerid); |
| 72 | if ($worker === false) continue; |
| 73 | |
| 74 | $status = incidents::add($worker["id"], $type, $details, $day, $begins, $ends); |
| 75 | |
| 76 | $person = "“".security::htmlsafe($worker["name"])."” (".security::htmlsafe($worker["companyname"]).")"; |
| 77 | |
| 78 | switch ($status) { |
| 79 | case 0: |
| 80 | echo "<p class='mdl-color-text--green'>Incidencia añadida correctamente a $person."; |
| 81 | break; |
| 82 | |
| 83 | case 2: |
| 84 | echo "<p class='mdl-color-text--orange'>La incidencia que se intentaba añadir se solapa con otra incidencia de $person, así que no se ha añadido a este trabajador."; |
| 85 | break; |
| 86 | |
| 87 | case 3: |
| 88 | echo "<p class='mdl-color-text--red'>No se ha podido añadir la incidencia a $person porque la fecha de inicio debe ser anterior a la de fin."; |
| 89 | break; |
| 90 | |
| 91 | default: |
| 92 | echo "<p class='mdl-color-text--red'>Ha ocurrido un error inesperado copiando la plantilla a $person."; |
| 93 | } |
| 94 | echo "</p>"; |
| 95 | } |
| 96 | ?> |
| 97 | </div> |
| 98 | </div> |
| 99 | </main> |
| 100 | </div> |
| 101 | </body> |
| 102 | </html> |