<?php 
/**
 * Rectángulo de estrellas 2 - for_1_9.php
 * 
 * @author    Bartolomé Sintes Marco <bartolome.sintes+mclibre@gmail.com>
 * @copyright 2011 Bartolomé Sintes Marco
 * @license   http://www.gnu.org/licenses/agpl.txt AGPL 3 or later
 * @version   2011-11-15
 * @link      http://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 <http://www.gnu.org/licenses/>.
 */

print "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?".">\n"; 
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
       "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <title>Rectángulo de estrellas 2 (Resultado). for (1). Ejercicios. PHP. Bartolomé 
  Sintes Marco</title>
  <link href="mclibre_php_soluciones.css" rel="stylesheet" type="text/css" 
  title="Color" />
</head>
<body>

<h1>Rectángulo de estrellas 2 (Resultado)</h1>
<?php

function recoge($var)
{ 
    $tmp = (isset($_REQUEST[$var])) ? strip_tags(trim(htmlspecialchars($_REQUEST[$var]))) : '';
    if (get_magic_quotes_gpc()) {
        $tmp = stripslashes($tmp);
    }
    return $tmp;
}

$ancho       = recoge('ancho');
$alto        = recoge('alto');
$valorMinimo = 2;
$valorMaximo = 100;
$anchoOk     = FALSE;
$altoOk      = FALSE;

if ($ancho=="") {
    print "<p class=\"aviso\">No ha escrito la anchura.</p>\n";
} elseif (!ctype_digit($ancho)) { 
    print "<p class=\"aviso\">No ha escrito la anchura "
        ."como número entero positivo.</p>\n";
} elseif ($ancho<$valorMinimo || $ancho>$valorMaximo) {
    print "<p class=\"aviso\">La anchura debe estar entre $valorMinimo y $valorMaximo.</p>\n";
} else {
	$anchoOk = TRUE;
}

if ($alto=="") {
    print "<p class=\"aviso\">No ha escrito la altura.</p>\n";
} elseif (!ctype_digit($alto)) { 
    print "<p class=\"aviso\">No ha escrito la altura "
        ."como número entero positivo.</p>\n";
} elseif ($alto<$valorMinimo || $alto>$valorMaximo) {
    print "<p class=\"aviso\">La altura debe estar entre $valorMinimo y $valorMaximo.</p>\n";
} else {
	$altoOk = TRUE;
}

if ($altoOk && $anchoOk) {
    print "<p>Ancho: $ancho</p>";
    print "<p>Alto: $alto</p>";
    
    print "<pre>";
    for ($j = 1; $j<=$ancho; $j++) {
        print "* ";
    }
    print "\n";
    for ($i = 1; $i<=$alto-2; $i++) {
        print "* ";
        for ($j = 1; $j<=$ancho-2; $j++) {
            print "  ";
        }
        print "* ";
        print "\n";
    }
    for ($j = 1; $j<=$ancho; $j++) {
        print "* ";
    }
    print "\n";
    print "</pre>\n";
}

print "<p><a href=\"for_1_9.html\">Volver al formulario.</a></p>\n";
?>

<address>
  Esta página forma parte del curso "Páginas web con PHP" disponible en <a
  href="http://www.mclibre.org/">http://www.mclibre.org</a><br />
  Autor: Bartolomé Sintes Marco<br />
  Última modificación de esta página: 15 de noviembre de 2011
</address>
<p class="licencia">El programa PHP que genera esta página está bajo 
<a rel="license" href="http://www.gnu.org/licenses/agpl.txt">licencia AGPL 3 o
posterior</a>.</p>
</body>
</html>
