<?php
/****************************************************************************************
 * SMI (Services Maintenance Interventions) est une gestion libre de maintenance et de SAV
 *
 * Version 1.0.0
 *
 * Copyright (C) 2006-2014  Sylvain FATOME
 * This program is free software; you can redistribute it and/or modify it under the terms
 * of the GNU General Public License as published by the Free Software Foundation;
 * either version 2 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with this program
 * (in the directory docs);
 * if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA  02110-1301, USA.
 *
 * Contact : galawa@free.fr
 *
 * Web : http://smi.no-ip.org
 ****************************************************************************************/


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

include_once("../inc/fic_age.inc.php");
include_once("../inc/fic_cli.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_prm.inc.php");
include_once("../inc/fic_tac.inc.php");
include_once("../inc/fic_tec.inc.php");
include_once("../inc/fic_zc.inc.php");
include_once("../inc/func.inc.php");
include_once("../inc/func_time.inc.php");
include_once("../inc/func_date.inc.php");
include_once("../inc/func_geo.inc.php");
include_once("../inc/func_txt.inc.php");
include_once("../classes/ezSQL/shared/ez_sql_core.php");
include_once("../classes/ezSQL/mysqli/ez_sql_mysqli.php");
include_once("../inc/func_sql.inc.php");
Archivelog(@$_SESSION["code_log"]);
// Variables Formulaire
fix_magic_quotes();
$_GET = clean_str($_GET);

$td = $_GET['td']; // Récupération type demande
$cd = $_GET['cd']; // Récupération code Dossier
$cc = $_GET['cc']; // Récupération code Client
$ca = $_GET['ca']; // Récupération code Agence

$pbm_dos = FALSE;
$nbligdos = 0;

if ($ca <> "") {
    // Contrôle qu'une agence n'essaye pas de "hacker" un dossier
    if (((@$_SESSION["niv_log"] == 4) OR (@$_SESSION["niv_log"] == 3)) AND ($ca <> @$_SESSION["code_age"]))
        $pbm_dos = TRUE;
    $dos_codeage = $ca;
}

if ($cd <> "") {
    // vérification qu'il existe bien des saisies dans le dossier
    // $nbligdos = nb_lig_in_dos($cd);

    // Récupération des informations dossier
    $row = lit_enr_dos($cd);
    if (is_array($row)) {
        $row = encode_str($row);
        extract($row);

        if ($td <> "add") {
            // Contrôle qu'une agence n'essaye pas de "hacker" un dossier
            if (((@$_SESSION["niv_log"] == 4) OR (@$_SESSION["niv_log"] == 3)) AND ($dos_codeage <> @$_SESSION["code_age"]))
                $pbm_dos = TRUE;
        }

        // Formatage des dates en français
        $dos_datecreaf = datetolocal($dos_datecrea);
        $dos_datemodf = datetolocal($dos_datemod);
        $dos_dateddef = datetolocal($dos_datedde);
        $dos_datefinpf = datetolocal($dos_datefinp);
        $dos_datefinf = datetolocal($dos_datefin);

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

        if ($td == "edit") {
            $cc = $dos_codecli;
            $ca = $dos_codeage;
        }

        if ($td == "add") {
            $dos_dateddef = $datef;
            $dos_code = $cd;
            $dos_codecli = $cc;
            $dos_codeage = $ca;
        }

        if (($td == "edit") OR ($td == "view") OR ($td == "del"))
            // Calcul du prix de revient du contrat
            $pxrevient = px_revient_dos($cd, TRUE);
    } else
        $pbm_dos = TRUE;


} else {
    if ($td == "add") {
        $dos_dateddef = $datef;
        $dos_code = crecodesession("DS");
        $cd = $dos_code;
    } else
        $pbm_dos = TRUE;
}

$pbm_cli = FALSE;
if ($cc <> "") {
    $row = lit_enr_cli($cc, TRUE);
    if (is_array($row)) {
        $dos_codecli = $cc;

        $row = encode_str($row);
        extract($row);
        $dos_codeage = $cli_prop;

        // Contrôle qu'une agence n'essaye pas de "hacker" une intervention
        switch (@$_SESSION["niv_log"]) {
            case 3 :
            case 4 :
                if (client_age_ok($cli_code, @$_SESSION["code_age"], TRUE) == FALSE)
                    $pbm_cli = TRUE;
                break;
            default :
                break;
        }
    } else {
        $pbm_cli = TRUE;
    }
} else {
    if (($td == "edit") OR ($td == "view") OR ($td == "del"))
        $pbm_cli = TRUE;
}

switch ($td) {
    case "add" :
        $titre = _("SAISIE DOSSIER");
        $dos_proba = "";
        break;
    case "edit" :
        $titre = _("MISE A JOUR DOSSIER");
        break;
    case "view" :
        $titre = _("VISUALISATION DOSSIER");
        break;
    case "del":
        $titre = _("SUPPRESSION DOSSIER");
        break;
    default:
        $titre = _("PROBLEME");
        $pbm_dos = TRUE;
        break;
}

if (($pbm_dos == FALSE) AND ($pbm_cli == FALSE)) {
    // En cas de création, la devise par défaut du dossier est celle du compte qui saisi
    if ($td == "add") {
        switch (@$_SESSION["niv_log"]) {
            case 3 :
            case 4 :
                $dos_codeadev = give_dev_codea_defaut_age($_SESSION["code_age"], $_SESSION["lng"], TRUE);
                break;
            default :
                $dos_codeadev = give_dev_codea_defaut($_SESSION["lng"], TRUE);
                break;
        }
    } else
        // Sinon, on récupère le code devise du dossier déjà créé
        $dos_codeadev = give_dev_codea_defaut_dos($dos_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;
    }

}

$lst_readonly_id = '';
$dos_cloture = true;
switch (@$_SESSION["niv_log"]) {
    case 3 :
        $lst_readonly_id = 'codeage-codesuiv';
        if ($_SESSION["code_log"] <> $dos_codesuiv)
        {
            $lst_readonly_id .= '-codecat-codestatut-urgence-proba-titred-resum-ave';
            $dos_cloture = false;
        }
        break;
    case 4 :
        $lst_readonly_id = 'codeage';
        if ($_SESSION["code_log"] <> $dos_codeage)
        {
            $lst_readonly_id .= '-codecat-codestatut-urgence-proba-titred-resum-ave';
            $dos_cloture = false;
        }
        break;
    default :
        if ($cli_prop <> NULL) // On affiche la liste uniquement si le client est non affecté
            $lst_readonly_id = 'codeage';
        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 _("Fiche Dossier"); ?></title>

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

    <?PHP
    if (($td == "edit")  OR ($td == "add")) {
        ?>
        <script language="javascript">
            <!--
            var tab1_champ = ["nom:dateddef ; format:date ; masque:<?PHP echo $_SESSION['date_fmtfull']; ?> ; req:Y ; txt:<?PHP echo _("Date demande"); ?> ; stok:frmok ; stbad:frmbad",
                "nom:codeage; format:liste ; req:Y ; txt:<?PHP echo _("Agence"); ?> ; vmn:1 ; stok:frmok ; stbad:frmbad",
                "nom:codecat; format:liste ; req:Y ; txt:<?PHP echo _("Catégorie"); ?> ; vmn:1 ; stok:frmok ; stbad:frmbad",
                "nom:codestatut; format:liste ; req:Y ; txt:<?PHP echo _("Statut"); ?> ; vmn:1 ; stok:frmok ; stbad:frmbad",
                "nom:urgence; format:liste ; req:Y ; txt:<?PHP echo _("Niveau d'urgence"); ?> ; vmn:1 ; stok:frmok ; stbad:frmbad",
                "nom:proba; format:liste ; req:Y ; txt:<?PHP echo _("Probabilité"); ?> ; vmn:1 ; stok:frmok ; stbad:frmbad",
                <?PHP
                if ($td <> "add")
                {
                    echo '"nom:ave; format:liste ; req:Y ; txt:'._("Etat avancemement").' ; vmn:1; stok:frmok ; stbad:frmbad",';
                    echo '"nom:codesuiv; format:liste ; req:Y ; txt:'._("Responsable dossier").' ; vmn:1; stok:frmok ; stbad:frmbad",';
                }
                ?>
                "nom:titred; format:txt ; req:Y ; txt:<?PHP echo _("Titre"); ?> ; lmx:50 ; stok:frmok ; stbad:frmbad",
                "nom:resum; format:txt ; req:Y ; txt:<?PHP echo _("Résumé"); ?> ; stok:frmok ; stbad:frmbad"];
            //-->
        </script>
    <?PHP
    }
    ?>

    <script type="text/javascript">
        <!--
        <?PHP cre_html_detindos($td,$cd,'detdosd',''); ?>

        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) { ?>
            $("#datefinf").datepicker({
                onSelect: function (datesel) {
                    $("#datefinf").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();
            init_autohref('tac', 'change','',false);
            img_checkpour('proba', 'nivproba');
            img_checkpour('ave', 'nivave', 2);
            init_autoraz('razdatefin', 'datefinf', 'click');
            init_datepicker();
            <?php
            switch ($td)
            {
                case "add" :
                    echo '$("#dateddef").datepicker({';
                    echo '    onSelect: function (datesel) {';
                    echo '        $("#dateddef").blur();';
                    echo "        chk_datedde('dateddef', '".$_SESSION['date_fmtshort']."', true);";
                    echo '    },';
                    echo '});';
                    echo '$("#datefinpf").datepicker({';
                    echo '    onSelect: function (datesel) {';
                    echo '        $("#datefinpf").blur();';
                    echo "        if (chk_datedif(datesel, this.id, '".$_SESSION['date_fmtshort']."', true, 'dateddef,today', '', '')) {";
                    echo "            chk_date_affwarnech(this.id, 'warn_ech', '".$_SESSION['date_fmtshort']."', '', '', 'today');";
                    echo '        }';
                    echo '    }';
                    echo '});';
                    echo "init_autoraz('razdatedde', 'dateddef', 'click');";
                    echo "init_autoraz('razdatefin', 'datefinpf', 'click');";
                    echo "init_warn('".nb_cli('')."cli','','back','','');";
                    echo "init_warn('".nb_tec_actifs()."tec','','back','','');";
                    echo "init_warn('".nb_age_actives()."age','','back','','');";

                    if (@$_SESSION["niv_log"] >= 3)
                    {
                        echo 'warn_cpta('.$cli_cpta.',"dos");';
                        echo "init_fensaisie('aff_notesc',930,380);";
                    }

                    echo "init_checkpour('proba','nivproba');";
                    echo "init_checkpour('ave','nivave',2);";
                    echo "init_valid_form('enr','dos_maj','".$_SESSION['date_fmtshort']."',tab1_champ,'','');";
                    break;
                case "edit" :
                    if (@$_SESSION["niv_log"] >= 3)
                    {
                        echo 'warn_cpta('.$cli_cpta.',"dos");';
                        echo "init_fensaisie('aff_notesc',930,380);";
                    }
                    echo "init_fensaisie('chx_dosd',900,650);";
                    echo "init_new_fen('imprim','impression','click');";
                    echo "init_checkpour('proba','nivproba');";
                    echo "init_checkpour('ave','nivave',2);";
                    echo "init_valid_form('enr','dos_maj','".$_SESSION['date_fmtshort']."',tab1_champ,'','');";
                    break;
                case "del" :
                    echo "warn_del('');";
                    echo "readonly_all();";
                    break;
                case "view" :
                    echo "init_new_fen('imprim','impression','click');";
                    echo "readonly_all();";
                    break;
            }
            ?>
            readonly_id('<?PHP echo $lst_readonly_id; ?>',false);
            detindos();
            init_autohref_classe('falselnkimg','');
            Focus_first();
        }

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

<?PHP include_once("../inc/entete.inc.php"); ?>
<!-- affiché uniquement s'il y a au moins un client, une agence active, une origine, un statut, un lieu, une civilité, un technicien dans l'agence, et un mode de règlement -->
<?PHP
if (($pbm_dos == FALSE) AND ($pbm_cli == FALSE)) {
    if ((nb_cli("") <> 0) AND (nb_age_actives() <> 0) AND (nb_doss() <> 0) AND (nb_dosc() <> 0) AND nb_tec("")) {
        ?>
        <!-- affiché uniquement s'il y a un code client -->
        <?PHP
        if ($cc <> "") {
            cre_ent_form($titre, 'dos_lst.php?ord=ASC&tri=Fin', $_SERVER['HTTP_REFERER'], 'dos_pdf.php?cd=' . $cd);
            ?>
            <form name="dos_maj" id="dos_maj" method="post" action="dos_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="codecli" type="hidden" id="codecli" value="<?PHP echo $dos_codecli; ?>">
            <input name="codeadev" type="hidden" id="codeadev" value="<?PHP echo $dos_codeadev; ?>">
            <input name="today" type="hidden" id="today" value="<?PHP echo $datef; ?>">
            <input name="nbutton" type="hidden" id="nbutton" value="">
            <?PHP if ($td == "add") { ?>
                <input name="code" type="hidden" id="code" value="<?PHP echo $dos_code ?>">
            <?PHP
            }
            ?>

            <!-- Date de demande -->
            <table width="100%" border="0">
                <tr>
                    <td width="160" class="rubfrm" id="f_dateddef" align="right"><?PHP echo _("Date Demande"); ?></td>
                    <td>
                        <input name="dateddef" type="text" id="dateddef" value="<?PHP echo $dos_dateddef ?>" size="10" maxlength="10" readonly>
                        <?PHP if ($td=="add")
                        {
                            echo ' <img src="../img/raz.png" id="razdatedde" border="0" align="absmiddle">';
                            echo ' <img src="../img/oblig.png" align="absmiddle" alt="'._("Champ obligatoire").'">';
                        }
                        ?>
                    </td>
                    <td align="right">
                        <?PHP
                        if (((@$_SESSION["niv_log"] == 5) OR (@$_SESSION["niv_log"] == 9) OR (@$_SESSION["niv_log"] == 4) OR (@$_SESSION["niv_log"] == 3)) AND ($td == "edit")) {
                            echo '<span id="strtac" style="visibility:visible">';
                            $nb_tac = nb_tac(4, $dos_code, TRUE);
                            if ($nb_tac > 0) {
                                echo "<span class=\"annot_petit_it\">";
                                echo "( " . $nb_tac . " " . _("tâche");
                                if ($nb_ot > 1)
                                    echo "( " . $nb_tac . " " . _("tâches");
                                else
                                    echo "( " . $nb_tac . " " . _("tâche");
                                $nb_tac_actives = nb_tac_actives(4, $dos_code, TRUE);
                                if ($nb_tac_actives > 0) {
                                    if ($nb_tac_actives > 1)
                                        echo ', ' . _("dont") . ' ' . $nb_tac_actives . ' ' . _("non terminée");
                                    else
                                        echo ', ' . _("dont") . ' ' . $nb_tac_actives . ' ' . _("non terminées");
                                }
                                echo ")";
                                echo "</span>";
                            } else {
                                echo '<span class="annot_petit_gras">';
                                echo _("Tâches") . ' : ';
                                echo '</span>';
                            }
                            echo '</span>';

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

            <!-- Date de fin prévue -->
            <table width="100%" border="0">
                <tr>
                    <td width="160" class="rubfrm" id="f_datefinpf" align="right"><?PHP echo _("Date fin prévue"); ?></td>
                    <td>
                        <input name="datefinpf" type="text" id="datefinpf" value="<?PHP echo $dos_datefinpf ?>" size="10" maxlength="10" readonly>
                        <?PHP if ($td=="add")
                        {
                            echo ' <img src="../img/raz.png" id="razdatefin" border="0" align="absmiddle">';
                            echo ' <img src="../img/oblig.png" align="absmiddle" alt="'._("Champ obligatoire").'">';
                        }
                        ?>
                    </td>
                    <td align="right">
                        <?PHP
                        echo "<span class=\"annot_petit_gras\">";
                        echo _("Devise d'origine") . ' : ';
                        echo give_dev_nom($dos_codeadev, TRUE) . " (" . $dos_codeadev . ")";
                        echo "</span>";
                        ?>
                    </td>
                </tr>
            </table>

            <!-- Code du dossier (affiché uniquement si édition ou suppression) -->
            <?PHP if ($td <> "add") { ?>
                <table width="100%" border="0">
                    <tr>
                        <td width="160" class="rubfrm" id="f_code" align="right"><?PHP echo _("Code"); ?></td>
                        <td>
                            <input name="code" type="text" id="code" value="<?PHP echo $dos_code ?>" size="20" maxlength="20" readonly>
                        </td>
                    </tr>
                </table>
            <?PHP } ?>

            <!-- Affichage du client -->
            <table width="100%" border="0">
                <tr>
                    <td class="rubfrm" id="f_codecli" align="center">
                        <?PHP
                        echo _("Client");
                        if ((@$_SESSION["niv_log"] == 5) OR (@$_SESSION["niv_log"] == 9) OR (@$_SESSION["niv_log"] == 4) OR (@$_SESSION["niv_log"] == 3))
                            echo " <img src=\"../img/" . $ico_cpta[$cli_cpta] . "\" title =\"" . $mess_cpta[$cli_cpta] . "\" border=\"0\" align=\"absmiddle\">";
                        ?>
                    </td>
                </tr>
            </table>

            <!-- détails client -->
            <table width="100%" border="0">
                <tr>
                    <td valign="top" bgcolor="#C5CED7">
                        <?PHP
                        echo "<span class=\"annot_std_gras\">";
                        if ($cli_ste <> "")
                            echo $cli_ste . "<br />";
                        else
                            echo $cli_civilite . " " . $cli_prenom . " " . $cli_nom . "<br />";
                        echo "</span>";
                        echo $cli_adr1 . "<br />";
                        if ($cli_adr2 <> "")
                            echo $cli_adr2 . "<br />";
                        echo Retournecp_Id($cli_ville, TRUE) . " " . Retourneville_Id($cli_ville, TRUE) . "<br />";
                        $chemin_imagesco = $chemin_images . "/telc.png";
                        echo "<img src=\"" . $chemin_imagesco . "\" align=\"bottom\">";
                        echo " " . $cli_telf . "<br />";
                        ?>
                    <td width="60" valign="top">
                        <?PHP
                        if (@$_SESSION["niv_log"] >= 3) {
                            $url_affnotesc = "aff_notesc.php?cc=" . $cc;
                            cre_falselnk('', 'aff_notesc', 'span', '', _("Notes"), $url_affnotesc, '../img/eye.png', _("Notes"));
                        } else
                            echo "&nbsp;";
                        ?>
                    </td>
                </tr>
            </table>

            <!-- Code de l'agence (choisi uniquement si création, affiché uniquement si édition ou suppression) -->
            <table width="100%" border="0">
                <tr>
                    <td width="160" class="rubfrm" id="f_agence" align="right"><?PHP echo _("Agence"); ?></td>
                    <td>
                        <?PHP
                        $tab_age = give_tab_age_cli($cli_code);
                        cre_select('codeage', 'codeage', $tab_age, $dos_codeage, '', _("-- Faites votre choix --"), 1, FALSE, '', _("-- Pas d'agence --"));
                        ?>
                    </td>
                </tr>
            </table>

            <!-- Paramètres du dossier -->
            <table width="100%" border="0">
                <tr>
                    <td width="160" class="rubfrm" id="f_cat" align="right"><?PHP echo _("Catégorie"); ?></td>
                    <td>
                        <?PHP
                        // création de la liste des Catégories
                        $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
                        $rech = "SELECT * FROM `" . TBDOSC . "` ORDER BY dosc_desc";
                        $rows = $db->get_results($rech, ARRAY_A);
                        $db->disconnect();
                        cre_select_tab('codecat', 'codecat', $rows, 'dosc_code', 'dosc_desc', '', $dos_codedosc, '', _("-- Faites votre choix --"));
                        ?>
                    </td>
                </tr>
                <tr>
                    <td width="160" class="rubfrm" id="f_statut" align="right"><?PHP echo _("Statut"); ?></td>
                    <td>
                        <?PHP
                        // création de la liste des Statuts
                        $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
                        $rech = "SELECT * FROM `" . TBDOSS . "` ORDER BY doss_desc";
                        $rows = $db->get_results($rech, ARRAY_A);
                        $db->disconnect();
                        cre_select_tab('codestatut', 'codestatut', $rows, 'doss_code', 'doss_desc', '', $dos_codedoss, '', _("-- Faites votre choix --"));
                        ?>
                    </td>
                </tr>
                <tr>
                    <td class="rubfrm" id="f_urg" align="right"><?PHP echo _("Niveau d'urgence"); ?></td>
                    <td>
                        <?PHP
                        // création de la liste des Niveaux d'urgence
                        $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
                        $rech = "SELECT * FROM `" . TBURG . "` ORDER BY urg_niveau";
                        $rows = $db->get_results($rech, ARRAY_A);
                        $db->disconnect();
                        cre_select_tab('urgence', 'urgence', $rows, 'urg_niveau', 'urg_des', '', $dos_urg, '', _("-- Faites votre choix --"));
                        ?>
                    </td>
                </tr>
                <tr>
                    <td class="rubfrm" id="f_proba" align="right"><?PHP echo _("Probabilité"); ?></td>
                    <td>
                        <?PHP
                        $tab_niveaux = [];
                        // création des niveaux
                        for ($i = 0; $i < 110; $i += 10) {
                            $tab_niveaux[$i] = $i . '%';
                        }
                        cre_select('proba', 'proba', $tab_niveaux, intval($dos_proba), '', _("-- Faites votre choix --"));
                        echo ' <span id="nivproba"></span>';
                        echo ' <div class="annot_petit_it">('._("Pourcentage de chances d'aboutir pour ce dossier").')</div>';
                        ?>
                    </td>
                </tr>
                <?PHP if ($td <> "add") { ?>
                    <tr>
                        <td class="rubfrm" id="f_ave" align="right"><?PHP echo _("Etat avancement"); ?></td>
                        <td>
                            <?PHP
                            cre_select('ave', 'ave', $tab_niveaux, intval($dos_avance), '', _("-- Faites votre choix --"));
                            echo ' <span id="nivave"></span>';
                            echo '<div class="annot_petit_it">(' . _("Niveau d'avancement du dossier") . ')</div>';
                            ?>
                        </td>
                    </tr>
                <?PHP } ?>
            </table>

            <!-- Titre et résumé du dossier -->
            <table width="100%" border="0">
                <tr>
                    <td width="160" class="rubfrm" id="f_titred" align="right"><?PHP echo _("Titre"); ?></td>
                    <td>
                        <input name="titred" type="text" id="titred" value="<?PHP echo $dos_titre ?>" size="50">
                        <img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo _("Champ obligatoire"); ?>">
                    </td>
                </tr>
                <tr>
                    <td width="160" class="rubfrm" id="f_resum" align="right"><?PHP echo _("Résumé"); ?></td>
                    <td>
                        <textarea name="resum" rows="5" id="resum" style="width:95%;"><?PHP echo $dos_res; ?></textarea>
                        <img src="../img/oblig.png" align="top" alt="<?PHP echo _("Champ obligatoire"); ?>">
                    </td>
                </tr>
            </table>

            <?PHP if ($td <> "add") { ?>
                <!-- Technicien Responsable -->
                <table width="100%" border="0">
                    <tr>
                        <td width="160" class="rubfrm" id="f_codesuiv"
                            align="right"><?PHP echo _("Responsable dossier"); ?></td>
                        <td>
                            <?PHP
                            $tab_cage = give_tab_cage($dos_codeage);
                            $tab_first_options = [
                                "-1" => _("-- Dossier non affecté --")
                            ];
                            $tab_cage = $tab_first_options + $tab_cage;
                            cre_select('codesuiv', 'codesuiv', $tab_cage, intval($dos_codesuiv), '', _("-- Faites votre choix --"));
                            ?>
                        </td>
                    </tr>
                </table>

                <!-- Date de clôture du dossier -->
                <table width="100%" border="0">
                    <tr>
                        <td width="160" class="rubfrm" id="f_datefinf"
                            align="right"><?PHP echo _("Dossier clôt le"); ?></td>
                        <td>
                            <table width="100%" border="0">
                                <tr>
                                    <td>
                                        <input name="datefinf" type="text" id="datefinf" value="<?PHP echo $dos_datefinf ?>" size="10" readonly>
                                        <?PHP
                                        if ($dos_cloture == true)
                                        {
                                            echo ' <img src="../img/raz.png" id="razdatefin" border="0" align="absmiddle">';
                                            echo ' <span class="annot_petit_it">('._("Si vous saisissez une date, le dossier sera clôt. Saisissez tous vos détails AVANT de clôre").')</span>;';
                                        }
                                        ?>
                                    </td>
                                    <td align="right" class="annot_petit_it">
                                        <?PHP if ((($td == "edit") OR ($td == "view")) AND ((@$_SESSION["niv_log"] == 4) OR (@$_SESSION["niv_log"] == 5) OR (@$_SESSION["niv_log"] == 9))) {
                                            echo _("Prix de revient (inclus actions non closes)") . ' : ';
                                            echo full_num_format($pxrevient, 'span', 'pxr', TRUE);
                                            echo _("HT");
                                        } else
                                            echo "&nbsp;";
                                        ?>
                                    </td>
                                </tr>
                            </table>
                        </td>
                    </tr>
                </table>
            <?PHP } ?> <!-- Fin de zone exclue si création -->
            <?PHP
            if (($td == "edit") OR ($td == "del") OR ($td == "view")) {
                ?>
                <table border="0" width="100%">
                    <tr>
                        <td class="rubfrm">
                            <div align="left"><?PHP echo _("Historique des actions effectuées"); ?></div>
                        </td>
                    </tr>
                </table>
                <div id="detdosd">
                </div>

                <!-- Lien d'ajout de détail-->
                <?PHP
                if ($td <> "del") {
                    if ($td == "edit") {
                        $urlchoixdosd = "dosd_maj.php?td=add&cd=" . $cd . "&nd=";

                        ?>
                        <table border="0" width="100%">
                            <tr>
                                <td width="50%">
                                    <?PHP
                                    if (exist_dosd_open_dos($cd, TRUE) == TRUE)
                                        echo '<span id="chxdetdosd" style="display:none;">';
                                    else
                                        echo '<span id="chxdetdosd" style="display:inline;">';
                                    cre_falselnk('', 'chx_dosd', 'span', '', _("Ajouter un détail"), $urlchoixdosd, '../img/add.png', _("Ajouter un détail"));
                                    echo '</span>';
                                    ?>
                                </td>
                                <td width="50%">&nbsp;

                                </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;
                    case "del" :
                        echo '<input name="del" type="submit" class="bton_std" id="del" value="'._("Supprimer").'">';
                        break;
                }
                ?>
            </p>
            </form>
            <!-- Fin affiché uniquement s'il y a un code client -->
        <?PHP
        } else
            pop_ret_auto(_("Merci de choisir un client"), 'warn', $lnk_cli_lst);
        ?>
        <!-- affiché uniquement s'il y a au moins un client, une agence active, une origine, un statut, un lieu, une civilité, un technicien dans l'agence, et un mode de règlement -->
    <?PHP
    } else {
        if (nb_cli("") == 0)
            pop_ret_auto(_("Aucun client"), 'warn',  $link_cli_lst);

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

        if (nb_dosc() == 0)
            pop_ret_auto(_("Aucune catégorie de dossier"), 'warn', 'dosc_lst.php');

        if (nb_doss() == 0)
            pop_ret_auto(_("Aucun statut de dossier"), 'warn', 'doss_lst.php');

        if (nb_tec("") == 0)
            pop_ret_auto( _("Aucun technicien"), 'warn', 'tec_lst.php?td=std&tl=1');
    }
} else {
    if ($pbm_dos == TRUE)
        pop_ret_auto(_("Merci de choisir un de vos dossiers"), 'warn', 'dos_lst.php?ord=DES&tri=Code');
    else {
        if ((@$_SESSION["niv_log"] == 4) OR (@$_SESSION["niv_log"] == 3))
            pop_ret_auto(_("Merci de choisir un de vos clients"), 'warn', $lnk_cli_lst);
    }
}
include_once("pied.php");
?>
</body>
</html>