66 public function select_contract($socid = -1, $selected = 0, $htmlname =
'contrattid', $maxlength = 16, $showempty = 1, $showRef = 0, $noouput = 0, $morecss =
'minwidth150')
69 global $user,
$conf, $langs;
71 $hideunselectables =
false;
73 $hideunselectables =
true;
79 $sql =
"SELECT c.rowid, c.ref, c.fk_soc, c.statut,";
80 $sql .=
" c.ref_customer, c.ref_supplier";
81 $sql .=
" FROM ".$this->db->prefix().
"contrat as c";
82 $sql .=
" WHERE c.entity = ".$conf->entity;
87 $sql .=
" AND (c.fk_soc=".((int) $socid).
" OR c.fk_soc IS NULL)";
89 $sql .=
" AND (c.fk_soc IN (".$this->db->sanitize(((
int) $socid).
",".((
int)
$conf->global->CONTRACT_ALLOW_TO_LINK_FROM_OTHER_COMPANY)).
")";
90 $sql .=
" OR c.fk_soc IS NULL)";
94 $sql .=
" AND (c.fk_soc = 0 OR c.fk_soc IS NULL)";
96 $sql .=
" ORDER BY c.ref ";
98 dol_syslog(get_class($this).
"::select_contract", LOG_DEBUG);
99 $resql = $this->db->query($sql);
101 $ret .=
'<select class="flat'.($morecss ?
' '.$morecss :
'').
'" name="'.$htmlname.
'" id="'.$htmlname.
'">';
103 $ret .=
'<option value="0"> </option>';
105 $num = $this->db->num_rows($resql);
109 $obj = $this->db->fetch_object($resql);
111 if ($socid > 0 && (empty($obj->fk_soc) || $obj->fk_soc == $socid) && !$user->hasRight(
'societe',
'lire')) {
117 if ($obj->ref_customer) {
118 $labeltoshow = $labeltoshow.
" - ".$obj->ref_customer;
120 if ($obj->ref_supplier) {
121 $labeltoshow = $labeltoshow.
" - ".$obj->ref_supplier;
127 if (!empty($selected) && $selected == $obj->rowid && $obj->statut > 0) {
128 $ret .=
'<option value="'.$obj->rowid.
'" selected>'.$labeltoshow.
'</option>';
131 if ($obj->statut == 0) {
133 $labeltoshow .=
' ('.$langs->trans(
"Draft").
')';
135 if (!
getDolGlobalString(
'CONTRACT_ALLOW_TO_LINK_FROM_OTHER_COMPANY') && $socid > 0 && (!empty($obj->fk_soc) && $obj->fk_soc != $socid)) {
137 $labeltoshow .=
' - '.$langs->trans(
"LinkedToAnotherCompany");
140 if ($hideunselectables && $disabled) {
143 $resultat =
'<option value="'.$obj->rowid.
'"';
145 $resultat .=
' disabled';
149 $resultat .=
'>'.$labeltoshow;
150 $resultat .=
'</option>';
159 $this->db->free($resql);
161 if (!empty(
$conf->use_javascript_ajax)) {
163 include_once DOL_DOCUMENT_ROOT.
'/core/lib/ajax.lib.php';
193 public function formSelectContract($page, $socid = -1, $selected = 0, $htmlname =
'contrattid', $maxlength = 16, $showempty = 1, $showRef = 0, $noouput = 0)
197 $ret =
'<form method="post" action="'.$page.
'">';
198 $ret .=
'<input type="hidden" name="action" value="setcontract">';
199 $ret .=
'<input type="hidden" name="token" value="'.newToken().
'">';
200 $ret .= $this->
select_contract($socid, $selected, $htmlname, $maxlength, $showempty, $showRef, 1);
201 $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.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...