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