dolibarr  9.0.0
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 <http://www.gnu.org/licenses/>.
16  * or see http://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.NotCamelCaps
63  function select_contract($socid=-1, $selected='', $htmlname='contrattid', $maxlength=16, $showempty=1)
64  {
65  // phpcs:enable
66  global $db,$user,$conf,$langs;
67 
68  $hideunselectables = false;
69  if (! empty($conf->global->CONTRACT_HIDE_UNSELECTABLES)) $hideunselectables = true;
70 
71  // Search all contacts
72  $sql = 'SELECT c.rowid, c.ref, c.fk_soc, c.statut';
73  $sql.= ' FROM '.MAIN_DB_PREFIX .'contrat as c';
74  $sql.= " WHERE c.entity = ".$conf->entity;
75  //if ($contratListId) $sql.= " AND c.rowid IN (".$contratListId.")";
76  if ($socid > 0)
77  {
78  // CONTRACT_ALLOW_TO_LINK_FROM_OTHER_COMPANY is 'all' or a list of ids separated by coma.
79  if (empty($conf->global->CONTRACT_ALLOW_TO_LINK_FROM_OTHER_COMPANY))
80  $sql.= " AND (c.fk_soc=".$socid." OR c.fk_soc IS NULL)";
81  else if ($conf->global->CONTRACT_ALLOW_TO_LINK_FROM_OTHER_COMPANY != 'all')
82  {
83  $sql.= " AND (c.fk_soc IN (".$socid.", ".$conf->global->CONTRACT_ALLOW_TO_LINK_FROM_OTHER_COMPANY.") ";
84  $sql.= " OR c.fk_soc IS NULL)";
85  }
86  }
87  if ($socid == 0) $sql.= " AND (c.fk_soc = 0 OR c.fk_soc IS NULL)";
88  $sql.= " ORDER BY c.ref ";
89 
90  dol_syslog(get_class($this)."::select_contract", LOG_DEBUG);
91  $resql=$db->query($sql);
92  if ($resql)
93  {
94  print '<select class="flat" name="'.$htmlname.'">';
95  if ($showempty) print '<option value="0">&nbsp;</option>';
96  $num = $db->num_rows($resql);
97  $i = 0;
98  if ($num)
99  {
100  while ($i < $num)
101  {
102  $obj = $db->fetch_object($resql);
103  // 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.
104  if ($socid > 0 && (empty($obj->fk_soc) || $obj->fk_soc == $socid) && ! $user->rights->societe->lire)
105  {
106  // Do nothing
107  }
108  else
109  {
110  $labeltoshow=dol_trunc($obj->ref,18);
111  //if ($obj->public) $labeltoshow.=' ('.$langs->trans("SharedProject").')';
112  //else $labeltoshow.=' ('.$langs->trans("Private").')';
113  if (!empty($selected) && $selected == $obj->rowid && $obj->statut > 0)
114  {
115  print '<option value="'.$obj->rowid.'" selected>'.$labeltoshow.'</option>';
116  }
117  else
118  {
119  $disabled=0;
120  if ( $obj->statut == 0)
121  {
122  $disabled=1;
123  $labeltoshow.=' ('.$langs->trans("Draft").')';
124  }
125  if ( empty($conf->global->CONTRACT_ALLOW_TO_LINK_FROM_OTHER_COMPANY) && $socid > 0 && (! empty($obj->fk_soc) && $obj->fk_soc != $socid))
126  {
127  $disabled=1;
128  $labeltoshow.=' - '.$langs->trans("LinkedToAnotherCompany");
129  }
130 
131  if ($hideunselectables && $disabled)
132  {
133  $resultat='';
134  }
135  else
136  {
137  $resultat='<option value="'.$obj->rowid.'"';
138  if ($disabled) $resultat.=' disabled';
139  //if ($obj->public) $labeltoshow.=' ('.$langs->trans("Public").')';
140  //else $labeltoshow.=' ('.$langs->trans("Private").')';
141  $resultat.='>'.$labeltoshow;
142  $resultat.='</option>';
143  }
144  print $resultat;
145  }
146  }
147  $i++;
148  }
149  }
150  print '</select>';
151  $db->free($resql);
152 
153  if (!empty($conf->use_javascript_ajax))
154  {
155  // Make select dynamic
156  include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
157  print ajax_combobox($htmlname);
158  }
159 
160  return $num;
161  }
162  else
163  {
164  dol_print_error($db);
165  return -1;
166  }
167  }
168 
180  function formSelectContract($page, $socid=-1, $selected='', $htmlname='contrattid', $maxlength=16, $showempty=1)
181  {
182  global $langs;
183 
184  print "\n";
185  print '<form method="post" action="'.$page.'">';
186  print '<input type="hidden" name="action" value="setcontract">';
187  print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
188  $this->select_contract($socid, $selected, $htmlname, $maxlength, $showempty);
189  print '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
190  print '</form>';
191  }
192 }
ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete='resolve')
Convert a html select field into an ajax combobox.
Definition: ajax.lib.php:374
print
Draft customers invoices.
Definition: index.php:91
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding &#39;...&#39; if string larger than length.
if(! empty($conf->facture->enabled) && $user->rights->facture->lire) if(! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture->lire) if(! empty($conf->don->enabled) && $user->rights->societe->lire) if(! empty($conf->tax->enabled) && $user->rights->tax->charges->lire) if(! empty($conf->facture->enabled) &&! empty($conf->commande->enabled) && $user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(! empty($conf->facture->enabled) && $user->rights->facture->lire) if(! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1053
select_contract($socid=-1, $selected='', $htmlname='contrattid', $maxlength=16, $showempty=1)
Show a combo list with contracts qualified for a third party.
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='')
Write log message into outputs.
__construct($db)
Constructor.
Class to manage generation of HTML components for contract module.
formSelectContract($page, $socid=-1, $selected='', $htmlname='contrattid', $maxlength=16, $showempty=1)
Show a form to select a contract.