64 public function select_contract($socid = -1, $selected =
'', $htmlname =
'contrattid', $maxlength = 16, $showempty = 1, $showRef = 0)
67 global $user, $conf, $langs;
69 $hideunselectables =
false;
70 if (!empty($conf->global->CONTRACT_HIDE_UNSELECTABLES)) {
71 $hideunselectables =
true;
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;
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)";
90 $sql .=
" AND (c.fk_soc = 0 OR c.fk_soc IS NULL)";
92 $sql .=
" ORDER BY c.ref ";
94 dol_syslog(get_class($this).
"::select_contract", LOG_DEBUG);
95 $resql = $this->db->query($sql);
97 print
'<select class="flat" name="'.$htmlname.
'">';
99 print
'<option value="0"> </option>';
101 $num = $this->db->num_rows($resql);
105 $obj = $this->db->fetch_object($resql);
107 if ($socid > 0 && (empty($obj->fk_soc) || $obj->fk_soc == $socid) && !$user->hasRight(
'societe',
'lire')) {
113 if ($obj->ref_customer) {
114 $labeltoshow = $labeltoshow.
" - ".$obj->ref_customer;
116 if ($obj->ref_supplier) {
117 $labeltoshow = $labeltoshow.
" - ".$obj->ref_supplier;
123 if (!empty($selected) && $selected == $obj->rowid && $obj->statut > 0) {
124 print
'<option value="'.$obj->rowid.
'" selected>'.$labeltoshow.
'</option>';
127 if ($obj->statut == 0) {
129 $labeltoshow .=
' ('.$langs->trans(
"Draft").
')';
131 if (empty($conf->global->CONTRACT_ALLOW_TO_LINK_FROM_OTHER_COMPANY) && $socid > 0 && (!empty($obj->fk_soc) && $obj->fk_soc != $socid)) {
133 $labeltoshow .=
' - '.$langs->trans(
"LinkedToAnotherCompany");
136 if ($hideunselectables && $disabled) {
139 $resultat =
'<option value="'.$obj->rowid.
'"';
141 $resultat .=
' disabled';
145 $resultat .=
'>'.$labeltoshow;
146 $resultat .=
'</option>';
155 $this->db->free($resql);
157 if (!empty($conf->use_javascript_ajax)) {
159 include_once DOL_DOCUMENT_ROOT.
'/core/lib/ajax.lib.php';
182 public function formSelectContract($page, $socid = -1, $selected =
'', $htmlname =
'contrattid', $maxlength = 16, $showempty = 1, $showRef = 0)
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 $result = $this->
select_contract($socid, $selected, $htmlname, $maxlength, $showempty, $showRef);
191 print
'<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='', $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.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.