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


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

include_once("../inc/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(@$_SESSION["code_log"]);
// Variables Formulaire
fix_magic_quotes();
$_GET = clean_str($_GET);

$coderech = $_GET['cc'];

if (@$_SESSION["niv_log"] == 1)
    $coderech = @$_SESSION["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 (@$_SESSION["niv_log"]) {
            case 3 :
            case 4 :
                if (client_age_ok($cli_code, @$_SESSION["code_age"], TRUE) == FALSE)
                    $pbm_cli = TRUE;
                break;
            default :
                break;
        }
    } else
        $pbm_cli = TRUE;
} else
    $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 (@$_SESSION["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);
                    $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;
                    }
                    $db->disconnect();
                    ?>
                </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);
                $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;
                }
                $db->disconnect();
                ?>
            </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 (@$_SESSION["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 (@$_SESSION["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);
        $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%\">\n";

        // 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>\n";
                echo "<td class=\"annot_petit\">";
                echo $row["ccli_civilite"] . " " . $row["ccli_nom"] . " " . $row["ccli_prenom"];
                echo "</td>\n";
                echo "<td class=\"annot_petit\">" . $row["ccli_telf"] . "</td>\n";
                echo "<td class=\"annot_petit\">" . $row["ccli_fax"] . "</td>\n";
                echo "<td class=\"annot_petit\">" . $row["ccli_telp"] . "</td>\n";
                echo "<td class=\"annot_petit\">" . $row["ccli_email"] . "</td>\n";
                echo "<td class=\"annot_petit\">" . $row["ccli_mess"] . "</td>\n";

                echo "</tr>\n";
            }
        }

        echo "</table>\n";
        // *** Fin affichage de la table

        $db->disconnect();
        if (nb_scli($coderech, "", TRUE) <> 0) {
            compimpfic("SITES");

            $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
            $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%\">\n";

            // 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>\n";
                    echo "<td class=\"annot_petit\">" . $row["scli_telf"] . "</td>\n";
                    echo "<td class=\"annot_petit\">" . $row["scli_fax"] . "</td>\n";
                    echo "<td class=\"annot_petit\">" . $row["scli_email"] . "</td>\n";
                    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>\n";

                    echo "</tr>\n";
                }
            }

            echo "</table>\n";
            // *** Fin affichage de la table

            $db->disconnect();
        }
    }
} else
    pop_ret_auto(_("Problème de paramètres"), 'warn', "index.php");
?>
</body>
</html>
