<?php
/**
 * Capitales del mundo - preguntar2.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-28
 * @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/>.
 */

include('funciones.php');

$db = conectaDb();
cabecera('Preguntar 2', MENU_VOLVER);

$ciudad = recoge('ciudad');
$id     = recoge('id');

if ($id=='') {
    print "<p class=\"aviso\">No se ha seleccionado ningún registro.</p>\n";
} elseif ($ciudad=='') {
    print "<p class=\"aviso\">No se ha contestado la pregunta.</p>\n";
} else {
    $consulta = "SELECT COUNT(*) FROM $dbTabla 
       WHERE id=:id";
    $result = $db->prepare($consulta);
    $result->execute(array(':id' => $id));
    if (!$result) {
        print "<p class=\"aviso\">Error en la consulta.</p>\n";
    } elseif ($result->fetchColumn()==0) {
        print "<p class=\"aviso\">Registro no encontrado.</p>\n";
    } else {
        $consulta = "SELECT * FROM $dbTabla 
            WHERE id=:id";
        $result = $db->prepare($consulta);
        $result->execute(array(':id' => $id));
        $valor = $result->fetch();
        if ($ciudad==$valor['ciudad']) {
            print "<p>Respuesta correcta. $ciudad es la capital de $valor[pais]</p>\n";
        } else {
            print "<p>Respuesta incorrecta. $ciudad <strong>no</strong> es la capital de $valor[pais]</p>\n";
        }
    }
}

$db = NULL;
pie();
?>
