dolibarr  13.0.2
extrafields_view.tpl.php
1 <?php
2 /* Copyright (C) 2014 Maxime Kohlhaas <support@atm-consulting.fr>
3  * Copyright (C) 2014 Juanjo Menent <jmenent@2byte.es>
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 <https://www.gnu.org/licenses/>.
17  *
18  * Show extrafields. It also show fields from hook formObjectOptions. Need to have following variables defined:
19  * $object (invoice, order, ...)
20  * $action
21  * $conf
22  * $langs
23  *
24  * $parameters
25  * $cols
26  */
27 
28 // Protection to avoid direct call of template
29 if (empty($object) || !is_object($object))
30 {
31  print "Error, template page can't be called as URL";
32  exit;
33 }
34 
35 if (!is_object($form)) $form = new Form($db);
36 
37 
38 ?>
39 <!-- BEGIN PHP TEMPLATE extrafields_view.tpl.php -->
40 <?php
41 if (!is_array($parameters)) $parameters = array();
42 if (!empty($cols)) $parameters['colspan'] = ' colspan="'.$cols.'"';
43 if (!empty($cols)) $parameters['cols'] = $cols;
44 if (!empty($object->fk_soc)) $parameters['socid'] = $object->fk_soc;
45 $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action);
46 print $hookmanager->resPrint;
47 if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
48 
49 
50 //var_dump($extrafields->attributes[$object->table_element]);
51 if (empty($reshook) && is_array($extrafields->attributes[$object->table_element]['label']))
52 {
53  $lastseparatorkeyfound = '';
54  $extrafields_collapse_num = '';
55  $extrafields_collapse_num_old = '';
56  $i = 0;
57  foreach ($extrafields->attributes[$object->table_element]['label'] as $tmpkeyextra => $tmplabelextra)
58  {
59  $i++;
60 
61  // Discard if extrafield is a hidden field on form
62 
63  $enabled = 1;
64  if ($enabled && isset($extrafields->attributes[$object->table_element]['enabled'][$tmpkeyextra]))
65  {
66  $enabled = dol_eval($extrafields->attributes[$object->table_element]['enabled'][$tmpkeyextra], 1);
67  }
68  if ($enabled && isset($extrafields->attributes[$object->table_element]['list'][$tmpkeyextra]))
69  {
70  $enabled = dol_eval($extrafields->attributes[$object->table_element]['list'][$tmpkeyextra], 1);
71  }
72 
73  $perms = 1;
74  if ($perms && isset($extrafields->attributes[$object->table_element]['perms'][$tmpkeyextra]))
75  {
76  $perms = dol_eval($extrafields->attributes[$object->table_element]['perms'][$tmpkeyextra], 1);
77  }
78  //print $tmpkeyextra.'-'.$enabled.'-'.$perms.'-'.$tmplabelextra.$_POST["options_" . $tmpkeyextra].'<br>'."\n";
79 
80  if (empty($enabled)) continue; // 0 = Never visible field
81  if (abs($enabled) != 1 && abs($enabled) != 3 && abs($enabled) != 5 && abs($enabled) != 4) continue; // <> -1 and <> 1 and <> 3 = not visible on forms, only on list <> 4 = not visible at the creation
82  if (empty($perms)) continue; // 0 = Not visible
83 
84  // Load language if required
85  if (!empty($extrafields->attributes[$object->table_element]['langfile'][$tmpkeyextra])) $langs->load($extrafields->attributes[$object->table_element]['langfile'][$tmpkeyextra]);
86  if ($action == 'edit_extras')
87  {
88  $value = (GETPOSTISSET("options_".$tmpkeyextra) ? GETPOST("options_".$tmpkeyextra) : $object->array_options["options_".$tmpkeyextra]);
89  } else {
90  $value = $object->array_options["options_".$tmpkeyextra];
91  //var_dump($tmpkeyextra.' - '.$value);
92  }
93 
94  // Print line tr of extra field
95  if ($extrafields->attributes[$object->table_element]['type'][$tmpkeyextra] == 'separate')
96  {
97  $extrafields_collapse_num = '';
98  $extrafield_param = $extrafields->attributes[$object->table_element]['param'][$tmpkeyextra];
99  if (!empty($extrafield_param) && is_array($extrafield_param)) {
100  $extrafield_param_list = array_keys($extrafield_param['options']);
101 
102  if (count($extrafield_param_list) > 0) {
103  $extrafield_collapse_display_value = intval($extrafield_param_list[0]);
104 
105  if ($extrafield_collapse_display_value == 1 || $extrafield_collapse_display_value == 2) {
106  $extrafields_collapse_num = $extrafields->attributes[$object->table_element]['pos'][$tmpkeyextra];
107  }
108  }
109  }
110 
111  print $extrafields->showSeparator($tmpkeyextra, $object);
112 
113  $lastseparatorkeyfound = $tmpkeyextra;
114  } else {
115  print '<tr class="trextrafields_collapse'.$extrafields_collapse_num;
116  /*if ($extrafields_collapse_num && $extrafields_collapse_num_old && $extrafields_collapse_num != $extrafields_collapse_num_old) {
117  print ' trextrafields_collapse_new';
118  }*/
119  if ($extrafields_collapse_num && $i == count($extrafields->attributes[$object->table_element]['label'])) {
120  print ' trextrafields_collapse_last';
121  }
122  print '">';
123  $extrafields_collapse_num_old = $extrafields_collapse_num;
124  print '<td class="titlefield">';
125  print '<table class="nobordernopadding centpercent">';
126  print '<tr>';
127 
128  print '<td class="';
129  if ((!empty($action) && ($action == 'create' || $action == 'edit')) && !empty($extrafields->attributes[$object->table_element]['required'][$tmpkeyextra])) print ' fieldrequired';
130  print '">';
131  if (!empty($extrafields->attributes[$object->table_element]['help'][$tmpkeyextra])) {
132  // You can also use 'TranslationString:keyfortooltiponlick' for a tooltip on click.
133  $tmptooltip = explode(':', $extrafields->attributes[$object->table_element]['help'][$tmpkeyextra]);
134  print $form->textwithpicto($langs->trans($tmplabelextra), $langs->trans($tmptooltip[0]), 1, 'help', '', 0, 3, (empty($tmptooltip[1]) ? '' : 'extra_'.$tmpkeyextra.'_'.$tmptooltip[1]));
135  } else {
136  print $langs->trans($tmplabelextra);
137  }
138  print '</td>';
139 
140  //TODO Improve element and rights detection
141  //var_dump($user->rights);
142  $permok = false;
143  $keyforperm = $object->element;
144  if ($object->element == 'fichinter') $keyforperm = 'ficheinter';
145  if (isset($user->rights->$keyforperm)) $permok = $user->rights->$keyforperm->creer || $user->rights->$keyforperm->create || $user->rights->$keyforperm->write;
146  if ($object->element == 'order_supplier') $permok = $user->rights->fournisseur->commande->creer;
147  if ($object->element == 'invoice_supplier') $permok = $user->rights->fournisseur->facture->creer;
148  if ($object->element == 'shipping') $permok = $user->rights->expedition->creer;
149  if ($object->element == 'delivery') $permok = $user->rights->expedition->delivery->creer;
150  if ($object->element == 'productlot') $permok = $user->rights->stock->creer;
151  if ($object->element == 'facturerec') $permok = $user->rights->facture->creer;
152  if ($object->element == 'mo') $permok = $user->rights->mrp->write;
153 
154  $isdraft = ((isset($object->statut) && $object->statut == 0) || (isset($object->status) && $object->status == 0));
155  if (($isdraft || !empty($extrafields->attributes[$object->table_element]['alwayseditable'][$tmpkeyextra]))
156  && $permok && $enabled != 5 && ($action != 'edit_extras' || GETPOST('attribute') != $tmpkeyextra)
157  && empty($extrafields->attributes[$object->table_element]['computed'][$tmpkeyextra]))
158  {
159  $fieldid = 'id';
160  if ($object->table_element == 'societe') $fieldid = 'socid';
161  print '<td class="right"><a class="reposition editfielda" href="'.$_SERVER['PHP_SELF'].'?'.$fieldid.'='.$object->id.'&action=edit_extras&attribute='.$tmpkeyextra.'&ignorecollapsesetup=1">'.img_edit().'</a></td>';
162  }
163  print '</tr></table>';
164  print '</td>';
165 
166  $html_id = !empty($object->id) ? $object->element.'_extras_'.$tmpkeyextra.'_'.$object->id : '';
167 
168  print '<td id="'.$html_id.'" class="'.$object->element.'_extras_'.$tmpkeyextra.' wordbreak"'.($cols ? ' colspan="'.$cols.'"' : '').'>';
169 
170  // Convert date into timestamp format
171  if (in_array($extrafields->attributes[$object->table_element]['type'][$tmpkeyextra], array('date')))
172  {
173  $datenotinstring = $object->array_options['options_'.$tmpkeyextra];
174  // print 'X'.$object->array_options['options_' . $tmpkeyextra].'-'.$datenotinstring.'x';
175  if (!is_numeric($object->array_options['options_'.$tmpkeyextra])) // For backward compatibility
176  {
177  $datenotinstring = $db->jdate($datenotinstring);
178  }
179  //print 'x'.$object->array_options['options_' . $tmpkeyextra].'-'.$datenotinstring.' - '.dol_print_date($datenotinstring, 'dayhour');
180  $value = GETPOSTISSET("options_".$tmpkeyextra) ? dol_mktime(12, 0, 0, GETPOST("options_".$tmpkeyextra."month", 'int'), GETPOST("options_".$tmpkeyextra."day", 'int'), GETPOST("options_".$tmpkeyextra."year", 'int')) : $datenotinstring;
181  }
182  if (in_array($extrafields->attributes[$object->table_element]['type'][$tmpkeyextra], array('datetime')))
183  {
184  $datenotinstring = $object->array_options['options_'.$tmpkeyextra];
185  // print 'X'.$object->array_options['options_' . $tmpkeyextra].'-'.$datenotinstring.'x';
186  if (!is_numeric($object->array_options['options_'.$tmpkeyextra])) // For backward compatibility
187  {
188  $datenotinstring = $db->jdate($datenotinstring);
189  }
190  //print 'x'.$object->array_options['options_' . $tmpkeyextra].'-'.$datenotinstring.' - '.dol_print_date($datenotinstring, 'dayhour');
191  $value = GETPOSTISSET("options_".$tmpkeyextra) ? dol_mktime(GETPOST("options_".$tmpkeyextra."hour", 'int'), GETPOST("options_".$tmpkeyextra."min", 'int'), GETPOST("options_".$tmpkeyextra."sec", 'int'), GETPOST("options_".$tmpkeyextra."month", 'int'), GETPOST("options_".$tmpkeyextra."day", 'int'), GETPOST("options_".$tmpkeyextra."year", 'int'), 'tzuserrel') : $datenotinstring;
192  }
193 
194  //TODO Improve element and rights detection
195  if ($action == 'edit_extras' && $permok && GETPOST('attribute', 'restricthtml') == $tmpkeyextra)
196  {
197  $fieldid = 'id';
198  if ($object->table_element == 'societe') $fieldid = 'socid';
199  print '<form enctype="multipart/form-data" action="'.$_SERVER["PHP_SELF"].'" method="post" name="formextra">';
200  print '<input type="hidden" name="action" value="update_extras">';
201  print '<input type="hidden" name="attribute" value="'.$tmpkeyextra.'">';
202  print '<input type="hidden" name="token" value="'.newToken().'">';
203  print '<input type="hidden" name="'.$fieldid.'" value="'.$object->id.'">';
204  print $extrafields->showInputField($tmpkeyextra, $value, '', '', '', 0, $object->id, $object->table_element);
205 
206  print '<input type="submit" class="button" value="'.dol_escape_htmltag($langs->trans('Modify')).'">';
207 
208  print '</form>';
209  } else {
210  //var_dump($tmpkeyextra.'-'.$value.'-'.$object->table_element);
211  print $extrafields->showOutputField($tmpkeyextra, $value, '', $object->table_element);
212  }
213 
214  print '</td>';
215  print '</tr>'."\n";
216  }
217  }
218 
219 
220  // Add code to manage list depending on others
221  // TODO Test/enhance this with a more generic solution
222  if (!empty($conf->use_javascript_ajax))
223  {
224  print "\n";
225  print '
226  <script>
227  jQuery(document).ready(function() {
228  function showOptions(child_list, parent_list)
229  {
230  var val = $("select[name="+parent_list+"]").val();
231  var parentVal = parent_list + ":" + val;
232  if(val > 0) {
233  $("select[name=\""+child_list+"\"] option[parent]").hide();
234  $("select[name=\""+child_list+"\"] option[parent=\""+parentVal+"\"]").show();
235  } else {
236  $("select[name=\""+child_list+"\"] option").show();
237  }
238  }
239  function setListDependencies() {
240  jQuery("select option[parent]").parent().each(function() {
241  var child_list = $(this).attr("name");
242  var parent = $(this).find("option[parent]:first").attr("parent");
243  var infos = parent.split(":");
244  var parent_list = infos[0];
245  showOptions(child_list, parent_list);
246 
247  /* Activate the handler to call showOptions on each future change */
248  $("select[name=\""+parent_list+"\"]").change(function() {
249  showOptions(child_list, parent_list);
250  });
251  });
252  }
253  setListDependencies();
254  });
255  </script>'."\n";
256  }
257 }
258 ?>
259 <!-- END PHP TEMPLATE extrafields_view.tpl.php -->
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
img_edit($titlealt= 'default', $float=0, $other= '')
Show logo editer/modifier fiche.
dol_eval($s, $returnvalue=0, $hideerrors=1)
Replace eval function to add more security.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm= 'auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
Class to manage generation of HTML components Only common components must be here.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname.
print
Draft customers invoices.
Definition: index.php:89