<?php
    include ('cabecera.php');
    include ('menu.php');

    include ('database.php');

    // obtener la lista de héroes
    $query = "SELECT * FROM heroes";
    $args  = array();
    $rslt  = $pdo->prepare($query);
    $rslt->execute($args);

    // obtener la lista de películas
    $query = "SELECT movie FROM appearances GROUP BY movie";
    $args  = array();
    $mrslt = $pdo->prepare($query);
    $mrslt->execute($args);
?>
    <main>
        <form name="add_hero" action="process_form.php">
            <ul>
                <li>
                    <label for="alias">Alias:</label>
                    <input type="text" name="alias" size="30" maxlength="50" hint="Iron Man">
                </li>
                <li>
                    <label for="identidad">Identidad:</label>
                    <input type="text" name="identidad" size="30" maxlength="50" hint="Tony Stark">
                </li>
                <li>
                    <label for="lado">Lado:</label>
                    <input type="radio" name="lado" value="Heroe" checked="checked"> Heroe<br>
                    <input type="radio" name="lado" value="Villano"> Villano
                </li>                    <li>
                    <label for="año">Primera Aparición:</label>
                    <input type="number" name="año">
                </li>                    <li>
                    <label for="power">Fuente de poder:</label>
                    <select name="power">
                        <option value="skill">Habilidad</option>
                        <option value="bio">Biológica</option>
                        <option value="magic">Magia</option>
                        <option value="tech">Tecnología</option>
                        <option value="mutant">Mutante</option>
                    </select>
                </li>
            </ul>
            <input type="submit" name="submit" value="Añadir Héroe">
            <!-- <p>Elige a tu héroe.</p>
            <button type="submit" name="name" value="Loki"></button>
            <button type="submit" name="name" value="Hulk"></button> -->
        </form>
        <form name="add_appearance" action="process_form.php">
            <ul>
                <li>
                    <label>Hero</label>
                    <select name="hero">
<?php
// display list of heroes
while($row = $rslt->fetch()) {
?>
                        <option value="<?php echo $row['alias']; ?>"><?php echo $row['alias']; ?></option>
<?php
}
?>
                    </select>
                </li>
                <li>
                    <label for="movie">Pelicula</label>
                    <ul>
<?php
    // display list of movies
    while($row = $mrslt->fetch()) {
?>
                        <li><input type="checkbox" name="movie[]" value="<?php echo $row['movie']; ?>" id=""> <?php echo $row['movie']; ?></li>
<?php
    }
?>
                        <li><input type="checkbox" name="movie[]" value="new" id=""> <input type="text" name="new_movie"></li>
                    </ul>
                </li>
                <input type="submit" name="submit" value="Add Appearance">
            </ul>
        </form>
        <!-- <ol>
            <li><a href="process_form.php?name=Loki">Loki</a></li>
            <li><a href="process_form.php?name=Hulk">Hulk</a></li>
        </ol> -->
    </main>
<?php
    include ('pie.php');
?>