<?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");

include_once("../inc/fic_age.inc.php");
include_once("../inc/fic_do.inc.php");
include_once("../inc/fic_cli.inc.php");
include_once("../inc/fic_cocl.inc.php");
include_once("../inc/fic_droits.inc.php");
include_once("../inc/fic_fici.inc.php");
include_once("../inc/fic_hum.inc.php");
include_once("../inc/fic_int.inc.php");
include_once("../inc/fic_ot.inc.php");
include_once("../inc/fic_rel.inc.php");
include_once("../inc/fic_tac.inc.php");
include_once("../inc/fic_st.inc.php");
include_once("../inc/fic_statut.inc.php");
include_once("../inc/fic_tec.inc.php");
include_once("../inc/func.inc.php");
include_once("../inc/func_time.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("../classes/ezSQL/shared/ez_sql_core.php");
include_once("../classes/ezSQL/mysqli/ez_sql_mysqli.php");
include_once("../inc/func_sql.inc.php");
Archivelog(@$_SESSION["code_log"]);
// Variables Formulaire
fix_magic_quotes();
$_GET = clean_str($_GET);

$tx = $_GET['tx']; // Source de l'appel m:depuis le menu, i:depuis l'intervention
$td = $_GET['td']; // Récupération type demande
$cc = $_GET['cc']; // Récupération code Client
$ci = $_GET['ci']; // Récupération code Intervention
$co = $_GET['co']; // Récupération code Ordre de travail 
$si = $_GET['si']; // Récupération id du site
$tr = $_GET['tr']; // Récupération technicien responsable
$ca = $_GET['ca']; // Récupération code agence gestionnaire du client
$cas = $_GET['cas']; // Récupération code agence gestionnaire du site

$pbm_ot = FALSE;
$pbm_cli = FALSE;
$tong =1 ;

if (($tx <> "m") AND ($tx <> "i"))
    $pbm_ot = TRUE;

if ((@$_SESSION["niv_log"] <> 3) AND (@$_SESSION["niv_log"] <> 4) AND (@$_SESSION["niv_log"] <> 5) AND (@$_SESSION["niv_log"] <> 9) AND (@$_SESSION["niv_log"] <> 10) AND (@$_SESSION["niv_log"] <> 11))
    $pbm_ot = TRUE;

if ($td <> "add") {
    if (isset($_GET['tong'])) {
        $tong = intval($_GET['tong']); // Récupération Numéro d'onglet à afficher
        if (($tong < 1) OR ($tong > 2))
            $pbm_ot = TRUE;
    }
}

// Récupération des paramètres de SMI
$db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
$rech = "SELECT * FROM `" . TBPPRM . "`";
$row = $db->get_row($rech, ARRAY_A);
if ($row)
    extract($row);
$db->disconnect();

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) AND ($int_idsite == $si)) {
            $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;
    else {
        // On récupère les informations client
        $row2 = lit_enr_cli($cc, 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;

        if ($pbm_cli == FALSE) {
            // On vérifie le dossier de stockage du client
            $mess_err = check_fic_cli($cli_code, $cli_ste, $cli_nom, $cli_prenom, TRUE);

            if ($mess_err == "") {
                $int_codecli = $cli_code;
                $nb_sites = nb_scli_actifs($cli_code, '', TRUE);
            } else
                $pbm_cli = TRUE;
        }
    }
}

if (($pbm_ot == FALSE) AND ($pbm_cli == FALSE)) {
    if ($co <> "") {
        // Récupération des informations ordre
        $row = lit_enr_ot($co);
        if (is_array($row)) {
            $row = encode_str($row);
            extract($row);

            $ci = $ot_codeint;

            // Formatage des dates en français
            $ot_datecreaf = datetolocal($ot_datecrea);
            $ot_datemodf = datetolocal($ot_datemod);
            $ot_dateddef = datetolocal($ot_datedde);
            $ot_daterdvf = datetolocal($ot_daterdv);
            $ot_dateprevf = datetolocal($ot_dateprev);
            $ot_datefinf = datetolocal($ot_datefin);

            // Si intervention terminée, on force le mode "view"
            if ($ot_datefinf <> "")
                $td = "view";

            // Récupération heure rdv
            $ot_hrdv = substr($ot_hrdv, 0, 5);
            if ($ot_daterdvf == "") // Si pas de RDV, pas d'heure possible...
                $ot_hrdv = "";

            // Nombre de tâches rattachées à ce bon de travail
            $nb_tac_actives = nb_tac_actives(6, $ot_code, TRUE);

            // Récupération du total travaillé & Techniciens traitants
            $nbtotalsec = 0;
            $nbtotalsecoff = 0;
            $str_tec_traitants = "";
            if ($td <> "add") {
                $nbtotalsec = tps_travaille_ot($co, TRUE);

                $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
                // Si un utilisateur a quitté avant de sauver (bien qu'ayant modifié le détail horaire),
                // on remet en état car seul le détail horaire et technicien enregistré est valable
                if ($ot_durees <> $nbtotalsec) {
                    $rech = "UPDATE `" . TBOT . "` SET `ot_datemod`='" . $datea . "', `ot_codemod`='" . $db->escape($codeuser) . "',`ot_durees`='" . $nbtotalsec . "'";
                    $rech .= " WHERE `ot_code` = '" . $db->escape($co) . "'";
                    $db->query($rech);
                    $ot_durees = $nbtotalsec;
                }
                $db->disconnect();

                $nbtotalsec = tps_offert_ot($co, TRUE);

                // Chaîne des techniciens traitants
                $str_tec_traitants = str_tec_traitants_ot($co, TRUE);

            }

            if ($td <> "add") {
                // Contrôle qu'un sous-traitant n'essaye pas de "hacker" un ordre
                if (((@$_SESSION["niv_log"] == 11) OR (@$_SESSION["niv_log"] == 10)) AND ($ot_codest <> @$_SESSION["code_st"]))
                    $pbm_ot = TRUE;
            }
        } else
            $pbm_ot = TRUE;
    } else {
        $td = "add";
        $ot_dateddef = $datef;
        $ot_code = crecodesession("OR");
        $co = $ot_code;
        $ot_codest = "";
        $ot_ccli = -1;
    }

    if (($tr <> "") AND ($tr <> "-1")) {
        switch (@$_SESSION["niv_log"]) {
            case 3 :
            case 10 :
                if (@$_SESSION["code_log"] <> $tr)
                    $pbm_ot = TRUE;
                break;
            case 4 :
                if ($ci <> "") {
                    if ((@$_SESSION["code_age"] <> $int_codeage) AND (@$_SESSION["code_age"] <> $int_codeages))
                        $pbm_ot = TRUE;
                }
                break;
            case 11 :
                $row = lit_enr_tec($tr, TRUE);
                if (is_array($row)) {
                    $row = encode_str($row);
                    extract($row);
                    if (@$_SESSION["code_st"] <> $tec_codest) $pbm_ot = TRUE;
                } else
                    $pbm_ot = TRUE;
                break;
            default :
                break;
        }
    } else {
        if (($tx == "i") AND ($tr == ""))
            $pbm_ot = TRUE;
    }
}

switch ($td) {
    case "add" :
        $titre = _("SAISIE BON DE TRAVAIL");
        // Si pas de code intervention -> A régulariser
        if ($ci == "")
            $ci = "--AR--";
        $ot_idsite = $si;
        break;
    case "edit" :
        $titre = _("MISE A JOUR BON DE TRAVAIL") . " " . $co;
        break;
    case "view" :
        $titre = _("DETAIL BON DE TRAVAIL") . " " . $co;
        break;
    case "del":
        $titre = _("SUPPRESSION BON DE TRAVAIL") . " " . $co;
        break;
    default:
        $titre = _("PROBLEME");
        $pbm_ot = TRUE;
        break;
}

$url_retliste = '';
if ($tx == "i")
    $url_retliste = "ot_lst.php?td=" . $td . "&tx=" . $tx . "&ca=" . $ca . "&cas=" . $cas . "&ci=" . $ci . "&tl=2&cc=" . $cc . "&si=" . $si . "&tr=" . $tr . "&co=&ord=DES&tri=Code";
else
    $url_retliste = "ot_lst.php?td=" . $td . "&tx=" . $tx . "&tl=2&ord=DES&tri=Code";
?>
    <!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 _("Fiche Ordre Sous-Traitance"); ?></title>

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

    <?PHP
    if (($td == "edit")  OR ($td == "add")) {
        ?>
        <script language="javascript">
            <!--
            var tab1_champ = ["nom:dateddef ; format:date ; masque:<?PHP echo $_SESSION['date_fmtfull']; ?> ; req:Y ; txt:<?PHP echo _("Date demande"); ?> ; stok:frmok ; stbad:frmbad",
                "nom:ddeur; format:liste ; req:Y ; txt:<?PHP echo _("Contact client"); ?> ; vmn:1 ; stok:frmok ; stbad:frmbad",
                <?PHP
                if ($td =="add")
                {
                ?>
                "nom:codesp; format:listem ; req:Y ; txt:<?PHP echo _("Spécialité"); ?> ; vmn:1 ; stok:frmok ; stbad:frmbad",
                <?PHP
                    if ((@$_SESSION["niv_log"] <> 10) AND (@$_SESSION["niv_log"] <> 11))
                    {
                ?>
                "nom:codest; format:liste ; req:Y ; txt:<?PHP echo _("Sous-traitant"); ?> ; vmn:1 ; stok:frmok ; stbad:frmbad",
                <?PHP }} else {
                    if ((@$_SESSION["niv_log"] <> 10) AND (@$_SESSION["niv_log"] <> 11))
                    {
                ?>
                "nom:codest; format:txt ; req:Y ; txt:<?PHP echo _("Sous-traitant"); ?> ; stok:frmok ; stbad:frmbad",
                <?PHP } } ?>
                "nom:codestatut; format:liste ; req:Y ; txt:<?PHP echo _("Statut"); ?> ; vmn:1 ; stok:frmok ; stbad:frmbad",
                "nom:codelieu; format:liste ; req:Y ; txt:<?PHP echo _("Lieu"); ?> ; vmn:1 ; stok:frmok ; stbad:frmbad",
                "nom:hrdv; format:liste ; req:N ; txt:<?PHP echo _("Heure rendez-vous"); ?> ; stok:frmok ; stbad:frmbad",
                "nom:mat; format:txt ; req:Y ; txt:<?PHP echo _("matériel"); ?> ; stok:frmok ; stbad:frmbad",
                <?PHP
                    if ((@$_SESSION["niv_log"] <> 4) AND (@$_SESSION["niv_log"] <> 3))
                    {
                        if ($td <> "add")
                        {
                ?>
                "nom:codetec; format:liste ; req:Y ; txt:<?PHP echo _("Responsable dossier"); ?> ; vmn:1; stok:frmok ; stbad:frmbad",
                "nom:fait; format:txt ; req:N ; txt:<?PHP echo _("Travail effectué"); ?>; stok:frmok ; stbad:frmbad",
                <?PHP
                        }
                    }
                ?>
                "nom:pbm; format:txt ; req:Y ; txt:<?PHP echo _("Travail à effectuer"); ?>; stok:frmok ; stbad:frmbad"];
            //-->
        </script>
    <?PHP
    }
    ?>


    <?PHP if (($pbm_ot == FALSE) AND ($pbm_cli == FALSE)) { ?>
        <script type="text/javascript">
            <!--
            function init_datepicker() {
                $.datepicker.setDefaults({
                    closeText: "<?PHP echo _("Fermer"); ?>",
                    prevText: "<?PHP echo _("Précédent"); ?>",
                    nextText: "<?PHP echo _("Suivant"); ?>",
                    currentText: "<?PHP echo _("Aujourd'hui"); ?>",
                    monthNames: ["<?PHP echo implode('","',$lng_tmoisf); ?>"],
                    monthNamesShort: ["<?PHP echo implode('","',$lng_tmoism); ?>"],
                    dayNames: ["<?PHP echo implode('","',$lng_tjourf); ?>"],
                    dayNamesShort: ["<?PHP echo implode('","',$lng_tjourm); ?>"],
                    dayNamesMin: ["<?PHP echo implode('","',$lng_tjours); ?>"],
                    weekHeader: "<?PHP echo _("Sem."); ?>",
                    dateFormat: "<?PHP echo $_SESSION['date_fmtshort']; ?>",
                    firstDay: 1,
                    isRTL: !1,
                    changeMonth: true,
                    changeYear: true,
                    showMonthAfterYear: !1,
                    yearSuffix: "",
                    showButtonPanel: true,
                    showOn: "both",
                    buttonImageOnly: true,
                    buttonImage: "../img/calendar.png",
                    buttonText: "<?PHP echo _("Calendrier"); ?>"
                });
                $("#dateddef").datepicker({
                    onSelect: function () {
                        $("#dateddef").blur();
                        chk_datedde('dateddef', '<?PHP echo $_SESSION['date_fmtshort']; ?>', true,true);
                    }
                });
                $("#daterdvf").datepicker({
                    onSelect: function (datesel) {
                        $("#daterdvf").blur();
                        if (chk_datedif(datesel, this.id, '<?PHP echo $_SESSION['date_fmtshort']; ?>', true, 'dateddef', '', '',false)) {
                            var messerr = chk_chp_ok_ot(this.id);
                            if (messerr != '') {
                                warn_txt(messerr);
                            }
                        }
                    }
                });
                $("#dateprevf").datepicker({
                    onSelect: function (datesel) {
                        $("#dateprevf").blur();
                        if (chk_datedif(datesel, this.id, '<?PHP echo $_SESSION['date_fmtshort']; ?>', true, 'dateddef', '', 'datefinf',false)) {
                            chk_dateprev_ot(this.id, 'gar,codetec,tect,fait', true);
                        }
                    }
                });
                $("#datefinf").datepicker({
                    onSelect: function (datesel) {
                        $("#datefinf").blur();
                        if (chk_datedif(datesel, this.id, '<?PHP echo $_SESSION['date_fmtshort']; ?>', true, 'dateddef,dateprevf', '', '',false)) {
                            chk_datefin_ot(this.id, 'gar,codetec,tect,fait,dateprevf', true);
                        }
                    }
                });
            }

            function init_all() {
                init_Body();
                init_datepicker();
                init_autohref('tac', 'change','',false);
                init_checkgar('gar', 'fgar','');
                init_checkfgar('fgar', 'gar','');
                <?php
                switch ($td)
                {
                    case "add" :
                        echo '$( "#onglets_ot" ).tabs();';
                        echo "init_warn('".nb_cli('')."cli','','back','','');";
                        echo "init_warn('".nb_tec_actifs()."tec','','back','','');";
                        echo "init_warn('".nb_age_actives()."age','','back','','');";
                        if (@$_SESSION["niv_log"] >= 3)
                            echo 'warn_cpta('.$cli_cpta.',"ot");';
                        echo 'init_ajax_st();';
                        echo 'init_ajax_st2();';
                        if ($cli_ste <> "")
                            echo "init_fensaisie('addccli',1024,600);";
                            //echo "init_fen_ctact('cli','addccli','fscomp',950,700,'ot');";
                        if ($nb_sites>0)
                        {
                            echo "init_fen_scli('tdtitsite','fscomp',910,650,'ot');";
                            echo "set_on_cursor('tdtitsite');";
                            echo "init_fen_scli('tddetsite','fscomp',910,650,'ot');";
                            echo "set_on_cursor('tddetsite');";
                        }
                        echo "init_autoraz('razdaterdvf','daterdvf','click');";
                        echo "init_autoraz('razhrdv','hrdv','click');";
                        echo "init_valid_ot('enr','ot_maj','".$_SESSION['date_fmtshort']."',tab1_champ,'','');";
                        echo "init_valid_ot('enrimp','ot_maj','".$_SESSION['date_fmtshort']."',tab1_champ,'','');";
                        break;
                    case "edit" :
                        if ($tong == 2)
                            echo '$( "#onglets_ot" ).tabs({ active: 1 });';
                        else
                            echo '$( "#onglets_ot" ).tabs();';
                        /*
                        if ((@$_SESSION["niv_log"] <> 4) AND (@$_SESSION["niv_log"] <> 3))
                            echo 'tst_aff_tpsoff(document.ot_maj.dureeoff.value);';
                        */
                        if ((@$_SESSION["niv_log"] <> 2) AND (@$_SESSION["niv_log"] <> 7) AND (@$_SESSION["niv_log"] <> 6))
                            echo 'warn_cpta('.$cli_cpta.',"ot");';
                        if ($cli_ste <> "")
                            echo "init_fensaisie('addccli',1024,600);";
                            // echo "init_fen_ctact('cli','addccli','fscomp',950,700,'ot');";
                        echo "init_autoraz('razdaterdvf','daterdvf','click');";
                        echo "init_autoraz('razhrdv','hrdv','click');";
                        echo "init_autoraz('razdateprevf','dateprevf','click');";
                        echo "init_autoraz('razdatefinf','datefinf','click');";
                        if ($nb_sites>0)
                        {
                            echo "init_fen_scli_ot('tdtitsite','fscomp',910,650,'ot');";
                            echo "set_on_cursor('tdtitsite');";
                            echo "init_fen_scli_ot('tddetsite','fscomp',910,650,'ot');";
                            echo "set_on_cursor('tddetsite');";
                        }
                        echo "chk_aff_tpsoff('dureeoff','affoffoui','affoffnon');";
                        echo "init_chk_aff_tpsoff('dureeoff','affoffoui','affoffnon');";
                        echo "init_new_fen('imprim','impression','click');";
                        echo "chk_tac('det_tac','nbtac','"._("Tâches en cours")."');";
                        echo "init_valid_ot('enr','ot_maj','".$_SESSION['date_fmtshort']."',tab1_champ,'','');";
                        echo "init_valid_ot('enrimp','ot_maj','".$_SESSION['date_fmtshort']."',tab1_champ,'','');";
                        break;
                    case "view" :
                    case "del" :
                        if ($tong == 2)
                            echo '$( "#onglets_ot" ).tabs({ active: 1 });';
                        else
                            echo '$( "#onglets_ot" ).tabs();';
                        /* if ((@$_SESSION["niv_log"] <> 4) AND (@$_SESSION["niv_log"] <> 3))
                            echo "tst_aff_tpsoff(document.ot_maj.dureeoff.value);";
                        */
                        if ($td == "del")
                            echo "warn_del('');";
                        echo "chk_aff_tpsoff('dureeoff','affoffoui','affoffnon');";
                        echo "init_new_fen('imprim','impression','click');";
                        echo 'readonly_all();';
                        break;
                }
                if ((@$_SESSION["niv_log"] <> 2) AND (@$_SESSION["niv_log"] <> 7) AND (@$_SESSION["niv_log"] <> 6))
                     echo "init_warn_focus('codelieu','lieu','codelieu');";
                if (($td == "edit") OR ($td == "view"))
                {
                    $url_detoth = "oth_maj.php?td=view&co=".$co;
                    if (($td == "edit") AND ($modif_ok==TRUE))
                       $url_detoth = "oth_maj.php?td=add&co=".$co;
                    if (url_ok($url_detoth)==TRUE)
                    {
                        echo "set_on_cursor('tect');";
                        echo "set_on_cursor('blockduree');";
                        echo "init_fen_detoth('blockduree','fscomp',1024,768);";
                        echo "init_fen_detoth('tect','fscomp',1024,768);";
                    }
                 }
                 ?>
                add_func_click('quit', 'sclose', '');
                init_autohref('lst', 'click', '<?PHP echo $url_retliste; ?>',false);
                Focus_first();
            }

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

    </head>
<body>
<?PHP
if ($tx == "m")
    include_once("../inc/entete.inc.php");
?>
    <p align="center"><span class="titrepage"><?PHP echo $titre ?></span></p>
    <!-- affiché uniquement s'il y a au moins un client, une agence active, un statut, un lieu, une civilité, un technicien dans l'agence, et un mode de règlement -->
<?PHP
if (($pbm_ot == FALSE) AND ($pbm_cli == FALSE)) {
    if ((nb_cli("") <> 0) AND (nb_st_actifs() <> 0) AND (nb_statuts() <> 0) AND (nb_lieux() <> 0) AND (nb_civ() <> 0)) {
        ?>
        <table width="100%" border="0">
            <tr>
                <td width="33%" class="annot_gras_it">
                    <?PHP
                    if ($tx == "i") {
                        echo '<input name="quit" type="button" class="bton_fgris_petit" id="quit" value="' . _("Quitter") . '">';
                        echo '<input name="lst" type="button" class="bton_fgris_petit" id="lst" value="' . _("Revenir à la liste") . '">';
                    } else
                        aff_lnk_lst_rech($url_retliste, _("Retour à la liste"), $_SERVER['HTTP_REFERER'], _("Retour à la page précédente"));
                    ?>
                </td>
                <td width="33%" valign="top" align="center" class="annot_std_gras">
                    <?PHP
                    if ($ci <> "--AR--") {
                        if ((@$_SESSION["niv_log"] == 3) OR (@$_SESSION["niv_log"] == 4) OR (@$_SESSION["niv_log"] == 5) OR (@$_SESSION["niv_log"] == 9))
                            echo _("Rattaché à l'intervention") . " " . $ci;
                        else
                            echo "&nbsp;";
                    } else {
                        if ((@$_SESSION["niv_log"] == 3) OR (@$_SESSION["niv_log"] == 4) OR (@$_SESSION["niv_log"] == 5) OR (@$_SESSION["niv_log"] == 9))
                            echo _("A régulariser");
                        else
                            echo "&nbsp;";
                    }
                    ?>
                </td>
                <td width="33%" align="right">
                    <?PHP
                    if (($td == "edit") OR ($td == "view")) {
                        $urlimp = "ot_pdf.php?co=" . $co;
                        if (url_ok($urlimp) == TRUE) {
                            echo '<div id="imprim" align="right" title="' . $urlimp . '" class="falselnk">';
                            echo '<img src="../img/print.png" title="' . _("Imprimer") . '" border="0" align="absmiddle"> ' . _("Imprimer");
                            echo '</div>';
                        } else
                            echo '&nbsp;';
                    } else
                        echo '&nbsp;';
                    ?>
                </td>
            </tr>
        </table>
        <form name="ot_maj" id="ot_maj" method="post" action="ot_enr.php">
        <input name="titre" type="hidden" id="titre" value="<?PHP echo $titre ?>">
        <input name="tx" type="hidden" id="tx" value="<?PHP echo $tx ?>">
        <input name="td" type="hidden" id="td" value="<?PHP echo $td ?>">
        <input name="code" type="hidden" id="code" value="<?PHP echo $co; ?>">
        <input name="codeint" type="hidden" id="codeint" value="<?PHP echo $ci ?>">
        <input name="codecli" type="hidden" id="codecli" value="<?PHP echo $cc ?>">
        <input name="ca" type="hidden" id="ca" value="<?PHP echo $ca ?>">
        <input name="cas" type="hidden" id="cas" value="<?PHP echo $cas ?>">
        <input name="idsite" type="hidden" id="idsite" value="<?PHP echo $si; ?>">
        <input name="nbsites" type="hidden" id="nbsites" value="<?PHP echo $nb_sites; ?>">
        <input name="nbtac" type="hidden" id="nbtac" value="<?PHP echo $nb_tac_actives; ?>">
        <input name="tr" type="hidden" id="tr" value="<?PHP echo $tr ?>">
        <input name="co" type="hidden" id="co" value="<?PHP echo $co ?>">
        <input name="nbutton" type="hidden" id="nbutton" value="">
        <?PHP if ($td == "add") { ?>
            <input name="code" type="hidden" id="code" value="<?PHP echo $ot_code ?>">
            <input name="payscli" type="hidden" id="payscli" value="<?PHP echo $scli_codepays ?>">
            <input name="depcli" type="hidden" id="depcli" value="<?PHP echo $scli_dep ?>">
        <?PHP
        }
        /* <input name="cc" type="hidden" id="cc" value="<?PHP echo $cc ?>">
        <input name="si" type="hidden" id="si" value="<?PHP echo $si ?>"> */
        ?>
        <div id="onglets_ot">
            <ul>
                <li><a href="#ot_sais"><?PHP echo _("Saisie"); ?></a></li>
                <?PHP
                if ($td <> "add")
                    echo '<li><a href="#ot_trait">'._("Traitement").'</a></li>';
                ?>
            </ul>
        <!-- détails internes de la fiche intervention -->
        <div id="ot_sais">
        <!-- Date de demande -->
        <table width="100%" border="0">
        <tr>
            <td width="160" class="rubfrm" id="f_dateddef" align="right"><?PHP echo _("Date Demande"); ?></td>
            <td>
                <input name="dateddef" type="text" id="dateddef" value="<?PHP echo $ot_dateddef; ?>" size="10"
                       maxlength="10" readonly>
            </td>
            <td align="right">
                <?PHP
                // création de la liste des Niveaux d'urgence
                $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
                $rech = "SELECT * FROM `" . TBURG . "` ORDER BY urg_niveau";
                $rows = $db->get_results($rech, ARRAY_A);
                $db->disconnect();
                cre_select_tab('urgence', 'urgence', $rows, 'urg_niveau', 'urg_des', '', $ot_urg);
                echo '<div class="annot_petit_it">(' . _("A modifier uniquement sur demande express du client") . '</div>';
                ?>
            </td>
        </tr>

        <!-- Code de l'agence qui gère le client (Si pas d'intervention rattachée) ou de l'agence et du technicien responsable si rattachée -->
        <?PHP
        if (((@$_SESSION["niv_log"] == 10) OR (@$_SESSION["niv_log"] == 11) OR (@$_SESSION["niv_log"] == 5)  OR (@$_SESSION["niv_log"] == 9))) {
        ?>
        <tr>
            <td width="160" class="rubfrm" id="f_codeage" align="right"><?PHP echo _("Agence"); ?></td>
            <td>
                <?PHP
                $txt_age = '';
                $codeage = '';
                if (($ot_codeint <> "--AR--") AND ($td <> "add")) {
                    $row = lit_enr_int($ot_codeint);
                    if (is_array($row)) {
                        $row = encode_str($row);
                        extract($row);

                        $codeage = $int_codeage;

                        // Coordonnées agence concernée
                        $row = lit_enr_age($int_codeage, TRUE);
                        extract($row);
                        $txt_age = $age_nom . " (" . $age_telf . ")";
                    }
                } else {
                    if (trim($cli_prop) <> "") {
                        $codeage = $cli_prop;

                        // Coordonnées agence concernée
                        $row = lit_enr_age($cli_prop, TRUE);
                        if (is_array($row)) {
                            $row = encode_str($row);
                            extract($row);
                        }
                        $txt_age = $age_nom . " (" . $age_telf . ")";
                    } else
                        $txt_age = "-";
                }
                $cp_age = Retournecp_Id($age_ville, TRUE);
                $ville_age = Retourneville_Id($age_ville, TRUE);
                echo '<input name="codeage" type="hidden" id="codeage" value="' . $codeage . '" readonly="1">';
                echo '<input name="nage" type="text" id="nage" value="' . $txt_age . '" size="70" maxlength="70" readonly="1">';
                ?>
            </td>
            <td align="right">
                <?PHP
                if ((((@$_SESSION["niv_log"] == 5) OR (@$_SESSION["niv_log"] == 9) OR (@$_SESSION["niv_log"] == 4) OR (@$_SESSION["niv_log"] == 3)) AND ($td == "edit")) AND ($tx == "m")) {
                    echo "<span class=\"annot_petit_gras\">";
                    echo _("Tâches") . " : ";
                    echo "</span>";

                    $tab_tac = [];
                    if (nb_tac(6, $ot_code, TRUE) > 0) {
                        $url = 'tac_lst.php?ord=DES&tri=Code&fi=8&search=' . $ot_code;
                        if (url_ok($url, TRUE) == TRUE)
                            $tab_tac[$url] = _("Voir");
                    }
                    $url = 'tac_maj.php?td=add&tr=6&cr=' . $ot_code;
                    if (url_ok($url, TRUE) == TRUE)
                        $tab_tac[$url] = _("Ajouter");
                    cre_select('tac', 'tac', $tab_tac, '', '', _("-- Faites votre choix --"), 1, FALSE, '', '', '', TRUE);

                    echo '<div id="det_tac" class="annot_upetit_it">';
                    echo '</div>';
                } else
                    echo "&nbsp;";
                ?>
            </td>
        </tr>
        <tr>
            <td width="160" class="rubfrm" id="f_codetecr" align="right"><?PHP echo _("Suivi par"); ?></td>
            <td>
                <?PHP
                // Récupération technicien agence responsable
                $codetecr = "-";
                if ($ot_codeint <> "") {
                    $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
                    $rech = "SELECT int_codetec FROM `" . TBINT . "` WHERE int_code='" . $ot_codeint . "'";
                    $row = $db->get_row($rech, ARRAY_A);
                    if ($row) {
                        extract($row);
                        if ((trim($int_codetec) <> "") AND (trim($int_codetec) <> "-1")) {
                            $row2 = lit_enr_tec($int_codetec, FALSE);
                            if (is_array($row2)) {
                                $row2 = encode_str($row2);
                                extract($row2);
                                $codetecr = $tec_nom . " " . $tec_prenom;
                            }
                        }
                    }
                    $db->disconnect();
                }
                echo '<input name="codetecr" type="text" id="codetecr" value="' . $codetecr . '" size="70" maxlength="70" readonly="1">';
                ?>
            </td>
        </tr>
        <?PHP } ?>

        <!-- Code du sous-traitant (choisi uniquement si création, affiché uniquement si édition ou suppression) -->
        <?PHP
        if ($td == "add") // Ajout = zone modifiable (on peut choisir un sous-traitant)
        {
        ?>
        <tr>
            <td width="160" class="rubfrm" id="f_spec" align="right"><?PHP echo _("Spécialité"); ?></td>
            <td>
                <?PHP
                $tab_first_options = [
                    "*" => _("Toutes les spécialités")
                ];
                // création de la liste des spécialités
                $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
                $rech = "SELECT * FROM `" . TBSP . "` ORDER BY sp_desc";
                $rows = $db->get_results($rech, ARRAY_A);
                $db->disconnect();
                cre_select_tab('codesp', 'codesp', $rows, 'sp_code', 'sp_desc', 'sp_code', '', '', _("-- Faites votre choix --"), 3, TRUE, '', '', TRUE, TRUE, FALSE, $tab_first_options);
                ?>
            </td>
        </tr>
        <tr>
            <td width="160" class="rubfrm" id="f_spniv" align="right"><?PHP echo _("Niveau minimum"); ?></td>
            <td>
                <?PHP
                // Création de la liste des spécialités
                cre_select('nivsp', 'nivsp', $spec_niveau, '', '', _("-- Faites votre choix --"), 3, TRUE);
                ?>
            </td>
        </tr>
        <?PHP
        }

        if ((@$_SESSION["niv_log"] == 5) OR (@$_SESSION["niv_log"] == 9) OR (@$_SESSION["niv_log"] == 4) OR (@$_SESSION["niv_log"] == 3)) {
        ?>
        <tr>
            <td width="160" class="rubfrm" id="f_agence" align="right"><?PHP echo _("Sous-traitant"); ?></td>
            <td>
                <?PHP
                if ($td == "add") // Ajout = zone modifiable (on peut choisir un sous-traitant)
                {
                    if ((@$_SESSION["niv_log"] == 5) OR (@$_SESSION["niv_log"] == 9) OR (@$_SESSION["niv_log"] == 4) OR (@$_SESSION["niv_log"] == 3)) {
                        echo '<select name="codest" id="codest">';
                        echo '<option>' . _("-- Faites votre choix --") . '</option>';
                        echo '</select>';
                        echo ' <img src="../img/oblig.png" align="absmiddle" alt="' . _("Champ obligatoire") . '">';
                    } else {
                        $row = lit_enr_st($_SESSION["code_st"]);
                        $row = encode_str($row);
                        extract($row);
                        $st_nomcode = $st_nom . " (" . $st_code . ")";
                        echo '<input name="codest" type="hidden" id="codest" value="' . $_SESSION["code_st"] . '">';
                        echo '<input name="nst" type="text" id="nst" value="' . $st_nomcode . '" size="50" maxlength="50" readonly>';
                    }
                } else // Edition ou suppression = zone non modifiable (affichage seul)
                {
                    $row = lit_enr_st($ot_codest);
                    $row = encode_str($row);
                    extract($row);
                    $st_nomcode = $st_nom . " (" . $st_code . ")";
                    echo '<input name="codest" type="hidden" id="codest" value="' . $ot_codest . '">';
                    echo '<input name="nst" type="text" id="nst" value="' . $st_nomcode . '" size="50" maxlength="50" readonly>';
                }
                ?>
            </td>
        </tr>
        <?PHP
        }
        ?>
        </table>


        <!-- Affichage du client -->
        <table width="100%" border="0">
        <tr>
            <td class="rubfrm" id="f_codecli" align="center" colspan="2"><?PHP echo _("Client"); ?></td>
        </tr>
        </table>
        <!-- détails client -->
        <table width="100%" border="0">
        <tr>
            <?PHP
            if ((@$_SESSION["niv_log"] == 3) OR (@$_SESSION["niv_log"] == 4) OR (@$_SESSION["niv_log"] == 5)  OR (@$_SESSION["niv_log"] == 9)) {
                ?>
                <td width="50%" align="center" valign="bottom"
                    class="ent_clisite"><?PHP echo _("Compte client"); ?></td>
            <?PHP
            }
            ?>
            <td align="center" valign="bottom" class="ent_clisite" id="tdtitsite">
                <?PHP
                if (($nb_sites > 0) AND ($modif_haut == TRUE))
                    echo '<div id="choixsitenon" style="display:none">';
                else
                    echo '<div id="choixsitenon" style="display:block">';
                if ((($td == "add") OR ($td == "edit")) AND ($cli_ste <> "") AND (@$_SESSION["niv_log"] <> 2))
                    echo '<img src="../img/sites.png" title="' . _("Choisir un site") . '" border="0" align="bottom"> ';

                echo _("Site d'intervention");
                echo '</div>';
                ?>
            </td>
        </tr>
        <tr>
            <?PHP
            if ((@$_SESSION["niv_log"] == 3) OR (@$_SESSION["niv_log"] == 4) OR (@$_SESSION["niv_log"] == 5)  OR (@$_SESSION["niv_log"] == 9)) {
                ?>
                <td width="50%" valign="top" bgcolor="#C5CED7">
                    <div id="nomste">
                    <?PHP
                    if ($cli_ste <> "")
                        echo $cli_ste . "<br />";
                    else
                        echo $cli_civilite . " " . $cli_prenom . " " . $cli_nom . "<br />";
                    echo $cli_adr1 . "<br />";
                    if ($cli_adr2 <> "")
                        echo $cli_adr2 . "<br />";
                    echo Retournecp_Id($cli_ville, TRUE) . " " . Retourneville_Id($cli_ville, TRUE) . "<br />";
                    echo _("Tel").' : '. $cli_telf;
                    if ($cli_telp <> '')
                        echo "  / " . $cli_telp;
                    ?>
                    </div>
                </td>
            <?PHP } ?>
            <td valign="top" bgcolor="#C5CED7" id="tddetsite">
                <div id="nomsite">
                    <?PHP
                    echo nom_scli($si, TRUE, FALSE, FALSE);
                    ?>
                </div>
            </td>
        </tr>
        </table>

        <!-- Contact client -->
        <table width="100%" border="0">
        <tr>
            <td width="160" class="rubfrm" id="f_ddeur" align="right"><?PHP echo _("Contact client"); ?></td>
            <td>
                <?PHP
                if (($td == "add") OR ($td == "edit")) // Ajout ou édition = zone modifiable (on peut choisir un contact)
                {
                    if ((@$_SESSION["niv_log"] == 5) OR (@$_SESSION["niv_log"] == 9) OR (@$_SESSION["niv_log"] == 4) OR (@$_SESSION["niv_log"] == 3)) {
                        if ($cli_ste <> "") {
                            // On récupère le code maître (si le client fait partie d'un regroupement)
                            $tab_maitre = [];
                            $tab_maitre = give_tab_maitre_cli($cli_code, TRUE);
                            $tab_ccli = [];
                            $tab_ccli = give_tab_ccli($cli_code, intval($ot_idsite), $tab_maitre);
                            cre_select('ddeur', 'ddeur', $tab_ccli, intval($ot_ccli), '', _("-- Faites votre choix --"));
                            $url = 'ccli_maj.php?td=add&cc=' . $cli_code . '&tx=ot';
                            if (url_ok($url, TRUE) == TRUE)
                                cre_falselnk('addccli', 'addccli', 'span', '', _("Ajouter contact"), $url, '../img/ctacts.png', _("Ajouter contact"));
                                /*
                                echo ' <span id="addccli" class="falselnk">';
                                echo '<img src="../img/ctacts.png" title="' . _("Ajouter contact") . '" border="0" align="absmiddle"> ' . _("Ajouter contact");
                                echo '</span>';
                            }*/
                        } else {
                            $txt_ccli = "";
                            $row = lit_enr_ccli_id_in_cli($ot_ccli, $cli_code);
                            if (is_array($row)) {
                                extract($row);
                                $txt_ccli = $ccli_nom . " " . $ccli_prenom;
                                $row2 = lit_enr_fonc($ccli_codefonc, TRUE);
                                if (is_array($row2)) {
                                    $row2 = encode_str($row2);
                                    extract($row2);
                                    $txt_fonc = $fonc_desc;
                                } else
                                    $txt_fonc = $ccli_codefonc;
                                $txt_ccli .= " (" . $txt_fonc;
                                $txt_ccli .= " - " . $ccli_telf . ")";
                            } else
                                $txt_ccli = _("Pas de contact");
                            echo '<input name="ddeur" type="hidden" id="ddeur" value="' . $ot_ccli . '">';
                            echo '<input name="nddeur" type="text" id="nddeur" value="' . $txt_ccli . '" size="100" maxlength="100" readonly>';
                        }
                    } else {
                        $txt_ccli = _("Pas de contact");
                        switch (intval($ot_ccli)) {
                            case -1 :
                                $txt_ccli = $cli_nom . " " . $cli_prenom . " (" . _("Contact principal");
                                $txt_ccli .= " - " . $cli_telf . ")";
                                break;
                            case 0 :
                                $row = lit_enr_scli_id($ot_idsite, TRUE);
                                if (is_array($row)) {
                                    extract($row);
                                    $txt_ccli = $scli_rnom . " " . $scli_rprenom . " (" . _("Contact site");
                                    $txt_ccli .= " - " . $scli_telf . ")";
                                }
                                break;
                            default :
                                $row = lit_enr_ccli_id_in_cli($ot_ccli, $cli_code);
                                if (is_array($row)) {
                                    extract($row);
                                    $txt_ccli = $ccli_nom . " " . $ccli_prenom;
                                    $row2 = lit_enr_fonc($ccli_codefonc, TRUE);
                                    if (is_array($row2)) {
                                        $row2 = encode_str($row2);
                                        extract($row2);
                                        $txt_fonc = $fonc_desc;
                                    } else
                                        $txt_fonc = $ccli_codefonc;
                                    $txt_ccli .= " (" . $txt_fonc;
                                    $txt_ccli .= " - " . $cli_telf . ")";
                                }
                                break;
                        }
                        echo '<input name="ddeur" type="hidden" id="ddeur" value="' . $ot_ccli . '">';
                        echo '<input name="nddeur" type="text" id="nddeur" value="' . $txt_ccli . '" size="100" maxlength="100" readonly>';
                    }
                } else // Vue ou suppression = zone non modifiable (affichage seul)
                {
                    $txt_ccli = _("Pas de contact");
                    switch (intval($ot_ccli)) {
                        case -1 :
                            $txt_ccli = $cli_nom . " " . $cli_prenom . " (" . _("Contact principal");
                            $txt_ccli .= " - " . $cli_telf . ")";
                            break;
                        case 0 :
                            $row = lit_enr_scli_id($ot_idsite, TRUE);
                            if (is_array($row)) {
                                extract($row);
                                $txt_ccli = $scli_rnom . " " . $scli_rprenom . " (" . _("Contact site");
                                $txt_ccli .= " - " . $ccli_telf . ")";
                            }
                            break;
                        default :
                            $row = lit_enr_ccli_id_in_cli($ot_ccli, $cli_code);
                            if (is_array($row)) {
                                extract($row);
                                $txt_ccli = $ccli_nom . " " . $ccli_prenom;
                                $row2 = lit_enr_fonc($ccli_codefonc, TRUE);
                                if (is_array($row2)) {
                                    $row2 = encode_str($row2);
                                    extract($row2);
                                    $txt_fonc = $fonc_desc;
                                } else
                                    $txt_fonc = $ccli_codefonc;
                                $txt_ccli .= " (" . $txt_fonc;
                                $txt_ccli .= " - " . $cli_telf . ")";
                            }
                            break;
                    }
                    echo '<input name="ddeur" type="hidden" id="ddeur" value="' . $o_ccli . '">';
                    echo '<input name="nddeur" type="text" id="nddeur" value="' . $txt_ccli . '" size="100" maxlength="100" readonly="1">';
                }
                ?>
            </td>
        </tr>

        <!-- Paramètres de la demande -->
            <tr>
                <td width="160" class="rubfrm" id="f_statut" align="right"><?PHP echo _("Statut"); ?></td>
                <td>
                    <?PHP
                    // Création de la liste des Statuts
                    if ($ot_codestatut <> 'CLOT')
                        $rows = give_rows_statut('CLOT');
                    else
                        $rows = give_rows_statut();
                    cre_select_tab('codestatut', 'codestatut', $rows, 'statut_code', 'statut_desc', '', $ot_codestatut, '', _("-- Faites votre choix --"));
                    ?>
                </td>
            </tr>
            <tr>
                <td width="160" class="rubfrm" id="f_lieu" align="right"><?PHP echo _("Lieu"); ?></td>
                <td>
                    <?PHP
                    // création de la liste des Types Lieux
                    $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
                    $rech = "SELECT * FROM `" . TBLIEU . "` ORDER BY lieu_desc";
                    $rows = $db->get_results($rech, ARRAY_A);
                    $db->disconnect();
                    cre_select_tab('codelieu', 'codelieu', $rows, 'lieu_code', 'lieu_desc', '', $ot_codelieu, '', _("-- Faites votre choix --"));
                    ?>
                </td>
            </tr>

        <!-- Date de RDV -->
            <tr>
                <td width="160" class="rubfrm" id="f_rdv" align="right"><?PHP echo _("Date RDV"); ?></td>
                <td>
                    <input name="daterdvf" type="text" id="daterdvf" value="<?PHP echo $ot_daterdvf ?>" size="10"
                           maxlength="10" readonly>
                    <?PHP
                    echo ' <img src="../img/raz.png" id ="razdaterdvf" border="0" align="absmiddle">';
                    echo ' / ' . _("heure") . ' : ';

                    // $tab_heures = give_tab_heures(0, 86400, ($pla_stepmin * 60));
                    $tab_heures = give_tab_heures(($pprm_firsthour * 3600), ($pprm_lasthour * 3600), ($pla_stepmin * 60));

                    cre_select('hrdv', 'hrdv', $tab_heures, $ot_hrdv);

                    echo ' <img src="../img/raz.png" id ="razhrdv" border="0" align="absmiddle">';
                    ?>
                </td>
            </tr>

        <!-- matériel et problème de la demande -->
            <tr>
                <td width="160" class="rubfrm" id="f_mat" align="right"><?PHP echo _("Matériel"); ?></td>
                <td>
                    <textarea name="mat" rows="5" id="mat"><?PHP echo $ot_mat; ?></textarea>
                </td>
                <td width="16">
                    <?PHP
                    if (($td == "add") OR ($td == "edit"))
                        echo '<img src="../img/oblig.png" align="absmiddle" align="top">';
                    else
                        echo '&nbsp;';
                    ?>
                </td>
            </tr>
            <tr>
                <td width="160" class="rubfrm" id="f_pbm">
                    <div align="right"><?PHP echo _("Travail à effectuer"); ?></div>
                </td>
                <td>
                    <textarea name="pbm" rows="5" id="pbm"><?PHP echo $ot_pbm; ?></textarea>
                </td>
                <td width="16">
                    <?PHP
                    if (($td == "add") OR ($td == "edit"))
                        echo '<img src="../img/oblig.png" align="absmiddle" align="top">';
                    else
                        echo '&nbsp;';
                    ?>
                </td>
            </tr>

        <!-- Intervention sous garantie ou pas ? -->
            <tr>
                <td width="160" class="rubfrm" id="f_gar" align="right"><?PHP echo _("Garantie"); ?></td>
                <td>
                    <?PHP
                    if (($td == "add") OR ($td == "edit")) {
                        cre_select('gar', 'gar', $non_oui, intval($ot_gar));
                        echo ' <span class="annot_std_gras">' . _("Référence facture") . ' :</span>';
                        echo '<input name="fgar" type="text" id="fgar" value="' . $ot_fgar . '" size="30" maxlength="30">';
                        echo '<span class="annot_petit_it"> (' . _("Obligatoire si garanti") . ')</span>';
                    } else {
                        echo '<input name="gar" type="text" id="gar" value="' . $non_oui[$ot_gar] . '" size="3" maxlength="3" readonly>';
                        if ($ot_gar == 1) {
                            echo ' <span class="annot_std_gras">' . _("Référence facture") . ' :</span>';
                            echo '<input name="fgar" type="text" id="fgar" value="' . $ot_fgar . '" size="30" maxlength="30" readonly>';
                        }

                    }
                    ?>
                </td>
            </tr>
        </table>
        </div>
        <?PHP
        if ($td <> "add") {
            echo '<div id="ot_trait">';

            $aff_ok = TRUE;
            $modif_ok = TRUE;
            switch ($td) {
                case "add" :
                    $aff_ok = FALSE;
                    break;
                default :
                    switch (@$_SESSION["niv_log"]) {
                        case 3 :
                            $modif_ok = FALSE;
                            if ($tr <> @$_SESSION["code_log"])
                                $aff_ok = FALSE;
                            break;
                        case 4 :
                            $modif_ok = FALSE;
                            if (($tr <> "") AND ($tr <> "-1")) {
                                $row = lit_enr_tec($tr, TRUE);
                                if (is_array($row)) {
                                    $row = encode_str($row);
                                    extract($row);
                                    if ($tec_codeage <> @$_SESSION["code_log"])
                                        $aff_ok = FALSE;
                                }
                            }
                            break;
                        default :
                            break;
                    }
                    break;
            }


            if ($aff_ok == TRUE) {
            ?>
            <table width="100%" border="0">
            <!-- Technicien Responsable -->
            <tr>
                <td width="160" class="rubfrm" id="f_codetec"
                    align="right"><?PHP echo _("Responsable dossier"); ?></td>
                <td>
                    <?PHP
                    if ($modif_ok == TRUE) {
                        $tab_first_options = [
                            "-1" => _("-- Dossier non affecté --")
                        ];
                        $rows = give_tab_rows_tec_st($ot_codest);
                        cre_select_tab('codetec', 'codetec', $rows, 'tec_code', 'tec_nom', 'tec_prenom-tec_codest', $ot_codetec, '', _("-- Faites votre choix --"), 1, FALSE, '', '', TRUE, TRUE, FALSE, $tab_first_options);
                    }
                    ?>
                </td>
            </tr>

            <!-- Techniciens traitants -->
            <tr>
                <td width="160" class="rubfrm" id="f_tect"
                    align="right"><?PHP echo _("Technicien(s) traitant(s)"); ?></td>
                <td>
                    <?PHP
                    echo '<div id="tect" style="height:50px;overflow:auto;">';
                    echo $str_tec_traitants;
                    echo '</div>';
                    ?>
                </td>
            </tr>

            <!-- Travail effectué -->
            <tr>
                <td width="160" class="rubfrm" id="f_duree"
                    align="right"><?PHP echo _("Temps travaillé"); ?></td>
                <td>
                    <!-- détails internes du temps passé -->
                    <?PHP
                    if ($modif_ok == TRUE) {
                        if (url_ok($url_detoth) == TRUE) {
                            echo '<span id="blockduree" class="falselnk">';
                            echo '<input name="duree" type="text" id="duree" value="' . heure_to_hhmm(sec_heure($ot_durees, 3, TRUE)) . '" size="6" maxlength="6" readonly="1">';
                            echo ' <img src="../img/clock.png" title="' . _("Détails horaires") . '" border="0" align="absmiddle">';
                            echo '</span>';
                        } else
                            echo '<input name="duree" type="text" id="duree" value="' . heure_to_hhmm(sec_heure($ot_durees, 3, TRUE)) . '" size="6" maxlength="6" readonly="1">';
                    } else
                        echo '<input name="duree" type="text" id="duree" value="' . heure_to_hhmm(sec_heure($ot_durees, 3, TRUE)) . '" size="6" maxlength="6" readonly="1">';
                    echo '<span class="annot_petit_it">';
                    echo '<div id="affoffoui" style="display:block">';
                    echo _("Dont temps offert") . ' : ';
                    echo ' <input name="dureeoff" type="text" id="dureeoff" value="' . heure_to_hhmm(sec_heure($nbtotalsecoff), 3, TRUE) . '" size="6" maxlength="6" readonly="1">';
                    echo '</div>';
                    echo '<div id="affoffnon" style="display:none">';
                    echo '&nbsp;';
                    echo '</div>';
                    echo '</span>';
                    ?>
                </td>
            </tr>
            <tr>
                <td width="160" class="rubfrm" id="f_fait"
                    align="right"><?PHP echo _("Travail effectué"); ?></td>
                <td>
                    <?PHP
                    echo '<textarea name="fait" rows="5" id="fait"';
                    if ($modif_ok == FALSE)
                        echo ' readonly';
                    echo '>' . $ot_fait . '</textarea>';
                    ?>
                </td>
            </tr>

            <!-- Date d'appel de l'agence une fois le dossier traité -->
            <tr>
                <td width="160" class="rubfrm" id="f_dateprevf"
                    align="right"><?PHP echo _("Agence prévenue le"); ?></td>
                <td>
                    <input name="dateprevf" type="text" id="dateprevf" value="<?PHP echo $ot_dateprevf ?>"
                           size="10" readonly>
                    <?PHP
                    if (($td == "edit") AND ($modif_ok == TRUE))
                        echo ' <img src="../img/raz.png" id ="razdateprevf" border="0" align="absmiddle">';
                    ?>
                </td>
            </tr>

            <!-- Date de clôture du dossier -->
            <tr>
                <td width="160" class="rubfrm" id="f_datefinf"
                    align="right"><?PHP echo _("Dossier clôt le"); ?></td>
                <td>
                    <input name="datefinf" type="text" id="datefinf" value="<?PHP echo $ot_datefinf ?>"
                           size="10" readonly>
                    <?PHP
                    if (($td == "edit") AND ($modif_ok == TRUE))
                        echo ' <img src="../img/raz.png" id="razdatefinf" border="0" align="absmiddle">';
                    echo '<div class="annot_petit_it">' . _("Si vous saisissez une date, le dossier sera clôt. Entrez vos pièces et prestations AVANT de clôre") . '</div>';
                    ?>
                </td>
            </tr>
            </table>
            <?PHP } else { ?>
                <input name="dateprevf" type="hidden" id="dateprevf" value="<?PHP echo $ot_dateprevf ?>">
                <input name="datefinf" type="hidden" id="datefinf" value="<?PHP echo $ot_datefinf ?>">
            <?PHP
            }

            echo '</div>';
        }
        ?>
        </div>
        <!-- Fin de zone exclue si création -->

        <p align="center">
            <?PHP

            switch ($td) {
                case "add" :
                case "edit" :
                    echo '<input name="RAZ" type="reset" class="bton_std" id="RAZ" value="' . _("Réinitialiser") . '">';
                    echo '<input name="enr" type="button" class="bton_std" id="enr" value="' . _("Enregistrer") . '">';
                    echo '<input name="enrimp" type="button" class="bton_std" id="enrimp" value="' . _("Enregistrer & Imprimer") . '">';
                    break;
                case "del" :
                    echo '<input name="del" type="submit" class="bton_std" id="del" value="' . _("Supprimer") . '">';
                    break;
            }
            ?>
        </p>
        </form>

        <!-- affiché uniquement s'il y a au moins un client, une agence active, une origine, un statut, un lieu, une civilité, un technicien dans l'agence, et un mode de règlement -->
    <?PHP
    } else {
        if (nb_cli("") == 0)
            pop_ret_auto(_("Aucun client"), 'warn', $lnk_cli_lst);

        if (nb_age_actives() == 0)
            pop_ret_auto( _("Aucune agence active"), 'warn', 'age_lst.php');

        if (nb_orig() == 0)
            pop_ret_auto(_("Aucune origine d'intervention"), 'warn', 'orig_lst.php');

        if (nb_statuts() == 0)
            pop_ret_auto( _("Aucun statut d'intervention"),'warn',  'statut_lst.php');

        if (nb_lieux() == 0)
            pop_ret_auto( _("Aucun lieu d'intervention"), 'warn', 'lieu_lst.php');

        if (nb_civ() == 0)
            pop_ret_auto(_("Aucune civilité"), 'warn', 'civ_lst.php');

        if (nb_tec("") == 0)
            pop_ret_auto( _("Aucun technicien"), 'warn', 'tec_lst.php?td=std&tl=1');

        if (nb_reg() == 0)
            pop_ret_auto( _("Aucun mode règlement"), 'warn', 'reg_lst.php');

        if (nb_st_actifs() == 0)
            pop_ret_auto(_("Aucun sous-traitant actif"), 'warn', 'st_lst.php');

        if ($tx == "i")
            close_fen_auto('', '');
    }
}
else
{
	if ($tx == 'i')
		close_fen_auto(_("Problème de paramètres"),'');
	else
		pop_ret_auto(_("Problème de paramètres"), 'warn', 'index.php');
}
if ($tx == "m")
    include_once("pied.php");
else {
    echo '</body>';
    echo '</html>';
}
?>