admin_extrafields_edit.tpl.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  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. /**
  20. * The following vars must be defined:
  21. * $type2label
  22. * $form
  23. * $conf, $lang,
  24. * The following vars may also be defined:
  25. * $elementtype
  26. */
  27. // Protection to avoid direct call of template
  28. if (empty($conf) || !is_object($conf)) {
  29. print "Error, template page can't be called as URL";
  30. exit;
  31. }
  32. $langs->load("modulebuilder");
  33. $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>...';
  34. ?>
  35. <!-- BEGIN PHP TEMPLATE admin_extrafields_edit.tpl.php -->
  36. <script>
  37. jQuery(document).ready(function() {
  38. function init_typeoffields(type)
  39. {
  40. console.log("select a new type (edit) = "+type);
  41. var size = jQuery("#size");
  42. var computed_value = jQuery("#computed_value");
  43. var langfile = jQuery("#langfile");
  44. var default_value = jQuery("#default_value");
  45. var unique = jQuery("#unique");
  46. var required = jQuery("#required");
  47. var alwayseditable = jQuery("#alwayseditable");
  48. var list = jQuery("#list");
  49. var totalizable = jQuery("#totalizable");
  50. <?php
  51. if ((GETPOST('type', 'alpha') != "select") && (GETPOST('type', 'alpha') != "sellist")) {
  52. print 'jQuery("#value_choice").hide();';
  53. }
  54. if (GETPOST('type', 'alpha') == "separate") {
  55. print "jQuery('#size, #default_value, #langfile').val('').prop('disabled', true);";
  56. print 'jQuery("#value_choice").hide();';
  57. }
  58. ?>
  59. // Case of computed field
  60. if (type == 'varchar' || type == 'int' || type == 'double' || type == 'price') {
  61. jQuery("tr.extra_computed_value").show();
  62. } else {
  63. computed_value.val(''); jQuery("tr.extra_computed_value").hide();
  64. }
  65. if (computed_value.val())
  66. {
  67. console.log("We enter a computed formula");
  68. jQuery("#default_value").val('');
  69. /* jQuery("#unique, #required, #alwayseditable, #list").removeAttr('checked'); */
  70. jQuery("#default_value, #unique, #required, #alwayseditable, #list").attr('disabled', true);
  71. jQuery("tr.extra_default_value, tr.extra_unique, tr.extra_required, tr.extra_alwayseditable, tr.extra_list").hide();
  72. }
  73. else
  74. {
  75. console.log("No computed formula");
  76. jQuery("#default_value, #unique, #required, #alwayseditable, #list").attr('disabled', false);
  77. jQuery("tr.extra_default_value, tr.extra_unique, tr.extra_required, tr.extra_alwayseditable, tr.extra_list").show();
  78. }
  79. if (type == 'date') { size.val('').prop('disabled', true); unique.removeAttr('disabled'); jQuery("#value_choice").hide();jQuery("#helpchkbxlst").hide(); }
  80. else if (type == 'datetime') { size.val('').prop('disabled', true); unique.removeAttr('disabled'); jQuery("#value_choice").hide(); jQuery("#helpchkbxlst").hide();}
  81. else if (type == 'double') { size.removeAttr('disabled'); unique.removeAttr('disabled'); jQuery("#value_choice").hide(); jQuery("#helpchkbxlst").hide();}
  82. else if (type == 'int') { size.removeAttr('disabled'); unique.removeAttr('disabled'); jQuery("#value_choice").hide(); jQuery("#helpchkbxlst").hide();}
  83. else if (type == 'text') { size.removeAttr('disabled'); unique.prop('disabled', true).removeAttr('checked'); jQuery("#value_choice").hide();jQuery("#helpchkbxlst").hide(); }
  84. else if (type == 'html') { size.removeAttr('disabled'); unique.prop('disabled', true).removeAttr('checked'); jQuery("#value_choice").hide();jQuery("#helpchkbxlst").hide(); }
  85. else if (type == 'varchar') { size.removeAttr('disabled'); unique.removeAttr('disabled'); jQuery("#value_choice").hide();jQuery("#helpchkbxlst").hide(); }
  86. 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();}
  87. else if (type == 'boolean') { size.val('').prop('disabled', true); unique.removeAttr('checked').prop('disabled', true); jQuery("#value_choice").hide(); jQuery("#helpchkbxlst").hide();}
  88. else if (type == 'price') { size.val('').prop('disabled', true); unique.removeAttr('checked').prop('disabled', true); jQuery("#value_choice").hide(); jQuery("#helpchkbxlst").hide();}
  89. else if (type == 'pricecy') { size.val('').prop('disabled', true); unique.removeAttr('checked').prop('disabled', true); jQuery("#value_choice").hide(); jQuery("#helpchkbxlst").hide();}
  90. 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();}
  91. 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();}
  92. 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();}
  93. 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();}
  94. 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();}
  95. else if (type == 'link') { size.val('').prop('disabled', true); unique.removeAttr('disabled'); jQuery("#value_choice").show(); jQuery(".spanforparamtooltip").hide(); jQuery("#helplink").show();}
  96. else if (type == 'separate') {
  97. size.val('').prop('disabled', true); unique.removeAttr('checked').prop('disabled', true); required.val('').prop('disabled', true); default_value.val('').prop('disabled', true);
  98. jQuery("#value_choice").show();
  99. jQuery(".spanforparamtooltip").hide(); jQuery("#helpseparate").show();
  100. }
  101. else { // type = string
  102. size.val('').prop('disabled', true);
  103. unique.removeAttr('disabled');
  104. }
  105. if (type == 'separate')
  106. {
  107. required.removeAttr('checked').prop('disabled', true); alwayseditable.removeAttr('checked').prop('disabled', true); list.removeAttr('checked').prop('disabled', true);
  108. jQuery('#size, #default_value, #langfile').val('').prop('disabled', true);
  109. jQuery('#list').val(3); // visible on create/update/view form only
  110. }
  111. else
  112. {
  113. default_value.removeAttr('disabled');
  114. required.removeAttr('disabled'); alwayseditable.removeAttr('disabled'); list.removeAttr('disabled');
  115. }
  116. }
  117. init_typeoffields(jQuery("#type").val());
  118. jQuery("#type").change(function() {
  119. init_typeoffields($(this).val());
  120. });
  121. // If we enter a formula, we disable other fields
  122. jQuery("#computed_value").keyup(function() {
  123. init_typeoffields(jQuery('#type').val());
  124. });
  125. });
  126. </script>
  127. <!-- Form to edit an extra field -->
  128. <form action="<?php echo $_SERVER["PHP_SELF"]; ?>?attrname=<?php echo $attrname; ?>" id="formeditextrafield" method="post">
  129. <input type="hidden" name="token" value="<?php echo newToken(); ?>">
  130. <input type="hidden" name="attrname" value="<?php echo $attrname; ?>">
  131. <input type="hidden" name="action" value="update">
  132. <input type="hidden" name="rowid" value="<?php echo (empty($rowid) ? '' : $rowid) ?>">
  133. <input type="hidden" name="enabled" value="<?php echo dol_escape_htmltag($extrafields->attributes[$elementtype]['enabled'][$attrname]); ?>">
  134. <?php print dol_get_fiche_head(); ?>
  135. <table summary="listofattributes" class="border centpercent">
  136. <?php
  137. $label = $extrafields->attributes[$elementtype]['label'][$attrname];
  138. $type = $extrafields->attributes[$elementtype]['type'][$attrname];
  139. $size = $extrafields->attributes[$elementtype]['size'][$attrname];
  140. $computed = $extrafields->attributes[$elementtype]['computed'][$attrname];
  141. $default = $extrafields->attributes[$elementtype]['default'][$attrname];
  142. $unique = $extrafields->attributes[$elementtype]['unique'][$attrname];
  143. $required = $extrafields->attributes[$elementtype]['required'][$attrname];
  144. $pos = $extrafields->attributes[$elementtype]['pos'][$attrname];
  145. $alwayseditable = $extrafields->attributes[$elementtype]['alwayseditable'][$attrname];
  146. $param = $extrafields->attributes[$elementtype]['param'][$attrname];
  147. $perms = $extrafields->attributes[$elementtype]['perms'][$attrname];
  148. $langfile = $extrafields->attributes[$elementtype]['langfile'][$attrname];
  149. $list = $extrafields->attributes[$elementtype]['list'][$attrname];
  150. $totalizable = $extrafields->attributes[$elementtype]['totalizable'][$attrname];
  151. $help = $extrafields->attributes[$elementtype]['help'][$attrname];
  152. $entitycurrentorall = $extrafields->attributes[$elementtype]['entityid'][$attrname];
  153. $printable = $extrafields->attributes[$elementtype]['printable'][$attrname];
  154. $enabled = $extrafields->attributes[$elementtype]['enabled'][$attrname];
  155. $css = $extrafields->attributes[$elementtype]['css'][$attrname];
  156. $cssview = $extrafields->attributes[$elementtype]['cssview'][$attrname];
  157. $csslist = $extrafields->attributes[$elementtype]['csslist'][$attrname];
  158. if (is_array($param)) {
  159. if (($type == 'select') || ($type == 'checkbox') || ($type == 'radio')) {
  160. $param_chain = '';
  161. foreach ($param['options'] as $key => $value) {
  162. if (strlen($key)) {
  163. $param_chain .= $key.','.$value."\n";
  164. }
  165. }
  166. } elseif (($type == 'sellist') || ($type == 'chkbxlst') || ($type == 'link') || ($type == 'password') || ($type == 'separate')) {
  167. $paramlist = array_keys($param['options']);
  168. $param_chain = $paramlist[0];
  169. }
  170. }
  171. ?>
  172. <!-- Label -->
  173. <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>
  174. <!-- Code -->
  175. <tr><td class="fieldrequired"><?php echo $langs->trans("AttributeCode"); ?></td><td class="valeur"><?php echo $attrname; ?></td></tr>
  176. <!-- Type -->
  177. <tr><td class="fieldrequired"><?php echo $langs->trans("Type"); ?></td><td class="valeur">
  178. <?php
  179. // Define list of possible type transition
  180. $typewecanchangeinto = array(
  181. 'varchar'=>array('varchar', 'phone', 'mail', 'url', 'ip', 'select', 'password', 'text', 'html'),
  182. 'double'=>array('double', 'price'),
  183. 'price'=>array('double', 'price'),
  184. 'text'=>array('text', 'html'),
  185. 'html'=>array('text', 'html'),
  186. 'password'=>array('password', 'varchar'),
  187. 'mail'=>array('varchar', 'phone', 'mail', 'url', 'ip', 'select'),
  188. 'url'=>array('varchar', 'phone', 'mail', 'url', 'ip', 'select'),
  189. 'phone'=>array('varchar', 'phone', 'mail', 'url', 'ip', 'select'),
  190. 'ip'=>array('varchar', 'phone', 'mail', 'url', 'ip', 'select'),
  191. 'select'=>array('varchar', 'phone', 'mail', 'url', 'ip', 'select'),
  192. 'date'=>array('date', 'datetime')
  193. );
  194. /* Disabled because text is text on several lines, when varchar is text on 1 line, we should not be able to convert
  195. if ($size <= 255 && in_array($type, array('text', 'html'))) {
  196. $typewecanchangeinto['text'][] = 'varchar';
  197. }*/
  198. if (in_array($type, array_keys($typewecanchangeinto))) {
  199. $newarray = array();
  200. print '<select id="type" class="flat type" name="type">';
  201. foreach ($type2label as $key => $val) {
  202. $selected = '';
  203. if ($key == (GETPOST('type', 'alpha') ?GETPOST('type', 'alpha') : $type)) {
  204. $selected = ' selected="selected"';
  205. }
  206. if (in_array($key, $typewecanchangeinto[$type])) {
  207. print '<option value="'.$key.'"'.$selected.'>'.$val.'</option>';
  208. } else {
  209. print '<option value="'.$key.'" disabled="disabled"'.$selected.'>'.$val.'</option>';
  210. }
  211. }
  212. print '</select>';
  213. print ajax_combobox('type');
  214. } else {
  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" class="spanforparamtooltip"><?php print $form->textwithpicto('', $langs->trans("ExtrafieldParamHelpselect"), 1, 0, '', 0, 2, 'helpvalue1')?></span>
  233. <span id="helpsellist" class="spanforparamtooltip"><?php print $form->textwithpicto('', $langs->trans("ExtrafieldParamHelpsellist"), 1, 0, '', 0, 2, 'helpvalue2')?></span>
  234. <span id="helpchkbxlst" class="spanforparamtooltip"><?php print $form->textwithpicto('', $langs->trans("ExtrafieldParamHelpchkbxlst"), 1, 0, '', 0, 2, 'helpvalue3')?></span>
  235. <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>
  236. <span id="helppassword" class="spanforparamtooltip"><?php print $form->textwithpicto('', $langs->trans("ExtrafieldParamHelpPassword"), 1, 0, '', 0, 2, 'helpvalue5')?></span>
  237. <span id="helpseparate" class="spanforparamtooltip"><?php print $form->textwithpicto('', $langs->trans("ExtrafieldParamHelpSeparator"), 1, 0, '', 0, 2, 'helpvalue6')?></span>
  238. </td></tr>
  239. </table>
  240. </td>
  241. </tr>
  242. <!-- Position -->
  243. <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>
  244. <!-- Language file -->
  245. <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>
  246. <!-- Computed value -->
  247. <tr class="extra_computed_value">
  248. <?php if (empty($conf->global->MAIN_STORE_COMPUTED_EXTRAFIELDS)) { ?>
  249. <td><?php echo $form->textwithpicto($langs->trans("ComputedFormula"), $langs->trans("ComputedFormulaDesc"), 1, 'help', '', 0, 2, 'tooltipcompute'); ?></td>
  250. <?php } else { ?>
  251. <td><?php echo $form->textwithpicto($langs->trans("ComputedFormula"), $langs->trans("ComputedFormulaDesc")).$form->textwithpicto($langs->trans("Computedpersistent"), $langs->trans("ComputedpersistentDesc"), 1, 'warning'); ?></td>
  252. <?php } ?>
  253. <td class="valeur"><textarea name="computed_value" id="computed_value" class="quatrevingtpercent" rows="<?php echo ROWS_4 ?>"><?php echo dol_htmlcleanlastbr($computed); ?></textarea></td>
  254. </tr>
  255. <!-- Default Value (at sql setup level) -->
  256. <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>
  257. <!-- Unique -->
  258. <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>
  259. <!-- Required -->
  260. <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>
  261. <!-- Always editable -->
  262. <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>
  263. <!-- Visibility -->
  264. <tr><td class="extra_list"><?php echo $form->textwithpicto($langs->trans("Visibility"), $langs->trans("VisibleDesc").'<br><br>'.$langs->trans("ItCanBeAnExpression")); ?>
  265. </td><td class="valeur"><input id="list" class="minwidth100" type="text" name="list" value="<?php echo ($list != '' ? $list : '1'); ?>"></td></tr>
  266. <!-- Visibility for PDF-->
  267. <tr><td class="extra_pdf"><?php echo $form->textwithpicto($langs->trans("DisplayOnPdf"), $langs->trans("DisplayOnPdfDesc")); ?>
  268. </td><td class="valeur"><input id="printable" class="minwidth100" type="text" name="printable" value="<?php echo dol_escape_htmltag($printable); ?>"></td></tr>
  269. <!-- Can be summed -->
  270. <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>
  271. <!-- Css edit -->
  272. <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>
  273. <!-- Css view -->
  274. <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>
  275. <!-- Css list -->
  276. <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>
  277. <!-- Help tooltip -->
  278. <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>
  279. <?php if (isModEnabled('multicompany')) { ?>
  280. <!-- Multicompany entity -->
  281. <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>
  282. <?php } ?>
  283. <!-- Show Enabled property when value is not a common value -->
  284. <?php if ($enabled != '1') { ?>
  285. <tr class="help"><td><?php echo $langs->trans("EnabledCondition"); ?></td><td class="valeur">
  286. <?php echo dol_escape_htmltag($enabled); ?>
  287. <?php } ?>
  288. </td></tr>
  289. </table>
  290. <?php print dol_get_fiche_end(); ?>
  291. <div class="center"><input type="submit" name="button" class="button button-save" value="<?php echo $langs->trans("Save"); ?>">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  292. <input type="submit" name="button" class="button button-cancel" value="<?php echo $langs->trans("Cancel"); ?>"></div>
  293. </form>
  294. <!-- END PHP TEMPLATE admin_extrafields_edit.tpl.php -->