diff --git a/htdocs/core/actions_extrafields.inc.php b/htdocs/core/actions_extrafields.inc.php index ca2499ab145..486764b167e 100644 --- a/htdocs/core/actions_extrafields.inc.php +++ b/htdocs/core/actions_extrafields.inc.php @@ -183,7 +183,8 @@ if ($action == 'add') (GETPOST('entitycurrentorall', 'alpha')?0:''), GETPOST('langfile', 'alpha'), 1, - (GETPOST('totalizable', 'alpha')?1:0) + (GETPOST('totalizable', 'alpha')?1:0), + (GETPOST('documentpdf', 'alpha')?1:0) ); if ($result > 0) { @@ -352,7 +353,8 @@ if ($action == 'update') (GETPOST('entitycurrentorall', 'alpha')?0:''), GETPOST('langfile'), 1, - (GETPOST('totalizable', 'alpha')?1:0) + (GETPOST('totalizable', 'alpha')?1:0), + (GETPOST('documentpdf', 'alpha')?1:0) ); if ($result > 0) { diff --git a/htdocs/core/class/commondocgenerator.class.php b/htdocs/core/class/commondocgenerator.class.php index cfab7d7f5d6..fcd2837735d 100644 --- a/htdocs/core/class/commondocgenerator.class.php +++ b/htdocs/core/class/commondocgenerator.class.php @@ -1187,16 +1187,7 @@ abstract class CommonDocGenerator foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $label) { // Enable extrafield ? - $enabled = 1; - if ($enabled && isset($extrafields->attributes[$object->table_element]['enabled'][$key])){ - $enabled = dol_eval($extrafields->attributes[$object->table_element]['enabled'][$key], 1); - } - - if ($enabled && isset($extrafields->attributes[$object->table_element]['list'][$key])){ - $enabled = dol_eval($extrafields->attributes[$object->table_element]['list'][$key], 1); - } - - // TODO : add extrafields enabled for display from extrafield config panel + $enabled = !empty($extrafields->attributes[$object->table_element]['documentpdf'][$key]); if(empty($enabled)){ continue; @@ -1338,16 +1329,8 @@ abstract class CommonDocGenerator } // Enable extrafield ? - $enabled = 1; - if ($enabled && isset($extrafields->attributes[$object->table_element]['enabled'][$key])){ - $enabled = dol_eval($extrafields->attributes[$object->table_element]['enabled'][$key], 1); - } + $enabled = !empty($extrafields->attributes[$object->table_element]['documentpdf'][$key]); - if ($enabled && isset($extrafields->attributes[$object->table_element]['list'][$key])){ - $enabled = dol_eval($extrafields->attributes[$object->table_element]['list'][$key], 1); - } - - // TODO : add extrafields $enabled from extrafield config panel // Load language if required if (!empty($extrafields->attributes[$object->table_element]['langfile'][$key])) $outputlangs->load($extrafields->attributes[$object->table_element]['langfile'][$key]); diff --git a/htdocs/core/class/extrafields.class.php b/htdocs/core/class/extrafields.class.php index 5d5540d77b8..7765999339d 100644 --- a/htdocs/core/class/extrafields.class.php +++ b/htdocs/core/class/extrafields.class.php @@ -374,9 +374,11 @@ class ExtraFields * @param string $langfile Language file * @param string $enabled Condition to have the field enabled or not * @param int $totalizable Is a measure. Must show a total on lists + * @param int $documentpdf Is extrafield displayed on PDF * @return int <=0 if KO, >0 if OK + * @throws Exception */ - private function create_label($attrname, $label = '', $type = '', $pos = 0, $size = 0, $elementtype = 'member', $unique = 0, $required = 0, $param = '', $alwayseditable = 0, $perms = '', $list = '-1', $help = '', $default = '', $computed = '', $entity = '', $langfile = '', $enabled = '1', $totalizable = 0) + private function create_label($attrname, $label = '', $type = '', $pos = 0, $size = 0, $elementtype = 'member', $unique = 0, $required = 0, $param = '', $alwayseditable = 0, $perms = '', $list = '-1', $help = '', $default = '', $computed = '', $entity = '', $langfile = '', $enabled = '1', $totalizable = 0, $documentpdf = 0) { // phpcs:enable global $conf, $user; @@ -421,6 +423,7 @@ class ExtraFields $sql .= " perms,"; $sql .= " langs,"; $sql .= " list,"; + $sql .= " documentpdf,"; $sql .= " fielddefault,"; $sql .= " fieldcomputed,"; $sql .= " fk_user_author,"; @@ -444,6 +447,7 @@ class ExtraFields $sql .= " ".($perms ? "'".$this->db->escape($perms)."'" : "null").","; $sql .= " ".($langfile ? "'".$this->db->escape($langfile)."'" : "null").","; $sql .= " '".$this->db->escape($list)."',"; + $sql .= " '".$this->db->escape($documentpdf)."',"; $sql .= " ".($default ? "'".$this->db->escape($default)."'" : "null").","; $sql .= " ".($computed ? "'".$this->db->escape($computed)."'" : "null").","; $sql .= " ".(is_object($user) ? $user->id : 0).","; @@ -590,9 +594,11 @@ class ExtraFields * @param string $langfile Language file * @param string $enabled Condition to have the field enabled or not * @param int $totalizable Is extrafield totalizable on list + * @param int $documentpdf Is extrafield displayed on PDF * @return int >0 if OK, <=0 if KO + * @throws Exception */ - public function update($attrname, $label, $type, $length, $elementtype, $unique = 0, $required = 0, $pos = 0, $param = '', $alwayseditable = 0, $perms = '', $list = '', $help = '', $default = '', $computed = '', $entity = '', $langfile = '', $enabled = '1', $totalizable = 0) + public function update($attrname, $label, $type, $length, $elementtype, $unique = 0, $required = 0, $pos = 0, $param = '', $alwayseditable = 0, $perms = '', $list = '', $help = '', $default = '', $computed = '', $entity = '', $langfile = '', $enabled = '1', $totalizable = 0, $documentpdf = 0) { if ($elementtype == 'thirdparty') $elementtype = 'societe'; if ($elementtype == 'contact') $elementtype = 'socpeople'; @@ -642,7 +648,7 @@ class ExtraFields { if ($label) { - $result = $this->update_label($attrname, $label, $type, $length, $elementtype, $unique, $required, $pos, $param, $alwayseditable, $perms, $list, $help, $default, $computed, $entity, $langfile, $enabled, $totalizable); + $result = $this->update_label($attrname, $label, $type, $length, $elementtype, $unique, $required, $pos, $param, $alwayseditable, $perms, $list, $help, $default, $computed, $entity, $langfile, $enabled, $totalizable, $documentpdf); } if ($result > 0) { @@ -700,13 +706,15 @@ class ExtraFields * @param string $langfile Language file * @param string $enabled Condition to have the field enabled or not * @param int $totalizable Is extrafield totalizable on list + * @param int $documentpdf Is extrafield displayed on PDF * @return int <=0 if KO, >0 if OK + * @throws Exception */ - private function update_label($attrname, $label, $type, $size, $elementtype, $unique = 0, $required = 0, $pos = 0, $param = '', $alwayseditable = 0, $perms = '', $list = '0', $help = '', $default = '', $computed = '', $entity = '', $langfile = '', $enabled = '1', $totalizable = 0) + private function update_label($attrname, $label, $type, $size, $elementtype, $unique = 0, $required = 0, $pos = 0, $param = '', $alwayseditable = 0, $perms = '', $list = '0', $help = '', $default = '', $computed = '', $entity = '', $langfile = '', $enabled = '1', $totalizable = 0, $documentpdf = 0) { // phpcs:enable global $conf, $user; - dol_syslog(get_class($this)."::update_label ".$attrname.", ".$label.", ".$type.", ".$size.", ".$elementtype.", ".$unique.", ".$required.", ".$pos.", ".$alwayseditable.", ".$perms.", ".$list.", ".$default.", ".$computed.", ".$entity.", ".$langfile.", ".$enabled.", ".$totalizable); + dol_syslog(get_class($this)."::update_label ".$attrname.", ".$label.", ".$type.", ".$size.", ".$elementtype.", ".$unique.", ".$required.", ".$pos.", ".$alwayseditable.", ".$perms.", ".$list.", ".$default.", ".$computed.", ".$entity.", ".$langfile.", ".$enabled.", ".$totalizable.", ".$documentpdf); // Clean parameters if ($elementtype == 'thirdparty') $elementtype = 'societe'; @@ -771,6 +779,7 @@ class ExtraFields $sql .= " alwayseditable,"; $sql .= " param,"; $sql .= " list,"; + $sql .= " documentpdf,"; $sql .= " totalizable,"; $sql .= " fielddefault,"; $sql .= " fieldcomputed,"; @@ -794,6 +803,7 @@ class ExtraFields $sql .= " '".$this->db->escape($alwayseditable)."',"; $sql .= " '".$this->db->escape($params)."',"; $sql .= " '".$this->db->escape($list)."', "; + $sql .= " '".$this->db->escape($documentpdf)."', "; $sql .= " ".$totalizable.","; $sql .= " ".(($default != '') ? "'".$this->db->escape($default)."'" : "null").","; $sql .= " ".($computed ? "'".$this->db->escape($computed)."'" : "null").","; @@ -871,7 +881,7 @@ class ExtraFields }*/ // We should not have several time this request. If we have, there is some optimization to do by calling a simple $extrafields->fetch_optionals() in top of code and not into subcode - $sql = "SELECT rowid,name,label,type,size,elementtype,fieldunique,fieldrequired,param,pos,alwayseditable,perms,langs,list,totalizable,fielddefault,fieldcomputed,entity,enabled,help"; + $sql = "SELECT rowid,name,label,type,size,elementtype,fieldunique,fieldrequired,param,pos,alwayseditable,perms,langs,list,documentpdf,totalizable,fielddefault,fieldcomputed,entity,enabled,help"; $sql .= " FROM ".MAIN_DB_PREFIX."extrafields"; //$sql.= " WHERE entity IN (0,".$conf->entity.")"; // Filter is done later if ($elementtype) $sql .= " WHERE elementtype = '".$elementtype."'"; // Filed with object->table_element @@ -933,6 +943,7 @@ class ExtraFields $this->attributes[$tab->elementtype]['perms'][$tab->name] = (strlen($tab->perms) == 0 ? 1 : $tab->perms); $this->attributes[$tab->elementtype]['langfile'][$tab->name] = $tab->langs; $this->attributes[$tab->elementtype]['list'][$tab->name] = $tab->list; + $this->attributes[$tab->elementtype]['documentpdf'][$tab->name] = $tab->documentpdf; $this->attributes[$tab->elementtype]['totalizable'][$tab->name] = $tab->totalizable; $this->attributes[$tab->elementtype]['entityid'][$tab->name] = $tab->entity; $this->attributes[$tab->elementtype]['enabled'][$tab->name] = $tab->enabled; diff --git a/htdocs/core/tpl/admin_extrafields_add.tpl.php b/htdocs/core/tpl/admin_extrafields_add.tpl.php index e695c7aa95f..37872f2a5c0 100644 --- a/htdocs/core/tpl/admin_extrafields_add.tpl.php +++ b/htdocs/core/tpl/admin_extrafields_add.tpl.php @@ -196,6 +196,9 @@ $langs->load("modulebuilder"); textwithpicto($langs->trans("Visibility"), $langs->trans("VisibleDesc")); ?> + +textwithpicto($langs->trans("DisplayOnPdf"), $langs->trans("DisplayOnPdfDesc")); ?> +> trans("Totalizable"); ?>> diff --git a/htdocs/core/tpl/admin_extrafields_edit.tpl.php b/htdocs/core/tpl/admin_extrafields_edit.tpl.php index 4063111a6fb..8e14ad978ca 100644 --- a/htdocs/core/tpl/admin_extrafields_edit.tpl.php +++ b/htdocs/core/tpl/admin_extrafields_edit.tpl.php @@ -165,6 +165,7 @@ $list=$extrafields->attributes[$elementtype]['list'][$attrname]; $totalizable = $extrafields->attributes[$elementtype]['totalizable'][$attrname]; $help=$extrafields->attributes[$elementtype]['help'][$attrname]; $entitycurrentorall=$extrafields->attributes[$elementtype]['entityid'][$attrname]; +$documentpdf=$extrafields->attributes[$elementtype]['documentpdf'][$attrname]; if((($type == 'select') || ($type == 'checkbox') || ($type == 'radio')) && is_array($param)) { @@ -261,8 +262,12 @@ else trans("Required"); ?>> trans("AlwaysEditable"); ?>> + textwithpicto($langs->trans("Visibility"), $langs->trans("VisibleDesc")); ?> + +textwithpicto($langs->trans("DisplayOnPdf"), $langs->trans("DisplayOnPdfDesc")); ?> +> textwithpicto($langs->trans("Totalizable"), $langs->trans("TotalizableDesc")); ?>> textwithpicto($langs->trans("HelpOnTooltip"), $langs->trans("HelpOnTooltipDesc")); ?> @@ -270,7 +275,6 @@ else trans("AllEntities"); ?>> - diff --git a/htdocs/core/tpl/admin_extrafields_view.tpl.php b/htdocs/core/tpl/admin_extrafields_view.tpl.php index 0ddd3f5a8fa..3bec8cb8d6f 100644 --- a/htdocs/core/tpl/admin_extrafields_view.tpl.php +++ b/htdocs/core/tpl/admin_extrafields_view.tpl.php @@ -64,8 +64,9 @@ print ''.$langs->trans("Unique").''; print ''.$langs->trans("Required").''; print ''.$langs->trans("AlwaysEditable").''; print ''.$form->textwithpicto($langs->trans("Visible"), $langs->trans("VisibleDesc")).''; +print ''.$form->textwithpicto($langs->trans("DisplayOnPdf"), $langs->trans("DisplayOnPdfDesc")).''; print ''.$form->textwithpicto($langs->trans("Totalizable"), $langs->trans("TotalizableDesc")).''; -if ($conf->multicompany->enabled) { +if ($conf->multicompany->enabled){ print ''.$langs->trans("Entities").''; } print ' '; @@ -92,6 +93,7 @@ if (is_array($extrafields->attributes[$elementtype]['type']) && count($extrafiel print ''.yn($extrafields->attributes[$elementtype]['required'][$key])."\n"; print ''.yn($extrafields->attributes[$elementtype]['alwayseditable'][$key])."\n"; print ''.$extrafields->attributes[$elementtype]['list'][$key]."\n"; + print ''.yn($extrafields->attributes[$elementtype]['documentpdf'][$key])."\n"; print ''.yn($extrafields->attributes[$elementtype]['totalizable'][$key])."\n"; if (! empty($conf->multicompany->enabled)) { print ''; diff --git a/htdocs/install/mysql/migration/11.0.0-12.0.0.sql b/htdocs/install/mysql/migration/11.0.0-12.0.0.sql index 0b47a28e058..0a91f960807 100644 --- a/htdocs/install/mysql/migration/11.0.0-12.0.0.sql +++ b/htdocs/install/mysql/migration/11.0.0-12.0.0.sql @@ -179,4 +179,6 @@ INSERT INTO llx_c_ticket_resolution (code, pos, label, active, use_default, desc INSERT INTO llx_c_ticket_resolution (code, pos, label, active, use_default, description) VALUES('CANCELED', '50', 'Canceled', 1, 0, NULL); INSERT INTO llx_c_ticket_resolution (code, pos, label, active, use_default, description) VALUES('OTHER', '90', 'Other', 1, 0, NULL); -DELETE FROM llx_const WHERE name = __ENCRYPT('DONATION_ART885')__; \ No newline at end of file +DELETE FROM llx_const WHERE name = __ENCRYPT('DONATION_ART885')__; + +ALTER TABLE llx_extrafields ADD COLUMN documentpdf integer DEFAULT 0; \ No newline at end of file diff --git a/htdocs/langs/en_US/modulebuilder.lang b/htdocs/langs/en_US/modulebuilder.lang index ca3fd3e68b8..9f64e93f9d1 100644 --- a/htdocs/langs/en_US/modulebuilder.lang +++ b/htdocs/langs/en_US/modulebuilder.lang @@ -84,6 +84,8 @@ ListOfPermissionsDefined=List of defined permissions SeeExamples=See examples here EnabledDesc=Condition to have this field active (Examples: 1 or $conf->global->MYMODULE_MYOPTION) VisibleDesc=Is the field visible ? (Examples: 0=Never visible, 1=Visible on list and create/update/view forms, 2=Visible on list only, 3=Visible on create/update/view form only (not list), 4=Visible on list and update/view form only (not create), 5=Visible on list end view form only (not create, not update). Using a negative value means field is not shown by default on list but can be selected for viewing). It can be an expression, for example:
preg_match('/public/', $_SERVER['PHP_SELF'])?0:1
($user->rights->holiday->define_holiday ? 1 : 0) +DisplayOnPdfDesc=Display this field on compatible PDF documents, you can manage position with "Position" field.
Currently, known compatibles PDF models are : eratostene (order), espadon (ship), sponge (invoices), cyan (propal/quotation), cornas (supplier order) +DisplayOnPdf=Display on PDF IsAMeasureDesc=Can the value of field be cumulated to get a total into list? (Examples: 1 or 0) SearchAllDesc=Is the field used to make a search from the quick search tool? (Examples: 1 or 0) SpecDefDesc=Enter here all documentation you want to provide with your module that is not already defined by other tabs. You can use .md or better, the rich .asciidoc syntax.