From f5c551d7255c47348e1e79da0662af4743cd6e66 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 3 Mar 2012 19:02:44 +0100 Subject: [PATCH] New: Can use personalized fields of products/services. --- ChangeLog | 3 ++- htdocs/product/class/product.class.php | 34 ++++++++++++++++------- htdocs/product/fiche.php | 37 +++++++++++++++++++------- 3 files changed, 54 insertions(+), 20 deletions(-) diff --git a/ChangeLog b/ChangeLog index ba13be8ba5a..dc14290ae1c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -5,9 +5,10 @@ English Dolibarr ChangeLog ***** ChangeLog for 3.2 compared to 3.1 ***** WARNING: PHP lower than 5.x are no more supported. WARNING: Because of a major datastructure change onto supplier prices tabkes, be aware -to make a backup of your datbase before making upgrade. +to make a backup of your database before making upgrade. For users: +- New: Can use personalized fields of products/services. - New: Can attach files on social contributions. - New: Show payments terms and conditions onto muscadet template. - New: Can open back a closed commercial proposal. diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index 54158d9e672..b1140ac5740 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -463,7 +463,7 @@ class Product extends CommonObject $sql.= ",accountancy_code_sell= '" . $this->accountancy_code_sell."'"; $sql.= " WHERE rowid = " . $id; - dol_syslog("Product::update sql=".$sql); + dol_syslog(get_class($this)."update sql=".$sql); $resql=$this->db->query($sql); if ($resql) { @@ -479,7 +479,23 @@ class Product extends CommonObject } } - if (! $notrigger) + // Actions on extra fields (by external module or standard code) + include_once(DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'); + $hookmanager=new HookManager($this->db); + $hookmanager->initHooks(array('productdao')); + $parameters=array('id'=>$this->id); + $reshook=$hookmanager->executeHooks('insertExtraFields',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks + if (empty($reshook)) + { + $result=$this->insertExtraFields(); + if ($result < 0) + { + $error++; + } + } + else if ($reshook < 0) $error++; + + if (! $error && ! $notrigger) { // Appel des triggers include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php"); @@ -735,7 +751,7 @@ class Product extends CommonObject $sql.= " ".$this->localtax1_tx.",".$this->localtax2_tx.",".$this->price_min.",".$this->price_min_ttc; $sql.= ")"; - dol_syslog("Product::_log_price sql=".$sql); + dol_syslog(get_class($this)."_log_price sql=".$sql); $resql=$this->db->query($sql); if(! $resql) { @@ -762,7 +778,7 @@ class Product extends CommonObject $sql = "DELETE FROM ".MAIN_DB_PREFIX."product_price"; $sql.= " WHERE rowid=".$rowid; - dol_syslog("Product::log_price_delete sql=".$sql, LOG_DEBUG); + dol_syslog(get_class($this)."log_price_delete sql=".$sql, LOG_DEBUG); $resql=$this->db->query($sql); if ($resql) { @@ -796,7 +812,7 @@ class Product extends CommonObject $sql.= " WHERE pfp.rowid = ".$prodfournprice; $sql.= " AND pfp.quantity <= ".$qty; - dol_syslog("Product::get_buyprice sql=".$sql); + dol_syslog(get_class($this)."get_buyprice sql=".$sql); $resql = $this->db->query($sql); if ($resql) { @@ -821,7 +837,7 @@ class Product extends CommonObject $sql.= " ORDER BY pfp.quantity DESC"; $sql.= " LIMIT 1"; - dol_syslog("Product::get_buyprice sql=".$sql); + dol_syslog(get_class($this)."get_buyprice sql=".$sql); $resql = $this->db->query($sql); if ($resql) { @@ -873,7 +889,7 @@ class Product extends CommonObject { global $conf,$langs; - dol_syslog("Product::update_price id=".$id." newprice=".$newprice." newpricebase=".$newpricebase." newminprice=".$newminprice." level=".$level." npr=".$newnpr); + dol_syslog(get_class($this)."update_price id=".$id." newprice=".$newprice." newpricebase=".$newpricebase." newminprice=".$newminprice." level=".$level." npr=".$newnpr); // Clean parameters if (empty($this->tva_tx)) $this->tva_tx=0; @@ -943,7 +959,7 @@ class Product extends CommonObject $sql.= " recuperableonly='".$newnpr."'"; $sql.= " WHERE rowid = ".$id; - dol_syslog("Product::update_price sql=".$sql, LOG_DEBUG); + dol_syslog(get_class($this)."update_price sql=".$sql, LOG_DEBUG); $resql=$this->db->query($sql); if ($resql) { @@ -1783,7 +1799,7 @@ class Product extends CommonObject $sql.= ", ".$user->id; $sql.= ")"; - dol_syslog("Product::add_fournisseur sql=".$sql); + dol_syslog(get_class($this)."add_fournisseur sql=".$sql); if ($this->db->query($sql)) { $this->product_fourn_price_id = $this->db->last_insert_id(MAIN_DB_PREFIX."product_fournisseur_price"); diff --git a/htdocs/product/fiche.php b/htdocs/product/fiche.php index 7d0adf0926f..b24bce1e703 100644 --- a/htdocs/product/fiche.php +++ b/htdocs/product/fiche.php @@ -118,8 +118,6 @@ if (empty($reshook)) $mesg=join(',',$product->errors); } $action=""; - $id=$_POST["id"]; - $_GET["id"]=$_POST["id"]; } if ($action == 'setproductaccountancycodesell') @@ -214,6 +212,15 @@ if (empty($reshook)) } } + // Get extra fields + foreach($_POST as $key => $value) + { + if (preg_match("/^options_/",$key)) + { + $product->array_options[$key]=$_POST[$key]; + } + } + $id = $product->create($user); if ($id > 0) @@ -265,6 +272,15 @@ if (empty($reshook)) $product->finished = $_POST["finished"]; $product->hidden = $_POST["hidden"]=='yes'?1:0; + // Get extra fields + foreach($_POST as $key => $value) + { + if (preg_match("/^options_/",$key)) + { + $product->array_options[$key]=$_POST[$key]; + } + } + if ($product->check()) { if ($product->update($product->id, $user) > 0) @@ -628,7 +644,7 @@ if (empty($reshook)) if (GETPOST("cancel") == $langs->trans("Cancel")) { $action = ''; - Header("Location: ".$_SERVER["PHP_SELF"]."?id=".$_POST["id"]); + Header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id); exit; } @@ -847,7 +863,9 @@ else else if ($id || $ref) { $object=new Product($db); - $object->fetch($id,$ref); + $res=$object->fetch($id,$ref); + if ($res < 0) { dol_print_error($db,$object->error); exit; } + $res=$object->fetch_optionals($id,$extralabels); /* * Fiche en mode edition @@ -1046,7 +1064,7 @@ else // Label print ''.$langs->trans("Label").''.$object->libelle.''; - $nblignes=9; + $nblignes=8; if ($object->type!=1) $nblignes++; if ($object->isservice()) $nblignes++; else $nblignes+=4; @@ -1212,7 +1230,7 @@ else print ''.$langs->trans("CountryOrigin").''.getCountry($object->country_id,0,$db).''; // Other attributes - $parameters=array('colspan' => ' colspan="2"'); + $parameters=array('colspan' => ' colspan="'.(2+(($showphoto||$showbarcode)?1:0)).'"'); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook if (empty($reshook) && ! empty($extrafields->attribute_label)) { @@ -1220,13 +1238,13 @@ else { $value=(isset($_POST["options_".$key])?$_POST["options_".$key]:$object->array_options["options_".$key]); print ''.$label.''; - print $extrafields->showInputField($key,$value); + print $extrafields->showOutputField($key,$value); print ''."\n"; } } // Note - print ''.$langs->trans("Note").''.(dol_textishtml($object->note)?$object->note:dol_nl2br($object->note,1,true)).''; + print ''.$langs->trans("Note").''.(dol_textishtml($object->note)?$object->note:dol_nl2br($object->note,1,true)).''; print "\n"; @@ -1709,8 +1727,7 @@ if ($object->id && ($action == '' || $action == 'view') && $object->status) -$db->close(); - llxFooter(); +$db->close(); ?>