diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index dfa0baf4e8b..8f2842b4651 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -4663,10 +4663,9 @@ abstract class CommonObject * @param string $keysuffix Prefix string to add into name and id of field (can be used to avoid duplicate names) * @param string $keyprefix Suffix string to add into name and id of field (can be used to avoid duplicate names) * @param mixed $showsize Value for css to define size. May also be a numeric. - * @param int $objectid Current object id * @return string */ - function showInputField($val, $key, $value, $moreparam='', $keysuffix='', $keyprefix='', $showsize=0, $objectid=0) + function showInputField($val, $key, $value, $moreparam='', $keysuffix='', $keyprefix='', $showsize=0) { global $conf,$langs,$form; @@ -4676,6 +4675,8 @@ abstract class CommonObject $form=new Form($this->db); } + $objectid = $this->id; + $label=$val['label']; $type =$val['type']; $size =$val['css']; @@ -5178,6 +5179,328 @@ abstract class CommonObject } + /** + * Return HTML string to show a field into a page + * Code very similar with showOutputField of extra fields + * + * @param array $val Array of properties for field to show + * @param string $key Key of attribute + * @param string $value Preselected value to show (for date type it must be in timestamp format, for amount or price it must be a php numeric value) + * @param string $moreparam To add more parametes on html input tag + * @param string $keysuffix Prefix string to add into name and id of field (can be used to avoid duplicate names) + * @param string $keyprefix Suffix string to add into name and id of field (can be used to avoid duplicate names) + * @param mixed $showsize Value for css to define size. May also be a numeric. + * @return string + */ + function showOutputField($val, $key, $value, $moreparam='', $keysuffix='', $keyprefix='', $showsize=0) + { + global $conf,$langs,$form; + + if (! is_object($form)) + { + require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php'; + $form=new Form($this->db); + } + + $objectid = $this->id; + + $label=$val['label']; + $type =$val['type']; + $size =$val['css']; + + // Convert var to be able to share same code than showOutputField of extrafields + if (preg_match('/varchar/', $type)) $type = 'varchar'; // convert varchar(xx) int varchar + if (is_array($val['arrayofkeyval'])) $type='select'; + if (preg_match('/^integer:(.*):(.*)/i', $val['type'], $reg)) $type='link'; + + //$elementtype=$this->attribute_elementtype[$key]; // seems to not be used + $default=$val['default']; + $computed=$val['computed']; + $unique=$val['unique']; + $required=$val['required']; + $param=$val['param']; + if (is_array($val['arrayofkeyval'])) $param['options'] = $val['arrayofkeyval']; + if (preg_match('/^integer:(.*):(.*)/i', $val['type'], $reg)) + { + $type='link'; + $param['options']=array($reg[1].':'.$reg[2]=>$reg[1].':'.$reg[2]); + } + $langfile=$val['langfile']; + $list=$val['list']; + $hidden=(abs($val['visible'])!=1 ? 1 : 0); + $help=$val['help']; + + if ($hidden) return ''; + + // If field is a computed field, value must become result of compute + if ($computed) + { + // Make the eval of compute string + //var_dump($computed); + $value = dol_eval($computed, 1, 0); + } + + $showsize=0; + if ($type == 'date') + { + $showsize=10; + $value=dol_print_date($value,'day'); + } + elseif ($type == 'datetime') + { + $showsize=19; + $value=dol_print_date($value,'dayhour'); + } + elseif ($type == 'int') + { + $showsize=10; + } + elseif ($type == 'double') + { + if (!empty($value)) { + $value=price($value); + } + } + elseif ($type == 'boolean') + { + $checked=''; + if (!empty($value)) { + $checked=' checked '; + } + $value=''; + } + elseif ($type == 'mail') + { + $value=dol_print_email($value,0,0,0,64,1,1); + } + elseif ($type == 'url') + { + $value=dol_print_url($value,'_blank',32,1); + } + elseif ($type == 'phone') + { + $value=dol_print_phone($value, '', 0, 0, '', ' ', 1); + } + elseif ($type == 'price') + { + $value=price($value,0,$langs,0,0,-1,$conf->currency); + } + elseif ($type == 'select') + { + $value=$params['options'][$value]; + } + elseif ($type == 'sellist') + { + $param_list=array_keys($params['options']); + $InfoFieldList = explode(":", $param_list[0]); + + $selectkey="rowid"; + $keyList='rowid'; + + if (count($InfoFieldList)>=3) + { + $selectkey = $InfoFieldList[2]; + $keyList=$InfoFieldList[2].' as rowid'; + } + + $fields_label = explode('|',$InfoFieldList[1]); + if(is_array($fields_label)) { + $keyList .=', '; + $keyList .= implode(', ', $fields_label); + } + + $sql = 'SELECT '.$keyList; + $sql.= ' FROM '.MAIN_DB_PREFIX .$InfoFieldList[0]; + if (strpos($InfoFieldList[4], 'extra')!==false) + { + $sql.= ' as main'; + } + if ($selectkey=='rowid' && empty($value)) { + $sql.= " WHERE ".$selectkey."=0"; + } elseif ($selectkey=='rowid') { + $sql.= " WHERE ".$selectkey."=".$this->db->escape($value); + }else { + $sql.= " WHERE ".$selectkey."='".$this->db->escape($value)."'"; + } + + //$sql.= ' AND entity = '.$conf->entity; + + dol_syslog(get_class($this).':showOutputField:$type=sellist', LOG_DEBUG); + $resql = $this->db->query($sql); + if ($resql) + { + $value=''; // value was used, so now we reste it to use it to build final output + + $obj = $this->db->fetch_object($resql); + + // Several field into label (eq table:code|libelle:rowid) + $fields_label = explode('|',$InfoFieldList[1]); + + if(is_array($fields_label) && count($fields_label)>1) + { + foreach ($fields_label as $field_toshow) + { + $translabel=''; + if (!empty($obj->$field_toshow)) { + $translabel=$langs->trans($obj->$field_toshow); + } + if ($translabel!=$field_toshow) { + $value.=dol_trunc($translabel,18).' '; + }else { + $value.=$obj->$field_toshow.' '; + } + } + } + else + { + $translabel=''; + if (!empty($obj->{$InfoFieldList[1]})) { + $translabel=$langs->trans($obj->{$InfoFieldList[1]}); + } + if ($translabel!=$obj->{$InfoFieldList[1]}) { + $value=dol_trunc($translabel,18); + }else { + $value=$obj->{$InfoFieldList[1]}; + } + } + } + else dol_syslog(get_class($this).'::showOutputField error '.$this->db->lasterror(), LOG_WARNING); + } + elseif ($type == 'radio') + { + $value=$params['options'][$value]; + } + elseif ($type == 'checkbox') + { + $value_arr=explode(',',$value); + $value=''; + if (is_array($value_arr)) + { + foreach ($value_arr as $keyval=>$valueval) { + $toprint[]='
  • '.$params['options'][$valueval].'
  • '; + } + } + $value='
    '; + } + elseif ($type == 'chkbxlst') + { + $value_arr = explode(',', $value); + + $param_list = array_keys($params['options']); + $InfoFieldList = explode(":", $param_list[0]); + + $selectkey = "rowid"; + $keyList = 'rowid'; + + if (count($InfoFieldList) >= 3) { + $selectkey = $InfoFieldList[2]; + $keyList = $InfoFieldList[2] . ' as rowid'; + } + + $fields_label = explode('|', $InfoFieldList[1]); + if (is_array($fields_label)) { + $keyList .= ', '; + $keyList .= implode(', ', $fields_label); + } + + $sql = 'SELECT ' . $keyList; + $sql .= ' FROM ' . MAIN_DB_PREFIX . $InfoFieldList[0]; + if (strpos($InfoFieldList[4], 'extra') !== false) { + $sql .= ' as main'; + } + // $sql.= " WHERE ".$selectkey."='".$this->db->escape($value)."'"; + // $sql.= ' AND entity = '.$conf->entity; + + dol_syslog(get_class($this) . ':showOutputField:$type=chkbxlst',LOG_DEBUG); + $resql = $this->db->query($sql); + if ($resql) { + $value = ''; // value was used, so now we reste it to use it to build final output + $toprint=array(); + while ( $obj = $this->db->fetch_object($resql) ) { + + // Several field into label (eq table:code|libelle:rowid) + $fields_label = explode('|', $InfoFieldList[1]); + if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) { + if (is_array($fields_label) && count($fields_label) > 1) { + foreach ( $fields_label as $field_toshow ) { + $translabel = ''; + if (! empty($obj->$field_toshow)) { + $translabel = $langs->trans($obj->$field_toshow); + } + if ($translabel != $field_toshow) { + $toprint[]='
  • '.dol_trunc($translabel, 18).'
  • '; + } else { + $toprint[]='
  • '.$obj->$field_toshow.'
  • '; + } + } + } else { + $translabel = ''; + if (! empty($obj->{$InfoFieldList[1]})) { + $translabel = $langs->trans($obj->{$InfoFieldList[1]}); + } + if ($translabel != $obj->{$InfoFieldList[1]}) { + $toprint[]='
  • '.dol_trunc($translabel, 18).'
  • '; + } else { + $toprint[]='
  • '.$obj->{$InfoFieldList[1]}.'
  • '; + } + } + } + } + $value='
    '; + + } else { + dol_syslog(get_class($this) . '::showOutputField error ' . $this->db->lasterror(), LOG_WARNING); + } + } + elseif ($type == 'link') + { + $out=''; + + // only if something to display (perf) + if ($value) + { + $param_list=array_keys($param['options']); // $param_list='ObjectName:classPath' + + $InfoFieldList = explode(":", $param_list[0]); + $classname=$InfoFieldList[0]; + $classpath=$InfoFieldList[1]; + if (! empty($classpath)) + { + dol_include_once($InfoFieldList[1]); + if ($classname && class_exists($classname)) + { + $object = new $classname($this->db); + $object->fetch($value); + $value=$object->getNomUrl(3); + } + } + else + { + dol_syslog('Error bad setup of extrafield', LOG_WARNING); + return 'Error bad setup of extrafield'; + } + } + } + elseif ($type == 'text') + { + $value=dol_htmlentitiesbr($value); + } + elseif ($type == 'password') + { + $value=preg_replace('/./i','*',$value); + } + else + { + $showsize=round($size); + if ($showsize > 48) $showsize=48; + } + + //print $type.'-'.$size; + $out=$value; + + return $out; + } + /** * Function to show lines of extrafields with output datas diff --git a/htdocs/core/class/extrafields.class.php b/htdocs/core/class/extrafields.class.php index 012a3ce7acc..68463aebb5b 100644 --- a/htdocs/core/class/extrafields.class.php +++ b/htdocs/core/class/extrafields.class.php @@ -809,7 +809,13 @@ class ExtraFields */ function showInputField($key, $value, $moreparam='', $keysuffix='', $keyprefix='', $showsize=0, $objectid=0) { - global $conf,$langs; + global $conf,$langs,$form; + + if (! is_object($form)) + { + require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php'; + $form=new Form($this->db); + } $keyprefix = $keyprefix.'options_'; // Because we work on extrafields @@ -885,10 +891,6 @@ class ExtraFields // Do not show current date when field not required (see select_date() method) if (!$required && $value == '') $value = '-1'; - require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php'; - global $form; - if (! is_object($form)) $form=new Form($this->db); - // TODO Must also support $moreparam $out = $form->select_date($value, $keyprefix.$key.$keysuffix, $showtime, $showtime, $required, '', 1, ($keyprefix != 'search_' ? 1 : 0), 1, 0, 1); } @@ -1125,12 +1127,8 @@ class ExtraFields } elseif ($type == 'checkbox') { - require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php'; - $form = new Form($db); - $value_arr=explode(',',$value); $out=$form->multiselectarray($keyprefix.$key.$keysuffix, (empty($param['options'])?null:$param['options']), $value_arr, '', 0, '', 0, '100%'); - } elseif ($type == 'radio') { @@ -1280,9 +1278,6 @@ class ExtraFields } $this->db->free($resql); - require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php'; - $form = new Form($db); - $out=$form->multiselectarray($keyprefix.$key.$keysuffix, $data, $value_arr, '', 0, '', 0, '100%'); } else { @@ -1293,33 +1288,9 @@ class ExtraFields } elseif ($type == 'link') { - $out=''; - - $param_list=array_keys($param['options']); - // 0 : ObjectName - // 1 : classPath - $InfoFieldList = explode(":", $param_list[0]); - dol_include_once($InfoFieldList[1]); - if ($InfoFieldList[0] && class_exists($InfoFieldList[0])) - { - $valuetoshow=$value; - if (!empty($value)) - { - $object = new $InfoFieldList[0]($this->db); - $resfetch=$object->fetch($value); - if ($resfetch > 0) - { - $valuetoshow=$object->ref; - if ($object->element == 'societe') $valuetoshow=$object->name; // Special case for thirdparty because ->ref is not name but id (because name is not unique) - } - } - $out.=''; - } - else - { - dol_syslog('Error bad setup of extrafield', LOG_WARNING); - $out.='Error bad setup of extrafield'; - } + $param_list=array_keys($param['options']); // $param_list='ObjectName:classPath' + $showempty=(($val['notnull'] == 1 && $val['default'] != '')?0:1); + $out=$form->selectForForms($param_list[0], $keyprefix.$key.$keysuffix, $value, $showempty); } elseif ($type == 'password') { @@ -1357,11 +1328,13 @@ class ExtraFields $computed=$this->attribute_computed[$key]; $unique=$this->attribute_unique[$key]; $required=$this->attribute_required[$key]; - $params=$this->attribute_param[$key]; + $param=$this->attribute_param[$key]; $perms=$this->attribute_perms[$key]; $langfile=$this->attribute_langfile[$key]; $list=$this->attribute_list[$key]; - $hidden=$this->attribute_hidden[$key]; // warning, do not rely on this. If your module need a hidden data, it must use its own table. + $hidden=(abs($list)!=1 ? 1 : 0); + + if ($hidden) return ''; // If field is a computed field, value must become result of compute if ($computed) @@ -1418,11 +1391,11 @@ class ExtraFields } elseif ($type == 'select') { - $value=$params['options'][$value]; + $value=$param['options'][$value]; } elseif ($type == 'sellist') { - $param_list=array_keys($params['options']); + $param_list=array_keys($param['options']); $InfoFieldList = explode(":", $param_list[0]); $selectkey="rowid"; @@ -1499,7 +1472,7 @@ class ExtraFields } elseif ($type == 'radio') { - $value=$params['options'][$value]; + $value=$param['options'][$value]; } elseif ($type == 'checkbox') { @@ -1508,7 +1481,7 @@ class ExtraFields if (is_array($value_arr)) { foreach ($value_arr as $keyval=>$valueval) { - $toprint[]='
  • '.$params['options'][$valueval].'
  • '; + $toprint[]='
  • '.$param['options'][$valueval].'
  • '; } } $value='
    '; @@ -1517,7 +1490,7 @@ class ExtraFields { $value_arr = explode(',', $value); - $param_list = array_keys($params['options']); + $param_list = array_keys($param['options']); $InfoFieldList = explode(":", $param_list[0]); $selectkey = "rowid"; @@ -1589,22 +1562,26 @@ class ExtraFields // only if something to display (perf) if ($value) { - $param_list=array_keys($params['options']); - // 0 : ObjectName - // 1 : classPath + $param_list=array_keys($param['options']); // $param_list='ObjectName:classPath' + $InfoFieldList = explode(":", $param_list[0]); - dol_include_once($InfoFieldList[1]); - if ($InfoFieldList[0] && class_exists($InfoFieldList[0])) - { - $object = new $InfoFieldList[0]($this->db); - $object->fetch($value); - $value=$object->getNomUrl(3); - } - else - { - dol_syslog('Error bad setup of extrafield', LOG_WARNING); - $out.='Error bad setup of extrafield'; - } + $classname=$InfoFieldList[0]; + $classpath=$InfoFieldList[1]; + if (! empty($classpath)) + { + dol_include_once($InfoFieldList[1]); + if ($classname && class_exists($classname)) + { + $object = new $classname($this->db); + $object->fetch($value); + $value=$object->getNomUrl(3); + } + } + else + { + dol_syslog('Error bad setup of extrafield', LOG_WARNING); + return 'Error bad setup of extrafield'; + } } } elseif ($type == 'text') @@ -1624,10 +1601,6 @@ class ExtraFields //print $type.'-'.$size; $out=$value; - if (!empty($hidden)) { - $out=''; - } - return $out; } diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index e95f43e3283..1eb4e600c74 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -5172,11 +5172,13 @@ class Form if (! empty($conf->use_javascript_ajax) && ! empty($conf->global->$confkeyforautocompletemode) && ! $forcecombo) { $objectdesc=$classname.':'.$classpath; + $urlforajaxcall = DOL_URL_ROOT.'/core/ajax/selectobject.php'; + //if ($objecttmp->element == 'societe') $urlforajaxcall = DOL_URL_ROOT.'/societe/ajax/company.php'; // No immediate load of all database $urloption='htmlname='.$htmlname.'&outjson=1&objectdesc='.$objectdesc.($moreparams?$moreparams:''); // Activate the auto complete using ajax call. - $out.= ajax_autocompleter($preselectedvalue, $htmlname, DOL_URL_ROOT.'/core/ajax/selectobject.php', $urloption, $conf->global->$confkeyforautocompletemode, 0, array()); + $out.= ajax_autocompleter($preselectedvalue, $htmlname, $urlforajaxcall, $urloption, $conf->global->$confkeyforautocompletemode, 0, array()); $out.= ''; if ($placeholder) $placeholder=' placeholder="'.$placeholder.'"'; $out.= ''; diff --git a/htdocs/core/tpl/card_presend.tpl.php b/htdocs/core/tpl/card_presend.tpl.php index 6e653372148..01b53487821 100644 --- a/htdocs/core/tpl/card_presend.tpl.php +++ b/htdocs/core/tpl/card_presend.tpl.php @@ -34,8 +34,10 @@ if ($action == 'presend') $object->fetch_projet(); - if (! in_array($object->element, array('societe', 'user'))) + if (! in_array($object->element, array('societe', 'user', 'member'))) { + // TODO get also the main_lastdoc field of $object. If not found, try to guess with following code + $ref = dol_sanitizeFileName($object->ref); include_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php'; $fileparams = dol_most_recent_file($diroutput . '/' . $ref, preg_quote($ref, '/').'[^\-]+'); @@ -75,19 +77,17 @@ if ($action == 'presend') } // Build document if it not exists - if (! in_array($object->element, array('societe', 'user'))) + if (! in_array($object->element, array('societe', 'user', 'member'))) { - if (! $file || ! is_readable($file)) { - if ($object->element != 'member') - { - $result = $object->generateDocument(GETPOST('model') ? GETPOST('model') : $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref); - if ($result <= 0) { - dol_print_error($db, $object->error, $object->errors); - exit(); - } - $fileparams = dol_most_recent_file($diroutput . '/' . $ref, preg_quote($ref, '/').'[^\-]+'); - $file = $fileparams['fullname']; + if ((! $file || ! is_readable($file)) && method_exists($object, 'generateDocument')) + { + $result = $object->generateDocument(GETPOST('model') ? GETPOST('model') : $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref); + if ($result <= 0) { + dol_print_error($db, $object->error, $object->errors); + exit(); } + $fileparams = dol_most_recent_file($diroutput . '/' . $ref, preg_quote($ref, '/').'[^\-]+'); + $file = $fileparams['fullname']; } } diff --git a/htdocs/core/tpl/commonfields_add.tpl.php b/htdocs/core/tpl/commonfields_add.tpl.php index e89c118c6f9..203ba67f3db 100644 --- a/htdocs/core/tpl/commonfields_add.tpl.php +++ b/htdocs/core/tpl/commonfields_add.tpl.php @@ -42,7 +42,7 @@ foreach($object->fields as $key => $val) if (in_array($val['type'], array('int', 'integer'))) $value = GETPOST($key, 'int'); elseif ($val['type'] == 'text') $value = GETPOST($key, 'none'); else $value = GETPOST($key, 'alpha'); - print $object->showInputField($val, $key, $value, '', '', '', 0, 0); + print $object->showInputField($val, $key, $value, '', '', '', 0); print ''; print ''; } diff --git a/htdocs/core/tpl/commonfields_edit.tpl.php b/htdocs/core/tpl/commonfields_edit.tpl.php index eeb8a761896..a70b92e6f46 100644 --- a/htdocs/core/tpl/commonfields_edit.tpl.php +++ b/htdocs/core/tpl/commonfields_edit.tpl.php @@ -36,22 +36,10 @@ foreach($object->fields as $key => $val) print '"'; print '>'.$langs->trans($val['label']).''; print ''; - $defaultcss='minwidth100'; - if ($val['type'] == 'text') - { - print ''; - } - elseif (is_array($val['arrayofkeyval'])) - { - print $form->selectarray($key, $val['arrayofkeyval'], GETPOST($key, 'int')!=''?GETPOST($key, 'int'):$object->$key); - } - else - { - $cssforinput = empty($val['css'])?$defaultcss:$val['css']; - print ''; - } + if (in_array($val['type'], array('int', 'integer'))) $value = GETPOSTISSET($key)?GETPOST($key, 'int'):$object->$key; + elseif ($val['type'] == 'text') $value = GETPOSTISSET($key)?GETPOST($key,'none'):$object->$key; + else $value = GETPOSTISSET($key)?GETPOST($key, 'alpha'):$object->$key; + print $object->showInputField($val, $key, $value, '', '', '', 0); print ''; print ''; } diff --git a/htdocs/core/tpl/commonfields_view.tpl.php b/htdocs/core/tpl/commonfields_view.tpl.php new file mode 100644 index 00000000000..4c0f23a5af2 --- /dev/null +++ b/htdocs/core/tpl/commonfields_view.tpl.php @@ -0,0 +1,84 @@ + + * + * 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, ...) + * $action + * $conf + * $langs + */ +?> + +fields as $key => $val) +{ + if (abs($val['visible']) != 1) continue; // Discard such field from form + if (array_key_exists('enabled', $val) && isset($val['enabled']) && ! $val['enabled']) continue; // We don't want this field + if ($key == 'status') continue; // Status is alreadt in dol_banner + + $value=$object->$key; + + print ''.$langs->trans($val['label']).''; + print ''; + print $object->showOutputField($val, $key, $value, '', '', '', 0); + //print dol_escape_htmltag($object->$key, 1, 1); + print ''; + print ''; + + //if ($key == 'targetsrcfile3') break; // key used for break on second column +} + +print ''; +print ''; +print '
    '; +print '
    '; +print '
    '; +print ''; + +$alreadyoutput = 1; +foreach($object->fields as $key => $val) +{ + if ($alreadyoutput) + { + //if ($key == 'targetsrcfile3') $alreadyoutput = 0; // key used for break on second column + continue; + } + + if (abs($val['visible']) != 1) continue; // Discard such field from form + if (array_key_exists('enabled', $val) && isset($val['enabled']) && ! $val['enabled']) continue; // We don't want this field + if ($key == 'status') continue; // Status is alreadt in dol_banner + + $value=$object->$key; + + print ''.$langs->trans($val['label']).''; + print ''; + print ''; +} + +?> + \ No newline at end of file diff --git a/htdocs/core/tpl/extrafields_view.tpl.php b/htdocs/core/tpl/extrafields_view.tpl.php index 973308b2e25..c4120552b80 100644 --- a/htdocs/core/tpl/extrafields_view.tpl.php +++ b/htdocs/core/tpl/extrafields_view.tpl.php @@ -111,7 +111,7 @@ if (empty($reshook) && ! empty($extrafields->attributes[$object->table_element][ print ''; print ''; - print $extrafields->showInputField($key, $value,'','','',0,$object->id); + print $extrafields->showInputField($key, $value, '', '', '', 0, $object->id); print ''; diff --git a/htdocs/langs/en_US/mails.lang b/htdocs/langs/en_US/mails.lang index ccf52302e9a..4be167d3061 100644 --- a/htdocs/langs/en_US/mails.lang +++ b/htdocs/langs/en_US/mails.lang @@ -99,7 +99,6 @@ NbOfCompaniesContacts=Unique contacts/addresses MailNoChangePossible=Recipients for validated emailing can't be changed SearchAMailing=Search mailing SendMailing=Send emailing -SendMail=Send email SentBy=Sent by MailingNeedCommand=Sending an emailing can be performed from command line. Ask your server administrator to launch the following command to send the emailing to all recipients: MailingNeedCommand2=You can however send them online by adding parameter MAILING_LIMIT_SENDBYWEB with value of max number of emails you want to send by session. For this, go on Home - Setup - Other. diff --git a/htdocs/langs/en_US/main.lang b/htdocs/langs/en_US/main.lang index 09b9bb1793c..bb1bda2fba1 100644 --- a/htdocs/langs/en_US/main.lang +++ b/htdocs/langs/en_US/main.lang @@ -610,6 +610,7 @@ SendByMail=Send by EMail MailSentBy=Email sent by TextUsedInTheMessageBody=Email body SendAcknowledgementByMail=Send confirmation email +SendMail=Send email EMail=E-mail NoEMail=No email Email=Email diff --git a/htdocs/langs/en_US/modulebuilder.lang b/htdocs/langs/en_US/modulebuilder.lang index 5d1ec1a243d..a66e8b636cf 100644 --- a/htdocs/langs/en_US/modulebuilder.lang +++ b/htdocs/langs/en_US/modulebuilder.lang @@ -71,7 +71,7 @@ NoWidget=No widget GoToApiExplorer=Go to API explorer ListOfPermissionsDefined=List of defined permissions 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 forms, 2=Visible on list only. Using a negative value means field is not shown by default on list but can be selected for viewing) +VisibleDesc=Is the field visible ? (Examples: 0=Never visible, 1=Visible on list and create/update/view forms, 2=Visible on list only. Using a negative value means field is not shown by default on list but can be selected for viewing) 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. diff --git a/htdocs/langs/en_US/website.lang b/htdocs/langs/en_US/website.lang index 043fcb52472..eb1bab43905 100644 --- a/htdocs/langs/en_US/website.lang +++ b/htdocs/langs/en_US/website.lang @@ -51,5 +51,6 @@ OrEnterPageInfoManually=Or create empty page from scratch... FetchAndCreate=Fetch and Create ExportSite=Export site IDOfPage=Id of page +WebsiteAccount=Web site account WebsiteAccounts=Web site accounts AddWebsiteAccount=Create web site account \ No newline at end of file diff --git a/htdocs/modulebuilder/template/class/myobject.class.php b/htdocs/modulebuilder/template/class/myobject.class.php index efb467e37b7..d837e413c14 100644 --- a/htdocs/modulebuilder/template/class/myobject.class.php +++ b/htdocs/modulebuilder/template/class/myobject.class.php @@ -48,7 +48,7 @@ class MyObject extends CommonObject */ public $ismultientitymanaged = 0; /** - * @var string String with name of icon for myobject + * @var string String with name of icon for myobject. Must be the part after the 'object_' into object_myobject.png */ public $picto = 'myobject@mymodule'; @@ -57,7 +57,7 @@ class MyObject extends CommonObject * 'type' if the field format. * 'label' the translation key. * 'enabled' is a condition when the field must be managed. - * 'visible' says if field is visible in list (Examples: 0=Not visible, 1=Visible on list and forms, 2=Visible on list only. Using a negative value means field is not shown by default on list but can be selected for viewing) + * 'visible' says if field is visible in list (Examples: 0=Not visible, 1=Visible on list and create/update/view forms, 2=Visible on list only. Using a negative value means field is not shown by default on list but can be selected for viewing) * 'notnull' is set to 1 if not null in database. Set to -1 if we must set data to null if empty ('' or 0). * 'index' if we want an index in database. * 'foreignkey'=>'tablename.field' if the field is a foreign key (it is recommanded to name the field fk_...). @@ -315,7 +315,7 @@ class MyObject extends CommonObject if ($withpicto) { - $result.=($linkstart.img_object(($notooltip?'':$label), 'label', ($notooltip?'':'class="classfortooltip"')).$linkend); + $result.=($linkstart.img_object(($notooltip?'':$label), ($this->picto?$this->picto:'generic'), ($notooltip?'':'class="classfortooltip"')).$linkend); if ($withpicto != 2) $result.=' '; } $result.= $linkstart . $this->ref . $linkend; diff --git a/htdocs/modulebuilder/template/myobject_card.php b/htdocs/modulebuilder/template/myobject_card.php index 76c5fd7dc16..8f5583ceed3 100644 --- a/htdocs/modulebuilder/template/myobject_card.php +++ b/htdocs/modulebuilder/template/myobject_card.php @@ -320,52 +320,8 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea print '
    '; print '
    '; + print $object->showOutputField($val, $key, $value, '', '', '', 0); + //print dol_escape_htmltag($object->$key, 1, 1); + print '
    '."\n"; - foreach($object->fields as $key => $val) - { - if (abs($val['visible']) != 1) continue; // Discard such field from form - if (array_key_exists('enabled', $val) && isset($val['enabled']) && ! $val['enabled']) continue; // We don't want this field - - print ''.$langs->trans($val['label']).''; - print ''; - print ''; - - //if ($key == 'targetsrcfile3') break; // key used for break on second column - } - - print '
    '; - print dol_escape_htmltag($object->$key, 1, 1); - print '
    '; - print '
    '; - print '
    '; - print '
    '; - print '
    '; - print ''; - - $alreadyoutput = 1; - foreach($object->fields as $key => $val) - { - if ($alreadyoutput) - { - //if ($key == 'targetsrcfile3') $alreadyoutput = 0; // key used for break on second column - continue; - } - - if (in_array($key, array('rowid', 'ref', 'entity', 'note_public', 'note_private', 'date_creation', 'tms', 'fk_user_creat', 'fk_user_modif', 'import_key', 'status'))) continue; - - print ''.$langs->trans($val['label']).''; - print ''; - print ''; - } + // Common attributes + include DOL_DOCUMENT_ROOT . '/core/tpl/commonfields_view.tpl.php'; // Other attributes include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php'; @@ -390,7 +346,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea if (empty($reshook)) { // Send - print ''."\n"; + print ''."\n"; if ($user->rights->mymodule->write) { @@ -429,15 +385,16 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea { print '
    '; print ''; // ancre + // Documents - $comref = dol_sanitizeFileName($object->ref); + /*$comref = dol_sanitizeFileName($object->ref); $relativepath = $comref . '/' . $comref . '.pdf'; $filedir = $conf->mymodule->dir_output . '/' . $comref; $urlsource = $_SERVER["PHP_SELF"] . "?id=" . $object->id; $genallowed = $user->rights->mymodule->read; // If you can read, you can build the PDF to read content $delallowed = $user->rights->mymodule->create; // If you can create/edit, you can remove a file on card print $formfile->showdocuments('mymodule', $comref, $filedir, $urlsource, $genallowed, $delallowed, $object->modelpdf, 1, 0, 0, 28, 0, '', '', '', $soc->default_lang); - + */ // Show links to link elements $linktoelem = $form->showLinkToObjectBlock($object, null, array('myobject')); diff --git a/htdocs/societe/website.php b/htdocs/societe/website.php index 6e7a74c45d9..7a17e05c827 100644 --- a/htdocs/societe/website.php +++ b/htdocs/societe/website.php @@ -491,7 +491,7 @@ while ($i < min($num, $limit)) print ''; if (in_array($val['type'], array('date'))) print dol_print_date($db->jdate($obj->$key), 'day', 'tzuser'); elseif (in_array($val['type'], array('datetime','timestamp'))) print dol_print_date($db->jdate($obj->$key), 'dayhour', 'tzuser'); - elseif ($key == 'ref') print $objectwebsiteaccount->getNomUrl(1, '', 0, '', 1); + elseif ($key == 'ref' || $key == 'login') print $objectwebsiteaccount->getNomUrl(1, '', 0, '', 1); elseif ($key == 'status') print $objectwebsiteaccount->getLibStatut(3); else print $obj->$key; print ''; diff --git a/htdocs/website/class/website.class.php b/htdocs/website/class/website.class.php index eebe072601b..8fb23d2b8a2 100644 --- a/htdocs/website/class/website.class.php +++ b/htdocs/website/class/website.class.php @@ -43,6 +43,10 @@ class Website extends CommonObject * @var string Name of table without prefix where object is stored */ public $table_element = 'website'; + /** + * @var string String with name of icon for websiteaccount. Must be the part after the 'object_' into object_myobject.png + */ + public $picto = 'globe'; /** * @var int @@ -648,21 +652,23 @@ class Website extends CommonObject $result = ''; $companylink = ''; - $label = '' . $langs->trans("MyModule") . ''; + $label = '' . $langs->trans("WebSite") . ''; $label.= '
    '; - $label.= '' . $langs->trans('Ref') . ': ' . $this->ref; + $label.= '' . $langs->trans('Nom') . ': ' . $this->ref; - $link = 'picto?$this->picto:'generic'), ($notooltip?'':'class="classfortooltip"')).$linkend); if ($withpicto != 2) $result.=' '; } - $result.= $link . $this->ref . $linkend; + $result.= $linkstart . $this->ref . $linkend; return $result; } diff --git a/htdocs/website/class/websiteaccount.class.php b/htdocs/website/class/websiteaccount.class.php index b96f511cac3..f420c8abcf8 100644 --- a/htdocs/website/class/websiteaccount.class.php +++ b/htdocs/website/class/websiteaccount.class.php @@ -43,23 +43,21 @@ class WebsiteAccount extends CommonObject * @var string Name of table without prefix where object is stored */ public $table_element = 'websiteaccount'; - /** * @var array Does websiteaccount support multicompany module ? 0=No test on entity, 1=Test with field entity, 2=Test with link by societe */ public $ismultientitymanaged = 0; - /** - * @var string String with name of icon for websiteaccount + * @var string String with name of icon for websiteaccount. Must be the part after the 'object_' into object_myobject.png */ - public $picto = 'object_globe'; + public $picto = 'globe'; /** * 'type' if the field format. * 'label' the translation key. * 'enabled' is a condition when the field must be managed. - * 'visible' says if field is visible in list (Examples: 0=Not visible, 1=Visible on list and forms, 2=Visible on list only. Using a negative value means field is not shown by default on list but can be selected for viewing) + * 'visible' says if field is visible in list (Examples: 0=Not visible, 1=Visible on list and create/update/view forms, 2=Visible on list only. Using a negative value means field is not shown by default on list but can be selected for viewing) * 'notnull' is set to 1 if not null in database. Set to -1 if we must set data to null if empty ('' or 0). * 'index' if we want an index in database. * 'foreignkey'=>'tablename.field' if the field is a foreign key (it is recommanded to name the field fk_...). @@ -284,9 +282,12 @@ class WebsiteAccount extends CommonObject $result = ''; $companylink = ''; + $this->ref = $this->login; + $label = '' . $langs->trans("WebsiteAccount") . ''; $label.= '
    '; - $label.= '' . $langs->trans('Ref') . ': ' . $this->ref; + $label.= '' . $langs->trans('Login') . ': ' . $this->ref; + //$label.= '' . $langs->trans('WebSite') . ': ' . $this->ref; $url = dol_buildpath('/website/websiteaccount_card.php',1).'?id='.$this->id; @@ -317,7 +318,7 @@ class WebsiteAccount extends CommonObject if ($withpicto) { - $result.=($linkstart.img_object(($notooltip?'':$label), 'label', ($notooltip?'':'class="classfortooltip"')).$linkend); + $result.=($linkstart.img_object(($notooltip?'':$label), ($this->picto?$this->picto:'generic'), ($notooltip?'':'class="classfortooltip"')).$linkend); if ($withpicto != 2) $result.=' '; } $result.= $linkstart . $this->ref . $linkend; diff --git a/htdocs/website/class/websitepage.class.php b/htdocs/website/class/websitepage.class.php index 12f36f5daa7..34a6f047874 100644 --- a/htdocs/website/class/websitepage.class.php +++ b/htdocs/website/class/websitepage.class.php @@ -43,6 +43,10 @@ class WebsitePage extends CommonObject * @var string Name of table without prefix where object is stored */ public $table_element = 'website_page'; + /** + * @var string String with name of icon for websiteaccount. Must be the part after the 'object_' into object_myobject.png + */ + public $picto = 'label'; /** */ @@ -408,17 +412,19 @@ class WebsitePage extends CommonObject $label.= '
    '; $label.= '' . $langs->trans('Ref') . ': ' . $this->ref; - $link = 'picto?$this->picto:'generic'), ($notooltip?'':'class="classfortooltip"')).$linkend); + if ($withpicto != 2) $result.=' '; } - $result.= $link . $this->ref . $linkend; + $result.= $linkstart . $this->ref . $linkend; return $result; } diff --git a/htdocs/website/lib/websiteaccount.lib.php b/htdocs/website/lib/websiteaccount.lib.php new file mode 100644 index 00000000000..b294b25f3b2 --- /dev/null +++ b/htdocs/website/lib/websiteaccount.lib.php @@ -0,0 +1,85 @@ + + * + * 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 . + */ + +/** + * \file htdocs/website/lib/websiteaccount.lib.php + * \ingroup website + * \brief Library files with common functions for WebsiteAccount + */ + +/** + * Prepare array of tabs for WebsiteAccount + * + * @param WebsiteAccount $object WebsiteAccount + * @return array Array of tabs + */ +function websiteaccountPrepareHead($object) +{ + global $db, $langs, $conf; + + $langs->load("monmodule@monmodule"); + + $h = 0; + $head = array(); + + $head[$h][0] = dol_buildpath("/website/websiteaccount_card.php", 1).'?id='.$object->id; + $head[$h][1] = $langs->trans("Card"); + $head[$h][2] = 'card'; + $h++; + + if (isset($object->fields['note_public']) || isset($object->fields['note_private'])) + { + $nbNote = 0; + if(!empty($object->fields['note_private'])) $nbNote++; + if(!empty($object->fields['note_public'])) $nbNote++; + $head[$h][0] = dol_buildpath('/monmodule/websiteaccount_note.php', 1).'?id='.$object->id; + $head[$h][1] = $langs->trans('Notes'); + if ($nbNote > 0) $head[$h][1].= ' '.$nbNote.''; + $head[$h][2] = 'note'; + $h++; + } + + /* + require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; + require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php'; + $upload_dir = $conf->monmodule->dir_output . "/websiteaccount/" . dol_sanitizeFileName($object->ref); + $nbFiles = count(dol_dir_list($upload_dir,'files',0,'','(\.meta|_preview.*\.png)$')); + $nbLinks=Link::count($db, $object->element, $object->id); + $head[$h][0] = dol_buildpath("/monmodule/websiteaccount_document.php", 1).'?id='.$object->id; + $head[$h][1] = $langs->trans('Documents'); + if (($nbFiles+$nbLinks) > 0) $head[$h][1].= ' '.($nbFiles+$nbLinks).''; + $head[$h][2] = 'document'; + $h++; + + $head[$h][0] = dol_buildpath("/monmodule/websiteaccount_agenda.php", 1).'?id='.$object->id; + $head[$h][1] = $langs->trans("Events"); + $head[$h][2] = 'agenda'; + $h++; + */ + + // Show more tabs from modules + // Entries must be declared in modules descriptor with line + //$this->tabs = array( + // 'entity:+tabname:Title:@monmodule:/monmodule/mypage.php?id=__ID__' + //); // to add new tab + //$this->tabs = array( + // 'entity:-tabname:Title:@monmodule:/monmodule/mypage.php?id=__ID__' + //); // to remove a tab + complete_head_from_modules($conf, $langs, $object, $head, $h, 'websiteaccount@website'); + + return $head; +} diff --git a/htdocs/website/websiteaccount_card.php b/htdocs/website/websiteaccount_card.php index abdfd06e911..a94e82597a0 100644 --- a/htdocs/website/websiteaccount_card.php +++ b/htdocs/website/websiteaccount_card.php @@ -1,7 +1,6 @@ - * Copyright (C) ---Put here your own copyright and developer email--- - * +* * 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 @@ -53,8 +52,8 @@ if (! $res) die("Include of main fails"); include_once(DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php'); include_once(DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php'); -dol_include_once('/website/class/websiteaccount.class.php'); -//dol_include_once('/website/lib/websiteaccount.lib.php'); +include_once(DOL_DOCUMENT_ROOT.'/website/class/websiteaccount.class.php'); +include_once(DOL_DOCUMENT_ROOT.'/website/lib/websiteaccount.lib.php'); // Load traductions files requiredby by page $langs->loadLangs(array("website","other")); @@ -259,7 +258,9 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea // Object card // ------------------------------------------------------------ - $linkback = '' . $langs->trans("BackToList") . ''; + $linkback=''; + if ($socid) $linkback = '' . $langs->trans("BackToList") . ''; + if ($fk_website) $linkback = '' . $langs->trans("BackToList") . ''; $morehtmlref='
    '; /* @@ -314,52 +315,8 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea print '
    '; print '
    '; - print dol_escape_htmltag($object->$key, 1, 1); - print '
    '."\n"; - foreach($object->fields as $key => $val) - { - if (abs($val['visible']) != 1) continue; // Discard such field from form - if (array_key_exists('enabled', $val) && isset($val['enabled']) && ! $val['enabled']) continue; // We don't want this field - - print ''.$langs->trans($val['label']).''; - print ''; - print ''; - - //if ($key == 'targetsrcfile3') break; // key used for break on second column - } - - print '
    '; - print dol_escape_htmltag($object->$key, 1, 1); - print '
    '; - print '
    '; - print '
    '; - print '
    '; - print '
    '; - print ''; - - $alreadyoutput = 1; - foreach($object->fields as $key => $val) - { - if ($alreadyoutput) - { - //if ($key == 'targetsrcfile3') $alreadyoutput = 0; // key used for break on second column - continue; - } - - if (in_array($key, array('rowid', 'ref', 'entity', 'note_public', 'note_private', 'date_creation', 'tms', 'fk_user_creat', 'fk_user_modif', 'import_key', 'status'))) continue; - - print ''.$langs->trans($val['label']).''; - print ''; - print ''; - } + // Common attributes + include DOL_DOCUMENT_ROOT . '/core/tpl/commonfields_view.tpl.php'; // Other attributes include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php'; @@ -384,7 +341,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea if (empty($reshook)) { // Send - print ''."\n"; + print ''."\n"; if ($user->rights->website->write) { @@ -423,29 +380,32 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea { print '
    '; print ''; // ancre + // Documents - $comref = dol_sanitizeFileName($object->ref); + /*$comref = dol_sanitizeFileName($object->ref); $relativepath = $comref . '/' . $comref . '.pdf'; $filedir = $conf->website->dir_output . '/' . $comref; $urlsource = $_SERVER["PHP_SELF"] . "?id=" . $object->id; $genallowed = $user->rights->website->read; // If you can read, you can build the PDF to read content $delallowed = $user->rights->website->create; // If you can create/edit, you can remove a file on card print $formfile->showdocuments('website', $comref, $filedir, $urlsource, $genallowed, $delallowed, $object->modelpdf, 1, 0, 0, 28, 0, '', '', '', $soc->default_lang); - + */ // Show links to link elements - $linktoelem = $form->showLinkToObjectBlock($object, null, array('websiteaccount')); + /*$linktoelem = $form->showLinkToObjectBlock($object, null, array('websiteaccount')); $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem); - + */ print '
    '; $MAXEVENT = 10; // List of actions on element + /* include_once DOL_DOCUMENT_ROOT . '/core/class/html.formactions.class.php'; $formactions = new FormActions($db); $somethingshown = $formactions->showactions($object, 'websiteaccount', $socid, 1, '', $MAXEVENT); + */ print '
    '; }
    '; - print dol_escape_htmltag($object->$key, 1, 1); - print '