dolibarr  7.0.0-beta
html.formbarcode.class.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2007-2012 Regis Houssin <regis.houssin@capnetworks.com>
3  * Copyright (C) 2008-2012 Laurent Destailleur <eldy@users.sourceforge.net>
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 */
19 
30 {
31  var $db;
32  var $error;
33 
34 
40  function __construct($db)
41  {
42  $this->db = $db;
43  return 1;
44  }
45 
46 
56  function setBarcodeEncoder($selected,$barcodelist,$code_id,$idForm='formbarcode')
57  {
58  global $conf, $langs;
59 
60  $disable = '';
61 
62  if ($conf->use_javascript_ajax)
63  {
64  print "\n".'<script type="text/javascript" language="javascript">';
65  print 'jQuery(document).ready(function () {
66  jQuery("#select'.$idForm.'").change(function() {
67  var formName = document.getElementById("form'.$idForm.'");
68  formName.action.value="setcoder";
69  formName.submit();
70  });
71  });';
72  print '</script>'."\n";
73  //onChange="barcode_coder_save(\''.$idForm.'\')
74  }
75 
76  // We check if barcode is already selected by default
77  if (((! empty($conf->product->enabled) || ! empty($conf->service->enabled)) && $conf->global->PRODUIT_DEFAULT_BARCODE_TYPE == $code_id) ||
78  (! empty($conf->societe->enabled) && $conf->global->GENBARCODE_BARCODETYPE_THIRDPARTY == $code_id))
79  {
80  $disable = 'disabled';
81  }
82 
83  $select_encoder = '<form action="'.DOL_URL_ROOT.'/admin/barcode.php" method="post" id="form'.$idForm.'">';
84  $select_encoder.= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
85  $select_encoder.= '<input type="hidden" name="action" value="update">';
86  $select_encoder.= '<input type="hidden" name="code_id" value="'.$code_id.'">';
87  $select_encoder.= '<select id="select'.$idForm.'" class="flat" name="coder">';
88  $select_encoder.= '<option value="0"'.($selected==0?' selected':'').' '.$disable.'>'.$langs->trans('Disable').'</option>';
89  $select_encoder.= '<option value="-1" disabled>--------------------</option>';
90  foreach($barcodelist as $key => $value)
91  {
92  $select_encoder.= '<option value="'.$key.'"'.($selected==$key?' selected':'').'>'.$value.'</option>';
93  }
94  $select_encoder.= '</select></form>';
95 
96  return $select_encoder;
97  }
98 
107  function select_barcode_type($selected='',$htmlname='barcodetype_id',$useempty=0)
108  {
109  global $langs,$conf;
110 
111  $sql = "SELECT rowid, code, libelle";
112  $sql.= " FROM ".MAIN_DB_PREFIX."c_barcode_type";
113  $sql.= " WHERE coder <> '0'";
114  $sql.= " AND entity = ".$conf->entity;
115  $sql.= " ORDER BY code";
116 
117  $result = $this->db->query($sql);
118  if ($result)
119  {
120  $num = $this->db->num_rows($result);
121  $i = 0;
122 
123  if ($useempty && $num > 0)
124  {
125  print '<select class="flat" name="'.$htmlname.'" id="select_'.$htmlname.'">';
126  print '<option value="0">&nbsp;</option>';
127  }
128  else
129  {
130  $langs->load("errors");
131  print '<select disabled class="flat" name="'.$htmlname.'" id="select_'.$htmlname.'">';
132  print '<option value="0" selected>'.$langs->trans('ErrorNoActivatedBarcode').'</option>';
133  }
134 
135  while ($i < $num)
136  {
137  $obj = $this->db->fetch_object($result);
138  if ($selected == $obj->rowid)
139  {
140  print '<option value="'.$obj->rowid.'" selected>';
141  }
142  else
143  {
144  print '<option value="'.$obj->rowid.'">';
145  }
146  print $obj->libelle;
147  print '</option>';
148  $i++;
149  }
150  print "</select>";
151  print ajax_combobox("select_".$htmlname);
152  }
153  else {
154  dol_print_error($this->db);
155  }
156  }
157 
166  function form_barcode_type($page, $selected='', $htmlname='barcodetype_id')
167  {
168  global $langs,$conf;
169  if ($htmlname != "none")
170  {
171  print '<form method="post" action="'.$page.'">';
172  print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
173  print '<input type="hidden" name="action" value="set'.$htmlname.'">';
174  print '<table class="nobordernopadding" cellpadding="0" cellspacing="0">';
175  print '<tr><td>';
176  $this->select_barcode_type($selected, $htmlname, 1);
177  print '</td>';
178  print '<td align="left"><input type="submit" class="button" value="'.$langs->trans("Modify").'">';
179  print '</td></tr></table></form>';
180  }
181  }
182 
183 }
184 
ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete='resolve')
Convert a html select field into an ajax combobox.
Definition: ajax.lib.php:392
setBarcodeEncoder($selected, $barcodelist, $code_id, $idForm='formbarcode')
Return HTML select with list of bar code generators.
form_barcode_type($page, $selected='', $htmlname='barcodetype_id')
Show form to select type of barcode.
select_barcode_type($selected='', $htmlname='barcodetype_id', $useempty=0)
Return form to select type of barcode.
__construct($db)
Constructor.
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
Class to manage barcode HTML.
print
Draft customers invoices.
Definition: index.php:91