diff --git a/htdocs/core/class/canvas.class.php b/htdocs/core/class/canvas.class.php index 3d3fbf11d06..1a1f3879c14 100644 --- a/htdocs/core/class/canvas.class.php +++ b/htdocs/core/class/canvas.class.php @@ -35,7 +35,7 @@ class Canvas var $template_dir; // Directory with all core and external templates files var $action; var $smarty; - + var $error; /** @@ -47,42 +47,44 @@ class Canvas $this->db = $DB ; $this->user = $user; } - + /** * \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')) - { - $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($this->db,0,$this->user); - $this->smarty = $this->object->smarty; - - return $this->object; - } - else - { - $this->error = $langs->trans('CanvasIsInvalid'); - return 0; - } - + $part1=$regs[2]; + $part2=$regs[1]; + } + + if (file_exists(DOL_DOCUMENT_ROOT.'/'.$part1.'/canvas/'.$part2.'/'.$part1.'.'.$part2.'.class.php')) + { + $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); + $this->smarty = $this->object->smarty; + + return $this->object; } else { - $this->error = $langs->trans('BadCanvasName'); + $this->error = $langs->trans('CanvasIsInvalid'); return 0; } } - + /** * \brief Fetch object values */ @@ -102,7 +104,7 @@ class Canvas if (!empty($this->smarty)) { global $smarty; - + $this->object->assign_smarty_values($smarty, $this->action); $smarty->template_dir = $this->template_dir; } @@ -110,20 +112,20 @@ class Canvas { $this->object->assign_values($this->action); } - + } - + /** * \brief Display canvas */ function display_canvas() { global $conf, $langs; - + if (!empty($this->smarty)) { global $smarty; - + $smarty->display($this->action.'.tpl'); } else diff --git a/htdocs/core/class/translate.class.php b/htdocs/core/class/translate.class.php index b673ed41f19..3e507151f66 100644 --- a/htdocs/core/class/translate.class.php +++ b/htdocs/core/class/translate.class.php @@ -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 diff --git a/htdocs/lib/functions.lib.php b/htdocs/lib/functions.lib.php index 3f0666906a1..0ce13468e7e 100644 --- a/htdocs/lib/functions.lib.php +++ b/htdocs/lib/functions.lib.php @@ -382,6 +382,15 @@ function dol_fiche_head($links, $active='0', $title='', $notab=0, $picto='') if (! $notab) print "\n".'
'."\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
\n"; +} + /** * \brief Add a delay to a date @@ -2052,7 +2061,7 @@ function print_fiche_titre($titre, $mesg='', $picto='title.png', $pictoisfullpat function load_fiche_titre($titre, $mesg='', $picto='title.png', $pictoisfullpath=0, $id='') { global $conf; - + $return=''; if ($picto == 'setup') $picto='title.png'; @@ -2069,7 +2078,7 @@ function load_fiche_titre($titre, $mesg='', $picto='title.png', $pictoisfullpath $return.= ''.$mesg.''; } $return.= ''."\n"; - + return $return; } @@ -3348,7 +3357,7 @@ if (! function_exists('glob')) if(PHP_OS=='WIN32') $slash='\\'; else $slash='/'; $lastpos=strrpos($pattern,$slash); - + if(!($lastpos===false)) { $path=substr($pattern,0,-$lastpos-1); @@ -3362,14 +3371,14 @@ if (! function_exists('glob')) $handle=@opendir($path); if($handle===false) return false; - + while($dir=readdir($handle)) { if(pattern_match($pattern,$dir)) $output[]=$dir; } - + closedir($handle); - + if(is_array($output)) return $output; return false; } @@ -3387,13 +3396,13 @@ function pattern_match($pattern,$string) { $escape=array('$','^','.','{','}','(',')','[',']','|'); while(strpos($pattern,'**')!==false) $pattern=str_replace('**','*',$pattern); - + foreach($escape as $probe) $pattern=str_replace($probe,"\\$probe",$pattern); - + $pattern=str_replace('?*','*',str_replace('*?','*',str_replace('*',".*",str_replace('?','.{1,1}',$pattern)))); $out[]=$pattern; } - + if(count($out)==1) { return(preg_match('/^'.$out[0].'$/i',$string)); diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index 91a3fc17656..e33b32f8627 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -127,7 +127,7 @@ class Product extends CommonObject //! Product ID already linked to a reference supplier var $product_id_already_linked; - + var $nbphoto; /** @@ -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=''; $nbphoto=0; $dir_osencoded=dol_osencode($dir); @@ -2623,9 +2623,9 @@ class Product extends CommonObject closedir($handle); } - + $this->nbphoto = $nbphoto; - + return $return; } @@ -2797,7 +2797,7 @@ class Product extends CommonObject return -1; } } - + /** * \brief Load type of canvas * \param id product id @@ -2806,7 +2806,7 @@ class Product extends CommonObject function getCanvas($id, $ref) { global $conf; - + $sql = "SELECT rowid, ref, canvas"; $sql.= " FROM ".MAIN_DB_PREFIX."product"; $sql.= " WHERE entity = ".$conf->entity; @@ -2817,11 +2817,11 @@ class Product extends CommonObject if ($resql) { $obj = $this->db->fetch_object($resql); - + $this->id = $obj->rowid; $this->ref = $obj->ref; $this->canvas = $obj->canvas; - + return 1; } else @@ -2830,7 +2830,7 @@ class Product extends CommonObject return -1; } } - + /** * \brief Affecte les valeurs communes */ @@ -2838,28 +2838,28 @@ class Product extends CommonObject { global $conf,$langs; global $html; - + // canvas $this->tpl['canvas'] = $this->canvas; - + // id $this->tpl['id'] = $this->id; - + // Ref $this->tpl['ref'] = $this->ref; - + // Label $this->tpl['label'] = $this->libelle; - + // Description $this->tpl['description'] = nl2br($this->description); - + // Statut $this->tpl['status'] = $this->getLibStatut(2); - + // Note $this->tpl['note'] = nl2br($this->note); - + // Hidden if ($this->user->rights->produit->hidden) { @@ -2869,38 +2869,38 @@ class Product extends CommonObject { $this->tpl['hidden'] = yn("No"); } - + if ($action == 'create') - { + { // Price $this->tpl['price'] = $this->price; $this->tpl['price_min'] = $this->price_min; $this->tpl['price_base_type'] = $html->load_PriceBaseType($this->price_base_type, "price_base_type"); - + // VAT $this->tpl['tva_tx'] = $html->load_tva("tva_tx",$conf->defaulttx,$mysoc,''); } - + if ($action == 'create' || $action == 'edit') { // Status $statutarray=array('1' => $langs->trans("OnSell"), '0' => $langs->trans("NotOnSell")); $this->tpl['status'] = $html->selectarray('statut',$statutarray,$this->status); - + // Hidden if ($this->user->rights->produit->hidden) { $this->tpl['hidden'] = $html->selectyesno('hidden',$this->hidden); } - + // TODO creer fonction if ($conf->fckeditor->enabled && $conf->global->FCKEDITOR_ENABLE_PRODUCTDESC) { require_once(DOL_DOCUMENT_ROOT."/lib/doleditor.class.php"); - + $doleditor=new DolEditor('desc',$this->description,160,'dolibarr_notes','',false); $this->tpl['doleditor_description'] = $doleditor; - + $doleditor=new DolEditor('note',$this->note,180,'dolibarr_notes','',false); $this->tpl['doleditor_note'] = $doleditor; } @@ -2910,14 +2910,14 @@ class Product extends CommonObject $textarea.= $this->description; $textarea.= ''; $this->tpl['textarea_description'] = $textarea; - + $textarea = ''; $this->tpl['textarea_note'] = $textarea; } } - + if ($action == 'view') { // Ref diff --git a/htdocs/product/fiche.php b/htdocs/product/fiche.php index 311a2e037a5..170d365e778 100644 --- a/htdocs/product/fiche.php +++ b/htdocs/product/fiche.php @@ -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='
'.$langs->trans('ErrorCanvasNotDefined').'
'; - $_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,28 +618,27 @@ $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ódulo_Productos'; + if (isset($_GET["type"]) && $_GET["type"] == 1) $helpurl='EN:Module_Services_En|FR:Module_Services|ES:Módulo_Servicios'; + + llxHeader('',$langs->trans("CardProduct".$_GET["type"]),$helpurl); + + $usecanvas=$_GET["canvas"]; + if (empty($usecanvas)) { - $helpurl=''; - if (isset($_GET["type"]) && $_GET["type"] == 0) $helpurl='EN:Module_Products|FR:Module_Produits|ES:Módulo_Productos'; - if (isset($_GET["type"]) && $_GET["type"] == 1) $helpurl='EN:Module_Services_En|FR:Module_Services|ES:Módulo_Servicios'; + // TODO Restore simple code here - llxHeader('',$langs->trans("CardProduct".$_GET["type"]),$helpurl); - if (! isset($product)) - { - $canvas = new Canvas($db,$user); - $product = $canvas->load_canvas('product',$_GET["canvas"]); + } + 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; - } + $canvas->assign_values('create'); + $canvas->display_canvas(); } } @@ -654,52 +649,358 @@ 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)) { - /* - * 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 '
'.$mesg.'

'; + } + + // Main official, simple, and not duplicated code + print "
\n"; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + + // Status + print ''; + + // Description (used in invoice, propal...) + print '"; + print "\n"; + + // Nature + if($product->type!=1) + { + print ''; + } + + if ($product->isproduct() && $conf->stock->enabled) + { + print "".''; + } + else + { + print ''; + } + + if ($product->isservice()) + { + // Duration + print ''; + } + else + { + // Weight + print ''; + // Length + print ''; + // Surface + print ''; + // Volume + print ''; + } + + // Hidden + if ((! $product->isservice() && $user->rights->produit->hidden) + || ($product->isservice() && $user->rights->service->hidden)) + { + print ''; + } + else + { + print ''; + } + + // Note + print '"; + print '
'.$langs->trans("Ref").'
'.$langs->trans("Label").'
'.$langs->trans("Status").''; + print ''; + print '
'.$langs->trans("Description").''; + 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 '"; + } + print "
'.$langs->trans("Nature").''; + $statutarray=array('-1'=>' ', '1' => $langs->trans("Finished"), '0' => $langs->trans("RowMaterial")); + $html->select_array('finished',$statutarray,$product->finished); + print '
'.$langs->trans("StockLimit").''; + print ''; + print '
'.$langs->trans("Duration").''; + print '  '; + print 'duration_unit=='h'?' checked':'').'>'.$langs->trans("Hour"); + print '  '; + print 'duration_unit=='d'?' checked':'').'>'.$langs->trans("Day"); + print '  '; + print 'duration_unit=='w'?' checked':'').'>'.$langs->trans("Week"); + print '  '; + print 'duration_unit=='m'?' checked':'').'>'.$langs->trans("Month"); + print '  '; + print 'duration_unit=='y'?' checked':'').'>'.$langs->trans("Year"); + + print '
'.$langs->trans("Weight").''; + print ' '; + print $formproduct->select_measuring_units("weight_units", "weight", $product->weight_units); + print '
'.$langs->trans("Length").''; + print ' '; + print $formproduct->select_measuring_units("size_units", "size", $product->length_units); + print '
'.$langs->trans("Surface").''; + print ' '; + print $formproduct->select_measuring_units("surface_units", "surface", $product->surface_units); + print '
'.$langs->trans("Volume").''; + print ' '; + print $formproduct->select_measuring_units("volume_units", "volume", $product->volume_units); + print '
'.$langs->trans("Hidden").''; + print $html->selectyesno('hidden',$product->hidden); + print '
'.$langs->trans("Hidden").''; + print yn("No"); + print '
'.$langs->trans("NoteNotVisibleOnBill").''; + 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 '"; + } + print "
'; + + print '
'; + + print '
    '; + print '
'; + + print '
'; + } + else { $canvas->assign_values('edit'); $canvas->display_canvas(); } - /* - * Fiche en mode visu - */ - else - { - $head=product_prepare_head($product, $user); - $titre=$langs->trans("CardProduct".$product->type); - $picto=($product->type==1?'service':'product'); - dol_fiche_head($head, 'card', $titre, 0, $picto); + } + /* + * Fiche en mode visu + */ + else + { + $head=product_prepare_head($product, $user); + $titre=$langs->trans("CardProduct".$product->type); + $picto=($product->type==1?'service':'product'); + dol_fiche_head($head, 'card', $titre, 0, $picto); - // Confirmation de la suppression de la facture - if ($_GET["action"] == 'delete') + // Confirmation de la suppression de la facture + if ($_GET["action"] == 'delete') + { + $ret=$html->form_confirm("fiche.php?id=".$product->id,$langs->trans("DeleteProduct"),$langs->trans("ConfirmDeleteProduct"),"confirm_delete",'',0,2); + if ($ret == 'html') print '
'; + } + + if (empty($usecanvas)) + { + // En mode visu + print ''; + + // Ref + print ''; + + print ''; + + // Label + print ''; + + $nblignes=4; + if ($product->is_photo_available($conf->produit->dir_output)) { - $ret=$html->form_confirm("fiche.php?id=".$product->id,$langs->trans("DeleteProduct"),$langs->trans("ConfirmDeleteProduct"),"confirm_delete",'',0,2); - if ($ret == 'html') print '
'; + // Photo + print ''; } + print ''; + + // Accountancy buy code + print ''; + + // Accountancy sell code + print ''; + + // Statut + print ''; + + // Description + print ''; + + // Nature + if($product->type!=1) + { + print ''; + } + + if ($product->isservice()) + { + // Duration + print ''; + } + else + { + // Weight + print '\n"; + // Length + print '\n"; + // Surface + print '\n"; + // Volume + print '\n"; + } + + // Hidden + if ((! $product->isservice() && $user->rights->produit->hidden) + || ($product->isservice() && $user->rights->service->hidden)) + { + print '\n"; + } + else + { + print ''; + } + + // Note + print ''; + + print "
'.$langs->trans("Ref").''; + print $html->showrefnav($product,'ref','',1,'ref'); + print '
'.$langs->trans("Label").''.$product->libelle.''; + print $product->show_photos($conf->produit->dir_output,1,1,0,0,0,80); + print '
'.$html->editfieldkey("ProductAccountancyBuyCode",'productaccountancycodesell',$product->accountancy_code_sell,'id',$product->id,$user->rights->produit->creer).''; + print $html->editfieldval("ProductAccountancyBuyCode",'productaccountancycodesell',$product->accountancy_code_sell,'id',$product->id,$user->rights->produit->creer); + print '
'.$html->editfieldkey("ProductAccountancySellCode",'productaccountancycodebuy',$product->accountancy_code_buy,'id',$product->id,$user->rights->produit->creer).''; + print $html->editfieldval("ProductAccountancySellCode",'productaccountancycodebuy',$product->accountancy_code_buy,'id',$product->id,$user->rights->produit->creer); + print '
'.$langs->trans("Status").''; + print $product->getLibStatut(2); + print '
'.$langs->trans("Description").''.nl2br($product->description).'
'.$langs->trans("Nature").''; + print $product->getLibFinished(); + print '
'.$langs->trans("Duration").''.$product->duration_value.' '; + 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])." "; + + print '
'.$langs->trans("Weight").''; + if ($product->weight != '') + { + print $product->weight." ".measuring_units_string($product->weight_units,"weight"); + } + else + { + print ' '; + } + print "
'.$langs->trans("Length").''; + if ($product->length != '') + { + print $product->length." ".measuring_units_string($product->length_units,"size"); + } + else + { + print ' '; + } + print "
'.$langs->trans("Surface").''; + if ($product->surface != '') + { + print $product->surface." ".measuring_units_string($product->surface_units,"surface"); + } + else + { + print ' '; + } + print "
'.$langs->trans("Volume").''; + if ($product->volume != '') + { + print $product->volume." ".measuring_units_string($product->volume_units,"volume"); + } + else + { + print ' '; + } + print "
'.$langs->trans("Hidden").''; + print yn($product->hidden); + print "
'.$langs->trans("Hidden").''; + print yn("No"); + print '
'.$langs->trans("Note").''.nl2br($product->note).'
\n"; + } + else + { $canvas->assign_values('view'); $canvas->display_canvas(); } + + dol_fiche_end(); } + } else if (!$_GET["action"] == 'create') {