dolibarr  13.0.2
geo.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <https://www.gnu.org/licenses/>.
16  */
17 
24 require '../../main.inc.php';
25 require_once DOL_DOCUMENT_ROOT.'/core/lib/member.lib.php';
26 require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
27 require_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
28 
29 $graphwidth = DolGraph::getDefaultGraphSizeForStats('width', 700);
30 $mapratio = 0.5;
31 $graphheight = round($graphwidth * $mapratio);
32 
33 $mode = GETPOST('mode') ?GETPOST('mode') : '';
34 
35 
36 // Security check
37 if ($user->socid > 0) {
38  $action = '';
39  $socid = $user->socid;
40 }
41 $result = restrictedArea($user, 'adherent', '', '', 'cotisation');
42 
43 $year = strftime("%Y", time());
44 $startyear = $year - 2;
45 $endyear = $year;
46 
47 // Load translation files required by the page
48 $langs->loadLangs(array("companies", "members", "banks"));
49 
50 
51 /*
52  * View
53  */
54 
55 $arrayjs = array('https://www.google.com/jsapi');
56 if (!empty($conf->dol_use_jmobile)) $arrayjs = array();
57 
58 $title = $langs->trans("Statistics");
59 if ($mode == 'memberbycountry') $title = $langs->trans("MembersStatisticsByCountries");
60 if ($mode == 'memberbystate') $title = $langs->trans("MembersStatisticsByState");
61 if ($mode == 'memberbytown') $title = $langs->trans("MembersStatisticsByTown");
62 if ($mode == 'memberbyregion') $title = $langs->trans("MembersStatisticsByRegion");
63 
64 llxHeader('', $title, '', '', 0, 0, $arrayjs);
65 
66 print load_fiche_titre($title, '', 'object_group');
67 
68 dol_mkdir($dir);
69 
70 if ($mode) {
71  // Define sql
72  if ($mode == 'memberbycountry') {
73  $label = $langs->trans("Country");
74  $tab = 'statscountry';
75 
76  $data = array();
77  $sql .= "SELECT COUNT(DISTINCT d.rowid) as nb, COUNT(s.rowid) as nbsubscriptions, MAX(d.datevalid) as lastdate, MAX(s.dateadh) as lastsubscriptiondate, c.code, c.label";
78  $sql .= " FROM ".MAIN_DB_PREFIX."adherent as d";
79  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as c on d.country = c.rowid";
80  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."subscription as s ON s.fk_adherent = d.rowid";
81  $sql .= " WHERE d.entity IN (".getEntity('adherent').")";
82  $sql .= " AND d.statut != -1";
83  $sql .= " GROUP BY c.label, c.code";
84  //print $sql;
85  }
86 
87  if ($mode == 'memberbystate') {
88  $label = $langs->trans("Country");
89  $label2 = $langs->trans("State");
90  $tab = 'statsstate';
91 
92  $data = array();
93  $sql .= "SELECT COUNT(DISTINCT d.rowid) as nb, COUNT(s.rowid) as nbsubscriptions, MAX(d.datevalid) as lastdate, MAX(s.dateadh) as lastsubscriptiondate, co.code, co.label, c.nom as label2"; //
94  $sql .= " FROM ".MAIN_DB_PREFIX."adherent as d";
95  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as c on d.state_id = c.rowid";
96  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_regions as r on c.fk_region = r.code_region";
97  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as co on d.country = co.rowid";
98  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."subscription as s ON s.fk_adherent = d.rowid";
99  $sql .= " WHERE d.entity IN (".getEntity('adherent').")";
100  $sql .= " AND d.statut != -1";
101  $sql .= " GROUP BY co.label, co.code, c.nom";
102  //print $sql;
103  }
104  if ($mode == 'memberbyregion') { //
105  $label = $langs->trans("Country");
106  $label2 = $langs->trans("Region"); //département
107  $tab = 'statsregion'; //onglet
108 
109  $data = array(); //tableau de donnée
110  $sql .= "SELECT COUNT(DISTINCT d.rowid) as nb, COUNT(s.rowid) as nbsubscriptions, MAX(d.datevalid) as lastdate, MAX(s.dateadh) as lastsubscriptiondate, co.code, co.label, r.nom as label2";
111  $sql .= " FROM ".MAIN_DB_PREFIX."adherent as d";
112  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as c on d.state_id = c.rowid";
113  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_regions as r on c.fk_region = r.code_region";
114  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as co on d.country = co.rowid";
115  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."subscription as s ON s.fk_adherent = d.rowid";
116  $sql .= " WHERE d.entity IN (".getEntity('adherent').")";
117  $sql .= " AND d.statut != -1";
118  $sql .= " GROUP BY co.label, co.code, r.nom"; //+
119  //print $sql;
120  }
121  if ($mode == 'memberbytown') {
122  $label = $langs->trans("Country");
123  $label2 = $langs->trans("Town");
124  $tab = 'statstown';
125 
126  $data = array();
127  $sql .= "SELECT COUNT(DISTINCT d.rowid) as nb, COUNT(s.rowid) as nbsubscriptions, MAX(d.datevalid) as lastdate, MAX(s.dateadh) as lastsubscriptiondate, c.code, c.label, d.town as label2";
128  $sql .= " FROM ".MAIN_DB_PREFIX."adherent as d";
129  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as c on d.country = c.rowid";
130  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."subscription as s ON s.fk_adherent = d.rowid";
131  $sql .= " WHERE d.entity IN (".getEntity('adherent').")";
132  $sql .= " AND d.statut != -1";
133  $sql .= " GROUP BY c.label, c.code, d.town";
134  //print $sql;
135  }
136 
137  $langsen = new Translate('', $conf);
138  $langsen->setDefaultLang('en_US');
139  $langsen->load("dict");
140  //print $langsen->trans("Country"."FI");exit;
141 
142  // Define $data array
143  dol_syslog("Count member", LOG_DEBUG);
144  $resql = $db->query($sql);
145  if ($resql) {
146  $num = $db->num_rows($resql);
147  $i = 0;
148  while ($i < $num) {
149  $obj = $db->fetch_object($resql);
150  if ($mode == 'memberbycountry') {
151  $data[] = array('label'=>(($obj->code && $langs->trans("Country".$obj->code) != "Country".$obj->code) ? $langs->trans("Country".$obj->code) : ($obj->label ? $obj->label : $langs->trans("Unknown"))),
152  'label_en'=>(($obj->code && $langsen->transnoentitiesnoconv("Country".$obj->code) != "Country".$obj->code) ? $langsen->transnoentitiesnoconv("Country".$obj->code) : ($obj->label ? $obj->label : $langs->trans("Unknown"))),
153  'code'=>$obj->code,
154  'nb'=>$obj->nb,
155  'lastdate'=>$db->jdate($obj->lastdate),
156  'lastsubscriptiondate'=>$db->jdate($obj->lastsubscriptiondate)
157  );
158  }
159  if ($mode == 'memberbyregion') { //+
160  $data[] = array(
161  'label'=>(($obj->code && $langs->trans("Country".$obj->code) != "Country".$obj->code) ? $langs->trans("Country".$obj->code) : ($obj->label ? $obj->label : $langs->trans("Unknown"))),
162  'label_en'=>(($obj->code && $langsen->transnoentitiesnoconv("Country".$obj->code) != "Country".$obj->code) ? $langsen->transnoentitiesnoconv("Country".$obj->code) : ($obj->label ? $obj->label : $langs->trans("Unknown"))),
163  'label2'=>($obj->label2 ? $obj->label2 : $langs->trans("Unknown")),
164  'nb'=>$obj->nb,
165  'lastdate'=>$db->jdate($obj->lastdate),
166  'lastsubscriptiondate'=>$db->jdate($obj->lastsubscriptiondate)
167  );
168  }
169  if ($mode == 'memberbystate') {
170  $data[] = array('label'=>(($obj->code && $langs->trans("Country".$obj->code) != "Country".$obj->code) ? $langs->trans("Country".$obj->code) : ($obj->label ? $obj->label : $langs->trans("Unknown"))),
171  'label_en'=>(($obj->code && $langsen->transnoentitiesnoconv("Country".$obj->code) != "Country".$obj->code) ? $langsen->transnoentitiesnoconv("Country".$obj->code) : ($obj->label ? $obj->label : $langs->trans("Unknown"))),
172  'label2'=>($obj->label2 ? $obj->label2 : $langs->trans("Unknown")),
173  'nb'=>$obj->nb,
174  'lastdate'=>$db->jdate($obj->lastdate),
175  'lastsubscriptiondate'=>$db->jdate($obj->lastsubscriptiondate)
176  );
177  }
178  if ($mode == 'memberbytown') {
179  $data[] = array('label'=>(($obj->code && $langs->trans("Country".$obj->code) != "Country".$obj->code) ? $langs->trans("Country".$obj->code) : ($obj->label ? $obj->label : $langs->trans("Unknown"))),
180  'label_en'=>(($obj->code && $langsen->transnoentitiesnoconv("Country".$obj->code) != "Country".$obj->code) ? $langsen->transnoentitiesnoconv("Country".$obj->code) : ($obj->label ? $obj->label : $langs->trans("Unknown"))),
181  'label2'=>($obj->label2 ? $obj->label2 : $langs->trans("Unknown")),
182  'nb'=>$obj->nb,
183  'lastdate'=>$db->jdate($obj->lastdate),
184  'lastsubscriptiondate'=>$db->jdate($obj->lastsubscriptiondate)
185  );
186  }
187 
188  $i++;
189  }
190  $db->free($resql);
191  } else {
192  dol_print_error($db);
193  }
194 }
195 
196 
197 $head = member_stats_prepare_head($adh);
198 
199 print dol_get_fiche_head($head, $tab, $langs->trans("Statistics"), -1, 'user');
200 
201 
202 // Print title
203 if ($mode && !count($data)) {
204  print $langs->trans("NoValidatedMemberYet").'<br>';
205  print '<br>';
206 } else {
207  if ($mode == 'memberbycountry') print '<span class="opacitymedium">'.$langs->trans("MembersByCountryDesc").'</span><br>';
208  elseif ($mode == 'memberbystate') print '<span class="opacitymedium">'.$langs->trans("MembersByStateDesc").'</span><br>';
209  elseif ($mode == 'memberbytown') print '<span class="opacitymedium">'.$langs->trans("MembersByTownDesc").'</span><br>';
210  elseif ($mode == 'memberbyregion') print '<span class="opacitymedium">'.$langs->trans("MembersByRegion").'</span><br>'; //+
211  else {
212  print '<span class="opacitymedium">'.$langs->trans("MembersStatisticsDesc").'</span><br>';
213  print '<br>';
214  print '<a href="'.$_SERVER["PHP_SELF"].'?mode=memberbycountry">'.$langs->trans("MembersStatisticsByCountries").'</a><br>';
215  print '<br>';
216  print '<a href="'.$_SERVER["PHP_SELF"].'?mode=memberbystate">'.$langs->trans("MembersStatisticsByState").'</a><br>';
217  print '<br>';
218  print '<a href="'.$_SERVER["PHP_SELF"].'?mode=memberbytown">'.$langs->trans("MembersStatisticsByTown").'</a><br>';
219  print '<br>'; //+
220  print '<a href="'.$_SERVER["PHP_SELF"].'?mode=memberbyregion">'.$langs->trans("MembersStatisticsByRegion").'</a><br>'; //+
221  }
222  print '<br>';
223 }
224 
225 
226 // Show graphics
227 if (count($arrayjs) && $mode == 'memberbycountry') {
228  $color_file = DOL_DOCUMENT_ROOT.'/theme/'.$conf->theme.'/theme_vars.inc.php';
229  if (is_readable($color_file)) include_once $color_file;
230 
231  // Assume we've already included the proper headers so just call our script inline
232  // More doc: https://developers.google.com/chart/interactive/docs/gallery/geomap?hl=fr-FR
233  print "\n<script type='text/javascript'>\n";
234  print "google.load('visualization', '1', {'packages': ['geomap']});\n";
235  print "google.setOnLoadCallback(drawMap);\n";
236  print "function drawMap() {\n\tvar data = new google.visualization.DataTable();\n";
237 
238  // Get the total number of rows
239  print "\tdata.addRows(".count($data).");\n";
240  print "\tdata.addColumn('string', 'Country');\n";
241  print "\tdata.addColumn('number', 'Number');\n";
242 
243  // loop and dump
244  $i = 0;
245  foreach ($data as $val) {
246  $valcountry = strtoupper($val['code']); // Should be ISO-3166 code (faster)
247  //$valcountry=ucfirst($val['label_en']);
248  if ($valcountry == 'Great Britain') { $valcountry = 'United Kingdom'; } // fix case of uk (when we use labels)
249  print "\tdata.setValue(".$i.", 0, \"".$valcountry."\");\n";
250  print "\tdata.setValue(".$i.", 1, ".$val['nb'].");\n";
251  // Google's Geomap only supports up to 400 entries
252  if ($i >= 400) { break; }
253  $i++;
254  }
255 
256  print "\tvar options = {};\n";
257  print "\toptions['dataMode'] = 'regions';\n";
258  print "\toptions['showZoomOut'] = false;\n";
259  //print "\toptions['zoomOutLabel'] = '".dol_escape_js($langs->transnoentitiesnoconv("Numbers"))."';\n";
260  print "\toptions['width'] = ".$graphwidth.";\n";
261  print "\toptions['height'] = ".$graphheight.";\n";
262  print "\toptions['colors'] = [0x".colorArrayToHex($theme_datacolor[1], 'BBBBBB').", 0x".colorArrayToHex($theme_datacolor[0], '444444')."];\n";
263  print "\tvar container = document.getElementById('".$mode."');\n";
264  print "\tvar geomap = new google.visualization.GeoMap(container);\n";
265  print "\tgeomap.draw(data, options);\n";
266  print "};\n";
267  print "</script>\n";
268 
269  // print the div tag that will contain the map
270  print '<div class="center" id="'.$mode.'"></div>'."\n";
271  print '<br>';
272 }
273 
274 if ($mode) {
275  // Print array
276  print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
277  print '<table class="liste centpercent">';
278  print '<tr class="liste_titre">';
279  print '<td>'.$label.'</td>';
280  if ($label2) print '<td class="center">'.$label2.'</td>';
281  print '<td class="right">'.$langs->trans("NbOfMembers").' <span class="opacitymedium">('.$langs->trans("AllTime").')</span></td>';
282  print '<td class="center">'.$langs->trans("LastMemberDate").'</td>';
283  print '<td class="center">'.$langs->trans("LatestSubscriptionDate").'</td>';
284  print '</tr>';
285 
286  foreach ($data as $val) {
287  $year = $val['year'];
288  print '<tr class="oddeven">';
289  print '<td>'.$val['label'].'</td>';
290  if ($label2) print '<td class="center">'.$val['label2'].'</td>';
291  print '<td class="right">'.$val['nb'].'</td>';
292  print '<td class="center">'.dol_print_date($val['lastdate'], 'dayhour').'</td>';
293  print '<td class="center">'.dol_print_date($val['lastsubscriptiondate'], 'dayhour').'</td>';
294  print '</tr>';
295  }
296 
297  print '</table>';
298  print '</div>';
299 }
300 
301 
303 
304 // End of page
305 llxFooter();
306 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
llxHeader()
Empty header.
Definition: wrapper.php:45
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
if(!GETPOST('transkey', 'alphanohtml')&&!GETPOST('transphrase', 'alphanohtml')) else
View.
Definition: notice.php:44
restrictedArea($user, $features, $objectid=0, $tableandshare= '', $feature2= '', $dbt_keyfield= 'fk_soc', $dbt_select= 'rowid', $isdraft=0)
Check permissions of a user to show a page and an object.
Class to manage translations.
member_stats_prepare_head($object)
Return array head with list of tabs to view object stats informations.
Definition: member.lib.php:217
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
print
Draft customers invoices.
Definition: index.php:89
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1232
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_get_fiche_end($notab=0)
Return tab footer of a card.
static getDefaultGraphSizeForStats($direction, $defaultsize= '')
getDefaultGraphSizeForStats
llxFooter()
Empty footer.
Definition: wrapper.php:59
colorArrayToHex($arraycolor, $colorifnotfound= '888888')
Convert an array with RGB value into hex RGB value.
dol_mkdir($dir, $dataroot= '', $newmask=null)
Creation of a directory (this can create recursive subdir)