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',
 
   98      $socid = $user->socid;
 
  100    if (!$user->hasRight(
'societe', 
'client', 
'voir')) {
 
  101      $prefix .= 
'private-'.$user->id.
'-'; 
 
  104    if ($user->hasRight(
'propal', 
'lire')) {
 
  105      $param_year = 
'DOLUSER_box_'.$this->boxcode.
'_year';
 
  106      $param_shownb = 
'DOLUSER_box_'.$this->boxcode.
'_shownb';
 
  107      $param_showtot = 
'DOLUSER_box_'.$this->boxcode.
'_showtot';
 
  109      include_once DOL_DOCUMENT_ROOT.
'/core/class/dolgraph.class.php';
 
  110      include_once DOL_DOCUMENT_ROOT.
'/comm/propal/class/propalestats.class.php';
 
  111      $autosetarray = preg_split(
"/[,;:]+/", 
GETPOST(
'DOL_AUTOSET_COOKIE'));
 
  112      if (in_array(
'DOLUSER_box_'.$this->boxcode, $autosetarray)) {
 
  114        $shownb = 
GETPOST($param_shownb, 
'alpha');
 
  115        $showtot = 
GETPOST($param_showtot, 
'alpha');
 
  117        $tmparray = (!empty($_COOKIE[
'DOLUSER_box_'.$this->boxcode]) ? json_decode($_COOKIE[
'DOLUSER_box_'.$this->boxcode], 
true) : array());
 
  118        $endyear = (!empty($tmparray[
'year']) ? $tmparray[
'year'] : 
'');
 
  119        $shownb = (!empty($tmparray[
'shownb']) ? $tmparray[
'shownb'] : 
'');
 
  120        $showtot = (!empty($tmparray[
'showtot']) ? $tmparray[
'showtot'] : 
'');
 
  122      if (empty($shownb) && empty($showtot)) {
 
  127      if (empty($endyear)) {
 
  128        $endyear = $nowarray[
'year'];
 
  130      $startyear = $endyear - 
getDolGlobalInt(
'MAIN_NB_OF_YEAR_IN_WIDGET_GRAPH', 3) + 1;
 
  132      $WIDTH = (($shownb && $showtot) || !empty(
$conf->dol_optimize_smallscreen)) ? 
'256' : 
'320';
 
  139        $data1 = $stats->getNbByMonthWithPrevYear($endyear, $startyear, (
GETPOST(
'action', 
'aZ09') == $refreshaction ? -1 : (3600 * 24)), ($WIDTH < 300 ? 2 : 0), $startmonth);
 
  140        $datatype1 = array_pad(array(), ($endyear - $startyear + 1), 
'bars');
 
  142        $filenamenb = $dir.
"/".$prefix.
"propalsnbinyear-".$endyear.
".png";
 
  143        $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=propalstats&file=propalsnbinyear-'.$endyear.
'.png';
 
  146        $mesg = $px1->isGraphKo();
 
  148          $px1->SetType($datatype1);
 
  149          $px1->SetData($data1);
 
  153          while ($i <= $endyear) {
 
  154            if ($startmonth != 1) {
 
  155              $legend[] = sprintf(
"%d/%d", $i - 2001, $i - 2000);
 
  161          $px1->SetLegend($legend);
 
  162          $px1->SetMaxValue($px1->GetCeilMaxValue());
 
  163          $px1->SetWidth($WIDTH);
 
  164          $px1->SetHeight($HEIGHT);
 
  165          $px1->SetYLabel($langs->trans(
"NumberOfProposals"));
 
  167          $px1->SetHorizTickIncrement(1);
 
  168          $px1->SetCssPrefix(
"cssboxes");
 
  169          $px1->mode = 
'depth';
 
  170          $px1->SetTitle($langs->trans(
"NumberOfProposalsByMonth"));
 
  172          $px1->draw($filenamenb, $fileurlnb);
 
  178        $data2 = $stats->getAmountByMonthWithPrevYear($endyear, $startyear, (
GETPOST(
'action', 
'aZ09') == $refreshaction ? -1 : (3600 * 24)), ($WIDTH < 300 ? 2 : 0), $startmonth);
 
  179        $datatype2 = array_pad(array(), ($endyear - $startyear + 1), 
'bars');
 
  182        $filenamenb = $dir.
"/".$prefix.
"propalsamountinyear-".$endyear.
".png";
 
  183        $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=propalstats&file=propalsamountinyear-'.$endyear.
'.png';
 
  186        $mesg = $px2->isGraphKo();
 
  188          $px2->SetType($datatype2);
 
  189          $px2->SetData($data2);
 
  193          while ($i <= $endyear) {
 
  194            if ($startmonth != 1) {
 
  195              $legend[] = sprintf(
"%d/%d", $i - 2001, $i - 2000);
 
  201          $px2->SetLegend($legend);
 
  202          $px2->SetMaxValue($px2->GetCeilMaxValue());
 
  203          $px2->SetWidth($WIDTH);
 
  204          $px2->SetHeight($HEIGHT);
 
  205          $px2->SetYLabel($langs->trans(
"AmountOfProposalsHT"));
 
  207          $px2->SetHorizTickIncrement(1);
 
  208          $px2->SetCssPrefix(
"cssboxes");
 
  209          $px2->mode = 
'depth';
 
  210          $px2->SetTitle($langs->trans(
"AmountOfProposalsByMonthHT"));
 
  212          $px2->draw($filenamenb, $fileurlnb);
 
  216      if (empty(
$conf->use_javascript_ajax)) {
 
  217        $langs->load(
"errors");
 
  218        $mesg = $langs->trans(
"WarningFeatureDisabledWithDisplayOptimizedForBlindNoJs");
 
  223        $stringtoshow .= 
'<script nonce="'.getNonce().
'" type="text/javascript"> 
  224          jQuery(document).ready(function() { 
  225            jQuery("#idsubimg'.$this->boxcode.
'").click(function() { 
  226              jQuery("#idfilter'.$this->boxcode.
'").toggle(); 
  230        $stringtoshow .= 
'<div class="center hideobject divboxfilter" id="idfilter'.$this->boxcode.
'">'; 
 
  231        $stringtoshow .= 
'<form class="flat formboxfilter" method="POST" action="'.$_SERVER[
"PHP_SELF"].
'">';
 
  232        $stringtoshow .= 
'<input type="hidden" name="token" value="'.newToken().
'">';
 
  233        $stringtoshow .= 
'<input type="hidden" name="action" value="'.$refreshaction.
'">';
 
  234        $stringtoshow .= 
'<input type="hidden" name="page_y" value="">';
 
  235        $stringtoshow .= 
'<input type="hidden" name="DOL_AUTOSET_COOKIE" value="DOLUSER_box_'.$this->boxcode.
':year,shownb,showtot">';
 
  236        $stringtoshow .= 
'<input type="checkbox" id="'.$param_shownb.
'" name="'.$param_shownb.
'"'.($shownb ? 
' checked' : 
'').
'><label for="'.$param_shownb.
'"> '.$langs->trans(
"NumberOfProposalsByMonth").
'</label>';
 
  237        $stringtoshow .= 
'   ';
 
  238        $stringtoshow .= 
'<input type="checkbox" id="'.$param_showtot.
'" name="'.$param_showtot.
'"'.($showtot ? 
' checked' : 
'').
'><label for="'.$param_showtot.
'"> '.$langs->trans(
"AmountOfProposalsByMonthHT").
'</label>';
 
  239        $stringtoshow .= 
'<br>';
 
  240        $stringtoshow .= $langs->trans(
"Year").
' <input class="flat" size="4" type="text" name="'.$param_year.
'" value="'.$endyear.
'">';
 
  241        $stringtoshow .= 
'<input type="image" class="reposition inline-block valigntextbottom" alt="'.$langs->trans(
"Refresh").
'" src="'.
img_picto($langs->trans(
"Refresh"), 
'refresh.png', 
'', 0, 1).
'">';
 
  242        $stringtoshow .= 
'</form>';
 
  243        $stringtoshow .= 
'</div>';
 
  244        if ($shownb && $showtot) {
 
  245          $stringtoshow .= 
'<div class="fichecenter">';
 
  246          $stringtoshow .= 
'<div class="fichehalfleft">';
 
  248        if ($shownb && $px1 !== 
null) {
 
  249          $stringtoshow .= $px1->show();
 
  251        if ($shownb && $showtot) {
 
  252          $stringtoshow .= 
'</div>';
 
  253          $stringtoshow .= 
'<div class="fichehalfright">';
 
  255        if ($showtot && $px2 !== 
null) {
 
  256          $stringtoshow .= $px2->show();
 
  258        if ($shownb && $showtot) {
 
  259          $stringtoshow .= 
'</div>';
 
  260          $stringtoshow .= 
'</div>';
 
  262        $this->info_box_contents[0][0] = array(
 
  263          'tr' => 
'class="oddeven nohover"',
 
  264          'td' => 
'class="nohover center"',
 
  265          'textnoformat' => $stringtoshow,
 
  268        $this->info_box_contents[0][0] = array(
 
  269          'tr' => 
'class="oddeven nohover"',
 
  270          'td' => 
'class="nohover left"',
 
  276      $this->info_box_contents[0][0] = array(
 
  277        'td' => 
'class="nohover left"',
 
  278        'text' => 
'<span class="opacitymedium">'.$langs->trans(
"ReadPermissionNotAllowed").
'</span>'