| Total Complexity | 1869 |
| Total Lines | 7894 |
| Duplicated Lines | 0 % |
| Changes | 4 | ||
| Bugs | 3 | Features | 0 |
Complex classes like Form often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Form, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 52 | class Form |
||
| 53 | { |
||
| 54 | /** |
||
| 55 | * @var DoliDB Database handler. |
||
| 56 | */ |
||
| 57 | public $db; |
||
| 58 | |||
| 59 | /** |
||
| 60 | * @var string Error code (or message) |
||
| 61 | */ |
||
| 62 | public $error = ''; |
||
| 63 | |||
| 64 | /** |
||
| 65 | * @var string[] Array of error strings |
||
| 66 | */ |
||
| 67 | public $errors = array(); |
||
| 68 | |||
| 69 | public $num; |
||
| 70 | |||
| 71 | // Cache arrays |
||
| 72 | public $cache_types_paiements = array(); |
||
| 73 | public $cache_conditions_paiements = array(); |
||
| 74 | public $cache_availability = array(); |
||
| 75 | public $cache_demand_reason = array(); |
||
| 76 | public $cache_types_fees = array(); |
||
| 77 | public $cache_vatrates = array(); |
||
| 78 | |||
| 79 | |||
| 80 | /** |
||
| 81 | * Constructor |
||
| 82 | * |
||
| 83 | * @param DoliDB $db Database handler |
||
| 84 | */ |
||
| 85 | public function __construct($db) |
||
| 88 | } |
||
| 89 | |||
| 90 | /** |
||
| 91 | * Output key field for an editable field |
||
| 92 | * |
||
| 93 | * @param string $text Text of label or key to translate |
||
| 94 | * @param string $htmlname Name of select field ('edit' prefix will be added) |
||
| 95 | * @param string $preselected Value to show/edit (not used in this function) |
||
| 96 | * @param object $object Object |
||
| 97 | * @param boolean $perm Permission to allow button to edit parameter. Set it to 0 to have a not edited field. |
||
| 98 | * @param string $typeofdata Type of data ('string' by default, 'email', 'amount:99', 'numeric:99', 'text' or 'textarea:rows:cols', 'datepicker' ('day' do not work, don't know why), 'ckeditor:dolibarr_zzz:width:height:savemethod:1:rows:cols', 'select;xxx[:class]'...) |
||
| 99 | * @param string $moreparam More param to add on a href URL. |
||
| 100 | * @param int $fieldrequired 1 if we want to show field as mandatory using the "fieldrequired" CSS. |
||
| 101 | * @param int $notabletag 1=Do not output table tags but output a ':', 2=Do not output table tags and no ':', 3=Do not output table tags but output a ' ' |
||
| 102 | * @param string $paramid Key of parameter for id ('id', 'socid') |
||
| 103 | * @param string $help Tooltip help |
||
| 104 | * @return string HTML edit field |
||
| 105 | */ |
||
| 106 | public function editfieldkey($text, $htmlname, $preselected, $object, $perm, $typeofdata = 'string', $moreparam = '', $fieldrequired = 0, $notabletag = 0, $paramid = 'id', $help = '') |
||
| 107 | { |
||
| 108 | global $conf, $langs; |
||
| 109 | |||
| 110 | $ret = ''; |
||
| 111 | |||
| 112 | // TODO change for compatibility |
||
| 113 | if (!empty($conf->global->MAIN_USE_JQUERY_JEDITABLE) && !preg_match('/^select;/', $typeofdata)) |
||
| 114 | { |
||
| 115 | if (!empty($perm)) |
||
| 116 | { |
||
| 117 | $tmp = explode(':', $typeofdata); |
||
| 118 | $ret .= '<div class="editkey_'.$tmp[0].(!empty($tmp[1]) ? ' '.$tmp[1] : '').'" id="'.$htmlname.'">'; |
||
| 119 | if ($fieldrequired) $ret .= '<span class="fieldrequired">'; |
||
| 120 | if ($help) { |
||
| 121 | $ret .= $this->textwithpicto($langs->trans($text), $help); |
||
| 122 | } else { |
||
| 123 | $ret .= $langs->trans($text); |
||
| 124 | } |
||
| 125 | if ($fieldrequired) $ret .= '</span>'; |
||
| 126 | $ret .= '</div>'."\n"; |
||
| 127 | } else { |
||
| 128 | if ($fieldrequired) $ret .= '<span class="fieldrequired">'; |
||
| 129 | if ($help) { |
||
| 130 | $ret .= $this->textwithpicto($langs->trans($text), $help); |
||
| 131 | } else { |
||
| 132 | $ret .= $langs->trans($text); |
||
| 133 | } |
||
| 134 | if ($fieldrequired) $ret .= '</span>'; |
||
| 135 | } |
||
| 136 | } else { |
||
| 137 | if (empty($notabletag) && GETPOST('action', 'aZ09') != 'edit'.$htmlname && $perm) $ret .= '<table class="nobordernopadding centpercent"><tr><td class="nowrap">'; |
||
| 138 | if ($fieldrequired) $ret .= '<span class="fieldrequired">'; |
||
| 139 | if ($help) { |
||
| 140 | $ret .= $this->textwithpicto($langs->trans($text), $help); |
||
| 141 | } else { |
||
| 142 | $ret .= $langs->trans($text); |
||
| 143 | } |
||
| 144 | if ($fieldrequired) $ret .= '</span>'; |
||
| 145 | if (!empty($notabletag)) $ret .= ' '; |
||
| 146 | if (empty($notabletag) && GETPOST('action', 'aZ09') != 'edit'.$htmlname && $perm) $ret .= '</td>'; |
||
| 147 | if (empty($notabletag) && GETPOST('action', 'aZ09') != 'edit'.$htmlname && $perm) $ret .= '<td class="right">'; |
||
| 148 | if ($htmlname && GETPOST('action', 'aZ09') != 'edit'.$htmlname && $perm) $ret .= '<a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=edit'.$htmlname.'&'.$paramid.'='.$object->id.$moreparam.'">'.img_edit($langs->trans('Edit'), ($notabletag ? 0 : 1)).'</a>'; |
||
| 149 | if (!empty($notabletag) && $notabletag == 1) $ret .= ' : '; |
||
| 150 | if (!empty($notabletag) && $notabletag == 3) $ret .= ' '; |
||
| 151 | if (empty($notabletag) && GETPOST('action', 'aZ09') != 'edit'.$htmlname && $perm) $ret .= '</td>'; |
||
| 152 | if (empty($notabletag) && GETPOST('action', 'aZ09') != 'edit'.$htmlname && $perm) $ret .= '</tr></table>'; |
||
| 153 | } |
||
| 154 | |||
| 155 | return $ret; |
||
| 156 | } |
||
| 157 | |||
| 158 | /** |
||
| 159 | * Output value of a field for an editable field |
||
| 160 | * |
||
| 161 | * @param string $text Text of label (not used in this function) |
||
| 162 | * @param string $htmlname Name of select field |
||
| 163 | * @param string $value Value to show/edit |
||
| 164 | * @param object $object Object |
||
| 165 | * @param boolean $perm Permission to allow button to edit parameter |
||
| 166 | * @param string $typeofdata Type of data ('string' by default, 'email', 'amount:99', 'numeric:99', 'text' or 'textarea:rows:cols%', 'datepicker' ('day' do not work, don't know why), 'dayhour' or 'datepickerhour', 'ckeditor:dolibarr_zzz:width:height:savemethod:toolbarstartexpanded:rows:cols', 'select;xkey:xval,ykey:yval,...') |
||
| 167 | * @param string $editvalue When in edit mode, use this value as $value instead of value (for example, you can provide here a formated price instead of value). Use '' to use same than $value |
||
| 168 | * @param object $extObject External object |
||
| 169 | * @param mixed $custommsg String or Array of custom messages : eg array('success' => 'MyMessage', 'error' => 'MyMessage') |
||
| 170 | * @param string $moreparam More param to add on the form action href URL |
||
| 171 | * @param int $notabletag Do no output table tags |
||
| 172 | * @param string $formatfunc Call a specific function to output field |
||
| 173 | * @param string $paramid Key of parameter for id ('id', 'socid') |
||
| 174 | * @return string HTML edit field |
||
| 175 | */ |
||
| 176 | public function editfieldval($text, $htmlname, $value, $object, $perm, $typeofdata = 'string', $editvalue = '', $extObject = null, $custommsg = null, $moreparam = '', $notabletag = 0, $formatfunc = '', $paramid = 'id') |
||
| 177 | { |
||
| 178 | global $conf, $langs, $db; |
||
| 179 | |||
| 180 | $ret = ''; |
||
| 181 | |||
| 182 | // Check parameters |
||
| 183 | if (empty($typeofdata)) return 'ErrorBadParameter'; |
||
| 184 | |||
| 185 | // When option to edit inline is activated |
||
| 186 | if (!empty($conf->global->MAIN_USE_JQUERY_JEDITABLE) && !preg_match('/^select;|datehourpicker/', $typeofdata)) // TODO add jquery timepicker and support select |
||
| 187 | { |
||
| 188 | $ret .= $this->editInPlace($object, $value, $htmlname, $perm, $typeofdata, $editvalue, $extObject, $custommsg); |
||
| 189 | } else { |
||
| 190 | if (GETPOST('action', 'aZ09') == 'edit'.$htmlname) |
||
| 191 | { |
||
| 192 | $ret .= "\n"; |
||
| 193 | $ret .= '<form method="post" action="'.$_SERVER["PHP_SELF"].($moreparam ? '?'.$moreparam : '').'">'; |
||
| 194 | $ret .= '<input type="hidden" name="action" value="set'.$htmlname.'">'; |
||
| 195 | $ret .= '<input type="hidden" name="token" value="'.newToken().'">'; |
||
| 196 | $ret .= '<input type="hidden" name="'.$paramid.'" value="'.$object->id.'">'; |
||
| 197 | if (empty($notabletag)) $ret .= '<table class="nobordernopadding centpercent" cellpadding="0" cellspacing="0">'; |
||
| 198 | if (empty($notabletag)) $ret .= '<tr><td>'; |
||
| 199 | if (preg_match('/^(string|safehtmlstring|email)/', $typeofdata)) |
||
| 200 | { |
||
| 201 | $tmp = explode(':', $typeofdata); |
||
| 202 | $ret .= '<input type="text" id="'.$htmlname.'" name="'.$htmlname.'" value="'.($editvalue ? $editvalue : $value).'"'.($tmp[1] ? ' size="'.$tmp[1].'"' : '').'>'; |
||
| 203 | } elseif (preg_match('/^(numeric|amount)/', $typeofdata)) |
||
| 204 | { |
||
| 205 | $tmp = explode(':', $typeofdata); |
||
| 206 | $valuetoshow = price2num($editvalue ? $editvalue : $value); |
||
| 207 | $ret .= '<input type="text" id="'.$htmlname.'" name="'.$htmlname.'" value="'.($valuetoshow != '' ?price($valuetoshow) : '').'"'.($tmp[1] ? ' size="'.$tmp[1].'"' : '').'>'; |
||
| 208 | } elseif (preg_match('/^text/', $typeofdata) || preg_match('/^note/', $typeofdata)) // if wysiwyg is enabled $typeofdata = 'ckeditor' |
||
| 209 | { |
||
| 210 | $tmp = explode(':', $typeofdata); |
||
| 211 | $cols = $tmp[2]; |
||
| 212 | $morealt = ''; |
||
| 213 | if (preg_match('/%/', $cols)) |
||
| 214 | { |
||
| 215 | $morealt = ' style="width: '.$cols.'"'; |
||
| 216 | $cols = ''; |
||
| 217 | } |
||
| 218 | |||
| 219 | $valuetoshow = ($editvalue ? $editvalue : $value); |
||
| 220 | $ret .= '<textarea id="'.$htmlname.'" name="'.$htmlname.'" wrap="soft" rows="'.($tmp[1] ? $tmp[1] : '20').'"'.($cols ? ' cols="'.$cols.'"' : 'class="quatrevingtpercent"').$morealt.'">'; |
||
| 221 | // textarea convert automatically entities chars into simple chars. |
||
| 222 | // So we convert & into & so a string like 'a < <b>b</b><br>é<br><script>alert('X');<script>' stay a correct html and is not converted by textarea component when wysiwig is off. |
||
| 223 | $valuetoshow = str_replace('&', '&', $valuetoshow); |
||
| 224 | $ret .= dol_string_neverthesehtmltags($valuetoshow, array('textarea')); |
||
| 225 | $ret .= '</textarea>'; |
||
| 226 | } elseif ($typeofdata == 'day' || $typeofdata == 'datepicker') |
||
| 227 | { |
||
| 228 | $ret .= $this->selectDate($value, $htmlname, 0, 0, 1, 'form'.$htmlname, 1, 0); |
||
| 229 | } elseif ($typeofdata == 'dayhour' || $typeofdata == 'datehourpicker') |
||
| 230 | { |
||
| 231 | $ret .= $this->selectDate($value, $htmlname, 1, 1, 1, 'form'.$htmlname, 1, 0); |
||
| 232 | } elseif (preg_match('/^select;/', $typeofdata)) |
||
| 233 | { |
||
| 234 | $arraydata = explode(',', preg_replace('/^select;/', '', $typeofdata)); |
||
| 235 | $arraylist = array(); |
||
| 236 | foreach ($arraydata as $val) |
||
| 237 | { |
||
| 238 | $tmp = explode(':', $val); |
||
| 239 | $tmpkey = str_replace('|', ':', $tmp[0]); |
||
| 240 | $arraylist[$tmpkey] = $tmp[1]; |
||
| 241 | } |
||
| 242 | $ret .= $this->selectarray($htmlname, $arraylist, $value); |
||
| 243 | } elseif (preg_match('/^ckeditor/', $typeofdata)) |
||
| 244 | { |
||
| 245 | $tmp = explode(':', $typeofdata); // Example: ckeditor:dolibarr_zzz:width:height:savemethod:toolbarstartexpanded:rows:cols:uselocalbrowser |
||
| 246 | require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; |
||
| 247 | $doleditor = new DolEditor($htmlname, ($editvalue ? $editvalue : $value), ($tmp[2] ? $tmp[2] : ''), ($tmp[3] ? $tmp[3] : '100'), ($tmp[1] ? $tmp[1] : 'dolibarr_notes'), 'In', ($tmp[5] ? $tmp[5] : 0), (isset($tmp[8]) ? ($tmp[8] ?true:false) : true), true, ($tmp[6] ? $tmp[6] : '20'), ($tmp[7] ? $tmp[7] : '100')); |
||
| 248 | $ret .= $doleditor->Create(1); |
||
| 249 | } |
||
| 250 | if (empty($notabletag)) $ret .= '</td>'; |
||
| 251 | |||
| 252 | if (empty($notabletag)) $ret .= '<td class="left">'; |
||
| 253 | //else $ret.='<div class="clearboth"></div>'; |
||
| 254 | $ret .= '<input type="submit" class="button'.(empty($notabletag) ? '' : ' ').'" name="modify" value="'.$langs->trans("Modify").'">'; |
||
| 255 | if (preg_match('/ckeditor|textarea/', $typeofdata) && empty($notabletag)) $ret .= '<br>'."\n"; |
||
| 256 | $ret .= '<input type="submit" class="button'.(empty($notabletag) ? '' : ' ').'" name="cancel" value="'.$langs->trans("Cancel").'">'; |
||
| 257 | if (empty($notabletag)) $ret .= '</td>'; |
||
| 258 | |||
| 259 | if (empty($notabletag)) $ret .= '</tr></table>'."\n"; |
||
| 260 | $ret .= '</form>'."\n"; |
||
| 261 | } else { |
||
| 262 | if (preg_match('/^(email)/', $typeofdata)) $ret .= dol_print_email($value, 0, 0, 0, 0, 1); |
||
| 263 | elseif (preg_match('/^(amount|numeric)/', $typeofdata)) $ret .= ($value != '' ? price($value, '', $langs, 0, -1, -1, $conf->currency) : ''); |
||
| 264 | elseif (preg_match('/^text/', $typeofdata) || preg_match('/^note/', $typeofdata)) $ret .= dol_htmlentitiesbr($value); |
||
| 265 | elseif (preg_match('/^safehtmlstring/', $typeofdata)) $ret .= dol_string_onlythesehtmltags($value); |
||
| 266 | elseif ($typeofdata == 'day' || $typeofdata == 'datepicker') $ret .= dol_print_date($value, 'day'); |
||
| 267 | elseif ($typeofdata == 'dayhour' || $typeofdata == 'datehourpicker') $ret .= dol_print_date($value, 'dayhour'); |
||
| 268 | elseif (preg_match('/^select;/', $typeofdata)) |
||
| 269 | { |
||
| 270 | $arraydata = explode(',', preg_replace('/^select;/', '', $typeofdata)); |
||
| 271 | $arraylist = array(); |
||
| 272 | foreach ($arraydata as $val) |
||
| 273 | { |
||
| 274 | $tmp = explode(':', $val); |
||
| 275 | $arraylist[$tmp[0]] = $tmp[1]; |
||
| 276 | } |
||
| 277 | $ret .= $arraylist[$value]; |
||
| 278 | } elseif (preg_match('/^ckeditor/', $typeofdata)) |
||
| 279 | { |
||
| 280 | $tmpcontent = dol_htmlentitiesbr($value); |
||
| 281 | if (!empty($conf->global->MAIN_DISABLE_NOTES_TAB)) |
||
| 282 | { |
||
| 283 | $firstline = preg_replace('/<br>.*/', '', $tmpcontent); |
||
| 284 | $firstline = preg_replace('/[\n\r].*/', '', $firstline); |
||
| 285 | $tmpcontent = $firstline.((strlen($firstline) != strlen($tmpcontent)) ? '...' : ''); |
||
| 286 | } |
||
| 287 | // We dont use dol_escape_htmltag to get the html formating active, but this need we must also |
||
| 288 | // clean data from some dangerous html |
||
| 289 | $ret .= dol_string_onlythesehtmltags(dol_htmlentitiesbr($tmpcontent)); |
||
| 290 | } else { |
||
| 291 | $ret .= dol_escape_htmltag($value); |
||
| 292 | } |
||
| 293 | |||
| 294 | if ($formatfunc && method_exists($object, $formatfunc)) |
||
| 295 | { |
||
| 296 | $ret = $object->$formatfunc($ret); |
||
| 297 | } |
||
| 298 | } |
||
| 299 | } |
||
| 300 | return $ret; |
||
| 301 | } |
||
| 302 | |||
| 303 | /** |
||
| 304 | * Output edit in place form |
||
| 305 | * |
||
| 306 | * @param string $fieldname Name of the field |
||
| 307 | * @param object $object Object |
||
| 308 | * @param boolean $perm Permission to allow button to edit parameter. Set it to 0 to have a not edited field. |
||
| 309 | * @param string $typeofdata Type of data ('string' by default, 'email', 'amount:99', 'numeric:99', 'text' or 'textarea:rows:cols', 'datepicker' ('day' do not work, don't know why), 'ckeditor:dolibarr_zzz:width:height:savemethod:1:rows:cols', 'select;xxx[:class]'...) |
||
| 310 | * @param string $check Same coe than $check parameter of GETPOST() |
||
| 311 | * @param string $morecss More CSS |
||
| 312 | * @return string HTML code for the edit of alternative language |
||
| 313 | */ |
||
| 314 | public function widgetForTranslation($fieldname, $object, $perm, $typeofdata = 'string', $check = '', $morecss = '') |
||
| 315 | { |
||
| 316 | global $conf, $langs, $extralanguages; |
||
| 317 | |||
| 318 | $result = ''; |
||
| 319 | |||
| 320 | // List of extra languages |
||
| 321 | $arrayoflangcode = array(); |
||
| 322 | if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE)) $arrayoflangcode[] = $conf->global->PDF_USE_ALSO_LANGUAGE_CODE; |
||
| 323 | |||
| 324 | if (is_array($arrayoflangcode) && count($arrayoflangcode)) { |
||
| 325 | if (!is_object($extralanguages)) { |
||
| 326 | include_once DOL_DOCUMENT_ROOT.'/core/class/extralanguages.class.php'; |
||
| 327 | $extralanguages = new ExtraLanguages($this->db); |
||
| 328 | } |
||
| 329 | $extralanguages->fetch_name_extralanguages('societe'); |
||
| 330 | |||
| 331 | if (!is_array($extralanguages->attributes[$object->element]) || empty($extralanguages->attributes[$object->element][$fieldname])) { |
||
| 332 | return ''; // No extralang field to show |
||
| 333 | } |
||
| 334 | |||
| 335 | $result .= '<!-- Widget for translation -->'."\n"; |
||
| 336 | $result .= '<div class="inline-block paddingleft image-'.$object->element.'-'.$fieldname.'">'; |
||
| 337 | $s = img_picto($langs->trans("ShowOtherLanguages"), 'language', '', false, 0, 0, '', 'fa-15 editfieldlang'); |
||
| 338 | $result .= $s; |
||
| 339 | $result .= '</div>'; |
||
| 340 | |||
| 341 | $result .= '<div class="inline-block hidden field-'.$object->element.'-'.$fieldname.'">'; |
||
| 342 | |||
| 343 | $resultforextrlang = ''; |
||
| 344 | foreach ($arrayoflangcode as $langcode) |
||
| 345 | { |
||
| 346 | $valuetoshow = GETPOSTISSET('field-'.$object->element."-".$fieldname."-".$langcode) ? GETPOST('field-'.$object->element.'-'.$fieldname."-".$langcode, $check) : ''; |
||
| 347 | if (empty($valuetoshow)) { |
||
| 348 | $object->fetchValuesForExtraLanguages(); |
||
| 349 | //var_dump($object->array_languages); |
||
| 350 | $valuetoshow = $object->array_languages[$fieldname][$langcode]; |
||
| 351 | } |
||
| 352 | |||
| 353 | $s = picto_from_langcode($langcode, 'class="pictoforlang paddingright"'); |
||
| 354 | $resultforextrlang .= $s; |
||
| 355 | |||
| 356 | // TODO Use the showInputField() method of ExtraLanguages object |
||
| 357 | if ($typeofdata == 'textarea') { |
||
| 358 | $resultforextrlang .= '<textarea name="field-'.$object->element."-".$fieldname."-".$langcode.'" id="'.$fieldname."-".$langcode.'" class="'.$morecss.'" rows="'.ROWS_2.'" wrap="soft">'; |
||
| 359 | $resultforextrlang .= $valuetoshow; |
||
| 360 | $resultforextrlang .= '</textarea>'; |
||
| 361 | } else { |
||
| 362 | $resultforextrlang .= '<input type="text" class="inputfieldforlang '.($morecss ? ' '.$morecss : '').'" name="field-'.$object->element.'-'.$fieldname.'-'.$langcode.'" value="'.$valuetoshow.'">'; |
||
| 363 | } |
||
| 364 | } |
||
| 365 | $result .= $resultforextrlang; |
||
| 366 | |||
| 367 | $result .= '</div>'; |
||
| 368 | $result .= '<script>$(".image-'.$object->element.'-'.$fieldname.'").click(function() { console.log("Toggle lang widget"); jQuery(".field-'.$object->element.'-'.$fieldname.'").toggle(); });</script>'; |
||
| 369 | } |
||
| 370 | |||
| 371 | return $result; |
||
| 372 | } |
||
| 373 | |||
| 374 | /** |
||
| 375 | * Output edit in place form |
||
| 376 | * |
||
| 377 | * @param object $object Object |
||
| 378 | * @param string $value Value to show/edit |
||
| 379 | * @param string $htmlname DIV ID (field name) |
||
| 380 | * @param int $condition Condition to edit |
||
| 381 | * @param string $inputType Type of input ('string', 'numeric', 'datepicker' ('day' do not work, don't know why), 'textarea:rows:cols', 'ckeditor:dolibarr_zzz:width:height:?:1:rows:cols', 'select:loadmethod:savemethod:buttononly') |
||
| 382 | * @param string $editvalue When in edit mode, use this value as $value instead of value |
||
| 383 | * @param object $extObject External object |
||
| 384 | * @param mixed $custommsg String or Array of custom messages : eg array('success' => 'MyMessage', 'error' => 'MyMessage') |
||
| 385 | * @return string HTML edit in place |
||
| 386 | */ |
||
| 387 | protected function editInPlace($object, $value, $htmlname, $condition, $inputType = 'textarea', $editvalue = null, $extObject = null, $custommsg = null) |
||
| 388 | { |
||
| 389 | global $conf; |
||
| 390 | |||
| 391 | $out = ''; |
||
| 392 | |||
| 393 | // Check parameters |
||
| 394 | if (preg_match('/^text/', $inputType)) $value = dol_nl2br($value); |
||
| 395 | elseif (preg_match('/^numeric/', $inputType)) $value = price($value); |
||
| 396 | elseif ($inputType == 'day' || $inputType == 'datepicker') $value = dol_print_date($value, 'day'); |
||
| 397 | |||
| 398 | if ($condition) |
||
| 399 | { |
||
| 400 | $element = false; |
||
| 401 | $table_element = false; |
||
| 402 | $fk_element = false; |
||
| 403 | $loadmethod = false; |
||
| 404 | $savemethod = false; |
||
| 405 | $ext_element = false; |
||
| 406 | $button_only = false; |
||
| 407 | $inputOption = ''; |
||
| 408 | |||
| 409 | if (is_object($object)) |
||
| 410 | { |
||
| 411 | $element = $object->element; |
||
| 412 | $table_element = $object->table_element; |
||
| 413 | $fk_element = $object->id; |
||
| 414 | } |
||
| 415 | |||
| 416 | if (is_object($extObject)) |
||
| 417 | { |
||
| 418 | $ext_element = $extObject->element; |
||
| 419 | } |
||
| 420 | |||
| 421 | if (preg_match('/^(string|email|numeric)/', $inputType)) |
||
| 422 | { |
||
| 423 | $tmp = explode(':', $inputType); |
||
| 424 | $inputType = $tmp[0]; |
||
| 425 | if (!empty($tmp[1])) $inputOption = $tmp[1]; |
||
| 426 | if (!empty($tmp[2])) $savemethod = $tmp[2]; |
||
| 427 | $out .= '<input id="width_'.$htmlname.'" value="'.$inputOption.'" type="hidden"/>'."\n"; |
||
| 428 | } elseif ((preg_match('/^day$/', $inputType)) || (preg_match('/^datepicker/', $inputType)) || (preg_match('/^datehourpicker/', $inputType))) |
||
| 429 | { |
||
| 430 | $tmp = explode(':', $inputType); |
||
| 431 | $inputType = $tmp[0]; |
||
| 432 | if (!empty($tmp[1])) $inputOption = $tmp[1]; |
||
| 433 | if (!empty($tmp[2])) $savemethod = $tmp[2]; |
||
| 434 | |||
| 435 | $out .= '<input id="timestamp" type="hidden"/>'."\n"; // Use for timestamp format |
||
| 436 | } elseif (preg_match('/^(select|autocomplete)/', $inputType)) |
||
| 437 | { |
||
| 438 | $tmp = explode(':', $inputType); |
||
| 439 | $inputType = $tmp[0]; $loadmethod = $tmp[1]; |
||
| 440 | if (!empty($tmp[2])) $savemethod = $tmp[2]; |
||
| 441 | if (!empty($tmp[3])) $button_only = true; |
||
| 442 | } elseif (preg_match('/^textarea/', $inputType)) |
||
| 443 | { |
||
| 444 | $tmp = explode(':', $inputType); |
||
| 445 | $inputType = $tmp[0]; |
||
| 446 | $rows = (empty($tmp[1]) ? '8' : $tmp[1]); |
||
| 447 | $cols = (empty($tmp[2]) ? '80' : $tmp[2]); |
||
| 448 | } elseif (preg_match('/^ckeditor/', $inputType)) |
||
| 449 | { |
||
| 450 | $tmp = explode(':', $inputType); |
||
| 451 | $inputType = $tmp[0]; $toolbar = $tmp[1]; |
||
| 452 | if (!empty($tmp[2])) $width = $tmp[2]; |
||
| 453 | if (!empty($tmp[3])) $heigth = $tmp[3]; |
||
| 454 | if (!empty($tmp[4])) $savemethod = $tmp[4]; |
||
| 455 | |||
| 456 | if (!empty($conf->fckeditor->enabled)) |
||
| 457 | { |
||
| 458 | $out .= '<input id="ckeditor_toolbar" value="'.$toolbar.'" type="hidden"/>'."\n"; |
||
| 459 | } else { |
||
| 460 | $inputType = 'textarea'; |
||
| 461 | } |
||
| 462 | } |
||
| 463 | |||
| 464 | $out .= '<input id="element_'.$htmlname.'" value="'.$element.'" type="hidden"/>'."\n"; |
||
| 465 | $out .= '<input id="table_element_'.$htmlname.'" value="'.$table_element.'" type="hidden"/>'."\n"; |
||
| 466 | $out .= '<input id="fk_element_'.$htmlname.'" value="'.$fk_element.'" type="hidden"/>'."\n"; |
||
| 467 | $out .= '<input id="loadmethod_'.$htmlname.'" value="'.$loadmethod.'" type="hidden"/>'."\n"; |
||
| 468 | if (!empty($savemethod)) $out .= '<input id="savemethod_'.$htmlname.'" value="'.$savemethod.'" type="hidden"/>'."\n"; |
||
| 469 | if (!empty($ext_element)) $out .= '<input id="ext_element_'.$htmlname.'" value="'.$ext_element.'" type="hidden"/>'."\n"; |
||
| 470 | if (!empty($custommsg)) |
||
| 471 | { |
||
| 472 | if (is_array($custommsg)) |
||
| 473 | { |
||
| 474 | if (!empty($custommsg['success'])) |
||
| 475 | $out .= '<input id="successmsg_'.$htmlname.'" value="'.$custommsg['success'].'" type="hidden"/>'."\n"; |
||
| 476 | if (!empty($custommsg['error'])) |
||
| 477 | $out .= '<input id="errormsg_'.$htmlname.'" value="'.$custommsg['error'].'" type="hidden"/>'."\n"; |
||
| 478 | } else $out .= '<input id="successmsg_'.$htmlname.'" value="'.$custommsg.'" type="hidden"/>'."\n"; |
||
| 479 | } |
||
| 480 | if ($inputType == 'textarea') { |
||
| 481 | $out .= '<input id="textarea_'.$htmlname.'_rows" value="'.$rows.'" type="hidden"/>'."\n"; |
||
|
|
|||
| 482 | $out .= '<input id="textarea_'.$htmlname.'_cols" value="'.$cols.'" type="hidden"/>'."\n"; |
||
| 483 | } |
||
| 484 | $out .= '<span id="viewval_'.$htmlname.'" class="viewval_'.$inputType.($button_only ? ' inactive' : ' active').'">'.$value.'</span>'."\n"; |
||
| 485 | $out .= '<span id="editval_'.$htmlname.'" class="editval_'.$inputType.($button_only ? ' inactive' : ' active').' hideobject">'.(!empty($editvalue) ? $editvalue : $value).'</span>'."\n"; |
||
| 486 | } else { |
||
| 487 | $out = $value; |
||
| 488 | } |
||
| 489 | |||
| 490 | return $out; |
||
| 491 | } |
||
| 492 | |||
| 493 | /** |
||
| 494 | * Show a text and picto with tooltip on text or picto. |
||
| 495 | * Can be called by an instancied $form->textwithtooltip or by a static call Form::textwithtooltip |
||
| 496 | * |
||
| 497 | * @param string $text Text to show |
||
| 498 | * @param string $htmltext HTML content of tooltip. Must be HTML/UTF8 encoded. |
||
| 499 | * @param int $tooltipon 1=tooltip on text, 2=tooltip on image, 3=tooltip sur les 2 |
||
| 500 | * @param int $direction -1=image is before, 0=no image, 1=image is after |
||
| 501 | * @param string $img Html code for image (use img_xxx() function to get it) |
||
| 502 | * @param string $extracss Add a CSS style to td tags |
||
| 503 | * @param int $notabs 0=Include table and tr tags, 1=Do not include table and tr tags, 2=use div, 3=use span |
||
| 504 | * @param string $incbefore Include code before the text |
||
| 505 | * @param int $noencodehtmltext Do not encode into html entity the htmltext |
||
| 506 | * @param string $tooltiptrigger ''=Tooltip on hover, 'abc'=Tooltip on click (abc is a unique key) |
||
| 507 | * @param int $forcenowrap Force no wrap between text and picto (works with notabs=2 only) |
||
| 508 | * @return string Code html du tooltip (texte+picto) |
||
| 509 | * @see textwithpicto() Use thisfunction if you can. |
||
| 510 | * TODO Move this as static as soon as everybody use textwithpicto or @Form::textwithtooltip |
||
| 511 | */ |
||
| 512 | public function textwithtooltip($text, $htmltext, $tooltipon = 1, $direction = 0, $img = '', $extracss = '', $notabs = 3, $incbefore = '', $noencodehtmltext = 0, $tooltiptrigger = '', $forcenowrap = 0) |
||
| 513 | { |
||
| 514 | if ($incbefore) $text = $incbefore.$text; |
||
| 515 | if (!$htmltext) return $text; |
||
| 516 | |||
| 517 | $tag = 'td'; |
||
| 518 | if ($notabs == 2) $tag = 'div'; |
||
| 519 | if ($notabs == 3) $tag = 'span'; |
||
| 520 | // Sanitize tooltip |
||
| 521 | $htmltext = str_replace(array("\r", "\n"), '', $htmltext); |
||
| 522 | |||
| 523 | $extrastyle = ''; |
||
| 524 | if ($direction < 0) { $extracss = ($extracss ? $extracss.' ' : '').($notabs != 3 ? 'inline-block' : ''); $extrastyle = 'padding: 0px; padding-left: 3px !important;'; } |
||
| 525 | if ($direction > 0) { $extracss = ($extracss ? $extracss.' ' : '').($notabs != 3 ? 'inline-block' : ''); $extrastyle = 'padding: 0px; padding-right: 3px !important;'; } |
||
| 526 | |||
| 527 | $classfortooltip = 'classfortooltip'; |
||
| 528 | |||
| 529 | $s = ''; $textfordialog = ''; |
||
| 530 | |||
| 531 | if ($tooltiptrigger == '') |
||
| 532 | { |
||
| 533 | $htmltext = str_replace('"', '"', $htmltext); |
||
| 534 | } else { |
||
| 535 | $classfortooltip = 'classfortooltiponclick'; |
||
| 536 | $textfordialog .= '<div style="display: none;" id="idfortooltiponclick_'.$tooltiptrigger.'" class="classfortooltiponclicktext">'.$htmltext.'</div>'; |
||
| 537 | } |
||
| 538 | if ($tooltipon == 2 || $tooltipon == 3) |
||
| 539 | { |
||
| 540 | $paramfortooltipimg = ' class="'.$classfortooltip.($notabs != 3 ? ' inline-block' : '').($extracss ? ' '.$extracss : '').'" style="padding: 0px;'.($extrastyle ? ' '.$extrastyle : '').'"'; |
||
| 541 | if ($tooltiptrigger == '') $paramfortooltipimg .= ' title="'.($noencodehtmltext ? $htmltext : dol_escape_htmltag($htmltext, 1)).'"'; // Attribut to put on img tag to store tooltip |
||
| 542 | else $paramfortooltipimg .= ' dolid="'.$tooltiptrigger.'"'; |
||
| 543 | } else $paramfortooltipimg = ($extracss ? ' class="'.$extracss.'"' : '').($extrastyle ? ' style="'.$extrastyle.'"' : ''); // Attribut to put on td text tag |
||
| 544 | if ($tooltipon == 1 || $tooltipon == 3) |
||
| 545 | { |
||
| 546 | $paramfortooltiptd = ' class="'.($tooltipon == 3 ? 'cursorpointer ' : '').$classfortooltip.' inline-block'.($extracss ? ' '.$extracss : '').'" style="padding: 0px;'.($extrastyle ? ' '.$extrastyle : '').'" '; |
||
| 547 | if ($tooltiptrigger == '') $paramfortooltiptd .= ' title="'.($noencodehtmltext ? $htmltext : dol_escape_htmltag($htmltext, 1)).'"'; // Attribut to put on td tag to store tooltip |
||
| 548 | else $paramfortooltiptd .= ' dolid="'.$tooltiptrigger.'"'; |
||
| 549 | } else $paramfortooltiptd = ($extracss ? ' class="'.$extracss.'"' : '').($extrastyle ? ' style="'.$extrastyle.'"' : ''); // Attribut to put on td text tag |
||
| 550 | if (empty($notabs)) $s .= '<table class="nobordernopadding"><tr style="height: auto;">'; |
||
| 551 | elseif ($notabs == 2) $s .= '<div class="inline-block'.($forcenowrap ? ' nowrap' : '').'">'; |
||
| 552 | // Define value if value is before |
||
| 553 | if ($direction < 0) { |
||
| 554 | $s .= '<'.$tag.$paramfortooltipimg; |
||
| 555 | if ($tag == 'td') { |
||
| 556 | $s .= ' class=valigntop" width="14"'; |
||
| 557 | } |
||
| 558 | $s .= '>'.$textfordialog.$img.'</'.$tag.'>'; |
||
| 559 | } |
||
| 560 | // Use another method to help avoid having a space in value in order to use this value with jquery |
||
| 561 | // Define label |
||
| 562 | if ((string) $text != '') $s .= '<'.$tag.$paramfortooltiptd.'>'.$text.'</'.$tag.'>'; |
||
| 563 | // Define value if value is after |
||
| 564 | if ($direction > 0) { |
||
| 565 | $s .= '<'.$tag.$paramfortooltipimg; |
||
| 566 | if ($tag == 'td') $s .= ' class="valignmiddle" width="14"'; |
||
| 567 | $s .= '>'.$textfordialog.$img.'</'.$tag.'>'; |
||
| 568 | } |
||
| 569 | if (empty($notabs)) $s .= '</tr></table>'; |
||
| 570 | elseif ($notabs == 2) $s .= '</div>'; |
||
| 571 | |||
| 572 | return $s; |
||
| 573 | } |
||
| 574 | |||
| 575 | /** |
||
| 576 | * Show a text with a picto and a tooltip on picto |
||
| 577 | * |
||
| 578 | * @param string $text Text to show |
||
| 579 | * @param string $htmltext Content of tooltip |
||
| 580 | * @param int $direction 1=Icon is after text, -1=Icon is before text, 0=no icon |
||
| 581 | * @param string $type Type of picto ('info', 'infoclickable', 'help', 'helpclickable', 'warning', 'superadmin', 'mypicto@mymodule', ...) or image filepath or 'none' |
||
| 582 | * @param string $extracss Add a CSS style to td, div or span tag |
||
| 583 | * @param int $noencodehtmltext Do not encode into html entity the htmltext |
||
| 584 | * @param int $notabs 0=Include table and tr tags, 1=Do not include table and tr tags, 2=use div, 3=use span |
||
| 585 | * @param string $tooltiptrigger ''=Tooltip on hover, 'abc'=Tooltip on click (abc is a unique key, clickable link is on image or on link if param $type='none' or on both if $type='xxxclickable') |
||
| 586 | * @param int $forcenowrap Force no wrap between text and picto (works with notabs=2 only) |
||
| 587 | * @return string HTML code of text, picto, tooltip |
||
| 588 | */ |
||
| 589 | public function textwithpicto($text, $htmltext, $direction = 1, $type = 'help', $extracss = '', $noencodehtmltext = 0, $notabs = 3, $tooltiptrigger = '', $forcenowrap = 0) |
||
| 631 | } |
||
| 632 | |||
| 633 | /** |
||
| 634 | * Generate select HTML to choose massaction |
||
| 635 | * |
||
| 636 | * @param string $selected Value auto selected when at least one record is selected. Not a preselected value. Use '0' by default. |
||
| 637 | * @param array $arrayofaction array('code'=>'label', ...). The code is the key stored into the GETPOST('massaction') when submitting action. |
||
| 638 | * @param int $alwaysvisible 1=select button always visible |
||
| 639 | * @param string $name Name for massaction |
||
| 640 | * @param string $cssclass CSS class used to check for select |
||
| 641 | * @return string|void Select list |
||
| 642 | */ |
||
| 643 | public function selectMassAction($selected, $arrayofaction, $alwaysvisible = 0, $name = 'massaction', $cssclass = 'checkforselect') |
||
| 644 | { |
||
| 645 | global $conf, $langs, $hookmanager; |
||
| 646 | |||
| 647 | |||
| 648 | $disabled = 0; |
||
| 649 | $ret = '<div class="centpercent center">'; |
||
| 650 | $ret .= '<select class="flat'.(empty($conf->use_javascript_ajax) ? '' : ' hideobject').' ' . $name . ' ' . $name . 'select valignmiddle alignstart" name="' . $name . '"'.($disabled ? ' disabled="disabled"' : '').'>'; |
||
| 651 | |||
| 652 | // Complete list with data from external modules. THe module can use $_SERVER['PHP_SELF'] to know on which page we are, or use the $parameters['currentcontext'] completed by executeHooks. |
||
| 653 | $parameters = array(); |
||
| 654 | $reshook = $hookmanager->executeHooks('addMoreMassActions', $parameters); // Note that $action and $object may have been modified by hook |
||
| 655 | // check if there is a mass action |
||
| 656 | if (count($arrayofaction) == 0 && empty($hookmanager->resPrint)) return; |
||
| 657 | if (empty($reshook)) |
||
| 658 | { |
||
| 659 | $ret .= '<option value="0"'.($disabled ? ' disabled="disabled"' : '').'>-- '.$langs->trans("SelectAction").' --</option>'; |
||
| 660 | foreach ($arrayofaction as $code => $label) |
||
| 661 | { |
||
| 662 | $ret .= '<option value="'.$code.'"'.($disabled ? ' disabled="disabled"' : '').' data-html="'.dol_escape_htmltag($label).'">'.$label.'</option>'; |
||
| 663 | } |
||
| 664 | } |
||
| 665 | $ret .= $hookmanager->resPrint; |
||
| 666 | |||
| 667 | $ret .= '</select>'; |
||
| 668 | |||
| 669 | if (empty($conf->dol_optimize_smallscreen)) $ret .= ajax_combobox('.' . $name . 'select'); |
||
| 670 | |||
| 671 | // Warning: if you set submit button to disabled, post using 'Enter' will no more work if there is no another input submit. So we add a hidden button |
||
| 672 | $ret .= '<input type="submit" name="confirmmassactioninvisible" style="display: none" tabindex="-1">'; // Hidden button BEFORE so it is the one used when we submit with ENTER. |
||
| 673 | $ret .= '<input type="submit" disabled name="confirmmassaction" class="button'.(empty($conf->use_javascript_ajax) ? '' : ' hideobject').' ' . $name . ' ' . $name . 'confirmed" value="'.dol_escape_htmltag($langs->trans("Confirm")).'">'; |
||
| 674 | $ret .= '</div>'; |
||
| 675 | |||
| 676 | if (!empty($conf->use_javascript_ajax)) |
||
| 677 | { |
||
| 678 | $ret .= '<!-- JS CODE TO ENABLE mass action select --> |
||
| 679 | <script> |
||
| 680 | function initCheckForSelect(mode, name, cssclass) /* mode is 0 during init of page or click all, 1 when we click on 1 checkboxi, "name" refers to the class of the massaction button, "cssclass" to the class of the checkfor select boxes */ |
||
| 681 | { |
||
| 682 | atleastoneselected=0; |
||
| 683 | jQuery("."+cssclass).each(function( index ) { |
||
| 684 | /* console.log( index + ": " + $( this ).text() ); */ |
||
| 685 | if ($(this).is(\':checked\')) atleastoneselected++; |
||
| 686 | }); |
||
| 687 | |||
| 688 | console.log("initCheckForSelect mode="+mode+" name="+name+" cssclass="+cssclass+" atleastoneselected="+atleastoneselected); |
||
| 689 | |||
| 690 | if (atleastoneselected || '.$alwaysvisible.') |
||
| 691 | { |
||
| 692 | jQuery("."+name).show(); |
||
| 693 | '.($selected ? 'if (atleastoneselected) { jQuery("."+name+"select").val("'.$selected.'").trigger(\'change\'); jQuery("."+name+"confirmed").prop(\'disabled\', false); }' : '').' |
||
| 694 | '.($selected ? 'if (! atleastoneselected) { jQuery("."+name+"select").val("0").trigger(\'change\'); jQuery("."+name+"confirmed").prop(\'disabled\', true); } ' : '').' |
||
| 695 | } |
||
| 696 | else |
||
| 697 | { |
||
| 698 | jQuery("."+name).hide(); |
||
| 699 | jQuery("."+name+"other").hide(); |
||
| 700 | } |
||
| 701 | } |
||
| 702 | |||
| 703 | jQuery(document).ready(function () { |
||
| 704 | initCheckForSelect(0, "' . $name . '", "' . $cssclass . '"); |
||
| 705 | jQuery(".' . $cssclass . '").click(function() { |
||
| 706 | initCheckForSelect(1, "'.$name.'", "' . $cssclass . '"); |
||
| 707 | }); |
||
| 708 | jQuery(".' . $name . 'select").change(function() { |
||
| 709 | var massaction = $( this ).val(); |
||
| 710 | var urlform = $( this ).closest("form").attr("action").replace("#show_files",""); |
||
| 711 | if (massaction == "builddoc") |
||
| 712 | { |
||
| 713 | urlform = urlform + "#show_files"; |
||
| 714 | } |
||
| 715 | $( this ).closest("form").attr("action", urlform); |
||
| 716 | console.log("we select a mass action name='.$name.' massaction="+massaction+" - "+urlform); |
||
| 717 | /* Warning: if you set submit button to disabled, post using Enter will no more work if there is no other button */ |
||
| 718 | if ($(this).val() != \'0\') |
||
| 719 | { |
||
| 720 | jQuery(".' . $name . 'confirmed").prop(\'disabled\', false); |
||
| 721 | jQuery(".' . $name . 'other").hide(); /* To disable if another div was open */ |
||
| 722 | jQuery(".' . $name . '"+massaction).show(); |
||
| 723 | } |
||
| 724 | else |
||
| 725 | { |
||
| 726 | jQuery(".' . $name . 'confirmed").prop(\'disabled\', true); |
||
| 727 | jQuery(".' . $name . 'other").hide(); /* To disable any div open */ |
||
| 728 | } |
||
| 729 | }); |
||
| 730 | }); |
||
| 731 | </script> |
||
| 732 | '; |
||
| 733 | } |
||
| 734 | |||
| 735 | return $ret; |
||
| 736 | } |
||
| 737 | |||
| 738 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps |
||
| 739 | /** |
||
| 740 | * Return combo list of activated countries, into language of user |
||
| 741 | * |
||
| 742 | * @param string $selected Id or Code or Label of preselected country |
||
| 743 | * @param string $htmlname Name of html select object |
||
| 744 | * @param string $htmloption More html options on select object |
||
| 745 | * @param integer $maxlength Max length for labels (0=no limit) |
||
| 746 | * @param string $morecss More css class |
||
| 747 | * @param string $usecodeaskey ''=Use id as key (default), 'code3'=Use code on 3 alpha as key, 'code2"=Use code on 2 alpha as key |
||
| 748 | * @param int $showempty Show empty choice |
||
| 749 | * @param int $disablefavorites 1=Disable favorites, |
||
| 750 | * @param int $addspecialentries 1=Add dedicated entries for group of countries (like 'European Economic Community', ...) |
||
| 751 | * @param array $exclude_country_code Array of country code (iso2) to exclude |
||
| 752 | * @return string HTML string with select |
||
| 753 | */ |
||
| 754 | public function select_country($selected = '', $htmlname = 'country_id', $htmloption = '', $maxlength = 0, $morecss = 'minwidth300', $usecodeaskey = '', $showempty = 1, $disablefavorites = 0, $addspecialentries = 0, $exclude_country_code = array()) |
||
| 755 | { |
||
| 756 | // phpcs:enable |
||
| 757 | global $conf, $langs, $mysoc; |
||
| 758 | |||
| 759 | $langs->load("dict"); |
||
| 760 | |||
| 761 | $out = ''; |
||
| 762 | $countryArray = array(); |
||
| 763 | $favorite = array(); |
||
| 764 | $label = array(); |
||
| 765 | $atleastonefavorite = 0; |
||
| 766 | |||
| 767 | $sql = "SELECT rowid, code as code_iso, code_iso as code_iso3, label, favorite"; |
||
| 768 | $sql .= " FROM ".MAIN_DB_PREFIX."c_country"; |
||
| 769 | $sql .= " WHERE active > 0"; |
||
| 770 | //$sql.= " ORDER BY code ASC"; |
||
| 771 | |||
| 772 | dol_syslog(get_class($this)."::select_country", LOG_DEBUG); |
||
| 773 | $resql = $this->db->query($sql); |
||
| 774 | if ($resql) |
||
| 775 | { |
||
| 776 | $out .= '<select id="select'.$htmlname.'" class="flat maxwidth200onsmartphone selectcountry'.($morecss ? ' '.$morecss : '').'" name="'.$htmlname.'" '.$htmloption.'>'; |
||
| 777 | $num = $this->db->num_rows($resql); |
||
| 778 | $i = 0; |
||
| 779 | if ($num) |
||
| 780 | { |
||
| 781 | $foundselected = false; |
||
| 782 | |||
| 783 | while ($i < $num) |
||
| 784 | { |
||
| 785 | $obj = $this->db->fetch_object($resql); |
||
| 786 | |||
| 787 | $countryArray[$i]['rowid'] = $obj->rowid; |
||
| 788 | $countryArray[$i]['code_iso'] = $obj->code_iso; |
||
| 789 | $countryArray[$i]['code_iso3'] = $obj->code_iso3; |
||
| 790 | $countryArray[$i]['label'] = ($obj->code_iso && $langs->transnoentitiesnoconv("Country".$obj->code_iso) != "Country".$obj->code_iso ? $langs->transnoentitiesnoconv("Country".$obj->code_iso) : ($obj->label != '-' ? $obj->label : '')); |
||
| 791 | $countryArray[$i]['favorite'] = $obj->favorite; |
||
| 792 | $favorite[$i] = $obj->favorite; |
||
| 793 | $label[$i] = dol_string_unaccent($countryArray[$i]['label']); |
||
| 794 | $i++; |
||
| 795 | } |
||
| 796 | |||
| 797 | if (empty($disablefavorites)) array_multisort($favorite, SORT_DESC, $label, SORT_ASC, $countryArray); |
||
| 798 | else $countryArray = dol_sort_array($countryArray, 'label'); |
||
| 799 | |||
| 800 | if ($showempty) |
||
| 801 | { |
||
| 802 | $out .= '<option value=""> </option>'."\n"; |
||
| 803 | } |
||
| 804 | |||
| 805 | if ($addspecialentries) // Add dedicated entries for groups of countries |
||
| 806 | { |
||
| 807 | //if ($showempty) $out.= '<option value="" disabled class="selectoptiondisabledwhite">--------------</option>'; |
||
| 808 | $out .= '<option value="special_allnotme"'.($selected == 'special_allnotme' ? ' selected' : '').'>'.$langs->trans("CountriesExceptMe", $langs->transnoentitiesnoconv("Country".$mysoc->country_code)).'</option>'; |
||
| 809 | $out .= '<option value="special_eec"'.($selected == 'special_eec' ? ' selected' : '').'>'.$langs->trans("CountriesInEEC").'</option>'; |
||
| 810 | if ($mysoc->isInEEC()) $out .= '<option value="special_eecnotme"'.($selected == 'special_eecnotme' ? ' selected' : '').'>'.$langs->trans("CountriesInEECExceptMe", $langs->transnoentitiesnoconv("Country".$mysoc->country_code)).'</option>'; |
||
| 811 | $out .= '<option value="special_noteec"'.($selected == 'special_noteec' ? ' selected' : '').'>'.$langs->trans("CountriesNotInEEC").'</option>'; |
||
| 812 | $out .= '<option value="" disabled class="selectoptiondisabledwhite">--------------</option>'; |
||
| 813 | } |
||
| 814 | |||
| 815 | foreach ($countryArray as $row) |
||
| 816 | { |
||
| 817 | //if (empty($showempty) && empty($row['rowid'])) continue; |
||
| 818 | if (empty($row['rowid'])) continue; |
||
| 819 | if (is_array($exclude_country_code) && count($exclude_country_code) && in_array($row['code_iso'], $exclude_country_code)) continue; // exclude some countries |
||
| 820 | |||
| 821 | if (empty($disablefavorites) && $row['favorite'] && $row['code_iso']) $atleastonefavorite++; |
||
| 822 | if (empty($row['favorite']) && $atleastonefavorite) |
||
| 823 | { |
||
| 824 | $atleastonefavorite = 0; |
||
| 825 | $out .= '<option value="" disabled class="selectoptiondisabledwhite">--------------</option>'; |
||
| 826 | } |
||
| 827 | if ($selected && $selected != '-1' && ($selected == $row['rowid'] || $selected == $row['code_iso'] || $selected == $row['code_iso3'] || $selected == $row['label'])) |
||
| 828 | { |
||
| 829 | $foundselected = true; |
||
| 830 | $out .= '<option value="'.($usecodeaskey ? ($usecodeaskey == 'code2' ? $row['code_iso'] : $row['code_iso3']) : $row['rowid']).'" selected>'; |
||
| 831 | } else { |
||
| 832 | $out .= '<option value="'.($usecodeaskey ? ($usecodeaskey == 'code2' ? $row['code_iso'] : $row['code_iso3']) : $row['rowid']).'">'; |
||
| 833 | } |
||
| 834 | if ($row['label']) $out .= dol_trunc($row['label'], $maxlength, 'middle'); |
||
| 835 | else $out .= ' '; |
||
| 836 | if ($row['code_iso']) $out .= ' ('.$row['code_iso'].')'; |
||
| 837 | $out .= '</option>'; |
||
| 838 | } |
||
| 839 | } |
||
| 840 | $out .= '</select>'; |
||
| 841 | } else { |
||
| 842 | dol_print_error($this->db); |
||
| 843 | } |
||
| 844 | |||
| 845 | // Make select dynamic |
||
| 846 | include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php'; |
||
| 847 | $out .= ajax_combobox('select'.$htmlname); |
||
| 848 | |||
| 849 | return $out; |
||
| 850 | } |
||
| 851 | |||
| 852 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps |
||
| 853 | /** |
||
| 854 | * Return select list of incoterms |
||
| 855 | * |
||
| 856 | * @param string $selected Id or Code of preselected incoterm |
||
| 857 | * @param string $location_incoterms Value of input location |
||
| 858 | * @param string $page Defined the form action |
||
| 859 | * @param string $htmlname Name of html select object |
||
| 860 | * @param string $htmloption Options html on select object |
||
| 861 | * @param int $forcecombo Force to load all values and output a standard combobox (with no beautification) |
||
| 862 | * @param array $events Event options to run on change. Example: array(array('method'=>'getContacts', 'url'=>dol_buildpath('/core/ajax/contacts.php',1), 'htmlname'=>'contactid', 'params'=>array('add-customer-contact'=>'disabled'))) |
||
| 863 | * @return string HTML string with select and input |
||
| 864 | */ |
||
| 865 | public function select_incoterms($selected = '', $location_incoterms = '', $page = '', $htmlname = 'incoterm_id', $htmloption = '', $forcecombo = 1, $events = array()) |
||
| 866 | { |
||
| 867 | // phpcs:enable |
||
| 868 | global $conf, $langs; |
||
| 869 | |||
| 870 | $langs->load("dict"); |
||
| 871 | |||
| 872 | $out = ''; |
||
| 873 | $incotermArray = array(); |
||
| 874 | |||
| 875 | $sql = "SELECT rowid, code"; |
||
| 876 | $sql .= " FROM ".MAIN_DB_PREFIX."c_incoterms"; |
||
| 877 | $sql .= " WHERE active > 0"; |
||
| 878 | $sql .= " ORDER BY code ASC"; |
||
| 879 | |||
| 880 | dol_syslog(get_class($this)."::select_incoterm", LOG_DEBUG); |
||
| 881 | $resql = $this->db->query($sql); |
||
| 882 | if ($resql) |
||
| 883 | { |
||
| 884 | if ($conf->use_javascript_ajax && !$forcecombo) |
||
| 885 | { |
||
| 886 | include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php'; |
||
| 887 | $out .= ajax_combobox($htmlname, $events); |
||
| 888 | } |
||
| 889 | |||
| 890 | if (!empty($page)) |
||
| 891 | { |
||
| 892 | $out .= '<form method="post" action="'.$page.'">'; |
||
| 893 | $out .= '<input type="hidden" name="action" value="set_incoterms">'; |
||
| 894 | $out .= '<input type="hidden" name="token" value="'.newToken().'">'; |
||
| 895 | } |
||
| 896 | |||
| 897 | $out .= '<select id="'.$htmlname.'" class="flat selectincoterm minwidth100imp noenlargeonsmartphone" name="'.$htmlname.'" '.$htmloption.'>'; |
||
| 898 | $out .= '<option value="0"> </option>'; |
||
| 899 | $num = $this->db->num_rows($resql); |
||
| 900 | $i = 0; |
||
| 901 | if ($num) |
||
| 902 | { |
||
| 903 | $foundselected = false; |
||
| 904 | |||
| 905 | while ($i < $num) |
||
| 906 | { |
||
| 907 | $obj = $this->db->fetch_object($resql); |
||
| 908 | $incotermArray[$i]['rowid'] = $obj->rowid; |
||
| 909 | $incotermArray[$i]['code'] = $obj->code; |
||
| 910 | $i++; |
||
| 911 | } |
||
| 912 | |||
| 913 | foreach ($incotermArray as $row) |
||
| 914 | { |
||
| 915 | if ($selected && ($selected == $row['rowid'] || $selected == $row['code'])) |
||
| 916 | { |
||
| 917 | $out .= '<option value="'.$row['rowid'].'" selected>'; |
||
| 918 | } else { |
||
| 919 | $out .= '<option value="'.$row['rowid'].'">'; |
||
| 920 | } |
||
| 921 | |||
| 922 | if ($row['code']) $out .= $row['code']; |
||
| 923 | |||
| 924 | $out .= '</option>'; |
||
| 925 | } |
||
| 926 | } |
||
| 927 | $out .= '</select>'; |
||
| 928 | |||
| 929 | $out .= '<input id="location_incoterms" class="maxwidth100onsmartphone" name="location_incoterms" value="'.$location_incoterms.'">'; |
||
| 930 | |||
| 931 | if (!empty($page)) |
||
| 932 | { |
||
| 933 | $out .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'"></form>'; |
||
| 934 | } |
||
| 935 | } else { |
||
| 936 | dol_print_error($this->db); |
||
| 937 | } |
||
| 938 | |||
| 939 | return $out; |
||
| 940 | } |
||
| 941 | |||
| 942 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps |
||
| 943 | /** |
||
| 944 | * Return list of types of lines (product or service) |
||
| 945 | * Example: 0=product, 1=service, 9=other (for external module) |
||
| 946 | * |
||
| 947 | * @param string $selected Preselected type |
||
| 948 | * @param string $htmlname Name of field in html form |
||
| 949 | * @param int $showempty Add an empty field |
||
| 950 | * @param int $hidetext Do not show label 'Type' before combo box (used only if there is at least 2 choices to select) |
||
| 951 | * @param integer $forceall 1=Force to show products and services in combo list, whatever are activated modules, 0=No force, 2=Force to show only Products, 3=Force to show only services, -1=Force none (and set hidden field to 'service') |
||
| 952 | * @return void |
||
| 953 | */ |
||
| 954 | public function select_type_of_lines($selected = '', $htmlname = 'type', $showempty = 0, $hidetext = 0, $forceall = 0) |
||
| 955 | { |
||
| 956 | // phpcs:enable |
||
| 957 | global $db, $langs, $user, $conf; |
||
| 958 | |||
| 959 | // If product & services are enabled or both disabled. |
||
| 960 | if ($forceall == 1 || (empty($forceall) && !empty($conf->product->enabled) && !empty($conf->service->enabled)) |
||
| 961 | || (empty($forceall) && empty($conf->product->enabled) && empty($conf->service->enabled))) |
||
| 962 | { |
||
| 963 | if (empty($hidetext)) print $langs->trans("Type").': '; |
||
| 964 | print '<select class="flat" id="select_'.$htmlname.'" name="'.$htmlname.'">'; |
||
| 965 | if ($showempty) |
||
| 966 | { |
||
| 967 | print '<option value="-1"'; |
||
| 968 | if ($selected == -1) print ' selected'; |
||
| 969 | print '> </option>'; |
||
| 970 | } |
||
| 971 | |||
| 972 | print '<option value="0"'; |
||
| 973 | if (0 == $selected) print ' selected'; |
||
| 974 | print '>'.$langs->trans("Product"); |
||
| 975 | |||
| 976 | print '<option value="1"'; |
||
| 977 | if (1 == $selected) print ' selected'; |
||
| 978 | print '>'.$langs->trans("Service"); |
||
| 979 | |||
| 980 | print '</select>'; |
||
| 981 | //if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1); |
||
| 982 | } |
||
| 983 | if ((empty($forceall) && empty($conf->product->enabled) && !empty($conf->service->enabled)) || $forceall == 3) |
||
| 984 | { |
||
| 985 | print $langs->trans("Service"); |
||
| 986 | print '<input type="hidden" name="'.$htmlname.'" value="1">'; |
||
| 987 | } |
||
| 988 | if ((empty($forceall) && !empty($conf->product->enabled) && empty($conf->service->enabled)) || $forceall == 2) |
||
| 989 | { |
||
| 990 | print $langs->trans("Product"); |
||
| 991 | print '<input type="hidden" name="'.$htmlname.'" value="0">'; |
||
| 992 | } |
||
| 993 | if ($forceall < 0) // This should happened only for contracts when both predefined product and service are disabled. |
||
| 994 | { |
||
| 995 | print '<input type="hidden" name="'.$htmlname.'" value="1">'; // By default we set on service for contract. If CONTRACT_SUPPORT_PRODUCTS is set, forceall should be 1 not -1 |
||
| 996 | } |
||
| 997 | } |
||
| 998 | |||
| 999 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps |
||
| 1000 | /** |
||
| 1001 | * Load into cache cache_types_fees, array of types of fees |
||
| 1002 | * |
||
| 1003 | * @return int Nb of lines loaded, <0 if KO |
||
| 1004 | */ |
||
| 1005 | public function load_cache_types_fees() |
||
| 1006 | { |
||
| 1007 | // phpcs:enable |
||
| 1008 | global $langs; |
||
| 1009 | |||
| 1010 | $num = count($this->cache_types_fees); |
||
| 1011 | if ($num > 0) return 0; // Cache already loaded |
||
| 1012 | |||
| 1013 | dol_syslog(__METHOD__, LOG_DEBUG); |
||
| 1014 | |||
| 1015 | $langs->load("trips"); |
||
| 1016 | |||
| 1017 | $sql = "SELECT c.code, c.label"; |
||
| 1018 | $sql .= " FROM ".MAIN_DB_PREFIX."c_type_fees as c"; |
||
| 1019 | $sql .= " WHERE active > 0"; |
||
| 1020 | |||
| 1021 | $resql = $this->db->query($sql); |
||
| 1022 | if ($resql) |
||
| 1023 | { |
||
| 1024 | $num = $this->db->num_rows($resql); |
||
| 1025 | $i = 0; |
||
| 1026 | |||
| 1027 | while ($i < $num) |
||
| 1028 | { |
||
| 1029 | $obj = $this->db->fetch_object($resql); |
||
| 1030 | |||
| 1031 | // Si traduction existe, on l'utilise, sinon on prend le libelle par defaut |
||
| 1032 | $label = ($obj->code != $langs->trans($obj->code) ? $langs->trans($obj->code) : $langs->trans($obj->label)); |
||
| 1033 | $this->cache_types_fees[$obj->code] = $label; |
||
| 1034 | $i++; |
||
| 1035 | } |
||
| 1036 | |||
| 1037 | asort($this->cache_types_fees); |
||
| 1038 | |||
| 1039 | return $num; |
||
| 1040 | } else { |
||
| 1041 | dol_print_error($this->db); |
||
| 1042 | return -1; |
||
| 1043 | } |
||
| 1044 | } |
||
| 1045 | |||
| 1046 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps |
||
| 1047 | /** |
||
| 1048 | * Return list of types of notes |
||
| 1049 | * |
||
| 1050 | * @param string $selected Preselected type |
||
| 1051 | * @param string $htmlname Name of field in form |
||
| 1052 | * @param int $showempty Add an empty field |
||
| 1053 | * @return void |
||
| 1054 | */ |
||
| 1055 | public function select_type_fees($selected = '', $htmlname = 'type', $showempty = 0) |
||
| 1056 | { |
||
| 1057 | // phpcs:enable |
||
| 1058 | global $user, $langs; |
||
| 1059 | |||
| 1060 | dol_syslog(__METHOD__." selected=".$selected.", htmlname=".$htmlname, LOG_DEBUG); |
||
| 1061 | |||
| 1062 | $this->load_cache_types_fees(); |
||
| 1063 | |||
| 1064 | print '<select id="select_'.$htmlname.'" class="flat" name="'.$htmlname.'">'; |
||
| 1065 | if ($showempty) |
||
| 1066 | { |
||
| 1067 | print '<option value="-1"'; |
||
| 1068 | if ($selected == -1) print ' selected'; |
||
| 1069 | print '> </option>'; |
||
| 1070 | } |
||
| 1071 | |||
| 1072 | foreach ($this->cache_types_fees as $key => $value) |
||
| 1073 | { |
||
| 1074 | print '<option value="'.$key.'"'; |
||
| 1075 | if ($key == $selected) print ' selected'; |
||
| 1076 | print '>'; |
||
| 1077 | print $value; |
||
| 1078 | print '</option>'; |
||
| 1079 | } |
||
| 1080 | |||
| 1081 | print '</select>'; |
||
| 1082 | if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1); |
||
| 1083 | } |
||
| 1084 | |||
| 1085 | |||
| 1086 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps |
||
| 1087 | /** |
||
| 1088 | * Return HTML code to select a company. |
||
| 1089 | * |
||
| 1090 | * @param int $selected Preselected products |
||
| 1091 | * @param string $htmlname Name of HTML select field (must be unique in page) |
||
| 1092 | * @param int $filter Filter on thirdparty |
||
| 1093 | * @param int $limit Limit on number of returned lines |
||
| 1094 | * @param array $ajaxoptions Options for ajax_autocompleter |
||
| 1095 | * @param int $forcecombo Force to load all values and output a standard combobox (with no beautification) |
||
| 1096 | * @return string Return select box for thirdparty. |
||
| 1097 | * @deprecated 3.8 Use select_company instead. For exemple $form->select_thirdparty(GETPOST('socid'),'socid','',0) => $form->select_company(GETPOST('socid'),'socid','',1,0,0,array(),0) |
||
| 1098 | */ |
||
| 1099 | public function select_thirdparty($selected = '', $htmlname = 'socid', $filter = '', $limit = 20, $ajaxoptions = array(), $forcecombo = 0) |
||
| 1100 | { |
||
| 1101 | // phpcs:enable |
||
| 1102 | return $this->select_thirdparty_list($selected, $htmlname, $filter, 1, 0, $forcecombo, array(), '', 0, $limit); |
||
| 1103 | } |
||
| 1104 | |||
| 1105 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps |
||
| 1106 | /** |
||
| 1107 | * Output html form to select a third party |
||
| 1108 | * |
||
| 1109 | * @param string $selected Preselected type |
||
| 1110 | * @param string $htmlname Name of field in form |
||
| 1111 | * @param string $filter Optional filters criteras. WARNING: To avoid SQL injection, only few chars [.a-z0-9 =<>] are allowed here (example: 's.rowid <> x', 's.client IN (1,3)') |
||
| 1112 | * @param string $showempty Add an empty field (Can be '1' or text key to use on empty line like 'SelectThirdParty') |
||
| 1113 | * @param int $showtype Show third party type in combolist (customer, prospect or supplier) |
||
| 1114 | * @param int $forcecombo Force to load all values and output a standard combobox (with no beautification) |
||
| 1115 | * @param array $events Ajax event options to run on change. Example: array(array('method'=>'getContacts', 'url'=>dol_buildpath('/core/ajax/contacts.php',1), 'htmlname'=>'contactid', 'params'=>array('add-customer-contact'=>'disabled'))) |
||
| 1116 | * @param int $limit Maximum number of elements |
||
| 1117 | * @param string $morecss Add more css styles to the SELECT component |
||
| 1118 | * @param string $moreparam Add more parameters onto the select tag. For example 'style="width: 95%"' to avoid select2 component to go over parent container |
||
| 1119 | * @param string $selected_input_value Value of preselected input text (for use with ajax) |
||
| 1120 | * @param int $hidelabel Hide label (0=no, 1=yes, 2=show search icon (before) and placeholder, 3 search icon after) |
||
| 1121 | * @param array $ajaxoptions Options for ajax_autocompleter |
||
| 1122 | * @param bool $multiple add [] in the name of element and add 'multiple' attribut (not working with ajax_autocompleter) |
||
| 1123 | * @return string HTML string with select box for thirdparty. |
||
| 1124 | */ |
||
| 1125 | public function select_company($selected = '', $htmlname = 'socid', $filter = '', $showempty = '', $showtype = 0, $forcecombo = 0, $events = array(), $limit = 0, $morecss = 'minwidth100', $moreparam = '', $selected_input_value = '', $hidelabel = 1, $ajaxoptions = array(), $multiple = false) |
||
| 1126 | { |
||
| 1127 | // phpcs:enable |
||
| 1128 | global $conf, $user, $langs; |
||
| 1129 | |||
| 1130 | $out = ''; |
||
| 1131 | |||
| 1132 | if (!empty($conf->use_javascript_ajax) && !empty($conf->global->COMPANY_USE_SEARCH_TO_SELECT) && !$forcecombo) |
||
| 1133 | { |
||
| 1134 | // No immediate load of all database |
||
| 1135 | $placeholder = ''; |
||
| 1136 | if ($selected && empty($selected_input_value)) |
||
| 1137 | { |
||
| 1138 | require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php'; |
||
| 1139 | $societetmp = new Societe($this->db); |
||
| 1140 | $societetmp->fetch($selected); |
||
| 1141 | $selected_input_value = $societetmp->name; |
||
| 1142 | unset($societetmp); |
||
| 1143 | } |
||
| 1144 | // mode 1 |
||
| 1145 | $urloption = 'htmlname='.urlencode($htmlname).'&outjson=1&filter='.urlencode($filter).($showtype ? '&showtype='.urlencode($showtype) : ''); |
||
| 1146 | $out .= ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT.'/societe/ajax/company.php', $urloption, $conf->global->COMPANY_USE_SEARCH_TO_SELECT, 0, $ajaxoptions); |
||
| 1147 | $out .= '<style type="text/css">.ui-autocomplete { z-index: 250; }</style>'; |
||
| 1148 | if (empty($hidelabel)) print $langs->trans("RefOrLabel").' : '; |
||
| 1149 | elseif ($hidelabel > 1) { |
||
| 1150 | $placeholder = ' placeholder="'.$langs->trans("RefOrLabel").'"'; |
||
| 1151 | if ($hidelabel == 2) { |
||
| 1152 | $out .= img_picto($langs->trans("Search"), 'search'); |
||
| 1153 | } |
||
| 1154 | } |
||
| 1155 | $out .= '<input type="text" class="'.$morecss.'" name="search_'.$htmlname.'" id="search_'.$htmlname.'" value="'.$selected_input_value.'"'.$placeholder.' '.(!empty($conf->global->THIRDPARTY_SEARCH_AUTOFOCUS) ? 'autofocus' : '').' />'; |
||
| 1156 | if ($hidelabel == 3) { |
||
| 1157 | $out .= img_picto($langs->trans("Search"), 'search'); |
||
| 1158 | } |
||
| 1159 | } else { |
||
| 1160 | // Immediate load of all database |
||
| 1161 | $out .= $this->select_thirdparty_list($selected, $htmlname, $filter, $showempty, $showtype, $forcecombo, $events, '', 0, $limit, $morecss, $moreparam, $multiple); |
||
| 1162 | } |
||
| 1163 | |||
| 1164 | return $out; |
||
| 1165 | } |
||
| 1166 | |||
| 1167 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps |
||
| 1168 | /** |
||
| 1169 | * Output html form to select a third party. |
||
| 1170 | * Note, you must use the select_company to get the component to select a third party. This function must only be called by select_company. |
||
| 1171 | * |
||
| 1172 | * @param string $selected Preselected type |
||
| 1173 | * @param string $htmlname Name of field in form |
||
| 1174 | * @param string $filter Optional filters criteras (example: 's.rowid <> x', 's.client in (1,3)') |
||
| 1175 | * @param string $showempty Add an empty field (Can be '1' or text to use on empty line like 'SelectThirdParty') |
||
| 1176 | * @param int $showtype Show third party type in combolist (customer, prospect or supplier) |
||
| 1177 | * @param int $forcecombo Force to use standard HTML select component without beautification |
||
| 1178 | * @param array $events Event options. Example: array(array('method'=>'getContacts', 'url'=>dol_buildpath('/core/ajax/contacts.php',1), 'htmlname'=>'contactid', 'params'=>array('add-customer-contact'=>'disabled'))) |
||
| 1179 | * @param string $filterkey Filter on key value |
||
| 1180 | * @param int $outputmode 0=HTML select string, 1=Array |
||
| 1181 | * @param int $limit Limit number of answers |
||
| 1182 | * @param string $morecss Add more css styles to the SELECT component |
||
| 1183 | * @param string $moreparam Add more parameters onto the select tag. For example 'style="width: 95%"' to avoid select2 component to go over parent container |
||
| 1184 | * @param bool $multiple add [] in the name of element and add 'multiple' attribut |
||
| 1185 | * @return string HTML string with |
||
| 1186 | */ |
||
| 1187 | public function select_thirdparty_list($selected = '', $htmlname = 'socid', $filter = '', $showempty = '', $showtype = 0, $forcecombo = 0, $events = array(), $filterkey = '', $outputmode = 0, $limit = 0, $morecss = 'minwidth100', $moreparam = '', $multiple = false) |
||
| 1188 | { |
||
| 1189 | // phpcs:enable |
||
| 1190 | global $conf, $user, $langs; |
||
| 1191 | |||
| 1192 | $out = ''; |
||
| 1193 | $num = 0; |
||
| 1194 | $outarray = array(); |
||
| 1195 | |||
| 1196 | if ($selected === '') $selected = array(); |
||
| 1197 | elseif (!is_array($selected)) $selected = array($selected); |
||
| 1198 | |||
| 1199 | // Clean $filter that may contains sql conditions so sql code |
||
| 1200 | if (function_exists('testSqlAndScriptInject')) { |
||
| 1201 | if (testSqlAndScriptInject($filter, 3) > 0) { |
||
| 1202 | $filter = ''; |
||
| 1203 | } |
||
| 1204 | } |
||
| 1205 | |||
| 1206 | // On recherche les societes |
||
| 1207 | $sql = "SELECT s.rowid, s.nom as name, s.name_alias, s.client, s.fournisseur, s.code_client, s.code_fournisseur"; |
||
| 1208 | |||
| 1209 | if ($conf->global->COMPANY_SHOW_ADDRESS_SELECTLIST) { |
||
| 1210 | $sql .= ", s.address, s.zip, s.town"; |
||
| 1211 | $sql .= ", dictp.code as country_code"; |
||
| 1212 | } |
||
| 1213 | |||
| 1214 | $sql .= " FROM ".MAIN_DB_PREFIX."societe as s"; |
||
| 1215 | if (!$user->rights->societe->client->voir && !$user->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; |
||
| 1216 | if ($conf->global->COMPANY_SHOW_ADDRESS_SELECTLIST) { |
||
| 1217 | $sql .= " LEFT OUTER JOIN ".MAIN_DB_PREFIX."c_country as dictp ON dictp.rowid=s.fk_pays"; |
||
| 1218 | } |
||
| 1219 | $sql .= " WHERE s.entity IN (".getEntity('societe').")"; |
||
| 1220 | if (!empty($user->socid)) $sql .= " AND s.rowid = ".$user->socid; |
||
| 1221 | if ($filter) $sql .= " AND (".$filter.")"; |
||
| 1222 | if (!$user->rights->societe->client->voir && !$user->socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id; |
||
| 1223 | if (!empty($conf->global->COMPANY_HIDE_INACTIVE_IN_COMBOBOX)) $sql .= " AND s.status <> 0"; |
||
| 1224 | // Add criteria |
||
| 1225 | if ($filterkey && $filterkey != '') |
||
| 1226 | { |
||
| 1227 | $sql .= " AND ("; |
||
| 1228 | $prefix = empty($conf->global->COMPANY_DONOTSEARCH_ANYWHERE) ? '%' : ''; // Can use index if COMPANY_DONOTSEARCH_ANYWHERE is on |
||
| 1229 | // For natural search |
||
| 1230 | $scrit = explode(' ', $filterkey); |
||
| 1231 | $i = 0; |
||
| 1232 | if (count($scrit) > 1) $sql .= "("; |
||
| 1233 | foreach ($scrit as $crit) { |
||
| 1234 | if ($i > 0) $sql .= " AND "; |
||
| 1235 | $sql .= "(s.nom LIKE '".$this->db->escape($prefix.$crit)."%')"; |
||
| 1236 | $i++; |
||
| 1237 | } |
||
| 1238 | if (count($scrit) > 1) $sql .= ")"; |
||
| 1239 | if (!empty($conf->barcode->enabled)) |
||
| 1240 | { |
||
| 1241 | $sql .= " OR s.barcode LIKE '".$this->db->escape($prefix.$filterkey)."%'"; |
||
| 1242 | } |
||
| 1243 | $sql .= " OR s.code_client LIKE '".$this->db->escape($prefix.$filterkey)."%' OR s.code_fournisseur LIKE '".$this->db->escape($prefix.$filterkey)."%'"; |
||
| 1244 | $sql .= ")"; |
||
| 1245 | } |
||
| 1246 | $sql .= $this->db->order("nom", "ASC"); |
||
| 1247 | $sql .= $this->db->plimit($limit, 0); |
||
| 1248 | |||
| 1249 | // Build output string |
||
| 1250 | dol_syslog(get_class($this)."::select_thirdparty_list", LOG_DEBUG); |
||
| 1251 | $resql = $this->db->query($sql); |
||
| 1252 | if ($resql) |
||
| 1253 | { |
||
| 1254 | if (!$forcecombo) |
||
| 1255 | { |
||
| 1256 | include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php'; |
||
| 1257 | $out .= ajax_combobox($htmlname, $events, $conf->global->COMPANY_USE_SEARCH_TO_SELECT); |
||
| 1258 | } |
||
| 1259 | |||
| 1260 | // Construct $out and $outarray |
||
| 1261 | $out .= '<select id="'.$htmlname.'" class="flat'.($morecss ? ' '.$morecss : '').'"'.($moreparam ? ' '.$moreparam : '').' name="'.$htmlname.($multiple ? '[]' : '').'" '.($multiple ? 'multiple' : '').'>'."\n"; |
||
| 1262 | |||
| 1263 | $textifempty = (($showempty && !is_numeric($showempty)) ? $langs->trans($showempty) : ''); |
||
| 1264 | if (!empty($conf->global->COMPANY_USE_SEARCH_TO_SELECT)) |
||
| 1265 | { |
||
| 1266 | // Do not use textifempty = ' ' or ' ' here, or search on key will search on ' key'. |
||
| 1267 | //if (! empty($conf->use_javascript_ajax) || $forcecombo) $textifempty=''; |
||
| 1268 | if ($showempty && !is_numeric($showempty)) $textifempty = $langs->trans($showempty); |
||
| 1269 | else $textifempty .= $langs->trans("All"); |
||
| 1270 | } |
||
| 1271 | if ($showempty) $out .= '<option value="-1">'.$textifempty.'</option>'."\n"; |
||
| 1272 | |||
| 1273 | $num = $this->db->num_rows($resql); |
||
| 1274 | $i = 0; |
||
| 1275 | if ($num) |
||
| 1276 | { |
||
| 1277 | while ($i < $num) |
||
| 1278 | { |
||
| 1279 | $obj = $this->db->fetch_object($resql); |
||
| 1280 | $label = ''; |
||
| 1281 | if ($conf->global->SOCIETE_ADD_REF_IN_LIST) { |
||
| 1282 | if (($obj->client) && (!empty($obj->code_client))) { |
||
| 1283 | $label = $obj->code_client.' - '; |
||
| 1284 | } |
||
| 1285 | if (($obj->fournisseur) && (!empty($obj->code_fournisseur))) { |
||
| 1286 | $label .= $obj->code_fournisseur.' - '; |
||
| 1287 | } |
||
| 1288 | $label .= ' '.$obj->name; |
||
| 1289 | } else { |
||
| 1290 | $label = $obj->name; |
||
| 1291 | } |
||
| 1292 | |||
| 1293 | if (!empty($obj->name_alias)) { |
||
| 1294 | $label .= ' ('.$obj->name_alias.')'; |
||
| 1295 | } |
||
| 1296 | |||
| 1297 | if ($showtype) |
||
| 1298 | { |
||
| 1299 | if ($obj->client || $obj->fournisseur) $label .= ' ('; |
||
| 1300 | if ($obj->client == 1 || $obj->client == 3) $label .= $langs->trans("Customer"); |
||
| 1301 | if ($obj->client == 2 || $obj->client == 3) $label .= ($obj->client == 3 ? ', ' : '').$langs->trans("Prospect"); |
||
| 1302 | if ($obj->fournisseur) $label .= ($obj->client ? ', ' : '').$langs->trans("Supplier"); |
||
| 1303 | if ($obj->client || $obj->fournisseur) $label .= ')'; |
||
| 1304 | } |
||
| 1305 | |||
| 1306 | if ($conf->global->COMPANY_SHOW_ADDRESS_SELECTLIST) { |
||
| 1307 | $label .= '-'.$obj->address.'-'.$obj->zip.' '.$obj->town; |
||
| 1308 | if (!empty($obj->country_code)) { |
||
| 1309 | $label .= ' '.$langs->trans('Country'.$obj->country_code); |
||
| 1310 | } |
||
| 1311 | } |
||
| 1312 | |||
| 1313 | if (empty($outputmode)) |
||
| 1314 | { |
||
| 1315 | if (in_array($obj->rowid, $selected)) |
||
| 1316 | { |
||
| 1317 | $out .= '<option value="'.$obj->rowid.'" selected>'.$label.'</option>'; |
||
| 1318 | } else { |
||
| 1319 | $out .= '<option value="'.$obj->rowid.'">'.$label.'</option>'; |
||
| 1320 | } |
||
| 1321 | } else { |
||
| 1322 | array_push($outarray, array('key'=>$obj->rowid, 'value'=>$label, 'label'=>$label)); |
||
| 1323 | } |
||
| 1324 | |||
| 1325 | $i++; |
||
| 1326 | if (($i % 10) == 0) $out .= "\n"; |
||
| 1327 | } |
||
| 1328 | } |
||
| 1329 | $out .= '</select>'."\n"; |
||
| 1330 | } else { |
||
| 1331 | dol_print_error($this->db); |
||
| 1332 | } |
||
| 1333 | |||
| 1334 | $this->result = array('nbofthirdparties'=>$num); |
||
| 1335 | |||
| 1336 | if ($outputmode) return $outarray; |
||
| 1337 | return $out; |
||
| 1338 | } |
||
| 1339 | |||
| 1340 | |||
| 1341 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps |
||
| 1342 | /** |
||
| 1343 | * Return HTML combo list of absolute discounts |
||
| 1344 | * |
||
| 1345 | * @param string $selected Id remise fixe pre-selectionnee |
||
| 1346 | * @param string $htmlname Nom champ formulaire |
||
| 1347 | * @param string $filter Criteres optionnels de filtre |
||
| 1348 | * @param int $socid Id of thirdparty |
||
| 1349 | * @param int $maxvalue Max value for lines that can be selected |
||
| 1350 | * @return int Return number of qualifed lines in list |
||
| 1351 | */ |
||
| 1352 | public function select_remises($selected, $htmlname, $filter, $socid, $maxvalue = 0) |
||
| 1353 | { |
||
| 1354 | // phpcs:enable |
||
| 1355 | global $langs, $conf; |
||
| 1356 | |||
| 1357 | // On recherche les remises |
||
| 1358 | $sql = "SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,"; |
||
| 1359 | $sql .= " re.description, re.fk_facture_source"; |
||
| 1360 | $sql .= " FROM ".MAIN_DB_PREFIX."societe_remise_except as re"; |
||
| 1361 | $sql .= " WHERE re.fk_soc = ".(int) $socid; |
||
| 1362 | $sql .= " AND re.entity = ".$conf->entity; |
||
| 1363 | if ($filter) $sql .= " AND ".$filter; |
||
| 1364 | $sql .= " ORDER BY re.description ASC"; |
||
| 1365 | |||
| 1366 | dol_syslog(get_class($this)."::select_remises", LOG_DEBUG); |
||
| 1367 | $resql = $this->db->query($sql); |
||
| 1368 | if ($resql) |
||
| 1369 | { |
||
| 1370 | print '<select id="select_'.$htmlname.'" class="flat maxwidthonsmartphone" name="'.$htmlname.'">'; |
||
| 1371 | $num = $this->db->num_rows($resql); |
||
| 1372 | |||
| 1373 | $qualifiedlines = $num; |
||
| 1374 | |||
| 1375 | $i = 0; |
||
| 1376 | if ($num) |
||
| 1377 | { |
||
| 1378 | print '<option value="0"> </option>'; |
||
| 1379 | while ($i < $num) |
||
| 1380 | { |
||
| 1381 | $obj = $this->db->fetch_object($resql); |
||
| 1382 | $desc = dol_trunc($obj->description, 40); |
||
| 1383 | if (preg_match('/\(CREDIT_NOTE\)/', $desc)) $desc = preg_replace('/\(CREDIT_NOTE\)/', $langs->trans("CreditNote"), $desc); |
||
| 1384 | if (preg_match('/\(DEPOSIT\)/', $desc)) $desc = preg_replace('/\(DEPOSIT\)/', $langs->trans("Deposit"), $desc); |
||
| 1385 | if (preg_match('/\(EXCESS RECEIVED\)/', $desc)) $desc = preg_replace('/\(EXCESS RECEIVED\)/', $langs->trans("ExcessReceived"), $desc); |
||
| 1386 | if (preg_match('/\(EXCESS PAID\)/', $desc)) $desc = preg_replace('/\(EXCESS PAID\)/', $langs->trans("ExcessPaid"), $desc); |
||
| 1387 | |||
| 1388 | $selectstring = ''; |
||
| 1389 | if ($selected > 0 && $selected == $obj->rowid) $selectstring = ' selected'; |
||
| 1390 | |||
| 1391 | $disabled = ''; |
||
| 1392 | if ($maxvalue > 0 && $obj->amount_ttc > $maxvalue) |
||
| 1393 | { |
||
| 1394 | $qualifiedlines--; |
||
| 1395 | $disabled = ' disabled'; |
||
| 1396 | } |
||
| 1397 | |||
| 1398 | if (!empty($conf->global->MAIN_SHOW_FACNUMBER_IN_DISCOUNT_LIST) && !empty($obj->fk_facture_source)) |
||
| 1399 | { |
||
| 1400 | $tmpfac = new Facture($this->db); |
||
| 1401 | if ($tmpfac->fetch($obj->fk_facture_source) > 0) $desc = $desc.' - '.$tmpfac->ref; |
||
| 1402 | } |
||
| 1403 | |||
| 1404 | print '<option value="'.$obj->rowid.'"'.$selectstring.$disabled.'>'.$desc.' ('.price($obj->amount_ht).' '.$langs->trans("HT").' - '.price($obj->amount_ttc).' '.$langs->trans("TTC").')</option>'; |
||
| 1405 | $i++; |
||
| 1406 | } |
||
| 1407 | } |
||
| 1408 | print '</select>'; |
||
| 1409 | return $qualifiedlines; |
||
| 1410 | } else { |
||
| 1411 | dol_print_error($this->db); |
||
| 1412 | return -1; |
||
| 1413 | } |
||
| 1414 | } |
||
| 1415 | |||
| 1416 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps |
||
| 1417 | /** |
||
| 1418 | * Return list of all contacts (for a third party or all) |
||
| 1419 | * |
||
| 1420 | * @param int $socid Id ot third party or 0 for all |
||
| 1421 | * @param string $selected Id contact pre-selectionne |
||
| 1422 | * @param string $htmlname Name of HTML field ('none' for a not editable field) |
||
| 1423 | * @param int $showempty 0=no empty value, 1=add an empty value, 2=add line 'Internal' (used by user edit), 3=add an empty value only if more than one record into list |
||
| 1424 | * @param string $exclude List of contacts id to exclude |
||
| 1425 | * @param string $limitto Disable answers that are not id in this array list |
||
| 1426 | * @param integer $showfunction Add function into label |
||
| 1427 | * @param string $moreclass Add more class to class style |
||
| 1428 | * @param integer $showsoc Add company into label |
||
| 1429 | * @param int $forcecombo Force to use combo box |
||
| 1430 | * @param array $events Event options. Example: array(array('method'=>'getContacts', 'url'=>dol_buildpath('/core/ajax/contacts.php',1), 'htmlname'=>'contactid', 'params'=>array('add-customer-contact'=>'disabled'))) |
||
| 1431 | * @param bool $options_only Return options only (for ajax treatment) |
||
| 1432 | * @param string $moreparam Add more parameters onto the select tag. For example 'style="width: 95%"' to avoid select2 component to go over parent container |
||
| 1433 | * @param string $htmlid Html id to use instead of htmlname |
||
| 1434 | * @return int <0 if KO, Nb of contact in list if OK |
||
| 1435 | * @deprected You can use selectcontacts directly (warning order of param was changed) |
||
| 1436 | */ |
||
| 1437 | public function select_contacts($socid, $selected = '', $htmlname = 'contactid', $showempty = 0, $exclude = '', $limitto = '', $showfunction = 0, $moreclass = '', $showsoc = 0, $forcecombo = 0, $events = array(), $options_only = false, $moreparam = '', $htmlid = '') |
||
| 1438 | { |
||
| 1439 | // phpcs:enable |
||
| 1440 | print $this->selectcontacts($socid, $selected, $htmlname, $showempty, $exclude, $limitto, $showfunction, $moreclass, $options_only, $showsoc, $forcecombo, $events, $moreparam, $htmlid); |
||
| 1441 | return $this->num; |
||
| 1442 | } |
||
| 1443 | |||
| 1444 | /** |
||
| 1445 | * Return HTML code of the SELECT of list of all contacts (for a third party or all). |
||
| 1446 | * This also set the number of contacts found into $this->num |
||
| 1447 | * |
||
| 1448 | * @since 9.0 Add afterSelectContactOptions hook |
||
| 1449 | * |
||
| 1450 | * @param int $socid Id ot third party or 0 for all or -1 for empty list |
||
| 1451 | * @param array|int $selected Array of ID of pre-selected contact id |
||
| 1452 | * @param string $htmlname Name of HTML field ('none' for a not editable field) |
||
| 1453 | * @param int $showempty 0=no empty value, 1=add an empty value, 2=add line 'Internal' (used by user edit), 3=add an empty value only if more than one record into list |
||
| 1454 | * @param string $exclude List of contacts id to exclude |
||
| 1455 | * @param string $limitto Disable answers that are not id in this array list |
||
| 1456 | * @param integer $showfunction Add function into label |
||
| 1457 | * @param string $moreclass Add more class to class style |
||
| 1458 | * @param bool $options_only Return options only (for ajax treatment) |
||
| 1459 | * @param integer $showsoc Add company into label |
||
| 1460 | * @param int $forcecombo Force to use combo box (so no ajax beautify effect) |
||
| 1461 | * @param array $events Event options. Example: array(array('method'=>'getContacts', 'url'=>dol_buildpath('/core/ajax/contacts.php',1), 'htmlname'=>'contactid', 'params'=>array('add-customer-contact'=>'disabled'))) |
||
| 1462 | * @param string $moreparam Add more parameters onto the select tag. For example 'style="width: 95%"' to avoid select2 component to go over parent container |
||
| 1463 | * @param string $htmlid Html id to use instead of htmlname |
||
| 1464 | * @param bool $multiple add [] in the name of element and add 'multiple' attribut |
||
| 1465 | * @return int <0 if KO, Nb of contact in list if OK |
||
| 1466 | */ |
||
| 1467 | public function selectcontacts($socid, $selected = '', $htmlname = 'contactid', $showempty = 0, $exclude = '', $limitto = '', $showfunction = 0, $moreclass = '', $options_only = false, $showsoc = 0, $forcecombo = 0, $events = array(), $moreparam = '', $htmlid = '', $multiple = false) |
||
| 1468 | { |
||
| 1469 | global $conf, $langs, $hookmanager, $action; |
||
| 1470 | |||
| 1471 | $langs->load('companies'); |
||
| 1472 | |||
| 1473 | if (empty($htmlid)) $htmlid = $htmlname; |
||
| 1474 | |||
| 1475 | if ($selected === '') $selected = array(); |
||
| 1476 | elseif (!is_array($selected)) $selected = array($selected); |
||
| 1477 | $out = ''; |
||
| 1478 | |||
| 1479 | if (!is_object($hookmanager)) |
||
| 1480 | { |
||
| 1481 | include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; |
||
| 1482 | $hookmanager = new HookManager($this->db); |
||
| 1483 | } |
||
| 1484 | |||
| 1485 | // We search third parties |
||
| 1486 | $sql = "SELECT sp.rowid, sp.lastname, sp.statut, sp.firstname, sp.poste"; |
||
| 1487 | if ($showsoc > 0) $sql .= " , s.nom as company"; |
||
| 1488 | $sql .= " FROM ".MAIN_DB_PREFIX."socpeople as sp"; |
||
| 1489 | if ($showsoc > 0) $sql .= " LEFT OUTER JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid=sp.fk_soc"; |
||
| 1490 | $sql .= " WHERE sp.entity IN (".getEntity('socpeople').")"; |
||
| 1491 | if ($socid > 0 || $socid == -1) $sql .= " AND sp.fk_soc=".$socid; |
||
| 1492 | if (!empty($conf->global->CONTACT_HIDE_INACTIVE_IN_COMBOBOX)) $sql .= " AND sp.statut <> 0"; |
||
| 1493 | $sql .= " ORDER BY sp.lastname ASC"; |
||
| 1494 | |||
| 1495 | dol_syslog(get_class($this)."::select_contacts", LOG_DEBUG); |
||
| 1496 | $resql = $this->db->query($sql); |
||
| 1497 | if ($resql) |
||
| 1498 | { |
||
| 1499 | $num = $this->db->num_rows($resql); |
||
| 1500 | |||
| 1501 | if ($conf->use_javascript_ajax && !$forcecombo && !$options_only) |
||
| 1502 | { |
||
| 1503 | include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php'; |
||
| 1504 | $out .= ajax_combobox($htmlid, $events, $conf->global->CONTACT_USE_SEARCH_TO_SELECT); |
||
| 1505 | } |
||
| 1506 | |||
| 1507 | if ($htmlname != 'none' && !$options_only) $out .= '<select class="flat'.($moreclass ? ' '.$moreclass : '').'" id="'.$htmlid.'" name="'.$htmlname.($multiple ? '[]' : '').'" '.($multiple ? 'multiple' : '').' '.(!empty($moreparam) ? $moreparam : '').'>'; |
||
| 1508 | if (($showempty == 1 || ($showempty == 3 && $num > 1)) && !$multiple) $out .= '<option value="0"'.(in_array(0, $selected) ? ' selected' : '').'> </option>'; |
||
| 1509 | if ($showempty == 2) $out .= '<option value="0"'.(in_array(0, $selected) ? ' selected' : '').'>-- '.$langs->trans("Internal").' --</option>'; |
||
| 1510 | |||
| 1511 | $num = $this->db->num_rows($resql); |
||
| 1512 | $i = 0; |
||
| 1513 | if ($num) |
||
| 1514 | { |
||
| 1515 | include_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php'; |
||
| 1516 | $contactstatic = new Contact($this->db); |
||
| 1517 | |||
| 1518 | while ($i < $num) |
||
| 1519 | { |
||
| 1520 | $obj = $this->db->fetch_object($resql); |
||
| 1521 | |||
| 1522 | $contactstatic->id = $obj->rowid; |
||
| 1523 | $contactstatic->lastname = $obj->lastname; |
||
| 1524 | $contactstatic->firstname = $obj->firstname; |
||
| 1525 | if ($obj->statut == 1) { |
||
| 1526 | if ($htmlname != 'none') |
||
| 1527 | { |
||
| 1528 | $disabled = 0; |
||
| 1529 | if (is_array($exclude) && count($exclude) && in_array($obj->rowid, $exclude)) $disabled = 1; |
||
| 1530 | if (is_array($limitto) && count($limitto) && !in_array($obj->rowid, $limitto)) $disabled = 1; |
||
| 1531 | if (!empty($selected) && in_array($obj->rowid, $selected)) |
||
| 1532 | { |
||
| 1533 | $out .= '<option value="'.$obj->rowid.'"'; |
||
| 1534 | if ($disabled) $out .= ' disabled'; |
||
| 1535 | $out .= ' selected>'; |
||
| 1536 | $out .= $contactstatic->getFullName($langs); |
||
| 1537 | if ($showfunction && $obj->poste) $out .= ' ('.$obj->poste.')'; |
||
| 1538 | if (($showsoc > 0) && $obj->company) $out .= ' - ('.$obj->company.')'; |
||
| 1539 | $out .= '</option>'; |
||
| 1540 | } else { |
||
| 1541 | $out .= '<option value="'.$obj->rowid.'"'; |
||
| 1542 | if ($disabled) $out .= ' disabled'; |
||
| 1543 | $out .= '>'; |
||
| 1544 | $out .= $contactstatic->getFullName($langs); |
||
| 1545 | if ($showfunction && $obj->poste) $out .= ' ('.$obj->poste.')'; |
||
| 1546 | if (($showsoc > 0) && $obj->company) $out .= ' - ('.$obj->company.')'; |
||
| 1547 | $out .= '</option>'; |
||
| 1548 | } |
||
| 1549 | } else { |
||
| 1550 | if (in_array($obj->rowid, $selected)) |
||
| 1551 | { |
||
| 1552 | $out .= $contactstatic->getFullName($langs); |
||
| 1553 | if ($showfunction && $obj->poste) $out .= ' ('.$obj->poste.')'; |
||
| 1554 | if (($showsoc > 0) && $obj->company) $out .= ' - ('.$obj->company.')'; |
||
| 1555 | } |
||
| 1556 | } |
||
| 1557 | } |
||
| 1558 | $i++; |
||
| 1559 | } |
||
| 1560 | } else { |
||
| 1561 | $out .= '<option value="-1"'.(($showempty == 2 || $multiple) ? '' : ' selected').' disabled>'; |
||
| 1562 | $out .= ($socid != -1) ? ($langs->trans($socid ? "NoContactDefinedForThirdParty" : "NoContactDefined")) : $langs->trans('SelectAThirdPartyFirst'); |
||
| 1563 | $out .= '</option>'; |
||
| 1564 | } |
||
| 1565 | |||
| 1566 | $parameters = array( |
||
| 1567 | 'socid'=>$socid, |
||
| 1568 | 'htmlname'=>$htmlname, |
||
| 1569 | 'resql'=>$resql, |
||
| 1570 | 'out'=>&$out, |
||
| 1571 | 'showfunction'=>$showfunction, |
||
| 1572 | 'showsoc'=>$showsoc, |
||
| 1573 | ); |
||
| 1574 | |||
| 1575 | $reshook = $hookmanager->executeHooks('afterSelectContactOptions', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks |
||
| 1576 | |||
| 1577 | if ($htmlname != 'none' && !$options_only) |
||
| 1578 | { |
||
| 1579 | $out .= '</select>'; |
||
| 1580 | } |
||
| 1581 | |||
| 1582 | $this->num = $num; |
||
| 1583 | return $out; |
||
| 1584 | } else { |
||
| 1585 | dol_print_error($this->db); |
||
| 1586 | return -1; |
||
| 1587 | } |
||
| 1588 | } |
||
| 1589 | |||
| 1590 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps |
||
| 1591 | /** |
||
| 1592 | * Return the HTML select list of users |
||
| 1593 | * |
||
| 1594 | * @param string $selected Id user preselected |
||
| 1595 | * @param string $htmlname Field name in form |
||
| 1596 | * @param int $show_empty 0=liste sans valeur nulle, 1=ajoute valeur inconnue |
||
| 1597 | * @param array $exclude Array list of users id to exclude |
||
| 1598 | * @param int $disabled If select list must be disabled |
||
| 1599 | * @param array|string $include Array list of users id to include. User '' for all users or 'hierarchy' to have only supervised users or 'hierarchyme' to have supervised + me |
||
| 1600 | * @param int $enableonly Array list of users id to be enabled. All other must be disabled |
||
| 1601 | * @param string $force_entity '0' or Ids of environment to force |
||
| 1602 | * @return void |
||
| 1603 | * @deprecated Use select_dolusers instead |
||
| 1604 | * @see select_dolusers() |
||
| 1605 | */ |
||
| 1606 | public function select_users($selected = '', $htmlname = 'userid', $show_empty = 0, $exclude = null, $disabled = 0, $include = '', $enableonly = '', $force_entity = '0') |
||
| 1607 | { |
||
| 1608 | // phpcs:enable |
||
| 1609 | print $this->select_dolusers($selected, $htmlname, $show_empty, $exclude, $disabled, $include, $enableonly, $force_entity); |
||
| 1610 | } |
||
| 1611 | |||
| 1612 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps |
||
| 1613 | /** |
||
| 1614 | * Return select list of users |
||
| 1615 | * |
||
| 1616 | * @param string $selected User id or user object of user preselected. If 0 or < -2, we use id of current user. If -1, keep unselected (if empty is allowed) |
||
| 1617 | * @param string $htmlname Field name in form |
||
| 1618 | * @param int $show_empty 0=list with no empty value, 1=add also an empty value into list |
||
| 1619 | * @param array $exclude Array list of users id to exclude |
||
| 1620 | * @param int $disabled If select list must be disabled |
||
| 1621 | * @param array|string $include Array list of users id to include. User '' for all users or 'hierarchy' to have only supervised users or 'hierarchyme' to have supervised + me |
||
| 1622 | * @param array $enableonly Array list of users id to be enabled. If defined, it means that others will be disabled |
||
| 1623 | * @param string $force_entity '0' or Ids of environment to force |
||
| 1624 | * @param int $maxlength Maximum length of string into list (0=no limit) |
||
| 1625 | * @param int $showstatus 0=show user status only if status is disabled, 1=always show user status into label, -1=never show user status |
||
| 1626 | * @param string $morefilter Add more filters into sql request (Example: 'employee = 1') |
||
| 1627 | * @param integer $show_every 0=default list, 1=add also a value "Everybody" at beginning of list |
||
| 1628 | * @param string $enableonlytext If option $enableonlytext is set, we use this text to explain into label why record is disabled. Not used if enableonly is empty. |
||
| 1629 | * @param string $morecss More css |
||
| 1630 | * @param int $noactive Show only active users (this will also happened whatever is this option if USER_HIDE_INACTIVE_IN_COMBOBOX is on). |
||
| 1631 | * @param int $outputmode 0=HTML select string, 1=Array |
||
| 1632 | * @param bool $multiple add [] in the name of element and add 'multiple' attribut |
||
| 1633 | * @return string HTML select string |
||
| 1634 | * @see select_dolgroups() |
||
| 1635 | */ |
||
| 1636 | public function select_dolusers($selected = '', $htmlname = 'userid', $show_empty = 0, $exclude = null, $disabled = 0, $include = '', $enableonly = '', $force_entity = '0', $maxlength = 0, $showstatus = 0, $morefilter = '', $show_every = 0, $enableonlytext = '', $morecss = '', $noactive = 0, $outputmode = 0, $multiple = false) |
||
| 1637 | { |
||
| 1638 | // phpcs:enable |
||
| 1639 | global $conf, $user, $langs, $hookmanager; |
||
| 1640 | |||
| 1641 | // If no preselected user defined, we take current user |
||
| 1642 | if ((is_numeric($selected) && ($selected < -2 || empty($selected))) && empty($conf->global->SOCIETE_DISABLE_DEFAULT_SALESREPRESENTATIVE)) $selected = $user->id; |
||
| 1643 | |||
| 1644 | if ($selected === '') $selected = array(); |
||
| 1645 | elseif (!is_array($selected)) $selected = array($selected); |
||
| 1646 | |||
| 1647 | $excludeUsers = null; |
||
| 1648 | $includeUsers = null; |
||
| 1649 | |||
| 1650 | // Permettre l'exclusion d'utilisateurs |
||
| 1651 | if (is_array($exclude)) $excludeUsers = implode(",", $exclude); |
||
| 1652 | // Permettre l'inclusion d'utilisateurs |
||
| 1653 | if (is_array($include)) $includeUsers = implode(",", $include); |
||
| 1654 | elseif ($include == 'hierarchy') |
||
| 1655 | { |
||
| 1656 | // Build list includeUsers to have only hierarchy |
||
| 1657 | $includeUsers = implode(",", $user->getAllChildIds(0)); |
||
| 1658 | } elseif ($include == 'hierarchyme') |
||
| 1659 | { |
||
| 1660 | // Build list includeUsers to have only hierarchy and current user |
||
| 1661 | $includeUsers = implode(",", $user->getAllChildIds(1)); |
||
| 1662 | } |
||
| 1663 | |||
| 1664 | $out = ''; |
||
| 1665 | $outarray = array(); |
||
| 1666 | |||
| 1667 | // Forge request to select users |
||
| 1668 | $sql = "SELECT DISTINCT u.rowid, u.lastname as lastname, u.firstname, u.statut, u.login, u.admin, u.entity"; |
||
| 1669 | if (!empty($conf->multicompany->enabled) && $conf->entity == 1 && $user->admin && !$user->entity) |
||
| 1670 | { |
||
| 1671 | $sql .= ", e.label"; |
||
| 1672 | } |
||
| 1673 | $sql .= " FROM ".MAIN_DB_PREFIX."user as u"; |
||
| 1674 | if (!empty($conf->multicompany->enabled) && $conf->entity == 1 && $user->admin && !$user->entity) |
||
| 1675 | { |
||
| 1676 | $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."entity as e ON e.rowid=u.entity"; |
||
| 1677 | if ($force_entity) $sql .= " WHERE u.entity IN (0,".$force_entity.")"; |
||
| 1678 | else $sql .= " WHERE u.entity IS NOT NULL"; |
||
| 1679 | } else { |
||
| 1680 | if (!empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) |
||
| 1681 | { |
||
| 1682 | $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."usergroup_user as ug"; |
||
| 1683 | $sql .= " ON ug.fk_user = u.rowid"; |
||
| 1684 | $sql .= " WHERE ug.entity = ".$conf->entity; |
||
| 1685 | } else { |
||
| 1686 | $sql .= " WHERE u.entity IN (0,".$conf->entity.")"; |
||
| 1687 | } |
||
| 1688 | } |
||
| 1689 | if (!empty($user->socid)) $sql .= " AND u.fk_soc = ".$user->socid; |
||
| 1690 | if (is_array($exclude) && $excludeUsers) $sql .= " AND u.rowid NOT IN (".$excludeUsers.")"; |
||
| 1691 | if ($includeUsers) $sql .= " AND u.rowid IN (".$includeUsers.")"; |
||
| 1692 | if (!empty($conf->global->USER_HIDE_INACTIVE_IN_COMBOBOX) || $noactive) $sql .= " AND u.statut <> 0"; |
||
| 1693 | if (!empty($morefilter)) $sql .= " ".$morefilter; |
||
| 1694 | |||
| 1695 | //Add hook to filter on user (for exemple on usergroup define in custom modules) |
||
| 1696 | $reshook = $hookmanager->executeHooks('addSQLWhereFilterOnSelectUsers', array(), $this, $action); |
||
| 1697 | if (!empty($reshook)) $sql .= $hookmanager->resPrint; |
||
| 1698 | |||
| 1699 | if (empty($conf->global->MAIN_FIRSTNAME_NAME_POSITION)) // MAIN_FIRSTNAME_NAME_POSITION is 0 means firstname+lastname |
||
| 1700 | { |
||
| 1701 | $sql .= " ORDER BY u.firstname ASC"; |
||
| 1702 | } else { |
||
| 1703 | $sql .= " ORDER BY u.lastname ASC"; |
||
| 1704 | } |
||
| 1705 | |||
| 1706 | dol_syslog(get_class($this)."::select_dolusers", LOG_DEBUG); |
||
| 1707 | $resql = $this->db->query($sql); |
||
| 1708 | if ($resql) |
||
| 1709 | { |
||
| 1710 | $num = $this->db->num_rows($resql); |
||
| 1711 | $i = 0; |
||
| 1712 | if ($num) |
||
| 1713 | { |
||
| 1714 | // Enhance with select2 |
||
| 1715 | include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php'; |
||
| 1716 | $out .= ajax_combobox($htmlname); |
||
| 1717 | |||
| 1718 | // do not use maxwidthonsmartphone by default. Set it by caller so auto size to 100% will work when not defined |
||
| 1719 | $out .= '<select class="flat'.($morecss ? ' minwidth100imp '.$morecss : ' minwidth200').'" id="'.$htmlname.'" name="'.$htmlname.($multiple ? '[]' : '').'" '.($multiple ? 'multiple' : '').' '.($disabled ? ' disabled' : '').'>'; |
||
| 1720 | if ($show_empty && !$multiple) $out .= '<option value="-1"'.((empty($selected) || in_array(-1, $selected)) ? ' selected' : '').'> </option>'."\n"; |
||
| 1721 | if ($show_every) $out .= '<option value="-2"'.((in_array(-2, $selected)) ? ' selected' : '').'>-- '.$langs->trans("Everybody").' --</option>'."\n"; |
||
| 1722 | |||
| 1723 | $userstatic = new User($this->db); |
||
| 1724 | |||
| 1725 | while ($i < $num) |
||
| 1726 | { |
||
| 1727 | $obj = $this->db->fetch_object($resql); |
||
| 1728 | |||
| 1729 | $userstatic->id = $obj->rowid; |
||
| 1730 | $userstatic->lastname = $obj->lastname; |
||
| 1731 | $userstatic->firstname = $obj->firstname; |
||
| 1732 | |||
| 1733 | $disableline = ''; |
||
| 1734 | if (is_array($enableonly) && count($enableonly) && !in_array($obj->rowid, $enableonly)) $disableline = ($enableonlytext ? $enableonlytext : '1'); |
||
| 1735 | |||
| 1736 | if ((is_object($selected) && $selected->id == $obj->rowid) || (!is_object($selected) && in_array($obj->rowid, $selected))) |
||
| 1737 | { |
||
| 1738 | $out .= '<option value="'.$obj->rowid.'"'; |
||
| 1739 | if ($disableline) $out .= ' disabled'; |
||
| 1740 | $out .= ' selected>'; |
||
| 1741 | } else { |
||
| 1742 | $out .= '<option value="'.$obj->rowid.'"'; |
||
| 1743 | if ($disableline) $out .= ' disabled'; |
||
| 1744 | $out .= '>'; |
||
| 1745 | } |
||
| 1746 | |||
| 1747 | // $fullNameMode is 0=Lastname+Firstname (MAIN_FIRSTNAME_NAME_POSITION=1), 1=Firstname+Lastname (MAIN_FIRSTNAME_NAME_POSITION=0) |
||
| 1748 | $fullNameMode = 0; |
||
| 1749 | if (empty($conf->global->MAIN_FIRSTNAME_NAME_POSITION)) |
||
| 1750 | { |
||
| 1751 | $fullNameMode = 1; //Firstname+lastname |
||
| 1752 | } |
||
| 1753 | $out .= $userstatic->getFullName($langs, $fullNameMode, -1, $maxlength); |
||
| 1754 | |||
| 1755 | // Complete name with more info |
||
| 1756 | $moreinfo = 0; |
||
| 1757 | if (!empty($conf->global->MAIN_SHOW_LOGIN)) |
||
| 1758 | { |
||
| 1759 | $out .= ($moreinfo ? ' - ' : ' (').$obj->login; |
||
| 1760 | $moreinfo++; |
||
| 1761 | } |
||
| 1762 | if ($showstatus >= 0) |
||
| 1763 | { |
||
| 1764 | if ($obj->statut == 1 && $showstatus == 1) |
||
| 1765 | { |
||
| 1766 | $out .= ($moreinfo ? ' - ' : ' (').$langs->trans('Enabled'); |
||
| 1767 | $moreinfo++; |
||
| 1768 | } |
||
| 1769 | if ($obj->statut == 0) |
||
| 1770 | { |
||
| 1771 | $out .= ($moreinfo ? ' - ' : ' (').$langs->trans('Disabled'); |
||
| 1772 | $moreinfo++; |
||
| 1773 | } |
||
| 1774 | } |
||
| 1775 | if (!empty($conf->multicompany->enabled) && empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE) && $conf->entity == 1 && $user->admin && !$user->entity) |
||
| 1776 | { |
||
| 1777 | if (!$obj->entity) |
||
| 1778 | { |
||
| 1779 | $out .= ($moreinfo ? ' - ' : ' (').$langs->trans("AllEntities"); |
||
| 1780 | $moreinfo++; |
||
| 1781 | } else { |
||
| 1782 | $out .= ($moreinfo ? ' - ' : ' (').($obj->label ? $obj->label : $langs->trans("EntityNameNotDefined")); |
||
| 1783 | $moreinfo++; |
||
| 1784 | } |
||
| 1785 | } |
||
| 1786 | $out .= ($moreinfo ? ')' : ''); |
||
| 1787 | if ($disableline && $disableline != '1') |
||
| 1788 | { |
||
| 1789 | $out .= ' - '.$disableline; // This is text from $enableonlytext parameter |
||
| 1790 | } |
||
| 1791 | $out .= '</option>'; |
||
| 1792 | $outarray[$userstatic->id] = $userstatic->getFullName($langs, $fullNameMode, -1, $maxlength); |
||
| 1793 | |||
| 1794 | $i++; |
||
| 1795 | } |
||
| 1796 | } else { |
||
| 1797 | $out .= '<select class="flat" id="'.$htmlname.'" name="'.$htmlname.'" disabled>'; |
||
| 1798 | $out .= '<option value="">'.$langs->trans("None").'</option>'; |
||
| 1799 | } |
||
| 1800 | $out .= '</select>'; |
||
| 1801 | } else { |
||
| 1802 | dol_print_error($this->db); |
||
| 1803 | } |
||
| 1804 | |||
| 1805 | if ($outputmode) return $outarray; |
||
| 1806 | return $out; |
||
| 1807 | } |
||
| 1808 | |||
| 1809 | |||
| 1810 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps |
||
| 1811 | /** |
||
| 1812 | * Return select list of users. Selected users are stored into session. |
||
| 1813 | * List of users are provided into $_SESSION['assignedtouser']. |
||
| 1814 | * |
||
| 1815 | * @param string $action Value for $action |
||
| 1816 | * @param string $htmlname Field name in form |
||
| 1817 | * @param int $show_empty 0=list without the empty value, 1=add empty value |
||
| 1818 | * @param array $exclude Array list of users id to exclude |
||
| 1819 | * @param int $disabled If select list must be disabled |
||
| 1820 | * @param array $include Array list of users id to include or 'hierarchy' to have only supervised users |
||
| 1821 | * @param array $enableonly Array list of users id to be enabled. All other must be disabled |
||
| 1822 | * @param int $force_entity '0' or Ids of environment to force |
||
| 1823 | * @param int $maxlength Maximum length of string into list (0=no limit) |
||
| 1824 | * @param int $showstatus 0=show user status only if status is disabled, 1=always show user status into label, -1=never show user status |
||
| 1825 | * @param string $morefilter Add more filters into sql request |
||
| 1826 | * @param int $showproperties Show properties of each attendees |
||
| 1827 | * @param array $listofuserid Array with properties of each user |
||
| 1828 | * @param array $listofcontactid Array with properties of each contact |
||
| 1829 | * @param array $listofotherid Array with properties of each other contact |
||
| 1830 | * @return string HTML select string |
||
| 1831 | * @see select_dolgroups() |
||
| 1832 | */ |
||
| 1833 | public function select_dolusers_forevent($action = '', $htmlname = 'userid', $show_empty = 0, $exclude = null, $disabled = 0, $include = '', $enableonly = '', $force_entity = '0', $maxlength = 0, $showstatus = 0, $morefilter = '', $showproperties = 0, $listofuserid = array(), $listofcontactid = array(), $listofotherid = array()) |
||
| 1834 | { |
||
| 1835 | // phpcs:enable |
||
| 1836 | global $conf, $user, $langs; |
||
| 1837 | |||
| 1838 | $userstatic = new User($this->db); |
||
| 1839 | $out = ''; |
||
| 1840 | |||
| 1841 | // Method with no ajax |
||
| 1842 | //$out.='<form method="POST" action="'.$_SERVER["PHP_SELF"].'">'; |
||
| 1843 | if ($action == 'view') |
||
| 1844 | { |
||
| 1845 | $out .= ''; |
||
| 1846 | } else { |
||
| 1847 | $out .= '<input type="hidden" class="removedassignedhidden" name="removedassigned" value="">'; |
||
| 1848 | $out .= '<script type="text/javascript" language="javascript">jQuery(document).ready(function () { jQuery(".removedassigned").click(function() { jQuery(".removedassignedhidden").val(jQuery(this).val()); });})</script>'; |
||
| 1849 | $out .= $this->select_dolusers('', $htmlname, $show_empty, $exclude, $disabled, $include, $enableonly, $force_entity, $maxlength, $showstatus, $morefilter); |
||
| 1850 | $out .= ' <input type="submit" class="button valignmiddle" name="'.$action.'assignedtouser" value="'.dol_escape_htmltag($langs->trans("Add")).'">'; |
||
| 1851 | $out .= '<br>'; |
||
| 1852 | } |
||
| 1853 | $assignedtouser = array(); |
||
| 1854 | if (!empty($_SESSION['assignedtouser'])) |
||
| 1855 | { |
||
| 1856 | $assignedtouser = json_decode($_SESSION['assignedtouser'], true); |
||
| 1857 | } |
||
| 1858 | $nbassignetouser = count($assignedtouser); |
||
| 1859 | |||
| 1860 | if ($nbassignetouser && $action != 'view') $out .= '<br>'; |
||
| 1861 | if ($nbassignetouser) $out .= '<ul class="attendees">'; |
||
| 1862 | $i = 0; $ownerid = 0; |
||
| 1863 | foreach ($assignedtouser as $key => $value) |
||
| 1864 | { |
||
| 1865 | if ($value['id'] == $ownerid) continue; |
||
| 1866 | |||
| 1867 | $out .= '<li>'; |
||
| 1868 | $userstatic->fetch($value['id']); |
||
| 1869 | $out .= $userstatic->getNomUrl(-1); |
||
| 1870 | if ($i == 0) { $ownerid = $value['id']; $out .= ' ('.$langs->trans("Owner").')'; } |
||
| 1871 | if ($nbassignetouser > 1 && $action != 'view') |
||
| 1872 | { |
||
| 1873 | $out .= ' <input type="image" style="border: 0px;" src="'.img_picto($langs->trans("Remove"), 'delete', '', 0, 1).'" value="'.$userstatic->id.'" class="removedassigned" id="removedassigned_'.$userstatic->id.'" name="removedassigned_'.$userstatic->id.'">'; |
||
| 1874 | } |
||
| 1875 | // Show my availability |
||
| 1876 | if ($showproperties) |
||
| 1877 | { |
||
| 1878 | if ($ownerid == $value['id'] && is_array($listofuserid) && count($listofuserid) && in_array($ownerid, array_keys($listofuserid))) |
||
| 1879 | { |
||
| 1880 | $out .= '<div class="myavailability inline-block">'; |
||
| 1881 | $out .= ' - <span class="opacitymedium">'.$langs->trans("Availability").':</span> <input id="transparency" class="marginleftonly marginrightonly" '.($action == 'view' ? 'disabled' : '').' type="checkbox" name="transparency"'.($listofuserid[$ownerid]['transparency'] ? ' checked' : '').'>'.$langs->trans("Busy"); |
||
| 1882 | $out .= '</div>'; |
||
| 1883 | } |
||
| 1884 | } |
||
| 1885 | //$out.=' '.($value['mandatory']?$langs->trans("Mandatory"):$langs->trans("Optional")); |
||
| 1886 | //$out.=' '.($value['transparency']?$langs->trans("Busy"):$langs->trans("NotBusy")); |
||
| 1887 | |||
| 1888 | $out .= '</li>'; |
||
| 1889 | $i++; |
||
| 1890 | } |
||
| 1891 | if ($nbassignetouser) $out .= '</ul>'; |
||
| 1892 | |||
| 1893 | //$out.='</form>'; |
||
| 1894 | return $out; |
||
| 1895 | } |
||
| 1896 | |||
| 1897 | |||
| 1898 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps |
||
| 1899 | /** |
||
| 1900 | * Return list of products for customer in Ajax if Ajax activated or go to select_produits_list |
||
| 1901 | * |
||
| 1902 | * @param int $selected Preselected products |
||
| 1903 | * @param string $htmlname Name of HTML select field (must be unique in page) |
||
| 1904 | * @param int $filtertype Filter on product type (''=nofilter, 0=product, 1=service) |
||
| 1905 | * @param int $limit Limit on number of returned lines |
||
| 1906 | * @param int $price_level Level of price to show |
||
| 1907 | * @param int $status Sell status -1=Return all products, 0=Products not on sell, 1=Products on sell |
||
| 1908 | * @param int $finished 2=all, 1=finished, 0=raw material |
||
| 1909 | * @param string $selected_input_value Value of preselected input text (for use with ajax) |
||
| 1910 | * @param int $hidelabel Hide label (0=no, 1=yes, 2=show search icon (before) and placeholder, 3 search icon after) |
||
| 1911 | * @param array $ajaxoptions Options for ajax_autocompleter |
||
| 1912 | * @param int $socid Thirdparty Id (to get also price dedicated to this customer) |
||
| 1913 | * @param string $showempty '' to not show empty line. Translation key to show an empty line. '1' show empty line with no text. |
||
| 1914 | * @param int $forcecombo Force to use combo box |
||
| 1915 | * @param string $morecss Add more css on select |
||
| 1916 | * @param int $hidepriceinlabel 1=Hide prices in label |
||
| 1917 | * @param string $warehouseStatus Warehouse status filter to count the quantity in stock. Following comma separated filter options can be used |
||
| 1918 | * 'warehouseopen' = count products from open warehouses, |
||
| 1919 | * 'warehouseclosed' = count products from closed warehouses, |
||
| 1920 | * 'warehouseinternal' = count products from warehouses for internal correct/transfer only |
||
| 1921 | * @param array $selected_combinations Selected combinations. Format: array([attrid] => attrval, [...]) |
||
| 1922 | * @return void |
||
| 1923 | */ |
||
| 1924 | public function select_produits($selected = '', $htmlname = 'productid', $filtertype = '', $limit = 20, $price_level = 0, $status = 1, $finished = 2, $selected_input_value = '', $hidelabel = 0, $ajaxoptions = array(), $socid = 0, $showempty = '1', $forcecombo = 0, $morecss = '', $hidepriceinlabel = 0, $warehouseStatus = '', $selected_combinations = array()) |
||
| 2056 | } |
||
| 2057 | } |
||
| 2058 | |||
| 2059 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps |
||
| 2060 | /** |
||
| 2061 | * Return list of products for a customer |
||
| 2062 | * |
||
| 2063 | * @param int $selected Preselected product |
||
| 2064 | * @param string $htmlname Name of select html |
||
| 2065 | * @param string $filtertype Filter on product type (''=nofilter, 0=product, 1=service) |
||
| 2066 | * @param int $limit Limit on number of returned lines |
||
| 2067 | * @param int $price_level Level of price to show |
||
| 2068 | * @param string $filterkey Filter on product |
||
| 2069 | * @param int $status -1=Return all products, 0=Products not on sell, 1=Products on sell |
||
| 2070 | * @param int $finished Filter on finished field: 2=No filter |
||
| 2071 | * @param int $outputmode 0=HTML select string, 1=Array |
||
| 2072 | * @param int $socid Thirdparty Id (to get also price dedicated to this customer) |
||
| 2073 | * @param string $showempty '' to not show empty line. Translation key to show an empty line. '1' show empty line with no text. |
||
| 2074 | * @param int $forcecombo Force to use combo box |
||
| 2075 | * @param string $morecss Add more css on select |
||
| 2076 | * @param int $hidepriceinlabel 1=Hide prices in label |
||
| 2077 | * @param string $warehouseStatus Warehouse status filter to group/count stock. Following comma separated filter options can be used. |
||
| 2078 | * 'warehouseopen' = count products from open warehouses, |
||
| 2079 | * 'warehouseclosed' = count products from closed warehouses, |
||
| 2080 | * 'warehouseinternal' = count products from warehouses for internal correct/transfer only |
||
| 2081 | * @return array Array of keys for json |
||
| 2082 | */ |
||
| 2083 | public function select_produits_list($selected = '', $htmlname = 'productid', $filtertype = '', $limit = 20, $price_level = 0, $filterkey = '', $status = 1, $finished = 2, $outputmode = 0, $socid = 0, $showempty = '1', $forcecombo = 0, $morecss = '', $hidepriceinlabel = 0, $warehouseStatus = '') |
||
| 2380 | } |
||
| 2381 | } |
||
| 2382 | |||
| 2383 | /** |
||
| 2384 | * constructProductListOption. |
||
| 2385 | * This define value for &$opt and &$optJson. |
||
| 2386 | * |
||
| 2387 | * @param resource $objp Resultset of fetch |
||
| 2388 | * @param string $opt Option (var used for returned value in string option format) |
||
| 2389 | * @param string $optJson Option (var used for returned value in json format) |
||
| 2390 | * @param int $price_level Price level |
||
| 2391 | * @param string $selected Preselected value |
||
| 2392 | * @param int $hidepriceinlabel Hide price in label |
||
| 2393 | * @param string $filterkey Filter key to highlight |
||
| 2394 | * @param int $novirtualstock Do not load virtual stock, even if slow option STOCK_SHOW_VIRTUAL_STOCK_IN_PRODUCTS_COMBO is on. |
||
| 2395 | * @return void |
||
| 2396 | */ |
||
| 2397 | protected function constructProductListOption(&$objp, &$opt, &$optJson, $price_level, $selected, $hidepriceinlabel = 0, $filterkey = '', $novirtualstock = 0) |
||
| 2398 | { |
||
| 2399 | global $langs, $conf, $user, $db; |
||
| 2400 | |||
| 2401 | $outkey = ''; |
||
| 2402 | $outval = ''; |
||
| 2403 | $outref = ''; |
||
| 2404 | $outlabel = ''; |
||
| 2405 | $outdesc = ''; |
||
| 2406 | $outbarcode = ''; |
||
| 2407 | $outorigin = ''; |
||
| 2408 | $outtype = ''; |
||
| 2409 | $outprice_ht = ''; |
||
| 2410 | $outprice_ttc = ''; |
||
| 2411 | $outpricebasetype = ''; |
||
| 2412 | $outtva_tx = ''; |
||
| 2413 | $outqty = 1; |
||
| 2414 | $outdiscount = 0; |
||
| 2415 | |||
| 2416 | $maxlengtharticle = (empty($conf->global->PRODUCT_MAX_LENGTH_COMBO) ? 48 : $conf->global->PRODUCT_MAX_LENGTH_COMBO); |
||
| 2417 | |||
| 2418 | $label = $objp->label; |
||
| 2419 | if (!empty($objp->label_translated)) $label = $objp->label_translated; |
||
| 2420 | if (!empty($filterkey) && $filterkey != '') $label = preg_replace('/('.preg_quote($filterkey, '/').')/i', '<strong>$1</strong>', $label, 1); |
||
| 2421 | |||
| 2422 | $outkey = $objp->rowid; |
||
| 2423 | $outref = $objp->ref; |
||
| 2424 | $outlabel = $objp->label; |
||
| 2425 | $outdesc = $objp->description; |
||
| 2426 | $outbarcode = $objp->barcode; |
||
| 2427 | $outorigin = $objp->fk_country; |
||
| 2428 | $outpbq = empty($objp->price_by_qty_rowid) ? '' : $objp->price_by_qty_rowid; |
||
| 2429 | |||
| 2430 | $outtype = $objp->fk_product_type; |
||
| 2431 | $outdurationvalue = $outtype == Product::TYPE_SERVICE ?substr($objp->duration, 0, dol_strlen($objp->duration) - 1) : ''; |
||
| 2432 | $outdurationunit = $outtype == Product::TYPE_SERVICE ?substr($objp->duration, -1) : ''; |
||
| 2433 | |||
| 2434 | if ($outorigin && !empty($conf->global->PRODUCT_SHOW_ORIGIN_IN_COMBO)) require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; |
||
| 2435 | |||
| 2436 | // Units |
||
| 2437 | $outvalUnits = ''; |
||
| 2438 | if (!empty($conf->global->PRODUCT_USE_UNITS)) { |
||
| 2439 | if (!empty($objp->unit_short)) { |
||
| 2440 | $outvalUnits .= ' - '.$objp->unit_short; |
||
| 2441 | } |
||
| 2442 | } |
||
| 2443 | if (!empty($conf->global->PRODUCT_SHOW_DIMENSIONS_IN_COMBO)) { |
||
| 2444 | if (!empty($objp->weight) && $objp->weight_units !== null) { |
||
| 2445 | $unitToShow = showDimensionInBestUnit($objp->weight, $objp->weight_units, 'weight', $langs); |
||
| 2446 | $outvalUnits .= ' - '.$unitToShow; |
||
| 2447 | } |
||
| 2448 | if ((!empty($objp->length) || !empty($objp->width) || !empty($objp->height)) && $objp->length_units !== null) { |
||
| 2449 | $unitToShow = $objp->length.' x '.$objp->width.' x '.$objp->height.' '.measuringUnitString(0, 'size', $objp->length_units); |
||
| 2450 | $outvalUnits .= ' - '.$unitToShow; |
||
| 2451 | } |
||
| 2452 | if (!empty($objp->surface) && $objp->surface_units !== null) { |
||
| 2453 | $unitToShow = showDimensionInBestUnit($objp->surface, $objp->surface_units, 'surface', $langs); |
||
| 2454 | $outvalUnits .= ' - '.$unitToShow; |
||
| 2455 | } |
||
| 2456 | if (!empty($objp->volume) && $objp->volume_units !== null) { |
||
| 2457 | $unitToShow = showDimensionInBestUnit($objp->volume, $objp->volume_units, 'volume', $langs); |
||
| 2458 | $outvalUnits .= ' - '.$unitToShow; |
||
| 2459 | } |
||
| 2460 | } |
||
| 2461 | if ($outdurationvalue && $outdurationunit) { |
||
| 2462 | $da = array( |
||
| 2463 | 'h' => $langs->trans('Hour'), |
||
| 2464 | 'd' => $langs->trans('Day'), |
||
| 2465 | 'w' => $langs->trans('Week'), |
||
| 2466 | 'm' => $langs->trans('Month'), |
||
| 2467 | 'y' => $langs->trans('Year') |
||
| 2468 | ); |
||
| 2469 | if (isset($da[$outdurationunit])) { |
||
| 2470 | $outvalUnits .= ' - '.$outdurationvalue.' '.$langs->transnoentities($da[$outdurationunit].($outdurationvalue > 1 ? 's' : '')); |
||
| 2471 | } |
||
| 2472 | } |
||
| 2473 | |||
| 2474 | $opt = '<option value="'.$objp->rowid.'"'; |
||
| 2475 | $opt .= ($objp->rowid == $selected) ? ' selected' : ''; |
||
| 2476 | if (!empty($objp->price_by_qty_rowid) && $objp->price_by_qty_rowid > 0) |
||
| 2477 | { |
||
| 2478 | $opt .= ' pbq="'.$objp->price_by_qty_rowid.'" data-pbq="'.$objp->price_by_qty_rowid.'" data-pbqup="'.$objp->price_by_qty_unitprice.'" data-pbqbase="'.$objp->price_by_qty_price_base_type.'" data-pbqqty="'.$objp->price_by_qty_quantity.'" data-pbqpercent="'.$objp->price_by_qty_remise_percent.'"'; |
||
| 2479 | } |
||
| 2480 | if (!empty($conf->stock->enabled) && isset($objp->stock) && ($objp->fk_product_type == Product::TYPE_PRODUCT || !empty($conf->global->STOCK_SUPPORTS_SERVICES))) |
||
| 2481 | { |
||
| 2482 | if (!empty($user->rights->stock->lire)) { |
||
| 2483 | if ($objp->stock > 0) $opt .= ' class="product_line_stock_ok"'; |
||
| 2484 | elseif ($objp->stock <= 0) $opt .= ' class="product_line_stock_too_low"'; |
||
| 2485 | } |
||
| 2486 | } |
||
| 2487 | $opt .= '>'; |
||
| 2488 | $opt .= $objp->ref; |
||
| 2489 | if ($outbarcode) $opt .= ' ('.$outbarcode.')'; |
||
| 2490 | $opt .= ' - '.dol_trunc($label, $maxlengtharticle); |
||
| 2491 | if ($outorigin && !empty($conf->global->PRODUCT_SHOW_ORIGIN_IN_COMBO)) $opt .= ' ('.getCountry($outorigin, 1).')'; |
||
| 2492 | |||
| 2493 | $objRef = $objp->ref; |
||
| 2494 | if (!empty($filterkey) && $filterkey != '') $objRef = preg_replace('/('.preg_quote($filterkey, '/').')/i', '<strong>$1</strong>', $objRef, 1); |
||
| 2495 | $outval .= $objRef; |
||
| 2496 | if ($outbarcode) $outval .= ' ('.$outbarcode.')'; |
||
| 2497 | $outval .= ' - '.dol_trunc($label, $maxlengtharticle); |
||
| 2498 | if ($outorigin && !empty($conf->global->PRODUCT_SHOW_ORIGIN_IN_COMBO)) $outval .= ' ('.getCountry($outorigin, 1).')'; |
||
| 2499 | |||
| 2500 | // Units |
||
| 2501 | $opt .= $outvalUnits; |
||
| 2502 | $outval .= $outvalUnits; |
||
| 2503 | |||
| 2504 | $found = 0; |
||
| 2505 | |||
| 2506 | // Multiprice |
||
| 2507 | // If we need a particular price level (from 1 to 6) |
||
| 2508 | if (empty($hidepriceinlabel) && $price_level >= 1 && (!empty($conf->global->PRODUIT_MULTIPRICES) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES))) |
||
| 2509 | { |
||
| 2510 | $sql = "SELECT price, price_ttc, price_base_type, tva_tx"; |
||
| 2511 | $sql .= " FROM ".MAIN_DB_PREFIX."product_price"; |
||
| 2512 | $sql .= " WHERE fk_product='".$objp->rowid."'"; |
||
| 2513 | $sql .= " AND entity IN (".getEntity('productprice').")"; |
||
| 2514 | $sql .= " AND price_level=".$price_level; |
||
| 2515 | $sql .= " ORDER BY date_price DESC, rowid DESC"; // Warning DESC must be both on date_price and rowid. |
||
| 2516 | $sql .= " LIMIT 1"; |
||
| 2517 | |||
| 2518 | dol_syslog(get_class($this).'::constructProductListOption search price for product '.$objp->rowid.' AND level '.$price_level.'', LOG_DEBUG); |
||
| 2519 | $result2 = $this->db->query($sql); |
||
| 2520 | if ($result2) |
||
| 2521 | { |
||
| 2522 | $objp2 = $this->db->fetch_object($result2); |
||
| 2523 | if ($objp2) |
||
| 2524 | { |
||
| 2525 | $found = 1; |
||
| 2526 | if ($objp2->price_base_type == 'HT') |
||
| 2527 | { |
||
| 2528 | $opt .= ' - '.price($objp2->price, 1, $langs, 0, 0, -1, $conf->currency).' '.$langs->trans("HT"); |
||
| 2529 | $outval .= ' - '.price($objp2->price, 0, $langs, 0, 0, -1, $conf->currency).' '.$langs->transnoentities("HT"); |
||
| 2530 | } else { |
||
| 2531 | $opt .= ' - '.price($objp2->price_ttc, 1, $langs, 0, 0, -1, $conf->currency).' '.$langs->trans("TTC"); |
||
| 2532 | $outval .= ' - '.price($objp2->price_ttc, 0, $langs, 0, 0, -1, $conf->currency).' '.$langs->transnoentities("TTC"); |
||
| 2533 | } |
||
| 2534 | $outprice_ht = price($objp2->price); |
||
| 2535 | $outprice_ttc = price($objp2->price_ttc); |
||
| 2536 | $outpricebasetype = $objp2->price_base_type; |
||
| 2537 | $outtva_tx = $objp2->tva_tx; |
||
| 2538 | } |
||
| 2539 | } else { |
||
| 2540 | dol_print_error($this->db); |
||
| 2541 | } |
||
| 2542 | } |
||
| 2543 | |||
| 2544 | // Price by quantity |
||
| 2545 | if (empty($hidepriceinlabel) && !empty($objp->quantity) && $objp->quantity >= 1 && (!empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES))) |
||
| 2546 | { |
||
| 2547 | $found = 1; |
||
| 2548 | $outqty = $objp->quantity; |
||
| 2549 | $outdiscount = $objp->remise_percent; |
||
| 2550 | if ($objp->quantity == 1) |
||
| 2551 | { |
||
| 2552 | $opt .= ' - '.price($objp->unitprice, 1, $langs, 0, 0, -1, $conf->currency)."/"; |
||
| 2553 | $outval .= ' - '.price($objp->unitprice, 0, $langs, 0, 0, -1, $conf->currency)."/"; |
||
| 2554 | $opt .= $langs->trans("Unit"); // Do not use strtolower because it breaks utf8 encoding |
||
| 2555 | $outval .= $langs->transnoentities("Unit"); |
||
| 2556 | } else { |
||
| 2557 | $opt .= ' - '.price($objp->price, 1, $langs, 0, 0, -1, $conf->currency)."/".$objp->quantity; |
||
| 2558 | $outval .= ' - '.price($objp->price, 0, $langs, 0, 0, -1, $conf->currency)."/".$objp->quantity; |
||
| 2559 | $opt .= $langs->trans("Units"); // Do not use strtolower because it breaks utf8 encoding |
||
| 2560 | $outval .= $langs->transnoentities("Units"); |
||
| 2561 | } |
||
| 2562 | |||
| 2563 | $outprice_ht = price($objp->unitprice); |
||
| 2564 | $outprice_ttc = price($objp->unitprice * (1 + ($objp->tva_tx / 100))); |
||
| 2565 | $outpricebasetype = $objp->price_base_type; |
||
| 2566 | $outtva_tx = $objp->tva_tx; |
||
| 2567 | } |
||
| 2568 | if (empty($hidepriceinlabel) && !empty($objp->quantity) && $objp->quantity >= 1) |
||
| 2569 | { |
||
| 2570 | $opt .= " (".price($objp->unitprice, 1, $langs, 0, 0, -1, $conf->currency)."/".$langs->trans("Unit").")"; // Do not use strtolower because it breaks utf8 encoding |
||
| 2571 | $outval .= " (".price($objp->unitprice, 0, $langs, 0, 0, -1, $conf->currency)."/".$langs->transnoentities("Unit").")"; // Do not use strtolower because it breaks utf8 encoding |
||
| 2572 | } |
||
| 2573 | if (empty($hidepriceinlabel) && !empty($objp->remise_percent) && $objp->remise_percent >= 1) |
||
| 2574 | { |
||
| 2575 | $opt .= " - ".$langs->trans("Discount")." : ".vatrate($objp->remise_percent).' %'; |
||
| 2576 | $outval .= " - ".$langs->transnoentities("Discount")." : ".vatrate($objp->remise_percent).' %'; |
||
| 2577 | } |
||
| 2578 | |||
| 2579 | // Price by customer |
||
| 2580 | if (empty($hidepriceinlabel) && !empty($conf->global->PRODUIT_CUSTOMER_PRICES)) |
||
| 2581 | { |
||
| 2582 | if (!empty($objp->idprodcustprice)) |
||
| 2583 | { |
||
| 2584 | $found = 1; |
||
| 2585 | |||
| 2586 | if ($objp->custprice_base_type == 'HT') |
||
| 2587 | { |
||
| 2588 | $opt .= ' - '.price($objp->custprice, 1, $langs, 0, 0, -1, $conf->currency).' '.$langs->trans("HT"); |
||
| 2589 | $outval .= ' - '.price($objp->custprice, 0, $langs, 0, 0, -1, $conf->currency).' '.$langs->transnoentities("HT"); |
||
| 2590 | } else { |
||
| 2591 | $opt .= ' - '.price($objp->custprice_ttc, 1, $langs, 0, 0, -1, $conf->currency).' '.$langs->trans("TTC"); |
||
| 2592 | $outval .= ' - '.price($objp->custprice_ttc, 0, $langs, 0, 0, -1, $conf->currency).' '.$langs->transnoentities("TTC"); |
||
| 2593 | } |
||
| 2594 | |||
| 2595 | $outprice_ht = price($objp->custprice); |
||
| 2596 | $outprice_ttc = price($objp->custprice_ttc); |
||
| 2597 | $outpricebasetype = $objp->custprice_base_type; |
||
| 2598 | $outtva_tx = $objp->custtva_tx; |
||
| 2599 | } |
||
| 2600 | } |
||
| 2601 | |||
| 2602 | // If level no defined or multiprice not found, we used the default price |
||
| 2603 | if (empty($hidepriceinlabel) && !$found) |
||
| 2604 | { |
||
| 2605 | if ($objp->price_base_type == 'HT') |
||
| 2606 | { |
||
| 2607 | $opt .= ' - '.price($objp->price, 1, $langs, 0, 0, -1, $conf->currency).' '.$langs->trans("HT"); |
||
| 2608 | $outval .= ' - '.price($objp->price, 0, $langs, 0, 0, -1, $conf->currency).' '.$langs->transnoentities("HT"); |
||
| 2609 | } else { |
||
| 2610 | $opt .= ' - '.price($objp->price_ttc, 1, $langs, 0, 0, -1, $conf->currency).' '.$langs->trans("TTC"); |
||
| 2611 | $outval .= ' - '.price($objp->price_ttc, 0, $langs, 0, 0, -1, $conf->currency).' '.$langs->transnoentities("TTC"); |
||
| 2612 | } |
||
| 2613 | $outprice_ht = price($objp->price); |
||
| 2614 | $outprice_ttc = price($objp->price_ttc); |
||
| 2615 | $outpricebasetype = $objp->price_base_type; |
||
| 2616 | $outtva_tx = $objp->tva_tx; |
||
| 2617 | } |
||
| 2618 | |||
| 2619 | if (!empty($conf->stock->enabled) && isset($objp->stock) && ($objp->fk_product_type == Product::TYPE_PRODUCT || !empty($conf->global->STOCK_SUPPORTS_SERVICES))) |
||
| 2620 | { |
||
| 2621 | if (!empty($user->rights->stock->lire)) { |
||
| 2622 | $opt .= ' - '.$langs->trans("Stock").':'.$objp->stock; |
||
| 2623 | |||
| 2624 | if ($objp->stock > 0) { |
||
| 2625 | $outval .= ' - <span class="product_line_stock_ok">'; |
||
| 2626 | } elseif ($objp->stock <= 0) { |
||
| 2627 | $outval .= ' - <span class="product_line_stock_too_low">'; |
||
| 2628 | } |
||
| 2629 | $outval .= $langs->transnoentities("Stock").':'.$objp->stock; |
||
| 2630 | $outval .= '</span>'; |
||
| 2631 | if (empty($novirtualstock) && !empty($conf->global->STOCK_SHOW_VIRTUAL_STOCK_IN_PRODUCTS_COMBO)) // Warning, this option may slow down combo list generation |
||
| 2632 | { |
||
| 2633 | $langs->load("stocks"); |
||
| 2634 | |||
| 2635 | $tmpproduct = new Product($this->db); |
||
| 2636 | $tmpproduct->fetch($objp->rowid, '', '', '', 1, 1, 1); // Load product without lang and prices arrays (we just need to make ->virtual_stock() after) |
||
| 2637 | $tmpproduct->load_virtual_stock(); |
||
| 2638 | $virtualstock = $tmpproduct->stock_theorique; |
||
| 2639 | |||
| 2640 | $opt .= ' - '.$langs->trans("VirtualStock").':'.$virtualstock; |
||
| 2641 | |||
| 2642 | $outval .= ' - '.$langs->transnoentities("VirtualStock").':'; |
||
| 2643 | if ($virtualstock > 0) { |
||
| 2644 | $outval .= '<span class="product_line_stock_ok">'; |
||
| 2645 | } elseif ($virtualstock <= 0) { |
||
| 2646 | $outval .= '<span class="product_line_stock_too_low">'; |
||
| 2647 | } |
||
| 2648 | $outval .= $virtualstock; |
||
| 2649 | $outval .= '</span>'; |
||
| 2650 | |||
| 2651 | unset($tmpproduct); |
||
| 2652 | } |
||
| 2653 | } |
||
| 2654 | } |
||
| 2655 | |||
| 2656 | $opt .= "</option>\n"; |
||
| 2657 | $optJson = array('key'=>$outkey, 'value'=>$outref, 'label'=>$outval, 'label2'=>$outlabel, 'desc'=>$outdesc, 'type'=>$outtype, 'price_ht'=>price2num($outprice_ht), 'price_ttc'=>price2num($outprice_ttc), 'pricebasetype'=>$outpricebasetype, 'tva_tx'=>$outtva_tx, 'qty'=>$outqty, 'discount'=>$outdiscount, 'duration_value'=>$outdurationvalue, 'duration_unit'=>$outdurationunit, 'pbq'=>$outpbq); |
||
| 2658 | } |
||
| 2659 | |||
| 2660 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps |
||
| 2661 | /** |
||
| 2662 | * Return list of products for customer (in Ajax if Ajax activated or go to select_produits_fournisseurs_list) |
||
| 2663 | * |
||
| 2664 | * @param int $socid Id third party |
||
| 2665 | * @param string $selected Preselected product |
||
| 2666 | * @param string $htmlname Name of HTML Select |
||
| 2667 | * @param string $filtertype Filter on product type (''=nofilter, 0=product, 1=service) |
||
| 2668 | * @param string $filtre For a SQL filter |
||
| 2669 | * @param array $ajaxoptions Options for ajax_autocompleter |
||
| 2670 | * @param int $hidelabel Hide label (0=no, 1=yes) |
||
| 2671 | * @param int $alsoproductwithnosupplierprice 1=Add also product without supplier prices |
||
| 2672 | * @param string $morecss More CSS |
||
| 2673 | * @return void |
||
| 2674 | */ |
||
| 2675 | public function select_produits_fournisseurs($socid, $selected = '', $htmlname = 'productid', $filtertype = '', $filtre = '', $ajaxoptions = array(), $hidelabel = 0, $alsoproductwithnosupplierprice = 0, $morecss = '') |
||
| 2676 | { |
||
| 2677 | // phpcs:enable |
||
| 2678 | global $langs, $conf; |
||
| 2679 | global $price_level, $status, $finished; |
||
| 2680 | |||
| 2681 | $selected_input_value = ''; |
||
| 2682 | if (!empty($conf->use_javascript_ajax) && !empty($conf->global->PRODUIT_USE_SEARCH_TO_SELECT)) |
||
| 2683 | { |
||
| 2684 | if ($selected > 0) |
||
| 2685 | { |
||
| 2686 | require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; |
||
| 2687 | $producttmpselect = new Product($this->db); |
||
| 2688 | $producttmpselect->fetch($selected); |
||
| 2689 | $selected_input_value = $producttmpselect->ref; |
||
| 2690 | unset($producttmpselect); |
||
| 2691 | } |
||
| 2692 | |||
| 2693 | // mode=2 means suppliers products |
||
| 2694 | $urloption = ($socid > 0 ? 'socid='.$socid.'&' : '').'htmlname='.$htmlname.'&outjson=1&price_level='.$price_level.'&type='.$filtertype.'&mode=2&status='.$status.'&finished='.$finished.'&alsoproductwithnosupplierprice='.$alsoproductwithnosupplierprice; |
||
| 2695 | print ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT.'/product/ajax/products.php', $urloption, $conf->global->PRODUIT_USE_SEARCH_TO_SELECT, 0, $ajaxoptions); |
||
| 2696 | print ($hidelabel ? '' : $langs->trans("RefOrLabel").' : ').'<input type="text" size="20" name="search_'.$htmlname.'" id="search_'.$htmlname.'" value="'.$selected_input_value.'">'; |
||
| 2697 | } else { |
||
| 2698 | print $this->select_produits_fournisseurs_list($socid, $selected, $htmlname, $filtertype, $filtre, '', -1, 0, 0, $alsoproductwithnosupplierprice, $morecss); |
||
| 2699 | } |
||
| 2700 | } |
||
| 2701 | |||
| 2702 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps |
||
| 2703 | /** |
||
| 2704 | * Return list of suppliers products |
||
| 2705 | * |
||
| 2706 | * @param int $socid Id societe fournisseur (0 pour aucun filtre) |
||
| 2707 | * @param int $selected Product price pre-selected (must be 'id' in product_fournisseur_price or 'idprod_IDPROD') |
||
| 2708 | * @param string $htmlname Nom de la zone select |
||
| 2709 | * @param string $filtertype Filter on product type (''=nofilter, 0=product, 1=service) |
||
| 2710 | * @param string $filtre Pour filtre sql |
||
| 2711 | * @param string $filterkey Filtre des produits |
||
| 2712 | * @param int $statut -1=Return all products, 0=Products not on sell, 1=Products on sell (not used here, a filter on tobuy is already hard coded in request) |
||
| 2713 | * @param int $outputmode 0=HTML select string, 1=Array |
||
| 2714 | * @param int $limit Limit of line number |
||
| 2715 | * @param int $alsoproductwithnosupplierprice 1=Add also product without supplier prices |
||
| 2716 | * @param string $morecss Add more CSS |
||
| 2717 | * @return array Array of keys for json |
||
| 2718 | */ |
||
| 2719 | public function select_produits_fournisseurs_list($socid, $selected = '', $htmlname = 'productid', $filtertype = '', $filtre = '', $filterkey = '', $statut = -1, $outputmode = 0, $limit = 100, $alsoproductwithnosupplierprice = 0, $morecss = '') |
||
| 2720 | { |
||
| 2721 | // phpcs:enable |
||
| 2722 | global $langs, $conf, $db; |
||
| 2723 | |||
| 2724 | $out = ''; |
||
| 2725 | $outarray = array(); |
||
| 2726 | |||
| 2727 | $maxlengtharticle = (empty($conf->global->PRODUCT_MAX_LENGTH_COMBO) ? 48 : $conf->global->PRODUCT_MAX_LENGTH_COMBO); |
||
| 2728 | |||
| 2729 | $langs->load('stocks'); |
||
| 2730 | // Units |
||
| 2731 | if ($conf->global->PRODUCT_USE_UNITS) { |
||
| 2732 | $langs->load('other'); |
||
| 2733 | } |
||
| 2734 | |||
| 2735 | $sql = "SELECT p.rowid, p.ref, p.label, p.price, p.duration, p.fk_product_type,"; |
||
| 2736 | $sql .= " pfp.ref_fourn, pfp.rowid as idprodfournprice, pfp.price as fprice, pfp.quantity, pfp.remise_percent, pfp.remise, pfp.unitprice,"; |
||
| 2737 | $sql .= " pfp.fk_supplier_price_expression, pfp.fk_product, pfp.tva_tx, pfp.fk_soc, s.nom as name,"; |
||
| 2738 | $sql .= " pfp.supplier_reputation"; |
||
| 2739 | // Units |
||
| 2740 | if ($conf->global->PRODUCT_USE_UNITS) { |
||
| 2741 | $sql .= ", u.label as unit_long, u.short_label as unit_short, p.weight, p.weight_units, p.length, p.length_units, p.width, p.width_units, p.height, p.height_units, p.surface, p.surface_units, p.volume, p.volume_units"; |
||
| 2742 | } |
||
| 2743 | if (!empty($conf->barcode->enabled)) $sql .= ", pfp.barcode"; |
||
| 2744 | $sql .= " FROM ".MAIN_DB_PREFIX."product as p"; |
||
| 2745 | $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_fournisseur_price as pfp ON ( p.rowid = pfp.fk_product AND pfp.entity IN (".getEntity('product').") )"; |
||
| 2746 | if ($socid) $sql .= " AND pfp.fk_soc = ".$socid; |
||
| 2747 | $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON pfp.fk_soc = s.rowid"; |
||
| 2748 | // Units |
||
| 2749 | if ($conf->global->PRODUCT_USE_UNITS) { |
||
| 2750 | $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_units u ON u.rowid = p.fk_unit"; |
||
| 2751 | } |
||
| 2752 | $sql .= " WHERE p.entity IN (".getEntity('product').")"; |
||
| 2753 | $sql .= " AND p.tobuy = 1"; |
||
| 2754 | if (strval($filtertype) != '') $sql .= " AND p.fk_product_type=".$this->db->escape($filtertype); |
||
| 2755 | if (!empty($filtre)) $sql .= " ".$filtre; |
||
| 2756 | // Add criteria on ref/label |
||
| 2757 | if ($filterkey != '') |
||
| 2758 | { |
||
| 2759 | $sql .= ' AND ('; |
||
| 2760 | $prefix = empty($conf->global->PRODUCT_DONOTSEARCH_ANYWHERE) ? '%' : ''; // Can use index if PRODUCT_DONOTSEARCH_ANYWHERE is on |
||
| 2761 | // For natural search |
||
| 2762 | $scrit = explode(' ', $filterkey); |
||
| 2763 | $i = 0; |
||
| 2764 | if (count($scrit) > 1) $sql .= "("; |
||
| 2765 | foreach ($scrit as $crit) |
||
| 2766 | { |
||
| 2767 | if ($i > 0) $sql .= " AND "; |
||
| 2768 | $sql .= "(pfp.ref_fourn LIKE '".$this->db->escape($prefix.$crit)."%' OR p.ref LIKE '".$this->db->escape($prefix.$crit)."%' OR p.label LIKE '".$this->db->escape($prefix.$crit)."%')"; |
||
| 2769 | $i++; |
||
| 2770 | } |
||
| 2771 | if (count($scrit) > 1) $sql .= ")"; |
||
| 2772 | if (!empty($conf->barcode->enabled)) { |
||
| 2773 | $sql .= " OR p.barcode LIKE '".$this->db->escape($prefix.$filterkey)."%'"; |
||
| 2774 | $sql .= " OR pfp.barcode LIKE '".$this->db->escape($prefix.$filterkey)."%'"; |
||
| 2775 | } |
||
| 2776 | $sql .= ')'; |
||
| 2777 | } |
||
| 2778 | $sql .= " ORDER BY pfp.ref_fourn DESC, pfp.quantity ASC"; |
||
| 2779 | $sql .= $db->plimit($limit, 0); |
||
| 2780 | |||
| 2781 | // Build output string |
||
| 2782 | |||
| 2783 | dol_syslog(get_class($this)."::select_produits_fournisseurs_list", LOG_DEBUG); |
||
| 2784 | $result = $this->db->query($sql); |
||
| 2785 | if ($result) |
||
| 2786 | { |
||
| 2787 | require_once DOL_DOCUMENT_ROOT.'/product/dynamic_price/class/price_parser.class.php'; |
||
| 2788 | require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php'; |
||
| 2789 | |||
| 2790 | $num = $this->db->num_rows($result); |
||
| 2791 | |||
| 2792 | //$out.='<select class="flat" id="select'.$htmlname.'" name="'.$htmlname.'">'; // remove select to have id same with combo and ajax |
||
| 2793 | $out .= '<select class="flat maxwidthonsmartphone'.($morecss ? ' '.$morecss : '').'" id="'.$htmlname.'" name="'.$htmlname.'">'; |
||
| 2794 | if (!$selected) $out .= '<option value="0" selected> </option>'; |
||
| 2795 | else $out .= '<option value="0"> </option>'; |
||
| 2796 | |||
| 2797 | $i = 0; |
||
| 2798 | while ($i < $num) |
||
| 2799 | { |
||
| 2800 | $objp = $this->db->fetch_object($result); |
||
| 2801 | |||
| 2802 | $outkey = $objp->idprodfournprice; // id in table of price |
||
| 2803 | if (!$outkey && $alsoproductwithnosupplierprice) $outkey = 'idprod_'.$objp->rowid; // id of product |
||
| 2804 | |||
| 2805 | $outref = $objp->ref; |
||
| 2806 | $outval = ''; |
||
| 2807 | $outbarcode = $objp->barcode; |
||
| 2808 | $outqty = 1; |
||
| 2809 | $outdiscount = 0; |
||
| 2810 | $outtype = $objp->fk_product_type; |
||
| 2811 | $outdurationvalue = $outtype == Product::TYPE_SERVICE ?substr($objp->duration, 0, dol_strlen($objp->duration) - 1) : ''; |
||
| 2812 | $outdurationunit = $outtype == Product::TYPE_SERVICE ?substr($objp->duration, -1) : ''; |
||
| 2813 | |||
| 2814 | // Units |
||
| 2815 | $outvalUnits = ''; |
||
| 2816 | if ($conf->global->PRODUCT_USE_UNITS) { |
||
| 2817 | if (!empty($objp->unit_short)) { |
||
| 2818 | $outvalUnits .= ' - '.$objp->unit_short; |
||
| 2819 | } |
||
| 2820 | if (!empty($objp->weight) && $objp->weight_units !== null) { |
||
| 2821 | $unitToShow = showDimensionInBestUnit($objp->weight, $objp->weight_units, 'weight', $langs); |
||
| 2822 | $outvalUnits .= ' - '.$unitToShow; |
||
| 2823 | } |
||
| 2824 | if ((!empty($objp->length) || !empty($objp->width) || !empty($objp->height)) && $objp->length_units !== null) { |
||
| 2825 | $unitToShow = $objp->length.' x '.$objp->width.' x '.$objp->height.' '.measuringUnitString(0, 'size', $objp->length_units); |
||
| 2826 | $outvalUnits .= ' - '.$unitToShow; |
||
| 2827 | } |
||
| 2828 | if (!empty($objp->surface) && $objp->surface_units !== null) { |
||
| 2829 | $unitToShow = showDimensionInBestUnit($objp->surface, $objp->surface_units, 'surface', $langs); |
||
| 2830 | $outvalUnits .= ' - '.$unitToShow; |
||
| 2831 | } |
||
| 2832 | if (!empty($objp->volume) && $objp->volume_units !== null) { |
||
| 2833 | $unitToShow = showDimensionInBestUnit($objp->volume, $objp->volume_units, 'volume', $langs); |
||
| 2834 | $outvalUnits .= ' - '.$unitToShow; |
||
| 2835 | } |
||
| 2836 | if ($outdurationvalue && $outdurationunit) { |
||
| 2837 | $da = array( |
||
| 2838 | 'h' => $langs->trans('Hour'), |
||
| 2839 | 'd' => $langs->trans('Day'), |
||
| 2840 | 'w' => $langs->trans('Week'), |
||
| 2841 | 'm' => $langs->trans('Month'), |
||
| 2842 | 'y' => $langs->trans('Year') |
||
| 2843 | ); |
||
| 2844 | if (isset($da[$outdurationunit])) { |
||
| 2845 | $outvalUnits .= ' - '.$outdurationvalue.' '.$langs->transnoentities($da[$outdurationunit].($outdurationvalue > 1 ? 's' : '')); |
||
| 2846 | } |
||
| 2847 | } |
||
| 2848 | } |
||
| 2849 | |||
| 2850 | $objRef = $objp->ref; |
||
| 2851 | if ($filterkey && $filterkey != '') $objRef = preg_replace('/('.preg_quote($filterkey, '/').')/i', '<strong>$1</strong>', $objRef, 1); |
||
| 2852 | $objRefFourn = $objp->ref_fourn; |
||
| 2853 | if ($filterkey && $filterkey != '') $objRefFourn = preg_replace('/('.preg_quote($filterkey, '/').')/i', '<strong>$1</strong>', $objRefFourn, 1); |
||
| 2854 | $label = $objp->label; |
||
| 2855 | if ($filterkey && $filterkey != '') $label = preg_replace('/('.preg_quote($filterkey, '/').')/i', '<strong>$1</strong>', $label, 1); |
||
| 2856 | |||
| 2857 | $optlabel = $objp->ref; |
||
| 2858 | if (!empty($objp->idprodfournprice) && ($objp->ref != $objp->ref_fourn)) { |
||
| 2859 | $optlabel .= ' <span class=\'opacitymedium\'>('.$objp->ref_fourn.')</span>'; |
||
| 2860 | } |
||
| 2861 | if (!empty($conf->barcode->enabled) && !empty($objp->barcode)) { |
||
| 2862 | $optlabel .= ' ('.$outbarcode.')'; |
||
| 2863 | } |
||
| 2864 | $optlabel .= ' - '.dol_trunc($label, $maxlengtharticle); |
||
| 2865 | |||
| 2866 | $outvallabel = $objRef; |
||
| 2867 | if (!empty($objp->idprodfournprice) && ($objp->ref != $objp->ref_fourn)) { |
||
| 2868 | $outvallabel .= ' ('.$objRefFourn.')'; |
||
| 2869 | } |
||
| 2870 | if (!empty($conf->barcode->enabled) && !empty($objp->barcode)) { |
||
| 2871 | $outvallabel .= ' ('.$outbarcode.')'; |
||
| 2872 | } |
||
| 2873 | $outvallabel .= ' - '.dol_trunc($label, $maxlengtharticle); |
||
| 2874 | |||
| 2875 | // Units |
||
| 2876 | $optlabel .= $outvalUnits; |
||
| 2877 | $outvallabel .= $outvalUnits; |
||
| 2878 | |||
| 2879 | if (!empty($objp->idprodfournprice)) |
||
| 2880 | { |
||
| 2881 | $outqty = $objp->quantity; |
||
| 2882 | $outdiscount = $objp->remise_percent; |
||
| 2883 | if (!empty($conf->dynamicprices->enabled) && !empty($objp->fk_supplier_price_expression)) { |
||
| 2884 | $prod_supplier = new ProductFournisseur($this->db); |
||
| 2885 | $prod_supplier->product_fourn_price_id = $objp->idprodfournprice; |
||
| 2886 | $prod_supplier->id = $objp->fk_product; |
||
| 2887 | $prod_supplier->fourn_qty = $objp->quantity; |
||
| 2888 | $prod_supplier->fourn_tva_tx = $objp->tva_tx; |
||
| 2889 | $prod_supplier->fk_supplier_price_expression = $objp->fk_supplier_price_expression; |
||
| 2890 | $priceparser = new PriceParser($this->db); |
||
| 2891 | $price_result = $priceparser->parseProductSupplier($prod_supplier); |
||
| 2892 | if ($price_result >= 0) { |
||
| 2893 | $objp->fprice = $price_result; |
||
| 2894 | if ($objp->quantity >= 1) |
||
| 2895 | { |
||
| 2896 | $objp->unitprice = $objp->fprice / $objp->quantity; // Replace dynamically unitprice |
||
| 2897 | } |
||
| 2898 | } |
||
| 2899 | } |
||
| 2900 | if ($objp->quantity == 1) |
||
| 2901 | { |
||
| 2902 | $optlabel .= ' - '.price($objp->fprice * (!empty($conf->global->DISPLAY_DISCOUNTED_SUPPLIER_PRICE) ? (1 - $objp->remise_percent / 100) : 1), 1, $langs, 0, 0, -1, $conf->currency)."/"; |
||
| 2903 | $outvallabel .= ' - '.price($objp->fprice * (!empty($conf->global->DISPLAY_DISCOUNTED_SUPPLIER_PRICE) ? (1 - $objp->remise_percent / 100) : 1), 0, $langs, 0, 0, -1, $conf->currency)."/"; |
||
| 2904 | $optlabel .= $langs->trans("Unit"); // Do not use strtolower because it breaks utf8 encoding |
||
| 2905 | $outvallabel .= $langs->transnoentities("Unit"); |
||
| 2906 | } else { |
||
| 2907 | $optlabel .= ' - '.price($objp->fprice * (!empty($conf->global->DISPLAY_DISCOUNTED_SUPPLIER_PRICE) ? (1 - $objp->remise_percent / 100) : 1), 1, $langs, 0, 0, -1, $conf->currency)."/".$objp->quantity; |
||
| 2908 | $outvallabel .= ' - '.price($objp->fprice * (!empty($conf->global->DISPLAY_DISCOUNTED_SUPPLIER_PRICE) ? (1 - $objp->remise_percent / 100) : 1), 0, $langs, 0, 0, -1, $conf->currency)."/".$objp->quantity; |
||
| 2909 | $optlabel .= ' '.$langs->trans("Units"); // Do not use strtolower because it breaks utf8 encoding |
||
| 2910 | $outvallabel .= ' '.$langs->transnoentities("Units"); |
||
| 2911 | } |
||
| 2912 | |||
| 2913 | if ($objp->quantity > 1) |
||
| 2914 | { |
||
| 2915 | $optlabel .= " (".price($objp->unitprice * (!empty($conf->global->DISPLAY_DISCOUNTED_SUPPLIER_PRICE) ? (1 - $objp->remise_percent / 100) : 1), 1, $langs, 0, 0, -1, $conf->currency)."/".$langs->trans("Unit").")"; // Do not use strtolower because it breaks utf8 encoding |
||
| 2916 | $outvallabel .= " (".price($objp->unitprice * (!empty($conf->global->DISPLAY_DISCOUNTED_SUPPLIER_PRICE) ? (1 - $objp->remise_percent / 100) : 1), 0, $langs, 0, 0, -1, $conf->currency)."/".$langs->transnoentities("Unit").")"; // Do not use strtolower because it breaks utf8 encoding |
||
| 2917 | } |
||
| 2918 | if ($objp->remise_percent >= 1) |
||
| 2919 | { |
||
| 2920 | $optlabel .= " - ".$langs->trans("Discount")." : ".vatrate($objp->remise_percent).' %'; |
||
| 2921 | $outvallabel .= " - ".$langs->transnoentities("Discount")." : ".vatrate($objp->remise_percent).' %'; |
||
| 2922 | } |
||
| 2923 | if ($objp->duration) |
||
| 2924 | { |
||
| 2925 | $optlabel .= " - ".$objp->duration; |
||
| 2926 | $outvallabel .= " - ".$objp->duration; |
||
| 2927 | } |
||
| 2928 | if (!$socid) |
||
| 2929 | { |
||
| 2930 | $optlabel .= " - ".dol_trunc($objp->name, 8); |
||
| 2931 | $outvallabel .= " - ".dol_trunc($objp->name, 8); |
||
| 2932 | } |
||
| 2933 | if ($objp->supplier_reputation) |
||
| 2934 | { |
||
| 2935 | //TODO dictionary |
||
| 2936 | $reputations = array(''=>$langs->trans('Standard'), 'FAVORITE'=>$langs->trans('Favorite'), 'NOTTHGOOD'=>$langs->trans('NotTheGoodQualitySupplier'), 'DONOTORDER'=>$langs->trans('DoNotOrderThisProductToThisSupplier')); |
||
| 2937 | |||
| 2938 | $optlabel .= " - ".$reputations[$objp->supplier_reputation]; |
||
| 2939 | $outvallabel .= " - ".$reputations[$objp->supplier_reputation]; |
||
| 2940 | } |
||
| 2941 | } else { |
||
| 2942 | if (empty($alsoproductwithnosupplierprice)) // No supplier price defined for couple product/supplier |
||
| 2943 | { |
||
| 2944 | $optlabel .= " - <span class='opacitymedium'>".$langs->trans("NoPriceDefinedForThisSupplier").'</span>'; |
||
| 2945 | $outvallabel .= ' - '.$langs->transnoentities("NoPriceDefinedForThisSupplier"); |
||
| 2946 | } else // No supplier price defined for product, even on other suppliers |
||
| 2947 | { |
||
| 2948 | $optlabel .= " - <span class='opacitymedium'>".$langs->trans("NoPriceDefinedForThisSupplier").'</span>'; |
||
| 2949 | $outvallabel .= ' - '.$langs->transnoentities("NoPriceDefinedForThisSupplier"); |
||
| 2950 | } |
||
| 2951 | } |
||
| 2952 | |||
| 2953 | $opt = '<option value="'.$outkey.'"'; |
||
| 2954 | if ($selected && $selected == $objp->idprodfournprice) $opt .= ' selected'; |
||
| 2955 | if (empty($objp->idprodfournprice) && empty($alsoproductwithnosupplierprice)) $opt .= ' disabled'; |
||
| 2956 | if (!empty($objp->idprodfournprice) && $objp->idprodfournprice > 0) |
||
| 2957 | { |
||
| 2958 | $opt .= ' pbq="'.$objp->idprodfournprice.'" data-pbq="'.$objp->idprodfournprice.'" data-pbqqty="'.$objp->quantity.'" data-pbqup="'.$objp->unitprice.'" data-pbqpercent="'.$objp->remise_percent.'"'; |
||
| 2959 | } |
||
| 2960 | $opt .= ' data-html="'.dol_escape_htmltag($optlabel).'"'; |
||
| 2961 | $opt .= '>'; |
||
| 2962 | |||
| 2963 | $opt .= $optlabel; |
||
| 2964 | $outval .= $outvallabel; |
||
| 2965 | |||
| 2966 | $opt .= "</option>\n"; |
||
| 2967 | |||
| 2968 | |||
| 2969 | // Add new entry |
||
| 2970 | // "key" value of json key array is used by jQuery automatically as selected value |
||
| 2971 | // "label" value of json key array is used by jQuery automatically as text for combo box |
||
| 2972 | $out .= $opt; |
||
| 2973 | array_push($outarray, array('key'=>$outkey, 'value'=>$outref, 'label'=>$outval, 'qty'=>$outqty, 'up'=>$objp->unitprice, 'discount'=>$outdiscount, 'type'=>$outtype, 'duration_value'=>$outdurationvalue, 'duration_unit'=>$outdurationunit, 'disabled'=>(empty($objp->idprodfournprice) ?true:false))); |
||
| 2974 | // Exemple of var_dump $outarray |
||
| 2975 | // array(1) {[0]=>array(6) {[key"]=>string(1) "2" ["value"]=>string(3) "ppp" |
||
| 2976 | // ["label"]=>string(76) "ppp (<strong>f</strong>ff2) - ppp - 20,00 Euros/1unité (20,00 Euros/unité)" |
||
| 2977 | // ["qty"]=>string(1) "1" ["discount"]=>string(1) "0" ["disabled"]=>bool(false) |
||
| 2978 | //} |
||
| 2979 | //var_dump($outval); var_dump(utf8_check($outval)); var_dump(json_encode($outval)); |
||
| 2980 | //$outval=array('label'=>'ppp (<strong>f</strong>ff2) - ppp - 20,00 Euros/ Unité (20,00 Euros/unité)'); |
||
| 2981 | //var_dump($outval); var_dump(utf8_check($outval)); var_dump(json_encode($outval)); |
||
| 2982 | |||
| 2983 | $i++; |
||
| 2984 | } |
||
| 2985 | $out .= '</select>'; |
||
| 2986 | |||
| 2987 | $this->db->free($result); |
||
| 2988 | |||
| 2989 | include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php'; |
||
| 2990 | $out .= ajax_combobox($htmlname); |
||
| 2991 | |||
| 2992 | if (empty($outputmode)) return $out; |
||
| 2993 | return $outarray; |
||
| 2994 | } else { |
||
| 2995 | dol_print_error($this->db); |
||
| 2996 | } |
||
| 2997 | } |
||
| 2998 | |||
| 2999 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps |
||
| 3000 | /** |
||
| 3001 | * Return list of suppliers prices for a product |
||
| 3002 | * |
||
| 3003 | * @param int $productid Id of product |
||
| 3004 | * @param string $htmlname Name of HTML field |
||
| 3005 | * @param int $selected_supplier Pre-selected supplier if more than 1 result |
||
| 3006 | * @return string |
||
| 3007 | */ |
||
| 3008 | public function select_product_fourn_price($productid, $htmlname = 'productfournpriceid', $selected_supplier = '') |
||
| 3009 | { |
||
| 3010 | // phpcs:enable |
||
| 3011 | global $langs, $conf; |
||
| 3012 | |||
| 3013 | $langs->load('stocks'); |
||
| 3014 | |||
| 3015 | $sql = "SELECT p.rowid, p.ref, p.label, p.price, p.duration, pfp.fk_soc,"; |
||
| 3016 | $sql .= " pfp.ref_fourn, pfp.rowid as idprodfournprice, pfp.price as fprice, pfp.remise_percent, pfp.quantity, pfp.unitprice,"; |
||
| 3017 | $sql .= " pfp.fk_supplier_price_expression, pfp.fk_product, pfp.tva_tx, s.nom as name"; |
||
| 3018 | $sql .= " FROM ".MAIN_DB_PREFIX."product as p"; |
||
| 3019 | $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_fournisseur_price as pfp ON p.rowid = pfp.fk_product"; |
||
| 3020 | $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON pfp.fk_soc = s.rowid"; |
||
| 3021 | $sql .= " WHERE pfp.entity IN (".getEntity('productsupplierprice').")"; |
||
| 3022 | $sql .= " AND p.tobuy = 1"; |
||
| 3023 | $sql .= " AND s.fournisseur = 1"; |
||
| 3024 | $sql .= " AND p.rowid = ".$productid; |
||
| 3025 | $sql .= " ORDER BY s.nom, pfp.ref_fourn DESC"; |
||
| 3026 | |||
| 3027 | dol_syslog(get_class($this)."::select_product_fourn_price", LOG_DEBUG); |
||
| 3028 | $result = $this->db->query($sql); |
||
| 3029 | |||
| 3030 | if ($result) |
||
| 3031 | { |
||
| 3032 | $num = $this->db->num_rows($result); |
||
| 3033 | |||
| 3034 | $form = '<select class="flat" id="select_'.$htmlname.'" name="'.$htmlname.'">'; |
||
| 3035 | |||
| 3036 | if (!$num) |
||
| 3037 | { |
||
| 3038 | $form .= '<option value="0">-- '.$langs->trans("NoSupplierPriceDefinedForThisProduct").' --</option>'; |
||
| 3039 | } else { |
||
| 3040 | require_once DOL_DOCUMENT_ROOT.'/product/dynamic_price/class/price_parser.class.php'; |
||
| 3041 | $form .= '<option value="0"> </option>'; |
||
| 3042 | |||
| 3043 | $i = 0; |
||
| 3044 | while ($i < $num) |
||
| 3045 | { |
||
| 3046 | $objp = $this->db->fetch_object($result); |
||
| 3047 | |||
| 3048 | $opt = '<option value="'.$objp->idprodfournprice.'"'; |
||
| 3049 | //if there is only one supplier, preselect it |
||
| 3050 | if ($num == 1 || ($selected_supplier > 0 && $objp->fk_soc == $selected_supplier)) { |
||
| 3051 | $opt .= ' selected'; |
||
| 3052 | } |
||
| 3053 | $opt .= '>'.$objp->name.' - '.$objp->ref_fourn.' - '; |
||
| 3054 | |||
| 3055 | if (!empty($conf->dynamicprices->enabled) && !empty($objp->fk_supplier_price_expression)) { |
||
| 3056 | $prod_supplier = new ProductFournisseur($this->db); |
||
| 3057 | $prod_supplier->product_fourn_price_id = $objp->idprodfournprice; |
||
| 3058 | $prod_supplier->id = $productid; |
||
| 3059 | $prod_supplier->fourn_qty = $objp->quantity; |
||
| 3060 | $prod_supplier->fourn_tva_tx = $objp->tva_tx; |
||
| 3061 | $prod_supplier->fk_supplier_price_expression = $objp->fk_supplier_price_expression; |
||
| 3062 | $priceparser = new PriceParser($this->db); |
||
| 3063 | $price_result = $priceparser->parseProductSupplier($prod_supplier); |
||
| 3064 | if ($price_result >= 0) { |
||
| 3065 | $objp->fprice = $price_result; |
||
| 3066 | if ($objp->quantity >= 1) |
||
| 3067 | { |
||
| 3068 | $objp->unitprice = $objp->fprice / $objp->quantity; |
||
| 3069 | } |
||
| 3070 | } |
||
| 3071 | } |
||
| 3072 | if ($objp->quantity == 1) |
||
| 3073 | { |
||
| 3074 | $opt .= price($objp->fprice * (!empty($conf->global->DISPLAY_DISCOUNTED_SUPPLIER_PRICE) ? (1 - $objp->remise_percent / 100) : 1), 1, $langs, 0, 0, -1, $conf->currency)."/"; |
||
| 3075 | } |
||
| 3076 | |||
| 3077 | $opt .= $objp->quantity.' '; |
||
| 3078 | |||
| 3079 | if ($objp->quantity == 1) |
||
| 3080 | { |
||
| 3081 | $opt .= $langs->trans("Unit"); |
||
| 3082 | } else { |
||
| 3083 | $opt .= $langs->trans("Units"); |
||
| 3084 | } |
||
| 3085 | if ($objp->quantity > 1) |
||
| 3086 | { |
||
| 3087 | $opt .= " - "; |
||
| 3088 | $opt .= price($objp->unitprice * (!empty($conf->global->DISPLAY_DISCOUNTED_SUPPLIER_PRICE) ? (1 - $objp->remise_percent / 100) : 1), 1, $langs, 0, 0, -1, $conf->currency)."/".$langs->trans("Unit"); |
||
| 3089 | } |
||
| 3090 | if ($objp->duration) $opt .= " - ".$objp->duration; |
||
| 3091 | $opt .= "</option>\n"; |
||
| 3092 | |||
| 3093 | $form .= $opt; |
||
| 3094 | $i++; |
||
| 3095 | } |
||
| 3096 | } |
||
| 3097 | |||
| 3098 | $form .= '</select>'; |
||
| 3099 | $this->db->free($result); |
||
| 3100 | return $form; |
||
| 3101 | } else { |
||
| 3102 | dol_print_error($this->db); |
||
| 3103 | } |
||
| 3104 | } |
||
| 3105 | |||
| 3106 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps |
||
| 3107 | /** |
||
| 3108 | * Return list of delivery address |
||
| 3109 | * |
||
| 3110 | * @param string $selected Id contact pre-selectionn |
||
| 3111 | * @param int $socid Id of company |
||
| 3112 | * @param string $htmlname Name of HTML field |
||
| 3113 | * @param int $showempty Add an empty field |
||
| 3114 | * @return integer|null |
||
| 3115 | */ |
||
| 3116 | public function select_address($selected, $socid, $htmlname = 'address_id', $showempty = 0) |
||
| 3117 | { |
||
| 3118 | // phpcs:enable |
||
| 3119 | // looking for users |
||
| 3120 | $sql = "SELECT a.rowid, a.label"; |
||
| 3121 | $sql .= " FROM ".MAIN_DB_PREFIX."societe_address as a"; |
||
| 3122 | $sql .= " WHERE a.fk_soc = ".$socid; |
||
| 3123 | $sql .= " ORDER BY a.label ASC"; |
||
| 3124 | |||
| 3125 | dol_syslog(get_class($this)."::select_address", LOG_DEBUG); |
||
| 3126 | $resql = $this->db->query($sql); |
||
| 3127 | if ($resql) |
||
| 3128 | { |
||
| 3129 | print '<select class="flat" id="select_'.$htmlname.'" name="'.$htmlname.'">'; |
||
| 3130 | if ($showempty) print '<option value="0"> </option>'; |
||
| 3131 | $num = $this->db->num_rows($resql); |
||
| 3132 | $i = 0; |
||
| 3133 | if ($num) |
||
| 3134 | { |
||
| 3135 | while ($i < $num) |
||
| 3136 | { |
||
| 3137 | $obj = $this->db->fetch_object($resql); |
||
| 3138 | |||
| 3139 | if ($selected && $selected == $obj->rowid) |
||
| 3140 | { |
||
| 3141 | print '<option value="'.$obj->rowid.'" selected>'.$obj->label.'</option>'; |
||
| 3142 | } else { |
||
| 3143 | print '<option value="'.$obj->rowid.'">'.$obj->label.'</option>'; |
||
| 3144 | } |
||
| 3145 | $i++; |
||
| 3146 | } |
||
| 3147 | } |
||
| 3148 | print '</select>'; |
||
| 3149 | return $num; |
||
| 3150 | } else { |
||
| 3151 | dol_print_error($this->db); |
||
| 3152 | } |
||
| 3153 | } |
||
| 3154 | |||
| 3155 | |||
| 3156 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps |
||
| 3157 | /** |
||
| 3158 | * Load into cache list of payment terms |
||
| 3159 | * |
||
| 3160 | * @return int Nb of lines loaded, <0 if KO |
||
| 3161 | */ |
||
| 3162 | public function load_cache_conditions_paiements() |
||
| 3163 | { |
||
| 3164 | // phpcs:enable |
||
| 3165 | global $langs; |
||
| 3166 | |||
| 3167 | $num = count($this->cache_conditions_paiements); |
||
| 3168 | if ($num > 0) return 0; // Cache already loaded |
||
| 3169 | |||
| 3170 | dol_syslog(__METHOD__, LOG_DEBUG); |
||
| 3171 | |||
| 3172 | $sql = "SELECT rowid, code, libelle as label"; |
||
| 3173 | $sql .= " FROM ".MAIN_DB_PREFIX.'c_payment_term'; |
||
| 3174 | $sql .= " WHERE entity IN (".getEntity('c_payment_term').")"; |
||
| 3175 | $sql .= " AND active > 0"; |
||
| 3176 | $sql .= " ORDER BY sortorder"; |
||
| 3177 | |||
| 3178 | $resql = $this->db->query($sql); |
||
| 3179 | if ($resql) |
||
| 3180 | { |
||
| 3181 | $num = $this->db->num_rows($resql); |
||
| 3182 | $i = 0; |
||
| 3183 | while ($i < $num) |
||
| 3184 | { |
||
| 3185 | $obj = $this->db->fetch_object($resql); |
||
| 3186 | |||
| 3187 | // Si traduction existe, on l'utilise, sinon on prend le libelle par defaut |
||
| 3188 | $label = ($langs->trans("PaymentConditionShort".$obj->code) != ("PaymentConditionShort".$obj->code) ? $langs->trans("PaymentConditionShort".$obj->code) : ($obj->label != '-' ? $obj->label : '')); |
||
| 3189 | $this->cache_conditions_paiements[$obj->rowid]['code'] = $obj->code; |
||
| 3190 | $this->cache_conditions_paiements[$obj->rowid]['label'] = $label; |
||
| 3191 | $i++; |
||
| 3192 | } |
||
| 3193 | |||
| 3194 | //$this->cache_conditions_paiements=dol_sort_array($this->cache_conditions_paiements, 'label', 'asc', 0, 0, 1); // We use the field sortorder of table |
||
| 3195 | |||
| 3196 | return $num; |
||
| 3197 | } else { |
||
| 3198 | dol_print_error($this->db); |
||
| 3199 | return -1; |
||
| 3200 | } |
||
| 3201 | } |
||
| 3202 | |||
| 3203 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps |
||
| 3204 | /** |
||
| 3205 | * Charge dans cache la liste des délais de livraison possibles |
||
| 3206 | * |
||
| 3207 | * @return int Nb of lines loaded, <0 if KO |
||
| 3208 | */ |
||
| 3209 | public function load_cache_availability() |
||
| 3210 | { |
||
| 3211 | // phpcs:enable |
||
| 3212 | global $langs; |
||
| 3213 | |||
| 3214 | $num = count($this->cache_availability); |
||
| 3215 | if ($num > 0) return 0; // Cache already loaded |
||
| 3216 | |||
| 3217 | dol_syslog(__METHOD__, LOG_DEBUG); |
||
| 3218 | |||
| 3219 | $langs->load('propal'); |
||
| 3220 | |||
| 3221 | $sql = "SELECT rowid, code, label"; |
||
| 3222 | $sql .= " FROM ".MAIN_DB_PREFIX.'c_availability'; |
||
| 3223 | $sql .= " WHERE active > 0"; |
||
| 3224 | |||
| 3225 | $resql = $this->db->query($sql); |
||
| 3226 | if ($resql) |
||
| 3227 | { |
||
| 3228 | $num = $this->db->num_rows($resql); |
||
| 3229 | $i = 0; |
||
| 3230 | while ($i < $num) |
||
| 3231 | { |
||
| 3232 | $obj = $this->db->fetch_object($resql); |
||
| 3233 | |||
| 3234 | // Si traduction existe, on l'utilise, sinon on prend le libelle par defaut |
||
| 3235 | $label = ($langs->trans("AvailabilityType".$obj->code) != ("AvailabilityType".$obj->code) ? $langs->trans("AvailabilityType".$obj->code) : ($obj->label != '-' ? $obj->label : '')); |
||
| 3236 | $this->cache_availability[$obj->rowid]['code'] = $obj->code; |
||
| 3237 | $this->cache_availability[$obj->rowid]['label'] = $label; |
||
| 3238 | $i++; |
||
| 3239 | } |
||
| 3240 | |||
| 3241 | $this->cache_availability = dol_sort_array($this->cache_availability, 'label', 'asc', 0, 0, 1); |
||
| 3242 | |||
| 3243 | return $num; |
||
| 3244 | } else { |
||
| 3245 | dol_print_error($this->db); |
||
| 3246 | return -1; |
||
| 3247 | } |
||
| 3248 | } |
||
| 3249 | |||
| 3250 | /** |
||
| 3251 | * Retourne la liste des types de delais de livraison possibles |
||
| 3252 | * |
||
| 3253 | * @param int $selected Id du type de delais pre-selectionne |
||
| 3254 | * @param string $htmlname Nom de la zone select |
||
| 3255 | * @param string $filtertype To add a filter |
||
| 3256 | * @param int $addempty Add empty entry |
||
| 3257 | * @return void |
||
| 3258 | */ |
||
| 3259 | public function selectAvailabilityDelay($selected = '', $htmlname = 'availid', $filtertype = '', $addempty = 0) |
||
| 3260 | { |
||
| 3261 | global $langs, $user; |
||
| 3262 | |||
| 3263 | $this->load_cache_availability(); |
||
| 3264 | |||
| 3265 | dol_syslog(__METHOD__." selected=".$selected.", htmlname=".$htmlname, LOG_DEBUG); |
||
| 3266 | |||
| 3267 | print '<select id="'.$htmlname.'" class="flat" name="'.$htmlname.'">'; |
||
| 3268 | if ($addempty) print '<option value="0"> </option>'; |
||
| 3269 | foreach ($this->cache_availability as $id => $arrayavailability) |
||
| 3270 | { |
||
| 3271 | if ($selected == $id) |
||
| 3272 | { |
||
| 3273 | print '<option value="'.$id.'" selected>'; |
||
| 3274 | } else { |
||
| 3275 | print '<option value="'.$id.'">'; |
||
| 3276 | } |
||
| 3277 | print $arrayavailability['label']; |
||
| 3278 | print '</option>'; |
||
| 3279 | } |
||
| 3280 | print '</select>'; |
||
| 3281 | if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1); |
||
| 3282 | } |
||
| 3283 | |||
| 3284 | /** |
||
| 3285 | * Load into cache cache_demand_reason, array of input reasons |
||
| 3286 | * |
||
| 3287 | * @return int Nb of lines loaded, <0 if KO |
||
| 3288 | */ |
||
| 3289 | public function loadCacheInputReason() |
||
| 3290 | { |
||
| 3291 | global $langs; |
||
| 3292 | |||
| 3293 | $num = count($this->cache_demand_reason); |
||
| 3294 | if ($num > 0) return 0; // Cache already loaded |
||
| 3295 | |||
| 3296 | $sql = "SELECT rowid, code, label"; |
||
| 3297 | $sql .= " FROM ".MAIN_DB_PREFIX.'c_input_reason'; |
||
| 3298 | $sql .= " WHERE active > 0"; |
||
| 3299 | |||
| 3300 | $resql = $this->db->query($sql); |
||
| 3301 | if ($resql) |
||
| 3302 | { |
||
| 3303 | $num = $this->db->num_rows($resql); |
||
| 3304 | $i = 0; |
||
| 3305 | $tmparray = array(); |
||
| 3306 | while ($i < $num) |
||
| 3307 | { |
||
| 3308 | $obj = $this->db->fetch_object($resql); |
||
| 3309 | |||
| 3310 | // Si traduction existe, on l'utilise, sinon on prend le libelle par defaut |
||
| 3311 | $label = ($obj->label != '-' ? $obj->label : ''); |
||
| 3312 | if ($langs->trans("DemandReasonType".$obj->code) != ("DemandReasonType".$obj->code)) $label = $langs->trans("DemandReasonType".$obj->code); // So translation key DemandReasonTypeSRC_XXX will work |
||
| 3313 | if ($langs->trans($obj->code) != $obj->code) $label = $langs->trans($obj->code); // So translation key SRC_XXX will work |
||
| 3314 | |||
| 3315 | $tmparray[$obj->rowid]['id'] = $obj->rowid; |
||
| 3316 | $tmparray[$obj->rowid]['code'] = $obj->code; |
||
| 3317 | $tmparray[$obj->rowid]['label'] = $label; |
||
| 3318 | $i++; |
||
| 3319 | } |
||
| 3320 | |||
| 3321 | $this->cache_demand_reason = dol_sort_array($tmparray, 'label', 'asc', 0, 0, 1); |
||
| 3322 | |||
| 3323 | unset($tmparray); |
||
| 3324 | return $num; |
||
| 3325 | } else { |
||
| 3326 | dol_print_error($this->db); |
||
| 3327 | return -1; |
||
| 3328 | } |
||
| 3329 | } |
||
| 3330 | |||
| 3331 | /** |
||
| 3332 | * Return list of input reason (events that triggered an object creation, like after sending an emailing, making an advert, ...) |
||
| 3333 | * List found into table c_input_reason loaded by loadCacheInputReason |
||
| 3334 | * |
||
| 3335 | * @param int $selected Id or code of type origin to select by default |
||
| 3336 | * @param string $htmlname Nom de la zone select |
||
| 3337 | * @param string $exclude To exclude a code value (Example: SRC_PROP) |
||
| 3338 | * @param int $addempty Add an empty entry |
||
| 3339 | * @return void |
||
| 3340 | */ |
||
| 3341 | public function selectInputReason($selected = '', $htmlname = 'demandreasonid', $exclude = '', $addempty = 0) |
||
| 3342 | { |
||
| 3343 | global $langs, $user; |
||
| 3344 | |||
| 3345 | $this->loadCacheInputReason(); |
||
| 3346 | |||
| 3347 | print '<select class="flat" id="select_'.$htmlname.'" name="'.$htmlname.'">'; |
||
| 3348 | if ($addempty) print '<option value="0"'.(empty($selected) ? ' selected' : '').'> </option>'; |
||
| 3349 | foreach ($this->cache_demand_reason as $id => $arraydemandreason) |
||
| 3350 | { |
||
| 3351 | if ($arraydemandreason['code'] == $exclude) continue; |
||
| 3352 | |||
| 3353 | if ($selected && ($selected == $arraydemandreason['id'] || $selected == $arraydemandreason['code'])) |
||
| 3354 | { |
||
| 3355 | print '<option value="'.$arraydemandreason['id'].'" selected>'; |
||
| 3356 | } else { |
||
| 3357 | print '<option value="'.$arraydemandreason['id'].'">'; |
||
| 3358 | } |
||
| 3359 | $label = $arraydemandreason['label']; // Translation of label was already done into the ->loadCacheInputReason |
||
| 3360 | print $langs->trans($label); |
||
| 3361 | print '</option>'; |
||
| 3362 | } |
||
| 3363 | print '</select>'; |
||
| 3364 | if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1); |
||
| 3365 | } |
||
| 3366 | |||
| 3367 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps |
||
| 3368 | /** |
||
| 3369 | * Charge dans cache la liste des types de paiements possibles |
||
| 3370 | * |
||
| 3371 | * @return int Nb of lines loaded, <0 if KO |
||
| 3372 | */ |
||
| 3373 | public function load_cache_types_paiements() |
||
| 3374 | { |
||
| 3375 | // phpcs:enable |
||
| 3376 | global $langs; |
||
| 3377 | |||
| 3378 | $num = count($this->cache_types_paiements); |
||
| 3379 | if ($num > 0) return $num; // Cache already loaded |
||
| 3380 | |||
| 3381 | dol_syslog(__METHOD__, LOG_DEBUG); |
||
| 3382 | |||
| 3383 | $this->cache_types_paiements = array(); |
||
| 3384 | |||
| 3385 | $sql = "SELECT id, code, libelle as label, type, active"; |
||
| 3386 | $sql .= " FROM ".MAIN_DB_PREFIX."c_paiement"; |
||
| 3387 | $sql .= " WHERE entity IN (".getEntity('c_paiement').")"; |
||
| 3388 | //if ($active >= 0) $sql.= " AND active = ".$active; |
||
| 3389 | |||
| 3390 | $resql = $this->db->query($sql); |
||
| 3391 | if ($resql) |
||
| 3392 | { |
||
| 3393 | $num = $this->db->num_rows($resql); |
||
| 3394 | $i = 0; |
||
| 3395 | while ($i < $num) |
||
| 3396 | { |
||
| 3397 | $obj = $this->db->fetch_object($resql); |
||
| 3398 | |||
| 3399 | // Si traduction existe, on l'utilise, sinon on prend le libelle par defaut |
||
| 3400 | $label = ($langs->transnoentitiesnoconv("PaymentTypeShort".$obj->code) != ("PaymentTypeShort".$obj->code) ? $langs->transnoentitiesnoconv("PaymentTypeShort".$obj->code) : ($obj->label != '-' ? $obj->label : '')); |
||
| 3401 | $this->cache_types_paiements[$obj->id]['id'] = $obj->id; |
||
| 3402 | $this->cache_types_paiements[$obj->id]['code'] = $obj->code; |
||
| 3403 | $this->cache_types_paiements[$obj->id]['label'] = $label; |
||
| 3404 | $this->cache_types_paiements[$obj->id]['type'] = $obj->type; |
||
| 3405 | $this->cache_types_paiements[$obj->id]['active'] = $obj->active; |
||
| 3406 | $i++; |
||
| 3407 | } |
||
| 3408 | |||
| 3409 | $this->cache_types_paiements = dol_sort_array($this->cache_types_paiements, 'label', 'asc', 0, 0, 1); |
||
| 3410 | |||
| 3411 | return $num; |
||
| 3412 | } else { |
||
| 3413 | dol_print_error($this->db); |
||
| 3414 | return -1; |
||
| 3415 | } |
||
| 3416 | } |
||
| 3417 | |||
| 3418 | |||
| 3419 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps |
||
| 3420 | /** |
||
| 3421 | * Return list of payment modes. |
||
| 3422 | * Constant MAIN_DEFAULT_PAYMENT_TERM_ID can used to set default value but scope is all application, probably not what you want. |
||
| 3423 | * See instead to force the default value by the caller. |
||
| 3424 | * |
||
| 3425 | * @param int $selected Id of payment term to preselect by default |
||
| 3426 | * @param string $htmlname Nom de la zone select |
||
| 3427 | * @param int $filtertype Not used |
||
| 3428 | * @param int $addempty Add an empty entry |
||
| 3429 | * @param int $noinfoadmin 0=Add admin info, 1=Disable admin info |
||
| 3430 | * @param string $morecss Add more CSS on select tag |
||
| 3431 | * @return void |
||
| 3432 | */ |
||
| 3433 | public function select_conditions_paiements($selected = 0, $htmlname = 'condid', $filtertype = -1, $addempty = 0, $noinfoadmin = 0, $morecss = '') |
||
| 3434 | { |
||
| 3435 | // phpcs:enable |
||
| 3436 | global $langs, $user, $conf; |
||
| 3437 | |||
| 3438 | dol_syslog(__METHOD__." selected=".$selected.", htmlname=".$htmlname, LOG_DEBUG); |
||
| 3439 | |||
| 3440 | $this->load_cache_conditions_paiements(); |
||
| 3441 | |||
| 3442 | // Set default value if not already set by caller |
||
| 3443 | if (empty($selected) && !empty($conf->global->MAIN_DEFAULT_PAYMENT_TERM_ID)) $selected = $conf->global->MAIN_DEFAULT_PAYMENT_TERM_ID; |
||
| 3444 | |||
| 3445 | print '<select id="'.$htmlname.'" class="flat selectpaymentterms'.($morecss ? ' '.$morecss : '').'" name="'.$htmlname.'">'; |
||
| 3446 | if ($addempty) print '<option value="0"> </option>'; |
||
| 3447 | foreach ($this->cache_conditions_paiements as $id => $arrayconditions) |
||
| 3448 | { |
||
| 3449 | if ($selected == $id) |
||
| 3450 | { |
||
| 3451 | print '<option value="'.$id.'" selected>'; |
||
| 3452 | } else { |
||
| 3453 | print '<option value="'.$id.'">'; |
||
| 3454 | } |
||
| 3455 | print $arrayconditions['label']; |
||
| 3456 | print '</option>'; |
||
| 3457 | } |
||
| 3458 | print '</select>'; |
||
| 3459 | if ($user->admin && empty($noinfoadmin)) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1); |
||
| 3460 | } |
||
| 3461 | |||
| 3462 | |||
| 3463 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps |
||
| 3464 | /** |
||
| 3465 | * Return list of payment methods |
||
| 3466 | * Constant MAIN_DEFAULT_PAYMENT_TYPE_ID can used to set default value but scope is all application, probably not what you want. |
||
| 3467 | * |
||
| 3468 | * @param string $selected Id or code or preselected payment mode |
||
| 3469 | * @param string $htmlname Name of select field |
||
| 3470 | * @param string $filtertype To filter on field type in llx_c_paiement ('CRDT' or 'DBIT' or array('code'=>xx,'label'=>zz)) |
||
| 3471 | * @param int $format 0=id+label, 1=code+code, 2=code+label, 3=id+code |
||
| 3472 | * @param int $empty 1=can be empty, 0 otherwise |
||
| 3473 | * @param int $noadmininfo 0=Add admin info, 1=Disable admin info |
||
| 3474 | * @param int $maxlength Max length of label |
||
| 3475 | * @param int $active Active or not, -1 = all |
||
| 3476 | * @param string $morecss Add more CSS on select tag |
||
| 3477 | * @return void |
||
| 3478 | */ |
||
| 3479 | public function select_types_paiements($selected = '', $htmlname = 'paiementtype', $filtertype = '', $format = 0, $empty = 1, $noadmininfo = 0, $maxlength = 0, $active = 1, $morecss = '') |
||
| 3480 | { |
||
| 3481 | // phpcs:enable |
||
| 3482 | global $langs, $user, $conf; |
||
| 3483 | |||
| 3484 | dol_syslog(__METHOD__." ".$selected.", ".$htmlname.", ".$filtertype.", ".$format, LOG_DEBUG); |
||
| 3485 | |||
| 3486 | $filterarray = array(); |
||
| 3487 | if ($filtertype == 'CRDT') $filterarray = array(0, 2, 3); |
||
| 3488 | elseif ($filtertype == 'DBIT') $filterarray = array(1, 2, 3); |
||
| 3489 | elseif ($filtertype != '' && $filtertype != '-1') $filterarray = explode(',', $filtertype); |
||
| 3490 | |||
| 3491 | $this->load_cache_types_paiements(); |
||
| 3492 | |||
| 3493 | // Set default value if not already set by caller |
||
| 3494 | if (empty($selected) && !empty($conf->global->MAIN_DEFAULT_PAYMENT_TYPE_ID)) $selected = $conf->global->MAIN_DEFAULT_PAYMENT_TYPE_ID; |
||
| 3495 | |||
| 3496 | print '<select id="select'.$htmlname.'" class="flat selectpaymenttypes'.($morecss ? ' '.$morecss : '').'" name="'.$htmlname.'">'; |
||
| 3497 | if ($empty) print '<option value=""> </option>'; |
||
| 3498 | foreach ($this->cache_types_paiements as $id => $arraytypes) |
||
| 3499 | { |
||
| 3500 | // If not good status |
||
| 3501 | if ($active >= 0 && $arraytypes['active'] != $active) continue; |
||
| 3502 | |||
| 3503 | // On passe si on a demande de filtrer sur des modes de paiments particuliers |
||
| 3504 | if (count($filterarray) && !in_array($arraytypes['type'], $filterarray)) continue; |
||
| 3505 | |||
| 3506 | // We discard empty line if showempty is on because an empty line has already been output. |
||
| 3507 | if ($empty && empty($arraytypes['code'])) continue; |
||
| 3508 | |||
| 3509 | if ($format == 0) print '<option value="'.$id.'"'; |
||
| 3510 | elseif ($format == 1) print '<option value="'.$arraytypes['code'].'"'; |
||
| 3511 | elseif ($format == 2) print '<option value="'.$arraytypes['code'].'"'; |
||
| 3512 | elseif ($format == 3) print '<option value="'.$id.'"'; |
||
| 3513 | // Print attribute selected or not |
||
| 3514 | if ($format == 1 || $format == 2) { |
||
| 3515 | if ($selected == $arraytypes['code']) print ' selected'; |
||
| 3516 | } else { |
||
| 3517 | if ($selected == $id) print ' selected'; |
||
| 3518 | } |
||
| 3519 | print '>'; |
||
| 3520 | if ($format == 0) $value = ($maxlength ?dol_trunc($arraytypes['label'], $maxlength) : $arraytypes['label']); |
||
| 3521 | elseif ($format == 1) $value = $arraytypes['code']; |
||
| 3522 | elseif ($format == 2) $value = ($maxlength ?dol_trunc($arraytypes['label'], $maxlength) : $arraytypes['label']); |
||
| 3523 | elseif ($format == 3) $value = $arraytypes['code']; |
||
| 3524 | print $value ? $value : ' '; |
||
| 3525 | print '</option>'; |
||
| 3526 | } |
||
| 3527 | print '</select>'; |
||
| 3528 | if ($user->admin && !$noadmininfo) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1); |
||
| 3529 | } |
||
| 3530 | |||
| 3531 | |||
| 3532 | /** |
||
| 3533 | * Selection HT or TTC |
||
| 3534 | * |
||
| 3535 | * @param string $selected Id pre-selectionne |
||
| 3536 | * @param string $htmlname Nom de la zone select |
||
| 3537 | * @return string Code of HTML select to chose tax or not |
||
| 3538 | */ |
||
| 3539 | public function selectPriceBaseType($selected = '', $htmlname = 'price_base_type') |
||
| 3540 | { |
||
| 3541 | global $langs; |
||
| 3542 | |||
| 3543 | $return = ''; |
||
| 3544 | |||
| 3545 | $return .= '<select class="flat maxwidth75" id="select_'.$htmlname.'" name="'.$htmlname.'">'; |
||
| 3546 | $options = array( |
||
| 3547 | 'HT'=>$langs->trans("HT"), |
||
| 3548 | 'TTC'=>$langs->trans("TTC") |
||
| 3549 | ); |
||
| 3550 | foreach ($options as $id => $value) |
||
| 3551 | { |
||
| 3552 | if ($selected == $id) |
||
| 3553 | { |
||
| 3554 | $return .= '<option value="'.$id.'" selected>'.$value; |
||
| 3555 | } else { |
||
| 3556 | $return .= '<option value="'.$id.'">'.$value; |
||
| 3557 | } |
||
| 3558 | $return .= '</option>'; |
||
| 3559 | } |
||
| 3560 | $return .= '</select>'; |
||
| 3561 | |||
| 3562 | return $return; |
||
| 3563 | } |
||
| 3564 | |||
| 3565 | /** |
||
| 3566 | * Return a HTML select list of shipping mode |
||
| 3567 | * |
||
| 3568 | * @param string $selected Id shipping mode pre-selected |
||
| 3569 | * @param string $htmlname Name of select zone |
||
| 3570 | * @param string $filtre To filter list |
||
| 3571 | * @param int $useempty 1=Add an empty value in list, 2=Add an empty value in list only if there is more than 2 entries. |
||
| 3572 | * @param string $moreattrib To add more attribute on select |
||
| 3573 | * @return void |
||
| 3574 | */ |
||
| 3575 | public function selectShippingMethod($selected = '', $htmlname = 'shipping_method_id', $filtre = '', $useempty = 0, $moreattrib = '') |
||
| 3616 | } |
||
| 3617 | } |
||
| 3618 | |||
| 3619 | /** |
||
| 3620 | * Display form to select shipping mode |
||
| 3621 | * |
||
| 3622 | * @param string $page Page |
||
| 3623 | * @param int $selected Id of shipping mode |
||
| 3624 | * @param string $htmlname Name of select html field |
||
| 3625 | * @param int $addempty 1=Add an empty value in list, 2=Add an empty value in list only if there is more than 2 entries. |
||
| 3626 | * @return void |
||
| 3627 | */ |
||
| 3628 | public function formSelectShippingMethod($page, $selected = '', $htmlname = 'shipping_method_id', $addempty = 0) |
||
| 3629 | { |
||
| 3630 | global $langs, $db; |
||
| 3631 | |||
| 3632 | $langs->load("deliveries"); |
||
| 3633 | |||
| 3634 | if ($htmlname != "none") { |
||
| 3635 | print '<form method="POST" action="'.$page.'">'; |
||
| 3636 | print '<input type="hidden" name="action" value="setshippingmethod">'; |
||
| 3637 | print '<input type="hidden" name="token" value="'.newToken().'">'; |
||
| 3638 | $this->selectShippingMethod($selected, $htmlname, '', $addempty); |
||
| 3639 | print '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">'; |
||
| 3640 | print '</form>'; |
||
| 3641 | } else { |
||
| 3642 | if ($selected) { |
||
| 3643 | $code = $langs->getLabelFromKey($db, $selected, 'c_shipment_mode', 'rowid', 'code'); |
||
| 3644 | print $langs->trans("SendingMethod".strtoupper($code)); |
||
| 3645 | } else { |
||
| 3646 | print " "; |
||
| 3647 | } |
||
| 3648 | } |
||
| 3649 | } |
||
| 3650 | |||
| 3651 | /** |
||
| 3652 | * Creates HTML last in cycle situation invoices selector |
||
| 3653 | * |
||
| 3654 | * @param string $selected Preselected ID |
||
| 3655 | * @param int $socid Company ID |
||
| 3656 | * |
||
| 3657 | * @return string HTML select |
||
| 3658 | */ |
||
| 3659 | public function selectSituationInvoices($selected = '', $socid = 0) |
||
| 3660 | { |
||
| 3661 | global $langs; |
||
| 3662 | |||
| 3663 | $langs->load('bills'); |
||
| 3664 | |||
| 3665 | $opt = '<option value ="" selected></option>'; |
||
| 3666 | $sql = 'SELECT rowid, ref, situation_cycle_ref, situation_counter, situation_final, fk_soc'; |
||
| 3667 | $sql .= ' FROM '.MAIN_DB_PREFIX.'facture'; |
||
| 3668 | $sql .= ' WHERE entity IN ('.getEntity('invoice').')'; |
||
| 3669 | $sql .= ' AND situation_counter >= 1'; |
||
| 3670 | $sql .= ' AND fk_soc = '.(int) $socid; |
||
| 3671 | $sql .= ' AND type <> 2'; |
||
| 3672 | $sql .= ' ORDER by situation_cycle_ref, situation_counter desc'; |
||
| 3673 | $resql = $this->db->query($sql); |
||
| 3674 | |||
| 3675 | if ($resql && $this->db->num_rows($resql) > 0) { |
||
| 3676 | // Last seen cycle |
||
| 3677 | $ref = 0; |
||
| 3678 | while ($obj = $this->db->fetch_object($resql)) { |
||
| 3679 | //Same cycle ? |
||
| 3680 | if ($obj->situation_cycle_ref != $ref) { |
||
| 3681 | // Just seen this cycle |
||
| 3682 | $ref = $obj->situation_cycle_ref; |
||
| 3683 | //not final ? |
||
| 3684 | if ($obj->situation_final != 1) { |
||
| 3685 | //Not prov? |
||
| 3686 | if (substr($obj->ref, 1, 4) != 'PROV') { |
||
| 3687 | if ($selected == $obj->rowid) { |
||
| 3688 | $opt .= '<option value="'.$obj->rowid.'" selected>'.$obj->ref.'</option>'; |
||
| 3689 | } else { |
||
| 3690 | $opt .= '<option value="'.$obj->rowid.'">'.$obj->ref.'</option>'; |
||
| 3691 | } |
||
| 3692 | } |
||
| 3693 | } |
||
| 3694 | } |
||
| 3695 | } |
||
| 3696 | } else { |
||
| 3697 | dol_syslog("Error sql=".$sql.", error=".$this->error, LOG_ERR); |
||
| 3698 | } |
||
| 3699 | if ($opt == '<option value ="" selected></option>') |
||
| 3700 | { |
||
| 3701 | $opt = '<option value ="0" selected>'.$langs->trans('NoSituations').'</option>'; |
||
| 3702 | } |
||
| 3703 | return $opt; |
||
| 3704 | } |
||
| 3705 | |||
| 3706 | /** |
||
| 3707 | * Creates HTML units selector (code => label) |
||
| 3708 | * |
||
| 3709 | * @param string $selected Preselected Unit ID |
||
| 3710 | * @param string $htmlname Select name |
||
| 3711 | * @param int $showempty Add a nempty line |
||
| 3712 | * @return string HTML select |
||
| 3713 | */ |
||
| 3714 | public function selectUnits($selected = '', $htmlname = 'units', $showempty = 0) |
||
| 3715 | { |
||
| 3716 | global $langs; |
||
| 3717 | |||
| 3718 | $langs->load('products'); |
||
| 3719 | |||
| 3720 | $return = '<select class="flat" id="'.$htmlname.'" name="'.$htmlname.'">'; |
||
| 3721 | |||
| 3722 | $sql = 'SELECT rowid, label, code from '.MAIN_DB_PREFIX.'c_units'; |
||
| 3723 | $sql .= ' WHERE active > 0'; |
||
| 3724 | |||
| 3725 | $resql = $this->db->query($sql); |
||
| 3726 | if ($resql && $this->db->num_rows($resql) > 0) |
||
| 3727 | { |
||
| 3728 | if ($showempty) $return .= '<option value="none"></option>'; |
||
| 3729 | |||
| 3730 | while ($res = $this->db->fetch_object($resql)) |
||
| 3731 | { |
||
| 3732 | $unitLabel = $res->label; |
||
| 3733 | if (!empty($langs->tab_translate['unit'.$res->code])) // check if Translation is available before |
||
| 3734 | { |
||
| 3735 | $unitLabel = $langs->trans('unit'.$res->code) != $res->label ? $langs->trans('unit'.$res->code) : $res->label; |
||
| 3736 | } |
||
| 3737 | |||
| 3738 | if ($selected == $res->rowid) |
||
| 3739 | { |
||
| 3740 | $return .= '<option value="'.$res->rowid.'" selected>'.$unitLabel.'</option>'; |
||
| 3741 | } else { |
||
| 3742 | $return .= '<option value="'.$res->rowid.'">'.$unitLabel.'</option>'; |
||
| 3743 | } |
||
| 3744 | } |
||
| 3745 | $return .= '</select>'; |
||
| 3746 | } |
||
| 3747 | return $return; |
||
| 3748 | } |
||
| 3749 | |||
| 3750 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps |
||
| 3751 | /** |
||
| 3752 | * Return a HTML select list of bank accounts |
||
| 3753 | * |
||
| 3754 | * @param string $selected Id account pre-selected |
||
| 3755 | * @param string $htmlname Name of select zone |
||
| 3756 | * @param int $status Status of searched accounts (0=open, 1=closed, 2=both) |
||
| 3757 | * @param string $filtre To filter list |
||
| 3758 | * @param int $useempty 1=Add an empty value in list, 2=Add an empty value in list only if there is more than 2 entries. |
||
| 3759 | * @param string $moreattrib To add more attribute on select |
||
| 3760 | * @param int $showcurrency Show currency in label |
||
| 3761 | * @param string $morecss More CSS |
||
| 3762 | * @return int <0 if error, Num of bank account found if OK (0, 1, 2, ...) |
||
| 3763 | */ |
||
| 3764 | public function select_comptes($selected = '', $htmlname = 'accountid', $status = 0, $filtre = '', $useempty = 0, $moreattrib = '', $showcurrency = 0, $morecss = '') |
||
| 3818 | } |
||
| 3819 | |||
| 3820 | /** |
||
| 3821 | * Return a HTML select list of establishment |
||
| 3822 | * |
||
| 3823 | * @param string $selected Id establishment pre-selected |
||
| 3824 | * @param string $htmlname Name of select zone |
||
| 3825 | * @param int $status Status of searched establishment (0=open, 1=closed, 2=both) |
||
| 3826 | * @param string $filtre To filter list |
||
| 3827 | * @param int $useempty 1=Add an empty value in list, 2=Add an empty value in list only if there is more than 2 entries. |
||
| 3828 | * @param string $moreattrib To add more attribute on select |
||
| 3829 | * @return int <0 if error, Num of establishment found if OK (0, 1, 2, ...) |
||
| 3830 | */ |
||
| 3831 | public function selectEstablishments($selected = '', $htmlname = 'entity', $status = 0, $filtre = '', $useempty = 0, $moreattrib = '') |
||
| 3832 | { |
||
| 3833 | // phpcs:enable |
||
| 3834 | global $langs, $conf; |
||
| 3835 | |||
| 3836 | $langs->load("admin"); |
||
| 3837 | $num = 0; |
||
| 3838 | |||
| 3839 | $sql = "SELECT rowid, name, fk_country, status, entity"; |
||
| 3840 | $sql .= " FROM ".MAIN_DB_PREFIX."establishment"; |
||
| 3841 | $sql .= " WHERE 1=1"; |
||
| 3842 | if ($status != 2) $sql .= " AND status = ".(int) $status; |
||
| 3843 | if ($filtre) $sql .= " AND ".$filtre; |
||
| 3844 | $sql .= " ORDER BY name"; |
||
| 3845 | |||
| 3846 | dol_syslog(get_class($this)."::select_establishment", LOG_DEBUG); |
||
| 3847 | $result = $this->db->query($sql); |
||
| 3848 | if ($result) |
||
| 3849 | { |
||
| 3850 | $num = $this->db->num_rows($result); |
||
| 3851 | $i = 0; |
||
| 3852 | if ($num) |
||
| 3853 | { |
||
| 3854 | print '<select id="select'.$htmlname.'" class="flat selectestablishment" name="'.$htmlname.'"'.($moreattrib ? ' '.$moreattrib : '').'>'; |
||
| 3855 | if ($useempty == 1 || ($useempty == 2 && $num > 1)) |
||
| 3856 | { |
||
| 3857 | print '<option value="-1"> </option>'; |
||
| 3858 | } |
||
| 3859 | |||
| 3860 | while ($i < $num) |
||
| 3861 | { |
||
| 3862 | $obj = $this->db->fetch_object($result); |
||
| 3863 | if ($selected == $obj->rowid) |
||
| 3864 | { |
||
| 3865 | print '<option value="'.$obj->rowid.'" selected>'; |
||
| 3866 | } else { |
||
| 3867 | print '<option value="'.$obj->rowid.'">'; |
||
| 3868 | } |
||
| 3869 | print trim($obj->name); |
||
| 3870 | if ($status == 2 && $obj->status == 1) print ' ('.$langs->trans("Closed").')'; |
||
| 3871 | print '</option>'; |
||
| 3872 | $i++; |
||
| 3873 | } |
||
| 3874 | print "</select>"; |
||
| 3875 | } else { |
||
| 3876 | if ($status == 0) print '<span class="opacitymedium">'.$langs->trans("NoActiveEstablishmentDefined").'</span>'; |
||
| 3877 | else print '<span class="opacitymedium">'.$langs->trans("NoEstablishmentFound").'</span>'; |
||
| 3878 | } |
||
| 3879 | } else { |
||
| 3880 | dol_print_error($this->db); |
||
| 3881 | } |
||
| 3882 | } |
||
| 3883 | |||
| 3884 | /** |
||
| 3885 | * Display form to select bank account |
||
| 3886 | * |
||
| 3887 | * @param string $page Page |
||
| 3888 | * @param int $selected Id of bank account |
||
| 3889 | * @param string $htmlname Name of select html field |
||
| 3890 | * @param int $addempty 1=Add an empty value in list, 2=Add an empty value in list only if there is more than 2 entries. |
||
| 3891 | * @return void |
||
| 3892 | */ |
||
| 3893 | public function formSelectAccount($page, $selected = '', $htmlname = 'fk_account', $addempty = 0) |
||
| 3894 | { |
||
| 3895 | global $langs; |
||
| 3896 | if ($htmlname != "none") { |
||
| 3897 | print '<form method="POST" action="'.$page.'">'; |
||
| 3898 | print '<input type="hidden" name="action" value="setbankaccount">'; |
||
| 3899 | print '<input type="hidden" name="token" value="'.newToken().'">'; |
||
| 3900 | $nbaccountfound = $this->select_comptes($selected, $htmlname, 0, '', $addempty); |
||
| 3901 | if ($nbaccountfound > 0) print '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">'; |
||
| 3902 | print '</form>'; |
||
| 3903 | } else { |
||
| 3904 | $langs->load('banks'); |
||
| 3905 | |||
| 3906 | if ($selected) { |
||
| 3907 | require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; |
||
| 3908 | $bankstatic = new Account($this->db); |
||
| 3909 | $result = $bankstatic->fetch($selected); |
||
| 3910 | if ($result) print $bankstatic->getNomUrl(1); |
||
| 3911 | } else { |
||
| 3912 | print " "; |
||
| 3913 | } |
||
| 3914 | } |
||
| 3915 | } |
||
| 3916 | |||
| 3917 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps |
||
| 3918 | /** |
||
| 3919 | * Return list of categories having choosed type |
||
| 3920 | * |
||
| 3921 | * @param string|int $type Type of category ('customer', 'supplier', 'contact', 'product', 'member'). Old mode (0, 1, 2, ...) is deprecated. |
||
| 3922 | * @param string $selected Id of category preselected or 'auto' (autoselect category if there is only one element). Not used if $outputmode = 1. |
||
| 3923 | * @param string $htmlname HTML field name |
||
| 3924 | * @param int $maxlength Maximum length for labels |
||
| 3925 | * @param int|string|array $markafterid Keep only or removed all categories including the leaf $markafterid in category tree (exclude) or Keep only of category is inside the leaf starting with this id. |
||
| 3926 | * $markafterid can be an : |
||
| 3927 | * - int (id of category) |
||
| 3928 | * - string (categories ids seprated by comma) |
||
| 3929 | * - array (list of categories ids) |
||
| 3930 | * @param int $outputmode 0=HTML select string, 1=Array |
||
| 3931 | * @param int $include [=0] Removed or 1=Keep only |
||
| 3932 | * @param string $morecss More CSS |
||
| 3933 | * @return string |
||
| 3934 | * @see select_categories() |
||
| 3935 | */ |
||
| 3936 | public function select_all_categories($type, $selected = '', $htmlname = "parent", $maxlength = 64, $markafterid = 0, $outputmode = 0, $include = 0, $morecss = '') |
||
| 3937 | { |
||
| 3938 | // phpcs:enable |
||
| 3939 | global $conf, $langs; |
||
| 3940 | $langs->load("categories"); |
||
| 3941 | |||
| 3942 | include_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; |
||
| 3943 | |||
| 3944 | // For backward compatibility |
||
| 3945 | if (is_numeric($type)) |
||
| 3946 | { |
||
| 3947 | dol_syslog(__METHOD__.': using numeric value for parameter type is deprecated. Use string code instead.', LOG_WARNING); |
||
| 3948 | } |
||
| 3949 | |||
| 3950 | if ($type === Categorie::TYPE_BANK_LINE) |
||
| 3951 | { |
||
| 3952 | // TODO Move this into common category feature |
||
| 3953 | $cate_arbo = array(); |
||
| 3954 | $sql = "SELECT c.label, c.rowid"; |
||
| 3955 | $sql .= " FROM ".MAIN_DB_PREFIX."bank_categ as c"; |
||
| 3956 | $sql .= " WHERE entity = ".$conf->entity; |
||
| 3957 | $sql .= " ORDER BY c.label"; |
||
| 3958 | $result = $this->db->query($sql); |
||
| 3959 | if ($result) |
||
| 3960 | { |
||
| 3961 | $num = $this->db->num_rows($result); |
||
| 3962 | $i = 0; |
||
| 3963 | while ($i < $num) |
||
| 3964 | { |
||
| 3965 | $objp = $this->db->fetch_object($result); |
||
| 3966 | if ($objp) $cate_arbo[$objp->rowid] = array('id'=>$objp->rowid, 'fulllabel'=>$objp->label); |
||
| 3967 | $i++; |
||
| 3968 | } |
||
| 3969 | $this->db->free($result); |
||
| 3970 | } else dol_print_error($this->db); |
||
| 3971 | } else { |
||
| 3972 | $cat = new Categorie($this->db); |
||
| 3973 | $cate_arbo = $cat->get_full_arbo($type, $markafterid, $include); |
||
| 3974 | } |
||
| 3975 | |||
| 3976 | $output = '<select class="flat'.($morecss ? ' '.$morecss : '').'" name="'.$htmlname.'" id="'.$htmlname.'">'; |
||
| 3977 | $outarray = array(); |
||
| 3978 | if (is_array($cate_arbo)) |
||
| 3979 | { |
||
| 3980 | if (!count($cate_arbo)) $output .= '<option value="-1" disabled>'.$langs->trans("NoCategoriesDefined").'</option>'; |
||
| 3981 | else { |
||
| 3982 | $output .= '<option value="-1"> </option>'; |
||
| 3983 | foreach ($cate_arbo as $key => $value) |
||
| 3984 | { |
||
| 3985 | if ($cate_arbo[$key]['id'] == $selected || ($selected == 'auto' && count($cate_arbo) == 1)) |
||
| 3986 | { |
||
| 3987 | $add = 'selected '; |
||
| 3988 | } else { |
||
| 3989 | $add = ''; |
||
| 3990 | } |
||
| 3991 | $output .= '<option '.$add.'value="'.$cate_arbo[$key]['id'].'">'.dol_trunc($cate_arbo[$key]['fulllabel'], $maxlength, 'middle').'</option>'; |
||
| 3992 | |||
| 3993 | $outarray[$cate_arbo[$key]['id']] = $cate_arbo[$key]['fulllabel']; |
||
| 3994 | } |
||
| 3995 | } |
||
| 3996 | } |
||
| 3997 | $output .= '</select>'; |
||
| 3998 | $output .= "\n"; |
||
| 3999 | |||
| 4000 | if ($outputmode) return $outarray; |
||
| 4001 | return $output; |
||
| 4002 | } |
||
| 4003 | |||
| 4004 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps |
||
| 4005 | /** |
||
| 4006 | * Show a confirmation HTML form or AJAX popup |
||
| 4007 | * |
||
| 4008 | * @param string $page Url of page to call if confirmation is OK |
||
| 4009 | * @param string $title Title |
||
| 4010 | * @param string $question Question |
||
| 4011 | * @param string $action Action |
||
| 4012 | * @param array $formquestion An array with forms complementary inputs |
||
| 4013 | * @param string $selectedchoice "" or "no" or "yes" |
||
| 4014 | * @param int $useajax 0=No, 1=Yes, 2=Yes but submit page with &confirm=no if choice is No, 'xxx'=preoutput confirm box with div id=dialog-confirm-xxx |
||
| 4015 | * @param int $height Force height of box |
||
| 4016 | * @param int $width Force width of box |
||
| 4017 | * @return void |
||
| 4018 | * @deprecated |
||
| 4019 | * @see formconfirm() |
||
| 4020 | */ |
||
| 4021 | public function form_confirm($page, $title, $question, $action, $formquestion = '', $selectedchoice = "", $useajax = 0, $height = 170, $width = 500) |
||
| 4022 | { |
||
| 4023 | // phpcs:enable |
||
| 4024 | dol_syslog(__METHOD__.': using form_confirm is deprecated. Use formconfim instead.', LOG_WARNING); |
||
| 4025 | print $this->formconfirm($page, $title, $question, $action, $formquestion, $selectedchoice, $useajax, $height, $width); |
||
| 4026 | } |
||
| 4027 | |||
| 4028 | /** |
||
| 4029 | * Show a confirmation HTML form or AJAX popup. |
||
| 4030 | * Easiest way to use this is with useajax=1. |
||
| 4031 | * If you use useajax='xxx', you must also add jquery code to trigger opening of box (with correct parameters) |
||
| 4032 | * just after calling this method. For example: |
||
| 4033 | * print '<script type="text/javascript">'."\n"; |
||
| 4034 | * print 'jQuery(document).ready(function() {'."\n"; |
||
| 4035 | * print 'jQuery(".xxxlink").click(function(e) { jQuery("#aparamid").val(jQuery(this).attr("rel")); jQuery("#dialog-confirm-xxx").dialog("open"); return false; });'."\n"; |
||
| 4036 | * print '});'."\n"; |
||
| 4037 | * print '</script>'."\n"; |
||
| 4038 | * |
||
| 4039 | * @param string $page Url of page to call if confirmation is OK. Can contains parameters (param 'action' and 'confirm' will be reformated) |
||
| 4040 | * @param string $title Title |
||
| 4041 | * @param string $question Question |
||
| 4042 | * @param string $action Action |
||
| 4043 | * @param array|string $formquestion An array with complementary inputs to add into forms: array(array('label'=> ,'type'=> , )) |
||
| 4044 | * type can be 'hidden', 'text', 'password', 'checkbox', 'radio', 'date', 'morecss', ... |
||
| 4045 | * @param string $selectedchoice '' or 'no', or 'yes' or '1' or '0' |
||
| 4046 | * @param int|string $useajax 0=No, 1=Yes, 2=Yes but submit page with &confirm=no if choice is No, 'xxx'=Yes and preoutput confirm box with div id=dialog-confirm-xxx |
||
| 4047 | * @param int $height Force height of box (0 = auto) |
||
| 4048 | * @param int $width Force width of box ('999' or '90%'). Ignored and forced to 90% on smartphones. |
||
| 4049 | * @param int $disableformtag 1=Disable form tag. Can be used if we are already inside a <form> section. |
||
| 4050 | * @return string HTML ajax code if a confirm ajax popup is required, Pure HTML code if it's an html form |
||
| 4051 | */ |
||
| 4052 | public function formconfirm($page, $title, $question, $action, $formquestion = '', $selectedchoice = '', $useajax = 0, $height = 0, $width = 500, $disableformtag = 0) |
||
| 4053 | { |
||
| 4054 | global $langs, $conf; |
||
| 4055 | |||
| 4056 | $more = '<!-- formconfirm -->'; |
||
| 4057 | $formconfirm = ''; |
||
| 4058 | $inputok = array(); |
||
| 4059 | $inputko = array(); |
||
| 4060 | |||
| 4061 | // Clean parameters |
||
| 4062 | $newselectedchoice = empty($selectedchoice) ? "no" : $selectedchoice; |
||
| 4063 | if ($conf->browser->layout == 'phone') $width = '95%'; |
||
| 4064 | |||
| 4065 | // Set height automatically if not defined |
||
| 4066 | if (empty($height)) { |
||
| 4067 | $height = 210; |
||
| 4068 | if (is_array($formquestion) && count($formquestion) > 2) { |
||
| 4069 | $height += ((count($formquestion) - 2) * 24); |
||
| 4070 | } |
||
| 4071 | } |
||
| 4072 | |||
| 4073 | if (is_array($formquestion) && !empty($formquestion)) |
||
| 4074 | { |
||
| 4075 | // First add hidden fields and value |
||
| 4076 | foreach ($formquestion as $key => $input) |
||
| 4077 | { |
||
| 4078 | if (is_array($input) && !empty($input)) |
||
| 4079 | { |
||
| 4080 | if ($input['type'] == 'hidden') |
||
| 4081 | { |
||
| 4082 | $more .= '<input type="hidden" id="'.$input['name'].'" name="'.$input['name'].'" value="'.dol_escape_htmltag($input['value']).'">'."\n"; |
||
| 4083 | } |
||
| 4084 | } |
||
| 4085 | } |
||
| 4086 | |||
| 4087 | // Now add questions |
||
| 4088 | $moreonecolumn = ''; |
||
| 4089 | $more .= '<div class="tagtable paddingtopbottomonly centpercent noborderspacing">'."\n"; |
||
| 4090 | foreach ($formquestion as $key => $input) |
||
| 4091 | { |
||
| 4092 | if (is_array($input) && !empty($input)) |
||
| 4093 | { |
||
| 4094 | $size = (!empty($input['size']) ? ' size="'.$input['size'].'"' : ''); |
||
| 4095 | $moreattr = (!empty($input['moreattr']) ? ' '.$input['moreattr'] : ''); |
||
| 4096 | $morecss = (!empty($input['morecss']) ? ' '.$input['morecss'] : ''); |
||
| 4097 | |||
| 4098 | if ($input['type'] == 'text') |
||
| 4099 | { |
||
| 4100 | $more .= '<div class="tagtr"><div class="tagtd'.(empty($input['tdclass']) ? '' : (' '.$input['tdclass'])).'">'.$input['label'].'</div><div class="tagtd"><input type="text" class="flat'.$morecss.'" id="'.$input['name'].'" name="'.$input['name'].'"'.$size.' value="'.$input['value'].'"'.$moreattr.' /></div></div>'."\n"; |
||
| 4101 | } elseif ($input['type'] == 'password') |
||
| 4102 | { |
||
| 4103 | $more .= '<div class="tagtr"><div class="tagtd'.(empty($input['tdclass']) ? '' : (' '.$input['tdclass'])).'">'.$input['label'].'</div><div class="tagtd"><input type="password" class="flat'.$morecss.'" id="'.$input['name'].'" name="'.$input['name'].'"'.$size.' value="'.$input['value'].'"'.$moreattr.' /></div></div>'."\n"; |
||
| 4104 | } elseif ($input['type'] == 'select') |
||
| 4105 | { |
||
| 4106 | $more .= '<div class="tagtr"><div class="tagtd'.(empty($input['tdclass']) ? '' : (' '.$input['tdclass'])).'">'; |
||
| 4107 | if (!empty($input['label'])) $more .= $input['label'].'</div><div class="tagtd left">'; |
||
| 4108 | $more .= $this->selectarray($input['name'], $input['values'], $input['default'], 1, 0, 0, $moreattr, 0, 0, 0, '', $morecss); |
||
| 4109 | $more .= '</div></div>'."\n"; |
||
| 4110 | } elseif ($input['type'] == 'checkbox') |
||
| 4111 | { |
||
| 4112 | $more .= '<div class="tagtr">'; |
||
| 4113 | $more .= '<div class="tagtd'.(empty($input['tdclass']) ? '' : (' '.$input['tdclass'])).'">'.$input['label'].' </div><div class="tagtd">'; |
||
| 4114 | $more .= '<input type="checkbox" class="flat'.$morecss.'" id="'.$input['name'].'" name="'.$input['name'].'"'.$moreattr; |
||
| 4115 | if (!is_bool($input['value']) && $input['value'] != 'false' && $input['value'] != '0') $more .= ' checked'; |
||
| 4116 | if (is_bool($input['value']) && $input['value']) $more .= ' checked'; |
||
| 4117 | if (isset($input['disabled'])) $more .= ' disabled'; |
||
| 4118 | $more .= ' /></div>'; |
||
| 4119 | $more .= '</div>'."\n"; |
||
| 4120 | } elseif ($input['type'] == 'radio') |
||
| 4121 | { |
||
| 4122 | $i = 0; |
||
| 4123 | foreach ($input['values'] as $selkey => $selval) |
||
| 4124 | { |
||
| 4125 | $more .= '<div class="tagtr">'; |
||
| 4126 | if ($i == 0) $more .= '<div class="tagtd'.(empty($input['tdclass']) ? ' tdtop' : (' tdtop '.$input['tdclass'])).'">'.$input['label'].'</div>'; |
||
| 4127 | else $more .= '<div clas="tagtd'.(empty($input['tdclass']) ? '' : (' "'.$input['tdclass'])).'"> </div>'; |
||
| 4128 | $more .= '<div class="tagtd"><input type="radio" class="flat'.$morecss.'" id="'.$input['name'].'" name="'.$input['name'].'" value="'.$selkey.'"'.$moreattr; |
||
| 4129 | if ($input['disabled']) $more .= ' disabled'; |
||
| 4130 | $more .= ' /> '; |
||
| 4131 | $more .= $selval; |
||
| 4132 | $more .= '</div></div>'."\n"; |
||
| 4133 | $i++; |
||
| 4134 | } |
||
| 4135 | } elseif ($input['type'] == 'date') |
||
| 4136 | { |
||
| 4137 | $more .= '<div class="tagtr"><div class="tagtd'.(empty($input['tdclass']) ? '' : (' '.$input['tdclass'])).'">'.$input['label'].'</div>'; |
||
| 4138 | $more .= '<div class="tagtd">'; |
||
| 4139 | $more .= $this->selectDate($input['value'], $input['name'], 0, 0, 0, '', 1, 0); |
||
| 4140 | $more .= '</div></div>'."\n"; |
||
| 4141 | $formquestion[] = array('name'=>$input['name'].'day'); |
||
| 4142 | $formquestion[] = array('name'=>$input['name'].'month'); |
||
| 4143 | $formquestion[] = array('name'=>$input['name'].'year'); |
||
| 4144 | $formquestion[] = array('name'=>$input['name'].'hour'); |
||
| 4145 | $formquestion[] = array('name'=>$input['name'].'min'); |
||
| 4146 | } elseif ($input['type'] == 'other') |
||
| 4147 | { |
||
| 4148 | $more .= '<div class="tagtr"><div class="tagtd'.(empty($input['tdclass']) ? '' : (' '.$input['tdclass'])).'">'; |
||
| 4149 | if (!empty($input['label'])) $more .= $input['label'].'</div><div class="tagtd">'; |
||
| 4150 | $more .= $input['value']; |
||
| 4151 | $more .= '</div></div>'."\n"; |
||
| 4152 | } elseif ($input['type'] == 'onecolumn') |
||
| 4153 | { |
||
| 4154 | $moreonecolumn .= '<div class="margintoponly">'; |
||
| 4155 | $moreonecolumn .= $input['value']; |
||
| 4156 | $moreonecolumn .= '</div>'."\n"; |
||
| 4157 | } |
||
| 4158 | } |
||
| 4159 | } |
||
| 4160 | $more .= '</div>'."\n"; |
||
| 4161 | $more .= $moreonecolumn; |
||
| 4162 | } |
||
| 4163 | |||
| 4164 | // JQUI method dialog is broken with jmobile, we use standard HTML. |
||
| 4165 | // Note: When using dol_use_jmobile or no js, you must also check code for button use a GET url with action=xxx and check that you also output the confirm code when action=xxx |
||
| 4166 | // See page product/card.php for example |
||
| 4167 | if (!empty($conf->dol_use_jmobile)) $useajax = 0; |
||
| 4168 | if (empty($conf->use_javascript_ajax)) $useajax = 0; |
||
| 4169 | |||
| 4170 | if ($useajax) |
||
| 4171 | { |
||
| 4172 | $autoOpen = true; |
||
| 4173 | $dialogconfirm = 'dialog-confirm'; |
||
| 4174 | $button = ''; |
||
| 4175 | if (!is_numeric($useajax)) |
||
| 4176 | { |
||
| 4177 | $button = $useajax; |
||
| 4178 | $useajax = 1; |
||
| 4179 | $autoOpen = false; |
||
| 4180 | $dialogconfirm .= '-'.$button; |
||
| 4181 | } |
||
| 4182 | $pageyes = $page.(preg_match('/\?/', $page) ? '&' : '?').'action='.$action.'&confirm=yes'; |
||
| 4183 | $pageno = ($useajax == 2 ? $page.(preg_match('/\?/', $page) ? '&' : '?').'confirm=no' : ''); |
||
| 4184 | // Add input fields into list of fields to read during submit (inputok and inputko) |
||
| 4185 | if (is_array($formquestion)) |
||
| 4186 | { |
||
| 4187 | foreach ($formquestion as $key => $input) |
||
| 4188 | { |
||
| 4189 | //print "xx ".$key." rr ".is_array($input)."<br>\n"; |
||
| 4190 | if (is_array($input) && isset($input['name'])) array_push($inputok, $input['name']); |
||
| 4191 | if (isset($input['inputko']) && $input['inputko'] == 1) array_push($inputko, $input['name']); |
||
| 4192 | } |
||
| 4193 | } |
||
| 4194 | // Show JQuery confirm box. |
||
| 4195 | $formconfirm .= '<div id="'.$dialogconfirm.'" title="'.dol_escape_htmltag($title).'" style="display: none;">'; |
||
| 4196 | if (is_array($formquestion) && !empty($formquestion['text'])) { |
||
| 4197 | $formconfirm .= '<div class="confirmtext">'.$formquestion['text'].'</div>'."\n"; |
||
| 4198 | } |
||
| 4199 | if (!empty($more)) { |
||
| 4200 | $formconfirm .= '<div class="confirmquestions">'.$more.'</div>'."\n"; |
||
| 4201 | } |
||
| 4202 | $formconfirm .= ($question ? '<div class="confirmmessage">'.img_help('', '').' '.$question.'</div>' : ''); |
||
| 4203 | $formconfirm .= '</div>'."\n"; |
||
| 4204 | |||
| 4205 | $formconfirm .= "\n<!-- begin ajax formconfirm page=".$page." -->\n"; |
||
| 4206 | $formconfirm .= '<script type="text/javascript">'."\n"; |
||
| 4207 | $formconfirm .= 'jQuery(document).ready(function() { |
||
| 4208 | $(function() { |
||
| 4209 | $( "#'.$dialogconfirm.'" ).dialog( |
||
| 4210 | { |
||
| 4211 | autoOpen: '.($autoOpen ? "true" : "false").','; |
||
| 4212 | if ($newselectedchoice == 'no') |
||
| 4213 | { |
||
| 4214 | $formconfirm .= ' |
||
| 4215 | open: function() { |
||
| 4216 | $(this).parent().find("button.ui-button:eq(2)").focus(); |
||
| 4217 | },'; |
||
| 4218 | } |
||
| 4219 | $formconfirm .= ' |
||
| 4220 | resizable: false, |
||
| 4221 | height: "'.$height.'", |
||
| 4222 | width: "'.$width.'", |
||
| 4223 | modal: true, |
||
| 4224 | closeOnEscape: false, |
||
| 4225 | buttons: { |
||
| 4226 | "'.dol_escape_js($langs->transnoentities("Yes")).'": function() { |
||
| 4227 | var options = "&token='.urlencode(newToken()).'"; |
||
| 4228 | var inputok = '.json_encode($inputok).'; /* List of fields into form */ |
||
| 4229 | var pageyes = "'.dol_escape_js(!empty($pageyes) ? $pageyes : '').'"; |
||
| 4230 | if (inputok.length>0) { |
||
| 4231 | $.each(inputok, function(i, inputname) { |
||
| 4232 | var more = ""; |
||
| 4233 | if ($("#" + inputname).attr("type") == "checkbox") { more = ":checked"; } |
||
| 4234 | if ($("#" + inputname).attr("type") == "radio") { more = ":checked"; } |
||
| 4235 | var inputvalue = $("#" + inputname + more).val(); |
||
| 4236 | if (typeof inputvalue == "undefined") { inputvalue=""; } |
||
| 4237 | options += "&" + inputname + "=" + encodeURIComponent(inputvalue); |
||
| 4238 | }); |
||
| 4239 | } |
||
| 4240 | var urljump = pageyes + (pageyes.indexOf("?") < 0 ? "?" : "") + options; |
||
| 4241 | //alert(urljump); |
||
| 4242 | if (pageyes.length > 0) { location.href = urljump; } |
||
| 4243 | $(this).dialog("close"); |
||
| 4244 | }, |
||
| 4245 | "'.dol_escape_js($langs->transnoentities("No")).'": function() { |
||
| 4246 | var options = "&token='.urlencode(newToken()).'"; |
||
| 4247 | var inputko = '.json_encode($inputko).'; /* List of fields into form */ |
||
| 4248 | var pageno="'.dol_escape_js(!empty($pageno) ? $pageno : '').'"; |
||
| 4249 | if (inputko.length>0) { |
||
| 4250 | $.each(inputko, function(i, inputname) { |
||
| 4251 | var more = ""; |
||
| 4252 | if ($("#" + inputname).attr("type") == "checkbox") { more = ":checked"; } |
||
| 4253 | var inputvalue = $("#" + inputname + more).val(); |
||
| 4254 | if (typeof inputvalue == "undefined") { inputvalue=""; } |
||
| 4255 | options += "&" + inputname + "=" + encodeURIComponent(inputvalue); |
||
| 4256 | }); |
||
| 4257 | } |
||
| 4258 | var urljump=pageno + (pageno.indexOf("?") < 0 ? "?" : "") + options; |
||
| 4259 | //alert(urljump); |
||
| 4260 | if (pageno.length > 0) { location.href = urljump; } |
||
| 4261 | $(this).dialog("close"); |
||
| 4262 | } |
||
| 4263 | } |
||
| 4264 | } |
||
| 4265 | ); |
||
| 4266 | |||
| 4267 | var button = "'.$button.'"; |
||
| 4268 | if (button.length > 0) { |
||
| 4269 | $( "#" + button ).click(function() { |
||
| 4270 | $("#'.$dialogconfirm.'").dialog("open"); |
||
| 4271 | }); |
||
| 4272 | } |
||
| 4273 | }); |
||
| 4274 | }); |
||
| 4275 | </script>'; |
||
| 4276 | $formconfirm .= "<!-- end ajax formconfirm -->\n"; |
||
| 4277 | } else { |
||
| 4278 | $formconfirm .= "\n<!-- begin formconfirm page=".$page." -->\n"; |
||
| 4279 | |||
| 4280 | if (empty($disableformtag)) $formconfirm .= '<form method="POST" action="'.$page.'" class="notoptoleftroright">'."\n"; |
||
| 4281 | |||
| 4282 | $formconfirm .= '<input type="hidden" name="action" value="'.$action.'">'."\n"; |
||
| 4283 | $formconfirm .= '<input type="hidden" name="token" value="'.newToken().'">'."\n"; |
||
| 4284 | |||
| 4285 | $formconfirm .= '<table class="valid centpercent">'."\n"; |
||
| 4286 | |||
| 4287 | // Line title |
||
| 4288 | $formconfirm .= '<tr class="validtitre"><td class="validtitre" colspan="3">'.img_picto('', 'recent').' '.$title.'</td></tr>'."\n"; |
||
| 4289 | |||
| 4290 | // Line text |
||
| 4291 | if (is_array($formquestion) && !empty($formquestion['text'])) { |
||
| 4292 | $formconfirm .= '<tr class="valid"><td class="valid" colspan="3">'.$formquestion['text'].'</td></tr>'."\n"; |
||
| 4293 | } |
||
| 4294 | |||
| 4295 | // Line form fields |
||
| 4296 | if ($more) |
||
| 4297 | { |
||
| 4298 | $formconfirm .= '<tr class="valid"><td class="valid" colspan="3">'."\n"; |
||
| 4299 | $formconfirm .= $more; |
||
| 4300 | $formconfirm .= '</td></tr>'."\n"; |
||
| 4301 | } |
||
| 4302 | |||
| 4303 | // Line with question |
||
| 4304 | $formconfirm .= '<tr class="valid">'; |
||
| 4305 | $formconfirm .= '<td class="valid">'.$question.'</td>'; |
||
| 4306 | $formconfirm .= '<td class="valid">'; |
||
| 4307 | $formconfirm .= $this->selectyesno("confirm", $newselectedchoice); |
||
| 4308 | $formconfirm .= '</td>'; |
||
| 4309 | $formconfirm .= '<td class="valid center"><input class="button valignmiddle" type="submit" value="'.$langs->trans("Validate").'"></td>'; |
||
| 4310 | $formconfirm .= '</tr>'."\n"; |
||
| 4311 | |||
| 4312 | $formconfirm .= '</table>'."\n"; |
||
| 4313 | |||
| 4314 | if (empty($disableformtag)) $formconfirm .= "</form>\n"; |
||
| 4315 | $formconfirm .= '<br>'; |
||
| 4316 | |||
| 4317 | $formconfirm .= "<!-- end formconfirm -->\n"; |
||
| 4318 | } |
||
| 4319 | |||
| 4320 | return $formconfirm; |
||
| 4321 | } |
||
| 4322 | |||
| 4323 | |||
| 4324 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps |
||
| 4325 | /** |
||
| 4326 | * Show a form to select a project |
||
| 4327 | * |
||
| 4328 | * @param int $page Page |
||
| 4329 | * @param int $socid Id third party (-1=all, 0=only projects not linked to a third party, id=projects not linked or linked to third party id) |
||
| 4330 | * @param int $selected Id pre-selected project |
||
| 4331 | * @param string $htmlname Name of select field |
||
| 4332 | * @param int $discard_closed Discard closed projects (0=Keep,1=hide completely except $selected,2=Disable) |
||
| 4333 | * @param int $maxlength Max length |
||
| 4334 | * @param int $forcefocus Force focus on field (works with javascript only) |
||
| 4335 | * @param int $nooutput No print is done. String is returned. |
||
| 4336 | * @return string Return html content |
||
| 4337 | */ |
||
| 4338 | public function form_project($page, $socid, $selected = '', $htmlname = 'projectid', $discard_closed = 0, $maxlength = 20, $forcefocus = 0, $nooutput = 0) |
||
| 4378 | } |
||
| 4379 | |||
| 4380 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps |
||
| 4381 | /** |
||
| 4382 | * Show a form to select payment conditions |
||
| 4383 | * |
||
| 4384 | * @param int $page Page |
||
| 4385 | * @param string $selected Id condition pre-selectionne |
||
| 4386 | * @param string $htmlname Name of select html field |
||
| 4387 | * @param int $addempty Add empty entry |
||
| 4388 | * @return void |
||
| 4389 | */ |
||
| 4390 | public function form_conditions_reglement($page, $selected = '', $htmlname = 'cond_reglement_id', $addempty = 0) |
||
| 4391 | { |
||
| 4392 | // phpcs:enable |
||
| 4393 | global $langs; |
||
| 4394 | if ($htmlname != "none") |
||
| 4395 | { |
||
| 4396 | print '<form method="post" action="'.$page.'">'; |
||
| 4397 | print '<input type="hidden" name="action" value="setconditions">'; |
||
| 4398 | print '<input type="hidden" name="token" value="'.newToken().'">'; |
||
| 4399 | $this->select_conditions_paiements($selected, $htmlname, -1, $addempty); |
||
| 4400 | print '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">'; |
||
| 4401 | print '</form>'; |
||
| 4402 | } else { |
||
| 4403 | if ($selected) |
||
| 4404 | { |
||
| 4405 | $this->load_cache_conditions_paiements(); |
||
| 4406 | print $this->cache_conditions_paiements[$selected]['label']; |
||
| 4407 | } else { |
||
| 4408 | print " "; |
||
| 4409 | } |
||
| 4410 | } |
||
| 4411 | } |
||
| 4412 | |||
| 4413 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps |
||
| 4414 | /** |
||
| 4415 | * Show a form to select a delivery delay |
||
| 4416 | * |
||
| 4417 | * @param int $page Page |
||
| 4418 | * @param string $selected Id condition pre-selectionne |
||
| 4419 | * @param string $htmlname Name of select html field |
||
| 4420 | * @param int $addempty Ajoute entree vide |
||
| 4421 | * @return void |
||
| 4422 | */ |
||
| 4423 | public function form_availability($page, $selected = '', $htmlname = 'availability', $addempty = 0) |
||
| 4424 | { |
||
| 4425 | // phpcs:enable |
||
| 4426 | global $langs; |
||
| 4427 | if ($htmlname != "none") |
||
| 4428 | { |
||
| 4429 | print '<form method="post" action="'.$page.'">'; |
||
| 4430 | print '<input type="hidden" name="action" value="setavailability">'; |
||
| 4431 | print '<input type="hidden" name="token" value="'.newToken().'">'; |
||
| 4432 | $this->selectAvailabilityDelay($selected, $htmlname, -1, $addempty); |
||
| 4433 | print '<input type="submit" class="button" value="'.$langs->trans("Modify").'">'; |
||
| 4434 | print '</form>'; |
||
| 4435 | } else { |
||
| 4436 | if ($selected) |
||
| 4437 | { |
||
| 4438 | $this->load_cache_availability(); |
||
| 4439 | print $this->cache_availability[$selected]['label']; |
||
| 4440 | } else { |
||
| 4441 | print " "; |
||
| 4442 | } |
||
| 4443 | } |
||
| 4444 | } |
||
| 4445 | |||
| 4446 | /** |
||
| 4447 | * Output HTML form to select list of input reason (events that triggered an object creation, like after sending an emailing, making an advert, ...) |
||
| 4448 | * List found into table c_input_reason loaded by loadCacheInputReason |
||
| 4449 | * |
||
| 4450 | * @param string $page Page |
||
| 4451 | * @param string $selected Id condition pre-selectionne |
||
| 4452 | * @param string $htmlname Name of select html field |
||
| 4453 | * @param int $addempty Add empty entry |
||
| 4454 | * @return void |
||
| 4455 | */ |
||
| 4456 | public function formInputReason($page, $selected = '', $htmlname = 'demandreason', $addempty = 0) |
||
| 4457 | { |
||
| 4458 | global $langs; |
||
| 4459 | if ($htmlname != "none") |
||
| 4460 | { |
||
| 4461 | print '<form method="post" action="'.$page.'">'; |
||
| 4462 | print '<input type="hidden" name="action" value="setdemandreason">'; |
||
| 4463 | print '<input type="hidden" name="token" value="'.newToken().'">'; |
||
| 4464 | $this->selectInputReason($selected, $htmlname, -1, $addempty); |
||
| 4465 | print '<input type="submit" class="button" value="'.$langs->trans("Modify").'">'; |
||
| 4466 | print '</form>'; |
||
| 4467 | } else { |
||
| 4468 | if ($selected) |
||
| 4469 | { |
||
| 4470 | $this->loadCacheInputReason(); |
||
| 4471 | foreach ($this->cache_demand_reason as $key => $val) |
||
| 4472 | { |
||
| 4473 | if ($val['id'] == $selected) |
||
| 4474 | { |
||
| 4475 | print $val['label']; |
||
| 4476 | break; |
||
| 4477 | } |
||
| 4478 | } |
||
| 4479 | } else { |
||
| 4480 | print " "; |
||
| 4481 | } |
||
| 4482 | } |
||
| 4483 | } |
||
| 4484 | |||
| 4485 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps |
||
| 4486 | /** |
||
| 4487 | * Show a form + html select a date |
||
| 4488 | * |
||
| 4489 | * @param string $page Page |
||
| 4490 | * @param string $selected Date preselected |
||
| 4491 | * @param string $htmlname Html name of date input fields or 'none' |
||
| 4492 | * @param int $displayhour Display hour selector |
||
| 4493 | * @param int $displaymin Display minutes selector |
||
| 4494 | * @param int $nooutput 1=No print output, return string |
||
| 4495 | * @return string |
||
| 4496 | * @see selectDate() |
||
| 4497 | */ |
||
| 4498 | public function form_date($page, $selected, $htmlname, $displayhour = 0, $displaymin = 0, $nooutput = 0) |
||
| 4499 | { |
||
| 4500 | // phpcs:enable |
||
| 4501 | global $langs; |
||
| 4502 | |||
| 4503 | $ret = ''; |
||
| 4504 | |||
| 4505 | if ($htmlname != "none") |
||
| 4506 | { |
||
| 4507 | $ret .= '<form method="post" action="'.$page.'" name="form'.$htmlname.'">'; |
||
| 4508 | $ret .= '<input type="hidden" name="action" value="set'.$htmlname.'">'; |
||
| 4509 | $ret .= '<input type="hidden" name="token" value="'.newToken().'">'; |
||
| 4510 | $ret .= '<table class="nobordernopadding" cellpadding="0" cellspacing="0">'; |
||
| 4511 | $ret .= '<tr><td>'; |
||
| 4512 | $ret .= $this->selectDate($selected, $htmlname, $displayhour, $displaymin, 1, 'form'.$htmlname, 1, 0); |
||
| 4513 | $ret .= '</td>'; |
||
| 4514 | $ret .= '<td class="left"><input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>'; |
||
| 4515 | $ret .= '</tr></table></form>'; |
||
| 4516 | } else { |
||
| 4517 | if ($displayhour) $ret .= dol_print_date($selected, 'dayhour'); |
||
| 4518 | else $ret .= dol_print_date($selected, 'day'); |
||
| 4519 | } |
||
| 4520 | |||
| 4521 | if (empty($nooutput)) print $ret; |
||
| 4522 | return $ret; |
||
| 4523 | } |
||
| 4524 | |||
| 4525 | |||
| 4526 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps |
||
| 4527 | /** |
||
| 4528 | * Show a select form to choose a user |
||
| 4529 | * |
||
| 4530 | * @param string $page Page |
||
| 4531 | * @param string $selected Id of user preselected |
||
| 4532 | * @param string $htmlname Name of input html field. If 'none', we just output the user link. |
||
| 4533 | * @param array $exclude List of users id to exclude |
||
| 4534 | * @param array $include List of users id to include |
||
| 4535 | * @return void |
||
| 4536 | */ |
||
| 4537 | public function form_users($page, $selected = '', $htmlname = 'userid', $exclude = '', $include = '') |
||
| 4538 | { |
||
| 4539 | // phpcs:enable |
||
| 4540 | global $langs; |
||
| 4541 | |||
| 4542 | if ($htmlname != "none") |
||
| 4543 | { |
||
| 4544 | print '<form method="POST" action="'.$page.'" name="form'.$htmlname.'">'; |
||
| 4545 | print '<input type="hidden" name="action" value="set'.$htmlname.'">'; |
||
| 4546 | print '<input type="hidden" name="token" value="'.newToken().'">'; |
||
| 4547 | print $this->select_dolusers($selected, $htmlname, 1, $exclude, 0, $include); |
||
| 4548 | print '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">'; |
||
| 4549 | print '</form>'; |
||
| 4550 | } else { |
||
| 4551 | if ($selected) |
||
| 4552 | { |
||
| 4553 | require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php'; |
||
| 4554 | $theuser = new User($this->db); |
||
| 4555 | $theuser->fetch($selected); |
||
| 4556 | print $theuser->getNomUrl(1); |
||
| 4557 | } else { |
||
| 4558 | print " "; |
||
| 4559 | } |
||
| 4560 | } |
||
| 4561 | } |
||
| 4562 | |||
| 4563 | |||
| 4564 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps |
||
| 4565 | /** |
||
| 4566 | * Show form with payment mode |
||
| 4567 | * |
||
| 4568 | * @param string $page Page |
||
| 4569 | * @param int $selected Id mode pre-selectionne |
||
| 4570 | * @param string $htmlname Name of select html field |
||
| 4571 | * @param string $filtertype To filter on field type in llx_c_paiement (array('code'=>xx,'label'=>zz)) |
||
| 4572 | * @param int $active Active or not, -1 = all |
||
| 4573 | * @param int $addempty 1=Add empty entry |
||
| 4574 | * @return void |
||
| 4575 | */ |
||
| 4576 | public function form_modes_reglement($page, $selected = '', $htmlname = 'mode_reglement_id', $filtertype = '', $active = 1, $addempty = 0) |
||
| 4577 | { |
||
| 4578 | // phpcs:enable |
||
| 4579 | global $langs; |
||
| 4580 | if ($htmlname != "none") |
||
| 4581 | { |
||
| 4582 | print '<form method="POST" action="'.$page.'">'; |
||
| 4583 | print '<input type="hidden" name="action" value="setmode">'; |
||
| 4584 | print '<input type="hidden" name="token" value="'.newToken().'">'; |
||
| 4585 | $this->select_types_paiements($selected, $htmlname, $filtertype, 0, $addempty, 0, 0, $active); |
||
| 4586 | print '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">'; |
||
| 4587 | print '</form>'; |
||
| 4588 | } else { |
||
| 4589 | if ($selected) |
||
| 4590 | { |
||
| 4591 | $this->load_cache_types_paiements(); |
||
| 4592 | print $this->cache_types_paiements[$selected]['label']; |
||
| 4593 | } else { |
||
| 4594 | print " "; |
||
| 4595 | } |
||
| 4596 | } |
||
| 4597 | } |
||
| 4598 | |||
| 4599 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps |
||
| 4600 | /** |
||
| 4601 | * Show form with multicurrency code |
||
| 4602 | * |
||
| 4603 | * @param string $page Page |
||
| 4604 | * @param string $selected code pre-selectionne |
||
| 4605 | * @param string $htmlname Name of select html field |
||
| 4606 | * @return void |
||
| 4607 | */ |
||
| 4608 | public function form_multicurrency_code($page, $selected = '', $htmlname = 'multicurrency_code') |
||
| 4609 | { |
||
| 4610 | // phpcs:enable |
||
| 4611 | global $langs; |
||
| 4612 | if ($htmlname != "none") |
||
| 4613 | { |
||
| 4614 | print '<form method="POST" action="'.$page.'">'; |
||
| 4615 | print '<input type="hidden" name="action" value="setmulticurrencycode">'; |
||
| 4616 | print '<input type="hidden" name="token" value="'.newToken().'">'; |
||
| 4617 | print $this->selectMultiCurrency($selected, $htmlname, 0); |
||
| 4618 | print '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">'; |
||
| 4619 | print '</form>'; |
||
| 4620 | } else { |
||
| 4621 | dol_include_once('/core/lib/company.lib.php'); |
||
| 4622 | print !empty($selected) ? currency_name($selected, 1) : ' '; |
||
| 4623 | } |
||
| 4624 | } |
||
| 4625 | |||
| 4626 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps |
||
| 4627 | /** |
||
| 4628 | * Show form with multicurrency rate |
||
| 4629 | * |
||
| 4630 | * @param string $page Page |
||
| 4631 | * @param double $rate Current rate |
||
| 4632 | * @param string $htmlname Name of select html field |
||
| 4633 | * @param string $currency Currency code to explain the rate |
||
| 4634 | * @return void |
||
| 4635 | */ |
||
| 4636 | public function form_multicurrency_rate($page, $rate = '', $htmlname = 'multicurrency_tx', $currency = '') |
||
| 4637 | { |
||
| 4638 | // phpcs:enable |
||
| 4639 | global $langs, $mysoc, $conf; |
||
| 4640 | |||
| 4641 | if ($htmlname != "none") |
||
| 4642 | { |
||
| 4643 | print '<form method="POST" action="'.$page.'">'; |
||
| 4644 | print '<input type="hidden" name="action" value="setmulticurrencyrate">'; |
||
| 4645 | print '<input type="hidden" name="token" value="'.newToken().'">'; |
||
| 4646 | print '<input type="text" class="maxwidth100" name="'.$htmlname.'" value="'.(!empty($rate) ? price(price2num($rate, 'CR')) : 1).'" /> '; |
||
| 4647 | print '<select name="calculation_mode">'; |
||
| 4648 | print '<option value="1">'.$currency.' > '.$conf->currency.'</option>'; |
||
| 4649 | print '<option value="2">'.$conf->currency.' > '.$currency.'</option>'; |
||
| 4650 | print '</select> '; |
||
| 4651 | print '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">'; |
||
| 4652 | print '</form>'; |
||
| 4653 | } else { |
||
| 4654 | if (!empty($rate)) |
||
| 4655 | { |
||
| 4656 | print price($rate, 1, $langs, 1, 0); |
||
| 4657 | if ($currency && $rate != 1) print ' ('.price($rate, 1, $langs, 1, 0).' '.$currency.' = 1 '.$conf->currency.')'; |
||
| 4658 | } else { |
||
| 4659 | print 1; |
||
| 4660 | } |
||
| 4661 | } |
||
| 4662 | } |
||
| 4663 | |||
| 4664 | |||
| 4665 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps |
||
| 4666 | /** |
||
| 4667 | * Show a select box with available absolute discounts |
||
| 4668 | * |
||
| 4669 | * @param string $page Page URL where form is shown |
||
| 4670 | * @param int $selected Value pre-selected |
||
| 4671 | * @param string $htmlname Name of SELECT component. If 'none', not changeable. Example 'remise_id'. |
||
| 4672 | * @param int $socid Third party id |
||
| 4673 | * @param float $amount Total amount available |
||
| 4674 | * @param string $filter SQL filter on discounts |
||
| 4675 | * @param int $maxvalue Max value for lines that can be selected |
||
| 4676 | * @param string $more More string to add |
||
| 4677 | * @param int $hidelist 1=Hide list |
||
| 4678 | * @param int $discount_type 0 => customer discount, 1 => supplier discount |
||
| 4679 | * @return void |
||
| 4680 | */ |
||
| 4681 | public function form_remise_dispo($page, $selected, $htmlname, $socid, $amount, $filter = '', $maxvalue = 0, $more = '', $hidelist = 0, $discount_type = 0) |
||
| 4682 | { |
||
| 4683 | // phpcs:enable |
||
| 4684 | global $conf, $langs; |
||
| 4685 | if ($htmlname != "none") |
||
| 4686 | { |
||
| 4687 | print '<form method="post" action="'.$page.'">'; |
||
| 4688 | print '<input type="hidden" name="action" value="setabsolutediscount">'; |
||
| 4689 | print '<input type="hidden" name="token" value="'.newToken().'">'; |
||
| 4690 | print '<div class="inline-block">'; |
||
| 4691 | if (!empty($discount_type)) { |
||
| 4692 | if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) |
||
| 4693 | { |
||
| 4694 | if (!$filter || $filter == "fk_invoice_supplier_source IS NULL") $translationKey = 'HasAbsoluteDiscountFromSupplier'; // If we want deposit to be substracted to payments only and not to total of final invoice |
||
| 4695 | else $translationKey = 'HasCreditNoteFromSupplier'; |
||
| 4696 | } else { |
||
| 4697 | if (!$filter || $filter == "fk_invoice_supplier_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS PAID)%')") $translationKey = 'HasAbsoluteDiscountFromSupplier'; |
||
| 4698 | else $translationKey = 'HasCreditNoteFromSupplier'; |
||
| 4699 | } |
||
| 4700 | } else { |
||
| 4701 | if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) |
||
| 4702 | { |
||
| 4703 | if (!$filter || $filter == "fk_facture_source IS NULL") $translationKey = 'CompanyHasAbsoluteDiscount'; // If we want deposit to be substracted to payments only and not to total of final invoice |
||
| 4704 | else $translationKey = 'CompanyHasCreditNote'; |
||
| 4705 | } else { |
||
| 4706 | if (!$filter || $filter == "fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')") $translationKey = 'CompanyHasAbsoluteDiscount'; |
||
| 4707 | else $translationKey = 'CompanyHasCreditNote'; |
||
| 4708 | } |
||
| 4709 | } |
||
| 4710 | print $langs->trans($translationKey, price($amount, 0, $langs, 0, 0, -1, $conf->currency)); |
||
| 4711 | if (empty($hidelist)) print ': '; |
||
| 4712 | print '</div>'; |
||
| 4713 | if (empty($hidelist)) |
||
| 4714 | { |
||
| 4715 | print '<div class="inline-block" style="padding-right: 10px">'; |
||
| 4716 | $newfilter = 'discount_type='.intval($discount_type); |
||
| 4717 | if (!empty($discount_type)) { |
||
| 4718 | $newfilter .= ' AND fk_invoice_supplier IS NULL AND fk_invoice_supplier_line IS NULL'; // Supplier discounts available |
||
| 4719 | } else { |
||
| 4720 | $newfilter .= ' AND fk_facture IS NULL AND fk_facture_line IS NULL'; // Customer discounts available |
||
| 4721 | } |
||
| 4722 | if ($filter) $newfilter .= ' AND ('.$filter.')'; |
||
| 4723 | $nbqualifiedlines = $this->select_remises($selected, $htmlname, $newfilter, $socid, $maxvalue); |
||
| 4724 | if ($nbqualifiedlines > 0) |
||
| 4725 | { |
||
| 4726 | print ' <input type="submit" class="button" value="'.dol_escape_htmltag($langs->trans("UseLine")).'"'; |
||
| 4727 | if (!empty($discount_type) && $filter && $filter != "fk_invoice_supplier_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS PAID)%')") |
||
| 4728 | print ' title="'.$langs->trans("UseCreditNoteInInvoicePayment").'"'; |
||
| 4729 | if (empty($discount_type) && $filter && $filter != "fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')") |
||
| 4730 | print ' title="'.$langs->trans("UseCreditNoteInInvoicePayment").'"'; |
||
| 4731 | |||
| 4732 | print '>'; |
||
| 4733 | } |
||
| 4734 | print '</div>'; |
||
| 4735 | } |
||
| 4736 | if ($more) |
||
| 4737 | { |
||
| 4738 | print '<div class="inline-block">'; |
||
| 4739 | print $more; |
||
| 4740 | print '</div>'; |
||
| 4741 | } |
||
| 4742 | print '</form>'; |
||
| 4743 | } else { |
||
| 4744 | if ($selected) |
||
| 4745 | { |
||
| 4746 | print $selected; |
||
| 4747 | } else { |
||
| 4748 | print "0"; |
||
| 4749 | } |
||
| 4750 | } |
||
| 4751 | } |
||
| 4752 | |||
| 4753 | |||
| 4754 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps |
||
| 4755 | /** |
||
| 4756 | * Show forms to select a contact |
||
| 4757 | * |
||
| 4758 | * @param string $page Page |
||
| 4759 | * @param Societe $societe Filter on third party |
||
| 4760 | * @param int $selected Id contact pre-selectionne |
||
| 4761 | * @param string $htmlname Name of HTML select. If 'none', we just show contact link. |
||
| 4762 | * @return void |
||
| 4763 | */ |
||
| 4764 | public function form_contacts($page, $societe, $selected = '', $htmlname = 'contactid') |
||
| 4794 | } |
||
| 4795 | } |
||
| 4796 | } |
||
| 4797 | |||
| 4798 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps |
||
| 4799 | /** |
||
| 4800 | * Output html select to select thirdparty |
||
| 4801 | * |
||
| 4802 | * @param string $page Page |
||
| 4803 | * @param string $selected Id preselected |
||
| 4804 | * @param string $htmlname Name of HTML select |
||
| 4805 | * @param string $filter optional filters criteras |
||
| 4806 | * @param int $showempty Add an empty field |
||
| 4807 | * @param int $showtype Show third party type in combolist (customer, prospect or supplier) |
||
| 4808 | * @param int $forcecombo Force to use combo box |
||
| 4809 | * @param array $events Event options. Example: array(array('method'=>'getContacts', 'url'=>dol_buildpath('/core/ajax/contacts.php',1), 'htmlname'=>'contactid', 'params'=>array('add-customer-contact'=>'disabled'))) |
||
| 4810 | * @param int $nooutput No print output. Return it only. |
||
| 4811 | * @return void|string |
||
| 4812 | */ |
||
| 4813 | public function form_thirdparty($page, $selected = '', $htmlname = 'socid', $filter = '', $showempty = 0, $showtype = 0, $forcecombo = 0, $events = array(), $nooutput = 0) |
||
| 4814 | { |
||
| 4815 | // phpcs:enable |
||
| 4816 | global $langs; |
||
| 4817 | |||
| 4818 | $out = ''; |
||
| 4819 | if ($htmlname != "none") |
||
| 4820 | { |
||
| 4821 | $out .= '<form method="post" action="'.$page.'">'; |
||
| 4822 | $out .= '<input type="hidden" name="action" value="set_thirdparty">'; |
||
| 4823 | $out .= '<input type="hidden" name="token" value="'.newToken().'">'; |
||
| 4824 | $out .= $this->select_company($selected, $htmlname, $filter, $showempty, $showtype, $forcecombo, $events); |
||
| 4825 | $out .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">'; |
||
| 4826 | $out .= '</form>'; |
||
| 4827 | } else { |
||
| 4828 | if ($selected) |
||
| 4829 | { |
||
| 4830 | require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php'; |
||
| 4831 | $soc = new Societe($this->db); |
||
| 4832 | $soc->fetch($selected); |
||
| 4833 | $out .= $soc->getNomUrl($langs); |
||
| 4834 | } else { |
||
| 4835 | $out .= " "; |
||
| 4836 | } |
||
| 4837 | } |
||
| 4838 | |||
| 4839 | if ($nooutput) return $out; |
||
| 4840 | else print $out; |
||
| 4841 | } |
||
| 4842 | |||
| 4843 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps |
||
| 4844 | /** |
||
| 4845 | * Retourne la liste des devises, dans la langue de l'utilisateur |
||
| 4846 | * |
||
| 4847 | * @param string $selected preselected currency code |
||
| 4848 | * @param string $htmlname name of HTML select list |
||
| 4849 | * @deprecated |
||
| 4850 | * @return void |
||
| 4851 | */ |
||
| 4852 | public function select_currency($selected = '', $htmlname = 'currency_id') |
||
| 4853 | { |
||
| 4854 | // phpcs:enable |
||
| 4855 | print $this->selectCurrency($selected, $htmlname); |
||
| 4856 | } |
||
| 4857 | |||
| 4858 | /** |
||
| 4859 | * Retourne la liste des devises, dans la langue de l'utilisateur |
||
| 4860 | * |
||
| 4861 | * @param string $selected preselected currency code |
||
| 4862 | * @param string $htmlname name of HTML select list |
||
| 4863 | * @param string $mode 0 = Add currency symbol into label, 1 = Add 3 letter iso code |
||
| 4864 | * @return string |
||
| 4865 | */ |
||
| 4866 | public function selectCurrency($selected = '', $htmlname = 'currency_id', $mode = 0) |
||
| 4867 | { |
||
| 4868 | global $conf, $langs, $user; |
||
| 4869 | |||
| 4870 | $langs->loadCacheCurrencies(''); |
||
| 4871 | |||
| 4872 | $out = ''; |
||
| 4873 | |||
| 4874 | if ($selected == 'euro' || $selected == 'euros') $selected = 'EUR'; // Pour compatibilite |
||
| 4875 | |||
| 4876 | $out .= '<select class="flat maxwidth200onsmartphone minwidth300" name="'.$htmlname.'" id="'.$htmlname.'">'; |
||
| 4877 | foreach ($langs->cache_currencies as $code_iso => $currency) |
||
| 4878 | { |
||
| 4879 | if ($selected && $selected == $code_iso) |
||
| 4880 | { |
||
| 4881 | $out .= '<option value="'.$code_iso.'" selected>'; |
||
| 4882 | } else { |
||
| 4883 | $out .= '<option value="'.$code_iso.'">'; |
||
| 4884 | } |
||
| 4885 | $out .= $currency['label']; |
||
| 4886 | if ($mode == 1) |
||
| 4887 | { |
||
| 4888 | $out .= ' ('.$code_iso.')'; |
||
| 4889 | } else { |
||
| 4890 | $out .= ' ('.$langs->getCurrencySymbol($code_iso).')'; |
||
| 4891 | } |
||
| 4892 | $out .= '</option>'; |
||
| 4893 | } |
||
| 4894 | $out .= '</select>'; |
||
| 4895 | if ($user->admin) $out .= info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1); |
||
| 4896 | |||
| 4897 | // Make select dynamic |
||
| 4898 | include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php'; |
||
| 4899 | $out .= ajax_combobox($htmlname); |
||
| 4900 | |||
| 4901 | return $out; |
||
| 4902 | } |
||
| 4903 | |||
| 4904 | /** |
||
| 4905 | * Return array of currencies in user language |
||
| 4906 | * |
||
| 4907 | * @param string $selected preselected currency code |
||
| 4908 | * @param string $htmlname name of HTML select list |
||
| 4909 | * @param integer $useempty 1=Add empty line |
||
| 4910 | * @return string |
||
| 4911 | */ |
||
| 4912 | public function selectMultiCurrency($selected = '', $htmlname = 'multicurrency_code', $useempty = 0) |
||
| 4913 | { |
||
| 4914 | global $db, $conf, $langs, $user; |
||
| 4915 | |||
| 4916 | $langs->loadCacheCurrencies(''); // Load ->cache_currencies |
||
| 4917 | |||
| 4918 | $TCurrency = array(); |
||
| 4919 | |||
| 4920 | $sql = 'SELECT code FROM '.MAIN_DB_PREFIX.'multicurrency'; |
||
| 4921 | $sql .= " WHERE entity IN ('".getEntity('mutlicurrency')."')"; |
||
| 4922 | $resql = $db->query($sql); |
||
| 4923 | if ($resql) |
||
| 4924 | { |
||
| 4925 | while ($obj = $db->fetch_object($resql)) $TCurrency[$obj->code] = $obj->code; |
||
| 4926 | } |
||
| 4927 | |||
| 4928 | $out = ''; |
||
| 4929 | $out .= '<select class="flat" name="'.$htmlname.'" id="'.$htmlname.'">'; |
||
| 4930 | if ($useempty) $out .= '<option value=""> </option>'; |
||
| 4931 | // If company current currency not in table, we add it into list. Should always be available. |
||
| 4932 | if (!in_array($conf->currency, $TCurrency)) |
||
| 4933 | { |
||
| 4934 | $TCurrency[$conf->currency] = $conf->currency; |
||
| 4935 | } |
||
| 4936 | if (count($TCurrency) > 0) |
||
| 4937 | { |
||
| 4938 | foreach ($langs->cache_currencies as $code_iso => $currency) |
||
| 4939 | { |
||
| 4940 | if (isset($TCurrency[$code_iso])) |
||
| 4941 | { |
||
| 4942 | if (!empty($selected) && $selected == $code_iso) $out .= '<option value="'.$code_iso.'" selected="selected">'; |
||
| 4943 | else $out .= '<option value="'.$code_iso.'">'; |
||
| 4944 | |||
| 4945 | $out .= $currency['label']; |
||
| 4946 | $out .= ' ('.$langs->getCurrencySymbol($code_iso).')'; |
||
| 4947 | $out .= '</option>'; |
||
| 4948 | } |
||
| 4949 | } |
||
| 4950 | } |
||
| 4951 | |||
| 4952 | $out .= '</select>'; |
||
| 4953 | // Make select dynamic |
||
| 4954 | include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php'; |
||
| 4955 | $out .= ajax_combobox($htmlname); |
||
| 4956 | |||
| 4957 | return $out; |
||
| 4958 | } |
||
| 4959 | |||
| 4960 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps |
||
| 4961 | /** |
||
| 4962 | * Load into the cache vat rates of a country |
||
| 4963 | * |
||
| 4964 | * @param string $country_code Country code with quotes ("'CA'", or "'CA,IN,...'") |
||
| 4965 | * @return int Nb of loaded lines, 0 if already loaded, <0 if KO |
||
| 4966 | */ |
||
| 4967 | public function load_cache_vatrates($country_code) |
||
| 4968 | { |
||
| 4969 | // phpcs:enable |
||
| 4970 | global $langs; |
||
| 4971 | |||
| 4972 | $num = count($this->cache_vatrates); |
||
| 4973 | if ($num > 0) return $num; // Cache already loaded |
||
| 4974 | |||
| 4975 | dol_syslog(__METHOD__, LOG_DEBUG); |
||
| 4976 | |||
| 4977 | $sql = "SELECT DISTINCT t.rowid, t.code, t.taux, t.localtax1, t.localtax1_type, t.localtax2, t.localtax2_type, t.recuperableonly"; |
||
| 4978 | $sql .= " FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_country as c"; |
||
| 4979 | $sql .= " WHERE t.fk_pays = c.rowid"; |
||
| 4980 | $sql .= " AND t.active > 0"; |
||
| 4981 | $sql .= " AND c.code IN (".$country_code.")"; |
||
| 4982 | $sql .= " ORDER BY t.code ASC, t.taux ASC, t.recuperableonly ASC"; |
||
| 4983 | |||
| 4984 | $resql = $this->db->query($sql); |
||
| 4985 | if ($resql) |
||
| 4986 | { |
||
| 4987 | $num = $this->db->num_rows($resql); |
||
| 4988 | if ($num) |
||
| 4989 | { |
||
| 4990 | for ($i = 0; $i < $num; $i++) |
||
| 4991 | { |
||
| 4992 | $obj = $this->db->fetch_object($resql); |
||
| 4993 | $this->cache_vatrates[$i]['rowid'] = $obj->rowid; |
||
| 4994 | $this->cache_vatrates[$i]['code'] = $obj->code; |
||
| 4995 | $this->cache_vatrates[$i]['txtva'] = $obj->taux; |
||
| 4996 | $this->cache_vatrates[$i]['nprtva'] = $obj->recuperableonly; |
||
| 4997 | $this->cache_vatrates[$i]['localtax1'] = $obj->localtax1; |
||
| 4998 | $this->cache_vatrates[$i]['localtax1_type'] = $obj->localtax1_type; |
||
| 4999 | $this->cache_vatrates[$i]['localtax2'] = $obj->localtax2; |
||
| 5000 | $this->cache_vatrates[$i]['localtax2_type'] = $obj->localtax1_type; |
||
| 5001 | |||
| 5002 | $this->cache_vatrates[$i]['label'] = $obj->taux.'%'.($obj->code ? ' ('.$obj->code.')' : ''); // Label must contains only 0-9 , . % or * |
||
| 5003 | $this->cache_vatrates[$i]['labelallrates'] = $obj->taux.'/'.($obj->localtax1 ? $obj->localtax1 : '0').'/'.($obj->localtax2 ? $obj->localtax2 : '0').($obj->code ? ' ('.$obj->code.')' : ''); // Must never be used as key, only label |
||
| 5004 | $positiverates = ''; |
||
| 5005 | if ($obj->taux) $positiverates .= ($positiverates ? '/' : '').$obj->taux; |
||
| 5006 | if ($obj->localtax1) $positiverates .= ($positiverates ? '/' : '').$obj->localtax1; |
||
| 5007 | if ($obj->localtax2) $positiverates .= ($positiverates ? '/' : '').$obj->localtax2; |
||
| 5008 | if (empty($positiverates)) $positiverates = '0'; |
||
| 5009 | $this->cache_vatrates[$i]['labelpositiverates'] = $positiverates.($obj->code ? ' ('.$obj->code.')' : ''); // Must never be used as key, only label |
||
| 5010 | } |
||
| 5011 | |||
| 5012 | return $num; |
||
| 5013 | } else { |
||
| 5014 | $this->error = '<font class="error">'.$langs->trans("ErrorNoVATRateDefinedForSellerCountry", $country_code).'</font>'; |
||
| 5015 | return -1; |
||
| 5016 | } |
||
| 5017 | } else { |
||
| 5018 | $this->error = '<font class="error">'.$this->db->error().'</font>'; |
||
| 5019 | return -2; |
||
| 5020 | } |
||
| 5021 | } |
||
| 5022 | |||
| 5023 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps |
||
| 5024 | /** |
||
| 5025 | * Output an HTML select vat rate. |
||
| 5026 | * The name of this function should be selectVat. We keep bad name for compatibility purpose. |
||
| 5027 | * |
||
| 5028 | * @param string $htmlname Name of HTML select field |
||
| 5029 | * @param float|string $selectedrate Force preselected vat rate. Can be '8.5' or '8.5 (NOO)' for example. Use '' for no forcing. |
||
| 5030 | * @param Societe $societe_vendeuse Thirdparty seller |
||
| 5031 | * @param Societe $societe_acheteuse Thirdparty buyer |
||
| 5032 | * @param int $idprod Id product. O if unknown of NA. |
||
| 5033 | * @param int $info_bits Miscellaneous information on line (1 for NPR) |
||
| 5034 | * @param int|string $type ''=Unknown, 0=Product, 1=Service (Used if idprod not defined) |
||
| 5035 | * Si vendeur non assujeti a TVA, TVA par defaut=0. Fin de regle. |
||
| 5036 | * Si le (pays vendeur = pays acheteur) alors la TVA par defaut=TVA du produit vendu. Fin de regle. |
||
| 5037 | * Si (vendeur et acheteur dans Communaute europeenne) et bien vendu = moyen de transports neuf (auto, bateau, avion), TVA par defaut=0 (La TVA doit etre paye par l'acheteur au centre d'impots de son pays et non au vendeur). Fin de regle. |
||
| 5038 | * Si vendeur et acheteur dans Communauté européenne et acheteur= particulier alors TVA par défaut=TVA du produit vendu. Fin de règle. |
||
| 5039 | * Si vendeur et acheteur dans Communauté européenne et acheteur= entreprise alors TVA par défaut=0. Fin de règle. |
||
| 5040 | * Sinon la TVA proposee par defaut=0. Fin de regle. |
||
| 5041 | * @param bool $options_only Return HTML options lines only (for ajax treatment) |
||
| 5042 | * @param int $mode 0=Use vat rate as key in combo list, 1=Add VAT code after vat rate into key, -1=Use id of vat line as key |
||
| 5043 | * @return string |
||
| 5044 | */ |
||
| 5045 | public function load_tva($htmlname = 'tauxtva', $selectedrate = '', $societe_vendeuse = '', $societe_acheteuse = '', $idprod = 0, $info_bits = 0, $type = '', $options_only = false, $mode = 0) |
||
| 5046 | { |
||
| 5047 | // phpcs:enable |
||
| 5048 | global $langs, $conf, $mysoc; |
||
| 5049 | |||
| 5050 | $langs->load('errors'); |
||
| 5051 | |||
| 5052 | $return = ''; |
||
| 5053 | |||
| 5054 | // Define defaultnpr, defaultttx and defaultcode |
||
| 5055 | $defaultnpr = ($info_bits & 0x01); |
||
| 5056 | $defaultnpr = (preg_match('/\*/', $selectedrate) ? 1 : $defaultnpr); |
||
| 5057 | $defaulttx = str_replace('*', '', $selectedrate); |
||
| 5058 | $defaultcode = ''; |
||
| 5059 | if (preg_match('/\((.*)\)/', $defaulttx, $reg)) |
||
| 5060 | { |
||
| 5061 | $defaultcode = $reg[1]; |
||
| 5062 | $defaulttx = preg_replace('/\s*\(.*\)/', '', $defaulttx); |
||
| 5063 | } |
||
| 5064 | //var_dump($selectedrate.'-'.$defaulttx.'-'.$defaultnpr.'-'.$defaultcode); |
||
| 5065 | |||
| 5066 | // Check parameters |
||
| 5067 | if (is_object($societe_vendeuse) && !$societe_vendeuse->country_code) |
||
| 5068 | { |
||
| 5069 | if ($societe_vendeuse->id == $mysoc->id) |
||
| 5070 | { |
||
| 5071 | $return .= '<font class="error">'.$langs->trans("ErrorYourCountryIsNotDefined").'</font>'; |
||
| 5072 | } else { |
||
| 5073 | $return .= '<font class="error">'.$langs->trans("ErrorSupplierCountryIsNotDefined").'</font>'; |
||
| 5074 | } |
||
| 5075 | return $return; |
||
| 5076 | } |
||
| 5077 | |||
| 5078 | //var_dump($societe_acheteuse); |
||
| 5079 | //print "name=$name, selectedrate=$selectedrate, seller=".$societe_vendeuse->country_code." buyer=".$societe_acheteuse->country_code." buyer is company=".$societe_acheteuse->isACompany()." idprod=$idprod, info_bits=$info_bits type=$type"; |
||
| 5080 | //exit; |
||
| 5081 | |||
| 5082 | // Define list of countries to use to search VAT rates to show |
||
| 5083 | // First we defined code_country to use to find list |
||
| 5084 | if (is_object($societe_vendeuse)) |
||
| 5085 | { |
||
| 5086 | $code_country = "'".$societe_vendeuse->country_code."'"; |
||
| 5087 | } else { |
||
| 5088 | $code_country = "'".$mysoc->country_code."'"; // Pour compatibilite ascendente |
||
| 5089 | } |
||
| 5090 | if (!empty($conf->global->SERVICE_ARE_ECOMMERCE_200238EC)) // If option to have vat for end customer for services is on |
||
| 5091 | { |
||
| 5092 | require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; |
||
| 5093 | if (!isInEEC($societe_vendeuse) && (!is_object($societe_acheteuse) || (isInEEC($societe_acheteuse) && !$societe_acheteuse->isACompany()))) |
||
| 5094 | { |
||
| 5095 | // We also add the buyer |
||
| 5096 | if (is_numeric($type)) |
||
| 5097 | { |
||
| 5098 | if ($type == 1) // We know product is a service |
||
| 5099 | { |
||
| 5100 | $code_country .= ",'".$societe_acheteuse->country_code."'"; |
||
| 5101 | } |
||
| 5102 | } elseif (!$idprod) // We don't know type of product |
||
| 5103 | { |
||
| 5104 | $code_country .= ",'".$societe_acheteuse->country_code."'"; |
||
| 5105 | } else { |
||
| 5106 | $prodstatic = new Product($this->db); |
||
| 5107 | $prodstatic->fetch($idprod); |
||
| 5108 | if ($prodstatic->type == Product::TYPE_SERVICE) // We know product is a service |
||
| 5109 | { |
||
| 5110 | $code_country .= ",'".$societe_acheteuse->country_code."'"; |
||
| 5111 | } |
||
| 5112 | } |
||
| 5113 | } |
||
| 5114 | } |
||
| 5115 | |||
| 5116 | // Now we get list |
||
| 5117 | $num = $this->load_cache_vatrates($code_country); // If no vat defined, return -1 with message into this->error |
||
| 5118 | |||
| 5119 | if ($num > 0) |
||
| 5120 | { |
||
| 5121 | // Definition du taux a pre-selectionner (si defaulttx non force et donc vaut -1 ou '') |
||
| 5122 | if ($defaulttx < 0 || dol_strlen($defaulttx) == 0) |
||
| 5123 | { |
||
| 5124 | $tmpthirdparty = new Societe($this->db); |
||
| 5125 | $defaulttx = get_default_tva($societe_vendeuse, (is_object($societe_acheteuse) ? $societe_acheteuse : $tmpthirdparty), $idprod); |
||
| 5126 | $defaultnpr = get_default_npr($societe_vendeuse, (is_object($societe_acheteuse) ? $societe_acheteuse : $tmpthirdparty), $idprod); |
||
| 5127 | if (preg_match('/\((.*)\)/', $defaulttx, $reg)) { |
||
| 5128 | $defaultcode = $reg[1]; |
||
| 5129 | $defaulttx = preg_replace('/\s*\(.*\)/', '', $defaulttx); |
||
| 5130 | } |
||
| 5131 | if (empty($defaulttx)) $defaultnpr = 0; |
||
| 5132 | } |
||
| 5133 | |||
| 5134 | // Si taux par defaut n'a pu etre determine, on prend dernier de la liste. |
||
| 5135 | // Comme ils sont tries par ordre croissant, dernier = plus eleve = taux courant |
||
| 5136 | if ($defaulttx < 0 || dol_strlen($defaulttx) == 0) |
||
| 5137 | { |
||
| 5138 | if (empty($conf->global->MAIN_VAT_DEFAULT_IF_AUTODETECT_FAILS)) $defaulttx = $this->cache_vatrates[$num - 1]['txtva']; |
||
| 5139 | else $defaulttx = ($conf->global->MAIN_VAT_DEFAULT_IF_AUTODETECT_FAILS == 'none' ? '' : $conf->global->MAIN_VAT_DEFAULT_IF_AUTODETECT_FAILS); |
||
| 5140 | } |
||
| 5141 | |||
| 5142 | // Disabled if seller is not subject to VAT |
||
| 5143 | $disabled = false; $title = ''; |
||
| 5144 | if (is_object($societe_vendeuse) && $societe_vendeuse->id == $mysoc->id && $societe_vendeuse->tva_assuj == "0") |
||
| 5145 | { |
||
| 5146 | // Override/enable VAT for expense report regardless of global setting - needed if expense report used for business expenses instead |
||
| 5147 | // of using supplier invoices (this is a very bad idea !) |
||
| 5148 | if (empty($conf->global->EXPENSEREPORT_OVERRIDE_VAT)) |
||
| 5149 | { |
||
| 5150 | $title = ' title="'.$langs->trans('VATIsNotUsed').'"'; |
||
| 5151 | $disabled = true; |
||
| 5152 | } |
||
| 5153 | } |
||
| 5154 | |||
| 5155 | if (!$options_only) $return .= '<select class="flat minwidth75imp" id="'.$htmlname.'" name="'.$htmlname.'"'.($disabled ? ' disabled' : '').$title.'>'; |
||
| 5156 | |||
| 5157 | $selectedfound = false; |
||
| 5158 | foreach ($this->cache_vatrates as $rate) |
||
| 5159 | { |
||
| 5160 | // Keep only 0 if seller is not subject to VAT |
||
| 5161 | if ($disabled && $rate['txtva'] != 0) continue; |
||
| 5162 | |||
| 5163 | // Define key to use into select list |
||
| 5164 | $key = $rate['txtva']; |
||
| 5165 | $key .= $rate['nprtva'] ? '*' : ''; |
||
| 5166 | if ($mode > 0 && $rate['code']) $key .= ' ('.$rate['code'].')'; |
||
| 5167 | if ($mode < 0) $key = $rate['rowid']; |
||
| 5168 | |||
| 5169 | $return .= '<option value="'.$key.'"'; |
||
| 5170 | if (!$selectedfound) |
||
| 5171 | { |
||
| 5172 | if ($defaultcode) // If defaultcode is defined, we used it in priority to select combo option instead of using rate+npr flag |
||
| 5173 | { |
||
| 5174 | if ($defaultcode == $rate['code']) |
||
| 5175 | { |
||
| 5176 | $return .= ' selected'; |
||
| 5177 | $selectedfound = true; |
||
| 5178 | } |
||
| 5179 | } elseif ($rate['txtva'] == $defaulttx && $rate['nprtva'] == $defaultnpr) |
||
| 5180 | { |
||
| 5181 | $return .= ' selected'; |
||
| 5182 | $selectedfound = true; |
||
| 5183 | } |
||
| 5184 | } |
||
| 5185 | $return .= '>'; |
||
| 5186 | //if (! empty($conf->global->MAIN_VAT_SHOW_POSITIVE_RATES)) |
||
| 5187 | if ($mysoc->country_code == 'IN' || !empty($conf->global->MAIN_VAT_LABEL_IS_POSITIVE_RATES)) |
||
| 5188 | { |
||
| 5189 | $return .= $rate['labelpositiverates']; |
||
| 5190 | } else { |
||
| 5191 | $return .= vatrate($rate['label']); |
||
| 5192 | } |
||
| 5193 | //$return.=($rate['code']?' '.$rate['code']:''); |
||
| 5194 | $return .= (empty($rate['code']) && $rate['nprtva']) ? ' *' : ''; // We show the * (old behaviour only if new vat code is not used) |
||
| 5195 | |||
| 5196 | $return .= '</option>'; |
||
| 5197 | } |
||
| 5198 | |||
| 5199 | if (!$options_only) $return .= '</select>'; |
||
| 5200 | } else { |
||
| 5201 | $return .= $this->error; |
||
| 5202 | } |
||
| 5203 | |||
| 5204 | $this->num = $num; |
||
| 5205 | return $return; |
||
| 5206 | } |
||
| 5207 | |||
| 5208 | |||
| 5209 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps |
||
| 5210 | /** |
||
| 5211 | * Show a HTML widget to input a date or combo list for day, month, years and optionaly hours and minutes. |
||
| 5212 | * Fields are preselected with : |
||
| 5213 | * - set_time date (must be a local PHP server timestamp or string date with format 'YYYY-MM-DD' or 'YYYY-MM-DD HH:MM') |
||
| 5214 | * - local date in user area, if set_time is '' (so if set_time is '', output may differs when done from two different location) |
||
| 5215 | * - Empty (fields empty), if set_time is -1 (in this case, parameter empty must also have value 1) |
||
| 5216 | * |
||
| 5217 | * @param integer $set_time Pre-selected date (must be a local PHP server timestamp), -1 to keep date not preselected, '' to use current date with 00:00 hour (Parameter 'empty' must be 0 or 2). |
||
| 5218 | * @param string $prefix Prefix for fields name |
||
| 5219 | * @param int $h 1 or 2=Show also hours (2=hours on a new line), -1 has same effect but hour and minutes are prefilled with 23:59 if date is empty, 3 show hour always empty |
||
| 5220 | * @param int $m 1=Show also minutes, -1 has same effect but hour and minutes are prefilled with 23:59 if date is empty, 3 show minutes always empty |
||
| 5221 | * @param int $empty 0=Fields required, 1=Empty inputs are allowed, 2=Empty inputs are allowed for hours only |
||
| 5222 | * @param string $form_name Not used |
||
| 5223 | * @param int $d 1=Show days, month, years |
||
| 5224 | * @param int $addnowlink Add a link "Now" |
||
| 5225 | * @param int $nooutput Do not output html string but return it |
||
| 5226 | * @param int $disabled Disable input fields |
||
| 5227 | * @param int $fullday When a checkbox with this html name is on, hour and day are set with 00:00 or 23:59 |
||
| 5228 | * @param string $addplusone Add a link "+1 hour". Value must be name of another select_date field. |
||
| 5229 | * @param datetime $adddateof Add a link "Date of invoice" using the following date. |
||
| 5230 | * @return string|void Nothing or string if nooutput is 1 |
||
| 5231 | * @deprecated |
||
| 5232 | * @see selectDate(), form_date(), select_month(), select_year(), select_dayofweek() |
||
| 5233 | */ |
||
| 5234 | public function select_date($set_time = '', $prefix = 're', $h = 0, $m = 0, $empty = 0, $form_name = "", $d = 1, $addnowlink = 0, $nooutput = 0, $disabled = 0, $fullday = '', $addplusone = '', $adddateof = '') |
||
| 5243 | } |
||
| 5244 | |||
| 5245 | /** |
||
| 5246 | * Show 2 HTML widget to input a date or combo list for day, month, years and optionaly hours and minutes. |
||
| 5247 | * Fields are preselected with : |
||
| 5248 | * - set_time date (must be a local PHP server timestamp or string date with format 'YYYY-MM-DD' or 'YYYY-MM-DD HH:MM') |
||
| 5249 | * - local date in user area, if set_time is '' (so if set_time is '', output may differs when done from two different location) |
||
| 5250 | * - Empty (fields empty), if set_time is -1 (in this case, parameter empty must also have value 1) |
||
| 5251 | * |
||
| 5252 | * @param integer $set_time Pre-selected date (must be a local PHP server timestamp), -1 to keep date not preselected, '' to use current date with 00:00 hour (Parameter 'empty' must be 0 or 2). |
||
| 5253 | * @param integer $set_time_end Pre-selected date (must be a local PHP server timestamp), -1 to keep date not preselected, '' to use current date with 00:00 hour (Parameter 'empty' must be 0 or 2). |
||
| 5254 | * @param string $prefix Prefix for fields name |
||
| 5255 | * @param string $empty 0=Fields required, 1=Empty inputs are allowed, 2=Empty inputs are allowed for hours only |
||
| 5256 | * @return string Html for selectDate |
||
| 5257 | * @see form_date(), select_month(), select_year(), select_dayofweek() |
||
| 5258 | */ |
||
| 5259 | public function selectDateToDate($set_time = '', $set_time_end = '', $prefix = 're', $empty = 0) |
||
| 5260 | { |
||
| 5261 | $ret = $this->selectDate($set_time, $prefix.'_start', 0, 0, $empty); |
||
| 5262 | $ret .= '<br/>'; |
||
| 5263 | $ret .= $this->selectDate($set_time_end, $prefix.'_end', 0, 0, $empty); |
||
| 5264 | return $ret; |
||
| 5265 | } |
||
| 5266 | |||
| 5267 | /** |
||
| 5268 | * Show a HTML widget to input a date or combo list for day, month, years and optionaly hours and minutes. |
||
| 5269 | * Fields are preselected with : |
||
| 5270 | * - set_time date (must be a local PHP server timestamp or string date with format 'YYYY-MM-DD' or 'YYYY-MM-DD HH:MM') |
||
| 5271 | * - local date in user area, if set_time is '' (so if set_time is '', output may differs when done from two different location) |
||
| 5272 | * - Empty (fields empty), if set_time is -1 (in this case, parameter empty must also have value 1) |
||
| 5273 | * |
||
| 5274 | * @param integer $set_time Pre-selected date (must be a local PHP server timestamp), -1 to keep date not preselected, '' to use current date with 00:00 hour (Parameter 'empty' must be 0 or 2). |
||
| 5275 | * @param string $prefix Prefix for fields name |
||
| 5276 | * @param int $h 1 or 2=Show also hours (2=hours on a new line), -1 has same effect but hour and minutes are prefilled with 23:59 if date is empty, 3 show hour always empty |
||
| 5277 | * @param int $m 1=Show also minutes, -1 has same effect but hour and minutes are prefilled with 23:59 if date is empty, 3 show minutes always empty |
||
| 5278 | * @param int $empty 0=Fields required, 1=Empty inputs are allowed, 2=Empty inputs are allowed for hours only |
||
| 5279 | * @param string $form_name Not used |
||
| 5280 | * @param int $d 1=Show days, month, years |
||
| 5281 | * @param int $addnowlink Add a link "Now", 1 with server time, 2 with local computer time |
||
| 5282 | * @param int $disabled Disable input fields |
||
| 5283 | * @param int $fullday When a checkbox with id #fullday is cheked, hours are set with 00:00 (if value if 'fulldaystart') or 23:59 (if value is 'fulldayend') |
||
| 5284 | * @param string $addplusone Add a link "+1 hour". Value must be name of another selectDate field. |
||
| 5285 | * @param datetime $adddateof Add a link "Date of ..." using the following date. See also $labeladddateof for the label used. |
||
| 5286 | * @param string $openinghours Specify hour start and hour end for the select ex 8,20 |
||
| 5287 | * @param int $stepminutes Specify step for minutes between 1 and 30 |
||
| 5288 | * @param string $labeladddateof Label to use for the $adddateof parameter. |
||
| 5289 | * @return string Html for selectDate |
||
| 5290 | * @see form_date(), select_month(), select_year(), select_dayofweek() |
||
| 5291 | */ |
||
| 5292 | public function selectDate($set_time = '', $prefix = 're', $h = 0, $m = 0, $empty = 0, $form_name = "", $d = 1, $addnowlink = 0, $disabled = 0, $fullday = '', $addplusone = '', $adddateof = '', $openinghours = '', $stepminutes = 1, $labeladddateof = '') |
||
| 5674 | } |
||
| 5675 | |||
| 5676 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps |
||
| 5677 | /** |
||
| 5678 | * Function to show a form to select a duration on a page |
||
| 5679 | * |
||
| 5680 | * @param string $prefix Prefix for input fields |
||
| 5681 | * @param int $iSecond Default preselected duration (number of seconds or '') |
||
| 5682 | * @param int $disabled Disable the combo box |
||
| 5683 | * @param string $typehour If 'select' then input hour and input min is a combo, |
||
| 5684 | * If 'text' input hour is in text and input min is a text, |
||
| 5685 | * If 'textselect' input hour is in text and input min is a combo |
||
| 5686 | * @param integer $minunderhours If 1, show minutes selection under the hours |
||
| 5687 | * @param int $nooutput Do not output html string but return it |
||
| 5688 | * @return string|void |
||
| 5689 | */ |
||
| 5690 | public function select_duration($prefix, $iSecond = '', $disabled = 0, $typehour = 'select', $minunderhours = 0, $nooutput = 0) |
||
| 5691 | { |
||
| 5692 | // phpcs:enable |
||
| 5693 | global $langs; |
||
| 5694 | |||
| 5695 | $retstring = ''; |
||
| 5696 | |||
| 5697 | $hourSelected = 0; $minSelected = 0; |
||
| 5698 | |||
| 5699 | // Hours |
||
| 5700 | if ($iSecond != '') |
||
| 5701 | { |
||
| 5702 | require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; |
||
| 5703 | |||
| 5704 | $hourSelected = convertSecondToTime($iSecond, 'allhour'); |
||
| 5705 | $minSelected = convertSecondToTime($iSecond, 'min'); |
||
| 5706 | } |
||
| 5707 | |||
| 5708 | if ($typehour == 'select') { |
||
| 5709 | $retstring .= '<select class="flat" id="select_'.$prefix.'hour" name="'.$prefix.'hour"'.($disabled ? ' disabled' : '').'>'; |
||
| 5710 | for ($hour = 0; $hour < 25; $hour++) // For a duration, we allow 24 hours |
||
| 5711 | { |
||
| 5712 | $retstring .= '<option value="'.$hour.'"'; |
||
| 5713 | if ($hourSelected == $hour) |
||
| 5714 | { |
||
| 5715 | $retstring .= " selected"; |
||
| 5716 | } |
||
| 5717 | $retstring .= ">".$hour."</option>"; |
||
| 5718 | } |
||
| 5719 | $retstring .= "</select>"; |
||
| 5720 | } elseif ($typehour == 'text' || $typehour == 'textselect') { |
||
| 5721 | $retstring .= '<input placeholder="'.$langs->trans('HourShort').'" type="number" min="0" name="'.$prefix.'hour"'.($disabled ? ' disabled' : '').' class="flat maxwidth50 inputhour" value="'.(($hourSelected != '') ? ((int) $hourSelected) : '').'">'; |
||
| 5722 | } else { |
||
| 5723 | return 'BadValueForParameterTypeHour'; |
||
| 5724 | } |
||
| 5725 | |||
| 5726 | if ($typehour != 'text') $retstring .= ' '.$langs->trans('HourShort'); |
||
| 5727 | else $retstring .= '<span class="hideonsmartphone">:</span>'; |
||
| 5728 | |||
| 5729 | // Minutes |
||
| 5730 | if ($minunderhours) $retstring .= '<br>'; |
||
| 5731 | else $retstring .= '<span class="hideonsmartphone"> </span>'; |
||
| 5732 | |||
| 5733 | if ($typehour == 'select' || $typehour == 'textselect') |
||
| 5734 | { |
||
| 5735 | $retstring .= '<select class="flat" id="select_'.$prefix.'min" name="'.$prefix.'min"'.($disabled ? ' disabled' : '').'>'; |
||
| 5736 | for ($min = 0; $min <= 55; $min = $min + 5) |
||
| 5737 | { |
||
| 5738 | $retstring .= '<option value="'.$min.'"'; |
||
| 5739 | if ($minSelected == $min) $retstring .= ' selected'; |
||
| 5740 | $retstring .= '>'.$min.'</option>'; |
||
| 5741 | } |
||
| 5742 | $retstring .= "</select>"; |
||
| 5743 | } elseif ($typehour == 'text') |
||
| 5744 | { |
||
| 5745 | $retstring .= '<input placeholder="'.$langs->trans('MinuteShort').'" type="number" min="0" name="'.$prefix.'min"'.($disabled ? ' disabled' : '').' class="flat maxwidth50 inputminute" value="'.(($minSelected != '') ? ((int) $minSelected) : '').'">'; |
||
| 5746 | } |
||
| 5747 | |||
| 5748 | if ($typehour != 'text') $retstring .= ' '.$langs->trans('MinuteShort'); |
||
| 5749 | |||
| 5750 | //$retstring.=" "; |
||
| 5751 | |||
| 5752 | if (!empty($nooutput)) return $retstring; |
||
| 5753 | |||
| 5754 | print $retstring; |
||
| 5755 | return; |
||
| 5756 | } |
||
| 5757 | |||
| 5758 | |||
| 5759 | /** |
||
| 5760 | * Generic method to select a component from a combo list. |
||
| 5761 | * This is the generic method that will replace all specific existing methods. |
||
| 5762 | * |
||
| 5763 | * @param string $objectdesc ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter]] |
||
| 5764 | * @param string $htmlname Name of HTML select component |
||
| 5765 | * @param int $preselectedvalue Preselected value (ID of element) |
||
| 5766 | * @param string $showempty ''=empty values not allowed, 'string'=value show if we allow empty values (for example 'All', ...) |
||
| 5767 | * @param string $searchkey Search criteria |
||
| 5768 | * @param string $placeholder Place holder |
||
| 5769 | * @param string $morecss More CSS |
||
| 5770 | * @param string $moreparams More params provided to ajax call |
||
| 5771 | * @param int $forcecombo Force to load all values and output a standard combobox (with no beautification) |
||
| 5772 | * @param int $disabled 1=Html component is disabled |
||
| 5773 | * @param string $selected_input_value Value of preselected input text (for use with ajax) |
||
| 5774 | * @return string Return HTML string |
||
| 5775 | * @see selectForFormsList() select_thirdparty |
||
| 5776 | */ |
||
| 5777 | public function selectForForms($objectdesc, $htmlname, $preselectedvalue, $showempty = '', $searchkey = '', $placeholder = '', $morecss = '', $moreparams = '', $forcecombo = 0, $disabled = 0, $selected_input_value = '') |
||
| 5778 | { |
||
| 5779 | global $conf, $user; |
||
| 5780 | |||
| 5781 | $objecttmp = null; |
||
| 5782 | |||
| 5783 | $InfoFieldList = explode(":", $objectdesc); |
||
| 5784 | $classname = $InfoFieldList[0]; |
||
| 5785 | $classpath = $InfoFieldList[1]; |
||
| 5786 | $addcreatebuttonornot = empty($InfoFieldList[2]) ? 0 : $InfoFieldList[2]; |
||
| 5787 | $filter = empty($InfoFieldList[3]) ? '' : $InfoFieldList[3]; |
||
| 5788 | |||
| 5789 | if (!empty($classpath)) |
||
| 5790 | { |
||
| 5791 | dol_include_once($classpath); |
||
| 5792 | |||
| 5793 | if ($classname && class_exists($classname)) |
||
| 5794 | { |
||
| 5795 | $objecttmp = new $classname($this->db); |
||
| 5796 | // Make some replacement |
||
| 5797 | $sharedentities = getEntity(strtolower($classname)); |
||
| 5798 | $objecttmp->filter = str_replace( |
||
| 5799 | array('__ENTITY__', '__SHARED_ENTITIES__', '__USER_ID__'), |
||
| 5800 | array($conf->entity, $sharedentities, $user->id), |
||
| 5801 | $filter); |
||
| 5802 | } |
||
| 5803 | } |
||
| 5804 | if (!is_object($objecttmp)) |
||
| 5805 | { |
||
| 5806 | dol_syslog('Error bad setup of type for field '.$InfoFieldList, LOG_WARNING); |
||
| 5807 | return 'Error bad setup of type for field '.join(',', $InfoFieldList); |
||
| 5808 | } |
||
| 5809 | |||
| 5810 | //var_dump($objecttmp->filter); |
||
| 5811 | $prefixforautocompletemode = $objecttmp->element; |
||
| 5812 | if ($prefixforautocompletemode == 'societe') $prefixforautocompletemode = 'company'; |
||
| 5813 | if ($prefixforautocompletemode == 'product') $prefixforautocompletemode = 'produit'; |
||
| 5814 | $confkeyforautocompletemode = strtoupper($prefixforautocompletemode).'_USE_SEARCH_TO_SELECT'; // For example COMPANY_USE_SEARCH_TO_SELECT |
||
| 5815 | |||
| 5816 | dol_syslog(get_class($this)."::selectForForms object->filter=".$objecttmp->filter, LOG_DEBUG); |
||
| 5817 | $out = ''; |
||
| 5818 | if (!empty($conf->use_javascript_ajax) && !empty($conf->global->$confkeyforautocompletemode) && !$forcecombo) |
||
| 5819 | { |
||
| 5820 | // No immediate load of all database |
||
| 5821 | $placeholder = ''; |
||
| 5822 | if ($preselectedvalue && empty($selected_input_value)) |
||
| 5823 | { |
||
| 5824 | $objecttmp->fetch($preselectedvalue); |
||
| 5825 | $selected_input_value = ($prefixforautocompletemode == 'company' ? $objecttmp->name : $objecttmp->ref); |
||
| 5826 | //unset($objecttmp); |
||
| 5827 | } |
||
| 5828 | |||
| 5829 | $objectdesc = $classname.':'.$classpath.':'.$addcreatebuttonornot.':'.$filter; |
||
| 5830 | $urlforajaxcall = DOL_URL_ROOT.'/core/ajax/selectobject.php'; |
||
| 5831 | |||
| 5832 | // No immediate load of all database |
||
| 5833 | $urloption = 'htmlname='.$htmlname.'&outjson=1&objectdesc='.$objectdesc.'&filter='.urlencode($objecttmp->filter); |
||
| 5834 | // Activate the auto complete using ajax call. |
||
| 5835 | $out .= ajax_autocompleter($preselectedvalue, $htmlname, $urlforajaxcall, $urloption, $conf->global->$confkeyforautocompletemode, 0, array()); |
||
| 5836 | $out .= '<style type="text/css">.ui-autocomplete { z-index: 250; }</style>'; |
||
| 5837 | if ($placeholder) $placeholder = ' placeholder="'.$placeholder.'"'; |
||
| 5838 | $out .= '<input type="text" class="'.$morecss.'"'.($disabled ? ' disabled="disabled"' : '').' name="search_'.$htmlname.'" id="search_'.$htmlname.'" value="'.$selected_input_value.'"'.$placeholder.' />'; |
||
| 5839 | } else { |
||
| 5840 | // Immediate load of table record. Note: filter is inside $objecttmp->filter |
||
| 5841 | $out .= $this->selectForFormsList($objecttmp, $htmlname, $preselectedvalue, $showempty, $searchkey, $placeholder, $morecss, $moreparams, $forcecombo, 0, $disabled); |
||
| 5842 | } |
||
| 5843 | |||
| 5844 | return $out; |
||
| 5845 | } |
||
| 5846 | |||
| 5847 | /** |
||
| 5848 | * Function to forge a SQL criteria |
||
| 5849 | * |
||
| 5850 | * @param array $matches Array of found string by regex search. Example: "t.ref:like:'SO-%'" or "t.date_creation:<:'20160101'" or "t.nature:is:NULL" |
||
| 5851 | * @return string Forged criteria. Example: "t.field like 'abc%'" |
||
| 5852 | */ |
||
| 5853 | protected static function forgeCriteriaCallback($matches) |
||
| 5854 | { |
||
| 5855 | global $db; |
||
| 5856 | |||
| 5857 | //dol_syslog("Convert matches ".$matches[1]); |
||
| 5858 | if (empty($matches[1])) return ''; |
||
| 5859 | $tmp = explode(':', $matches[1]); |
||
| 5860 | if (count($tmp) < 3) return ''; |
||
| 5861 | |||
| 5862 | $tmpescaped = $tmp[2]; |
||
| 5863 | $regbis = array(); |
||
| 5864 | if (preg_match('/^\'(.*)\'$/', $tmpescaped, $regbis)) |
||
| 5865 | { |
||
| 5866 | $tmpescaped = "'".$db->escape($regbis[1])."'"; |
||
| 5867 | } else { |
||
| 5868 | $tmpescaped = $db->escape($tmpescaped); |
||
| 5869 | } |
||
| 5870 | return $db->escape($tmp[0]).' '.strtoupper($db->escape($tmp[1]))." ".$tmpescaped; |
||
| 5871 | } |
||
| 5872 | |||
| 5873 | /** |
||
| 5874 | * Output html form to select an object. |
||
| 5875 | * Note, this function is called by selectForForms or by ajax selectobject.php |
||
| 5876 | * |
||
| 5877 | * @param Object $objecttmp Object to knwo the table to scan for combo. |
||
| 5878 | * @param string $htmlname Name of HTML select component |
||
| 5879 | * @param int $preselectedvalue Preselected value (ID of element) |
||
| 5880 | * @param string $showempty ''=empty values not allowed, 'string'=value show if we allow empty values (for example 'All', ...) |
||
| 5881 | * @param string $searchkey Search value |
||
| 5882 | * @param string $placeholder Place holder |
||
| 5883 | * @param string $morecss More CSS |
||
| 5884 | * @param string $moreparams More params provided to ajax call |
||
| 5885 | * @param int $forcecombo Force to load all values and output a standard combobox (with no beautification) |
||
| 5886 | * @param int $outputmode 0=HTML select string, 1=Array |
||
| 5887 | * @param int $disabled 1=Html component is disabled |
||
| 5888 | * @return string|array Return HTML string |
||
| 5889 | * @see selectForForms() |
||
| 5890 | */ |
||
| 5891 | public function selectForFormsList($objecttmp, $htmlname, $preselectedvalue, $showempty = '', $searchkey = '', $placeholder = '', $morecss = '', $moreparams = '', $forcecombo = 0, $outputmode = 0, $disabled = 0) |
||
| 6027 | } |
||
| 6028 | |||
| 6029 | |||
| 6030 | /** |
||
| 6031 | * Return a HTML select string, built from an array of key+value. |
||
| 6032 | * Note: Do not apply langs->trans function on returned content, content may be entity encoded twice. |
||
| 6033 | * |
||
| 6034 | * @param string $htmlname Name of html select area. Must start with "multi" if this is a multiselect |
||
| 6035 | * @param array $array Array like array(key => value) or array(key=>array('label'=>..., 'data-...'=>...)) |
||
| 6036 | * @param string|string[] $id Preselected key or preselected keys for multiselect |
||
| 6037 | * @param int|string $show_empty 0 no empty value allowed, 1 or string to add an empty value into list (key is -1 and value is '' or ' ' if 1, key is -1 and value is text if string), <0 to add an empty value with key that is this value. |
||
| 6038 | * @param int $key_in_label 1 to show key into label with format "[key] value" |
||
| 6039 | * @param int $value_as_key 1 to use value as key |
||
| 6040 | * @param string $moreparam Add more parameters onto the select tag. For example 'style="width: 95%"' to avoid select2 component to go over parent container |
||
| 6041 | * @param int $translate 1=Translate and encode value |
||
| 6042 | * @param int $maxlen Length maximum for labels |
||
| 6043 | * @param int $disabled Html select box is disabled |
||
| 6044 | * @param string $sort 'ASC' or 'DESC' = Sort on label, '' or 'NONE' or 'POS' = Do not sort, we keep original order |
||
| 6045 | * @param string $morecss Add more class to css styles |
||
| 6046 | * @param int $addjscombo Add js combo |
||
| 6047 | * @param string $moreparamonempty Add more param on the empty option line. Not used if show_empty not set |
||
| 6048 | * @param int $disablebademail 1=Check if a not valid email, 2=Check string '---', and if found into value, disable and colorize entry |
||
| 6049 | * @param int $nohtmlescape No html escaping. |
||
| 6050 | * @return string HTML select string. |
||
| 6051 | * @see multiselectarray(), selectArrayAjax(), selectArrayFilter() |
||
| 6052 | */ |
||
| 6053 | public static function selectarray($htmlname, $array, $id = '', $show_empty = 0, $key_in_label = 0, $value_as_key = 0, $moreparam = '', $translate = 0, $maxlen = 0, $disabled = 0, $sort = '', $morecss = '', $addjscombo = 0, $moreparamonempty = '', $disablebademail = 0, $nohtmlescape = 0) |
||
| 6054 | { |
||
| 6055 | global $conf, $langs; |
||
| 6056 | |||
| 6057 | // Do we want a multiselect ? |
||
| 6058 | //$jsbeautify = 0; |
||
| 6059 | //if (preg_match('/^multi/',$htmlname)) $jsbeautify = 1; |
||
| 6060 | $jsbeautify = 1; |
||
| 6061 | |||
| 6062 | if ($value_as_key) $array = array_combine($array, $array); |
||
| 6063 | |||
| 6064 | $out = ''; |
||
| 6065 | |||
| 6066 | // Add code for jquery to use multiselect |
||
| 6067 | if ($addjscombo && $jsbeautify) |
||
| 6068 | { |
||
| 6069 | $minLengthToAutocomplete = 0; |
||
| 6070 | $tmpplugin = empty($conf->global->MAIN_USE_JQUERY_MULTISELECT) ? (constant('REQUIRE_JQUERY_MULTISELECT') ?constant('REQUIRE_JQUERY_MULTISELECT') : 'select2') : $conf->global->MAIN_USE_JQUERY_MULTISELECT; |
||
| 6071 | |||
| 6072 | // Enhance with select2 |
||
| 6073 | include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php'; |
||
| 6074 | $out .= ajax_combobox($htmlname); |
||
| 6075 | } |
||
| 6076 | |||
| 6077 | $out .= '<select id="'.preg_replace('/^\./', '', $htmlname).'" '.($disabled ? 'disabled="disabled" ' : '').'class="flat '.(preg_replace('/^\./', '', $htmlname)).($morecss ? ' '.$morecss : '').'"'; |
||
| 6078 | $out .= ' name="'.preg_replace('/^\./', '', $htmlname).'" '.($moreparam ? $moreparam : ''); |
||
| 6079 | $out .= '>'; |
||
| 6080 | |||
| 6081 | if ($show_empty) |
||
| 6082 | { |
||
| 6083 | $textforempty = ' '; |
||
| 6084 | if (!empty($conf->use_javascript_ajax)) $textforempty = ' '; // If we use ajaxcombo, we need here to avoid to have an empty element that is too small. |
||
| 6085 | if (!is_numeric($show_empty)) $textforempty = $show_empty; |
||
| 6086 | $out .= '<option class="optiongrey" '.($moreparamonempty ? $moreparamonempty.' ' : '').'value="'.($show_empty < 0 ? $show_empty : -1).'"'.($id == $show_empty ? ' selected' : '').'>'.$textforempty.'</option>'."\n"; |
||
| 6087 | } |
||
| 6088 | |||
| 6089 | if (is_array($array)) |
||
| 6090 | { |
||
| 6091 | // Translate |
||
| 6092 | if ($translate) |
||
| 6093 | { |
||
| 6094 | foreach ($array as $key => $value) |
||
| 6095 | { |
||
| 6096 | if (!is_array($value)) $array[$key] = $langs->trans($value); |
||
| 6097 | else $array[$key]['label'] = $langs->trans($value['label']); |
||
| 6098 | } |
||
| 6099 | } |
||
| 6100 | |||
| 6101 | // Sort |
||
| 6102 | if ($sort == 'ASC') asort($array); |
||
| 6103 | elseif ($sort == 'DESC') arsort($array); |
||
| 6104 | |||
| 6105 | foreach ($array as $key => $tmpvalue) |
||
| 6106 | { |
||
| 6107 | if (is_array($tmpvalue)) $value = $tmpvalue['label']; |
||
| 6108 | else $value = $tmpvalue; |
||
| 6109 | |||
| 6110 | $disabled = ''; $style = ''; |
||
| 6111 | if (!empty($disablebademail)) |
||
| 6112 | { |
||
| 6113 | if (($disablebademail == 1 && !preg_match('/<.+@.+>/', $value)) |
||
| 6114 | || ($disablebademail == 2 && preg_match('/---/', $value))) |
||
| 6115 | { |
||
| 6116 | $disabled = ' disabled'; |
||
| 6117 | $style = ' class="warning"'; |
||
| 6118 | } |
||
| 6119 | } |
||
| 6120 | |||
| 6121 | if ($key_in_label) |
||
| 6122 | { |
||
| 6123 | if (empty($nohtmlescape)) $selectOptionValue = dol_escape_htmltag($key.' - '.($maxlen ?dol_trunc($value, $maxlen) : $value)); |
||
| 6124 | else $selectOptionValue = $key.' - '.($maxlen ?dol_trunc($value, $maxlen) : $value); |
||
| 6125 | } else { |
||
| 6126 | if (empty($nohtmlescape)) $selectOptionValue = dol_escape_htmltag($maxlen ?dol_trunc($value, $maxlen) : $value); |
||
| 6127 | else $selectOptionValue = $maxlen ?dol_trunc($value, $maxlen) : $value; |
||
| 6128 | if ($value == '' || $value == '-') $selectOptionValue = ' '; |
||
| 6129 | } |
||
| 6130 | |||
| 6131 | $out .= '<option value="'.$key.'"'; |
||
| 6132 | $out .= $style.$disabled; |
||
| 6133 | if (is_array($id)) { |
||
| 6134 | if (in_array($key, $id) && !$disabled) $out .= ' selected'; // To preselect a value |
||
| 6135 | } else { |
||
| 6136 | $id = (string) $id; // if $id = 0, then $id = '0' |
||
| 6137 | if ($id != '' && $id == $key && !$disabled) $out .= ' selected'; // To preselect a value |
||
| 6138 | } |
||
| 6139 | if ($nohtmlescape) $out .= ' data-html="'.dol_escape_htmltag($selectOptionValue).'"'; |
||
| 6140 | if (is_array($tmpvalue)) |
||
| 6141 | { |
||
| 6142 | foreach ($tmpvalue as $keyforvalue => $valueforvalue) |
||
| 6143 | { |
||
| 6144 | if (preg_match('/^data-/', $keyforvalue)) $out .= ' '.$keyforvalue.'="'.$valueforvalue.'"'; |
||
| 6145 | } |
||
| 6146 | } |
||
| 6147 | $out .= '>'; |
||
| 6148 | //var_dump($selectOptionValue); |
||
| 6149 | $out .= $selectOptionValue; |
||
| 6150 | $out .= "</option>\n"; |
||
| 6151 | } |
||
| 6152 | } |
||
| 6153 | |||
| 6154 | $out .= "</select>"; |
||
| 6155 | return $out; |
||
| 6156 | } |
||
| 6157 | |||
| 6158 | |||
| 6159 | /** |
||
| 6160 | * Return a HTML select string, built from an array of key+value, but content returned into select come from an Ajax call of an URL. |
||
| 6161 | * Note: Do not apply langs->trans function on returned content of Ajax service, content may be entity encoded twice. |
||
| 6162 | * |
||
| 6163 | * @param string $htmlname Name of html select area |
||
| 6164 | * @param string $url Url. Must return a json_encode of array(key=>array('text'=>'A text', 'url'=>'An url'), ...) |
||
| 6165 | * @param string $id Preselected key |
||
| 6166 | * @param string $moreparam Add more parameters onto the select tag |
||
| 6167 | * @param string $moreparamtourl Add more parameters onto the Ajax called URL |
||
| 6168 | * @param int $disabled Html select box is disabled |
||
| 6169 | * @param int $minimumInputLength Minimum Input Length |
||
| 6170 | * @param string $morecss Add more class to css styles |
||
| 6171 | * @param int $callurlonselect If set to 1, some code is added so an url return by the ajax is called when value is selected. |
||
| 6172 | * @param string $placeholder String to use as placeholder |
||
| 6173 | * @param integer $acceptdelayedhtml 1 = caller is requesting to have html js content not returned but saved into global $delayedhtmlcontent (so caller can show it at end of page to avoid flash FOUC effect) |
||
| 6174 | * @return string HTML select string |
||
| 6175 | * @see selectArrayFilter(), ajax_combobox() in ajax.lib.php |
||
| 6176 | */ |
||
| 6177 | public static function selectArrayAjax($htmlname, $url, $id = '', $moreparam = '', $moreparamtourl = '', $disabled = 0, $minimumInputLength = 1, $morecss = '', $callurlonselect = 0, $placeholder = '', $acceptdelayedhtml = 0) |
||
| 6178 | { |
||
| 6179 | global $conf, $langs; |
||
| 6180 | global $delayedhtmlcontent; |
||
| 6181 | |||
| 6182 | // TODO Use an internal dolibarr component instead of select2 |
||
| 6183 | if (empty($conf->global->MAIN_USE_JQUERY_MULTISELECT) && !defined('REQUIRE_JQUERY_MULTISELECT')) return ''; |
||
| 6184 | |||
| 6185 | $out = '<select type="text" class="'.$htmlname.($morecss ? ' '.$morecss : '').'" '.($moreparam ? $moreparam.' ' : '').'name="'.$htmlname.'"></select>'; |
||
| 6186 | |||
| 6187 | $tmpplugin = 'select2'; |
||
| 6188 | $outdelayed = "\n".'<!-- JS CODE TO ENABLE '.$tmpplugin.' for id '.$htmlname.' --> |
||
| 6189 | <script> |
||
| 6190 | $(document).ready(function () { |
||
| 6191 | |||
| 6192 | '.($callurlonselect ? 'var saveRemoteData = [];' : '').' |
||
| 6193 | |||
| 6194 | $(".'.$htmlname.'").select2({ |
||
| 6195 | ajax: { |
||
| 6196 | dir: "ltr", |
||
| 6197 | url: "'.$url.'", |
||
| 6198 | dataType: \'json\', |
||
| 6199 | delay: 250, |
||
| 6200 | data: function (params) { |
||
| 6201 | return { |
||
| 6202 | q: params.term, // search term |
||
| 6203 | page: params.page |
||
| 6204 | }; |
||
| 6205 | }, |
||
| 6206 | processResults: function (data) { |
||
| 6207 | // parse the results into the format expected by Select2. |
||
| 6208 | // since we are using custom formatting functions we do not need to alter the remote JSON data |
||
| 6209 | //console.log(data); |
||
| 6210 | saveRemoteData = data; |
||
| 6211 | /* format json result for select2 */ |
||
| 6212 | result = [] |
||
| 6213 | $.each( data, function( key, value ) { |
||
| 6214 | result.push({id: key, text: value.text}); |
||
| 6215 | }); |
||
| 6216 | //return {results:[{id:\'none\', text:\'aa\'}, {id:\'rrr\', text:\'Red\'},{id:\'bbb\', text:\'Search a into projects\'}], more:false} |
||
| 6217 | //console.log(result); |
||
| 6218 | return {results: result, more: false} |
||
| 6219 | }, |
||
| 6220 | cache: true |
||
| 6221 | }, |
||
| 6222 | language: select2arrayoflanguage, |
||
| 6223 | containerCssClass: \':all:\', /* Line to add class of origin SELECT propagated to the new <span class="select2-selection...> tag */ |
||
| 6224 | placeholder: "'.dol_escape_js($placeholder).'", |
||
| 6225 | escapeMarkup: function (markup) { return markup; }, // let our custom formatter work |
||
| 6226 | minimumInputLength: '.$minimumInputLength.', |
||
| 6227 | formatResult: function(result, container, query, escapeMarkup) { |
||
| 6228 | return escapeMarkup(result.text); |
||
| 6229 | }, |
||
| 6230 | }); |
||
| 6231 | |||
| 6232 | '.($callurlonselect ? ' |
||
| 6233 | /* Code to execute a GET when we select a value */ |
||
| 6234 | $(".'.$htmlname.'").change(function() { |
||
| 6235 | var selected = $(".'.$htmlname.'").val(); |
||
| 6236 | console.log("We select in selectArrayAjax the entry "+selected) |
||
| 6237 | $(".'.$htmlname.'").val(""); /* reset visible combo value */ |
||
| 6238 | $.each( saveRemoteData, function( key, value ) { |
||
| 6239 | if (key == selected) |
||
| 6240 | { |
||
| 6241 | console.log("selectArrayAjax - Do a redirect to "+value.url) |
||
| 6242 | location.assign(value.url); |
||
| 6243 | } |
||
| 6244 | }); |
||
| 6245 | });' : '').' |
||
| 6246 | |||
| 6247 | }); |
||
| 6248 | </script>'; |
||
| 6249 | |||
| 6250 | if ($acceptdelayedhtml) |
||
| 6251 | { |
||
| 6252 | $delayedhtmlcontent .= $outdelayed; |
||
| 6253 | } else { |
||
| 6254 | $out .= $outdelayed; |
||
| 6255 | } |
||
| 6256 | return $out; |
||
| 6257 | } |
||
| 6258 | |||
| 6259 | /** |
||
| 6260 | * Return a HTML select string, built from an array of key+value, but content returned into select is defined into $array parameter. |
||
| 6261 | * Note: Do not apply langs->trans function on returned content of Ajax service, content may be entity encoded twice. |
||
| 6262 | * |
||
| 6263 | * @param string $htmlname Name of html select area |
||
| 6264 | * @param string $array Array (key=>array('text'=>'A text', 'url'=>'An url'), ...) |
||
| 6265 | * @param string $id Preselected key |
||
| 6266 | * @param string $moreparam Add more parameters onto the select tag |
||
| 6267 | * @param int $disableFiltering If set to 1, results are not filtered with searched string |
||
| 6268 | * @param int $disabled Html select box is disabled |
||
| 6269 | * @param int $minimumInputLength Minimum Input Length |
||
| 6270 | * @param string $morecss Add more class to css styles |
||
| 6271 | * @param int $callurlonselect If set to 1, some code is added so an url return by the ajax is called when value is selected. |
||
| 6272 | * @param string $placeholder String to use as placeholder |
||
| 6273 | * @param integer $acceptdelayedhtml 1 = caller is requesting to have html js content not returned but saved into global $delayedhtmlcontent (so caller can show it at end of page to avoid flash FOUC effect) |
||
| 6274 | * @return string HTML select string |
||
| 6275 | * @see selectArrayAjax(), ajax_combobox() in ajax.lib.php |
||
| 6276 | */ |
||
| 6277 | public static function selectArrayFilter($htmlname, $array, $id = '', $moreparam = '', $disableFiltering = 0, $disabled = 0, $minimumInputLength = 1, $morecss = '', $callurlonselect = 0, $placeholder = '', $acceptdelayedhtml = 0) |
||
| 6278 | { |
||
| 6279 | global $conf, $langs; |
||
| 6280 | global $delayedhtmlcontent; |
||
| 6281 | |||
| 6282 | // TODO Use an internal dolibarr component instead of select2 |
||
| 6283 | if (empty($conf->global->MAIN_USE_JQUERY_MULTISELECT) && !defined('REQUIRE_JQUERY_MULTISELECT')) return ''; |
||
| 6284 | |||
| 6285 | $out = '<select type="text" class="'.$htmlname.($morecss ? ' '.$morecss : '').'" '.($moreparam ? $moreparam.' ' : '').'name="'.$htmlname.'"><option></option></select>'; |
||
| 6286 | |||
| 6287 | $formattedarrayresult = array(); |
||
| 6288 | |||
| 6289 | foreach ($array as $key => $value) { |
||
| 6290 | $o = new stdClass(); |
||
| 6291 | $o->id = $key; |
||
| 6292 | $o->text = $value['text']; |
||
| 6293 | $o->url = $value['url']; |
||
| 6294 | $formattedarrayresult[] = $o; |
||
| 6295 | } |
||
| 6296 | |||
| 6297 | $tmpplugin = 'select2'; |
||
| 6298 | $outdelayed = "\n".'<!-- JS CODE TO ENABLE '.$tmpplugin.' for id '.$htmlname.' --> |
||
| 6299 | <script> |
||
| 6300 | $(document).ready(function () { |
||
| 6301 | var data = '.json_encode($formattedarrayresult).'; |
||
| 6302 | |||
| 6303 | '.($callurlonselect ? 'var saveRemoteData = '.json_encode($array).';' : '').' |
||
| 6304 | |||
| 6305 | $(".'.$htmlname.'").select2({ |
||
| 6306 | data: data, |
||
| 6307 | language: select2arrayoflanguage, |
||
| 6308 | containerCssClass: \':all:\', /* Line to add class of origin SELECT propagated to the new <span class="select2-selection...> tag */ |
||
| 6309 | placeholder: "'.dol_escape_js($placeholder).'", |
||
| 6310 | escapeMarkup: function (markup) { return markup; }, // let our custom formatter work |
||
| 6311 | minimumInputLength: '.$minimumInputLength.', |
||
| 6312 | formatResult: function(result, container, query, escapeMarkup) { |
||
| 6313 | return escapeMarkup(result.text); |
||
| 6314 | }, |
||
| 6315 | matcher: function (params, data) { |
||
| 6316 | |||
| 6317 | if(! data.id) return null;'; |
||
| 6318 | |||
| 6319 | if ($callurlonselect) { |
||
| 6320 | $outdelayed .= ' |
||
| 6321 | |||
| 6322 | var urlBase = data.url; |
||
| 6323 | var separ = urlBase.indexOf("?") >= 0 ? "&" : "?"; |
||
| 6324 | /* console.log("params.term="+params.term); */ |
||
| 6325 | /* console.log("params.term encoded="+encodeURIComponent(params.term)); */ |
||
| 6326 | saveRemoteData[data.id].url = urlBase + separ + "sall=" + encodeURIComponent(params.term);'; |
||
| 6327 | } |
||
| 6328 | |||
| 6329 | if (!$disableFiltering) { |
||
| 6330 | $outdelayed .= ' |
||
| 6331 | |||
| 6332 | if(data.text.match(new RegExp(params.term))) { |
||
| 6333 | return data; |
||
| 6334 | } |
||
| 6335 | |||
| 6336 | return null;'; |
||
| 6337 | } else { |
||
| 6338 | $outdelayed .= ' |
||
| 6339 | |||
| 6340 | return data;'; |
||
| 6341 | } |
||
| 6342 | |||
| 6343 | $outdelayed .= ' |
||
| 6344 | } |
||
| 6345 | }); |
||
| 6346 | |||
| 6347 | '.($callurlonselect ? ' |
||
| 6348 | /* Code to execute a GET when we select a value */ |
||
| 6349 | $(".'.$htmlname.'").change(function() { |
||
| 6350 | var selected = $(".'.$htmlname.'").val(); |
||
| 6351 | console.log("We select "+selected) |
||
| 6352 | |||
| 6353 | $(".'.$htmlname.'").val(""); /* reset visible combo value */ |
||
| 6354 | $.each( saveRemoteData, function( key, value ) { |
||
| 6355 | if (key == selected) |
||
| 6356 | { |
||
| 6357 | console.log("selectArrayAjax - Do a redirect to "+value.url) |
||
| 6358 | location.assign(value.url); |
||
| 6359 | } |
||
| 6360 | }); |
||
| 6361 | });' : '').' |
||
| 6362 | |||
| 6363 | }); |
||
| 6364 | </script>'; |
||
| 6365 | |||
| 6366 | if ($acceptdelayedhtml) |
||
| 6367 | { |
||
| 6368 | $delayedhtmlcontent .= $outdelayed; |
||
| 6369 | } else { |
||
| 6370 | $out .= $outdelayed; |
||
| 6371 | } |
||
| 6372 | return $out; |
||
| 6373 | } |
||
| 6374 | |||
| 6375 | /** |
||
| 6376 | * Show a multiselect form from an array. |
||
| 6377 | * |
||
| 6378 | * @param string $htmlname Name of select |
||
| 6379 | * @param array $array Array with key+value |
||
| 6380 | * @param array $selected Array with key+value preselected |
||
| 6381 | * @param int $key_in_label 1 pour afficher la key dans la valeur "[key] value" |
||
| 6382 | * @param int $value_as_key 1 to use value as key |
||
| 6383 | * @param string $morecss Add more css style |
||
| 6384 | * @param int $translate Translate and encode value |
||
| 6385 | * @param int $width Force width of select box. May be used only when using jquery couch. Example: 250, 95% |
||
| 6386 | * @param string $moreattrib Add more options on select component. Example: 'disabled' |
||
| 6387 | * @param string $elemtype Type of element we show ('category', ...). Will execute a formating function on it. To use in readonly mode if js component support HTML formatting. |
||
| 6388 | * @param string $placeholder String to use as placeholder |
||
| 6389 | * @param int $addjscombo Add js combo |
||
| 6390 | * @return string HTML multiselect string |
||
| 6391 | * @see selectarray(), selectArrayAjax(), selectArrayFilter() |
||
| 6392 | */ |
||
| 6393 | public static function multiselectarray($htmlname, $array, $selected = array(), $key_in_label = 0, $value_as_key = 0, $morecss = '', $translate = 0, $width = 0, $moreattrib = '', $elemtype = '', $placeholder = '', $addjscombo = -1) |
||
| 6485 | } |
||
| 6486 | |||
| 6487 | |||
| 6488 | /** |
||
| 6489 | * Show a multiselect dropbox from an array. |
||
| 6490 | * |
||
| 6491 | * @param string $htmlname Name of HTML field |
||
| 6492 | * @param array $array Array with array of fields we could show. This array may be modified according to setup of user. |
||
| 6493 | * @param string $varpage Id of context for page. Can be set by caller with $varpage=(empty($contextpage)?$_SERVER["PHP_SELF"]:$contextpage); |
||
| 6494 | * @return string HTML multiselect string |
||
| 6495 | * @see selectarray() |
||
| 6496 | */ |
||
| 6497 | public static function multiSelectArrayWithCheckbox($htmlname, &$array, $varpage) |
||
| 6498 | { |
||
| 6499 | global $conf, $langs, $user, $extrafields; |
||
| 6500 | |||
| 6501 | if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) return ''; |
||
| 6502 | |||
| 6503 | $tmpvar = "MAIN_SELECTEDFIELDS_".$varpage; // To get list of saved seleteced properties |
||
| 6504 | if (!empty($user->conf->$tmpvar)) |
||
| 6505 | { |
||
| 6506 | $tmparray = explode(',', $user->conf->$tmpvar); |
||
| 6507 | foreach ($array as $key => $val) |
||
| 6508 | { |
||
| 6509 | //var_dump($key); |
||
| 6510 | //var_dump($tmparray); |
||
| 6511 | if (in_array($key, $tmparray)) $array[$key]['checked'] = 1; |
||
| 6512 | else $array[$key]['checked'] = 0; |
||
| 6513 | } |
||
| 6514 | } |
||
| 6515 | |||
| 6516 | $lis = ''; |
||
| 6517 | $listcheckedstring = ''; |
||
| 6518 | |||
| 6519 | foreach ($array as $key => $val) |
||
| 6520 | { |
||
| 6521 | /* var_dump($val); |
||
| 6522 | var_dump(array_key_exists('enabled', $val)); |
||
| 6523 | var_dump(!$val['enabled']);*/ |
||
| 6524 | if (array_key_exists('enabled', $val) && isset($val['enabled']) && !$val['enabled']) |
||
| 6525 | { |
||
| 6526 | unset($array[$key]); // We don't want this field |
||
| 6527 | continue; |
||
| 6528 | } |
||
| 6529 | if ($val['label']) |
||
| 6530 | { |
||
| 6531 | if (! empty($val['langfile']) && is_object($langs)) { |
||
| 6532 | $langs->load($val['langfile']); |
||
| 6533 | } |
||
| 6534 | |||
| 6535 | $lis .= '<li><input type="checkbox" id="checkbox'.$key.'" value="'.$key.'"'.(empty($val['checked']) ? '' : ' checked="checked"').'/><label for="checkbox'.$key.'">'.dol_escape_htmltag($langs->trans($val['label'])).'</label></li>'; |
||
| 6536 | $listcheckedstring .= (empty($val['checked']) ? '' : $key.','); |
||
| 6537 | } |
||
| 6538 | } |
||
| 6539 | |||
| 6540 | $out = '<!-- Component multiSelectArrayWithCheckbox '.$htmlname.' --> |
||
| 6541 | |||
| 6542 | <dl class="dropdown"> |
||
| 6543 | <dt> |
||
| 6544 | <a href="#'.$htmlname.'"> |
||
| 6545 | '.img_picto('', 'list').' |
||
| 6546 | </a> |
||
| 6547 | <input type="hidden" class="'.$htmlname.'" name="'.$htmlname.'" value="'.$listcheckedstring.'"> |
||
| 6548 | </dt> |
||
| 6549 | <dd class="dropdowndd"> |
||
| 6550 | <div class="multiselectcheckbox'.$htmlname.'"> |
||
| 6551 | <ul class="ul'.$htmlname.'"> |
||
| 6552 | '.$lis.' |
||
| 6553 | </ul> |
||
| 6554 | </div> |
||
| 6555 | </dd> |
||
| 6556 | </dl> |
||
| 6557 | |||
| 6558 | <script type="text/javascript"> |
||
| 6559 | jQuery(document).ready(function () { |
||
| 6560 | $(\'.multiselectcheckbox'.$htmlname.' input[type="checkbox"]\').on(\'click\', function () { |
||
| 6561 | console.log("A new field was added/removed, we edit field input[name=formfilteraction]"); |
||
| 6562 | |||
| 6563 | $("input:hidden[name=formfilteraction]").val(\'listafterchangingselectedfields\'); // Update field so we know we changed something on selected fields after POST |
||
| 6564 | |||
| 6565 | var title = $(this).val() + ","; |
||
| 6566 | if ($(this).is(\':checked\')) { |
||
| 6567 | $(\'.'.$htmlname.'\').val(title + $(\'.'.$htmlname.'\').val()); |
||
| 6568 | } |
||
| 6569 | else { |
||
| 6570 | $(\'.'.$htmlname.'\').val( $(\'.'.$htmlname.'\').val().replace(title, \'\') ) |
||
| 6571 | } |
||
| 6572 | // Now, we submit page |
||
| 6573 | //$(this).parents(\'form:first\').submit(); |
||
| 6574 | }); |
||
| 6575 | |||
| 6576 | |||
| 6577 | }); |
||
| 6578 | </script> |
||
| 6579 | |||
| 6580 | '; |
||
| 6581 | return $out; |
||
| 6582 | } |
||
| 6583 | |||
| 6584 | /** |
||
| 6585 | * Render list of categories linked to object with id $id and type $type |
||
| 6586 | * |
||
| 6587 | * @param int $id Id of object |
||
| 6588 | * @param string $type Type of category ('member', 'customer', 'supplier', 'product', 'contact'). Old mode (0, 1, 2, ...) is deprecated. |
||
| 6589 | * @param int $rendermode 0=Default, use multiselect. 1=Emulate multiselect (recommended) |
||
| 6590 | * @param int $nolink 1=Do not add html links |
||
| 6591 | * @return string String with categories |
||
| 6592 | */ |
||
| 6593 | public function showCategories($id, $type, $rendermode = 0, $nolink = 0) |
||
| 6594 | { |
||
| 6595 | global $db; |
||
| 6596 | |||
| 6597 | include_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; |
||
| 6598 | |||
| 6599 | $cat = new Categorie($db); |
||
| 6600 | $categories = $cat->containing($id, $type); |
||
| 6601 | |||
| 6602 | if ($rendermode == 1) |
||
| 6603 | { |
||
| 6604 | $toprint = array(); |
||
| 6605 | foreach ($categories as $c) |
||
| 6606 | { |
||
| 6607 | $ways = $c->print_all_ways(' >> ', ($nolink ? 'none' : ''), 0, 1); // $ways[0] = "ccc2 >> ccc2a >> ccc2a1" with html formated text |
||
| 6608 | foreach ($ways as $way) |
||
| 6609 | { |
||
| 6610 | $toprint[] = '<li class="select2-search-choice-dolibarr noborderoncategories"'.($c->color ? ' style="background: #'.$c->color.';"' : ' style="background: #aaa"').'>'.$way.'</li>'; |
||
| 6611 | } |
||
| 6612 | } |
||
| 6613 | return '<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">'.implode(' ', $toprint).'</ul></div>'; |
||
| 6614 | } |
||
| 6615 | |||
| 6616 | if ($rendermode == 0) |
||
| 6617 | { |
||
| 6618 | $arrayselected = array(); |
||
| 6619 | $cate_arbo = $this->select_all_categories($type, '', 'parent', 64, 0, 1); |
||
| 6620 | foreach ($categories as $c) { |
||
| 6621 | $arrayselected[] = $c->id; |
||
| 6622 | } |
||
| 6623 | |||
| 6624 | return $this->multiselectarray('categories', $cate_arbo, $arrayselected, '', 0, '', 0, '100%', 'disabled', 'category'); |
||
| 6625 | } |
||
| 6626 | |||
| 6627 | return 'ErrorBadValueForParameterRenderMode'; // Should not happened |
||
| 6628 | } |
||
| 6629 | |||
| 6630 | /** |
||
| 6631 | * Show linked object block. |
||
| 6632 | * |
||
| 6633 | * @param CommonObject $object Object we want to show links to |
||
| 6634 | * @param string $morehtmlright More html to show on right of title |
||
| 6635 | * @param array $compatibleImportElementsList Array of compatibles elements object for "import from" action |
||
| 6636 | * @return int <0 if KO, >=0 if OK |
||
| 6637 | */ |
||
| 6638 | public function showLinkedObjectBlock($object, $morehtmlright = '', $compatibleImportElementsList = false) |
||
| 6639 | { |
||
| 6640 | global $conf, $langs, $hookmanager; |
||
| 6641 | global $bc, $action; |
||
| 6642 | |||
| 6643 | $object->fetchObjectLinked(); |
||
| 6644 | |||
| 6645 | // Bypass the default method |
||
| 6646 | $hookmanager->initHooks(array('commonobject')); |
||
| 6647 | $parameters = array( |
||
| 6648 | 'morehtmlright' => $morehtmlright, |
||
| 6649 | 'compatibleImportElementsList' => &$compatibleImportElementsList, |
||
| 6650 | ); |
||
| 6651 | $reshook = $hookmanager->executeHooks('showLinkedObjectBlock', $parameters, $object, $action); // Note that $action and $object may have been modified by hook |
||
| 6652 | |||
| 6653 | if (empty($reshook)) |
||
| 6654 | { |
||
| 6655 | $nbofdifferenttypes = count($object->linkedObjects); |
||
| 6656 | |||
| 6657 | print '<!-- showLinkedObjectBlock -->'; |
||
| 6658 | print load_fiche_titre($langs->trans('RelatedObjects'), $morehtmlright, '', 0, 0, 'showlinkedobjectblock'); |
||
| 6659 | |||
| 6660 | |||
| 6661 | print '<div class="div-table-responsive-no-min">'; |
||
| 6662 | print '<table class="noborder allwidth" data-block="showLinkedObject" data-element="'.$object->element.'" data-elementid="'.$object->id.'" >'; |
||
| 6663 | |||
| 6664 | print '<tr class="liste_titre">'; |
||
| 6665 | print '<td>'.$langs->trans("Type").'</td>'; |
||
| 6666 | print '<td>'.$langs->trans("Ref").'</td>'; |
||
| 6667 | print '<td class="center"></td>'; |
||
| 6668 | print '<td class="center">'.$langs->trans("Date").'</td>'; |
||
| 6669 | print '<td class="right">'.$langs->trans("AmountHTShort").'</td>'; |
||
| 6670 | print '<td class="right">'.$langs->trans("Status").'</td>'; |
||
| 6671 | print '<td></td>'; |
||
| 6672 | print '</tr>'; |
||
| 6673 | |||
| 6674 | $nboftypesoutput = 0; |
||
| 6675 | |||
| 6676 | foreach ($object->linkedObjects as $objecttype => $objects) |
||
| 6677 | { |
||
| 6678 | $tplpath = $element = $subelement = $objecttype; |
||
| 6679 | |||
| 6680 | // to display inport button on tpl |
||
| 6681 | $showImportButton = false; |
||
| 6682 | if (!empty($compatibleImportElementsList) && in_array($element, $compatibleImportElementsList)) { |
||
| 6683 | $showImportButton = true; |
||
| 6684 | } |
||
| 6685 | |||
| 6686 | $regs = array(); |
||
| 6687 | if ($objecttype != 'supplier_proposal' && preg_match('/^([^_]+)_([^_]+)/i', $objecttype, $regs)) |
||
| 6688 | { |
||
| 6689 | $element = $regs[1]; |
||
| 6690 | $subelement = $regs[2]; |
||
| 6691 | $tplpath = $element.'/'.$subelement; |
||
| 6692 | } |
||
| 6693 | $tplname = 'linkedobjectblock'; |
||
| 6694 | |||
| 6695 | // To work with non standard path |
||
| 6696 | if ($objecttype == 'facture') { |
||
| 6697 | $tplpath = 'compta/'.$element; |
||
| 6698 | if (empty($conf->facture->enabled)) continue; // Do not show if module disabled |
||
| 6699 | } elseif ($objecttype == 'facturerec') { |
||
| 6700 | $tplpath = 'compta/facture'; |
||
| 6701 | $tplname = 'linkedobjectblockForRec'; |
||
| 6702 | if (empty($conf->facture->enabled)) continue; // Do not show if module disabled |
||
| 6703 | } elseif ($objecttype == 'propal') { |
||
| 6704 | $tplpath = 'comm/'.$element; |
||
| 6705 | if (empty($conf->propal->enabled)) continue; // Do not show if module disabled |
||
| 6706 | } elseif ($objecttype == 'supplier_proposal') { |
||
| 6707 | if (empty($conf->supplier_proposal->enabled)) continue; // Do not show if module disabled |
||
| 6708 | } elseif ($objecttype == 'shipping' || $objecttype == 'shipment') { |
||
| 6709 | $tplpath = 'expedition'; |
||
| 6710 | if (empty($conf->expedition->enabled)) continue; // Do not show if module disabled |
||
| 6711 | } elseif ($objecttype == 'reception') { |
||
| 6712 | $tplpath = 'reception'; |
||
| 6713 | if (empty($conf->reception->enabled)) continue; // Do not show if module disabled |
||
| 6714 | } elseif ($objecttype == 'delivery') { |
||
| 6715 | $tplpath = 'livraison'; |
||
| 6716 | if (empty($conf->expedition->enabled)) continue; // Do not show if module disabled |
||
| 6717 | } elseif ($objecttype == 'invoice_supplier') { |
||
| 6718 | $tplpath = 'fourn/facture'; |
||
| 6719 | } elseif ($objecttype == 'order_supplier') { |
||
| 6720 | $tplpath = 'fourn/commande'; |
||
| 6721 | } elseif ($objecttype == 'expensereport') { |
||
| 6722 | $tplpath = 'expensereport'; |
||
| 6723 | } elseif ($objecttype == 'subscription') { |
||
| 6724 | $tplpath = 'adherents'; |
||
| 6725 | } |
||
| 6726 | |||
| 6727 | global $linkedObjectBlock; |
||
| 6728 | $linkedObjectBlock = $objects; |
||
| 6729 | |||
| 6730 | |||
| 6731 | // Output template part (modules that overwrite templates must declare this into descriptor) |
||
| 6732 | $dirtpls = array_merge($conf->modules_parts['tpl'], array('/'.$tplpath.'/tpl')); |
||
| 6733 | foreach ($dirtpls as $reldir) |
||
| 6734 | { |
||
| 6735 | if ($nboftypesoutput == ($nbofdifferenttypes - 1)) // No more type to show after |
||
| 6736 | { |
||
| 6737 | global $noMoreLinkedObjectBlockAfter; |
||
| 6738 | $noMoreLinkedObjectBlockAfter = 1; |
||
| 6739 | } |
||
| 6740 | |||
| 6741 | $res = @include dol_buildpath($reldir.'/'.$tplname.'.tpl.php'); |
||
| 6742 | if ($res) |
||
| 6743 | { |
||
| 6744 | $nboftypesoutput++; |
||
| 6745 | break; |
||
| 6746 | } |
||
| 6747 | } |
||
| 6748 | } |
||
| 6749 | |||
| 6750 | if (!$nboftypesoutput) |
||
| 6751 | { |
||
| 6752 | print '<tr><td class="impair opacitymedium" colspan="7">'.$langs->trans("None").'</td></tr>'; |
||
| 6753 | } |
||
| 6754 | |||
| 6755 | print '</table>'; |
||
| 6756 | |||
| 6757 | if (!empty($compatibleImportElementsList)) |
||
| 6758 | { |
||
| 6759 | $res = @include dol_buildpath('core/tpl/ajax/objectlinked_lineimport.tpl.php'); |
||
| 6760 | } |
||
| 6761 | |||
| 6762 | |||
| 6763 | print '</div>'; |
||
| 6764 | |||
| 6765 | return $nbofdifferenttypes; |
||
| 6766 | } |
||
| 6767 | } |
||
| 6768 | |||
| 6769 | /** |
||
| 6770 | * Show block with links to link to other objects. |
||
| 6771 | * |
||
| 6772 | * @param CommonObject $object Object we want to show links to |
||
| 6773 | * @param array $restrictlinksto Restrict links to some elements, for exemple array('order') or array('supplier_order'). null or array() if no restriction. |
||
| 6774 | * @param array $excludelinksto Do not show links of this type, for exemple array('order') or array('supplier_order'). null or array() if no exclusion. |
||
| 6775 | * @return string <0 if KO, >0 if OK |
||
| 6776 | */ |
||
| 6777 | public function showLinkToObjectBlock($object, $restrictlinksto = array(), $excludelinksto = array()) |
||
| 6778 | { |
||
| 6779 | global $conf, $langs, $hookmanager; |
||
| 6780 | global $bc, $action; |
||
| 6781 | |||
| 6782 | $linktoelem = ''; |
||
| 6783 | $linktoelemlist = ''; |
||
| 6784 | $listofidcompanytoscan = ''; |
||
| 6785 | |||
| 6786 | if (!is_object($object->thirdparty)) $object->fetch_thirdparty(); |
||
| 6787 | |||
| 6788 | $possiblelinks = array(); |
||
| 6789 | if (is_object($object->thirdparty) && !empty($object->thirdparty->id) && $object->thirdparty->id > 0) |
||
| 6790 | { |
||
| 6791 | $listofidcompanytoscan = $object->thirdparty->id; |
||
| 6792 | if (($object->thirdparty->parent > 0) && !empty($conf->global->THIRDPARTY_INCLUDE_PARENT_IN_LINKTO)) $listofidcompanytoscan .= ','.$object->thirdparty->parent; |
||
| 6793 | if (($object->fk_project > 0) && !empty($conf->global->THIRDPARTY_INCLUDE_PROJECT_THIRDPARY_IN_LINKTO)) |
||
| 6794 | { |
||
| 6795 | include_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; |
||
| 6796 | $tmpproject = new Project($this->db); |
||
| 6797 | $tmpproject->fetch($object->fk_project); |
||
| 6798 | if ($tmpproject->socid > 0 && ($tmpproject->socid != $object->thirdparty->id)) $listofidcompanytoscan .= ','.$tmpproject->socid; |
||
| 6799 | unset($tmpproject); |
||
| 6800 | } |
||
| 6801 | |||
| 6802 | $possiblelinks = array( |
||
| 6803 | 'propal'=>array('enabled'=>$conf->propal->enabled, 'perms'=>1, 'label'=>'LinkToProposal', 'sql'=>"SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref, t.ref_client, t.total_ht FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."propal as t WHERE t.fk_soc = s.rowid AND t.fk_soc IN (".$listofidcompanytoscan.') AND t.entity IN ('.getEntity('propal').')'), |
||
| 6804 | 'order'=>array('enabled'=>$conf->commande->enabled, 'perms'=>1, 'label'=>'LinkToOrder', 'sql'=>"SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref, t.ref_client, t.total_ht FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."commande as t WHERE t.fk_soc = s.rowid AND t.fk_soc IN (".$listofidcompanytoscan.') AND t.entity IN ('.getEntity('commande').')'), |
||
| 6805 | 'invoice'=>array('enabled'=>$conf->facture->enabled, 'perms'=>1, 'label'=>'LinkToInvoice', 'sql'=>"SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref, t.ref_client, t.total as total_ht FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."facture as t WHERE t.fk_soc = s.rowid AND t.fk_soc IN (".$listofidcompanytoscan.') AND t.entity IN ('.getEntity('invoice').')'), |
||
| 6806 | 'invoice_template'=>array('enabled'=>$conf->facture->enabled, 'perms'=>1, 'label'=>'LinkToTemplateInvoice', 'sql'=>"SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.titre as ref, t.total as total_ht FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."facture_rec as t WHERE t.fk_soc = s.rowid AND t.fk_soc IN (".$listofidcompanytoscan.') AND t.entity IN ('.getEntity('invoice').')'), |
||
| 6807 | 'contrat'=>array('enabled'=>$conf->contrat->enabled, 'perms'=>1, 'label'=>'LinkToContract', |
||
| 6808 | 'sql'=>"SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref, t.ref_customer as ref_client, t.ref_supplier, '' as total_ht FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."contrat as t WHERE t.fk_soc = s.rowid AND t.fk_soc IN (".$listofidcompanytoscan.') AND t.entity IN ('.getEntity('contract').')'), |
||
| 6809 | 'fichinter'=>array('enabled'=>$conf->ficheinter->enabled, 'perms'=>1, 'label'=>'LinkToIntervention', 'sql'=>"SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."fichinter as t WHERE t.fk_soc = s.rowid AND t.fk_soc IN (".$listofidcompanytoscan.') AND t.entity IN ('.getEntity('intervention').')'), |
||
| 6810 | 'supplier_proposal'=>array('enabled'=>$conf->supplier_proposal->enabled, 'perms'=>1, 'label'=>'LinkToSupplierProposal', 'sql'=>"SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref, '' as ref_supplier, t.total_ht FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."supplier_proposal as t WHERE t.fk_soc = s.rowid AND t.fk_soc IN (".$listofidcompanytoscan.') AND t.entity IN ('.getEntity('supplier_proposal').')'), |
||
| 6811 | 'order_supplier'=>array('enabled'=>$conf->supplier_order->enabled, 'perms'=>1, 'label'=>'LinkToSupplierOrder', 'sql'=>"SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref, t.ref_supplier, t.total_ht FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."commande_fournisseur as t WHERE t.fk_soc = s.rowid AND t.fk_soc IN (".$listofidcompanytoscan.') AND t.entity IN ('.getEntity('commande_fournisseur').')'), |
||
| 6812 | 'invoice_supplier'=>array('enabled'=>$conf->supplier_invoice->enabled, 'perms'=>1, 'label'=>'LinkToSupplierInvoice', 'sql'=>"SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref, t.ref_supplier, t.total_ht FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."facture_fourn as t WHERE t.fk_soc = s.rowid AND t.fk_soc IN (".$listofidcompanytoscan.') AND t.entity IN ('.getEntity('facture_fourn').')'), |
||
| 6813 | 'ticket'=>array('enabled'=>$conf->ticket->enabled, 'perms'=>1, 'label'=>'LinkToTicket', 'sql'=>"SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref, t.track_id, '0' as total_ht FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."ticket as t WHERE t.fk_soc = s.rowid AND t.fk_soc IN (".$listofidcompanytoscan.') AND t.entity IN ('.getEntity('ticket').')') |
||
| 6814 | ); |
||
| 6815 | } |
||
| 6816 | |||
| 6817 | // Can complete the possiblelink array |
||
| 6818 | $hookmanager->initHooks(array('commonobject')); |
||
| 6819 | $parameters = array('listofidcompanytoscan' => $listofidcompanytoscan); |
||
| 6820 | |||
| 6821 | if (!empty($listofidcompanytoscan)) // If empty, we don't have criteria to scan the object we can link to |
||
| 6822 | { |
||
| 6823 | $reshook = $hookmanager->executeHooks('showLinkToObjectBlock', $parameters, $object, $action); // Note that $action and $object may have been modified by hook |
||
| 6824 | } |
||
| 6825 | |||
| 6826 | if (empty($reshook)) |
||
| 6827 | { |
||
| 6828 | if (is_array($hookmanager->resArray) && count($hookmanager->resArray)) |
||
| 6829 | { |
||
| 6830 | $possiblelinks = array_merge($possiblelinks, $hookmanager->resArray); |
||
| 6831 | } |
||
| 6832 | } elseif ($reshook > 0) |
||
| 6833 | { |
||
| 6834 | if (is_array($hookmanager->resArray) && count($hookmanager->resArray)) |
||
| 6835 | { |
||
| 6836 | $possiblelinks = $hookmanager->resArray; |
||
| 6837 | } |
||
| 6838 | } |
||
| 6839 | |||
| 6840 | foreach ($possiblelinks as $key => $possiblelink) |
||
| 6841 | { |
||
| 6842 | $num = 0; |
||
| 6843 | |||
| 6844 | if (empty($possiblelink['enabled'])) continue; |
||
| 6845 | |||
| 6846 | if (!empty($possiblelink['perms']) && (empty($restrictlinksto) || in_array($key, $restrictlinksto)) && (empty($excludelinksto) || !in_array($key, $excludelinksto))) |
||
| 6847 | { |
||
| 6848 | print '<div id="'.$key.'list"'.(empty($conf->use_javascript_ajax) ? '' : ' style="display:none"').'>'; |
||
| 6849 | $sql = $possiblelink['sql']; |
||
| 6850 | |||
| 6851 | $resqllist = $this->db->query($sql); |
||
| 6852 | if ($resqllist) |
||
| 6853 | { |
||
| 6854 | $num = $this->db->num_rows($resqllist); |
||
| 6855 | $i = 0; |
||
| 6856 | |||
| 6857 | print '<br>'; |
||
| 6858 | print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST" name="formlinked'.$key.'">'; |
||
| 6859 | print '<input type="hidden" name="action" value="addlink">'; |
||
| 6860 | print '<input type="hidden" name="token" value="'.newToken().'">'; |
||
| 6861 | print '<input type="hidden" name="id" value="'.$object->id.'">'; |
||
| 6862 | print '<input type="hidden" name="addlink" value="'.$key.'">'; |
||
| 6863 | print '<table class="noborder">'; |
||
| 6864 | print '<tr class="liste_titre">'; |
||
| 6865 | print '<td class="nowrap"></td>'; |
||
| 6866 | print '<td class="center">'.$langs->trans("Ref").'</td>'; |
||
| 6867 | print '<td class="left">'.$langs->trans("RefCustomer").'</td>'; |
||
| 6868 | print '<td class="right">'.$langs->trans("AmountHTShort").'</td>'; |
||
| 6869 | print '<td class="left">'.$langs->trans("Company").'</td>'; |
||
| 6870 | print '</tr>'; |
||
| 6871 | while ($i < $num) |
||
| 6872 | { |
||
| 6873 | $objp = $this->db->fetch_object($resqllist); |
||
| 6874 | |||
| 6875 | print '<tr class="oddeven">'; |
||
| 6876 | print '<td class="left">'; |
||
| 6877 | print '<input type="radio" name="idtolinkto" value='.$objp->rowid.'>'; |
||
| 6878 | print '</td>'; |
||
| 6879 | print '<td class="center">'.$objp->ref.'</td>'; |
||
| 6880 | print '<td>'.$objp->ref_client.'</td>'; |
||
| 6881 | print '<td class="right">'.price($objp->total_ht).'</td>'; |
||
| 6882 | print '<td>'.$objp->name.'</td>'; |
||
| 6883 | print '</tr>'; |
||
| 6884 | $i++; |
||
| 6885 | } |
||
| 6886 | print '</table>'; |
||
| 6887 | print '<div class="center"><input type="submit" class="button valignmiddle" value="'.$langs->trans('ToLink').'"> <input type="submit" class="button" name="cancel" value="'.$langs->trans('Cancel').'"></div>'; |
||
| 6888 | |||
| 6889 | print '</form>'; |
||
| 6890 | $this->db->free($resqllist); |
||
| 6891 | } else { |
||
| 6892 | dol_print_error($this->db); |
||
| 6893 | } |
||
| 6894 | print '</div>'; |
||
| 6895 | if ($num > 0) |
||
| 6896 | { |
||
| 6897 | } |
||
| 6898 | |||
| 6899 | //$linktoelem.=($linktoelem?' ':''); |
||
| 6900 | if ($num > 0) $linktoelemlist .= '<li><a href="#linkto'.$key.'" class="linkto dropdowncloseonclick" rel="'.$key.'">'.$langs->trans($possiblelink['label']).' ('.$num.')</a></li>'; |
||
| 6901 | //else $linktoelem.=$langs->trans($possiblelink['label']); |
||
| 6902 | else $linktoelemlist .= '<li><span class="linktodisabled">'.$langs->trans($possiblelink['label']).' (0)</span></li>'; |
||
| 6903 | } |
||
| 6904 | } |
||
| 6905 | |||
| 6906 | if ($linktoelemlist) |
||
| 6907 | { |
||
| 6908 | $linktoelem = ' |
||
| 6909 | <dl class="dropdown" id="linktoobjectname"> |
||
| 6910 | '; |
||
| 6911 | if (!empty($conf->use_javascript_ajax)) $linktoelem .= '<dt><a href="#linktoobjectname">'.$langs->trans("LinkTo").'...</a></dt>'; |
||
| 6912 | $linktoelem .= '<dd> |
||
| 6913 | <div class="multiselectlinkto"> |
||
| 6914 | <ul class="ulselectedfields">'.$linktoelemlist.' |
||
| 6915 | </ul> |
||
| 6916 | </div> |
||
| 6917 | </dd> |
||
| 6918 | </dl>'; |
||
| 6919 | } else { |
||
| 6920 | $linktoelem = ''; |
||
| 6921 | } |
||
| 6922 | |||
| 6923 | if (!empty($conf->use_javascript_ajax)) |
||
| 6924 | { |
||
| 6925 | print '<!-- Add js to show linkto box --> |
||
| 6926 | <script> |
||
| 6927 | jQuery(document).ready(function() { |
||
| 6928 | jQuery(".linkto").click(function() { |
||
| 6929 | console.log("We choose to show/hide link for rel="+jQuery(this).attr(\'rel\')); |
||
| 6930 | jQuery("#"+jQuery(this).attr(\'rel\')+"list").toggle(); |
||
| 6931 | }); |
||
| 6932 | }); |
||
| 6933 | </script> |
||
| 6934 | '; |
||
| 6935 | } |
||
| 6936 | |||
| 6937 | return $linktoelem; |
||
| 6938 | } |
||
| 6939 | |||
| 6940 | /** |
||
| 6941 | * Return an html string with a select combo box to choose yes or no |
||
| 6942 | * |
||
| 6943 | * @param string $htmlname Name of html select field |
||
| 6944 | * @param string $value Pre-selected value |
||
| 6945 | * @param int $option 0 return yes/no, 1 return 1/0 |
||
| 6946 | * @param bool $disabled true or false |
||
| 6947 | * @param int $useempty 1=Add empty line |
||
| 6948 | * @return string See option |
||
| 6949 | */ |
||
| 6950 | public function selectyesno($htmlname, $value = '', $option = 0, $disabled = false, $useempty = 0) |
||
| 6951 | { |
||
| 6952 | global $langs; |
||
| 6953 | |||
| 6954 | $yes = "yes"; $no = "no"; |
||
| 6955 | if ($option) |
||
| 6956 | { |
||
| 6957 | $yes = "1"; |
||
| 6958 | $no = "0"; |
||
| 6959 | } |
||
| 6960 | |||
| 6961 | $disabled = ($disabled ? ' disabled' : ''); |
||
| 6962 | |||
| 6963 | $resultyesno = '<select class="flat width75" id="'.$htmlname.'" name="'.$htmlname.'"'.$disabled.'>'."\n"; |
||
| 6964 | if ($useempty) $resultyesno .= '<option value="-1"'.(($value < 0) ? ' selected' : '').'> </option>'."\n"; |
||
| 6965 | if (("$value" == 'yes') || ($value == 1)) |
||
| 6966 | { |
||
| 6967 | $resultyesno .= '<option value="'.$yes.'" selected>'.$langs->trans("Yes").'</option>'."\n"; |
||
| 6968 | $resultyesno .= '<option value="'.$no.'">'.$langs->trans("No").'</option>'."\n"; |
||
| 6969 | } else { |
||
| 6970 | $selected = (($useempty && $value != '0' && $value != 'no') ? '' : ' selected'); |
||
| 6971 | $resultyesno .= '<option value="'.$yes.'">'.$langs->trans("Yes").'</option>'."\n"; |
||
| 6972 | $resultyesno .= '<option value="'.$no.'"'.$selected.'>'.$langs->trans("No").'</option>'."\n"; |
||
| 6973 | } |
||
| 6974 | $resultyesno .= '</select>'."\n"; |
||
| 6975 | return $resultyesno; |
||
| 6976 | } |
||
| 6977 | |||
| 6978 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps |
||
| 6979 | /** |
||
| 6980 | * Return list of export templates |
||
| 6981 | * |
||
| 6982 | * @param string $selected Id modele pre-selectionne |
||
| 6983 | * @param string $htmlname Name of HTML select |
||
| 6984 | * @param string $type Type of searched templates |
||
| 6985 | * @param int $useempty Affiche valeur vide dans liste |
||
| 6986 | * @return void |
||
| 6987 | */ |
||
| 6988 | public function select_export_model($selected = '', $htmlname = 'exportmodelid', $type = '', $useempty = 0) |
||
| 6989 | { |
||
| 6990 | // phpcs:enable |
||
| 6991 | $sql = "SELECT rowid, label"; |
||
| 6992 | $sql .= " FROM ".MAIN_DB_PREFIX."export_model"; |
||
| 6993 | $sql .= " WHERE type = '".$type."'"; |
||
| 6994 | $sql .= " ORDER BY rowid"; |
||
| 6995 | $result = $this->db->query($sql); |
||
| 6996 | if ($result) |
||
| 6997 | { |
||
| 6998 | print '<select class="flat" id="select_'.$htmlname.'" name="'.$htmlname.'">'; |
||
| 6999 | if ($useempty) |
||
| 7000 | { |
||
| 7001 | print '<option value="-1"> </option>'; |
||
| 7002 | } |
||
| 7003 | |||
| 7004 | $num = $this->db->num_rows($result); |
||
| 7005 | $i = 0; |
||
| 7006 | while ($i < $num) |
||
| 7007 | { |
||
| 7008 | $obj = $this->db->fetch_object($result); |
||
| 7009 | if ($selected == $obj->rowid) |
||
| 7010 | { |
||
| 7011 | print '<option value="'.$obj->rowid.'" selected>'; |
||
| 7012 | } else { |
||
| 7013 | print '<option value="'.$obj->rowid.'">'; |
||
| 7014 | } |
||
| 7015 | print $obj->label; |
||
| 7016 | print '</option>'; |
||
| 7017 | $i++; |
||
| 7018 | } |
||
| 7019 | print "</select>"; |
||
| 7020 | } else { |
||
| 7021 | dol_print_error($this->db); |
||
| 7022 | } |
||
| 7023 | } |
||
| 7024 | |||
| 7025 | /** |
||
| 7026 | * Return a HTML area with the reference of object and a navigation bar for a business object |
||
| 7027 | * Note: To complete search with a particular filter on select, you can set $object->next_prev_filter set to define SQL criterias. |
||
| 7028 | * |
||
| 7029 | * @param object $object Object to show. |
||
| 7030 | * @param string $paramid Name of parameter to use to name the id into the URL next/previous link. |
||
| 7031 | * @param string $morehtml More html content to output just before the nav bar. |
||
| 7032 | * @param int $shownav Show Condition (navigation is shown if value is 1). |
||
| 7033 | * @param string $fieldid Name of field id into database to use for select next and previous (we make the select max and min on this field compared to $object->ref). Use 'none' to disable next/prev. |
||
| 7034 | * @param string $fieldref Name of field ref of object (object->ref) to show or 'none' to not show ref. |
||
| 7035 | * @param string $morehtmlref More html to show after ref. |
||
| 7036 | * @param string $moreparam More param to add in nav link url. Must start with '&...'. |
||
| 7037 | * @param int $nodbprefix Do not include DB prefix to forge table name. |
||
| 7038 | * @param string $morehtmlleft More html code to show before ref. |
||
| 7039 | * @param string $morehtmlstatus More html code to show under navigation arrows (status place). |
||
| 7040 | * @param string $morehtmlright More html code to show after ref. |
||
| 7041 | * @return string Portion HTML with ref + navigation buttons |
||
| 7042 | */ |
||
| 7043 | public function showrefnav($object, $paramid, $morehtml = '', $shownav = 1, $fieldid = 'rowid', $fieldref = 'ref', $morehtmlref = '', $moreparam = '', $nodbprefix = 0, $morehtmlleft = '', $morehtmlstatus = '', $morehtmlright = '') |
||
| 7044 | { |
||
| 7045 | global $langs, $conf, $hookmanager, $extralanguages; |
||
| 7046 | |||
| 7047 | $ret = ''; |
||
| 7048 | if (empty($fieldid)) $fieldid = 'rowid'; |
||
| 7049 | if (empty($fieldref)) $fieldref = 'ref'; |
||
| 7050 | |||
| 7051 | // Add where from hooks |
||
| 7052 | if (is_object($hookmanager)) |
||
| 7053 | { |
||
| 7054 | $parameters = array(); |
||
| 7055 | $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object); // Note that $action and $object may have been modified by hook |
||
| 7056 | $object->next_prev_filter .= $hookmanager->resPrint; |
||
| 7057 | } |
||
| 7058 | $previous_ref = $next_ref = ''; |
||
| 7059 | if ($shownav) |
||
| 7060 | { |
||
| 7061 | //print "paramid=$paramid,morehtml=$morehtml,shownav=$shownav,$fieldid,$fieldref,$morehtmlref,$moreparam"; |
||
| 7062 | $object->load_previous_next_ref((isset($object->next_prev_filter) ? $object->next_prev_filter : ''), $fieldid, $nodbprefix); |
||
| 7063 | |||
| 7064 | $navurl = $_SERVER["PHP_SELF"]; |
||
| 7065 | // Special case for project/task page |
||
| 7066 | if ($paramid == 'project_ref') |
||
| 7067 | { |
||
| 7068 | if (preg_match('/\/tasks\/(task|contact|note|document)\.php/', $navurl)) // TODO Remove this when nav with project_ref on task pages are ok |
||
| 7069 | { |
||
| 7070 | $navurl = preg_replace('/\/tasks\/(task|contact|time|note|document)\.php/', '/tasks.php', $navurl); |
||
| 7071 | $paramid = 'ref'; |
||
| 7072 | } |
||
| 7073 | } |
||
| 7074 | |||
| 7075 | // accesskey is for Windows or Linux: ALT + key for chrome, ALT + SHIFT + KEY for firefox |
||
| 7076 | // accesskey is for Mac: CTRL + key for all browsers |
||
| 7077 | $stringforfirstkey = $langs->trans("KeyboardShortcut"); |
||
| 7078 | if ($conf->browser->name == 'chrome') |
||
| 7079 | { |
||
| 7080 | $stringforfirstkey .= ' ALT +'; |
||
| 7081 | } elseif ($conf->browser->name == 'firefox') |
||
| 7082 | { |
||
| 7083 | $stringforfirstkey .= ' ALT + SHIFT +'; |
||
| 7084 | } else { |
||
| 7085 | $stringforfirstkey .= ' CTL +'; |
||
| 7086 | } |
||
| 7087 | |||
| 7088 | $previous_ref = $object->ref_previous ? '<a accesskey="p" title="'.$stringforfirstkey.' p" class="classfortooltip" href="'.$navurl.'?'.$paramid.'='.urlencode($object->ref_previous).$moreparam.'"><i class="fa fa-chevron-left"></i></a>' : '<span class="inactive"><i class="fa fa-chevron-left opacitymedium"></i></span>'; |
||
| 7089 | $next_ref = $object->ref_next ? '<a accesskey="n" title="'.$stringforfirstkey.' n" class="classfortooltip" href="'.$navurl.'?'.$paramid.'='.urlencode($object->ref_next).$moreparam.'"><i class="fa fa-chevron-right"></i></a>' : '<span class="inactive"><i class="fa fa-chevron-right opacitymedium"></i></span>'; |
||
| 7090 | } |
||
| 7091 | |||
| 7092 | //print "xx".$previous_ref."x".$next_ref; |
||
| 7093 | $ret .= '<!-- Start banner content --><div style="vertical-align: middle">'; |
||
| 7094 | |||
| 7095 | // Right part of banner |
||
| 7096 | if ($morehtmlright) $ret .= '<div class="inline-block floatleft">'.$morehtmlright.'</div>'; |
||
| 7097 | |||
| 7098 | if ($previous_ref || $next_ref || $morehtml) |
||
| 7099 | { |
||
| 7100 | $ret .= '<div class="pagination paginationref"><ul class="right">'; |
||
| 7101 | } |
||
| 7102 | if ($morehtml) |
||
| 7103 | { |
||
| 7104 | $ret .= '<li class="noborder litext">'.$morehtml.'</li>'; |
||
| 7105 | } |
||
| 7106 | if ($shownav && ($previous_ref || $next_ref)) |
||
| 7107 | { |
||
| 7108 | $ret .= '<li class="pagination">'.$previous_ref.'</li>'; |
||
| 7109 | $ret .= '<li class="pagination">'.$next_ref.'</li>'; |
||
| 7110 | } |
||
| 7111 | if ($previous_ref || $next_ref || $morehtml) |
||
| 7112 | { |
||
| 7113 | $ret .= '</ul></div>'; |
||
| 7114 | } |
||
| 7115 | |||
| 7116 | $parameters = array(); |
||
| 7117 | $reshook = $hookmanager->executeHooks('moreHtmlStatus', $parameters, $object); // Note that $action and $object may have been modified by hook |
||
| 7118 | if (empty($reshook)) $morehtmlstatus .= $hookmanager->resPrint; |
||
| 7119 | else $morehtmlstatus = $hookmanager->resPrint; |
||
| 7120 | if ($morehtmlstatus) $ret .= '<div class="statusref">'.$morehtmlstatus.'</div>'; |
||
| 7121 | |||
| 7122 | $parameters = array(); |
||
| 7123 | $reshook = $hookmanager->executeHooks('moreHtmlRef', $parameters, $object); // Note that $action and $object may have been modified by hook |
||
| 7124 | if (empty($reshook)) $morehtmlref .= $hookmanager->resPrint; |
||
| 7125 | elseif ($reshook > 0) $morehtmlref = $hookmanager->resPrint; |
||
| 7126 | |||
| 7127 | // Left part of banner |
||
| 7128 | if ($morehtmlleft) |
||
| 7129 | { |
||
| 7130 | if ($conf->browser->layout == 'phone') $ret .= '<!-- morehtmlleft --><div class="floatleft">'.$morehtmlleft.'</div>'; // class="center" to have photo in middle |
||
| 7131 | else $ret .= '<!-- morehtmlleft --><div class="inline-block floatleft">'.$morehtmlleft.'</div>'; |
||
| 7132 | } |
||
| 7133 | |||
| 7134 | //if ($conf->browser->layout == 'phone') $ret.='<div class="clearboth"></div>'; |
||
| 7135 | $ret .= '<div class="inline-block floatleft valignmiddle refid'.(($shownav && ($previous_ref || $next_ref)) ? ' refidpadding' : '').'">'; |
||
| 7136 | |||
| 7137 | // For thirdparty, contact, user, member, the ref is the id, so we show something else |
||
| 7138 | if ($object->element == 'societe') |
||
| 7139 | { |
||
| 7140 | $ret .= dol_htmlentities($object->name); |
||
| 7141 | |||
| 7142 | // List of extra languages |
||
| 7143 | $arrayoflangcode = array(); |
||
| 7144 | if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE)) $arrayoflangcode[] = $conf->global->PDF_USE_ALSO_LANGUAGE_CODE; |
||
| 7145 | |||
| 7146 | if (is_array($arrayoflangcode) && count($arrayoflangcode)) { |
||
| 7147 | if (!is_object($extralanguages)) { |
||
| 7148 | include_once DOL_DOCUMENT_ROOT.'/core/class/extralanguages.class.php'; |
||
| 7149 | $extralanguages = new ExtraLanguages($this->db); |
||
| 7150 | } |
||
| 7151 | $extralanguages->fetch_name_extralanguages('societe'); |
||
| 7152 | |||
| 7153 | if (!empty($extralanguages->attributes['societe']['name'])) |
||
| 7154 | { |
||
| 7155 | $object->fetchValuesForExtraLanguages(); |
||
| 7156 | |||
| 7157 | $htmltext = ''; |
||
| 7158 | // If there is extra languages |
||
| 7159 | foreach ($arrayoflangcode as $extralangcode) { |
||
| 7160 | $htmltext .= picto_from_langcode($extralangcode, 'class="pictoforlang paddingright"'); |
||
| 7161 | if ($object->array_languages['name'][$extralangcode]) { |
||
| 7162 | $htmltext .= $object->array_languages['name'][$extralangcode]; |
||
| 7163 | } else { |
||
| 7164 | $htmltext .= '<span class="opacitymedium">'.$langs->trans("SwitchInEditModeToAddTranslation").'</span>'; |
||
| 7165 | } |
||
| 7166 | } |
||
| 7167 | $ret .= '<!-- Show translations of name -->'."\n"; |
||
| 7168 | $ret .= $this->textwithpicto('', $htmltext, -1, 'language', 'opacitymedium paddingleft'); |
||
| 7169 | } |
||
| 7170 | } |
||
| 7171 | } elseif ($object->element == 'member') |
||
| 7172 | { |
||
| 7173 | $ret .= $object->ref.'<br>'; |
||
| 7174 | $fullname = $object->getFullName($langs); |
||
| 7175 | if ($object->morphy == 'mor' && $object->societe) { |
||
| 7176 | $ret .= dol_htmlentities($object->societe).((!empty($fullname) && $object->societe != $fullname) ? ' ('.dol_htmlentities($fullname).')' : ''); |
||
| 7177 | } else { |
||
| 7178 | $ret .= dol_htmlentities($fullname).((!empty($object->societe) && $object->societe != $fullname) ? ' ('.dol_htmlentities($object->societe).')' : ''); |
||
| 7179 | } |
||
| 7180 | } elseif (in_array($object->element, array('contact', 'user', 'usergroup'))) |
||
| 7181 | { |
||
| 7182 | $ret .= dol_htmlentities($object->getFullName($langs)); |
||
| 7183 | } elseif (in_array($object->element, array('action', 'agenda'))) |
||
| 7184 | { |
||
| 7185 | $ret .= $object->ref.'<br>'.$object->label; |
||
| 7186 | } elseif (in_array($object->element, array('adherent_type'))) |
||
| 7187 | { |
||
| 7188 | $ret .= $object->label; |
||
| 7189 | } elseif ($object->element == 'ecm_directories') |
||
| 7190 | { |
||
| 7191 | $ret .= ''; |
||
| 7192 | } elseif ($fieldref != 'none') |
||
| 7193 | { |
||
| 7194 | $ret .= dol_htmlentities($object->$fieldref); |
||
| 7195 | } |
||
| 7196 | |||
| 7197 | if ($morehtmlref) |
||
| 7198 | { |
||
| 7199 | // don't add a additional space, when "$morehtmlref" starts with a HTML div tag |
||
| 7200 | if (substr($morehtmlref, 0, 4) != '<div') |
||
| 7201 | { |
||
| 7202 | $ret .= ' '; |
||
| 7203 | } |
||
| 7204 | |||
| 7205 | $ret .= $morehtmlref; |
||
| 7206 | } |
||
| 7207 | |||
| 7208 | $ret .= '</div>'; |
||
| 7209 | |||
| 7210 | $ret .= '</div><!-- End banner content -->'; |
||
| 7211 | |||
| 7212 | return $ret; |
||
| 7213 | } |
||
| 7214 | |||
| 7215 | |||
| 7216 | /** |
||
| 7217 | * Return HTML code to output a barcode |
||
| 7218 | * |
||
| 7219 | * @param Object $object Object containing data to retrieve file name |
||
| 7220 | * @param int $width Width of photo |
||
| 7221 | * @return string HTML code to output barcode |
||
| 7222 | */ |
||
| 7223 | public function showbarcode(&$object, $width = 100) |
||
| 7224 | { |
||
| 7225 | global $conf; |
||
| 7226 | |||
| 7227 | //Check if barcode is filled in the card |
||
| 7228 | if (empty($object->barcode)) return ''; |
||
| 7229 | |||
| 7230 | // Complete object if not complete |
||
| 7231 | if (empty($object->barcode_type_code) || empty($object->barcode_type_coder)) |
||
| 7232 | { |
||
| 7233 | $result = $object->fetch_barcode(); |
||
| 7234 | //Check if fetch_barcode() failed |
||
| 7235 | if ($result < 1) return '<!-- ErrorFetchBarcode -->'; |
||
| 7236 | } |
||
| 7237 | |||
| 7238 | // Barcode image |
||
| 7239 | $url = DOL_URL_ROOT.'/viewimage.php?modulepart=barcode&generator='.urlencode($object->barcode_type_coder).'&code='.urlencode($object->barcode).'&encoding='.urlencode($object->barcode_type_code); |
||
| 7240 | $out = '<!-- url barcode = '.$url.' -->'; |
||
| 7241 | $out .= '<img src="'.$url.'">'; |
||
| 7242 | return $out; |
||
| 7243 | } |
||
| 7244 | |||
| 7245 | /** |
||
| 7246 | * Return HTML code to output a photo |
||
| 7247 | * |
||
| 7248 | * @param string $modulepart Key to define module concerned ('societe', 'userphoto', 'memberphoto') |
||
| 7249 | * @param object $object Object containing data to retrieve file name |
||
| 7250 | * @param int $width Width of photo |
||
| 7251 | * @param int $height Height of photo (auto if 0) |
||
| 7252 | * @param int $caneditfield Add edit fields |
||
| 7253 | * @param string $cssclass CSS name to use on img for photo |
||
| 7254 | * @param string $imagesize 'mini', 'small' or '' (original) |
||
| 7255 | * @param int $addlinktofullsize Add link to fullsize image |
||
| 7256 | * @param int $cache 1=Accept to use image in cache |
||
| 7257 | * @param string $forcecapture Force parameter capture on HTML input file element to ask a smartphone to allow to open camera to take photo. Auto if empty. |
||
| 7258 | * @return string HTML code to output photo |
||
| 7259 | */ |
||
| 7260 | public static function showphoto($modulepart, $object, $width = 100, $height = 0, $caneditfield = 0, $cssclass = 'photowithmargin', $imagesize = '', $addlinktofullsize = 1, $cache = 0, $forcecapture = '') |
||
| 7261 | { |
||
| 7262 | global $conf, $langs; |
||
| 7263 | |||
| 7264 | $entity = (!empty($object->entity) ? $object->entity : $conf->entity); |
||
| 7265 | $id = (!empty($object->id) ? $object->id : $object->rowid); |
||
| 7266 | |||
| 7267 | $ret = ''; $dir = ''; $file = ''; $originalfile = ''; $altfile = ''; $email = ''; $capture = ''; |
||
| 7268 | if ($modulepart == 'societe') |
||
| 7269 | { |
||
| 7270 | $dir = $conf->societe->multidir_output[$entity]; |
||
| 7271 | if (!empty($object->logo)) |
||
| 7272 | { |
||
| 7273 | if ((string) $imagesize == 'mini') $file = get_exdir(0, 0, 0, 0, $object, 'thirdparty').'/logos/'.getImageFileNameForSize($object->logo, '_mini'); // getImageFileNameForSize include the thumbs |
||
| 7274 | elseif ((string) $imagesize == 'small') $file = get_exdir(0, 0, 0, 0, $object, 'thirdparty').'/logos/'.getImageFileNameForSize($object->logo, '_small'); |
||
| 7275 | else $file = get_exdir(0, 0, 0, 0, $object, 'thirdparty').'/logos/'.$object->logo; |
||
| 7276 | $originalfile = get_exdir(0, 0, 0, 0, $object, 'thirdparty').'/logos/'.$object->logo; |
||
| 7277 | } |
||
| 7278 | $email = $object->email; |
||
| 7279 | } elseif ($modulepart == 'contact') |
||
| 7280 | { |
||
| 7281 | $dir = $conf->societe->multidir_output[$entity].'/contact'; |
||
| 7282 | if (!empty($object->photo)) |
||
| 7283 | { |
||
| 7284 | if ((string) $imagesize == 'mini') $file = get_exdir(0, 0, 0, 0, $object, 'contact').'/photos/'.getImageFileNameForSize($object->photo, '_mini'); |
||
| 7285 | elseif ((string) $imagesize == 'small') $file = get_exdir(0, 0, 0, 0, $object, 'contact').'/photos/'.getImageFileNameForSize($object->photo, '_small'); |
||
| 7286 | else $file = get_exdir(0, 0, 0, 0, $object, 'contact').'/photos/'.$object->photo; |
||
| 7287 | $originalfile = get_exdir(0, 0, 0, 0, $object, 'contact').'/photos/'.$object->photo; |
||
| 7288 | } |
||
| 7289 | $email = $object->email; |
||
| 7290 | $capture = 'user'; |
||
| 7291 | } elseif ($modulepart == 'userphoto') |
||
| 7292 | { |
||
| 7293 | $dir = $conf->user->dir_output; |
||
| 7294 | if (!empty($object->photo)) |
||
| 7295 | { |
||
| 7296 | if ((string) $imagesize == 'mini') $file = get_exdir(0, 0, 0, 0, $object, 'user').$object->id.'/'.getImageFileNameForSize($object->photo, '_mini'); |
||
| 7297 | elseif ((string) $imagesize == 'small') $file = get_exdir(0, 0, 0, 0, $object, 'user').$object->id.'/'.getImageFileNameForSize($object->photo, '_small'); |
||
| 7298 | else $file = get_exdir(0, 0, 0, 0, $object, 'user').'/'.$object->id.'/'.$object->photo; |
||
| 7299 | $originalfile = get_exdir(0, 0, 0, 0, $object, 'user').'/'.$object->id.'/'.$object->photo; |
||
| 7300 | } |
||
| 7301 | if (!empty($conf->global->MAIN_OLD_IMAGE_LINKS)) $altfile = $object->id.".jpg"; // For backward compatibility |
||
| 7302 | $email = $object->email; |
||
| 7303 | $capture = 'user'; |
||
| 7304 | } elseif ($modulepart == 'memberphoto') |
||
| 7305 | { |
||
| 7306 | $dir = $conf->adherent->dir_output; |
||
| 7307 | if (!empty($object->photo)) |
||
| 7308 | { |
||
| 7309 | if ((string) $imagesize == 'mini') $file = get_exdir(0, 0, 0, 0, $object, 'member').'photos/'.getImageFileNameForSize($object->photo, '_mini'); |
||
| 7310 | elseif ((string) $imagesize == 'small') $file = get_exdir(0, 0, 0, 0, $object, 'member').'photos/'.getImageFileNameForSize($object->photo, '_small'); |
||
| 7311 | else $file = get_exdir(0, 0, 0, 0, $object, 'member').'photos/'.$object->photo; |
||
| 7312 | $originalfile = get_exdir(0, 0, 0, 0, $object, 'member').'photos/'.$object->photo; |
||
| 7313 | } |
||
| 7314 | if (!empty($conf->global->MAIN_OLD_IMAGE_LINKS)) $altfile = $object->id.".jpg"; // For backward compatibility |
||
| 7315 | $email = $object->email; |
||
| 7316 | $capture = 'user'; |
||
| 7317 | } else { |
||
| 7318 | // Generic case to show photos |
||
| 7319 | $dir = $conf->$modulepart->dir_output; |
||
| 7320 | if (!empty($object->photo)) |
||
| 7321 | { |
||
| 7322 | if ((string) $imagesize == 'mini') $file = get_exdir($id, 2, 0, 0, $object, $modulepart).'photos/'.getImageFileNameForSize($object->photo, '_mini'); |
||
| 7323 | elseif ((string) $imagesize == 'small') $file = get_exdir($id, 2, 0, 0, $object, $modulepart).'photos/'.getImageFileNameForSize($object->photo, '_small'); |
||
| 7324 | else $file = get_exdir($id, 2, 0, 0, $object, $modulepart).'photos/'.$object->photo; |
||
| 7325 | $originalfile = get_exdir($id, 2, 0, 0, $object, $modulepart).'photos/'.$object->photo; |
||
| 7326 | } |
||
| 7327 | if (!empty($conf->global->MAIN_OLD_IMAGE_LINKS)) $altfile = $object->id.".jpg"; // For backward compatibility |
||
| 7328 | $email = $object->email; |
||
| 7329 | } |
||
| 7330 | |||
| 7331 | if ($forcecapture) $capture = $forcecapture; |
||
| 7332 | |||
| 7333 | if ($dir) |
||
| 7334 | { |
||
| 7335 | if ($file && file_exists($dir."/".$file)) |
||
| 7336 | { |
||
| 7337 | if ($addlinktofullsize) |
||
| 7338 | { |
||
| 7339 | $urladvanced = getAdvancedPreviewUrl($modulepart, $originalfile, 0, '&entity='.$entity); |
||
| 7340 | if ($urladvanced) $ret .= '<a href="'.$urladvanced.'">'; |
||
| 7341 | else $ret .= '<a href="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.$entity.'&file='.urlencode($originalfile).'&cache='.$cache.'">'; |
||
| 7342 | } |
||
| 7343 | $ret .= '<img alt="Photo" class="photo'.$modulepart.($cssclass ? ' '.$cssclass : '').' photologo'.(preg_replace('/[^a-z]/i', '_', $file)).'" '.($width ? ' width="'.$width.'"' : '').($height ? ' height="'.$height.'"' : '').' src="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.$entity.'&file='.urlencode($file).'&cache='.$cache.'">'; |
||
| 7344 | if ($addlinktofullsize) $ret .= '</a>'; |
||
| 7345 | } elseif ($altfile && file_exists($dir."/".$altfile)) |
||
| 7346 | { |
||
| 7347 | if ($addlinktofullsize) |
||
| 7348 | { |
||
| 7349 | $urladvanced = getAdvancedPreviewUrl($modulepart, $originalfile, 0, '&entity='.$entity); |
||
| 7350 | if ($urladvanced) $ret .= '<a href="'.$urladvanced.'">'; |
||
| 7351 | else $ret .= '<a href="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.$entity.'&file='.urlencode($originalfile).'&cache='.$cache.'">'; |
||
| 7352 | } |
||
| 7353 | $ret .= '<img class="photo'.$modulepart.($cssclass ? ' '.$cssclass : '').'" alt="Photo alt" id="photologo'.(preg_replace('/[^a-z]/i', '_', $file)).'" class="'.$cssclass.'" '.($width ? ' width="'.$width.'"' : '').($height ? ' height="'.$height.'"' : '').' src="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.$entity.'&file='.urlencode($altfile).'&cache='.$cache.'">'; |
||
| 7354 | if ($addlinktofullsize) $ret .= '</a>'; |
||
| 7355 | } else { |
||
| 7356 | $nophoto = '/public/theme/common/nophoto.png'; |
||
| 7357 | if (in_array($modulepart, array('userphoto', 'contact', 'memberphoto'))) // For module that are "physical" users |
||
| 7358 | { |
||
| 7359 | if ($modulepart == 'memberphoto' && strpos($object->morphy, 'mor') !== false) { |
||
| 7360 | $nophoto = '/public/theme/common/company.png'; |
||
| 7361 | } else { |
||
| 7362 | $nophoto = '/public/theme/common/user_anonymous.png'; |
||
| 7363 | if ($object->gender == 'man') $nophoto = '/public/theme/common/user_man.png'; |
||
| 7364 | if ($object->gender == 'woman') $nophoto = '/public/theme/common/user_woman.png'; |
||
| 7365 | } |
||
| 7366 | } |
||
| 7367 | |||
| 7368 | if (!empty($conf->gravatar->enabled) && $email) |
||
| 7369 | { |
||
| 7370 | /** |
||
| 7371 | * @see https://gravatar.com/site/implement/images/php/ |
||
| 7372 | */ |
||
| 7373 | global $dolibarr_main_url_root; |
||
| 7374 | $ret .= '<!-- Put link to gravatar -->'; |
||
| 7375 | //$defaultimg=urlencode(dol_buildpath($nophoto,3)); |
||
| 7376 | $defaultimg = 'mm'; |
||
| 7377 | $ret .= '<img class="photo'.$modulepart.($cssclass ? ' '.$cssclass : '').'" alt="Gravatar avatar" title="'.$email.' Gravatar avatar" '.($width ? ' width="'.$width.'"' : '').($height ? ' height="'.$height.'"' : '').' src="https://www.gravatar.com/avatar/'.md5(strtolower(trim($email))).'?s='.$width.'&d='.$defaultimg.'">'; // gravatar need md5 hash |
||
| 7378 | } else { |
||
| 7379 | $ret .= '<img class="photo'.$modulepart.($cssclass ? ' '.$cssclass : '').'" alt="No photo" '.($width ? ' width="'.$width.'"' : '').($height ? ' height="'.$height.'"' : '').' src="'.DOL_URL_ROOT.$nophoto.'">'; |
||
| 7380 | } |
||
| 7381 | } |
||
| 7382 | |||
| 7383 | if ($caneditfield) |
||
| 7384 | { |
||
| 7385 | if ($object->photo) $ret .= "<br>\n"; |
||
| 7386 | $ret .= '<table class="nobordernopadding centpercent">'; |
||
| 7387 | if ($object->photo) $ret .= '<tr><td><input type="checkbox" class="flat photodelete" name="deletephoto" id="photodelete"> '.$langs->trans("Delete").'<br><br></td></tr>'; |
||
| 7388 | $ret .= '<tr><td class="tdoverflow"><input type="file" class="flat maxwidth200onsmartphone" name="photo" id="photoinput" accept="image/*"'.($capture ? ' capture="'.$capture.'"' : '').'></td></tr>'; |
||
| 7389 | $ret .= '</table>'; |
||
| 7390 | } |
||
| 7391 | } else dol_print_error('', 'Call of showphoto with wrong parameters modulepart='.$modulepart); |
||
| 7392 | |||
| 7393 | return $ret; |
||
| 7394 | } |
||
| 7395 | |||
| 7396 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps |
||
| 7397 | /** |
||
| 7398 | * Return select list of groups |
||
| 7399 | * |
||
| 7400 | * @param string $selected Id group preselected |
||
| 7401 | * @param string $htmlname Field name in form |
||
| 7402 | * @param int $show_empty 0=liste sans valeur nulle, 1=ajoute valeur inconnue |
||
| 7403 | * @param string $exclude Array list of groups id to exclude |
||
| 7404 | * @param int $disabled If select list must be disabled |
||
| 7405 | * @param string $include Array list of groups id to include |
||
| 7406 | * @param int $enableonly Array list of groups id to be enabled. All other must be disabled |
||
| 7407 | * @param string $force_entity '0' or Ids of environment to force |
||
| 7408 | * @param bool $multiple add [] in the name of element and add 'multiple' attribut (not working with ajax_autocompleter) |
||
| 7409 | * @param string $morecss More css to add to html component |
||
| 7410 | * @return string |
||
| 7411 | * @see select_dolusers() |
||
| 7412 | */ |
||
| 7413 | public function select_dolgroups($selected = '', $htmlname = 'groupid', $show_empty = 0, $exclude = '', $disabled = 0, $include = '', $enableonly = '', $force_entity = '0', $multiple = false, $morecss = '') |
||
| 7414 | { |
||
| 7415 | // phpcs:enable |
||
| 7416 | global $conf, $user, $langs; |
||
| 7417 | |||
| 7418 | // Permettre l'exclusion de groupes |
||
| 7419 | if (is_array($exclude)) $excludeGroups = implode("','", $exclude); |
||
| 7420 | // Permettre l'inclusion de groupes |
||
| 7421 | if (is_array($include)) $includeGroups = implode("','", $include); |
||
| 7422 | |||
| 7423 | if (!is_array($selected)) $selected = array($selected); |
||
| 7424 | |||
| 7425 | $out = ''; |
||
| 7426 | |||
| 7427 | // On recherche les groupes |
||
| 7428 | $sql = "SELECT ug.rowid, ug.nom as name"; |
||
| 7429 | if (!empty($conf->multicompany->enabled) && $conf->entity == 1 && $user->admin && !$user->entity) |
||
| 7430 | { |
||
| 7431 | $sql .= ", e.label"; |
||
| 7432 | } |
||
| 7433 | $sql .= " FROM ".MAIN_DB_PREFIX."usergroup as ug "; |
||
| 7434 | if (!empty($conf->multicompany->enabled) && $conf->entity == 1 && $user->admin && !$user->entity) |
||
| 7435 | { |
||
| 7436 | $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."entity as e ON e.rowid=ug.entity"; |
||
| 7437 | if ($force_entity) $sql .= " WHERE ug.entity IN (0,".$force_entity.")"; |
||
| 7438 | else $sql .= " WHERE ug.entity IS NOT NULL"; |
||
| 7439 | } else { |
||
| 7440 | $sql .= " WHERE ug.entity IN (0,".$conf->entity.")"; |
||
| 7441 | } |
||
| 7442 | if (is_array($exclude) && $excludeGroups) $sql .= " AND ug.rowid NOT IN ('".$excludeGroups."')"; |
||
| 7443 | if (is_array($include) && $includeGroups) $sql .= " AND ug.rowid IN ('".$includeGroups."')"; |
||
| 7444 | $sql .= " ORDER BY ug.nom ASC"; |
||
| 7445 | |||
| 7446 | dol_syslog(get_class($this)."::select_dolgroups", LOG_DEBUG); |
||
| 7447 | $resql = $this->db->query($sql); |
||
| 7448 | if ($resql) |
||
| 7449 | { |
||
| 7450 | // Enhance with select2 |
||
| 7451 | include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php'; |
||
| 7452 | $out .= ajax_combobox($htmlname); |
||
| 7453 | |||
| 7454 | $out .= '<select class="flat minwidth200'.($morecss ? ' '.$morecss : '').'" id="'.$htmlname.'" name="'.$htmlname.($multiple ? '[]' : '').'" '.($multiple ? 'multiple' : '').' '.($disabled ? ' disabled' : '').'>'; |
||
| 7455 | |||
| 7456 | $num = $this->db->num_rows($resql); |
||
| 7457 | $i = 0; |
||
| 7458 | if ($num) |
||
| 7459 | { |
||
| 7460 | if ($show_empty && !$multiple) $out .= '<option value="-1"'.(in_array(-1, $selected) ? ' selected' : '').'> </option>'."\n"; |
||
| 7461 | |||
| 7462 | while ($i < $num) |
||
| 7463 | { |
||
| 7464 | $obj = $this->db->fetch_object($resql); |
||
| 7465 | $disableline = 0; |
||
| 7466 | if (is_array($enableonly) && count($enableonly) && !in_array($obj->rowid, $enableonly)) $disableline = 1; |
||
| 7467 | |||
| 7468 | $out .= '<option value="'.$obj->rowid.'"'; |
||
| 7469 | if ($disableline) $out .= ' disabled'; |
||
| 7470 | if ((is_object($selected[0]) && $selected[0]->id == $obj->rowid) || (!is_object($selected[0]) && in_array($obj->rowid, $selected))) |
||
| 7471 | { |
||
| 7472 | $out .= ' selected'; |
||
| 7473 | } |
||
| 7474 | $out .= '>'; |
||
| 7475 | |||
| 7476 | $out .= $obj->name; |
||
| 7477 | if (!empty($conf->multicompany->enabled) && empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE) && $conf->entity == 1) |
||
| 7478 | { |
||
| 7479 | $out .= " (".$obj->label.")"; |
||
| 7480 | } |
||
| 7481 | |||
| 7482 | $out .= '</option>'; |
||
| 7483 | $i++; |
||
| 7484 | } |
||
| 7485 | } else { |
||
| 7486 | if ($show_empty) $out .= '<option value="-1"'.(in_array(-1, $selected) ? ' selected' : '').'></option>'."\n"; |
||
| 7487 | $out .= '<option value="" disabled>'.$langs->trans("NoUserGroupDefined").'</option>'; |
||
| 7488 | } |
||
| 7489 | $out .= '</select>'; |
||
| 7490 | } else { |
||
| 7491 | dol_print_error($this->db); |
||
| 7492 | } |
||
| 7493 | |||
| 7494 | return $out; |
||
| 7495 | } |
||
| 7496 | |||
| 7497 | |||
| 7498 | /** |
||
| 7499 | * Return HTML to show the search and clear seach button |
||
| 7500 | * |
||
| 7501 | * @return string |
||
| 7502 | */ |
||
| 7503 | public function showFilterButtons() |
||
| 7504 | { |
||
| 7505 | $out = '<div class="nowrap">'; |
||
| 7506 | $out .= '<button type="submit" class="liste_titre button_search" name="button_search_x" value="x"><span class="fa fa-search"></span></button>'; |
||
| 7507 | $out .= '<button type="submit" class="liste_titre button_removefilter" name="button_removefilter_x" value="x"><span class="fa fa-remove"></span></button>'; |
||
| 7508 | $out .= '</div>'; |
||
| 7509 | |||
| 7510 | return $out; |
||
| 7511 | } |
||
| 7512 | |||
| 7513 | /** |
||
| 7514 | * Return HTML to show the search and clear seach button |
||
| 7515 | * |
||
| 7516 | * @param string $cssclass CSS class |
||
| 7517 | * @param int $calljsfunction 0=default. 1=call function initCheckForSelect() after changing status of checkboxes |
||
| 7518 | * @param string $massactionname Mass action button name that will launch an action on the selected items |
||
| 7519 | * @return string |
||
| 7520 | */ |
||
| 7521 | public function showCheckAddButtons($cssclass = 'checkforaction', $calljsfunction = 0, $massactionname = "massaction") |
||
| 7522 | { |
||
| 7523 | global $conf, $langs; |
||
| 7524 | |||
| 7525 | $out = ''; |
||
| 7526 | $id = uniqid(); |
||
| 7527 | if (!empty($conf->use_javascript_ajax)) $out .= '<div class="inline-block checkallactions"><input type="checkbox" id="' . $cssclass . 's" name="' . $cssclass . 's" class="checkallactions"></div>'; |
||
| 7528 | $out .= '<script> |
||
| 7529 | $(document).ready(function() { |
||
| 7530 | $("#' . $cssclass . 's").click(function() { |
||
| 7531 | if($(this).is(\':checked\')){ |
||
| 7532 | console.log("We check all '.$cssclass.'"); |
||
| 7533 | $(".'.$cssclass.'").prop(\'checked\', true).trigger(\'change\'); |
||
| 7534 | } |
||
| 7535 | else |
||
| 7536 | { |
||
| 7537 | console.log("We uncheck all"); |
||
| 7538 | $(".'.$cssclass.'").prop(\'checked\', false).trigger(\'change\'); |
||
| 7539 | }'."\n"; |
||
| 7540 | if ($calljsfunction) $out .= 'if (typeof initCheckForSelect == \'function\') { initCheckForSelect(0, "' . $massactionname . '", "' . $cssclass . '"); } else { console.log("No function initCheckForSelect found. Call won\'t be done."); }'; |
||
| 7541 | $out .= ' }); |
||
| 7542 | |||
| 7543 | $(".' . $cssclass . '").change(function() { |
||
| 7544 | $(this).closest("tr").toggleClass("highlight", this.checked); |
||
| 7545 | }); |
||
| 7546 | |||
| 7547 | }); |
||
| 7548 | </script>'; |
||
| 7549 | |||
| 7550 | return $out; |
||
| 7551 | } |
||
| 7552 | |||
| 7553 | /** |
||
| 7554 | * Return HTML to show the search and clear seach button |
||
| 7555 | * |
||
| 7556 | * @param int $addcheckuncheckall Add the check all/uncheck all checkbox (use javascript) and code to manage this |
||
| 7557 | * @param string $cssclass CSS class |
||
| 7558 | * @param int $calljsfunction 0=default. 1=call function initCheckForSelect() after changing status of checkboxes |
||
| 7559 | * @param string $massactionname Mass action name |
||
| 7560 | * @return string |
||
| 7561 | */ |
||
| 7562 | public function showFilterAndCheckAddButtons($addcheckuncheckall = 0, $cssclass = 'checkforaction', $calljsfunction = 0, $massactionname = "massaction") |
||
| 7570 | } |
||
| 7571 | |||
| 7572 | /** |
||
| 7573 | * Return HTML to show the select of expense categories |
||
| 7574 | * |
||
| 7575 | * @param string $selected preselected category |
||
| 7576 | * @param string $htmlname name of HTML select list |
||
| 7577 | * @param integer $useempty 1=Add empty line |
||
| 7578 | * @param array $excludeid id to exclude |
||
| 7579 | * @param string $target htmlname of target select to bind event |
||
| 7580 | * @param int $default_selected default category to select if fk_c_type_fees change = EX_KME |
||
| 7581 | * @param array $params param to give |
||
| 7582 | * @return string |
||
| 7583 | */ |
||
| 7584 | public function selectExpenseCategories($selected = '', $htmlname = 'fk_c_exp_tax_cat', $useempty = 0, $excludeid = array(), $target = '', $default_selected = 0, $params = array()) |
||
| 7662 | } |
||
| 7663 | |||
| 7664 | /** |
||
| 7665 | * Return HTML to show the select ranges of expense range |
||
| 7666 | * |
||
| 7667 | * @param string $selected preselected category |
||
| 7668 | * @param string $htmlname name of HTML select list |
||
| 7669 | * @param integer $useempty 1=Add empty line |
||
| 7670 | * @return string |
||
| 7671 | */ |
||
| 7672 | public function selectExpenseRanges($selected = '', $htmlname = 'fk_range', $useempty = 0) |
||
| 7696 | } |
||
| 7697 | |||
| 7698 | /** |
||
| 7699 | * Return HTML to show a select of expense |
||
| 7700 | * |
||
| 7701 | * @param string $selected preselected category |
||
| 7702 | * @param string $htmlname name of HTML select list |
||
| 7703 | * @param integer $useempty 1=Add empty choice |
||
| 7704 | * @param integer $allchoice 1=Add all choice |
||
| 7705 | * @param integer $useid 0=use 'code' as key, 1=use 'id' as key |
||
| 7706 | * @return string |
||
| 7707 | */ |
||
| 7708 | public function selectExpense($selected = '', $htmlname = 'fk_c_type_fees', $useempty = 0, $allchoice = 1, $useid = 0) |
||
| 7709 | { |
||
| 7710 | global $db, $langs; |
||
| 7711 | |||
| 7712 | $out = ''; |
||
| 7713 | $sql = 'SELECT id, code, label FROM '.MAIN_DB_PREFIX.'c_type_fees'; |
||
| 7714 | $sql .= ' WHERE active = 1'; |
||
| 7715 | |||
| 7716 | $resql = $db->query($sql); |
||
| 7717 | if ($resql) |
||
| 7718 | { |
||
| 7719 | $out = '<select id="select_'.$htmlname.'" name="'.$htmlname.'" class="'.$htmlname.' flat minwidth75imp">'; |
||
| 7720 | if ($useempty) $out .= '<option value="0"></option>'; |
||
| 7721 | if ($allchoice) $out .= '<option value="-1">'.$langs->trans('AllExpenseReport').'</option>'; |
||
| 7722 | |||
| 7723 | $field = 'code'; |
||
| 7724 | if ($useid) $field = 'id'; |
||
| 7725 | |||
| 7726 | while ($obj = $db->fetch_object($resql)) |
||
| 7727 | { |
||
| 7728 | $key = $langs->trans($obj->code); |
||
| 7729 | $out .= '<option '.($selected == $obj->{$field} ? 'selected="selected"' : '').' value="'.$obj->{$field}.'">'.($key != $obj->code ? $key : $obj->label).'</option>'; |
||
| 7730 | } |
||
| 7731 | $out .= '</select>'; |
||
| 7732 | } else { |
||
| 7733 | dol_print_error($db); |
||
| 7734 | } |
||
| 7735 | |||
| 7736 | return $out; |
||
| 7737 | } |
||
| 7738 | |||
| 7739 | /** |
||
| 7740 | * Output a combo list with invoices qualified for a third party |
||
| 7741 | * |
||
| 7742 | * @param int $socid Id third party (-1=all, 0=only projects not linked to a third party, id=projects not linked or linked to third party id) |
||
| 7743 | * @param int $selected Id invoice preselected |
||
| 7744 | * @param string $htmlname Name of HTML select |
||
| 7745 | * @param int $maxlength Maximum length of label |
||
| 7746 | * @param int $option_only Return only html options lines without the select tag |
||
| 7747 | * @param string $show_empty Add an empty line ('1' or string to show for empty line) |
||
| 7748 | * @param int $discard_closed Discard closed projects (0=Keep,1=hide completely,2=Disable) |
||
| 7749 | * @param int $forcefocus Force focus on field (works with javascript only) |
||
| 7750 | * @param int $disabled Disabled |
||
| 7751 | * @param string $morecss More css added to the select component |
||
| 7752 | * @param string $projectsListId ''=Automatic filter on project allowed. List of id=Filter on project ids. |
||
| 7753 | * @param string $showproject 'all' = Show project info, ''=Hide project info |
||
| 7754 | * @param User $usertofilter User object to use for filtering |
||
| 7755 | * @return int Nbr of project if OK, <0 if KO |
||
| 7756 | */ |
||
| 7757 | public function selectInvoice($socid = -1, $selected = '', $htmlname = 'invoiceid', $maxlength = 24, $option_only = 0, $show_empty = '1', $discard_closed = 0, $forcefocus = 0, $disabled = 0, $morecss = 'maxwidth500', $projectsListId = '', $showproject = 'all', $usertofilter = null) |
||
| 7758 | { |
||
| 7759 | global $user, $conf, $langs; |
||
| 7760 | |||
| 7761 | require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; |
||
| 7762 | |||
| 7763 | if (is_null($usertofilter)) |
||
| 7764 | { |
||
| 7765 | $usertofilter = $user; |
||
| 7766 | } |
||
| 7767 | |||
| 7768 | $out = ''; |
||
| 7769 | |||
| 7770 | $hideunselectables = false; |
||
| 7771 | if (!empty($conf->global->PROJECT_HIDE_UNSELECTABLES)) $hideunselectables = true; |
||
| 7772 | |||
| 7773 | if (empty($projectsListId)) |
||
| 7774 | { |
||
| 7775 | if (empty($usertofilter->rights->projet->all->lire)) |
||
| 7776 | { |
||
| 7777 | $projectstatic = new Project($this->db); |
||
| 7778 | $projectsListId = $projectstatic->getProjectsAuthorizedForUser($usertofilter, 0, 1); |
||
| 7779 | } |
||
| 7780 | } |
||
| 7781 | |||
| 7782 | // Search all projects |
||
| 7783 | $sql = 'SELECT f.rowid, f.ref as fref, "nolabel" as flabel, p.rowid as pid, f.ref, |
||
| 7784 | p.title, p.fk_soc, p.fk_statut, p.public,'; |
||
| 7785 | $sql .= ' s.nom as name'; |
||
| 7786 | $sql .= ' FROM '.MAIN_DB_PREFIX.'projet as p'; |
||
| 7787 | $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe as s ON s.rowid = p.fk_soc,'; |
||
| 7788 | $sql .= ' '.MAIN_DB_PREFIX.'facture as f'; |
||
| 7789 | $sql .= " WHERE p.entity IN (".getEntity('project').")"; |
||
| 7790 | $sql .= " AND f.fk_projet = p.rowid AND f.fk_statut=0"; //Brouillons seulement |
||
| 7791 | //if ($projectsListId) $sql.= " AND p.rowid IN (".$projectsListId.")"; |
||
| 7792 | //if ($socid == 0) $sql.= " AND (p.fk_soc=0 OR p.fk_soc IS NULL)"; |
||
| 7793 | //if ($socid > 0) $sql.= " AND (p.fk_soc=".$socid." OR p.fk_soc IS NULL)"; |
||
| 7794 | $sql .= " GROUP BY f.ref ORDER BY p.ref, f.ref ASC"; |
||
| 7795 | |||
| 7796 | $resql = $this->db->query($sql); |
||
| 7797 | if ($resql) |
||
| 7798 | { |
||
| 7799 | // Use select2 selector |
||
| 7800 | if (!empty($conf->use_javascript_ajax)) |
||
| 7801 | { |
||
| 7802 | include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php'; |
||
| 7803 | $comboenhancement = ajax_combobox($htmlname, '', 0, $forcefocus); |
||
| 7804 | $out .= $comboenhancement; |
||
| 7805 | $morecss = 'minwidth200imp maxwidth500'; |
||
| 7806 | } |
||
| 7807 | |||
| 7808 | if (empty($option_only)) { |
||
| 7809 | $out .= '<select class="valignmiddle flat'.($morecss ? ' '.$morecss : '').'"'.($disabled ? ' disabled="disabled"' : '').' id="'.$htmlname.'" name="'.$htmlname.'">'; |
||
| 7810 | } |
||
| 7811 | if (!empty($show_empty)) { |
||
| 7812 | $out .= '<option value="0" class="optiongrey">'; |
||
| 7813 | if (!is_numeric($show_empty)) $out .= $show_empty; |
||
| 7814 | else $out .= ' '; |
||
| 7815 | $out .= '</option>'; |
||
| 7816 | } |
||
| 7817 | $num = $this->db->num_rows($resql); |
||
| 7818 | $i = 0; |
||
| 7819 | if ($num) |
||
| 7820 | { |
||
| 7821 | while ($i < $num) |
||
| 7822 | { |
||
| 7823 | $obj = $this->db->fetch_object($resql); |
||
| 7824 | // 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. |
||
| 7825 | if ($socid > 0 && (empty($obj->fk_soc) || $obj->fk_soc == $socid) && empty($usertofilter->rights->societe->lire)) |
||
| 7826 | { |
||
| 7827 | // Do nothing |
||
| 7828 | } else { |
||
| 7829 | if ($discard_closed == 1 && $obj->fk_statut == Project::STATUS_CLOSED) |
||
| 7830 | { |
||
| 7831 | $i++; |
||
| 7832 | continue; |
||
| 7833 | } |
||
| 7834 | |||
| 7835 | $labeltoshow = ''; |
||
| 7836 | |||
| 7837 | if ($showproject == 'all') |
||
| 7838 | { |
||
| 7839 | $labeltoshow .= dol_trunc($obj->ref, 18); // Invoice ref |
||
| 7840 | if ($obj->name) $labeltoshow .= ' - '.$obj->name; // Soc name |
||
| 7841 | |||
| 7842 | $disabled = 0; |
||
| 7843 | if ($obj->fk_statut == Project::STATUS_DRAFT) |
||
| 7844 | { |
||
| 7845 | $disabled = 1; |
||
| 7846 | $labeltoshow .= ' - '.$langs->trans("Draft"); |
||
| 7847 | } elseif ($obj->fk_statut == Project::STATUS_CLOSED) |
||
| 7848 | { |
||
| 7849 | if ($discard_closed == 2) $disabled = 1; |
||
| 7850 | $labeltoshow .= ' - '.$langs->trans("Closed"); |
||
| 7851 | } elseif ($socid > 0 && (!empty($obj->fk_soc) && $obj->fk_soc != $socid)) |
||
| 7852 | { |
||
| 7853 | $disabled = 1; |
||
| 7854 | $labeltoshow .= ' - '.$langs->trans("LinkedToAnotherCompany"); |
||
| 7855 | } |
||
| 7856 | } |
||
| 7857 | |||
| 7858 | if (!empty($selected) && $selected == $obj->rowid) |
||
| 7859 | { |
||
| 7860 | $out .= '<option value="'.$obj->rowid.'" selected'; |
||
| 7861 | //if ($disabled) $out.=' disabled'; // with select2, field can't be preselected if disabled |
||
| 7862 | $out .= '>'.$labeltoshow.'</option>'; |
||
| 7863 | } else { |
||
| 7864 | if ($hideunselectables && $disabled && ($selected != $obj->rowid)) |
||
| 7865 | { |
||
| 7866 | $resultat = ''; |
||
| 7867 | } else { |
||
| 7868 | $resultat = '<option value="'.$obj->rowid.'"'; |
||
| 7869 | if ($disabled) $resultat .= ' disabled'; |
||
| 7870 | //if ($obj->public) $labeltoshow.=' ('.$langs->trans("Public").')'; |
||
| 7871 | //else $labeltoshow.=' ('.$langs->trans("Private").')'; |
||
| 7872 | $resultat .= '>'; |
||
| 7873 | $resultat .= $labeltoshow; |
||
| 7874 | $resultat .= '</option>'; |
||
| 7875 | } |
||
| 7876 | $out .= $resultat; |
||
| 7877 | } |
||
| 7878 | } |
||
| 7879 | $i++; |
||
| 7880 | } |
||
| 7881 | } |
||
| 7882 | if (empty($option_only)) { |
||
| 7883 | $out .= '</select>'; |
||
| 7884 | } |
||
| 7885 | |||
| 7886 | print $out; |
||
| 7887 | |||
| 7888 | $this->db->free($resql); |
||
| 7889 | return $num; |
||
| 7890 | } else { |
||
| 7891 | dol_print_error($this->db); |
||
| 7892 | return -1; |
||
| 7893 | } |
||
| 7894 | } |
||
| 7895 | |||
| 7896 | /** |
||
| 7897 | * Output the component to make advanced search criteries |
||
| 7898 | * |
||
| 7899 | * @param array $arrayofcriterias Array of available search criterias. Example: array($object->element => $object->fields, 'otherfamily' => otherarrayoffields, ...) |
||
| 7900 | * @param array $search_component_params Array of selected search criterias |
||
| 7901 | * @param array $arrayofinputfieldsalreadyoutput Array of input fields already inform. The component will not generate a hidden input field if it is in this list. |
||
| 7902 | * @return string HTML component for advanced search |
||
| 7903 | */ |
||
| 7904 | public function searchComponent($arrayofcriterias, $search_component_params, $arrayofinputfieldsalreadyoutput = array()) |
||
| 7946 | } |
||
| 7947 | } |
||
| 7948 |