dolibarr 23.0.3
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 * Copyright (C) 2025 Frédéric France <frederic.france@free.fr>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 * or see https://www.gnu.org/
19 */
20
31{
35 public $db;
36
40 public $error = '';
41
42
48 public function __construct($db)
49 {
50 $this->db = $db;
51 }
52
53
54 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
66 public function select_interventions($socid = -1, $selected = 0, $htmlname = 'interventionid', $maxlength = 16, $showempty = '1', $draftonly = false)
67 {
68 // phpcs:enable
69 global $user, $conf, $langs;
70
71 $out = '';
72
73 $hideunselectables = getDolGlobalInt('MAIN_SHOW_UNSELECTABLES_IN_SELECT_INTERVENTIONS');
74
75 // Search all contacts
76 $sql = "SELECT f.rowid, f.ref, f.fk_soc, f.fk_statut as status";
77 $sql .= " FROM ".$this->db->prefix()."fichinter as f";
78 $sql .= " WHERE f.entity = ".$conf->entity;
79 if ($socid >= 0) {
80 if ($socid == '0') {
81 $sql .= " AND (f.fk_soc = 0 OR f.fk_soc IS NULL)";
82 } else {
83 $sql .= " AND f.fk_soc = ".((int) $socid);
84 }
85 }
86 if ($draftonly) {
87 $sql .= " AND f.fk_statut = 0";
88 }
89
90 dol_syslog(get_class($this)."::select_interventions", LOG_DEBUG);
91 $resql = $this->db->query($sql);
92 if ($resql) {
93 $out .= '<select id="'.dol_escape_htmltag($htmlname).'" class="flat" name="'.dol_escape_htmltag($htmlname).'">';
94 if ($showempty) {
95 $out .= '<option value="0">';
96 if (!is_numeric($showempty)) {
97 $out .= $showempty;
98 } else {
99 $out .= '&nbsp;';
100 }
101 $out .= '</option>';
102 }
103 $num = $this->db->num_rows($resql);
104 $i = 0;
105 if ($num) {
106 while ($i < $num) {
107 $obj = $this->db->fetch_object($resql);
108 // 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.
109 if ($socid > 0 && (empty($obj->fk_soc) || $obj->fk_soc == $socid) && !$user->hasRight('societe', 'lire')) {
110 // Do nothing
111 } else {
112 $labeltoshow = dol_trunc($obj->ref, 18);
113 if (!empty($selected) && $selected == $obj->rowid && $obj->status > 0) {
114 $out .= '<option value="'.$obj->rowid.'" selected>'.$labeltoshow.'</option>';
115 } else {
116 $disabled = 0;
117 if (!$obj->status > 0 && ! $draftonly) {
118 $disabled = 1;
119 $labeltoshow .= ' ('.$langs->trans("Draft").')';
120 }
121 if ($socid > 0 && (!empty($obj->fk_soc) && $obj->fk_soc != $socid)) {
122 $disabled = 1;
123 $labeltoshow .= ' - '.$langs->trans("LinkedToAnotherCompany");
124 }
125
126 if ($hideunselectables && $disabled) {
127 $resultat = '';
128 } else {
129 $resultat = '<option value="'.$obj->rowid.'"';
130 if ($disabled) {
131 $resultat .= ' disabled';
132 }
133 $resultat .= '>'.$labeltoshow;
134 $resultat .= '</option>';
135 }
136 $out .= $resultat;
137 }
138 }
139 $i++;
140 }
141 }
142 $out .= '</select>';
143 $this->db->free($resql);
144 return $out;
145 } else {
146 dol_print_error($this->db);
147 return '';
148 }
149 }
150}
Class to manage generation of HTML components for intervention module.
select_interventions($socid=-1, $selected=0, $htmlname='interventionid', $maxlength=16, $showempty='1', $draftonly=false)
Show a combo list with interventions qualified for a third party.
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.
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...