html.formpropal.class.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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 <http://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. var $db;
  28. var $error;
  29. /**
  30. * Constructor
  31. *
  32. * @param DoliDB $db Database handler
  33. */
  34. public function __construct($db)
  35. {
  36. $this->db = $db;
  37. }
  38. /**
  39. * Return combo list of differents status of a proposal
  40. * Values are id of table c_propalst
  41. *
  42. * @param string $selected Preselected value
  43. * @param int $short Use short labels
  44. * @param int $excludedraft 0=All status, 1=Exclude draft status
  45. * @param int $showempty 1=Add empty line
  46. * @param string $mode 'customer', 'supplier'
  47. * @param string $htmlname Name of select field
  48. * @return void
  49. */
  50. function selectProposalStatus($selected='',$short=0, $excludedraft=0, $showempty=1, $mode='customer',$htmlname='propal_statut')
  51. {
  52. global $langs;
  53. $prefix='';
  54. $listofstatus=array();
  55. if ($mode == 'supplier')
  56. {
  57. $prefix='SupplierProposalStatus';
  58. $langs->load("supplier_proposal");
  59. $listofstatus=array(
  60. 0=>array('id'=>0, 'code'=>'PR_DRAFT'),
  61. 1=>array('id'=>1, 'code'=>'PR_OPEN'),
  62. 2=>array('id'=>2, 'code'=>'PR_SIGNED'),
  63. 3=>array('id'=>3, 'code'=>'PR_NOTSIGNED'),
  64. 4=>array('id'=>4, 'code'=>'PR_CLOSED')
  65. );
  66. }
  67. else
  68. {
  69. $prefix="PropalStatus";
  70. $sql = "SELECT id, code, label, active FROM ".MAIN_DB_PREFIX."c_propalst";
  71. $sql .= " WHERE active = 1";
  72. dol_syslog(get_class($this)."::selectProposalStatus", LOG_DEBUG);
  73. $resql=$this->db->query($sql);
  74. if ($resql)
  75. {
  76. $num = $this->db->num_rows($resql);
  77. $i = 0;
  78. if ($num)
  79. {
  80. while ($i < $num)
  81. {
  82. $obj = $this->db->fetch_object($resql);
  83. $listofstatus[$obj->id]=array('id'=>$obj->id,'code'=>$obj->code,'label'=>$obj->label);
  84. $i++;
  85. }
  86. }
  87. }
  88. else
  89. {
  90. dol_print_error($this->db);
  91. }
  92. }
  93. print '<select class="flat" name="'.$htmlname.'">';
  94. if ($showempty) print '<option value="-1">&nbsp;</option>';
  95. foreach($listofstatus as $key => $obj)
  96. {
  97. if ($excludedraft)
  98. {
  99. if ($obj['code'] == 'Draft' || $obj['code'] == 'PR_DRAFT')
  100. {
  101. $i++;
  102. continue;
  103. }
  104. }
  105. if ($selected != '' && $selected == $obj['id'])
  106. {
  107. print '<option value="'.$obj['id'].'" selected>';
  108. }
  109. else
  110. {
  111. print '<option value="'.$obj['id'].'">';
  112. }
  113. $key=$obj['code'];
  114. if ($langs->trans($prefix.$key.($short?'Short':'')) != $prefix.$key.($short?'Short':''))
  115. {
  116. print $langs->trans($prefix.$key.($short?'Short':''));
  117. }
  118. else
  119. {
  120. $conv_to_new_code=array('PR_DRAFT'=>'Draft','PR_OPEN'=>'Validated','PR_CLOSED'=>'Closed','PR_SIGNED'=>'Signed','PR_NOTSIGNED'=>'NotSigned','PR_FAC'=>'Billed');
  121. if (! empty($conv_to_new_code[$obj['code']])) $key=$conv_to_new_code[$obj['code']];
  122. print ($langs->trans($prefix.$key.($short?'Short':''))!=$prefix.$key.($short?'Short':''))?$langs->trans($prefix.$key.($short?'Short':'')):($obj['label']?$obj['label']:$obj['code']);
  123. }
  124. print '</option>';
  125. $i++;
  126. }
  127. print '</select>';
  128. }
  129. }