Works on product canvas and templates

Add possibility to move canvas directory to module directory
This commit is contained in:
Regis Houssin 2010-05-05 08:49:17 +00:00
parent 8aae74307a
commit 9dc1c8344e
5 changed files with 122 additions and 56 deletions

View File

@ -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');
}
}
}
?>

View File

@ -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';

View File

@ -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

View File

@ -21,7 +21,7 @@
<!-- BEGIN PHP TEMPLATE -->
<?php echo $product->tpl['title']; ?>
<?php echo $this->object->tpl['title']; ?>
<?php if ($mesg) { ?>
<br><div class="error"><?php echo $mesg; ?></div><br>
@ -37,68 +37,68 @@
<tr>
<td class="fieldrequired" width="20%"><?php echo $langs->trans("Ref"); ?></td>
<td><input name="ref" size="40" maxlength="32" value="<?php echo $product->tpl['ref']; ?>">
<td><input name="ref" size="40" maxlength="32" value="<?php echo $this->object->tpl['ref']; ?>">
<?php if ($_error == 1) echo $langs->trans("RefAlreadyExists"); ?>
</td></tr>
<tr>
<td class="fieldrequired"><?php echo $langs->trans("Label"); ?></td>
<td><input name="libelle" size="40" value="<?php echo $product->tpl['label']; ?>"></td>
<td><input name="libelle" size="40" value="<?php echo $this->object->tpl['label']; ?>"></td>
</tr>
<tr>
<td class="fieldrequired"><?php echo $langs->trans("Status"); ?></td>
<td><?php echo $product->tpl['status']; ?></td>
<td><?php echo $this->object->tpl['status']; ?></td>
</tr>
<?php if ($conf->stock->enabled) { ?>
<tr><td><?php echo $langs->trans("StockLimit"); ?></td><td>
<input name="seuil_stock_alerte" size="4" value="<?php echo $product->tpl['seuil_stock_alerte']; ?>">
<input name="seuil_stock_alerte" size="4" value="<?php echo $this->object->tpl['seuil_stock_alerte']; ?>">
</td></tr>
<?php } else { ?>
<input name="seuil_stock_alerte" type="hidden" value="0">
<?php } ?>
<tr><td valign="top"><?php echo $langs->trans("Description"); ?></td><td>
<?php if (! $product->tpl['textarea_description']) {
$product->tpl['doleditor_description']->Create();
<?php if (! $this->object->tpl['textarea_description']) {
$this->object->tpl['doleditor_description']->Create();
}else{
echo $product->tpl['textarea_description'];
echo $this->object->tpl['textarea_description'];
}?>
</td></tr>
<tr><td><?php echo $langs->trans("Nature"); ?></td><td>
<?php echo $product->tpl['finished']; ?>
<?php echo $this->object->tpl['finished']; ?>
</td></tr>
<tr><td><?php echo $langs->trans("Weight"); ?></td><td>
<input name="weight" size="4" value="<?php echo $product->tpl['weight']; ?>">
<?php echo $product->tpl['weight_units']; ?>
<input name="weight" size="4" value="<?php echo $this->object->tpl['weight']; ?>">
<?php echo $this->object->tpl['weight_units']; ?>
</td></tr>
<tr><td><?php echo $langs->trans("Length"); ?></td><td>
<input name="size" size="4" value="<?php echo $product->tpl['length']; ?>">
<?php echo $product->tpl['length_units']; ?>
<input name="size" size="4" value="<?php echo $this->object->tpl['length']; ?>">
<?php echo $this->object->tpl['length_units']; ?>
</td></tr>
<tr><td><?php echo $langs->trans("Surface"); ?></td><td>
<input name="surface" size="4" value="<?php echo $product->tpl['surface']; ?>">
<?php echo $product->tpl['surface_units']; ?>
<input name="surface" size="4" value="<?php echo $this->object->tpl['surface']; ?>">
<?php echo $this->object->tpl['surface_units']; ?>
</td></tr>
<tr><td><?php echo $langs->trans("Volume"); ?></td><td>
<input name="volume" size="4" value="<?php echo $product->tpl['volume']; ?>">
<?php echo $product->tpl['volume_units']; ?>
<input name="volume" size="4" value="<?php echo $this->object->tpl['volume']; ?>">
<?php echo $this->object->tpl['volume_units']; ?>
</td></tr>
<tr><td><?php echo $langs->trans("Hidden"); ?></td>
<td><?php echo $product->tpl['hidden']; ?></td></tr>
<td><?php echo $this->object->tpl['hidden']; ?></td></tr>
<tr><td valign="top"><?php echo $langs->trans("NoteNotVisibleOnBill"); ?></td><td>
<?php if (! $product->tpl['textarea_note']) {
$product->tpl['doleditor_note']->Create();
<?php if (! $this->object->tpl['textarea_note']) {
$this->object->tpl['doleditor_note']->Create();
}else{
echo $product->tpl['textarea_note'];
echo $this->object->tpl['textarea_note'];
}?>
</td></tr>
</table>
@ -110,16 +110,16 @@ echo $product->tpl['textarea_note'];
<table class="border" width="100%">
<tr><td><?php echo $langs->trans("SellingPrice"); ?></td>
<td><input name="price" size="10" value="<?php echo $product->tpl['price']; ?>">
<?php echo $product->tpl['price_base_type']; ?>
<td><input name="price" size="10" value="<?php echo $this->object->tpl['price']; ?>">
<?php echo $this->object->tpl['price_base_type']; ?>
</td></tr>
<tr><td><?php echo $langs->trans("MinPrice"); ?></td>
<td><input name="price_min" size="10" value="<?php echo $product->tpl['price_min']; ?>">
<td><input name="price_min" size="10" value="<?php echo $this->object->tpl['price_min']; ?>">
</td></tr>
<tr><td width="20%"><?php echo $langs->trans("VATRate"); ?></td><td>
<?php echo $product->tpl['tva_tx']; ?>
<?php echo $this->object->tpl['tva_tx']; ?>
</td></tr>
</table>

View File

@ -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&oacute;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)