<?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/fic_droits.inc.php");
include_once("../inc/fic_zc.inc.php");
include_once("../inc/func.inc.php");
include_once("../inc/func_date.inc.php");
include_once("../inc/func_geo.inc.php");
include_once("../inc/func_txt.inc.php");
include_once("../inc/lst.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['ca'];

if (@$_SESSION["niv_log"] == 4)
    $coderech = @$_SESSION["code_log"];

$pbm_age = FALSE;
$nbtecs = 0;

if (@$_SESSION["niv_log"] <= 3)
    $pbm_age = TRUE;

if ($coderech <> "") {
    $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);

    // vérification qu'il existe bien des techniciens et nombre de ceux-ci
    $rech = "SELECT COUNT(*) FROM `" . TBTEC . "` WHERE tec_codeage = '" . $db->escape($coderech) . "'";
    $nbtecs = $db->get_var($rech);

    // Récupération des informations agence
    $rech = "SELECT * FROM `" . TBAGE . "` WHERE age_code = '" . $db->escape($coderech) . "'";
    $row = $db->get_row($rech, ARRAY_A);
    if ($row) {
        $row = encode_str($row);
        extract($row);
    } else
        $pbm_age = TRUE;

    $db->disconnect();
} else
    $pbm_age = 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 Agence"); ?></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_age == FALSE) {
    entimpfic(_("FICHE AGENCE"));
    ?>
    <table class="Ftable" width="740" border="0">
    <?PHP
    if (@$_SESSION["niv_log"] >= 5) {
        ?>
        <tr>
            <td class="rubNormal" id="f_code" align="right"><?PHP echo _("Ouverture ?"); ?></td>
            <td width="62%">
                <?PHP
                if ($age_ouvert == 1)
                    echo _("Ouverte");
                else
                    echo _("Fermée");
                ?>
            </td>
        </tr>
    <?PHP
    }
    ?>
    <tr>
        <td width="21%" class="rubNormal" id="f_code" align="right"><?PHP echo _("Code"); ?></td>
        <td>
            <?PHP
            echo $age_code;
            ?>
        </td>
    </tr>
    <tr>
        <td height="21" class="rubNormal" id="f_logo" align="right"><?PHP echo _("Logo"); ?></td>
        <td>
            <?PHP
            echo "<div align=\"left\">";
            echo "<img src=\"" . $chemin_logos . "/log" . strtolower($age_code) . ".png" . "\"><br />";
            echo "</div>";
            ?>
        </td>
    </tr>
    <tr>
        <td width="21%" class="rubNormal" id="f_nom" align="right"><?PHP echo _("Nom"); ?></td>
        <td><?PHP echo $age_nom; ?></td>
    </tr>
    <tr>
        <td class="rubNormal" id="f_rcs" align="right"><?PHP echo _("Siret"); ?></td>
        <td><?PHP echo $age_rcs ?></td>
    </tr>
    <tr>
        <td class="rubNormal" id="f_rcs" align="right"><?PHP echo _("APE"); ?></td>
        <td><?PHP echo $age_ape ?></td>
    </tr>
    <tr>
        <td class="rubNormal" id="f_rcs" align="right"><?PHP echo _("TVA intra."); ?></td>
        <td><?PHP echo $age_tvai ?></td>
    </tr>
    <tr>
        <td class="rubNormal" id="f_tcom" align="right"><?PHP echo _("Tribunal com."); ?></td>
        <td><?PHP echo $age_tcom ?></td>
    </tr>
    <tr>
        <td width="21%" class="rubNormal" id="f_adr1" align="right"><?PHP echo _("Adresse"); ?></td>
        <td><?PHP echo $age_adr1 ?></td>
    </tr>
    <tr>
        <td width="21%" class="rubNormal" id="f_adr2" align="right"><?PHP echo _("Adresse (2)"); ?></td>
        <td><?PHP echo $age_adr2 ?></td>
    </tr>
    <tr>
        <td width="21%" class="rubNormal" id="f_ville" align="right"><?PHP echo _("Code Postal"); ?></td>
        <td>
            <?PHP
            // Affichage du Code Postal
            echo Retournecp_Id($age_ville, TRUE);
            ?>
        </td>
    </tr>
    <tr>
        <td width="21%" class="rubNormal" id="f_ville" align="right"><?PHP echo _("Ville"); ?></td>
        <td>
            <?PHP
            // Affichage de la ville
            echo Retourneville_Id($age_ville, TRUE);
            ?>
        </td>
    </tr>
    <tr>
        <td class="rubNormal" id="f_pays" align="right"><?PHP echo _("Pays"); ?></td>
        <td>
            <?PHP
            // Affichage du pays
            echo Retournepays($age_codepays, TRUE);
            ?>
        </td>
    </tr>
    <tr>
        <td class="rubNormal" id="f_zone" align="right"><?PHP echo _("Zone Chalandise"); ?></td>
        <td>
            <?PHP
            $tab_zcc = tab_zcc_age_open_full($age_code, TRUE);
            foreach ($tab_zcc as $value) {
                echo $value . "<br />";
            }
            ?>
        </td>
    </tr>
    <tr>
        <td width="21%" class="rubNormal" id="f_telf" align="right"><?PHP echo _("Téléphone Fixe"); ?> </td>
        <td>
            <?PHP
            echo $age_telf . "<br />";
            echo $age_txttelf;
            ?>
        </td>
    </tr>
    <tr>
        <td width="21%" class="rubNormal" id="f_fax" align="right"><?PHP echo _("Télécopieur"); ?></td>
        <td>
            <?PHP
            echo $age_fax . "<br />";
            echo $age_txtfax;
            ?>
        </td>
    </tr>
    <tr>
        <td class="rubNormal" id="f_web" align="right"><?PHP echo _("Site Web"); ?></td>
        <td><?PHP echo $age_web ?></td>
    </tr>
    <tr>
        <td class="rubNormal" id="f_heures" align="right"><?PHP echo _("Horaires"); ?></td>
        <td><?PHP echo $age_heures ?></td>
    </tr>
    <tr>
        <td class="rubNormal" id="f_heures" align="right"><?PHP echo _("Entête"); ?></td>
        <td>
            <?PHP
            echo formatetxt($age_txtent);
            ?>
        </td>
    </tr>
    <tr>
    <td colspan="2">&nbsp;</td>
    </tr>
    <tr>
        <td colspan="2" class="rubNormal" id="f_web" align="center"><?PHP echo _("Responsable d'agence"); ?></td>
    </tr>
    <tr>
        <td class="rubNormal" id="f_rcivil" align="right"><?PHP echo _("Civilité"); ?></td>
        <td>
            <?PHP
            // Affichage de la civilité
            $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
            $rech = "SELECT civ_desc FROM `" . TBCIV . "` WHERE civ_code = '" . $db->escape($age_resp_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_rprenom" align="right"><?PHP echo _("Prénom"); ?></td>
        <td><?PHP echo $age_resp_prenom ?></td>
    </tr>
    <tr>
        <td class="rubNormal" id="f_rnom" align="right"><?PHP echo _("Nom"); ?></td>
        <td><?PHP echo $age_resp_nom ?></td>
    </tr>
    <tr>
        <td class="rubNormal" id="f_rtelf" align="right"><?PHP echo _("Tel. Fixe"); ?></td>
        <td><?PHP echo $age_resp_telf ?></td>
    </tr>
    <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
    </tr>
    <tr>
        <td colspan="2" class="rubNormal" align="center"><span class="annot_gras_it"><?PHP echo _("Emails"); ?></span></td>
        <td width="17%">
    </tr>
    <tr>
        <td width="21%" class="rubNormal" id="f_email" align="right"><?PHP echo _("Général"); ?></td>
        <td><?PHP echo $age_email ?>
            <span class="annot_std_it">(<?PHP echo _("Pour contacts clients"); ?>)</span>
        </td>
    </tr>
    <tr>
        <td width="21%" class="rubNormal" id="f_emaild" align="right"><?PHP echo _("Direction"); ?></td>
        <td><?PHP echo $age_emaild ?></td>
    </tr>
    <tr>
        <td width="21%" class="rubNormal" id="f_emailc" align="right"><?PHP echo _("Comptabilité"); ?></td>
        <td><?PHP echo $age_emailc ?></td>
    </tr>
    <tr>
        <td width="21%" class="rubNormal" id="f_emailt" align="right"><?PHP echo _("Technique"); ?></td>
        <td><?PHP echo $age_emailt ?></td>
    </tr>
    <tr>
        <td width="21%">&nbsp;</td>
        <td>&nbsp;</td>
    </tr>
    <?PHP
    if (@$_SESSION["niv_log"] >= 5) {
        ?>
        <tr>
            <td width="21%" class="rubNormal" id="f_nota" align="right"><?PHP echo _("Notes"); ?></td>
            <td><?PHP
                echo "<span class=\"txtnotes\">";
                echo formatetxt($age_nota);
                echo "</span>";
                ?>
            </td>
        </tr>
        <tr>
            <td width="21%">&nbsp;</td>
            <td>&nbsp;</td>
        </tr>
        <tr>
            <td width="21%" class="rubNormal" id="f_factures" align="right"><?PHP echo _("Emet ses factures"); ?></td>
            <td><?PHP echo $non_oui[$age_fact]; ?></td>
        </tr>
    <?PHP
    }
    ?>
    </table>

<?PHP
if ($nbtecs <> 0) {
    compimpfic(_("TECHNICIENS"));

    $en_vacances = FALSE;
    $parti = FALSE;

    $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
    $rech = "SELECT * FROM `" . TBTEC . "` WHERE tec_codeage='" . $db->escape($coderech) . "' ORDER by tec_nom";

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

    // *** Affichage de la table
    echo "<table border=\"0\" width=\"800\">\n";

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

    if ($rows) {
        foreach ($rows as $row) {
            $row = encode_str($row);
            $t_en_vacances = FALSE;
            $t_parti = FALSE;

            echo "<tr>";

            echo "<td>" . $row["tec_code"];

            // CREATION d'un code en cas de congés
            if ((comp_date($row["tec_congd"], $datea) == TRUE) AND (comp_date($datea, $row["tec_congf"]) == TRUE)) {
                $en_vacances = TRUE;
                $t_en_vacances = TRUE;
                echo " (V";
            }

            // CREATION d'un code si le technicien n'est plus salarié
            if ($row["tec_out"] == TRUE) {
                $parti = TRUE;
                $t_parti = TRUE;
                if ($t_en_vacances == FALSE)
                    echo " (";
                else
                    echo "/";
                echo "S";
            }

            if (($t_en_vacances == TRUE) OR ($t_parti == TRUE))
                echo ")";
            echo "</td>\n";
            echo "<td>" . $row["tec_prenom"] . "</td>\n";
            echo "<td>" . $row["tec_nom"] . "</td>\n";
            echo "<td>" . $row["tec_telf"] . "</td>\n";
            echo "<td>" . $row["tec_telp"] . "</td>\n";
            echo "<td>";
            echo $row["tec_email"];
            echo "</td>\n";

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

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

    $db->disconnect();

    echo "<br />";
    echo "<div align=\"center\">";
    if ($parti == TRUE)
        echo "S : N'est plus salarié(e)";
    if ($en_vacances == TRUE) {
        if ($parti == TRUE)
            echo " / ";
        echo "V : En vacances";
    }
    echo "</div>";
}
}
else
{
?>
    <script type="text/javascript">
        <!--
        window.close();
        //-->
    </script>
<?PHP
}
?>
</body>
</html>