dolibarr  17.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  *
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
64  public function select_interventions($socid = -1, $selected = '', $htmlname = 'interventionid', $maxlength = 16, $showempty = 1, $draftonly = false)
65  {
66  // phpcs:enable
67  global $user, $conf, $langs;
68 
69  $out = '';
70 
71  $hideunselectables = false;
72 
73  // Search all contacts
74  $sql = "SELECT f.rowid, f.ref, f.fk_soc, f.fk_statut";
75  $sql .= " FROM ".$this->db->prefix()."fichinter as f";
76  $sql .= " WHERE f.entity = ".$conf->entity;
77  if ($socid != '') {
78  if ($socid == '0') {
79  $sql .= " AND (f.fk_soc = 0 OR f.fk_soc IS NULL)";
80  } else {
81  $sql .= " AND f.fk_soc = ".((int) $socid);
82  }
83  }
84  if ($draftonly) $sql .= " AND f.fk_statut = 0";
85 
86  dol_syslog(get_class($this)."::select_intervention", LOG_DEBUG);
87  $resql = $this->db->query($sql);
88  if ($resql) {
89  $out .= '<select id="interventionid" class="flat" name="'.dol_escape_htmltag($htmlname).'">';
90  if ($showempty) {
91  $out .= '<option value="0">';
92  if (!is_numeric($showempty)) $out .= $showempty;
93  else $out .= '&nbsp;';
94  $out .= '</option>';
95  }
96  $num = $this->db->num_rows($resql);
97  $i = 0;
98  if ($num) {
99  while ($i < $num) {
100  $obj = $this->db->fetch_object($resql);
101  // 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.
102  if ($socid > 0 && (empty($obj->fk_soc) || $obj->fk_soc == $socid) && !$user->hasRight('societe', 'lire')) {
103  // Do nothing
104  } else {
105  $labeltoshow = dol_trunc($obj->ref, 18);
106  if (!empty($selected) && $selected == $obj->rowid && $obj->statut > 0) {
107  $out .= '<option value="'.$obj->rowid.'" selected>'.$labeltoshow.'</option>';
108  } else {
109  $disabled = 0;
110  if (!$obj->fk_statut > 0 && ! $draftonly) {
111  $disabled = 1;
112  $labeltoshow .= ' ('.$langs->trans("Draft").')';
113  }
114  if ($socid > 0 && (!empty($obj->fk_soc) && $obj->fk_soc != $socid)) {
115  $disabled = 1;
116  $labeltoshow .= ' - '.$langs->trans("LinkedToAnotherCompany");
117  }
118 
119  if ($hideunselectables && $disabled) {
120  $resultat = '';
121  } else {
122  $resultat = '<option value="'.$obj->rowid.'"';
123  if ($disabled) {
124  $resultat .= ' disabled';
125  }
126  $resultat .= '>'.$labeltoshow;
127  $resultat .= '</option>';
128  }
129  $out .= $resultat;
130  }
131  }
132  $i++;
133  }
134  }
135  $out .= '</select>';
136  $this->db->free($resql);
137  return $out;
138  } else {
139  dol_print_error($this->db);
140  return '';
141  }
142  }
143 }
FormIntervention\select_interventions
select_interventions($socid=-1, $selected='', $htmlname='interventionid', $maxlength=16, $showempty=1, $draftonly=false)
Show a combo list with contracts qualified for a third party.
Definition: html.formintervention.class.php:64
db
$conf db
API class for accounts.
Definition: inc.php:41
dol_trunc
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.
Definition: functions.lib.php:3949
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4993
FormIntervention
Class to manage generation of HTML components for contract module.
Definition: html.formintervention.class.php:28
FormIntervention\__construct
__construct($db)
Constructor.
Definition: html.formintervention.class.php:46
$resql
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:745
dol_syslog
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
Definition: functions.lib.php:1628