<?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_cocl.inc.php');
include_once('../inc/fic_do.inc.php');
include_once('../inc/fic_droits.inc.php');
include_once('../inc/fic_hum.inc.php');
include_once('../inc/fic_loc.inc.php');
include_once('../inc/fic_cli.inc.php');
include_once('../inc/fic_fici.inc.php');
include_once('../inc/fic_rel.inc.php');
include_once('../inc/fic_zc.inc.php');
include_once('../inc/func.inc.php');
include_once('../inc/func_fic.inc.php');
include_once('../inc/func_geo.inc.php');
include_once('../inc/func_txt.inc.php');
include_once('../classes/geoplugin/geoplugin.class.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'));
check_modules();

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

$td = $_GET['td'];
$coderech = '';
if (isset($_GET['cc'])) {
    $coderech = $_GET['cc'];
} else {
    if (CheckNivLog('1')) {
        $coderech = valsession('code_log');
    }
}
$nbcontacts = 0;
$nbcontrats = 0;
$nbinterventions = 0;
$nbdossiers = 0;
$nbcoloc = 0;
$ca = '';
$pbm_cli = FALSE;

switch (valsession('niv_log')) {
    // Un client ne peux qu'éditer son propre compte ou ceux qu'il gère
    case 1 :
        $td = 'edit';
        $tab_cli = give_tab_rcli($_SESSION['code_log'], TRUE);
        $cli_codeadev = give_dev_codea_defaut_cli($_SESSION['code_log'], $_SESSION['lng']);
        if (exist_in_array($coderech, $tab_cli) == FALSE) {
            $pbm_cli = TRUE;
        }
        break;
    case 3 :
    case 4 :
        $cli_codeadev = give_dev_codea_defaut_age($_SESSION['code_age'], $_SESSION['lng'], TRUE);
        break;
    case 6 :
    case 7 :
        $cli_codeadev = give_dev_codea_defaut_do($_SESSION['code_age'], $_SESSION['lng']);
        break;
    default :
        $cli_codeadev = give_dev_codea_defaut($_SESSION['lng'], TRUE);
        break;
}

if ($coderech <> '') {
    // vérification qu'il existe bien des contacts et nombre de ceux-ci
    $nbcontacts = nb_ccli_in_cli($coderech);

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

    // vérification qu'il existe bien des interventions et nombre de celles-ci
    switch ($_SESSION['niv_log']) {
        case 3 :
        case 4 :
            $nbinterventions = nb_int_cli($coderech, $_SESSION['niv_log'], $_SESSION['code_age']);
            $nbdossiers = nb_dos_cli($coderech, $_SESSION['niv_log'], $_SESSION['code_age']);
            $nbcoloc = nb_coloc_cli($coderech, $_SESSION['niv_log'], $_SESSION['code_age']);
            break;
        case 6 :
        case 7 :
            $nbinterventions = nb_int_cli($coderech, $_SESSION['niv_log'], $_SESSION['code_do']);
            $nbdossiers = nb_dos_cli($coderech, $_SESSION['niv_log'], $_SESSION['code_age']);
            $nbcoloc = nb_coloc_cli($coderech, $_SESSION['niv_log'], $_SESSION['code_age']);
            break;
        case 5 :
        case 9 :
            $nbinterventions = nb_int_cli($coderech, $_SESSION['niv_log'], '');
            $nbdossiers = nb_dos_cli($coderech, $_SESSION['niv_log'], $_SESSION['code_age']);
            $nbcoloc = nb_coloc_cli($coderech, $_SESSION['niv_log'], $_SESSION['code_age']);
            break;
    }

    // Contrôle qu'une agence n'essaye pas de "hacker" un client
    if ($td <> 'add') {
        // Récupération des informations clients
        $row = lit_enr_cli($coderech, TRUE);
        if (is_array($row)) {
            $row = encode_str($row);
            extract($row);
            $cli_codeadev = give_dev_codea_defaut_cli($cli_code, $_SESSION['lng']);

            $mess_err = check_fic_cli($cli_code, $cli_ste, $cli_nom, $cli_prenom, TRUE);
            if ($mess_err == '') {
                switch (valsession('niv_log')) {
                    case 3 :
                    case 4 :
                        if (client_age_ok($cli_code, valsession('code_age'), TRUE) == FALSE) {
                            $pbm_cli = TRUE;
                        }
                        break;
                    default :
                        break;
                }
            } else {
                $pbm_cli = TRUE;
            }
            if (CheckNivLog('3-4') AND ($pbm_cli == FALSE)) {
                switch (nivges_cli($cli_code, valsession('code_age'), TRUE)) {
                    case 0 :
                        $td = 'view';
                        break;
                    case -1 :
                        $pbm_cli = TRUE;
                        break;
                    case 9 :
                        break;
                }
            }
        } else {
            $pbm_cli = TRUE;
        }
    } else {
        $pbm_cli = TRUE;
    }
} else {
    if ($td == 'add') {
        $cli_code = crecodesession('C');
        $cli_cpta = 0;
        $cli_prev = 0;
    } else {
        $pbm_cli = TRUE;
    }
}

$titre = '';
switch ($td) {
    case 'add' :
        $titre = _('CREATION COMPTE CLIENT');
        break;
    case 'edit' :
        $titre = _('MISE A JOUR COMPTE CLIENT');
        break;
    case 'del' :
        $titre = _('SUPPRESSION COMPTE CLIENT');
        break;
    default :
        $pbm_cli = TRUE;
        break;
}

$lst_readonly = '';
if (exist_cli_in_int_act($cli_code) == TRUE) {
    $lst_readonly .= 'prop';
}
if ((($td == 'edit') OR ($td == 'del')) AND ((int)$cli_type == 2)) {
    $lst_readonly .= '-typ';
}
if (CheckNivLog('1')) {
    $lst_readonly .= '-pays-dep-ville';
}

if ((CheckNivLog('4') AND mod_fact_age(valsession('code_log')) <> 1) OR CheckNivLog('3')) {
    $lst_readonly .= '-cpta-mfact';
}
?>
<!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 Client'); ?></title>

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

    <script language="javascript">
        <!--
        var tab1_champ = [
            <?php
            if (CheckNivLog('5-9'))
            {
                echo '"nom:prop ; format:liste ; req:Y ; txt:'._('Agence gestionnaire').'; vmn:1 ; stok:frmok ; stbad:frmbad",';
                echo '"nom:codeadev ; format:liste ; req:Y ; txt:'._('Devise').' ; vmn:1; stok:frmok ; stbad:frmbad",';
            }

            if (valsession('niv_log') >= 2)
            {
                if ($td=='add')
                    {echo '"nom:typ ; format:liste ; req:Y ; txt:'._('Type').'; vmn:1 ; stok:frmok ; stbad:frmbad",';}
                else
                    {echo '"nom:typ ; format:txt ; req:Y ; txt:'._('Type').'; stok:frmok ; stbad:frmbad",';}
                echo '"nom:cat ; format:liste ; req:Y ; txt:'._('Catégorie').' ; vmn:1; stok:frmok ; stbad:frmbad",';
            }
            ?>
            "nom:ste ; format:txt ; req:N ; txt:<?php echo _('Société'); ?>; lmx:50 ; stok:frmok ; stbad:frmbad",
            "nom:rcs ; format:siret ; req:N ; txt:<?php echo _('Siret'); ?> ; lmx:50; stok:frmok ; stbad:frmbad",
            "nom:ape ; format:naf ; req:N ; txt:<?php echo _('APE'); ?> ; lmx:10; stok:frmok ; stbad:frmbad",
            "nom:tvai ; format:tva ; req:N ; txt:<?php echo _('TVA intra.'); ?> ; lmx:50; stok:frmok ; stbad:frmbad",
            "nom:civil ; format:liste ; req:Y ; txt:<?php echo _('Civilité'); ?> ; vmn:1; stok:frmok ; stbad:frmbad",
            "nom:prenom ; format:txt ; req:Y ; txt:<?php echo _('Civilité'); ?> ; lmx:50; stok:frmok ; stbad:frmbad",
            "nom:nom ; format:txt ; req:Y ; txt:<?php echo _('Civilité'); ?> ; lmx:50; stok:frmok ; stbad:frmbad",
            "nom:adr1 ; format:txt ; req:Y ; txt:<?php echo _('Adresse'); ?> ; lmx:50; stok:frmok ; stbad:frmbad",
            "nom:adr2 ; format:txt ; req:N ; txt:<?php echo _('Adresse (2)'); ?> ; lmx:50; stok:frmok ; stbad:frmbad",
            "nom:dep ; format:liste ; req:Y ; txt:<?php echo _('Département'); ?> ; vmn:1; stok:frmok ; stbad:frmbad",
            "nom:ville ; format:liste ; req:Y ; txt:<?php echo _('Ville'); ?> ; vmn:1; stok:frmok ; stbad:frmbad",
            "nom:pays ; format:liste ; req:Y ; txt:<?php echo _('Pays'); ?> ; vmn:1; stok:frmok ; stbad:frmbad",
            "nom:telf ; format:tel ; req:Y ; txt:<?php echo _('Téléphone Fixe'); ?>; stok:frmok ; stbad:frmbad",
            "nom:fax ; format:tel ; req:N ; txt:<?php echo _('Télécopieur'); ?>; stok:frmok ; stbad:frmbad",
            "nom:telp ; format:telp ; req:N ; txt:<?php echo _('Téléphone portable'); ?>; stok:frmok ; stbad:frmbad",
            <?php
                echo '"nom:email ; format:mail ; req:';
                switch (valsession('niv_log'))
                {
                    case 1 :
                        if ($cli_prev==0) {echo 'Y';} else {echo 'N';}
                        break;
                    case 2 :
                        echo 'Y';
                        break;
                    default :
                        echo 'N';
                        break;
                }
                echo '; txt:'._('Email').' ; lmx:50; stok:frmok ; stbad:frmbad",';

            if (CheckNivLog('5-9'))
            {
                echo '"nom:notaa ; format:txt ; req:N ; txt:'._('Notes administration').'; stok:frmok ; stbad:frmbad",';
                echo '"nom:ccpta ; format:txt ; req:N ; txt:'._('Code compta').'; lmx:15 ; stok:frmok ; stbad:frmbad",';
                echo '"nom:ccptasp ; format:txt ; req:N ; txt:'._('Code compta site principal').'; lmx:15 ; stok:frmok ; stbad:frmbad",';
            }
            if (valsession('niv_log') >= 3)
                {echo '"nom:notat ; format:txt ; req:N ; txt:'._('Notes techniques').'; stok:frmok ; stbad:frmbad",';}
            ?>
            "nom:mess ; format:mail ; req:N ; txt:<?php echo _('Messagerie'); ?>  ; lmx:50; stok:frmok ; stbad:frmbad"];
        //-->
    </script>

    <script type="text/javascript">
        <!--
        $(function () {
            $("#ste").Setcase({caseValue: 'upper', changeonFocusout: true});
            $("#rcs").Setcase({caseValue: 'upper', changeonFocusout: true});
            $("#ape").Setcase({caseValue: 'upper', changeonFocusout: true});
            $("#tvai").Setcase({caseValue: 'upper', changeonFocusout: true});
            $("#tcom").Setcase({caseValue: 'upper', changeonFocusout: true});
            $("#adr1").Setcase({caseValue: 'upper', changeonFocusout: true});
            $("#adr2").Setcase({caseValue: 'upper', changeonFocusout: true});
            $("#nom").Setcase({caseValue: 'upper', changeonFocusout: true});
            $("#email").Setcase({caseValue: 'lower', changeonFocusout: true});
            $("#mess").Setcase({caseValue: 'lower', changeonFocusout: true});
            $("#prenom").Setcase({caseValue: 'allfirst', changeonFocusout: true});
        });

        function init_all() {
            init_Body();
            $("#onglets_cli").tabs();
            <?php
            if ($pbm_cli==FALSE)
            {
                switch ($td)
                {
                    case 'add' :
                        echo "init_valid_cli('enr','cli_maj','".valsession('date_fmtshort')."',tab1_champ,'pays','');";
                        echo "init_valid_cli('int','cli_maj','".valsession('date_fmtshort')."',tab1_champ,'pays','');";
                        break;
                    case 'edit' :
                        echo "init_sitecli('ste','site','pas_site');";
                        echo "init_chk_sitecli('ste','site','pas_site');";
                        echo "init_new_fen('etats','impression','change',true);";
                        echo "init_valid_cli('enr','cli_maj','".valsession('date_fmtshort')."',tab1_champ,'pays','');";
                        echo "init_valid_cli('int','cli_maj','".valsession('date_fmtshort')."',tab1_champ,'pays','');";
                        break;
                    case 'view' :
                        echo "init_sitecli('ste','site','pas_site');";
                        echo "init_new_fen('etats','impression','change',true);";
                        echo 'readonly_all();';
                        break;
                    case 'del' :
                        echo "init_sitecli('ste','site','pas_site');";
                        echo 'readonly_all();';
                        echo "warn_del('cli');";
                        break;
                }
                if (valsession('niv_log')>=3)
                {
                    if ($td <>'del')
                        {echo 'warn_cpta('.$cli_cpta.',"cli");';}
                }
            ?>
            init_ajax_ville();
            //init_ajax_dep();
            init_ajax_dep_zc_pays_cli();
            init_fensaisie('add_ccli', 950, 560);
            init_fensaisie('edit_ccli', 950, 560);
            init_fensaisie('tra_cli', 800, 500);
            init_fensaisie('hist_coclh', 800, 560);
            init_fensaisie('gcli', 970, 750);
            init_fensaisie('pjcli', 970, 750);
            init_fensaisie('fen_scli', 910, 660);
            init_autohref('repcli', 'click', '', true);
            init_autohref('add_dos', 'click', '', true);
            init_autohref('view_dos', 'click', '', true);
            init_autohref('add_int', 'click', '', true);
            init_autohref('view_int', 'click', '', true);
            init_autohref('add_intp', 'click', '', true);
            init_autohref('add_cocl', 'click', '', true);
            init_autohref('view_cocl', 'click', '', true);
            init_autohref('add_coloc', 'click', '', true);
            init_autohref('view_coloc', 'click', '', true);
            init_autohref('add_rel', 'click', '', true);
            <?php
            }
            ?>
            init_back('annul', 'click');
            readonly_id('<?php echo $lst_readonly; ?>', false);
            Focus_first();
        }

        $(document).ready(function () {
            init_all();
        });
        //-->
    </script>
</head>
<body>
<?php include_once('../inc/entete.inc.php');
cre_ent_form($titre, '', '', '', FALSE);
if ($pbm_cli == FALSE) {
    if ((nb_ccat() <> 0) AND (nb_civ(TRUE) <> 0) AND (nb_fonc() <> 0) AND (nb_age_actives() <> 0)) {
        ?>
        <table width="100%" border="0">
            <tr>
                <td width="33%">
                    <?php
                    switch (valsession('niv_log')) {
                        case 1 :
                            if (count($tab_cli) == 1) {
                                aff_lnk_lst_rech('index.php?tl=1', _("Retour à l'accueil"), $_SERVER['HTTP_REFERER'], _('Retour à la page précédente'));
                            } else {
                                aff_lnk_lst_rech($lnk_cli_lst, _('Retour à la liste'), $_SERVER['HTTP_REFERER'], _('Retour à la page précédente'));
                            }
                            break;
                        case 2 :
                            aff_lnk_lst_rech('index.php?tl=1', _("Retour à l'accueil"), $_SERVER['HTTP_REFERER'], _('Retour à la page précédente'));
                            break;
                        default :
                            aff_lnk_lst_rech($lnk_cli_lst, _('Retour à la liste'), $_SERVER['HTTP_REFERER'], _('Retour à la page précédente'));
                            break;
                    }
                    ?>
                </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">
                    <?php
                    if (valsession('niv_log') <> 2) {
                        switch ($td) {
                            case 'edit' :
                            case 'view' :
                                echo '<select name="etats" size="1" id="etats" class="annot_petit">';
                                echo '<option value="" selected>&#187; ' . _('Etats') . ' &#171;</option>';
                                $urlimp = 'cli_maji.php?cc=' . $coderech;
                                if (url_ok($urlimp) == TRUE) {
                                    echo '<option value="' . $urlimp . '" class="icone" style="background-image: url(../img/sel_fiche.gif);">' . _('Fiche Client') . '</option>';
                                }

                                if ($nbinterventions <> 0) {
                                    $url_inter = 'int_lsti.php?ord=DES&tri=Code';
                                    if (valsession('niv_log') <> 1) {
                                        $url_inter = 'int_lsti.php?ord=DES&tri=Code&search=' . $cli_code . '&rech=Rechercher';
                                    }
                                    if (url_ok($url_inter) == TRUE) {
                                        echo '<optgroup label="' . _('Interventions') . '" class="icone" style="background-image: url(../img/sel_int.gif);">';
                                        echo '<option value="' . $url_inter . '">' . _('Liste') . '</option>';
                                        echo '</optgroup>';
                                    }
                                }

                                if ($nbcontrats <> 0) {
                                    $url_cocl = 'cocl_lsti.php?ord=DES&tri=Code';
                                    if (valsession('niv_log') <> 1) {
                                        $url_cocl = 'cocl_lsti.php?ord=DES&tri=Code&search=' . $cli_code . '&rech=Rechercher';
                                    }
                                    $url_coclsm = 'coclsm_pdf.php?cc=' . $cli_code;
                                    if ((url_ok($url_cocl) == TRUE) OR (url_ok($url_coclsm) == TRUE)) {
                                        echo '<optgroup label="' . _('Contrats') . '" class="icone" style="background-image: url(../img/sel_con.gif);">';
                                    }
                                    if (url_ok($url_cocl) == TRUE) {
                                        echo '<option value="' . $url_cocl . '">' . _('Liste') . '</option>';
                                    }
                                    if (url_ok($url_coclsm) == TRUE) {
                                        echo '<option value="' . $url_coclsm . '">' . _('Synthèse complète') . '</option>';
                                        echo '<option value="' . $url_coclsm . '&tco=o">' . _('Synthèse ouverts') . '</option>';
                                        echo '<option value="' . $url_coclsm . '&tco=c">' . _('Synthèse clots') . '</option>';
                                    }
                                    if ((url_ok($url_cocl) == TRUE) OR (url_ok($url_coclsm) == TRUE)) {
                                        echo '</optgroup>';
                                    }
                                }

                                if (valsession('niv_log') <> 1) {
                                    if ($nbdossiers <> 0) {
                                        $url_dos = 'dos_lsti.php?ord=DES&tri=Code&search=' . $cli_code . '&rech=Rechercher';
                                        if (url_ok($url_dos) == TRUE) {
                                            echo '<optgroup label="' . _('Dossiers') . '" class="icone" style="background-image: url(../img/sel_dos.gif);">';
                                            echo '<option value="' . $url_dos . '">' . _('Liste') . '</option>';
                                            echo '</optgroup>';
                                        }
                                    }
                                }
                                if (exist_rel_cli($cli_code) == TRUE) {
                                    $url_rel = 'rel_pdf.php?cr=' . num_rel_cli($cli_code) . '&pbm=0';
                                    $url_relp = 'rel_pdf.php?cr=' . num_rel_cli($cli_code) . '&pbm=1';
                                    if ((url_ok($url_rel) == TRUE) OR (url_ok($url_relp) == TRUE)) {
                                        echo '<optgroup label="' . _('relevé de parc') . '" class="icone" style="background-image: url(../img/sel_rel.gif);">';
                                    }
                                    if (url_ok($url_rel) == TRUE) {
                                        echo '<option value="' . $url_rel . '">' . _('relevé complet') . '</option>';
                                    }
                                    if (url_ok($url_relp) == TRUE) {
                                        echo '<option value="' . $url_relp . '">' . _('relevé avec problèmes') . '</option>';
                                    }
                                    if ((url_ok($url_rel) == TRUE) OR (url_ok($url_relp) == TRUE)) {
                                        echo '</optgroup>';
                                    }
                                }
                                echo '</select>';
                                break;
                            default :
                                echo '&nbsp;';
                                break;
                        }
                    }
                    ?>
                </td>
            </tr>
            <tr>
                <td width="31%">
                    <?php if (($td == 'edit') AND ($cli_ste <> '') AND (valsession('niv_log') <> 2)) {
                        $url_ccli = 'ccli_maj.php?td=add&cc=' . $cli_code . '&tx=cli';
                        if (url_ok($url_ccli) == TRUE) {
                            cre_falselnk('', 'add_ccli', 'span', '', _('Ajouter un contact'), $url_ccli, '../img/ctacts.png', _('Ajouter un contact'));
                        }

                        if (valsession('niv_log') <> 2) {
                            $url_ccli = 'ccli_maj.php?td=lst&cc=' . $cli_code . '&tx=cli';
                            if ($nbcontacts == 0) {
                                echo '<span id="ctact" style="display:none">';
                            } else {
                                echo '<span id="ctact" style="display:inline">';
                            }
                            if (url_ok($url_ccli) == TRUE) {
                                cre_falselnk('', 'edit_ccli', 'span', '', _('Edition contacts'), $url_ccli, '', _('Edition contacts'), true);
                            }
                            echo '</span>';
                        }
                    }
                    ?>
                </td>
                <td width="39%">&nbsp;</td>
                <td width="30%" align="right">
                    <?php
                    if ((valsession('niv_log') >= 3) AND ($td == 'edit') AND (valsession('niv_log') <> 7) AND (valsession('niv_log') <> 6)) {
                        $url_repcli = 'fic_down.php?dir=clients/' . strtolower($cli_code);
                        if (url_ok($url_repcli) == TRUE) {
                            cre_falselnk('', 'repcli', 'div', '', _('Aller dans le répertoire privé'), $url_repcli, '../img/rep_priv.png', _('Aller dans le répertoire privé'));
                        }
                    } else {
                        echo '&nbsp;';
                    }
                    ?>
                </td>
            </tr>
            <tr>
                <td width="33%">
                    <?php if (($td == 'edit') AND ($nbcontrats <> 0) AND (valsession('niv_log') <> 2) AND (valsession('niv_log') <> 7) AND (valsession('niv_log') <> 6)) {
                        if (CheckNivLog('5-9')) {
                            $url_tracli = 'tra_lst.php?tx=r&tl=c&cr=' . $cli_code;
                            if (url_ok($url_detcli) == TRUE) {
                                cre_falselnk('', 'tra_cli', 'span', '', _('Traçabilité'), $url_tracli, '../img/trace.gif', _('Traçabilité'));
                            }
                        }

                        $url_coclh = 'coclhd_lst.php?or=cli&cc=' . $cli_code;
                        if (url_ok($url_coclh) == TRUE) {
                            $nbf_contrats = sprintf("%'03s", $nbcontrats);
                            if (CheckNivLog('5-9')) {
                                cre_falselnk('', 'hist_coclh', 'span', '', _('Historique contrats'), $url_coclh, '../img/hcon.png', _('Historique contrats') . ' (' . $nbf_contrats . ')', true);
                            } else {
                                cre_falselnk('', 'hist_coclh', 'span', '', _('Historique contrats'), $url_coclh, '../img/hcon.png', _('Historique contrats') . ' (' . $nbf_contrats . ')');
                            }
                        }
                    } else {
                        echo '&nbsp;';
                    }
                    ?>
                </td>
                <td width="33%" valign="top" align="center">
                    <?php if (($td == 'edit') AND (valsession('niv_log') >= 3) AND (valsession('niv_log') <> 7) AND (valsession('niv_log') <> 6)) {
                        $url_adddos = '';
                        switch (valsession('niv_log')) {
                            case 3 :
                            case 4 :
                                $url_adddos = 'dos_maj.php?td=add&cc=' . $cli_code . '&ca=' . valsession('code_age');
                                break;
                            default :
                                $url_adddos = 'dos_maj.php?td=add&cc=' . $cli_code . '&ca=' . $cli_prop;
                                break;
                        }
                        if ($url_adddos <> '') {
                            if (url_ok($url_adddos) == TRUE) {
                                cre_falselnk('', 'add_dos', 'span', '', _('Ajouter dossier'), $url_adddos, '../img/dossier.png', _('Ajouter dossier'));
                            }

                            if (($nbdossiers <> 0) AND (valsession('niv_log') <> 2)) {
                                $url_dos = 'dos_lst.php?ord=DES&tri=Code&search=' . $cli_code . '&rech=Rechercher';
                                $texte = _('Voir dossiers') . ' (' . sprintf("%'03s", $nbdossiers) . ')';
                                if (url_ok($url_dos) == TRUE) {
                                    cre_falselnk('', 'view_dos', 'span', '', '', $url_dos, '', $texte, TRUE);
                                }
                            }
                        }
                    }
                    ?>
                </td>
                <td width="33%" align="right">
                    <?php if (($td == 'edit') AND (valsession('niv_log') >= 2)) {
                        $url_addint = '';
                        switch (valsession('niv_log')) {
                            case 3 :
                            case 4 :
                                $url_addint = 'int_maj.php?td=add&cc=' . $cli_code . '&ca=' . valsession('code_age');
                                break;
                            default :
                                $url_addint = 'int_maj.php?td=add&cc=' . $cli_code . '&ca=' . $cli_prop;
                                break;
                        }
                        if ($url_addint <> '') {
                            if (url_ok($url_addint) == TRUE) {
                                cre_falselnk('', 'add_int', 'span', '', _('Saisir intervention'), $url_addint, '../img/int.png', _('Saisir intervention'));
                            }

                            if (($nbinterventions <> 0) AND (valsession('niv_log') <> 2)) {
                                $url_inter = 'int_lst.php?ord=DES&tri=Code&search=' . $cli_code . '&rech=Rechercher';
                                $texte = _('Voir interventions') . ' (' . sprintf("%'03s", $nbinterventions) . ')';
                                if (url_ok($url_inter) == TRUE) {
                                    cre_falselnk('', 'view_int', 'span', '', '', $url_inter, '', $texte, TRUE);
                                }
                            }
                        }
                    }
                    ?>    </td>
            </tr>
            <tr>
                <td width="31%" align="left" valign="top">
                    <?php if (($td == 'edit') AND (valsession('niv_log') >= 3) AND (valsession('niv_log') <> 7) AND (valsession('niv_log') <> 6)) {
                        if (CheckNivLog('3-4')) {
                            $url_addcocl = 'cocl_maj.php?td=add&co=&cc=' . $cli_code . '&ca=' . valsession('code_age');
                        } else {
                            $url_addcocl = 'cocl_maj.php?td=add&co=&cc=' . $cli_code . '&ca=' . $cli_prop;
                        }
                        if (url_ok($url_addcocl) == TRUE) {
                            cre_falselnk('', 'add_cocl', 'span', '', _('Saisir contrat'), $url_addcocl, '../img/contrat.png', _('Saisir contrat'));
                        }

                        if (($nbcontrats <> 0) AND (valsession('niv_log') <> 2)) {
                            $url_cocl = 'cocl_lst.php?ord=DES&tri=Code&search=' . $cli_code . '&rech=Rechercher';
                            $texte = _('Voir contrats') . ' (' . sprintf("%'03s", $nbcontrats) . ')';
                            if (url_ok($url_cocl) == TRUE) {
                                cre_falselnk('', 'view_cocl', 'span', '', '', $url_cocl, '', $texte, TRUE);
                            }
                        }
                    } else {
                        echo '&nbsp;';
                    }
                    ?>
                </td>
                <td width="39%" valign="top" align="center">
                    <?php if (($td == 'edit') AND (valsession('niv_log') >= 3) AND (valsession('niv_log') <> 7) AND (valsession('niv_log') <> 6)) {
                        if (CheckNivLog('3-4')) {
                            $url_addcoloc = 'coloc_maj.php?td=add&cc=' . $cli_code . '&ca=' . valsession('code_age');
                        } else {
                            $url_addcoloc = 'coloc_maj.php?td=add&cc=' . $cli_code . '&ca=' . $cli_prop;
                        }
                        if (url_ok($url_addcoloc) == TRUE) {
                            cre_falselnk('', 'add_coloc', 'span', '', _('Saisir contrat location'), $url_addcoloc, '../img/coloc.png', _('Saisir contrat location'));
                        }

                        if ($nbcoloc <> 0) {
                            $url_coloc = 'coloc_lst.php?ord=DES&tri=Code&search=' . $cli_code . '&rech=Rechercher';
                            $texte = _('Voir contrats location') . ' (' . sprintf("%'03s", $nbcoloc) . ')';
                            if (url_ok($url_coloc) == TRUE) {
                                cre_falselnk('', 'view_coloc', 'span', '', '', $url_coloc, '', $texte, TRUE);
                            }
                        }
                    }
                    ?>
                </td>
                <td width="30%" align="right">
                    <?php if (($td == 'edit') AND (valsession('niv_log') <> 1) AND (valsession('niv_log') <> 2) AND (valsession('niv_log') <> 7) AND (valsession('niv_log') <> 6)) {
                        // On vérifie si le module planning est bien en place
                        if ($mod_planning == TRUE) {
                            $url_addintp = 'intp_maj.php?cc=' . $cli_code;
                            if (url_ok($url_addintp) == TRUE) {
                                cre_falselnk('', 'add_intp', 'span', '', '', $url_addintp, '../img/intp.png', _('Programmer intervention'));
                            }
                        }

                        $url_rel = '';
                        if (exist_rel_cli($coderech) == TRUE) {
                            $url_rel = 'rel_maj.php';
                            if (valsession('niv_log') >= 3) {
                                $url_rel = 'rel_maj.php?td=edit&cr=' . num_rel_cli($cli_code);
                            }
                        } else {
                            if (valsession('niv_log') >= 3) {
                                $url_rel = 'rel_maj.php?td=add&cc=' . $cli_code;
                            }
                        }

                        if ($url_rel <> '') {
                            if (url_ok($url_rel) == TRUE) {
                                cre_falselnk('', 'add_rel', 'span', '', _('Saisir relevé de parc'), $url_rel, '../img/rel.png', _('Saisir relevé de parc'), TRUE);
                            }
                        }
                    } else {
                        echo '&nbsp;';
                    }
                    ?>
                </td>
            </tr>
        </table>
        <form name="cli_maj" id="cli_maj" method="post" action="cli_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="nbutton" type="hidden" id="nbutton" value="">
            <?php if (valsession('niv_log') <= 2) { ?>
                <input name="prev" type="hidden" id="prev" value="<?php echo $cli_prev ?>">
                <?php
                /*
                    <form name="cli_maj" method="post" action="cli_enr.php"
                      onSubmit="javascript:; return (verif_cli(this,tab1_champ,document.cli_maj.pays.value,'<?php echo $_SESSION['lng']; ?>'));"> */
            }
            ?>
            <div id="onglets_cli">
                <ul>
                    <li><a href="#cli_coord"><?php echo _('Coordonnées'); ?></a></li>
                    <?php
                    if (valsession('niv_log') >= 3) {
                        echo '<li><a href="#cli_cpta">' . _('Comptabilité') . '</a></li>';
                        echo '<li><a href="#cli_note">' . _('Notes') . '</a></li>';
                    }
                    ?>
                </ul>
                <div id="cli_coord">
                    <?php
                    if ($td == 'add') {
                        echo '<input name="codecli" type="hidden" id="codecli" value="' . $cli_code . '">';
                    } else {
                        ?>
                        <table width="100%" border="0">
                            <tr>
                                <td width="160" class="rubfrm" id="f_codecli"
                                    align="right"><?php echo _('Code Client'); ?></td>
                                <td>
                                    <input name="codecli" type="text" id="codecli" value="<?php echo $cli_code ?>"
                                           readonly>
                                    <?php
                                    $affrcli = TRUE;
                                    switch ($_SESSION['niv_log']) {
                                        case 1 :
                                        case 2 :
                                        case 3 :
                                        case 4 :
                                        case 6 :
                                        case 7 :
                                        case 10 :
                                        case 11 :
                                            $affrcli = FALSE;
                                            break;
                                        default :
                                            $url_rcli = 'rcli_maj.php?cc=' . $cli_code;
                                            break;
                                    }
                                    if ($affrcli == TRUE) {
                                        if (url_ok($url_rcli) == TRUE) {
                                            cre_falselnk('', 'gcli', 'span', '', _('Groupement de clients'), $url_rcli, '../img/rcli.png', _('Groupement de clients'));
                                        }
                                    }

                                    $affpj = TRUE;
                                    switch ($_SESSION['niv_log']) {
                                        case 1 :
                                        case 2 :
                                        case 6 :
                                        case 7 :
                                        case 10 :
                                        case 11 :
                                            $affpj = FALSE;
                                            break;
                                        default :
                                            $url_pj = 'fic_pj.php?dir=clients/' . strtolower($cli_code) . '/PJ&cc=' . $cli_code . '&tx=cli';
                                            break;
                                    }
                                    if ($affpj == TRUE) {
                                        if (url_ok($url_pj) == TRUE) {
                                            cre_falselnk('', 'pjcli', 'span', '', _('Pièces liées'), $url_pj, '../img/pj.png', _('Pièces liées'), true);
                                        }
                                    }
                                    ?>
                                </td>
                            </tr>
                        </table>
                        <?php
                    }
                    ?>

                    <table width="100%" border="0">
                        <?php
                        if (CheckNivLog('5-9')) {
                            ?>
                            <tr>
                                <td width="160" class="rubfrm" id="f_prop"
                                    align="right"><?php echo _('Agence gestionnaire'); ?></td>
                                <td>
                                    <?php
                                    $tab_first_options = [
                                        '-1' => _('-- Aucune agence en particulier --')
                                    ];
                                    // création de la liste des agences ouvertes
                                    $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST, 'utf8');
                                    // Filtre sur agences ouvertes
                                    $rech = 'SELECT * FROM `' . TBAGE . "` WHERE `age_ouvert` = '1' ORDER BY age_nom";
                                    $rows = $db->get_results($rech, ARRAY_A);
                                    close_database();
                                    cre_select_tab('prop', 'prop', $rows, 'age_code', 'age_nom', 'age_code', $cli_prop, '', _('-- Faites votre choix --'), 1, FALSE, '', _("-- Pas d'agence active --"), TRUE, TRUE, $small = FALSE, $tab_first_options);
                                    ?>
                                    <div
                                        class="annot_petit_it"><?php echo _('Modifiable uniquement si aucune intervention en cours'); ?></div>
                                </td>
                            </tr>
                            <?php
                        }

                        if (valsession('niv_log') >= 2) {
                            ?>
                            <tr>
                                <td width="160" class="rubfrm" id="f_typ" align="right"><?php echo _('Type'); ?></td>
                                <td>
                                    <?php
                                    cre_select('typ', 'typ', $typ_client, (int)$cli_type, '', _('-- Faites votre choix --'));
                                    ?>
                                </td>
                            </tr>
                            <tr>
                                <td width="160" class="rubfrm" id="f_cat"
                                    align="right"><?php echo _('Catégorie'); ?></span></td>
                                <td>
                                    <?php
                                    // Création de la liste des catégories
                                    $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST, 'utf8');
                                    $sql = 'SELECT * FROM `' . TBCCAT . '` ORDER BY cat_desc';
                                    $rows = $db->get_results($sql, ARRAY_A);
                                    close_database();
                                    cre_select_tab('cat', 'cat', $rows, 'cat_code', 'cat_desc', '', $cli_cat, '', _('-- Faites votre choix --'));
                                    ?>
                                </td>
                            </tr>
                            <?php
                        }
                        ?>
                        <tr>
                            <td width="160" class="rubfrm" id="f_ste" align="right"><?php echo _('Société'); ?></td>
                            <td>
                                <table width="100%" border="0">
                                    <tr>
                                        <td width="200">
                                            <input name="ste" type="text" id="ste" value="<?php echo $cli_ste; ?>"
                                                   size="50">
                                        </td>
                                        <td align="left">
                                            <?php
                                            if ((valsession('niv_log') <> 2) AND ($td <> 'add')) {
                                                echo '<div id="site" style="display:none" align="left">';
                                                $url_scli = 'scli_maj.php?cc=' . $cli_code;
                                                if (url_ok($url_scli) == TRUE) {
                                                    cre_falselnk('', 'fen_scli', 'span', '', _('Gérer les sites secondaires'), $url_scli, '../img/sites.png', _('Gérer les sites secondaires'));
                                                } else {
                                                    echo '&nbsp;';
                                                }
                                                echo '</div>';
                                                echo '<div id="pas_site"  style="display:block" align="left">';
                                                echo '&nbsp;';
                                                echo '</div>';
                                            } else {
                                                echo '&nbsp;';
                                            }
                                            ?>
                                        </td>
                                    </tr>
                                </table>
                            </td>
                        </tr>
                        <tr>
                            <td width="160" class="rubfrm" id="f_civil" align="right"><?php echo _('Civilité'); ?></td>
                            <td>
                                <?php
                                // Création de la liste des civilités
                                $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST, 'utf8');
                                $rech = 'SELECT * FROM `' . TBCIV . '` ORDER BY civ_desc';
                                $rows = $db->get_results($rech, ARRAY_A);
                                close_database();
                                cre_select_tab('civil', 'civil', $rows, 'civ_code', 'civ_desc', '', $cli_civilite, '', _('-- Faites votre choix --'));
                                ?>
                            </td>
                        </tr>
                        <tr>
                            <td class="rubfrm" id="f_prenom" align="right"><?php echo _('Prénom'); ?></td>
                            <td>
                                <input name="prenom" type="text" id="prenom" value="<?php echo $cli_prenom ?>"
                                       size="50">
                                <img src="../img/oblig.png" align="absmiddle"
                                     alt="<?php echo _('Champ obligatoire'); ?>">
                            </td>
                        </tr>
                        <tr>
                            <td class="rubfrm" id="f_nom" align="right"><?php echo _('Nom'); ?></td>
                            <td>
                                <input name="nom" type="text" id="nom" value="<?php echo $cli_nom ?>" size="50">
                                <img src="../img/oblig.png" align="absmiddle"
                                     alt="<?php echo _('Champ obligatoire'); ?>">
                            </td>
                        </tr>
                        <tr>
                            <td class="rubfrm" id="f_adr1" align="right"><?php echo _('Adresse'); ?></td>
                            <td>
                                <input name="adr1" type="text" id="adr1" value="<?php echo $cli_adr1 ?>" size="50">
                                <img src="../img/oblig.png" align="absmiddle"
                                     alt="<?php echo _('Champ obligatoire'); ?>">
                            </td>
                        </tr>
                        <tr>
                            <td class="rubfrm" id="f_adr2" align="right"><?php echo _('Adresse (2)'); ?></td>
                            <td>
                                <input name="adr2" type="text" id="adr2" value="<?php echo $cli_adr2 ?>" size="50">
                            </td>
                        </tr>
                        <tr>
                            <td class="rubfrm" id="f_pays" align="right"><?php echo _('Pays'); ?></td>
                            <td>
                                <?php
                                // Création de la liste des pays
                                $rows = give_rows_pays();
                                cre_select_tab('pays', 'pays', $rows, 'pays_code', 'pays_nom', '', $cli_codepays, '', _('-- Faites votre choix --'), 1, FALSE, '-1', _('-- Inconnu --'));
                                ?>
                            </td>
                        </tr>
                        <tr>
                            <td class="rubfrm" id="f_dep" align="right"><?php echo _('Département'); ?></td>
                            <td>
                                <?php
                                // Création de la liste des départements
                                $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST, 'utf8');

                                $tab_zone = [];
                                $lst_zone = [];
                                switch (valsession('niv_log')) {
                                    case 1 :
                                    case 2 :
                                    case 5 :
                                    case 6 :
                                    case 7 :
                                    case 9 :
                                        /* On construit d'abord la liste des Départements couverts pour ce pays */
                                        $tab_zone = tab_zcc_pays_open(str_majuscules($cli_codepays), FALSE);
                                        break;

                                    case 3 :
                                        /* On construit d'abord la liste des Départements couverts par cette agence */
                                        $tab_zone = tab_zcc_age_open(valsession('code_age'), FALSE);
                                        break;
                                    case 4 :
                                        /* On construit d'abord la liste des Départements couverts par cette agence */
                                        $tab_zone = tab_zcc_age_open(valsession('code_log'), FALSE);
                                        break;
                                    default :
                                        break;
                                }
                                if (count($tab_zone) > 0) {
                                    /* On construit ensuite (pour le select) la liste des Départements trouvés */
                                    $rech = '';
                                    $rech = 'SELECT * FROM `' . TBDEP . '` WHERE';
                                    foreach ($tab_zone as $value) {
                                        $tab_value = explode('_', $value);
                                        $rech .= " (dep_code='" . $tab_value[0] . "' AND dep_codepays='" . $tab_value[1] . "') OR";
                                    }
                                    // Suppression du dernier 'OR'
                                    $rech = substr($rech, 0, -3);
                                    $rech .= ' ORDER BY dep_code';

                                    // On cree le resultat
                                    if ($rech <> '') {
                                        $rows = $db->get_results($rech, ARRAY_A);
                                        if ($rows) {
                                            foreach ($rows as $row) {
                                                $row = encode_str($row);
                                                extract($row);
                                                $lst_zone[] = [$dep_code, $dep_code . ' (' . $dep_nom . ')'];
                                            }
                                        }
                                    }
                                }
                                close_database();
                                cre_select('dep', 'dep', $lst_zone, $cli_dep, '', _('-- Faites votre choix --'), 1, FALSE, '-1', _('-- Inconnu --'));
                                if (valsession('niv_log') > 1) {
                                    echo '<div class="annot_petit_it">';
                                    if (CheckNivLog('3-4')) {
                                        echo '(' . _('Départements couverts par votre agence') . ')';
                                    } else {
                                        echo '(' . _('Départements couverts par les agences') . ')';
                                    }
                                    echo '</div>';
                                }
                                ?>
                            </td>
                        </tr>
                        <tr>
                            <td class="rubfrm" id="f_ville" align="right"><?php echo _('Ville'); ?></td>
                            <td>
                                <?php
                                // Création de la liste des villes
                                $rows = give_rows_villes($cli_dep, $cli_codepays);
                                cre_select_tab('ville', 'ville', $rows, 'villes_id', 'villes_nom', 'villes_cp', $cli_ville, '', _('-- Faites votre choix --'), 1, FALSE, '-1', _('-- Inconnu --'));
                                ?>
                            </td>
                        </tr>
                        <?php
                        if (valsession('niv_log') >= 3) {
                            ?>
                            <tr>
                                <td class="rubfrm" id="f_codeadev" align="right"><?php echo _('Devise'); ?></td>
                                <td>
                                    <?php
                                    // Création de la liste des devises
                                    $rows = give_rows_devises();
                                    cre_select_tab('codeadev', 'codeadev', $rows, 'dev_codea', 'dev_nom', 'dev_codea', $cli_codeadev, '', _('-- Faites votre choix --'));
                                    ?>
                                </td>
                            </tr>
                            <?php
                        }
                        ?>
                        <tr>
                            <td class="rubfrm" id="f_telf" align="right"><?php echo _('Téléphone Fixe'); ?> </td>
                            <td>
                                <input name="telf" type="text" id="telf" value="<?php echo $cli_telf ?>" size="20"
                                       maxlength="20">
                                <img src="../img/oblig.png" align="absmiddle"
                                     alt="<?php echo _('Champ obligatoire'); ?>">
                            </td>
                        </tr>
                        <tr>
                            <td class="rubfrm" id="f_fax" align="right"><?php echo _('Télécopieur'); ?></td>
                            <td>
                                <input name="fax" type="text" id="fax" value="<?php echo $cli_fax ?>" size="20"
                                       maxlength="20">
                            </td>
                        </tr>
                        <tr>
                            <td class="rubfrm" id="f_telp" align="right"><?php echo _('Téléphone portable'); ?></td>
                            <td>
                                <input name="telp" type="text" id="telp" value="<?php echo $cli_telp ?>" size="20"
                                       maxlength="20">
                            </td>
                        </tr>
                        <tr>
                            <td class="rubfrm" id="f_email" align="right"><?php echo _('Email'); ?></td>
                            <td>
                                <input name="email" type="text" id="email" value="<?php echo $cli_email ?>" size="50"
                                       maxlength="50">
                                <?php
                                if (($td == 'edit') AND (valsession('niv_log') >= 3)) {
                                    ?>
                                    <a href="mailto:<?php echo $cli_email ?>"><img src="../img/mail.png"
                                                                                   title="<?php echo _('Envoyer e-mail'); ?>"
                                                                                   border="0"
                                                                                   align="absmiddle"></a>
                                    <?php
                                }
                                if (CheckNivLog('2') OR (CheckNivLog('1') AND ($cli_prev == 0))) {
                                    echo ' <img src="../img/oblig.png" align="absmiddle" alt="' . _('Champ obligatoire') . '">';
                                }
                                ?>
                            </td>
                        </tr>
                        <tr>
                            <td class="rubfrm" id="f_mess" align="right"><?php echo _('Messagerie'); ?></td>
                            <td>
                                <input name="mess" type="text" id="mess" value="<?php echo $cli_mess ?>" size="50"
                                       maxlength="50">
                            </td>
                        </tr>
                        <?php
                        if (valsession('niv_log') >= 3) {
                            ?>
                            <tr>
                                <td height="37" class="rubfrm" id="f_prev"
                                    align="right"><?php echo _('Prévenir par'); ?></td>
                                <td>
                                    <?php
                                    echo '<div id="typ_prev">';
                                    foreach ($prev_client as $key => $value) {
                                        echo '<input type="radio" name="prev" id="prev" style="background-color : #FFFFFF;" value="' . $key . '"';
                                        if ($key == (int)$cli_prev) {
                                            echo ' checked';
                                        }
                                        echo '>';
                                        echo ' ' . $value . ' ';
                                        if ($key <> (count($prev_client) - 1)) {
                                            echo '/';
                                        }
                                    }
                                    echo ' <img src="../img/oblig.png" align="absmiddle" alt="' . _('Champ obligatoire') . '">';
                                    echo '</div>';
                                    ?>
                                    <br/>
                    <span
                        class="annot_petit_it"><?php echo _('Pour création des comptes, interventions closes, et créations contrats'); ?></span>
                                </td>
                            </tr>
                            <?php
                        }
                        ?>
                    </table>
                </div>
                <?php
                if (valsession('niv_log') >= 3) {
                    echo '<div id="cli_cpta">';

                    echo '<table width="100%"  border="0">';
                    echo '<tr>';
                    echo '<td width="160" class="rubfrm" id="f_rcs" align="right">' . _('Siret') . '</td>';
                    echo '<td>';
                    echo '<input name="rcs" type="text" id="rcs" value="' . $cli_rcs . '" size="50">';
                    echo '</td>';
                    echo '</tr>';
                    echo '<tr>';
                    echo '<td class="rubfrm" id="f_ape" align="right">' . _('APE') . '</td>';
                    echo '<td>';
                    echo '<input name="ape" type="text" id="ape" value="' . $cli_ape . '" size="10">';
                    echo '</td>';
                    echo '</tr>';
                    echo '<tr>';
                    echo '<td class="rubfrm" id="f_tvai" align="right">' . _('TVA intra.') . '</td>';
                    echo '<td>';
                    echo '<input name="tvai" type="text" id="tvai" value="' . $cli_tvai . '" size="50">';
                    echo '</td>';
                    echo '</tr>';
                    echo '</table>';

                    if (CheckNivLog('5-9')) {
                        echo '<table width="100%"  border="0">';
                        echo '<tr>';
                        echo '<td width="160" class="rubfrm" id="f_ccpta" align="right">' . _('Code compta') . '</td>';
                        echo '<td>';
                        echo '<input name="ccpta" type="text" id="ccpta" value="' . $cli_ccpta . '">';
                        echo '</td>';
                        echo '<td width="190" class="rubfrm" id="f_ccptasp" align="right">' . _('Code compta site principal') . '</td>';
                        echo '<td>';
                        echo '<input name="ccptasp" type="text" id="ccptasp" value="' . $cli_ccptasp . '">';
                        echo '</td>';
                        echo '</tr>';
                        echo '</table>';
                    }


                    if (CheckNivLog('4-5-9')) {
                        echo '<table width="100%"  border="0">';
                        echo '<tr>';
                        echo '<td width="160" class="rubfrm" id="f_cpta" align="right">' . _('Comptabilité') . '</td>';
                        echo '<td>';
                        cre_select('cpta', 'cpta', $niv_cpta, $cli_cpta);
                        echo '</td>';
                        echo '</tr>';
                        echo '<tr>';
                        echo '<td class="rubfrm" id="f_mfact" align="right">' . _('Mode de facturation') . '</td>';
                        echo '<td>';
                        cre_select('mfact', 'mfact', $typ_fact, $cli_modfact);
                        echo '</td>';
                        echo '</tr>';
                        echo '</table>';
                    } else {
                        echo '<input name="cpta" type="hidden" id="cpta" value="' . $cli_cpta . '" >';
                        echo '<input name="mfact" type="hidden" id="mfact" value="' . $cli_modfact . '">';
                    }
                    echo '</div>';

                    echo '<div id="cli_note">';
                    echo '<table width="100%"  border="0">';
                    if (CheckNivLog('5-9')) {
                        echo '<tr>';
                        echo '<td width="160" class="rubfrm" id="f_notaa" align="right">' . _('Notes administration') . '</td>';
                        echo '<td>';
                        echo '<textarea name="notaa" rows="5" id="notaa">' . $cli_notaa . '</textarea>';
                        echo '</td>';
                        echo '</tr>';
                    }
                    echo '<tr>';
                    echo '<td width="160" class="rubfrm" id="f_notat" align="right">' . _('Notes techniques') . '</td>';
                    echo '<td>';
                    echo '<textarea name="notat" rows="5" id="notat">' . $cli_notat . '</textarea>';
                    echo '</td>';
                    echo '</tr>';
                    echo '</table>';
                    echo '</div>';
                }
                ?>

                <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') . '">';
                            if (((int)$cli_cpta <> 3) AND (valsession('niv_log') >= 3)) {
                                echo '<input name="int" type="button" class="bton_std" id="int" value="' . _('Enregistrer & Saisir Intervention') . '">';
                            }
                            break;
                        case 'del' :
                            if (($td == 'del') AND (valsession('niv_log') >= 3)) {
                                echo '<input name="del" type="submit" class="bton_std" id="del" value="' . _('Supprimer') . '">';
                                echo '<input name="annul" type="button" class="bton_std" id="annul" value="' . _('Annuler') . '">';
                            }
                            break;
                    }
                    ?>
                </p>
        </form>
        <?php
        // On n'alerte sur le client que si on est en niveau "technicien" ou supérieur
        if (valsession('niv_log') >= 3) {
            if (($td == 'edit') AND (exist_rpbm_actif('add', $cli_code, '') == TRUE)) {
                $msg = _('Il y a des problèmes non affectés sur ce compte client') . '<br />' . _('Voir dans le relevé de parc');
                exec_func_js("warn_txt('" . str_escape($msg) . "',3000)");
            }
        }
    } else {
        if (valsession('niv_log') >= 5) {
            if (nb_ccat() == 0) {
                pop_ret_auto(_('Aucune catégorie de client'), 'warn', 'cat_lst.php');
            }

            if (nb_civ() == 0) {
                pop_ret_auto(_('Aucune civilité'), 'warn', 'civ_lst.php');
            }

            if (nb_fonc() == 0) {
                pop_ret_auto(_('Aucune fonction'), 'warn', 'fonc_lst.php');
            }

            if (nb_age_actives() == 0) {
                pop_ret_auto(_('Aucune agence active'), 'warn', 'age_lst.php');
            }
        } else {
            pop_ret_auto(_("SMI n'a pas encore été totalement configuré") . '<br />' . _("Merci de contacter l'administrateur ou le centre de gestion"), 'warn', 'index.php');
        }
    }
} else {
    pop_ret_auto(_('Problème de paramètres'), 'warn', 'index.php');
}
include_once('pied.php');
?>
</body>
</html>