html.formsocialcontrib.class.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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.formsocialcontrib.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 social contributions management
  24. */
  25. class FormSocialContrib
  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 list of social contributions.
  40. * Use mysoc->country_id or mysoc->country_code so they must be defined.
  41. *
  42. * @param string $selected Preselected type
  43. * @param string $htmlname Name of field in form
  44. * @param int $useempty Set to 1 if we want an empty value
  45. * @param int $maxlen Max length of text in combo box
  46. * @param int $help Add or not the admin help picto
  47. * @return void
  48. */
  49. function select_type_socialcontrib($selected='',$htmlname='actioncode', $useempty=0, $maxlen=40, $help=1)
  50. {
  51. global $db,$langs,$user,$mysoc;
  52. if (empty($mysoc->country_id) && empty($mysoc->country_code))
  53. {
  54. dol_print_error('','Call to select_type_socialcontrib with mysoc country not yet defined');
  55. exit;
  56. }
  57. if (! empty($mysoc->country_id))
  58. {
  59. $sql = "SELECT c.id, c.libelle as type";
  60. $sql.= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c";
  61. $sql.= " WHERE c.active = 1";
  62. $sql.= " AND c.fk_pays = ".$mysoc->country_id;
  63. $sql.= " ORDER BY c.libelle ASC";
  64. }
  65. else
  66. {
  67. $sql = "SELECT c.id, c.libelle as type";
  68. $sql.= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c, ".MAIN_DB_PREFIX."c_country as co";
  69. $sql.= " WHERE c.active = 1 AND c.fk_pays = co.rowid";
  70. $sql.= " AND co.code = '".$mysoc->country_code."'";
  71. $sql.= " ORDER BY c.libelle ASC";
  72. }
  73. dol_syslog("Form::select_type_socialcontrib", LOG_DEBUG);
  74. $resql=$db->query($sql);
  75. if ($resql)
  76. {
  77. $num = $db->num_rows($resql);
  78. if ($num)
  79. {
  80. print '<select class="flat" name="'.$htmlname.'">';
  81. $i = 0;
  82. if ($useempty) print '<option value="0">&nbsp;</option>';
  83. while ($i < $num)
  84. {
  85. $obj = $db->fetch_object($resql);
  86. print '<option value="'.$obj->id.'"';
  87. if ($obj->id == $selected) print ' selected';
  88. print '>'.dol_trunc($obj->type,$maxlen);
  89. $i++;
  90. }
  91. print '</select>';
  92. if ($user->admin && $help) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
  93. }
  94. else
  95. {
  96. print $langs->trans("ErrorNoSocialContributionForSellerCountry",$mysoc->country_code);
  97. }
  98. }
  99. else
  100. {
  101. dol_print_error($db,$db->lasterror());
  102. }
  103. }
  104. }