* @copyright 2008 Bartolomé Sintes Marco
* @license http://www.gnu.org/licenses/agpl.txt AGPL 3 or later
* @version 2008-02-10
* @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 .
*/
function cabecera($texto)
{
print "\n";
print "\n";
print "
\n";
print "\n";
}
function limpia($var)
{
return trim(strip_tags($var));
}
// Función de recogida de datos
function recoge($key, $type = "")
{
if (!is_string($key) && !is_int($key) || $key == "") {
trigger_error("Function recoge(): Argument #1 (\$key) must be a non-empty string or an integer", E_USER_ERROR);
} elseif ($type !== "" && $type !== []) {
trigger_error("Function recoge(): Argument #2 (\$type) is optional, but if provided, it must be an empty array or an empty string", E_USER_ERROR);
}
$tmp = $type;
if (isset($_REQUEST[$key])) {
if (!is_array($_REQUEST[$key]) && !is_array($type)) {
$tmp = trim(htmlspecialchars($_REQUEST[$key]));
} elseif (is_array($_REQUEST[$key]) && is_array($type)) {
$tmp = $_REQUEST[$key];
array_walk_recursive($tmp, function (&$value) {
$value = trim(htmlspecialchars($value));
});
}
}
return $tmp;
}
function recogeNumero($var, $inicial, $minimo, $maximo)
{
$tmp = recoge($var);
if (!is_numeric($tmp)) {
return $inicial;
}
if ($tmp < $minimo) {
return $minimo;
}
if ($tmp > $maximo) {
return $maximo;
}
return $tmp;
}
function recogeTexto($var, $inicial, $valores)
{
$tmp = recoge($var);
foreach ($valores as $valor) {
if ($tmp == $valor) {
return $tmp;
}
}
return $inicial;
}
// Recoge configuración de la gráfica
$tamanyoGraficaXInicial = 400;
$tamanyoGraficaXMinimo = 200;
$tamanyoGraficaXMaximo = 600;
$tamanyoGraficaX = recogeNumero(
"tamanyoGraficaX",
$tamanyoGraficaXInicial,
$tamanyoGraficaXMinimo,
$tamanyoGraficaXMaximo
);
$tamanyoGraficaYInicial = 200;
$tamanyoGraficaYMinimo = 100;
$tamanyoGraficaYMaximo = 300;
$tamanyoGraficaY = recogeNumero(
"tamanyoGraficaY",
$tamanyoGraficaYInicial,
$tamanyoGraficaYMinimo,
$tamanyoGraficaYMaximo
);
$tipoGrafica = "lc";
$tituloGrafica = recoge("tituloGrafica");
$unidadesEjeY = recoge("unidadesEjeY");
if (isset($_REQUEST[$unidadesEjeY])) {
$unidadesEjeY = "on";
}
// Recoge el número de datos y lo valida, aumenta o reduce
$numeroValoresInicial = 4;
$numeroValoresMinimo = 2;
$numeroValoresMaximo = 15;
$numeroValores = recogeNumero(
"numeroValores",
$numeroValoresInicial,
$numeroValoresMinimo,
$numeroValoresMaximo
);
if (isset($_REQUEST["anyadir"]) && ($numeroValores < $numeroValoresMaximo)) {
$numeroValores++;
} elseif (isset($_REQUEST["quitar"]) && ($numeroValores > $numeroValoresMinimo)) {
$numeroValores--;
}
// Recoge valores numéricos y los valida
$valores = recoge("valores", []);
// Esto es para cuando se añaden y quiten valores, que la matriz $valores
// tengo el número de elementos igual que $numeroValores
if (isset($valores[$numeroValores + 1])) {
unset($valores[$numeroValores + 1]);
}
if (isset($valores[$numeroValores - 1]) && !isset($valores[$numeroValores])) {
$valores[$numeroValores] = "";
}
$okValores = true;
for ($i = 1; $i < $numeroValores; $i++) {
if (!isset($valores[$i])) {
$okValores = false;
} elseif ($valores[$i] != "" && !is_numeric($valores[$i])) {
$okValores = false;
}
// Al hacer clic en Añadir el último valor todavía no existe
if (!isset($_REQUEST["anyadir"])) {
if (!isset($valores[$numeroValores])) {
$okValores = false;
} elseif ($valores[$i] != "" && !is_numeric($valores[$i])) {
$okValores = false;
}
}
}
// Si no se ha hecho clic en Enviar o los valores no son correctos
if (!isset($_REQUEST["enviar"]) || !$okValores) {
if (isset($_REQUEST["enviar"])) {
cabecera("Resultado inválido");
print"