dolibarr 21.0.0-beta
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
66 public function select_type_socialcontrib($selected = 0, $htmlname = 'actioncode', $useempty = 0, $maxlen = 40, $help = 1, $morecss = 'minwidth300', $noerrorifempty = 0)
67 {
68 // phpcs:enable
69 global $conf, $db, $langs, $user, $mysoc;
70
71 if (empty($mysoc->country_id) && empty($mysoc->country_code)) {
72 print $langs->trans("ErrorSetupOfCountryMustBeDone");
73 return;
74 }
75
76 if (!empty($mysoc->country_id)) {
77 $sql = "SELECT c.id, c.libelle as type";
78 $sql .= " FROM ".$this->db->prefix()."c_chargesociales as c";
79 $sql .= " WHERE c.active = 1";
80 $sql .= " AND c.fk_pays = ".((int) $mysoc->country_id);
81 $sql .= " ORDER BY c.libelle ASC";
82 } else {
83 $sql = "SELECT c.id, c.libelle as type";
84 $sql .= " FROM ".$this->db->prefix()."c_chargesociales as c, ".$this->db->prefix()."c_country as co";
85 $sql .= " WHERE c.active = 1 AND c.fk_pays = co.rowid";
86 $sql .= " AND co.code = '".$this->db->escape($mysoc->country_code)."'";
87 $sql .= " ORDER BY c.libelle ASC";
88 }
89
90 dol_syslog("Form::select_type_socialcontrib", LOG_DEBUG);
91 $resql = $this->db->query($sql);
92 if ($resql) {
93 $num = $this->db->num_rows($resql);
94 if ($num) {
95 print '<select class="'.($morecss ? $morecss : '').'" id="'.$htmlname.'" name="'.$htmlname.'">';
96 $i = 0;
97
98 if ($useempty) {
99 print '<option value="0">&nbsp;</option>';
100 }
101 while ($i < $num) {
102 $obj = $this->db->fetch_object($resql);
103 print '<option value="'.$obj->id.'"';
104 if ($obj->id == $selected) {
105 print ' selected';
106 }
107 print '>'.dol_trunc($obj->type, $maxlen);
108 $i++;
109 }
110 print '</select>';
111 if ($user->admin && $help) {
112 print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
113 }
114 if (!empty($conf->use_javascript_ajax)) {
115 print ajax_combobox($htmlname);
116 }
117 } else {
118 if (empty($noerrorifempty)) {
119 print $langs->trans("ErrorNoSocialContributionForSellerCountry", $mysoc->country_code);
120 }
121 }
122 } else {
123 dol_print_error($this->db);
124 }
125 }
126}
ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete='resolve', $idforemptyvalue='-1', $morecss='')
Convert a html select field into an ajax combobox.
Definition ajax.lib.php:459
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)
Return list of social contributions.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='', $picto='')
Show information in HTML for admin users or standard users.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79