html.formsocialcontrib.class.php 4.1 KB

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