From 666e850d72b5a79c7095d8c22a03d56e02182484 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Sun, 20 Nov 2011 11:58:52 +0100 Subject: [PATCH 1/4] Fix: uniform code --- htdocs/product/stats/fiche.php | 84 +++++++++++++++++----------------- 1 file changed, 41 insertions(+), 43 deletions(-) diff --git a/htdocs/product/stats/fiche.php b/htdocs/product/stats/fiche.php index e9a11bc217b..f48b5d13e4d 100644 --- a/htdocs/product/stats/fiche.php +++ b/htdocs/product/stats/fiche.php @@ -1,8 +1,8 @@ - * Copyright (c) 2004-2010 Laurent Destailleur - * Copyright (C) 2005-2010 Regis Houssin - * Copyright (C) 2005 Eric Seigne +/* Copyright (C) 2001-2007 Rodolphe Quiedeville + * Copyright (c) 2004-2011 Laurent Destailleur + * Copyright (C) 2005-2011 Regis Houssin + * Copyright (C) 2005 Eric Seigne * * 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 @@ -34,18 +34,17 @@ $langs->load("products"); $langs->load("bills"); $langs->load("other"); -$mode=isset($_GET["mode"])?$_GET["mode"]:'byunit'; -$error=0; -$mesg=''; +$id = GETPOST('id'); +$ref = GETPOST('ref'); +$mode = (GETPOST('mode') ? GETPOST('mode') : 'byunit'); +$error = 0; +$mesg = ''; // Security check -if (isset($_GET["id"]) || isset($_GET["ref"])) -{ - $id = isset($_GET["id"])?$_GET["id"]:(isset($_GET["ref"])?$_GET["ref"]:''); -} -$fieldid = isset($_GET["ref"])?'ref':'rowid'; +$fieldid = (! empty($id) ? $id : $ref); +$fieldtype = (! empty($ref) ? 'ref' : 'rowid'); if ($user->societe_id) $socid=$user->societe_id; -$result=restrictedArea($user,'produit|service',$id,'product','','',$fieldid); +$result=restrictedArea($user,'produit|service',$fieldid,'product','','',$fieldtype); /* @@ -53,19 +52,18 @@ $result=restrictedArea($user,'produit|service',$id,'product','','',$fieldid); */ $form = new Form($db); -if ($_GET["id"] || $_GET["ref"]) +if (! empty($id) || ! empty($ref)) { - $product = new Product($db); - if ($_GET["ref"]) $result = $product->fetch('',$_GET["ref"]); - if ($_GET["id"]) $result = $product->fetch($_GET["id"]); + $object = new Product($db); + $result = $object->fetch($id,$ref); - llxHeader("","",$langs->trans("CardProduct".$product->type)); + llxHeader("","",$langs->trans("CardProduct".$object->type)); if ($result) { - $head=product_prepare_head($product, $user); - $titre=$langs->trans("CardProduct".$product->type); - $picto=($product->type==1?'service':'product'); + $head=product_prepare_head($object, $user); + $titre=$langs->trans("CardProduct".$object->type); + $picto=($object->type==1?'service':'product'); dol_fiche_head($head, 'stats', $titre, 0, $picto); @@ -74,34 +72,34 @@ if ($_GET["id"] || $_GET["ref"]) // Reference print ''; print ''.$langs->trans("Ref").''; - print $form->showrefnav($product,'ref','',1,'ref'); + print $form->showrefnav($object,'ref','',1,'ref'); print ''; print ''; // Label - print ''.$langs->trans("Label").''.$product->libelle.''; + print ''.$langs->trans("Label").''.$object->libelle.''; // Status (to sell) print ''.$langs->trans("Status").' ('.$langs->trans("Sell").')'.''; - print $product->getLibStatut(2,0); + print $object->getLibStatut(2,0); print ''; // Status (to buy) print ''.$langs->trans("Status").' ('.$langs->trans("Buy").')'.''; - print $product->getLibStatut(2,1); + print $object->getLibStatut(2,1); print ''; // Graphs additionels generes pas le script product-graph.php $year = strftime('%Y',time()); - $file = get_exdir($product->id, 3) . "ventes-".$year."-".$product->id.".png"; + $file = get_exdir($object->id, 3) . "ventes-".$year."-".$object->id.".png"; if (file_exists (DOL_DATA_ROOT.'/product/temp/'.$file) ) { print 'Ventes'; $url=DOL_URL_ROOT.'/viewimage.php?modulepart=graph_product&file='.$file; print 'Ventes'; - $file = get_exdir($product->id, 3) . "ventes-".$product->id.".png"; + $file = get_exdir($object->id, 3) . "ventes-".$object->id.".png"; $url=DOL_URL_ROOT.'/viewimage.php?modulepart=graph_product&file='.$file; print 'Ventes'; print ''; @@ -113,12 +111,12 @@ if ($_GET["id"] || $_GET["ref"]) // Choice of stats - if ($mode == 'bynumber') print ''; + if ($mode == 'bynumber') print ''; else print img_picto('','tick').' '; print $langs->trans("StatsByNumberOfUnits"); if ($mode == 'bynumber') print ''; print '       '; - if ($mode == 'byunit') print ''; + if ($mode == 'byunit') print ''; else print img_picto('','tick').' '; print $langs->trans("StatsByNumberOfEntities"); if ($mode == 'byunit') print ''; @@ -131,9 +129,9 @@ if ($_GET["id"] || $_GET["ref"]) $WIDTH=380; $HEIGHT=160; $dir = (!empty($conf->product->dir_temp)?$conf->product->dir_temp:$conf->service->dir_temp); - if (! file_exists($dir.'/'.$product->id)) + if (! file_exists($dir.'/'.$object->id)) { - if (dol_mkdir($dir.'/'.$product->id) < 0) + if (dol_mkdir($dir.'/'.$object->id) < 0) { $mesg = $langs->trans("ErrorCanNotCreateDir",$dir); $error++; @@ -142,20 +140,20 @@ if ($_GET["id"] || $_GET["ref"]) $graphfiles=array( 'propal' =>array('modulepart'=>'productstats_proposals', - 'file' => $product->id.'/propal12m.png', + 'file' => $object->id.'/propal12m.png', 'label' => ($mode=='byunit'?$langs->trans("NumberOfUnitsProposals"):$langs->trans("NumberOfProposals"))), 'orders' =>array('modulepart'=>'productstats_orders', - 'file' => $product->id.'/orders12m.png', + 'file' => $object->id.'/orders12m.png', 'label' => ($mode=='byunit'?$langs->trans("NumberOfUnitsCustomerOrders"):$langs->trans("NumberOfCustomerOrders"))), 'invoices' =>array('modulepart'=>'productstats_invoices', - 'file' => $product->id.'/invoices12m.png', + 'file' => $object->id.'/invoices12m.png', 'label' => ($mode=='byunit'?$langs->trans("NumberOfUnitsCustomerInvoices"):$langs->trans("NumberOfCustomerInvoices"))), 'invoicessuppliers'=>array('modulepart'=>'productstats_invoicessuppliers', - 'file' => $product->id.'/invoicessuppliers12m.png', + 'file' => $object->id.'/invoicessuppliers12m.png', 'label' => ($mode=='byunit'?$langs->trans("NumberOfUnitsSupplierInvoices"):$langs->trans("NumberOfSupplierInvoices"))), - // 'orderssuppliers' =>array('modulepart'=>'productstats_orderssuppliers', 'file' => $product->id.'/orderssuppliers12m.png', 'label' => $langs->trans("Nombre commande fournisseurs sur les 12 derniers mois")), - // 'contracts' =>array('modulepart'=>'productstats_contracts', 'file' => $product->id.'/contracts12m.png', 'label' => $langs->trans("Nombre contrats sur les 12 derniers mois")), + // 'orderssuppliers' =>array('modulepart'=>'productstats_orderssuppliers', 'file' => $object->id.'/orderssuppliers12m.png', 'label' => $langs->trans("Nombre commande fournisseurs sur les 12 derniers mois")), + // 'contracts' =>array('modulepart'=>'productstats_contracts', 'file' => $object->id.'/contracts12m.png', 'label' => $langs->trans("Nombre contrats sur les 12 derniers mois")), ); @@ -173,10 +171,10 @@ if ($_GET["id"] || $_GET["ref"]) $graph_data = array(); // TODO Test si deja existant et recent, on ne genere pas - if ($key == 'propal') $graph_data = $product->get_nb_propal($socid,$mode); - if ($key == 'orders') $graph_data = $product->get_nb_order($socid,$mode); - if ($key == 'invoices') $graph_data = $product->get_nb_vente($socid,$mode); - if ($key == 'invoicessuppliers') $graph_data = $product->get_nb_achat($socid,$mode); + if ($key == 'propal') $graph_data = $object->get_nb_propal($socid,$mode); + if ($key == 'orders') $graph_data = $object->get_nb_order($socid,$mode); + if ($key == 'invoices') $graph_data = $object->get_nb_vente($socid,$mode); + if ($key == 'invoicessuppliers') $graph_data = $object->get_nb_achat($socid,$mode); if (is_array($graph_data)) { $px->SetData($graph_data); @@ -193,7 +191,7 @@ if ($_GET["id"] || $_GET["ref"]) } else { - dol_print_error($db,'Error for calculating graph on key='.$key.' - '.$product->error); + dol_print_error($db,'Error for calculating graph on key='.$key.' - '.$object->error); } } } @@ -240,7 +238,7 @@ if ($_GET["id"] || $_GET["ref"]) { print ''.($mesg?''.$mesg.'':$langs->trans("ChartNotGenerated")).''; } - print ''.img_picto($langs->trans("ReCalculate"),'refresh').''; + print ''.img_picto($langs->trans("ReCalculate"),'refresh').''; print ''; print ''; From 065d7996f5f5e860affb3f5993c371a88345c501 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Sun, 20 Nov 2011 15:25:08 +0100 Subject: [PATCH 2/4] Fix: better with json_encode --- htdocs/adherents/index.php | 8 +- htdocs/comm/propal/index.php | 2 +- htdocs/commande/index.php | 2 +- htdocs/compta/deplacement/index.php | 2 +- htdocs/compta/dons/index.php | 2 +- htdocs/contrat/index.php | 2 +- htdocs/core/lib/functions.lib.php | 378 +++++++++++++--------------- htdocs/fourn/commande/index.php | 2 +- htdocs/societe/index.php | 6 +- 9 files changed, 188 insertions(+), 216 deletions(-) diff --git a/htdocs/adherents/index.php b/htdocs/adherents/index.php index bf775508338..98cd8deac0b 100644 --- a/htdocs/adherents/index.php +++ b/htdocs/adherents/index.php @@ -178,10 +178,10 @@ if ($conf->use_javascript_ajax) */ $dataseries=array(); - $dataseries[]=array('label'=>$langs->trans("MenuMembersNotUpToDate"),'values'=>array(round($SommeB))); - $dataseries[]=array('label'=>$langs->trans("MenuMembersUpToDate"),'values'=>array(round($SommeC))); - $dataseries[]=array('label'=>$langs->trans("MembersStatusResiliated"),'values'=>array(round($SommeD))); - $dataseries[]=array('label'=>$langs->trans("MembersStatusToValid"),'values'=>array(round($SommeA))); + $dataseries[]=array('label'=>$langs->trans("MenuMembersNotUpToDate"),'data'=>round($SommeB)); + $dataseries[]=array('label'=>$langs->trans("MenuMembersUpToDate"),'data'=>round($SommeC)); + $dataseries[]=array('label'=>$langs->trans("MembersStatusResiliated"),'data'=>round($SommeD)); + $dataseries[]=array('label'=>$langs->trans("MembersStatusToValid"),'data'=>round($SommeA)); $data=array('series'=>$dataseries); dol_print_graph('stats',300,180,$data,1,'pie',1); print ''; diff --git a/htdocs/comm/propal/index.php b/htdocs/comm/propal/index.php index ae58515b3a4..6e5c667466c 100644 --- a/htdocs/comm/propal/index.php +++ b/htdocs/comm/propal/index.php @@ -121,7 +121,7 @@ if ($resql) $listofstatus=array(0,1,2,3,4); foreach ($listofstatus as $status) { - $dataseries[]=array('label'=>$propalstatic->LibStatut($status,1),'values'=>array(0=>(isset($vals[$status])?$vals[$status]:0))); + $dataseries[]=array('label'=>$propalstatic->LibStatut($status,1),'data'=>(isset($vals[$status])?$vals[$status]:0)); if (! $conf->use_javascript_ajax) { $var=!$var; diff --git a/htdocs/commande/index.php b/htdocs/commande/index.php index 2a3c6d91175..ee8c7db198b 100644 --- a/htdocs/commande/index.php +++ b/htdocs/commande/index.php @@ -121,7 +121,7 @@ if ($resql) $bool=false; foreach ($listofstatus as $status) { - $dataseries[]=array('label'=>$commandestatic->LibStatut($status,$bool,1),'values'=>array(0=>(isset($vals[$status.$bool])?$vals[$status.$bool]:0))); + $dataseries[]=array('label'=>$commandestatic->LibStatut($status,$bool,1),'data'=>(isset($vals[$status.$bool])?$vals[$status.$bool]:0)); if ($status==3 && $bool==false) $bool=true; else $bool=false; } diff --git a/htdocs/compta/deplacement/index.php b/htdocs/compta/deplacement/index.php index abd0e3d226e..2cb32b122e1 100644 --- a/htdocs/compta/deplacement/index.php +++ b/htdocs/compta/deplacement/index.php @@ -105,7 +105,7 @@ print "\n"; $listoftype=$tripandexpense_static->listOfTypes(); foreach ($listoftype as $code => $label) { - $dataseries[]=array('label'=>$label,'values'=>array(0=>(isset($nb[$code])?$nb[$code]:0))); + $dataseries[]=array('label'=>$label,'data'=>(isset($nb[$code])?$nb[$code]:0)); } if ($conf->use_javascript_ajax) diff --git a/htdocs/compta/dons/index.php b/htdocs/compta/dons/index.php index 9f9dab362e1..b849975e147 100644 --- a/htdocs/compta/dons/index.php +++ b/htdocs/compta/dons/index.php @@ -87,7 +87,7 @@ print "\n"; $listofstatus=array(0,1,-1,2); foreach ($listofstatus as $status) { - $dataseries[]=array('label'=>$donstatic->LibStatut($status,1),'values'=>array(0=>(isset($nb[$status])?$nb[$status]:0))); + $dataseries[]=array('label'=>$donstatic->LibStatut($status,1),'data'=>(isset($nb[$status])?$nb[$status]:0)); } if ($conf->use_javascript_ajax) diff --git a/htdocs/contrat/index.php b/htdocs/contrat/index.php index 5c3ae69c4a6..31bcbeb9127 100644 --- a/htdocs/contrat/index.php +++ b/htdocs/contrat/index.php @@ -180,7 +180,7 @@ $var=true; $listofstatus=array(0,4,4,5); $bool=false; foreach($listofstatus as $status) { - $dataseries[]=array('label'=>$staticcontratligne->LibStatut($status,1,($bool?1:0)),'values'=>array(0=>($nb[$status.$bool]?$nb[$status.$bool]:0))); + $dataseries[]=array('label'=>$staticcontratligne->LibStatut($status,1,($bool?1:0)),'data'=>($nb[$status.$bool]?$nb[$status.$bool]:0)); if (! $conf->use_javascript_ajax) { $var=!$var; diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 2a906d070ba..5570fc2d963 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -1500,213 +1500,185 @@ function dolibarr_trunc($string,$size=40,$trunc='right',$stringencoding='') /** * Show a javascript graph - * @param htmlid Html id name - * @param width Width in pixel - * @param height Height in pixel - * @param data Data array - * @param showlegend 1 to show legend, 0 otherwise - * @param type Type of graph ('pie', 'barline') - * @param showpercent Show percent (with type='pie' only) - * @param url Param to add an url to click values + * + * @param string $htmlid Html id name + * @param int $width Width in pixel + * @param int $height Height in pixel + * @param array $data Data array + * @param int $showlegend 1 to show legend, 0 otherwise + * @param string $type Type of graph ('pie', 'barline') + * @param int $showpercent Show percent (with type='pie' only) + * @param string $url Param to add an url to click values + * @return void */ function dol_print_graph($htmlid,$width,$height,$data,$showlegend=0,$type='pie',$showpercent=0,$url='') { - global $conf,$langs; - global $theme_datacolor; // To have var kept when function is called several times - if (empty($conf->use_javascript_ajax)) return; - $jsgraphlib='flot'; - $datacolor=array(); - + global $conf,$langs; + global $theme_datacolor; // To have var kept when function is called several times + if (empty($conf->use_javascript_ajax)) return; + $jsgraphlib='flot'; + $datacolor=array(); + // Load colors of theme into $datacolor array - $color_file = DOL_DOCUMENT_ROOT."/theme/".$conf->theme."/graph-color.php"; - if (is_readable($color_file)) - { - include_once($color_file); - if (isset($theme_datacolor)) - { - $datacolor=array(); - foreach($theme_datacolor as $val) - { - $datacolor[]="#".sprintf("%02x",$val[0]).sprintf("%02x",$val[1]).sprintf("%02x",$val[2]); - } - } - } - print '
'; - - // We use Flot js lib - if ($jsgraphlib == 'flot') - { - if ($type == 'pie') - { - // data is array('series'=>array(serie1,serie2,...), - // 'seriestype'=>array('bar','line',...), - // 'seriescolor'=>array(0=>'#999999',1=>'#999999',...) - // 'xlabel'=>array(0=>labelx1,1=>labelx2,...)); - // serieX is array('label'=>'label', values=>array(0=>val)) - print ' - '; - } - else if ($type == 'barline') - { - // data is array('series'=>array(serie1,serie2,...), - // 'seriestype'=>array('bar','line',...), - // 'seriescolor'=>array(0=>'#999999',1=>'#999999',...) - // 'xlabel'=>array(0=>labelx1,1=>labelx2,...)); - // serieX is array('label'=>'label', values=>array(0=>y1,1=>y2,...)) with same nb of value than into xlabel - print ' - '; - } - else print 'BadValueForPArameterType'; - } + $color_file = DOL_DOCUMENT_ROOT."/theme/".$conf->theme."/graph-color.php"; + if (is_readable($color_file)) + { + include_once($color_file); + if (isset($theme_datacolor)) + { + $datacolor=array(); + foreach($theme_datacolor as $val) + { + $datacolor[]="#".sprintf("%02x",$val[0]).sprintf("%02x",$val[1]).sprintf("%02x",$val[2]); + } + } + } + print '
'; + + // We use Flot js lib + if ($jsgraphlib == 'flot') + { + if ($type == 'pie') + { + // data is array('series'=>array(serie1,serie2,...), + // 'seriestype'=>array('bar','line',...), + // 'seriescolor'=>array(0=>'#999999',1=>'#999999',...) + // 'xlabel'=>array(0=>labelx1,1=>labelx2,...)); + // serieX is array('label'=>'label', data=>val) + print ' + '; + } + else if ($type == 'barline') + { + // data is array('series'=>array(serie1,serie2,...), + // 'seriestype'=>array('bar','line',...), + // 'seriescolor'=>array(0=>'#999999',1=>'#999999',...) + // 'xlabel'=>array(0=>labelx1,1=>labelx2,...)); + // serieX is array('label'=>'label', values=>array(0=>y1,1=>y2,...)) with same nb of value than into xlabel + print ' + '; + } + else print 'BadValueForPArameterType'; + } } /** diff --git a/htdocs/fourn/commande/index.php b/htdocs/fourn/commande/index.php index 69654b83e42..fa1349fe59b 100644 --- a/htdocs/fourn/commande/index.php +++ b/htdocs/fourn/commande/index.php @@ -118,7 +118,7 @@ if ($resql) print "\n"; foreach (array(0,1,2,3,4,5,6) as $statut) { - $dataseries[]=array('label'=>$commandestatic->LibStatut($statut,1),'values'=>array(0=>(isset($vals[$statut])?$vals[$statut]:0))); + $dataseries[]=array('label'=>$commandestatic->LibStatut($statut,1),'data'=>(isset($vals[$statut])?$vals[$statut]:0)); if (! $conf->use_javascript_ajax) { $var=!$var; diff --git a/htdocs/societe/index.php b/htdocs/societe/index.php index bbd9938994d..ebbdbfd7292 100644 --- a/htdocs/societe/index.php +++ b/htdocs/societe/index.php @@ -108,9 +108,9 @@ if ($conf->use_javascript_ajax && ((round($third['prospect'])?1:0)+(round($third { print ''; $dataseries=array(); - if ($conf->societe->enabled && empty($conf->global->SOCIETE_DISABLE_PROSPECTS_STATS)) $dataseries[]=array('label'=>$langs->trans("Prospects"),'values'=>array(round($third['prospect']))); - if ($conf->societe->enabled && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS_STATS)) $dataseries[]=array('label'=>$langs->trans("Customers"),'values'=>array(round($third['customer']))); - if ($conf->fournisseur->enabled && empty($conf->global->SOCIETE_DISABLE_SUPPLIERS_STATS)) $dataseries[]=array('label'=>$langs->trans("Suppliers"),'values'=>array(round($third['supplier']))); + if ($conf->societe->enabled && empty($conf->global->SOCIETE_DISABLE_PROSPECTS_STATS)) $dataseries[]=array('label'=>$langs->trans("Prospects"),'data'=>round($third['prospect'])); + if ($conf->societe->enabled && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS_STATS)) $dataseries[]=array('label'=>$langs->trans("Customers"),'data'=>round($third['customer'])); + if ($conf->fournisseur->enabled && empty($conf->global->SOCIETE_DISABLE_SUPPLIERS_STATS)) $dataseries[]=array('label'=>$langs->trans("Suppliers"),'data'=>round($third['supplier'])); $data=array('series'=>$dataseries); dol_print_graph('stats',300,180,$data,1,'pie',0); print ''; From 3c7c220bad31f4d1c6b22924f2e2b420a89b1d22 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Sun, 20 Nov 2011 16:34:30 +0100 Subject: [PATCH 3/4] Fix: better with json_encode for use string for cols and rows name --- htdocs/adherents/index.php | 27 ++- htdocs/comm/propal/index.php | 2 +- htdocs/commande/index.php | 2 +- htdocs/compta/deplacement/index.php | 2 +- htdocs/compta/dons/index.php | 2 +- htdocs/contrat/index.php | 2 +- htdocs/core/lib/functions.lib.php | 354 ++++++++++++---------------- htdocs/fourn/commande/index.php | 2 +- htdocs/societe/index.php | 6 +- 9 files changed, 174 insertions(+), 225 deletions(-) diff --git a/htdocs/adherents/index.php b/htdocs/adherents/index.php index bf775508338..2734139d87e 100644 --- a/htdocs/adherents/index.php +++ b/htdocs/adherents/index.php @@ -154,13 +154,14 @@ if ($conf->use_javascript_ajax) $SommeD=0; $dataval=array(); $datalabels=array(); + $i=1; foreach ($AdherentType as $key => $adhtype) { - $datalabels[]=$adhtype->getNomUrl(0,dol_size(16)); - $dataval['draft'][]=isset($MemberToValidate[$key])?$MemberToValidate[$key]:0; - $dataval['notuptodate'][]=isset($MembersValidated[$key])?$MembersValidated[$key]-$MemberUpToDate[$key]:0; - $dataval['uptodate'][]=isset($MemberUpToDate[$key])?$MemberUpToDate[$key]:0; - $dataval['resiliated'][]=isset($MembersResiliated[$key])?$MembersResiliated[$key]:0; + $datalabels[]=array($i,$adhtype->getNomUrl(0,dol_size(16))); + $dataval['draft'][]=array($i,isset($MemberToValidate[$key])?$MemberToValidate[$key]:0); + $dataval['notuptodate'][]=array($i,isset($MembersValidated[$key])?$MembersValidated[$key]-$MemberUpToDate[$key]:0); + $dataval['uptodate'][]=array($i,isset($MemberUpToDate[$key])?$MemberUpToDate[$key]:0); + $dataval['resiliated'][]=array($i,isset($MembersResiliated[$key])?$MembersResiliated[$key]:0); $SommeA+=isset($MemberToValidate[$key])?$MemberToValidate[$key]:0; $SommeB+=isset($MembersValidated[$key])?$MembersValidated[$key]-$MemberUpToDate[$key]:0; $SommeC+=isset($MemberUpToDate[$key])?$MemberUpToDate[$key]:0; @@ -169,19 +170,19 @@ if ($conf->use_javascript_ajax) /* $dataseries=array(); - $dataseries[]=array('label'=>$langs->trans("MembersStatusToValid"),'values'=> $dataval['draft']); - $dataseries[]=array('label'=>$langs->trans("MenuMembersNotUpToDate"),'values'=> $dataval['notuptodate']); - $dataseries[]=array('label'=>$langs->trans("MenuMembersUpToDate"),'values'=> $dataval['uptodate']); - $dataseries[]=array('label'=>$langs->trans("MembersStatusResiliated"),'values'=> $dataval['resiliated']); + $dataseries[]=array('label'=>$langs->trans("MembersStatusToValid"),'data'=> $dataval['draft']); + $dataseries[]=array('label'=>$langs->trans("MenuMembersNotUpToDate"),'data'=> $dataval['notuptodate']); + $dataseries[]=array('label'=>$langs->trans("MenuMembersUpToDate"),'data'=> $dataval['uptodate']); + $dataseries[]=array('label'=>$langs->trans("MembersStatusResiliated"),'data'=> $dataval['resiliated']); $data=array('series'=>$dataseries,'seriestype'=>array('bar','bar','bar','bar'),'xlabel'=>$datalabels); dol_print_graph('stats2',300,180,$data,1,'barline'); */ $dataseries=array(); - $dataseries[]=array('label'=>$langs->trans("MenuMembersNotUpToDate"),'values'=>array(round($SommeB))); - $dataseries[]=array('label'=>$langs->trans("MenuMembersUpToDate"),'values'=>array(round($SommeC))); - $dataseries[]=array('label'=>$langs->trans("MembersStatusResiliated"),'values'=>array(round($SommeD))); - $dataseries[]=array('label'=>$langs->trans("MembersStatusToValid"),'values'=>array(round($SommeA))); + $dataseries[]=array('label'=>$langs->trans("MenuMembersNotUpToDate"),'data'=>round($SommeB)); + $dataseries[]=array('label'=>$langs->trans("MenuMembersUpToDate"),'data'=>round($SommeC)); + $dataseries[]=array('label'=>$langs->trans("MembersStatusResiliated"),'data'=>round($SommeD)); + $dataseries[]=array('label'=>$langs->trans("MembersStatusToValid"),'data'=>round($SommeA)); $data=array('series'=>$dataseries); dol_print_graph('stats',300,180,$data,1,'pie',1); print ''; diff --git a/htdocs/comm/propal/index.php b/htdocs/comm/propal/index.php index ae58515b3a4..6e5c667466c 100644 --- a/htdocs/comm/propal/index.php +++ b/htdocs/comm/propal/index.php @@ -121,7 +121,7 @@ if ($resql) $listofstatus=array(0,1,2,3,4); foreach ($listofstatus as $status) { - $dataseries[]=array('label'=>$propalstatic->LibStatut($status,1),'values'=>array(0=>(isset($vals[$status])?$vals[$status]:0))); + $dataseries[]=array('label'=>$propalstatic->LibStatut($status,1),'data'=>(isset($vals[$status])?$vals[$status]:0)); if (! $conf->use_javascript_ajax) { $var=!$var; diff --git a/htdocs/commande/index.php b/htdocs/commande/index.php index 2a3c6d91175..ee8c7db198b 100644 --- a/htdocs/commande/index.php +++ b/htdocs/commande/index.php @@ -121,7 +121,7 @@ if ($resql) $bool=false; foreach ($listofstatus as $status) { - $dataseries[]=array('label'=>$commandestatic->LibStatut($status,$bool,1),'values'=>array(0=>(isset($vals[$status.$bool])?$vals[$status.$bool]:0))); + $dataseries[]=array('label'=>$commandestatic->LibStatut($status,$bool,1),'data'=>(isset($vals[$status.$bool])?$vals[$status.$bool]:0)); if ($status==3 && $bool==false) $bool=true; else $bool=false; } diff --git a/htdocs/compta/deplacement/index.php b/htdocs/compta/deplacement/index.php index abd0e3d226e..2cb32b122e1 100644 --- a/htdocs/compta/deplacement/index.php +++ b/htdocs/compta/deplacement/index.php @@ -105,7 +105,7 @@ print "\n"; $listoftype=$tripandexpense_static->listOfTypes(); foreach ($listoftype as $code => $label) { - $dataseries[]=array('label'=>$label,'values'=>array(0=>(isset($nb[$code])?$nb[$code]:0))); + $dataseries[]=array('label'=>$label,'data'=>(isset($nb[$code])?$nb[$code]:0)); } if ($conf->use_javascript_ajax) diff --git a/htdocs/compta/dons/index.php b/htdocs/compta/dons/index.php index 9f9dab362e1..b849975e147 100644 --- a/htdocs/compta/dons/index.php +++ b/htdocs/compta/dons/index.php @@ -87,7 +87,7 @@ print "\n"; $listofstatus=array(0,1,-1,2); foreach ($listofstatus as $status) { - $dataseries[]=array('label'=>$donstatic->LibStatut($status,1),'values'=>array(0=>(isset($nb[$status])?$nb[$status]:0))); + $dataseries[]=array('label'=>$donstatic->LibStatut($status,1),'data'=>(isset($nb[$status])?$nb[$status]:0)); } if ($conf->use_javascript_ajax) diff --git a/htdocs/contrat/index.php b/htdocs/contrat/index.php index 5c3ae69c4a6..31bcbeb9127 100644 --- a/htdocs/contrat/index.php +++ b/htdocs/contrat/index.php @@ -180,7 +180,7 @@ $var=true; $listofstatus=array(0,4,4,5); $bool=false; foreach($listofstatus as $status) { - $dataseries[]=array('label'=>$staticcontratligne->LibStatut($status,1,($bool?1:0)),'values'=>array(0=>($nb[$status.$bool]?$nb[$status.$bool]:0))); + $dataseries[]=array('label'=>$staticcontratligne->LibStatut($status,1,($bool?1:0)),'data'=>($nb[$status.$bool]?$nb[$status.$bool]:0)); if (! $conf->use_javascript_ajax) { $var=!$var; diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 2a906d070ba..85e627190bd 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -1500,213 +1500,161 @@ function dolibarr_trunc($string,$size=40,$trunc='right',$stringencoding='') /** * Show a javascript graph - * @param htmlid Html id name - * @param width Width in pixel - * @param height Height in pixel - * @param data Data array - * @param showlegend 1 to show legend, 0 otherwise - * @param type Type of graph ('pie', 'barline') - * @param showpercent Show percent (with type='pie' only) - * @param url Param to add an url to click values + * + * @param string $htmlid Html id name + * @param int $width Width in pixel + * @param int $height Height in pixel + * @param array $data Data array + * @param int $showlegend 1 to show legend, 0 otherwise + * @param string $type Type of graph ('pie', 'barline') + * @param int $showpercent Show percent (with type='pie' only) + * @param string $url Param to add an url to click values + * @return void */ function dol_print_graph($htmlid,$width,$height,$data,$showlegend=0,$type='pie',$showpercent=0,$url='') { - global $conf,$langs; - global $theme_datacolor; // To have var kept when function is called several times - if (empty($conf->use_javascript_ajax)) return; - $jsgraphlib='flot'; - $datacolor=array(); - + global $conf,$langs; + global $theme_datacolor; // To have var kept when function is called several times + if (empty($conf->use_javascript_ajax)) return; + $jsgraphlib='flot'; + $datacolor=array(); + // Load colors of theme into $datacolor array - $color_file = DOL_DOCUMENT_ROOT."/theme/".$conf->theme."/graph-color.php"; - if (is_readable($color_file)) - { - include_once($color_file); - if (isset($theme_datacolor)) - { - $datacolor=array(); - foreach($theme_datacolor as $val) - { - $datacolor[]="#".sprintf("%02x",$val[0]).sprintf("%02x",$val[1]).sprintf("%02x",$val[2]); - } - } - } - print '
'; - - // We use Flot js lib - if ($jsgraphlib == 'flot') - { - if ($type == 'pie') - { - // data is array('series'=>array(serie1,serie2,...), - // 'seriestype'=>array('bar','line',...), - // 'seriescolor'=>array(0=>'#999999',1=>'#999999',...) - // 'xlabel'=>array(0=>labelx1,1=>labelx2,...)); - // serieX is array('label'=>'label', values=>array(0=>val)) - print ' - '; - } - else if ($type == 'barline') - { - // data is array('series'=>array(serie1,serie2,...), - // 'seriestype'=>array('bar','line',...), - // 'seriescolor'=>array(0=>'#999999',1=>'#999999',...) - // 'xlabel'=>array(0=>labelx1,1=>labelx2,...)); - // serieX is array('label'=>'label', values=>array(0=>y1,1=>y2,...)) with same nb of value than into xlabel - print ' - '; - } - else print 'BadValueForPArameterType'; - } + $color_file = DOL_DOCUMENT_ROOT."/theme/".$conf->theme."/graph-color.php"; + if (is_readable($color_file)) + { + include_once($color_file); + if (isset($theme_datacolor)) + { + $datacolor=array(); + foreach($theme_datacolor as $val) + { + $datacolor[]="#".sprintf("%02x",$val[0]).sprintf("%02x",$val[1]).sprintf("%02x",$val[2]); + } + } + } + print '
'; + + // We use Flot js lib + if ($jsgraphlib == 'flot') + { + if ($type == 'pie') + { + // data is array('series'=>array(serie1,serie2,...), + // 'seriestype'=>array('bar','line',...), + // 'seriescolor'=>array(0=>'#999999',1=>'#999999',...) + // 'xlabel'=>array(0=>labelx1,1=>labelx2,...)); + // serieX is array('label'=>'label', data=>val) + print ' + '; + } + else if ($type == 'barline') + { + // data is array('series'=>array(serie1,serie2,...), + // 'seriestype'=>array('bar','line',...), + // 'seriescolor'=>array(0=>'#999999',1=>'#999999',...) + // 'xlabel'=>array(1=>labelx1,2=>labelx2,...)); + // serieX is array('label'=>'label', data=>array(1=>y1,2=>y2,...)) with same nb of value than into xlabel + print ' + '; + } + else print 'BadValueForPArameterType'; + } } /** diff --git a/htdocs/fourn/commande/index.php b/htdocs/fourn/commande/index.php index 69654b83e42..fa1349fe59b 100644 --- a/htdocs/fourn/commande/index.php +++ b/htdocs/fourn/commande/index.php @@ -118,7 +118,7 @@ if ($resql) print "\n"; foreach (array(0,1,2,3,4,5,6) as $statut) { - $dataseries[]=array('label'=>$commandestatic->LibStatut($statut,1),'values'=>array(0=>(isset($vals[$statut])?$vals[$statut]:0))); + $dataseries[]=array('label'=>$commandestatic->LibStatut($statut,1),'data'=>(isset($vals[$statut])?$vals[$statut]:0)); if (! $conf->use_javascript_ajax) { $var=!$var; diff --git a/htdocs/societe/index.php b/htdocs/societe/index.php index bbd9938994d..ebbdbfd7292 100644 --- a/htdocs/societe/index.php +++ b/htdocs/societe/index.php @@ -108,9 +108,9 @@ if ($conf->use_javascript_ajax && ((round($third['prospect'])?1:0)+(round($third { print ''; $dataseries=array(); - if ($conf->societe->enabled && empty($conf->global->SOCIETE_DISABLE_PROSPECTS_STATS)) $dataseries[]=array('label'=>$langs->trans("Prospects"),'values'=>array(round($third['prospect']))); - if ($conf->societe->enabled && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS_STATS)) $dataseries[]=array('label'=>$langs->trans("Customers"),'values'=>array(round($third['customer']))); - if ($conf->fournisseur->enabled && empty($conf->global->SOCIETE_DISABLE_SUPPLIERS_STATS)) $dataseries[]=array('label'=>$langs->trans("Suppliers"),'values'=>array(round($third['supplier']))); + if ($conf->societe->enabled && empty($conf->global->SOCIETE_DISABLE_PROSPECTS_STATS)) $dataseries[]=array('label'=>$langs->trans("Prospects"),'data'=>round($third['prospect'])); + if ($conf->societe->enabled && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS_STATS)) $dataseries[]=array('label'=>$langs->trans("Customers"),'data'=>round($third['customer'])); + if ($conf->fournisseur->enabled && empty($conf->global->SOCIETE_DISABLE_SUPPLIERS_STATS)) $dataseries[]=array('label'=>$langs->trans("Suppliers"),'data'=>round($third['supplier'])); $data=array('series'=>$dataseries); dol_print_graph('stats',300,180,$data,1,'pie',0); print ''; From bb8aa4525393eceffb0e5dcd5fec48f98f11f659 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Sun, 20 Nov 2011 18:45:55 +0100 Subject: [PATCH 4/4] Fix: duplication result problem --- htdocs/compta/facture.php | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index e5b8043ec6d..8cc637afa0d 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -3052,20 +3052,21 @@ else $facturestatic=new Facture($db); - $sql = 'SELECT '; + if (! $sall) $sql = 'SELECT'; + else $sql = 'SELECT DISTINCT'; $sql.= ' f.rowid as facid, f.facnumber, f.type, f.increment, f.total, f.total_ttc,'; $sql.= ' f.datef as df, f.date_lim_reglement as datelimite,'; $sql.= ' f.paye as paye, f.fk_statut,'; $sql.= ' s.nom, s.rowid as socid'; - if (! $sall) $sql.= ' ,SUM(pf.amount) as am'; // To be able to sort on status + if (! $sall) $sql.= ', SUM(pf.amount) as am'; // To be able to sort on status $sql.= ' FROM '.MAIN_DB_PREFIX.'societe as s'; - if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + if (! $user->rights->societe->client->voir && ! $socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= ', '.MAIN_DB_PREFIX.'facture as f'; - if ($sall) $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'facturedet as fd ON fd.fk_facture = f.rowid'; if (! $sall) $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'paiement_facture as pf ON pf.fk_facture = f.rowid'; + else $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'facturedet as fd ON fd.fk_facture = f.rowid'; $sql.= ' WHERE f.fk_soc = s.rowid'; $sql.= " AND f.entity = ".$conf->entity; - if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; + if (! $user->rights->societe->client->voir && ! $socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; if ($socid) $sql.= ' AND s.rowid = '.$socid; if ($userid) { @@ -3112,10 +3113,6 @@ else { $sql.= ' AND f.facnumber LIKE \'%'.$db->escape(trim($search_ref)) . '%\''; } - if ($sall) - { - $sql.= ' AND (s.nom LIKE \'%'.$db->escape($sall).'%\' OR f.facnumber LIKE \'%'.$db->escape($sall).'%\' OR f.note LIKE \'%'.$db->escape($sall).'%\' OR fd.description LIKE \'%'.$db->escape($sall).'%\')'; - } if (! $sall) { $sql.= ' GROUP BY f.rowid, f.facnumber, f.type, f.increment, f.total, f.total_ttc,'; @@ -3123,6 +3120,10 @@ else $sql.= ' f.paye, f.fk_statut,'; $sql.= ' s.nom, s.rowid'; } + else + { + $sql.= ' AND (s.nom LIKE \'%'.$db->escape($sall).'%\' OR f.facnumber LIKE \'%'.$db->escape($sall).'%\' OR f.note LIKE \'%'.$db->escape($sall).'%\' OR fd.description LIKE \'%'.$db->escape($sall).'%\')'; + } $sql.= ' ORDER BY '; $listfield=explode(',',$sortfield); foreach ($listfield as $key => $value) $sql.= $listfield[$key].' '.$sortorder.',';