html.formpropal.class.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <?php
  2. /* Copyright (C) 2012 Laurent Destailleur <eldy@users.sourceforge.net>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  16. */
  17. /**
  18. * \file htdocs/core/class/html.formpropal.class.php
  19. * \ingroup core
  20. * \brief File of class with all html predefined components
  21. */
  22. /**
  23. * Class to manage generation of HTML components for proposal management
  24. */
  25. class FormPropal
  26. {
  27. /**
  28. * @var DoliDB Database handler.
  29. */
  30. public $db;
  31. /**
  32. * @var string Error code (or message)
  33. */
  34. public $error = '';
  35. /**
  36. * Constructor
  37. *
  38. * @param DoliDB $db Database handler
  39. */
  40. public function __construct($db)
  41. {
  42. $this->db = $db;
  43. }
  44. /**
  45. * Return combo list of differents status of a proposal
  46. * Values are id of table c_propalst
  47. *
  48. * @param string $selected Preselected value
  49. * @param int $short Use short labels
  50. * @param int $excludedraft 0=All status, 1=Exclude draft status
  51. * @param int $showempty 1=Add empty line
  52. * @param string $mode 'customer', 'supplier'
  53. * @param string $htmlname Name of select field
  54. * @param string $morecss More css
  55. * @return void
  56. */
  57. public function selectProposalStatus($selected = '', $short = 0, $excludedraft = 0, $showempty = 1, $mode = 'customer', $htmlname = 'propal_statut', $morecss = '')
  58. {
  59. global $langs;
  60. $prefix = '';
  61. $listofstatus = array();
  62. if ($mode == 'supplier') {
  63. $prefix = 'SupplierProposalStatus';
  64. $langs->load("supplier_proposal");
  65. $listofstatus = array(
  66. 0=>array('id'=>0, 'code'=>'PR_DRAFT'),
  67. 1=>array('id'=>1, 'code'=>'PR_OPEN'),
  68. 2=>array('id'=>2, 'code'=>'PR_SIGNED'),
  69. 3=>array('id'=>3, 'code'=>'PR_NOTSIGNED'),
  70. 4=>array('id'=>4, 'code'=>'PR_CLOSED')
  71. );
  72. } else {
  73. $prefix = "PropalStatus";
  74. $sql = "SELECT id, code, label, active FROM ".$this->db->prefix()."c_propalst";
  75. $sql .= " WHERE active = 1";
  76. dol_syslog(get_class($this)."::selectProposalStatus", LOG_DEBUG);
  77. $resql = $this->db->query($sql);
  78. if ($resql) {
  79. $num = $this->db->num_rows($resql);
  80. $i = 0;
  81. if ($num) {
  82. while ($i < $num) {
  83. $obj = $this->db->fetch_object($resql);
  84. $listofstatus[$obj->id] = array('id'=>$obj->id, 'code'=>$obj->code, 'label'=>$obj->label);
  85. $i++;
  86. }
  87. }
  88. } else {
  89. dol_print_error($this->db);
  90. }
  91. }
  92. print '<select id="'.$htmlname.'" name="'.$htmlname.'" class="flat'.($morecss ? ' '.$morecss : '').'">';
  93. if ($showempty) {
  94. print '<option value="-1">&nbsp;</option>';
  95. }
  96. $i = 0;
  97. foreach ($listofstatus as $key => $obj) {
  98. if ($excludedraft) {
  99. if ($obj['code'] == 'Draft' || $obj['code'] == 'PR_DRAFT') {
  100. $i++;
  101. continue;
  102. }
  103. }
  104. if ($selected != '' && $selected == $obj['id']) {
  105. print '<option value="'.$obj['id'].'" selected>';
  106. } else {
  107. print '<option value="'.$obj['id'].'">';
  108. }
  109. $key = $obj['code'];
  110. if ($langs->trans($prefix.$key.($short ? 'Short' : '')) != $prefix.$key.($short ? 'Short' : '')) {
  111. print $langs->trans($prefix.$key.($short ? 'Short' : ''));
  112. } else {
  113. $conv_to_new_code = array('PR_DRAFT'=>'Draft', 'PR_OPEN'=>'Validated', 'PR_CLOSED'=>'Closed', 'PR_SIGNED'=>'Signed', 'PR_NOTSIGNED'=>'NotSigned', 'PR_FAC'=>'Billed');
  114. if (!empty($conv_to_new_code[$obj['code']])) {
  115. $key = $conv_to_new_code[$obj['code']];
  116. }
  117. print ($langs->trans($prefix.$key.($short ? 'Short' : '')) != $prefix.$key.($short ? 'Short' : '')) ? $langs->trans($prefix.$key.($short ? 'Short' : '')) : ($obj['label'] ? $obj['label'] : $obj['code']);
  118. }
  119. print '</option>';
  120. $i++;
  121. }
  122. print '</select>';
  123. print ajax_combobox($htmlname, array(), 0, 0, 'resolve', ($showempty < 0 ? (string) $showempty : '-1'), $morecss);
  124. }
  125. }