From 96ed2fe994b13f23cbf0451cb892aee484d19482 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Sat, 24 Sep 2011 15:57:52 +0000 Subject: [PATCH] Fix: broken canvas --- .../actions_contactcard_common.class.php | 172 ++++++++----- .../actions_contactcard_default.class.php | 51 ++-- htdocs/contact/fiche.php | 88 ++----- htdocs/core/class/canvas.class.php | 155 ++++------- htdocs/includes/modules/modBanque.class.php | 14 +- .../canvas/actions_card_common.class.php | 242 +++++++++--------- .../company/actions_card_company.class.php | 43 ++-- .../actions_card_individual.class.php | 41 +-- .../dao_thirdparty_individual.class.php | 4 +- htdocs/societe/class/societe.class.php | 82 +++--- htdocs/societe/soc.php | 147 ++++------- 11 files changed, 490 insertions(+), 549 deletions(-) diff --git a/htdocs/contact/canvas/actions_contactcard_common.class.php b/htdocs/contact/canvas/actions_contactcard_common.class.php index a2e0f7e33cf..9e8d17fa718 100644 --- a/htdocs/contact/canvas/actions_contactcard_common.class.php +++ b/htdocs/contact/canvas/actions_contactcard_common.class.php @@ -28,12 +28,11 @@ abstract class ActionsContactCardCommon { var $db; + var $dirmodule; var $targetmodule; var $canvas; var $card; - //! Numero d'erreur Plage 1280-1535 - var $errno = 0; //! Template container var $tpl = array(); //! Object container @@ -46,19 +45,66 @@ abstract class ActionsContactCardCommon /** * Constructor * - * @param DoliDB $DB Handler acces base de donnees - * @param string $targetmodule Name of directory of module where canvas is stored - * @param string $canvas Name of canvas - * @param streing $card Name of tab (sub-canvas) + * @param DoliDB $DB Handler acces base de donnees + * @param string $dirmodule Name of directory of module + * @param string $targetmodule Name of directory where canvas is stored + * @param string $canvas Name of canvas + * @param string $card Name of tab (sub-canvas) */ - function ActionsContactCardCommon($DB,$targetmodule,$canvas,$card) + function __construct($DB, $dirmodule, $targetmodule, $canvas, $card) { - $this->db = $DB; - $this->targetmodule = $targetmodule; - $this->canvas = $canvas; - $this->card = $card; + $this->db = $DB; + $this->dirmodule = $targetmodule; + $this->targetmodule = $targetmodule; + $this->canvas = $canvas; + $this->card = $card; } - + + /** + * Instantiation of DAO class + * + * @return void + */ + private function getInstanceDao() + { + if (! is_object($this->object)) + { + $modelclassfile = dol_buildpath('/'.$this->dirmodule.'/canvas/'.$this->canvas.'/dao_'.$this->targetmodule.'_'.$this->canvas.'.class.php'); + if (file_exists($modelclassfile)) + { + // Include dataservice class (model) + $ret = require_once($modelclassfile); + if ($ret) + { + // Instantiate dataservice class (model) + $modelclassname = 'Dao'.ucfirst($this->targetmodule).ucfirst($this->canvas); + $this->object = new $modelclassname($this->db); + } + } + } + } + + /** + * Get object + * + * @param int Object id + * @return object Object loaded + */ + function getObject($id) + { + $ret = $this->getInstanceDao(); + + if (is_object($this->object) && method_exists($this->object,'fetch')) + { + if (! empty($id)) $this->object->fetch($id); + } + else + { + $object = new Contact($this->db); + if (! empty($id)) $object->fetch($id); + $this->object = $object; + } + } /** * Load data control @@ -66,12 +112,12 @@ abstract class ActionsContactCardCommon * @param int $id Id of object * @return void */ - function doActions($id) + function doActions(&$action) { global $conf, $user, $langs; // Creation utilisateur depuis contact - if (GETPOST("action") == 'confirm_create_user' && GETPOST("confirm") == 'yes') + if ($action == 'confirm_create_user' && GETPOST("confirm") == 'yes') { // Recuperation contact actuel $result = $this->object->fetch($id); @@ -110,14 +156,14 @@ abstract class ActionsContactCardCommon } // Creation contact - if ($_POST["action"] == 'add') + if ($action == 'add') { $this->assign_post(); if (! $_POST["name"]) { array_push($this->errors,$langs->trans("ErrorFieldRequired",$langs->transnoentities("Lastname").' / '.$langs->transnoentities("Label"))); - $_GET["action"] = $_POST["action"] = 'create'; + $action = 'create'; } if ($_POST["name"]) @@ -131,12 +177,12 @@ abstract class ActionsContactCardCommon else { $this->errors=$this->object->errors; - $_GET["action"] = $_POST["action"] = 'create'; + $action = 'create'; } } } - if (GETPOST("action") == 'confirm_delete' && GETPOST("confirm") == 'yes') + if ($action == 'confirm_delete' && GETPOST("confirm") == 'yes') { $result=$this->object->fetch($id); @@ -146,7 +192,7 @@ abstract class ActionsContactCardCommon $result = $this->object->delete(); if ($result > 0) { - Header("Location: index.php"); + Header("Location: list.php"); exit; } else @@ -155,12 +201,18 @@ abstract class ActionsContactCardCommon } } - if ($_POST["action"] == 'update' && ! $_POST["cancel"]) + if ($action == 'update') { + if ($_POST["cancel"]) + { + Header("Location: ".$_SERVER["PHP_SELF"]."?id=".$this->object->id); + exit; + } + if (empty($_POST["name"])) { $this->error=array($langs->trans("ErrorFieldRequired",$langs->transnoentities("Name").' / '.$langs->transnoentities("Label"))); - $_GET["action"] = $_POST["action"] = 'edit'; + $action = 'edit'; } if (empty($this->error)) @@ -175,55 +227,36 @@ abstract class ActionsContactCardCommon if ($result > 0) { - $this->object->old_name=''; - $this->object->old_firstname=''; + Header("Location: ".$_SERVER["PHP_SELF"]."?id=".$this->object->id); + exit; } else { $this->errors=$this->object->errors; + $action = 'edit'; } } } } - - /** - * Return the title of card - * - * @param string $action Type of action - * @return string HTML output - */ - function getTitle($action) - { - global $langs; - - $out=''; - - if ($action == 'view' || $action == 'edit') $out.= $langs->trans("ContactsAddresses"); - if ($action == 'create') $out.= $langs->trans("AddContact"); - - return $out; - } - /** * Set content of ->tpl array, to use into template * * @param string $action Type of action * @return string HTML output */ - function assign_values($action='') + function assign_values(&$action) { global $conf, $langs, $user, $canvas; global $form, $formcompany, $objsoc; - if ($action == 'create' || $action == 'edit') $this->assign_post($action); + if ($action == 'add' || $action == 'update') $this->assign_post(); foreach($this->object as $key => $value) { $this->tpl[$key] = $value; } - $this->tpl['title']=$this->getTitle($action); $this->tpl['error']=$this->error; $this->tpl['errors']=$this->errors; @@ -289,7 +322,7 @@ abstract class ActionsContactCardCommon $this->tpl['select_visibility'] = $form->selectarray('priv',$selectarray,$this->object->priv,0); } - if ($action == 'view' || $action == 'edit') + if ($action == 'view' || $action == 'edit' || $action == 'delete') { // Emailing if ($conf->mailing->enabled) @@ -339,29 +372,8 @@ abstract class ActionsContactCardCommon else $this->tpl['dolibarr_user'] = $langs->trans("NoDolibarrAccess"); } - if ($action == 'view') + if ($action == 'view' || $action == 'delete') { - if ($_GET["action"] == 'create_user') - { - // Full firstname and name separated with a dot : firstname.name - include_once(DOL_DOCUMENT_ROOT.'/lib/functions2.lib.php'); - $login=dol_buildlogin($this->object->nom, $this->object->prenom); - - $generated_password=''; - if (! $ldap_sid) - { - $generated_password=getRandomPassword(''); - } - $password=$generated_password; - - // Create a form array - $formquestion=array( - array('label' => $langs->trans("LoginToCreate"), 'type' => 'text', 'name' => 'login', 'value' => $login), - array('label' => $langs->trans("Password"), 'type' => 'text', 'name' => 'password', 'value' => $password)); - - $this->tpl['action_create_user'] = $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$this->object->id,$langs->trans("CreateDolibarrLogin"),$langs->trans("ConfirmCreateContact"),"confirm_create_user",$formquestion,'no'); - } - $this->tpl['showrefnav'] = $form->showrefnav($this->object,'id'); if ($this->object->socid > 0) @@ -395,15 +407,35 @@ abstract class ActionsContactCardCommon $this->tpl['note'] = nl2br($this->object->note); } + + if ($action == 'create_user') + { + // Full firstname and name separated with a dot : firstname.name + include_once(DOL_DOCUMENT_ROOT.'/lib/functions2.lib.php'); + $login=dol_buildlogin($this->object->nom, $this->object->prenom); + + $generated_password=''; + if (! $ldap_sid) + { + $generated_password=getRandomPassword(''); + } + $password=$generated_password; + + // Create a form array + $formquestion=array( + array('label' => $langs->trans("LoginToCreate"), 'type' => 'text', 'name' => 'login', 'value' => $login), + array('label' => $langs->trans("Password"), 'type' => 'text', 'name' => 'password', 'value' => $password)); + + $this->tpl['action_create_user'] = $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$this->object->id,$langs->trans("CreateDolibarrLogin"),$langs->trans("ConfirmCreateContact"),"confirm_create_user",$formquestion,'no'); + } } /** * Assign POST values into object * - * @param string $action Action string * @return string HTML output */ - private function assign_post($action) + private function assign_post() { global $langs, $mysoc; diff --git a/htdocs/contact/canvas/default/actions_contactcard_default.class.php b/htdocs/contact/canvas/default/actions_contactcard_default.class.php index ae33c4e0d78..4230d8bbe38 100644 --- a/htdocs/contact/canvas/default/actions_contactcard_default.class.php +++ b/htdocs/contact/canvas/default/actions_contactcard_default.class.php @@ -30,26 +30,44 @@ include_once(DOL_DOCUMENT_ROOT.'/contact/canvas/actions_contactcard_common.class class ActionsContactCardDefault extends ActionsContactCardCommon { var $db; + var $dirmodule; var $targetmodule; var $canvas; var $card; /** - * Constructor + * Constructor * - * @param DoliDB $DB Handler acces base de donnees - * @param string $targetmodule Name of directory of module where canvas is stored - * @param string $canvas Name of canvas - * @param string $card Name of tab (sub-canvas) + * @param DoliDB $DB Handler acces base de donnees + * @param string $dirmodule Name of directory of module + * @param string $targetmodule Name of directory of module where canvas is stored + * @param string $canvas Name of canvas + * @param string $card Name of tab (sub-canvas) */ - function ActionsContactCardDefault($DB,$targetmodule,$canvas,$card) + function __construct($DB, $dirmodule, $targetmodule, $canvas, $card) { $this->db = $DB; + $this->dirmodule = $dirmodule; $this->targetmodule = $targetmodule; $this->canvas = $canvas; $this->card = $card; } + + /** + * Return the title of card + */ + private function getTitle($action) + { + global $langs; + $out=''; + + if ($action == 'view') $out.= $langs->trans("Contact"); + if ($action == 'edit') $out.= $langs->trans("EditContact"); + if ($action == 'create') $out.= $langs->trans("NewContact"); + + return $out; + } /** * Assign custom values for canvas @@ -57,10 +75,12 @@ class ActionsContactCardDefault extends ActionsContactCardCommon * @param string $action Type of action * @return void */ - function assign_values($action='') + function assign_values(&$action, $id) { global $conf, $db, $langs, $user; global $form; + + $ret = $this->getObject($id); parent::assign_values($action); @@ -77,15 +97,6 @@ class ActionsContactCardDefault extends ActionsContactCardCommon $this->tpl['showhead']=dol_get_fiche_head($head, 'card', $title, 0, 'contact'); $this->tpl['showend']=dol_get_fiche_end(); - // Confirm delete contact - if ($user->rights->societe->contact->supprimer) - { - if ($_GET["action"] == 'delete') - { - $this->tpl['action_delete'] = $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$this->object->id,$langs->trans("DeleteContact"),$langs->trans("ConfirmDeleteContact"),"confirm_delete",'',0,1); - } - } - $objsoc = new Societe($db); $objsoc->fetch($this->object->fk_soc); @@ -93,6 +104,14 @@ class ActionsContactCardDefault extends ActionsContactCardCommon $this->tpl['actionsdone']=show_actions_done($conf,$langs,$db,$objsoc,$this->object,1); } + else + { + // Confirm delete contact + if ($action == 'delete' && $user->rights->societe->contact->supprimer) + { + $this->tpl['action_delete'] = $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$this->object->id,$langs->trans("DeleteContact"),$langs->trans("ConfirmDeleteContact"),"confirm_delete",'',0,1); + } + } if ($action == 'list') { diff --git a/htdocs/contact/fiche.php b/htdocs/contact/fiche.php index 7e01644b08d..4f66bbdfc92 100644 --- a/htdocs/contact/fiche.php +++ b/htdocs/contact/fiche.php @@ -39,9 +39,10 @@ $langs->load("commercial"); $mesg=''; $error=0; $errors=array(); -$action = GETPOST('action'); -$id = GETPOST("id"); -$socid = GETPOST("socid"); +$action = (GETPOST('action') ? GETPOST('action') : 'view'); +$confirm = GETPOST('confirm'); +$id = GETPOST("id"); +$socid = GETPOST("socid"); if ($user->societe_id) $socid=$user->societe_id; $object = new Contact($db); @@ -52,8 +53,8 @@ $canvas = $object->canvas?$object->canvas:GETPOST("canvas"); if (! empty($canvas)) { require_once(DOL_DOCUMENT_ROOT."/core/class/canvas.class.php"); - $objcanvas = new Canvas($db,$action); - $objcanvas->getCanvas('contact','contactcard',$canvas); + $objcanvas = new Canvas($db, $action); + $objcanvas->getCanvas('contact', 'contactcard', $canvas); } // Security check @@ -69,25 +70,9 @@ $hookmanager->callHooks(array('contactcard')); * Actions */ -$parameters=array('id'=>$id); +$parameters=array('id'=>$id, 'objcanvas'=>$objcanvas); $reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks - -// ---------- start deprecated. Use hook to hook actions. -// If canvas actions are defined, because on url, or because contact was created with canvas feature on, we use the canvas feature. -// If canvas actions are not defined, we use standard feature. -if (method_exists($objcanvas->control,'doActions')) -{ - $objcanvas->doActions($id); - if (! empty($objcanvas->error) || (! empty($objcanvas->errors) && count($objcanvas->errors) > 0)) - { - $error=$objcanvas->error; $errors=$objcanvas->errors; - if ($action=='add') { $objcanvas->action='create'; $action='create'; } - if ($action=='update') { $objcanvas->action='edit'; $action='edit'; } - } -} -// ---------- end deprecated. - if (empty($reshook)) { // Cancel @@ -98,7 +83,7 @@ if (empty($reshook)) } // Creation utilisateur depuis contact - if ($_POST["action"] == 'confirm_create_user' && $_POST["confirm"] == 'yes' && $user->rights->user->user->creer) + if ($action == 'confirm_create_user' && $confirm == 'yes' && $user->rights->user->user->creer) { // Recuperation contact actuel $result = $object->fetch($_GET["id"]); @@ -137,7 +122,7 @@ if (empty($reshook)) } // Add contact - if (GETPOST("action") == 'add' && $user->rights->societe->contact->creer) + if ($action == 'add' && $user->rights->societe->contact->creer) { $db->begin(); @@ -196,7 +181,7 @@ if (empty($reshook)) } } - if (GETPOST("action") == 'confirm_delete' && GETPOST("confirm") == 'yes' && $user->rights->societe->contact->supprimer) + if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->societe->contact->supprimer) { $result=$object->fetch($_GET["id"]); @@ -215,12 +200,12 @@ if (empty($reshook)) } } - if ($_POST["action"] == 'update' && ! $_POST["cancel"] && $user->rights->societe->contact->creer) + if ($action == 'update' && ! $_POST["cancel"] && $user->rights->societe->contact->creer) { if (empty($_POST["name"])) { $error++; $errors=array($langs->trans("ErrorFieldRequired",$langs->transnoentities("Name").' / '.$langs->transnoentities("Label"))); - $_GET["action"] = $_POST["action"] = 'edit'; + $action = 'edit'; } if (! count($errors)) @@ -287,41 +272,14 @@ if ($socid > 0) $objsoc->fetch($socid); } -// TODO Mutualize this part of code (same than societe/soc.php and product/fiche.php) -if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) +if (is_object($objcanvas) && $objcanvas->displayCanvasExists()) { // ----------------------------------------- // When used with CANVAS // ----------------------------------------- - if ($action == 'create') - { - $objcanvas->assign_values($action); // Set value for templates - $objcanvas->display_canvas($action); // Show template - } - else if ($action == 'edit') - { - $objcanvas->control->object=$objcanvas->getObject($id); // TODO: Getting and storing object should be done into assign_values (for template with no code) or into tpl - if (empty($objcanvas->control->object)) - { - $object = new Contact($db); - $object->fetch($id,$user); - $objcanvas->control->object=$object; - } - $objcanvas->assign_values($action); // Set value for templates - $objcanvas->display_canvas($action); // Show template - } - else - { - $objcanvas->control->object=$objcanvas->getObject($id); // TODO: Getting and storing object should be done into assign_values (for template with no code) or into tpl - if (empty($objcanvas->control->object)) - { - $object = new Contact($db); - $object->fetch($id,$user); - $objcanvas->control->object=$object; - } - $objcanvas->assign_values('view'); // Assign values - $objcanvas->display_canvas('view'); // Show template - } + + $objcanvas->assign_values($action, $id); // Set value for templates + $objcanvas->display_canvas(); // Show template } else { @@ -332,7 +290,7 @@ else // Confirm deleting contact if ($user->rights->societe->contact->supprimer) { - if ($_GET["action"] == 'delete') + if ($action == 'delete') { $ret=$form->form_confirm($_SERVER["PHP_SELF"]."?id=".$_GET["id"],$langs->trans("DeleteContact"),$langs->trans("ConfirmDeleteContact"),"confirm_delete",'',0,1); if ($ret == 'html') print '
'; @@ -342,7 +300,7 @@ else /* * Onglets */ - if (GETPOST("id") > 0) + if ($id > 0) { // Si edition contact deja existant $object = new Contact($db); @@ -350,7 +308,7 @@ else if ($return <= 0) { dol_print_error('',$object->error); - $_GET["id"]=0; + $id=0; } // Show tabs @@ -361,7 +319,7 @@ else if ($user->rights->societe->contact->creer) { - if (GETPOST("action") == 'create') + if ($action == 'create') { /* * Fiche en mode creation @@ -549,7 +507,7 @@ else print ""; } - elseif (GETPOST("action") == 'edit' && GETPOST("id")) + elseif ($action == 'edit' && ! empty($id)) { /* * Fiche en mode edition @@ -734,7 +692,7 @@ else } } - if (GETPOST("id") && GETPOST("action") != 'edit') + if (! empty($id) && $action != 'edit') { $objsoc = new Societe($db); @@ -744,7 +702,7 @@ else dol_htmloutput_errors($error,$errors); - if ($_GET["action"] == 'create_user') + if ($action == 'create_user') { // Full firstname and name separated with a dot : firstname.name include_once(DOL_DOCUMENT_ROOT.'/lib/functions2.lib.php'); diff --git a/htdocs/core/class/canvas.class.php b/htdocs/core/class/canvas.class.php index 032b646d340..e2a9672428a 100644 --- a/htdocs/core/class/canvas.class.php +++ b/htdocs/core/class/canvas.class.php @@ -32,9 +32,10 @@ class Canvas var $db; var $error; var $errors=array(); + + var $actiontype; - var $action; - + var $dirmodule; // Module directory var $targetmodule; // Module concerned by canvas (ex: thirdparty, contact, ...) var $canvas; // Name of canvas var $card; // Tab (sub-canvas) @@ -49,29 +50,17 @@ class Canvas * Constructor * * @param DoliDB $DB Database handler - * @param string $action Action ('create', 'view', 'edit') */ - function Canvas($DB, $action='view') + function __construct($DB, $actiontype='view') { $this->db = $DB; - $this->action = $action; - if ($this->action == 'add') $this->action='create'; - if ($this->action == 'update') $this->action='edit'; - if (empty($this->action)) $this->action='view'; + + $this->actiontype = $actiontype; + if ($this->actiontype == 'add') $this->actiontype='create'; + if ($this->actiontype == 'update') $this->actiontype='edit'; + if (empty($this->actiontype) || $this->actiontype == 'delete' || $this->actiontype == 'create_user') $this->actiontype='view'; } - /** - * Set action type - * - * @deprecated Kept for backward compatibility - */ - function setAction($action='view') - { - return $this->action = $action; - } - - - /** * Initialize properties: ->targetmodule, ->canvas, ->card * and MVC properties: ->control (Controller), ->control->object (Model), ->template_dir (View) @@ -90,17 +79,17 @@ class Canvas $this->targetmodule = $module; $this->canvas = $canvas; $this->card = $card; - $dirmodule = $module; + $this->dirmodule = $module; // Correct values if canvas is into an external module if (preg_match('/^([^@]+)@([^@]+)$/i',$canvas,$regs)) { $this->canvas = $regs[1]; - $dirmodule = $regs[2]; + $this->dirmodule = $regs[2]; } // For compatibility - if ($dirmodule == 'thirdparty') { $dirmodule = 'societe'; } + if ($this->dirmodule == 'thirdparty') { $this->dirmodule = 'societe'; } - $controlclassfile = dol_buildpath('/'.$dirmodule.'/canvas/'.$this->canvas.'/actions_'.$this->card.'_'.$this->canvas.'.class.php'); + $controlclassfile = dol_buildpath('/'.$this->dirmodule.'/canvas/'.$this->canvas.'/actions_'.$this->card.'_'.$this->canvas.'.class.php'); if (file_exists($controlclassfile)) { // Include actions class (controller) @@ -109,23 +98,11 @@ class Canvas // Instantiate actions class (controller) $controlclassname = 'Actions'.ucfirst($this->card).ucfirst($this->canvas); - $this->control = new $controlclassname($this->db,$this->targetmodule,$this->canvas,$this->card); + $this->control = new $controlclassname($this->db, $this->dirmodule, $this->targetmodule, $this->canvas, $this->card); } - // TODO Dao should be declared and used by controller or templates when required only - $modelclassfile = dol_buildpath('/'.$dirmodule.'/canvas/'.$this->canvas.'/dao_'.$this->targetmodule.'_'.$this->canvas.'.class.php'); - if (file_exists($modelclassfile)) - { - // Include dataservice class (model) - require_once($modelclassfile); - - // Instantiate dataservice class (model) - $modelclassname = 'Dao'.ucfirst($this->targetmodule).ucfirst($this->canvas); - $this->control->object = new $modelclassname($this->db); - } - // Template dir - $this->template_dir = dol_buildpath('/'.$dirmodule.'/canvas/'.$this->canvas.'/tpl/'); + $this->template_dir = dol_buildpath('/'.$this->dirmodule.'/canvas/'.$this->canvas.'/tpl/'); if (! is_dir($this->template_dir)) { $this->template_dir=''; @@ -137,89 +114,61 @@ class Canvas return 1; } - - /** - * Execute actions - * - * @param id Id of object (may be empty for creation) - * @deprecated Use actions with hooks instead - */ - function doActions($id) - { - $out=''; - - // If function to do actions is overwritten, we use new one - if (method_exists($this->control,'doActions')) - { - $out = $this->control->doActions($id,$this->targetmodule,$this->canvas,$this->card); - - $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; - } - - /** - * Get object - * - * @param param1 Param1 - * @param param2 Param2 - * @param param3 Param3 - * @return object Object loaded - */ - function getObject($param1, $param2='', $param3='') - { - if (is_object($this->control->object) && method_exists($this->control->object,'fetch')) - { - $this->control->object->fetch($param1, $param2, $param3); - return $this->control->object; - } - else - { - return 0; - } - } - - /** - * Shared method for canvas to assign values for templates + + /** + * Shared method for canvas to execute actions + * + * @param string $action Action string + * @param int $id Object id + * @return void */ - function assign_values($action) + function doActions(&$action='view', $id=0) { - if (method_exists($this->control,'assign_values')) $this->control->assign_values($action); + if (method_exists($this->control,'doActions')) + { + $ret = $this->control->doActions($action, $id); + return $ret; + } } /** - * Return the template to display canvas (if it exists) + * Shared method for canvas to assign values for templates + * + * @param string $action Action string + * @param int $id Object id + * @return void + */ + function assign_values(&$action='view', $id=0) + { + if (method_exists($this->control,'assign_values')) $this->control->assign_values($action, $id); + } + + /** + * Return the template to display canvas (if it exists) * - * @param string $mode 'create', ''='view', 'edit', 'list' - * @return string Path to display canvas file if it exists, '' otherwise. + * @return string Path to display canvas file if it exists, '' otherwise. */ - function displayCanvasExists($mode='view') + function displayCanvasExists() { - $newmode=$mode; - if (empty($newmode)) $newmode='view'; if (empty($this->template_dir)) return 0; - //print $this->template_dir.($this->card?$this->card.'_':'').$newmode.'.tpl.php'; - if (file_exists($this->template_dir.($this->card?$this->card.'_':'').$newmode.'.tpl.php')) return 1; + //print $this->template_dir.($this->card?$this->card.'_':'').$this->actiontype.'.tpl.php'; + if (file_exists($this->template_dir.($this->card?$this->card.'_':'').$this->actiontype.'.tpl.php')) return 1; else return 0; } /** - * Display a canvas page. This will include the template for output. - * Variables used by templates may have been defined, loaded before - * into the assign_values function. + * Display a canvas page. This will include the template for output. + * Variables used by templates may have been defined, loaded before + * into the assign_values function. * - * @param string $mode 'create', 'view', 'edit' - * @param int $id Id of object to show + * @return void */ - function display_canvas($mode='view',$id=0) + function display_canvas() { global $db, $conf, $langs, $user, $canvas; - global $id, $form, $formfile; + global $form, $formfile; - //print $this->template_dir.($this->card?$this->card.'_':'').$mode.'.tpl.php';exit; - include($this->template_dir.($this->card?$this->card.'_':'').$mode.'.tpl.php'); // Include native PHP template + include($this->template_dir.($this->card?$this->card.'_':'').$this->actiontype.'.tpl.php'); // Include native PHP template } } diff --git a/htdocs/includes/modules/modBanque.class.php b/htdocs/includes/modules/modBanque.class.php index e4acc6943d7..d3bdfc89976 100644 --- a/htdocs/includes/modules/modBanque.class.php +++ b/htdocs/includes/modules/modBanque.class.php @@ -3,7 +3,7 @@ * Copyright (C) 2004-2008 Laurent Destailleur * Copyright (C) 2004 Sebastien Di Cintio * Copyright (C) 2004 Benoit Mortier - * Copyright (C) 2008-2009 Regis Houssin + * Copyright (C) 2008-2011 Regis Houssin * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -30,16 +30,18 @@ include_once(DOL_DOCUMENT_ROOT ."/includes/modules/DolibarrModules.class.php"); -/** \class modBanque - \brief Classe de description et activation du module Banque +/** + * \class modBanque + * \brief Classe de description et activation du module Banque */ class modBanque extends DolibarrModules { /** - * \brief Constructeur. Definit les noms, constantes et boites - * \param DB handler d'acc�s base + * Constructor. + * + * @param DoliDB $DB Database handler */ function modBanque($DB) { @@ -166,6 +168,7 @@ class modBanque extends DolibarrModules * Function called when module is enabled. * The init function add constants, boxes, permissions and menus (defined in constructor) into Dolibarr database. * It also creates data directories. + * * @return int 1 if OK, 0 if KO */ function init() @@ -184,6 +187,7 @@ class modBanque extends DolibarrModules * Function called when module is disabled. * Remove from database constants, boxes and permissions from Dolibarr database. * Data directories are not deleted. + * * @return int 1 if OK, 0 if KO */ function remove() diff --git a/htdocs/societe/canvas/actions_card_common.class.php b/htdocs/societe/canvas/actions_card_common.class.php index 68fd3c1d99f..c8d0591f61e 100644 --- a/htdocs/societe/canvas/actions_card_common.class.php +++ b/htdocs/societe/canvas/actions_card_common.class.php @@ -29,6 +29,7 @@ abstract class ActionsCardCommon { var $db; + var $dirmodule; var $targetmodule; var $canvas; var $card; @@ -45,27 +46,74 @@ abstract class ActionsCardCommon /** * Constructor * - * @param DoliDB $DB Database handler - * @param string $targetmodule Name of directory of module where canvas is stored - * @param string $canvas Name of canvas - * @param string $card Name of tab (sub-canvas) + * @param DoliDB $DB Database handler + * @param string $dirmodule Name of directory of module + * @param string $targetmodule Name of directory where canvas is stored + * @param string $canvas Name of canvas + * @param string $card Name of tab (sub-canvas) */ - function ActionsCardCommon($DB,$targetmodule,$canvas,$card) + function __construct($DB, $dirmodule, $targetmodule, $canvas, $card) { $this->db = $DB; + $this->dirmodule = $dirmodule; $this->targetmodule = $targetmodule; $this->canvas = $canvas; $this->card = $card; } - + + /** + * Instantiation of DAO class + * + * @return void + */ + private function getInstanceDao() + { + if (! is_object($this->object)) + { + $modelclassfile = dol_buildpath('/'.$this->dirmodule.'/canvas/'.$this->canvas.'/dao_'.$this->targetmodule.'_'.$this->canvas.'.class.php'); + if (file_exists($modelclassfile)) + { + // Include dataservice class (model) + $ret = require_once($modelclassfile); + if ($ret) + { + // Instantiate dataservice class (model) + $modelclassname = 'Dao'.ucfirst($this->targetmodule).ucfirst($this->canvas); + $this->object = new $modelclassname($this->db); + } + } + } + } + + /** + * Get object + * + * @param int Object id + * @return object Object loaded + */ + function getObject($id) + { + $ret = $this->getInstanceDao(); + + if (is_object($this->object) && method_exists($this->object,'fetch')) + { + if (! empty($id)) $this->object->fetch($id); + } + else + { + $object = new Societe($this->db); + if (! empty($id)) $object->fetch($id); + $this->object = $object; + } + } /** - * Load data control + * Load data control * - * @param int $socid Id of third party - * @return void + * @param int $socid Id of third party + * @return void */ - function doActions($socid) + function doActions(&$action) { global $conf, $user, $langs; @@ -83,78 +131,68 @@ abstract class ActionsCardCommon // Add new third party if ((! $_POST["getcustomercode"] && ! $_POST["getsuppliercode"]) - && ($_POST["action"] == 'add' || $_POST["action"] == 'update')) + && ($action == 'add' || $action == 'update')) { require_once(DOL_DOCUMENT_ROOT."/lib/functions2.lib.php"); $error=0; - if ($_POST["action"] == 'update') + if (GETPOST("private") == 1) { - // Load properties of company - $this->object->fetch($socid); - } + $this->object->particulier = GETPOST("private"); - if ($_REQUEST["private"] == 1) - { - $this->object->particulier = $_REQUEST["private"]; - - $this->object->nom = empty($conf->global->MAIN_FIRSTNAME_NAME_POSITION)?trim($_POST["prenom"].' '.$_POST["nom"]):trim($_POST["nom"].' '.$_POST["prenom"]); - $this->object->nom_particulier = $_POST["nom"]; - $this->object->prenom = $_POST["prenom"]; - $this->object->civilite_id = $_POST["civilite_id"]; + $this->object->nom = empty($conf->global->MAIN_FIRSTNAME_NAME_POSITION)?trim($_POST["prenom"].' '.$_POST["nom"]):trim($_POST["nom"].' '.$_POST["prenom"]); + $this->object->nom_particulier = $_POST["nom"]; + $this->object->prenom = $_POST["prenom"]; + $this->object->civilite_id = $_POST["civilite_id"]; } else { - $this->object->nom = $_POST["nom"]; + $this->object->name = $_POST["nom"]; } - $this->object->adresse = $_POST["adresse"]; // TODO deprecated - $this->object->address = $_POST["adresse"]; - $this->object->cp = $_POST["zipcode"]; // TODO deprecated - $this->object->zip = $_POST["zipcode"]; - $this->object->ville = $_POST["town"]; // TODO deprecated - $this->object->town = $_POST["town"]; - $this->object->pays_id = $_POST["pays_id"]; // TODO deprecated - $this->object->country_id = $_POST["pays_id"]; - $this->object->state_id = $_POST["departement_id"]; - $this->object->tel = $_POST["tel"]; - $this->object->fax = $_POST["fax"]; - $this->object->email = trim($_POST["email"]); - $this->object->url = $_POST["url"]; - $this->object->siren = $_POST["idprof1"]; - $this->object->siret = $_POST["idprof2"]; - $this->object->ape = $_POST["idprof3"]; - $this->object->idprof4 = $_POST["idprof4"]; - $this->object->prefix_comm = $_POST["prefix_comm"]; - $this->object->code_client = $_POST["code_client"]; - $this->object->code_fournisseur = $_POST["code_fournisseur"]; - $this->object->capital = $_POST["capital"]; - $this->object->gencod = $_POST["gencod"]; - $this->object->canvas = $_REQUEST["canvas"]; + $this->object->address = $_POST["adresse"]; + $this->object->zip = $_POST["zipcode"]; + $this->object->town = $_POST["town"]; + $this->object->country_id = $_POST["pays_id"]; + $this->object->state_id = $_POST["departement_id"]; + $this->object->tel = $_POST["tel"]; + $this->object->fax = $_POST["fax"]; + $this->object->email = trim($_POST["email"]); + $this->object->url = $_POST["url"]; + $this->object->idprof1 = $_POST["idprof1"]; + $this->object->idprof2 = $_POST["idprof2"]; + $this->object->idprof3 = $_POST["idprof3"]; + $this->object->idprof4 = $_POST["idprof4"]; + $this->object->prefix_comm = $_POST["prefix_comm"]; + $this->object->code_client = $_POST["code_client"]; + $this->object->code_fournisseur = $_POST["code_fournisseur"]; + $this->object->capital = $_POST["capital"]; + $this->object->gencod = $_POST["gencod"]; + $this->object->canvas = GETPOST("canvas"); - $this->object->tva_assuj = $_POST["assujtva_value"]; + $this->object->tva_assuj = $_POST["assujtva_value"]; // Local Taxes - $this->object->localtax1_assuj = $_POST["localtax1assuj_value"]; - $this->object->localtax2_assuj = $_POST["localtax2assuj_value"]; - $this->object->tva_intra = $_POST["tva_intra"]; + $this->object->localtax1_assuj = $_POST["localtax1assuj_value"]; + $this->object->localtax2_assuj = $_POST["localtax2assuj_value"]; + $this->object->tva_intra = $_POST["tva_intra"]; - $this->object->forme_juridique_code = $_POST["forme_juridique_code"]; - $this->object->effectif_id = $_POST["effectif_id"]; - if ($_REQUEST["private"] == 1) + $this->object->forme_juridique_code = $_POST["forme_juridique_code"]; + $this->object->effectif_id = $_POST["effectif_id"]; + if (GETPOST("private") == 1) { - $this->object->typent_id = 8; // TODO predict another method if the field "special" change of rowid + $this->object->typent_id = 8; // TODO predict another method if the field "special" change of rowid } else { - $this->object->typent_id = $_POST["typent_id"]; + $this->object->typent_id = $_POST["typent_id"]; } - $this->object->client = $_POST["client"]; - $this->object->fournisseur = $_POST["fournisseur"]; - $this->object->fournisseur_categorie = $_POST["fournisseur_categorie"]; + $this->object->client = $_POST["client"]; + $this->object->fournisseur = $_POST["fournisseur"]; + $this->object->fournisseur_categorie = $_POST["fournisseur_categorie"]; - $this->object->commercial_id = $_POST["commercial_id"]; - $this->object->default_lang = $_POST["default_lang"]; + $this->object->commercial_id = $_POST["commercial_id"]; + $this->object->default_lang = $_POST["default_lang"]; // Check parameters if (empty($_POST["cancel"])) @@ -164,27 +202,27 @@ abstract class ActionsCardCommon $error = 1; $langs->load("errors"); $this->error = $langs->trans("ErrorBadEMail",$this->object->email); - $_GET["action"] = $_POST["action"]=='add'?'create':'edit'; + $action = ($action == 'add' ? 'create' : 'edit'); } if (! empty($this->object->url) && ! isValidUrl($this->object->url)) { $error = 1; $langs->load("errors"); $this->error = $langs->trans("ErrorBadUrl",$this->object->url); - $_GET["action"] = $_POST["action"]=='add'?'create':'edit'; + $action = ($action == 'add' ? 'create' : 'edit'); } if ($this->object->fournisseur && ! $conf->fournisseur->enabled) { $error = 1; $langs->load("errors"); $this->error = $langs->trans("ErrorSupplierModuleNotEnabled"); - $_GET["action"] = $_POST["action"]=='add'?'create':'edit'; + $action = ($action == 'add' ? 'create' : 'edit'); } } if (! $error) { - if ($_POST["action"] == 'add') + if ($action == 'add') { $this->db->begin(); @@ -248,48 +286,44 @@ abstract class ActionsCardCommon $this->db->rollback(); $this->errors=$this->object->errors; - $_GET["action"]='create'; + $action = 'create'; } } - if ($_POST["action"] == 'update') + if ($action == 'update') { if ($_POST["cancel"]) { - Header("Location: ".$_SERVER["PHP_SELF"]."?socid=".$socid); + Header("Location: ".$_SERVER["PHP_SELF"]."?socid=".$this->object->id); exit; } - - $oldsoccanvas = new Canvas($this->db); - $oldsoccanvas->getCanvas('thirdparty','card',$this->object->canvas); - $result=$oldsoccanvas->control->object->fetch($socid); + + $oldsoccanvas = dol_clone($this->object); // 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->fournisseur)&& empty($oldsoccanvas->control->object->code_fournisseur)) $this->object->code_fournisseur=''; //var_dump($soccanvas);exit; + if (empty($this->object->client) && empty($oldsoccanvas->code_client)) $this->object->code_client=''; + if (empty($this->object->fournisseur) && empty($oldsoccanvas->code_fournisseur)) $this->object->code_fournisseur=''; - $result = $this->object->update($socid,$user,1,$oldsoccanvas->control->object->codeclient_modifiable(),$oldsoccanvas->control->object->codefournisseur_modifiable()); + $result = $this->object->update($this->object->id, $user, 1, $oldsoccanvas->codeclient_modifiable(), $oldsoccanvas->codefournisseur_modifiable()); if ($result >= 0) { - Header("Location: ".$_SERVER["PHP_SELF"]."?socid=".$socid); + Header("Location: ".$_SERVER["PHP_SELF"]."?socid=".$this->object->id); exit; } else { - $this->object->id = $socid; + $this->object->id = $this->object->id; $reload = 0; $this->errors = $this->object->errors; - $_GET["action"]="edit"; + $action = "edit"; } } } } - if (GETPOST("action") == 'confirm_delete' && GETPOST("confirm") == 'yes') + if ($action == 'confirm_delete' && GETPOST("confirm") == 'yes') { - $this->object->fetch($socid); - - $result = $this->object->delete($socid); + $result = $this->object->delete($this->object->id); if ($result >= 0) { @@ -300,14 +334,14 @@ abstract class ActionsCardCommon { $reload = 0; $this->errors=$this->object->errors; - $_GET["action"]=''; + $action = ''; } } /* * Generate document */ - if (GETPOST('action') == 'builddoc') // En get ou en post + if ($action == 'builddoc') // En get ou en post { if (is_numeric(GETPOST('model'))) { @@ -317,7 +351,6 @@ abstract class ActionsCardCommon { require_once(DOL_DOCUMENT_ROOT.'/includes/modules/societe/modules_societe.class.php'); - $this->object->fetch($socid); $this->object->fetch_thirdparty(); // Define output language @@ -345,38 +378,18 @@ abstract class ActionsCardCommon } } - - /** - * Return the title of card - * - * @param string $action Type of action - * @return string HTML output - */ - private function getTitle($action) - { - global $langs; - - $out=''; - - if ($action == 'view') $out.= $langs->trans("Individual"); - if ($action == 'edit') $out.= $langs->trans("EditIndividual"); - if ($action == 'create') $out.= $langs->trans("NewIndividual"); - - return $out; - } - /** * Set content of ->tpl array, to use into template * * @param string $action Type of action * @return string HTML output */ - function assign_values($action) + function assign_values(&$action) { global $conf, $langs, $user, $mysoc, $canvas; global $form, $formadmin, $formcompany; - if ($action == 'create' || $action == 'edit') $this->assign_post(); + if ($action == 'add' || $action == 'update') $this->assign_post($action); if ($_GET["type"]=='f') { $this->object->fournisseur=1; } if ($_GET["type"]=='c') { $this->object->client=1; } @@ -389,8 +402,6 @@ abstract class ActionsCardCommon $this->tpl[$key] = $value; } - $this->tpl['title'] = $this->getTitle($action); - $this->tpl['error'] = get_htmloutput_errors($this->object->error,$this->object->errors); if ($action == 'create') @@ -546,7 +557,6 @@ abstract class ActionsCardCommon else { $head = societe_prepare_head($this->object); - $title = $this->getTitle($action); $this->tpl['showhead']=dol_get_fiche_head($head, 'card', $title, 0, 'company'); $this->tpl['showend']=dol_get_fiche_end(); @@ -666,27 +676,25 @@ abstract class ActionsCardCommon global $langs, $mysoc; $this->object->id = $_POST["socid"]; - $this->object->nom = $_POST["nom"]; + $this->object->name = $_POST["nom"]; $this->object->prefix_comm = $_POST["prefix_comm"]; $this->object->client = $_POST["client"]; $this->object->code_client = $_POST["code_client"]; $this->object->fournisseur = $_POST["fournisseur"]; $this->object->code_fournisseur = $_POST["code_fournisseur"]; - $this->object->adresse = $_POST["adresse"]; // TODO obsolete $this->object->address = $_POST["adresse"]; $this->object->zip = $_POST["zipcode"]; $this->object->town = $_POST["town"]; - $this->object->pays_id = $_POST["pays_id"]?$_POST["pays_id"]:$mysoc->pays_id; - $this->object->country_id = $_POST["pays_id"]?$_POST["pays_id"]:$mysoc->pays_id; + $this->object->country_id = $_POST["pays_id"]?$_POST["pays_id"]:$mysoc->country_id; $this->object->state_id = $_POST["departement_id"]; $this->object->tel = $_POST["tel"]; $this->object->fax = $_POST["fax"]; $this->object->email = $_POST["email"]; $this->object->url = $_POST["url"]; $this->object->capital = $_POST["capital"]; - $this->object->siren = $_POST["idprof1"]; - $this->object->siret = $_POST["idprof2"]; - $this->object->ape = $_POST["idprof3"]; + $this->object->idprof1 = $_POST["idprof1"]; + $this->object->idprof2 = $_POST["idprof2"]; + $this->object->idprof3 = $_POST["idprof3"]; $this->object->idprof4 = $_POST["idprof4"]; $this->object->typent_id = $_POST["typent_id"]; $this->object->effectif_id = $_POST["effectif_id"]; diff --git a/htdocs/societe/canvas/company/actions_card_company.class.php b/htdocs/societe/canvas/company/actions_card_company.class.php index 678625ba3cb..b7e6e344e15 100644 --- a/htdocs/societe/canvas/company/actions_card_company.class.php +++ b/htdocs/societe/canvas/company/actions_card_company.class.php @@ -1,6 +1,6 @@ - * Copyright (C) 2011 Laurent Destailleur +/* Copyright (C) 2010-2011 Regis Houssin + * Copyright (C) 2011 Laurent Destailleur * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -29,24 +29,27 @@ include_once(DOL_DOCUMENT_ROOT.'/societe/canvas/actions_card_common.class.php'); */ class ActionsCardCompany extends ActionsCardCommon { - var $targetmodule; + var $dirmodule; + var $targetmodule; var $canvas; var $card; /** * Constructor * - * @param DoliDB $DB Handler acces base de donnees - * @param string $targetmodule Name of directory of module where canvas is stored - * @param string $canvas Name of canvas - * @param string $card Name of tab (sub-canvas) + * @param DoliDB $DB Handler acces base de donnees + * @param string $dirmodule Name of directory of module + * @param string $targetmodule Name of directory of module where canvas is stored + * @param string $canvas Name of canvas + * @param string $card Name of tab (sub-canvas) */ - function ActionsCardCompany($DB,$targetmodule,$canvas,$card) + function __construct($DB, $dirmodule, $targetmodule, $canvas, $card) { - $this->db = $DB; - $this->targetmodule = $targetmodule; - $this->canvas = $canvas; - $this->card = $card; + $this->db = $DB; + $this->dirmodule = $dirmodule; + $this->targetmodule = $targetmodule; + $this->canvas = $canvas; + $this->card = $card; } /** @@ -75,9 +78,11 @@ class ActionsCardCompany extends ActionsCardCommon * @param int $socid Id of object (may be empty for creation) * @return int <0 if KO, >0 if OK */ - function doActions($socid) + function doActions(&$action, $id) { - $return = parent::doActions($socid); + $ret = $this->getObject($id); + + $return = parent::doActions($action); return $return; } @@ -88,12 +93,16 @@ class ActionsCardCompany extends ActionsCardCommon * @param string $action Type of action * @return void */ - function assign_values($action) + function assign_values(&$action, $id) { global $conf, $langs, $user, $mysoc; global $form, $formadmin, $formcompany; + + $ret = $this->getObject($id); parent::assign_values($action); + + $this->tpl['title'] = $this->getTitle($action); $this->tpl['profid1'] = $this->object->siren; $this->tpl['profid2'] = $this->object->siret; @@ -153,7 +162,7 @@ class ActionsCardCompany extends ActionsCardCommon else { // Confirm delete third party - if ($_GET["action"] == 'delete' || $conf->use_javascript_ajax) + if ($action == 'delete') { $this->tpl['action_delete'] = $form->formconfirm($_SERVER["PHP_SELF"]."?socid=".$this->object->id,$langs->trans("DeleteACompany"),$langs->trans("ConfirmDeleteCompany"),"confirm_delete",'',0,"1,action-delete"); } @@ -201,7 +210,7 @@ class ActionsCardCompany extends ActionsCardCommon $socm = new Societe($this->db); $socm->fetch($this->object->parent); $this->tpl['parent_company'] = $socm->getNomUrl(1).' '.($socm->code_client?"(".$socm->code_client.")":""); - $this->tpl['parent_company'].= $socm->ville?' - '.$socm->ville:''; + $this->tpl['parent_company'].= ($socm->town ? ' - ' . $socm->town : ''); } else { diff --git a/htdocs/societe/canvas/individual/actions_card_individual.class.php b/htdocs/societe/canvas/individual/actions_card_individual.class.php index 51dfe098b1b..fc6d183cb8f 100644 --- a/htdocs/societe/canvas/individual/actions_card_individual.class.php +++ b/htdocs/societe/canvas/individual/actions_card_individual.class.php @@ -28,24 +28,27 @@ include_once(DOL_DOCUMENT_ROOT.'/societe/canvas/actions_card_common.class.php'); */ class ActionsCardIndividual extends ActionsCardCommon { - var $targetmodule; + var $dirmodule; + var $targetmodule; var $canvas; var $card; /** * Constructor * - * @param DoliDB $DB Handler acces base de donnees - * @param string $targetmodule Name of directory of module where canvas is stored - * @param string $canvas Name of canvas - * @param string $card Name of tab (sub-canvas) + * @param DoliDB $DB Handler acces base de donnees + * @param string $dirmodule Name of directory of module + * @param string $targetmodule Name of directory of module where canvas is stored + * @param string $canvas Name of canvas + * @param string $card Name of tab (sub-canvas) */ - function ActionsCardIndividual($DB,$targetmodule,$canvas,$card) + function __construct($DB, $dirmodule, $targetmodule, $canvas, $card) { - $this->db = $DB; - $this->targetmodule = $targetmodule; - $this->canvas = $canvas; - $this->card = $card; + $this->db = $DB; + $this->dirmodule = $dirmodule; + $this->targetmodule = $targetmodule; + $this->canvas = $canvas; + $this->card = $card; } @@ -72,12 +75,14 @@ class ActionsCardIndividual extends ActionsCardCommon /** * Execute actions * - * @param int $socid Id of object (may be empty for creation) - * @return int <0 if KO, >0 if OK + * @param int $id Id of object (may be empty for creation) + * @return int <0 if KO, >0 if OK */ - function doActions($socid) + function doActions(&$action, $id) { - $return = parent::doActions($socid); + $ret = $this->getObject($id); + + $return = parent::doActions($action); return $return; } @@ -88,12 +93,16 @@ class ActionsCardIndividual extends ActionsCardCommon * @param string $action Type of action * @return void */ - function assign_values($action) + function assign_values(&$action, $id) { global $conf, $langs; global $form, $formcompany; + + $ret = $this->getObject($id); parent::assign_values($action); + + $this->tpl['title'] = $this->getTitle($action); if ($action == 'create' || $action == 'edit') { @@ -102,7 +111,7 @@ class ActionsCardIndividual extends ActionsCardCommon else { // Confirm delete third party - if ($_GET["action"] == 'delete' || $conf->use_javascript_ajax) + if ($action == 'delete' || $conf->use_javascript_ajax) { $this->tpl['action_delete'] = $form->formconfirm($_SERVER["PHP_SELF"]."?socid=".$this->object->id,$langs->trans("DeleteAnIndividual"),$langs->trans("ConfirmDeleteIndividual"),"confirm_delete",'',0,"1,action-delete"); } diff --git a/htdocs/societe/canvas/individual/dao_thirdparty_individual.class.php b/htdocs/societe/canvas/individual/dao_thirdparty_individual.class.php index c11d65440fb..e96e6e7f2c0 100644 --- a/htdocs/societe/canvas/individual/dao_thirdparty_individual.class.php +++ b/htdocs/societe/canvas/individual/dao_thirdparty_individual.class.php @@ -1,5 +1,5 @@ +/* Copyright (C) 2010-2011 Regis Houssin * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -34,7 +34,7 @@ class DaoThirdPartyIndividual extends Societe * * @param DoliDB $DB Databae handler */ - function DaoThirdPartyIndividual($DB) + function __construct($DB) { $this->db = $DB; } diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index c85f5bb1e46..a8d7823341a 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -297,8 +297,7 @@ class Societe extends CommonObject $this->errors=array(); $result = 0; - $this->name=$this->name?trim($this->name):trim($this->nom); - $this->nom=$this->name; // For backward compatibility + $this->name = trim($this->name); if (! $this->name) { @@ -393,34 +392,29 @@ class Societe extends CommonObject $now=dol_now(); // Clean parameters - $this->id=$id; - $this->name=$this->name?trim($this->name):trim($this->nom); - $this->nom=trim($this->nom); // TODO obsolete - $this->address=$this->address?trim($this->address):trim($this->adresse); - $this->adresse=$this->address; // TODO obsolete - $this->zip=$this->zip?trim($this->zip):trim($this->cp); - $this->cp=$this->zip; // TODO obsolete - $this->town=$this->town?trim($this->town):trim($this->ville); - $this->ville=$this->town; // TODO obsolete - $this->state_id=trim($this->state_id); - $this->pays_id=trim($this->pays_id); - $this->country_id=trim($this->country_id); - $this->tel=trim($this->tel); - $this->fax=trim($this->fax); - $this->tel = preg_replace("/\s/","",$this->tel); - $this->tel = preg_replace("/\./","",$this->tel); - $this->fax = preg_replace("/\s/","",$this->fax); - $this->fax = preg_replace("/\./","",$this->fax); - $this->email=trim($this->email); - $this->url=$this->url?clean_url($this->url,0):''; - $this->siren=trim($this->siren); - $this->siret=trim($this->siret); - $this->ape=trim($this->ape); - $this->idprof4=trim($this->idprof4); - $this->prefix_comm=trim($this->prefix_comm); + $this->id = $id; + $this->name = trim($this->name); + $this->address = trim($this->address); + $this->zip = trim($this->zip); + $this->town = trim($this->town); + $this->state_id = trim($this->state_id); + $this->country_id = trim($this->country_id); + $this->tel = trim($this->tel); + $this->fax = trim($this->fax); + $this->tel = preg_replace("/\s/","",$this->tel); + $this->tel = preg_replace("/\./","",$this->tel); + $this->fax = preg_replace("/\s/","",$this->fax); + $this->fax = preg_replace("/\./","",$this->fax); + $this->email = trim($this->email); + $this->url = $this->url?clean_url($this->url,0):''; + $this->idprof1 = trim($this->idprof1); + $this->idprof2 = trim($this->idprof2); + $this->idprof3 = trim($this->idprof3); + $this->idprof4 = trim($this->idprof4); + $this->prefix_comm = trim($this->prefix_comm); - $this->tva_assuj=trim($this->tva_assuj); - $this->tva_intra=dol_sanitizeFileName($this->tva_intra,''); + $this->tva_assuj = trim($this->tva_assuj); + $this->tva_intra = dol_sanitizeFileName($this->tva_intra,''); if (empty($this->status)) $this->status = 0; // Local taxes @@ -477,9 +471,9 @@ class Societe extends CommonObject $sql .= ",email = ".($this->email?"'".$this->db->escape($this->email)."'":"null"); $sql .= ",url = ".($this->url?"'".$this->db->escape($this->url)."'":"null"); - $sql .= ",siren = '". $this->db->escape($this->siren) ."'"; - $sql .= ",siret = '". $this->db->escape($this->siret) ."'"; - $sql .= ",ape = '". $this->db->escape($this->ape) ."'"; + $sql .= ",siren = '". $this->db->escape($this->idprof1) ."'"; + $sql .= ",siret = '". $this->db->escape($this->idprof2) ."'"; + $sql .= ",ape = '". $this->db->escape($this->idprof3) ."'"; $sql .= ",idprof4 = '". $this->db->escape($this->idprof4) ."'"; $sql .= ",tva_assuj = ".($this->tva_assuj!=''?"'".$this->tva_assuj."'":"null"); @@ -629,7 +623,7 @@ class Societe extends CommonObject $sql .= ', s.price_level'; $sql .= ', s.tms as date_update'; $sql .= ', s.tel, s.fax, s.email, s.url, s.cp as zip, s.ville as town, s.note, s.client, s.fournisseur'; - $sql .= ', s.siren, s.siret, s.ape, s.idprof4'; + $sql .= ', s.siren as idprof1, s.siret as idprof2, s.ape as idprof3, s.idprof4'; $sql .= ', s.capital, s.tva_intra'; $sql .= ', s.fk_typent as typent_id'; $sql .= ', s.fk_effectif as effectif_id'; @@ -655,9 +649,9 @@ class Societe extends CommonObject if ($ref) $sql .= " WHERE s.nom = '".$this->db->escape($ref)."' AND s.entity = ".$conf->entity; if ($ref_ext) $sql .= " WHERE s.ref_ext = '".$this->db->escape($ref_ext)."' AND s.entity = ".$conf->entity; if ($ref_int) $sql .= " WHERE s.ref_int = '".$this->db->escape($ref_int)."' AND s.entity = ".$conf->entity; - if ($idprof1) $sql .= " WHERE s.siren = '".$this->db->escape($siren)."' AND s.entity = ".$conf->entity; - if ($idprof2) $sql .= " WHERE s.siret = '".$this->db->escape($siret)."' AND s.entity = ".$conf->entity; - if ($idprof3) $sql .= " WHERE s.ape = '".$this->db->escape($ape)."' AND s.entity = ".$conf->entity; + if ($idprof1) $sql .= " WHERE s.siren = '".$this->db->escape($idprof1)."' AND s.entity = ".$conf->entity; + if ($idprof2) $sql .= " WHERE s.siret = '".$this->db->escape($idprof2)."' AND s.entity = ".$conf->entity; + if ($idprof3) $sql .= " WHERE s.ape = '".$this->db->escape($idprof3)."' AND s.entity = ".$conf->entity; if ($idprof4) $sql .= " WHERE s.idprof4 = '".$this->db->escape($idprof4)."' AND s.entity = ".$conf->entity; $resql=$this->db->query($sql); @@ -680,7 +674,7 @@ class Societe extends CommonObject $this->ref = $obj->rowid; $this->name = $obj->name; - $this->nom = $obj->name; // TODO obsolete + $this->nom = $obj->name; // TODO obsolete $this->ref_ext = $obj->ref_ext; $this->ref_int = $obj->ref_int; @@ -688,13 +682,13 @@ class Societe extends CommonObject $this->date_update = $this->db->jdate($obj->date_update); $this->address = $obj->address; - $this->adresse = $obj->address; // TODO obsolete + $this->adresse = $obj->address; // TODO obsolete $this->zip = $obj->zip; - $this->cp = $obj->zip; // TODO obsolete + $this->cp = $obj->zip; // TODO obsolete $this->town = $obj->town; - $this->ville = $obj->town;// TODO obsolete + $this->ville = $obj->town; // TODO obsolete - $this->pays_id = $obj->fk_pays; // TODO obsolete + $this->pays_id = $obj->fk_pays; // TODO obsolete $this->country_id = $obj->fk_pays; $this->pays_code = $obj->fk_pays?$obj->pays_code:''; // TODO obsolete $this->country_code = $obj->fk_pays?$obj->pays_code:''; @@ -717,11 +711,11 @@ class Societe extends CommonObject $this->parent = $obj->parent; - $this->siren = $obj->siren; // TODO obsolete + $this->siren = $obj->siren; // TODO obsolete $this->idprof1 = $obj->siren; - $this->siret = $obj->siret; // TODO obsolete + $this->siret = $obj->siret; // TODO obsolete $this->idprof2 = $obj->siret; - $this->ape = $obj->ape; // TODO obsolete + $this->ape = $obj->ape; // TODO obsolete $this->idprof3 = $obj->ape; $this->idprof4 = $obj->idprof4; diff --git a/htdocs/societe/soc.php b/htdocs/societe/soc.php index 40a0f586aec..b289e334c60 100644 --- a/htdocs/societe/soc.php +++ b/htdocs/societe/soc.php @@ -47,9 +47,9 @@ if ($conf->notification->enabled) $langs->load("mails"); $mesg=''; $error=0; $errors=array(); -$action = GETPOST('action'); -$confirm = GETPOST('confirm'); -$socid = GETPOST("socid"); +$action = (GETPOST('action') ? GETPOST('action') : 'view'); +$confirm = GETPOST('confirm'); +$socid = GETPOST("socid"); if ($user->societe_id) $socid=$user->societe_id; $object = new Societe($db); @@ -61,8 +61,8 @@ $canvas = $object->canvas?$object->canvas:GETPOST("canvas"); if (! empty($canvas)) { require_once(DOL_DOCUMENT_ROOT."/core/class/canvas.class.php"); - $objcanvas = new Canvas($db,$action); - $objcanvas->getCanvas('thirdparty','card',$canvas); + $objcanvas = new Canvas($db, $action); + $objcanvas->getCanvas('thirdparty', 'card', $canvas); } // Security check @@ -75,12 +75,11 @@ $hookmanager=new HookManager($db); $hookmanager->callHooks(array('thirdpartycard','thirdparty_extrafields')); - /* * Actions */ -$parameters=array('socid'=>$socid); +$parameters=array('id'=>$socid, 'objcanvas'=>$objcanvas); $reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks $error=$hookmanager->error; $errors=$hookmanager->errors; @@ -104,42 +103,33 @@ if (empty($reshook)) { require_once(DOL_DOCUMENT_ROOT."/lib/functions2.lib.php"); - if ($action == 'update') - { - $object->fetch($socid); - } + if ($action == 'update') $object->fetch($socid); if (GETPOST("private") == 1) { - $object->particulier = GETPOST("private"); + $object->particulier = GETPOST("private"); - $object->name = empty($conf->global->MAIN_FIRSTNAME_NAME_POSITION)?trim($_POST["prenom"].' '.$_POST["nom"]):trim($_POST["nom"].' '.$_POST["prenom"]); - $object->nom = $object->name; // TODO obsolete - $object->nom_particulier = $_POST["nom"]; - $object->prenom = $_POST["prenom"]; - $object->civilite_id = $_POST["civilite_id"]; + $object->name = empty($conf->global->MAIN_FIRSTNAME_NAME_POSITION)?trim($_POST["prenom"].' '.$_POST["nom"]):trim($_POST["nom"].' '.$_POST["prenom"]); + $object->nom_particulier = $_POST["nom"]; + $object->prenom = $_POST["prenom"]; + $object->civilite_id = $_POST["civilite_id"]; } else { - $object->name = $_POST["nom"]; - $object->nom = $object->name; // TODO obsolete + $object->name = $_POST["nom"]; } $object->address = $_POST["adresse"]; - $object->adresse = $_POST["adresse"]; // TODO obsolete $object->zip = $_POST["zipcode"]; - $object->cp = $_POST["zipcode"]; // TODO obsolete $object->town = $_POST["town"]; - $object->ville = $_POST["town"]; // TODO obsolete - $object->pays_id = $_POST["pays_id"]; $object->country_id = $_POST["pays_id"]; $object->state_id = $_POST["departement_id"]; $object->tel = $_POST["tel"]; $object->fax = $_POST["fax"]; $object->email = trim($_POST["email"]); $object->url = trim($_POST["url"]); - $object->siren = $_POST["idprof1"]; - $object->siret = $_POST["idprof2"]; - $object->ape = $_POST["idprof3"]; + $object->idprof1 = $_POST["idprof1"]; + $object->idprof2 = $_POST["idprof2"]; + $object->idprof4 = $_POST["idprof3"]; $object->idprof4 = $_POST["idprof4"]; $object->prefix_comm = $_POST["prefix_comm"]; $object->code_client = $_POST["code_client"]; @@ -159,11 +149,11 @@ if (empty($reshook)) $object->effectif_id = $_POST["effectif_id"]; if (GETPOST("private") == 1) { - $object->typent_id = 8; // TODO predict another method if the field "special" change of rowid + $object->typent_id = 8; // TODO predict another method if the field "special" change of rowid } else { - $object->typent_id = $_POST["typent_id"]; + $object->typent_id = $_POST["typent_id"]; } $object->client = $_POST["client"]; @@ -479,41 +469,14 @@ $formcompany = new FormCompany($db); $countrynotdefined=$langs->trans("ErrorSetACountryFirst").' ('.$langs->trans("SeeAbove").')'; -// TODO Mutualize this part of code (same than product/fiche.php and contact/fiche.php) -if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) +if (is_object($objcanvas) && $objcanvas->displayCanvasExists()) { // ----------------------------------------- // When used with CANVAS // ----------------------------------------- - if ($action == 'create') - { - $objcanvas->assign_values($action); // Set value for templates - $objcanvas->display_canvas($action,0); // Show template - } - elseif ($action == 'edit') - { - $objcanvas->control->object=$objcanvas->getObject($socid); // TODO: Getting and storing object should be done into assign_values (for template with no code) or into tpl - if (empty($objcanvas->control->object)) - { - $object = new Societe($db); - $object->fetch($socid); - $objcanvas->control->object=$object; - } - $objcanvas->assign_values($action); // Set value for templates - $objcanvas->display_canvas($action); // Show template - } - else - { - $objcanvas->control->object=$objcanvas->getObject($socid); // TODO: Getting and storing object should be done into assign_values (for template with no code) or into tpl - if (empty($objcanvas->control->object)) - { - $object = new Societe($db); - $object->fetch($socid); - $objcanvas->control->object=$object; - } - $objcanvas->assign_values('view'); - $objcanvas->display_canvas('view'); // Show template - } + + $objcanvas->assign_values($action, $socid); // Set value for templates + $objcanvas->display_canvas(); // Show template } else { @@ -551,46 +514,42 @@ else if ($conf->fournisseur->enabled && (GETPOST("type")=='f' || GETPOST("type")=='')) { $object->fournisseur=1; } if (GETPOST("private")==1) { $object->particulier=1; } - $object->name=$_POST["nom"]; - $object->nom=$_POST["nom"]; // TODO obsolete - $object->prenom=$_POST["prenom"]; - $object->particulier=$_REQUEST["private"]; - $object->prefix_comm=$_POST["prefix_comm"]; - $object->client=$_POST["client"]?$_POST["client"]:$object->client; - $object->code_client=$_POST["code_client"]; - $object->fournisseur=$_POST["fournisseur"]?$_POST["fournisseur"]:$object->fournisseur; - $object->code_fournisseur=$_POST["code_fournisseur"]; - $object->adresse=$_POST["adresse"]; // TODO obsolete - $object->address=$_POST["adresse"]; - $object->cp=$_POST["zipcode"]; // TODO obsolete - $object->zip=$_POST["zipcode"]; - $object->ville=$_POST["town"]; // TODO obsolete - $object->town=$_POST["town"]; - $object->state_id=$_POST["departement_id"]; - $object->tel=$_POST["tel"]; - $object->fax=$_POST["fax"]; - $object->email=$_POST["email"]; - $object->url=$_POST["url"]; - $object->capital=$_POST["capital"]; - $object->gencod=$_POST["gencod"]; - $object->siren=$_POST["idprof1"]; - $object->siret=$_POST["idprof2"]; - $object->ape=$_POST["idprof3"]; - $object->idprof4=$_POST["idprof4"]; - $object->typent_id=$_POST["typent_id"]; - $object->effectif_id=$_POST["effectif_id"]; + $object->name = $_POST["nom"]; + $object->prenom = $_POST["prenom"]; + $object->particulier = $_REQUEST["private"]; + $object->prefix_comm = $_POST["prefix_comm"]; + $object->client = $_POST["client"]?$_POST["client"]:$object->client; + $object->code_client = $_POST["code_client"]; + $object->fournisseur = $_POST["fournisseur"]?$_POST["fournisseur"]:$object->fournisseur; + $object->code_fournisseur = $_POST["code_fournisseur"]; + $object->address = $_POST["adresse"]; + $object->zip = $_POST["zipcode"]; + $object->town = $_POST["town"]; + $object->state_id = $_POST["departement_id"]; + $object->tel = $_POST["tel"]; + $object->fax = $_POST["fax"]; + $object->email = $_POST["email"]; + $object->url = $_POST["url"]; + $object->capital = $_POST["capital"]; + $object->gencod = $_POST["gencod"]; + $object->idprof1 = $_POST["idprof1"]; + $object->idprof2 = $_POST["idprof2"]; + $object->idprof3 = $_POST["idprof3"]; + $object->idprof4 = $_POST["idprof4"]; + $object->typent_id = $_POST["typent_id"]; + $object->effectif_id = $_POST["effectif_id"]; - $object->tva_assuj = $_POST["assujtva_value"]; - $object->status= $_POST["status"]; + $object->tva_assuj = $_POST["assujtva_value"]; + $object->status = $_POST["status"]; //Local Taxes - $object->localtax1_assuj = $_POST["localtax1assuj_value"]; - $object->localtax2_assuj = $_POST["localtax2assuj_value"]; + $object->localtax1_assuj = $_POST["localtax1assuj_value"]; + $object->localtax2_assuj = $_POST["localtax2assuj_value"]; - $object->tva_intra=$_POST["tva_intra"]; + $object->tva_intra = $_POST["tva_intra"]; - $object->commercial_id=$_POST["commercial_id"]; - $object->default_lang=$_POST["default_lang"]; + $object->commercial_id = $_POST["commercial_id"]; + $object->default_lang = $_POST["default_lang"]; $object->logo = dol_sanitizeFileName($_FILES['photo']['name']);