<?php
defined('BASEPATH') OR exit('No direct script access allowed');
?>
<main>

</main>
<body>
<br>
<!-- Cambiar todos los echos de phpp para los referees
        Completar como en teams el mismo rpocedimiento
 -->

<div class="row">
    <div class="col s12 xl4 " >
        <div class="container ">
            <form method="post" action="<?php echo base_url() ?>referee/addReferee">
                <div class="row">
                    <span style="font-weight: bold"><?php echo $text_referee['referee_create_referee']; ?></span><br>
                    <span style="font-weight:bold"> <i class="material-icons">warning</i> <?php echo $text_referee['referee_not_empty_fields'];?></span>
                </div>
                <div class="row">
                    <div class="input-field col s12 xl12">
                        <i class="material-icons prefix">create</i>
                        <input class="validate" type="text" name="dni" id="dni" data-length="9" maxlength="9" minlength="9" required/>
                        <label for="nombre"><?php echo $text_referee['referee_dni']; ?>(*)</label>
                    </div>
                    <div class="input-field col s12 xl12">
                        <i class="material-icons prefix">create</i>
                        <input class="validate" type="text" name="nombre" data-length="30" id="nombre" required/>
                        <label for="nombre"><?php echo $text_referee['referee_name']; ?>(*)</label>
                    </div>
                </div>
                <div class="row">
                    <div class="input-field col s12 xl12">
                        <i class="material-icons prefix">create</i>
                        <input class="validate" type="text" name="primer_apellido" data-length="30" id="primer_apellido"
                               required/>
                        <label for="directorTecnico"><?php echo $text_referee['referee_surname']; ?>(*)</label>
                    </div>
                    <div class="input-field col s12 xl12">
                        <i class="material-icons prefix">create</i>
                        <input class="validate" type="text" name="segundo_apellido" data-length="30"
                               id="primer_apellido"/>
                        <label for="directorTecnico"><?php echo $text_referee['referee_second_surname']; ?></label>
                    </div>
                </div>
                <div class="row">
                    <div class="input-field col s12 xl12">
                        <i class="material-icons prefix">list</i>
                        <select name="idCategoriaArbitral" id="refereeCategoryID">
                            <option value="" disabled selected><?php echo $text_referee['referee_category']; ?>(*)</option>
                            <?php foreach ($referees_categories as $categorie) { ?>
                                <option value="<?php echo $categorie->idCategoriaArbitral; ?>"><?php echo $categorie->descripcion; ?></option>
                            <?php } ?>
                        </select>
                        <label><?php echo $text_referee['referee_category']; ?></label>
                    </div>
                    <div class="input-field col s12 xl12">
                        <i class="material-icons prefix">list</i>
                        <select name="paisISOA3">
                            <option value="" disabled selected><?php echo $text_referee['referee_country'];?></option>
                            <option value="ESP">España</option>
                            <option value="ALE">Francia</option>

                        </select>
                        <label><?php echo $text_referee['referee_country'];?></label>
                    </div>


                    <div class="input-field col s12 xl12">
                        <i class="material-icons prefix">create</i>
                        <input class="validate" type="text" name="autonomia" id="primer_apellido" data-length="30"/>
                        <label for="directorTecnico"><?php echo $text_referee['referee_autonomous_community']; ?></label>
                    </div>
                    <div class="input-field col s12 xl12">
                        <i class="material-icons prefix">create</i>
                        <input class="validate" type="text" name="provincia" id="primer_apellido" data-length="30"
                               required/>
                        <label for="directorTecnico"><?php echo $text_referee['referee_province']; ?>(*)</label>
                    </div>
                    <div class="input-field col s12 xl12">
                        <i class="material-icons prefix">create</i>
                        <input class="validate" type="text" name="email" data-length="30" id="email" />
                        <label for="autonomia"><?php echo $text_referee['referee_email']; ?></label>
                    </div>
                    <div class="col s6 offset-s6">
                        <button class="btn btn-large waves-effect indigo" onclick="return validateRequiredFields()"><?php echo $text_referee['referee_btn_create']; ?></button>
                    </div>
                </div>
            </form>
        </div>
    </div>


    <?php if ($referees != null) { ?>

        <div class="col s12 xl5">
            <div class="row z-depth-1 center indigo lighten-5">
                <span style="font-weight: bold"><?php echo $text_referee['referee_num_referees_info']?> </span> <br>
                <span style="font-weight: bold"> <?php echo $text_referee['referee_total_referees'] ?> : </span></spanç> <span style="font-weight: bold; color: #251e96;"> <?php echo $num_referees?></span>
            </div>
            <div class="row">
                <div class="col s3"><span style="font-weight: bold">  <?php echo $text_referee['referee_name']; ?></span>
                </div>
                <div class="col s3"><span
                            style="font-weight: bold"> <?php echo $text_referee['referee_surname']; ?></span></div>
                <div class="col s3"><span
                            style="font-weight: bold"><?php echo $text_referee['referee_second_surname']; ?></span>
                </div>
                <div class="col s3"><span
                            style="font-weight: bold"> <?php echo $text_referee['referee_category']; ?></span></div>

            </div>
            <ul class="collapsible " data-collapsible="accordion">
                <?php $count = 0; ?>
                <?php foreach ($referees as $row) { ?>
                    <li>
                        <?php $count++;
                        $class = $count % 2 != 0 ? 'grey lighten-2' : '';
                        ?>

                        <div class="collapsible-header <?php echo $class ?> ">
                            <div class="row">
                                <div class="col s3"> <?php echo $row->nombre ?></div>
                                <div class="col s3"> <?php echo $row->apellido1 ?></div>
                                <div class="col s3"> <?php echo $row->apellido2 ?></div>
                                <div class="col s3"> <?php echo $row->descripcion ?></div>

                            </div>

                        </div>
                        <div class="collapsible-body ">
                            <form method="post" action="<?php echo base_url() ?>referee/deleteReferee"
                                  onsubmit=" return confirm('Estas seguro de que quieres eliminar al arbitro?')">
                                <input type="hidden" name="dni" value="<?php echo $row->dni; ?>">
                                <div class="row">
                                    <div class="col s12 xl12">
                                        <span style="font-weight: bold"> <?php echo $text_referee['referee_email'] ?>
                                            : </span><?php echo $row->email ?>
                                    </div>
                                </div>

                                <div class="row">
                                    <div class="col s12 xl4">
                                        <span style="font-weight: bold">  <?php echo $text_referee['referee_country'] ?>
                                            : </span><?php echo $row->paisISOA3 ?>
                                    </div>
                                    <div class="col s12 xl4">
                                        <span style="font-weight: bold"> <?php echo $text_referee['referee_autonomous_community'] ?>
                                            : </span><?php echo $row->autonomia ?>
                                    </div>
                                    <div class="col s12 xl4">
                                        <span style="font-weight: bold">  <?php echo $text_referee['referee_province'] ?>
                                            : </span><?php echo $row->provincia ?>
                                    </div>
                                </div>
                                <hr>
                                <div class="row">
                                    <div class="col s12 xl6">

                                        <button style="width: 170px" id="delete_button"
                                                class="btn btn-neutral waves-effect red lighten-1"><?php echo $text_referee['referee_btn_delete']; ?>
                                            <i
                                                    class="material-icons right">delete</i></button>
                                    </div>


                                    <div class="col s12 xl6">
                                        <button onclick="return updateReferee(<?php echo $count ?>)"
                                                style="width: 170px" id="delete_button"
                                                class="btn btn-neutral waves-effect indigo"><?php echo $text_referee['referee_btn_update']; ?>
                                            <i class="material-icons right">edit</i></button>
                                    </div>
                                </div>

                            </form>
                        </div>

                    </li>
                    <div id="updateRefereeID<?php echo $count; ?>" class="modal ">
                        <form method="post" action="<?php echo base_url() ?>referee/updateReferee">
                            <div class="modal-content ">
                                <div class="container">

                                    <div>
                                        <span style="font-weight: bold"> <?php echo $text_referee['referee_update_referee']; ?></span>
                                    </div>
                                    <div class="row">
                                        <div class="input-field col s12 xl6">
                                            <i class="material-icons prefix">create</i>
                                            <input class="validate " type="text" name="dni" required disabled
                                                   value="<?php echo $row->dni; ?>"/>
                                            <label for="nombre"><?php echo $text_referee['referee_dni']; ?></label>
                                            <input type="hidden" name="dni" value="<?php echo $row->dni; ?>">
                                        </div>
                                        <div class="input-field col  s12 xl6">
                                            <i class="material-icons prefix">create</i>
                                            <input class="validate" type="text" name="nombre" required
                                                   value="<?php echo $row->nombre; ?>"/>
                                            <label for="directorTecnico"><?php echo $text_referee['referee_name']; ?></label>
                                        </div>
                                    </div>
                                    <div class="row">
                                        <div class="input-field col  s12 xl6">
                                            <i class="material-icons prefix">create</i>
                                            <input class="validate" type="text" name="apellido1" required
                                                   value="<?php echo $row->apellido1; ?>"/>
                                            <label for="directorTecnico"><?php echo $text_referee['referee_surname']; ?></label>
                                        </div>
                                        <div class="input-field col  s12 xl6">
                                            <i class="material-icons prefix">create</i>
                                            <input class="validate" type="text" name="apellido2" required
                                                   value="<?php echo $row->apellido2; ?>"/>
                                            <label for="directorTecnico"><?php echo $text_referee['referee_second_surname']; ?></label>
                                        </div>
                                    </div>
                                    <div class="row">
                                        <div class="input-field col  s12 xl6">
                                            <i class="material-icons prefix">list</i>
                                            <select name="idCategoriaArbitral">
                                                <option value="" disabled
                                                        selected><?php echo $text_referee['referee_category']; ?></option>
                                                <?php foreach ($referees_categories as $categorie) { ?>
                                                    <option value="<?php echo $categorie->idCategoriaArbitral; ?>" <?php if ($categorie->idCategoriaArbitral == $row->idCategoriaArbitral) echo "selected" ?>><?php echo $categorie->descripcion; ?></option>
                                                <?php } ?>
                                            </select>
                                            <label><?php echo $text_referee['referee_category']; ?></label>
                                        </div>
                                        <div class="input-field col  s12 xl6">
                                            <i class="material-icons prefix">list</i>
                                            <select name="paisISOA3">
                                                <option value="" disabled
                                                        selected><?php echo $text_referee['referee_country']; ?></option>
                                                <option value="ESP">España</option>
                                                <option value="ALE">Alemania</option>
                                                <option value="FRE">Francia</option>

                                            </select>
                                            <label><?php echo $text_referee['referee_country']; ?></label>
                                        </div>
                                        <div class="input-field col  s12 xl6">
                                            <i class="material-icons prefix">create</i>
                                            <input class="validate" type="text" name="autonomia" id="primer_apellido" required
                                                   value="<?php echo $row->autonomia; ?>"/>
                                            <label for="directorTecnico"><?php echo $text_referee['referee_autonomous_community']; ?></label>
                                        </div>
                                        <div class="input-field col  s12 xl6">
                                            <i class="material-icons prefix">create</i>
                                            <input class="validate" type="text" name="provincia" id="primer_apellido"
                                                   value="<?php echo $row->provincia; ?>"/>
                                            <label for="directorTecnico"><?php echo $text_referee['referee_province']; ?></label>
                                        </div>
                                        <div class="input-field col  s12 xl6">
                                            <i class="material-icons prefix ">create</i>
                                            <input class="validate" type="text" name="email" id="email"
                                                   value="<?php echo $row->email; ?>"/>
                                            <label for="autonomia"><?php echo $text_referee['referee_email']; ?></label>
                                        </div>

                                    </div>

                                </div>
                            </div>
                            <div class="modal-footer">
                                <button class="btn btn-large waves-effect indigo"><?php echo $text_referee['referee_btn_update']; ?></button>
                            </div>
                        </form>
                    </div>

                <?php } ?>
            </ul>
            <?php echo $this -> pagination -> create_links();?>
        </div>
    <?php } ?>
    <?php if ($referees == null) { ?>
        <div class="col s12 xl5">
            <span style="font-weight: bold"> <?php echo $text_referee['referee_not_exists_referees']; ?></span>
        </div>
    <?php } ?>
    <div class=" col xl3 s12">

        <?php $category_selected = isset($_GET['selectRefereeCategory']) ? $_GET['selectRefereeCategory'] : 0; ?>
        <form method="get" action="<?php echo base_url() ?>referee/search">
            <div class="input-field col s12 m4 l4" style="width: 250px">
                <select name="selectRefereeCategory" onchange="this.form.submit()">
                    <option value="" disabled selected><?php echo $text_referee['referee_category']; ?></option>
                    <option value="0" selected><?php echo $text_referee['referee_input_all']?></option>

                    <?php foreach ($referees_categories as $categorie) { ?>
                        <option <?php if ($categorie->idCategoriaArbitral == $category_selected) echo "selected" ?>

                                value="<?php echo $categorie->idCategoriaArbitral; ?>"><?php echo $categorie->descripcion; ?></option>
                    <?php } ?>
                </select>
                <label><?php echo $text_referee['referee_category']; ?></label>

            </div>


        </form>
    </div>
</div>
    <div id="modal-add-referee-category" class="modal modal-fixed-footer">
        <div class="modal-content">
            <h4><?php echo $text_referee['referee_exists_dni']; ?></h4>
            <p><?php echo $text_referee['referee_exists_text']; ?></p>
            <form class="row" method="post" action="<?php echo base_url() ?>referee/addRefereeCategory">
                <input type="hidden" name="dni"
                       value="<?php echo $this->session->has_userdata('dni_add_referee_category') ? $this->session->userdata('dni_add_referee_category') : null; ?>">
                <div class="col s6 offset-s3">
                    <select name="idRefereeCategory">
                        <option value="" disabled
                                selected><?php echo $text_referee['referee_category']; ?></option>
                        <?php foreach ($referees_categories as $categorie) { ?>

                            <option value="<?php echo $categorie->idCategoriaArbitral; ?>" <?php if ($categorie->idCategoriaArbitral == $row->idCategoriaArbitral) echo "selected" ?>><?php echo $categorie->descripcion; ?></option>
                        <?php } ?>
                        <label><?php echo $text_referee['referee_category']; ?></label>
                    </select>
                </div>


        </div>
        <div class="modal-footer">
            <button class="btn"> <?php echo $text_referee['referee_add_category']; ?></button>
        </div>
        </form>
    </div>

</div>
</body>

<script>
    function validateRequiredFields() {
        if ($('#refereeCategoryID').val() == null) {
            Materialize.toast("<?php echo $text_referee['referee_not_empty_referee_category']; ?>", 5000)
            return false;
        }
    }
</script>