<?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");
header('Content-Type: text/html; charset=utf-8');

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_droits.inc.php");
include_once("../inc/fic_int.inc.php");
include_once("../inc/fic_pdt.inc.php");
include_once("../inc/fic_plan.inc.php");
include_once("../inc/fic_prm.inc.php");
include_once("../inc/fic_rdv.inc.php");
include_once("../inc/fic_rel.inc.php");
include_once("../inc/fic_sig.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("../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(@$_SESSION["code_log"]);
check_modules();

$pbm_inth = FALSE;
$enr_ok = false;
$msg = "";
$inth_codeint = "-1";
$td = 'add'; // Le mode par défaut est en ajout
$tdh = 'add'; // Mode $td pour l'historique affiché (si $id <>0)
$inth_signee = FALSE;
$inth_chx_pbm = FALSE;
// $url_retour = "";
$fen_chx_pbm = FALSE;
$rpbm_atraiter = FALSE;
$add_sig = TRUE; // Peut ajouter signature
$view_sig = FALSE; // Peut voir signature
$acpte = 0;
$pxrevient = 0;
$url_traitepbm = '';
$str_pbm = '';
$str_pbmfait = '';
$txtfaitint = '';
$action_to_do = '';

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

if (isset($_GET['td'])) {
    $td = @$_GET['td'];
    if (($td <> "edit") AND ($td <> "del"))
        $pbm_inth = TRUE;
    else
        $tdh = $td;
}

if (isset($_GET['ci']))
    $codeint = @$_GET['ci'];
else
    $codeint = @$_POST['ci'];

$id = 0;
if (isset($_GET['id']))
    $id = intval(@$_GET['id']);
else
    $id = intval(@$_POST['id']);
$_SESSION["idinth"] = $id;

if (isset($_GET['cc']))
    $cc = @$_GET['cc'];
else
    $cc = @$_POST['cc'];
if (isset($_GET['co']))
    $co = @$_GET['co'];
else
    $co = @$_POST['co'];
if (isset($_GET['ca']))
    $ca = @$_GET['ca'];
else
    $ca = @$_POST['ca'];
if (isset($_GET['si']))
    $si = intval(@$_GET['si']);
else
    $si = intval(@$_POST['si']);
if (isset($_GET['cas']))
    $cas = @$_GET['cas'];
else
    $cas = @$_POST['cas'];
if (isset($_GET['tr']))
    $tecr = @$_GET['tr'];
else
    $tecr = @$_POST['tr'];
if (isset($_GET['cat']))
    $codecat = @$_GET['cat'];
else
    $codecat = @$_POST['cat'];
if (isset($_GET['ac']))
    $acpte = floatval(@$_GET['ac']);
else
    $acpte = floatval(@$_POST['ac']);

// 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();

$url_lst = 'inth_maj.php?ci=' . $codeint . '&cc=' . $cc . '&co=' . $co . '&ca=' . $ca . '&cas=' . $cas . '&si=' . $si . '&tr=' . $tecr . '&cat=' . $codecat;

if ($codeint <> "") {
    $row = lit_enr_int($codeint);
    if (is_array($row)) {
        $row = encode_str($row);
        extract($row);
        if (datetolocal($int_datefin) <> "") {
            $td = "view";
            $tdh = "view";
        }
        $pxrevient = px_revient_int($codeint, TRUE);
    } else
        $pbm_inth = TRUE;
} else
    $pbm_inth = TRUE;

if ($pbm_inth == FALSE) {
    // vérification de la signature historique (si ID)
    // Construction historique produits (si ID)
    if ($id > 0) {
        $row2 = lit_enr_inth($id);
        if (is_array($row2)) {
            $row2 = encode_str($row2);
            extract($row2);
        } else
            $pbm_inth = TRUE;

        if ($pbm_inth == FALSE) {
            if (($inth_codetec <> @$_SESSION["code_log"]) AND (@$_SESSION["niv_log"] == 3)) {
                $td = "view";
                $tdh = "view";
            }

            $row3 = lit_enr_sig_code(1, $codeint, $id);
            if (is_array($row3)) {
                $row3 = encode_str($row3);
                extract($row3);
                $_SESSION["idinthsig"] = $sig_id;
                $inth_signee = TRUE;
                $tdh = "view";
            }
        }
    }
}

if ($pbm_inth == FALSE) {
    if (($ca <> "") AND ($cas <> "")) {
        $row = lit_enr_age($ca, TRUE);
        if (is_array($row)) {
            $row = encode_str($row);
            extract($row);
        } else
            $pbm_inth = TRUE;

        $row = lit_enr_age($cas, TRUE);
        if (is_array($row)) {
            $row = encode_str($row);
            extract($row);
        } else {
            if ($cas <> "-1")
                $pbm_inth = TRUE;
        }

        switch (@$_SESSION["niv_log"]) {
            case 3 :
            case 4 :
                // vérification tentative de hack d'une agence ou d'un technicien agence
                if (($ca <> @$_SESSION["code_age"]) AND ($cas <> @$_SESSION["code_age"]))
                    $pbm_inth = TRUE;
                break;
            default :
                break;
        }
    } else
        $pbm_inth = TRUE;
}

// Enregistrement si validation
if ($pbm_inth == FALSE) {
    switch ($_POST["nbutton"]) {
        case "enr" :
            $action_to_do = 'add';
            break;
        case "val" :
            $action_to_do = 'valid';
            break;
        case "del" :
            $action_to_do = 'del';
            break;
        default :
            break;
    }

    if ($action_to_do <> '') {
        // On récupère l'ancien ID RDV
        $ex_idrdv = 0;
        if ($id > 0) {
            $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
            $rech2 = "SELECT inth_idrdv FROM `" . TBINTH . "`";
            $rech2 .= " WHERE inth_id=" . $id;
            $row2 = $db->get_row($rech2, ARRAY_A);
            if ($row2) {
                $row2 = encode_str($row2);
                extract($row2);
                $ex_idrdv = $inth_idrdv;
            }
            $db->disconnect();
        }

        if ($action_to_do <> 'del') {
            $idrdv = intval(@$_POST["rdv"]);
            $datesais = @$_POST["date"];
            if ($datesais <> "")
                $date = datetomysql($datesais);
            else
                $date = "";
            $codetec = @$_POST["codetec"];
            $codelieu = @$_POST["codelieu"];
            $heurea = @$_POST["heurea"];
            $heurea_full = $heurea . ":00";
            $heured = @$_POST["heured"];
            $heured_full = $heured . ":00";
            $indice = @$_POST["ind"];
            $offert = 0;
            if (strtolower(@$_POST["offert"]) == "on")
                $offert = 1;
            $fait = @$_POST["fait"];
            $acodemt = @$_POST["a_mt"];
            $aheured = @$_POST["a_heured"];
            if ($aheured == "")
                $aheured = "00:00";
            $aheured_full = $aheured . ":00";
            $aheuref = @$_POST["a_heuref"];
            if ($aheuref == "")
                $aheuref = "00:00";
            $aheuref_full = $aheuref . ":00";
            $akm = floatval(@$_POST["a_km"]);
            $acd = floatval(@$_POST["a_cd"]);
            $afa = floatval(@$_POST["a_fa"]);
            $afad = @$_POST["a_fad"];
            $rcodemt = @$_POST["r_mt"];
            $rheured = @$_POST["r_heured"];
            if ($rheured == "")
                $rheured = "00:00";
            $rheured_full = $rheured . ":00";
            $rheuref = @$_POST["r_heuref"];
            if ($rheuref == "")
                $rheuref = "00:00";
            $rheuref_full = $rheuref . ":00";
            $rkm = floatval(@$_POST["r_km"]);
            $rcd = floatval(@$_POST["r_cd"]);
            $rfa = floatval(@$_POST["r_fa"]);
            $rfad = @$_POST["r_fad"];
            $codeuser = @$_SESSION["code_log"];

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

            // Traitement de la fiche historique intervention
            switch ($action_to_do) {
                // Fiche remplie : On ajoute l'historique
                case "add" :
                    $rech = "INSERT INTO `" . TBINTH . "`";
                    $rech .= " (inth_datecrea,inth_codecrea,inth_datemod,inth_codemod,inth_codeint,inth_idrdv,inth_date,inth_codetec,inth_codelieu,";
                    $rech .= "inth_heurea,inth_heured,inth_codeind,inth_offert,inth_fait,inth_acodemt,inth_aheured,inth_aheuref,inth_akm,inth_acd,inth_afrais,";
                    $rech .= "inth_afraisd,inth_rcodemt,inth_rheured,inth_rheuref,inth_rkm,inth_rcd,inth_rfrais,inth_rfraisd) VALUES";
                    $rech .= " ('$datea','$codeuser','$datea','$codeuser','$codeint','$idrdv','$date','$codetec','$codelieu','$heurea_full','$heured_full','$indice',";
                    $rech .= "'$offert','" . $db->escape($fait) . "','$acodemt','$aheured_full','$aheuref_full','$akm','$acd','$afa','$afad','$rcodemt','$rheured_full',";
                    $rech .= "'$rheuref_full','$rkm','$rcd','$rfa','$rfad')";

                    $enr_ok = TRUE;
                    break;

                case "valid" :
                    if ($id > 0) {
                        $rech = "UPDATE `" . TBINTH;
                        $rech .= "` SET `inth_datemod`='" . $datea . "',`inth_codemod`='" . $codeuser . "', `inth_idrdv`='" . $idrdv . "', `inth_date`='" . $date . "',";
                        $rech .= " `inth_codetec`='" . $codetec . "', `inth_codelieu`='" . $codelieu . "', `inth_heurea`='" . $heurea_full . "',";
                        $rech .= " `inth_heured`='" . $heured_full . "', `inth_offert`='" . $offert . "', `inth_fait`='" . $db->escape($fait) . "',";
                        $rech .= " `inth_acodemt`='" . $acodemt . "',`inth_aheured`='" . $aheured_full . "', `inth_codeind`='" . $indice . "',";
                        $rech .= "`inth_aheuref`='" . $aheuref_full . "',";
                        $rech .= " `inth_akm`='" . $akm . "',`inth_acd`='" . $acd . "', `inth_afrais`='" . $afa . "', `inth_afraisd`='" . $afad . "',";
                        $rech .= " `inth_rcodemt`='" . $rcodemt . "',`inth_rheured`='" . $rheured_full . "', `inth_rheuref`='" . $rheuref_full . "',";
                        $rech .= " `inth_rkm`='" . $rkm . "',`inth_rcd`='" . $rcd . "', `inth_rfrais`='" . $rfa . "', `inth_rfraisd`='" . $rfad . "'";
                        $rech .= "  WHERE `inth_id` = '" . $id . "'";

                        $enr_ok = TRUE;
                    }
                    break;
            }

            if (trim($rech) <> "") {
                $db->query($rech);
                // Mise à jour des produits historique intervention
                // Et des taxes parafiscales
                if (($action_to_do == "add") OR ($action_to_do == "valid")) {
                    if ($id == 0)
                        $id = $db->insert_id;

                    // On met à jour l'enregistrement signature
                    if (intval($_SESSION["idinthsig"]) > 0) {
                        $rech = "UPDATE `" . TBSIG . "` SET `sig_idhisto`='" . $id . "'";
                        $rech .= " WHERE `sig_id` = '" . intval($_SESSION["idinthsig"]) . "'";
                        $db->query($rech);
                    }

                    // On supprime d'abord tous les produits dans l'historique
                    $rech2 = "DELETE FROM `" . TBPDTIH . "` WHERE `pdtih_idhisto` = '$id'";
                    $db->query($rech2);

                    // On insère les produits dans l'historique
                    if (count($_SESSION["pdtih"]) > 0) {
                        foreach ($_SESSION["pdtih"] as $row) {
                            $row = encode_str($row);
                            extract($row);

                            $rech2 = "INSERT INTO `" . TBPDTIH . "`";
                            $rech2 .= " (pdtih_codeint,pdtih_idhisto,pdtih_codepdt,pdtih_frompdt,pdtih_puttc,pdtih_codetva,pdtih_qte,pdtih_ns,pdtih_texte,pdtih_facture) VALUES";
                            $rech2 .= " ('$codeint','$id','" . $db->escape($pdtih_codepdt) . "',";
                            $rech2 .= "'" . $db->escape($pdtih_frompdt) . "','$pdtih_puttc','$pdtih_codetva',";
                            $rech2 .= "'$pdtih_qte','" . $db->escape($pdtih_ns) . "',";
                            $rech2 .= "'" . $db->escape($pdtih_texte) . "','$pdtih_facture')";
                            $db->query($rech2);
                        }
                    }

                    // On supprime d'abord toutes les taxes dans l'historique
                    $rech2 = "DELETE FROM `" . TBTPFIH . "` WHERE `tpfih_idhisto` = '$id'";
                    $db->query($rech2);

                    // On insère les taxes dans l'historique
                    if (count($_SESSION["tpfih"]) > 0) {
                        foreach ($_SESSION["tpfih"] as $row) {
                            extract($row);

                            $rech2 = "INSERT INTO `" . TBTPFIH . "`";
                            $rech2 .= " (tpfih_codeint,tpfih_idhisto,tpfih_codetpf,tpfih_valeur,tpfih_codetva,tpfih_qte,tpfih_texte) VALUES";
                            $rech2 .= " ('$codeint','$id','" . $db->escape($tpfih_codetpf) . "',";
                            $rech2 .= "'$tpfih_valeur','$tpfih_codetva',";
                            $rech2 .= "'$tpfih_qte',";
                            $rech2 .= "'" . $db->escape($tpfih_texte) . "')";
                            $db->query($rech2);
                        }
                    }

                    // On "vide" d'abord les travaux sur problèmes déjà saisis
                    $rech2 = "UPDATE `" . TBRPBM . "` SET `rpbm_fait`='',";
                    $rech2 .= " `rpbm_datett`='', `rpbm_codeint`=''";
                    $rech2 .= " WHERE `rpbm_idinth` = '" . $id . "'";
                    $db->query($rech2);

                    // On met à jour les problèmes traités
                    if (count($_SESSION["pbm_faits"]) > 0) {
                        foreach ($_SESSION["pbm_faits"] as $key => $value) {
                            if ($value <> '') {
                                $rech2 = "UPDATE `" . TBRPBM . "` SET `rpbm_fait`='" . $value . "',";
                                $rech2 .= " `rpbm_datett`='" . $date . "', `rpbm_idinth`='" . $id . "', `rpbm_codeint`='" . $codeint . "'";
                                $rech2 .= " WHERE `rpbm_id` = '" . $key . "'";
                                $db->query($rech2);
                            }
                        }
                    }

                }

                // On met à jour le RDV rattaché (s'il y en a un)
                if ($idrdv > 0) {
                    $rech = "UPDATE `" . TBRDV . "` SET `rdv_datemod`='" . $datea . "', `rdv_codemod`='" . $codeuser . "',";
                    $rech .= " `rdv_honore`='1'";
                    $rech .= " WHERE `rdv_id` = '" . $idrdv . "'";
                    $db->query($rech);
                } else {
                    if ($ex_idrdv > 0) {
                        $rech = "UPDATE `" . TBRDV . "` SET `rdv_datemod`='" . $datea . "', `rdv_codemod`='" . $codeuser . "',";
                        $rech .= " `rdv_honore`='0'";
                        $rech .= " WHERE `rdv_id` = '" . $ex_idrdv . "'";
                        $db->query($rech);
                    }
                }

                // On met à jour les check-list rattachées
                $tab_clcgintc = give_tab_clcg_full_intc($codecat, FALSE);

                if (count($tab_clcgintc) > 0) {
                    // On supprime d'abord toutes les check-list dans l'historique
                    $rech2 = "DELETE FROM `" . TBCLCGINTH . "` WHERE `clcginth_idinth` = '$id'";
                    $db->query($rech2);

                    $tab_tmp = [];
                    $code_clcg_courant = '';

                    // On réinjecte les choix effectués
                    foreach ($tab_clcgintc as $key => $value) {
                        $code_clcg_courant = $code_clcg;

                        $tab_tmp = $value;

                        foreach ($tab_tmp as $key2 => $value2) {
                            $choixclc = intval(@$_POST['clcg_' . $key . '_clc_' . $key2]);
                            $rech2 = "INSERT INTO `" . TBCLCGINTH . "`";
                            $rech2 .= " (clcginth_codeclcg,clcginth_codeclc,clcginth_idinth,clcginth_choix) VALUES";
                            $rech2 .= " ('" . $db->escape($key) . "','" . $db->escape($key2) . "',";
                            $rech2 .= "'$id','$choixclc')";
                            $db->query($rech2);
                        }
                    }
                }
            }

            // RAZ des données de session
            $_SESSION["idinthsig"] = 0;

            $db->disconnect();
        } else {
            if ($id > 0) {
                $enr_ok = TRUE;

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

                // On met à jour l'enregistrement signature
                if (intval($_SESSION["idinthsig"]) > 0) {
                    $rech = "UPDATE `" . TBSIG . "` SET `sig_idhisto`='" . $id . "'";
                    $rech .= " WHERE `sig_id` = '" . intval($_SESSION["idinthsig"]) . "'";
                    $db->query($rech);
                }

                // On "libère" le RDV (il redevient non honoré), s'il y en a un de rattaché
                if ($ex_idrdv > 0) {
                    $rech = "UPDATE `" . TBRDV . "` SET `rdv_datemod`='" . $datea . "', `rdv_codemod`='" . $codeuser . "',";
                    $rech .= " `rdv_honore`='0'";
                    $rech .= " WHERE `rdv_id` = '" . $ex_idrdv . "'";
                    $db->query($rech);
                }

                // On met à jour les problèmes rattachés(s'il y en a)
                $rech = "UPDATE `" . TBRPBM . "` SET `rpbm_idinth`='0'";
                $rech .= " WHERE `rpbm_idinth` = '" . $id . "'";
                $db->query($rech);

                // On supprime tous les produits dans l'historique
                $rech = "DELETE FROM `" . TBPDTIH . "` WHERE `pdtih_idhisto` = '$id'";
                $db->query($rech);

                // On supprime toutes les taxes dans l'historique
                $rech = "DELETE FROM `" . TBTPFIH . "` WHERE `tpfih_idhisto` = '$id'";
                $db->query($rech);

                // On supprime toutes les check-list dans l'historique
                $rech2 = "DELETE FROM `" . TBCLCGINTH . "` WHERE `clcginth_idinth` = '$id'";
                $db->query($rech2);

                // On supprime finalement l'historique intervention
                $rech = "DELETE FROM `" . TBINTH . "` WHERE `inth_id` = '$id'";
                $db->query($rech);

                // RAZ des données de session
                $_SESSION["idinthsig"] = 0;

                $db->disconnect();
            }
        }
    } else {
        $_SESSION["pdtih"] = give_tab_pdtih($codeint, $id);
        $_SESSION["tpfih"] = give_tab_tpfih($codeint, $id);
        $_SESSION["clcgintc"] = give_tab_clcg_full_intc($codecat);
    }
}

if ($pbm_inth == FALSE) {
    // Récupération du total travaillé & Techniciens traitants
    $nbtotalsec = 0;
    $nbtotalsecoff = 0;
    $str_tec_traitants = "";

    $nbtotalsec = tps_travaille_int($codeint, TRUE);
    $nbtotalsecoff = tps_offert_int($codeint, TRUE);
    $str_tec_traitants = str_tec_traitants_int($codeint, TRUE);
}

if ($pbm_inth == FALSE) {
    // En cas de création, la devise par défaut de l'intervention dossier est celle du compte qui saisi
    if ($td == "add") {
        switch (@$_SESSION["niv_log"]) {
            case 3 :
            case 4 :
                $int_codeadev = give_dev_codea_defaut_age($_SESSION["code_age"], $_SESSION["lng"], TRUE);
                break;
            default :
                $int_codeadev = give_dev_codea_defaut($_SESSION["lng"], TRUE);
                break;
        }
    } else
        // Sinon, on récupère le code devise de l'intervention déjà créée
        $int_codeadev = give_dev_codea_defaut_int($int_code, $_SESSION["lng"], TRUE);

    // On récupère le code devise du compte qui visualise
    switch (@$_SESSION["niv_log"]) {
        case 3 :
        case 4 :
            $codeadev_local = give_dev_codea_defaut_age($_SESSION["code_age"], $_SESSION["lng"], TRUE);
            break;
        default :
            $codeadev_local = give_dev_codea_defaut($_SESSION["lng"], TRUE);
            break;
    }

}

switch (@$_SESSION["niv_log"]) {
    // Client : on ne peut que voir
    case 1 :
        $td = "view";
        $tdh = "view";
        $add_sig = FALSE;
        break;
    case 3 :
    case 4 :
        // vérification tentative de hack d'une agence ou d'un technicien agence
        if (($ca <> @$_SESSION["code_age"]) AND ($cas <> @$_SESSION["code_age"]))
            $pbm_inth = TRUE;
        break;
    case 6 :
    case 7 :
        // vérification tentative de hack d'un donneur d'ordres
        if ($int_codedo <> @$_SESSION["code_do"])
            $pbm_inth = TRUE;
        // Si intervention close, on ne peut que voir
        if (datetolocal($int_datefin) <> "")
            $td = "view";
        break;
}
if ($inth_signee == TRUE)
    $view_sig = TRUE;

switch ($tdh) {
    case "add" :
        $titre = _("Ajout");
        $rpbm_atraiter = (strlen(trim($_SESSION["pbm_choisis"])) > 0);
        $str_pbm = cre_str_pbm_int($_SESSION["pbm_choisis"]);
        $str_pbmfait = cre_str_pbmfait_int($_SESSION["pbm_faits"]);
        if ($id > 0)
            $url_traitepbm = 'rpbmtt_maj.php?ci=' . $codeint . '&inth=' . $id;
        $txtfaitint = str_replace("'", "\'", cree_txt_fait_int($codeint, TRUE, TRUE, TRUE));
        $inth_aheured = '';
        $inth_aheuref = '';
        $inth_rheured = '';
        $inth_rheuref = '';
        // $rpbm_atraiter = exist_rpbm_int($codeint,$id);
        break;
    case "edit" :
        $rpbm_atraiter = (strlen(trim($_SESSION["pbm_choisis"])) > 0);
        $str_pbm = cre_str_pbm_int($_SESSION["pbm_choisis"]);
        $str_pbmfait = cre_str_pbmfait_int($_SESSION["pbm_faits"]);
        if ($id > 0)
            $url_traitepbm = 'rpbmtt_maj.php?ci=' . $codeint . '&inth=' . $id;
        $txtfaitint = str_replace("'", "\'", cree_txt_fait_int($codeint, TRUE, TRUE, TRUE));
        // $rpbm_atraiter = exist_rpbm_int($codeint,$id);
        $titre = _("Edition");
        break;
    case "del" :
        $titre = _("Suppression");
        $add_sig = FALSE;
        break;
    case "view" :
        $titre = _("Visualisation");
        $add_sig = FALSE;
        break;
    default :
        $pbm_inth = TRUE;
        break;
}
?>
<!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 _("Détail Horaire Intervention"); ?></title>

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

<script language="javascript">
    <!--
    var tab1_champ = ["nom:date ; format:date ; masque:<?PHP echo $_SESSION['date_fmtfull']; ?> ; req:Y ; txt:<?PHP echo _("Date"); ?> ; stok:frmok ; stbad:frmbad",
        "nom:codetec ; format:liste ; req:Y ; txt:<?PHP echo _("Technicien"); ?> ; vmn:1 ; stok:frmok ; stbad:frmbad",
        "nom:codelieu ; format:liste ; req:Y ; txt:<?PHP echo _("Lieu"); ?> ; vmn:1 ; stok:frmok ; stbad:frmbad",
        "nom:heurea ; format:liste ; req:Y ; txt:<?PHP echo _("Heure de début"); ?> ; vmn:1 ; stok:frmok ; stbad:frmbad",
        <?PHP
        if (count($_SESSION["clcgintc"]) >0)
        {
            foreach($_SESSION["clcgintc"] as $key=>$value)
            {
                foreach($value as $key2=>$value2)
                {
                    $tab_select = explode("%%",$value2);
                    echo '"nom:clcg_'.$key.'_clc_'.$key2.' ; format:liste ; req:Y ; txt:'.$tab_select[0].' ; vmn:1 ; stok:frmok ; stbad:frmbad",';
                }
            }
        }
        ?>
        "nom:heured ; format:liste ; req:Y ; txt:<?PHP echo _("Heure de fin"); ?> ; vmn:1 ; stok:frmok ; stbad:frmbad"];
    //-->
</script>

<?PHP
if (($td == "add") OR ($td == "edit")) {
    ?>
    <script language="javascript">
    <!--
    var sec = 0; // secondes
    var mn = 0; // minutes
    var h = 0; // heures
    var str_sec = '';
    var str_mn = '';
    var str_m = '';
    var str_h = '';
    var started = false;
    var paused = false;
    var curr_hour = 0;
    var curr_min = 0;
    var step_min = <?PHP echo $pla_stepmin; ?>;
    var chrono;
    function Chrono() {
        if (started == true) {
            if (sec < 10) {
                str_sec = '0' + sec;
            }
            else
                str_sec = '' + sec;
            if (mn < 10) {
                str_mn = '0' + mn;
            }
            else
                str_mn = '' + mn;
            if (h < 10) {
                str_h = '0' + h;
            }
            else
                str_h = '' + h;
            $('#chrono_h').val(str_h);
            $('#chrono_m').val(str_mn);
            $('#chrono_s').val(str_sec);
            if (paused == false)
                sec++;
            if (sec == 60) {
                sec = 0;
                mn++;
            }
            if (mn == 60) {
                mn = 0;
                h++;
            }
        }
        chrono = window.setTimeout("Chrono()", 1000);
    }

    // Démarre le chronomêtre
    function start_chrono() {
        if ((started == false) || (paused == true)) {
            var $heurea = $('#heurea');
            var val_objha = $heurea.val();
            var $heured = $('#heured');
            var val_objhd = $heured.val();
            var start_ok = true;
            if (started == false)
            {
                if ((val_objha != '') || (val_objhd != ''))  {
                    start_ok = confirm('<?PHP echo str_escape(_("Merci de confirmer la réinitialisation de l'heure de début et de fin")); ?>');
                }
            }

            if (start_ok == true) {
                // Calcul de l'heure machine actuelle
                var add_heure = 0;
                var d = new Date();
                curr_min = parseInt(d.getMinutes());
                curr_min = (Math.ceil(curr_min / step_min)) * step_min;
                if (curr_min == 60)
                {
                    curr_min = 0;
                    add_heure = 1;
                }
                var str_curr_min = '';
                if (curr_min < 10) {
                    str_curr_min = '0' + curr_min;
                }
                else {
                    str_curr_min = '' + curr_min;
                }

                curr_hour = parseInt(d.getHours()) + add_heure;
                var str_curr_hour = '';
                if (curr_hour < 10) {
                    str_curr_hour = '0' + curr_hour;
                }
                else {
                    str_curr_hour = '' + curr_hour;
                }
                var heurea = str_curr_hour + ':' + str_curr_min;

                $heurea.val(heurea);
                $heured.val('');
                readonly_id('heurea-heured',false);

                // Remise à zéro du chronomètre
                sec = 0;
                mn = 0;
                h = 0;
                $('#chrono_h').val('00');
                $('#chrono_m').val('00');
                $('#chrono_s').val('00');

                $('#chrono_anim').show();
                $( "#chrono_start" ).fadeTo( "slow" , 0.2);
                $( "#chrono_pause" ).fadeTo( "slow" , 1);
                $( "#chrono_stop" ).fadeTo( "slow" , 1);
                $( "#chrono_RAZ" ).fadeTo( "slow" , 1);
                paused = false;
                started = true;
                Chrono();
            }
        }
    }

    function stop_chrono() {
        if ((started == true) || (paused == true)) {
            window.clearTimeout(chrono);
            started = false;
            paused = false;
            var val_chronoh = parseInt($('#chrono_h').val());
            var val_chronom = parseInt($('#chrono_m').val());
            var val_chronos = parseInt($('#chrono_s').val());

            var heurea_sec = (parseInt(curr_hour) * 3600) + (parseInt(curr_min) * 60);
            var heured_sec = val_chronos + (val_chronom*60) + (val_chronoh * 3600) + heurea_sec;
            if ((heured_sec % (step_min * 60)) != 0)
            {
                heured_sec = (Math.floor(heured_sec/(step_min*60))+1)*(step_min*60);
            }
            var heure = Math.floor(heured_sec / 3600);
            var minutes = Math.ceil((heured_sec - (heure * 3600)) / 60);

            var str_heure = '';
            if (heure < 10) {
                str_heure = '0' + heure;
            }
            else {
                str_heure = '' + heure;
            }
            var str_min = '';
            if (minutes < 10) {
                str_min = '0' + minutes;
            }
            else {
                str_min = '' + minutes;
            }

            var heured = str_heure + ':' + str_min;
            $('#heured').val(heured);
            readok_id('heurea-heured',false);

            $('#chrono_anim').hide();
            $( "#chrono_start" ).fadeTo( "slow" , 1);
            $( "#chrono_pause" ).fadeTo( "slow" , 0.2);
            $( "#chrono_stop" ).fadeTo( "slow" , 0.2);
            $( "#chrono_RAZ" ).fadeTo( "slow" , 0.2);
        }
    }

    function pause_chrono() {
        if ((started == true) && (paused == false)) {
            window.clearTimeout(chrono);
            $('#chrono_anim').hide();
            $( "#chrono_start" ).fadeTo( "slow" , 1);
            $( "#chrono_pause" ).fadeTo( "slow" , 0.2);
            $( "#chrono_stop" ).fadeTo( "slow" , 1);
            $( "#chrono_RAZ" ).fadeTo( "slow" , 1);
            paused = true;
        }
    }

    function clear_chrono() {
        var raz_ok = confirm('<?PHP echo str_escape(_("Confirmez-vous la réinitialisation du chronomêtre ?")); ?>');
        if (raz_ok == true) {
            window.clearTimeout(chrono);
            started = false;
            paused = false;
            sec = 0;
            mn = 0;
            h = 0;
            $('#chrono_h').val('00');
            $('#chrono_m').val('00');
            $('#chrono_s').val('00');
            readok_id('heurea-heured',false);
            $('#chrono_anim').hide();
            $( "#chrono_start" ).fadeTo( "slow" , 1);
            $( "#chrono_pause" ).fadeTo( "slow" , 0.2);
            $( "#chrono_stop" ).fadeTo( "slow" , 0.2);
            $( "#chrono_RAZ" ).fadeTo( "slow" , 0.2);
        }
    }
    //-->
    </script>

<?php
}

if ($pbm_inth == FALSE) {
    ?>
    <script language="javascript">
        <!--
        <?PHP 
        // création du code javascript pour mettre à jour la fiche intervention
        cre_html_trdv('detmrdv','edit',$codeint,'window.opener.');
        cre_html_nextrdv('nextrdv','edit',$codeint,'window.opener.');
        cre_sel_deduc_cocl_int('lsttded',$co,$codeint,$cc,$si,'window.opener.');
        ?>

        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"); ?>"
            });
            $("#date").datepicker({
                onSelect: function (datesel) {
                    $("#date").blur();
                    if (chk_datedif(datesel, this.id, '<?PHP echo $_SESSION['date_fmtshort']; ?>', false, 'dateddef', '', '', true) == false) {
                        var val_regul = parseInt(window.opener.$('#regul').val());
                        if (val_regul == 0) {
                            warn_txt('<?PHP echo _("Erreur de saisie, contrôlez vos dates"); ?>');
                            $('#' + this.id).val('');
                        }
                    }

                }
            });
        }


        function init_all() {
            init_Body();
            $('#chrono_anim').hide();
            $("#onglets_inth").tabs();
            init_autohref_classe('falselnkimg','');
            init_datepicker();
            init_ajax_rens2();
            init_fdeci('a_km', 2,'');
            init_fdeci('r_km', 2,'');
            init_fdeci('a_cd', <?PHP echo $_SESSION['num_nbdec']; ?>,'');
            init_fdeci('r_cd', <?PHP echo $_SESSION['num_nbdec']; ?>,'');
            init_fdeci('a_fa', <?PHP echo $_SESSION['num_nbdec']; ?>,'');
            init_fdeci('r_fa', <?PHP echo $_SESSION['num_nbdec']; ?>,'');
            init_maj_tps('<?PHP echo heure_to_hhmm(sec_heure($nbtotalsec,3,TRUE)); ?>', '<?PHP echo heure_to_hhmm(sec_heure($nbtotalsecoff,3,TRUE)); ?>', '<?PHP echo str_escape($str_tec_traitants); ?>');
            init_maj_pxr('pxr', '<?PHP echo full_num_format($pxrevient,'','',FALSE); ?>');
            init_maj_txtfait('travail', '<?PHP echo str_escape($txtfaitint); ?>');
            <?php
    if ($enr_ok == TRUE)
    {
        echo "clear_form_elements('inth_maj');";
        echo "$('#travail').text('');";
        echo 'self.location.href=\''.$url_lst.'\';';
    }

    switch ($tdh)
    {
        case "add" :
        case "edit" :
            // echo ' updatpdti();';
            // echo ' updatinth();';
            echo ' updatmrdv();';
            echo ' updatnextrdv();';
            echo ' $( "#chrono_start" ).fadeTo( "slow" , 1);';
            echo ' $( "#chrono_pause" ).fadeTo( "slow" , 0.2);';
            echo ' $( "#chrono_stop" ).fadeTo( "slow" , 0.2);';
            echo ' $( "#chrono_RAZ" ).fadeTo( "slow" , 0.2);';
            if ($id ==0)
                echo "$('#travail').text();";
            echo 'updatcoded();';
            if ($add_sig == TRUE)
                $url_signature = 'sig_maj.php?td=add&cr='.$int_code.'&id='.$id.'&ca='.$int_codeage.'&tx=inth';
            if ($view_sig == TRUE)
                $url_signature = 'sig_maj.php?td=view&cr='.$int_code.'&id='.$id.'&ca='.$int_codeage.'&tx=inth';
            echo "init_fensaisie('siglnk',900,700);";
            echo "chk_affsig('signature',tab1_champ,'codelieu');";
            echo "init_chk_affsig_multinp('#detailm1','signature',tab1_champ,'codelieu');";
            echo "init_chk_affsig_multinp('#detdepl','signature',tab1_champ,'codelieu');";
            echo "init_chk_affsig_multsel('lst_checklist','signature',tab1_champ,'codelieu');";
            echo "init_chk_affsig_inthfait('fait','signature',tab1_champ,'codelieu');";
            echo "init_chk_heuredif('heurea','change',true,'','','heured');";
            echo "init_chk_heuredif('heured','change',true,'heurea','','');";
            echo "chk_affbutpbm('butpbm',tab1_champ);";
            echo "init_chk_affbutpbm('date','butpbm',tab1_champ);";
            echo "init_chk_affbutpbm('codetec','butpbm',tab1_champ);";
            echo "init_chk_affbutpbm('codelieu','butpbm',tab1_champ);";
            echo "init_chk_affbutpbm('fait','butpbm',tab1_champ,'blur');";
            echo "init_autoraz('razdate','date','click');";
            echo "init_autoraz('razheurea','heurea','click');";
            echo "init_autoraz('razheured','heured','click');";
            echo "init_autoraz('raza_heured','a_heured','click');";
            echo "init_autoraz('raza_heuref','a_heuref','click');";
            echo "init_autoraz('razr_heured','r_heured','click');";
            echo "init_autoraz('razr_heuref','r_heuref','click');";
            $urlchoixart = "pdt_lst.php?ta=ih&td=".$td."&cc=".$cc."&ci=".$codeint."&cih=".$id;
            $urlchoixtpf = "tpf_lst.php?ta=ih&td=".$td."&cc=".$cc."&ci=".$codeint."&cih=".$id;
            echo "init_fensaisie('addpdt',900,500,'".$urlchoixart."');";
            echo "init_fensaisie('addtpf',900,500,'".$urlchoixtpf."');";
            echo "init_chk_frais('a_fa','a_fad');";
            echo "init_chk_frais('r_fa','r_fad');";
            echo "chk_codelieu('codelieu','onglet_detdepl','detdepl');";
            echo "init_chk_codelieu('codelieu','onglet_detdepl','detdepl');";
            if ((@$_SESSION["niv_log"] <> 2) AND (@$_SESSION["niv_log"] <> 7) AND (@$_SESSION["niv_log"] <> 6))
            {
                echo "update_detail_pbm(true,'detailpbm','".str_replace("'","\'",$str_pbm)."','viewpbm','viewpbmfait');";
                echo "update_fait_pbm(true,'detailpbmfait','".str_replace("'","\'",$str_pbmfait)."','viewpbmfait');";
                echo "update_fait_pbm(false,'travail','".str_replace("'","\'",$str_pbmfait)."','');";
                echo "init_valid_inth('enr','inth_maj',tab1_champ,'','');";
                echo "init_valid_inth('val','inth_maj',tab1_champ,'','');";
            }
            break;
        case "view" :
            // echo ' updatpdti();';
            // echo ' updatinth();';
            echo "chk_affsig('signature',tab1_champ,'codelieu');";
            if ($view_sig == TRUE)
                $url_signature = 'sig_maj.php?td=view&cr='.$int_code.'&id='.$id.'&ca='.$int_codeage.'&tx=inth';
            echo "init_fensaisie('siglnk',900,700);";
            echo "chk_codelieu('codelieu','onglet_detdepl','detdepl');";
            echo "readonly_all();";
            break;
        case "del" :
            // echo ' updatpdti();';
            // echo ' updatinth();';
            echo 'updatcoded();';
            echo "chk_codelieu('codelieu','onglet_detdepl','detdepl');";
            echo "init_valid_inth('del','inth_maj',tab1_champ,'','');";
            echo "readonly_all();";
            break;
    }
    if ($url_traitepbm <> '')
        echo "init_fen_ttpbm('enrp','".$url_traitepbm."',tab1_champ,'fscomp2',1024,600);";
    ?>
            init_autohref('annul', 'click', '<?PHP echo $url_lst; ?>',false);
            add_func_click('quit', 'sclose','');
            Focus_first();
        }

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

</head>
<body>
<?PHP
if (($pbm_inth == FALSE) AND ($pbm_enr_inth == FALSE)) {
    // On enregistre les codes obligatoires
    $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
    // ->Code du contrat en cours (historique contrat)
    $rech = "SELECT COUNT(*) FROM `" . TBCOCLH . "` WHERE `coclh_codeint` = '" . $db->escape($codeint) . "'";
    $nbres = $db->get_var($rech);
    if ($nbres == 1) {
        $rech2 = "UPDATE `" . TBCOCLH . "` SET `coclh_codecocl`='" . $db->escape($co) . "'";
        $rech2 .= " WHERE `coclh_codeint` = '" . $db->escape($codeint) . "'";
    } else {
        $rech2 = "INSERT INTO `" . TBCOCLH . "`";
        $rech2 .= " (coclh_codecli,coclh_codecocl,coclh_codeint)";
        $rech2 .= " VALUES";
        $rech2 .= " ('" . $db->escape($cc) . "','" . $db->escape($co) . "','" . $db->escape($codeint) . "')";
    }
    $db->query($rech2);

    // ->code agence gestionnaire du compte
    // ->code technicien responsable de l'intervention
    // ->id du site d'intervention
    // ->Code du contrat en cours
    $rech = "UPDATE `" . TBINT . "` SET `int_datemod`='" . $datea . "', `int_codemod`='" . $_SESSION["code_log"] . "',";
    $rech .= " `int_codeage`='" . $db->escape($ca) . "', `int_codetec`='" . $db->escape($tecr) . "', `int_idsite`= '" . $si . "', `int_codecocl`= '" . $db->escape($co) . "'";
    $rech .= " WHERE `int_code` = '" . $db->escape($codeint) . "'";
    $db->query($rech);
    $db->disconnect();
    ?>
    <p align="center"><span class="titrepage"><?PHP echo _("DETAIL HORAIRE"); ?></span></p>
    <p align="center"><span class="titre_gras"><?PHP echo _("Pour l'intervention"); ?> : <?php echo $codeint; ?></span>
        <?PHP
        if (($td == "add") AND (($_SESSION["niv_log"] == 3) OR ($_SESSION["niv_log"] == 4) OR ($_SESSION["niv_log"] == 5) OR ($_SESSION["niv_log"] == 9)))
            echo '<br /><span class="annot_petit_it">' . _("Dès que vous aurez saisi un détail, il ne sera plus possible de changer de site") . '</span>';
        ?>
    </p>
    <div align="right">
        <input name="quit" type="button" class="bton_std" id="quit" value="<?PHP echo _("Quitter"); ?>">
    </div>
    <br />
    <?PHP
    $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
    $rech = "SELECT * FROM `" . TBINTH . "` WHERE `inth_codeint`= '" . $codeint . "' ORDER BY inth_date, inth_heurea";
    $rows = $db->get_results($rech, ARRAY_A);

    if (($rows) AND (count($rows) <> 0)) {
        echo "<table class=\"MtableD\" border=\"0\" width=\"890\" cellpadding=\"0\" cellspacing=\"0\" align=\"center\">\n";

        // création de l'entête de la table "détail intervention"
        echo "<th>";
        echo _("Date");
        echo "</th>\n";
        echo "<th>";
        echo _("Technicien");
        echo "</th>\n";
        echo "<th>";
        echo _("Lieu");
        echo "</th>\n";
        echo "<th>";
        echo _("Heure début");
        echo "</th>\n";
        echo "<th>";
        echo _("Heure fin");
        echo "</th>\n";
        echo "<th>";
        echo _("Temps passé");
        echo "</th>\n";
        echo "<th>";
        echo _("Indice");
        echo "</th>\n";
        echo "<th>";
        echo _("Temps retenu");
        echo "</th>\n";
        echo "<th>";
        echo _("Offert ?");
        echo "</th>\n";
        echo "<th>";
        echo _("Cliquer");
        echo "</th>\n";

        $j = 0;

        foreach ($rows as $row) {
            $row = encode_str($row);
            // création de l'entête de ligne (TR)
            creetrlstdet($j);

            echo "<td align=\"center\">\n";
            echo datetolocal($row["inth_date"]);
            echo "<td>\n";
            echo $row["inth_codetec"];
            // Récupération et affichage détail technicien
            $rech2 = "SELECT * FROM `" . TBTEC . "` WHERE `tec_code`= '" . $row["inth_codetec"] . "'";
            $row2 = $db->get_row($rech2, ARRAY_A);
            if ($row2) {
                $row2 = encode_str($row2);
                extract($row2);
                echo "<br />";
                echo "<span class=\"annot_petit_it\">";
                echo $tec_nom . " " . $tec_prenom . " (" . $tec_codeage . ")";
                echo "</span>";
            } else
                echo "&nbsp;";
            echo "</td>\n";
            echo "</td>\n";
            echo "<td align=\"center\">\n";
            // Récupération et affichage libellé lieu
            $rech2 = "SELECT * FROM `" . TBLIEU . "` WHERE `lieu_code`= '" . $row["inth_codelieu"] . "'";
            $row2 = $db->get_row($rech2, ARRAY_A);
            if ($row2) {
                $row2 = encode_str($row2);
                extract($row2);
                echo $lieu_desc;
            } else
                echo "&nbsp;";
            echo "</td>\n";
            echo "<td align=\"center\">\n";
            echo substr($row["inth_heurea"], 0, 5);
            echo "</td>\n";
            echo "<td align=\"center\">\n";
            echo substr($row["inth_heured"], 0, 5);
            echo "</td>\n";
            $tpsreelsec = diff_time_sec($row["inth_heurea"], $row["inth_heured"]);
            echo "<td align=\"center\">\n";
            echo heure_to_hhmm(sec_heure($tpsreelsec));
            echo "</td>\n";
            echo "<td align=\"center\">\n";
            $ind_coeff = 1;
            if ($row["inth_codeind"] == "-1")
                echo "-";
            else {
                echo $row["inth_codeind"];
                $row2 = lit_enr_ind($row["inth_codeind"], FALSE);
                if (is_array($row2)) {
                    $row2 = encode_str($row2);
                    extract($row2);
                    echo ' <a href="#" class="popi"><img src="../img/help.png" alt="' . _("Détail") . '" border="0" align="absmiddle"><span>' . $ind_desc . ' (' . _("coefficient") . ' ' . $ind_coeff . ')</span></a>';
                }
            }
            echo "</td>\n";
            echo "<td align=\"center\">\n";
            echo heure_to_hhmm(sec_heure($tpsreelsec * $ind_coeff));
            echo "</td>\n";
            echo "<td align=\"center\">\n";
            echo $non_oui2[$row["inth_offert"]];
            echo "</td>\n";
            echo "<td align=\"center\">\n";
            $url_edit = 'inth_maj.php?td=edit&ci=' . $codeint . '&id=' . $row["inth_id"] . '&cc=' . $cc . '&co=' . $co . '&ca=' . $ca . '&cas=' . $cas . '&si=' . $si . '&tr=' . $tecr . '&cat=' . $codecat;
            $url_del = 'inth_maj.php?td=del&ci=' . $codeint . '&id=' . $row["inth_id"] . '&cc=' . $cc . '&co=' . $co . '&ca=' . $ca . '&cas=' . $cas . '&si=' . $si . '&tr=' . $tecr . '&cat=' . $codecat;
            $url_view = 'inth_maj.php?ci=' . $codeint . '&id=' . $row["inth_id"] . '&cc=' . $cc . '&co=' . $co . '&ca=' . $ca . '&cas=' . $cas . '&si=' . $si . '&tr=' . $tecr . '&cat=' . $codecat;


            if ($td <> "view") {
                switch ($_SESSION["niv_log"]) {
                    case 3 :
                        if (($tec_code == $_SESSION["code_log"]) OR ($tecr == $_SESSION["code_log"])) {
                            if (inth_signee($codeint, $row["inth_id"], FALSE) == FALSE) {
                                if (url_ok($url_edit, FALSE) == TRUE) {
                                    $lst_maj = TRUE;
                                    cre_falselnk_img('', 'inth_edit_'.$row["inth_id"], 'span', 'center', _("Edition"), 'lnk', $url_edit, '../img/edit.png');
                                }

                                if (url_ok($url_del, FALSE) == TRUE)
                                {
                                    $lst_del = TRUE;
                                    cre_falselnk_img('', 'inth_del_'.$row["inth_id"], 'span', 'center', _("Suppression"), 'lnk', $url_del, '../img/del.png');
                                }
                            } else {
                                if (url_ok($url_view, FALSE) == TRUE)
                                {
                                    $lst_view = TRUE;
                                    cre_falselnk_img('', 'inth_view_'.$row["inth_id"], 'span', 'center', _("Visualisation"), 'lnk', $url_view, '../img/eye.png');
                                }
                            }
                        }
                        break;
                    case 4 :
                        if ($tec_codeage == $_SESSION["code_age"]) {
                            if (inth_signee($codeint, $row["inth_id"], FALSE) == FALSE) {
                                if (url_ok($url_edit, FALSE) == TRUE) {
                                    $lst_maj = TRUE;
                                    cre_falselnk_img('', 'inth_edit_'.$row["inth_id"], 'span', 'center', _("Edition"), 'lnk', $url_edit, '../img/edit.png');
                                }

                                if (url_ok($url_del, FALSE) == TRUE)
                                {
                                    $lst_del = TRUE;
                                    cre_falselnk_img('', 'inth_del_'.$row["inth_id"], 'span', 'center', _("Suppression"), 'lnk', $url_del, '../img/del.png');
                                }
                            } else {
                                if (url_ok($url_view, FALSE) == TRUE)
                                {
                                    $lst_view = TRUE;
                                    cre_falselnk_img('', 'inth_view_'.$row["inth_id"], 'span', 'center', _("Visualisation"), 'lnk', $url_view, '../img/eye.png');
                                }
                            }
                        }
                        break;
                    default :
                        if (inth_signee($codeint, $row["inth_id"], FALSE) == FALSE) {
                            if (url_ok($url_edit, FALSE) == TRUE) {
                                $lst_maj = TRUE;
                                cre_falselnk_img('', 'inth_edit_'.$row["inth_id"], 'span', 'center', _("Edition"), 'lnk', $url_edit, '../img/edit.png');
                            }

                            if (url_ok($url_del, FALSE) == TRUE)
                            {
                                $lst_del = TRUE;
                                cre_falselnk_img('', 'inth_del_'.$row["inth_id"], 'span', 'center', _("Suppression"), 'lnk', $url_del, '../img/del.png');
                            }
                        } else {
                            if (url_ok($url_view, FALSE) == TRUE)
                            {
                                $lst_view = TRUE;
                                cre_falselnk_img('', 'inth_view_'.$row["inth_id"], 'span', 'center', _("Visualisation"), 'lnk', $url_view, '../img/eye.png');
                            }
                        }
                        break;
                }
            } else {
                $lst_view = TRUE;
                cre_falselnk_img('', 'inth_view_'.$row["inth_id"], 'span', 'center', _("Visualisation"), 'lnk', $url_view, '../img/eye.png');
            }
            echo "</td>\n";

            echo "</tr>\n";

            $j++;
        }

        /* Totaux */

        // Total Général

        // création de l'entête de ligne (TR)
        creetrlstdet($j);

        echo "<td colspan=\"7\" align=\"right\">";
        echo "<span class=\"annot_std_gras\">";
        echo _("Temps total") . " : ";
        echo "</span>";
        echo "</td>\n";
        echo "<td align=\"center\">";
        echo "<span class=\"annot_std_gras\">";
        echo heure_to_hhmm(sec_heure($nbtotalsec, 3, TRUE));
        $du = heure_to_hhmm(sec_heure($nbtotalsec, 3, TRUE));
        echo "</span>";
        echo "</td>\n";
        echo "<td colspan=\"2\">";
        echo "&nbsp;";
        echo "</td>\n";

        // Temps offert

        // création de l'entête de ligne (TR)
        $j++;
        creetrlstdet($j);

        echo "<td colspan=\"7\" align=\"right\">";
        echo "<span class=\"annot_std_gras\">";
        echo _("Temps offert") . " : ";
        echo "</span>";
        echo "</td>\n";
        echo "<td align=\"center\">";
        if ($nbtotalsecoff <> 0) {
            echo "<span class=\"annot_std_gras\">";
            echo heure_to_hhmm(sec_heure($nbtotalsecoff, 3, TRUE));
            $duo = heure_to_hhmm(sec_heure($nbtotalsecoff, 3, TRUE));
            echo "</span>";
        } else {
            echo "-";
            $duo = "00:00";
        }
        echo "</td>\n";
        echo "<td colspan=\"2\">";
        echo "&nbsp;";
        echo "</td>\n";

        // Temps retenu

        // création de l'entête de ligne (TR)
        $j++;
        creetrlstdet($j);

        echo "</td>\n";
        echo "<td colspan=\"7\" align=\"right\">";
        echo "<span class=\"annot_std_gras\">";
        echo _("Temps retenu") . " : ";
        echo "</span>";
        echo "</td>\n";
        echo "<td align=\"center\">";
        echo "<span class=\"annot_std_gras\">";
        echo heure_to_hhmm(sec_heure($nbtotalsec - $nbtotalsecoff, 3, TRUE));
        echo "</span>";
        echo "</td>\n";
        echo "<td colspan=\"2\">";
        echo "&nbsp;";
        echo "</td>\n";

        echo "</table>\n";
        // Fin affichage table détail horaire

        $pas_horaire = FALSE;
    } else {
        $pas_horaire = TRUE;
        echo '<p class="annot_petit_it">' . _("Aucun détail horaire enregistré") . '</p>';
    }
    $db->disconnect();

    $taille_piedla = "";
    include_once("piedla.inc.php");
    ?>
    <br />
    <form name="inth_maj" id="inth_maj" class="bord_pointilles" method="post" action="inth_maj.php">
    <input name="ci" type="hidden" id="ci" value="<?PHP echo $codeint; ?>">
    <input name="id" type="hidden" id="id" value="<?PHP echo $id; ?>">
    <input name="sig" type="hidden" id="sig" value="<?PHP echo $inth_signee; ?>">
    <input name="cc" type="hidden" id="cc" value="<?PHP echo $cc; ?>">
    <input name="co" type="hidden" id="co" value="<?PHP echo $co; ?>">
    <input name="si" type="hidden" id="si" value="<?PHP echo $si; ?>">
    <input name="ca" type="hidden" id="ca" value="<?PHP echo $ca; ?>">
    <input name="cas" type="hidden" id="cas" value="<?PHP echo $cas; ?>">
    <input name="tr" type="hidden" id="tr" value="<?PHP echo $tecr; ?>">
    <input name="cat" type="hidden" id="cat" value="<?PHP echo $codecat; ?>">
    <input name="re" type="hidden" id="re" value="<?PHP echo $re; ?>">
    <input name="nbutton" type="hidden" id="nbutton" value="">

    <p align="center"><span class="annot_std_gras"><?PHP echo $titre; ?></span>

    <table width="98%" border="0" align="center">
        <tr>
            <td width="50%">
                <?PHP
                if ($tdh <> "view") {
                    echo '<span class="annot_petit_it" style="margin-right:5px">' . _("Chronomètre") . '</span> ';
                    echo '<input class="annot_petit" name="chrono_h" type="text" id="chrono_h" value="00" size="2" readonly="1"> :';
                    echo ' <input class="annot_petit" name="chrono_m" type="text" id="chrono_m" value="00" size="2" readonly="1"> :';
                    echo ' <input class="annot_petit" name="chrono_s" type="text" id="chrono_s" value="00" size="2" readonly="1">';
                    echo ' <a href="javascript:;" onClick="start_chrono();"><img src="../img/chrono_start.png" align="absmiddle" alt="' . _("Lancer") . '" title="' . _("Lancer") . '" id="chrono_start" style="border:0;"></a> ';
                    echo '<a href="javascript:;" onClick="pause_chrono();"><img src="../img/chrono_pause.png" align="absmiddle" alt="' . _("Pause") . '" title="' . _("Pause") . '" id="chrono_pause" style="border:0"></a> ';
                    echo '<a href="javascript:;" onClick="stop_chrono();"><img src="../img/chrono_stop.png" align="absmiddle" alt="' . _("Stop") . '" title="' . _("Stopper et transférer") . '" id="chrono_stop" style="border:0;"></a> ';
                    echo '<a href="javascript:;" onClick="clear_chrono();"><img src="../img/raz.png" align="absmiddle" alt="' . _("RAZ") . '" title="' . _("RAZ") . '" id="chrono_RAZ" style="border:0;"></a> ';
                    echo '<span id="chrono_anim"><img src="../img/chrono_anim.gif" align="absmiddle" alt="chrono_anim"></span>';
                } else
                    echo '&nbsp;';
                ?>
            </td>
            <td width="50%" align="right">
                <?PHP
                // On vérifie si le module signature est bien en place
                if ($mod_signature == TRUE)
                {
                    echo '<div id="signature" style="display:none;">';
                    cre_falselnk('siglnk', 'siglnk', 'span', '', _("Signature"), $url_signature, '../img/signer.png', '');
                    echo '</div>';
                }
                else
                    echo "&nbsp;";
                ?>
            </td>
        </tr>
    </table>

    <div id="onglets_inth">
    <ul>
        <li><a href="#inth_deth"><?PHP echo _("Détail horaire"); ?></a></li>
        <li><a href="#inth_travs"><?PHP echo _("Travail (Saisie)"); ?></a></li>
        <li><a href="#inth_travpd"><?PHP echo _("Travail (problèmes déclarés)"); ?></a></li>
        <li><a href="#inth_fpf"><?PHP echo _("Forfaits et pièces facturées"); ?></a></li>
        <li><a href="#inth_cl"><?PHP echo _("Check-List"); ?></a></li>
        <?PHP
        if ((@$_SESSION["niv_log"] == 3) OR (@$_SESSION["niv_log"] == 4) OR (@$_SESSION["niv_log"] == 5) OR (@$_SESSION["niv_log"] == 9))
            echo '<li><a href="#inth_dd" id="onglet_detdepl">'._("Détail déplacement").'</a></li>';
        ?>
    </ul>

    <div id="inth_deth">
    <table width="98%" border="0" align="center">
    <tr>
        <td width="170" class="rubfrm" id="f_irdv" align="right"><?PHP echo _("Rendez-vous concerné"); ?></td>
        <td>
            <?PHP
            if ($tdh <> "view") {
                $rech = "";
                switch (@$_SESSION["niv_log"]) {
                    case 3 :
                    case 4 :
                        $rech = "SELECT * FROM `" . TBRDV . "`";
                        $rech .= " WHERE rdv_typrat=1 AND rdv_coderat='" . $codeint . "'";
                        if ($tdh == "add")
                            $rech .= " AND rdv_honore=0";
                        else
                            $rech .= " AND rdv_honore=0 OR (rdv_honore = 1 AND rdv_id = " . $inth_idrdv . ")";
                        $rech .= " ORDER BY rdv_date, rdv_heure";
                        break;
                    case 10 :
                    case 11 :
                        break;
                    default :
                        $rech = "SELECT * FROM `" . TBRDV . "`";
                        $rech .= " WHERE rdv_typrat=1 AND rdv_coderat='" . $codeint . "'";
                        if ($tdh == "add")
                            $rech .= " AND rdv_honore=0";
                        else
                            $rech .= " AND rdv_honore=0 OR (rdv_honore = 1 AND rdv_id = " . $inth_idrdv . ")";
                        $rech .= " ORDER BY rdv_date, rdv_heure";
                        break;
                }

                echo '<select name="rdv" id="rdv">';
                echo '<option value="">' . _("-- Faites votre choix --") . '</option>';
                if ($rech <> "") {
                    $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
                    $rows = $db->get_results($rech, ARRAY_A);
                    if (($rows) AND (count($rows) > 0)) {
                        foreach ($rows as $row) {
                            extract($row);
                            $txtrdv = _("Le") . " " . datetolocal($rdv_date) . " " . _("à") . " " . substr($rdv_heure, 0, 5);
                            echo '<option';
                            echo ' value="' . $rdv_id . '"';
                            if (intval($inth_idrdv) == intval($rdv_id))
                                echo ' class="vert"';
                            if (intval($inth_idrdv) == intval($rdv_id))
                                echo ' selected';
                            echo '>' . $txtrdv . '</option>';
                        }
                    }
                    $db->disconnect();
                }
                echo '</select>';
            } else {
                $txtrdv = '-';
                if ($inth_idrdv > 0) {
                    $row = lit_enr_rdv_id($inth_idrdv);
                    if (is_array($row)) {
                        extract($row);
                        $txtrdv = _("Le") . " " . datetolocal($rdv_date) . " " . _("à") . " " . substr($rdv_heure, 0, 5);
                    }
                }
                echo '<input name="rdv" type="hidden" id="rdv" value="' . $inth_idrdv . '" readonly="1">';
                echo '<input name="txtrdv" type="text" id="txtrdv" value="' . $txtrdv . '" size="50" readonly="1">';
            }
            ?>
        </td>
    </tr>
    <tr>
        <td class="rubfrm" id="f_date" align="right"><?PHP echo _("Date"); ?></td>
        <td align="left">
            <input name="date" type="text" id="date" value="<?PHP echo datetolocal($inth_date); ?>" size="10" maxlength="10" readonly>
            <?PHP
            if ($tdh <> "view") {
                echo '<span id="imgprev">';
                echo '<a href="javascript:;"><img src="../img/raz.png" id="razdate" border="0" align="absmiddle"></a>';
                echo '</span>';
                echo '<div class="annot_petit_it">';
                echo _("Au moins le") . ' ';
                echo datetolocal($int_datedde) . ' (' . _("date de création") . ') - ' . _("sauf mode régularisation");
                echo '</div>';
            }
            ?>
        </td>
    </tr>
    <tr>
        <td class="rubfrm" id="f_tec" align="right"><?PHP echo _("Technicien"); ?></td>
        <td>
            <?PHP
            if ($tdh <> "view") {
                $rows = give_tab_rows_tec_toaff_int($codeint, TRUE, TRUE);
                //$rows = encode_str($rows);
                if (count($rows) > 0)
                    cre_select_tab('codetec', 'codetec', $rows, 'tec_code', 'tec_nom', 'tec_prenom-tec_codeage', $inth_codetec, '', _("-- Faites votre choix --"));
                else {
                    $tab_nosel = [];
                    switch (intval($_SESSION["niv_log"])) {
                        case 3 :
                            $tab_nosel[""] = _("-- Vous ne pouvez pas saisir de détail horaire technicien --");
                            break;
                        case 4 :
                            $tab_nosel[""] = _("-- Aucun technicien de votre agence affecté à cette intervention --");
                            break;
                        default :
                            $tab_nosel[""] = _("-- Pas de technicien affecté à cette intervention --");
                            break;
                    }
                    cre_select('codetec', 'codetec', $tab_nosel, '');
                }
            } else {
                $txt_tec = '-';
                $row = lit_enr_tec($inth_codetec, TRUE);
                if (is_array($row)) {
                    $row = encode_str($row);
                    extract($row);
                    $txt_tec = $tec_nom . " " . $tec_prenom . " (" . $tec_codeage . ")";
                }
                echo '<input name="codetec" type="hidden" id="codetec" value="' . $inth_codetec . '" readonly="1">';
                echo '<input name="txttec" type="text" id="txttec" value="' . $txt_tec . '" size="50" readonly="1">';
            }
            ?>
        </td>
    </tr>
    <tr>
        <td class="rubfrm" id="f_lieu" align="right"><?PHP echo _("Lieu"); ?></td>
        <td align="left">
            <?PHP
            // création de la liste cachée des lieux 
            // pour savoir si déplacement = "_"+codelieu
            $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
            $rech = "SELECT * FROM `" . TBLIEU . "`";
            $rows = $db->get_results($rech, ARRAY_A);
            foreach ($rows as $row) {
                $row = encode_str($row);
                extract($row);
                echo '<input name="_' . $lieu_code . '" type="hidden" id="_' . $lieu_code . '" value="' . $lieu_depl . '">';
            }
            $db->disconnect();

            cre_select_tab('codelieu', 'codelieu', $rows, 'lieu_code', 'lieu_desc', '', $inth_codelieu, '', _("-- Faites votre choix --"));
            ?>
        </td>
    </tr>
    <tr>
        <td class="rubfrm" id="f_horaires" align="right"><?PHP echo _("Horaires"); ?></td>
        <td align="left">
            <?PHP
            $tab_heures = give_tab_heures(($pprm_firsthour * 3600), ($pprm_lasthour * 3600), ($pla_stepmin * 60));
            // $tab_heures = give_tab_heures(($pprm_firsthour * 3600), ($pprm_lasthour * 3600), 300, true);


            echo ' ' . _("Début") . ' ';
            cre_select('heurea', 'heurea', $tab_heures, substr($inth_heurea, 0, 5));

            if ($tdh <> "view")
                echo '<a href="javascript:;"><img src="../img/raz.png" id="razheurea" border="0" align="absmiddle"></a>';

            echo ' / Fin ';

            cre_select('heured', 'heured', $tab_heures, substr($inth_heured, 0, 5));

            echo '<a href="javascript:;"><img src="../img/raz.png" id="razheured" border="0" align="absmiddle"></a>';
            ?>
        </td>
    </tr>
    <tr>
        <td class="rubfrm" id="f_ind" align="right"><?PHP echo _("Indice"); ?></td>
        <td>
            <?PHP
            if ($tdh <> "view") {
                // création de la liste des Indices
                echo '<select name="ind" id="ind">';
                echo '<option value="-1"';
                if ($inth_codeind == "-1")
                    echo ' selected';
                echo '>' . _("Pas d'indice (coefficient 1)") . '</option>';

                $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
                $rech = "SELECT ind_code, ind_desc, ind_coeff FROM `" . TBIND . "` WHERE `ind_actif`=1 ORDER BY `ind_desc`";
                $rows = $db->get_results($rech, ARRAY_A);

                if ($rows) {
                    foreach ($rows as $row) {
                        $row = encode_str($row);
                        extract($row);
                        echo '<option value="' . $ind_code . '"';
                        if ($inth_codeind == $ind_code)
                            echo ' selected';
                        echo '>' . $ind_desc . ' (' . _("coefficient") . $ind_coeff . ')</option>';
                    }
                }
                echo '</select>';
                $db->disconnect();
            } else {
                $txt_indice = _("Pas d'indice (coefficient 1)");
                $row = lit_enr_ind($inth_codeind);
                if (is_array($row)) {
                    extract($row);
                    $txt_indice = $ind_desc . ' (coefficient' . $ind_coeff . ')';
                }
                echo '<input name="ind" type="hidden" id="ind" value="' . $inth_codeind . '" readonly="1">';
                echo '<input name="txtind" type="text" id="txtind" value="' . $txt_indice . '" size="50" readonly="1">';
            }
            ?>
        </td>
    </tr>
    <tr>
        <td class="rubfrm" id="f_offert" align="right"><?PHP echo _("Offert"); ?></td>
        <td align="left">
            <?PHP
            echo '<input type="checkbox" name="offert" style="background : #FFFFFF;"';
            if ($inth_offert == 1)
                echo ' checked';
            echo '>';
            ?>
        </td>
    </tr>
    </table>
    </div>

    <div id="inth_travs">
        <?PHP
        echo '<textarea name="fait" rows="10" id="fait"';
        echo '>' . $inth_fait . '</textarea>';
        ?>
    </div>

    <div id="inth_travpd">
        <?PHP
        echo '<textarea name="travail" rows="10" id="travail"';
        echo ' readonly></textarea>';
        ?>
    </div>

    <!-- Articles ou de prestations -->
    <div id="inth_fpf">
        <div id="artinth">
            <div id="detpdti">
            </div>

            <?PHP
            if ($tdh <> "view") {
                ?>
                <table border="0" width="100%">
                    <tr>
                        <td width="50%">
                            <?PHP
                            if (url_ok($urlchoixart, TRUE) == TRUE)
                                cre_falselnk('', 'addpdt', 'span', '', _("Ajouter un article"), $urlchoixart, '../img/add.png', _("Ajouter un article"));
                            else
                                echo '&nbsp;';
                            ?>
                        </td>
                        <td width="50%">
                            <?PHP
                            if (url_ok($urlchoixtpf, TRUE) == TRUE)
                                cre_falselnk('', 'addtpf', 'span', '', _("Ajouter une taxe parafiscale"), $urlchoixtpf, '../img/add.png', _("Ajouter une taxe parafiscale"));

                            else
                                echo '&nbsp;';
                            ?>
                        </td>
                    </tr>
                </table>
            <?PHP
            }
            ?>
        </div>
    </div>

    <div id="inth_cl">
        <?PHP
        if (count($_SESSION["clcgintc"]) > 0) {
            $idx = 0;
            $code_clcg_courant = '';
            $tab_tmp = [];
            echo '<div align="center" id="lst_checklist">';
            echo '<table border="0" width="98%">';
            foreach ($_SESSION["clcgintc"] as $key => $value) {
                $code_clcg = $key;

                if ($code_clcg <> $code_clcg_courant) {
                    echo '<tr>';
                    echo '<td colspan="2" class="titrerubrique2" align="center">';
                    $row4 = lit_enr_clcg($code_clcg);
                    if (is_array($row4)) {
                        $row4 = encode_str($row4);
                        extract($row4);
                        echo $clcg_desc;
                    } else
                        echo "&nbsp;";
                    echo "</td>";
                    echo '</tr>';
                }
                $code_clcg_courant = $code_clcg;

                $tab_tmp = $value;

                foreach ($tab_tmp as $key2 => $value2) {
                    $idx++;
                    if ($idx % 2 <> 0)
                        echo '<tr>';

                    echo '<td width="50%">';
                    echo '<span class="annot_petit_gras" style="margin-right:5px;">';
                    $tab_select = explode("%%", $value2);
                    echo $tab_select[0] . ' : ';
                    echo '</span>';
                    if ($tdh <> "view") {
                        echo '<select class="annot_petit" name="clcg_' . $key . '_clc_' . $key2 . '" id="clcg_' . $key . '_clc_' . $key2 . '">';
                        echo '<option value="" class="annot_petit">' . _("-- Faites votre choix --") . '</option>';
                        for ($i = 0; $i < 3; $i++) {
                            if (substr($tab_select[1], $i, 1) == "1") {
                                echo '<option value="' . $i . '" class="annot_petit"';
                                $row = lit_enr_clc_clcg_inth($key, $key2, $id);
                                if (is_array($row)) {
                                    $row = encode_str($row);
                                    extract($row);
                                    if (intval($clcginth_choix) == $i)
                                        echo ' selected';
                                }
                                echo '>';
                                echo $non_oui3[$i] . "</option>";
                            }
                        }
                        echo '</select>';
                    } else {
                        $row = lit_enr_clc_clcg_inth($key, $key2, $id);
                        if (is_array($row)) {
                            $row = encode_str($row);
                            extract($row);
                            echo '<input name="txtclcg_' . $key . '_txtclc_' . $key2 . '" type="text" id="txtclcg_' . $key . '_txtclc_' . $key2 . '" value="' . $non_oui3[intval($clcginth_choix)] . '" class="annot_petit" size="50" readonly="1">';
                        }
                    }
                    echo '</td>';
                    if ($idx % 2 == 0)
                        echo '</tr>';
                }
            }
            if ($idx % 2 <> 0) {
                echo '<td width="50%" style="padding-left:5px;">';
                echo "&nbsp;";
                echo '</td>';
                echo '</tr>';
            }
            echo '</table>';
            echo '</div>';
        } else
            echo _("Pas de check-list sur cette catégorie d'intervention");
        ?>
    </div>

    <?PHP
    if ((@$_SESSION["niv_log"] == 3) OR (@$_SESSION["niv_log"] == 4) OR (@$_SESSION["niv_log"] == 5) OR (@$_SESSION["niv_log"] == 9)) {
        ?>
        <div id="detdepl" style="display:none">
            <div id="inth_dd">
                <table width="890" border="0" align="center">
                    <tr>
                        <td width="20%"></td>
                        <td width="40%" class="rubfrm" id="f_aller" align="center"><?PHP echo _("Aller"); ?></td>
                        <td class="rubfrm" id="f_retour" align="center"><?PHP echo _("Retour"); ?></td>
                    </tr>
                    <tr>
                        <td width="20%" class="rubfrm" id="f_transmt" align="right"><?PHP echo _("Transport"); ?></td>
                        <td width="40%" align="centerleft">
                            <?PHP
                            $tab_amt = [];
                            $tab_rmt = [];
                            $tab_rmt['-1'] = _("Pas de retour agence");

                            // Création de la liste cachée des moyens de transport
                            // pour savoir si coût à saisir = "M_"+codemt
                            $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
                            $rech = "SELECT * FROM `" . TBMT . "` WHERE `mt_valid`='1'  ORDER BY mt_des";
                            $rows = $db->get_results($rech, ARRAY_A);
                            foreach ($rows as $row) {
                                $row = encode_str($row);
                                extract($row);
                                echo '<input name="M_' . $mt_code . '" type="hidden" id="M_' . $mt_code . '" value="' . $mt_coutas . '">';
                                if ($mt_coutas == 1) {
                                    $tab_amt[$mt_code] = $mt_des . ' (AS)';
                                    $tab_rmt[$mt_code] = $mt_des . ' (AS)';
                                } else {
                                    $tab_amt[$mt_code] = $mt_des;
                                    $tab_rmt[$mt_code] = $mt_des;
                                }
                            }
                            $db->disconnect();
                            cre_select('a_mt', 'a_mt', $tab_amt, $inth_acodemt, '', _("-- Faites votre choix --"));
                            ?>
                        </td>
                        <td align="left">
                            <?PHP
                            cre_select('r_mt', 'r_mt', $tab_rmt, $inth_rcodemt, '', _("-- Faites votre choix --"));
                            ?>
                            <div class="annot_petit_it"><?PHP echo _("Pas de retour agence : départ direct chez un autre client"); ?></div>
                        </td>
                    </tr>
                    <tr>
                        <td width="20%" class="rubfrm" id="f_transh" align="right"><?PHP echo _("Horaires"); ?></td>
                        <td width="40%" align="left">
                            <?PHP
                            echo _("De") . ' ';
                            $tab_heures = give_tab_heures(0,86400,300);
                            cre_select('a_heured', 'a_heured', $tab_heures, substr($inth_aheured, 0, 5));

                            echo ' <img src="../img/raz.png" id="raza_heured" border="0" align="absmiddle">';
                            echo ' ' . _("à") . ' ';
                            cre_select('a_heuref', 'a_heuref', $tab_heures, substr($inth_aheuref, 0, 5));
                            echo ' <img src="../img/raz.png" id="raza_heuref" border="0" align="absmiddle">';
                            ?>
                        </td>
                        <td align="left">
                            <?PHP
                            echo _("De") . ' ';
                            cre_select('r_heured', 'r_heured', $tab_heures, substr($inth_rheured, 0, 5));
                            echo ' <img src="../img/raz.png" id="razr_heured" border="0" align="absmiddle">';

                            echo ' ' . _("à") . ' ';
                            cre_select('r_heuref', 'r_heuref', $tab_heures, substr($inth_rheuref, 0, 5));
                            echo ' <img src="../img/raz.png" id="razr_heuref" border="0" align="absmiddle">';
                            ?>
                        </td>
                    </tr>
                    <tr>
                        <td width="20%" class="rubfrm" id="f_transkm" align="right"><?PHP echo _("Distance"); ?></td>
                        <td width="40%" align="left">
                            <input name="a_km" type="text" id="a_km" value="<?PHP echo full_num_format($inth_akm); ?>"size="10"> <?PHP echo _("km"); ?>
                             <img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo _("Champ obligatoire"); ?>">
                        </td>
                        <td align="left">
                            <input name="r_km" type="text" id="r_km" value="<?PHP echo full_num_format($inth_rkm); ?>"
                                   size="10"> <?PHP echo _("km"); ?>
                            <img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo _("Champ obligatoire"); ?>">
                        </td>
                    </tr>
                    <tr>
                        <td width="20%" class="rubfrm" id="f_transcd"
                            align="right"><?PHP echo _("Coût transport"); ?></td>
                        <td width="40%" align="left">
                            <?PHP
                            cre_input_num('a_cd', $inth_acd, TRUE);
                            ?>
                            <br /><span class="annot_petit_it"><?PHP echo _("Uniquement si coût à saisir (AS)"); ?></span>
                        </td>
                        <td align="left">
                            <?PHP
                            cre_input_num('r_cd', $inth_rcd, TRUE);
                            ?>
                            <br /><span class="annot_petit_it"><?PHP echo _("Uniquement si coût à saisir (AS)"); ?></span>
                        </td>
                    </tr>
                    <tr>
                        <td width="20%" class="rubfrm" id="f_transfa" align="right"><?PHP echo _("Frais annexes"); ?></td>
                        <td width="40%" align="left">
                            <?PHP
                            cre_input_num('a_fa', $inth_afrais, TRUE);
                            ?>
                            <br /><span
                                class="annot_petit_it"><?PHP echo _("Ne pas saisir de coût kilométrique supplémentaire car il est automatiquement calculé"); ?></span>
                        </td>
                        <td align="left">
                            <?PHP
                            cre_input_num('r_fa', $inth_rfrais, TRUE);
                            ?>
                            <br /><span
                                class="annot_petit_it"><?PHP echo _("Ne pas saisir de coût kilométrique supplémentaire car il est automatiquement calculé"); ?></span>
                        </td>
                    </tr>
                    <tr>
                        <td width="20%" class="rubfrm" id="f_transfad" align="right"><?PHP echo _("Détail frais annexes"); ?></td>
                        <td width="40%" align="left">
                            <textarea name="a_fad" id="a_fad" rows="3"
                                      width="100%"><?PHP echo $inth_afraisd; ?></textarea>
                        </td>
                        <td align="center">
                            <textarea name="r_fad" id="r_fad" rows="3"
                                      width="100%"><?PHP echo $inth_rfraisd; ?></textarea>
                        </td>
                    </tr>
                </table>
            </div>
        </div>
    <?PHP
    }
    ?>
    </div>
    <?PHP
    echo '<p align="center">';
    echo '<input name="annul" type="button" class="bton_std" id="annul" value="' . _("Annuler") . '">';
    switch ($tdh) {
        case "add" :
            echo '<input name="enr" type="button" class="bton_std" id="enr" value="' . _("Ajouter") . '">';
            if ($rpbm_atraiter == TRUE) {
                echo '<span id="butpbm" align="center">';
                echo '<input name="enrp" type="button" class="bton_std" id="enrp" value="' . _("Traiter Problèmes") . '">';
                echo '</span>';
            }
            break;
        case "edit" :
            echo '<input name="val" type="button" class="bton_std" id="val" value="' . _("Valider") . '">';
            if ($rpbm_atraiter == TRUE) {
                echo '<span id="butpbm" align="center">';
                echo '<input name="enrp" type="button" class="bton_std" id="enrp" value="' . _("Traiter Problèmes") . '">';
                echo '</span>';
            }
            break;
        case "del" :
            echo '<input name="del" type="button" class="bton_std" id="del" value="' . _("Supprimer") . '">';
            break;
        default :
            break;
    }
    echo '</p>';
    ?>
    </form>
<?PHP
} else {
    if ($pbm_inth == TRUE)
        close_fen_auto('', '');

    if ($pbm_enr_inth == TRUE)
        pop_ret_auto($msg, 'warn', 'inth_maj.php?ci=' . $codeint . '&td=' . $td . '&id=' . $id);
}
?>
</body>
</html>
