<?php
// --------
// Sécurité
// --------
if (isValidConstant() != 1) {
    fermeSessionUtilisateur();
}

// ----------------------
// Droit de l'utilisateur
// ----------------------
if ($_SESSION['gestion_site'] < 'Oui') {
    exit;
}

// ------------------------------
// Caractéristiques du module
// ------------------------------
unset($module);
$module = array(
    "titre" => "Générateur de rapports",
    "urldest" => $SCRIPT_NAME . "?page=generateur_rapports",
    "recherche" => array("engin" => false),
    "jeton" => $jeton,
    "compte" => 0
);
?>
<script type="text/javascript">

    $(document).ready(function () {
        $('#datedebut').datepicker({
            onSelect: function () {
                activeBoutonDateFin();
            },
            showOn: "x", // Hack pour ne pas permettre l'affichage immédiat du calendrier
            changeYear: true
        });
        $("#datefin").datepicker({showOn: "x", changeYear: true});
        $("#frmModif").validate();
    });

    function activeBoutonDateDebut() {
        $('#datedebut').datepicker('show');
    }

    function activeBoutonDateFin(reset) {
        if ((document.getElementById("optiondate").selectedIndex === 4 && $("#datedebut").val() !== "") && !reset) {
            $("#datefin").removeAttr("readonly");
            var dateactuelle = creerDate($("#datedebut").val());
            if (dateactuelle.getMonth() + 1 < 10)
                var mois = "0" + (dateactuelle.getMonth() + 1);
            else
                var mois = (dateactuelle.getMonth() + 1);
            if (dateactuelle.getDate() + 1 < 10)
                var jour = "0" + (dateactuelle.getDate() + 1);
            else
                var jour = (dateactuelle.getDate() + 1);
            $("#datefin").val(dateactuelle.getFullYear() + "-" + mois + "-" + jour);
            $("#datefin").datepicker("show");
        } else {
            $("#datefin").attr("readonly", "readonly");
            $("#datefin").val("");
            $("#datefin").datepicker("hide");
        }
    }

    function estEmployeurSelectionne(rapport, car) {
        var ctl = document.menu2.ListeEmployeurs;
        if (ctl.selectedIndex > 0) {
            ouvrefenetre(rapport + car + obtientValeurs(document.menu2), 1000);
        } else {
            jAlert("Veuillez sélectionné un employeur!", "Employeur manquant");
        }
    }
</script>
<?php
print preparerModule($module);
?>
<form name="menu2" id="menu2" action="">
    <table border="0" width="100%">
        <tbody>
            <tr>
                <td>
                    <table align="center" border="0">
                        <tbody>
                            <tr>
                                <td class="Style0" style="height: 2cm; width: 10cm;"> Rapports avec paramètres </td>
                                <td>&nbsp;</td>
                                <td>
                                </td>
                            </tr>
                            <tr>
                                <td><input class="Style1" value="Liste des libérations" style="height: 1cm; width: 8.5cm; font-size: 12pt;" type="button"
                                           onclick="ouvrefenetre('rapport_liberations.php?jeton=<?= $jeton; ?>&' + obtientValeurs(document.menu2), 600);"></td>
                                <td style="font-size: 12pt;"> Relation :</td>
                                <td>
                                    <fieldset id="CadreA" style="font-size: 12pt;">
                                        <?php
                                        if ($_SESSION['gestion_site'] >= 'Oui') {
                                            print "<label> <input value='1' id='radio1' name='relation' type='radio'  onclick=\"requestEmploye('1',document.getElementById('ListeEmployeurs').value, '$jeton');\"> Aucune relation </label>\n";
                                            print "<label> <input value='2' id='radio2' checked name='relation' type='radio' onclick=\"requestEmploye('2',document.getElementById('ListeEmployeurs').value, '$jeton');\"> Employés par employeur </label>\n";
                                        } else {
                                            print "<label> <input value='2' id='radio2' name='relation' type='radio' checked> Employés par employeur </label>\n";
                                        }
                                        ?>
                                    </fieldset>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <?php
                                    if ($_SESSION['gestion_site'] >= 'Oui') {
                                        print "<input class=\"Style1\" value=\"Liste des employés par employeur\" style=\"height: 1cm; width: 8.5cm; font-size: 12pt;\" type=\"button\"";
                                        print "onclick=\"estEmployeurSelectionne('rapport_employes_employeur.php','?jeton=$jeton?>&');\">\n";
                                    } else {
                                        print "<input class=\"Style1\" value=\"Compilation de documents\" style=\"height: 1cm; width: 8.5cm; font-size: 12pt;\" type=\"button\"";
                                        print "onclick=\"ouvrefenetre('index2.php?page=compilation_documents&jeton=$jeton'+obtientValeurs(document.menu2),600);\">\n";
                                    }
                                    ?>
                                </td>
                                <td style="font-size: 12pt;">
                                    Employeur :
                                </td>
                                <td>
                                    <?php
                                    $condition = "";
                                    // Liste des employeurs
                                    unset($result2);
                                    $result2 = getEmployeurs($_SESSION["gestion_site"]);
                                    unset($param);
                                    $param["form"] = "menu2";
                                    $param["nom"] = "ListeEmployeurs";
                                    $param["etq"] = "";
                                    if ($_SESSION['gestion_site'] >= 'Oui') {
                                        $param["defaut"] = -1;
                                    } else {
                                        $param["defaut"] = $_SESSION["employeur"];
                                    }
                                    $param["donnees"] = $result2;
                                    $param["menu"] = true;
                                    if ($_SESSION["gestion_site"] == "Oui") {
                                        $param["evt"] = "onchange=\"requestEmploye(getCheckedValue(document.forms['menu2'].elements['relation']),this.value,'$jeton');\"";
                                    } else {
                                        $param["evt"] = " ";
                                    }
                                    print formListbox2($param);
                                    ?>
                                </td>
                            </tr>
                            <tr>
                                <?php
                                if ($_SESSION['gestion_site'] >= 'Oui') {
                                    ?>
                                    <td>
                                        <input class="Style1" value="Liste des libérations selon le paiement" style="height: 1cm; width: 8.5cm; font-size: 12pt;" type="button"
                                               onclick="ouvrefenetre('rapport_liberations_paiement.php?' + obtientValeurs(document.menu2), 600);">
                                    </td>
                                    <?php
                                } else {
                                    print "<td></td>\n";
                                }
                                ?>
                                <td style="font-size: 12pt;">
                                    Employé :
                                </td>
                                <td>
                                    <?php
                                    unset($result2);
                                    $result2 = getEmployes($_SESSION["employeur"], "gestion_site", true);
                                    unset($param);
                                    $param["form"] = "menu2";
                                    $param["nom"] = "ListeEmployes";
                                    $param["etq"] = "";
                                    $param["defaut"] = -1;
                                    $param["donnees"] = $result2;
                                    $param["menu"] = true;
                                    $param["evt"] = " ";
                                    print formListbox2($param);
                                    ?>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <?php
                                    if ($_SESSION['gestion_site'] >= 'Oui') {
                                        print "<input class=\"Style1\" value=\"Compilation de documents\" style=\"height: 1cm; width: 8.5cm; font-size: 12pt;\" type=\"button\"";
                                        print "onclick=\"ouvrefenetre('index2.php?page=compilation_documents&jeton=$jeton'+obtientValeurs(document.menu2),600);\">\n";
                                    }
                                    ?>
                                </td>

                                <td rowspan="2" valign='top' style="font-size: 12pt;">Article :</td>
                                <td rowspan="2">
                                    <select name='ListeArticles' id='ListeArticles' class='Style12' style='width: 8.6cm;' size='4' multiple='multiple'>
                                        <option>--------------------</option>
                                        <?php
                                        unset($sqlparam);
                                        $sqlparam["table"][] = "articles";
                                        $sqlparam["champs"][] = "refarticle";
                                        $sqlparam["champs"][] = "noarticle";
                                        $sqlparam["ordre"][] = "length(noarticle)";
                                        $sqlparam["ordre"][] = "noarticle";
                                        unset($resultart);
                                        $resultart = executerRequeteSql($sqlparam);
                                        foreach ($resultart as $clef => $champs) {
                                            print "<option value='" . $champs["refarticle"] . "'>" . $champs["noarticle"] . "</option>";
                                        }
                                        ?>
                                    </select>
                                </td>
                            </tr>
                            <tr>
                                <?php
                                if ($_SESSION['gestion_site'] >= 'Oui') {
                                    ?>
                                    <td>
                                        <input class="Style1" value="Compilation du solde" style="height: 1cm; width: 8.5cm; font-size: 12pt;" type="button"
                                               onclick="estEmployeurSelectionne('index2.php?page=compilation_soldes&jeton=<?php print $jeton; ?>&tag=N', '');">
                                    </td>
                                    <?php
                                } else {
                                    print "<td></td>\n";
                                }
                                ?>
                            </tr>

                            <tr>
                                <td>&nbsp;
                                </td>
                                <td style="font-size: 12pt;">Date de début :</td>
                                <td>
                                    <input name="datedebut" size="10" maxlength="10" style="height: 0.5cm; width: 3.463cm;" type="text" id="datedebut" class="date">
                                    <img alt="Calendrier"  src="images/calendar.gif" class="calendrier" id="butdatedebut" onclick="activeBoutonDateDebut();" >
                                    <select name="optiondate" style="width:72px;" id="optiondate" size="1" onchange="activeBoutonDateFin();">
                                        <option value="0">-----</option>
                                        <option value="1">Égale</option>
                                        <option value="2">Inférieure</option>
                                        <option value="3">Supérieure</option>
                                        <option value="4">Entre</option>
                                    </select>

                                </td>
                            </tr>
                            <tr>
                                <td> &nbsp;

                                </td>
                                <td style="font-size: 12pt;">Date de fin :</td>
                                <td>
                                    <input name="datefin" size="10" maxlength="10" style="height: 0.5cm; width: 3.463cm;" type="text" id="datefin" readonly="readonly" class="date">
                                    <img alt="Calendrier"  src="images/calendar.gif" class="calendrier" id="butdatefin" onclick="activeBoutonDateFin();" disabled="disabled">
                                </td>
                            </tr>
                            <?php
                            if ($_SESSION['gestion_site'] >= 'Oui') {
                                ?>
                                <tr>
                                    <td class="Style0" style="height: 1.5cm; width: 6.412cm;">
                                        États instantanés
                                    </td>
                                    <td style="font-size: 12pt;">Commentaire :</td>
                                    <td>
                                        <input name="Commentaire" size="20" maxlength="20" style="height: 0.5cm; width: 8.5cm;" type="text" id="commentaire">
                                    </td>
                                </tr>
                                <tr>
                                    <td class="Style0" style="height: 2cm; width: 6.412cm;">
                                        <input class="Style1" value="Liste des membres du CA" style="height: 1cm; width: 8.5cm; font-size: 12pt;" type="button" onclick="ouvrefenetre('rapport_membre_ca.php', 600);">
                                    </td>
                                    <td style="font-size: 12pt;">Assumée par :</td>
                                    <td>
                                        <fieldset id="CadreB" style="width: 7.9cm;font-size: 12pt;">
                                            <label> <input value="1" name="Assumerpar" type="radio"> Syndicat</label>
                                            <label> <input value="2" name="Assumerpar" type="radio"> Employeur </label>
                                        </fieldset>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        <input class="Style1" value="Liste des employés par ordre croissant" style="height: 1cm; width: 8.5cm; font-size: 12pt;" type="button" onclick="ouvrefenetre('rapport_employes_croissant.php', 600);">
                                    </td>
                                    <td style="font-size: 12pt;">Paiement :</td>
                                    <td>
                                        <fieldset id="CadreC" style="width: 7.9cm;font-size: 12pt;">
                                            <label> <input value="1" name="Paiement" type="radio"> Payées</label>
                                            <label> <input value="2" name="Paiement" type="radio"> À payer </label>
                                        </fieldset>
                                    </td>
                                </tr>
                                <?php
                            }
                            ?>
                            <tr>
                                <td>
                                    &nbsp;
                                </td>
                                <td>&nbsp;</td>
                                <td>
                                    <input value="Effacer" class="Style1" style="height: 1cm; width: 8.6cm; font-size: 12pt;" type="reset" onclick="activeBoutonDateFin(true);
                                            $('#radio1').focus();
                                           <?php
                                           if ($_SESSION["gestion_site"] == "Oui") {
                                               print "requestEmploye('1',document.getElementById('ListeEmployeurs').value, '$jeton');";
                                           }
                                           ?>">
                                </td>
                            </tr>
                        </tbody>
                    </table>
                </td>
            </tr>
        </tbody>
    </table>
</form>
<SCRIPT type="text/javascript">
                                        function requestEmploye(valeur, prm1, jeton) {
                                            switch (valeur) {
                                                case "":
                                                case "1":
                                                    $("#ListeEmployes").load("obtemploye3.php", {prm1: -1, jeton : jeton});
                                                    break;
                                                case "2":
                                                    $("#ListeEmployes").load("obtemploye3.php", {prm1: prm1, jeton : jeton});
                                                    break;
                                            }
                                        }
</SCRIPT>