62 global $conf, $user, $langs;
66 $refreshaction =
'refresh_'.$this->boxcode;
76 $langs->load(
"propal");
78 $text = $langs->trans(
"BoxProposalsPerMonth", $max);
79 $this->info_box_head = array(
84 'subtext'=>$langs->trans(
"Filter"),
85 'subpicto'=>
'filter.png',
86 'subclass'=>
'linkobject boxfilter',
94 $socid = $user->socid;
96 if (!$user->hasRight(
'societe',
'client',
'voir')) {
97 $prefix .=
'private-'.$user->id.
'-';
100 if ($user->hasRight(
'propal',
'lire')) {
101 $param_year =
'DOLUSERCOOKIE_box_'.$this->boxcode.
'_year';
102 $param_shownb =
'DOLUSERCOOKIE_box_'.$this->boxcode.
'_shownb';
103 $param_showtot =
'DOLUSERCOOKIE_box_'.$this->boxcode.
'_showtot';
105 include_once DOL_DOCUMENT_ROOT.
'/core/class/dolgraph.class.php';
106 include_once DOL_DOCUMENT_ROOT.
'/comm/propal/class/propalestats.class.php';
107 $autosetarray = preg_split(
"/[,;:]+/",
GETPOST(
'DOL_AUTOSET_COOKIE'));
108 if (in_array(
'DOLUSERCOOKIE_box_'.$this->boxcode, $autosetarray)) {
110 $shownb =
GETPOST($param_shownb,
'alpha');
111 $showtot =
GETPOST($param_showtot,
'alpha');
113 $tmparray = (!empty($_COOKIE[
'DOLUSERCOOKIE_box_'.$this->boxcode]) ? json_decode($_COOKIE[
'DOLUSERCOOKIE_box_'.$this->boxcode],
true) : array());
114 $endyear = (!empty($tmparray[
'year']) ? $tmparray[
'year'] :
'');
115 $shownb = (!empty($tmparray[
'shownb']) ? $tmparray[
'shownb'] :
'');
116 $showtot = (!empty($tmparray[
'showtot']) ? $tmparray[
'showtot'] :
'');
118 if (empty($shownb) && empty($showtot)) {
123 if (empty($endyear)) {
124 $endyear = $nowarray[
'year'];
126 $startyear = $endyear -
getDolGlobalInt(
'MAIN_NB_OF_YEAR_IN_WIDGET_GRAPH', 3) + 1;
128 $WIDTH = (($shownb && $showtot) || !empty($conf->dol_optimize_smallscreen)) ?
'256' :
'320';
135 $data1 = $stats->getNbByMonthWithPrevYear($endyear, $startyear, (
GETPOST(
'action',
'aZ09') == $refreshaction ? -1 : (3600 * 24)), ($WIDTH < 300 ? 2 : 0), $startmonth);
136 $datatype1 = array_pad(array(), ($endyear - $startyear + 1),
'bars');
138 $filenamenb = $dir.
"/".$prefix.
"propalsnbinyear-".$endyear.
".png";
139 $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=propalstats&file=propalsnbinyear-'.$endyear.
'.png';
142 $mesg = $px1->isGraphKo();
144 $px1->SetType($datatype1);
145 $px1->SetData($data1);
149 while ($i <= $endyear) {
150 if ($startmonth != 1) {
151 $legend[] = sprintf(
"%d/%d", $i - 2001, $i - 2000);
157 $px1->SetLegend($legend);
158 $px1->SetMaxValue($px1->GetCeilMaxValue());
159 $px1->SetWidth($WIDTH);
160 $px1->SetHeight($HEIGHT);
161 $px1->SetYLabel($langs->trans(
"NumberOfProposals"));
163 $px1->SetHorizTickIncrement(1);
164 $px1->SetCssPrefix(
"cssboxes");
165 $px1->mode =
'depth';
166 $px1->SetTitle($langs->trans(
"NumberOfProposalsByMonth"));
168 $px1->draw($filenamenb, $fileurlnb);
174 $data2 = $stats->getAmountByMonthWithPrevYear($endyear, $startyear, (
GETPOST(
'action',
'aZ09') == $refreshaction ? -1 : (3600 * 24)), ($WIDTH < 300 ? 2 : 0), $startmonth);
175 $datatype2 = array_pad(array(), ($endyear - $startyear + 1),
'bars');
178 $filenamenb = $dir.
"/".$prefix.
"propalsamountinyear-".$endyear.
".png";
179 $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=propalstats&file=propalsamountinyear-'.$endyear.
'.png';
182 $mesg = $px2->isGraphKo();
184 $px2->SetType($datatype2);
185 $px2->SetData($data2);
189 while ($i <= $endyear) {
190 if ($startmonth != 1) {
191 $legend[] = sprintf(
"%d/%d", $i - 2001, $i - 2000);
197 $px2->SetLegend($legend);
198 $px2->SetMaxValue($px2->GetCeilMaxValue());
199 $px2->SetWidth($WIDTH);
200 $px2->SetHeight($HEIGHT);
201 $px2->SetYLabel($langs->trans(
"AmountOfProposalsHT"));
203 $px2->SetHorizTickIncrement(1);
204 $px2->SetCssPrefix(
"cssboxes");
205 $px2->mode =
'depth';
206 $px2->SetTitle($langs->trans(
"AmountOfProposalsByMonthHT"));
208 $px2->draw($filenamenb, $fileurlnb);
212 if (empty($conf->use_javascript_ajax)) {
213 $langs->load(
"errors");
214 $mesg = $langs->trans(
"WarningFeatureDisabledWithDisplayOptimizedForBlindNoJs");
219 $stringtoshow .=
'<script nonce="'.getNonce().
'" type="text/javascript">
220 jQuery(document).ready(function() {
221 jQuery("#idsubimg'.$this->boxcode.
'").click(function() {
222 jQuery("#idfilter'.$this->boxcode.
'").toggle();
226 $stringtoshow .=
'<div class="center hideobject divboxfilter" id="idfilter'.$this->boxcode.
'">';
227 $stringtoshow .=
'<form class="flat formboxfilter" method="POST" action="'.$_SERVER[
"PHP_SELF"].
'">';
228 $stringtoshow .=
'<input type="hidden" name="token" value="'.newToken().
'">';
229 $stringtoshow .=
'<input type="hidden" name="action" value="'.$refreshaction.
'">';
230 $stringtoshow .=
'<input type="hidden" name="page_y" value="">';
231 $stringtoshow .=
'<input type="hidden" name="DOL_AUTOSET_COOKIE" value="DOLUSERCOOKIE_box_'.$this->boxcode.
':year,shownb,showtot">';
232 $stringtoshow .=
'<input type="checkbox" name="'.$param_shownb.
'"'.($shownb ?
' checked' :
'').
'> '.$langs->trans(
"NumberOfProposalsByMonth");
233 $stringtoshow .=
' ';
234 $stringtoshow .=
'<input type="checkbox" name="'.$param_showtot.
'"'.($showtot ?
' checked' :
'').
'> '.$langs->trans(
"AmountOfProposalsByMonthHT");
235 $stringtoshow .=
'<br>';
236 $stringtoshow .= $langs->trans(
"Year").
' <input class="flat" size="4" type="text" name="'.$param_year.
'" value="'.$endyear.
'">';
237 $stringtoshow .=
'<input type="image" class="reposition inline-block valigntextbottom" alt="'.$langs->trans(
"Refresh").
'" src="'.
img_picto($langs->trans(
"Refresh"),
'refresh.png',
'',
'', 1).
'">';
238 $stringtoshow .=
'</form>';
239 $stringtoshow .=
'</div>';
240 if ($shownb && $showtot) {
241 $stringtoshow .=
'<div class="fichecenter">';
242 $stringtoshow .=
'<div class="fichehalfleft">';
245 $stringtoshow .= $px1->show();
247 if ($shownb && $showtot) {
248 $stringtoshow .=
'</div>';
249 $stringtoshow .=
'<div class="fichehalfright">';
252 $stringtoshow .= $px2->show();
254 if ($shownb && $showtot) {
255 $stringtoshow .=
'</div>';
256 $stringtoshow .=
'</div>';
258 $this->info_box_contents[0][0] = array(
259 'tr'=>
'class="oddeven nohover"',
260 'td' =>
'class="nohover center"',
261 'textnoformat'=>$stringtoshow,
264 $this->info_box_contents[0][0] = array(
265 'tr'=>
'class="oddeven nohover"',
266 'td' =>
'class="nohover left"',
272 $this->info_box_contents[0][0] = array(
273 'td' =>
'class="nohover left"',
274 'text' =>
'<span class="opacitymedium">'.$langs->trans(
"ReadPermissionNotAllowed").
'</span>'