blob: 2651bacc3657617cf38c5c81510f39ba2e1c46fb [file] [log] [blame]
<?php
/*
* hores
* Copyright (c) 2023 Adrià Vilanova Martínez
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with this program.
* If not, see http://www.gnu.org/licenses/.
*/
require_once("core.php");
security::checkType(security::ADMIN);
if (!security::checkParams("POST", [
["template", security::PARAM_ISINT],
["workers", security::PARAM_ISARRAY]
])) {
security::go("workers.php?msg=unexpected");
}
$template = (int)$_POST["template"];
$active = ((isset($_POST["active"]) && $_POST["active"] == 1) ? 1 : 0);
$mdHeaderRowBefore = visual::backBtn("workers.php");
?>
<!DOCTYPE html>
<html>
<head>
<title><?php echo $conf["appName"]; ?></title>
<?php visual::includeHead(); ?>
<link rel="stylesheet" href="css/dashboard.css">
</head>
<?php visual::printBodyTag(); ?>
<div class="mdl-layout mdl-js-layout mdl-layout--fixed-header mdl-layout--fixed-drawer">
<?php visual::includeNav(); ?>
<main class="mdl-layout__content">
<div class="page-content">
<div class="main mdl-shadow--4dp">
<h2>Resultado de la copia de plantilla</h2>
<?php
foreach ($_POST["workers"] as $workerid) {
$worker = workers::get($workerid);
if ($worker === false) continue;
$status = schedules::copyTemplate($template, $worker["id"], $active);
$person = "&ldquo;".security::htmlsafe($worker["name"])."&rdquo; (".security::htmlsafe($worker["companyname"]).")";
switch ($status) {
case 0:
echo "<p class='mdl-color-text--green'>Plantilla copiada correctamente a $person.";
break;
case 2:
echo "<p class='mdl-color-text--orange'>El horario de la plantilla se solapa con uno de los horarios de $person, así que no se ha copiado al trabajador.";
break;
case 1:
echo "<p class='mdl-color-text--red'>No se ha podido copiar la plantilla a $person porque la plantilla no existe.";
break;
case -1:
echo "<p class='mdl-color-text--red'>Se ha empezado a copiar la plantilla a $person pero no se han podido copiar todos los horarios de cada día correctamente por algún error desconocido.";
break;
default:
echo "<p class='mdl-color-text--red'>Ha ocurrido un error inesperado copiando la plantilla a $person.";
}
echo "</p>";
}
?>
</div>
</div>
</main>
</div>
</body>
</html>