From 99e5bf3120c81b17a13a41abf8e2a35f60919985 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 26 Jul 2013 18:40:43 +0200 Subject: [PATCH] New: Enhance graphical boxes. Prepare to show filters form to modify graph. --- .../boxes/box_graph_invoices_permonth.php | 28 ++++++++++---- .../box_graph_invoices_supplier_permonth.php | 28 ++++++++++---- .../core/boxes/box_graph_orders_permonth.php | 28 ++++++++++---- .../box_graph_orders_supplier_permonth.php | 28 ++++++++++---- .../boxes/box_graph_propales_permonth.php | 37 ++++++++++++++----- htdocs/core/boxes/modules_boxes.php | 24 ++++++------ htdocs/core/class/dolgraph.class.php | 7 ++-- htdocs/core/class/stats.class.php | 8 ++-- 8 files changed, 132 insertions(+), 56 deletions(-) diff --git a/htdocs/core/boxes/box_graph_invoices_permonth.php b/htdocs/core/boxes/box_graph_invoices_permonth.php index 63140c64c28..026a0b9da80 100644 --- a/htdocs/core/boxes/box_graph_invoices_permonth.php +++ b/htdocs/core/boxes/box_graph_invoices_permonth.php @@ -74,10 +74,10 @@ class box_graph_invoices_permonth extends ModeleBoxes 'text' => $text, 'limit'=> dol_strlen($text), 'graph'=> 1, - 'sublink'=>$_SERVER["PHP_SELF"].'?action='.$refreshaction, - 'subtext'=>$langs->trans("Refresh"), - 'subpicto'=>'refresh.png', - 'target'=>'none' + 'sublink'=>'', + 'subtext'=>$langs->trans("Filter"), + 'subpicto'=>'filter.png', + 'target'=>'none' // Set '' to get target="_blank" ); if ($user->rights->facture->lire) @@ -88,11 +88,11 @@ class box_graph_invoices_permonth extends ModeleBoxes $shownb=(! empty($conf->global->FACTURE_BOX_GRAPH_SHOW_NB)); $showtot=(! isset($conf->global->FACTURE_BOX_GRAPH_SHOW_TOT) || ! empty($conf->global->FACTURE_BOX_GRAPH_SHOW_TOT)); $nowarray=dol_getdate(dol_now(),true); - $endyear=$nowarray['year']; + $endyear=(GETPOST('param'.$this->boxcode.'year')?GETPOST('param'.$this->boxcode.'year','int'):$nowarray['year']); $startyear=$endyear-1; $mode='customer'; $userid=0; - $WIDTH='256'; + $WIDTH=($shownb && $showtot)?'256':'320'; $HEIGHT='192'; $stats = new FactureStats($this->db, 0, $mode, ($userid>0?$userid:0)); @@ -175,9 +175,23 @@ class box_graph_invoices_permonth extends ModeleBoxes if (! $mesg) { + $stringtoshow=''; + $stringtoshow.=''; + $stringtoshow.='
'; + $stringtoshow.=$langs->trans("Year").' '; + $stringtoshow.=''; + $stringtoshow.=img_picto($langs->trans("Refresh"),'refresh.png'); + $stringtoshow.=''; + $stringtoshow.='
'; if ($shownb && $showtot) { - $stringtoshow ='
'; + $stringtoshow.='
'; $stringtoshow.='
'; } if ($shownb) $stringtoshow.=$px1->show(); diff --git a/htdocs/core/boxes/box_graph_invoices_supplier_permonth.php b/htdocs/core/boxes/box_graph_invoices_supplier_permonth.php index ad59e64e89f..a435a9cfdc7 100644 --- a/htdocs/core/boxes/box_graph_invoices_supplier_permonth.php +++ b/htdocs/core/boxes/box_graph_invoices_supplier_permonth.php @@ -73,10 +73,10 @@ class box_graph_invoices_supplier_permonth extends ModeleBoxes 'text' => $text, 'limit'=> dol_strlen($text), 'graph'=> 1, - 'sublink'=>$_SERVER["PHP_SELF"].'?action='.$refreshaction, - 'subtext'=>$langs->trans("Refresh"), - 'subpicto'=>'refresh.png', - 'target'=>'none' + 'sublink'=>'', + 'subtext'=>$langs->trans("Filter"), + 'subpicto'=>'filter.png', + 'target'=>'none' // Set '' to get target="_blank" ); if ($user->rights->fournisseur->facture->lire) @@ -87,11 +87,11 @@ class box_graph_invoices_supplier_permonth extends ModeleBoxes $shownb=(! empty($conf->global->FACTURE_BOX_GRAPH_SHOW_NB)); $showtot=(! isset($conf->global->FACTURE_BOX_GRAPH_SHOW_TOT) || ! empty($conf->global->FACTURE_BOX_GRAPH_SHOW_TOT)); $nowarray=dol_getdate(dol_now(),true); - $endyear=$nowarray['year']; + $endyear=(GETPOST('param'.$this->boxcode.'year')?GETPOST('param'.$this->boxcode.'year','int'):$nowarray['year']); $startyear=$endyear-1; $mode='supplier'; $userid=0; - $WIDTH='256'; + $WIDTH=($shownb && $showtot)?'256':'320'; $HEIGHT='192'; $stats = new FactureStats($this->db, 0, $mode, ($userid>0?$userid:0)); @@ -174,9 +174,23 @@ class box_graph_invoices_supplier_permonth extends ModeleBoxes if (! $mesg) { + $stringtoshow=''; + $stringtoshow.=''; + $stringtoshow.='
'; + $stringtoshow.=$langs->trans("Year").' '; + $stringtoshow.=''; + $stringtoshow.=img_picto($langs->trans("Refresh"),'refresh.png'); + $stringtoshow.=''; + $stringtoshow.='
'; if ($shownb && $showtot) { - $stringtoshow ='
'; + $stringtoshow.='
'; $stringtoshow.='
'; } if ($shownb) $stringtoshow.=$px1->show(); diff --git a/htdocs/core/boxes/box_graph_orders_permonth.php b/htdocs/core/boxes/box_graph_orders_permonth.php index 1f292364aa2..cc4310a266e 100644 --- a/htdocs/core/boxes/box_graph_orders_permonth.php +++ b/htdocs/core/boxes/box_graph_orders_permonth.php @@ -74,10 +74,10 @@ class box_graph_orders_permonth extends ModeleBoxes 'text' => $text, 'limit'=> dol_strlen($text), 'graph'=> 1, - 'sublink'=>$_SERVER["PHP_SELF"].'?action='.$refreshaction, - 'subtext'=>$langs->trans("Refresh"), - 'subpicto'=>'refresh.png', - 'target'=>'none' + 'sublink'=>'', + 'subtext'=>$langs->trans("Filter"), + 'subpicto'=>'filter.png', + 'target'=>'none' // Set '' to get target="_blank" ); if ($user->rights->commande->lire) @@ -88,11 +88,11 @@ class box_graph_orders_permonth extends ModeleBoxes $shownb=(! empty($conf->global->COMMANDE_BOX_GRAPH_SHOW_NB)); $showtot=(! isset($conf->global->COMMANDE_BOX_GRAPH_SHOW_TOT) || ! empty($conf->global->COMMANDE_BOX_GRAPH_SHOW_TOT)); $nowarray=dol_getdate(dol_now(),true); - $endyear=$nowarray['year']; + $endyear=(GETPOST('param'.$this->boxcode.'year')?GETPOST('param'.$this->boxcode.'year','int'):$nowarray['year']); $startyear=$endyear-1; $mode='customer'; $userid=0; - $WIDTH='256'; + $WIDTH=($shownb && $showtot)?'256':'320'; $HEIGHT='192'; $stats = new CommandeStats($this->db, 0, $mode, ($userid>0?$userid:0)); @@ -175,9 +175,23 @@ class box_graph_orders_permonth extends ModeleBoxes if (! $mesg) { + $stringtoshow=''; + $stringtoshow.=''; + $stringtoshow.='
'; + $stringtoshow.=$langs->trans("Year").' '; + $stringtoshow.=''; + $stringtoshow.=img_picto($langs->trans("Refresh"),'refresh.png'); + $stringtoshow.=''; + $stringtoshow.='
'; if ($shownb && $showtot) { - $stringtoshow ='
'; + $stringtoshow.='
'; $stringtoshow.='
'; } if ($shownb) $stringtoshow.=$px1->show(); diff --git a/htdocs/core/boxes/box_graph_orders_supplier_permonth.php b/htdocs/core/boxes/box_graph_orders_supplier_permonth.php index 23e701af36e..75b4f26bbc4 100644 --- a/htdocs/core/boxes/box_graph_orders_supplier_permonth.php +++ b/htdocs/core/boxes/box_graph_orders_supplier_permonth.php @@ -73,10 +73,10 @@ class box_graph_orders_supplier_permonth extends ModeleBoxes 'text' => $text, 'limit'=> dol_strlen($text), 'graph'=> 1, - 'sublink'=>$_SERVER["PHP_SELF"].'?action='.$refreshaction, - 'subtext'=>$langs->trans("Refresh"), - 'subpicto'=>'refresh.png', - 'target'=>'none' + 'sublink'=>'', + 'subtext'=>$langs->trans("Filter"), + 'subpicto'=>'filter.png', + 'target'=>'none' // Set '' to get target="_blank" ); if ($user->rights->fournisseur->commande->lire) @@ -87,11 +87,11 @@ class box_graph_orders_supplier_permonth extends ModeleBoxes $shownb=(! empty($conf->global->COMMANDE_BOX_GRAPH_SHOW_NB)); $showtot=(! isset($conf->global->COMMANDE_BOX_GRAPH_SHOW_TOT) || ! empty($conf->global->COMMANDE_BOX_GRAPH_SHOW_TOT)); $nowarray=dol_getdate(dol_now(),true); - $endyear=$nowarray['year']; + $endyear=(GETPOST('param'.$this->boxcode.'year')?GETPOST('param'.$this->boxcode.'year','int'):$nowarray['year']); $startyear=$endyear-1; $mode='supplier'; $userid=0; - $WIDTH='256'; + $WIDTH=($shownb && $showtot)?'256':'320'; $HEIGHT='192'; $stats = new CommandeStats($this->db, 0, $mode, ($userid>0?$userid:0)); @@ -174,9 +174,23 @@ class box_graph_orders_supplier_permonth extends ModeleBoxes if (! $mesg) { + $stringtoshow=''; + $stringtoshow.=''; + $stringtoshow.='
'; + $stringtoshow.=$langs->trans("Year").' '; + $stringtoshow.=''; + $stringtoshow.=img_picto($langs->trans("Refresh"),'refresh.png'); + $stringtoshow.=''; + $stringtoshow.='
'; if ($shownb && $showtot) { - $stringtoshow ='
'; + $stringtoshow.='
'; $stringtoshow.='
'; } if ($shownb) $stringtoshow.=$px1->show(); diff --git a/htdocs/core/boxes/box_graph_propales_permonth.php b/htdocs/core/boxes/box_graph_propales_permonth.php index 182639da994..d27d4385d8f 100644 --- a/htdocs/core/boxes/box_graph_propales_permonth.php +++ b/htdocs/core/boxes/box_graph_propales_permonth.php @@ -74,10 +74,10 @@ class box_graph_propales_permonth extends ModeleBoxes 'text' => $text, 'limit'=> dol_strlen($text), 'graph'=> 1, - 'sublink'=>$_SERVER["PHP_SELF"].'?action='.$refreshaction, - 'subtext'=>$langs->trans("Refresh"), - 'subpicto'=>'refresh.png', - 'target'=>'none' + 'sublink'=>'', + 'subtext'=>$langs->trans("Filter"), + 'subpicto'=>'filter.png', + 'target'=>'none' // Set '' to get target="_blank" ); if ($user->rights->commande->lire) @@ -88,11 +88,11 @@ class box_graph_propales_permonth extends ModeleBoxes $shownb=(! empty($conf->global->PROPAL_BOX_GRAPH_SHOW_NB)); $showtot=(! isset($conf->global->PROPAL_BOX_GRAPH_SHOW_TOT) || ! empty($conf->global->PROPAL_BOX_GRAPH_SHOW_TOT)); $nowarray=dol_getdate(dol_now(),true); - $endyear=$nowarray['year']; + $endyear=(GETPOST('param'.$this->boxcode.'year')?GETPOST('param'.$this->boxcode.'year','int'):$nowarray['year']); $startyear=$endyear-1; $mode='customer'; $userid=0; - $WIDTH='256'; + $WIDTH=($shownb && $showtot)?'256':'320'; $HEIGHT='192'; $stats = new PropaleStats($this->db, 0, $mode, ($userid>0?$userid:0)); @@ -101,7 +101,8 @@ class box_graph_propales_permonth extends ModeleBoxes if ($shownb) { $data1 = $stats->getNbByMonthWithPrevYear($endyear,$startyear,(GETPOST('action')==$refreshaction?-1:(3600*24))); - + $datatype1 = array_pad(array(), ($endyear-$startyear+1), 'bars'); + $filenamenb = $dir."/propalsnbinyear-".$year.".png"; if ($mode == 'customer') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=propalstats&file=propalsnbinyear-'.$year.'.png'; if ($mode == 'supplier') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=propalstatssupplier&file=propalsnbinyear-'.$year.'.png'; @@ -110,6 +111,7 @@ class box_graph_propales_permonth extends ModeleBoxes $mesg = $px1->isGraphKo(); if (! $mesg) { + $px1->SetType($datatype1); $px1->SetData($data1); unset($data1); $px1->SetPrecisionY(0); @@ -139,7 +141,9 @@ class box_graph_propales_permonth extends ModeleBoxes if ($showtot) { $data2 = $stats->getAmountByMonthWithPrevYear($endyear,$startyear,(GETPOST('action')==$refreshaction?-1:(3600*24))); - + $datatype2 = array_pad(array(), ($endyear-$startyear+1), 'bars'); + //$datatype2 = array('lines','bars'); + $filenamenb = $dir."/propalsamountinyear-".$year.".png"; if ($mode == 'customer') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=propalstats&file=propalsamountinyear-'.$year.'.png'; if ($mode == 'supplier') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=propalstatssupplier&file=propalsamountinyear-'.$year.'.png'; @@ -148,6 +152,7 @@ class box_graph_propales_permonth extends ModeleBoxes $mesg = $px2->isGraphKo(); if (! $mesg) { + $px2->SetType($datatype2); $px2->SetData($data2); unset($data2); $px2->SetPrecisionY(0); @@ -175,9 +180,23 @@ class box_graph_propales_permonth extends ModeleBoxes if (! $mesg) { + $stringtoshow=''; + $stringtoshow.=''; + $stringtoshow.='
'; + $stringtoshow.=$langs->trans("Year").' '; + $stringtoshow.=''; + $stringtoshow.=img_picto($langs->trans("Refresh"),'refresh.png'); + $stringtoshow.=''; + $stringtoshow.='
'; if ($shownb && $showtot) { - $stringtoshow ='
'; + $stringtoshow.='
'; $stringtoshow.='
'; } if ($shownb) $stringtoshow.=$px1->show(); diff --git a/htdocs/core/boxes/modules_boxes.php b/htdocs/core/boxes/modules_boxes.php index 10ea413740a..2d83e26a870 100644 --- a/htdocs/core/boxes/modules_boxes.php +++ b/htdocs/core/boxes/modules_boxes.php @@ -1,6 +1,6 @@ - * Copyright (C) 2005-2012 Regis Houssin +/* Copyright (C) 2004-2013 Laurent Destailleur + * Copyright (C) 2005-2012 Regis Houssin * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -135,13 +135,13 @@ class ModeleBoxes // Can't be abtract as it is instanciated to build "empty" print "\n\n\n"; print '
'."\n"; - if (! empty($head['text']) || ! empty($head['sublink']) || $nblines) + if (! empty($head['text']) || ! empty($head['sublink']) || ! empty($head['subpicto']) || $nblines) { print ''."\n"; } // Show box title - if (! empty($head['text']) || ! empty($head['sublink'])) + if (! empty($head['text']) || ! empty($head['sublink']) || ! empty($head['subpicto'])) { //print '
'."\n"; //print '
'."\n"; @@ -158,10 +158,10 @@ class ModeleBoxes // Can't be abtract as it is instanciated to build "empty" $s=dol_trunc($head['text'],isset($head['limit'])?$head['limit']:$MAXLENGTHBOX); print $s; } - if (! empty($head['sublink'])) - { - print ' '.img_picto($head['subtext'],$head['subpicto']).''; - } + print ' '; + if (! empty($head['sublink'])) print ''; + if (! empty($head['subpicto'])) print img_picto($head['subtext'], $head['subpicto'], 'class="" id="idsubimg'.$this->boxcode.'"'); + if (! empty($head['sublink'])) ''; if ($conf->use_javascript_ajax) { print ''; print "\n"; -// print "
'; @@ -175,8 +175,8 @@ class ModeleBoxes // Can't be abtract as it is instanciated to build "empty" } print '
\n"; -// print "
\n"; + //print "\n"; + //print "
\n"; } // Show box lines @@ -251,13 +251,13 @@ class ModeleBoxes // Can't be abtract as it is instanciated to build "empty" } } - if (! empty($head['text']) || ! empty($head['sublink']) || $nblines) + if (! empty($head['text']) || ! empty($head['sublink']) || ! empty($head['subpicto']) || $nblines) { print "\n"; } // If invisible box with no contents - if (empty($head['text']) && empty($head['sublink']) && ! $nblines) print "
\n"; + if (empty($head['text']) && empty($head['sublink']) && empty($head['subpicto']) && ! $nblines) print "
\n"; print "
\n"; print "\n\n"; diff --git a/htdocs/core/class/dolgraph.class.php b/htdocs/core/class/dolgraph.class.php index 5dd7fb735e9..b604ae4f8f0 100644 --- a/htdocs/core/class/dolgraph.class.php +++ b/htdocs/core/class/dolgraph.class.php @@ -43,7 +43,7 @@ class DolGraph { //! Type of graph - var $type=array('bars'); // bars, lines, ... + var $type=array(); // Array with type of each series. Example: array('bars', 'lines', ...) var $mode='side'; // Mode bars graph: side, depth private $_library='jflot'; // Graphic library to use (jflot, artichow) @@ -578,8 +578,9 @@ class DolGraph // Create graph $classname=''; - if ($this->type[0] == 'bars') $classname='BarPlot'; // Only first type of type is supported by artichow - if ($this->type[0] == 'lines') $classname='LinePlot'; + if (! isset($this->type[0]) || $this->type[0] == 'bars') $classname='BarPlot'; // Only one type (first one) is supported by artichow + else if ($this->type[0] == 'lines') $classname='LinePlot'; + else $classname='TypeUnknown'; include_once ARTICHOW_PATH.$classname.'.class.php'; // Definition de couleurs diff --git a/htdocs/core/class/stats.class.php b/htdocs/core/class/stats.class.php index 819ca4c5350..24e4ffa8980 100644 --- a/htdocs/core/class/stats.class.php +++ b/htdocs/core/class/stats.class.php @@ -76,7 +76,7 @@ abstract class Stats dol_syslog(get_class($this).'_'.__FUNCTION__." cache file ".$newpathofdestfile." is not found or older than now - cachedelay (".$nowgmt." - ".$cachedelay.") so we can't use it."); } } - + // Load file into $data if ($foundintocache) // Cache file found and is not too old { @@ -184,14 +184,14 @@ abstract class Stats } $data = array(); - + // $data = array('xval'=>array(0=>xlabel,1=>yval1,2=>yval2...),...) for ($i = 0 ; $i < 12 ; $i++) { - $data[$i][]=$datay[$endyear][$i][0]; + $data[$i][]=$datay[$endyear][$i][0]; // set label $year=$startyear; while($year <= $endyear) { - $data[$i][]=$datay[$year][$i][1]; + $data[$i][]=$datay[$year][$i][1]; // set yval for x=i $year++; } }