Fix: Better error management

This commit is contained in:
Laurent Destailleur 2011-07-04 10:04:18 +00:00
parent 7521acb00a
commit ea208fda3b

View File

@ -23,7 +23,7 @@
* \file htdocs/product/stats/fiche.php
* \ingroup product
* \brief Page des stats produits
* \version $Id$
* \version $Id: fiche.php,v 1.109 2011/07/04 10:04:18 eldy Exp $
*/
require("../../main.inc.php");
@ -37,6 +37,8 @@ $langs->load("bills");
$langs->load("other");
$mode=isset($_GET["mode"])?$_GET["mode"]:'byunit';
$error=0;
$mesg='';
// Security check
if (isset($_GET["id"]) || isset($_GET["ref"]))
@ -47,8 +49,6 @@ $fieldid = isset($_GET["ref"])?'ref':'rowid';
if ($user->societe_id) $socid=$user->societe_id;
$result=restrictedArea($user,'produit|service',$id,'product','','',$fieldid);
$mesg = '';
/*
* View
@ -135,9 +135,10 @@ if ($_GET["id"] || $_GET["ref"])
$dir = (!empty($conf->product->dir_temp)?$conf->product->dir_temp:$conf->service->dir_temp);
if (! file_exists($dir.'/'.$product->id))
{
if (create_exdir($dir.'/'.$product->id) < 0)
if (dol_mkdir($dir.'/'.$product->id) < 0)
{
$mesg = $langs->trans("ErrorCanNotCreateDir",$dir);
$error++;
}
}
@ -161,44 +162,48 @@ if ($_GET["id"] || $_GET["ref"])
);
$px = new DolGraph();
$mesg = $px->isGraphKo();
if (! $mesg)
if (! $error)
{
foreach($graphfiles as $key => $val)
$mesg = $px->isGraphKo();
if (! $mesg)
{
if (! $graphfiles[$key]['file']) continue;
$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 (is_array($graph_data))
foreach($graphfiles as $key => $val)
{
$px->SetData($graph_data);
$px->SetMaxValue($px->GetCeilMaxValue()<0?0:$px->GetCeilMaxValue());
$px->SetMinValue($px->GetFloorMinValue()>0?0:$px->GetFloorMinValue());
$px->SetWidth($WIDTH);
$px->SetHeight($HEIGHT);
$px->SetHorizTickIncrement(1);
$px->SetPrecisionY(0);
$px->SetShading(3);
//print 'x '.$key.' '.$graphfiles[$key]['file'];
$px->draw($dir."/".$graphfiles[$key]['file']);
}
else
{
dol_print_error($db,'Error for calculating graph on key='.$key.' - '.$product->error);
if (! $graphfiles[$key]['file']) continue;
$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 (is_array($graph_data))
{
$px->SetData($graph_data);
$px->SetMaxValue($px->GetCeilMaxValue()<0?0:$px->GetCeilMaxValue());
$px->SetMinValue($px->GetFloorMinValue()>0?0:$px->GetFloorMinValue());
$px->SetWidth($WIDTH);
$px->SetHeight($HEIGHT);
$px->SetHorizTickIncrement(1);
$px->SetPrecisionY(0);
$px->SetShading(3);
//print 'x '.$key.' '.$graphfiles[$key]['file'];
$px->draw($dir."/".$graphfiles[$key]['file']);
}
else
{
dol_print_error($db,'Error for calculating graph on key='.$key.' - '.$product->error);
}
}
}
$mesg = $langs->trans("ChartGenerated");
}
$mesg = $langs->trans("ChartGenerated");
// Affichage graphs
// Show graphs
$i=0;
foreach($graphfiles as $key => $val)
{
@ -266,5 +271,5 @@ else
$db->close();
llxFooter('$Date$ - $Revision$');
llxFooter('$Date: 2011/07/04 10:04:18 $ - $Revision: 1.109 $');
?>