From 96ed2fe994b13f23cbf0451cb892aee484d19482 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Sat, 24 Sep 2011 15:57:52 +0000 Subject: [PATCH 01/32] 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']); From aa6625c78c6ae385d7788a21d8a92c45788eccf2 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Sat, 24 Sep 2011 16:06:07 +0000 Subject: [PATCH 02/32] Fix: bad name --- htdocs/contact/canvas/actions_contactcard_common.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/contact/canvas/actions_contactcard_common.class.php b/htdocs/contact/canvas/actions_contactcard_common.class.php index 9e8d17fa718..6f7ceced553 100644 --- a/htdocs/contact/canvas/actions_contactcard_common.class.php +++ b/htdocs/contact/canvas/actions_contactcard_common.class.php @@ -54,7 +54,7 @@ abstract class ActionsContactCardCommon function __construct($DB, $dirmodule, $targetmodule, $canvas, $card) { $this->db = $DB; - $this->dirmodule = $targetmodule; + $this->dirmodule = $dirmodule; $this->targetmodule = $targetmodule; $this->canvas = $canvas; $this->card = $card; From 47b6694527689f6d97d5e47a9ef396364ecd3da2 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Sat, 24 Sep 2011 15:57:52 +0000 Subject: [PATCH 03/32] Fix: broken canvas --- htdocs/contact/canvas/actions_contactcard_common.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/contact/canvas/actions_contactcard_common.class.php b/htdocs/contact/canvas/actions_contactcard_common.class.php index 6f7ceced553..9e8d17fa718 100644 --- a/htdocs/contact/canvas/actions_contactcard_common.class.php +++ b/htdocs/contact/canvas/actions_contactcard_common.class.php @@ -54,7 +54,7 @@ abstract class ActionsContactCardCommon function __construct($DB, $dirmodule, $targetmodule, $canvas, $card) { $this->db = $DB; - $this->dirmodule = $dirmodule; + $this->dirmodule = $targetmodule; $this->targetmodule = $targetmodule; $this->canvas = $canvas; $this->card = $card; From 7f69441bb6317dd63af5c7013ecf0d8b78d8cda6 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Sat, 24 Sep 2011 15:57:52 +0000 Subject: [PATCH 04/32] Fix: broken canvas From 22c32e04aa8876fbcf389c549608caf4ee977bab Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Sat, 24 Sep 2011 16:06:07 +0000 Subject: [PATCH 05/32] Fix: bad name --- htdocs/contact/canvas/actions_contactcard_common.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/contact/canvas/actions_contactcard_common.class.php b/htdocs/contact/canvas/actions_contactcard_common.class.php index 9e8d17fa718..6f7ceced553 100644 --- a/htdocs/contact/canvas/actions_contactcard_common.class.php +++ b/htdocs/contact/canvas/actions_contactcard_common.class.php @@ -54,7 +54,7 @@ abstract class ActionsContactCardCommon function __construct($DB, $dirmodule, $targetmodule, $canvas, $card) { $this->db = $DB; - $this->dirmodule = $targetmodule; + $this->dirmodule = $dirmodule; $this->targetmodule = $targetmodule; $this->canvas = $canvas; $this->card = $card; From bebf134caad21f08727d75b73ee957ff29a09f8a Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Sat, 24 Sep 2011 16:06:07 +0000 Subject: [PATCH 06/32] Fix: bad name From ed81eedb7c888d050b8b354b59092a59e2049a7c Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 24 Sep 2011 20:50:57 +0000 Subject: [PATCH 07/32] Fix: Little fix after canvas changes to be able to have "pure canvas" (canvas with no controller, only templates). --- htdocs/contact/fiche.php | 8 +++++++- htdocs/societe/soc.php | 11 ++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/htdocs/contact/fiche.php b/htdocs/contact/fiche.php index 4f66bbdfc92..745d0c3d6e7 100644 --- a/htdocs/contact/fiche.php +++ b/htdocs/contact/fiche.php @@ -277,7 +277,11 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists()) // ----------------------------------------- // When used with CANVAS // ----------------------------------------- - + if (! $objcanvas->hasActions() && $id) + { + $object = new Societe($db); + $object->fetch($id); // For use with "pure canvas" (canvas that contains templates only) + } $objcanvas->assign_values($action, $id); // Set value for templates $objcanvas->display_canvas(); // Show template } @@ -324,6 +328,8 @@ else /* * Fiche en mode creation */ + $object->canvas=$canvas; + $object->fk_departement = $_POST["departement_id"]; // We set pays_id, pays_code and label for the selected country diff --git a/htdocs/societe/soc.php b/htdocs/societe/soc.php index b289e334c60..66097323008 100644 --- a/htdocs/societe/soc.php +++ b/htdocs/societe/soc.php @@ -104,6 +104,7 @@ if (empty($reshook)) require_once(DOL_DOCUMENT_ROOT."/lib/functions2.lib.php"); if ($action == 'update') $object->fetch($socid); + else $object->canvas=$canvas; if (GETPOST("private") == 1) { @@ -474,9 +475,13 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists()) // ----------------------------------------- // When used with CANVAS // ----------------------------------------- - - $objcanvas->assign_values($action, $socid); // Set value for templates - $objcanvas->display_canvas(); // Show template + if (! $objcanvas->hasActions() && $socid) + { + $object = new Societe($db); + $object->fetch($socid); // For use with "pure canvas" (canvas that contains templates only) + } + $objcanvas->assign_values($action, $socid); // Set value for templates + $objcanvas->display_canvas(); // Show template } else { From 6a1a2127537f087e96d67e76e4d4287add335e74 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 24 Sep 2011 20:50:57 +0000 Subject: [PATCH 08/32] Fix: Little fix after canvas changes to be able to have "pure canvas" (canvas with no controller, only templates). From 727288c94ba4420fdf3661024553ca7b191c4ad0 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 24 Sep 2011 20:51:36 +0000 Subject: [PATCH 09/32] Doxygen --- htdocs/core/class/canvas.class.php | 54 +++++++++++++++++------------- 1 file changed, 30 insertions(+), 24 deletions(-) diff --git a/htdocs/core/class/canvas.class.php b/htdocs/core/class/canvas.class.php index e2a9672428a..1a56caeae7c 100644 --- a/htdocs/core/class/canvas.class.php +++ b/htdocs/core/class/canvas.class.php @@ -32,29 +32,28 @@ class Canvas var $db; var $error; var $errors=array(); - + var $actiontype; var $dirmodule; // Module directory var $targetmodule; // Module concerned by canvas (ex: thirdparty, contact, ...) - var $canvas; // Name of canvas + var $canvas; // Name of canvas (ex: company, individual, product, service, ...) var $card; // Tab (sub-canvas) - var $template_dir; // Initialized by getCanvas with templates directory - var $control_file; // Initialized by getCanvas with controller file name - var $control; // Initialized by getCanvas with controller instance - var $object; // Initialized by getCanvas with dao instance, filled by getObject + var $template_dir; // Initialized by getCanvas with templates directory + var $control; // Initialized by getCanvas with controller instance /** * Constructor * - * @param DoliDB $DB Database handler + * @param DoliDB $DB Database handler + * @param string $actiontype Action type ('create', 'view', 'edit', 'list') */ function __construct($DB, $actiontype='view') { $this->db = $DB; - + $this->actiontype = $actiontype; if ($this->actiontype == 'add') $this->actiontype='create'; if ($this->actiontype == 'update') $this->actiontype='edit'; @@ -62,19 +61,16 @@ class Canvas } /** - * Initialize properties: ->targetmodule, ->canvas, ->card - * and MVC properties: ->control (Controller), ->control->object (Model), ->template_dir (View) + * Initialize properties: ->targetmodule, ->canvas, ->card, ->dirmodule, ->template_dir * - * @param module Name of target module (thirdparty, contact, ...) - * @param card Type of card (ex: 'card', 'info', 'contactcard', ...) or '' for a list page - * @param canvas Name of canvas (ex: mycanvas, default, or mycanvas@myexternalmodule) + * @param string $module Name of target module (thirdparty, contact, ...) + * @param string $card Tab name of card (ex: 'card', 'info', 'contactcard', ...) or '' for a list page + * @param string $canvas Name of canvas (ex: mycanvas, default, or mycanvas@myexternalmodule) */ function getCanvas($module, $card, $canvas) { global $conf, $langs; - $error=''; - // Set properties with value specific to dolibarr core: this->targetmodule, this->card, this->canvas $this->targetmodule = $module; $this->canvas = $canvas; @@ -89,6 +85,7 @@ class Canvas // For compatibility if ($this->dirmodule == 'thirdparty') { $this->dirmodule = 'societe'; } + // Control file $controlclassfile = dol_buildpath('/'.$this->dirmodule.'/canvas/'.$this->canvas.'/actions_'.$this->card.'_'.$this->canvas.'.class.php'); if (file_exists($controlclassfile)) { @@ -110,21 +107,31 @@ class Canvas //print 'dimodule='.$dirmodule.' canvas='.$this->canvas.'
'; //print ' => template_dir='.$this->template_dir.'
'; - //print ' => control_file='.$this->control_file.' is_object(this->control)='.is_object($this->control).'
'; return 1; } - + + + /** + * Return if a canvas contains an action controller + * + * @return boolean Return if canvas contains actions (old feature. now actions should be inside hooks) + */ + function hasActions() + { + return (! is_object($this->control)); + } + /** * Shared method for canvas to execute actions - * + * * @param string $action Action string * @param int $id Object id - * @return void + * @return mixed Return return code of doActions of canvas */ function doActions(&$action='view', $id=0) { - if (method_exists($this->control,'doActions')) + if (method_exists($this->control,'doActions')) { $ret = $this->control->doActions($action, $id); return $ret; @@ -133,7 +140,7 @@ class Canvas /** * Shared method for canvas to assign values for templates - * + * * @param string $action Action string * @param int $id Object id * @return void @@ -146,7 +153,7 @@ class Canvas /** * Return the template to display canvas (if it exists) * - * @return string Path to display canvas file if it exists, '' otherwise. + * @return int 0=Canvas template file does not exist, 1=Canvas template file exists */ function displayCanvasExists() { @@ -158,8 +165,7 @@ class Canvas /** * 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. + * Variables used by templates may have been defined or loaded before into the assign_values function. * * @return void */ From 684947ec6059f5c3cb87c380538a1275daf29ae8 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 24 Sep 2011 20:51:36 +0000 Subject: [PATCH 10/32] Doxygen From a41ec9a5befbe7fb476232ae34a9b87a91e5cfc9 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 24 Sep 2011 20:56:08 +0000 Subject: [PATCH 11/32] Doxygen --- htdocs/core/class/canvas.class.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/htdocs/core/class/canvas.class.php b/htdocs/core/class/canvas.class.php index 1a56caeae7c..5e7d4321ca4 100644 --- a/htdocs/core/class/canvas.class.php +++ b/htdocs/core/class/canvas.class.php @@ -66,6 +66,7 @@ class Canvas * @param string $module Name of target module (thirdparty, contact, ...) * @param string $card Tab name of card (ex: 'card', 'info', 'contactcard', ...) or '' for a list page * @param string $canvas Name of canvas (ex: mycanvas, default, or mycanvas@myexternalmodule) + * @return void */ function getCanvas($module, $card, $canvas) { @@ -107,8 +108,6 @@ class Canvas //print 'dimodule='.$dirmodule.' canvas='.$this->canvas.'
'; //print ' => template_dir='.$this->template_dir.'
'; - - return 1; } @@ -125,7 +124,7 @@ class Canvas /** * Shared method for canvas to execute actions * - * @param string $action Action string + * @param string &$action Action string * @param int $id Object id * @return mixed Return return code of doActions of canvas */ @@ -141,7 +140,7 @@ class Canvas /** * Shared method for canvas to assign values for templates * - * @param string $action Action string + * @param string &$action Action string * @param int $id Object id * @return void */ From 08bfeab8241477c6ba8d95c8da1dad632f8e7839 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 24 Sep 2011 21:51:52 +0000 Subject: [PATCH 12/32] Doxygen --- htdocs/fourn/class/fournisseur.product.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/fourn/class/fournisseur.product.class.php b/htdocs/fourn/class/fournisseur.product.class.php index f657fd8c0c3..bf522ab6680 100644 --- a/htdocs/fourn/class/fournisseur.product.class.php +++ b/htdocs/fourn/class/fournisseur.product.class.php @@ -459,8 +459,8 @@ class ProductFournisseur extends Product /** * List all supplier prices of a product * - * @param rowid id du produit - * @return table table de ProductFournisseur + * @param int $rowid id du produit + * @return array Array of ProductFournisseur */ function fetch_product_fournisseur($prodid) { From 20fd93d4ec45d88c7ab6c80f93196004ae0c6987 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 24 Sep 2011 21:52:53 +0000 Subject: [PATCH 13/32] Add file to ignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 6daf64aa0ec..279cf733140 100755 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ default.properties .settings/ .buildpath .gitmodules +dolibarr_install.log From 8aa638220605bdd0badbf9f3d6ea2e68c2440cab Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 24 Sep 2011 21:55:18 +0000 Subject: [PATCH 14/32] Add hidden option PROJECT_CAN_ALWAYS_LINK_TO_ALL_SUPPLIERS --- htdocs/fourn/commande/fiche.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/fourn/commande/fiche.php b/htdocs/fourn/commande/fiche.php index 8efd161e25e..f34716bfc03 100644 --- a/htdocs/fourn/commande/fiche.php +++ b/htdocs/fourn/commande/fiche.php @@ -986,7 +986,7 @@ if ($id > 0 || ! empty($ref)) //print "$object->id, $object->socid, $object->fk_project"; if ($action == 'classify') { - $html->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'projectid'); + $html->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, empty($conf->global->PROJECT_CAN_ALWAYS_LINK_TO_ALL_SUPPLIERS)?$object->socid:'-1', $object->fk_project, 'projectid'); } else { From c58a6adf2e389a5f42a08a77cbe61ede98b9b842 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 24 Sep 2011 22:25:01 +0000 Subject: [PATCH 15/32] Qual: Uniformize code --- htdocs/compta/sociales/index.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/htdocs/compta/sociales/index.php b/htdocs/compta/sociales/index.php index e5db721dead..ec0d6286858 100644 --- a/htdocs/compta/sociales/index.php +++ b/htdocs/compta/sociales/index.php @@ -121,13 +121,11 @@ if ($resql) print_barre_liste($langs->trans("SocialContributions"),$page,$_SERVER["PHP_SELF"],$param,$sortfield,$sortorder,'',$num,$totalnboflines); } - if ($mesg) - { - print $mesg."
"; - } + + dol_htmloutput_mesg($mesg); - if (empty($mysoc->pays_id) && empty($mysoc->pays_code)) + if (empty($mysoc->country_id) && empty($mysoc->country_code)) { print '
'; $langs->load("errors"); From dc41fa50b8cd9337c802b42cc9b03169bc1437c6 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 24 Sep 2011 22:31:28 +0000 Subject: [PATCH 16/32] Fix: Restore obsolete var when they are used as "init". I suggest to remove first all references that are in "read" mode by new name and remove reference that are in "write" mode only once there is no more call to old name in page that used them. This is to reduce risk of bugs. --- htdocs/societe/class/societe.class.php | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index a8d7823341a..36b8bf3a7d0 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -298,7 +298,8 @@ class Societe extends CommonObject $result = 0; $this->name = trim($this->name); - + $this->nom=$this->name; // For backward compatibility + if (! $this->name) { $this->errors[] = 'ErrorBadThirdPartyName'; @@ -393,11 +394,16 @@ class Societe extends CommonObject // Clean parameters $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->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); @@ -407,6 +413,9 @@ class Societe extends CommonObject $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); // TODO obsolete + $this->siret=trim($this->siret); // TODO obsolete + $this->ape=trim($this->ape); // TODO obsolete $this->idprof1 = trim($this->idprof1); $this->idprof2 = trim($this->idprof2); $this->idprof3 = trim($this->idprof3); From ab017e0a72cde79b4a8b3784e4c626465aa1a1a5 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 24 Sep 2011 22:43:52 +0000 Subject: [PATCH 17/32] Qual: Removed warnings --- htdocs/main.inc.php | 74 ++++++++++++++++++++++++++------------------- 1 file changed, 43 insertions(+), 31 deletions(-) diff --git a/htdocs/main.inc.php b/htdocs/main.inc.php index 0e2f6ee691f..59ca0510c23 100644 --- a/htdocs/main.inc.php +++ b/htdocs/main.inc.php @@ -676,7 +676,7 @@ if (! defined('NOLOGIN')) { // If not active, we refuse the user $langs->load("other"); - dol_syslog ("Authentification ko as login is disabled"); + dol_syslog("Authentification ko as login is disabled"); accessforbidden($langs->trans("ErrorLoginDisabled")); exit; } @@ -763,11 +763,13 @@ if (! function_exists("llxHeader")) * @param string $help_url Url links to help page * Syntax is: For a wiki page: EN:EnglishPage|FR:FrenchPage|ES:SpanishPage * For other external page: http://server/url + * @param string $target Target to use on links * @param int $disablejs More content into html header * @param int $disablehead More content into html header * @param array $arrayofjs Array of complementary js files * @param array $arrayofcss Array of complementary css files * @param string $morequerystring Query string to add to the link "print" to get same parameters (use only if autodetect fails) + * @return void */ function llxHeader($head = '', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='') { @@ -781,6 +783,8 @@ if (! function_exists("llxHeader")) /** * Show HTTP header + * + * @return void */ function top_httphead() { @@ -1047,6 +1051,7 @@ function top_htmlhead($head, $title='', $disablejs=0, $disablehead=0, $arrayofjs * @param array $arrayofjs Array of js files to add in header * @param array $arrayofcss Array of css files to add in header * @param string $morequerystring Query string to add to the link "print" to get same parameters (use only if autodetect fails) + * @return void */ function top_menu($head, $title='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='') { @@ -1275,14 +1280,16 @@ function top_menu($head, $title='', $target='', $disablejs=0, $disablehead=0, $a /** * Show left menu bar - * @param menu_array_before Table of menu entries to show before entries of menu handler - * @param helppagename Name of wiki page for help ('' by default). - * Syntax is: For a wiki page: EN:EnglishPage|FR:FrenchPage|ES:SpanishPage - * For other external page: http://server/url - * @param moresearchform Search Form Permanent Supplemental - * @param menu_array_after Table of menu entries to show after entries of menu handler - * @param leftmenuwithoutmainarea Must be set to 1. 0 by default for backward compatibility with old modules. - * @param title Title of web page + * + * @param array $menu_array_before Table of menu entries to show before entries of menu handler + * @param string $helppagename Name of wiki page for help ('' by default). + * Syntax is: For a wiki page: EN:EnglishPage|FR:FrenchPage|ES:SpanishPage + * For other external page: http://server/url + * @param string $moresearchform Search Form Permanent Supplemental + * @param array $menu_array_after Table of menu entries to show after entries of menu handler + * @param int $leftmenuwithoutmainarea Must be set to 1. 0 by default for backward compatibility with old modules. + * @param string $title Title of web page + * @return void */ function left_menu($menu_array_before, $helppagename='', $moresearchform='', $menu_array_after='', $leftmenuwithoutmainarea=0, $title='') { @@ -1305,30 +1312,26 @@ function left_menu($menu_array_before, $helppagename='', $moresearchform='', $me if ($conf->societe->enabled && $conf->global->MAIN_SEARCHFORM_SOCIETE && $user->rights->societe->lire) { $langs->load("companies"); - $searchform.=printSearchForm(DOL_URL_ROOT.'/societe/societe.php', DOL_URL_ROOT.'/societe/societe.php', - img_object('','company').' '.$langs->trans("ThirdParties"), 'soc', 'socname'); + $searchform.=printSearchForm(DOL_URL_ROOT.'/societe/societe.php', DOL_URL_ROOT.'/societe/societe.php', img_object('','company').' '.$langs->trans("ThirdParties"), 'soc', 'socname'); } if ($conf->societe->enabled && $conf->global->MAIN_SEARCHFORM_CONTACT && $user->rights->societe->lire) { $langs->load("companies"); - $searchform.=printSearchForm(DOL_URL_ROOT.'/contact/list.php', DOL_URL_ROOT.'/contact/list.php', - img_object('','contact').' '.$langs->trans("Contacts"), 'contact', 'contactname'); + $searchform.=printSearchForm(DOL_URL_ROOT.'/contact/list.php', DOL_URL_ROOT.'/contact/list.php', img_object('','contact').' '.$langs->trans("Contacts"), 'contact', 'contactname'); } if ((($conf->product->enabled && $user->rights->produit->lire) || ($conf->service->enabled && $user->rights->service->lire)) && $conf->global->MAIN_SEARCHFORM_PRODUITSERVICE) { $langs->load("products"); - $searchform.=printSearchForm(DOL_URL_ROOT.'/product/liste.php', DOL_URL_ROOT.'/product/liste.php', - img_object('','product').' '.$langs->trans("Products")."/".$langs->trans("Services"), 'products', 'sall'); + $searchform.=printSearchForm(DOL_URL_ROOT.'/product/liste.php', DOL_URL_ROOT.'/product/liste.php', img_object('','product').' '.$langs->trans("Products")."/".$langs->trans("Services"), 'products', 'sall'); } if ($conf->adherent->enabled && $conf->global->MAIN_SEARCHFORM_ADHERENT && $user->rights->adherent->lire) { $langs->load("members"); - $searchform.=printSearchForm(DOL_URL_ROOT.'/adherents/liste.php', DOL_URL_ROOT.'/adherents/liste.php', - img_object('','user').' '.$langs->trans("Members"), 'member', 'sall'); + $searchform.=printSearchForm(DOL_URL_ROOT.'/adherents/liste.php', DOL_URL_ROOT.'/adherents/liste.php', img_object('','user').' '.$langs->trans("Members"), 'member', 'sall'); } // Execute hook printSearchForm @@ -1460,8 +1463,12 @@ function left_menu($menu_array_before, $helppagename='', $moresearchform='', $me if (empty($leftmenuwithoutmainarea)) main_area($title); } + /** * Begin main area + * + * @param string $title Title + * @return void */ function main_area($title='') { @@ -1499,8 +1506,10 @@ function main_area($title='') /** * Return helpbaseurl, helppage and mode - * @param helppagename Page name (EN:xxx,ES:eee,FR:fff...) - * @param langs Language + * + * @param string $helppagename Page name (EN:xxx,ES:eee,FR:fff...) + * @param Translate $langs Language + * @return array Array of help urls */ function getHelpParamFor($helppagename,$langs) { @@ -1538,13 +1547,14 @@ function getHelpParamFor($helppagename,$langs) /** * Show a search area * - * @param urlaction Url post - * @param urlobject Url of the link under the search box - * @param title Title search area - * @param htmlmodesearch 'search' - * @param htmlinputname Field Name input form + * @param string $urlaction Url post + * @param string $urlobject Url of the link under the search box + * @param string $title Title search area + * @param string $htmlmodesearch Value to set into parameter "mode_search" ('soc','contact','products','member',...) + * @param string $htmlinputname Field Name input form + * @return void */ -function printSearchForm($urlaction,$urlobject,$title,$htmlmodesearch='search',$htmlinputname) +function printSearchForm($urlaction,$urlobject,$title,$htmlmodesearch,$htmlinputname) { global $conf,$langs; @@ -1567,14 +1577,16 @@ function printSearchForm($urlaction,$urlobject,$title,$htmlmodesearch='search',$ } -/** - * Show HTML footer - * Close div /DIV data-role=page + /DIV class=fiche + /DIV /DIV main layout + /BODY + /HTML - * @param foot A text to add in HTML generated page - */ if (! function_exists("llxFooter")) { - function llxFooter($foot='') + /** + * Show HTML footer + * Close div /DIV data-role=page + /DIV class=fiche + /DIV /DIV main layout + /BODY + /HTML + * + * @param string $foot A text to add in HTML generated page + * @return void + */ + function llxFooter($foot='') { global $conf, $langs, $dolibarr_auto_user, $micro_start_time; From 9e09b162194dd7fa4c71935d9885c3c0b7cf1de0 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 24 Sep 2011 23:42:31 +0000 Subject: [PATCH 18/32] Qual: Uniformize code --- htdocs/fourn/commande/note.php | 178 +++++++++++++++++---------------- htdocs/fourn/facture/note.php | 4 +- 2 files changed, 92 insertions(+), 90 deletions(-) diff --git a/htdocs/fourn/commande/note.php b/htdocs/fourn/commande/note.php index 8951011775b..d0bd737f374 100644 --- a/htdocs/fourn/commande/note.php +++ b/htdocs/fourn/commande/note.php @@ -44,15 +44,15 @@ $result = restrictedArea($user, 'commande_fournisseur', $id,''); if ($_POST["action"] == 'updatenote' && $user->rights->fournisseur->commande->creer) { - $commande = new CommandeFournisseur($db); - $commande->fetch($_GET["id"]); + $commande = new CommandeFournisseur($db); + $commande->fetch($_GET["id"]); - $result = $commande->UpdateNote($user, $_POST["note"], $_POST["note_public"]); - if ($result >= 0) - { - Header("Location: note.php?id=".$_GET["id"]); - exit; - } + $result = $commande->UpdateNote($user, $_POST["note"], $_POST["note_public"]); + if ($result >= 0) + { + Header("Location: note.php?id=".$_GET["id"]); + exit; + } } @@ -76,103 +76,105 @@ $id = $_GET['id']; $ref= $_GET['ref']; if ($id > 0 || ! empty($ref)) { - $commande = new CommandeFournisseur($db); - $result=$commande->fetch($_GET["id"],$_GET['ref']); - if ($result >= 0) - { - $soc = new Societe($db); - $soc->fetch($commande->socid); + $commande = new CommandeFournisseur($db); + $result=$commande->fetch($_GET["id"],$_GET['ref']); + if ($result >= 0) + { + $soc = new Societe($db); + $soc->fetch($commande->socid); - $author = new User($db); - $author->fetch($commande->user_author_id); + $author = new User($db); + $author->fetch($commande->user_author_id); - $head = ordersupplier_prepare_head($commande); + $head = ordersupplier_prepare_head($commande); - $title=$langs->trans("SupplierOrder"); - dol_fiche_head($head, 'note', $title, 0, 'order'); + $title=$langs->trans("SupplierOrder"); + dol_fiche_head($head, 'note', $title, 0, 'order'); - /* - * Commande - */ - print '
'; - print ''; - print ''; + /* + * Commande + */ + print ''; + print ''; + print ''; - print ''; + print '
'; - // Ref - print ''; - print ''; - print ''; + // Ref + print ''; + print ''; + print ''; - // Fournisseur - print '"; - print ''; - print ''; + // Fournisseur + print '"; + print ''; + print ''; - // Statut - print ''; - print ''; - print '"; + // Statut + print ''; + print ''; + print '"; - // Date - if ($commande->methode_commande_id > 0) - { - print '"; + // Date + if ($commande->methode_commande_id > 0) + { + print '"; - if ($commande->methode_commande) - { - print ''; - } - } + if ($commande->methode_commande) + { + print ''; + } + } - // Auteur - print ''; - print ''; - print ''; + // Auteur + print ''; + print ''; + print ''; - print ''; - print ''; + print ''; + print ''; - if (! $user->societe_id) - { - print ''; - print ''; - } + if (! $user->societe_id) + { + print ''; + print ''; + } - if ($user->rights->fournisseur->commande->creer) - { - print ''; - } + print "
'.$langs->trans("Ref").''; - print $html->showrefnav($commande,'ref','',1,'ref','ref'); - print '
'.$langs->trans("Ref").''; + print $html->showrefnav($commande,'ref','',1,'ref','ref'); + print '
'.$langs->trans("Supplier")."'.$soc->getNomUrl(1,'supplier').'
'.$langs->trans("Supplier")."'.$soc->getNomUrl(1,'supplier').'
'.$langs->trans("Status").''; - print $commande->getLibStatut(4); - print "
'.$langs->trans("Status").''; + print $commande->getLibStatut(4); + print "
'.$langs->trans("Date").''; - if ($commande->date_commande) - { - print dol_print_date($commande->date_commande,"dayhourtext")."\n"; - } - print "
'.$langs->trans("Date").''; + if ($commande->date_commande) + { + print dol_print_date($commande->date_commande,"dayhourtext")."\n"; + } + print "
'.$langs->trans("Method").''.$commande->methode_commande.'
'.$langs->trans("Method").''.$commande->methode_commande.'
'.$langs->trans("AuthorRequest").''.$author->getNomUrl(1).'
'.$langs->trans("AuthorRequest").''.$author->getNomUrl(1).'
'.$langs->trans("NotePublic").''; - if ($user->rights->fournisseur->commande->creer) print ''; - print '
'.$langs->trans("NotePublic").''; + if ($user->rights->fournisseur->commande->creer) print ''; + print '
'.$langs->trans("NotePrivate").''; - if ($user->rights->fournisseur->commande->creer) print ''; - print '
'.$langs->trans("NotePrivate").''; + if ($user->rights->fournisseur->commande->creer) print ''; + print '
"; - print "
"; + if ($user->rights->fournisseur->commande->creer) + { + print '

'; + } - print "
\n"; - } - else - { - /* Order not found */ - $langs->load("errors"); - print $langs->trans("ErrorRecordNotFound"); - } + print ""; + + dol_fiche_end(); + } + else + { + /* Order not found */ + $langs->load("errors"); + print $langs->trans("ErrorRecordNotFound"); + } } diff --git a/htdocs/fourn/facture/note.php b/htdocs/fourn/facture/note.php index 724edb40c91..e8af8fe7fc1 100644 --- a/htdocs/fourn/facture/note.php +++ b/htdocs/fourn/facture/note.php @@ -130,7 +130,7 @@ if ($_GET["facid"]) } print ""; - // Note priv�e + // Note private if (! $user->societe_id) { print ''.$langs->trans("NotePrivate").' :'; @@ -153,11 +153,11 @@ if ($_GET["facid"]) print ""; + dol_fiche_end(); /* * Actions */ - print ''; print '
'; if ($user->rights->fournisseur->facture->creer && $_GET["action"] <> 'edit') From 78ac6060f51c1d65bb27aad53c1c91914a46afe6 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 24 Sep 2011 23:49:45 +0000 Subject: [PATCH 19/32] Move dev module mantis to nltechno repository --- htdocs/includes/modules/modMantis.class.php | 132 ------------- htdocs/mantis/admin/mantis.php | 206 -------------------- htdocs/mantis/class/mantis.class.php | 68 ------- htdocs/mantis/index.php | 1 - htdocs/mantis/mantis.php | 68 ------- htdocs/mantis/mantistop.php | 39 ---- 6 files changed, 514 deletions(-) delete mode 100644 htdocs/includes/modules/modMantis.class.php delete mode 100644 htdocs/mantis/admin/mantis.php delete mode 100644 htdocs/mantis/class/mantis.class.php delete mode 100644 htdocs/mantis/index.php delete mode 100644 htdocs/mantis/mantis.php delete mode 100644 htdocs/mantis/mantistop.php diff --git a/htdocs/includes/modules/modMantis.class.php b/htdocs/includes/modules/modMantis.class.php deleted file mode 100644 index 239dab8abb7..00000000000 --- a/htdocs/includes/modules/modMantis.class.php +++ /dev/null @@ -1,132 +0,0 @@ - - * Copyright (C) 2004-2007 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 - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -/** - * \defgroup mantis Module mantis - * \brief Module to include Mantis into Dolibarr - * \file htdocs/includes/modules/modMantis.class.php - * \ingroup mantis - * \brief Description and activation file for module Mantis - */ - -include_once(DOL_DOCUMENT_ROOT ."/includes/modules/DolibarrModules.class.php"); - - -/** - * \class modMantis - * \brief Description and activation class for module Mantis - */ - -class modMantis extends DolibarrModules -{ - - /** - * \brief Constructor. Define names, constants, directories, boxes, permissions - * \param DB Database handler - */ - function modMantis($DB) - { - $this->db = $DB; - - // Id for module (must be unique). - // Use here a free id. - $this->numero = 50300; - - // Family can be 'crm','financial','hr','projects','product','technic','other' - // It is used to sort modules in module setup page - $this->family = "projects"; - // Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module) - $this->name = preg_replace('/^mod/i','',get_class($this)); - // Module description used translation string 'ModuleXXXDesc' not found (XXX is id value) - $this->description = "Interfacage avec le bug tracking Mantis"; - // Possible values for version are: 'experimental' or 'dolibarr' or version - $this->version = 'development'; - // Id used in llx_const table to manage module status (enabled/disabled) - $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name); - // Where to store the module in setup page (0=common,1=interface,2=other) - $this->special = 1; - // Name of png file (without png) used for this module - $this->picto='calendar'; - - // Data directories to create when module is enabled - $this->dirs = array(); - - // Config pages - $this->config_page_url = array("mantis.php@mantis"); - - // Dependencies - $this->depends = array(); // List of modules id that must be enabled - $this->requiredby = array(); // List of modules id to disable if this one is disabled - - // Constants - $this->const = array(); // List of parameters - - // Boxes - $this->boxes = array(); // List of boxes - - // Permissions - $this->rights_class = 'mantis'; // Permission key - $this->rights = array(); // Permission array used by this module - - // Menus - //------ - $r=0; - - $this->menu[$r]=array('fk_menu'=>0, - 'type'=>'top', - 'titre'=>'BugTracker', - 'mainmenu'=>'mantis', - 'leftmenu'=>'1', - 'url'=>'/mantis/mantis.php', - 'langs'=>'other', - 'position'=>100, - 'enabled'=>'$conf->mantis->enabled', - 'perms'=>'', - 'target'=>'', - 'user'=>0); - $r++; - - } - - /** - * \brief Function called when module is enabled. - * Add constants, boxes and permissions into Dolibarr database. - * It also creates data directories. - */ - function init() - { - $sql = array(); - - return $this->_init($sql); - } - - /** - * \brief Function called when module is disabled. - * Remove from database constants, boxes and permissions from Dolibarr database. - * Data directories are not deleted. - */ - function remove() - { - $sql = array(); - - return $this->_remove($sql); - } - -} - -?> diff --git a/htdocs/mantis/admin/mantis.php b/htdocs/mantis/admin/mantis.php deleted file mode 100644 index c26cc6ba146..00000000000 --- a/htdocs/mantis/admin/mantis.php +++ /dev/null @@ -1,206 +0,0 @@ - - * Copyright (C) 2003 �ric Seigne - * Copyright (C) 2004-2008 Laurent Destailleur - * Copyright (C) 2004 Sebastien Di Cintio - * Copyright (C) 2004 Benoit Mortier - * - * 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 - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -/** - * \file htdocs/mantis/admin/mantis.php - * \ingroup mantis - * \brief Page de configuration du module mantis - */ - -require("../../main.inc.php"); -require_once(DOL_DOCUMENT_ROOT."/lib/admin.lib.php"); -require_once(DOL_DOCUMENT_ROOT.'/mantis/class/mantis.class.php'); - - -if (!$user->admin) - accessforbidden(); - - -$langs->load("admin"); -$langs->load("other"); - -$def = array(); -$actiontest=$_POST["test"]; -$actionsave=$_POST["save"]; - -// Sauvegardes parametres -if ($actionsave) -{ - $i=0; - - $db->begin(); - - $i+=dolibarr_set_const($db,'PHPMANTIS_URL',trim($_POST["phpmantis_url"]),'chaine',0,'',$conf->entity); - $i+=dolibarr_set_const($db,'PHPMANTIS_HOST',trim($_POST["phpmantis_host"]),'chaine',0,'',$conf->entity); - $i+=dolibarr_set_const($db,'PHPMANTIS_DBNAME',trim($_POST["phpmantis_dbname"]),'chaine',0,'',$conf->entity); - $i+=dolibarr_set_const($db,'PHPMANTIS_USER',trim($_POST["phpmantis_user"]),'chaine',0,'',$conf->entity); - $i+=dolibarr_set_const($db,'PHPMANTIS_PASS',trim($_POST["phpmantis_pass"]),'chaine',0,'',$conf->entity); - - if ($i >= 5) - { - $db->commit(); - $mesg = "".$langs->trans("MantisSetupSaved").""; - } - else - { - $db->rollback(); - header("Location: ".$_SERVER["PHP_SELF"]); - exit; - } -} -elseif ($actiontest) -{ - //$resql=$db->query("select count(*) from llx_const"); - //print "< ".$db." - ".$db->db." - ".$resql." - ".$db->error().">
\n"; - - // Test de la connexion a la database mantis - $conf->mantis->db->type=$dolibarr_main_db_type; - $conf->mantis->db->host=$_POST["phpmantis_host"]; - $conf->mantis->db->port=$_POST["phpmantis_port"]; - $conf->mantis->db->user=$_POST["phpmantis_user"]; - $conf->mantis->db->pass=$_POST["phpmantis_pass"]; - $conf->mantis->db->name=$_POST["phpmantis_dbname"]; - - $mantis=new Mantis(); - - //print "D ".$db." - ".$db->db."
\n"; - //print "W ".$mantis->localdb." - ".$mantis->localdb->db."
\n"; - - if ($mantis->localdb->connected == 1 && $mantis->localdb->database_selected == 1) - { - // V�rifie si bonne base - $sql="SELECT value FROM mantis_config_table WHERE config_id='database_version'"; - $resql=$mantis->localdb->query($sql); - if ($resql) { - $mesg ="
"; - $mesg.=$langs->trans("MantisTestOk",$_POST["phpmantis_host"],$_POST["phpmantis_dbname"],$_POST["phpmantis_user"]); - $mesg.="
"; - } - else { - $mesg ="
"; - $mesg.=$langs->trans("MantisErrorConnectOkButWrongDatabase"); - $mesg.="
"; - } - - //$mantis->localdb->close(); Ne pas fermer car la conn de mantis est la meme que dolibarr si parametre host/user/pass identique - } - elseif ($mantis->connected == 1 && $mantis->database_selected != 1) - { - $mesg ="
".$langs->trans("MantisTestKo1",$_POST["phpmantis_host"],$_POST["phpmantis_dbname"]); - $mesg.="
".$mantis->localdb->error(); - $mesg.="
"; - //$mantis->localdb->close(); Ne pas fermer car la conn de mantis est la meme que dolibarr si parametre host/user/pass identique - } - else - { - $mesg ="
".$langs->trans("MantisTestKo2",$_POST["phpmantis_host"],$_POST["phpmantis_user"]); - $mesg.="
".$mantis->localdb->error(); - $mesg.="
"; - } - - //$resql=$db->query("select count(*) from llx_const"); - //print "< ".$db." - ".$db->db." - ".$resql." - ".$db->error().">
\n"; -} - - -/** - * Affichage du formulaire de saisie - */ - -llxHeader(); - -$linkback=''.$langs->trans("BackToModuleList").''; -print_fiche_titre($langs->trans("MantisSetup"),$linkback,'setup'); -print '
'; - - -print '
'; -print ''; -print ""; - -print ""; -print ""; -print ""; -print ""; -print ""; - -print ""; -print ""; -print ""; -print ""; -print ""; - -print ""; -print ""; -print ""; -print ""; -print ""; - -print ""; -print ""; -print ""; -print ""; -print ""; - -print ""; -print ""; -print ""; -print ""; -print ""; - -print ""; -print ""; -print ""; -print ''; -print ""; - -print "
".$langs->trans("Parameter")."".$langs->trans("Value")."".$langs->trans("Examples")."
".$langs->trans("MantisURL")."global->PHPMANTIS_URL) . "\" size=\"40\">http://localhost/mantis/"; -print "
https://mantisserver/"; -print "
".$langs->trans("MantisServer")."global->PHPMANTIS_HOST) . "\" size=\"30\">localhost"; -//print "
__dolibarr_main_db_host__ (".$dolibarr_main_db_host.")" -print "
".$langs->trans("MantisDatabaseName")."global->PHPMANTIS_DBNAME) . "\" size=\"30\">bugtracker"; -//print "
__dolibarr_main_db_name__ (".$dolibarr_main_db_name.")"; -print "
".$langs->trans("MantisUser")."global->PHPMANTIS_USER) . "\" size=\"30\">mantis"; -//print "
__dolibarr_main_db_user__ (".$dolibarr_main_db_user.")"; -print "
".$langs->trans("Password")."global->PHPMANTIS_PASS) . "\" size=\"30\">'; -//if ($dolibarr_main_db_pass) print '__dolibarr_main_db_pass__ ('.preg_replace('/./i','*',$dolibarr_main_db_pass).')'; -print ' 
"; - - -print '
'; -print "trans("TestConnection")."\">"; -print "   "; -print "trans("Save")."\">"; -print "
"; - -print "
\n"; - - -clearstatcache(); - -if ($mesg) print "
$mesg
"; -print "
"; - -$db->close(); - -llxFooter(); -?> diff --git a/htdocs/mantis/class/mantis.class.php b/htdocs/mantis/class/mantis.class.php deleted file mode 100644 index 53c2c715852..00000000000 --- a/htdocs/mantis/class/mantis.class.php +++ /dev/null @@ -1,68 +0,0 @@ - - * Copyright (C) 2004-2008 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 - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -/** - * \file htdocs/mantis/class/mantis.class.php - * \ingroup mantis - * \brief Ensemble des fonctions permettant d'acceder a la database mantis. - * \author Laurent Destailleur. - */ - - -/** - * \class Mantis - * \brief Classe permettant d'acceder a la database mantis - */ - -class Mantis { - - var $localdb; - - var $date; - var $duree = 0; // Secondes - var $texte; - var $desc; - - var $error; - - - /** - \brief Constructeur de la classe d'interface a mantisendar - */ - function Mantis() - { - global $conf; - global $dolibarr_main_db_type,$dolibarr_main_db_host,$dolibarr_main_db_user; - global $dolibarr_main_db_pass,$dolibarr_main_db_name; - - // Defini parametres mantis (avec substitution eventuelle) - $mantistype=preg_replace('/__dolibarr_main_db_type__/i',$dolibarr_main_db_type,$conf->mantis->db->type); - $mantishost=preg_replace('/__dolibarr_main_db_host__/i',$dolibarr_main_db_host,$conf->mantis->db->host); - $mantisport=preg_replace('/__dolibarr_main_db_port__/i',$dolibarr_main_db_port,$conf->mantis->db->port); - $mantisuser=preg_replace('/__dolibarr_main_db_user__/i',$dolibarr_main_db_user,$conf->mantis->db->user); - $mantispass=preg_replace('/__dolibarr_main_db_pass__/i',$dolibarr_main_db_pass,$conf->mantis->db->pass); - $mantisname=preg_replace('/__dolibarr_main_db_name__/i',$dolibarr_main_db_name,$conf->mantis->db->name); - - // On initie la connexion a la base mantisendar - require_once (DOL_DOCUMENT_ROOT ."/lib/databases/".$mantistype.".lib.php"); - $this->localdb = new DoliDb($mantistype,$mantishost,$mantisuser,$mantispass,$mantisname,$mantisport); - } - -} -?> diff --git a/htdocs/mantis/index.php b/htdocs/mantis/index.php deleted file mode 100644 index 7db0dd9ebf9..00000000000 --- a/htdocs/mantis/index.php +++ /dev/null @@ -1 +0,0 @@ -Url not available \ No newline at end of file diff --git a/htdocs/mantis/mantis.php b/htdocs/mantis/mantis.php deleted file mode 100644 index 707517133a1..00000000000 --- a/htdocs/mantis/mantis.php +++ /dev/null @@ -1,68 +0,0 @@ - - * - * 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 - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -/** - * \file htdocs/mantis/mantis.php - * \ingroup mantis - * \brief Page generant 2 frames, une pour le menu Dolibarr, l'autre pour l'affichage de Mantis - * \author Laurent Destailleur - */ - -require("../main.inc.php"); - -if (empty($conf->global->PHPMANTIS_URL)) -{ - llxHeader(); - print '
Module Mantis was not configured properly.
'; - llxFooter(); -} - -$mainmenu=isset($_GET["mainmenu"])?$_GET["mainmenu"]:""; -$leftmenu=isset($_GET["leftmenu"])?$_GET["leftmenu"]:""; -$idmenu=isset($_GET["idmenu"])?$_GET["idmenu"]:""; - -print " - - -Dolibarr frame for Mantis - - - - - global->PHPMANTIS_URL."\"> - - <body> - - </body> - - - - -<body> - <br><center> - Sorry, your browser is too old or not correctly configured to view this area.<br> - Your browser must support frames.<br> - </center> -</body> - - - -"; - - -?> diff --git a/htdocs/mantis/mantistop.php b/htdocs/mantis/mantistop.php deleted file mode 100644 index 7020b1b93d0..00000000000 --- a/htdocs/mantis/mantistop.php +++ /dev/null @@ -1,39 +0,0 @@ - - * - * 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 - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -/** - * \file htdocs/mantis/mantistop.php - * \ingroup mantis - * \brief Top frame to show mantis application - */ - -require ("../main.inc.php"); - -top_htmlhead("",""); -top_menu("","","_top"); - -?> - - - - - - - - - - From 8d900740fc294aacb4a5665bb8132ab5f9690aa5 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Sat, 24 Sep 2011 15:57:52 +0000 Subject: [PATCH 20/32] Fix: broken canvas --- .../actions_contactcard_common.class.php | 2 +- htdocs/contact/fiche.php | 8 +-- htdocs/core/class/canvas.class.php | 61 +++++++++---------- htdocs/societe/class/societe.class.php | 21 ++----- htdocs/societe/soc.php | 11 +--- 5 files changed, 39 insertions(+), 64 deletions(-) diff --git a/htdocs/contact/canvas/actions_contactcard_common.class.php b/htdocs/contact/canvas/actions_contactcard_common.class.php index 6f7ceced553..9e8d17fa718 100644 --- a/htdocs/contact/canvas/actions_contactcard_common.class.php +++ b/htdocs/contact/canvas/actions_contactcard_common.class.php @@ -54,7 +54,7 @@ abstract class ActionsContactCardCommon function __construct($DB, $dirmodule, $targetmodule, $canvas, $card) { $this->db = $DB; - $this->dirmodule = $dirmodule; + $this->dirmodule = $targetmodule; $this->targetmodule = $targetmodule; $this->canvas = $canvas; $this->card = $card; diff --git a/htdocs/contact/fiche.php b/htdocs/contact/fiche.php index 745d0c3d6e7..4f66bbdfc92 100644 --- a/htdocs/contact/fiche.php +++ b/htdocs/contact/fiche.php @@ -277,11 +277,7 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists()) // ----------------------------------------- // When used with CANVAS // ----------------------------------------- - if (! $objcanvas->hasActions() && $id) - { - $object = new Societe($db); - $object->fetch($id); // For use with "pure canvas" (canvas that contains templates only) - } + $objcanvas->assign_values($action, $id); // Set value for templates $objcanvas->display_canvas(); // Show template } @@ -328,8 +324,6 @@ else /* * Fiche en mode creation */ - $object->canvas=$canvas; - $object->fk_departement = $_POST["departement_id"]; // We set pays_id, pays_code and label for the selected country diff --git a/htdocs/core/class/canvas.class.php b/htdocs/core/class/canvas.class.php index 5e7d4321ca4..e2a9672428a 100644 --- a/htdocs/core/class/canvas.class.php +++ b/htdocs/core/class/canvas.class.php @@ -32,28 +32,29 @@ class Canvas var $db; var $error; var $errors=array(); - + var $actiontype; var $dirmodule; // Module directory var $targetmodule; // Module concerned by canvas (ex: thirdparty, contact, ...) - var $canvas; // Name of canvas (ex: company, individual, product, service, ...) + var $canvas; // Name of canvas var $card; // Tab (sub-canvas) - var $template_dir; // Initialized by getCanvas with templates directory - var $control; // Initialized by getCanvas with controller instance + var $template_dir; // Initialized by getCanvas with templates directory + var $control_file; // Initialized by getCanvas with controller file name + var $control; // Initialized by getCanvas with controller instance + var $object; // Initialized by getCanvas with dao instance, filled by getObject /** * Constructor * - * @param DoliDB $DB Database handler - * @param string $actiontype Action type ('create', 'view', 'edit', 'list') + * @param DoliDB $DB Database handler */ function __construct($DB, $actiontype='view') { $this->db = $DB; - + $this->actiontype = $actiontype; if ($this->actiontype == 'add') $this->actiontype='create'; if ($this->actiontype == 'update') $this->actiontype='edit'; @@ -61,17 +62,19 @@ class Canvas } /** - * Initialize properties: ->targetmodule, ->canvas, ->card, ->dirmodule, ->template_dir + * Initialize properties: ->targetmodule, ->canvas, ->card + * and MVC properties: ->control (Controller), ->control->object (Model), ->template_dir (View) * - * @param string $module Name of target module (thirdparty, contact, ...) - * @param string $card Tab name of card (ex: 'card', 'info', 'contactcard', ...) or '' for a list page - * @param string $canvas Name of canvas (ex: mycanvas, default, or mycanvas@myexternalmodule) - * @return void + * @param module Name of target module (thirdparty, contact, ...) + * @param card Type of card (ex: 'card', 'info', 'contactcard', ...) or '' for a list page + * @param canvas Name of canvas (ex: mycanvas, default, or mycanvas@myexternalmodule) */ function getCanvas($module, $card, $canvas) { global $conf, $langs; + $error=''; + // Set properties with value specific to dolibarr core: this->targetmodule, this->card, this->canvas $this->targetmodule = $module; $this->canvas = $canvas; @@ -86,7 +89,6 @@ class Canvas // For compatibility if ($this->dirmodule == 'thirdparty') { $this->dirmodule = 'societe'; } - // Control file $controlclassfile = dol_buildpath('/'.$this->dirmodule.'/canvas/'.$this->canvas.'/actions_'.$this->card.'_'.$this->canvas.'.class.php'); if (file_exists($controlclassfile)) { @@ -108,29 +110,21 @@ class Canvas //print 'dimodule='.$dirmodule.' canvas='.$this->canvas.'
'; //print ' => template_dir='.$this->template_dir.'
'; + //print ' => control_file='.$this->control_file.' is_object(this->control)='.is_object($this->control).'
'; + + return 1; } - - - /** - * Return if a canvas contains an action controller - * - * @return boolean Return if canvas contains actions (old feature. now actions should be inside hooks) - */ - function hasActions() - { - return (! is_object($this->control)); - } - + /** * Shared method for canvas to execute actions - * - * @param string &$action Action string + * + * @param string $action Action string * @param int $id Object id - * @return mixed Return return code of doActions of canvas + * @return void */ function doActions(&$action='view', $id=0) { - if (method_exists($this->control,'doActions')) + if (method_exists($this->control,'doActions')) { $ret = $this->control->doActions($action, $id); return $ret; @@ -139,8 +133,8 @@ class Canvas /** * Shared method for canvas to assign values for templates - * - * @param string &$action Action string + * + * @param string $action Action string * @param int $id Object id * @return void */ @@ -152,7 +146,7 @@ class Canvas /** * Return the template to display canvas (if it exists) * - * @return int 0=Canvas template file does not exist, 1=Canvas template file exists + * @return string Path to display canvas file if it exists, '' otherwise. */ function displayCanvasExists() { @@ -164,7 +158,8 @@ class Canvas /** * Display a canvas page. This will include the template for output. - * Variables used by templates may have been defined or loaded before into the assign_values function. + * Variables used by templates may have been defined, loaded before + * into the assign_values function. * * @return void */ diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index 36b8bf3a7d0..a8d7823341a 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -298,8 +298,7 @@ class Societe extends CommonObject $result = 0; $this->name = trim($this->name); - $this->nom=$this->name; // For backward compatibility - + if (! $this->name) { $this->errors[] = 'ErrorBadThirdPartyName'; @@ -394,16 +393,11 @@ class Societe extends CommonObject // 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->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); @@ -413,9 +407,6 @@ class Societe extends CommonObject $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); // TODO obsolete - $this->siret=trim($this->siret); // TODO obsolete - $this->ape=trim($this->ape); // TODO obsolete $this->idprof1 = trim($this->idprof1); $this->idprof2 = trim($this->idprof2); $this->idprof3 = trim($this->idprof3); diff --git a/htdocs/societe/soc.php b/htdocs/societe/soc.php index 66097323008..b289e334c60 100644 --- a/htdocs/societe/soc.php +++ b/htdocs/societe/soc.php @@ -104,7 +104,6 @@ if (empty($reshook)) require_once(DOL_DOCUMENT_ROOT."/lib/functions2.lib.php"); if ($action == 'update') $object->fetch($socid); - else $object->canvas=$canvas; if (GETPOST("private") == 1) { @@ -475,13 +474,9 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists()) // ----------------------------------------- // When used with CANVAS // ----------------------------------------- - if (! $objcanvas->hasActions() && $socid) - { - $object = new Societe($db); - $object->fetch($socid); // For use with "pure canvas" (canvas that contains templates only) - } - $objcanvas->assign_values($action, $socid); // Set value for templates - $objcanvas->display_canvas(); // Show template + + $objcanvas->assign_values($action, $socid); // Set value for templates + $objcanvas->display_canvas(); // Show template } else { From b306a41811b16d028a43506145a186959ddb9a12 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Sat, 24 Sep 2011 16:06:07 +0000 Subject: [PATCH 21/32] Fix: bad name --- htdocs/contact/canvas/actions_contactcard_common.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/contact/canvas/actions_contactcard_common.class.php b/htdocs/contact/canvas/actions_contactcard_common.class.php index 9e8d17fa718..6f7ceced553 100644 --- a/htdocs/contact/canvas/actions_contactcard_common.class.php +++ b/htdocs/contact/canvas/actions_contactcard_common.class.php @@ -54,7 +54,7 @@ abstract class ActionsContactCardCommon function __construct($DB, $dirmodule, $targetmodule, $canvas, $card) { $this->db = $DB; - $this->dirmodule = $targetmodule; + $this->dirmodule = $dirmodule; $this->targetmodule = $targetmodule; $this->canvas = $canvas; $this->card = $card; From af2e30010064d9d08b95fa0321c163b2ac3fdf2b Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 24 Sep 2011 20:50:57 +0000 Subject: [PATCH 22/32] Fix: Little fix after canvas changes to be able to have "pure canvas" (canvas with no controller, only templates). --- htdocs/contact/fiche.php | 8 +++++++- htdocs/societe/soc.php | 11 ++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/htdocs/contact/fiche.php b/htdocs/contact/fiche.php index 4f66bbdfc92..745d0c3d6e7 100644 --- a/htdocs/contact/fiche.php +++ b/htdocs/contact/fiche.php @@ -277,7 +277,11 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists()) // ----------------------------------------- // When used with CANVAS // ----------------------------------------- - + if (! $objcanvas->hasActions() && $id) + { + $object = new Societe($db); + $object->fetch($id); // For use with "pure canvas" (canvas that contains templates only) + } $objcanvas->assign_values($action, $id); // Set value for templates $objcanvas->display_canvas(); // Show template } @@ -324,6 +328,8 @@ else /* * Fiche en mode creation */ + $object->canvas=$canvas; + $object->fk_departement = $_POST["departement_id"]; // We set pays_id, pays_code and label for the selected country diff --git a/htdocs/societe/soc.php b/htdocs/societe/soc.php index b289e334c60..66097323008 100644 --- a/htdocs/societe/soc.php +++ b/htdocs/societe/soc.php @@ -104,6 +104,7 @@ if (empty($reshook)) require_once(DOL_DOCUMENT_ROOT."/lib/functions2.lib.php"); if ($action == 'update') $object->fetch($socid); + else $object->canvas=$canvas; if (GETPOST("private") == 1) { @@ -474,9 +475,13 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists()) // ----------------------------------------- // When used with CANVAS // ----------------------------------------- - - $objcanvas->assign_values($action, $socid); // Set value for templates - $objcanvas->display_canvas(); // Show template + if (! $objcanvas->hasActions() && $socid) + { + $object = new Societe($db); + $object->fetch($socid); // For use with "pure canvas" (canvas that contains templates only) + } + $objcanvas->assign_values($action, $socid); // Set value for templates + $objcanvas->display_canvas(); // Show template } else { From 2386315c57eda6bf0611db5b0397a20edc5d6e75 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 24 Sep 2011 20:51:36 +0000 Subject: [PATCH 23/32] Doxygen --- htdocs/core/class/canvas.class.php | 54 +++++++++++++++++------------- 1 file changed, 30 insertions(+), 24 deletions(-) diff --git a/htdocs/core/class/canvas.class.php b/htdocs/core/class/canvas.class.php index e2a9672428a..1a56caeae7c 100644 --- a/htdocs/core/class/canvas.class.php +++ b/htdocs/core/class/canvas.class.php @@ -32,29 +32,28 @@ class Canvas var $db; var $error; var $errors=array(); - + var $actiontype; var $dirmodule; // Module directory var $targetmodule; // Module concerned by canvas (ex: thirdparty, contact, ...) - var $canvas; // Name of canvas + var $canvas; // Name of canvas (ex: company, individual, product, service, ...) var $card; // Tab (sub-canvas) - var $template_dir; // Initialized by getCanvas with templates directory - var $control_file; // Initialized by getCanvas with controller file name - var $control; // Initialized by getCanvas with controller instance - var $object; // Initialized by getCanvas with dao instance, filled by getObject + var $template_dir; // Initialized by getCanvas with templates directory + var $control; // Initialized by getCanvas with controller instance /** * Constructor * - * @param DoliDB $DB Database handler + * @param DoliDB $DB Database handler + * @param string $actiontype Action type ('create', 'view', 'edit', 'list') */ function __construct($DB, $actiontype='view') { $this->db = $DB; - + $this->actiontype = $actiontype; if ($this->actiontype == 'add') $this->actiontype='create'; if ($this->actiontype == 'update') $this->actiontype='edit'; @@ -62,19 +61,16 @@ class Canvas } /** - * Initialize properties: ->targetmodule, ->canvas, ->card - * and MVC properties: ->control (Controller), ->control->object (Model), ->template_dir (View) + * Initialize properties: ->targetmodule, ->canvas, ->card, ->dirmodule, ->template_dir * - * @param module Name of target module (thirdparty, contact, ...) - * @param card Type of card (ex: 'card', 'info', 'contactcard', ...) or '' for a list page - * @param canvas Name of canvas (ex: mycanvas, default, or mycanvas@myexternalmodule) + * @param string $module Name of target module (thirdparty, contact, ...) + * @param string $card Tab name of card (ex: 'card', 'info', 'contactcard', ...) or '' for a list page + * @param string $canvas Name of canvas (ex: mycanvas, default, or mycanvas@myexternalmodule) */ function getCanvas($module, $card, $canvas) { global $conf, $langs; - $error=''; - // Set properties with value specific to dolibarr core: this->targetmodule, this->card, this->canvas $this->targetmodule = $module; $this->canvas = $canvas; @@ -89,6 +85,7 @@ class Canvas // For compatibility if ($this->dirmodule == 'thirdparty') { $this->dirmodule = 'societe'; } + // Control file $controlclassfile = dol_buildpath('/'.$this->dirmodule.'/canvas/'.$this->canvas.'/actions_'.$this->card.'_'.$this->canvas.'.class.php'); if (file_exists($controlclassfile)) { @@ -110,21 +107,31 @@ class Canvas //print 'dimodule='.$dirmodule.' canvas='.$this->canvas.'
'; //print ' => template_dir='.$this->template_dir.'
'; - //print ' => control_file='.$this->control_file.' is_object(this->control)='.is_object($this->control).'
'; return 1; } - + + + /** + * Return if a canvas contains an action controller + * + * @return boolean Return if canvas contains actions (old feature. now actions should be inside hooks) + */ + function hasActions() + { + return (! is_object($this->control)); + } + /** * Shared method for canvas to execute actions - * + * * @param string $action Action string * @param int $id Object id - * @return void + * @return mixed Return return code of doActions of canvas */ function doActions(&$action='view', $id=0) { - if (method_exists($this->control,'doActions')) + if (method_exists($this->control,'doActions')) { $ret = $this->control->doActions($action, $id); return $ret; @@ -133,7 +140,7 @@ class Canvas /** * Shared method for canvas to assign values for templates - * + * * @param string $action Action string * @param int $id Object id * @return void @@ -146,7 +153,7 @@ class Canvas /** * Return the template to display canvas (if it exists) * - * @return string Path to display canvas file if it exists, '' otherwise. + * @return int 0=Canvas template file does not exist, 1=Canvas template file exists */ function displayCanvasExists() { @@ -158,8 +165,7 @@ class Canvas /** * 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. + * Variables used by templates may have been defined or loaded before into the assign_values function. * * @return void */ From 5a9acc9009057583b66b5de1e427f09124269dd8 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 24 Sep 2011 20:56:08 +0000 Subject: [PATCH 24/32] Doxygen --- htdocs/core/class/canvas.class.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/htdocs/core/class/canvas.class.php b/htdocs/core/class/canvas.class.php index 1a56caeae7c..5e7d4321ca4 100644 --- a/htdocs/core/class/canvas.class.php +++ b/htdocs/core/class/canvas.class.php @@ -66,6 +66,7 @@ class Canvas * @param string $module Name of target module (thirdparty, contact, ...) * @param string $card Tab name of card (ex: 'card', 'info', 'contactcard', ...) or '' for a list page * @param string $canvas Name of canvas (ex: mycanvas, default, or mycanvas@myexternalmodule) + * @return void */ function getCanvas($module, $card, $canvas) { @@ -107,8 +108,6 @@ class Canvas //print 'dimodule='.$dirmodule.' canvas='.$this->canvas.'
'; //print ' => template_dir='.$this->template_dir.'
'; - - return 1; } @@ -125,7 +124,7 @@ class Canvas /** * Shared method for canvas to execute actions * - * @param string $action Action string + * @param string &$action Action string * @param int $id Object id * @return mixed Return return code of doActions of canvas */ @@ -141,7 +140,7 @@ class Canvas /** * Shared method for canvas to assign values for templates * - * @param string $action Action string + * @param string &$action Action string * @param int $id Object id * @return void */ From 1d89a4ac25517f6bc0174e2b78346551b20052b7 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 24 Sep 2011 21:51:52 +0000 Subject: [PATCH 25/32] Doxygen From eb7d374d3b6ad76759c1814b0b7cfe82375be220 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 24 Sep 2011 21:52:53 +0000 Subject: [PATCH 26/32] Add file to ignore From 1049c650c71cf2c5fccae5b6f29fc458e81000ef Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 24 Sep 2011 21:55:18 +0000 Subject: [PATCH 27/32] Add hidden option PROJECT_CAN_ALWAYS_LINK_TO_ALL_SUPPLIERS From b939445c939a1c2dc4ff33cb885404f3553fa5fc Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 24 Sep 2011 22:25:01 +0000 Subject: [PATCH 28/32] Qual: Uniformize code From 37fa08390cd5f863c6ce9842f2e6b171fc605c20 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 24 Sep 2011 22:31:28 +0000 Subject: [PATCH 29/32] Fix: Restore obsolete var when they are used as "init". I suggest to remove first all references that are in "read" mode by new name and remove reference that are in "write" mode only once there is no more call to old name in page that used them. This is to reduce risk of bugs. --- htdocs/societe/class/societe.class.php | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index a8d7823341a..36b8bf3a7d0 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -298,7 +298,8 @@ class Societe extends CommonObject $result = 0; $this->name = trim($this->name); - + $this->nom=$this->name; // For backward compatibility + if (! $this->name) { $this->errors[] = 'ErrorBadThirdPartyName'; @@ -393,11 +394,16 @@ class Societe extends CommonObject // Clean parameters $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->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); @@ -407,6 +413,9 @@ class Societe extends CommonObject $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); // TODO obsolete + $this->siret=trim($this->siret); // TODO obsolete + $this->ape=trim($this->ape); // TODO obsolete $this->idprof1 = trim($this->idprof1); $this->idprof2 = trim($this->idprof2); $this->idprof3 = trim($this->idprof3); From 91960b9b890d07a4e1f74bd37fb968d437a3e165 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 24 Sep 2011 22:43:52 +0000 Subject: [PATCH 30/32] Qual: Removed warnings From 2d09b2e54a2b3b39730e2a17efdca1b297b008b9 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 24 Sep 2011 23:42:31 +0000 Subject: [PATCH 31/32] Qual: Uniformize code From b02d7662b080358915246027d3e75363905c5fad Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 24 Sep 2011 23:49:45 +0000 Subject: [PATCH 32/32] Move dev module mantis to nltechno repository