dolibarr 19.0.3
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 *
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 <https://www.gnu.org/licenses/>.
16 * or see https://www.gnu.org/
17 */
18
29{
33 public $db;
34
38 public $error = '';
39
40
46 public function __construct($db)
47 {
48 $this->db = $db;
49 }
50
51
52 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
66 public function select_contract($socid = -1, $selected = '', $htmlname = 'contrattid', $maxlength = 16, $showempty = 1, $showRef = 0, $noouput = 0, $morecss = 'minwidth150')
67 {
68 // phpcs:enable
69 global $user, $conf, $langs;
70
71 $hideunselectables = false;
72 if (getDolGlobalString('CONTRACT_HIDE_UNSELECTABLES')) {
73 $hideunselectables = true;
74 }
75
76 $ret = '';
77
78 // Search all contacts
79 $sql = "SELECT c.rowid, c.ref, c.fk_soc, c.statut,";
80 $sql .= " c.ref_customer, c.ref_supplier";
81 $sql .= " FROM ".$this->db->prefix()."contrat as c";
82 $sql .= " WHERE c.entity = ".$conf->entity;
83 //if ($contratListId) $sql.= " AND c.rowid IN (".$this->db->sanitize($contratListId).")";
84 if ($socid > 0) {
85 // CONTRACT_ALLOW_TO_LINK_FROM_OTHER_COMPANY is 'all' or a list of ids separated by coma.
86 if (!getDolGlobalString('CONTRACT_ALLOW_TO_LINK_FROM_OTHER_COMPANY')) {
87 $sql .= " AND (c.fk_soc=".((int) $socid)." OR c.fk_soc IS NULL)";
88 } elseif (getDolGlobalString('CONTRACT_ALLOW_TO_LINK_FROM_OTHER_COMPANY') != 'all') {
89 $sql .= " AND (c.fk_soc IN (".$this->db->sanitize(((int) $socid).",".((int) $conf->global->CONTRACT_ALLOW_TO_LINK_FROM_OTHER_COMPANY)).")";
90 $sql .= " OR c.fk_soc IS NULL)";
91 }
92 }
93 if ($socid == 0) {
94 $sql .= " AND (c.fk_soc = 0 OR c.fk_soc IS NULL)";
95 }
96 $sql .= " ORDER BY c.ref ";
97
98 dol_syslog(get_class($this)."::select_contract", LOG_DEBUG);
99 $resql = $this->db->query($sql);
100 if ($resql) {
101 $ret .= '<select class="flat'.($morecss ? ' '.$morecss : '').'" name="'.$htmlname.'">';
102 if ($showempty) {
103 $ret .= '<option value="0">&nbsp;</option>';
104 }
105 $num = $this->db->num_rows($resql);
106 $i = 0;
107 if ($num) {
108 while ($i < $num) {
109 $obj = $this->db->fetch_object($resql);
110 // 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.
111 if ($socid > 0 && (empty($obj->fk_soc) || $obj->fk_soc == $socid) && !$user->hasRight('societe', 'lire')) {
112 // Do nothing
113 } else {
114 $labeltoshow = dol_trunc($obj->ref, 18);
115
116 if ($showRef) {
117 if ($obj->ref_customer) {
118 $labeltoshow = $labeltoshow." - ".$obj->ref_customer;
119 }
120 if ($obj->ref_supplier) {
121 $labeltoshow = $labeltoshow." - ".$obj->ref_supplier;
122 }
123 }
124
125 //if ($obj->public) $labeltoshow.=' ('.$langs->trans("SharedProject").')';
126 //else $labeltoshow.=' ('.$langs->trans("Private").')';
127 if (!empty($selected) && $selected == $obj->rowid && $obj->statut > 0) {
128 $ret .= '<option value="'.$obj->rowid.'" selected>'.$labeltoshow.'</option>';
129 } else {
130 $disabled = 0;
131 if ($obj->statut == 0) {
132 $disabled = 1;
133 $labeltoshow .= ' ('.$langs->trans("Draft").')';
134 }
135 if (!getDolGlobalString('CONTRACT_ALLOW_TO_LINK_FROM_OTHER_COMPANY') && $socid > 0 && (!empty($obj->fk_soc) && $obj->fk_soc != $socid)) {
136 $disabled = 1;
137 $labeltoshow .= ' - '.$langs->trans("LinkedToAnotherCompany");
138 }
139
140 if ($hideunselectables && $disabled) {
141 $resultat = '';
142 } else {
143 $resultat = '<option value="'.$obj->rowid.'"';
144 if ($disabled) {
145 $resultat .= ' disabled';
146 }
147 //if ($obj->public) $labeltoshow.=' ('.$langs->trans("Public").')';
148 //else $labeltoshow.=' ('.$langs->trans("Private").')';
149 $resultat .= '>'.$labeltoshow;
150 $resultat .= '</option>';
151 }
152 $ret .= $resultat;
153 }
154 }
155 $i++;
156 }
157 }
158 $ret .= '</select>';
159 $this->db->free($resql);
160
161 if (!empty($conf->use_javascript_ajax)) {
162 // Make select dynamic
163 include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
164 $ret .= ajax_combobox($htmlname);
165 }
166
167 if ($noouput) {
168 return $ret;
169 }
170
171 print $ret;
172
173 return $num;
174 } else {
175 dol_print_error($this->db);
176 return -1;
177 }
178 }
179
193 public function formSelectContract($page, $socid = -1, $selected = '', $htmlname = 'contrattid', $maxlength = 16, $showempty = 1, $showRef = 0, $noouput = 0)
194 {
195 global $langs;
196
197 $ret = '<form method="post" action="'.$page.'">';
198 $ret .= '<input type="hidden" name="action" value="setcontract">';
199 $ret .= '<input type="hidden" name="token" value="'.newToken().'">';
200 $ret .= $this->select_contract($socid, $selected, $htmlname, $maxlength, $showempty, $showRef, 1);
201 $ret .= '<input type="submit" class="button smallpaddingimp valignmiddle" value="'.$langs->trans("Modify").'">';
202 $ret .= '</form>';
203
204 if ($noouput) {
205 return $ret;
206 }
207
208 print $ret;
209 }
210}
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:447
Class to manage generation of HTML components for contract module.
select_contract($socid=-1, $selected='', $htmlname='contrattid', $maxlength=16, $showempty=1, $showRef=0, $noouput=0, $morecss='minwidth150')
Show a combo list with contracts qualified for a third party.
formSelectContract($page, $socid=-1, $selected='', $htmlname='contrattid', $maxlength=16, $showempty=1, $showRef=0, $noouput=0)
Show a form to select a contract.
__construct($db)
Constructor.
dol_print_error($db='', $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 dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.