28require
'../../main.inc.php';
29require_once DOL_DOCUMENT_ROOT.
'/core/lib/member.lib.php';
30require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
31require_once DOL_DOCUMENT_ROOT.
'/core/class/dolgraph.class.php';
32require_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php';
36$graphheight = round($graphwidth * $mapratio);
42if ($user->socid > 0) {
44 $socid = $user->socid;
53$langs->loadLangs(array(
"companies",
"members",
"banks"));
62$arrayjs = array(
'https://www.google.com/jsapi');
63if (!empty($conf->dol_use_jmobile)) {
67$title = $langs->trans(
"Statistics");
68if ($mode ==
'memberbycountry') {
69 $title = $langs->trans(
"MembersStatisticsByCountries");
71if ($mode ==
'memberbystate') {
72 $title = $langs->trans(
"MembersStatisticsByState");
74if ($mode ==
'memberbytown') {
75 $title = $langs->trans(
"MembersStatisticsByTown");
77if ($mode ==
'memberbyregion') {
78 $title = $langs->trans(
"MembersStatisticsByRegion");
81$help_url =
'EN:Module_Services_En|FR:Module_Services|ES:Módulo_Servicios|DE:Modul_Mitglieder';
83llxHeader(
'', $title, $help_url,
'', 0, 0, $arrayjs,
'',
'',
'mod-member page-stats_geo');
94 if ($mode ==
'memberbycountry') {
95 $label = $langs->trans(
"Country");
96 $tab =
'statscountry';
98 $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";
99 $sql .=
" FROM ".MAIN_DB_PREFIX.
"adherent as d";
100 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_country as c on d.country = c.rowid";
101 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"subscription as s ON s.fk_adherent = d.rowid";
102 $sql .=
" WHERE d.entity IN (".getEntity(
'adherent').
")";
103 $sql .=
" AND d.statut <> ".Adherent::STATUS_DRAFT;
104 $sql .=
" GROUP BY c.label, c.code";
108 if ($mode ==
'memberbystate') {
109 $label = $langs->trans(
"Country");
110 $label2 = $langs->trans(
"State");
114 $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";
115 $sql .=
" FROM ".MAIN_DB_PREFIX.
"adherent as d";
116 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_departements as c on d.state_id = c.rowid";
117 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_regions as r on c.fk_region = r.code_region";
118 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_country as co on d.country = co.rowid";
119 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"subscription as s ON s.fk_adherent = d.rowid";
120 $sql .=
" WHERE d.entity IN (".getEntity(
'adherent').
")";
121 $sql .=
" AND d.statut <> ".Adherent::STATUS_DRAFT;
122 $sql .=
" GROUP BY co.label, co.code, c.nom";
125 if ($mode ==
'memberbyregion') {
126 $label = $langs->trans(
"Country");
127 $label2 = $langs->trans(
"Region");
128 $tab =
'statsregion';
131 $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";
132 $sql .=
" FROM ".MAIN_DB_PREFIX.
"adherent as d";
133 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_departements as c on d.state_id = c.rowid";
134 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_regions as r on c.fk_region = r.code_region";
135 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_country as co on d.country = co.rowid";
136 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"subscription as s ON s.fk_adherent = d.rowid";
137 $sql .=
" WHERE d.entity IN (".getEntity(
'adherent').
")";
138 $sql .=
" AND d.statut <> ".Adherent::STATUS_DRAFT;
139 $sql .=
" GROUP BY co.label, co.code, r.nom";
142 if ($mode ==
'memberbytown') {
143 $label = $langs->trans(
"Country");
144 $label2 = $langs->trans(
"Town");
148 $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";
149 $sql .=
" FROM ".MAIN_DB_PREFIX.
"adherent as d";
150 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_country as c on d.country = c.rowid";
151 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"subscription as s ON s.fk_adherent = d.rowid";
152 $sql .=
" WHERE d.entity IN (".getEntity(
'adherent').
")";
153 $sql .=
" AND d.statut <> ".Adherent::STATUS_DRAFT;
154 $sql .=
" GROUP BY c.label, c.code, d.town";
159 $langsen->setDefaultLang(
'en_US');
160 $langsen->load(
"dict");
166 $resql = $db->query($sql);
169 dol_syslog(__FILE__.
":No SQL, invalid mode '$mode'", LOG_ERR);
172 $num = $db->num_rows($resql);
175 $obj = $db->fetch_object($resql);
176 if ($mode ==
'memberbycountry') {
177 $data[] = array(
'label' => (($obj->code && $langs->trans(
"Country".$obj->code) !=
"Country".$obj->code) ?
img_picto(
'', DOL_URL_ROOT.
'/theme/common/flags/'.strtolower($obj->code).
'.png',
'', 1).
' '.$langs->trans(
"Country".$obj->code) : ($obj->label ? $obj->label :
'<span class="opacitymedium">'.$langs->trans(
"Unknown").
'</span>')),
178 'label_en' => (($obj->code && $langsen->transnoentitiesnoconv(
"Country".$obj->code) !=
"Country".$obj->code) ? $langsen->transnoentitiesnoconv(
"Country".$obj->code) : ($obj->label ? $obj->label :
'<span class="opacitymedium">'.$langs->trans(
"Unknown").
'</span>')),
179 'code' => $obj->code,
181 'lastdate' => $db->jdate($obj->lastdate),
182 'lastsubscriptiondate' => $db->jdate($obj->lastsubscriptiondate)
185 if ($mode ==
'memberbyregion') {
187 'label' => (($obj->code && $langs->trans(
"Country".$obj->code) !=
"Country".$obj->code) ?
img_picto(
'', DOL_URL_ROOT.
'/theme/common/flags/'.strtolower($obj->code).
'.png',
'', 1).
' '.$langs->trans(
"Country".$obj->code) : ($obj->label ? $obj->label :
'<span class="opacitymedium">'.$langs->trans(
"Unknown").
'</span>')),
188 'label_en' => (($obj->code && $langsen->transnoentitiesnoconv(
"Country".$obj->code) !=
"Country".$obj->code) ? $langsen->transnoentitiesnoconv(
"Country".$obj->code) : ($obj->label ? $obj->label :
'<span class="opacitymedium">'.$langs->trans(
"Unknown").
'</span>')),
189 'label2' => ($obj->label2 ? $obj->label2 :
'<span class="opacitymedium">'.$langs->trans(
"Unknown").
'</span>'),
191 'lastdate' => $db->jdate($obj->lastdate),
192 'lastsubscriptiondate' => $db->jdate($obj->lastsubscriptiondate)
195 if ($mode ==
'memberbystate') {
196 $data[] = array(
'label' => (($obj->code && $langs->trans(
"Country".$obj->code) !=
"Country".$obj->code) ?
img_picto(
'', DOL_URL_ROOT.
'/theme/common/flags/'.strtolower($obj->code).
'.png',
'', 1).
' '.$langs->trans(
"Country".$obj->code) : ($obj->label ? $obj->label :
'<span class="opacitymedium">'.$langs->trans(
"Unknown").
'</span>')),
197 'label_en' => (($obj->code && $langsen->transnoentitiesnoconv(
"Country".$obj->code) !=
"Country".$obj->code) ? $langsen->transnoentitiesnoconv(
"Country".$obj->code) : ($obj->label ? $obj->label :
'<span class="opacitymedium">'.$langs->trans(
"Unknown").
'</span>')),
198 'label2' => ($obj->label2 ? $obj->label2 :
'<span class="opacitymedium">'.$langs->trans(
"Unknown").
'</span>'),
200 'lastdate' => $db->jdate($obj->lastdate),
201 'lastsubscriptiondate' => $db->jdate($obj->lastsubscriptiondate)
204 if ($mode ==
'memberbytown') {
205 $data[] = array(
'label' => (($obj->code && $langs->trans(
"Country".$obj->code) !=
"Country".$obj->code) ?
img_picto(
'', DOL_URL_ROOT.
'/theme/common/flags/'.strtolower($obj->code).
'.png',
'', 1).
' '.$langs->trans(
"Country".$obj->code) : ($obj->label ? $obj->label :
'<span class="opacitymedium">'.$langs->trans(
"Unknown").
'</span>')),
206 'label_en' => (($obj->code && $langsen->transnoentitiesnoconv(
"Country".$obj->code) !=
"Country".$obj->code) ? $langsen->transnoentitiesnoconv(
"Country".$obj->code) : ($obj->label ? $obj->label :
'<span class="opacitymedium">'.$langs->trans(
"Unknown").
'</span>')),
207 'label2' => ($obj->label2 ? $obj->label2 :
'<span class="opacitymedium">'.$langs->trans(
"Unknown").
'</span>'),
209 'lastdate' => $db->jdate($obj->lastdate),
210 'lastsubscriptiondate' => $db->jdate($obj->lastsubscriptiondate)
229if ($mode && !count($data)) {
230 print $langs->trans(
"NoValidatedMemberYet").
'<br>';
233 if ($mode ==
'memberbycountry') {
234 print
'<span class="opacitymedium">'.$langs->trans(
"MembersByCountryDesc").
'</span><br>';
235 } elseif ($mode ==
'memberbystate') {
236 print
'<span class="opacitymedium">'.$langs->trans(
"MembersByStateDesc").
'</span><br>';
237 } elseif ($mode ==
'memberbytown') {
238 print
'<span class="opacitymedium">'.$langs->trans(
"MembersByTownDesc").
'</span><br>';
239 } elseif ($mode ==
'memberbyregion') {
240 print
'<span class="opacitymedium">'.$langs->trans(
"MembersByRegion").
'</span><br>';
242 print
'<span class="opacitymedium">'.$langs->trans(
"MembersStatisticsDesc").
'</span><br>';
244 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?mode=memberbycountry">'.$langs->trans(
"MembersStatisticsByCountries").
'</a><br>';
246 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?mode=memberbystate">'.$langs->trans(
"MembersStatisticsByState").
'</a><br>';
248 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?mode=memberbytown">'.$langs->trans(
"MembersStatisticsByTown").
'</a><br>';
250 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?mode=memberbyregion">'.$langs->trans(
"MembersStatisticsByRegion").
'</a><br>';
257if (count($arrayjs) && $mode ==
'memberbycountry') {
258 $color_file = DOL_DOCUMENT_ROOT.
'/theme/'.$conf->theme.
'/theme_vars.inc.php';
259 if (is_readable($color_file)) {
265 print
"\n<script type='text/javascript'>\n";
266 print
"google.load('visualization', '1', {'packages': ['geomap']});\n";
267 print
"google.setOnLoadCallback(drawMap);\n";
268 print
"function drawMap() {\n\tvar data = new google.visualization.DataTable();\n";
271 print
"\tdata.addRows(".count($data).
");\n";
272 print
"\tdata.addColumn('string', 'Country');\n";
273 print
"\tdata.addColumn('number', 'Number');\n";
277 foreach ($data as $val) {
278 $valcountry = strtoupper($val[
'code']);
280 if ($valcountry ==
'Great Britain') {
281 $valcountry =
'United Kingdom';
283 print
"\tdata.setValue(".$i.
", 0, \"".$valcountry.
"\");\n";
284 print
"\tdata.setValue(".$i.
", 1, ".$val[
'nb'].
");\n";
292 print
"\tvar options = {};\n";
293 print
"\toptions['dataMode'] = 'regions';\n";
294 print
"\toptions['showZoomOut'] = false;\n";
296 print
"\toptions['width'] = ".$graphwidth.
";\n";
297 print
"\toptions['height'] = ".$graphheight.
";\n";
298 print
"\toptions['colors'] = [0x".colorArrayToHex($theme_datacolor[1],
'BBBBBB').
", 0x".
colorArrayToHex($theme_datacolor[0],
'444444').
"];\n";
299 print
"\tvar container = document.getElementById('".$mode.
"');\n";
300 print
"\tvar geomap = new google.visualization.GeoMap(container);\n";
301 print
"\tgeomap.draw(data, options);\n";
306 print
'<div class="center" id="'.$mode.
'"></div>'.
"\n";
311 print
'<div class="div-table-responsive">';
312 print
'<table class="liste centpercent noborder">';
313 print
'<tr class="liste_titre">';
314 print
'<th>'.$label.
'</th>';
315 if (isset($label2)) {
316 print
'<th class="center">'.$label2.
'</th>';
318 print
'<th class="right">'.$langs->trans(
"NbOfMembers").
' <span class="opacitymedium">('.$langs->trans(
"AllTime").
')</span></th>';
319 print
'<th class="center">'.$langs->trans(
"LastMemberDate").
'</th>';
320 print
'<th class="center">'.$langs->trans(
"LatestSubscriptionDate").
'</th>';
323 foreach ($data as $val) {
324 print
'<tr class="oddeven">';
325 print
'<td>'.$val[
'label'].
'</td>';
326 if (isset($label2)) {
327 print
'<td class="center">'.$val[
'label2'].
'</td>';
329 print
'<td class="right">'.$val[
'nb'].
'</td>';
330 print
'<td class="center">'.dol_print_date($val[
'lastdate'],
'dayhour').
'</td>';
331 print
'<td class="center">'.dol_print_date($val[
'lastsubscriptiondate'],
'dayhour').
'</td>';
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Class to manage members of a foundation.
static getDefaultGraphSizeForStats($direction, $defaultsize='')
getDefaultGraphSizeForStats
Class to manage translations.
colorArrayToHex($arraycolor, $colorifnotfound='888888')
Convert an array with RGB value into hex RGB value.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
dol_now($mode='auto')
Return date for now.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
member_stats_prepare_head($object)
Return array head with list of tabs to view object stats information.
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.