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 | class validationsView { |
| 22 | public static function renderPendingValidations($userId) { |
| 23 | $workers = workers::getPersonWorkers((int)$userId); |
| 24 | $companies = companies::getAll(); |
| 25 | |
| 26 | if ($workers === false || $companies === false) { |
| 27 | return false; |
| 28 | } |
| 29 | ?> |
| 30 | <h4>Incidencias</h4> |
| 31 | <?php |
| 32 | $iFlag = false; |
| 33 | foreach ($workers as $w) { |
| 34 | $incidents = incidents::getAll(false, 0, 0, (int)$w["id"], null, null, true); |
| 35 | if ($incidents === false) continue; |
| 36 | |
| 37 | if (count($incidents)) { |
| 38 | $iFlag = true; |
| 39 | echo "<h5>".security::htmlsafe($w["companyname"])."</h5>"; |
| 40 | incidentsView::renderIncidents($incidents, $companies, false, false, true, true); |
| 41 | } |
| 42 | |
| 43 | visual::printDebug("incidents::getAll(false, 0, 0, ".(int)$w["id"].", null, null, true)", $incidents); |
| 44 | } |
| 45 | |
| 46 | if (!$iFlag) echo "<p>No hay incidencias pendientes para validar.</p>"; |
| 47 | ?> |
| 48 | |
| 49 | <h4>Registros de horario</h4> |
| 50 | <?php |
| 51 | $rFlag = false; |
| 52 | foreach ($workers as $w) { |
| 53 | $registry = registry::getWorkerRecords((int)$w["id"], false, false, false, true); |
| 54 | if ($registry === false) continue; |
| 55 | |
| 56 | if (count($registry)) { |
| 57 | $rFlag = true; |
| 58 | echo "<h5>".security::htmlsafe($w["companyname"])."</h5>"; |
| 59 | registryView::renderRegistry($registry, $companies, false, false, true, true); |
| 60 | } |
| 61 | |
| 62 | visual::printDebug("registry::getWorkerRecords(".(int)$w["id"].", false, false, false, true)", $registry); |
| 63 | } |
| 64 | |
| 65 | if (!$rFlag) echo "<p>No hay registros pendientes para validar.</p>"; |
| 66 | |
| 67 | if ($iFlag || $rFlag) { |
| 68 | ?> |
| 69 | <p style="margin-top: 16px;"><button id="submit" class="mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect mdl-button--accent">Validar</button></p> |
| 70 | <?php |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | public static function renderChallengeInstructions($method) { |
| 75 | switch ($method) { |
| 76 | case validations::METHOD_SIMPLE: |
| 77 | ?> |
| 78 | <form action="dovalidate.php" method="POST"> |
| 79 | <input type="hidden" name="incidents" value="<?=security::htmlsafe($_POST["incidents"] ?? "")?>"> |
| 80 | <input type="hidden" name="records" value="<?=security::htmlsafe($_POST["records"] ?? "")?>"> |
| 81 | <input type="hidden" name="method" value="<?=(int)validations::METHOD_SIMPLE?>"> |
| 82 | <p>Para completar la validación guardaremos tu <a href="https://help.gnome.org/users/gnome-help/stable/net-what-is-ip-address.html.es" target="_blank" rel="noopener noreferrer">dirección IP</a> y la fecha y hora actual. Para proceder, haz clic en el siguiente botón:</p> |
| 83 | <p><button id="submit" class="mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect mdl-button--accent">Confirmar validación</button></p> |
| 84 | </form> |
| 85 | <?php |
| 86 | break; |
| 87 | |
| 88 | default: |
| 89 | echo "Undefined"; |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | public static function noPIIIpAddress($validation) { |
| 94 | $ipAddress = $validation["attestation"]["ipAddress"] ?? "unknown"; |
| 95 | |
| 96 | if (security::isAdminView() || $validation["method"] == validations::METHOD_SIMPLE || ($validation["method"] == validations::METHOD_AUTOVALIDATION && $validation["attestation"]["user"] == people::userData("id"))) return $ipAddress; |
| 97 | |
| 98 | return "oculta (solo visible para los administradores)"; |
| 99 | } |
| 100 | |
| 101 | public static function renderValidationInfo($validation) { |
| 102 | ?> |
| 103 | <li><b>Validada por el trabajador:</b></li> |
| 104 | <ul> |
| 105 | <li><b>Método de validación:</b> <?=security::htmlsafe(validations::$methodName[$validation["method"]])?></li> |
| 106 | <li><b>Fecha de validación:</b> <?=security::htmlsafe(date("d/m/Y H:i", $validation["timestamp"]))?></li> |
| 107 | <?php |
| 108 | switch ($validation["method"]) { |
| 109 | case validations::METHOD_SIMPLE: |
| 110 | echo "<li><b>Dirección IP:</b> ".security::htmlsafe(self::noPIIIpAddress($validation))."</li>"; |
| 111 | break; |
| 112 | |
| 113 | case validations::METHOD_AUTOVALIDATION: |
| 114 | echo "<li><b>Dirección IP:</b> ".security::htmlsafe(self::noPIIIpAddress($validation))."</li>"; |
| 115 | echo "<li><b>Persona que autovalida la incidencia:</b> ".security::htmlsafe(people::userData("name", $validation["attestation"]["user"]))."</li>"; |
| 116 | break; |
| 117 | |
| 118 | default: |
| 119 | } |
| 120 | ?> |
| 121 | </ul> |
| 122 | <?php |
| 123 | } |
| 124 | } |