dolibarr  7.0.0-beta
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 <http://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->societe_id > 0)
38 {
39  $action = '';
40  $socid = $user->societe_id;
41 }
42 $result=restrictedArea($user,'adherent','','','cotisation');
43 
44 $year = strftime("%Y", time());
45 $startyear=$year-2;
46 $endyear=$year;
47 
48 $langs->load("members");
49 $langs->load("companies");
50 
51 
52 /*
53  * View
54  */
55 
56 $arrayjs=array('https://www.google.com/jsapi');
57 if (! empty($conf->dol_use_jmobile)) $arrayjs=array();
58 
59 $title=$langs->trans("Statistics");
60 if ($mode == 'memberbycountry') $title=$langs->trans("MembersStatisticsByCountries");
61 if ($mode == 'memberbystate') $title=$langs->trans("MembersStatisticsByState");
62 if ($mode == 'memberbytown') $title=$langs->trans("MembersStatisticsByTown");
63 if ($mode == 'memberbyregion') $title=$langs->trans("MembersStatisticsByRegion");
64 
65 llxHeader('', $title,'','',0,0,$arrayjs);
66 
68 
69 dol_mkdir($dir);
70 
71 if ($mode)
72 {
73  // Define sql
74  if ($mode == 'memberbycountry')
75  {
76  $label=$langs->trans("Country");
77  $tab='statscountry';
78 
79  $data = array();
80  $sql.="SELECT COUNT(d.rowid) as nb, MAX(d.datevalid) as lastdate, c.code, c.label";
81  $sql.=" FROM ".MAIN_DB_PREFIX."adherent as d LEFT JOIN ".MAIN_DB_PREFIX."c_country as c on d.country = c.rowid";
82  $sql.=" WHERE d.entity IN (".getEntity('adherent').")";
83  $sql.=" AND d.statut = 1";
84  $sql.=" GROUP BY c.label, c.code";
85  //print $sql;
86  }
87 
88  if ($mode == 'memberbystate')
89  {
90  $label=$langs->trans("Country");
91  $label2=$langs->trans("State");
92  $tab='statsstate';
93 
94  $data = array();
95  $sql.="SELECT COUNT(d.rowid) as nb, MAX(d.datevalid) as lastdate, co.code, co.label, c.nom as label2"; //
96  $sql.=" FROM ".MAIN_DB_PREFIX."adherent as d LEFT JOIN ".MAIN_DB_PREFIX."c_departements as c on d.state_id = c.rowid";
97  $sql.=" LEFT JOIN ".MAIN_DB_PREFIX."c_regions as r on c.fk_region = r.code_region";
98  $sql.=" LEFT JOIN ".MAIN_DB_PREFIX."c_country as co on d.country = co.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  {
106  $label=$langs->trans("Country");
107  $label2=$langs->trans("Region"); //département
108  $tab='statsregion'; //onglet
109 
110  $data = array(); //tableau de donnée
111  $sql.="SELECT COUNT(d.rowid) as nb, MAX(d.datevalid) as lastdate, co.code, co.label, r.nom as label2";
112  $sql.=" FROM ".MAIN_DB_PREFIX."adherent as d 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.=" WHERE d.entity IN (".getEntity('adherent').")";
116  $sql.=" AND d.statut = 1";
117  $sql.=" GROUP BY co.label, co.code, r.nom"; //+
118  //print $sql;
119  }
120  if ($mode == 'memberbytown')
121  {
122  $label=$langs->trans("Country");
123  $label2=$langs->trans("Town");
124  $tab='statstown';
125 
126  $data = array();
127  $sql.="SELECT COUNT(d.rowid) as nb, MAX(d.datevalid) as lastdate, 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.=" WHERE d.entity IN (".getEntity('adherent').")";
131  $sql.=" AND d.statut = 1";
132  $sql.=" GROUP BY c.label, c.code, d.town";
133  //print $sql;
134  }
135 
136  $langsen=new Translate('',$conf);
137  $langsen->setDefaultLang('en_US');
138  $langsen->load("dict");
139  //print $langsen->trans("Country"."FI");exit;
140 
141  // Define $data array
142  dol_syslog("Count member", LOG_DEBUG);
143  $resql=$db->query($sql);
144  if ($resql)
145  {
146  $num=$db->num_rows($resql);
147  $i=0;
148  while ($i < $num)
149  {
150  $obj=$db->fetch_object($resql);
151  if ($mode == 'memberbycountry')
152  {
153  $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"))),
154  'label_en'=>(($obj->code && $langsen->transnoentitiesnoconv("Country".$obj->code)!="Country".$obj->code)?$langsen->transnoentitiesnoconv("Country".$obj->code):($obj->label?$obj->label:$langs->trans("Unknown"))),
155  'code'=>$obj->code,
156  'nb'=>$obj->nb,
157  'lastdate'=>$db->jdate($obj->lastdate)
158  );
159  }
160  if ($mode == 'memberbyregion') //+
161  {
162  $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"))),
163  'label_en'=>(($obj->code && $langsen->transnoentitiesnoconv("Country".$obj->code)!="Country".$obj->code)?$langsen->transnoentitiesnoconv("Country".$obj->code):($obj->label?$obj->label:$langs->trans("Unknown"))),
164  'label2'=>($obj->label2?$obj->label2:$langs->trans("Unknown")),
165  'nb'=>$obj->nb,
166  'lastdate'=>$db->jdate($obj->lastdate)
167  );
168  }
169  if ($mode == 'memberbystate')
170  {
171  $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"))),
172  'label_en'=>(($obj->code && $langsen->transnoentitiesnoconv("Country".$obj->code)!="Country".$obj->code)?$langsen->transnoentitiesnoconv("Country".$obj->code):($obj->label?$obj->label:$langs->trans("Unknown"))),
173  'label2'=>($obj->label2?$obj->label2:$langs->trans("Unknown")),
174  'nb'=>$obj->nb,
175  'lastdate'=>$db->jdate($obj->lastdate)
176  );
177  }
178  if ($mode == 'memberbytown')
179  {
180  $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"))),
181  'label_en'=>(($obj->code && $langsen->transnoentitiesnoconv("Country".$obj->code)!="Country".$obj->code)?$langsen->transnoentitiesnoconv("Country".$obj->code):($obj->label?$obj->label:$langs->trans("Unknown"))),
182  'label2'=>($obj->label2?$obj->label2:$langs->trans("Unknown")),
183  'nb'=>$obj->nb,
184  'lastdate'=>$db->jdate($obj->lastdate)
185  );
186  }
187 
188  $i++;
189  }
190  $db->free($resql);
191  }
192  else
193  {
194  dol_print_error($db);
195  }
196 }
197 
198 
199 $head = member_stats_prepare_head($adh);
200 
201 dol_fiche_head($head, $tab, $langs->trans("Statistics"), -1, 'user');
202 
203 
204 // Print title
205 if ($mode && ! count($data))
206 {
207  print $langs->trans("NoValidatedMemberYet").'<br>';
208  print '<br>';
209 }
210 else
211 {
212  if ($mode == 'memberbycountry') print $langs->trans("MembersByCountryDesc").'<br>';
213  else if ($mode == 'memberbystate') print $langs->trans("MembersByStateDesc").'<br>';
214  else if ($mode == 'memberbytown') print $langs->trans("MembersByTownDesc").'<br>';
215  else if ($mode == 'memberbyregion') print $langs->trans("MembersByRegion").'<br>';//+
216  else
217  {
218  print $langs->trans("MembersStatisticsDesc").'<br>';
219  print '<br>';
220  print '<a href="'.$_SERVER["PHP_SELF"].'?mode=memberbycountry">'.$langs->trans("MembersStatisticsByCountries").'</a><br>';
221  print '<br>';
222  print '<a href="'.$_SERVER["PHP_SELF"].'?mode=memberbystate">'.$langs->trans("MembersStatisticsByState").'</a><br>';
223  print '<br>';
224  print '<a href="'.$_SERVER["PHP_SELF"].'?mode=memberbytown">'.$langs->trans("MembersStatisticsByTown").'</a><br>';
225  print '<br>';//+
226  print '<a href="'.$_SERVER["PHP_SELF"].'?mode=memberbyregion">'.$langs->trans("MembersStatisticsByRegion").'</a><br>';//+
227  }
228  print '<br>';
229 }
230 
231 
232 // Show graphics
233 if (count($arrayjs) && $mode == 'memberbycountry')
234 {
235  $color_file = DOL_DOCUMENT_ROOT.'/theme/'.$conf->theme.'/graph-color.php';
236  if (is_readable($color_file)) include_once $color_file;
237 
238  // Assume we've already included the proper headers so just call our script inline
239  // More doc: https://developers.google.com/chart/interactive/docs/gallery/geomap?hl=fr-FR
240  print "\n<script type='text/javascript'>\n";
241  print "google.load('visualization', '1', {'packages': ['geomap']});\n";
242  print "google.setOnLoadCallback(drawMap);\n";
243  print "function drawMap() {\n\tvar data = new google.visualization.DataTable();\n";
244 
245  // Get the total number of rows
246  print "\tdata.addRows(".count($data).");\n";
247  print "\tdata.addColumn('string', 'Country');\n";
248  print "\tdata.addColumn('number', 'Number');\n";
249 
250  // loop and dump
251  $i=0;
252  foreach($data as $val)
253  {
254  $valcountry=strtoupper($val['code']); // Should be ISO-3166 code (faster)
255  //$valcountry=ucfirst($val['label_en']);
256  if ($valcountry == 'Great Britain') { $valcountry = 'United Kingdom'; } // fix case of uk (when we use labels)
257  print "\tdata.setValue(".$i.", 0, \"".$valcountry."\");\n";
258  print "\tdata.setValue(".$i.", 1, ".$val['nb'].");\n";
259  // Google's Geomap only supports up to 400 entries
260  if ($i >= 400){ break; }
261  $i++;
262  }
263 
264  print "\tvar options = {};\n";
265  print "\toptions['dataMode'] = 'regions';\n";
266  print "\toptions['showZoomOut'] = false;\n";
267  //print "\toptions['zoomOutLabel'] = '".dol_escape_js($langs->transnoentitiesnoconv("Numbers"))."';\n";
268  print "\toptions['width'] = ".$graphwidth.";\n";
269  print "\toptions['height'] = ".$graphheight.";\n";
270  print "\toptions['colors'] = [0x".colorArrayToHex($theme_datacolor[1],'BBBBBB').", 0x".colorArrayToHex($theme_datacolor[0],'444444')."];\n";
271  print "\tvar container = document.getElementById('".$mode."');\n";
272  print "\tvar geomap = new google.visualization.GeoMap(container);\n";
273  print "\tgeomap.draw(data, options);\n";
274  print "};\n";
275  print "</script>\n";
276 
277  // print the div tag that will contain the map
278  print '<div align="center" id="'.$mode.'"></div>'."\n";
279  print '<br>';
280 }
281 
282 if ($mode)
283 {
284  // Print array / Affiche le tableau
285  print '<table class="liste" width="100%">';
286  print '<tr class="liste_titre">';
287  print '<td>'.$label.'</td>';
288  if ($label2) print '<td align="center">'.$label2.'</td>';
289  print '<td align="right">'.$langs->trans("NbOfMembers").'</td>';
290  print '<td align="center">'.$langs->trans("LastMemberDate").'</td>';
291  print '</tr>';
292 
293  $oldyear=0;
294  foreach ($data as $val)
295  {
296  $year = $val['year'];
297  print '<tr class="oddeven">';
298  print '<td>'.$val['label'].'</td>';
299  if ($label2) print '<td align="center">'.$val['label2'].'</td>';
300  print '<td align="right">'.$val['nb'].'</td>';
301  print '<td align="center">'.dol_print_date($val['lastdate'],'dayhour').'</td>';
302  print '</tr>';
303  $oldyear=$year;
304  }
305 
306  print '</table>';
307 }
308 
309 
310 dol_fiche_end();
311 
312 
313 
314 llxFooter();
315 
316 $db->close();
llxFooter()
Empty footer.
Definition: wrapper.php:58
dol_fiche_head($links=array(), $active='0', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='')
Show tab header of a card.
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
GETPOST($paramname, $check='none', $method=0, $filter=NULL, $options=NULL, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='')
Write log message into outputs.
static getDefaultGraphSizeForStats($direction, $defaultsize='')
getDefaultGraphSizeForStats
if($_POST["cancel"]==$langs->trans("Cancel")&&!$id) if($action== 'setdatev'&&$user->rights->tax->charges->creer) if($action== 'add'&&$_POST["cancel"]<> $langs->trans("Cancel")) if($action== 'delete') $title
Actions.
Definition: card.php:183
dol_fiche_end($notab=0)
Show tab footer of a card.
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id=0, $morecssontable='', $morehtmlcenter='')
Load a title with picto.
llxHeader()
Empty header.
Definition: wrapper.php:46
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:206
print
Draft customers invoices.
Definition: index.php:91
dol_mkdir($dir, $dataroot='', $newmask=null)
Creation of a directory (this can create recursive subdir)
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if(!empty($conf->fournisseur->enabled)&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->societe->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)&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1013
colorArrayToHex($arraycolor, $colorifnotfound='888888')
Convert an array with RGB value into hex RGB value.
restrictedArea($user, $features, $objectid=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $objcanvas=null)
Check permissions of a user to show a page and an object.