1<?php 2/* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org> 3 * Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net> 4 * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com> 5 * 6 * This program is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation; either version 3 of the License, or 9 * (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program. If not, see <https://www.gnu.org/licenses/>. 18 */ 19 20/** 21 * \file htdocs/adherents/stats/index.php 22 * \ingroup member 23 * \brief Page of subscription members statistics 24 */ 25 26require '../../main.inc.php'; 27require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php'; 28require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherentstats.class.php'; 29require_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php'; 30require_once DOL_DOCUMENT_ROOT.'/core/lib/member.lib.php'; 31 32$WIDTH = DolGraph::getDefaultGraphSizeForStats('width'); 33$HEIGHT = DolGraph::getDefaultGraphSizeForStats('height'); 34 35$userid = GETPOST('userid', 'int'); if ($userid < 0) { 36 $userid = 0; 37} 38$socid = GETPOST('socid', 'int'); if ($socid < 0) { 39 $socid = 0; 40} 41 42// Security check 43if ($user->socid > 0) { 44 $action = ''; 45 $socid = $user->socid; 46} 47$result = restrictedArea($user, 'adherent', '', '', 'cotisation'); 48 49$year = strftime("%Y", time()); 50$startyear = $year - (empty($conf->global->MAIN_STATS_GRAPHS_SHOW_N_YEARS) ? 2 : max(1, min(10, $conf->global->MAIN_STATS_GRAPHS_SHOW_N_YEARS))); 51$endyear = $year; 52 53// Load translation files required by the page 54$langs->loadLangs(array("companies", "members")); 55 56 57/* 58 * View 59 */ 60 61$memberstatic = new Adherent($db); 62$form = new Form($db); 63 64$title = $langs->trans("SubscriptionsStatistics"); 65llxHeader('', $title); 66 67print load_fiche_titre($title, '', $memberstatic->picto); 68 69$dir = $conf->adherent->dir_temp; 70 71dol_mkdir($dir); 72 73$stats = new AdherentStats($db, $socid, $userid); 74 75// Build graphic number of object 76$data = $stats->getNbByMonthWithPrevYear($endyear, $startyear); 77//var_dump($data); 78// $data = array(array('Lib',val1,val2,val3),...) 79 80 81$filenamenb = $dir.'/subscriptionsnbinyear-'.$year.'.png'; 82$fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=memberstats&file=subscriptionsnbinyear-'.$year.'.png'; 83 84 85$px1 = new DolGraph(); 86$mesg = $px1->isGraphKo(); 87if (!$mesg) { 88 $px1->SetData($data); 89 $i = $startyear; 90 while ($i <= $endyear) { 91 $legend[] = $i; 92 $i++; 93 } 94 $px1->SetLegend($legend); 95 $px1->SetMaxValue($px1->GetCeilMaxValue()); 96 $px1->SetMinValue(min(0, $px1->GetFloorMinValue())); 97 $px1->SetWidth($WIDTH); 98 $px1->SetHeight($HEIGHT); 99 $px1->SetYLabel($langs->trans("NbOfSubscriptions")); 100 $px1->SetShading(3); 101 $px1->SetHorizTickIncrement(1); 102 $px1->mode = 'depth'; 103 $px1->SetTitle($langs->trans("NbOfSubscriptions")); 104 105 $px1->draw($filenamenb, $fileurlnb); 106} 107 108// Build graphic amount of object 109$data = $stats->getAmountByMonthWithPrevYear($endyear, $startyear); 110//var_dump($data); 111// $data = array(array('Lib',val1,val2,val3),...) 112 113$filenameamount = $dir.'/subscriptionsamountinyear-'.$year.'.png'; 114$fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=memberstats&file=subscriptionsamountinyear-'.$year.'.png'; 115 116$px2 = new DolGraph(); 117$mesg = $px2->isGraphKo(); 118if (!$mesg) { 119 $px2->SetData($data); 120 $i = $startyear; 121 while ($i <= $endyear) { 122 $legend[] = $i; 123 $i++; 124 } 125 $px2->SetLegend($legend); 126 $px2->SetMaxValue($px2->GetCeilMaxValue()); 127 $px2->SetMinValue(min(0, $px2->GetFloorMinValue())); 128 $px2->SetWidth($WIDTH); 129 $px2->SetHeight($HEIGHT); 130 $px2->SetYLabel($langs->trans("AmountOfSubscriptions")); 131 $px2->SetShading(3); 132 $px2->SetHorizTickIncrement(1); 133 $px2->mode = 'depth'; 134 $px2->SetTitle($langs->trans("AmountOfSubscriptions")); 135 136 $px2->draw($filenameamount, $fileurlamount); 137} 138 139 140$head = member_stats_prepare_head($memberstatic); 141 142print dol_get_fiche_head($head, 'statssubscription', '', -1, ''); 143 144 145print '<div class="fichecenter"><div class="fichethirdleft">'; 146 147// Show filter box 148/*print '<form name="stats" method="POST" action="'.$_SERVER["PHP_SELF"].'">'; 149print '<input type="hidden" name="token" value="'.newToken().'">'; 150 151print '<table class="border centpercent">'; 152print '<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans("Filter").'</td></tr>'; 153print '<tr><td>'.$langs->trans("Member").'</td><td>'; 154print img_picto('', 'company', 'class="pictofixedwidth"'); 155print $form->select_company($id,'memberid','',1); 156print '</td></tr>'; 157print '<tr><td>'.$langs->trans("User").'</td><td>'; 158print img_picto('', 'user', 'class="pictofixedwidth"'); 159print $form->select_dolusers($userid, 'userid', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'widthcentpercentminusx maxwidth300'); 160print '</td></tr>'; 161print '<tr><td class="center" colspan="2"><input type="submit" name="submit" class="button small" value="'.$langs->trans("Refresh").'"></td></tr>'; 162print '</table>'; 163print '</form>'; 164print '<br><br>'; 165*/ 166 167// Show array 168$data = $stats->getAllByYear(); 169 170 171print '<div class="div-table-responsive-no-min">'; 172print '<table class="noborder">'; 173print '<tr class="liste_titre" height="24">'; 174print '<td class="center">'.$langs->trans("Year").'</td>'; 175print '<td class="right">'.$langs->trans("NbOfSubscriptions").'</td>'; 176print '<td class="right">'.$langs->trans("AmountTotal").'</td>'; 177print '<td class="right">'.$langs->trans("AmountAverage").'</td>'; 178print '</tr>'; 179 180$oldyear = 0; 181foreach ($data as $val) { 182 $year = $val['year']; 183 while ($oldyear > $year + 1) { // If we have empty year 184 $oldyear--; 185 print '<tr class="oddeven" height="24">'; 186 print '<td class="center">'; 187 //print '<a href="month.php?year='.$oldyear.'&mode='.$mode.'">'; 188 print $oldyear; 189 //print '</a>'; 190 print '</td>'; 191 print '<td class="right">0</td>'; 192 print '<td class="right amount nowraponall">0</td>'; 193 print '<td class="right amount nowraponall">0</td>'; 194 print '</tr>'; 195 } 196 print '<tr class="oddeven" height="24">'; 197 print '<td class="center">'; 198 //print '<a href="month.php?year='.$year.'">'; 199 print $year; 200 //print '</a>'; 201 print '</td>'; 202 print '<td class="right">'.$val['nb'].'</td>'; 203 print '<td class="right amount nowraponall"><span class="amount">'.price(price2num($val['total'], 'MT'), 1).'</span></td>'; 204 print '<td class="right amount nowraponall"><span class="amount">'.price(price2num($val['avg'], 'MT'), 1).'</span></td>'; 205 print '</tr>'; 206 $oldyear = $year; 207} 208 209print '</table>'; 210print '</div>'; 211 212 213print '</div><div class="fichetwothirdright"><div class="ficheaddleft">'; 214 215 216// Show graphs 217print '<table class="border centpercent"><tr class="pair nohover"><td class="center">'; 218if ($mesg) { 219 print $mesg; 220} else { 221 print $px1->show(); 222 print "<br>\n"; 223 print $px2->show(); 224} 225print '</td></tr></table>'; 226 227 228print '</div></div></div>'; 229print '<div style="clear:both"></div>'; 230 231 232print dol_get_fiche_end(); 233 234// End of page 235llxFooter(); 236$db->close(); 237