dolibarr  16.0.5
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 require '../../main.inc.php';
27 require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
28 require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherentstats.class.php';
29 require_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
30 require_once DOL_DOCUMENT_ROOT.'/core/lib/member.lib.php';
31 
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
43 if ($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");
65 llxHeader('', $title);
66 
67 print load_fiche_titre($title, '', $memberstatic->picto);
68 
69 $dir = $conf->adherent->dir_temp;
70 
71 dol_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();
87 if (!$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();
118 if (!$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 
142 print dol_get_fiche_head($head, 'statssubscription', '', -1, '');
143 
144 
145 print '<div class="fichecenter"><div class="fichethirdleft">';
146 
147 // Show filter box
148 /*print '<form name="stats" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
149 print '<input type="hidden" name="token" value="'.newToken().'">';
150 
151 print '<table class="border centpercent">';
152 print '<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans("Filter").'</td></tr>';
153 print '<tr><td>'.$langs->trans("Member").'</td><td>';
154 print img_picto('', 'company', 'class="pictofixedwidth"');
155 print $form->select_company($id,'memberid','',1);
156 print '</td></tr>';
157 print '<tr><td>'.$langs->trans("User").'</td><td>';
158 print img_picto('', 'user', 'class="pictofixedwidth"');
159 print $form->select_dolusers($userid, 'userid', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'widthcentpercentminusx maxwidth300');
160 print '</td></tr>';
161 print '<tr><td class="center" colspan="2"><input type="submit" name="submit" class="button small" value="'.$langs->trans("Refresh").'"></td></tr>';
162 print '</table>';
163 print '</form>';
164 print '<br><br>';
165 */
166 
167 // Show array
168 $data = $stats->getAllByYear();
169 
170 
171 print '<div class="div-table-responsive-no-min">';
172 print '<table class="noborder">';
173 print '<tr class="liste_titre" height="24">';
174 print '<td class="center">'.$langs->trans("Year").'</td>';
175 print '<td class="right">'.$langs->trans("NbOfSubscriptions").'</td>';
176 print '<td class="right">'.$langs->trans("AmountTotal").'</td>';
177 print '<td class="right">'.$langs->trans("AmountAverage").'</td>';
178 print '</tr>';
179 
180 $oldyear = 0;
181 foreach ($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.'&amp;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="'.DOL_URL_ROOT.'/adherents/subscription/list.php?date_select='.((int) $year).'">'.$year.'</a>';
199  print '</td>';
200  print '<td class="right">'.$val['nb'].'</td>';
201  print '<td class="right amount nowraponall"><span class="amount">'.price(price2num($val['total'], 'MT'), 1).'</span></td>';
202  print '<td class="right amount nowraponall"><span class="amount">'.price(price2num($val['avg'], 'MT'), 1).'</span></td>';
203  print '</tr>';
204  $oldyear = $year;
205 }
206 
207 print '</table>';
208 print '</div>';
209 
210 
211 print '</div><div class="fichetwothirdright">';
212 
213 
214 // Show graphs
215 print '<table class="border centpercent"><tr class="pair nohover"><td class="center">';
216 if ($mesg) {
217  print $mesg;
218 } else {
219  print $px1->show();
220  print "<br>\n";
221  print $px2->show();
222 }
223 print '</td></tr></table>';
224 
225 
226 print '</div></div>';
227 print '<div style="clear:both"></div>';
228 
229 
230 print dol_get_fiche_end();
231 
232 // End of page
233 llxFooter();
234 $db->close();
DolGraph\getDefaultGraphSizeForStats
static getDefaultGraphSizeForStats($direction, $defaultsize='')
getDefaultGraphSizeForStats
Definition: dolgraph.class.php:1539
restrictedArea
restrictedArea($user, $features, $objectid=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.
Definition: security.lib.php:234
load_fiche_titre
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
Definition: functions.lib.php:5204
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
DolGraph
Class to build graphs.
Definition: dolgraph.class.php:40
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
price2num
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
Definition: functions.lib.php:5661
llxFooter
llxFooter()
Footer empty.
Definition: index.php:71
AdherentStats
Class to manage statistics of members.
Definition: adherentstats.class.php:33
member_stats_prepare_head
member_stats_prepare_head($object)
Return array head with list of tabs to view object stats informations.
Definition: member.lib.php:233
Adherent
Class to manage members of a foundation.
Definition: adherent.class.php:46
llxHeader
if(!defined('NOTOKENRENEWAL')) if(!defined('NOLOGIN')) if(!defined('NOCSRFCHECK')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) if(!defined('NOIPCHECK')) if(!defined('NOBROWSERNOTIF')) llxHeader()
Header empty.
Definition: index.php:63
dol_get_fiche_head
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
Definition: functions.lib.php:1822
dol_get_fiche_end
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition: functions.lib.php:2018
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
dol_mkdir
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
Definition: functions.lib.php:6603