diff --git a/htdocs/core/class/canvas.class.php b/htdocs/core/class/canvas.class.php index a47357737a2..e8d1c93b3c9 100644 --- a/htdocs/core/class/canvas.class.php +++ b/htdocs/core/class/canvas.class.php @@ -31,19 +31,98 @@ class Canvas { + var $canvas; var $template_dir; // Directory with all core and external templates files - var $errors = array(); // Array for errors + var $action; + var $smarty; + + var $error; /** * \brief Constructor. * \param DB Database handler */ - function Canvas($DB) + function Canvas($DB=0) { $this->db = $DB ; } + /** + * \brief Load class + */ + function load_canvas($object,$canvas) + { + global $langs; + + if (preg_match('/^([^@]+)@([^@]+)$/i',$canvas,$regs)) + { + var_dump($regs); + $ret = DOL_DOCUMENT_ROOT.'/'.$regs[2].'/canvas/'.$regs[1].'/'.$object.'.'.$regs[1].'.class.php'; print $ret; + if (file_exists(DOL_DOCUMENT_ROOT.'/'.$regs[2].'/canvas/'.$regs[1].'/'.$object.'.'.$regs[1].'.class.php')) + { + $filecanvas = DOL_DOCUMENT_ROOT.'/'.$regs[2].'/canvas/'.$regs[1].'/'.$object.'.'.$regs[1].'.class.php'; + $classname = ucfirst($object).ucfirst($regs[1]); + $this->template_dir = DOL_DOCUMENT_ROOT.'/'.$regs[2].'/canvas/'.$regs[1].'/tpl/'; + + include_once($filecanvas); + $this->object = new $classname($db,0,$user); + $this->smarty = $this->object->smarty; + + return $this->object; + } + else + { + $this->error = $langs->trans('CanvasIsInvalid'); + return 0; + } + + } + else + { + $this->error = $langs->trans('BadCanvasName'); + return 0; + } + } + + /** + * \brief Assign values + */ + function assign_values($action='') + { + $this->action = $action; + + if (!empty($this->smarty)) + { + global $smarty; + + $smarty->assign_smarty_values($this->smarty, $this->action); + $smarty->template_dir = $this->template_dir; + } + else + { + $this->object->assign_values($this->action); + } + + } + /** + * \brief Display + */ + function display_canvas() + { + global $langs; + + if (!empty($this->smarty)) + { + global $smarty; + + $this->smarty->display($this->action.'.tpl'); + } + else + { + include($this->template_dir.$this->action.'.tpl.php'); + } + } } ?> diff --git a/htdocs/install/mysql/migration/2.8.0-2.9.0.sql b/htdocs/install/mysql/migration/2.8.0-2.9.0.sql index ed6ae8f2fb1..d1fb2b05788 100755 --- a/htdocs/install/mysql/migration/2.8.0-2.9.0.sql +++ b/htdocs/install/mysql/migration/2.8.0-2.9.0.sql @@ -187,5 +187,9 @@ ALTER TABLE llx_categorie_member ADD INDEX idx_categorie_member_fk_member (fk_me ALTER TABLE llx_categorie_member ADD CONSTRAINT fk_categorie_member_categorie_rowid FOREIGN KEY (fk_categorie) REFERENCES llx_categorie (rowid); ALTER TABLE llx_categorie_member ADD CONSTRAINT fk_categorie_member_member_rowid FOREIGN KEY (fk_member) REFERENCES llx_adherent (rowid); -UPDATE llx_product SET canvas = 'default' WHERE fk_product_type = 0 AND canvas = ''; -UPDATE llx_product SET canvas = 'service' WHERE fk_product_type = 1 AND canvas = ''; +ALTER TABLE llx_product MODIFY COLUMN canvas varchar(32) DEFAULT 'default@product'; +UPDATE llx_product SET canvas = 'default@product' WHERE fk_product_type = 0 AND (canvas = '' OR canvas = 'default'); +UPDATE llx_product SET canvas = 'service@product' WHERE fk_product_type = 1 AND (canvas = '' OR canvas = 'service'); +UPDATE llx_product SET canvas = 'livre@droitpret' WHERE canvas = 'livre'; +UPDATE llx_product SET canvas = 'livrecontrat@droitpret' WHERE canvas = 'livrecontrat'; +UPDATE llx_product SET canvas = 'livrecouverture@droitpret' WHERE canvas = 'livrecouverture'; diff --git a/htdocs/install/mysql/tables/llx_product.sql b/htdocs/install/mysql/tables/llx_product.sql index 81922629ec1..efd71defb31 100644 --- a/htdocs/install/mysql/tables/llx_product.sql +++ b/htdocs/install/mysql/tables/llx_product.sql @@ -61,7 +61,7 @@ create table llx_product volume_units tinyint DEFAULT NULL, stock integer, -- physical stock pmp double(24,8) DEFAULT 0 NOT NULL, - canvas varchar(15) DEFAULT 'default', + canvas varchar(32) DEFAULT 'default@product', finished tinyint DEFAULT NULL, hidden tinyint DEFAULT 0, -- Need permission see also hidden products import_key varchar(14) -- import key diff --git a/htdocs/product/canvas/default/tpl/create.tpl.php b/htdocs/product/canvas/default/tpl/create.tpl.php index c5d3287c917..e90c2566594 100644 --- a/htdocs/product/canvas/default/tpl/create.tpl.php +++ b/htdocs/product/canvas/default/tpl/create.tpl.php @@ -21,7 +21,7 @@ -tpl['title']; ?> +object->tpl['title']; ?>

@@ -37,68 +37,68 @@ trans("Ref"); ?> - + trans("RefAlreadyExists"); ?> trans("Label"); ?> - + trans("Status"); ?> -tpl['status']; ?> +object->tpl['status']; ?> stock->enabled) { ?> trans("StockLimit"); ?> - + trans("Description"); ?> -tpl['textarea_description']) { -$product->tpl['doleditor_description']->Create(); +object->tpl['textarea_description']) { +$this->object->tpl['doleditor_description']->Create(); }else{ -echo $product->tpl['textarea_description']; +echo $this->object->tpl['textarea_description']; }?> trans("Nature"); ?> -tpl['finished']; ?> +object->tpl['finished']; ?> trans("Weight"); ?> - -tpl['weight_units']; ?> + +object->tpl['weight_units']; ?> trans("Length"); ?> - -tpl['length_units']; ?> + +object->tpl['length_units']; ?> trans("Surface"); ?> - -tpl['surface_units']; ?> + +object->tpl['surface_units']; ?> trans("Volume"); ?> - -tpl['volume_units']; ?> + +object->tpl['volume_units']; ?> trans("Hidden"); ?> -tpl['hidden']; ?> +object->tpl['hidden']; ?> trans("NoteNotVisibleOnBill"); ?> -tpl['textarea_note']) { -$product->tpl['doleditor_note']->Create(); +object->tpl['textarea_note']) { +$this->object->tpl['doleditor_note']->Create(); }else{ -echo $product->tpl['textarea_note']; +echo $this->object->tpl['textarea_note']; }?> @@ -110,16 +110,16 @@ echo $product->tpl['textarea_note']; - -
trans("SellingPrice"); ?> -tpl['price_base_type']; ?> + +object->tpl['price_base_type']; ?>
trans("MinPrice"); ?> +
trans("VATRate"); ?> -tpl['tva_tx']; ?> +object->tpl['tva_tx']; ?>
diff --git a/htdocs/product/fiche.php b/htdocs/product/fiche.php index b9fa5192e7a..5a0b1604476 100644 --- a/htdocs/product/fiche.php +++ b/htdocs/product/fiche.php @@ -30,6 +30,7 @@ */ require("../main.inc.php"); +require_once(DOL_DOCUMENT_ROOT."/core/class/canvas.class.php"); require_once(DOL_DOCUMENT_ROOT."/product/class/product.class.php"); require_once(DOL_DOCUMENT_ROOT."/product/class/html.formproduct.class.php"); require_once(DOL_DOCUMENT_ROOT."/lib/product.lib.php"); @@ -53,8 +54,8 @@ $result=restrictedArea($user,'produit|service',$id,'product','','',$fieldid); if (empty($_GET["canvas"])) { - $_GET["canvas"] = 'default'; - if ($_GET["type"] == 1) $_GET["canvas"] = 'service'; + $_GET["canvas"] = 'default@product'; + if ($_GET["type"] == 1) $_GET["canvas"] = 'service@product'; } $mesg = ''; @@ -623,7 +624,7 @@ $formproduct = new FormProduct($db); */ if ($_GET["action"] == 'create' && ($user->rights->produit->creer || $user->rights->service->creer)) { - if (!empty($_GET["canvas"]) && file_exists(DOL_DOCUMENT_ROOT.'/product/canvas/'.$_GET["canvas"].'/product.'.$_GET["canvas"].'.class.php')) + if (!empty($_GET["canvas"])) { $helpurl=''; if (isset($_GET["type"]) && $_GET["type"] == 0) $helpurl='EN:Module_Products|FR:Module_Produits|ES:Módulo_Productos'; @@ -633,30 +634,12 @@ if ($_GET["action"] == 'create' && ($user->rights->produit->creer || $user->righ if (! isset($product)) { - $filecanvas = DOL_DOCUMENT_ROOT.'/product/canvas/'.$_GET["canvas"].'/product.'.$_GET["canvas"].'.class.php'; - $classname = 'Product'.ucfirst($_GET["canvas"]); - - include_once($filecanvas); - $product = new $classname($db,0,$user); + $canvas = new Canvas(); - $template_dir = DOL_DOCUMENT_ROOT.'/product/canvas/'.$_GET["canvas"].'/tpl/'; - - if ($product->smarty) - { - $product->assign_smarty_values($smarty, $_GET["action"]); - $smarty->template_dir = $template_dir; - - //$tvaarray = load_tva($db,"tva_tx",$conf->defaulttx,$mysoc,''); - //$smarty->assign('tva_taux_value', $tvaarray['value']); - //$smarty->assign('tva_taux_libelle', $tvaarray['label']); - - $smarty->display($_GET["canvas"].'-create.tpl'); - } - else - { - $product->assign_values($_GET["action"]); - include($template_dir.'create.tpl.php'); - } + $product = $canvas->load_canvas('product',$_GET["canvas"]); + print $canvas->error; + $canvas->assign_values($_GET["action"],$smarty); + $canvas->display_canvas(); } if ($_error == 1)