Meilleure gestion d'erreur si smarty mal configur

This commit is contained in:
Laurent Destailleur 2007-10-07 14:49:36 +00:00
parent 0f49ae8e44
commit 9586bccf27
7 changed files with 262 additions and 244 deletions

View File

@ -132,6 +132,11 @@ $character_set_client="ISO-8859-1";
# Parameters not used yet
# dolibarr_smarty_libs_dir
# Examples:
# $dolibarr_smarty_libs_dir="/var/www/dolibarr/external-libs/smarty/libs/";
# $dolibarr_smarty_compile="/var/www/dolibarr/documents/temp/smarty_templates";
# $dolibarr_smarty_cache="/var/www/dolibarr/documents/temp/smarty_cache";
$dolibarr_smarty_libs_dir="";
$dolibarr_smarty_compile="";
$dolibarr_smarty_cache="";

View File

@ -183,8 +183,9 @@ if ($socid > 0)
// Courriers
// Les courriers sont des documents speciaux generes par des scripts
// situes dans scripts/courrier.
// Voir Rodo
if ($conf->global->SOCIETE_NOLIST_COURRIER)
if ($conf->global->MAIN_MODULE_EDITEUR)
{
$filearray=array();
$errorlevel=error_reporting();

View File

@ -492,6 +492,7 @@ if ($user->admin)
$user->rights->user->self->password=1;
}
/**
* Overwrite configs global par configs perso
* ------------------------------------------
@ -534,22 +535,6 @@ if (isset($user->conf->MAIN_DISABLE_JAVASCRIPT) && $user->conf->MAIN_DISABLE_JAV
$conf->use_javascript=! $user->conf->MAIN_DISABLE_JAVASCRIPT;
}
// SMARTY
// Definit dans le fichier de conf
// $dolibarr_smarty_libs_dir="/home/www/dolitar/external-libs/smarty/libs/";
// $dolibarr_smarty_compile="/home/www/dolitar/smarty_templates";
// $dolibarr_smarty_cache="/home/www/dolitar/smarty_cache";
$smarty_libs = $dolibarr_smarty_libs_dir. "Smarty.class.php";
if (file_exists ($smarty_libs))
{
require($smarty_libs);
$smarty = new Smarty();
$smarty->compile_dir = $dolibarr_smarty_compile;
$smarty->cache_dir = $dolibarr_smarty_cache;
//$smarty->config_dir = '/web/www.domain.com/smarty/configs';
}
// Defini gestionnaire de menu a utiliser
if (! $user->societe_id) // Si utilisateur interne
{
@ -564,6 +549,33 @@ else // Si utilisateur externe
$conf->left_menu=$conf->global->MAIN_MENUFRONT_BARRELEFT;
}
if ($conf->left_menu != 'default.php') $conf->global->PRODUCT_CANVAS_ABILITY=0;
// Si besoin de smarty
if ($conf->global->PRODUCT_CANVAS_ABILITY)
{
// SMARTY
// Definit dans le fichier de conf
// $dolibarr_smarty_libs_dir="/home/www/dolibarr/external-libs/smarty/libs/";
// $dolibarr_smarty_compile="/home/www/dolibarr/documents/temp/smarty_templates";
// $dolibarr_smarty_cache="/home/www/dolibarr/documents/temp/smarty_cache";
$smarty_libs = $dolibarr_smarty_libs_dir. "Smarty.class.php";
if (file_exists ($smarty_libs))
{
require_once($smarty_libs);
$smarty = new Smarty();
$smarty->compile_dir = $dolibarr_smarty_compile;
$smarty->cache_dir = $dolibarr_smarty_cache;
//$smarty->config_dir = '/web/www.domain.com/smarty/configs';
}
else
{
dolibarr_print_error('',"Library Smarty ".$smarty_libs." not found. Check parameter dolibarr_smarty_libs_dir in conf file.");
}
}
// Si le login n'a pu etre recupere, on est identifie avec un compte qui n'existe pas.
// Tentative de hacking ?
if (! $user->login) accessforbidden();

View File

@ -175,6 +175,7 @@ if (! defined('NOREQUIREUSER'))
/*
* Chargement objet $conf
* After this, all parameters conf->global->CONSTANTS are loaded
*/
if (! defined('NOREQUIREDB'))
{

View File

@ -382,7 +382,6 @@ class ProductLivre extends Product
*/
function assign_smarty_values(&$smarty, $action='')
{
if ($action =='edit' or $action == 'create')
{
$this->GetAvailableFormat();

View File

@ -407,168 +407,169 @@ $html = new Form($db);
*/
if ($_GET["action"] == 'create' && $user->rights->produit->creer)
{
if ( !isset($product) )
{
if ($_GET["canvas"] <> '' && file_exists('canvas/product.'.$_GET["canvas"].'.class.php') )
if (! isset($product))
{
$class = 'Product'.ucfirst($_GET["canvas"]);
include_once('canvas/product.'.$_GET["canvas"].'.class.php');
$product = new $class($db,0,$user);
$filecanvas=DOL_DOCUMENT_ROOT.'/product/canvas/product.'.$_GET["canvas"].'.class.php';
if ($_GET["canvas"] && file_exists($filecanvas) )
{
$class = 'Product'.ucfirst($_GET["canvas"]);
include_once($filecanvas);
$product = new $class($db,0,$user);
}
else
{
$product = new Product($db);
}
}
else
{
$product = new Product($db);
}
}
$product->assign_smarty_values($smarty, 'create');
$product->assign_smarty_values($smarty, 'create');
if ($_error == 1)
{
$product = $e_product;
}
llxHeader("","",$langs->trans("CardProduct".$product->type));
if ($mesg) print "$mesg\n";
if ($_GET["canvas"] == '')
{
print '<form action="fiche.php" method="post">';
print '<input type="hidden" name="action" value="add">';
print '<input type="hidden" name="type" value="'.$_GET["type"].'">'."\n";
if ($_GET["type"]==1) $title=$langs->trans("NewService");
else $title=$langs->trans("NewProduct");
print_fiche_titre($title);
print '<table class="border" width="100%">';
print '<tr>';
print '<td width="20%">'.$langs->trans("Ref").'</td><td><input name="ref" size="40" maxlength="32" value="'.$product->ref.'">';
if ($_error == 1)
if ($_error == 1)
{
print $langs->trans("RefAlreadyExists");
$product = $e_product;
}
print '</td></tr>';
print '<tr><td>'.$langs->trans("Label").'</td><td><input name="libelle" size="40" value="'.$product->libelle.'"></td></tr>';
if($conf->global->PRODUIT_MULTIPRICES == 1)
{
print '<tr><td>'.$langs->trans("SellingPrice").' 1</td>';
print '<td><input name="price" size="10" value="'.$product->price.'">';
print $html->select_PriceBaseType($product->price_base_type, "price_base_type");
print '</td></tr>';
for($i=2;$i<=$conf->global->PRODUIT_MULTIPRICES_LIMIT;$i++)
{
print '<tr><td>'.$langs->trans("SellingPrice").' '.$i.'</td>';
print '<td><input name="price_'.$i.'" size="10" value="'.$product->multiprices["$i"].'">';
print $html->select_PriceBaseType($product->multiprices_base_type["$i"], "multiprices_base_type_".$i);
print '</td></tr>';
}
}
// PRIX
else
{
print '<tr><td>'.$langs->trans("SellingPrice").'</td>';
print '<td><input name="price" size="10" value="'.$product->price.'">';
print $html->select_PriceBaseType($product->price_base_type, "price_base_type");
print '</td></tr>';
}
print '<tr><td>'.$langs->trans("VATRate").'</td><td>';
print $html->select_tva("tva_tx",$conf->defaulttx,$mysoc,'');
print '</td></tr>';
print '<tr><td>'.$langs->trans("Status").'</td><td>';
print '<select class="flat" name="statut">';
print '<option value="1">'.$langs->trans("OnSell").'</option>';
print '<option value="0" selected="true">'.$langs->trans("NotOnSell").'</option>';
print '</select>';
print '</td></tr>';
if ($_GET["type"] != 1 && $conf->stock->enabled)
llxHeader("","",$langs->trans("CardProduct".$product->type));
if ($mesg) print "$mesg\n";
if (! $_GET["canvas"])
{
print '<tr><td>Seuil stock</td><td>';
print '<input name="seuil_stock_alerte" size="4" value="0">';
print '</td></tr>';
print '<form action="fiche.php" method="post">';
print '<input type="hidden" name="action" value="add">';
print '<input type="hidden" name="type" value="'.$_GET["type"].'">'."\n";
if ($_GET["type"]==1) $title=$langs->trans("NewService");
else $title=$langs->trans("NewProduct");
print_fiche_titre($title);
print '<table class="border" width="100%">';
print '<tr>';
print '<td width="20%">'.$langs->trans("Ref").'</td><td><input name="ref" size="40" maxlength="32" value="'.$product->ref.'">';
if ($_error == 1)
{
print $langs->trans("RefAlreadyExists");
}
print '</td></tr>';
print '<tr><td>'.$langs->trans("Label").'</td><td><input name="libelle" size="40" value="'.$product->libelle.'"></td></tr>';
if($conf->global->PRODUIT_MULTIPRICES == 1)
{
print '<tr><td>'.$langs->trans("SellingPrice").' 1</td>';
print '<td><input name="price" size="10" value="'.$product->price.'">';
print $html->select_PriceBaseType($product->price_base_type, "price_base_type");
print '</td></tr>';
for($i=2;$i<=$conf->global->PRODUIT_MULTIPRICES_LIMIT;$i++)
{
print '<tr><td>'.$langs->trans("SellingPrice").' '.$i.'</td>';
print '<td><input name="price_'.$i.'" size="10" value="'.$product->multiprices["$i"].'">';
print $html->select_PriceBaseType($product->multiprices_base_type["$i"], "multiprices_base_type_".$i);
print '</td></tr>';
}
}
// PRIX
else
{
print '<tr><td>'.$langs->trans("SellingPrice").'</td>';
print '<td><input name="price" size="10" value="'.$product->price.'">';
print $html->select_PriceBaseType($product->price_base_type, "price_base_type");
print '</td></tr>';
}
print '<tr><td>'.$langs->trans("VATRate").'</td><td>';
print $html->select_tva("tva_tx",$conf->defaulttx,$mysoc,'');
print '</td></tr>';
print '<tr><td>'.$langs->trans("Status").'</td><td>';
print '<select class="flat" name="statut">';
print '<option value="1">'.$langs->trans("OnSell").'</option>';
print '<option value="0" selected="true">'.$langs->trans("NotOnSell").'</option>';
print '</select>';
print '</td></tr>';
if ($_GET["type"] != 1 && $conf->stock->enabled)
{
print '<tr><td>Seuil stock</td><td>';
print '<input name="seuil_stock_alerte" size="4" value="0">';
print '</td></tr>';
}
else
{
print '<input name="seuil_stock_alerte" type="hidden" value="0">';
}
// Description (utilisé dans facture, propale...)
print '<tr><td valign="top">'.$langs->trans("Description").'</td><td>';
if ($conf->fckeditor->enabled && $conf->global->FCKEDITOR_ENABLE_PRODUCTDESC)
{
require_once(DOL_DOCUMENT_ROOT."/lib/doleditor.class.php");
$doleditor=new DolEditor('desc','',160,'dolibarr_notes','',false);
$doleditor->Create();
}
else
{
print '<textarea name="desc" rows="4" cols="90">';
print '</textarea>';
}
print "</td></tr>";
if ($_GET["type"] == 1)
{
print '<tr><td>'.$langs->trans("Duration").'</td><td><input name="duration_value" size="6" maxlength="5" value="'.$product->duree.'"> &nbsp;';
print '<input name="duration_unit" type="radio" value="h">'.$langs->trans("Hour").'&nbsp;';
print '<input name="duration_unit" type="radio" value="d">'.$langs->trans("Day").'&nbsp;';
print '<input name="duration_unit" type="radio" value="w">'.$langs->trans("Week").'&nbsp;';
print '<input name="duration_unit" type="radio" value="m">'.$langs->trans("Month").'&nbsp;';
print '<input name="duration_unit" type="radio" value="y">'.$langs->trans("Year").'&nbsp;';
print '</td></tr>';
}
else
{
// Le poids et le volume ne concerne que les produits et pas les services
print '<tr><td>'.$langs->trans("Weight").'</td><td>';
print '<input name="weight" size="4" value="">';
print $html->select_measuring_units("weight_units","weight");
print '</td></tr>';
print '<tr><td>'.$langs->trans("volume").'</td><td>';
print '<input name="volume" size="4" value="">';
print $html->select_measuring_units("volume_units","volume");
print '</td></tr>';
}
// Note (invisible sur facture, propales...)
print '<tr><td valign="top">'.$langs->trans("NoteNotVisibleOnBill").'</td><td>';
if ($conf->fckeditor->enabled && $conf->global->FCKEDITOR_ENABLE_PRODUCTDESC)
{
require_once(DOL_DOCUMENT_ROOT."/lib/doleditor.class.php");
$doleditor=new DolEditor('note','',200,'dolibarr_notes','',false);
$doleditor->Create();
}
else
{
print '<textarea name="note" rows="8" cols="70">';
print '</textarea>';
}
print "</td></tr>";
print '<tr><td colspan="3" align="center"><input type="submit" class="button" value="'.$langs->trans("Create").'"></td></tr>';
print '</table>';
print '</form>';
}
else
else
{
print '<input name="seuil_stock_alerte" type="hidden" value="0">';
//RODO
// On assigne les valeurs meme en creation car elles sont definies si
// on revient en erreur
//
$smarty->template_dir = DOL_DOCUMENT_ROOT.'/product/canvas/'.$_GET["canvas"].'/';
$null = $html->load_tva("tva_tx",$conf->defaulttx,$mysoc,'');
$smarty->assign('tva_taux_value', $html->tva_taux_value);
$smarty->assign('tva_taux_libelle', $html->tva_taux_libelle);
$smarty->display($_GET["canvas"].'-create.tpl');
}
// Description (utilisé dans facture, propale...)
print '<tr><td valign="top">'.$langs->trans("Description").'</td><td>';
if ($conf->fckeditor->enabled && $conf->global->FCKEDITOR_ENABLE_PRODUCTDESC)
{
require_once(DOL_DOCUMENT_ROOT."/lib/doleditor.class.php");
$doleditor=new DolEditor('desc','',160,'dolibarr_notes','',false);
$doleditor->Create();
}
else
{
print '<textarea name="desc" rows="4" cols="90">';
print '</textarea>';
}
print "</td></tr>";
if ($_GET["type"] == 1)
{
print '<tr><td>'.$langs->trans("Duration").'</td><td><input name="duration_value" size="6" maxlength="5" value="'.$product->duree.'"> &nbsp;';
print '<input name="duration_unit" type="radio" value="h">'.$langs->trans("Hour").'&nbsp;';
print '<input name="duration_unit" type="radio" value="d">'.$langs->trans("Day").'&nbsp;';
print '<input name="duration_unit" type="radio" value="w">'.$langs->trans("Week").'&nbsp;';
print '<input name="duration_unit" type="radio" value="m">'.$langs->trans("Month").'&nbsp;';
print '<input name="duration_unit" type="radio" value="y">'.$langs->trans("Year").'&nbsp;';
print '</td></tr>';
}
else
{
// Le poids et le volume ne concerne que les produits et pas les services
print '<tr><td>'.$langs->trans("Weight").'</td><td>';
print '<input name="weight" size="4" value="">';
print $html->select_measuring_units("weight_units","weight");
print '</td></tr>';
print '<tr><td>'.$langs->trans("volume").'</td><td>';
print '<input name="volume" size="4" value="">';
print $html->select_measuring_units("volume_units","volume");
print '</td></tr>';
}
// Note (invisible sur facture, propales...)
print '<tr><td valign="top">'.$langs->trans("NoteNotVisibleOnBill").'</td><td>';
if ($conf->fckeditor->enabled && $conf->global->FCKEDITOR_ENABLE_PRODUCTDESC)
{
require_once(DOL_DOCUMENT_ROOT."/lib/doleditor.class.php");
$doleditor=new DolEditor('note','',200,'dolibarr_notes','',false);
$doleditor->Create();
}
else
{
print '<textarea name="note" rows="8" cols="70">';
print '</textarea>';
}
print "</td></tr>";
print '<tr><td colspan="3" align="center"><input type="submit" class="button" value="'.$langs->trans("Create").'"></td></tr>';
print '</table>';
print '</form>';
}
else
{
//RODO
// On assigne les valeurs meme en creation car elles sont definies si
// on revient en erreur
//
$smarty->template_dir = DOL_DOCUMENT_ROOT.'/product/canvas/'.$_GET["canvas"].'/';
$null = $html->load_tva("tva_tx",$conf->defaulttx,$mysoc,'');
$smarty->assign('tva_taux_value', $html->tva_taux_value);
$smarty->assign('tva_taux_libelle', $html->tva_taux_libelle);
$smarty->display($_GET["canvas"].'-create.tpl');
}
}
/**

View File

@ -38,89 +38,88 @@ $user->getrights('facture');
function llxHeader($head = "", $urlp = "", $title="")
{
global $user, $conf, $langs;
global $user, $conf, $langs;
$user->getrights("produit");
top_menu($head, $title);
$menu = new Menu();
if ($conf->produit->enabled)
{
$menu->add(DOL_URL_ROOT."/product/index.php?type=0", $langs->trans("Products"));
$menu->add_submenu(DOL_URL_ROOT."/product/liste.php?type=0", $langs->trans("List"));
if ($user->societe_id == 0 && $user->rights->produit->creer)
{
$menu->add_submenu(DOL_URL_ROOT."/product/fiche.php?action=create&amp;type=0", $langs->trans("NewProduct"));
}
}
// Produit specifique
$dir = DOL_DOCUMENT_ROOT . "/product/canvas/";
$user->getrights("produit");
if(is_dir($dir) && $conf->global->PRODUCT_CANVAS_ABILITY==='1' )
{
if ($handle = opendir($dir))
top_menu($head, $title);
$menu = new Menu();
if ($conf->produit->enabled)
{
while (($file = readdir($handle))!==false)
{
if (substr($file, strlen($file) -10) == '.class.php' && substr($file,0,8) == 'product.')
$menu->add(DOL_URL_ROOT."/product/index.php?type=0", $langs->trans("Products"));
$menu->add_submenu(DOL_URL_ROOT."/product/liste.php?type=0", $langs->trans("List"));
if ($user->societe_id == 0 && $user->rights->produit->creer)
{
$parts = explode('.',$file);
$classname = 'Product'.ucfirst($parts[1]);
require_once($dir.$file);
$module = new $classname();
if ($module->active === '1' && $module->menu_add === 1)
{
$module->PersonnalizeMenu($menu);
$langs->load("products_".$module->canvas);
for ($j = 0 ; $j < sizeof($module->menus) ; $j++)
{
$menu->add_submenu($module->menus[$j][0], $langs->trans($module->menus[$j][1]));
}
}
$menu->add_submenu(DOL_URL_ROOT."/product/fiche.php?action=create&amp;type=0", $langs->trans("NewProduct"));
}
}
closedir($handle);
}
}
$menu->add_submenu(DOL_URL_ROOT."/product/reassort.php?type=0", $langs->trans("Restock"));
if ($conf->service->enabled)
{
$menu->add(DOL_URL_ROOT."/product/index.php?type=1", $langs->trans("Services"));
$menu->add_submenu(DOL_URL_ROOT."/product/liste.php?type=1", $langs->trans("List"));
if ($user->societe_id == 0 && $user->rights->produit->creer)
// Produit specifique
$dir = DOL_DOCUMENT_ROOT . "/product/canvas/";
if(is_dir($dir) && $conf->global->PRODUCT_CANVAS_ABILITY)
{
$menu->add_submenu(DOL_URL_ROOT."/product/fiche.php?action=create&amp;type=1", $langs->trans("NewService"));
if ($handle = opendir($dir))
{
while (($file = readdir($handle))!==false)
{
if (substr($file, strlen($file) -10) == '.class.php' && substr($file,0,8) == 'product.')
{
$parts = explode('.',$file);
$classname = 'Product'.ucfirst($parts[1]);
require_once($dir.$file);
$module = new $classname();
if ($module->active === '1' && $module->menu_add === 1)
{
$module->PersonnalizeMenu($menu);
$langs->load("products_".$module->canvas);
for ($j = 0 ; $j < sizeof($module->menus) ; $j++)
{
$menu->add_submenu($module->menus[$j][0], $langs->trans($module->menus[$j][1]));
}
}
}
}
closedir($handle);
}
}
}
if ($conf->fournisseur->enabled) {
$langs->load("suppliers");
$menu->add(DOL_URL_ROOT."/fourn/index.php", $langs->trans("Suppliers"));
}
$menu->add(DOL_URL_ROOT."/product/stats/", $langs->trans("Statistics"));
if ($conf->propal->enabled)
{
$menu->add_submenu(DOL_URL_ROOT."/product/popuprop.php", $langs->trans("Popularity"));
}
if ($conf->stock->enabled)
{
$menu->add(DOL_URL_ROOT."/product/stock/", $langs->trans("Stock"));
}
if ($conf->categorie->enabled)
{
$menu->add(DOL_URL_ROOT."/categories/index.php?type=0", $langs->trans("Categories"));
}
left_menu($menu->liste);
$menu->add_submenu(DOL_URL_ROOT."/product/reassort.php?type=0", $langs->trans("Restock"));
if ($conf->service->enabled)
{
$menu->add(DOL_URL_ROOT."/product/index.php?type=1", $langs->trans("Services"));
$menu->add_submenu(DOL_URL_ROOT."/product/liste.php?type=1", $langs->trans("List"));
if ($user->societe_id == 0 && $user->rights->produit->creer)
{
$menu->add_submenu(DOL_URL_ROOT."/product/fiche.php?action=create&amp;type=1", $langs->trans("NewService"));
}
}
if ($conf->fournisseur->enabled) {
$langs->load("suppliers");
$menu->add(DOL_URL_ROOT."/fourn/index.php", $langs->trans("Suppliers"));
}
$menu->add(DOL_URL_ROOT."/product/stats/", $langs->trans("Statistics"));
if ($conf->propal->enabled)
{
$menu->add_submenu(DOL_URL_ROOT."/product/popuprop.php", $langs->trans("Popularity"));
}
if ($conf->stock->enabled)
{
$menu->add(DOL_URL_ROOT."/product/stock/", $langs->trans("Stock"));
}
if ($conf->categorie->enabled)
{
$menu->add(DOL_URL_ROOT."/categories/index.php?type=0", $langs->trans("Categories"));
}
left_menu($menu->liste);
}
?>