Optimize cookie usage for boxes. Only 1 cookie per box, instead of 1

cookie
per
parameter.
This commit is contained in:
Laurent Destailleur 2013-09-21 12:30:44 +02:00
parent b20b82df3d
commit fd564f5c7d
7 changed files with 130 additions and 49 deletions

View File

@ -83,17 +83,29 @@ class box_graph_invoices_permonth extends ModeleBoxes
if ($user->rights->facture->lire)
{
$param_year='DOLUSERCOOKIE_param'.$this->boxcode.'year';
$param_shownb='DOLUSERCOOKIE_param'.$this->boxcode.'shownb';
$param_showtot='DOLUSERCOOKIE_param'.$this->boxcode.'showtot';
$param_year='DOLUSERCOOKIE_box_'.$this->boxcode.'_year';
$param_shownb='DOLUSERCOOKIE_box_'.$this->boxcode.'_shownb';
$param_showtot='DOLUSERCOOKIE_box_'.$this->boxcode.'_showtot';
include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
include_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facturestats.class.php';
$shownb=GETPOST($param_shownb,'alpha',4);
$showtot=GETPOST($param_showtot,'alpha',4);
if (GETPOST('DOL_AUTOSET_COOKIE'))
{
$endyear=GETPOST($param_year,'int');
$shownb=GETPOST($param_shownb,'alpha');
$showtot=GETPOST($param_showtot,'alpha');
}
else
{
include_once DOL_DOCUMENT_ROOT.'/core/lib/json.lib.php';
$tmparray=dol_json_decode($_COOKIE['DOLUSERCOOKIE_box_'.$this->boxcode],true);
$endyear=$tmparray['year'];
$shownb=$tmparray['shownb'];
$showtot=$tmparray['showtot'];
}
if (empty($shownb) && empty($showtot)) $showtot=1;
$nowarray=dol_getdate(dol_now(),true);
$endyear=(GETPOST($param_year,'',4)?GETPOST($param_year,'int',4):$nowarray['year']);
if (empty($endyear)) $endyear=$nowarray['year'];
$startyear=$endyear-1;
$mode='customer';
$userid=0;
@ -191,7 +203,7 @@ class box_graph_invoices_permonth extends ModeleBoxes
$stringtoshow.='<div class="center hideobject" id="idfilter'.$this->boxcode.'">'; // hideobject is to start hidden
$stringtoshow.='<form class="flat formboxfilter" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
$stringtoshow.='<input type="hidden" name="action" value="'.$refreshaction.'">';
$stringtoshow.='<input type="hidden" name="DOL_AUTOSET_COOKIE" value="'.$param_year.','.$param_shownb.','.$param_showtot.'">';
$stringtoshow.='<input type="hidden" name="DOL_AUTOSET_COOKIE" value="DOLUSERCOOKIE_box_'.$this->boxcode.':year,shownb,showtot">';
$stringtoshow.='<input type="checkbox" name="'.$param_shownb.'"'.($shownb?' checked="true"':'').'"> '.$langs->trans("NumberOfBillsByMonth");
$stringtoshow.=' &nbsp; ';
$stringtoshow.='<input type="checkbox" name="'.$param_showtot.'"'.($showtot?' checked="true"':'').'"> '.$langs->trans("AmountOfBillsByMonthHT");

View File

@ -82,17 +82,29 @@ class box_graph_invoices_supplier_permonth extends ModeleBoxes
if ($user->rights->fournisseur->facture->lire)
{
$param_year='DOLUSERCOOKIE_param'.$this->boxcode.'year';
$param_shownb='DOLUSERCOOKIE_param'.$this->boxcode.'shownb';
$param_showtot='DOLUSERCOOKIE_param'.$this->boxcode.'showtot';
$param_year='DOLUSERCOOKIE_box_'.$this->boxcode.'_year';
$param_shownb='DOLUSERCOOKIE_box_'.$this->boxcode.'_shownb';
$param_showtot='DOLUSERCOOKIE_box_'.$this->boxcode.'_showtot';
include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
include_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facturestats.class.php';
$shownb=GETPOST($param_shownb,'alpha',4);
$showtot=GETPOST($param_showtot,'alpha',4);
if (GETPOST('DOL_AUTOSET_COOKIE'))
{
$endyear=GETPOST($param_year,'int');
$shownb=GETPOST($param_shownb,'alpha');
$showtot=GETPOST($param_showtot,'alpha');
}
else
{
include_once DOL_DOCUMENT_ROOT.'/core/lib/json.lib.php';
$tmparray=dol_json_decode($_COOKIE['DOLUSERCOOKIE_box_'.$this->boxcode],true);
$endyear=$tmparray['year'];
$shownb=$tmparray['shownb'];
$showtot=$tmparray['showtot'];
}
if (empty($shownb) && empty($showtot)) $showtot=1;
$nowarray=dol_getdate(dol_now(),true);
$endyear=(GETPOST($param_year,'',4)?GETPOST($param_year,'int',4):$nowarray['year']);
if (empty($endyear)) $endyear=$nowarray['year'];
$startyear=$endyear-1;
$mode='supplier';
$userid=0;
@ -190,7 +202,7 @@ class box_graph_invoices_supplier_permonth extends ModeleBoxes
$stringtoshow.='<div class="center hideobject" id="idfilter'.$this->boxcode.'">'; // hideobject is to start hidden
$stringtoshow.='<form class="flat formboxfilter" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
$stringtoshow.='<input type="hidden" name="action" value="'.$refreshaction.'">';
$stringtoshow.='<input type="hidden" name="DOL_AUTOSET_COOKIE" value="'.$param_year.','.$param_shownb.','.$param_showtot.'">';
$stringtoshow.='<input type="hidden" name="DOL_AUTOSET_COOKIE" value="DOLUSERCOOKIE_box_'.$this->boxcode.':year,shownb,showtot">';
$stringtoshow.='<input type="checkbox" name="'.$param_shownb.'"'.($shownb?' checked="true"':'').'"> '.$langs->trans("NumberOfBillsByMonth");
$stringtoshow.=' &nbsp; ';
$stringtoshow.='<input type="checkbox" name="'.$param_showtot.'"'.($showtot?' checked="true"':'').'"> '.$langs->trans("AmountOfBillsByMonthHT");

View File

@ -83,17 +83,29 @@ class box_graph_orders_permonth extends ModeleBoxes
if ($user->rights->commande->lire)
{
$param_year='DOLUSERCOOKIE_param'.$this->boxcode.'year';
$param_shownb='DOLUSERCOOKIE_param'.$this->boxcode.'shownb';
$param_showtot='DOLUSERCOOKIE_param'.$this->boxcode.'showtot';
$param_year='DOLUSERCOOKIE_box_'.$this->boxcode.'_year';
$param_shownb='DOLUSERCOOKIE_box_'.$this->boxcode.'_shownb';
$param_showtot='DOLUSERCOOKIE_box_'.$this->boxcode.'_showtot';
include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
include_once DOL_DOCUMENT_ROOT.'/commande/class/commandestats.class.php';
$shownb=GETPOST($param_shownb,'alpha',4);
$showtot=GETPOST($param_showtot,'alpha',4);
if (GETPOST('DOL_AUTOSET_COOKIE'))
{
$endyear=GETPOST($param_year,'int');
$shownb=GETPOST($param_shownb,'alpha');
$showtot=GETPOST($param_showtot,'alpha');
}
else
{
include_once DOL_DOCUMENT_ROOT.'/core/lib/json.lib.php';
$tmparray=dol_json_decode($_COOKIE['DOLUSERCOOKIE_box_'.$this->boxcode],true);
$endyear=$tmparray['year'];
$shownb=$tmparray['shownb'];
$showtot=$tmparray['showtot'];
}
if (empty($shownb) && empty($showtot)) $showtot=1;
$nowarray=dol_getdate(dol_now(),true);
$endyear=(GETPOST($param_year,'',4)?GETPOST($param_year,'int',4):$nowarray['year']);
if (empty($endyear)) $endyear=$nowarray['year'];
$startyear=$endyear-1;
$mode='customer';
$userid=0;
@ -191,7 +203,7 @@ class box_graph_orders_permonth extends ModeleBoxes
$stringtoshow.='<div class="center hideobject" id="idfilter'.$this->boxcode.'">'; // hideobject is to start hidden
$stringtoshow.='<form class="flat formboxfilter" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
$stringtoshow.='<input type="hidden" name="action" value="'.$refreshaction.'">';
$stringtoshow.='<input type="hidden" name="DOL_AUTOSET_COOKIE" value="'.$param_year.','.$param_shownb.','.$param_showtot.'">';
$stringtoshow.='<input type="hidden" name="DOL_AUTOSET_COOKIE" value="DOLUSERCOOKIE_box_'.$this->boxcode.':year,shownb,showtot">';
$stringtoshow.='<input type="checkbox" name="'.$param_shownb.'"'.($shownb?' checked="true"':'').'"> '.$langs->trans("NumberOfOrdersByMonth");
$stringtoshow.=' &nbsp; ';
$stringtoshow.='<input type="checkbox" name="'.$param_showtot.'"'.($showtot?' checked="true"':'').'"> '.$langs->trans("AmountOfOrdersByMonthHT");

View File

@ -82,17 +82,29 @@ class box_graph_orders_supplier_permonth extends ModeleBoxes
if ($user->rights->fournisseur->commande->lire)
{
$param_year='DOLUSERCOOKIE_param'.$this->boxcode.'year';
$param_shownb='DOLUSERCOOKIE_param'.$this->boxcode.'shownb';
$param_showtot='DOLUSERCOOKIE_param'.$this->boxcode.'showtot';
$param_year='DOLUSERCOOKIE_box_'.$this->boxcode.'_year';
$param_shownb='DOLUSERCOOKIE_box_'.$this->boxcode.'_shownb';
$param_showtot='DOLUSERCOOKIE_box_'.$this->boxcode.'_showtot';
include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
include_once DOL_DOCUMENT_ROOT.'/commande/class/commandestats.class.php';
$shownb=GETPOST($param_shownb,'alpha',4);
$showtot=GETPOST($param_showtot,'alpha',4);
if (GETPOST('DOL_AUTOSET_COOKIE'))
{
$endyear=GETPOST($param_year,'int');
$shownb=GETPOST($param_shownb,'alpha');
$showtot=GETPOST($param_showtot,'alpha');
}
else
{
include_once DOL_DOCUMENT_ROOT.'/core/lib/json.lib.php';
$tmparray=dol_json_decode($_COOKIE['DOLUSERCOOKIE_box_'.$this->boxcode],true);
$endyear=$tmparray['year'];
$shownb=$tmparray['shownb'];
$showtot=$tmparray['showtot'];
}
if (empty($shownb) && empty($showtot)) $showtot=1;
$nowarray=dol_getdate(dol_now(),true);
$endyear=(GETPOST($param_year,'',4)?GETPOST($param_year,'int',4):$nowarray['year']);
if (empty($endyear)) $endyear=$nowarray['year'];
$startyear=$endyear-1;
$mode='supplier';
$userid=0;
@ -190,7 +202,7 @@ class box_graph_orders_supplier_permonth extends ModeleBoxes
$stringtoshow.='<div class="center hideobject" id="idfilter'.$this->boxcode.'">'; // hideobject is to start hidden
$stringtoshow.='<form class="flat formboxfilter" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
$stringtoshow.='<input type="hidden" name="action" value="'.$refreshaction.'">';
$stringtoshow.='<input type="hidden" name="DOL_AUTOSET_COOKIE" value="'.$param_year.','.$param_shownb.','.$param_showtot.'">';
$stringtoshow.='<input type="hidden" name="DOL_AUTOSET_COOKIE" value="DOLUSERCOOKIE_box_'.$this->boxcode.':year,shownb,showtot">';
$stringtoshow.='<input type="checkbox" name="'.$param_shownb.'"'.($shownb?' checked="true"':'').'"> '.$langs->trans("NumberOfOrdersByMonth");
$stringtoshow.=' &nbsp; ';
$stringtoshow.='<input type="checkbox" name="'.$param_showtot.'"'.($showtot?' checked="true"':'').'"> '.$langs->trans("AmountOfOrdersByMonthHT");

View File

@ -82,20 +82,33 @@ class box_graph_product_distribution extends ModeleBoxes
'target'=>'none' // Set '' to get target="_blank"
);
$param_year='DOLUSERCOOKIE_param'.$this->boxcode.'year';
$param_showinvoicenb='DOLUSERCOOKIE_param'.$this->boxcode.'showinvoicenb';
$param_showpropalnb='DOLUSERCOOKIE_param'.$this->boxcode.'showpropalnb';
$param_showordernb='DOLUSERCOOKIE_param'.$this->boxcode.'showordernb';
$showinvoicenb=GETPOST($param_showinvoicenb,'alpha',4);
$showpropalnb=GETPOST($param_showpropalnb,'alpha',4);
$showordernb=GETPOST($param_showordernb,'alpha',4);
$param_year='DOLUSERCOOKIE_box_'.$this->boxcode.'_year';
$param_showinvoicenb='DOLUSERCOOKIE_box_'.$this->boxcode.'_showinvoicenb';
$param_showpropalnb='DOLUSERCOOKIE_box_'.$this->boxcode.'_showpropalnb';
$param_showordernb='DOLUSERCOOKIE_box_'.$this->boxcode.'_showordernb';
if (GETPOST('DOL_AUTOSET_COOKIE'))
{
$year=GETPOST($param_year,'int');
$showinvoicenb=GETPOST($param_showinvoicenb,'alpha');
$showpropalnb=GETPOST($param_showpropalnb,'alpha');
$showordernb=GETPOST($param_showordernb,'alpha');
}
else
{
include_once DOL_DOCUMENT_ROOT.'/core/lib/json.lib.php';
$tmparray=dol_json_decode($_COOKIE['DOLUSERCOOKIE_box_'.$this->boxcode],true);
$year=$tmparray['year'];
$showinvoicenb=$tmparray['showinvoicenb'];
$showpropalnb=$tmparray['showpropalnb'];
$showordernb=$tmparray['showordernb'];
}
if (empty($showinvoicenb) && empty($showpropalnb) && empty($showordernb)) { $showpropalnb=1; $showinvoicenb=1; $showordernb=1; }
if (empty($conf->facture->enabled) || empty($user->rights->facture->lire)) $showinvoicenb=0;
if (empty($conf->propal->enabled) || empty($user->rights->propal->lire)) $showpropalnb=0;
if (empty($conf->commande->enabled) || empty($user->rights->commande->lire)) $showordernb=0;
$nowarray=dol_getdate(dol_now(),true);
$year=(GETPOST($param_year,'',4)?GETPOST($param_year,'int',4):$nowarray['year']);
if (empty($year)) $year=$nowarray['year'];
$nbofgraph=0;
if ($showinvoicenb) $nbofgraph++;
@ -300,7 +313,7 @@ class box_graph_product_distribution extends ModeleBoxes
$stringtoshow.='<div class="center hideobject" id="idfilter'.$this->boxcode.'">'; // hideobject is to start hidden
$stringtoshow.='<form class="flat formboxfilter" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
$stringtoshow.='<input type="hidden" name="action" value="'.$refreshaction.'">';
$stringtoshow.='<input type="hidden" name="DOL_AUTOSET_COOKIE" value="'.$param_year.','.$param_showinvoicenb.','.$param_showpropalnb.','.$param_showordernb.'">';
$stringtoshow.='<input type="hidden" name="DOL_AUTOSET_COOKIE" value="DOLUSERCOOKIE_box_'.$this->boxcode.':year,showinvoicenb,showpropalnb,showordernb">';
if (! empty($conf->facture->enabled) || ! empty($user->rights->facture->lire))
{
$stringtoshow.='<input type="checkbox" name="'.$param_showinvoicenb.'"'.($showinvoicenb?' checked="true"':'').'> '.$langs->trans("ForCustomersInvoices");

View File

@ -83,17 +83,29 @@ class box_graph_propales_permonth extends ModeleBoxes
if ($user->rights->propal->lire)
{
$param_year='DOLUSERCOOKIE_param'.$this->boxcode.'year';
$param_shownb='DOLUSERCOOKIE_param'.$this->boxcode.'shownb';
$param_showtot='DOLUSERCOOKIE_param'.$this->boxcode.'showtot';
$param_year='DOLUSERCOOKIE_box_'.$this->boxcode.'_year';
$param_shownb='DOLUSERCOOKIE_box_'.$this->boxcode.'_shownb';
$param_showtot='DOLUSERCOOKIE_box_'.$this->boxcode.'_showtot';
include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
include_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propalestats.class.php';
$shownb=GETPOST($param_shownb,'alpha',4);
$showtot=GETPOST($param_showtot,'alpha',4);
if (GETPOST('DOL_AUTOSET_COOKIE'))
{
$endyear=GETPOST($param_year,'int');
$shownb=GETPOST($param_shownb,'alpha');
$showtot=GETPOST($param_showtot,'alpha');
}
else
{
include_once DOL_DOCUMENT_ROOT.'/core/lib/json.lib.php';
$tmparray=dol_json_decode($_COOKIE['DOLUSERCOOKIE_box_'.$this->boxcode],true);
$endyear=$tmparray['year'];
$shownb=$tmparray['shownb'];
$showtot=$tmparray['showtot'];
}
if (empty($shownb) && empty($showtot)) $showtot=1;
$nowarray=dol_getdate(dol_now(),true);
$endyear=(GETPOST($param_year,'',4)?GETPOST($param_year,'int',4):$nowarray['year']);
if (empty($endyear)) $endyear=$nowarray['year'];
$startyear=$endyear-1;
$mode='customer';
$userid=0;
@ -196,7 +208,7 @@ class box_graph_propales_permonth extends ModeleBoxes
$stringtoshow.='<div class="center hideobject divboxfilter" id="idfilter'.$this->boxcode.'">'; // hideobject is to start hidden
$stringtoshow.='<form class="flat formboxfilter" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
$stringtoshow.='<input type="hidden" name="action" value="'.$refreshaction.'">';
$stringtoshow.='<input type="hidden" name="DOL_AUTOSET_COOKIE" value="'.$param_year.','.$param_shownb.','.$param_showtot.'">';
$stringtoshow.='<input type="hidden" name="DOL_AUTOSET_COOKIE" value="DOLUSERCOOKIE_box_'.$this->boxcode.':year,shownb,showtot">';
$stringtoshow.='<input type="checkbox" name="'.$param_shownb.'"'.($shownb?' checked="true"':'').'"> '.$langs->trans("NumberOfProposalsByMonth");
$stringtoshow.=' &nbsp; ';
$stringtoshow.='<input type="checkbox" name="'.$param_showtot.'"'.($showtot?' checked="true"':'').'"> '.$langs->trans("AmountOfProposalsByMonthHT");

View File

@ -165,13 +165,21 @@ require_once 'filefunc.inc.php';
// If there is a POST parameter to tell to save automatically some POST params into a cookies, we do it
if (! empty($_POST["DOL_AUTOSET_COOKIE"]))
{
$tmplist=explode(',',$_POST["DOL_AUTOSET_COOKIE"]);
foreach ($tmplist as $value)
require_once DOL_DOCUMENT_ROOT.'/core/lib/json.lib.php';
$tmpautoset=explode(':',$_POST["DOL_AUTOSET_COOKIE"],2);
$tmplist=explode(',',$tmpautoset[1]);
$cookiearrayvalue='';
foreach ($tmplist as $tmpkey)
{
//var_dump('setcookie key='.$value.' value='.$_POST[$value]);
setcookie($value, empty($_POST[$value])?'':$_POST[$value], empty($_POST[$value])?0:(time()+(86400*354)), '/'); // keep cookie 1 year
if (empty($_POST[$value])) unset($_COOKIE[$value]);
$postkey=$tmpautoset[0].'_'.$tmpkey;
//var_dump('tmpkey='.$tmpkey.' postkey='.$postkey.' value='.$_POST[$postkey]);
if (! empty($_POST[$postkey])) $cookiearrayvalue[$tmpkey]=$_POST[$postkey];
}
$cookiename=$tmpautoset[0];
$cookievalue=dol_json_encode($cookiearrayvalue);
//var_dump('setcookie cookiename='.$cookiename.' cookievalue='.$cookievalue);
setcookie($cookiename, empty($cookievalue)?'':$cookievalue, empty($cookievalue)?0:(time()+(86400*354)), '/'); // keep cookie 1 year
if (empty($cookievalue)) unset($_COOKIE[$cookiename]);
}
// Init session. Name of session is specific to Dolibarr instance.