helper.class.php 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. class VoucherHelper
  3. {
  4. public $db;
  5. /**
  6. * Class constructor.
  7. */
  8. public function __construct()
  9. {
  10. global $db;
  11. $this->db = $db;
  12. }
  13. function showInputField($fk_product)
  14. {
  15. $inputFieldString = '';
  16. $sql = "SELECT pr.rowid, pr.label FROM llx_product as pr
  17. INNER JOIN llx_product_extrafields as pre ON pre.fk_object = pr.rowid
  18. WHERE pre.is_in_bundle IS null
  19. AND pre.hotelsales is null
  20. ORDER BY pr.label";
  21. $result = $this->db->query($sql);
  22. $inputFieldString .= '<select class="flat minwidth100" id="fk_product" name="fk_product" data-select2-id="fk_product" tabindex="-1" aria-hidden="true">';
  23. $inputFieldString .= '<option value="-1" data-select2-id="4">&nbsp;</option>';
  24. if ($this->db->num_rows($result) > 0) {
  25. while ($row = $this->db->fetch_object($result)) {
  26. $selected = $row->rowid == $fk_product ? 'selected' : '';
  27. $inputFieldString .= '<option value="' . $row->rowid . '" ' . $selected . '>' . $row->label . '</option>';
  28. }
  29. }
  30. $inputFieldString .= '</select>';
  31. return $inputFieldString;
  32. }
  33. function JSGeneratorForSelectInput($id){
  34. print '<script>$("#' . $id . '").select2({
  35. dir: "ltr",
  36. width: "resolve",
  37. minimumInputLength: 0,
  38. language: select2arrayoflanguage,
  39. matcher: function(params, data) {
  40. if ($.trim(params.term) === "") {
  41. return data;
  42. }
  43. keywords = (params.term).split(" ");
  44. for (var i = 0; i < keywords.length; i++) {
  45. if (((data.text).toUpperCase()).indexOf((keywords[i]).toUpperCase()) == -1) {
  46. return null;
  47. }
  48. }
  49. return data;
  50. },
  51. theme: "default",
  52. containerCssClass: ":all:",
  53. selectionCssClass: ":all:",
  54. templateResult: function(data, container) {
  55. if (data.element) {
  56. $(container).addClass($(data.element).attr("class"));
  57. }
  58. if (data.id == -1 && $(data.element).attr("data-html") == undefined) {
  59. return "&nbsp;";
  60. }
  61. if ($(data.element).attr("data-html") != undefined) return htmlEntityDecodeJs($(data.element).attr("data-html")); // If property html set, we decode html entities and use this
  62. return data.text;
  63. },
  64. templateSelection: function(selection) {
  65. if (selection.id == -1) return "<span class="placeholder">" + selection.text + "</span>";
  66. return selection.text;
  67. },
  68. escapeMarkup: function(markup) {
  69. return markup;
  70. },
  71. dropdownCssClass: "ui-dialog"
  72. });</script>';
  73. }
  74. }
  75. ?>