dolibarr 25.0.0-alpha
html.formsocialcontrib.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2012 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 */
18
30{
34 public $db;
35
39 public $error = '';
40
41
47 public function __construct($db)
48 {
49 $this->db = $db;
50 }
51
52 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
67 public function select_type_socialcontrib($selected = 0, $htmlname = 'actioncode', $useempty = 0, $maxlen = 40, $help = 1, $morecss = 'minwidth300', $noerrorifempty = 0, $noout = 0)
68 {
69 // phpcs:enable
70 global $conf, $langs, $user, $mysoc;
71
72 if (empty($mysoc->country_id) && empty($mysoc->country_code)) {
73 $out = $langs->trans("ErrorSetupOfCountryMustBeDone");
74 if (empty($noout)) {
75 print $out;
76 }
77 return $out;
78 }
79
80 if (!empty($mysoc->country_id)) {
81 $sql = "SELECT c.id, c.libelle as type";
82 $sql .= " FROM ".$this->db->prefix()."c_chargesociales as c";
83 $sql .= " WHERE c.active = 1";
84 $sql .= " AND c.fk_pays = ".((int) $mysoc->country_id);
85 $sql .= " ORDER BY c.libelle ASC";
86 } else {
87 $sql = "SELECT c.id, c.libelle as type";
88 $sql .= " FROM ".$this->db->prefix()."c_chargesociales as c, ".$this->db->prefix()."c_country as co";
89 $sql .= " WHERE c.active = 1 AND c.fk_pays = co.rowid";
90 $sql .= " AND co.code = '".$this->db->escape($mysoc->country_code)."'";
91 $sql .= " ORDER BY c.libelle ASC";
92 }
93
94 dol_syslog("Form::select_type_socialcontrib", LOG_DEBUG);
95
96 $out = '';
97
98 $resql = $this->db->query($sql);
99 if ($resql) {
100 $num = $this->db->num_rows($resql);
101 if ($num) {
102 $out .= '<select class="'.($morecss ? $morecss : '').'" id="'.$htmlname.'" name="'.$htmlname.'">';
103 $i = 0;
104
105 if ($useempty) {
106 $out .= '<option value="-1">';
107 if (!is_numeric($useempty)) {
108 $out .= $useempty;
109 } else {
110 $out .= '&nbsp;';
111 }
112 $out .= '</option>';
113 }
114 while ($i < $num) {
115 $obj = $this->db->fetch_object($resql);
116 $out .= '<option value="'.$obj->id.'"';
117 if ($obj->id == $selected) {
118 $out .= ' selected';
119 }
120 $out .= '>'.dol_trunc($obj->type, $maxlen);
121 $i++;
122 }
123 $out .= '</select>';
124 if ($user->admin && $help) {
125 $out .= info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
126 }
127 if (!empty($conf->use_javascript_ajax)) {
128 $out .= ajax_combobox($htmlname);
129 }
130 } else {
131 if (empty($noerrorifempty)) {
132 $out .= $langs->trans("ErrorNoSocialContributionForSellerCountry", $mysoc->country_code);
133 }
134 }
135 } else {
136 dol_print_error($this->db);
137 }
138
139 if (empty($noout)) {
140 print $out;
141 }
142
143 return $out;
144 }
145}
ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete='resolve', $idforemptyvalue='-1', $morecss='', $placeholder='')
Convert a html select field into an ajax combobox.
Definition ajax.lib.php:477
Class to manage generation of HTML components for social contributions management.
select_type_socialcontrib($selected=0, $htmlname='actioncode', $useempty=0, $maxlen=40, $help=1, $morecss='minwidth300', $noerrorifempty=0, $noout=0)
Return list of social contributions.
global $mysoc
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='', $picto='', $textonpictotooltip='', $cssfordropdown='info_admin')
Show information in HTML for admin users or standard users.