dolibarr  7.0.0-beta
html.formcontract.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 <http://www.gnu.org/licenses/>.
16  * or see http://www.gnu.org/
17  */
18 
29 {
30  var $db;
31  var $error;
32 
33 
39  public function __construct($db)
40  {
41  $this->db = $db;
42  }
43 
44 
55  function select_contract($socid=-1, $selected='', $htmlname='contrattid', $maxlength=16, $showempty=1)
56  {
57  global $db,$user,$conf,$langs;
58 
59  $hideunselectables = false;
60  if (! empty($conf->global->PROJECT_HIDE_UNSELECTABLES)) $hideunselectables = true;
61 
62  // Search all contacts
63  $sql = 'SELECT c.rowid, c.ref, c.fk_soc, c.statut';
64  $sql.= ' FROM '.MAIN_DB_PREFIX .'contrat as c';
65  $sql.= " WHERE c.entity = ".$conf->entity;
66  //if ($contratListId) $sql.= " AND c.rowid IN (".$contratListId.")";
67  if ($socid == 0) $sql.= " AND (c.fk_soc = 0 OR c.fk_soc IS NULL)";
68  if ($socid > 0) $sql.= " AND (c.fk_soc=".$socid." OR c.fk_soc IS NULL)";
69  $sql.= " ORDER BY c.ref ";
70 
71  dol_syslog(get_class($this)."::select_contract", LOG_DEBUG);
72  $resql=$db->query($sql);
73  if ($resql)
74  {
75  print '<select class="flat" name="'.$htmlname.'">';
76  if ($showempty) print '<option value="0">&nbsp;</option>';
77  $num = $db->num_rows($resql);
78  $i = 0;
79  if ($num)
80  {
81  while ($i < $num)
82  {
83  $obj = $db->fetch_object($resql);
84  // 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.
85  if ($socid > 0 && (empty($obj->fk_soc) || $obj->fk_soc == $socid) && ! $user->rights->societe->lire)
86  {
87  // Do nothing
88  }
89  else
90  {
91  $labeltoshow=dol_trunc($obj->ref,18);
92  //if ($obj->public) $labeltoshow.=' ('.$langs->trans("SharedProject").')';
93  //else $labeltoshow.=' ('.$langs->trans("Private").')';
94  if (!empty($selected) && $selected == $obj->rowid && $obj->statut > 0)
95  {
96  print '<option value="'.$obj->rowid.'" selected>'.$labeltoshow.'</option>';
97  }
98  else
99  {
100  $disabled=0;
101  if (! $obj->statut > 0)
102  {
103  $disabled=1;
104  $labeltoshow.=' ('.$langs->trans("Draft").')';
105  }
106  if ($socid > 0 && (! empty($obj->fk_soc) && $obj->fk_soc != $socid))
107  {
108  $disabled=1;
109  $labeltoshow.=' - '.$langs->trans("LinkedToAnotherCompany");
110  }
111 
112  if ($hideunselectables && $disabled)
113  {
114  $resultat='';
115  }
116  else
117  {
118  $resultat='<option value="'.$obj->rowid.'"';
119  if ($disabled) $resultat.=' disabled';
120  //if ($obj->public) $labeltoshow.=' ('.$langs->trans("Public").')';
121  //else $labeltoshow.=' ('.$langs->trans("Private").')';
122  $resultat.='>'.$labeltoshow;
123  $resultat.='</option>';
124  }
125  print $resultat;
126  }
127  }
128  $i++;
129  }
130  }
131  print '</select>';
132  $db->free($resql);
133 
134  if (!empty($conf->use_javascript_ajax))
135  {
136  // Make select dynamic
137  include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
138  print ajax_combobox($htmlname);
139  }
140 
141  return $num;
142  }
143  else
144  {
145  dol_print_error($db);
146  return -1;
147  }
148  }
149 
161  function formSelectContract($page, $socid=-1, $selected='', $htmlname='contrattid', $maxlength=16, $showempty=1)
162  {
163  global $langs;
164 
165  print "\n";
166  print '<form method="post" action="'.$page.'">';
167  print '<input type="hidden" name="action" value="setcontract">';
168  print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
169  $this->select_contract($socid, $selected, $htmlname, $maxlength, $showempty);
170  print '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
171  print '</form>';
172  }
173 
174 }
ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete='resolve')
Convert a html select field into an ajax combobox.
Definition: ajax.lib.php:392
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.
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.
print
Draft customers invoices.
Definition: index.php:91
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:1013
formSelectContract($page, $socid=-1, $selected='', $htmlname='contrattid', $maxlength=16, $showempty=1)
Show a form to select a contract.