From af6f075b5c25061b68355219ad0fcb6fa7337c6d Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 9 Apr 2013 23:56:52 +0200 Subject: [PATCH] Qual: Better error management. Qual: Uniformize code for canvas --- htdocs/adherents/fiche.php | 17 +++++++++-------- htdocs/contact/fiche.php | 19 ++++++++++--------- .../install/mysql/migration/3.3.0-3.4.0.sql | 2 ++ htdocs/product/fiche.php | 16 +++++++++++----- htdocs/societe/soc.php | 4 ++-- 5 files changed, 34 insertions(+), 24 deletions(-) diff --git a/htdocs/adherents/fiche.php b/htdocs/adherents/fiche.php index dda805ec113..65c79d66068 100644 --- a/htdocs/adherents/fiche.php +++ b/htdocs/adherents/fiche.php @@ -49,8 +49,8 @@ $backtopage=GETPOST('backtopage','alpha'); $confirm=GETPOST('confirm','alpha'); $rowid=GETPOST('rowid','int'); $typeid=GETPOST('typeid','int'); -$userid=GETPOST('userid','int'); -$socid=GETPOST('socid','int'); +$userid=GETPOST('userid','int'); +$socid=GETPOST('socid','int'); if (! empty($conf->mailmanspip->enabled)) { @@ -68,7 +68,7 @@ $extrafields = new ExtraFields($db); $extralabels=$extrafields->fetch_name_optionals_label('member'); // Get object canvas (By default, this is not defined, so standard usage of dolibarr) -$object->getCanvas($socid); +$object->getCanvas($rowid); $canvas = $object->canvas?$object->canvas:GETPOST("canvas"); $objcanvas=''; if (! empty($canvas)) @@ -117,7 +117,7 @@ $hookmanager->initHooks(array('membercard')); * Actions */ -$parameters=array('socid'=>$socid, 'objcanvas'=>$objcanvas); +$parameters=array('rowid'=>$rowid, 'objcanvas'=>$objcanvas); $reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks if ($action == 'setuserid' && ($user->rights->user->self->creer || $user->rights->user->user->creer)) @@ -694,13 +694,14 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) // ----------------------------------------- // When used with CANVAS // ----------------------------------------- - if (empty($object->error) && $socid) + if (empty($object->error) && $rowid) { $object = new Adherent($db); - $object->fetch($socid); + $result=$object->fetch($rowid); + if ($result <= 0) dol_print_error('',$object->error); } - $objcanvas->assign_values($action, $socid); // Set value for templates - $objcanvas->display_canvas($action); // Show template + $objcanvas->assign_values($action, $object->id, $object->ref); // Set value for templates + $objcanvas->display_canvas($action); // Show template } else { diff --git a/htdocs/contact/fiche.php b/htdocs/contact/fiche.php index a0ca630a423..9711654fa03 100644 --- a/htdocs/contact/fiche.php +++ b/htdocs/contact/fiche.php @@ -162,7 +162,7 @@ if (empty($reshook)) $object->birthday_alert = $_POST["birthday_alert"]; // Fill array 'array_options' with data from add form - $ret = $extrafields->setOptionalsFromPost($extralabels,$object); + $ret = $extrafields->setOptionalsFromPost($extralabels,$object); if (! $_POST["lastname"]) { @@ -254,7 +254,7 @@ if (empty($reshook)) $object->note_private = GETPOST("note_private"); // Fill array 'array_options' with data from add form - $ret = $extrafields->setOptionalsFromPost($extralabels,$object); + $ret = $extrafields->setOptionalsFromPost($extralabels,$object); $result = $object->update($_POST["contactid"], $user); @@ -300,11 +300,12 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) // ----------------------------------------- if (empty($object->error) && $id) { - $object = new Contact($db); - $object->fetch($id); + $object = new Contact($db); + $result=$object->fetch($id); + if ($result <= 0) dol_print_error('',$object->error); } - $objcanvas->assign_values($action, $id); // Set value for templates - $objcanvas->display_canvas($action); // Show template + $objcanvas->assign_values($action, $object->id, $object->ref); // Set value for templates + $objcanvas->display_canvas($action); // Show template } else { @@ -510,7 +511,7 @@ else print $doleditor->Create(1); //print ''; print ''; - + // Note Private print ''.$langs->trans("NotePrivate").''; print ''; @@ -728,7 +729,7 @@ else // print isset($_POST["note"])?$_POST["note"]:$object->note; // print ''; print ''; - + // Note Private print ''.$langs->trans("NotePrivate").''; $doleditor = new DolEditor('note_private', $object->note_private, '', 80, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, 70); @@ -941,7 +942,7 @@ else print ''.$langs->trans("NotePublic").''; print nl2br($object->note_public); print ''; - + // Note Private print ''.$langs->trans("NotePrivate").''; print nl2br($object->note_private); diff --git a/htdocs/install/mysql/migration/3.3.0-3.4.0.sql b/htdocs/install/mysql/migration/3.3.0-3.4.0.sql index b2be5f7fa14..45d28802558 100755 --- a/htdocs/install/mysql/migration/3.3.0-3.4.0.sql +++ b/htdocs/install/mysql/migration/3.3.0-3.4.0.sql @@ -244,6 +244,8 @@ ALTER TABLE llx_actioncomm ADD COLUMN transparency integer after fk_user_action; INSERT INTO llx_c_action_trigger (rowid,code,label,description,elementtype,rang) VALUES (29,'FICHINTER_SENTBYMAIL','Intervention sent by mail','Executed when a intervention is sent by mail','ficheinter',29); +ALTER TABLE llx_adherent ADD COLUMN canvas varchar(32) after fk_user_valid; + ALTER TABLE llx_expedition CHANGE COLUMN note note_private text; ALTER TABLE llx_expedition ADD COLUMN note_public text after note_private; ALTER TABLE llx_livraison CHANGE COLUMN note note_private text; diff --git a/htdocs/product/fiche.php b/htdocs/product/fiche.php index 60c3785751f..e8775f44621 100644 --- a/htdocs/product/fiche.php +++ b/htdocs/product/fiche.php @@ -638,11 +638,17 @@ $formproduct = new FormProduct($db); if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) { - // ----------------------------------------- - // When used with CANVAS (more simple) - // ----------------------------------------- - $objcanvas->assign_values($action, $object->id, $object->ref); // Set value for templates - $objcanvas->display_canvas($action); // Show template + // ----------------------------------------- + // When used with CANVAS + // ----------------------------------------- + if (empty($object->error) && $id) + { + $object = new Product($db); + $result=$object->fetch($id); + if ($result <= 0) dol_print_error('',$object->error); + } + $objcanvas->assign_values($action, $object->id, $object->ref); // Set value for templates + $objcanvas->display_canvas($action); // Show template } else { diff --git a/htdocs/societe/soc.php b/htdocs/societe/soc.php index 7274c51cf9f..ceef3ec324e 100644 --- a/htdocs/societe/soc.php +++ b/htdocs/societe/soc.php @@ -531,8 +531,8 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) $result=$object->fetch($socid); if ($result <= 0) dol_print_error('',$object->error); } - $objcanvas->assign_values($action, $socid); // Set value for templates - $objcanvas->display_canvas($action); // Show template + $objcanvas->assign_values($action, $object->id, $object->ref); // Set value for templates + $objcanvas->display_canvas($action); // Show template } else {