Copybara bot | be50d49 | 2023-11-30 00:16:42 +0100 | [diff] [blame] | 1 | <?php |
| 2 | class validationsView { |
| 3 | public static function renderPendingValidations($userId) { |
| 4 | $workers = workers::getPersonWorkers((int)$userId); |
| 5 | $companies = companies::getAll(); |
| 6 | |
| 7 | if ($workers === false || $companies === false) { |
| 8 | return false; |
| 9 | } |
| 10 | ?> |
| 11 | <h4>Incidencias</h4> |
| 12 | <?php |
| 13 | $iFlag = false; |
| 14 | foreach ($workers as $w) { |
| 15 | $incidents = incidents::getAll(false, 0, 0, (int)$w["id"], null, null, true); |
| 16 | if ($incidents === false) continue; |
| 17 | |
| 18 | if (count($incidents)) { |
| 19 | $iFlag = true; |
| 20 | echo "<h5>".security::htmlsafe($w["companyname"])."</h5>"; |
| 21 | incidentsView::renderIncidents($incidents, $companies, false, false, true, true); |
| 22 | } |
| 23 | |
| 24 | visual::printDebug("incidents::getAll(false, 0, 0, ".(int)$w["id"].", null, null, true)", $incidents); |
| 25 | } |
| 26 | |
| 27 | if (!$iFlag) echo "<p>No hay incidencias pendientes para validar.</p>"; |
| 28 | ?> |
| 29 | |
| 30 | <h4>Registros de horario</h4> |
| 31 | <?php |
| 32 | $rFlag = false; |
| 33 | foreach ($workers as $w) { |
| 34 | $registry = registry::getWorkerRecords((int)$w["id"], false, false, false, true); |
| 35 | if ($registry === false) continue; |
| 36 | |
| 37 | if (count($registry)) { |
| 38 | $rFlag = true; |
| 39 | echo "<h5>".security::htmlsafe($w["companyname"])."</h5>"; |
| 40 | registryView::renderRegistry($registry, $companies, false, false, true, true); |
| 41 | } |
| 42 | |
| 43 | visual::printDebug("registry::getWorkerRecords(".(int)$w["id"].", false, false, false, true)", $registry); |
| 44 | } |
| 45 | |
| 46 | if (!$rFlag) echo "<p>No hay registros pendientes para validar.</p>"; |
| 47 | |
| 48 | if ($iFlag || $rFlag) { |
| 49 | ?> |
| 50 | <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> |
| 51 | <?php |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | public static function renderChallengeInstructions($method) { |
| 56 | switch ($method) { |
| 57 | case validations::METHOD_SIMPLE: |
| 58 | ?> |
| 59 | <form action="dovalidate.php" method="POST"> |
| 60 | <input type="hidden" name="incidents" value="<?=security::htmlsafe($_POST["incidents"] ?? "")?>"> |
| 61 | <input type="hidden" name="records" value="<?=security::htmlsafe($_POST["records"] ?? "")?>"> |
| 62 | <input type="hidden" name="method" value="<?=(int)validations::METHOD_SIMPLE?>"> |
| 63 | <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> |
| 64 | <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> |
| 65 | </form> |
| 66 | <?php |
| 67 | break; |
| 68 | |
| 69 | default: |
| 70 | echo "Undefined"; |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | public static function noPIIIpAddress($validation) { |
| 75 | $ipAddress = $validation["attestation"]["ipAddress"] ?? "unknown"; |
| 76 | |
| 77 | if (security::isAdminView() || $validation["method"] == validations::METHOD_SIMPLE || ($validation["method"] == validations::METHOD_AUTOVALIDATION && $validation["attestation"]["user"] == people::userData("id"))) return $ipAddress; |
| 78 | |
| 79 | return "oculta (solo visible para los administradores)"; |
| 80 | } |
| 81 | |
| 82 | public static function renderValidationInfo($validation) { |
| 83 | ?> |
| 84 | <li><b>Validada por el trabajador:</b></li> |
| 85 | <ul> |
| 86 | <li><b>Método de validación:</b> <?=security::htmlsafe(validations::$methodName[$validation["method"]])?></li> |
| 87 | <li><b>Fecha de validación:</b> <?=security::htmlsafe(date("d/m/Y H:i", $validation["timestamp"]))?></li> |
| 88 | <?php |
| 89 | switch ($validation["method"]) { |
| 90 | case validations::METHOD_SIMPLE: |
| 91 | echo "<li><b>Dirección IP:</b> ".security::htmlsafe(self::noPIIIpAddress($validation))."</li>"; |
| 92 | break; |
| 93 | |
| 94 | case validations::METHOD_AUTOVALIDATION: |
| 95 | echo "<li><b>Dirección IP:</b> ".security::htmlsafe(self::noPIIIpAddress($validation))."</li>"; |
| 96 | echo "<li><b>Persona que autovalida la incidencia:</b> ".security::htmlsafe(people::userData("name", $validation["attestation"]["user"]))."</li>"; |
| 97 | break; |
| 98 | |
| 99 | default: |
| 100 | } |
| 101 | ?> |
| 102 | </ul> |
| 103 | <?php |
| 104 | } |
| 105 | } |