Fix a lot of bugs after changes for canvas (photo hidden, edit field for accountancy disappeared, etc...). Too complicated to fix with canvas so I restore the "simple" code. Canvas feature should still works but with some bugs.

This commit is contained in:
Laurent Destailleur
2010-05-26 14:52:32 +00:00
parent ff4935fbc6
commit 4b7d4fa571
5 changed files with 427 additions and 115 deletions

View File

@@ -50,18 +50,27 @@ class Canvas
/**
* \brief Load canvas
* \param Name of first part of canvas
* \canvas Name of second part of canvas
*/
function load_canvas($object,$canvas)
{
global $langs;
$part1=$object;
$part2=$canvas;
if (preg_match('/^([^@]+)@([^@]+)$/i',$canvas,$regs))
{
if (file_exists(DOL_DOCUMENT_ROOT.'/'.$regs[2].'/canvas/'.$regs[1].'/'.$object.'.'.$regs[1].'.class.php'))
$part1=$regs[2];
$part2=$regs[1];
}
if (file_exists(DOL_DOCUMENT_ROOT.'/'.$part1.'/canvas/'.$part2.'/'.$part1.'.'.$part2.'.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/';
$filecanvas = DOL_DOCUMENT_ROOT.'/'.$part1.'/canvas/'.$part2.'/'.$part1.'.'.$part2.'.class.php';
$classname = ucfirst($part1).ucfirst($part2);
$this->template_dir = DOL_DOCUMENT_ROOT.'/'.$part1.'/canvas/'.$part2.'/tpl/';
include_once($filecanvas);
$this->object = new $classname($this->db,0,$this->user);
@@ -74,13 +83,6 @@ class Canvas
$this->error = $langs->trans('CanvasIsInvalid');
return 0;
}
}
else
{
$this->error = $langs->trans('BadCanvasName');
return 0;
}
}
/**

View File

@@ -127,7 +127,7 @@ class Translate {
* \brief Load translation key-value for a particular file, into a memory array.
* If data for file already loaded, do nothing.
* All data in translation array are stored in UTF-8 format.
* \param domain File name to load (.lang file). Use @ before value if domain is in a module directory.
* \param domain File name to load (.lang file). Use file@module if file is in a module directory.
* \param alt 0,1,2
* \param soptafterdirection Stop when the DIRECTION tag is found (optimize)
* \param forcelangdir To force a lang directory

View File

@@ -382,6 +382,15 @@ function dol_fiche_head($links, $active='0', $title='', $notab=0, $picto='')
if (! $notab) print "\n".'<div class="tabBar">'."\n";
}
/**
* \brief Show tab footer of a card
* \param notab 0=Add tab footer, 1=no tab footer
*/
function dol_fiche_end($notab=0)
{
if (! $notab) print "\n</div>\n";
}
/**
* \brief Add a delay to a date

View File

@@ -2493,7 +2493,7 @@ class Product extends CommonObject
* \param showfilename 1=Show filename
* \param showaction 1=Show icon with action links (resize, delete)
* \param maxheight Max height of image when size=1
* \return int Number of photos shown
* \return string Html code to show photo. Number of photos shown is saved in this->nbphoto
*/
function show_photos($sdir,$size=0,$nbmax=0,$nbbyrow=5,$showfilename=0,$showaction=0,$maxheight=120)
{
@@ -2507,7 +2507,7 @@ class Product extends CommonObject
$dirthumb = $dir.'thumbs/';
$pdirthumb = $pdir.'thumbs/';
$return='';
$return='<!-- Photo -->';
$nbphoto=0;
$dir_osencoded=dol_osencode($dir);

View File

@@ -127,19 +127,14 @@ if ($_POST["action"] == 'add' && ($user->rights->produit->creer || $user->rights
$error++;
}
if (!empty($_POST["canvas"]))
$product=new Product($db);
$usecanvas=$_POST["canvas"];
if (! empty($usecanvas)) // Overwrite product here
{
$canvas = new Canvas($db,$user);
$product = $canvas->load_canvas('product',$_POST["canvas"]);
}
else
{
$mesg='<div class="error">'.$langs->trans('ErrorCanvasNotDefined').'</div>';
$_GET["action"] = "create";
$_GET["canvas"] = $_POST["canvas"];
$_GET["type"] = $_POST["type"];
$error++;
}
if (! $error)
{
@@ -192,8 +187,6 @@ if ($_POST["action"] == 'add' && ($user->rights->produit->creer || $user->rights
}
}
if ( $value != $current_lang ) $e_product = $product;
$id = $product->create($user);
if ($id > 0)
@@ -220,7 +213,10 @@ if ($_POST["action"] == 'update' && ($user->rights->produit->creer || $user->rig
}
else
{
if (!empty($_POST["canvas"]))
$product=new Product($db);
$usecanvas=$_POST["canvas"];
if (! empty($usecanvas)) // Overwrite product here
{
$canvas = new Canvas($db,$user);
$product = $canvas->load_canvas('product',$_POST["canvas"]);
@@ -362,7 +358,7 @@ if ($_REQUEST['action'] == 'confirm_delete' && $_REQUEST['confirm'] == 'yes' &&
*/
if ($_POST["action"] == 'addinpropal')
{
$propal = New Propal($db);
$propal = new Propal($db);
$result=$propal->fetch($_POST["propalid"]);
if ($result <= 0)
{
@@ -622,29 +618,28 @@ $formproduct = new FormProduct($db);
*/
if ($_GET["action"] == 'create' && ($user->rights->produit->creer || $user->rights->service->creer))
{
if (!empty($_GET["canvas"]))
{
$helpurl='';
if (isset($_GET["type"]) && $_GET["type"] == 0) $helpurl='EN:Module_Products|FR:Module_Produits|ES:M&oacute;dulo_Productos';
if (isset($_GET["type"]) && $_GET["type"] == 1) $helpurl='EN:Module_Services_En|FR:Module_Services|ES:M&oacute;dulo_Servicios';
llxHeader('',$langs->trans("CardProduct".$_GET["type"]),$helpurl);
if (! isset($product))
$usecanvas=$_GET["canvas"];
if (empty($usecanvas))
{
// TODO Restore simple code here
}
else
{
$canvas = new Canvas($db,$user);
$product = $canvas->load_canvas('product',$_GET["canvas"]);
$canvas->assign_values('create');
$canvas->display_canvas();
}
if ($_error == 1)
{
$product = $e_product;
}
}
}
/**
@@ -654,31 +649,196 @@ if ($_GET["action"] == 'create' && ($user->rights->produit->creer || $user->righ
*/
if ($_GET["id"] || $_GET["ref"])
{
$product=new Product($db);
// TODO en attendant d'inclure le nom du canvas dans les liens
$productstatic = new Product($db);
$result = $productstatic->getCanvas($_GET["id"],$_GET["ref"]);
$usecanvas=$productstatic->canvas;
// Gestion des produits specifiques
if (!empty($productstatic->canvas))
if (empty($usecanvas))
{
$product->fetch($_GET["id"],$_GET["ref"]);
}
else // Gestion des produits specifiques
{
$canvas = new Canvas($db,$user);
$product = $canvas->load_canvas('product',$productstatic->canvas);
if (! $product) dol_print_error('','Faled to load canvas product-'.$productstatic->canvas);
$canvas->fetch($productstatic->id,'',$_GET["action"]);
}
llxHeader('',$langs->trans("CardProduct".$product->type));
if ( $result )
{
/*
* Fiche en mode edition
*/
if ($_GET["action"] == 'edit' && ($user->rights->produit->creer || $user->rights->service->creer))
{
if (empty($usecanvas))
{
if ($product->isservice()) {
print_fiche_titre($langs->trans('Modify').' '.$langs->trans('Service').' : '.$product->ref, "");
} else {
print_fiche_titre($langs->trans('Modify').' '.$langs->trans('Product').' : '.$product->ref, "");
}
if ($mesg) {
print '<br><div class="error">'.$mesg.'</div><br>';
}
// Main official, simple, and not duplicated code
print "<form action=\"fiche.php\" method=\"post\">\n";
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="update">';
print '<input type="hidden" name="id" value="'.$product->id.'">';
print '<input type="hidden" name="canvas" value="'.$product->canvas.'">';
print '<table class="border" width="100%">';
print '<tr><td width="15%">'.$langs->trans("Ref").'</td><td colspan="2"><input name="ref" size="40" maxlength="32" value="'.$product->ref.'"></td></tr>';
print '<tr><td>'.$langs->trans("Label").'</td><td><input name="libelle" size="40" value="'.$product->libelle.'"></td></tr>';
// Status
print '<tr><td>'.$langs->trans("Status").'</td><td colspan="2">';
print '<select class="flat" name="statut">';
if ($product->status)
{
print '<option value="1" selected="true">'.$langs->trans("OnSell").'</option>';
print '<option value="0">'.$langs->trans("NotOnSell").'</option>';
}
else
{
print '<option value="1">'.$langs->trans("OnSell").'</option>';
print '<option value="0" selected="true">'.$langs->trans("NotOnSell").'</option>';
}
print '</select>';
print '</td></tr>';
// Description (used in invoice, propal...)
print '<tr><td valign="top">'.$langs->trans("Description").'</td><td colspan="2">';
print "\n";
if ($conf->fckeditor->enabled && $conf->global->FCKEDITOR_ENABLE_PRODUCTDESC)
{
require_once(DOL_DOCUMENT_ROOT."/lib/doleditor.class.php");
$doleditor=new DolEditor('desc',$product->description,160,'dolibarr_notes','',false);
$doleditor->Create();
}
else
{
print '<textarea name="desc" rows="4" cols="90">';
print dol_htmlentitiesbr_decode($product->description);
print "</textarea>";
}
print "</td></tr>";
print "\n";
// Nature
if($product->type!=1)
{
print '<tr><td>'.$langs->trans("Nature").'</td><td>';
$statutarray=array('-1'=>'&nbsp;', '1' => $langs->trans("Finished"), '0' => $langs->trans("RowMaterial"));
$html->select_array('finished',$statutarray,$product->finished);
print '</td></tr>';
}
if ($product->isproduct() && $conf->stock->enabled)
{
print "<tr>".'<td>'.$langs->trans("StockLimit").'</td><td colspan="2">';
print '<input name="seuil_stock_alerte" size="4" value="'.$product->seuil_stock_alerte.'">';
print '</td></tr>';
}
else
{
print '<input name="seuil_stock_alerte" type="hidden" value="'.$product->seuil_stock_alerte.'">';
}
if ($product->isservice())
{
// Duration
print '<tr><td>'.$langs->trans("Duration").'</td><td colspan="2"><input name="duration_value" size="3" maxlength="5" value="'.$product->duration_value.'">';
print '&nbsp; ';
print '<input name="duration_unit" type="radio" value="h"'.($product->duration_unit=='h'?' checked':'').'>'.$langs->trans("Hour");
print '&nbsp; ';
print '<input name="duration_unit" type="radio" value="d"'.($product->duration_unit=='d'?' checked':'').'>'.$langs->trans("Day");
print '&nbsp; ';
print '<input name="duration_unit" type="radio" value="w"'.($product->duration_unit=='w'?' checked':'').'>'.$langs->trans("Week");
print '&nbsp; ';
print '<input name="duration_unit" type="radio" value="m"'.($product->duration_unit=='m'?' checked':'').'>'.$langs->trans("Month");
print '&nbsp; ';
print '<input name="duration_unit" type="radio" value="y"'.($product->duration_unit=='y'?' checked':'').'>'.$langs->trans("Year");
print '</td></tr>';
}
else
{
// Weight
print '<tr><td>'.$langs->trans("Weight").'</td><td>';
print '<input name="weight" size="5" value="'.$product->weight.'"> ';
print $formproduct->select_measuring_units("weight_units", "weight", $product->weight_units);
print '</td></tr>';
// Length
print '<tr><td>'.$langs->trans("Length").'</td><td>';
print '<input name="size" size="5" value="'.$product->length.'"> ';
print $formproduct->select_measuring_units("size_units", "size", $product->length_units);
print '</td></tr>';
// Surface
print '<tr><td>'.$langs->trans("Surface").'</td><td>';
print '<input name="surface" size="5" value="'.$product->surface.'"> ';
print $formproduct->select_measuring_units("surface_units", "surface", $product->surface_units);
print '</td></tr>';
// Volume
print '<tr><td>'.$langs->trans("Volume").'</td><td>';
print '<input name="volume" size="5" value="'.$product->volume.'"> ';
print $formproduct->select_measuring_units("volume_units", "volume", $product->volume_units);
print '</td></tr>';
}
// Hidden
if ((! $product->isservice() && $user->rights->produit->hidden)
|| ($product->isservice() && $user->rights->service->hidden))
{
print '<tr><td>'.$langs->trans("Hidden").'</td><td>';
print $html->selectyesno('hidden',$product->hidden);
print '</td></tr>';
}
else
{
print '<tr><td>'.$langs->trans("Hidden").'</td><td>';
print yn("No");
print '</td></tr>';
}
// Note
print '<tr><td valign="top">'.$langs->trans("NoteNotVisibleOnBill").'</td><td colspan="2">';
if ($conf->fckeditor->enabled && $conf->global->FCKEDITOR_ENABLE_PRODUCTDESC)
{
require_once(DOL_DOCUMENT_ROOT."/lib/doleditor.class.php");
$doleditor=new DolEditor('note',$product->note,200,'dolibarr_notes','',false);
$doleditor->Create();
}
else
{
print '<textarea name="note" rows="8" cols="70">';
print dol_htmlentitiesbr_decode($product->note);
print "</textarea>";
}
print "</td></tr>";
print '</table>';
print '<br>';
print '<center><input type="submit" class="button" value="'.$langs->trans("Save").'"> &nbsp; &nbsp; ';
print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'"></center>';
print '</form>';
}
else
{
$canvas->assign_values('edit');
$canvas->display_canvas();
}
}
/*
* Fiche en mode visu
*/
@@ -696,10 +856,151 @@ if ($_GET["id"] || $_GET["ref"])
if ($ret == 'html') print '<br>';
}
if (empty($usecanvas))
{
// En mode visu
print '<table class="border" width="100%"><tr>';
// Ref
print '<td width="15%">'.$langs->trans("Ref").'</td><td colspan="2">';
print $html->showrefnav($product,'ref','',1,'ref');
print '</td>';
print '</tr>';
// Label
print '<tr><td>'.$langs->trans("Label").'</td><td>'.$product->libelle.'</td>';
$nblignes=4;
if ($product->is_photo_available($conf->produit->dir_output))
{
// Photo
print '<td valign="middle" align="center" width="30%" rowspan="'.$nblignes.'">';
print $product->show_photos($conf->produit->dir_output,1,1,0,0,0,80);
print '</td>';
}
print '</tr>';
// Accountancy buy code
print '<tr><td>'.$html->editfieldkey("ProductAccountancyBuyCode",'productaccountancycodesell',$product->accountancy_code_sell,'id',$product->id,$user->rights->produit->creer).'</td><td>';
print $html->editfieldval("ProductAccountancyBuyCode",'productaccountancycodesell',$product->accountancy_code_sell,'id',$product->id,$user->rights->produit->creer);
print '</td></tr>';
// Accountancy sell code
print '<tr><td>'.$html->editfieldkey("ProductAccountancySellCode",'productaccountancycodebuy',$product->accountancy_code_buy,'id',$product->id,$user->rights->produit->creer).'</td><td>';
print $html->editfieldval("ProductAccountancySellCode",'productaccountancycodebuy',$product->accountancy_code_buy,'id',$product->id,$user->rights->produit->creer);
print '</td></tr>';
// Statut
print '<tr><td>'.$langs->trans("Status").'</td><td>';
print $product->getLibStatut(2);
print '</td></tr>';
// Description
print '<tr><td valign="top">'.$langs->trans("Description").'</td><td colspan="2">'.nl2br($product->description).'</td></tr>';
// Nature
if($product->type!=1)
{
print '<tr><td>'.$langs->trans("Nature").'</td><td colspan="2">';
print $product->getLibFinished();
print '</td></tr>';
}
if ($product->isservice())
{
// Duration
print '<tr><td>'.$langs->trans("Duration").'</td><td colspan="2">'.$product->duration_value.'&nbsp;';
if ($product->duration_value > 1)
{
$dur=array("h"=>$langs->trans("Hours"),"d"=>$langs->trans("Days"),"w"=>$langs->trans("Weeks"),"m"=>$langs->trans("Months"),"y"=>$langs->trans("Years"));
}
else if ($product->duration_value > 0)
{
$dur=array("h"=>$langs->trans("Hour"),"d"=>$langs->trans("Day"),"w"=>$langs->trans("Week"),"m"=>$langs->trans("Month"),"y"=>$langs->trans("Year"));
}
print $langs->trans($dur[$product->duration_unit])."&nbsp;";
print '</td></tr>';
}
else
{
// Weight
print '<tr><td>'.$langs->trans("Weight").'</td><td colspan="2">';
if ($product->weight != '')
{
print $product->weight." ".measuring_units_string($product->weight_units,"weight");
}
else
{
print '&nbsp;';
}
print "</td></tr>\n";
// Length
print '<tr><td>'.$langs->trans("Length").'</td><td colspan="2">';
if ($product->length != '')
{
print $product->length." ".measuring_units_string($product->length_units,"size");
}
else
{
print '&nbsp;';
}
print "</td></tr>\n";
// Surface
print '<tr><td>'.$langs->trans("Surface").'</td><td colspan="2">';
if ($product->surface != '')
{
print $product->surface." ".measuring_units_string($product->surface_units,"surface");
}
else
{
print '&nbsp;';
}
print "</td></tr>\n";
// Volume
print '<tr><td>'.$langs->trans("Volume").'</td><td colspan="2">';
if ($product->volume != '')
{
print $product->volume." ".measuring_units_string($product->volume_units,"volume");
}
else
{
print '&nbsp;';
}
print "</td></tr>\n";
}
// Hidden
if ((! $product->isservice() && $user->rights->produit->hidden)
|| ($product->isservice() && $user->rights->service->hidden))
{
print '<tr><td>'.$langs->trans("Hidden").'</td><td colspan="2">';
print yn($product->hidden);
print "</td></tr>\n";
}
else
{
print '<tr><td>'.$langs->trans("Hidden").'</td><td>';
print yn("No");
print '</td></tr>';
}
// Note
print '<tr><td valign="top">'.$langs->trans("Note").'</td><td colspan="2">'.nl2br($product->note).'</td></tr>';
print "</table>\n";
}
else
{
$canvas->assign_values('view');
$canvas->display_canvas();
}
dol_fiche_end();
}
}
else if (!$_GET["action"] == 'create')
{