67    global 
$conf, $user, $langs;
 
   70    $dir = 
$conf->user->dir_temp;
 
   72    $refreshaction = 
'refresh_'.$this->boxcode;
 
   74    include_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
 
   75    include_once DOL_DOCUMENT_ROOT.
'/comm/propal/class/propal.class.php';
 
   76    include_once DOL_DOCUMENT_ROOT.
'/commande/class/commande.class.php';
 
   78    $param_year = 
'DOLUSER_box_'.$this->boxcode.
'_year';
 
   79    $param_showinvoicenb = 
'DOLUSER_box_'.$this->boxcode.
'_showinvoicenb';
 
   80    $param_showpropalnb = 
'DOLUSER_box_'.$this->boxcode.
'_showpropalnb';
 
   81    $param_showordernb = 
'DOLUSER_box_'.$this->boxcode.
'_showordernb';
 
   82    $autosetarray = preg_split(
"/[,;:]+/", 
GETPOST(
'DOL_AUTOSET_COOKIE'));
 
   83    if (in_array(
'DOLUSER_box_'.$this->boxcode, $autosetarray)) {
 
   85      $showinvoicenb = 
GETPOST($param_showinvoicenb, 
'alpha');
 
   86      $showpropalnb = 
GETPOST($param_showpropalnb, 
'alpha');
 
   87      $showordernb = 
GETPOST($param_showordernb, 
'alpha');
 
   89      $tmparray = (!empty($_COOKIE[
'DOLUSER_box_'.$this->boxcode]) ? json_decode($_COOKIE[
'DOLUSER_box_'.$this->boxcode], 
true) : array());
 
   90      $year = (!empty($tmparray[
'year']) ? $tmparray[
'year'] : 
'');
 
   91      $showinvoicenb = (!empty($tmparray[
'showinvoicenb']) ? $tmparray[
'showinvoicenb'] : 
'');
 
   92      $showpropalnb = (!empty($tmparray[
'showpropalnb']) ? $tmparray[
'showpropalnb'] : 
'');
 
   93      $showordernb = (!empty($tmparray[
'showordernb']) ? $tmparray[
'showordernb'] : 
'');
 
   95    if (empty($showinvoicenb) && empty($showpropalnb) && empty($showordernb)) {
 
  100    if (!isModEnabled(
'invoice') || !$user->hasRight(
'facture', 
'lire')) {
 
  103    if (isModEnabled(
'propal') || !$user->hasRight(
'propal', 
'lire')) {
 
  106    if (!isModEnabled(
'order') || !$user->hasRight(
'commande', 
'lire')) {
 
  112      $year = $nowarray[
'year'];
 
  116    if ($showinvoicenb) {
 
  126    $text = $langs->trans(
"BoxProductDistribution", $max).
' - '.$langs->trans(
"Year").
': '.$year;
 
  127    $this->info_box_head = array(
 
  132        'subtext' => $langs->trans(
"Filter"),
 
  133        'subpicto' => 
'filter.png',
 
  134        'subclass' => 
'linkobject boxfilter',
 
  139    $socid = empty($user->socid) ? 0 : $user->socid;
 
  146    $WIDTH = ($nbofgraph >= 2 || !empty(
$conf->dol_optimize_smallscreen)) ? 
'300' : 
'320';
 
  149    if (isModEnabled(
"propal") && $user->hasRight(
'propal', 
'lire')) {
 
  152        $langs->load(
"propal");
 
  153        include_once DOL_DOCUMENT_ROOT.
'/comm/propal/class/propalestats.class.php';
 
  157        $stats_proposal = 
new PropaleStats($this->db, $socid, ($userid > 0 ? $userid : 0));
 
  158        $data2 = $stats_proposal->getAllByProductEntry($year, (
GETPOST(
'action', 
'aZ09') == $refreshaction ? -1 : (3600 * 24)), $max);
 
  162          $data2 = array(array(0 => $langs->trans(
"None"), 1 => 1));
 
  165        $filenamenb = $dir.
"/prodserforpropal-".$year.
".png";
 
  166        $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=proposalstats&file=prodserforpropal-'.$year.
'.png';
 
  169        $mesg = $px2->isGraphKo();
 
  175          foreach ($data2 as $key => $val) {
 
  176            $data2[$key][0] = 
dol_trunc($data2[$key][0], 32);
 
  177            $legend[] = $data2[$key][0];
 
  181          $px2->SetData($data2);
 
  185            $px2->SetDataColor(array(array(220, 220, 220)));
 
  187          $px2->SetLegend($legend);
 
  188          $px2->setShowLegend(2);
 
  189          if (!empty(
$conf->dol_optimize_smallscreen)) {
 
  192          $px2->setShowPointValue($showpointvalue);
 
  193          $px2->setShowPercent(0);
 
  194          $px2->SetMaxValue($px2->GetCeilMaxValue());
 
  195          $px2->SetWidth($WIDTH);
 
  196          $px2->SetHeight($HEIGHT);
 
  199          $px2->SetHorizTickIncrement(1);
 
  200          $px2->SetCssPrefix(
"cssboxes");
 
  202          $px2->SetType(array(
'pie'));
 
  203          $px2->SetTitle($langs->trans(
"ForObject", $langs->transnoentitiesnoconv(
"Proposals")));
 
  204          $px2->combine = 0.05;
 
  206          $px2->draw($filenamenb, $fileurlnb);
 
  211    if (isModEnabled(
'order') && $user->hasRight(
'commande', 
'lire')) {
 
  214        $langs->load(
"orders");
 
  215        include_once DOL_DOCUMENT_ROOT.
'/commande/class/commandestats.class.php';
 
  220        $stats_order = 
new CommandeStats($this->db, $socid, $mode, ($userid > 0 ? $userid : 0));
 
  221        $data3 = $stats_order->getAllByProductEntry($year, (
GETPOST(
'action', 
'aZ09') == $refreshaction ? -1 : (3600 * 24)), $max);
 
  225          $data3 = array(array(0 => $langs->trans(
"None"), 1 => 1));
 
  228        $filenamenb = $dir.
"/prodserfororder-".$year.
".png";
 
  229        $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstats&file=prodserfororder-'.$year.
'.png';
 
  232        $mesg = $px3->isGraphKo();
 
  238          foreach ($data3 as $key => $val) {
 
  239            $data3[$key][0] = 
dol_trunc($data3[$key][0], 32);
 
  240            $legend[] = $data3[$key][0];
 
  244          $px3->SetData($data3);
 
  248            $px3->SetDataColor(array(array(220, 220, 220)));
 
  250          $px3->SetLegend($legend);
 
  251          $px3->setShowLegend(2);
 
  252          if (!empty(
$conf->dol_optimize_smallscreen)) {
 
  255          $px3->setShowPointValue($showpointvalue);
 
  256          $px3->setShowPercent(0);
 
  257          $px3->SetMaxValue($px3->GetCeilMaxValue());
 
  258          $px3->SetWidth($WIDTH);
 
  259          $px3->SetHeight($HEIGHT);
 
  262          $px3->SetHorizTickIncrement(1);
 
  263          $px3->SetCssPrefix(
"cssboxes");
 
  265          $px3->SetType(array(
'pie'));
 
  266          $px3->SetTitle($langs->trans(
"ForObject", $langs->transnoentitiesnoconv(
"Orders")));
 
  267          $px3->combine = 0.05;
 
  269          $px3->draw($filenamenb, $fileurlnb);
 
  275    if (isModEnabled(
'invoice') && $user->hasRight(
'facture', 
'lire')) {
 
  277      if ($showinvoicenb) {
 
  278        $langs->load(
"bills");
 
  279        include_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facturestats.class.php';
 
  284        $stats_invoice = 
new FactureStats($this->db, $socid, $mode, ($userid > 0 ? $userid : 0));
 
  285        $data1 = $stats_invoice->getAllByProductEntry($year, (
GETPOST(
'action', 
'aZ09') == $refreshaction ? -1 : (3600 * 24)), $max);
 
  290          $data1 = array(array(0 => $langs->trans(
"None"), 1 => 1));
 
  292        $filenamenb = $dir.
"/prodserforinvoice-".$year.
".png";
 
  293        $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=productstats&file=prodserforinvoice-'.$year.
'.png';
 
  296        $mesg = $px1->isGraphKo();
 
  302          foreach ($data1 as $key => $val) {
 
  303            $data1[$key][0] = 
dol_trunc($data1[$key][0], 32);
 
  304            $legend[] = $data1[$key][0];
 
  308          $px1->SetData($data1);
 
  312            $px1->SetDataColor(array(array(220, 220, 220)));
 
  314          $px1->SetLegend($legend);
 
  315          $px1->setShowLegend(2);
 
  316          if (!empty(
$conf->dol_optimize_smallscreen)) {
 
  319          $px1->setShowPointValue($showpointvalue);
 
  320          $px1->setShowPercent(0);
 
  321          $px1->SetMaxValue($px1->GetCeilMaxValue());
 
  322          $px1->SetWidth($WIDTH);
 
  323          $px1->SetHeight($HEIGHT);
 
  326          $px1->SetHorizTickIncrement(1);
 
  327          $px1->SetCssPrefix(
"cssboxes");
 
  329          $px1->SetType(array(
'pie'));
 
  330          $px1->SetTitle($langs->trans(
"ForObject", $langs->transnoentitiesnoconv(
"Invoices")));
 
  331          $px1->combine = 0.05;
 
  333          $px1->draw($filenamenb, $fileurlnb);
 
  338    if (empty($nbofgraph)) {
 
  339      $langs->load(
"errors");
 
  340      $mesg = $langs->trans(
"ReadPermissionNotAllowed");
 
  342    if (empty(
$conf->use_javascript_ajax)) {
 
  343      $langs->load(
"errors");
 
  344      $mesg = $langs->trans(
"WarningFeatureDisabledWithDisplayOptimizedForBlindNoJs");
 
  349      $stringtoshow .= 
'<script nonce="'.getNonce().
'" type="text/javascript"> 
  350        jQuery(document).ready(function() { 
  351          jQuery("#idsubimg'.$this->boxcode.
'").click(function() { 
  352            jQuery("#idfilter'.$this->boxcode.
'").toggle(); 
  356      $stringtoshow .= 
'<div class="center hideobject" id="idfilter'.$this->boxcode.
'">'; 
 
  357      $stringtoshow .= 
'<form class="flat formboxfilter" method="POST" action="'.$_SERVER[
"PHP_SELF"].
'">';
 
  358      $stringtoshow .= 
'<input type="hidden" name="token" value="'.newToken().
'">';
 
  359      $stringtoshow .= 
'<input type="hidden" name="action" value="'.$refreshaction.
'">';
 
  360      $stringtoshow .= 
'<input type="hidden" name="page_y" value="">';
 
  361      $stringtoshow .= 
'<input type="hidden" name="DOL_AUTOSET_COOKIE" value="DOLUSER_box_'.$this->boxcode.
':year,showinvoicenb,showpropalnb,showordernb">';
 
  362      if (isModEnabled(
"propal") || $user->hasRight(
'propal', 
'lire')) {
 
  363        $stringtoshow .= 
'<input type="checkbox" name="'.$param_showpropalnb.
'"'.($showpropalnb ? 
' checked' : 
'').
'> '.$langs->trans(
"ForProposals");
 
  364        $stringtoshow .= 
' ';
 
  366      if (isModEnabled(
'order') || $user->hasRight(
'commande', 
'lire')) {
 
  367        $stringtoshow .= 
'<input type="checkbox" name="'.$param_showordernb.
'"'.($showordernb ? 
' checked' : 
'').
'> '.$langs->trans(
"ForCustomersOrders");
 
  369      if (isModEnabled(
'invoice') || $user->hasRight(
'facture', 
'lire')) {
 
  370        $stringtoshow .= 
'<input type="checkbox" name="'.$param_showinvoicenb.
'"'.($showinvoicenb ? 
' checked' : 
'').
'> '.$langs->trans(
"ForCustomersInvoices");
 
  371        $stringtoshow .= 
'   ';
 
  373      $stringtoshow .= 
'<br>';
 
  374      $stringtoshow .= $langs->trans(
"Year").
' <input class="flat" size="4" type="text" name="'.$param_year.
'" value="'.$year.
'">';
 
  375      $stringtoshow .= 
'<input type="image" class="reposition inline-block valigntextbottom" alt="'.$langs->trans(
"Refresh").
'" src="'.
img_picto(
'', 
'refresh.png', 
'', 0, 1).
'">';
 
  376      $stringtoshow .= 
'</form>';
 
  377      $stringtoshow .= 
'</div>';
 
  379      if ($nbofgraph == 1) {
 
  380        if ($showpropalnb && $px2 !== 
null) {
 
  381          $stringtoshow .= $px2->show();
 
  382        } elseif ($showordernb && $px3 !== 
null) {
 
  383          $stringtoshow .= $px3->show();
 
  384        } elseif ($px1 !== 
null) {
 
  385          $stringtoshow .= $px1->show();
 
  388      if ($nbofgraph == 2) {
 
  389        $stringtoshow .= 
'<div class="fichecenter"><div class="containercenter"><div class="fichehalfleft">';
 
  390        if (isModEnabled(
'propal') && $showpropalnb && $px2 !== 
null) {
 
  391          $stringtoshow .= $px2->show();
 
  392        } elseif (isModEnabled(
'order') && $showordernb && $px3 !== 
null) {
 
  393          $stringtoshow .= $px3->show();
 
  395        $stringtoshow .= 
'</div><div class="fichehalfright">';
 
  396        if (isModEnabled(
'invoice') && $showinvoicenb && $px1 !== 
null) {
 
  397          $stringtoshow .= $px1->show();
 
  398        } elseif (isModEnabled(
'order') && $showordernb && $px3 !== 
null) {
 
  399          $stringtoshow .= $px3->show();
 
  401        $stringtoshow .= 
'</div></div></div>';
 
  403      if ($nbofgraph == 3 && $px1 !== 
null && $px2 !== 
null && $px3 !== 
null) {
 
  404        $stringtoshow .= 
'<div class="fichecenter"><div class="containercenter"><div class="fichehalfleft">';
 
  405        $stringtoshow .= $px2->show();
 
  406        $stringtoshow .= 
'</div><div class="fichehalfright">';
 
  407        $stringtoshow .= $px3->show();
 
  408        $stringtoshow .= 
'</div></div></div>';
 
  409        $stringtoshow .= 
'<div class="fichecenter"><div class="containercenter">';
 
  410        $stringtoshow .= $px1->show();
 
  411        $stringtoshow .= 
'</div></div>';
 
  413      $this->info_box_contents[0][0] = array(
 
  414        'tr' => 
'class="oddeven nohover"',
 
  415        'td' => 
'class="nohover center"',
 
  416        'textnoformat' => $stringtoshow,
 
  419      $this->info_box_contents[0][0] = array(
 
  420        'td' => 
'class="nohover left"',
 
  422        'text' => 
'<span class="opacitymedium">'.$mesg.
'</span>'