<?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/func.inc.php');
include_once('../inc/func_geo.inc.php');
include_once('../inc/func_txt.inc.php');
include_once('../inc/lst.inc.php');
include_once('../inc/fic_age.inc.php');
include_once('../inc/fic_cli.inc.php');
include_once('../inc/fic_droits.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();
$_GET = clean_str($_GET);

$nbcontacts = 0;

$coderech = $_GET['cc'];

if (CheckNivLog('1')) {
    $coderech = valsession('code_log');
}

$pbm_cli = FALSE;

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

    // Récupération des informations clients

    // Récupération des informations clients
    $row = lit_enr_cli($coderech, TRUE);
    if (is_array($row)) {
        $row = encode_str($row);
        extract($row);

        // Contrôle qu'une agence n'essaye pas de "hacker" un client
        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;
    }
} else {
    $pbm_cli = TRUE;
}
?>
<!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 _('Impression Fiche Client'); ?></title>

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

    <script type="text/javascript">
        <!--
        function init_all() {
            init_Body();
            warn_print(2);
        }

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

</head>

<body>

<?php
if ($pbm_cli == FALSE) {
    entimpfic(_('FICHE CLIENT'));
    ?>
    <table class="Ftable" width="100%" border="0">
        <tr>
            <td width="25%" class="rubNormal" id="f_codecli"><?php echo _('Code Client'); ?></td>
            <td width="75%"><?php echo $cli_code ?></td>
        </tr>
        <?php
        if (valsession('niv_log') >= 3) {
            ?>
            <tr>
                <td class="rubNormal" id="f_cat"><?php echo _('Type'); ?></td>
                <td>
                    <?php
                    for ($i = 0; $i < 3; $i++) {
                        if ($i == $cli_type) {
                            echo $typ_client[$i];
                        }
                    }
                    ?>
                </td>
            </tr>
            <tr>
                <td width="16%" class="rubNormal" id="f_cat"><?php echo _('Catégorie'); ?></span></td>
                <td width="84%">
                    <?php
                    // Affichage de la catégorie
                    $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST, 'utf8');
                    $rech = 'SELECT cat_desc FROM `' . TBCCAT . "` WHERE cat_code = '" . $cli_cat . "'";
                    $row = $db->get_row($rech, ARRAY_A);
                    if ($row) {
                        extract($row);
                        echo $cat_desc;
                    }
                    close_database();
                    ?>
                </td>
            </tr>
            <?php
        }
        ?>
        <tr>
            <td width="16%" class="rubNormal" id="f_ste"><?php echo _('Société'); ?></td>
            <td width="84%"><?php echo $cli_ste ?></td>
        </tr>
        <tr>
            <td class="rubNormal" id="f_rcs"><?php echo _('Siret'); ?></td>
            <td><?php echo $cli_rcs ?></td>
        </tr>
        <tr>
            <td class="rubNormal" id="f_ape">APE</td>
            <td><?php echo $cli_ape ?></td>
        </tr>
        <tr>
            <td class="rubNormal" id="f_tvai">TVA intra.</td>
            <td><?php echo $cli_tvai ?></td>
        </tr>
        <tr>
            <td width="16%" class="rubNormal" id="f_civil"><?php echo _('Civilité'); ?></td>
            <td width="84%">
                <?php
                // Affichage de la civilité
                $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST, 'utf8');
                $rech = 'SELECT civ_desc FROM `' . TBCIV . "` WHERE civ_code = '" . $cli_civilite . "'";
                $row = $db->get_row($rech, ARRAY_A);
                if ($row) {
                    extract($row);
                    echo $civ_desc;
                }
                close_database();
                ?>
            </td>
        </tr>
        <tr>
            <td class="rubNormal" id="f_prenom"><?php echo _('Prénom'); ?></td>
            <td><?php echo $cli_prenom ?></td>
        </tr>
        <tr>
            <td class="rubNormal" id="f_nom"><?php echo _('Nom'); ?></td>
            <td><?php echo $cli_nom ?></td>
        </tr>
        <tr>
            <td class="rubNormal" id="f_adr1"><?php echo _('Adresse'); ?></td>
            <td><?php echo $cli_adr1 ?></td>
        </tr>
        <tr>
            <td class="rubNormal" id="f_adr2"><?php echo _('Adresse (2)'); ?></td>
            <td><?php echo $cli_adr2 ?></td>
        </tr>
        <tr>
            <td class="rubNormal" id="f_cp"><?php echo _('Code Postal'); ?></td>
            <td>
                <?php
                echo Retournecp_Id($cli_ville, TRUE);
                ?>
            </td>
        </tr>
        <tr>
            <td class="rubNormal" id="f_ville"><?php echo _('Ville'); ?></td>
            <td>
                <?php
                echo Retourneville_Id($cli_ville, TRUE);
                ?>
            </td>
        </tr>
        <tr>
            <td class="rubNormal" id="f_pays"><?php echo _('Pays'); ?></td>
            <td>
                <?php
                // Affichage du pays
                echo Retournepays($cli_codepays, TRUE);
                ?>
            </td>
        </tr>
        <tr>
            <td class="rubNormal" id="f_telf"><?php echo _('Téléphone Fixe'); ?> </td>
            <td><?php echo $cli_telf ?></td>
        </tr>
        <tr>
            <td class="rubNormal" id="f_fax"><?php echo _('Télécopieur'); ?></td>
            <td><?php echo $cli_fax ?></td>
        </tr>
        <tr>
            <td class="rubNormal" id="f_telp"><?php echo _('Téléphone portable'); ?></td>
            <td><?php echo $cli_telp ?>
            </td>
        </tr>
        <tr>
            <td class="rubNormal" id="f_email"><?php echo _('Email'); ?></td>
            <td><?php echo $cli_email ?></td>
        </tr>
        <tr>
            <td class="rubNormal" id="f_mess"><?php echo _('Messagerie'); ?></td>
            <td><?php echo $cli_mess ?></td>
        </tr>
        <?php
        if (valsession('niv_log') >= 5) {
            ?>
            <tr>
                <td class="rubNormal" id="f_notaa"><?php echo _('Notes Administration'); ?></td>
                <td>
                    <?php
                    echo '<span class="txtnotes">';
                    echo formatetxt($cli_notaa);
                    echo '</span>';
                    ?>
                </td>
            </tr>
            <?php
        }

        if (valsession('niv_log') >= 3) {
            ?>
            <tr>
                <td height="37" class="rubNormal" id="f_notat">Notes Techniciens</td>
                <td>
                    <?php
                    echo '<span class="txtnotes">';
                    echo formatetxt($cli_notat);
                    echo '</span>';
                    ?>
                </td>
            </tr>
            <tr>
                <td class="rubNormal" id="f_cpta"><?php echo _('Comptabilité'); ?></td>
                <td><?php echo $mess_cpta[$cli_cpta]; ?></td>
            </tr>
            <tr>
                <td class="rubNormal" id="f_mfact">Mode Facturation</td>
                <td><?php echo $typ_fact[$cli_modfact]; ?></td>
            </tr>
            <tr>
                <td class="rubNormal" id="f_prev"><?php echo _('Prévenir par'); ?></td>
                <td><?php echo $prev_client[$cli_prev]; ?></td>
            </tr>
            <?php
        }
        ?>
    </table>

    <?php
    if ($nbcontacts <> 0) {
        compimpfic('CONTACTS');

        $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST, 'utf8');
        $rech = 'SELECT * FROM `' . TBCCLI . "` WHERE ccli_codecli='" . $db->escape($coderech) . "' ORDER BY ccli_nom";

        $rows = $db->get_results($rech, ARRAY_A);

        // *** Affichage de la table
        echo '<table border="1" width="100%">';

        // création entête
        titimplst($ccli_titre_col);

        if ($rows) {
            foreach ($rows as $row) {
                $row = encode_str($row);
                echo '<tr>';
                echo '<td class="annot_petit">';
                $rech2 = 'SELECT fonc_desc FROM `' . TBFONC . "` WHERE `fonc_code`= '" . $row['ccli_codefonc'] . "'";
                $row2 = $db->get_row($rech2, ARRAY_A);
                if ($row2) {
                    extract($row2);
                    echo $fonc_desc;
                } else {
                    echo '&nbsp;';
                }
                echo '</td>';
                echo '<td class="annot_petit">';
                echo $row['ccli_civilite'] . ' ' . $row['ccli_nom'] . ' ' . $row['ccli_prenom'];
                echo '</td>';
                echo '<td class="annot_petit">' . $row['ccli_telf'] . '</td>';
                echo '<td class="annot_petit">' . $row['ccli_fax'] . '</td>';
                echo '<td class="annot_petit">' . $row['ccli_telp'] . '</td>';
                echo '<td class="annot_petit">' . $row['ccli_email'] . '</td>';
                echo '<td class="annot_petit">' . $row['ccli_mess'] . '</td>';

                echo '</tr>';
            }
        }

        echo '</table>';
        // *** Fin affichage de la table

        close_database();
        if (nb_scli($coderech, '', TRUE) <> 0) {
            compimpfic(_('SITES'));

            $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST, 'utf8');
            $rech = 'SELECT * FROM `' . TBSCLI . "` WHERE scli_codecli='" . $coderech . "' ORDER BY scli_ste";

            $rows = $db->get_results($rech, ARRAY_A);

            // *** Affichage de la table
            echo '<table border="1" width="100%">';

            // création entête
            titimplst($scli_titre_col);

            if ($rows) {
                foreach ($rows as $row) {
                    echo '<tr>';
                    echo '<td class="annot_petit">';
                    echo '<strong>' . $row['scli_ste'] . '</strong><br />';
                    echo $row['scli_adr1'] . '<br />';
                    if ($row['scli_adr2'] <> '') {
                        echo $row['scli_adr2'] . '<br />';
                    }
                    echo Retournecp_Id($row['scli_ville'], FALSE) . ' ' . Retourneville_Id($row['scli_ville'], FALSE) . '<br />';
                    echo '</td>';
                    echo '<td class="annot_petit">' . $row['scli_telf'] . '</td>';
                    echo '<td class="annot_petit">' . $row['scli_fax'] . '</td>';
                    echo '<td class="annot_petit">' . $row['scli_email'] . '</td>';
                    echo '<td class="annot_petit">';
                    echo $row['scli_rcivil'] . ' ' . $row['scli_rprenom'] . ' ' . $row['scli_rnom'] . '<br />';
                    echo _('Tel.') . ' ' . $row['scli_rtelf'] . ' / ' . _('Fax') . ' ' . $row['scli_rfax'] . '<br />';
                    echo _('Por.') . ' ' . $row['scli_rtelp'] . ' / ' . _('Mail') . ' ' . $row['scli_remail'] . '<br />';
                    echo '</td>';

                    echo '</tr>';
                }
            }

            echo '</table>';
            // *** Fin affichage de la table

            close_database();
        }
    }
} else {
    pop_ret_auto(_('Problème de paramètres'), 'warn', 'index.php');
}
?>
</body>
</html>
