Skip to content
Snippets Groups Projects
Commit 3d7752ca authored by Laurent Destailleur's avatar Laurent Destailleur
Browse files

Qual: Simplify canvas code

parent a918f3bf
Branches
No related tags found
No related merge requests found
...@@ -72,42 +72,33 @@ class Canvas ...@@ -72,42 +72,33 @@ class Canvas
/** /**
* Initialize properties like ->control, ->control->object, ->template_dir * Initialize properties: ->targetmodule, ->card, ->canvas
* @param module Name of target module (thirdparty, ...) * and MVC properties: ->control (Controller), ->control->object (Model), ->template_dir (View)
* @param card Type of card (ex: card, info, ...) * @param module Name of target module (thirdparty, contact, ...)
* @param canvas Name of canvas (ex: mycanvas@mymodule) * @param card Type of card (ex: card, info, contactcard, ...)
* @param canvas Name of canvas (ex: mycanvas, default, or mycanvas@myexternalmodule)
*/ */
function getCanvas($module, $card, $canvas) function getCanvas($module, $card, $canvas)
{ {
global $conf, $langs; global $conf, $langs;
$error=''; $error='';
$this->card = $card;
// Define this->canvas, this->targetmodule, this->aliasmodule, targetmodule, childmodule // Set properties with value specific to dolibarr core: this->targetmodule, this->card, this->canvas
$this->targetmodule = $module;
$this->card = $card;
$this->canvas = $canvas; $this->canvas = $canvas;
$this->targetmodule = $this->aliasmodule = $module; $dirmodule = $module;
// Correct values if canvas is into an external module
if (preg_match('/^([^@]+)@([^@]+)$/i',$canvas,$regs)) if (preg_match('/^([^@]+)@([^@]+)$/i',$canvas,$regs))
{ {
$this->canvas = $regs[1]; $this->canvas = $regs[1];
$this->aliasmodule = $regs[2]; $dirmodule = $regs[2];
} }
$targetmodule = $this->targetmodule;
$childmodule = $this->aliasmodule;
// For compatibility // For compatibility
if ($targetmodule == 'thirdparty') { $targetmodule = 'societe'; } if ($dirmodule == 'thirdparty') { $dirmodule = 'societe'; }
if ($childmodule == 'thirdparty') { $childmodule = 'societe'; $this->aliasmodule = 'societe'; }
if ($targetmodule == 'contact') { $targetmodule = 'societe'; }
if ($childmodule == 'contact') { $childmodule = 'societe'; }
/*print 'canvas='.$this->canvas.'<br>';
print 'childmodule='.$childmodule.' targetmodule='.$targetmodule.'<br>';
print 'this->aliasmodule='.$this->aliasmodule.' this->targetmodule='.$this->targetmodule.'<br>';
print 'childmodule='.$conf->$childmodule->enabled.' targetmodule='.$conf->$targetmodule->enabled.'<br>';*/
if (! $conf->$childmodule->enabled || ! $conf->$targetmodule->enabled) accessforbidden();
$controlclassfile = dol_buildpath('/'.$this->aliasmodule.'/canvas/'.$this->canvas.'/actions_'.$this->card.'_'.$this->canvas.'.class.php'); $controlclassfile = dol_buildpath('/'.$dirmodule.'/canvas/'.$this->canvas.'/actions_'.$this->card.'_'.$this->canvas.'.class.php');
if (file_exists($controlclassfile)) if (file_exists($controlclassfile))
{ {
// Include actions class (controller) // Include actions class (controller)
...@@ -119,7 +110,7 @@ class Canvas ...@@ -119,7 +110,7 @@ class Canvas
} }
// TODO Dao should be declared and used by controller or templates when required only // TODO Dao should be declared and used by controller or templates when required only
$modelclassfile = dol_buildpath('/'.$this->aliasmodule.'/canvas/'.$this->canvas.'/dao_'.$this->targetmodule.'_'.$this->canvas.'.class.php'); $modelclassfile = dol_buildpath('/'.$dirmodule.'/canvas/'.$this->canvas.'/dao_'.$this->targetmodule.'_'.$this->canvas.'.class.php');
if (file_exists($modelclassfile)) if (file_exists($modelclassfile))
{ {
// Include dataservice class (model) // Include dataservice class (model)
...@@ -132,16 +123,16 @@ class Canvas ...@@ -132,16 +123,16 @@ class Canvas
// Include specific library // Include specific library
// TODO Specific libraries must be included by files that need them only, so by actions and/or dao files. // TODO Specific libraries must be included by files that need them only, so by actions and/or dao files.
$libfile = dol_buildpath('/'.$this->aliasmodule.'/lib/'.$this->aliasmodule.'.lib.php'); $libfile = dol_buildpath('/'.$dirmodule.'/lib/'.$dirmodule.'.lib.php');
if (file_exists($libfile)) require_once($libfile); if (file_exists($libfile)) require_once($libfile);
// Template dir // Template dir
$this->template_dir = dol_buildpath('/'.$this->aliasmodule.'/canvas/'.$this->canvas.'/tpl/'); $this->template_dir = dol_buildpath('/'.$dirmodule.'/canvas/'.$this->canvas.'/tpl/');
if (! is_dir($this->template_dir)) if (! is_dir($this->template_dir))
{ {
$this->template_dir=''; $this->template_dir='';
} }
//print '/'.$this->aliasmodule.'/canvas/'.$this->canvas.'/tpl/'; //print '/'.$dirmodule.'/canvas/'.$this->canvas.'/tpl/';
//print 'template_dir='.$this->template_dir.'<br>'; //print 'template_dir='.$this->template_dir.'<br>';
return 1; return 1;
......
...@@ -173,9 +173,12 @@ class Societe extends CommonObject ...@@ -173,9 +173,12 @@ class Societe extends CommonObject
global $langs,$conf; global $langs,$conf;
// Clean parameters // Clean parameters
if (empty($this->status)) $this->status=0;
$this->name=$this->name?trim($this->name):trim($this->nom); $this->name=$this->name?trim($this->name):trim($this->nom);
if (! empty($conf->global->MAIN_FIRST_TO_UPPER)) $this->name=ucwords($this->name); if (! empty($conf->global->MAIN_FIRST_TO_UPPER)) $this->name=ucwords($this->name);
$this->nom=$this->name; // For backward compatibility $this->nom=$this->name; // For backward compatibility
if (empty($this->client)) $this->client=0;
if (empty($this->fournisseur)) $this->fournisseur=0;
dol_syslog("Societe::create ".$this->name); dol_syslog("Societe::create ".$this->name);
...@@ -186,8 +189,8 @@ class Societe extends CommonObject ...@@ -186,8 +189,8 @@ class Societe extends CommonObject
$this->error = $langs->trans("ErrorBadEMail",$this->email); $this->error = $langs->trans("ErrorBadEMail",$this->email);
return -1; return -1;
} }
if (empty($this->client)) $this->client=0;
if (empty($this->fournisseur)) $this->fournisseur=0; $now=dol_now();
$this->db->begin(); $this->db->begin();
...@@ -195,8 +198,6 @@ class Societe extends CommonObject ...@@ -195,8 +198,6 @@ class Societe extends CommonObject
if ($this->code_client == -1) $this->get_codeclient($this->prefix_comm,0); if ($this->code_client == -1) $this->get_codeclient($this->prefix_comm,0);
if ($this->code_fournisseur == -1) $this->get_codefournisseur($this->prefix_comm,1); if ($this->code_fournisseur == -1) $this->get_codefournisseur($this->prefix_comm,1);
$now=dol_now();
// Check more parameters // Check more parameters
$result = $this->verify(); $result = $this->verify();
......
...@@ -56,6 +56,8 @@ $soc = new Societe($db); ...@@ -56,6 +56,8 @@ $soc = new Societe($db);
// Get object canvas (By default, this is not defined, so standard usage of dolibarr) // Get object canvas (By default, this is not defined, so standard usage of dolibarr)
if (!empty($socid)) $soc->getCanvas($socid); if (!empty($socid)) $soc->getCanvas($socid);
$canvas = (!empty($soc->canvas)?$soc->canvas:GETPOST("canvas")); $canvas = (!empty($soc->canvas)?$soc->canvas:GETPOST("canvas"));
if (! empty($canvas)) if (! empty($canvas))
{ {
require_once(DOL_DOCUMENT_ROOT."/core/class/canvas.class.php"); require_once(DOL_DOCUMENT_ROOT."/core/class/canvas.class.php");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment