25require
'../../main.inc.php';
26require_once DOL_DOCUMENT_ROOT.
'/core/lib/member.lib.php';
27require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
28require_once DOL_DOCUMENT_ROOT.
'/core/class/dolgraph.class.php';
29require_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php';
33$graphheight = round($graphwidth * $mapratio);
39if ($user->socid > 0) {
41 $socid = $user->socid;
46$startyear = $year - (empty($conf->global->MAIN_STATS_GRAPHS_SHOW_N_YEARS) ? 2 : max(1, min(10, $conf->global->MAIN_STATS_GRAPHS_SHOW_N_YEARS)));
50$langs->loadLangs(array(
"companies",
"members",
"banks"));
59$arrayjs = array(
'https://www.google.com/jsapi');
60if (!empty($conf->dol_use_jmobile)) {
64$title = $langs->trans(
"Statistics");
65if ($mode ==
'memberbycountry') {
66 $title = $langs->trans(
"MembersStatisticsByCountries");
68if ($mode ==
'memberbystate') {
69 $title = $langs->trans(
"MembersStatisticsByState");
71if ($mode ==
'memberbytown') {
72 $title = $langs->trans(
"MembersStatisticsByTown");
74if ($mode ==
'memberbyregion') {
75 $title = $langs->trans(
"MembersStatisticsByRegion");
78llxHeader(
'', $title,
'',
'', 0, 0, $arrayjs);
86 if ($mode ==
'memberbycountry') {
87 $label = $langs->trans(
"Country");
88 $tab =
'statscountry';
91 $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";
92 $sql .=
" FROM ".MAIN_DB_PREFIX.
"adherent as d";
93 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_country as c on d.country = c.rowid";
94 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"subscription as s ON s.fk_adherent = d.rowid";
95 $sql .=
" WHERE d.entity IN (".getEntity(
'adherent').
")";
96 $sql .=
" AND d.statut <> ".Adherent::STATUS_DRAFT;
97 $sql .=
" GROUP BY c.label, c.code";
101 if ($mode ==
'memberbystate') {
102 $label = $langs->trans(
"Country");
103 $label2 = $langs->trans(
"State");
107 $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";
108 $sql .=
" FROM ".MAIN_DB_PREFIX.
"adherent as d";
109 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_departements as c on d.state_id = c.rowid";
110 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_regions as r on c.fk_region = r.code_region";
111 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_country as co on d.country = co.rowid";
112 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"subscription as s ON s.fk_adherent = d.rowid";
113 $sql .=
" WHERE d.entity IN (".getEntity(
'adherent').
")";
114 $sql .=
" AND d.statut <> ".Adherent::STATUS_DRAFT;
115 $sql .=
" GROUP BY co.label, co.code, c.nom";
118 if ($mode ==
'memberbyregion') {
119 $label = $langs->trans(
"Country");
120 $label2 = $langs->trans(
"Region");
121 $tab =
'statsregion';
124 $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";
125 $sql .=
" FROM ".MAIN_DB_PREFIX.
"adherent as d";
126 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_departements as c on d.state_id = c.rowid";
127 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_regions as r on c.fk_region = r.code_region";
128 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_country as co on d.country = co.rowid";
129 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"subscription as s ON s.fk_adherent = d.rowid";
130 $sql .=
" WHERE d.entity IN (".getEntity(
'adherent').
")";
131 $sql .=
" AND d.statut <> ".Adherent::STATUS_DRAFT;
132 $sql .=
" GROUP BY co.label, co.code, r.nom";
135 if ($mode ==
'memberbytown') {
136 $label = $langs->trans(
"Country");
137 $label2 = $langs->trans(
"Town");
141 $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";
142 $sql .=
" FROM ".MAIN_DB_PREFIX.
"adherent as d";
143 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_country as c on d.country = c.rowid";
144 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"subscription as s ON s.fk_adherent = d.rowid";
145 $sql .=
" WHERE d.entity IN (".getEntity(
'adherent').
")";
146 $sql .=
" AND d.statut <> ".Adherent::STATUS_DRAFT;
147 $sql .=
" GROUP BY c.label, c.code, d.town";
152 $langsen->setDefaultLang(
'en_US');
153 $langsen->load(
"dict");
158 $resql = $db->query($sql);
160 $num = $db->num_rows($resql);
163 $obj = $db->fetch_object($resql);
164 if ($mode ==
'memberbycountry') {
165 $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>')),
166 '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>')),
169 'lastdate'=>$db->jdate($obj->lastdate),
170 'lastsubscriptiondate'=>$db->jdate($obj->lastsubscriptiondate)
173 if ($mode ==
'memberbyregion') {
175 '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>')),
176 '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>')),
177 'label2'=>($obj->label2 ? $obj->label2 :
'<span class="opacitymedium">'.$langs->trans(
"Unknown").
'</span>'),
179 'lastdate'=>$db->jdate($obj->lastdate),
180 'lastsubscriptiondate'=>$db->jdate($obj->lastsubscriptiondate)
183 if ($mode ==
'memberbystate') {
184 $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>')),
185 '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>')),
186 'label2'=>($obj->label2 ? $obj->label2 :
'<span class="opacitymedium">'.$langs->trans(
"Unknown").
'</span>'),
188 'lastdate'=>$db->jdate($obj->lastdate),
189 'lastsubscriptiondate'=>$db->jdate($obj->lastsubscriptiondate)
192 if ($mode ==
'memberbytown') {
193 $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>')),
194 '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>')),
195 'label2'=>($obj->label2 ? $obj->label2 :
'<span class="opacitymedium">'.$langs->trans(
"Unknown").
'</span>'),
197 'lastdate'=>$db->jdate($obj->lastdate),
198 'lastsubscriptiondate'=>$db->jdate($obj->lastsubscriptiondate)
217if ($mode && !count($data)) {
218 print $langs->trans(
"NoValidatedMemberYet").
'<br>';
221 if ($mode ==
'memberbycountry') {
222 print
'<span class="opacitymedium">'.$langs->trans(
"MembersByCountryDesc").
'</span><br>';
223 } elseif ($mode ==
'memberbystate') {
224 print
'<span class="opacitymedium">'.$langs->trans(
"MembersByStateDesc").
'</span><br>';
225 } elseif ($mode ==
'memberbytown') {
226 print
'<span class="opacitymedium">'.$langs->trans(
"MembersByTownDesc").
'</span><br>';
227 } elseif ($mode ==
'memberbyregion') {
228 print
'<span class="opacitymedium">'.$langs->trans(
"MembersByRegion").
'</span><br>';
230 print
'<span class="opacitymedium">'.$langs->trans(
"MembersStatisticsDesc").
'</span><br>';
232 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?mode=memberbycountry">'.$langs->trans(
"MembersStatisticsByCountries").
'</a><br>';
234 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?mode=memberbystate">'.$langs->trans(
"MembersStatisticsByState").
'</a><br>';
236 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?mode=memberbytown">'.$langs->trans(
"MembersStatisticsByTown").
'</a><br>';
238 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?mode=memberbyregion">'.$langs->trans(
"MembersStatisticsByRegion").
'</a><br>';
245if (count($arrayjs) && $mode ==
'memberbycountry') {
246 $color_file = DOL_DOCUMENT_ROOT.
'/theme/'.$conf->theme.
'/theme_vars.inc.php';
247 if (is_readable($color_file)) {
253 print
"\n<script type='text/javascript'>\n";
254 print
"google.load('visualization', '1', {'packages': ['geomap']});\n";
255 print
"google.setOnLoadCallback(drawMap);\n";
256 print
"function drawMap() {\n\tvar data = new google.visualization.DataTable();\n";
259 print
"\tdata.addRows(".count($data).
");\n";
260 print
"\tdata.addColumn('string', 'Country');\n";
261 print
"\tdata.addColumn('number', 'Number');\n";
265 foreach ($data as $val) {
266 $valcountry = strtoupper($val[
'code']);
268 if ($valcountry ==
'Great Britain') {
269 $valcountry =
'United Kingdom';
271 print
"\tdata.setValue(".$i.
", 0, \"".$valcountry.
"\");\n";
272 print
"\tdata.setValue(".$i.
", 1, ".$val[
'nb'].
");\n";
280 print
"\tvar options = {};\n";
281 print
"\toptions['dataMode'] = 'regions';\n";
282 print
"\toptions['showZoomOut'] = false;\n";
284 print
"\toptions['width'] = ".$graphwidth.
";\n";
285 print
"\toptions['height'] = ".$graphheight.
";\n";
286 print
"\toptions['colors'] = [0x".colorArrayToHex($theme_datacolor[1],
'BBBBBB').
", 0x".
colorArrayToHex($theme_datacolor[0],
'444444').
"];\n";
287 print
"\tvar container = document.getElementById('".$mode.
"');\n";
288 print
"\tvar geomap = new google.visualization.GeoMap(container);\n";
289 print
"\tgeomap.draw(data, options);\n";
294 print
'<div class="center" id="'.$mode.
'"></div>'.
"\n";
299 print
'<div class="div-table-responsive">';
300 print
'<table class="liste centpercent">';
301 print
'<tr class="liste_titre">';
302 print
'<td>'.$label.
'</td>';
303 if (isset($label2)) {
304 print
'<td class="center">'.$label2.
'</td>';
306 print
'<td class="right">'.$langs->trans(
"NbOfMembers").
' <span class="opacitymedium">('.$langs->trans(
"AllTime").
')</span></td>';
307 print
'<td class="center">'.$langs->trans(
"LastMemberDate").
'</td>';
308 print
'<td class="center">'.$langs->trans(
"LatestSubscriptionDate").
'</td>';
311 foreach ($data as $val) {
312 $year = isset($val[
'year']) ? $val[
'year'] :
'';
313 print
'<tr class="oddeven">';
314 print
'<td>'.$val[
'label'].
'</td>';
315 if (isset($label2)) {
316 print
'<td class="center">'.$val[
'label2'].
'</td>';
318 print
'<td class="right">'.$val[
'nb'].
'</td>';
319 print
'<td class="center">'.dol_print_date($val[
'lastdate'],
'dayhour').
'</td>';
320 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($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
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_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_get_fiche_end($notab=0)
Return tab footer of a card.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_now($mode='auto')
Return date for now.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
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 informations.
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.