dolibarr/htdocs/core/class/html.formintervention.class.php

150 lines
4.5 KiB
PHP
Raw Normal View History

2014-09-15 16:18:19 +02:00
<?php
/* Copyright (C) 2012-2013 Charles-Fr BENKE <charles.fr@benke.fr>
2025-02-11 02:12:49 +01:00
* Copyright (C) 2025 MDW <mdeweerd@users.noreply.github.com>
2014-09-15 16:18:19 +02:00
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
2019-09-23 21:55:30 +02:00
* along with this program. If not, see <https://www.gnu.org/licenses/>.
* or see https://www.gnu.org/
2014-09-15 16:18:19 +02:00
*/
/**
* \file htdocs/core/class/html.formintervention.class.php
* \ingroup core
* \brief File of class with all html predefined components
*/
/**
* Class to manage generation of HTML components for contract module
*/
class FormIntervention
{
/**
* @var DoliDB Database handler.
*/
public $db;
2018-09-05 20:36:44 +02:00
/**
2018-08-22 10:37:16 +02:00
* @var string Error code (or message)
*/
public $error = '';
2014-09-15 16:18:19 +02:00
/**
* Constructor
*
* @param DoliDB $db Database handler
*/
public function __construct($db)
{
$this->db = $db;
}
2014-09-15 16:18:19 +02:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2014-09-15 16:18:19 +02:00
/**
* Show a combo list with contracts qualified for a third party
*
* @param int $socid Id third party (-1=all, 0=only interventions not linked to a third party, id=intervention not linked or linked to third party id)
* @param int $selected Id intervention preselected
* @param string $htmlname Nom de la zone html
* @param int $maxlength Maximum length of label
2025-02-11 02:12:49 +01:00
* @param string $showempty Show empty line ('1' or string to show for empty line)
* @param bool $draftonly Show only drafts intervention
* @return string HTML code for the select list if OK, empty if KO
2014-09-15 16:18:19 +02:00
*/
2025-02-11 02:12:49 +01:00
public function select_interventions($socid = -1, $selected = 0, $htmlname = 'interventionid', $maxlength = 16, $showempty = '1', $draftonly = false)
2014-09-15 16:18:19 +02:00
{
// phpcs:enable
global $user, $conf, $langs;
2014-09-15 16:18:19 +02:00
$out = '';
2014-09-15 16:18:19 +02:00
$hideunselectables = false;
2014-09-15 16:18:19 +02:00
// Search all contacts
2024-11-19 12:21:29 +01:00
$sql = "SELECT f.rowid, f.ref, f.fk_soc, f.fk_statut as status";
$sql .= " FROM ".$this->db->prefix()."fichinter as f";
$sql .= " WHERE f.entity = ".$conf->entity;
if ($socid >= 0) {
2021-02-23 22:03:23 +01:00
if ($socid == '0') {
$sql .= " AND (f.fk_soc = 0 OR f.fk_soc IS NULL)";
} else {
2021-06-09 15:36:47 +02:00
$sql .= " AND f.fk_soc = ".((int) $socid);
2021-02-23 22:03:23 +01:00
}
2014-09-15 16:18:19 +02:00
}
2023-12-04 12:04:36 +01:00
if ($draftonly) {
$sql .= " AND f.fk_statut = 0";
}
2014-09-15 16:18:19 +02:00
dol_syslog(get_class($this)."::select_intervention", LOG_DEBUG);
2020-09-19 23:30:29 +02:00
$resql = $this->db->query($sql);
2021-02-23 22:03:23 +01:00
if ($resql) {
$out .= '<select id="'.dol_escape_htmltag($htmlname).'" class="flat" name="'.dol_escape_htmltag($htmlname).'">';
2021-02-23 22:03:23 +01:00
if ($showempty) {
2021-06-30 10:56:09 +02:00
$out .= '<option value="0">';
2023-12-04 12:04:36 +01:00
if (!is_numeric($showempty)) {
$out .= $showempty;
} else {
$out .= '&nbsp;';
}
2021-06-30 10:56:09 +02:00
$out .= '</option>';
2021-02-23 22:03:23 +01:00
}
2020-09-19 23:30:29 +02:00
$num = $this->db->num_rows($resql);
2014-09-15 16:18:19 +02:00
$i = 0;
2021-02-23 22:03:23 +01:00
if ($num) {
while ($i < $num) {
2020-09-19 23:30:29 +02:00
$obj = $this->db->fetch_object($resql);
2014-09-15 16:18:19 +02:00
// 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.
2022-09-10 11:14:25 +02:00
if ($socid > 0 && (empty($obj->fk_soc) || $obj->fk_soc == $socid) && !$user->hasRight('societe', 'lire')) {
2014-09-15 16:18:19 +02:00
// Do nothing
2020-05-21 15:05:19 +02:00
} else {
$labeltoshow = dol_trunc($obj->ref, 18);
2024-11-19 12:21:29 +01:00
if (!empty($selected) && $selected == $obj->rowid && $obj->status > 0) {
$out .= '<option value="'.$obj->rowid.'" selected>'.$labeltoshow.'</option>';
2020-05-21 15:05:19 +02:00
} else {
$disabled = 0;
2024-11-19 12:21:29 +01:00
if (!$obj->status > 0 && ! $draftonly) {
$disabled = 1;
$labeltoshow .= ' ('.$langs->trans("Draft").')';
2014-09-15 16:18:19 +02:00
}
2021-02-23 22:03:23 +01:00
if ($socid > 0 && (!empty($obj->fk_soc) && $obj->fk_soc != $socid)) {
$disabled = 1;
$labeltoshow .= ' - '.$langs->trans("LinkedToAnotherCompany");
2014-09-15 16:18:19 +02:00
}
2021-02-23 22:03:23 +01:00
if ($hideunselectables && $disabled) {
$resultat = '';
2020-05-21 15:05:19 +02:00
} else {
$resultat = '<option value="'.$obj->rowid.'"';
2021-02-23 22:03:23 +01:00
if ($disabled) {
$resultat .= ' disabled';
}
$resultat .= '>'.$labeltoshow;
$resultat .= '</option>';
2014-09-15 16:18:19 +02:00
}
$out .= $resultat;
2014-09-15 16:18:19 +02:00
}
}
$i++;
}
}
$out .= '</select>';
2020-09-19 23:30:29 +02:00
$this->db->free($resql);
2014-09-15 16:18:19 +02:00
return $out;
2020-05-21 15:05:19 +02:00
} else {
2020-09-19 23:30:29 +02:00
dol_print_error($this->db);
2014-09-15 16:18:19 +02:00
return '';
}
}
}