dolibarr  19.0.0-dev
admin_extrafields_edit.tpl.php
1 <?php
2 /* Copyright (C) 2010-2012 Laurent Destailleur <eldy@users.sourceforge.net>
3  * Copyright (C) 2012 Regis Houssin <regis.houssin@inodbox.com>
4  * Copyright (C) 2018-2023 Frédéric France <frederic.france@netlogic.fr>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <https://www.gnu.org/licenses/>.
18  */
19 
29 // Protection to avoid direct call of template
30 if (empty($conf) || !is_object($conf)) {
31  print "Error, template page can't be called as URL";
32  exit;
33 }
34 
35 
36 $langs->load("modulebuilder");
37 
38 $listofexamplesforlink = 'Societe:societe/class/societe.class.php<br>Contact:contact/class/contact.class.php<br>Product:product/class/product.class.php<br>Project:projet/class/project.class.php<br>...';
39 
40 ?>
41 
42 <!-- BEGIN PHP TEMPLATE admin_extrafields_edit.tpl.php -->
43 <script>
44  jQuery(document).ready(function() {
45  function init_typeoffields(type)
46  {
47  console.log("select a new type (edit) = "+type);
48  var size = jQuery("#size");
49  var computed_value = jQuery("#computed_value");
50  var langfile = jQuery("#langfile");
51  var default_value = jQuery("#default_value");
52  var unique = jQuery("#unique");
53  var required = jQuery("#required");
54  var alwayseditable = jQuery("#alwayseditable");
55  var list = jQuery("#list");
56  var totalizable = jQuery("#totalizable");
57  <?php
58  if ((GETPOST('type', 'alpha') != "select") && (GETPOST('type', 'alpha') != "sellist")) {
59  print 'jQuery("#value_choice").hide();';
60  }
61 
62  if (GETPOST('type', 'alpha') == "separate") {
63  print "jQuery('#size, #default_value, #langfile').val('').prop('disabled', true);";
64  print 'jQuery("#value_choice").hide();';
65  }
66  ?>
67 
68  // Case of computed field
69  if (type == 'varchar' || type == 'int' || type == 'double' || type == 'price') {
70  jQuery("tr.extra_computed_value").show();
71  } else {
72  computed_value.val(''); jQuery("tr.extra_computed_value").hide();
73  }
74  if (computed_value.val())
75  {
76  console.log("We enter a computed formula");
77  jQuery("#default_value").val('');
78  /* jQuery("#unique, #required, #alwayseditable, #list").removeAttr('checked'); */
79  jQuery("#default_value, #unique, #required, #alwayseditable, #list").attr('disabled', true);
80  jQuery("tr.extra_default_value, tr.extra_unique, tr.extra_required, tr.extra_alwayseditable, tr.extra_list").hide();
81  }
82  else
83  {
84  console.log("No computed formula");
85  jQuery("#default_value, #unique, #required, #alwayseditable, #list").attr('disabled', false);
86  jQuery("tr.extra_default_value, tr.extra_unique, tr.extra_required, tr.extra_alwayseditable, tr.extra_list").show();
87  }
88 
89  if (type == 'date') { size.val('').prop('disabled', true); unique.removeAttr('disabled'); jQuery("#value_choice").hide();jQuery("#helpchkbxlst").hide(); }
90  else if (type == 'datetime') { size.val('').prop('disabled', true); unique.removeAttr('disabled'); jQuery("#value_choice").hide(); jQuery("#helpchkbxlst").hide();}
91  else if (type == 'double') { size.removeAttr('disabled'); unique.removeAttr('disabled'); jQuery("#value_choice").hide(); jQuery("#helpchkbxlst").hide();}
92  else if (type == 'int') { size.removeAttr('disabled'); unique.removeAttr('disabled'); jQuery("#value_choice").hide(); jQuery("#helpchkbxlst").hide();}
93  else if (type == 'text') { size.removeAttr('disabled'); unique.prop('disabled', true).removeAttr('checked'); jQuery("#value_choice").hide();jQuery("#helpchkbxlst").hide(); }
94  else if (type == 'html') { size.removeAttr('disabled'); unique.prop('disabled', true).removeAttr('checked'); jQuery("#value_choice").hide();jQuery("#helpchkbxlst").hide(); }
95  else if (type == 'varchar') { size.removeAttr('disabled'); unique.removeAttr('disabled'); jQuery("#value_choice").hide();jQuery("#helpchkbxlst").hide(); }
96  else if (type == 'password') { size.val('').prop('disabled', true); unique.removeAttr('checked').prop('disabled', true); required.val('').prop('disabled', true); default_value.val('').prop('disabled', true); jQuery("#value_choice").show(); jQuery(".spanforparamtooltip").hide(); jQuery("#helppassword").show();}
97  else if (type == 'boolean') { size.val('').prop('disabled', true); unique.removeAttr('checked').prop('disabled', true); jQuery("#value_choice").hide(); jQuery("#helpchkbxlst").hide();}
98  else if (type == 'price') { size.val('').prop('disabled', true); unique.removeAttr('checked').prop('disabled', true); jQuery("#value_choice").hide(); jQuery("#helpchkbxlst").hide();}
99  else if (type == 'pricecy') { size.val('').prop('disabled', true); unique.removeAttr('checked').prop('disabled', true); jQuery("#value_choice").hide(); jQuery("#helpchkbxlst").hide();}
100  else if (type == 'select') { size.val('').prop('disabled', true); unique.removeAttr('checked').prop('disabled', true); jQuery("#value_choice").show(); jQuery(".spanforparamtooltip").hide(); jQuery("#helpselect").show();}
101  else if (type == 'sellist') { size.val('').prop('disabled', true); unique.removeAttr('checked').prop('disabled', true); jQuery("#value_choice").show(); jQuery(".spanforparamtooltip").hide(); jQuery("#helpsellist").show();}
102  else if (type == 'radio') { size.val('').prop('disabled', true); unique.removeAttr('checked').prop('disabled', true); jQuery("#value_choice").show(); jQuery(".spanforparamtooltip").hide(); jQuery("#helpselect").show();}
103  else if (type == 'checkbox') { size.val('').prop('disabled', true); unique.removeAttr('checked').prop('disabled', true); jQuery("#value_choice").show(); jQuery(".spanforparamtooltip").hide(); jQuery("#helpselect").show();}
104  else if (type == 'chkbxlst') { size.val('').prop('disabled', true); unique.removeAttr('checked').prop('disabled', true); jQuery("#value_choice").show(); jQuery(".spanforparamtooltip").hide(); jQuery("#helpchkbxlst").show();}
105  else if (type == 'link') { size.val('').prop('disabled', true); unique.removeAttr('disabled'); jQuery("#value_choice").show(); jQuery(".spanforparamtooltip").hide(); jQuery("#helplink").show();}
106  else if (type == 'separate') {
107  size.val('').prop('disabled', true); unique.removeAttr('checked').prop('disabled', true); required.val('').prop('disabled', true); default_value.val('').prop('disabled', true);
108  jQuery("#value_choice").show();
109  jQuery(".spanforparamtooltip").hide(); jQuery("#helpseparate").show();
110  }
111  else { // type = string
112  size.val('').prop('disabled', true);
113  unique.removeAttr('disabled');
114  }
115 
116  if (type == 'separate')
117  {
118  required.removeAttr('checked').prop('disabled', true); alwayseditable.removeAttr('checked').prop('disabled', true); list.removeAttr('checked').prop('disabled', true);
119  jQuery('#size, #default_value, #langfile').val('').prop('disabled', true);
120  jQuery('#list').val(3); // visible on create/update/view form only
121  }
122  else
123  {
124  default_value.removeAttr('disabled');
125  required.removeAttr('disabled'); alwayseditable.removeAttr('disabled'); list.removeAttr('disabled');
126  }
127  }
128  init_typeoffields(jQuery("#type").val());
129  jQuery("#type").change(function() {
130  init_typeoffields($(this).val());
131  });
132 
133  // If we enter a formula, we disable other fields
134  jQuery("#computed_value").keyup(function() {
135  init_typeoffields(jQuery('#type').val());
136  });
137  });
138 </script>
139 
140 <!-- Form to edit an extra field -->
141 <form action="<?php echo $_SERVER["PHP_SELF"]; ?>?attrname=<?php echo $attrname; ?>" id="formeditextrafield" method="post">
142 <input type="hidden" name="token" value="<?php echo newToken(); ?>">
143 <input type="hidden" name="attrname" value="<?php echo $attrname; ?>">
144 <input type="hidden" name="action" value="update">
145 <input type="hidden" name="rowid" value="<?php echo (empty($rowid) ? '' : $rowid) ?>">
146 <input type="hidden" name="enabled" value="<?php echo dol_escape_htmltag($extrafields->attributes[$elementtype]['enabled'][$attrname]); ?>">
147 
148 <?php print dol_get_fiche_head(); ?>
149 
150 <table summary="listofattributes" class="border centpercent">
151 
152 <?php
153 $label = $extrafields->attributes[$elementtype]['label'][$attrname];
154 $type = $extrafields->attributes[$elementtype]['type'][$attrname];
155 $size = $extrafields->attributes[$elementtype]['size'][$attrname];
156 $computed = $extrafields->attributes[$elementtype]['computed'][$attrname];
157 $default = $extrafields->attributes[$elementtype]['default'][$attrname];
158 $unique = $extrafields->attributes[$elementtype]['unique'][$attrname];
159 $required = $extrafields->attributes[$elementtype]['required'][$attrname];
160 $pos = $extrafields->attributes[$elementtype]['pos'][$attrname];
161 $alwayseditable = $extrafields->attributes[$elementtype]['alwayseditable'][$attrname];
162 $param = $extrafields->attributes[$elementtype]['param'][$attrname];
163 $perms = $extrafields->attributes[$elementtype]['perms'][$attrname];
164 $langfile = $extrafields->attributes[$elementtype]['langfile'][$attrname];
165 $list = $extrafields->attributes[$elementtype]['list'][$attrname];
166 $totalizable = $extrafields->attributes[$elementtype]['totalizable'][$attrname];
167 $help = $extrafields->attributes[$elementtype]['help'][$attrname];
168 $entitycurrentorall = $extrafields->attributes[$elementtype]['entityid'][$attrname];
169 $printable = $extrafields->attributes[$elementtype]['printable'][$attrname];
170 $enabled = $extrafields->attributes[$elementtype]['enabled'][$attrname];
171 $css = $extrafields->attributes[$elementtype]['css'][$attrname];
172 $cssview = $extrafields->attributes[$elementtype]['cssview'][$attrname];
173 $csslist = $extrafields->attributes[$elementtype]['csslist'][$attrname];
174 
175 $param_chain = '';
176 if (is_array($param)) {
177  if (($type == 'select') || ($type == 'checkbox') || ($type == 'radio')) {
178  foreach ($param['options'] as $key => $value) {
179  if (strlen($key)) {
180  $param_chain .= $key.','.$value."\n";
181  }
182  }
183  } elseif (($type == 'sellist') || ($type == 'chkbxlst') || ($type == 'link') || ($type == 'password') || ($type == 'separate')) {
184  $paramlist = array_keys($param['options']);
185  $param_chain = $paramlist[0];
186  }
187 }
188 ?>
189 <!-- Label -->
190 <tr><td class="titlefieldcreate fieldrequired"><?php echo $langs->trans("LabelOrTranslationKey"); ?></td><td class="valeur"><input type="text" name="label" size="40" value="<?php echo $label; ?>"></td></tr>
191 
192 <!-- Code -->
193 <tr><td class="fieldrequired"><?php echo $langs->trans("AttributeCode"); ?></td><td class="valeur"><?php echo $attrname; ?></td></tr>
194 
195 <!-- Type -->
196 <tr><td class="fieldrequired"><?php echo $langs->trans("Type"); ?></td><td class="valeur">
197 <?php
198 // Define list of possible type transition
199 $typewecanchangeinto = array(
200  'varchar'=>array('varchar', 'phone', 'mail', 'url', 'ip', 'select', 'password', 'text', 'html'),
201  'double'=>array('double', 'price'),
202  'price'=>array('double', 'price'),
203  'text'=>array('text', 'html'),
204  'html'=>array('text', 'html'),
205  'password'=>array('password', 'varchar'),
206  'mail'=>array('varchar', 'phone', 'mail', 'url', 'ip', 'select'),
207  'url'=>array('varchar', 'phone', 'mail', 'url', 'ip', 'select'),
208  'phone'=>array('varchar', 'phone', 'mail', 'url', 'ip', 'select'),
209  'ip'=>array('varchar', 'phone', 'mail', 'url', 'ip', 'select'),
210  'select'=>array('varchar', 'phone', 'mail', 'url', 'ip', 'select'),
211  'date'=>array('date', 'datetime')
212 );
213 /* Disabled because text is text on several lines, when varchar is text on 1 line, we should not be able to convert
214 if ($size <= 255 && in_array($type, array('text', 'html'))) {
215  $typewecanchangeinto['text'][] = 'varchar';
216 }*/
217 
218 if (in_array($type, array_keys($typewecanchangeinto))) {
219  $newarray = array();
220  print '<select id="type" class="flat type" name="type">';
221  foreach ($type2label as $key => $val) {
222  $selected = '';
223  if ($key == (GETPOST('type', 'alpha') ?GETPOST('type', 'alpha') : $type)) {
224  $selected = ' selected="selected"';
225  }
226  if (in_array($key, $typewecanchangeinto[$type])) {
227  print '<option value="'.$key.'"'.$selected.'>'.$val.'</option>';
228  } else {
229  print '<option value="'.$key.'" disabled="disabled"'.$selected.'>'.$val.'</option>';
230  }
231  }
232  print '</select>';
233  print ajax_combobox('type');
234 } else {
235  print $type2label[$type];
236  print '<input type="hidden" name="type" id="type" value="'.$type.'">';
237 }
238 ?>
239 </td></tr>
240 
241 <!-- Size -->
242 <tr class="extra_size"><td class="fieldrequired"><?php echo $langs->trans("Size"); ?></td><td><input id="size" type="text" name="size" size="5" value="<?php echo $size; ?>"></td></tr>
243 
244 <!-- Value (for some fields like password, select list, radio, ...) -->
245 <tr id="value_choice">
246 <td>
247  <?php echo $langs->trans("Value"); ?>
248 </td>
249 <td>
250  <table class="nobordernopadding">
251  <tr><td>
252  <textarea name="param" id="param" cols="80" rows="<?php echo ROWS_4 ?>"><?php echo dol_htmlcleanlastbr($param_chain); ?></textarea>
253  </td><td>
254  <span id="helpselect" class="spanforparamtooltip"><?php print $form->textwithpicto('', $langs->trans("ExtrafieldParamHelpselect"), 1, 0, '', 0, 2, 'helpvalue1')?></span>
255  <span id="helpsellist" class="spanforparamtooltip"><?php print $form->textwithpicto('', $langs->trans("ExtrafieldParamHelpsellist"), 1, 0, '', 0, 2, 'helpvalue2')?></span>
256  <span id="helpchkbxlst" class="spanforparamtooltip"><?php print $form->textwithpicto('', $langs->trans("ExtrafieldParamHelpchkbxlst"), 1, 0, '', 0, 2, 'helpvalue3')?></span>
257  <span id="helplink" class="spanforparamtooltip"><?php print $form->textwithpicto('', $langs->trans("ExtrafieldParamHelplink").'<br><br>'.$langs->trans("Examples").':<br>'.$listofexamplesforlink, 1, 0, '', 0, 2, 'helpvalue4')?></span>
258  <span id="helppassword" class="spanforparamtooltip"><?php print $form->textwithpicto('', $langs->trans("ExtrafieldParamHelpPassword"), 1, 0, '', 0, 2, 'helpvalue5')?></span>
259  <span id="helpseparate" class="spanforparamtooltip"><?php print $form->textwithpicto('', $langs->trans("ExtrafieldParamHelpSeparator"), 1, 0, '', 0, 2, 'helpvalue6')?></span>
260  </td></tr>
261  </table>
262 </td>
263 </tr>
264 
265 <!-- Position -->
266 <tr><td class="titlefield"><?php echo $langs->trans("Position"); ?></td><td class="valeur"><input type="text" name="pos" size="5" value="<?php echo dol_escape_htmltag($pos); ?>"></td></tr>
267 
268 <!-- Language file -->
269 <tr><td class="titlefield"><?php echo $langs->trans("LanguageFile"); ?></td><td class="valeur"><input type="text" name="langfile" class="minwidth200" value="<?php echo dol_escape_htmltag($langfile); ?>"></td></tr>
270 
271 <!-- Computed value -->
272 <tr class="extra_computed_value">
273 <?php if (empty($conf->global->MAIN_STORE_COMPUTED_EXTRAFIELDS)) { ?>
274  <td><?php echo $form->textwithpicto($langs->trans("ComputedFormula"), $langs->trans("ComputedFormulaDesc"), 1, 'help', '', 0, 2, 'tooltipcompute'); ?></td>
275 <?php } else { ?>
276  <td><?php echo $form->textwithpicto($langs->trans("ComputedFormula"), $langs->trans("ComputedFormulaDesc")).$form->textwithpicto($langs->trans("Computedpersistent"), $langs->trans("ComputedpersistentDesc"), 1, 'warning'); ?></td>
277 <?php } ?>
278 <td class="valeur"><textarea name="computed_value" id="computed_value" class="quatrevingtpercent" rows="<?php echo ROWS_4 ?>"><?php echo dol_htmlcleanlastbr($computed); ?></textarea></td>
279 </tr>
280 
281 <!-- Default Value (at sql setup level) -->
282 <tr class="extra_default_value"><td><?php echo $langs->trans("DefaultValue").' ('.$langs->trans("Database").')'; ?></td><td class="valeur"><input id="default_value" type="text" name="default_value" size="5" value="<?php echo dol_escape_htmltag($default); ?>"></td></tr>
283 
284 <!-- Unique -->
285 <tr class="extra_unique"><td><?php echo $langs->trans("Unique"); ?></td><td class="valeur"><input id="unique" type="checkbox" name="unique"<?php echo ($unique ? ' checked' : ''); ?>></td></tr>
286 
287 <!-- Required -->
288 <tr class="extra_required"><td><?php echo $langs->trans("Mandatory"); ?></td><td class="valeur"><input id="required" type="checkbox" name="required"<?php echo ($required ? ' checked' : ''); ?>></td></tr>
289 
290 <!-- Always editable -->
291 <tr class="extra_alwayseditable"><td><?php echo $form->textwithpicto($langs->trans("AlwaysEditable"), $langs->trans("EditableWhenDraftOnly")); ?></td><td class="valeur"><input id="alwayseditable" type="checkbox" name="alwayseditable"<?php echo ($alwayseditable ? ' checked' : ''); ?>></td></tr>
292 
293 <!-- Visibility -->
294 <tr><td class="extra_list"><?php echo $form->textwithpicto($langs->trans("Visibility"), $langs->trans("VisibleDesc").'<br><br>'.$langs->trans("ItCanBeAnExpression")); ?>
295 </td><td class="valeur"><input id="list" class="minwidth100" type="text" name="list" value="<?php echo ($list != '' ? $list : '1'); ?>"></td></tr>
296 
297 <!-- Visibility for PDF-->
298 <tr><td class="extra_pdf"><?php echo $form->textwithpicto($langs->trans("DisplayOnPdf"), $langs->trans("DisplayOnPdfDesc")); ?>
299 </td><td class="valeur"><input id="printable" class="minwidth100" type="text" name="printable" value="<?php echo dol_escape_htmltag($printable); ?>"></td></tr>
300 
301 <!-- Can be summed -->
302 <tr class="extra_totalizable"><td><?php echo $form->textwithpicto($langs->trans("Totalizable"), $langs->trans("TotalizableDesc")); ?></td><td class="valeur"><input id="totalizable" type="checkbox" name="totalizable"<?php echo ($totalizable ? ' checked' : ''); ?>></td></tr>
303 
304 <!-- Css edit -->
305 <tr class="extra_css"><td><?php echo $form->textwithpicto($langs->trans("CssOnEdit"), $langs->trans("HelpCssOnEditDesc")); ?></td><td class="valeur"><input id="css" type="text" name="css" value="<?php echo $css ?>"></td></tr>
306 
307 <!-- Css view -->
308 <tr class="extra_cssview"><td><?php echo $form->textwithpicto($langs->trans("CssOnView"), $langs->trans("HelpCssOnViewDesc")); ?></td><td class="valeur"><input id="cssview" type="text" name="cssview" value="<?php echo $cssview; ?>"></td></tr>
309 
310 <!-- Css list -->
311 <tr class="extra_csslist"><td><?php echo $form->textwithpicto($langs->trans("CssOnList"), $langs->trans("HelpCssOnListDesc")); ?></td><td class="valeur"><input id="csslist" type="text" name="csslist" value="<?php echo $csslist; ?>"></td></tr>
312 
313 <!-- Help tooltip -->
314 <tr class="help"><td><?php echo $form->textwithpicto($langs->trans("HelpOnTooltip"), $langs->trans("HelpOnTooltipDesc")); ?></td><td class="valeur"><input id="help" class="quatrevingtpercent" type="text" name="help" value="<?php echo dol_escape_htmltag($help); ?>"></td></tr>
315 
316 <?php if (isModEnabled('multicompany')) { ?>
317  <!-- Multicompany entity -->
318  <tr><td><?php echo $langs->trans("AllEntities"); ?></td><td class="valeur"><input id="entitycurrentorall" type="checkbox" name="entitycurrentorall"<?php echo (empty($entitycurrentorall) ? ' checked' : ''); ?>></td></tr>
319 <?php } ?>
320 
321 <!-- Show Enabled property when value is not a common value -->
322 <?php if ($enabled != '1') { ?>
323  <tr class="help"><td><?php echo $langs->trans("EnabledCondition"); ?></td><td class="valeur">
324  <?php echo dol_escape_htmltag($enabled); ?>
325 <?php } ?>
326 </td></tr>
327 
328 </table>
329 
330 <?php print dol_get_fiche_end(); ?>
331 
332 <div class="center"><input type="submit" name="button" class="button button-save" value="<?php echo $langs->trans("Save"); ?>">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
333 <input type="submit" name="button" class="button button-cancel" value="<?php echo $langs->trans("Cancel"); ?>"></div>
334 
335 </form>
336 
337 <!-- END PHP TEMPLATE admin_extrafields_edit.tpl.php -->
ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete='resolve', $idforemptyvalue='-1', $morecss='')
Convert a html select field into an ajax combobox.
Definition: ajax.lib.php:449
Class to manage generation of HTML components Only common components must be here.
Class for Position.
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
dol_htmlcleanlastbr($stringtodecode)
This function remove all ending and br at end.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
isModEnabled($module)
Is Dolibarr module enabled.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition: repair.php:120
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition: repair.php:123