dolibarr  9.0.0
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 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 <http://www.gnu.org/licenses/>.
18  */
19 
29 // Protection to avoid direct call of template
30 if (empty($conf) || ! is_object($conf))
31 {
32  print "Error, template page can't be called as URL";
33  exit;
34 }
35 
36 
37 $langs->load("modulebuilder");
38 
39 ?>
40 
41 <!-- BEGIN PHP TEMPLATE admin_extrafields_edit.tpl.php -->
42 <script type="text/javascript">
43  jQuery(document).ready(function() {
44  function init_typeoffields(type)
45  {
46  console.log("select new type "+type);
47  var size = jQuery("#size");
48  var computed_value = jQuery("#computed_value");
49  var langfile = jQuery("#langfile");
50  var default_value = jQuery("#default_value");
51  var unique = jQuery("#unique");
52  var required = jQuery("#required");
53  var alwayseditable = jQuery("#alwayseditable");
54  var list = jQuery("#list");
55  var totalizable = jQuery("#totalizable");
56  <?php
57  if((GETPOST('type','alpha') != "select") && (GETPOST('type','alpha') != "sellist"))
58  {
59  print 'jQuery("#value_choice").hide();';
60  }
61 
62  if (GETPOST('type','alpha') == "separate")
63  {
64  print "jQuery('#size, #default_value, #langfile').val('').prop('disabled', true);";
65  print 'jQuery("#value_choice").hide();';
66  }
67  ?>
68 
69  // Case of computed field
70  if (type == 'varchar' || type == 'int' || type == 'double' || type == 'price') {
71  jQuery("tr.extra_computed_value").show();
72  } else {
73  computed_value.val(''); jQuery("tr.extra_computed_value").hide();
74  }
75  if (computed_value.val())
76  {
77  console.log("We enter a computed formula");
78  jQuery("#default_value").val('');
79  /* jQuery("#unique, #required, #alwayseditable, #list").removeAttr('checked'); */
80  jQuery("#default_value, #unique, #required, #alwayseditable, #list").attr('disabled', true);
81  jQuery("tr.extra_default_value, tr.extra_unique, tr.extra_required, tr.extra_alwayseditable, tr.extra_list").hide();
82  }
83  else
84  {
85  console.log("No computed formula");
86  jQuery("#default_value, #unique, #required, #alwayseditable, #list").attr('disabled', false);
87  jQuery("tr.extra_default_value, tr.extra_unique, tr.extra_required, tr.extra_alwayseditable, tr.extra_list").show();
88  }
89 
90  if (type == 'date') { size.val('').prop('disabled', true); unique.removeAttr('disabled'); jQuery("#value_choice").hide();jQuery("#helpchkbxlst").hide(); }
91  else if (type == 'datetime') { size.val('').prop('disabled', true); unique.removeAttr('disabled'); jQuery("#value_choice").hide(); jQuery("#helpchkbxlst").hide();}
92  else if (type == 'double') { size.removeAttr('disabled'); unique.removeAttr('disabled'); jQuery("#value_choice").hide(); jQuery("#helpchkbxlst").hide();}
93  else if (type == 'int') { size.removeAttr('disabled'); unique.removeAttr('disabled'); jQuery("#value_choice").hide(); jQuery("#helpchkbxlst").hide();}
94  else if (type == 'text') { size.removeAttr('disabled'); unique.prop('disabled', true).removeAttr('checked'); jQuery("#value_choice").hide();jQuery("#helpchkbxlst").hide(); }
95  else if (type == 'html') { size.removeAttr('disabled'); unique.prop('disabled', true).removeAttr('checked'); jQuery("#value_choice").hide();jQuery("#helpchkbxlst").hide(); }
96  else if (type == 'varchar') { size.removeAttr('disabled'); unique.removeAttr('disabled'); jQuery("#value_choice").hide();jQuery("#helpchkbxlst").hide(); }
97  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("#helpselect").hide();jQuery("#helpsellist").hide();jQuery("#helpchkbxlst").hide();jQuery("#helplink").hide();jQuery("#helppassword").show();}
98  else if (type == 'boolean') { size.val('').prop('disabled', true); unique.removeAttr('checked').prop('disabled', true); jQuery("#value_choice").hide();jQuery("#helpchkbxlst").hide();}
99  else if (type == 'price') { 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("#helpselect").show();jQuery("#helpsellist").hide();jQuery("#helpchkbxlst").hide();jQuery("#helplink").hide();jQuery("#helppassword").hide();}
101  else if (type == 'sellist') { size.val('').prop('disabled', true); unique.removeAttr('checked').prop('disabled', true); jQuery("#value_choice").show();jQuery("#helpselect").hide();jQuery("#helpsellist").show();jQuery("#helpchkbxlst").hide();jQuery("#helplink").hide();jQuery("#helppassword").hide();}
102  else if (type == 'radio') { size.val('').prop('disabled', true); unique.removeAttr('checked').prop('disabled', true); jQuery("#value_choice").show();jQuery("#helpselect").show();jQuery("#helpsellist").hide();jQuery("#helpchkbxlst").hide();jQuery("#helplink").hide();jQuery("#helppassword").hide();}
103  else if (type == 'checkbox') { size.val('').prop('disabled', true); unique.removeAttr('checked').prop('disabled', true); jQuery("#value_choice").show();jQuery("#helpselect").show();jQuery("#helpsellist").hide();jQuery("#helpchkbxlst").hide();jQuery("#helplink").hide();jQuery("#helppassword").hide();}
104  else if (type == 'chkbxlst') { size.val('').prop('disabled', true); unique.removeAttr('checked').prop('disabled', true); jQuery("#value_choice").show();jQuery("#helpselect").hide();jQuery("#helpsellist").hide();jQuery("#helpchkbxlst").show();jQuery("#helplink").hide();jQuery("#helppassword").hide();}
105  else if (type == 'link') { size.val('').prop('disabled', true); unique.removeAttr('disabled'); jQuery("#value_choice").show();jQuery("#helpselect").hide();jQuery("#helpsellist").hide();jQuery("#helpchkbxlst").hide();jQuery("#helplink").show();jQuery("#helppassword").hide();}
106  else if (type == 'separate') { 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").hide();jQuery("#helpselect").hide();jQuery("#helpsellist").hide();jQuery("#helpchkbxlst").hide();jQuery("#helplink").hide();jQuery("#helppassword").hide();}
107  else { // type = string
108  size.val('').prop('disabled', true);
109  unique.removeAttr('disabled');
110  }
111 
112  if (type == 'separate')
113  {
114  required.removeAttr('checked').prop('disabled', true); alwayseditable.removeAttr('checked').prop('disabled', true); list.removeAttr('checked').prop('disabled', true);
115  jQuery('#size, #default_value, #langfile').val('').prop('disabled', true);
116  jQuery('#list').val(3); // visible on create/update/view form only
117  }
118  else
119  {
120  default_value.removeAttr('disabled');
121  required.removeAttr('disabled'); alwayseditable.removeAttr('disabled'); list.removeAttr('disabled');
122  }
123  }
124  init_typeoffields(jQuery("#type").val());
125  jQuery("#type").change(function() {
126  init_typeoffields($(this).val());
127  });
128 
129  // If we enter a formula, we disable other fields
130  jQuery("#computed_value").keyup(function() {
131  init_typeoffields(jQuery('#type').val());
132  });
133  });
134 </script>
135 
136 <!-- Form to edit an extra field -->
137 <form action="<?php echo $_SERVER["PHP_SELF"]; ?>?attrname=<?php echo $attrname; ?>" id="formeditextrafield" method="post">
138 <input type="hidden" name="token" value="<?php echo $_SESSION['newtoken']; ?>">
139 <input type="hidden" name="attrname" value="<?php echo $attrname; ?>">
140 <input type="hidden" name="action" value="update">
141 <input type="hidden" name="rowid" value="<?php echo $rowid ?>">
142 
143 <?php dol_fiche_head(); ?>
144 
145 <table summary="listofattributes" class="border centpercent">
146 
147 <?php
148 $label=$extrafields->attributes[$elementtype]['label'][$attrname];
149 $type=$extrafields->attributes[$elementtype]['type'][$attrname];
150 $size=$extrafields->attributes[$elementtype]['size'][$attrname];
151 $computed=$extrafields->attributes[$elementtype]['computed'][$attrname];
152 $default=$extrafields->attributes[$elementtype]['default'][$attrname];
153 $unique=$extrafields->attributes[$elementtype]['unique'][$attrname];
154 $required=$extrafields->attributes[$elementtype]['required'][$attrname];
155 $pos=$extrafields->attributes[$elementtype]['pos'][$attrname];
156 $alwayseditable=$extrafields->attributes[$elementtype]['alwayseditable'][$attrname];
157 $param=$extrafields->attributes[$elementtype]['param'][$attrname];
158 $perms=$extrafields->attributes[$elementtype]['perms'][$attrname];
159 $langfile=$extrafields->attributes[$elementtype]['langfile'][$attrname];
160 $list=$extrafields->attributes[$elementtype]['list'][$attrname];
161 $totalizable = $extrafields->attributes[$elementtype]['totalizable'][$attrname];
162 $help=$extrafields->attributes[$elementtype]['help'][$attrname];
163 $entitycurrentorall=$extrafields->attributes[$elementtype]['entityid'][$attrname];
164 
165 if((($type == 'select') || ($type == 'checkbox') || ($type == 'radio')) && is_array($param))
166 {
167  $param_chain = '';
168  foreach ($param['options'] as $key => $value)
169  {
170  if(strlen($key))
171  {
172  $param_chain .= $key.','.$value."\n";
173  }
174  }
175 }
176 elseif (($type== 'sellist') || ($type == 'chkbxlst') || ($type == 'link') || ($type == 'password'))
177 {
178  $paramlist=array_keys($param['options']);
179  $param_chain = $paramlist[0];
180 }
181 ?>
182 <!-- Label -->
183 <tr><td class="titlefield fieldrequired"><?php echo $langs->trans("LabelOrTranslationKey"); ?></td><td class="valeur"><input type="text" name="label" size="40" value="<?php echo $label; ?>"></td></tr>
184 <!-- Code -->
185 <tr><td class="fieldrequired"><?php echo $langs->trans("AttributeCode"); ?></td><td class="valeur"><?php echo $attrname; ?></td></tr>
186 <!-- Type -->
187 <tr><td class="fieldrequired"><?php echo $langs->trans("Type"); ?></td><td class="valeur">
188 <?php
189 // Define list of possible type transition
190 $typewecanchangeinto=array(
191  'varchar'=>array('varchar', 'phone', 'mail', 'url', 'select', 'password', 'text', 'html'),
192  'text'=>array('text','html'),
193  'html'=>array('text','html'),
194  'password'=>array('password', 'varchar'),
195  'mail'=>array('varchar', 'phone', 'mail', 'url', 'select'),
196  'url'=>array('varchar', 'phone', 'mail', 'url', 'select'),
197  'phone'=>array('varchar', 'phone', 'mail', 'url', 'select'),
198  'select'=>array('varchar', 'phone', 'mail', 'url', 'select')
199 );
200 if (in_array($type, array_keys($typewecanchangeinto)))
201 {
202  $newarray=array();
203  print '<select id="type" class="flat type" name="type">';
204  foreach($type2label as $key => $val)
205  {
206  $selected='';
207  if ($key == (GETPOST('type','alpha')?GETPOST('type','alpha'):$type)) $selected=' selected="selected"';
208  if (in_array($key, $typewecanchangeinto[$type])) print '<option value="'.$key.'"'.$selected.'>'.$val.'</option>';
209  else print '<option value="'.$key.'" disabled="disabled"'.$selected.'>'.$val.'</option>';
210  }
211  print '</select>';
212 }
213 else
214 {
215  print $type2label[$type];
216  print '<input type="hidden" name="type" id="type" value="'.$type.'">';
217 }
218 ?>
219 </td></tr>
220 <!-- Size -->
221 <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>
222 <!-- Value (for some fields like password, select list, radio, ...) -->
223 <tr id="value_choice">
224 <td>
225  <?php echo $langs->trans("Value"); ?>
226 </td>
227 <td>
228  <table class="nobordernopadding">
229  <tr><td>
230  <textarea name="param" id="param" cols="80" rows="<?php echo ROWS_4 ?>"><?php echo dol_htmlcleanlastbr($param_chain); ?></textarea>
231  </td><td>
232  <span id="helpselect"><?php print $form->textwithpicto('', $langs->trans("ExtrafieldParamHelpselect"),1,0,'', 0, 2, 'helpvalue1')?></span>
233  <span id="helpsellist"><?php print $form->textwithpicto('', $langs->trans("ExtrafieldParamHelpsellist"),1,0,'', 0, 2, 'helpvalue2')?></span>
234  <span id="helpchkbxlst"><?php print $form->textwithpicto('', $langs->trans("ExtrafieldParamHelpchkbxlst"),1,0,'', 0, 2, 'helpvalue3')?></span>
235  <span id="helplink"><?php print $form->textwithpicto('', $langs->trans("ExtrafieldParamHelplink"),1,0,'', 0, 2, 'helpvalue4')?></span>
236  <span id="helppassword"><?php print $form->textwithpicto('', $langs->trans("ExtrafieldParamHelpPassword"),1,0,'', 0, 2, 'helpvalue5')?></span>
237  </td></tr>
238  </table>
239 </td>
240 </tr>
241 <!-- Position -->
242 <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>
243 <!-- Language file -->
244 <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>
245 <!-- Computed value -->
246 <tr class="extra_computed_value"><td><?php echo $form->textwithpicto($langs->trans("ComputedFormula"), $langs->trans("ComputedFormulaDesc"), 1, 'help', '', 0, 2, 'tooltipcompute'); ?></td><td class="valeur"><input id="computed_value" class="quatrevingtpercent" type="text" name="computed_value" value="<?php echo dol_escape_htmltag($computed); ?>"></td></tr>
247 <!-- Default Value (at sql setup level) -->
248 <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>
249 <!-- Unique -->
250 <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>
251 <!-- Required -->
252 <tr class="extra_required"><td><?php echo $langs->trans("Required"); ?></td><td class="valeur"><input id="required" type="checkbox" name="required"<?php echo ($required?' checked':''); ?>></td></tr>
253 <!-- Always editable -->
254 <tr class="extra_alwayseditable"><td><?php echo $langs->trans("AlwaysEditable"); ?></td><td class="valeur"><input id="alwayseditable" type="checkbox" name="alwayseditable"<?php echo ($alwayseditable?' checked':''); ?>></td></tr>
255 <tr><td class="extra_list"><?php echo $form->textwithpicto($langs->trans("Visibility"), $langs->trans("VisibleDesc")); ?>
256 </td><td class="valeur"><input id="list" class="minwidth100" type="text" name="list" value="<?php echo ($list!=''?$list:'1'); ?>"></td></tr>
257 <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>
258 <!-- Help tooltip -->
259 <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>
260 <?php if ($conf->multicompany->enabled) { ?>
261  <!-- Multicompany entity -->
262  <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>
263 <?php } ?>
264 <!-- Visibility -->
265 </table>
266 
267 <?php dol_fiche_end(); ?>
268 
269 <div align="center"><input type="submit" name="button" class="button" value="<?php echo $langs->trans("Save"); ?>">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
270 <input type="submit" name="button" class="button" value="<?php echo $langs->trans("Cancel"); ?>"></div>
271 
272 </form>
273 
274 <!-- END PHP TEMPLATE admin_extrafields_edit.tpl.php -->
GETPOST($paramname, $check='none', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
print
Draft customers invoices.
Definition: index.php:91
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition: repair.php:103
Class to manage generation of HTML components Only common components must be here.
type
Definition: viewcat.php:284
dol_fiche_end($notab=0)
Show tab footer of a card.
dol_htmlcleanlastbr($stringtodecode)
This function remove all ending and br at end.
dol_fiche_head($links=array(), $active='0', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='')
Show tab header of a card.