dolibarr  7.0.0-beta
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 
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 ?>
36 <!-- BEGIN PHP TEMPLATE extrafields_view.tpl.php -->
37 <?php
38 
39 if (! is_array($parameters)) $parameters = array();
40 if (! empty($cols)) $parameters['colspan'] = ' colspan="'.$cols.'"';
41 if (! empty($cols)) $parameters['cols'] = $cols;
42 if (! empty($object->fk_soc)) $parameters['socid'] = $object->fk_soc;
43 
44 $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action);
45 print $hookmanager->resPrint;
46 if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
47 
48 //var_dump($extrafields->attributes);
49 if (empty($reshook) && ! empty($extrafields->attributes[$object->table_element]['label']))
50 {
51  foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $label)
52  {
53  // Discard if extrafield is a hidden field on form
54  if (empty($extrafields->attributes[$object->table_element]['list'][$key])) continue; // 0 = Never visible field
55  if (abs($extrafields->attributes[$object->table_element]['list'][$key]) != 1 && abs($extrafields->attributes[$object->table_element]['list'][$key]) != 3) continue; // <> -1 and <> 1 and <> 3 = not visible on forms, only on list
56 
57  // Load language if required
58  if (! empty($extrafields->attributes[$object->table_element]['langfile'][$key])) $langs->load($extrafields->attributes[$object->table_element]['langfile'][$key]);
59 
60  if ($action == 'edit_extras')
61  {
62  $value = (isset($_POST["options_" . $key]) ? $_POST["options_" . $key] : $object->array_options["options_" . $key]);
63  }
64  else
65  {
66  $value = $object->array_options["options_" . $key];
67  }
68  if ($extrafields->attributes[$object->table_element]['type'][$key] == 'separate')
69  {
70  print $extrafields->showSeparator($key);
71  }
72  else
73  {
74  print '<tr><td>';
75  print '<table width="100%" class="nobordernopadding">';
76  print '<tr>';
77  print '<td';
78  //var_dump($action);exit;
79  if ((! empty($action) && ($action == 'create' || $action == 'edit')) && ! empty($extrafields->attributes[$object->table_element]['required'][$key])) print ' class="fieldrequired"';
80  print '>' . $langs->trans($label) . '</td>';
81 
82  //TODO Improve element and rights detection
83  //var_dump($user->rights);
84  $permok=false;
85 
86  $keyforperm=$object->element;
87  if ($object->element == 'fichinter') $keyforperm='ficheinter';
88  if (isset($user->rights->$keyforperm)) $permok=$user->rights->$keyforperm->creer||$user->rights->$keyforperm->create||$user->rights->$keyforperm->write;
89 
90  if ($object->element=='order_supplier') $permok=$user->rights->fournisseur->commande->creer;
91  if ($object->element=='invoice_supplier') $permok=$user->rights->fournisseur->facture->creer;
92  if ($object->element=='shipping') $permok=$user->rights->expedition->creer;
93  if ($object->element=='delivery') $permok=$user->rights->expedition->livraison->creer;
94  if ($object->element=='productlot') $permok=$user->rights->stock->creer;
95  if ($object->element=='facturerec') $permok=$user->rights->facture->creer;
96 
97  if (($object->statut == 0 || ! empty($extrafields->attributes[$object->table_element]['alwayseditable'][$key]))
98  && $permok && ($action != 'edit_extras' || GETPOST('attribute') != $key)
99  && empty($extrafields->attributes[$object->table_element]['computed'][$key]))
100  {
101  $fieldid='id';
102  if ($object->table_element == 'societe') $fieldid='socid';
103  print '<td align="right"><a href="' . $_SERVER['PHP_SELF'] . '?'.$fieldid.'=' . $object->id . '&action=edit_extras&attribute=' . $key . '">' . img_edit().'</a></td>';
104  }
105  print '</tr></table>';
106  $html_id = !empty($object->id) ? $object->element.'_extras_'.$key.'_'.$object->id : '';
107  print '<td id="'.$html_id.'" class="'.$object->element.'_extras_'.$key.'" colspan="'.$cols.'">';
108 
109  // Convert date into timestamp format
110  if (in_array($extrafields->attributes[$object->table_element]['type'][$key], array('date','datetime'))) {
111  $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"]) : $db->jdate($object->array_options['options_' . $key]);
112  }
113 
114  //TODO Improve element and rights detection
115  if ($action == 'edit_extras' && $permok && GETPOST('attribute') == $key)
116  {
117  $fieldid='id';
118  if ($object->table_element == 'societe') $fieldid='socid';
119 
120  print '<form enctype="multipart/form-data" action="' . $_SERVER["PHP_SELF"] . '" method="post" name="formextra">';
121  print '<input type="hidden" name="action" value="update_extras">';
122  print '<input type="hidden" name="attribute" value="' . $key . '">';
123  print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
124  print '<input type="hidden" name="'.$fieldid.'" value="' . $object->id . '">';
125 
126  print $extrafields->showInputField($key, $value, '', '', '', 0, $object->id);
127 
128  print '<input type="submit" class="button" value="' . $langs->trans('Modify') . '">';
129 
130  print '</form>';
131  }
132  else
133  {
134  print $extrafields->showOutputField($key, $value);
135  }
136  print '</td></tr>' . "\n";
137 
138  print "\n";
139  // Add code to manage list depending on others
140  if (! empty($conf->use_javascript_ajax))
141  print '
142  <script type="text/javascript">
143  jQuery(document).ready(function() {
144  function showOptions(child_list, parent_list)
145  {
146  var val = $("select[name=\"options_"+parent_list+"\"]").val();
147  var parentVal = parent_list + ":" + val;
148  if(val > 0) {
149  $("select[name=\""+child_list+"\"] option[parent]").hide();
150  $("select[name=\""+child_list+"\"] option[parent=\""+parentVal+"\"]").show();
151  } else {
152  $("select[name=\""+child_list+"\"] option").show();
153  }
154  }
155  function setListDependencies() {
156  jQuery("select option[parent]").parent().each(function() {
157  var child_list = $(this).attr("name");
158  var parent = $(this).find("option[parent]:first").attr("parent");
159  var infos = parent.split(":");
160  var parent_list = infos[0];
161  $("select[name=\""+parent_list+"\"]").change(function() {
162  showOptions(child_list, parent_list);
163  });
164  });
165  }
166 
167  setListDependencies();
168  });
169  </script>'."\n";
170  }
171  }
172 }
173 ?>
174 <!-- END PHP TEMPLATE extrafields_view.tpl.php -->
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...
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
img_edit($titlealt= 'default', $float=0, $other= 'class="pictoedit"')
Show logo editer/modifier fiche.