27require
'../../main.inc.php';
28require_once DOL_DOCUMENT_ROOT.
'/core/lib/member.lib.php';
29require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
30require_once DOL_DOCUMENT_ROOT.
'/core/class/dolgraph.class.php';
31require_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php';
35$graphheight = round($graphwidth * $mapratio);
41if ($user->socid > 0) {
43 $socid = $user->socid;
52$langs->loadLangs(array(
"companies",
"members",
"banks"));
61$arrayjs = array(
'https://www.google.com/jsapi');
62if (!empty($conf->dol_use_jmobile)) {
66$title = $langs->trans(
"Statistics");
67if ($mode ==
'memberbycountry') {
68 $title = $langs->trans(
"MembersStatisticsByCountries");
70if ($mode ==
'memberbystate') {
71 $title = $langs->trans(
"MembersStatisticsByState");
73if ($mode ==
'memberbytown') {
74 $title = $langs->trans(
"MembersStatisticsByTown");
76if ($mode ==
'memberbyregion') {
77 $title = $langs->trans(
"MembersStatisticsByRegion");
80$help_url =
'EN:Module_Services_En|FR:Module_Services|ES:Módulo_Servicios|DE:Modul_Mitglieder';
82llxHeader(
'', $title, $help_url,
'', 0, 0, $arrayjs,
'',
'',
'mod-member page-stats_geo');
90 if ($mode ==
'memberbycountry') {
91 $label = $langs->trans(
"Country");
92 $tab =
'statscountry';
95 $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";
96 $sql .=
" FROM ".MAIN_DB_PREFIX.
"adherent as d";
97 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_country as c on d.country = c.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 <> ".Adherent::STATUS_DRAFT;
101 $sql .=
" GROUP BY c.label, c.code";
105 if ($mode ==
'memberbystate') {
106 $label = $langs->trans(
"Country");
107 $label2 = $langs->trans(
"State");
111 $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";
112 $sql .=
" FROM ".MAIN_DB_PREFIX.
"adherent as d";
113 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_departements as c on d.state_id = c.rowid";
114 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_regions as r on c.fk_region = r.code_region";
115 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_country as co on d.country = co.rowid";
116 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"subscription as s ON s.fk_adherent = d.rowid";
117 $sql .=
" WHERE d.entity IN (".getEntity(
'adherent').
")";
118 $sql .=
" AND d.statut <> ".Adherent::STATUS_DRAFT;
119 $sql .=
" GROUP BY co.label, co.code, c.nom";
122 if ($mode ==
'memberbyregion') {
123 $label = $langs->trans(
"Country");
124 $label2 = $langs->trans(
"Region");
125 $tab =
'statsregion';
128 $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";
129 $sql .=
" FROM ".MAIN_DB_PREFIX.
"adherent as d";
130 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_departements as c on d.state_id = c.rowid";
131 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_regions as r on c.fk_region = r.code_region";
132 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_country as co on d.country = co.rowid";
133 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"subscription as s ON s.fk_adherent = d.rowid";
134 $sql .=
" WHERE d.entity IN (".getEntity(
'adherent').
")";
135 $sql .=
" AND d.statut <> ".Adherent::STATUS_DRAFT;
136 $sql .=
" GROUP BY co.label, co.code, r.nom";
139 if ($mode ==
'memberbytown') {
140 $label = $langs->trans(
"Country");
141 $label2 = $langs->trans(
"Town");
145 $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";
146 $sql .=
" FROM ".MAIN_DB_PREFIX.
"adherent as d";
147 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_country as c on d.country = c.rowid";
148 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"subscription as s ON s.fk_adherent = d.rowid";
149 $sql .=
" WHERE d.entity IN (".getEntity(
'adherent').
")";
150 $sql .=
" AND d.statut <> ".Adherent::STATUS_DRAFT;
151 $sql .=
" GROUP BY c.label, c.code, d.town";
156 $langsen->setDefaultLang(
'en_US');
157 $langsen->load(
"dict");
162 $resql = $db->query($sql);
164 $num = $db->num_rows($resql);
167 $obj = $db->fetch_object($resql);
168 if ($mode ==
'memberbycountry') {
169 $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>')),
170 '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>')),
171 'code' => $obj->code,
173 'lastdate' => $db->jdate($obj->lastdate),
174 'lastsubscriptiondate' => $db->jdate($obj->lastsubscriptiondate)
177 if ($mode ==
'memberbyregion') {
179 '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>')),
180 '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>')),
181 'label2' => ($obj->label2 ? $obj->label2 :
'<span class="opacitymedium">'.$langs->trans(
"Unknown").
'</span>'),
183 'lastdate' => $db->jdate($obj->lastdate),
184 'lastsubscriptiondate' => $db->jdate($obj->lastsubscriptiondate)
187 if ($mode ==
'memberbystate') {
188 $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>')),
189 '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>')),
190 'label2' => ($obj->label2 ? $obj->label2 :
'<span class="opacitymedium">'.$langs->trans(
"Unknown").
'</span>'),
192 'lastdate' => $db->jdate($obj->lastdate),
193 'lastsubscriptiondate' => $db->jdate($obj->lastsubscriptiondate)
196 if ($mode ==
'memberbytown') {
197 $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>')),
198 '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>')),
199 'label2' => ($obj->label2 ? $obj->label2 :
'<span class="opacitymedium">'.$langs->trans(
"Unknown").
'</span>'),
201 'lastdate' => $db->jdate($obj->lastdate),
202 'lastsubscriptiondate' => $db->jdate($obj->lastsubscriptiondate)
221if ($mode && !count($data)) {
222 print $langs->trans(
"NoValidatedMemberYet").
'<br>';
225 if ($mode ==
'memberbycountry') {
226 print
'<span class="opacitymedium">'.$langs->trans(
"MembersByCountryDesc").
'</span><br>';
227 } elseif ($mode ==
'memberbystate') {
228 print
'<span class="opacitymedium">'.$langs->trans(
"MembersByStateDesc").
'</span><br>';
229 } elseif ($mode ==
'memberbytown') {
230 print
'<span class="opacitymedium">'.$langs->trans(
"MembersByTownDesc").
'</span><br>';
231 } elseif ($mode ==
'memberbyregion') {
232 print
'<span class="opacitymedium">'.$langs->trans(
"MembersByRegion").
'</span><br>';
234 print
'<span class="opacitymedium">'.$langs->trans(
"MembersStatisticsDesc").
'</span><br>';
236 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?mode=memberbycountry">'.$langs->trans(
"MembersStatisticsByCountries").
'</a><br>';
238 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?mode=memberbystate">'.$langs->trans(
"MembersStatisticsByState").
'</a><br>';
240 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?mode=memberbytown">'.$langs->trans(
"MembersStatisticsByTown").
'</a><br>';
242 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?mode=memberbyregion">'.$langs->trans(
"MembersStatisticsByRegion").
'</a><br>';
249if (count($arrayjs) && $mode ==
'memberbycountry') {
250 $color_file = DOL_DOCUMENT_ROOT.
'/theme/'.$conf->theme.
'/theme_vars.inc.php';
251 if (is_readable($color_file)) {
257 print
"\n<script type='text/javascript'>\n";
258 print
"google.load('visualization', '1', {'packages': ['geomap']});\n";
259 print
"google.setOnLoadCallback(drawMap);\n";
260 print
"function drawMap() {\n\tvar data = new google.visualization.DataTable();\n";
263 print
"\tdata.addRows(".count($data).
");\n";
264 print
"\tdata.addColumn('string', 'Country');\n";
265 print
"\tdata.addColumn('number', 'Number');\n";
269 foreach ($data as $val) {
270 $valcountry = strtoupper($val[
'code']);
272 if ($valcountry ==
'Great Britain') {
273 $valcountry =
'United Kingdom';
275 print
"\tdata.setValue(".$i.
", 0, \"".$valcountry.
"\");\n";
276 print
"\tdata.setValue(".$i.
", 1, ".$val[
'nb'].
");\n";
284 print
"\tvar options = {};\n";
285 print
"\toptions['dataMode'] = 'regions';\n";
286 print
"\toptions['showZoomOut'] = false;\n";
288 print
"\toptions['width'] = ".$graphwidth.
";\n";
289 print
"\toptions['height'] = ".$graphheight.
";\n";
290 print
"\toptions['colors'] = [0x".colorArrayToHex($theme_datacolor[1],
'BBBBBB').
", 0x".
colorArrayToHex($theme_datacolor[0],
'444444').
"];\n";
291 print
"\tvar container = document.getElementById('".$mode.
"');\n";
292 print
"\tvar geomap = new google.visualization.GeoMap(container);\n";
293 print
"\tgeomap.draw(data, options);\n";
298 print
'<div class="center" id="'.$mode.
'"></div>'.
"\n";
303 print
'<div class="div-table-responsive">';
304 print
'<table class="liste centpercent">';
305 print
'<tr class="liste_titre">';
306 print
'<td>'.$label.
'</td>';
307 if (isset($label2)) {
308 print
'<td class="center">'.$label2.
'</td>';
310 print
'<td class="right">'.$langs->trans(
"NbOfMembers").
' <span class="opacitymedium">('.$langs->trans(
"AllTime").
')</span></td>';
311 print
'<td class="center">'.$langs->trans(
"LastMemberDate").
'</td>';
312 print
'<td class="center">'.$langs->trans(
"LatestSubscriptionDate").
'</td>';
315 foreach ($data as $val) {
316 $year = isset($val[
'year']) ? $val[
'year'] :
'';
317 print
'<tr class="oddeven">';
318 print
'<td>'.$val[
'label'].
'</td>';
319 if (isset($label2)) {
320 print
'<td class="center">'.$val[
'label2'].
'</td>';
322 print
'<td class="right">'.$val[
'nb'].
'</td>';
323 print
'<td class="center">'.dol_print_date($val[
'lastdate'],
'dayhour').
'</td>';
324 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 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.