diff --git a/htdocs/core/class/canvas.class.php b/htdocs/core/class/canvas.class.php index f098a90dea8..a2b88dc7572 100644 --- a/htdocs/core/class/canvas.class.php +++ b/htdocs/core/class/canvas.class.php @@ -32,7 +32,7 @@ class Canvas var $db; var $error; var $errors=array(); - + var $actiontype; var $dirmodule; // Module directory @@ -114,12 +114,13 @@ class Canvas * Shared method for canvas to assign values for templates * * @param string &$action Action string - * @param int $id Object id + * @param int $id Object id (if ref not provided) + * @param string $ref Object ref (if id not provided) * @return void */ - function assign_values(&$action='view', $id=0) + function assign_values(&$action='view', $id=0, $ref='') { - if (method_exists($this->control,'assign_values')) $this->control->assign_values($action, $id); + if (method_exists($this->control,'assign_values')) $this->control->assign_values($action, $id, $ref); } /** diff --git a/htdocs/product/canvas/product/actions_card_product.class.php b/htdocs/product/canvas/product/actions_card_product.class.php index 10384ca0086..a89ea74941c 100755 --- a/htdocs/product/canvas/product/actions_card_product.class.php +++ b/htdocs/product/canvas/product/actions_card_product.class.php @@ -40,18 +40,20 @@ class ActionsCardProduct extends Product public $list_datas = array(); - /** + /** * Constructor * - * @param DoliDB $DB Handler acces base de donnees - * @param string $targetmodule Name of directory of module where canvas is stored - * @param string $canvas Name of canvas - * @param string $card Name of tab (sub-canvas) + * @param DoliDB $DB Database handler + * @param string $dirmodule Name of directory of module + * @param string $targetmodule Name of directory where canvas is stored + * @param string $canvas Name of canvas + * @param string $card Name of tab (sub-canvas) */ - function ActionsCardProduct($DB,$targetmodule,$canvas,$card) + function __construct($DB, $dirmodule, $targetmodule, $canvas, $card) { - $this->db = $DB; - $this->targetmodule = $targetmodule; + $this->db = $DB; + $this->dirmodule = $dirmodule; + $this->targetmodule = $targetmodule; $this->canvas = $canvas; $this->card = $card; @@ -74,18 +76,45 @@ class ActionsCardProduct extends Product return $langs->trans("Products"); } + /** + * Get object from id or ref and save it into this->object + * + * @param int $id Object id + * @param string $ref Ojbect ref + * @return Object Object loaded + */ + function getObject($id,$ref='') + { + $object = new Product($this->db); + if (! empty($id) || ! empty($ref)) $object->fetch($id,$ref); + $this->object = $object; + } + /** * Assign custom values for canvas (for example into this->tpl to be used by templates) * - * @param string $action Type of action + * @param string &$action Type of action + * @param string $id Id of object + * @param string $ref Ref of object * @return void */ - function assign_values($action) + function assign_values(&$action, $id=0, $ref='') { - global $conf,$langs,$user; + global $conf, $langs, $user, $mysoc, $canvas; global $html, $formproduct; - // canvas + $ret = $this->getObject($id,$ref); + + //parent::assign_values($action); + + foreach($this->object as $key => $value) + { + $this->tpl[$key] = $value; + } + + $this->tpl['error'] = get_htmloutput_errors($this->object->error,$this->object->errors); + + // canvas $this->tpl['canvas'] = $this->canvas; // id @@ -133,10 +162,16 @@ class ActionsCardProduct extends Product if ($action == 'view') { - // Ref - $this->tpl['ref'] = $html->showrefnav($this,'ref','',1,'ref'); + $head = product_prepare_head($this->object,$user); - // Accountancy buy code + $this->tpl['showrefnav'] = $html->showrefnav($this->object,'ref','',1,'ref'); + + $titre=$langs->trans("CardProduct".$this->object->type); + $picto=($this->object->type==1?'service':'product'); + $this->tpl['showhead']=dol_get_fiche_head($head, 'card', $titre, 0, $picto); + $this->tpl['showend']=dol_get_fiche_end(); + + // Accountancy buy code $this->tpl['accountancyBuyCodeKey'] = $html->editfieldkey("ProductAccountancyBuyCode",'productaccountancycodesell',$this->accountancy_code_sell,'id',$this->id,$user->rights->produit->creer); $this->tpl['accountancyBuyCodeVal'] = $html->editfieldval("ProductAccountancyBuyCode",'productaccountancycodesell',$this->accountancy_code_sell,'id',$this->id,$user->rights->produit->creer); @@ -196,11 +231,6 @@ class ActionsCardProduct extends Product if ($action == 'view') { - $head=product_prepare_head($this->object, $user); - $titre=$langs->trans("CardProduct".$this->object->type); - $picto=($this->object->type==1?'service':'product'); - $this->tpl['fiche_head']=dol_get_fiche_head($head, 'card', $titre, 0, $picto); - // Status $this->tpl['status'] = $this->object->getLibStatut(2,0); $this->tpl['status_buy'] = $this->object->getLibStatut(2,1); diff --git a/htdocs/product/canvas/product/tpl/card_view.tpl.php b/htdocs/product/canvas/product/tpl/card_view.tpl.php index e22d529772b..8b03e20c66c 100755 --- a/htdocs/product/canvas/product/tpl/card_view.tpl.php +++ b/htdocs/product/canvas/product/tpl/card_view.tpl.php @@ -18,7 +18,7 @@ ?> -control->tpl['fiche_head']; ?> +control->tpl['showhead']; ?> control->tpl['error'],$this->control->tpl['errors']); ?> @@ -26,7 +26,7 @@ trans("Ref"); ?> -control->tpl['ref']; ?> +control->tpl['showrefnav']; ?> @@ -88,6 +88,6 @@ -control->tpl['fiche_end']; ?> +control->tpl['showend']; ?> \ No newline at end of file diff --git a/htdocs/product/canvas/service/actions_card_service.class.php b/htdocs/product/canvas/service/actions_card_service.class.php index 7706a5827db..f8262beae6a 100755 --- a/htdocs/product/canvas/service/actions_card_service.class.php +++ b/htdocs/product/canvas/service/actions_card_service.class.php @@ -74,17 +74,45 @@ class ActionsCardService extends Product return $langs->trans("Products"); } + /** + * Get object from id or ref and save it into this->object + * + * @param int $id Object id + * @param string $ref Ojbect ref + * @return Object Object loaded + */ + function getObject($id,$ref='') + { + $object = new Product($this->db); + if (! empty($id) || ! empty($ref)) $object->fetch($id,$ref); + $this->object = $object; + } + + /** * Assign custom values for canvas (for example into this->tpl to be used by templates) * - * @param string $action Type of action + * @param string &$action Type of action + * @param string $id Id of object + * @param string $ref Ref of object * @return void */ - function assign_values($action) + function assign_values(&$action, $id=0, $ref='') { - global $conf,$langs,$user; + global $conf, $langs, $user, $mysoc, $canvas; global $html, $formproduct; + $ret = $this->getObject($id,$ref); + + //parent::assign_values($action); + + foreach($this->object as $key => $value) + { + $this->tpl[$key] = $value; + } + + $this->tpl['error'] = get_htmloutput_errors($this->object->error,$this->object->errors); + // canvas $this->tpl['canvas'] = $this->canvas; @@ -133,8 +161,14 @@ class ActionsCardService extends Product if ($action == 'view') { - // Ref - $this->tpl['ref'] = $html->showrefnav($this,'ref','',1,'ref'); + $head = product_prepare_head($this->object,$user); + + $this->tpl['showrefnav'] = $html->showrefnav($this->object,'ref','',1,'ref'); + + $titre=$langs->trans("CardProduct".$this->object->type); + $picto=($this->object->type==1?'service':'product'); + $this->tpl['showhead']=dol_get_fiche_head($head, 'card', $titre, 0, $picto); + $this->tpl['showend']=dol_get_fiche_end(); // Accountancy buy code $this->tpl['accountancyBuyCodeKey'] = $html->editfieldkey("ProductAccountancyBuyCode",'productaccountancycodesell',$this->accountancy_code_sell,'id',$this->id,$user->rights->produit->creer); @@ -192,11 +226,6 @@ class ActionsCardService extends Product if ($action == 'view') { - $head=product_prepare_head($this->object, $user); - $titre=$langs->trans("CardProduct".$this->object->type); - $picto=($this->object->type==1?'service':'product'); - $this->tpl['fiche_head']=dol_get_fiche_head($head, 'card', $titre, 0, $picto); - // Status $this->tpl['status'] = $this->object->getLibStatut(2,0); $this->tpl['status_buy'] = $this->object->getLibStatut(2,1); diff --git a/htdocs/product/canvas/service/tpl/card_view.tpl.php b/htdocs/product/canvas/service/tpl/card_view.tpl.php index e46548c032a..bac35c05d10 100755 --- a/htdocs/product/canvas/service/tpl/card_view.tpl.php +++ b/htdocs/product/canvas/service/tpl/card_view.tpl.php @@ -18,7 +18,7 @@ ?> -control->tpl['fiche_head']; ?> +control->tpl['showhead']; ?> control->tpl['error'],$this->control->tpl['errors']); ?> @@ -26,7 +26,7 @@ trans("Ref"); ?> -control->tpl['ref']; ?> +control->tpl['showrefnav']; ?> @@ -73,5 +73,5 @@ -control->tpl['fiche_end']; ?> +control->tpl['showend']; ?> \ No newline at end of file diff --git a/htdocs/product/fiche.php b/htdocs/product/fiche.php index db622fdfeda..904a4182f4c 100644 --- a/htdocs/product/fiche.php +++ b/htdocs/product/fiche.php @@ -47,7 +47,7 @@ $mesg = ''; $error=0; $errors=array(); $id=GETPOST('id'); $ref=GETPOST('ref'); -$action=GETPOST('action'); +$action=(GETPOST('action') ? GETPOST('action') : 'view'); $confirm=GETPOST('confirm'); $socid=GETPOST("socid"); if ($user->societe_id) $socid=$user->societe_id; @@ -66,8 +66,8 @@ if (! empty($canvas)) } // Security check -if (isset($id) || isset($ref)) $value = isset($id)?$id:(isset($ref)?$ref:''); -$type = isset($ref)?'ref':'rowid'; +$value = $ref?$ref:$id; +$type = $ref?'ref':'rowid'; $result=restrictedArea($user,'produit|service',$value,'product','','',$type, $objcanvas); // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array @@ -81,7 +81,7 @@ $hookmanager->callHooks(array('product')); * Actions */ -$parameters=array('socid'=>$socid); +$parameters=array('id'=>$id, 'ref'=>$ref, 'objcanvas'=>$objcanvas); $reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks $error=$hookmanager->error; $errors=$hookmanager->errors; @@ -90,7 +90,7 @@ if (empty($reshook)) if ($action == 'setproductaccountancycodebuy') { $product = new Product($db); - $result=$product->fetch($id); + $result=$product->fetch($id,$ref); $product->accountancy_code_buy=$_POST["productaccountancycodebuy"]; $result=$product->update($product->id,$user,1,0,1); if ($result < 0) @@ -105,7 +105,7 @@ if (empty($reshook)) if ($action == 'setproductaccountancycodesell') { $product = new Product($db); - $result=$product->fetch($id); + $result=$product->fetch($id,$ref); $product->accountancy_code_sell=$_POST["productaccountancycodesell"]; $result=$product->update($product->id,$user,1,0,1); if ($result < 0) @@ -118,9 +118,9 @@ if (empty($reshook)) if ($action == 'fastappro') { $product = new Product($db); - $product->fetch($id); - $result = $product->fastappro($user); - Header("Location: fiche.php?id=".$id); + $result=$product->fetch($id,$ref); + $result=$product->fastappro($user); + Header("Location: fiche.php?id=".$product->id); exit; } @@ -229,7 +229,7 @@ if (empty($reshook)) else { $product=new Product($db); - if ($product->fetch($id)) + if ($product->fetch($id,$ref)) { $product->ref = $ref; $product->libelle = $_POST["libelle"]; @@ -288,7 +288,7 @@ if (empty($reshook)) $product = new Product($db); $originalId = $id; - if ($product->fetch($id) > 0) + if ($product->fetch($id,$ref) > 0) { $product->ref = GETPOST('clone_ref'); $product->status = 0; @@ -343,7 +343,7 @@ if (empty($reshook)) if ($action == 'confirm_delete' && $confirm == 'yes') { $object = new Product($db); - $object->fetch($id); + $object->fetch($id,$ref); if ( ($object->type == 0 && $user->rights->produit->supprimer) || ($object->type == 1 && $user->rights->service->supprimer) ) { @@ -384,7 +384,7 @@ if (empty($reshook)) } $prod = new Product($db); - $result=$prod->fetch($id); + $result=$prod->fetch($id,$ref); if ($result <= 0) { dol_print_error($db,$prod->error); @@ -464,7 +464,7 @@ if (empty($reshook)) } $prod = new Product($db); - $result=$prod->fetch($id); + $result=$prod->fetch($id,$ref); if ($result <= 0) { dol_print_error($db,$prod->error); @@ -546,7 +546,7 @@ if (empty($reshook)) } $prod = new Product($db); - $result = $prod->fetch($id); + $result = $prod->fetch($id,$ref); if ($result <= 0) { dol_print_error($db,$prod->error); @@ -635,42 +635,18 @@ llxHeader('',$langs->trans("CardProduct".$_GET["type"]),$helpurl); $html = new Form($db); $formproduct = new FormProduct($db); - -// TODO Mutualize this part of code (same than societe/soc.php and contact/fiche.php) if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) { // ----------------------------------------- // When used with CANVAS // ----------------------------------------- - if ($action == 'create') - { - $objcanvas->assign_values($action); // Set value for templates - $objcanvas->display_canvas($action,0); // Show template - } - elseif ($action == 'edit') - { - $objcanvas->control->object=$objcanvas->getObject($socid); // TODO: Getting and storing object should be done into assign_values (for template with no code) or into tpl - if (empty($objcanvas->control->object)) - { - $object = new Product($db); - $object->fetch($id); - $objcanvas->control->object=$object; - } - $objcanvas->assign_values($action); // Set value for templates - $objcanvas->display_canvas($action); // Show template - } - else - { - $objcanvas->control->object=$objcanvas->getObject($socid); // TODO: Getting and storing object should be done into assign_values (for template with no code) or into tpl - if (empty($objcanvas->control->object)) - { - $object = new Product($db); - $object->fetch($id); - $objcanvas->control->object=$object; - } - $objcanvas->assign_values('view'); - $objcanvas->display_canvas('view'); // Show template - } + if (! $objcanvas->hasActions() && ($id || $ref)) + { + $object = new Product($db); + $object->fetch($id, $ref); // For use with "pure canvas" (canvas that contains templates only) + } + $objcanvas->assign_values($action, $id, $ref); // Set value for templates + $objcanvas->display_canvas(); // Show template } else { diff --git a/htdocs/societe/canvas/actions_card_common.class.php b/htdocs/societe/canvas/actions_card_common.class.php index c8d0591f61e..a3c25e33478 100644 --- a/htdocs/societe/canvas/actions_card_common.class.php +++ b/htdocs/societe/canvas/actions_card_common.class.php @@ -60,10 +60,10 @@ abstract class ActionsCardCommon $this->canvas = $canvas; $this->card = $card; } - + /** * Instantiation of DAO class - * + * * @return void */ private function getInstanceDao() @@ -84,25 +84,26 @@ abstract class ActionsCardCommon } } } - + /** - * Get object + * Get object from id or ref and save it into this->object * * @param int Object id + * @param ref Object ref * @return object Object loaded */ - function getObject($id) + function getObject($id,$ref='') { $ret = $this->getInstanceDao(); - + if (is_object($this->object) && method_exists($this->object,'fetch')) { - if (! empty($id)) $this->object->fetch($id); + if (! empty($id) || ! empty($ref)) $this->object->fetch($id,$ref); } else { $object = new Societe($this->db); - if (! empty($id)) $object->fetch($id); + if (! empty($id) || ! empty($ref)) $object->fetch($id,$ref); $this->object = $object; } } @@ -297,7 +298,7 @@ abstract class ActionsCardCommon Header("Location: ".$_SERVER["PHP_SELF"]."?socid=".$this->object->id); exit; } - + $oldsoccanvas = dol_clone($this->object); // To avoid setting code if third party is not concerned. But if it had values, we keep them. @@ -379,12 +380,14 @@ abstract class ActionsCardCommon } /** - * Set content of ->tpl array, to use into template - * - * @param string $action Type of action - * @return string HTML output + * Assign custom values for canvas (for example into this->tpl to be used by templates) + * + * @param string &$action Type of action + * @param string $id Id of object + * @param string $ref Ref of object + * @return void */ - function assign_values(&$action) + function assign_values(&$action, $id=0, $ref='') { global $conf, $langs, $user, $mysoc, $canvas; global $form, $formadmin, $formcompany; diff --git a/htdocs/societe/canvas/company/actions_card_company.class.php b/htdocs/societe/canvas/company/actions_card_company.class.php index b7e6e344e15..1238894b885 100644 --- a/htdocs/societe/canvas/company/actions_card_company.class.php +++ b/htdocs/societe/canvas/company/actions_card_company.class.php @@ -81,7 +81,7 @@ class ActionsCardCompany extends ActionsCardCommon function doActions(&$action, $id) { $ret = $this->getObject($id); - + $return = parent::doActions($action); return $return; @@ -90,18 +90,20 @@ class ActionsCardCompany extends ActionsCardCommon /** * Assign custom values for canvas (for example into this->tpl to be used by templates) * - * @param string $action Type of action + * @param string &$action Type of action + * @param string $id Id of object + * @param string $ref Ref of object * @return void */ - function assign_values(&$action, $id) + function assign_values(&$action, $id=0, $ref='') { global $conf, $langs, $user, $mysoc; global $form, $formadmin, $formcompany; - - $ret = $this->getObject($id); + + $ret = $this->getObject($id,$ref); parent::assign_values($action); - + $this->tpl['title'] = $this->getTitle($action); $this->tpl['profid1'] = $this->object->siren; diff --git a/htdocs/societe/canvas/individual/actions_card_individual.class.php b/htdocs/societe/canvas/individual/actions_card_individual.class.php index fc6d183cb8f..27982f3026d 100644 --- a/htdocs/societe/canvas/individual/actions_card_individual.class.php +++ b/htdocs/societe/canvas/individual/actions_card_individual.class.php @@ -81,27 +81,29 @@ class ActionsCardIndividual extends ActionsCardCommon function doActions(&$action, $id) { $ret = $this->getObject($id); - + $return = parent::doActions($action); return $return; } /** - * Assign custom values for canvas (for example into this->tpl to be used by templates) + * Assign custom values for canvas (for example into this->tpl to be used by templates) * - * @param string $action Type of action - * @return void + * @param string &$action Type of action + * @param string $id Id of object + * @param string $ref Ref of object + * @return void */ - function assign_values(&$action, $id) + function assign_values(&$action, $id=0, $ref='') { global $conf, $langs; global $form, $formcompany; - - $ret = $this->getObject($id); + + $ret = $this->getObject($id,$ref); parent::assign_values($action); - + $this->tpl['title'] = $this->getTitle($action); if ($action == 'create' || $action == 'edit')