26require
'../../main.inc.php';
27require_once DOL_DOCUMENT_ROOT.
'/core/lib/member.lib.php';
28require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
29require_once DOL_DOCUMENT_ROOT.
'/core/class/dolgraph.class.php';
30require_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php';
34$graphheight = round($graphwidth * $mapratio);
40if ($user->socid > 0) {
42 $socid = $user->socid;
51$langs->loadLangs(array(
"companies",
"members",
"banks"));
60$arrayjs = array(
'https://www.google.com/jsapi');
61if (!empty($conf->dol_use_jmobile)) {
65$title = $langs->trans(
"Statistics");
66if ($mode ==
'memberbycountry') {
67 $title = $langs->trans(
"MembersStatisticsByCountries");
69if ($mode ==
'memberbystate') {
70 $title = $langs->trans(
"MembersStatisticsByState");
72if ($mode ==
'memberbytown') {
73 $title = $langs->trans(
"MembersStatisticsByTown");
75if ($mode ==
'memberbyregion') {
76 $title = $langs->trans(
"MembersStatisticsByRegion");
79llxHeader(
'', $title,
'',
'', 0, 0, $arrayjs);
87 if ($mode ==
'memberbycountry') {
88 $label = $langs->trans(
"Country");
89 $tab =
'statscountry';
92 $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";
93 $sql .=
" FROM ".MAIN_DB_PREFIX.
"adherent as d";
94 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_country as c on d.country = c.rowid";
95 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"subscription as s ON s.fk_adherent = d.rowid";
96 $sql .=
" WHERE d.entity IN (".getEntity(
'adherent').
")";
97 $sql .=
" AND d.statut <> ".Adherent::STATUS_DRAFT;
98 $sql .=
" GROUP BY c.label, c.code";
102 if ($mode ==
'memberbystate') {
103 $label = $langs->trans(
"Country");
104 $label2 = $langs->trans(
"State");
108 $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";
109 $sql .=
" FROM ".MAIN_DB_PREFIX.
"adherent as d";
110 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_departements as c on d.state_id = c.rowid";
111 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_regions as r on c.fk_region = r.code_region";
112 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_country as co on d.country = co.rowid";
113 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"subscription as s ON s.fk_adherent = d.rowid";
114 $sql .=
" WHERE d.entity IN (".getEntity(
'adherent').
")";
115 $sql .=
" AND d.statut <> ".Adherent::STATUS_DRAFT;
116 $sql .=
" GROUP BY co.label, co.code, c.nom";
119 if ($mode ==
'memberbyregion') {
120 $label = $langs->trans(
"Country");
121 $label2 = $langs->trans(
"Region");
122 $tab =
'statsregion';
125 $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";
126 $sql .=
" FROM ".MAIN_DB_PREFIX.
"adherent as d";
127 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_departements as c on d.state_id = c.rowid";
128 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_regions as r on c.fk_region = r.code_region";
129 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_country as co on d.country = co.rowid";
130 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"subscription as s ON s.fk_adherent = d.rowid";
131 $sql .=
" WHERE d.entity IN (".getEntity(
'adherent').
")";
132 $sql .=
" AND d.statut <> ".Adherent::STATUS_DRAFT;
133 $sql .=
" GROUP BY co.label, co.code, r.nom";
136 if ($mode ==
'memberbytown') {
137 $label = $langs->trans(
"Country");
138 $label2 = $langs->trans(
"Town");
142 $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";
143 $sql .=
" FROM ".MAIN_DB_PREFIX.
"adherent as d";
144 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_country as c on d.country = c.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 c.label, c.code, d.town";
153 $langsen->setDefaultLang(
'en_US');
154 $langsen->load(
"dict");
159 $resql = $db->query($sql);
161 $num = $db->num_rows($resql);
164 $obj = $db->fetch_object($resql);
165 if ($mode ==
'memberbycountry') {
166 $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>')),
167 '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>')),
168 'code' => $obj->code,
170 'lastdate' => $db->jdate($obj->lastdate),
171 'lastsubscriptiondate' => $db->jdate($obj->lastsubscriptiondate)
174 if ($mode ==
'memberbyregion') {
176 '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>')),
177 '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>')),
178 'label2' => ($obj->label2 ? $obj->label2 :
'<span class="opacitymedium">'.$langs->trans(
"Unknown").
'</span>'),
180 'lastdate' => $db->jdate($obj->lastdate),
181 'lastsubscriptiondate' => $db->jdate($obj->lastsubscriptiondate)
184 if ($mode ==
'memberbystate') {
185 $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>')),
186 '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>')),
187 'label2' => ($obj->label2 ? $obj->label2 :
'<span class="opacitymedium">'.$langs->trans(
"Unknown").
'</span>'),
189 'lastdate' => $db->jdate($obj->lastdate),
190 'lastsubscriptiondate' => $db->jdate($obj->lastsubscriptiondate)
193 if ($mode ==
'memberbytown') {
194 $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>')),
195 '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>')),
196 'label2' => ($obj->label2 ? $obj->label2 :
'<span class="opacitymedium">'.$langs->trans(
"Unknown").
'</span>'),
198 'lastdate' => $db->jdate($obj->lastdate),
199 'lastsubscriptiondate' => $db->jdate($obj->lastsubscriptiondate)
218if ($mode && !count($data)) {
219 print $langs->trans(
"NoValidatedMemberYet").
'<br>';
222 if ($mode ==
'memberbycountry') {
223 print
'<span class="opacitymedium">'.$langs->trans(
"MembersByCountryDesc").
'</span><br>';
224 } elseif ($mode ==
'memberbystate') {
225 print
'<span class="opacitymedium">'.$langs->trans(
"MembersByStateDesc").
'</span><br>';
226 } elseif ($mode ==
'memberbytown') {
227 print
'<span class="opacitymedium">'.$langs->trans(
"MembersByTownDesc").
'</span><br>';
228 } elseif ($mode ==
'memberbyregion') {
229 print
'<span class="opacitymedium">'.$langs->trans(
"MembersByRegion").
'</span><br>';
231 print
'<span class="opacitymedium">'.$langs->trans(
"MembersStatisticsDesc").
'</span><br>';
233 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?mode=memberbycountry">'.$langs->trans(
"MembersStatisticsByCountries").
'</a><br>';
235 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?mode=memberbystate">'.$langs->trans(
"MembersStatisticsByState").
'</a><br>';
237 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?mode=memberbytown">'.$langs->trans(
"MembersStatisticsByTown").
'</a><br>';
239 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?mode=memberbyregion">'.$langs->trans(
"MembersStatisticsByRegion").
'</a><br>';
246if (count($arrayjs) && $mode ==
'memberbycountry') {
247 $color_file = DOL_DOCUMENT_ROOT.
'/theme/'.$conf->theme.
'/theme_vars.inc.php';
248 if (is_readable($color_file)) {
254 print
"\n<script type='text/javascript'>\n";
255 print
"google.load('visualization', '1', {'packages': ['geomap']});\n";
256 print
"google.setOnLoadCallback(drawMap);\n";
257 print
"function drawMap() {\n\tvar data = new google.visualization.DataTable();\n";
260 print
"\tdata.addRows(".count($data).
");\n";
261 print
"\tdata.addColumn('string', 'Country');\n";
262 print
"\tdata.addColumn('number', 'Number');\n";
266 foreach ($data as $val) {
267 $valcountry = strtoupper($val[
'code']);
269 if ($valcountry ==
'Great Britain') {
270 $valcountry =
'United Kingdom';
272 print
"\tdata.setValue(".$i.
", 0, \"".$valcountry.
"\");\n";
273 print
"\tdata.setValue(".$i.
", 1, ".$val[
'nb'].
");\n";
281 print
"\tvar options = {};\n";
282 print
"\toptions['dataMode'] = 'regions';\n";
283 print
"\toptions['showZoomOut'] = false;\n";
285 print
"\toptions['width'] = ".$graphwidth.
";\n";
286 print
"\toptions['height'] = ".$graphheight.
";\n";
287 print
"\toptions['colors'] = [0x".colorArrayToHex($theme_datacolor[1],
'BBBBBB').
", 0x".
colorArrayToHex($theme_datacolor[0],
'444444').
"];\n";
288 print
"\tvar container = document.getElementById('".$mode.
"');\n";
289 print
"\tvar geomap = new google.visualization.GeoMap(container);\n";
290 print
"\tgeomap.draw(data, options);\n";
295 print
'<div class="center" id="'.$mode.
'"></div>'.
"\n";
300 print
'<div class="div-table-responsive">';
301 print
'<table class="liste centpercent">';
302 print
'<tr class="liste_titre">';
303 print
'<td>'.$label.
'</td>';
304 if (isset($label2)) {
305 print
'<td class="center">'.$label2.
'</td>';
307 print
'<td class="right">'.$langs->trans(
"NbOfMembers").
' <span class="opacitymedium">('.$langs->trans(
"AllTime").
')</span></td>';
308 print
'<td class="center">'.$langs->trans(
"LastMemberDate").
'</td>';
309 print
'<td class="center">'.$langs->trans(
"LatestSubscriptionDate").
'</td>';
312 foreach ($data as $val) {
313 $year = isset($val[
'year']) ? $val[
'year'] :
'';
314 print
'<tr class="oddeven">';
315 print
'<td>'.$val[
'label'].
'</td>';
316 if (isset($label2)) {
317 print
'<td class="center">'.$val[
'label2'].
'</td>';
319 print
'<td class="right">'.$val[
'nb'].
'</td>';
320 print
'<td class="center">'.dol_print_date($val[
'lastdate'],
'dayhour').
'</td>';
321 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()
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.