<?php
/**
 * Convertidor de unidades - anyadir1.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-08-31
 * @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();

$consulta = "SELECT COUNT(*) FROM $dbTabla";
$result = $db->query($consulta);
if (!$result) {
    cabecera('Añadir 1', MENU_2, CABECERA_SIN_CURSOR);
    print "<p>Error en la consulta.</p>\n";
} elseif ($result->fetchColumn()>=MAX_REG_TABLA) {
    cabecera('Añadir 1', MENU_2, CABECERA_SIN_CURSOR);
    print "<p>Se ha alcanzado el número máximo de conversiones que se pueden "
        ."guardar.</p>\n<p>Por favor, borre alguna conversión antes.</p>\n";
} else {
    cabecera('Añadir 1', MENU_2, CABECERA_CON_CURSOR);
    print "<form action=\"anyadir2.php\" method=\"".FORM_METHOD."\">
  <p>Escriba la conversión de unidades (por ejemplo 1 km = 1000 m):</p>
  <table>
    <tbody>
      <tr>
        <td><input type=\"text\" name=\"valor1\" size=\"$tamValor\" "
        ."maxlength=\"$tamValor\" id=\"cursor\" /></td>
        <td><input type=\"text\" name=\"unidad1\" size=\"$tamUnidad\" "
        ."maxlength=\"$tamUnidad\" /></td>
        <td>=</td> 
        <td><input type=\"text\" name=\"valor2\" size=\"$tamValor\" "
        ."maxlength=\"$tamValor\" id=\"cursor\" /></td>
        <td><input type=\"text\" name=\"unidad2\" size=\"$tamUnidad\" "
        ."maxlength=\"$tamUnidad\" /></td>
        </tr>
    </tbody>
  </table>
  <p><input type=\"submit\" value=\"Añadir\" /></p>
</form>\n";
}

$db = NULL; 
pie();
?>
