<?php
/****************************************************************************************
 * SMI (Services Maintenance Interventions) est une gestion libre de maintenance et de SAV
 *
 * Version 1.0.4
 *
 * Copyright (C) 2006-2016  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) {
    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(valsession('code_log'));
// Variables Formulaire
fix_magic_quotes();
$_POST = clean_str($_POST);
$_GET = clean_str($_GET);

$pbm_cocl = FALSE;
$pbm_cocla = FALSE;
$pbm_cli = FALSE;
$pv_ttc = 0;
$tab_cli = [];
$str_tlp = '';
$cocla_id = 0;
$td = '';
$_SESSION['scli_choisis'] = '';
$_SESSION['sclia_choisis'] = '';
$_SESSION['rlp_choisis'] = '';

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

// Niveau <=3 ne peut que voir les annexes contrats
if (valsession('niv_log') <= 3) {
    $td = 'view';
}

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

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

if (($pbm_cocl == FALSE) AND ($pbm_cocla == FALSE)) {
    $codeadev = give_dev_codea_defaut($_SESSION['lng'], TRUE);

    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 (trim($cocl_codeadev) == '') {
                $cocl_codeadev = give_dev_codea_defaut_cocl($cocl_code, $_SESSION['lng']);
            }

            // Si contrat n'est pas signé ou est terminé, on ne peut pas ajouter d'annexe
            if ((($cocl_signe == '') OR (datetolocal($cocl_datefin) <> '')) AND ($td == 'add')) {
                $pbm_cocl = TRUE;
            }

            // Si contrat terminé, force le mode "view"
            if (datetolocal($cocl_datefin) <> '') {
                $td = 'view';
            }

            if ($pbm_cocl == FALSE) {
                // Récupération des informations client
                $row = lit_enr_cli($cocl_codecli);
                if ($row) {
                    $row = encode_str($row);
                    extract($row);
                }

                switch (valsession('niv_log')) {
                    // Contrôle qu'un client n'essaye pas de "hacker" un contrat
                    case 1 :
                        $tab_cli = give_tab_rcli($_SESSION['code_log'], TRUE);
                        if (exist_in_array($cocl_codecli, $tab_cli) == FALSE) {
                            $pbm_cocl = TRUE;
                        }
                        break;
                    // Contrôle qu'une agence n'essaye pas de "hacker" un contrat
                    case 3 :
                    case 4 :
                        if ($cocl_codeage <> valsession('code_age')) {
                            $pbm_cocl = TRUE;
                        }
                        break;
                }
            }
        } else {
            $pbm_cocl = TRUE;
        }
    } else {
        $pbm_cocl = TRUE;
    }
}

if (($pbm_cocl == FALSE) AND ($pbm_cocla == FALSE)) {

    // Construction de la chaîne des sites sélectionnés sur le contrat et TOUTES les annexes de celui-ci
    $lstsites_annexes = cree_str_lstsites_cocl($co, TRUE);
    // $lstsites_annexes = cree_str_lstsites_cocla($co,0);
    $_SESSION['sclia_choisis'] = $lstsites_annexes;

    if ($coa <> '') {
        // Récupération des informations annexe contrat client
        $row = lit_enr_cocla($coa, $co);
        if (is_array($row)) {
            $row = encode_str($row);
            extract($row);

            if ($cocla_codecocl <> $co) {
                $pbm_cocla = TRUE;
            }

            if ($pbm_cocla == FALSE) {
                // Récupération des informations TVA
                $row = lit_enr_tva($cocla_codetva, TRUE);
                if ($row) {
                    extract($row);
                }

                $txtva = $tva_tx / 100;


                $cocla_datecreaf = datetolocal($cocla_datecrea);
                $cocla_dateenvf = datetolocal($cocla_dateenv);
                $cocla_daterecf = datetolocal($cocla_daterec);
                $cocla_datesigf = datetolocal($cocla_datesig);
                $cocla_daterelf = datetolocal($cocla_daterel);
                $pvttc = round(($cocla_pvht * (1 + $txtva)) * 100) / 100;

                // Construction de la chaîne des sites sélectionnés pour cette annexe
                $lstsites = cree_str_lstsites_cocla($co, $cocla_id);
                $_SESSION['scli_choisis'] = $lstsites;

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

                // Si l'annexe est signée, on passe en mode "view"
                if ($cocla_signe <> '') {
                    $td = 'view';
                }


            }
        }
    } else {
        if ($td == 'add') {
            $cocla_code = '';
            $cocla_datecreaf = $datef;
            $cocla_dateenvf = $datef;
            $cocla_daterecf = '';
            $cocla_datesigf = '';
            $cocla_daterelf = '';
            $cocla_codecocl = $co;
            $_SESSION['scli_choisis'] = '';
        } else {
            $pbm_cocla = TRUE;
        }
    }

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

// Vérification du nombre de licences et matériels actifs pour les sites sélectionnés
if (($pbm_cocl == FALSE) AND ($pbm_cocla == FALSE)) {
    $exist_rlic_aselect = (count(cre_tab_rlic_aselect_coa($co, $cocla_id, $_SESSION['sclia_choisis'], $cocla_sitep)) > 0);
    // $exist_rlic_aselect = exist_rlic_actif($cocl_codecli, $_SESSION['sclia_choisis'], $cocla_sitep);
    $exist_rpdt_aselect = (count(cre_tab_rpdt_aselect_coa($co, $cocla_id, $_SESSION['sclia_choisis'], $cocla_sitep)) > 0);
    // $exist_rpdt_aselect = exist_rpdt_actif($cocl_codecli, $_SESSION['sclia_choisis'], $cocla_sitep);
}

switch ($td) {
    case 'add' :
        $titre = _('CREATION ANNEXE CONTRAT CLIENT');
        $cocla_codetva = give_code_tva_default(TRUE);
        break;
    case 'edit' :
        $titre = _('MISE A JOUR ANNEXE CONTRAT CLIENT');
        break;
    case 'del' :
        $titre = _('SUPPRESSION ANNEXE CONTRAT CLIENT');
        break;
    case 'view' :
        if (CheckNivLog('1')) {
            $titre = _('VISUALISATION ANNEXE CONTRAT');
        } else {
            $titre = _('VISUALISATION ANNEXE 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 Annexe Contrat Client'); ?></title>

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

    <script language="javascript">
        var tab1_champ = ["nom:codea ; format:txt ; req:Y ; txt:<?php echo _('Code annexe contrat'); ?> ; stok:frmok ; stbad:frmbad",
            "nom:datecreaf ; format:date ; masque:<?php echo $_SESSION['date_fmtfull']; ?> ; req:Y ; vmn:<?php echo datetolocal($cocl_datesig); ?> ; txt:<?php echo _('Date création'); ?>  ; stok:frmok ; stbad:frmbad",
            "nom:matos ; format:txt ; req:N ; txt:<?php echo _('matériel'); ?>; stok:frmok ; stbad:frmbad",
            <?php if ($td <> 'add') { ?>
            "nom:datesigf ; format:date ; masque jj-mm-aaa ; req:N ; txt:<?php echo _('signé le') ; ?> ; stok:frmok ; stbad:frmbad",
            "nom:signe ; format:txt ; req:N ; txt:<?php echo _('signé par'); ?> ; lmx:70 ; stok:frmok ; stbad:frmbad",
            <?php } ?>
            "nom:pu ; format:reel_ns ; req:Y ; txt:<?php echo _('Prix de vente hors taxes'); ?> ; lmx:10 ; stok:frmok ; stbad:frmbad"];
    </script>

    <script type="text/javascript">
        <!--
        function init_datepicker() {
            <?php include_once ('../jscript/datepicker_prm.js.php'); ?>
            <?php if ($td == 'add') { ?>
            $("#datecreaf").datepicker({
                beforeShow: function() {
                    var mindate = $('#cocldatesigf').val();
                    $(this).datepicker('option', 'minDate', mindate);
                },
                onSelect: function (datesel) {
                    $("#datecreaf").blur();
                    return chk_datedif(datesel, this.id, '<?php echo valsession('date_fmtshort'); ?>', true, 'cocldatesigf', '', '', false);
                }
            });
            <?php } ?>
        }

        function init_calculator() {
            <?php include_once ('../jscript/calculator_prm.js.php'); ?>
            $('#pu').calculator({
                onClose: function(value, inst) {
                    fdeci(this.id, <?php echo valsession('num_nbdec'); ?>);
                    calc_taxe(this.id, 'puttc', 'tva', <?php echo valsession('num_nbdec'); ?>, 'to_ttc');
                }
            });
            $('#puttc').calculator({
                onClose: function(value, inst) {
                    fdeci(this.id, <?php echo valsession('num_nbdec'); ?>);
                    calc_taxe('puht', this.id, 'tva', <?php echo valsession('num_nbdec'); ?>, 'to_ht');
                }
            });
        }

        function init_all() {
        init_Body();
        init_datepicker();
        init_fdeci('pu', <?php echo valsession('num_nbdec'); ?>);
        init_calc_taxe('pu', 'pu', 'puttc', 'tva', <?php echo valsession('num_nbdec'); ?>, 'to_ttc');
        init_fdeci('puttc', <?php echo valsession('num_nbdec'); ?>);
        init_calc_taxe('puttc', 'pu', 'puttc', 'tva', <?php echo valsession('num_nbdec'); ?>, 'to_ht');
        init_calc_taxe('tva', 'pu', 'puttc', 'tva', <?php echo valsession('num_nbdec'); ?>, 'to_ttc');
        <?php
        // readonly_id('tva',false);
        $url_choixsites = 'sites_lst.php?tx=coa&cc='.$cocl_codecli.'&co='.$cocl_code.'&coa='.$cocla_code.'&td='.$td;
        switch ($td)
        {
            case 'add' :
                echo 'init_calculator();';
                if (valsession('niv_log') >= 3)
                    {echo 'warn_cpta('.$cli_cpta.',"cocl");';}
                echo "init_valid_cocla('enr','cocla_maj','".valsession('date_fmtshort')."',tab1_champ,'','');";
                echo "init_valid_cocla('enrimp','cocla_maj','".valsession('date_fmtshort')."',tab1_champ,'','');";
                echo "init_warn('".nb_age_actives()."age','','back','','');";
                echo "init_fen_mat('addmat','fscomp',1024,600);";
                echo "chk_disp_addmat(false,'addmat','".(int)$exist_rlic_aselect."','".(int)$exist_rpdt_aselect."');";
                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');";
                break;
            case 'edit' :
                echo 'init_calculator();';
                if (valsession('niv_log') >= 3)
                    {echo 'warn_cpta('.$cli_cpta.',"cocl");';}
                echo "init_valid_cocla('enr','cocla_maj','".valsession('date_fmtshort')."',tab1_champ,'','');";
                echo "init_valid_cocla('enrimp','cocla_maj','".valsession('date_fmtshort')."',tab1_champ,'','');";
                echo "init_fen_mat('addmat','fscomp',1024,600);";
                echo "chk_disp_addmat(false,'addmat','".(int)$exist_rlic_aselect."','".(int)$exist_rpdt_aselect."');";
                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');";
                break;
            case 'view' :
                echo 'readonly_all();';
                break;
            case 'del' :
                echo "warn_del('');";
                echo 'readonly_all();';
                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');";
                break;
        }
        if (valsession('niv_log') >= 3)
            {echo "init_fensaisie('notes_cli',930,380);";}
        ?>
        init_fensaisie('sites_cocl', 920, 500);
        init_autohref_classe('falselnkimg', '');
        Focus_first();
    }

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

</head>

<body>

<?php include_once('../inc/entete.inc.php');
if (($pbm_cocla == FALSE) AND ($pbm_cocl == FALSE) AND ($pbm_cli == FALSE)) {
    cre_ent_form($titre, 'cocla_lst.php?ord=DES&tri=Code', $_SERVER['HTTP_REFERER'], '');
    ?>
    <form name="cocla_maj" id="cocla_maj" method="post" action="cocla_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="coa">
        <input name="codecli" type="hidden" id="codecli" value="<?php echo $cocl_codecli; ?>">
        <input name="cocldatesigf" type="hidden" id="cocldatesigf" value="<?php echo datetolocal($cocl_datesig); ?>">
        <input name="nbutton" type="hidden" id="nbutton" value="">

        <!-- détails internes de la fiche contrat -->

        <!-- 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 $cocla_datecreaf ?>" size="10"
                           maxlength="10" readonly>
                    <?php if ($td == 'add') {
                        echo ' <img src="../img/oblig.png" align="absmiddle" alt="' . _('Champ obligatoire') . '">';
                        echo '<div class="annot_petit_it">';
                        echo _('Contrat signé le') . ' ' . datetolocal($cocl_datesig);
                        echo '</div>';
                    } ?>
                </td>
            </tr>
        </table>

        <!-- Code de l'annexe au contrat client -->
        <table width="100%" border="0">
            <tr>
                <td width="250" class="rubfrm" id="f_code" align="right"><?php echo _('Code'); ?></td>
                <td>
                    <input name="code" type="text" id="code" value="<?php echo $cocla_codecocl; ?>" readonly> -
                    <input name="codea" type="text" id="codea" value="<?php echo $cocla_code ?>" size="20"
                           maxlength="20" <?php if ($td <> 'add') {
                        echo 'readonly="1"';
                    } ?>>
                    <?php
                    if ((datetolocal($cocla_datesig) == '') AND ($td <> 'add')) {
                        echo ' <span class="alerte1">';
                        echo _('Non signée');
                        echo '</span>';
                        cre_falselnk_img('', 'sig_' . $cocla_id, 'span', 'center', _('Réceptionner'), 'lnk', 'coclreca_maj.php?coa=' . $cocla_id, '../img/coclsig.png');
                    }
                    ?>
                </td>
            </tr>
        </table>

        <!-- Affichage du client -->
        <table width="100%" border="0">
            <tr>
                <td class="rubfrm" id="f_codecli" align="center"><?php echo _('Client'); ?>
                    <?php
                    if (CheckNivLog('3-4-5-9')) {
                        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="350" valign="top">
                    <?php
                    if (valsession('niv_log') >= 3) {
                        $url_affnotesc = 'aff_notesc.php?cc=' . $cocl_codecli;
                        if (url_ok($url_affnotesc, TRUE) == TRUE) {
                            cre_falselnk('', 'notes_cli', 'span', '', _('Notes'), $url_affnotesc, '../img/eye.png', _('Notes'));
                        }
                    }

                    echo '<br />';


                    $sitep_inclus = sitep_in_cocl_except($cocl_code, $cocla_code);
                    $nbscli_libres = nb_scli_non_affectes($cocl_codecli, $cocl_code, $cocla_code);

                    echo '<input name="sitep" type="hidden" id="sitep" value="';
                    if (($sitep_inclus == TRUE) OR ($cocla_sitep == 1)) {
                        echo '1';
                    } else {
                        echo '0';
                    }
                    echo '">';
                    echo '<input name="sitesec" type="hidden" id="sitesec" value="' . $_SESSION['scli_choisis'] . '">';

                    // On ne peut choisir un site que s'il y en a de possibles
                    if (($nbscli_libres > 0) OR ($sitep_inclus == FALSE)) {
                        if (url_ok($url_choixsites, TRUE) == TRUE) {
                            cre_falselnk('', 'sites_cocl', 'div', '', _('Sites couverts'), $url_choixsites, '../img/sites.png', _('Sites couverts'));
                        }
                    }

                    ?>
                </td>
            </tr>
        </table>

        <!-- détail matériel concerné -->
        <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">' . $cocla_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>

        <!-- 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>
                    <?php
                    switch ($td) {
                        case 'add' :
                        case 'edit' :
                            cre_input_num('pu', $cocla_pvht, TRUE, FALSE);
                            break;
                        default :
                            cre_input_num('pu', $cocla_pvht, TRUE, TRUE);
                            break;
                    }
                    ?>
            </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, 'utf8');
                    $rech = 'SELECT * FROM `' . TBTVA . '` WHERE tva_actif=1 ORDER BY tva_desc';
                    $rows = $db->get_results($rech, ARRAY_A);
                    close_database();
                    cre_select_tab('tva', 'tva', $rows, 'tva_code', 'tva_desc', '', $cocla_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>

        <?php if ($td <> 'add') { ?>
            <!-- Signataire du contrat -->
            <table width="100%" border="0">
                <tr>
                    <td width="250" class="rubfrm" id="f_datesig" align="right"><?php echo('Signée le'); ?></td>
                    <td>
                        <input name="datesigf" type="text" id="datesigf" value="<?php echo $cocla_datesigf ?>" size="10" maxlength="10" readonly>
                        <?php
                        if ((datetolocal($cocla_datesig) == '') AND ($td <> 'add')) {
                            cre_falselnk_img('', 'sig_' . $cocla_id, 'span', 'center', _('Réceptionner'), 'lnk', 'coclreca_maj.php?coa=' . $cocla_id, '../img/coclsig.png');
                        }
                        ?>
                    </td>
                </tr>
                <tr>
                    <td width="250" class="rubfrm" id="f_signe" align="right"><?php echo _('Signée par'); ?></td>
                    <td>
                        <input name="signe" type="text" id="signe" value="<?php echo $cocla_signe ?>" size="70" readonly>
                    </td>
                </tr>
            </table>
            <br/>

            <?php if ($cocla_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 $cocla_daterelf ?>"
                                   size="10"
                                   maxlength="10" readonly>
        <span class="annot_petit_it">
		<?php
        echo '(' . $cocla_nivrel . ' fois)';
        ?>
		</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" id="enr" type="button" class="bton_std"value="' . _('Enregistrer') . '">';
                    echo '<input name="enrimp" id="enrimp" type="button" class="bton_std" 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 (CheckNivLog('1')) {
            pop_ret_auto(_('Merci de choisir votre compte'), 'warn', 'index.php');
        }
        if (CheckNivLog('3-4')) {
            pop_ret_auto(_('Merci de choisir un de vos clients'), 'warn', 'cli_lst.php&td=con');
        }
    }
}
include_once('pied.php');
?>
</body>
</html>