html.formsocialcontrib.class.php 4.2 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. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
  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. * @return void
  56. */
  57. function select_type_socialcontrib($selected='',$htmlname='actioncode', $useempty=0, $maxlen=40, $help=1, $morecss='minwidth300')
  58. {
  59. // phpcs:enable
  60. global $conf,$db,$langs,$user,$mysoc;
  61. if (empty($mysoc->country_id) && empty($mysoc->country_code))
  62. {
  63. dol_print_error('','Call to select_type_socialcontrib with mysoc country not yet defined');
  64. exit;
  65. }
  66. if (! empty($mysoc->country_id))
  67. {
  68. $sql = "SELECT c.id, c.libelle as type";
  69. $sql.= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c";
  70. $sql.= " WHERE c.active = 1";
  71. $sql.= " AND c.fk_pays = ".$mysoc->country_id;
  72. $sql.= " ORDER BY c.libelle ASC";
  73. }
  74. else
  75. {
  76. $sql = "SELECT c.id, c.libelle as type";
  77. $sql.= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c, ".MAIN_DB_PREFIX."c_country as co";
  78. $sql.= " WHERE c.active = 1 AND c.fk_pays = co.rowid";
  79. $sql.= " AND co.code = '".$mysoc->country_code."'";
  80. $sql.= " ORDER BY c.libelle ASC";
  81. }
  82. dol_syslog("Form::select_type_socialcontrib", LOG_DEBUG);
  83. $resql=$db->query($sql);
  84. if ($resql)
  85. {
  86. $num = $db->num_rows($resql);
  87. if ($num)
  88. {
  89. print '<select class="'.($morecss?$morecss:'').'" id="'.$htmlname.'" name="'.$htmlname.'">';
  90. $i = 0;
  91. if ($useempty) print '<option value="0">&nbsp;</option>';
  92. while ($i < $num)
  93. {
  94. $obj = $db->fetch_object($resql);
  95. print '<option value="'.$obj->id.'"';
  96. if ($obj->id == $selected) print ' selected';
  97. print '>'.dol_trunc($obj->type,$maxlen);
  98. $i++;
  99. }
  100. print '</select>';
  101. if ($user->admin && $help) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
  102. if (! empty($conf->use_javascript_ajax)) print ajax_combobox($htmlname);
  103. }
  104. else
  105. {
  106. print $langs->trans("ErrorNoSocialContributionForSellerCountry",$mysoc->country_code);
  107. }
  108. }
  109. else
  110. {
  111. dol_print_error($db,$db->lasterror());
  112. }
  113. }
  114. }