<h1 align="center"><?php echo __('em.eq.titre'); ?></h1>
<?php
$T_CLEAN = v('T_CLEAN', true);
$maj = v('maj');
if ($maj != '') {
    ?>
<div id="maj" class="alert alert-info" align="center"><?php echo $maj; ?></div>
<?php } ?>

<?php if (v('erreur')) { ?>
<div class="erreurs alert alert-error"><?php echo display_erreurs(); ?></div>
<?php } ?>


<?php

//Administrer une équipe

if (v('etat') > 0) {
    echo do_action('eqi_sel');


    if (p('rejoindre') == null) {
        ?>
    <div align="center">
        <form action="<?php echo php_self();?>" method="post">
            <input type="submit" class="btn btn-success" id="rejoindre" name="rejoindre"
                   value="<?php echo __('em.eq.join.autre'); ?>"/>
        </form>
    </div>
    <?php

    }
    if (v('choisir_equipe') === 1) {
        return;
    }


}

if (v('etat') == -1) {
    if (v('liste_equipe') == null || sizeof(v('liste_equipe')) == 0) {
        //rien
    } else { //Rejoindre une équipe ou créer la sienne
        ?>
    <form action="<?php echo php_self();?>" method="post" name="rejoindre_une_equipe" id="rejoindre_une_equipe">
        <?php echo ZAuth::get_fingerprint(); ?>
        <table align="center">
            <tr>
                <td colspan="2">
                    <h2><?php echo __('em.eq.join'); ?></h2>
                </td>
            </tr>
            <tr>
                <td><?php echo __('em.eq.choix'); ?></td>
                <td><select name="EQI_CLE">
                    <?php
                    foreach (decode(v('liste_equipe')) as $EQI_CLE => $T_EQI) {
                        ?>
                        <option value="<?php echo $EQI_CLE; ?>"><?php echo $T_EQI['EQI_NOM']; ?></option><?php

                    }
                    ?>
                </select>
                </td>
            </tr>
            <tr>
                <td><?php echo __('com.txt.mdp'); ?></td>
                <td><input type="password" name="EQI_PASS"/></td>
            </tr>
            <tr>
                <td colspan="2" align="right">
                    <input type="hidden" id="rejoindre" name="rejoindre" value="rejoindre"/>
                    <input type="submit" name="submit" class="btn btn-primary" value="Rejoindre"/></td>
            </tr>
        </table>
    </form>
    <?php } ?>



<form action="<?php echo php_self();?>" method="post" name="creer_une_equipe" id="creer_une_equipe">
    <?php echo ZAuth::get_fingerprint(); ?>
    <table align="center">
        <tr>
            <td colspan="2">
                <h2><?php echo __('em.eq.creer'); ?></h2>
            </td>
        </tr>

        <tr>
            <td><?php echo __('em.eq.nom'); ?></td>
            <td>
                <input type="text" name="EQI_NOM" maxlength="40"
                       value="<?php echo isset($T_CLEAN['EQI_NOM']) && $T_CLEAN['EQI_NOM'] != '' ? $T_CLEAN['EQI_NOM'] : ''; ?>"/>
                <?php echo get_perror('EQI_NOM'); ?>

            </td>
        </tr>
        <tr>
            <td><?php echo __('em.eq.tag'); ?></td>
            <td>
                <input type="text" name="EQI_TAG" maxlength="10"
                       value="<?php echo isset($T_CLEAN['EQI_TAG']) && $T_CLEAN['EQI_TAG'] != '' ? $T_CLEAN['EQI_TAG'] : ''; ?>"/>
                <?php echo get_perror('EQI_TAG'); ?>
            </td>
        </tr>
        <tr>
            <td><?php echo __('com.txt.mdp'); ?></td>
            <td>
                <input type="password" name="EQI_PASS"
                       value="<?php echo isset($T_CLEAN['EQI_PASS']) && $T_CLEAN['EQI_PASS'] != '' ? $T_CLEAN['EQI_PASS'] : '';; ?>"/>
                <?php echo get_perror('EQI_PASS'); ?>
            </td>
        </tr>
        <tr>
            <td><?php echo __('com.txt.confirm'); ?></td>
            <td>
                <input type="password" name="EQI_PASS2"
                       value="<?php echo isset($T_CLEAN['EQI_PASS2']) && $T_CLEAN['EQI_PASS2'] != '' ? $T_CLEAN['EQI_PASS2'] : '';; ?>"/>
                <?php echo get_perror('EQI_PASS2'); ?>
            </td>
        </tr>
        <tr>
            <td><?php echo __('com.txt.jeu'); ?></td>
            <td>
                <?php echo formSelect('EQI_JEU', null, v('tJeux')); ?>
                <?php echo get_perror('EQI_JEU'); ?>
            </td>
        </tr>
        <tr>
            <td colspan="2" align="right">
                <input type="hidden" id="rejoindre" name="rejoindre" value="rejoindre"/>
                <input type="submit" class="btn btn-primary" name="submit" value="Valider"/>
            </td>
        </tr>
    </table>
</form>
<?php

} else if (v('etat') == 9) {


    if (v('confirmation_suppression') == 1) {
        ?>
    <h2><?php echo __('em.eq.sup'); ?> (<?php echo p('EQI_NOM'); ?>)</h2>
    <p><?php echo __('em.eq.sup.txt'); ?></p>
    <form action="<?php echo php_self();?>" method="post" name="administrer_son_equipe" id="administrer_son_equipe">
        <?php echo ZAuth::get_fingerprint(); ?>
        <table class="nod" align="center">
            <?php
            if (v('erreur_conf')) {
                ?>
                <tr>
                    <td colspan="2" class="erreurs"
                        style="color: red; text-align: center"><?php echo v('erreur_conf'); ?></td>
                </tr>
                <?php } ?>
            <tr>
                <td class="g"><label><?php echo __('com.txt.mdp'); ?></label></td>
                <td class="d"><?php echo form('input', array('type' => 'text', 'maxlength' => 32, 'name' => 'confirmation')); ?></td>
            </tr>
            <tr>
                <td colspan="2" align="center">
                    <input type="submit" name="submit" class="btn btn-danger" value="<?php echo __('em.eq.sup.val'); ?>"
                           onclick="return confirm('<?php echo __('em.eq.sup.conf'); ?>');"/>
                </td>
            </tr>
        </table>
    </form>
    <?php

    } else {

        $T_REL_EQI_JOU = v('T_REL_EQI_JOU', true);
        ?>
    <h2 align="center"><?php echo __('em.eq.gerer'); ?> <?php echo zk_equipe(array('EQI_NOM' => p('EQI_NOM'), 'EQI_CLE' => p('EQI_CLE'), 'EQI_PAYS' => p('pays'),'EQI_LOGO'=>p('EQI_LOGO'))); ?></h2>


    <ul class="nav nav-tabs">
        <li class="active"><a href="#tab-equipe" data-toggle="tab"><?php echo __('em.eq.titre'); ?></a></li>
        <li><a href="#tab-joueurs" data-toggle="tab"><?php echo __('com.txt.roster'); ?></a></li>
        <li><a href="#tab-logo" data-toggle="tab"><?php echo __('com.txt.logo'); ?></a></li>
    </ul>

    <div class="tab-content">
        <div class="tab-pane active" id="tab-equipe">
            <form action="<?php echo php_self();?>" method="post" name="administrer_son_equipe"
                  id="administrer_son_equipe"
                  enctype="multipart/form-data">
                <?php echo ZAuth::get_fingerprint(); ?>
                <table align="center">
                    <tr>
                        <td class="g"><label><?php echo __('em.eq.nom'); ?> <font style="color:red">*</font></label>
                        </td>
                        <td class="d"><?php echo form('input', array('type' => 'text', 'maxlength' => 40, 'name' => 'EQI_NOM')); ?></td>

                    <tr>
                        <td class="g"><label><?php echo __('em.eq.tag'); ?> <font
                                style="color:red">*</font></label></td>
                        <td class="d"><?php echo form('input', array('type' => 'text', 'maxlength' => 10, 'name' => 'EQI_TAG')); ?></td>
                    </tr>
                    <tr>
                        <td class="g"><label><?php echo __('com.txt.mdp'); ?> <font
                                style="color:red">*</font></label></td>
                        <td class="d"><?php echo form('input', array('type' => 'text', 'maxlength' => 32, 'name' => 'EQI_PASS')); ?></td>
                    </tr>
                    <tr>
                        <td class="g"><label><?php echo __('com.txt.pays'); ?> <font
                                style="color:red">*</font></label></td>
                        <td class="d"><?php echo do_action('liste_pays'); ?></td>
                    </tr>
                    <?php $dis_jeu = OPT_FIGER_JEU === true && p('EQI_JEU') > 1 ? array('disabled', 'disabled') : MON_NULL;
                    ?>
                    <tr>
                        <td class="g"><label><?php echo __('com.txt.jeu'); ?> <font
                                style="color:red">*</font></label>
                        </td>
                        <td class="d"><?php echo formSelect('EQI_JEU', $dis_jeu, v('tJeux')); ?></td>
                    </tr>
                    <tr>
                        <td class="g"><label><?php echo __('com.txt.contact'); ?> <font
                                style="color:red">*</font></label>
                        </td>
                        <td class="d"><?php echo form('input', array('type' => 'text', 'maxlength' => 100, 'name' => 'EQI_CONTACT')); ?></td>
                    </tr>
                    <!--
                		<tr>
                			<td class="g"><label for="EQI_LOC"><?php echo __('com.txt.lieu'); ?></label></td>
                			<td class="d"><?php echo form('input', array('type' => 'text', 'maxlength' => 30, 'name' => 'EQI_LOC')); ?></td>
                		</tr>
                		-->
                    <tr>
                        <td class="g"><label><?php echo __('com.txt.url'); ?></label></td>
                        <td class="d"><?php echo form('input', array('type' => 'text', 'maxlength' => 100, 'name' => 'EQI_URL')); ?></td>
                    </tr>

                    <!--<tr>
                			<td class="g"><label for="EQI_LOGO"><?php echo __('com.txt.logo'); ?></label></td>
                			<td class="d"><?php echo form('input', array('type' => 'text', 'maxlength' => 100, 'name' => 'EQI_LOGO')); ?></td>
                		</tr>-->
                    <tr>
                        <td class="g"><label><?php echo __('com.txt.slogan'); ?></label></td>
                        <td class="d"><?php echo form('input', array('type' => 'text', 'maxlength' => 200, 'name' => 'EQI_SLOGAN')); ?></td>
                    </tr>
                    <tr>
                        <td class="g"><label><?php echo __('com.txt.desc'); ?></label></td>
                        <td class="d"><?php echo form('textarea', array('name' => 'EQI_DESC', 'id' => 'EQI_DESC')); ?></td>
                    </tr>
                    <tr>
                        <td class="g"><label><?php echo __('com.txt.date_insc'); ?></label></td>
                        <td class="d"><?php echo date_fr(p('EQI_DATE_INS')); ?></td>
                    </tr>

                    <tr>
                        <td colspan="2" align="center" style="padding: 10px;">
                            <input type="submit" class="btn btn-primary" name="submit"
                                   value="<?php echo __('com.action.mod'); ?>"/>
                            <input type="submit" class="btn btn-link" name="submit"
                                   value="<?php echo __('em.eq.sup_eq'); ?>"
                                   class="asHref"/>
                        </td>
                    </tr>
                </table>

            </form>
        </div>
        <!-- Fin onglet equipe -->
        <div class="tab-pane" id="tab-joueurs">
            <form action="<?php echo php_self();?>" method="post" name="administrer_son_equipe">
                <?php echo ZAuth::get_fingerprint(); ?>
                <table align="center">
                    <tr>
                        <td>#</td>
                        <td><?php echo __('com.txt.login'); ?></td>
                        <td><?php echo __('com.txt.poste'); ?></td>
                    </tr>

                    <?php
                    $T_JOU = v('T_JOU', true);

                    foreach ($T_JOU as $UN_JOU) {
                        ?>
                        <tr>
                            <td><?php echo $UN_JOU['JOU_CLE']; ?></td>
                            <td><?php echo href($UN_JOU['JOU_LOGIN'], array('controleur' => 'Profil', 'action' => 'Joueur', 'params' => $UN_JOU['JOU_LOGIN'] . '-' . $UN_JOU['JOU_CLE'])); ?></td>
                            <td><?php add_template('liste_postes', 'liste_postes_' . $UN_JOU['JOU_CLE'], 'JOU_POSTE',
                                array('JOU_POSTE' => $UN_JOU['JOU_POSTE'], 'JOU_CLE' => $UN_JOU['JOU_CLE']));

                                echo do_action('liste_postes_' . $UN_JOU['JOU_CLE']); ?>
                            </td>
                        </tr>

                        <?php

                    }
                    ?>
                    <tr>
                        <td colspan="2">
                            <input type="submit" name="submit" class="btn btn-primary" value="Enregistrer"/>
                        </td>
                    </tr>
                </table>
            </form>
        </div>
        <!-- Fin onglet joueurs -->
        <div class="tab-pane" id="tab-logo">
            <?php echo zk_aff_logo_eq(p('EQI_LOGO')); ?>

            <h2 align="center"><?php echo __('com.txt.logo'); ?></h2>

            <form action="<?php echo php_self();?>" method="post" name="administrer_son_equipe"
                  id="administrer_son_equipe"
                  enctype="multipart/form-data">
                <?php echo ZAuth::get_fingerprint(); ?>
                <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo POIDS_IMAGE; ?>"/>
                <?php echo form('input', array('type' => 'file', 'name' => 'UP_LOGO')); ?>
                <div class="supprim-logo"><input type="checkbox" name="DEL_AVATAR"
                                                 value="1"/> <?php echo __('em.eq.sup_avatar'); ?></div>
                <input type="submit" class="btn btn-primary" name="submit"
                       value="<?php echo __('com.action.val'); ?>"/>
            </form>
        </div>
        <!-- Fin onglet logo -->
    </div>

    <?php

    }

} else {
    //Quitter son équipe
    $T_REL_EQI_JOU = v('T_REL_EQI_JOU', true);
    ?>
<h2 align="center"><?php echo __('em.eq.titre'); ?></h2>
<table align="center" class="table" style="width: 300px !important">
    <thead>
    <tr>
        <th><?php echo __('em.eq.nom'); ?></th>
        <th>Action</th>
    </tr>
    </thead>
    <tr>
        <td><?php echo href($T_REL_EQI_JOU['EQI_NOM'], array('controleur' => 'Profil', 'action' => 'Equipe', 'params' => $T_REL_EQI_JOU['EQI_NOM'] . '-' . $T_REL_EQI_JOU['EQI_CLE'])); ?></td>
        <td>
            <form action="<?php echo php_self();?>" method="post" name="quitter_son_equipe" id="quitter_son_equipe">
                <?php echo ZAuth::get_fingerprint(); ?>
                <?php echo __('em.eq.quitter'); ?> <input onclick="return confirm('<?php echo __('com.txt.confirm.question'); ?>')" type="submit" name="submit" class="btn btn-danger" value="oui"/>
            </form>
        </td>
    </tr>
</table>

<?php

} ?>