dolibarr 22.0.5
html.formintervention.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2012-2013 Charles-Fr BENKE <charles.fr@benke.fr>
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
65 public function select_interventions($socid = -1, $selected = 0, $htmlname = 'interventionid', $maxlength = 16, $showempty = '1', $draftonly = false)
66 {
67 // phpcs:enable
68 global $user, $conf, $langs;
69
70 $out = '';
71
72 $hideunselectables = false;
73
74 // Search all contacts
75 $sql = "SELECT f.rowid, f.ref, f.fk_soc, f.fk_statut as status";
76 $sql .= " FROM ".$this->db->prefix()."fichinter as f";
77 $sql .= " WHERE f.entity = ".$conf->entity;
78 if ($socid >= 0) {
79 if ($socid == '0') {
80 $sql .= " AND (f.fk_soc = 0 OR f.fk_soc IS NULL)";
81 } else {
82 $sql .= " AND f.fk_soc = ".((int) $socid);
83 }
84 }
85 if ($draftonly) {
86 $sql .= " AND f.fk_statut = 0";
87 }
88
89 dol_syslog(get_class($this)."::select_intervention", LOG_DEBUG);
90 $resql = $this->db->query($sql);
91 if ($resql) {
92 $out .= '<select id="'.dol_escape_htmltag($htmlname).'" class="flat" name="'.dol_escape_htmltag($htmlname).'">';
93 if ($showempty) {
94 $out .= '<option value="0">';
95 if (!is_numeric($showempty)) {
96 $out .= $showempty;
97 } else {
98 $out .= '&nbsp;';
99 }
100 $out .= '</option>';
101 }
102 $num = $this->db->num_rows($resql);
103 $i = 0;
104 if ($num) {
105 while ($i < $num) {
106 $obj = $this->db->fetch_object($resql);
107 // 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.
108 if ($socid > 0 && (empty($obj->fk_soc) || $obj->fk_soc == $socid) && !$user->hasRight('societe', 'lire')) {
109 // Do nothing
110 } else {
111 $labeltoshow = dol_trunc($obj->ref, 18);
112 if (!empty($selected) && $selected == $obj->rowid && $obj->status > 0) {
113 $out .= '<option value="'.$obj->rowid.'" selected>'.$labeltoshow.'</option>';
114 } else {
115 $disabled = 0;
116 if (!$obj->status > 0 && ! $draftonly) {
117 $disabled = 1;
118 $labeltoshow .= ' ('.$langs->trans("Draft").')';
119 }
120 if ($socid > 0 && (!empty($obj->fk_soc) && $obj->fk_soc != $socid)) {
121 $disabled = 1;
122 $labeltoshow .= ' - '.$langs->trans("LinkedToAnotherCompany");
123 }
124
125 if ($hideunselectables && $disabled) {
126 $resultat = '';
127 } else {
128 $resultat = '<option value="'.$obj->rowid.'"';
129 if ($disabled) {
130 $resultat .= ' disabled';
131 }
132 $resultat .= '>'.$labeltoshow;
133 $resultat .= '</option>';
134 }
135 $out .= $resultat;
136 }
137 }
138 $i++;
139 }
140 }
141 $out .= '</select>';
142 $this->db->free($resql);
143 return $out;
144 } else {
145 dol_print_error($this->db);
146 return '';
147 }
148 }
149}
Class to manage generation of HTML components for contract module.
select_interventions($socid=-1, $selected=0, $htmlname='interventionid', $maxlength=16, $showempty='1', $draftonly=false)
Show a combo list with contracts qualified for a third party.
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.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79