dolibarr 24.0.0-beta
html.formcontract.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2012-2026 Charlene BENKE <charlene@patas-monkey.com>
3 * Copyright (C) 2025 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 * or see https://www.gnu.org/
18 */
19
30{
34 public $db;
35
39 public $error = '';
40
41
47 public function __construct($db)
48 {
49 $this->db = $db;
50 }
51
52
53 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
69 public function select_contract($socid = -1, $selected = 0, $htmlname = 'contrattid', $maxlength = 16, $showempty = 1, $showRef = 0, $noouput = 0, $morecss = 'minwidth150')
70 {
71 // phpcs:enable
72 global $user, $conf, $langs;
73
74 $hideunselectables = false;
75 if (getDolGlobalString('CONTRACT_HIDE_UNSELECTABLES')) {
76 $hideunselectables = true;
77 }
78
79 $ret = '';
80
81 // Search all contacts
82 $sql = "SELECT c.rowid, c.ref, c.fk_soc, c.statut as status, s.nom,";
83 $sql .= " c.ref_customer, c.ref_supplier";
84 $sql .= " FROM ".$this->db->prefix()."contrat as c";
85 $sql .= " INNER JOIN ".$this->db->prefix()."societe as s ON s.rowid = c.fk_soc";
86 $sql .= " WHERE c.entity = ".((int) $conf->entity);
87 //if ($contratListId) $sql.= " AND c.rowid IN (".$this->db->sanitize($contratListId).")";
88 if ($socid > 0) {
89 // CONTRACT_ALLOW_TO_LINK_FROM_OTHER_COMPANY is 'all' or a list of ids separated by coma.
90 if (!getDolGlobalString('CONTRACT_ALLOW_TO_LINK_FROM_OTHER_COMPANY')) {
91 $sql .= " AND (c.fk_soc=".((int) $socid)." OR c.fk_soc IS NULL)";
92 } elseif (getDolGlobalString('CONTRACT_ALLOW_TO_LINK_FROM_OTHER_COMPANY') != 'all') {
93 $sql .= " AND (c.fk_soc IN (".$this->db->sanitize(((int) $socid).",".getDolGlobalInt('CONTRACT_ALLOW_TO_LINK_FROM_OTHER_COMPANY')).")";
94 $sql .= " OR c.fk_soc IS NULL)";
95 }
96 }
97 if ($socid == 0) {
98 $sql .= " AND (c.fk_soc = 0 OR c.fk_soc IS NULL)";
99 }
100 $sql .= " ORDER BY c.ref ";
101
102 dol_syslog(get_class($this)."::select_contract", LOG_DEBUG);
103 $resql = $this->db->query($sql);
104 if ($resql) {
105 $ret .= '<select class="flat'.($morecss ? ' '.$morecss : '').'" name="'.$htmlname.'" id="'.$htmlname.'">';
106 if ($showempty) {
107 $ret .= '<option value="0">&nbsp;</option>'."\n";
108 }
109 $num = $this->db->num_rows($resql);
110 $i = 0;
111 if ($num) {
112 while ($i < $num) {
113 $obj = $this->db->fetch_object($resql);
114 // If we ask to filter on a company and user has no permission to see all companies and project is linked to another company, we hide project.
115 if ($socid > 0 && (empty($obj->fk_soc) || $obj->fk_soc == $socid) && !$user->hasRight('societe', 'lire')) {
116 // Do nothing
117 } else {
118 $labeltoshow = dol_trunc($obj->ref, 18);
119
120 if ($showRef) {
121 $labeltoshow = $labeltoshow." - ".$obj->nom;
122 if ($obj->ref_customer) {
123 $labeltoshow = $labeltoshow." - ".$obj->ref_customer;
124 }
125 if ($obj->ref_supplier) {
126 $labeltoshow = $labeltoshow." - ".$obj->ref_supplier;
127 }
128 }
129
130 //if ($obj->public) $labeltoshow.=' ('.$langs->trans("SharedProject").')';
131 //else $labeltoshow.=' ('.$langs->trans("Private").')';
132 if (!empty($selected) && $selected == $obj->rowid && $obj->status > 0) {
133 $ret .= '<option value="'.$obj->rowid.'" selected>'.$labeltoshow.'</option>';
134 } else {
135 $disabled = 0;
136 if ($obj->status == 0) {
137 $disabled = 1;
138 $labeltoshow .= ' ('.$langs->transnoentitiesnoconv("Draft").')';
139 }
140 if (!getDolGlobalString('CONTRACT_ALLOW_TO_LINK_FROM_OTHER_COMPANY') && $socid > 0 && (!empty($obj->fk_soc) && $obj->fk_soc != $socid)) {
141 $disabled = 1;
142 $labeltoshow .= ' - '.$langs->transnoentitiesnoconv("LinkedToAnotherCompany");
143 }
144
145 if ($hideunselectables && $disabled) {
146 $resultat = '';
147 } else {
148 $resultat = '<option value="'.$obj->rowid.'"';
149 if ($disabled) {
150 $resultat .= ' disabled';
151 }
152 //if ($obj->public) $labeltoshow.=' ('.$langs->trans("Public").')';
153 //else $labeltoshow.=' ('.$langs->trans("Private").')';
154 $resultat .= '>'.dolPrintHTML($labeltoshow);
155 $resultat .= '</option>'."\n";
156 }
157 $ret .= $resultat;
158 }
159 }
160 $i++;
161 }
162 }
163 $ret .= '</select>';
164 $this->db->free($resql);
165
166 if (!empty($conf->use_javascript_ajax)) {
167 // Make select dynamic
168 include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
169 $ret .= ajax_combobox($htmlname);
170 }
171
172 if ($noouput) {
173 return $ret;
174 }
175
176 print $ret;
177
178 return $num;
179 } else {
180 dol_print_error($this->db);
181 return -1;
182 }
183 }
184
198 public function formSelectContract($page, $socid = -1, $selected = 0, $htmlname = 'contrattid', $maxlength = 16, $showempty = 1, $showRef = 0, $nooutput = 0)
199 {
200 global $langs;
201
202 $ret = '<form method="post" action="'.$page.'">';
203 $ret .= '<input type="hidden" name="action" value="setcontract">';
204 $ret .= '<input type="hidden" name="token" value="'.newToken().'">';
205 $ret .= $this->select_contract($socid, $selected, $htmlname, $maxlength, $showempty, $showRef, 1);
206 $ret .= '<input type="submit" class="button smallpaddingimp valignmiddle" value="'.$langs->trans("Modify").'">';
207 $ret .= '</form>';
208
209 if ($nooutput) {
210 return $ret;
211 }
212
213 print $ret;
214 }
215}
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:476
Class to manage generation of HTML components for contract module.
formSelectContract($page, $socid=-1, $selected=0, $htmlname='contrattid', $maxlength=16, $showempty=1, $showRef=0, $nooutput=0)
Show a form to select a contract.
select_contract($socid=-1, $selected=0, $htmlname='contrattid', $maxlength=16, $showempty=1, $showRef=0, $noouput=0, $morecss='minwidth150')
Show a combo list with contracts qualified for a third party TODO This is a bugged function.
__construct($db)
Constructor.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.