From 452636b0e41ac0f6ffd9cb19aa1e16504d65bdcf Mon Sep 17 00:00:00 2001 From: Maxime Kohlhaas Date: Tue, 14 Oct 2014 15:27:40 +0200 Subject: [PATCH 1/5] New : Add option to allow extrafield to be modified regardless of the document status --- htdocs/comm/propal.php | 13 ++++++---- htdocs/core/actions_extrafields.inc.php | 4 ++-- htdocs/core/class/extrafields.class.php | 24 ++++++++++++------- htdocs/core/tpl/admin_extrafields_add.tpl.php | 2 ++ .../core/tpl/admin_extrafields_edit.tpl.php | 3 +++ .../install/mysql/migration/3.6.0-3.7.0.sql | 2 ++ .../install/mysql/tables/llx_extrafields.sql | 3 ++- 7 files changed, 35 insertions(+), 16 deletions(-) diff --git a/htdocs/comm/propal.php b/htdocs/comm/propal.php index b344da39112..1f211c3cb79 100644 --- a/htdocs/comm/propal.php +++ b/htdocs/comm/propal.php @@ -2032,9 +2032,16 @@ if ($action == 'create') } else { - print ''; + print 'attribute_required [$key])) print ' class="fieldrequired"'; - print '>' . $label . ''; + if (($object->statut == 0 || $extrafields->attribute_alwayseditable[$key]) && $user->rights->propal->creer && ($action != 'edit_extras' || GETPOST('attribute') != $key)) + print ''; + + print '
'; + print '>' . $label . '' . img_edit().'
'; + print ''; + // Convert date into timestamp format if (in_array($extrafields->attribute_type [$key], array('date','datetime'))) { $value = isset($_POST ["options_" . $key]) ? dol_mktime($_POST ["options_" . $key . "hour"], $_POST ["options_" . $key . "min"], 0, $_POST ["options_" . $key . "month"], $_POST ["options_" . $key . "day"], $_POST ["options_" . $key . "year"]) : $db->jdate($object->array_options ['options_' . $key]); @@ -2057,8 +2064,6 @@ if ($action == 'create') else { print $extrafields->showOutputField($key, $value); - if ($object->statut == 0 && $user->rights->propal->creer) - print '' . img_picto('', 'edit') . ' ' . $langs->trans('Modify') . ''; } print '' . "\n"; } diff --git a/htdocs/core/actions_extrafields.inc.php b/htdocs/core/actions_extrafields.inc.php index 89edfcbae8e..d5f8ea7c18c 100644 --- a/htdocs/core/actions_extrafields.inc.php +++ b/htdocs/core/actions_extrafields.inc.php @@ -141,7 +141,7 @@ if ($action == 'add') } } - $result=$extrafields->addExtraField($_POST['attrname'],$_POST['label'],$_POST['type'],$_POST['pos'],$extrasize,$elementtype,(GETPOST('unique')?1:0),(GETPOST('required')?1:0),$default_value,$params); + $result=$extrafields->addExtraField($_POST['attrname'],$_POST['label'],$_POST['type'],$_POST['pos'],$extrasize,$elementtype,(GETPOST('unique')?1:0),(GETPOST('required')?1:0),$default_value,$params,(GETPOST('alwayseditable')?1:0)); if ($result > 0) { setEventMessage($langs->trans('SetupSaved')); @@ -278,7 +278,7 @@ if ($action == 'update') $params['options'][$key] = $value; } } - $result=$extrafields->update($_POST['attrname'],$_POST['label'],$_POST['type'],$extrasize,$elementtype,(GETPOST('unique')?1:0),(GETPOST('required')?1:0),$pos,$params); + $result=$extrafields->update($_POST['attrname'],$_POST['label'],$_POST['type'],$extrasize,$elementtype,(GETPOST('unique')?1:0),(GETPOST('required')?1:0),$pos,$params,(GETPOST('alwayseditable')?1:0)); if ($result > 0) { setEventMessage($langs->trans('SetupSaved')); diff --git a/htdocs/core/class/extrafields.class.php b/htdocs/core/class/extrafields.class.php index 42c505a54bf..9075cac94e3 100644 --- a/htdocs/core/class/extrafields.class.php +++ b/htdocs/core/class/extrafields.class.php @@ -50,6 +50,8 @@ class ExtraFields var $attribute_param; // Int to store position of attribute var $attribute_pos; + // Int to store if attribute is editable regardless of the document status + var $attribute_alwayseditable; var $error; var $errno; @@ -105,7 +107,7 @@ class ExtraFields * @param array $param Params for field * @return int <=0 if KO, >0 if OK */ - function addExtraField($attrname, $label, $type, $pos, $size, $elementtype, $unique=0, $required=0,$default_value='', $param=0) + function addExtraField($attrname, $label, $type, $pos, $size, $elementtype, $unique=0, $required=0, $default_value='', $param=0, $alwayseditable=0) { if (empty($attrname)) return -1; if (empty($label)) return -1; @@ -119,7 +121,7 @@ class ExtraFields if ($result > 0 || $err1 == 'DB_ERROR_COLUMN_ALREADY_EXISTS' || $type == 'separate') { // Add declaration of field into table - $result2=$this->create_label($attrname,$label,$type,$pos,$size,$elementtype, $unique, $required, $param); + $result2=$this->create_label($attrname,$label,$type,$pos,$size,$elementtype, $unique, $required, $param, $alwayseditable); $err2=$this->errno; if ($result2 > 0 || ($err1 == 'DB_ERROR_COLUMN_ALREADY_EXISTS' && $err2 == 'DB_ERROR_RECORD_ALREADY_EXISTS')) { @@ -219,7 +221,7 @@ class ExtraFields * @param array||string $param Params for field (ex for select list : array('options' => array(value'=>'label of option')) ) * @return int <=0 if KO, >0 if OK */ - private function create_label($attrname, $label='', $type='', $pos=0, $size=0, $elementtype='member', $unique=0, $required=0, $param='') + private function create_label($attrname, $label='', $type='', $pos=0, $size=0, $elementtype='member', $unique=0, $required=0, $param='', $alwayseditable=0) { global $conf; @@ -241,7 +243,7 @@ class ExtraFields $params=''; } - $sql = "INSERT INTO ".MAIN_DB_PREFIX."extrafields(name, label, type, pos, size, entity, elementtype, fieldunique, fieldrequired, param)"; + $sql = "INSERT INTO ".MAIN_DB_PREFIX."extrafields(name, label, type, pos, size, entity, elementtype, fieldunique, fieldrequired, param, alwayseditable)"; $sql.= " VALUES('".$attrname."',"; $sql.= " '".$this->db->escape($label)."',"; $sql.= " '".$type."',"; @@ -251,7 +253,8 @@ class ExtraFields $sql.= " '".$elementtype."',"; $sql.= " '".$unique."',"; $sql.= " '".$required."',"; - $sql.= " '".$params."'"; + $sql.= " '".$params."',"; + $sql.= " '".$alwayseditable."'"; $sql.=')'; dol_syslog(get_class($this)."::create_label", LOG_DEBUG); @@ -349,7 +352,7 @@ class ExtraFields * @param array $param Params for field (ex for select list : array('options' => array(value'=>'label of option')) ) * @return int >0 if OK, <=0 if KO */ - function update($attrname,$label,$type,$length,$elementtype,$unique=0,$required=0,$pos=0,$param='') + function update($attrname,$label,$type,$length,$elementtype,$unique=0,$required=0,$pos=0,$param='',$alwayseditable=0) { $table=$elementtype.'_extrafields'; @@ -384,7 +387,7 @@ class ExtraFields { if ($label) { - $result=$this->update_label($attrname,$label,$type,$length,$elementtype,$unique,$required,$pos,$param); + $result=$this->update_label($attrname,$label,$type,$length,$elementtype,$unique,$required,$pos,$param,$alwayseditable); } if ($result > 0) { @@ -434,7 +437,7 @@ class ExtraFields * @param array $param Params for field (ex for select list : array('options' => array(value'=>'label of option')) ) * @return int <=0 if KO, >0 if OK */ - private function update_label($attrname,$label,$type,$size,$elementtype,$unique=0,$required=0,$pos=0,$param='') + private function update_label($attrname,$label,$type,$size,$elementtype,$unique=0,$required=0,$pos=0,$param='',$alwayseditable=0) { global $conf; dol_syslog(get_class($this)."::update_label ".$attrname.", ".$label.", ".$type.", ".$size.", ".$elementtype.", ".$unique.", ".$required); @@ -465,6 +468,7 @@ class ExtraFields $sql.= " fieldunique,"; $sql.= " fieldrequired,"; $sql.= " pos,"; + $sql.= " alwayseditable,"; $sql.= " param"; $sql.= ") VALUES ("; $sql.= "'".$attrname."',"; @@ -476,6 +480,7 @@ class ExtraFields $sql.= " '".$unique."',"; $sql.= " '".$required."',"; $sql.= " '".$pos."',"; + $sql.= " '".$alwayseditable."',"; $sql.= " '".$param."'"; $sql.= ")"; dol_syslog(get_class($this)."::update_label", LOG_DEBUG); @@ -529,7 +534,7 @@ class ExtraFields if (!$forceload && !empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) return $array_name_label; - $sql = "SELECT rowid,name,label,type,size,elementtype,fieldunique,fieldrequired,param,pos"; + $sql = "SELECT rowid,name,label,type,size,elementtype,fieldunique,fieldrequired,param,pos,alwayseditable"; $sql.= " FROM ".MAIN_DB_PREFIX."extrafields"; $sql.= " WHERE entity IN (0,".$conf->entity.")"; if ($elementtype) $sql.= " AND elementtype = '".$elementtype."'"; @@ -557,6 +562,7 @@ class ExtraFields $this->attribute_required[$tab->name]=$tab->fieldrequired; $this->attribute_param[$tab->name]=unserialize($tab->param); $this->attribute_pos[$tab->name]=$tab->pos; + $this->attribute_alwayseditable[$tab->name]=$tab->alwayseditable; } } diff --git a/htdocs/core/tpl/admin_extrafields_add.tpl.php b/htdocs/core/tpl/admin_extrafields_add.tpl.php index e4c4d75c85e..bdced511867 100644 --- a/htdocs/core/tpl/admin_extrafields_add.tpl.php +++ b/htdocs/core/tpl/admin_extrafields_add.tpl.php @@ -101,6 +101,8 @@ trans("Unique"); ?>> trans("Required"); ?>> + +trans("AlwaysEditable"); ?>>

">   diff --git a/htdocs/core/tpl/admin_extrafields_edit.tpl.php b/htdocs/core/tpl/admin_extrafields_edit.tpl.php index e24a3e86948..dcf1af56ed1 100644 --- a/htdocs/core/tpl/admin_extrafields_edit.tpl.php +++ b/htdocs/core/tpl/admin_extrafields_edit.tpl.php @@ -54,6 +54,7 @@ $size=$extrafields->attribute_size[$attrname]; $unique=$extrafields->attribute_unique[$attrname]; $required=$extrafields->attribute_required[$attrname]; $pos=$extrafields->attribute_pos[$attrname]; +$alwayseditable=$extrafields->attribute_alwayseditable[$attrname]; $param=$extrafields->attribute_param[$attrname]; if((($type == 'select') || ($type == 'checkbox') ||(($type == 'radio'))) && is_array($param)) @@ -110,6 +111,8 @@ if(($type == 'select') || ($type == 'sellist') || ($type == 'checkbox') ||(($typ trans("Unique"); ?>> trans("Required"); ?>> + +trans("AlwaysEditable"); ?>> diff --git a/htdocs/install/mysql/migration/3.6.0-3.7.0.sql b/htdocs/install/mysql/migration/3.6.0-3.7.0.sql index 5e633eb2660..dfbf0676eae 100644 --- a/htdocs/install/mysql/migration/3.6.0-3.7.0.sql +++ b/htdocs/install/mysql/migration/3.6.0-3.7.0.sql @@ -1096,3 +1096,5 @@ DELETE FROM llx_const WHERE name = 'MAIN_MODULE_BOUTIQUE'; DELETE FROM llx_const WHERE name = 'OSC_DB_HOST'; DELETE FROM llx_menu WHERE module = 'boutique'; +-- Add option always editable on extrafield +ALTER TABLE llx_extrafields ADD alwayseditable INT(11) NOT NULL AFTER pos; \ No newline at end of file diff --git a/htdocs/install/mysql/tables/llx_extrafields.sql b/htdocs/install/mysql/tables/llx_extrafields.sql index ba4c7df964f..04963eb3905 100644 --- a/htdocs/install/mysql/tables/llx_extrafields.sql +++ b/htdocs/install/mysql/tables/llx_extrafields.sql @@ -22,7 +22,7 @@ create table llx_extrafields rowid integer AUTO_INCREMENT PRIMARY KEY, name varchar(64) NOT NULL, -- nom de l'attribut entity integer DEFAULT 1 NOT NULL, -- multi company id - elementtype varchar(64) NOT NULL DEFAULT 'member', + elementtype varchar(64) NOT NULL DEFAULT 'member', tms timestamp, label varchar(255) NOT NULL, -- label correspondant a l'attribut type varchar(8), @@ -30,5 +30,6 @@ create table llx_extrafields fieldunique integer DEFAULT 0, fieldrequired integer DEFAULT 0, pos integer DEFAULT 0, + alwayseditable integer DEFAULT 0, param text )ENGINE=innodb; From 68179c8794daf5063c18d857ea7fb52ac1835d22 Mon Sep 17 00:00:00 2001 From: Maxime Kohlhaas Date: Tue, 14 Oct 2014 16:13:17 +0200 Subject: [PATCH 2/5] Always editable option for extrafields on invoice and order --- htdocs/commande/card.php | 19 +++++++++++++------ htdocs/compta/facture.php | 14 ++++++++++---- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/htdocs/commande/card.php b/htdocs/commande/card.php index 136ade4df3c..f39d827b03e 100644 --- a/htdocs/commande/card.php +++ b/htdocs/commande/card.php @@ -618,7 +618,7 @@ else if ($action == 'addline' && $user->rights->commande->creer) { $filter = array('t.fk_product' => $prod->id,'t.fk_soc' => $object->thirdparty->id); $result = $prodcustprice->fetch_all('', '', 0, 0, $filter); - if ($result >= 0) + if ($result >= 0) { if (count($prodcustprice->lines) > 0) { @@ -628,9 +628,9 @@ else if ($action == 'addline' && $user->rights->commande->creer) { $prod->tva_tx = $prodcustprice->lines [0]->tva_tx; } } - else - { - setEventMessage($prodcustprice->error,'errors'); + else + { + setEventMessage($prodcustprice->error,'errors'); } } @@ -2152,9 +2152,16 @@ if ($action == 'create' && $user->rights->commande->creer) { } else { - print ''; + print 'attribute_required [$key])) print ' class="fieldrequired"'; - print '>' . $label . ''; + if (($object->statut == 0 || $extrafields->attribute_alwayseditable[$key]) && $user->rights->propal->creer && ($action != 'edit_extras' || GETPOST('attribute') != $key)) + print ''; + + print '
'; + print '>' . $label . '' . img_edit().'
'; + print ''; + // Convert date into timestamp format if (in_array($extrafields->attribute_type [$key], array('date','datetime'))) { diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index 245f187d166..22246fc8f03 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -3341,10 +3341,16 @@ if ($action == 'create') if ($extrafields->attribute_type [$key] == 'separate') { print $extrafields->showSeparator($key); } else { - print 'attribute_required [$key])) - print ' class="fieldrequired"'; - print '>' . $label . ''; + print ''; + print 'attribute_required [$key])) print ' class="fieldrequired"'; + print '>' . $label . ''; + if (($object->statut == 0 || $extrafields->attribute_alwayseditable[$key]) && $user->rights->propal->creer && ($action != 'edit_extras' || GETPOST('attribute') != $key)) + print ''; + + print '
' . img_edit().'
'; + print ''; + // Convert date into timestamp format if (in_array($extrafields->attribute_type [$key], array('date','datetime'))) { $value = isset($_POST["options_" . $key]) ? dol_mktime($_POST["options_" . $key . "hour"], $_POST["options_" . $key . "min"], 0, $_POST["options_" . $key . "month"], $_POST["options_" . $key . "day"], $_POST["options_" . $key . "year"]) : $db->jdate($object->array_options ['options_' . $key]); From ee4b807a5d1512aa62b33f1f4d096cfb79654776 Mon Sep 17 00:00:00 2001 From: Maxime Kohlhaas Date: Tue, 14 Oct 2014 17:00:06 +0200 Subject: [PATCH 3/5] Qual : refactoring extrafields display on objects into a single tpl file --- htdocs/comm/propal.php | 64 +------------- htdocs/commande/card.php | 64 +------------- htdocs/compta/facture.php | 55 +----------- htdocs/contrat/card.php | 48 +---------- htdocs/core/tpl/extrafields_view.tpl.php | 83 +++++++++++++++++++ htdocs/fichinter/card.php | 46 +--------- .../fourn/class/fournisseur.facture.class.php | 9 ++ htdocs/fourn/commande/card.php | 75 +---------------- htdocs/fourn/facture/card.php | 49 ++++++++++- 9 files changed, 155 insertions(+), 338 deletions(-) create mode 100644 htdocs/core/tpl/extrafields_view.tpl.php diff --git a/htdocs/comm/propal.php b/htdocs/comm/propal.php index 1f211c3cb79..6cd70b273be 100644 --- a/htdocs/comm/propal.php +++ b/htdocs/comm/propal.php @@ -2008,67 +2008,9 @@ if ($action == 'create') print ''; } - // Other attributes (TODO Move this into an include) - $res = $object->fetch_optionals($object->id, $extralabels); - $parameters = array('colspan' => ' colspan="3"'); - $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)) - { - foreach ($extrafields->attribute_label as $key => $label) - { - if ($action == 'edit_extras') - { - $value = (isset($_POST ["options_" . $key]) ? $_POST ["options_" . $key] : $object->array_options ["options_" . $key]); - } - else - { - $value = $object->array_options ["options_" . $key]; - } - if ($extrafields->attribute_type [$key] == 'separate') - { - print $extrafields->showSeparator($key); - } - else - { - print ''; - print 'attribute_required [$key])) print ' class="fieldrequired"'; - print '>' . $label . ''; - if (($object->statut == 0 || $extrafields->attribute_alwayseditable[$key]) && $user->rights->propal->creer && ($action != 'edit_extras' || GETPOST('attribute') != $key)) - print ''; - - print '
' . img_edit().'
'; - print ''; - - // Convert date into timestamp format - if (in_array($extrafields->attribute_type [$key], array('date','datetime'))) { - $value = isset($_POST ["options_" . $key]) ? dol_mktime($_POST ["options_" . $key . "hour"], $_POST ["options_" . $key . "min"], 0, $_POST ["options_" . $key . "month"], $_POST ["options_" . $key . "day"], $_POST ["options_" . $key . "year"]) : $db->jdate($object->array_options ['options_' . $key]); - } - - if ($action == 'edit_extras' && $user->rights->propal->creer && GETPOST('attribute') == $key) - { - print '
'; - print ''; - print ''; - print ''; - print ''; - - print $extrafields->showInputField($key, $value); - - print ''; - - print '
'; - } - else - { - print $extrafields->showOutputField($key, $value); - } - print '' . "\n"; - } - } - } + // Other attributes + $cols = 3; + include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php'; // Amount HT print '' . $langs->trans('AmountHT') . ''; diff --git a/htdocs/commande/card.php b/htdocs/commande/card.php index f39d827b03e..60e5d81e37a 100644 --- a/htdocs/commande/card.php +++ b/htdocs/commande/card.php @@ -2130,67 +2130,9 @@ if ($action == 'create' && $user->rights->commande->creer) { print ''; } - // Other attributes (TODO Move this into an include) - $parameters = array('colspan' => ' colspan="3"'); - $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)) - { - foreach ($extrafields->attribute_label as $key => $label) - { - if ($action == 'edit_extras') - { - $value = (isset($_POST["options_".$key])?$_POST["options_".$key]:$object->array_options["options_".$key]); - } - else - { - $value = $object->array_options["options_" . $key]; - } - - if ($extrafields->attribute_type[$key] == 'separate') - { - print $extrafields->showSeparator($key); - } - else - { - print ''; - print 'attribute_required [$key])) print ' class="fieldrequired"'; - print '>' . $label . ''; - if (($object->statut == 0 || $extrafields->attribute_alwayseditable[$key]) && $user->rights->propal->creer && ($action != 'edit_extras' || GETPOST('attribute') != $key)) - print ''; - - print '
' . img_edit().'
'; - print ''; - - // Convert date into timestamp format - if (in_array($extrafields->attribute_type [$key], array('date','datetime'))) - { - $value = isset($_POST["options_" . $key]) ? dol_mktime($_POST["options_" . $key . "hour"], $_POST["options_" . $key . "min"], 0, $_POST["options_" . $key . "month"], $_POST["options_" . $key . "day"], $_POST["options_" . $key . "year"]) : $db->jdate($object->array_options ['options_' . $key]); - } - - if ($action == 'edit_extras' && $user->rights->commande->creer && GETPOST('attribute') == $key) - { - print '
'; - print ''; - print ''; - print ''; - print ''; - - print $extrafields->showInputField($key, $value); - - print ''; - print '
'; - } - else - { - print $extrafields->showOutputField($key, $value); - if ($object->statut == 0 && $user->rights->commande->creer) - print '' . img_picto('', 'edit') . ' ' . $langs->trans('Modify') . ''; - } - print '' . "\n"; - } - } - } + // Other attributes + $cols = 3; + include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php'; $rowspan = 4; if ($mysoc->localtax1_assuj == "1" || $object->total_localtax1 != 0) diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index 22246fc8f03..eb4ca29f022 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -3324,58 +3324,9 @@ if ($action == 'create') print ''; } - // Other attributes (TODO Move this into an include) - $res = $object->fetch_optionals($object->id, $extralabels); - $parameters = array('colspan' => ' colspan="5"', "cols" => 5); - $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)) - { - foreach ($extrafields->attribute_label as $key => $label) - { - if ($action == 'edit_extras') { - $value = (isset($_POST["options_" . $key]) ? $_POST["options_" . $key] : $object->array_options ["options_" . $key]); - } else { - $value = $object->array_options ["options_" . $key]; - } - if ($extrafields->attribute_type [$key] == 'separate') { - print $extrafields->showSeparator($key); - } else { - print ''; - print 'attribute_required [$key])) print ' class="fieldrequired"'; - print '>' . $label . ''; - if (($object->statut == 0 || $extrafields->attribute_alwayseditable[$key]) && $user->rights->propal->creer && ($action != 'edit_extras' || GETPOST('attribute') != $key)) - print ''; - - print '
' . img_edit().'
'; - print ''; - - // Convert date into timestamp format - if (in_array($extrafields->attribute_type [$key], array('date','datetime'))) { - $value = isset($_POST["options_" . $key]) ? dol_mktime($_POST["options_" . $key . "hour"], $_POST["options_" . $key . "min"], 0, $_POST["options_" . $key . "month"], $_POST["options_" . $key . "day"], $_POST["options_" . $key . "year"]) : $db->jdate($object->array_options ['options_' . $key]); - } - - if ($action == 'edit_extras' && $user->rights->facture->creer && GETPOST('attribute') == $key) { - print '
'; - print ''; - print ''; - print ''; - print ''; - - print $extrafields->showInputField($key, $value); - - print ''; - print '
'; - } else { - print $extrafields->showOutputField($key, $value); - if ($object->statut == 0 && $user->rights->facture->creer) - print '' . img_picto('', 'edit') . ' ' . $langs->trans('Modify') . ''; - } - print '' . "\n"; - } - } - } + // Other attributes + $cols = 5; + include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php'; print '
'; diff --git a/htdocs/contrat/card.php b/htdocs/contrat/card.php index 1b47912fa41..af5f83cdbde 100644 --- a/htdocs/contrat/card.php +++ b/htdocs/contrat/card.php @@ -1189,52 +1189,8 @@ else } // Other attributes - $parameters=array('colspan' => ' colspan="3"'); - $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook - - $res = $object->fetch_optionals($object->id, $extralabels); - if (empty($reshook) && ! empty($extrafields->attribute_label)) { - foreach ($extrafields->attribute_label as $key => $label) { - if ($action == 'edit_extras') { - $value = (isset($_POST ["options_" . $key]) ? $_POST ["options_" . $key] : $object->array_options ["options_" . $key]); - } else { - $value = $object->array_options ["options_" . $key]; - } - if ($extrafields->attribute_type [$key] == 'separate') { - print $extrafields->showSeparator($key); - } else { - print 'attribute_required [$key])) - print ' class="fieldrequired"'; - print '>' . $label . ''; - // Convert date into timestamp format - if (in_array($extrafields->attribute_type [$key], array('date','datetime'))) { - $value = isset($_POST ["options_" . $key]) ? dol_mktime($_POST ["options_" . $key . "hour"], $_POST ["options_" . $key . "min"], 0, $_POST ["options_" . $key . "month"], $_POST ["options_" . $key . "day"], $_POST ["options_" . $key . "year"]) : $db->jdate($object->array_options ['options_' . $key]); - } - - if ($action == 'edit_extras' && $user->rights->commande->creer && GETPOST('attribute') == $key) { - print '
'; - print ''; - print ''; - print ''; - print ''; - - print $extrafields->showInputField($key, $value); - - print ''; - print '
'; - } else { - print $extrafields->showOutputField($key, $value); - if ($object->statut == 0 && $user->rights->commande->creer) - print '' . img_picto('', 'edit') . ' ' . $langs->trans('Modify') . ''; - } - print '' . "\n"; - } - } - } - - - + $cols = 3; + include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php'; print ""; diff --git a/htdocs/core/tpl/extrafields_view.tpl.php b/htdocs/core/tpl/extrafields_view.tpl.php new file mode 100644 index 00000000000..1591ce9fb6d --- /dev/null +++ b/htdocs/core/tpl/extrafields_view.tpl.php @@ -0,0 +1,83 @@ + + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * Need to have following variables defined: + * $object (invoice, order, ...) + * $conf + * $langs + * + * $cols + */ + +//$res = $object->fetch_optionals($object->id, $extralabels); +$parameters = array('colspan' => ' colspan="'.$cols.'"', 'cols' => $cols, 'socid' => $object->fk_soc); +$reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); + +if (empty($reshook) && ! empty($extrafields->attribute_label)) +{ + foreach ($extrafields->attribute_label as $key => $label) + { + if ($action == 'edit_extras') + { + $value = (isset($_POST ["options_" . $key]) ? $_POST ["options_" . $key] : $object->array_options ["options_" . $key]); + } + else + { + $value = $object->array_options ["options_" . $key]; + } + if ($extrafields->attribute_type [$key] == 'separate') + { + print $extrafields->showSeparator($key); + } + else + { + print ''; + print 'attribute_required [$key])) print ' class="fieldrequired"'; + print '>' . $label . ''; + if (($object->statut == 0 || $extrafields->attribute_alwayseditable[$key]) && $user->rights->propal->creer && ($action != 'edit_extras' || GETPOST('attribute') != $key)) + print ''; + + print '
' . img_edit().'
'; + print ''; + + // Convert date into timestamp format + if (in_array($extrafields->attribute_type [$key], array('date','datetime'))) { + $value = isset($_POST ["options_" . $key]) ? dol_mktime($_POST ["options_" . $key . "hour"], $_POST ["options_" . $key . "min"], 0, $_POST ["options_" . $key . "month"], $_POST ["options_" . $key . "day"], $_POST ["options_" . $key . "year"]) : $db->jdate($object->array_options ['options_' . $key]); + } + + if ($action == 'edit_extras' && $user->rights->propal->creer && GETPOST('attribute') == $key) + { + print '
'; + print ''; + print ''; + print ''; + print ''; + + print $extrafields->showInputField($key, $value); + + print ''; + + print '
'; + } + else + { + print $extrafields->showOutputField($key, $value); + } + print '' . "\n"; + } + } +} diff --git a/htdocs/fichinter/card.php b/htdocs/fichinter/card.php index 70d425d04a1..983293916b6 100644 --- a/htdocs/fichinter/card.php +++ b/htdocs/fichinter/card.php @@ -1330,49 +1330,9 @@ else if ($id > 0 || ! empty($ref)) // Statut print ''.$langs->trans("Status").''.$object->getLibStatut(4).''; - // Other attributes (TODO Move this into an include) - $parameters=array('colspan' => ' colspan="3"'); - $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)) - { - foreach($extrafields->attribute_label as $key=>$label) - { - if ($action == 'edit_extras') { - $value=(isset($_POST["options_".$key])?$_POST["options_".$key]:$object->array_options["options_".$key]); - } else { - $value=$object->array_options["options_".$key]; - } - if ($extrafields->attribute_type[$key] == 'separate') - { - print $extrafields->showSeparator($key); - } - else - { - print 'attribute_required[$key])) print ' class="fieldrequired"'; - print '>'.$label.''; - // Convert date into timestamp format - if (in_array($extrafields->attribute_type[$key],array('date','datetime'))) - { - $value = isset($_POST["options_".$key])?dol_mktime($_POST["options_".$key."hour"], $_POST["options_".$key."min"], 0, $_POST["options_".$key."month"], $_POST["options_".$key."day"], $_POST["options_".$key."year"]):$db->jdate($object->array_options['options_'.$key]); - } - if ($action == 'edit_extras' && $user->rights->ficheinter->creer && GETPOST('attribute') == $key) - { - print ''; - - print $extrafields->showInputField($key,$value); - - print '   '; - } - else - { - print $extrafields->showOutputField($key,$value); - if (($object->statut == 0 || $object->statut == 1) && $user->rights->ficheinter->creer) print '   '.img_picto('','edit').' '.$langs->trans('Modify').''; - } - print ''."\n"; - } - } - } + // Other attributes + $cols = 3; + include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php'; print ""; diff --git a/htdocs/fourn/class/fournisseur.facture.class.php b/htdocs/fourn/class/fournisseur.facture.class.php index e5ba7b3b1dd..9c72319f74f 100644 --- a/htdocs/fourn/class/fournisseur.facture.class.php +++ b/htdocs/fourn/class/fournisseur.facture.class.php @@ -413,6 +413,15 @@ class FactureFournisseur extends CommonInvoice $this->socid = $obj->socid; $this->socnom = $obj->socnom; + + // Retreive all extrafield + // fetch optionals attributes and labels + require_once(DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'); + $extrafields=new ExtraFields($this->db); + $extralabels=$extrafields->fetch_name_optionals_label($this->table_element,true); + $this->fetch_optionals($this->id,$extralabels); + + if ($this->statut == 0) $this->brouillon = 1; $result=$this->fetch_lines(); if ($result < 0) diff --git a/htdocs/fourn/commande/card.php b/htdocs/fourn/commande/card.php index d6be5491f54..911a7a52159 100644 --- a/htdocs/fourn/commande/card.php +++ b/htdocs/fourn/commande/card.php @@ -1484,78 +1484,9 @@ elseif (! empty($object->id)) print ''; } - // Other attributes (TODO Move this into an include) - $parameters=array('socid'=>$socid, 'colspan' => ' colspan="3"'); - $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)) - { - foreach($extrafields->attribute_label as $key=>$label) - { - if ($action == 'edit_extras') - { - $value=(isset($_POST["options_".$key])?$_POST["options_".$key]:$object->array_options["options_".$key]); - } - else - { - $value=$object->array_options["options_".$key]; - } - - if ($extrafields->attribute_type[$key] == 'separate') - { - print $extrafields->showSeparator($key); - } - else - { - print 'attribute_required[$key])) print ' class="fieldrequired"'; - print '>'.$label.''; - // Convert date into timestamp format - if (in_array($extrafields->attribute_type[$key],array('date','datetime'))) - { - $value = isset($_POST["options_".$key])?dol_mktime($_POST["options_".$key."hour"], $_POST["options_".$key."min"], 0, $_POST["options_".$key."month"], $_POST["options_".$key."day"], $_POST["options_".$key."year"]):$db->jdate($object->array_options['options_'.$key]); - } - - if ($action == 'edit_extras' && $user->rights->commande->creer && GETPOST('attribute') == $key) - { - print '
'; - print ''; - print ''; - print ''; - print ''; - - print $extrafields->showInputField($key, $value); - - print ''; - print '
'; - } - else - { - print $extrafields->showOutputField($key, $value); - if ($object->statut == 0 && $user->rights->commande->creer) - print '' . img_picto('', 'edit') . ' ' . $langs->trans('Modify') . ''; - } - print ''."\n"; - } - } - - if(count($extrafields->attribute_label) > 0) - { - if ($action == 'edit_extras' && $user->rights->fournisseur->commande->creer) - { - print ''; - print ''; - print ''; - print ''; - } - else - { - if ($object->statut == 0 && $user->rights->fournisseur->commande->creer) - { - print ''.img_picto('','edit').' '.$langs->trans('Modify').''; - } - } - } - } + // Other attributes + $cols = 3; + include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php'; // Ligne de 3 colonnes print ''.$langs->trans("AmountHT").''; diff --git a/htdocs/fourn/facture/card.php b/htdocs/fourn/facture/card.php index b58c17dcf62..c8db601a8d9 100644 --- a/htdocs/fourn/facture/card.php +++ b/htdocs/fourn/facture/card.php @@ -72,6 +72,10 @@ $result = restrictedArea($user, 'fournisseur', $id, 'facture_fourn', 'facture'); $hookmanager->initHooks(array('invoicesuppliercard','globalcard')); $object=new FactureFournisseur($db); +$extrafields = new ExtraFields($db); + +// fetch optionals attributes and labels +$extralabels=$extrafields->fetch_name_optionals_label($object->table_element); // Load object if ($id > 0 || ! empty($ref)) @@ -1054,6 +1058,45 @@ elseif ($action == 'remove_file') } } +elseif ($action == 'update_extras') +{ + // Fill array 'array_options' with data from add form + $extralabels=$extrafields->fetch_name_optionals_label($object->table_element); + $ret = $extrafields->setOptionalsFromPost($extralabels,$object); + + if($ret < 0) $error++; + + if (!$error) + { + // Actions on extra fields (by external module or standard code) + // FIXME le hook fait double emploi avec le trigger !! + $hookmanager->initHooks(array('supplierorderdao')); + $parameters=array('id'=>$object->id); + + $reshook=$hookmanager->executeHooks('insertExtraFields',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks + + if (empty($reshook)) + { + if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used + { + + $result=$object->insertExtraFields(); + + if ($result < 0) + { + $error++; + } + + } + } + else if ($reshook < 0) $error++; + } + else + { + $action = 'edit_extras'; + } +} + if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $user->rights->fournisseur->facture->creer) { if ($action == 'addcontact') @@ -1884,9 +1927,9 @@ else print ''; } - // Other options - $parameters=array('colspan' => ' colspan="4"'); - $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook + // Other attributes + $cols = 4; + include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php'; print ''; From 850771206d191a7674d7c8b8d6feeca263a01a9c Mon Sep 17 00:00:00 2001 From: Maxime Kohlhaas Date: Tue, 14 Oct 2014 17:12:45 +0200 Subject: [PATCH 4/5] Changelog :) --- ChangeLog | 1 + 1 file changed, 1 insertion(+) diff --git a/ChangeLog b/ChangeLog index 57673bac498..8efb6c5858a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -65,6 +65,7 @@ For users: - New: Add feature to order to invoice on supplier part - Upgrade phpexcel lib to 1.7.8 - New : Use of MAIN_USE_FILECACHE_EXPORT_EXCEL_DIR to use disk cache for big excel export +- New : Option on extrafields to have them always editable regardless of the document status - Fix: [ bug #1487 ] PAYMENT_DELETE trigger does not intercept trigger action - Fix: [ bug #1470, #1472, #1473] User trigger problem - Fix: [ bug #1489, #1491 ] Intervention trigger problem From 8e3a3500c25f594474c6093d093dce86b3aa89ee Mon Sep 17 00:00:00 2001 From: Maxime Kohlhaas Date: Thu, 16 Oct 2014 13:28:39 +0200 Subject: [PATCH 5/5] Add comments (for travis' sake) --- htdocs/core/class/extrafields.class.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/htdocs/core/class/extrafields.class.php b/htdocs/core/class/extrafields.class.php index 9075cac94e3..db24d257aee 100644 --- a/htdocs/core/class/extrafields.class.php +++ b/htdocs/core/class/extrafields.class.php @@ -105,6 +105,7 @@ class ExtraFields * @param int $required Is field required or not * @param string $default_value Defaulted value * @param array $param Params for field + * @param int $alwayseditable Is attribute always editable regardless of the document status * @return int <=0 if KO, >0 if OK */ function addExtraField($attrname, $label, $type, $pos, $size, $elementtype, $unique=0, $required=0, $default_value='', $param=0, $alwayseditable=0) @@ -219,6 +220,7 @@ class ExtraFields * @param int $unique Is field unique or not * @param int $required Is field required or not * @param array||string $param Params for field (ex for select list : array('options' => array(value'=>'label of option')) ) + * @param int $alwayseditable Is attribute always editable regardless of the document status * @return int <=0 if KO, >0 if OK */ private function create_label($attrname, $label='', $type='', $pos=0, $size=0, $elementtype='member', $unique=0, $required=0, $param='', $alwayseditable=0) @@ -350,6 +352,7 @@ class ExtraFields * @param int $required Is field required or not * @param int $pos Position of attribute * @param array $param Params for field (ex for select list : array('options' => array(value'=>'label of option')) ) + * @param int $alwayseditable Is attribute always editable regardless of the document status * @return int >0 if OK, <=0 if KO */ function update($attrname,$label,$type,$length,$elementtype,$unique=0,$required=0,$pos=0,$param='',$alwayseditable=0) @@ -435,6 +438,7 @@ class ExtraFields * @param int $required Is field required or not * @param int $pos Position of attribute * @param array $param Params for field (ex for select list : array('options' => array(value'=>'label of option')) ) + * @param int $alwayseditable Is attribute always editable regardless of the document status * @return int <=0 if KO, >0 if OK */ private function update_label($attrname,$label,$type,$size,$elementtype,$unique=0,$required=0,$pos=0,$param='',$alwayseditable=0)