@@ -442,195 +442,6 @@ public function selectForForms($objectdesc, $htmlname, $preselectedvalue, $showe
442442 return $ out ;
443443 }
444444
445- /**
446- * Output html form to select an object.
447- * Note, this function is called by selectForForms or by ajax selectobject.php
448- *
449- * @param Object $objecttmp Object to know the table to scan for combo.
450- * @param string $htmlname Name of HTML select component
451- * @param int $preselectedvalue Preselected value (ID of element)
452- * @param string $showempty ''=empty values not allowed, 'string'=value show if we allow empty values (for example 'All', ...)
453- * @param string $searchkey Search value
454- * @param string $placeholder Place holder
455- * @param string $morecss More CSS
456- * @param string $moreparams More params provided to ajax call
457- * @param int $forcecombo Force to load all values and output a standard combobox (with no beautification)
458- * @param int $outputmode 0=HTML select string, 1=Array
459- * @param int $disabled 1=Html component is disabled
460- * @param string $sortfield Sort field
461- * @param string $filter Add more filter (Universal Search Filter)
462- * @return string|array<array{key:int,value:string,label:string}> Return HTML string
463- * @see selectForForms()
464- */
465- public function selectForFormsList ($ objecttmp , $ htmlname , $ preselectedvalue , $ showempty = '' , $ searchkey = '' , $ placeholder = '' , $ morecss = '' , $ moreparams = '' , $ forcecombo = 0 , $ outputmode = 0 , $ disabled = 0 , $ sortfield = '' , $ filter = '' )
466- {
467- global $ langs , $ hookmanager ;
468-
469- // TODO Why having a duplication of code of selectForFormsList of html.form.class.php ? Original seems more complete. Remove or replace with return parent::selectForFormsList();
470-
471- //print "$htmlname, $preselectedvalue, $showempty, $searchkey, $placeholder, $morecss, $moreparams, $forcecombo, $outputmode, $disabled";
472-
473- $ prefixforautocompletemode = $ objecttmp ->element ;
474- if ($ prefixforautocompletemode == 'societe ' ) {
475- $ prefixforautocompletemode = 'company ' ;
476- }
477- $ confkeyforautocompletemode = strtoupper ($ prefixforautocompletemode ) . '_USE_SEARCH_TO_SELECT ' ; // For example COMPANY_USE_SEARCH_TO_SELECT
478-
479- if (in_array ($ objecttmp ->element , array ('adherent_type ' ))) {
480- $ fieldstoshow = 't.libelle ' ;
481- }
482- if (!empty ($ objecttmp ->fields )) { // For object that declare it, it is better to use declared fields (like societe, contact, ...)
483- $ tmpfieldstoshow = '' ;
484- foreach ($ objecttmp ->fields as $ key => $ val ) {
485- if (! (int ) dol_eval ((string ) $ val ['enabled ' ], 1 , 1 , '1 ' )) {
486- continue ;
487- }
488- if (!empty ($ val ['showoncombobox ' ])) {
489- $ tmpfieldstoshow .= ($ tmpfieldstoshow ? ', ' : '' ) . 't. ' . $ key ;
490- }
491- }
492- if ($ tmpfieldstoshow ) {
493- $ fieldstoshow = $ tmpfieldstoshow ;
494- }
495- } elseif (!in_array ($ objecttmp ->element , array ('adherent_type ' ))) {
496- // For backward compatibility
497- $ objecttmp ->fields ['ref ' ] = array ('type ' => 'varchar(30) ' , 'label ' => 'Ref ' , 'showoncombobox ' => 1 );
498- }
499-
500- if (empty ($ fieldstoshow )) {
501- if (isset ($ objecttmp ->fields ['ref ' ])) {
502- $ fieldstoshow = 't.ref ' ;
503- } else {
504- $ langs ->load ("errors " );
505- $ this ->error = $ langs ->trans ("ErrorNoFieldWithAttributeShowoncombobox " );
506- return $ langs ->trans ('ErrorNoFieldWithAttributeShowoncombobox ' );
507- }
508- }
509-
510- $ out = '' ;
511- $ outarray = array ();
512- $ tmparray = array ();
513-
514- $ num = 0 ;
515-
516- // Search data
517- $ sql = "SELECT t.rowid, " . $ fieldstoshow . " FROM " . $ this ->db ->prefix () . $ objecttmp ->table_element . " as t " ;
518- if (isset ($ objecttmp ->ismultientitymanaged )) {
519- if (!is_numeric ($ objecttmp ->ismultientitymanaged )) {
520- $ tmparray = explode ('@ ' , $ objecttmp ->ismultientitymanaged );
521- $ sql .= " INNER JOIN " . $ this ->db ->prefix () . $ tmparray [1 ] . " as parenttable ON parenttable.rowid = t. " . $ tmparray [0 ];
522- }
523- }
524-
525- if (!empty ($ objecttmp ->isextrafieldmanaged )) {
526- $ sql .= " LEFT JOIN " . $ this ->db ->prefix () . $ this ->db ->sanitize ($ objecttmp ->table_element ) . "_extrafields as e ON t.rowid = e.fk_object " ;
527- }
528-
529- // Add where from hooks
530- $ parameters = array (
531- 'object ' => $ objecttmp ,
532- 'htmlname ' => $ htmlname ,
533- 'filter ' => $ filter ,
534- 'searchkey ' => $ searchkey
535- );
536-
537- $ reshook = $ hookmanager ->executeHooks ('selectForFormsListWhere ' , $ parameters ); // Note that $action and $object may have been modified by hook
538- if (!empty ($ hookmanager ->resPrint )) {
539- $ sql .= $ hookmanager ->resPrint ;
540- } else {
541- $ sql .= " WHERE 1=1 " ;
542- if (isset ($ objecttmp ->ismultientitymanaged )) {
543- if ($ objecttmp ->ismultientitymanaged == 1 ) {
544- $ sql .= " AND t.entity IN ( " . getEntity ($ objecttmp ->table_element ) . ") " ;
545- }
546- if (!is_numeric ($ objecttmp ->ismultientitymanaged )) {
547- $ sql .= " AND parenttable.entity = t. " . $ tmparray [0 ];
548- }
549- }
550- if ($ searchkey != '' ) {
551- $ sql .= natural_search (explode (', ' , $ fieldstoshow ), $ searchkey );
552- }
553-
554- if ($ filter ) { // Syntax example "(t.ref:like:'SO-%') and (t.date_creation:<:'20160101')"
555- $ errormessage = '' ;
556- $ sql .= forgeSQLFromUniversalSearchCriteria ($ filter , $ errormessage );
557- if ($ errormessage ) {
558- return 'Error forging a SQL request from an universal criteria: ' . $ errormessage ;
559- }
560- }
561- }
562- $ sql .= $ this ->db ->order ($ sortfield ? $ sortfield : $ fieldstoshow , "ASC " );
563-
564- // Build output string
565- $ resql = $ this ->db ->query ($ sql );
566- if ($ resql ) {
567- // Construct $out and $outarray
568- $ out .= '<select id=" ' . $ htmlname . '" class=" ' . ($ morecss ? ' ' . $ morecss : '' ) . '" ' . ($ disabled ? ' disabled="disabled" ' : '' ) . ($ moreparams ? ' ' . $ moreparams : '' ) . ' name=" ' . $ htmlname . '"> ' . "\n" ;
569-
570- // Warning: Do not use textifempty = ' ' or ' ' here, or search on key will search on ' key'. Seems it is no more true with selec2 v4
571- $ textifempty = ' ' ;
572-
573- //if (!empty($conf->use_javascript_ajax) || $forcecombo) $textifempty='';
574- if (getDolGlobalString ($ confkeyforautocompletemode )) {
575- if ($ showempty && !is_numeric ($ showempty )) {
576- $ textifempty = $ langs ->trans ($ showempty );
577- } else {
578- $ textifempty .= $ langs ->trans ("All " );
579- }
580- }
581- if ($ showempty ) {
582- $ out .= '<option value="-1"> ' . $ textifempty . '</option> ' . "\n" ;
583- }
584-
585- $ num = $ this ->db ->num_rows ($ resql );
586- $ i = 0 ;
587- if ($ num ) {
588- while ($ i < $ num ) {
589- $ obj = $ this ->db ->fetch_object ($ resql );
590- $ label = '' ;
591- $ labelhtml = '' ;
592- $ tmparray = explode (', ' , $ fieldstoshow );
593- $ oldvalueforshowoncombobox = 0 ;
594- foreach ($ tmparray as $ key => $ val ) {
595- $ val = preg_replace ('/t\./ ' , '' , $ val );
596- $ label .= (($ label && $ obj ->$ val ) ? ($ oldvalueforshowoncombobox != $ objecttmp ->fields [$ val ]['showoncombobox ' ] ? ' - ' : ' ' ) : '' );
597- $ labelhtml .= (($ label && $ obj ->$ val ) ? ($ oldvalueforshowoncombobox != $ objecttmp ->fields [$ val ]['showoncombobox ' ] ? ' - ' : ' ' ) : '' );
598- $ label .= $ obj ->$ val ;
599- $ labelhtml .= $ obj ->$ val ;
600-
601- $ oldvalueforshowoncombobox = empty ($ objecttmp ->fields [$ val ]['showoncombobox ' ]) ? 0 : $ objecttmp ->fields [$ val ]['showoncombobox ' ];
602- }
603- if (empty ($ outputmode )) {
604- if ($ preselectedvalue > 0 && $ preselectedvalue == $ obj ->rowid ) {
605- $ 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> ' ;
606- } else {
607- $ out .= '<option value=" ' . $ obj ->rowid . '" data-html=" ' . dol_escape_htmltag ($ labelhtml , 0 , 0 , '' , 0 , 1 ) . '"> ' . dol_escape_htmltag ($ label , 0 , 0 , '' , 0 , 1 ) . '</option> ' ;
608- }
609- } else {
610- array_push ($ outarray , array ('key ' => $ obj ->rowid , 'value ' => $ label , 'label ' => $ label ));
611- }
612-
613- $ i ++;
614- if (($ i % 10 ) == 0 ) {
615- $ out .= "\n" ;
616- }
617- }
618- }
619-
620- $ out .= '</select> ' . "\n" ;
621- } else {
622- dol_print_error ($ this ->db );
623- }
624-
625- $ this ->result = array ('nbofelement ' => $ num );
626-
627- if ($ outputmode ) {
628- return $ outarray ;
629- }
630-
631- return $ out ;
632- }
633-
634445 /**
635446 * Return HTML string to put an input field into a page
636447 * Code very similar with showInputField for common object
0 commit comments