dolibarr  9.0.0
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 <http://www.gnu.org/licenses/>.
17  *
18  * Need to have following variables defined:
19  * $object (invoice, order, ...)
20  * $action
21  * $conf
22  * $langs
23  *
24  * $parameters
25  * $cols
26  */
27 // Protection to avoid direct call of template
28 if (empty($object) || ! is_object($object))
29 {
30  print "Error, template page can't be called as URL";
31  exit;
32 }
33 
34 if (! is_object($form)) $form=new Form($db);
35 
36 
37 ?>
38 <!-- BEGIN PHP TEMPLATE extrafields_view.tpl.php -->
39 <?php
40 if (! is_array($parameters)) $parameters = array();
41 if (! empty($cols)) $parameters['colspan'] = ' colspan="'.$cols.'"';
42 if (! empty($cols)) $parameters['cols'] = $cols;
43 if (! empty($object->fk_soc)) $parameters['socid'] = $object->fk_soc;
44 $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action);
45 print $hookmanager->resPrint;
46 if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
47 
48 
49 //var_dump($extrafields->attributes[$object->table_element]);
50 if (empty($reshook) && is_array($extrafields->attributes[$object->table_element]['label']))
51 
52 {
53  foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $label)
54  {
55  // Discard if extrafield is a hidden field on form
56 
57  $enabled = 1;
58  if ($enabled && isset($extrafields->attributes[$object->table_element]['enabled'][$key]))
59  {
60  $enabled = dol_eval($extrafields->attributes[$object->table_element]['enabled'][$key], 1);
61  }
62  if ($enabled && isset($extrafields->attributes[$object->table_element]['list'][$key]))
63  {
64  $enabled = dol_eval($extrafields->attributes[$object->table_element]['list'][$key], 1);
65  }
66  $perms = 1;
67  if ($perms && isset($extrafields->attributes[$object->table_element]['perms'][$key]))
68  {
69  $perms = dol_eval($extrafields->attributes[$object->table_element]['perms'][$key], 1);
70  }
71  //print $key.'-'.$enabled.'-'.$perms.'-'.$label.$_POST["options_" . $key].'<br>'."\n";
72 
73  if (empty($enabled)) continue; // 0 = Never visible field
74  if (abs($enabled) != 1 && abs($enabled) != 3) continue; // <> -1 and <> 1 and <> 3 = not visible on forms, only on list
75  if (empty($perms)) continue; // 0 = Not visible
76 
77  // Load language if required
78  if (! empty($extrafields->attributes[$object->table_element]['langfile'][$key])) $langs->load($extrafields->attributes[$object->table_element]['langfile'][$key]);
79  if ($action == 'edit_extras')
80  {
81  $value = (isset($_POST["options_" . $key]) ? $_POST["options_" . $key] : $object->array_options["options_" . $key]);
82  }
83  else
84  {
85  $value = $object->array_options["options_" . $key];
86  }
87  if ($extrafields->attributes[$object->table_element]['type'][$key] == 'separate')
88  {
89  print $extrafields->showSeparator($key, $object);
90  }
91  else
92  {
93  print '<tr>';
94  print '<td class="titlefield">';
95  print '<table width="100%" class="nobordernopadding">';
96  print '<tr>';
97  print '<td';
98  print ' class="';
99  //var_dump($action);exit;
100 
101  if ((! empty($action) && ($action == 'create' || $action == 'edit')) && ! empty($extrafields->attributes[$object->table_element]['required'][$key])) print ' fieldrequired';
102  print '">';
103  if (! empty($extrafields->attributes[$object->table_element]['help'][$key])) print $form->textwithpicto($langs->trans($label), $langs->trans($extrafields->attributes[$object->table_element]['help'][$key]));
104  else print $langs->trans($label);
105  print '</td>';
106 
107  //TODO Improve element and rights detection
108  //var_dump($user->rights);
109  $permok=false;
110  $keyforperm=$object->element;
111  if ($object->element == 'fichinter') $keyforperm='ficheinter';
112  if (isset($user->rights->$keyforperm)) $permok=$user->rights->$keyforperm->creer||$user->rights->$keyforperm->create||$user->rights->$keyforperm->write;
113  if ($object->element=='order_supplier') $permok=$user->rights->fournisseur->commande->creer;
114  if ($object->element=='invoice_supplier') $permok=$user->rights->fournisseur->facture->creer;
115  if ($object->element=='shipping') $permok=$user->rights->expedition->creer;
116  if ($object->element=='delivery') $permok=$user->rights->expedition->livraison->creer;
117  if ($object->element=='productlot') $permok=$user->rights->stock->creer;
118  if ($object->element=='facturerec') $permok=$user->rights->facture->creer;
119  if (($object->statut == 0 || ! empty($extrafields->attributes[$object->table_element]['alwayseditable'][$key]))
120  && $permok && ($action != 'edit_extras' || GETPOST('attribute') != $key)
121  && empty($extrafields->attributes[$object->table_element]['computed'][$key]))
122  {
123  $fieldid='id';
124  if ($object->table_element == 'societe') $fieldid='socid';
125  print '<td align="right"><a class="reposition" href="' . $_SERVER['PHP_SELF'] . '?'.$fieldid.'=' . $object->id . '&action=edit_extras&attribute=' . $key . '">' . img_edit().'</a></td>';
126  }
127  print '</tr></table>';
128  print '</td>';
129 
130  $html_id = !empty($object->id) ? $object->element.'_extras_'.$key.'_'.$object->id : '';
131 
132  print '<td id="'.$html_id.'" class="'.$object->element.'_extras_'.$key.' wordbreak"'.($cols?' colspan="'.$cols.'"':'').'>';
133 
134  // Convert date into timestamp format
135  if (in_array($extrafields->attributes[$object->table_element]['type'][$key], array('date','datetime')))
136  {
137  $datenotinstring = $object->array_options['options_' . $key];
138  // print 'X'.$object->array_options['options_' . $key].'-'.$datenotinstring.'x';
139  if (! is_numeric($object->array_options['options_' . $key])) // For backward compatibility
140  {
141  $datenotinstring = $db->jdate($datenotinstring);
142  }
143  //print 'x'.$object->array_options['options_' . $key].'-'.$datenotinstring.' - '.dol_print_date($datenotinstring, 'dayhour');
144  $value = isset($_POST["options_" . $key]) ? dol_mktime($_POST["options_" . $key . "hour"], $_POST["options_" . $key . "min"], 0, $_POST["options_" . $key . "month"], $_POST["options_" . $key . "day"], $_POST["options_" . $key . "year"]) : $datenotinstring;
145  }
146  //TODO Improve element and rights detection
147  if ($action == 'edit_extras' && $permok && GETPOST('attribute','none') == $key)
148  {
149  $fieldid='id';
150  if ($object->table_element == 'societe') $fieldid='socid';
151  print '<form enctype="multipart/form-data" action="' . $_SERVER["PHP_SELF"] . '" method="post" name="formextra">';
152  print '<input type="hidden" name="action" value="update_extras">';
153  print '<input type="hidden" name="attribute" value="' . $key . '">';
154  print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
155  print '<input type="hidden" name="'.$fieldid.'" value="' . $object->id . '">';
156  print $extrafields->showInputField($key, $value, '', '', '', 0, $object->id);
157 
158 
159  print '<input type="submit" class="button" value="' . dol_escape_htmltag($langs->trans('Modify')) . '">';
160 
161  print '</form>';
162  }
163  else
164  {
165  //print $key.'-'.$value.'-'.$object->table_element;
166  print $extrafields->showOutputField($key, $value, '', $object->table_element);
167  }
168 
169  print '</td>';
170  print '</tr>' . "\n";
171  }
172  }
173 
174 
175  // Add code to manage list depending on others
176  // TODO Test/enhance this with a more generic solution
177  if (! empty($conf->use_javascript_ajax))
178  {
179  print "\n";
180  print '
181  <script type="text/javascript">
182  jQuery(document).ready(function() {
183  function showOptions(child_list, parent_list)
184  {
185  var val = $("select[name="+parent_list+"]").val();
186  var parentVal = parent_list + ":" + val;
187  if(val > 0) {
188  $("select[name=\""+child_list+"\"] option[parent]").hide();
189  $("select[name=\""+child_list+"\"] option[parent=\""+parentVal+"\"]").show();
190  } else {
191  $("select[name=\""+child_list+"\"] option").show();
192  }
193  }
194  function setListDependencies() {
195  jQuery("select option[parent]").parent().each(function() {
196  var child_list = $(this).attr("name");
197  var parent = $(this).find("option[parent]:first").attr("parent");
198  var infos = parent.split(":");
199  var parent_list = infos[0];
200  $("select[name=\""+parent_list+"\"]").change(function() {
201  showOptions(child_list, parent_list);
202  });
203  });
204  }
205  setListDependencies();
206  });
207  </script>'."\n";
208  }
209 }
210 ?>
211 <!-- END PHP TEMPLATE extrafields_view.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
dol_eval($s, $returnvalue=0, $hideerrors=1)
Replace eval function to add more security.
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm=false, $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
img_edit($titlealt='default', $float=0, $other='class="pictoedit"')
Show logo editer/modifier fiche.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields...
Class to manage generation of HTML components Only common components must be here.