* @copyright 2010 Bartolomé Sintes Marco
* @license http://www.gnu.org/licenses/agpl.txt AGPL 3 or later
* @version 2010-03-25
* @link https://www.mclibre.org
*
* 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
* 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
\n"; print " \n"; print " \n"; print " \n"; print " \n"; print "
\n"; print " \n"; print "\n"; } print " \n"; print "\n"; print "\n"; } // Recoge el número de datos y lo valida, aumenta o reduce define("FORM_METHOD", "get"); define("TAM_VALOR", 5); define("NUM_VALORES_INICIAL", 4); define("NUM_VALORES_MINIMO", 2); define("NUM_VALORES_MAXIMO", 10); define("CON_ENLACE", true); define("SIN_ENLACE", false); define("CON_BOTONES", true); define("SIN_BOTONES", false); $valores = recoge("valores", []); $numeroValores = recoge("numeroValores"); if ($numeroValores < NUM_VALORES_MINIMO) { $numeroValores = NUM_VALORES_MINIMO; } elseif ($numeroValores > NUM_VALORES_MAXIMO) { $numeroValores = NUM_VALORES_MAXIMO; } if (isset($_REQUEST["anyadir"]) && ($numeroValores < NUM_VALORES_MAXIMO)) { $numeroValores++; $valores[$numeroValores] = ""; // Al añdir se crea un nuevo valor vacío } elseif (isset($_REQUEST["quitar"]) && ($numeroValores > NUM_VALORES_MINIMO)) { $numeroValores--; } $valoresOk = []; $valoresTodoOk = true; for ($i = 1; $i <= $numeroValores; $i++) { $valoresOk[$i] = true; if (!isset($valores[$i])) { // Por si falta un valor en la matriz $valoresTodoOk = false; $valores[$i] = ""; } elseif ($valores[$i] == "") { // Por si un valor es vacío $valoresTodoOk = false; } elseif ($valores[$i] != "" && !is_numeric($valores[$i])) { // Por si un valor no es numérico $valoresOk[$i] = false; $valoresTodoOk = false; } } $valoresTodoVacio = true; for ($i = 1; $i <= $numeroValores; $i++) { if ($valores[$i] != "") { $valoresTodoVacio = false; } } if ($valoresTodoOk) { cabecera("Resultado válido"); print"Los valores introducidos son correctos.
\n"; print "\n"; for ($i = 1; $i <= $numeroValores; $i++) { print "Valor $i: $valores[$i]
\n"; print "\n"; } pie(CON_ENLACE, SIN_BOTONES, $numeroValores); } elseif (!$valoresTodoVacio && (isset($_REQUEST["enviar"]) || isset($_REQUEST["anyadir"]) || isset($_REQUEST["quitar"]))) { cabecera("Resultado inválido"); print"Por favor, corrija los datos incorrectos y/o complete todas las casillas:
\n"; print "\n"; print "