html.formbarcode.class.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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. /**
  20. * \file htdocs/core/class/html.formbarcode.class.php
  21. * \brief Fichier de la classe des fonctions predefinie de composants html
  22. */
  23. /**
  24. * Class to manage barcode HTML
  25. */
  26. class FormBarCode
  27. {
  28. var $db;
  29. var $error;
  30. /**
  31. * Constructor
  32. *
  33. * @param DoliDB $db Database handler
  34. */
  35. function __construct($db)
  36. {
  37. $this->db = $db;
  38. return 1;
  39. }
  40. /**
  41. * Return HTML select with list of bar code generators
  42. *
  43. * @param int $selected Id code pre-selected
  44. * @param array $barcodelist Array of barcodes generators
  45. * @param int $code_id Id du code barre
  46. * @param int $idForm Id du formulaire
  47. * @return string HTML select string
  48. */
  49. function setBarcodeEncoder($selected,$barcodelist,$code_id,$idForm='formbarcode')
  50. {
  51. global $conf, $langs;
  52. $disable = '';
  53. if ($conf->use_javascript_ajax)
  54. {
  55. print "\n".'<script type="text/javascript" language="javascript">';
  56. print 'jQuery(document).ready(function () {
  57. jQuery("#select'.$idForm.'").change(function() {
  58. var formName = document.getElementById("form'.$idForm.'");
  59. formName.action.value="setcoder";
  60. formName.submit();
  61. });
  62. });';
  63. print '</script>'."\n";
  64. //onChange="barcode_coder_save(\''.$idForm.'\')
  65. }
  66. // We check if barcode is already selected by default
  67. if (((! empty($conf->product->enabled) || ! empty($conf->service->enabled)) && $conf->global->PRODUIT_DEFAULT_BARCODE_TYPE == $code_id) ||
  68. (! empty($conf->societe->enabled) && $conf->global->GENBARCODE_BARCODETYPE_THIRDPARTY == $code_id))
  69. {
  70. $disable = 'disabled';
  71. }
  72. $select_encoder = '<form action="'.DOL_URL_ROOT.'/admin/barcode.php" method="post" id="form'.$idForm.'">';
  73. $select_encoder.= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  74. $select_encoder.= '<input type="hidden" name="action" value="update">';
  75. $select_encoder.= '<input type="hidden" name="code_id" value="'.$code_id.'">';
  76. $select_encoder.= '<select id="select'.$idForm.'" class="flat" name="coder">';
  77. $select_encoder.= '<option value="0"'.($selected==0?' selected':'').' '.$disable.'>'.$langs->trans('Disable').'</option>';
  78. $select_encoder.= '<option value="-1" disabled>--------------------</option>';
  79. foreach($barcodelist as $key => $value)
  80. {
  81. $select_encoder.= '<option value="'.$key.'"'.($selected==$key?' selected':'').'>'.$value.'</option>';
  82. }
  83. $select_encoder.= '</select></form>';
  84. return $select_encoder;
  85. }
  86. /**
  87. * Return form to select type of barcode
  88. *
  89. * @param int $selected Id code pre-selected
  90. * @param string $htmlname Name of HTML select field
  91. * @param int $useempty Affiche valeur vide dans liste
  92. * @return void
  93. */
  94. function select_barcode_type($selected='',$htmlname='barcodetype_id',$useempty=0)
  95. {
  96. global $langs,$conf;
  97. $sql = "SELECT rowid, code, libelle";
  98. $sql.= " FROM ".MAIN_DB_PREFIX."c_barcode_type";
  99. $sql.= " WHERE coder <> '0'";
  100. $sql.= " AND entity = ".$conf->entity;
  101. $sql.= " ORDER BY code";
  102. $result = $this->db->query($sql);
  103. if ($result)
  104. {
  105. $num = $this->db->num_rows($result);
  106. $i = 0;
  107. if ($useempty && $num > 0)
  108. {
  109. print '<select class="flat" name="'.$htmlname.'" id="select_'.$htmlname.'">';
  110. print '<option value="0">&nbsp;</option>';
  111. }
  112. else
  113. {
  114. $langs->load("errors");
  115. print '<select disabled class="flat" name="'.$htmlname.'" id="select_'.$htmlname.'">';
  116. print '<option value="0" selected>'.$langs->trans('ErrorNoActivatedBarcode').'</option>';
  117. }
  118. while ($i < $num)
  119. {
  120. $obj = $this->db->fetch_object($result);
  121. if ($selected == $obj->rowid)
  122. {
  123. print '<option value="'.$obj->rowid.'" selected>';
  124. }
  125. else
  126. {
  127. print '<option value="'.$obj->rowid.'">';
  128. }
  129. print $obj->libelle;
  130. print '</option>';
  131. $i++;
  132. }
  133. print "</select>";
  134. }
  135. else {
  136. dol_print_error($this->db);
  137. }
  138. }
  139. /**
  140. * Show form to select type of barcode
  141. *
  142. * @param string $page Page
  143. * @param int $selected Id condition preselected
  144. * @param string $htmlname Nom du formulaire select
  145. * @return void
  146. */
  147. function form_barcode_type($page, $selected='', $htmlname='barcodetype_id')
  148. {
  149. global $langs,$conf;
  150. if ($htmlname != "none")
  151. {
  152. print '<form method="post" action="'.$page.'">';
  153. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  154. print '<input type="hidden" name="action" value="set'.$htmlname.'">';
  155. print '<table class="nobordernopadding" cellpadding="0" cellspacing="0">';
  156. print '<tr><td>';
  157. $this->select_barcode_type($selected, $htmlname, 1);
  158. print '</td>';
  159. print '<td align="left"><input type="submit" class="button" value="'.$langs->trans("Modify").'">';
  160. print '</td></tr></table></form>';
  161. }
  162. }
  163. }