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