69  public $errors = array();
 
   76  public $cache_types_paiements = array();
 
   77  public $cache_conditions_paiements = array();
 
   78  public $cache_transport_mode = array();
 
   79  public $cache_availability = array();
 
   80  public $cache_demand_reason = array();
 
   81  public $cache_types_fees = array();
 
   82  public $cache_vatrates = array();
 
   83  public $cache_invoice_subtype = array();
 
  112  public function editfieldkey($text, $htmlname, $preselected, $object, $perm, $typeofdata = 
'string', $moreparam = 
'', $fieldrequired = 0, $notabletag = 0, $paramid = 
'id', $help = 
'')
 
  114    global $conf, $langs;
 
  119    if (
getDolGlobalString(
'MAIN_USE_JQUERY_JEDITABLE') && !preg_match(
'/^select;/', $typeofdata)) {
 
  121        $tmp = explode(
':', $typeofdata);
 
  122        $ret .= 
'<div class="editkey_' . $tmp[0] . (!empty($tmp[1]) ? 
' ' . $tmp[1] : 
'') . 
'" id="' . $htmlname . 
'">';
 
  123        if ($fieldrequired) {
 
  124          $ret .= 
'<span class="fieldrequired">';
 
  129          $ret .= $langs->trans($text);
 
  131        if ($fieldrequired) {
 
  134        $ret .= 
'</div>' . 
"\n";
 
  136        if ($fieldrequired) {
 
  137          $ret .= 
'<span class="fieldrequired">';
 
  142          $ret .= $langs->trans($text);
 
  144        if ($fieldrequired) {
 
  149      if (empty($notabletag) && $perm) {
 
  150        $ret .= 
'<table class="nobordernopadding centpercent"><tr><td class="nowrap">';
 
  152      if ($fieldrequired) {
 
  153        $ret .= 
'<span class="fieldrequired">';
 
  158        $ret .= $langs->trans($text);
 
  160      if ($fieldrequired) {
 
  163      if (!empty($notabletag)) {
 
  166      if (empty($notabletag) && $perm) {
 
  169      if (empty($notabletag) && $perm) {
 
  170        $ret .= 
'<td class="right">';
 
  172      if ($htmlname && 
GETPOST(
'action', 
'aZ09') != 
'edit' . $htmlname && $perm) {
 
  173        $ret .= 
'<a class="editfielda reposition" href="' . $_SERVER[
"PHP_SELF"] . 
'?action=edit' . $htmlname . 
'&token=' . newToken() . 
'&' . $paramid . 
'=' . $object->id . $moreparam . 
'">' . 
img_edit($langs->trans(
'Edit'), ($notabletag ? 0 : 1)) . 
'</a>';
 
  175      if (!empty($notabletag) && $notabletag == 1) {
 
  182      if (!empty($notabletag) && $notabletag == 3) {
 
  185      if (empty($notabletag) && $perm) {
 
  188      if (empty($notabletag) && $perm) {
 
  189        $ret .= 
'</tr></table>';
 
 
  219  public function editfieldval($text, $htmlname, $value, $object, $perm, $typeofdata = 
'string', $editvalue = 
'', $extObject = 
null, $custommsg = 
null, $moreparam = 
'', $notabletag = 1, $formatfunc = 
'', $paramid = 
'id', $gm = 
'auto', $moreoptions = array(), $editaction = 
'')
 
  221    global $conf, $langs;
 
  226    if (empty($typeofdata)) {
 
  227      return 'ErrorBadParameter typeofdata is empty';
 
  230    if ($typeofdata == 
'datetime') {
 
  231      $typeofdata = 
'dayhour';
 
  234    if (preg_match(
'/^(\w+)\((\d+)\)$/', $typeofdata, $reg)) {
 
  235      if ($reg[1] == 
'varchar') {
 
  236        $typeofdata = 
'string';
 
  237      } elseif ($reg[1] == 
'int') {
 
  238        $typeofdata = 
'numeric';
 
  240        return 'ErrorBadParameter ' . $typeofdata;
 
  245    if (
getDolGlobalString(
'MAIN_USE_JQUERY_JEDITABLE') && !preg_match(
'/^select;|day|datepicker|dayhour|datehourpicker/', $typeofdata)) { 
 
  246      $ret .= $this->
editInPlace($object, $value, $htmlname, $perm, $typeofdata, $editvalue, $extObject, $custommsg);
 
  248      if ($editaction == 
'') {
 
  249        $editaction = 
GETPOST(
'action', 
'aZ09');
 
  251      $editmode = ($editaction == 
'edit' . $htmlname);
 
  254        $ret .= 
'<form method="post" action="' . $_SERVER[
"PHP_SELF"] . ($moreparam ? 
'?' . $moreparam : 
'') . 
'">';
 
  255        $ret .= 
'<input type="hidden" name="action" value="set' . $htmlname . 
'">';
 
  256        $ret .= 
'<input type="hidden" name="token" value="' . newToken() . 
'">';
 
  257        $ret .= 
'<input type="hidden" name="' . $paramid . 
'" value="' . $object->id . 
'">';
 
  258        if (empty($notabletag)) {
 
  259          $ret .= 
'<table class="nobordernopadding centpercent">';
 
  261        if (empty($notabletag)) {
 
  264        if (preg_match(
'/^(string|safehtmlstring|email|phone|url)/', $typeofdata)) {
 
  265          $tmp = explode(
':', $typeofdata);
 
  266          $ret .= 
'<input type="text" id="' . $htmlname . 
'" name="' . $htmlname . 
'" value="' . ($editvalue ? $editvalue : $value) . 
'"' . (empty($tmp[1]) ? 
'' : 
' size="' . $tmp[1] . 
'"') . 
' autofocus>';
 
  267        } elseif (preg_match(
'/^(integer)/', $typeofdata)) {
 
  268          $tmp = explode(
':', $typeofdata);
 
  269          $valuetoshow = 
price2num($editvalue ? $editvalue : $value, 0);
 
  270          $ret .= 
'<input type="text" id="' . $htmlname . 
'" name="' . $htmlname . 
'" value="' . $valuetoshow . 
'"' . (empty($tmp[1]) ? 
'' : 
' size="' . $tmp[1] . 
'"') . 
' autofocus>';
 
  271        } elseif (preg_match(
'/^(numeric|amount)/', $typeofdata)) {
 
  272          $tmp = explode(
':', $typeofdata);
 
  273          $valuetoshow = 
price2num($editvalue ? $editvalue : $value);
 
  274          $ret .= 
'<input type="text" id="' . $htmlname . 
'" name="' . $htmlname . 
'" value="' . ($valuetoshow != 
'' ? 
price($valuetoshow) : 
'') . 
'"' . (empty($tmp[1]) ? 
'' : 
' size="' . $tmp[1] . 
'"') . 
' autofocus>';
 
  275        } elseif (preg_match(
'/^(checkbox)/', $typeofdata)) {
 
  276          $tmp = explode(
':', $typeofdata);
 
  277          $ret .= 
'<input type="checkbox" id="' . $htmlname . 
'" name="' . $htmlname . 
'" value="' . ($value ? $value : 
'on') . 
'"' . ($value ? 
' checked' : 
'') . (empty($tmp[1]) ? 
'' : $tmp[1]) . 
'/>';
 
  278        } elseif (preg_match(
'/^text/', $typeofdata) || preg_match(
'/^note/', $typeofdata)) {    
 
  279          $tmp = explode(
':', $typeofdata);
 
  280          $cols = (empty($tmp[2]) ? 
'' : $tmp[2]);
 
  282          if (preg_match(
'/%/', $cols)) {
 
  283            $morealt = 
' style="width: ' . $cols . 
'"';
 
  286          $valuetoshow = ($editvalue ? $editvalue : $value);
 
  287          $ret .= 
'<textarea id="' . $htmlname . 
'" name="' . $htmlname . 
'" wrap="soft" rows="' . (empty($tmp[1]) ? 
'20' : $tmp[1]) . 
'"' . ($cols ? 
' cols="' . $cols . 
'"' : 
'class="quatrevingtpercent"') . $morealt . 
'" autofocus>';
 
  290          $valuetoshow = str_replace(
'&', 
'&', $valuetoshow);
 
  292          $ret .= 
'</textarea>';
 
  293        } elseif ($typeofdata == 
'day' || $typeofdata == 
'datepicker') {
 
  294          $addnowlink = empty($moreoptions[
'addnowlink']) ? 0 : $moreoptions[
'addnowlink'];
 
  295          $adddateof = empty($moreoptions[
'adddateof']) ? 
'' : $moreoptions[
'adddateof'];
 
  296          $labeladddateof = empty($moreoptions[
'labeladddateof']) ? 
'' : $moreoptions[
'labeladddateof'];
 
  297          $ret .= $this->
selectDate($value, $htmlname, 0, 0, 1, 
'form' . $htmlname, 1, $addnowlink, 0, 
'', 
'', $adddateof, 
'', 1, $labeladddateof, 
'', $gm);
 
  298        } elseif ($typeofdata == 
'dayhour' || $typeofdata == 
'datehourpicker') {
 
  299          $addnowlink = empty($moreoptions[
'addnowlink']) ? 0 : $moreoptions[
'addnowlink'];
 
  300          $adddateof = empty($moreoptions[
'adddateof']) ? 
'' : $moreoptions[
'adddateof'];
 
  301          $labeladddateof = empty($moreoptions[
'labeladddateof']) ? 
'' : $moreoptions[
'labeladddateof'];
 
  302          $ret .= $this->
selectDate($value, $htmlname, 1, 1, 1, 
'form' . $htmlname, 1, $addnowlink, 0, 
'', 
'', $adddateof, 
'', 1, $labeladddateof, 
'', $gm);
 
  303        } elseif (preg_match(
'/^select;/', $typeofdata)) {
 
  304          $arraydata = explode(
',', preg_replace(
'/^select;/', 
'', $typeofdata));
 
  305          $arraylist = array();
 
  306          foreach ($arraydata as $val) {
 
  307            $tmp = explode(
':', $val);
 
  308            $tmpkey = str_replace(
'|', 
':', $tmp[0]);
 
  309            $arraylist[$tmpkey] = $tmp[1];
 
  311          $ret .= $this->
selectarray($htmlname, $arraylist, $value);
 
  312        } elseif (preg_match(
'/^link/', $typeofdata)) {
 
  314        } elseif (preg_match(
'/^ckeditor/', $typeofdata)) {
 
  315          $tmp = explode(
':', $typeofdata); 
 
  316          require_once DOL_DOCUMENT_ROOT . 
'/core/class/doleditor.class.php';
 
  317          $doleditor = 
new DolEditor($htmlname, ($editvalue ? $editvalue : $value), (empty($tmp[2]) ? 
'' : $tmp[2]), (empty($tmp[3]) ? 
'100' : $tmp[3]), (empty($tmp[1]) ? 
'dolibarr_notes' : $tmp[1]), 
'In', (empty($tmp[5]) ? 0 : $tmp[5]), (isset($tmp[8]) ? ($tmp[8] ? true : 
false) : 
true), 
true, (empty($tmp[6]) ? 
'20' : $tmp[6]), (empty($tmp[7]) ? 
'100' : $tmp[7]));
 
  318          $ret .= $doleditor->Create(1);
 
  319        } elseif ($typeofdata == 
'asis') {
 
  320          $ret .= ($editvalue ? $editvalue : $value);
 
  322        if (empty($notabletag)) {
 
  327        if (empty($notabletag)) {
 
  331        $ret .= 
'<input type="submit" class="smallpaddingimp button' . (empty($notabletag) ? 
'' : 
' ') . 
'" name="modify" value="' . $langs->trans(
"Modify") . 
'">';
 
  332        if (preg_match(
'/ckeditor|textarea/', $typeofdata) && empty($notabletag)) {
 
  333          $ret .= 
'<br>' . 
"\n";
 
  335        $ret .= 
'<input type="submit" class="smallpaddingimp button button-cancel' . (empty($notabletag) ? 
'' : 
' ') . 
'" name="cancel" value="' . $langs->trans(
"Cancel") . 
'">';
 
  336        if (empty($notabletag)) {
 
  340        if (empty($notabletag)) {
 
  341          $ret .= 
'</tr></table>' . 
"\n";
 
  343        $ret .= 
'</form>' . 
"\n";
 
  345        if (preg_match(
'/^email/', $typeofdata)) {
 
  347        } elseif (preg_match(
'/^phone/', $typeofdata)) {
 
  349        } elseif (preg_match(
'/^url/', $typeofdata)) {
 
  351        } elseif (preg_match(
'/^(amount|numeric)/', $typeofdata)) {
 
  352          $ret .= ($value != 
'' ? 
price($value, 
'', $langs, 0, -1, -1, $conf->currency) : 
'');
 
  353        } elseif (preg_match(
'/^checkbox/', $typeofdata)) {
 
  354          $tmp = explode(
':', $typeofdata);
 
  355          $ret .= 
'<input type="checkbox" disabled id="' . $htmlname . 
'" name="' . $htmlname . 
'" value="' . $value . 
'"' . ($value ? 
' checked' : 
'') . ($tmp[1] ? $tmp[1] : 
'') . 
'/>';
 
  356        } elseif (preg_match(
'/^text/', $typeofdata) || preg_match(
'/^note/', $typeofdata)) {
 
  358        } elseif (preg_match(
'/^(safehtmlstring|restricthtml)/', $typeofdata)) {  
 
  360        } elseif ($typeofdata == 
'day' || $typeofdata == 
'datepicker') {
 
  361          $ret .= 
'<span class="valuedate">' . 
dol_print_date($value, 
'day', $gm) . 
'</span>';
 
  362        } elseif ($typeofdata == 
'dayhour' || $typeofdata == 
'datehourpicker') {
 
  363          $ret .= 
'<span class="valuedate">' . 
dol_print_date($value, 
'dayhour', $gm) . 
'</span>';
 
  364        } elseif (preg_match(
'/^select;/', $typeofdata)) {
 
  365          $arraydata = explode(
',', preg_replace(
'/^select;/', 
'', $typeofdata));
 
  366          $arraylist = array();
 
  367          foreach ($arraydata as $val) {
 
  368            $tmp = explode(
':', $val);
 
  369            $arraylist[$tmp[0]] = $tmp[1];
 
  371          $ret .= $arraylist[$value];
 
  372          if ($htmlname == 
'fk_product_type') {
 
  374              $ret = 
img_picto($langs->trans(
"Product"), 
'product', 
'class="paddingleftonly paddingrightonly colorgrey"') . $ret;
 
  376              $ret = 
img_picto($langs->trans(
"Service"), 
'service', 
'class="paddingleftonly paddingrightonly colorgrey"') . $ret;
 
  379        } elseif (preg_match(
'/^ckeditor/', $typeofdata)) {
 
  382            $firstline = preg_replace(
'/<br>.*/', 
'', $tmpcontent);
 
  383            $firstline = preg_replace(
'/[\n\r].*/', 
'', $firstline);
 
  384            $tmpcontent = $firstline . ((strlen($firstline) != strlen($tmpcontent)) ? 
'...' : 
'');
 
  390          if (empty($moreoptions[
'valuealreadyhtmlescaped'])) {
 
  398        if ($formatfunc && method_exists($object, $formatfunc)) {
 
  399          $ret = $object->$formatfunc($ret);
 
 
  417  public function widgetForTranslation($fieldname, $object, $perm, $typeofdata = 
'string', $check = 
'', $morecss = 
'')
 
  419    global $conf, $langs, $extralanguages;
 
  424    $arrayoflangcode = array();
 
  426      $arrayoflangcode[] = $conf->global->PDF_USE_ALSO_LANGUAGE_CODE;
 
  429    if (is_array($arrayoflangcode) && count($arrayoflangcode)) {
 
  430      if (!is_object($extralanguages)) {
 
  431        include_once DOL_DOCUMENT_ROOT . 
'/core/class/extralanguages.class.php';
 
  434      $extralanguages->fetch_name_extralanguages(
'societe');
 
  436      if (!is_array($extralanguages->attributes[$object->element]) || empty($extralanguages->attributes[$object->element][$fieldname])) {
 
  440      $result .= 
'<!-- Widget for translation -->' . 
"\n";
 
  441      $result .= 
'<div class="inline-block paddingleft image-' . $object->element . 
'-' . $fieldname . 
'">';
 
  442      $s = 
img_picto($langs->trans(
"ShowOtherLanguages"), 
'language', 
'', 
false, 0, 0, 
'', 
'fa-15 editfieldlang');
 
  446      $result .= 
'<div class="inline-block hidden field-' . $object->element . 
'-' . $fieldname . 
'">';
 
  448      $resultforextrlang = 
'';
 
  449      foreach ($arrayoflangcode as $langcode) {
 
  450        $valuetoshow = GETPOSTISSET(
'field-' . $object->element . 
"-" . $fieldname . 
"-" . $langcode) ? 
GETPOST(
'field-' . $object->element . 
'-' . $fieldname . 
"-" . $langcode, $check) : 
'';
 
  451        if (empty($valuetoshow)) {
 
  452          $object->fetchValuesForExtraLanguages();
 
  454          $valuetoshow = $object->array_languages[$fieldname][$langcode];
 
  458        $resultforextrlang .= $s;
 
  461        if ($typeofdata == 
'textarea') {
 
  462          $resultforextrlang .= 
'<textarea name="field-' . $object->element . 
"-" . $fieldname . 
"-" . $langcode . 
'" id="' . $fieldname . 
"-" . $langcode . 
'" class="' . $morecss . 
'" rows="' . ROWS_2 . 
'" wrap="soft">';
 
  463          $resultforextrlang .= $valuetoshow;
 
  464          $resultforextrlang .= 
'</textarea>';
 
  466          $resultforextrlang .= 
'<input type="text" class="inputfieldforlang ' . ($morecss ? 
' ' . $morecss : 
'') . 
'" name="field-' . $object->element . 
'-' . $fieldname . 
'-' . $langcode . 
'" value="' . $valuetoshow . 
'">';
 
  469      $result .= $resultforextrlang;
 
  472      $result .= 
'<script nonce="' . 
getNonce() . 
'">$(".image-' . $object->element . 
'-' . $fieldname . 
'").click(function() { console.log("Toggle lang widget"); jQuery(".field-' . $object->element . 
'-' . $fieldname . 
'").toggle(); });</script>';
 
 
  491  protected function editInPlace($object, $value, $htmlname, $condition, $inputType = 
'textarea', $editvalue = 
null, $extObject = 
null, $custommsg = 
null)
 
  498    if (preg_match(
'/^text/', $inputType)) {
 
  500    } elseif (preg_match(
'/^numeric/', $inputType)) {
 
  501      $value = 
price($value);
 
  502    } elseif ($inputType == 
'day' || $inputType == 
'datepicker') {
 
  508      $table_element = 
false;
 
  512      $ext_element = 
false;
 
  513      $button_only = 
false;
 
  518      if (is_object($object)) {
 
  519        $element = $object->element;
 
  520        $table_element = $object->table_element;
 
  521        $fk_element = $object->id;
 
  524      if (is_object($extObject)) {
 
  525        $ext_element = $extObject->element;
 
  528      if (preg_match(
'/^(string|email|numeric)/', $inputType)) {
 
  529        $tmp = explode(
':', $inputType);
 
  530        $inputType = $tmp[0];
 
  531        if (!empty($tmp[1])) {
 
  532          $inputOption = $tmp[1];
 
  534        if (!empty($tmp[2])) {
 
  535          $savemethod = $tmp[2];
 
  537        $out .= 
'<input id="width_' . $htmlname . 
'" value="' . $inputOption . 
'" type="hidden"/>' . 
"\n";
 
  538      } elseif ((preg_match(
'/^day$/', $inputType)) || (preg_match(
'/^datepicker/', $inputType)) || (preg_match(
'/^datehourpicker/', $inputType))) {
 
  539        $tmp = explode(
':', $inputType);
 
  540        $inputType = $tmp[0];
 
  541        if (!empty($tmp[1])) {
 
  542          $inputOption = $tmp[1];
 
  544        if (!empty($tmp[2])) {
 
  545          $savemethod = $tmp[2];
 
  548        $out .= 
'<input id="timestamp" type="hidden"/>' . 
"\n"; 
 
  549      } elseif (preg_match(
'/^(select|autocomplete)/', $inputType)) {
 
  550        $tmp = explode(
':', $inputType);
 
  551        $inputType = $tmp[0];
 
  552        $loadmethod = $tmp[1];
 
  553        if (!empty($tmp[2])) {
 
  554          $savemethod = $tmp[2];
 
  556        if (!empty($tmp[3])) {
 
  559      } elseif (preg_match(
'/^textarea/', $inputType)) {
 
  560        $tmp = explode(
':', $inputType);
 
  561        $inputType = $tmp[0];
 
  562        $rows = (empty($tmp[1]) ? 
'8' : $tmp[1]);
 
  563        $cols = (empty($tmp[2]) ? 
'80' : $tmp[2]);
 
  564      } elseif (preg_match(
'/^ckeditor/', $inputType)) {
 
  565        $tmp = explode(
':', $inputType);
 
  566        $inputType = $tmp[0];
 
  568        if (!empty($tmp[2])) {
 
  571        if (!empty($tmp[3])) {
 
  574        if (!empty($tmp[4])) {
 
  575          $savemethod = $tmp[4];
 
  578        if (isModEnabled(
'fckeditor')) {
 
  579          $out .= 
'<input id="ckeditor_toolbar" value="' . $toolbar . 
'" type="hidden"/>' . 
"\n";
 
  581          $inputType = 
'textarea';
 
  585      $out .= 
'<input id="element_' . $htmlname . 
'" value="' . $element . 
'" type="hidden"/>' . 
"\n";
 
  586      $out .= 
'<input id="table_element_' . $htmlname . 
'" value="' . $table_element . 
'" type="hidden"/>' . 
"\n";
 
  587      $out .= 
'<input id="fk_element_' . $htmlname . 
'" value="' . $fk_element . 
'" type="hidden"/>' . 
"\n";
 
  588      $out .= 
'<input id="loadmethod_' . $htmlname . 
'" value="' . $loadmethod . 
'" type="hidden"/>' . 
"\n";
 
  589      if (!empty($savemethod)) {
 
  590        $out .= 
'<input id="savemethod_' . $htmlname . 
'" value="' . $savemethod . 
'" type="hidden"/>' . 
"\n";
 
  592      if (!empty($ext_element)) {
 
  593        $out .= 
'<input id="ext_element_' . $htmlname . 
'" value="' . $ext_element . 
'" type="hidden"/>' . 
"\n";
 
  595      if (!empty($custommsg)) {
 
  596        if (is_array($custommsg)) {
 
  597          if (!empty($custommsg[
'success'])) {
 
  598            $out .= 
'<input id="successmsg_' . $htmlname . 
'" value="' . $custommsg[
'success'] . 
'" type="hidden"/>' . 
"\n";
 
  600          if (!empty($custommsg[
'error'])) {
 
  601            $out .= 
'<input id="errormsg_' . $htmlname . 
'" value="' . $custommsg[
'error'] . 
'" type="hidden"/>' . 
"\n";
 
  604          $out .= 
'<input id="successmsg_' . $htmlname . 
'" value="' . $custommsg . 
'" type="hidden"/>' . 
"\n";
 
  607      if ($inputType == 
'textarea') {
 
  608        $out .= 
'<input id="textarea_' . $htmlname . 
'_rows" value="' . $rows . 
'" type="hidden"/>' . 
"\n";
 
  609        $out .= 
'<input id="textarea_' . $htmlname . 
'_cols" value="' . $cols . 
'" type="hidden"/>' . 
"\n";
 
  611      $out .= 
'<span id="viewval_' . $htmlname . 
'" class="viewval_' . $inputType . ($button_only ? 
' inactive' : 
' active') . 
'">' . $value . 
'</span>' . 
"\n";
 
  612      $out .= 
'<span id="editval_' . $htmlname . 
'" class="editval_' . $inputType . ($button_only ? 
' inactive' : 
' active') . 
' hideobject">' . (!empty($editvalue) ? $editvalue : $value) . 
'</span>' . 
"\n";
 
 
  638  public function textwithtooltip($text, $htmltext, $tooltipon = 1, $direction = 0, $img = 
'', $extracss = 
'', $notabs = 3, $incbefore = 
'', $noencodehtmltext = 0, $tooltiptrigger = 
'', $forcenowrap = 0)
 
  641      $text = $incbefore . $text;
 
  646    $direction = (int) $direction;    
 
  656    $htmltext = str_replace(array(
"\r", 
"\n"), 
'', $htmltext);
 
  659    if ($direction < 0) {
 
  660      $extracss = ($extracss ? $extracss . 
' ' : 
'') . ($notabs != 3 ? 
'inline-block' : 
'');
 
  661      $extrastyle = 
'padding: 0px; padding-left: 3px;';
 
  663    if ($direction > 0) {
 
  664      $extracss = ($extracss ? $extracss . 
' ' : 
'') . ($notabs != 3 ? 
'inline-block' : 
'');
 
  665      $extrastyle = 
'padding: 0px; padding-right: 3px;';
 
  668    $classfortooltip = 
'classfortooltip';
 
  673    if ($tooltiptrigger == 
'') {
 
  674      $htmltext = str_replace(
'"', 
'"', $htmltext);
 
  676      $classfortooltip = 
'classfortooltiponclick';
 
  677      $textfordialog .= 
'<div style="display: none;" id="idfortooltiponclick_' . $tooltiptrigger . 
'" class="classfortooltiponclicktext">' . $htmltext . 
'</div>';
 
  679    if ($tooltipon == 2 || $tooltipon == 3) {
 
  680      $paramfortooltipimg = 
' class="' . $classfortooltip . ($notabs != 3 ? 
' inline-block' : 
'') . ($extracss ? 
' ' . $extracss : 
'') . 
'" style="padding: 0px;' . ($extrastyle ? 
' ' . $extrastyle : 
'') . 
'"';
 
  681      if ($tooltiptrigger == 
'') {
 
  682        $paramfortooltipimg .= 
' title="' . ($noencodehtmltext ? $htmltext : 
dol_escape_htmltag($htmltext, 1)) . 
'"'; 
 
  684        $paramfortooltipimg .= 
' dolid="' . $tooltiptrigger . 
'"';
 
  687      $paramfortooltipimg = ($extracss ? 
' class="' . $extracss . 
'"' : 
'') . ($extrastyle ? 
' style="' . $extrastyle . 
'"' : 
''); 
 
  689    if ($tooltipon == 1 || $tooltipon == 3) {
 
  690      $paramfortooltiptd = 
' class="' . ($tooltipon == 3 ? 
'cursorpointer ' : 
'') . $classfortooltip . 
' inline-block' . ($extracss ? 
' ' . $extracss : 
'') . 
'" style="padding: 0px;' . ($extrastyle ? 
' ' . $extrastyle : 
'') . 
'" ';
 
  691      if ($tooltiptrigger == 
'') {
 
  692        $paramfortooltiptd .= 
' title="' . ($noencodehtmltext ? $htmltext : 
dol_escape_htmltag($htmltext, 1)) . 
'"'; 
 
  694        $paramfortooltiptd .= 
' dolid="' . $tooltiptrigger . 
'"';
 
  697      $paramfortooltiptd = ($extracss ? 
' class="' . $extracss . 
'"' : 
'') . ($extrastyle ? 
' style="' . $extrastyle . 
'"' : 
''); 
 
  699    if (empty($notabs)) {
 
  700      $s .= 
'<table class="nobordernopadding"><tr style="height: auto;">';
 
  701    } elseif ($notabs == 2) {
 
  702      $s .= 
'<div class="inline-block' . ($forcenowrap ? 
' nowrap' : 
'') . 
'">';
 
  705    if ($direction < 0) {
 
  706      $s .= 
'<' . $tag . $paramfortooltipimg;
 
  708        $s .= 
' class="valigntop" width="14"';
 
  710      $s .= 
'>' . $textfordialog . $img . 
'</' . $tag . 
'>';
 
  714    if ((
string) $text != 
'') {
 
  715      $s .= 
'<' . $tag . $paramfortooltiptd . 
'>' . $text . 
'</' . $tag . 
'>';
 
  718    if ($direction > 0) {
 
  719      $s .= 
'<' . $tag . $paramfortooltipimg;
 
  721        $s .= 
' class="valignmiddle" width="14"';
 
  723      $s .= 
'>' . $textfordialog . $img . 
'</' . $tag . 
'>';
 
  725    if (empty($notabs)) {
 
  726      $s .= 
'</tr></table>';
 
  727    } elseif ($notabs == 2) {
 
 
  748  public function textwithpicto($text, $htmltext, $direction = 1, $type = 
'help', $extracss = 
'', $noencodehtmltext = 0, $notabs = 3, $tooltiptrigger = 
'', $forcenowrap = 0)
 
  750    global $conf, $langs;
 
  755    } elseif ($type == 
'1') {
 
  759    $tooltiptrigger = preg_replace(
'/[^a-z0-9]/i', 
'', $tooltiptrigger);
 
  761    if (preg_match(
'/onsmartphone$/', $tooltiptrigger) && empty($conf->dol_no_mouse_hover)) {
 
  762      $tooltiptrigger = preg_replace(
'/^.*onsmartphone$/', 
'', $tooltiptrigger);
 
  765    if ($tooltiptrigger) {
 
  766      $alt = $langs->transnoentitiesnoconv(
"ClickToShowHelp");
 
  770    if (empty($conf->use_javascript_ajax)) {
 
  771      if ($type == 
'info' || $type == 
'infoclickable' || $type == 
'help' || $type == 
'helpclickable') {
 
  780    if (!empty($conf->dol_no_mouse_hover) && empty($tooltiptrigger)) {
 
  781      if ($type == 
'info' || $type == 
'infoclickable' || $type == 
'help' || $type == 
'helpclickable') {
 
  792    if ($type == 
'info') {
 
  794    } elseif ($type == 
'help') {
 
  795      $img = 
img_help(($tooltiptrigger != 
'' ? 2 : 1), $alt);
 
  796    } elseif ($type == 
'helpclickable') {
 
  797      $img = 
img_help(($tooltiptrigger != 
'' ? 2 : 1), $alt);
 
  798    } elseif ($type == 
'superadmin') {
 
  800    } elseif ($type == 
'admin') {
 
  802    } elseif ($type == 
'warning') {
 
  804    } elseif ($type != 
'none') {
 
  808    return $this->
textwithtooltip($text, $htmltext, ((($tooltiptrigger && !$img) || strpos($type, 
'clickable')) ? 3 : 2), $direction, $img, $extracss, $notabs, 
'', $noencodehtmltext, $tooltiptrigger, $forcenowrap);
 
 
  821  public function selectMassAction($selected, $arrayofaction, $alwaysvisible = 0, $name = 
'massaction', $cssclass = 
'checkforselect')
 
  823    global $conf, $langs, $hookmanager;
 
  826    $ret = 
'<div class="centpercent center">';
 
  827    $ret .= 
'<select class="flat' . (empty($conf->use_javascript_ajax) ? 
'' : 
' hideobject') . 
' ' . $name . 
' ' . $name . 
'select valignmiddle alignstart" id="' . $name . 
'" name="' . $name . 
'"' . ($disabled ? 
' disabled="disabled"' : 
'') . 
'>';
 
  830    $parameters = array();
 
  831    $reshook = $hookmanager->executeHooks(
'addMoreMassActions', $parameters); 
 
  834    if (is_array($arrayofaction) && count($arrayofaction) == 0 && empty($hookmanager->resPrint)) {
 
  837    if (empty($reshook)) {
 
  838      $ret .= 
'<option value="0"' . ($disabled ? 
' disabled="disabled"' : 
'') . 
'>-- ' . $langs->trans(
"SelectAction") . 
' --</option>';
 
  839      if (is_array($arrayofaction)) {
 
  840        foreach ($arrayofaction as $code => $label) {
 
  841          $ret .= 
'<option value="' . $code . 
'"' . ($disabled ? 
' disabled="disabled"' : 
'') . 
' data-html="' . 
dol_escape_htmltag($label) . 
'">' . $label . 
'</option>';
 
  845    $ret .= $hookmanager->resPrint;
 
  849    if (empty($conf->dol_optimize_smallscreen)) {
 
  854    $ret .= 
'<input type="submit" name="confirmmassactioninvisible" style="display: none" tabindex="-1">'; 
 
  855    $ret .= 
'<input type="submit" disabled name="confirmmassaction"' . (empty($conf->use_javascript_ajax) ? 
'' : 
' style="display: none"') . 
' class="reposition button smallpaddingimp' . (empty($conf->use_javascript_ajax) ? 
'' : 
' hideobject') . 
' ' . $name . 
' ' . $name . 
'confirmed" value="' . 
dol_escape_htmltag($langs->trans(
"Confirm")) . 
'">';
 
  858    if (!empty($conf->use_javascript_ajax)) {
 
  859      $ret .= 
'<!-- JS CODE TO ENABLE mass action select --> 
  861                        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 */ 
  863              atleastoneselected=0; 
  864                                jQuery("."+cssclass).each(function( index ) { 
  865                /* console.log( index + ": " + $( this ).text() ); */ 
  866                if ($(this).is(\':checked\')) atleastoneselected++; 
  869          console.log("initCheckForSelect mode="+mode+" name="+name+" cssclass="+cssclass+" atleastoneselected="+atleastoneselected); 
  871              if (atleastoneselected || ' . $alwaysvisible . 
') 
  873                                    jQuery("."+name).show(); 
  874                  ' . ($selected ? 
'if (atleastoneselected) { jQuery("."+name+"select").val("' . $selected . 
'").trigger(\'change\'); jQuery("."+name+"confirmed").prop(\'disabled\', false); }' : 
'') . 
' 
  875                  ' . ($selected ? 
'if (! atleastoneselected) { jQuery("."+name+"select").val("0").trigger(\'change\'); jQuery("."+name+"confirmed").prop(\'disabled\', true); } ' : 
'') . 
' 
  879                                    jQuery("."+name).hide(); 
  880                                    jQuery("."+name+"other").hide(); 
  884          jQuery(document).ready(function () { 
  885                    initCheckForSelect(0, "' . $name . 
'", "' . $cssclass . 
'"); 
  886                    jQuery(".' . $cssclass . 
'").click(function() { 
  887                        initCheckForSelect(1, "' . $name . 
'", "' . $cssclass . 
'"); 
  889                        jQuery(".' . $name . 
'select").change(function() { 
  890              var massaction = $( this ).val(); 
  891              var urlform = $( this ).closest("form").attr("action").replace("#show_files",""); 
  892              if (massaction == "builddoc") 
  894                        urlform = urlform + "#show_files"; 
  896              $( this ).closest("form").attr("action", urlform); 
  897                    console.log("we select a mass action name=' . $name . 
' massaction="+massaction+" - "+urlform); 
  898                  /* Warning: if you set submit button to disabled, post using Enter will no more work if there is no other button */ 
  899              if ($(this).val() != \'0\') 
  901                                        jQuery(".' . $name . 
'confirmed").prop(\'disabled\', false); 
  902                    jQuery(".' . $name . 
'other").hide(); /* To disable if another div was open */ 
  903                                        jQuery(".' . $name . 
'"+massaction).show(); 
  907                                        jQuery(".' . $name . 
'confirmed").prop(\'disabled\', true); 
  908                    jQuery(".' . $name . 
'other").hide(); /* To disable any div open */ 
 
  937  public function select_country($selected = 
'', $htmlname = 
'country_id', $htmloption = 
'', $maxlength = 0, $morecss = 
'minwidth300', $usecodeaskey = 
'', $showempty = 1, $disablefavorites = 0, $addspecialentries = 0, $exclude_country_code = array(), $hideflags = 0)
 
  940    global $conf, $langs, $mysoc;
 
  942    $langs->load(
"dict");
 
  945    $countryArray = array();
 
  948    $atleastonefavorite = 0;
 
  950    $sql = 
"SELECT rowid, code as code_iso, code_iso as code_iso3, label, favorite, eec";
 
  951    $sql .= 
" FROM " . $this->db->prefix() . 
"c_country";
 
  952    $sql .= 
" WHERE active > 0";
 
  955    dol_syslog(get_class($this) . 
"::select_country", LOG_DEBUG);
 
  956    $resql = $this->db->query($sql);
 
  958      $out .= 
'<select id="select' . $htmlname . 
'" class="flat maxwidth200onsmartphone selectcountry' . ($morecss ? 
' ' . $morecss : 
'') . 
'" name="' . $htmlname . 
'" ' . $htmloption . 
'>';
 
  959      $num = $this->db->num_rows($resql);
 
  963          $obj = $this->db->fetch_object($resql);
 
  965          $countryArray[$i][
'rowid'] = $obj->rowid;
 
  966          $countryArray[$i][
'code_iso'] = $obj->code_iso;
 
  967          $countryArray[$i][
'code_iso3'] = $obj->code_iso3;
 
  968          $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 : 
''));
 
  969          $countryArray[$i][
'favorite'] = $obj->favorite;
 
  970          $countryArray[$i][
'eec'] = $obj->eec;
 
  971          $favorite[$i] = $obj->favorite;
 
  976        if (empty($disablefavorites)) {
 
  977          $array1_sort_order = SORT_DESC;
 
  978          $array2_sort_order = SORT_ASC;
 
  979          array_multisort($favorite, $array1_sort_order, $label, $array2_sort_order, $countryArray);
 
  985          if (is_numeric($showempty)) {
 
  986            $out .= 
'<option value=""> </option>' . 
"\n";
 
  988            $out .= 
'<option value="-1">' . $langs->trans($showempty) . 
'</option>' . 
"\n";
 
  992        if ($addspecialentries) {    
 
  994          $out .= 
'<option value="special_allnotme"' . ($selected == 
'special_allnotme' ? 
' selected' : 
'') . 
'>' . $langs->trans(
"CountriesExceptMe", $langs->transnoentitiesnoconv(
"Country" . $mysoc->country_code)) . 
'</option>';
 
  995          $out .= 
'<option value="special_eec"' . ($selected == 
'special_eec' ? 
' selected' : 
'') . 
'>' . $langs->trans(
"CountriesInEEC") . 
'</option>';
 
  996          if ($mysoc->isInEEC()) {
 
  997            $out .= 
'<option value="special_eecnotme"' . ($selected == 
'special_eecnotme' ? 
' selected' : 
'') . 
'>' . $langs->trans(
"CountriesInEECExceptMe", $langs->transnoentitiesnoconv(
"Country" . $mysoc->country_code)) . 
'</option>';
 
  999          $out .= 
'<option value="special_noteec"' . ($selected == 
'special_noteec' ? 
' selected' : 
'') . 
'>' . $langs->trans(
"CountriesNotInEEC") . 
'</option>';
 
 1000          $out .= 
'<option value="" disabled class="selectoptiondisabledwhite">------------</option>';
 
 1003        foreach ($countryArray as $row) {
 
 1005          if (empty($row[
'rowid'])) {
 
 1008          if (is_array($exclude_country_code) && count($exclude_country_code) && in_array($row[
'code_iso'], $exclude_country_code)) {
 
 1012          if (empty($disablefavorites) && $row[
'favorite'] && $row[
'code_iso']) {
 
 1013            $atleastonefavorite++;
 
 1015          if (empty($row[
'favorite']) && $atleastonefavorite) {
 
 1016            $atleastonefavorite = 0;
 
 1017            $out .= 
'<option value="" disabled class="selectoptiondisabledwhite">------------</option>';
 
 1021          if ($row[
'label']) {
 
 1022            $labeltoshow .= 
dol_trunc($row[
'label'], $maxlength, 
'middle');
 
 1024            $labeltoshow .= 
' ';
 
 1026          if ($row[
'code_iso']) {
 
 1027            $labeltoshow .= 
' <span class="opacitymedium">(' . $row[
'code_iso'] . 
')</span>';
 
 1028            if (empty($hideflags)) {
 
 1029              $tmpflag = 
picto_from_langcode($row[
'code_iso'], 
'class="saturatemedium paddingrightonly"', 1);
 
 1030              $labeltoshow = $tmpflag . 
' ' . $labeltoshow;
 
 1034          if ($selected && $selected != 
'-1' && ($selected == $row[
'rowid'] || $selected == $row[
'code_iso'] || $selected == $row[
'code_iso3'] || $selected == $row[
'label'])) {
 
 1035            $out .= 
'<option value="' . ($usecodeaskey ? ($usecodeaskey == 
'code2' ? $row[
'code_iso'] : $row[
'code_iso3']) : $row[
'rowid']) . 
'" selected data-html="' . 
dol_escape_htmltag($labeltoshow) . 
'" data-eec="' . ((int) $row[
'eec']) . 
'">';
 
 1037            $out .= 
'<option value="' . ($usecodeaskey ? ($usecodeaskey == 
'code2' ? $row[
'code_iso'] : $row[
'code_iso3']) : $row[
'rowid']) . 
'" data-html="' . 
dol_escape_htmltag($labeltoshow) . 
'" data-eec="' . ((int) $row[
'eec']) . 
'">';
 
 1039          $out .= $labeltoshow;
 
 1040          $out .= 
'</option>' . 
"\n";
 
 1043      $out .= 
'</select>';
 
 1049    include_once DOL_DOCUMENT_ROOT . 
'/core/lib/ajax.lib.php';
 
 1050    $out .= 
ajax_combobox(
'select' . $htmlname, array(), 0, 0, 
'resolve');
 
 
 1070  public function select_incoterms($selected = 
'', $location_incoterms = 
'', $page = 
'', $htmlname = 
'incoterm_id', $htmloption = 
'', $forcecombo = 1, $events = array(), $disableautocomplete = 0)
 
 1073    global $conf, $langs;
 
 1075    $langs->load(
"dict");
 
 1079    $incotermArray = array();
 
 1081    $sql = 
"SELECT rowid, code";
 
 1082    $sql .= 
" FROM " . $this->db->prefix() . 
"c_incoterms";
 
 1083    $sql .= 
" WHERE active > 0";
 
 1084    $sql .= 
" ORDER BY code ASC";
 
 1086    dol_syslog(get_class($this) . 
"::select_incoterm", LOG_DEBUG);
 
 1087    $resql = $this->db->query($sql);
 
 1089      if ($conf->use_javascript_ajax && !$forcecombo) {
 
 1090        include_once DOL_DOCUMENT_ROOT . 
'/core/lib/ajax.lib.php';
 
 1094      if (!empty($page)) {
 
 1095        $out .= 
'<form method="post" action="' . $page . 
'">';
 
 1096        $out .= 
'<input type="hidden" name="action" value="set_incoterms">';
 
 1097        $out .= 
'<input type="hidden" name="token" value="' . newToken() . 
'">';
 
 1100      $out .= 
'<select id="' . $htmlname . 
'" class="flat selectincoterm width75" name="' . $htmlname . 
'" ' . $htmloption . 
'>';
 
 1101      $out .= 
'<option value="0"> </option>';
 
 1102      $num = $this->db->num_rows($resql);
 
 1106          $obj = $this->db->fetch_object($resql);
 
 1107          $incotermArray[$i][
'rowid'] = $obj->rowid;
 
 1108          $incotermArray[$i][
'code'] = $obj->code;
 
 1112        foreach ($incotermArray as $row) {
 
 1113          if ($selected && ($selected == $row[
'rowid'] || $selected == $row[
'code'])) {
 
 1114            $out .= 
'<option value="' . $row[
'rowid'] . 
'" selected>';
 
 1116            $out .= 
'<option value="' . $row[
'rowid'] . 
'">';
 
 1120            $out .= $row[
'code'];
 
 1123          $out .= 
'</option>';
 
 1126      $out .= 
'</select>';
 
 1128      if ($conf->use_javascript_ajax && empty($disableautocomplete)) {
 
 1129        $out .= 
ajax_multiautocompleter(
'location_incoterms', array(), DOL_URL_ROOT . 
'/core/ajax/locationincoterms.php') . 
"\n";
 
 1130        $moreattrib .= 
' autocomplete="off"';
 
 1132      $out .= 
'<input id="location_incoterms" class="maxwidthonsmartphone type="text" name="location_incoterms" value="' . $location_incoterms . 
'">' . 
"\n";
 
 1134      if (!empty($page)) {
 
 1135        $out .= 
'<input type="submit" class="button valignmiddle smallpaddingimp nomargintop nomarginbottom" value="' . $langs->trans(
"Modify") . 
'"></form>';
 
 
 1157  public function select_type_of_lines($selected = 
'', $htmlname = 
'type', $showempty = 0, $hidetext = 0, $forceall = 0)
 
 1163    if ($forceall == 1 || (empty($forceall) && isModEnabled(
"product") && isModEnabled(
"service"))
 
 1164      || (empty($forceall) && !isModEnabled(
'product') && !isModEnabled(
'service'))) {
 
 1165      if (empty($hidetext)) {
 
 1166        print $langs->trans(
"Type") . 
': ';
 
 1168      print 
'<select class="flat" id="select_' . $htmlname . 
'" name="' . $htmlname . 
'">';
 
 1170        print 
'<option value="-1"';
 
 1171        if ($selected == -1) {
 
 1174        print 
'> </option>';
 
 1177      print 
'<option value="0"';
 
 1178      if (0 == $selected || ($selected == -1 && 
getDolGlobalString(
'MAIN_FREE_PRODUCT_CHECKED_BY_DEFAULT') == 
'product')) {
 
 1181      print 
'>' . $langs->trans(
"Product");
 
 1183      print 
'<option value="1"';
 
 1184      if (1 == $selected || ($selected == -1 && 
getDolGlobalString(
'MAIN_FREE_PRODUCT_CHECKED_BY_DEFAULT') == 
'service')) {
 
 1187      print 
'>' . $langs->trans(
"Service");
 
 1193    if ((empty($forceall) && !isModEnabled(
'product') && isModEnabled(
"service")) || $forceall == 3) {
 
 1194      print $langs->trans(
"Service");
 
 1195      print 
'<input type="hidden" name="' . $htmlname . 
'" value="1">';
 
 1197    if ((empty($forceall) && isModEnabled(
"product") && !isModEnabled(
'service')) || $forceall == 2) {
 
 1198      print $langs->trans(
"Product");
 
 1199      print 
'<input type="hidden" name="' . $htmlname . 
'" value="0">';
 
 1201    if ($forceall < 0) {    
 
 1202      print 
'<input type="hidden" name="' . $htmlname . 
'" value="1">'; 
 
 
 1218    $num = count($this->cache_types_fees);
 
 1225    $langs->load(
"trips");
 
 1227    $sql = 
"SELECT c.code, c.label";
 
 1228    $sql .= 
" FROM " . $this->db->prefix() . 
"c_type_fees as c";
 
 1229    $sql .= 
" WHERE active > 0";
 
 1231    $resql = $this->db->query($sql);
 
 1233      $num = $this->db->num_rows($resql);
 
 1237        $obj = $this->db->fetch_object($resql);
 
 1240        $label = ($obj->code != $langs->trans($obj->code) ? $langs->trans($obj->code) : $langs->trans($obj->label));
 
 1241        $this->cache_types_fees[$obj->code] = $label;
 
 1245      asort($this->cache_types_fees);
 
 
 1267    global $user, $langs;
 
 1269    dol_syslog(__METHOD__ . 
" selected=" . $selected . 
", htmlname=" . $htmlname, LOG_DEBUG);
 
 1273    print 
'<select id="select_' . $htmlname . 
'" class="flat" name="' . $htmlname . 
'">';
 
 1275      print 
'<option value="-1"';
 
 1276      if ($selected == -1) {
 
 1279      print 
'> </option>';
 
 1282    foreach ($this->cache_types_fees as $key => $value) {
 
 1283      print 
'<option value="' . $key . 
'"';
 
 1284      if ($key == $selected) {
 
 1294      print 
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
 
 
 1322  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, $excludeids = array(), $showcode = 0)
 
 1325    global $conf, $user, $langs;
 
 1329    if (!empty($conf->use_javascript_ajax) && 
getDolGlobalString(
'COMPANY_USE_SEARCH_TO_SELECT') && !$forcecombo) {
 
 1330      if (is_null($ajaxoptions)) {
 
 1331        $ajaxoptions = array();
 
 1334      require_once DOL_DOCUMENT_ROOT . 
'/core/lib/ajax.lib.php';
 
 1338      if ($selected && empty($selected_input_value)) {
 
 1339        require_once DOL_DOCUMENT_ROOT . 
'/societe/class/societe.class.php';
 
 1340        $societetmp = 
new Societe($this->db);
 
 1341        $societetmp->fetch($selected);
 
 1342        $selected_input_value = $societetmp->name;
 
 1347      $urloption = 
'htmlname=' . urlencode(str_replace(
'.', 
'_', $htmlname)) . 
'&outjson=1&filter=' . urlencode($filter) . (empty($excludeids) ? 
'' : 
'&excludeids=' . join(
',', $excludeids)) . ($showtype ? 
'&showtype=' . urlencode($showtype) : 
'') . ($showcode ? 
'&showcode=' . urlencode($showcode) : 
'');
 
 1349      $out .= 
'<!-- force css to be higher than dialog popup --><style type="text/css">.ui-autocomplete { z-index: 1010; }</style>';
 
 1350      if (empty($hidelabel)) {
 
 1351        print $langs->trans(
"RefOrLabel") . 
' : ';
 
 1352      } elseif ($hidelabel > 1) {
 
 1353        $placeholder = $langs->trans(
"RefOrLabel");
 
 1354        if ($hidelabel == 2) {
 
 1355          $out .= 
img_picto($langs->trans(
"Search"), 
'search');
 
 1358      $out .= 
'<input type="text" class="' . $morecss . 
'" name="search_' . $htmlname . 
'" id="search_' . $htmlname . 
'" value="' . $selected_input_value . 
'"' . ($placeholder ? 
' placeholder="' . 
dol_escape_htmltag($placeholder) . 
'"' : 
'') . 
' ' . (
getDolGlobalString(
'THIRDPARTY_SEARCH_AUTOFOCUS') ? 
'autofocus' : 
'') . 
' />';
 
 1359      if ($hidelabel == 3) {
 
 1360        $out .= 
img_picto($langs->trans(
"Search"), 
'search');
 
 1365      $out .= 
ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT . 
'/societe/ajax/company.php', $urloption, $conf->global->COMPANY_USE_SEARCH_TO_SELECT, 0, $ajaxoptions);
 
 1368      $out .= $this->
select_thirdparty_list($selected, $htmlname, $filter, $showempty, $showtype, $forcecombo, $events, 
'', 0, $limit, $morecss, $moreparam, $multiple, $excludeids, $showcode);
 
 
 1399  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, $excludeids = array(), $showcode = 0)
 
 1402    global $conf, $user, $langs;
 
 1403    global $hookmanager;
 
 1407    $outarray = array();
 
 1409    if ($selected === 
'') {
 
 1410      $selected = array();
 
 1411    } elseif (!is_array($selected)) {
 
 1412      $selected = array($selected);
 
 1416    if (function_exists(
'testSqlAndScriptInject')) {
 
 1419        return 'SQLInjectionTryDetected';
 
 1423    if ($filter != 
'') {  
 
 1424      if (preg_match(
'/[\(\)]/', $filter)) {
 
 1430        if (function_exists(
'testSqlAndScriptInject')) {
 
 1433            return 'SQLInjectionTryDetected';
 
 1439        dol_syslog(
"Warning, select_thirdparty_list was called with a filter criteria not using the Universal Search Syntax.", LOG_WARNING);
 
 1444    $sql = 
"SELECT s.rowid, s.nom as name, s.name_alias, s.tva_intra, s.client, s.fournisseur, s.code_client, s.code_fournisseur";
 
 1446      $sql .= 
", s.address, s.zip, s.town";
 
 1447      $sql .= 
", dictp.code as country_code";
 
 1449    $sql .= 
" FROM " . $this->db->prefix() . 
"societe as s";
 
 1451      $sql .= 
" LEFT JOIN " . $this->db->prefix() . 
"c_country as dictp ON dictp.rowid = s.fk_pays";
 
 1453    if (!$user->hasRight(
'societe', 
'client', 
'voir') && !$user->socid) {
 
 1454      $sql .= 
", " . $this->db->prefix() . 
"societe_commerciaux as sc";
 
 1456    $sql .= 
" WHERE s.entity IN (" . 
getEntity(
'societe') . 
")";
 
 1457    if (!empty($user->socid)) {
 
 1458      $sql .= 
" AND s.rowid = " . ((int) $user->socid);
 
 1463      $sql .= 
" AND (" . $filter . 
")";
 
 1465    if (!$user->hasRight(
'societe', 
'client', 
'voir') && !$user->socid) {
 
 1466      $sql .= 
" AND s.rowid = sc.fk_soc AND sc.fk_user = " . ((int) $user->id);
 
 1469      $sql .= 
" AND s.status <> 0";
 
 1471    if (!empty($excludeids)) {
 
 1472      $sql .= 
" AND s.rowid NOT IN (" . $this->db->sanitize(join(
',', $excludeids)) . 
")";
 
 1475    $parameters = array();
 
 1476    $reshook = $hookmanager->executeHooks(
'selectThirdpartyListWhere', $parameters); 
 
 1477    $sql .= $hookmanager->resPrint;
 
 1479    if ($filterkey && $filterkey != 
'') {
 
 1483      $scrit = explode(
' ', $filterkey);
 
 1485      if (count($scrit) > 1) {
 
 1488      foreach ($scrit as $crit) {
 
 1492        $sql .= 
"(s.nom LIKE '" . $this->db->escape($prefix . $crit) . 
"%')";
 
 1495      if (count($scrit) > 1) {
 
 1498      if (isModEnabled(
'barcode')) {
 
 1499        $sql .= 
" OR s.barcode LIKE '" . $this->db->escape($prefix . $filterkey) . 
"%'";
 
 1501      $sql .= 
" OR s.code_client LIKE '" . $this->db->escape($prefix . $filterkey) . 
"%' OR s.code_fournisseur LIKE '" . $this->db->escape($prefix . $filterkey) . 
"%'";
 
 1502      $sql .= 
" OR s.name_alias LIKE '" . $this->db->escape($prefix . $filterkey) . 
"%' OR s.tva_intra LIKE '" . $this->db->escape($prefix . $filterkey) . 
"%'";
 
 1505    $sql .= $this->db->order(
"nom", 
"ASC");
 
 1506    $sql .= $this->db->plimit($limit, 0);
 
 1509    dol_syslog(get_class($this).
"::select_thirdparty_list", LOG_DEBUG);
 
 1510    $resql = $this->db->query($sql);
 
 1513        include_once DOL_DOCUMENT_ROOT . 
'/core/lib/ajax.lib.php';
 
 1518      $out .= 
'<select id="' . $htmlname . 
'" class="flat' . ($morecss ? 
' ' . $morecss : 
'') . 
'"' . ($moreparam ? 
' ' . $moreparam : 
'') . 
' name="' . $htmlname . ($multiple ? 
'[]' : 
'') . 
'" ' . ($multiple ? 
'multiple' : 
'') . 
'>' . 
"\n";
 
 1520      $textifempty = (($showempty && !is_numeric($showempty)) ? $langs->trans($showempty) : 
'');
 
 1524        if ($showempty && !is_numeric($showempty)) {
 
 1525          $textifempty = $langs->trans($showempty);
 
 1527          $textifempty .= $langs->trans(
"All");
 
 1531        $out .= 
'<option value="-1" data-html="' . 
dol_escape_htmltag(
'<span class="opacitymedium">' . ($textifempty ? $textifempty : 
' ') . 
'</span>') . 
'">' . $textifempty . 
'</option>' . 
"\n";
 
 1534      $companytemp = 
new Societe($this->db);
 
 1536      $num = $this->db->num_rows($resql);
 
 1540          $obj = $this->db->fetch_object($resql);
 
 1543            if (($obj->client) && (!empty($obj->code_client))) {
 
 1544              $label = $obj->code_client . 
' - ';
 
 1546            if (($obj->fournisseur) && (!empty($obj->code_fournisseur))) {
 
 1547              $label .= $obj->code_fournisseur . 
' - ';
 
 1549            $label .= 
' ' . $obj->name;
 
 1551            $label = $obj->name;
 
 1554          if (!empty($obj->name_alias)) {
 
 1555            $label .= 
' (' . $obj->name_alias . 
')';
 
 1559            $label .= 
' - '.$obj->tva_intra;
 
 1562          $labelhtml = $label;
 
 1565            $companytemp->id = $obj->rowid;
 
 1566            $companytemp->client = $obj->client;
 
 1567            $companytemp->fournisseur = $obj->fournisseur;
 
 1568            $tmptype = $companytemp->getTypeUrl(1, 
'', 0, 
'span');
 
 1570              $labelhtml .= 
' ' . $tmptype;
 
 1573            if ($obj->client || $obj->fournisseur) {
 
 1576            if ($obj->client == 1 || $obj->client == 3) {
 
 1577              $label .= $langs->trans(
"Customer");
 
 1579            if ($obj->client == 2 || $obj->client == 3) {
 
 1580              $label .= ($obj->client == 3 ? 
', ' : 
'') . $langs->trans(
"Prospect");
 
 1582            if ($obj->fournisseur) {
 
 1583              $label .= ($obj->client ? 
', ' : 
'') . $langs->trans(
"Supplier");
 
 1585            if ($obj->client || $obj->fournisseur) {
 
 1591            $s = ($obj->address ? 
' - ' . $obj->address : 
'') . ($obj->zip ? 
' - ' . $obj->zip : 
'') . ($obj->town ? 
' ' . $obj->town : 
'');
 
 1592            if (!empty($obj->country_code)) {
 
 1593              $s .= 
', ' . $langs->trans(
'Country' . $obj->country_code);
 
 1599          if (empty($outputmode)) {
 
 1600            if (in_array($obj->rowid, $selected)) {
 
 1601              $out .= 
'<option value="' . $obj->rowid . 
'" selected data-html="' . 
dol_escape_htmltag($labelhtml, 0, 0, 
'', 0, 1) . 
'">' . 
dol_escape_htmltag($label, 0, 0, 
'', 0, 1) . 
'</option>';
 
 1603              $out .= 
'<option value="' . $obj->rowid . 
'" data-html="' . 
dol_escape_htmltag($labelhtml, 0, 0, 
'', 0, 1) . 
'">' . 
dol_escape_htmltag($label, 0, 0, 
'', 0, 1) . 
'</option>';
 
 1606            array_push($outarray, array(
'key' => $obj->rowid, 
'value' => $label, 
'label' => $label, 
'labelhtml' => $labelhtml));
 
 1610          if (($i % 10) == 0) {
 
 1615      $out .= 
'</select>' . 
"\n";
 
 1620    $this->result = array(
'nbofthirdparties' => $num);
 
 
 1644    global $langs, $conf;
 
 1647    $sql = 
"SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,";
 
 1648    $sql .= 
" re.description, re.fk_facture_source";
 
 1649    $sql .= 
" FROM " . $this->db->prefix() . 
"societe_remise_except as re";
 
 1650    $sql .= 
" WHERE re.fk_soc = " . (int) $socid;
 
 1651    $sql .= 
" AND re.entity = " . $conf->entity;
 
 1653      $sql .= 
" AND " . $filter;
 
 1655    $sql .= 
" ORDER BY re.description ASC";
 
 1657    dol_syslog(get_class($this) . 
"::select_remises", LOG_DEBUG);
 
 1658    $resql = $this->db->query($sql);
 
 1660      print 
'<select id="select_' . $htmlname . 
'" class="flat maxwidthonsmartphone" name="' . $htmlname . 
'">';
 
 1661      $num = $this->db->num_rows($resql);
 
 1663      $qualifiedlines = $num;
 
 1667        print 
'<option value="0"> </option>';
 
 1669          $obj = $this->db->fetch_object($resql);
 
 1670          $desc = 
dol_trunc($obj->description, 40);
 
 1671          if (preg_match(
'/\(CREDIT_NOTE\)/', $desc)) {
 
 1672            $desc = preg_replace(
'/\(CREDIT_NOTE\)/', $langs->trans(
"CreditNote"), $desc);
 
 1674          if (preg_match(
'/\(DEPOSIT\)/', $desc)) {
 
 1675            $desc = preg_replace(
'/\(DEPOSIT\)/', $langs->trans(
"Deposit"), $desc);
 
 1677          if (preg_match(
'/\(EXCESS RECEIVED\)/', $desc)) {
 
 1678            $desc = preg_replace(
'/\(EXCESS RECEIVED\)/', $langs->trans(
"ExcessReceived"), $desc);
 
 1680          if (preg_match(
'/\(EXCESS PAID\)/', $desc)) {
 
 1681            $desc = preg_replace(
'/\(EXCESS PAID\)/', $langs->trans(
"ExcessPaid"), $desc);
 
 1685          if ($selected > 0 && $selected == $obj->rowid) {
 
 1686            $selectstring = 
' selected';
 
 1690          if ($maxvalue > 0 && $obj->amount_ttc > $maxvalue) {
 
 1692            $disabled = 
' disabled';
 
 1695          if (
getDolGlobalString(
'MAIN_SHOW_FACNUMBER_IN_DISCOUNT_LIST') && !empty($obj->fk_facture_source)) {
 
 1696            $tmpfac = 
new Facture($this->db);
 
 1697            if ($tmpfac->fetch($obj->fk_facture_source) > 0) {
 
 1698              $desc = $desc . 
' - ' . $tmpfac->ref;
 
 1702          print 
'<option value="' . $obj->rowid . 
'"' . $selectstring . $disabled . 
'>' . $desc . 
' (' . 
price($obj->amount_ht) . 
' ' . $langs->trans(
"HT") . 
' - ' . 
price($obj->amount_ttc) . 
' ' . $langs->trans(
"TTC") . 
')</option>';
 
 1709      return $qualifiedlines;
 
 
 1738  public function select_contacts($socid, $selected = 
'', $htmlname = 
'contactid', $showempty = 0, $exclude = 
'', $limitto = 
'', $showfunction = 0, $morecss = 
'', $showsoc = 0, $forcecombo = 0, $events = array(), $options_only = 
false, $moreparam = 
'', $htmlid = 
'')
 
 1741    print $this->
selectcontacts($socid, $selected, $htmlname, $showempty, $exclude, $limitto, $showfunction, $morecss, $options_only, $showsoc, $forcecombo, $events, $moreparam, $htmlid);
 
 
 1769  public function selectcontacts($socid, $selected = array(), $htmlname = 
'contactid', $showempty = 0, $exclude = 
'', $limitto = 
'', $showfunction = 0, $morecss = 
'', $options_only = 
false, $showsoc = 0, $forcecombo = 0, $events = array(), $moreparam = 
'', $htmlid = 
'', $multiple = 
false, $disableifempty = 0)
 
 1771    global $conf, $langs, $hookmanager, $action;
 
 1773    $langs->load(
'companies');
 
 1775    if (empty($htmlid)) {
 
 1776      $htmlid = $htmlname;
 
 1780    if ($selected === 
'') {
 
 1781      $selected = array();
 
 1782    } elseif (!is_array($selected)) {
 
 1783      $selected = array($selected);
 
 1787    if (!is_object($hookmanager)) {
 
 1788      include_once DOL_DOCUMENT_ROOT . 
'/core/class/hookmanager.class.php';
 
 1793    $sql = 
"SELECT sp.rowid, sp.lastname, sp.statut, sp.firstname, sp.poste, sp.email, sp.phone, sp.phone_perso, sp.phone_mobile, sp.town AS contact_town";
 
 1794    if ($showsoc > 0 || 
getDolGlobalString(
'CONTACT_SHOW_EMAIL_PHONE_TOWN_SELECTLIST')) {
 
 1795      $sql .= 
", s.nom as company, s.town AS company_town";
 
 1797    $sql .= 
" FROM " . $this->db->prefix() . 
"socpeople as sp";
 
 1798    if ($showsoc > 0 || 
getDolGlobalString(
'CONTACT_SHOW_EMAIL_PHONE_TOWN_SELECTLIST')) {
 
 1799      $sql .= 
" LEFT OUTER JOIN  " . $this->db->prefix() . 
"societe as s ON s.rowid=sp.fk_soc";
 
 1801    $sql .= 
" WHERE sp.entity IN (" . 
getEntity(
'contact') . 
")";
 
 1802    if ($socid > 0 || $socid == -1) {
 
 1803      $sql .= 
" AND sp.fk_soc = " . ((int) $socid);
 
 1806      $sql .= 
" AND sp.statut <> 0";
 
 1809    $parameters = array();
 
 1810    $reshook = $hookmanager->executeHooks(
'selectContactListWhere', $parameters); 
 
 1811    $sql .= $hookmanager->resPrint;
 
 1812    $sql .= 
" ORDER BY sp.lastname ASC";
 
 1814    dol_syslog(get_class($this) . 
"::selectcontacts", LOG_DEBUG);
 
 1815    $resql = $this->db->query($sql);
 
 1817      $num = $this->db->num_rows($resql);
 
 1819      if ($htmlname != 
'none' && !$options_only) {
 
 1820        $out .= 
'<select class="flat' . ($morecss ? 
' ' . $morecss : 
'') . 
'" id="' . $htmlid . 
'" name="' . $htmlname . (($num || empty($disableifempty)) ? 
'' : 
' disabled') . ($multiple ? 
'[]' : 
'') . 
'" ' . ($multiple ? 
'multiple' : 
'') . 
' ' . (!empty($moreparam) ? $moreparam : 
'') . 
'>';
 
 1823      if ($showempty && !is_numeric($showempty)) {
 
 1824        $textforempty = $showempty;
 
 1825        $out .= 
'<option class="optiongrey" value="-1"' . (in_array(-1, $selected) ? 
' selected' : 
'') . 
'>' . $textforempty . 
'</option>';
 
 1827        if (($showempty == 1 || ($showempty == 3 && $num > 1)) && !$multiple) {
 
 1828          $out .= 
'<option value="0"' . (in_array(0, $selected) ? 
' selected' : 
'') . 
'> </option>';
 
 1830        if ($showempty == 2) {
 
 1831          $out .= 
'<option value="0"' . (in_array(0, $selected) ? 
' selected' : 
'') . 
'>-- ' . $langs->trans(
"Internal") . 
' --</option>';
 
 1837        include_once DOL_DOCUMENT_ROOT . 
'/contact/class/contact.class.php';
 
 1838        $contactstatic = 
new Contact($this->db);
 
 1841          $obj = $this->db->fetch_object($resql);
 
 1844          $extendedInfos = 
'';
 
 1846            $extendedInfos = array();
 
 1847            $email = trim($obj->email);
 
 1848            if (!empty($email)) {
 
 1849              $extendedInfos[] = $email;
 
 1851              $phone = trim($obj->phone);
 
 1852              $phone_perso = trim($obj->phone_perso);
 
 1853              $phone_mobile = trim($obj->phone_mobile);
 
 1854              if (!empty($phone)) {
 
 1855                $extendedInfos[] = $phone;
 
 1857              if (!empty($phone_perso)) {
 
 1858                $extendedInfos[] = $phone_perso;
 
 1860              if (!empty($phone_mobile)) {
 
 1861                $extendedInfos[] = $phone_mobile;
 
 1864            $contact_town = trim($obj->contact_town);
 
 1865            $company_town = trim($obj->company_town);
 
 1866            if (!empty($contact_town)) {
 
 1867              $extendedInfos[] = $contact_town;
 
 1868            } elseif (!empty($company_town)) {
 
 1869              $extendedInfos[] = $company_town;
 
 1871            $extendedInfos = implode(
' - ', $extendedInfos);
 
 1872            if (!empty($extendedInfos)) {
 
 1873              $extendedInfos = 
' - ' . $extendedInfos;
 
 1877          $contactstatic->id = $obj->rowid;
 
 1878          $contactstatic->lastname = $obj->lastname;
 
 1879          $contactstatic->firstname = $obj->firstname;
 
 1880          if ($obj->statut == 1) {
 
 1881            if ($htmlname != 
'none') {
 
 1883              if (is_array($exclude) && count($exclude) && in_array($obj->rowid, $exclude)) {
 
 1886              if (is_array($limitto) && count($limitto) && !in_array($obj->rowid, $limitto)) {
 
 1889              if (!empty($selected) && in_array($obj->rowid, $selected)) {
 
 1890                $out .= 
'<option value="' . $obj->rowid . 
'"';
 
 1892                  $out .= 
' disabled';
 
 1894                $out .= 
' selected>';
 
 1895                $out .= $contactstatic->getFullName($langs) . $extendedInfos;
 
 1896                if ($showfunction && $obj->poste) {
 
 1897                  $out .= 
' (' . $obj->poste . 
')';
 
 1899                if (($showsoc > 0) && $obj->company) {
 
 1900                  $out .= 
' - (' . $obj->company . 
')';
 
 1902                $out .= 
'</option>';
 
 1904                $out .= 
'<option value="' . $obj->rowid . 
'"';
 
 1906                  $out .= 
' disabled';
 
 1909                $out .= $contactstatic->getFullName($langs) . $extendedInfos;
 
 1910                if ($showfunction && $obj->poste) {
 
 1911                  $out .= 
' (' . $obj->poste . 
')';
 
 1913                if (($showsoc > 0) && $obj->company) {
 
 1914                  $out .= 
' - (' . $obj->company . 
')';
 
 1916                $out .= 
'</option>';
 
 1919              if (in_array($obj->rowid, $selected)) {
 
 1920                $out .= $contactstatic->getFullName($langs) . $extendedInfos;
 
 1921                if ($showfunction && $obj->poste) {
 
 1922                  $out .= 
' (' . $obj->poste . 
')';
 
 1924                if (($showsoc > 0) && $obj->company) {
 
 1925                  $out .= 
' - (' . $obj->company . 
')';
 
 1933        $labeltoshow = ($socid != -1) ? ($langs->trans($socid ? 
"NoContactDefinedForThirdParty" : 
"NoContactDefined")) : $langs->trans(
'SelectAThirdPartyFirst');
 
 1934        $out .= 
'<option class="disabled" value="-1"' . (($showempty == 2 || $multiple) ? 
'' : 
' selected') . 
' disabled="disabled">';
 
 1935        $out .= $labeltoshow;
 
 1936        $out .= 
'</option>';
 
 1939      $parameters = array(
 
 1941        'htmlname' => $htmlname,
 
 1944        'showfunction' => $showfunction,
 
 1945        'showsoc' => $showsoc,
 
 1948      $reshook = $hookmanager->executeHooks(
'afterSelectContactOptions', $parameters, $this, $action); 
 
 1950      if ($htmlname != 
'none' && !$options_only) {
 
 1951        $out .= 
'</select>';
 
 1954      if ($conf->use_javascript_ajax && !$forcecombo && !$options_only) {
 
 1955        include_once DOL_DOCUMENT_ROOT . 
'/core/lib/ajax.lib.php';
 
 
 1984  public function select_users($selected = 
'', $htmlname = 
'userid', $show_empty = 0, $exclude = 
null, $disabled = 0, $include = 
'', $enableonly = array(), $force_entity = 
'0')
 
 1987    print $this->
select_dolusers($selected, $htmlname, $show_empty, $exclude, $disabled, $include, $enableonly, $force_entity);
 
 
 2016  public function select_dolusers($selected = 
'', $htmlname = 
'userid', $show_empty = 0, $exclude = 
null, $disabled = 0, $include = 
'', $enableonly = 
'', $force_entity = 
'', $maxlength = 0, $showstatus = 0, $morefilter = 
'', $show_every = 0, $enableonlytext = 
'', $morecss = 
'', $notdisabled = 0, $outputmode = 0, $multiple = 
false, $forcecombo = 0)
 
 2019    global $conf, $user, $langs, $hookmanager;
 
 2023    if ((is_numeric($selected) && ($selected < -2 || empty($selected))) && !
getDolGlobalString(
'SOCIETE_DISABLE_DEFAULT_SALESREPRESENTATIVE')) {
 
 2024      $selected = $user->id;
 
 2027    if ($selected === 
'') {
 
 2028      $selected = array();
 
 2029    } elseif (!is_array($selected)) {
 
 2030      $selected = array($selected);
 
 2033    $excludeUsers = 
null;
 
 2034    $includeUsers = 
null;
 
 2037    if (is_array($exclude)) {
 
 2038      $excludeUsers = implode(
",", $exclude);
 
 2041    if (is_array($include)) {
 
 2042      $includeUsers = implode(
",", $include);
 
 2043    } elseif ($include == 
'hierarchy') {
 
 2045      $includeUsers = implode(
",", $user->getAllChildIds(0));
 
 2046    } elseif ($include == 
'hierarchyme') {
 
 2048      $includeUsers = implode(
",", $user->getAllChildIds(1));
 
 2052    $outarray = array();
 
 2053    $outarray2 = array();
 
 2056    $sql = 
"SELECT DISTINCT u.rowid, u.lastname as lastname, u.firstname, u.statut as status, u.login, u.admin, u.entity, u.photo";
 
 2057    if (isModEnabled(
'multicompany') && $conf->entity == 1 && $user->admin && !$user->entity) {
 
 2058      $sql .= 
", e.label";
 
 2060    $sql .= 
" FROM " . $this->db->prefix() . 
"user as u";
 
 2061    if (isModEnabled(
'multicompany') && $conf->entity == 1 && $user->admin && !$user->entity) {
 
 2062      $sql .= 
" LEFT JOIN " . $this->db->prefix() . 
"entity as e ON e.rowid = u.entity";
 
 2063      if (!empty($force_entity)) {
 
 2064        $sql .= 
" WHERE u.entity IN (0, " . $this->db->sanitize($force_entity) . 
")";
 
 2066        $sql .= 
" WHERE u.entity IS NOT NULL";
 
 2069      if (isModEnabled(
'multicompany') && 
getDolGlobalInt(
'MULTICOMPANY_TRANSVERSE_MODE')) {
 
 2070        $sql .= 
" WHERE u.rowid IN (SELECT ug.fk_user FROM ".$this->db->prefix().
"usergroup_user as ug WHERE ug.entity IN (".
getEntity(
'usergroup').
"))";
 
 2072        $sql .= 
" WHERE u.entity IN (" . 
getEntity(
'user') . 
")";
 
 2075    if (!empty($user->socid)) {
 
 2076      $sql .= 
" AND u.fk_soc = " . ((int) $user->socid);
 
 2078    if (is_array($exclude) && $excludeUsers) {
 
 2079      $sql .= 
" AND u.rowid NOT IN (" . $this->db->sanitize($excludeUsers) . 
")";
 
 2081    if ($includeUsers) {
 
 2082      $sql .= 
" AND u.rowid IN (" . $this->db->sanitize($includeUsers) . 
")";
 
 2085      $sql .= 
" AND u.statut <> 0";
 
 2087    if (!empty($morefilter)) {
 
 2088      $sql .= 
" " . $morefilter;
 
 2092    $reshook = $hookmanager->executeHooks(
'addSQLWhereFilterOnSelectUsers', array(), $this, $action);
 
 2093    if (!empty($reshook)) {
 
 2094      $sql .= $hookmanager->resPrint;
 
 2098      $sql .= 
" ORDER BY u.statut DESC, u.firstname ASC, u.lastname ASC";
 
 2100      $sql .= 
" ORDER BY u.statut DESC, u.lastname ASC, u.firstname ASC";
 
 2103    dol_syslog(get_class($this) . 
"::select_dolusers", LOG_DEBUG);
 
 2105    $resql = $this->db->query($sql);
 
 2107      $num = $this->db->num_rows($resql);
 
 2111        $out .= 
'<select class="flat' . ($morecss ? 
' ' . $morecss : 
' minwidth200') . 
'" id="' . $htmlname . 
'" name="' . $htmlname . ($multiple ? 
'[]' : 
'') . 
'" ' . ($multiple ? 
'multiple' : 
'') . 
' ' . ($disabled ? 
' disabled' : 
'') . 
'>';
 
 2112        if ($show_empty && !$multiple) {
 
 2113          $textforempty = 
' ';
 
 2114          if (!empty($conf->use_javascript_ajax)) {
 
 2115            $textforempty = 
' '; 
 
 2117          if (!is_numeric($show_empty)) {
 
 2118            $textforempty = $show_empty;
 
 2120          $out .= 
'<option class="optiongrey" value="' . ($show_empty < 0 ? $show_empty : -1) . 
'"' . ((empty($selected) || in_array(-1, $selected)) ? 
' selected' : 
'') . 
'>' . $textforempty . 
'</option>' . 
"\n";
 
 2123          $out .= 
'<option value="-2"' . ((in_array(-2, $selected)) ? 
' selected' : 
'') . 
'>-- ' . $langs->trans(
"Everybody") . 
' --</option>' . 
"\n";
 
 2126        $userstatic = 
new User($this->db);
 
 2129          $obj = $this->db->fetch_object($resql);
 
 2131          $userstatic->id = $obj->rowid;
 
 2132          $userstatic->lastname = $obj->lastname;
 
 2133          $userstatic->firstname = $obj->firstname;
 
 2134          $userstatic->photo = $obj->photo;
 
 2135          $userstatic->statut = $obj->status;
 
 2136          $userstatic->entity = $obj->entity;
 
 2137          $userstatic->admin = $obj->admin;
 
 2140          if (is_array($enableonly) && count($enableonly) && !in_array($obj->rowid, $enableonly)) {
 
 2141            $disableline = ($enableonlytext ? $enableonlytext : 
'1');
 
 2145          $labeltoshowhtml = 
'';
 
 2152          $labeltoshow .= $userstatic->getFullName($langs, $fullNameMode, -1, $maxlength);
 
 2153          $labeltoshowhtml .= $userstatic->getFullName($langs, $fullNameMode, -1, $maxlength);
 
 2154          if (empty($obj->firstname) && empty($obj->lastname)) {
 
 2155            $labeltoshow .= $obj->login;
 
 2156            $labeltoshowhtml .= $obj->login;
 
 2163            $moreinfo .= ($moreinfo ? 
' - ' : 
' (');
 
 2164            $moreinfohtml .= ($moreinfohtml ? 
' - ' : 
' <span class="opacitymedium">(');
 
 2165            $moreinfo .= $obj->login;
 
 2166            $moreinfohtml .= $obj->login;
 
 2168          if ($showstatus >= 0) {
 
 2169            if ($obj->status == 1 && $showstatus == 1) {
 
 2170              $moreinfo .= ($moreinfo ? 
' - ' : 
' (') . $langs->trans(
'Enabled');
 
 2171              $moreinfohtml .= ($moreinfohtml ? 
' - ' : 
' <span class="opacitymedium">(') . $langs->trans(
'Enabled');
 
 2173            if ($obj->status == 0 && $showstatus == 1) {
 
 2174              $moreinfo .= ($moreinfo ? 
' - ' : 
' (') . $langs->trans(
'Disabled');
 
 2175              $moreinfohtml .= ($moreinfohtml ? 
' - ' : 
' <span class="opacitymedium">(') . $langs->trans(
'Disabled');
 
 2178          if (isModEnabled(
'multicompany') && !
getDolGlobalInt(
'MULTICOMPANY_TRANSVERSE_MODE') && $conf->entity == 1 && !empty($user->admin) && empty($user->entity)) {
 
 2179            if (empty($obj->entity)) {
 
 2180              $moreinfo .= ($moreinfo ? 
' - ' : 
' (') . $langs->trans(
"AllEntities");
 
 2181              $moreinfohtml .= ($moreinfohtml ? 
' - ' : 
' <span class="opacitymedium">(') . $langs->trans(
"AllEntities");
 
 2183              if ($obj->entity != $conf->entity) {
 
 2184                $moreinfo .= ($moreinfo ? 
' - ' : 
' (') . ($obj->label ? $obj->label : $langs->trans(
"EntityNameNotDefined"));
 
 2185                $moreinfohtml .= ($moreinfohtml ? 
' - ' : 
' <span class="opacitymedium">(') . ($obj->label ? $obj->label : $langs->trans(
"EntityNameNotDefined"));
 
 2189          $moreinfo .= (!empty($moreinfo) ? 
')' : 
'');
 
 2190          $moreinfohtml .= (!empty($moreinfohtml) ? 
')</span>' : 
'');
 
 2191          if (!empty($disableline) && $disableline != 
'1') {
 
 2193            $moreinfo .= 
' - ' . $disableline;
 
 2194            $moreinfohtml .= 
' - ' . $disableline;
 
 2196          $labeltoshow .= $moreinfo;
 
 2197          $labeltoshowhtml .= $moreinfohtml;
 
 2199          $out .= 
'<option value="' . $obj->rowid . 
'"';
 
 2200          if (!empty($disableline)) {
 
 2201            $out .= 
' disabled';
 
 2203          if ((is_object($selected) && $selected->id == $obj->rowid) || (!is_object($selected) && in_array($obj->rowid, $selected))) {
 
 2204            $out .= 
' selected';
 
 2206          $out .= 
' data-html="';
 
 2207          $outhtml = $userstatic->getNomUrl(-3, 
'', 0, 1, 24, 1, 
'login', 
'', 1) . 
' ';
 
 2208          if ($showstatus >= 0 && $obj->status == 0) {
 
 2209            $outhtml .= 
'<strike class="opacitymediumxxx">';
 
 2211          $outhtml .= $labeltoshowhtml;
 
 2212          if ($showstatus >= 0 && $obj->status == 0) {
 
 2213            $outhtml .= 
'</strike>';
 
 2217          $out .= $labeltoshow;
 
 2218          $out .= 
'</option>';
 
 2220          $outarray[$userstatic->id] = $userstatic->getFullName($langs, $fullNameMode, -1, $maxlength) . $moreinfo;
 
 2221          $outarray2[$userstatic->id] = array(
 
 2222            'id'=>$userstatic->id,
 
 2223            'label'=>$labeltoshow,
 
 2224            'labelhtml'=>$labeltoshowhtml,
 
 2232        $out .= 
'<select class="flat" id="' . $htmlname . 
'" name="' . $htmlname . 
'" disabled>';
 
 2233        $out .= 
'<option value="">' . $langs->trans(
"None") . 
'</option>';
 
 2235      $out .= 
'</select>';
 
 2237      if ($num && !$forcecombo) {
 
 2239        include_once DOL_DOCUMENT_ROOT . 
'/core/lib/ajax.lib.php';
 
 2246    if ($outputmode == 2) {
 
 2248    } elseif ($outputmode) {
 
 
 2279  public function select_dolusers_forevent($action = 
'', $htmlname = 
'userid', $show_empty = 0, $exclude = 
null, $disabled = 0, $include = array(), $enableonly = array(), $force_entity = 
'0', $maxlength = 0, $showstatus = 0, $morefilter = 
'', $showproperties = 0, $listofuserid = array(), $listofcontactid = array(), $listofotherid = array())
 
 2284    $userstatic = 
new User($this->db);
 
 2287    $assignedtouser = array();
 
 2288    if (!empty($_SESSION[
'assignedtouser'])) {
 
 2289      $assignedtouser = json_decode($_SESSION[
'assignedtouser'], 
true);
 
 2291    $nbassignetouser = count($assignedtouser);
 
 2294    if ($nbassignetouser) {
 
 2295      $out .= 
'<ul class="attendees">';
 
 2299    foreach ($assignedtouser as $key => $value) {
 
 2300      if ($value[
'id'] == $ownerid) {
 
 2305      $userstatic->fetch($value[
'id']);
 
 2306      $out .= $userstatic->getNomUrl(-1);
 
 2308        $ownerid = $value[
'id'];
 
 2309        $out .= 
' (' . $langs->trans(
"Owner") . 
')';
 
 2311      if ($nbassignetouser > 1 && $action != 
'view') {
 
 2312        $out .= 
' <input type="image" style="border: 0px;" src="' . 
img_picto($langs->trans(
"Remove"), 
'delete', 
'', 0, 1) . 
'" value="' . $userstatic->id . 
'" class="removedassigned reposition" id="removedassigned_' . $userstatic->id . 
'" name="removedassigned_' . $userstatic->id . 
'">';
 
 2315      if ($showproperties) {
 
 2316        if ($ownerid == $value[
'id'] && is_array($listofuserid) && count($listofuserid) && in_array($ownerid, array_keys($listofuserid))) {
 
 2317          $out .= 
'<div class="myavailability inline-block">';
 
 2318          $out .= 
'<span class="hideonsmartphone"> - <span class="opacitymedium">' . $langs->trans(
"Availability") . 
':</span>  </span><input id="transparency" class="paddingrightonly" ' . ($action == 
'view' ? 
'disabled' : 
'') . 
' type="checkbox" name="transparency"' . ($listofuserid[$ownerid][
'transparency'] ? 
' checked' : 
'') . 
'><label for="transparency">' . $langs->trans(
"Busy") . 
'</label>';
 
 2328    if ($nbassignetouser) {
 
 2333    if ($action != 
'view') {
 
 2334      $out .= 
'<input type="hidden" class="removedassignedhidden" name="removedassigned" value="">';
 
 2335      $out .= 
'<script nonce="' . 
getNonce() . 
'" type="text/javascript">jQuery(document).ready(function () {';
 
 2336      $out .= 
'jQuery(".removedassigned").click(function() { jQuery(".removedassignedhidden").val(jQuery(this).val()); });';
 
 2337      $out .= 
'jQuery(".assignedtouser").change(function() { console.log(jQuery(".assignedtouser option:selected").val());';
 
 2338      $out .= 
' if (jQuery(".assignedtouser option:selected").val() > 0) { jQuery("#' . $action . 
'assignedtouser").attr("disabled", false); }';
 
 2339      $out .= 
' else { jQuery("#' . $action . 
'assignedtouser").attr("disabled", true); }';
 
 2341      $out .= 
'})</script>';
 
 2342      $out .= $this->
select_dolusers(
'', $htmlname, $show_empty, $exclude, $disabled, $include, $enableonly, $force_entity, $maxlength, $showstatus, $morefilter);
 
 2343      $out .= 
' <input type="submit" disabled class="button valignmiddle smallpaddingimp reposition" id="' . $action . 
'assignedtouser" name="' . $action . 
'assignedtouser" value="' . 
dol_escape_htmltag($langs->trans(
"Add")) . 
'">';
 
 
 2370  public function select_dolresources_forevent($action = 
'', $htmlname = 
'userid', $show_empty = 0, $exclude = 
null, $disabled = 0, $include = array(), $enableonly = array(), $force_entity = 
'0', $maxlength = 0, $showstatus = 0, $morefilter = 
'', $showproperties = 0, $listofresourceid = array())
 
 2375    require_once DOL_DOCUMENT_ROOT.
'/resource/class/html.formresource.class.php';
 
 2376    require_once DOL_DOCUMENT_ROOT.
'/resource/class/dolresource.class.php';
 
 2381    $assignedtoresource = array();
 
 2382    if (!empty($_SESSION[
'assignedtoresource'])) {
 
 2383      $assignedtoresource = json_decode($_SESSION[
'assignedtoresource'], 
true);
 
 2385    $nbassignetoresource = count($assignedtoresource);
 
 2388    if ($nbassignetoresource) {
 
 2389      $out .= 
'<ul class="attendees">';
 
 2393    foreach ($assignedtoresource as $key => $value) {
 
 2395      $resourcestatic->fetch($value[
'id']);
 
 2396      $out .= $resourcestatic->getNomUrl(-1);
 
 2397      if ($nbassignetoresource > 1 && $action != 
'view') {
 
 2398        $out .= 
' <input type="image" style="border: 0px;" src="' . 
img_picto($langs->trans(
"Remove"), 
'delete', 
'', 0, 1) . 
'" value="' . $resourcestatic->id . 
'" class="removedassigned reposition" id="removedassignedresource_' . $resourcestatic->id . 
'" name="removedassignedresource_' . $resourcestatic->id . 
'">';
 
 2401      if ($showproperties) {
 
 2402        if (is_array($listofresourceid) && count($listofresourceid)) {
 
 2403          $out .= 
'<div class="myavailability inline-block">';
 
 2404          $out .= 
'<span class="hideonsmartphone"> - <span class="opacitymedium">' . $langs->trans(
"Availability") . 
':</span>  </span><input id="transparencyresource" class="paddingrightonly" ' . ($action == 
'view' ? 
'disabled' : 
'') . 
' type="checkbox" name="transparency"' . ($listofresourceid[$value[
'id']][
'transparency'] ? 
' checked' : 
'') . 
'><label for="transparency">' . $langs->trans(
"Busy") . 
'</label>';
 
 2414    if ($nbassignetoresource) {
 
 2419    if ($action != 
'view') {
 
 2420      $out .= 
'<input type="hidden" class="removedassignedhidden" name="removedassignedresource" value="">';
 
 2421      $out .= 
'<script nonce="' . 
getNonce() . 
'" type="text/javascript">jQuery(document).ready(function () {';
 
 2422      $out .= 
'jQuery(".removedassignedresource").click(function() { jQuery(".removedassignedresourcehidden").val(jQuery(this).val()); });';
 
 2423      $out .= 
'jQuery(".assignedtoresource").change(function() { console.log(jQuery(".assignedtoresource option:selected").val());';
 
 2424      $out .= 
' if (jQuery(".assignedtoresource option:selected").val() > 0) { jQuery("#' . $action . 
'assignedtoresource").attr("disabled", false); }';
 
 2425      $out .= 
' else { jQuery("#' . $action . 
'assignedtoresource").attr("disabled", true); }';
 
 2427      $out .= 
'})</script>';
 
 2430      $out .= 
img_picto(
'', 
'resource', 
'class="pictofixedwidth"');
 
 2431      $out .= $formresources->select_resource_list(
'', $htmlname, 
'', 1, 1, 0, $events, 
'', 2, 
null);
 
 2433      $out .= 
' <input type="submit" disabled class="button valignmiddle smallpaddingimp reposition" id="' . $action . 
'assignedtoresource" name="' . $action . 
'assignedtoresource" value="' . 
dol_escape_htmltag($langs->trans(
"Add")) . 
'">';
 
 
 2469  public function select_produits($selected = 0, $htmlname = 
'productid', $filtertype = 
'', $limit = 0, $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 = 
null, $nooutput = 0, $status_purchase = -1)
 
 2472    global $langs, $conf;
 
 2477    $price_level = (!empty($price_level) ? $price_level : 0);
 
 2478    if (is_null($ajaxoptions)) {
 
 2479      $ajaxoptions = array();
 
 2482    if (strval($filtertype) === 
'' && (isModEnabled(
"product") || isModEnabled(
"service"))) {
 
 2483      if (isModEnabled(
"product") && !isModEnabled(
'service')) {
 
 2485      } elseif (!isModEnabled(
'product') && isModEnabled(
"service")) {
 
 2490    if (!empty($conf->use_javascript_ajax) && 
getDolGlobalString(
'PRODUIT_USE_SEARCH_TO_SELECT')) {
 
 2493      if ($selected && empty($selected_input_value)) {
 
 2494        require_once DOL_DOCUMENT_ROOT . 
'/product/class/product.class.php';
 
 2495        $producttmpselect = 
new Product($this->db);
 
 2496        $producttmpselect->fetch($selected);
 
 2497        $selected_input_value = $producttmpselect->ref;
 
 2498        unset($producttmpselect);
 
 2501      if ($filtertype == 
'') {
 
 2502        if (!isModEnabled(
'product')) { 
 
 2504        } elseif (!isModEnabled(
'service')) { 
 
 2509      $urloption = ($socid > 0 ? 
'socid=' . $socid . 
'&' : 
'') . 
'htmlname=' . $htmlname . 
'&outjson=1&price_level=' . $price_level . 
'&type=' . $filtertype . 
'&mode=1&status=' . $status . 
'&status_purchase=' . $status_purchase . 
'&finished=' . $finished . 
'&hidepriceinlabel=' . $hidepriceinlabel . 
'&warehousestatus=' . $warehouseStatus;
 
 2510      $out .= 
ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT . 
'/product/ajax/products.php', $urloption, $conf->global->PRODUIT_USE_SEARCH_TO_SELECT, 1, $ajaxoptions);
 
 2512      if (isModEnabled(
'variants') && is_array($selected_combinations)) {
 
 2516        <!-- script to auto show attributes select tags if a variant was selected --> 
 2517        <script nonce="' . 
getNonce() . 
'"> 
 2518          // auto show attributes fields 
 2519          selected = ' . json_encode($selected_combinations) . 
'; 
 2522          jQuery(document).ready(function () { 
 2524            jQuery("input[name=\'prod_entry_mode\']").change(function () { 
 2525              if (jQuery(this).val() == \'free\') { 
 2526                jQuery(\'div#attributes_box\').empty(); 
 2530            jQuery("input#' . $htmlname . 
'").change(function () { 
 2532              if (!jQuery(this).val()) { 
 2533                jQuery(\'div#attributes_box\').empty(); 
 2537              console.log("A change has started. We get variants fields to inject html select"); 
 2539              jQuery.getJSON("' . DOL_URL_ROOT . 
'/variants/ajax/getCombinations.php", { 
 2540                id: jQuery(this).val() 
 2541              }, function (data) { 
 2542                jQuery(\'div#attributes_box\').empty(); 
 2544                jQuery.each(data, function (key, val) { 
 2546                  combvalues[val.id] = val.values; 
 2548                  var span = jQuery(document.createElement(\'div\')).css({ 
 2549                    \'display\': \'table-row\' 
 2553                    jQuery(document.createElement(\'div\')).text(val.label).css({ 
 2554                      \'font-weight\': \'bold\', 
 2555                      \'display\': \'table-cell\' 
 2559                  var html = jQuery(document.createElement(\'select\')).attr(\'name\', \'combinations[\' + val.id + \']\').css({ 
 2560                    \'margin-left\': \'15px\', 
 2561                    \'white-space\': \'pre\' 
 2563                    jQuery(document.createElement(\'option\')).val(\'\') 
 2566                  jQuery.each(combvalues[val.id], function (key, val) { 
 2567                    var tag = jQuery(document.createElement(\'option\')).val(val.id).html(val.value); 
 2569                    if (selected[val.fk_product_attribute] == val.id) { 
 2570                      tag.attr(\'selected\', \'selected\'); 
 2577                  jQuery(\'div#attributes_box\').append(span); 
 2582            ' . ($selected ? 
'jQuery("input#' . $htmlname . 
'").change();' : 
'') . 
' 
 2588      if (empty($hidelabel)) {
 
 2589        $out .= $langs->trans(
"RefOrLabel") . 
' : ';
 
 2590      } elseif ($hidelabel > 1) {
 
 2591        $placeholder = 
' placeholder="' . $langs->trans(
"RefOrLabel") . 
'"';
 
 2592        if ($hidelabel == 2) {
 
 2593          $out .= 
img_picto($langs->trans(
"Search"), 
'search');
 
 2596      $out .= 
'<input type="text" class="minwidth100' . ($morecss ? 
' ' . $morecss : 
'') . 
'" name="search_' . $htmlname . 
'" id="search_' . $htmlname . 
'" value="' . $selected_input_value . 
'"' . $placeholder . 
' ' . (
getDolGlobalString(
'PRODUCT_SEARCH_AUTOFOCUS') ? 
'autofocus' : 
'') . 
' />';
 
 2597      if ($hidelabel == 3) {
 
 2598        $out .= 
img_picto($langs->trans(
"Search"), 
'search');
 
 2601      $out .= $this->
select_produits_list($selected, $htmlname, $filtertype, $limit, $price_level, 
'', $status, $finished, 0, $socid, $showempty, $forcecombo, $morecss, $hidepriceinlabel, $warehouseStatus, $status_purchase);
 
 2604    if (empty($nooutput)) {
 
 
 2628  public function select_bom($selected = 
'', $htmlname = 
'bom_id', $limit = 0, $status = 1, $type = 0, $showempty = 
'1', $morecss = 
'', $nooutput = 
'', $forcecombo = 0, $TProducts = [])
 
 2631    global $conf, $user, $langs, $db;
 
 2633    require_once DOL_DOCUMENT_ROOT . 
'/product/class/product.class.php';
 
 2639      include_once DOL_DOCUMENT_ROOT . 
'/core/lib/ajax.lib.php';
 
 2644    $out .= 
'<select class="flat' . ($morecss ? 
' ' . $morecss : 
'') . 
'" name="' . $htmlname . 
'" id="' . $htmlname . 
'">';
 
 2646    $sql = 
'SELECT b.rowid, b.ref, b.label, b.fk_product';
 
 2647    $sql .= 
' FROM ' . MAIN_DB_PREFIX . 
'bom_bom as b';
 
 2648    $sql .= 
' WHERE b.entity IN (' . 
getEntity(
'bom') . 
')';
 
 2649    if (!empty($status)) {
 
 2650      $sql .= 
' AND status = ' . (int) $status;
 
 2652    if (!empty($type)) {
 
 2653      $sql .= 
' AND bomtype = ' . (int) $type;
 
 2655    if (!empty($TProducts)) {
 
 2656      $sql .= 
' AND fk_product IN (' . $this->db->sanitize(implode(
',', $TProducts)) . 
')';
 
 2658    if (!empty($limit)) {
 
 2659      $sql .= 
' LIMIT ' . (int) $limit;
 
 2661    $resql = $db->query($sql);
 
 2664        $out .= 
'<option value="-1"';
 
 2665        if (empty($selected)) {
 
 2666          $out .= 
' selected';
 
 2668        $out .= 
'> </option>';
 
 2670      while ($obj = $db->fetch_object($resql)) {
 
 2672        $res = $product->fetch($obj->fk_product);
 
 2673        $out .= 
'<option value="' . $obj->rowid . 
'"';
 
 2674        if ($obj->rowid == $selected) {
 
 2677        $out .= 
'>' . $obj->ref . 
' - ' . $product->label . 
' - ' . $obj->label . 
'</option>';
 
 2683    $out .= 
'</select>';
 
 2684    if (empty($nooutput)) {
 
 
 2718  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 = 
'', $status_purchase = -1)
 
 2721    global $langs, $conf;
 
 2722    global $hookmanager;
 
 2725    $outarray = array();
 
 2729      $langs->load(
'other');
 
 2732    $warehouseStatusArray = array();
 
 2733    if (!empty($warehouseStatus)) {
 
 2734      require_once DOL_DOCUMENT_ROOT . 
'/product/stock/class/entrepot.class.php';
 
 2735      if (preg_match(
'/warehouseclosed/', $warehouseStatus)) {
 
 2738      if (preg_match(
'/warehouseopen/', $warehouseStatus)) {
 
 2741      if (preg_match(
'/warehouseinternal/', $warehouseStatus)) {
 
 2746    $selectFields = 
" p.rowid, p.ref, p.label, p.description, p.barcode, p.fk_country, p.fk_product_type, p.price, p.price_ttc, p.price_base_type, p.tva_tx, p.default_vat_code, p.duration, p.fk_price_expression";
 
 2747    if (count($warehouseStatusArray)) {
 
 2748      $selectFieldsGrouped = 
", sum(" . $this->db->ifsql(
"e.statut IS NULL", 
"0", 
"ps.reel") . 
") as stock"; 
 
 2750      $selectFieldsGrouped = 
", " . $this->db->ifsql(
"p.stock IS NULL", 0, 
"p.stock") . 
" AS stock";
 
 2756    $parameters = array();
 
 2757    $reshook = $hookmanager->executeHooks(
'selectProductsListSelect', $parameters); 
 
 2758    if (empty($reshook)) {
 
 2759      $sql .= $selectFields.$selectFieldsGrouped.$hookmanager->resPrint;
 
 2761      $sql .= $hookmanager->resPrint;
 
 2766      $sql .= 
", (SELECT " . $this->db->prefix() . 
"categorie_product.fk_categorie 
 2767            FROM " . $this->db->prefix() . 
"categorie_product 
 2768            WHERE " . $this->db->prefix() . 
"categorie_product.fk_product=p.rowid 
 2770        ) AS categorie_product_id ";
 
 2775      $sql .= 
', pcp.rowid as idprodcustprice, pcp.price as custprice, pcp.price_ttc as custprice_ttc,';
 
 2776      $sql .= 
' pcp.price_base_type as custprice_base_type, pcp.tva_tx as custtva_tx, pcp.default_vat_code as custdefault_vat_code, pcp.ref_customer as custref';
 
 2777      $selectFields .= 
", idprodcustprice, custprice, custprice_ttc, custprice_base_type, custtva_tx, custdefault_vat_code, custref";
 
 2781      $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";
 
 2782      $selectFields .= 
', unit_long, 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';
 
 2787      $sql .= 
", pl.label as label_translated";
 
 2788      $sql .= 
", pl.description as description_translated";
 
 2789      $selectFields .= 
", label_translated";
 
 2790      $selectFields .= 
", description_translated";
 
 2794      $sql .= 
", (SELECT pp.rowid FROM " . $this->db->prefix() . 
"product_price as pp WHERE pp.fk_product = p.rowid";
 
 2795      if ($price_level >= 1 && 
getDolGlobalString(
'PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES')) {
 
 2796        $sql .= 
" AND price_level = " . ((int) $price_level);
 
 2798      $sql .= 
" ORDER BY date_price";
 
 2799      $sql .= 
" DESC LIMIT 1) as price_rowid";
 
 2800      $sql .= 
", (SELECT pp.price_by_qty FROM " . $this->db->prefix() . 
"product_price as pp WHERE pp.fk_product = p.rowid"; 
 
 2801      if ($price_level >= 1 && 
getDolGlobalString(
'PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES')) {
 
 2802        $sql .= 
" AND price_level = " . ((int) $price_level);
 
 2804      $sql .= 
" ORDER BY date_price";
 
 2805      $sql .= 
" DESC LIMIT 1) as price_by_qty";
 
 2806      $selectFields .= 
", price_rowid, price_by_qty";
 
 2809    $sql .= 
" FROM ".$this->db->prefix().
"product as p";
 
 2811    $parameters = array();
 
 2812    $reshook = $hookmanager->executeHooks(
'selectProductsListFrom', $parameters); 
 
 2813    $sql .= $hookmanager->resPrint;
 
 2815    if (count($warehouseStatusArray)) {
 
 2816      $sql .= 
" LEFT JOIN " . $this->db->prefix() . 
"product_stock as ps on ps.fk_product = p.rowid";
 
 2817      $sql .= 
" LEFT JOIN " . $this->db->prefix() . 
"entrepot as e on ps.fk_entrepot = e.rowid AND e.entity IN (" . 
getEntity(
'stock') . 
")";
 
 2818      $sql .= 
' AND e.statut IN (' . $this->db->sanitize($this->db->escape(implode(
',', $warehouseStatusArray))) . 
')'; 
 
 2823      $sql .= 
" LEFT JOIN " . $this->db->prefix() . 
"product_fournisseur_price as pfp ON p.rowid = pfp.fk_product";
 
 2828      $sql .= 
" LEFT JOIN  " . $this->db->prefix() . 
"product_customer_price as pcp ON pcp.fk_soc=" . ((int) $socid) . 
" AND pcp.fk_product=p.rowid";
 
 2832      $sql .= 
" LEFT JOIN " . $this->db->prefix() . 
"c_units u ON u.rowid = p.fk_unit";
 
 2836      $sql .= 
" LEFT JOIN " . $this->db->prefix() . 
"product_lang as pl ON pl.fk_product = p.rowid ";
 
 2838        require_once DOL_DOCUMENT_ROOT . 
'/societe/class/societe.class.php';
 
 2839        $soc = 
new Societe($this->db);
 
 2840        $result = $soc->fetch($socid);
 
 2841        if ($result > 0 && !empty($soc->default_lang)) {
 
 2842          $sql .= 
" AND pl.lang = '" . $this->db->escape($soc->default_lang) . 
"'";
 
 2844          $sql .= 
" AND pl.lang = '" . $this->db->escape($langs->getDefaultLang()) . 
"'";
 
 2847        $sql .= 
" AND pl.lang = '" . $this->db->escape($langs->getDefaultLang()) . 
"'";
 
 2852      $sql .= 
" LEFT JOIN " . $this->db->prefix() . 
"product_attribute_combination pac ON pac.fk_product_child = p.rowid";
 
 2855    $sql .= 
' WHERE p.entity IN (' . 
getEntity(
'product') . 
')';
 
 2858      $sql .= 
" AND pac.rowid IS NULL";
 
 2861    if ($finished == 0) {
 
 2862      $sql .= 
" AND p.finished = " . ((int) $finished);
 
 2863    } elseif ($finished == 1) {
 
 2864      $sql .= 
" AND p.finished = ".((int) $finished);
 
 2867      $sql .= 
" AND p.tosell = ".((int) $status);
 
 2869    if ($status_purchase >= 0) {
 
 2870      $sql .= 
" AND p.tobuy = " . ((int) $status_purchase);
 
 2873    if (strval($filtertype) != 
'') {
 
 2874      $sql .= 
" AND p.fk_product_type = " . ((int) $filtertype);
 
 2875    } elseif (!isModEnabled(
'product')) { 
 
 2876      $sql .= 
" AND p.fk_product_type = 1";
 
 2877    } elseif (!isModEnabled(
'service')) { 
 
 2878      $sql .= 
" AND p.fk_product_type = 0";
 
 2881    $parameters = array();
 
 2882    $reshook = $hookmanager->executeHooks(
'selectProductsListWhere', $parameters); 
 
 2883    $sql .= $hookmanager->resPrint;
 
 2885    if ($filterkey != 
'') {
 
 2889      $scrit = explode(
' ', $filterkey);
 
 2891      if (count($scrit) > 1) {
 
 2894      foreach ($scrit as $crit) {
 
 2898        $sql .= 
"(p.ref LIKE '" . $this->db->escape($prefix . $crit) . 
"%' OR p.label LIKE '" . $this->db->escape($prefix . $crit) . 
"%'";
 
 2900          $sql .= 
" OR pl.label LIKE '" . $this->db->escape($prefix . $crit) . 
"%'";
 
 2903          $sql .= 
" OR pcp.ref_customer LIKE '" . $this->db->escape($prefix . $crit) . 
"%'";
 
 2906          $sql .= 
" OR p.description LIKE '" . $this->db->escape($prefix . $crit) . 
"%'";
 
 2908            $sql .= 
" OR pl.description LIKE '" . $this->db->escape($prefix . $crit) . 
"%'";
 
 2912          $sql .= 
" OR pfp.ref_fourn LIKE '" . $this->db->escape($prefix . $crit) . 
"%'";
 
 2917      if (count($scrit) > 1) {
 
 2920      if (isModEnabled(
'barcode')) {
 
 2921        $sql .= 
" OR p.barcode LIKE '" . $this->db->escape($prefix . $filterkey) . 
"%'";
 
 2925    if (count($warehouseStatusArray)) {
 
 2926      $sql .= 
" GROUP BY " . $selectFields;
 
 2931      $sql .= 
" ORDER BY categorie_product_id ";
 
 2933      (
getDolGlobalInt(
'PRODUCT_SORT_BY_CATEGORY') == 1) ? $sql .= 
"ASC" : $sql .= 
"DESC";
 
 2935      $sql .= $this->db->order(
"p.ref");
 
 2938    $sql .= $this->db->plimit($limit, 0);
 
 2941    dol_syslog(get_class($this) . 
"::select_produits_list search products", LOG_DEBUG);
 
 2942    $result = $this->db->query($sql);
 
 2944      require_once DOL_DOCUMENT_ROOT . 
'/product/class/product.class.php';
 
 2945      require_once DOL_DOCUMENT_ROOT . 
'/product/dynamic_price/class/price_parser.class.php';
 
 2946      require_once DOL_DOCUMENT_ROOT . 
'/core/lib/product.lib.php';
 
 2948      $num = $this->db->num_rows($result);
 
 2953        include_once DOL_DOCUMENT_ROOT . 
'/core/lib/ajax.lib.php';
 
 2957      $out .= 
'<select class="flat' . ($morecss ? 
' ' . $morecss : 
'') . 
'" name="' . $htmlname . 
'" id="' . $htmlname . 
'">';
 
 2963        if ($showempty && !is_numeric($showempty)) {
 
 2964          $textifempty = $langs->trans($showempty);
 
 2966          $textifempty .= $langs->trans(
"All");
 
 2969        if ($showempty && !is_numeric($showempty)) {
 
 2970          $textifempty = $langs->trans($showempty);
 
 2974        $out .= 
'<option value="-1" selected>' . ($textifempty ? $textifempty : 
' ') . 
'</option>';
 
 2978      while ($num && $i < $num) {
 
 2981        $objp = $this->db->fetch_object($result);
 
 2983        if ((
getDolGlobalString(
'PRODUIT_CUSTOMER_PRICES_BY_QTY') || 
getDolGlobalString(
'PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES')) && !empty($objp->price_by_qty) && $objp->price_by_qty == 1) { 
 
 2984          $sql = 
"SELECT rowid, quantity, price, unitprice, remise_percent, remise, price_base_type";
 
 2985          $sql .= 
" FROM " . $this->db->prefix() . 
"product_price_by_qty";
 
 2986          $sql .= 
" WHERE fk_product_price = " . ((int) $objp->price_rowid);
 
 2987          $sql .= 
" ORDER BY quantity ASC";
 
 2989          dol_syslog(get_class($this) . 
"::select_produits_list search prices by qty", LOG_DEBUG);
 
 2990          $result2 = $this->db->query($sql);
 
 2992            $nb_prices = $this->db->num_rows($result2);
 
 2994            while ($nb_prices && $j < $nb_prices) {
 
 2995              $objp2 = $this->db->fetch_object($result2);
 
 2997              $objp->price_by_qty_rowid = $objp2->rowid;
 
 2998              $objp->price_by_qty_price_base_type = $objp2->price_base_type;
 
 2999              $objp->price_by_qty_quantity = $objp2->quantity;
 
 3000              $objp->price_by_qty_unitprice = $objp2->unitprice;
 
 3001              $objp->price_by_qty_remise_percent = $objp2->remise_percent;
 
 3003              $objp->quantity = $objp2->quantity;
 
 3004              $objp->price = $objp2->price;
 
 3005              $objp->unitprice = $objp2->unitprice;
 
 3006              $objp->remise_percent = $objp2->remise_percent;
 
 3019              array_push($outarray, $optJson);
 
 3023          if (isModEnabled(
'dynamicprices') && !empty($objp->fk_price_expression)) {
 
 3024            $price_product = 
new Product($this->db);
 
 3025            $price_product->fetch($objp->rowid, 
'', 
'', 1);
 
 3027            require_once DOL_DOCUMENT_ROOT . 
'/product/dynamic_price/class/price_parser.class.php';
 
 3029            $price_result = $priceparser->parseProduct($price_product);
 
 3030            if ($price_result >= 0) {
 
 3031              $objp->price = $price_result;
 
 3032              $objp->unitprice = $price_result;
 
 3034              $objp->price_ttc = 
price2num($objp->price) * (1 + ($objp->tva_tx / 100));
 
 3035              $objp->price_ttc = 
price2num($objp->price_ttc, 
'MU');
 
 3044          array_push($outarray, $optJson);
 
 3050      $out .= 
'</select>';
 
 3052      $this->db->free($result);
 
 3054      if (empty($outputmode)) {
 
 
 3081  protected function constructProductListOption(&$objp, &$opt, &$optJson, $price_level, $selected, $hidepriceinlabel = 0, $filterkey = 
'', $novirtualstock = 0)
 
 3083    global $langs, $conf, $user;
 
 3084    global $hookmanager;
 
 3090    $outlabel_translated = 
'';
 
 3092    $outdesc_translated = 
'';
 
 3098    $outpricebasetype = 
'';
 
 3100    $outdefault_vat_code = 
'';
 
 3104    $maxlengtharticle = (!
getDolGlobalString(
'PRODUCT_MAX_LENGTH_COMBO') ? 48 : $conf->global->PRODUCT_MAX_LENGTH_COMBO);
 
 3106    $label = $objp->label;
 
 3107    if (!empty($objp->label_translated)) {
 
 3108      $label = $objp->label_translated;
 
 3110    if (!empty($filterkey) && $filterkey != 
'') {
 
 3111      $label = preg_replace(
'/(' . preg_quote($filterkey, 
'/') . 
')/i', 
'<strong>$1</strong>', $label, 1);
 
 3114    $outkey = $objp->rowid;
 
 3115    $outref = $objp->ref;
 
 3116    $outrefcust = empty($objp->custref) ? 
'' : $objp->custref;
 
 3117    $outlabel = $objp->label;
 
 3118    $outdesc = $objp->description;
 
 3120      $outlabel_translated = $objp->label_translated;
 
 3121      $outdesc_translated = $objp->description_translated;
 
 3123    $outbarcode = $objp->barcode;
 
 3124    $outorigin = $objp->fk_country;
 
 3125    $outpbq = empty($objp->price_by_qty_rowid) ? 
'' : $objp->price_by_qty_rowid;
 
 3127    $outtype = $objp->fk_product_type;
 
 3132      require_once DOL_DOCUMENT_ROOT . 
'/core/lib/company.lib.php';
 
 3138      if (!empty($objp->unit_short)) {
 
 3139        $outvalUnits .= 
' - ' . $objp->unit_short;
 
 3143      if (!empty($objp->weight) && $objp->weight_units !== 
null) {
 
 3145        $outvalUnits .= 
' - ' . $unitToShow;
 
 3147      if ((!empty($objp->length) || !empty($objp->width) || !empty($objp->height)) && $objp->length_units !== 
null) {
 
 3148        $unitToShow = $objp->length . 
' x ' . $objp->width . 
' x ' . $objp->height . 
' ' . 
measuringUnitString(0, 
'size', $objp->length_units);
 
 3149        $outvalUnits .= 
' - ' . $unitToShow;
 
 3151      if (!empty($objp->surface) && $objp->surface_units !== 
null) {
 
 3153        $outvalUnits .= 
' - ' . $unitToShow;
 
 3155      if (!empty($objp->volume) && $objp->volume_units !== 
null) {
 
 3157        $outvalUnits .= 
' - ' . $unitToShow;
 
 3160    if ($outdurationvalue && $outdurationunit) {
 
 3162        'h' => $langs->trans(
'Hour'),
 
 3163        'd' => $langs->trans(
'Day'),
 
 3164        'w' => $langs->trans(
'Week'),
 
 3165        'm' => $langs->trans(
'Month'),
 
 3166        'y' => $langs->trans(
'Year')
 
 3168      if (isset($da[$outdurationunit])) {
 
 3169        $outvalUnits .= 
' - ' . $outdurationvalue . 
' ' . $langs->transnoentities($da[$outdurationunit] . ($outdurationvalue > 1 ? 
's' : 
''));
 
 3173    $opt = 
'<option value="' . $objp->rowid . 
'"';
 
 3174    $opt .= ($objp->rowid == $selected) ? 
' selected' : 
'';
 
 3175    if (!empty($objp->price_by_qty_rowid) && $objp->price_by_qty_rowid > 0) {
 
 3176      $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 . 
'"';
 
 3179      if ($user->hasRight(
'stock', 
'lire')) {
 
 3180        if ($objp->stock > 0) {
 
 3181          $opt .= 
' class="product_line_stock_ok"';
 
 3182        } elseif ($objp->stock <= 0) {
 
 3183          $opt .= 
' class="product_line_stock_too_low"';
 
 3188      $opt .= 
' data-labeltrans="' . $outlabel_translated . 
'"';
 
 3193    if (!empty($objp->custref)) {
 
 3194      $opt .= 
' (' . $objp->custref . 
')';
 
 3197      $opt .= 
' (' . $outbarcode . 
')';
 
 3199    $opt .= 
' - ' . 
dol_trunc($label, $maxlengtharticle);
 
 3201      $opt .= 
' (' . 
getCountry($outorigin, 1) . 
')';
 
 3204    $objRef = $objp->ref;
 
 3205    if (!empty($objp->custref)) {
 
 3206      $objRef .= 
' (' . $objp->custref . 
')';
 
 3208    if (!empty($filterkey) && $filterkey != 
'') {
 
 3209      $objRef = preg_replace(
'/(' . preg_quote($filterkey, 
'/') . 
')/i', 
'<strong>$1</strong>', $objRef, 1);
 
 3213      $outval .= 
' (' . $outbarcode . 
')';
 
 3215    $outval .= 
' - ' . 
dol_trunc($label, $maxlengtharticle);
 
 3217      $outval .= 
' (' . 
getCountry($outorigin, 1) . 
')';
 
 3221    $opt .= $outvalUnits;
 
 3222    $outval .= $outvalUnits;
 
 3229      $sql = 
"SELECT price, price_ttc, price_base_type, tva_tx, default_vat_code";
 
 3230      $sql .= 
" FROM " . $this->db->prefix() . 
"product_price";
 
 3231      $sql .= 
" WHERE fk_product = " . ((int) $objp->rowid);
 
 3232      $sql .= 
" AND entity IN (" . 
getEntity(
'productprice') . 
")";
 
 3233      $sql .= 
" AND price_level = " . ((int) $price_level);
 
 3234      $sql .= 
" ORDER BY date_price DESC, rowid DESC"; 
 
 3237      dol_syslog(get_class($this) . 
'::constructProductListOption search price for product ' . $objp->rowid . 
' AND level ' . $price_level, LOG_DEBUG);
 
 3238      $result2 = $this->db->query($sql);
 
 3240        $objp2 = $this->db->fetch_object($result2);
 
 3243          if ($objp2->price_base_type == 
'HT') {
 
 3244            $opt .= 
' - ' . 
price($objp2->price, 1, $langs, 0, 0, -1, $conf->currency) . 
' ' . $langs->trans(
"HT");
 
 3245            $outval .= 
' - ' . 
price($objp2->price, 0, $langs, 0, 0, -1, $conf->currency) . 
' ' . $langs->transnoentities(
"HT");
 
 3247            $opt .= 
' - ' . 
price($objp2->price_ttc, 1, $langs, 0, 0, -1, $conf->currency) . 
' ' . $langs->trans(
"TTC");
 
 3248            $outval .= 
' - ' . 
price($objp2->price_ttc, 0, $langs, 0, 0, -1, $conf->currency) . 
' ' . $langs->transnoentities(
"TTC");
 
 3250          $outprice_ht = 
price($objp2->price);
 
 3251          $outprice_ttc = 
price($objp2->price_ttc);
 
 3252          $outpricebasetype = $objp2->price_base_type;
 
 3254            $outtva_tx = $objp2->tva_tx;                        
 
 3255            $outdefault_vat_code = $objp2->default_vat_code;    
 
 3257            $outtva_tx = $objp->tva_tx;                            
 
 3258            $outdefault_vat_code = $objp->default_vat_code;        
 
 3267    if (empty($hidepriceinlabel) && !empty($objp->quantity) && $objp->quantity >= 1 && (
getDolGlobalString(
'PRODUIT_CUSTOMER_PRICES_BY_QTY') || 
getDolGlobalString(
'PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES'))) {
 
 3269      $outqty = $objp->quantity;
 
 3270      $outdiscount = $objp->remise_percent;
 
 3271      if ($objp->quantity == 1) {
 
 3272        $opt .= 
' - ' . 
price($objp->unitprice, 1, $langs, 0, 0, -1, $conf->currency) . 
"/";
 
 3273        $outval .= 
' - ' . 
price($objp->unitprice, 0, $langs, 0, 0, -1, $conf->currency) . 
"/";
 
 3274        $opt .= $langs->trans(
"Unit"); 
 
 3275        $outval .= $langs->transnoentities(
"Unit");
 
 3277        $opt .= 
' - ' . 
price($objp->price, 1, $langs, 0, 0, -1, $conf->currency) . 
"/" . $objp->quantity;
 
 3278        $outval .= 
' - ' . 
price($objp->price, 0, $langs, 0, 0, -1, $conf->currency) . 
"/" . $objp->quantity;
 
 3279        $opt .= $langs->trans(
"Units"); 
 
 3280        $outval .= $langs->transnoentities(
"Units");
 
 3283      $outprice_ht = 
price($objp->unitprice);
 
 3284      $outprice_ttc = 
price($objp->unitprice * (1 + ($objp->tva_tx / 100)));
 
 3285      $outpricebasetype = $objp->price_base_type;
 
 3286      $outtva_tx = $objp->tva_tx;                            
 
 3287      $outdefault_vat_code = $objp->default_vat_code;        
 
 3289    if (empty($hidepriceinlabel) && !empty($objp->quantity) && $objp->quantity >= 1) {
 
 3290      $opt .= 
" (" . 
price($objp->unitprice, 1, $langs, 0, 0, -1, $conf->currency) . 
"/" . $langs->trans(
"Unit") . 
")"; 
 
 3291      $outval .= 
" (" . 
price($objp->unitprice, 0, $langs, 0, 0, -1, $conf->currency) . 
"/" . $langs->transnoentities(
"Unit") . 
")"; 
 
 3293    if (empty($hidepriceinlabel) && !empty($objp->remise_percent) && $objp->remise_percent >= 1) {
 
 3294      $opt .= 
" - " . $langs->trans(
"Discount") . 
" : " . 
vatrate($objp->remise_percent) . 
' %';
 
 3295      $outval .= 
" - " . $langs->transnoentities(
"Discount") . 
" : " . 
vatrate($objp->remise_percent) . 
' %';
 
 3300      if (!empty($objp->idprodcustprice)) {
 
 3303        if ($objp->custprice_base_type == 
'HT') {
 
 3304          $opt .= 
' - ' . 
price($objp->custprice, 1, $langs, 0, 0, -1, $conf->currency) . 
' ' . $langs->trans(
"HT");
 
 3305          $outval .= 
' - ' . 
price($objp->custprice, 0, $langs, 0, 0, -1, $conf->currency) . 
' ' . $langs->transnoentities(
"HT");
 
 3307          $opt .= 
' - ' . 
price($objp->custprice_ttc, 1, $langs, 0, 0, -1, $conf->currency) . 
' ' . $langs->trans(
"TTC");
 
 3308          $outval .= 
' - ' . 
price($objp->custprice_ttc, 0, $langs, 0, 0, -1, $conf->currency) . 
' ' . $langs->transnoentities(
"TTC");
 
 3311        $outprice_ht = 
price($objp->custprice);
 
 3312        $outprice_ttc = 
price($objp->custprice_ttc);
 
 3313        $outpricebasetype = $objp->custprice_base_type;
 
 3314        $outtva_tx = $objp->custtva_tx;
 
 3315        $outdefault_vat_code = $objp->custdefault_vat_code;
 
 3320    if (empty($hidepriceinlabel) && !$found) {
 
 3321      if ($objp->price_base_type == 
'HT') {
 
 3322        $opt .= 
' - ' . 
price($objp->price, 1, $langs, 0, 0, -1, $conf->currency) . 
' ' . $langs->trans(
"HT");
 
 3323        $outval .= 
' - ' . 
price($objp->price, 0, $langs, 0, 0, -1, $conf->currency) . 
' ' . $langs->transnoentities(
"HT");
 
 3325        $opt .= 
' - ' . 
price($objp->price_ttc, 1, $langs, 0, 0, -1, $conf->currency) . 
' ' . $langs->trans(
"TTC");
 
 3326        $outval .= 
' - ' . 
price($objp->price_ttc, 0, $langs, 0, 0, -1, $conf->currency) . 
' ' . $langs->transnoentities(
"TTC");
 
 3328      $outprice_ht = 
price($objp->price);
 
 3329      $outprice_ttc = 
price($objp->price_ttc);
 
 3330      $outpricebasetype = $objp->price_base_type;
 
 3331      $outtva_tx = $objp->tva_tx;
 
 3332      $outdefault_vat_code = $objp->default_vat_code;
 
 3336      if ($user->hasRight(
'stock', 
'lire')) {
 
 3337        $opt .= 
' - ' . $langs->trans(
"Stock") . 
': ' . 
price(
price2num($objp->stock, 
'MS'), 0, $langs, 0, 0);
 
 3339        if ($objp->stock > 0) {
 
 3340          $outval .= 
' - <span class="product_line_stock_ok">';
 
 3341        } elseif ($objp->stock <= 0) {
 
 3342          $outval .= 
' - <span class="product_line_stock_too_low">';
 
 3344        $outval .= $langs->transnoentities(
"Stock") . 
': ' . 
price(
price2num($objp->stock, 
'MS'));
 
 3345        $outval .= 
'</span>';
 
 3346        if (empty($novirtualstock) && 
getDolGlobalString(
'STOCK_SHOW_VIRTUAL_STOCK_IN_PRODUCTS_COMBO')) {  
 
 3347          $langs->load(
"stocks");
 
 3349          $tmpproduct = 
new Product($this->db);
 
 3350          $tmpproduct->fetch($objp->rowid, 
'', 
'', 
'', 1, 1, 1); 
 
 3351          $tmpproduct->load_virtual_stock();
 
 3352          $virtualstock = $tmpproduct->stock_theorique;
 
 3354          $opt .= 
' - ' . $langs->trans(
"VirtualStock") . 
':' . $virtualstock;
 
 3356          $outval .= 
' - ' . $langs->transnoentities(
"VirtualStock") . 
':';
 
 3357          if ($virtualstock > 0) {
 
 3358            $outval .= 
'<span class="product_line_stock_ok">';
 
 3359          } elseif ($virtualstock <= 0) {
 
 3360            $outval .= 
'<span class="product_line_stock_too_low">';
 
 3362          $outval .= $virtualstock;
 
 3363          $outval .= 
'</span>';
 
 3370    $parameters = array(
'objp'=>$objp);
 
 3371    $reshook = $hookmanager->executeHooks(
'constructProductListOption', $parameters); 
 
 3372    if (empty($reshook)) {
 
 3373      $opt .= $hookmanager->resPrint;
 
 3375      $opt = $hookmanager->resPrint;
 
 3378    $opt .= 
"</option>\n";
 
 3383      'label2' => $outlabel,
 
 3387      'price_ttc' => 
price2num($outprice_ttc),
 
 3390      'pricebasetype' => $outpricebasetype,
 
 3391      'tva_tx' => $outtva_tx,
 
 3392      'default_vat_code' => $outdefault_vat_code,
 
 3394      'discount' => $outdiscount,
 
 3395      'duration_value' => $outdurationvalue,
 
 3396      'duration_unit' => $outdurationunit,
 
 3398      'labeltrans' => $outlabel_translated,
 
 3399      'desctrans' => $outdesc_translated,
 
 3400      'ref_customer' => $outrefcust
 
 
 3421  public function select_produits_fournisseurs($socid, $selected = 
'', $htmlname = 
'productid', $filtertype = 
'', $filtre = 
'', $ajaxoptions = array(), $hidelabel = 0, $alsoproductwithnosupplierprice = 0, $morecss = 
'', $placeholder = 
'')
 
 3424    global $langs, $conf;
 
 3425    global $price_level, $status, $finished;
 
 3427    if (!isset($status)) {
 
 3431    $selected_input_value = 
'';
 
 3432    if (!empty($conf->use_javascript_ajax) && 
getDolGlobalString(
'PRODUIT_USE_SEARCH_TO_SELECT')) {
 
 3433      if ($selected > 0) {
 
 3434        require_once DOL_DOCUMENT_ROOT . 
'/product/class/product.class.php';
 
 3435        $producttmpselect = 
new Product($this->db);
 
 3436        $producttmpselect->fetch($selected);
 
 3437        $selected_input_value = $producttmpselect->ref;
 
 3438        unset($producttmpselect);
 
 3442      $urloption = ($socid > 0 ? 
'socid=' . $socid . 
'&' : 
'') . 
'htmlname=' . $htmlname . 
'&outjson=1&price_level=' . $price_level . 
'&type=' . $filtertype . 
'&mode=2&status=' . $status . 
'&finished=' . $finished . 
'&alsoproductwithnosupplierprice=' . $alsoproductwithnosupplierprice;
 
 3443      print 
ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT . 
'/product/ajax/products.php', $urloption, $conf->global->PRODUIT_USE_SEARCH_TO_SELECT, 0, $ajaxoptions);
 
 3445      print($hidelabel ? 
'' : $langs->trans(
"RefOrLabel") . 
' : ') . 
'<input type="text" class="minwidth300" name="search_' . $htmlname . 
'" id="search_' . $htmlname . 
'" value="' . $selected_input_value . 
'"' . ($placeholder ? 
' placeholder="' . $placeholder . 
'"' : 
'') . 
'>';
 
 3447      print $this->
select_produits_fournisseurs_list($socid, $selected, $htmlname, $filtertype, $filtre, 
'', $status, 0, 0, $alsoproductwithnosupplierprice, $morecss, 0, $placeholder);
 
 
 3471  public function select_produits_fournisseurs_list($socid, $selected = 
'', $htmlname = 
'productid', $filtertype = 
'', $filtre = 
'', $filterkey = 
'', $statut = -1, $outputmode = 0, $limit = 100, $alsoproductwithnosupplierprice = 0, $morecss = 
'', $showstockinlist = 0, $placeholder = 
'')
 
 3474    global $langs, $conf, $user;
 
 3475    global $hookmanager;
 
 3478    $outarray = array();
 
 3480    $maxlengtharticle = (!
getDolGlobalString(
'PRODUCT_MAX_LENGTH_COMBO') ? 48 : $conf->global->PRODUCT_MAX_LENGTH_COMBO);
 
 3482    $langs->load(
'stocks');
 
 3485      $langs->load(
'other');
 
 3488    $sql = 
"SELECT p.rowid, p.ref, p.label, p.price, p.duration, p.fk_product_type, p.stock, p.tva_tx as tva_tx_sale, p.default_vat_code as default_vat_code_sale,";
 
 3489    $sql .= 
" pfp.ref_fourn, pfp.rowid as idprodfournprice, pfp.price as fprice, pfp.quantity, pfp.remise_percent, pfp.remise, pfp.unitprice";
 
 3490    $sql .= 
", pfp.multicurrency_code, pfp.multicurrency_unitprice";
 
 3491    $sql .= 
", pfp.fk_supplier_price_expression, pfp.fk_product, pfp.tva_tx, pfp.default_vat_code, pfp.fk_soc, s.nom as name";
 
 3492    $sql .= 
", pfp.supplier_reputation";
 
 3495      $sql .= 
", pfp.desc_fourn as description";
 
 3497      $sql .= 
", p.description";
 
 3501      $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";
 
 3503    if (isModEnabled(
'barcode')) {
 
 3504      $sql .= 
", pfp.barcode";
 
 3506    $sql .= 
" FROM " . $this->db->prefix() . 
"product as p";
 
 3507    $sql .= 
" LEFT JOIN " . $this->db->prefix() . 
"product_fournisseur_price as pfp ON ( p.rowid = pfp.fk_product AND pfp.entity IN (" . 
getEntity(
'product') . 
") )";
 
 3509      $sql .= 
" AND pfp.fk_soc = " . ((int) $socid);
 
 3511    $sql .= 
" LEFT JOIN " . $this->db->prefix() . 
"societe as s ON pfp.fk_soc = s.rowid";
 
 3514      $sql .= 
" LEFT JOIN " . $this->db->prefix() . 
"c_units u ON u.rowid = p.fk_unit";
 
 3516    $sql .= 
" WHERE p.entity IN (" . 
getEntity(
'product') . 
")";
 
 3517    if ($statut != -1) {
 
 3518      $sql .= 
" AND p.tobuy = " . ((int) $statut);
 
 3520    if (strval($filtertype) != 
'') {
 
 3521      $sql .= 
" AND p.fk_product_type = " . ((int) $filtertype);
 
 3523    if (!empty($filtre)) {
 
 3524      $sql .= 
" " . $filtre;
 
 3527    $parameters = array();
 
 3528    $reshook = $hookmanager->executeHooks(
'selectSuppliersProductsListWhere', $parameters); 
 
 3529    $sql .= $hookmanager->resPrint;
 
 3531    if ($filterkey != 
'') {
 
 3535      $scrit = explode(
' ', $filterkey);
 
 3537      if (count($scrit) > 1) {
 
 3540      foreach ($scrit as $crit) {
 
 3544        $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) . 
"%'";
 
 3546          $sql .= 
" OR pfp.desc_fourn LIKE '" . $this->db->escape($prefix . $crit) . 
"%'";
 
 3551      if (count($scrit) > 1) {
 
 3554      if (isModEnabled(
'barcode')) {
 
 3555        $sql .= 
" OR p.barcode LIKE '" . $this->db->escape($prefix . $filterkey) . 
"%'";
 
 3556        $sql .= 
" OR pfp.barcode LIKE '" . $this->db->escape($prefix . $filterkey) . 
"%'";
 
 3560    $sql .= 
" ORDER BY pfp.ref_fourn DESC, pfp.quantity ASC";
 
 3561    $sql .= $this->db->plimit($limit, 0);
 
 3565    dol_syslog(get_class($this) . 
"::select_produits_fournisseurs_list", LOG_DEBUG);
 
 3566    $result = $this->db->query($sql);
 
 3568      require_once DOL_DOCUMENT_ROOT . 
'/product/dynamic_price/class/price_parser.class.php';
 
 3569      require_once DOL_DOCUMENT_ROOT . 
'/core/lib/product.lib.php';
 
 3571      $num = $this->db->num_rows($result);
 
 3574      $out .= 
'<select class="flat ' . ($morecss ? 
' ' . $morecss : 
'') . 
'" id="' . $htmlname . 
'" name="' . $htmlname . 
'">';
 
 3576        $out .= 
'<option value="-1" selected>' . ($placeholder ? $placeholder : 
' ') . 
'</option>';
 
 3578        $out .= 
'<option value="-1">' . ($placeholder ? $placeholder : 
' ') . 
'</option>';
 
 3583        $objp = $this->db->fetch_object($result);
 
 3585        if (is_null($objp->idprodfournprice)) {
 
 3587          $objp->tva_tx = $objp->tva_tx_sale;
 
 3588          $objp->default_vat_code = $objp->default_vat_code_sale;
 
 3591        $outkey = $objp->idprodfournprice; 
 
 3592        if (!$outkey && $alsoproductwithnosupplierprice) {
 
 3593          $outkey = 
'idprod_' . $objp->rowid; 
 
 3596        $outref = $objp->ref;
 
 3597        $outbarcode = $objp->barcode;
 
 3600        $outtype = $objp->fk_product_type;
 
 3607          if (!empty($objp->unit_short)) {
 
 3608            $outvalUnits .= 
' - ' . $objp->unit_short;
 
 3610          if (!empty($objp->weight) && $objp->weight_units !== 
null) {
 
 3612            $outvalUnits .= 
' - ' . $unitToShow;
 
 3614          if ((!empty($objp->length) || !empty($objp->width) || !empty($objp->height)) && $objp->length_units !== 
null) {
 
 3615            $unitToShow = $objp->length . 
' x ' . $objp->width . 
' x ' . $objp->height . 
' ' . 
measuringUnitString(0, 
'size', $objp->length_units);
 
 3616            $outvalUnits .= 
' - ' . $unitToShow;
 
 3618          if (!empty($objp->surface) && $objp->surface_units !== 
null) {
 
 3620            $outvalUnits .= 
' - ' . $unitToShow;
 
 3622          if (!empty($objp->volume) && $objp->volume_units !== 
null) {
 
 3624            $outvalUnits .= 
' - ' . $unitToShow;
 
 3626          if ($outdurationvalue && $outdurationunit) {
 
 3628              'h' => $langs->trans(
'Hour'),
 
 3629              'd' => $langs->trans(
'Day'),
 
 3630              'w' => $langs->trans(
'Week'),
 
 3631              'm' => $langs->trans(
'Month'),
 
 3632              'y' => $langs->trans(
'Year')
 
 3634            if (isset($da[$outdurationunit])) {
 
 3635              $outvalUnits .= 
' - ' . $outdurationvalue . 
' ' . $langs->transnoentities($da[$outdurationunit] . ($outdurationvalue > 1 ? 
's' : 
''));
 
 3640        $objRef = $objp->ref;
 
 3641        if ($filterkey && $filterkey != 
'') {
 
 3642          $objRef = preg_replace(
'/(' . preg_quote($filterkey, 
'/') . 
')/i', 
'<strong>$1</strong>', $objRef, 1);
 
 3644        $objRefFourn = $objp->ref_fourn;
 
 3645        if ($filterkey && $filterkey != 
'') {
 
 3646          $objRefFourn = preg_replace(
'/(' . preg_quote($filterkey, 
'/') . 
')/i', 
'<strong>$1</strong>', $objRefFourn, 1);
 
 3648        $label = $objp->label;
 
 3649        if ($filterkey && $filterkey != 
'') {
 
 3650          $label = preg_replace(
'/(' . preg_quote($filterkey, 
'/') . 
')/i', 
'<strong>$1</strong>', $label, 1);
 
 3653        switch ($objp->fk_product_type) {
 
 3665        if (empty($picto)) {
 
 3668          $optlabel = 
img_object(
'', $picto, 
'class="paddingright classfortooltip"', 0, 0, 1);
 
 3671        $optlabel .= $objp->ref;
 
 3672        if (!empty($objp->idprodfournprice) && ($objp->ref != $objp->ref_fourn)) {
 
 3673          $optlabel .= 
' <span class="opacitymedium">(' . $objp->ref_fourn . 
')</span>';
 
 3675        if (isModEnabled(
'barcode') && !empty($objp->barcode)) {
 
 3676          $optlabel .= 
' (' . $outbarcode . 
')';
 
 3678        $optlabel .= 
' - ' . 
dol_trunc($label, $maxlengtharticle);
 
 3680        $outvallabel = $objRef;
 
 3681        if (!empty($objp->idprodfournprice) && ($objp->ref != $objp->ref_fourn)) {
 
 3682          $outvallabel .= 
' (' . $objRefFourn . 
')';
 
 3684        if (isModEnabled(
'barcode') && !empty($objp->barcode)) {
 
 3685          $outvallabel .= 
' (' . $outbarcode . 
')';
 
 3687        $outvallabel .= 
' - ' . 
dol_trunc($label, $maxlengtharticle);
 
 3690        $optlabel .= $outvalUnits;
 
 3691        $outvallabel .= $outvalUnits;
 
 3693        if (!empty($objp->idprodfournprice)) {
 
 3694          $outqty = $objp->quantity;
 
 3695          $outdiscount = $objp->remise_percent;
 
 3696          if (isModEnabled(
'dynamicprices') && !empty($objp->fk_supplier_price_expression)) {
 
 3698            $prod_supplier->product_fourn_price_id = $objp->idprodfournprice;
 
 3699            $prod_supplier->id = $objp->fk_product;
 
 3700            $prod_supplier->fourn_qty = $objp->quantity;
 
 3701            $prod_supplier->fourn_tva_tx = $objp->tva_tx;
 
 3702            $prod_supplier->fk_supplier_price_expression = $objp->fk_supplier_price_expression;
 
 3704            require_once DOL_DOCUMENT_ROOT . 
'/product/dynamic_price/class/price_parser.class.php';
 
 3706            $price_result = $priceparser->parseProductSupplier($prod_supplier);
 
 3707            if ($price_result >= 0) {
 
 3708              $objp->fprice = $price_result;
 
 3709              if ($objp->quantity >= 1) {
 
 3710                $objp->unitprice = $objp->fprice / $objp->quantity; 
 
 3714          if ($objp->quantity == 1) {
 
 3715            $optlabel .= 
' - ' . 
price($objp->fprice * (
getDolGlobalString(
'DISPLAY_DISCOUNTED_SUPPLIER_PRICE') ? (1 - $objp->remise_percent / 100) : 1), 1, $langs, 0, 0, -1, $conf->currency) . 
"/";
 
 3716            $outvallabel .= 
' - ' . 
price($objp->fprice * (
getDolGlobalString(
'DISPLAY_DISCOUNTED_SUPPLIER_PRICE') ? (1 - $objp->remise_percent / 100) : 1), 0, $langs, 0, 0, -1, $conf->currency) . 
"/";
 
 3717            $optlabel .= $langs->trans(
"Unit"); 
 
 3718            $outvallabel .= $langs->transnoentities(
"Unit");
 
 3720            $optlabel .= 
' - ' . 
price($objp->fprice * (
getDolGlobalString(
'DISPLAY_DISCOUNTED_SUPPLIER_PRICE') ? (1 - $objp->remise_percent / 100) : 1), 1, $langs, 0, 0, -1, $conf->currency) . 
"/" . $objp->quantity;
 
 3721            $outvallabel .= 
' - ' . 
price($objp->fprice * (
getDolGlobalString(
'DISPLAY_DISCOUNTED_SUPPLIER_PRICE') ? (1 - $objp->remise_percent / 100) : 1), 0, $langs, 0, 0, -1, $conf->currency) . 
"/" . $objp->quantity;
 
 3722            $optlabel .= 
' ' . $langs->trans(
"Units"); 
 
 3723            $outvallabel .= 
' ' . $langs->transnoentities(
"Units");
 
 3726          if ($objp->quantity > 1) {
 
 3727            $optlabel .= 
" (" . 
price($objp->unitprice * (
getDolGlobalString(
'DISPLAY_DISCOUNTED_SUPPLIER_PRICE') ? (1 - $objp->remise_percent / 100) : 1), 1, $langs, 0, 0, -1, $conf->currency) . 
"/" . $langs->trans(
"Unit") . 
")"; 
 
 3728            $outvallabel .= 
" (" . 
price($objp->unitprice * (
getDolGlobalString(
'DISPLAY_DISCOUNTED_SUPPLIER_PRICE') ? (1 - $objp->remise_percent / 100) : 1), 0, $langs, 0, 0, -1, $conf->currency) . 
"/" . $langs->transnoentities(
"Unit") . 
")"; 
 
 3730          if ($objp->remise_percent >= 1) {
 
 3731            $optlabel .= 
" - " . $langs->trans(
"Discount") . 
" : " . 
vatrate($objp->remise_percent) . 
' %';
 
 3732            $outvallabel .= 
" - " . $langs->transnoentities(
"Discount") . 
" : " . 
vatrate($objp->remise_percent) . 
' %';
 
 3734          if ($objp->duration) {
 
 3735            $optlabel .= 
" - " . $objp->duration;
 
 3736            $outvallabel .= 
" - " . $objp->duration;
 
 3739            $optlabel .= 
" - " . 
dol_trunc($objp->name, 8);
 
 3740            $outvallabel .= 
" - " . 
dol_trunc($objp->name, 8);
 
 3742          if ($objp->supplier_reputation) {
 
 3744            $reputations = array(
'' => $langs->trans(
'Standard'), 
'FAVORITE' => $langs->trans(
'Favorite'), 
'NOTTHGOOD' => $langs->trans(
'NotTheGoodQualitySupplier'), 
'DONOTORDER' => $langs->trans(
'DoNotOrderThisProductToThisSupplier'));
 
 3746            $optlabel .= 
" - " . $reputations[$objp->supplier_reputation];
 
 3747            $outvallabel .= 
" - " . $reputations[$objp->supplier_reputation];
 
 3750          if (empty($alsoproductwithnosupplierprice)) {     
 
 3751            $optlabel .= 
" - <span class='opacitymedium'>" . $langs->trans(
"NoPriceDefinedForThisSupplier") . 
'</span>';
 
 3752            $outvallabel .= 
' - ' . $langs->transnoentities(
"NoPriceDefinedForThisSupplier");
 
 3754            $optlabel .= 
" - <span class='opacitymedium'>" . $langs->trans(
"NoPriceDefinedForThisSupplier") . 
'</span>';
 
 3755            $outvallabel .= 
' - ' . $langs->transnoentities(
"NoPriceDefinedForThisSupplier");
 
 3760          $novirtualstock = ($showstockinlist == 2);
 
 3762          if ($user->hasRight(
'stock', 
'lire')) {
 
 3763            $outvallabel .= 
' - ' . $langs->trans(
"Stock") . 
': ' . 
price(
price2num($objp->stock, 
'MS'));
 
 3765            if ($objp->stock > 0) {
 
 3766              $optlabel .= 
' - <span class="product_line_stock_ok">';
 
 3767            } elseif ($objp->stock <= 0) {
 
 3768              $optlabel .= 
' - <span class="product_line_stock_too_low">';
 
 3770            $optlabel .= $langs->transnoentities(
"Stock") . 
':' . 
price(
price2num($objp->stock, 
'MS'));
 
 3771            $optlabel .= 
'</span>';
 
 3772            if (empty($novirtualstock) && 
getDolGlobalString(
'STOCK_SHOW_VIRTUAL_STOCK_IN_PRODUCTS_COMBO')) {  
 
 3773              $langs->load(
"stocks");
 
 3775              $tmpproduct = 
new Product($this->db);
 
 3776              $tmpproduct->fetch($objp->rowid, 
'', 
'', 
'', 1, 1, 1); 
 
 3777              $tmpproduct->load_virtual_stock();
 
 3778              $virtualstock = $tmpproduct->stock_theorique;
 
 3780              $outvallabel .= 
' - ' . $langs->trans(
"VirtualStock") . 
':' . $virtualstock;
 
 3782              $optlabel .= 
' - ' . $langs->transnoentities(
"VirtualStock") . 
':';
 
 3783              if ($virtualstock > 0) {
 
 3784                $optlabel .= 
'<span class="product_line_stock_ok">';
 
 3785              } elseif ($virtualstock <= 0) {
 
 3786                $optlabel .= 
'<span class="product_line_stock_too_low">';
 
 3788              $optlabel .= $virtualstock;
 
 3789              $optlabel .= 
'</span>';
 
 3796        $optstart = 
'<option value="' . $outkey . 
'"';
 
 3797        if ($selected && $selected == $objp->idprodfournprice) {
 
 3798          $optstart .= 
' selected';
 
 3800        if (empty($objp->idprodfournprice) && empty($alsoproductwithnosupplierprice)) {
 
 3801          $optstart .= 
' disabled';
 
 3804        if (!empty($objp->idprodfournprice) && $objp->idprodfournprice > 0) {
 
 3813          $optstart .= 
' data-default-vat-code="' . 
dol_escape_htmltag($objp->default_vat_code) . 
'"';
 
 3815          if (isModEnabled(
'multicurrency')) {
 
 3816            $optstart .= 
' data-multicurrency-code="' . 
dol_escape_htmltag($objp->multicurrency_code) . 
'"';
 
 3817            $optstart .= 
' data-multicurrency-unitprice="' . 
dol_escape_htmltag($objp->multicurrency_unitprice) . 
'"';
 
 3820        $optstart .= 
' data-description="' . 
dol_escape_htmltag($objp->description, 0, 1) . 
'"';
 
 3822        $outarrayentry = array(
 
 3825          'label' => $outvallabel,
 
 3827          'price_qty_ht' => 
price2num($objp->fprice, 
'MU'),    
 
 3828          'price_unit_ht' => 
price2num($objp->unitprice, 
'MU'),    
 
 3829          'price_ht' => 
price2num($objp->unitprice, 
'MU'),        
 
 3830          'tva_tx_formated' => 
price($objp->tva_tx, 0, $langs, 1, -1, 2),
 
 3832          'default_vat_code' => $objp->default_vat_code,
 
 3833          'discount' => $outdiscount,
 
 3835          'duration_value' => $outdurationvalue,
 
 3836          'duration_unit' => $outdurationunit,
 
 3837          'disabled' => (empty($objp->idprodfournprice) ? 
true : 
false),
 
 3838          'description' => $objp->description
 
 3840        if (isModEnabled(
'multicurrency')) {
 
 3841          $outarrayentry[
'multicurrency_code'] = $objp->multicurrency_code;
 
 3842          $outarrayentry[
'multicurrency_unitprice'] = 
price2num($objp->multicurrency_unitprice, 
'MU');
 
 3845        $parameters = array(
 
 3847          'optstart' => &$optstart,
 
 3848          'optlabel' => &$optlabel,
 
 3849          'outvallabel' => &$outvallabel,
 
 3850          'outarrayentry' => &$outarrayentry
 
 3852        $reshook = $hookmanager->executeHooks(
'selectProduitsFournisseurListOption', $parameters, $this);
 
 3858        $out .= $optstart . 
' data-html="' . 
dol_escape_htmltag($optlabel) . 
'">' . $optlabel . 
"</option>\n";
 
 3859        $outarraypush = array(
 
 3862          'label' => $outvallabel,
 
 3864          'price_qty_ht' => 
price2num($objp->fprice, 
'MU'),        
 
 3865          'price_qty_ht_locale' => 
price($objp->fprice),
 
 3866          'price_unit_ht' => 
price2num($objp->unitprice, 
'MU'),    
 
 3867          'price_unit_ht_locale' => 
price($objp->unitprice),
 
 3868          'price_ht' => 
price2num($objp->unitprice, 
'MU'),        
 
 3869          'tva_tx_formated' => 
price($objp->tva_tx),
 
 3871          'default_vat_code' => $objp->default_vat_code,
 
 3872          'discount' => $outdiscount,
 
 3874          'duration_value' => $outdurationvalue,
 
 3875          'duration_unit' => $outdurationunit,
 
 3876          'disabled' => (empty($objp->idprodfournprice) ? 
true : 
false),
 
 3877          'description' => $objp->description
 
 3879        if (isModEnabled(
'multicurrency')) {
 
 3880          $outarraypush[
'multicurrency_code'] = $objp->multicurrency_code;
 
 3881          $outarraypush[
'multicurrency_unitprice'] = 
price2num($objp->multicurrency_unitprice, 
'MU');
 
 3883        array_push($outarray, $outarraypush);
 
 3896      $out .= 
'</select>';
 
 3898      $this->db->free($result);
 
 3900      include_once DOL_DOCUMENT_ROOT . 
'/core/lib/ajax.lib.php';
 
 3906    if (empty($outputmode)) {
 
 
 3925    global $langs, $conf;
 
 3927    $langs->load(
'stocks');
 
 3929    $sql = 
"SELECT p.rowid, p.ref, p.label, p.price, p.duration, pfp.fk_soc,";
 
 3930    $sql .= 
" pfp.ref_fourn, pfp.rowid as idprodfournprice, pfp.price as fprice, pfp.remise_percent, pfp.quantity, pfp.unitprice,";
 
 3931    $sql .= 
" pfp.fk_supplier_price_expression, pfp.fk_product, pfp.tva_tx, s.nom as name";
 
 3932    $sql .= 
" FROM " . $this->db->prefix() . 
"product as p";
 
 3933    $sql .= 
" LEFT JOIN " . $this->db->prefix() . 
"product_fournisseur_price as pfp ON p.rowid = pfp.fk_product";
 
 3934    $sql .= 
" LEFT JOIN " . $this->db->prefix() . 
"societe as s ON pfp.fk_soc = s.rowid";
 
 3935    $sql .= 
" WHERE pfp.entity IN (" . 
getEntity(
'productsupplierprice') . 
")";
 
 3936    $sql .= 
" AND p.tobuy = 1";
 
 3937    $sql .= 
" AND s.fournisseur = 1";
 
 3938    $sql .= 
" AND p.rowid = " . ((int) $productid);
 
 3940      $sql .= 
" ORDER BY s.nom, pfp.ref_fourn DESC";
 
 3942      $sql .= 
" ORDER BY pfp.unitprice ASC";
 
 3945    dol_syslog(get_class($this) . 
"::select_product_fourn_price", LOG_DEBUG);
 
 3946    $result = $this->db->query($sql);
 
 3949      $num = $this->db->num_rows($result);
 
 3951      $form = 
'<select class="flat" id="select_' . $htmlname . 
'" name="' . $htmlname . 
'">';
 
 3954        $form .= 
'<option value="0">-- ' . $langs->trans(
"NoSupplierPriceDefinedForThisProduct") . 
' --</option>';
 
 3956        require_once DOL_DOCUMENT_ROOT . 
'/product/dynamic_price/class/price_parser.class.php';
 
 3957        $form .= 
'<option value="0"> </option>';
 
 3961          $objp = $this->db->fetch_object($result);
 
 3963          $opt = 
'<option value="' . $objp->idprodfournprice . 
'"';
 
 3965          if ($num == 1 || ($selected_supplier > 0 && $objp->fk_soc == $selected_supplier) || ($i == 0 && 
getDolGlobalString(
'PRODUCT_BEST_SUPPLIER_PRICE_PRESELECTED'))) {
 
 3966            $opt .= 
' selected';
 
 3968          $opt .= 
'>' . $objp->name . 
' - ' . $objp->ref_fourn . 
' - ';
 
 3970          if (isModEnabled(
'dynamicprices') && !empty($objp->fk_supplier_price_expression)) {
 
 3972            $prod_supplier->product_fourn_price_id = $objp->idprodfournprice;
 
 3973            $prod_supplier->id = $productid;
 
 3974            $prod_supplier->fourn_qty = $objp->quantity;
 
 3975            $prod_supplier->fourn_tva_tx = $objp->tva_tx;
 
 3976            $prod_supplier->fk_supplier_price_expression = $objp->fk_supplier_price_expression;
 
 3978            require_once DOL_DOCUMENT_ROOT . 
'/product/dynamic_price/class/price_parser.class.php';
 
 3980            $price_result = $priceparser->parseProductSupplier($prod_supplier);
 
 3981            if ($price_result >= 0) {
 
 3982              $objp->fprice = $price_result;
 
 3983              if ($objp->quantity >= 1) {
 
 3984                $objp->unitprice = $objp->fprice / $objp->quantity;
 
 3988          if ($objp->quantity == 1) {
 
 3989            $opt .= 
price($objp->fprice * (
getDolGlobalString(
'DISPLAY_DISCOUNTED_SUPPLIER_PRICE') ? (1 - $objp->remise_percent / 100) : 1), 1, $langs, 0, 0, -1, $conf->currency) . 
"/";
 
 3992          $opt .= $objp->quantity . 
' ';
 
 3994          if ($objp->quantity == 1) {
 
 3995            $opt .= $langs->trans(
"Unit");
 
 3997            $opt .= $langs->trans(
"Units");
 
 3999          if ($objp->quantity > 1) {
 
 4001            $opt .= 
price($objp->unitprice * (
getDolGlobalString(
'DISPLAY_DISCOUNTED_SUPPLIER_PRICE') ? (1 - $objp->remise_percent / 100) : 1), 1, $langs, 0, 0, -1, $conf->currency) . 
"/" . $langs->trans(
"Unit");
 
 4003          if ($objp->duration) {
 
 4004            $opt .= 
" - " . $objp->duration;
 
 4006          $opt .= 
"</option>\n";
 
 4013      $form .= 
'</select>';
 
 4014      $this->db->free($result);
 
 
 4034    $num = count($this->cache_conditions_paiements);
 
 4041    $sql = 
"SELECT rowid, code, libelle as label, deposit_percent";
 
 4042    $sql .= 
" FROM " . $this->db->prefix() . 
'c_payment_term';
 
 4043    $sql .= 
" WHERE entity IN (" . 
getEntity(
'c_payment_term') . 
")";
 
 4044    $sql .= 
" AND active > 0";
 
 4045    $sql .= 
" ORDER BY sortorder";
 
 4047    $resql = $this->db->query($sql);
 
 4049      $num = $this->db->num_rows($resql);
 
 4052        $obj = $this->db->fetch_object($resql);
 
 4055        $label = ($langs->trans(
"PaymentConditionShort" . $obj->code) != 
"PaymentConditionShort" . $obj->code ? $langs->trans(
"PaymentConditionShort" . $obj->code) : ($obj->label != 
'-' ? $obj->label : 
''));
 
 4056        $this->cache_conditions_paiements[$obj->rowid][
'code'] = $obj->code;
 
 4057        $this->cache_conditions_paiements[$obj->rowid][
'label'] = $label;
 
 4058        $this->cache_conditions_paiements[$obj->rowid][
'deposit_percent'] = $obj->deposit_percent;
 
 
 4083    $num = count($this->cache_availability);    
 
 4090    $langs->load(
'propal');
 
 4092    $sql = 
"SELECT rowid, code, label, position";
 
 4093    $sql .= 
" FROM " . $this->db->prefix() . 
'c_availability';
 
 4094    $sql .= 
" WHERE active > 0";
 
 4096    $resql = $this->db->query($sql);
 
 4098      $num = $this->db->num_rows($resql);
 
 4101        $obj = $this->db->fetch_object($resql);
 
 4104        $label = ($langs->trans(
"AvailabilityType" . $obj->code) != 
"AvailabilityType" . $obj->code ? $langs->trans(
"AvailabilityType" . $obj->code) : ($obj->label != 
'-' ? $obj->label : 
''));
 
 4105        $this->cache_availability[$obj->rowid][
'code'] = $obj->code;
 
 4106        $this->cache_availability[$obj->rowid][
'label'] = $label;
 
 4107        $this->cache_availability[$obj->rowid][
'position'] = $obj->position;
 
 4111      $this->cache_availability = 
dol_sort_array($this->cache_availability, 
'position', 
'asc', 0, 0, 1);
 
 
 4132    global $langs, $user;
 
 4136    dol_syslog(__METHOD__ . 
" selected=" . $selected . 
", htmlname=" . $htmlname, LOG_DEBUG);
 
 4138    print 
'<select id="' . $htmlname . 
'" class="flat' . ($morecss ? 
' ' . $morecss : 
'') . 
'" name="' . $htmlname . 
'">';
 
 4140      print 
'<option value="0"> </option>';
 
 4142    foreach ($this->cache_availability as $id => $arrayavailability) {
 
 4143      if ($selected == $id) {
 
 4144        print 
'<option value="' . $id . 
'" selected>';
 
 4146        print 
'<option value="' . $id . 
'">';
 
 4153      print 
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
 
 
 4167    $num = count($this->cache_demand_reason);    
 
 4172    $sql = 
"SELECT rowid, code, label";
 
 4173    $sql .= 
" FROM " . $this->db->prefix() . 
'c_input_reason';
 
 4174    $sql .= 
" WHERE active > 0";
 
 4176    $resql = $this->db->query($sql);
 
 4178      $num = $this->db->num_rows($resql);
 
 4180      $tmparray = array();
 
 4182        $obj = $this->db->fetch_object($resql);
 
 4185        $label = ($obj->label != 
'-' ? $obj->label : 
'');
 
 4186        if ($langs->trans(
"DemandReasonType" . $obj->code) != 
"DemandReasonType" . $obj->code) {
 
 4187          $label = $langs->trans(
"DemandReasonType" . $obj->code); 
 
 4189        if ($langs->trans($obj->code) != $obj->code) {
 
 4190          $label = $langs->trans($obj->code); 
 
 4193        $tmparray[$obj->rowid][
'id'] = $obj->rowid;
 
 4194        $tmparray[$obj->rowid][
'code'] = $obj->code;
 
 4195        $tmparray[$obj->rowid][
'label'] = $label;
 
 4199      $this->cache_demand_reason = 
dol_sort_array($tmparray, 
'label', 
'asc', 0, 0, 1);
 
 
 4221  public function selectInputReason($selected = 
'', $htmlname = 
'demandreasonid', $exclude = 
'', $addempty = 0, $morecss = 
'', $notooltip = 0)
 
 4223    global $langs, $user;
 
 4227    print 
'<select class="flat' . ($morecss ? 
' ' . $morecss : 
'') . 
'" id="select_' . $htmlname . 
'" name="' . $htmlname . 
'">';
 
 4229      print 
'<option value="0"' . (empty($selected) ? 
' selected' : 
'') . 
'> </option>';
 
 4231    foreach ($this->cache_demand_reason as $id => $arraydemandreason) {
 
 4232      if ($arraydemandreason[
'code'] == $exclude) {
 
 4236      if ($selected && ($selected == $arraydemandreason[
'id'] || $selected == $arraydemandreason[
'code'])) {
 
 4237        print 
'<option value="' . $arraydemandreason[
'id'] . 
'" selected>';
 
 4239        print 
'<option value="' . $arraydemandreason[
'id'] . 
'">';
 
 4241      $label = $arraydemandreason[
'label']; 
 
 4242      print $langs->trans($label);
 
 4246    if ($user->admin && empty($notooltip)) {
 
 4247      print 
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
 
 
 4264    $num = count($this->cache_types_paiements);        
 
 4271    $this->cache_types_paiements = array();
 
 4273    $sql = 
"SELECT id, code, libelle as label, type, active";
 
 4274    $sql .= 
" FROM " . $this->db->prefix() . 
"c_paiement";
 
 4275    $sql .= 
" WHERE entity IN (" . 
getEntity(
'c_paiement') . 
")";
 
 4277    $resql = $this->db->query($sql);
 
 4279      $num = $this->db->num_rows($resql);
 
 4282        $obj = $this->db->fetch_object($resql);
 
 4285        $label = ($langs->transnoentitiesnoconv(
"PaymentTypeShort" . $obj->code) != 
"PaymentTypeShort" . $obj->code ? $langs->transnoentitiesnoconv(
"PaymentTypeShort" . $obj->code) : ($obj->label != 
'-' ? $obj->label : 
''));
 
 4286        $this->cache_types_paiements[$obj->id][
'id'] = $obj->id;
 
 4287        $this->cache_types_paiements[$obj->id][
'code'] = $obj->code;
 
 4288        $this->cache_types_paiements[$obj->id][
'label'] = $label;
 
 4289        $this->cache_types_paiements[$obj->id][
'type'] = $obj->type;
 
 4290        $this->cache_types_paiements[$obj->id][
'active'] = $obj->active;
 
 4294      $this->cache_types_paiements = 
dol_sort_array($this->cache_types_paiements, 
'label', 
'asc', 0, 0, 1);
 
 
 4323  public function select_conditions_paiements($selected = 0, $htmlname = 
'condid', $filtertype = -1, $addempty = 0, $noinfoadmin = 0, $morecss = 
'', $deposit_percent = -1)
 
 
 4346  public function getSelectConditionsPaiements($selected = 0, $htmlname = 
'condid', $filtertype = -1, $addempty = 0, $noinfoadmin = 0, $morecss = 
'', $deposit_percent = -1)
 
 4348    global $langs, $user, $conf;
 
 4351    dol_syslog(__METHOD__ . 
" selected=" . $selected . 
", htmlname=" . $htmlname, LOG_DEBUG);
 
 4357      dol_syslog(__METHOD__ . 
"Using deprecated option MAIN_DEFAULT_PAYMENT_TERM_ID", LOG_NOTICE);
 
 4358      $selected = $conf->global->MAIN_DEFAULT_PAYMENT_TERM_ID;
 
 4361    $out .= 
'<select id="' . $htmlname . 
'" class="flat selectpaymentterms' . ($morecss ? 
' ' . $morecss : 
'') . 
'" name="' . $htmlname . 
'">';
 
 4363      $out .= 
'<option value="0"> </option>';
 
 4366    $selectedDepositPercent = 
null;
 
 4368    foreach ($this->cache_conditions_paiements as $id => $arrayconditions) {
 
 4369      if ($filtertype <= 0 && !empty($arrayconditions[
'deposit_percent'])) {
 
 4373      if ($selected == $id) {
 
 4374        $selectedDepositPercent = $deposit_percent > 0 ? $deposit_percent : $arrayconditions[
'deposit_percent'];
 
 4375        $out .= 
'<option value="' . $id . 
'" data-deposit_percent="' . $arrayconditions[
'deposit_percent'] . 
'" selected>';
 
 4377        $out .= 
'<option value="' . $id . 
'" data-deposit_percent="' . $arrayconditions[
'deposit_percent'] . 
'">';
 
 4379      $label = $arrayconditions[
'label'];
 
 4381      if (!empty($arrayconditions[
'deposit_percent'])) {
 
 4382        $label = str_replace(
'__DEPOSIT_PERCENT__', $deposit_percent > 0 ? $deposit_percent : $arrayconditions[
'deposit_percent'], $label);
 
 4386      $out .= 
'</option>';
 
 4388    $out .= 
'</select>';
 
 4389    if ($user->admin && empty($noinfoadmin)) {
 
 4390      $out .= 
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
 
 4394    if ($deposit_percent >= 0) {
 
 4395      $out .= 
' <span id="' . $htmlname . 
'_deposit_percent_container"' . (empty($selectedDepositPercent) ? 
' style="display: none"' : 
'') . 
'>';
 
 4396      $out .= $langs->trans(
'DepositPercent') . 
' : ';
 
 4397      $out .= 
'<input id="' . $htmlname . 
'_deposit_percent" name="' . $htmlname . 
'_deposit_percent" class="maxwidth50" value="' . $deposit_percent . 
'" />';
 
 4400        <script nonce="' . 
getNonce() . 
'"> 
 4401          $(document).ready(function () { 
 4402            $("#' . $htmlname . 
'").change(function () { 
 4403              let $selected = $(this).find("option:selected"); 
 4404              let depositPercent = $selected.attr("data-deposit_percent"); 
 4406              if (depositPercent.length > 0) { 
 4407                $("#' . $htmlname . 
'_deposit_percent_container").show().find("#' . $htmlname . 
'_deposit_percent").val(depositPercent); 
 4409                $("#' . $htmlname . 
'_deposit_percent_container").hide().find("#' . $htmlname . 
'_deposit_percent").val(0); 
 
 4440  public function select_types_paiements($selected = 
'', $htmlname = 
'paiementtype', $filtertype = 
'', $format = 0, $empty = 1, $noadmininfo = 0, $maxlength = 0, $active = 1, $morecss = 
'', $nooutput = 0)
 
 4443    global $langs, $user, $conf;
 
 4447    dol_syslog(__METHOD__ . 
" " . $selected . 
", " . $htmlname . 
", " . $filtertype . 
", " . $format, LOG_DEBUG);
 
 4449    $filterarray = array();
 
 4450    if ($filtertype == 
'CRDT') {
 
 4451      $filterarray = array(0, 2, 3);
 
 4452    } elseif ($filtertype == 
'DBIT') {
 
 4453      $filterarray = array(1, 2, 3);
 
 4454    } elseif ($filtertype != 
'' && $filtertype != 
'-1') {
 
 4455      $filterarray = explode(
',', $filtertype);
 
 4462      dol_syslog(__METHOD__ . 
"Using deprecated option MAIN_DEFAULT_PAYMENT_TYPE_ID", LOG_NOTICE);
 
 4463      $selected = $conf->global->MAIN_DEFAULT_PAYMENT_TYPE_ID;
 
 4466    $out .= 
'<select id="select' . $htmlname . 
'" class="flat selectpaymenttypes' . ($morecss ? 
' ' . $morecss : 
'') . 
'" name="' . $htmlname . 
'">';
 
 4468      $out .= 
'<option value=""> </option>';
 
 4470    foreach ($this->cache_types_paiements as $id => $arraytypes) {
 
 4472      if ($active >= 0 && $arraytypes[
'active'] != $active) {
 
 4477      if (count($filterarray) && !in_array($arraytypes[
'type'], $filterarray)) {
 
 4482      if ($empty && empty($arraytypes[
'code'])) {
 
 4487        $out .= 
'<option value="' . $id . 
'"';
 
 4488      } elseif ($format == 1) {
 
 4489        $out .= 
'<option value="' . $arraytypes[
'code'] . 
'"';
 
 4490      } elseif ($format == 2) {
 
 4491        $out .= 
'<option value="' . $arraytypes[
'code'] . 
'"';
 
 4492      } elseif ($format == 3) {
 
 4493        $out .= 
'<option value="' . $id . 
'"';
 
 4496      if ($format == 1 || $format == 2) {
 
 4497        if ($selected == $arraytypes[
'code']) {
 
 4498          $out .= 
' selected';
 
 4501        if ($selected == $id) {
 
 4502          $out .= 
' selected';
 
 4508        $value = ($maxlength ? 
dol_trunc($arraytypes[
'label'], $maxlength) : $arraytypes[
'label']);
 
 4509      } elseif ($format == 1) {
 
 4510        $value = $arraytypes[
'code'];
 
 4511      } elseif ($format == 2) {
 
 4512        $value = ($maxlength ? 
dol_trunc($arraytypes[
'label'], $maxlength) : $arraytypes[
'label']);
 
 4513      } elseif ($format == 3) {
 
 4514        $value = $arraytypes[
'code'];
 
 4516      $out .= $value ? $value : 
' ';
 
 4517      $out .= 
'</option>';
 
 4519    $out .= 
'</select>';
 
 4520    if ($user->admin && !$noadmininfo) {
 
 4521      $out .= 
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
 
 4525    if (empty($nooutput)) {
 
 
 4545    $return = 
'<select class="flat maxwidth100" id="select_' . $htmlname . 
'" name="' . $htmlname . 
'">';
 
 4547      'HT' => $langs->trans(
"HT"),
 
 4548      'TTC' => $langs->trans(
"TTC")
 
 4550    foreach ($options as $id => $value) {
 
 4551      if ($selected == $id) {
 
 4552        $return .= 
'<option value="' . $id . 
'" selected>' . $value;
 
 4554        $return .= 
'<option value="' . $id . 
'">' . $value;
 
 4556      $return .= 
'</option>';
 
 4558    $return .= 
'</select>';
 
 
 4578    $num = count($this->cache_transport_mode);        
 
 4585    $this->cache_transport_mode = array();
 
 4587    $sql = 
"SELECT rowid, code, label, active";
 
 4588    $sql .= 
" FROM " . $this->db->prefix() . 
"c_transport_mode";
 
 4589    $sql .= 
" WHERE entity IN (" . 
getEntity(
'c_transport_mode') . 
")";
 
 4591    $resql = $this->db->query($sql);
 
 4593      $num = $this->db->num_rows($resql);
 
 4596        $obj = $this->db->fetch_object($resql);
 
 4599        $label = ($langs->transnoentitiesnoconv(
"PaymentTypeShort" . $obj->code) != 
"PaymentTypeShort" . $obj->code ? $langs->transnoentitiesnoconv(
"PaymentTypeShort" . $obj->code) : ($obj->label != 
'-' ? $obj->label : 
''));
 
 4600        $this->cache_transport_mode[$obj->rowid][
'rowid'] = $obj->rowid;
 
 4601        $this->cache_transport_mode[$obj->rowid][
'code'] = $obj->code;
 
 4602        $this->cache_transport_mode[$obj->rowid][
'label'] = $label;
 
 4603        $this->cache_transport_mode[$obj->rowid][
'active'] = $obj->active;
 
 4607      $this->cache_transport_mode = 
dol_sort_array($this->cache_transport_mode, 
'label', 
'asc', 0, 0, 1);
 
 
 4629  public function selectTransportMode($selected = 
'', $htmlname = 
'transportmode', $format = 0, $empty = 1, $noadmininfo = 0, $maxlength = 0, $active = 1, $morecss = 
'')
 
 4631    global $langs, $user;
 
 4633    dol_syslog(__METHOD__ . 
" " . $selected . 
", " . $htmlname . 
", " . $format, LOG_DEBUG);
 
 4637    print 
'<select id="select' . $htmlname . 
'" class="flat selectmodetransport' . ($morecss ? 
' ' . $morecss : 
'') . 
'" name="' . $htmlname . 
'">';
 
 4639      print 
'<option value=""> </option>';
 
 4641    foreach ($this->cache_transport_mode as $id => $arraytypes) {
 
 4643      if ($active >= 0 && $arraytypes[
'active'] != $active) {
 
 4648      if ($empty && empty($arraytypes[
'code'])) {
 
 4653        print 
'<option value="' . $id . 
'"';
 
 4654      } elseif ($format == 1) {
 
 4655        print 
'<option value="' . $arraytypes[
'code'] . 
'"';
 
 4656      } elseif ($format == 2) {
 
 4657        print 
'<option value="' . $arraytypes[
'code'] . 
'"';
 
 4658      } elseif ($format == 3) {
 
 4659        print 
'<option value="' . $id . 
'"';
 
 4662      if (preg_match(
'/[a-z]/i', $selected) && $selected == $arraytypes[
'code']) {
 
 4664      } elseif ($selected == $id) {
 
 4670        $value = ($maxlength ? 
dol_trunc($arraytypes[
'label'], $maxlength) : $arraytypes[
'label']);
 
 4671      } elseif ($format == 1) {
 
 4672        $value = $arraytypes[
'code'];
 
 4673      } elseif ($format == 2) {
 
 4674        $value = ($maxlength ? 
dol_trunc($arraytypes[
'label'], $maxlength) : $arraytypes[
'label']);
 
 4675      } elseif ($format == 3) {
 
 4676        $value = $arraytypes[
'code'];
 
 4678      print $value ? $value : 
' ';
 
 4682    if ($user->admin && !$noadmininfo) {
 
 4683      print 
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
 
 
 4699  public function selectShippingMethod($selected = 
'', $htmlname = 
'shipping_method_id', $filtre = 
'', $useempty = 0, $moreattrib = 
'', $noinfoadmin = 0, $morecss = 
'')
 
 4701    global $langs, $user;
 
 4703    $langs->load(
"admin");
 
 4704    $langs->load(
"deliveries");
 
 4706    $sql = 
"SELECT rowid, code, libelle as label";
 
 4707    $sql .= 
" FROM " . $this->db->prefix() . 
"c_shipment_mode";
 
 4708    $sql .= 
" WHERE active > 0";
 
 4710      $sql .= 
" AND " . $filtre;
 
 4712    $sql .= 
" ORDER BY libelle ASC";
 
 4714    dol_syslog(get_class($this) . 
"::selectShippingMode", LOG_DEBUG);
 
 4715    $result = $this->db->query($sql);
 
 4717      $num = $this->db->num_rows($result);
 
 4720        print 
'<select id="select' . $htmlname . 
'" class="flat selectshippingmethod' . ($morecss ? 
' ' . $morecss : 
'') . 
'" name="' . $htmlname . 
'"' . ($moreattrib ? 
' ' . $moreattrib : 
'') . 
'>';
 
 4721        if ($useempty == 1 || ($useempty == 2 && $num > 1)) {
 
 4722          print 
'<option value="-1"> </option>';
 
 4725          $obj = $this->db->fetch_object($result);
 
 4726          if ($selected == $obj->rowid) {
 
 4727            print 
'<option value="' . $obj->rowid . 
'" selected>';
 
 4729            print 
'<option value="' . $obj->rowid . 
'">';
 
 4731          print ($langs->trans(
"SendingMethod" . strtoupper($obj->code)) != 
"SendingMethod" . strtoupper($obj->code)) ? $langs->trans(
"SendingMethod" . strtoupper($obj->code)) : $obj->label;
 
 4736        if ($user->admin && empty($noinfoadmin)) {
 
 4737          print 
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
 
 4742        print $langs->trans(
"NoShippingMethodDefined");
 
 
 4762    $langs->load(
"deliveries");
 
 4764    if ($htmlname != 
"none") {
 
 4765      print 
'<form method="POST" action="' . $page . 
'">';
 
 4766      print 
'<input type="hidden" name="action" value="setshippingmethod">';
 
 4767      print 
'<input type="hidden" name="token" value="' . newToken() . 
'">';
 
 4769      print 
'<input type="submit" class="button valignmiddle" value="' . $langs->trans(
"Modify") . 
'">';
 
 4773        $code = $langs->getLabelFromKey($this->db, $selected, 
'c_shipment_mode', 
'rowid', 
'code');
 
 4774        print $langs->trans(
"SendingMethod" . strtoupper($code));
 
 
 4793    $langs->load(
'bills');
 
 4795    $opt = 
'<option value="" selected></option>';
 
 4796    $sql = 
"SELECT rowid, ref, situation_cycle_ref, situation_counter, situation_final, fk_soc";
 
 4797    $sql .= 
' FROM ' . $this->db->prefix() . 
'facture';
 
 4798    $sql .= 
' WHERE entity IN (' . 
getEntity(
'invoice') . 
')';
 
 4799    $sql .= 
' AND situation_counter >= 1';
 
 4800    $sql .= 
' AND fk_soc = ' . (int) $socid;
 
 4801    $sql .= 
' AND type <> 2';
 
 4802    $sql .= 
' ORDER by situation_cycle_ref, situation_counter desc';
 
 4803    $resql = $this->db->query($sql);
 
 4805    if ($resql && $this->db->num_rows($resql) > 0) {
 
 4808      while ($obj = $this->db->fetch_object($resql)) {
 
 4810        if ($obj->situation_cycle_ref != $ref) {
 
 4812          $ref = $obj->situation_cycle_ref;
 
 4814          if ($obj->situation_final != 1) {
 
 4816            if (substr($obj->ref, 1, 4) != 
'PROV') {
 
 4817              if ($selected == $obj->rowid) {
 
 4818                $opt .= 
'<option value="' . $obj->rowid . 
'" selected>' . $obj->ref . 
'</option>';
 
 4820                $opt .= 
'<option value="' . $obj->rowid . 
'">' . $obj->ref . 
'</option>';
 
 4827      dol_syslog(
"Error sql=" . $sql . 
", error=" . $this->error, LOG_ERR);
 
 4829    if ($opt == 
'<option value ="" selected></option>') {
 
 4830      $opt = 
'<option value ="0" selected>' . $langs->trans(
'NoSituations') . 
'</option>';
 
 
 4844  public function selectUnits($selected = 
'', $htmlname = 
'units', $showempty = 0, $unit_type = 
'')
 
 4848    $langs->load(
'products');
 
 4850    $return = 
'<select class="flat" id="' . $htmlname . 
'" name="' . $htmlname . 
'">';
 
 4852    $sql = 
"SELECT rowid, label, code FROM " . $this->db->prefix() . 
"c_units";
 
 4853    $sql .= 
' WHERE active > 0';
 
 4854    if (!empty($unit_type)) {
 
 4855      $sql .= 
" AND unit_type = '" . $this->db->escape($unit_type) . 
"'";
 
 4857    $sql .= 
" ORDER BY sortorder";
 
 4859    $resql = $this->db->query($sql);
 
 4860    if ($resql && $this->db->num_rows($resql) > 0) {
 
 4862        $return .= 
'<option value="none"></option>';
 
 4865      while ($res = $this->db->fetch_object($resql)) {
 
 4866        $unitLabel = $res->label;
 
 4867        if (!empty($langs->tab_translate[
'unit' . $res->code])) {    
 
 4868          $unitLabel = $langs->trans(
'unit' . $res->code) != $res->label ? $langs->trans(
'unit' . $res->code) : $res->label;
 
 4871        if ($selected == $res->rowid) {
 
 4872          $return .= 
'<option value="' . $res->rowid . 
'" selected>' . $unitLabel . 
'</option>';
 
 4874          $return .= 
'<option value="' . $res->rowid . 
'">' . $unitLabel . 
'</option>';
 
 4877      $return .= 
'</select>';
 
 
 4898  public function select_comptes($selected = 
'', $htmlname = 
'accountid', $status = 0, $filtre = 
'', $useempty = 0, $moreattrib = 
'', $showcurrency = 0, $morecss = 
'', $nooutput = 0)
 
 4901    global $langs, $conf;
 
 4905    $langs->load(
"admin");
 
 4908    $sql = 
"SELECT rowid, label, bank, clos as status, currency_code";
 
 4909    $sql .= 
" FROM " . $this->db->prefix() . 
"bank_account";
 
 4910    $sql .= 
" WHERE entity IN (" . 
getEntity(
'bank_account') . 
")";
 
 4912      $sql .= 
" AND clos = " . (int) $status;
 
 4915      $sql .= 
" AND " . $filtre;
 
 4917    $sql .= 
" ORDER BY label";
 
 4919    dol_syslog(get_class($this) . 
"::select_comptes", LOG_DEBUG);
 
 4920    $result = $this->db->query($sql);
 
 4922      $num = $this->db->num_rows($result);
 
 4925        $out .= 
'<select id="select' . $htmlname . 
'" class="flat selectbankaccount' . ($morecss ? 
' ' . $morecss : 
'') . 
'" name="' . $htmlname . 
'"' . ($moreattrib ? 
' ' . $moreattrib : 
'') . 
'>';
 
 4926        if ($useempty == 1 || ($useempty == 2 && $num > 1)) {
 
 4927          $out .= 
'<option value="-1"> </option>';
 
 4931          $obj = $this->db->fetch_object($result);
 
 4932          if ($selected == $obj->rowid || ($useempty == 2 && $num == 1 && empty($selected))) {
 
 4933            $out .= 
'<option value="' . $obj->rowid . 
'" data-currency-code="' . $obj->currency_code . 
'" selected>';
 
 4935            $out .= 
'<option value="' . $obj->rowid . 
'" data-currency-code="' . $obj->currency_code . 
'">';
 
 4937          $out .= trim($obj->label);
 
 4938          if ($showcurrency) {
 
 4939            $out .= 
' (' . $obj->currency_code . 
')';
 
 4941          if ($status == 2 && $obj->status == 1) {
 
 4942            $out .= 
' (' . $langs->trans(
"Closed") . 
')';
 
 4944          $out .= 
'</option>';
 
 4947        $out .= 
"</select>";
 
 4951          $out .= 
'<span class="opacitymedium">' . $langs->trans(
"NoActiveBankAccountDefined") . 
'</span>';
 
 4953          $out .= 
'<span class="opacitymedium">' . $langs->trans(
"NoBankAccountFound") . 
'</span>';
 
 4961    if (empty($nooutput)) {
 
 
 4981  public function selectEstablishments($selected = 
'', $htmlname = 
'entity', $status = 0, $filtre = 
'', $useempty = 0, $moreattrib = 
'')
 
 4983    global $langs, $conf;
 
 4985    $langs->load(
"admin");
 
 4988    $sql = 
"SELECT rowid, name, fk_country, status, entity";
 
 4989    $sql .= 
" FROM " . $this->db->prefix() . 
"establishment";
 
 4990    $sql .= 
" WHERE 1=1";
 
 4992      $sql .= 
" AND status = " . (int) $status;
 
 4995      $sql .= 
" AND " . $filtre;
 
 4997    $sql .= 
" ORDER BY name";
 
 4999    dol_syslog(get_class($this) . 
"::select_establishment", LOG_DEBUG);
 
 5000    $result = $this->db->query($sql);
 
 5002      $num = $this->db->num_rows($result);
 
 5005        print 
'<select id="select' . $htmlname . 
'" class="flat selectestablishment" name="' . $htmlname . 
'"' . ($moreattrib ? 
' ' . $moreattrib : 
'') . 
'>';
 
 5006        if ($useempty == 1 || ($useempty == 2 && $num > 1)) {
 
 5007          print 
'<option value="-1"> </option>';
 
 5011          $obj = $this->db->fetch_object($result);
 
 5012          if ($selected == $obj->rowid) {
 
 5013            print 
'<option value="' . $obj->rowid . 
'" selected>';
 
 5015            print 
'<option value="' . $obj->rowid . 
'">';
 
 5017          print trim($obj->name);
 
 5018          if ($status == 2 && $obj->status == 1) {
 
 5019            print 
' (' . $langs->trans(
"Closed") . 
')';
 
 5027          print 
'<span class="opacitymedium">' . $langs->trans(
"NoActiveEstablishmentDefined") . 
'</span>';
 
 5029          print 
'<span class="opacitymedium">' . $langs->trans(
"NoEstablishmentFound") . 
'</span>';
 
 
 5052    if ($htmlname != 
"none") {
 
 5053      print 
'<form method="POST" action="' . $page . 
'">';
 
 5054      print 
'<input type="hidden" name="action" value="setbankaccount">';
 
 5055      print 
'<input type="hidden" name="token" value="' . newToken() . 
'">';
 
 5056      print 
img_picto(
'', 
'bank_account', 
'class="pictofixedwidth"');
 
 5057      $nbaccountfound = $this->
select_comptes($selected, $htmlname, 0, 
'', $addempty);
 
 5058      if ($nbaccountfound > 0) {
 
 5059        print 
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
"Modify") . 
'">';
 
 5063      $langs->load(
'banks');
 
 5066        require_once DOL_DOCUMENT_ROOT . 
'/compta/bank/class/account.class.php';
 
 5067        $bankstatic = 
new Account($this->db);
 
 5068        $result = $bankstatic->fetch($selected);
 
 5070          print $bankstatic->getNomUrl(1);
 
 
 5098  public function select_all_categories($type, $selected = 
'', $htmlname = 
"parent", $maxlength = 64, $markafterid = 0, $outputmode = 0, $include = 0, $morecss = 
'')
 
 5101    global $conf, $langs;
 
 5102    $langs->load(
"categories");
 
 5104    include_once DOL_DOCUMENT_ROOT . 
'/categories/class/categorie.class.php';
 
 5107    if (is_numeric($type)) {
 
 5108      dol_syslog(__METHOD__ . 
': using numeric value for parameter type is deprecated. Use string code instead.', LOG_WARNING);
 
 5111    if ($type === Categorie::TYPE_BANK_LINE) {
 
 5113      $cate_arbo = array();
 
 5114      $sql = 
"SELECT c.label, c.rowid";
 
 5115      $sql .= 
" FROM " . $this->db->prefix() . 
"bank_categ as c";
 
 5116      $sql .= 
" WHERE entity = " . $conf->entity;
 
 5117      $sql .= 
" ORDER BY c.label";
 
 5118      $result = $this->db->query($sql);
 
 5120        $num = $this->db->num_rows($result);
 
 5123          $objp = $this->db->fetch_object($result);
 
 5125            $cate_arbo[$objp->rowid] = array(
'id' => $objp->rowid, 
'fulllabel' => $objp->label, 
'color' => 
'', 
'picto' => 
'category');
 
 5129        $this->db->free($result);
 
 5135      $cate_arbo = $cat->get_full_arbo($type, $markafterid, $include);
 
 5138    $outarray = array();
 
 5139    $outarrayrichhtml = array();
 
 5141    $output = 
'<select class="flat' . ($morecss ? 
' ' . $morecss : 
'') . 
'" name="' . $htmlname . 
'" id="' . $htmlname . 
'">';
 
 5142    if (is_array($cate_arbo)) {
 
 5143      if (!count($cate_arbo)) {
 
 5144        $output .= 
'<option value="-1" disabled>' . $langs->trans(
"NoCategoriesDefined") . 
'</option>';
 
 5146        $output .= 
'<option value="-1"> </option>';
 
 5147        foreach ($cate_arbo as $key => $value) {
 
 5148          if ($cate_arbo[$key][
'id'] == $selected || ($selected === 
'auto' && count($cate_arbo) == 1)) {
 
 5154          $labeltoshow = 
img_picto(
'', 
'category', 
'class="pictofixedwidth" style="color: #' . $cate_arbo[$key][
'color'] . 
'"');
 
 5155          $labeltoshow .= 
dol_trunc($cate_arbo[$key][
'fulllabel'], $maxlength, 
'middle');
 
 5157          $outarray[$cate_arbo[$key][
'id']] = $cate_arbo[$key][
'fulllabel'];
 
 5159          $outarrayrichhtml[$cate_arbo[$key][
'id']] = $labeltoshow;
 
 5161          $output .= 
'<option ' . $add . 
'value="' . $cate_arbo[$key][
'id'] . 
'"';
 
 5164          $output .= 
dol_trunc($cate_arbo[$key][
'fulllabel'], $maxlength, 
'middle');
 
 5165          $output .= 
'</option>';
 
 5169    $output .= 
'</select>';
 
 5172    if ($outputmode == 2) {
 
 5174    } elseif ($outputmode == 1) {
 
 5176    } elseif ($outputmode == 3) {
 
 5177      return $outarrayrichhtml;
 
 
 5200  public function form_confirm($page, $title, $question, $action, $formquestion = array(), $selectedchoice = 
"", $useajax = 0, $height = 170, $width = 500)
 
 5203    dol_syslog(__METHOD__ . 
': using form_confirm is deprecated. Use formconfim instead.', LOG_WARNING);
 
 5204    print $this->
formconfirm($page, $title, $question, $action, $formquestion, $selectedchoice, $useajax, $height, $width);
 
 
 5234  public function formconfirm($page, $title, $question, $action, $formquestion = 
'', $selectedchoice = 
'', $useajax = 0, $height = 0, $width = 500, $disableformtag = 0, $labelbuttonyes = 
'Yes', $labelbuttonno = 
'No')
 
 5236    global $langs, $conf;
 
 5238    $more = 
'<!-- formconfirm - before call, page=' . 
dol_escape_htmltag($page) . 
' -->';
 
 5244    $newselectedchoice = empty($selectedchoice) ? 
"no" : $selectedchoice;
 
 5245    if ($conf->browser->layout == 
'phone') {
 
 5250    if (empty($height)) {
 
 5252      if (is_array($formquestion) && count($formquestion) > 2) {
 
 5253        $height += ((count($formquestion) - 2) * 24);
 
 5257    if (is_array($formquestion) && !empty($formquestion)) {
 
 5259      foreach ($formquestion as $key => $input) {
 
 5260        if (is_array($input) && !empty($input)) {
 
 5261          if ($input[
'type'] == 
'hidden') {
 
 5262            $moreattr = (!empty($input[
'moreattr']) ? 
' ' . $input[
'moreattr'] : 
'');
 
 5263            $morecss = (!empty($input[
'morecss']) ? 
' ' . $input[
'morecss'] : 
'');
 
 5271      $moreonecolumn = 
'';
 
 5272      $more .= 
'<div class="tagtable paddingtopbottomonly centpercent noborderspacing">' . 
"\n";
 
 5273      foreach ($formquestion as $key => $input) {
 
 5274        if (is_array($input) && !empty($input)) {
 
 5275          $size = (!empty($input[
'size']) ? 
' size="' . $input[
'size'] . 
'"' : 
'');    
 
 5276          $moreattr = (!empty($input[
'moreattr']) ? 
' ' . $input[
'moreattr'] : 
'');
 
 5277          $morecss = (!empty($input[
'morecss']) ? 
' ' . $input[
'morecss'] : 
'');
 
 5279          if ($input[
'type'] == 
'text') {
 
 5280            $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="' . 
dol_escape_htmltag($input[
'name']) . 
'" name="' . 
dol_escape_htmltag($input[
'name']) . 
'"' . $size . 
' value="' . (empty($input[
'value']) ? 
'' : $input[
'value']) . 
'"' . $moreattr . 
' /></div></div>' . 
"\n";
 
 5281          } elseif ($input[
'type'] == 
'password') {
 
 5282            $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="' . 
dol_escape_htmltag($input[
'name']) . 
'" name="' . 
dol_escape_htmltag($input[
'name']) . 
'"' . $size . 
' value="' . (empty($input[
'value']) ? 
'' : $input[
'value']) . 
'"' . $moreattr . 
' /></div></div>' . 
"\n";
 
 5283          } elseif ($input[
'type'] == 
'textarea') {
 
 5289            $moreonecolumn .= 
'<div class="margintoponly">';
 
 5290            $moreonecolumn .= $input[
'label'] . 
'<br>';
 
 5292            $moreonecolumn .= $input[
'value'];
 
 5293            $moreonecolumn .= 
'</textarea>';
 
 5294            $moreonecolumn .= 
'</div>';
 
 5295          } elseif (in_array($input[
'type'], [
'select', 
'multiselect'])) {
 
 5296            if (empty($morecss)) {
 
 5297              $morecss = 
'minwidth100';
 
 5300            $show_empty = isset($input[
'select_show_empty']) ? $input[
'select_show_empty'] : 1;
 
 5301            $key_in_label = isset($input[
'select_key_in_label']) ? $input[
'select_key_in_label'] : 0;
 
 5302            $value_as_key = isset($input[
'select_value_as_key']) ? $input[
'select_value_as_key'] : 0;
 
 5303            $translate = isset($input[
'select_translate']) ? $input[
'select_translate'] : 0;
 
 5304            $maxlen = isset($input[
'select_maxlen']) ? $input[
'select_maxlen'] : 0;
 
 5305            $disabled = isset($input[
'select_disabled']) ? $input[
'select_disabled'] : 0;
 
 5306            $sort = isset($input[
'select_sort']) ? $input[
'select_sort'] : 
'';
 
 5308            $more .= 
'<div class="tagtr"><div class="tagtd' . (empty($input[
'tdclass']) ? 
'' : (
' ' . $input[
'tdclass'])) . 
'">';
 
 5309            if (!empty($input[
'label'])) {
 
 5310              $more .= $input[
'label'] . 
'</div><div class="tagtd left">';
 
 5312            if ($input[
'type'] == 
'select') {
 
 5313              $more .= $this->
selectarray($input[
'name'], $input[
'values'], isset($input[
'default']) ? $input[
'default'] : 
'-1', $show_empty, $key_in_label, $value_as_key, $moreattr, $translate, $maxlen, $disabled, $sort, $morecss);
 
 5315              $more .= $this->
multiselectarray($input[
'name'], $input[
'values'], is_array($input[
'default']) ? $input[
'default'] : [$input[
'default']], $key_in_label, $value_as_key, $morecss, $translate, $maxlen, $moreattr);
 
 5317            $more .= 
'</div></div>' . 
"\n";
 
 5318          } elseif ($input[
'type'] == 
'checkbox') {
 
 5319            $more .= 
'<div class="tagtr">';
 
 5320            $more .= 
'<div class="tagtd' . (empty($input[
'tdclass']) ? 
'' : (
' ' . $input[
'tdclass'])) . 
'"><label for="' . 
dol_escape_htmltag($input[
'name']) . 
'">' . $input[
'label'] . 
'</label></div><div class="tagtd">';
 
 5321            $more .= 
'<input type="checkbox" class="flat' . ($morecss ? 
' ' . $morecss : 
'') . 
'" id="' . 
dol_escape_htmltag($input[
'name']) . 
'" name="' . 
dol_escape_htmltag($input[
'name']) . 
'"' . $moreattr;
 
 5322            if (!is_bool($input[
'value']) && $input[
'value'] != 
'false' && $input[
'value'] != 
'0' && $input[
'value'] != 
'') {
 
 5323              $more .= 
' checked';
 
 5325            if (is_bool($input[
'value']) && $input[
'value']) {
 
 5326              $more .= 
' checked';
 
 5328            if (isset($input[
'disabled'])) {
 
 5329              $more .= 
' disabled';
 
 5331            $more .= 
' /></div>';
 
 5332            $more .= 
'</div>' . 
"\n";
 
 5333          } elseif ($input[
'type'] == 
'radio') {
 
 5335            foreach ($input[
'values'] as $selkey => $selval) {
 
 5336              $more .= 
'<div class="tagtr">';
 
 5337              if (isset($input[
'label'])) {
 
 5339                  $more .= 
'<div class="tagtd' . (empty($input[
'tdclass']) ? 
' tdtop' : (
' tdtop ' . $input[
'tdclass'])) . 
'">' . $input[
'label'] . 
'</div>';
 
 5341                  $more .= 
'<div clas="tagtd' . (empty($input[
'tdclass']) ? 
'' : (
' "' . $input[
'tdclass'])) . 
'"> </div>';
 
 5344              $more .= 
'<div class="tagtd' . ($i == 0 ? 
' tdtop' : 
'') . 
'"><input type="radio" class="flat' . $morecss . 
'" id="' . 
dol_escape_htmltag($input[
'name'] . $selkey) . 
'" name="' . 
dol_escape_htmltag($input[
'name']) . 
'" value="' . $selkey . 
'"' . $moreattr;
 
 5345              if (!empty($input[
'disabled'])) {
 
 5346                $more .= 
' disabled';
 
 5348              if (isset($input[
'default']) && $input[
'default'] === $selkey) {
 
 5349                $more .= 
' checked="checked"';
 
 5352              $more .= 
'<label for="' . 
dol_escape_htmltag($input[
'name'] . $selkey) . 
'" class="valignmiddle">' . $selval . 
'</label>';
 
 5353              $more .= 
'</div></div>' . 
"\n";
 
 5356          } elseif ($input[
'type'] == 
'date' || $input[
'type'] == 
'datetime') {
 
 5357            $more .= 
'<div class="tagtr"><div class="tagtd' . (empty($input[
'tdclass']) ? 
'' : (
' ' . $input[
'tdclass'])) . 
'">' . $input[
'label'] . 
'</div>';
 
 5358            $more .= 
'<div class="tagtd">';
 
 5359            $addnowlink = (empty($input[
'datenow']) ? 0 : 1);
 
 5361            if ($input[
'type'] == 
'datetime') {
 
 5362              $h = isset($input[
'hours']) ? $input[
'hours'] : 1;
 
 5363              $m = isset($input[
'minutes']) ? $input[
'minutes'] : 1;
 
 5365            $more .= $this->
selectDate($input[
'value'], $input[
'name'], $h, $m, 0, 
'', 1, $addnowlink);
 
 5366            $more .= 
'</div></div>'.
"\n";
 
 5367            $formquestion[] = array(
'name'=>$input[
'name'].
'day');
 
 5368            $formquestion[] = array(
'name'=>$input[
'name'].
'month');
 
 5369            $formquestion[] = array(
'name'=>$input[
'name'].
'year');
 
 5370            $formquestion[] = array(
'name'=>$input[
'name'].
'hour');
 
 5371            $formquestion[] = array(
'name'=>$input[
'name'].
'min');
 
 5372          } elseif ($input[
'type'] == 
'other') { 
 
 5373            $more .= 
'<div class="tagtr"><div class="tagtd'.(empty($input[
'tdclass']) ? 
'' : (
' '.$input[
'tdclass'])).
'">';
 
 5374            if (!empty($input[
'label'])) {
 
 5375              $more .= $input[
'label'] . 
'</div><div class="tagtd">';
 
 5377            $more .= $input[
'value'];
 
 5378            $more .= 
'</div></div>' . 
"\n";
 
 5379          } elseif ($input[
'type'] == 
'onecolumn') {
 
 5380            $moreonecolumn .= 
'<div class="margintoponly">';
 
 5381            $moreonecolumn .= $input[
'value'];
 
 5382            $moreonecolumn .= 
'</div>' . 
"\n";
 
 5383          } elseif ($input[
'type'] == 
'hidden') {
 
 5385          } elseif ($input[
'type'] == 
'separator') {
 
 5388            $more .= 
'Error type ' . $input[
'type'] . 
' for the confirm box is not a supported type';
 
 5392      $more .= 
'</div>' . 
"\n";
 
 5393      $more .= $moreonecolumn;
 
 5399    if (!empty($conf->dol_use_jmobile)) {
 
 5402    if (empty($conf->use_javascript_ajax)) {
 
 5408      $dialogconfirm = 
'dialog-confirm';
 
 5410      if (!is_numeric($useajax)) {
 
 5414        $dialogconfirm .= 
'-' . $button;
 
 5416      $pageyes = $page . (preg_match(
'/\?/', $page) ? 
'&' : 
'?') . 
'action=' . urlencode($action) . 
'&confirm=yes';
 
 5417      $pageno = ($useajax == 2 ? $page . (preg_match(
'/\?/', $page) ? 
'&' : 
'?') . 
'action=' . urlencode($action) . 
'&confirm=no' : 
'');
 
 5420      if (is_array($formquestion)) {
 
 5421        foreach ($formquestion as $key => $input) {
 
 5424          if (is_array($input) && isset($input[
'name'])) {
 
 5425            if (strpos($input[
'name'], 
',') > 0) {
 
 5426              $inputok = array_merge($inputok, explode(
',', $input[
'name']));
 
 5428              array_push($inputok, $input[
'name']);
 
 5432          if (isset($input[
'inputko']) && $input[
'inputko'] == 1) {
 
 5433            array_push($inputko, $input[
'name']);
 
 5439      $formconfirm .= 
'<div id="' . $dialogconfirm . 
'" title="' . 
dol_escape_htmltag($title) . 
'" style="display: none;">';
 
 5440      if (is_array($formquestion) && !empty($formquestion[
'text'])) {
 
 5441        $formconfirm .= 
'<div class="confirmtext">' . $formquestion[
'text'] . 
'</div>' . 
"\n";
 
 5443      if (!empty($more)) {
 
 5444        $formconfirm .= 
'<div class="confirmquestions">' . $more . 
'</div>' . 
"\n";
 
 5446      $formconfirm .= ($question ? 
'<div class="confirmmessage">' . 
img_help(
'', 
'') . 
' ' . $question . 
'</div>' : 
'');
 
 5447      $formconfirm .= 
'</div>' . 
"\n";
 
 5449      $formconfirm .= 
"\n<!-- begin code of popup for formconfirm page=" . $page . 
" -->\n";
 
 5450      $formconfirm .= 
'<script nonce="' . 
getNonce() . 
'" type="text/javascript">' . 
"\n";
 
 5451      $formconfirm .= 
"/* Code for the jQuery('#dialogforpopup').dialog() */\n";
 
 5452      $formconfirm .= 
'jQuery(document).ready(function() { 
 5454              $( "#' . $dialogconfirm . 
'" ).dialog( 
 5456                    autoOpen: ' . ($autoOpen ? 
"true" : 
"false") . 
',';
 
 5457      if ($newselectedchoice == 
'no') {
 
 5460                    $(this).parent().find("button.ui-button:eq(2)").focus(); 
 5465      if ($useajax == 1) {
 
 5466        $jsforcursor = 
'// The call to urljump can be slow, so we set the wait cursor' . 
"\n";
 
 5467        $jsforcursor .= 
'jQuery("html,body,#id-container").addClass("cursorwait");' . 
"\n";
 
 5470      $postconfirmas = 
'GET';
 
 5474                    height: "' . $height . 
'", 
 5475                    width: "' . $width . 
'", 
 5477                    closeOnEscape: false, 
 5479                        "' . 
dol_escape_js($langs->transnoentities($labelbuttonyes)) . 
'": function() { 
 5480              var options = "token=' . urlencode(newToken()) . 
'"; 
 5481                          var inputok = ' . json_encode($inputok) . 
';  /* List of fields into form */ 
 5482              var page = "' . 
dol_escape_js(!empty($page) ? $page : 
'') . 
'"; 
 5483                          var pageyes = "' . 
dol_escape_js(!empty($pageyes) ? $pageyes : 
'') . 
'"; 
 5485                          if (inputok.length > 0) { 
 5486                            $.each(inputok, function(i, inputname) { 
 5489                              if ($("input[name=\'" + inputname + "\']").attr("type") == "radio") { 
 5490                    inputvalue = $("input[name=\'" + inputname + "\']:checked").val(); 
 5492                                  if ($("#" + inputname).attr("type") == "checkbox") { more = ":checked"; } 
 5493                                inputvalue = $("#" + inputname + more).val(); 
 5495                              if (typeof inputvalue == "undefined") { inputvalue=""; } 
 5496                  console.log("formconfirm check inputname="+inputname+" inputvalue="+inputvalue); 
 5497                              options += "&" + inputname + "=" + encodeURIComponent(inputvalue); 
 5500                          var urljump = pageyes + (pageyes.indexOf("?") < 0 ? "?" : "&") + options; 
 5501                    if (pageyes.length > 0) {';
 
 5502      if ($postconfirmas == 
'GET') {
 
 5503        $formconfirm .= 
'location.href = urljump;';
 
 5505        $formconfirm .= $jsforcursor;
 
 5506        $formconfirm .= 
'var post = $.post( 
 5509                  function(data) { $("body").html(data); jQuery("html,body,#id-container").removeClass("cursorwait"); } 
 5513                console.log("after post ok"); 
 5515                          $(this).dialog("close"); 
 5517                        "' . 
dol_escape_js($langs->transnoentities($labelbuttonno)) . 
'": function() { 
 5518                          var options = "token=' . urlencode(newToken()) . 
'"; 
 5519                          var inputko = ' . json_encode($inputko) . 
';  /* List of fields into form */ 
 5520              var page = "' . 
dol_escape_js(!empty($page) ? $page : 
'') . 
'"; 
 5521                          var pageno="' . 
dol_escape_js(!empty($pageno) ? $pageno : 
'') . 
'"; 
 5522                          if (inputko.length > 0) { 
 5523                            $.each(inputko, function(i, inputname) { 
 5525                              if ($("#" + inputname).attr("type") == "checkbox") { more = ":checked"; } 
 5526                              var inputvalue = $("#" + inputname + more).val(); 
 5527                              if (typeof inputvalue == "undefined") { inputvalue=""; } 
 5528                              options += "&" + inputname + "=" + encodeURIComponent(inputvalue); 
 5531                          var urljump=pageno + (pageno.indexOf("?") < 0 ? "?" : "&") + options; 
 5533                    if (pageno.length > 0) {';
 
 5534      if ($postconfirmas == 
'GET') {
 
 5535        $formconfirm .= 
'location.href = urljump;';
 
 5537        $formconfirm .= $jsforcursor;
 
 5538        $formconfirm .= 
'var post = $.post( 
 5541                  function(data) { $("body").html(data); jQuery("html,body,#id-container").removeClass("cursorwait"); } 
 5545                console.log("after post ko"); 
 5547                            $(this).dialog("close"); 
 5553              var button = "' . $button . 
'"; 
 5554              if (button.length > 0) { 
 5555                  $( "#" + button ).click(function() { 
 5556                    $("#' . $dialogconfirm . 
'").dialog("open"); 
 5562      $formconfirm .= 
"<!-- end ajax formconfirm -->\n";
 
 5564      $formconfirm .= 
"\n<!-- begin formconfirm page=" . 
dol_escape_htmltag($page) . 
" -->\n";
 
 5566      if (empty($disableformtag)) {
 
 5567        $formconfirm .= 
'<form method="POST" action="' . $page . 
'" class="notoptoleftroright">' . 
"\n";
 
 5570      $formconfirm .= 
'<input type="hidden" name="action" value="' . $action . 
'">' . 
"\n";
 
 5571      $formconfirm .= 
'<input type="hidden" name="token" value="' . newToken() . 
'">' . 
"\n";
 
 5573      $formconfirm .= 
'<table class="valid centpercent">' . 
"\n";
 
 5576      $formconfirm .= 
'<tr class="validtitre"><td class="validtitre" colspan="2">';
 
 5577      $formconfirm .= 
img_picto(
'', 
'pictoconfirm') . 
' ' . $title;
 
 5578      $formconfirm .= 
'</td></tr>' . 
"\n";
 
 5581      if (is_array($formquestion) && !empty($formquestion[
'text'])) {
 
 5582        $formconfirm .= 
'<tr class="valid"><td class="valid" colspan="2">' . $formquestion[
'text'] . 
'</td></tr>' . 
"\n";
 
 5587        $formconfirm .= 
'<tr class="valid"><td class="valid" colspan="2">' . 
"\n";
 
 5588        $formconfirm .= $more;
 
 5589        $formconfirm .= 
'</td></tr>' . 
"\n";
 
 5593      $formconfirm .= 
'<tr class="valid">';
 
 5594      $formconfirm .= 
'<td class="valid">' . $question . 
'</td>';
 
 5595      $formconfirm .= 
'<td class="valid center">';
 
 5596      $formconfirm .= $this->
selectyesno(
"confirm", $newselectedchoice, 0, 
false, 0, 0, 
'marginleftonly marginrightonly', $labelbuttonyes, $labelbuttonno);
 
 5597      $formconfirm .= 
'<input class="button valignmiddle confirmvalidatebutton small" type="submit" value="' . $langs->trans(
"Validate") . 
'">';
 
 5598      $formconfirm .= 
'</td>';
 
 5599      $formconfirm .= 
'</tr>' . 
"\n";
 
 5601      $formconfirm .= 
'</table>' . 
"\n";
 
 5603      if (empty($disableformtag)) {
 
 5604        $formconfirm .= 
"</form>\n";
 
 5606      $formconfirm .= 
'<br>';
 
 5608      if (!empty($conf->use_javascript_ajax)) {
 
 5609        $formconfirm .= 
'<!-- code to disable button to avoid double clic -->';
 
 5610        $formconfirm .= 
'<script nonce="' . 
getNonce() . 
'" type="text/javascript">' . 
"\n";
 
 5612        $(document).ready(function () { 
 5613          $(".confirmvalidatebutton").on("click", function() { 
 5614            console.log("We click on button confirmvalidatebutton"); 
 5615            $(this).attr("disabled", "disabled"); 
 5616            setTimeout(\'$(".confirmvalidatebutton").removeAttr("disabled")\', 3000); 
 5617            //console.log($(this).closest("form")); 
 5618            $(this).closest("form").submit(); 
 5622        $formconfirm .= 
'</script>' . 
"\n";
 
 5625      $formconfirm .= 
"<!-- end formconfirm -->\n";
 
 5628    return $formconfirm;
 
 
 5649  public function form_project($page, $socid, $selected = 
'', $htmlname = 
'projectid', $discard_closed = 0, $maxlength = 20, $forcefocus = 0, $nooutput = 0, $textifnoproject = 
'', $morecss = 
'')
 
 5654    require_once DOL_DOCUMENT_ROOT . 
'/core/lib/project.lib.php';
 
 5655    require_once DOL_DOCUMENT_ROOT . 
'/core/class/html.formprojet.class.php';
 
 5661    $langs->load(
"project");
 
 5662    if ($htmlname != 
"none") {
 
 5663      $out .= 
'<form method="post" action="' . $page . 
'">';
 
 5664      $out .= 
'<input type="hidden" name="action" value="classin">';
 
 5665      $out .= 
'<input type="hidden" name="token" value="' . newToken() . 
'">';
 
 5666      $out .= $formproject->select_projects($socid, $selected, $htmlname, $maxlength, 0, 1, $discard_closed, $forcefocus, 0, 0, 
'', 1, 0, $morecss);
 
 5667      $out .= 
'<input type="submit" class="button smallpaddingimp" value="' . $langs->trans(
"Modify") . 
'">';
 
 5670      $out .= 
'<span class="project_head_block">';
 
 5672        $projet = 
new Project($this->db);
 
 5673        $projet->fetch($selected);
 
 5674        $out .= $projet->getNomUrl(0, 
'', 1);
 
 5676        $out .= 
'<span class="opacitymedium">' . $textifnoproject . 
'</span>';
 
 5681    if (empty($nooutput)) {
 
 
 5705  public function form_conditions_reglement($page, $selected = 
'', $htmlname = 
'cond_reglement_id', $addempty = 0, $type = 
'', $filtertype = -1, $deposit_percent = -1, $nooutput = 0)
 
 5712    if ($htmlname != 
"none") {
 
 5713      $out .= 
'<form method="POST" action="' . $page . 
'">';
 
 5714      $out .= 
'<input type="hidden" name="action" value="setconditions">';
 
 5715      $out .= 
'<input type="hidden" name="token" value="' . newToken() . 
'">';
 
 5717        $out .= 
'<input type="hidden" name="type" value="' . 
dol_escape_htmltag($type) . 
'">';
 
 5720      $out .= 
'<input type="submit" class="button valignmiddle smallpaddingimp" value="' . $langs->trans(
"Modify") . 
'">';
 
 5725        if (isset($this->cache_conditions_paiements[$selected])) {
 
 5726          $label = $this->cache_conditions_paiements[$selected][
'label'];
 
 5728          if (!empty($this->cache_conditions_paiements[$selected][
'deposit_percent'])) {
 
 5729            $label = str_replace(
'__DEPOSIT_PERCENT__', $deposit_percent > 0 ? $deposit_percent : $this->cache_conditions_paiements[$selected][
'deposit_percent'], $label);
 
 5734          $langs->load(
'errors');
 
 5735          $out .= $langs->trans(
'ErrorNotInDictionaryPaymentConditions');
 
 5742    if (empty($nooutput)) {
 
 
 5764    if ($htmlname != 
"none") {
 
 5765      print 
'<form method="post" action="' . $page . 
'">';
 
 5766      print 
'<input type="hidden" name="action" value="setavailability">';
 
 5767      print 
'<input type="hidden" name="token" value="' . newToken() . 
'">';
 
 5769      print 
'<input type="submit" name="modify" class="button smallpaddingimp" value="' . $langs->trans(
"Modify") . 
'">';
 
 5770      print 
'<input type="submit" name="cancel" class="button smallpaddingimp" value="' . $langs->trans(
"Cancel") . 
'">';
 
 5775        print $this->cache_availability[$selected][
'label'];
 
 
 5792  public function formInputReason($page, $selected = 
'', $htmlname = 
'demandreason', $addempty = 0)
 
 5795    if ($htmlname != 
"none") {
 
 5796      print 
'<form method="post" action="' . $page . 
'">';
 
 5797      print 
'<input type="hidden" name="action" value="setdemandreason">';
 
 5798      print 
'<input type="hidden" name="token" value="' . newToken() . 
'">';
 
 5800      print 
'<input type="submit" class="button smallpaddingimp" value="' . $langs->trans(
"Modify") . 
'">';
 
 5805        foreach ($this->cache_demand_reason as $key => $val) {
 
 5806          if ($val[
'id'] == $selected) {
 
 5807            print $val[
'label'];
 
 
 5832  public function form_date($page, $selected, $htmlname, $displayhour = 0, $displaymin = 0, $nooutput = 0, $type = 
'')
 
 5839    if ($htmlname != 
"none") {
 
 5840      $ret .= 
'<form method="POST" action="' . $page . 
'" name="form' . $htmlname . 
'">';
 
 5841      $ret .= 
'<input type="hidden" name="action" value="set' . $htmlname . 
'">';
 
 5842      $ret .= 
'<input type="hidden" name="token" value="' . newToken() . 
'">';
 
 5844        $ret .= 
'<input type="hidden" name="type" value="' . 
dol_escape_htmltag($type) . 
'">';
 
 5846      $ret .= 
'<table class="nobordernopadding">';
 
 5848      $ret .= $this->
selectDate($selected, $htmlname, $displayhour, $displaymin, 1, 
'form' . $htmlname, 1, 0);
 
 5850      $ret .= 
'<td class="left"><input type="submit" class="button smallpaddingimp" value="' . $langs->trans(
"Modify") . 
'"></td>';
 
 5851      $ret .= 
'</tr></table></form>';
 
 5860    if (empty($nooutput)) {
 
 
 5879  public function form_users($page, $selected = 
'', $htmlname = 
'userid', $exclude = array(), $include = array())
 
 5884    if ($htmlname != 
"none") {
 
 5885      print 
'<form method="POST" action="' . $page . 
'" name="form' . $htmlname . 
'">';
 
 5886      print 
'<input type="hidden" name="action" value="set' . $htmlname . 
'">';
 
 5887      print 
'<input type="hidden" name="token" value="' . newToken() . 
'">';
 
 5888      print $this->
select_dolusers($selected, $htmlname, 1, $exclude, 0, $include);
 
 5889      print 
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
"Modify") . 
'">';
 
 5893        require_once DOL_DOCUMENT_ROOT . 
'/user/class/user.class.php';
 
 5894        $theuser = 
new User($this->db);
 
 5895        $theuser->fetch($selected);
 
 5896        print $theuser->getNomUrl(1);
 
 
 5919  public function form_modes_reglement($page, $selected = 
'', $htmlname = 
'mode_reglement_id', $filtertype = 
'', $active = 1, $addempty = 0, $type = 
'', $nooutput = 0)
 
 5925    if ($htmlname != 
"none") {
 
 5926      $out .= 
'<form method="POST" action="' . $page . 
'">';
 
 5927      $out .= 
'<input type="hidden" name="action" value="setmode">';
 
 5928      $out .= 
'<input type="hidden" name="token" value="' . newToken() . 
'">';
 
 5930        $out .= 
'<input type="hidden" name="type" value="' . 
dol_escape_htmltag($type) . 
'">';
 
 5932      $out .= $this->
select_types_paiements($selected, $htmlname, $filtertype, 0, $addempty, 0, 0, $active, 
'', 1);
 
 5933      $out .= 
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
"Modify") . 
'">';
 
 5938        $out .= $this->cache_types_paiements[$selected][
'label'];
 
 
 5965    if ($htmlname != 
"none") {
 
 5966      print 
'<form method="POST" action="' . $page . 
'">';
 
 5967      print 
'<input type="hidden" name="action" value="settransportmode">';
 
 5968      print 
'<input type="hidden" name="token" value="' . newToken() . 
'">';
 
 5970      print 
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
"Modify") . 
'">';
 
 5975        print $this->cache_transport_mode[$selected][
'label'];
 
 
 5996    if ($htmlname != 
"none") {
 
 5997      print 
'<form method="POST" action="' . $page . 
'">';
 
 5998      print 
'<input type="hidden" name="action" value="setmulticurrencycode">';
 
 5999      print 
'<input type="hidden" name="token" value="' . newToken() . 
'">';
 
 6001      print 
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
"Modify") . 
'">';
 
 6005      print !empty($selected) ? 
currency_name($selected, 1) : 
' ';
 
 
 6023    global $langs, $mysoc, $conf;
 
 6025    if ($htmlname != 
"none") {
 
 6026      print 
'<form method="POST" action="' . $page . 
'">';
 
 6027      print 
'<input type="hidden" name="action" value="setmulticurrencyrate">';
 
 6028      print 
'<input type="hidden" name="token" value="' . newToken() . 
'">';
 
 6029      print 
'<input type="text" class="maxwidth100" name="' . $htmlname . 
'" value="' . (!empty($rate) ? 
price(
price2num($rate, 
'CU')) : 1) . 
'" /> ';
 
 6030      print 
'<select name="calculation_mode">';
 
 6031      print 
'<option value="1">Change ' . $langs->trans(
"PriceUHT") . 
' of lines</option>';
 
 6032      print 
'<option value="2">Change ' . $langs->trans(
"PriceUHTCurrency") . 
' of lines</option>';
 
 6034      print 
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
"Modify") . 
'">';
 
 6037      if (!empty($rate)) {
 
 6038        print 
price($rate, 1, $langs, 0, 0);
 
 6039        if ($currency && $rate != 1) {
 
 6040          print 
'   (' . 
price($rate, 1, $langs, 0, 0) . 
' ' . $currency . 
' = 1 ' . $conf->currency . 
')';
 
 
 6066  public function form_remise_dispo($page, $selected, $htmlname, $socid, $amount, $filter = 
'', $maxvalue = 0, $more = 
'', $hidelist = 0, $discount_type = 0)
 
 6069    global $conf, $langs;
 
 6070    if ($htmlname != 
"none") {
 
 6071      print 
'<form method="post" action="' . $page . 
'">';
 
 6072      print 
'<input type="hidden" name="action" value="setabsolutediscount">';
 
 6073      print 
'<input type="hidden" name="token" value="' . newToken() . 
'">';
 
 6074      print 
'<div class="inline-block">';
 
 6075      if (!empty($discount_type)) {
 
 6077          if (!$filter || $filter == 
"fk_invoice_supplier_source IS NULL") {
 
 6078            $translationKey = 
'HasAbsoluteDiscountFromSupplier'; 
 
 6080            $translationKey = 
'HasCreditNoteFromSupplier';
 
 6083          if (!$filter || $filter == 
"fk_invoice_supplier_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS PAID)%')") {
 
 6084            $translationKey = 
'HasAbsoluteDiscountFromSupplier';
 
 6086            $translationKey = 
'HasCreditNoteFromSupplier';
 
 6091          if (!$filter || $filter == 
"fk_facture_source IS NULL") {
 
 6092            $translationKey = 
'CompanyHasAbsoluteDiscount'; 
 
 6094            $translationKey = 
'CompanyHasCreditNote';
 
 6097          if (!$filter || $filter == 
"fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')") {
 
 6098            $translationKey = 
'CompanyHasAbsoluteDiscount';
 
 6100            $translationKey = 
'CompanyHasCreditNote';
 
 6104      print $langs->trans($translationKey, 
price($amount, 0, $langs, 0, 0, -1, $conf->currency));
 
 6105      if (empty($hidelist)) {
 
 6109      if (empty($hidelist)) {
 
 6110        print 
'<div class="inline-block" style="padding-right: 10px">';
 
 6111        $newfilter = 
'discount_type=' . intval($discount_type);
 
 6112        if (!empty($discount_type)) {
 
 6113          $newfilter .= 
' AND fk_invoice_supplier IS NULL AND fk_invoice_supplier_line IS NULL'; 
 
 6115          $newfilter .= 
' AND fk_facture IS NULL AND fk_facture_line IS NULL'; 
 
 6118          $newfilter .= 
' AND (' . $filter . 
')';
 
 6121        $nbqualifiedlines = $this->
select_remises($selected, $htmlname, $newfilter, $socid, $maxvalue);
 
 6122        if ($nbqualifiedlines > 0) {
 
 6123          print 
'   <input type="submit" class="button smallpaddingimp" value="' . 
dol_escape_htmltag($langs->trans(
"UseLine")) . 
'"';
 
 6124          if (!empty($discount_type) && $filter && $filter != 
"fk_invoice_supplier_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS PAID)%')") {
 
 6125            print 
' title="' . $langs->trans(
"UseCreditNoteInInvoicePayment") . 
'"';
 
 6127          if (empty($discount_type) && $filter && $filter != 
"fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')") {
 
 6128            print 
' title="' . $langs->trans(
"UseCreditNoteInInvoicePayment") . 
'"';
 
 6136        print 
'<div class="inline-block">';
 
 
 6162  public function form_contacts($page, $societe, $selected = 
'', $htmlname = 
'contactid')
 
 6165    global $langs, $conf;
 
 6167    if ($htmlname != 
"none") {
 
 6168      print 
'<form method="post" action="' . $page . 
'">';
 
 6169      print 
'<input type="hidden" name="action" value="set_contact">';
 
 6170      print 
'<input type="hidden" name="token" value="' . newToken() . 
'">';
 
 6171      print 
'<table class="nobordernopadding">';
 
 6176        $addcontact = (
getDolGlobalString(
'SOCIETE_ADDRESSES_MANAGEMENT') ? $langs->trans(
"AddContact") : $langs->trans(
"AddContactAddress"));
 
 6177        print 
'<a href="' . DOL_URL_ROOT . 
'/contact/card.php?socid=' . $societe->id . 
'&action=create&backtoreferer=1">' . $addcontact . 
'</a>';
 
 6180      print 
'<td class="left"><input type="submit" class="button smallpaddingimp" value="' . $langs->trans(
"Modify") . 
'"></td>';
 
 6181      print 
'</tr></table></form>';
 
 6184        require_once DOL_DOCUMENT_ROOT . 
'/contact/class/contact.class.php';
 
 6185        $contact = 
new Contact($this->db);
 
 6186        $contact->fetch($selected);
 
 6187        print $contact->getFullName($langs);
 
 
 6212  public function form_thirdparty($page, $selected = 
'', $htmlname = 
'socid', $filter = 
'', $showempty = 0, $showtype = 0, $forcecombo = 0, $events = array(), $nooutput = 0, $excludeids = array(), $textifnothirdparty = 
'')
 
 6218    if ($htmlname != 
"none") {
 
 6219      $out .= 
'<form method="post" action="' . $page . 
'">';
 
 6220      $out .= 
'<input type="hidden" name="action" value="set_thirdparty">';
 
 6221      $out .= 
'<input type="hidden" name="token" value="' . newToken() . 
'">';
 
 6222      $out .= $this->
select_company($selected, $htmlname, $filter, $showempty, $showtype, $forcecombo, $events, 0, 
'minwidth100', 
'', 
'', 1, array(), 
false, $excludeids);
 
 6223      $out .= 
'<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans(
"Modify") . 
'">';
 
 6227        require_once DOL_DOCUMENT_ROOT . 
'/societe/class/societe.class.php';
 
 6228        $soc = 
new Societe($this->db);
 
 6229        $soc->fetch($selected);
 
 6230        $out .= $soc->getNomUrl(0, 
'');
 
 6232        $out .= 
'<span class="opacitymedium">' . $textifnothirdparty . 
'</span>';
 
 
 6270  public function selectCurrency($selected = 
'', $htmlname = 
'currency_id', $mode = 0, $useempty = 
'')
 
 6272    global $conf, $langs, $user;
 
 6274    $langs->loadCacheCurrencies(
'');
 
 6278    if ($selected == 
'euro' || $selected == 
'euros') {
 
 6282    $out .= 
'<select class="flat maxwidth200onsmartphone minwidth300" name="' . $htmlname . 
'" id="' . $htmlname . 
'">';
 
 6284      $out .= 
'<option value="-1" selected></option>';
 
 6286    foreach ($langs->cache_currencies as $code_iso => $currency) {
 
 6287      $labeltoshow = $currency[
'label'];
 
 6289        $labeltoshow .= 
' <span class="opacitymedium">(' . $code_iso . 
')</span>';
 
 6291        $labeltoshow .= 
' <span class="opacitymedium">(' . $langs->getCurrencySymbol($code_iso) . 
')</span>';
 
 6294      if ($selected && $selected == $code_iso) {
 
 6295        $out .= 
'<option value="' . $code_iso . 
'" selected data-html="' . 
dol_escape_htmltag($labeltoshow) . 
'">';
 
 6297        $out .= 
'<option value="' . $code_iso . 
'" data-html="' . 
dol_escape_htmltag($labeltoshow) . 
'">';
 
 6299      $out .= $labeltoshow;
 
 6300      $out .= 
'</option>';
 
 6302    $out .= 
'</select>';
 
 6304      $out .= 
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
 
 6308    include_once DOL_DOCUMENT_ROOT . 
'/core/lib/ajax.lib.php';
 
 
 6326  public function selectMultiCurrency($selected = 
'', $htmlname = 
'multicurrency_code', $useempty = 0, $filter = 
'', $excludeConfCurrency = 
false, $morecss = 
'')
 
 6328    global $conf, $langs;
 
 6330    $langs->loadCacheCurrencies(
''); 
 
 6332    $TCurrency = array();
 
 6334    $sql = 
"SELECT code FROM " . $this->db->prefix() . 
"multicurrency";
 
 6335    $sql .= 
" WHERE entity IN ('" . 
getEntity(
'multicurrency') . 
"')";
 
 6337      $sql .= 
" AND " . $filter;
 
 6339    $resql = $this->db->query($sql);
 
 6341      while ($obj = $this->db->fetch_object($resql)) {
 
 6342        $TCurrency[$obj->code] = $obj->code;
 
 6347    $out .= 
'<select class="flat' . ($morecss ? 
' ' . $morecss : 
'') . 
'" name="' . $htmlname . 
'" id="' . $htmlname . 
'">';
 
 6349      $out .= 
'<option value=""> </option>';
 
 6352    if (!in_array($conf->currency, $TCurrency) && !$excludeConfCurrency) {
 
 6353      $TCurrency[$conf->currency] = $conf->currency;
 
 6355    if (count($TCurrency) > 0) {
 
 6356      foreach ($langs->cache_currencies as $code_iso => $currency) {
 
 6357        if (isset($TCurrency[$code_iso])) {
 
 6358          if (!empty($selected) && $selected == $code_iso) {
 
 6359            $out .= 
'<option value="' . $code_iso . 
'" selected="selected">';
 
 6361            $out .= 
'<option value="' . $code_iso . 
'">';
 
 6364          $out .= $currency[
'label'];
 
 6365          $out .= 
' (' . $langs->getCurrencySymbol($code_iso) . 
')';
 
 6366          $out .= 
'</option>';
 
 6371    $out .= 
'</select>';
 
 6374    include_once DOL_DOCUMENT_ROOT . 
'/core/lib/ajax.lib.php';
 
 
 6391    global $langs, $user;
 
 6393    $num = count($this->cache_vatrates);
 
 6400    $sql = 
"SELECT DISTINCT t.rowid, t.code, t.taux, t.localtax1, t.localtax1_type, t.localtax2, t.localtax2_type, t.recuperableonly";
 
 6401    $sql .= 
" FROM " . $this->db->prefix() . 
"c_tva as t, " . $this->db->prefix() . 
"c_country as c";
 
 6402    $sql .= 
" WHERE t.fk_pays = c.rowid";
 
 6403    $sql .= 
" AND t.active > 0";
 
 6404    $sql .= 
" AND t.entity IN (".getEntity(
'c_tva').
")";
 
 6405    $sql .= 
" AND c.code IN (" . $this->db->sanitize($country_code, 1) . 
")";
 
 6406    $sql .= 
" ORDER BY t.code ASC, t.taux ASC, t.recuperableonly ASC";
 
 6408    $resql = $this->db->query($sql);
 
 6410      $num = $this->db->num_rows($resql);
 
 6412        for ($i = 0; $i < $num; $i++) {
 
 6413          $obj = $this->db->fetch_object($resql);
 
 6414          $this->cache_vatrates[$i][
'rowid'] = $obj->rowid;
 
 6415          $this->cache_vatrates[$i][
'code'] = $obj->code;
 
 6416          $this->cache_vatrates[$i][
'txtva'] = $obj->taux;
 
 6417          $this->cache_vatrates[$i][
'nprtva'] = $obj->recuperableonly;
 
 6418          $this->cache_vatrates[$i][
'localtax1'] = $obj->localtax1;
 
 6419          $this->cache_vatrates[$i][
'localtax1_type'] = $obj->localtax1_type;
 
 6420          $this->cache_vatrates[$i][
'localtax2'] = $obj->localtax2;
 
 6421          $this->cache_vatrates[$i][
'localtax2_type'] = $obj->localtax1_type;
 
 6423          $this->cache_vatrates[$i][
'label'] = $obj->taux . 
'%' . ($obj->code ? 
' (' . $obj->code . 
')' : 
''); 
 
 6424          $this->cache_vatrates[$i][
'labelallrates'] = $obj->taux . 
'/' . ($obj->localtax1 ? $obj->localtax1 : 
'0') . 
'/' . ($obj->localtax2 ? $obj->localtax2 : 
'0') . ($obj->code ? 
' (' . $obj->code . 
')' : 
''); 
 
 6425          $positiverates = 
'';
 
 6427            $positiverates .= ($positiverates ? 
'/' : 
'') . $obj->taux;
 
 6429          if ($obj->localtax1) {
 
 6430            $positiverates .= ($positiverates ? 
'/' : 
'') . $obj->localtax1;
 
 6432          if ($obj->localtax2) {
 
 6433            $positiverates .= ($positiverates ? 
'/' : 
'') . $obj->localtax2;
 
 6435          if (empty($positiverates)) {
 
 6436            $positiverates = 
'0';
 
 6438          $this->cache_vatrates[$i][
'labelpositiverates'] = $positiverates . ($obj->code ? 
' (' . $obj->code . 
')' : 
''); 
 
 6443        $this->error = 
'<span class="error">';
 
 6444        $this->error .= $langs->trans(
"ErrorNoVATRateDefinedForSellerCountry", $country_code);
 
 6446        if (!empty($user) && $user->admin && preg_match(
'/\'(..)\'/', $country_code, $reg)) {
 
 6447          $langs->load(
"errors");
 
 6448          $new_country_code = $reg[1];
 
 6449          $country_id = 
dol_getIdFromCode($this->db, $new_country_code, 
'c_pays', 
'code', 
'rowid');
 
 6450          $this->error .= 
'<br>'.$langs->trans(
"ErrorFixThisHere", DOL_URL_ROOT.
'/admin/dict.php?id=10'.($country_id > 0 ? 
'&countryidforinsert='.$country_id : 
''));
 
 6452        $this->error .= 
'</span>';
 
 6456      $this->error = 
'<span class="error">' . $this->db->error() . 
'</span>';
 
 
 6484  public function load_tva($htmlname = 
'tauxtva', $selectedrate = 
'', $societe_vendeuse = 
null, $societe_acheteuse = 
null, $idprod = 0, $info_bits = 0, $type = 
'', $options_only = 
false, $mode = 0)
 
 6487    global $langs, $conf, $mysoc;
 
 6489    $langs->load(
'errors');
 
 6494    $defaultnpr = ($info_bits & 0x01);
 
 6495    $defaultnpr = (preg_match(
'/\*/', $selectedrate) ? 1 : $defaultnpr);
 
 6496    $defaulttx = str_replace(
'*', 
'', $selectedrate);
 
 6499    if (preg_match(
'/\((.*)\)/', $defaulttx, $reg)) {
 
 6500      $defaultcode = $reg[1];
 
 6501      $defaulttx = preg_replace(
'/\s*\(.*\)/', 
'', $defaulttx);
 
 6506    if (is_object($societe_vendeuse) && !$societe_vendeuse->country_code) {
 
 6507      if ($societe_vendeuse->id == $mysoc->id) {
 
 6508        $return .= 
'<span class="error">' . $langs->trans(
"ErrorYourCountryIsNotDefined") . 
'</span>';
 
 6510        $return .= 
'<span class="error">' . $langs->trans(
"ErrorSupplierCountryIsNotDefined") . 
'</span>';
 
 6521    if (is_object($societe_vendeuse)) {
 
 6522      $code_country = 
"'" . $societe_vendeuse->country_code . 
"'";
 
 6524      $code_country = 
"'" . $mysoc->country_code . 
"'"; 
 
 6527      require_once DOL_DOCUMENT_ROOT . 
'/core/lib/company.lib.php';
 
 6531      if (is_object($societe_vendeuse) && is_object($societe_acheteuse) && 
isInEEC($societe_vendeuse) && 
isInEEC($societe_acheteuse) && !$societe_acheteuse->isACompany()) {
 
 6533        if (is_numeric($type)) {
 
 6535            switch ($selectVatComboMode) {
 
 6537                $code_country .= 
",'" . $societe_acheteuse->country_code . 
"'";
 
 6540                $code_country = 
"'" . $societe_acheteuse->country_code . 
"'";
 
 6544        } elseif (!$idprod) {  
 
 6545          switch ($selectVatComboMode) {
 
 6547              $code_country .= 
",'" . $societe_acheteuse->country_code . 
"'";
 
 6550              $code_country = 
"'" . $societe_acheteuse->country_code . 
"'";
 
 6554          $prodstatic = 
new Product($this->db);
 
 6555          $prodstatic->fetch($idprod);
 
 6557            $code_country .= 
",'" . $societe_acheteuse->country_code . 
"'";
 
 6568      if ($defaulttx < 0 || 
dol_strlen($defaulttx) == 0) {
 
 6569        $tmpthirdparty = 
new Societe($this->db);
 
 6571        $defaulttx = 
get_default_tva($societe_vendeuse, (is_object($societe_acheteuse) ? $societe_acheteuse : $tmpthirdparty), $idprod);
 
 6572        $defaultnpr = 
get_default_npr($societe_vendeuse, (is_object($societe_acheteuse) ? $societe_acheteuse : $tmpthirdparty), $idprod);
 
 6574        if (preg_match(
'/\((.*)\)/', $defaulttx, $reg)) {
 
 6575          $defaultcode = $reg[1];
 
 6576          $defaulttx = preg_replace(
'/\s*\(.*\)/', 
'', $defaulttx);
 
 6578        if (empty($defaulttx)) {
 
 6585      if ($defaulttx < 0 || 
dol_strlen($defaulttx) == 0) {
 
 6588          $defaulttx = $this->cache_vatrates[$num - 1][
'txtva'];
 
 6593            $defaulttx = $conf->global->MAIN_VAT_DEFAULT_IF_AUTODETECT_FAILS;
 
 6595          if (preg_match(
'/\((.*)\)/', $defaulttx, $reg)) {
 
 6596            $defaultcode = $reg[1];
 
 6597            $defaulttx = preg_replace(
'/\s*\(.*\)/', 
'', $defaulttx);
 
 6605      if (is_object($societe_vendeuse) && $societe_vendeuse->id == $mysoc->id && $societe_vendeuse->tva_assuj == 
"0") {
 
 6614      if (!$options_only) {
 
 6615        $return .= 
'<select class="flat minwidth50imp maxwidth100" id="' . $htmlname . 
'" name="' . $htmlname . 
'"' . ($disabled ? 
' disabled' : 
'') . $title . 
'>';
 
 6618      $selectedfound = 
false;
 
 6619      foreach ($this->cache_vatrates as $rate) {
 
 6621        if ($disabled && $rate[
'txtva'] != 0) {
 
 6626        $key = $rate[
'txtva'];
 
 6627        $key .= $rate[
'nprtva'] ? 
'*' : 
'';
 
 6628        if ($mode > 0 && $rate[
'code']) {
 
 6629          $key .= 
' (' . $rate[
'code'] . 
')';
 
 6632          $key = $rate[
'rowid'];
 
 6635        $return .= 
'<option value="' . $key . 
'"';
 
 6636        if (!$selectedfound) {
 
 6638            if ($defaultcode == $rate[
'code']) {
 
 6639              $return .= 
' selected';
 
 6640              $selectedfound = 
true;
 
 6642          } elseif ($rate[
'txtva'] == $defaulttx && $rate[
'nprtva'] == $defaultnpr) {
 
 6643            $return .= 
' selected';
 
 6644            $selectedfound = 
true;
 
 6650        if ($mysoc->country_code == 
'IN' || 
getDolGlobalString(
'MAIN_VAT_LABEL_IS_POSITIVE_RATES')) {
 
 6652          $return .= $rate[
'labelpositiverates'];
 
 6655          $return .= 
vatrate($rate[
'label']);
 
 6659        $return .= (empty($rate[
'code']) && $rate[
'nprtva']) ? 
' *' : 
''; 
 
 6661        $return .= 
'</option>';
 
 6664      if (!$options_only) {
 
 6665        $return .= 
'</select>';
 
 6669      $return .= $this->error;
 
 
 6703  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 = 0, $addplusone = 
'', $adddateof = 
'')
 
 6706    dol_syslog(__METHOD__ . 
': using select_date is deprecated. Use selectDate instead.', LOG_WARNING);
 
 6707    $retstring = $this->
selectDate($set_time, $prefix, $h, $m, $empty, $form_name, $d, $addnowlink, $disabled, $fullday, $addplusone, $adddateof);
 
 6708    if (!empty($nooutput)) {
 
 
 6731  public function selectDateToDate($set_time = 
'', $set_time_end = 
'', $prefix = 
're', $empty = 0, $forcenewline = 0)
 
 6735    $ret = $this->
selectDate($set_time, $prefix . 
'_start', 0, 0, $empty, 
'', 1, 0, 0, 
'', 
'', 
'', 
'', 1, 
'', $langs->trans(
"from"), 
'tzuserrel');
 
 6736    if ($forcenewline) {
 
 6739    $ret .= $this->
selectDate($set_time_end, $prefix . 
'_end', 0, 0, $empty, 
'', 1, 0, 0, 
'', 
'', 
'', 
'', 1, 
'', $langs->trans(
"to"), 
'tzuserrel');
 
 
 6770  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 = 
'', $placeholder = 
'', $gm = 
'auto')
 
 6772    global $conf, $langs;
 
 6774    if ($gm === 
'auto') {
 
 6775      $gm = (empty($conf) ? 
'tzserver' : $conf->tzuserinputkey);
 
 6780    if ($prefix == 
'') {
 
 6791    if ($stepminutes <= 0 || $stepminutes > 30) {
 
 6802    $orig_set_time = $set_time;
 
 6804    if ($set_time === 
'' && $emptydate == 0) {
 
 6805      include_once DOL_DOCUMENT_ROOT . 
'/core/lib/date.lib.php';
 
 6806      if ($gm == 
'tzuser' || $gm == 
'tzuserrel') {
 
 6818    if (preg_match(
'/^([0-9]+)\-([0-9]+)\-([0-9]+)\s?([0-9]+)?:?([0-9]+)?/', $set_time, $reg)) {    
 
 6820      $syear = (!empty($reg[1]) ? $reg[1] : 
'');
 
 6821      $smonth = (!empty($reg[2]) ? $reg[2] : 
'');
 
 6822      $sday = (!empty($reg[3]) ? $reg[3] : 
'');
 
 6823      $shour = (!empty($reg[4]) ? $reg[4] : 
'');
 
 6824      $smin = (!empty($reg[5]) ? $reg[5] : 
'');
 
 6825    } elseif (strval($set_time) != 
'' && $set_time != -1) {
 
 6830      if ($orig_set_time != 
'') {
 
 6840      $shour = !isset($conf->global->MAIN_DEFAULT_DATE_HOUR) ? ($h == -1 ? 
'23' : 
'') : $conf->global->MAIN_DEFAULT_DATE_HOUR;
 
 6841      $smin = !isset($conf->global->MAIN_DEFAULT_DATE_MIN) ? ($h == -1 ? 
'59' : 
'') : $conf->global->MAIN_DEFAULT_DATE_MIN;
 
 6842      $ssec = !isset($conf->global->MAIN_DEFAULT_DATE_SEC) ? ($h == -1 ? 
'59' : 
'') : $conf->global->MAIN_DEFAULT_DATE_SEC;
 
 6855    $usecalendar = 
'combo';
 
 6862      if ($usecalendar != 
'combo') {
 
 6863        $formated_date = 
'';
 
 6865        if (strval($set_time) != 
'' && $set_time != -1) {
 
 6867          $formated_date = 
dol_print_date($set_time, $langs->trans(
"FormatDateShortInput"), $gm); 
 
 6871        if ($usecalendar == 
"eldy") {
 
 6873          $retstring .= 
'<input id="' . $prefix . 
'" name="' . $prefix . 
'" type="text" class="maxwidthdate" maxlength="11" value="' . $formated_date . 
'"';
 
 6874          $retstring .= ($disabled ? 
' disabled' : 
'');
 
 6875          $retstring .= 
' onChange="dpChangeDay(\'' . $prefix . 
'\',\
'' . $langs->trans(
"FormatDateShortJavaInput") . 
'\'); 
"'; // FormatDateShortInput for dol_print_date / FormatDateShortJavaInput that is same for javascript 
 6879          $retstringbuttom = ''; 
 6881            $retstringbuttom = '<button id="' . $prefix . 'Button
" type="button" class="dpInvisibleButtons
"'; 
 6882            $base = DOL_URL_ROOT . '/core/'; 
 6883            $retstringbuttom .= ' onClick="showDP(\
'' . $base . 
'\',\
'' . $prefix . 
'\',\
'' . $langs->trans(
"FormatDateShortJavaInput") . 
'\',\
'' . $langs->defaultlang . 
'\');
"'; 
 6884            $retstringbuttom .= '>' . img_object($langs->trans("SelectDate
"), 'calendarday', 'class="datecallink
"') . '</button>'; 
 6886            $retstringbuttom = '<button id="' . $prefix . 'Button
" type="button" class="dpInvisibleButtons
">' . img_object($langs->trans("Disabled
"), 'calendarday', 'class="datecallink
"') . '</button>'; 
 6888          $retstring = $retstringbuttom . $retstring; 
 6890          $retstring .= '<input type="hidden
" id="' . $prefix . 'day
"   name="' . $prefix . 'day
"   value="' . $sday . '">' . "\n
"; 
 6891          $retstring .= '<input type="hidden
" id="' . $prefix . 'month
" name="' . $prefix . 'month
" value="' . $smonth . '">' . "\n
"; 
 6892          $retstring .= '<input type="hidden
" id="' . $prefix . 'year
"  name="' . $prefix . 'year
"  value="' . $syear . '">' . "\n
"; 
 6893        } elseif ($usecalendar == 'jquery') { 
 6895            // Output javascript for datepicker 
 6896            $minYear = getDolGlobalInt('MIN_YEAR_SELECT_DATE', (date('Y') - 100)); 
 6897            $maxYear = getDolGlobalInt('MAX_YEAR_SELECT_DATE', (date('Y') + 100)); 
 6899            $retstring .= '<script nonce="' . getNonce() . '" type="text/javascript
">'; 
 6900            $retstring .= "$(
function(){ $(
'#" . $prefix . "').datepicker({
 
 6901              dateFormat: 
'" . $langs->trans("FormatDateShortJQueryInput") . "',
 
 6903              todayHighlight: 
true,
 
 6904              yearRange: 
'" . $minYear . ":" . $maxYear . "',
"; 
 6905            if (!empty($conf->dol_use_jmobile)) { 
 6907                beforeShow: 
function (input, datePicker) {
 
 6908                  input.disabled = 
true;
 
 6910                onClose: 
function (dateText, datePicker) {
 
 6911                  this.disabled = 
false;
 
 6915            // Note: We don't need monthNames, monthNamesShort, dayNames, dayNamesShort, dayNamesMin, they are set globally on datepicker component in lib_head.js.php 
 6916            if (!getDolGlobalString('MAIN_POPUP_CALENDAR_ON_FOCUS')) { 
 6919                buttonImage: 
'" . DOL_URL_ROOT . "/theme/" . dol_escape_js($conf->theme) . "/img/object_calendarday.png',
 
 6920                buttonImageOnly: 
true"; 
 6924            $retstring .= "</script>
"; 
 6927          // Zone de saisie manuelle de la date 
 6928          $retstring .= '<div class="nowraponall 
inline-block divfordateinput
">'; 
 6929          $retstring .= '<input id="'.$prefix.'" name="'.$prefix.'" type="text
" class="maxwidthdate
" maxlength="11
" value="'.$formated_date.'"'; 
 6930          $retstring .= ($disabled ? ' disabled' : ''); 
 6931          $retstring .= ($placeholder ? ' placeholder="' . dol_escape_htmltag($placeholder) . '"' : ''); 
 6932          $retstring .= ' onChange="dpChangeDay(\
'' . 
dol_escape_js($prefix) . 
'\',\
'' . 
dol_escape_js($langs->trans(
"FormatDateShortJavaInput")) . 
'\'); 
"'; // FormatDateShortInput for dol_print_date / FormatDateShortJavaInput that is same for javascript 
 6937            /* Not required. Managed by option buttonImage of jquery 
 6938            $retstring.=img_object($langs->trans("SelectDate
"),'calendarday','id="'.$prefix.'id" class="datecallink
"'); 
 6939            $retstring.='<script nonce="'.getNonce().'" type="text/javascript
">'; 
 6940            $retstring.="jQuery(document).ready(
function() {
"; 
 6941            $retstring.=' jQuery("#
'.$prefix.'id").click(function() {'; 
 6942            $retstring.="     jQuery(
'#".$prefix."').focus();
"; 
 6945            $retstring.="</script>
";*/ 
 6947            $retstringbutton = '<button id="' . $prefix . 'Button
" type="button" class="dpInvisibleButtons
">' . img_object($langs->trans("Disabled
"), 'calendarday', 'class="datecallink
"') . '</button>'; 
 6948            $retsring = $retstringbutton . $retstring; 
 6951          $retstring .= '</div>'; 
 6952          $retstring .= '<input type="hidden
" id="' . $prefix . 'day
"   name="' . $prefix . 'day
"   value="' . $sday . '">' . "\n
"; 
 6953          $retstring .= '<input type="hidden
" id="' . $prefix . 'month
" name="' . $prefix . 'month
" value="' . $smonth . '">' . "\n
"; 
 6954          $retstring .= '<input type="hidden
" id="' . $prefix . 'year
"  name="' . $prefix . 'year
"  value="' . $syear . '">' . "\n
"; 
 6956          $retstring .= "Bad value of MAIN_POPUP_CALENDAR
"; 
 6959        // Show date with combo selects 
 6961        $retstring .= '<select' . ($disabled ? ' disabled' : '') . ' class="flat valignmiddle maxwidth50imp
" id="' . $prefix . 'day
" name="' . $prefix . 'day
">'; 
 6963        if ($emptydate || $set_time == -1) { 
 6964          $retstring .= '<option value="0
" selected> </option>'; 
 6967        for ($day = 1; $day <= 31; $day++) { 
 6968          $retstring .= '<option value="' . $day . '"' . ($day == $sday ? ' selected' : '') . '>' . $day . '</option>'; 
 6971        $retstring .= "</select>
"; 
 6973        $retstring .= '<select' . ($disabled ? ' disabled' : '') . ' class="flat valignmiddle maxwidth75imp
" id="' . $prefix . 'month
" name="' . $prefix . 'month
">'; 
 6974        if ($emptydate || $set_time == -1) { 
 6975          $retstring .= '<option value="0
" selected> </option>'; 
 6979        for ($month = 1; $month <= 12; $month++) { 
 6980          $retstring .= '<option value="' . $month . '"' . ($month == $smonth ? ' selected' : '') . '>'; 
 6981          $retstring .= dol_print_date(mktime(12, 0, 0, $month, 1, 2000), "%b
"); 
 6982          $retstring .= "</option>
"; 
 6984        $retstring .= "</select>
"; 
 6987        if ($emptydate || $set_time == -1) { 
 6988          $retstring .= '<input' . ($disabled ? ' disabled' : '') . ' placeholder="' . dol_escape_htmltag($langs->trans("Year")) . '" class="flat maxwidth50imp valignmiddle
" type="number
" min="0
" max="3000
" maxlength="4
" id="' . $prefix . 'year
" name="' . $prefix . 'year
" value="' . $syear . '">'; 
 6990          $retstring .= '<select' . ($disabled ? ' disabled' : '') . ' class="flat valignmiddle maxwidth75imp
" id="' . $prefix . 'year
" name="' . $prefix . 'year
">'; 
 6992          for ($year = $syear - 10; $year < $syear + 10; $year++) { 
 6993            $retstring .= '<option value="' . $year . '"' . ($year == $syear ? ' selected' : '') . '>' . $year . '</option>'; 
 6995          $retstring .= "</select>\n
"; 
 7001      $retstring .= ($h == 2 ? '<br>' : ' '); 
 7002      $retstring .= '<span class="nowraponall
">'; 
 7008      if ($openinghours != '') { 
 7009        $openinghours = explode(',', $openinghours); 
 7010        $hourstart = $openinghours[0]; 
 7011        $hourend = $openinghours[1]; 
 7012        if ($hourend < $hourstart) { 
 7013          $hourend = $hourstart; 
 7017      $retstring .= '<select' . ($disabled ? ' disabled' : '') . ' class="flat valignmiddle maxwidth50 
' . ($fullday ? $fullday . 'hour
' : '') . '" id="' . $prefix . 'hour
" name="' . $prefix . 'hour
">'; 
 7019        $retstring .= '<option value="-1
"> </option>'; 
 7021      for ($hour = $hourstart; $hour < $hourend; $hour++) { 
 7022        if (strlen($hour) < 2) { 
 7023          $hour = "0
" . $hour; 
 7025        $retstring .= '<option value="' . $hour . '"' . (($hour == $shour) ? ' selected' : '') . '>' . $hour; 
 7026        //$retstring .= (empty($conf->dol_optimize_smallscreen) ? '' : 'H'); 
 7027        $retstring .= '</option>'; 
 7029      $retstring .= '</select>'; 
 7030      //if ($m && empty($conf->dol_optimize_smallscreen)) $retstring .= ":
"; 
 7038      $retstring .= '<select' . ($disabled ? ' disabled' : '') . ' class="flat valignmiddle maxwidth50 
' . ($fullday ? $fullday . 'min
' : '') . '" id="' . $prefix . 'min
" name="' . $prefix . 'min
">'; 
 7040        $retstring .= '<option value="-1
"> </option>'; 
 7042      for ($min = 0; $min < 60; $min += $stepminutes) { 
 7043        if (strlen($min) < 2) { 
 7046        $retstring .= '<option value="' . $min . '"' . (($min == $smin) ? ' selected' : '') . '>' . $min . (empty($conf->dol_optimize_smallscreen) ? '' : '') . '</option>'; 
 7048      $retstring .= '</select>'; 
 7050      $retstring .= '<input type="hidden
" name="' . $prefix . 'sec
" value="' . $ssec . '">'; 
 7054      $retstring .= '</span>'; 
 7058    if (!empty($conf->use_javascript_ajax) && $addnowlink) { 
 7059      // Script which will be inserted in the onClick of the "Now
" link 
 7060      $reset_scripts = ""; 
 7061      if ($addnowlink == 2) { // local computer time 
 7062        // pad add leading 0 on numbers 
 7063        $reset_scripts .= "Number.prototype.pad = 
function(size) {
 
 7064                        var s = String(
this);
 
 7065                        while (s.length < (size || 2)) {s = 
'0' + s;}
 
 7068                    var d = 
new Date();
"; 
 7071      // Generate the date part, depending on the use or not of the javascript calendar 
 7072      if ($addnowlink == 1) { // server time expressed in user time setup 
 7073        $reset_scripts .= 'jQuery(\'#' . $prefix . '\').val(\'' . dol_print_date($nowgmt, 'day', 'tzuserrel') . '\');'; 
 7074        $reset_scripts .= 'jQuery(\'#' . $prefix . 'day\').val(\'' . dol_print_date($nowgmt, '%d', 'tzuserrel') . '\');'; 
 7075        $reset_scripts .= 'jQuery(\'#' . $prefix . 'month\').val(\'' . dol_print_date($nowgmt, '%m', 'tzuserrel') . '\');'; 
 7076        $reset_scripts .= 'jQuery(\'#' . $prefix . 'year\').val(\'' . dol_print_date($nowgmt, '%Y', 'tzuserrel') . '\');'; 
 7077      } elseif ($addnowlink == 2) { 
 7078        /* Disabled because the output does not use the string format defined by FormatDateShort key to forge the value into #prefix. 
 7079         * This break application for foreign languages. 
 7080        $reset_scripts .= 'jQuery(\'#'.$prefix.'\').val(d.toLocaleDateString(\''.str_replace('_', '-', $langs->defaultlang).'\'));'; 
 7081        $reset_scripts .= 'jQuery(\'#'.$prefix.'day\').val(d.getDate().pad());'; 
 7082        $reset_scripts .= 'jQuery(\'#'.$prefix.'month\').val(parseInt(d.getMonth().pad()) + 1);'; 
 7083        $reset_scripts .= 'jQuery(\'#'.$prefix.'year\').val(d.getFullYear());'; 
 7085        $reset_scripts .= 'jQuery(\'#' . $prefix . '\').val(\'' . dol_print_date($nowgmt, 'day', 'tzuserrel') . '\');'; 
 7086        $reset_scripts .= 'jQuery(\'#' . $prefix . 'day\').val(\'' . dol_print_date($nowgmt, '%d', 'tzuserrel') . '\');'; 
 7087        $reset_scripts .= 'jQuery(\'#' . $prefix . 'month\').val(\'' . dol_print_date($nowgmt, '%m', 'tzuserrel') . '\');'; 
 7088        $reset_scripts .= 'jQuery(\'#' . $prefix . 'year\').val(\'' . dol_print_date($nowgmt, '%Y', 'tzuserrel') . '\');'; 
 7090      /*if ($usecalendar == "eldy
") 
 7092        $base=DOL_URL_ROOT.'/core/'; 
 7093        $reset_scripts .= 'resetDP(\''.$base.'\',\''.$prefix.'\',\''.$langs->trans("FormatDateShortJavaInput
").'\',\''.$langs->defaultlang.'\');'; 
 7097        $reset_scripts .= 'this.form.elements[\''.$prefix.'day\'].value=formatDate(new Date(), \'d\'); '; 
 7098        $reset_scripts .= 'this.form.elements[\''.$prefix.'month\'].value=formatDate(new Date(), \'M\'); '; 
 7099        $reset_scripts .= 'this.form.elements[\''.$prefix.'year\'].value=formatDate(new Date(), \'yyyy\'); '; 
 7101      // Update the hour part 
 7104          $reset_scripts .= " if (jQuery(
'#fullday:checked').val() == 
null) {
"; 
 7106        //$reset_scripts .= 'this.form.elements[\''.$prefix.'hour\'].value=formatDate(new Date(), \'HH\'); '; 
 7107        if ($addnowlink == 1) { 
 7108          $reset_scripts .= 'jQuery(\'#' . $prefix . 'hour\').val(\'' . dol_print_date($nowgmt, '%H', 'tzuserrel') . '\');'; 
 7109          $reset_scripts .= 'jQuery(\'#' . $prefix . 'hour\').change();'; 
 7110        } elseif ($addnowlink == 2) { 
 7111          $reset_scripts .= 'jQuery(\'#' . $prefix . 'hour\').val(d.getHours().pad());'; 
 7112          $reset_scripts .= 'jQuery(\'#' . $prefix . 'hour\').change();'; 
 7116          $reset_scripts .= ' } '; 
 7119      // Update the minute part 
 7122          $reset_scripts .= " if (jQuery(
'#fullday:checked').val() == 
null) {
"; 
 7124        //$reset_scripts .= 'this.form.elements[\''.$prefix.'min\'].value=formatDate(new Date(), \'mm\'); '; 
 7125        if ($addnowlink == 1) { 
 7126          $reset_scripts .= 'jQuery(\'#' . $prefix . 'min\').val(\'' . dol_print_date($nowgmt, '%M', 'tzuserrel') . '\');'; 
 7127          $reset_scripts .= 'jQuery(\'#' . $prefix . 'min\').change();'; 
 7128        } elseif ($addnowlink == 2) { 
 7129          $reset_scripts .= 'jQuery(\'#' . $prefix . 'min\').val(d.getMinutes().pad());'; 
 7130          $reset_scripts .= 'jQuery(\'#' . $prefix . 'min\').change();'; 
 7133          $reset_scripts .= ' } '; 
 7136      // If reset_scripts is not empty, print the link with the reset_scripts in the onClick 
 7137      if ($reset_scripts && !getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) { 
 7138        $retstring .= ' <button class="dpInvisibleButtons datenowlink
" id="' . $prefix . 'ButtonNow
" type="button" name="_useless
" value="now
" onClick="' . $reset_scripts . '">'; 
 7139        $retstring .= $langs->trans("Now
"); 
 7140        $retstring .= '</button> '; 
 7144    // Add a "Plus one hour
" link 
 7145    if ($conf->use_javascript_ajax && $addplusone) { 
 7146      // Script which will be inserted in the onClick of the "Add plusone
" link 
 7147      $reset_scripts = ""; 
 7149      // Generate the date part, depending on the use or not of the javascript calendar 
 7150      $reset_scripts .= 'jQuery(\'#' . $prefix . '\').val(\'' . dol_print_date($nowgmt, 'dayinputnoreduce', 'tzuserrel') . '\');'; 
 7151      $reset_scripts .= 'jQuery(\'#' . $prefix . 'day\').val(\'' . dol_print_date($nowgmt, '%d', 'tzuserrel') . '\');'; 
 7152      $reset_scripts .= 'jQuery(\'#' . $prefix . 'month\').val(\'' . dol_print_date($nowgmt, '%m', 'tzuserrel') . '\');'; 
 7153      $reset_scripts .= 'jQuery(\'#' . $prefix . 'year\').val(\'' . dol_print_date($nowgmt, '%Y', 'tzuserrel') . '\');'; 
 7154      // Update the hour part 
 7157          $reset_scripts .= " if (jQuery(
'#fullday:checked').val() == 
null) {
"; 
 7159        $reset_scripts .= 'jQuery(\'#' . $prefix . 'hour\').val(\'' . dol_print_date($nowgmt, '%H', 'tzuserrel') . '\');'; 
 7161          $reset_scripts .= ' } '; 
 7164      // Update the minute part 
 7167          $reset_scripts .= " if (jQuery(
'#fullday:checked').val() == 
null) {
"; 
 7169        $reset_scripts .= 'jQuery(\'#' . $prefix . 'min\').val(\'' . dol_print_date($nowgmt, '%M', 'tzuserrel') . '\');'; 
 7171          $reset_scripts .= ' } '; 
 7174      // If reset_scripts is not empty, print the link with the reset_scripts in the onClick 
 7175      if ($reset_scripts && empty($conf->dol_optimize_smallscreen)) { 
 7176        $retstring .= ' <button class="dpInvisibleButtons datenowlink
" id="' . $prefix . 'ButtonPlusOne
" type="button" name="_useless2
" value="plusone
" onClick="' . $reset_scripts . '">'; 
 7177        $retstring .= $langs->trans("DateStartPlusOne
"); 
 7178        $retstring .= '</button> '; 
 7182    // Add a link to set data 
 7183    if ($conf->use_javascript_ajax && !empty($adddateof)) { 
 7184      if (!is_array($adddateof)) { 
 7185        $arrayofdateof = array(array('adddateof'=>$adddateof, 'labeladddateof'=>$labeladddateof)); 
 7187        $arrayofdateof = $adddateof; 
 7189      foreach ($arrayofdateof as $valuedateof) { 
 7190        $tmpadddateof = empty($valuedateof['adddateof']) ? 0 : $valuedateof['adddateof']; 
 7191        $tmplabeladddateof = empty($valuedateof['labeladddateof']) ? '' : $valuedateof['labeladddateof']; 
 7192        $tmparray = dol_getdate($tmpadddateof); 
 7193        if (empty($tmplabeladddateof)) { 
 7194          $tmplabeladddateof = $langs->trans("DateInvoice
"); 
 7196        $reset_scripts = 'console.log(\'Click on now link\'); '; 
 7197        $reset_scripts .= 'jQuery(\'#'.$prefix.'\').val(\''.dol_print_date($tmpadddateof, 'dayinputnoreduce').'\');'; 
 7198        $reset_scripts .= 'jQuery(\'#'.$prefix.'day\').val(\''.$tmparray['mday'].'\');'; 
 7199        $reset_scripts .= 'jQuery(\'#'.$prefix.'month\').val(\''.$tmparray['mon'].'\');'; 
 7200        $reset_scripts .= 'jQuery(\'#'.$prefix.'year\').val(\''.$tmparray['year'].'\');'; 
 7201        $retstring .= ' - <button class="dpInvisibleButtons datenowlink
" id="dateofinvoice
" type="button" name="_dateofinvoice
" value="now
" onclick="'.$reset_scripts.'">'.$tmplabeladddateof.'</button>'; 
 
 7216  public function selectTypeDuration($prefix, $selected = 'i', $excludetypes = array())
 
 7220    $TDurationTypes = array(
 
 7221      'y' => $langs->trans('Years'),
 
 7222      'm' => $langs->trans('Month'),
 
 7223      'w' => $langs->trans('Weeks'),
 
 7224      'd' => $langs->trans('Days'),
 
 7225      'h' => $langs->trans('Hours'),
 
 7226      'i' => $langs->trans('Minutes')
 
 7229    // Removed undesired duration types
 
 7230    foreach ($excludetypes as $value) {
 
 7231      unset($TDurationTypes[$value]);
 
 7234    $retstring = '<select class="flat minwidth75 maxwidth100
" id="select_
' . $prefix . 'type_duration
" name="' . $prefix . 'type_duration
">'; 
 7235    foreach ($TDurationTypes as $key => $typeduration) { 
 7236      $retstring .= '<option value="' . $key . '"'; 
 7237      if ($key == $selected) { 
 7238        $retstring .= " selected
"; 
 7240      $retstring .= ">
" . $typeduration . "</option>
"; 
 7242    $retstring .= "</select>
"; 
 7244    $retstring .= ajax_combobox('select_' . $prefix . 'type_duration'); 
 
 7249  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps 
 7264  public function select_duration($prefix, $iSecond = '', $disabled = 0, $typehour = 'select', $minunderhours = 0, $nooutput = 0)
 
 7269    $retstring = '<span class="nowraponall
">'; 
 7275    if ($iSecond != '') { 
 7276      require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php'; 
 7278      $hourSelected = convertSecondToTime($iSecond, 'allhour'); 
 7279      $minSelected = convertSecondToTime($iSecond, 'min'); 
 7282    if ($typehour == 'select') { 
 7283      $retstring .= '<select class="flat
" id="select_
' . $prefix . 'hour
" name="' . $prefix . 'hour
"' . ($disabled ? ' disabled' : '') . '>'; 
 7284      for ($hour = 0; $hour < 25; $hour++) {    // For a duration, we allow 24 hours 
 7285        $retstring .= '<option value="' . $hour . '"'; 
 7286        if (is_numeric($hourSelected) && $hourSelected == $hour) { 
 7287          $retstring .= " selected
"; 
 7289        $retstring .= ">
" . $hour . "</option>
"; 
 7291      $retstring .= "</select>
"; 
 7292    } elseif ($typehour == 'text' || $typehour == 'textselect') { 
 7293      $retstring .= '<input placeholder="' . $langs->trans('HourShort
') . '" type="number
" min="0
" name="' . $prefix . 'hour
"' . ($disabled ? ' disabled' : '') . ' class="flat maxwidth50 inputhour right
" value="' . (($hourSelected != '') ? ((int) $hourSelected) : '') . '">'; 
 7295      return 'BadValueForParameterTypeHour'; 
 7298    if ($typehour != 'text') { 
 7299      $retstring .= ' ' . $langs->trans('HourShort'); 
 7301      $retstring .= '<span class="">:</span>'; 
 7305    if ($minunderhours) { 
 7306      $retstring .= '<br>'; 
 7308      if ($typehour != 'text') { 
 7309        $retstring .= '<span class="hideonsmartphone
"> </span>'; 
 7313    if ($typehour == 'select' || $typehour == 'textselect') { 
 7314      $retstring .= '<select class="flat
" id="select_
' . $prefix . 'min
" name="' . $prefix . 'min
"' . ($disabled ? ' disabled' : '') . '>'; 
 7315      for ($min = 0; $min <= 55; $min = $min + 5) { 
 7316        $retstring .= '<option value="' . $min . '"'; 
 7317        if (is_numeric($minSelected) && $minSelected == $min) { 
 7318          $retstring .= ' selected'; 
 7320        $retstring .= '>' . $min . '</option>'; 
 7322      $retstring .= "</select>
"; 
 7323    } elseif ($typehour == 'text') { 
 7324      $retstring .= '<input placeholder="' . $langs->trans('MinuteShort
') . '" type="number
" min="0
" name="' . $prefix . 'min
"' . ($disabled ? ' disabled' : '') . ' class="flat maxwidth50 inputminute right
" value="' . (($minSelected != '') ? ((int) $minSelected) : '') . '">'; 
 7327    if ($typehour != 'text') { 
 7328      $retstring .= ' ' . $langs->trans('MinuteShort'); 
 7331    $retstring .= "</span>
"; 
 7333    if (!empty($nooutput)) { 
 
 7361  public function selectTickets($selected = '', $htmlname = 'ticketid', $filtertype = '', $limit = 0, $status = 1, $selected_input_value = '', $hidelabel = 0, $ajaxoptions = array(), $socid = 0, $showempty = '1', $forcecombo = 0, $morecss = '', $selected_combinations = null, $nooutput = 0)
 
 7363    global $langs, $conf;
 
 7368    if (is_null($ajaxoptions)) {
 
 7369      $ajaxoptions = array();
 
 7372    if (!empty($conf->use_javascript_ajax) && getDolGlobalString('TICKET_USE_SEARCH_TO_SELECT')) {
 
 7375      if ($selected && empty($selected_input_value)) {
 
 7376        require_once DOL_DOCUMENT_ROOT . '/ticket/class/ticket.class.php';
 
 7377        $tickettmpselect = new Ticket($this->db);
 
 7378        $tickettmpselect->fetch($selected);
 
 7379        $selected_input_value = $tickettmpselect->ref;
 
 7380        unset($tickettmpselect);
 
 7384      $out .= ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT . '/ticket/ajax/tickets.php', $urloption, $conf->global->PRODUIT_USE_SEARCH_TO_SELECT, 1, $ajaxoptions);
 
 7386      if (empty($hidelabel)) {
 
 7387        $out .= $langs->trans("RefOrLabel
") . ' : '; 
 7388      } elseif ($hidelabel > 1) { 
 7389        $placeholder = ' placeholder="' . $langs->trans("RefOrLabel") . '"'; 
 7390        if ($hidelabel == 2) { 
 7391          $out .= img_picto($langs->trans("Search
"), 'search'); 
 7394      $out .= '<input type="text
" class="minwidth100
" name="search_
' . $htmlname . '" id="search_
' . $htmlname . '" value="' . $selected_input_value . '"' . $placeholder . ' ' . (getDolGlobalString('PRODUCT_SEARCH_AUTOFOCUS') ? 'autofocus' : '') . ' />'; 
 7395      if ($hidelabel == 3) { 
 7396        $out .= img_picto($langs->trans("Search
"), 'search'); 
 7399      $out .= $this->selectTicketsList($selected, $htmlname, $filtertype, $limit, $status, 0, $socid, $showempty, $forcecombo, $morecss); 
 7402    if (empty($nooutput)) { 
 
 7427  public function selectTicketsList($selected = '', $htmlname = 'ticketid', $filtertype = '', $limit = 20, $filterkey = '', $status = 1, $outputmode = 0, $showempty = '1', $forcecombo = 0, $morecss = '')
 
 7429    global $langs, $conf;
 
 7432    $outarray = array();
 
 7434    $selectFields = " p.rowid, p.ref, p.message
"; 
 7437    $sql .= $selectFields; 
 7438    $sql .= " FROM 
" . $this->db->prefix() . "ticket as p
"; 
 7439    $sql .= ' WHERE p.entity IN (' . getEntity('ticket') . ')'; 
 7441    // Add criteria on ref/label 
 7442    if ($filterkey != '') { 
 7444      $prefix = !getDolGlobalString('TICKET_DONOTSEARCH_ANYWHERE') ? '%' : ''; // Can use index if PRODUCT_DONOTSEARCH_ANYWHERE is on 
 7445      // For natural search 
 7446      $scrit = explode(' ', $filterkey); 
 7448      if (count($scrit) > 1) { 
 7451      foreach ($scrit as $crit) { 
 7455        $sql .= "(p.ref LIKE 
'" . $this->db->escape($prefix . $crit) . "%' OR p.subject LIKE 
'" . $this->db->escape($prefix . $crit) . "%'"; 
 7459      if (count($scrit) > 1) { 
 7465    $sql .= $this->db->plimit($limit, 0); 
 7467    // Build output string 
 7469    $result = $this->db->query($sql); 
 7471      require_once DOL_DOCUMENT_ROOT . '/ticket/class/ticket.class.php'; 
 7472      require_once DOL_DOCUMENT_ROOT . '/core/lib/ticket.lib.php'; 
 7474      $num = $this->db->num_rows($result); 
 7479        include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php'; 
 7480        $out .= ajax_combobox($htmlname, $events, $conf->global->TICKET_USE_SEARCH_TO_SELECT); 
 7483      $out .= '<select class="flat
' . ($morecss ? ' ' . $morecss : '') . '" name="' . $htmlname . '" id="' . $htmlname . '">'; 
 7486      // Do not use textifempty = ' ' or ' ' here, or search on key will search on ' key'. 
 7487      //if (!empty($conf->use_javascript_ajax) || $forcecombo) $textifempty=''; 
 7488      if (getDolGlobalString('TICKET_USE_SEARCH_TO_SELECT')) { 
 7489        if ($showempty && !is_numeric($showempty)) { 
 7490          $textifempty = $langs->trans($showempty); 
 7492          $textifempty .= $langs->trans("All
"); 
 7495        if ($showempty && !is_numeric($showempty)) { 
 7496          $textifempty = $langs->trans($showempty); 
 7500        $out .= '<option value="0
" selected>' . $textifempty . '</option>'; 
 7504      while ($num && $i < $num) { 
 7507        $objp = $this->db->fetch_object($result); 
 7509        $this->constructTicketListOption($objp, $opt, $optJson, $selected, $filterkey); 
 7511        // "key
" value of json key array is used by jQuery automatically as selected value 
 7512        // "label
" value of json key array is used by jQuery automatically as text for combo box 
 7514        array_push($outarray, $optJson); 
 7519      $out .= '</select>'; 
 7521      $this->db->free($result); 
 7523      if (empty($outputmode)) { 
 7528      dol_print_error($this->db); 
 
 7545  protected function constructTicketListOption(&$objp, &$opt, &$optJson, $selected, $filterkey = '')
 
 7551    $outkey = $objp->rowid;
 
 7552    $outref = $objp->ref;
 
 7553    $outtype = $objp->fk_product_type;
 
 7555    $opt = '<option value="
' . $objp->rowid . '"'; 
 7556    $opt .= ($objp->rowid == $selected) ? ' selected' : ''; 
 7559    $objRef = $objp->ref; 
 7560    if (!empty($filterkey) && $filterkey != '') { 
 7561      $objRef = preg_replace('/(' . preg_quote($filterkey, '/') . ')/i', '<strong>$1</strong>', $objRef, 1); 
 7564    $opt .= "</option>\n
"; 
 7565    $optJson = array('key' => $outkey, 'value' => $outref, 'type' => $outtype); 
 
 7587  public function selectProjects($selected = '', $htmlname = 'projectid', $filtertype = '', $limit = 0, $status = 1, $selected_input_value = '', $hidelabel = 0, $ajaxoptions = array(), $socid = 0, $showempty = '1', $forcecombo = 0, $morecss = '', $selected_combinations = null, $nooutput = 0)
 
 7589    global $langs, $conf;
 
 7594    if (is_null($ajaxoptions)) {
 
 7595      $ajaxoptions = array();
 
 7598    if (!empty($conf->use_javascript_ajax) && getDolGlobalString('TICKET_USE_SEARCH_TO_SELECT')) {
 
 7601      if ($selected && empty($selected_input_value)) {
 
 7602        require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php';
 
 7603        $projecttmpselect = new Project($this->db);
 
 7604        $projecttmpselect->fetch($selected);
 
 7605        $selected_input_value = $projecttmpselect->ref;
 
 7606        unset($projecttmpselect);
 
 7610      $out .= ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT . '/projet/ajax/projects.php', $urloption, $conf->global->PRODUIT_USE_SEARCH_TO_SELECT, 1, $ajaxoptions);
 
 7612      if (empty($hidelabel)) {
 
 7613        $out .= $langs->trans("RefOrLabel
") . ' : '; 
 7614      } elseif ($hidelabel > 1) { 
 7615        $placeholder = ' placeholder="' . $langs->trans("RefOrLabel") . '"'; 
 7616        if ($hidelabel == 2) { 
 7617          $out .= img_picto($langs->trans("Search
"), 'search'); 
 7620      $out .= '<input type="text
" class="minwidth100
" name="search_
' . $htmlname . '" id="search_
' . $htmlname . '" value="' . $selected_input_value . '"' . $placeholder . ' ' . (getDolGlobalString('PRODUCT_SEARCH_AUTOFOCUS') ? 'autofocus' : '') . ' />'; 
 7621      if ($hidelabel == 3) { 
 7622        $out .= img_picto($langs->trans("Search
"), 'search'); 
 7625      $out .= $this->selectProjectsList($selected, $htmlname, $filtertype, $limit, $status, 0, $socid, $showempty, $forcecombo, $morecss); 
 7628    if (empty($nooutput)) { 
 
 7652  public function selectProjectsList($selected = '', $htmlname = 'projectid', $filtertype = '', $limit = 20, $filterkey = '', $status = 1, $outputmode = 0, $showempty = '1', $forcecombo = 0, $morecss = '')
 
 7654    global $langs, $conf;
 
 7657    $outarray = array();
 
 7659    $selectFields = " p.rowid, p.ref
"; 
 7662    $sql .= $selectFields; 
 7663    $sql .= " FROM 
" . $this->db->prefix() . "projet as p
"; 
 7664    $sql .= ' WHERE p.entity IN (' . getEntity('project') . ')'; 
 7666    // Add criteria on ref/label 
 7667    if ($filterkey != '') { 
 7669      $prefix = !getDolGlobalString('TICKET_DONOTSEARCH_ANYWHERE') ? '%' : ''; // Can use index if PRODUCT_DONOTSEARCH_ANYWHERE is on 
 7670      // For natural search 
 7671      $scrit = explode(' ', $filterkey); 
 7673      if (count($scrit) > 1) { 
 7676      foreach ($scrit as $crit) { 
 7680        $sql .= "p.ref LIKE 
'" . $this->db->escape($prefix . $crit) . "%'"; 
 7684      if (count($scrit) > 1) { 
 7690    $sql .= $this->db->plimit($limit, 0); 
 7692    // Build output string 
 7694    $result = $this->db->query($sql); 
 7696      require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php'; 
 7697      require_once DOL_DOCUMENT_ROOT . '/core/lib/project.lib.php'; 
 7699      $num = $this->db->num_rows($result); 
 7704        include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php'; 
 7705        $out .= ajax_combobox($htmlname, $events, $conf->global->PROJECT_USE_SEARCH_TO_SELECT); 
 7708      $out .= '<select class="flat
' . ($morecss ? ' ' . $morecss : '') . '" name="' . $htmlname . '" id="' . $htmlname . '">'; 
 7711      // Do not use textifempty = ' ' or ' ' here, or search on key will search on ' key'. 
 7712      //if (!empty($conf->use_javascript_ajax) || $forcecombo) $textifempty=''; 
 7713      if (getDolGlobalString('PROJECT_USE_SEARCH_TO_SELECT')) { 
 7714        if ($showempty && !is_numeric($showempty)) { 
 7715          $textifempty = $langs->trans($showempty); 
 7717          $textifempty .= $langs->trans("All
"); 
 7720        if ($showempty && !is_numeric($showempty)) { 
 7721          $textifempty = $langs->trans($showempty); 
 7725        $out .= '<option value="0
" selected>' . $textifempty . '</option>'; 
 7729      while ($num && $i < $num) { 
 7732        $objp = $this->db->fetch_object($result); 
 7734        $this->constructProjectListOption($objp, $opt, $optJson, $selected, $filterkey); 
 7736        // "key
" value of json key array is used by jQuery automatically as selected value 
 7737        // "label
" value of json key array is used by jQuery automatically as text for combo box 
 7739        array_push($outarray, $optJson); 
 7744      $out .= '</select>'; 
 7746      $this->db->free($result); 
 7748      if (empty($outputmode)) { 
 7753      dol_print_error($this->db); 
 
 7770  protected function constructProjectListOption(&$objp, &$opt, &$optJson, $selected, $filterkey = '')
 
 7776    $label = $objp->label;
 
 7778    $outkey = $objp->rowid;
 
 7779    $outref = $objp->ref;
 
 7780    $outlabel = $objp->label;
 
 7781    $outtype = $objp->fk_product_type;
 
 7783    $opt = '<option value="
' . $objp->rowid . '"'; 
 7784    $opt .= ($objp->rowid == $selected) ? ' selected' : ''; 
 7787    $objRef = $objp->ref; 
 7788    if (!empty($filterkey) && $filterkey != '') { 
 7789      $objRef = preg_replace('/(' . preg_quote($filterkey, '/') . ')/i', '<strong>$1</strong>', $objRef, 1); 
 7792    $opt .= "</option>\n
"; 
 7793    $optJson = array('key' => $outkey, 'value' => $outref, 'type' => $outtype); 
 
 7816  public function selectMembers($selected = '', $htmlname = 'adherentid', $filtertype = '', $limit = 0, $status = 1, $selected_input_value = '', $hidelabel = 0, $ajaxoptions = array(), $socid = 0, $showempty = '1', $forcecombo = 0, $morecss = '', $selected_combinations = null, $nooutput = 0)
 
 7818    global $langs, $conf;
 
 7823    if (is_null($ajaxoptions)) {
 
 7824      $ajaxoptions = array();
 
 7827    if (!empty($conf->use_javascript_ajax) && getDolGlobalString('TICKET_USE_SEARCH_TO_SELECT')) {
 
 7831      if ($selected && empty($selected_input_value)) {
 
 7832        require_once DOL_DOCUMENT_ROOT . '/adherents/class/adherent.class.php';
 
 7833        $adherenttmpselect = new Adherent($this->db);
 
 7834        $adherenttmpselect->fetch($selected);
 
 7835        $selected_input_value = $adherenttmpselect->ref;
 
 7836        unset($adherenttmpselect);
 
 7841      $out .= ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT . '/adherents/ajax/adherents.php', $urloption, $conf->global->PRODUIT_USE_SEARCH_TO_SELECT, 1, $ajaxoptions);
 
 7843      if (empty($hidelabel)) {
 
 7844        $out .= $langs->trans("RefOrLabel
") . ' : '; 
 7845      } elseif ($hidelabel > 1) { 
 7846        $placeholder = ' placeholder="' . $langs->trans("RefOrLabel") . '"'; 
 7847        if ($hidelabel == 2) { 
 7848          $out .= img_picto($langs->trans("Search
"), 'search'); 
 7851      $out .= '<input type="text
" class="minwidth100
" name="search_
' . $htmlname . '" id="search_
' . $htmlname . '" value="' . $selected_input_value . '"' . $placeholder . ' ' . (getDolGlobalString('PRODUCT_SEARCH_AUTOFOCUS') ? 'autofocus' : '') . ' />'; 
 7852      if ($hidelabel == 3) { 
 7853        $out .= img_picto($langs->trans("Search
"), 'search'); 
 7858      $out .= $this->selectMembersList($selected, $htmlname, $filtertype, $limit, $filterkey, $status, 0, $showempty, $forcecombo, $morecss); 
 7861    if (empty($nooutput)) { 
 
 7885  public function selectMembersList($selected = '', $htmlname = 'adherentid', $filtertype = '', $limit = 20, $filterkey = '', $status = 1, $outputmode = 0, $showempty = '1', $forcecombo = 0, $morecss = '')
 
 7887    global $langs, $conf;
 
 7890    $outarray = array();
 
 7892    $selectFields = " p.rowid, p.ref, p.firstname, p.lastname, p.fk_adherent_type
"; 
 7895    $sql .= $selectFields; 
 7896    $sql .= " FROM 
" . $this->db->prefix() . "adherent as p
"; 
 7897    $sql .= ' WHERE p.entity IN (' . getEntity('adherent') . ')'; 
 7899    // Add criteria on ref/label 
 7900    if ($filterkey != '') { 
 7902      $prefix = !getDolGlobalString('MEMBER_DONOTSEARCH_ANYWHERE') ? '%' : ''; // Can use index if PRODUCT_DONOTSEARCH_ANYWHERE is on 
 7903      // For natural search 
 7904      $scrit = explode(' ', $filterkey); 
 7906      if (count($scrit) > 1) { 
 7909      foreach ($scrit as $crit) { 
 7913        $sql .= "(p.firstname LIKE 
'" . $this->db->escape($prefix . $crit) . "%'"; 
 7914        $sql .= " OR p.lastname LIKE 
'" . $this->db->escape($prefix . $crit) . "%')
"; 
 7917      if (count($scrit) > 1) { 
 7922    if ($status != -1) { 
 7923      $sql .= ' AND statut = ' . ((int) $status); 
 7925    $sql .= $this->db->plimit($limit, 0); 
 7927    // Build output string 
 7929    $result = $this->db->query($sql); 
 7931      require_once DOL_DOCUMENT_ROOT . '/adherents/class/adherent.class.php'; 
 7932      require_once DOL_DOCUMENT_ROOT . '/core/lib/member.lib.php'; 
 7934      $num = $this->db->num_rows($result); 
 7939        include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php'; 
 7940        $out .= ajax_combobox($htmlname, $events, getDolGlobalString('PROJECT_USE_SEARCH_TO_SELECT') ? $conf->global->PROJECT_USE_SEARCH_TO_SELECT : ''); 
 7943      $out .= '<select class="flat
' . ($morecss ? ' ' . $morecss : '') . '" name="' . $htmlname . '" id="' . $htmlname . '">'; 
 7946      // Do not use textifempty = ' ' or ' ' here, or search on key will search on ' key'. 
 7947      //if (!empty($conf->use_javascript_ajax) || $forcecombo) $textifempty=''; 
 7948      if (getDolGlobalString('PROJECT_USE_SEARCH_TO_SELECT')) { 
 7949        if ($showempty && !is_numeric($showempty)) { 
 7950          $textifempty = $langs->trans($showempty); 
 7952          $textifempty .= $langs->trans("All
"); 
 7955        if ($showempty && !is_numeric($showempty)) { 
 7956          $textifempty = $langs->trans($showempty); 
 7960        $out .= '<option value="-1
" selected>' . $textifempty . '</option>'; 
 7964      while ($num && $i < $num) { 
 7967        $objp = $this->db->fetch_object($result); 
 7969        $this->constructMemberListOption($objp, $opt, $optJson, $selected, $filterkey); 
 7972        // "key
" value of json key array is used by jQuery automatically as selected value 
 7973        // "label
" value of json key array is used by jQuery automatically as text for combo box 
 7975        array_push($outarray, $optJson); 
 7980      $out .= '</select>'; 
 7982      $this->db->free($result); 
 7984      if (empty($outputmode)) { 
 7989      dol_print_error($this->db); 
 
 8006  protected function constructMemberListOption(&$objp, &$opt, &$optJson, $selected, $filterkey = '')
 
 8012    $outkey = $objp->rowid;
 
 8013    $outlabel = dolGetFirstLastname($objp->firstname, $objp->lastname);
 
 8014    $outtype = $objp->fk_adherent_type;
 
 8016    $opt = '<option value="
' . $objp->rowid . '"'; 
 8017    $opt .= ($objp->rowid == $selected) ? ' selected' : ''; 
 8019    if (!empty($filterkey) && $filterkey != '') { 
 8020      $outlabel = preg_replace('/(' . preg_quote($filterkey, '/') . ')/i', '<strong>$1</strong>', $outlabel, 1); 
 8023    $opt .= "</option>\n
"; 
 8025    $optJson = array('key' => $outkey, 'value' => $outlabel, 'type' => $outtype); 
 
 8048  public function selectForForms($objectdesc, $htmlname, $preSelectedValue, $showempty = '', $searchkey = '', $placeholder = '', $morecss = '', $moreparams = '', $forcecombo = 0, $disabled = 0, $selected_input_value = '', $objectfield = '')
 
 8050    global $conf, $extrafields, $user;
 
 8052    //var_dump($objectdesc); debug_print_backtrace();
 
 8054    $objectdescorig = $objectdesc;
 
 8056    $InfoFieldList = array();
 
 8058    if ($objectfield) { // We must retreive the objectdesc from the field or extrafield
 
 8059      // Example: $objectfield = 'product:options_package'
 
 8060      $tmparray = explode(':', $objectfield);
 
 8062      // Load object according to $id and $element
 
 8063      $objectforfieldstmp = fetchObjectByElement(0, strtolower($tmparray[0]));
 
 8065      if (is_object($objectforfieldstmp)) {
 
 8069        if (preg_match('/^options_(.*)$/', $tmparray[1], $reg)) {
 
 8070          // For a property in extrafields
 
 8072          // fetch optionals attributes and labels
 
 8073          $extrafields->fetch_name_optionals_label($objectforfieldstmp->table_element);
 
 8075          if (!empty($extrafields->attributes[$objectforfieldstmp->table_element]['type'][$key]) && $extrafields->attributes[$objectforfieldstmp->table_element]['type'][$key] == 'link') {
 
 8076            if (!empty($extrafields->attributes[$objectforfieldstmp->table_element]['param'][$key]['options'])) {
 
 8077              $tmpextrafields = array_keys($extrafields->attributes[$objectforfieldstmp->table_element]['param'][$key]['options']);
 
 8078              $objectdesc = $tmpextrafields[0];
 
 8082          // For a property in ->fields
 
 8083          if (array_key_exists($tmparray[1], $objectforfieldstmp->fields)) {
 
 8084            $objectdesc = $objectforfieldstmp->fields[$tmparray[1]]['type'];
 
 8085            $objectdesc = preg_replace('/^integer[^:]*:/', '', $objectdesc);
 
 8092      // Example of value for $objectdesc:
 
 8093      // Bom:bom/class/bom.class.php:0:t.status=1
 
 8094      // Bom:bom/class/bom.class.php:0:t.status=1:ref
 
 8095      // Bom:bom/class/bom.class.php:0:(t.status:=:1) OR (t.field2:=:2):ref
 
 8096      $InfoFieldList = explode(":
", $objectdesc, 4); 
 8097      $vartmp = (empty($InfoFieldList[3]) ? '' : $InfoFieldList[3]); 
 8099      if (preg_match('/^.*:(\w*)$/', $vartmp, $reg)) { 
 8100        $InfoFieldList[4] = $reg[1];    // take the sort field 
 8102      $InfoFieldList[3] = preg_replace('/:\w*$/', '', $vartmp);    // take the filter field 
 8104      $classname = $InfoFieldList[0]; 
 8105      $classpath = empty($InfoFieldList[1]) ? '' : $InfoFieldList[1]; 
 8106      //$addcreatebuttonornot = empty($InfoFieldList[2]) ? 0 : $InfoFieldList[2]; 
 8107      $filter = empty($InfoFieldList[3]) ? '' : $InfoFieldList[3]; 
 8108      $sortfield = empty($InfoFieldList[4]) ? '' : $InfoFieldList[4]; 
 8110      // Load object according to $id and $element 
 8111      $objecttmp = fetchObjectByElement(0, strtolower($InfoFieldList[0])); 
 8113      // Fallback to another solution to get $objecttmp 
 8114      if (empty($objecttmp) && !empty($classpath)) { 
 8115        dol_include_once($classpath); 
 8117        if ($classname && class_exists($classname)) { 
 8118          $objecttmp = new $classname($this->db); 
 8123    // Make some replacement in $filter. May not be used if we used the ajax mode with $objectfield. In such a case 
 8124    // we propagate the $objectfield and not the filter and replacement is done by the ajax/selectobject.php component. 
 8125    $sharedentities = getEntity($objecttmp->element); 
 8126    $filter = str_replace( 
 8127      array('__ENTITY__', '__SHARED_ENTITIES__', '__USER_ID__'), 
 8128      array($conf->entity, $sharedentities, $user->id), 
 8132    if (!is_object($objecttmp)) { 
 8133      dol_syslog('selectForForms: Error bad setup of field objectdescorig=' . $objectdescorig.', objectfield='.$objectfield.', objectdesc='.$objectdesc, LOG_WARNING); 
 8134      return 'selectForForms: Error bad setup of field objectdescorig=' . $objectdescorig.', objectfield='.$objectfield.', objectdesc='.$objectdesc; 
 8137    //var_dump($filter); 
 8138    $prefixforautocompletemode = $objecttmp->element; 
 8139    if ($prefixforautocompletemode == 'societe') { 
 8140      $prefixforautocompletemode = 'company'; 
 8142    if ($prefixforautocompletemode == 'product') { 
 8143      $prefixforautocompletemode = 'produit'; 
 8145    $confkeyforautocompletemode = strtoupper($prefixforautocompletemode) . '_USE_SEARCH_TO_SELECT'; // For example COMPANY_USE_SEARCH_TO_SELECT 
 8147    dol_syslog(get_class($this) . "::
selectForForms filter=
" . $filter, LOG_DEBUG); 
 8149    // Generate the combo HTML component 
 8151    if (!empty($conf->use_javascript_ajax) && getDolGlobalString($confkeyforautocompletemode) && !$forcecombo) { 
 8152      // No immediate load of all database 
 8155      if ($preSelectedValue && empty($selected_input_value)) { 
 8156        $objecttmp->fetch($preSelectedValue); 
 8157        $selected_input_value = ($prefixforautocompletemode == 'company' ? $objecttmp->name : $objecttmp->ref); 
 8159        $oldValueForShowOnCombobox = 0; 
 8160        foreach ($objecttmp->fields as $fieldK => $fielV) { 
 8161          if (!array_key_exists('showoncombobox', $fielV) || !$fielV['showoncombobox'] || empty($objecttmp->$fieldK)) continue; 
 8163          if (!$oldValueForShowOnCombobox) { 
 8164            $selected_input_value = ''; 
 8167          $selected_input_value .= $oldValueForShowOnCombobox ? ' - ' : ''; 
 8168          $selected_input_value .= $objecttmp->$fieldK; 
 8169          $oldValueForShowOnCombobox = empty($fielV['showoncombobox']) ? 0 : $fielV['showoncombobox']; 
 8173      // Set url and param to call to get json of the search results 
 8174      $urlforajaxcall = DOL_URL_ROOT . '/core/ajax/selectobject.php'; 
 8175      $urloption = 'htmlname=' . urlencode($htmlname) . '&outjson=1&objectdesc=' . urlencode($objectdescorig) . '&objectfield='.urlencode($objectfield) . ($sortfield ? '&sortfield=' . urlencode($sortfield) : ''); 
 8177      // Activate the auto complete using ajax call. 
 8178      $out .= ajax_autocompleter($preSelectedValue, $htmlname, $urlforajaxcall, $urloption, getDolGlobalString($confkeyforautocompletemode), 0); 
 8179      $out .= '<!-- force css to be higher than dialog popup --><style type="text/css
">.ui-autocomplete { z-index: 1010; }</style>'; 
 8180      $out .= '<input type="text
" class="' . $morecss . '"' . ($disabled ? ' disabled="disabled
"' : '') . ' name="search_
' . $htmlname . '" id="search_
' . $htmlname . '" value="' . $selected_input_value . '"' . ($placeholder ? ' placeholder="' . dol_escape_htmltag($placeholder) . '"' : '') . ' />'; 
 8182      // Immediate load of table record. 
 8183      $out .= $this->selectForFormsList($objecttmp, $htmlname, $preSelectedValue, $showempty, $searchkey, $placeholder, $morecss, $moreparams, $forcecombo, 0, $disabled, $sortfield, $filter); 
 
 8210  public function selectForFormsList($objecttmp, $htmlname, $preselectedvalue, $showempty = '', $searchkey = '', $placeholder = '', $morecss = '', $moreparams = '', $forcecombo = 0, $outputmode = 0, $disabled = 0, $sortfield = '', $filter = '')
 
 8212    global $langs, $user, $hookmanager;
 
 8214    //print "$htmlname, $preselectedvalue, $showempty, $searchkey, $placeholder, $morecss, $moreparams, $forcecombo, $outputmode, $disabled
"; 
 8216    $prefixforautocompletemode = $objecttmp->element; 
 8217    if ($prefixforautocompletemode == 'societe') { 
 8218      $prefixforautocompletemode = 'company'; 
 8220    $confkeyforautocompletemode = strtoupper($prefixforautocompletemode) . '_USE_SEARCH_TO_SELECT'; // For example COMPANY_USE_SEARCH_TO_SELECT 
 8222    if (!empty($objecttmp->fields)) {    // For object that declare it, it is better to use declared fields (like societe, contact, ...) 
 8223      $tmpfieldstoshow = ''; 
 8224      foreach ($objecttmp->fields as $key => $val) { 
 8225        if (!dol_eval($val['enabled'], 1, 1, '1')) { 
 8228        if (!empty($val['showoncombobox'])) { 
 8229          $tmpfieldstoshow .= ($tmpfieldstoshow ? ',' : '') . 't.' . $key; 
 8232      if ($tmpfieldstoshow) { 
 8233        $fieldstoshow = $tmpfieldstoshow; 
 8236      // For backward compatibility 
 8237      $objecttmp->fields['ref'] = array('type' => 'varchar(30)', 'label' => 'Ref', 'showoncombobox' => 1); 
 8240    if (empty($fieldstoshow)) { 
 8241      if (isset($objecttmp->fields['ref'])) { 
 8242        $fieldstoshow = 't.ref'; 
 8244        $langs->load("errors
"); 
 8245        $this->error = $langs->trans("ErrorNoFieldWithAttributeShowoncombobox
"); 
 8246        return $langs->trans('ErrorNoFieldWithAttributeShowoncombobox'); 
 8251    $outarray = array(); 
 8252    $tmparray = array(); 
 8257    $sql = "SELECT t.
rowid, 
" . $fieldstoshow . " FROM 
" . $this->db->prefix() . $objecttmp->table_element . " as t
"; 
 8258    if (!empty($objecttmp->isextrafieldmanaged)) { 
 8259      $sql .= " LEFT JOIN 
" . $this->db->prefix() . $objecttmp->table_element . "_extrafields as e ON t.
rowid=e.fk_object
"; 
 8261    if (isset($objecttmp->ismultientitymanaged)) { 
 8262      if (!is_numeric($objecttmp->ismultientitymanaged)) { 
 8263        $tmparray = explode('@', $objecttmp->ismultientitymanaged); 
 8264        $sql .= " INNER JOIN 
" . $this->db->prefix() . $tmparray[1] . " as parenttable ON parenttable.
rowid = t.
" . $tmparray[0]; 
 8266      if ($objecttmp->ismultientitymanaged === 'fk_soc@societe') { 
 8267        if (!$user->hasRight('societe', 'client', 'voir') && !$user->socid) { 
 8268          $sql .= ", 
" . $this->db->prefix() . "societe_commerciaux as sc
"; 
 8273    // Add where from hooks 
 8274    $parameters = array( 
 8275      'object' => $objecttmp, 
 8276      'htmlname' => $htmlname, 
 8277      'filter' => $filter, 
 8278      'searchkey' => $searchkey 
 8281    $reshook = $hookmanager->executeHooks('selectForFormsListWhere', $parameters); // Note that $action and $object may have been modified by hook 
 8282    if (!empty($hookmanager->resPrint)) { 
 8283      $sql .= $hookmanager->resPrint; 
 8285      $sql .= " WHERE 1=1
"; 
 8286      if (isset($objecttmp->ismultientitymanaged)) { 
 8287        if ($objecttmp->ismultientitymanaged == 1) { 
 8288          $sql .= " AND t.entity IN (
" . getEntity($objecttmp->table_element) . ")
"; 
 8290        if (!is_numeric($objecttmp->ismultientitymanaged)) { 
 8291          $sql .= " AND parenttable.entity = t.
" . $tmparray[0]; 
 8293        if ($objecttmp->ismultientitymanaged == 1 && !empty($user->socid)) { 
 8294          if ($objecttmp->element == 'societe') { 
 8295            $sql .= " AND t.
rowid = 
" . ((int) $user->socid); 
 8297            $sql .= " AND t.fk_soc = 
" . ((int) $user->socid); 
 8300        if ($objecttmp->ismultientitymanaged === 'fk_soc@societe') { 
 8301          if (!$user->hasRight('societe', 'client', 'voir') && !$user->socid) { 
 8302            $sql .= " AND t.
rowid = sc.fk_soc AND sc.fk_user = 
" . ((int) $user->id); 
 8306      if ($searchkey != '') { 
 8307        $sql .= natural_search(explode(',', $fieldstoshow), $searchkey); 
 8310      if ($filter) {     // Syntax example "(t.
ref:like:
'SO-%') and (t.date_creation:<:
'20160101')
" 
 8312        $sql .= forgeSQLFromUniversalSearchCriteria($filter, $errormessage); 
 8313        if ($errormessage) { 
 8314          return 'Error forging a SQL request from an universal criteria: ' . $errormessage; 
 8318    $sql .= $this->db->order($sortfield ? $sortfield : $fieldstoshow, "ASC
"); 
 8319    //$sql.=$this->db->plimit($limit, 0); 
 8322    // Build output string 
 8323    $resql = $this->db->query($sql); 
 8325      // Construct $out and $outarray 
 8326      $out .= '<select id="' . $htmlname . '" class="flat minwidth100
' . ($morecss ? ' ' . $morecss : '') . '"' . ($disabled ? ' disabled="disabled
"' : '') . ($moreparams ? ' ' . $moreparams : '') . ' name="' . $htmlname . '">' . "\n
"; 
 8328      // Warning: Do not use textifempty = ' ' or ' ' here, or search on key will search on ' key'. Seems it is no more true with selec2 v4 
 8329      $textifempty = ' '; 
 8331      //if (!empty($conf->use_javascript_ajax) || $forcecombo) $textifempty=''; 
 8332      if (getDolGlobalInt($confkeyforautocompletemode)) { 
 8333        if ($showempty && !is_numeric($showempty)) { 
 8334          $textifempty = $langs->trans($showempty); 
 8336          $textifempty .= $langs->trans("All
"); 
 8340        $out .= '<option value="-1
">' . $textifempty . '</option>' . "\n
"; 
 8343      $num = $this->db->num_rows($resql); 
 8347          $obj = $this->db->fetch_object($resql); 
 8350          $tmparray = explode(',', $fieldstoshow); 
 8351          $oldvalueforshowoncombobox = 0; 
 8352          foreach ($tmparray as $key => $val) { 
 8353            $val = preg_replace('/t\./', '', $val); 
 8354            $label .= (($label && $obj->$val) ? ($oldvalueforshowoncombobox != $objecttmp->fields[$val]['showoncombobox'] ? ' - ' : ' ') : ''); 
 8355            $labelhtml .= (($label && $obj->$val) ? ($oldvalueforshowoncombobox != $objecttmp->fields[$val]['showoncombobox'] ? ' - ' : ' ') : ''); 
 8356            $label .= $obj->$val; 
 8357            $labelhtml .= $obj->$val; 
 8359            $oldvalueforshowoncombobox = empty($objecttmp->fields[$val]['showoncombobox']) ? 0 : $objecttmp->fields[$val]['showoncombobox']; 
 8361          if (empty($outputmode)) { 
 8362            if ($preselectedvalue > 0 && $preselectedvalue == $obj->rowid) { 
 8363              $out .= '<option value="' . $obj->rowid . '" selected data-html="' . dol_escape_htmltag($labelhtml, 0, 0, '', 0, 1) . '">' . dol_escape_htmltag($label, 0, 0, '', 0, 1) . '</option>'; 
 8365              $out .= '<option value="' . $obj->rowid . '" data-html="' . dol_escape_htmltag($labelhtml, 0, 0, '', 0, 1) . '">' . dol_escape_htmltag($label, 0, 0, '', 0, 1) . '</option>'; 
 8368            array_push($outarray, array('key' => $obj->rowid, 'value' => $label, 'label' => $label)); 
 8372          if (($i % 10) == 0) { 
 8378      $out .= '</select>' . "\n
"; 
 8381        include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php'; 
 8382        $out .= ajax_combobox($htmlname, null, getDolGlobalInt($confkeyforautocompletemode, 0)); 
 8385      dol_print_error($this->db); 
 8388    $this->result = array('nbofelement' => $num); 
 
 8420  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 = 'minwidth75', $addjscombo = 1, $moreparamonempty = '', $disablebademail = 0, $nohtmlescape = 0)
 
 8422    global $conf, $langs;
 
 8424    // Do we want a multiselect ?
 
 8426    //if (preg_match('/^multi/',$htmlname)) $jsbeautify = 1;
 
 8429    if ($value_as_key) {
 
 8430      $array = array_combine($array, $array);
 
 8435    if ($addjscombo < 0) {
 
 8436      if (!getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
 
 8442    $idname = str_replace(array('[', ']'), array('', ''), $htmlname);
 
 8443    $out .= '<select id="
' . preg_replace('/^\./
', '', $idname) . '" ' . ($disabled ? 'disabled="disabled
" ' : '') . 'class="flat 
' . (preg_replace('/^\./
', '', $htmlname)) . ($morecss ? ' ' . $morecss : '') . ' selectformat
"'; 
 8444    $out .= ' name="' . preg_replace('/^\./
', '', $htmlname) . '" ' . ($moreparam ? $moreparam : ''); 
 8448      $textforempty = ' '; 
 8449      if (!empty($conf->use_javascript_ajax)) { 
 8450        $textforempty = ' '; // If we use ajaxcombo, we need   here to avoid to have an empty element that is too small. 
 8452      if (!is_numeric($show_empty)) { 
 8453        $textforempty = $show_empty; 
 8455      $out .= '<option class="optiongrey
" ' . ($moreparamonempty ? $moreparamonempty . ' ' : '') . 'value="' . (((int) $show_empty) < 0 ? $show_empty : -1) . '"' . ($id == $show_empty ? ' selected' : '') . '>' . $textforempty . '</option>' . "\n
"; 
 8457    if (is_array($array)) { 
 8460        foreach ($array as $key => $value) { 
 8461          if (!is_array($value)) { 
 8462            $array[$key] = $langs->trans($value); 
 8464            $array[$key]['label'] = $langs->trans($value['label']); 
 8469      if ($sort == 'ASC') { 
 8471      } elseif ($sort == 'DESC') { 
 8474      foreach ($array as $key => $tmpvalue) { 
 8475        if (is_array($tmpvalue)) { 
 8476          $value = $tmpvalue['label']; 
 8477          $disabled = empty($tmpvalue['disabled']) ? '' : ' disabled'; 
 8478          $style = empty($tmpvalue['css']) ? '' : ' class="' . $tmpvalue['css
'] . '"'; 
 8484        if (!empty($disablebademail)) { 
 8485          if (($disablebademail == 1 && !preg_match('/<.+@.+>/', $value)) 
 8486            || ($disablebademail == 2 && preg_match('/---/', $value))) { 
 8487            $disabled = ' disabled'; 
 8488            $style = ' class="warning
"'; 
 8491        if ($key_in_label) { 
 8492          if (empty($nohtmlescape)) { 
 8493            $selectOptionValue = dol_escape_htmltag($key . ' - ' . ($maxlen ? dol_trunc($value, $maxlen) : $value)); 
 8495            $selectOptionValue = $key . ' - ' . ($maxlen ? dol_trunc($value, $maxlen) : $value); 
 8498          if (empty($nohtmlescape)) { 
 8499            $selectOptionValue = dol_escape_htmltag($maxlen ? dol_trunc($value, $maxlen) : $value); 
 8501            $selectOptionValue = $maxlen ? dol_trunc($value, $maxlen) : $value; 
 8503          if ($value == '' || $value == '-') { 
 8504            $selectOptionValue = ' '; 
 8507        $out .= '<option value="' . $key . '"'; 
 8508        $out .= $style . $disabled; 
 8509        if (is_array($id)) { 
 8510          if (in_array($key, $id) && !$disabled) { 
 8511            $out .= ' selected'; // To preselect a value 
 8514          $id = (string) $id; // if $id = 0, then $id = '0' 
 8515          if ($id != '' && ($id == $key || ($id == 'ifone' && count($array) == 1)) && !$disabled) { 
 8516            $out .= ' selected'; // To preselect a value 
 8519        if ($nohtmlescape) { 
 8520          $out .= ' data-html="' . dol_escape_htmltag($selectOptionValue) . '"'; 
 8522        if (is_array($tmpvalue)) { 
 8523          foreach ($tmpvalue as $keyforvalue => $valueforvalue) { 
 8524            if (preg_match('/^data-/', $keyforvalue)) { 
 8525              $out .= ' '.$keyforvalue.'="'.dol_escape_htmltag($valueforvalue).'"'; 
 8530        $out .= $selectOptionValue; 
 8531        $out .= "</option>\n
"; 
 8534    $out .= "</select>
"; 
 8535    // Add code for jquery to use multiselect 
 8536    if ($addjscombo && $jsbeautify) { 
 8537      // Enhance with select2 
 8538      include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php'; 
 8539      $out .= ajax_combobox($idname, array(), 0, 0, 'resolve', (((int) $show_empty) < 0 ? (string) $show_empty : '-1'), $morecss); 
 
 8563  public static function selectArrayAjax($htmlname, $url, $id = '', $moreparam = '', $moreparamtourl = '', $disabled = 0, $minimumInputLength = 1, $morecss = '', $callurlonselect = 0, $placeholder = '', $acceptdelayedhtml = 0)
 
 8565    global $conf, $langs;
 
 8566    global $delayedhtmlcontent;    // Will be used later outside of this function
 
 8568    // TODO Use an internal dolibarr component instead of select2
 
 8569    if (!getDolGlobalString('MAIN_USE_JQUERY_MULTISELECT') && !defined('REQUIRE_JQUERY_MULTISELECT')) {
 
 8573    $out = '<select type="text
" class="' . $htmlname . ($morecss ? ' ' . $morecss : '') . '" ' . ($moreparam ? $moreparam . ' ' : '') . 'name="' . $htmlname . '"></select>'; 
 8576    if (!empty($conf->use_javascript_ajax)) { 
 8577      $tmpplugin = 'select2'; 
 8578      $outdelayed = "\n
" . '<!-- JS CODE TO ENABLE ' . $tmpplugin . ' for id ' . $htmlname . ' --> 
 8579          <script nonce="' . getNonce() . '"> 
 8580          $(document).ready(function () { 
 8582                ' . ($callurlonselect ? 'var saveRemoteData = [];' : '') . ' 
 8584                  $(".
' . $htmlname . '").select2({ 
 8587                url: "' . $url . '", 
 8590                data: function (params) { 
 8592                    q: params.term,   // search term 
 8596                processResults: function (data) { 
 8597                  // parse the results into the format expected by Select2. 
 8598                  // since we are using custom formatting functions we do not need to alter the remote JSON data 
 8599                  //console.log(data); 
 8600                saveRemoteData = data; 
 8601                    /* format json result for select2 */ 
 8603                    $.each( data, function( key, value ) { 
 8604                       result.push({id: key, text: value.text}); 
 8606                  //return {results:[{id:\'none\', text:\'aa\'}, {id:\'rrr\', text:\'Red\'},{id:\'bbb\', text:\'Search a into projects\'}], more:false} 
 8607                  //console.log(result); 
 8608                  return {results: result, more: false} 
 8612            language: (typeof select2arrayoflanguage === \'undefined\') ? \'en\' : select2arrayoflanguage, 
 8613            containerCssClass: \':all:\',         /* Line to add class of origin SELECT propagated to the new <span class="select2-selection...> tag */
 
 8614              placeholder: 
"' . dol_escape_js($placeholder) . '",
 
 8615              escapeMarkup: function (markup) { 
return markup; },   
 
 8616              minimumInputLength: 
' . ((int) $minimumInputLength) . ',
 
 8617                formatResult: 
function (result, container, query, escapeMarkup) {
 
 8618                          return escapeMarkup(result.text);
 
 8622                  ' . ($callurlonselect ? ' 
 8624                  $(
".' . $htmlname . '").change(
function() {
 
 8625              var selected = $(
".' . $htmlname . '").val();
 
 8626                    console.log(
"We select in selectArrayAjax the entry "+selected)
 
 8627                $(
".' . $htmlname . '").val(
"");  
 
 8628                $.each( saveRemoteData, 
function( key, value ) {
 
 8629                      if (key == selected)
 
 8631                             console.log(
"selectArrayAjax - Do a redirect to "+value.url)
 
 8632                             location.assign(value.url);
 
 8641    if ($acceptdelayedhtml) { 
 8642      $delayedhtmlcontent .= $outdelayed; 
 8644      $out .= $outdelayed; 
 
 8668  public static function selectArrayFilter($htmlname, $array, $id = '
', $moreparam = '', $disableFiltering = 0, $disabled = 0, $minimumInputLength = 1, $morecss = '', $callurlonselect = 0, $placeholder = '', $acceptdelayedhtml = 0, $textfortitle = '') 
 8670    global $conf, $langs; 
 8671    global $delayedhtmlcontent;    // Will be used later outside of this function 
 8673    // TODO Use an internal dolibarr component instead of select2 
 8674    if (!getDolGlobalString('MAIN_USE_JQUERY_MULTISELECT
') && !defined('REQUIRE_JQUERY_MULTISELECT
')) { 
 8678    $out = '<select 
type=
"text"'.($textfortitle ? ' title=
"'.dol_escape_htmltag($textfortitle).'"' : '').' id=
"'.$htmlname.'" class=
"'.$htmlname.($morecss ? ' ' . $morecss : '').'"'.($moreparam ? ' '.$moreparam : '').' name=
"'.$htmlname.'"><option></option></select>
'; 
 8680    $formattedarrayresult = array(); 
 8682    foreach ($array as $key => $value) { 
 8683      $o = new stdClass(); 
 8685      $o->text = $value['text
']; 
 8686      $o->url = $value['url
']; 
 8687      $formattedarrayresult[] = $o; 
 8691    if (!empty($conf->use_javascript_ajax)) { 
 8692      $tmpplugin = 'select2
'; 
 8693      $outdelayed = "\n" . '<!-- JS CODE TO ENABLE 
' . $tmpplugin . ' for id ' . $htmlname . ' -->
 
 8694        <script nonce=
"' . getNonce() . '">
 
 8695        $(document).ready(
function () {
 
 8696          var data = 
' . json_encode($formattedarrayresult) . ';
 
 8698          ' . ($callurlonselect ? 'var saveRemoteData = 
' . json_encode($array) . ';
' : '') . ' 
 8700          $(
".' . $htmlname . '").select2({
 
 8702            language: (typeof select2arrayoflanguage === \
'undefined\') ? \'en\' : select2arrayoflanguage, 
 8703            containerCssClass: \':all:\',         /* Line to add class of origin SELECT propagated to the new <span class="select2-selection...> tag */ 
 8705            escapeMarkup: function (markup) { return markup; },   // let our custom formatter work 
 8706            minimumInputLength: ' . $minimumInputLength . 
', 
 8707            formatResult: function (result, container, query, escapeMarkup) { 
 8708              return escapeMarkup(result.text); 
 8710            matcher: function (params, data) { 
 8712              if(! data.id) return null;';
 
 8714      if ($callurlonselect) {
 
 8718              var urlBase = data.url; 
 8719              var separ = urlBase.indexOf("?") >= 0 ? "&" : "?"; 
 8720              /* console.log("params.term="+params.term); */ 
 8721              /* console.log("params.term encoded="+encodeURIComponent(params.term)); */ 
 8722              saveRemoteData[data.id].url = urlBase + separ + "search_all=" + encodeURIComponent(params.term.replace(/\"/g, ""));';
 
 8725      if (!$disableFiltering) {
 
 8728              if(data.text.match(new RegExp(params.term))) { 
 8743          ' . ($callurlonselect ? 
' 
 8744          /* Code to execute a GET when we select a value */ 
 8745          $(".' . $htmlname . 
'").change(function() { 
 8746            var selected = $(".' . $htmlname . 
'").val(); 
 8747            console.log("We select "+selected) 
 8749            $(".' . $htmlname . 
'").val("");  /* reset visible combo value */ 
 8750            $.each( saveRemoteData, function( key, value ) { 
 8751              if (key == selected) 
 8753                console.log("selectArrayFilter - Do a redirect to "+value.url) 
 8754                location.assign(value.url); 
 8763    if ($acceptdelayedhtml) {
 
 8764      $delayedhtmlcontent .= $outdelayed;
 
 8766      $out .= $outdelayed;
 
 
 8789  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)
 
 8791    global $conf, $langs;
 
 8795    if ($addjscombo < 0) {
 
 8803    $useenhancedmultiselect = 0;
 
 8804    if (!empty($conf->use_javascript_ajax) && (
getDolGlobalString(
'MAIN_USE_JQUERY_MULTISELECT') || defined(
'REQUIRE_JQUERY_MULTISELECT'))) {
 
 8806        $useenhancedmultiselect = 1;  
 
 8813    $out .= 
'<input type="hidden" name="'.$htmlname.
'_multiselect" value="1">';
 
 8815    $out .= 
'<select id="' . $htmlname . 
'" class="multiselect' . ($useenhancedmultiselect ? 
' multiselectononeline' : 
'') . ($morecss ? 
' ' . $morecss : 
'') . 
'" multiple name="' . $htmlname . 
'[]"' . ($moreattrib ? 
' ' . $moreattrib : 
'') . ($width ? 
' style="width: ' . (preg_match(
'/%/', $width) ? $width : $width . 
'px') . 
'"' : 
'') . 
'>' . 
"\n";
 
 8816    if (is_array($array) && !empty($array)) {
 
 8817      if ($value_as_key) {
 
 8818        $array = array_combine($array, $array);
 
 8821      if (!empty($array)) {
 
 8822        foreach ($array as $key => $value) {
 
 8828          if (is_array($value) && array_key_exists(
'id', $value) && array_key_exists(
'label', $value)) {
 
 8829            $tmpkey = $value[
'id'];
 
 8830            $tmpvalue = empty($value[
'label']) ? 
'' : $value[
'label'];
 
 8831            $tmpcolor = empty($value[
'color']) ? 
'' : $value[
'color'];
 
 8832            $tmppicto = empty($value[
'picto']) ? 
'' : $value[
'picto'];
 
 8833            $tmplabelhtml = empty($value[
'labelhtml']) ? 
'' : $value[
'labelhtml'];
 
 8835          $newval = ($translate ? $langs->trans($tmpvalue) : $tmpvalue);
 
 8836          $newval = ($key_in_label ? $tmpkey . 
' - ' . $newval : $newval);
 
 8838          $out .= 
'<option value="' . $tmpkey . 
'"';
 
 8839          if (is_array($selected) && !empty($selected) && in_array((
string) $tmpkey, $selected) && ((string) $tmpkey != 
'')) {
 
 8840            $out .= 
' selected';
 
 8842          if (!empty($tmplabelhtml)) {
 
 8845            $tmplabelhtml = ($tmppicto ? 
img_picto(
'', $tmppicto, 
'class="pictofixedwidth" style="color: #' . $tmpcolor . 
'"') : 
'') . $newval;
 
 8850          $out .= 
'</option>' . 
"\n";
 
 8854    $out .= 
'</select>' . 
"\n";
 
 8857    if (!empty($conf->use_javascript_ajax) && 
getDolGlobalString(
'MAIN_USE_JQUERY_MULTISELECT') || defined(
'REQUIRE_JQUERY_MULTISELECT')) {
 
 8858      $out .= 
"\n" . 
'<!-- JS CODE TO ENABLE select for id ' . $htmlname . 
', addjscombo=' . $addjscombo . 
' -->';
 
 8859      $out .= 
"\n" . 
'<script nonce="' . 
getNonce() . 
'">' . 
"\n";
 
 8860      if ($addjscombo == 1) {
 
 8861        $tmpplugin = !
getDolGlobalString(
'MAIN_USE_JQUERY_MULTISELECT') ? constant(
'REQUIRE_JQUERY_MULTISELECT') : $conf->global->MAIN_USE_JQUERY_MULTISELECT;
 
 8862        $out .= 
'function formatResult(record, container) {' . 
"\n";
 
 8865        $out .= 
' if ($(record.element).attr("data-html") != undefined) { return htmlEntityDecodeJs($(record.element).attr("data-html")); }'.
"\n";
 
 8866        $out .= 
' return record.text;';
 
 8868        $out .= 
'function formatSelection(record) {' . 
"\n";
 
 8869        if ($elemtype == 
'category') {
 
 8870          $out .= 
'return \'<span><img src="' . DOL_URL_ROOT . 
'/theme/eldy/img/object_category.png"> \'+record.text+\'</span>\';';
 
 8872          $out .= 
'return record.text;';
 
 8875        $out .= 
'$(document).ready(function () { 
 8876              $(\'#' . $htmlname . 
'\').
' . $tmpplugin . '({
'; 
 8884        $out .= '   dir: \
'ltr\', 
 8885                containerCssClass: \':all:\',         /* Line to add class of origin SELECT propagated to the new <span class="select2-selection...> tag (ko with multiselect) */ 
 8886                dropdownCssClass: \'' . $morecss . 
'\',       
 
 8888                formatResult: formatResult,
 
 8889                templateResult: formatResult,   
 
 8890                escapeMarkup: 
function (markup) { 
return markup; },   
 
 8892                formatSelection: formatSelection,
 
 8893                templateSelection: formatSelection,   
 
 8894                language: select2arrayoflanguage
 
 8899              $(\
'#' . $htmlname . 
' + .select2\').addClass(\'' . $morecss . 
'\');
 
 8901      } elseif ($addjscombo == 2 && !defined('DISABLE_MULTISELECT
')) { 
 8903        // TODO external lib multiselect/jquery.multi-select.js must have been loaded to use this multiselect plugin 
 8905        $out .= 'console.log(\
'addjscombo=2 for htmlname=' . $htmlname . 
'\');
'; 
 8906        $out .= '$(document).ready(
function () {
 
 8907              $(\
'#' . $htmlname . 
'\').multiSelect({
 
 8908                containerHTML: \
'<div class="multi-select-container">\', 
 8909                menuHTML: \'<div class="multi-select-menu">\', 
 8910                buttonHTML: \'<span class="multi-select-button ' . $morecss . 
'">\', 
 8911                menuItemHTML: \'<label class="multi-select-menuitem">\', 
 8912                activeClass: \'multi-select-container--open\', 
 8913                noneText: \'' . $placeholder . 
'\' 
 8917      $out .= '</script>
'; 
 
 8934  public static function multiSelectArrayWithCheckbox($htmlname, &$array, $varpage, $pos = '
') 
 8936    global $conf, $langs, $user, $extrafields; 
 8938    if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER
')) { 
 8941    if (empty($array)) { 
 8945    $tmpvar = "MAIN_SELECTEDFIELDS_" . $varpage; // To get list of saved selected fields to show 
 8947    if (!empty($user->conf->$tmpvar)) {        // A list of fields was already customized for user 
 8948      $tmparray = explode(',
', $user->conf->$tmpvar); 
 8949      foreach ($array as $key => $val) { 
 8951        //var_dump($tmparray); 
 8952        if (in_array($key, $tmparray)) { 
 8953          $array[$key]['checked
'] = 1; 
 8955          $array[$key]['checked
'] = 0; 
 8958    } else {                                // There is no list of fields already customized for user 
 8959      foreach ($array as $key => $val) { 
 8960        if (!empty($array[$key]['checked
']) && $array[$key]['checked
'] < 0) { 
 8961          $array[$key]['checked
'] = 0; 
 8966    $listoffieldsforselection = ''; 
 8967    $listcheckedstring = ''; 
 8969    foreach ($array as $key => $val) { 
 8971      // var_dump(array_key_exists('enabled
', $val)); 
 8972      // var_dump(!$val['enabled
']); 
 8973      if (array_key_exists('enabled
', $val) && isset($val['enabled
']) && !$val['enabled
']) { 
 8974        unset($array[$key]); // We don't want 
this field
 
 8977      if (!empty($val[
'type']) && $val[
'type'] == 
'separate') {
 
 8982      if ($val[
'label']) {
 
 8983        if (!empty($val[
'langfile']) && is_object($langs)) {
 
 8984          $langs->load($val[
'langfile']);
 
 8988        $listoffieldsforselection .= 
'<li><input type="checkbox" id="checkbox' . $key . 
'" value="' . $key . 
'"' . ((empty($val[
'checked']) || $val[
'checked'] == 
'-1') ? 
'' : 
' checked="checked"') . 
'/><label for="checkbox' . $key . 
'">' . 
dol_escape_htmltag($langs->trans($val[
'label'])) . 
'</label></li>';
 
 8989        $listcheckedstring .= (empty($val[
'checked']) ? 
'' : $key . 
',');
 
 8993    $out = 
'<!-- Component multiSelectArrayWithCheckbox ' . $htmlname . 
' --> 
 8995        <dl class="dropdown"> 
 8997            <a href="#' . $htmlname . 
'"> 
 9000            <input type="hidden" class="' . $htmlname . 
'" name="' . $htmlname . 
'" value="' . $listcheckedstring . 
'"> 
 9002            <dd class="dropdowndd"> 
 9003                <div class="multiselectcheckbox'.$htmlname.
'"> 
 9004                    <ul class="'.$htmlname.($pos == 
'1' ? 
'left' : 
'').
'"> 
 9005                    <li><input class="inputsearch_dropdownselectedfields width90p minwidth200imp" style="width:90%;" type="text" placeholder="'.$langs->trans(
'Search').
'"></li> 
 9006                    '.$listoffieldsforselection.
' 
 9012        <script nonce="' . 
getNonce() . 
'" type="text/javascript"> 
 9013          jQuery(document).ready(function () { 
 9014              $(\'.multiselectcheckbox' . $htmlname . 
' input[type="checkbox"]\').on(\'click\', function () { 
 9015                  console.log("A new field was added/removed, we edit field input[name=formfilteraction]"); 
 9017                  $("input:hidden[name=formfilteraction]").val(\'listafterchangingselectedfields\');  // Update field so we know we changed something on selected fields after POST 
 9019                  var title = $(this).val() + ","; 
 9020                  if ($(this).is(\':checked\')) { 
 9021                      $(\'.' . $htmlname . 
'\').val(title + $(\
'.' . $htmlname . 
'\').val());
 
 9024                      $(\
'.' . $htmlname . 
'\').val( $(\
'.' . $htmlname . 
'\').val().replace(title, \
'\') )
 
 9029              $(
"input.inputsearch_dropdownselectedfields").on(
"keyup", 
function() {
 
 9030          var value = $(
this).val().toLowerCase();
 
 9031          $(\
'.multiselectcheckbox'.$htmlname.
' li > label\').filter(function() { 
 9032            $(this).parent().toggle($(this).text().toLowerCase().indexOf(value) > -1) 
 
 9055    include_once DOL_DOCUMENT_ROOT . 
'/categories/class/categorie.class.php';
 
 9058    $categories = $cat->containing($id, $type);
 
 9060    if ($rendermode == 1) {
 
 9062      foreach ($categories as $c) {
 
 9063        $ways = $c->print_all_ways(
' >> ', ($nolink ? 
'none' : 
''), 0, 1); 
 
 9064        foreach ($ways as $way) {
 
 9065          $toprint[] = 
'<li class="select2-search-choice-dolibarr noborderoncategories"' . ($c->color ? 
' style="background: #' . $c->color . 
';"' : 
' style="background: #bbb"') . 
'>' . $way . 
'</li>';
 
 9068      return '<div class="select2-container-multi-dolibarr"><ul class="select2-choices-dolibarr">' . implode(
' ', $toprint) . 
'</ul></div>';
 
 9071    if ($rendermode == 0) {
 
 9072      $arrayselected = array();
 
 9074      foreach ($categories as $c) {
 
 9075        $arrayselected[] = $c->id;
 
 9078      return $this->
multiselectarray(
'categories', $cate_arbo, $arrayselected, 
'', 0, 
'', 0, 
'100%', 
'disabled', 
'category');
 
 9081    return 'ErrorBadValueForParameterRenderMode'; 
 
 
 9093  public function showLinkedObjectBlock($object, $morehtmlright = 
'', $compatibleImportElementsList = array(), $title = 
'RelatedObjects')
 
 9095    global $conf, $langs, $hookmanager;
 
 9096    global $bc, $action;
 
 9098    $object->fetchObjectLinked();
 
 9101    $hookmanager->initHooks(array(
'commonobject'));
 
 9102    $parameters = array(
 
 9103      'morehtmlright' => $morehtmlright,
 
 9104      'compatibleImportElementsList' => &$compatibleImportElementsList,
 
 9106    $reshook = $hookmanager->executeHooks(
'showLinkedObjectBlock', $parameters, $object, $action); 
 
 9108    $nbofdifferenttypes = count($object->linkedObjects);
 
 9110    if (empty($reshook)) {
 
 9111      print 
'<!-- showLinkedObjectBlock -->';
 
 9112      print 
load_fiche_titre($langs->trans($title), $morehtmlright, 
'', 0, 0, 
'showlinkedobjectblock');
 
 9115      print 
'<div class="div-table-responsive-no-min">';
 
 9116      print 
'<table class="noborder allwidth" data-block="showLinkedObject" data-element="' . $object->element . 
'"  data-elementid="' . $object->id . 
'"   >';
 
 9118      print 
'<tr class="liste_titre">';
 
 9119      print 
'<td>' . $langs->trans(
"Type") . 
'</td>';
 
 9120      print 
'<td>' . $langs->trans(
"Ref") . 
'</td>';
 
 9121      print 
'<td class="center"></td>';
 
 9122      print 
'<td class="center">' . $langs->trans(
"Date") . 
'</td>';
 
 9123      print 
'<td class="right">' . $langs->trans(
"AmountHTShort") . 
'</td>';
 
 9124      print 
'<td class="right">' . $langs->trans(
"Status") . 
'</td>';
 
 9128      $nboftypesoutput = 0;
 
 9130      foreach ($object->linkedObjects as $objecttype => $objects) {
 
 9131        $tplpath = $element = $subelement = $objecttype;
 
 9134        $showImportButton = 
false;
 
 9135        if (!empty($compatibleImportElementsList) && in_array($element, $compatibleImportElementsList)) {
 
 9136          $showImportButton = 
true;
 
 9140        if ($objecttype != 
'supplier_proposal' && preg_match(
'/^([^_]+)_([^_]+)/i', $objecttype, $regs)) {
 
 9141          $element = $regs[1];
 
 9142          $subelement = $regs[2];
 
 9143          $tplpath = $element . 
'/' . $subelement;
 
 9145        $tplname = 
'linkedobjectblock';
 
 9148        if ($objecttype == 
'facture') {
 
 9149          $tplpath = 
'compta/' . $element;
 
 9150          if (!isModEnabled(
'facture')) {
 
 9153        } elseif ($objecttype == 
'facturerec') {
 
 9154          $tplpath = 
'compta/facture';
 
 9155          $tplname = 
'linkedobjectblockForRec';
 
 9156          if (!isModEnabled(
'facture')) {
 
 9159        } elseif ($objecttype == 
'propal') {
 
 9160          $tplpath = 
'comm/' . $element;
 
 9161          if (!isModEnabled(
'propal')) {
 
 9164        } elseif ($objecttype == 
'supplier_proposal') {
 
 9165          if (!isModEnabled(
'supplier_proposal')) {
 
 9168        } elseif ($objecttype == 
'shipping' || $objecttype == 
'shipment' || $objecttype == 
'expedition') {
 
 9169          $tplpath = 
'expedition';
 
 9170          if (!isModEnabled(
'expedition')) {
 
 9173        } elseif ($objecttype == 
'reception') {
 
 9174          $tplpath = 
'reception';
 
 9175          if (!isModEnabled(
'reception')) {
 
 9178        } elseif ($objecttype == 
'delivery') {
 
 9179          $tplpath = 
'delivery';
 
 9180          if (!isModEnabled(
'expedition')) {
 
 9183        } elseif ($objecttype == 
'ficheinter') {
 
 9184          $tplpath = 
'fichinter';
 
 9185          if (!isModEnabled(
'ficheinter')) {
 
 9188        } elseif ($objecttype == 
'invoice_supplier') {
 
 9189          $tplpath = 
'fourn/facture';
 
 9190        } elseif ($objecttype == 
'order_supplier') {
 
 9191          $tplpath = 
'fourn/commande';
 
 9192        } elseif ($objecttype == 
'expensereport') {
 
 9193          $tplpath = 
'expensereport';
 
 9194        } elseif ($objecttype == 
'subscription') {
 
 9195          $tplpath = 
'adherents';
 
 9196        } elseif ($objecttype == 
'conferenceorbooth') {
 
 9197          $tplpath = 
'eventorganization';
 
 9198        } elseif ($objecttype == 
'conferenceorboothattendee') {
 
 9199          $tplpath = 
'eventorganization';
 
 9200        } elseif ($objecttype == 
'mo') {
 
 9202          if (!isModEnabled(
'mrp')) {
 
 9207        global $linkedObjectBlock;
 
 9208        $linkedObjectBlock = $objects;
 
 9211        $dirtpls = array_merge($conf->modules_parts[
'tpl'], array(
'/' . $tplpath . 
'/tpl'));
 
 9212        foreach ($dirtpls as $reldir) {
 
 9213          if ($nboftypesoutput == ($nbofdifferenttypes - 1)) {    
 
 9214            global $noMoreLinkedObjectBlockAfter;
 
 9215            $noMoreLinkedObjectBlockAfter = 1;
 
 9218          $res = @include 
dol_buildpath($reldir . 
'/' . $tplname . 
'.tpl.php');
 
 9226      if (!$nboftypesoutput) {
 
 9227        print 
'<tr><td class="impair" colspan="7"><span class="opacitymedium">' . $langs->trans(
"None") . 
'</span></td></tr>';
 
 9232      if (!empty($compatibleImportElementsList)) {
 
 9233        $res = @include 
dol_buildpath(
'core/tpl/objectlinked_lineimport.tpl.php');
 
 9239    return $nbofdifferenttypes;
 
 
 9252    global $conf, $langs, $hookmanager;
 
 9256    $linktoelemlist = 
'';
 
 9257    $listofidcompanytoscan = 
'';
 
 9259    if (!is_object($object->thirdparty)) {
 
 9260      $object->fetch_thirdparty();
 
 9263    $possiblelinks = array();
 
 9264    if (is_object($object->thirdparty) && !empty($object->thirdparty->id) && $object->thirdparty->id > 0) {
 
 9265      $listofidcompanytoscan = $object->thirdparty->id;
 
 9266      if (($object->thirdparty->parent > 0) && 
getDolGlobalString(
'THIRDPARTY_INCLUDE_PARENT_IN_LINKTO')) {
 
 9267        $listofidcompanytoscan .= 
',' . $object->thirdparty->parent;
 
 9269      if (($object->fk_project > 0) && 
getDolGlobalString(
'THIRDPARTY_INCLUDE_PROJECT_THIRDPARY_IN_LINKTO')) {
 
 9270        include_once DOL_DOCUMENT_ROOT . 
'/projet/class/project.class.php';
 
 9271        $tmpproject = 
new Project($this->db);
 
 9272        $tmpproject->fetch($object->fk_project);
 
 9273        if ($tmpproject->socid > 0 && ($tmpproject->socid != $object->thirdparty->id)) {
 
 9274          $listofidcompanytoscan .= 
',' . $tmpproject->socid;
 
 9279      $possiblelinks = array(
 
 9281          'enabled' => isModEnabled(
'propal'),
 
 9283          'label' => 
'LinkToProposal',
 
 9284          'sql' => 
"SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref, t.ref_client, t.total_ht FROM " . $this->db->prefix() . 
"societe as s, " . $this->db->prefix() . 
"propal as t WHERE t.fk_soc = s.rowid AND t.fk_soc IN (" . $this->db->sanitize($listofidcompanytoscan) . 
') AND t.entity IN (' . 
getEntity(
'propal') . 
')'),
 
 9285        'shipping' => array(
 
 9286          'enabled' => isModEnabled(
'expedition'),
 
 9288          'label' => 
'LinkToExpedition',
 
 9289          'sql' => 
"SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref FROM " . $this->db->prefix() . 
"societe as s, " . $this->db->prefix() . 
"expedition as t WHERE t.fk_soc = s.rowid AND t.fk_soc IN (" . $this->db->sanitize($listofidcompanytoscan) . 
') AND t.entity IN (' . 
getEntity(
'shipping') . 
')'),
 
 9291          'enabled' => isModEnabled(
'commande'),
 
 9293          'label' => 
'LinkToOrder',
 
 9294          'sql' => 
"SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref, t.ref_client, t.total_ht FROM " . $this->db->prefix() . 
"societe as s, " . $this->db->prefix() . 
"commande as t WHERE t.fk_soc = s.rowid AND t.fk_soc IN (" . $this->db->sanitize($listofidcompanytoscan) . 
') AND t.entity IN (' . 
getEntity(
'commande') . 
')'),
 
 9296          'enabled' => isModEnabled(
'facture'),
 
 9298          'label' => 
'LinkToInvoice',
 
 9299          'sql' => 
"SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref, t.ref_client, t.total_ht FROM " . $this->db->prefix() . 
"societe as s, " . $this->db->prefix() . 
"facture as t WHERE t.fk_soc = s.rowid AND t.fk_soc IN (" . $this->db->sanitize($listofidcompanytoscan) . 
') AND t.entity IN (' . 
getEntity(
'invoice') . 
')'),
 
 9300        'invoice_template' => array(
 
 9301          'enabled' => isModEnabled(
'facture'),
 
 9303          'label' => 
'LinkToTemplateInvoice',
 
 9304          'sql' => 
"SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.titre as ref, t.total_ht FROM " . $this->db->prefix() . 
"societe as s, " . $this->db->prefix() . 
"facture_rec as t WHERE t.fk_soc = s.rowid AND t.fk_soc IN (" . $this->db->sanitize($listofidcompanytoscan) . 
') AND t.entity IN (' . 
getEntity(
'invoice') . 
')'),
 
 9306          'enabled' => isModEnabled(
'contrat'),
 
 9308          'label' => 
'LinkToContract',
 
 9309          '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, SUM(td.total_ht) as total_ht 
 9310              FROM " . $this->db->prefix() . 
"societe as s, " . $this->db->prefix() . 
"contrat as t, " . $this->db->prefix() . 
"contratdet as td WHERE t.fk_soc = s.rowid AND td.fk_contrat = t.rowid AND t.fk_soc IN (" . $this->db->sanitize($listofidcompanytoscan) . 
') AND t.entity IN (' . 
getEntity(
'contract') . 
') GROUP BY s.rowid, s.nom, s.client, t.rowid, t.ref, t.ref_customer, t.ref_supplier' 
 9312        'fichinter' => array(
 
 9313          'enabled' => isModEnabled(
'ficheinter'),
 
 9315          'label' => 
'LinkToIntervention',
 
 9316          'sql' => 
"SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref FROM " . $this->db->prefix() . 
"societe as s, " . $this->db->prefix() . 
"fichinter as t WHERE t.fk_soc = s.rowid AND t.fk_soc IN (" . $this->db->sanitize($listofidcompanytoscan) . 
') AND t.entity IN (' . 
getEntity(
'intervention') . 
')'),
 
 9317        'supplier_proposal' => array(
 
 9318          'enabled' => isModEnabled(
'supplier_proposal'),
 
 9320          'label' => 
'LinkToSupplierProposal',
 
 9321          'sql' => 
"SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref, '' as ref_supplier, t.total_ht FROM " . $this->db->prefix() . 
"societe as s, " . $this->db->prefix() . 
"supplier_proposal as t WHERE t.fk_soc = s.rowid AND t.fk_soc IN (" . $this->db->sanitize($listofidcompanytoscan) . 
') AND t.entity IN (' . 
getEntity(
'supplier_proposal') . 
')'),
 
 9322        'order_supplier' => array(
 
 9323          'enabled' => isModEnabled(
"supplier_order"),
 
 9325          'label' => 
'LinkToSupplierOrder',
 
 9326          'sql' => 
"SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref, t.ref_supplier, t.total_ht FROM " . $this->db->prefix() . 
"societe as s, " . $this->db->prefix() . 
"commande_fournisseur as t WHERE t.fk_soc = s.rowid AND t.fk_soc IN (" . $this->db->sanitize($listofidcompanytoscan) . 
') AND t.entity IN (' . 
getEntity(
'commande_fournisseur') . 
')'),
 
 9327        'invoice_supplier' => array(
 
 9328          'enabled' => isModEnabled(
"supplier_invoice"),
 
 9329          'perms' => 1, 
'label' => 
'LinkToSupplierInvoice',
 
 9330          'sql' => 
"SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref, t.ref_supplier, t.total_ht FROM " . $this->db->prefix() . 
"societe as s, " . $this->db->prefix() . 
"facture_fourn as t WHERE t.fk_soc = s.rowid AND t.fk_soc IN (" . $this->db->sanitize($listofidcompanytoscan) . 
') AND t.entity IN (' . 
getEntity(
'facture_fourn') . 
')'),
 
 9332          'enabled' => isModEnabled(
'ticket'),
 
 9334          'label' => 
'LinkToTicket',
 
 9335          'sql' => 
"SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref, t.track_id, '0' as total_ht FROM " . $this->db->prefix() . 
"societe as s, " . $this->db->prefix() . 
"ticket as t WHERE t.fk_soc = s.rowid AND t.fk_soc IN (" . $this->db->sanitize($listofidcompanytoscan) . 
') AND t.entity IN (' . 
getEntity(
'ticket') . 
')'),
 
 9337          'enabled' => isModEnabled(
'mrp'),
 
 9339          'label' => 
'LinkToMo',
 
 9340          'sql' => 
"SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref, t.rowid, '0' as total_ht FROM " . $this->db->prefix() . 
"societe as s INNER JOIN " . $this->db->prefix() . 
"mrp_mo as t ON t.fk_soc = s.rowid  WHERE  t.fk_soc IN (" . $this->db->sanitize($listofidcompanytoscan) . 
') AND t.entity IN (' . 
getEntity(
'mo') . 
')')
 
 9344    if ($object->table_element == 
'commande_fournisseur') {
 
 9345      $possiblelinks[
'mo'][
'sql'] = 
"SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref, t.rowid, '0' as total_ht FROM ".$this->db->prefix().
"societe as s INNER JOIN ".$this->db->prefix().
'mrp_mo as t ON t.fk_soc = s.rowid  WHERE t.entity IN ('.
getEntity(
'mo').
')';
 
 9346    } elseif ($object->table_element == 
'mrp_mo') {
 
 9347      $possiblelinks[
'order_supplier'][
'sql'] = 
"SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref, t.ref_supplier, t.total_ht FROM ".$this->db->prefix().
"societe as s, ".$this->db->prefix().
'commande_fournisseur as t WHERE t.fk_soc = s.rowid AND t.entity IN ('.
getEntity(
'commande_fournisseur').
')';
 
 9350    if (!empty($listofidcompanytoscan)) {  
 
 9352      $hookmanager->initHooks(array(
'commonobject'));
 
 9353      $parameters = array(
'listofidcompanytoscan' => $listofidcompanytoscan, 
'possiblelinks' => $possiblelinks);
 
 9354      $reshook = $hookmanager->executeHooks(
'showLinkToObjectBlock', $parameters, $object, $action); 
 
 9357    if (empty($reshook)) {
 
 9358      if (is_array($hookmanager->resArray) && count($hookmanager->resArray)) {
 
 9359        $possiblelinks = array_merge($possiblelinks, $hookmanager->resArray);
 
 9361    } elseif ($reshook > 0) {
 
 9362      if (is_array($hookmanager->resArray) && count($hookmanager->resArray)) {
 
 9363        $possiblelinks = $hookmanager->resArray;
 
 9367    foreach ($possiblelinks as $key => $possiblelink) {
 
 9370      if (empty($possiblelink[
'enabled'])) {
 
 9374      if (!empty($possiblelink[
'perms']) && (empty($restrictlinksto) || in_array($key, $restrictlinksto)) && (empty($excludelinksto) || !in_array($key, $excludelinksto))) {
 
 9375        print 
'<div id="' . $key . 
'list"' . (empty($conf->use_javascript_ajax) ? 
'' : 
' style="display:none"') . 
'>';
 
 9379          print 
'<!-- form to add a link from anywhere -->'.
"\n";
 
 9380          print 
'<form action="' . $_SERVER[
"PHP_SELF"] . 
'" method="POST" name="formlinkedbyref' . $key . 
'">';
 
 9381          print 
'<input type="hidden" name="id" value="' . $object->id . 
'">';
 
 9382          print 
'<input type="hidden" name="action" value="addlinkbyref">';
 
 9383          print 
'<input type="hidden" name="token" value="' . newToken() . 
'">';
 
 9384          print 
'<input type="hidden" name="addlink" value="' . $key . 
'">';
 
 9385          print 
'<table class="noborder">';
 
 9388          print 
'<td class="center"><input type="text" placeholder="'.dol_escape_htmltag($langs->trans(
"Ref")).
'" name="reftolinkto" value="' . 
dol_escape_htmltag(
GETPOST(
'reftolinkto', 
'alpha')) . 
'"> ';
 
 9389          print 
'<input type="submit" class="button small valignmiddle" value="' . $langs->trans(
'ToLink') . 
'"> ';
 
 9390          print 
'<input type="submit" class="button small" name="cancel" value="' . $langs->trans(
'Cancel') . 
'"></td>';
 
 9396        $sql = $possiblelink[
'sql'];
 
 9398        $resqllist = $this->db->query($sql);
 
 9400          $num = $this->db->num_rows($resqllist);
 
 9404          print 
'<!-- form to add a link from object to same thirdparty -->'.
"\n";
 
 9405          print 
'<form action="' . $_SERVER[
"PHP_SELF"] . 
'" method="POST" name="formlinked' . $key . 
'">';
 
 9406          print 
'<input type="hidden" name="action" value="addlink">';
 
 9407          print 
'<input type="hidden" name="token" value="' . newToken() . 
'">';
 
 9408          print 
'<input type="hidden" name="id" value="' . $object->id . 
'">';
 
 9409          print 
'<input type="hidden" name="addlink" value="' . $key . 
'">';
 
 9410          print 
'<table class="noborder">';
 
 9411          print 
'<tr class="liste_titre">';
 
 9412          print 
'<td class="nowrap"></td>';
 
 9413          print 
'<td class="center">' . $langs->trans(
"Ref") . 
'</td>';
 
 9414          print 
'<td class="left">' . $langs->trans(
"RefCustomer") . 
'</td>';
 
 9415          print 
'<td class="right">' . $langs->trans(
"AmountHTShort") . 
'</td>';
 
 9416          print 
'<td class="left">' . $langs->trans(
"Company") . 
'</td>';
 
 9419            $objp = $this->db->fetch_object($resqllist);
 
 9421            print 
'<tr class="oddeven">';
 
 9422            print 
'<td class="left">';
 
 9423            print 
'<input type="radio" name="idtolinkto" id="' . $key . 
'_' . $objp->rowid . 
'" value="' . $objp->rowid . 
'">';
 
 9425            print 
'<td class="center"><label for="' . $key . 
'_' . $objp->rowid . 
'">' . $objp->ref . 
'</label></td>';
 
 9426            print 
'<td>' . (!empty($objp->ref_client) ? $objp->ref_client : (!empty($objp->ref_supplier) ? $objp->ref_supplier : 
'')) . 
'</td>';
 
 9427            print 
'<td class="right">';
 
 9428            if ($possiblelink[
'label'] == 
'LinkToContract') {
 
 9429              $form = 
new Form($this->db);
 
 9430              print $form->textwithpicto(
'', $langs->trans(
"InformationOnLinkToContract")) . 
' ';
 
 9432            print 
'<span class="amount">' . (isset($objp->total_ht) ? 
price($objp->total_ht) : 
'') . 
'</span>';
 
 9434            print 
'<td>' . $objp->name . 
'</td>';
 
 9439          print 
'<div class="center">';
 
 9441            print 
'<input type="submit" class="button valignmiddle marginleftonly marginrightonly small" value="' . $langs->trans(
'ToLink') . 
'">';
 
 9443          if (empty($conf->use_javascript_ajax)) {
 
 9444            print 
'<input type="submit" class="button button-cancel marginleftonly marginrightonly small" name="cancel" value="' . $langs->trans(
"Cancel") . 
'"></div>';
 
 9446            print 
'<input type="submit" onclick="jQuery(\'#' . $key . 
'list\').toggle(); return false;" class="button button-cancel marginleftonly marginrightonly small" name="cancel" value="' . $langs->trans(
"Cancel") . 
'"></div>';
 
 9449          $this->db->free($resqllist);
 
 9457          $linktoelemlist .= 
'<li><a href="#linkto' . $key . 
'" class="linkto dropdowncloseonclick" rel="' . $key . 
'">' . $langs->trans($possiblelink[
'label']) . 
' (' . $num . 
')</a></li>';
 
 9460          $linktoelemlist .= 
'<li><span class="linktodisabled">' . $langs->trans($possiblelink[
'label']) . 
' (0)</span></li>';
 
 9465    if ($linktoelemlist) {
 
 9467        <dl class="dropdown" id="linktoobjectname"> 
 9469      if (!empty($conf->use_javascript_ajax)) {
 
 9470        $linktoelem .= 
'<dt><a href="#linktoobjectname"><span class="fas fa-link paddingrightonly"></span>' . $langs->trans(
"LinkTo") . 
'...</a></dt>';
 
 9472      $linktoelem .= 
'<dd> 
 9473        <div class="multiselectlinkto"> 
 9474        <ul class="ulselectedfields">' . $linktoelemlist . 
' 
 9483    if (!empty($conf->use_javascript_ajax)) {
 
 9484      print 
'<!-- Add js to show linkto box --> 
 9485        <script nonce="' . 
getNonce() . 
'"> 
 9486        jQuery(document).ready(function() { 
 9487          jQuery(".linkto").click(function() { 
 9488            console.log("We choose to show/hide links for rel="+jQuery(this).attr(\'rel\')+" so #"+jQuery(this).attr(\'rel\')+"list"); 
 9489              jQuery("#"+jQuery(this).attr(\'rel\')+"list").toggle(); 
 
 9513  public function selectyesno($htmlname, $value = 
'', $option = 0, $disabled = 
false, $useempty = 0, $addjscombo = 0, $morecss = 
'', $labelyes = 
'Yes', $labelno = 
'No')
 
 9524    $disabled = ($disabled ? 
' disabled' : 
'');
 
 9526    $resultyesno = 
'<select class="flat width75' . ($morecss ? 
' ' . $morecss : 
'') . 
'" id="' . $htmlname . 
'" name="' . $htmlname . 
'"' . $disabled . 
'>' . 
"\n";
 
 9528      $resultyesno .= 
'<option value="-1"' . (($value < 0) ? 
' selected' : 
'') . 
'> </option>' . 
"\n";
 
 9530    if ((
"$value" == 
'yes') || ($value == 1)) {
 
 9531      $resultyesno .= 
'<option value="' . $yes . 
'" selected>' . $langs->trans($labelyes) . 
'</option>' . 
"\n";
 
 9532      $resultyesno .= 
'<option value="' . $no . 
'">' . $langs->trans($labelno) . 
'</option>' . 
"\n";
 
 9534      $selected = (($useempty && $value != 
'0' && $value != 
'no') ? 
'' : 
' selected');
 
 9535      $resultyesno .= 
'<option value="' . $yes . 
'">' . $langs->trans($labelyes) . 
'</option>' . 
"\n";
 
 9536      $resultyesno .= 
'<option value="' . $no . 
'"' . $selected . 
'>' . $langs->trans($labelno) . 
'</option>' . 
"\n";
 
 9538    $resultyesno .= 
'</select>' . 
"\n";
 
 9541      $resultyesno .= 
ajax_combobox($htmlname, array(), 0, 0, 
'resolve', ($useempty < 0 ? (
string) $useempty : 
'-1'), $morecss);
 
 9544    return $resultyesno;
 
 
 9561    $sql = 
"SELECT rowid, label";
 
 9562    $sql .= 
" FROM " . $this->db->prefix() . 
"export_model";
 
 9563    $sql .= 
" WHERE type = '" . $this->db->escape($type) . 
"'";
 
 9564    $sql .= 
" ORDER BY rowid";
 
 9565    $result = $this->db->query($sql);
 
 9567      print 
'<select class="flat" id="select_' . $htmlname . 
'" name="' . $htmlname . 
'">';
 
 9569        print 
'<option value="-1"> </option>';
 
 9572      $num = $this->db->num_rows($result);
 
 9575        $obj = $this->db->fetch_object($result);
 
 9576        if ($selected == $obj->rowid) {
 
 9577          print 
'<option value="' . $obj->rowid . 
'" selected>';
 
 9579          print 
'<option value="' . $obj->rowid . 
'">';
 
 
 9609  public function showrefnav($object, $paramid, $morehtml = 
'', $shownav = 1, $fieldid = 
'rowid', $fieldref = 
'ref', $morehtmlref = 
'', $moreparam = 
'', $nodbprefix = 0, $morehtmlleft = 
'', $morehtmlstatus = 
'', $morehtmlright = 
'')
 
 9611    global $conf, $langs, $hookmanager, $extralanguages;
 
 9614    if (empty($fieldid)) {
 
 9617    if (empty($fieldref)) {
 
 9623    if (property_exists($object, 
'gender') && !empty($object->gender)) {
 
 9624      $addgendertxt = 
' ';
 
 9625      switch ($object->gender) {
 
 9627          $addgendertxt .= 
'<i class="fas fa-mars"></i>';
 
 9630          $addgendertxt .= 
'<i class="fas fa-venus"></i>';
 
 9633          $addgendertxt .= 
'<i class="fas fa-transgender"></i>';
 
 9639    if (is_object($hookmanager)) {
 
 9640      $parameters = array(
'showrefnav' => 
true);
 
 9641      $reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters, $object); 
 
 9642      $object->next_prev_filter .= $hookmanager->resPrint;
 
 9644    $previous_ref = $next_ref = 
'';
 
 9647      $object->load_previous_next_ref((isset($object->next_prev_filter) ? $object->next_prev_filter : 
''), $fieldid, $nodbprefix);
 
 9649      $navurl = $_SERVER[
"PHP_SELF"];
 
 9651      if ($paramid == 
'project_ref') {
 
 9652        if (preg_match(
'/\/tasks\/(task|contact|note|document)\.php/', $navurl)) {     
 
 9653          $navurl = preg_replace(
'/\/tasks\/(task|contact|time|note|document)\.php/', 
'/tasks.php', $navurl);
 
 9660      $stringforfirstkey = $langs->trans(
"KeyboardShortcut");
 
 9661      if ($conf->browser->name == 
'chrome') {
 
 9662        $stringforfirstkey .= 
' ALT +';
 
 9663      } elseif ($conf->browser->name == 
'firefox') {
 
 9664        $stringforfirstkey .= 
' ALT + SHIFT +';
 
 9666        $stringforfirstkey .= 
' CTL +';
 
 9669      $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>';
 
 9670      $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>';
 
 9674    $ret .= 
'<!-- Start banner content --><div style="vertical-align: middle">';
 
 9677    if ($morehtmlright) {
 
 9678      $ret .= 
'<div class="inline-block floatleft">' . $morehtmlright . 
'</div>';
 
 9681    if ($previous_ref || $next_ref || $morehtml) {
 
 9682      $ret .= 
'<div class="pagination paginationref"><ul class="right">';
 
 9685      $ret .= 
'<li class="noborder litext' . (($shownav && $previous_ref && $next_ref) ? 
' clearbothonsmartphone' : 
'') . 
'">' . $morehtml . 
'</li>';
 
 9687    if ($shownav && ($previous_ref || $next_ref)) {
 
 9688      $ret .= 
'<li class="pagination">' . $previous_ref . 
'</li>';
 
 9689      $ret .= 
'<li class="pagination">' . $next_ref . 
'</li>';
 
 9691    if ($previous_ref || $next_ref || $morehtml) {
 
 9692      $ret .= 
'</ul></div>';
 
 9696    $parameters = array(
'morehtmlstatus' => $morehtmlstatus);
 
 9697    $reshook = $hookmanager->executeHooks(
'moreHtmlStatus', $parameters, $object); 
 
 9698    if (empty($reshook)) {
 
 9699      $morehtmlstatus .= $hookmanager->resPrint;
 
 9701      $morehtmlstatus = $hookmanager->resPrint;
 
 9703    if ($morehtmlstatus) {
 
 9704      $ret .= 
'<div class="statusref">' . $morehtmlstatus . 
'</div>';
 
 9707    $parameters = array();
 
 9708    $reshook = $hookmanager->executeHooks(
'moreHtmlRef', $parameters, $object); 
 
 9709    if (empty($reshook)) {
 
 9710      $morehtmlref .= $hookmanager->resPrint;
 
 9711    } elseif ($reshook > 0) {
 
 9712      $morehtmlref = $hookmanager->resPrint;
 
 9716    if ($morehtmlleft) {
 
 9717      if ($conf->browser->layout == 
'phone') {
 
 9718        $ret .= 
'<!-- morehtmlleft --><div class="floatleft">' . $morehtmlleft . 
'</div>';
 
 9720        $ret .= 
'<!-- morehtmlleft --><div class="inline-block floatleft">' . $morehtmlleft . 
'</div>';
 
 9725    $ret .= 
'<div class="inline-block floatleft valignmiddle maxwidth750 marginbottomonly refid' . (($shownav && ($previous_ref || $next_ref)) ? 
' refidpadding' : 
'') . 
'">';
 
 9728    if ($object->element == 
'societe') {
 
 9732      $arrayoflangcode = array();
 
 9734        $arrayoflangcode[] = $conf->global->PDF_USE_ALSO_LANGUAGE_CODE;
 
 9737      if (is_array($arrayoflangcode) && count($arrayoflangcode)) {
 
 9738        if (!is_object($extralanguages)) {
 
 9739          include_once DOL_DOCUMENT_ROOT . 
'/core/class/extralanguages.class.php';
 
 9742        $extralanguages->fetch_name_extralanguages(
'societe');
 
 9744        if (!empty($extralanguages->attributes[
'societe'][
'name'])) {
 
 9745          $object->fetchValuesForExtraLanguages();
 
 9749          foreach ($arrayoflangcode as $extralangcode) {
 
 9751            if ($object->array_languages[
'name'][$extralangcode]) {
 
 9752              $htmltext .= $object->array_languages[
'name'][$extralangcode];
 
 9754              $htmltext .= 
'<span class="opacitymedium">' . $langs->trans(
"SwitchInEditModeToAddTranslation") . 
'</span>';
 
 9757          $ret .= 
'<!-- Show translations of name -->' . 
"\n";
 
 9758          $ret .= $this->
textwithpicto(
'', $htmltext, -1, 
'language', 
'opacitymedium paddingleft');
 
 9761    } elseif ($object->element == 
'member') {
 
 9762      $ret .= $object->ref . 
'<br>';
 
 9763      $fullname = $object->getFullName($langs);
 
 9764      if ($object->morphy == 
'mor' && $object->societe) {
 
 9765        $ret .= 
dol_htmlentities($object->societe) . ((!empty($fullname) && $object->societe != $fullname) ? 
' (' . 
dol_htmlentities($fullname) . $addgendertxt . 
')' : 
'');
 
 9767        $ret .= 
dol_htmlentities($fullname) . $addgendertxt . ((!empty($object->societe) && $object->societe != $fullname) ? 
' (' . 
dol_htmlentities($object->societe) . 
')' : 
'');
 
 9769    } elseif (in_array($object->element, array(
'contact', 
'user'))) {
 
 9771    } elseif ($object->element == 
'usergroup') {
 
 9773    } elseif (in_array($object->element, array(
'action', 
'agenda'))) {
 
 9774      $ret .= $object->ref . 
'<br>' . $object->label;
 
 9775    } elseif (in_array($object->element, array(
'adherent_type'))) {
 
 9776      $ret .= $object->label;
 
 9777    } elseif ($object->element == 
'ecm_directories') {
 
 9779    } elseif ($fieldref != 
'none') {
 
 9780      $ret .= 
dol_htmlentities(!empty($object->$fieldref) ? $object->$fieldref : 
"");
 
 9784      if (substr($morehtmlref, 0, 4) != 
'<div') {
 
 9788      $ret .= $morehtmlref;
 
 9793    $ret .= 
'</div><!-- End banner content -->';
 
 
 9812    if (empty($object->barcode)) {
 
 9817    if (empty($object->barcode_type_code) || empty($object->barcode_type_coder)) {
 
 9818      $result = $object->fetch_barcode();
 
 9821        return '<!-- ErrorFetchBarcode -->';
 
 9826    $url = DOL_URL_ROOT . 
'/viewimage.php?modulepart=barcode&generator=' . urlencode($object->barcode_type_coder) . 
'&code=' . urlencode($object->barcode) . 
'&encoding=' . urlencode($object->barcode_type_code);
 
 9827    $out = 
'<!-- url barcode = ' . $url . 
' -->';
 
 9828    $out .= 
'<img src="' . $url . 
'"' . ($morecss ? 
' class="' . $morecss . 
'"' : 
'') . 
'>';
 
 
 9849  public static function showphoto($modulepart, $object, $width = 100, $height = 0, $caneditfield = 0, $cssclass = 
'photowithmargin', $imagesize = 
'', $addlinktofullsize = 1, $cache = 0, $forcecapture = 
'', $noexternsourceoverwrite = 0)
 
 9851    global $conf, $langs;
 
 9853    $entity = (empty($object->entity) ? $conf->entity : $object->entity);
 
 9854    $id = (empty($object->id) ? $object->rowid : $object->id);
 
 9863    if ($modulepart == 
'societe') {
 
 9864      $dir = $conf->societe->multidir_output[$entity];
 
 9865      if (!empty($object->logo)) {
 
 9867          if ((
string) $imagesize == 
'mini') {
 
 9869          } elseif ((
string) $imagesize == 
'small') {
 
 9872            $file = 
get_exdir(0, 0, 0, 0, $object, 
'thirdparty') . 
'logos/' . $object->logo;
 
 9874          $originalfile = 
get_exdir(0, 0, 0, 0, $object, 
'thirdparty') . 
'logos/' . $object->logo;
 
 9877      $email = $object->email;
 
 9878    } elseif ($modulepart == 
'contact') {
 
 9879      $dir = $conf->societe->multidir_output[$entity] . 
'/contact';
 
 9880      if (!empty($object->photo)) {
 
 9882          if ((
string) $imagesize == 
'mini') {
 
 9884          } elseif ((
string) $imagesize == 
'small') {
 
 9887            $file = 
get_exdir(0, 0, 0, 0, $object, 
'contact') . 
'photos/' . $object->photo;
 
 9889          $originalfile = 
get_exdir(0, 0, 0, 0, $object, 
'contact') . 
'photos/' . $object->photo;
 
 9892      $email = $object->email;
 
 9894    } elseif ($modulepart == 
'userphoto') {
 
 9895      $dir = $conf->user->dir_output;
 
 9896      if (!empty($object->photo)) {
 
 9898          if ((
string) $imagesize == 
'mini') {
 
 9900          } elseif ((
string) $imagesize == 
'small') {
 
 9903            $file = 
get_exdir(0, 0, 0, 0, $object, 
'user') . 
'photos/' . $object->photo;
 
 9905          $originalfile = 
get_exdir(0, 0, 0, 0, $object, 
'user') . 
'photos/' . $object->photo;
 
 9909        $altfile = $object->id . 
".jpg"; 
 
 9911      $email = $object->email;
 
 9913    } elseif ($modulepart == 
'memberphoto') {
 
 9914      $dir = $conf->adherent->dir_output;
 
 9915      if (!empty($object->photo)) {
 
 9917          if ((
string) $imagesize == 
'mini') {
 
 9919          } elseif ((
string) $imagesize == 
'small') {
 
 9922            $file = 
get_exdir(0, 0, 0, 0, $object, 
'member') . 
'photos/' . $object->photo;
 
 9924          $originalfile = 
get_exdir(0, 0, 0, 0, $object, 
'member') . 
'photos/' . $object->photo;
 
 9928        $altfile = $object->id . 
".jpg"; 
 
 9930      $email = $object->email;
 
 9934      $dir = $conf->$modulepart->dir_output;
 
 9935      if (!empty($object->photo)) {
 
 9937          if ((
string) $imagesize == 
'mini') {
 
 9939          } elseif ((
string) $imagesize == 
'small') {
 
 9942            $file = 
get_exdir($id, 2, 0, 0, $object, $modulepart) . 
'photos/' . $object->photo;
 
 9944          $originalfile = 
get_exdir($id, 2, 0, 0, $object, $modulepart) . 
'photos/' . $object->photo;
 
 9948        $altfile = $object->id . 
".jpg"; 
 
 9950      $email = $object->email;
 
 9953    if ($forcecapture) {
 
 9954      $capture = $forcecapture;
 
 9958      if ($file && file_exists($dir . 
"/" . $file)) {
 
 9959        if ($addlinktofullsize) {
 
 9962            $ret .= 
'<a href="' . $urladvanced . 
'">';
 
 9964            $ret .= 
'<a href="' . DOL_URL_ROOT . 
'/viewimage.php?modulepart=' . $modulepart . 
'&entity=' . $entity . 
'&file=' . urlencode($originalfile) . 
'&cache=' . $cache . 
'">';
 
 9967        $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 . 
'">';
 
 9968        if ($addlinktofullsize) {
 
 9971      } elseif ($altfile && file_exists($dir . 
"/" . $altfile)) {
 
 9972        if ($addlinktofullsize) {
 
 9975            $ret .= 
'<a href="' . $urladvanced . 
'">';
 
 9977            $ret .= 
'<a href="' . DOL_URL_ROOT . 
'/viewimage.php?modulepart=' . $modulepart . 
'&entity=' . $entity . 
'&file=' . urlencode($originalfile) . 
'&cache=' . $cache . 
'">';
 
 9980        $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 . 
'">';
 
 9981        if ($addlinktofullsize) {
 
 9985        $nophoto = 
'/public/theme/common/nophoto.png';
 
 9986        $defaultimg = 
'identicon';        
 
 9987        if (in_array($modulepart, array(
'societe', 
'userphoto', 
'contact', 
'memberphoto'))) {    
 
 9988          if ($modulepart == 
'societe' || ($modulepart == 
'memberphoto' && !empty($object->morphy) && strpos($object->morphy, 
'mor')) !== 
false) {
 
 9989            $nophoto = 
'company';
 
 9991            $nophoto = 
'/public/theme/common/user_anonymous.png';
 
 9992            if (!empty($object->gender) && $object->gender == 
'man') {
 
 9993              $nophoto = 
'/public/theme/common/user_man.png';
 
 9995            if (!empty($object->gender) && $object->gender == 
'woman') {
 
 9996              $nophoto = 
'/public/theme/common/user_woman.png';
 
10001        if (isModEnabled(
'gravatar') && $email && empty($noexternsourceoverwrite)) {
 
10003          $ret .= 
'<!-- Put link to gravatar -->';
 
10004          $ret .= 
'<img class="photo' . $modulepart . ($cssclass ? 
' ' . $cssclass : 
'') . 
'" alt="" title="' . $email . 
' Gravatar avatar" ' . ($width ? 
' width="' . $width . 
'"' : 
'') . ($height ? 
' height="' . $height . 
'"' : 
'') . 
' src="https://www.gravatar.com/avatar/' . 
dol_hash(strtolower(trim($email)), 
'sha256', 1) . 
'?s=' . $width . 
'&d=' . $defaultimg . 
'">'; 
 
10006          if ($nophoto == 
'company') {
 
10007            $ret .= 
'<div class="divforspanimg photo' . $modulepart . ($cssclass ? 
' ' . $cssclass : 
'') . 
'" alt="" ' . ($width ? 
' width="' . $width . 
'"' : 
'') . ($height ? 
' height="' . $height . 
'"' : 
'') . 
'>' . 
img_picto(
'', 
'company') . 
'</div>';
 
10008            $ret .= 
'<div class="difforspanimgright"></div>';
 
10010            $ret .= 
'<img class="photo' . $modulepart . ($cssclass ? 
' ' . $cssclass : 
'') . 
'" alt="" ' . ($width ? 
' width="' . $width . 
'"' : 
'') . ($height ? 
' height="' . $height . 
'"' : 
'') . 
' src="' . DOL_URL_ROOT . $nophoto . 
'">';
 
10015      if ($caneditfield) {
 
10016        if ($object->photo) {
 
10019        $ret .= 
'<table class="nobordernopadding centpercent">';
 
10020        if ($object->photo) {
 
10021          $ret .= 
'<tr><td><input type="checkbox" class="flat photodelete" name="deletephoto" id="photodelete"> <label for="photodelete">' . $langs->trans(
"Delete") . 
'</label><br><br></td></tr>';
 
10023        $ret .= 
'<tr><td class="tdoverflow">';
 
10025        $maxmin = $maxfilesizearray[
'maxmin'];
 
10027          $ret .= 
'<input type="hidden" name="MAX_FILE_SIZE" value="' . ($maxmin * 1024) . 
'">';    
 
10029        $ret .= 
'<input type="file" class="flat maxwidth200onsmartphone" name="photo" id="photoinput" accept="image/*"' . ($capture ? 
' capture="' . $capture . 
'"' : 
'') . 
'>';
 
10030        $ret .= 
'</td></tr>';
 
10031        $ret .= 
'</table>';
 
 
10056  public function select_dolgroups($selected = 
'', $htmlname = 
'groupid', $show_empty = 0, $exclude = 
'', $disabled = 0, $include = 
'', $enableonly = array(), $force_entity = 
'0', $multiple = 
false, $morecss = 
'')
 
10059    global $conf, $user, $langs;
 
10062    $excludeGroups = 
null;
 
10063    if (is_array($exclude)) {
 
10064      $excludeGroups = implode(
",", $exclude);
 
10067    $includeGroups = 
null;
 
10068    if (is_array($include)) {
 
10069      $includeGroups = implode(
",", $include);
 
10072    if (!is_array($selected)) {
 
10073      $selected = array($selected);
 
10079    $sql = 
"SELECT ug.rowid, ug.nom as name";
 
10080    if (isModEnabled(
'multicompany') && $conf->entity == 1 && $user->admin && !$user->entity) {
 
10081      $sql .= 
", e.label";
 
10083    $sql .= 
" FROM " . $this->db->prefix() . 
"usergroup as ug ";
 
10084    if (isModEnabled(
'multicompany') && $conf->entity == 1 && $user->admin && !$user->entity) {
 
10085      $sql .= 
" LEFT JOIN " . $this->db->prefix() . 
"entity as e ON e.rowid=ug.entity";
 
10086      if ($force_entity) {
 
10087        $sql .= 
" WHERE ug.entity IN (0, " . $force_entity . 
")";
 
10089        $sql .= 
" WHERE ug.entity IS NOT NULL";
 
10092      $sql .= 
" WHERE ug.entity IN (0, " . $conf->entity . 
")";
 
10094    if (is_array($exclude) && $excludeGroups) {
 
10095      $sql .= 
" AND ug.rowid NOT IN (" . $this->db->sanitize($excludeGroups) . 
")";
 
10097    if (is_array($include) && $includeGroups) {
 
10098      $sql .= 
" AND ug.rowid IN (" . $this->db->sanitize($includeGroups) . 
")";
 
10100    $sql .= 
" ORDER BY ug.nom ASC";
 
10102    dol_syslog(get_class($this) . 
"::select_dolgroups", LOG_DEBUG);
 
10103    $resql = $this->db->query($sql);
 
10106      include_once DOL_DOCUMENT_ROOT . 
'/core/lib/ajax.lib.php';
 
10108      $out .= 
'<select class="flat minwidth200' . ($morecss ? 
' ' . $morecss : 
'') . 
'" id="' . $htmlname . 
'" name="' . $htmlname . ($multiple ? 
'[]' : 
'') . 
'" ' . ($multiple ? 
'multiple' : 
'') . 
' ' . ($disabled ? 
' disabled' : 
'') . 
'>';
 
10110      $num = $this->db->num_rows($resql);
 
10113        if ($show_empty && !$multiple) {
 
10114          $out .= 
'<option value="-1"' . (in_array(-1, $selected) ? 
' selected' : 
'') . 
'> </option>' . 
"\n";
 
10117        while ($i < $num) {
 
10118          $obj = $this->db->fetch_object($resql);
 
10120          if (is_array($enableonly) && count($enableonly) && !in_array($obj->rowid, $enableonly)) {
 
10124          $label = $obj->name;
 
10125          $labelhtml = $obj->name;
 
10126          if (isModEnabled(
'multicompany') && !
getDolGlobalInt(
'MULTICOMPANY_TRANSVERSE_MODE') && $conf->entity == 1) {
 
10127            $label .= 
" (" . $obj->label . 
")";
 
10128            $labelhtml .= 
' <span class="opacitymedium">(' . $obj->label . 
')</span>';
 
10131          $out .= 
'<option value="' . $obj->rowid . 
'"';
 
10132          if ($disableline) {
 
10133            $out .= 
' disabled';
 
10135          if ((isset($selected[0]) && is_object($selected[0]) && $selected[0]->
id == $obj->rowid) || ((!isset($selected[0]) || !is_object($selected[0])) && !empty($selected) && in_array($obj->rowid, $selected))) {
 
10136            $out .= 
' selected';
 
10138          $out .= 
' data-html="'.dol_escape_htmltag($labelhtml).
'"';
 
10141          $out .= 
'</option>';
 
10146          $out .= 
'<option value="-1"' . (in_array(-1, $selected) ? 
' selected' : 
'') . 
'></option>' . 
"\n";
 
10148        $out .= 
'<option value="" disabled>' . $langs->trans(
"NoUserGroupDefined") . 
'</option>';
 
10150      $out .= 
'</select>';
 
 
10169    $out = 
'<div class="nowraponall">';
 
10170    if ($pos == 
'left') {
 
10171      $out .= 
'<button type="submit" class="liste_titre button_search reposition" name="button_search_x" value="x"><span class="fas fa-search"></span></button>';
 
10172      $out .= 
'<button type="submit" class="liste_titre button_removefilter reposition" name="button_removefilter_x" value="x"><span class="fas fa-times"></span></button>';
 
10174      $out .= 
'<button type="submit" class="liste_titre button_search reposition" name="button_search_x" value="x"><span class="fas fa-search"></span></button>';
 
10175      $out .= 
'<button type="submit" class="liste_titre button_removefilter reposition" name="button_removefilter_x" value="x"><span class="fas fa-times"></span></button>';
 
 
10190  public function showCheckAddButtons($cssclass = 
'checkforaction', $calljsfunction = 0, $massactionname = 
"massaction")
 
10196    if (!empty($conf->use_javascript_ajax)) {
 
10197      $out .= 
'<div class="inline-block checkallactions"><input type="checkbox" id="' . $cssclass . 
's" name="' . $cssclass . 
's" class="checkallactions"></div>';
 
10199    $out .= 
'<script nonce="' . 
getNonce() . 
'"> 
10200            $(document).ready(function() { 
10201                $("#' . $cssclass . 
's").click(function() { 
10202                    if($(this).is(\':checked\')){ 
10203                        console.log("We check all ' . $cssclass . 
' and trigger the change method"); 
10204                    $(".' . $cssclass . 
'").prop(\'checked\', true).trigger(\'change\'); 
10208                        console.log("We uncheck all"); 
10209                    $(".' . $cssclass . 
'").prop(\'checked\', false).trigger(\'change\'); 
10211    if ($calljsfunction) {
 
10212      $out .= 
'if (typeof initCheckForSelect == \'function\') { initCheckForSelect(0, "' . $massactionname . 
'", "' . $cssclass . 
'"); } else { console.log("No function initCheckForSelect found. Call won\'t be done."); }';
 
10215                  $(".' . $cssclass . 
'").change(function() { 
10216          $(this).closest("tr").toggleClass("highlight", this.checked); 
 
10236    if ($addcheckuncheckall) {
 
 
10255  public function selectExpenseCategories($selected = 
'', $htmlname = 
'fk_c_exp_tax_cat', $useempty = 0, $excludeid = array(), $target = 
'', $default_selected = 0, $params = array(), $info_admin = 1)
 
10257    global $langs, $user;
 
10260    $sql = 
"SELECT rowid, label FROM " . $this->db->prefix() . 
"c_exp_tax_cat WHERE active = 1";
 
10261    $sql .= 
" AND entity IN (0," . 
getEntity(
'exp_tax_cat') . 
")";
 
10262    if (!empty($excludeid)) {
 
10263      $sql .= 
" AND rowid NOT IN (" . $this->db->sanitize(implode(
',', $excludeid)) . 
")";
 
10265    $sql .= 
" ORDER BY label";
 
10267    $resql = $this->db->query($sql);
 
10269      $out = 
'<select id="select_' . $htmlname . 
'" name="' . $htmlname . 
'" class="' . $htmlname . 
' flat minwidth75imp maxwidth200">';
 
10271        $out .= 
'<option value="0"> </option>';
 
10274      while ($obj = $this->db->fetch_object($resql)) {
 
10275        $out .= 
'<option ' . ($selected == $obj->rowid ? 
'selected="selected"' : 
'') . 
' value="' . $obj->rowid . 
'">' . $langs->trans($obj->label) . 
'</option>';
 
10277      $out .= 
'</select>';
 
10280      if (!empty($htmlname) && $user->admin && $info_admin) {
 
10281        $out .= 
' ' . 
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
 
10284      if (!empty($target)) {
 
10285        $sql = 
"SELECT c.id FROM " . $this->db->prefix() . 
"c_type_fees as c WHERE c.code = 'EX_KME' AND c.active = 1";
 
10286        $resql = $this->db->query($sql);
 
10288          if ($this->db->num_rows($resql) > 0) {
 
10289            $obj = $this->db->fetch_object($resql);
 
10290            $out .= 
'<script nonce="' . 
getNonce() . 
'"> 
10292                $("select[name=' . $target . 
']").on("change", function() { 
10293                  var current_val = $(this).val(); 
10294                  if (current_val == ' . $obj->id . 
') {';
 
10295            if (!empty($default_selected) || !empty($selected)) {
 
10296              $out .= 
'$("select[name=' . $htmlname . 
']").val("' . ($default_selected > 0 ? $default_selected : $selected) . 
'");';
 
10300                    $("select[name=' . $htmlname . 
']").change(); 
10304                $("select[name=' . $htmlname . 
']").change(function() { 
10306                  if ($("select[name=' . $target . 
']").val() == ' . $obj->id . 
') { 
10307                    // get price of kilometer to fill the unit price 
10311                      data: { fk_c_exp_tax_cat: $(this).val(), token: \'' . 
currentToken() . 
'\' },
 
10312                      url: 
"' . (DOL_URL_ROOT . '/expensereport/ajax/ajaxik.php?' . join('&', $params)) . '",
 
10313                    }).done(
function( data, textStatus, jqXHR ) {
 
10315                      if (typeof data.up != 
"undefined") {
 
10316                        $(
"input[name=value_unit]").val(data.up);
 
10317                        $(
"select[name=' . $htmlname . ']").attr(
"title", data.title);
 
10319                        $(
"input[name=value_unit]").val(
"");
 
10320                        $(
"select[name=' . $htmlname . ']").attr(
"title", 
"");
 
10331      dol_print_error($this->db); 
 
10345  public function selectExpenseRanges($selected = '
', $htmlname = 'fk_range
', $useempty = 0) 
10347    global $conf, $langs; 
10350    $sql = "SELECT rowid, range_ik FROM " . $this->db->prefix() . "c_exp_tax_range"; 
10351    $sql .= " WHERE entity = " . $conf->entity . " AND active = 1"; 
10353    $resql = $this->db->query($sql); 
10355      $out = '<select 
id=
"select_' . $htmlname . '" name=
"' . $htmlname . '" class=
"' . $htmlname . ' flat minwidth75imp">
'; 
10357        $out .= '<option value=
"0"></option>
'; 
10360      while ($obj = $this->db->fetch_object($resql)) { 
10361        $out .= '<option 
' . ($selected == $obj->rowid ? 'selected=
"selected"' : '') . ' value=
"' . $obj->rowid . '">
' . price($obj->range_ik, 0, $langs, 1, 0) . '</option>
'; 
10363      $out .= '</select>
'; 
10365      dol_print_error($this->db); 
 
10381  public function selectExpense($selected = '
', $htmlname = 'fk_c_type_fees
', $useempty = 0, $allchoice = 1, $useid = 0) 
10386    $sql = "SELECT id, code, label"; 
10387    $sql .= " FROM ".$this->db->prefix()."c_type_fees"; 
10388    $sql .= " WHERE active = 1"; 
10390    $resql = $this->db->query($sql); 
10392      $out = '<select 
id=
"select_' . $htmlname . '" name=
"' . $htmlname . '" class=
"' . $htmlname . ' flat minwidth75imp">
'; 
10394        $out .= '<option value=
"0"></option>
'; 
10397        $out .= '<option value=
"-1">
' . $langs->trans('AllExpenseReport
') . '</option>
'; 
10405      while ($obj = $this->db->fetch_object($resql)) { 
10406        $key = $langs->trans($obj->code); 
10407        $out .= '<option 
' . ($selected == $obj->{$field} ? 'selected=
"selected"' : '') . ' value=
"' . $obj->{$field} . '">
' . ($key != $obj->code ? $key : $obj->label) . '</option>
'; 
10409      $out .= '</select>
'; 
10411      $out .= ajax_combobox('select_
'.$htmlname); 
10413      dol_print_error($this->db); 
 
10437  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) 
10439    global $user, $conf, $langs; 
10441    require_once DOL_DOCUMENT_ROOT . '/projet/
class/project.class.php
'; 
10443    if (is_null($usertofilter)) { 
10444      $usertofilter = $user; 
10449    $hideunselectables = false; 
10450    if (getDolGlobalString('PROJECT_HIDE_UNSELECTABLES
')) { 
10451      $hideunselectables = true; 
10454    if (empty($projectsListId)) { 
10455      if (!$usertofilter->hasRight('projet
', 'all
', 'lire
')) { 
10456        $projectstatic = new Project($this->db); 
10457        $projectsListId = $projectstatic->getProjectsAuthorizedForUser($usertofilter, 0, 1); 
10461    // Search all projects 
10462    $sql = "SELECT f.rowid, f.ref as fref, 'nolabel
' as flabel, p.rowid as pid, f.ref, 
10463            p.title, p.fk_soc, p.fk_statut, p.public,"; 
10464    $sql .= ' s.nom as 
name'; 
10465    $sql .= ' FROM 
' . $this->db->prefix() . 'projet as p
'; 
10466    $sql .= ' LEFT JOIN 
' . $this->db->prefix() . 'societe as s ON s.rowid = p.fk_soc,
'; 
10467    $sql .= ' ' . $this->db->prefix() . 'facture as f
'; 
10468    $sql .= " WHERE p.entity IN (" . getEntity('project
') . ")"; 
10469    $sql .= " AND f.fk_projet = p.rowid AND f.fk_statut=0"; //Brouillons seulement 
10470    //if ($projectsListId) $sql.= " AND p.rowid IN (".$this->db->sanitize($projectsListId).")"; 
10471    //if ($socid == 0) $sql.= " AND (p.fk_soc=0 OR p.fk_soc IS NULL)"; 
10472    //if ($socid > 0)  $sql.= " AND (p.fk_soc=".((int) $socid)." OR p.fk_soc IS NULL)"; 
10473    $sql .= " ORDER BY p.ref, f.ref ASC"; 
10475    $resql = $this->db->query($sql); 
10477      // Use select2 selector 
10478      if (!empty($conf->use_javascript_ajax)) { 
10479        include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php
'; 
10480        $comboenhancement = ajax_combobox($htmlname, '', 0, $forcefocus); 
10481        $out .= $comboenhancement; 
10482        $morecss = 'minwidth200imp maxwidth500
'; 
10485      if (empty($option_only)) { 
10486        $out .= '<select 
class=
"valignmiddle flat' . ($morecss ? ' ' . $morecss : '') . '"' . ($disabled ? ' disabled=
"disabled"' : '') . ' id=
"' . $htmlname . '" name=
"' . $htmlname . '">
'; 
10488      if (!empty($show_empty)) { 
10489        $out .= '<option value=
"0" class=
"optiongrey">
'; 
10490        if (!is_numeric($show_empty)) { 
10491          $out .= $show_empty; 
10495        $out .= '</option>
'; 
10497      $num = $this->db->num_rows($resql); 
10500        while ($i < $num) { 
10501          $obj = $this->db->fetch_object($resql); 
10502          // 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. 
10503          if ($socid > 0 && (empty($obj->fk_soc) || $obj->fk_soc == $socid) && !$usertofilter->hasRight('societe
', 'lire
')) { 
10506            if ($discard_closed == 1 && $obj->fk_statut == Project::STATUS_CLOSED) { 
10513            if ($showproject == 'all
') { 
10514              $labeltoshow .= dol_trunc($obj->ref, 18); // Invoice ref 
10516                $labeltoshow .= ' - 
' . $obj->name; // Soc name 
10520              if ($obj->fk_statut == Project::STATUS_DRAFT) { 
10522                $labeltoshow .= ' - 
' . $langs->trans("Draft"); 
10523              } elseif ($obj->fk_statut == Project::STATUS_CLOSED) { 
10524                if ($discard_closed == 2) { 
10527                $labeltoshow .= ' - 
' . $langs->trans("Closed"); 
10528              } elseif ($socid > 0 && (!empty($obj->fk_soc) && $obj->fk_soc != $socid)) { 
10530                $labeltoshow .= ' - 
' . $langs->trans("LinkedToAnotherCompany"); 
10534            if (!empty($selected) && $selected == $obj->rowid) { 
10535              $out .= '<option value=
"' . $obj->rowid . '" selected
'; 
10536              //if ($disabled) $out.=' disabled
';           // with select2, field can't be preselected 
if disabled
 
10537              $out .= 
'>' . $labeltoshow . 
'</option>';
 
10539              if ($hideunselectables && $disabled && ($selected != $obj->rowid)) {
 
10542                $resultat = 
'<option value="' . $obj->rowid . 
'"';
 
10544                  $resultat .= 
' disabled';
 
10549                $resultat .= $labeltoshow;
 
10550                $resultat .= 
'</option>';
 
10558      if (empty($option_only)) {
 
10559        $out .= 
'</select>';
 
10562      $this->db->free($resql);
 
 
10584  public function selectInvoiceRec($selected = 
'', $htmlname = 
'facrecid', $maxlength = 24, $option_only = 0, $show_empty = 
'1', $forcefocus = 0, $disabled = 0, $morecss = 
'maxwidth500')
 
10586    global $conf, $langs;
 
10592    $sql = 
'SELECT f.rowid, f.entity, f.titre as title, f.suspended, f.fk_soc';
 
10594    $sql .= 
' FROM ' . MAIN_DB_PREFIX . 
'facture_rec as f';
 
10595    $sql .= 
" WHERE f.entity IN (" . 
getEntity(
'invoice') . 
")";
 
10596    $sql .= 
" ORDER BY f.titre ASC";
 
10598    $resql = $this->db->query($sql);
 
10601      if (!empty($conf->use_javascript_ajax)) {
 
10602        include_once DOL_DOCUMENT_ROOT . 
'/core/lib/ajax.lib.php';
 
10603        $comboenhancement = 
ajax_combobox($htmlname, 
'', 0, $forcefocus);
 
10604        $out .= $comboenhancement;
 
10605        $morecss = 
'minwidth200imp maxwidth500';
 
10608      if (empty($option_only)) {
 
10609        $out .= 
'<select class="valignmiddle flat' . ($morecss ? 
' ' . $morecss : 
'') . 
'"' . ($disabled ? 
' disabled="disabled"' : 
'') . 
' id="' . $htmlname . 
'" name="' . $htmlname . 
'">';
 
10611      if (!empty($show_empty)) {
 
10612        $out .= 
'<option value="0" class="optiongrey">';
 
10613        if (!is_numeric($show_empty)) {
 
10614          $out .= $show_empty;
 
10618        $out .= 
'</option>';
 
10620      $num = $this->db->num_rows($resql);
 
10622        while ($obj = $this->db->fetch_object($resql)) {
 
10623          $labeltoshow = 
dol_trunc($obj->title, 18); 
 
10626          if (!empty($obj->suspended)) {
 
10628            $labeltoshow .= 
' - ' . $langs->trans(
"Closed");
 
10632          if (!empty($selected) && $selected == $obj->rowid) {
 
10633            $out .= 
'<option value="' . $obj->rowid . 
'" selected';
 
10635            $out .= 
'>' . $labeltoshow . 
'</option>';
 
10637            if ($disabled && ($selected != $obj->rowid)) {
 
10640              $resultat = 
'<option value="' . $obj->rowid . 
'"';
 
10642                $resultat .= 
' disabled';
 
10645              $resultat .= $labeltoshow;
 
10646              $resultat .= 
'</option>';
 
10652      if (empty($option_only)) {
 
10653        $out .= 
'</select>';
 
10658      $this->db->free($resql);
 
10661      $this->errors[] = $this->db->lasterror;
 
 
10675  public function searchComponent($arrayofcriterias, $search_component_params, $arrayofinputfieldsalreadyoutput = array(), $search_component_params_hidden = 
'')
 
10679    if ($search_component_params_hidden != 
'' && !preg_match(
'/^\(.*\)$/', $search_component_params_hidden)) {    
 
10680      $search_component_params_hidden = 
'(' . $search_component_params_hidden . 
')';
 
10685    $ret .= 
'<div class="divadvancedsearchfieldcomp inline-block">';
 
10686    $ret .= 
'<a href="#" class="dropdownsearch-toggle unsetcolor">';
 
10687    $ret .= 
'<span class="fas fa-filter linkobject boxfilter paddingright pictofixedwidth" title="' . 
dol_escape_htmltag($langs->trans(
"Filters")) . 
'" id="idsubimgproductdistribution"></span>';
 
10690    $ret .= 
'<div class="divadvancedsearchfieldcompinput inline-block minwidth500 maxwidth300onsmartphone">';
 
10693    $ret .= 
'<div name="divsearch_component_params" class="noborderbottom search_component_params inline-block valignmiddle">';
 
10695    if ($search_component_params_hidden) {
 
10699      $nbofchars = 
dol_strlen($search_component_params_hidden);
 
10700      $arrayofandtags = array();
 
10703      $countparenthesis = 0;
 
10704      while ($i < $nbofchars) {
 
10705        $char = 
dol_substr($search_component_params_hidden, $i, 1);
 
10707        if ($char == 
'(') {
 
10708          $countparenthesis++;
 
10709        } elseif ($char == 
')') {
 
10710          $countparenthesis--;
 
10713        if ($countparenthesis == 0) {
 
10714          $char2 = 
dol_substr($search_component_params_hidden, $i+1, 1);
 
10715          $char3 = 
dol_substr($search_component_params_hidden, $i+2, 1);
 
10716          if ($char == 
'A' && $char2 == 
'N' && $char3 == 
'D') {
 
10718            $arrayofandtags[] = trim($s);
 
10730        $arrayofandtags[] = trim($s);
 
10734      foreach ($arrayofandtags as $tmpkey => $tmpval) {
 
10735        $errormessage = 
'';
 
10737        if ($errormessage) {
 
10738          $this->error = 
'ERROR in parsing search string: '.$errormessage;
 
10741        include_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
 
10744        $ret .= 
'<span class="marginleftonlyshort valignmiddle tagsearch" data-ufilterid="'.($tmpkey+1).
'" data-ufilter="'.
dol_escape_htmltag($tmpval).
'">';
 
10745        $ret .= 
'<span class="tagsearchdelete select2-selection__choice__remove" data-ufilterid="'.($tmpkey+1).
'">x</span> ';
 
10757    $show_search_component_params_hidden = 1;
 
10758    if ($show_search_component_params_hidden) {
 
10759      $ret .= 
'<input type="hidden" name="show_search_component_params_hidden" value="1">';
 
10761    $ret .= 
"<!-- We store the full Universal Search String into this field. For example: (t.ref:like:'SO-%') AND ((t.ref:like:'CO-%') OR (t.ref:like:'AA%')) -->";
 
10762    $ret .= 
'<input type="hidden" name="search_component_params_hidden" value="' . 
dol_escape_htmltag($search_component_params_hidden) . 
'">';
 
10766    foreach ($arrayofcriterias as $criterias) {
 
10767      foreach ($criterias as $criteriafamilykey => $criteriafamilyval) {
 
10768        if (in_array(
'search_' . $criteriafamilykey, $arrayofinputfieldsalreadyoutput)) {
 
10771        if (in_array($criteriafamilykey, array(
'rowid', 
'ref_ext', 
'entity', 
'extraparams'))) {
 
10774        if (in_array($criteriafamilyval[
'type'], array(
'date', 
'datetime', 
'timestamp'))) {
 
10775          $ret .= 
'<input type="hidden" name="search_' . $criteriafamilykey . 
'_start">';
 
10776          $ret .= 
'<input type="hidden" name="search_' . $criteriafamilykey . 
'_startyear">';
 
10777          $ret .= 
'<input type="hidden" name="search_' . $criteriafamilykey . 
'_startmonth">';
 
10778          $ret .= 
'<input type="hidden" name="search_' . $criteriafamilykey . 
'_startday">';
 
10779          $ret .= 
'<input type="hidden" name="search_' . $criteriafamilykey . 
'_end">';
 
10780          $ret .= 
'<input type="hidden" name="search_' . $criteriafamilykey . 
'_endyear">';
 
10781          $ret .= 
'<input type="hidden" name="search_' . $criteriafamilykey . 
'_endmonth">';
 
10782          $ret .= 
'<input type="hidden" name="search_' . $criteriafamilykey . 
'_endday">';
 
10784          $ret .= 
'<input type="hidden" name="search_' . $criteriafamilykey . 
'">';
 
10791    $ret .= 
"<!-- Field to enter a generic filter string: t.ref:like:'SO-%', t.date_creation:<:'20160101', t.date_creation:<:'2016-01-01 12:30:00', t.nature:is:NULL, t.field2:isnot:NULL -->\n";
 
10792    $ret .= 
'<input type="text" placeholder="' . $langs->trans(
"Search") . 
'" name="search_component_params_input" class="noborderbottom search_component_input" value="">';
 
10798    jQuery(".tagsearchdelete").click(function() { 
10799      var filterid = $(this).parents().data("ufilterid"); 
10800      console.log("We click to delete a criteria nb "+filterid); 
10801      // TODO Update the search_component_params_hidden with all data-ufilter except the one delete and post page 
 
10822    global $langs, $user;
 
10826    $TModels = array();
 
10828    include_once DOL_DOCUMENT_ROOT . 
'/core/class/html.formmail.class.php';
 
10829    $formmail = 
new FormMail($this->db);
 
10830    $result = $formmail->fetchAllEMailTemplate($modelType, $user, $langs);
 
10833      $TModels[0] = $langs->trans(
'DefaultMailModel');
 
10836      foreach ($formmail->lines_model as $model) {
 
10837        $TModels[$model->id] = $model->label;
 
10841    $retstring .= 
'<select class="flat" id="select_' . $prefix . 
'model_mail" name="' . $prefix . 
'model_mail">';
 
10843    foreach ($TModels as $id_model => $label_model) {
 
10844      $retstring .= 
'<option value="' . $id_model . 
'"';
 
10845      $retstring .= 
">" . $label_model . 
"</option>";
 
10848    $retstring .= 
"</select>";
 
10851      $retstring .= 
ajax_combobox(
'select_' . $prefix . 
'model_mail');
 
 
10868  public function buttonsSaveCancel($save_label = 
'Save', $cancel_label = 
'Cancel', $morebuttons = array(), $withoutdiv = 
false, $morecss = 
'', $dol_openinpopup = 
'')
 
10872    $buttons = array();
 
10876      'label_key' => $save_label,
 
10879    if ($save_label == 
'Create' || $save_label == 
'Add') {
 
10880      $save[
'name'] = 
'add';
 
10881    } elseif ($save_label == 
'Modify') {
 
10882      $save[
'name'] = 
'edit';
 
10886      'name' => 
'cancel',
 
10887      'label_key' => 
'Cancel',
 
10890    !empty($save_label) ? $buttons[] = $save : 
'';
 
10892    if (!empty($morebuttons)) {
 
10893      $buttons[] = $morebuttons;
 
10896    !empty($cancel_label) ? $buttons[] = $cancel : 
'';
 
10898    $retstring = $withoutdiv ? 
'' : 
'<div class="center">';
 
10900    foreach ($buttons as $button) {
 
10901      $addclass = empty($button[
'addclass']) ? 
'' : $button[
'addclass'];
 
10902      $retstring .= 
'<input type="submit" class="button button-' . $button[
'name'] . ($morecss ? 
' ' . $morecss : 
'') . 
' ' . $addclass . 
'" name="' . $button[
'name'] . 
'" value="' . 
dol_escape_htmltag($langs->trans($button[
'label_key'])) . 
'">';
 
10904    $retstring .= $withoutdiv ? 
'' : 
'</div>';
 
10906    if ($dol_openinpopup) {
 
10907      $retstring .= 
'<!-- buttons are shown into a $dol_openinpopup=' . $dol_openinpopup . 
' context, so we enable the close of dialog on cancel -->' . 
"\n";
 
10908      $retstring .= 
'<script nonce="' . 
getNonce() . 
'">';
 
10909      $retstring .= 
'jQuery(".button-cancel").click(function(e) { 
10910        e.preventDefault(); console.log(\'We click on cancel in iframe popup ' . $dol_openinpopup . 
'\');
 
10911        window.parent.jQuery(\
'#idfordialog' . $dol_openinpopup . 
'\').dialog(\
'close\'); 
10913      $retstring .= 
'</script>';
 
 
10932    $num = count($this->cache_invoice_subtype);
 
10939    $sql = 
"SELECT rowid, code, label as label";
 
10940    $sql .= 
" FROM " . MAIN_DB_PREFIX . 
'c_invoice_subtype';
 
10941    $sql .= 
" WHERE active = 1";
 
10943    $resql = $this->db->query($sql);
 
10945      $num = $this->db->num_rows($resql);
 
10947      while ($i < $num) {
 
10948        $obj = $this->db->fetch_object($resql);
 
10951        $label = ($langs->trans(
"InvoiceSubtype" . $obj->rowid) != 
"InvoiceSubtype" . $obj->rowid) ? $langs->trans(
"InvoiceSubtype" . $obj->rowid) : (($obj->label != 
'-') ? $obj->label : 
'');
 
10952        $this->cache_invoice_subtype[$obj->rowid][
'rowid'] = $obj->rowid;
 
10953        $this->cache_invoice_subtype[$obj->rowid][
'code'] = $obj->code;
 
10954        $this->cache_invoice_subtype[$obj->rowid][
'label'] = $label;
 
10958      $this->cache_invoice_subtype = 
dol_sort_array($this->cache_invoice_subtype, 
'code', 
'asc', 0, 0, 1);
 
 
10980    global $langs, $user;
 
10983    dol_syslog(__METHOD__ . 
" selected=" . $selected . 
", htmlname=" . $htmlname, LOG_DEBUG);
 
10985    $this->load_cache_invoice_subtype();
 
10987    $out .= 
'<select id="' . $htmlname . 
'" class="flat selectsubtype' . ($morecss ? 
' ' . $morecss : 
'') . 
'" name="' . $htmlname . 
'">';
 
10989      $out .= 
'<option value="0"> </option>';
 
10992    foreach ($this->cache_invoice_subtype as $rowid => $subtype) {
 
10993      $label = $subtype[
'label'];
 
10994      $out .= 
'<option value="' . $subtype[
'rowid'] . 
'"';
 
10995      if ($selected == $subtype[
'rowid']) {
 
10996        $out .= 
' selected="selected"';
 
11000      $out .= 
'</option>';
 
11003    $out .= 
'</select>';
 
11004    if ($user->admin && empty($noinfoadmin)) {
 
11005      $out .= 
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
 
 
 
ajax_autocompleter($selected, $htmlname, $url, $urloption='', $minLength=2, $autoselect=0, $ajaxoptions=array(), $moreparams='')
Generic function that return javascript to add to a page to transform a common input field into an au...
 
ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete='resolve', $idforemptyvalue='-1', $morecss='')
Convert a html select field into an ajax combobox.
 
ajax_multiautocompleter($htmlname, $fields, $url, $option='', $minLength=2, $autoselect=0)
Generic function that return javascript to add to a page to transform a common input field into an au...
 
ajax_event($htmlname, $events)
Add event management script.
 
Class to manage bank accounts.
 
Class to manage categories.
 
Class to manage a WYSIWYG editor.
 
const STATUS_OPEN_INTERNAL
Warehouse open and only operations for stock transfers/corrections allowed (not for customer shipping...
 
const STATUS_OPEN_ALL
Warehouse open and any operations are allowed (customer shipping, supplier dispatch,...
 
const STATUS_CLOSED
Warehouse closed, inactive.
 
Class to manage invoices.
 
Class to parse product price expressions.
 
Class to manage predefined suppliers products.
 
Class to manage products or services.
 
const TYPE_PRODUCT
Regular product.
 
const TYPE_SERVICE
Service.
 
Class to manage projects.
 
Class to manage third parties objects (customers, suppliers, prospects...)
 
Class to manage Dolibarr users.
 
currency_name($code_iso, $withcode='', $outputlangs=null)
Return label of currency or code+label.
 
getCountry($searchkey, $withcode='', $dbtouse=0, $outputlangs='', $entconv=1, $searchlabel='')
Return country label, code or id from an id, code or label.
 
isInEEC($object)
Return if a country of an object is inside the EEC (European Economic Community)
 
getServerTimeZoneInt($refgmtdate='now')
Return server timezone int.
 
removeGlobalParenthesis($string)
Remove first and last parenthesis but only if first is the opening and last the closing of the same g...
 
dol_getIdFromCode($db, $key, $tablename, $fieldkey='code', $fieldid='id', $entityfilter=0, $filters='', $useCache=true)
Return an id or code from a code or id.
 
vatrate($rate, $addpercent=false, $info_bits=0, $usestarfornpr=0, $html=0)
Return a string with VAT rate label formated for view output Used into pdf and HTML pages.
 
picto_from_langcode($codelang, $moreatt='', $notitlealt=0)
Return img flag of country for a language code or country code.
 
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
 
img_help($usehelpcursor=1, $usealttitle=1)
Show help logo with cursor "?".
 
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
 
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
 
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
 
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
 
currentToken()
Return the value of token currently saved into session with name 'token'.
 
dol_nl2br($stringtoencode, $nl2brmode=0, $forxml=false)
Replace CRLF in string with a HTML BR tag.
 
dol_print_url($url, $target='_blank', $max=32, $withpicto=0, $morecss='')
Show Url link.
 
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
 
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
 
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
 
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0)
forgeSQLFromUniversalSearchCriteria
 
dol_print_email($email, $cid=0, $socid=0, $addlink=0, $max=64, $showinvalid=1, $withpicto=0)
Show EMail link formatted for HTML output.
 
dol_print_phone($phone, $countrycode='', $cid=0, $socid=0, $addlink='', $separ=" ", $withpicto='', $titlealt='', $adddivfloat=0)
Format phone numbers according to country.
 
dol_now($mode='auto')
Return date for now.
 
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
 
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
 
dol_escape_js($stringtoescape, $mode=0, $noescapebackslashn=0)
Returns text escaped for inclusion into javascript code.
 
dol_string_onlythesehtmltags($stringtoclean, $cleanalsosomestyles=1, $removeclassattribute=1, $cleanalsojavascript=0, $allowiframe=0, $allowed_tags=array(), $allowlink=0)
Clean a string to keep only desirable HTML tags.
 
dol_sort_array(&$array, $index, $order='asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by second index function, which produces ascending (default) or descending output...
 
if(!function_exists( 'dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
 
showDimensionInBestUnit($dimension, $unit, $type, $outputlangs, $round=-1, $forceunitoutput='no', $use_short_label=0)
Output a dimension with best unit.
 
dol_string_unaccent($str)
Clean a string from all accent characters to be used as ref, login or by dol_sanitizeFileName.
 
dol_string_neverthesehtmltags($stringtoclean, $disallowed_tags=array('textarea'), $cleanalsosomestyles=0)
Clean a string from some undesirable HTML tags.
 
get_default_npr(Societe $thirdparty_seller, Societe $thirdparty_buyer, $idprod=0, $idprodfournprice=0)
Function that returns whether VAT must be recoverable collected VAT (e.g.: VAT NPR in France)
 
dol_htmlentities($string, $flags=ENT_QUOTES|ENT_SUBSTITUTE, $encoding='UTF-8', $double_encode=false)
Replace htmlentities functions.
 
getImageFileNameForSize($file, $extName, $extImgTarget='')
Return the filename of file to get the thumbs.
 
dol_substr($string, $start, $length=null, $stringencoding='', $trunconbytes=0)
Make a substring.
 
getAdvancedPreviewUrl($modulepart, $relativepath, $alldata=0, $param='')
Return URL we can use for advanced preview links.
 
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
 
dolIsAllowedForPreview($file)
Return if a file is qualified for preview.
 
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='')
Show information for admin users or standard users.
 
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
 
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
 
getNonce()
Return a random string to be used as a nonce value for js.
 
dol_htmlentitiesbr($stringtoencode, $nl2brmode=0, $pagecodefrom='UTF-8', $removelasteolbr=1)
This function is called to encode a string into a HTML string but differs from htmlentities because a...
 
dol_htmlwithnojs($stringtoencode, $nouseofiframesandbox=0, $check='restricthtml')
Sanitize a HTML to remove js, dangerous content and external link.
 
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
 
img_edit($titlealt='default', $float=0, $other='')
Show logo editer/modifier fiche.
 
get_default_tva(Societe $thirdparty_seller, Societe $thirdparty_buyer, $idprod=0, $idprodfournprice=0)
Function that return vat rate of a product line (according to seller, buyer and product vat rate) VAT...
 
get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart='')
Return a path to have a the directory according to object where files are stored.
 
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
 
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
 
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
 
publicphonebutton2 phonegreen basiclayout basiclayout TotalHT VATCode TotalVAT TotalLT1 TotalLT2 TotalTTC TotalHT clearboth nowraponall right right takeposterminal SELECT e rowid
 
testSqlAndScriptInject($val, $type)
Security: WAF layer for SQL Injection and XSS Injection (scripts) protection (Filters on GET,...
 
ui dialog ui datepicker calendar ui widget content ui state ui datepicker calendar ui widget header ui state ui datepicker calendar ui button
0 = Do not include form tag and submit button -1 = Do not include form tag but include submit button
 
measuringUnitString($unit, $measuring_style='', $scale='', $use_short_label=0, $outputlangs=null)
Return translation label of a unit key.
 
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
 
$conf db name
Only used if Module[ID]Name translation string is not found.
 
getMaxFileSizeArray()
Return the max allowed for file upload.
 
dol_hash($chain, $type='0', $nosalt=0)
Returns a hash (non reversible encryption) of a string.