<?php
/****************************************************************************************
 * SMI (Services Maintenance Interventions) est une gestion libre de maintenance et de SAV
 *
 * Version 1.0.2
 *
 * Copyright (C) 2006-2015  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/config.inc.php");
include_once("../inc/fic_age.inc.php");
include_once("../inc/fic_cli.inc.php");
include_once("../inc/fic_do.inc.php");
include_once("../inc/fic_dos.inc.php");
include_once("../inc/fic_droits.inc.php");
include_once("../inc/fic_hum.inc.php");
include_once("../inc/fic_mque.inc.php");
include_once("../inc/fic_prm.inc.php");
include_once("../inc/fic_st.inc.php");
include_once("../inc/func.inc.php");
include_once("../inc/func_log.inc.php");
include_once("../inc/func_date.inc.php");
include_once("../inc/func_time.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);

$td = @$_GET['td'];
$codedos = @$_GET['cd'];
$iddosd = @$_GET['nd'];

$pbm_dosd = FALSE;

// 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 ($codedos <> "") {
    // Récupération des données de la fiche dossier
    $row = lit_enr_dos($codedos);
    if (is_array($row)) {
        $row = encode_str($row);
        extract($row);

        $codeadev = give_dev_codea_defaut_dos($dos_code, $_SESSION["lng"], TRUE);

        $row = lit_enr_doss($dos_codedoss);
        if (is_array($row))
            extract($row);

        if (datetolocal($dosd_datefin) <> "")
            $td = "view";

        if ($td == "add") {
            $dosd_codedos = $dos_code;
            $dosd_dateactf = $datef;
        }

        if (($td == "edit") OR ($td == "del") OR ($td == "view")) {
            $row = lit_enr_dosd_in_dos($iddosd, $codedos);
            if (is_array($row)) {
                extract($row);
                $dosd_dateactf = datetolocal($dosd_dateact);
            } else
                $pbm_dosd = TRUE;
        }
    }
} else
    $pbm_dosd = TRUE;

switch ($td) {
    case "add" :
        $titre = _("SAISIE DETAIL");
        break;
    case "edit" :
        $titre = _("EDITION DETAIL");
        break;
    case "del" :
        $titre = _("SUPPRESSION DETAIL");
        break;
    case "view" :
        $titre = _("VISUALISATION DETAIL");
        break;
    default :
        $pbm_dosd = 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 dossier"); ?></title>

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

    <?PHP if (($td == "add") or ($td == "edit")) { ?>
        <script language="javascript">
            <!--
            var tab1_champ = ["nom:typea ; format:liste ; req:Y ; txt:<?PHP echo _("Type"); ?> action ; vmn:1 ; stok:frmok ; stbad:frmbad",
                "nom:dateactf ; format:date ; masque:<?PHP echo $_SESSION['date_fmtfull']; ?> ; req:Y ; txt:<?PHP echo _("Date"); ?> ; stok:frmok ; stbad:frmbad",
                "nom:heured; format:liste ; req:Y ; txt:<?PHP echo _("Heure début"); ?> ; vmn:1; stok:frmok ; stbad:frmbad",
                "nom:heuref; format:liste ; req:Y ; txt:<?PHP _("Heure fin"); ?> ; vmn:1 ; stok:frmok ; stbad:frmbad",
                "nom:obj; format:txt ; req:Y ; txt:<?PHP echo _("Objectif"); ?> ; stok:frmok ; stbad:frmbad"];
            //-->
        </script>
    <?PHP } ?>

    <?PHP if ($pbm_dosd == 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"); ?>"
                });

                <?PHP if ($dos_cloture == true) { ?>
                $("#dateactf").datepicker({
                    onSelect: function (datesel) {
                        $("#dateactf").blur();
                        if (chk_datedif(datesel, this.id, '<?PHP echo $_SESSION['date_fmtshort']; ?>', true, 'dateddef', '', '',false)) {
                            chk_datefin_dos(this.id, 'codeage,codecat,codestatut,urgence,proba,ave,titred,resum,codesuiv', true);
                        }
                    }
                });
                <?PHP } ?>
            }

            function init_all() {
                init_Body();
                $( "#onglets_dosd1" ).tabs();
                $( "#onglets_dosd2" ).tabs();
                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']; ?>,'');
                img_checkpour('proba', 'nivnproba');
                img_checkpour('ave', 'nivnave', 2);
                img_checkpour('exproba', 'nivexproba');
                img_checkpour('exave', 'nivexave', 2);
                chk_ta($('#typea').val(),'det_depl');
                <?php
                switch ($td)
                {
                    case "add" :
                    case "edit" :
                        echo "init_ajax_cmque();";
                        echo "chk_addctact('mque','addcmque');";
                        // echo "verif_lnk_addctact('0','mque','addcmque');";
                        echo "init_ajax_cdo();";
                        echo "chk_addctact('do','addcdo');";
                        // echo "verif_lnk_addctact('0','do','addcdo');";
                        echo "init_ajax_cst();";
                        echo "chk_addctact('st','addst');";
                        // echo "verif_lnk_addctact('0','st','addcst');";
                        echo "init_chk_frais('a_fa','a_fad');";
                        echo "init_chk_frais('r_fa','r_fad');";
                        echo "init_checkpour('proba','nivnproba');";
                        echo "init_checkpour('ave','nivnave',2);";
                        echo "img_checksw('codestatut','exstatut','swstatut');";
                        echo "img_checksw('urgence','exurg','swurg');";
                        echo "img_checksw('proba','exproba','swproba');";
                        echo "img_checksw('ave','exave','swave');";
                        echo "init_fensaisie('add_ctactage',1024,600);";
                        echo "init_fensaisie('add_ctactcli',1024,650);";
                        echo "init_fensaisie('add_ctactmque',1024,650);";
                        echo "init_fen_cmque_dosd('add_ctactmque','fscomp2',1024,650),";
                        echo "init_fen_cdo_dosd('add_ctactdo','fscomp2',1024,650);";
                        echo "init_fen_cst_dosd('add_ctactst','fscomp2',1024,650);";
                        echo "init_chk_ta('typea','det_depl');";
                        echo "init_chk_dosdclos('clore','cage-codetec-ccli-cmque-cdo-cst-res-concl-codestatut-urgence-proba-ave',true);";
                        echo "init_autoraz('razdateact','dateactf','click');";
                        echo "init_autoraz('razheured','heured','click');";
                        echo "init_autoraz('razheuref','heuref','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');";
                        echo "init_chk_heuredif('heured','change',true,'','','heuref');";
                        echo "init_chk_heuredif('heuref','change',true,'heured','','');";
                        echo "init_chk_heuredif('a_heured','change',true,'','','heured,heuref,a_heuref,r_heured,r_heuref');";
                        echo "init_chk_heuredif('a_heuref','change',true,'a_heured','','heured,heuref,r_heured,r_heuref');";
                        echo "init_chk_heuredif('r_heured','change',true,'heured,heuref,a_heured,a_heuref','','r_heuref');";
                        echo "init_chk_heuredif('r_heuref','change',true,'heured,heuref,a_heured,a_heuref,r_heured','','');";
                        echo "init_valid_dosd('enr','dosd_maj',tab1_champ,'','');";
                        break;
                    case "del" :
                        echo "readonly_all();";
                        echo "warn_del('age');";
                        break;
                    case "view" :
                        echo "readonly_all();";
                        break;
                }
                ?>
                add_func_click('quit', 'sclose','');
                Focus_first();
            }

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

<?PHP
if ($pbm_dosd == FALSE) {
    ?>
    <p align="center"><span class="titrepage"><?PHP echo $titre ?></span></p>
    <p align="center"><span class="titre_gras"><?PHP echo _("Pour le dossier"). ' : '.$dos_code; ?> </span><br />
        <span class="annot_petit_it"><?PHP echo $dos_titre; ?> </span></p>

    <form name="dosd_maj" id="dosd_maj"  method="post" action="dosd_enr.php">
    <input name="titre" type="hidden" id="titre" value="<?PHP echo $titre ?>">
    <input name="td" type="hidden" id="td" value="<?PHP echo $td ?>">
    <input name="codeage" type="hidden" id="codeage" value="<?PHP echo $dos_codeage ?>">
    <input name="codecli" type="hidden" id="codecli" value="<?PHP echo $dos_codecli ?>">
    <input name="codedos" type="hidden" id="codedos" value="<?PHP echo $dos_code ?>">
    <input name="nd" type="hidden" id="nd" value="<?PHP echo $iddosd ?>">
    <input name="nbutton" type="hidden" id="nbutton" value="">
    <div align="right">
        <input name="quit" type="button" class="bton_std" id="quit" value="<?PHP echo _("Quitter"); ?>">
    </div>

    <table width="100%" border="0">
    <tr>
        <td width="160" class="rubfrm" id="f_typea" align="right"><?PHP echo _("Type action"); ?></td>
        <td>
            <?PHP
            // Création de la liste cachée des types
            // pour savoir si déplacement = "_"+codetype
            $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
            $rech = "SELECT * FROM `" . TBTA . "`";
            $rows = $db->get_results($rech, ARRAY_A);
            if ($rows) {
                foreach ($rows as $row) {
                    $row = encode_str($row);
                    extract($row);
                    echo '<input name="_' . $ta_code . '" type="hidden" id="_' . $ta_code . '" value="' . $ta_depl . '">';
                }
            }
            $db->disconnect();

            // Création de la liste des Types
            $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
            $rech = "SELECT * FROM `" . TBTA . "` WHERE `ta_doss`=1 ORDER BY ta_desc";
            $rows = $db->get_results($rech, ARRAY_A);
            $db->disconnect();
            cre_select_tab('typea', 'typea', $rows, 'ta_code', 'ta_desc', '', $dosd_codeta, '', _("-- Faites votre choix --"));
            ?>
        </td>
        <td id="f_clore" align="right">
        <?PHP
        echo _("Clore fiche");
        echo ' <input type="checkbox" name="clore" id="clore" value="clos" align="bottom" style="background-color:#FFFFFF;';
         if ($dosd_clos == 1)
            echo ' checked';
        echo '>';
        ?>
        </td>
    </tr>
    </table>
    <table width="100%" border="0">
    <tr>
        <td width="160" class="rubfrm" id="f_dta" align="right"><?PHP echo _("Date/heures action"); ?></td>
        <td>
            <input name="dateactf" type="text" id="dateactf" value="<?PHP echo $dosd_dateactf ?>" size="10" maxlength="10" readonly>
            <?PHP
            if (($td == "add") OR ($td == "edit"))
                echo ' <img src="../img/raz.png" id="razdateact" border="0" align="absmiddle">';

            $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 ' '._("heure début").' : ';
            cre_select('heured', 'heured', $tab_heures, substr($dosd_heured, 0, 5));
            if (($td == "add") OR ($td == "edit"))
                echo ' <img src="../img/raz.png" id="razheured" border="0" align="absmiddle">';
            echo ' / ';

            echo _("heure fin"). ' : ';
            cre_select('heuref', 'heuref', $tab_heures, substr($dosd_heuref, 0, 5));
            if (($td == "add") OR ($td == "edit"))
                echo ' <img src="../img/raz.png" id="razheuref" border="0" align="absmiddle">';
            ?>
        </td>
    </tr>
    </table>
    <div id="det_depl" style="display:none">
    <table width="100%" border="0">
    <tr>
        <td colspan="2" class="rubfrm" align="center"><?PHP echo _("Détail déplacement"); ?></td>
    </tr>
    <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, $dosd_acodemt, '', _("-- Faites votre choix --"));
            ?>
        </td>
        <td align="left">
            <?PHP
            cre_select('r_mt', 'r_mt', $tab_rmt, $dosd_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, ($pla_stepmin * 60), false);
            /*
            $tab_heures = give_tab_heures(($pprm_firsthour * 3600), ($pprm_lasthour * 3600), ($pla_stepmin * 60), false);
            $tab_heures = give_tab_heures(0,86400,300);
            */
            cre_select('a_heured', 'a_heured', $tab_heures, substr($dosd_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($dosd_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($dosd_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($dosd_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($dosd_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($dosd_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', $dosd_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', $dosd_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', $dosd_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', $dosd_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 $dosd_afraisd; ?></textarea>
        </td>
        <td align="center">
            <textarea name="r_fad" id="r_fad" rows="3" width="100%"><?PHP echo $dosd_rfraisd; ?></textarea>
        </td>
    </tr>
    </table>
    </div>
    <table width="100%" border="0">
        <tr>
            <td colspan="2" class="rubfrm" align="center"><?PHP echo _("Déroulement"); ?></td>
        </tr>
    </table>

    <div id="onglets_dosd1">
    <ul>
        <li><a href="#dosd1_obj"><?PHP echo _("Objectif"); ?></a></li>
        <li><a href="#dosd1_syn"><?PHP echo _("Synthèse"); ?></a></li>
        <li><a href="#dosd1_con"><?PHP echo _("Conclusion"); ?></a></li>
    </ul>
    <div id="dosd1_obj">
    <table width="100%" border="0">
        <tr>
            <td>
                <textarea name="obj" rows="7" id="obj" style="width:95%;"><?PHP echo $dosd_obj ?></textarea>
                <?PHP
                if (($td == "add") OR ($td == "edit"))
                    echo ' <img src="../img/oblig.png" align="top" alt="'._("Champ obligatoire").'">';
                ?>
            </td>
        </tr>
    </table>
    </div>

    <div id="dosd1_syn">
    <table width="100%" border="0">
        <tr>
            <td>
                <textarea name="res" rows="7" id="res" style="width:95%;"><?PHP echo $dosd_res ?></textarea>
                <?PHP
                if (($td == "add") OR ($td == "edit"))
                    echo ' <img src="../img/oblig.png" align="top" alt="'._("Champ obligatoire").'">';
                ?>
            </td>
        </tr>
    </table>
    </div>

    <div id="dosd1_con">
    <table width="100%" border="0">
        <tr>
            <td>
                <textarea name="concl" rows="7" id="concl" style="width:95%;"><?PHP echo $dosd_concl ?></textarea>
                <?PHP
                if (($td == "add") OR ($td == "edit"))
                    echo ' <img src="../img/oblig.png" align="top" alt="'._("Champ obligatoire").'">';
                ?>
            </td>
        </tr>
    </table>
    </div>
    </div>


    <table width="100%" border="0">
        <tr>
            <td colspan="2" class="rubfrm" align="center"><?PHP echo _("Intervenants"); ?></td>
        </tr>
    </table>
    <?PHP
    if (($td == "add") or ($td == "edit"))
    {
        echo '<div align="center" class="annot_petit_it">';
        echo '('._("Pour plusieurs contacts, sélectionnez les personnes concernées avec Ctrl + clic gauche, catégorie par catégorie").')';
        echo '</div>';
    }
    ?>

    <div id="onglets_dosd2">
    <ul>
        <li><a href="#dosd2_age"><?PHP echo _("Agence"); ?></a></li>
        <li><a href="#dosd2_tec"><?PHP echo _("Technicien(s)"); ?></a></li>
        <li><a href="#dosd2_cli"><?PHP echo _("Client"); ?></a></li>
        <li><a href="#dosd2_fe"><?PHP echo _("Fabriquant / Editeur"); ?></a></li>
        <li><a href="#dosd2_do"><?PHP echo _("Donneur d'ordres"); ?></a></li>
        <li><a href="#dosd2_st"><?PHP echo _("Sous-traitant"); ?></a></li>
    </ul>
    <div id="dosd2_age">
    <table width="100%" border="0">
        <tr>
            <td>&nbsp;</td>
            <td align="right">
                <?PHP
                if (($td == "add") or ($td == "edit")) {
                    $url_addctact = 'cage_maj.php?td=add&ca=' . $dos_codeage . '&tx=dosd_cage';
                    cre_falselnk('', 'add_ctactage', 'span', '', _("Ajouter un contact"), $url_addctact, '../img/ctacts.png', _("Ajouter un contact"));
                } else
                    echo "&nbsp;";
                ?>
            </td>
        </tr>
        <tr>
            <td colspan="2">
                <?PHP
                // Création de la liste des contacts de l'agence
                echo '<select name="cage[]" id="cage" size="5" class="annot_petit" multiple="multiple" style="width:95%;"';
                if (($td == "del") or ($td == "view"))
                    echo ' disabled';
                echo '>';
                $row = lit_enr_age($dos_codeage, TRUE);
                if (is_array($row))
                    extract($row);

                // Contact principal
                $txt_cage = $age_resp_nom . " " . $age_resp_prenom . " (Contact principal)";
                if (($td == "add") or ($td == "edit")) {
                    echo '<option value="-1"';
                    if (exist_inter_id_in_dosdi($dosd_id, 0, "-1", $dos_codeage, TRUE))
                        echo ' selected';
                    echo '>' . $txt_cage . '</option>';
                } else {
                    if (exist_inter_id_in_dosdi($dosd_id, 0, "-1", $dos_codeage, TRUE)) {
                        echo '<option value="-1" selected';
                        echo '>' . $txt_cage . '</option>';
                    }
                }
                $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);

                // Contacts secondaires
                $rech = "SELECT * FROM `" . TBCAGE . "` WHERE `cage_codeage` = '" . $dos_codeage . "' ORDER BY cage_nom";
                $rows = $db->get_results($rech, ARRAY_A);
                if ($rows) {
                    foreach ($rows as $row) {
                        $row = encode_str($row);
                        extract($row);

                        $txt_cage = $cage_nom . " " . $cage_prenom;
                        $row2 = lit_enr_fonc($cage_codefonc, FALSE);
                        if (is_array($row2)) {
                            $row2 = encode_str($row2);
                            extract($row2);
                            $txt_fonc = $fonc_desc;
                        } else
                            $txt_fonc = $cage_codefonc;
                        $txt_cage .= " (" . $txt_fonc . ")";
                        if (($td == "add") or ($td == "edit")) {
                            echo '<option value="' . $cage_id . '"';
                            if ($td == "edit") {
                                if (exist_inter_id_in_dosdi($dosd_id, 0, $cage_id, $dos_codeage, FALSE))
                                    echo ' selected';
                            }
                            echo '>' . $txt_cage . '</option>';
                        } else {
                            if (exist_inter_id_in_dosdi($dosd_id, 0, $cage_id, $dos_codeage, FALSE)) {
                                echo '<option value="' . $cage_id . '" selected';
                                echo '>' . $txt_cage . '</option>';
                            }
                        }
                    }
                }
                $db->disconnect();
                echo '</select>';
                ?>
            </td>
        </tr>
    </table>
    </div>

    <div id="dosd2_tec">
    <table width="100%" height="50px" border="0">
        <tr>
            <td>&nbsp;</td>
        </tr>
        <tr>
            <td>
                <?PHP
                echo '<select name="codetec[]" id="codetec" class="annot_petit" multiple="multiple" size="5" style="width:95%;"';
                if (($td == "del") or ($td == "view"))
                    echo ' disabled';
                echo '>';

                // Création de la liste des Techniciens de l'agence
                $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
                $rech = "SELECT * FROM `" . TBTEC . "` WHERE `tec_codeage` = '$dos_codeage' AND `tec_out` = '0' ORDER BY tec_nom";
                $rows = $db->get_results($rech, ARRAY_A);
                if ($rows) {
                    foreach ($rows as $row) {
                        $row = encode_str($row);
                        extract($row);
                        $txt_tec = $tec_nom . " " . $tec_prenom;
                        if (($td == "add") or ($td == "edit")) {
                            echo '<option value="' . $tec_id . '"';
                            if (exist_inter_id_in_dosdi($dosd_id, '1', $tec_id, $tec_code, FALSE))
                                echo ' selected';
                            echo '>' . $txt_tec . '</option>';
                        } else {
                            if (exist_inter_id_in_dosdi($dosd_id, '1', $tec_id, $tec_code, FALSE)) {
                                echo '<option value="' . $tec_id . '" selected';
                                echo '>' . $txt_tec . '</option>';
                            }
                        }
                    }
                }
                $db->disconnect();
                echo '</select>';
                ?>
            </td>
        </tr>
    </table>
    </div>

    <div id="dosd2_cli">
    <table width="100%" border="0">
        <tr>
            <td>
                <span class="annot_petit_it"><?PHP echo _("Les contacts sites sont en fin de liste"); ?></span>
            </td>
            <td align="right">
                <?PHP
                if (($td == "add") or ($td == "edit")) {
                    $url_addctact = 'ccli_maj.php?td=add&cc=' . $dos_codecli . '&tx=dosd_ccli';
                    cre_falselnk('', 'add_ctactcli', 'span', '', _("Ajouter un contact"), $url_addctact, '../img/ctacts.png', _("Ajouter un contact"));
                } else
                    echo "&nbsp;";
                ?>
            </td>
        </tr>
        <tr>
            <td colspan="2">
                <?PHP
                // Création de la liste des contacts du client
                echo '<select name="ccli[]" id="ccli" size="5" class="annot_petit" multiple="multiple" style="width:95%;"';
                if (($td == "del") or ($td == "view"))
                    echo ' disabled';
                echo '>';
                $row = lit_enr_cli($dos_codecli, TRUE);
                if (is_array($row))
                    extract($row);

                // Contact principal
                $txt_ccli = $cli_nom . " " . $cli_prenom . " (Contact principal)";
                if (($td == "add") or ($td == "edit")) {
                    echo '<option value="-1"';
                    if (exist_inter_id_in_dosdi($dosd_id, 2, "-1", $cli_code, TRUE))
                        echo ' selected';
                    echo '>' . $txt_ccli . '</option>';
                } else {
                    if (exist_inter_id_in_dosdi($dosd_id, 2, "-1", $cli_code, TRUE)) {
                        echo '<option value="-1" selected';
                        echo '>' . $txt_ccli . '</option>';
                    }
                }
                $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);

                // Contacts secondaires
                $rech = "SELECT * FROM `" . TBCCLI . "` WHERE `ccli_codecli` = '" . $cli_code . "' ORDER BY ccli_nom";
                $rows = $db->get_results($rech, ARRAY_A);
                if ($rows) {
                    foreach ($rows as $row) {
                        $row = encode_str($row);
                        extract($row);

                        $txt_ccli = $ccli_nom . " " . $ccli_prenom;
                        $row2 = lit_enr_fonc($ccli_codefonc, FALSE);
                        if (is_array($row2)) {
                            $row2 = encode_str($row2);
                            extract($row2);
                            $txt_fonc = $fonc_desc;
                        } else
                            $txt_fonc = $ccli_codefonc;
                        $txt_ccli .= " (" . $txt_fonc . ")";
                        if (($td == "add") or ($td == "edit")) {
                            echo '<option value="' . $ccli_id . '"';
                            if ($td == "edit") {
                                if (exist_inter_id_in_dosdi($dosd_id, 2, $ccli_id, $cli_code, FALSE))
                                    echo ' selected';
                            }
                            echo '>' . $txt_ccli . '</option>';
                        } else {
                            if (exist_inter_id_in_dosdi($dosd_id, 2, $ccli_id, $cli_code, FALSE)) {
                                echo '<option value="' . $ccli_id . '" selected';
                                echo '>' . $txt_ccli . '</option>';
                            }
                        }
                    }
                }

                // Contacts sites client
                if (($td == "add") or ($td == "edit"))
                    echo '<optgroup label="'._("Sites secondaires").'">';
                $rech = "SELECT * FROM `" . TBSCLI . "` WHERE `scli_codecli` = '" . $cli_code . "' ORDER BY scli_ste,scli_rnom";
                $rows = $db->get_results($rech, ARRAy_A);
                if ($rows) {
                    $siteact = "";
                    foreach ($rows as $row) {
                        $row = encode_str($row);
                        extract($row);
                        $txt_ccli = $scli_rnom . " " . $scli_rprenom;
                        $row2 = lit_enr_fonc($scli_rcodefonc, FALSE);
                        if (is_array($row2)) {
                            $row2 = encode_str($row2);
                            extract($row2);
                            $txt_fonc = $fonc_desc;
                        } else
                            $txt_fonc = $scli_rcodefonc;
                        $txt_ccli .= " (" . $txt_fonc . ")";
                        if (($td == "add") or ($td == "edit")) {
                            if ($siteact <> $scli_ste) {
                                if ($siteact <> "")
                                    echo "</optgroup>\n";
                                echo "<optgroup label=\">>Site : " . $scli_ste . "\">\n";
                            }
                            echo '<option value="S_' . $scli_id . '"';
                            if ($td == "edit") {
                                if (exist_inter_id_in_dosdi($dosd_id, 6, $scli_id, $cli_code, FALSE))
                                    echo ' selected';
                            }
                            echo '>' . $txt_ccli . '</option>';
                        } else {
                            if (exist_inter_id_in_dosdi($dosd_id, 6, $scli_id, $cli_code, FALSE)) {
                                echo '<option value="S_' . $scli_id . '" selected';
                                $txt_ccli .= " - site " . $scli_ste;
                                echo '>' . $txt_ccli . '</option>';
                            }
                        }
                        $siteact = $scli_ste;
                    }
                }
                if (($td == "add") or ($td == "edit"))
                    echo "</optgroup>\n";
                $db->disconnect();
                echo '</select>';
                ?>
            </td>
        </tr>
    </table>
    </div>

    <div id="dosd2_fe">
    <table width="100%" border="0">
        <tr>
            <td width="33%">
                <?PHP
                $codemque = "";
                if ($td <> "add")
                    $codemque = donne_code_mds($iddosd, 3, TRUE);
                // Création de la liste des marques
                $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
                $rech = "SELECT * FROM `" . TBMQUE. "`";
                $rech.= " WHERE `mque_code` <> '*'";
                $rech.= " ORDER BY mque_ste";
                $rows = $db->get_results($rech, ARRAY_A);
                $db->disconnect();
                cre_select_tab('mque', 'mque', $rows, 'mque_code', 'mque_ste', '', $codemque, '', _("-- Faites votre choix --"),1,FALSE,'','',FALSE);
                ?>
            </td>
            <td width="33%">
            </td>
            <td align="right">
                <span id="addcmque" style="display:none;">
                <?PHP
                if (($td == "add") or ($td == "edit"))
                {
                    $url_addctact = 'ccli_maj.php?td=add&cm=' . $dos_codecli . '&tx=dosd_cmque';
                    cre_falselnk('', 'add_ctactmque', 'span', '', _("Ajouter un contact"), $url_addctact, '../img/ctacts.png', _("Ajouter un contact"));
                }
                else
                    echo "&nbsp;";
                ?>
                </span>
            </td>
        </tr>
        <tr>
            <td colspan="3">
                <?PHP
                echo '<select name="cmque[]" id="cmque" size="5" class="annot_petit" multiple="multiple" style="width:95%;">';

                // Création de la liste des contacts marques
                $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
                $rech = "SELECT * FROM `" . TBCMQUE . "` WHERE `cmque_codemque` = '" . $codemque . "' ORDER BY cmque_nom";
                $rows = $db->get_results($rech, ARRAY_A);
                if ($rows) {
                    foreach ($rows as $row) {
                        $row = encode_str($row);
                        extract($row);
                        $txt = $cmque_nom . " " . $cmque_prenom;
                        $row2 = lit_enr_fonc($cmque_codefonc, FALSE);
                        if (is_array($row2)) {
                            $row2 = encode_str($row2);
                            extract($row2);
                            $txt_fonc = $fonc_desc;
                        } else
                            $txt_fonc = $cmque_codefonc;
                        $txt .= " (" . $txt_fonc . ")";

                        if (($td == "add") or ($td == "edit")) {
                            echo '<option value="' . $cmque_id . '"';
                            if ($td == "edit") {
                                if (exist_inter_id_in_dosdi($dosd_id, 3, $cmque_id, $codemque, FALSE))
                                    echo ' selected';
                            }
                            echo '>' . $txt . '</option>';
                        } else {
                            if (exist_inter_id_in_dosdi($dosd_id, 3, $cmque_id, $codemque, FALSE)) {
                                echo '<option value="' . $cmque_id . '" selected';
                                echo '>' . $txt . '</option>';
                            }
                        }
                    }
                }
                $db->disconnect();
                echo '</select>';
                ?>
            </td>
        </tr>
    </table>
    </div>

    <div id="dosd2_do">
    <table width="100%" border="0">
        <tr>
            <td width="33%">
                <?PHP
                $codedo = "";
                if ($td <> "add")
                    $codedo = donne_code_mds($iddosd, 4, TRUE);
                // Création de la liste des donneurs d'ordres
                $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
                $rech = "SELECT * FROM `" . TBDO . "` ORDER BY do_nom";
                $rows = $db->get_results($rech, ARRAY_A);
                $db->disconnect();
                cre_select_tab('do', 'do', $rows, 'do_code', 'do_nom', '', $codedo, '', _("-- Faites votre choix --"),1,FALSE,'','',FALSE);
                ?>
            </td>
            <td width="33%">
            </td>
            <td align="right">
            <span id="addcdo" style="display:none;">
            <?PHP
            if (($td == "add") or ($td == "edit"))
                echo '<a href="" id="add_ctactdo"><img src="../img/ctacts.png" border="0" align="absmiddle"> '._("Ajouter un contact").'</a>';
            else
                echo "&nbsp;";
            ?>
            </span>
            </td>
        </tr>
        <tr>
            <td colspan="3">
                <?PHP
                echo '<select name="cdo[]" id="cdo" size="5" class="annot_petit" multiple="multiple" style="width:95%;">';

                // Création de la liste des contacts donneurs d'ordres
                $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
                $rech = "SELECT * FROM `" . TBCDO . "` WHERE `cdo_codedo` = '" . $codedo . "' ORDER BY cdo_nom";
                $rows = $db->get_results($rech, ARRAY_A);
                if ($rows) {
                    foreach ($rows as $row) {
                        $row = encode_str($row);
                        extract($row);
                        $txt = $cdo_nom . " " . $cdo_prenom;
                        $row2 = lit_enr_fonc($cdo_codefonc, FALSE);
                        if (is_array($row2)) {
                            $row2 = encode_str($row2);
                            extract($row2);
                            $txt_fonc = $fonc_desc;
                        } else
                            $txt_fonc = $cdo_codefonc;
                        $txt .= " (" . $txt_fonc . ")";

                        if (($td == "add") or ($td == "edit")) {
                            echo '<option value="' . $cdo_id . '"';
                            if ($td == "edit") {
                                if (exist_inter_id_in_dosdi($dosd_id, 4, $cdo_id, $codedo, FALSE))
                                    echo ' selected';
                            }
                            echo '>' . $txt . '</option>';
                        } else {
                            if (exist_inter_id_in_dosdi($dosd_id, 4, $cdo_id, $codedo, FALSE)) {
                                echo '<option value="' . $cdo_id . '" selected';
                                echo '>' . $txt . '</option>';
                            }
                        }
                    }
                }
                $db->disconnect();
                echo '</select>';
                ?>
            </td>
        </tr>
    </table>
    </div>

    <div id="dosd2_st">
    <table width="100%" border="0">
        <tr>
            <td width="33%">
                <?PHP
                $codest = "";
                if ($td <> "add")
                    $codest = donne_code_mds($iddosd, 5, TRUE);
                // Création de la liste des sous-traitants
                $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
                $rech = "SELECT * FROM `" . TBST . "` ORDER BY st_nom";
                $rows = $db->get_results($rech, ARRAY_A);
                $db->disconnect();
                cre_select_tab('st', 'st', $rows, 'st_code', 'st_nom', '', $codest, '', _("-- Faites votre choix --"),1,FALSE,'','',FALSE);
                ?>
            </td>
            <td width="33%">
            </td>
            <td align="right">
            <span id="addcst" style="display:none;">
            <?PHP
            if (($td == "add") or ($td == "edit"))
                echo '<a href="" id="add_ctactst"><img src="../img/ctacts.png" border="0" align="absmiddle"> '._("Ajouter un contact").'</a>';
            else
                echo "&nbsp;";
            ?>
            </span>
            </td>
        </tr>
        <tr>
            <td colspan="3">
                <?PHP
                echo '<select name="cst[]" id="cst" size="5" class="annot_petit" multiple="multiple" style="width:95%;">';
                $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
                $rech = "SELECT * FROM `" . TBCST . "` WHERE `cst_codest` = '" . $codest . "' ORDER BY cst_nom";
                $rows = $db->get_results($rech, ARRAY_A);
                if ($rows) {
                    foreach ($rows as $row) {
                        $row = encode_str($row);
                        extract($row);
                        $txt = $cst_nom . " " . $cst_prenom;
                        $row2 = lit_enr_fonc($cst_codefonc, FALSE);
                        if (is_array($row2)) {
                            $row2 = encode_str($row2);
                            extract($row2);
                            $txt_fonc = $fonc_desc;
                        } else
                            $txt_fonc = $cst_codefonc;
                        $txt .= " (" . $txt_fonc . ")";

                        if (($td == "add") or ($td == "edit")) {
                            echo '<option value="' . $cst_id . '"';
                            if ($td == "edit") {
                                if (exist_inter_id_in_dosdi($dosd_id, 5, $cst_id, $codest, FALSE))
                                    echo ' selected';
                            }
                            echo '>' . $txt . '</option>';
                        } else {
                            if (exist_inter_id_in_dosdi($dosd_id, 5, $cst_id, $codest, FALSE)) {
                                echo '<option value="' . $cst_id . '" selected';
                                echo '>' . $txt . '</option>';
                            }
                        }
                    }
                }
                $db->disconnect();
                echo '</select>';
                ?>
            </td>
        </tr>
    </table>
    </div>

    <?PHP if (($td == "add") OR ($td == "edit")) { ?>
        <table width="100%" border="0">
            <tr>
                <td colspan="4" class="rubfrm" align="center"><?PHP echo _("Nouveaux paramètres dossier").' '.$codedos; ?></td>
            </tr>
            <tr>
                <td width="160">&nbsp;</td>
                <td class="rubfrm" align="center"><?PHP echo _("Actuellement"); ?></td>
                <td width="16px">&nbsp;</td>
                <td width="40%" class="rubfrm" align="center"><?PHP echo _("Nouveau"); ?></td>
            </tr>
            <tr>
                <td width="160" class="rubfrm" align="right"><?PHP echo _("Statut"); ?></td>
                <td>
                    <input name="exstatut" type="hidden" id="exstatut" value="<?PHP echo $doss_code; ?>" readonly>
                    <input name="nexstatut" type="text" id="nexstatut" value="<?PHP echo $doss_desc; ?>" size="50" readonly>
                </td>
                <td width="16px"><span id="swstatut"></span></td>
                <td width="40%">
                    <?PHP
                    // Création de la liste des Statuts
                    $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
                    $rech = "SELECT * FROM `" . TBDOSS . "`";
                    $rech.= "  WHERE `doss_code` <> 'CLOT'";
                    $rech .= " ORDER BY doss_desc";
                    $rows = $db->get_results($rech, ARRAY_A);
                    $db->disconnect();
                    cre_select_tab('codestatut', 'codestatut', $rows, 'doss_code', 'doss_desc', '', $doss_code, '', _("-- Faites votre choix --"));
                    ?>
                </td>
            </tr>
            <tr>
                <td width="160" class="rubfrm" align="right"><?PHP echo _("Urgence"); ?></td>
                <td>
                    <?PHP
                    $row = lit_enr_urg($dos_urg);
                    if (is_array($row))
                    {
                        encode_str($row);
                        extract($row);
                    }
                    ?>
                    <input name="exurg" type="hidden" id="exurg" value="<?PHP echo $dos_urg; ?>" readonly>
                    <input name="nexurg" type="text" id="nexurg" value="<?PHP echo $urg_des; ?>" size="50" maxlength="50" readonly>
                </td>
                <td width="16px"><span id="swurg"></span></td>
                <td width="40%">
                    <?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();
                    // echo ' <span id="obl4" style="display:none;"><img src="../img/oblig.png" align="absmiddle" alt="'._("Champ obligatoire").'"></span>';
                    cre_select_tab('urgence', 'urgence', $rows, 'urg_niveau', 'urg_des', '', $dos_urg);
                    ?>
                </td>
            </tr>
            <tr>
                <td width="160" class="rubfrm" align="right"><?PHP echo _("Probabilité"); ?></td>
                <td>
                    <input name="exproba" type="text" id="exproba" value="<?PHP echo $dos_proba; ?>" size="5" readonly>%
                    <span id="nivexproba"></span>
                </td>
                <td width="16px"><span id="swproba"></span></td>
                <td width="40%">
                    <?PHP
                    $tab_niveaux = [];
                    // Création des niveaux
                    for ($i = 0; $i < 110; $i += 10) {
                        $tab_niveaux[$i] = $i . '%';
                    }
                    cre_select('proba', 'proba', $tab_niveaux, $dos_proba, '', _("-- Faites votre choix --"));
                    ?>
                    <span id="nivnproba"></span>
                </td>
            </tr>
            <tr>
                <td width="160" class="rubfrm" align="right"><?PHP echo _("Etat Avancement"); ?></td>
                <td>
                    <input name="exave" type="text" id="exave" value="<?PHP echo $dos_avance; ?>" size="5" readonly>%
                    <span id="nivexave"></span>
                </td>
                <td width="16px"><span id="swave"></span></td>
                <td width="40%">
                    <?PHP
                    cre_select('ave', 'ave', $tab_niveaux, $dos_avance, '', _("-- Faites votre choix --"));
                    ?>
                    <span id="nivnave"></span>
                </td>
            </tr>
        </table>
    <?PHP } ?>
    <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").'">';
                break;
                break;
            case "del" :
                echo '<input name="del" type="submit" class="bton_std" id="del" value="'._("Supprimer").'">';
                break;
        }
        ?>
    </p>
    </form>
<?PHP
} else
    close_fen_auto('', 'fscomp');
?>
</body>
</html>
