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';
44$graphheight = round($graphwidth * $mapratio);
50if ($user->socid > 0) {
52 $socid = $user->socid;
61$langs->loadLangs(array(
"companies",
"members",
"banks"));
70$arrayjs = array(
'https://www.google.com/jsapi');
71if (!empty(
$conf->dol_use_jmobile)) {
75$title = $langs->trans(
"Statistics");
76if ($mode ==
'memberbycountry') {
77 $title = $langs->trans(
"MembersStatisticsByCountries");
79if ($mode ==
'memberbystate') {
80 $title = $langs->trans(
"MembersStatisticsByState");
82if ($mode ==
'memberbytown') {
83 $title = $langs->trans(
"MembersStatisticsByTown");
85if ($mode ==
'memberbyregion') {
86 $title = $langs->trans(
"MembersStatisticsByRegion");
89$help_url =
'EN:Module_Services_En|FR:Module_Services|ES:Módulo_Servicios|DE:Modul_Mitglieder';
91llxHeader(
'', $title, $help_url,
'', 0, 0, $arrayjs,
'',
'',
'mod-member page-stats_geo');
103 if ($mode ==
'memberbycountry') {
104 $label = $langs->trans(
"Country");
105 $tab =
'statscountry';
107 $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";
108 $sql .=
" FROM ".MAIN_DB_PREFIX.
"adherent as d";
109 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_country as c on d.country = c.rowid";
110 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"subscription as s ON s.fk_adherent = d.rowid";
111 $sql .=
" WHERE d.entity IN (".getEntity(
'adherent').
")";
112 $sql .=
" AND d.statut <> ".Adherent::STATUS_DRAFT;
113 $sql .=
" GROUP BY c.label, c.code";
117 if ($mode ==
'memberbystate') {
118 $label = $langs->trans(
"Country");
119 $label2 = $langs->trans(
"State");
123 $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";
124 $sql .=
" FROM ".MAIN_DB_PREFIX.
"adherent as d";
125 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_departements as c on d.state_id = c.rowid";
126 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_regions as r on c.fk_region = r.code_region";
127 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_country as co on d.country = co.rowid";
128 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"subscription as s ON s.fk_adherent = d.rowid";
129 $sql .=
" WHERE d.entity IN (".getEntity(
'adherent').
")";
130 $sql .=
" AND d.statut <> ".Adherent::STATUS_DRAFT;
131 $sql .=
" GROUP BY co.label, co.code, c.nom";
134 if ($mode ==
'memberbyregion') {
135 $label = $langs->trans(
"Country");
136 $label2 = $langs->trans(
"Region");
137 $tab =
'statsregion';
140 $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";
141 $sql .=
" FROM ".MAIN_DB_PREFIX.
"adherent as d";
142 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_departements as c on d.state_id = c.rowid";
143 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_regions as r on c.fk_region = r.code_region";
144 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_country as co on d.country = co.rowid";
145 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"subscription as s ON s.fk_adherent = d.rowid";
146 $sql .=
" WHERE d.entity IN (".getEntity(
'adherent').
")";
147 $sql .=
" AND d.statut <> ".Adherent::STATUS_DRAFT;
148 $sql .=
" GROUP BY co.label, co.code, r.nom";
151 if ($mode ==
'memberbytown') {
152 $label = $langs->trans(
"Country");
153 $label2 = $langs->trans(
"Town");
157 $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";
158 $sql .=
" FROM ".MAIN_DB_PREFIX.
"adherent as d";
159 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_country as c on d.country = c.rowid";
160 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"subscription as s ON s.fk_adherent = d.rowid";
161 $sql .=
" WHERE d.entity IN (".getEntity(
'adherent').
")";
162 $sql .=
" AND d.statut <> ".Adherent::STATUS_DRAFT;
163 $sql .=
" GROUP BY c.label, c.code, d.town";
168 $langsen->setDefaultLang(
'en_US');
169 $langsen->load(
"dict");
175 $resql = $db->query($sql);
178 dol_syslog(__FILE__.
":No SQL, invalid mode '$mode'", LOG_ERR);
181 $num = $db->num_rows($resql);
184 $obj = $db->fetch_object($resql);
185 if ($mode ==
'memberbycountry') {
186 $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>')),
187 '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>')),
188 'code' => $obj->code,
190 'lastdate' => $db->jdate($obj->lastdate),
191 'lastsubscriptiondate' => $db->jdate($obj->lastsubscriptiondate)
194 if ($mode ==
'memberbyregion') {
196 '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 ==
'memberbystate') {
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)
213 if ($mode ==
'memberbytown') {
214 $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>')),
215 '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>')),
216 'label2' => ($obj->label2 ? $obj->label2 :
'<span class="opacitymedium">'.$langs->trans(
"Unknown").
'</span>'),
218 'lastdate' => $db->jdate($obj->lastdate),
219 'lastsubscriptiondate' => $db->jdate($obj->lastsubscriptiondate)
238if ($mode && !count($data)) {
239 print $langs->trans(
"NoValidatedMemberYet").
'<br>';
242 if ($mode ==
'memberbycountry') {
243 print
'<span class="opacitymedium">'.$langs->trans(
"MembersByCountryDesc").
'</span><br>';
244 } elseif ($mode ==
'memberbystate') {
245 print
'<span class="opacitymedium">'.$langs->trans(
"MembersByStateDesc").
'</span><br>';
246 } elseif ($mode ==
'memberbytown') {
247 print
'<span class="opacitymedium">'.$langs->trans(
"MembersByTownDesc").
'</span><br>';
248 } elseif ($mode ==
'memberbyregion') {
249 print
'<span class="opacitymedium">'.$langs->trans(
"MembersByRegion").
'</span><br>';
251 print
'<span class="opacitymedium">'.$langs->trans(
"MembersStatisticsDesc").
'</span><br>';
253 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?mode=memberbycountry">'.$langs->trans(
"MembersStatisticsByCountries").
'</a><br>';
255 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?mode=memberbystate">'.$langs->trans(
"MembersStatisticsByState").
'</a><br>';
257 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?mode=memberbytown">'.$langs->trans(
"MembersStatisticsByTown").
'</a><br>';
259 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?mode=memberbyregion">'.$langs->trans(
"MembersStatisticsByRegion").
'</a><br>';
266if (count($arrayjs) && $mode ==
'memberbycountry') {
267 global $theme_bordercolor, $theme_datacolor, $theme_bgcolor, $theme_bgcoloronglet;
268 $color_file = DOL_DOCUMENT_ROOT.
'/theme/'.
$conf->theme.
'/theme_vars.inc.php';
269 if (is_readable($color_file)) {
275 print
"\n<script type='text/javascript'>\n";
276 print
"google.load('visualization', '1', {'packages': ['geomap']});\n";
277 print
"google.setOnLoadCallback(drawMap);\n";
278 print
"function drawMap() {\n\tvar data = new google.visualization.DataTable();\n";
281 print
"\tdata.addRows(".count($data).
");\n";
282 print
"\tdata.addColumn('string', 'Country');\n";
283 print
"\tdata.addColumn('number', 'Number');\n";
287 foreach ($data as $val) {
288 $valcountry = strtoupper($val[
'code']);
290 if ($valcountry ==
'Great Britain') {
291 $valcountry =
'United Kingdom';
293 print
"\tdata.setValue(".$i.
", 0, \"".$valcountry.
"\");\n";
294 print
"\tdata.setValue(".$i.
", 1, ".$val[
'nb'].
");\n";
302 print
"\tvar options = {};\n";
303 print
"\toptions['dataMode'] = 'regions';\n";
304 print
"\toptions['showZoomOut'] = false;\n";
306 print
"\toptions['width'] = ".$graphwidth.
";\n";
307 print
"\toptions['height'] = ".$graphheight.
";\n";
308 print
"\toptions['colors'] = [0x".colorArrayToHex($theme_datacolor[1],
'BBBBBB').
", 0x".
colorArrayToHex($theme_datacolor[0],
'444444').
"];\n";
309 print
"\tvar container = document.getElementById('".$mode.
"');\n";
310 print
"\tvar geomap = new google.visualization.GeoMap(container);\n";
311 print
"\tgeomap.draw(data, options);\n";
316 print
'<div class="center" id="'.$mode.
'"></div>'.
"\n";
321 print
'<div class="div-table-responsive">';
322 print
'<table class="liste centpercent noborder">';
323 print
'<tr class="liste_titre">';
324 print
'<th>'.$label.
'</th>';
325 if (isset($label2)) {
326 print
'<th class="center">'.$label2.
'</th>';
328 print
'<th class="right">'.$langs->trans(
"NbOfMembers").
' <span class="opacitymedium">('.$langs->trans(
"AllTime").
')</span></th>';
329 print
'<th class="center">'.$langs->trans(
"LastMemberDate").
'</th>';
330 print
'<th class="center">'.$langs->trans(
"LatestSubscriptionDate").
'</th>';
333 foreach ($data as $val) {
334 print
'<tr class="oddeven">';
335 print
'<td>'.$val[
'label'].
'</td>';
336 if (isset($label2)) {
337 print
'<td class="center">'.$val[
'label2'].
'</td>';
339 print
'<td class="right">'.$val[
'nb'].
'</td>';
340 print
'<td class="center">'.dol_print_date($val[
'lastdate'],
'dayhour').
'</td>';
341 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.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
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.