<?php
/****************************************************************************************
 * SMI (Services Maintenance Interventions) est une gestion libre de maintenance et de SAV
 *
 * Version 1.0.0
 *
 * Copyright (C) 2006-2014  Sylvain FATOME
 * This program is free software; you can redistribute it and/or modify it under the terms
 * of the GNU General Public License as published by the Free Software Foundation;
 * either version 2 of the License, or (at your option) 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with this program
 * (in the directory docs);
 * if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA  02110-1301, USA.
 *
 * Contact : galawa@free.fr
 *
 * Web : http://smi.no-ip.org
 ****************************************************************************************/


// Vérification des tentatives de hack
$pos = strpos($_SERVER['PHP_SELF'], "inc.php");
if ($pos === FALSE)
    $ok_inc = TRUE;
else
    $ok_inc = FALSE;
if ($ok_inc == FALSE) header("Location: ../index.php");

// Variables Formulaire
fix_magic_quotes();
// $_GET = clean_str($_GET);
?>
<br />
<!--- Formulaire de Recherche -->
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="GET" name="formr" id="formr">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
    <td nowrap width="40%">
        <input type="text" name="search" id="search"  value="<?php echo @$_GET['search']; ?>" class="searchBox">
        <input type="hidden" name="page" id="page" value="1">
        <input type="hidden" name="ntab" id="ntab" value="<?PHP echo $ntab; ?>">
        <?PHP
        switch ($_SESSION["typ_filtres"]) {
            case "int" :
                if (@$_GET['ta'] <> "i") {
                    echo ' <img src="../img/rech_add.png" id="rech_more" border="0" align="absmiddle" title="'._("Critères supplémentaires").'" alt="' . _("Critères supplémentaires") . '">';

                    echo '<div id="rech_etendue"  style="display: none">';

                    echo '<div id="prm_rechet">';
                    echo '<div style="float:right;">';
                    echo '<img id="close_rech_etendue" src="../img/rech_close.png" border="0" align="absmiddle" title="'._("Fermer").'" alt="'._("Fermer").'">';
                    echo "</div>";
                    echo _("Critères supplémentaires");
                    echo '<table class="MtableR" border="0" width="100%" cellpadding="0" cellspacing="0">';
                    echo '<th>' . _("Sur dates") . '</th>';
                    echo '<th>' . _("Sup. ou égal à") . '</th>';
                    echo '<th>' . _("Inf.ou égal à") . '</th>';
                    echo '<tr>';
                    echo '<td align="right" width="50">' . _("Date demande") . '</td>';
                    echo '<td align="center">';
                    echo '<input name="dateddef1" type="text" id="dateddef1" value="' . $dateddef1 . '" size="10" maxlength="10" readonly="1">';
                    echo ' <img src="../img/raz.png" id="razdateddef1" border="0" align="absmiddle">';
                    echo '</td>';
                    echo '<td align="center">';
                    echo '<input name="dateddef2" type="text" id="dateddef2" value="' . $dateddef2 . '" size="10" maxlength="10" readonly="1">';
                    echo ' <img src="../img/raz.png" id="razdateddef2" border="0" align="absmiddle">';
                    echo '</td>';
                    echo '</tr>';
                    echo '<tr>';
                    echo '<td align="right">' . _("Date fin prévue") . '</td>';
                    echo '<td align="center">';
                    echo '<input name="dateddefp1" type="text" id="dateddefp1" value="' . $dateddefp1 . '" size="10" maxlength="10" readonly="1">';
                    echo ' <img src="../img/raz.png" id="razdateddefp1" border="0" align="absmiddle">';
                    echo '</td>';
                    echo '<td align="center">';
                    echo '<input name="dateddefp2" type="text" id="dateddefp2" value="' . $dateddefp2 . '" size="10" maxlength="10" readonly="1">';
                    echo ' <img src="../img/raz.png" id="razdateddefp2" border="0" align="absmiddle">';
                    echo '</td>';
                    echo '</tr>';
                    echo '</table>';

                    echo '<table class="MtableR" border="0" width="100%" cellpadding="0" cellspacing="0">';
                    echo '<th>' . _("Divers") . '</th>';
                    echo '<th>' . _("Sélectionner") . '</th>';
                    // Filtre sur catégories
                    echo '<tr>';
                    echo '<td align="right">' . _("Catégories") . '</td>';
                    echo '<td align="center">';

                    $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);

                    echo ' <select class="annot_petit" name="cat" size="1" id="cat">';
                    echo '<option value="" class="annot_petit" ';
                    if ($cat == "")
                        echo 'selected';
                    echo '>&#187; '._("Toutes les catégories").' &#171;</option>';
                    $rechform = "SELECT * FROM `" . TBINTC . "` ORDER BY intc_desc";
                    $rowsform = $db->get_results($rechform, ARRAY_A);
                    if ($rowsform) {
                        foreach ($rowsform as $rowform) {
                            extract($rowform);
                            echo '<option value="' . $intc_code . '"';
                            if ($cat == $intc_code)
                                echo ' selected';
                            echo '>' . $intc_desc . '</option>';
                        }
                    }
                    echo '</select>';

                    echo '</td>';
                    echo '</tr>';

                    // Filtre sur niveaux d'urgence
                    echo '<tr>';
                    echo '<td align="right">'._("Niv. urgence").'</td>';
                    echo '<td align="center" colspan="2">';
                    echo ' <select class="annot_petit" name="urg" size="1" id="urg">';
                    echo '<option value="" class="annot_petit"';
                    if ($urg == "")
                        echo ' selected';
                    echo '>&#187; '._("Niveau d'urgence").' &#171;</option>';
                    $rechurg = "SELECT * FROM `" . TBURG . "` ORDER BY urg_des";
                    $rowsurg = $db->get_results($rech, ARRAY_A);

                    if ($rowsurg) {
                        foreach ($rowsurg as $rowurg) {
                            extract($rowurg);
                            echo '<option value="' . $urg_niveau . '"';
                            if ($urg == $urg_niveau)
                                echo ' selected';
                            echo '>' . $urg_des . '</option>';
                        }
                    }
                    echo '</select>';

                    $db->disconnect();
                    echo '</td>';
                    echo '</tr>';
                    echo '</table>';
                    echo ' <input name="valid_compl" type="button" class="bton_search" id="valid_compl" value="'._("Lancer recherche").'">';
                    echo '</div>';

                    echo '</div>';
                }
                break;
            default :
                break;
        }
        echo '<img src="../img/rech_init.png" border="0" align="absmiddle" title="'._("Annuler").'" alt="'._("Annuler").'" id="cancel_rech">';
        echo ' <input name="lst_valid" type="button" class="bton_search" id="lst_valid" value="'._("Lancer recherche").'">';

        foreach ($_GET as $key => $value) {
            if (($key <> "ntab") && ($key <> "search") && ($key <> "fi") && ($key <> "page") && ($key <> "cat") && ($key <> "urg") && ($key <> "dateddef1") && ($key <> "dateddef2") && ($key <> "dateddefp1") && ($key <> "dateddefp2") && ($key <> "init"))
                echo '<input type="hidden" name="' . $key . '" id="' . $key . '" value="' . $value . '">';

        }
        if ($lst_villes == TRUE)
            echo '<div class="annot_petit_it">'._("Merci de saisir au moins 4 lettres").'</div>';
        ?>
    </td>
    <td nowrap align="center" width="20%">
        <?PHP
        cre_falselnk('lst_reload', 'lst_reload', 'span', '', _("Rafraîchir l'affichage"), '', '../img/reload.png', _("Rafraîchir l'affichage"));
        /* <a href="javascript:;" onclick="self.location.reload();"><img src="../img/reload.png"
                                                                      title="<?PHP echo _("Rafraîchir l'affichage"); ?>" border="0"
                                                                      align="absmiddle"> <?PHP echo _("Rafraîchir l'affichage"); ?></a> */
        ?>
    </td>
    <td nowrap align="right">
        <?PHP
        if (@$_GET['ta'] <> "i") {
            $imp_ok = false;
            if ($fic_imp <> "") {
                if (url_ok($fic_imp, TRUE) == TRUE) {
                    $urlimp = $fic_imp;
                    if ($_SERVER['QUERY_STRING'] <> '')
                        $urlimp .= "?" . $_SERVER['QUERY_STRING'];
                    cre_falselnk('imprim', 'imprim', 'span', 'right', _("Imprimer"), $urlimp, '../img/print.png', _("Imprimer"));
                    $imp_ok = TRUE;
                }
            }

            if ($fic_exp == TRUE) {
                if ($imp_ok == true)
                    echo ' - ';
                echo '<span id="fic_exp">';
                echo '<img src="../img/export.png" title="'._("Exporter").'" border="0" align="absmiddle">';
                echo ' '._("Exporter");
                echo '</span>';
            }

            $add_ok = false;
            if ($url_add <> "") {
                if (url_ok($url_add, TRUE) == TRUE) {
                    if (($imp_ok == true) OR ($fic_exp == true))
                        echo ' - ';
                    echo ' <a href="' . $url_add . '"><img src="../img/add.png" title ="'._("Ajouter enregistrement").'" border="0" align="absmiddle"> '._("Ajouter").'</a>';
                    $add_ok = true;
                }
            }

            if (($imp_ok == false) AND ($fic_exp == false) AND ($add_ok == false))
                echo "&nbsp;";
        } else
            echo "&nbsp;";
        ?>
    </td>
</tr>
<tr>
    <td nowrap style="padding-top:5px;">
        <?PHP
        if (count($tab_fi) > 0) {
            echo '<img src="../img/filtre.png" border="0" align="absmiddle" title="'._("Filtrer").'">';
            echo ' <select class="annot_petit" name="fi" size="1" id="fi" onChange="javascript:; fen_lst_filtre(this.id,' . intval(tab_key_value($tab_fi, end($tab_fi))) . ');">';
            echo '<option value="-1" class="annot_petit" ';
            if ($fi == -1) echo "selected";
            echo '>&#187; '._("Choisir filtre").' &#171;</option>';
            foreach ($tab_fi as $key => $value) {
                echo '<option value="' . $key . '" class="annot_petit"';
                if (($fi == $key) AND ($fi <> ""))
                    echo ' selected';
                echo '>';
                echo $value . "</option>";
            }
            echo '</select>';
        } else
            echo '&nbsp;';
        ?>
    </td>
    <td nowrap align="center" width="20%">
        <?PHP
        if (!empty($_GET['tri'])) {
            ?>
            <span class="annot_petit_it">
		<?PHP
        echo _("Actuellement trié sur") . ' ';
        echo $_GET['tri'];
        if ($_GET['ord'] == "ASC")
            echo ", " . _("ascendant");
        else
            echo ", " . _("descendant");
        ?>
		</span>
        <?PHP
        } else echo "&nbsp;";
        ?>
    </td>
    <td align="right" style="padding-top:5px;">
        <?PHP
        if ($url_rss <> "") {
            // On vérifie si le module rss est bien en place
            if (file_exists("../rss/rss.php")) {
                echo '<img src="../img/feed_add.png" title ="'._("S'abonner à un flux RSS").'" border="0" align="absmiddle"> ';
                echo '<select class="annot_petit" name="rss" size="1" id="rss"';
                echo ' onChange="javascript: var lnk=this.value; this.value=\'-1\'; if (document.all) {init_new_window(lnk,\'rss\',800,600,\'yes\');}else{document.location.href=lnk;}">';
                echo '<option value="-1" class="annot_petit" "selected">&#187; '._("Choisir le flux RSS").' &#171;</option>';
                // 15 derniers enregistrements
                echo '<option value="' . $url_rss . '&lst=15" class="annot_petit">';
                echo _("Les 15 derniers enregistrements").'</option>';
                // 30 derniers enregistrements
                echo '<option value="' . $url_rss . '&lst=30" class="annot_petit">';
                echo _("Les 30 derniers enregistrements").'</option>';
                // Cette semaine
                echo '<option value="' . $url_rss . '&week=1" class="annot_petit">';
                echo _("Les enregistrements de cette semaine").'</option>';
                // 15 derniers jours
                echo '<option value="' . $url_rss . '&nday=15" class="annot_petit">';
                echo _("Les enregistrements des 15 derniers jours").'</option>';
                // Cette semaine
                echo '<option value="' . $url_rss . '&nday=30" class="annot_petit">';
                echo _("Les enregistrements des 30 derniers jours").'</option>';
                echo '</select>';
            } else
                echo "&nbsp;";
        } else
            echo "&nbsp;";
        ?>
    </td>
</tr>
</table>
</form>
<!--- Fin du Formulaire de Recherche -->
