<?php
/****************************************************************************************
 * SMI (Services Maintenance Interventions) est une gestion libre de maintenance et de SAV
 *
 * Version 1.0.4
 *
 * Copyright (C) 2006-2016  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) {
    header('Location: ../index.php');
}

include_once('../inc/func.inc.php');
include_once('../inc/func_date.inc.php');
include_once('../inc/func_geo.inc.php');
include_once('../inc/func_txt.inc.php');
include_once('../inc/fic_age.inc.php');
include_once('../inc/fic_cli.inc.php');
include_once('../inc/fic_cocl.inc.php');
include_once('../inc/fic_int.inc.php');
include_once('../inc/fic_ot.inc.php');
include_once('../inc/fic_droits.inc.php');
include_once('../inc/fic_prm.inc.php');
include_once('../inc/fic_statut.inc.php');
include_once('../inc/fic_tac.inc.php');
include_once('../inc/fic_tec.inc.php');
include_once('../inc/lst.inc.php');
include_once('../classes/ezSQL/shared/ez_sql_core.php');
include_once('../classes/ezSQL/mysqli/ez_sql_mysqli.php');
include_once('../inc/func_sql.inc.php');
Archivelog(valsession('code_log'));
$_SESSION['typ_filtres'] = 'ot';

// Variables Formulaire
fix_magic_quotes();
$_GET = clean_str($_GET);

$pbm_ot = FALSE;
$pbm_cli = FALSE;

$url_query = $_SERVER['QUERY_STRING'];
$tx = valget('tx'); // Source de l'appel m:depuis le menu, i:depuis l'intervention
$td = $_GET['td']; // Récupération type demande
$ca = $_GET['ca']; // Récupération code Agence gestionnaire du compte client
$cas = $_GET['cas']; // Récupération code Agence gestionnaire du site client
$cc = $_GET['cc']; // Récupération code Client
$ci = $_GET['ci']; // Récupération code Intervention
$si = $_GET['si']; // Récupération id du site
$tr = $_GET['tr']; // Récupération code technicien responsable
$co = $_GET['co']; // Récupération code contrat
$tl = 1;
if (isset($_GET['tl'])) {
    $tl = (int)$_GET['tl'];
} // Récupération type liste
if (($tl <> 1) AND ($tl <> 2)) {
    $tl = 1;
}
if (CheckNivLog('10-11')) {
    $tl = 1;
}

if (($tx <> 'm') AND ($tx <> 'i')) {
    $pbm_ot = TRUE;
}

if ((valsession('niv_log') <> 3) AND (valsession('niv_log') <> 4) AND (valsession('niv_log') <> 5) AND (valsession('niv_log') <> 9) AND (valsession('niv_log') <> 10) AND (valsession('niv_log') <> 11)) {
    $pbm_ot = TRUE;
}
if ($pbm_ot == FALSE) {
    if ($ci <> '') {
        // Récupération des informations Intervention
        $row = lit_enr_int($ci);
        if (is_array($row)) {
            $row = encode_str($row);
            extract($row);

            if ($int_codecli == $cc) {
                $row2 = lit_enr_cli($int_codecli, TRUE);
                if (is_array($row2)) {
                    $row2 = encode_str($row2);
                    extract($row2);
                    if ($si > 0) {
                        $row3 = lit_enr_scli_id($si, TRUE);
                        if (is_array($row3)) {
                            $row3 = encode_str($row3);
                            extract($row3);
                            if ($scli_codecli <> $cc) {
                                $pbm_cli = TRUE;
                            }
                        } else {
                            $pbm_cli = TRUE;
                        }
                    } else {
                        $scli_codepays = $cli_codepays;
                        $scli_dep = $cli_dep;
                    }
                } else {
                    $pbm_cli = TRUE;
                }
            } else {
                $pbm_cli = TRUE;
            }
        } else {
            $pbm_ot = TRUE;
        }
    } else {
        if ($tx == 'i') {
            $pbm_ot = TRUE;
        }
    }
}
if (($pbm_ot == FALSE) AND ($pbm_cli == FALSE)) {
    if ($tr <> '') {
        $row = lit_enr_tec($tr, TRUE);
        if (is_array($row)) {
            $row = encode_str($row);
            extract($row);
            switch (valsession('niv_log')) {
                case 3 :
                    if (($tec_codeage <> valsession('code_age')) AND ($tec_codeage <> valsession('code_age'))) {
                        $pbm_ot = TRUE;
                    }
                    break;
                case 4 :
                    if (($ca <> valsession('code_log')) AND ($cas <> valsession('code_log'))) {
                        $pbm_ot = TRUE;
                    }
                    break;
                case 10 :
                    if (valsession('code_log') <> $tec_codest) {
                        $pbm_ot = TRUE;
                    }
                    break;
                case 11 :
                    if (valsession('code_log') <> $tec_code) {
                        $pbm_ot = TRUE;
                    }
                    break;
                default :
                    break;
            }
        } else {
            $pbm_ot = TRUE;
        }
    } else {
        if ($tx == 'i') {
            $pbm_ot = TRUE;
        }
    }
}
if (($pbm_ot == FALSE) AND ($pbm_cli == FALSE)) {
    if ($ca <> '') {
        $row = lit_enr_age($ca, TRUE);
        if (is_array($row)) {
            $row = encode_str($row);
            extract($row);
        } else {
            $pbm_ot = TRUE;
        }
    } else {
        if ($tx == 'i') {
            $pbm_ot = TRUE;
        }
    }

    if ($cas <> '') {
        if ($cas <> '-1') {
            $row = lit_enr_age($cas, TRUE);
            if (is_array($row)) {
                $row = encode_str($row);
                extract($row);
            } else {
                $pbm_ot = TRUE;
            }
        }
    } else {
        if ($tx == 'i') {
            $pbm_ot = TRUE;
        }
    }
}

$fi = '';
if (isset($_GET['fi']) && (trim($_GET['fi']) <> '')) {
    $fi = (int)$_GET['fi'];
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>

    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <title>SMI - <?php echo _('ESPACE PRIVE'); ?> : <?php echo _('Liste Ordres Sous-traitants'); ?></title>

    <?php include_once('../inc/header.inc.php'); ?>

    <script type="text/javascript">
        <!--
        function init_all() {
            init_Body();
            init_autohref_classe('falselnkimg', '');
            <?php
            if ($tx=='i')
            {
                echo '$( "#onglets_lstot" ).tabs({ active: 1 });';
                echo "chk_ot('det_ot', 'nbot', '"._('Bons régularisés')."', 'nbota', '"._('Bons à régulariser')."',true);";
                echo "add_func_click('quit', 'sclose', '');";
            }
            else
            {
                echo '$( "#onglets_lstot" ).tabs();';
                echo "init_new_fen('imprim','impression','click');";
            }
            ?>
            Focus_first();
        }

        $(document).ready(function () {
            init_all();
        });
        //-->
    </script>

</head>

<body>
<?php
if ($tx <> 'i') {
    include_once('../inc/entete.inc.php');
}

switch (valsession('niv_log')) {
    case 3 :
    case 4 :
        cre_ent_form(_('BONS DE TRAVAIL'), '', '', '', FALSE);
        echo '<p align="center"><span class="annot_gras_it">' . _('Dont vous assurez le suivi des clients') . '</span></p>';
        break;
    case 5 :
    case 9 :
        cre_ent_form(_('BONS DE TRAVAIL'), '', '', '', FALSE);
        break;
    case 10 :
    case 11 :
        cre_ent_form(_('VOS BONS DE TRAVAIL'), '', '', '', FALSE);
        break;
}

if (($pbm_ot == FALSE) AND ($pbm_cli == FALSE)) {
    if ($tx == 'i') {
        // Récupération si rattachement à une intervention
        if (((valsession('niv_log') <> 10) AND (valsession('niv_log') <> 11)) OR (CheckNivLog('3') AND (valsession('code_log') == $tr))) {
            if (isset($_GET['cxi'])) {
                $cxi = (int)$_GET['cxi'];
                // cxi=1 : une régularisation est demandée
                if ($cxi == 1) {
                    // Si le code bon de travail est affiché et est valide, on peut transférer
                    if (isset($_GET['ot'])) {
                        $row = lit_enr_ot(trim($_GET['ot']));
                        if (is_array($row)) {
                            $row = encode_str($row);
                            extract($row);
                            if ((trim($ot_codeint) == '--AR--') AND (trim($ot_codecli) == $cc) AND (trim($ot_idsite) == $si)) {
                                // Régularisation du bon de travail
                                $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST, 'utf8');
                                $rech = 'UPDATE `' . TBOT . "` SET `ot_codeint`= '" . $ci . "' WHERE `ot_code`= '" . $ot_code . "'";
                                $db->query($rech);
                                close_database();
                            }
                        }
                    }
                }
                // cxi=-1 : une dissociation est demandée
                if ($cxi == -1) {
                    // Si le code bon de travail est affiché et est valide, on peut transférer
                    if (isset($_GET['ot'])) {
                        $row = lit_enr_ot(trim($_GET['ot']));
                        if (is_array($row)) {
                            $row = encode_str($row);
                            extract($row);
                            if ((trim($ot_codeint) == $ci) AND (trim($ot_codecli) == $cc) AND (trim($ot_idsite) == $si)) {
                                // Dissociation du bon de travail
                                $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST, 'utf8');
                                $rech = 'UPDATE `' . TBOT . "` SET `ot_codeint`= '--AR--' WHERE `ot_code`= '" . $ot_code . "'";
                                $db->query($rech);
                                close_database();
                            }
                        }
                    }
                }
                $url_query = str_ireplace('&cxi=-1', '', $url_query);
                $url_query = str_ireplace('&cxi=0', '', $url_query);
                $url_query = str_ireplace('&cxi=1', '', $url_query);
            }
        }

        // On enregistre les codes obligatoires
        $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST, 'utf8');
        // ->Code du contrat en cours (historique contrat)
        $rech = 'SELECT COUNT(*) FROM `' . TBCOCLH . "` WHERE `coclh_codeint` = '$ci'";
        $nbres = $db->get_var($rech);
        if ($nbres == 1) {
            $rech2 = 'UPDATE `' . TBCOCLH . "` SET `coclh_codecocl`='" . $co . "'";
            $rech2 .= " WHERE `coclh_codeint` = '" . $ci . "'";
        } else {
            $rech2 = 'INSERT INTO `' . TBCOCLH . '`';
            $rech2 .= ' (coclh_codecli,coclh_codecocl,coclh_codeint)';
            $rech2 .= ' VALUES';
            $rech2 .= " ('$cc','$co','$ci')";
        }
        $db->query($rech2);
        // ->code agence gestionnaire du compte
        // ->code technicien responsable du dossier
        // ->id site intervention
        $rech = 'UPDATE `' . TBINT . "` SET `int_datemod`='" . $datea . "', `int_codemod`='" . $_SESSION['code_log'] . "', `int_codeage`='" . $ca . "',";
        $rech .= " `int_codeage`='" . $ca . "', `int_codetec`='" . $tr . "', `int_idsite`= '" . $si . "', `int_codecocl`= '" . $co . "'";
        $rech .= " WHERE `int_code` = '" . $ci . "'";
        $db->query($rech);
        close_database();

        if ($ci <> '') {
            echo '<p align="center"><span class="annot_std_it">(' . _("Pour l'intervention N°") . '<span class="annot_std_gras">' . $ci . '</span>';
            echo ' - ' . _("Même client, même site d'intervention") . ')';
            echo '</span></p>';
        }
        echo '<p align="right"><input name="quit" type="button" class="bton_std" id="quit" value="' . _('Quitter') . '"></p>';
        if (($ci <> '') AND ($td <> 'view') AND CheckNivLog('3-4-5-9')) {
            $url_add = 'ot_maj.php?tx=' . $tx . '&td=add&ca=' . $ca . '&cas=' . $cas . '&ci=' . $ci . '&cc=' . $cc . '&co=&si=' . $si . '&tr=' . $tr;
        }
    } else {
        $fic_imp = 'ot_lsti.php';
        if ((valsession('niv_log') <> 1) AND (valsession('niv_log') <> 3) AND (valsession('niv_log') <> 11) AND (valsession('niv_log') <> 10)) {
            $url_add = 'cli_lst.php?td=ot&tl=1';
        }
        $url_rss = lien_rss(valsession('code_log'), valsession('niv_log'), 'ot');
    }

    $tab_fi = $tab_fi_ot_full;
    if (CheckNivLog('3')) {
        $tab_fi[] = _('Bons à régulariser');
    }

    include_once('formr.inc.php');

    $aff_full = TRUE;
    switch ($_SESSION['niv_log']) {
        case 10 :
        case 11 :
            $aff_full = FALSE;
            break;
        case 3 :
            if ($tx <> 'i') {
                $aff_full = FALSE;
            }
            break;
        default :
            break;
    }
    ?>
    <div id="onglets_lstot">
        <ul>
            <li><a href="#lstot_otr"><?php echo _('Régularisés'); ?></a></li>
            <li><a href="#lstot_otar"><?php echo _('A régulariser'); ?></a></li>
        </ul>
        <div id="lstot_otr">
            <?php
            // RAZ variables pour les pieds de liste
            include('../inc/init_varpl.inc.php');

            // Bon régularisés
            $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST, 'utf8');

            switch (valsession('niv_log')) {
                case 10 :
                case 11 :
                    $rech = cree_strrechlstotst();
                    $rechnum = cree_strrechlstotst(TRUE);
                    if (!stristr($rech, 'WHERE ')) {
                        $rech .= ' WHERE ' . TBOT . ".ot_codest='" . valsession('code_st') . "'";
                    } else {
                        $rech .= ' AND ' . TBOT . ".ot_codest='" . valsession('code_st') . "'";
                    }
                    if (!stristr($rechnum, 'WHERE ')) {
                        $rechnum .= ' WHERE ' . TBOT . ".ot_codest='" . valsession('code_st') . "'";
                    } else {
                        $rechnum .= ' AND ' . TBOT . ".ot_codest='" . valsession('code_st') . "'";
                    }
                    break;
                case 3 :
                    $rech = cree_strrechlstot_r();
                    $rechnum = cree_strrechlstot_r(TRUE);
                    if (!stristr($rech, 'WHERE ')) {
                        $rech .= ' WHERE (' . TBINT . ".int_codeage='" . valsession('code_age') . "'";
                        $rech .= ' OR ' . TBINT . ".int_codeages='" . valsession('code_age') . "')";
                        $rech .= ' AND ' . TBINT . ".int_codetec='" . valsession('code_log') . "'";
                    } else {
                        $rech .= ' AND (' . TBINT . ".int_codeage='" . valsession('code_age') . "'";
                        $rech .= ' OR ' . TBINT . ".int_codeages='" . valsession('code_age') . "')";
                        $rech .= ' AND ' . TBINT . ".int_codetec='" . valsession('code_log') . "'";
                    }
                    if (!stristr($rechnum, 'WHERE ')) {
                        $rechnum .= ' WHERE (' . TBINT . ".int_codeage='" . valsession('code_age') . "'";
                        $rechnum .= ' OR ' . TBINT . ".int_codeages='" . valsession('code_age') . "')";
                        $rechnum .= ' AND ' . TBINT . ".int_codetec='" . valsession('code_log') . "'";
                    } else {
                        $rechnum .= ' AND (' . TBINT . ".int_codeage='" . valsession('code_age') . "'";
                        $rechnum .= ' OR ' . TBINT . ".int_codeages='" . valsession('code_age') . "')";
                        $rechnum .= ' AND ' . TBINT . ".int_codetec='" . valsession('code_log') . "'";
                    }
                    break;
                case 4 :
                    $rech = cree_strrechlstot_r();
                    $rechnum = cree_strrechlstot_r(TRUE);
                    if (!stristr($rech, 'WHERE ')) {
                        $rech .= ' WHERE (' . TBINT . ".int_codeage='" . valsession('code_age') . "'";
                        $rech .= ' OR ' . TBINT . ".int_codeages='" . valsession('code_age') . "')";
                    } else {
                        $rech .= ' AND (' . TBINT . ".int_codeage='" . valsession('code_age') . "'";
                        $rech .= ' OR ' . TBINT . ".int_codeages='" . valsession('code_age') . "')";
                    }
                    if (!stristr($rechnum, 'WHERE ')) {
                        $rechnum .= ' WHERE (' . TBINT . ".int_codeage='" . valsession('code_age') . "'";
                        $rechnum .= ' OR ' . TBINT . ".int_codeages='" . valsession('code_age') . "')";
                    } else {
                        $rechnum .= ' AND (' . TBINT . ".int_codeage='" . valsession('code_age') . "'";
                        $rechnum .= ' OR ' . TBINT . ".int_codeages='" . valsession('code_age') . "')";
                    }
                    if (!stristr($rech, 'WHERE ')) {
                        $rech .= ' WHERE ' . TBOT . ".ot_codeint<>'--AR--'";
                    } else {
                        $rech .= ' AND ' . TBOT . ".ot_codeint<>'--AR--'";
                    }
                    if (!stristr($rechnum, 'WHERE ')) {
                        $rechnum .= ' WHERE ' . TBOT . ".ot_codeint<>'--AR--'";
                    } else {
                        $rechnum .= ' AND ' . TBOT . ".ot_codeint<>'--AR--'";
                    }
                    break;
                default :
                    $rech = cree_strrechlstot_r();
                    $rechnum = cree_strrechlstot_r(TRUE);
                    if (!stristr($rech, 'WHERE ')) {
                        $rech .= ' WHERE ' . TBOT . ".ot_codeint<>'--AR--'";
                    } else {
                        $rech .= ' AND ' . TBOT . ".ot_codeint<>'--AR--'";
                    }
                    if (!stristr($rechnum, 'WHERE ')) {
                        $rechnum .= ' WHERE ' . TBOT . ".ot_codeint<>'--AR--'";
                    } else {
                        $rechnum .= ' AND ' . TBOT . ".ot_codeint<>'--AR--'";
                    }
                    break;
            }

            if ($ci <> '') {
                if (!stristr($rech, 'WHERE ')) {
                    $rech .= ' WHERE ' . TBOT . ".ot_codeint='" . $ci . "'";
                } else {
                    $rech .= ' AND ' . TBOT . ".ot_codeint='" . $ci . "'";
                }
                if (!stristr($rechnum, 'WHERE ')) {
                    $rechnum .= ' WHERE ' . TBOT . ".ot_codeint='" . $ci . "'";
                } else {
                    $rechnum .= ' AND ' . TBOT . ".ot_codeint='" . $ci . "'";
                }
            }

            switch ($fi) {
                case '1' :
                    if (!stristr($rech, 'WHERE ')) {
                        $rechnum .= " WHERE ot_datefin='0000-00-00'";
                    } else {
                        $rechnum .= " AND ot_datefin='0000-00-00'";
                    }
                    if (!stristr($rechnum, 'WHERE ')) {
                        $rechnum .= " WHERE ot_datefin='0000-00-00'";
                    } else {
                        $rechnum .= " AND ot_datefin='0000-00-00'";
                    }
                    break;
                case '2' :
                    if (!stristr($rech, 'WHERE ')) {
                        $rech .= " WHERE ot_datefin<>'0000-00-00'";
                    } else {
                        $rech .= " AND ot_datefin<>'0000-00-00'";
                    }
                    if (!stristr($rechnum, 'WHERE ')) {
                        $rechnum .= " WHERE ot_datefin<>'0000-00-00'";
                    } else {
                        $rechnum .= " AND ot_datefin<>'0000-00-00'";
                    }
                    break;
                default :
                    break;
            }

            $rech .= crestr_triord($ot_titre_col, 'ot_code', TRUE, $limit);

            // Exécution de la requête
            $numrows = $db->get_var($rechnum);
            close_database();

            if ($numrows > 0) {
                $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST, 'utf8');

                $rows = $db->get_results($rech, ARRAY_A);

                // *** Pagination de pied
                pagine_lst($numrows, $limit);

                // *** Affichage de la table
                echo '<table class="Mtable" border="0" width="100%" cellpadding="0" cellspacing="0">';

                // création entête
                if ((valsession('niv_log') <> 11) AND (valsession('niv_log') <> 10)) {
                    titlst($ot_titre_col);
                } else {
                    titlst($ot2_titre_col);
                }
                echo '<th>' . _('Cliquer') . '</th>';


                $i = 0;


                foreach ($rows as $row) {
                    $row = encode_str($row);
                    // Affichage résumé ordre

                    // création de l'entête de ligne (TR)
                    echo '<tr>';

                    echo '<td>';
                    echo $row['ot_code'];

                    $detfic = '>>' . _('Matériel') . ' :<br />' . $row['ot_mat'] . '<br /><br />>>' . _('Travail à effectuer') . ' :<br />' . $row['ot_pbm'];
                    if (datetolocal($row['ot_datefin']) <> '') {
                        $detfic .= '<br /><br />>>' . _('Travail effectué') . ' :<br />' . $row['ot_fait'];
                    }
                    if ($detfic <> '') {
                        echo ' <a href="#" class="pop"><img src="../img/help.png" alt="' . _('Détail') . '" border="0" align="absmiddle"><span>' . formatetxtbr($detfic) . '</span></a>';
                    }

                    // Affichage détail intervention rattachée
                    if ($tx == 'm') {
                        // icône si tâche rattachée
                        $nb_tac_actives = nb_tac_actives(6, $row['ot_code'], FALSE);
                        if ($nb_tac_actives > 0) {
                            $url_taclst = 'tac_lst.php?ord=DES&tri=Code&fi=8&search=' . $row['ot_code'];
                            if ($nb_tac_actives > 1) {
                                $txt_tac = $nb_tac_actives . ' ' . _('tâches');
                                $txt_tac .= ' ' . _('non terminées');
                            } else {
                                $txt_tac = $nb_tac_actives . ' ' . _('tâche');
                                $txt_tac .= ' ' . _('non terminée');
                            }
                            $txt_tac .= ' (' . _('cliquez pour la liste des tâches rattachées à ce bon de travail') . ')';
                            echo ' <a href="' . $url_taclst . '"><img src="../img/tacwarn.png" title="' . $txt_tac . '" border="0" align="absmiddle"></a>';
                        }
                        if ((valsession('niv_log') <> 11) AND (valsession('niv_log') <> 10)) {
                            echo '<div class="annot_petit_it" align="right">';
                            $txtint = '';
                            if ($int_codedo <> '') {
                                $txtint = _('Ordre intervention');
                            } else {
                                $txtint = _('Intervention');
                            }
                            echo $txtint . ' ' . $row['ot_codeint'];

                            $row2 = lit_enr_int($row['ot_codeint'], FALSE);
                            if (is_array($row2)) {
                                $row2 = encode_str($row2);
                                extract($row2);
                            }
                            if (datetolocal($int_datefin) <> '') {
                                echo ' <img src="../img/ok.png" border="0" align="absmiddle" title="' . _('Terminé') . '">';
                            } else {
                                if (datetolocal($int_dateprev) <> '') {
                                    echo ' <img src="../img/phone.png" border="0" align="absmiddle" title="' . _('Client prévenu') . '">';
                                }
                            }
                            if (datetolocal($int_datefin) == '') {
                                cre_falselnk_img('', 'int_edit_' . $row['ot_id'], 'span', 'center', _('Edition'), 'lnk', 'int_maj.php?td=edit&ci=' . $int_code . '&cc=' . $int_codecli . '&ca=' . $int_codeage, '../img/edit.png');
                            } else {
                                cre_falselnk_img('', 'int_view_' . $row['ot_id'], 'span', 'center', _('Visualisation'), 'lnk', 'int_maj.php?td=view&ci=' . $int_code . '&cc=' . $int_codecli . '&ca=' . $int_codeage, '../img/eye.png');
                            }
                            echo '</div>';
                            if ($int_codedo <> '') {
                                echo '<div align="right" class="annot_upetit_it">';
                                echo _('Ordre de') . ' ' . $int_codedo;
                                echo '</div>';
                            }
                            if ($int_codeman <> '') {
                                echo '<div align="right" class="annot_upetit_it">';
                                echo _('Saisie manuelle') . ' : ' . $int_codeman;
                                echo '</div>';
                            }
                            if ($int_codeext <> '') {
                                echo '<div align="right" class="annot_upetit_it">';
                                echo _('Dossier') . ' : ' . $int_codeext;
                                echo '</div>';
                            }
                            echo '<div class="annot_petit_it" align="right">';
                            echo _('Client') . ' ' . $int_codecli;
                            $url = 'cli_maj.php?td=edit&cc=' . $nt_codecli;
                            if (url_ok($url, FALSE) == TRUE) {
                                cre_falselnk_img('', 'cli_edit_' . $row['ot_id'], 'span', 'center', _('Edition client'), 'lnk', $url, '../img/edit.png');
                            }
                            echo '</div>';
                        }

                    }
                    echo '</td>';

                    echo '<td align="center">';
                    echo datetolocal($row['ot_datedde']);
                    echo '</td>';
                    echo '<td align="center">';
                    echo datetolocal($row['ot_daterdv']);
                    if (datetolocal($row['ot_daterdv']) <> '') {
                        echo '<div class="annot_petit_it">';
                        echo substr($row['ot_hrdv'], 0, 5);
                        echo '</div>';
                    }
                    echo '</td>';

                    // Affichage icône Lieu
                    echo '<td>';
                    $rech2 = 'SELECT * FROM `' . TBLIEU . "` WHERE lieu_code = '" . $row['ot_codelieu'] . "'";
                    $row2 = $db->get_row($rech2, ARRAY_A);

                    if ($row2) {
                        $row2 = encode_str($row2);
                        extract($row2);
                        if ($lieu_img <> '') {
                            $lieuint = $lieu_desc . ' (' . $row['ot_codelieu'] . ')';
                            echo '<div style="float:left;width:40px;">';
                            echo ' <img src="' . $lieu_img . '" title="' . $lieuint . '" border="0" align="absmiddle">';
                            echo '</div>';
                        } else {
                            echo '<span class="annot_std_it" style="float:left;">';
                            echo $row['ot_codelieu'];
                            echo '</span>';
                        }
                    }

                    // Affichage site client
                    $sitecli = '';
                    switch ((int)$row['ot_idsite']) {
                        case 0 :
                            $row2 = lit_enr_cli($row['ot_codecli'], FALSE);
                            if (is_array($row2)) {
                                $row2 = encode_str($row2);
                                extract($row2);
                                $sitecli .= '<strong>';
                                if ($cli_ste <> '') {
                                    $sitecli .= $cli_ste . '<br />';
                                } else {
                                    $sitecli .= $cli_civilite . ' ' . $cli_prenom . ' ' . $cli_nom . '<br />';
                                }
                                $sitecli .= '</strong>';
                                $sitecli .= $cli_adr1 . '<br />';
                                if ($cli_adr2 <> '') {
                                    $sitecli .= $cli_adr2 . '<br />';
                                }
                                $sitecli .= Retournecp_Id($cli_ville, FALSE) . ' ' . Retourneville_Id($cli_ville, FALSE) . '<br />';
                            }
                            break;
                        default :
                            $rech2 = 'SELECT * FROM `' . TBSCLI . "` WHERE `scli_id` = '" . trim($row['ot_idsite']) . "'";
                            $row2 = $db->get_row($rech2, ARRAY_A);
                            if ($row2) {
                                extract($row2);
                                $sitecli .= '<strong>';
                                $sitecli .= $scli_ste . '<br />';
                                $sitecli .= '</strong>';
                                $sitecli .= $scli_adr1 . '<br />';
                                if ($scli_adr2 <> '') {
                                    $sitecli .= $scli_adr2 . '<br />';
                                }
                                $sitecli .= Retournecp_Id($scli_ville, FALSE) . ' ' . Retourneville_Id($scli_ville, FALSE) . '<br />';
                            }
                    }
                    if ($sitecli <> '') {
                        echo '<div class="annot_petit_it" style="float:left;">';
                        echo $sitecli;
                        echo '</div>';
                    }

                    echo '</td>';

                    // Affichage détail urgence
                    echo '<td ';
                    $couleur = give_coul_urg($row['ot_urg'], FALSE);
                    if ($couleur <> 'XX') {
                        echo ' style="background:' . $couleur . '"';
                    }
                    echo ' align="center">';
                    echo give_nom_urg($row['ot_urg'], FALSE);
                    echo '</td>';
                    // Fin affichage détail urgence

                    if ((valsession('niv_log') <> 11) AND (valsession('niv_log') <> 10)) {
                        echo '<td align="center">';
                        echo $row['ot_codest'];
                        if ($tx == 'm') {
                            $rech2 = 'SELECT st_dep FROM `' . TBST . "` WHERE `st_code`='" . $row['ot_codest'] . "'";
                            $row2 = $db->get_row($rech2, ARRAY_A);
                            if ($row2) {
                                cre_falselnk_img('', 'st_edit_' . $row['ot_id'], 'span', 'center', _('Edition sous-traitant'), 'lnk', 'st_maj.php?td=edit&code=' . $row['ot_codest'] . '&dep=' . $row2['st_dep'], '../img/edit.png');
                            }
                        }

                        // Affichage détail sous-traitant
                        $detailst = $row['st_nom'] . ', ';
                        $detailst .= $row['st_resp_civilite'] . ' ' . $row['st_resp_nom'];
                        echo '<div class="annot_petit_it" style="margin-left:5px;">';
                        echo $detailst;
                        echo '</div>';
                        // Fin affichage détail sous-trainat
                        echo '</td>';
                    }

                    // Affichage technicien traitant
                    echo '<td align="center">';
                    if (($row['ot_codetec'] <> '') AND ($row['ot_codetec'] <> '-1')) {
                        echo $row['ot_codetec'];
                    } else {
                        echo '&nbsp;';
                    }
                    echo '</td>';

                    // Affichage icône Statut
                    echo '<td align="center">';

                    echo str_div_ico_statut($row['ot_codestatut'], '', FALSE);
                    if ($statut == 'CLOT') {
                        echo '<div class="annot_upetit_it">';
                        echo datetolocal($row['ot_datefin']);
                        echo '</div>';
                    }
                    echo '</td>';

                    // CREATION lien dynamique sur icône (édition, suppression, etc...)
                    echo '<td align="center">';

                    if ($td <> 'view') {
                        if ($row['ot_codestatut'] <> 'CLOT') {
                            $lst_maj = TRUE;
                            if (CheckNivLog('10-11')) {
                                cre_falselnk_img('', 'ot_edit_' . $row['ot_id'], 'span', 'center', _('Edition'), 'lnk', 'ot_maj.php?tx=' . $tx . '&td=edit&ca=' . $int_codeage . '&cas=' . $int_codeages . '&cc=' . $row['ot_codecli'] . '&co=' . $row['ot_code'] . '&si=' . $row['ot_idsite'] . '&tr=' . $int_codetec, '../img/edit.png');
                            } else {
                                cre_falselnk_img('', 'ot_edit_' . $row['ot_id'], 'span', 'center', _('Edition'), 'lnk', 'ot_maj.php?tx=' . $tx . '&td=edit&ca=' . $int_codeage . '&cas=' . $int_codeages . '&ci=' . $row['ot_codeint'] . '&cc=' . $row['ot_codecli'] . '&co=' . $row['ot_code'] . '&si=' . $row['ot_idsite'] . '&tr=' . $int_codetec, '../img/edit.png');
                            }
                        } else {
                            $lst_voir = TRUE;
                            if (CheckNivLog('10-11')) {
                                cre_falselnk_img('', 'ot_view_' . $row['ot_id'], 'span', 'center', _('Visualisation'), 'lnk', 'ot_maj.php?tx=' . $tx . '&td=view&ca=' . $int_codeage . '&cas=' . $int_codeages . '&cc=' . $row['ot_codecli'] . '&co=' . $row['ot_code'] . '&si=' . $row['ot_idsite'] . '&tr=' . $int_codetec, '../img/eye.png');
                            } else {
                                cre_falselnk_img('', 'ot_view_' . $row['ot_id'], 'span', 'center', _('Visualisation'), 'lnk', 'ot_maj.php?tx=' . $tx . '&td=view&ca=' . $int_codeage . '&cas=' . $int_codeages . '&ci=' . $row['ot_codeint'] . '&cc=' . $row['ot_codecli'] . '&co=' . $row['ot_code'] . '&si=' . $row['ot_idsite'] . '&tr=' . $int_codetec, '../img/eye.png');
                            }
                        }

                        if ($tx == 'i') {
                            $lst_otulnk = TRUE;
                            cre_falselnk_img('', 'ot_lstd_' . $row['ot_id'], 'span', 'center', _('Dissocier bon de travail'), 'lnk', 'ot_lst.php?' . $url_query . '&cxi=-1&ot=' . $row['ot_code'], '../img/ot_lnkdel.png');
                        }

                        $lst_imp = TRUE;
                        $urlimp = 'ot_pdf.php?co=' . $row['ot_code'];
                        cre_falselnk_img('', 'ot_prn_' . $row['ot_id'], 'span', 'center', _('Imprimer'), 'lnkpop', $urlimp, '../img/print.png');

                        if ($row['ot_codestatut'] <> 'CLOT') {
                            $del = TRUE;

                            if (CheckNivLog('10-11')) {
                                $del = FALSE;
                            }

                            if ($del == TRUE) {
                                $lst_del = TRUE;
                                cre_falselnk_img('', 'ot_view_' . $row['ot_id'], 'span', 'center', _('Suppression'), 'lnk', 'ot_maj.php?tx=' . $tx . '&td=del&ca=' . $int_codeage . '&cas=' . $int_codeages . '&cc=' . $row['ot_codecli'] . '&co=' . $row['ot_code'] . '&si=' . $row['ot_idsite'] . '&tr=' . $int_codetec, '../img/del.png');
                            }
                        }
                        echo '</td>';
                    } else {
                        $lst_voir = TRUE;
                        if (CheckNivLog('10-11')) {
                            cre_falselnk_img('', 'ot_view_' . $row['ot_id'], 'span', 'center', _('Visualisation'), 'lnk', 'ot_maj.php?tx=' . $tx . '&td=view&ca=' . $int_codeage . '&cas=' . $int_codeages . '&cc=' . $row['ot_codecli'] . '&co=' . $row['ot_code'] . '&si=' . $row['ot_idsite'] . '&tr=' . $int_codetec, '../img/eye.png');
                        } else {
                            cre_falselnk_img('', 'ot_view_' . $row['ot_id'], 'span', 'center', _('Visualisation'), 'lnk', 'ot_maj.php?tx=' . $tx . '&td=view&ca=' . $int_codeage . '&cas=' . $int_codeages . '&ci=' . $row['ot_codeint'] . '&cc=' . $row['ot_codecli'] . '&co=' . $row['ot_code'] . '&si=' . $row['ot_idsite'] . '&tr=' . $int_codetec, '../img/eye.png');
                        }
                    }

                    echo '</tr>';
                    // Fin affichage résumé ordre

                    $i++;
                }
                echo '</table>';
                // *** Fin affichage de la table

                close_database();

                // *** Pagination de pied
                pagine_lst($numrows, $limit);

                $taille_piedla = '';
                include('piedla.inc.php');
            } else {
                retpp();
            }
            ?>
        </div>
        <div id="lstot_otar">
            <?php
            // RAZ variables pour les pieds de liste
            include('../inc/init_varpl.inc.php');

            // Bons à régulariser
            $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST, 'utf8');

            switch (valsession('niv_log')) {
                case 10 :
                case 11 :
                    $rech2 = cree_strrechlstotst();
                    $rechnum2 = cree_strrechlstotst(TRUE);
                    if (!stristr($rech2, 'WHERE ')) {
                        $rech2 .= ' WHERE ' . TBOT . ".ot_codest='" . valsession('code_st') . "'";
                    } else {
                        $rech2 .= ' AND ' . TBOT . ".ot_codest='" . valsession('code_st') . "'";
                    }
                    if (!stristr($rechnum2, 'WHERE ')) {
                        $rechnum2 .= ' WHERE ' . TBOT . ".ot_codest='" . valsession('code_st') . "'";
                    } else {
                        $rechnum2 .= ' AND ' . TBOT . ".ot_codest='" . valsession('code_st') . "'";
                    }
                    break;
                case 3 :
                    $rech2 = cree_strrechlstot_ar();
                    $rechnum2 = cree_strrechlstot_ar(TRUE);
                    if (!stristr($rech2, 'WHERE ')) {
                        $rech2 .= ' WHERE ' . TBCLI . ".cli_prop='" . valsession('code_age') . "'";
                    } else {
                        $rech2 .= ' AND ' . TBCLI . ".cli_prop='" . valsession('code_age') . "'";
                    }
                    if (!stristr($rechnum2, 'WHERE ')) {
                        $rechnum2 .= ' WHERE ' . TBCLI . ".cli_prop='" . valsession('code_age') . "'";
                    } else {
                        $rechnum2 .= ' AND ' . TBCLI . ".cli_prop='" . valsession('code_age') . "'";
                    }
                    if (!stristr($rech2, 'WHERE ')) {
                        $rech2 .= ' WHERE ' . TBOT . ".ot_codeint='--AR--'";
                    } else {
                        $rech2 .= ' AND ' . TBOT . ".ot_codeint='--AR--'";
                    }
                    if (!stristr($rechnum2, 'WHERE ')) {
                        $rechnum2 .= ' WHERE ' . TBOT . ".ot_codeint='--AR--'";
                    } else {
                        $rechnum2 .= ' AND ' . TBOT . ".ot_codeint='--AR--'";
                    }
                    break;
                case 4 :
                    $rech2 = cree_strrechlstot_ar();
                    $rechnum2 = cree_strrechlstot_ar(TRUE);
                    if (!stristr($rech2, 'WHERE ')) {
                        $rech2 .= ' WHERE ' . TBOT . ".ot_codeint='--AR--'";
                    } else {
                        $rech2 .= ' AND ' . TBOT . ".ot_codeint='--AR--'";
                    }
                    if (!stristr($rechnum2, 'WHERE ')) {
                        $rechnum2 .= ' WHERE ' . TBCLI . ".cli_prop='" . valsession('code_age') . "'";
                    } else {
                        $rechnum2 .= ' AND ' . TBCLI . ".cli_prop='" . valsession('code_age') . "'";
                    }
                    break;
                default :
                    $rech2 = cree_strrechlstot_ar();
                    $rechnum2 = cree_strrechlstot_ar(TRUE);
                    if (!stristr($rech2, 'WHERE ')) {
                        $rech2 .= ' WHERE ' . TBOT . ".ot_codeint='--AR--'";
                    } else {
                        $rech2 .= ' AND ' . TBOT . ".ot_codeint='--AR--'";
                    }
                    if (!stristr($rechnum2, 'WHERE ')) {
                        $rechnum2 .= ' WHERE ' . TBOT . ".ot_codeint='--AR--'";
                    } else {
                        $rechnum2 .= ' AND ' . TBOT . ".ot_codeint='--AR--'";
                    }
                    break;
            }

            if ($tx == 'i') {
                if (!stristr($rech2, 'WHERE ')) {
                    $rech2 .= ' WHERE (' . TBOT . ".ot_codecli='" . $cc . "'";
                    $rech2 .= ' AND ' . TBOT . ".ot_idsite='" . $si . "')";
                } else {
                    $rech2 .= ' AND ' . TBOT . ".ot_codecli='" . $cc . "'";
                    $rech2 .= ' AND ' . TBOT . ".ot_idsite='" . $si . "'";
                }
                if (!stristr($rechnum2, 'WHERE ')) {
                    $rechnum2 .= ' WHERE (' . TBOT . ".ot_codecli='" . $cc . "'";
                    $rechnum2 .= ' AND ' . TBOT . ".ot_idsite='" . $si . "')";
                } else {
                    $rechnum2 .= ' AND ' . TBOT . ".ot_codecli='" . $cc . "'";
                    $rechnum2 .= ' AND ' . TBOT . ".ot_idsite='" . $si . "'";
                }
            }

            switch ($fi) {
                case '1' :
                    if (!stristr($rech2, 'WHERE ')) {
                        $rech2 .= " WHERE ot_datefin='0000-00-00'";
                    } else {
                        $rech2 .= " AND ot_datefin='0000-00-00'";
                    }
                    if (!stristr($rechnum2, 'WHERE ')) {
                        $rechnum2 .= " WHERE ot_datefin='0000-00-00'";
                    } else {
                        $rechnum2 .= " AND ot_datefin='0000-00-00'";
                    }
                    break;
                case '2' :
                    if (!stristr($rech2, 'WHERE ')) {
                        $rech2 .= " WHERE ot_datefin<>'0000-00-00'";
                    } else {
                        $rech2 .= " AND ot_datefin<>'0000-00-00'";
                    }
                    if (!stristr($rechnum2, 'WHERE ')) {
                        $rechnum2 .= " WHERE ot_datefin<>'0000-00-00'";
                    } else {
                        $rechnum2 .= " AND ot_datefin<>'0000-00-00'";
                    }
                    break;
                case '3' :
                    if (!stristr($rech2, 'WHERE ')) {
                        $rech2 .= " WHERE ot_codeint='--AR--'";
                    } else {
                        $rech2 .= " AND ot_codeint='--AR--'";
                    }
                    if (!stristr($rechnum2, 'WHERE ')) {
                        $rechnum2 .= " WHERE ot_codeint='--AR--'";
                    } else {
                        $rechnum2 .= " AND ot_codeint='--AR--'";
                    }
                    break;
                default :
                    break;
            }
            $rech2 .= crestr_triord($ot_titre_col, 'ot_code', TRUE, $limit);

            // Exécution de la requête
            $numrows2 = $db->get_var($rechnum2);
            close_database();

            if ($numrows2 > 0) {
                $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST, 'utf8');

                $rows2 = $db->get_results($rech2, ARRAY_A);
                // *** Pagination de pied
                pagine_lst($numrows2, $limit);

                // *** Affichage de la table
                echo '<table class="Mtable" border="0" width="100%" cellpadding="0" cellspacing="0">';

                // création entête
                if ((valsession('niv_log') <> 11) AND (valsession('niv_log') <> 10)) {
                    titlst($ot_titre_col);
                } else {
                    titlst($ot2_titre_col);
                }
                if ($td <> 'view') {
                    echo '<th>' . _('Cliquer') . '</th>';
                }

                $i = 0;

                foreach ($rows2 as $row2) {
                    $row2 = encode_str($row2);
                    // Affichage résumé ordre

                    // création de l'entête de ligne (TR)
                    echo '<tr>';

                    echo '<td>';
                    echo $row2['ot_code'];

                    $detfic = '>>' . _('Matériel') . ' :<br />' . $row2['ot_mat'] . '<br /><br />>>' . _('Travail à effectuer') . ' :<br />' . $row2['ot_pbm'];
                    if (datetolocal($row2['ot_datefin']) <> '') {
                        $detfic .= '<br /><br />>>' . _('Travail effectué') . ' :<br />' . $row2['ot_fait'];
                    }
                    if ($detfic <> '') {
                        echo ' <a href="#" class="pop"><img src="../img/help.png" alt="' . _('Détail') . '" border="0" align="absmiddle"><span>' . formatetxtbr($detfic) . '</span></a>';
                    }

                    // Affichage détail intervention rattachée
                    if ($tx == 'm') {
                        // icône si tâche rattachée
                        $nb_tac_actives = nb_tac_actives(6, $row2['ot_code'], FALSE);
                        if ($nb_tac_actives > 0) {
                            $url_taclst = 'tac_lst.php?ord=DES&tri=Code&fi=8&search=' . $row2['ot_code'];
                            if ($nb_tac_actives > 1) {
                                $txt_tac = $nb_tac_actives . ' ' . _('tâches');
                                $txt_tac .= ' ' . _('non terminées');
                            } else {
                                $txt_tac = $nb_tac_actives . ' ' . _('tâche');
                                $txt_tac .= ' ' . _('non terminée');
                            }
                            $txt_tac .= ' (' . _('cliquez pour la liste des tâches rattachées à ce bon de travail') . ')';
                            echo ' <a href="' . $url_taclst . '"><img src="../img/tacwarn.png" title="' . $txt_tac . '" border="0" align="absmiddle"></a>';
                        }
                        if ((valsession('niv_log') <> 11) AND (valsession('niv_log') <> 10)) {
                            echo '<div class="annot_petit_it" align="right">';
                            echo _('Client') . ' ' . $row2['ot_codecli'];
                            $url = 'cli_maj.php?td=edit&cc=' . $row2['ot_codecli'];
                            if (url_ok($url, FALSE) == TRUE) {
                                cre_falselnk_img('', 'cli_edit_' . $row2['ot_id'], 'span', 'center', _('Edition client'), 'lnk', $url, '../img/edit.png');
                            }
                            echo '</div>';
                        }

                    }
                    echo '</td>';

                    echo '<td align="center">';
                    echo datetolocal($row2['ot_datedde']);
                    echo '</td>';
                    echo '<td align="center">';
                    echo datetolocal($row2['ot_daterdv']);
                    if (datetolocal($row2['ot_daterdv']) <> '') {
                        echo '<div class="annot_petit_it">';
                        echo substr($row2['ot_hrdv'], 0, 5);
                        echo '</div>';
                    }
                    echo '</td>';

                    // Affichage icône Lieu
                    echo '<td>';
                    $lieu = $row2['ot_codelieu'];
                    $rech3 = 'SELECT * FROM `' . TBLIEU . "` WHERE lieu_code = '$lieu'";
                    $row3 = $db->get_row($rech3, ARRAY_A);

                    if ($row3) {
                        $row3 = encode_str($row3);
                        extract($row3);
                        if ($lieu_img <> '') {
                            $lieuint = $lieu_desc . ' (' . $lieu . ')';
                            echo '<div style="float:left;width:40px;">';
                            echo ' <img src="' . $row3['lieu_img'] . '" title="' . $lieuint . '" border="0" align="absmiddle">';
                            echo '</div>';
                        } else {
                            echo '<span class="annot_std_it" style="float:left;">';
                            echo $lieu;
                            echo '</span>';
                        }
                    }

                    // Affichage site client
                    $sitecli = '';
                    switch (trim($row2['ot_idsite'])) {
                        case '0' :
                            $row3 = lit_enr_cli($row2['ot_codecli'], FALSE);
                            if (is_array($row3)) {
                                $row3 = encode_str($row3);
                                extract($row3);
                                $sitecli .= '<strong>';
                                if ($cli_ste <> '') {
                                    $sitecli .= $cli_ste . '<br />';
                                } else {
                                    $sitecli .= $cli_civilite . ' ' . $cli_prenom . ' ' . $cli_nom . '<br />';
                                }
                                $sitecli .= '</strong>';
                                $sitecli .= $cli_adr1 . '<br />';
                                if ($cli_adr2 <> '') {
                                    $sitecli .= $cli_adr2 . '<br />';
                                }
                                $sitecli .= Retournecp_Id($cli_ville, FALSE) . ' ' . Retourneville_Id($cli_ville, FALSE) . '<br />';
                            }
                            break;
                        default :
                            $rech3 = 'SELECT * FROM `' . TBSCLI . "` WHERE `scli_id` = '" . trim($row2['ot_idsite']) . "'";
                            $row3 = $db->get_row($rech3, ARRAY_A);
                            if ($row3) {
                                extract($row3);
                                $sitecli .= '<strong>';
                                $sitecli .= $scli_ste . '<br />';
                                $sitecli .= '</strong>';
                                $sitecli .= $scli_adr1 . '<br />';
                                if ($scli_adr2 <> '') {
                                    $sitecli .= $scli_adr2 . '<br />';
                                }
                                $sitecli .= Retournecp_Id($scli_ville, FALSE) . ' ' . Retourneville_Id($scli_ville, FALSE) . '<br />';
                            }
                    }

                    if ($sitecli <> '') {
                        echo '<div class="annot_petit_it" style="float:left;">';
                        echo $sitecli;
                        echo '</div>';
                    }
                    echo '</td>';

                    // Affichage détail urgence
                    echo '<td ';
                    $couleur = give_coul_urg($row2['ot_urg'], FALSE);
                    if ($couleur <> 'XX') {
                        echo ' style="background:' . $couleur . '"';
                    }
                    echo ' align="center">';
                    echo give_nom_urg($row2['ot_urg'], FALSE);
                    echo '</td>';
                    // Fin affichage détail urgence

                    if ((valsession('niv_log') <> 11) AND (valsession('niv_log') <> 10)) {
                        echo '<td align="center">';
                        echo $row2['ot_codest'];
                        if ($tx == 'm') {
                            $rech3 = 'SELECT st_dep FROM `' . TBST . "` WHERE `st_code`='" . $row2['ot_codest'] . "'";
                            $row3 = $db->get_row($rech3, ARRAY_A);
                            if ($row3) {
                                $url = 'st_maj.php?td=edit&code=' . $row2['ot_codest'] . '&dep=' . $row3['st_dep'];
                                if (url_ok($url, FALSE) == TRUE) {
                                    cre_falselnk_img('', 'st_edit_' . $row2['ot_id'], 'span', 'center', _('Edition sous-traitant'), 'lnk', $url, '../img/edit.png');
                                }
                            }
                        }

                        // Affichage détail sous-traitant
                        $detailst = $row2['st_nom'] . ', ';
                        $detailst .= $row2['st_resp_civilite'] . ' ' . $row2['st_resp_nom'];
                        echo '<div class="annot_petit_it" style="margin-left:5px;">';
                        echo $detailst;
                        echo '</div>';
                        // Fin affichage détail sous-trainat
                        echo '</td>';
                    }

                    // Affichage technicien traitant
                    echo '<td align="center">';
                    if (($row2['ot_codetec'] <> '') AND ($row2['ot_codetec'] <> '-1')) {
                        echo $row2['ot_codetec'];
                    } else {
                        echo '&nbsp;';
                    }
                    echo '</td>';

                    // Affichage icône Statut
                    echo '<td align="center">';

                    echo str_div_ico_statut($row2['ot_codestatut'], '', FALSE);
                    if ($statut == 'CLOT') {
                        echo '<div class="annot_upetit_it">';
                        echo datetolocal($row2['ot_datefin']);
                        echo '</div>';
                    }

                    echo '</td>';

                    if ($td <> 'view') {
                        // CREATION lien dynamique sur icône (édition, suppression, etc...)
                        echo '<td align="center">';

                        if ($tx == 'm') {
                            if ($row2['ot_codestatut'] <> 'CLOT') {
                                $lst_maj = TRUE;
                                $url = 'ot_maj.php?tx=' . $tx . '&td=edit&ca=' . $ca . '&cas=' . $cas . '&ci=&cc=' . $row2['ot_codecli'] . '&co=' . $row2['ot_code'] . '&si=' . $row2['ot_idsite'] . '&tr=';
                                if (url_ok($url, FALSE) == TRUE) {
                                    cre_falselnk_img('', 'ot_edit_' . $row2['ot_id'], 'span', 'center', _('Edition'), 'lnk', $url, '../img/edit.png');
                                }
                                echo ' ';
                            } else {
                                $lst_voir = TRUE;
                                $url = 'ot_maj.php?tx=' . $tx . '&td=view&ca=' . $ca . '&cas=' . $cas . '&ci=&cc=' . $row2['ot_codecli'] . '&co=' . $row2['ot_code'] . '&si=' . $row2['ot_idsite'] . '&tr=';
                                if (url_ok($url, FALSE) == TRUE) {
                                    cre_falselnk_img('', 'ot_view_' . $row2['ot_id'], 'span', 'center', _('Visualisation'), 'lnk', $url, '../img/eye.png');
                                }
                                echo ' ';
                            }
                        }

                        $lst_otlnk = TRUE;
                        if ($tx == 'm') {
                            if ($row2['ot_codeint'] == '--AR--') {
                                $url = 'int_maj.php?td=add&ci=&ot=' . $row2['ot_code'];
                                if (url_ok($url, FALSE) == TRUE) {
                                    cre_falselnk_img('', 'int_add_' . $row2['ot_id'], 'span', 'center', _('Ajouter intervention'), 'lnk', $url, '../img/ot_lnkadd.png');
                                }
                            }
                        } else {
                            cre_falselnk_img('', 'ot_lst_' . $row2['ot_id'], 'span', 'center', _('Rattacher cette intervention'), 'lnk', 'ot_lst.php?' . $url_query . '&cxi=1&ot=' . $row2['ot_code'], '../img/ot_lnkadd.png');
                        }

                        if ($tx == 'm') {
                            $urlimp = 'ot_pdf.php?co=' . $row2['ot_code'];
                            if (url_ok($urlimp, FALSE) == TRUE) {
                                $lst_imp = TRUE;
                                cre_falselnk_img('', 'ot_prn_' . $row2['ot_id'], 'span', 'center', _('Imprimer'), 'lnkpop', $urlimp, '../img/print.png');
                            }
                        }

                        if ($row2['ot_codestatut'] <> 'CLOT') {
                            $del = TRUE;

                            if (CheckNivLog('10-11') OR ($tx == 'i')) {
                                $del = FALSE;
                            }

                            if ($del == TRUE) {
                                $url = 'ot_maj.php?tx=' . $tx . '&td=del&ca=' . $ca . '&cas=' . $cas . '&ci=&cc=' . $row2['ot_codecli'] . '&co=' . $row2['ot_code'] . '&si=' . $row2['ot_idsite'] . '&tr=';
                                if (url_ok($url, FALSE) == TRUE) {
                                    $lst_del = TRUE;
                                }
                                cre_falselnk_img('', 'ot_del_' . $row2['ot_id'], 'span', 'center', _('Suppression'), 'lnk', $url, '../img/del.png');
                            }
                        }
                        echo '</td>';
                    }

                    echo '</tr>';
                    // Fin affichage résumé ordre

                    $i++;
                }
                echo '</table>';
                // *** Fin affichage de la table

                close_database();

                // *** Pagination de pied
                pagine_lst($numrows2, $limit);

                $taille_piedla = '';
                include('piedla.inc.php');
            } else {
                retpp();
            }
            ?>
        </div>
    </div>
    <?php
} else {
    if ($tx == 'i') {
        close_fen_auto(_('Problème de paramètres'), 'fscomp');
    } else {
        pop_ret_auto('', '', 'index.php');
    }
}
if ($tx == 'm') {
    include_once('pied.php');
} else {
    echo '</body>';
    echo '</html>';
}
?>
