<?php
/****************************************************************************************
SMI (Services Maintenance Interventions) est une gestion libre de maintenance et de SAV

Version 1.0.2

Copyright (C) 2006-2015  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
 ****************************************************************************************/

session_start();

require_once("../lib/gettext/gettext.inc");
include_once("../inc/config.inc.php");
include_once("../inc/func_log.inc.php");
if (CheckURLLog(FALSE) == FALSE) header("Location: ../index.php");
if (CheckNivLog("5-9") == FALSE) header("Location: ../index.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/fic_do.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();
$_POST = clean_str($_POST);

$txt_stat_do = [
    1 => _("Nombre de créations de clients sur une période donnée"),
    2 => _("Nombre de créations d'interventions sur une période donnée")];

$pbm_stat = FALSE;
$aff_stat = FALSE;
$ts = 0;
$date1 = '';
$date2 = '';

// On a choisi le type de statistique
if (@$_POST["nbutton"] == "calc") {
    $aff_stat = TRUE;

    $ts = intval($_POST['ts']);

    $do_select_tab = [];
    for ($i = 0; $i < count($_POST["do"]); $i++) {
        $do_select_tab[] = $_POST["do"][$i];
    }

    $date1 = datetomysql($_POST["date1f"]);
    $date2 = datetomysql($_POST["date2f"]);

    switch ($ts) {
        /* Nombre de créations de clients sur une période donnée */
        case 1 :
            // Analyse des données et traitements statistiques
            $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);

            /* Initialisation des totaux généraux */

            $nb_cli_crees_total = 0;
            $nb_cli_prospects_crees_total = 0;
            $nb_cli_ddeint_crees_total = 0;
            $nb_cli_inter_crees_total = 0;

            /* Calcul des totaux généraux */

            $rech = "SELECT do_code FROM `" . TBDO . "`";
            $rech .= " ORDER BY do_code";

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

            if ($rows) {
                foreach ($rows as $row) {
                    $row = encode_str($row);
                    extract($row);

                    // Détermination du nombre de clients créés par les donneurs d'ordres sur la période
                    $rech2 = "SELECT * FROM `" . TBCLI . "`";
                    $rech2 .= " WHERE cli_codecrea='" . $do_code . "'";
                    $rech2 .= " AND cli_datecrea>='" . $date1 . "' AND cli_datecrea<='" . $date2 . "'";

                    $rows2 = $db->get_results($rech2, ARRAY_A);
                    $nb_cli_crees_total = $nb_cli_crees_total + count($rows2);

                    // Détermination du nombre de clients encore prospects et créés par les donneurs d'ordres sur la période
                    $rech2 = "SELECT * FROM `" . TBCLI . "`";
                    $rech2 .= " WHERE cli_codecrea='" . $do_code . "'";
                    $rech2 .= " AND cli_type=0";
                    $rech2 .= " AND cli_datecrea>='" . $date1 . "' AND cli_datecrea<='" . $date2 . "'";

                    $rows2 = $db->get_results($rech2, ARRAY_A);
                    $nb_cli_prospects_crees_total = $nb_cli_prospects_crees_total + count($rows2);

                    // Détermination du nombre de client ayant demandé une intervention (non effectuée) et créés par les donneurs d'ordres sur la période
                    $rech2 = "SELECT * FROM `" . TBCLI . "`";
                    $rech2 .= " WHERE cli_codecrea='" . $do_code . "'";
                    $rech2 .= " AND cli_type=1";
                    $rech2 .= " AND cli_datecrea>='" . $date1 . "' AND cli_datecrea<='" . $date2 . "'";

                    $rows2 = $db->get_results($rech2, ARRAY_A);
                    $nb_cli_ddeint_crees_total = $nb_cli_ddeint_crees_total + count($rows2);

                    // Détermination du nombre total de clients ayant demandé une intervention (effectuée) et créés par les donneurs d'ordres sur la période
                    $nb_cli_inter_crees_total = $nb_cli_crees_total - $nb_cli_prospects_crees_total - $nb_cli_ddeint_crees_total;
                }
            }

            /* Traitement par donneur d'ordres */
            $rech = "SELECT * FROM `" . TBDO . "`";

            // Traitement de multiples
            if (!in_array("*", $do_select_tab)) {
                $rech .= " WHERE (";
                for ($i = 0; $i < count($do_select_tab); $i++) {
                    $rech .= " do_code='" . $do_select_tab[$i] . "' OR";
                }
                // Suppression du dernier 'OR'
                $rech = substr($rech, 0, strlen($rech) - 3);
                $rech .= ")";
            }

            $rech .= " ORDER BY do_nom";

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

            $i = 0;

            if ($nb_do_select > 0) {
                foreach ($rows as $row) {
                    $row = encode_str($row);
                    extract($row);

                    // Récupération du code donneur d'ordres
                    $code_donneur_ordres[$i] = $do_code;

                    // Détermination du nombre de clients créés par l'donneur d'ordres sur la période
                    $rech2 = "SELECT * FROM `" . TBCLI . "`";
                    $rech2 .= " WHERE cli_codecrea='" . $do_code . "'";
                    $rech2 .= " AND cli_datecrea>='" . $date1 . "' AND cli_datecrea<='" . $date2 . "'";

                    $rows2 = $db->get_results($rech2, ARRAY_A);
                    $nb_cli_crees_do[$i] = count($rows2);

                    // Détermination du nombre de clients encore prospects et créés par l'donneur d'ordres sur la période
                    $rech2 = "SELECT * FROM `" . TBCLI . "`";
                    $rech2 .= " WHERE cli_codecrea='" . $do_code . "'";
                    $rech2 .= " AND cli_type=0";
                    $rech2 .= " AND cli_datecrea>='" . $date1 . "' AND cli_datecrea<='" . $date2 . "'";

                    $rows2 = $db->get_results($rech2, ARRAY_A);
                    $nb_cli_prospects_crees_do[$i] = count($rows2);

                    // Détermination du nombre de client ayant demandé une intervention (non effectuée) et créés par les donneurs d'ordres sur la période
                    $rech2 = "SELECT * FROM `" . TBCLI . "`";
                    $rech2 .= " WHERE cli_codecrea='" . $do_code . "'";
                    $rech2 .= " AND cli_type=1";
                    $rech2 .= " AND cli_datecrea>='" . $date1 . "' AND cli_datecrea<='" . $date2 . "'";

                    $rows2 = $db->get_results($rech2, ARRAY_A);
                    $nb_cli_ddeint_crees_do[$i] = count($rows2);

                    // Détermination du nombre total de clients ayant demandé une intervention (effectuée) et créés par les donneurs d'ordres sur la période
                    $nb_cli_inter_crees_do[$i] = $nb_cli_crees_do[$i] - $nb_cli_prospects_crees_do[$i] - $nb_cli_ddeint_crees_do[$i];

                    $i++;
                }
            }
            $db->disconnect();

            $aff_stat = TRUE;

            break;

        /* Nombre de créations d'interventions sur une période donnée */
        case 2 :
            // Analyse des données et traitements statistiques
            $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);

            /* Initialisation des totaux généraux */

            $nb_int_crees_total = 0;
            $nb_int_ouv_crees_total = 0;
            $nb_int_prev_crees_total = 0;
            $nb_int_clos_crees_total = 0;

            /* Calcul des totaux généraux */

            $rech = "SELECT do_code FROM `" . TBDO . "`";
            $rech .= " ORDER BY do_code";

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

            if ($rows) {
                foreach ($rows as $row) {
                    $row = encode_str($row);
                    extract($row);

                    // Détermination du nombre d'interventions créées par les donneurs d'ordres sur la période
                    $rech2 = "SELECT * FROM `" . TBINT . "`";
                    $rech2 .= " WHERE int_codecrea='" . $do_code . "'";
                    $rech2 .= " AND int_datecrea>='" . $date1 . "' AND int_datecrea<='" . $date2 . "'";

                    $rows2 = $db->get_results($rech2, ARRAY_A);
                    $nb_int_crees_total = $nb_int_crees_total + count($rows2);

                    // Détermination du nombre d'interventions encore ouvertes et créées par les donneurs d'ordres sur la période
                    $rech2 = "SELECT * FROM `" . TBINT . "`";
                    $rech2 .= " WHERE int_codecrea='" . $do_code . "'";
                    $rech2 .= " AND int_dateprev='0000-00-00'";
                    $rech2 .= " AND int_datecrea>='" . $date1 . "' AND int_datecrea<='" . $date2 . "'";

                    $rows2 = $db->get_results($rech2, ARRAY_A);
                    $nb_int_ouv_crees_total = $nb_int_ouv_crees_total + count($rows2);

                    // Détermination du nombre d'interventions, où le client a été prévenu, et créées par les donneurs d'ordres sur la période
                    $rech2 = "SELECT * FROM `" . TBINT . "`";
                    $rech2 .= " WHERE int_codecrea='" . $do_code . "'";
                    $rech2 .= " AND int_dateprev<>'0000-00-00'";
                    $rech2 .= " AND int_datefin='0000-00-00'";
                    $rech2 .= " AND int_datecrea>='" . $date1 . "' AND int_datecrea<='" . $date2 . "'";

                    $rows2 = $db->get_results($rech2, ARRAY_A);
                    $nb_int_prev_crees_total = $nb_int_prev_crees_total + count($rows2);

                    // Détermination du nombre total d'interventions closes et créés par les donneurs d'ordres sur la période
                    $nb_int_clos_crees_total = $nb_int_crees_total - $nb_int_ouv_crees_total - $nb_int_prev_crees_total;
                }
            }

            /* Traitement par donneur d'ordres */
            $rech = "SELECT * FROM `" . TBDO . "`";

            // Traitement de multiples
            if (!in_array("*", $do_select_tab)) {
                $rech .= " WHERE (";
                for ($i = 0; $i < count($do_select_tab); $i++) {
                    $rech .= " do_code='" . $do_select_tab[$i] . "' OR";
                }
                // Suppression du dernier 'OR'
                $rech = substr($rech, 0, strlen($rech) - 3);
                $rech .= ")";
            }

            $rech .= " ORDER BY do_nom";

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

            $i = 0;

            if ($nb_do_select > 0) {
                foreach ($rows as $row) {
                    $row = encode_str($row);
                    extract($row);

                    // Récupération du code donneur d'ordres
                    $code_donneur_ordres[$i] = $do_code;

                    // Détermination du nombre d'interventions créées par l'donneur d'ordres sur la période
                    $rech2 = "SELECT * FROM `" . TBINT . "`";
                    $rech2 .= " WHERE int_codecrea='" . $do_code . "'";
                    $rech2 .= " AND int_datecrea>='" . $date1 . "' AND int_datecrea<='" . $date2 . "'";

                    $rows2 = $db->get_results($rech2, ARRAY_A);
                    $nb_int_crees_do[$i] = count($rows2);

                    // Détermination du nombre d'interventions encore ouvertes et créées par l'donneur d'ordres sur la période
                    $rech2 = "SELECT * FROM `" . TBINT . "`";
                    $rech2 .= " WHERE int_codecrea='" . $do_code . "'";
                    $rech2 .= " AND int_dateprev='0000-00-00'";
                    $rech2 .= " AND int_datecrea>='" . $date1 . "' AND int_datecrea<='" . $date2 . "'";

                    $rows2 = $db->get_results($rech2, ARRAY_A);
                    $nb_int_ouv_crees_do[$i] = count($rows2);

                    // Détermination du nombre d'interventions, o�le client a été prévenu, et créées par les donneurs d'ordres sur la période
                    $rech2 = "SELECT * FROM `" . TBINT . "`";
                    $rech2 .= " WHERE int_codecrea='" . $do_code . "'";
                    $rech2 .= " AND int_dateprev<>'0000-00-00'";
                    $rech2 .= " AND int_datefin='0000-00-00'";
                    $rech2 .= " AND int_datecrea>='" . $date1 . "' AND int_datecrea<='" . $date2 . "'";

                    $rows2 = $db->get_results($rech2, ARRAY_A);
                    $nb_int_prev_crees_do[$i] = count($rows2);

                    // Détermination du nombre total d'interventions closes et créées par les donneurs d'ordres sur la période
                    $nb_int_clos_crees_do[$i] = $nb_int_crees_do[$i] - $nb_int_ouv_crees_do[$i] - $nb_int_prev_crees_do[$i];

                    $i++;
                }
            }
            $db->disconnect();

            $aff_stat = TRUE;

            break;

        default :
            $pbm_stat = TRUE;
            break;
    }
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <title>SMI - <?PHP echo _("ESPACE PRIVE"); ?> : <?PHP echo _("Statistiques Donneurs d'ordres"); ?></title>

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

    <script language="javascript">
        <!--
        var tab_champ = [];
        //-->
    </script>

    <script type="text/javascript">
        <!--
        <?PHP
        if ($aff_stat == FALSE)
        {
        ?>
        function init_datepicker() {
            $.datepicker.setDefaults({
                closeText: "<?PHP echo _("Fermer"); ?>",
                prevText: "<?PHP echo _("Précédent"); ?>",
                nextText: "<?PHP echo _("Suivant"); ?>",
                currentText: "<?PHP echo _("Aujourd'hui"); ?>",
                monthNames: ["<?PHP echo implode('","',$lng_tmoisf); ?>"],
                monthNamesShort: ["<?PHP echo implode('","',$lng_tmoism); ?>"],
                dayNames: ["<?PHP echo implode('","',$lng_tjourf); ?>"],
                dayNamesShort: ["<?PHP echo implode('","',$lng_tjourm); ?>"],
                dayNamesMin: ["<?PHP echo implode('","',$lng_tjours); ?>"],
                weekHeader: "<?PHP echo _("Sem."); ?>",
                dateFormat: "<?PHP echo $_SESSION['date_fmtshort']; ?>",
                firstDay: 1,
                isRTL: !1,
                changeMonth: true,
                changeYear: true,
                showMonthAfterYear: !1,
                yearSuffix: "",
                showButtonPanel: true,
                showOn: "both",
                buttonImageOnly: true,
                buttonImage: "../img/calendar.png",
                buttonText: "<?PHP echo _("Calendrier"); ?>"
            });
            $("#date1f").datepicker({
                onSelect: function (datesel) {
                    $("#date1f").blur();
                    chk_datedif(datesel, this.id, '<?PHP echo $_SESSION['date_fmtshort']; ?>', true, '', '', 'date2f',false);
                }
            });
            $("#date2f").datepicker({
                onSelect: function (datesel) {
                    $("#date2f").blur();
                    chk_datedif(datesel, this.id, '<?PHP echo $_SESSION['date_fmtshort']; ?>', true, 'date1f', '', 'today',false);
                }
            });
        }
        <?PHP } ?>

        function init_all() {
            init_Body();
            <?PHP
            if ($aff_stat == TRUE)
            {
                echo "init_autohref('newstat', 'click', '', true);";
                echo "readonly_all_id('prm_stat');";
            }
            else
            {
                echo "init_datepicker();";
                echo "init_stats_do('calc','prm_stat','".$_SESSION['date_fmtshort']."',tab_champ,'','');";
                echo "init_autoraz('razdate1f','date1f','click');";
                echo "init_autoraz('razdate2f','date2f','click');";
            }
            ?>
            Focus_first();
        }

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

<body>

<?php
include_once("../inc/entete.inc.php");
?>

<p align="center"><span class="titrepage"><?PHP echo _("STATISTIQUES DONNEURS D'ORDRES"); ?></span></p>
<?PHP
if ($pbm_stat == FALSE) {
    if (nb_do() > 0) {
        if ($aff_stat == TRUE)
            cre_falselnk('', 'newstat', 'div', '', _("Autre statistique"), 'do_stat.php', '../img/stat.png', _("Autre statistique"));
?>
    <div align="center" style="margin-top: 5px; margin-bottom: 5px;">
    <form name="prm_stat" id="prm_stat" class="bord_pointilles" method="post" action="do_stat.php">
    <input name="today" type="hidden" id="today" value="<?PHP echo $datef; ?>">
    <input name="nbutton" type="hidden" id="nbutton" value="">
    <?PHP
    cre_select('ts', 'ts', $txt_stat_do, (int)$ts, '', _("-- Faites votre choix --"));
        if ($aff_stat == FALSE)
        {
        ?>
        <table width="100%" border="0">
            <tr>
                <td width="50%" align="center">
                    <?PHP echo _("Choisissez un donneur d'ordres (sélections multiples possibles)"); ?>
                    <div class="annot_petit_it"><?PHP echo "("._("Si 'Tous', les donneurs d'ordres fermés seront aussi analysés").")"; ?></div>
                </td>
            </tr>
            <tr>
                <td width="50%" align="center">
                    <?PHP
                    // Création de la liste des donneurs d'ordres actifs
                    $tab_do = give_tab_do('');
                    cre_select('do[]', 'do', $tab_do, '*', '*', _("---------- Tous ----------"), 5, TRUE);
                    ?>
                </td>
            </tr>
        </table>
        <?PHP
        } else
            echo '<br /><br />';
        ?>
        <div id = "dates">
            <span class="rubfrm" id="f_date1" style="margin-right: 5px;"><?PHP echo ' '._("Du").'... '; ?></span>
            <input name="date1f" type="text" id="date1f" size="10" value="<?PHP echo datetolocal($date1); ?>" maxlength="10" readonly>
            <?PHP
            if ($aff_stat == FALSE)
            {
                echo ' <img src="../img/oblig.png" align="absmiddle" alt="'._("Champ obligatoire").'">';
                echo ' <img src="../img/raz.png" id ="razdate2f" border="0" align="absmiddle">';
            }
            ?>
            <span class="rubfrm" id="f_date2f" style="margin-right: 5px;"><?PHP echo ' '._("Au").'... '; ?></span>
            <input name="date2f" type="text" id="date2f" size="10" value="<?PHP echo datetolocal($date1); ?>" maxlength="10" readonly>
            <?PHP
            if ($aff_stat == FALSE)
            {
                echo ' <img src="../img/oblig.png" align="absmiddle" alt="'._("Champ obligatoire").'">';
                echo ' <img src="../img/raz.png" id ="razdate2f" border="0" align="absmiddle">';
            }
            ?>
        </div>
        <?PHP
        if ($aff_stat == FALSE)
        {
            echo '<p align="center">';
            echo '<input name="calc" type="button" class="bton_std" id="calc" value="'._("Calculer").'">';
            echo '<input name="init" type="reset" class="bton_std" id="init" value="'._("Réinitialiser").'">';
            echo '</p>';
        }
        ?>
    </form>

    <?PHP
    switch ($ts)
    {
    /* Nombre de créations de clients sur une période donnée */
    case 1 :
        // Définition et entête de la table
        echo "<table class=\"Mtable\" border=\"0\" width=\"100%\" cellpadding=\"0\" cellspacing=\"0\">\n";

        echo "<th>";
        echo _("Agence");
        echo "</th>\n";
        echo "<th>";
        echo _("Total créés");
        echo "</th>\n";
        echo "<th>";
        echo _("Encore prospects");
        echo "</th>\n";
        echo "<th>";
        echo _("Attente intervention");
        echo "</th>\n";
        echo "<th>";
        echo _("Intervention");
        echo "</th>\n";

        $i = 0;

        /* données pour tous les donneurs d'ordres */

        // création de l'entête de ligne (TR)
        creetrlst($i);

        echo "<td>";
        echo "<span class=\"annot_std_it\">";
        echo _("Tous les donneurs d'ordres");
        echo "</span>";
        echo "</td>\n";
        echo "<td align=\"center\">";
        if ($nb_cli_crees_total <> 0) {
            echo "<span class=\"annot_std_it\">";
            echo $nb_cli_crees_total;
            echo "</span>";
        } else
            echo "-";
        echo "</td>\n";
        echo "<td align=\"center\">";
        if ($nb_cli_prospects_crees_total <> 0) {
            echo "<span class=\"annot_std_it\">";
            echo $nb_cli_prospects_crees_total;
            echo "</span>";
            if ($nb_cli_crees_total <> 0) {
                echo "<span class=\"annot_petit_it\">";
                echo " (" . round((($nb_cli_prospects_crees_total / $nb_cli_crees_total) * 100), 2) . "%)";
                echo "</span>";
            }
        } else
            echo "-";
        echo "</td>\n";
        echo "<td align=\"center\">";
        if ($nb_cli_ddeint_crees_total <> 0) {
            echo "<span class=\"annot_std_it\">";
            echo $nb_cli_ddeint_crees_total;
            echo "</span>";
            if ($nb_cli_crees_total <> 0) {
                echo "<span class=\"annot_petit_it\">";
                echo " (" . round((($nb_cli_ddeint_crees_total / $nb_cli_crees_total) * 100), 2) . "%)";
                echo "</span>";
            }
        } else
            echo "-";
        echo "</td>\n";
        echo "<td align=\"center\">";
        if ($nb_cli_inter_crees_total <> 0) {
            echo "<span class=\"annot_std_it\">";
            echo $nb_cli_inter_crees_total;
            echo "</span>";
            if ($nb_cli_crees_total <> 0) {
                echo "<span class=\"annot_petit_it\">";
                echo " (" . round((($nb_cli_inter_crees_total / $nb_cli_crees_total) * 100), 2) . "%)";
                echo "</span>";
            }
        } else
            echo "-";
        echo "</td>\n";

        echo "</tr>\n";

        $i++;

        /* Saut de ligne pour lisibilité */

        // création de l'entête de ligne (TR)
        creetrlst($i);

        echo "<td>";
        echo "&nbsp;";
        echo "</td>\n";
        echo "<td>";
        echo "&nbsp;";
        echo "</td>\n";
        echo "<td>";
        echo "&nbsp;";
        echo "</td>\n";
        echo "<td>";
        echo "&nbsp;";
        echo "</td>\n";
        echo "<td>";
        echo "&nbsp;";
        echo "</td>\n";

        echo "</tr>\n";

        $i++;

        if ($nb_do_select > 0) {
            for ($j = 0; $j < $nb_do_select; $j++) {
                // création de l'entête de ligne (TR)
                creetrlst($i);

                echo "<td>";
                $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
                $rech = "SELECT * FROM `" . TBDO . "` WHERE `do_code` = '" . $code_donneur_ordres[$j] . "'";
                $rows = $db->get_results($rech, ARRAY_A);
                foreach ($rows as $row) {
                    $row = encode_str($row);
                    extract($row);
                    $txt_do = $do_nom;
                }
                $db->disconnect();
                echo "<span class=\"annot_std_gras\">";
                echo $txt_do . " (" . $code_donneur_ordres[$j] . ")";
                echo "</span>";
                if ($do_ouvert == 0) {
                    echo "<span class=\"annot_petit_it\">";
                    echo " " . _("Fermée");
                    echo "</span>";
                }
                echo "<br />";
                if ($nb_cli_crees_do[$j] <> 0) {
                    echo "<span class=\"annot_petit_it\">";
                    echo "<div align=\"right\">";
                    echo _("Par rapport donneur d'ordres : ");
                    echo "<br />" . _("Par rapport total") . " : ";
                    echo "</div>";
                    echo "</span>";
                }
                echo "</td>\n";
                echo "<td align=\"center\">";
                if ($nb_cli_crees_do[$j] <> 0) {
                    echo "<span class=\"annot_std_gras\">";
                    echo $nb_cli_crees_do[$j];
                    echo "</span>";
                    if ($nb_cli_crees_total <> 0) {
                        echo "<span class=\"annot_petit_it\">";
                        echo "<br />-<br />(" . round((($nb_cli_crees_do[$j] / $nb_cli_crees_total) * 100), 2) . "%)";
                        echo "</span>";
                    }
                } else
                    echo "-";
                echo "</td>\n";
                echo "<td align=\"center\">";
                if ($nb_cli_prospects_crees_do[$j] <> 0) {
                    echo "<span class=\"annot_std_gras\">";
                    echo $nb_cli_prospects_crees_do[$j];
                    echo "</span>";
                    echo "<br />";
                    if ($nb_cli_crees_do[$j] <> 0) {
                        echo "<span class=\"annot_petit_it\">";
                        echo "(" . round((($nb_cli_prospects_crees_do[$j] / $nb_cli_crees_do[$j]) * 100), 2) . "%)";
                        echo "</span>";
                    } else
                        echo "-";
                    echo "<br />";
                    if ($nb_cli_prospects_crees_total <> 0) {
                        echo "<span class=\"annot_petit_it\">";
                        echo "(" . round((($nb_cli_prospects_crees_do[$j] / $nb_cli_prospects_crees_total) * 100), 2) . "%)";
                        echo "</span>";
                    } else
                        echo "-";
                } else
                    echo "-";
                echo "</td>\n";
                echo "<td align=\"center\">";
                if ($nb_cli_ddeint_crees_do[$j] <> 0) {
                    echo "<span class=\"annot_std_gras\">";
                    echo $nb_cli_ddeint_crees_do[$j];
                    echo "</span>";
                    echo "<br />";
                    if ($nb_cli_crees_do[$j] <> 0) {
                        echo "<span class=\"annot_petit_it\">";
                        echo " (" . round((($nb_cli_ddeint_crees_do[$j] / $nb_cli_crees_do[$j]) * 100), 2) . "%)";
                        echo "</span>";
                    } else
                        echo "-";
                    echo "<br />";
                    if ($nb_cli_ddeint_crees_total <> 0) {
                        echo "<span class=\"annot_petit_it\">";
                        echo "(" . round((($nb_cli_ddeint_crees_do[$j] / $nb_cli_ddeint_crees_total) * 100), 2) . "%)";
                        echo "</span>";
                    } else
                        echo "-";
                } else
                    echo "-";
                echo "</td>\n";
                echo "<td align=\"center\">";
                if ($nb_cli_inter_crees_do[$j] <> 0) {
                    echo "<span class=\"annot_std_gras\">";
                    echo $nb_cli_inter_crees_do[$j];
                    echo "</span>";
                    echo "<br />";
                    if ($nb_cli_crees_do[$j] <> 0) {
                        echo "<span class=\"annot_petit_it\">";
                        echo " (" . round((($nb_cli_inter_crees_do[$j] / $nb_cli_crees_do[$j]) * 100), 2) . "%)";
                        echo "</span>";
                    }
                    echo "<br />";
                    if ($nb_cli_inter_crees_total <> 0) {
                        echo "<span class=\"annot_petit_it\">";
                        echo "(" . round((($nb_cli_inter_crees_do[$j] / $nb_cli_inter_crees_total) * 100), 2) . "%)";
                        echo "</span>";
                    } else
                        echo "-";
                } else
                    echo "-";
                echo "</td>\n";

                echo "</tr>\n";

                $i++;
            }
        } else {
            // création de l'entête de ligne (TR)
            creetrlst($i);

            echo "<td>";
            echo "<span class=\"annot_petit_it\">";
            echo _("Aucun résultat à cette demande") . ".";
            echo "</span>";
            echo "</td>\n";
            echo "<td>";
            echo "&nbsp;";
            echo "</td>\n";
            echo "<td>";
            echo "&nbsp;";
            echo "</td>\n";
            echo "<td>";
            echo "&nbsp;";
            echo "</td>\n";
            echo "<td>";
            echo "&nbsp;";
            echo "</td>\n";

            echo "</tr>\n";
        }

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

    /* Nombre de créations d'interventions sur une période donnée */
    case 2 :
        // Définition et entête de la table
        echo "<table class=\"Mtable\" border=\"0\" width=\"100%\" cellpadding=\"0\" cellspacing=\"0\">\n";

        echo "<th>";
        echo _("Agence");
        echo "</th>\n";
        echo "<th>";
        echo _("Total créées");
        echo "</th>\n";
        echo "<th>";
        echo _("Ouvertes");
        echo "</th>\n";
        echo "<th>";
        echo _("Clients prévenus");
        echo "</th>\n";
        echo "<th>";
        echo _("Closes");
        echo "</th>\n";

        $i = 0;

        /* données pour toutes les donneurs d'ordres */

        // création de l'entête de ligne (TR)
        creetrlst($i);

        echo "<td>";
        echo "<span class=\"annot_std_it\">";
        echo _("Tous les donneurs d'ordres");
        echo "</span>";
        echo "</td>\n";
        echo "<td align=\"center\">";
        if ($nb_int_crees_total <> 0) {
            echo "<span class=\"annot_std_it\">";
            echo $nb_int_crees_total;
            echo "</span>";
        } else
            echo "-";
        echo "</td>\n";
        echo "<td align=\"center\">";
        if ($nb_int_ouv_crees_total <> 0) {
            echo "<span class=\"annot_std_it\">";
            echo $nb_int_ouv_crees_total;
            echo "</span>";
            if ($nb_int_crees_total <> 0) {
                echo "<span class=\"annot_petit_it\">";
                echo " (" . round((($nb_int_ouv_crees_total / $nb_int_crees_total) * 100), 2) . "%)";
                echo "</span>";
            }
        } else
            echo "-";
        echo "</td>\n";
        echo "<td align=\"center\">";
        if ($nb_int_prev_crees_total <> 0) {
            echo "<span class=\"annot_std_it\">";
            echo $nb_int_prev_crees_total;
            echo "</span>";
            if ($nb_int_crees_total <> 0) {
                echo "<span class=\"annot_petit_it\">";
                echo " (" . round((($nb_int_prev_crees_total / $nb_int_crees_total) * 100), 2) . "%)";
                echo "</span>";
            }
        } else
            echo "-";
        echo "</td>\n";
        echo "<td align=\"center\">";
        if ($nb_int_clos_crees_total <> 0) {
            echo "<span class=\"annot_std_it\">";
            echo $nb_int_clos_crees_total;
            echo "</span>";
            if ($nb_int_crees_total <> 0) {
                echo "<span class=\"annot_petit_it\">";
                echo " (" . round((($nb_int_clos_crees_total / $nb_int_crees_total) * 100), 2) . "%)";
                echo "</span>";
            }
        } else
            echo "-";
        echo "</td>\n";

        echo "</tr>\n";

        $i++;

        /* Saut de ligne pour lisibilité */

        // création de l'entête de ligne (TR)
        creetrlst($i);

        echo "<td>";
        echo "&nbsp;";
        echo "</td>\n";
        echo "<td>";
        echo "&nbsp;";
        echo "</td>\n";
        echo "<td>";
        echo "&nbsp;";
        echo "</td>\n";
        echo "<td>";
        echo "&nbsp;";
        echo "</td>\n";
        echo "<td>";
        echo "&nbsp;";
        echo "</td>\n";

        echo "</tr>\n";

        $i++;

        if ($nb_do_select > 0) {
            for ($j = 0; $j < $nb_do_select; $j++) {
                // création de l'entête de ligne (TR)
                creetrlst($i);

                echo "<td>";
                $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
                $rech = "SELECT * FROM `" . TBDO . "` WHERE `do_code` = '" . $code_donneur_ordres[$j] . "'";
                $rows = $db->get_results($rech, ARRAY_A);
                foreach ($rows as $row) {
                    $row = encode_str($row);
                    extract($row);
                    $txt_do = $do_nom;
                }
                $db->disconnect();
                echo "<span class=\"annot_std_gras\">";
                echo $txt_do . " (" . $code_donneur_ordres[$j] . ")";
                echo "</span>";
                if ($do_ouvert == 0) {
                    echo "<span class=\"annot_petit_it\">";
                    echo " " . _("Fermée");
                    echo "</span>";
                }
                echo "<br />";
                if ($nb_int_crees_do[$j] <> 0) {
                    echo "<span class=\"annot_petit_it\">";
                    echo "<div align=\"right\">";
                    echo _("Par rapport donneur d'ordres : ");
                    echo "<br />" . _("Par rapport total") . " : ";
                    echo "</div>";
                    echo "</span>";
                }
                echo "</td>\n";
                echo "<td align=\"center\">";
                if ($nb_int_crees_do[$j] <> 0) {
                    echo "<span class=\"annot_std_gras\">";
                    echo $nb_int_crees_do[$j];
                    echo "</span>";
                    if ($nb_int_crees_total <> 0) {
                        echo "<span class=\"annot_petit_it\">";
                        echo "<br />-<br />(" . round((($nb_int_crees_do[$j] / $nb_int_crees_total) * 100), 2) . "%)";
                        echo "</span>";
                    }
                } else
                    echo "-";
                echo "</td>\n";
                echo "<td align=\"center\">";
                if ($nb_int_ouv_crees_do[$j] <> 0) {
                    echo "<span class=\"annot_std_gras\">";
                    echo $nb_int_ouv_crees_do[$j];
                    echo "</span>";
                    echo "<br />";
                    if ($nb_int_crees_do[$j] <> 0) {
                        echo "<span class=\"annot_petit_it\">";
                        echo "(" . round((($nb_int_ouv_crees_do[$j] / $nb_int_crees_do[$j]) * 100), 2) . "%)";
                        echo "</span>";
                    } else
                        echo "-";
                    echo "<br />";
                    if ($nb_int_ouv_crees_total <> 0) {
                        echo "<span class=\"annot_petit_it\">";
                        echo "(" . round((($nb_int_ouv_crees_do[$j] / $nb_int_ouv_crees_total) * 100), 2) . "%)";
                        echo "</span>";
                    } else
                        echo "-";
                } else
                    echo "-";
                echo "</td>\n";
                echo "<td align=\"center\">";
                if ($nb_int_prev_crees_do[$j] <> 0) {
                    echo "<span class=\"annot_std_gras\">";
                    echo $nb_int_prev_crees_do[$j];
                    echo "</span>";
                    echo "<br />";
                    if ($nb_int_crees_do[$j] <> 0) {
                        echo "<span class=\"annot_petit_it\">";
                        echo " (" . round((($nb_int_prev_crees_do[$j] / $nb_int_crees_do[$j]) * 100), 2) . "%)";
                        echo "</span>";
                    } else
                        echo "-";
                    echo "<br />";
                    if ($nb_int_prev_crees_total <> 0) {
                        echo "<span class=\"annot_petit_it\">";
                        echo "(" . round((($nb_int_prev_crees_do[$j] / $nb_int_prev_crees_total) * 100), 2) . "%)";
                        echo "</span>";
                    } else
                        echo "-";
                } else
                    echo "-";
                echo "</td>\n";
                echo "<td align=\"center\">";
                if ($nb_int_clos_crees_do[$j] <> 0) {
                    echo "<span class=\"annot_std_gras\">";
                    echo $nb_int_clos_crees_do[$j];
                    echo "</span>";
                    echo "<br />";
                    if ($nb_int_crees_do[$j] <> 0) {
                        echo "<span class=\"annot_petit_it\">";
                        echo " (" . round((($nb_int_clos_crees_do[$j] / $nb_int_crees_do[$j]) * 100), 2) . "%)";
                        echo "</span>";
                    }
                    echo "<br />";
                    if ($nb_int_clos_crees_total <> 0) {
                        echo "<span class=\"annot_petit_it\">";
                        echo "(" . round((($nb_int_clos_crees_do[$j] / $nb_int_clos_crees_total) * 100), 2) . "%)";
                        echo "</span>";
                    } else
                        echo "-";
                } else
                    echo "-";
                echo "</td>\n";

                echo "</tr>\n";

                $i++;
            }
        } else {
            // création de l'entête de ligne (TR)
            creetrlst($i);

            echo "<td>";
            echo "<span class=\"annot_petit_it\">";
            echo _("Aucun résultat à cette demande") . ".";
            echo "</span>";
            echo "</td>\n";
            echo "<td>";
            echo "&nbsp;";
            echo "</td>\n";
            echo "<td>";
            echo "&nbsp;";
            echo "</td>\n";
            echo "<td>";
            echo "&nbsp;";
            echo "</td>\n";
            echo "<td>";
            echo "&nbsp;";
            echo "</td>\n";

            echo "</tr>\n";
        }

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

    default :
        break;
    }
    } else
        pop_ret_auto(_("Aucun donneur d'ordres "), 'warn', "index.php");
} else
    pop_ret_auto(_("Problème de paramètres"), 'warn', "index.php");
include_once("pied.php");
?>
</body>

</html>