dolibarr 22.0.5
html.formcontract.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2012-2018 Charlene BENKE <charlie@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
67 public function select_contract($socid = -1, $selected = 0, $htmlname = 'contrattid', $maxlength = 16, $showempty = 1, $showRef = 0, $noouput = 0, $morecss = 'minwidth150')
68 {
69 // phpcs:enable
70 global $user, $conf, $langs;
71
72 $hideunselectables = false;
73 if (getDolGlobalString('CONTRACT_HIDE_UNSELECTABLES')) {
74 $hideunselectables = true;
75 }
76
77 $ret = '';
78
79 // Search all contacts
80 $sql = "SELECT c.rowid, c.ref, c.fk_soc, c.statut,";
81 $sql .= " c.ref_customer, c.ref_supplier";
82 $sql .= " FROM ".$this->db->prefix()."contrat as c";
83 $sql .= " WHERE c.entity = ".$conf->entity;
84 //if ($contratListId) $sql.= " AND c.rowid IN (".$this->db->sanitize($contratListId).")";
85 if ($socid > 0) {
86 // CONTRACT_ALLOW_TO_LINK_FROM_OTHER_COMPANY is 'all' or a list of ids separated by coma.
87 if (!getDolGlobalString('CONTRACT_ALLOW_TO_LINK_FROM_OTHER_COMPANY')) {
88 $sql .= " AND (c.fk_soc=".((int) $socid)." OR c.fk_soc IS NULL)";
89 } elseif (getDolGlobalString('CONTRACT_ALLOW_TO_LINK_FROM_OTHER_COMPANY') != 'all') {
90 $sql .= " AND (c.fk_soc IN (".$this->db->sanitize(((int) $socid).",".((int) $conf->global->CONTRACT_ALLOW_TO_LINK_FROM_OTHER_COMPANY)).")";
91 $sql .= " OR c.fk_soc IS NULL)";
92 }
93 }
94 if ($socid == 0) {
95 $sql .= " AND (c.fk_soc = 0 OR c.fk_soc IS NULL)";
96 }
97 $sql .= " ORDER BY c.ref ";
98
99 dol_syslog(get_class($this)."::select_contract", LOG_DEBUG);
100 $resql = $this->db->query($sql);
101 if ($resql) {
102 $ret .= '<select class="flat'.($morecss ? ' '.$morecss : '').'" name="'.$htmlname.'" id="'.$htmlname.'">';
103 if ($showempty) {
104 $ret .= '<option value="0">&nbsp;</option>';
105 }
106 $num = $this->db->num_rows($resql);
107 $i = 0;
108 if ($num) {
109 while ($i < $num) {
110 $obj = $this->db->fetch_object($resql);
111 // 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.
112 if ($socid > 0 && (empty($obj->fk_soc) || $obj->fk_soc == $socid) && !$user->hasRight('societe', 'lire')) {
113 // Do nothing
114 } else {
115 $labeltoshow = dol_trunc($obj->ref, 18);
116
117 if ($showRef) {
118 if ($obj->ref_customer) {
119 $labeltoshow = $labeltoshow." - ".$obj->ref_customer;
120 }
121 if ($obj->ref_supplier) {
122 $labeltoshow = $labeltoshow." - ".$obj->ref_supplier;
123 }
124 }
125
126 //if ($obj->public) $labeltoshow.=' ('.$langs->trans("SharedProject").')';
127 //else $labeltoshow.=' ('.$langs->trans("Private").')';
128 if (!empty($selected) && $selected == $obj->rowid && $obj->statut > 0) {
129 $ret .= '<option value="'.$obj->rowid.'" selected>'.$labeltoshow.'</option>';
130 } else {
131 $disabled = 0;
132 if ($obj->statut == 0) {
133 $disabled = 1;
134 $labeltoshow .= ' ('.$langs->trans("Draft").')';
135 }
136 if (!getDolGlobalString('CONTRACT_ALLOW_TO_LINK_FROM_OTHER_COMPANY') && $socid > 0 && (!empty($obj->fk_soc) && $obj->fk_soc != $socid)) {
137 $disabled = 1;
138 $labeltoshow .= ' - '.$langs->trans("LinkedToAnotherCompany");
139 }
140
141 if ($hideunselectables && $disabled) {
142 $resultat = '';
143 } else {
144 $resultat = '<option value="'.$obj->rowid.'"';
145 if ($disabled) {
146 $resultat .= ' disabled';
147 }
148 //if ($obj->public) $labeltoshow.=' ('.$langs->trans("Public").')';
149 //else $labeltoshow.=' ('.$langs->trans("Private").')';
150 $resultat .= '>'.$labeltoshow;
151 $resultat .= '</option>';
152 }
153 $ret .= $resultat;
154 }
155 }
156 $i++;
157 }
158 }
159 $ret .= '</select>';
160 $this->db->free($resql);
161
162 if (!empty($conf->use_javascript_ajax)) {
163 // Make select dynamic
164 include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
165 $ret .= ajax_combobox($htmlname);
166 }
167
168 if ($noouput) {
169 return $ret;
170 }
171
172 print $ret;
173
174 return $num;
175 } else {
176 dol_print_error($this->db);
177 return -1;
178 }
179 }
180
194 public function formSelectContract($page, $socid = -1, $selected = 0, $htmlname = 'contrattid', $maxlength = 16, $showempty = 1, $showRef = 0, $nooutput = 0)
195 {
196 global $langs;
197
198 $ret = '<form method="post" action="'.$page.'">';
199 $ret .= '<input type="hidden" name="action" value="setcontract">';
200 $ret .= '<input type="hidden" name="token" value="'.newToken().'">';
201 $ret .= $this->select_contract($socid, $selected, $htmlname, $maxlength, $showempty, $showRef, 1);
202 $ret .= '<input type="submit" class="button smallpaddingimp valignmiddle" value="'.$langs->trans("Modify").'">';
203 $ret .= '</form>';
204
205 if ($nooutput) {
206 return $ret;
207 }
208
209 print $ret;
210 }
211}
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:475
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.
__construct($db)
Constructor.
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.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79