Fix: regression, canvas is broken and societe.class and contact.class are incompatible with callHook function

This commit is contained in:
Regis Houssin 2011-06-30 13:25:32 +00:00
parent 6385641a8e
commit 79880a1aea
3 changed files with 463 additions and 455 deletions

View File

@ -24,7 +24,7 @@
* \file htdocs/contact/fiche.php * \file htdocs/contact/fiche.php
* \ingroup societe * \ingroup societe
* \brief Card of a contact * \brief Card of a contact
* \version $Id: fiche.php,v 1.214 2011/06/29 22:29:51 eldy Exp $ * \version $Id: fiche.php,v 1.215 2011/06/30 13:25:32 hregis Exp $
*/ */
require("../main.inc.php"); require("../main.inc.php");
@ -45,11 +45,11 @@ $action = GETPOST('action');
$socid = GETPOST("socid"); $socid = GETPOST("socid");
$id = GETPOST("id"); $id = GETPOST("id");
$object = new Contact($db);
// Security check // Security check
if ($user->societe_id) $socid=$user->societe_id; if ($user->societe_id) $socid=$user->societe_id;
$object = new Contact($db);
// Get object canvas (By default, this is not defined, so standard usage of dolibarr) // Get object canvas (By default, this is not defined, so standard usage of dolibarr)
if (!empty($id)) $object->getCanvas($id); if (!empty($id)) $object->getCanvas($id);
$canvas = (!empty($object->canvas)?$object->canvas:GETPOST("canvas")); $canvas = (!empty($object->canvas)?$object->canvas:GETPOST("canvas"));
@ -68,36 +68,40 @@ else
$result = restrictedArea($user, 'contact', $id, 'socpeople'); // If we create a contact with no company (shared contacts), no check on write permission $result = restrictedArea($user, 'contact', $id, 'socpeople'); // If we create a contact with no company (shared contacts), no check on write permission
} }
// Instantiate hooks of thirdparty module
if (is_array($conf->hooks_modules) && !empty($conf->hooks_modules))
{
$object->callHooks('contactcard');
}
/* /*
* Actions * Actions
*/ */
// Hook of actions // If canvas actions are defined, because on url, or because contact was created with canvas feature on, we use the canvas feature.
if (! empty($object->hooks['contactcard'])) // If canvas actions are not defined, we use standard feature.
if (method_exists($objcanvas->control,'doActions'))
{ {
foreach($object->hooks['contactcard'] as $module) // -----------------------------------------
// When used with CANVAS
// -----------------------------------------
$objcanvas->doActions($id);
if (empty($objcanvas->error) && (empty($objcanvas->errors) || sizeof($objcanvas->errors) == 0))
{ {
$reshook+=$module->doActions($object); if ($action=='add') { $objcanvas->action='create'; $action='create'; }
if (! empty($module->error) || (! empty($module->errors) && sizeof($module->errors) > 0)) if ($action=='update') { $objcanvas->action='view'; $action='view'; }
{
$error=$module->error; $errors[]=$module->errors;
if ($action=='add') $action='create';
if ($action=='update') $action='edit';
} }
else
{
$error=$objcanvas->error; $errors=$objcanvas->errors;
if ($action=='add') { $objcanvas->action='create'; $action='create'; }
if ($action=='update') { $objcanvas->action='edit'; $action='edit'; }
} }
} }
else
// Creation utilisateur depuis contact
if ($_POST["action"] == 'confirm_create_user' && $_POST["confirm"] == 'yes' && $user->rights->user->user->creer)
{ {
// -----------------------------------------
// When used in standard mode
// -----------------------------------------
// Creation utilisateur depuis contact
if ($_POST["action"] == 'confirm_create_user' && $_POST["confirm"] == 'yes' && $user->rights->user->user->creer)
{
// Recuperation contact actuel // Recuperation contact actuel
$result = $object->fetch($_GET["id"]); $result = $object->fetch($_GET["id"]);
@ -132,18 +136,18 @@ if ($_POST["action"] == 'confirm_create_user' && $_POST["confirm"] == 'yes' && $
{ {
$error=$object->error; $errors=$object->errors; $error=$object->error; $errors=$object->errors;
} }
} }
// Cancel // Cancel
if (GETPOST("cancel") && GETPOST('backtopage')) if (GETPOST("cancel") && GETPOST('backtopage'))
{ {
header("Location: ".GETPOST('backtopage')); header("Location: ".GETPOST('backtopage'));
exit; exit;
} }
// Add contact // Add contact
if (GETPOST("action") == 'add' && $user->rights->societe->contact->creer) if (GETPOST("action") == 'add' && $user->rights->societe->contact->creer)
{ {
$db->begin(); $db->begin();
if ($canvas) $object->canvas=$canvas; if ($canvas) $object->canvas=$canvas;
@ -199,10 +203,10 @@ if (GETPOST("action") == 'add' && $user->rights->societe->contact->creer)
{ {
$db->rollback(); $db->rollback();
} }
} }
if (GETPOST("action") == 'confirm_delete' && GETPOST("confirm") == 'yes' && $user->rights->societe->contact->supprimer) if (GETPOST("action") == 'confirm_delete' && GETPOST("confirm") == 'yes' && $user->rights->societe->contact->supprimer)
{ {
$result=$object->fetch($_GET["id"]); $result=$object->fetch($_GET["id"]);
$object->old_name = $_POST["old_name"]; $object->old_name = $_POST["old_name"];
@ -218,10 +222,10 @@ if (GETPOST("action") == 'confirm_delete' && GETPOST("confirm") == 'yes' && $use
{ {
$error=$object->error; $errors[]=$object->errors; $error=$object->error; $errors[]=$object->errors;
} }
} }
if ($_POST["action"] == 'update' && ! $_POST["cancel"] && $user->rights->societe->contact->creer) if ($_POST["action"] == 'update' && ! $_POST["cancel"] && $user->rights->societe->contact->creer)
{ {
if (empty($_POST["name"])) if (empty($_POST["name"]))
{ {
$error++; $errors=array($langs->trans("ErrorFieldRequired",$langs->transnoentities("Name").' / '.$langs->transnoentities("Label"))); $error++; $errors=array($langs->trans("ErrorFieldRequired",$langs->transnoentities("Name").' / '.$langs->transnoentities("Label")));
@ -270,6 +274,7 @@ if ($_POST["action"] == 'update' && ! $_POST["cancel"] && $user->rights->societe
$error=$object->error; $errors=$object->errors; $error=$object->error; $errors=$object->errors;
} }
} }
}
} }
@ -945,5 +950,5 @@ else
$db->close(); $db->close();
llxFooter('$Date: 2011/06/29 22:29:51 $ - $Revision: 1.214 $'); llxFooter('$Date: 2011/06/30 13:25:32 $ - $Revision: 1.215 $');
?> ?>

View File

@ -21,7 +21,7 @@
* \file htdocs/societe/canvas/actions_card_common.class.php * \file htdocs/societe/canvas/actions_card_common.class.php
* \ingroup thirdparty * \ingroup thirdparty
* \brief Fichier de la classe Thirdparty card controller (common) * \brief Fichier de la classe Thirdparty card controller (common)
* \version $Id$ * \version $Id: actions_card_common.class.php,v 1.22 2011/06/30 13:25:32 hregis Exp $
*/ */
/** /**
@ -259,7 +259,7 @@ class ActionsCardCommon
$oldsoccanvas = new Canvas($this->db); $oldsoccanvas = new Canvas($this->db);
$oldsoccanvas->getCanvas('thirdparty','card',$this->object->canvas); $oldsoccanvas->getCanvas('thirdparty','card',$this->object->canvas);
$result=$oldsoccanvas->fetch($socid); $result=$oldsoccanvas->control->object->fetch($socid);
// To avoid setting code if third party is not concerned. But if it had values, we keep them. // To avoid setting code if third party is not concerned. But if it had values, we keep them.
if (empty($this->object->client) && empty($oldsoccanvas->control->object->code_client)) $this->object->code_client=''; if (empty($this->object->client) && empty($oldsoccanvas->control->object->code_client)) $this->object->code_client='';

View File

@ -26,7 +26,7 @@
* \file htdocs/societe/soc.php * \file htdocs/societe/soc.php
* \ingroup societe * \ingroup societe
* \brief Third party card page * \brief Third party card page
* \version $Id: soc.php,v 1.112 2011/06/29 22:29:51 eldy Exp $ * \version $Id: soc.php,v 1.113 2011/06/30 13:25:33 hregis Exp $
*/ */
require("../main.inc.php"); require("../main.inc.php");
@ -50,17 +50,11 @@ if ($conf->notification->enabled) $langs->load("mails");
$action = GETPOST('action'); $action = GETPOST('action');
$confirm = GETPOST('confirm'); $confirm = GETPOST('confirm');
$error=0; $errors=array();
$extrafields = new ExtraFields($db);
$soc = new Societe($db); // TODO Replace this wit object
$object = new Societe($db);
// Security check // Security check
$socid = GETPOST("socid"); $socid = GETPOST("socid");
if ($user->societe_id) $socid=$user->societe_id; if ($user->societe_id) $socid=$user->societe_id;
$soc = new Societe($db);
// Get object canvas (By default, this is not defined, so standard usage of dolibarr) // Get object canvas (By default, this is not defined, so standard usage of dolibarr)
if (!empty($socid)) $soc->getCanvas($socid); if (!empty($socid)) $soc->getCanvas($socid);
$canvas = (!empty($soc->canvas)?$soc->canvas:GETPOST("canvas")); $canvas = (!empty($soc->canvas)?$soc->canvas:GETPOST("canvas"));
@ -79,50 +73,58 @@ else
$result = restrictedArea($user, 'societe', $socid); $result = restrictedArea($user, 'societe', $socid);
} }
// Instantiate hooks of thirdparty module $error=0; $errors=array();
if (is_array($conf->hooks_modules) && !empty($conf->hooks_modules))
{
$object->callHooks('thirdpartycard');
}
$extrafields = new ExtraFields($db);
/* /*
* Actions * Actions
*/ */
// Hook of actions // If canvas actions are defined, because on url, or because contact was created with canvas feature on, we use the canvas feature.
if (! empty($object->hooks['thirdpartycard'])) // If canvas actions are not defined, we use standard feature.
if (method_exists($objcanvas->control,'doActions'))
{ {
foreach($object->hooks['thirdpartycard'] as $module) // -----------------------------------------
// When used with CANVAS
// -----------------------------------------
$objcanvas->doActions($socid);
if (empty($objcanvas->error) && (empty($objcanvas->errors) || sizeof($objcanvas->errors) == 0))
{ {
$reshook+=$module->doActions($object); if ($action=='add') { $objcanvas->action='create'; $action='create'; }
if (! empty($module->error) || (! empty($module->errors) && sizeof($module->errors) > 0)) if ($action=='update') { $objcanvas->action='view'; $action='view'; }
{
$error=$module->error; $errors[]=$module->errors;
if ($action=='add') $action='create';
if ($action=='update') $action='edit';
} }
else
{
$error=$objcanvas->error; $errors=$objcanvas->errors;
if ($action=='add') { $objcanvas->action='create'; $action='create'; }
if ($action=='update') { $objcanvas->action='edit'; $action='edit'; }
} }
} }
else
if ($_POST["getcustomercode"])
{ {
// -----------------------------------------
// When used in standard mode
// -----------------------------------------
if ($_POST["getcustomercode"])
{
// We defined value code_client // We defined value code_client
$_POST["code_client"]="Acompleter"; $_POST["code_client"]="Acompleter";
} }
if ($_POST["getsuppliercode"]) if ($_POST["getsuppliercode"])
{ {
// We defined value code_fournisseur // We defined value code_fournisseur
$_POST["code_fournisseur"]="Acompleter"; $_POST["code_fournisseur"]="Acompleter";
} }
// Add new third party // Add new third party
if ((! $_POST["getcustomercode"] && ! $_POST["getsuppliercode"]) if ((! $_POST["getcustomercode"] && ! $_POST["getsuppliercode"])
&& ($action == 'add' || $action == 'update') && $user->rights->societe->creer) && ($action == 'add' || $action == 'update') && $user->rights->societe->creer)
{ {
require_once(DOL_DOCUMENT_ROOT."/lib/functions2.lib.php"); require_once(DOL_DOCUMENT_ROOT."/lib/functions2.lib.php");
if ($action == 'update') if ($action == 'update')
@ -401,11 +403,11 @@ if ((! $_POST["getcustomercode"] && ! $_POST["getsuppliercode"])
} }
} }
} }
} }
// Delete third party // Delete third party
if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->societe->supprimer) if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->societe->supprimer)
{ {
$soc->fetch($socid); $soc->fetch($socid);
$result = $soc->delete($socid); $result = $soc->delete($socid);
@ -420,14 +422,14 @@ if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->societe->
$error=$langs->trans($soc->error); $errors = $soc->errors; $error=$langs->trans($soc->error); $errors = $soc->errors;
$action=''; $action='';
} }
} }
/* /*
* Generate document * Generate document
*/ */
if ($action == 'builddoc') // En get ou en post if ($action == 'builddoc') // En get ou en post
{ {
if (is_numeric(GETPOST('model'))) if (is_numeric(GETPOST('model')))
{ {
$error=$langs->trans("ErrorFieldRequired",$langs->transnoentities("Model")); $error=$langs->trans("ErrorFieldRequired",$langs->transnoentities("Model"));
@ -462,6 +464,7 @@ if ($action == 'builddoc') // En get ou en post
exit; exit;
} }
} }
}
} }
@ -1943,5 +1946,5 @@ else
$db->close(); $db->close();
llxFooter('$Date: 2011/06/29 22:29:51 $ - $Revision: 1.112 $'); llxFooter('$Date: 2011/06/30 13:25:33 $ - $Revision: 1.113 $');
?> ?>