Fix: bad error management
This commit is contained in:
parent
0df44a7787
commit
dc3fd00557
@ -39,6 +39,10 @@ class ActionsContactCardCommon
|
||||
var $object;
|
||||
//! Canvas
|
||||
var $canvas;
|
||||
//! Error string
|
||||
var $error;
|
||||
//! Error array
|
||||
var $errors=array();
|
||||
|
||||
/**
|
||||
* Constructeur de la classe
|
||||
@ -269,8 +273,6 @@ class ActionsContactCardCommon
|
||||
{
|
||||
global $conf, $user, $langs;
|
||||
|
||||
$errors='';
|
||||
|
||||
// Creation utilisateur depuis contact
|
||||
if (GETPOST("action") == 'confirm_create_user' && GETPOST("confirm") == 'yes' && $user->rights->user->user->creer)
|
||||
{
|
||||
@ -285,15 +287,13 @@ class ActionsContactCardCommon
|
||||
|
||||
if ($result < 0)
|
||||
{
|
||||
$errors=$nuser->error;
|
||||
$this->errors=$nuser->errors;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$errors=$this->object->error;
|
||||
$this->errors=$this->object->errors;
|
||||
}
|
||||
|
||||
return $errors;
|
||||
}
|
||||
|
||||
// Creation contact
|
||||
@ -303,7 +303,7 @@ class ActionsContactCardCommon
|
||||
|
||||
if (! $_POST["name"])
|
||||
{
|
||||
array_push($errors,$langs->trans("ErrorFieldRequired",$langs->transnoentities("Lastname").' / '.$langs->transnoentities("Label")));
|
||||
array_push($this->errors,$langs->trans("ErrorFieldRequired",$langs->transnoentities("Lastname").' / '.$langs->transnoentities("Label")));
|
||||
$_GET["action"] = $_POST["action"] = 'create';
|
||||
}
|
||||
|
||||
@ -317,12 +317,10 @@ class ActionsContactCardCommon
|
||||
}
|
||||
else
|
||||
{
|
||||
$errors=array($this->object->error);
|
||||
$this->errors=$this->object->errors;
|
||||
$_GET["action"] = $_POST["action"] = 'create';
|
||||
}
|
||||
}
|
||||
|
||||
return $errors;
|
||||
}
|
||||
|
||||
if (GETPOST("action") == 'confirm_delete' && GETPOST("confirm") == 'yes' && $user->rights->societe->contact->supprimer)
|
||||
@ -340,22 +338,19 @@ class ActionsContactCardCommon
|
||||
}
|
||||
else
|
||||
{
|
||||
$errors=$this->object->error;
|
||||
$this->errors=$this->object->errors;
|
||||
}
|
||||
|
||||
return $errors;
|
||||
}
|
||||
|
||||
if ($_POST["action"] == 'update' && ! $_POST["cancel"] && $user->rights->societe->contact->creer)
|
||||
{
|
||||
if (empty($_POST["name"]))
|
||||
{
|
||||
$errors=array($langs->trans("ErrorFieldRequired",$langs->transnoentities("Name").' / '.$langs->transnoentities("Label")));
|
||||
$error++;
|
||||
$this->error=array($langs->trans("ErrorFieldRequired",$langs->transnoentities("Name").' / '.$langs->transnoentities("Label")));
|
||||
$_GET["action"] = $_POST["action"] = 'edit';
|
||||
}
|
||||
|
||||
if (empty($errors))
|
||||
if (empty($this->error))
|
||||
{
|
||||
$this->object->fetch($_POST["contactid"]);
|
||||
|
||||
@ -372,11 +367,9 @@ class ActionsContactCardCommon
|
||||
}
|
||||
else
|
||||
{
|
||||
$errors=$this->object->error;
|
||||
$this->errors=$this->object->errors;
|
||||
}
|
||||
}
|
||||
|
||||
return $errors;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -80,7 +80,7 @@ if (! empty($canvas))
|
||||
// -----------------------------------------
|
||||
|
||||
// Load data control
|
||||
$msg = $objcanvas->doActions($id);
|
||||
$objcanvas->doActions($id);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -261,63 +261,60 @@ if (! empty($canvas))
|
||||
}
|
||||
}
|
||||
|
||||
if ($user->rights->societe->contact->creer)
|
||||
if (GETPOST("action") == 'create')
|
||||
{
|
||||
if (GETPOST("action") == 'create')
|
||||
// Set action type
|
||||
$objcanvas->setAction(GETPOST("action"));
|
||||
|
||||
// Card header
|
||||
$title = $objcanvas->getTitle();
|
||||
print_fiche_titre($title);
|
||||
|
||||
// Assign _POST data
|
||||
$objcanvas->assign_post();
|
||||
|
||||
// Assign template values
|
||||
$objcanvas->assign_values();
|
||||
|
||||
// Show errors
|
||||
dol_htmloutput_errors($objcanvas->error,$objcanvas->errors);
|
||||
|
||||
// Display canvas
|
||||
$objcanvas->display_canvas();
|
||||
}
|
||||
else if (GETPOST("id") && GETPOST("action") == 'edit')
|
||||
{
|
||||
/*
|
||||
* Mode edition
|
||||
*/
|
||||
|
||||
// Set action type
|
||||
$objcanvas->setAction(GETPOST("action"));
|
||||
|
||||
// Fetch object
|
||||
$result=$objcanvas->fetch($id);
|
||||
if ($result > 0)
|
||||
{
|
||||
// Set action type
|
||||
$objcanvas->setAction(GETPOST("action"));
|
||||
|
||||
// Card header
|
||||
$head = contact_prepare_head($objcanvas->control->object);
|
||||
$title = $objcanvas->getTitle();
|
||||
print_fiche_titre($title);
|
||||
|
||||
// Assign _POST data
|
||||
$objcanvas->assign_post();
|
||||
|
||||
// Assign template values
|
||||
dol_fiche_head($head, 'general', $title, 0, 'contact');
|
||||
|
||||
if ($_POST["name"])
|
||||
{
|
||||
// Assign _POST data
|
||||
$objcanvas->assign_post();
|
||||
}
|
||||
|
||||
// Assign values
|
||||
$objcanvas->assign_values();
|
||||
|
||||
dol_htmloutput_errors($objcanvas->error,$objcanvas->errors);
|
||||
|
||||
// Display canvas
|
||||
$objcanvas->display_canvas();
|
||||
}
|
||||
else if (GETPOST("id") && GETPOST("action") == 'edit')
|
||||
else
|
||||
{
|
||||
/*
|
||||
* Mode edition
|
||||
*/
|
||||
|
||||
// Set action type
|
||||
$objcanvas->setAction(GETPOST("action"));
|
||||
|
||||
// Fetch object
|
||||
$result=$objcanvas->fetch($id);
|
||||
if ($result > 0)
|
||||
{
|
||||
// Card header
|
||||
$head = contact_prepare_head($objcanvas->control->object);
|
||||
$title = $objcanvas->getTitle();
|
||||
dol_fiche_head($head, 'general', $title, 0, 'contact');
|
||||
|
||||
if ($_POST["name"])
|
||||
{
|
||||
// Assign _POST data
|
||||
$objcanvas->assign_post();
|
||||
}
|
||||
|
||||
// Assign values
|
||||
$objcanvas->assign_values();
|
||||
|
||||
// Display canvas
|
||||
$objcanvas->display_canvas();
|
||||
}
|
||||
else
|
||||
{
|
||||
dol_htmloutput_errors($objcanvas->error,$objcanvas->errors);
|
||||
}
|
||||
|
||||
dol_htmloutput_errors($objcanvas->error,$objcanvas->errors);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -32,6 +32,8 @@
|
||||
class Canvas
|
||||
{
|
||||
var $db;
|
||||
var $error;
|
||||
var $errors;
|
||||
|
||||
var $card;
|
||||
var $canvas;
|
||||
@ -44,8 +46,7 @@ class Canvas
|
||||
var $template_dir; // Directory with all core and external templates files
|
||||
var $action;
|
||||
var $smarty;
|
||||
|
||||
var $error;
|
||||
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
@ -86,7 +87,12 @@ class Canvas
|
||||
*/
|
||||
function doActions($id)
|
||||
{
|
||||
return $this->control->doActions($id);
|
||||
$out = $this->control->doActions($id);
|
||||
|
||||
$this->errors = ($this->control->errors?$this->control->errors:$this->control->object->errors);
|
||||
$this->error = ($this->control->error?$this->control->error:$this->control->object->error);
|
||||
|
||||
return $out;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -39,6 +39,10 @@ class ActionsCardCommon
|
||||
var $object;
|
||||
//! Canvas
|
||||
var $canvas;
|
||||
//! Error string
|
||||
var $error;
|
||||
//! Error array
|
||||
var $errors=array();
|
||||
|
||||
/**
|
||||
* Constructeur de la classe
|
||||
@ -477,21 +481,21 @@ class ActionsCardCommon
|
||||
{
|
||||
$error = 1;
|
||||
$langs->load("errors");
|
||||
$this->object->error = $langs->trans("ErrorBadEMail",$this->object->email);
|
||||
$this->error = $langs->trans("ErrorBadEMail",$this->object->email);
|
||||
$_GET["action"] = $_POST["action"]=='add'?'create':'edit';
|
||||
}
|
||||
if (! empty($this->object->url) && ! isValidUrl($this->object->url))
|
||||
{
|
||||
$error = 1;
|
||||
$langs->load("errors");
|
||||
$this->object->error = $langs->trans("ErrorBadUrl",$this->object->url);
|
||||
$this->error = $langs->trans("ErrorBadUrl",$this->object->url);
|
||||
$_GET["action"] = $_POST["action"]=='add'?'create':'edit';
|
||||
}
|
||||
if ($this->object->fournisseur && ! $conf->fournisseur->enabled)
|
||||
{
|
||||
$error = 1;
|
||||
$langs->load("errors");
|
||||
$this->object->error = $langs->trans("ErrorSupplierModuleNotEnabled");
|
||||
$this->error = $langs->trans("ErrorSupplierModuleNotEnabled");
|
||||
$_GET["action"] = $_POST["action"]=='add'?'create':'edit';
|
||||
}
|
||||
}
|
||||
@ -530,7 +534,7 @@ class ActionsCardCommon
|
||||
}
|
||||
else
|
||||
{
|
||||
$mesg=$this->object->error;
|
||||
$this->errors=$this->object->errors;
|
||||
}
|
||||
|
||||
if ($result >= 0)
|
||||
@ -561,8 +565,7 @@ class ActionsCardCommon
|
||||
{
|
||||
$this->db->rollback();
|
||||
|
||||
$langs->load("errors");
|
||||
$mesg=$langs->trans($this->object->error);
|
||||
$this->errors=$this->object->errors;
|
||||
$_GET["action"]='create';
|
||||
}
|
||||
}
|
||||
@ -594,8 +597,7 @@ class ActionsCardCommon
|
||||
{
|
||||
$this->object->id = $socid;
|
||||
$reload = 0;
|
||||
|
||||
$mesg = $this->object->error;
|
||||
$this->errors = $this->object->errors;
|
||||
$_GET["action"]= "edit";
|
||||
}
|
||||
}
|
||||
@ -616,8 +618,7 @@ class ActionsCardCommon
|
||||
else
|
||||
{
|
||||
$reload = 0;
|
||||
$langs->load("errors");
|
||||
$mesg=$langs->trans($this->object->error);
|
||||
$this->errors=$this->object->errors;
|
||||
$_GET["action"]='';
|
||||
}
|
||||
}
|
||||
@ -629,7 +630,7 @@ class ActionsCardCommon
|
||||
{
|
||||
if (is_numeric($_REQUEST['model']))
|
||||
{
|
||||
$mesg=$langs->trans("ErrorFieldRequired",$langs->transnoentities("Model"));
|
||||
$this->error=$langs->trans("ErrorFieldRequired",$langs->transnoentities("Model"));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@ -409,6 +409,7 @@ if (! empty($canvas))
|
||||
// Assign template values
|
||||
$soccanvas->assign_values();
|
||||
|
||||
// Show errors
|
||||
dol_htmloutput_errors($soccanvas->error,$soccanvas->errors);
|
||||
|
||||
// Display canvas
|
||||
|
||||
Loading…
Reference in New Issue
Block a user