dolibarr  17.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
64  public function select_contract($socid = -1, $selected = '', $htmlname = 'contrattid', $maxlength = 16, $showempty = 1, $showRef = 0)
65  {
66  // phpcs:enable
67  global $user, $conf, $langs;
68 
69  $hideunselectables = false;
70  if (!empty($conf->global->CONTRACT_HIDE_UNSELECTABLES)) {
71  $hideunselectables = true;
72  }
73 
74  // Search all contacts
75  $sql = "SELECT c.rowid, c.ref, c.fk_soc, c.statut,";
76  $sql .= " c.ref_customer, c.ref_supplier";
77  $sql .= " FROM ".$this->db->prefix()."contrat as c";
78  $sql .= " WHERE c.entity = ".$conf->entity;
79  //if ($contratListId) $sql.= " AND c.rowid IN (".$this->db->sanitize($contratListId).")";
80  if ($socid > 0) {
81  // CONTRACT_ALLOW_TO_LINK_FROM_OTHER_COMPANY is 'all' or a list of ids separated by coma.
82  if (empty($conf->global->CONTRACT_ALLOW_TO_LINK_FROM_OTHER_COMPANY)) {
83  $sql .= " AND (c.fk_soc=".((int) $socid)." OR c.fk_soc IS NULL)";
84  } elseif ($conf->global->CONTRACT_ALLOW_TO_LINK_FROM_OTHER_COMPANY != 'all') {
85  $sql .= " AND (c.fk_soc IN (".$this->db->sanitize(((int) $socid).",".((int) $conf->global->CONTRACT_ALLOW_TO_LINK_FROM_OTHER_COMPANY)).")";
86  $sql .= " OR c.fk_soc IS NULL)";
87  }
88  }
89  if ($socid == 0) {
90  $sql .= " AND (c.fk_soc = 0 OR c.fk_soc IS NULL)";
91  }
92  $sql .= " ORDER BY c.ref ";
93 
94  dol_syslog(get_class($this)."::select_contract", LOG_DEBUG);
95  $resql = $this->db->query($sql);
96  if ($resql) {
97  print '<select class="flat" name="'.$htmlname.'">';
98  if ($showempty) {
99  print '<option value="0">&nbsp;</option>';
100  }
101  $num = $this->db->num_rows($resql);
102  $i = 0;
103  if ($num) {
104  while ($i < $num) {
105  $obj = $this->db->fetch_object($resql);
106  // 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.
107  if ($socid > 0 && (empty($obj->fk_soc) || $obj->fk_soc == $socid) && !$user->hasRight('societe', 'lire')) {
108  // Do nothing
109  } else {
110  $labeltoshow = dol_trunc($obj->ref, 18);
111 
112  if ($showRef) {
113  if ($obj->ref_customer) {
114  $labeltoshow = $labeltoshow." - ".$obj->ref_customer;
115  }
116  if ($obj->ref_supplier) {
117  $labeltoshow = $labeltoshow." - ".$obj->ref_supplier;
118  }
119  }
120 
121  //if ($obj->public) $labeltoshow.=' ('.$langs->trans("SharedProject").')';
122  //else $labeltoshow.=' ('.$langs->trans("Private").')';
123  if (!empty($selected) && $selected == $obj->rowid && $obj->statut > 0) {
124  print '<option value="'.$obj->rowid.'" selected>'.$labeltoshow.'</option>';
125  } else {
126  $disabled = 0;
127  if ($obj->statut == 0) {
128  $disabled = 1;
129  $labeltoshow .= ' ('.$langs->trans("Draft").')';
130  }
131  if (empty($conf->global->CONTRACT_ALLOW_TO_LINK_FROM_OTHER_COMPANY) && $socid > 0 && (!empty($obj->fk_soc) && $obj->fk_soc != $socid)) {
132  $disabled = 1;
133  $labeltoshow .= ' - '.$langs->trans("LinkedToAnotherCompany");
134  }
135 
136  if ($hideunselectables && $disabled) {
137  $resultat = '';
138  } else {
139  $resultat = '<option value="'.$obj->rowid.'"';
140  if ($disabled) {
141  $resultat .= ' disabled';
142  }
143  //if ($obj->public) $labeltoshow.=' ('.$langs->trans("Public").')';
144  //else $labeltoshow.=' ('.$langs->trans("Private").')';
145  $resultat .= '>'.$labeltoshow;
146  $resultat .= '</option>';
147  }
148  print $resultat;
149  }
150  }
151  $i++;
152  }
153  }
154  print '</select>';
155  $this->db->free($resql);
156 
157  if (!empty($conf->use_javascript_ajax)) {
158  // Make select dynamic
159  include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
160  print ajax_combobox($htmlname);
161  }
162 
163  return $num;
164  } else {
165  dol_print_error($this->db);
166  return -1;
167  }
168  }
169 
182  public function formSelectContract($page, $socid = -1, $selected = '', $htmlname = 'contrattid', $maxlength = 16, $showempty = 1, $showRef = 0)
183  {
184  global $langs;
185 
186  print "\n";
187  print '<form method="post" action="'.$page.'">';
188  print '<input type="hidden" name="action" value="setcontract">';
189  print '<input type="hidden" name="token" value="'.newToken().'">';
190  $this->select_contract($socid, $selected, $htmlname, $maxlength, $showempty, $showRef);
191  print '<input type="submit" class="button smallpaddingimp valignmiddle" value="'.$langs->trans("Modify").'">';
192  print '</form>';
193  }
194 }
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
FormContract
Class to manage generation of HTML components for contract module.
Definition: html.formcontract.class.php:28
FormContract\formSelectContract
formSelectContract($page, $socid=-1, $selected='', $htmlname='contrattid', $maxlength=16, $showempty=1, $showRef=0)
Show a form to select a contract.
Definition: html.formcontract.class.php:182
$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
FormContract\__construct
__construct($db)
Constructor.
Definition: html.formcontract.class.php:46
FormContract\select_contract
select_contract($socid=-1, $selected='', $htmlname='contrattid', $maxlength=16, $showempty=1, $showRef=0)
Show a combo list with contracts qualified for a third party.
Definition: html.formcontract.class.php:64
ajax_combobox
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:449