* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ /** * \file htdocs/adherents/stats/geo.php * \ingroup member * \brief Page with geographical statistics on members */ require '../../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/member.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php'; $graphwidth=DolGraph::getDefaultGraphSizeForStats('width',700); $mapratio = 0.5; $graphheight = round($graphwidth * $mapratio); $mode=GETPOST('mode')?GETPOST('mode'):''; // Security check if ($user->societe_id > 0) { $action = ''; $socid = $user->societe_id; } $result=restrictedArea($user,'adherent','','','cotisation'); $year = strftime("%Y", time()); $startyear=$year-2; $endyear=$year; $langs->load("members"); $langs->load("companies"); /* * View */ $arrayjs=array('http://www.google.com/jsapi'); if (! empty($conf->dol_use_jmobile)) $arrayjs=array(); llxHeader('','','','',0,0,$arrayjs); $title=$langs->trans("Statistics"); if ($mode == 'memberbycountry') $title=$langs->trans("MembersStatisticsByCountries"); if ($mode == 'memberbystate') $title=$langs->trans("MembersStatisticsByState"); if ($mode == 'memberbytown') $title=$langs->trans("MembersStatisticsByTown"); if ($mode == 'memberbyregion') $title=$langs->trans("MembersStatisticsByRegion"); print_fiche_titre($title, $mesg); dol_mkdir($dir); if ($mode) { // Define sql if ($mode == 'memberbycountry') { $label=$langs->trans("Country"); $tab='statscountry'; $data = array(); $sql.="SELECT COUNT(d.rowid) as nb, MAX(d.datevalid) as lastdate, c.code, c.label"; $sql.=" FROM ".MAIN_DB_PREFIX."adherent as d LEFT JOIN ".MAIN_DB_PREFIX."c_country as c on d.country = c.rowid"; $sql.=" WHERE d.entity IN (".getEntity().")"; $sql.=" AND d.statut = 1"; $sql.=" GROUP BY c.label, c.code"; //print $sql; } if ($mode == 'memberbystate') { $label=$langs->trans("Country"); $label2=$langs->trans("State"); $tab='statsstate'; $data = array(); $sql.="SELECT COUNT(d.rowid) as nb, MAX(d.datevalid) as lastdate, co.code, co.label, c.nom as label2"; // $sql.=" FROM ".MAIN_DB_PREFIX."adherent as d LEFT JOIN ".MAIN_DB_PREFIX."c_departements as c on d.state_id = c.rowid"; $sql.=" LEFT JOIN ".MAIN_DB_PREFIX."c_regions as r on c.fk_region = r.code_region"; $sql.=" LEFT JOIN ".MAIN_DB_PREFIX."c_country as co on d.country = co.rowid"; $sql.=" WHERE d.entity IN (".getEntity().")"; $sql.=" AND d.statut = 1"; $sql.=" GROUP BY co.label, co.code, c.nom"; //print $sql; } if ($mode == 'memberbyregion') // { $label=$langs->trans("Country"); $label2=$langs->trans("Region"); //département $tab='statsregion'; //onglet $data = array(); //tableau de donnée $sql.="SELECT COUNT(d.rowid) as nb, MAX(d.datevalid) as lastdate, co.code, co.label, r.nom as label2"; $sql.=" FROM ".MAIN_DB_PREFIX."adherent as d LEFT JOIN ".MAIN_DB_PREFIX."c_departements as c on d.state_id = c.rowid"; $sql.=" LEFT JOIN ".MAIN_DB_PREFIX."c_regions as r on c.fk_region = r.code_region"; $sql.=" LEFT JOIN ".MAIN_DB_PREFIX."c_country as co on d.country = co.rowid"; $sql.=" WHERE d.entity IN (".getEntity().")"; $sql.=" AND d.statut = 1"; $sql.=" GROUP BY co.label, co.code, r.nom"; //+ //print $sql; } if ($mode == 'memberbytown') { $label=$langs->trans("Country"); $label2=$langs->trans("Town"); $tab='statstown'; $data = array(); $sql.="SELECT COUNT(d.rowid) as nb, MAX(d.datevalid) as lastdate, c.code, c.label, d.town as label2"; $sql.=" FROM ".MAIN_DB_PREFIX."adherent as d"; $sql.=" LEFT JOIN ".MAIN_DB_PREFIX."c_country as c on d.country = c.rowid"; $sql.=" WHERE d.entity IN (".getEntity().")"; $sql.=" AND d.statut = 1"; $sql.=" GROUP BY c.label, c.code, d.town"; //print $sql; } $langsen=new Translate('',$conf); $langsen->setDefaultLang('en_US'); $langsen->load("dict"); //print $langsen->trans("Country"."FI");exit; // Define $data array dol_syslog("Count member", LOG_DEBUG); $resql=$db->query($sql); if ($resql) { $num=$db->num_rows($resql); $i=0; while ($i < $num) { $obj=$db->fetch_object($resql); if ($mode == 'memberbycountry') { $data[]=array('label'=>(($obj->code && $langs->trans("Country".$obj->code)!="Country".$obj->code)?$langs->trans("Country".$obj->code):($obj->label?$obj->label:$langs->trans("Unknown"))), 'label_en'=>(($obj->code && $langsen->transnoentitiesnoconv("Country".$obj->code)!="Country".$obj->code)?$langsen->transnoentitiesnoconv("Country".$obj->code):($obj->label?$obj->label:$langs->trans("Unknown"))), 'code'=>$obj->code, 'nb'=>$obj->nb, 'lastdate'=>$db->jdate($obj->lastdate) ); } if ($mode == 'memberbyregion') //+ { $data[]=array('label'=>(($obj->code && $langs->trans("Country".$obj->code)!="Country".$obj->code)?$langs->trans("Country".$obj->code):($obj->label?$obj->label:$langs->trans("Unknown"))), 'label_en'=>(($obj->code && $langsen->transnoentitiesnoconv("Country".$obj->code)!="Country".$obj->code)?$langsen->transnoentitiesnoconv("Country".$obj->code):($obj->label?$obj->label:$langs->trans("Unknown"))), 'label2'=>($obj->label2?$obj->label2:$langs->trans("Unknown")), 'nb'=>$obj->nb, 'lastdate'=>$db->jdate($obj->lastdate) ); } if ($mode == 'memberbystate') { $data[]=array('label'=>(($obj->code && $langs->trans("Country".$obj->code)!="Country".$obj->code)?$langs->trans("Country".$obj->code):($obj->label?$obj->label:$langs->trans("Unknown"))), 'label_en'=>(($obj->code && $langsen->transnoentitiesnoconv("Country".$obj->code)!="Country".$obj->code)?$langsen->transnoentitiesnoconv("Country".$obj->code):($obj->label?$obj->label:$langs->trans("Unknown"))), 'label2'=>($obj->label2?$obj->label2:$langs->trans("Unknown")), 'nb'=>$obj->nb, 'lastdate'=>$db->jdate($obj->lastdate) ); } if ($mode == 'memberbytown') { $data[]=array('label'=>(($obj->code && $langs->trans("Country".$obj->code)!="Country".$obj->code)?$langs->trans("Country".$obj->code):($obj->label?$obj->label:$langs->trans("Unknown"))), 'label_en'=>(($obj->code && $langsen->transnoentitiesnoconv("Country".$obj->code)!="Country".$obj->code)?$langsen->transnoentitiesnoconv("Country".$obj->code):($obj->label?$obj->label:$langs->trans("Unknown"))), 'label2'=>($obj->label2?$obj->label2:$langs->trans("Unknown")), 'nb'=>$obj->nb, 'lastdate'=>$db->jdate($obj->lastdate) ); } $i++; } $db->free($resql); } else { dol_print_error($db); } } $head = member_stats_prepare_head($adh); dol_fiche_head($head, $tab, $langs->trans("Statistics"), 0, 'user'); // Print title if ($mode && ! count($data)) { print $langs->trans("NoValidatedMemberYet").'
'; print '
'; } else { if ($mode == 'memberbycountry') print $langs->trans("MembersByCountryDesc").'
'; else if ($mode == 'memberbystate') print $langs->trans("MembersByStateDesc").'
'; else if ($mode == 'memberbytown') print $langs->trans("MembersByTownDesc").'
'; else if ($mode == 'memberbyregion') print $langs->trans("MembersByRegion").'
';//+ else { print $langs->trans("MembersStatisticsDesc").'
'; print '
'; print ''.$langs->trans("MembersStatisticsByCountries").'
'; print '
'; print ''.$langs->trans("MembersStatisticsByState").'
'; print '
'; print ''.$langs->trans("MembersStatisticsByTown").'
'; print '
';//+ print ''.$langs->trans("MembersStatisticsByRegion").'
';//+ } print '
'; } // Show graphics if (count($arrayjs) && $mode == 'memberbycountry') { $color_file = DOL_DOCUMENT_ROOT.'/theme/'.$conf->theme.'/graph-color.php'; if (is_readable($color_file)) include_once $color_file; // Assume we've already included the proper headers so just call our script inline // More doc: https://developers.google.com/chart/interactive/docs/gallery/geomap?hl=fr-FR print "\n\n"; // print the div tag that will contain the map print '
'."\n"; print '
'; } if ($mode) { // Print array / Affiche le tableau print ''; print ''; print ''; if ($label2) print ''; print ''; print ''; print ''; $oldyear=0; $var=true; foreach ($data as $val) { $year = $val['year']; $var=!$var; print ''; print ''; if ($label2) print ''; print ''; print ''; print ''; $oldyear=$year; } print '
'.$label.''.$label2.''.$langs->trans("NbOfMembers").''.$langs->trans("LastMemberDate").'
'.$val['label'].''.$val['label2'].''.$val['nb'].''.dol_print_date($val['lastdate'],'dayhour').'
'; } dol_fiche_end(); llxFooter(); $db->close();