Copybara bot | be50d49 | 2023-11-30 00:16:42 +0100 | [diff] [blame^] | 1 | <?php |
| 2 | require_once("core.php"); |
| 3 | security::checkType(security::ADMIN); |
| 4 | |
| 5 | if (!security::checkParams("POST", [ |
| 6 | ["type", security::PARAM_ISINT], |
| 7 | ["workers", security::PARAM_ISARRAY], |
| 8 | ["day", security::PARAM_ISDATE] |
| 9 | ])) { |
| 10 | security::go("incidents.php?msg=empty"); |
| 11 | } |
| 12 | |
| 13 | $type = (int)$_POST["type"]; |
| 14 | $day = $_POST["day"]; |
| 15 | $details = ((isset($_POST["details"]) && is_string($_POST["details"])) ? $_POST["details"] : ""); |
| 16 | |
| 17 | if (isset($_POST["allday"]) && $_POST["allday"] == 1) { |
| 18 | $begins = 0; |
| 19 | $ends = incidents::ENDOFDAY; |
| 20 | } else { |
| 21 | if (!security::checkParams("POST", [ |
| 22 | ["begins", security::PARAM_ISTIME], |
| 23 | ["ends", security::PARAM_ISTIME] |
| 24 | ])) { |
| 25 | security::go("incidents.php?msg=empty"); |
| 26 | } |
| 27 | |
| 28 | $begins = schedules::time2sec($_POST["begins"]); |
| 29 | $ends = schedules::time2sec($_POST["ends"]); |
| 30 | } |
| 31 | |
| 32 | $mdHeaderRowBefore = visual::backBtn("workers.php"); |
| 33 | ?> |
| 34 | <!DOCTYPE html> |
| 35 | <html> |
| 36 | <head> |
| 37 | <title><?php echo $conf["appName"]; ?></title> |
| 38 | <?php visual::includeHead(); ?> |
| 39 | <link rel="stylesheet" href="css/dashboard.css"> |
| 40 | </head> |
| 41 | <?php visual::printBodyTag(); ?> |
| 42 | <div class="mdl-layout mdl-js-layout mdl-layout--fixed-header mdl-layout--fixed-drawer"> |
| 43 | <?php visual::includeNav(); ?> |
| 44 | |
| 45 | <main class="mdl-layout__content"> |
| 46 | <div class="page-content"> |
| 47 | <div class="main mdl-shadow--4dp"> |
| 48 | <h2>Resultado de la creación de incidencias</h2> |
| 49 | |
| 50 | <?php |
| 51 | foreach ($_POST["workers"] as $workerid) { |
| 52 | $worker = workers::get($workerid); |
| 53 | if ($worker === false) continue; |
| 54 | |
| 55 | $status = incidents::add($worker["id"], $type, $details, $day, $begins, $ends); |
| 56 | |
| 57 | $person = "“".security::htmlsafe($worker["name"])."” (".security::htmlsafe($worker["companyname"]).")"; |
| 58 | |
| 59 | switch ($status) { |
| 60 | case 0: |
| 61 | echo "<p class='mdl-color-text--green'>Incidencia añadida correctamente a $person."; |
| 62 | break; |
| 63 | |
| 64 | case 2: |
| 65 | 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."; |
| 66 | break; |
| 67 | |
| 68 | case 3: |
| 69 | 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."; |
| 70 | break; |
| 71 | |
| 72 | default: |
| 73 | echo "<p class='mdl-color-text--red'>Ha ocurrido un error inesperado copiando la plantilla a $person."; |
| 74 | } |
| 75 | echo "</p>"; |
| 76 | } |
| 77 | ?> |
| 78 | </div> |
| 79 | </div> |
| 80 | </main> |
| 81 | </div> |
| 82 | </body> |
| 83 | </html> |