67 public function select_contract($socid = -1, $selected = 0, $htmlname =
'contrattid', $maxlength = 16, $showempty = 1, $showRef = 0, $noouput = 0, $morecss =
'minwidth150')
70 global $user, $conf, $langs;
72 $hideunselectables =
false;
74 $hideunselectables =
true;
80 $sql =
"SELECT c.rowid, c.ref, c.fk_soc, c.statut,";
81 $sql .=
" c.ref_customer, c.ref_supplier";
82 $sql .=
" FROM ".$this->db->prefix().
"contrat as c";
83 $sql .=
" WHERE c.entity = ".$conf->entity;
88 $sql .=
" AND (c.fk_soc=".((int) $socid).
" OR c.fk_soc IS NULL)";
90 $sql .=
" AND (c.fk_soc IN (".$this->db->sanitize(((
int) $socid).
",".((
int) $conf->global->CONTRACT_ALLOW_TO_LINK_FROM_OTHER_COMPANY)).
")";
91 $sql .=
" OR c.fk_soc IS NULL)";
95 $sql .=
" AND (c.fk_soc = 0 OR c.fk_soc IS NULL)";
97 $sql .=
" ORDER BY c.ref ";
99 dol_syslog(get_class($this).
"::select_contract", LOG_DEBUG);
100 $resql = $this->db->query($sql);
102 $ret .=
'<select class="flat'.($morecss ?
' '.$morecss :
'').
'" name="'.$htmlname.
'" id="'.$htmlname.
'">';
104 $ret .=
'<option value="0"> </option>';
106 $num = $this->db->num_rows($resql);
110 $obj = $this->db->fetch_object($resql);
112 if ($socid > 0 && (empty($obj->fk_soc) || $obj->fk_soc == $socid) && !$user->hasRight(
'societe',
'lire')) {
118 if ($obj->ref_customer) {
119 $labeltoshow = $labeltoshow.
" - ".$obj->ref_customer;
121 if ($obj->ref_supplier) {
122 $labeltoshow = $labeltoshow.
" - ".$obj->ref_supplier;
128 if (!empty($selected) && $selected == $obj->rowid && $obj->statut > 0) {
129 $ret .=
'<option value="'.$obj->rowid.
'" selected>'.$labeltoshow.
'</option>';
132 if ($obj->statut == 0) {
134 $labeltoshow .=
' ('.$langs->trans(
"Draft").
')';
136 if (!
getDolGlobalString(
'CONTRACT_ALLOW_TO_LINK_FROM_OTHER_COMPANY') && $socid > 0 && (!empty($obj->fk_soc) && $obj->fk_soc != $socid)) {
138 $labeltoshow .=
' - '.$langs->trans(
"LinkedToAnotherCompany");
141 if ($hideunselectables && $disabled) {
144 $resultat =
'<option value="'.$obj->rowid.
'"';
146 $resultat .=
' disabled';
150 $resultat .=
'>'.$labeltoshow;
151 $resultat .=
'</option>';
160 $this->db->free($resql);
162 if (!empty($conf->use_javascript_ajax)) {
164 include_once DOL_DOCUMENT_ROOT.
'/core/lib/ajax.lib.php';
194 public function formSelectContract($page, $socid = -1, $selected = 0, $htmlname =
'contrattid', $maxlength = 16, $showempty = 1, $showRef = 0, $nooutput = 0)
198 $ret =
'<form method="post" action="'.$page.
'">';
199 $ret .=
'<input type="hidden" name="action" value="setcontract">';
200 $ret .=
'<input type="hidden" name="token" value="'.newToken().
'">';
201 $ret .= $this->
select_contract($socid, $selected, $htmlname, $maxlength, $showempty, $showRef, 1);
202 $ret .=
'<input type="submit" class="button smallpaddingimp valignmiddle" value="'.$langs->trans(
"Modify").
'">';
ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete='resolve', $idforemptyvalue='-1', $morecss='')
Convert a html select field into an ajax combobox.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.