<?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/fic_age.inc.php");
include_once("../inc/fic_cli.inc.php");
include_once("../inc/fic_co.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_prm.inc.php");
include_once("../inc/fic_rel.inc.php");
include_once("../inc/fic_taxes.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();
$_POST = clean_str($_POST);
$_GET = clean_str($_GET);

$nbcontrats = 0;
$exist_rlic_actif = FALSE;
$exist_rpdt_actif = FALSE;
$pbm_cocl = FALSE;
$pbm_cli = FALSE;
$preavis_mini = preavis_min();
$pv_ttc = 0;
$pxrevient = 0;
$tab_cli = [];
$str_rlp = '';
$_SESSION["scli_choisis"] = "";
$_SESSION["sclia_choisis"] = "";
$_SESSION["rlp_choisis"] = "";
$select_age = TRUE;

$td = '';
if (isset($_GET['td']))
    $td = $_GET['td']; // Récupération type demande
else
    $pbm_cocl = TRUE;

// Niveau <=3 ne peut que voir les contrats
if (@$_SESSION["niv_log"] <= 3)
    $td = "view";

$co = '';
if (isset($_GET['co']))
    $co = $_GET['co']; // Récupération code Contrat
else {
    if ($td <> "add")
        $pbm_cocl = TRUE;
}

$cc = '';
if (isset($_GET['cc']))
    $cc = $_GET['cc']; // Récupération code Client
else
    $pbm_cli = TRUE;

if (($pbm_cocl == FALSE) AND ($pbm_cli == FALSE))
    $codeadev = give_dev_codea_defaut($_SESSION["lng"], TRUE);

if ($cc <> "") {
    $row = lit_enr_cli($cc, TRUE);
    if (is_array($row)) {
        $row = encode_str($row);
        extract($row);

        // Contrôle qu'on n'essaye pas de "hacker" un client
        switch (@$_SESSION["niv_log"]) {
            case 1 :
                $tab_cli = give_tab_rcli($_SESSION["code_log"], TRUE);
                if (exist_in_array($cc, $tab_cli) == FALSE)
                    $pbm_cli = TRUE;
                $select_age = FALSE;
                break;
            case 3 :
            case 4 :
                if (client_age_ok($cli_code, @$_SESSION["code_age"], TRUE) == FALSE)
                    $pbm_cli = TRUE;
                // On force l'agence
                $select_age = FALSE;
                $cocl_codeage = @$_SESSION["code_age"];
                break;
            default :
                // Si agence propriétaire, on ne peut pas choisir l'agence
                if (trim($cli_prop) <> NULL) {
                    $select_age = FALSE;
                    $cocl_codeage = $cli_prop;
                }
                break;
        }
    } else
        $pbm_cli = TRUE;
} else
    $pbm_cli = TRUE;


if (($pbm_cocl == FALSE) AND ($pbm_cli == FALSE)) {
    if ($co <> "") {
        // Récupération des informations contrat client
        $row = lit_enr_cocl($co);
        if (is_array($row)) {
            $row = encode_str($row);
            extract($row);
            if ($cocl_codecli <> $cc)
                $pbm_cocl = TRUE;

            if ($pbm_cocl == FALSE)
            {
                // Si contrat terminé ou signé, force le mode "view"
                if ((datetolocal($cocl_datefin) <> '') OR ($cocl_signe <> ''))
                    $td = "view";

                if ($td <> "add") {
                    // Contrôle qu'on n'essaye pas de "hacker" un contrat
                    switch (@$_SESSION["niv_log"]) {
                        case 1 :
                            if ($cocl_codecli <> $_SESSION["code_log"])
                                $pbm_cocl = TRUE;
                            break;
                        case 3 :
                            if ($cocl_codeage <> $_SESSION["code_age"])
                                $pbm_cocl = TRUE;
                            break;
                        case 4 :
                            if ($cocl_codeage <> $_SESSION["code_log"])
                                $pbm_cocl = TRUE;
                            break;
                        default :
                            break;
                    }
                }

                if ($pbm_cocl == FALSE)
                {
                    if (trim($cocl_codeadev) == '')
                        $cocl_codeadev = give_dev_codea_defaut_cocl($cocl_code, $_SESSION["lng"]);

                    // Récupération des informations TVA
                    $row = lit_enr_tva($cocl_codetva, TRUE);
                    if (is_array($row)) {
                        $row = encode_str($row);
                        extract($row);
                    }

                    $txtva = $tva_tx / 100;
                    $pvttc = round(($cocl_pvht * (1 + $txtva)) * 100) / 100;

                    // Calcul du prix de revient du contrat
                    $pxrevient = px_revient_cocl($co, TRUE);

                    // Construction de la chaîne des sites sélectionnés pour le contrat (hors annexes)
                    $lstsites = cree_str_lstsites_cocl($co, FALSE);
                    $_SESSION["scli_choisis"] = $lstsites;

                    // Construction de la chaîne des sites sélectionnés sur TOUTES les annexes
                    $lstsites_annexes = cree_str_lstsites_cocla($co,0);
                    $_SESSION["sclia_choisis"] = $lstsites_annexes;

                    // Si aucun site secondaire choisi, on force le site principal
                    if ((trim($_SESSION["scli_choisis"]) == '') AND trim($_SESSION["sclia_choisis"]) == '')
                        $cocl_sitep = 1;

                    // Construction de la liste et du texte des produits sur relevés
                    $_SESSION["rlp_choisis"] = $cocl_coderlp;
                    if ($cocl_coderlp <> "")
                        $str_rlp = cree_txt_matos_cocl($cocl_coderlp);

                    // vérification qu'il existe bien des contrats et nombre de ceux-ci
                    $nbcontrats = nb_cocl_in_cli($cocl_codecli);

                    $cocl_datecreaf = datetolocal($cocl_datecrea);
                    $cocl_datemodf = datetolocal($cocl_datemod);
                    $cocl_dateenvf = datetolocal($cocl_dateenv);
                    $cocl_daterecf = datetolocal($cocl_daterec);
                    $cocl_datesigf = datetolocal($cocl_datesig);
                    $cocl_datedf = datetolocal($cocl_dated);
                    $cocl_dateff = datetolocal($cocl_datef);
                    $cocl_daterelf = datetolocal($cocl_daterel);
                    $cocl_datefinf = datetolocal($cocl_datefin);
                }
            }
        } else
            $pbm_cocl = TRUE;
    } else {
        if ($td == "add") {
            $cocl_datecreaf = $datef;
            $cocl_dateenvf = $datef;
            $cocl_code = crecodesession("CO");
            $cocl_daterecf = $datef;
            $co = '';
            $cocl_nbs = 3600; // 1 heure...en secondes
            $cocl_nbsnc = 0;
            $cocl_renauto = 1;
            $cocl_preavis = preavis_max();
            $cocl_datedf = $datef;
            $cocl_renouv = 0;
            $cocl_sitep = 1;
            $cocl_codecli = $cc;
            $cocl_codeadev = give_dev_codea_defaut_cli($cocl_codecli, $_SESSION["lng"]);
        } else
            $pbm_cocl = TRUE;
    }
}
// Vérification du nombre de licences et matériels actifs pour les sites sélectionnés
$exist_rlic_actif = exist_rlic_actif($cocl_codecli, $_SESSION["scli_choisis"], $cocl_sitep);
$exist_rpdt_actif = exist_rpdt_actif($cocl_codecli, $_SESSION["scli_choisis"], $cocl_sitep);

$ca = @$_GET['ca']; // Récupération code Agence

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

if (($pbm_cli == FALSE) AND ($pbm_cocl == FALSE)) {
    $nbh = heure_to_hhmm(sec_heure($cocl_nbs, 3, TRUE));
    $soldes = solde_contrat_sec($co, TRUE);
    $soldeh = heure_to_hhmm(sec_heure(solde_contrat_sec($co, TRUE), 3, TRUE));
    // Si le délai d'intervention est nul on n'affiche rien
    if ($cocl_delai == 0)
        $cocl_delai = "";
}

switch ($td) {
    case "add" :
        $titre = _("CREATION CONTRAT CLIENT");
        $cocl_codetva = give_code_tva_default(TRUE);
        break;
    case "edit" :
        $titre = _("MISE A JOUR CONTRAT CLIENT");
        break;
    case "del" :
        $titre = _("SUPPRESSION CONTRAT CLIENT");
        break;
    case "view" :
        if (@$_SESSION["niv_log"] == 1)
            $titre = _("VISUALISATION CONTRAT");
        else
            $titre = _("VISUALISATION CONTRAT CLIENT");
        break;
    default :
        $pbm_cocl = 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 _("Fiche Contrat Client"); ?></title>

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

<script language="javascript">
    var tab1_champ = ["nom:datecreaf ; format:date ; masque:<?PHP echo $_SESSION['date_fmtfull']; ?> ; req:Y ; txt:<?PHP echo _("Date création"); ?> ; stok:frmok ; stbad:frmbad",
        "nom:codeage ; format:liste ; req:Y ; txt:<?PHP echo _("Agence"); ?> ; vmn:1 ; stok:frmok ; stbad:frmbad",
        "nom:co ; format:liste ; req:Y ; txt:<?PHP echo _("Contrat type"); ?> ; vmn:1 ; stok:frmok ; stbad:frmbad",
        "nom:cope ; format:liste ; req:Y ; txt:<?PHP echo _("Fréquence"); ?> ; vmn:1 ; stok:frmok ; stbad:frmbad",
        "nom:delai ; format:unsigned ; req:N ; txt:<?PHP echo _("Délai intervention"); ?> ; lmx:2 ; stok:frmok ; stbad:frmbad",
        "nom:nbh ; format:dureehhmm ; req:Y ; txt:<?PHP echo _("Nombre d'heures"); ?> ; stok:frmok ; stbad:frmbad",
        "nom:datedf ; format:date ; masque:<?PHP echo $_SESSION['date_fmtfull']; ?> ; req:Y ; txt:<?PHP echo _("Date début"); ?>  ; stok:frmok ; stbad:frmbad",
        "nom:dateff ; format:date ; masque:<?PHP echo $_SESSION['date_fmtfull']; ?> ; req:N ; txt:<?PHP echo _("Date fin"); ?>  ; stok:frmok ; stbad:frmbad",
        "nom:preavis ; format:unsigned ; req:Y ; txt:<?PHP echo _("Préavis"); ?> ; lmx:3; stok:frmok ; stbad:frmbad",
        "nom:matos ; format:txt ; req:N ; txt:<?PHP echo _("matériel"); ?>; stok:frmok ; stbad:frmbad",
        "nom:pu ; format:reel_ns ; req:Y ; txt:<?PHP echo _("Prix de vente hors taxes"); ?> ; lmx:10 ; stok:frmok ; stbad:frmbad",
        "nom:puttc ; format:reel_ns ; req:Y ; txt:<?PHP echo _("Prix de vente TTC"); ?> ; lmx:10 ; stok:frmok ; stbad:frmbad",
    <?PHP
        if ($td == "edit")
        {
            echo '"nom:datesig ; format:date ; masque jj-mm-aaa ; req:N ; txt:'._("signé le").' ; stok:frmok ; stbad:frmbad",';
            echo '"nom:signe ; format:txt ; req:N ; txt:'._("signé par").' ; lmx:70 ; stok:frmok ; stbad:frmbad",';
        }
    ?>
    "nom:tva; format:liste ; req:Y ; txt:<?PHP echo _("TVA"); ?> ; vmn:1 ; stok:frmok ; stbad:frmbad"];
</script>

<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"); ?>"
        });
        $("#datedf").datepicker({
            onSelect: function (datesel) {
                $("#datedf").blur();
                return chk_datedif(datesel, this.id, '<?PHP echo $_SESSION['date_fmtshort']; ?>', true, '', '', 'dateff',false);
            }
        });
        $("#dateff").datepicker({
            onSelect: function (datesel) {
                $("#dateff").blur();
                return chk_datedif(datesel, this.id, '<?PHP echo $_SESSION['date_fmtshort']; ?>', true, 'datedf', '', '',false);
            }
        });
    }

    function init_all() {
        init_Body();
        init_datepicker();
        init_autohref('tac', 'change','',false);
        init_fdeci('pu', <?PHP echo $_SESSION['num_nbdec']; ?>);
        init_calc_taxe('pu', 'pu', 'puttc', 'tva', <?PHP echo $_SESSION['num_nbdec']; ?>, 'to_ttc');
        init_fdeci('puttc', <?PHP echo $_SESSION['num_nbdec']; ?>);
        init_calc_taxe('puttc', 'pu', 'puttc', 'tva', <?PHP echo $_SESSION['num_nbdec']; ?>, 'to_ht');
        init_calc_taxe('tva', 'pu', 'puttc', 'tva', <?PHP echo $_SESSION['num_nbdec']; ?>, 'to_ttc');
        init_chk_delai('cope', 'delai');
        init_autoraz('razdatescocl', 'datedf', 'click');
        init_autoraz('razdatescocl', 'dateff', 'click');
        <?php
        $url_choixsites = "sites_lst.php?tx=co&cc=".$cc."&co=".$cocl_code."&td=".$td;
        switch ($td)
        {
            case "add" :
                echo '$( "#datecreaf" ).datepicker();';
                echo 'warn_cpta('.$cli_cpta.',"cocl");';
                echo "init_warn('".nb_age_actives()."age','','back','','');";
                echo "init_valid_cocl('enr','cocl_maj','".$_SESSION['date_fmtshort']."',tab1_champ,'','');";
                echo "init_valid_cocl('enrimp','cocl_maj','".$_SESSION['date_fmtshort']."',tab1_champ,'','');";
                echo "init_fen_mat('addmat','fscomp',1024,600);";
                echo "chk_disp_addmat(false,'addmat','".(int)$exist_rlic_actif."','".(int)$exist_rpdt_actif."');";
                echo "init_display_id('viewmat','popmatselected',true,'click');";
                echo "init_hide_id('closemat','popmatselected','click');";
                if ($select_age == FALSE)
                    echo "readonly_id('codeage',false);";
                echo "update_detail_rlp(false,'detailmat','".str_replace("'","\'",$str_rlp)."','viewmat');";
                break;
            case "edit" :
                echo 'warn_cpta('.$cli_cpta.',"cocl");';
                echo "init_fensaisie('histo_cocl',900,560);";
                echo "init_fensaisie('det_cocl',800,300);";
                echo "init_new_fen('etats','impression');";
                echo "init_valid_cocl('enr','cocl_maj','".$_SESSION['date_fmtshort']."',tab1_champ,'','');";
                echo "init_valid_cocl('enrimp','cocl_maj','".$_SESSION['date_fmtshort']."',tab1_champ,'','');";
                echo "init_fen_mat('addmat','fscomp',1024,600);";
                echo "chk_disp_addmat(false,'addmat','".(int)$exist_rlic_actif."','".(int)$exist_rpdt_actif."');";
                echo "init_display_id('viewmat','popmatselected',true,'click');";
                echo "init_hide_id('closemat','popmatselected','click');";
                echo "update_detail_rlp(false,'detailmat','".str_replace("'","\'",$str_rlp)."','viewmat');";
                echo "readonly_id('codeage',false);";
                break;
            case "del" :
                echo "readonly_all();";
                echo "warn_del('');";
                break;
            case "view" :
                if (@$_SESSION["niv_log"] >= 3)
                {
                    echo 'warn_cpta('.$cli_cpta.',"cocl");';
                    echo "init_fensaisie('det_cocl',800,300);";
                }
                echo "init_fensaisie('histo_cocl',900,560);";
                echo "init_new_fen('etats','impression');";
                echo "init_display_id('viewmat','popmatselected',true,'click');";
                echo "update_detail_rlp(false,'detailmat','".str_replace("'","\'",$str_rlp)."','viewmat');";
                echo "init_hide_id('closemat','popmatselected','click');";
                echo "readonly_all();";
                echo "$('#etats').attr('disabled', false);";
                break;
        }
        if (@$_SESSION["niv_log"] >= 3)
            echo "init_fensaisie('notes_cli',930,380);";
        ?>
        init_autohref('add_int', 'click', '', true);
        init_autohref('add_cocla', 'click', '', true);
        init_autohref('lst_cocla', 'click', '', true);
        init_fensaisie('sites_cocl', 920, 500);
        Focus_first();
    }

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

</head>

<body>

<?PHP
include_once("../inc/entete.inc.php");
?>
<p align="center"><span class="titrepage"><?PHP echo $titre ?></span></p>
<!-- affiché uniquement s'il y a un code client -->
<?PHP
if (($pbm_cocl == FALSE) AND ($pbm_cli == FALSE)) {
        ?>
        <table width="100%" border="0">
            <tr>
                <td width="33%"
                    class="annot_gras_it"><?PHP aff_lnk_lst_rech('cocl_lst.php?ord=DES&tri=Code', _("Retour à la liste"), $_SERVER['HTTP_REFERER'], _("Retour à la page précédente")); ?></td>
                <td width="33%" align="center" class="annot_petit_it">
                    <div id="oblig">(<img src="../img/oblig.png" align="absmiddle"
                                          alt="<?PHP echo _("Champ obligatoire"); ?>">
                        : <?PHP echo _("Saisie obligatoire"); ?>)
                    </div>
                </td>
                <td width="33%" align="right">&nbsp;</td>
            </tr>
            <tr>
                <td width="33%">
                    <?PHP
                    if (($td == "edit") OR ($td == "view")) {
                        $url_coclh = "coclhd_lst.php?or=con&cc=" . $cocl_codecli . "&search=" . $cocl_code;

                        if (url_ok($url_coclh, TRUE) == TRUE)
                            cre_falselnk('', 'histo_cocl', 'span', '', _("Historique contrat"), $url_coclh, '../img/hcon.png', _("Historique contrat"));
                    } else
                        echo "&nbsp;";
                    ?>
                </td>
                <td width="33%" align="center" valign="top">
                    <?PHP
                    if ((datetolocal($cocl_datesig) <> "") AND (datetolocal($cocl_datefin) == "")) {
                        if (($td == "edit") OR ($td == "view")) {
                            $nbcocla = nb_cocla_cocl($cocl_code, TRUE);
                            if ($td == "edit") {
                                if (url_ok('cocla_maj.php?td=add&co=' . $cocl_code . '&coa=', TRUE) == TRUE)
                                    echo ' <a href="cocla_maj.php?td=add&co=' . $cocl_code . '&coa="><img src="../img/annexe_add.png" border="0" align="absmiddle" title="' . _("Ajouter annexes") . '"> ' . _("Ajouter annexes") . '</a>';
                                if ($nbcocla > 0) echo "/";
                            }
                            if ($nbcocla > 0) {
                                if (url_ok('cocla_lst.php?co=' . $cocl_code, TRUE) == TRUE)
                                    echo ' <a href="cocla_lst.php?co=' . $cocl_code . '"><img src="../img/annexe_lst.png" border="0" align="absmiddle" title="' . _("Voir annexes") . '"> ' . _("Voir annexes") . '</a>';
                            }
                        } else
                            echo "&nbsp;";
                    } else
                        echo "&nbsp;";
                    ?>
                </td>
                <td width="33%" align="right">
                    <?PHP
                    if (($td == "edit") OR ($td == "view")) {
                        echo '<select name="etats" size="1" id="etats" class="annot_petit">';
                        echo '<option value="" selected>&#187; '._("Etats").' &#171;</option>';
                        if (@$_SESSION["niv_log"] <> 2) {
                            $urlimp = "cocl_pdf.php?code=" . $co;
                            if (url_ok($urlimp, TRUE) == TRUE)
                                echo "<option value=\"" . $urlimp . "\"  class=\"icone\" style=\"background-image: url(../img/sel_con.gif);\">" . _("Contrat") . "</option>";

                            $urlhisto = "cocls_pdf.php?co=" . $co;
                            if (url_ok($urlhisto, TRUE) == TRUE)
                                echo "<option value=\"" . $urlhisto . "\"  class=\"icone\" style=\"background-image: url(../img/sel_cons.gif);\">" . _("Synthèse") . "</option>";
                        }
                        echo '</select>';
                    } else
                        echo '&nbsp;';
                    ?>
                </td>
            </tr>
        </table>

        <form name="cocl_maj" id="cocl_maj" method="post" action="cocl_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="tx" type="hidden" id="tx" value="co">
        <input name="codecli" type="hidden" id="codecli" value="<?PHP echo $cc; ?>">
        <input name="prev" type="hidden" id="prev" value="<?PHP echo $cli_prev ?>">
        <input name="codeadev" type="hidden" id="codeadev" value="<?PHP echo $cocl_codeadev; ?>" readonly>
        <input name="nbutton" type="hidden" id="nbutton" value="">
        <?PHP if ($td == "add") { ?>
            <input name="code" type="hidden" id="code" value="<?PHP echo $cocl_code ?>">
            <input name="renouv" type="hidden" id="renouv" value="<?PHP echo $cocl_renouv ?>">
            <input name="num" type="hidden" id="num" value="">
            <input name="datefinf" type="hidden" id="datefinf" value="">
        <?PHP } ?>

        <!-- détails internes de la fiche contrat -->
        <table width="100%" border="0">
            <tr>
                <td width="33%">
                    <?PHP if ((($td == "edit") OR ($td == "view")) AND (@$_SESSION["niv_log"] >= 3)) {
                        $url_detcocl = "cocld_maj.php?co=" . $co;
                        if (url_ok($url_detcocl, TRUE) == TRUE)
                            cre_falselnk('', 'det_cocl', 'span', '', _("Détails"), $url_detcocl, '../img/eye.png', _("Détails"));
                    } else
                        echo '&nbsp;';
                    ?>
                </td>
                <td width="33%" valign="top">&nbsp;</td>
                <td width="33%">
                    <?PHP
                    $echeance_ok = TRUE;
                    if ($cocl_dateff <> "") {
                        if (echeance_depassee_date($datea, $cocl_datef) == TRUE)
                            $echeance_ok = FALSE;
                    }
                    if ((($td == "edit") OR ($td == "view")) AND ($cocl_datefinf == "") AND ($cocl_datesigf <> "") AND ($echeance_ok == TRUE) AND (@$_SESSION["niv_log"] >= 3)) {
                        echo '<div align="right">';
                        $url_int = "int_maj.php?td=add&ci=&cc=" . $cc . "&ca=" . $ca . "&co=" . $co;
                        if (url_ok($url_int) == TRUE)
                            cre_falselnk('', 'add_int', 'span', '', _("Saisir intervention"), $url_int, '../img/int.png', _("Saisir intervention"));
                        $url_addcocla = 'cocla_maj.php?td=add&co=' . $co . '&coa=';
                        if (url_ok($url_addcocla) == TRUE) {
                            echo ' / ';
                            cre_falselnk('', 'add_cocla', 'span', '', _("Ajouter annexe"), $url_addcocla, '../img/annexe_add.png', _("Ajouter annexe"));
                        }
                        if (nb_cocla_cocl($co) > 0) {
                            $url_lstcocla = 'cocla_lst.php?co=' . $co;
                            if (url_ok($url_lstcocla) == TRUE) {
                                echo ' / ';
                                cre_falselnk('', 'lst_cocla', 'span', '', _("Voir annexes"), $url_lstcocla, '../img/annexe_lst.png', _("Voir annexes"));
                            }
                        }
                        echo '</div>';
                    } else
                        echo '&nbsp;';
                    ?>
                </td>
            </tr>
        </table>

        <!-- Date de création -->
        <table width="100%" border="0">
            <tr>
                <td width="250" class="rubfrm" id="f_datecreaf" align="right"><?PHP echo _("Date Création"); ?> </td>
                <td>
                    <input name="datecreaf" type="text" id="datecreaf" value="<?PHP echo $cocl_datecreaf ?>" size="10"
                           maxlength="10" readonly>
                </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(2, $cocl_code, TRUE);
                        if ($nb_tac > 0) {
                            echo "<span class=\"annot_petit_it\">";
                            if ($nb_tac == 1)
                                echo "( " . $nb_tac . " " . _("tâche");
                            else
                                echo "( " . $nb_tac . " " . _("tâches");
                            $nb_tac_actives = nb_tac_actives(2, $cocl_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=4&search=' . $cocl_code;
                            if (url_ok($url, TRUE) == TRUE)
                                $tab_tac[$url] = _("Voir");
                        }
                        $url = 'tac_maj.php?td=add&tr=2&cr=' . $cocl_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>

        <!-- Code du contrat client (affiché uniquement si édition ou suppression) -->
        <?PHP if ($td <> "add") { ?>
            <table width="100%" border="0">
                <tr>
                    <td width="250" class="rubfrm" id="f_codecocl" align="right"><?PHP echo _("Code"); ?></td>
                    <td>
                        <input name="code" type="text" id="code" value="<?PHP echo $cocl_code ?>" size="20"
                               maxlength="20" readonly>
                        <?PHP
                        $echeance_ok = TRUE;
                        if ($cocl_dateff <> "") {
                            if (echeance_depassee_date($datea, $cocl_datef) == TRUE)
                                $echeance_ok = FALSE;
                        }
                        if (($cocl_datesigf == "") OR ($cocl_datefinf <> "") OR ($echeance_ok == FALSE)) {
                            if ($cocl_datesigf == "") {
                                echo '<span class="alerte1">';
                                echo _("Non signé");
                                echo '</span>';
                            }
                            if (($cocl_datefinf <> "") OR ($echeance_ok == FALSE)) {
                                if ($cocl_datesigf == "") {
                                    echo "<strong><em>";
                                    echo " / ";
                                    echo "</strong></em>";
                                }
                                echo '<span class="alerte1">';
                                echo _("Terminé");
                                echo '</span>';
                            }
                        }
                        ?>
                    </td>
                </tr>
            </table>
        <?PHP } ?>

        <!-- Affichage du client -->
        <table width="100%" border="0">
            <tr>
                <td class="rubfrm" id="f_codecli" align="center"><?PHP echo _("Client"); ?>
                    <?PHP
                    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>
                <td width="280" valign="top">
                    <?PHP
                    if (@$_SESSION["niv_log"] >= 3) {
                        $url_affnotesc = "aff_notesc.php?cc=" . $cc;
                        if (url_ok($url_affnotesc, TRUE) == TRUE)
                            cre_falselnk('', 'notes_cli', 'span', '', _("Notes"), $url_affnotesc, '../img/eye.png', _("Notes"));
                    }
                    echo '<input name="sitep" type="hidden" id="sitep" value="' . $cocl_sitep . '">';
                    echo '<input name="sitesec" type="hidden" id="sitesec" value="' . $_SESSION["scli_choisis"] . '">';
                    if (url_ok($url_choixsites, TRUE) == TRUE)
                        cre_falselnk('', 'sites_cocl', 'div', '', _("Sites couverts"), $url_choixsites, '../img/sites.png', _("Sites couverts"));
                    ?>
                </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="250" 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, $cocl_codeage, '', _("-- Faites votre choix --"), 1, FALSE, '', _("-- Pas d'agence --"));
                    ?>
                </td>
            </tr>
        </table>

        <!-- Type de contrat -->
        <table width="100%" border="0">
            <tr>
                <td width="250" class="rubfrm" id="f_co" align="right"><?PHP echo _("Contrat Type"); ?></td>
                <td>
                    <?PHP
                    // Création de la liste des types de contrats actifs
                    $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
                    $rech = "SELECT * FROM `" . TBCO . "`  WHERE co_actif = '1' ORDER BY co_nom";
                    $rows = $db->get_results($rech, ARRAY_A);
                    $db->disconnect();
                    cre_select_tab('co', 'co', $rows, 'co_code', 'co_nom', '', $cocl_codeco, '', _("-- Faites votre choix --"), 1, FALSE, '', _("-- Pas de contrat type actif --"));
                    ?>
                </td>
            </tr>
        </table>

        <!-- périodicité du contrat -->
        <table width="100%" border="0">
            <tr>
                <td width="250" class="rubfrm" id="f_cope" align="right"><?PHP echo _("Fréquence"); ?></td>
                <td>
                    <?PHP
                    $tab_cope = [];

                    // Création de la liste des types des périodicités
                    // et des champs cachés de périodicité (pour connaitre le délai)
                    $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
                    $rech = "SELECT * FROM `" . TBPER . "` ORDER BY per_nbj";
                    $rows = $db->get_results($rech, ARRAY_A);
                    if (($rows) AND (count($rows) > 0)) {
                        foreach ($rows as $row) {
                            $row = encode_str($row);
                            extract($row);
                            if ($per_nbj <> 0)
                                $txt_nbj = " (" . _("tous les") . " " . $per_nbj . " " . _("jours") . ")";
                            else
                                $txt_nbj = " (" . _("à la demande") . ")";

                            $tab_cope[$per_code] = $per_desc . $txt_nbj;
                            echo '<input name="_' . $per_code . '" type="hidden" id="_' . $per_code . '" value="' . $per_nbj . '">';
                        }
                    }
                    $db->disconnect();
                    cre_select('cope', 'cope', $tab_cope, $cocl_codeper, '0', _("-- Faites votre choix --"), 1, FALSE, '', _("-- Pas de fréquence à choisir --"));
                    ?>
                </td>
            </tr>
        </table>

        <!-- Délai d'intervention -->
        <table width="100%" border="0">
            <tr>
                <td width="250" class="rubfrm" id="f_delai" align="right"><?PHP echo _("Délai Interv."); ?></td>
                <td>
                    <input name="delai" type="text" id="delai" value="<?PHP echo $cocl_delai ?>" size="2" maxlength="2"
                           align="right">
                    <span
                        class="annot_petit_it"><?PHP echo _("heures ouvrées(obligatoire seulement si à la demande)"); ?></span>
                </td>
            </tr>
        </table>

        <!-- Nombre d'heures par contrat -->
        <table width="100%" border="0">
            <tr>
                <td width="250" class="rubfrm" id="f_nbheures" align="right"><?PHP echo _("Nb heures"); ?></td>
                <td>
                    <?PHP
                    $tab_heures = [];
                    // création de la liste des heures
                    for ($i = 0; $i < 3600000; $i += 900) {
                        $heure = heure_to_hhmm(sec_heure($i, 3, TRUE));
                        $tab_heures[$heure] = $heure;
                    }
                    cre_select('nbh', 'nbh', $tab_heures, $nbh);
                    echo ' ';
                    cre_select('typh', 'typh', $typ_horaire, intval($cocl_typh));

                    if ((($td == "edit") OR ($td == "del") OR ($td == "view")) AND ($cocl_typh == 1)) {
                        ?>
                        <br />
                        <span class="annot_std_it"><?PHP echo _("Solde"); ?> :</span>
                        <input name="soldeh" type="text" id="soldeh" value="<?PHP echo $soldeh ?>" size="6"
                               maxlength="6" readonly>
                        <span class="annot_petit_it">(<?PHP echo _("Heures à sortir"); ?>
                            : <?PHP echo heure_to_hhmm(sec_heure(tps_trav_non_clot_sec($cocl_code, TRUE), 3, TRUE)); ?>
                            . <?PHP echo _("Voir historique"); ?>)</span>
                    <?PHP
                    }
                    ?>
                </td>
            </tr>
            <tr>
                <td width="250" class="rubfrm" id="f_nbsnc"
                    align="right"><?PHP echo _("Report heures non consommées ?"); ?></td>
                <td>
                    <?PHP
                    cre_select('nbsnc', 'nbsnc', $non_oui, (int)$cocl_nbsnc);
                    ?>
                    <br />
                    <span
                        class="annot_petit_it"><?PHP echo _("Si 'Oui' : à la clôture, si la date d'échéance est dépassée, les heures non consommées seront rajoutées sur un autre contrat. Paramètre pris en compte uniquement pour les 'Quotas Horaires'"); ?></span>
            </tr>
            <tr>
                <td width="250" class="rubfrm" id="f_nbsdep"
                    align="right"><?PHP echo _("Report heures dépassées ?"); ?></td>
                <td>
                    <?PHP
                    cre_select('nbsdep', 'nbsdep', $non_oui, (int)$cocl_nbsdep);
                    ?>
                    <br />
                    <span
                        class="annot_petit_it"><?PHP echo _("Si 'Oui' : à la clôture, les heures dépassant le quota seront déduites d'un autre contrat.  Paramètre pris en compte uniquement pour les 'Quotas Horaires'"); ?></span>
            </tr>
        </table>

        <!-- Dates de "vie" du contrat -->
        <table width="100%" border="0">
            <tr>
                <td width="250" class="rubfrm" id="f_validite" align="right"><?PHP echo _("Validité"); ?></td>
                <td>
                    <span class="annot_petit_gras"><?PHP echo _("Du"); ?></span>
                    <input name="datedf" type="text" id="datedf" value="<?PHP echo $cocl_datedf ?>" size="10"
                           maxlength="10" readonly>
                    <img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo _("Champ obligatoire"); ?>">
                    <span class="annot_petit_gras"><?PHP echo _("au"); ?></span>
                    <input name="dateff" type="text" id="dateff" value="<?PHP echo $cocl_dateff ?>" size="10"
                           maxlength="10" readonly>
                    <img src="../img/raz.png" id="razdatescocl" border="0" align="absmiddle">
                    <span
                        class="annot_petit_it">(<?PHP echo _("ne pas mettre de date de fin pour un contrat 'illimité'"); ?>
                        )</span>
                </td>
            </tr>
            <tr>
                <td width="250" class="rubfrm" id="f_renauto"
                    align="right"><?PHP echo _("Renouvellement automatique ?"); ?></td>
                <td>
                    <?PHP
                    cre_select('renauto', 'renuto', $non_oui, (int)$cocl_renauto);
                    ?>
                    <br />
                    <span
                        class="annot_petit_it"><?PHP echo _("Si 'Oui' : à la clôture, le contrat sera automatiquement renouvelé, avec validation directe de l'accord client"); ?></span>
            </tr>
        </table>

        <!-- Nombre de jours de préavis -->
        <table width="100%" border="0">
            <tr>
                <td width="250" class="rubfrm" id="f_preavis" align="right"><?PHP echo _("Préavis"); ?></td>
                <td>
                    <input name="preavis" type="text" id="preavis" value="<?PHP echo $cocl_preavis ?>" size="3"
                           maxlength="3" align="right">
                    <span class="annot_std_gras">jours avant date d'échéance</span>
                    <?PHP
                    echo "<span class=\"annot_petit_it\">";
                    echo "(" . _("La valeur doit se trouver entre") . " " . preavis_max() . " " . _("et") . " " . preavis_min() . " " . _("jours") . ")";
                    echo "</span>";
                    ?>
                </td>
            </tr>
        </table>

        <!-- Détail matériel couvert par contrat -->
        <table width="100%" border="0">
            <tr>
                <td width="250" class="rubfrm" id="f_matos" align="right"><?PHP echo _("Matériel / Licences"); ?></td>
                <td>
                    <?PHP
                    if (($td == "add") OR ($td == "edit")) {
                        echo '<span id="addmat" class="falselnk">';
                        echo ' <img src="../img/addmat.gif" title="' . _("Gérer Matériels & Licences") . '" border="0" align="absmiddle"> ' . _("Gérer Matériels & Licences");
                        echo ' / ';
                        echo '</span>';
                    }

                    echo '<span id="viewmat" class="falselnk">';
                    echo ' <img src="../img/eye.png" title="' . _("Voir Matériels & Licences") . '" border="0" align="absmiddle"> ' . _("Voir Matériels & Licences");
                    echo '</span>';


                    echo '<div id="popmatselected" class="pop_detailpbm">';

                    echo '<div align="right">';
                    echo '<img src="../img/close.gif" id="closemat" title="' . _("Fermer") . '" border="0" align="absmiddle">';
                    echo '</div>';

                    echo '<div class="annot_gras_it" align="center">';
                    echo _("MATERIELS / LICENCES");
                    echo '</div>';
                    echo '<textarea name="detailmat" rows="10" id="detailmat" readonly>';
                    echo '</textarea>';

                    echo '</div>';

                    echo '<textarea name="matos" rows="10" id="matos">' . $cocl_matos . '</textarea>';
                    ?>
                </td>
                <td width="16">
                    <?PHP
                    if (($td == "add") OR ($td == "edit"))
                        echo '<img src="../img/oblig.png" align="absmiddle" align="top">';
                    else
                        echo '&nbsp;';
                    ?>
            </tr>
        </table>

        <?PHP if ($td <> "add") { ?>  <!-- début de zone exclue si création -->
            <!-- Signataire du contrat -->
            <table width="100%" border="0">
                <tr>
                    <td width="250" class="rubfrm" id="f_datesig" align="right"><?PHP echo("Signé le"); ?></td>
                    <td>
                        <input name="datesig" type="text" id="datesig" value="<?PHP echo $cocl_datesigf ?>" size="10"
                               maxlength="10" readonly>
                    </td>
                </tr>
                <tr>
                    <td width="250" class="rubfrm" id="f_signe" align="right"><?PHP echo _("Signé par"); ?></td>
                    <td>
                        <input name="signe" type="text" id="signe" value="<?PHP echo $cocl_signe ?>" size="70" readonly>
                    </td>
                </tr>
            </table>
            <br />

            <!-- Affichage uniquement si le client a été relancé -->
            <?PHP if ($cocl_daterelf <> "") { ?>
                <!-- Date de relance du contrat -->
                <table width="100%" border="0">
                    <tr>
                        <td width="250" class="rubfrm" id="f_daterelf" align="right"><?PHP echo _("Relancé le"); ?></td>
                        <td>
                            <input name="daterelf" type="text" id="daterelf" value="<?PHP echo $cocl_daterelf ?>"
                                   size="10" maxlength="10" readonly>
        <span class="annot_petit_it">
		<?PHP
        echo "(" . $cocl_nivrel . " " . _("fois") . ")";
        ?>
		</span>
                        </td>
                    </tr>
                </table>
            <?PHP } ?>

            <!-- affiché uniquement si contrat signé -->
            <?PHP if ($cocl_datesigf <> "") { ?>

                <!-- Contrat renouvelé ou pas ? -->
                <table width="100%" border="0">
                    <tr>
                        <td width="250" class="rubfrm" id="f_renouv" align="right"><?PHP echo _("Renouvelé"); ?></td>
                        <td>
                            <input name="renouv" type="text" id="renouv" value="<?PHP echo $non_oui[$cocl_renouv]; ?>"
                                   size="3" maxlength="3" readonly>
                            <span class="annot_std_gras"><?PHP echo _("Nouveau contrat"); ?> :</span>
                            <input name="num" type="text" id="num" value="<?PHP echo $cocl_rnum; ?>" size="20"
                                   maxlength="20" readonly>
                            <?PHP
                            if (@$_SESSION["niv_log"] >= 4) {
                                if ($cocl_renouv == 0) {
                                    if (datetolocal($cocl_datesig) <> "") // Uniquement si signé
                                    {
                                        $url_rencocl = "coclren_maj.php?co=" . $cocl_code;
                                        ?>
                                        <a href="<?PHP echo $url_rencocl ?>"><img src="../img/renouv.png"
                                                                                  title="<?PHP echo _("Renouveler le contrat"); ?>"
                                                                                  border="0" align="absmiddle"></a>
                                        <a href="<?PHP echo $url_rencocl ?>"> <?PHP echo _("Renouveler le contrat"); ?> </a>
                                        <?PHP
                                        if (datetolocal($cocl_datef) <> "") // Uniquement si date de fin
                                        {
                                            $datemin = nouv_date_moins_jours($cocl_datef, $preavis_mini);
                                            $datebut = nouv_date_moins_jours($cocl_datef, $cocl_preavis);

                                            // Si c'est trop tôt (date mini de préavis < aujourd'hui) on affiche une icône complémentaire
                                            if (comp_date($datemin, $datea) == FALSE) {
                                                $lst_ttot = TRUE;

                                                echo " ";
                                                echo '<img src="../img/tot.png" title="' . _("Trop tôt") . ' (' . _("à partir du") . ' ' . datetolocal($datemin) . ')" border="0" align="absmiddle">';
                                            }

                                            // Si c'est trop tard (aujourd'hui > date butoir) on affiche une icône complémentaire
                                            if (comp_date($datea, $datebut) == FALSE) {
                                                $lst_ttard = TRUE;

                                                echo " ";
                                                echo '<img src="../img/tard.png" title="' . _("Trop tard (depuis le") . ' ' . datetolocal($datebut) . ')" border="0" align="absmiddle">';
                                            }
                                        }
                                    }
                                }
                            }
                            ?>
                        </td>
                    </tr>
                </table>

                <!-- Date de clôture du contrat -->
                <table width="100%"  border="0">
                <tr>
                    <td width="250" class="rubfrm" id="f_datefinf"
                        align="right"><?PHP echo _("Contrat clôt le"); ?></td>
                    <td>
                        <input name="datefinf" type="text" id="datefinf" value="<?PHP echo $cocl_datefinf ?>" size="10"
                               maxlength="10" readonly>
                        <?PHP
                        if (($cocl_datefinf == "") AND (tps_trav_non_clot_sec($cocl_code, TRUE) == 0) AND ((@$_SESSION["niv_log"] == 9) OR (@$_SESSION["niv_log"] == 5) OR (@$_SESSION["niv_log"] == 4)))
                            echo ' <a href="coclclos_maj.php?co=' . $cocl_code . '"><img src="../img/clore.png" border="0" align="absmiddle"> ' . _("Clore manuellement") . '</a>';
                        ?>
                    </td>
                </tr>
                <!-- Fin affiché uniquement si contrat signé -->
            <?PHP
            }
            ?>
            </table>


        <?PHP } ?>  <!-- Fin de zone exclue si création -->

        <!-- Montant du contrat -->
        <table width="100%" border="0">
            <tr>
            <tr>
                <td width="250" class="rubfrm" id="f_pu" align="right"><?PHP echo _("PV HT"); ?></td>
                <td>
                    <table width="100%" border="0">
                        <tr>
                            <td>
                                <?PHP
                                switch ($td) {
                                    case "add" :
                                    case "edit" :
                                        cre_input_num('pu', $cocl_pvht, TRUE, FALSE);
                                        break;
                                    default :
                                        cre_input_num('pu', $cocl_pvht, TRUE, TRUE);
                                        break;
                                }
                                ?>
                            </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 HT (inclus 'à sortir'") . ") : ";
                                    echo full_num_format($pxrevient, 'span', 'pxr', TRUE);
                                } else
                                    echo "&nbsp;";
                                ?>
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
            <tr>
                <td width="250" class="rubfrm" id="f_tva" align="right"><?PHP echo _("TVA"); ?></td>
                <td>
                    <?PHP
                    // Création de la liste des TVA
                    $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
                    $rech = "SELECT * FROM `" . TBTVA . "` WHERE tva_actif=1 ORDER BY tva_desc";
                    $rows = $db->get_results($rech, ARRAY_A);
                    $db->disconnect();
                    cre_select_tab('tva', 'tva', $rows, 'tva_code', 'tva_desc', '', $cocl_codetva, '', _("-- Faites votre choix --"));

                    // création des taux de TVA (champs cachés)
                    if ($rows) {
                        foreach ($rows as $row) {
                            $row = encode_str($row);
                            extract($row);
                            echo '<input name="' . $tva_code . '" type="hidden" id="' . $tva_code . '" value="' . $tva_tx . '">';
                        }
                    }
                    ?>
                </td>
            </tr>
            <tr>
                <td width="250" class="rubfrm" id="f_puttc" align="right"><?PHP echo _("PV TTC"); ?></td>
                <td>
                    <?PHP
                    switch ($td) {
                        case "add" :
                        case "edit" :
                            cre_input_num('puttc', $pvttc, TRUE, FALSE);
                            break;
                        default :
                            cre_input_num('puttc', $pvttc, TRUE, TRUE);
                            break;
                    }
                    ?>
                </td>
            </tr>
        </table>


        <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" id="enr" type="button" class="bton_std" id="enr" value="'._("Enregistrer").'">';
                    echo '<input name="enrimp" id="enrimp" type="button" class="bton_std" id="enrimp" value="'._("Enregistrer & Imprimer").'">';
                    break;
                case "del" :
                    echo '<input name="del" type="submit" class="bton_std" id="del" value="'._("Supprimer").'">';
                    break;
            }
            ?>
        </p>
        </form>
        <!-- Fin affiché uniquement s'il y a un code client -->
    <?PHP
} else {
    if ($pbm_cocl == TRUE)
        pop_ret_auto(_("Merci de choisir un de vos contrats"), 'warn', 'cocl_lst.php?ord=DES&tri=Code');
    else {
        if (@$_SESSION["niv_log"] == 1)
            pop_ret_auto(_("Merci de choisir votre compte"), 'warn', "index.php");
        if ((@$_SESSION["niv_log"] == 4) OR (@$_SESSION["niv_log"] == 3))
            pop_ret_auto(_("Merci de choisir un de vos clients"), 'warn', "cli_lst.php&td=con");
    }
}
include_once("pied.php");
?>