28require
'../../main.inc.php';
36require_once DOL_DOCUMENT_ROOT.
'/core/lib/member.lib.php';
37require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
38require_once DOL_DOCUMENT_ROOT.
'/core/class/dolgraph.class.php';
39require_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php';
43$graphheight = round($graphwidth * $mapratio);
49if ($user->socid > 0) {
51 $socid = $user->socid;
60$langs->loadLangs(array(
"companies",
"members",
"banks"));
69$arrayjs = array(
'https://www.google.com/jsapi');
70if (!empty($conf->dol_use_jmobile)) {
74$title = $langs->trans(
"MembershipStatistics");
76$help_url =
'EN:Module_Services_En|FR:Module_Services|ES:Módulo_Servicios|DE:Modul_Mitglieder';
78llxHeader(
'', $title, $help_url,
'', 0, 0, $arrayjs,
'',
'',
'mod-member page-stats_geo');
90 if ($mode ==
'memberbycountry') {
91 $label = $langs->trans(
"Country");
92 $tab =
'statscountry';
94 $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";
95 $sql .=
" FROM ".MAIN_DB_PREFIX.
"adherent as d";
96 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_country as c on d.country = c.rowid";
97 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"subscription as s ON s.fk_adherent = d.rowid";
98 $sql .=
" WHERE d.entity IN (".getEntity(
'adherent').
")";
99 $sql .=
" AND d.statut <> ".Adherent::STATUS_DRAFT;
100 $sql .=
" GROUP BY c.label, c.code";
104 if ($mode ==
'memberbystate') {
105 $label = $langs->trans(
"Country");
106 $label2 = $langs->trans(
"State");
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, c.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 <> ".Adherent::STATUS_DRAFT;
118 $sql .=
" GROUP BY co.label, co.code, c.nom";
121 if ($mode ==
'memberbyregion') {
122 $label = $langs->trans(
"Country");
123 $label2 = $langs->trans(
"Region");
124 $tab =
'statsregion';
127 $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";
128 $sql .=
" FROM ".MAIN_DB_PREFIX.
"adherent as d";
129 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_departements as c on d.state_id = c.rowid";
130 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_regions as r on c.fk_region = r.code_region";
131 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_country as co on d.country = co.rowid";
132 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"subscription as s ON s.fk_adherent = d.rowid";
133 $sql .=
" WHERE d.entity IN (".getEntity(
'adherent').
")";
134 $sql .=
" AND d.statut <> ".Adherent::STATUS_DRAFT;
135 $sql .=
" GROUP BY co.label, co.code, r.nom";
138 if ($mode ==
'memberbytown') {
139 $label = $langs->trans(
"Country");
140 $label2 = $langs->trans(
"Town");
144 $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";
145 $sql .=
" FROM ".MAIN_DB_PREFIX.
"adherent as d";
146 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_country as c on d.country = c.rowid";
147 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"subscription as s ON s.fk_adherent = d.rowid";
148 $sql .=
" WHERE d.entity IN (".getEntity(
'adherent').
")";
149 $sql .=
" AND d.statut <> ".Adherent::STATUS_DRAFT;
150 $sql .=
" GROUP BY c.label, c.code, d.town";
155 $langsen->setDefaultLang(
'en_US');
156 $langsen->load(
"dict");
162 $resql = $db->query($sql);
165 dol_syslog(__FILE__.
":No SQL, invalid mode '$mode'", LOG_ERR);
168 $num = $db->num_rows($resql);
171 $obj = $db->fetch_object($resql);
172 if ($mode ==
'memberbycountry') {
174 'label' => (
string) (($obj->code && $langs->trans(
"Country".$obj->code) !=
"Country".$obj->code) ?
picto_from_langcode($obj->code,
'class="saturatemedium paddingrightonly"', 1).
' '.$langs->trans(
"Country".$obj->code) : ($obj->label ? $obj->label :
'<span class="opacitymedium">'.$langs->trans(
"Unknown").
'</span>')),
175 'label_en' => (string) (($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>')),
176 'code' => (string) $obj->code,
177 'nb' => (int) $obj->nb,
178 'lastdate' => $db->jdate($obj->lastdate),
179 'lastsubscriptiondate' => $db->jdate($obj->lastsubscriptiondate)
182 if ($mode ==
'memberbyregion') {
184 'label' => (
string) (($obj->code && $langs->trans(
"Country".$obj->code) !=
"Country".$obj->code) ?
picto_from_langcode($obj->code,
'class="saturatemedium paddingrightonly"', 1).
' '.$langs->trans(
"Country".$obj->code) : ($obj->label ? $obj->label :
'<span class="opacitymedium">'.$langs->trans(
"Unknown").
'</span>')),
185 'label_en' => (string) (($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>')),
186 'label2' => ($obj->label2 ? $obj->label2 :
'<span class="opacitymedium">'.$langs->trans(
"Unknown").
'</span>'),
187 'nb' => (int) $obj->nb,
188 'lastdate' => $db->jdate($obj->lastdate),
189 'lastsubscriptiondate' => $db->jdate($obj->lastsubscriptiondate)
192 if ($mode ==
'memberbystate') {
194 'label' => (
string) (($obj->code && $langs->trans(
"Country".$obj->code) !=
"Country".$obj->code) ?
picto_from_langcode($obj->code,
'class="saturatemedium paddingrightonly"', 1).
' '.$langs->trans(
"Country".$obj->code) : ($obj->label ? $obj->label :
'<span class="opacitymedium">'.$langs->trans(
"Unknown").
'</span>')),
195 'label_en' => (string) (($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>')),
196 'label2' => ($obj->label2 ? $obj->label2 :
'<span class="opacitymedium">'.$langs->trans(
"Unknown").
'</span>'),
197 'nb' => (int) $obj->nb,
198 'lastdate' => $db->jdate($obj->lastdate),
199 'lastsubscriptiondate' => $db->jdate($obj->lastsubscriptiondate)
202 if ($mode ==
'memberbytown') {
204 'label' => (
string) (($obj->code && $langs->trans(
"Country".$obj->code) !=
"Country".$obj->code) ?
picto_from_langcode($obj->code,
'class="saturatemedium paddingrightonly"', 1).
' '.$langs->trans(
"Country".$obj->code) : ($obj->label ? $obj->label :
'<span class="opacitymedium">'.$langs->trans(
"Unknown").
'</span>')),
205 'label_en' => (string) (($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>')),
206 'label2' => (string) ($obj->label2 ? $obj->label2 :
'<span class="opacitymedium">'.$langs->trans(
"Unknown").
'</span>'),
207 'nb' => (int) $obj->nb,
208 'lastdate' => $db->jdate($obj->lastdate),
209 'lastsubscriptiondate' => $db->jdate($obj->lastsubscriptiondate)
228if ($mode && !count($data)) {
229 print
'<span class="opacitymedium">'.$langs->trans(
"NoValidatedMemberYet").
'</span><br>';
232 if (empty($mode) || $mode ==
'memberbycountry') {
233 print
'<span class="opacitymedium">'.$langs->trans(
"MembersByCountryDesc");
235 print $langs->trans(
"MembersByCountryDesc2");
238 } elseif ($mode ==
'memberbystate') {
239 print
'<span class="opacitymedium">'.$langs->trans(
"MembersByStateDesc").
'</span><br>';
240 } elseif ($mode ==
'memberbytown') {
241 print
'<span class="opacitymedium">'.$langs->trans(
"MembersByTownDesc").
'</span><br>';
242 } elseif ($mode ==
'memberbyregion') {
243 print
'<span class="opacitymedium">'.$langs->trans(
"MembersByRegion").
'</span><br>';
251 global $theme_bordercolor,
$theme_datacolor, $theme_bgcolor, $theme_bgcoloronglet;
252 $color_file = DOL_DOCUMENT_ROOT.
'/theme/'.$conf->theme.
'/theme_vars.inc.php';
253 if (is_readable($color_file)) {
259 print
"\n<script type='text/javascript'>\n";
260 print
"google.load('visualization', '1', {'packages': ['geomap']});\n";
261 print
"google.setOnLoadCallback(drawMap);\n";
262 print
"function drawMap() {\n\tvar data = new google.visualization.DataTable();\n";
265 print
"\tdata.addRows(".count($data).
");\n";
266 print
"\tdata.addColumn('string', 'Country');\n";
267 print
"\tdata.addColumn('number', 'Number');\n";
271 foreach ($data as $val) {
272 $valcountry = strtoupper($val[
'code']);
277 print
"\tdata.setValue(".$i.
", 0, \"".$valcountry.
"\");\n";
278 print
"\tdata.setValue(".$i.
", 1, ".$val[
'nb'].
");\n";
286 print
"\tvar options = {};\n";
287 print
"\toptions['dataMode'] = 'regions';\n";
288 print
"\toptions['showZoomOut'] = false;\n";
290 print
"\toptions['width'] = ".$graphwidth.
";\n";
291 print
"\toptions['height'] = ".$graphheight.
";\n";
293 print
"\tvar container = document.getElementById('".$mode.
"');\n";
294 print
"\tvar geomap = new google.visualization.GeoMap(container);\n";
295 print
"\tgeomap.draw(data, options);\n";
300 print
'<div class="center" id="'.$mode.
'"></div>'.
"\n";
305 print
'<div class="div-table-responsive">';
306 print
'<table class="liste centpercent noborder">';
307 print
'<tr class="liste_titre">';
308 print
'<th>'.$label.
'</th>';
309 if (isset($label2)) {
310 print
'<th class="center">'.$label2.
'</th>';
312 print
'<th class="right">'.$langs->trans(
"NbOfMembers").
' <span class="opacitymedium">('.$langs->trans(
"AllTime").
')</span></th>';
313 print
'<th class="center">'.$langs->trans(
"LastMemberDate").
'</th>';
314 print
'<th class="center">'.$langs->trans(
"LatestSubscriptionDate").
'</th>';
317 foreach ($data as $val) {
318 print
'<tr class="oddeven">';
319 print
'<td>'.$val[
'label'].
'</td>';
320 if (isset($label2)) {
321 print
'<td class="center">'.$val[
'label2'].
'</td>';
323 print
'<td class="right">'.$val[
'nb'].
'</td>';
324 print
'<td class="center">'.dol_print_date($val[
'lastdate'],
'dayhour',
'auto',
null,
false, 1).
'</td>';
325 print
'<td class="center">'.dol_print_date($val[
'lastsubscriptiondate'],
'dayhour',
'auto',
null,
false, 1).
'</td>';
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
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.
dol_now($mode='gmt')
Return date for now.
picto_from_langcode($codelang, $moreatt='', $notitlealt=0)
Return img flag of country for a language code or country code.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
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.