2
0
forked from Wavyzz/dolibarr

NEW Mutualize code for action="update_extras"

NEW Can use setValueFrom without user modification field
FIX Exclude separators from mandatory extrafields test
More code to use the new framework array for extrafields
Can use text condition in extrafield visibility
This commit is contained in:
Laurent Destailleur
2018-04-12 23:16:23 +02:00
parent 1c9661d9d6
commit 3cecfd02c7
12 changed files with 155 additions and 92 deletions

View File

@@ -28,6 +28,7 @@
// $permissiontodelete must be defined // $permissiontodelete must be defined
// $backurlforlist must be defined // $backurlforlist must be defined
// $backtopage may be defined // $backtopage may be defined
// $triggermodname may be defined
if ($cancel) if ($cancel)
{ {
@@ -134,8 +135,7 @@ if ($action == 'update' && ! empty($permissiontoadd))
else else
{ {
// Creation KO // Creation KO
if (! empty($object->errors)) setEventMessages(null, $object->errors, 'errors'); setEventMessages($object->error, $object->errors, 'errors');
else setEventMessages($object->error, null, 'errors');
$action='edit'; $action='edit';
} }
} }
@@ -145,6 +145,27 @@ if ($action == 'update' && ! empty($permissiontoadd))
} }
} }
// Action to update one extrafield
if ($action == "update_extras" && ! empty($permissiontoadd))
{
$object->fetch(GETPOST('id','int'));
$attributekey = GETPOST('attribute','alpha');
$attributekeylong = 'options_'.$attributekey;
$object->array_options['options_'.$attributekey] = GETPOST($attributekeylong,' alpha');
$result = $object->updateExtraField($attributekey, empty($triggermodname)?'':$triggermodname, $user);
if ($result > 0)
{
setEventMessages($langs->trans('RecordSaved'), null, 'mesgs');
$action = 'view';
}
else
{
setEventMessages($object->error, $object->errors, 'errors');
$action = 'edit_extras';
}
}
// Action to delete // Action to delete
if ($action == 'confirm_delete' && ! empty($permissiontodelete)) if ($action == 'confirm_delete' && ! empty($permissiontodelete))
{ {

View File

@@ -1416,10 +1416,11 @@ abstract class CommonObject
* @param string $id_field To force rowid field name. 'rowid' is used if not defined * @param string $id_field To force rowid field name. 'rowid' is used if not defined
* @param User|string $fuser Update the user of last update field with this user. If not provided, current user is used except if value is 'none' * @param User|string $fuser Update the user of last update field with this user. If not provided, current user is used except if value is 'none'
* @param string $trigkey Trigger key to run (in most cases something like 'XXX_MODIFY') * @param string $trigkey Trigger key to run (in most cases something like 'XXX_MODIFY')
* @param string $fk_user_field Name of field to save user id making change
* @return int <0 if KO, >0 if OK * @return int <0 if KO, >0 if OK
* @see updateExtraField * @see updateExtraField
*/ */
function setValueFrom($field, $value, $table='', $id=null, $format='', $id_field='', $fuser=null, $trigkey='') function setValueFrom($field, $value, $table='', $id=null, $format='', $id_field='', $fuser=null, $trigkey='', $fk_user_field='fk_user_modif')
{ {
global $user,$langs,$conf; global $user,$langs,$conf;
@@ -1428,24 +1429,26 @@ abstract class CommonObject
if (empty($format)) $format='text'; if (empty($format)) $format='text';
if (empty($id_field)) $id_field='rowid'; if (empty($id_field)) $id_field='rowid';
$fk_user_field = 'fk_user_modif';
$error=0; $error=0;
$this->db->begin(); $this->db->begin();
// Special case // Special case
if ($table == 'product' && $field == 'note_private') $field='note'; if ($table == 'product' && $field == 'note_private') $field='note';
if (in_array($table, array('actioncomm', 'adherent', 'advtargetemailing', 'cronjob', 'establishment'))) { if (in_array($table, array('actioncomm', 'adherent', 'advtargetemailing', 'cronjob', 'establishment'))) $fk_user_field = 'fk_user_mod';
$fk_user_field = 'fk_user_mod';
}
$sql = "UPDATE ".MAIN_DB_PREFIX.$table." SET "; $sql = "UPDATE ".MAIN_DB_PREFIX.$table." SET ";
if ($format == 'text') $sql.= $field." = '".$this->db->escape($value)."'"; if ($format == 'text') $sql.= $field." = '".$this->db->escape($value)."'";
else if ($format == 'int') $sql.= $field." = ".$this->db->escape($value); else if ($format == 'int') $sql.= $field." = ".$this->db->escape($value);
else if ($format == 'date') $sql.= $field." = ".($value ? "'".$this->db->idate($value)."'" : "null"); else if ($format == 'date') $sql.= $field." = ".($value ? "'".$this->db->idate($value)."'" : "null");
if ($fk_user_field)
{
if (! empty($fuser) && is_object($fuser)) $sql.=", ".$fk_user_field." = ".$fuser->id; if (! empty($fuser) && is_object($fuser)) $sql.=", ".$fk_user_field." = ".$fuser->id;
elseif (empty($fuser) || $fuser != 'none') $sql.=", ".$fk_user_field." = ".$user->id; elseif (empty($fuser) || $fuser != 'none') $sql.=", ".$fk_user_field." = ".$user->id;
}
$sql.= " WHERE ".$id_field." = ".$id; $sql.= " WHERE ".$id_field." = ".$id;
dol_syslog(get_class($this)."::".__FUNCTION__."", LOG_DEBUG); dol_syslog(get_class($this)."::".__FUNCTION__."", LOG_DEBUG);
@@ -5934,25 +5937,29 @@ abstract class CommonObject
$out = ''; $out = '';
if (count($extrafields->attribute_label) > 0) if (is_array($extrafields->attributes[$this->table_element]['label']) && count($extrafields->attributes[$this->table_element]['label']) > 0)
{ {
$out .= "\n"; $out .= "\n";
$out .= '<!-- showOptionalsInput --> '; $out .= '<!-- showOptionalsInput --> ';
$out .= "\n"; $out .= "\n";
$e = 0; $e = 0;
foreach($extrafields->attribute_label as $key=>$label) foreach($extrafields->attributes[$this->table_element]['label'] as $key=>$label)
{ {
$enabled = $extrafields->attribute_list[$key]; $enabled = 1;
if (empty($enabled)) continue; // 0 = Never visible field if ($enabled && isset($extrafields->attributes[$this->table_element]['list'][$key]))
if (! is_numeric($enabled))
{ {
$enabled=dol_eval($enabled, 1); $enabled = dol_eval($extrafields->attributes[$this->table_element]['list'][$key], 1);
if (empty($enabled)) continue; }
else $enabled = 1;
$perms = 1;
if ($perms && isset($extrafields->attributes[$this->table_element]['perms'][$key]))
{
$perms = dol_eval($extrafields->attributes[$this->table_element]['perms'][$key], 1);
} }
if (($mode == 'create' || $mode == 'edit') && abs($enabled) != 1 && abs($enabled) != 3) continue; // <> -1 and <> 1 and <> 3 = not visible on forms, only on list if (($mode == 'create' || $mode == 'edit') && abs($enabled) != 1 && abs($enabled) != 3) continue; // <> -1 and <> 1 and <> 3 = not visible on forms, only on list
if (empty($perms)) continue;
// Load language if required // Load language if required
if (! empty($extrafields->attributes[$this->table_element]['langfile'][$key])) $langs->load($extrafields->attributes[$this->table_element]['langfile'][$key]); if (! empty($extrafields->attributes[$this->table_element]['langfile'][$key])) $langs->load($extrafields->attributes[$this->table_element]['langfile'][$key]);
@@ -5987,14 +5994,14 @@ abstract class CommonObject
} }
//var_dump($value); //var_dump($value);
if ($extrafields->attribute_type[$key] == 'separate') if ($extrafields->attributes[$this->table_element]['type'][$key] == 'separate')
{ {
$out .= $extrafields->showSeparator($key); $out .= $extrafields->showSeparator($key);
} }
else else
{ {
$csstyle=''; $csstyle='';
$class=(!empty($extrafields->attribute_hidden[$key]) ? 'hideobject ' : ''); $class=(!empty($extrafields->attributes[$this->table_element]['hidden'][$key]) ? 'hideobject ' : '');
if (is_array($params) && count($params)>0) { if (is_array($params) && count($params)>0) {
if (array_key_exists('style',$params)) { if (array_key_exists('style',$params)) {
$csstyle=$params['style']; $csstyle=$params['style'];
@@ -6018,19 +6025,19 @@ abstract class CommonObject
if ($action == 'selectlines') { $colspan++; } if ($action == 'selectlines') { $colspan++; }
// Convert date into timestamp format (value in memory must be a timestamp) // Convert date into timestamp format (value in memory must be a timestamp)
if (in_array($extrafields->attribute_type[$key],array('date','datetime'))) if (in_array($extrafields->attributes[$this->table_element]['type'][$key],array('date','datetime')))
{ {
$value = GETPOSTISSET($keyprefix.'options_'.$key.$keysuffix)?dol_mktime(GETPOST($keyprefix.'options_'.$key.$keysuffix."hour",'int',3), GETPOST($keyprefix.'options_'.$key.$keysuffix."min",'int',3), 0, GETPOST($keyprefix.'options_'.$key.$keysuffix."month",'int',3), GETPOST($keyprefix.'options_'.$key.$keysuffix."day",'int',3), GETPOST($keyprefix.'options_'.$key.$keysuffix."year",'int',3)):$this->db->jdate($this->array_options['options_'.$key]); $value = GETPOSTISSET($keyprefix.'options_'.$key.$keysuffix)?dol_mktime(GETPOST($keyprefix.'options_'.$key.$keysuffix."hour",'int',3), GETPOST($keyprefix.'options_'.$key.$keysuffix."min",'int',3), 0, GETPOST($keyprefix.'options_'.$key.$keysuffix."month",'int',3), GETPOST($keyprefix.'options_'.$key.$keysuffix."day",'int',3), GETPOST($keyprefix.'options_'.$key.$keysuffix."year",'int',3)):$this->db->jdate($this->array_options['options_'.$key]);
} }
// Convert float submited string into real php numeric (value in memory must be a php numeric) // Convert float submited string into real php numeric (value in memory must be a php numeric)
if (in_array($extrafields->attribute_type[$key],array('price','double'))) if (in_array($extrafields->attributes[$this->table_element]['type'][$key],array('price','double')))
{ {
$value = GETPOSTISSET($keyprefix.'options_'.$key.$keysuffix)?price2num(GETPOST($keyprefix.'options_'.$key.$keysuffix,'int',3)):$this->array_options['options_'.$key]; $value = GETPOSTISSET($keyprefix.'options_'.$key.$keysuffix)?price2num(GETPOST($keyprefix.'options_'.$key.$keysuffix,'int',3)):$this->array_options['options_'.$key];
} }
$labeltoshow = $langs->trans($label); $labeltoshow = $langs->trans($label);
if($extrafields->attribute_required[$key]) if ($extrafields->attributes[$this->table_element]['required'][$key])
{ {
$labeltoshow = '<span'.($mode != 'view' ? ' class="fieldrequired"':'').'>'.$labeltoshow.'</span>'; $labeltoshow = '<span'.($mode != 'view' ? ' class="fieldrequired"':'').'>'.$labeltoshow.'</span>';
} }

View File

@@ -137,7 +137,7 @@ class ExtraFields
* @param int $type Type of attribute ('boolean','int','varchar','text','html','date','datehour','price','phone','mail','password','url','select','checkbox','separate',...) * @param int $type Type of attribute ('boolean','int','varchar','text','html','date','datehour','price','phone','mail','password','url','select','checkbox','separate',...)
* @param int $pos Position of attribute * @param int $pos Position of attribute
* @param string $size Size/length of attribute * @param string $size Size/length of attribute
* @param string $elementtype Element type ('member', 'product', 'thirdparty', ...) * @param string $elementtype Element type. Same value than object->table_element (Example 'member', 'product', 'thirdparty', ...)
* @param int $unique Is field unique or not * @param int $unique Is field unique or not
* @param int $required Is field required or not * @param int $required Is field required or not
* @param string $default_value Defaulted value (In database. use the default_value feature for default value on screen. Example: '', '0', 'null', 'avalue') * @param string $default_value Defaulted value (In database. use the default_value feature for default value on screen. Example: '', '0', 'null', 'avalue')
@@ -761,7 +761,7 @@ class ExtraFields
$sql = "SELECT rowid,name,label,type,size,elementtype,fieldunique,fieldrequired,param,pos,alwayseditable,perms,langs,list,fielddefault,fieldcomputed,entity"; $sql = "SELECT rowid,name,label,type,size,elementtype,fieldunique,fieldrequired,param,pos,alwayseditable,perms,langs,list,fielddefault,fieldcomputed,entity";
$sql.= " FROM ".MAIN_DB_PREFIX."extrafields"; $sql.= " FROM ".MAIN_DB_PREFIX."extrafields";
$sql.= " WHERE entity IN (0,".$conf->entity.")"; $sql.= " WHERE entity IN (0,".$conf->entity.")";
if ($elementtype) $sql.= " AND elementtype = '".$elementtype."'"; if ($elementtype) $sql.= " AND elementtype = '".$elementtype."'"; // Filed with object->table_element
$sql.= " ORDER BY pos"; $sql.= " ORDER BY pos";
$resql=$this->db->query($sql); $resql=$this->db->query($sql);
@@ -1375,7 +1375,7 @@ class ExtraFields
* @param string $key Key of attribute * @param string $key Key of attribute
* @param string $value Value to show * @param string $value Value to show
* @param string $moreparam To add more parameters on html input tag (only checkbox use html input for output rendering) * @param string $moreparam To add more parameters on html input tag (only checkbox use html input for output rendering)
* @param string $extrafieldsobjectkey If defined, use the new method to get extrafields data * @param string $extrafieldsobjectkey If defined (for example $object->table_element), use the new method to get extrafields data
* @return string Formated value * @return string Formated value
*/ */
function showOutputField($key, $value, $moreparam='', $extrafieldsobjectkey='') function showOutputField($key, $value, $moreparam='', $extrafieldsobjectkey='')
@@ -1393,10 +1393,10 @@ class ExtraFields
$unique=$this->attributes[$extrafieldsobjectkey]['unique'][$key]; $unique=$this->attributes[$extrafieldsobjectkey]['unique'][$key];
$required=$this->attributes[$extrafieldsobjectkey]['required'][$key]; $required=$this->attributes[$extrafieldsobjectkey]['required'][$key];
$param=$this->attributes[$extrafieldsobjectkey]['param'][$key]; $param=$this->attributes[$extrafieldsobjectkey]['param'][$key];
$perms=$this->attributes[$extrafieldsobjectkey]['perms'][$key]; $perms=dol_eval($this->attributes[$extrafieldsobjectkey]['perms'][$key], 1);
$langfile=$this->attributes[$extrafieldsobjectkey]['langfile'][$key]; $langfile=$this->attributes[$extrafieldsobjectkey]['langfile'][$key];
$list=$this->attributes[$extrafieldsobjectkey]['list'][$key]; $list=dol_eval($this->attributes[$extrafieldsobjectkey]['list'][$key], 1);
$hidden=(($list == 0) ? 1 : 0); // If zero, we are sure it is hidden, otherwise we show. If it depends on mode (view/create/edit form or list, this must be filtered by caller) $hidden=(empty($list) ? 1 : 0); // If empty, we are sure it is hidden, otherwise we show. If it depends on mode (view/create/edit form or list, this must be filtered by caller)
} }
else // Old usage else // Old usage
{ {
@@ -1409,10 +1409,10 @@ class ExtraFields
$unique=$this->attribute_unique[$key]; $unique=$this->attribute_unique[$key];
$required=$this->attribute_required[$key]; $required=$this->attribute_required[$key];
$param=$this->attribute_param[$key]; $param=$this->attribute_param[$key];
$perms=$this->attribute_perms[$key]; $perms=dol_eval($this->attribute_perms[$key], 1);
$langfile=$this->attribute_langfile[$key]; $langfile=$this->attribute_langfile[$key];
$list=$this->attribute_list[$key]; $list=dol_eval($this->attribute_list[$key], 1);
$hidden=(($list == 0) ? 1 : 0); // If zero, we are sure it is hidden, otherwise we show. If it depends on mode (view/create/edit form or list, this must be filtered by caller) $hidden=(empty($list) ? 1 : 0); // If empty, we are sure it is hidden, otherwise we show. If it depends on mode (view/create/edit form or list, this must be filtered by caller)
} }
if ($hidden) return ''; // This is a protection. If field is hidden, we should just not call this method. if ($hidden) return ''; // This is a protection. If field is hidden, we should just not call this method.
@@ -1754,7 +1754,7 @@ class ExtraFields
/** /**
* Fill array_options property of object by extrafields value (using for data sent by forms) * Fill array_options property of object by extrafields value (using for data sent by forms)
* *
* @param array $extralabels $array of extrafields * @param array $extralabels $array of extrafields (@deprecated)
* @param object $object Object * @param object $object Object
* @param string $onlykey Only following key is filled. When we make update of only one extrafield ($action = 'update_extras'), calling page must must set this to avoid to have other extrafields being reset. * @param string $onlykey Only following key is filled. When we make update of only one extrafield ($action = 'update_extras'), calling page must must set this to avoid to have other extrafields being reset.
* @return int 1 if array_options set, 0 if no value, -1 if error (field required missing for example) * @return int 1 if array_options set, 0 if no value, -1 if error (field required missing for example)
@@ -1765,6 +1765,8 @@ class ExtraFields
$nofillrequired='';// For error when required field left blank $nofillrequired='';// For error when required field left blank
$error_field_required = array(); $error_field_required = array();
if (is_array($this->attributes[$object->table_element]['label'])) $extralabels=$this->attributes[$object->table_element]['label'];
if (is_array($extralabels)) if (is_array($extralabels))
{ {
// Get extra fields // Get extra fields
@@ -1772,11 +1774,27 @@ class ExtraFields
{ {
if (! empty($onlykey) && $key != $onlykey) continue; if (! empty($onlykey) && $key != $onlykey) continue;
$key_type = $this->attribute_type[$key]; $key_type = $this->attributes[$object->table_element]['type'][$key];
if ($this->attribute_required[$key] && empty($_POST["options_".$key])) // Check if empty without GETPOST, value can be alpha, int, array, etc... if ($key_type == 'separate') continue;
$enabled = 1;
if (isset($this->attributes[$object->table_element]['list'][$key]))
{ {
$enabled = dol_eval($this->attributes[$object->table_element]['list'][$key], 1);
}
$perms = 1;
if (isset($this->attributes[$object->table_element]['perms'][$key]))
{
$perms = dol_eval($this->attributes[$object->table_element]['perms'][$key], 1);
}
if (empty($enabled)) continue;
if (empty($perms)) continue;
if ($this->attributes[$object->table_element]['required'][$key] && empty($_POST["options_".$key])) // Check if empty without GETPOST, value can be alpha, int, array, etc...
{
//print 'ccc'.$value.'-'.$this->attributes[$object->table_element]['required'][$key];
$nofillrequired++; $nofillrequired++;
$error_field_required[] = $value; $error_field_required[] = $langs->transnoentitiesnoconv($value);
} }
if (in_array($key_type,array('date'))) if (in_array($key_type,array('date')))
@@ -1829,7 +1847,7 @@ class ExtraFields
/** /**
* return array_options array of data of extrafields value of object sent by a search form * return array_options array of data of extrafields value of object sent by a search form
* *
* @param array $extralabels $array of extrafields * @param array $extralabels $array of extrafields (@deprecated)
* @param string $keyprefix Prefix string to add into name and id of field (can be used to avoid duplicate names) * @param string $keyprefix Prefix string to add into name and id of field (can be used to avoid duplicate names)
* @param string $keysuffix Suffix string to add into name and id of field (can be used to avoid duplicate names) * @param string $keysuffix Suffix string to add into name and id of field (can be used to avoid duplicate names)
* @return array|int array_options set or 0 if no value * @return array|int array_options set or 0 if no value
@@ -1838,13 +1856,15 @@ class ExtraFields
{ {
global $_POST; global $_POST;
if (is_array($this->attributes[$object->table_element]['label'])) $extralabels=$this->attributes[$object->table_element]['label'];
$array_options = array(); $array_options = array();
if (is_array($extralabels)) if (is_array($extralabels))
{ {
// Get extra fields // Get extra fields
foreach ($extralabels as $key => $value) foreach ($extralabels as $key => $value)
{ {
$key_type = $this->attribute_type[$key]; $key_type = $this->attributes[$object->table_element]['type'][$key];
if (in_array($key_type,array('date','datetime'))) if (in_array($key_type,array('date','datetime')))
{ {

View File

@@ -191,7 +191,7 @@ $langs->load("modulebuilder");
<?php } ?> <?php } ?>
<!-- Visibility --> <!-- Visibility -->
<tr><td class="extra_list"><?php echo $form->textwithpicto($langs->trans("Visibility"), $langs->trans("VisibleDesc")); ?> <tr><td class="extra_list"><?php echo $form->textwithpicto($langs->trans("Visibility"), $langs->trans("VisibleDesc")); ?>
</td><td class="valeur"><input id="list" size="1" type="text" name="list" value="<?php echo GETPOST('list','int')!='' ? GETPOST('list','int') : '1'; ?>"></td></tr> </td><td class="valeur"><input id="list" class="minwidth100" type="text" name="list" value="<?php echo GETPOST('list','int')!='' ? GETPOST('list','int') : '1'; ?>"></td></tr>
</table> </table>
<?php dol_fiche_end(); ?> <?php dol_fiche_end(); ?>

View File

@@ -8,16 +8,16 @@ if (empty($conf) || ! is_object($conf))
} }
// Loop to show all columns of extrafields for the title line // Loop to show all columns of extrafields for the title line
if (is_array($extrafields->attributes[$object->element]['label']) && count($extrafields->attributes[$object->element]['label'])) if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label']))
{ {
foreach($extrafields->attributes[$object->element]['label'] as $key => $val) foreach($extrafields->attributes[$object->table_element]['label'] as $key => $val)
{ {
if (! empty($arrayfields["ef.".$key]['checked'])) if (! empty($arrayfields["ef.".$key]['checked']))
{ {
$align=$extrafields->getAlignFlag($key); $align=$extrafields->getAlignFlag($key);
$sortonfield = "ef.".$key; $sortonfield = "ef.".$key;
if (! empty($extrafields->attributes[$object->element]['computed'][$key])) $sortonfield=''; if (! empty($extrafields->attributes[$object->table_element]['computed'][$key])) $sortonfield='';
if ($extrafields->attributes[$object->element]['type'][$key] == 'separate') print '<th class="liste_titre thseparator"></th>'; if ($extrafields->attributes[$object->table_element]['type'][$key] == 'separate') print '<th class="liste_titre thseparator"></th>';
else print getTitleFieldOfList($langs->trans($extralabels[$key]), 0, $_SERVER["PHP_SELF"], $sortonfield, "", $param, ($align?'align="'.$align.'"':''), $sortfield, $sortorder)."\n"; else print getTitleFieldOfList($langs->trans($extralabels[$key]), 0, $_SERVER["PHP_SELF"], $sortonfield, "", $param, ($align?'align="'.$align.'"':''), $sortfield, $sortorder)."\n";
} }
} }

View File

@@ -51,8 +51,21 @@ if (empty($reshook) && ! empty($extrafields->attributes[$object->table_element][
foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $label) foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $label)
{ {
// Discard if extrafield is a hidden field on form // Discard if extrafield is a hidden field on form
if (empty($extrafields->attributes[$object->table_element]['list'][$key])) continue; // 0 = Never visible field $enabled = 1;
if (abs($extrafields->attributes[$object->table_element]['list'][$key]) != 1 && abs($extrafields->attributes[$object->table_element]['list'][$key]) != 3) continue; // <> -1 and <> 1 and <> 3 = not visible on forms, only on list if ($enabled && isset($extrafields->attributes[$object->table_element]['list'][$key]))
{
$enabled = dol_eval($extrafields->attributes[$object->table_element]['list'][$key], 1);
}
$perms = 1;
if ($perms && isset($extrafields->attributes[$object->table_element]['perms'][$key]))
{
$perms = dol_eval($extrafields->attributes[$object->table_element]['perms'][$key], 1);
}
//print $key.'-'.$enabled.'-'.$perms.'-'.$label.$_POST["options_" . $key].'<br>'."\n";
if (empty($enabled)) continue; // 0 = Never visible field
if (abs($enabled) != 1 && abs($enabled) != 3) continue; // <> -1 and <> 1 and <> 3 = not visible on forms, only on list
if (empty($perms)) continue; // 0 = Not visible
// Load language if required // Load language if required
if (! empty($extrafields->attributes[$object->table_element]['langfile'][$key])) $langs->load($extrafields->attributes[$object->table_element]['langfile'][$key]); if (! empty($extrafields->attributes[$object->table_element]['langfile'][$key])) $langs->load($extrafields->attributes[$object->table_element]['langfile'][$key]);
@@ -139,7 +152,8 @@ if (empty($reshook) && ! empty($extrafields->attributes[$object->table_element][
} }
else else
{ {
print $extrafields->showOutputField($key, $value, '', (empty($extrafieldsobjectkey)?'':$extrafieldsobjectkey)); //print $key.'-'.$value.'-'.$object->table_element;
print $extrafields->showOutputField($key, $value, '', $object->table_element);
} }
print '</td></tr>' . "\n"; print '</td></tr>' . "\n";

View File

@@ -119,6 +119,7 @@ if (empty($reshook))
$permissiontoadd = $user->rights->mymodule->write; $permissiontoadd = $user->rights->mymodule->write;
$permissiontodelete = $user->rights->mymodule->delete; $permissiontodelete = $user->rights->mymodule->delete;
$backurlforlist = dol_buildpath('/mymodule/myobject_list.php',1); $backurlforlist = dol_buildpath('/mymodule/myobject_list.php',1);
$triggermodname = 'MYMODULE_MODIFY';
// Actions cancel, add, update or delete // Actions cancel, add, update or delete
include DOL_DOCUMENT_ROOT.'/core/actions_addupdatedelete.inc.php'; include DOL_DOCUMENT_ROOT.'/core/actions_addupdatedelete.inc.php';

View File

@@ -132,12 +132,12 @@ foreach($object->fields as $key => $val)
if (! empty($val['visible'])) $arrayfields['t.'.$key]=array('label'=>$val['label'], 'checked'=>(($val['visible']<0)?0:1), 'enabled'=>$val['enabled'], 'position'=>$val['position']); if (! empty($val['visible'])) $arrayfields['t.'.$key]=array('label'=>$val['label'], 'checked'=>(($val['visible']<0)?0:1), 'enabled'=>$val['enabled'], 'position'=>$val['position']);
} }
// Extra fields // Extra fields
if (is_array($extrafields->attributes[$object->element]['label']) && count($extrafields->attributes[$object->element]['label'])) if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label']))
{ {
foreach($extrafields->attributes[$object->element]['label'] as $key => $val) foreach($extrafields->attributes[$object->table_element]['label'] as $key => $val)
{ {
if (! empty($extrafields->attributes[$object->element]['list'][$key])) if (! empty($extrafields->attributes[$object->table_element]['list'][$key]))
$arrayfields["ef.".$key]=array('label'=>$extrafields->attributes[$object->element]['label'][$key], 'checked'=>(($extrafields->attributes[$object->element]['list'][$key]<0)?0:1), 'position'=>$extrafields->attributes[$object->element]['pos'][$key], 'enabled'=>(abs($extrafields->attributes[$object->element]['list'][$key])!=3 && $extrafields->attributes[$object->element]['perms'][$key])); $arrayfields["ef.".$key]=array('label'=>$extrafields->attributes[$object->table_element]['label'][$key], 'checked'=>(($extrafields->attributes[$object->table_element]['list'][$key]<0)?0:1), 'position'=>$extrafields->attributes[$object->table_element]['pos'][$key], 'enabled'=>(abs($extrafields->attributes[$object->table_element]['list'][$key])!=3 && $extrafields->attributes[$object->table_element]['perms'][$key]));
} }
} }
$object->fields = dol_sort_array($object->fields, 'position'); $object->fields = dol_sort_array($object->fields, 'position');
@@ -214,15 +214,15 @@ foreach($object->fields as $key => $val)
$sql.='t.'.$key.', '; $sql.='t.'.$key.', ';
} }
// Add fields from extrafields // Add fields from extrafields
if (! empty($extrafields->attributes[$object->element]['label'])) if (! empty($extrafields->attributes[$object->table_element]['label']))
foreach ($extrafields->attributes[$object->element]['label'] as $key => $val) $sql.=($extrafields->attributes[$object->element]['type'][$key] != 'separate' ? ", ef.".$key.' as options_'.$key : ''); foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) $sql.=($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? "ef.".$key.' as options_'.$key.', ' : '');
// Add fields from hooks // Add fields from hooks
$parameters=array(); $parameters=array();
$reshook=$hookmanager->executeHooks('printFieldListSelect', $parameters, $object); // Note that $action and $object may have been modified by hook $reshook=$hookmanager->executeHooks('printFieldListSelect', $parameters, $object); // Note that $action and $object may have been modified by hook
$sql.=$hookmanager->resPrint; $sql.=$hookmanager->resPrint;
$sql=preg_replace('/, $/','', $sql); $sql=preg_replace('/, $/','', $sql);
$sql.= " FROM ".MAIN_DB_PREFIX.$object->table_element." as t"; $sql.= " FROM ".MAIN_DB_PREFIX.$object->table_element." as t";
if (is_array($extrafields->attributes[$object->element]['label']) && count($extrafields->attributes[$object->element]['label'])) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."myobject_extrafields as ef on (t.rowid = ef.fk_object)"; if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."myobject_extrafields as ef on (t.rowid = ef.fk_object)";
if ($object->ismultientitymanaged == 1) $sql.= " WHERE t.entity IN (".getEntity('myobject').")"; if ($object->ismultientitymanaged == 1) $sql.= " WHERE t.entity IN (".getEntity('myobject').")";
else $sql.=" WHERE 1 = 1"; else $sql.=" WHERE 1 = 1";
foreach($search as $key => $val) foreach($search as $key => $val)
@@ -246,8 +246,8 @@ foreach($object->fields as $key => $val)
$sql.='t.'.$key.', '; $sql.='t.'.$key.', ';
} }
// Add fields from extrafields // Add fields from extrafields
if (! empty($extrafields->attributes[$object->element]['label'])) { if (! empty($extrafields->attributes[$object->table_element]['label'])) {
foreach ($extrafields->attributes[$object->element]['label'] as $key => $val) $sql.=($extrafields->attributes[$object->element]['type'][$key] != 'separate' ? ",ef.".$key : ''); foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) $sql.=($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? "ef.".$key.', ' : '');
// Add where from hooks // Add where from hooks
$parameters=array(); $parameters=array();
$reshook=$hookmanager->executeHooks('printFieldListGroupBy',$parameters); // Note that $action and $object may have been modified by hook $reshook=$hookmanager->executeHooks('printFieldListGroupBy',$parameters); // Note that $action and $object may have been modified by hook
@@ -440,7 +440,7 @@ print '</tr>'."\n";
// Detect if we need a fetch on each output line // Detect if we need a fetch on each output line
$needToFetchEachLine=0; $needToFetchEachLine=0;
foreach ($extrafields->attributes[$object->element]['computed'] as $key => $val) foreach ($extrafields->attributes[$object->table_element]['computed'] as $key => $val)
{ {
if (preg_match('/\$object/',$val)) $needToFetchEachLine++; // There is at least one compute field that use $object if (preg_match('/\$object/',$val)) $needToFetchEachLine++; // There is at least one compute field that use $object
} }

View File

@@ -104,12 +104,12 @@ foreach($object->fields as $key => $val)
if (! empty($val['visible'])) $arrayfields['t.'.$key]=array('label'=>$val['label'], 'checked'=>(($val['visible']<0)?0:1), 'enabled'=>$val['enabled'], 'position'=>$val['position']); if (! empty($val['visible'])) $arrayfields['t.'.$key]=array('label'=>$val['label'], 'checked'=>(($val['visible']<0)?0:1), 'enabled'=>$val['enabled'], 'position'=>$val['position']);
} }
// Extra fields // Extra fields
if (is_array($extrafields->attributes[$object->element]['label']) && count($extrafields->attributes[$object->element]['label'])) if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label']))
{ {
foreach($extrafields->attributes[$object->element]['label'] as $key => $val) foreach($extrafields->attributes[$object->table_element]['label'] as $key => $val)
{ {
if (! empty($extrafields->attributes[$object->element]['list'][$key])) if (! empty($extrafields->attributes[$object->table_element]['list'][$key]))
$arrayfields["ef.".$key]=array('label'=>$extrafields->attributes[$object->element]['label'][$key], 'checked'=>(($extrafields->attributes[$object->element]['list'][$key]<0)?0:1), 'position'=>$extrafields->attributes[$object->element]['pos'][$key], 'enabled'=>(abs($extrafields->attributes[$object->element]['list'][$key])!=3 && $extrafields->attributes[$object->element]['perms'][$key])); $arrayfields["ef.".$key]=array('label'=>$extrafields->attributes[$object->table_element]['label'][$key], 'checked'=>(($extrafields->attributes[$object->table_element]['list'][$key]<0)?0:1), 'position'=>$extrafields->attributes[$object->table_element]['pos'][$key], 'enabled'=>(abs($extrafields->attributes[$object->table_element]['list'][$key])!=3 && $extrafields->attributes[$object->table_element]['perms'][$key]));
} }
} }
$object->fields = dol_sort_array($object->fields, 'position'); $object->fields = dol_sort_array($object->fields, 'position');
@@ -185,8 +185,8 @@ foreach($object->fields as $key => $val)
$sql.='t.'.$key.', '; $sql.='t.'.$key.', ';
} }
// Add fields from extrafields // Add fields from extrafields
if (! empty($extrafields->attributes[$object->element]['label'])) { if (! empty($extrafields->attributes[$object->table_element]['label'])) {
foreach ($extrafields->attributes[$object->element]['label'] as $key => $val) $sql.=($extrafields->attributes[$object->element]['type'][$key] != 'separate' ? ", ef.".$key.' as options_'.$key : ''); foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) $sql.=($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? "ef.".$key.' as options_'.$key.', ' : '');
} }
// Add fields from hooks // Add fields from hooks
$parameters=array(); $parameters=array();
@@ -194,7 +194,7 @@ $reshook=$hookmanager->executeHooks('printFieldListSelect', $parameters, $object
$sql.=$hookmanager->resPrint; $sql.=$hookmanager->resPrint;
$sql=preg_replace('/, $/','', $sql); $sql=preg_replace('/, $/','', $sql);
$sql.= " FROM ".MAIN_DB_PREFIX.$object->table_element." as t"; $sql.= " FROM ".MAIN_DB_PREFIX.$object->table_element." as t";
if (is_array($extrafields->attributes[$object->element]['label']) && count($extrafields->attributes[$object->element]['label'])) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."myobject_extrafields as ef on (t.rowid = ef.fk_object)"; if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."myobject_extrafields as ef on (t.rowid = ef.fk_object)";
if ($object->ismultientitymanaged == 1) $sql.= " WHERE t.entity IN (".getEntity('myobject').")"; if ($object->ismultientitymanaged == 1) $sql.= " WHERE t.entity IN (".getEntity('myobject').")";
else $sql.=" WHERE 1 = 1"; else $sql.=" WHERE 1 = 1";
foreach($search as $key => $val) foreach($search as $key => $val)
@@ -218,7 +218,7 @@ foreach($object->fields as $key => $val)
$sql.='t.'.$key.', '; $sql.='t.'.$key.', ';
} }
// Add fields from extrafields // Add fields from extrafields
foreach ($extrafields->attributes[$object->element]['label'] as $key => $val) $sql.=($extrafields->attributes[$object->element]['type'][$key] != 'separate' ? ",ef.".$key : ''); foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) $sql.=($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? "ef.".$key.', ' : '');
// Add where from hooks // Add where from hooks
$parameters=array(); $parameters=array();
$reshook=$hookmanager->executeHooks('printFieldListGroupBy',$parameters); // Note that $action and $object may have been modified by hook $reshook=$hookmanager->executeHooks('printFieldListGroupBy',$parameters); // Note that $action and $object may have been modified by hook
@@ -411,8 +411,8 @@ print '</tr>'."\n";
// Detect if we need a fetch on each output line // Detect if we need a fetch on each output line
$needToFetchEachLine=0; $needToFetchEachLine=0;
if (! empty($extrafields->attributes[$object->element]['computed'])) { if (! empty($extrafields->attributes[$object->table_element]['computed'])) {
foreach ($extrafields->attributes[$object->element]['computed'] as $key => $val) foreach ($extrafields->attributes[$object->table_element]['computed'] as $key => $val)
{ {
if (preg_match('/\$object/',$val)) $needToFetchEachLine++; // There is at least one compute field that use $object if (preg_match('/\$object/',$val)) $needToFetchEachLine++; // There is at least one compute field that use $object
} }

View File

@@ -180,12 +180,12 @@ $arrayfields=array(
'p.tobuy'=>array('label'=>$langs->trans("Status").' ('.$langs->trans("Buy").')', 'checked'=>1, 'position'=>1000) 'p.tobuy'=>array('label'=>$langs->trans("Status").' ('.$langs->trans("Buy").')', 'checked'=>1, 'position'=>1000)
); );
// Extra fields // Extra fields
if (is_array($extrafields->attributes[$object->element]['label']) && count($extrafields->attributes[$object->element]['label'])) if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label']))
{ {
foreach($extrafields->attributes[$object->element]['label'] as $key => $val) foreach($extrafields->attributes[$object->table_element]['label'] as $key => $val)
{ {
if (! empty($extrafields->attributes[$object->element]['list'][$key])) if (! empty($extrafields->attributes[$object->table_element]['list'][$key]))
$arrayfields["ef.".$key]=array('label'=>$extrafields->attributes[$object->element]['label'][$key], 'checked'=>(($extrafields->attributes[$object->element]['list'][$key]<0)?0:1), 'position'=>$extrafields->attributes[$object->element]['pos'][$key], 'enabled'=>(abs($extrafields->attributes[$object->element]['list'][$key])!=3 && $extrafields->attributes[$object->element]['perms'][$key])); $arrayfields["ef.".$key]=array('label'=>$extrafields->attributes[$object->table_element]['label'][$key], 'checked'=>(($extrafields->attributes[$object->table_element]['list'][$key]<0)?0:1), 'position'=>$extrafields->attributes[$object->table_element]['pos'][$key], 'enabled'=>(abs($extrafields->attributes[$object->table_element]['list'][$key])!=3 && $extrafields->attributes[$object->table_element]['perms'][$key]));
} }
} }
$object->fields = dol_sort_array($object->fields, 'position'); $object->fields = dol_sort_array($object->fields, 'position');
@@ -278,15 +278,15 @@ else
$sql .= ', pac.rowid prod_comb_id'; $sql .= ', pac.rowid prod_comb_id';
} }
// Add fields from extrafields // Add fields from extrafields
if (! empty($extrafields->attributes[$object->element]['label'])) { if (! empty($extrafields->attributes[$object->table_element]['label'])) {
foreach ($extrafields->attributes[$object->element]['label'] as $key => $val) $sql.=($extrafields->attributes[$object->element]['type'][$key] != 'separate' ? ",ef.".$key.' as options_'.$key : ''); foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) $sql.=($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key.' as options_'.$key : '');
} }
// Add fields from hooks // Add fields from hooks
$parameters=array(); $parameters=array();
$reshook=$hookmanager->executeHooks('printFieldListSelect',$parameters); // Note that $action and $object may have been modified by hook $reshook=$hookmanager->executeHooks('printFieldListSelect',$parameters); // Note that $action and $object may have been modified by hook
$sql.=$hookmanager->resPrint; $sql.=$hookmanager->resPrint;
$sql.= ' FROM '.MAIN_DB_PREFIX.'product as p'; $sql.= ' FROM '.MAIN_DB_PREFIX.'product as p';
if (is_array($extrafields->attributes[$object->element]['label']) && count($extrafields->attributes[$object->element]['label'])) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product_extrafields as ef on (p.rowid = ef.fk_object)"; if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product_extrafields as ef on (p.rowid = ef.fk_object)";
if (! empty($search_categ) || ! empty($catid)) $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX."categorie_product as cp ON p.rowid = cp.fk_product"; // We'll need this table joined to the select in order to filter by categ if (! empty($search_categ) || ! empty($catid)) $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX."categorie_product as cp ON p.rowid = cp.fk_product"; // We'll need this table joined to the select in order to filter by categ
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product_fournisseur_price as pfp ON p.rowid = pfp.fk_product"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product_fournisseur_price as pfp ON p.rowid = pfp.fk_product";
// multilang // multilang
@@ -337,8 +337,8 @@ else
$sql .= ', pac.rowid'; $sql .= ', pac.rowid';
} }
// Add fields from extrafields // Add fields from extrafields
if (! empty($extrafields->attributes[$object->element]['label'])) { if (! empty($extrafields->attributes[$object->table_element]['label'])) {
foreach ($extrafields->attributes[$object->element]['label'] as $key => $val) $sql.=($extrafields->attributes[$object->element]['type'][$key] != 'separate' ? ",ef.".$key : ''); foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) $sql.=($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key : '');
} }
// Add fields from hooks // Add fields from hooks
$parameters=array(); $parameters=array();