dolibarr 18.0.6
index.php
Go to the documentation of this file.
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
26// Load Dolibarr environment
27require '../../main.inc.php';
28require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
29require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherentstats.class.php';
30require_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
31require_once DOL_DOCUMENT_ROOT.'/core/lib/member.lib.php';
32
35
36$userid = GETPOST('userid', 'int'); if ($userid < 0) {
37 $userid = 0;
38}
39$socid = GETPOST('socid', 'int'); if ($socid < 0) {
40 $socid = 0;
41}
42
43// Security check
44if ($user->socid > 0) {
45 $action = '';
46 $socid = $user->socid;
47}
48$result = restrictedArea($user, 'adherent', '', '', 'cotisation');
49
50$year = dol_print_date(dol_now('gmt'), "%Y", 'gmt');
51$startyear = $year - (empty($conf->global->MAIN_STATS_GRAPHS_SHOW_N_YEARS) ? 2 : max(1, min(10, $conf->global->MAIN_STATS_GRAPHS_SHOW_N_YEARS)));
52$endyear = $year;
53
54// Load translation files required by the page
55$langs->loadLangs(array("companies", "members"));
56
57
58/*
59 * View
60 */
61
62$memberstatic = new Adherent($db);
63$form = new Form($db);
64
65$title = $langs->trans("SubscriptionsStatistics");
66llxHeader('', $title);
67
68print load_fiche_titre($title, '', $memberstatic->picto);
69
70$dir = $conf->adherent->dir_temp;
71
72dol_mkdir($dir);
73
74$stats = new AdherentStats($db, $socid, $userid);
75
76// Build graphic number of object
77$data = $stats->getNbByMonthWithPrevYear($endyear, $startyear);
78//var_dump($data);
79// $data = array(array('Lib',val1,val2,val3),...)
80
81
82$filenamenb = $dir.'/subscriptionsnbinyear-'.$year.'.png';
83$fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=memberstats&file=subscriptionsnbinyear-'.$year.'.png';
84
85
86$px1 = new DolGraph();
87$mesg = $px1->isGraphKo();
88if (!$mesg) {
89 $px1->SetData($data);
90 $i = $startyear;
91 while ($i <= $endyear) {
92 $legend[] = $i;
93 $i++;
94 }
95 $px1->SetLegend($legend);
96 $px1->SetMaxValue($px1->GetCeilMaxValue());
97 $px1->SetMinValue(min(0, $px1->GetFloorMinValue()));
98 $px1->SetWidth($WIDTH);
99 $px1->SetHeight($HEIGHT);
100 $px1->SetYLabel($langs->trans("NbOfSubscriptions"));
101 $px1->SetShading(3);
102 $px1->SetHorizTickIncrement(1);
103 $px1->mode = 'depth';
104 $px1->SetTitle($langs->trans("NbOfSubscriptions"));
105
106 $px1->draw($filenamenb, $fileurlnb);
107}
108
109// Build graphic amount of object
110$data = $stats->getAmountByMonthWithPrevYear($endyear, $startyear);
111//var_dump($data);
112// $data = array(array('Lib',val1,val2,val3),...)
113
114$filenameamount = $dir.'/subscriptionsamountinyear-'.$year.'.png';
115$fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=memberstats&file=subscriptionsamountinyear-'.$year.'.png';
116
117$px2 = new DolGraph();
118$mesg = $px2->isGraphKo();
119if (!$mesg) {
120 $px2->SetData($data);
121 $i = $startyear;
122 while ($i <= $endyear) {
123 $legend[] = $i;
124 $i++;
125 }
126 $px2->SetLegend($legend);
127 $px2->SetMaxValue($px2->GetCeilMaxValue());
128 $px2->SetMinValue(min(0, $px2->GetFloorMinValue()));
129 $px2->SetWidth($WIDTH);
130 $px2->SetHeight($HEIGHT);
131 $px2->SetYLabel($langs->trans("AmountOfSubscriptions"));
132 $px2->SetShading(3);
133 $px2->SetHorizTickIncrement(1);
134 $px2->mode = 'depth';
135 $px2->SetTitle($langs->trans("AmountOfSubscriptions"));
136
137 $px2->draw($filenameamount, $fileurlamount);
138}
139
140
141$head = member_stats_prepare_head($memberstatic);
142
143print dol_get_fiche_head($head, 'statssubscription', '', -1, '');
144
145
146print '<div class="fichecenter"><div class="fichethirdleft">';
147
148// Show filter box
149/*print '<form name="stats" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
150print '<input type="hidden" name="token" value="'.newToken().'">';
151
152print '<table class="border centpercent">';
153print '<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans("Filter").'</td></tr>';
154print '<tr><td>'.$langs->trans("Member").'</td><td>';
155print img_picto('', 'company', 'class="pictofixedwidth"');
156print $form->select_company($id,'memberid','',1);
157print '</td></tr>';
158print '<tr><td>'.$langs->trans("User").'</td><td>';
159print img_picto('', 'user', 'class="pictofixedwidth"');
160print $form->select_dolusers($userid, 'userid', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'widthcentpercentminusx maxwidth300');
161print '</td></tr>';
162print '<tr><td class="center" colspan="2"><input type="submit" name="submit" class="button small" value="'.$langs->trans("Refresh").'"></td></tr>';
163print '</table>';
164print '</form>';
165print '<br><br>';
166*/
167
168// Show array
169$data = $stats->getAllByYear();
170
171
172print '<div class="div-table-responsive-no-min">';
173print '<table class="noborder">';
174print '<tr class="liste_titre" height="24">';
175print '<td class="center">'.$langs->trans("Year").'</td>';
176print '<td class="right">'.$langs->trans("NbOfSubscriptions").'</td>';
177print '<td class="right">'.$langs->trans("AmountTotal").'</td>';
178print '<td class="right">'.$langs->trans("AmountAverage").'</td>';
179print '</tr>';
180
181$oldyear = 0;
182foreach ($data as $val) {
183 $year = $val['year'];
184 while ($oldyear > $year + 1) { // If we have empty year
185 $oldyear--;
186 print '<tr class="oddeven" height="24">';
187 print '<td class="center">';
188 //print '<a href="month.php?year='.$oldyear.'&amp;mode='.$mode.'">';
189 print $oldyear;
190 //print '</a>';
191 print '</td>';
192 print '<td class="right">0</td>';
193 print '<td class="right amount nowraponall">0</td>';
194 print '<td class="right amount nowraponall">0</td>';
195 print '</tr>';
196 }
197 print '<tr class="oddeven" height="24">';
198 print '<td class="center">';
199 print '<a href="'.DOL_URL_ROOT.'/adherents/subscription/list.php?date_select='.((int) $year).'">'.$year.'</a>';
200 print '</td>';
201 print '<td class="right">'.$val['nb'].'</td>';
202 print '<td class="right amount nowraponall"><span class="amount">'.price(price2num($val['total'], 'MT'), 1).'</span></td>';
203 print '<td class="right amount nowraponall"><span class="amount">'.price(price2num($val['avg'], 'MT'), 1).'</span></td>';
204 print '</tr>';
205 $oldyear = $year;
206}
207
208print '</table>';
209print '</div>';
210
211
212print '</div><div class="fichetwothirdright">';
213
214
215// Show graphs
216print '<table class="border centpercent"><tr class="pair nohover"><td class="center">';
217if ($mesg) {
218 print $mesg;
219} else {
220 print $px1->show();
221 print "<br>\n";
222 print $px2->show();
223}
224print '</td></tr></table>';
225
226
227print '</div></div>';
228print '<div class="clearboth"></div>';
229
230
231print dol_get_fiche_end();
232
233// End of page
234llxFooter();
235$db->close();
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
Definition wrapper.php:56
llxFooter()
Empty footer.
Definition wrapper.php:70
Class to manage members of a foundation.
Class to manage statistics of members.
Class to build graphs.
static getDefaultGraphSizeForStats($direction, $defaultsize='')
getDefaultGraphSizeForStats
Class to manage generation of HTML components Only common components must be here.
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.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
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.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
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.