70 global $conf, $user, $langs;
74 $refreshaction =
'refresh_'.$this->boxcode;
79 $startmonth = $conf->global->SOCIETE_FISCAL_MONTH_START ? ($conf->global->SOCIETE_FISCAL_MONTH_START) : 1;
84 $langs->load(
"propal");
86 $text = $langs->trans(
"BoxProposalsPerMonth", $max);
87 $this->info_box_head = array(
92 'subtext'=>$langs->trans(
"Filter"),
93 'subpicto'=>
'filter.png',
94 'subclass'=>
'linkobject boxfilter',
102 $socid = $user->socid;
104 if (!$user->hasRight(
'societe',
'client',
'voir') || $socid) {
105 $prefix .=
'private-'.$user->id.
'-';
108 if ($user->hasRight(
'propal',
'lire')) {
109 $param_year =
'DOLUSERCOOKIE_box_'.$this->boxcode.
'_year';
110 $param_shownb =
'DOLUSERCOOKIE_box_'.$this->boxcode.
'_shownb';
111 $param_showtot =
'DOLUSERCOOKIE_box_'.$this->boxcode.
'_showtot';
113 include_once DOL_DOCUMENT_ROOT.
'/core/class/dolgraph.class.php';
114 include_once DOL_DOCUMENT_ROOT.
'/comm/propal/class/propalestats.class.php';
115 $autosetarray = preg_split(
"/[,;:]+/",
GETPOST(
'DOL_AUTOSET_COOKIE'));
116 if (in_array(
'DOLUSERCOOKIE_box_'.$this->boxcode, $autosetarray)) {
117 $endyear =
GETPOST($param_year,
'int');
118 $shownb =
GETPOST($param_shownb,
'alpha');
119 $showtot =
GETPOST($param_showtot,
'alpha');
121 $tmparray = (!empty($_COOKIE[
'DOLUSERCOOKIE_box_'.$this->boxcode]) ? json_decode($_COOKIE[
'DOLUSERCOOKIE_box_'.$this->boxcode],
true) : array());
122 $endyear = (!empty($tmparray[
'year']) ? $tmparray[
'year'] :
'');
123 $shownb = (!empty($tmparray[
'shownb']) ? $tmparray[
'shownb'] :
'');
124 $showtot = (!empty($tmparray[
'showtot']) ? $tmparray[
'showtot'] :
'');
126 if (empty($shownb) && empty($showtot)) {
131 if (empty($endyear)) {
132 $endyear = $nowarray[
'year'];
134 $startyear = $endyear - (!
getDolGlobalString(
'MAIN_NB_OF_YEAR_IN_WIDGET_GRAPH') ? 2 : ($conf->global->MAIN_NB_OF_YEAR_IN_WIDGET_GRAPH - 1));
136 $WIDTH = (($shownb && $showtot) || !empty($conf->dol_optimize_smallscreen)) ?
'256' :
'320';
143 $data1 = $stats->getNbByMonthWithPrevYear($endyear, $startyear, (
GETPOST(
'action',
'aZ09') == $refreshaction ? -1 : (3600 * 24)), ($WIDTH < 300 ? 2 : 0), $startmonth);
144 $datatype1 = array_pad(array(), ($endyear - $startyear + 1),
'bars');
146 $filenamenb = $dir.
"/".$prefix.
"propalsnbinyear-".$endyear.
".png";
147 $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=propalstats&file=propalsnbinyear-'.$endyear.
'.png';
150 $mesg = $px1->isGraphKo();
152 $px1->SetType($datatype1);
153 $px1->SetData($data1);
157 while ($i <= $endyear) {
158 if ($startmonth != 1) {
159 $legend[] = sprintf(
"%d/%d", $i - 2001, $i - 2000);
165 $px1->SetLegend($legend);
166 $px1->SetMaxValue($px1->GetCeilMaxValue());
167 $px1->SetWidth($WIDTH);
168 $px1->SetHeight($HEIGHT);
169 $px1->SetYLabel($langs->trans(
"NumberOfProposals"));
171 $px1->SetHorizTickIncrement(1);
172 $px1->SetCssPrefix(
"cssboxes");
173 $px1->mode =
'depth';
174 $px1->SetTitle($langs->trans(
"NumberOfProposalsByMonth"));
176 $px1->draw($filenamenb, $fileurlnb);
182 $data2 = $stats->getAmountByMonthWithPrevYear($endyear, $startyear, (
GETPOST(
'action',
'aZ09') == $refreshaction ? -1 : (3600 * 24)), ($WIDTH < 300 ? 2 : 0), $startmonth);
183 $datatype2 = array_pad(array(), ($endyear - $startyear + 1),
'bars');
186 $filenamenb = $dir.
"/".$prefix.
"propalsamountinyear-".$endyear.
".png";
187 $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=propalstats&file=propalsamountinyear-'.$endyear.
'.png';
190 $mesg = $px2->isGraphKo();
192 $px2->SetType($datatype2);
193 $px2->SetData($data2);
197 while ($i <= $endyear) {
198 if ($startmonth != 1) {
199 $legend[] = sprintf(
"%d/%d", $i - 2001, $i - 2000);
205 $px2->SetLegend($legend);
206 $px2->SetMaxValue($px2->GetCeilMaxValue());
207 $px2->SetWidth($WIDTH);
208 $px2->SetHeight($HEIGHT);
209 $px2->SetYLabel($langs->trans(
"AmountOfProposalsHT"));
211 $px2->SetHorizTickIncrement(1);
212 $px2->SetCssPrefix(
"cssboxes");
213 $px2->mode =
'depth';
214 $px2->SetTitle($langs->trans(
"AmountOfProposalsByMonthHT"));
216 $px2->draw($filenamenb, $fileurlnb);
220 if (empty($conf->use_javascript_ajax)) {
221 $langs->load(
"errors");
222 $mesg = $langs->trans(
"WarningFeatureDisabledWithDisplayOptimizedForBlindNoJs");
227 $stringtoshow .=
'<script nonce="'.getNonce().
'" type="text/javascript">
228 jQuery(document).ready(function() {
229 jQuery("#idsubimg'.$this->boxcode.
'").click(function() {
230 jQuery("#idfilter'.$this->boxcode.
'").toggle();
234 $stringtoshow .=
'<div class="center hideobject divboxfilter" id="idfilter'.$this->boxcode.
'">';
235 $stringtoshow .=
'<form class="flat formboxfilter" method="POST" action="'.$_SERVER[
"PHP_SELF"].
'">';
236 $stringtoshow .=
'<input type="hidden" name="token" value="'.newToken().
'">';
237 $stringtoshow .=
'<input type="hidden" name="action" value="'.$refreshaction.
'">';
238 $stringtoshow .=
'<input type="hidden" name="page_y" value="">';
239 $stringtoshow .=
'<input type="hidden" name="DOL_AUTOSET_COOKIE" value="DOLUSERCOOKIE_box_'.$this->boxcode.
':year,shownb,showtot">';
240 $stringtoshow .=
'<input type="checkbox" name="'.$param_shownb.
'"'.($shownb ?
' checked' :
'').
'> '.$langs->trans(
"NumberOfProposalsByMonth");
241 $stringtoshow .=
' ';
242 $stringtoshow .=
'<input type="checkbox" name="'.$param_showtot.
'"'.($showtot ?
' checked' :
'').
'> '.$langs->trans(
"AmountOfProposalsByMonthHT");
243 $stringtoshow .=
'<br>';
244 $stringtoshow .= $langs->trans(
"Year").
' <input class="flat" size="4" type="text" name="'.$param_year.
'" value="'.$endyear.
'">';
245 $stringtoshow .=
'<input type="image" class="reposition inline-block valigntextbottom" alt="'.$langs->trans(
"Refresh").
'" src="'.
img_picto($langs->trans(
"Refresh"),
'refresh.png',
'',
'', 1).
'">';
246 $stringtoshow .=
'</form>';
247 $stringtoshow .=
'</div>';
248 if ($shownb && $showtot) {
249 $stringtoshow .=
'<div class="fichecenter">';
250 $stringtoshow .=
'<div class="fichehalfleft">';
253 $stringtoshow .= $px1->show();
255 if ($shownb && $showtot) {
256 $stringtoshow .=
'</div>';
257 $stringtoshow .=
'<div class="fichehalfright">';
260 $stringtoshow .= $px2->show();
262 if ($shownb && $showtot) {
263 $stringtoshow .=
'</div>';
264 $stringtoshow .=
'</div>';
266 $this->info_box_contents[0][0] = array(
267 'tr'=>
'class="oddeven nohover"',
268 'td' =>
'class="nohover center"',
269 'textnoformat'=>$stringtoshow,
272 $this->info_box_contents[0][0] = array(
273 'tr'=>
'class="oddeven nohover"',
274 'td' =>
'class="nohover left"',
280 $this->info_box_contents[0][0] = array(
281 'td' =>
'class="nohover left"',
282 'text' =>
'<span class="opacitymedium">'.$langs->trans(
"ReadPermissionNotAllowed").
'</span>'