PEEL Shopping
Open source ecommerce : PEEL Shopping
chart-data.php
Go to the documentation of this file.
1 <?php
2 // This file should be in UTF8 without BOM - Accents examples: éèê
3 // +----------------------------------------------------------------------+
4 // | Copyright (c) 2004-2015 Advisto SAS, service PEEL - contact@peel.fr |
5 // +----------------------------------------------------------------------+
6 // | This file is part of PEEL Shopping 8.0.0, which is subject to an |
7 // | opensource GPL license: you are allowed to customize the code |
8 // | for your own needs, but must keep your changes under GPL |
9 // | More information: https://www.peel.fr/lire/licence-gpl-70.html |
10 // +----------------------------------------------------------------------+
11 // | Author: Advisto SAS, RCS 479 205 452, France, https://www.peel.fr/ |
12 // +----------------------------------------------------------------------+
13 // $Id: chart-data.php 46935 2015-09-18 08:49:48Z gboussin $
14 define('IN_PEEL_ADMIN', true);
15 include("../configuration.inc.php");
17 necessite_priv("admin*");
18 
19 require($GLOBALS['dirroot'] . '/modules/chart/advisto-chart.php');
20 
21 foreach(array('date1', 'date2', 'type', 'renewals', 'width') as $item) {
22  if (isset($_GET[$item])) {
23  $$item = $_GET[$item];
24  } else {
25  $$item = null;
26  }
27 }
28 
29 $data = array();
31 $graph_type = array();
32 $colors = array();
35 
36 if(vb($GLOBALS['site_parameters']['chart_product']) == 'flot') {
37  $date_format = 'timestamp1000';
38 } elseif (strtotime($date2) - strtotime($date1) < 6300 * 24 * 30 * 6) {
39  $date_format = 'veryshort';
40 } else {
41  $date_format = 'short';
42 }
43 if (strlen($date2) == '10') {
44  $date2 .= ' 23:59:00';
45 }
46 if ($type == 'users-by-age' && a_priv('admin_users', true)) {
54  $sql_age_formula = 'IF(date_naissance>"' . date('Y-m-d 12:00:00', round(time() - 365.25 * 18 * 24 * 3600)) . '", 18,IF(date_naissance BETWEEN "' . date('Y-m-d 12:00:00', round(time() - 365.25 * 25 * 24 * 3600)) . '" AND "' . date('Y-m-d 12:00:00', round(time() - 365.25 * 18 * 24 * 3600)) . '", 25,IF(date_naissance BETWEEN "' . date('Y-m-d 12:00:00', round(time() - 365.25 * 35 * 24 * 3600)) . '" AND "' . date('Y-m-d 12:00:00', round(time() - 365.25 * 25 * 24 * 3600)) . '", 35,IF(date_naissance BETWEEN "' . date('Y-m-d 12:00:00', round(time() - 365.25 * 45 * 24 * 3600)) . '" AND "' . date('Y-m-d 12:00:00', round(time() - 365.25 * 35 * 24 * 3600)) . '", 45,IF(date_naissance<"' . date('Y-m-d 12:00:00', round(time() - 365.25 * 45 * 24 * 3600)) . '", 50,0)))))';
55  $type_names = array(18 => '- de 18 ans', 25 => '18 à 25 ans', 35 => '25 à 35 ans', 45 => '35 à 45 ans', 50 => '45 ans et +');
56  $sex_names = array('M.' => 'H', 'Mlle' => 'F', 'Mme' => 'F');
57  $res = query('SELECT count(*) AS this_count, civilite, ' . $sql_age_formula . ' AS tranche
58  FROM peel_utilisateurs
59  WHERE ' . get_filter_site_cond('utilisateurs') . ' ' . (!empty($date1)?(' AND date_insert BETWEEN "' . nohtml_real_escape_string($date1) . '" AND "' . nohtml_real_escape_string($date2) . '"'):'') . '
60  GROUP BY civilite, ' . $sql_age_formula);
61  $data['Tous'] = array();
62  while ($row = fetch_assoc($res)) {
63  $data[$sex_names[$row['sexe']]][($type_names[$row['tranche']])] = $row['this_count'];
64  if (empty($data['Tous'][($type_names[$row['tranche']])])) {
65  $data['Tous'][($type_names[$row['tranche']])] = 0;
66  }
67  $data['Tous'][($type_names[$row['tranche']])] += $row['this_count'];
68  }
69  $graph_type['Tous'] = 'bar';
70  $graph_type['H'] = 'bar';
71  $graph_type['F'] = 'bar';
72  $title = $GLOBALS['STR_ADMIN_CHART_DATA_AGE_TITLE'] . ' ' . (!empty($date1)?' ' . $GLOBALS['strStartingOn'] . ' ' . get_formatted_date($date1) . ' ' . $GLOBALS['strTillDay'] . ' ' . get_formatted_date($date2):'');
73 } elseif ($type == 'forums-count' && a_priv('admin_content', true)) {
74  $res = query('SELECT count(*) AS this_count, date
75  FROM peel_forums a
76  WHERE 1 ' . (!empty($date1)?(' AND date BETWEEN "' . nohtml_real_escape_string($date1) . '" AND "' . nohtml_real_escape_string($date2) . '"'):'') . '
77  GROUP BY TO_DAYS(a.date)');
78  $total = 0;
79  while ($row = fetch_assoc($res)) {
80  $data['Messages'][get_formatted_date($row['date'], $date_format)] = $row['this_count'];
81  $total += $row['this_count'];
82  }
83  $title = sprintf($GLOBALS['STR_ADMIN_CHART_DATA_MESSAGES_NUMBER_TITLE'], intval($total)) . ' ' . (!empty($date1)?$GLOBALS['STR_ADMIN_PUBLISHED'] . ' ' . $GLOBALS['strTillDay'] . ' ' . get_formatted_date($date1) . ' ' . $GLOBALS['strTillDay'] . ' ' . get_formatted_date($date2):'');
84 } elseif ($type == 'forums-categories' && a_priv('admin_content', true)) {
85  $res = query('SELECT count(*) AS this_count, c.nom
86  FROM peel_forums a
87  INNER JOIN peel_forums_cat c ON c.id=a.id_cat
88  WHERE 1 ' . (!empty($date1)?(' AND date BETWEEN "' . nohtml_real_escape_string($date1) . '" AND "' . nohtml_real_escape_string($date2) . '"'):'') . '
89  GROUP BY a.id_cat');
90  $total = 0;
91  while ($row = fetch_assoc($res)) {
92  $data[String::substr($row['nom'], 0, 20)] = $row['this_count'];
93  $total += $row['this_count'];
94  }
95  $all_graph_type = 'pie';
97  $title = sprintf($GLOBALS['STR_ADMIN_CHART_DATA_MESSAGES_CATEGORIES_TITLE'], intval($total)) . ' ' . (!empty($date1)?$GLOBALS['STR_ADMIN_PUBLISHED'] . ' ' . $GLOBALS['strTillDay'] . ' ' . get_formatted_date($date1) . ' ' . $GLOBALS['strTillDay'] . ' ' . get_formatted_date($date2):'');
98 } elseif ($type == 'users-count' && a_priv('admin_users', true)) {
99  $data[$GLOBALS["STR_ADMIN_INSCRIPTIONS"]] = array();
100  if (empty($graph_type[$GLOBALS["STR_ADMIN_INSCRIPTIONS"]]) || $graph_type[$GLOBALS["STR_ADMIN_INSCRIPTIONS"]] != 'dot') {
101  if (!empty($date1)) {
102  $t2 = strtotime($date2);
103  for($t = strtotime($date1);$t <= $t2;$t += 3600 * 24) {
104  $data[$GLOBALS["STR_ADMIN_INSCRIPTIONS"]][get_formatted_date(date('Y-m-d', $t), $date_format)] = 0;
105  }
106  }
107  }
108  $res = query('SELECT count(*) AS this_count, date_insert AS date_inscription, 1 AS actif
109  FROM peel_utilisateurs
110  WHERE ' . get_filter_site_cond('utilisateurs') . ' ' . (!empty($date1)?(' AND date_insert BETWEEN "' . nohtml_real_escape_string($date1) . '" AND "' . nohtml_real_escape_string($date2) . '"'):'') . '
111  GROUP BY TO_DAYS(date_insert)');
112  // On déclare pour définir l'ordre d'affichage dans le flash
113  while ($row = fetch_assoc($res)) {
114  if (empty($data[$GLOBALS["STR_ADMIN_INSCRIPTIONS"]][get_formatted_date(String::substr($row['date_inscription'], 0, 10), $date_format)])) {
115  $data[$GLOBALS["STR_ADMIN_INSCRIPTIONS"]][get_formatted_date(String::substr($row['date_inscription'], 0, 10), $date_format)] = 0;
116  }
117  $data[$GLOBALS["STR_ADMIN_INSCRIPTIONS"]][get_formatted_date(String::substr($row['date_inscription'], 0, 10), $date_format)] += $row['this_count'];
118  }
119  $colors[$GLOBALS["STR_ADMIN_INSCRIPTIONS"]] = '0000FF';
120  $title = (!empty($date1)?'' . $GLOBALS['strStartingOn'] . ' ' . get_formatted_date($date1) . ' ' . $GLOBALS['strTillDay'] . ' ' . get_formatted_date($date2):'');
121 } elseif ($type == 'product-categories' && a_priv('admin_products', true)) {
122  $res = query('SELECT count(*) AS this_count, c.nom_'.$_SESSION['session_langue'].' AS nom_categorie
123  FROM peel_produits p
124  INNER JOIN peel_produits_categories pc ON pc.produit_id=p.id
125  INNER JOIN peel_categories c ON c.id=pc.categorie_id AND ' . get_filter_site_cond('categories', 'c') . '
126  WHERE ' . get_filter_site_cond('produits', 'p') . '
127  GROUP BY c.id');
128  while ($row = fetch_assoc($res)) {
129  $data[String::substr($row['nom_categorie'], 0, 20)] = $row['this_count'];
130  }
131  $all_graph_type = 'pie';
132  $legend_font_size = 9;
133  // $title = 'Catégories des produits';
134 } elseif ($type == 'users-by-sex' && a_priv('admin_users', true)) {
135  $res = query('SELECT count(*) AS this_count, civilite
136  FROM peel_utilisateurs
137  WHERE ' . get_filter_site_cond('utilisateurs') . '' . (!empty($date1)?(' AND (date BETWEEN "' . nohtml_real_escape_string($date1) . '" AND "' . nohtml_real_escape_string($date2) . '")'):'') . '
138  GROUP BY civilite');
139  while ($row = fetch_assoc($res)) {
140  if ($row['civilite'] == 'M.') {
141  $type_name = 'H';
142  } else {
143  $type_name = 'F';
144  }
145  $data[$type_name] = $row['this_count'];
146  }
147  $all_graph_type = 'pie';
148  $title = $GLOBALS['STR_ADMIN_CHART_DATA_USERS_BY_SEX'] . ' ' . (!empty($date1)?' ' . $GLOBALS['strStartingOn'] . ' ' . get_formatted_date($date1) . ' ' . $GLOBALS['strTillDay'] . ' ' . get_formatted_date($date2):'');
149 } elseif ($type == 'users-by-country' && a_priv('admin_users', true)) {
150  $res = query('SELECT count(*) AS this_count, c.nom_'.$_SESSION['session_langue'].' AS country_name
151  FROM `peel_utilisateurs` a
152  INNER JOIN peel_pays c ON c.id = a.pays AND ' . get_filter_site_cond('pays', 'c') . '
153  WHERE ' . get_filter_site_cond('utilisateurs', 'a') . '' . (!empty($date1)?(' AND (a.date_insert BETWEEN "' . nohtml_real_escape_string($date1) . '" AND "' . nohtml_real_escape_string($date2) . '")'):'') . '
154  GROUP BY a.pays');
155  while ($row = fetch_assoc($res)) {
156  $data[$row['country_name']] = $row['this_count'];
157  }
158  $all_graph_type = 'pie';
159  $title = $GLOBALS['STR_ADMIN_CHART_DATA_USERS_BY_COUNTRY'] . (!empty($date1)?' ' . $GLOBALS['strStartingOn'] . ' ' . get_formatted_date($date1) . ' ' . $GLOBALS['strTillDay'] . ' ' . get_formatted_date($date2):'');
160 } elseif ($type == 'sales' && a_priv('admin_sales', true)) {
161  $data['CA'] = array();
162  $graph_type['CA'] = 'bar';
163  if (empty($graph_type['CA']) || $graph_type['CA'] != 'dot') {
164  if (!empty($date1)) {
165  $t2 = strtotime($date2);
166  for($t = strtotime($date1);$t <= $t2;$t += 3600 * 24) {
167  $data['CA'][get_formatted_date(date('Y-m-d', $t), $date_format)] = 0;
168  }
169  }
170  }
171  $res = query('SELECT SUM(c.montant_ht) AS this_total, c.a_timestamp
172  FROM peel_commandes c
173  LEFT JOIN peel_statut_paiement sp ON sp.id=c.id_statut_paiement AND ' . get_filter_site_cond('statut_paiement', 'sp') . '
174  WHERE sp.technical_code IN ("being_checked","completed") AND ' . get_filter_site_cond('commandes', 'c') . ' ' . (!empty($date1)?(' AND c.a_timestamp BETWEEN "' . nohtml_real_escape_string($date1) . '" AND "' . nohtml_real_escape_string($date2) . '"'):'') . '
175  GROUP BY TO_DAYS(c.a_timestamp)');
176  while ($row = fetch_assoc($res)) {
177  if (empty($data['CA'][get_formatted_date($row['a_timestamp'], $date_format)])) {
178  $data['CA'][get_formatted_date($row['a_timestamp'], $date_format)] = 0;
179  }
180  $data['CA'][get_formatted_date($row['a_timestamp'], $date_format)] += round($row['this_total'], 2);
181  }
182  $title = '' . (!empty($date1)?' ' . $GLOBALS['strStartingOn'] . ' ' . get_formatted_date($date1) . ' ' . $GLOBALS['strTillDay'] . ' ' . get_formatted_date($date2):'');
183 }
185 
foreach(array('date1', 'date2', 'type', 'renewals', 'width') as $item) $data
Definition: chart-data.php:29
$font_size
Definition: chart-data.php:34
$colors
Definition: chart-data.php:32
$graph_type
Definition: chart-data.php:31
nohtml_real_escape_string($value, $allowed_tags=null)
Protège les données pour insertion dans MySQL ET supprime les tags HTML pour protéger de toute sorte ...
Definition: database.php:400
necessite_priv($priv, $demo_allowed=true, $configuration_modification=false)
Cette fonction vérifie si l'utilisateur a les privilèges de $priv.
Definition: fonctions.php:1575
get_filter_site_cond($table_technical_code, $table_alias=null, $use_strict_rights_if_in_admin=false, $specific_site_id=null, $exclude_public_items=false, $admin_force_multisite_if_allowed=false)
Retourne la condition SQL permettant de filtrer les données pour une table.
Definition: fonctions.php:4643
advistoChart(&$data, $title=null, $all_graph_type=null, $graph_type=array(), $colors=array(), $legend_font_size=12, $width=300, $force_chart_product=null)
advistoChart()
query($query, $die_if_error=false, $database_object=null, $silent_if_error=false, $security_sql_filter=true)
The query() function is meant to be called anywhere you want to make a query.
Definition: database.php:158
vb(&$var, $default=null)
Variable blanche if $var n'est pas défini, retourne $default, sinon retourne $var.
Definition: format.php:97
if(strlen($date2)== '10') if($type== 'users-by-age'&&a_priv('admin_users', true)) elseif($type== 'forums-count'&&a_priv('admin_content', true)) elseif($type== 'forums-categories'&&a_priv('admin_content', true)) elseif($type== 'users-count'&&a_priv('admin_users', true)) elseif($type== 'product-categories'&&a_priv('admin_products', true)) elseif($type== 'users-by-sex'&&a_priv('admin_users', true)) elseif($type== 'users-by-country'&&a_priv('admin_users', true)) elseif($type== 'sales'&&a_priv('admin_sales', true))
Definition: chart-data.php:160
necessite_identification()
Si l'utilisateur n'est pas connecté à un compte, on affiche une page d'identification et arrête le sc...
Definition: fonctions.php:1596
fetch_assoc($query_result)
fetch_assoc()
Definition: database.php:283
get_formatted_date($datetime_or_timestamp=null, $mode= 'short', $hour_minute=false)
Afficher une date formatée, en évitant les problèmes liés aux noms de mois sur les serveurs qui ne so...
Definition: format.php:440
$legend_font_size
Definition: chart-data.php:33
$GLOBALS['page_columns_count']
$total
$all_graph_type
Definition: chart-data.php:30
a_priv($requested_priv, $demo_allowed=false, $site_configuration_modification=false, $user_id=null)
Renvoie true si l'utilisateur de la session a le privilège $requested_priv ou un droit supérieur Des ...
Definition: user.php:63
static substr($string, $start, $length=null)
Returns the portion of string specified by the start and length parameters.
Definition: String.php:112
if(defined('IN_PEEL_ADMIN')||IN_INSTALLATION) $_SESSION['session_langue']

This documentation for Open ecommerce PEEL Shopping and PEEL.fr has been generated by Doxygen on Thu Oct 15 2015 14:29:00 - Peel ecommerce is a product of Agence web Advisto SAS. All rights reserved.