63 global $conf, $user, $langs;
67 $refreshaction =
'refresh_'.$this->boxcode;
77 $langs->load(
"propal");
79 $text = $langs->trans(
"BoxProposalsPerMonth", $max);
80 $this->info_box_head = array(
85 'subtext' => $langs->trans(
"Filter"),
86 'subpicto' =>
'filter.png',
87 'subclass' =>
'linkobject boxfilter',
95 $socid = $user->socid;
97 if (!$user->hasRight(
'societe',
'client',
'voir')) {
98 $prefix .=
'private-'.$user->id.
'-';
101 if ($user->hasRight(
'propal',
'lire')) {
102 $param_year =
'DOLUSER_box_'.$this->boxcode.
'_year';
103 $param_shownb =
'DOLUSER_box_'.$this->boxcode.
'_shownb';
104 $param_showtot =
'DOLUSER_box_'.$this->boxcode.
'_showtot';
106 include_once DOL_DOCUMENT_ROOT.
'/core/class/dolgraph.class.php';
107 include_once DOL_DOCUMENT_ROOT.
'/comm/propal/class/propalestats.class.php';
108 $autosetarray = preg_split(
"/[,;:]+/",
GETPOST(
'DOL_AUTOSET_COOKIE'));
109 if (in_array(
'DOLUSER_box_'.$this->boxcode, $autosetarray)) {
111 $shownb =
GETPOST($param_shownb,
'alpha');
112 $showtot =
GETPOST($param_showtot,
'alpha');
114 $tmparray = (!empty($_COOKIE[
'DOLUSER_box_'.$this->boxcode]) ? json_decode($_COOKIE[
'DOLUSER_box_'.$this->boxcode],
true) : array());
115 $endyear = (!empty($tmparray[
'year']) ? $tmparray[
'year'] :
'');
116 $shownb = (!empty($tmparray[
'shownb']) ? $tmparray[
'shownb'] :
'');
117 $showtot = (!empty($tmparray[
'showtot']) ? $tmparray[
'showtot'] :
'');
119 if (empty($shownb) && empty($showtot)) {
124 if (empty($endyear)) {
125 $endyear = $nowarray[
'year'];
127 $startyear = $endyear -
getDolGlobalInt(
'MAIN_NB_OF_YEAR_IN_WIDGET_GRAPH', 3) + 1;
129 $WIDTH = (($shownb && $showtot) || !empty($conf->dol_optimize_smallscreen)) ?
'256' :
'320';
136 $data1 = $stats->getNbByMonthWithPrevYear($endyear, $startyear, (
GETPOST(
'action',
'aZ09') == $refreshaction ? -1 : (3600 * 24)), ($WIDTH < 300 ? 2 : 0), $startmonth);
137 $datatype1 = array_pad(array(), ($endyear - $startyear + 1),
'bars');
139 $filenamenb = $dir.
"/".$prefix.
"propalsnbinyear-".$endyear.
".png";
140 $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=propalstats&file=propalsnbinyear-'.$endyear.
'.png';
143 $mesg = $px1->isGraphKo();
145 $px1->SetType($datatype1);
146 $px1->SetData($data1);
150 while ($i <= $endyear) {
151 if ($startmonth != 1) {
152 $legend[] = sprintf(
"%d/%d", $i - 2001, $i - 2000);
158 $px1->SetLegend($legend);
159 $px1->SetMaxValue($px1->GetCeilMaxValue());
160 $px1->SetWidth($WIDTH);
161 $px1->SetHeight($HEIGHT);
162 $px1->SetYLabel($langs->trans(
"NumberOfProposals"));
164 $px1->SetHorizTickIncrement(1);
165 $px1->SetCssPrefix(
"cssboxes");
166 $px1->mode =
'depth';
167 $px1->SetTitle($langs->trans(
"NumberOfProposalsByMonth"));
169 $px1->draw($filenamenb, $fileurlnb);
175 $data2 = $stats->getAmountByMonthWithPrevYear($endyear, $startyear, (
GETPOST(
'action',
'aZ09') == $refreshaction ? -1 : (3600 * 24)), ($WIDTH < 300 ? 2 : 0), $startmonth);
176 $datatype2 = array_pad(array(), ($endyear - $startyear + 1),
'bars');
179 $filenamenb = $dir.
"/".$prefix.
"propalsamountinyear-".$endyear.
".png";
180 $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=propalstats&file=propalsamountinyear-'.$endyear.
'.png';
183 $mesg = $px2->isGraphKo();
185 $px2->SetType($datatype2);
186 $px2->SetData($data2);
190 while ($i <= $endyear) {
191 if ($startmonth != 1) {
192 $legend[] = sprintf(
"%d/%d", $i - 2001, $i - 2000);
198 $px2->SetLegend($legend);
199 $px2->SetMaxValue($px2->GetCeilMaxValue());
200 $px2->SetWidth($WIDTH);
201 $px2->SetHeight($HEIGHT);
202 $px2->SetYLabel($langs->trans(
"AmountOfProposalsHT"));
204 $px2->SetHorizTickIncrement(1);
205 $px2->SetCssPrefix(
"cssboxes");
206 $px2->mode =
'depth';
207 $px2->SetTitle($langs->trans(
"AmountOfProposalsByMonthHT"));
209 $px2->draw($filenamenb, $fileurlnb);
213 if (empty($conf->use_javascript_ajax)) {
214 $langs->load(
"errors");
215 $mesg = $langs->trans(
"WarningFeatureDisabledWithDisplayOptimizedForBlindNoJs");
220 $stringtoshow .=
'<script nonce="'.getNonce().
'" type="text/javascript">
221 jQuery(document).ready(function() {
222 jQuery("#idsubimg'.$this->boxcode.
'").click(function() {
223 jQuery("#idfilter'.$this->boxcode.
'").toggle();
227 $stringtoshow .=
'<div class="center hideobject divboxfilter" id="idfilter'.$this->boxcode.
'">';
228 $stringtoshow .=
'<form class="flat formboxfilter" method="POST" action="'.$_SERVER[
"PHP_SELF"].
'">';
229 $stringtoshow .=
'<input type="hidden" name="token" value="'.newToken().
'">';
230 $stringtoshow .=
'<input type="hidden" name="action" value="'.$refreshaction.
'">';
231 $stringtoshow .=
'<input type="hidden" name="page_y" value="">';
232 $stringtoshow .=
'<input type="hidden" name="DOL_AUTOSET_COOKIE" value="DOLUSER_box_'.$this->boxcode.
':year,shownb,showtot">';
233 $stringtoshow .=
'<input type="checkbox" id="'.$param_shownb.
'" name="'.$param_shownb.
'"'.($shownb ?
' checked' :
'').
'><label for="'.$param_shownb.
'"> '.$langs->trans(
"NumberOfProposalsByMonth").
'</label>';
234 $stringtoshow .=
' ';
235 $stringtoshow .=
'<input type="checkbox" id="'.$param_showtot.
'" name="'.$param_showtot.
'"'.($showtot ?
' checked' :
'').
'><label for="'.$param_showtot.
'"> '.$langs->trans(
"AmountOfProposalsByMonthHT").
'</label>';
236 $stringtoshow .=
'<br>';
237 $stringtoshow .= $langs->trans(
"Year").
' <input class="flat" size="4" type="text" name="'.$param_year.
'" value="'.$endyear.
'">';
238 $stringtoshow .=
'<input type="image" class="reposition inline-block valigntextbottom" alt="'.$langs->trans(
"Refresh").
'" src="'.
img_picto($langs->trans(
"Refresh"),
'refresh.png',
'', 0, 1).
'">';
239 $stringtoshow .=
'</form>';
240 $stringtoshow .=
'</div>';
241 if ($shownb && $showtot) {
242 $stringtoshow .=
'<div class="fichecenter">';
243 $stringtoshow .=
'<div class="fichehalfleft">';
246 $stringtoshow .= $px1->show();
248 if ($shownb && $showtot) {
249 $stringtoshow .=
'</div>';
250 $stringtoshow .=
'<div class="fichehalfright">';
253 $stringtoshow .= $px2->show();
255 if ($shownb && $showtot) {
256 $stringtoshow .=
'</div>';
257 $stringtoshow .=
'</div>';
259 $this->info_box_contents[0][0] = array(
260 'tr' =>
'class="oddeven nohover"',
261 'td' =>
'class="nohover center"',
262 'textnoformat' => $stringtoshow,
265 $this->info_box_contents[0][0] = array(
266 'tr' =>
'class="oddeven nohover"',
267 'td' =>
'class="nohover left"',
273 $this->info_box_contents[0][0] = array(
274 'td' =>
'class="nohover left"',
275 'text' =>
'<span class="opacitymedium">'.$langs->trans(
"ReadPermissionNotAllowed").
'</span>'