2010-05-03 10:22:35 +02:00
< ? php
2015-05-23 18:52:31 +02:00
/* Copyright ( c ) 2002 - 2007 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
* Copyright ( C ) 2004 - 2012 Laurent Destailleur < eldy @ users . sourceforge . net >
* Copyright ( C ) 2004 Benoit Mortier < benoit . mortier @ opensides . be >
* Copyright ( C ) 2004 Sebastien Di Cintio < sdicintio @ ressource - toi . org >
* Copyright ( C ) 2004 Eric Seigne < eric . seigne @ ryxeo . com >
2018-10-27 14:43:12 +02:00
* Copyright ( C ) 2005 - 2017 Regis Houssin < regis . houssin @ inodbox . com >
2015-05-23 18:52:31 +02:00
* Copyright ( C ) 2006 Andre Cianfarani < acianfa @ free . fr >
* Copyright ( C ) 2006 Marc Barilley / Ocebo < marc @ ocebo . com >
* Copyright ( C ) 2007 Franky Van Liedekerke < franky . van . liedekerker @ telenet . be >
* Copyright ( C ) 2007 Patrick Raguin < patrick . raguin @ gmail . com >
* Copyright ( C ) 2010 Juanjo Menent < jmenent @ 2 byte . es >
2019-01-19 12:40:17 +01:00
* Copyright ( C ) 2010 - 2019 Philippe Grand < philippe . grand @ atoo - net . com >
2015-05-23 18:52:31 +02:00
* Copyright ( C ) 2011 Herve Prot < herve . prot @ symeos . com >
2016-07-23 16:37:21 +02:00
* Copyright ( C ) 2012 - 2016 Marcos García < marcosgdf @ gmail . com >
2015-05-23 18:52:31 +02:00
* Copyright ( C ) 2012 Cedric Salvador < csalvador @ gpcsolutions . fr >
* Copyright ( C ) 2012 - 2015 Raphaël Doursenaud < rdoursenaud @ gpcsolutions . fr >
2020-11-05 16:56:28 +01:00
* Copyright ( C ) 2014 - 2020 Alexandre Spangaro < aspangaro @ open - dsi . fr >
2021-03-30 11:10:07 +02:00
* Copyright ( C ) 2018 - 2021 Ferran Marcet < fmarcet @ 2 byte . es >
2021-02-07 18:31:31 +01:00
* Copyright ( C ) 2018 - 2021 Frédéric France < frederic . france @ netlogic . fr >
2018-12-01 18:19:45 +01:00
* Copyright ( C ) 2018 Nicolas ZABOURI < info @ inovea - conseil . com >
2018-12-14 15:10:32 +01:00
* Copyright ( C ) 2018 Christophe Battarel < christophe @ altairis . fr >
2018-12-07 17:28:31 +01:00
* Copyright ( C ) 2018 Josep Lluis Amador < joseplluis @ lliuretic . cat >
2010-05-03 10:22:35 +02:00
*
* This program is free software ; you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
2013-01-16 15:36:08 +01:00
* the Free Software Foundation ; either version 3 of the License , or
2010-05-03 10:22:35 +02:00
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
2019-09-23 21:55:30 +02:00
* along with this program . If not , see < https :// www . gnu . org / licenses />.
2010-05-03 10:22:35 +02:00
*/
/**
2010-06-08 01:52:43 +02:00
* \file htdocs / core / class / html . form . class . php
2010-11-22 10:18:53 +01:00
* \ingroup core
2010-07-10 01:49:41 +02:00
* \brief File of class with all html predefined components
2010-05-03 10:22:35 +02:00
*/
/**
2012-02-21 10:47:08 +01:00
* Class to manage generation of HTML components
* Only common components must be here .
2015-06-06 13:22:15 +02:00
*
2015-06-06 14:21:18 +02:00
* TODO Merge all function load_cache_ * and loadCache * ( except load_cache_vatrates ) into one generic function loadCacheTable
2010-05-03 10:22:35 +02:00
*/
class Form
{
2018-08-22 11:06:34 +02:00
/**
2020-04-18 15:11:38 +02:00
* @ var DoliDB Database handler .
*/
public $db ;
2012-02-21 10:47:08 +01:00
2018-08-22 10:37:16 +02:00
/**
* @ var string Error code ( or message )
*/
2019-11-08 15:51:54 +01:00
public $error = '' ;
2012-02-21 10:47:08 +01:00
2020-04-18 15:11:38 +02:00
/**
* @ var string [] Array of error strings
*/
public $errors = array ();
2012-02-21 10:47:08 +01:00
2018-10-06 12:34:51 +02:00
public $num ;
2012-02-21 10:47:08 +01:00
2017-10-07 13:09:31 +02:00
// Cache arrays
2019-11-08 15:51:54 +01:00
public $cache_types_paiements = array ();
public $cache_conditions_paiements = array ();
2020-07-06 04:47:27 +02:00
public $cache_transport_mode = array ();
2019-11-08 15:51:54 +01:00
public $cache_availability = array ();
public $cache_demand_reason = array ();
public $cache_types_fees = array ();
public $cache_vatrates = array ();
2012-03-15 22:51:02 +01:00
2012-02-21 10:47:08 +01:00
2017-10-07 13:09:31 +02:00
/**
* Constructor
*
* @ param DoliDB $db Database handler
*/
public function __construct ( $db )
{
$this -> db = $db ;
}
2012-02-21 10:47:08 +01:00
2017-10-07 13:09:31 +02:00
/**
* Output key field for an editable field
*
* @ param string $text Text of label or key to translate
* @ param string $htmlname Name of select field ( 'edit' prefix will be added )
* @ param string $preselected Value to show / edit ( not used in this function )
* @ param object $object Object
* @ param boolean $perm Permission to allow button to edit parameter . Set it to 0 to have a not edited field .
2021-03-26 18:37:11 +01:00
* @ param string $typeofdata Type of data ( 'string' by default , 'email' , 'amount:99' , 'numeric:99' , 'text' or 'textarea:rows:cols' , 'datepicker' ( 'day' do not work , don 't know why), ' checkbox : ckeditor : dolibarr_zzz : width : height : savemethod : 1 : rows : cols ', ' select ; xxx [ : class ] ' ... )
2017-10-07 13:09:31 +02:00
* @ param string $moreparam More param to add on a href URL .
* @ param int $fieldrequired 1 if we want to show field as mandatory using the " fieldrequired " CSS .
* @ param int $notabletag 1 = Do not output table tags but output a ':' , 2 = Do not output table tags and no ':' , 3 = Do not output table tags but output a ' '
2018-03-13 17:32:49 +01:00
* @ param string $paramid Key of parameter for id ( 'id' , 'socid' )
2019-12-15 17:32:45 +01:00
* @ param string $help Tooltip help
2017-10-07 13:09:31 +02:00
* @ return string HTML edit field
*/
2020-04-18 15:11:38 +02:00
public function editfieldkey ( $text , $htmlname , $preselected , $object , $perm , $typeofdata = 'string' , $moreparam = '' , $fieldrequired = 0 , $notabletag = 0 , $paramid = 'id' , $help = '' )
{
2019-11-08 15:51:54 +01:00
global $conf , $langs ;
2017-10-07 13:09:31 +02:00
2019-11-08 15:51:54 +01:00
$ret = '' ;
2012-02-21 10:47:08 +01:00
2017-10-07 13:09:31 +02:00
// TODO change for compatibility
2021-02-23 22:03:23 +01:00
if ( ! empty ( $conf -> global -> MAIN_USE_JQUERY_JEDITABLE ) && ! preg_match ( '/^select;/' , $typeofdata )) {
if ( ! empty ( $perm )) {
2019-11-08 15:51:54 +01:00
$tmp = explode ( ':' , $typeofdata );
$ret .= '<div class="editkey_' . $tmp [ 0 ] . ( ! empty ( $tmp [ 1 ]) ? ' ' . $tmp [ 1 ] : '' ) . '" id="' . $htmlname . '">' ;
2021-02-23 22:03:23 +01:00
if ( $fieldrequired ) {
$ret .= '<span class="fieldrequired">' ;
}
2019-12-15 17:32:45 +01:00
if ( $help ) {
$ret .= $this -> textwithpicto ( $langs -> trans ( $text ), $help );
} else {
$ret .= $langs -> trans ( $text );
}
2021-02-23 22:03:23 +01:00
if ( $fieldrequired ) {
$ret .= '</span>' ;
}
2019-11-08 15:51:54 +01:00
$ret .= '</div>' . " \n " ;
2020-05-21 15:05:19 +02:00
} else {
2021-02-23 22:03:23 +01:00
if ( $fieldrequired ) {
$ret .= '<span class="fieldrequired">' ;
}
2019-12-15 17:32:45 +01:00
if ( $help ) {
$ret .= $this -> textwithpicto ( $langs -> trans ( $text ), $help );
} else {
$ret .= $langs -> trans ( $text );
}
2021-02-23 22:03:23 +01:00
if ( $fieldrequired ) {
$ret .= '</span>' ;
}
2017-10-07 13:09:31 +02:00
}
2020-05-21 15:05:19 +02:00
} else {
2021-02-23 22:03:23 +01:00
if ( empty ( $notabletag ) && GETPOST ( 'action' , 'aZ09' ) != 'edit' . $htmlname && $perm ) {
$ret .= '<table class="nobordernopadding centpercent"><tr><td class="nowrap">' ;
}
if ( $fieldrequired ) {
$ret .= '<span class="fieldrequired">' ;
}
2019-12-15 17:32:45 +01:00
if ( $help ) {
$ret .= $this -> textwithpicto ( $langs -> trans ( $text ), $help );
} else {
$ret .= $langs -> trans ( $text );
}
2021-02-23 22:03:23 +01:00
if ( $fieldrequired ) {
$ret .= '</span>' ;
}
if ( ! empty ( $notabletag )) {
$ret .= ' ' ;
}
if ( empty ( $notabletag ) && GETPOST ( 'action' , 'aZ09' ) != 'edit' . $htmlname && $perm ) {
$ret .= '</td>' ;
}
if ( empty ( $notabletag ) && GETPOST ( 'action' , 'aZ09' ) != 'edit' . $htmlname && $perm ) {
$ret .= '<td class="right">' ;
}
if ( $htmlname && GETPOST ( 'action' , 'aZ09' ) != 'edit' . $htmlname && $perm ) {
$ret .= '<a class="editfielda" href="' . $_SERVER [ " PHP_SELF " ] . '?action=edit' . $htmlname . '&' . $paramid . '=' . $object -> id . $moreparam . '">' . img_edit ( $langs -> trans ( 'Edit' ), ( $notabletag ? 0 : 1 )) . '</a>' ;
}
if ( ! empty ( $notabletag ) && $notabletag == 1 ) {
$ret .= ' : ' ;
}
if ( ! empty ( $notabletag ) && $notabletag == 3 ) {
$ret .= ' ' ;
}
if ( empty ( $notabletag ) && GETPOST ( 'action' , 'aZ09' ) != 'edit' . $htmlname && $perm ) {
$ret .= '</td>' ;
}
if ( empty ( $notabletag ) && GETPOST ( 'action' , 'aZ09' ) != 'edit' . $htmlname && $perm ) {
$ret .= '</tr></table>' ;
}
2017-10-07 13:09:31 +02:00
}
2012-02-21 10:47:08 +01:00
2017-10-07 13:09:31 +02:00
return $ret ;
2020-04-18 15:11:38 +02:00
}
2013-11-16 14:26:42 +01:00
2017-10-07 13:09:31 +02:00
/**
2017-10-09 14:16:22 +02:00
* Output value of a field for an editable field
2017-10-07 13:09:31 +02:00
*
* @ param string $text Text of label ( not used in this function )
* @ param string $htmlname Name of select field
* @ param string $value Value to show / edit
* @ param object $object Object
* @ param boolean $perm Permission to allow button to edit parameter
2019-07-14 00:10:15 +02:00
* @ param string $typeofdata Type of data ( 'string' by default , 'email' , 'amount:99' , 'numeric:99' , 'text' or 'textarea:rows:cols%' , 'datepicker' ( 'day' do not work , don 't know why), ' dayhour ' or ' datepickerhour ', ' ckeditor : dolibarr_zzz : width : height : savemethod : toolbarstartexpanded : rows : cols ', ' select ; xkey : xval , ykey : yval , ... ' )
2017-10-07 13:09:31 +02:00
* @ param string $editvalue When in edit mode , use this value as $value instead of value ( for example , you can provide here a formated price instead of value ) . Use '' to use same than $value
* @ param object $extObject External object
* @ param mixed $custommsg String or Array of custom messages : eg array ( 'success' => 'MyMessage' , 'error' => 'MyMessage' )
2018-03-15 00:40:29 +01:00
* @ param string $moreparam More param to add on the form action href URL
2017-10-07 13:09:31 +02:00
* @ param int $notabletag Do no output table tags
2017-10-09 14:16:22 +02:00
* @ param string $formatfunc Call a specific function to output field
2018-03-13 17:32:49 +01:00
* @ param string $paramid Key of parameter for id ( 'id' , 'socid' )
2017-10-07 13:09:31 +02:00
* @ return string HTML edit field
*/
2020-04-18 15:11:38 +02:00
public function editfieldval ( $text , $htmlname , $value , $object , $perm , $typeofdata = 'string' , $editvalue = '' , $extObject = null , $custommsg = null , $moreparam = '' , $notabletag = 0 , $formatfunc = '' , $paramid = 'id' )
2017-10-07 13:09:31 +02:00
{
2019-11-08 15:51:54 +01:00
global $conf , $langs , $db ;
2016-08-04 09:21:04 +02:00
2019-11-08 15:51:54 +01:00
$ret = '' ;
2016-03-25 14:49:48 +01:00
2017-10-07 13:09:31 +02:00
// Check parameters
2021-02-23 22:03:23 +01:00
if ( empty ( $typeofdata )) {
return 'ErrorBadParameter' ;
}
2017-10-07 13:09:31 +02:00
// When option to edit inline is activated
2021-02-23 22:03:23 +01:00
if ( ! empty ( $conf -> global -> MAIN_USE_JQUERY_JEDITABLE ) && ! preg_match ( '/^select;|datehourpicker/' , $typeofdata )) { // TODO add jquery timepicker and support select
2019-11-08 15:51:54 +01:00
$ret .= $this -> editInPlace ( $object , $value , $htmlname , $perm , $typeofdata , $editvalue , $extObject , $custommsg );
2020-05-21 15:05:19 +02:00
} else {
2020-11-18 16:23:08 +01:00
$editmode = ( GETPOST ( 'action' , 'aZ09' ) == 'edit' . $htmlname );
2021-02-23 22:03:23 +01:00
if ( $editmode ) {
2019-11-08 15:51:54 +01:00
$ret .= " \n " ;
$ret .= '<form method="post" action="' . $_SERVER [ " PHP_SELF " ] . ( $moreparam ? '?' . $moreparam : '' ) . '">' ;
$ret .= '<input type="hidden" name="action" value="set' . $htmlname . '">' ;
2019-12-01 10:20:11 +01:00
$ret .= '<input type="hidden" name="token" value="' . newToken () . '">' ;
2019-11-08 15:51:54 +01:00
$ret .= '<input type="hidden" name="' . $paramid . '" value="' . $object -> id . '">' ;
2021-02-23 22:03:23 +01:00
if ( empty ( $notabletag )) {
2021-04-30 15:22:17 +02:00
$ret .= '<table class="nobordernopadding centpercent">' ;
2021-02-23 22:03:23 +01:00
}
if ( empty ( $notabletag )) {
$ret .= '<tr><td>' ;
}
if ( preg_match ( '/^(string|safehtmlstring|email)/' , $typeofdata )) {
2019-11-08 15:51:54 +01:00
$tmp = explode ( ':' , $typeofdata );
2020-08-27 21:18:40 +02:00
$ret .= '<input type="text" id="' . $htmlname . '" name="' . $htmlname . '" value="' . ( $editvalue ? $editvalue : $value ) . '"' . ( $tmp [ 1 ] ? ' size="' . $tmp [ 1 ] . '"' : '' ) . ' autofocus>' ;
2021-02-23 22:03:23 +01:00
} elseif ( preg_match ( '/^(numeric|amount)/' , $typeofdata )) {
2019-11-08 15:51:54 +01:00
$tmp = explode ( ':' , $typeofdata );
$valuetoshow = price2num ( $editvalue ? $editvalue : $value );
2020-08-27 21:18:40 +02:00
$ret .= '<input type="text" id="' . $htmlname . '" name="' . $htmlname . '" value="' . ( $valuetoshow != '' ? price ( $valuetoshow ) : '' ) . '"' . ( $tmp [ 1 ] ? ' size="' . $tmp [ 1 ] . '"' : '' ) . ' autofocus>' ;
2021-03-23 21:04:38 +01:00
} elseif ( preg_match ( '/^(checkbox)/' , $typeofdata )) {
$tmp = explode ( ':' , $typeofdata );
$ret .= '<input type="checkbox" id="' . $htmlname . '" name="' . $htmlname . '" value="' . $value . '"' . ( $tmp [ 1 ] ? $tmp [ 1 ] : '' ) . '/>' ;
2021-02-23 22:03:23 +01:00
} elseif ( preg_match ( '/^text/' , $typeofdata ) || preg_match ( '/^note/' , $typeofdata )) { // if wysiwyg is enabled $typeofdata = 'ckeditor'
2019-11-08 15:51:54 +01:00
$tmp = explode ( ':' , $typeofdata );
$cols = $tmp [ 2 ];
$morealt = '' ;
2021-02-23 22:03:23 +01:00
if ( preg_match ( '/%/' , $cols )) {
2019-11-08 15:51:54 +01:00
$morealt = ' style="width: ' . $cols . '"' ;
$cols = '' ;
2017-10-07 13:09:31 +02:00
}
2018-07-09 14:13:01 +02:00
2019-11-08 15:51:54 +01:00
$valuetoshow = ( $editvalue ? $editvalue : $value );
2020-08-27 21:18:40 +02:00
$ret .= '<textarea id="' . $htmlname . '" name="' . $htmlname . '" wrap="soft" rows="' . ( $tmp [ 1 ] ? $tmp [ 1 ] : '20' ) . '"' . ( $cols ? ' cols="' . $cols . '"' : 'class="quatrevingtpercent"' ) . $morealt . '" autofocus>' ;
2020-01-18 19:53:48 +01:00
// textarea convert automatically entities chars into simple chars.
// So we convert & into & so a string like 'a < <b>b</b><br>é<br><script>alert('X');<script>' stay a correct html and is not converted by textarea component when wysiwig is off.
$valuetoshow = str_replace ( '&' , '&' , $valuetoshow );
2019-11-08 15:51:54 +01:00
$ret .= dol_string_neverthesehtmltags ( $valuetoshow , array ( 'textarea' ));
$ret .= '</textarea>' ;
2021-02-23 22:03:23 +01:00
} elseif ( $typeofdata == 'day' || $typeofdata == 'datepicker' ) {
2019-11-08 15:51:54 +01:00
$ret .= $this -> selectDate ( $value , $htmlname , 0 , 0 , 1 , 'form' . $htmlname , 1 , 0 );
2021-02-23 22:03:23 +01:00
} elseif ( $typeofdata == 'dayhour' || $typeofdata == 'datehourpicker' ) {
2019-11-08 15:51:54 +01:00
$ret .= $this -> selectDate ( $value , $htmlname , 1 , 1 , 1 , 'form' . $htmlname , 1 , 0 );
2021-02-23 22:03:23 +01:00
} elseif ( preg_match ( '/^select;/' , $typeofdata )) {
2019-11-08 15:51:54 +01:00
$arraydata = explode ( ',' , preg_replace ( '/^select;/' , '' , $typeofdata ));
2020-04-18 15:11:38 +02:00
$arraylist = array ();
2021-02-23 22:03:23 +01:00
foreach ( $arraydata as $val ) {
2019-11-08 15:51:54 +01:00
$tmp = explode ( ':' , $val );
$tmpkey = str_replace ( '|' , ':' , $tmp [ 0 ]);
$arraylist [ $tmpkey ] = $tmp [ 1 ];
2019-10-27 11:18:36 +01:00
}
2019-11-08 15:51:54 +01:00
$ret .= $this -> selectarray ( $htmlname , $arraylist , $value );
2021-02-23 22:03:23 +01:00
} elseif ( preg_match ( '/^ckeditor/' , $typeofdata )) {
2020-04-18 15:11:38 +02:00
$tmp = explode ( ':' , $typeofdata ); // Example: ckeditor:dolibarr_zzz:width:height:savemethod:toolbarstartexpanded:rows:cols:uselocalbrowser
2017-10-07 13:09:31 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/class/doleditor.class.php' ;
2019-11-08 15:51:54 +01:00
$doleditor = new DolEditor ( $htmlname , ( $editvalue ? $editvalue : $value ), ( $tmp [ 2 ] ? $tmp [ 2 ] : '' ), ( $tmp [ 3 ] ? $tmp [ 3 ] : '100' ), ( $tmp [ 1 ] ? $tmp [ 1 ] : 'dolibarr_notes' ), 'In' , ( $tmp [ 5 ] ? $tmp [ 5 ] : 0 ), ( isset ( $tmp [ 8 ]) ? ( $tmp [ 8 ] ? true : false ) : true ), true , ( $tmp [ 6 ] ? $tmp [ 6 ] : '20' ), ( $tmp [ 7 ] ? $tmp [ 7 ] : '100' ));
$ret .= $doleditor -> Create ( 1 );
2017-10-07 13:09:31 +02:00
}
2021-02-23 22:03:23 +01:00
if ( empty ( $notabletag )) {
$ret .= '</td>' ;
}
2017-10-07 13:09:31 +02:00
2021-02-23 22:03:23 +01:00
if ( empty ( $notabletag )) {
$ret .= '<td class="left">' ;
}
2017-10-07 13:09:31 +02:00
//else $ret.='<div class="clearboth"></div>';
2021-02-15 22:15:14 +01:00
$ret .= '<input type="submit" class="smallpaddingimp button' . ( empty ( $notabletag ) ? '' : ' ' ) . '" name="modify" value="' . $langs -> trans ( " Modify " ) . '">' ;
2021-02-23 22:03:23 +01:00
if ( preg_match ( '/ckeditor|textarea/' , $typeofdata ) && empty ( $notabletag )) {
$ret .= '<br>' . " \n " ;
}
2021-02-15 22:15:14 +01:00
$ret .= '<input type="submit" class="smallpaddingimp button button-cancel' . ( empty ( $notabletag ) ? '' : ' ' ) . '" name="cancel" value="' . $langs -> trans ( " Cancel " ) . '">' ;
2021-02-23 22:03:23 +01:00
if ( empty ( $notabletag )) {
$ret .= '</td>' ;
}
2017-10-07 13:09:31 +02:00
2021-02-23 22:03:23 +01:00
if ( empty ( $notabletag )) {
$ret .= '</tr></table>' . " \n " ;
}
2019-11-08 15:51:54 +01:00
$ret .= '</form>' . " \n " ;
2020-05-21 15:05:19 +02:00
} else {
2021-02-23 22:03:23 +01:00
if ( preg_match ( '/^(email)/' , $typeofdata )) {
$ret .= dol_print_email ( $value , 0 , 0 , 0 , 0 , 1 );
} elseif ( preg_match ( '/^(amount|numeric)/' , $typeofdata )) {
$ret .= ( $value != '' ? price ( $value , '' , $langs , 0 , - 1 , - 1 , $conf -> currency ) : '' );
2021-03-23 21:04:38 +01:00
} elseif ( preg_match ( '/^(checkbox)/' , $typeofdata )) {
$tmp = explode ( ':' , $typeofdata );
$ret .= '<input type="checkbox" disabled id="' . $htmlname . '" name="' . $htmlname . '" value="' . $value . '"' . ( $tmp [ 1 ] ? $tmp [ 1 ] : '' ) . '/>' ;
2021-02-23 22:03:23 +01:00
} elseif ( preg_match ( '/^text/' , $typeofdata ) || preg_match ( '/^note/' , $typeofdata )) {
$ret .= dol_htmlentitiesbr ( $value );
} elseif ( preg_match ( '/^safehtmlstring/' , $typeofdata )) {
$ret .= dol_string_onlythesehtmltags ( $value );
} elseif ( preg_match ( '/^restricthtml/' , $typeofdata )) {
$ret .= dol_string_onlythesehtmltags ( $value );
} elseif ( $typeofdata == 'day' || $typeofdata == 'datepicker' ) {
$ret .= '<span class="valuedate">' . dol_print_date ( $value , 'day' ) . '</span>' ;
} elseif ( $typeofdata == 'dayhour' || $typeofdata == 'datehourpicker' ) {
$ret .= '<span class="valuedate">' . dol_print_date ( $value , 'dayhour' ) . '</span>' ;
} elseif ( preg_match ( '/^select;/' , $typeofdata )) {
2019-11-08 15:51:54 +01:00
$arraydata = explode ( ',' , preg_replace ( '/^select;/' , '' , $typeofdata ));
2020-04-18 15:11:38 +02:00
$arraylist = array ();
2021-02-23 22:03:23 +01:00
foreach ( $arraydata as $val ) {
2019-11-08 15:51:54 +01:00
$tmp = explode ( ':' , $val );
$arraylist [ $tmp [ 0 ]] = $tmp [ 1 ];
2017-10-07 13:09:31 +02:00
}
2019-11-08 15:51:54 +01:00
$ret .= $arraylist [ $value ];
2021-02-26 11:00:58 +01:00
if ( $htmlname == 'fk_product_type' ) {
if ( $value == 0 ) {
$ret = img_picto ( $langs -> trans ( " Product " ), 'product' , 'class="paddingleftonly paddingrightonly colorgrey"' ) . $ret ;
} else {
$ret = img_picto ( $langs -> trans ( " Service " ), 'service' , 'class="paddingleftonly paddingrightonly colorgrey"' ) . $ret ;
}
}
2021-02-23 22:03:23 +01:00
} elseif ( preg_match ( '/^ckeditor/' , $typeofdata )) {
2019-11-08 15:51:54 +01:00
$tmpcontent = dol_htmlentitiesbr ( $value );
2021-02-23 22:03:23 +01:00
if ( ! empty ( $conf -> global -> MAIN_DISABLE_NOTES_TAB )) {
2019-11-08 15:51:54 +01:00
$firstline = preg_replace ( '/<br>.*/' , '' , $tmpcontent );
$firstline = preg_replace ( '/[\n\r].*/' , '' , $firstline );
$tmpcontent = $firstline . (( strlen ( $firstline ) != strlen ( $tmpcontent )) ? '...' : '' );
2017-10-07 13:09:31 +02:00
}
2020-02-09 18:28:34 +01:00
// We dont use dol_escape_htmltag to get the html formating active, but this need we must also
// clean data from some dangerous html
$ret .= dol_string_onlythesehtmltags ( dol_htmlentitiesbr ( $tmpcontent ));
2020-05-21 15:05:19 +02:00
} else {
2020-02-09 18:28:34 +01:00
$ret .= dol_escape_htmltag ( $value );
2017-10-07 13:09:31 +02:00
}
2012-02-21 10:47:08 +01:00
2021-02-23 22:03:23 +01:00
if ( $formatfunc && method_exists ( $object , $formatfunc )) {
2019-11-08 15:51:54 +01:00
$ret = $object -> $formatfunc ( $ret );
2017-10-09 14:16:22 +02:00
}
2017-10-07 13:09:31 +02:00
}
}
return $ret ;
}
2012-02-21 10:47:08 +01:00
2020-03-22 19:11:21 +01:00
/**
* Output edit in place form
*
* @ param string $fieldname Name of the field
* @ param object $object Object
* @ param boolean $perm Permission to allow button to edit parameter . Set it to 0 to have a not edited field .
* @ param string $typeofdata Type of data ( 'string' by default , 'email' , 'amount:99' , 'numeric:99' , 'text' or 'textarea:rows:cols' , 'datepicker' ( 'day' do not work , don 't know why), ' ckeditor : dolibarr_zzz : width : height : savemethod : 1 : rows : cols ', ' select ; xxx [ : class ] ' ... )
2020-03-27 16:02:58 +01:00
* @ param string $check Same coe than $check parameter of GETPOST ()
* @ param string $morecss More CSS
2020-03-22 19:11:21 +01:00
* @ return string HTML code for the edit of alternative language
*/
2020-03-27 16:02:58 +01:00
public function widgetForTranslation ( $fieldname , $object , $perm , $typeofdata = 'string' , $check = '' , $morecss = '' )
2020-03-22 19:40:58 +01:00
{
2020-04-01 23:15:53 +02:00
global $conf , $langs , $extralanguages ;
2020-03-22 19:11:21 +01:00
$result = '' ;
2020-04-01 23:15:53 +02:00
// List of extra languages
$arrayoflangcode = array ();
2021-02-23 22:03:23 +01:00
if ( ! empty ( $conf -> global -> PDF_USE_ALSO_LANGUAGE_CODE )) {
$arrayoflangcode [] = $conf -> global -> PDF_USE_ALSO_LANGUAGE_CODE ;
}
2020-04-01 23:15:53 +02:00
if ( is_array ( $arrayoflangcode ) && count ( $arrayoflangcode )) {
2020-04-10 10:59:32 +02:00
if ( ! is_object ( $extralanguages )) {
2020-04-01 23:15:53 +02:00
include_once DOL_DOCUMENT_ROOT . '/core/class/extralanguages.class.php' ;
$extralanguages = new ExtraLanguages ( $this -> db );
}
$extralanguages -> fetch_name_extralanguages ( 'societe' );
2020-04-10 10:59:32 +02:00
if ( ! is_array ( $extralanguages -> attributes [ $object -> element ]) || empty ( $extralanguages -> attributes [ $object -> element ][ $fieldname ])) {
return '' ; // No extralang field to show
2020-04-01 23:15:53 +02:00
}
2020-03-22 19:11:21 +01:00
2020-04-21 14:54:30 +02:00
$result .= '<!-- Widget for translation -->' . " \n " ;
2020-04-10 10:59:32 +02:00
$result .= '<div class="inline-block paddingleft image-' . $object -> element . '-' . $fieldname . '">' ;
$s = img_picto ( $langs -> trans ( " ShowOtherLanguages " ), 'language' , '' , false , 0 , 0 , '' , 'fa-15 editfieldlang' );
2020-03-22 19:11:21 +01:00
$result .= $s ;
2020-03-27 16:02:58 +01:00
$result .= '</div>' ;
2020-04-10 10:59:32 +02:00
$result .= '<div class="inline-block hidden field-' . $object -> element . '-' . $fieldname . '">' ;
2020-03-27 16:02:58 +01:00
2020-04-01 23:15:53 +02:00
$resultforextrlang = '' ;
2021-02-23 22:03:23 +01:00
foreach ( $arrayoflangcode as $langcode ) {
2020-04-01 23:15:53 +02:00
$valuetoshow = GETPOSTISSET ( 'field-' . $object -> element . " - " . $fieldname . " - " . $langcode ) ? GETPOST ( 'field-' . $object -> element . '-' . $fieldname . " - " . $langcode , $check ) : '' ;
if ( empty ( $valuetoshow )) {
$object -> fetchValuesForExtraLanguages ();
//var_dump($object->array_languages);
$valuetoshow = $object -> array_languages [ $fieldname ][ $langcode ];
}
2020-03-22 19:11:21 +01:00
2020-04-10 10:59:32 +02:00
$s = picto_from_langcode ( $langcode , 'class="pictoforlang paddingright"' );
2020-04-01 23:15:53 +02:00
$resultforextrlang .= $s ;
2020-05-21 13:06:36 +02:00
// TODO Use the showInputField() method of ExtraLanguages object
2020-04-01 23:15:53 +02:00
if ( $typeofdata == 'textarea' ) {
$resultforextrlang .= '<textarea name="field-' . $object -> element . " - " . $fieldname . " - " . $langcode . '" id="' . $fieldname . " - " . $langcode . '" class="' . $morecss . '" rows="' . ROWS_2 . '" wrap="soft">' ;
$resultforextrlang .= $valuetoshow ;
$resultforextrlang .= '</textarea>' ;
} else {
$resultforextrlang .= '<input type="text" class="inputfieldforlang ' . ( $morecss ? ' ' . $morecss : '' ) . '" name="field-' . $object -> element . '-' . $fieldname . '-' . $langcode . '" value="' . $valuetoshow . '">' ;
}
2020-03-27 16:02:58 +01:00
}
2020-04-01 23:15:53 +02:00
$result .= $resultforextrlang ;
2020-03-22 19:11:21 +01:00
$result .= '</div>' ;
2020-03-27 16:02:58 +01:00
$result .= '<script>$(".image-' . $object -> element . '-' . $fieldname . '").click(function() { console.log("Toggle lang widget"); jQuery(".field-' . $object -> element . '-' . $fieldname . '").toggle(); });</script>' ;
2020-03-22 19:11:21 +01:00
}
return $result ;
}
2017-10-07 13:09:31 +02:00
/**
* Output edit in place form
*
* @ param object $object Object
* @ param string $value Value to show / edit
* @ param string $htmlname DIV ID ( field name )
* @ param int $condition Condition to edit
2019-07-14 00:10:15 +02:00
* @ param string $inputType Type of input ( 'string' , 'numeric' , 'datepicker' ( 'day' do not work , don 't know why), ' textarea : rows : cols ', ' ckeditor : dolibarr_zzz : width : height : ? : 1 : rows : cols ', ' select : loadmethod : savemethod : buttononly ' )
2017-10-07 13:09:31 +02:00
* @ param string $editvalue When in edit mode , use this value as $value instead of value
* @ param object $extObject External object
* @ param mixed $custommsg String or Array of custom messages : eg array ( 'success' => 'MyMessage' , 'error' => 'MyMessage' )
* @ return string HTML edit in place
*/
2019-08-02 12:31:24 +02:00
protected function editInPlace ( $object , $value , $htmlname , $condition , $inputType = 'textarea' , $editvalue = null , $extObject = null , $custommsg = null )
2017-10-07 13:09:31 +02:00
{
global $conf ;
2012-02-21 10:47:08 +01:00
2019-11-08 15:51:54 +01:00
$out = '' ;
2012-02-21 10:47:08 +01:00
2017-10-07 13:09:31 +02:00
// Check parameters
2021-02-23 22:03:23 +01:00
if ( preg_match ( '/^text/' , $inputType )) {
$value = dol_nl2br ( $value );
} elseif ( preg_match ( '/^numeric/' , $inputType )) {
$value = price ( $value );
} elseif ( $inputType == 'day' || $inputType == 'datepicker' ) {
$value = dol_print_date ( $value , 'day' );
}
2012-02-21 10:47:08 +01:00
2021-02-23 22:03:23 +01:00
if ( $condition ) {
2019-11-08 15:51:54 +01:00
$element = false ;
$table_element = false ;
2017-10-07 13:09:31 +02:00
$fk_element = false ;
$loadmethod = false ;
$savemethod = false ;
$ext_element = false ;
$button_only = false ;
2019-11-08 15:51:54 +01:00
$inputOption = '' ;
2017-10-07 13:09:31 +02:00
2021-02-23 22:03:23 +01:00
if ( is_object ( $object )) {
2017-10-07 13:09:31 +02:00
$element = $object -> element ;
$table_element = $object -> table_element ;
$fk_element = $object -> id ;
}
2021-02-23 22:03:23 +01:00
if ( is_object ( $extObject )) {
2017-10-07 13:09:31 +02:00
$ext_element = $extObject -> element ;
}
2021-02-23 22:03:23 +01:00
if ( preg_match ( '/^(string|email|numeric)/' , $inputType )) {
2019-11-08 15:51:54 +01:00
$tmp = explode ( ':' , $inputType );
$inputType = $tmp [ 0 ];
2021-02-23 22:03:23 +01:00
if ( ! empty ( $tmp [ 1 ])) {
$inputOption = $tmp [ 1 ];
}
if ( ! empty ( $tmp [ 2 ])) {
$savemethod = $tmp [ 2 ];
}
2019-11-08 15:51:54 +01:00
$out .= '<input id="width_' . $htmlname . '" value="' . $inputOption . '" type="hidden"/>' . " \n " ;
2021-02-23 22:03:23 +01:00
} elseif (( preg_match ( '/^day$/' , $inputType )) || ( preg_match ( '/^datepicker/' , $inputType )) || ( preg_match ( '/^datehourpicker/' , $inputType ))) {
2019-11-08 15:51:54 +01:00
$tmp = explode ( ':' , $inputType );
$inputType = $tmp [ 0 ];
2021-02-23 22:03:23 +01:00
if ( ! empty ( $tmp [ 1 ])) {
$inputOption = $tmp [ 1 ];
}
if ( ! empty ( $tmp [ 2 ])) {
$savemethod = $tmp [ 2 ];
}
2012-02-21 10:47:08 +01:00
2019-11-08 15:51:54 +01:00
$out .= '<input id="timestamp" type="hidden"/>' . " \n " ; // Use for timestamp format
2021-02-23 22:03:23 +01:00
} elseif ( preg_match ( '/^(select|autocomplete)/' , $inputType )) {
2019-11-08 15:51:54 +01:00
$tmp = explode ( ':' , $inputType );
2021-03-01 20:37:16 +01:00
$inputType = $tmp [ 0 ];
$loadmethod = $tmp [ 1 ];
2021-02-23 22:03:23 +01:00
if ( ! empty ( $tmp [ 2 ])) {
$savemethod = $tmp [ 2 ];
}
if ( ! empty ( $tmp [ 3 ])) {
$button_only = true ;
}
} elseif ( preg_match ( '/^textarea/' , $inputType )) {
2019-11-08 15:51:54 +01:00
$tmp = explode ( ':' , $inputType );
$inputType = $tmp [ 0 ];
$rows = ( empty ( $tmp [ 1 ]) ? '8' : $tmp [ 1 ]);
$cols = ( empty ( $tmp [ 2 ]) ? '80' : $tmp [ 2 ]);
2021-02-23 22:03:23 +01:00
} elseif ( preg_match ( '/^ckeditor/' , $inputType )) {
2019-11-08 15:51:54 +01:00
$tmp = explode ( ':' , $inputType );
2021-03-01 20:37:16 +01:00
$inputType = $tmp [ 0 ];
$toolbar = $tmp [ 1 ];
2021-02-23 22:03:23 +01:00
if ( ! empty ( $tmp [ 2 ])) {
$width = $tmp [ 2 ];
}
if ( ! empty ( $tmp [ 3 ])) {
$heigth = $tmp [ 3 ];
}
if ( ! empty ( $tmp [ 4 ])) {
$savemethod = $tmp [ 4 ];
}
2012-02-21 10:47:08 +01:00
2021-02-23 22:03:23 +01:00
if ( ! empty ( $conf -> fckeditor -> enabled )) {
2019-11-08 15:51:54 +01:00
$out .= '<input id="ckeditor_toolbar" value="' . $toolbar . '" type="hidden"/>' . " \n " ;
2020-05-21 15:05:19 +02:00
} else {
2017-10-07 13:09:31 +02:00
$inputType = 'textarea' ;
}
}
2012-02-21 10:47:08 +01:00
2019-11-08 15:51:54 +01:00
$out .= '<input id="element_' . $htmlname . '" value="' . $element . '" type="hidden"/>' . " \n " ;
$out .= '<input id="table_element_' . $htmlname . '" value="' . $table_element . '" type="hidden"/>' . " \n " ;
$out .= '<input id="fk_element_' . $htmlname . '" value="' . $fk_element . '" type="hidden"/>' . " \n " ;
$out .= '<input id="loadmethod_' . $htmlname . '" value="' . $loadmethod . '" type="hidden"/>' . " \n " ;
2021-02-23 22:03:23 +01:00
if ( ! empty ( $savemethod )) {
$out .= '<input id="savemethod_' . $htmlname . '" value="' . $savemethod . '" type="hidden"/>' . " \n " ;
}
if ( ! empty ( $ext_element )) {
$out .= '<input id="ext_element_' . $htmlname . '" value="' . $ext_element . '" type="hidden"/>' . " \n " ;
}
if ( ! empty ( $custommsg )) {
if ( is_array ( $custommsg )) {
if ( ! empty ( $custommsg [ 'success' ])) {
2019-11-08 15:51:54 +01:00
$out .= '<input id="successmsg_' . $htmlname . '" value="' . $custommsg [ 'success' ] . '" type="hidden"/>' . " \n " ;
2021-02-23 22:03:23 +01:00
}
if ( ! empty ( $custommsg [ 'error' ])) {
$out .= '<input id="errormsg_' . $htmlname . '" value="' . $custommsg [ 'error' ] . '" type="hidden"/>' . " \n " ;
}
} else {
$out .= '<input id="successmsg_' . $htmlname . '" value="' . $custommsg . '" type="hidden"/>' . " \n " ;
}
2017-10-07 13:09:31 +02:00
}
if ( $inputType == 'textarea' ) {
2019-11-08 15:51:54 +01:00
$out .= '<input id="textarea_' . $htmlname . '_rows" value="' . $rows . '" type="hidden"/>' . " \n " ;
$out .= '<input id="textarea_' . $htmlname . '_cols" value="' . $cols . '" type="hidden"/>' . " \n " ;
2017-10-07 13:09:31 +02:00
}
2019-11-08 15:51:54 +01:00
$out .= '<span id="viewval_' . $htmlname . '" class="viewval_' . $inputType . ( $button_only ? ' inactive' : ' active' ) . '">' . $value . '</span>' . " \n " ;
$out .= '<span id="editval_' . $htmlname . '" class="editval_' . $inputType . ( $button_only ? ' inactive' : ' active' ) . ' hideobject">' . ( ! empty ( $editvalue ) ? $editvalue : $value ) . '</span>' . " \n " ;
2020-05-21 15:05:19 +02:00
} else {
2017-10-07 13:09:31 +02:00
$out = $value ;
}
2012-02-21 10:47:08 +01:00
2017-10-07 13:09:31 +02:00
return $out ;
}
/**
* Show a text and picto with tooltip on text or picto .
* Can be called by an instancied $form -> textwithtooltip or by a static call Form :: textwithtooltip
*
* @ param string $text Text to show
* @ param string $htmltext HTML content of tooltip . Must be HTML / UTF8 encoded .
* @ param int $tooltipon 1 = tooltip on text , 2 = tooltip on image , 3 = tooltip sur les 2
* @ param int $direction - 1 = image is before , 0 = no image , 1 = image is after
* @ param string $img Html code for image ( use img_xxx () function to get it )
* @ param string $extracss Add a CSS style to td tags
* @ param int $notabs 0 = Include table and tr tags , 1 = Do not include table and tr tags , 2 = use div , 3 = use span
* @ param string $incbefore Include code before the text
* @ param int $noencodehtmltext Do not encode into html entity the htmltext
2017-11-19 12:41:37 +01:00
* @ param string $tooltiptrigger '' = Tooltip on hover , 'abc' = Tooltip on click ( abc is a unique key )
* @ param int $forcenowrap Force no wrap between text and picto ( works with notabs = 2 only )
2017-10-07 13:09:31 +02:00
* @ return string Code html du tooltip ( texte + picto )
2019-03-19 13:14:44 +01:00
* @ see textwithpicto () Use thisfunction if you can .
2017-10-07 13:09:31 +02:00
*/
2020-04-18 15:11:38 +02:00
public function textwithtooltip ( $text , $htmltext , $tooltipon = 1 , $direction = 0 , $img = '' , $extracss = '' , $notabs = 3 , $incbefore = '' , $noencodehtmltext = 0 , $tooltiptrigger = '' , $forcenowrap = 0 )
2017-10-07 13:09:31 +02:00
{
2021-02-23 22:03:23 +01:00
if ( $incbefore ) {
$text = $incbefore . $text ;
}
if ( ! $htmltext ) {
return $text ;
}
2012-02-21 10:47:08 +01:00
2019-11-08 15:51:54 +01:00
$tag = 'td' ;
2021-02-23 22:03:23 +01:00
if ( $notabs == 2 ) {
$tag = 'div' ;
}
if ( $notabs == 3 ) {
$tag = 'span' ;
}
2017-10-07 13:09:31 +02:00
// Sanitize tooltip
2020-02-15 10:56:44 +01:00
$htmltext = str_replace ( array ( " \r " , " \n " ), '' , $htmltext );
2012-02-21 10:47:08 +01:00
2019-11-08 15:51:54 +01:00
$extrastyle = '' ;
2021-02-23 22:03:23 +01:00
if ( $direction < 0 ) {
2021-03-01 20:37:16 +01:00
$extracss = ( $extracss ? $extracss . ' ' : '' ) . ( $notabs != 3 ? 'inline-block' : '' );
$extrastyle = 'padding: 0px; padding-left: 3px !important;' ;
2021-02-23 22:03:23 +01:00
}
if ( $direction > 0 ) {
2021-03-01 20:37:16 +01:00
$extracss = ( $extracss ? $extracss . ' ' : '' ) . ( $notabs != 3 ? 'inline-block' : '' );
$extrastyle = 'padding: 0px; padding-right: 3px !important;' ;
2021-02-23 22:03:23 +01:00
}
2015-06-04 10:42:12 +02:00
2019-11-08 15:51:54 +01:00
$classfortooltip = 'classfortooltip' ;
2017-05-25 08:48:59 +02:00
2021-03-01 20:37:16 +01:00
$s = '' ;
$textfordialog = '' ;
2017-05-25 08:48:59 +02:00
2021-02-23 22:03:23 +01:00
if ( $tooltiptrigger == '' ) {
2020-02-15 10:56:44 +01:00
$htmltext = str_replace ( '"' , '"' , $htmltext );
2020-05-21 15:05:19 +02:00
} else {
2019-11-08 15:51:54 +01:00
$classfortooltip = 'classfortooltiponclick' ;
$textfordialog .= '<div style="display: none;" id="idfortooltiponclick_' . $tooltiptrigger . '" class="classfortooltiponclicktext">' . $htmltext . '</div>' ;
2017-10-07 13:09:31 +02:00
}
2021-02-23 22:03:23 +01:00
if ( $tooltipon == 2 || $tooltipon == 3 ) {
2019-11-08 15:51:54 +01:00
$paramfortooltipimg = ' class="' . $classfortooltip . ( $notabs != 3 ? ' inline-block' : '' ) . ( $extracss ? ' ' . $extracss : '' ) . '" style="padding: 0px;' . ( $extrastyle ? ' ' . $extrastyle : '' ) . '"' ;
2021-02-23 22:03:23 +01:00
if ( $tooltiptrigger == '' ) {
$paramfortooltipimg .= ' title="' . ( $noencodehtmltext ? $htmltext : dol_escape_htmltag ( $htmltext , 1 )) . '"' ; // Attribut to put on img tag to store tooltip
} else {
$paramfortooltipimg .= ' dolid="' . $tooltiptrigger . '"' ;
}
} else {
$paramfortooltipimg = ( $extracss ? ' class="' . $extracss . '"' : '' ) . ( $extrastyle ? ' style="' . $extrastyle . '"' : '' ); // Attribut to put on td text tag
}
if ( $tooltipon == 1 || $tooltipon == 3 ) {
2019-11-08 15:51:54 +01:00
$paramfortooltiptd = ' class="' . ( $tooltipon == 3 ? 'cursorpointer ' : '' ) . $classfortooltip . ' inline-block' . ( $extracss ? ' ' . $extracss : '' ) . '" style="padding: 0px;' . ( $extrastyle ? ' ' . $extrastyle : '' ) . '" ' ;
2021-02-23 22:03:23 +01:00
if ( $tooltiptrigger == '' ) {
$paramfortooltiptd .= ' title="' . ( $noencodehtmltext ? $htmltext : dol_escape_htmltag ( $htmltext , 1 )) . '"' ; // Attribut to put on td tag to store tooltip
} else {
$paramfortooltiptd .= ' dolid="' . $tooltiptrigger . '"' ;
}
} else {
$paramfortooltiptd = ( $extracss ? ' class="' . $extracss . '"' : '' ) . ( $extrastyle ? ' style="' . $extrastyle . '"' : '' ); // Attribut to put on td text tag
}
if ( empty ( $notabs )) {
$s .= '<table class="nobordernopadding"><tr style="height: auto;">' ;
} elseif ( $notabs == 2 ) {
$s .= '<div class="inline-block' . ( $forcenowrap ? ' nowrap' : '' ) . '">' ;
}
2017-10-07 13:09:31 +02:00
// Define value if value is before
if ( $direction < 0 ) {
2019-11-08 15:51:54 +01:00
$s .= '<' . $tag . $paramfortooltipimg ;
2017-10-07 13:09:31 +02:00
if ( $tag == 'td' ) {
2019-01-20 23:36:39 +01:00
$s .= ' class=valigntop" width="14"' ;
2017-10-07 13:09:31 +02:00
}
2019-11-08 15:51:54 +01:00
$s .= '>' . $textfordialog . $img . '</' . $tag . '>' ;
2017-10-07 13:09:31 +02:00
}
// Use another method to help avoid having a space in value in order to use this value with jquery
// Define label
2021-02-23 22:03:23 +01:00
if (( string ) $text != '' ) {
$s .= '<' . $tag . $paramfortooltiptd . '>' . $text . '</' . $tag . '>' ;
}
2017-10-07 13:09:31 +02:00
// Define value if value is after
if ( $direction > 0 ) {
2019-11-08 15:51:54 +01:00
$s .= '<' . $tag . $paramfortooltipimg ;
2021-02-23 22:03:23 +01:00
if ( $tag == 'td' ) {
$s .= ' class="valignmiddle" width="14"' ;
}
2019-11-08 15:51:54 +01:00
$s .= '>' . $textfordialog . $img . '</' . $tag . '>' ;
2017-10-07 13:09:31 +02:00
}
2021-02-23 22:03:23 +01:00
if ( empty ( $notabs )) {
$s .= '</tr></table>' ;
} elseif ( $notabs == 2 ) {
$s .= '</div>' ;
}
2012-02-21 10:47:08 +01:00
2017-10-07 13:09:31 +02:00
return $s ;
}
2010-08-22 17:46:34 +02:00
2017-10-07 13:09:31 +02:00
/**
* Show a text with a picto and a tooltip on picto
*
* @ param string $text Text to show
* @ param string $htmltext Content of tooltip
* @ param int $direction 1 = Icon is after text , - 1 = Icon is before text , 0 = no icon
2019-10-02 15:54:42 +02:00
* @ param string $type Type of picto ( 'info' , 'infoclickable' , 'help' , 'helpclickable' , 'warning' , 'superadmin' , 'mypicto@mymodule' , ... ) or image filepath or 'none'
2017-10-07 13:09:31 +02:00
* @ param string $extracss Add a CSS style to td , div or span tag
* @ param int $noencodehtmltext Do not encode into html entity the htmltext
* @ param int $notabs 0 = Include table and tr tags , 1 = Do not include table and tr tags , 2 = use div , 3 = use span
2019-10-02 15:54:42 +02:00
* @ param string $tooltiptrigger '' = Tooltip on hover , 'abc' = Tooltip on click ( abc is a unique key , clickable link is on image or on link if param $type = 'none' or on both if $type = 'xxxclickable' )
2017-11-19 12:41:37 +01:00
* @ param int $forcenowrap Force no wrap between text and picto ( works with notabs = 2 only )
2017-10-07 13:09:31 +02:00
* @ return string HTML code of text , picto , tooltip
*/
2020-04-18 15:11:38 +02:00
public function textwithpicto ( $text , $htmltext , $direction = 1 , $type = 'help' , $extracss = '' , $noencodehtmltext = 0 , $notabs = 3 , $tooltiptrigger = '' , $forcenowrap = 0 )
2017-10-07 13:09:31 +02:00
{
global $conf , $langs ;
2010-08-22 17:46:34 +02:00
2017-10-07 13:09:31 +02:00
$alt = '' ;
2021-02-23 22:03:23 +01:00
if ( $tooltiptrigger ) {
$alt = $langs -> transnoentitiesnoconv ( " ClickToShowHelp " );
}
2017-05-25 08:48:59 +02:00
2017-10-07 13:09:31 +02:00
//For backwards compatibility
2021-02-23 22:03:23 +01:00
if ( $type == '0' ) {
$type = 'info' ;
} elseif ( $type == '1' ) {
$type = 'help' ;
}
2010-08-22 17:46:34 +02:00
2017-10-07 13:09:31 +02:00
// If info or help with no javascript, show only text
2021-02-23 22:03:23 +01:00
if ( empty ( $conf -> use_javascript_ajax )) {
if ( $type == 'info' || $type == 'infoclickable' || $type == 'help' || $type == 'helpclickable' ) {
return $text ;
} else {
2017-10-07 13:09:31 +02:00
$alt = $htmltext ;
$htmltext = '' ;
}
}
2013-04-03 15:20:56 +02:00
2018-01-12 20:50:18 +01:00
// If info or help with smartphone, show only text (tooltip hover can't works)
2021-02-23 22:03:23 +01:00
if ( ! empty ( $conf -> dol_no_mouse_hover ) && empty ( $tooltiptrigger )) {
if ( $type == 'info' || $type == 'infoclickable' || $type == 'help' || $type == 'helpclickable' ) {
return $text ;
}
2018-01-12 20:50:18 +01:00
}
2019-03-09 18:37:07 +01:00
// If info or help with smartphone, show only text (tooltip on click does not works with dialog on smaprtphone)
//if (! empty($conf->dol_no_mouse_hover) && ! empty($tooltiptrigger))
//{
2020-04-18 15:11:38 +02:00
//if ($type == 'info' || $type == 'help') return '<a href="'..'">'.$text.''</a>';
2019-03-09 18:37:07 +01:00
//}
2012-08-05 14:37:45 +02:00
2019-11-08 15:51:54 +01:00
$img = '' ;
2021-02-23 22:03:23 +01:00
if ( $type == 'info' ) {
$img = img_help ( 0 , $alt );
} elseif ( $type == 'help' ) {
$img = img_help (( $tooltiptrigger != '' ? 2 : 1 ), $alt );
} elseif ( $type == 'helpclickable' ) {
$img = img_help (( $tooltiptrigger != '' ? 2 : 1 ), $alt );
} elseif ( $type == 'superadmin' ) {
$img = img_picto ( $alt , 'redstar' );
} elseif ( $type == 'admin' ) {
$img = img_picto ( $alt , 'star' );
} elseif ( $type == 'warning' ) {
$img = img_warning ( $alt );
} elseif ( $type != 'none' ) {
$img = img_picto ( $alt , $type ); // $type can be an image path
}
2012-07-30 22:36:43 +02:00
2019-11-08 15:51:54 +01:00
return $this -> textwithtooltip ( $text , $htmltext , ((( $tooltiptrigger && ! $img ) || strpos ( $type , 'clickable' )) ? 3 : 2 ), $direction , $img , $extracss , $notabs , '' , $noencodehtmltext , $tooltiptrigger , $forcenowrap );
2017-10-07 13:09:31 +02:00
}
2010-09-02 21:31:18 +02:00
2017-10-07 13:09:31 +02:00
/**
* Generate select HTML to choose massaction
*
* @ param string $selected Value auto selected when at least one record is selected . Not a preselected value . Use '0' by default .
2020-11-29 15:16:53 +01:00
* @ param array $arrayofaction array ( 'code' => 'label' , ... ) . The code is the key stored into the GETPOST ( 'massaction' ) when submitting action .
2017-10-07 13:09:31 +02:00
* @ param int $alwaysvisible 1 = select button always visible
2020-11-29 15:16:53 +01:00
* @ param string $name Name for massaction
* @ param string $cssclass CSS class used to check for select
* @ return string | void Select list
2017-10-07 13:09:31 +02:00
*/
2020-05-02 06:42:12 +02:00
public function selectMassAction ( $selected , $arrayofaction , $alwaysvisible = 0 , $name = 'massaction' , $cssclass = 'checkforselect' )
2017-10-07 13:09:31 +02:00
{
2019-11-08 15:51:54 +01:00
global $conf , $langs , $hookmanager ;
2017-10-07 13:09:31 +02:00
2019-11-08 15:51:54 +01:00
$disabled = 0 ;
$ret = '<div class="centpercent center">' ;
2020-10-01 18:08:46 +02:00
$ret .= '<select class="flat' . ( empty ( $conf -> use_javascript_ajax ) ? '' : ' hideobject' ) . ' ' . $name . ' ' . $name . 'select valignmiddle alignstart" id="' . $name . '" name="' . $name . '"' . ( $disabled ? ' disabled="disabled"' : '' ) . '>' ;
2017-10-07 13:09:31 +02:00
// Complete list with data from external modules. THe module can use $_SERVER['PHP_SELF'] to know on which page we are, or use the $parameters['currentcontext'] completed by executeHooks.
2019-11-08 15:51:54 +01:00
$parameters = array ();
$reshook = $hookmanager -> executeHooks ( 'addMoreMassActions' , $parameters ); // Note that $action and $object may have been modified by hook
2020-01-07 21:41:36 +01:00
// check if there is a mass action
2021-02-23 22:03:23 +01:00
if ( count ( $arrayofaction ) == 0 && empty ( $hookmanager -> resPrint )) {
return ;
}
if ( empty ( $reshook )) {
2019-11-08 15:51:54 +01:00
$ret .= '<option value="0"' . ( $disabled ? ' disabled="disabled"' : '' ) . '>-- ' . $langs -> trans ( " SelectAction " ) . ' --</option>' ;
2021-02-23 22:03:23 +01:00
foreach ( $arrayofaction as $code => $label ) {
2019-11-08 15:51:54 +01:00
$ret .= '<option value="' . $code . '"' . ( $disabled ? ' disabled="disabled"' : '' ) . ' data-html="' . dol_escape_htmltag ( $label ) . '">' . $label . '</option>' ;
2017-10-07 13:09:31 +02:00
}
}
2019-11-08 15:51:54 +01:00
$ret .= $hookmanager -> resPrint ;
2017-06-02 23:02:48 +02:00
2019-11-08 15:51:54 +01:00
$ret .= '</select>' ;
2019-04-13 10:29:09 +02:00
2021-02-23 22:03:23 +01:00
if ( empty ( $conf -> dol_optimize_smallscreen )) {
$ret .= ajax_combobox ( '.' . $name . 'select' );
}
2019-04-13 10:29:09 +02:00
2017-11-27 17:12:48 +01:00
// Warning: if you set submit button to disabled, post using 'Enter' will no more work if there is no another input submit. So we add a hidden button
2019-11-08 15:51:54 +01:00
$ret .= '<input type="submit" name="confirmmassactioninvisible" style="display: none" tabindex="-1">' ; // Hidden button BEFORE so it is the one used when we submit with ENTER.
2021-02-18 15:58:38 +01:00
$ret .= '<input type="submit" disabled name="confirmmassaction"' . ( empty ( $conf -> use_javascript_ajax ) ? '' : ' style="display: none"' ) . ' class="button' . ( empty ( $conf -> use_javascript_ajax ) ? '' : ' hideobject' ) . ' ' . $name . ' ' . $name . 'confirmed" value="' . dol_escape_htmltag ( $langs -> trans ( " Confirm " )) . '">' ;
2019-11-08 15:51:54 +01:00
$ret .= '</div>' ;
2016-08-04 09:21:04 +02:00
2021-02-23 22:03:23 +01:00
if ( ! empty ( $conf -> use_javascript_ajax )) {
2019-11-08 15:51:54 +01:00
$ret .= ' <!-- JS CODE TO ENABLE mass action select -->
2019-01-20 23:36:39 +01:00
< script >
2020-05-02 06:53:11 +02:00
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 */
2016-11-17 19:04:10 +01:00
{
atleastoneselected = 0 ;
2020-05-02 06:42:12 +02:00
jQuery ( " . " + cssclass ) . each ( function ( index ) {
2016-11-17 19:04:10 +01:00
/* console.log( index + ": " + $( this ).text() ); */
if ( $ ( this ) . is ( \ ' : checked\ ' )) atleastoneselected ++ ;
});
2020-03-26 00:52:05 +01:00
2020-05-02 06:42:12 +02:00
console . log ( " initCheckForSelect mode= " + mode + " name= " + name + " cssclass= " + cssclass + " atleastoneselected= " + atleastoneselected );
2020-03-26 00:52:05 +01:00
2016-11-17 19:04:10 +01:00
if ( atleastoneselected || '.$alwaysvisible.' )
{
2020-05-02 06:42:12 +02:00
jQuery ( " . " + name ) . show ();
'.($selected ? ' if ( atleastoneselected ) { jQuery ( " . " + name + " select " ) . val ( " '. $selected .' " ) . trigger ( \ 'change\'); jQuery("."+name+"confirmed").prop(\'disabled\', false); }' : '' ) . '
'.($selected ? ' if ( ! atleastoneselected ) { jQuery ( " . " + name + " select " ) . val ( " 0 " ) . trigger ( \ 'change\'); jQuery("."+name+"confirmed").prop(\'disabled\', true); } ' : '' ) . '
2016-11-17 19:04:10 +01:00
}
else
{
2020-05-02 06:42:12 +02:00
jQuery ( " . " + name ) . hide ();
jQuery ( " . " + name + " other " ) . hide ();
2016-11-17 19:04:10 +01:00
}
}
2017-05-18 14:18:59 +02:00
2016-11-17 19:04:10 +01:00
jQuery ( document ) . ready ( function () {
2020-09-07 10:18:17 +02:00
initCheckForSelect ( 0 , " ' . $name .' " , " '. $cssclass .' " );
jQuery ( " .' . $cssclass .' " ) . click ( function () {
initCheckForSelect ( 1 , " '. $name .' " , " '. $cssclass .' " );
2020-05-02 06:42:12 +02:00
});
2020-09-07 10:18:17 +02:00
jQuery ( " .' . $name .'select " ) . change ( function () {
2017-05-18 14:18:59 +02:00
var massaction = $ ( this ) . val ();
2016-12-07 14:14:03 +01:00
var urlform = $ ( this ) . closest ( " form " ) . attr ( " action " ) . replace ( " #show_files " , " " );
2017-05-18 14:18:59 +02:00
if ( massaction == " builddoc " )
2016-12-07 14:14:03 +01:00
{
urlform = urlform + " #show_files " ;
}
$ ( this ) . closest ( " form " ) . attr ( " action " , urlform );
2020-05-26 22:29:46 +02:00
console . log ( " we select a mass action name='. $name .' massaction= " + massaction + " - " + urlform );
2017-11-27 17:12:48 +01:00
/* Warning: if you set submit button to disabled, post using Enter will no more work if there is no other button */
2016-12-07 14:14:03 +01:00
if ( $ ( this ) . val () != \ ' 0 \ ' )
2016-11-17 19:04:10 +01:00
{
2020-09-07 10:18:17 +02:00
jQuery ( " .' . $name .'confirmed " ) . prop ( \ ' disabled\ ' , false );
jQuery ( " .' . $name .'other " ) . hide (); /* To disable if another div was open */
jQuery ( " .' . $name .' " + massaction ) . show ();
2016-11-17 19:04:10 +01:00
}
else
{
2020-09-07 10:18:17 +02:00
jQuery ( " .' . $name .'confirmed " ) . prop ( \ ' disabled\ ' , true );
jQuery ( " .' . $name .'other " ) . hide (); /* To disable any div open */
2016-11-17 19:04:10 +01:00
}
2016-12-07 14:14:03 +01:00
});
2016-11-17 19:04:10 +01:00
});
</ script >
' ;
2017-10-07 13:09:31 +02:00
}
2011-03-19 03:17:05 +01:00
2017-10-07 13:09:31 +02:00
return $ret ;
}
2010-09-02 21:31:18 +02:00
2020-04-18 15:11:38 +02:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2017-10-07 13:09:31 +02:00
/**
* Return combo list of activated countries , into language of user
*
2020-01-21 23:49:04 +01:00
* @ param string $selected Id or Code or Label of preselected country
* @ param string $htmlname Name of html select object
* @ param string $htmloption More html options on select object
* @ param integer $maxlength Max length for labels ( 0 = no limit )
* @ param string $morecss More css class
* @ param string $usecodeaskey '' = Use id as key ( default ), 'code3' = Use code on 3 alpha as key , ' code2 " =Use code on 2 alpha as key
* @ param int $showempty Show empty choice
* @ param int $disablefavorites 1 = Disable favorites ,
* @ param int $addspecialentries 1 = Add dedicated entries for group of countries ( like 'European Economic Community' , ... )
* @ param array $exclude_country_code Array of country code ( iso2 ) to exclude
2021-05-03 13:35:10 +02:00
* @ param int $hideflags Hide flags
2020-01-21 23:49:04 +01:00
* @ return string HTML string with select
2017-10-07 13:09:31 +02:00
*/
2021-05-03 13:35:10 +02:00
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 )
2017-10-07 13:09:31 +02:00
{
2020-04-18 15:11:38 +02:00
// phpcs:enable
2019-11-08 15:51:54 +01:00
global $conf , $langs , $mysoc ;
2017-10-07 13:09:31 +02:00
$langs -> load ( " dict " );
2019-11-08 15:51:54 +01:00
$out = '' ;
$countryArray = array ();
$favorite = array ();
$label = array ();
$atleastonefavorite = 0 ;
2010-08-22 17:46:34 +02:00
2021-04-13 22:50:50 +02:00
$sql = " SELECT rowid, code as code_iso, code_iso as code_iso3, label, favorite, eec " ;
2019-11-08 15:51:54 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " c_country " ;
$sql .= " WHERE active > 0 " ;
2017-10-07 13:09:31 +02:00
//$sql.= " ORDER BY code ASC";
dol_syslog ( get_class ( $this ) . " ::select_country " , LOG_DEBUG );
2019-11-08 15:51:54 +01:00
$resql = $this -> db -> query ( $sql );
2021-02-23 22:03:23 +01:00
if ( $resql ) {
2019-11-08 15:51:54 +01:00
$out .= '<select id="select' . $htmlname . '" class="flat maxwidth200onsmartphone selectcountry' . ( $morecss ? ' ' . $morecss : '' ) . '" name="' . $htmlname . '" ' . $htmloption . '>' ;
2017-10-07 13:09:31 +02:00
$num = $this -> db -> num_rows ( $resql );
$i = 0 ;
2021-02-23 22:03:23 +01:00
if ( $num ) {
while ( $i < $num ) {
2017-10-07 13:09:31 +02:00
$obj = $this -> db -> fetch_object ( $resql );
2020-01-21 23:49:04 +01:00
2019-11-08 15:51:54 +01:00
$countryArray [ $i ][ 'rowid' ] = $obj -> rowid ;
$countryArray [ $i ][ 'code_iso' ] = $obj -> code_iso ;
2017-10-07 13:09:31 +02:00
$countryArray [ $i ][ 'code_iso3' ] = $obj -> code_iso3 ;
2019-11-08 15:51:54 +01:00
$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 : '' ));
2021-04-13 22:50:50 +02:00
$countryArray [ $i ][ 'favorite' ] = $obj -> favorite ;
$countryArray [ $i ][ 'eec' ] = $obj -> eec ;
2019-11-08 15:51:54 +01:00
$favorite [ $i ] = $obj -> favorite ;
2014-10-12 15:28:01 +02:00
$label [ $i ] = dol_string_unaccent ( $countryArray [ $i ][ 'label' ]);
2017-10-07 13:09:31 +02:00
$i ++ ;
}
2011-03-10 13:09:59 +01:00
2021-02-23 22:03:23 +01:00
if ( empty ( $disablefavorites )) {
array_multisort ( $favorite , SORT_DESC , $label , SORT_ASC , $countryArray );
} else {
$countryArray = dol_sort_array ( $countryArray , 'label' );
}
2011-11-01 04:57:45 +01:00
2021-02-23 22:03:23 +01:00
if ( $showempty ) {
2019-11-08 15:51:54 +01:00
$out .= '<option value=""> </option>' . " \n " ;
2018-10-09 01:47:37 +02:00
}
2021-02-23 22:03:23 +01:00
if ( $addspecialentries ) { // Add dedicated entries for groups of countries
2018-10-09 01:47:37 +02:00
//if ($showempty) $out.= '<option value="" disabled class="selectoptiondisabledwhite">--------------</option>';
2019-11-08 15:51:54 +01:00
$out .= '<option value="special_allnotme"' . ( $selected == 'special_allnotme' ? ' selected' : '' ) . '>' . $langs -> trans ( " CountriesExceptMe " , $langs -> transnoentitiesnoconv ( " Country " . $mysoc -> country_code )) . '</option>' ;
$out .= '<option value="special_eec"' . ( $selected == 'special_eec' ? ' selected' : '' ) . '>' . $langs -> trans ( " CountriesInEEC " ) . '</option>' ;
2021-02-23 22:03:23 +01:00
if ( $mysoc -> isInEEC ()) {
$out .= '<option value="special_eecnotme"' . ( $selected == 'special_eecnotme' ? ' selected' : '' ) . '>' . $langs -> trans ( " CountriesInEECExceptMe " , $langs -> transnoentitiesnoconv ( " Country " . $mysoc -> country_code )) . '</option>' ;
}
2019-11-08 15:51:54 +01:00
$out .= '<option value="special_noteec"' . ( $selected == 'special_noteec' ? ' selected' : '' ) . '>' . $langs -> trans ( " CountriesNotInEEC " ) . '</option>' ;
2020-10-16 15:40:52 +02:00
$out .= '<option value="" disabled class="selectoptiondisabledwhite">------------</option>' ;
2018-10-09 01:47:37 +02:00
}
2011-03-10 13:09:59 +01:00
2021-02-23 22:03:23 +01:00
foreach ( $countryArray as $row ) {
2018-10-09 01:47:37 +02:00
//if (empty($showempty) && empty($row['rowid'])) continue;
2021-02-23 22:03:23 +01:00
if ( empty ( $row [ 'rowid' ])) {
continue ;
}
if ( is_array ( $exclude_country_code ) && count ( $exclude_country_code ) && in_array ( $row [ 'code_iso' ], $exclude_country_code )) {
continue ; // exclude some countries
}
2011-11-01 04:57:45 +01:00
2021-02-23 22:03:23 +01:00
if ( empty ( $disablefavorites ) && $row [ 'favorite' ] && $row [ 'code_iso' ]) {
$atleastonefavorite ++ ;
}
if ( empty ( $row [ 'favorite' ]) && $atleastonefavorite ) {
2019-11-08 15:51:54 +01:00
$atleastonefavorite = 0 ;
2020-10-16 15:40:52 +02:00
$out .= '<option value="" disabled class="selectoptiondisabledwhite">------------</option>' ;
2014-10-18 15:53:42 +02:00
}
2020-11-29 15:47:08 +01:00
$labeltoshow = '' ;
2021-02-23 22:03:23 +01:00
if ( $row [ 'label' ]) {
$labeltoshow .= dol_trunc ( $row [ 'label' ], $maxlength , 'middle' );
} else {
$labeltoshow .= ' ' ;
}
2020-11-29 15:47:08 +01:00
if ( $row [ 'code_iso' ]) {
$labeltoshow .= ' <span class="opacitymedium">(' . $row [ 'code_iso' ] . ')</span>' ;
2021-05-03 13:35:10 +02:00
if ( empty ( $hideflags )) {
2021-06-16 21:06:55 +02:00
$tmpflag = picto_from_langcode ( $row [ 'code_iso' ], 'class="saturatemedium paddingrightonly"' );
2021-05-03 13:35:10 +02:00
$labeltoshow = $tmpflag . ' ' . $labeltoshow ;
}
2020-11-29 15:47:08 +01:00
}
if ( $selected && $selected != '-1' && ( $selected == $row [ 'rowid' ] || $selected == $row [ 'code_iso' ] || $selected == $row [ 'code_iso3' ] || $selected == $row [ 'label' ])) {
2021-04-13 22:50:50 +02:00
$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' ]) . '">' ;
2020-05-21 15:05:19 +02:00
} else {
2021-04-13 22:50:50 +02:00
$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' ]) . '">' ;
2017-10-07 13:09:31 +02:00
}
2020-11-29 15:47:08 +01:00
$out .= $labeltoshow ;
2019-11-08 15:51:54 +01:00
$out .= '</option>' ;
2017-10-07 13:09:31 +02:00
}
}
2019-11-08 15:51:54 +01:00
$out .= '</select>' ;
2020-05-21 15:05:19 +02:00
} else {
2017-10-07 13:09:31 +02:00
dol_print_error ( $this -> db );
}
2010-09-02 21:31:18 +02:00
2017-10-07 13:09:31 +02:00
// Make select dynamic
2019-11-08 15:51:54 +01:00
include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php' ;
2021-06-16 21:06:55 +02:00
$out .= ajax_combobox ( 'select' . $htmlname , array (), 0 , 0 , 'resolve' );
2015-05-31 12:25:33 +02:00
2017-10-07 13:09:31 +02:00
return $out ;
}
2010-08-22 17:46:34 +02:00
2020-04-18 15:11:38 +02:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2015-02-09 17:55:43 +01:00
/**
2017-10-07 13:09:31 +02:00
* Return select list of incoterms
*
* @ param string $selected Id or Code of preselected incoterm
* @ param string $location_incoterms Value of input location
* @ param string $page Defined the form action
* @ param string $htmlname Name of html select object
* @ param string $htmloption Options html on select object
2017-10-25 22:02:07 +02:00
* @ param int $forcecombo Force to load all values and output a standard combobox ( with no beautification )
2017-10-07 13:09:31 +02:00
* @ param array $events Event options to run on change . Example : array ( array ( 'method' => 'getContacts' , 'url' => dol_buildpath ( '/core/ajax/contacts.php' , 1 ), 'htmlname' => 'contactid' , 'params' => array ( 'add-customer-contact' => 'disabled' )))
* @ return string HTML string with select and input
*/
2020-04-18 15:11:38 +02:00
public function select_incoterms ( $selected = '' , $location_incoterms = '' , $page = '' , $htmlname = 'incoterm_id' , $htmloption = '' , $forcecombo = 1 , $events = array ())
2017-10-07 13:09:31 +02:00
{
2020-04-18 15:11:38 +02:00
// phpcs:enable
2019-11-08 15:51:54 +01:00
global $conf , $langs ;
2015-02-09 17:55:43 +01:00
2017-10-07 13:09:31 +02:00
$langs -> load ( " dict " );
2015-02-09 17:55:43 +01:00
2019-11-08 15:51:54 +01:00
$out = '' ;
$incotermArray = array ();
2015-02-09 17:55:43 +01:00
2017-10-07 13:09:31 +02:00
$sql = " SELECT rowid, code " ;
2019-11-08 15:51:54 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " c_incoterms " ;
$sql .= " WHERE active > 0 " ;
$sql .= " ORDER BY code ASC " ;
2015-03-18 21:44:57 +01:00
2017-10-07 13:09:31 +02:00
dol_syslog ( get_class ( $this ) . " ::select_incoterm " , LOG_DEBUG );
2019-11-08 15:51:54 +01:00
$resql = $this -> db -> query ( $sql );
2021-02-23 22:03:23 +01:00
if ( $resql ) {
if ( $conf -> use_javascript_ajax && ! $forcecombo ) {
2019-11-08 15:51:54 +01:00
include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php' ;
2015-02-10 10:22:38 +01:00
$out .= ajax_combobox ( $htmlname , $events );
}
2015-03-18 21:44:57 +01:00
2021-02-23 22:03:23 +01:00
if ( ! empty ( $page )) {
2015-02-10 10:22:38 +01:00
$out .= '<form method="post" action="' . $page . '">' ;
2017-10-07 13:09:31 +02:00
$out .= '<input type="hidden" name="action" value="set_incoterms">' ;
2019-12-01 10:20:11 +01:00
$out .= '<input type="hidden" name="token" value="' . newToken () . '">' ;
2015-02-10 10:22:38 +01:00
}
2015-03-18 21:44:57 +01:00
2021-05-19 14:38:39 +02:00
$out .= '<select id="' . $htmlname . '" class="flat selectincoterm width75" name="' . $htmlname . '" ' . $htmloption . '>' ;
2019-11-08 15:51:54 +01:00
$out .= '<option value="0"> </option>' ;
2017-10-07 13:09:31 +02:00
$num = $this -> db -> num_rows ( $resql );
$i = 0 ;
2021-02-23 22:03:23 +01:00
if ( $num ) {
2019-11-08 15:51:54 +01:00
$foundselected = false ;
2015-02-09 17:55:43 +01:00
2021-02-23 22:03:23 +01:00
while ( $i < $num ) {
2017-10-07 13:09:31 +02:00
$obj = $this -> db -> fetch_object ( $resql );
$incotermArray [ $i ][ 'rowid' ] = $obj -> rowid ;
$incotermArray [ $i ][ 'code' ] = $obj -> code ;
$i ++ ;
}
2021-02-23 22:03:23 +01:00
foreach ( $incotermArray as $row ) {
if ( $selected && ( $selected == $row [ 'rowid' ] || $selected == $row [ 'code' ])) {
2019-11-08 15:51:54 +01:00
$out .= '<option value="' . $row [ 'rowid' ] . '" selected>' ;
2020-05-21 15:05:19 +02:00
} else {
2019-11-08 15:51:54 +01:00
$out .= '<option value="' . $row [ 'rowid' ] . '">' ;
2017-10-07 13:09:31 +02:00
}
2015-03-18 21:44:57 +01:00
2021-02-23 22:03:23 +01:00
if ( $row [ 'code' ]) {
$out .= $row [ 'code' ];
}
2015-03-18 21:44:57 +01:00
2019-11-08 15:51:54 +01:00
$out .= '</option>' ;
2017-10-07 13:09:31 +02:00
}
}
2019-11-08 15:51:54 +01:00
$out .= '</select>' ;
2015-03-18 21:44:57 +01:00
2021-02-27 02:44:52 +01:00
$out .= '<input id="location_incoterms" class="maxwidth100onsmartphone nomargintop nomarginbottom" name="location_incoterms" value="' . $location_incoterms . '">' ;
2015-03-18 21:44:57 +01:00
2021-02-23 22:03:23 +01:00
if ( ! empty ( $page )) {
2021-02-27 02:44:52 +01:00
$out .= '<input type="submit" class="button valignmiddle smallpaddingimp nomargintop nomarginbottom" value="' . $langs -> trans ( " Modify " ) . '"></form>' ;
2015-02-10 10:22:38 +01:00
}
2020-05-21 15:05:19 +02:00
} else {
2017-10-07 13:09:31 +02:00
dol_print_error ( $this -> db );
}
2015-02-09 17:55:43 +01:00
2017-10-07 13:09:31 +02:00
return $out ;
}
2015-02-09 17:55:43 +01:00
2020-04-18 15:11:38 +02:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2017-10-07 13:09:31 +02:00
/**
* Return list of types of lines ( product or service )
* Example : 0 = product , 1 = service , 9 = other ( for external module )
*
* @ param string $selected Preselected type
* @ param string $htmlname Name of field in html form
* @ param int $showempty Add an empty field
* @ param int $hidetext Do not show label 'Type' before combo box ( used only if there is at least 2 choices to select )
2018-12-13 10:36:30 +01:00
* @ param integer $forceall 1 = Force to show products and services in combo list , whatever are activated modules , 0 = No force , 2 = Force to show only Products , 3 = Force to show only services , - 1 = Force none ( and set hidden field to 'service' )
2017-10-07 13:09:31 +02:00
* @ return void
*/
2020-04-18 15:11:38 +02:00
public function select_type_of_lines ( $selected = '' , $htmlname = 'type' , $showempty = 0 , $hidetext = 0 , $forceall = 0 )
2017-10-07 13:09:31 +02:00
{
2020-04-18 15:11:38 +02:00
// phpcs:enable
2019-11-08 15:51:54 +01:00
global $db , $langs , $user , $conf ;
2010-08-22 17:46:34 +02:00
2017-10-07 13:09:31 +02:00
// If product & services are enabled or both disabled.
2019-11-08 15:51:54 +01:00
if ( $forceall == 1 || ( empty ( $forceall ) && ! empty ( $conf -> product -> enabled ) && ! empty ( $conf -> service -> enabled ))
2021-02-23 22:03:23 +01:00
|| ( empty ( $forceall ) && empty ( $conf -> product -> enabled ) && empty ( $conf -> service -> enabled ))) {
if ( empty ( $hidetext )) {
print $langs -> trans ( " Type " ) . ': ' ;
}
2017-10-07 13:09:31 +02:00
print '<select class="flat" id="select_' . $htmlname . '" name="' . $htmlname . '">' ;
2021-02-23 22:03:23 +01:00
if ( $showempty ) {
2017-10-07 13:09:31 +02:00
print '<option value="-1"' ;
2021-02-23 22:03:23 +01:00
if ( $selected == - 1 ) {
print ' selected' ;
}
2017-10-07 13:09:31 +02:00
print '> </option>' ;
}
2010-08-22 17:46:34 +02:00
2017-10-07 13:09:31 +02:00
print '<option value="0"' ;
2021-02-23 22:03:23 +01:00
if ( 0 == $selected ) {
print ' selected' ;
}
2017-10-07 13:09:31 +02:00
print '>' . $langs -> trans ( " Product " );
2010-08-22 17:46:34 +02:00
2017-10-07 13:09:31 +02:00
print '<option value="1"' ;
2021-02-23 22:03:23 +01:00
if ( 1 == $selected ) {
print ' selected' ;
}
2017-10-07 13:09:31 +02:00
print '>' . $langs -> trans ( " Service " );
2010-08-22 17:46:34 +02:00
2017-10-07 13:09:31 +02:00
print '</select>' ;
2021-02-15 14:19:05 +01:00
print ajax_combobox ( 'select_' . $htmlname );
2017-10-07 13:09:31 +02:00
//if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
}
2021-02-23 22:03:23 +01:00
if (( empty ( $forceall ) && empty ( $conf -> product -> enabled ) && ! empty ( $conf -> service -> enabled )) || $forceall == 3 ) {
2017-10-07 13:09:31 +02:00
print $langs -> trans ( " Service " );
print '<input type="hidden" name="' . $htmlname . '" value="1">' ;
}
2021-02-23 22:03:23 +01:00
if (( empty ( $forceall ) && ! empty ( $conf -> product -> enabled ) && empty ( $conf -> service -> enabled )) || $forceall == 2 ) {
2017-10-07 13:09:31 +02:00
print $langs -> trans ( " Product " );
print '<input type="hidden" name="' . $htmlname . '" value="0">' ;
}
2021-02-23 22:03:23 +01:00
if ( $forceall < 0 ) { // This should happened only for contracts when both predefined product and service are disabled.
2019-11-08 15:51:54 +01:00
print '<input type="hidden" name="' . $htmlname . '" value="1">' ; // By default we set on service for contract. If CONTRACT_SUPPORT_PRODUCTS is set, forceall should be 1 not -1
2014-07-19 22:05:35 +02:00
}
2017-10-07 13:09:31 +02:00
}
2011-11-01 04:57:45 +01:00
2020-04-18 15:11:38 +02:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2017-10-07 13:09:31 +02:00
/**
* Load into cache cache_types_fees , array of types of fees
*
* @ return int Nb of lines loaded , < 0 if KO
*/
2020-04-18 15:11:38 +02:00
public function load_cache_types_fees ()
2017-10-07 13:09:31 +02:00
{
2020-04-18 15:11:38 +02:00
// phpcs:enable
2017-10-07 13:09:31 +02:00
global $langs ;
2012-02-21 10:47:08 +01:00
2017-10-07 13:09:31 +02:00
$num = count ( $this -> cache_types_fees );
2021-02-23 22:03:23 +01:00
if ( $num > 0 ) {
return 0 ; // Cache already loaded
}
2015-06-06 13:22:15 +02:00
2017-10-07 13:09:31 +02:00
dol_syslog ( __METHOD__ , LOG_DEBUG );
2012-02-21 10:47:08 +01:00
2017-10-07 13:09:31 +02:00
$langs -> load ( " trips " );
2012-02-21 10:47:08 +01:00
2017-10-07 13:09:31 +02:00
$sql = " SELECT c.code, c.label " ;
2019-11-08 15:51:54 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " c_type_fees as c " ;
$sql .= " WHERE active > 0 " ;
2012-02-21 10:47:08 +01:00
2019-11-08 15:51:54 +01:00
$resql = $this -> db -> query ( $sql );
2021-02-23 22:03:23 +01:00
if ( $resql ) {
2017-10-07 13:09:31 +02:00
$num = $this -> db -> num_rows ( $resql );
$i = 0 ;
2012-02-21 10:47:08 +01:00
2021-02-23 22:03:23 +01:00
while ( $i < $num ) {
2017-10-07 13:09:31 +02:00
$obj = $this -> db -> fetch_object ( $resql );
2012-02-21 10:47:08 +01:00
2017-10-07 13:09:31 +02:00
// Si traduction existe, on l'utilise, sinon on prend le libelle par defaut
2019-11-08 15:51:54 +01:00
$label = ( $obj -> code != $langs -> trans ( $obj -> code ) ? $langs -> trans ( $obj -> code ) : $langs -> trans ( $obj -> label ));
2017-10-07 13:09:31 +02:00
$this -> cache_types_fees [ $obj -> code ] = $label ;
$i ++ ;
}
2014-09-06 16:24:44 +02:00
asort ( $this -> cache_types_fees );
2017-10-07 13:09:31 +02:00
return $num ;
2020-05-21 15:05:19 +02:00
} else {
2017-10-07 13:09:31 +02:00
dol_print_error ( $this -> db );
return - 1 ;
}
}
2010-08-22 17:46:34 +02:00
2020-04-18 15:11:38 +02:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2017-10-07 13:09:31 +02:00
/**
* Return list of types of notes
*
* @ param string $selected Preselected type
* @ param string $htmlname Name of field in form
* @ param int $showempty Add an empty field
* @ return void
*/
2020-04-18 15:11:38 +02:00
public function select_type_fees ( $selected = '' , $htmlname = 'type' , $showempty = 0 )
2017-10-07 13:09:31 +02:00
{
2020-04-18 15:11:38 +02:00
// phpcs:enable
2017-10-07 13:09:31 +02:00
global $user , $langs ;
2011-11-01 04:57:45 +01:00
2017-10-07 13:09:31 +02:00
dol_syslog ( __METHOD__ . " selected= " . $selected . " , htmlname= " . $htmlname , LOG_DEBUG );
2011-11-01 04:57:45 +01:00
2017-10-07 13:09:31 +02:00
$this -> load_cache_types_fees ();
2010-08-22 17:46:34 +02:00
2018-12-07 17:28:31 +01:00
print '<select id="select_' . $htmlname . '" class="flat" name="' . $htmlname . '">' ;
2021-02-23 22:03:23 +01:00
if ( $showempty ) {
2017-10-07 13:09:31 +02:00
print '<option value="-1"' ;
2021-02-23 22:03:23 +01:00
if ( $selected == - 1 ) {
print ' selected' ;
}
2017-10-07 13:09:31 +02:00
print '> </option>' ;
}
2011-11-01 04:57:45 +01:00
2021-02-23 22:03:23 +01:00
foreach ( $this -> cache_types_fees as $key => $value ) {
2017-10-07 13:09:31 +02:00
print '<option value="' . $key . '"' ;
2021-02-23 22:03:23 +01:00
if ( $key == $selected ) {
print ' selected' ;
}
2017-10-07 13:09:31 +02:00
print '>' ;
print $value ;
print '</option>' ;
}
2011-10-31 11:49:47 +01:00
2017-10-07 13:09:31 +02:00
print '</select>' ;
2021-02-23 22:03:23 +01:00
if ( $user -> admin ) {
print info_admin ( $langs -> trans ( " YouCanChangeValuesForThisListFromDictionarySetup " ), 1 );
}
2017-10-07 13:09:31 +02:00
}
2010-11-18 23:17:44 +01:00
2013-06-05 22:01:35 +02:00
2020-04-18 15:11:38 +02:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2017-10-07 13:09:31 +02:00
/**
* Output html form to select a third party
*
* @ param string $selected Preselected type
* @ param string $htmlname Name of field in form
2019-05-21 17:22:38 +02:00
* @ param string $filter Optional filters criteras . WARNING : To avoid SQL injection , only few chars [ . a - z0 - 9 =<> ] are allowed here ( example : 's.rowid <> x' , 's.client IN (1,3)' )
2017-10-07 13:09:31 +02:00
* @ param string $showempty Add an empty field ( Can be '1' or text key to use on empty line like 'SelectThirdParty' )
* @ param int $showtype Show third party type in combolist ( customer , prospect or supplier )
2017-10-25 22:02:07 +02:00
* @ param int $forcecombo Force to load all values and output a standard combobox ( with no beautification )
2017-10-07 13:09:31 +02:00
* @ param array $events Ajax event options to run on change . Example : array ( array ( 'method' => 'getContacts' , 'url' => dol_buildpath ( '/core/ajax/contacts.php' , 1 ), 'htmlname' => 'contactid' , 'params' => array ( 'add-customer-contact' => 'disabled' )))
* @ param int $limit Maximum number of elements
* @ param string $morecss Add more css styles to the SELECT component
* @ param string $moreparam Add more parameters onto the select tag . For example 'style="width: 95%"' to avoid select2 component to go over parent container
2017-03-26 05:02:06 +02:00
* @ param string $selected_input_value Value of preselected input text ( for use with ajax )
2017-10-07 13:09:31 +02:00
* @ param int $hidelabel Hide label ( 0 = no , 1 = yes , 2 = show search icon ( before ) and placeholder , 3 search icon after )
* @ param array $ajaxoptions Options for ajax_autocompleter
2018-06-29 11:48:54 +02:00
* @ param bool $multiple add [] in the name of element and add 'multiple' attribut ( not working with ajax_autocompleter )
2021-03-22 22:50:43 +01:00
* @ param array $excludeids Exclude IDs from the select combo
2017-10-07 13:09:31 +02:00
* @ return string HTML string with select box for thirdparty .
*/
2021-03-22 22:50:43 +01:00
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 ())
2017-10-07 13:09:31 +02:00
{
2020-04-18 15:11:38 +02:00
// phpcs:enable
2019-11-08 15:51:54 +01:00
global $conf , $user , $langs ;
2013-06-05 22:01:35 +02:00
2019-11-08 15:51:54 +01:00
$out = '' ;
2010-11-18 23:17:44 +01:00
2021-02-23 22:03:23 +01:00
if ( ! empty ( $conf -> use_javascript_ajax ) && ! empty ( $conf -> global -> COMPANY_USE_SEARCH_TO_SELECT ) && ! $forcecombo ) {
2021-03-22 22:50:43 +01:00
if ( is_null ( $ajaxoptions )) {
$ajaxoptions = array ();
}
2017-10-07 13:09:31 +02:00
// No immediate load of all database
2019-11-08 15:51:54 +01:00
$placeholder = '' ;
2021-02-23 22:03:23 +01:00
if ( $selected && empty ( $selected_input_value )) {
2017-10-07 13:09:31 +02:00
require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php' ;
$societetmp = new Societe ( $this -> db );
$societetmp -> fetch ( $selected );
2019-11-08 15:51:54 +01:00
$selected_input_value = $societetmp -> name ;
2017-10-07 13:09:31 +02:00
unset ( $societetmp );
}
// mode 1
2021-03-22 22:50:43 +01:00
$urloption = 'htmlname=' . urlencode ( $htmlname ) . '&outjson=1&filter=' . urlencode ( $filter ) . ( empty ( $excludeids ) ? '' : '&excludeids=' . join ( ',' , $excludeids )) . ( $showtype ? '&showtype=' . urlencode ( $showtype ) : '' );
2019-11-08 15:51:54 +01:00
$out .= ajax_autocompleter ( $selected , $htmlname , DOL_URL_ROOT . '/societe/ajax/company.php' , $urloption , $conf -> global -> COMPANY_USE_SEARCH_TO_SELECT , 0 , $ajaxoptions );
$out .= '<style type="text/css">.ui-autocomplete { z-index: 250; }</style>' ;
2021-02-23 22:03:23 +01:00
if ( empty ( $hidelabel )) {
print $langs -> trans ( " RefOrLabel " ) . ' : ' ;
} elseif ( $hidelabel > 1 ) {
2019-11-08 15:51:54 +01:00
$placeholder = ' placeholder="' . $langs -> trans ( " RefOrLabel " ) . '"' ;
2017-10-07 13:09:31 +02:00
if ( $hidelabel == 2 ) {
2019-11-08 15:51:54 +01:00
$out .= img_picto ( $langs -> trans ( " Search " ), 'search' );
2017-10-07 13:09:31 +02:00
}
}
2019-11-08 15:51:54 +01:00
$out .= '<input type="text" class="' . $morecss . '" name="search_' . $htmlname . '" id="search_' . $htmlname . '" value="' . $selected_input_value . '"' . $placeholder . ' ' . ( ! empty ( $conf -> global -> THIRDPARTY_SEARCH_AUTOFOCUS ) ? 'autofocus' : '' ) . ' />' ;
2017-10-07 13:09:31 +02:00
if ( $hidelabel == 3 ) {
2019-11-08 15:51:54 +01:00
$out .= img_picto ( $langs -> trans ( " Search " ), 'search' );
2017-10-07 13:09:31 +02:00
}
2020-05-21 15:05:19 +02:00
} else {
2017-10-07 13:09:31 +02:00
// Immediate load of all database
2021-03-22 22:50:43 +01:00
$out .= $this -> select_thirdparty_list ( $selected , $htmlname , $filter , $showempty , $showtype , $forcecombo , $events , '' , 0 , $limit , $morecss , $moreparam , $multiple , $excludeids );
2017-10-07 13:09:31 +02:00
}
return $out ;
}
2020-04-18 15:11:38 +02:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2017-10-07 13:09:31 +02:00
/**
* Output html form to select a third party .
* Note , you must use the select_company to get the component to select a third party . This function must only be called by select_company .
*
* @ param string $selected Preselected type
* @ param string $htmlname Name of field in form
2021-03-22 22:50:43 +01:00
* @ param string $filter Optional filters criteras ( example : 's.rowid NOT IN (x)' , 's.client IN (1,3)' ) . Do not use a filter coming from input of users .
2017-10-07 13:09:31 +02:00
* @ param string $showempty Add an empty field ( Can be '1' or text to use on empty line like 'SelectThirdParty' )
* @ param int $showtype Show third party type in combolist ( customer , prospect or supplier )
2017-10-25 22:02:07 +02:00
* @ param int $forcecombo Force to use standard HTML select component without beautification
2017-10-07 13:09:31 +02:00
* @ param array $events Event options . Example : array ( array ( 'method' => 'getContacts' , 'url' => dol_buildpath ( '/core/ajax/contacts.php' , 1 ), 'htmlname' => 'contactid' , 'params' => array ( 'add-customer-contact' => 'disabled' )))
* @ param string $filterkey Filter on key value
* @ param int $outputmode 0 = HTML select string , 1 = Array
* @ param int $limit Limit number of answers
* @ param string $morecss Add more css styles to the SELECT component
* @ param string $moreparam Add more parameters onto the select tag . For example 'style="width: 95%"' to avoid select2 component to go over parent container
2018-06-29 11:48:54 +02:00
* @ param bool $multiple add [] in the name of element and add 'multiple' attribut
2021-03-22 22:50:43 +01:00
* @ param array $excludeids Exclude IDs from the select combo
2017-10-07 13:09:31 +02:00
* @ return string HTML string with
*/
2021-03-22 22:50:43 +01:00
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 ())
2017-10-07 13:09:31 +02:00
{
2020-04-18 15:11:38 +02:00
// phpcs:enable
2019-11-08 15:51:54 +01:00
global $conf , $user , $langs ;
2017-10-07 13:09:31 +02:00
2019-11-08 15:51:54 +01:00
$out = '' ;
$num = 0 ;
$outarray = array ();
2018-07-09 15:39:59 +02:00
2021-02-23 22:03:23 +01:00
if ( $selected === '' ) {
$selected = array ();
} elseif ( ! is_array ( $selected )) {
$selected = array ( $selected );
}
2018-07-09 15:39:59 +02:00
2018-06-25 14:06:09 +02:00
// Clean $filter that may contains sql conditions so sql code
2018-09-01 17:42:16 +02:00
if ( function_exists ( 'testSqlAndScriptInject' )) {
2019-05-21 17:22:38 +02:00
if ( testSqlAndScriptInject ( $filter , 3 ) > 0 ) {
2019-11-08 15:51:54 +01:00
$filter = '' ;
2018-08-03 17:09:58 +02:00
}
}
2018-06-25 14:06:09 +02:00
2020-10-23 04:24:54 +02:00
// We search companies
2017-10-07 13:09:31 +02:00
$sql = " SELECT s.rowid, s.nom as name, s.name_alias, s.client, s.fournisseur, s.code_client, s.code_fournisseur " ;
2020-10-31 14:32:18 +01:00
if ( ! empty ( $conf -> global -> COMPANY_SHOW_ADDRESS_SELECTLIST )) {
2019-01-05 15:14:06 +01:00
$sql .= " , s.address, s.zip, s.town " ;
2020-04-18 15:11:38 +02:00
$sql .= " , dictp.code as country_code " ;
2018-08-06 10:52:10 +02:00
}
2019-11-08 15:51:54 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " societe as s " ;
2020-10-31 14:32:18 +01:00
if ( ! empty ( $conf -> global -> COMPANY_SHOW_ADDRESS_SELECTLIST )) {
2020-10-07 01:03:48 +02:00
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " c_country as dictp ON dictp.rowid = s.fk_pays " ;
2018-08-06 10:52:10 +02:00
}
2021-02-23 22:03:23 +01:00
if ( ! $user -> rights -> societe -> client -> voir && ! $user -> socid ) {
$sql .= " , " . MAIN_DB_PREFIX . " societe_commerciaux as sc " ;
}
2019-11-08 15:51:54 +01:00
$sql .= " WHERE s.entity IN ( " . getEntity ( 'societe' ) . " ) " ;
2021-02-23 22:03:23 +01:00
if ( ! empty ( $user -> socid )) {
$sql .= " AND s.rowid = " . $user -> socid ;
}
if ( $filter ) {
$sql .= " AND ( " . $filter . " ) " ;
}
if ( ! $user -> rights -> societe -> client -> voir && ! $user -> socid ) {
$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " . $user -> id ;
}
if ( ! empty ( $conf -> global -> COMPANY_HIDE_INACTIVE_IN_COMBOBOX )) {
$sql .= " AND s.status <> 0 " ;
}
2021-03-22 22:50:43 +01:00
if ( ! empty ( $excludeids )) {
$sql .= " AND rowid NOT IN ( " . $this -> db -> sanitize ( join ( ',' , $excludeids )) . " ) " ;
}
2017-10-07 13:09:31 +02:00
// Add criteria
2021-02-23 22:03:23 +01:00
if ( $filterkey && $filterkey != '' ) {
2019-11-08 15:51:54 +01:00
$sql .= " AND ( " ;
$prefix = empty ( $conf -> global -> COMPANY_DONOTSEARCH_ANYWHERE ) ? '%' : '' ; // Can use index if COMPANY_DONOTSEARCH_ANYWHERE is on
2017-10-07 13:09:31 +02:00
// For natural search
$scrit = explode ( ' ' , $filterkey );
2019-11-08 15:51:54 +01:00
$i = 0 ;
2021-02-23 22:03:23 +01:00
if ( count ( $scrit ) > 1 ) {
$sql .= " ( " ;
}
2017-10-07 13:09:31 +02:00
foreach ( $scrit as $crit ) {
2021-02-23 22:03:23 +01:00
if ( $i > 0 ) {
$sql .= " AND " ;
}
2019-11-08 15:51:54 +01:00
$sql .= " (s.nom LIKE ' " . $this -> db -> escape ( $prefix . $crit ) . " %') " ;
2017-10-07 13:09:31 +02:00
$i ++ ;
}
2021-02-23 22:03:23 +01:00
if ( count ( $scrit ) > 1 ) {
$sql .= " ) " ;
}
if ( ! empty ( $conf -> barcode -> enabled )) {
2018-09-01 14:41:44 +02:00
$sql .= " OR s.barcode LIKE ' " . $this -> db -> escape ( $prefix . $filterkey ) . " %' " ;
2017-10-07 13:09:31 +02:00
}
2019-11-08 15:51:54 +01:00
$sql .= " OR s.code_client LIKE ' " . $this -> db -> escape ( $prefix . $filterkey ) . " %' OR s.code_fournisseur LIKE ' " . $this -> db -> escape ( $prefix . $filterkey ) . " %' " ;
$sql .= " ) " ;
2017-10-07 13:09:31 +02:00
}
2019-11-08 15:51:54 +01:00
$sql .= $this -> db -> order ( " nom " , " ASC " );
$sql .= $this -> db -> plimit ( $limit , 0 );
2014-04-02 14:53:42 +02:00
2017-03-26 05:02:06 +02:00
// Build output string
2017-10-07 13:09:31 +02:00
dol_syslog ( get_class ( $this ) . " ::select_thirdparty_list " , LOG_DEBUG );
2019-11-08 15:51:54 +01:00
$resql = $this -> db -> query ( $sql );
2021-02-23 22:03:23 +01:00
if ( $resql ) {
if ( ! $forcecombo ) {
2019-11-08 15:51:54 +01:00
include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php' ;
2017-11-24 09:23:18 +01:00
$out .= ajax_combobox ( $htmlname , $events , $conf -> global -> COMPANY_USE_SEARCH_TO_SELECT );
2017-10-07 13:09:31 +02:00
}
2011-05-01 20:22:58 +02:00
2017-10-07 13:09:31 +02:00
// Construct $out and $outarray
2019-11-08 15:51:54 +01:00
$out .= '<select id="' . $htmlname . '" class="flat' . ( $morecss ? ' ' . $morecss : '' ) . '"' . ( $moreparam ? ' ' . $moreparam : '' ) . ' name="' . $htmlname . ( $multiple ? '[]' : '' ) . '" ' . ( $multiple ? 'multiple' : '' ) . '>' . " \n " ;
2014-09-08 12:05:24 +02:00
2020-04-29 20:21:17 +02:00
$textifempty = (( $showempty && ! is_numeric ( $showempty )) ? $langs -> trans ( $showempty ) : '' );
2021-02-23 22:03:23 +01:00
if ( ! empty ( $conf -> global -> COMPANY_USE_SEARCH_TO_SELECT )) {
2020-04-29 20:21:17 +02:00
// Do not use textifempty = ' ' or ' ' here, or search on key will search on ' key'.
//if (! empty($conf->use_javascript_ajax) || $forcecombo) $textifempty='';
2021-02-23 22:03:23 +01:00
if ( $showempty && ! is_numeric ( $showempty )) {
$textifempty = $langs -> trans ( $showempty );
} else {
$textifempty .= $langs -> trans ( " All " );
}
}
if ( $showempty ) {
$out .= '<option value="-1" data-html="' . dol_escape_htmltag ( '<span class="opacitymedium">' . $textifempty . '</span>' ) . '">' . $textifempty . '</option>' . " \n " ;
2017-10-07 13:09:31 +02:00
}
2014-09-08 12:05:24 +02:00
2017-03-26 05:02:06 +02:00
$num = $this -> db -> num_rows ( $resql );
2017-10-07 13:09:31 +02:00
$i = 0 ;
2021-02-23 22:03:23 +01:00
if ( $num ) {
while ( $i < $num ) {
2017-10-07 13:09:31 +02:00
$obj = $this -> db -> fetch_object ( $resql );
2019-11-08 15:51:54 +01:00
$label = '' ;
2017-10-07 13:09:31 +02:00
if ( $conf -> global -> SOCIETE_ADD_REF_IN_LIST ) {
if (( $obj -> client ) && ( ! empty ( $obj -> code_client ))) {
2019-11-08 15:51:54 +01:00
$label = $obj -> code_client . ' - ' ;
2017-10-07 13:09:31 +02:00
}
if (( $obj -> fournisseur ) && ( ! empty ( $obj -> code_fournisseur ))) {
2019-11-08 15:51:54 +01:00
$label .= $obj -> code_fournisseur . ' - ' ;
2017-10-07 13:09:31 +02:00
}
2019-11-08 15:51:54 +01:00
$label .= ' ' . $obj -> name ;
2020-05-21 15:05:19 +02:00
} else {
2019-11-08 15:51:54 +01:00
$label = $obj -> name ;
2017-10-07 13:09:31 +02:00
}
2013-10-12 11:58:38 +02:00
2019-11-08 15:51:54 +01:00
if ( ! empty ( $obj -> name_alias )) {
$label .= ' (' . $obj -> name_alias . ')' ;
2015-11-16 19:10:20 +01:00
}
2021-02-23 22:03:23 +01:00
if ( $showtype ) {
if ( $obj -> client || $obj -> fournisseur ) {
$label .= ' (' ;
}
if ( $obj -> client == 1 || $obj -> client == 3 ) {
$label .= $langs -> trans ( " Customer " );
}
if ( $obj -> client == 2 || $obj -> client == 3 ) {
$label .= ( $obj -> client == 3 ? ', ' : '' ) . $langs -> trans ( " Prospect " );
}
if ( $obj -> fournisseur ) {
$label .= ( $obj -> client ? ', ' : '' ) . $langs -> trans ( " Supplier " );
}
if ( $obj -> client || $obj -> fournisseur ) {
$label .= ')' ;
}
2017-10-07 13:09:31 +02:00
}
2013-06-05 22:01:35 +02:00
2020-10-31 14:32:18 +01:00
if ( ! empty ( $conf -> global -> COMPANY_SHOW_ADDRESS_SELECTLIST )) {
2020-10-17 15:53:31 +02:00
$label .= ( $obj -> address ? ' - ' . $obj -> address : '' ) . ( $obj -> zip ? ' - ' . $obj -> zip : '' ) . ( $obj -> town ? ' ' . $obj -> town : '' );
2018-08-06 10:52:10 +02:00
if ( ! empty ( $obj -> country_code )) {
2020-10-17 15:53:31 +02:00
$label .= ', ' . $langs -> trans ( 'Country' . $obj -> country_code );
2018-08-06 10:52:10 +02:00
}
}
2013-06-05 22:01:35 +02:00
2021-02-23 22:03:23 +01:00
if ( empty ( $outputmode )) {
if ( in_array ( $obj -> rowid , $selected )) {
2019-11-08 15:51:54 +01:00
$out .= '<option value="' . $obj -> rowid . '" selected>' . $label . '</option>' ;
2020-05-21 15:05:19 +02:00
} else {
2019-11-08 15:51:54 +01:00
$out .= '<option value="' . $obj -> rowid . '">' . $label . '</option>' ;
2017-10-25 22:02:07 +02:00
}
2020-05-21 15:05:19 +02:00
} else {
2017-10-25 22:02:07 +02:00
array_push ( $outarray , array ( 'key' => $obj -> rowid , 'value' => $label , 'label' => $label ));
2017-10-07 13:09:31 +02:00
}
2010-11-18 23:17:44 +01:00
2017-10-07 13:09:31 +02:00
$i ++ ;
2021-02-23 22:03:23 +01:00
if (( $i % 10 ) == 0 ) {
$out .= " \n " ;
}
2013-07-18 09:41:37 +02:00
}
2017-10-07 13:09:31 +02:00
}
2019-11-08 15:51:54 +01:00
$out .= '</select>' . " \n " ;
2020-05-21 15:05:19 +02:00
} else {
2017-10-07 13:09:31 +02:00
dol_print_error ( $this -> db );
}
2014-04-16 00:06:16 +02:00
2019-11-08 15:51:54 +01:00
$this -> result = array ( 'nbofthirdparties' => $num );
2010-08-22 17:46:34 +02:00
2021-02-23 22:03:23 +01:00
if ( $outputmode ) {
return $outarray ;
}
2017-10-07 13:09:31 +02:00
return $out ;
}
2010-08-22 17:46:34 +02:00
2011-02-09 19:20:00 +01:00
2020-04-18 15:11:38 +02:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2017-10-07 13:09:31 +02:00
/**
2019-02-26 23:15:28 +01:00
* Return HTML combo list of absolute discounts
2017-10-07 13:09:31 +02:00
*
2019-02-26 23:15:28 +01:00
* @ param string $selected Id remise fixe pre - selectionnee
* @ param string $htmlname Nom champ formulaire
* @ param string $filter Criteres optionnels de filtre
* @ param int $socid Id of thirdparty
* @ param int $maxvalue Max value for lines that can be selected
* @ return int Return number of qualifed lines in list
2017-10-07 13:09:31 +02:00
*/
2020-04-18 15:11:38 +02:00
public function select_remises ( $selected , $htmlname , $filter , $socid , $maxvalue = 0 )
2017-10-07 13:09:31 +02:00
{
2020-04-18 15:11:38 +02:00
// phpcs:enable
2019-11-08 15:51:54 +01:00
global $langs , $conf ;
2017-10-07 13:09:31 +02:00
// On recherche les remises
$sql = " SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc, " ;
2019-11-08 15:51:54 +01:00
$sql .= " re.description, re.fk_facture_source " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " societe_remise_except as re " ;
$sql .= " WHERE re.fk_soc = " . ( int ) $socid ;
$sql .= " AND re.entity = " . $conf -> entity ;
2021-02-23 22:03:23 +01:00
if ( $filter ) {
$sql .= " AND " . $filter ;
}
2019-11-08 15:51:54 +01:00
$sql .= " ORDER BY re.description ASC " ;
2017-10-07 13:09:31 +02:00
dol_syslog ( get_class ( $this ) . " ::select_remises " , LOG_DEBUG );
2019-11-08 15:51:54 +01:00
$resql = $this -> db -> query ( $sql );
2021-02-23 22:03:23 +01:00
if ( $resql ) {
2018-12-07 17:28:31 +01:00
print '<select id="select_' . $htmlname . '" class="flat maxwidthonsmartphone" name="' . $htmlname . '">' ;
2017-10-07 13:09:31 +02:00
$num = $this -> db -> num_rows ( $resql );
2010-08-22 17:46:34 +02:00
2019-11-08 15:51:54 +01:00
$qualifiedlines = $num ;
2013-06-23 18:33:03 +02:00
2017-10-07 13:09:31 +02:00
$i = 0 ;
2021-02-23 22:03:23 +01:00
if ( $num ) {
2017-10-07 13:09:31 +02:00
print '<option value="0"> </option>' ;
2021-02-23 22:03:23 +01:00
while ( $i < $num ) {
2017-10-07 13:09:31 +02:00
$obj = $this -> db -> fetch_object ( $resql );
2019-11-08 15:51:54 +01:00
$desc = dol_trunc ( $obj -> description , 40 );
2021-02-23 22:03:23 +01:00
if ( preg_match ( '/\(CREDIT_NOTE\)/' , $desc )) {
$desc = preg_replace ( '/\(CREDIT_NOTE\)/' , $langs -> trans ( " CreditNote " ), $desc );
}
if ( preg_match ( '/\(DEPOSIT\)/' , $desc )) {
$desc = preg_replace ( '/\(DEPOSIT\)/' , $langs -> trans ( " Deposit " ), $desc );
}
if ( preg_match ( '/\(EXCESS RECEIVED\)/' , $desc )) {
$desc = preg_replace ( '/\(EXCESS RECEIVED\)/' , $langs -> trans ( " ExcessReceived " ), $desc );
}
if ( preg_match ( '/\(EXCESS PAID\)/' , $desc )) {
$desc = preg_replace ( '/\(EXCESS PAID\)/' , $langs -> trans ( " ExcessPaid " ), $desc );
}
2017-02-21 09:22:50 +01:00
2019-11-08 15:51:54 +01:00
$selectstring = '' ;
2021-02-23 22:03:23 +01:00
if ( $selected > 0 && $selected == $obj -> rowid ) {
$selectstring = ' selected' ;
}
2017-10-07 13:09:31 +02:00
2019-11-08 15:51:54 +01:00
$disabled = '' ;
2021-02-23 22:03:23 +01:00
if ( $maxvalue > 0 && $obj -> amount_ttc > $maxvalue ) {
2017-10-07 13:09:31 +02:00
$qualifiedlines -- ;
2019-11-08 15:51:54 +01:00
$disabled = ' disabled' ;
2015-06-03 21:01:50 +02:00
}
2010-08-22 17:46:34 +02:00
2021-02-23 22:03:23 +01:00
if ( ! empty ( $conf -> global -> MAIN_SHOW_FACNUMBER_IN_DISCOUNT_LIST ) && ! empty ( $obj -> fk_facture_source )) {
2017-10-13 09:21:37 +02:00
$tmpfac = new Facture ( $this -> db );
2021-02-23 22:03:23 +01:00
if ( $tmpfac -> fetch ( $obj -> fk_facture_source ) > 0 ) {
$desc = $desc . ' - ' . $tmpfac -> ref ;
}
2017-10-13 09:21:37 +02:00
}
2017-10-12 09:59:25 +02:00
2017-10-07 13:09:31 +02:00
print '<option value="' . $obj -> rowid . '"' . $selectstring . $disabled . '>' . $desc . ' (' . price ( $obj -> amount_ht ) . ' ' . $langs -> trans ( " HT " ) . ' - ' . price ( $obj -> amount_ttc ) . ' ' . $langs -> trans ( " TTC " ) . ')</option>' ;
$i ++ ;
}
}
print '</select>' ;
return $qualifiedlines ;
2020-05-21 15:05:19 +02:00
} else {
2017-10-07 13:09:31 +02:00
dol_print_error ( $this -> db );
return - 1 ;
}
}
2010-08-22 17:46:34 +02:00
2020-04-18 15:11:38 +02:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2017-10-07 13:09:31 +02:00
/**
2019-02-26 23:15:28 +01:00
* Return list of all contacts ( for a third party or all )
2017-10-07 13:09:31 +02:00
*
2019-02-26 23:15:28 +01:00
* @ param int $socid Id ot third party or 0 for all
* @ param string $selected Id contact pre - selectionne
* @ param string $htmlname Name of HTML field ( 'none' for a not editable field )
* @ param int $showempty 0 = no empty value , 1 = add an empty value , 2 = add line 'Internal' ( used by user edit ), 3 = add an empty value only if more than one record into list
* @ param string $exclude List of contacts id to exclude
* @ param string $limitto Disable answers that are not id in this array list
* @ param integer $showfunction Add function into label
* @ param string $moreclass Add more class to class style
* @ param integer $showsoc Add company into label
* @ param int $forcecombo Force to use combo box
2017-10-07 13:09:31 +02:00
* @ param array $events Event options . Example : array ( array ( 'method' => 'getContacts' , 'url' => dol_buildpath ( '/core/ajax/contacts.php' , 1 ), 'htmlname' => 'contactid' , 'params' => array ( 'add-customer-contact' => 'disabled' )))
* @ param bool $options_only Return options only ( for ajax treatment )
2017-11-22 14:42:47 +01:00
* @ param string $moreparam Add more parameters onto the select tag . For example 'style="width: 95%"' to avoid select2 component to go over parent container
2017-11-18 11:54:21 +01:00
* @ param string $htmlid Html id to use instead of htmlname
2019-02-26 23:15:28 +01:00
* @ return int < 0 if KO , Nb of contact in list if OK
2020-11-29 15:16:53 +01:00
* @ deprecated You can use selectcontacts directly ( warning order of param was changed )
2017-10-07 13:09:31 +02:00
*/
2020-04-18 15:11:38 +02:00
public function select_contacts ( $socid , $selected = '' , $htmlname = 'contactid' , $showempty = 0 , $exclude = '' , $limitto = '' , $showfunction = 0 , $moreclass = '' , $showsoc = 0 , $forcecombo = 0 , $events = array (), $options_only = false , $moreparam = '' , $htmlid = '' )
{
// phpcs:enable
2019-01-27 11:55:16 +01:00
print $this -> selectcontacts ( $socid , $selected , $htmlname , $showempty , $exclude , $limitto , $showfunction , $moreclass , $options_only , $showsoc , $forcecombo , $events , $moreparam , $htmlid );
2017-10-07 13:09:31 +02:00
return $this -> num ;
2020-04-18 15:11:38 +02:00
}
2010-08-22 17:46:34 +02:00
2017-10-07 13:09:31 +02:00
/**
* Return HTML code of the SELECT of list of all contacts ( for a third party or all ) .
* This also set the number of contacts found into $this -> num
*
2018-12-14 17:32:41 +01:00
* @ since 9.0 Add afterSelectContactOptions hook
2018-11-19 17:40:16 +01:00
*
2018-07-16 10:46:10 +02:00
* @ param int $socid Id ot third party or 0 for all or - 1 for empty list
2017-11-23 00:59:43 +01:00
* @ param array | int $selected Array of ID of pre - selected contact id
* @ param string $htmlname Name of HTML field ( 'none' for a not editable field )
2018-07-16 10:46:10 +02:00
* @ param int $showempty 0 = no empty value , 1 = add an empty value , 2 = add line 'Internal' ( used by user edit ), 3 = add an empty value only if more than one record into list
2017-11-23 00:59:43 +01:00
* @ param string $exclude List of contacts id to exclude
* @ param string $limitto Disable answers that are not id in this array list
* @ param integer $showfunction Add function into label
* @ param string $moreclass Add more class to class style
* @ param bool $options_only Return options only ( for ajax treatment )
* @ param integer $showsoc Add company into label
2018-08-24 15:25:18 +02:00
* @ param int $forcecombo Force to use combo box ( so no ajax beautify effect )
2017-11-23 00:59:43 +01:00
* @ param array $events Event options . Example : array ( array ( 'method' => 'getContacts' , 'url' => dol_buildpath ( '/core/ajax/contacts.php' , 1 ), 'htmlname' => 'contactid' , 'params' => array ( 'add-customer-contact' => 'disabled' )))
* @ param string $moreparam Add more parameters onto the select tag . For example 'style="width: 95%"' to avoid select2 component to go over parent container
* @ param string $htmlid Html id to use instead of htmlname
2018-06-29 11:48:54 +02:00
* @ param bool $multiple add [] in the name of element and add 'multiple' attribut
2020-12-03 14:34:15 +01:00
* @ param integer $disableifempty Set tag 'disabled' on select if there is no choice
2021-01-31 18:06:02 +01:00
* @ return int | string < 0 if KO , HTML with select string if OK .
2017-10-07 13:09:31 +02:00
*/
2020-12-03 14:34:15 +01:00
public function selectcontacts ( $socid , $selected = '' , $htmlname = 'contactid' , $showempty = 0 , $exclude = '' , $limitto = '' , $showfunction = 0 , $moreclass = '' , $options_only = false , $showsoc = 0 , $forcecombo = 0 , $events = array (), $moreparam = '' , $htmlid = '' , $multiple = false , $disableifempty = 0 )
2020-04-18 15:11:38 +02:00
{
2019-11-08 15:51:54 +01:00
global $conf , $langs , $hookmanager , $action ;
2012-03-19 17:18:11 +01:00
2017-10-07 13:09:31 +02:00
$langs -> load ( 'companies' );
2012-03-19 17:18:11 +01:00
2021-02-23 22:03:23 +01:00
if ( empty ( $htmlid )) {
$htmlid = $htmlname ;
}
2020-11-30 12:35:05 +01:00
$num = 0 ;
2018-07-09 15:39:59 +02:00
2021-02-23 22:03:23 +01:00
if ( $selected === '' ) {
$selected = array ();
} elseif ( ! is_array ( $selected )) {
$selected = array ( $selected );
}
2019-11-08 15:51:54 +01:00
$out = '' ;
2011-02-09 20:22:40 +01:00
2021-02-23 22:03:23 +01:00
if ( ! is_object ( $hookmanager )) {
2018-11-19 17:40:16 +01:00
include_once DOL_DOCUMENT_ROOT . '/core/class/hookmanager.class.php' ;
2019-11-08 15:51:54 +01:00
$hookmanager = new HookManager ( $this -> db );
2018-11-19 17:40:16 +01:00
}
2018-12-14 17:32:41 +01:00
// We search third parties
2020-11-18 13:14:29 +01:00
$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 " ;
2021-02-23 22:03:23 +01:00
if ( $showsoc > 0 || ! empty ( $conf -> global -> CONTACT_SHOW_EMAIL_PHONE_TOWN_SELECTLIST )) {
$sql .= " , s.nom as company, s.town AS company_town " ;
}
2019-11-08 15:51:54 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " socpeople as sp " ;
2021-02-23 22:03:23 +01:00
if ( $showsoc > 0 || ! empty ( $conf -> global -> CONTACT_SHOW_EMAIL_PHONE_TOWN_SELECTLIST )) {
$sql .= " LEFT OUTER JOIN " . MAIN_DB_PREFIX . " societe as s ON s.rowid=sp.fk_soc " ;
}
2019-11-08 15:51:54 +01:00
$sql .= " WHERE sp.entity IN ( " . getEntity ( 'socpeople' ) . " ) " ;
2021-02-23 22:03:23 +01:00
if ( $socid > 0 || $socid == - 1 ) {
$sql .= " AND sp.fk_soc= " . $socid ;
}
if ( ! empty ( $conf -> global -> CONTACT_HIDE_INACTIVE_IN_COMBOBOX )) {
$sql .= " AND sp.statut <> 0 " ;
}
2019-11-08 15:51:54 +01:00
$sql .= " ORDER BY sp.lastname ASC " ;
2017-10-07 13:09:31 +02:00
2021-02-09 18:09:35 +01:00
dol_syslog ( get_class ( $this ) . " ::selectcontacts " , LOG_DEBUG );
2019-11-08 15:51:54 +01:00
$resql = $this -> db -> query ( $sql );
2021-02-23 22:03:23 +01:00
if ( $resql ) {
2019-11-08 15:51:54 +01:00
$num = $this -> db -> num_rows ( $resql );
2017-10-07 13:09:31 +02:00
2021-02-23 22:03:23 +01:00
if ( $conf -> use_javascript_ajax && ! $forcecombo && ! $options_only ) {
2019-11-08 15:51:54 +01:00
include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php' ;
2017-11-24 09:23:18 +01:00
$out .= ajax_combobox ( $htmlid , $events , $conf -> global -> CONTACT_USE_SEARCH_TO_SELECT );
2017-10-07 13:09:31 +02:00
}
2010-08-22 17:46:34 +02:00
2020-12-03 14:34:15 +01:00
if ( $htmlname != 'none' && ! $options_only ) {
2020-12-04 01:59:47 +01:00
$out .= '<select class="flat' . ( $moreclass ? ' ' . $moreclass : '' ) . '" id="' . $htmlid . '" name="' . $htmlname . (( $num || empty ( $disableifempty )) ? '' : ' disabled' ) . ( $multiple ? '[]' : '' ) . '" ' . ( $multiple ? 'multiple' : '' ) . ' ' . ( ! empty ( $moreparam ) ? $moreparam : '' ) . '>' ;
2020-12-03 14:34:15 +01:00
}
2021-02-23 22:03:23 +01:00
if (( $showempty == 1 || ( $showempty == 3 && $num > 1 )) && ! $multiple ) {
$out .= '<option value="0"' . ( in_array ( 0 , $selected ) ? ' selected' : '' ) . '> </option>' ;
}
if ( $showempty == 2 ) {
$out .= '<option value="0"' . ( in_array ( 0 , $selected ) ? ' selected' : '' ) . '>-- ' . $langs -> trans ( " Internal " ) . ' --</option>' ;
}
2018-12-22 19:06:58 +01:00
2017-10-07 13:09:31 +02:00
$i = 0 ;
2021-02-23 22:03:23 +01:00
if ( $num ) {
2017-10-07 13:09:31 +02:00
include_once DOL_DOCUMENT_ROOT . '/contact/class/contact.class.php' ;
2019-11-08 15:51:54 +01:00
$contactstatic = new Contact ( $this -> db );
2011-02-09 19:20:00 +01:00
2021-02-23 22:03:23 +01:00
while ( $i < $num ) {
2017-10-07 13:09:31 +02:00
$obj = $this -> db -> fetch_object ( $resql );
2011-02-09 19:20:00 +01:00
2020-11-18 09:41:42 +01:00
// Set email (or phones) and town extended infos
$extendedInfos = '' ;
if ( ! empty ( $conf -> global -> CONTACT_SHOW_EMAIL_PHONE_TOWN_SELECTLIST )) {
$extendedInfos = array ();
$email = trim ( $obj -> email );
2021-02-23 22:03:23 +01:00
if ( ! empty ( $email )) {
$extendedInfos [] = $email ;
} else {
2020-11-18 09:41:42 +01:00
$phone = trim ( $obj -> phone );
$phone_perso = trim ( $obj -> phone_perso );
$phone_mobile = trim ( $obj -> phone_mobile );
2021-02-23 22:03:23 +01:00
if ( ! empty ( $phone )) {
$extendedInfos [] = $phone ;
}
if ( ! empty ( $phone_perso )) {
$extendedInfos [] = $phone_perso ;
}
if ( ! empty ( $phone_mobile )) {
$extendedInfos [] = $phone_mobile ;
}
2020-11-18 09:41:42 +01:00
}
$contact_town = trim ( $obj -> contact_town );
$company_town = trim ( $obj -> company_town );
2021-02-23 22:03:23 +01:00
if ( ! empty ( $contact_town )) {
$extendedInfos [] = $contact_town ;
} elseif ( ! empty ( $company_town )) {
$extendedInfos [] = $company_town ;
}
2020-11-18 09:41:42 +01:00
$extendedInfos = implode ( ' - ' , $extendedInfos );
2021-02-23 22:03:23 +01:00
if ( ! empty ( $extendedInfos )) {
$extendedInfos = ' - ' . $extendedInfos ;
}
2020-11-18 09:41:42 +01:00
}
2019-11-08 15:51:54 +01:00
$contactstatic -> id = $obj -> rowid ;
$contactstatic -> lastname = $obj -> lastname ;
$contactstatic -> firstname = $obj -> firstname ;
2019-02-03 22:58:56 +01:00
if ( $obj -> statut == 1 ) {
2021-02-23 22:03:23 +01:00
if ( $htmlname != 'none' ) {
2020-04-18 15:11:38 +02:00
$disabled = 0 ;
2021-02-23 22:03:23 +01:00
if ( is_array ( $exclude ) && count ( $exclude ) && in_array ( $obj -> rowid , $exclude )) {
$disabled = 1 ;
}
if ( is_array ( $limitto ) && count ( $limitto ) && ! in_array ( $obj -> rowid , $limitto )) {
$disabled = 1 ;
}
if ( ! empty ( $selected ) && in_array ( $obj -> rowid , $selected )) {
2020-04-18 15:11:38 +02:00
$out .= '<option value="' . $obj -> rowid . '"' ;
2021-02-23 22:03:23 +01:00
if ( $disabled ) {
$out .= ' disabled' ;
}
2020-04-18 15:11:38 +02:00
$out .= ' selected>' ;
2020-12-01 02:41:19 +01:00
$out .= $contactstatic -> getFullName ( $langs ) . $extendedInfos ;
2021-02-23 22:03:23 +01:00
if ( $showfunction && $obj -> poste ) {
$out .= ' (' . $obj -> poste . ')' ;
}
if (( $showsoc > 0 ) && $obj -> company ) {
$out .= ' - (' . $obj -> company . ')' ;
}
2020-04-18 15:11:38 +02:00
$out .= '</option>' ;
2020-05-21 15:05:19 +02:00
} else {
2020-04-18 15:11:38 +02:00
$out .= '<option value="' . $obj -> rowid . '"' ;
2021-02-23 22:03:23 +01:00
if ( $disabled ) {
$out .= ' disabled' ;
}
2020-04-18 15:11:38 +02:00
$out .= '>' ;
2020-12-01 02:41:19 +01:00
$out .= $contactstatic -> getFullName ( $langs ) . $extendedInfos ;
2021-02-23 22:03:23 +01:00
if ( $showfunction && $obj -> poste ) {
$out .= ' (' . $obj -> poste . ')' ;
}
if (( $showsoc > 0 ) && $obj -> company ) {
$out .= ' - (' . $obj -> company . ')' ;
}
2020-04-18 15:11:38 +02:00
$out .= '</option>' ;
}
2020-05-21 15:05:19 +02:00
} else {
2021-02-23 22:03:23 +01:00
if ( in_array ( $obj -> rowid , $selected )) {
2020-12-01 02:41:19 +01:00
$out .= $contactstatic -> getFullName ( $langs ) . $extendedInfos ;
2021-02-23 22:03:23 +01:00
if ( $showfunction && $obj -> poste ) {
$out .= ' (' . $obj -> poste . ')' ;
}
if (( $showsoc > 0 ) && $obj -> company ) {
$out .= ' - (' . $obj -> company . ')' ;
}
2020-04-18 15:11:38 +02:00
}
}
}
2017-10-07 13:09:31 +02:00
$i ++ ;
}
2020-05-21 15:05:19 +02:00
} else {
2020-11-29 15:16:53 +01:00
$labeltoshow = ( $socid != - 1 ) ? ( $langs -> trans ( $socid ? " NoContactDefinedForThirdParty " : " NoContactDefined " )) : $langs -> trans ( 'SelectAThirdPartyFirst' );
$out .= '<option class="disabled" value="-1"' . (( $showempty == 2 || $multiple ) ? '' : ' selected' ) . ' disabled="disabled">' ;
$out .= $labeltoshow ;
2019-11-08 15:51:54 +01:00
$out .= '</option>' ;
2017-10-07 13:09:31 +02:00
}
2018-11-19 17:40:16 +01:00
$parameters = array (
'socid' => $socid ,
'htmlname' => $htmlname ,
'resql' => $resql ,
'out' =>& $out ,
'showfunction' => $showfunction ,
'showsoc' => $showsoc ,
);
2019-11-08 15:51:54 +01:00
$reshook = $hookmanager -> executeHooks ( 'afterSelectContactOptions' , $parameters , $this , $action ); // Note that $action and $object may have been modified by some hooks
2018-11-19 17:40:16 +01:00
2021-02-23 22:03:23 +01:00
if ( $htmlname != 'none' && ! $options_only ) {
2019-11-08 15:51:54 +01:00
$out .= '</select>' ;
2017-10-07 13:09:31 +02:00
}
2012-03-19 17:18:11 +01:00
2017-10-07 13:09:31 +02:00
$this -> num = $num ;
return $out ;
2020-05-21 15:05:19 +02:00
} else {
2017-10-07 13:09:31 +02:00
dol_print_error ( $this -> db );
return - 1 ;
}
}
2010-09-02 21:31:18 +02:00
2020-04-18 15:11:38 +02:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2017-10-07 13:09:31 +02:00
/**
2020-05-04 21:59:31 +02:00
* Return the HTML select list of users
2017-10-07 13:09:31 +02:00
*
2020-05-04 21:59:31 +02:00
* @ param string $selected Id user preselected
* @ param string $htmlname Field name in form
* @ param int $show_empty 0 = liste sans valeur nulle , 1 = ajoute valeur inconnue
* @ param array $exclude Array list of users id to exclude
* @ param int $disabled If select list must be disabled
* @ param array | string $include Array list of users id to include . User '' for all users or 'hierarchy' to have only supervised users or 'hierarchyme' to have supervised + me
* @ param int $enableonly Array list of users id to be enabled . All other must be disabled
* @ param string $force_entity '0' or Ids of environment to force
2017-10-07 13:09:31 +02:00
* @ return void
* @ deprecated Use select_dolusers instead
* @ see select_dolusers ()
*/
2020-04-18 15:11:38 +02:00
public function select_users ( $selected = '' , $htmlname = 'userid' , $show_empty = 0 , $exclude = null , $disabled = 0 , $include = '' , $enableonly = '' , $force_entity = '0' )
2017-10-07 13:09:31 +02:00
{
2020-04-18 15:11:38 +02:00
// phpcs:enable
2019-01-27 11:55:16 +01:00
print $this -> select_dolusers ( $selected , $htmlname , $show_empty , $exclude , $disabled , $include , $enableonly , $force_entity );
2017-10-07 13:09:31 +02:00
}
2010-09-01 22:51:10 +02:00
2020-04-18 15:11:38 +02:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2017-10-07 13:09:31 +02:00
/**
* Return select list of users
*
2020-05-05 15:16:30 +02:00
* @ param string $selected User id or user object of user preselected . If 0 or < - 2 , we use id of current user . If - 1 , keep unselected ( if empty is allowed )
* @ param string $htmlname Field name in form
2021-03-27 13:17:56 +01:00
* @ param int | string $show_empty 0 = list with no empty value , 1 = add also an empty value into list
2020-05-05 15:16:30 +02:00
* @ param array $exclude Array list of users id to exclude
* @ param int $disabled If select list must be disabled
* @ param array | string $include Array list of users id to include . User '' for all users or 'hierarchy' to have only supervised users or 'hierarchyme' to have supervised + me
* @ param array $enableonly Array list of users id to be enabled . If defined , it means that others will be disabled
* @ param string $force_entity '0' or Ids of environment to force
* @ param int $maxlength Maximum length of string into list ( 0 = no limit )
* @ param int $showstatus 0 = show user status only if status is disabled , 1 = always show user status into label , - 1 = never show user status
2021-06-14 13:51:09 +02:00
* @ param string $morefilter Add more filters into sql request ( Example : 'employee = 1' ) . This value must not come from user input .
2020-05-05 15:16:30 +02:00
* @ param integer $show_every 0 = default list , 1 = add also a value " Everybody " at beginning of list
* @ param string $enableonlytext If option $enableonlytext is set , we use this text to explain into label why record is disabled . Not used if enableonly is empty .
* @ param string $morecss More css
* @ param int $noactive Show only active users ( this will also happened whatever is this option if USER_HIDE_INACTIVE_IN_COMBOBOX is on ) .
* @ param int $outputmode 0 = HTML select string , 1 = Array
* @ param bool $multiple add [] in the name of element and add 'multiple' attribut
* @ return string HTML select string
2019-03-19 13:14:44 +01:00
* @ see select_dolgroups ()
2017-10-07 13:09:31 +02:00
*/
2020-04-18 15:11:38 +02:00
public function select_dolusers ( $selected = '' , $htmlname = 'userid' , $show_empty = 0 , $exclude = null , $disabled = 0 , $include = '' , $enableonly = '' , $force_entity = '0' , $maxlength = 0 , $showstatus = 0 , $morefilter = '' , $show_every = 0 , $enableonlytext = '' , $morecss = '' , $noactive = 0 , $outputmode = 0 , $multiple = false )
2017-10-07 13:09:31 +02:00
{
2020-04-18 15:11:38 +02:00
// phpcs:enable
2020-03-16 11:49:03 +01:00
global $conf , $user , $langs , $hookmanager ;
2011-02-06 23:23:03 +01:00
2017-10-07 13:09:31 +02:00
// If no preselected user defined, we take current user
2021-02-23 22:03:23 +01:00
if (( is_numeric ( $selected ) && ( $selected < - 2 || empty ( $selected ))) && empty ( $conf -> global -> SOCIETE_DISABLE_DEFAULT_SALESREPRESENTATIVE )) {
$selected = $user -> id ;
}
2010-08-22 17:46:34 +02:00
2021-02-23 22:03:23 +01:00
if ( $selected === '' ) {
$selected = array ();
} elseif ( ! is_array ( $selected )) {
$selected = array ( $selected );
}
2014-10-30 11:16:01 +01:00
2019-11-08 15:51:54 +01:00
$excludeUsers = null ;
$includeUsers = null ;
2017-10-07 13:09:31 +02:00
// Permettre l'exclusion d'utilisateurs
2021-02-23 22:03:23 +01:00
if ( is_array ( $exclude )) {
$excludeUsers = implode ( " , " , $exclude );
}
2017-10-07 13:09:31 +02:00
// Permettre l'inclusion d'utilisateurs
2021-02-23 22:03:23 +01:00
if ( is_array ( $include )) {
$includeUsers = implode ( " , " , $include );
} elseif ( $include == 'hierarchy' ) {
2014-08-11 10:54:32 +02:00
// Build list includeUsers to have only hierarchy
2019-01-27 11:55:16 +01:00
$includeUsers = implode ( " , " , $user -> getAllChildIds ( 0 ));
2021-02-23 22:03:23 +01:00
} elseif ( $include == 'hierarchyme' ) {
2017-10-07 13:09:31 +02:00
// Build list includeUsers to have only hierarchy and current user
2019-01-27 11:55:16 +01:00
$includeUsers = implode ( " , " , $user -> getAllChildIds ( 1 ));
2017-01-26 18:08:00 +01:00
}
2014-08-14 01:04:15 +02:00
2019-12-16 13:06:25 +01:00
$out = '' ;
2018-03-09 18:59:06 +01:00
$outarray = array ();
2010-08-22 17:46:34 +02:00
2017-12-18 11:55:34 +01:00
// Forge request to select users
2020-10-17 13:27:39 +02:00
$sql = " SELECT DISTINCT u.rowid, u.lastname as lastname, u.firstname, u.statut as status, u.login, u.admin, u.entity, u.photo " ;
2021-02-23 22:03:23 +01:00
if ( ! empty ( $conf -> multicompany -> enabled ) && $conf -> entity == 1 && $user -> admin && ! $user -> entity ) {
2019-12-16 13:06:25 +01:00
$sql .= " , e.label " ;
2017-10-07 13:09:31 +02:00
}
2019-12-16 13:06:25 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " user as u " ;
2021-02-23 22:03:23 +01:00
if ( ! empty ( $conf -> multicompany -> enabled ) && $conf -> entity == 1 && $user -> admin && ! $user -> entity ) {
2021-06-14 13:51:09 +02:00
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " entity as e ON e.rowid = u.entity " ;
2021-02-23 22:03:23 +01:00
if ( $force_entity ) {
2021-06-14 13:51:09 +02:00
$sql .= " WHERE u.entity IN (0, " . $this -> db -> sanitize ( $force_entity ) . " ) " ;
2021-02-23 22:03:23 +01:00
} else {
$sql .= " WHERE u.entity IS NOT NULL " ;
}
2020-05-21 15:05:19 +02:00
} else {
2021-02-23 22:03:23 +01:00
if ( ! empty ( $conf -> global -> MULTICOMPANY_TRANSVERSE_MODE )) {
2019-12-16 13:06:25 +01:00
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " usergroup_user as ug " ;
$sql .= " ON ug.fk_user = u.rowid " ;
$sql .= " WHERE ug.entity = " . $conf -> entity ;
2020-05-21 15:05:19 +02:00
} else {
2021-03-22 12:47:23 +01:00
$sql .= " WHERE u.entity IN (0, " . $conf -> entity . " ) " ;
2017-10-07 13:09:31 +02:00
}
}
2021-02-23 22:03:23 +01:00
if ( ! empty ( $user -> socid )) {
2021-06-14 13:51:09 +02:00
$sql .= " AND u.fk_soc = " . (( int ) $user -> socid );
2021-02-23 22:03:23 +01:00
}
if ( is_array ( $exclude ) && $excludeUsers ) {
2021-03-22 11:30:18 +01:00
$sql .= " AND u.rowid NOT IN ( " . $this -> db -> sanitize ( $excludeUsers ) . " ) " ;
2021-02-23 22:03:23 +01:00
}
if ( $includeUsers ) {
2021-03-22 11:30:18 +01:00
$sql .= " AND u.rowid IN ( " . $this -> db -> sanitize ( $includeUsers ) . " ) " ;
2021-02-23 22:03:23 +01:00
}
if ( ! empty ( $conf -> global -> USER_HIDE_INACTIVE_IN_COMBOBOX ) || $noactive ) {
$sql .= " AND u.statut <> 0 " ;
}
if ( ! empty ( $morefilter )) {
$sql .= " " . $morefilter ;
}
2017-02-21 09:22:50 +01:00
2020-03-16 11:49:03 +01:00
//Add hook to filter on user (for exemple on usergroup define in custom modules)
$reshook = $hookmanager -> executeHooks ( 'addSQLWhereFilterOnSelectUsers' , array (), $this , $action );
2021-02-23 22:03:23 +01:00
if ( ! empty ( $reshook )) {
$sql .= $hookmanager -> resPrint ;
}
2020-03-16 11:49:03 +01:00
2021-02-23 22:03:23 +01:00
if ( empty ( $conf -> global -> MAIN_FIRSTNAME_NAME_POSITION )) { // MAIN_FIRSTNAME_NAME_POSITION is 0 means firstname+lastname
2021-03-29 11:58:51 +02:00
$sql .= " ORDER BY u.statut DESC, u.firstname ASC, u.lastname ASC " ;
2020-05-21 15:05:19 +02:00
} else {
2021-03-29 11:58:51 +02:00
$sql .= " ORDER BY u.statut DESC, u.lastname ASC, u.firstname ASC " ;
2017-10-07 13:09:31 +02:00
}
2010-08-22 17:46:34 +02:00
2017-10-07 13:09:31 +02:00
dol_syslog ( get_class ( $this ) . " ::select_dolusers " , LOG_DEBUG );
2019-12-16 13:06:25 +01:00
$resql = $this -> db -> query ( $sql );
2021-02-23 22:03:23 +01:00
if ( $resql ) {
2017-10-07 13:09:31 +02:00
$num = $this -> db -> num_rows ( $resql );
$i = 0 ;
2021-02-23 22:03:23 +01:00
if ( $num ) {
2020-04-18 15:11:38 +02:00
// Enhance with select2
2019-11-08 15:51:54 +01:00
include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php' ;
2017-11-24 09:23:18 +01:00
$out .= ajax_combobox ( $htmlname );
2014-12-22 03:14:22 +01:00
2017-10-07 13:09:31 +02:00
// do not use maxwidthonsmartphone by default. Set it by caller so auto size to 100% will work when not defined
2020-12-04 15:39:30 +01:00
$out .= '<select class="flat' . ( $morecss ? ' ' . $morecss : ' minwidth200' ) . '" id="' . $htmlname . '" name="' . $htmlname . ( $multiple ? '[]' : '' ) . '" ' . ( $multiple ? 'multiple' : '' ) . ' ' . ( $disabled ? ' disabled' : '' ) . '>' ;
2021-02-23 22:03:23 +01:00
if ( $show_empty && ! $multiple ) {
2021-03-27 13:17:56 +01:00
$textforempty = ' ' ;
if ( ! empty ( $conf -> use_javascript_ajax )) {
$textforempty = ' ' ; // If we use ajaxcombo, we need here to avoid to have an empty element that is too small.
}
if ( ! is_numeric ( $show_empty )) {
$textforempty = $show_empty ;
}
$out .= '<option class="optiongrey" value="' . ( $show_empty < 0 ? $show_empty : - 1 ) . '"' . (( empty ( $selected ) || in_array ( - 1 , $selected )) ? ' selected' : '' ) . '>' . $textforempty . '</option>' . " \n " ;
2021-02-23 22:03:23 +01:00
}
if ( $show_every ) {
$out .= '<option value="-2"' . (( in_array ( - 2 , $selected )) ? ' selected' : '' ) . '>-- ' . $langs -> trans ( " Everybody " ) . ' --</option>' . " \n " ;
}
2011-08-31 16:55:54 +02:00
2019-11-08 15:51:54 +01:00
$userstatic = new User ( $this -> db );
2011-02-09 19:20:00 +01:00
2021-02-23 22:03:23 +01:00
while ( $i < $num ) {
2017-10-07 13:09:31 +02:00
$obj = $this -> db -> fetch_object ( $resql );
2011-02-09 19:20:00 +01:00
2019-11-08 15:51:54 +01:00
$userstatic -> id = $obj -> rowid ;
$userstatic -> lastname = $obj -> lastname ;
$userstatic -> firstname = $obj -> firstname ;
2020-10-17 13:27:39 +02:00
$userstatic -> photo = $obj -> photo ;
$userstatic -> statut = $obj -> status ;
$userstatic -> entity = $obj -> entity ;
$userstatic -> admin = $obj -> admin ;
2011-02-09 19:20:00 +01:00
2019-11-08 15:51:54 +01:00
$disableline = '' ;
2021-02-23 22:03:23 +01:00
if ( is_array ( $enableonly ) && count ( $enableonly ) && ! in_array ( $obj -> rowid , $enableonly )) {
$disableline = ( $enableonlytext ? $enableonlytext : '1' );
}
2010-08-22 17:46:34 +02:00
2020-10-02 14:19:44 +02:00
$labeltoshow = '' ;
2013-06-23 18:33:03 +02:00
2018-08-13 01:10:51 +02:00
// $fullNameMode is 0=Lastname+Firstname (MAIN_FIRSTNAME_NAME_POSITION=1), 1=Firstname+Lastname (MAIN_FIRSTNAME_NAME_POSITION=0)
$fullNameMode = 0 ;
2021-02-23 22:03:23 +01:00
if ( empty ( $conf -> global -> MAIN_FIRSTNAME_NAME_POSITION )) {
2018-08-13 01:10:51 +02:00
$fullNameMode = 1 ; //Firstname+lastname
2017-10-07 13:09:31 +02:00
}
2020-10-02 14:19:44 +02:00
$labeltoshow .= $userstatic -> getFullName ( $langs , $fullNameMode , - 1 , $maxlength );
2021-02-23 22:03:23 +01:00
if ( empty ( $obj -> firstname ) && empty ( $obj -> lastname )) {
$labeltoshow .= $obj -> login ;
}
2017-02-21 09:22:50 +01:00
2017-10-07 13:09:31 +02:00
// Complete name with more info
2020-08-28 17:17:22 +02:00
$moreinfo = '' ;
2021-02-23 22:03:23 +01:00
if ( ! empty ( $conf -> global -> MAIN_SHOW_LOGIN )) {
2020-08-28 17:17:22 +02:00
$moreinfo .= ( $moreinfo ? ' - ' : ' (' ) . $obj -> login ;
2017-10-07 13:09:31 +02:00
}
2021-02-23 22:03:23 +01:00
if ( $showstatus >= 0 ) {
if ( $obj -> status == 1 && $showstatus == 1 ) {
2020-08-28 17:17:22 +02:00
$moreinfo .= ( $moreinfo ? ' - ' : ' (' ) . $langs -> trans ( 'Enabled' );
2017-10-07 13:09:31 +02:00
}
2021-02-23 22:03:23 +01:00
if ( $obj -> status == 0 && $showstatus == 1 ) {
2020-08-28 17:17:22 +02:00
$moreinfo .= ( $moreinfo ? ' - ' : ' (' ) . $langs -> trans ( 'Disabled' );
2013-07-27 14:45:55 +02:00
}
2013-07-22 11:17:45 +02:00
}
2021-02-23 22:03:23 +01:00
if ( ! empty ( $conf -> multicompany -> enabled ) && empty ( $conf -> global -> MULTICOMPANY_TRANSVERSE_MODE ) && $conf -> entity == 1 && $user -> admin && ! $user -> entity ) {
if ( ! $obj -> entity ) {
2020-08-28 17:17:22 +02:00
$moreinfo .= ( $moreinfo ? ' - ' : ' (' ) . $langs -> trans ( " AllEntities " );
2020-05-21 15:05:19 +02:00
} else {
2021-03-25 03:58:54 +01:00
if ( $obj -> entity != $conf -> entity ) {
$moreinfo .= ( $moreinfo ? ' - ' : ' (' ) . ( $obj -> label ? $obj -> label : $langs -> trans ( " EntityNameNotDefined " ));
}
2020-04-18 15:11:38 +02:00
}
2017-10-07 13:09:31 +02:00
}
2020-08-28 17:17:22 +02:00
$moreinfo .= ( $moreinfo ? ')' : '' );
2021-02-23 22:03:23 +01:00
if ( $disableline && $disableline != '1' ) {
2020-08-28 17:17:22 +02:00
$moreinfo .= ' - ' . $disableline ; // This is text from $enableonlytext parameter
2017-10-07 13:09:31 +02:00
}
2020-10-02 14:19:44 +02:00
$labeltoshow .= $moreinfo ;
$out .= '<option value="' . $obj -> rowid . '"' ;
2021-02-23 22:03:23 +01:00
if ( $disableline ) {
$out .= ' disabled' ;
}
2020-10-02 14:19:44 +02:00
if (( is_object ( $selected ) && $selected -> id == $obj -> rowid ) || ( ! is_object ( $selected ) && in_array ( $obj -> rowid , $selected ))) {
$out .= ' selected' ;
}
2020-10-17 13:27:39 +02:00
$out .= ' data-html="' ;
$outhtml = '' ;
2021-02-07 18:31:31 +01:00
// if (!empty($obj->photo)) {
$outhtml .= $userstatic -> getNomUrl ( - 3 , '' , 0 , 1 , 24 , 1 , 'login' , '' , 1 ) . ' ' ;
// }
2021-02-23 22:03:23 +01:00
if ( $showstatus >= 0 && $obj -> status == 0 ) {
$outhtml .= '<strike class="opacitymediumxxx">' ;
}
2020-10-17 13:27:39 +02:00
$outhtml .= $labeltoshow ;
2021-02-23 22:03:23 +01:00
if ( $showstatus >= 0 && $obj -> status == 0 ) {
$outhtml .= '</strike>' ;
}
2020-10-17 13:27:39 +02:00
$out .= dol_escape_htmltag ( $outhtml );
$out .= '">' ;
2020-10-02 14:19:44 +02:00
$out .= $labeltoshow ;
2019-11-08 15:51:54 +01:00
$out .= '</option>' ;
2020-10-02 14:19:44 +02:00
2020-08-28 17:17:22 +02:00
$outarray [ $userstatic -> id ] = $userstatic -> getFullName ( $langs , $fullNameMode , - 1 , $maxlength ) . $moreinfo ;
2013-07-27 14:21:47 +02:00
2017-10-07 13:09:31 +02:00
$i ++ ;
}
2020-05-21 15:05:19 +02:00
} else {
2019-11-08 15:51:54 +01:00
$out .= '<select class="flat" id="' . $htmlname . '" name="' . $htmlname . '" disabled>' ;
$out .= '<option value="">' . $langs -> trans ( " None " ) . '</option>' ;
2017-10-07 13:09:31 +02:00
}
2019-11-08 15:51:54 +01:00
$out .= '</select>' ;
2020-05-21 15:05:19 +02:00
} else {
2017-10-07 13:09:31 +02:00
dol_print_error ( $this -> db );
}
2010-09-02 21:31:18 +02:00
2021-02-23 22:03:23 +01:00
if ( $outputmode ) {
return $outarray ;
}
2017-10-07 13:09:31 +02:00
return $out ;
}
2010-08-22 17:46:34 +02:00
2020-04-18 15:11:38 +02:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2017-10-07 13:09:31 +02:00
/**
* Return select list of users . Selected users are stored into session .
* List of users are provided into $_SESSION [ 'assignedtouser' ] .
*
* @ param string $action Value for $action
* @ param string $htmlname Field name in form
2017-11-22 14:42:47 +01:00
* @ param int $show_empty 0 = list without the empty value , 1 = add empty value
2017-10-07 13:09:31 +02:00
* @ param array $exclude Array list of users id to exclude
* @ param int $disabled If select list must be disabled
* @ param array $include Array list of users id to include or 'hierarchy' to have only supervised users
* @ param array $enableonly Array list of users id to be enabled . All other must be disabled
2018-06-25 09:19:45 +02:00
* @ param int $force_entity '0' or Ids of environment to force
2017-10-07 13:09:31 +02:00
* @ param int $maxlength Maximum length of string into list ( 0 = no limit )
* @ param int $showstatus 0 = show user status only if status is disabled , 1 = always show user status into label , - 1 = never show user status
* @ param string $morefilter Add more filters into sql request
2017-11-22 14:42:47 +01:00
* @ param int $showproperties Show properties of each attendees
* @ param array $listofuserid Array with properties of each user
* @ param array $listofcontactid Array with properties of each contact
2017-11-22 21:36:01 +01:00
* @ param array $listofotherid Array with properties of each other contact
2017-10-07 13:09:31 +02:00
* @ return string HTML select string
2019-03-19 13:14:44 +01:00
* @ see select_dolgroups ()
2017-10-07 13:09:31 +02:00
*/
2020-04-18 15:11:38 +02:00
public function select_dolusers_forevent ( $action = '' , $htmlname = 'userid' , $show_empty = 0 , $exclude = null , $disabled = 0 , $include = '' , $enableonly = '' , $force_entity = '0' , $maxlength = 0 , $showstatus = 0 , $morefilter = '' , $showproperties = 0 , $listofuserid = array (), $listofcontactid = array (), $listofotherid = array ())
2017-10-07 13:09:31 +02:00
{
2020-04-18 15:11:38 +02:00
// phpcs:enable
2017-11-22 14:42:47 +01:00
global $conf , $user , $langs ;
2014-09-09 14:38:10 +02:00
2019-11-08 15:51:54 +01:00
$userstatic = new User ( $this -> db );
$out = '' ;
2014-09-09 14:38:10 +02:00
2020-09-14 20:53:42 +02:00
2019-11-08 15:51:54 +01:00
$assignedtouser = array ();
2021-02-23 22:03:23 +01:00
if ( ! empty ( $_SESSION [ 'assignedtouser' ])) {
2019-11-08 15:51:54 +01:00
$assignedtouser = json_decode ( $_SESSION [ 'assignedtouser' ], true );
2014-09-23 16:15:15 +02:00
}
2019-11-08 15:51:54 +01:00
$nbassignetouser = count ( $assignedtouser );
2014-09-26 12:27:18 +02:00
2020-09-14 20:53:42 +02:00
//if ($nbassignetouser && $action != 'view') $out .= '<br>';
2021-02-23 22:03:23 +01:00
if ( $nbassignetouser ) {
$out .= '<ul class="attendees">' ;
}
2021-03-01 20:37:16 +01:00
$i = 0 ;
$ownerid = 0 ;
2021-02-23 22:03:23 +01:00
foreach ( $assignedtouser as $key => $value ) {
if ( $value [ 'id' ] == $ownerid ) {
continue ;
}
2017-11-22 14:42:47 +01:00
2019-11-08 15:51:54 +01:00
$out .= '<li>' ;
2014-09-23 16:15:15 +02:00
$userstatic -> fetch ( $value [ 'id' ]);
2019-11-08 15:51:54 +01:00
$out .= $userstatic -> getNomUrl ( - 1 );
2021-02-23 22:03:23 +01:00
if ( $i == 0 ) {
2021-03-01 20:37:16 +01:00
$ownerid = $value [ 'id' ];
$out .= ' (' . $langs -> trans ( " Owner " ) . ')' ;
2021-02-23 22:03:23 +01:00
}
if ( $nbassignetouser > 1 && $action != 'view' ) {
2021-05-19 13:56:13 +02:00
$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 . '">' ;
2018-04-05 19:52:54 +02:00
}
2017-11-22 14:42:47 +01:00
// Show my availability
2021-02-23 22:03:23 +01:00
if ( $showproperties ) {
if ( $ownerid == $value [ 'id' ] && is_array ( $listofuserid ) && count ( $listofuserid ) && in_array ( $ownerid , array_keys ( $listofuserid ))) {
2019-11-08 15:51:54 +01:00
$out .= '<div class="myavailability inline-block">' ;
2020-10-13 10:05:47 +02:00
$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>' ;
2019-11-08 15:51:54 +01:00
$out .= '</div>' ;
2017-11-22 14:42:47 +01:00
}
}
2014-09-09 14:38:10 +02:00
//$out.=' '.($value['mandatory']?$langs->trans("Mandatory"):$langs->trans("Optional"));
//$out.=' '.($value['transparency']?$langs->trans("Busy"):$langs->trans("NotBusy"));
2017-11-22 14:42:47 +01:00
2019-11-08 15:51:54 +01:00
$out .= '</li>' ;
2014-09-20 00:57:29 +02:00
$i ++ ;
2014-09-09 14:38:10 +02:00
}
2021-02-23 22:03:23 +01:00
if ( $nbassignetouser ) {
$out .= '</ul>' ;
}
2014-09-09 14:38:10 +02:00
2020-09-14 20:53:42 +02:00
// Method with no ajax
2021-02-23 22:03:23 +01:00
if ( $action != 'view' ) {
2020-09-14 20:53:42 +02:00
$out .= '<input type="hidden" class="removedassignedhidden" name="removedassigned" value="">' ;
2020-10-18 14:00:47 +02:00
$out .= '<script type="text/javascript" language="javascript">jQuery(document).ready(function () {' ;
$out .= 'jQuery(".removedassigned").click(function() { jQuery(".removedassignedhidden").val(jQuery(this).val()); });' ;
$out .= 'jQuery(".assignedtouser").change(function() { console.log(jQuery(".assignedtouser option:selected").val());' ;
$out .= ' if (jQuery(".assignedtouser option:selected").val() > 0) { jQuery("#' . $action . 'assignedtouser").attr("disabled", false); }' ;
$out .= ' else { jQuery("#' . $action . 'assignedtouser").attr("disabled", true); }' ;
$out .= '});' ;
$out .= '})</script>' ;
2020-09-14 20:53:42 +02:00
$out .= $this -> select_dolusers ( '' , $htmlname , $show_empty , $exclude , $disabled , $include , $enableonly , $force_entity , $maxlength , $showstatus , $morefilter );
2021-05-19 13:56:13 +02:00
$out .= ' <input type="submit" disabled class="button valignmiddle smallpaddingimp reposition" id="' . $action . 'assignedtouser" name="' . $action . 'assignedtouser" value="' . dol_escape_htmltag ( $langs -> trans ( " Add " )) . '">' ;
2020-09-14 20:53:42 +02:00
$out .= '<br>' ;
}
2017-10-07 13:09:31 +02:00
return $out ;
}
2014-09-09 14:38:10 +02:00
2020-04-18 15:11:38 +02:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2017-10-07 13:09:31 +02:00
/**
* Return list of products for customer in Ajax if Ajax activated or go to select_produits_list
*
* @ param int $selected Preselected products
2021-02-02 13:04:41 +01:00
* @ param string $htmlname Name of HTML select field ( must be unique in page ) .
2017-10-07 13:09:31 +02:00
* @ param int $filtertype Filter on product type ( '' = nofilter , 0 = product , 1 = service )
* @ param int $limit Limit on number of returned lines
* @ param int $price_level Level of price to show
2018-02-01 20:19:04 +01:00
* @ param int $status Sell status - 1 = Return all products , 0 = Products not on sell , 1 = Products on sell
2017-10-07 13:09:31 +02:00
* @ param int $finished 2 = all , 1 = finished , 0 = raw material
* @ param string $selected_input_value Value of preselected input text ( for use with ajax )
* @ param int $hidelabel Hide label ( 0 = no , 1 = yes , 2 = show search icon ( before ) and placeholder , 3 search icon after )
* @ param array $ajaxoptions Options for ajax_autocompleter
* @ param int $socid Thirdparty Id ( to get also price dedicated to this customer )
* @ param string $showempty '' to not show empty line . Translation key to show an empty line . '1' show empty line with no text .
* @ param int $forcecombo Force to use combo box
* @ param string $morecss Add more css on select
* @ param int $hidepriceinlabel 1 = Hide prices in label
2019-08-26 22:34:41 +02:00
* @ param string $warehouseStatus Warehouse status filter to count the quantity in stock . Following comma separated filter options can be used
* 'warehouseopen' = count products from open warehouses ,
* 'warehouseclosed' = count products from closed warehouses ,
* 'warehouseinternal' = count products from warehouses for internal correct / transfer only
2018-02-01 20:19:04 +01:00
* @ param array $selected_combinations Selected combinations . Format : array ([ attrid ] => attrval , [ ... ])
2020-10-05 02:24:45 +02:00
* @ param string $nooutput No print , return the output into a string
* @ return void | string
2017-10-07 13:09:31 +02:00
*/
2021-02-02 13:04:41 +01:00
public function select_produits ( $selected = '' , $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 )
2017-10-07 13:09:31 +02:00
{
2020-04-18 15:11:38 +02:00
// phpcs:enable
2019-11-08 15:51:54 +01:00
global $langs , $conf ;
2011-08-31 17:12:09 +02:00
2020-10-05 02:24:45 +02:00
$out = '' ;
2019-05-07 00:26:31 +02:00
// check parameters
2019-11-08 15:51:54 +01:00
$price_level = ( ! empty ( $price_level ) ? $price_level : 0 );
2021-02-23 22:03:23 +01:00
if ( is_null ( $ajaxoptions )) {
$ajaxoptions = array ();
}
2019-05-10 20:09:41 +02:00
2019-11-08 15:51:54 +01:00
if ( strval ( $filtertype ) === '' && ( ! empty ( $conf -> product -> enabled ) || ! empty ( $conf -> service -> enabled ))) {
if ( ! empty ( $conf -> product -> enabled ) && empty ( $conf -> service -> enabled )) {
2019-08-27 11:54:20 +02:00
$filtertype = '0' ;
2020-05-21 15:05:19 +02:00
} elseif ( empty ( $conf -> product -> enabled ) && ! empty ( $conf -> service -> enabled )) {
2019-08-27 11:54:20 +02:00
$filtertype = '1' ;
}
}
2021-02-23 22:03:23 +01:00
if ( ! empty ( $conf -> use_javascript_ajax ) && ! empty ( $conf -> global -> PRODUIT_USE_SEARCH_TO_SELECT )) {
2019-11-08 15:51:54 +01:00
$placeholder = '' ;
2012-08-22 17:42:40 +02:00
2021-02-23 22:03:23 +01:00
if ( $selected && empty ( $selected_input_value )) {
2017-10-07 13:09:31 +02:00
require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php' ;
$producttmpselect = new Product ( $this -> db );
$producttmpselect -> fetch ( $selected );
2019-11-08 15:51:54 +01:00
$selected_input_value = $producttmpselect -> ref ;
2017-10-07 13:09:31 +02:00
unset ( $producttmpselect );
}
2019-06-01 17:00:15 +02:00
// handle case where product or service module is disabled + no filter specified
2021-02-23 22:03:23 +01:00
if ( $filtertype == '' ) {
2019-06-01 17:00:15 +02:00
if ( empty ( $conf -> product -> enabled )) { // when product module is disabled, show services only
$filtertype = 1 ;
2020-05-21 15:05:19 +02:00
} elseif ( empty ( $conf -> service -> enabled )) { // when service module is disabled, show products only
2019-06-01 17:00:15 +02:00
$filtertype = 0 ;
}
}
2017-10-07 13:09:31 +02:00
// mode=1 means customers products
2019-11-08 15:51:54 +01:00
$urloption = 'htmlname=' . $htmlname . '&outjson=1&price_level=' . $price_level . '&type=' . $filtertype . '&mode=1&status=' . $status . '&finished=' . $finished . '&hidepriceinlabel=' . $hidepriceinlabel . '&warehousestatus=' . $warehouseStatus ;
2017-10-07 13:09:31 +02:00
//Price by customer
2019-11-08 15:51:54 +01:00
if ( ! empty ( $conf -> global -> PRODUIT_CUSTOMER_PRICES ) && ! empty ( $socid )) {
$urloption .= '&socid=' . $socid ;
2017-10-07 13:09:31 +02:00
}
2020-12-09 21:16:25 +01:00
$out .= ajax_autocompleter ( $selected , $htmlname , DOL_URL_ROOT . '/product/ajax/products.php' , $urloption , $conf -> global -> PRODUIT_USE_SEARCH_TO_SELECT , 1 , $ajaxoptions );
2016-07-23 16:37:21 +02:00
2021-02-02 13:04:41 +01:00
if ( ! empty ( $conf -> variants -> enabled ) && is_array ( $selected_combinations )) {
// Code to automatically insert with javascript the select of attributes under the select of product
// when a parent of variant has been selected.
2020-10-05 02:24:45 +02:00
$out .= '
2021-02-02 13:04:41 +01:00
<!-- script to auto show attributes select tags if a variant was selected -->
2016-07-23 16:37:21 +02:00
< script >
2021-02-02 13:04:41 +01:00
// auto show attributes fields
2020-10-05 02:24:45 +02:00
selected = '.json_encode($selected_combinations).' ;
2016-07-23 16:37:21 +02:00
combvalues = {};
jQuery ( document ) . ready ( function () {
2020-10-05 02:24:45 +02:00
jQuery ( " input[name= \ 'prod_entry_mode \ '] " ) . change ( function () {
if ( jQuery ( this ) . val () == \ ' free\ ' ) {
jQuery ( \ ' div #attributes_box\').empty();
2016-07-23 16:37:21 +02:00
}
});
2020-10-05 02:24:45 +02:00
jQuery ( " input#'. $htmlname .' " ) . change ( function () {
2016-07-23 16:37:21 +02:00
if ( ! jQuery ( this ) . val ()) {
2020-10-05 02:24:45 +02:00
jQuery ( \ ' div #attributes_box\').empty();
2016-07-23 16:37:21 +02:00
return ;
}
2021-02-02 13:12:12 +01:00
console . log ( " A change has started. We get variants fields to inject html select " );
2021-02-02 13:04:41 +01:00
2020-10-05 02:24:45 +02:00
jQuery . getJSON ( " '.DOL_URL_ROOT.'/variants/ajax/getCombinations.php " , {
2016-07-23 16:37:21 +02:00
id : jQuery ( this ) . val ()
}, function ( data ) {
2020-10-05 02:24:45 +02:00
jQuery ( \ ' div #attributes_box\').empty();
2016-07-23 16:37:21 +02:00
jQuery . each ( data , function ( key , val ) {
combvalues [ val . id ] = val . values ;
2020-10-05 02:24:45 +02:00
var span = jQuery ( document . createElement ( \ ' div\ ' )) . css ({
\ ' display\ ' : \ ' table - row\ '
2016-07-23 16:37:21 +02:00
});
span . append (
2020-10-05 02:24:45 +02:00
jQuery ( document . createElement ( \ ' div\ ' )) . text ( val . label ) . css ({
\ ' font - weight\ ' : \ ' bold\ ' ,
2021-02-02 13:12:12 +01:00
\ ' display\ ' : \ ' table - cell\ '
2016-07-23 16:37:21 +02:00
})
);
2020-10-05 02:24:45 +02:00
var html = jQuery ( document . createElement ( \ ' select\ ' )) . attr ( \ ' name\ ' , \ ' combinations [ \ ' + val . id + \ ' ] \ ' ) . css ({
\ ' margin - left\ ' : \ ' 15 px\ ' ,
\ ' white - space\ ' : \ ' pre\ '
2016-07-23 16:37:21 +02:00
}) . append (
2020-10-05 02:24:45 +02:00
jQuery ( document . createElement ( \ ' option\ ' )) . val ( \ ' \ ' )
2016-07-23 16:37:21 +02:00
);
jQuery . each ( combvalues [ val . id ], function ( key , val ) {
2020-10-05 02:24:45 +02:00
var tag = jQuery ( document . createElement ( \ ' option\ ' )) . val ( val . id ) . html ( val . value );
2016-07-23 16:37:21 +02:00
if ( selected [ val . fk_product_attribute ] == val . id ) {
2020-10-05 02:24:45 +02:00
tag . attr ( \ ' selected\ ' , \ ' selected\ ' );
2016-07-23 16:37:21 +02:00
}
html . append ( tag );
});
span . append ( html );
2020-10-05 02:24:45 +02:00
jQuery ( \ ' div #attributes_box\').append(span);
2016-07-23 16:37:21 +02:00
});
})
});
2020-10-05 02:24:45 +02:00
'.($selected ? ' jQuery ( " input#'. $htmlname .' " ) . change (); ' : ' ').'
2016-07-23 16:37:21 +02:00
});
</ script >
2020-10-05 02:24:45 +02:00
' ;
2017-10-07 13:09:31 +02:00
}
2020-10-05 02:24:45 +02:00
2021-02-23 22:03:23 +01:00
if ( empty ( $hidelabel )) {
$out .= $langs -> trans ( " RefOrLabel " ) . ' : ' ;
} elseif ( $hidelabel > 1 ) {
2019-11-08 15:51:54 +01:00
$placeholder = ' placeholder="' . $langs -> trans ( " RefOrLabel " ) . '"' ;
2017-10-07 13:09:31 +02:00
if ( $hidelabel == 2 ) {
2020-10-05 02:24:45 +02:00
$out .= img_picto ( $langs -> trans ( " Search " ), 'search' );
2017-10-07 13:09:31 +02:00
}
}
2020-10-05 02:24:45 +02:00
$out .= '<input type="text" class="minwidth100" name="search_' . $htmlname . '" id="search_' . $htmlname . '" value="' . $selected_input_value . '"' . $placeholder . ' ' . ( ! empty ( $conf -> global -> PRODUCT_SEARCH_AUTOFOCUS ) ? 'autofocus' : '' ) . ' />' ;
2017-10-07 13:09:31 +02:00
if ( $hidelabel == 3 ) {
2020-10-05 02:24:45 +02:00
$out .= img_picto ( $langs -> trans ( " Search " ), 'search' );
2017-10-07 13:09:31 +02:00
}
2020-05-21 15:05:19 +02:00
} else {
2020-10-05 02:24:45 +02:00
$out .= $this -> select_produits_list ( $selected , $htmlname , $filtertype , $limit , $price_level , '' , $status , $finished , 0 , $socid , $showempty , $forcecombo , $morecss , $hidepriceinlabel , $warehouseStatus );
2017-10-07 13:09:31 +02:00
}
2020-10-05 02:24:45 +02:00
2021-02-23 22:03:23 +01:00
if ( empty ( $nooutput )) {
print $out ;
} else {
return $out ;
}
2017-10-07 13:09:31 +02:00
}
2010-08-22 17:46:34 +02:00
2020-09-07 10:18:17 +02:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2017-10-07 13:09:31 +02:00
/**
2020-10-05 02:24:45 +02:00
* Return list of products for a customer .
* Called by select_produits .
2017-10-07 13:09:31 +02:00
*
* @ param int $selected Preselected product
* @ param string $htmlname Name of select html
* @ param string $filtertype Filter on product type ( '' = nofilter , 0 = product , 1 = service )
* @ param int $limit Limit on number of returned lines
* @ param int $price_level Level of price to show
* @ param string $filterkey Filter on product
* @ param int $status - 1 = Return all products , 0 = Products not on sell , 1 = Products on sell
* @ param int $finished Filter on finished field : 2 = No filter
* @ param int $outputmode 0 = HTML select string , 1 = Array
* @ param int $socid Thirdparty Id ( to get also price dedicated to this customer )
* @ param string $showempty '' to not show empty line . Translation key to show an empty line . '1' show empty line with no text .
* @ param int $forcecombo Force to use combo box
* @ param string $morecss Add more css on select
* @ param int $hidepriceinlabel 1 = Hide prices in label
2019-08-26 22:34:41 +02:00
* @ param string $warehouseStatus Warehouse status filter to group / count stock . Following comma separated filter options can be used .
* 'warehouseopen' = count products from open warehouses ,
* 'warehouseclosed' = count products from closed warehouses ,
* 'warehouseinternal' = count products from warehouses for internal correct / transfer only
2017-10-07 13:09:31 +02:00
* @ return array Array of keys for json
*/
2020-09-07 10:18:17 +02:00
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 = '' )
2017-10-07 13:09:31 +02:00
{
2020-09-07 10:18:17 +02:00
// phpcs:enable
2019-11-08 15:51:54 +01:00
global $langs , $conf , $user , $db ;
2013-06-05 22:01:35 +02:00
2019-11-08 15:51:54 +01:00
$out = '' ;
$outarray = array ();
2017-10-07 13:09:31 +02:00
2020-09-07 10:18:17 +02:00
// Units
2020-11-25 18:07:52 +01:00
if ( ! empty ( $conf -> global -> PRODUCT_USE_UNITS )) {
2020-09-07 10:18:17 +02:00
$langs -> load ( 'other' );
}
2017-10-07 13:09:31 +02:00
$warehouseStatusArray = array ();
2021-02-23 22:03:23 +01:00
if ( ! empty ( $warehouseStatus )) {
2017-10-07 13:09:31 +02:00
require_once DOL_DOCUMENT_ROOT . '/product/stock/class/entrepot.class.php' ;
2021-02-23 22:03:23 +01:00
if ( preg_match ( '/warehouseclosed/' , $warehouseStatus )) {
2017-10-07 13:09:31 +02:00
$warehouseStatusArray [] = Entrepot :: STATUS_CLOSED ;
}
2021-02-23 22:03:23 +01:00
if ( preg_match ( '/warehouseopen/' , $warehouseStatus )) {
2017-10-07 13:09:31 +02:00
$warehouseStatusArray [] = Entrepot :: STATUS_OPEN_ALL ;
}
2021-02-23 22:03:23 +01:00
if ( preg_match ( '/warehouseinternal/' , $warehouseStatus )) {
2017-10-07 13:09:31 +02:00
$warehouseStatusArray [] = Entrepot :: STATUS_OPEN_INTERNAL ;
}
}
2014-02-23 16:16:47 +01:00
2020-03-26 03:55:34 +01:00
$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.duration, p.fk_price_expression " ;
2021-02-23 22:03:23 +01:00
if ( count ( $warehouseStatusArray )) {
2020-09-19 23:30:29 +02:00
$selectFieldsGrouped = " , sum( " . $this -> db -> ifsql ( " e.statut IS NULL " , " 0 " , " ps.reel " ) . " ) as stock " ; // e.statut is null if there is no record in stock
2020-05-21 15:05:19 +02:00
} else {
2020-09-19 23:30:29 +02:00
$selectFieldsGrouped = " , " . $this -> db -> ifsql ( " p.stock IS NULL " , 0 , " p.stock " ) . " AS stock " ;
2019-08-26 22:34:41 +02:00
}
2014-02-23 16:16:47 +01:00
2017-10-07 13:09:31 +02:00
$sql = " SELECT " ;
2019-11-08 15:51:54 +01:00
$sql .= $selectFields . $selectFieldsGrouped ;
2018-12-14 18:58:55 +01:00
2021-02-23 22:03:23 +01:00
if ( ! empty ( $conf -> global -> PRODUCT_SORT_BY_CATEGORY )) {
2018-12-14 10:01:12 +01:00
//Product category
2019-11-08 15:51:54 +01:00
$sql .= " , (SELECT " . MAIN_DB_PREFIX . " categorie_product.fk_categorie
2018-12-14 10:01:12 +01:00
FROM " .MAIN_DB_PREFIX. " categorie_product
2018-12-14 18:58:55 +01:00
WHERE " .MAIN_DB_PREFIX. " categorie_product . fk_product = p . rowid
2018-12-14 10:01:12 +01:00
LIMIT 1
2018-11-23 21:26:10 +01:00
) AS categorie_product_id " ;
2018-12-14 10:01:12 +01:00
}
2018-12-14 18:58:55 +01:00
2017-10-07 13:09:31 +02:00
//Price by customer
2021-02-23 22:03:23 +01:00
if ( ! empty ( $conf -> global -> PRODUIT_CUSTOMER_PRICES ) && ! empty ( $socid )) {
2019-11-08 15:51:54 +01:00
$sql .= ', pcp.rowid as idprodcustprice, pcp.price as custprice, pcp.price_ttc as custprice_ttc,' ;
2020-10-28 11:04:15 +01:00
$sql .= ' pcp.price_base_type as custprice_base_type, pcp.tva_tx as custtva_tx, pcp.ref_customer as custref' ;
$selectFields .= " , idprodcustprice, custprice, custprice_ttc, custprice_base_type, custtva_tx, custref " ;
2017-10-07 13:09:31 +02:00
}
2020-09-07 10:18:17 +02:00
// Units
if ( ! empty ( $conf -> global -> PRODUCT_USE_UNITS )) {
$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 " ;
$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' ;
}
2014-04-02 14:53:42 +02:00
2017-10-07 13:09:31 +02:00
// Multilang : we add translation
2021-02-23 22:03:23 +01:00
if ( ! empty ( $conf -> global -> MAIN_MULTILANGS )) {
2019-11-08 15:51:54 +01:00
$sql .= " , pl.label as label_translated " ;
2020-10-27 09:52:04 +01:00
$sql .= " , pl.description as description_translated " ;
2019-11-08 15:51:54 +01:00
$selectFields .= " , label_translated " ;
2020-10-27 09:52:04 +01:00
$selectFields .= " , description_translated " ;
2017-10-07 13:09:31 +02:00
}
2012-10-26 01:00:03 +02:00
// Price by quantity
2021-02-23 22:03:23 +01:00
if ( ! empty ( $conf -> global -> PRODUIT_CUSTOMER_PRICES_BY_QTY ) || ! empty ( $conf -> global -> PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES )) {
2019-11-08 15:51:54 +01:00
$sql .= " , (SELECT pp.rowid FROM " . MAIN_DB_PREFIX . " product_price as pp WHERE pp.fk_product = p.rowid " ;
2021-02-23 22:03:23 +01:00
if ( $price_level >= 1 && ! empty ( $conf -> global -> PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES )) {
$sql .= " AND price_level= " . $price_level ;
}
2019-11-08 15:51:54 +01:00
$sql .= " ORDER BY date_price " ;
$sql .= " DESC LIMIT 1) as price_rowid " ;
$sql .= " , (SELECT pp.price_by_qty FROM " . MAIN_DB_PREFIX . " product_price as pp WHERE pp.fk_product = p.rowid " ; // price_by_qty is 1 if some prices by qty exists in subtable
2021-02-23 22:03:23 +01:00
if ( $price_level >= 1 && ! empty ( $conf -> global -> PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES )) {
$sql .= " AND price_level= " . $price_level ;
}
2019-11-08 15:51:54 +01:00
$sql .= " ORDER BY date_price " ;
$sql .= " DESC LIMIT 1) as price_by_qty " ;
$selectFields .= " , price_rowid, price_by_qty " ;
}
$sql .= " FROM " . MAIN_DB_PREFIX . " product as p " ;
2021-02-23 22:03:23 +01:00
if ( count ( $warehouseStatusArray )) {
2019-11-08 15:51:54 +01:00
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " product_stock as ps on ps.fk_product = p.rowid " ;
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " entrepot as e on ps.fk_entrepot = e.rowid AND e.entity IN ( " . getEntity ( 'stock' ) . " ) " ;
2020-09-18 17:47:40 +02:00
$sql .= ' AND e.statut IN (' . $this -> db -> sanitize ( $this -> db -> escape ( implode ( ',' , $warehouseStatusArray ))) . ')' ; // Return line if product is inside the selected stock. If not, an empty line will be returned so we will count 0.
2012-10-26 01:00:03 +02:00
}
2016-12-24 21:39:40 +01:00
2018-10-23 23:21:30 +02:00
// include search in supplier ref
2021-02-23 22:03:23 +01:00
if ( ! empty ( $conf -> global -> MAIN_SEARCH_PRODUCT_BY_FOURN_REF )) {
2020-09-07 10:18:17 +02:00
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " product_fournisseur_price as pfp ON p.rowid = pfp.fk_product " ;
2018-10-23 23:21:30 +02:00
}
2016-11-06 15:01:40 +01:00
2017-10-07 13:09:31 +02:00
//Price by customer
2019-11-08 15:51:54 +01:00
if ( ! empty ( $conf -> global -> PRODUIT_CUSTOMER_PRICES ) && ! empty ( $socid )) {
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " product_customer_price as pcp ON pcp.fk_soc= " . $socid . " AND pcp.fk_product=p.rowid " ;
2017-10-07 13:09:31 +02:00
}
2020-09-07 10:18:17 +02:00
// Units
if ( ! empty ( $conf -> global -> PRODUCT_USE_UNITS )) {
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " c_units u ON u.rowid = p.fk_unit " ;
}
2017-10-07 13:09:31 +02:00
// Multilang : we add translation
2021-02-23 22:03:23 +01:00
if ( ! empty ( $conf -> global -> MAIN_MULTILANGS )) {
2020-10-27 09:52:04 +01:00
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " product_lang as pl ON pl.fk_product = p.rowid " ;
if ( ! empty ( $conf -> global -> PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE ) && ! empty ( $socid )) {
2021-02-08 11:06:21 +01:00
require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php' ;
2020-10-27 09:52:04 +01:00
$soc = new Societe ( $db );
$result = $soc -> fetch ( $socid );
if ( $result > 0 && ! empty ( $soc -> default_lang )) {
$sql .= " AND pl.lang=' " . $this -> db -> escape ( $soc -> default_lang ) . " ' " ;
} else {
$sql .= " AND pl.lang=' " . $this -> db -> escape ( $langs -> getDefaultLang ()) . " ' " ;
}
} else {
$sql .= " AND pl.lang=' " . $this -> db -> escape ( $langs -> getDefaultLang ()) . " ' " ;
}
2017-10-07 13:09:31 +02:00
}
2016-07-23 16:37:21 +02:00
2017-10-07 13:09:31 +02:00
if ( ! empty ( $conf -> global -> PRODUIT_ATTRIBUTES_HIDECHILD )) {
2017-11-22 20:24:04 +01:00
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " product_attribute_combination pac ON pac.fk_product_child = p.rowid " ;
2017-10-07 13:09:31 +02:00
}
2016-07-23 16:37:21 +02:00
2019-11-08 15:51:54 +01:00
$sql .= ' WHERE p.entity IN (' . getEntity ( 'product' ) . ')' ;
2016-07-23 16:37:21 +02:00
2017-10-07 13:09:31 +02:00
if ( ! empty ( $conf -> global -> PRODUIT_ATTRIBUTES_HIDECHILD )) {
$sql .= " AND pac.rowid IS NULL " ;
}
2016-07-23 16:37:21 +02:00
2021-02-23 22:03:23 +01:00
if ( $finished == 0 ) {
2021-06-09 15:36:47 +02:00
$sql .= " AND p.finished = " . (( int ) $finished );
2021-02-23 22:03:23 +01:00
} elseif ( $finished == 1 ) {
2021-06-09 15:36:47 +02:00
$sql .= " AND p.finished = " . (( int ) $finished );
2021-02-23 22:03:23 +01:00
if ( $status >= 0 ) {
2021-06-09 15:36:47 +02:00
$sql .= " AND p.tosell = " . (( int ) $status );
2021-02-23 22:03:23 +01:00
}
} elseif ( $status >= 0 ) {
2021-06-09 15:36:47 +02:00
$sql .= " AND p.tosell = " . (( int ) $status );
2017-10-07 13:09:31 +02:00
}
2019-06-01 17:00:15 +02:00
// Filter by product type
2021-02-23 22:03:23 +01:00
if ( strval ( $filtertype ) != '' ) {
2021-06-09 15:36:47 +02:00
$sql .= " AND p.fk_product_type = " . (( int ) $filtertype );
2021-02-23 22:03:23 +01:00
} elseif ( empty ( $conf -> product -> enabled )) { // when product module is disabled, show services only
2019-11-08 15:51:54 +01:00
$sql .= " AND p.fk_product_type = 1 " ;
2020-05-21 15:05:19 +02:00
} elseif ( empty ( $conf -> service -> enabled )) { // when service module is disabled, show products only
2019-11-08 15:51:54 +01:00
$sql .= " AND p.fk_product_type = 0 " ;
2019-06-01 17:00:15 +02:00
}
2017-10-07 13:09:31 +02:00
// Add criteria on ref/label
2021-02-23 22:03:23 +01:00
if ( $filterkey != '' ) {
2019-11-08 15:51:54 +01:00
$sql .= ' AND (' ;
$prefix = empty ( $conf -> global -> PRODUCT_DONOTSEARCH_ANYWHERE ) ? '%' : '' ; // Can use index if PRODUCT_DONOTSEARCH_ANYWHERE is on
2017-10-07 13:09:31 +02:00
// For natural search
$scrit = explode ( ' ' , $filterkey );
2019-11-08 15:51:54 +01:00
$i = 0 ;
2021-02-23 22:03:23 +01:00
if ( count ( $scrit ) > 1 ) {
$sql .= " ( " ;
}
foreach ( $scrit as $crit ) {
if ( $i > 0 ) {
$sql .= " AND " ;
}
2020-09-19 23:30:29 +02:00
$sql .= " (p.ref LIKE ' " . $this -> db -> escape ( $prefix . $crit ) . " %' OR p.label LIKE ' " . $this -> db -> escape ( $prefix . $crit ) . " %' " ;
2021-02-23 22:03:23 +01:00
if ( ! empty ( $conf -> global -> MAIN_MULTILANGS )) {
$sql .= " OR pl.label LIKE ' " . $this -> db -> escape ( $prefix . $crit ) . " %' " ;
}
if ( ! empty ( $conf -> global -> PRODUIT_CUSTOMER_PRICES ) && ! empty ( $socid )) {
$sql .= " OR pcp.ref_customer LIKE ' " . $this -> db -> escape ( $prefix . $crit ) . " %' " ;
}
if ( ! empty ( $conf -> global -> PRODUCT_AJAX_SEARCH_ON_DESCRIPTION )) {
2020-09-19 23:30:29 +02:00
$sql .= " OR p.description LIKE ' " . $this -> db -> escape ( $prefix . $crit ) . " %' " ;
2021-02-23 22:03:23 +01:00
if ( ! empty ( $conf -> global -> MAIN_MULTILANGS )) {
$sql .= " OR pl.description LIKE ' " . $this -> db -> escape ( $prefix . $crit ) . " %' " ;
}
}
if ( ! empty ( $conf -> global -> MAIN_SEARCH_PRODUCT_BY_FOURN_REF )) {
$sql .= " OR pfp.ref_fourn LIKE ' " . $this -> db -> escape ( $prefix . $crit ) . " %' " ;
2018-12-14 15:10:32 +01:00
}
2019-11-08 15:51:54 +01:00
$sql .= " ) " ;
2017-10-07 13:09:31 +02:00
$i ++ ;
}
2021-02-23 22:03:23 +01:00
if ( count ( $scrit ) > 1 ) {
$sql .= " ) " ;
}
if ( ! empty ( $conf -> barcode -> enabled )) {
$sql .= " OR p.barcode LIKE ' " . $this -> db -> escape ( $prefix . $filterkey ) . " %' " ;
}
2019-11-08 15:51:54 +01:00
$sql .= ')' ;
2017-10-07 13:09:31 +02:00
}
2021-02-23 22:03:23 +01:00
if ( count ( $warehouseStatusArray )) {
2019-11-08 15:51:54 +01:00
$sql .= ' GROUP BY' . $selectFields ;
2017-10-07 13:09:31 +02:00
}
2018-12-14 18:58:55 +01:00
2018-11-23 21:26:10 +01:00
//Sort by category
2021-02-23 22:03:23 +01:00
if ( ! empty ( $conf -> global -> PRODUCT_SORT_BY_CATEGORY )) {
2018-11-23 21:26:10 +01:00
$sql .= " ORDER BY categorie_product_id " ;
//ASC OR DESC order
2019-11-08 15:51:54 +01:00
( $conf -> global -> PRODUCT_SORT_BY_CATEGORY == 1 ) ? $sql .= " ASC " : $sql .= " DESC " ;
2020-05-21 15:05:19 +02:00
} else {
2020-09-19 23:30:29 +02:00
$sql .= $this -> db -> order ( " p.ref " );
2018-11-23 21:26:10 +01:00
}
2017-10-07 13:09:31 +02:00
2020-09-19 23:30:29 +02:00
$sql .= $this -> db -> plimit ( $limit , 0 );
2010-08-22 17:46:34 +02:00
2017-10-07 13:09:31 +02:00
// Build output string
2020-10-05 02:24:45 +02:00
dol_syslog ( get_class ( $this ) . " ::select_produits_list search products " , LOG_DEBUG );
2019-11-08 15:51:54 +01:00
$result = $this -> db -> query ( $sql );
2021-02-23 22:03:23 +01:00
if ( $result ) {
2017-10-07 13:09:31 +02:00
require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/product/dynamic_price/class/price_parser.class.php' ;
2020-04-13 16:13:02 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/product.lib.php' ;
2017-10-07 13:09:31 +02:00
$num = $this -> db -> num_rows ( $result );
2010-08-22 17:46:34 +02:00
2019-11-08 15:51:54 +01:00
$events = null ;
2016-11-06 15:01:40 +01:00
2021-02-23 22:03:23 +01:00
if ( ! $forcecombo ) {
2019-11-08 15:51:54 +01:00
include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php' ;
2017-11-24 09:23:18 +01:00
$out .= ajax_combobox ( $htmlname , $events , $conf -> global -> PRODUIT_USE_SEARCH_TO_SELECT );
2017-10-07 13:09:31 +02:00
}
2016-11-06 15:01:40 +01:00
2019-11-08 15:51:54 +01:00
$out .= '<select class="flat' . ( $morecss ? ' ' . $morecss : '' ) . '" name="' . $htmlname . '" id="' . $htmlname . '">' ;
2016-11-06 15:01:40 +01:00
2019-11-08 15:51:54 +01:00
$textifempty = '' ;
2017-10-07 13:09:31 +02:00
// Do not use textifempty = ' ' or ' ' here, or search on key will search on ' key'.
//if (! empty($conf->use_javascript_ajax) || $forcecombo) $textifempty='';
2021-02-23 22:03:23 +01:00
if ( ! empty ( $conf -> global -> PRODUIT_USE_SEARCH_TO_SELECT )) {
if ( $showempty && ! is_numeric ( $showempty )) {
$textifempty = $langs -> trans ( $showempty );
} else {
$textifempty .= $langs -> trans ( " All " );
}
2020-05-21 15:05:19 +02:00
} else {
2021-02-23 22:03:23 +01:00
if ( $showempty && ! is_numeric ( $showempty )) {
$textifempty = $langs -> trans ( $showempty );
}
}
if ( $showempty ) {
2021-03-21 13:46:01 +01:00
$out .= '<option value="0" selected>' . ( $textifempty ? $textifempty : ' ' ) . '</option>' ;
2019-01-30 20:01:55 +01:00
}
2011-02-05 18:25:56 +01:00
2017-10-07 13:09:31 +02:00
$i = 0 ;
2021-02-23 22:03:23 +01:00
while ( $num && $i < $num ) {
2017-10-07 13:09:31 +02:00
$opt = '' ;
2012-10-26 01:00:03 +02:00
$optJson = array ();
$objp = $this -> db -> fetch_object ( $result );
2012-12-07 13:48:11 +01:00
2021-02-23 22:03:23 +01:00
if (( ! empty ( $conf -> global -> PRODUIT_CUSTOMER_PRICES_BY_QTY ) || ! empty ( $conf -> global -> PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES )) && ! empty ( $objp -> price_by_qty ) && $objp -> price_by_qty == 1 ) { // Price by quantity will return many prices for the same product
2017-12-22 10:56:52 +01:00
$sql = " SELECT rowid, quantity, price, unitprice, remise_percent, remise, price_base_type " ;
2019-11-08 15:51:54 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " product_price_by_qty " ;
$sql .= " WHERE fk_product_price= " . $objp -> price_rowid ;
$sql .= " ORDER BY quantity ASC " ;
2012-12-07 13:48:11 +01:00
2020-10-05 02:24:45 +02:00
dol_syslog ( get_class ( $this ) . " ::select_produits_list search prices by qty " , LOG_DEBUG );
2012-10-26 01:00:03 +02:00
$result2 = $this -> db -> query ( $sql );
2021-02-23 22:03:23 +01:00
if ( $result2 ) {
2012-10-26 01:00:03 +02:00
$nb_prices = $this -> db -> num_rows ( $result2 );
$j = 0 ;
while ( $nb_prices && $j < $nb_prices ) {
$objp2 = $this -> db -> fetch_object ( $result2 );
2012-12-07 13:48:11 +01:00
2017-12-22 10:56:52 +01:00
$objp -> price_by_qty_rowid = $objp2 -> rowid ;
$objp -> price_by_qty_price_base_type = $objp2 -> price_base_type ;
$objp -> price_by_qty_quantity = $objp2 -> quantity ;
$objp -> price_by_qty_unitprice = $objp2 -> unitprice ;
$objp -> price_by_qty_remise_percent = $objp2 -> remise_percent ;
// For backward compatibility
2012-11-07 00:38:53 +01:00
$objp -> quantity = $objp2 -> quantity ;
2012-10-26 01:00:03 +02:00
$objp -> price = $objp2 -> price ;
2012-11-07 00:38:53 +01:00
$objp -> unitprice = $objp2 -> unitprice ;
2012-10-26 01:00:03 +02:00
$objp -> remise_percent = $objp2 -> remise_percent ;
$objp -> remise = $objp2 -> remise ;
2012-12-07 13:48:11 +01:00
2019-02-21 20:13:03 +01:00
$this -> constructProductListOption ( $objp , $opt , $optJson , 0 , $selected , $hidepriceinlabel , $filterkey );
2012-12-07 13:48:11 +01:00
2012-10-26 01:00:03 +02:00
$j ++ ;
2012-12-07 13:48:11 +01:00
2012-10-26 01:00:03 +02:00
// Add new entry
// "key" value of json key array is used by jQuery automatically as selected value
// "label" value of json key array is used by jQuery automatically as text for combo box
2019-11-08 15:51:54 +01:00
$out .= $opt ;
2013-06-05 22:01:35 +02:00
array_push ( $outarray , $optJson );
2012-10-26 01:00:03 +02:00
}
}
2020-05-21 15:05:19 +02:00
} else {
2017-10-07 13:09:31 +02:00
if ( ! empty ( $conf -> dynamicprices -> enabled ) && ! empty ( $objp -> fk_price_expression )) {
$price_product = new Product ( $this -> db );
$price_product -> fetch ( $objp -> rowid , '' , '' , 1 );
$priceparser = new PriceParser ( $this -> db );
$price_result = $priceparser -> parseProduct ( $price_product );
if ( $price_result >= 0 ) {
$objp -> price = $price_result ;
$objp -> unitprice = $price_result ;
//Calculate the VAT
$objp -> price_ttc = price2num ( $objp -> price ) * ( 1 + ( $objp -> tva_tx / 100 ));
2019-01-27 11:55:16 +01:00
$objp -> price_ttc = price2num ( $objp -> price_ttc , 'MU' );
2017-10-07 13:09:31 +02:00
}
}
2020-01-23 20:59:18 +01:00
2019-02-21 20:13:03 +01:00
$this -> constructProductListOption ( $objp , $opt , $optJson , $price_level , $selected , $hidepriceinlabel , $filterkey );
2012-10-26 01:00:03 +02:00
// Add new entry
// "key" value of json key array is used by jQuery automatically as selected value
// "label" value of json key array is used by jQuery automatically as text for combo box
2019-11-08 15:51:54 +01:00
$out .= $opt ;
2013-06-05 22:01:35 +02:00
array_push ( $outarray , $optJson );
2012-10-26 01:00:03 +02:00
}
2010-10-20 00:52:32 +02:00
2017-10-07 13:09:31 +02:00
$i ++ ;
}
2010-08-22 17:46:34 +02:00
2019-11-08 15:51:54 +01:00
$out .= '</select>' ;
2010-08-22 17:46:34 +02:00
2017-10-07 13:09:31 +02:00
$this -> db -> free ( $result );
2010-08-22 17:46:34 +02:00
2021-02-23 22:03:23 +01:00
if ( empty ( $outputmode )) {
return $out ;
}
2017-10-07 13:09:31 +02:00
return $outarray ;
2020-05-21 15:05:19 +02:00
} else {
2017-10-07 13:09:31 +02:00
dol_print_error ( $db );
}
}
2010-08-22 17:46:34 +02:00
2017-10-07 13:09:31 +02:00
/**
2019-02-21 20:13:03 +01:00
* constructProductListOption .
* This define value for & $opt and & $optJson .
2017-10-07 13:09:31 +02:00
*
2019-04-04 18:33:12 +02:00
* @ param resource $objp Resultset of fetch
2017-10-07 13:09:31 +02:00
* @ param string $opt Option ( var used for returned value in string option format )
* @ param string $optJson Option ( var used for returned value in json format )
* @ param int $price_level Price level
* @ param string $selected Preselected value
* @ param int $hidepriceinlabel Hide price in label
2019-02-21 20:13:03 +01:00
* @ param string $filterkey Filter key to highlight
2020-02-28 16:12:42 +01:00
* @ param int $novirtualstock Do not load virtual stock , even if slow option STOCK_SHOW_VIRTUAL_STOCK_IN_PRODUCTS_COMBO is on .
2017-10-07 13:09:31 +02:00
* @ return void
*/
2020-02-28 16:12:42 +01:00
protected function constructProductListOption ( & $objp , & $opt , & $optJson , $price_level , $selected , $hidepriceinlabel = 0 , $filterkey = '' , $novirtualstock = 0 )
2013-05-02 13:10:39 +02:00
{
2019-02-21 20:13:03 +01:00
global $langs , $conf , $user , $db ;
2012-12-07 13:48:11 +01:00
2019-11-08 15:51:54 +01:00
$outkey = '' ;
$outval = '' ;
$outref = '' ;
$outlabel = '' ;
2020-10-27 09:52:04 +01:00
$outlabel_translated = '' ;
2019-11-08 15:51:54 +01:00
$outdesc = '' ;
2020-10-27 09:52:04 +01:00
$outdesc_translated = '' ;
2019-11-08 15:51:54 +01:00
$outbarcode = '' ;
2020-03-24 17:28:12 +01:00
$outorigin = '' ;
2019-11-08 15:51:54 +01:00
$outtype = '' ;
$outprice_ht = '' ;
$outprice_ttc = '' ;
$outpricebasetype = '' ;
$outtva_tx = '' ;
$outqty = 1 ;
$outdiscount = 0 ;
$maxlengtharticle = ( empty ( $conf -> global -> PRODUCT_MAX_LENGTH_COMBO ) ? 48 : $conf -> global -> PRODUCT_MAX_LENGTH_COMBO );
$label = $objp -> label ;
2021-02-23 22:03:23 +01:00
if ( ! empty ( $objp -> label_translated )) {
$label = $objp -> label_translated ;
}
if ( ! empty ( $filterkey ) && $filterkey != '' ) {
$label = preg_replace ( '/(' . preg_quote ( $filterkey , '/' ) . ')/i' , '<strong>$1</strong>' , $label , 1 );
}
2019-11-08 15:51:54 +01:00
$outkey = $objp -> rowid ;
$outref = $objp -> ref ;
2020-10-28 11:04:15 +01:00
$outrefcust = empty ( $objp -> custref ) ? '' : $objp -> custref ;
2019-11-08 15:51:54 +01:00
$outlabel = $objp -> label ;
$outdesc = $objp -> description ;
2021-02-23 22:03:23 +01:00
if ( ! empty ( $conf -> global -> MAIN_MULTILANGS )) {
2020-10-27 09:52:04 +01:00
$outlabel_translated = $objp -> label_translated ;
$outdesc_translated = $objp -> description_translated ;
}
2019-11-08 15:51:54 +01:00
$outbarcode = $objp -> barcode ;
2020-03-26 03:55:34 +01:00
$outorigin = $objp -> fk_country ;
2020-02-19 11:33:45 +01:00
$outpbq = empty ( $objp -> price_by_qty_rowid ) ? '' : $objp -> price_by_qty_rowid ;
2019-11-08 15:51:54 +01:00
$outtype = $objp -> fk_product_type ;
$outdurationvalue = $outtype == Product :: TYPE_SERVICE ? substr ( $objp -> duration , 0 , dol_strlen ( $objp -> duration ) - 1 ) : '' ;
$outdurationunit = $outtype == Product :: TYPE_SERVICE ? substr ( $objp -> duration , - 1 ) : '' ;
2012-10-26 01:00:03 +02:00
2021-02-23 22:03:23 +01:00
if ( $outorigin && ! empty ( $conf -> global -> PRODUCT_SHOW_ORIGIN_IN_COMBO )) {
require_once DOL_DOCUMENT_ROOT . '/core/lib/company.lib.php' ;
}
2020-05-31 14:28:41 +02:00
2020-09-07 10:18:17 +02:00
// Units
$outvalUnits = '' ;
if ( ! empty ( $conf -> global -> PRODUCT_USE_UNITS )) {
if ( ! empty ( $objp -> unit_short )) {
$outvalUnits .= ' - ' . $objp -> unit_short ;
}
}
if ( ! empty ( $conf -> global -> PRODUCT_SHOW_DIMENSIONS_IN_COMBO )) {
if ( ! empty ( $objp -> weight ) && $objp -> weight_units !== null ) {
$unitToShow = showDimensionInBestUnit ( $objp -> weight , $objp -> weight_units , 'weight' , $langs );
$outvalUnits .= ' - ' . $unitToShow ;
}
if (( ! empty ( $objp -> length ) || ! empty ( $objp -> width ) || ! empty ( $objp -> height )) && $objp -> length_units !== null ) {
$unitToShow = $objp -> length . ' x ' . $objp -> width . ' x ' . $objp -> height . ' ' . measuringUnitString ( 0 , 'size' , $objp -> length_units );
$outvalUnits .= ' - ' . $unitToShow ;
}
if ( ! empty ( $objp -> surface ) && $objp -> surface_units !== null ) {
$unitToShow = showDimensionInBestUnit ( $objp -> surface , $objp -> surface_units , 'surface' , $langs );
$outvalUnits .= ' - ' . $unitToShow ;
}
if ( ! empty ( $objp -> volume ) && $objp -> volume_units !== null ) {
$unitToShow = showDimensionInBestUnit ( $objp -> volume , $objp -> volume_units , 'volume' , $langs );
$outvalUnits .= ' - ' . $unitToShow ;
}
}
if ( $outdurationvalue && $outdurationunit ) {
$da = array (
'h' => $langs -> trans ( 'Hour' ),
'd' => $langs -> trans ( 'Day' ),
'w' => $langs -> trans ( 'Week' ),
'm' => $langs -> trans ( 'Month' ),
'y' => $langs -> trans ( 'Year' )
);
if ( isset ( $da [ $outdurationunit ])) {
$outvalUnits .= ' - ' . $outdurationvalue . ' ' . $langs -> transnoentities ( $da [ $outdurationunit ] . ( $outdurationvalue > 1 ? 's' : '' ));
}
}
2012-10-26 01:00:03 +02:00
2017-10-07 13:09:31 +02:00
$opt = '<option value="' . $objp -> rowid . '"' ;
2019-11-08 15:51:54 +01:00
$opt .= ( $objp -> rowid == $selected ) ? ' selected' : '' ;
2021-02-23 22:03:23 +01:00
if ( ! empty ( $objp -> price_by_qty_rowid ) && $objp -> price_by_qty_rowid > 0 ) {
2020-02-19 03:07:12 +01:00
$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 . '"' ;
2017-12-22 10:56:52 +01:00
}
2021-02-23 22:03:23 +01:00
if ( ! empty ( $conf -> stock -> enabled ) && isset ( $objp -> stock ) && ( $objp -> fk_product_type == Product :: TYPE_PRODUCT || ! empty ( $conf -> global -> STOCK_SUPPORTS_SERVICES ))) {
2020-09-07 10:18:17 +02:00
if ( ! empty ( $user -> rights -> stock -> lire )) {
2021-02-23 22:03:23 +01:00
if ( $objp -> stock > 0 ) {
$opt .= ' class="product_line_stock_ok"' ;
} elseif ( $objp -> stock <= 0 ) {
$opt .= ' class="product_line_stock_too_low"' ;
}
2020-09-07 10:18:17 +02:00
}
2017-10-07 13:09:31 +02:00
}
2020-10-27 09:52:04 +01:00
if ( ! empty ( $conf -> global -> PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE )) {
$opt .= ' data-labeltrans="' . $outlabel_translated . '"' ;
$opt .= ' data-desctrans="' . dol_escape_htmltag ( $outdesc_translated ) . '"' ;
}
2019-11-08 15:51:54 +01:00
$opt .= '>' ;
$opt .= $objp -> ref ;
2021-02-23 22:03:23 +01:00
if ( ! empty ( $objp -> custref )) {
$opt .= ' (' . $objp -> custref . ')' ;
}
if ( $outbarcode ) {
$opt .= ' (' . $outbarcode . ')' ;
}
2019-11-08 15:51:54 +01:00
$opt .= ' - ' . dol_trunc ( $label , $maxlengtharticle );
2021-02-23 22:03:23 +01:00
if ( $outorigin && ! empty ( $conf -> global -> PRODUCT_SHOW_ORIGIN_IN_COMBO )) {
$opt .= ' (' . getCountry ( $outorigin , 1 ) . ')' ;
}
2017-10-07 13:09:31 +02:00
$objRef = $objp -> ref ;
2021-02-23 22:03:23 +01:00
if ( ! empty ( $objp -> custref )) {
$objRef .= ' (' . $objp -> custref . ')' ;
}
if ( ! empty ( $filterkey ) && $filterkey != '' ) {
$objRef = preg_replace ( '/(' . preg_quote ( $filterkey , '/' ) . ')/i' , '<strong>$1</strong>' , $objRef , 1 );
}
2019-11-08 15:51:54 +01:00
$outval .= $objRef ;
2021-02-23 22:03:23 +01:00
if ( $outbarcode ) {
$outval .= ' (' . $outbarcode . ')' ;
}
2019-11-08 15:51:54 +01:00
$outval .= ' - ' . dol_trunc ( $label , $maxlengtharticle );
2021-02-23 22:03:23 +01:00
if ( $outorigin && ! empty ( $conf -> global -> PRODUCT_SHOW_ORIGIN_IN_COMBO )) {
$outval .= ' (' . getCountry ( $outorigin , 1 ) . ')' ;
}
2020-03-24 17:32:50 +01:00
2020-09-07 10:18:17 +02:00
// Units
$opt .= $outvalUnits ;
$outval .= $outvalUnits ;
2017-10-07 13:09:31 +02:00
2019-11-08 15:51:54 +01:00
$found = 0 ;
2017-10-07 13:09:31 +02:00
// Multiprice
2018-05-23 17:05:08 +02:00
// If we need a particular price level (from 1 to 6)
2021-02-23 22:03:23 +01:00
if ( empty ( $hidepriceinlabel ) && $price_level >= 1 && ( ! empty ( $conf -> global -> PRODUIT_MULTIPRICES ) || ! empty ( $conf -> global -> PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES ))) {
2017-10-07 13:09:31 +02:00
$sql = " SELECT price, price_ttc, price_base_type, tva_tx " ;
2019-11-08 15:51:54 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " product_price " ;
2020-09-19 21:19:04 +02:00
$sql .= " WHERE fk_product = " . (( int ) $objp -> rowid );
2019-11-08 15:51:54 +01:00
$sql .= " AND entity IN ( " . getEntity ( 'productprice' ) . " ) " ;
2020-09-19 21:19:04 +02:00
$sql .= " AND price_level = " . (( int ) $price_level );
2019-11-08 15:51:54 +01:00
$sql .= " ORDER BY date_price DESC, rowid DESC " ; // Warning DESC must be both on date_price and rowid.
$sql .= " LIMIT 1 " ;
2017-10-07 13:09:31 +02:00
2020-01-23 20:59:18 +01:00
dol_syslog ( get_class ( $this ) . '::constructProductListOption search price for product ' . $objp -> rowid . ' AND level ' . $price_level . '' , LOG_DEBUG );
2017-10-07 13:09:31 +02:00
$result2 = $this -> db -> query ( $sql );
2021-02-23 22:03:23 +01:00
if ( $result2 ) {
2017-10-07 13:09:31 +02:00
$objp2 = $this -> db -> fetch_object ( $result2 );
2021-02-23 22:03:23 +01:00
if ( $objp2 ) {
2019-11-08 15:51:54 +01:00
$found = 1 ;
2021-02-23 22:03:23 +01:00
if ( $objp2 -> price_base_type == 'HT' ) {
2019-11-08 15:51:54 +01:00
$opt .= ' - ' . price ( $objp2 -> price , 1 , $langs , 0 , 0 , - 1 , $conf -> currency ) . ' ' . $langs -> trans ( " HT " );
$outval .= ' - ' . price ( $objp2 -> price , 0 , $langs , 0 , 0 , - 1 , $conf -> currency ) . ' ' . $langs -> transnoentities ( " HT " );
2020-05-21 15:05:19 +02:00
} else {
2019-11-08 15:51:54 +01:00
$opt .= ' - ' . price ( $objp2 -> price_ttc , 1 , $langs , 0 , 0 , - 1 , $conf -> currency ) . ' ' . $langs -> trans ( " TTC " );
$outval .= ' - ' . price ( $objp2 -> price_ttc , 0 , $langs , 0 , 0 , - 1 , $conf -> currency ) . ' ' . $langs -> transnoentities ( " TTC " );
2017-10-07 13:09:31 +02:00
}
2019-11-08 15:51:54 +01:00
$outprice_ht = price ( $objp2 -> price );
$outprice_ttc = price ( $objp2 -> price_ttc );
$outpricebasetype = $objp2 -> price_base_type ;
$outtva_tx = $objp2 -> tva_tx ;
2017-10-07 13:09:31 +02:00
}
2020-05-21 15:05:19 +02:00
} else {
2017-10-07 13:09:31 +02:00
dol_print_error ( $this -> db );
}
}
2010-08-22 17:46:34 +02:00
2012-10-26 01:00:03 +02:00
// Price by quantity
2021-02-23 22:03:23 +01:00
if ( empty ( $hidepriceinlabel ) && ! empty ( $objp -> quantity ) && $objp -> quantity >= 1 && ( ! empty ( $conf -> global -> PRODUIT_CUSTOMER_PRICES_BY_QTY ) || ! empty ( $conf -> global -> PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES ))) {
2012-10-26 01:00:03 +02:00
$found = 1 ;
2019-11-08 15:51:54 +01:00
$outqty = $objp -> quantity ;
$outdiscount = $objp -> remise_percent ;
2021-02-23 22:03:23 +01:00
if ( $objp -> quantity == 1 ) {
2019-11-08 15:51:54 +01:00
$opt .= ' - ' . price ( $objp -> unitprice , 1 , $langs , 0 , 0 , - 1 , $conf -> currency ) . " / " ;
$outval .= ' - ' . price ( $objp -> unitprice , 0 , $langs , 0 , 0 , - 1 , $conf -> currency ) . " / " ;
$opt .= $langs -> trans ( " Unit " ); // Do not use strtolower because it breaks utf8 encoding
$outval .= $langs -> transnoentities ( " Unit " );
2020-05-21 15:05:19 +02:00
} else {
2019-11-08 15:51:54 +01:00
$opt .= ' - ' . price ( $objp -> price , 1 , $langs , 0 , 0 , - 1 , $conf -> currency ) . " / " . $objp -> quantity ;
$outval .= ' - ' . price ( $objp -> price , 0 , $langs , 0 , 0 , - 1 , $conf -> currency ) . " / " . $objp -> quantity ;
$opt .= $langs -> trans ( " Units " ); // Do not use strtolower because it breaks utf8 encoding
$outval .= $langs -> transnoentities ( " Units " );
2012-10-26 01:00:03 +02:00
}
2012-12-07 13:48:11 +01:00
2019-11-08 15:51:54 +01:00
$outprice_ht = price ( $objp -> unitprice );
$outprice_ttc = price ( $objp -> unitprice * ( 1 + ( $objp -> tva_tx / 100 )));
$outpricebasetype = $objp -> price_base_type ;
$outtva_tx = $objp -> tva_tx ;
2012-10-26 01:00:03 +02:00
}
2021-02-23 22:03:23 +01:00
if ( empty ( $hidepriceinlabel ) && ! empty ( $objp -> quantity ) && $objp -> quantity >= 1 ) {
2019-11-08 15:51:54 +01:00
$opt .= " ( " . price ( $objp -> unitprice , 1 , $langs , 0 , 0 , - 1 , $conf -> currency ) . " / " . $langs -> trans ( " Unit " ) . " ) " ; // Do not use strtolower because it breaks utf8 encoding
$outval .= " ( " . price ( $objp -> unitprice , 0 , $langs , 0 , 0 , - 1 , $conf -> currency ) . " / " . $langs -> transnoentities ( " Unit " ) . " ) " ; // Do not use strtolower because it breaks utf8 encoding
2012-10-26 01:00:03 +02:00
}
2021-02-23 22:03:23 +01:00
if ( empty ( $hidepriceinlabel ) && ! empty ( $objp -> remise_percent ) && $objp -> remise_percent >= 1 ) {
2019-11-08 15:51:54 +01:00
$opt .= " - " . $langs -> trans ( " Discount " ) . " : " . vatrate ( $objp -> remise_percent ) . ' %' ;
$outval .= " - " . $langs -> transnoentities ( " Discount " ) . " : " . vatrate ( $objp -> remise_percent ) . ' %' ;
2012-10-26 01:00:03 +02:00
}
2014-04-02 14:53:42 +02:00
2016-02-26 12:22:32 +01:00
// Price by customer
2021-02-23 22:03:23 +01:00
if ( empty ( $hidepriceinlabel ) && ! empty ( $conf -> global -> PRODUIT_CUSTOMER_PRICES )) {
if ( ! empty ( $objp -> idprodcustprice )) {
2014-02-23 16:16:47 +01:00
$found = 1 ;
2014-04-02 14:53:42 +02:00
2021-02-23 22:03:23 +01:00
if ( $objp -> custprice_base_type == 'HT' ) {
2019-11-08 15:51:54 +01:00
$opt .= ' - ' . price ( $objp -> custprice , 1 , $langs , 0 , 0 , - 1 , $conf -> currency ) . ' ' . $langs -> trans ( " HT " );
$outval .= ' - ' . price ( $objp -> custprice , 0 , $langs , 0 , 0 , - 1 , $conf -> currency ) . ' ' . $langs -> transnoentities ( " HT " );
2020-05-21 15:05:19 +02:00
} else {
2019-11-08 15:51:54 +01:00
$opt .= ' - ' . price ( $objp -> custprice_ttc , 1 , $langs , 0 , 0 , - 1 , $conf -> currency ) . ' ' . $langs -> trans ( " TTC " );
$outval .= ' - ' . price ( $objp -> custprice_ttc , 0 , $langs , 0 , 0 , - 1 , $conf -> currency ) . ' ' . $langs -> transnoentities ( " TTC " );
2014-02-23 16:16:47 +01:00
}
2014-04-02 14:53:42 +02:00
2019-11-08 15:51:54 +01:00
$outprice_ht = price ( $objp -> custprice );
$outprice_ttc = price ( $objp -> custprice_ttc );
$outpricebasetype = $objp -> custprice_base_type ;
$outtva_tx = $objp -> custtva_tx ;
2014-02-23 16:16:47 +01:00
}
}
2012-10-26 01:00:03 +02:00
2017-10-07 13:09:31 +02:00
// If level no defined or multiprice not found, we used the default price
2021-02-23 22:03:23 +01:00
if ( empty ( $hidepriceinlabel ) && ! $found ) {
if ( $objp -> price_base_type == 'HT' ) {
2019-11-08 15:51:54 +01:00
$opt .= ' - ' . price ( $objp -> price , 1 , $langs , 0 , 0 , - 1 , $conf -> currency ) . ' ' . $langs -> trans ( " HT " );
$outval .= ' - ' . price ( $objp -> price , 0 , $langs , 0 , 0 , - 1 , $conf -> currency ) . ' ' . $langs -> transnoentities ( " HT " );
2020-05-21 15:05:19 +02:00
} else {
2019-11-08 15:51:54 +01:00
$opt .= ' - ' . price ( $objp -> price_ttc , 1 , $langs , 0 , 0 , - 1 , $conf -> currency ) . ' ' . $langs -> trans ( " TTC " );
$outval .= ' - ' . price ( $objp -> price_ttc , 0 , $langs , 0 , 0 , - 1 , $conf -> currency ) . ' ' . $langs -> transnoentities ( " TTC " );
2017-10-07 13:09:31 +02:00
}
2019-11-08 15:51:54 +01:00
$outprice_ht = price ( $objp -> price );
$outprice_ttc = price ( $objp -> price_ttc );
$outpricebasetype = $objp -> price_base_type ;
$outtva_tx = $objp -> tva_tx ;
2017-10-07 13:09:31 +02:00
}
2010-08-22 17:46:34 +02:00
2021-02-23 22:03:23 +01:00
if ( ! empty ( $conf -> stock -> enabled ) && isset ( $objp -> stock ) && ( $objp -> fk_product_type == Product :: TYPE_PRODUCT || ! empty ( $conf -> global -> STOCK_SUPPORTS_SERVICES ))) {
2020-09-07 10:18:17 +02:00
if ( ! empty ( $user -> rights -> stock -> lire )) {
2020-12-31 16:06:54 +01:00
$opt .= ' - ' . $langs -> trans ( " Stock " ) . ': ' . price ( price2num ( $objp -> stock , 'MS' ));
2020-09-07 10:18:17 +02:00
if ( $objp -> stock > 0 ) {
$outval .= ' - <span class="product_line_stock_ok">' ;
} elseif ( $objp -> stock <= 0 ) {
$outval .= ' - <span class="product_line_stock_too_low">' ;
}
2020-12-31 16:06:54 +01:00
$outval .= $langs -> transnoentities ( " Stock " ) . ': ' . price ( price2num ( $objp -> stock , 'MS' ));
2020-09-07 10:18:17 +02:00
$outval .= '</span>' ;
2021-02-23 22:03:23 +01:00
if ( empty ( $novirtualstock ) && ! empty ( $conf -> global -> STOCK_SHOW_VIRTUAL_STOCK_IN_PRODUCTS_COMBO )) { // Warning, this option may slow down combo list generation
2020-09-07 10:18:17 +02:00
$langs -> load ( " stocks " );
$tmpproduct = new Product ( $this -> db );
$tmpproduct -> fetch ( $objp -> rowid , '' , '' , '' , 1 , 1 , 1 ); // Load product without lang and prices arrays (we just need to make ->virtual_stock() after)
$tmpproduct -> load_virtual_stock ();
$virtualstock = $tmpproduct -> stock_theorique ;
$opt .= ' - ' . $langs -> trans ( " VirtualStock " ) . ':' . $virtualstock ;
$outval .= ' - ' . $langs -> transnoentities ( " VirtualStock " ) . ':' ;
if ( $virtualstock > 0 ) {
$outval .= '<span class="product_line_stock_ok">' ;
} elseif ( $virtualstock <= 0 ) {
$outval .= '<span class="product_line_stock_too_low">' ;
}
$outval .= $virtualstock ;
$outval .= '</span>' ;
unset ( $tmpproduct );
}
}
2017-10-07 13:09:31 +02:00
}
2012-10-26 01:00:03 +02:00
2019-11-08 15:51:54 +01:00
$opt .= " </option> \n " ;
2020-10-27 09:52:04 +01:00
$optJson = array (
'key' => $outkey ,
'value' => $outref ,
'label' => $outval ,
'label2' => $outlabel ,
'desc' => $outdesc ,
'type' => $outtype ,
'price_ht' => price2num ( $outprice_ht ),
'price_ttc' => price2num ( $outprice_ttc ),
'pricebasetype' => $outpricebasetype ,
'tva_tx' => $outtva_tx , 'qty' => $outqty ,
'discount' => $outdiscount ,
'duration_value' => $outdurationvalue ,
'duration_unit' => $outdurationunit ,
'pbq' => $outpbq ,
'labeltrans' => $outlabel_translated ,
2021-01-12 15:10:15 +01:00
'desctrans' => $outdesc_translated ,
'ref_customer' => $outrefcust
2020-10-27 09:52:04 +01:00
);
2012-10-26 01:00:03 +02:00
}
2010-08-22 17:46:34 +02:00
2020-09-07 10:18:17 +02:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2017-10-07 13:09:31 +02:00
/**
* Return list of products for customer ( in Ajax if Ajax activated or go to select_produits_fournisseurs_list )
*
* @ param int $socid Id third party
* @ param string $selected Preselected product
* @ param string $htmlname Name of HTML Select
* @ param string $filtertype Filter on product type ( '' = nofilter , 0 = product , 1 = service )
* @ param string $filtre For a SQL filter
* @ param array $ajaxoptions Options for ajax_autocompleter
2014-05-05 17:59:43 +02:00
* @ param int $hidelabel Hide label ( 0 = no , 1 = yes )
2016-09-11 16:05:38 +02:00
* @ param int $alsoproductwithnosupplierprice 1 = Add also product without supplier prices
2018-12-22 11:57:23 +01:00
* @ param string $morecss More CSS
2021-02-15 14:19:05 +01:00
* @ param string $placeholder Placeholder
2017-10-07 13:09:31 +02:00
* @ return void
*/
2021-02-15 14:19:05 +01:00
public function select_produits_fournisseurs ( $socid , $selected = '' , $htmlname = 'productid' , $filtertype = '' , $filtre = '' , $ajaxoptions = array (), $hidelabel = 0 , $alsoproductwithnosupplierprice = 0 , $morecss = '' , $placeholder = '' )
2017-10-07 13:09:31 +02:00
{
2020-09-07 10:18:17 +02:00
// phpcs:enable
2019-11-08 15:51:54 +01:00
global $langs , $conf ;
2017-10-07 13:09:31 +02:00
global $price_level , $status , $finished ;
2016-08-04 09:21:04 +02:00
2021-05-26 17:24:27 +02:00
if ( ! isset ( $status )) {
2021-05-26 16:44:35 +02:00
$status = 1 ;
}
2019-11-08 15:51:54 +01:00
$selected_input_value = '' ;
2021-02-23 22:03:23 +01:00
if ( ! empty ( $conf -> use_javascript_ajax ) && ! empty ( $conf -> global -> PRODUIT_USE_SEARCH_TO_SELECT )) {
if ( $selected > 0 ) {
2017-10-07 13:09:31 +02:00
require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php' ;
$producttmpselect = new Product ( $this -> db );
$producttmpselect -> fetch ( $selected );
2019-11-08 15:51:54 +01:00
$selected_input_value = $producttmpselect -> ref ;
2017-10-07 13:09:31 +02:00
unset ( $producttmpselect );
}
2016-04-28 20:04:48 +02:00
2016-04-15 12:28:35 +02:00
// mode=2 means suppliers products
2019-11-08 15:51:54 +01:00
$urloption = ( $socid > 0 ? 'socid=' . $socid . '&' : '' ) . 'htmlname=' . $htmlname . '&outjson=1&price_level=' . $price_level . '&type=' . $filtertype . '&mode=2&status=' . $status . '&finished=' . $finished . '&alsoproductwithnosupplierprice=' . $alsoproductwithnosupplierprice ;
2017-10-07 13:09:31 +02:00
print ajax_autocompleter ( $selected , $htmlname , DOL_URL_ROOT . '/product/ajax/products.php' , $urloption , $conf -> global -> PRODUIT_USE_SEARCH_TO_SELECT , 0 , $ajaxoptions );
2021-02-15 14:19:05 +01:00
print ( $hidelabel ? '' : $langs -> trans ( " RefOrLabel " ) . ' : ' ) . '<input type="text" class="minwidth300" name="search_' . $htmlname . '" id="search_' . $htmlname . '" value="' . $selected_input_value . '"' . ( $placeholder ? ' placeholder="' . $placeholder . '"' : '' ) . '>' ;
2020-05-21 15:05:19 +02:00
} else {
2021-05-26 16:44:35 +02:00
print $this -> select_produits_fournisseurs_list ( $socid , $selected , $htmlname , $filtertype , $filtre , '' , $status , 0 , 0 , $alsoproductwithnosupplierprice , $morecss , 0 , $placeholder );
2017-10-07 13:09:31 +02:00
}
}
2010-08-22 17:46:34 +02:00
2020-09-07 10:18:17 +02:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2017-10-07 13:09:31 +02:00
/**
* Return list of suppliers products
*
2021-06-14 13:51:09 +02:00
* @ param int $socid Id of supplier thirdparty ( 0 = no filter )
* @ param int $selected Product price pre - selected ( must be 'id' in product_fournisseur_price or 'idprod_IDPROD' )
* @ param string $htmlname Name of HTML select
* @ param string $filtertype Filter on product type ( '' = nofilter , 0 = product , 1 = service )
* @ param string $filtre Generic filter . Data must not come from user input .
* @ param string $filterkey Filter of produdts
* @ param int $statut - 1 = Return all products , 0 = Products not on buy , 1 = Products on buy
* @ param int $outputmode 0 = HTML select string , 1 = Array
* @ param int $limit Limit of line number
2016-09-11 16:05:38 +02:00
* @ param int $alsoproductwithnosupplierprice 1 = Add also product without supplier prices
2021-06-14 13:51:09 +02:00
* @ param string $morecss Add more CSS
2020-11-26 19:17:09 +01:00
* @ param int $showstockinlist Show stock information ( slower ) .
2021-06-14 13:51:09 +02:00
* @ param string $placeholder Placeholder
* @ return array Array of keys for json
2017-10-07 13:09:31 +02:00
*/
2021-02-15 14:19:05 +01:00
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 = '' )
2017-10-07 13:09:31 +02:00
{
2020-09-07 10:18:17 +02:00
// phpcs:enable
2020-11-26 14:12:02 +01:00
global $langs , $conf , $db , $user ;
2010-08-22 17:46:34 +02:00
2019-11-08 15:51:54 +01:00
$out = '' ;
$outarray = array ();
2017-10-07 13:09:31 +02:00
2020-02-13 11:26:11 +01:00
$maxlengtharticle = ( empty ( $conf -> global -> PRODUCT_MAX_LENGTH_COMBO ) ? 48 : $conf -> global -> PRODUCT_MAX_LENGTH_COMBO );
2017-10-07 13:09:31 +02:00
$langs -> load ( 'stocks' );
2020-09-07 10:18:17 +02:00
// Units
2020-11-25 18:07:52 +01:00
if ( ! empty ( $conf -> global -> PRODUCT_USE_UNITS )) {
2020-09-07 10:18:17 +02:00
$langs -> load ( 'other' );
}
2017-10-07 13:09:31 +02:00
2020-11-26 19:17:09 +01:00
$sql = " SELECT p.rowid, p.ref, p.label, p.price, p.duration, p.fk_product_type, p.stock, " ;
2019-11-08 15:51:54 +01:00
$sql .= " pfp.ref_fourn, pfp.rowid as idprodfournprice, pfp.price as fprice, pfp.quantity, pfp.remise_percent, pfp.remise, pfp.unitprice, " ;
$sql .= " pfp.fk_supplier_price_expression, pfp.fk_product, pfp.tva_tx, pfp.fk_soc, s.nom as name, " ;
$sql .= " pfp.supplier_reputation " ;
2020-10-26 16:31:07 +01:00
// if we use supplier description of the products
if ( ! empty ( $conf -> global -> PRODUIT_FOURN_TEXTS )) {
$sql .= " ,pfp.desc_fourn as description " ;
} else {
$sql .= " ,p.description " ;
}
2020-09-07 10:18:17 +02:00
// Units
2020-11-25 18:07:52 +01:00
if ( ! empty ( $conf -> global -> PRODUCT_USE_UNITS )) {
2020-09-07 10:18:17 +02:00
$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 " ;
}
2021-02-23 22:03:23 +01:00
if ( ! empty ( $conf -> barcode -> enabled )) {
$sql .= " , pfp.barcode " ;
}
2019-11-08 15:51:54 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " product as p " ;
2020-05-14 10:50:20 +02:00
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " product_fournisseur_price as pfp ON ( p.rowid = pfp.fk_product AND pfp.entity IN ( " . getEntity ( 'product' ) . " ) ) " ;
2021-06-14 13:51:09 +02:00
if ( $socid > 0 ) {
$sql .= " AND pfp.fk_soc = " . (( int ) $socid );
2021-02-23 22:03:23 +01:00
}
2019-11-08 15:51:54 +01:00
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " societe as s ON pfp.fk_soc = s.rowid " ;
2020-09-07 10:18:17 +02:00
// Units
2020-11-25 18:07:52 +01:00
if ( ! empty ( $conf -> global -> PRODUCT_USE_UNITS )) {
2020-09-07 10:18:17 +02:00
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " c_units u ON u.rowid = p.fk_unit " ;
}
2019-11-08 15:51:54 +01:00
$sql .= " WHERE p.entity IN ( " . getEntity ( 'product' ) . " ) " ;
2021-05-26 17:10:12 +02:00
if ( $statut != - 1 ) {
2021-05-26 17:20:09 +02:00
$sql .= " AND p.tobuy = " . (( int ) $statut );
2021-05-26 16:44:35 +02:00
}
2021-02-23 22:03:23 +01:00
if ( strval ( $filtertype ) != '' ) {
2021-06-14 13:51:09 +02:00
$sql .= " AND p.fk_product_type = " . (( int ) $filtertype );
2021-02-23 22:03:23 +01:00
}
if ( ! empty ( $filtre )) {
$sql .= " " . $filtre ;
}
2017-10-07 13:09:31 +02:00
// Add criteria on ref/label
2021-02-23 22:03:23 +01:00
if ( $filterkey != '' ) {
2019-11-08 15:51:54 +01:00
$sql .= ' AND (' ;
$prefix = empty ( $conf -> global -> PRODUCT_DONOTSEARCH_ANYWHERE ) ? '%' : '' ; // Can use index if PRODUCT_DONOTSEARCH_ANYWHERE is on
2017-10-07 13:09:31 +02:00
// For natural search
$scrit = explode ( ' ' , $filterkey );
2019-11-08 15:51:54 +01:00
$i = 0 ;
2021-02-23 22:03:23 +01:00
if ( count ( $scrit ) > 1 ) {
$sql .= " ( " ;
}
foreach ( $scrit as $crit ) {
if ( $i > 0 ) {
$sql .= " AND " ;
}
2020-10-26 16:31:07 +01:00
$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 ) . " %' " ;
if ( ! empty ( $conf -> global -> PRODUIT_FOURN_TEXTS )) {
$sql .= " OR pfp.desc_fourn LIKE ' " . $this -> db -> escape ( $prefix . $crit ) . " %' " ;
}
$sql .= " ) " ;
2017-10-07 13:09:31 +02:00
$i ++ ;
}
2021-02-23 22:03:23 +01:00
if ( count ( $scrit ) > 1 ) {
$sql .= " ) " ;
}
2019-11-08 15:51:54 +01:00
if ( ! empty ( $conf -> barcode -> enabled )) {
2020-09-07 10:18:17 +02:00
$sql .= " OR p.barcode LIKE ' " . $this -> db -> escape ( $prefix . $filterkey ) . " %' " ;
$sql .= " OR pfp.barcode LIKE ' " . $this -> db -> escape ( $prefix . $filterkey ) . " %' " ;
}
2019-11-08 15:51:54 +01:00
$sql .= ')' ;
2017-10-07 13:09:31 +02:00
}
2019-11-08 15:51:54 +01:00
$sql .= " ORDER BY pfp.ref_fourn DESC, pfp.quantity ASC " ;
2020-09-19 23:30:29 +02:00
$sql .= $this -> db -> plimit ( $limit , 0 );
2010-08-22 17:46:34 +02:00
2017-10-07 13:09:31 +02:00
// Build output string
2010-08-22 17:46:34 +02:00
2017-10-07 13:09:31 +02:00
dol_syslog ( get_class ( $this ) . " ::select_produits_fournisseurs_list " , LOG_DEBUG );
2019-11-08 15:51:54 +01:00
$result = $this -> db -> query ( $sql );
2021-02-23 22:03:23 +01:00
if ( $result ) {
2017-10-07 13:09:31 +02:00
require_once DOL_DOCUMENT_ROOT . '/product/dynamic_price/class/price_parser.class.php' ;
2020-04-13 16:13:02 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/product.lib.php' ;
2010-08-22 17:46:34 +02:00
2017-10-07 13:09:31 +02:00
$num = $this -> db -> num_rows ( $result );
2010-08-22 17:46:34 +02:00
2017-10-07 13:09:31 +02:00
//$out.='<select class="flat" id="select'.$htmlname.'" name="'.$htmlname.'">'; // remove select to have id same with combo and ajax
2021-02-15 14:19:05 +01:00
$out .= '<select class="flat ' . ( $morecss ? ' ' . $morecss : '' ) . '" id="' . $htmlname . '" name="' . $htmlname . '">' ;
2021-02-23 22:03:23 +01:00
if ( ! $selected ) {
$out .= '<option value="-1" selected>' . ( $placeholder ? $placeholder : ' ' ) . '</option>' ;
} else {
$out .= '<option value="-1">' . ( $placeholder ? $placeholder : ' ' ) . '</option>' ;
}
2010-08-22 17:46:34 +02:00
2017-10-07 13:09:31 +02:00
$i = 0 ;
2021-02-23 22:03:23 +01:00
while ( $i < $num ) {
2017-10-07 13:09:31 +02:00
$objp = $this -> db -> fetch_object ( $result );
2010-08-22 17:46:34 +02:00
2019-11-08 15:51:54 +01:00
$outkey = $objp -> idprodfournprice ; // id in table of price
2021-02-23 22:03:23 +01:00
if ( ! $outkey && $alsoproductwithnosupplierprice ) {
$outkey = 'idprod_' . $objp -> rowid ; // id of product
}
2016-09-11 16:05:38 +02:00
2019-11-08 15:51:54 +01:00
$outref = $objp -> ref ;
$outval = '' ;
2020-02-13 11:26:11 +01:00
$outbarcode = $objp -> barcode ;
2019-11-08 15:51:54 +01:00
$outqty = 1 ;
$outdiscount = 0 ;
$outtype = $objp -> fk_product_type ;
$outdurationvalue = $outtype == Product :: TYPE_SERVICE ? substr ( $objp -> duration , 0 , dol_strlen ( $objp -> duration ) - 1 ) : '' ;
$outdurationunit = $outtype == Product :: TYPE_SERVICE ? substr ( $objp -> duration , - 1 ) : '' ;
2017-10-07 13:09:31 +02:00
2020-09-07 10:18:17 +02:00
// Units
$outvalUnits = '' ;
2020-11-25 18:07:52 +01:00
if ( ! empty ( $conf -> global -> PRODUCT_USE_UNITS )) {
2020-09-07 10:18:17 +02:00
if ( ! empty ( $objp -> unit_short )) {
$outvalUnits .= ' - ' . $objp -> unit_short ;
}
if ( ! empty ( $objp -> weight ) && $objp -> weight_units !== null ) {
$unitToShow = showDimensionInBestUnit ( $objp -> weight , $objp -> weight_units , 'weight' , $langs );
$outvalUnits .= ' - ' . $unitToShow ;
}
if (( ! empty ( $objp -> length ) || ! empty ( $objp -> width ) || ! empty ( $objp -> height )) && $objp -> length_units !== null ) {
$unitToShow = $objp -> length . ' x ' . $objp -> width . ' x ' . $objp -> height . ' ' . measuringUnitString ( 0 , 'size' , $objp -> length_units );
$outvalUnits .= ' - ' . $unitToShow ;
}
if ( ! empty ( $objp -> surface ) && $objp -> surface_units !== null ) {
$unitToShow = showDimensionInBestUnit ( $objp -> surface , $objp -> surface_units , 'surface' , $langs );
$outvalUnits .= ' - ' . $unitToShow ;
}
if ( ! empty ( $objp -> volume ) && $objp -> volume_units !== null ) {
$unitToShow = showDimensionInBestUnit ( $objp -> volume , $objp -> volume_units , 'volume' , $langs );
$outvalUnits .= ' - ' . $unitToShow ;
}
if ( $outdurationvalue && $outdurationunit ) {
$da = array (
'h' => $langs -> trans ( 'Hour' ),
'd' => $langs -> trans ( 'Day' ),
'w' => $langs -> trans ( 'Week' ),
'm' => $langs -> trans ( 'Month' ),
'y' => $langs -> trans ( 'Year' )
);
if ( isset ( $da [ $outdurationunit ])) {
$outvalUnits .= ' - ' . $outdurationvalue . ' ' . $langs -> transnoentities ( $da [ $outdurationunit ] . ( $outdurationvalue > 1 ? 's' : '' ));
}
}
}
2017-10-07 13:09:31 +02:00
$objRef = $objp -> ref ;
2021-02-23 22:03:23 +01:00
if ( $filterkey && $filterkey != '' ) {
$objRef = preg_replace ( '/(' . preg_quote ( $filterkey , '/' ) . ')/i' , '<strong>$1</strong>' , $objRef , 1 );
}
2017-10-07 13:09:31 +02:00
$objRefFourn = $objp -> ref_fourn ;
2021-02-23 22:03:23 +01:00
if ( $filterkey && $filterkey != '' ) {
$objRefFourn = preg_replace ( '/(' . preg_quote ( $filterkey , '/' ) . ')/i' , '<strong>$1</strong>' , $objRefFourn , 1 );
}
2017-10-07 13:09:31 +02:00
$label = $objp -> label ;
2021-02-23 22:03:23 +01:00
if ( $filterkey && $filterkey != '' ) {
$label = preg_replace ( '/(' . preg_quote ( $filterkey , '/' ) . ')/i' , '<strong>$1</strong>' , $label , 1 );
}
2017-10-07 13:09:31 +02:00
2019-10-24 20:33:16 +02:00
$optlabel = $objp -> ref ;
2020-02-13 11:26:11 +01:00
if ( ! empty ( $objp -> idprodfournprice ) && ( $objp -> ref != $objp -> ref_fourn )) {
2019-11-08 15:51:54 +01:00
$optlabel .= ' <span class=\'opacitymedium\'>(' . $objp -> ref_fourn . ')</span>' ;
2020-02-13 11:26:11 +01:00
}
if ( ! empty ( $conf -> barcode -> enabled ) && ! empty ( $objp -> barcode )) {
$optlabel .= ' (' . $outbarcode . ')' ;
}
$optlabel .= ' - ' . dol_trunc ( $label , $maxlengtharticle );
2019-10-24 20:33:16 +02:00
$outvallabel = $objRef ;
2020-02-13 11:26:11 +01:00
if ( ! empty ( $objp -> idprodfournprice ) && ( $objp -> ref != $objp -> ref_fourn )) {
2019-11-08 15:51:54 +01:00
$outvallabel .= ' (' . $objRefFourn . ')' ;
2020-02-13 11:26:11 +01:00
}
if ( ! empty ( $conf -> barcode -> enabled ) && ! empty ( $objp -> barcode )) {
$outvallabel .= ' (' . $outbarcode . ')' ;
}
$outvallabel .= ' - ' . dol_trunc ( $label , $maxlengtharticle );
2019-10-24 20:33:16 +02:00
2020-09-07 10:18:17 +02:00
// Units
2019-10-24 20:33:16 +02:00
$optlabel .= $outvalUnits ;
$outvallabel .= $outvalUnits ;
2017-10-07 13:09:31 +02:00
2021-02-23 22:03:23 +01:00
if ( ! empty ( $objp -> idprodfournprice )) {
2019-11-08 15:51:54 +01:00
$outqty = $objp -> quantity ;
$outdiscount = $objp -> remise_percent ;
2017-10-07 13:09:31 +02:00
if ( ! empty ( $conf -> dynamicprices -> enabled ) && ! empty ( $objp -> fk_supplier_price_expression )) {
$prod_supplier = new ProductFournisseur ( $this -> db );
$prod_supplier -> product_fourn_price_id = $objp -> idprodfournprice ;
$prod_supplier -> id = $objp -> fk_product ;
$prod_supplier -> fourn_qty = $objp -> quantity ;
$prod_supplier -> fourn_tva_tx = $objp -> tva_tx ;
$prod_supplier -> fk_supplier_price_expression = $objp -> fk_supplier_price_expression ;
$priceparser = new PriceParser ( $this -> db );
$price_result = $priceparser -> parseProductSupplier ( $prod_supplier );
if ( $price_result >= 0 ) {
$objp -> fprice = $price_result ;
2021-02-23 22:03:23 +01:00
if ( $objp -> quantity >= 1 ) {
2020-03-12 12:45:44 +01:00
$objp -> unitprice = $objp -> fprice / $objp -> quantity ; // Replace dynamically unitprice
2017-10-07 13:09:31 +02:00
}
}
}
2021-02-23 22:03:23 +01:00
if ( $objp -> quantity == 1 ) {
2019-11-08 15:51:54 +01:00
$optlabel .= ' - ' . price ( $objp -> fprice * ( ! empty ( $conf -> global -> DISPLAY_DISCOUNTED_SUPPLIER_PRICE ) ? ( 1 - $objp -> remise_percent / 100 ) : 1 ), 1 , $langs , 0 , 0 , - 1 , $conf -> currency ) . " / " ;
$outvallabel .= ' - ' . price ( $objp -> fprice * ( ! empty ( $conf -> global -> DISPLAY_DISCOUNTED_SUPPLIER_PRICE ) ? ( 1 - $objp -> remise_percent / 100 ) : 1 ), 0 , $langs , 0 , 0 , - 1 , $conf -> currency ) . " / " ;
$optlabel .= $langs -> trans ( " Unit " ); // Do not use strtolower because it breaks utf8 encoding
$outvallabel .= $langs -> transnoentities ( " Unit " );
2020-05-21 15:05:19 +02:00
} else {
2019-11-08 15:51:54 +01:00
$optlabel .= ' - ' . price ( $objp -> fprice * ( ! empty ( $conf -> global -> DISPLAY_DISCOUNTED_SUPPLIER_PRICE ) ? ( 1 - $objp -> remise_percent / 100 ) : 1 ), 1 , $langs , 0 , 0 , - 1 , $conf -> currency ) . " / " . $objp -> quantity ;
$outvallabel .= ' - ' . price ( $objp -> fprice * ( ! empty ( $conf -> global -> DISPLAY_DISCOUNTED_SUPPLIER_PRICE ) ? ( 1 - $objp -> remise_percent / 100 ) : 1 ), 0 , $langs , 0 , 0 , - 1 , $conf -> currency ) . " / " . $objp -> quantity ;
$optlabel .= ' ' . $langs -> trans ( " Units " ); // Do not use strtolower because it breaks utf8 encoding
$outvallabel .= ' ' . $langs -> transnoentities ( " Units " );
2017-10-07 13:09:31 +02:00
}
2012-10-23 09:30:48 +02:00
2021-02-23 22:03:23 +01:00
if ( $objp -> quantity > 1 ) {
2019-11-08 15:51:54 +01:00
$optlabel .= " ( " . price ( $objp -> unitprice * ( ! empty ( $conf -> global -> DISPLAY_DISCOUNTED_SUPPLIER_PRICE ) ? ( 1 - $objp -> remise_percent / 100 ) : 1 ), 1 , $langs , 0 , 0 , - 1 , $conf -> currency ) . " / " . $langs -> trans ( " Unit " ) . " ) " ; // Do not use strtolower because it breaks utf8 encoding
$outvallabel .= " ( " . price ( $objp -> unitprice * ( ! empty ( $conf -> global -> DISPLAY_DISCOUNTED_SUPPLIER_PRICE ) ? ( 1 - $objp -> remise_percent / 100 ) : 1 ), 0 , $langs , 0 , 0 , - 1 , $conf -> currency ) . " / " . $langs -> transnoentities ( " Unit " ) . " ) " ; // Do not use strtolower because it breaks utf8 encoding
2017-10-07 13:09:31 +02:00
}
2021-02-23 22:03:23 +01:00
if ( $objp -> remise_percent >= 1 ) {
2019-11-08 15:51:54 +01:00
$optlabel .= " - " . $langs -> trans ( " Discount " ) . " : " . vatrate ( $objp -> remise_percent ) . ' %' ;
$outvallabel .= " - " . $langs -> transnoentities ( " Discount " ) . " : " . vatrate ( $objp -> remise_percent ) . ' %' ;
2017-10-07 13:09:31 +02:00
}
2021-02-23 22:03:23 +01:00
if ( $objp -> duration ) {
2019-10-24 20:33:16 +02:00
$optlabel .= " - " . $objp -> duration ;
2019-11-08 15:51:54 +01:00
$outvallabel .= " - " . $objp -> duration ;
2017-10-07 13:09:31 +02:00
}
2021-02-23 22:03:23 +01:00
if ( ! $socid ) {
2019-10-24 20:33:16 +02:00
$optlabel .= " - " . dol_trunc ( $objp -> name , 8 );
2019-11-08 15:51:54 +01:00
$outvallabel .= " - " . dol_trunc ( $objp -> name , 8 );
2017-10-07 13:09:31 +02:00
}
2021-02-23 22:03:23 +01:00
if ( $objp -> supplier_reputation ) {
2017-10-07 13:09:31 +02:00
//TODO dictionary
2019-11-08 15:51:54 +01:00
$reputations = array ( '' => $langs -> trans ( 'Standard' ), 'FAVORITE' => $langs -> trans ( 'Favorite' ), 'NOTTHGOOD' => $langs -> trans ( 'NotTheGoodQualitySupplier' ), 'DONOTORDER' => $langs -> trans ( 'DoNotOrderThisProductToThisSupplier' ));
2016-04-06 10:17:13 +02:00
2019-10-24 20:33:16 +02:00
$optlabel .= " - " . $reputations [ $objp -> supplier_reputation ];
2019-11-08 15:51:54 +01:00
$outvallabel .= " - " . $reputations [ $objp -> supplier_reputation ];
2017-10-07 13:09:31 +02:00
}
2020-05-21 15:05:19 +02:00
} else {
2021-02-23 22:03:23 +01:00
if ( empty ( $alsoproductwithnosupplierprice )) { // No supplier price defined for couple product/supplier
2019-11-08 15:51:54 +01:00
$optlabel .= " - <span class='opacitymedium'> " . $langs -> trans ( " NoPriceDefinedForThisSupplier " ) . '</span>' ;
$outvallabel .= ' - ' . $langs -> transnoentities ( " NoPriceDefinedForThisSupplier " );
2020-05-21 15:05:19 +02:00
} else // No supplier price defined for product, even on other suppliers
2017-10-07 13:09:31 +02:00
{
2019-11-08 15:51:54 +01:00
$optlabel .= " - <span class='opacitymedium'> " . $langs -> trans ( " NoPriceDefinedForThisSupplier " ) . '</span>' ;
$outvallabel .= ' - ' . $langs -> transnoentities ( " NoPriceDefinedForThisSupplier " );
2017-10-07 13:09:31 +02:00
}
}
2019-10-24 20:33:16 +02:00
2021-02-23 22:03:23 +01:00
if ( ! empty ( $conf -> stock -> enabled ) && $showstockinlist && isset ( $objp -> stock ) && ( $objp -> fk_product_type == Product :: TYPE_PRODUCT || ! empty ( $conf -> global -> STOCK_SUPPORTS_SERVICES ))) {
2020-11-26 19:17:09 +01:00
$novirtualstock = ( $showstockinlist == 2 );
2020-11-26 14:12:02 +01:00
if ( ! empty ( $user -> rights -> stock -> lire )) {
2020-12-31 16:06:54 +01:00
$outvallabel .= ' - ' . $langs -> trans ( " Stock " ) . ': ' . price ( price2num ( $objp -> stock , 'MS' ));
2020-11-26 14:12:02 +01:00
if ( $objp -> stock > 0 ) {
2020-11-26 19:17:09 +01:00
$optlabel .= ' - <span class="product_line_stock_ok">' ;
2020-11-26 14:12:02 +01:00
} elseif ( $objp -> stock <= 0 ) {
2020-11-26 19:17:09 +01:00
$optlabel .= ' - <span class="product_line_stock_too_low">' ;
2020-11-26 14:12:02 +01:00
}
2020-12-31 16:06:54 +01:00
$optlabel .= $langs -> transnoentities ( " Stock " ) . ':' . price ( price2num ( $objp -> stock , 'MS' ));
2020-11-26 19:17:09 +01:00
$optlabel .= '</span>' ;
2021-02-23 22:03:23 +01:00
if ( empty ( $novirtualstock ) && ! empty ( $conf -> global -> STOCK_SHOW_VIRTUAL_STOCK_IN_PRODUCTS_COMBO )) { // Warning, this option may slow down combo list generation
2020-11-26 14:12:02 +01:00
$langs -> load ( " stocks " );
$tmpproduct = new Product ( $this -> db );
$tmpproduct -> fetch ( $objp -> rowid , '' , '' , '' , 1 , 1 , 1 ); // Load product without lang and prices arrays (we just need to make ->virtual_stock() after)
$tmpproduct -> load_virtual_stock ();
$virtualstock = $tmpproduct -> stock_theorique ;
2020-11-26 19:17:09 +01:00
$outvallabel .= ' - ' . $langs -> trans ( " VirtualStock " ) . ':' . $virtualstock ;
2020-11-26 14:12:02 +01:00
2020-11-26 19:17:09 +01:00
$optlabel .= ' - ' . $langs -> transnoentities ( " VirtualStock " ) . ':' ;
2020-11-26 14:12:02 +01:00
if ( $virtualstock > 0 ) {
2020-11-26 19:17:09 +01:00
$optlabel .= '<span class="product_line_stock_ok">' ;
2020-11-26 14:12:02 +01:00
} elseif ( $virtualstock <= 0 ) {
2020-11-26 19:17:09 +01:00
$optlabel .= '<span class="product_line_stock_too_low">' ;
2020-11-26 14:12:02 +01:00
}
2020-11-26 19:17:09 +01:00
$optlabel .= $virtualstock ;
$optlabel .= '</span>' ;
2020-11-26 14:12:02 +01:00
unset ( $tmpproduct );
}
}
}
2019-10-24 20:33:16 +02:00
$opt = '<option value="' . $outkey . '"' ;
2021-02-23 22:03:23 +01:00
if ( $selected && $selected == $objp -> idprodfournprice ) {
$opt .= ' selected' ;
}
if ( empty ( $objp -> idprodfournprice ) && empty ( $alsoproductwithnosupplierprice )) {
$opt .= ' disabled' ;
}
if ( ! empty ( $objp -> idprodfournprice ) && $objp -> idprodfournprice > 0 ) {
2020-10-26 16:31:07 +01:00
$opt .= ' data-qty="' . $objp -> quantity . '" data-up="' . $objp -> unitprice . '" data-discount="' . $outdiscount . '"' ;
2019-10-24 20:33:16 +02:00
}
2020-10-26 16:31:07 +01:00
$opt .= ' data-description="' . dol_escape_htmltag ( $objp -> description ) . '"' ;
2019-11-08 15:51:54 +01:00
$opt .= ' data-html="' . dol_escape_htmltag ( $optlabel ) . '"' ;
$opt .= '>' ;
2019-10-24 20:33:16 +02:00
2019-11-08 15:51:54 +01:00
$opt .= $optlabel ;
$outval .= $outvallabel ;
2019-10-24 20:33:16 +02:00
2017-10-07 13:09:31 +02:00
$opt .= " </option> \n " ;
2012-10-23 09:30:48 +02:00
2017-10-07 13:09:31 +02:00
// Add new entry
2021-02-15 13:00:21 +01:00
// "key" value of json key array is used by jQuery automatically as selected value. Example: 'type' = product or service, 'price_ht' = unit price without tax
2017-10-07 13:09:31 +02:00
// "label" value of json key array is used by jQuery automatically as text for combo box
2019-11-08 15:51:54 +01:00
$out .= $opt ;
2021-02-23 22:03:23 +01:00
array_push (
$outarray ,
2020-10-26 16:31:07 +01:00
array ( 'key' => $outkey ,
'value' => $outref ,
'label' => $outval ,
'qty' => $outqty ,
2021-02-15 13:12:27 +01:00
'price_ht' => price2num ( $objp -> unitprice , 'MT' ),
2020-10-26 16:31:07 +01:00
'discount' => $outdiscount ,
'type' => $outtype ,
'duration_value' => $outdurationvalue ,
'duration_unit' => $outdurationunit ,
2021-02-15 13:12:27 +01:00
'disabled' => ( empty ( $objp -> idprodfournprice ) ? true : false ),
2020-10-26 16:31:07 +01:00
'description' => $objp -> description
)
);
2013-06-05 22:01:35 +02:00
// Exemple of var_dump $outarray
2012-10-18 16:30:12 +02:00
// array(1) {[0]=>array(6) {[key"]=>string(1) "2" ["value"]=>string(3) "ppp"
// ["label"]=>string(76) "ppp (<strong>f</strong>ff2) - ppp - 20,00 Euros/1unité (20,00 Euros/unité)"
2012-10-28 13:57:21 +01:00
// ["qty"]=>string(1) "1" ["discount"]=>string(1) "0" ["disabled"]=>bool(false)
2017-10-07 13:09:31 +02:00
//}
//var_dump($outval); var_dump(utf8_check($outval)); var_dump(json_encode($outval));
//$outval=array('label'=>'ppp (<strong>f</strong>ff2) - ppp - 20,00 Euros/ Unité (20,00 Euros/unité)');
//var_dump($outval); var_dump(utf8_check($outval)); var_dump(json_encode($outval));
2010-08-22 17:46:34 +02:00
2017-10-07 13:09:31 +02:00
$i ++ ;
}
2019-11-08 15:51:54 +01:00
$out .= '</select>' ;
2010-08-22 17:46:34 +02:00
2017-10-07 13:09:31 +02:00
$this -> db -> free ( $result );
2010-08-22 17:46:34 +02:00
2019-11-08 15:51:54 +01:00
include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php' ;
$out .= ajax_combobox ( $htmlname );
2010-08-22 17:46:34 +02:00
2021-02-23 22:03:23 +01:00
if ( empty ( $outputmode )) {
return $out ;
}
2017-10-07 13:09:31 +02:00
return $outarray ;
2020-05-21 15:05:19 +02:00
} else {
2017-10-07 13:09:31 +02:00
dol_print_error ( $this -> db );
}
}
2010-08-22 17:46:34 +02:00
2020-09-07 10:18:17 +02:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2017-10-07 13:09:31 +02:00
/**
* Return list of suppliers prices for a product
*
* @ param int $productid Id of product
* @ param string $htmlname Name of HTML field
* @ param int $selected_supplier Pre - selected supplier if more than 1 result
2020-01-13 10:43:39 +01:00
* @ return string
2017-10-07 13:09:31 +02:00
*/
2020-09-07 10:18:17 +02:00
public function select_product_fourn_price ( $productid , $htmlname = 'productfournpriceid' , $selected_supplier = '' )
2017-10-07 13:09:31 +02:00
{
2020-09-07 10:18:17 +02:00
// phpcs:enable
2019-11-08 15:51:54 +01:00
global $langs , $conf ;
2017-10-07 13:09:31 +02:00
$langs -> load ( 'stocks' );
2020-02-13 11:26:11 +01:00
$sql = " SELECT p.rowid, p.ref, p.label, p.price, p.duration, pfp.fk_soc, " ;
2019-11-08 15:51:54 +01:00
$sql .= " pfp.ref_fourn, pfp.rowid as idprodfournprice, pfp.price as fprice, pfp.remise_percent, pfp.quantity, pfp.unitprice, " ;
$sql .= " pfp.fk_supplier_price_expression, pfp.fk_product, pfp.tva_tx, s.nom as name " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " product as p " ;
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " product_fournisseur_price as pfp ON p.rowid = pfp.fk_product " ;
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " societe as s ON pfp.fk_soc = s.rowid " ;
$sql .= " WHERE pfp.entity IN ( " . getEntity ( 'productsupplierprice' ) . " ) " ;
$sql .= " AND p.tobuy = 1 " ;
$sql .= " AND s.fournisseur = 1 " ;
$sql .= " AND p.rowid = " . $productid ;
$sql .= " ORDER BY s.nom, pfp.ref_fourn DESC " ;
2017-10-07 13:09:31 +02:00
dol_syslog ( get_class ( $this ) . " ::select_product_fourn_price " , LOG_DEBUG );
2019-11-08 15:51:54 +01:00
$result = $this -> db -> query ( $sql );
2017-10-07 13:09:31 +02:00
2021-02-23 22:03:23 +01:00
if ( $result ) {
2017-10-07 13:09:31 +02:00
$num = $this -> db -> num_rows ( $result );
2010-08-22 17:46:34 +02:00
2018-12-07 17:28:31 +01:00
$form = '<select class="flat" id="select_' . $htmlname . '" name="' . $htmlname . '">' ;
2010-08-22 17:46:34 +02:00
2021-02-23 22:03:23 +01:00
if ( ! $num ) {
2019-11-08 15:51:54 +01:00
$form .= '<option value="0">-- ' . $langs -> trans ( " NoSupplierPriceDefinedForThisProduct " ) . ' --</option>' ;
2020-05-21 15:05:19 +02:00
} else {
2017-10-07 13:09:31 +02:00
require_once DOL_DOCUMENT_ROOT . '/product/dynamic_price/class/price_parser.class.php' ;
2019-11-08 15:51:54 +01:00
$form .= '<option value="0"> </option>' ;
2010-08-22 17:46:34 +02:00
2017-10-07 13:09:31 +02:00
$i = 0 ;
2021-02-23 22:03:23 +01:00
while ( $i < $num ) {
2017-10-07 13:09:31 +02:00
$objp = $this -> db -> fetch_object ( $result );
2010-08-22 17:46:34 +02:00
2017-10-07 13:09:31 +02:00
$opt = '<option value="' . $objp -> idprodfournprice . '"' ;
//if there is only one supplier, preselect it
2019-11-08 15:51:54 +01:00
if ( $num == 1 || ( $selected_supplier > 0 && $objp -> fk_soc == $selected_supplier )) {
2017-10-07 13:09:31 +02:00
$opt .= ' selected' ;
}
2019-11-08 15:51:54 +01:00
$opt .= '>' . $objp -> name . ' - ' . $objp -> ref_fourn . ' - ' ;
2017-10-07 13:09:31 +02:00
if ( ! empty ( $conf -> dynamicprices -> enabled ) && ! empty ( $objp -> fk_supplier_price_expression )) {
$prod_supplier = new ProductFournisseur ( $this -> db );
$prod_supplier -> product_fourn_price_id = $objp -> idprodfournprice ;
$prod_supplier -> id = $productid ;
$prod_supplier -> fourn_qty = $objp -> quantity ;
$prod_supplier -> fourn_tva_tx = $objp -> tva_tx ;
$prod_supplier -> fk_supplier_price_expression = $objp -> fk_supplier_price_expression ;
$priceparser = new PriceParser ( $this -> db );
$price_result = $priceparser -> parseProductSupplier ( $prod_supplier );
if ( $price_result >= 0 ) {
$objp -> fprice = $price_result ;
2021-02-23 22:03:23 +01:00
if ( $objp -> quantity >= 1 ) {
2017-10-07 13:09:31 +02:00
$objp -> unitprice = $objp -> fprice / $objp -> quantity ;
}
}
}
2021-02-23 22:03:23 +01:00
if ( $objp -> quantity == 1 ) {
2019-11-08 15:51:54 +01:00
$opt .= price ( $objp -> fprice * ( ! empty ( $conf -> global -> DISPLAY_DISCOUNTED_SUPPLIER_PRICE ) ? ( 1 - $objp -> remise_percent / 100 ) : 1 ), 1 , $langs , 0 , 0 , - 1 , $conf -> currency ) . " / " ;
2017-10-07 13:09:31 +02:00
}
2016-04-25 11:26:13 +02:00
2019-11-08 15:51:54 +01:00
$opt .= $objp -> quantity . ' ' ;
2010-08-22 17:46:34 +02:00
2021-02-23 22:03:23 +01:00
if ( $objp -> quantity == 1 ) {
2019-11-08 15:51:54 +01:00
$opt .= $langs -> trans ( " Unit " );
2020-05-21 15:05:19 +02:00
} else {
2019-11-08 15:51:54 +01:00
$opt .= $langs -> trans ( " Units " );
2017-10-07 13:09:31 +02:00
}
2021-02-23 22:03:23 +01:00
if ( $objp -> quantity > 1 ) {
2019-11-08 15:51:54 +01:00
$opt .= " - " ;
$opt .= price ( $objp -> unitprice * ( ! empty ( $conf -> global -> DISPLAY_DISCOUNTED_SUPPLIER_PRICE ) ? ( 1 - $objp -> remise_percent / 100 ) : 1 ), 1 , $langs , 0 , 0 , - 1 , $conf -> currency ) . " / " . $langs -> trans ( " Unit " );
2017-10-07 13:09:31 +02:00
}
2021-02-23 22:03:23 +01:00
if ( $objp -> duration ) {
$opt .= " - " . $objp -> duration ;
}
2017-10-07 13:09:31 +02:00
$opt .= " </option> \n " ;
2010-08-22 17:46:34 +02:00
2019-11-08 15:51:54 +01:00
$form .= $opt ;
2017-10-07 13:09:31 +02:00
$i ++ ;
}
}
2010-08-22 17:46:34 +02:00
2019-11-08 15:51:54 +01:00
$form .= '</select>' ;
2017-10-07 13:09:31 +02:00
$this -> db -> free ( $result );
return $form ;
2020-05-21 15:05:19 +02:00
} else {
2017-10-07 13:09:31 +02:00
dol_print_error ( $this -> db );
}
}
2010-08-22 17:46:34 +02:00
2020-09-07 10:18:17 +02:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2017-10-07 13:09:31 +02:00
/**
* Return list of delivery address
*
* @ param string $selected Id contact pre - selectionn
* @ param int $socid Id of company
* @ param string $htmlname Name of HTML field
* @ param int $showempty Add an empty field
* @ return integer | null
*/
2020-09-07 10:18:17 +02:00
public function select_address ( $selected , $socid , $htmlname = 'address_id' , $showempty = 0 )
2017-10-07 13:09:31 +02:00
{
2020-09-07 10:18:17 +02:00
// phpcs:enable
2018-09-02 09:27:59 +02:00
// looking for users
2017-10-07 13:09:31 +02:00
$sql = " SELECT a.rowid, a.label " ;
2019-11-08 15:51:54 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " societe_address as a " ;
2021-03-30 17:53:25 +02:00
$sql .= " WHERE a.fk_soc = " . (( int ) $socid );
2017-10-07 13:09:31 +02:00
$sql .= " ORDER BY a.label ASC " ;
dol_syslog ( get_class ( $this ) . " ::select_address " , LOG_DEBUG );
2019-11-08 15:51:54 +01:00
$resql = $this -> db -> query ( $sql );
2021-02-23 22:03:23 +01:00
if ( $resql ) {
2018-12-07 17:28:31 +01:00
print '<select class="flat" id="select_' . $htmlname . '" name="' . $htmlname . '">' ;
2021-02-23 22:03:23 +01:00
if ( $showempty ) {
print '<option value="0"> </option>' ;
}
2017-10-07 13:09:31 +02:00
$num = $this -> db -> num_rows ( $resql );
$i = 0 ;
2021-02-23 22:03:23 +01:00
if ( $num ) {
while ( $i < $num ) {
2017-10-07 13:09:31 +02:00
$obj = $this -> db -> fetch_object ( $resql );
2011-04-18 22:56:10 +02:00
2021-02-23 22:03:23 +01:00
if ( $selected && $selected == $obj -> rowid ) {
2017-10-07 13:09:31 +02:00
print '<option value="' . $obj -> rowid . '" selected>' . $obj -> label . '</option>' ;
2020-05-21 15:05:19 +02:00
} else {
2017-10-07 13:09:31 +02:00
print '<option value="' . $obj -> rowid . '">' . $obj -> label . '</option>' ;
}
$i ++ ;
}
}
print '</select>' ;
return $num ;
2020-05-21 15:05:19 +02:00
} else {
2017-10-07 13:09:31 +02:00
dol_print_error ( $this -> db );
}
}
2015-06-06 13:22:15 +02:00
2014-07-24 18:08:08 +02:00
2020-09-07 10:18:17 +02:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2014-11-14 16:43:49 +01:00
/**
2017-10-07 13:09:31 +02:00
* Load into cache list of payment terms
2014-11-14 16:43:49 +01:00
*
2017-10-07 13:09:31 +02:00
* @ return int Nb of lines loaded , < 0 if KO
2014-11-14 16:43:49 +01:00
*/
2020-09-07 10:18:17 +02:00
public function load_cache_conditions_paiements ()
2014-11-14 16:43:49 +01:00
{
2020-09-07 10:18:17 +02:00
// phpcs:enable
2018-03-07 17:53:15 +01:00
global $langs ;
2010-08-22 17:46:34 +02:00
2017-10-07 13:09:31 +02:00
$num = count ( $this -> cache_conditions_paiements );
2021-02-23 22:03:23 +01:00
if ( $num > 0 ) {
return 0 ; // Cache already loaded
}
2010-08-22 17:46:34 +02:00
2017-10-07 13:09:31 +02:00
dol_syslog ( __METHOD__ , LOG_DEBUG );
2015-06-06 13:22:15 +02:00
2017-10-07 13:09:31 +02:00
$sql = " SELECT rowid, code, libelle as label " ;
2019-11-08 15:51:54 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . 'c_payment_term' ;
$sql .= " WHERE entity IN ( " . getEntity ( 'c_payment_term' ) . " ) " ;
$sql .= " AND active > 0 " ;
$sql .= " ORDER BY sortorder " ;
2015-06-06 13:22:15 +02:00
2014-11-14 16:43:49 +01:00
$resql = $this -> db -> query ( $sql );
2021-02-23 22:03:23 +01:00
if ( $resql ) {
2017-10-07 13:09:31 +02:00
$num = $this -> db -> num_rows ( $resql );
$i = 0 ;
2021-02-23 22:03:23 +01:00
while ( $i < $num ) {
2017-10-07 13:09:31 +02:00
$obj = $this -> db -> fetch_object ( $resql );
2010-08-22 17:46:34 +02:00
2017-10-07 13:09:31 +02:00
// Si traduction existe, on l'utilise, sinon on prend le libelle par defaut
2019-11-08 15:51:54 +01:00
$label = ( $langs -> trans ( " PaymentConditionShort " . $obj -> code ) != ( " PaymentConditionShort " . $obj -> code ) ? $langs -> trans ( " PaymentConditionShort " . $obj -> code ) : ( $obj -> label != '-' ? $obj -> label : '' ));
$this -> cache_conditions_paiements [ $obj -> rowid ][ 'code' ] = $obj -> code ;
$this -> cache_conditions_paiements [ $obj -> rowid ][ 'label' ] = $label ;
2017-10-07 13:09:31 +02:00
$i ++ ;
2014-11-14 16:43:49 +01:00
}
2015-06-06 13:22:15 +02:00
2015-06-21 17:05:49 +02:00
//$this->cache_conditions_paiements=dol_sort_array($this->cache_conditions_paiements, 'label', 'asc', 0, 0, 1); // We use the field sortorder of table
2015-06-06 13:22:15 +02:00
2017-10-07 13:09:31 +02:00
return $num ;
2020-05-21 15:05:19 +02:00
} else {
2017-10-07 13:09:31 +02:00
dol_print_error ( $this -> db );
return - 1 ;
2014-11-14 16:43:49 +01:00
}
}
2010-08-22 17:46:34 +02:00
2020-09-07 10:18:17 +02:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2017-10-07 13:09:31 +02:00
/**
* Charge dans cache la liste des délais de livraison possibles
*
* @ return int Nb of lines loaded , < 0 if KO
*/
2020-09-07 10:18:17 +02:00
public function load_cache_availability ()
2017-10-07 13:09:31 +02:00
{
2020-09-07 10:18:17 +02:00
// phpcs:enable
2017-10-07 13:09:31 +02:00
global $langs ;
2011-04-01 12:04:49 +02:00
2017-10-07 13:09:31 +02:00
$num = count ( $this -> cache_availability );
2021-02-23 22:03:23 +01:00
if ( $num > 0 ) {
return 0 ; // Cache already loaded
}
2015-06-06 13:22:15 +02:00
2017-10-07 13:09:31 +02:00
dol_syslog ( __METHOD__ , LOG_DEBUG );
2011-04-01 12:04:49 +02:00
2015-07-17 17:24:11 +02:00
$langs -> load ( 'propal' );
2011-04-01 12:04:49 +02:00
2020-11-05 16:56:28 +01:00
$sql = " SELECT rowid, code, label, position " ;
2019-11-08 15:51:54 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . 'c_availability' ;
$sql .= " WHERE active > 0 " ;
2015-06-06 13:22:15 +02:00
2017-10-07 13:09:31 +02:00
$resql = $this -> db -> query ( $sql );
2021-02-23 22:03:23 +01:00
if ( $resql ) {
2017-10-07 13:09:31 +02:00
$num = $this -> db -> num_rows ( $resql );
$i = 0 ;
2021-02-23 22:03:23 +01:00
while ( $i < $num ) {
2017-10-07 13:09:31 +02:00
$obj = $this -> db -> fetch_object ( $resql );
2011-04-01 12:04:49 +02:00
2017-10-07 13:09:31 +02:00
// Si traduction existe, on l'utilise, sinon on prend le libelle par defaut
2019-11-08 15:51:54 +01:00
$label = ( $langs -> trans ( " AvailabilityType " . $obj -> code ) != ( " AvailabilityType " . $obj -> code ) ? $langs -> trans ( " AvailabilityType " . $obj -> code ) : ( $obj -> label != '-' ? $obj -> label : '' ));
$this -> cache_availability [ $obj -> rowid ][ 'code' ] = $obj -> code ;
$this -> cache_availability [ $obj -> rowid ][ 'label' ] = $label ;
2020-11-05 16:56:28 +01:00
$this -> cache_availability [ $obj -> rowid ][ 'position' ] = $obj -> position ;
2017-10-07 13:09:31 +02:00
$i ++ ;
}
2015-06-06 13:22:15 +02:00
2020-11-05 16:56:28 +01:00
$this -> cache_availability = dol_sort_array ( $this -> cache_availability , 'position' , 'asc' , 0 , 0 , 1 );
2015-06-06 13:22:15 +02:00
2017-10-07 13:09:31 +02:00
return $num ;
2020-05-21 15:05:19 +02:00
} else {
2017-10-07 13:09:31 +02:00
dol_print_error ( $this -> db );
return - 1 ;
2016-05-22 16:36:48 +02:00
}
2017-10-07 13:09:31 +02:00
}
2011-04-01 12:04:49 +02:00
2017-10-07 13:09:31 +02:00
/**
* Retourne la liste des types de delais de livraison possibles
*
2021-05-19 14:38:39 +02:00
* @ param int $selected Id du type de delais pre - selectionne
* @ param string $htmlname Nom de la zone select
* @ param string $filtertype To add a filter
2017-10-07 13:09:31 +02:00
* @ param int $addempty Add empty entry
2021-05-19 14:38:39 +02:00
* @ param string $morecss More CSS
2017-10-07 13:09:31 +02:00
* @ return void
*/
2021-05-19 14:38:39 +02:00
public function selectAvailabilityDelay ( $selected = '' , $htmlname = 'availid' , $filtertype = '' , $addempty = 0 , $morecss = '' )
2017-10-07 13:09:31 +02:00
{
2019-11-08 15:51:54 +01:00
global $langs , $user ;
2011-04-01 12:04:49 +02:00
2017-10-07 13:09:31 +02:00
$this -> load_cache_availability ();
2011-04-01 12:04:49 +02:00
2017-10-07 13:09:31 +02:00
dol_syslog ( __METHOD__ . " selected= " . $selected . " , htmlname= " . $htmlname , LOG_DEBUG );
2015-06-06 13:22:15 +02:00
2021-05-19 14:38:39 +02:00
print '<select id="' . $htmlname . '" class="flat' . ( $morecss ? ' ' . $morecss : '' ) . '" name="' . $htmlname . '">' ;
2021-02-23 22:03:23 +01:00
if ( $addempty ) {
print '<option value="0"> </option>' ;
}
foreach ( $this -> cache_availability as $id => $arrayavailability ) {
if ( $selected == $id ) {
2017-10-07 13:09:31 +02:00
print '<option value="' . $id . '" selected>' ;
2020-05-21 15:05:19 +02:00
} else {
2017-10-07 13:09:31 +02:00
print '<option value="' . $id . '">' ;
}
2021-05-19 14:38:39 +02:00
print dol_escape_htmltag ( $arrayavailability [ 'label' ]);
2017-10-07 13:09:31 +02:00
print '</option>' ;
}
print '</select>' ;
2021-02-23 22:03:23 +01:00
if ( $user -> admin ) {
print info_admin ( $langs -> trans ( " YouCanChangeValuesForThisListFromDictionarySetup " ), 1 );
}
2020-10-17 15:53:31 +02:00
print ajax_combobox ( $htmlname );
2017-10-07 13:09:31 +02:00
}
2011-04-01 12:04:49 +02:00
2017-10-07 13:09:31 +02:00
/**
* Load into cache cache_demand_reason , array of input reasons
*
* @ return int Nb of lines loaded , < 0 if KO
*/
2020-09-07 10:18:17 +02:00
public function loadCacheInputReason ()
2017-10-07 13:09:31 +02:00
{
global $langs ;
2015-06-06 14:21:18 +02:00
2017-10-07 13:09:31 +02:00
$num = count ( $this -> cache_demand_reason );
2021-02-23 22:03:23 +01:00
if ( $num > 0 ) {
return 0 ; // Cache already loaded
}
2011-05-09 15:39:23 +02:00
2017-10-07 13:09:31 +02:00
$sql = " SELECT rowid, code, label " ;
2019-11-08 15:51:54 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . 'c_input_reason' ;
$sql .= " WHERE active > 0 " ;
2017-10-07 13:09:31 +02:00
$resql = $this -> db -> query ( $sql );
2021-02-23 22:03:23 +01:00
if ( $resql ) {
2017-10-07 13:09:31 +02:00
$num = $this -> db -> num_rows ( $resql );
$i = 0 ;
2019-11-08 15:51:54 +01:00
$tmparray = array ();
2021-02-23 22:03:23 +01:00
while ( $i < $num ) {
2017-10-07 13:09:31 +02:00
$obj = $this -> db -> fetch_object ( $resql );
2011-04-18 22:56:10 +02:00
2017-10-07 13:09:31 +02:00
// Si traduction existe, on l'utilise, sinon on prend le libelle par defaut
2019-11-08 15:51:54 +01:00
$label = ( $obj -> label != '-' ? $obj -> label : '' );
2021-02-23 22:03:23 +01:00
if ( $langs -> trans ( " DemandReasonType " . $obj -> code ) != ( " DemandReasonType " . $obj -> code )) {
$label = $langs -> trans ( " DemandReasonType " . $obj -> code ); // So translation key DemandReasonTypeSRC_XXX will work
}
if ( $langs -> trans ( $obj -> code ) != $obj -> code ) {
$label = $langs -> trans ( $obj -> code ); // So translation key SRC_XXX will work
}
2018-10-08 14:04:22 +02:00
2019-11-08 15:51:54 +01:00
$tmparray [ $obj -> rowid ][ 'id' ] = $obj -> rowid ;
$tmparray [ $obj -> rowid ][ 'code' ] = $obj -> code ;
$tmparray [ $obj -> rowid ][ 'label' ] = $label ;
2017-10-07 13:09:31 +02:00
$i ++ ;
}
2019-11-08 15:51:54 +01:00
$this -> cache_demand_reason = dol_sort_array ( $tmparray , 'label' , 'asc' , 0 , 0 , 1 );
2017-10-07 13:09:31 +02:00
unset ( $tmparray );
return $num ;
2020-05-21 15:05:19 +02:00
} else {
2017-10-07 13:09:31 +02:00
dol_print_error ( $this -> db );
return - 1 ;
2017-04-07 16:44:43 +02:00
}
2017-10-07 13:09:31 +02:00
}
2017-05-25 08:48:59 +02:00
2017-10-07 13:09:31 +02:00
/**
2014-04-02 14:53:42 +02:00
* Return list of input reason ( events that triggered an object creation , like after sending an emailing , making an advert , ... )
* List found into table c_input_reason loaded by loadCacheInputReason
2017-10-07 13:09:31 +02:00
*
* @ param int $selected Id or code of type origin to select by default
* @ param string $htmlname Nom de la zone select
* @ param string $exclude To exclude a code value ( Example : SRC_PROP )
* @ param int $addempty Add an empty entry
2021-03-02 00:11:15 +01:00
* @ param string $morecss Add more css to the HTML select component
* @ param int $notooltip Do not show the tooltip for admin
2017-10-07 13:09:31 +02:00
* @ return void
*/
2021-03-02 00:11:15 +01:00
public function selectInputReason ( $selected = '' , $htmlname = 'demandreasonid' , $exclude = '' , $addempty = 0 , $morecss = '' , $notooltip = 0 )
2017-10-07 13:09:31 +02:00
{
2019-11-08 15:51:54 +01:00
global $langs , $user ;
2011-04-18 22:56:10 +02:00
2017-10-07 13:09:31 +02:00
$this -> loadCacheInputReason ();
2011-04-18 22:56:10 +02:00
2021-03-02 00:11:15 +01:00
print '<select class="flat' . ( $morecss ? ' ' . $morecss : '' ) . '" id="select_' . $htmlname . '" name="' . $htmlname . '">' ;
2021-02-23 22:03:23 +01:00
if ( $addempty ) {
print '<option value="0"' . ( empty ( $selected ) ? ' selected' : '' ) . '> </option>' ;
}
foreach ( $this -> cache_demand_reason as $id => $arraydemandreason ) {
if ( $arraydemandreason [ 'code' ] == $exclude ) {
continue ;
}
2011-05-07 13:36:47 +02:00
2021-02-23 22:03:23 +01:00
if ( $selected && ( $selected == $arraydemandreason [ 'id' ] || $selected == $arraydemandreason [ 'code' ])) {
2017-10-07 13:09:31 +02:00
print '<option value="' . $arraydemandreason [ 'id' ] . '" selected>' ;
2020-05-21 15:05:19 +02:00
} else {
2017-10-07 13:09:31 +02:00
print '<option value="' . $arraydemandreason [ 'id' ] . '">' ;
}
2019-11-08 15:51:54 +01:00
$label = $arraydemandreason [ 'label' ]; // Translation of label was already done into the ->loadCacheInputReason
2018-10-08 14:04:22 +02:00
print $langs -> trans ( $label );
2017-10-07 13:09:31 +02:00
print '</option>' ;
}
print '</select>' ;
2021-03-02 00:11:15 +01:00
if ( $user -> admin && empty ( $notooltip )) {
2021-02-23 22:03:23 +01:00
print info_admin ( $langs -> trans ( " YouCanChangeValuesForThisListFromDictionarySetup " ), 1 );
}
2020-10-17 15:53:31 +02:00
print ajax_combobox ( 'select_' . $htmlname );
2017-10-07 13:09:31 +02:00
}
2011-04-18 22:56:10 +02:00
2020-09-07 10:18:17 +02:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2017-10-07 13:09:31 +02:00
/**
* Charge dans cache la liste des types de paiements possibles
*
* @ return int Nb of lines loaded , < 0 if KO
*/
2020-09-07 10:18:17 +02:00
public function load_cache_types_paiements ()
2017-10-07 13:09:31 +02:00
{
2020-09-07 10:18:17 +02:00
// phpcs:enable
2018-03-07 17:53:15 +01:00
global $langs ;
2010-08-22 17:46:34 +02:00
2019-11-08 15:51:54 +01:00
$num = count ( $this -> cache_types_paiements );
2021-02-23 22:03:23 +01:00
if ( $num > 0 ) {
return $num ; // Cache already loaded
}
2015-06-06 13:22:15 +02:00
2017-10-07 13:09:31 +02:00
dol_syslog ( __METHOD__ , LOG_DEBUG );
2010-08-22 17:46:34 +02:00
2017-10-07 13:09:31 +02:00
$this -> cache_types_paiements = array ();
2015-06-21 17:05:49 +02:00
2017-10-07 13:09:31 +02:00
$sql = " SELECT id, code, libelle as label, type, active " ;
2019-11-08 15:51:54 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " c_paiement " ;
$sql .= " WHERE entity IN ( " . getEntity ( 'c_paiement' ) . " ) " ;
2015-06-06 13:22:15 +02:00
2017-10-07 13:09:31 +02:00
$resql = $this -> db -> query ( $sql );
2021-02-23 22:03:23 +01:00
if ( $resql ) {
2017-10-07 13:09:31 +02:00
$num = $this -> db -> num_rows ( $resql );
$i = 0 ;
2021-02-23 22:03:23 +01:00
while ( $i < $num ) {
2017-10-07 13:09:31 +02:00
$obj = $this -> db -> fetch_object ( $resql );
// Si traduction existe, on l'utilise, sinon on prend le libelle par defaut
2019-11-08 15:51:54 +01:00
$label = ( $langs -> transnoentitiesnoconv ( " PaymentTypeShort " . $obj -> code ) != ( " PaymentTypeShort " . $obj -> code ) ? $langs -> transnoentitiesnoconv ( " PaymentTypeShort " . $obj -> code ) : ( $obj -> label != '-' ? $obj -> label : '' ));
$this -> cache_types_paiements [ $obj -> id ][ 'id' ] = $obj -> id ;
$this -> cache_types_paiements [ $obj -> id ][ 'code' ] = $obj -> code ;
$this -> cache_types_paiements [ $obj -> id ][ 'label' ] = $label ;
$this -> cache_types_paiements [ $obj -> id ][ 'type' ] = $obj -> type ;
$this -> cache_types_paiements [ $obj -> id ][ 'active' ] = $obj -> active ;
2017-10-07 13:09:31 +02:00
$i ++ ;
}
2015-06-06 13:22:15 +02:00
2017-10-07 13:09:31 +02:00
$this -> cache_types_paiements = dol_sort_array ( $this -> cache_types_paiements , 'label' , 'asc' , 0 , 0 , 1 );
2015-06-06 13:22:15 +02:00
2017-10-07 13:09:31 +02:00
return $num ;
2020-05-21 15:05:19 +02:00
} else {
2017-10-07 13:09:31 +02:00
dol_print_error ( $this -> db );
return - 1 ;
}
}
2010-08-22 17:46:34 +02:00
2020-09-07 10:18:17 +02:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2017-10-07 13:09:31 +02:00
/**
* Return list of payment modes .
* Constant MAIN_DEFAULT_PAYMENT_TERM_ID can used to set default value but scope is all application , probably not what you want .
* See instead to force the default value by the caller .
*
* @ param int $selected Id of payment term to preselect by default
* @ param string $htmlname Nom de la zone select
* @ param int $filtertype Not used
* @ param int $addempty Add an empty entry
* @ param int $noinfoadmin 0 = Add admin info , 1 = Disable admin info
* @ param string $morecss Add more CSS on select tag
* @ return void
*/
2020-09-07 10:18:17 +02:00
public function select_conditions_paiements ( $selected = 0 , $htmlname = 'condid' , $filtertype = - 1 , $addempty = 0 , $noinfoadmin = 0 , $morecss = '' )
2017-10-07 13:09:31 +02:00
{
2020-09-07 10:18:17 +02:00
// phpcs:enable
2017-10-07 13:09:31 +02:00
global $langs , $user , $conf ;
2010-08-22 17:46:34 +02:00
2017-10-07 13:09:31 +02:00
dol_syslog ( __METHOD__ . " selected= " . $selected . " , htmlname= " . $htmlname , LOG_DEBUG );
2015-06-06 13:22:15 +02:00
2017-10-07 13:09:31 +02:00
$this -> load_cache_conditions_paiements ();
2010-08-22 17:46:34 +02:00
2017-10-07 13:09:31 +02:00
// Set default value if not already set by caller
2021-02-23 22:03:23 +01:00
if ( empty ( $selected ) && ! empty ( $conf -> global -> MAIN_DEFAULT_PAYMENT_TERM_ID )) {
$selected = $conf -> global -> MAIN_DEFAULT_PAYMENT_TERM_ID ;
}
2016-11-06 15:01:40 +01:00
2019-11-08 15:51:54 +01:00
print '<select id="' . $htmlname . '" class="flat selectpaymentterms' . ( $morecss ? ' ' . $morecss : '' ) . '" name="' . $htmlname . '">' ;
2021-02-23 22:03:23 +01:00
if ( $addempty ) {
print '<option value="0"> </option>' ;
}
foreach ( $this -> cache_conditions_paiements as $id => $arrayconditions ) {
if ( $selected == $id ) {
2017-10-07 13:09:31 +02:00
print '<option value="' . $id . '" selected>' ;
2020-05-21 15:05:19 +02:00
} else {
2017-10-07 13:09:31 +02:00
print '<option value="' . $id . '">' ;
}
print $arrayconditions [ 'label' ];
print '</option>' ;
}
print '</select>' ;
2021-02-23 22:03:23 +01:00
if ( $user -> admin && empty ( $noinfoadmin )) {
print info_admin ( $langs -> trans ( " YouCanChangeValuesForThisListFromDictionarySetup " ), 1 );
}
2020-10-08 19:22:21 +02:00
print ajax_combobox ( $htmlname );
2017-10-07 13:09:31 +02:00
}
2010-08-22 17:46:34 +02:00
2020-09-07 10:18:17 +02:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2016-01-18 19:45:27 +01:00
/**
2017-10-07 13:09:31 +02:00
* Return list of payment methods
2020-03-06 15:05:18 +01:00
* Constant MAIN_DEFAULT_PAYMENT_TYPE_ID can used to set default value but scope is all application , probably not what you want .
2017-10-07 13:09:31 +02:00
*
2020-03-22 20:50:50 +01:00
* @ param string $selected Id or code or preselected payment mode
* @ param string $htmlname Name of select field
2017-10-07 13:09:31 +02:00
* @ param string $filtertype To filter on field type in llx_c_paiement ( 'CRDT' or 'DBIT' or array ( 'code' => xx , 'label' => zz ))
2020-03-22 20:50:50 +01:00
* @ param int $format 0 = id + label , 1 = code + code , 2 = code + label , 3 = id + code
* @ param int $empty 1 = can be empty , 0 otherwise
2017-10-07 13:09:31 +02:00
* @ param int $noadmininfo 0 = Add admin info , 1 = Disable admin info
* @ param int $maxlength Max length of label
* @ param int $active Active or not , - 1 = all
* @ param string $morecss Add more CSS on select tag
* @ return void
*/
2020-09-07 10:18:17 +02:00
public function select_types_paiements ( $selected = '' , $htmlname = 'paiementtype' , $filtertype = '' , $format = 0 , $empty = 1 , $noadmininfo = 0 , $maxlength = 0 , $active = 1 , $morecss = '' )
2017-09-12 09:27:59 +02:00
{
2020-09-07 10:18:17 +02:00
// phpcs:enable
2020-02-11 09:57:52 +01:00
global $langs , $user , $conf ;
2010-08-22 17:46:34 +02:00
2017-10-07 13:09:31 +02:00
dol_syslog ( __METHOD__ . " " . $selected . " , " . $htmlname . " , " . $filtertype . " , " . $format , LOG_DEBUG );
2011-08-12 23:29:29 +02:00
2019-11-08 15:51:54 +01:00
$filterarray = array ();
2021-02-23 22:03:23 +01:00
if ( $filtertype == 'CRDT' ) {
$filterarray = array ( 0 , 2 , 3 );
} elseif ( $filtertype == 'DBIT' ) {
$filterarray = array ( 1 , 2 , 3 );
} elseif ( $filtertype != '' && $filtertype != '-1' ) {
$filterarray = explode ( ',' , $filtertype );
}
2010-08-22 17:46:34 +02:00
2017-10-07 13:09:31 +02:00
$this -> load_cache_types_paiements ();
2010-08-22 17:46:34 +02:00
2020-02-11 09:57:52 +01:00
// Set default value if not already set by caller
2021-02-23 22:03:23 +01:00
if ( empty ( $selected ) && ! empty ( $conf -> global -> MAIN_DEFAULT_PAYMENT_TYPE_ID )) {
$selected = $conf -> global -> MAIN_DEFAULT_PAYMENT_TYPE_ID ;
}
2010-08-22 17:46:34 +02:00
2019-11-08 15:51:54 +01:00
print '<select id="select' . $htmlname . '" class="flat selectpaymenttypes' . ( $morecss ? ' ' . $morecss : '' ) . '" name="' . $htmlname . '">' ;
2021-02-23 22:03:23 +01:00
if ( $empty ) {
print '<option value=""> </option>' ;
}
foreach ( $this -> cache_types_paiements as $id => $arraytypes ) {
2017-10-07 13:09:31 +02:00
// If not good status
2021-02-23 22:03:23 +01:00
if ( $active >= 0 && $arraytypes [ 'active' ] != $active ) {
continue ;
}
2017-10-07 13:09:31 +02:00
// On passe si on a demande de filtrer sur des modes de paiments particuliers
2021-02-23 22:03:23 +01:00
if ( count ( $filterarray ) && ! in_array ( $arraytypes [ 'type' ], $filterarray )) {
continue ;
}
2017-10-07 13:09:31 +02:00
// We discard empty line if showempty is on because an empty line has already been output.
2021-02-23 22:03:23 +01:00
if ( $empty && empty ( $arraytypes [ 'code' ])) {
continue ;
}
2017-10-07 13:09:31 +02:00
2021-02-23 22:03:23 +01:00
if ( $format == 0 ) {
print '<option value="' . $id . '"' ;
} elseif ( $format == 1 ) {
print '<option value="' . $arraytypes [ 'code' ] . '"' ;
} elseif ( $format == 2 ) {
print '<option value="' . $arraytypes [ 'code' ] . '"' ;
} elseif ( $format == 3 ) {
print '<option value="' . $id . '"' ;
}
2020-03-22 20:50:50 +01:00
// Print attribute selected or not
2020-04-10 10:59:32 +02:00
if ( $format == 1 || $format == 2 ) {
2021-02-23 22:03:23 +01:00
if ( $selected == $arraytypes [ 'code' ]) {
print ' selected' ;
}
2020-03-22 20:50:50 +01:00
} else {
2021-02-23 22:03:23 +01:00
if ( $selected == $id ) {
print ' selected' ;
}
2020-03-22 20:50:50 +01:00
}
2017-10-07 13:09:31 +02:00
print '>' ;
2021-02-23 22:03:23 +01:00
if ( $format == 0 ) {
$value = ( $maxlength ? dol_trunc ( $arraytypes [ 'label' ], $maxlength ) : $arraytypes [ 'label' ]);
} elseif ( $format == 1 ) {
$value = $arraytypes [ 'code' ];
} elseif ( $format == 2 ) {
$value = ( $maxlength ? dol_trunc ( $arraytypes [ 'label' ], $maxlength ) : $arraytypes [ 'label' ]);
} elseif ( $format == 3 ) {
$value = $arraytypes [ 'code' ];
}
2019-11-08 15:51:54 +01:00
print $value ? $value : ' ' ;
2017-10-07 13:09:31 +02:00
print '</option>' ;
}
print '</select>' ;
2021-02-23 22:03:23 +01:00
if ( $user -> admin && ! $noadmininfo ) {
print info_admin ( $langs -> trans ( " YouCanChangeValuesForThisListFromDictionarySetup " ), 1 );
}
2020-10-08 19:22:21 +02:00
print ajax_combobox ( 'select' . $htmlname );
2017-10-07 13:09:31 +02:00
}
2010-08-22 17:46:34 +02:00
2017-10-07 13:09:31 +02:00
/**
* Selection HT or TTC
*
* @ param string $selected Id pre - selectionne
* @ param string $htmlname Nom de la zone select
2020-12-15 11:18:29 +01:00
* @ param string $addjscombo Add js combo
2017-10-07 13:09:31 +02:00
* @ return string Code of HTML select to chose tax or not
*/
2020-12-15 11:18:29 +01:00
public function selectPriceBaseType ( $selected = '' , $htmlname = 'price_base_type' , $addjscombo = 0 )
2017-10-07 13:09:31 +02:00
{
global $langs ;
2020-12-15 11:18:29 +01:00
$return = '<select class="flat maxwidth100" id="select_' . $htmlname . '" name="' . $htmlname . '">' ;
2017-10-07 13:09:31 +02:00
$options = array (
2012-03-12 15:09:46 +01:00
'HT' => $langs -> trans ( " HT " ),
'TTC' => $langs -> trans ( " TTC " )
2017-10-07 13:09:31 +02:00
);
2021-02-23 22:03:23 +01:00
foreach ( $options as $id => $value ) {
if ( $selected == $id ) {
2019-11-08 15:51:54 +01:00
$return .= '<option value="' . $id . '" selected>' . $value ;
2020-05-21 15:05:19 +02:00
} else {
2019-11-08 15:51:54 +01:00
$return .= '<option value="' . $id . '">' . $value ;
2017-10-07 13:09:31 +02:00
}
2019-11-08 15:51:54 +01:00
$return .= '</option>' ;
2017-10-07 13:09:31 +02:00
}
2019-11-08 15:51:54 +01:00
$return .= '</select>' ;
2021-02-23 22:03:23 +01:00
if ( $addjscombo ) {
$return .= ajax_combobox ( 'select_' . $htmlname );
}
2010-08-22 17:46:34 +02:00
2017-10-07 13:09:31 +02:00
return $return ;
}
2010-08-22 17:46:34 +02:00
2020-10-31 14:32:18 +01:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Load in cache list of transport mode
*
* @ return int Nb of lines loaded , < 0 if KO
*/
public function load_cache_transport_mode ()
{
// phpcs:enable
global $langs ;
2020-10-31 18:51:30 +01:00
$num = count ( $this -> cache_transport_mode );
2021-02-23 22:03:23 +01:00
if ( $num > 0 ) {
return $num ; // Cache already loaded
}
2020-10-31 14:32:18 +01:00
dol_syslog ( __METHOD__ , LOG_DEBUG );
$this -> cache_transport_mode = array ();
$sql = " SELECT rowid, code, label, active " ;
2020-10-31 18:51:30 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " c_transport_mode " ;
$sql .= " WHERE entity IN ( " . getEntity ( 'c_transport_mode' ) . " ) " ;
2020-10-31 14:32:18 +01:00
$resql = $this -> db -> query ( $sql );
2021-02-23 22:03:23 +01:00
if ( $resql ) {
2020-10-31 14:32:18 +01:00
$num = $this -> db -> num_rows ( $resql );
$i = 0 ;
2021-02-23 22:03:23 +01:00
while ( $i < $num ) {
2020-10-31 14:32:18 +01:00
$obj = $this -> db -> fetch_object ( $resql );
// If traduction exist, we use it else we take the default label
2020-10-31 18:51:30 +01:00
$label = ( $langs -> transnoentitiesnoconv ( " PaymentTypeShort " . $obj -> code ) != ( " PaymentTypeShort " . $obj -> code ) ? $langs -> transnoentitiesnoconv ( " PaymentTypeShort " . $obj -> code ) : ( $obj -> label != '-' ? $obj -> label : '' ));
2020-10-31 14:32:18 +01:00
$this -> cache_transport_mode [ $obj -> rowid ][ 'rowid' ] = $obj -> rowid ;
$this -> cache_transport_mode [ $obj -> rowid ][ 'code' ] = $obj -> code ;
2020-10-31 18:51:30 +01:00
$this -> cache_transport_mode [ $obj -> rowid ][ 'label' ] = $label ;
2020-10-31 14:32:18 +01:00
$this -> cache_transport_mode [ $obj -> rowid ][ 'active' ] = $obj -> active ;
$i ++ ;
}
$this -> cache_transport_mode = dol_sort_array ( $this -> cache_transport_mode , 'label' , 'asc' , 0 , 0 , 1 );
return $num ;
2021-02-23 22:03:23 +01:00
} else {
2020-10-31 14:32:18 +01:00
dol_print_error ( $this -> db );
return - 1 ;
}
}
2019-07-22 06:56:55 +02:00
2020-10-31 14:32:18 +01:00
/**
* Return list of transport mode for intracomm report
*
* @ param string $selected Id of the transport mode pre - selected
* @ param string $htmlname Name of the select field
* @ param int $format 0 = id + label , 1 = code + code , 2 = code + label , 3 = id + code
* @ param int $empty 1 = can be empty , 0 else
* @ param int $noadmininfo 0 = Add admin info , 1 = Disable admin info
* @ param int $maxlength Max length of label
* @ param int $active Active or not , - 1 = all
* @ param string $morecss Add more CSS on select tag
* @ return void
*/
public function selectTransportMode ( $selected = '' , $htmlname = 'transportmode' , $format = 0 , $empty = 1 , $noadmininfo = 0 , $maxlength = 0 , $active = 1 , $morecss = '' )
{
2020-10-31 18:51:30 +01:00
global $langs , $user ;
2019-07-22 06:56:55 +02:00
2020-10-31 14:32:18 +01:00
dol_syslog ( __METHOD__ . " " . $selected . " , " . $htmlname . " , " . $format , LOG_DEBUG );
$this -> load_cache_transport_mode ();
2020-10-31 18:51:30 +01:00
print '<select id="select' . $htmlname . '" class="flat selectmodetransport' . ( $morecss ? ' ' . $morecss : '' ) . '" name="' . $htmlname . '">' ;
2021-02-23 22:03:23 +01:00
if ( $empty ) {
print '<option value=""> </option>' ;
}
foreach ( $this -> cache_transport_mode as $id => $arraytypes ) {
2020-10-31 14:32:18 +01:00
// If not good status
2021-02-23 22:03:23 +01:00
if ( $active >= 0 && $arraytypes [ 'active' ] != $active ) {
continue ;
}
2020-10-31 14:32:18 +01:00
// We discard empty line if showempty is on because an empty line has already been output.
2021-02-23 22:03:23 +01:00
if ( $empty && empty ( $arraytypes [ 'code' ])) {
continue ;
}
2020-10-31 14:32:18 +01:00
2021-02-23 22:03:23 +01:00
if ( $format == 0 ) {
print '<option value="' . $id . '"' ;
} elseif ( $format == 1 ) {
print '<option value="' . $arraytypes [ 'code' ] . '"' ;
} elseif ( $format == 2 ) {
print '<option value="' . $arraytypes [ 'code' ] . '"' ;
} elseif ( $format == 3 ) {
print '<option value="' . $id . '"' ;
}
2020-10-31 14:32:18 +01:00
// If text is selected, we compare with code, else with id
2021-02-23 22:03:23 +01:00
if ( preg_match ( '/[a-z]/i' , $selected ) && $selected == $arraytypes [ 'code' ]) {
print ' selected' ;
} elseif ( $selected == $id ) {
print ' selected' ;
}
2020-10-31 14:32:18 +01:00
print '>' ;
2021-02-23 22:03:23 +01:00
if ( $format == 0 ) {
$value = ( $maxlength ? dol_trunc ( $arraytypes [ 'label' ], $maxlength ) : $arraytypes [ 'label' ]);
} elseif ( $format == 1 ) {
$value = $arraytypes [ 'code' ];
} elseif ( $format == 2 ) {
$value = ( $maxlength ? dol_trunc ( $arraytypes [ 'label' ], $maxlength ) : $arraytypes [ 'label' ]);
} elseif ( $format == 3 ) {
$value = $arraytypes [ 'code' ];
}
2020-10-31 18:51:30 +01:00
print $value ? $value : ' ' ;
2020-10-31 14:32:18 +01:00
print '</option>' ;
}
print '</select>' ;
2021-02-23 22:03:23 +01:00
if ( $user -> admin && ! $noadmininfo ) {
print info_admin ( $langs -> trans ( " YouCanChangeValuesForThisListFromDictionarySetup " ), 1 );
}
2020-10-31 14:32:18 +01:00
}
2019-07-22 06:56:55 +02:00
2017-10-07 13:09:31 +02:00
/**
* Return a HTML select list of shipping mode
*
2021-05-19 14:38:39 +02:00
* @ param string $selected Id shipping mode pre - selected
* @ param string $htmlname Name of select zone
* @ param string $filtre To filter list . This parameter must not come from input of users
* @ param int $useempty 1 = Add an empty value in list , 2 = Add an empty value in list only if there is more than 2 entries .
* @ param string $moreattrib To add more attribute on select
2021-01-05 22:50:54 +01:00
* @ param int $noinfoadmin 0 = Add admin info , 1 = Disable admin info
2021-05-19 14:38:39 +02:00
* @ param string $morecss More CSS
2017-10-07 13:09:31 +02:00
* @ return void
*/
2021-05-19 14:38:39 +02:00
public function selectShippingMethod ( $selected = '' , $htmlname = 'shipping_method_id' , $filtre = '' , $useempty = 0 , $moreattrib = '' , $noinfoadmin = 0 , $morecss = '' )
2017-10-07 13:09:31 +02:00
{
global $langs , $conf , $user ;
$langs -> load ( " admin " );
$langs -> load ( " deliveries " );
$sql = " SELECT rowid, code, libelle as label " ;
2019-11-08 15:51:54 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " c_shipment_mode " ;
$sql .= " WHERE active > 0 " ;
2021-02-23 22:03:23 +01:00
if ( $filtre ) {
$sql .= " AND " . $filtre ;
}
2019-11-08 15:51:54 +01:00
$sql .= " ORDER BY libelle ASC " ;
2017-10-07 13:09:31 +02:00
dol_syslog ( get_class ( $this ) . " ::selectShippingMode " , LOG_DEBUG );
$result = $this -> db -> query ( $sql );
if ( $result ) {
$num = $this -> db -> num_rows ( $result );
$i = 0 ;
if ( $num ) {
2021-05-19 14:38:39 +02:00
print '<select id="select' . $htmlname . '" class="flat selectshippingmethod' . ( $morecss ? ' ' . $morecss : '' ) . '" name="' . $htmlname . '"' . ( $moreattrib ? ' ' . $moreattrib : '' ) . '>' ;
2017-10-07 13:09:31 +02:00
if ( $useempty == 1 || ( $useempty == 2 && $num > 1 )) {
print '<option value="-1"> </option>' ;
}
while ( $i < $num ) {
$obj = $this -> db -> fetch_object ( $result );
if ( $selected == $obj -> rowid ) {
print '<option value="' . $obj -> rowid . '" selected>' ;
} else {
print '<option value="' . $obj -> rowid . '">' ;
}
print ( $langs -> trans ( " SendingMethod " . strtoupper ( $obj -> code )) != " SendingMethod " . strtoupper ( $obj -> code )) ? $langs -> trans ( " SendingMethod " . strtoupper ( $obj -> code )) : $obj -> label ;
print '</option>' ;
$i ++ ;
}
print " </select> " ;
2021-02-23 22:03:23 +01:00
if ( $user -> admin && empty ( $noinfoadmin )) {
print info_admin ( $langs -> trans ( " YouCanChangeValuesForThisListFromDictionarySetup " ), 1 );
}
2020-10-17 15:53:31 +02:00
print ajax_combobox ( 'select' . $htmlname );
2017-10-07 13:09:31 +02:00
} else {
print $langs -> trans ( " NoShippingMethodDefined " );
}
} else {
dol_print_error ( $this -> db );
}
}
2014-08-14 01:04:15 +02:00
2017-10-07 13:09:31 +02:00
/**
* Display form to select shipping mode
*
* @ param string $page Page
* @ param int $selected Id of shipping mode
* @ param string $htmlname Name of select html field
* @ param int $addempty 1 = Add an empty value in list , 2 = Add an empty value in list only if there is more than 2 entries .
* @ return void
*/
2020-09-07 10:18:17 +02:00
public function formSelectShippingMethod ( $page , $selected = '' , $htmlname = 'shipping_method_id' , $addempty = 0 )
2017-10-07 13:09:31 +02:00
{
global $langs , $db ;
$langs -> load ( " deliveries " );
if ( $htmlname != " none " ) {
print '<form method="POST" action="' . $page . '">' ;
print '<input type="hidden" name="action" value="setshippingmethod">' ;
2019-12-01 10:20:11 +01:00
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
2017-10-07 13:09:31 +02:00
$this -> selectShippingMethod ( $selected , $htmlname , '' , $addempty );
print '<input type="submit" class="button valignmiddle" value="' . $langs -> trans ( " Modify " ) . '">' ;
print '</form>' ;
} else {
if ( $selected ) {
2019-11-08 15:51:54 +01:00
$code = $langs -> getLabelFromKey ( $db , $selected , 'c_shipment_mode' , 'rowid' , 'code' );
2017-10-07 13:09:31 +02:00
print $langs -> trans ( " SendingMethod " . strtoupper ( $code ));
} else {
print " " ;
}
}
}
2014-07-24 18:08:08 +02:00
2014-11-14 16:43:49 +01:00
/**
* Creates HTML last in cycle situation invoices selector
*
2015-06-06 14:21:18 +02:00
* @ param string $selected Preselected ID
* @ param int $socid Company ID
2014-11-14 16:43:49 +01:00
*
* @ return string HTML select
*/
2020-09-07 10:18:17 +02:00
public function selectSituationInvoices ( $selected = '' , $socid = 0 )
2014-11-14 16:43:49 +01:00
{
global $langs ;
$langs -> load ( 'bills' );
2015-05-07 12:20:20 +02:00
$opt = '<option value ="" selected></option>' ;
2019-03-19 13:14:44 +01:00
$sql = 'SELECT rowid, ref, situation_cycle_ref, situation_counter, situation_final, fk_soc' ;
2019-11-08 15:51:54 +01:00
$sql .= ' FROM ' . MAIN_DB_PREFIX . 'facture' ;
$sql .= ' WHERE entity IN (' . getEntity ( 'invoice' ) . ')' ;
2020-05-27 14:39:19 +02:00
$sql .= ' AND situation_counter >= 1' ;
2020-05-25 00:20:00 +02:00
$sql .= ' AND fk_soc = ' . ( int ) $socid ;
$sql .= ' AND type <> 2' ;
2019-11-08 15:51:54 +01:00
$sql .= ' ORDER by situation_cycle_ref, situation_counter desc' ;
2014-11-14 16:43:49 +01:00
$resql = $this -> db -> query ( $sql );
2020-05-25 00:20:00 +02:00
2014-11-14 16:43:49 +01:00
if ( $resql && $this -> db -> num_rows ( $resql ) > 0 ) {
// Last seen cycle
$ref = 0 ;
2019-11-08 15:51:54 +01:00
while ( $obj = $this -> db -> fetch_object ( $resql )) {
2020-05-25 00:20:00 +02:00
//Same cycle ?
2020-09-07 10:18:17 +02:00
if ( $obj -> situation_cycle_ref != $ref ) {
2020-05-25 00:20:00 +02:00
// Just seen this cycle
2020-09-07 10:18:17 +02:00
$ref = $obj -> situation_cycle_ref ;
2020-05-25 00:20:00 +02:00
//not final ?
2020-09-07 10:18:17 +02:00
if ( $obj -> situation_final != 1 ) {
2020-05-25 00:20:00 +02:00
//Not prov?
2020-09-07 10:18:17 +02:00
if ( substr ( $obj -> ref , 1 , 4 ) != 'PROV' ) {
if ( $selected == $obj -> rowid ) {
$opt .= '<option value="' . $obj -> rowid . '" selected>' . $obj -> ref . '</option>' ;
2020-05-25 00:20:00 +02:00
} else {
2020-09-07 10:18:17 +02:00
$opt .= '<option value="' . $obj -> rowid . '">' . $obj -> ref . '</option>' ;
2014-11-14 16:43:49 +01:00
}
}
}
}
}
2020-05-21 15:05:19 +02:00
} else {
2019-11-08 15:51:54 +01:00
dol_syslog ( " Error sql= " . $sql . " , error= " . $this -> error , LOG_ERR );
2014-11-14 16:43:49 +01:00
}
2021-02-23 22:03:23 +01:00
if ( $opt == '<option value ="" selected></option>' ) {
2019-11-08 15:51:54 +01:00
$opt = '<option value ="0" selected>' . $langs -> trans ( 'NoSituations' ) . '</option>' ;
2014-11-14 16:43:49 +01:00
}
return $opt ;
}
2017-10-07 13:09:31 +02:00
/**
* Creates HTML units selector ( code => label )
*
* @ param string $selected Preselected Unit ID
* @ param string $htmlname Select name
* @ param int $showempty Add a nempty line
2021-01-07 10:32:23 +01:00
* @ param string $unit_type Restrict to one given unit type
2017-10-07 13:09:31 +02:00
* @ return string HTML select
*/
2021-01-07 10:32:23 +01:00
public function selectUnits ( $selected = '' , $htmlname = 'units' , $showempty = 0 , $unit_type = '' )
2017-10-07 13:09:31 +02:00
{
global $langs ;
2015-02-26 14:15:33 +01:00
2017-10-07 13:09:31 +02:00
$langs -> load ( 'products' );
2015-02-26 14:15:33 +01:00
2019-11-08 15:51:54 +01:00
$return = '<select class="flat" id="' . $htmlname . '" name="' . $htmlname . '">' ;
2015-04-21 15:49:58 +02:00
2017-10-07 13:09:31 +02:00
$sql = 'SELECT rowid, label, code from ' . MAIN_DB_PREFIX . 'c_units' ;
2019-11-08 15:51:54 +01:00
$sql .= ' WHERE active > 0' ;
2021-01-07 10:32:23 +01:00
if ( ! empty ( $unit_type )) {
$sql .= " AND unit_type = ' " . $this -> db -> escape ( $unit_type ) . " ' " ;
2021-01-06 15:15:51 +01:00
}
2015-06-06 14:21:18 +02:00
2017-10-07 13:09:31 +02:00
$resql = $this -> db -> query ( $sql );
2021-02-23 22:03:23 +01:00
if ( $resql && $this -> db -> num_rows ( $resql ) > 0 ) {
if ( $showempty ) {
$return .= '<option value="none"></option>' ;
}
2015-02-26 14:15:33 +01:00
2021-02-23 22:03:23 +01:00
while ( $res = $this -> db -> fetch_object ( $resql )) {
2020-09-07 10:18:17 +02:00
$unitLabel = $res -> label ;
2021-02-23 22:03:23 +01:00
if ( ! empty ( $langs -> tab_translate [ 'unit' . $res -> code ])) { // check if Translation is available before
2020-09-07 10:18:17 +02:00
$unitLabel = $langs -> trans ( 'unit' . $res -> code ) != $res -> label ? $langs -> trans ( 'unit' . $res -> code ) : $res -> label ;
}
2018-10-30 14:27:14 +01:00
2021-02-23 22:03:23 +01:00
if ( $selected == $res -> rowid ) {
2020-09-07 10:18:17 +02:00
$return .= '<option value="' . $res -> rowid . '" selected>' . $unitLabel . '</option>' ;
2020-05-21 15:05:19 +02:00
} else {
2020-09-07 10:18:17 +02:00
$return .= '<option value="' . $res -> rowid . '">' . $unitLabel . '</option>' ;
2017-10-07 13:09:31 +02:00
}
}
2019-11-08 15:51:54 +01:00
$return .= '</select>' ;
2017-10-07 13:09:31 +02:00
}
return $return ;
}
2015-02-26 14:15:33 +01:00
2020-09-07 10:18:17 +02:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2017-10-07 13:09:31 +02:00
/**
* Return a HTML select list of bank accounts
*
* @ param string $selected Id account pre - selected
* @ param string $htmlname Name of select zone
2019-11-02 11:36:48 +01:00
* @ param int $status Status of searched accounts ( 0 = open , 1 = closed , 2 = both )
2021-03-22 13:31:06 +01:00
* @ param string $filtre To filter list . This parameter must not come from input of users
2017-10-07 13:09:31 +02:00
* @ param int $useempty 1 = Add an empty value in list , 2 = Add an empty value in list only if there is more than 2 entries .
* @ param string $moreattrib To add more attribute on select
* @ param int $showcurrency Show currency in label
2019-05-26 18:23:30 +02:00
* @ param string $morecss More CSS
2020-12-23 22:17:05 +01:00
* @ param int $nooutput 1 = Return string , do not send to output
2018-12-14 19:04:17 +01:00
* @ return int < 0 if error , Num of bank account found if OK ( 0 , 1 , 2 , ... )
2017-10-07 13:09:31 +02:00
*/
2020-12-23 22:17:05 +01:00
public function select_comptes ( $selected = '' , $htmlname = 'accountid' , $status = 0 , $filtre = '' , $useempty = 0 , $moreattrib = '' , $showcurrency = 0 , $morecss = '' , $nooutput = 0 )
2017-10-07 13:09:31 +02:00
{
2020-09-07 10:18:17 +02:00
// phpcs:enable
2017-10-07 13:09:31 +02:00
global $langs , $conf ;
2010-08-22 17:46:34 +02:00
2020-12-23 22:17:05 +01:00
$out = '' ;
2017-10-07 13:09:31 +02:00
$langs -> load ( " admin " );
2018-12-14 19:04:17 +01:00
$num = 0 ;
2010-08-22 17:46:34 +02:00
2017-10-07 13:09:31 +02:00
$sql = " SELECT rowid, label, bank, clos as status, currency_code " ;
2019-12-16 13:06:25 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " bank_account " ;
$sql .= " WHERE entity IN ( " . getEntity ( 'bank_account' ) . " ) " ;
2021-02-23 22:03:23 +01:00
if ( $status != 2 ) {
$sql .= " AND clos = " . ( int ) $status ;
}
if ( $filtre ) {
$sql .= " AND " . $filtre ;
}
2019-12-16 13:06:25 +01:00
$sql .= " ORDER BY label " ;
2014-07-06 20:49:34 +02:00
2017-10-07 13:09:31 +02:00
dol_syslog ( get_class ( $this ) . " ::select_comptes " , LOG_DEBUG );
$result = $this -> db -> query ( $sql );
2021-02-23 22:03:23 +01:00
if ( $result ) {
2017-10-07 13:09:31 +02:00
$num = $this -> db -> num_rows ( $result );
$i = 0 ;
2021-02-23 22:03:23 +01:00
if ( $num ) {
2020-12-23 22:17:05 +01:00
$out .= '<select id="select' . $htmlname . '" class="flat selectbankaccount' . ( $morecss ? ' ' . $morecss : '' ) . '" name="' . $htmlname . '"' . ( $moreattrib ? ' ' . $moreattrib : '' ) . '>' ;
2021-02-23 22:03:23 +01:00
if ( $useempty == 1 || ( $useempty == 2 && $num > 1 )) {
2020-12-23 22:17:05 +01:00
$out .= '<option value="-1"> </option>' ;
2017-10-07 13:09:31 +02:00
}
2021-02-23 22:03:23 +01:00
while ( $i < $num ) {
2017-10-07 13:09:31 +02:00
$obj = $this -> db -> fetch_object ( $result );
2021-01-19 12:25:05 +01:00
if ( $selected == $obj -> rowid || ( $useempty == 2 && $num == 1 && empty ( $selected ))) {
2021-03-23 16:26:31 +01:00
$out .= '<option value="' . $obj -> rowid . '" data-currency-code="' . $obj -> currency_code . '" selected>' ;
2020-05-21 15:05:19 +02:00
} else {
2021-03-23 16:26:31 +01:00
$out .= '<option value="' . $obj -> rowid . '" data-currency-code="' . $obj -> currency_code . '">' ;
2017-10-07 13:09:31 +02:00
}
2020-12-23 22:17:05 +01:00
$out .= trim ( $obj -> label );
2021-02-23 22:03:23 +01:00
if ( $showcurrency ) {
$out .= ' (' . $obj -> currency_code . ')' ;
}
if ( $status == 2 && $obj -> status == 1 ) {
$out .= ' (' . $langs -> trans ( " Closed " ) . ')' ;
}
2020-12-23 22:17:05 +01:00
$out .= '</option>' ;
2017-10-07 13:09:31 +02:00
$i ++ ;
}
2020-12-23 22:17:05 +01:00
$out .= " </select> " ;
$out .= ajax_combobox ( 'select' . $htmlname );
2020-05-21 15:05:19 +02:00
} else {
2021-02-23 22:03:23 +01:00
if ( $status == 0 ) {
$out .= '<span class="opacitymedium">' . $langs -> trans ( " NoActiveBankAccountDefined " ) . '</span>' ;
} else {
$out .= '<span class="opacitymedium">' . $langs -> trans ( " NoBankAccountFound " ) . '</span>' ;
}
2017-10-07 13:09:31 +02:00
}
2020-05-21 15:05:19 +02:00
} else {
2017-10-07 13:09:31 +02:00
dol_print_error ( $this -> db );
}
2018-12-14 19:04:17 +01:00
2020-12-23 22:17:05 +01:00
// Output or return
2021-02-23 22:03:23 +01:00
if ( empty ( $nooutput )) {
print $out ;
} else {
return $out ;
}
2020-12-23 22:17:05 +01:00
2018-12-14 19:04:17 +01:00
return $num ;
2017-10-07 13:09:31 +02:00
}
2019-02-26 18:42:05 +01:00
/**
* Return a HTML select list of establishment
*
* @ param string $selected Id establishment pre - selected
* @ param string $htmlname Name of select zone
2019-11-02 11:36:48 +01:00
* @ param int $status Status of searched establishment ( 0 = open , 1 = closed , 2 = both )
2021-03-22 13:31:06 +01:00
* @ param string $filtre To filter list . This parameter must not come from input of users
2019-02-26 18:42:05 +01:00
* @ param int $useempty 1 = Add an empty value in list , 2 = Add an empty value in list only if there is more than 2 entries .
* @ param string $moreattrib To add more attribute on select
* @ return int < 0 if error , Num of establishment found if OK ( 0 , 1 , 2 , ... )
*/
2019-11-02 11:36:48 +01:00
public function selectEstablishments ( $selected = '' , $htmlname = 'entity' , $status = 0 , $filtre = '' , $useempty = 0 , $moreattrib = '' )
2019-02-26 18:42:05 +01:00
{
2020-09-07 10:18:17 +02:00
// phpcs:enable
2019-02-26 18:42:05 +01:00
global $langs , $conf ;
$langs -> load ( " admin " );
$num = 0 ;
$sql = " SELECT rowid, name, fk_country, status, entity " ;
2019-12-16 13:06:25 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " establishment " ;
$sql .= " WHERE 1=1 " ;
2021-02-23 22:03:23 +01:00
if ( $status != 2 ) {
$sql .= " AND status = " . ( int ) $status ;
}
if ( $filtre ) {
$sql .= " AND " . $filtre ;
}
2019-12-16 13:06:25 +01:00
$sql .= " ORDER BY name " ;
2019-02-26 18:42:05 +01:00
dol_syslog ( get_class ( $this ) . " ::select_establishment " , LOG_DEBUG );
$result = $this -> db -> query ( $sql );
2021-02-23 22:03:23 +01:00
if ( $result ) {
2019-02-26 18:42:05 +01:00
$num = $this -> db -> num_rows ( $result );
$i = 0 ;
2021-02-23 22:03:23 +01:00
if ( $num ) {
2019-11-08 15:51:54 +01:00
print '<select id="select' . $htmlname . '" class="flat selectestablishment" name="' . $htmlname . '"' . ( $moreattrib ? ' ' . $moreattrib : '' ) . '>' ;
2021-02-23 22:03:23 +01:00
if ( $useempty == 1 || ( $useempty == 2 && $num > 1 )) {
2019-02-26 18:42:05 +01:00
print '<option value="-1"> </option>' ;
}
2021-02-23 22:03:23 +01:00
while ( $i < $num ) {
2019-02-26 18:42:05 +01:00
$obj = $this -> db -> fetch_object ( $result );
2021-02-23 22:03:23 +01:00
if ( $selected == $obj -> rowid ) {
2019-02-26 18:42:05 +01:00
print '<option value="' . $obj -> rowid . '" selected>' ;
2020-05-21 15:05:19 +02:00
} else {
2019-02-26 18:42:05 +01:00
print '<option value="' . $obj -> rowid . '">' ;
}
print trim ( $obj -> name );
2021-02-23 22:03:23 +01:00
if ( $status == 2 && $obj -> status == 1 ) {
print ' (' . $langs -> trans ( " Closed " ) . ')' ;
}
2019-02-26 18:42:05 +01:00
print '</option>' ;
$i ++ ;
}
print " </select> " ;
2020-05-21 15:05:19 +02:00
} else {
2021-02-23 22:03:23 +01:00
if ( $status == 0 ) {
print '<span class="opacitymedium">' . $langs -> trans ( " NoActiveEstablishmentDefined " ) . '</span>' ;
} else {
print '<span class="opacitymedium">' . $langs -> trans ( " NoEstablishmentFound " ) . '</span>' ;
}
2019-02-26 18:42:05 +01:00
}
2020-05-21 15:05:19 +02:00
} else {
2019-02-26 18:42:05 +01:00
dol_print_error ( $this -> db );
}
}
2017-10-07 13:09:31 +02:00
/**
* Display form to select bank account
*
* @ param string $page Page
* @ param int $selected Id of bank account
* @ param string $htmlname Name of select html field
* @ param int $addempty 1 = Add an empty value in list , 2 = Add an empty value in list only if there is more than 2 entries .
* @ return void
*/
2020-09-07 10:18:17 +02:00
public function formSelectAccount ( $page , $selected = '' , $htmlname = 'fk_account' , $addempty = 0 )
2017-10-07 13:09:31 +02:00
{
global $langs ;
if ( $htmlname != " none " ) {
print '<form method="POST" action="' . $page . '">' ;
print '<input type="hidden" name="action" value="setbankaccount">' ;
2019-12-01 10:20:11 +01:00
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
2021-02-16 17:05:38 +01:00
print img_picto ( '' , 'bank_account' , 'class="pictofixedwidth"' );
2018-12-14 19:04:17 +01:00
$nbaccountfound = $this -> select_comptes ( $selected , $htmlname , 0 , '' , $addempty );
2021-02-23 22:03:23 +01:00
if ( $nbaccountfound > 0 ) {
print '<input type="submit" class="button valignmiddle" value="' . $langs -> trans ( " Modify " ) . '">' ;
}
2017-10-07 13:09:31 +02:00
print '</form>' ;
} else {
$langs -> load ( 'banks' );
if ( $selected ) {
2019-11-08 15:51:54 +01:00
require_once DOL_DOCUMENT_ROOT . '/compta/bank/class/account.class.php' ;
$bankstatic = new Account ( $this -> db );
2018-04-20 08:47:53 +02:00
$result = $bankstatic -> fetch ( $selected );
2021-02-23 22:03:23 +01:00
if ( $result ) {
print $bankstatic -> getNomUrl ( 1 );
}
2017-10-07 13:09:31 +02:00
} else {
print " " ;
}
}
}
2020-09-07 10:18:17 +02:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2017-10-07 13:09:31 +02:00
/**
* Return list of categories having choosed type
*
2019-04-02 11:01:46 +02:00
* @ param string | int $type Type of category ( 'customer' , 'supplier' , 'contact' , 'product' , 'member' ) . Old mode ( 0 , 1 , 2 , ... ) is deprecated .
2020-05-26 00:19:32 +02:00
* @ param string $selected Id of category preselected or 'auto' ( autoselect category if there is only one element ) . Not used if $outputmode = 1.
2019-04-02 11:01:46 +02:00
* @ param string $htmlname HTML field name
* @ param int $maxlength Maximum length for labels
2020-09-07 10:18:17 +02:00
* @ param int | string | array $markafterid Keep only or removed all categories including the leaf $markafterid in category tree ( exclude ) or Keep only of category is inside the leaf starting with this id .
* $markafterid can be an :
* - int ( id of category )
* - string ( categories ids seprated by comma )
* - array ( list of categories ids )
2019-04-02 11:01:46 +02:00
* @ param int $outputmode 0 = HTML select string , 1 = Array
2020-09-07 10:18:17 +02:00
* @ param int $include [ = 0 ] Removed or 1 = Keep only
* @ param string $morecss More CSS
2017-10-07 13:09:31 +02:00
* @ return string
2019-03-15 01:28:54 +01:00
* @ see select_categories ()
2017-10-07 13:09:31 +02:00
*/
2020-09-07 10:18:17 +02:00
public function select_all_categories ( $type , $selected = '' , $htmlname = " parent " , $maxlength = 64 , $markafterid = 0 , $outputmode = 0 , $include = 0 , $morecss = '' )
2017-10-07 13:09:31 +02:00
{
2020-09-07 10:18:17 +02:00
// phpcs:enable
2017-10-07 13:09:31 +02:00
global $conf , $langs ;
$langs -> load ( " categories " );
2010-08-22 17:46:34 +02:00
2015-09-17 19:35:03 +02:00
include_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php' ;
2016-08-04 09:21:04 +02:00
2016-05-22 16:36:48 +02:00
// For backward compatibility
2021-02-23 22:03:23 +01:00
if ( is_numeric ( $type )) {
2019-11-08 15:51:54 +01:00
dol_syslog ( __METHOD__ . ': using numeric value for parameter type is deprecated. Use string code instead.' , LOG_WARNING );
2016-05-22 16:36:48 +02:00
}
2016-08-04 09:21:04 +02:00
2021-02-23 22:03:23 +01:00
if ( $type === Categorie :: TYPE_BANK_LINE ) {
2017-10-07 13:09:31 +02:00
// TODO Move this into common category feature
2019-11-28 14:16:54 +01:00
$cate_arbo = array ();
2017-10-07 13:09:31 +02:00
$sql = " SELECT c.label, c.rowid " ;
2019-11-08 15:51:54 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " bank_categ as c " ;
$sql .= " WHERE entity = " . $conf -> entity ;
$sql .= " ORDER BY c.label " ;
2017-10-07 13:09:31 +02:00
$result = $this -> db -> query ( $sql );
2021-02-23 22:03:23 +01:00
if ( $result ) {
2017-10-07 13:09:31 +02:00
$num = $this -> db -> num_rows ( $result );
$i = 0 ;
2021-02-23 22:03:23 +01:00
while ( $i < $num ) {
2017-10-07 13:09:31 +02:00
$objp = $this -> db -> fetch_object ( $result );
2021-02-23 22:03:23 +01:00
if ( $objp ) {
$cate_arbo [ $objp -> rowid ] = array ( 'id' => $objp -> rowid , 'fulllabel' => $objp -> label );
}
2017-10-07 13:09:31 +02:00
$i ++ ;
}
$this -> db -> free ( $result );
2021-02-23 22:03:23 +01:00
} else {
dol_print_error ( $this -> db );
}
2020-05-21 15:05:19 +02:00
} else {
2017-10-07 13:09:31 +02:00
$cat = new Categorie ( $this -> db );
2020-09-07 10:18:17 +02:00
$cate_arbo = $cat -> get_full_arbo ( $type , $markafterid , $include );
2017-04-07 16:44:43 +02:00
}
2017-05-25 08:48:59 +02:00
2019-12-04 16:43:56 +01:00
$output = '<select class="flat' . ( $morecss ? ' ' . $morecss : '' ) . '" name="' . $htmlname . '" id="' . $htmlname . '">' ;
2019-11-08 15:51:54 +01:00
$outarray = array ();
2021-02-23 22:03:23 +01:00
if ( is_array ( $cate_arbo )) {
if ( ! count ( $cate_arbo )) {
$output .= '<option value="-1" disabled>' . $langs -> trans ( " NoCategoriesDefined " ) . '</option>' ;
} else {
2019-11-08 15:51:54 +01:00
$output .= '<option value="-1"> </option>' ;
2021-02-23 22:03:23 +01:00
foreach ( $cate_arbo as $key => $value ) {
if ( $cate_arbo [ $key ][ 'id' ] == $selected || ( $selected === 'auto' && count ( $cate_arbo ) == 1 )) {
2017-10-07 13:09:31 +02:00
$add = 'selected ' ;
2020-05-21 15:05:19 +02:00
} else {
2017-10-07 13:09:31 +02:00
$add = '' ;
}
2019-11-08 15:51:54 +01:00
$output .= '<option ' . $add . 'value="' . $cate_arbo [ $key ][ 'id' ] . '">' . dol_trunc ( $cate_arbo [ $key ][ 'fulllabel' ], $maxlength , 'middle' ) . '</option>' ;
2015-04-21 15:49:58 +02:00
2015-04-18 03:07:49 +02:00
$outarray [ $cate_arbo [ $key ][ 'id' ]] = $cate_arbo [ $key ][ 'fulllabel' ];
2017-10-07 13:09:31 +02:00
}
}
}
2019-11-08 15:51:54 +01:00
$output .= '</select>' ;
$output .= " \n " ;
2015-04-18 03:07:49 +02:00
2021-02-23 22:03:23 +01:00
if ( $outputmode ) {
return $outarray ;
}
2015-04-18 03:07:49 +02:00
return $output ;
2017-10-07 13:09:31 +02:00
}
2010-09-02 21:31:18 +02:00
2020-09-07 10:18:17 +02:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2017-10-07 13:09:31 +02:00
/**
* Show a confirmation HTML form or AJAX popup
*
* @ param string $page Url of page to call if confirmation is OK
* @ param string $title Title
* @ param string $question Question
* @ param string $action Action
* @ param array $formquestion An array with forms complementary inputs
* @ param string $selectedchoice " " or " no " or " yes "
* @ param int $useajax 0 = No , 1 = Yes , 2 = Yes but submit page with & confirm = no if choice is No , 'xxx' = preoutput confirm box with div id = dialog - confirm - xxx
* @ param int $height Force height of box
* @ param int $width Force width of box
* @ return void
* @ deprecated
* @ see formconfirm ()
*/
2020-09-07 10:18:17 +02:00
public function form_confirm ( $page , $title , $question , $action , $formquestion = '' , $selectedchoice = " " , $useajax = 0 , $height = 170 , $width = 500 )
2017-10-07 13:09:31 +02:00
{
2020-09-07 10:18:17 +02:00
// phpcs:enable
dol_syslog ( __METHOD__ . ': using form_confirm is deprecated. Use formconfim instead.' , LOG_WARNING );
2017-10-07 13:09:31 +02:00
print $this -> formconfirm ( $page , $title , $question , $action , $formquestion , $selectedchoice , $useajax , $height , $width );
}
2016-03-25 15:31:28 +01:00
2017-10-07 13:09:31 +02:00
/**
* Show a confirmation HTML form or AJAX popup .
* Easiest way to use this is with useajax = 1.
* If you use useajax = 'xxx' , you must also add jquery code to trigger opening of box ( with correct parameters )
* just after calling this method . For example :
* print '<script type="text/javascript">' . " \n " ;
* print 'jQuery(document).ready(function() {' . " \n " ;
* print 'jQuery(".xxxlink").click(function(e) { jQuery("#aparamid").val(jQuery(this).attr("rel")); jQuery("#dialog-confirm-xxx").dialog("open"); return false; });' . " \n " ;
* print '});' . " \n " ;
* print '</script>' . " \n " ;
*
2020-06-03 00:46:09 +02:00
* @ param string $page Url of page to call if confirmation is OK . Can contains parameters ( param 'action' and 'confirm' will be reformated )
* @ param string $title Title
* @ param string $question Question
* @ param string $action Action
2020-12-06 15:59:19 +01:00
* @ param array | string $formquestion An array with complementary inputs to add into forms : array ( array ( 'label' => , 'type' => , 'size' => , 'morecss' => , 'moreattr' => ))
2021-02-09 17:52:33 +01:00
* type can be 'hidden' , 'text' , 'password' , 'checkbox' , 'radio' , 'date' , 'morecss' , 'other' or 'onecolumn' ...
2020-06-03 00:46:09 +02:00
* @ param string $selectedchoice '' or 'no' , or 'yes' or '1' or '0'
* @ param int | string $useajax 0 = No , 1 = Yes , 2 = Yes but submit page with & confirm = no if choice is No , 'xxx' = Yes and preoutput confirm box with div id = dialog - confirm - xxx
2020-09-23 16:36:19 +02:00
* @ param int | string $height Force height of box ( 0 = auto )
2020-06-03 00:46:09 +02:00
* @ param int $width Force width of box ( '999' or '90%' ) . Ignored and forced to 90 % on smartphones .
* @ param int $disableformtag 1 = Disable form tag . Can be used if we are already inside a < form > section .
* @ return string HTML ajax code if a confirm ajax popup is required , Pure HTML code if it ' s an html form
2017-10-07 13:09:31 +02:00
*/
2020-09-07 10:18:17 +02:00
public function formconfirm ( $page , $title , $question , $action , $formquestion = '' , $selectedchoice = '' , $useajax = 0 , $height = 0 , $width = 500 , $disableformtag = 0 )
2017-10-07 13:09:31 +02:00
{
2019-11-08 15:51:54 +01:00
global $langs , $conf ;
2014-01-05 18:30:35 +01:00
2021-06-19 23:52:52 +02:00
$more = '<!-- formconfirm before calling page=' . dol_escape_htmltag ( $page ) . ' -->' ;
2019-11-08 15:51:54 +01:00
$formconfirm = '' ;
$inputok = array ();
$inputko = array ();
2012-07-10 22:10:12 +02:00
2017-10-07 13:09:31 +02:00
// Clean parameters
2019-11-08 15:51:54 +01:00
$newselectedchoice = empty ( $selectedchoice ) ? " no " : $selectedchoice ;
2021-02-23 22:03:23 +01:00
if ( $conf -> browser -> layout == 'phone' ) {
$width = '95%' ;
}
2017-10-07 13:09:31 +02:00
2019-10-31 14:06:26 +01:00
// Set height automatically if not defined
if ( empty ( $height )) {
2020-09-24 08:55:33 +02:00
$height = 220 ;
2019-10-31 14:06:26 +01:00
if ( is_array ( $formquestion ) && count ( $formquestion ) > 2 ) {
$height += (( count ( $formquestion ) - 2 ) * 24 );
}
}
2021-02-23 22:03:23 +01:00
if ( is_array ( $formquestion ) && ! empty ( $formquestion )) {
2017-10-07 13:09:31 +02:00
// First add hidden fields and value
2021-02-23 22:03:23 +01:00
foreach ( $formquestion as $key => $input ) {
if ( is_array ( $input ) && ! empty ( $input )) {
if ( $input [ 'type' ] == 'hidden' ) {
2019-11-08 15:51:54 +01:00
$more .= '<input type="hidden" id="' . $input [ 'name' ] . '" name="' . $input [ 'name' ] . '" value="' . dol_escape_htmltag ( $input [ 'value' ]) . '">' . " \n " ;
2017-10-07 13:09:31 +02:00
}
}
}
// Now add questions
2020-01-07 20:36:36 +01:00
$moreonecolumn = '' ;
2019-11-08 15:51:54 +01:00
$more .= '<div class="tagtable paddingtopbottomonly centpercent noborderspacing">' . " \n " ;
2021-02-23 22:03:23 +01:00
foreach ( $formquestion as $key => $input ) {
if ( is_array ( $input ) && ! empty ( $input )) {
2019-11-08 15:51:54 +01:00
$size = ( ! empty ( $input [ 'size' ]) ? ' size="' . $input [ 'size' ] . '"' : '' );
$moreattr = ( ! empty ( $input [ 'moreattr' ]) ? ' ' . $input [ 'moreattr' ] : '' );
$morecss = ( ! empty ( $input [ 'morecss' ]) ? ' ' . $input [ 'morecss' ] : '' );
2017-10-07 13:09:31 +02:00
2021-02-16 11:43:26 +01:00
if ( $input [ 'type' ] == 'text' ) {
2019-11-08 15:51:54 +01:00
$more .= '<div class="tagtr"><div class="tagtd' . ( empty ( $input [ 'tdclass' ]) ? '' : ( ' ' . $input [ 'tdclass' ])) . '">' . $input [ 'label' ] . '</div><div class="tagtd"><input type="text" class="flat' . $morecss . '" id="' . $input [ 'name' ] . '" name="' . $input [ 'name' ] . '"' . $size . ' value="' . $input [ 'value' ] . '"' . $moreattr . ' /></div></div>' . " \n " ;
2021-02-16 11:43:26 +01:00
} elseif ( $input [ 'type' ] == 'password' ) {
2019-11-08 15:51:54 +01:00
$more .= '<div class="tagtr"><div class="tagtd' . ( empty ( $input [ 'tdclass' ]) ? '' : ( ' ' . $input [ 'tdclass' ])) . '">' . $input [ 'label' ] . '</div><div class="tagtd"><input type="password" class="flat' . $morecss . '" id="' . $input [ 'name' ] . '" name="' . $input [ 'name' ] . '"' . $size . ' value="' . $input [ 'value' ] . '"' . $moreattr . ' /></div></div>' . " \n " ;
2021-02-16 11:43:26 +01:00
} elseif ( $input [ 'type' ] == 'select' ) {
2021-02-14 20:12:43 +01:00
if ( empty ( $morecss )) {
$morecss = 'minwidth100' ;
}
2021-04-13 20:19:05 +02:00
2021-04-13 10:44:14 +02:00
$show_empty = isset ( $input [ 'select_show_empty' ]) ? $input [ 'select_show_empty' ] : 1 ;
$key_in_label = isset ( $input [ 'select_key_in_label' ]) ? $input [ 'select_key_in_label' ] : 0 ;
$value_as_key = isset ( $input [ 'select_value_as_key' ]) ? $input [ 'select_value_as_key' ] : 0 ;
$translate = isset ( $input [ 'select_translate' ]) ? $input [ 'select_translate' ] : 0 ;
$maxlen = isset ( $input [ 'select_maxlen' ]) ? $input [ 'select_maxlen' ] : 0 ;
$disabled = isset ( $input [ 'select_disabled' ]) ? $input [ 'select_disabled' ] : 0 ;
$sort = isset ( $input [ 'select_sort' ]) ? $input [ 'select_sort' ] : '' ;
2019-11-08 15:51:54 +01:00
$more .= '<div class="tagtr"><div class="tagtd' . ( empty ( $input [ 'tdclass' ]) ? '' : ( ' ' . $input [ 'tdclass' ])) . '">' ;
2021-02-23 22:03:23 +01:00
if ( ! empty ( $input [ 'label' ])) {
$more .= $input [ 'label' ] . '</div><div class="tagtd left">' ;
}
2021-04-13 10:44:14 +02:00
$more .= $this -> selectarray ( $input [ 'name' ], $input [ 'values' ], $input [ 'default' ], $show_empty , $key_in_label , $value_as_key , $moreattr , $translate , $maxlen , $disabled , $sort , $morecss );
2019-11-08 15:51:54 +01:00
$more .= '</div></div>' . " \n " ;
2021-02-16 11:43:26 +01:00
} elseif ( $input [ 'type' ] == 'checkbox' ) {
2019-11-08 15:51:54 +01:00
$more .= '<div class="tagtr">' ;
$more .= '<div class="tagtd' . ( empty ( $input [ 'tdclass' ]) ? '' : ( ' ' . $input [ 'tdclass' ])) . '">' . $input [ 'label' ] . ' </div><div class="tagtd">' ;
$more .= '<input type="checkbox" class="flat' . $morecss . '" id="' . $input [ 'name' ] . '" name="' . $input [ 'name' ] . '"' . $moreattr ;
2021-02-23 22:03:23 +01:00
if ( ! is_bool ( $input [ 'value' ]) && $input [ 'value' ] != 'false' && $input [ 'value' ] != '0' ) {
$more .= ' checked' ;
}
if ( is_bool ( $input [ 'value' ]) && $input [ 'value' ]) {
$more .= ' checked' ;
}
if ( isset ( $input [ 'disabled' ])) {
$more .= ' disabled' ;
}
2019-11-08 15:51:54 +01:00
$more .= ' /></div>' ;
$more .= '</div>' . " \n " ;
2021-02-16 11:43:26 +01:00
} elseif ( $input [ 'type' ] == 'radio' ) {
2019-11-08 15:51:54 +01:00
$i = 0 ;
2021-02-23 22:03:23 +01:00
foreach ( $input [ 'values' ] as $selkey => $selval ) {
2019-11-08 15:51:54 +01:00
$more .= '<div class="tagtr">' ;
2021-02-23 22:03:23 +01:00
if ( $i == 0 ) {
$more .= '<div class="tagtd' . ( empty ( $input [ 'tdclass' ]) ? ' tdtop' : ( ' tdtop ' . $input [ 'tdclass' ])) . '">' . $input [ 'label' ] . '</div>' ;
} else {
$more .= '<div clas="tagtd' . ( empty ( $input [ 'tdclass' ]) ? '' : ( ' "' . $input [ 'tdclass' ])) . '"> </div>' ;
}
2020-10-14 14:02:07 +02:00
$more .= '<div class="tagtd' . ( $i == 0 ? ' tdtop' : '' ) . '"><input type="radio" class="flat' . $morecss . '" id="' . $input [ 'name' ] . $selkey . '" name="' . $input [ 'name' ] . '" value="' . $selkey . '"' . $moreattr ;
2021-02-23 22:03:23 +01:00
if ( $input [ 'disabled' ]) {
$more .= ' disabled' ;
}
if ( isset ( $input [ 'default' ]) && $input [ 'default' ] === $selkey ) {
$more .= ' checked="checked"' ;
}
2019-11-08 15:51:54 +01:00
$more .= ' /> ' ;
2020-10-14 14:02:07 +02:00
$more .= '<label for="' . $input [ 'name' ] . $selkey . '">' . $selval . '</label>' ;
2019-11-08 15:51:54 +01:00
$more .= '</div></div>' . " \n " ;
2017-10-07 13:09:31 +02:00
$i ++ ;
}
2021-02-16 11:43:26 +01:00
} elseif ( $input [ 'type' ] == 'date' ) {
2019-11-08 15:51:54 +01:00
$more .= '<div class="tagtr"><div class="tagtd' . ( empty ( $input [ 'tdclass' ]) ? '' : ( ' ' . $input [ 'tdclass' ])) . '">' . $input [ 'label' ] . '</div>' ;
$more .= '<div class="tagtd">' ;
$more .= $this -> selectDate ( $input [ 'value' ], $input [ 'name' ], 0 , 0 , 0 , '' , 1 , 0 );
$more .= '</div></div>' . " \n " ;
2015-06-26 18:50:57 +02:00
$formquestion [] = array ( 'name' => $input [ 'name' ] . 'day' );
$formquestion [] = array ( 'name' => $input [ 'name' ] . 'month' );
$formquestion [] = array ( 'name' => $input [ 'name' ] . 'year' );
$formquestion [] = array ( 'name' => $input [ 'name' ] . 'hour' );
$formquestion [] = array ( 'name' => $input [ 'name' ] . 'min' );
2021-02-16 11:43:26 +01:00
} elseif ( $input [ 'type' ] == 'other' ) {
2019-11-08 15:51:54 +01:00
$more .= '<div class="tagtr"><div class="tagtd' . ( empty ( $input [ 'tdclass' ]) ? '' : ( ' ' . $input [ 'tdclass' ])) . '">' ;
2021-02-23 22:03:23 +01:00
if ( ! empty ( $input [ 'label' ])) {
$more .= $input [ 'label' ] . '</div><div class="tagtd">' ;
}
2019-11-08 15:51:54 +01:00
$more .= $input [ 'value' ];
$more .= '</div></div>' . " \n " ;
2021-02-16 11:43:26 +01:00
} elseif ( $input [ 'type' ] == 'onecolumn' ) {
2020-01-07 20:36:36 +01:00
$moreonecolumn .= '<div class="margintoponly">' ;
$moreonecolumn .= $input [ 'value' ];
$moreonecolumn .= '</div>' . " \n " ;
2021-02-16 11:43:26 +01:00
} elseif ( $input [ 'type' ] == 'hidden' ) {
// Do nothing more, already added by a previous loop
2021-02-09 17:52:33 +01:00
} else {
$more .= 'Error type ' . $input [ 'type' ] . ' for the confirm box is not a supported type' ;
2017-10-07 13:09:31 +02:00
}
}
}
2019-11-08 15:51:54 +01:00
$more .= '</div>' . " \n " ;
2020-01-07 20:36:36 +01:00
$more .= $moreonecolumn ;
2017-10-07 13:09:31 +02:00
}
2013-08-01 04:20:08 +02:00
2017-10-07 13:09:31 +02:00
// JQUI method dialog is broken with jmobile, we use standard HTML.
// Note: When using dol_use_jmobile or no js, you must also check code for button use a GET url with action=xxx and check that you also output the confirm code when action=xxx
// See page product/card.php for example
2021-02-23 22:03:23 +01:00
if ( ! empty ( $conf -> dol_use_jmobile )) {
$useajax = 0 ;
}
if ( empty ( $conf -> use_javascript_ajax )) {
$useajax = 0 ;
}
2017-10-07 13:09:31 +02:00
2021-02-23 22:03:23 +01:00
if ( $useajax ) {
2019-11-08 15:51:54 +01:00
$autoOpen = true ;
$dialogconfirm = 'dialog-confirm' ;
$button = '' ;
2021-02-23 22:03:23 +01:00
if ( ! is_numeric ( $useajax )) {
2019-11-08 15:51:54 +01:00
$button = $useajax ;
$useajax = 1 ;
$autoOpen = false ;
$dialogconfirm .= '-' . $button ;
2017-10-07 13:09:31 +02:00
}
2019-11-08 15:51:54 +01:00
$pageyes = $page . ( preg_match ( '/\?/' , $page ) ? '&' : '?' ) . 'action=' . $action . '&confirm=yes' ;
$pageno = ( $useajax == 2 ? $page . ( preg_match ( '/\?/' , $page ) ? '&' : '?' ) . 'confirm=no' : '' );
2021-02-09 17:52:33 +01:00
2017-10-07 13:09:31 +02:00
// Add input fields into list of fields to read during submit (inputok and inputko)
2021-02-09 17:52:33 +01:00
if ( is_array ( $formquestion )) {
foreach ( $formquestion as $key => $input ) {
2017-10-07 13:09:31 +02:00
//print "xx ".$key." rr ".is_array($input)."<br>\n";
2021-02-09 17:52:33 +01:00
// Add name of fields to propagate with the GET when submitting the form with button OK.
if ( is_array ( $input ) && isset ( $input [ 'name' ])) {
if ( strpos ( $input [ 'name' ], ',' ) > 0 ) {
$inputok = array_merge ( $inputok , explode ( ',' , $input [ 'name' ]));
} else {
array_push ( $inputok , $input [ 'name' ]);
}
}
// Add name of fields to propagate with the GET when submitting the form with button KO.
2021-02-23 22:03:23 +01:00
if ( isset ( $input [ 'inputko' ]) && $input [ 'inputko' ] == 1 ) {
array_push ( $inputko , $input [ 'name' ]);
}
2017-10-07 13:09:31 +02:00
}
}
2021-02-09 17:52:33 +01:00
2020-05-27 11:38:28 +02:00
// Show JQuery confirm box.
2019-11-08 15:51:54 +01:00
$formconfirm .= '<div id="' . $dialogconfirm . '" title="' . dol_escape_htmltag ( $title ) . '" style="display: none;">' ;
2020-06-03 00:46:09 +02:00
if ( is_array ( $formquestion ) && ! empty ( $formquestion [ 'text' ])) {
2019-12-23 11:10:55 +01:00
$formconfirm .= '<div class="confirmtext">' . $formquestion [ 'text' ] . '</div>' . " \n " ;
}
2019-11-08 15:51:54 +01:00
if ( ! empty ( $more )) {
2019-12-23 11:10:55 +01:00
$formconfirm .= '<div class="confirmquestions">' . $more . '</div>' . " \n " ;
2017-10-07 13:09:31 +02:00
}
2019-11-08 15:51:54 +01:00
$formconfirm .= ( $question ? '<div class="confirmmessage">' . img_help ( '' , '' ) . ' ' . $question . '</div>' : '' );
$formconfirm .= '</div>' . " \n " ;
2012-08-17 15:13:10 +02:00
2019-11-08 15:51:54 +01:00
$formconfirm .= " \n <!-- begin ajax formconfirm page= " . $page . " --> \n " ;
$formconfirm .= '<script type="text/javascript">' . " \n " ;
$formconfirm .= ' jQuery ( document ) . ready ( function () {
2012-08-17 15:13:10 +02:00
$ ( function () {
2015-06-20 20:35:57 +02:00
$ ( " #'. $dialogconfirm .' " ) . dialog (
{
2012-11-20 12:23:32 +01:00
autoOpen : '.($autoOpen ? "true" : "false").' , ' ;
2021-02-23 22:03:23 +01:00
if ( $newselectedchoice == 'no' ) {
2019-11-08 15:51:54 +01:00
$formconfirm .= '
2012-11-20 12:23:32 +01:00
open : function () {
2015-06-21 03:47:16 +02:00
$ ( this ) . parent () . find ( " button.ui-button:eq(2) " ) . focus ();
2012-11-20 12:23:32 +01:00
}, ' ;
2018-08-24 15:02:19 +02:00
}
2019-11-08 15:51:54 +01:00
$formconfirm .= '
2012-08-17 15:13:10 +02:00
resizable : false ,
height : " '. $height .' " ,
width : " '. $width .' " ,
modal : true ,
closeOnEscape : false ,
buttons : {
" '.dol_escape_js( $langs->transnoentities ( " Yes " )).' " : function () {
2019-12-01 10:20:11 +01:00
var options = " &token='.urlencode(newToken()).' " ;
2020-04-17 12:32:05 +02:00
var inputok = '.json_encode($inputok).' ; /* List of fields into form */
2019-11-08 15:51:54 +01:00
var pageyes = " '.dol_escape_js(!empty( $pageyes ) ? $pageyes : '').' " ;
2012-08-17 15:13:10 +02:00
if ( inputok . length > 0 ) {
$ . each ( inputok , function ( i , inputname ) {
var more = " " ;
2021-01-16 17:50:02 +01:00
var inputvalue ;
if ( $ ( " input[name= \ ' " + inputname + " \ '] " ) . attr ( " type " ) == " radio " ) {
2021-05-21 15:38:03 +02:00
inputvalue = $ ( " input[name= \ ' " + inputname + " \ ']:checked " ) . val ();
2021-01-16 17:50:02 +01:00
} else {
if ( $ ( " # " + inputname ) . attr ( " type " ) == " checkbox " ) { more = " :checked " ; }
inputvalue = $ ( " # " + inputname + more ) . val ();
}
2012-08-17 15:13:10 +02:00
if ( typeof inputvalue == " undefined " ) { inputvalue = " " ; }
2021-01-16 17:50:02 +01:00
console . log ( " check inputname= " + inputname + " inputvalue= " + inputvalue );
2018-06-13 14:51:20 +02:00
options += " & " + inputname + " = " + encodeURIComponent ( inputvalue );
2012-08-17 15:13:10 +02:00
});
}
var urljump = pageyes + ( pageyes . indexOf ( " ? " ) < 0 ? " ? " : " " ) + options ;
if ( pageyes . length > 0 ) { location . href = urljump ; }
$ ( this ) . dialog ( " close " );
},
" '.dol_escape_js( $langs->transnoentities ( " No " )).' " : function () {
2019-12-01 10:20:11 +01:00
var options = " &token='.urlencode(newToken()).' " ;
2020-04-17 12:32:05 +02:00
var inputko = '.json_encode($inputko).' ; /* List of fields into form */
2019-11-08 15:51:54 +01:00
var pageno = " '.dol_escape_js(!empty( $pageno ) ? $pageno : '').' " ;
2012-08-17 15:13:10 +02:00
if ( inputko . length > 0 ) {
$ . each ( inputko , function ( i , inputname ) {
var more = " " ;
if ( $ ( " # " + inputname ) . attr ( " type " ) == " checkbox " ) { more = " :checked " ; }
var inputvalue = $ ( " # " + inputname + more ) . val ();
if ( typeof inputvalue == " undefined " ) { inputvalue = " " ; }
2018-06-13 14:51:20 +02:00
options += " & " + inputname + " = " + encodeURIComponent ( inputvalue );
2012-08-17 15:13:10 +02:00
});
}
var urljump = pageno + ( pageno . indexOf ( " ? " ) < 0 ? " ? " : " " ) + options ;
//alert(urljump);
if ( pageno . length > 0 ) { location . href = urljump ; }
$ ( this ) . dialog ( " close " );
}
}
2015-06-20 20:35:57 +02:00
}
);
2012-08-17 15:13:10 +02:00
var button = " '. $button .' " ;
2013-08-01 04:20:08 +02:00
if ( button . length > 0 ) {
2012-08-17 15:13:10 +02:00
$ ( " # " + button ) . click ( function () {
$ ( " #'. $dialogconfirm .' " ) . dialog ( " open " );
2012-11-20 12:23:32 +01:00
});
2012-08-17 15:13:10 +02:00
}
});
2015-06-20 17:24:34 +02:00
});
2012-08-16 15:46:36 +02:00
</ script > ' ;
2019-11-08 15:51:54 +01:00
$formconfirm .= " <!-- end ajax formconfirm --> \n " ;
2020-05-21 15:05:19 +02:00
} else {
2020-11-17 18:39:34 +01:00
$formconfirm .= " \n <!-- begin formconfirm page= " . dol_escape_htmltag ( $page ) . " --> \n " ;
2016-11-06 15:01:40 +01:00
2021-02-23 22:03:23 +01:00
if ( empty ( $disableformtag )) {
$formconfirm .= '<form method="POST" action="' . $page . '" class="notoptoleftroright">' . " \n " ;
}
2010-08-22 17:46:34 +02:00
2019-11-08 15:51:54 +01:00
$formconfirm .= '<input type="hidden" name="action" value="' . $action . '">' . " \n " ;
2019-12-01 10:20:11 +01:00
$formconfirm .= '<input type="hidden" name="token" value="' . newToken () . '">' . " \n " ;
2010-08-22 17:46:34 +02:00
2019-11-08 15:51:54 +01:00
$formconfirm .= '<table class="valid centpercent">' . " \n " ;
2011-04-01 12:04:49 +02:00
2017-10-07 13:09:31 +02:00
// Line title
2021-05-19 14:13:42 +02:00
$formconfirm .= '<tr class="validtitre"><td class="validtitre" colspan="2">' ;
$formconfirm .= img_picto ( '' , 'recent' ) . ' ' . $title ;
$formconfirm .= '</td></tr>' . " \n " ;
2017-10-07 13:09:31 +02:00
2019-12-23 11:10:55 +01:00
// Line text
2020-06-03 00:46:09 +02:00
if ( is_array ( $formquestion ) && ! empty ( $formquestion [ 'text' ])) {
2021-05-19 14:04:01 +02:00
$formconfirm .= '<tr class="valid"><td class="valid" colspan="2">' . $formquestion [ 'text' ] . '</td></tr>' . " \n " ;
2019-12-23 11:10:55 +01:00
}
2011-05-07 13:47:38 +02:00
2017-10-07 13:09:31 +02:00
// Line form fields
2021-02-23 22:03:23 +01:00
if ( $more ) {
2021-05-19 14:04:01 +02:00
$formconfirm .= '<tr class="valid"><td class="valid" colspan="2">' . " \n " ;
2019-11-08 15:51:54 +01:00
$formconfirm .= $more ;
$formconfirm .= '</td></tr>' . " \n " ;
2017-10-07 13:09:31 +02:00
}
2015-04-25 22:20:10 +02:00
2017-10-07 13:09:31 +02:00
// Line with question
2019-11-08 15:51:54 +01:00
$formconfirm .= '<tr class="valid">' ;
$formconfirm .= '<td class="valid">' . $question . '</td>' ;
2021-05-19 14:04:01 +02:00
$formconfirm .= '<td class="valid center">' ;
2021-05-19 14:13:42 +02:00
$formconfirm .= $this -> selectyesno ( " confirm " , $newselectedchoice , 0 , false , 0 , 0 , 'marginleftonly marginrightonly' );
2021-05-19 14:04:01 +02:00
$formconfirm .= '<input class="button valignmiddle confirmvalidatebutton" type="submit" value="' . $langs -> trans ( " Validate " ) . '">' ;
2019-11-08 15:51:54 +01:00
$formconfirm .= '</td>' ;
$formconfirm .= '</tr>' . " \n " ;
2010-08-22 17:46:34 +02:00
2019-11-08 15:51:54 +01:00
$formconfirm .= '</table>' . " \n " ;
2010-08-22 17:46:34 +02:00
2021-02-23 22:03:23 +01:00
if ( empty ( $disableformtag )) {
$formconfirm .= " </form> \n " ;
}
2019-11-08 15:51:54 +01:00
$formconfirm .= '<br>' ;
2010-08-22 17:46:34 +02:00
2020-11-17 18:39:34 +01:00
if ( empty ( $conf -> use_javascript_ajax )) {
$formconfirm .= '<!-- code to disable button to avoid double clic -->' ;
$formconfirm .= '<script type="text/javascript">' . " \n " ;
$formconfirm .= '
$ ( document ) . ready ( function () {
$ ( " .confirmvalidatebutton " ) . on ( " click " , function () {
console . log ( " We click on button " );
$ ( this ) . attr ( " disabled " , " disabled " );
setTimeout ( \ ' $ ( " .confirmvalidatebutton " ) . removeAttr ( " disabled " ) \ ' , 3000 );
//console.log($(this).closest("form"));
$ ( this ) . closest ( " form " ) . submit ();
});
});
' ;
$formconfirm .= '</script>' . " \n " ;
}
2019-11-08 15:51:54 +01:00
$formconfirm .= " <!-- end formconfirm --> \n " ;
2017-10-07 13:09:31 +02:00
}
2010-08-22 17:46:34 +02:00
2017-10-07 13:09:31 +02:00
return $formconfirm ;
}
2016-08-04 09:21:04 +02:00
2020-09-07 10:18:17 +02:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2016-01-18 19:45:27 +01:00
/**
2017-10-07 13:09:31 +02:00
* Show a form to select a project
*
* @ param int $page Page
* @ param int $socid Id third party ( - 1 = all , 0 = only projects not linked to a third party , id = projects not linked or linked to third party id )
* @ param int $selected Id pre - selected project
* @ param string $htmlname Name of select field
* @ param int $discard_closed Discard closed projects ( 0 = Keep , 1 = hide completely except $selected , 2 = Disable )
* @ param int $maxlength Max length
* @ param int $forcefocus Force focus on field ( works with javascript only )
* @ param int $nooutput No print is done . String is returned .
* @ return string Return html content
*/
2020-09-07 10:18:17 +02:00
public function form_project ( $page , $socid , $selected = '' , $htmlname = 'projectid' , $discard_closed = 0 , $maxlength = 20 , $forcefocus = 0 , $nooutput = 0 )
2017-09-12 09:27:59 +02:00
{
2020-09-07 10:18:17 +02:00
// phpcs:enable
2017-10-07 13:09:31 +02:00
global $langs ;
2011-03-19 03:17:05 +01:00
2017-10-07 13:09:31 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/project.lib.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formprojet.class.php' ;
2010-10-22 10:11:51 +02:00
2019-11-08 15:51:54 +01:00
$out = '' ;
2010-08-22 17:46:34 +02:00
2019-11-08 15:51:54 +01:00
$formproject = new FormProjets ( $this -> db );
2010-08-22 17:46:34 +02:00
2017-10-07 13:09:31 +02:00
$langs -> load ( " project " );
2021-02-23 22:03:23 +01:00
if ( $htmlname != " none " ) {
2019-11-08 15:51:54 +01:00
$out .= " \n " ;
$out .= '<form method="post" action="' . $page . '">' ;
$out .= '<input type="hidden" name="action" value="classin">' ;
2019-12-01 10:20:11 +01:00
$out .= '<input type="hidden" name="token" value="' . newToken () . '">' ;
2019-11-08 15:51:54 +01:00
$out .= $formproject -> select_projects ( $socid , $selected , $htmlname , $maxlength , 0 , 1 , $discard_closed , $forcefocus , 0 , 0 , '' , 1 );
2020-11-30 20:13:42 +01:00
$out .= '<input type="submit" class="button smallpaddingimp" value="' . $langs -> trans ( " Modify " ) . '">' ;
2019-11-08 15:51:54 +01:00
$out .= '</form>' ;
2020-05-21 15:05:19 +02:00
} else {
2021-02-23 22:03:23 +01:00
if ( $selected ) {
2017-10-07 13:09:31 +02:00
$projet = new Project ( $this -> db );
$projet -> fetch ( $selected );
//print '<a href="'.DOL_URL_ROOT.'/projet/card.php?id='.$selected.'">'.$projet->title.'</a>';
2019-11-08 15:51:54 +01:00
$out .= $projet -> getNomUrl ( 0 , '' , 1 );
2020-05-21 15:05:19 +02:00
} else {
2019-11-08 15:51:54 +01:00
$out .= " " ;
2017-09-12 09:27:59 +02:00
}
}
2021-02-23 22:03:23 +01:00
if ( empty ( $nooutput )) {
2017-10-07 13:09:31 +02:00
print $out ;
return '' ;
}
2017-09-12 09:27:59 +02:00
return $out ;
}
2010-08-22 17:46:34 +02:00
2020-09-07 10:18:17 +02:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2016-01-18 19:45:27 +01:00
/**
2017-10-07 13:09:31 +02:00
* Show a form to select payment conditions
2016-08-04 09:21:04 +02:00
*
2017-10-07 13:09:31 +02:00
* @ param int $page Page
* @ param string $selected Id condition pre - selectionne
* @ param string $htmlname Name of select html field
* @ param int $addempty Add empty entry
* @ return void
*/
2020-09-07 10:18:17 +02:00
public function form_conditions_reglement ( $page , $selected = '' , $htmlname = 'cond_reglement_id' , $addempty = 0 )
2017-10-07 13:09:31 +02:00
{
2020-09-07 10:18:17 +02:00
// phpcs:enable
2017-10-07 13:09:31 +02:00
global $langs ;
2021-02-23 22:03:23 +01:00
if ( $htmlname != " none " ) {
2017-10-07 13:09:31 +02:00
print '<form method="post" action="' . $page . '">' ;
print '<input type="hidden" name="action" value="setconditions">' ;
2019-12-01 10:20:11 +01:00
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
2019-01-27 11:55:16 +01:00
$this -> select_conditions_paiements ( $selected , $htmlname , - 1 , $addempty );
2020-11-30 20:13:42 +01:00
print '<input type="submit" class="button valignmiddle smallpaddingimp" value="' . $langs -> trans ( " Modify " ) . '">' ;
2017-10-07 13:09:31 +02:00
print '</form>' ;
2020-05-21 15:05:19 +02:00
} else {
2021-02-23 22:03:23 +01:00
if ( $selected ) {
2017-10-07 13:09:31 +02:00
$this -> load_cache_conditions_paiements ();
print $this -> cache_conditions_paiements [ $selected ][ 'label' ];
} else {
print " " ;
}
2016-01-18 19:45:27 +01:00
}
2017-10-07 13:09:31 +02:00
}
2016-08-04 09:21:04 +02:00
2020-09-07 10:18:17 +02:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2017-10-07 13:09:31 +02:00
/**
* Show a form to select a delivery delay
*
* @ param int $page Page
* @ param string $selected Id condition pre - selectionne
* @ param string $htmlname Name of select html field
* @ param int $addempty Ajoute entree vide
* @ return void
*/
2020-09-07 10:18:17 +02:00
public function form_availability ( $page , $selected = '' , $htmlname = 'availability' , $addempty = 0 )
2017-10-07 13:09:31 +02:00
{
2020-09-07 10:18:17 +02:00
// phpcs:enable
2017-10-07 13:09:31 +02:00
global $langs ;
2021-02-23 22:03:23 +01:00
if ( $htmlname != " none " ) {
2017-10-07 13:09:31 +02:00
print '<form method="post" action="' . $page . '">' ;
print '<input type="hidden" name="action" value="setavailability">' ;
2019-12-01 10:20:11 +01:00
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
2019-01-27 11:55:16 +01:00
$this -> selectAvailabilityDelay ( $selected , $htmlname , - 1 , $addempty );
2020-11-30 20:13:42 +01:00
print '<input type="submit" class="button smallpaddingimp" value="' . $langs -> trans ( " Modify " ) . '">' ;
2017-10-07 13:09:31 +02:00
print '</form>' ;
2020-05-21 15:05:19 +02:00
} else {
2021-02-23 22:03:23 +01:00
if ( $selected ) {
2017-10-07 13:09:31 +02:00
$this -> load_cache_availability ();
print $this -> cache_availability [ $selected ][ 'label' ];
} else {
print " " ;
}
2016-01-18 19:45:27 +01:00
}
2017-10-07 13:09:31 +02:00
}
2016-08-04 09:21:04 +02:00
2017-10-07 13:09:31 +02:00
/**
2019-02-27 23:55:18 +01:00
* Output HTML form to select list of input reason ( events that triggered an object creation , like after sending an emailing , making an advert , ... )
2017-10-07 13:09:31 +02:00
* List found into table c_input_reason loaded by loadCacheInputReason
*
* @ param string $page Page
* @ param string $selected Id condition pre - selectionne
* @ param string $htmlname Name of select html field
2019-02-27 23:55:18 +01:00
* @ param int $addempty Add empty entry
2017-10-07 13:09:31 +02:00
* @ return void
2020-09-07 10:18:17 +02:00
*/
public function formInputReason ( $page , $selected = '' , $htmlname = 'demandreason' , $addempty = 0 )
{
2017-10-07 13:09:31 +02:00
global $langs ;
2021-02-23 22:03:23 +01:00
if ( $htmlname != " none " ) {
2017-10-07 13:09:31 +02:00
print '<form method="post" action="' . $page . '">' ;
print '<input type="hidden" name="action" value="setdemandreason">' ;
2019-12-01 10:20:11 +01:00
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
2019-01-27 11:55:16 +01:00
$this -> selectInputReason ( $selected , $htmlname , - 1 , $addempty );
2020-11-30 20:13:42 +01:00
print '<input type="submit" class="button smallpaddingimp" value="' . $langs -> trans ( " Modify " ) . '">' ;
2017-10-07 13:09:31 +02:00
print '</form>' ;
2020-05-21 15:05:19 +02:00
} else {
2021-02-23 22:03:23 +01:00
if ( $selected ) {
2017-10-07 13:09:31 +02:00
$this -> loadCacheInputReason ();
2021-02-23 22:03:23 +01:00
foreach ( $this -> cache_demand_reason as $key => $val ) {
if ( $val [ 'id' ] == $selected ) {
2017-10-07 13:09:31 +02:00
print $val [ 'label' ];
break ;
}
}
} else {
print " " ;
}
}
}
2020-09-07 10:18:17 +02:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2017-10-07 13:09:31 +02:00
/**
* Show a form + html select a date
*
* @ param string $page Page
* @ param string $selected Date preselected
* @ param string $htmlname Html name of date input fields or 'none'
* @ param int $displayhour Display hour selector
* @ param int $displaymin Display minutes selector
* @ param int $nooutput 1 = No print output , return string
* @ return string
2019-03-19 13:14:44 +01:00
* @ see selectDate ()
2017-10-07 13:09:31 +02:00
*/
2020-09-07 10:18:17 +02:00
public function form_date ( $page , $selected , $htmlname , $displayhour = 0 , $displaymin = 0 , $nooutput = 0 )
2017-10-07 13:09:31 +02:00
{
2020-09-07 10:18:17 +02:00
// phpcs:enable
2017-10-07 13:09:31 +02:00
global $langs ;
2019-11-08 15:51:54 +01:00
$ret = '' ;
2017-10-07 13:09:31 +02:00
2021-02-23 22:03:23 +01:00
if ( $htmlname != " none " ) {
2019-11-08 15:51:54 +01:00
$ret .= '<form method="post" action="' . $page . '" name="form' . $htmlname . '">' ;
$ret .= '<input type="hidden" name="action" value="set' . $htmlname . '">' ;
2019-12-01 10:20:11 +01:00
$ret .= '<input type="hidden" name="token" value="' . newToken () . '">' ;
2021-04-30 15:22:17 +02:00
$ret .= '<table class="nobordernopadding">' ;
2019-11-08 15:51:54 +01:00
$ret .= '<tr><td>' ;
$ret .= $this -> selectDate ( $selected , $htmlname , $displayhour , $displaymin , 1 , 'form' . $htmlname , 1 , 0 );
$ret .= '</td>' ;
2020-12-20 06:06:24 +01:00
$ret .= '<td class="left"><input type="submit" class="button smallpaddingimp" value="' . $langs -> trans ( " Modify " ) . '"></td>' ;
2019-11-08 15:51:54 +01:00
$ret .= '</tr></table></form>' ;
2020-05-21 15:05:19 +02:00
} else {
2021-02-23 22:03:23 +01:00
if ( $displayhour ) {
$ret .= dol_print_date ( $selected , 'dayhour' );
} else {
$ret .= dol_print_date ( $selected , 'day' );
}
2017-10-07 13:09:31 +02:00
}
2021-02-23 22:03:23 +01:00
if ( empty ( $nooutput )) {
print $ret ;
}
2017-10-07 13:09:31 +02:00
return $ret ;
}
2020-09-07 10:18:17 +02:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2017-10-07 13:09:31 +02:00
/**
* Show a select form to choose a user
*
* @ param string $page Page
* @ param string $selected Id of user preselected
* @ param string $htmlname Name of input html field . If 'none' , we just output the user link .
* @ param array $exclude List of users id to exclude
* @ param array $include List of users id to include
* @ return void
*/
2020-09-07 10:18:17 +02:00
public function form_users ( $page , $selected = '' , $htmlname = 'userid' , $exclude = '' , $include = '' )
2017-10-07 13:09:31 +02:00
{
2020-09-07 10:18:17 +02:00
// phpcs:enable
2017-10-07 13:09:31 +02:00
global $langs ;
2021-02-23 22:03:23 +01:00
if ( $htmlname != " none " ) {
2017-10-07 13:09:31 +02:00
print '<form method="POST" action="' . $page . '" name="form' . $htmlname . '">' ;
print '<input type="hidden" name="action" value="set' . $htmlname . '">' ;
2019-12-01 10:20:11 +01:00
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
2019-01-27 11:55:16 +01:00
print $this -> select_dolusers ( $selected , $htmlname , 1 , $exclude , 0 , $include );
2020-11-30 20:13:42 +01:00
print '<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs -> trans ( " Modify " ) . '">' ;
2017-10-07 13:09:31 +02:00
print '</form>' ;
2020-05-21 15:05:19 +02:00
} else {
2021-02-23 22:03:23 +01:00
if ( $selected ) {
2019-11-08 15:51:54 +01:00
require_once DOL_DOCUMENT_ROOT . '/user/class/user.class.php' ;
$theuser = new User ( $this -> db );
2017-10-07 13:09:31 +02:00
$theuser -> fetch ( $selected );
print $theuser -> getNomUrl ( 1 );
} else {
print " " ;
}
}
}
2020-09-07 10:18:17 +02:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2017-10-07 13:09:31 +02:00
/**
* Show form with payment mode
*
* @ param string $page Page
* @ param int $selected Id mode pre - selectionne
* @ param string $htmlname Name of select html field
* @ param string $filtertype To filter on field type in llx_c_paiement ( array ( 'code' => xx , 'label' => zz ))
* @ param int $active Active or not , - 1 = all
2018-12-28 23:06:04 +01:00
* @ param int $addempty 1 = Add empty entry
2017-10-07 13:09:31 +02:00
* @ return void
*/
2020-09-07 10:18:17 +02:00
public function form_modes_reglement ( $page , $selected = '' , $htmlname = 'mode_reglement_id' , $filtertype = '' , $active = 1 , $addempty = 0 )
2017-10-07 13:09:31 +02:00
{
2020-09-07 10:18:17 +02:00
// phpcs:enable
2017-10-07 13:09:31 +02:00
global $langs ;
2021-02-23 22:03:23 +01:00
if ( $htmlname != " none " ) {
2017-10-07 13:09:31 +02:00
print '<form method="POST" action="' . $page . '">' ;
print '<input type="hidden" name="action" value="setmode">' ;
2019-12-01 10:20:11 +01:00
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
2018-12-28 23:06:04 +01:00
$this -> select_types_paiements ( $selected , $htmlname , $filtertype , 0 , $addempty , 0 , 0 , $active );
2020-11-30 20:13:42 +01:00
print '<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs -> trans ( " Modify " ) . '">' ;
2017-10-07 13:09:31 +02:00
print '</form>' ;
2020-05-21 15:05:19 +02:00
} else {
2021-02-23 22:03:23 +01:00
if ( $selected ) {
2017-10-07 13:09:31 +02:00
$this -> load_cache_types_paiements ();
print $this -> cache_types_paiements [ $selected ][ 'label' ];
} else {
print " " ;
}
}
}
2020-10-31 14:32:18 +01:00
/**
* Show form with transport mode
*
* @ param string $page Page
* @ param int $selected Id mode pre - select
* @ param string $htmlname Name of select html field
* @ param int $active Active or not , - 1 = all
* @ param int $addempty 1 = Add empty entry
* @ return void
*/
public function formSelectTransportMode ( $page , $selected = '' , $htmlname = 'transport_mode_id' , $active = 1 , $addempty = 0 )
{
global $langs ;
2021-02-23 22:03:23 +01:00
if ( $htmlname != " none " ) {
2020-10-31 14:32:18 +01:00
print '<form method="POST" action="' . $page . '">' ;
2021-06-03 21:47:10 +02:00
print '<input type="hidden" name="action" value="settransportmode">' ;
2020-10-31 14:32:18 +01:00
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
2021-06-03 21:47:10 +02:00
$this -> selectTransportMode ( $selected , $htmlname , 0 , $addempty , 0 , 0 , $active );
2020-11-30 20:13:42 +01:00
print '<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs -> trans ( " Modify " ) . '">' ;
2020-10-31 14:32:18 +01:00
print '</form>' ;
2021-02-23 22:03:23 +01:00
} else {
if ( $selected ) {
2020-10-31 14:32:18 +01:00
$this -> load_cache_transport_mode ();
print $this -> cache_transport_mode [ $selected ][ 'label' ];
} else {
print " " ;
}
}
}
2019-07-22 06:56:55 +02:00
2020-10-31 14:32:18 +01:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2017-10-07 13:09:31 +02:00
/**
* Show form with multicurrency code
*
* @ param string $page Page
* @ param string $selected code pre - selectionne
* @ param string $htmlname Name of select html field
* @ return void
*/
2020-09-07 10:18:17 +02:00
public function form_multicurrency_code ( $page , $selected = '' , $htmlname = 'multicurrency_code' )
2017-10-07 13:09:31 +02:00
{
2020-09-07 10:18:17 +02:00
// phpcs:enable
2017-10-07 13:09:31 +02:00
global $langs ;
2021-02-23 22:03:23 +01:00
if ( $htmlname != " none " ) {
2017-10-07 13:09:31 +02:00
print '<form method="POST" action="' . $page . '">' ;
print '<input type="hidden" name="action" value="setmulticurrencycode">' ;
2019-12-01 10:20:11 +01:00
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
2017-10-07 13:09:31 +02:00
print $this -> selectMultiCurrency ( $selected , $htmlname , 0 );
2020-11-30 20:13:42 +01:00
print '<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs -> trans ( " Modify " ) . '">' ;
2017-10-07 13:09:31 +02:00
print '</form>' ;
2020-05-21 15:05:19 +02:00
} else {
2017-10-07 13:09:31 +02:00
dol_include_once ( '/core/lib/company.lib.php' );
2019-01-27 11:55:16 +01:00
print ! empty ( $selected ) ? currency_name ( $selected , 1 ) : ' ' ;
2017-10-07 13:09:31 +02:00
}
}
2020-09-07 10:18:17 +02:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2017-10-07 13:09:31 +02:00
/**
* Show form with multicurrency rate
*
* @ param string $page Page
* @ param double $rate Current rate
* @ param string $htmlname Name of select html field
* @ param string $currency Currency code to explain the rate
* @ return void
*/
2020-09-07 10:18:17 +02:00
public function form_multicurrency_rate ( $page , $rate = '' , $htmlname = 'multicurrency_tx' , $currency = '' )
2017-10-07 13:09:31 +02:00
{
2020-09-07 10:18:17 +02:00
// phpcs:enable
2017-10-07 13:09:31 +02:00
global $langs , $mysoc , $conf ;
2021-02-23 22:03:23 +01:00
if ( $htmlname != " none " ) {
2017-10-07 13:09:31 +02:00
print '<form method="POST" action="' . $page . '">' ;
print '<input type="hidden" name="action" value="setmulticurrencyrate">' ;
2019-12-01 10:20:11 +01:00
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
2021-01-11 13:36:53 +01:00
print '<input type="text" class="maxwidth100" name="' . $htmlname . '" value="' . ( ! empty ( $rate ) ? price ( price2num ( $rate , 'CU' )) : 1 ) . '" /> ' ;
2017-10-07 13:09:31 +02:00
print '<select name="calculation_mode">' ;
2021-03-02 01:17:28 +01:00
print '<option value="1">Change ' . $langs -> trans ( " PriceUHT " ) . ' of lines</option>' ;
print '<option value="2">Change ' . $langs -> trans ( " PriceUHTCurrency " ) . ' of lines</option>' ;
2017-10-07 13:09:31 +02:00
print '</select> ' ;
2020-11-30 20:13:42 +01:00
print '<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs -> trans ( " Modify " ) . '">' ;
2017-10-07 13:09:31 +02:00
print '</form>' ;
2020-05-21 15:05:19 +02:00
} else {
2021-02-23 22:03:23 +01:00
if ( ! empty ( $rate )) {
2017-10-07 13:09:31 +02:00
print price ( $rate , 1 , $langs , 1 , 0 );
2021-02-23 22:03:23 +01:00
if ( $currency && $rate != 1 ) {
print ' (' . price ( $rate , 1 , $langs , 1 , 0 ) . ' ' . $currency . ' = 1 ' . $conf -> currency . ')' ;
}
2020-05-21 15:05:19 +02:00
} else {
2017-10-07 13:09:31 +02:00
print 1 ;
}
}
}
2020-09-07 10:18:17 +02:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2017-10-07 13:09:31 +02:00
/**
* Show a select box with available absolute discounts
*
* @ param string $page Page URL where form is shown
* @ param int $selected Value pre - selected
* @ param string $htmlname Name of SELECT component . If 'none' , not changeable . Example 'remise_id' .
* @ param int $socid Third party id
* @ param float $amount Total amount available
* @ param string $filter SQL filter on discounts
* @ param int $maxvalue Max value for lines that can be selected
* @ param string $more More string to add
* @ param int $hidelist 1 = Hide list
2018-02-14 18:02:40 +01:00
* @ param int $discount_type 0 => customer discount , 1 => supplier discount
2017-10-07 13:09:31 +02:00
* @ return void
*/
2020-09-07 10:18:17 +02:00
public function form_remise_dispo ( $page , $selected , $htmlname , $socid , $amount , $filter = '' , $maxvalue = 0 , $more = '' , $hidelist = 0 , $discount_type = 0 )
2017-10-07 13:09:31 +02:00
{
2020-09-07 10:18:17 +02:00
// phpcs:enable
2019-11-08 15:51:54 +01:00
global $conf , $langs ;
2021-02-23 22:03:23 +01:00
if ( $htmlname != " none " ) {
2017-10-07 13:09:31 +02:00
print '<form method="post" action="' . $page . '">' ;
print '<input type="hidden" name="action" value="setabsolutediscount">' ;
2019-12-01 10:20:11 +01:00
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
2017-10-07 13:09:31 +02:00
print '<div class="inline-block">' ;
2019-11-08 15:51:54 +01:00
if ( ! empty ( $discount_type )) {
2021-02-23 22:03:23 +01:00
if ( ! empty ( $conf -> global -> FACTURE_DEPOSITS_ARE_JUST_PAYMENTS )) {
if ( ! $filter || $filter == " fk_invoice_supplier_source IS NULL " ) {
$translationKey = 'HasAbsoluteDiscountFromSupplier' ; // If we want deposit to be substracted to payments only and not to total of final invoice
} else {
$translationKey = 'HasCreditNoteFromSupplier' ;
}
2020-05-21 15:05:19 +02:00
} else {
2021-02-23 22:03:23 +01:00
if ( ! $filter || $filter == " fk_invoice_supplier_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS PAID)%') " ) {
$translationKey = 'HasAbsoluteDiscountFromSupplier' ;
} else {
$translationKey = 'HasCreditNoteFromSupplier' ;
}
2018-02-14 10:47:10 +01:00
}
} else {
2021-02-23 22:03:23 +01:00
if ( ! empty ( $conf -> global -> FACTURE_DEPOSITS_ARE_JUST_PAYMENTS )) {
if ( ! $filter || $filter == " fk_facture_source IS NULL " ) {
$translationKey = 'CompanyHasAbsoluteDiscount' ; // If we want deposit to be substracted to payments only and not to total of final invoice
} else {
$translationKey = 'CompanyHasCreditNote' ;
}
2020-05-21 15:05:19 +02:00
} else {
2021-02-23 22:03:23 +01:00
if ( ! $filter || $filter == " fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%') " ) {
$translationKey = 'CompanyHasAbsoluteDiscount' ;
} else {
$translationKey = 'CompanyHasCreditNote' ;
}
2018-02-14 10:47:10 +01:00
}
2017-10-07 13:09:31 +02:00
}
2019-01-27 11:55:16 +01:00
print $langs -> trans ( $translationKey , price ( $amount , 0 , $langs , 0 , 0 , - 1 , $conf -> currency ));
2021-02-23 22:03:23 +01:00
if ( empty ( $hidelist )) {
print ' ' ;
}
2017-10-07 13:09:31 +02:00
print '</div>' ;
2021-02-23 22:03:23 +01:00
if ( empty ( $hidelist )) {
2017-10-07 13:09:31 +02:00
print '<div class="inline-block" style="padding-right: 10px">' ;
2018-02-14 18:02:40 +01:00
$newfilter = 'discount_type=' . intval ( $discount_type );
2019-11-08 15:51:54 +01:00
if ( ! empty ( $discount_type )) {
$newfilter .= ' AND fk_invoice_supplier IS NULL AND fk_invoice_supplier_line IS NULL' ; // Supplier discounts available
2018-02-14 10:47:10 +01:00
} else {
2019-11-08 15:51:54 +01:00
$newfilter .= ' AND fk_facture IS NULL AND fk_facture_line IS NULL' ; // Customer discounts available
2018-02-14 10:47:10 +01:00
}
2021-02-23 22:03:23 +01:00
if ( $filter ) {
$newfilter .= ' AND (' . $filter . ')' ;
}
2019-11-08 15:51:54 +01:00
$nbqualifiedlines = $this -> select_remises ( $selected , $htmlname , $newfilter , $socid , $maxvalue );
2021-02-23 22:03:23 +01:00
if ( $nbqualifiedlines > 0 ) {
2020-11-30 18:28:04 +01:00
print ' <input type="submit" class="button smallpaddingimp" value="' . dol_escape_htmltag ( $langs -> trans ( " UseLine " )) . '"' ;
2021-02-23 22:03:23 +01:00
if ( ! empty ( $discount_type ) && $filter && $filter != " fk_invoice_supplier_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS PAID)%') " ) {
2018-02-14 10:47:10 +01:00
print ' title="' . $langs -> trans ( " UseCreditNoteInInvoicePayment " ) . '"' ;
2021-02-23 22:03:23 +01:00
}
if ( empty ( $discount_type ) && $filter && $filter != " fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%') " ) {
2018-02-14 10:47:10 +01:00
print ' title="' . $langs -> trans ( " UseCreditNoteInInvoicePayment " ) . '"' ;
2021-02-23 22:03:23 +01:00
}
2018-02-14 10:47:10 +01:00
2017-10-07 13:09:31 +02:00
print '>' ;
}
print '</div>' ;
}
2021-02-23 22:03:23 +01:00
if ( $more ) {
2017-10-07 13:09:31 +02:00
print '<div class="inline-block">' ;
print $more ;
print '</div>' ;
}
print '</form>' ;
2020-05-21 15:05:19 +02:00
} else {
2021-02-23 22:03:23 +01:00
if ( $selected ) {
2017-10-07 13:09:31 +02:00
print $selected ;
2020-05-21 15:05:19 +02:00
} else {
2017-10-07 13:09:31 +02:00
print " 0 " ;
}
}
}
2020-09-07 10:18:17 +02:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Show forms to select a contact
*
* @ param string $page Page
* @ param Societe $societe Filter on third party
* @ param int $selected Id contact pre - selectionne
* @ param string $htmlname Name of HTML select . If 'none' , we just show contact link .
* @ return void
*/
public function form_contacts ( $page , $societe , $selected = '' , $htmlname = 'contactid' )
{
// phpcs:enable
2017-10-07 13:09:31 +02:00
global $langs , $conf ;
2021-02-23 22:03:23 +01:00
if ( $htmlname != " none " ) {
2017-10-07 13:09:31 +02:00
print '<form method="post" action="' . $page . '">' ;
print '<input type="hidden" name="action" value="set_contact">' ;
2019-12-01 10:20:11 +01:00
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
2021-04-30 15:22:17 +02:00
print '<table class="nobordernopadding">' ;
2017-10-07 13:09:31 +02:00
print '<tr><td>' ;
2020-11-30 12:35:05 +01:00
print $this -> selectcontacts ( $societe -> id , $selected , $htmlname );
$num = $this -> num ;
2021-02-23 22:03:23 +01:00
if ( $num == 0 ) {
2019-11-08 15:51:54 +01:00
$addcontact = ( ! empty ( $conf -> global -> SOCIETE_ADDRESSES_MANAGEMENT ) ? $langs -> trans ( " AddContact " ) : $langs -> trans ( " AddContactAddress " ));
2017-10-07 13:09:31 +02:00
print '<a href="' . DOL_URL_ROOT . '/contact/card.php?socid=' . $societe -> id . '&action=create&backtoreferer=1">' . $addcontact . '</a>' ;
}
print '</td>' ;
2020-11-30 20:13:42 +01:00
print '<td class="left"><input type="submit" class="button smallpaddingimp" value="' . $langs -> trans ( " Modify " ) . '"></td>' ;
2017-10-07 13:09:31 +02:00
print '</tr></table></form>' ;
2020-05-21 15:05:19 +02:00
} else {
2021-02-23 22:03:23 +01:00
if ( $selected ) {
2019-11-08 15:51:54 +01:00
require_once DOL_DOCUMENT_ROOT . '/contact/class/contact.class.php' ;
$contact = new Contact ( $this -> db );
2017-10-07 13:09:31 +02:00
$contact -> fetch ( $selected );
print $contact -> getFullName ( $langs );
} else {
print " " ;
}
}
}
2020-09-07 10:18:17 +02:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2017-10-07 13:09:31 +02:00
/**
* Output html select to select thirdparty
*
* @ param string $page Page
* @ param string $selected Id preselected
* @ param string $htmlname Name of HTML select
2021-03-22 22:50:43 +01:00
* @ param string $filter Optional filters criteras . Do not use a filter coming from input of users .
2017-10-07 13:09:31 +02:00
* @ param int $showempty Add an empty field
* @ param int $showtype Show third party type in combolist ( customer , prospect or supplier )
* @ param int $forcecombo Force to use combo box
* @ param array $events Event options . Example : array ( array ( 'method' => 'getContacts' , 'url' => dol_buildpath ( '/core/ajax/contacts.php' , 1 ), 'htmlname' => 'contactid' , 'params' => array ( 'add-customer-contact' => 'disabled' )))
2018-10-01 03:19:21 +02:00
* @ param int $nooutput No print output . Return it only .
2021-03-22 22:50:43 +01:00
* @ param array $excludeids Exclude IDs from the select combo
2019-12-02 20:18:12 +01:00
* @ return void | string
2017-10-07 13:09:31 +02:00
*/
2021-03-22 22:50:43 +01:00
public function form_thirdparty ( $page , $selected = '' , $htmlname = 'socid' , $filter = '' , $showempty = 0 , $showtype = 0 , $forcecombo = 0 , $events = array (), $nooutput = 0 , $excludeids = array ())
2017-10-07 13:09:31 +02:00
{
2020-09-07 10:18:17 +02:00
// phpcs:enable
2017-10-07 13:09:31 +02:00
global $langs ;
2018-10-01 03:19:21 +02:00
$out = '' ;
2021-02-23 22:03:23 +01:00
if ( $htmlname != " none " ) {
2019-11-08 15:51:54 +01:00
$out .= '<form method="post" action="' . $page . '">' ;
$out .= '<input type="hidden" name="action" value="set_thirdparty">' ;
2019-12-01 10:20:11 +01:00
$out .= '<input type="hidden" name="token" value="' . newToken () . '">' ;
2021-03-22 22:50:43 +01:00
$out .= $this -> select_company ( $selected , $htmlname , $filter , $showempty , $showtype , $forcecombo , $events , 0 , 'minwidth100' , '' , '' , 1 , array (), false , $excludeids );
2020-11-30 20:13:42 +01:00
$out .= '<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs -> trans ( " Modify " ) . '">' ;
2019-11-08 15:51:54 +01:00
$out .= '</form>' ;
2020-05-21 15:05:19 +02:00
} else {
2021-02-23 22:03:23 +01:00
if ( $selected ) {
2019-11-08 15:51:54 +01:00
require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php' ;
2017-10-07 13:09:31 +02:00
$soc = new Societe ( $this -> db );
$soc -> fetch ( $selected );
2019-11-08 15:51:54 +01:00
$out .= $soc -> getNomUrl ( $langs );
2020-05-21 15:05:19 +02:00
} else {
2019-11-08 15:51:54 +01:00
$out .= " " ;
2017-10-07 13:09:31 +02:00
}
}
2018-10-01 03:19:21 +02:00
2021-02-23 22:03:23 +01:00
if ( $nooutput ) {
return $out ;
} else {
print $out ;
}
2017-10-07 13:09:31 +02:00
}
2020-09-07 10:18:17 +02:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2017-10-07 13:09:31 +02:00
/**
* Retourne la liste des devises , dans la langue de l ' utilisateur
*
* @ param string $selected preselected currency code
* @ param string $htmlname name of HTML select list
2020-09-07 10:18:17 +02:00
* @ deprecated
2017-10-07 13:09:31 +02:00
* @ return void
*/
2020-09-07 10:18:17 +02:00
public function select_currency ( $selected = '' , $htmlname = 'currency_id' )
2017-10-07 13:09:31 +02:00
{
2020-09-07 10:18:17 +02:00
// phpcs:enable
2019-01-27 11:55:16 +01:00
print $this -> selectCurrency ( $selected , $htmlname );
2017-10-07 13:09:31 +02:00
}
/**
* Retourne la liste des devises , dans la langue de l ' utilisateur
*
* @ param string $selected preselected currency code
* @ param string $htmlname name of HTML select list
2019-05-02 13:45:49 +02:00
* @ param string $mode 0 = Add currency symbol into label , 1 = Add 3 letter iso code
2017-10-07 13:09:31 +02:00
* @ return string
*/
2020-09-07 10:18:17 +02:00
public function selectCurrency ( $selected = '' , $htmlname = 'currency_id' , $mode = 0 )
2017-10-07 13:09:31 +02:00
{
2019-11-08 15:51:54 +01:00
global $conf , $langs , $user ;
2017-10-07 13:09:31 +02:00
$langs -> loadCacheCurrencies ( '' );
2019-11-08 15:51:54 +01:00
$out = '' ;
2017-10-07 13:09:31 +02:00
2021-02-23 22:03:23 +01:00
if ( $selected == 'euro' || $selected == 'euros' ) {
$selected = 'EUR' ; // Pour compatibilite
}
2017-10-07 13:09:31 +02:00
2019-11-08 15:51:54 +01:00
$out .= '<select class="flat maxwidth200onsmartphone minwidth300" name="' . $htmlname . '" id="' . $htmlname . '">' ;
2021-02-23 22:03:23 +01:00
foreach ( $langs -> cache_currencies as $code_iso => $currency ) {
2020-11-29 16:02:39 +01:00
$labeltoshow = $currency [ 'label' ];
2021-02-23 22:03:23 +01:00
if ( $mode == 1 ) {
2020-11-29 16:02:39 +01:00
$labeltoshow .= ' <span class="opacitymedium">(' . $code_iso . ')</span>' ;
2020-05-21 15:05:19 +02:00
} else {
2020-11-29 16:02:39 +01:00
$labeltoshow .= ' <span class="opacitymedium">(' . $langs -> getCurrencySymbol ( $code_iso ) . ')</span>' ;
2017-10-07 13:09:31 +02:00
}
2020-11-29 16:02:39 +01:00
2021-02-23 22:03:23 +01:00
if ( $selected && $selected == $code_iso ) {
2020-11-29 16:02:39 +01:00
$out .= '<option value="' . $code_iso . '" selected data-html="' . dol_escape_htmltag ( $labeltoshow ) . '">' ;
2020-05-21 15:05:19 +02:00
} else {
2020-11-29 16:02:39 +01:00
$out .= '<option value="' . $code_iso . '" data-html="' . dol_escape_htmltag ( $labeltoshow ) . '">' ;
2019-05-02 13:45:49 +02:00
}
2020-11-29 16:02:39 +01:00
$out .= $labeltoshow ;
2019-11-08 15:51:54 +01:00
$out .= '</option>' ;
2017-10-07 13:09:31 +02:00
}
2019-11-08 15:51:54 +01:00
$out .= '</select>' ;
2021-02-23 22:03:23 +01:00
if ( $user -> admin ) {
$out .= info_admin ( $langs -> trans ( " YouCanChangeValuesForThisListFromDictionarySetup " ), 1 );
}
2017-10-07 13:09:31 +02:00
// Make select dynamic
2019-11-08 15:51:54 +01:00
include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php' ;
2017-10-07 13:09:31 +02:00
$out .= ajax_combobox ( $htmlname );
return $out ;
}
/**
* Return array of currencies in user language
*
* @ param string $selected preselected currency code
* @ param string $htmlname name of HTML select list
* @ param integer $useempty 1 = Add empty line
2020-10-23 11:14:18 +02:00
* @ param string $filter Optional filters criteras ( example : 'code <> x' , ' in (1,3)' )
* @ param bool $excludeConfCurrency false = If company current currency not in table , we add it into list . Should always be available . true = we are in currency_rate update , we don ' t want to see conf -> currency in select
2017-10-07 13:09:31 +02:00
* @ return string
*/
2020-10-23 13:55:55 +02:00
public function selectMultiCurrency ( $selected = '' , $htmlname = 'multicurrency_code' , $useempty = 0 , $filter = '' , $excludeConfCurrency = false )
2017-10-07 13:09:31 +02:00
{
2019-11-08 15:51:54 +01:00
global $db , $conf , $langs , $user ;
2017-10-07 13:09:31 +02:00
2019-11-08 15:51:54 +01:00
$langs -> loadCacheCurrencies ( '' ); // Load ->cache_currencies
2017-10-07 13:09:31 +02:00
$TCurrency = array ();
$sql = 'SELECT code FROM ' . MAIN_DB_PREFIX . 'multicurrency' ;
2019-11-08 15:51:54 +01:00
$sql .= " WHERE entity IN (' " . getEntity ( 'mutlicurrency' ) . " ') " ;
2021-02-23 22:03:23 +01:00
if ( $filter ) {
$sql .= " AND " . $filter ;
}
2020-09-19 23:30:29 +02:00
$resql = $this -> db -> query ( $sql );
2021-02-23 22:03:23 +01:00
if ( $resql ) {
while ( $obj = $this -> db -> fetch_object ( $resql )) {
$TCurrency [ $obj -> code ] = $obj -> code ;
}
2017-10-07 13:09:31 +02:00
}
2019-11-08 15:51:54 +01:00
$out = '' ;
$out .= '<select class="flat" name="' . $htmlname . '" id="' . $htmlname . '">' ;
2021-02-23 22:03:23 +01:00
if ( $useempty ) {
$out .= '<option value=""> </option>' ;
}
2017-10-07 13:09:31 +02:00
// If company current currency not in table, we add it into list. Should always be available.
2021-02-23 22:03:23 +01:00
if ( ! in_array ( $conf -> currency , $TCurrency ) && ! $excludeConfCurrency ) {
2017-10-07 13:09:31 +02:00
$TCurrency [ $conf -> currency ] = $conf -> currency ;
}
2021-02-23 22:03:23 +01:00
if ( count ( $TCurrency ) > 0 ) {
foreach ( $langs -> cache_currencies as $code_iso => $currency ) {
if ( isset ( $TCurrency [ $code_iso ])) {
if ( ! empty ( $selected ) && $selected == $code_iso ) {
$out .= '<option value="' . $code_iso . '" selected="selected">' ;
} else {
$out .= '<option value="' . $code_iso . '">' ;
}
2017-10-07 13:09:31 +02:00
2019-11-08 15:51:54 +01:00
$out .= $currency [ 'label' ];
$out .= ' (' . $langs -> getCurrencySymbol ( $code_iso ) . ')' ;
$out .= '</option>' ;
2017-10-07 13:09:31 +02:00
}
}
}
2019-11-08 15:51:54 +01:00
$out .= '</select>' ;
2016-12-10 16:20:37 +01:00
// Make select dynamic
2019-11-08 15:51:54 +01:00
include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php' ;
$out .= ajax_combobox ( $htmlname );
2016-12-24 21:39:40 +01:00
2017-10-07 13:09:31 +02:00
return $out ;
}
2020-09-07 10:18:17 +02:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2017-10-07 13:09:31 +02:00
/**
2019-02-27 23:55:18 +01:00
* Load into the cache vat rates of a country
2017-10-07 13:09:31 +02:00
*
2019-02-27 23:55:18 +01:00
* @ param string $country_code Country code with quotes ( " 'CA' " , or " 'CA,IN,...' " )
* @ return int Nb of loaded lines , 0 if already loaded , < 0 if KO
2017-10-07 13:09:31 +02:00
*/
2020-09-07 10:18:17 +02:00
public function load_cache_vatrates ( $country_code )
2017-10-07 13:09:31 +02:00
{
2020-09-07 10:18:17 +02:00
// phpcs:enable
2017-10-07 13:09:31 +02:00
global $langs ;
$num = count ( $this -> cache_vatrates );
2021-02-23 22:03:23 +01:00
if ( $num > 0 ) {
return $num ; // Cache already loaded
}
2017-10-07 13:09:31 +02:00
dol_syslog ( __METHOD__ , LOG_DEBUG );
2019-11-08 15:51:54 +01:00
$sql = " SELECT DISTINCT t.rowid, t.code, t.taux, t.localtax1, t.localtax1_type, t.localtax2, t.localtax2_type, t.recuperableonly " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " c_tva as t, " . MAIN_DB_PREFIX . " c_country as c " ;
$sql .= " WHERE t.fk_pays = c.rowid " ;
$sql .= " AND t.active > 0 " ;
2021-03-23 12:22:30 +01:00
$sql .= " AND c.code IN ( " . $this -> db -> sanitize ( $country_code , 1 ) . " ) " ;
2019-11-08 15:51:54 +01:00
$sql .= " ORDER BY t.code ASC, t.taux ASC, t.recuperableonly ASC " ;
2017-10-07 13:09:31 +02:00
2019-11-08 15:51:54 +01:00
$resql = $this -> db -> query ( $sql );
2021-02-23 22:03:23 +01:00
if ( $resql ) {
2017-10-07 13:09:31 +02:00
$num = $this -> db -> num_rows ( $resql );
2021-02-23 22:03:23 +01:00
if ( $num ) {
for ( $i = 0 ; $i < $num ; $i ++ ) {
2017-10-07 13:09:31 +02:00
$obj = $this -> db -> fetch_object ( $resql );
$this -> cache_vatrates [ $i ][ 'rowid' ] = $obj -> rowid ;
2019-11-08 15:51:54 +01:00
$this -> cache_vatrates [ $i ][ 'code' ] = $obj -> code ;
2017-10-07 13:09:31 +02:00
$this -> cache_vatrates [ $i ][ 'txtva' ] = $obj -> taux ;
2019-11-08 15:51:54 +01:00
$this -> cache_vatrates [ $i ][ 'nprtva' ] = $obj -> recuperableonly ;
2017-10-07 13:09:31 +02:00
$this -> cache_vatrates [ $i ][ 'localtax1' ] = $obj -> localtax1 ;
$this -> cache_vatrates [ $i ][ 'localtax1_type' ] = $obj -> localtax1_type ;
$this -> cache_vatrates [ $i ][ 'localtax2' ] = $obj -> localtax2 ;
$this -> cache_vatrates [ $i ][ 'localtax2_type' ] = $obj -> localtax1_type ;
2019-11-08 15:51:54 +01:00
$this -> cache_vatrates [ $i ][ 'label' ] = $obj -> taux . '%' . ( $obj -> code ? ' (' . $obj -> code . ')' : '' ); // Label must contains only 0-9 , . % or *
$this -> cache_vatrates [ $i ][ 'labelallrates' ] = $obj -> taux . '/' . ( $obj -> localtax1 ? $obj -> localtax1 : '0' ) . '/' . ( $obj -> localtax2 ? $obj -> localtax2 : '0' ) . ( $obj -> code ? ' (' . $obj -> code . ')' : '' ); // Must never be used as key, only label
$positiverates = '' ;
2021-02-23 22:03:23 +01:00
if ( $obj -> taux ) {
$positiverates .= ( $positiverates ? '/' : '' ) . $obj -> taux ;
}
if ( $obj -> localtax1 ) {
$positiverates .= ( $positiverates ? '/' : '' ) . $obj -> localtax1 ;
}
if ( $obj -> localtax2 ) {
$positiverates .= ( $positiverates ? '/' : '' ) . $obj -> localtax2 ;
}
if ( empty ( $positiverates )) {
$positiverates = '0' ;
}
2019-11-08 15:51:54 +01:00
$this -> cache_vatrates [ $i ][ 'labelpositiverates' ] = $positiverates . ( $obj -> code ? ' (' . $obj -> code . ')' : '' ); // Must never be used as key, only label
2017-10-07 13:09:31 +02:00
}
return $num ;
2020-05-21 15:05:19 +02:00
} else {
2019-01-27 11:55:16 +01:00
$this -> error = '<font class="error">' . $langs -> trans ( " ErrorNoVATRateDefinedForSellerCountry " , $country_code ) . '</font>' ;
2017-10-07 13:09:31 +02:00
return - 1 ;
}
2020-05-21 15:05:19 +02:00
} else {
2017-10-07 13:09:31 +02:00
$this -> error = '<font class="error">' . $this -> db -> error () . '</font>' ;
return - 2 ;
}
}
2020-09-07 10:18:17 +02:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2017-10-07 13:09:31 +02:00
/**
* Output an HTML select vat rate .
* The name of this function should be selectVat . We keep bad name for compatibility purpose .
*
* @ param string $htmlname Name of HTML select field
* @ param float | string $selectedrate Force preselected vat rate . Can be '8.5' or '8.5 (NOO)' for example . Use '' for no forcing .
* @ param Societe $societe_vendeuse Thirdparty seller
* @ param Societe $societe_acheteuse Thirdparty buyer
* @ param int $idprod Id product . O if unknown of NA .
* @ param int $info_bits Miscellaneous information on line ( 1 for NPR )
* @ param int | string $type '' = Unknown , 0 = Product , 1 = Service ( Used if idprod not defined )
* Si vendeur non assujeti a TVA , TVA par defaut = 0. Fin de regle .
* Si le ( pays vendeur = pays acheteur ) alors la TVA par defaut = TVA du produit vendu . Fin de regle .
* Si ( vendeur et acheteur dans Communaute europeenne ) et bien vendu = moyen de transports neuf ( auto , bateau , avion ), TVA par defaut = 0 ( La TVA doit etre paye par l 'acheteur au centre d' impots de son pays et non au vendeur ) . Fin de regle .
* Si vendeur et acheteur dans Communauté européenne et acheteur = particulier alors TVA par défaut = TVA du produit vendu . Fin de règle .
* Si vendeur et acheteur dans Communauté européenne et acheteur = entreprise alors TVA par défaut = 0. Fin de règle .
* Sinon la TVA proposee par defaut = 0. Fin de regle .
* @ param bool $options_only Return HTML options lines only ( for ajax treatment )
* @ param int $mode 0 = Use vat rate as key in combo list , 1 = Add VAT code after vat rate into key , - 1 = Use id of vat line as key
* @ return string
*/
2020-09-07 10:18:17 +02:00
public function load_tva ( $htmlname = 'tauxtva' , $selectedrate = '' , $societe_vendeuse = '' , $societe_acheteuse = '' , $idprod = 0 , $info_bits = 0 , $type = '' , $options_only = false , $mode = 0 )
2017-10-07 13:09:31 +02:00
{
2020-09-07 10:18:17 +02:00
// phpcs:enable
2019-11-08 15:51:54 +01:00
global $langs , $conf , $mysoc ;
2017-10-07 13:09:31 +02:00
2017-10-16 22:56:16 +02:00
$langs -> load ( 'errors' );
2019-11-08 15:51:54 +01:00
$return = '' ;
2017-10-07 13:09:31 +02:00
// Define defaultnpr, defaultttx and defaultcode
2019-11-08 15:51:54 +01:00
$defaultnpr = ( $info_bits & 0x01 );
$defaultnpr = ( preg_match ( '/\*/' , $selectedrate ) ? 1 : $defaultnpr );
$defaulttx = str_replace ( '*' , '' , $selectedrate );
$defaultcode = '' ;
2021-03-23 12:22:30 +01:00
$reg = array ();
2021-02-23 22:03:23 +01:00
if ( preg_match ( '/\((.*)\)/' , $defaulttx , $reg )) {
2019-11-08 15:51:54 +01:00
$defaultcode = $reg [ 1 ];
$defaulttx = preg_replace ( '/\s*\(.*\)/' , '' , $defaulttx );
2017-10-07 13:09:31 +02:00
}
//var_dump($selectedrate.'-'.$defaulttx.'-'.$defaultnpr.'-'.$defaultcode);
// Check parameters
2021-02-23 22:03:23 +01:00
if ( is_object ( $societe_vendeuse ) && ! $societe_vendeuse -> country_code ) {
if ( $societe_vendeuse -> id == $mysoc -> id ) {
2020-01-22 14:10:46 +01:00
$return .= '<font class="error">' . $langs -> trans ( " ErrorYourCountryIsNotDefined " ) . '</font>' ;
2020-05-21 15:05:19 +02:00
} else {
2020-01-22 14:10:46 +01:00
$return .= '<font class="error">' . $langs -> trans ( " ErrorSupplierCountryIsNotDefined " ) . '</font>' ;
2017-10-07 13:09:31 +02:00
}
return $return ;
}
//var_dump($societe_acheteuse);
//print "name=$name, selectedrate=$selectedrate, seller=".$societe_vendeuse->country_code." buyer=".$societe_acheteuse->country_code." buyer is company=".$societe_acheteuse->isACompany()." idprod=$idprod, info_bits=$info_bits type=$type";
//exit;
// Define list of countries to use to search VAT rates to show
// First we defined code_country to use to find list
2021-02-23 22:03:23 +01:00
if ( is_object ( $societe_vendeuse )) {
2019-11-08 15:51:54 +01:00
$code_country = " ' " . $societe_vendeuse -> country_code . " ' " ;
2020-05-21 15:05:19 +02:00
} else {
2019-11-08 15:51:54 +01:00
$code_country = " ' " . $mysoc -> country_code . " ' " ; // Pour compatibilite ascendente
2017-10-07 13:09:31 +02:00
}
2021-02-23 22:03:23 +01:00
if ( ! empty ( $conf -> global -> SERVICE_ARE_ECOMMERCE_200238EC )) { // If option to have vat for end customer for services is on
2017-12-15 22:14:28 +01:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/company.lib.php' ;
2021-02-23 22:03:23 +01:00
if ( ! isInEEC ( $societe_vendeuse ) && ( ! is_object ( $societe_acheteuse ) || ( isInEEC ( $societe_acheteuse ) && ! $societe_acheteuse -> isACompany ()))) {
2017-10-07 13:09:31 +02:00
// We also add the buyer
2021-02-23 22:03:23 +01:00
if ( is_numeric ( $type )) {
if ( $type == 1 ) { // We know product is a service
2019-11-08 15:51:54 +01:00
$code_country .= " ,' " . $societe_acheteuse -> country_code . " ' " ;
2017-10-07 13:09:31 +02:00
}
2021-02-23 22:03:23 +01:00
} elseif ( ! $idprod ) { // We don't know type of product
2019-11-08 15:51:54 +01:00
$code_country .= " ,' " . $societe_acheteuse -> country_code . " ' " ;
2020-05-21 15:05:19 +02:00
} else {
2019-11-08 15:51:54 +01:00
$prodstatic = new Product ( $this -> db );
2017-10-07 13:09:31 +02:00
$prodstatic -> fetch ( $idprod );
2021-02-23 22:03:23 +01:00
if ( $prodstatic -> type == Product :: TYPE_SERVICE ) { // We know product is a service
2019-11-08 15:51:54 +01:00
$code_country .= " ,' " . $societe_acheteuse -> country_code . " ' " ;
2017-10-07 13:09:31 +02:00
}
}
}
}
// Now we get list
2019-11-08 15:51:54 +01:00
$num = $this -> load_cache_vatrates ( $code_country ); // If no vat defined, return -1 with message into this->error
2017-10-07 13:09:31 +02:00
2021-02-23 22:03:23 +01:00
if ( $num > 0 ) {
2017-10-07 13:09:31 +02:00
// Definition du taux a pre-selectionner (si defaulttx non force et donc vaut -1 ou '')
2021-02-23 22:03:23 +01:00
if ( $defaulttx < 0 || dol_strlen ( $defaulttx ) == 0 ) {
2019-11-08 15:51:54 +01:00
$tmpthirdparty = new Societe ( $this -> db );
$defaulttx = get_default_tva ( $societe_vendeuse , ( is_object ( $societe_acheteuse ) ? $societe_acheteuse : $tmpthirdparty ), $idprod );
$defaultnpr = get_default_npr ( $societe_vendeuse , ( is_object ( $societe_acheteuse ) ? $societe_acheteuse : $tmpthirdparty ), $idprod );
2020-09-07 10:18:17 +02:00
if ( preg_match ( '/\((.*)\)/' , $defaulttx , $reg )) {
$defaultcode = $reg [ 1 ];
$defaulttx = preg_replace ( '/\s*\(.*\)/' , '' , $defaulttx );
}
2021-02-23 22:03:23 +01:00
if ( empty ( $defaulttx )) {
$defaultnpr = 0 ;
}
2017-10-07 13:09:31 +02:00
}
// Si taux par defaut n'a pu etre determine, on prend dernier de la liste.
// Comme ils sont tries par ordre croissant, dernier = plus eleve = taux courant
2021-02-23 22:03:23 +01:00
if ( $defaulttx < 0 || dol_strlen ( $defaulttx ) == 0 ) {
if ( empty ( $conf -> global -> MAIN_VAT_DEFAULT_IF_AUTODETECT_FAILS )) {
$defaulttx = $this -> cache_vatrates [ $num - 1 ][ 'txtva' ];
} else {
$defaulttx = ( $conf -> global -> MAIN_VAT_DEFAULT_IF_AUTODETECT_FAILS == 'none' ? '' : $conf -> global -> MAIN_VAT_DEFAULT_IF_AUTODETECT_FAILS );
}
2017-10-07 13:09:31 +02:00
}
// Disabled if seller is not subject to VAT
2021-03-01 20:37:16 +01:00
$disabled = false ;
$title = '' ;
2021-02-23 22:03:23 +01:00
if ( is_object ( $societe_vendeuse ) && $societe_vendeuse -> id == $mysoc -> id && $societe_vendeuse -> tva_assuj == " 0 " ) {
2020-03-06 11:06:07 +01:00
// Override/enable VAT for expense report regardless of global setting - needed if expense report used for business expenses instead
// of using supplier invoices (this is a very bad idea !)
2021-02-23 22:03:23 +01:00
if ( empty ( $conf -> global -> EXPENSEREPORT_OVERRIDE_VAT )) {
2019-11-08 15:51:54 +01:00
$title = ' title="' . $langs -> trans ( 'VATIsNotUsed' ) . '"' ;
$disabled = true ;
2018-12-05 13:36:46 +01:00
}
2017-10-07 13:09:31 +02:00
}
2021-02-23 22:03:23 +01:00
if ( ! $options_only ) {
$return .= '<select class="flat minwidth75imp" id="' . $htmlname . '" name="' . $htmlname . '"' . ( $disabled ? ' disabled' : '' ) . $title . '>' ;
}
2017-10-07 13:09:31 +02:00
2019-11-08 15:51:54 +01:00
$selectedfound = false ;
2021-02-23 22:03:23 +01:00
foreach ( $this -> cache_vatrates as $rate ) {
2017-10-07 13:09:31 +02:00
// Keep only 0 if seller is not subject to VAT
2021-02-23 22:03:23 +01:00
if ( $disabled && $rate [ 'txtva' ] != 0 ) {
continue ;
}
2017-10-07 13:09:31 +02:00
// Define key to use into select list
$key = $rate [ 'txtva' ];
2019-11-08 15:51:54 +01:00
$key .= $rate [ 'nprtva' ] ? '*' : '' ;
2021-02-23 22:03:23 +01:00
if ( $mode > 0 && $rate [ 'code' ]) {
$key .= ' (' . $rate [ 'code' ] . ')' ;
}
if ( $mode < 0 ) {
$key = $rate [ 'rowid' ];
}
2017-10-07 13:09:31 +02:00
2019-11-08 15:51:54 +01:00
$return .= '<option value="' . $key . '"' ;
2021-02-23 22:03:23 +01:00
if ( ! $selectedfound ) {
if ( $defaultcode ) { // If defaultcode is defined, we used it in priority to select combo option instead of using rate+npr flag
if ( $defaultcode == $rate [ 'code' ]) {
2019-11-08 15:51:54 +01:00
$return .= ' selected' ;
$selectedfound = true ;
2017-10-07 13:09:31 +02:00
}
2021-02-23 22:03:23 +01:00
} elseif ( $rate [ 'txtva' ] == $defaulttx && $rate [ 'nprtva' ] == $defaultnpr ) {
$return .= ' selected' ;
$selectedfound = true ;
2017-10-07 13:09:31 +02:00
}
}
2019-11-08 15:51:54 +01:00
$return .= '>' ;
2017-10-07 13:09:31 +02:00
//if (! empty($conf->global->MAIN_VAT_SHOW_POSITIVE_RATES))
2021-02-23 22:03:23 +01:00
if ( $mysoc -> country_code == 'IN' || ! empty ( $conf -> global -> MAIN_VAT_LABEL_IS_POSITIVE_RATES )) {
2019-11-08 15:51:54 +01:00
$return .= $rate [ 'labelpositiverates' ];
2020-05-21 15:05:19 +02:00
} else {
2019-11-08 15:51:54 +01:00
$return .= vatrate ( $rate [ 'label' ]);
2017-10-07 13:09:31 +02:00
}
//$return.=($rate['code']?' '.$rate['code']:'');
2019-11-08 15:51:54 +01:00
$return .= ( empty ( $rate [ 'code' ]) && $rate [ 'nprtva' ]) ? ' *' : '' ; // We show the * (old behaviour only if new vat code is not used)
2017-10-07 13:09:31 +02:00
2019-11-08 15:51:54 +01:00
$return .= '</option>' ;
2017-10-07 13:09:31 +02:00
}
2016-08-04 09:21:04 +02:00
2021-02-23 22:03:23 +01:00
if ( ! $options_only ) {
$return .= '</select>' ;
}
2020-05-21 15:05:19 +02:00
} else {
2019-11-08 15:51:54 +01:00
$return .= $this -> error ;
2017-10-07 13:09:31 +02:00
}
$this -> num = $num ;
return $return ;
}
2020-09-07 10:18:17 +02:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Show a HTML widget to input a date or combo list for day , month , years and optionaly hours and minutes .
2017-10-07 13:09:31 +02:00
* Fields are preselected with :
* - set_time date ( must be a local PHP server timestamp or string date with format 'YYYY-MM-DD' or 'YYYY-MM-DD HH:MM' )
* - local date in user area , if set_time is '' ( so if set_time is '' , output may differs when done from two different location )
* - Empty ( fields empty ), if set_time is - 1 ( in this case , parameter empty must also have value 1 )
*
2019-04-24 11:25:14 +02:00
* @ param integer $set_time Pre - selected date ( must be a local PHP server timestamp ), - 1 to keep date not preselected , '' to use current date with 00 : 00 hour ( Parameter 'empty' must be 0 or 2 ) .
2017-10-07 13:09:31 +02:00
* @ param string $prefix Prefix for fields name
2018-04-26 10:07:27 +02:00
* @ param int $h 1 or 2 = Show also hours ( 2 = hours on a new line ), - 1 has same effect but hour and minutes are prefilled with 23 : 59 if date is empty , 3 show hour always empty
* @ param int $m 1 = Show also minutes , - 1 has same effect but hour and minutes are prefilled with 23 : 59 if date is empty , 3 show minutes always empty
2017-10-07 13:09:31 +02:00
* @ param int $empty 0 = Fields required , 1 = Empty inputs are allowed , 2 = Empty inputs are allowed for hours only
* @ param string $form_name Not used
* @ param int $d 1 = Show days , month , years
* @ param int $addnowlink Add a link " Now "
* @ param int $nooutput Do not output html string but return it
* @ param int $disabled Disable input fields
* @ param int $fullday When a checkbox with this html name is on , hour and day are set with 00 : 00 or 23 : 59
* @ param string $addplusone Add a link " +1 hour " . Value must be name of another select_date field .
* @ param datetime $adddateof Add a link " Date of invoice " using the following date .
2018-10-26 20:12:46 +02:00
* @ return string | void Nothing or string if nooutput is 1
2020-09-07 10:18:17 +02:00
* @ deprecated
2019-09-06 02:47:20 +02:00
* @ see selectDate (), form_date (), select_month (), select_year (), select_dayofweek ()
2017-10-07 13:09:31 +02:00
*/
2020-09-07 10:18:17 +02:00
public function select_date ( $set_time = '' , $prefix = 're' , $h = 0 , $m = 0 , $empty = 0 , $form_name = " " , $d = 1 , $addnowlink = 0 , $nooutput = 0 , $disabled = 0 , $fullday = '' , $addplusone = '' , $adddateof = '' )
{
// phpcs:enable
$retstring = $this -> selectDate ( $set_time , $prefix , $h , $m , $empty , $form_name , $d , $addnowlink , $disabled , $fullday , $addplusone , $adddateof );
if ( ! empty ( $nooutput )) {
return $retstring ;
}
print $retstring ;
return ;
}
2010-08-22 17:46:34 +02:00
2020-09-07 10:18:17 +02:00
/**
* Show 2 HTML widget to input a date or combo list for day , month , years and optionaly hours and minutes .
* Fields are preselected with :
* - set_time date ( must be a local PHP server timestamp or string date with format 'YYYY-MM-DD' or 'YYYY-MM-DD HH:MM' )
* - local date in user area , if set_time is '' ( so if set_time is '' , output may differs when done from two different location )
* - Empty ( fields empty ), if set_time is - 1 ( in this case , parameter empty must also have value 1 )
*
* @ param integer $set_time Pre - selected date ( must be a local PHP server timestamp ), - 1 to keep date not preselected , '' to use current date with 00 : 00 hour ( Parameter 'empty' must be 0 or 2 ) .
* @ param integer $set_time_end Pre - selected date ( must be a local PHP server timestamp ), - 1 to keep date not preselected , '' to use current date with 00 : 00 hour ( Parameter 'empty' must be 0 or 2 ) .
* @ param string $prefix Prefix for fields name
* @ param string $empty 0 = Fields required , 1 = Empty inputs are allowed , 2 = Empty inputs are allowed for hours only
* @ return string Html for selectDate
* @ see form_date (), select_month (), select_year (), select_dayofweek ()
*/
public function selectDateToDate ( $set_time = '' , $set_time_end = '' , $prefix = 're' , $empty = 0 )
{
2021-02-07 19:44:22 +01:00
global $langs ;
$ret = $this -> selectDate ( $set_time , $prefix . '_start' , 0 , 0 , $empty , '' , 1 , 0 , 0 , '' , '' , '' , '' , 1 , '' , $langs -> trans ( " from " ), 'tzuserrel' );
$ret .= '<br>' ;
$ret .= $this -> selectDate ( $set_time_end , $prefix . '_end' , 0 , 0 , $empty , '' , 1 , 0 , 0 , '' , '' , '' , '' , 1 , '' , $langs -> trans ( " to " ), 'tzuserrel' );
2020-09-07 10:18:17 +02:00
return $ret ;
}
2010-08-22 17:46:34 +02:00
2020-09-07 10:18:17 +02:00
/**
* Show a HTML widget to input a date or combo list for day , month , years and optionaly hours and minutes .
2018-09-08 12:00:11 +02:00
* Fields are preselected with :
* - set_time date ( must be a local PHP server timestamp or string date with format 'YYYY-MM-DD' or 'YYYY-MM-DD HH:MM' )
* - local date in user area , if set_time is '' ( so if set_time is '' , output may differs when done from two different location )
* - Empty ( fields empty ), if set_time is - 1 ( in this case , parameter empty must also have value 1 )
*
2019-03-19 13:14:44 +01:00
* @ param integer $set_time Pre - selected date ( must be a local PHP server timestamp ), - 1 to keep date not preselected , '' to use current date with 00 : 00 hour ( Parameter 'empty' must be 0 or 2 ) .
2018-09-08 12:00:11 +02:00
* @ param string $prefix Prefix for fields name
* @ param int $h 1 or 2 = Show also hours ( 2 = hours on a new line ), - 1 has same effect but hour and minutes are prefilled with 23 : 59 if date is empty , 3 show hour always empty
* @ param int $m 1 = Show also minutes , - 1 has same effect but hour and minutes are prefilled with 23 : 59 if date is empty , 3 show minutes always empty
* @ param int $empty 0 = Fields required , 1 = Empty inputs are allowed , 2 = Empty inputs are allowed for hours only
* @ param string $form_name Not used
* @ param int $d 1 = Show days , month , years
2019-10-16 14:32:17 +02:00
* @ param int $addnowlink Add a link " Now " , 1 with server time , 2 with local computer time
2018-09-08 12:00:11 +02:00
* @ param int $disabled Disable input fields
2020-08-17 15:27:05 +02:00
* @ param int $fullday When a checkbox with id #fullday is checked, hours are set with 00:00 (if value if 'fulldaystart') or 23:59 (if value is 'fulldayend')
2018-09-08 12:47:27 +02:00
* @ param string $addplusone Add a link " +1 hour " . Value must be name of another selectDate field .
2020-04-06 12:03:37 +02:00
* @ param datetime $adddateof Add a link " Date of ... " using the following date . See also $labeladddateof for the label used .
2020-09-07 10:18:17 +02:00
* @ param string $openinghours Specify hour start and hour end for the select ex 8 , 20
* @ param int $stepminutes Specify step for minutes between 1 and 30
* @ param string $labeladddateof Label to use for the $adddateof parameter .
2020-09-22 15:26:29 +02:00
* @ param string $placeholder Placeholder
2021-02-02 00:19:41 +01:00
* @ param mixed $gm 'auto' ( for backward compatibility , avoid this ), 'gmt' or 'tzserver' or 'tzuserrel'
2018-09-08 12:00:11 +02:00
* @ return string Html for selectDate
2019-03-19 13:14:44 +01:00
* @ see form_date (), select_month (), select_year (), select_dayofweek ()
2017-10-07 13:09:31 +02:00
*/
2021-01-03 18:42:45 +01:00
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' )
2017-10-07 13:09:31 +02:00
{
2019-11-08 15:51:54 +01:00
global $conf , $langs ;
2017-10-07 13:09:31 +02:00
2021-02-02 00:19:41 +01:00
if ( $gm === 'auto' ) {
$gm = ( empty ( $conf ) ? 'tzserver' : $conf -> tzuserinputkey );
2021-01-03 18:42:45 +01:00
}
2019-11-08 15:51:54 +01:00
$retstring = '' ;
2017-10-07 13:09:31 +02:00
2021-02-23 22:03:23 +01:00
if ( $prefix == '' ) {
$prefix = 're' ;
}
if ( $h == '' ) {
$h = 0 ;
}
if ( $m == '' ) {
$m = 0 ;
}
2019-11-08 15:51:54 +01:00
$emptydate = 0 ;
$emptyhours = 0 ;
2021-02-23 22:03:23 +01:00
if ( $stepminutes <= 0 || $stepminutes > 30 ) {
$stepminutes = 1 ;
}
if ( $empty == 1 ) {
2021-03-01 20:37:16 +01:00
$emptydate = 1 ;
$emptyhours = 1 ;
2021-02-23 22:03:23 +01:00
}
if ( $empty == 2 ) {
2021-03-01 20:37:16 +01:00
$emptydate = 0 ;
$emptyhours = 1 ;
2021-02-23 22:03:23 +01:00
}
2019-11-08 15:51:54 +01:00
$orig_set_time = $set_time ;
2017-10-07 13:09:31 +02:00
2021-02-23 22:03:23 +01:00
if ( $set_time === '' && $emptydate == 0 ) {
2017-10-07 13:09:31 +02:00
include_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php' ;
2021-01-03 18:42:45 +01:00
if ( $gm == 'tzuser' || $gm == 'tzuserrel' ) {
$set_time = dol_now ( $gm );
} else {
$set_time = dol_now ( 'tzuser' ) - ( getServerTimeZoneInt ( 'now' ) * 3600 ); // set_time must be relative to PHP server timezone
}
2017-10-07 13:09:31 +02:00
}
// Analysis of the pre-selection date
2020-10-07 00:26:03 +02:00
$reg = array ();
2021-02-23 22:03:23 +01:00
if ( preg_match ( '/^([0-9]+)\-([0-9]+)\-([0-9]+)\s?([0-9]+)?:?([0-9]+)?/' , $set_time , $reg )) { // deprecated usage
2017-10-07 13:09:31 +02:00
// Date format 'YYYY-MM-DD' or 'YYYY-MM-DD HH:MM:SS'
2019-11-08 15:51:54 +01:00
$syear = ( ! empty ( $reg [ 1 ]) ? $reg [ 1 ] : '' );
$smonth = ( ! empty ( $reg [ 2 ]) ? $reg [ 2 ] : '' );
$sday = ( ! empty ( $reg [ 3 ]) ? $reg [ 3 ] : '' );
$shour = ( ! empty ( $reg [ 4 ]) ? $reg [ 4 ] : '' );
$smin = ( ! empty ( $reg [ 5 ]) ? $reg [ 5 ] : '' );
2021-02-23 22:03:23 +01:00
} elseif ( strval ( $set_time ) != '' && $set_time != - 1 ) {
2017-10-07 13:09:31 +02:00
// set_time est un timestamps (0 possible)
2021-01-03 18:42:45 +01:00
$syear = dol_print_date ( $set_time , " %Y " , $gm );
$smonth = dol_print_date ( $set_time , " %m " , $gm );
$sday = dol_print_date ( $set_time , " %d " , $gm );
2021-02-23 22:03:23 +01:00
if ( $orig_set_time != '' ) {
2021-01-03 18:42:45 +01:00
$shour = dol_print_date ( $set_time , " %H " , $gm );
$smin = dol_print_date ( $set_time , " %M " , $gm );
$ssec = dol_print_date ( $set_time , " %S " , $gm );
2020-05-21 15:05:19 +02:00
} else {
2017-10-27 00:07:58 +02:00
$shour = '' ;
$smin = '' ;
$ssec = '' ;
}
2020-05-21 15:05:19 +02:00
} else {
2017-10-07 13:09:31 +02:00
// Date est '' ou vaut -1
$syear = '' ;
$smonth = '' ;
$sday = '' ;
2017-10-18 18:50:30 +02:00
$shour = ! isset ( $conf -> global -> MAIN_DEFAULT_DATE_HOUR ) ? ( $h == - 1 ? '23' : '' ) : $conf -> global -> MAIN_DEFAULT_DATE_HOUR ;
$smin = ! isset ( $conf -> global -> MAIN_DEFAULT_DATE_MIN ) ? ( $h == - 1 ? '59' : '' ) : $conf -> global -> MAIN_DEFAULT_DATE_MIN ;
$ssec = ! isset ( $conf -> global -> MAIN_DEFAULT_DATE_SEC ) ? ( $h == - 1 ? '59' : '' ) : $conf -> global -> MAIN_DEFAULT_DATE_SEC ;
2017-10-07 13:09:31 +02:00
}
2021-02-23 22:03:23 +01:00
if ( $h == 3 ) {
$shour = '' ;
}
if ( $m == 3 ) {
$smin = '' ;
}
2017-10-07 13:09:31 +02:00
2021-02-19 22:00:44 +01:00
$nowgmt = dol_now ( 'gmt' );
//var_dump(dol_print_date($nowgmt, 'dayhourinputnoreduce', 'tzuserrel'));
2017-10-07 13:09:31 +02:00
// You can set MAIN_POPUP_CALENDAR to 'eldy' or 'jquery'
2019-11-08 15:51:54 +01:00
$usecalendar = 'combo' ;
if ( ! empty ( $conf -> use_javascript_ajax ) && ( empty ( $conf -> global -> MAIN_POPUP_CALENDAR ) || $conf -> global -> MAIN_POPUP_CALENDAR != " none " )) {
$usecalendar = (( empty ( $conf -> global -> MAIN_POPUP_CALENDAR ) || $conf -> global -> MAIN_POPUP_CALENDAR == 'eldy' ) ? 'jquery' : $conf -> global -> MAIN_POPUP_CALENDAR );
2017-10-10 08:49:00 +02:00
}
2017-10-07 13:09:31 +02:00
2021-02-23 22:03:23 +01:00
if ( $d ) {
2017-10-07 13:09:31 +02:00
// Show date with popup
2021-02-23 22:03:23 +01:00
if ( $usecalendar != 'combo' ) {
2019-11-08 15:51:54 +01:00
$formated_date = '' ;
2017-10-07 13:09:31 +02:00
//print "e".$set_time." t ".$conf->format_date_short;
2021-02-23 22:03:23 +01:00
if ( strval ( $set_time ) != '' && $set_time != - 1 ) {
2017-10-07 13:09:31 +02:00
//$formated_date=dol_print_date($set_time,$conf->format_date_short);
2021-02-07 19:44:22 +01:00
$formated_date = dol_print_date ( $set_time , $langs -> trans ( " FormatDateShortInput " ), $gm ); // FormatDateShortInput for dol_print_date / FormatDateShortJavaInput that is same for javascript
2017-10-07 13:09:31 +02:00
}
// Calendrier popup version eldy
2021-02-23 22:03:23 +01:00
if ( $usecalendar == " eldy " ) {
2021-02-19 22:00:44 +01:00
// Input area to enter date manually
2020-06-28 19:35:24 +02:00
$retstring .= '<input id="' . $prefix . '" name="' . $prefix . '" type="text" class="maxwidthdate" maxlength="11" value="' . $formated_date . '"' ;
2019-11-08 15:51:54 +01:00
$retstring .= ( $disabled ? ' disabled' : '' );
$retstring .= ' onChange="dpChangeDay(\'' . $prefix . '\',\'' . $langs -> trans ( " FormatDateShortJavaInput " ) . '\'); "' ; // FormatDateShortInput for dol_print_date / FormatDateShortJavaInput that is same for javascript
$retstring .= '>' ;
2017-10-07 13:09:31 +02:00
2021-02-19 22:00:44 +01:00
// Icon calendar
2021-01-15 13:14:21 +01:00
$retstringbuttom = '' ;
if ( ! $disabled ) {
$retstringbuttom = '<button id="' . $prefix . 'Button" type="button" class="dpInvisibleButtons"' ;
2019-11-08 15:51:54 +01:00
$base = DOL_URL_ROOT . '/core/' ;
2021-01-15 13:14:21 +01:00
$retstringbuttom .= ' onClick="showDP(\'' . $base . '\',\'' . $prefix . '\',\'' . $langs -> trans ( " FormatDateShortJavaInput " ) . '\',\'' . $langs -> defaultlang . '\');"' ;
$retstringbuttom .= '>' . img_object ( $langs -> trans ( " SelectDate " ), 'calendarday' , 'class="datecallink"' ) . '</button>' ;
} else {
$retstringbuttom = '<button id="' . $prefix . 'Button" type="button" class="dpInvisibleButtons">' . img_object ( $langs -> trans ( " Disabled " ), 'calendarday' , 'class="datecallink"' ) . '</button>' ;
}
$retstring = $retstringbuttom . $retstring ;
2017-10-07 13:09:31 +02:00
2019-11-08 15:51:54 +01:00
$retstring .= '<input type="hidden" id="' . $prefix . 'day" name="' . $prefix . 'day" value="' . $sday . '">' . " \n " ;
$retstring .= '<input type="hidden" id="' . $prefix . 'month" name="' . $prefix . 'month" value="' . $smonth . '">' . " \n " ;
$retstring .= '<input type="hidden" id="' . $prefix . 'year" name="' . $prefix . 'year" value="' . $syear . '">' . " \n " ;
2021-02-23 22:03:23 +01:00
} elseif ( $usecalendar == 'jquery' ) {
if ( ! $disabled ) {
2017-12-01 12:01:17 +01:00
// Output javascript for datepicker
2019-11-08 15:51:54 +01:00
$retstring .= " <script type='text/javascript'> " ;
$retstring .= " $ (function() { $ ('# " . $prefix . " ').datepicker( {
2017-12-01 12:01:17 +01:00
dateFormat : '".$langs->trans("FormatDateShortJQueryInput")."' ,
2017-10-13 22:37:30 +02:00
autoclose : true ,
2017-12-01 12:01:17 +01:00
todayHighlight : true , " ;
2021-02-23 22:03:23 +01:00
if ( ! empty ( $conf -> dol_use_jmobile )) {
2019-11-08 15:51:54 +01:00
$retstring .= "
2017-12-01 12:01:17 +01:00
beforeShow : function ( input , datePicker ) {
input . disabled = true ;
},
onClose : function ( dateText , datePicker ) {
this . disabled = false ;
},
" ;
2019-10-27 11:18:36 +01:00
}
// Note: We don't need monthNames, monthNamesShort, dayNames, dayNamesShort, dayNamesMin, they are set globally on datepicker component in lib_head.js.php
2021-02-23 22:03:23 +01:00
if ( empty ( $conf -> global -> MAIN_POPUP_CALENDAR_ON_FOCUS )) {
2019-11-08 15:51:54 +01:00
$retstring .= "
2021-01-15 13:36:24 +01:00
showOn : 'button' , /* both has problem with autocompletion */
2017-12-01 12:01:17 +01:00
buttonImage : '".DOL_URL_ROOT."/theme/".$conf->theme."/img/object_calendarday.png' ,
buttonImageOnly : true " ;
2019-10-27 11:18:36 +01:00
}
2019-11-08 15:51:54 +01:00
$retstring .= "
2017-12-01 12:01:17 +01:00
}) }); " ;
2019-11-08 15:51:54 +01:00
$retstring .= " </script> " ;
2017-10-07 13:09:31 +02:00
}
// Zone de saisie manuelle de la date
2021-01-15 13:14:21 +01:00
$retstring .= '<div class="nowrap inline-block divfordateinput">' ;
2020-06-28 19:35:24 +02:00
$retstring .= '<input id="' . $prefix . '" name="' . $prefix . '" type="text" class="maxwidthdate" maxlength="11" value="' . $formated_date . '"' ;
2019-11-08 15:51:54 +01:00
$retstring .= ( $disabled ? ' disabled' : '' );
2021-01-17 15:59:04 +01:00
$retstring .= ( $placeholder ? ' placeholder="' . dol_escape_htmltag ( $placeholder ) . '"' : '' );
2019-11-08 15:51:54 +01:00
$retstring .= ' onChange="dpChangeDay(\'' . $prefix . '\',\'' . $langs -> trans ( " FormatDateShortJavaInput " ) . '\'); "' ; // FormatDateShortInput for dol_print_date / FormatDateShortJavaInput that is same for javascript
$retstring .= '>' ;
2017-10-07 13:09:31 +02:00
// Icone calendrier
2021-02-23 22:03:23 +01:00
if ( ! $disabled ) {
2017-10-07 13:09:31 +02:00
/* Not required . Managed by option buttonImage of jquery
2021-02-23 22:03:23 +01:00
$retstring .= img_object ( $langs -> trans ( " SelectDate " ), 'calendarday' , 'id="' . $prefix . 'id" class="datecallink"' );
$retstring .= " <script type='text/javascript'> " ;
$retstring .= " jQuery(document).ready(function() { " ;
$retstring .= ' jQuery("#' . $prefix . 'id").click(function() {' ;
$retstring .= " jQuery('# " . $prefix . " ').focus(); " ;
$retstring .= ' });' ;
$retstring .= '});' ;
$retstring .= " </script> " ; */
2020-05-21 15:05:19 +02:00
} else {
2021-01-15 13:14:21 +01:00
$retstringbutton = '<button id="' . $prefix . 'Button" type="button" class="dpInvisibleButtons">' . img_object ( $langs -> trans ( " Disabled " ), 'calendarday' , 'class="datecallink"' ) . '</button>' ;
$retsring = $retstringbutton . $retstring ;
2017-10-07 13:09:31 +02:00
}
2019-11-08 15:51:54 +01:00
$retstring .= '</div>' ;
$retstring .= '<input type="hidden" id="' . $prefix . 'day" name="' . $prefix . 'day" value="' . $sday . '">' . " \n " ;
$retstring .= '<input type="hidden" id="' . $prefix . 'month" name="' . $prefix . 'month" value="' . $smonth . '">' . " \n " ;
$retstring .= '<input type="hidden" id="' . $prefix . 'year" name="' . $prefix . 'year" value="' . $syear . '">' . " \n " ;
2020-05-21 15:05:19 +02:00
} else {
2019-11-08 15:51:54 +01:00
$retstring .= " Bad value of MAIN_POPUP_CALENDAR " ;
2017-10-07 13:09:31 +02:00
}
2021-03-01 20:37:16 +01:00
} else {
// Show date with combo selects
2017-10-07 13:09:31 +02:00
// Day
2019-11-08 15:51:54 +01:00
$retstring .= '<select' . ( $disabled ? ' disabled' : '' ) . ' class="flat valignmiddle maxwidth50imp" id="' . $prefix . 'day" name="' . $prefix . 'day">' ;
2017-10-07 13:09:31 +02:00
2021-02-23 22:03:23 +01:00
if ( $emptydate || $set_time == - 1 ) {
2019-11-08 15:51:54 +01:00
$retstring .= '<option value="0" selected> </option>' ;
2017-10-07 13:09:31 +02:00
}
2021-02-23 22:03:23 +01:00
for ( $day = 1 ; $day <= 31 ; $day ++ ) {
2019-11-08 15:51:54 +01:00
$retstring .= '<option value="' . $day . '"' . ( $day == $sday ? ' selected' : '' ) . '>' . $day . '</option>' ;
2017-10-07 13:09:31 +02:00
}
2019-11-08 15:51:54 +01:00
$retstring .= " </select> " ;
2017-10-07 13:09:31 +02:00
2019-11-08 15:51:54 +01:00
$retstring .= '<select' . ( $disabled ? ' disabled' : '' ) . ' class="flat valignmiddle maxwidth75imp" id="' . $prefix . 'month" name="' . $prefix . 'month">' ;
2021-02-23 22:03:23 +01:00
if ( $emptydate || $set_time == - 1 ) {
2019-11-08 15:51:54 +01:00
$retstring .= '<option value="0" selected> </option>' ;
2017-10-07 13:09:31 +02:00
}
// Month
2021-02-23 22:03:23 +01:00
for ( $month = 1 ; $month <= 12 ; $month ++ ) {
2019-11-08 15:51:54 +01:00
$retstring .= '<option value="' . $month . '"' . ( $month == $smonth ? ' selected' : '' ) . '>' ;
$retstring .= dol_print_date ( mktime ( 12 , 0 , 0 , $month , 1 , 2000 ), " %b " );
$retstring .= " </option> " ;
2017-10-07 13:09:31 +02:00
}
2019-11-08 15:51:54 +01:00
$retstring .= " </select> " ;
2017-10-07 13:09:31 +02:00
// Year
2021-02-23 22:03:23 +01:00
if ( $emptydate || $set_time == - 1 ) {
2019-11-08 15:51:54 +01:00
$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 . '">' ;
2020-05-21 15:05:19 +02:00
} else {
2019-11-08 15:51:54 +01:00
$retstring .= '<select' . ( $disabled ? ' disabled' : '' ) . ' class="flat valignmiddle maxwidth75imp" id="' . $prefix . 'year" name="' . $prefix . 'year">' ;
2017-10-07 13:09:31 +02:00
2021-02-23 22:03:23 +01:00
for ( $year = $syear - 10 ; $year < $syear + 10 ; $year ++ ) {
2019-11-08 15:51:54 +01:00
$retstring .= '<option value="' . $year . '"' . ( $year == $syear ? ' selected' : '' ) . '>' . $year . '</option>' ;
2017-10-07 13:09:31 +02:00
}
2019-11-08 15:51:54 +01:00
$retstring .= " </select> \n " ;
2017-10-07 13:09:31 +02:00
}
}
}
2020-10-13 10:05:47 +02:00
if ( $d && $h ) {
$retstring .= ( $h == 2 ? '<br>' : ' ' );
2020-10-31 14:32:18 +01:00
$retstring .= '<span class="nowraponall">' ;
2020-10-13 10:05:47 +02:00
}
2017-10-07 13:09:31 +02:00
2021-02-23 22:03:23 +01:00
if ( $h ) {
2019-06-17 14:03:57 +02:00
$hourstart = 0 ;
$hourend = 24 ;
if ( $openinghours != '' ) {
$openinghours = explode ( ',' , $openinghours );
$hourstart = $openinghours [ 0 ];
$hourend = $openinghours [ 1 ];
2021-02-23 22:03:23 +01:00
if ( $hourend < $hourstart ) {
$hourend = $hourstart ;
}
2019-06-17 14:03:57 +02:00
}
2017-10-07 13:09:31 +02:00
// Show hour
2019-11-08 15:51:54 +01:00
$retstring .= '<select' . ( $disabled ? ' disabled' : '' ) . ' class="flat valignmiddle maxwidth50 ' . ( $fullday ? $fullday . 'hour' : '' ) . '" id="' . $prefix . 'hour" name="' . $prefix . 'hour">' ;
2021-02-23 22:03:23 +01:00
if ( $emptyhours ) {
$retstring .= '<option value="-1"> </option>' ;
}
for ( $hour = $hourstart ; $hour < $hourend ; $hour ++ ) {
if ( strlen ( $hour ) < 2 ) {
$hour = " 0 " . $hour ;
}
2020-10-13 10:05:47 +02:00
$retstring .= '<option value="' . $hour . '"' . (( $hour == $shour ) ? ' selected' : '' ) . '>' . $hour ;
//$retstring .= (empty($conf->dol_optimize_smallscreen) ? '' : 'H');
$retstring .= '</option>' ;
2017-10-07 13:09:31 +02:00
}
2019-11-08 15:51:54 +01:00
$retstring .= '</select>' ;
2020-10-13 10:05:47 +02:00
//if ($m && empty($conf->dol_optimize_smallscreen)) $retstring .= ":";
2021-02-23 22:03:23 +01:00
if ( $m ) {
$retstring .= " : " ;
}
2017-10-07 13:09:31 +02:00
}
2021-02-23 22:03:23 +01:00
if ( $m ) {
2017-10-07 13:09:31 +02:00
// Show minutes
2019-11-08 15:51:54 +01:00
$retstring .= '<select' . ( $disabled ? ' disabled' : '' ) . ' class="flat valignmiddle maxwidth50 ' . ( $fullday ? $fullday . 'min' : '' ) . '" id="' . $prefix . 'min" name="' . $prefix . 'min">' ;
2021-02-23 22:03:23 +01:00
if ( $emptyhours ) {
$retstring .= '<option value="-1"> </option>' ;
}
for ( $min = 0 ; $min < 60 ; $min += $stepminutes ) {
if ( strlen ( $min ) < 2 ) {
$min = " 0 " . $min ;
}
2019-11-08 15:51:54 +01:00
$retstring .= '<option value="' . $min . '"' . (( $min == $smin ) ? ' selected' : '' ) . '>' . $min . ( empty ( $conf -> dol_optimize_smallscreen ) ? '' : '' ) . '</option>' ;
2017-10-07 13:09:31 +02:00
}
2019-11-08 15:51:54 +01:00
$retstring .= '</select>' ;
2017-10-17 10:44:18 +02:00
2019-11-08 15:51:54 +01:00
$retstring .= '<input type="hidden" name="' . $prefix . 'sec" value="' . $ssec . '">' ;
2017-10-07 13:09:31 +02:00
}
2016-08-04 09:21:04 +02:00
2020-10-13 10:05:47 +02:00
if ( $d && $h ) {
$retstring .= '</span>' ;
}
2017-10-07 13:09:31 +02:00
// Add a "Now" link
2021-02-23 22:03:23 +01:00
if ( $conf -> use_javascript_ajax && $addnowlink ) {
2017-10-07 13:09:31 +02:00
// Script which will be inserted in the onClick of the "Now" link
$reset_scripts = " " ;
2021-02-19 22:00:44 +01:00
if ( $addnowlink == 2 ) { // local computer time
2020-09-07 10:18:17 +02:00
// pad add leading 0 on numbers
$reset_scripts .= " Number.prototype.pad = function(size) {
2019-10-16 14:32:17 +02:00
var s = String ( this );
while ( s . length < ( size || 2 )) { s = '0' + s ;}
return s ;
};
var d = new Date (); " ;
2020-09-07 10:18:17 +02:00
}
2017-10-07 13:09:31 +02:00
// Generate the date part, depending on the use or not of the javascript calendar
2021-02-19 22:00:44 +01:00
if ( $addnowlink == 1 ) { // server time expressed in user time setup
$reset_scripts .= 'jQuery(\'#' . $prefix . '\').val(\'' . dol_print_date ( $nowgmt , 'day' , 'tzuserrel' ) . '\');' ;
$reset_scripts .= 'jQuery(\'#' . $prefix . 'day\').val(\'' . dol_print_date ( $nowgmt , '%d' , 'tzuserrel' ) . '\');' ;
$reset_scripts .= 'jQuery(\'#' . $prefix . 'month\').val(\'' . dol_print_date ( $nowgmt , '%m' , 'tzuserrel' ) . '\');' ;
$reset_scripts .= 'jQuery(\'#' . $prefix . 'year\').val(\'' . dol_print_date ( $nowgmt , '%Y' , 'tzuserrel' ) . '\');' ;
} elseif ( $addnowlink == 2 ) {
2020-09-07 10:18:17 +02:00
/* Disabled because the output does not use the string format defined by FormatDateShort key to forge the value into #prefix.
2021-02-23 22:03:23 +01:00
* This break application for foreign languages .
$reset_scripts .= 'jQuery(\'#' . $prefix . '\').val(d.toLocaleDateString(\'' . str_replace ( '_' , '-' , $langs -> defaultlang ) . '\'));' ;
$reset_scripts .= 'jQuery(\'#' . $prefix . 'day\').val(d.getDate().pad());' ;
$reset_scripts .= 'jQuery(\'#' . $prefix . 'month\').val(parseInt(d.getMonth().pad()) + 1);' ;
$reset_scripts .= 'jQuery(\'#' . $prefix . 'year\').val(d.getFullYear());' ;
*/
2021-02-19 22:00:44 +01:00
$reset_scripts .= 'jQuery(\'#' . $prefix . '\').val(\'' . dol_print_date ( $nowgmt , 'day' , 'tzuserrel' ) . '\');' ;
$reset_scripts .= 'jQuery(\'#' . $prefix . 'day\').val(\'' . dol_print_date ( $nowgmt , '%d' , 'tzuserrel' ) . '\');' ;
$reset_scripts .= 'jQuery(\'#' . $prefix . 'month\').val(\'' . dol_print_date ( $nowgmt , '%m' , 'tzuserrel' ) . '\');' ;
$reset_scripts .= 'jQuery(\'#' . $prefix . 'year\').val(\'' . dol_print_date ( $nowgmt , '%Y' , 'tzuserrel' ) . '\');' ;
2020-09-07 10:18:17 +02:00
}
2017-10-07 13:09:31 +02:00
/* if ( $usecalendar == " eldy " )
{
2021-02-23 22:03:23 +01:00
$base = DOL_URL_ROOT . '/core/' ;
$reset_scripts .= 'resetDP(\'' . $base . '\',\'' . $prefix . '\',\'' . $langs -> trans ( " FormatDateShortJavaInput " ) . '\',\'' . $langs -> defaultlang . '\');' ;
}
else
{
$reset_scripts .= 'this.form.elements[\'' . $prefix . 'day\'].value=formatDate(new Date(), \'d\'); ' ;
$reset_scripts .= 'this.form.elements[\'' . $prefix . 'month\'].value=formatDate(new Date(), \'M\'); ' ;
$reset_scripts .= 'this.form.elements[\'' . $prefix . 'year\'].value=formatDate(new Date(), \'yyyy\'); ' ;
} */
// Update the hour part
if ( $h ) {
if ( $fullday ) {
$reset_scripts .= " if (jQuery('#fullday:checked').val() == null) { " ;
}
2017-10-07 13:09:31 +02:00
//$reset_scripts .= 'this.form.elements[\''.$prefix.'hour\'].value=formatDate(new Date(), \'HH\'); ';
2021-02-23 22:03:23 +01:00
if ( $addnowlink == 1 ) {
2021-02-19 22:00:44 +01:00
$reset_scripts .= 'jQuery(\'#' . $prefix . 'hour\').val(\'' . dol_print_date ( $nowgmt , '%H' , 'tzuserrel' ) . '\');' ;
2020-09-08 21:27:28 +02:00
$reset_scripts .= 'jQuery(\'#' . $prefix . 'hour\').change();' ;
2021-02-23 22:03:23 +01:00
} elseif ( $addnowlink == 2 ) {
2020-09-08 21:27:28 +02:00
$reset_scripts .= 'jQuery(\'#' . $prefix . 'hour\').val(d.getHours().pad());' ;
$reset_scripts .= 'jQuery(\'#' . $prefix . 'hour\').change();' ;
}
2019-10-16 14:32:17 +02:00
2021-02-23 22:03:23 +01:00
if ( $fullday ) {
$reset_scripts .= ' } ' ;
}
2017-10-07 13:09:31 +02:00
}
// Update the minute part
2021-02-23 22:03:23 +01:00
if ( $m ) {
if ( $fullday ) {
$reset_scripts .= " if (jQuery('#fullday:checked').val() == null) { " ;
}
2017-10-07 13:09:31 +02:00
//$reset_scripts .= 'this.form.elements[\''.$prefix.'min\'].value=formatDate(new Date(), \'mm\'); ';
2021-02-23 22:03:23 +01:00
if ( $addnowlink == 1 ) {
2021-02-19 22:00:44 +01:00
$reset_scripts .= 'jQuery(\'#' . $prefix . 'min\').val(\'' . dol_print_date ( $nowgmt , '%M' , 'tzuserrel' ) . '\');' ;
2020-09-08 21:27:28 +02:00
$reset_scripts .= 'jQuery(\'#' . $prefix . 'min\').change();' ;
2021-02-23 22:03:23 +01:00
} elseif ( $addnowlink == 2 ) {
2020-09-08 21:27:28 +02:00
$reset_scripts .= 'jQuery(\'#' . $prefix . 'min\').val(d.getMinutes().pad());' ;
$reset_scripts .= 'jQuery(\'#' . $prefix . 'min\').change();' ;
}
2021-02-23 22:03:23 +01:00
if ( $fullday ) {
$reset_scripts .= ' } ' ;
}
2017-10-07 13:09:31 +02:00
}
// If reset_scripts is not empty, print the link with the reset_scripts in the onClick
2021-02-23 22:03:23 +01:00
if ( $reset_scripts && empty ( $conf -> dol_optimize_smallscreen )) {
2019-11-08 15:51:54 +01:00
$retstring .= ' <button class="dpInvisibleButtons datenowlink" id="' . $prefix . 'ButtonNow" type="button" name="_useless" value="now" onClick="' . $reset_scripts . '">' ;
$retstring .= $langs -> trans ( " Now " );
$retstring .= '</button> ' ;
2017-10-07 13:09:31 +02:00
}
}
2010-08-22 17:46:34 +02:00
2017-10-07 13:09:31 +02:00
// Add a "Plus one hour" link
2021-02-23 22:03:23 +01:00
if ( $conf -> use_javascript_ajax && $addplusone ) {
2017-10-07 13:09:31 +02:00
// Script which will be inserted in the onClick of the "Add plusone" link
$reset_scripts = " " ;
// Generate the date part, depending on the use or not of the javascript calendar
2021-02-19 22:00:44 +01:00
$reset_scripts .= 'jQuery(\'#' . $prefix . '\').val(\'' . dol_print_date ( $nowgmt , 'dayinputnoreduce' , 'tzuserrel' ) . '\');' ;
$reset_scripts .= 'jQuery(\'#' . $prefix . 'day\').val(\'' . dol_print_date ( $nowgmt , '%d' , 'tzuserrel' ) . '\');' ;
$reset_scripts .= 'jQuery(\'#' . $prefix . 'month\').val(\'' . dol_print_date ( $nowgmt , '%m' , 'tzuserrel' ) . '\');' ;
$reset_scripts .= 'jQuery(\'#' . $prefix . 'year\').val(\'' . dol_print_date ( $nowgmt , '%Y' , 'tzuserrel' ) . '\');' ;
2017-10-07 13:09:31 +02:00
// Update the hour part
2021-02-23 22:03:23 +01:00
if ( $h ) {
if ( $fullday ) {
$reset_scripts .= " if (jQuery('#fullday:checked').val() == null) { " ;
}
2021-02-19 22:00:44 +01:00
$reset_scripts .= 'jQuery(\'#' . $prefix . 'hour\').val(\'' . dol_print_date ( $nowgmt , '%H' , 'tzuserrel' ) . '\');' ;
2021-02-23 22:03:23 +01:00
if ( $fullday ) {
$reset_scripts .= ' } ' ;
}
2017-10-07 13:09:31 +02:00
}
// Update the minute part
2021-02-23 22:03:23 +01:00
if ( $m ) {
if ( $fullday ) {
$reset_scripts .= " if (jQuery('#fullday:checked').val() == null) { " ;
}
2021-02-19 22:00:44 +01:00
$reset_scripts .= 'jQuery(\'#' . $prefix . 'min\').val(\'' . dol_print_date ( $nowgmt , '%M' , 'tzuserrel' ) . '\');' ;
2021-02-23 22:03:23 +01:00
if ( $fullday ) {
$reset_scripts .= ' } ' ;
}
2017-10-07 13:09:31 +02:00
}
// If reset_scripts is not empty, print the link with the reset_scripts in the onClick
2021-02-23 22:03:23 +01:00
if ( $reset_scripts && empty ( $conf -> dol_optimize_smallscreen )) {
2019-12-16 13:06:25 +01:00
$retstring .= ' <button class="dpInvisibleButtons datenowlink" id="' . $prefix . 'ButtonPlusOne" type="button" name="_useless2" value="plusone" onClick="' . $reset_scripts . '">' ;
$retstring .= $langs -> trans ( " DateStartPlusOne " );
$retstring .= '</button> ' ;
2017-09-12 09:27:59 +02:00
}
}
2010-09-15 15:29:17 +02:00
2021-02-19 22:00:44 +01:00
// Add a link to set data
2021-02-23 22:03:23 +01:00
if ( $conf -> use_javascript_ajax && $adddateof ) {
2019-12-16 13:06:25 +01:00
$tmparray = dol_getdate ( $adddateof );
2021-02-23 22:03:23 +01:00
if ( empty ( $labeladddateof )) {
$labeladddateof = $langs -> trans ( " DateInvoice " );
}
2021-02-19 22:00:44 +01:00
$retstring .= ' - <button class="dpInvisibleButtons datenowlink" id="dateofinvoice" type="button" name="_dateofinvoice" value="now" onclick="console.log(\'Click on now link\'); jQuery(\'#re\').val(\'' . dol_print_date ( $adddateof , 'dayinputnoreduce' ) . '\');jQuery(\'#reday\').val(\'' . $tmparray [ 'mday' ] . '\');jQuery(\'#remonth\').val(\'' . $tmparray [ 'mon' ] . '\');jQuery(\'#reyear\').val(\'' . $tmparray [ 'year' ] . '\');">' . $labeladddateof . '</a>' ;
2017-10-07 13:09:31 +02:00
}
2012-03-15 22:51:02 +01:00
2018-09-08 12:00:11 +02:00
return $retstring ;
2017-09-12 09:27:59 +02:00
}
2016-08-04 09:21:04 +02:00
2020-08-29 04:58:07 +02:00
/**
2020-08-30 03:00:35 +02:00
* selectTypeDuration
2020-08-29 04:58:07 +02:00
*
2020-12-11 02:23:43 +01:00
* @ param string $prefix Prefix
* @ param string $selected Selected duration type
2020-12-11 13:46:47 +01:00
* @ param array $excludetypes Array of duration types to exclude . Example array ( 'y' , 'm' )
2020-12-11 02:23:43 +01:00
* @ return string HTML select string
2020-08-29 04:58:07 +02:00
*/
2020-12-11 13:46:47 +01:00
public function selectTypeDuration ( $prefix , $selected = 'i' , $excludetypes = array ())
2020-08-29 04:58:07 +02:00
{
2020-08-29 06:10:18 +02:00
global $langs ;
2020-08-25 12:40:29 +02:00
2020-12-11 13:46:47 +01:00
$TDurationTypes = array (
'y' => $langs -> trans ( 'Years' ),
'm' => $langs -> trans ( 'Month' ),
'w' => $langs -> trans ( 'Weeks' ),
'd' => $langs -> trans ( 'Days' ),
'h' => $langs -> trans ( 'Hours' ),
'i' => $langs -> trans ( 'Minutes' )
);
2020-08-25 12:40:29 +02:00
2020-12-11 02:23:43 +01:00
// Removed undesired duration types
2020-12-11 13:46:47 +01:00
foreach ( $excludetypes as $value ) {
unset ( $TDurationTypes [ $value ]);
2020-12-11 02:23:43 +01:00
}
2020-08-25 12:40:29 +02:00
2020-09-08 21:27:28 +02:00
$retstring = '<select class="flat" id="select_' . $prefix . 'type_duration" name="' . $prefix . 'type_duration">' ;
2020-12-11 13:43:03 +01:00
foreach ( $TDurationTypes as $key => $typeduration ) {
2020-09-08 21:27:28 +02:00
$retstring .= '<option value="' . $key . '"' ;
if ( $key == $selected ) {
$retstring .= " selected " ;
}
$retstring .= " > " . $typeduration . " </option> " ;
}
$retstring .= " </select> " ;
2020-08-25 12:40:29 +02:00
2020-12-11 02:23:43 +01:00
$retstring .= ajax_combobox ( 'select_' . $prefix . 'type_duration' );
2020-09-08 21:27:28 +02:00
return $retstring ;
}
2020-08-25 12:40:29 +02:00
2020-09-07 10:18:17 +02:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Function to show a form to select a duration on a page
2016-08-04 09:21:04 +02:00
*
2019-11-17 17:36:36 +01:00
* @ param string $prefix Prefix for input fields
* @ param int $iSecond Default preselected duration ( number of seconds or '' )
* @ param int $disabled Disable the combo box
* @ param string $typehour If 'select' then input hour and input min is a combo ,
* If 'text' input hour is in text and input min is a text ,
* If 'textselect' input hour is in text and input min is a combo
* @ param integer $minunderhours If 1 , show minutes selection under the hours
* @ param int $nooutput Do not output html string but return it
2018-10-26 20:12:46 +02:00
* @ return string | void
2017-10-07 13:09:31 +02:00
*/
2020-09-07 10:18:17 +02:00
public function select_duration ( $prefix , $iSecond = '' , $disabled = 0 , $typehour = 'select' , $minunderhours = 0 , $nooutput = 0 )
2017-10-07 13:09:31 +02:00
{
2020-09-07 10:18:17 +02:00
// phpcs:enable
2017-10-07 13:09:31 +02:00
global $langs ;
2012-03-15 22:51:02 +01:00
2019-11-08 15:51:54 +01:00
$retstring = '' ;
2012-03-19 17:18:11 +01:00
2021-03-01 20:37:16 +01:00
$hourSelected = 0 ;
$minSelected = 0 ;
2010-08-22 17:46:34 +02:00
2017-10-07 13:09:31 +02:00
// Hours
2021-02-23 22:03:23 +01:00
if ( $iSecond != '' ) {
2017-10-07 13:09:31 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php' ;
2010-08-22 17:46:34 +02:00
2019-01-27 11:55:16 +01:00
$hourSelected = convertSecondToTime ( $iSecond , 'allhour' );
$minSelected = convertSecondToTime ( $iSecond , 'min' );
2016-01-18 19:45:27 +01:00
}
2010-08-22 17:46:34 +02:00
2020-06-20 12:28:14 +02:00
if ( $typehour == 'select' ) {
2019-11-08 15:51:54 +01:00
$retstring .= '<select class="flat" id="select_' . $prefix . 'hour" name="' . $prefix . 'hour"' . ( $disabled ? ' disabled' : '' ) . '>' ;
2021-02-23 22:03:23 +01:00
for ( $hour = 0 ; $hour < 25 ; $hour ++ ) { // For a duration, we allow 24 hours
2019-11-08 15:51:54 +01:00
$retstring .= '<option value="' . $hour . '"' ;
2021-02-23 22:03:23 +01:00
if ( $hourSelected == $hour ) {
2019-11-08 15:51:54 +01:00
$retstring .= " selected " ;
2017-10-07 13:09:31 +02:00
}
2019-11-08 15:51:54 +01:00
$retstring .= " > " . $hour . " </option> " ;
2017-10-07 13:09:31 +02:00
}
2019-11-08 15:51:54 +01:00
$retstring .= " </select> " ;
2020-06-20 12:28:14 +02:00
} elseif ( $typehour == 'text' || $typehour == 'textselect' ) {
2020-06-20 00:00:17 +02:00
$retstring .= '<input placeholder="' . $langs -> trans ( 'HourShort' ) . '" type="number" min="0" name="' . $prefix . 'hour"' . ( $disabled ? ' disabled' : '' ) . ' class="flat maxwidth50 inputhour" value="' . (( $hourSelected != '' ) ? (( int ) $hourSelected ) : '' ) . '">' ;
2020-06-20 12:28:14 +02:00
} else {
return 'BadValueForParameterTypeHour' ;
2016-10-13 21:17:46 +02:00
}
2010-08-22 17:46:34 +02:00
2021-02-23 22:03:23 +01:00
if ( $typehour != 'text' ) {
$retstring .= ' ' . $langs -> trans ( 'HourShort' );
} else {
$retstring .= '<span class="hideonsmartphone">:</span>' ;
}
2011-05-01 20:22:58 +02:00
2017-10-07 13:09:31 +02:00
// Minutes
2021-02-23 22:03:23 +01:00
if ( $minunderhours ) {
$retstring .= '<br>' ;
} else {
$retstring .= '<span class="hideonsmartphone"> </span>' ;
}
2010-08-22 17:46:34 +02:00
2021-02-23 22:03:23 +01:00
if ( $typehour == 'select' || $typehour == 'textselect' ) {
2019-11-08 15:51:54 +01:00
$retstring .= '<select class="flat" id="select_' . $prefix . 'min" name="' . $prefix . 'min"' . ( $disabled ? ' disabled' : '' ) . '>' ;
2021-02-23 22:03:23 +01:00
for ( $min = 0 ; $min <= 55 ; $min = $min + 5 ) {
2019-11-08 15:51:54 +01:00
$retstring .= '<option value="' . $min . '"' ;
2021-02-23 22:03:23 +01:00
if ( $minSelected == $min ) {
$retstring .= ' selected' ;
}
2019-11-08 15:51:54 +01:00
$retstring .= '>' . $min . '</option>' ;
2017-10-07 13:09:31 +02:00
}
2019-11-08 15:51:54 +01:00
$retstring .= " </select> " ;
2021-02-23 22:03:23 +01:00
} elseif ( $typehour == 'text' ) {
2020-06-20 00:00:17 +02:00
$retstring .= '<input placeholder="' . $langs -> trans ( 'MinuteShort' ) . '" type="number" min="0" name="' . $prefix . 'min"' . ( $disabled ? ' disabled' : '' ) . ' class="flat maxwidth50 inputminute" value="' . (( $minSelected != '' ) ? (( int ) $minSelected ) : '' ) . '">' ;
2017-10-07 13:09:31 +02:00
}
2010-08-22 17:46:34 +02:00
2021-02-23 22:03:23 +01:00
if ( $typehour != 'text' ) {
$retstring .= ' ' . $langs -> trans ( 'MinuteShort' );
}
2013-04-14 14:45:23 +02:00
2017-10-07 13:09:31 +02:00
//$retstring.=" ";
2010-08-22 17:46:34 +02:00
2021-02-23 22:03:23 +01:00
if ( ! empty ( $nooutput )) {
return $retstring ;
}
2010-08-22 17:46:34 +02:00
2017-10-07 13:09:31 +02:00
print $retstring ;
return ;
}
2010-08-22 17:46:34 +02:00
2017-10-25 22:02:07 +02:00
/**
* Generic method to select a component from a combo list .
2020-09-19 00:44:47 +02:00
* Can use autocomplete with ajax after x key pressed or a full combo , depending on setup .
2017-10-25 22:02:07 +02:00
* This is the generic method that will replace all specific existing methods .
*
2019-10-22 03:46:08 +02:00
* @ param string $objectdesc ObjectClass : PathToClass [ : AddCreateButtonOrNot [ : Filter ]]
2017-10-25 22:02:07 +02:00
* @ param string $htmlname Name of HTML select component
* @ param int $preselectedvalue Preselected value ( ID of element )
* @ param string $showempty '' = empty values not allowed , 'string' = value show if we allow empty values ( for example 'All' , ... )
* @ param string $searchkey Search criteria
* @ param string $placeholder Place holder
* @ param string $morecss More CSS
* @ param string $moreparams More params provided to ajax call
* @ param int $forcecombo Force to load all values and output a standard combobox ( with no beautification )
2019-10-21 14:44:39 +02:00
* @ param int $disabled 1 = Html component is disabled
2019-10-30 02:09:29 +01:00
* @ param string $selected_input_value Value of preselected input text ( for use with ajax )
2017-10-25 22:02:07 +02:00
* @ return string Return HTML string
2020-10-07 00:59:05 +02:00
* @ see selectForFormsList () select_thirdparty_list ()
2017-10-25 22:02:07 +02:00
*/
2019-10-30 02:09:29 +01:00
public function selectForForms ( $objectdesc , $htmlname , $preselectedvalue , $showempty = '' , $searchkey = '' , $placeholder = '' , $morecss = '' , $moreparams = '' , $forcecombo = 0 , $disabled = 0 , $selected_input_value = '' )
2017-10-25 22:02:07 +02:00
{
global $conf , $user ;
2010-08-22 17:46:34 +02:00
2017-10-25 22:02:07 +02:00
$objecttmp = null ;
2010-08-22 17:46:34 +02:00
2017-10-25 22:02:07 +02:00
$InfoFieldList = explode ( " : " , $objectdesc );
2019-11-08 15:51:54 +01:00
$classname = $InfoFieldList [ 0 ];
$classpath = $InfoFieldList [ 1 ];
$addcreatebuttonornot = empty ( $InfoFieldList [ 2 ]) ? 0 : $InfoFieldList [ 2 ];
$filter = empty ( $InfoFieldList [ 3 ]) ? '' : $InfoFieldList [ 3 ];
2019-10-22 03:46:08 +02:00
2021-02-23 22:03:23 +01:00
if ( ! empty ( $classpath )) {
2017-10-25 22:02:07 +02:00
dol_include_once ( $classpath );
2020-05-29 21:45:50 +02:00
2021-02-23 22:03:23 +01:00
if ( $classname && class_exists ( $classname )) {
2017-10-26 01:02:13 +02:00
$objecttmp = new $classname ( $this -> db );
2019-11-01 18:35:48 +01:00
// Make some replacement
2019-11-01 18:44:32 +01:00
$sharedentities = getEntity ( strtolower ( $classname ));
2019-11-01 18:35:48 +01:00
$objecttmp -> filter = str_replace (
2019-11-01 18:44:32 +01:00
array ( '__ENTITY__' , '__SHARED_ENTITIES__' , '__USER_ID__' ),
array ( $conf -> entity , $sharedentities , $user -> id ),
2021-02-23 22:03:23 +01:00
$filter
);
2017-10-25 22:02:07 +02:00
}
}
2021-02-23 22:03:23 +01:00
if ( ! is_object ( $objecttmp )) {
2017-10-25 22:02:07 +02:00
dol_syslog ( 'Error bad setup of type for field ' . $InfoFieldList , LOG_WARNING );
return 'Error bad setup of type for field ' . join ( ',' , $InfoFieldList );
}
2010-08-22 17:46:34 +02:00
2019-11-01 18:44:32 +01:00
//var_dump($objecttmp->filter);
2019-12-16 13:06:25 +01:00
$prefixforautocompletemode = $objecttmp -> element ;
2021-02-23 22:03:23 +01:00
if ( $prefixforautocompletemode == 'societe' ) {
$prefixforautocompletemode = 'company' ;
}
if ( $prefixforautocompletemode == 'product' ) {
$prefixforautocompletemode = 'produit' ;
}
2019-12-16 13:06:25 +01:00
$confkeyforautocompletemode = strtoupper ( $prefixforautocompletemode ) . '_USE_SEARCH_TO_SELECT' ; // For example COMPANY_USE_SEARCH_TO_SELECT
2010-08-22 17:46:34 +02:00
2019-10-22 03:46:08 +02:00
dol_syslog ( get_class ( $this ) . " ::selectForForms object->filter= " . $objecttmp -> filter , LOG_DEBUG );
2019-12-16 13:06:25 +01:00
$out = '' ;
2021-02-23 22:03:23 +01:00
if ( ! empty ( $conf -> use_javascript_ajax ) && ! empty ( $conf -> global -> $confkeyforautocompletemode ) && ! $forcecombo ) {
2020-09-07 10:18:17 +02:00
// No immediate load of all database
$placeholder = '' ;
2021-02-23 22:03:23 +01:00
if ( $preselectedvalue && empty ( $selected_input_value )) {
2020-09-07 10:18:17 +02:00
$objecttmp -> fetch ( $preselectedvalue );
$selected_input_value = ( $prefixforautocompletemode == 'company' ? $objecttmp -> name : $objecttmp -> ref );
//unset($objecttmp);
}
2019-10-30 02:09:29 +01:00
2020-09-07 10:18:17 +02:00
$objectdesc = $classname . ':' . $classpath . ':' . $addcreatebuttonornot . ':' . $filter ;
2017-10-26 02:55:43 +02:00
$urlforajaxcall = DOL_URL_ROOT . '/core/ajax/selectobject.php' ;
2017-10-25 22:02:07 +02:00
// No immediate load of all database
2020-08-04 14:13:52 +02:00
$urloption = 'htmlname=' . $htmlname . '&outjson=1&objectdesc=' . $objectdesc . '&filter=' . urlencode ( $objecttmp -> filter );
2017-10-25 22:02:07 +02:00
// Activate the auto complete using ajax call.
2019-12-16 13:06:25 +01:00
$out .= ajax_autocompleter ( $preselectedvalue , $htmlname , $urlforajaxcall , $urloption , $conf -> global -> $confkeyforautocompletemode , 0 , array ());
$out .= '<style type="text/css">.ui-autocomplete { z-index: 250; }</style>' ;
2021-02-23 22:03:23 +01:00
if ( $placeholder ) {
$placeholder = ' placeholder="' . $placeholder . '"' ;
}
2019-12-16 13:06:25 +01:00
$out .= '<input type="text" class="' . $morecss . '"' . ( $disabled ? ' disabled="disabled"' : '' ) . ' name="search_' . $htmlname . '" id="search_' . $htmlname . '" value="' . $selected_input_value . '"' . $placeholder . ' />' ;
2020-05-21 15:05:19 +02:00
} else {
2019-10-22 03:46:08 +02:00
// Immediate load of table record. Note: filter is inside $objecttmp->filter
2019-12-16 13:06:25 +01:00
$out .= $this -> selectForFormsList ( $objecttmp , $htmlname , $preselectedvalue , $showempty , $searchkey , $placeholder , $morecss , $moreparams , $forcecombo , 0 , $disabled );
2017-10-25 22:02:07 +02:00
}
2010-08-22 17:46:34 +02:00
2017-10-25 22:02:07 +02:00
return $out ;
}
2010-08-22 17:46:34 +02:00
2019-10-22 03:46:08 +02:00
/**
* Function to forge a SQL criteria
*
* @ param array $matches Array of found string by regex search . Example : " t.ref:like:'SO-%' " or " t.date_creation:<:'20160101' " or " t.nature:is:NULL "
* @ return string Forged criteria . Example : " t.field like 'abc%' "
*/
protected static function forgeCriteriaCallback ( $matches )
{
global $db ;
//dol_syslog("Convert matches ".$matches[1]);
2021-02-23 22:03:23 +01:00
if ( empty ( $matches [ 1 ])) {
return '' ;
}
2019-11-08 15:51:54 +01:00
$tmp = explode ( ':' , $matches [ 1 ]);
2021-02-23 22:03:23 +01:00
if ( count ( $tmp ) < 3 ) {
return '' ;
}
2019-10-22 03:46:08 +02:00
2019-11-08 15:51:54 +01:00
$tmpescaped = $tmp [ 2 ];
2019-10-22 03:46:08 +02:00
$regbis = array ();
2021-02-23 22:03:23 +01:00
if ( preg_match ( '/^\'(.*)\'$/' , $tmpescaped , $regbis )) {
2019-10-22 03:46:08 +02:00
$tmpescaped = " ' " . $db -> escape ( $regbis [ 1 ]) . " ' " ;
2020-05-21 15:05:19 +02:00
} else {
2019-10-22 03:46:08 +02:00
$tmpescaped = $db -> escape ( $tmpescaped );
}
return $db -> escape ( $tmp [ 0 ]) . ' ' . strtoupper ( $db -> escape ( $tmp [ 1 ])) . " " . $tmpescaped ;
}
2017-10-25 22:02:07 +02:00
/**
* Output html form to select an object .
* Note , this function is called by selectForForms or by ajax selectobject . php
*
2019-10-22 03:46:08 +02:00
* @ param Object $objecttmp Object to knwo the table to scan for combo .
2017-10-25 22:02:07 +02:00
* @ param string $htmlname Name of HTML select component
* @ param int $preselectedvalue Preselected value ( ID of element )
* @ param string $showempty '' = empty values not allowed , 'string' = value show if we allow empty values ( for example 'All' , ... )
* @ param string $searchkey Search value
* @ param string $placeholder Place holder
* @ param string $morecss More CSS
* @ param string $moreparams More params provided to ajax call
* @ param int $forcecombo Force to load all values and output a standard combobox ( with no beautification )
* @ param int $outputmode 0 = HTML select string , 1 = Array
2019-10-21 14:44:39 +02:00
* @ param int $disabled 1 = Html component is disabled
2019-11-06 19:38:51 +01:00
* @ return string | array Return HTML string
2019-03-19 13:14:44 +01:00
* @ see selectForForms ()
2017-10-25 22:02:07 +02:00
*/
2020-09-07 10:18:17 +02:00
public function selectForFormsList ( $objecttmp , $htmlname , $preselectedvalue , $showempty = '' , $searchkey = '' , $placeholder = '' , $morecss = '' , $moreparams = '' , $forcecombo = 0 , $outputmode = 0 , $disabled = 0 )
2017-10-25 22:02:07 +02:00
{
2021-02-11 20:10:15 +01:00
global $conf , $langs , $user , $hookmanager ;
2010-08-22 17:46:34 +02:00
2019-10-22 03:46:08 +02:00
//print "$objecttmp->filter, $htmlname, $preselectedvalue, $showempty = '', $searchkey = '', $placeholder = '', $morecss = '', $moreparams = '', $forcecombo = 0, $outputmode = 0, $disabled";
2019-12-16 13:06:25 +01:00
$prefixforautocompletemode = $objecttmp -> element ;
2021-02-23 22:03:23 +01:00
if ( $prefixforautocompletemode == 'societe' ) {
$prefixforautocompletemode = 'company' ;
}
2019-12-16 13:06:25 +01:00
$confkeyforautocompletemode = strtoupper ( $prefixforautocompletemode ) . '_USE_SEARCH_TO_SELECT' ; // For example COMPANY_USE_SEARCH_TO_SELECT
2010-08-22 17:46:34 +02:00
2021-02-23 22:03:23 +01:00
if ( ! empty ( $objecttmp -> fields )) { // For object that declare it, it is better to use declared fields (like societe, contact, ...)
2019-12-16 13:06:25 +01:00
$tmpfieldstoshow = '' ;
2021-02-23 22:03:23 +01:00
foreach ( $objecttmp -> fields as $key => $val ) {
if ( ! dol_eval ( $val [ 'enabled' ], 1 , 1 )) {
continue ;
}
2021-03-19 10:01:40 +01:00
if ( ! empty ( $val [ 'showoncombobox' ])) {
2021-02-23 22:03:23 +01:00
$tmpfieldstoshow .= ( $tmpfieldstoshow ? ',' : '' ) . 't.' . $key ;
}
}
if ( $tmpfieldstoshow ) {
$fieldstoshow = $tmpfieldstoshow ;
2017-10-25 22:02:07 +02:00
}
2020-05-21 15:05:19 +02:00
} else {
2020-04-12 16:47:56 +02:00
// For backward compatibility
2020-04-12 21:38:23 +02:00
$objecttmp -> fields [ 'ref' ] = array ( 'type' => 'varchar(30)' , 'label' => 'Ref' , 'showoncombobox' => 1 );
2020-09-07 10:18:17 +02:00
}
2020-04-11 18:37:06 +02:00
2021-02-23 22:03:23 +01:00
if ( empty ( $fieldstoshow )) {
2019-11-06 19:38:51 +01:00
if ( isset ( $objecttmp -> fields [ 'ref' ])) {
2019-12-16 13:06:25 +01:00
$fieldstoshow = 't.ref' ;
2020-05-21 15:05:19 +02:00
} else {
2019-11-06 19:38:51 +01:00
$langs -> load ( " errors " );
$this -> error = $langs -> trans ( " ErrorNoFieldWithAttributeShowoncombobox " );
return $langs -> trans ( 'ErrorNoFieldWithAttributeShowoncombobox' );
}
}
2010-08-22 17:46:34 +02:00
2019-12-16 13:06:25 +01:00
$out = '' ;
$outarray = array ();
2015-07-04 11:57:55 +02:00
2019-12-16 13:06:25 +01:00
$num = 0 ;
2015-11-07 23:41:45 +01:00
2017-10-25 22:02:07 +02:00
// Search data
2019-12-16 13:06:25 +01:00
$sql = " SELECT t.rowid, " . $fieldstoshow . " FROM " . MAIN_DB_PREFIX . $objecttmp -> table_element . " as t " ;
2020-04-18 15:11:38 +02:00
if ( isset ( $objecttmp -> ismultientitymanaged ) && ! is_numeric ( $objecttmp -> ismultientitymanaged )) {
$tmparray = explode ( '@' , $objecttmp -> ismultientitymanaged );
$sql .= ' INNER JOIN ' . MAIN_DB_PREFIX . $tmparray [ 1 ] . ' as parenttable ON parenttable.rowid = t.' . $tmparray [ 0 ];
}
2021-02-23 22:03:23 +01:00
if ( $objecttmp -> ismultientitymanaged == 'fk_soc@societe' ) {
if ( ! $user -> rights -> societe -> client -> voir && ! $user -> socid ) {
$sql .= " , " . MAIN_DB_PREFIX . " societe_commerciaux as sc " ;
}
}
2021-02-09 23:46:07 +01:00
// Add where from hooks
2021-02-23 22:03:23 +01:00
$parameters = array ();
$reshook = $hookmanager -> executeHooks ( 'selectForFormsListWhere' , $parameters ); // Note that $action and $object may have been modified by hook
if ( ! empty ( $hookmanager -> resPrint )) {
$sql .= $hookmanager -> resPrint ;
} else {
$sql .= " WHERE 1=1 " ;
if ( isset ( $objecttmp -> ismultientitymanaged ) && $objecttmp -> ismultientitymanaged == 1 ) {
$sql .= " AND t.entity IN ( " . getEntity ( $objecttmp -> table_element ) . " ) " ;
}
if ( isset ( $objecttmp -> ismultientitymanaged ) && ! is_numeric ( $objecttmp -> ismultientitymanaged )) {
$sql .= ' AND parenttable.entity = t.' . $tmparray [ 0 ];
}
if ( $objecttmp -> ismultientitymanaged == 1 && ! empty ( $user -> socid )) {
if ( $objecttmp -> element == 'societe' ) {
$sql .= " AND t.rowid = " . $user -> socid ;
} else {
$sql .= " AND t.fk_soc = " . $user -> socid ;
}
}
if ( $searchkey != '' ) {
$sql .= natural_search ( explode ( ',' , $fieldstoshow ), $searchkey );
}
if ( $objecttmp -> ismultientitymanaged == 'fk_soc@societe' ) {
if ( ! $user -> rights -> societe -> client -> voir && ! $user -> socid ) {
$sql .= " AND t.rowid = sc.fk_soc AND sc.fk_user = " . $user -> id ;
}
}
if ( $objecttmp -> filter ) { // Syntax example "(t.ref:like:'SO-%') and (t.date_creation:<:'20160101')"
/* if ( ! DolibarrApi :: _checkFilters ( $objecttmp -> filter ))
{
throw new RestException ( 503 , 'Error when validating parameter sqlfilters ' . $objecttmp -> filter );
} */
2021-05-03 14:58:29 +02:00
$regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^\(\)]+)\)' ;
2021-02-23 22:03:23 +01:00
$sql .= " AND ( " . preg_replace_callback ( '/' . $regexstring . '/' , 'Form::forgeCriteriaCallback' , $objecttmp -> filter ) . " ) " ;
}
}
2019-12-16 13:06:25 +01:00
$sql .= $this -> db -> order ( $fieldstoshow , " ASC " );
2017-10-25 22:02:07 +02:00
//$sql.=$this->db->plimit($limit, 0);
2019-10-22 03:46:08 +02:00
//print $sql;
2010-08-22 17:46:34 +02:00
2017-10-25 22:02:07 +02:00
// Build output string
2019-12-16 13:06:25 +01:00
$resql = $this -> db -> query ( $sql );
2021-02-23 22:03:23 +01:00
if ( $resql ) {
2017-10-25 22:02:07 +02:00
// Construct $out and $outarray
2019-12-16 13:06:25 +01:00
$out .= '<select id="' . $htmlname . '" class="flat' . ( $morecss ? ' ' . $morecss : '' ) . '"' . ( $disabled ? ' disabled="disabled"' : '' ) . ( $moreparams ? ' ' . $moreparams : '' ) . ' name="' . $htmlname . '">' . " \n " ;
2013-06-05 22:01:35 +02:00
2017-10-25 22:02:07 +02:00
// Warning: Do not use textifempty = ' ' or ' ' here, or search on key will search on ' key'. Seems it is no more true with selec2 v4
2019-12-16 13:06:25 +01:00
$textifempty = ' ' ;
2014-12-21 14:58:18 +01:00
2017-10-25 22:02:07 +02:00
//if (! empty($conf->use_javascript_ajax) || $forcecombo) $textifempty='';
2021-02-23 22:03:23 +01:00
if ( ! empty ( $conf -> global -> $confkeyforautocompletemode )) {
if ( $showempty && ! is_numeric ( $showempty )) {
$textifempty = $langs -> trans ( $showempty );
} else {
$textifempty .= $langs -> trans ( " All " );
}
}
if ( $showempty ) {
$out .= '<option value="-1">' . $textifempty . '</option>' . " \n " ;
2017-10-25 22:02:07 +02:00
}
2014-12-21 14:58:18 +01:00
2017-10-25 22:02:07 +02:00
$num = $this -> db -> num_rows ( $resql );
$i = 0 ;
2021-02-23 22:03:23 +01:00
if ( $num ) {
while ( $i < $num ) {
2017-10-25 22:02:07 +02:00
$obj = $this -> db -> fetch_object ( $resql );
2019-11-08 15:51:54 +01:00
$label = '' ;
$tmparray = explode ( ',' , $fieldstoshow );
2021-06-05 15:27:49 +02:00
$oldvalueforshowoncombobox = 0 ;
2021-02-23 22:03:23 +01:00
foreach ( $tmparray as $key => $val ) {
2019-01-27 11:55:16 +01:00
$val = preg_replace ( '/t\./' , '' , $val );
2021-06-05 15:27:49 +02:00
$label .= (( $label && $obj -> $val ) ? ( $oldvalueforshowoncombobox != $objecttmp -> fields [ $val ][ 'showoncombobox' ] ? ' - ' : ' ' ) : '' );
$label .= $obj -> $val ;
$oldvalueforshowoncombobox = $objecttmp -> fields [ $val ][ 'showoncombobox' ];
2017-10-25 22:02:07 +02:00
}
2021-02-23 22:03:23 +01:00
if ( empty ( $outputmode )) {
2020-12-11 16:30:45 +01:00
if ( $preselectedvalue > 0 && $preselectedvalue == $obj -> rowid ) {
2019-11-08 15:51:54 +01:00
$out .= '<option value="' . $obj -> rowid . '" selected>' . $label . '</option>' ;
2020-05-21 15:05:19 +02:00
} else {
2019-11-08 15:51:54 +01:00
$out .= '<option value="' . $obj -> rowid . '">' . $label . '</option>' ;
2017-10-25 22:02:07 +02:00
}
2020-05-21 15:05:19 +02:00
} else {
2017-10-25 22:02:07 +02:00
array_push ( $outarray , array ( 'key' => $obj -> rowid , 'value' => $label , 'label' => $label ));
}
2010-08-22 17:46:34 +02:00
2017-10-25 22:02:07 +02:00
$i ++ ;
2021-02-23 22:03:23 +01:00
if (( $i % 10 ) == 0 ) {
$out .= " \n " ;
}
2017-10-25 22:02:07 +02:00
}
}
2013-06-05 22:01:35 +02:00
2019-11-08 15:51:54 +01:00
$out .= '</select>' . " \n " ;
2020-12-17 21:42:10 +01:00
2020-12-17 21:50:05 +01:00
if ( ! $forcecombo ) {
2020-12-17 21:42:10 +01:00
include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php' ;
2021-03-19 10:01:40 +01:00
$out .= ajax_combobox ( $htmlname , null , ( ! empty ( $conf -> global -> $confkeyforautocompletemode ) ? $conf -> global -> $confkeyforautocompletemode : 0 ));
2020-12-17 21:42:10 +01:00
}
2020-05-21 15:05:19 +02:00
} else {
2017-10-25 22:02:07 +02:00
dol_print_error ( $this -> db );
}
2017-05-25 08:48:59 +02:00
2019-11-08 15:51:54 +01:00
$this -> result = array ( 'nbofelement' => $num );
2017-03-16 17:02:30 +01:00
2021-02-23 22:03:23 +01:00
if ( $outputmode ) {
return $outarray ;
}
2017-10-25 22:02:07 +02:00
return $out ;
}
2014-12-21 14:58:18 +01:00
2017-10-07 13:09:31 +02:00
/**
* Return a HTML select string , built from an array of key + value .
* Note : Do not apply langs -> trans function on returned content , content may be entity encoded twice .
*
2018-03-23 16:09:46 +01:00
* @ param string $htmlname Name of html select area . Must start with " multi " if this is a multiselect
2020-11-21 14:14:53 +01:00
* @ param array $array Array like array ( key => value ) or array ( key => array ( 'label' =>... , 'data-...' =>... , 'disabled' =>... , 'css' =>... ))
2018-03-23 16:09:46 +01:00
* @ param string | string [] $id Preselected key or preselected keys for multiselect
2021-02-06 00:05:24 +01:00
* @ param int | string $show_empty 0 no empty value allowed , 1 or string to add an empty value into list ( If 1 : key is - 1 and value is '' or ' ' , If placeholder string : key is - 1 and value is the string ), < 0 to add an empty value with key that is this value .
2018-03-23 16:09:46 +01:00
* @ param int $key_in_label 1 to show key into label with format " [key] value "
* @ param int $value_as_key 1 to use value as key
* @ param string $moreparam Add more parameters onto the select tag . For example 'style="width: 95%"' to avoid select2 component to go over parent container
* @ param int $translate 1 = Translate and encode value
* @ param int $maxlen Length maximum for labels
* @ param int $disabled Html select box is disabled
* @ param string $sort 'ASC' or 'DESC' = Sort on label , '' or 'NONE' or 'POS' = Do not sort , we keep original order
* @ param string $morecss Add more class to css styles
* @ param int $addjscombo Add js combo
* @ param string $moreparamonempty Add more param on the empty option line . Not used if show_empty not set
2019-03-26 19:15:18 +01:00
* @ param int $disablebademail 1 = Check if a not valid email , 2 = Check string '---' , and if found into value , disable and colorize entry
2018-03-23 16:09:46 +01:00
* @ param int $nohtmlescape No html escaping .
* @ return string HTML select string .
2019-03-26 19:15:18 +01:00
* @ see multiselectarray (), selectArrayAjax (), selectArrayFilter ()
2017-10-07 13:09:31 +02:00
*/
2021-02-07 17:25:41 +01:00
public static function selectarray ( $htmlname , $array , $id = '' , $show_empty = 0 , $key_in_label = 0 , $value_as_key = 0 , $moreparam = '' , $translate = 0 , $maxlen = 0 , $disabled = 0 , $sort = '' , $morecss = '' , $addjscombo = 1 , $moreparamonempty = '' , $disablebademail = 0 , $nohtmlescape = 0 )
2017-10-07 13:09:31 +02:00
{
global $conf , $langs ;
2010-08-22 17:46:34 +02:00
2017-10-07 13:09:31 +02:00
// Do we want a multiselect ?
//$jsbeautify = 0;
//if (preg_match('/^multi/',$htmlname)) $jsbeautify = 1;
$jsbeautify = 1 ;
2010-08-22 17:46:34 +02:00
2021-02-23 22:03:23 +01:00
if ( $value_as_key ) {
$array = array_combine ( $array , $array );
}
2012-04-11 13:29:23 +02:00
2019-11-08 15:51:54 +01:00
$out = '' ;
2015-05-22 15:19:27 +02:00
2021-02-19 15:37:42 +01:00
if ( $addjscombo < 0 ) {
2021-02-23 22:03:23 +01:00
if ( empty ( $conf -> global -> MAIN_OPTIMIZEFORTEXTBROWSER )) {
$addjscombo = 1 ;
} else {
$addjscombo = 0 ;
}
2021-02-19 15:37:42 +01:00
}
2017-10-07 13:09:31 +02:00
// Add code for jquery to use multiselect
2021-02-07 17:25:41 +01:00
if ( $addjscombo && $jsbeautify ) {
2017-10-07 13:09:31 +02:00
// Enhance with select2
2019-11-08 15:51:54 +01:00
include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php' ;
2021-05-25 22:51:37 +02:00
$out .= ajax_combobox ( $htmlname , array (), 0 , 0 , 'resolve' , $show_empty < 0 ? ( string ) $show_empty : '-1' );
2017-10-07 13:09:31 +02:00
}
2014-11-20 15:32:10 +01:00
2020-03-15 13:57:31 +01:00
$out .= '<select id="' . preg_replace ( '/^\./' , '' , $htmlname ) . '" ' . ( $disabled ? 'disabled="disabled" ' : '' ) . 'class="flat ' . ( preg_replace ( '/^\./' , '' , $htmlname )) . ( $morecss ? ' ' . $morecss : '' ) . '"' ;
2019-11-08 15:51:54 +01:00
$out .= ' name="' . preg_replace ( '/^\./' , '' , $htmlname ) . '" ' . ( $moreparam ? $moreparam : '' );
$out .= '>' ;
2014-11-20 15:32:10 +01:00
2021-02-07 17:25:41 +01:00
if ( $show_empty ) {
2019-11-08 15:51:54 +01:00
$textforempty = ' ' ;
2021-02-23 22:03:23 +01:00
if ( ! empty ( $conf -> use_javascript_ajax )) {
$textforempty = ' ' ; // If we use ajaxcombo, we need here to avoid to have an empty element that is too small.
}
if ( ! is_numeric ( $show_empty )) {
$textforempty = $show_empty ;
}
2019-11-08 15:51:54 +01:00
$out .= '<option class="optiongrey" ' . ( $moreparamonempty ? $moreparamonempty . ' ' : '' ) . 'value="' . ( $show_empty < 0 ? $show_empty : - 1 ) . '"' . ( $id == $show_empty ? ' selected' : '' ) . '>' . $textforempty . '</option>' . " \n " ;
2017-10-07 13:09:31 +02:00
}
2010-08-22 17:46:34 +02:00
2021-02-07 17:25:41 +01:00
if ( is_array ( $array )) {
2017-10-07 13:09:31 +02:00
// Translate
2021-02-23 22:03:23 +01:00
if ( $translate ) {
foreach ( $array as $key => $value ) {
if ( ! is_array ( $value )) {
$array [ $key ] = $langs -> trans ( $value );
} else {
$array [ $key ][ 'label' ] = $langs -> trans ( $value [ 'label' ]);
}
2017-10-07 13:09:31 +02:00
}
}
2010-08-22 17:46:34 +02:00
2017-10-07 13:09:31 +02:00
// Sort
2021-02-23 22:03:23 +01:00
if ( $sort == 'ASC' ) {
asort ( $array );
} elseif ( $sort == 'DESC' ) {
arsort ( $array );
}
2013-10-28 02:13:07 +01:00
2021-02-23 22:03:23 +01:00
foreach ( $array as $key => $tmpvalue ) {
2020-11-21 14:14:53 +01:00
if ( is_array ( $tmpvalue )) {
$value = $tmpvalue [ 'label' ];
$disabled = empty ( $tmpvalue [ 'disabled' ]) ? '' : ' disabled' ;
$style = empty ( $tmpvalue [ 'css' ]) ? ' class="' . $tmpvalue [ 'css' ] . '"' : '' ;
} else {
$value = $tmpvalue ;
2021-03-01 20:37:16 +01:00
$disabled = '' ;
$style = '' ;
2020-11-21 14:14:53 +01:00
}
2021-01-14 10:56:24 +01:00
if ( ! empty ( $disablebademail )) {
2020-09-07 10:18:17 +02:00
if (( $disablebademail == 1 && ! preg_match ( '/<.+@.+>/' , $value ))
2021-02-23 22:03:23 +01:00
|| ( $disablebademail == 2 && preg_match ( '/---/' , $value ))) {
2019-11-08 15:51:54 +01:00
$disabled = ' disabled' ;
$style = ' class="warning"' ;
2017-10-07 13:09:31 +02:00
}
}
2010-08-22 17:46:34 +02:00
2021-01-14 10:56:24 +01:00
if ( $key_in_label ) {
2021-02-23 22:03:23 +01:00
if ( empty ( $nohtmlescape )) {
$selectOptionValue = dol_escape_htmltag ( $key . ' - ' . ( $maxlen ? dol_trunc ( $value , $maxlen ) : $value ));
} else {
$selectOptionValue = $key . ' - ' . ( $maxlen ? dol_trunc ( $value , $maxlen ) : $value );
}
2020-05-21 15:05:19 +02:00
} else {
2021-02-23 22:03:23 +01:00
if ( empty ( $nohtmlescape )) {
$selectOptionValue = dol_escape_htmltag ( $maxlen ? dol_trunc ( $value , $maxlen ) : $value );
} else {
$selectOptionValue = $maxlen ? dol_trunc ( $value , $maxlen ) : $value ;
}
if ( $value == '' || $value == '-' ) {
$selectOptionValue = ' ' ;
}
2017-10-07 13:09:31 +02:00
}
2017-10-26 20:06:23 +02:00
2019-11-08 15:51:54 +01:00
$out .= '<option value="' . $key . '"' ;
$out .= $style . $disabled ;
2020-01-21 22:20:32 +01:00
if ( is_array ( $id )) {
2021-02-23 22:03:23 +01:00
if ( in_array ( $key , $id ) && ! $disabled ) {
$out .= ' selected' ; // To preselect a value
}
2020-01-21 22:20:32 +01:00
} else {
2020-01-30 01:48:28 +01:00
$id = ( string ) $id ; // if $id = 0, then $id = '0'
2021-02-23 22:03:23 +01:00
if ( $id != '' && $id == $key && ! $disabled ) {
$out .= ' selected' ; // To preselect a value
}
2020-01-21 22:20:32 +01:00
}
2021-02-23 22:03:23 +01:00
if ( $nohtmlescape ) {
$out .= ' data-html="' . dol_escape_htmltag ( $selectOptionValue ) . '"' ;
}
if ( is_array ( $tmpvalue )) {
foreach ( $tmpvalue as $keyforvalue => $valueforvalue ) {
if ( preg_match ( '/^data-/' , $keyforvalue )) {
$out .= ' ' . $keyforvalue . '="' . $valueforvalue . '"' ;
}
2020-09-07 10:18:17 +02:00
}
2019-04-07 18:32:01 +02:00
}
2019-11-08 15:51:54 +01:00
$out .= '>' ;
2017-10-07 13:09:31 +02:00
//var_dump($selectOptionValue);
2019-11-08 15:51:54 +01:00
$out .= $selectOptionValue ;
$out .= " </option> \n " ;
2017-10-07 13:09:31 +02:00
}
}
2019-11-08 15:51:54 +01:00
$out .= " </select> " ;
2017-10-07 13:09:31 +02:00
return $out ;
}
2012-04-11 13:29:23 +02:00
2015-05-10 21:21:29 +02:00
2017-10-07 13:09:31 +02:00
/**
2018-05-13 12:42:16 +02:00
* Return a HTML select string , built from an array of key + value , but content returned into select come from an Ajax call of an URL .
2017-10-07 13:09:31 +02:00
* Note : Do not apply langs -> trans function on returned content of Ajax service , content may be entity encoded twice .
*
* @ param string $htmlname Name of html select area
* @ param string $url Url . Must return a json_encode of array ( key => array ( 'text' => 'A text' , 'url' => 'An url' ), ... )
* @ param string $id Preselected key
* @ param string $moreparam Add more parameters onto the select tag
* @ param string $moreparamtourl Add more parameters onto the Ajax called URL
* @ param int $disabled Html select box is disabled
* @ param int $minimumInputLength Minimum Input Length
* @ param string $morecss Add more class to css styles
* @ param int $callurlonselect If set to 1 , some code is added so an url return by the ajax is called when value is selected .
* @ param string $placeholder String to use as placeholder
2018-09-15 13:31:25 +02:00
* @ param integer $acceptdelayedhtml 1 = caller is requesting to have html js content not returned but saved into global $delayedhtmlcontent ( so caller can show it at end of page to avoid flash FOUC effect )
2017-10-07 13:09:31 +02:00
* @ return string HTML select string
2019-03-19 13:14:44 +01:00
* @ see selectArrayFilter (), ajax_combobox () in ajax . lib . php
2017-10-07 13:09:31 +02:00
*/
2019-02-27 23:55:18 +01:00
public static function selectArrayAjax ( $htmlname , $url , $id = '' , $moreparam = '' , $moreparamtourl = '' , $disabled = 0 , $minimumInputLength = 1 , $morecss = '' , $callurlonselect = 0 , $placeholder = '' , $acceptdelayedhtml = 0 )
2017-10-07 13:09:31 +02:00
{
global $conf , $langs ;
global $delayedhtmlcontent ;
2016-08-04 09:21:04 +02:00
2017-10-07 13:09:31 +02:00
// TODO Use an internal dolibarr component instead of select2
2021-02-23 22:03:23 +01:00
if ( empty ( $conf -> global -> MAIN_USE_JQUERY_MULTISELECT ) && ! defined ( 'REQUIRE_JQUERY_MULTISELECT' )) {
return '' ;
}
2016-08-04 09:21:04 +02:00
2019-11-08 15:51:54 +01:00
$out = '<select type="text" class="' . $htmlname . ( $morecss ? ' ' . $morecss : '' ) . '" ' . ( $moreparam ? $moreparam . ' ' : '' ) . 'name="' . $htmlname . '"></select>' ;
2016-08-04 09:21:04 +02:00
2019-11-08 15:51:54 +01:00
$tmpplugin = 'select2' ;
$outdelayed = " \n " . '<!-- JS CODE TO ENABLE ' . $tmpplugin . ' for id ' . $htmlname . ' -->
2019-01-20 23:36:39 +01:00
< script >
2015-09-12 11:33:22 +02:00
$ ( document ) . ready ( function () {
2016-08-04 09:21:04 +02:00
2019-11-08 15:51:54 +01:00
'.($callurlonselect ? ' var saveRemoteData = []; ' : ' ').'
2016-08-04 09:21:04 +02:00
2015-11-07 15:13:51 +01:00
$ ( " .'. $htmlname .' " ) . select2 ({
2015-09-12 11:33:22 +02:00
ajax : {
dir : " ltr " ,
url : " '. $url .' " ,
dataType : \ ' json\ ' ,
delay : 250 ,
2017-10-21 19:05:24 +02:00
data : function ( params ) {
2015-09-12 11:33:22 +02:00
return {
2017-10-21 19:05:24 +02:00
q : params . term , // search term
page : params . page
2015-09-12 11:33:22 +02:00
};
},
2017-10-21 19:05:24 +02:00
processResults : function ( data ) {
// parse the results into the format expected by Select2.
// since we are using custom formatting functions we do not need to alter the remote JSON data
//console.log(data);
saveRemoteData = data ;
2015-10-26 11:23:31 +01:00
/* format json result for select2 */
2015-10-21 20:43:11 +02:00
result = []
2017-10-21 19:05:24 +02:00
$ . each ( data , function ( key , value ) {
2015-10-26 11:23:31 +01:00
result . push ({ id : key , text : value . text });
2015-10-21 20:43:11 +02:00
});
//return {results:[{id:\'none\', text:\'aa\'}, {id:\'rrr\', text:\'Red\'},{id:\'bbb\', text:\'Search a into projects\'}], more:false}
2017-10-21 19:05:24 +02:00
//console.log(result);
return { results : result , more : false }
},
2015-09-12 11:33:22 +02:00
cache : true
},
2017-10-21 19:05:24 +02:00
language : select2arrayoflanguage ,
2017-11-11 14:20:08 +01:00
containerCssClass : \ ' : all : \ ' , /* Line to add class of origin SELECT propagated to the new <span class="select2-selection...> tag */
2015-10-26 12:16:40 +01:00
placeholder : " '.dol_escape_js( $placeholder ).' " ,
2017-10-21 19:05:24 +02:00
escapeMarkup : function ( markup ) { return markup ; }, // let our custom formatter work
2015-09-12 11:33:22 +02:00
minimumInputLength : '.$minimumInputLength.' ,
2015-10-26 11:23:31 +01:00
formatResult : function ( result , container , query , escapeMarkup ) {
return escapeMarkup ( result . text );
2017-10-21 19:05:24 +02:00
},
2015-09-12 11:33:22 +02:00
});
2016-08-04 09:21:04 +02:00
2015-10-26 11:23:31 +01:00
'.($callurlonselect ? '
2017-10-21 19:05:24 +02:00
/* Code to execute a GET when we select a value */
2016-08-04 09:21:04 +02:00
$ ( " .'. $htmlname .' " ) . change ( function () {
2017-10-28 17:34:46 +02:00
var selected = $ ( " .'. $htmlname .' " ) . val ();
2018-05-13 12:42:16 +02:00
console . log ( " We select in selectArrayAjax the entry " + selected )
2017-10-28 17:34:46 +02:00
$ ( " .'. $htmlname .' " ) . val ( " " ); /* reset visible combo value */
2015-10-26 11:23:31 +01:00
$ . each ( saveRemoteData , function ( key , value ) {
if ( key == selected )
{
2017-10-28 17:34:46 +02:00
console . log ( " selectArrayAjax - Do a redirect to " + value . url )
2015-10-26 11:23:31 +01:00
location . assign ( value . url );
}
});
2019-11-08 15:51:54 +01:00
}); ' : ' ').'
2016-08-04 09:21:04 +02:00
2015-11-07 15:13:51 +01:00
});
</ script > ' ;
2015-09-12 11:33:22 +02:00
2021-02-23 22:03:23 +01:00
if ( $acceptdelayedhtml ) {
2019-11-08 15:51:54 +01:00
$delayedhtmlcontent .= $outdelayed ;
2020-05-21 15:05:19 +02:00
} else {
2019-11-08 15:51:54 +01:00
$out .= $outdelayed ;
2015-11-07 15:13:51 +01:00
}
2015-05-10 21:21:29 +02:00
return $out ;
2017-10-07 13:09:31 +02:00
}
2020-09-07 10:18:17 +02:00
/**
* Return a HTML select string , built from an array of key + value , but content returned into select is defined into $array parameter .
* Note : Do not apply langs -> trans function on returned content of Ajax service , content may be entity encoded twice .
*
* @ param string $htmlname Name of html select area
2020-11-08 00:35:10 +01:00
* @ param array $array Array ( key => array ( 'text' => 'A text' , 'url' => 'An url' ), ... )
2018-03-21 15:08:20 +01:00
* @ param string $id Preselected key
* @ param string $moreparam Add more parameters onto the select tag
* @ param int $disableFiltering If set to 1 , results are not filtered with searched string
* @ param int $disabled Html select box is disabled
* @ param int $minimumInputLength Minimum Input Length
* @ param string $morecss Add more class to css styles
* @ param int $callurlonselect If set to 1 , some code is added so an url return by the ajax is called when value is selected .
* @ param string $placeholder String to use as placeholder
2018-09-15 13:31:25 +02:00
* @ param integer $acceptdelayedhtml 1 = caller is requesting to have html js content not returned but saved into global $delayedhtmlcontent ( so caller can show it at end of page to avoid flash FOUC effect )
2019-02-27 23:55:18 +01:00
* @ return string HTML select string
2019-04-04 18:33:12 +02:00
* @ see selectArrayAjax (), ajax_combobox () in ajax . lib . php
2018-03-21 15:08:20 +01:00
*/
2019-02-27 23:55:18 +01:00
public static function selectArrayFilter ( $htmlname , $array , $id = '' , $moreparam = '' , $disableFiltering = 0 , $disabled = 0 , $minimumInputLength = 1 , $morecss = '' , $callurlonselect = 0 , $placeholder = '' , $acceptdelayedhtml = 0 )
2018-03-21 15:08:20 +01:00
{
global $conf , $langs ;
global $delayedhtmlcontent ;
// TODO Use an internal dolibarr component instead of select2
2021-02-23 22:03:23 +01:00
if ( empty ( $conf -> global -> MAIN_USE_JQUERY_MULTISELECT ) && ! defined ( 'REQUIRE_JQUERY_MULTISELECT' )) {
return '' ;
}
2018-03-21 15:08:20 +01:00
2019-11-08 15:51:54 +01:00
$out = '<select type="text" class="' . $htmlname . ( $morecss ? ' ' . $morecss : '' ) . '" ' . ( $moreparam ? $moreparam . ' ' : '' ) . 'name="' . $htmlname . '"><option></option></select>' ;
2018-03-21 15:08:20 +01:00
$formattedarrayresult = array ();
2019-11-08 15:51:54 +01:00
foreach ( $array as $key => $value ) {
2018-03-21 15:08:20 +01:00
$o = new stdClass ();
$o -> id = $key ;
$o -> text = $value [ 'text' ];
$o -> url = $value [ 'url' ];
$formattedarrayresult [] = $o ;
}
2019-11-08 15:51:54 +01:00
$tmpplugin = 'select2' ;
$outdelayed = " \n " . '<!-- JS CODE TO ENABLE ' . $tmpplugin . ' for id ' . $htmlname . ' -->
2019-01-20 23:36:39 +01:00
< script >
2018-03-21 15:08:20 +01:00
$ ( document ) . ready ( function () {
var data = '.json_encode($formattedarrayresult).' ;
2019-11-08 15:51:54 +01:00
'.($callurlonselect ? ' var saveRemoteData = '.json_encode($array).' ; ' : ' ').'
2018-03-21 15:08:20 +01:00
$ ( " .'. $htmlname .' " ) . select2 ({
data : data ,
language : select2arrayoflanguage ,
containerCssClass : \ ' : all : \ ' , /* Line to add class of origin SELECT propagated to the new <span class="select2-selection...> tag */
placeholder : " '.dol_escape_js( $placeholder ).' " ,
escapeMarkup : function ( markup ) { return markup ; }, // let our custom formatter work
minimumInputLength : '.$minimumInputLength.' ,
formatResult : function ( result , container , query , escapeMarkup ) {
return escapeMarkup ( result . text );
},
matcher : function ( params , data ) {
if ( ! data . id ) return null ; ' ;
2019-11-08 15:51:54 +01:00
if ( $callurlonselect ) {
$outdelayed .= '
2018-03-21 15:08:20 +01:00
var urlBase = data . url ;
var separ = urlBase . indexOf ( " ? " ) >= 0 ? " & " : " ? " ;
2018-05-13 12:42:16 +02:00
/* console.log("params.term="+params.term); */
/* console.log("params.term encoded="+encodeURIComponent(params.term)); */
2020-11-26 23:50:00 +01:00
saveRemoteData [ data . id ] . url = urlBase + separ + " sall= " + encodeURIComponent ( params . term . replace ( / \ " /g, " " ));';
2018-03-21 15:08:20 +01:00
}
2019-11-08 15:51:54 +01:00
if ( ! $disableFiltering ) {
$outdelayed .= '
2018-03-21 15:08:20 +01:00
if ( data . text . match ( new RegExp ( params . term ))) {
return data ;
}
return null ; ' ;
} else {
2019-11-08 15:51:54 +01:00
$outdelayed .= '
2018-03-21 15:08:20 +01:00
return data ; ' ;
}
2019-11-08 15:51:54 +01:00
$outdelayed .= '
2018-03-21 15:08:20 +01:00
}
});
'.($callurlonselect ? '
/* Code to execute a GET when we select a value */
$ ( " .'. $htmlname .' " ) . change ( function () {
var selected = $ ( " .'. $htmlname .' " ) . val ();
console . log ( " We select " + selected )
$ ( " .'. $htmlname .' " ) . val ( " " ); /* reset visible combo value */
$ . each ( saveRemoteData , function ( key , value ) {
if ( key == selected )
{
2020-11-26 23:50:00 +01:00
console . log ( " selectArrayFilter - Do a redirect to " + value . url )
2018-03-21 15:08:20 +01:00
location . assign ( value . url );
}
});
2019-11-08 15:51:54 +01:00
}); ' : ' ').'
2018-03-21 15:08:20 +01:00
});
</ script > ' ;
2021-01-02 10:18:58 +01:00
if ( $acceptdelayedhtml ) {
2019-11-08 15:51:54 +01:00
$delayedhtmlcontent .= $outdelayed ;
2020-05-21 15:05:19 +02:00
} else {
2019-11-08 15:51:54 +01:00
$out .= $outdelayed ;
2018-03-21 15:08:20 +01:00
}
return $out ;
}
2017-10-07 13:09:31 +02:00
/**
2021-04-01 13:15:23 +02:00
* Show a multiselect form from an array . WARNING : Use this only for short lists .
2017-10-07 13:09:31 +02:00
*
* @ param string $htmlname Name of select
* @ param array $array Array with key + value
* @ param array $selected Array with key + value preselected
2020-08-28 17:17:22 +02:00
* @ param int $key_in_label 1 to show key like in " [key] value "
2017-10-07 13:09:31 +02:00
* @ param int $value_as_key 1 to use value as key
* @ param string $morecss Add more css style
* @ param int $translate Translate and encode value
* @ param int $width Force width of select box . May be used only when using jquery couch . Example : 250 , 95 %
* @ param string $moreattrib Add more options on select component . Example : 'disabled'
2020-01-30 19:14:59 +01:00
* @ param string $elemtype Type of element we show ( 'category' , ... ) . Will execute a formating function on it . To use in readonly mode if js component support HTML formatting .
2018-09-15 13:31:25 +02:00
* @ param string $placeholder String to use as placeholder
* @ param int $addjscombo Add js combo
2017-10-07 13:09:31 +02:00
* @ return string HTML multiselect string
2019-03-19 13:14:44 +01:00
* @ see selectarray (), selectArrayAjax (), selectArrayFilter ()
2017-10-07 13:09:31 +02:00
*/
2019-02-27 23:55:18 +01:00
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 )
2017-10-07 13:09:31 +02:00
{
global $conf , $langs ;
$out = '' ;
2019-01-08 14:05:07 +01:00
if ( $addjscombo < 0 ) {
2021-02-23 22:03:23 +01:00
if ( empty ( $conf -> global -> MAIN_OPTIMIZEFORTEXTBROWSER )) {
$addjscombo = 1 ;
} else {
$addjscombo = 0 ;
}
2019-01-08 14:05:07 +01:00
}
2018-09-15 13:31:25 +02:00
2017-10-07 13:09:31 +02:00
// Add code for jquery to use multiselect
2021-01-02 10:17:11 +01:00
if ( ! empty ( $conf -> global -> MAIN_USE_JQUERY_MULTISELECT ) || defined ( 'REQUIRE_JQUERY_MULTISELECT' )) {
2021-01-18 11:07:46 +01:00
$out .= " \n " . '<!-- JS CODE TO ENABLE select for id ' . $htmlname . ', addjscombo=' . $addjscombo . ' -->' ;
$out .= " \n " . '<script>' . " \n " ;
2021-01-02 10:17:11 +01:00
if ( $addjscombo == 1 ) {
2019-11-08 15:51:54 +01:00
$tmpplugin = empty ( $conf -> global -> MAIN_USE_JQUERY_MULTISELECT ) ? constant ( 'REQUIRE_JQUERY_MULTISELECT' ) : $conf -> global -> MAIN_USE_JQUERY_MULTISELECT ;
$out .= 'function formatResult(record) {' . " \n " ;
2021-01-02 10:17:11 +01:00
if ( $elemtype == 'category' ) {
2020-04-27 00:09:21 +02:00
$out .= 'return \'<span><img src="' . DOL_URL_ROOT . '/theme/eldy/img/object_category.png"> \'+record.text+\'</span>\';' ;
2020-05-21 15:05:19 +02:00
} else {
2019-11-08 15:51:54 +01:00
$out .= 'return record.text;' ;
2018-09-15 13:31:25 +02:00
}
2019-11-08 15:51:54 +01:00
$out .= '};' . " \n " ;
$out .= 'function formatSelection(record) {' . " \n " ;
2021-01-02 10:17:11 +01:00
if ( $elemtype == 'category' ) {
2020-04-27 00:09:21 +02:00
$out .= 'return \'<span><img src="' . DOL_URL_ROOT . '/theme/eldy/img/object_category.png"> \'+record.text+\'</span>\';' ;
2020-05-21 15:05:19 +02:00
} else {
2019-11-08 15:51:54 +01:00
$out .= 'return record.text;' ;
2018-09-15 13:31:25 +02:00
}
2019-11-08 15:51:54 +01:00
$out .= '};' . " \n " ;
$out .= ' $ ( document ) . ready ( function () {
2018-09-15 13:31:25 +02:00
$ ( \ '#' . $htmlname . '\').' . $tmpplugin . ' ({
dir : \ ' ltr\ ' ,
// Specify format function for dropdown item
formatResult : formatResult ,
templateResult : formatResult , /* For 4.0 */
// Specify format function for selected item
formatSelection : formatSelection ,
2020-05-25 23:05:29 +02:00
templateSelection : formatSelection /* For 4.0 */
2018-09-15 13:31:25 +02:00
});
2021-01-18 11:05:02 +01:00
/* Add also morecss to the css . select2 that is after the #htmlname, for component that are show dynamically after load, because select2 set
the size only if component is not hidden by default on load */
$ ( \ '#' . $htmlname . ' + .select2\').addClass(\'' . $morecss . ' \ ' );
2018-09-15 13:31:25 +02:00
}); ' . " \n " ;
2021-01-02 10:17:11 +01:00
} elseif ( $addjscombo == 2 && ! defined ( 'DISABLE_MULTISELECT' )) {
2018-09-15 13:31:25 +02:00
// Add other js lib
2019-11-22 14:06:43 +01:00
// TODO external lib multiselect/jquery.multi-select.js must have been loaded to use this multiselect plugin
2018-09-15 13:31:25 +02:00
// ...
2020-09-21 12:16:22 +02:00
$out .= 'console.log(\'addjscombo=2 for htmlname=' . $htmlname . '\');' ;
2019-11-08 15:51:54 +01:00
$out .= ' $ ( document ) . ready ( function () {
2018-09-15 13:31:25 +02:00
$ ( \ '#' . $htmlname . ' \ ' ) . multiSelect ({
containerHTML : \ ' < div class = " multi-select-container " > \ ' ,
menuHTML : \ ' < div class = " multi-select-menu " > \ ' ,
buttonHTML : \ '<span class="multi-select-button ' . $morecss . ' " > \ ',
menuItemHTML : \ ' < label class = " multi-select-menuitem " > \ ' ,
activeClass : \ ' multi - select - container -- open\ ' ,
noneText : \ '' . $placeholder . ' \ '
});
}) ' ;
}
2019-11-08 15:51:54 +01:00
$out .= '</script>' ;
2017-10-07 13:09:31 +02:00
}
2014-11-04 00:33:50 +01:00
2017-10-07 13:09:31 +02:00
// Try also magic suggest
2019-11-08 15:51:54 +01:00
$out .= '<select id="' . $htmlname . '" class="multiselect' . ( $morecss ? ' ' . $morecss : '' ) . '" multiple name="' . $htmlname . '[]"' . ( $moreattrib ? ' ' . $moreattrib : '' ) . ( $width ? ' style="width: ' . ( preg_match ( '/%/' , $width ) ? $width : $width . 'px' ) . '"' : '' ) . '>' . " \n " ;
2021-01-02 10:17:11 +01:00
if ( is_array ( $array ) && ! empty ( $array )) {
if ( $value_as_key ) {
$array = array_combine ( $array , $array );
}
2015-05-14 15:43:07 +02:00
2021-01-02 10:17:11 +01:00
if ( ! empty ( $array )) {
foreach ( $array as $key => $value ) {
2020-08-28 17:17:22 +02:00
$newval = ( $translate ? $langs -> trans ( $value ) : $value );
$newval = ( $key_in_label ? $key . ' - ' . $newval : $newval );
2019-11-08 15:51:54 +01:00
$out .= '<option value="' . $key . '"' ;
2021-01-02 10:17:11 +01:00
if ( is_array ( $selected ) && ! empty ( $selected ) && in_array (( string ) $key , $selected ) && (( string ) $key != '' )) {
2019-11-08 15:51:54 +01:00
$out .= ' selected' ;
2017-10-07 13:09:31 +02:00
}
2020-12-11 17:11:50 +01:00
$out .= ' data-html="' . dol_escape_htmltag ( $newval ) . '"' ;
2019-11-08 15:51:54 +01:00
$out .= '>' ;
$out .= dol_htmlentitiesbr ( $newval );
$out .= '</option>' . " \n " ;
2017-10-07 13:09:31 +02:00
}
}
}
2019-11-08 15:51:54 +01:00
$out .= '</select>' . " \n " ;
2010-08-22 17:46:34 +02:00
2017-10-07 13:09:31 +02:00
return $out ;
}
2010-08-22 17:46:34 +02:00
2016-08-04 09:21:04 +02:00
2017-10-07 13:09:31 +02:00
/**
2021-03-28 19:15:59 +02:00
* Show a multiselect dropbox from an array . If a saved selection of fields exists for user ( into $user -> conf -> MAIN_SELECTEDFIELDS_contextofpage ), we use this one instead of default .
2017-10-07 13:09:31 +02:00
*
2017-10-29 11:00:02 +01:00
* @ param string $htmlname Name of HTML field
2017-10-07 13:09:31 +02:00
* @ param array $array Array with array of fields we could show . This array may be modified according to setup of user .
2017-10-25 22:23:54 +02:00
* @ param string $varpage Id of context for page . Can be set by caller with $varpage = ( empty ( $contextpage ) ? $_SERVER [ " PHP_SELF " ] : $contextpage );
2017-10-07 13:09:31 +02:00
* @ return string HTML multiselect string
2019-03-19 13:14:44 +01:00
* @ see selectarray ()
2017-10-07 13:09:31 +02:00
*/
2019-02-27 23:55:18 +01:00
public static function multiSelectArrayWithCheckbox ( $htmlname , & $array , $varpage )
2017-10-07 13:09:31 +02:00
{
2020-08-07 15:19:26 +02:00
global $conf , $langs , $user , $extrafields ;
2017-10-07 13:09:31 +02:00
2021-01-02 10:17:11 +01:00
if ( ! empty ( $conf -> global -> MAIN_OPTIMIZEFORTEXTBROWSER )) {
return '' ;
}
2016-08-04 09:21:04 +02:00
2021-03-28 19:15:59 +02:00
$tmpvar = " MAIN_SELECTEDFIELDS_ " . $varpage ; // To get list of saved selected fields to show
if ( ! empty ( $user -> conf -> $tmpvar )) { // A list of fields was already customized for user
2019-11-08 15:51:54 +01:00
$tmparray = explode ( ',' , $user -> conf -> $tmpvar );
2021-01-02 10:17:11 +01:00
foreach ( $array as $key => $val ) {
2017-10-07 13:09:31 +02:00
//var_dump($key);
//var_dump($tmparray);
2021-01-02 10:17:11 +01:00
if ( in_array ( $key , $tmparray )) {
$array [ $key ][ 'checked' ] = 1 ;
} else {
$array [ $key ][ 'checked' ] = 0 ;
}
2017-10-07 13:09:31 +02:00
}
2021-03-28 19:15:59 +02:00
} else { // There is no list of fields already customized for user
foreach ( $array as $key => $val ) {
if ( $array [ $key ][ 'checked' ] < 0 ) {
$array [ $key ][ 'checked' ] = 0 ;
}
}
2017-10-07 13:09:31 +02:00
}
2016-08-04 09:21:04 +02:00
2021-06-13 13:29:15 +02:00
$listoffieldsforselection = '' ;
2019-11-08 15:51:54 +01:00
$listcheckedstring = '' ;
2016-08-04 09:21:04 +02:00
2021-01-02 10:17:11 +01:00
foreach ( $array as $key => $val ) {
2020-09-08 21:27:28 +02:00
/* var_dump ( $val );
2021-02-23 22:03:23 +01:00
var_dump ( array_key_exists ( 'enabled' , $val ));
var_dump ( ! $val [ 'enabled' ]); */
2021-01-02 10:17:11 +01:00
if ( array_key_exists ( 'enabled' , $val ) && isset ( $val [ 'enabled' ]) && ! $val [ 'enabled' ]) {
2020-09-08 21:27:28 +02:00
unset ( $array [ $key ]); // We don't want this field
continue ;
}
2021-06-13 13:29:15 +02:00
if ( ! empty ( $val [ 'type' ]) && $val [ 'type' ] == 'separate' ) {
// Field remains in array but we don't add it into $listoffieldsforselection
//$listoffieldsforselection .= '<li>-----</li>';
continue ;
}
2021-01-02 10:17:11 +01:00
if ( $val [ 'label' ]) {
2020-09-08 21:27:28 +02:00
if ( ! empty ( $val [ 'langfile' ]) && is_object ( $langs )) {
$langs -> load ( $val [ 'langfile' ]);
}
2021-03-28 19:15:59 +02:00
// Note: $val['checked'] <> 0 means we must show the field into the combo list
2021-06-13 13:29:15 +02:00
$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>' ;
2020-09-08 21:27:28 +02:00
$listcheckedstring .= ( empty ( $val [ 'checked' ]) ? '' : $key . ',' );
}
2017-10-07 13:09:31 +02:00
}
2016-08-04 09:21:04 +02:00
2019-11-08 15:51:54 +01:00
$out = '<!-- Component multiSelectArrayWithCheckbox ' . $htmlname . ' -->
2016-08-04 09:21:04 +02:00
2016-08-05 13:08:23 +02:00
< dl class = " dropdown " >
2015-10-09 16:35:14 +02:00
< dt >
2019-04-11 17:59:11 +02:00
< a href = " #'. $htmlname .' " >
2019-01-27 11:55:16 +01:00
'.img_picto(' ', ' list ').'
2015-10-09 16:35:14 +02:00
</ a >
2016-08-28 15:21:09 +02:00
< input type = " hidden " class = " '. $htmlname .' " name = " '. $htmlname .' " value = " '. $listcheckedstring .' " >
2015-10-09 16:35:14 +02:00
</ dt >
2018-04-16 19:56:53 +02:00
< dd class = " dropdowndd " >
2015-10-09 16:35:14 +02:00
< div class = " multiselectcheckbox'. $htmlname .' " >
2016-01-03 16:23:23 +01:00
< ul class = " ul'. $htmlname .' " >
2021-06-13 13:29:15 +02:00
'.$listoffieldsforselection.'
2015-10-09 16:35:14 +02:00
</ ul >
</ div >
</ dd >
</ dl >
2016-08-04 09:21:04 +02:00
2015-10-09 16:35:14 +02:00
< script type = " text/javascript " >
2016-08-05 12:18:51 +02:00
jQuery ( document ) . ready ( function () {
$ ( \ '.multiselectcheckbox' . $htmlname . ' input [ type = " checkbox " ] \ ' ) . on ( \ ' click\ ' , function () {
2020-02-23 21:38:24 +01:00
console . log ( " A new field was added/removed, we edit field input[name=formfilteraction] " );
$ ( " input:hidden[name=formfilteraction] " ) . val ( \ ' listafterchangingselectedfields\ ' ); // Update field so we know we changed something on selected fields after POST
2016-08-05 12:18:51 +02:00
var title = $ ( this ) . val () + " , " ;
if ( $ ( this ) . is ( \ ' : checked\ ' )) {
$ ( \ '.' . $htmlname . '\').val(title + $(\'.' . $htmlname . ' \ ' ) . val ());
}
else {
$ ( \ '.' . $htmlname . '\').val( $(\'.' . $htmlname . ' \ ' ) . val () . replace ( title , \ ' \ ' ) )
}
// Now, we submit page
2020-02-23 21:38:24 +01:00
//$(this).parents(\'form:first\').submit();
2016-08-05 12:18:51 +02:00
});
2020-02-23 21:38:24 +01:00
2016-08-05 12:18:51 +02:00
});
2016-08-04 09:21:04 +02:00
</ script >
2015-10-09 16:35:14 +02:00
' ;
2017-10-07 13:09:31 +02:00
return $out ;
}
2015-05-14 15:43:07 +02:00
2015-05-03 15:51:55 +02:00
/**
* Render list of categories linked to object with id $id and type $type
*
* @ param int $id Id of object
2017-10-07 13:09:31 +02:00
* @ param string $type Type of category ( 'member' , 'customer' , 'supplier' , 'product' , 'contact' ) . Old mode ( 0 , 1 , 2 , ... ) is deprecated .
* @ param int $rendermode 0 = Default , use multiselect . 1 = Emulate multiselect ( recommended )
2020-06-16 02:56:48 +02:00
* @ param int $nolink 1 = Do not add html links
2016-06-23 20:19:35 +02:00
* @ return string String with categories
2015-05-03 15:51:55 +02:00
*/
2020-09-07 10:18:17 +02:00
public function showCategories ( $id , $type , $rendermode = 0 , $nolink = 0 )
2015-05-03 15:51:55 +02:00
{
global $db ;
2015-09-17 19:35:03 +02:00
include_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php' ;
2015-09-16 21:24:51 +02:00
2015-05-03 15:51:55 +02:00
$cat = new Categorie ( $db );
$categories = $cat -> containing ( $id , $type );
2021-02-23 22:03:23 +01:00
if ( $rendermode == 1 ) {
2015-05-03 15:51:55 +02:00
$toprint = array ();
2021-02-23 22:03:23 +01:00
foreach ( $categories as $c ) {
2020-06-16 02:56:48 +02:00
$ways = $c -> print_all_ways ( ' >> ' , ( $nolink ? 'none' : '' ), 0 , 1 ); // $ways[0] = "ccc2 >> ccc2a >> ccc2a1" with html formated text
2021-02-23 22:03:23 +01:00
foreach ( $ways as $way ) {
2020-11-23 19:53:58 +01:00
$toprint [] = '<li class="select2-search-choice-dolibarr noborderoncategories"' . ( $c -> color ? ' style="background: #' . $c -> color . ';"' : ' style="background: #bbb"' ) . '>' . $way . '</li>' ;
2015-05-03 15:51:55 +02:00
}
}
2015-06-22 22:31:44 +02:00
return '<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">' . implode ( ' ' , $toprint ) . '</ul></div>' ;
2015-05-03 15:51:55 +02:00
}
2021-02-23 22:03:23 +01:00
if ( $rendermode == 0 ) {
2019-11-08 15:51:54 +01:00
$arrayselected = array ();
2015-10-08 11:03:08 +02:00
$cate_arbo = $this -> select_all_categories ( $type , '' , 'parent' , 64 , 0 , 1 );
2019-11-08 15:51:54 +01:00
foreach ( $categories as $c ) {
2015-05-03 15:51:55 +02:00
$arrayselected [] = $c -> id ;
}
2015-05-07 11:57:23 +02:00
return $this -> multiselectarray ( 'categories' , $cate_arbo , $arrayselected , '' , 0 , '' , 0 , '100%' , 'disabled' , 'category' );
2015-05-03 15:51:55 +02:00
}
2019-11-08 15:51:54 +01:00
return 'ErrorBadValueForParameterRenderMode' ; // Should not happened
2015-05-03 15:51:55 +02:00
}
2017-10-07 13:09:31 +02:00
/**
* Show linked object block .
*
* @ param CommonObject $object Object we want to show links to
* @ param string $morehtmlright More html to show on right of title
2018-02-22 15:19:20 +01:00
* @ param array $compatibleImportElementsList Array of compatibles elements object for " import from " action
2017-10-07 13:09:31 +02:00
* @ return int < 0 if KO , >= 0 if OK
*/
2020-09-07 10:18:17 +02:00
public function showLinkedObjectBlock ( $object , $morehtmlright = '' , $compatibleImportElementsList = false )
2017-10-07 13:09:31 +02:00
{
2019-11-08 15:51:54 +01:00
global $conf , $langs , $hookmanager ;
2019-06-17 15:54:54 +02:00
global $bc , $action ;
2015-06-06 12:26:47 +02:00
2017-10-07 13:09:31 +02:00
$object -> fetchObjectLinked ();
2015-06-06 12:26:47 +02:00
2017-10-07 13:09:31 +02:00
// Bypass the default method
$hookmanager -> initHooks ( array ( 'commonobject' ));
2019-11-08 15:51:54 +01:00
$parameters = array (
2018-07-01 18:22:18 +02:00
'morehtmlright' => $morehtmlright ,
2020-09-07 10:18:17 +02:00
'compatibleImportElementsList' => & $compatibleImportElementsList ,
2018-02-22 15:19:20 +01:00
);
2019-11-08 15:51:54 +01:00
$reshook = $hookmanager -> executeHooks ( 'showLinkedObjectBlock' , $parameters , $object , $action ); // Note that $action and $object may have been modified by hook
2015-06-06 12:26:47 +02:00
2021-02-23 22:03:23 +01:00
if ( empty ( $reshook )) {
2017-10-07 13:09:31 +02:00
$nbofdifferenttypes = count ( $object -> linkedObjects );
2015-06-06 12:26:47 +02:00
2017-10-07 13:09:31 +02:00
print '<!-- showLinkedObjectBlock -->' ;
print load_fiche_titre ( $langs -> trans ( 'RelatedObjects' ), $morehtmlright , '' , 0 , 0 , 'showlinkedobjectblock' );
2016-06-24 00:45:35 +02:00
2016-08-25 10:15:26 +02:00
2017-10-07 13:09:31 +02:00
print '<div class="div-table-responsive-no-min">' ;
2018-02-20 16:49:49 +01:00
print '<table class="noborder allwidth" data-block="showLinkedObject" data-element="' . $object -> element . '" data-elementid="' . $object -> id . '" >' ;
2017-09-16 09:13:57 +02:00
2017-10-07 13:09:31 +02:00
print '<tr class="liste_titre">' ;
print '<td>' . $langs -> trans ( " Type " ) . '</td>' ;
print '<td>' . $langs -> trans ( " Ref " ) . '</td>' ;
2019-01-20 23:36:39 +01:00
print '<td class="center"></td>' ;
print '<td class="center">' . $langs -> trans ( " Date " ) . '</td>' ;
print '<td class="right">' . $langs -> trans ( " AmountHTShort " ) . '</td>' ;
print '<td class="right">' . $langs -> trans ( " Status " ) . '</td>' ;
2017-10-07 13:09:31 +02:00
print '<td></td>' ;
print '</tr>' ;
2016-08-25 10:15:26 +02:00
2019-11-08 15:51:54 +01:00
$nboftypesoutput = 0 ;
2016-08-25 10:15:26 +02:00
2021-02-23 22:03:23 +01:00
foreach ( $object -> linkedObjects as $objecttype => $objects ) {
2017-10-07 13:09:31 +02:00
$tplpath = $element = $subelement = $objecttype ;
2016-06-24 00:45:35 +02:00
2018-02-22 15:19:20 +01:00
// to display inport button on tpl
2019-11-08 15:51:54 +01:00
$showImportButton = false ;
if ( ! empty ( $compatibleImportElementsList ) && in_array ( $element , $compatibleImportElementsList )) {
2020-09-07 10:18:17 +02:00
$showImportButton = true ;
2018-02-22 15:19:20 +01:00
}
2015-06-06 12:26:47 +02:00
2019-06-17 15:54:54 +02:00
$regs = array ();
2021-02-23 22:03:23 +01:00
if ( $objecttype != 'supplier_proposal' && preg_match ( '/^([^_]+)_([^_]+)/i' , $objecttype , $regs )) {
2017-10-07 13:09:31 +02:00
$element = $regs [ 1 ];
$subelement = $regs [ 2 ];
$tplpath = $element . '/' . $subelement ;
}
2019-11-08 15:51:54 +01:00
$tplname = 'linkedobjectblock' ;
2016-08-04 09:21:04 +02:00
2017-10-07 13:09:31 +02:00
// To work with non standard path
2019-11-08 15:51:54 +01:00
if ( $objecttype == 'facture' ) {
2017-10-07 13:09:31 +02:00
$tplpath = 'compta/' . $element ;
2021-02-23 22:03:23 +01:00
if ( empty ( $conf -> facture -> enabled )) {
continue ; // Do not show if module disabled
}
2020-05-21 15:05:19 +02:00
} elseif ( $objecttype == 'facturerec' ) {
2017-10-07 13:09:31 +02:00
$tplpath = 'compta/facture' ;
$tplname = 'linkedobjectblockForRec' ;
2021-02-23 22:03:23 +01:00
if ( empty ( $conf -> facture -> enabled )) {
continue ; // Do not show if module disabled
}
2020-05-21 15:05:19 +02:00
} elseif ( $objecttype == 'propal' ) {
2017-10-07 13:09:31 +02:00
$tplpath = 'comm/' . $element ;
2021-02-23 22:03:23 +01:00
if ( empty ( $conf -> propal -> enabled )) {
continue ; // Do not show if module disabled
}
2020-05-21 15:05:19 +02:00
} elseif ( $objecttype == 'supplier_proposal' ) {
2021-02-23 22:03:23 +01:00
if ( empty ( $conf -> supplier_proposal -> enabled )) {
continue ; // Do not show if module disabled
}
2020-05-21 15:05:19 +02:00
} elseif ( $objecttype == 'shipping' || $objecttype == 'shipment' ) {
2017-10-07 13:09:31 +02:00
$tplpath = 'expedition' ;
2021-02-23 22:03:23 +01:00
if ( empty ( $conf -> expedition -> enabled )) {
continue ; // Do not show if module disabled
}
2020-05-21 15:05:19 +02:00
} elseif ( $objecttype == 'reception' ) {
2020-09-07 10:18:17 +02:00
$tplpath = 'reception' ;
2021-02-23 22:03:23 +01:00
if ( empty ( $conf -> reception -> enabled )) {
continue ; // Do not show if module disabled
}
2020-09-07 10:18:17 +02:00
} elseif ( $objecttype == 'delivery' ) {
2020-10-06 13:32:02 +02:00
$tplpath = 'delivery' ;
2021-02-23 22:03:23 +01:00
if ( empty ( $conf -> expedition -> enabled )) {
continue ; // Do not show if module disabled
}
2020-05-21 15:05:19 +02:00
} elseif ( $objecttype == 'invoice_supplier' ) {
2017-10-07 13:09:31 +02:00
$tplpath = 'fourn/facture' ;
2020-05-21 15:05:19 +02:00
} elseif ( $objecttype == 'order_supplier' ) {
2017-10-07 13:09:31 +02:00
$tplpath = 'fourn/commande' ;
2020-05-21 15:05:19 +02:00
} elseif ( $objecttype == 'expensereport' ) {
2017-10-07 13:09:31 +02:00
$tplpath = 'expensereport' ;
2020-05-21 15:05:19 +02:00
} elseif ( $objecttype == 'subscription' ) {
2017-10-07 13:09:31 +02:00
$tplpath = 'adherents' ;
}
2016-08-04 09:21:04 +02:00
2017-10-07 13:09:31 +02:00
global $linkedObjectBlock ;
$linkedObjectBlock = $objects ;
2016-08-04 09:21:04 +02:00
2015-06-06 12:26:47 +02:00
2017-10-07 13:09:31 +02:00
// Output template part (modules that overwrite templates must declare this into descriptor)
2019-11-08 15:51:54 +01:00
$dirtpls = array_merge ( $conf -> modules_parts [ 'tpl' ], array ( '/' . $tplpath . '/tpl' ));
2021-02-23 22:03:23 +01:00
foreach ( $dirtpls as $reldir ) {
if ( $nboftypesoutput == ( $nbofdifferenttypes - 1 )) { // No more type to show after
2017-10-07 13:09:31 +02:00
global $noMoreLinkedObjectBlockAfter ;
2019-11-08 15:51:54 +01:00
$noMoreLinkedObjectBlockAfter = 1 ;
2017-10-07 13:09:31 +02:00
}
2018-04-16 19:56:53 +02:00
2019-11-08 15:51:54 +01:00
$res = @ include dol_buildpath ( $reldir . '/' . $tplname . '.tpl.php' );
2021-02-23 22:03:23 +01:00
if ( $res ) {
2017-10-07 13:09:31 +02:00
$nboftypesoutput ++ ;
break ;
}
}
}
2016-07-07 12:19:20 +02:00
2021-02-23 22:03:23 +01:00
if ( ! $nboftypesoutput ) {
2017-10-07 13:09:31 +02:00
print '<tr><td class="impair opacitymedium" colspan="7">' . $langs -> trans ( " None " ) . '</td></tr>' ;
}
print '</table>' ;
2018-04-16 19:56:53 +02:00
2021-02-23 22:03:23 +01:00
if ( ! empty ( $compatibleImportElementsList )) {
2020-09-07 10:18:17 +02:00
$res = @ include dol_buildpath ( 'core/tpl/ajax/objectlinked_lineimport.tpl.php' );
2018-02-22 15:19:20 +01:00
}
2018-04-16 19:56:53 +02:00
2016-07-07 12:19:20 +02:00
2017-09-16 09:13:57 +02:00
print '</div>' ;
2016-08-04 09:21:04 +02:00
2017-10-07 13:09:31 +02:00
return $nbofdifferenttypes ;
}
}
2015-06-06 12:26:47 +02:00
2017-10-07 13:09:31 +02:00
/**
* Show block with links to link to other objects .
*
* @ param CommonObject $object Object we want to show links to
* @ param array $restrictlinksto Restrict links to some elements , for exemple array ( 'order' ) or array ( 'supplier_order' ) . null or array () if no restriction .
* @ param array $excludelinksto Do not show links of this type , for exemple array ( 'order' ) or array ( 'supplier_order' ) . null or array () if no exclusion .
* @ return string < 0 if KO , > 0 if OK
*/
2020-09-07 10:18:17 +02:00
public function showLinkToObjectBlock ( $object , $restrictlinksto = array (), $excludelinksto = array ())
2017-10-07 13:09:31 +02:00
{
global $conf , $langs , $hookmanager ;
2019-06-17 15:54:54 +02:00
global $bc , $action ;
2015-06-06 15:57:59 +02:00
2019-11-08 15:51:54 +01:00
$linktoelem = '' ;
$linktoelemlist = '' ;
$listofidcompanytoscan = '' ;
2015-06-06 15:57:59 +02:00
2021-02-23 22:03:23 +01:00
if ( ! is_object ( $object -> thirdparty )) {
$object -> fetch_thirdparty ();
}
2015-06-06 15:57:59 +02:00
2019-11-08 15:51:54 +01:00
$possiblelinks = array ();
2021-02-23 22:03:23 +01:00
if ( is_object ( $object -> thirdparty ) && ! empty ( $object -> thirdparty -> id ) && $object -> thirdparty -> id > 0 ) {
2019-11-08 15:51:54 +01:00
$listofidcompanytoscan = $object -> thirdparty -> id ;
2021-02-23 22:03:23 +01:00
if (( $object -> thirdparty -> parent > 0 ) && ! empty ( $conf -> global -> THIRDPARTY_INCLUDE_PARENT_IN_LINKTO )) {
$listofidcompanytoscan .= ',' . $object -> thirdparty -> parent ;
}
if (( $object -> fk_project > 0 ) && ! empty ( $conf -> global -> THIRDPARTY_INCLUDE_PROJECT_THIRDPARY_IN_LINKTO )) {
2017-07-18 10:04:58 +02:00
include_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php' ;
2019-11-08 15:51:54 +01:00
$tmpproject = new Project ( $this -> db );
2017-07-18 10:04:58 +02:00
$tmpproject -> fetch ( $object -> fk_project );
2021-02-23 22:03:23 +01:00
if ( $tmpproject -> socid > 0 && ( $tmpproject -> socid != $object -> thirdparty -> id )) {
$listofidcompanytoscan .= ',' . $tmpproject -> socid ;
}
2017-07-18 10:04:58 +02:00
unset ( $tmpproject );
}
2017-05-18 14:18:59 +02:00
2019-11-08 15:51:54 +01:00
$possiblelinks = array (
2021-03-22 11:30:18 +01:00
'propal' => array ( 'enabled' => $conf -> propal -> enabled , 'perms' => 1 , 'label' => 'LinkToProposal' , 'sql' => " SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref, t.ref_client, t.total_ht FROM " . MAIN_DB_PREFIX . " societe as s, " . MAIN_DB_PREFIX . " propal as t WHERE t.fk_soc = s.rowid AND t.fk_soc IN ( " . $this -> db -> sanitize ( $listofidcompanytoscan ) . ') AND t.entity IN (' . getEntity ( 'propal' ) . ')' ),
'order' => array ( 'enabled' => $conf -> commande -> enabled , 'perms' => 1 , 'label' => 'LinkToOrder' , 'sql' => " SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref, t.ref_client, t.total_ht FROM " . MAIN_DB_PREFIX . " societe as s, " . MAIN_DB_PREFIX . " commande as t WHERE t.fk_soc = s.rowid AND t.fk_soc IN ( " . $this -> db -> sanitize ( $listofidcompanytoscan ) . ') AND t.entity IN (' . getEntity ( 'commande' ) . ')' ),
2021-03-28 06:16:33 +02:00
'invoice' => array ( 'enabled' => $conf -> facture -> enabled , 'perms' => 1 , 'label' => 'LinkToInvoice' , 'sql' => " SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref, t.ref_client, t.total_ht FROM " . MAIN_DB_PREFIX . " societe as s, " . MAIN_DB_PREFIX . " facture as t WHERE t.fk_soc = s.rowid AND t.fk_soc IN ( " . $this -> db -> sanitize ( $listofidcompanytoscan ) . ') AND t.entity IN (' . getEntity ( 'invoice' ) . ')' ),
'invoice_template' => array ( 'enabled' => $conf -> facture -> enabled , 'perms' => 1 , 'label' => 'LinkToTemplateInvoice' , 'sql' => " SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.titre as ref, t.total_ht FROM " . MAIN_DB_PREFIX . " societe as s, " . MAIN_DB_PREFIX . " facture_rec as t WHERE t.fk_soc = s.rowid AND t.fk_soc IN ( " . $this -> db -> sanitize ( $listofidcompanytoscan ) . ') AND t.entity IN (' . getEntity ( 'invoice' ) . ')' ),
avoid sql error with sql_mode=only_full_group_by
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 FROM llx_societe as s, llx_contrat as t, llx_contratdet as td WHERE t.fk_soc = s.rowid AND td.fk_contrat = t.rowid AND t.fk_soc IN (2) AND t.entity IN (1)[DB_ERROR_1140] In aggregated query without GROUP BY, expression #4 of SELECT list contains nonaggregated column 'dolibarrdev.t.rowid'; this is incompatible with sql_mode=only_full_group_by
2021-05-14 18:30:56 +02:00
'contrat' => array (
'enabled' => $conf -> contrat -> enabled ,
'perms' => 1 ,
'label' => 'LinkToContract' ,
2021-05-17 07:11:41 +02:00
'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 FROM " . MAIN_DB_PREFIX . " societe as s, " . MAIN_DB_PREFIX . " contrat as t, " . MAIN_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'
avoid sql error with sql_mode=only_full_group_by
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 FROM llx_societe as s, llx_contrat as t, llx_contratdet as td WHERE t.fk_soc = s.rowid AND td.fk_contrat = t.rowid AND t.fk_soc IN (2) AND t.entity IN (1)[DB_ERROR_1140] In aggregated query without GROUP BY, expression #4 of SELECT list contains nonaggregated column 'dolibarrdev.t.rowid'; this is incompatible with sql_mode=only_full_group_by
2021-05-14 18:30:56 +02:00
),
2021-03-22 11:30:18 +01:00
'fichinter' => array ( 'enabled' => $conf -> ficheinter -> enabled , 'perms' => 1 , 'label' => 'LinkToIntervention' , 'sql' => " SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref FROM " . MAIN_DB_PREFIX . " societe as s, " . MAIN_DB_PREFIX . " fichinter as t WHERE t.fk_soc = s.rowid AND t.fk_soc IN ( " . $this -> db -> sanitize ( $listofidcompanytoscan ) . ') AND t.entity IN (' . getEntity ( 'intervention' ) . ')' ),
'supplier_proposal' => array ( 'enabled' => $conf -> supplier_proposal -> enabled , 'perms' => 1 , 'label' => 'LinkToSupplierProposal' , 'sql' => " SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref, '' as ref_supplier, t.total_ht FROM " . MAIN_DB_PREFIX . " societe as s, " . MAIN_DB_PREFIX . " supplier_proposal as t WHERE t.fk_soc = s.rowid AND t.fk_soc IN ( " . $this -> db -> sanitize ( $listofidcompanytoscan ) . ') AND t.entity IN (' . getEntity ( 'supplier_proposal' ) . ')' ),
'order_supplier' => array ( 'enabled' => $conf -> supplier_order -> enabled , 'perms' => 1 , 'label' => 'LinkToSupplierOrder' , 'sql' => " SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref, t.ref_supplier, t.total_ht FROM " . MAIN_DB_PREFIX . " societe as s, " . MAIN_DB_PREFIX . " commande_fournisseur as t WHERE t.fk_soc = s.rowid AND t.fk_soc IN ( " . $this -> db -> sanitize ( $listofidcompanytoscan ) . ') AND t.entity IN (' . getEntity ( 'commande_fournisseur' ) . ')' ),
'invoice_supplier' => array ( 'enabled' => $conf -> supplier_invoice -> enabled , 'perms' => 1 , 'label' => 'LinkToSupplierInvoice' , 'sql' => " SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref, t.ref_supplier, t.total_ht FROM " . MAIN_DB_PREFIX . " societe as s, " . MAIN_DB_PREFIX . " facture_fourn as t WHERE t.fk_soc = s.rowid AND t.fk_soc IN ( " . $this -> db -> sanitize ( $listofidcompanytoscan ) . ') AND t.entity IN (' . getEntity ( 'facture_fourn' ) . ')' ),
'ticket' => array ( 'enabled' => $conf -> ticket -> enabled , 'perms' => 1 , 'label' => 'LinkToTicket' , 'sql' => " SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref, t.track_id, '0' as total_ht FROM " . MAIN_DB_PREFIX . " societe as s, " . MAIN_DB_PREFIX . " ticket as t WHERE t.fk_soc = s.rowid AND t.fk_soc IN ( " . $this -> db -> sanitize ( $listofidcompanytoscan ) . ') AND t.entity IN (' . getEntity ( 'ticket' ) . ')' )
2017-10-07 13:09:31 +02:00
);
2017-04-04 12:23:44 +02:00
}
2017-05-18 14:18:59 +02:00
2017-04-04 12:23:44 +02:00
// Can complete the possiblelink array
2017-01-21 17:30:35 +01:00
$hookmanager -> initHooks ( array ( 'commonobject' ));
2019-11-08 15:51:54 +01:00
$parameters = array ( 'listofidcompanytoscan' => $listofidcompanytoscan );
2019-03-23 12:04:50 +01:00
2021-02-23 22:03:23 +01:00
if ( ! empty ( $listofidcompanytoscan )) { // If empty, we don't have criteria to scan the object we can link to
2020-09-07 10:18:17 +02:00
$reshook = $hookmanager -> executeHooks ( 'showLinkToObjectBlock' , $parameters , $object , $action ); // Note that $action and $object may have been modified by hook
2019-03-23 12:04:50 +01:00
}
2018-12-27 03:45:30 +01:00
2021-02-23 22:03:23 +01:00
if ( empty ( $reshook )) {
if ( is_array ( $hookmanager -> resArray ) && count ( $hookmanager -> resArray )) {
2019-11-08 15:51:54 +01:00
$possiblelinks = array_merge ( $possiblelinks , $hookmanager -> resArray );
2017-10-07 13:09:31 +02:00
}
2021-02-23 22:03:23 +01:00
} elseif ( $reshook > 0 ) {
if ( is_array ( $hookmanager -> resArray ) && count ( $hookmanager -> resArray )) {
2019-11-08 15:51:54 +01:00
$possiblelinks = $hookmanager -> resArray ;
2017-10-07 13:09:31 +02:00
}
2017-01-21 17:30:35 +01:00
}
2016-08-05 15:30:28 +02:00
2021-02-23 22:03:23 +01:00
foreach ( $possiblelinks as $key => $possiblelink ) {
2016-08-04 11:57:37 +02:00
$num = 0 ;
2015-06-06 15:57:59 +02:00
2021-02-23 22:03:23 +01:00
if ( empty ( $possiblelink [ 'enabled' ])) {
continue ;
}
2016-11-06 15:01:40 +01:00
2021-02-23 22:03:23 +01:00
if ( ! empty ( $possiblelink [ 'perms' ]) && ( empty ( $restrictlinksto ) || in_array ( $key , $restrictlinksto )) && ( empty ( $excludelinksto ) || ! in_array ( $key , $excludelinksto ))) {
2019-11-08 15:51:54 +01:00
print '<div id="' . $key . 'list"' . ( empty ( $conf -> use_javascript_ajax ) ? '' : ' style="display:none"' ) . '>' ;
2016-08-04 11:57:37 +02:00
$sql = $possiblelink [ 'sql' ];
2017-01-21 17:30:35 +01:00
2016-08-04 11:57:37 +02:00
$resqllist = $this -> db -> query ( $sql );
2021-02-23 22:03:23 +01:00
if ( $resqllist ) {
2016-08-04 11:57:37 +02:00
$num = $this -> db -> num_rows ( $resqllist );
$i = 0 ;
2016-08-25 10:15:26 +02:00
2018-12-27 03:45:30 +01:00
print '<br>' ;
print '<form action="' . $_SERVER [ " PHP_SELF " ] . '" method="POST" name="formlinked' . $key . '">' ;
2016-08-04 11:57:37 +02:00
print '<input type="hidden" name="action" value="addlink">' ;
2019-12-01 10:20:11 +01:00
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
2018-12-27 03:45:30 +01:00
print '<input type="hidden" name="id" value="' . $object -> id . '">' ;
2016-08-04 11:57:37 +02:00
print '<input type="hidden" name="addlink" value="' . $key . '">' ;
print '<table class="noborder">' ;
print '<tr class="liste_titre">' ;
print '<td class="nowrap"></td>' ;
2019-11-08 15:51:54 +01:00
print '<td class="center">' . $langs -> trans ( " Ref " ) . '</td>' ;
print '<td class="left">' . $langs -> trans ( " RefCustomer " ) . '</td>' ;
print '<td class="right">' . $langs -> trans ( " AmountHTShort " ) . '</td>' ;
print '<td class="left">' . $langs -> trans ( " Company " ) . '</td>' ;
2016-01-31 18:56:05 +01:00
print '</tr>' ;
2021-02-23 22:03:23 +01:00
while ( $i < $num ) {
2018-07-01 17:48:01 +02:00
$objp = $this -> db -> fetch_object ( $resqllist );
2016-08-25 10:15:26 +02:00
2018-09-26 23:44:27 +02:00
print '<tr class="oddeven">' ;
2019-03-07 20:46:38 +01:00
print '<td class="left">' ;
2021-03-26 17:58:00 +01:00
print '<input type="radio" name="idtolinkto" id="' . $key . '_' . $objp -> rowid . '" value="' . $objp -> rowid . '">' ;
2016-08-04 11:57:37 +02:00
print '</td>' ;
2021-03-26 17:58:00 +01:00
print '<td class="center"><label for="' . $key . '_' . $objp -> rowid . '">' . $objp -> ref . '</label></td>' ;
2021-03-31 13:53:36 +02:00
print '<td>' . ( ! empty ( $objp -> ref_client ) ? $objp -> ref_client : $objp -> ref_supplier ) . '</td>' ;
2021-03-01 03:09:36 +01:00
print '<td class="right">' ;
2021-03-03 12:02:48 +01:00
if ( $possiblelink [ 'label' ] == 'LinkToContract' ) {
$form = new Form ( $this -> db );
2021-03-01 03:09:36 +01:00
print $form -> textwithpicto ( '' , $langs -> trans ( " InformationOnLinkToContract " )) . ' ' ;
}
2021-03-26 17:58:00 +01:00
print '<span class="amount">' . price ( $objp -> total_ht ) . '</span>' ;
print '</td>' ;
2019-11-08 15:51:54 +01:00
print '<td>' . $objp -> name . '</td>' ;
2016-08-04 11:57:37 +02:00
print '</tr>' ;
$i ++ ;
}
print '</table>' ;
2021-06-23 14:38:24 +02:00
print '<div class="center">' ;
print '<input type="submit" class="button valignmiddle marginleftonly marginrightonly" value="' . $langs -> trans ( 'ToLink' ) . '">' ;
if ( empty ( $conf -> use_javascript_ajax )) {
print '<input type="submit" class="button button-cancel marginleftonly marginrightonly" name="cancel" value="' . $langs -> trans ( " Cancel " ) . '"></div>' ;
} else {
print '<input type="submit"; onclick="javascript:jQuery(\'#' . $key . 'list\').toggle(); return false;" class="button button-cancel marginleftonly marginrightonly" name="cancel" value="' . $langs -> trans ( " Cancel " ) . '"></div>' ;
}
2016-08-04 11:57:37 +02:00
print '</form>' ;
$this -> db -> free ( $resqllist );
} else {
dol_print_error ( $this -> db );
2016-01-31 18:56:05 +01:00
}
2016-08-04 11:57:37 +02:00
print '</div>' ;
2016-07-07 12:19:20 +02:00
2016-08-05 15:30:28 +02:00
//$linktoelem.=($linktoelem?' ':'');
2021-02-23 22:03:23 +01:00
if ( $num > 0 ) {
$linktoelemlist .= '<li><a href="#linkto' . $key . '" class="linkto dropdowncloseonclick" rel="' . $key . '">' . $langs -> trans ( $possiblelink [ 'label' ]) . ' (' . $num . ')</a></li>' ;
2021-03-01 20:37:16 +01:00
// } else $linktoelem.=$langs->trans($possiblelink['label']);
} else {
2021-02-23 22:03:23 +01:00
$linktoelemlist .= '<li><span class="linktodisabled">' . $langs -> trans ( $possiblelink [ 'label' ]) . ' (0)</span></li>' ;
}
2015-06-06 15:57:59 +02:00
}
}
2021-02-23 22:03:23 +01:00
if ( $linktoelemlist ) {
2019-11-08 15:51:54 +01:00
$linktoelem = '
2016-10-04 20:52:15 +02:00
< dl class = " dropdown " id = " linktoobjectname " >
2019-01-08 14:05:07 +01:00
' ;
2021-02-23 22:03:23 +01:00
if ( ! empty ( $conf -> use_javascript_ajax )) {
2021-03-26 17:58:00 +01:00
$linktoelem .= '<dt><a href="#linktoobjectname"><span class="fas fa-link paddingrightonly"></span>' . $langs -> trans ( " LinkTo " ) . '...</a></dt>' ;
2021-02-23 22:03:23 +01:00
}
2019-11-08 15:51:54 +01:00
$linktoelem .= ' < dd >
2016-10-04 20:52:15 +02:00
< div class = " multiselectlinkto " >
< ul class = " ulselectedfields " > '.$linktoelemlist.'
</ ul >
</ div >
</ dd >
</ dl > ' ;
2020-05-21 15:05:19 +02:00
} else {
2019-11-08 15:51:54 +01:00
$linktoelem = '' ;
2016-10-04 20:52:15 +02:00
}
2016-08-25 10:15:26 +02:00
2021-02-23 22:03:23 +01:00
if ( ! empty ( $conf -> use_javascript_ajax )) {
2020-09-07 10:18:17 +02:00
print ' <!-- Add js to show linkto box -->
2019-01-20 23:36:39 +01:00
< script >
2016-08-05 15:30:28 +02:00
jQuery ( document ) . ready ( function () {
jQuery ( " .linkto " ) . click ( function () {
2021-06-23 14:38:24 +02:00
console . log ( " We choose to show/hide links for rel= " + jQuery ( this ) . attr ( \ ' rel\ ' ) + " so # " + jQuery ( this ) . attr ( \ ' rel\ ' ) + " list " );
2016-08-05 15:30:28 +02:00
jQuery ( " # " + jQuery ( this ) . attr ( \ ' rel\ ' ) + " list " ) . toggle ();
});
});
</ script >
2019-10-27 11:18:36 +01:00
' ;
2019-01-08 14:05:07 +01:00
}
2015-06-06 15:57:59 +02:00
return $linktoelem ;
2017-10-07 13:09:31 +02:00
}
2010-08-22 17:46:34 +02:00
2017-10-07 13:09:31 +02:00
/**
* Return an html string with a select combo box to choose yes or no
*
* @ param string $htmlname Name of html select field
* @ param string $value Pre - selected value
* @ param int $option 0 return yes / no , 1 return 1 / 0
* @ param bool $disabled true or false
* @ param int $useempty 1 = Add empty line
2020-10-16 13:30:20 +02:00
* @ param int $addjscombo 1 = Add js beautifier on combo box
2021-05-19 14:13:42 +02:00
* @ param string $morecss More CSS
2017-10-07 13:09:31 +02:00
* @ return string See option
*/
2021-05-19 14:13:42 +02:00
public function selectyesno ( $htmlname , $value = '' , $option = 0 , $disabled = false , $useempty = 0 , $addjscombo = 0 , $morecss = '' )
2017-10-07 13:09:31 +02:00
{
global $langs ;
2011-12-29 23:50:02 +01:00
2021-03-01 20:37:16 +01:00
$yes = " yes " ;
$no = " no " ;
2021-02-23 22:03:23 +01:00
if ( $option ) {
2019-11-08 15:51:54 +01:00
$yes = " 1 " ;
$no = " 0 " ;
2017-10-07 13:09:31 +02:00
}
2010-08-22 17:46:34 +02:00
2017-10-07 13:09:31 +02:00
$disabled = ( $disabled ? ' disabled' : '' );
2010-08-22 17:46:34 +02:00
2021-05-19 14:13:42 +02:00
$resultyesno = '<select class="flat width75' . ( $morecss ? ' ' . $morecss : '' ) . '" id="' . $htmlname . '" name="' . $htmlname . '"' . $disabled . '>' . " \n " ;
2021-02-23 22:03:23 +01:00
if ( $useempty ) {
$resultyesno .= '<option value="-1"' . (( $value < 0 ) ? ' selected' : '' ) . '> </option>' . " \n " ;
}
if (( " $value " == 'yes' ) || ( $value == 1 )) {
2017-10-07 13:09:31 +02:00
$resultyesno .= '<option value="' . $yes . '" selected>' . $langs -> trans ( " Yes " ) . '</option>' . " \n " ;
$resultyesno .= '<option value="' . $no . '">' . $langs -> trans ( " No " ) . '</option>' . " \n " ;
2020-05-21 15:05:19 +02:00
} else {
2021-02-23 22:03:23 +01:00
$selected = (( $useempty && $value != '0' && $value != 'no' ) ? '' : ' selected' );
2017-10-07 13:09:31 +02:00
$resultyesno .= '<option value="' . $yes . '">' . $langs -> trans ( " Yes " ) . '</option>' . " \n " ;
$resultyesno .= '<option value="' . $no . '"' . $selected . '>' . $langs -> trans ( " No " ) . '</option>' . " \n " ;
}
$resultyesno .= '</select>' . " \n " ;
2020-10-16 13:30:20 +02:00
if ( $addjscombo ) {
$resultyesno .= ajax_combobox ( $htmlname );
}
2017-10-07 13:09:31 +02:00
return $resultyesno ;
}
2010-08-22 17:46:34 +02:00
2020-09-07 10:18:17 +02:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2017-10-07 13:09:31 +02:00
/**
* Return list of export templates
*
* @ param string $selected Id modele pre - selectionne
* @ param string $htmlname Name of HTML select
* @ param string $type Type of searched templates
* @ param int $useempty Affiche valeur vide dans liste
* @ return void
*/
2020-09-07 10:18:17 +02:00
public function select_export_model ( $selected = '' , $htmlname = 'exportmodelid' , $type = '' , $useempty = 0 )
2017-10-07 13:09:31 +02:00
{
2020-09-07 10:18:17 +02:00
// phpcs:enable
2017-10-07 13:09:31 +02:00
$sql = " SELECT rowid, label " ;
2019-11-08 15:51:54 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " export_model " ;
2020-09-19 21:19:04 +02:00
$sql .= " WHERE type = ' " . $this -> db -> escape ( $type ) . " ' " ;
2019-11-08 15:51:54 +01:00
$sql .= " ORDER BY rowid " ;
2017-10-07 13:09:31 +02:00
$result = $this -> db -> query ( $sql );
2021-02-23 22:03:23 +01:00
if ( $result ) {
2018-12-07 17:28:31 +01:00
print '<select class="flat" id="select_' . $htmlname . '" name="' . $htmlname . '">' ;
2021-02-23 22:03:23 +01:00
if ( $useempty ) {
2017-10-07 13:09:31 +02:00
print '<option value="-1"> </option>' ;
}
2010-08-22 17:46:34 +02:00
2017-10-07 13:09:31 +02:00
$num = $this -> db -> num_rows ( $result );
$i = 0 ;
2021-02-23 22:03:23 +01:00
while ( $i < $num ) {
2017-10-07 13:09:31 +02:00
$obj = $this -> db -> fetch_object ( $result );
2021-02-23 22:03:23 +01:00
if ( $selected == $obj -> rowid ) {
2017-10-07 13:09:31 +02:00
print '<option value="' . $obj -> rowid . '" selected>' ;
2020-05-21 15:05:19 +02:00
} else {
2017-10-07 13:09:31 +02:00
print '<option value="' . $obj -> rowid . '">' ;
}
print $obj -> label ;
print '</option>' ;
$i ++ ;
}
print " </select> " ;
2020-05-21 15:05:19 +02:00
} else {
2017-10-07 13:09:31 +02:00
dol_print_error ( $this -> db );
}
}
2010-08-22 17:46:34 +02:00
2017-10-07 13:09:31 +02:00
/**
* Return a HTML area with the reference of object and a navigation bar for a business object
2017-11-03 17:20:08 +01:00
* Note : To complete search with a particular filter on select , you can set $object -> next_prev_filter set to define SQL criterias .
2017-10-07 13:09:31 +02:00
*
* @ param object $object Object to show .
* @ param string $paramid Name of parameter to use to name the id into the URL next / previous link .
* @ param string $morehtml More html content to output just before the nav bar .
* @ param int $shownav Show Condition ( navigation is shown if value is 1 ) .
2017-11-03 17:20:08 +01:00
* @ param string $fieldid Name of field id into database to use for select next and previous ( we make the select max and min on this field compared to $object -> ref ) . Use 'none' to disable next / prev .
2017-10-07 13:09:31 +02:00
* @ param string $fieldref Name of field ref of object ( object -> ref ) to show or 'none' to not show ref .
* @ param string $morehtmlref More html to show after ref .
* @ param string $moreparam More param to add in nav link url . Must start with '&...' .
* @ param int $nodbprefix Do not include DB prefix to forge table name .
* @ param string $morehtmlleft More html code to show before ref .
* @ param string $morehtmlstatus More html code to show under navigation arrows ( status place ) .
* @ param string $morehtmlright More html code to show after ref .
* @ return string Portion HTML with ref + navigation buttons
*/
2020-09-07 10:18:17 +02:00
public function showrefnav ( $object , $paramid , $morehtml = '' , $shownav = 1 , $fieldid = 'rowid' , $fieldref = 'ref' , $morehtmlref = '' , $moreparam = '' , $nodbprefix = 0 , $morehtmlleft = '' , $morehtmlstatus = '' , $morehtmlright = '' )
2017-07-12 15:52:58 +02:00
{
2020-04-01 23:15:53 +02:00
global $langs , $conf , $hookmanager , $extralanguages ;
2013-04-24 15:49:43 +02:00
2019-11-08 15:51:54 +01:00
$ret = '' ;
2021-02-23 22:03:23 +01:00
if ( empty ( $fieldid )) {
$fieldid = 'rowid' ;
}
if ( empty ( $fieldref )) {
$fieldref = 'ref' ;
}
2017-06-09 10:12:01 +02:00
2021-03-10 16:31:50 +01:00
// Preparing gender's display if there is one
2021-03-11 18:15:22 +01:00
$addgendertxt = '' ;
2021-03-15 21:03:54 +01:00
if ( ! empty ( $object -> gender )) {
2021-03-10 16:31:50 +01:00
$addgendertxt = ' ' ;
switch ( $object -> gender ) {
case 'man' :
$addgendertxt .= '<i class="fas fa-mars"></i>' ;
break ;
case 'woman' :
$addgendertxt .= '<i class="fas fa-venus"></i>' ;
break ;
case 'other' :
$addgendertxt .= '<i class="fas fa-genderless"></i>' ;
break ;
}
2021-03-11 18:15:22 +01:00
}
2017-06-09 10:12:01 +02:00
2017-10-07 13:09:31 +02:00
// Add where from hooks
2021-02-23 22:03:23 +01:00
if ( is_object ( $hookmanager )) {
2019-11-08 15:51:54 +01:00
$parameters = array ();
$reshook = $hookmanager -> executeHooks ( 'printFieldListWhere' , $parameters , $object ); // Note that $action and $object may have been modified by hook
$object -> next_prev_filter .= $hookmanager -> resPrint ;
2017-10-07 13:09:31 +02:00
}
$previous_ref = $next_ref = '' ;
2021-02-23 22:03:23 +01:00
if ( $shownav ) {
2017-10-07 13:09:31 +02:00
//print "paramid=$paramid,morehtml=$morehtml,shownav=$shownav,$fieldid,$fieldref,$morehtmlref,$moreparam";
2019-11-08 15:51:54 +01:00
$object -> load_previous_next_ref (( isset ( $object -> next_prev_filter ) ? $object -> next_prev_filter : '' ), $fieldid , $nodbprefix );
2017-10-07 13:09:31 +02:00
$navurl = $_SERVER [ " PHP_SELF " ];
// Special case for project/task page
2021-02-23 22:03:23 +01:00
if ( $paramid == 'project_ref' ) {
if ( preg_match ( '/\/tasks\/(task|contact|note|document)\.php/' , $navurl )) { // TODO Remove this when nav with project_ref on task pages are ok
2020-09-07 10:18:17 +02:00
$navurl = preg_replace ( '/\/tasks\/(task|contact|time|note|document)\.php/' , '/tasks.php' , $navurl );
$paramid = 'ref' ;
}
2017-10-07 13:09:31 +02:00
}
2018-01-24 17:29:29 +01:00
// accesskey is for Windows or Linux: ALT + key for chrome, ALT + SHIFT + KEY for firefox
// accesskey is for Mac: CTRL + key for all browsers
2018-12-14 19:29:15 +01:00
$stringforfirstkey = $langs -> trans ( " KeyboardShortcut " );
2021-02-23 22:03:23 +01:00
if ( $conf -> browser -> name == 'chrome' ) {
2018-12-14 19:29:15 +01:00
$stringforfirstkey .= ' ALT +' ;
2021-02-23 22:03:23 +01:00
} elseif ( $conf -> browser -> name == 'firefox' ) {
2018-12-14 19:29:15 +01:00
$stringforfirstkey .= ' ALT + SHIFT +' ;
2020-05-21 15:05:19 +02:00
} else {
2018-12-14 19:29:15 +01:00
$stringforfirstkey .= ' CTL +' ;
2018-12-02 11:29:04 +01:00
}
2018-12-14 19:33:43 +01:00
2019-11-08 15:51:54 +01:00
$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>' ;
$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>' ;
2017-10-07 13:09:31 +02:00
}
2010-08-22 17:46:34 +02:00
2017-10-07 13:09:31 +02:00
//print "xx".$previous_ref."x".$next_ref;
2019-11-08 15:51:54 +01:00
$ret .= '<!-- Start banner content --><div style="vertical-align: middle">' ;
2010-08-22 17:46:34 +02:00
2017-10-07 13:09:31 +02:00
// Right part of banner
2021-02-23 22:03:23 +01:00
if ( $morehtmlright ) {
$ret .= '<div class="inline-block floatleft">' . $morehtmlright . '</div>' ;
}
2016-08-04 09:21:04 +02:00
2021-02-23 22:03:23 +01:00
if ( $previous_ref || $next_ref || $morehtml ) {
2019-11-08 15:51:54 +01:00
$ret .= '<div class="pagination paginationref"><ul class="right">' ;
2017-07-12 15:52:58 +02:00
}
2021-02-23 22:03:23 +01:00
if ( $morehtml ) {
2020-10-13 10:51:51 +02:00
$ret .= '<li class="noborder litext' . (( $shownav && $previous_ref && $next_ref ) ? ' clearbothonsmartphone' : '' ) . '">' . $morehtml . '</li>' ;
2017-10-07 13:09:31 +02:00
}
2021-02-23 22:03:23 +01:00
if ( $shownav && ( $previous_ref || $next_ref )) {
2019-11-08 15:51:54 +01:00
$ret .= '<li class="pagination">' . $previous_ref . '</li>' ;
$ret .= '<li class="pagination">' . $next_ref . '</li>' ;
2017-10-07 13:09:31 +02:00
}
2021-02-23 22:03:23 +01:00
if ( $previous_ref || $next_ref || $morehtml ) {
2019-11-08 15:51:54 +01:00
$ret .= '</ul></div>' ;
2017-10-07 13:09:31 +02:00
}
2018-02-27 22:06:21 +01:00
2019-11-08 15:51:54 +01:00
$parameters = array ();
$reshook = $hookmanager -> executeHooks ( 'moreHtmlStatus' , $parameters , $object ); // Note that $action and $object may have been modified by hook
2021-02-23 22:03:23 +01:00
if ( empty ( $reshook )) {
$morehtmlstatus .= $hookmanager -> resPrint ;
} else {
$morehtmlstatus = $hookmanager -> resPrint ;
}
if ( $morehtmlstatus ) {
$ret .= '<div class="statusref">' . $morehtmlstatus . '</div>' ;
}
2016-11-11 23:17:37 +01:00
2018-03-27 17:36:25 +02:00
$parameters = array ();
$reshook = $hookmanager -> executeHooks ( 'moreHtmlRef' , $parameters , $object ); // Note that $action and $object may have been modified by hook
2021-02-23 22:03:23 +01:00
if ( empty ( $reshook )) {
$morehtmlref .= $hookmanager -> resPrint ;
} elseif ( $reshook > 0 ) {
$morehtmlref = $hookmanager -> resPrint ;
}
2018-03-27 17:36:25 +02:00
2017-10-07 13:09:31 +02:00
// Left part of banner
2021-02-23 22:03:23 +01:00
if ( $morehtmlleft ) {
if ( $conf -> browser -> layout == 'phone' ) {
$ret .= '<!-- morehtmlleft --><div class="floatleft">' . $morehtmlleft . '</div>' ; // class="center" to have photo in middle
} else {
$ret .= '<!-- morehtmlleft --><div class="inline-block floatleft">' . $morehtmlleft . '</div>' ;
}
2016-11-11 23:17:37 +01:00
}
2016-11-27 18:10:01 +01:00
2016-11-11 23:17:37 +01:00
//if ($conf->browser->layout == 'phone') $ret.='<div class="clearboth"></div>';
2020-09-21 12:16:22 +02:00
$ret .= '<div class="inline-block floatleft valignmiddle maxwidth750 marginbottomonly refid' . (( $shownav && ( $previous_ref || $next_ref )) ? ' refidpadding' : '' ) . '">' ;
2016-11-27 18:10:01 +01:00
2016-11-11 23:17:37 +01:00
// For thirdparty, contact, user, member, the ref is the id, so we show something else
2021-02-23 22:03:23 +01:00
if ( $object -> element == 'societe' ) {
2019-11-08 15:51:54 +01:00
$ret .= dol_htmlentities ( $object -> name );
2020-04-01 18:11:28 +02:00
2020-04-01 23:15:53 +02:00
// List of extra languages
$arrayoflangcode = array ();
2021-02-23 22:03:23 +01:00
if ( ! empty ( $conf -> global -> PDF_USE_ALSO_LANGUAGE_CODE )) {
$arrayoflangcode [] = $conf -> global -> PDF_USE_ALSO_LANGUAGE_CODE ;
}
2020-04-01 23:15:53 +02:00
if ( is_array ( $arrayoflangcode ) && count ( $arrayoflangcode )) {
2020-04-10 10:59:32 +02:00
if ( ! is_object ( $extralanguages )) {
2020-04-01 23:15:53 +02:00
include_once DOL_DOCUMENT_ROOT . '/core/class/extralanguages.class.php' ;
$extralanguages = new ExtraLanguages ( $this -> db );
}
$extralanguages -> fetch_name_extralanguages ( 'societe' );
2021-02-23 22:03:23 +01:00
if ( ! empty ( $extralanguages -> attributes [ 'societe' ][ 'name' ])) {
2020-04-01 23:15:53 +02:00
$object -> fetchValuesForExtraLanguages ();
2020-04-01 18:11:28 +02:00
$htmltext = '' ;
// If there is extra languages
2020-04-10 10:59:32 +02:00
foreach ( $arrayoflangcode as $extralangcode ) {
2020-04-21 14:54:30 +02:00
$htmltext .= picto_from_langcode ( $extralangcode , 'class="pictoforlang paddingright"' );
if ( $object -> array_languages [ 'name' ][ $extralangcode ]) {
$htmltext .= $object -> array_languages [ 'name' ][ $extralangcode ];
} else {
$htmltext .= '<span class="opacitymedium">' . $langs -> trans ( " SwitchInEditModeToAddTranslation " ) . '</span>' ;
}
2020-04-01 18:11:28 +02:00
}
2020-04-21 14:54:30 +02:00
$ret .= '<!-- Show translations of name -->' . " \n " ;
2020-04-01 18:11:28 +02:00
$ret .= $this -> textwithpicto ( '' , $htmltext , - 1 , 'language' , 'opacitymedium paddingleft' );
}
}
2021-02-23 22:03:23 +01:00
} elseif ( $object -> element == 'member' ) {
2019-11-08 15:51:54 +01:00
$ret .= $object -> ref . '<br>' ;
$fullname = $object -> getFullName ( $langs );
2018-03-23 23:59:35 +01:00
if ( $object -> morphy == 'mor' && $object -> societe ) {
2021-03-10 16:31:50 +01:00
$ret .= dol_htmlentities ( $object -> societe ) . (( ! empty ( $fullname ) && $object -> societe != $fullname ) ? ' (' . dol_htmlentities ( $fullname ) . $addgendertxt . ')' : '' );
2017-10-09 15:35:08 +02:00
} else {
2021-03-10 16:31:50 +01:00
$ret .= dol_htmlentities ( $fullname ) . $addgendertxt . (( ! empty ( $object -> societe ) && $object -> societe != $fullname ) ? ' (' . dol_htmlentities ( $object -> societe ) . ')' : '' );
2017-10-09 15:35:08 +02:00
}
2021-02-23 22:03:23 +01:00
} elseif ( in_array ( $object -> element , array ( 'contact' , 'user' , 'usergroup' ))) {
2021-03-10 16:31:50 +01:00
$ret .= dol_htmlentities ( $object -> getFullName ( $langs )) . $addgendertxt ;
2021-02-23 22:03:23 +01:00
} elseif ( in_array ( $object -> element , array ( 'action' , 'agenda' ))) {
2019-11-08 15:51:54 +01:00
$ret .= $object -> ref . '<br>' . $object -> label ;
2021-02-23 22:03:23 +01:00
} elseif ( in_array ( $object -> element , array ( 'adherent_type' ))) {
2019-11-08 15:51:54 +01:00
$ret .= $object -> label ;
2021-02-23 22:03:23 +01:00
} elseif ( $object -> element == 'ecm_directories' ) {
2019-11-08 15:51:54 +01:00
$ret .= '' ;
2021-02-23 22:03:23 +01:00
} elseif ( $fieldref != 'none' ) {
2020-02-13 12:36:05 +01:00
$ret .= dol_htmlentities ( $object -> $fieldref );
2017-08-01 18:32:21 +02:00
}
2017-05-18 14:18:59 +02:00
2021-02-23 22:03:23 +01:00
if ( $morehtmlref ) {
2020-01-28 08:55:49 +01:00
// don't add a additional space, when "$morehtmlref" starts with a HTML div tag
2021-02-23 22:03:23 +01:00
if ( substr ( $morehtmlref , 0 , 4 ) != '<div' ) {
2020-02-13 12:36:05 +01:00
$ret .= ' ' ;
2020-01-28 08:55:49 +01:00
}
2020-02-13 12:36:05 +01:00
$ret .= $morehtmlref ;
2016-11-11 23:17:37 +01:00
}
2020-01-28 08:55:49 +01:00
2019-11-08 15:51:54 +01:00
$ret .= '</div>' ;
2016-11-27 18:10:01 +01:00
2019-11-08 15:51:54 +01:00
$ret .= '</div><!-- End banner content -->' ;
2016-08-04 09:21:04 +02:00
2017-10-07 13:09:31 +02:00
return $ret ;
}
/**
2021-05-18 17:24:17 +02:00
* Return HTML code to output a barcode
2017-10-07 13:09:31 +02:00
*
2021-05-18 17:24:17 +02:00
* @ param Object $object Object containing data to retrieve file name
* @ param int $width Width of photo
* @ param string $morecss More CSS on img of barcode
* @ return string HTML code to output barcode
2017-10-07 13:09:31 +02:00
*/
2021-05-18 17:24:17 +02:00
public function showbarcode ( & $object , $width = 100 , $morecss = '' )
2017-10-07 13:09:31 +02:00
{
global $conf ;
//Check if barcode is filled in the card
2021-02-23 22:03:23 +01:00
if ( empty ( $object -> barcode )) {
return '' ;
}
2017-10-07 13:09:31 +02:00
// Complete object if not complete
2021-02-23 22:03:23 +01:00
if ( empty ( $object -> barcode_type_code ) || empty ( $object -> barcode_type_coder )) {
2017-10-07 13:09:31 +02:00
$result = $object -> fetch_barcode ();
//Check if fetch_barcode() failed
2021-02-23 22:03:23 +01:00
if ( $result < 1 ) {
return '<!-- ErrorFetchBarcode -->' ;
}
2017-10-07 13:09:31 +02:00
}
// Barcode image
2019-11-08 15:51:54 +01:00
$url = DOL_URL_ROOT . '/viewimage.php?modulepart=barcode&generator=' . urlencode ( $object -> barcode_type_coder ) . '&code=' . urlencode ( $object -> barcode ) . '&encoding=' . urlencode ( $object -> barcode_type_code );
$out = '<!-- url barcode = ' . $url . ' -->' ;
2021-05-18 17:24:17 +02:00
$out .= '<img src="' . $url . '"' . ( $morecss ? ' class="' . $morecss . '"' : '' ) . '>' ;
2017-10-07 13:09:31 +02:00
return $out ;
}
/**
* Return HTML code to output a photo
*
* @ param string $modulepart Key to define module concerned ( 'societe' , 'userphoto' , 'memberphoto' )
* @ param object $object Object containing data to retrieve file name
* @ param int $width Width of photo
* @ param int $height Height of photo ( auto if 0 )
* @ param int $caneditfield Add edit fields
* @ param string $cssclass CSS name to use on img for photo
* @ param string $imagesize 'mini' , 'small' or '' ( original )
* @ param int $addlinktofullsize Add link to fullsize image
* @ param int $cache 1 = Accept to use image in cache
2020-11-22 01:47:17 +01:00
* @ param string $forcecapture '' , 'user' or 'environment' . Force parameter capture on HTML input file element to ask a smartphone to allow to open camera to take photo . Auto if '' .
* @ param int $noexternsourceoverwrite No overwrite image with extern source ( like 'gravatar' or other module )
2017-10-07 13:09:31 +02:00
* @ return string HTML code to output photo
*/
2020-11-22 01:47:17 +01:00
public static function showphoto ( $modulepart , $object , $width = 100 , $height = 0 , $caneditfield = 0 , $cssclass = 'photowithmargin' , $imagesize = '' , $addlinktofullsize = 1 , $cache = 0 , $forcecapture = '' , $noexternsourceoverwrite = 0 )
2017-10-07 13:09:31 +02:00
{
2019-11-08 15:51:54 +01:00
global $conf , $langs ;
2017-10-07 13:09:31 +02:00
2019-11-08 15:51:54 +01:00
$entity = ( ! empty ( $object -> entity ) ? $object -> entity : $conf -> entity );
$id = ( ! empty ( $object -> id ) ? $object -> id : $object -> rowid );
2017-10-07 13:09:31 +02:00
2021-03-01 20:37:16 +01:00
$ret = '' ;
$dir = '' ;
$file = '' ;
$originalfile = '' ;
$altfile = '' ;
$email = '' ;
$capture = '' ;
2021-02-23 22:03:23 +01:00
if ( $modulepart == 'societe' ) {
2019-11-08 15:51:54 +01:00
$dir = $conf -> societe -> multidir_output [ $entity ];
2020-12-10 18:13:30 +01:00
if ( ! empty ( $object -> logo )) {
2021-05-24 19:46:19 +02:00
if ( dolIsAllowedForPreview ( $object -> logo )) {
if (( string ) $imagesize == 'mini' ) {
$file = get_exdir ( 0 , 0 , 0 , 0 , $object , 'thirdparty' ) . 'logos/' . getImageFileNameForSize ( $object -> logo , '_mini' ); // getImageFileNameForSize include the thumbs
} elseif (( string ) $imagesize == 'small' ) {
$file = get_exdir ( 0 , 0 , 0 , 0 , $object , 'thirdparty' ) . 'logos/' . getImageFileNameForSize ( $object -> logo , '_small' );
} else {
$file = get_exdir ( 0 , 0 , 0 , 0 , $object , 'thirdparty' ) . 'logos/' . $object -> logo ;
}
$originalfile = get_exdir ( 0 , 0 , 0 , 0 , $object , 'thirdparty' ) . 'logos/' . $object -> logo ;
2021-02-23 22:03:23 +01:00
}
2017-10-07 13:09:31 +02:00
}
2019-11-08 15:51:54 +01:00
$email = $object -> email ;
2020-12-10 18:13:30 +01:00
} elseif ( $modulepart == 'contact' ) {
2019-11-08 15:51:54 +01:00
$dir = $conf -> societe -> multidir_output [ $entity ] . '/contact' ;
2021-02-23 22:03:23 +01:00
if ( ! empty ( $object -> photo )) {
2021-05-25 22:09:58 +02:00
if ( dolIsAllowedForPreview ( $object -> photo )) {
2021-05-24 19:46:19 +02:00
if (( string ) $imagesize == 'mini' ) {
$file = get_exdir ( 0 , 0 , 0 , 0 , $object , 'contact' ) . 'photos/' . getImageFileNameForSize ( $object -> photo , '_mini' );
} elseif (( string ) $imagesize == 'small' ) {
$file = get_exdir ( 0 , 0 , 0 , 0 , $object , 'contact' ) . 'photos/' . getImageFileNameForSize ( $object -> photo , '_small' );
} else {
$file = get_exdir ( 0 , 0 , 0 , 0 , $object , 'contact' ) . 'photos/' . $object -> photo ;
}
$originalfile = get_exdir ( 0 , 0 , 0 , 0 , $object , 'contact' ) . 'photos/' . $object -> photo ;
2021-02-23 22:03:23 +01:00
}
2017-10-07 13:09:31 +02:00
}
2019-11-08 15:51:54 +01:00
$email = $object -> email ;
$capture = 'user' ;
2020-12-10 18:13:30 +01:00
} elseif ( $modulepart == 'userphoto' ) {
2019-11-08 15:51:54 +01:00
$dir = $conf -> user -> dir_output ;
2021-02-23 22:03:23 +01:00
if ( ! empty ( $object -> photo )) {
2021-05-25 22:09:58 +02:00
if ( dolIsAllowedForPreview ( $object -> photo )) {
2021-05-24 19:46:19 +02:00
if (( string ) $imagesize == 'mini' ) {
$file = get_exdir ( 0 , 0 , 0 , 0 , $object , 'user' ) . getImageFileNameForSize ( $object -> photo , '_mini' );
} elseif (( string ) $imagesize == 'small' ) {
$file = get_exdir ( 0 , 0 , 0 , 0 , $object , 'user' ) . getImageFileNameForSize ( $object -> photo , '_small' );
} else {
$file = get_exdir ( 0 , 0 , 0 , 0 , $object , 'user' ) . $object -> photo ;
}
$originalfile = get_exdir ( 0 , 0 , 0 , 0 , $object , 'user' ) . $object -> photo ;
2021-02-23 22:03:23 +01:00
}
2017-10-07 13:09:31 +02:00
}
2021-02-23 22:03:23 +01:00
if ( ! empty ( $conf -> global -> MAIN_OLD_IMAGE_LINKS )) {
$altfile = $object -> id . " .jpg " ; // For backward compatibility
}
2019-11-08 15:51:54 +01:00
$email = $object -> email ;
$capture = 'user' ;
2020-12-10 18:13:30 +01:00
} elseif ( $modulepart == 'memberphoto' ) {
2019-11-08 15:51:54 +01:00
$dir = $conf -> adherent -> dir_output ;
2021-02-23 22:03:23 +01:00
if ( ! empty ( $object -> photo )) {
2021-05-25 22:09:58 +02:00
if ( dolIsAllowedForPreview ( $object -> photo )) {
2021-05-24 19:46:19 +02:00
if (( string ) $imagesize == 'mini' ) {
$file = get_exdir ( 0 , 0 , 0 , 0 , $object , 'member' ) . 'photos/' . getImageFileNameForSize ( $object -> photo , '_mini' );
} elseif (( string ) $imagesize == 'small' ) {
$file = get_exdir ( 0 , 0 , 0 , 0 , $object , 'member' ) . 'photos/' . getImageFileNameForSize ( $object -> photo , '_small' );
} else {
$file = get_exdir ( 0 , 0 , 0 , 0 , $object , 'member' ) . 'photos/' . $object -> photo ;
}
$originalfile = get_exdir ( 0 , 0 , 0 , 0 , $object , 'member' ) . 'photos/' . $object -> photo ;
2021-02-23 22:03:23 +01:00
}
2017-10-07 13:09:31 +02:00
}
2021-02-23 22:03:23 +01:00
if ( ! empty ( $conf -> global -> MAIN_OLD_IMAGE_LINKS )) {
$altfile = $object -> id . " .jpg " ; // For backward compatibility
}
2019-11-08 15:51:54 +01:00
$email = $object -> email ;
$capture = 'user' ;
2020-05-21 15:05:19 +02:00
} else {
2017-10-07 13:09:31 +02:00
// Generic case to show photos
2019-11-08 15:51:54 +01:00
$dir = $conf -> $modulepart -> dir_output ;
2021-02-23 22:03:23 +01:00
if ( ! empty ( $object -> photo )) {
2021-05-25 22:09:58 +02:00
if ( dolIsAllowedForPreview ( $object -> photo )) {
2021-05-24 19:46:19 +02:00
if (( string ) $imagesize == 'mini' ) {
$file = get_exdir ( $id , 2 , 0 , 0 , $object , $modulepart ) . 'photos/' . getImageFileNameForSize ( $object -> photo , '_mini' );
} elseif (( string ) $imagesize == 'small' ) {
$file = get_exdir ( $id , 2 , 0 , 0 , $object , $modulepart ) . 'photos/' . getImageFileNameForSize ( $object -> photo , '_small' );
} else {
$file = get_exdir ( $id , 2 , 0 , 0 , $object , $modulepart ) . 'photos/' . $object -> photo ;
}
$originalfile = get_exdir ( $id , 2 , 0 , 0 , $object , $modulepart ) . 'photos/' . $object -> photo ;
2021-02-23 22:03:23 +01:00
}
2017-10-07 13:09:31 +02:00
}
2021-02-23 22:03:23 +01:00
if ( ! empty ( $conf -> global -> MAIN_OLD_IMAGE_LINKS )) {
$altfile = $object -> id . " .jpg " ; // For backward compatibility
}
2019-11-08 15:51:54 +01:00
$email = $object -> email ;
2017-08-01 18:32:21 +02:00
}
2017-05-18 14:18:59 +02:00
2021-02-23 22:03:23 +01:00
if ( $forcecapture ) {
$capture = $forcecapture ;
}
2017-05-18 14:18:59 +02:00
2021-02-23 22:03:23 +01:00
if ( $dir ) {
if ( $file && file_exists ( $dir . " / " . $file )) {
2020-11-22 01:47:17 +01:00
if ( $addlinktofullsize ) {
2019-12-16 13:06:25 +01:00
$urladvanced = getAdvancedPreviewUrl ( $modulepart , $originalfile , 0 , '&entity=' . $entity );
2021-02-23 22:03:23 +01:00
if ( $urladvanced ) {
$ret .= '<a href="' . $urladvanced . '">' ;
} else {
$ret .= '<a href="' . DOL_URL_ROOT . '/viewimage.php?modulepart=' . $modulepart . '&entity=' . $entity . '&file=' . urlencode ( $originalfile ) . '&cache=' . $cache . '">' ;
}
2017-10-07 13:09:31 +02:00
}
2019-12-16 13:06:25 +01:00
$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 . '">' ;
2021-02-23 22:03:23 +01:00
if ( $addlinktofullsize ) {
$ret .= '</a>' ;
}
2020-11-22 01:47:17 +01:00
} elseif ( $altfile && file_exists ( $dir . " / " . $altfile )) {
if ( $addlinktofullsize ) {
2019-12-16 13:06:25 +01:00
$urladvanced = getAdvancedPreviewUrl ( $modulepart , $originalfile , 0 , '&entity=' . $entity );
2021-02-23 22:03:23 +01:00
if ( $urladvanced ) {
$ret .= '<a href="' . $urladvanced . '">' ;
} else {
$ret .= '<a href="' . DOL_URL_ROOT . '/viewimage.php?modulepart=' . $modulepart . '&entity=' . $entity . '&file=' . urlencode ( $originalfile ) . '&cache=' . $cache . '">' ;
}
2017-10-07 13:09:31 +02:00
}
2019-12-16 13:06:25 +01:00
$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 . '">' ;
2021-02-23 22:03:23 +01:00
if ( $addlinktofullsize ) {
$ret .= '</a>' ;
}
2020-05-21 15:05:19 +02:00
} else {
2019-12-16 13:06:25 +01:00
$nophoto = '/public/theme/common/nophoto.png' ;
2021-04-01 12:27:02 +02:00
$defaultimg = 'identicon' ; // For gravatar
if ( in_array ( $modulepart , array ( 'societe' , 'userphoto' , 'contact' , 'memberphoto' ))) { // For modules that need a special image when photo not found
if ( $modulepart == 'societe' || ( $modulepart == 'memberphoto' && strpos ( $object -> morphy , 'mor' )) !== false ) {
$nophoto = 'company' ;
2020-05-21 15:05:19 +02:00
} else {
2019-12-16 13:06:25 +01:00
$nophoto = '/public/theme/common/user_anonymous.png' ;
2021-05-27 22:28:59 +02:00
if ( ! empty ( $object -> gender ) && $object -> gender == 'man' ) {
2021-02-23 22:03:23 +01:00
$nophoto = '/public/theme/common/user_man.png' ;
}
2021-05-27 22:28:59 +02:00
if ( ! empty ( $object -> gender ) && $object -> gender == 'woman' ) {
2021-02-23 22:03:23 +01:00
$nophoto = '/public/theme/common/user_woman.png' ;
}
2019-10-23 21:00:29 +02:00
}
2015-05-30 19:50:07 +02:00
}
2020-11-22 01:47:17 +01:00
if ( ! empty ( $conf -> gravatar -> enabled ) && $email && empty ( $noexternsourceoverwrite )) {
// see https://gravatar.com/site/implement/images/php/
2019-12-16 13:06:25 +01:00
$ret .= '<!-- Put link to gravatar -->' ;
$ret .= '<img class="photo' . $modulepart . ( $cssclass ? ' ' . $cssclass : '' ) . '" alt="Gravatar avatar" title="' . $email . ' Gravatar avatar" ' . ( $width ? ' width="' . $width . '"' : '' ) . ( $height ? ' height="' . $height . '"' : '' ) . ' src="https://www.gravatar.com/avatar/' . md5 ( strtolower ( trim ( $email ))) . '?s=' . $width . '&d=' . $defaultimg . '">' ; // gravatar need md5 hash
2020-05-21 15:05:19 +02:00
} else {
2021-04-01 12:27:02 +02:00
if ( $nophoto == 'company' ) {
$ret .= '<div class="photo' . $modulepart . ( $cssclass ? ' ' . $cssclass : '' ) . '" alt="No photo" ' . ( $width ? ' width="' . $width . '"' : '' ) . ( $height ? ' height="' . $height . '"' : '' ) . '">' . img_picto ( '' , 'company' ) . '</div>' ;
} else {
$ret .= '<img class="photo' . $modulepart . ( $cssclass ? ' ' . $cssclass : '' ) . '" alt="No photo" ' . ( $width ? ' width="' . $width . '"' : '' ) . ( $height ? ' height="' . $height . '"' : '' ) . ' src="' . DOL_URL_ROOT . $nophoto . '">' ;
}
2017-10-07 13:09:31 +02:00
}
}
2015-05-30 02:17:05 +02:00
2021-02-23 22:03:23 +01:00
if ( $caneditfield ) {
if ( $object -> photo ) {
$ret .= " <br> \n " ;
}
2019-12-16 13:06:25 +01:00
$ret .= '<table class="nobordernopadding centpercent">' ;
2021-02-23 22:03:23 +01:00
if ( $object -> photo ) {
$ret .= '<tr><td><input type="checkbox" class="flat photodelete" name="deletephoto" id="photodelete"> ' . $langs -> trans ( " Delete " ) . '<br><br></td></tr>' ;
}
2019-12-16 13:06:25 +01:00
$ret .= '<tr><td class="tdoverflow"><input type="file" class="flat maxwidth200onsmartphone" name="photo" id="photoinput" accept="image/*"' . ( $capture ? ' capture="' . $capture . '"' : '' ) . '></td></tr>' ;
$ret .= '</table>' ;
2017-10-07 13:09:31 +02:00
}
2021-02-23 22:03:23 +01:00
} else {
dol_print_error ( '' , 'Call of showphoto with wrong parameters modulepart=' . $modulepart );
}
2010-08-22 17:46:34 +02:00
2017-10-07 13:09:31 +02:00
return $ret ;
}
2010-11-18 23:17:44 +01:00
2020-09-07 10:18:17 +02:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2017-10-07 13:09:31 +02:00
/**
* Return select list of groups
*
* @ param string $selected Id group preselected
* @ param string $htmlname Field name in form
* @ param int $show_empty 0 = liste sans valeur nulle , 1 = ajoute valeur inconnue
* @ param string $exclude Array list of groups id to exclude
* @ param int $disabled If select list must be disabled
* @ param string $include Array list of groups id to include
* @ param int $enableonly Array list of groups id to be enabled . All other must be disabled
2018-06-25 09:19:45 +02:00
* @ param string $force_entity '0' or Ids of environment to force
2018-06-29 11:48:54 +02:00
* @ param bool $multiple add [] in the name of element and add 'multiple' attribut ( not working with ajax_autocompleter )
2020-05-10 21:07:49 +02:00
* @ param string $morecss More css to add to html component
2017-10-07 13:09:31 +02:00
* @ return string
2019-03-19 13:14:44 +01:00
* @ see select_dolusers ()
2017-10-07 13:09:31 +02:00
*/
2020-09-07 10:18:17 +02:00
public function select_dolgroups ( $selected = '' , $htmlname = 'groupid' , $show_empty = 0 , $exclude = '' , $disabled = 0 , $include = '' , $enableonly = '' , $force_entity = '0' , $multiple = false , $morecss = '' )
2017-10-07 13:09:31 +02:00
{
2020-09-07 10:18:17 +02:00
// phpcs:enable
2019-11-08 15:51:54 +01:00
global $conf , $user , $langs ;
2010-11-08 20:04:52 +01:00
2017-10-07 13:09:31 +02:00
// Permettre l'exclusion de groupes
2021-02-23 22:03:23 +01:00
if ( is_array ( $exclude )) {
2021-03-22 12:47:23 +01:00
$excludeGroups = implode ( " , " , $exclude );
2021-02-23 22:03:23 +01:00
}
2017-10-07 13:09:31 +02:00
// Permettre l'inclusion de groupes
2021-02-23 22:03:23 +01:00
if ( is_array ( $include )) {
2021-03-22 12:47:23 +01:00
$includeGroups = implode ( " , " , $include );
2021-02-23 22:03:23 +01:00
}
2010-11-08 20:04:52 +01:00
2021-02-23 22:03:23 +01:00
if ( ! is_array ( $selected )) {
$selected = array ( $selected );
}
2010-11-08 20:04:52 +01:00
2019-11-08 15:51:54 +01:00
$out = '' ;
2014-12-20 13:06:08 +01:00
2017-10-07 13:09:31 +02:00
// On recherche les groupes
$sql = " SELECT ug.rowid, ug.nom as name " ;
2021-02-23 22:03:23 +01:00
if ( ! empty ( $conf -> multicompany -> enabled ) && $conf -> entity == 1 && $user -> admin && ! $user -> entity ) {
2019-11-08 15:51:54 +01:00
$sql .= " , e.label " ;
2017-10-07 13:09:31 +02:00
}
2019-11-08 15:51:54 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " usergroup as ug " ;
2021-02-23 22:03:23 +01:00
if ( ! empty ( $conf -> multicompany -> enabled ) && $conf -> entity == 1 && $user -> admin && ! $user -> entity ) {
2019-11-08 15:51:54 +01:00
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " entity as e ON e.rowid=ug.entity " ;
2021-02-23 22:03:23 +01:00
if ( $force_entity ) {
$sql .= " WHERE ug.entity IN (0, " . $force_entity . " ) " ;
} else {
$sql .= " WHERE ug.entity IS NOT NULL " ;
}
2020-05-21 15:05:19 +02:00
} else {
2020-09-19 21:19:04 +02:00
$sql .= " WHERE ug.entity IN (0, " . $conf -> entity . " ) " ;
2017-10-07 13:09:31 +02:00
}
2021-02-23 22:03:23 +01:00
if ( is_array ( $exclude ) && $excludeGroups ) {
2021-03-22 12:47:23 +01:00
$sql .= " AND ug.rowid NOT IN ( " . $this -> db -> sanitize ( $excludeGroups ) . " ) " ;
2021-02-23 22:03:23 +01:00
}
if ( is_array ( $include ) && $includeGroups ) {
2021-03-22 12:47:23 +01:00
$sql .= " AND ug.rowid IN ( " . $this -> db -> sanitize ( $includeGroups ) . " ) " ;
2021-02-23 22:03:23 +01:00
}
2019-11-08 15:51:54 +01:00
$sql .= " ORDER BY ug.nom ASC " ;
2014-12-22 03:14:22 +01:00
2017-10-07 13:09:31 +02:00
dol_syslog ( get_class ( $this ) . " ::select_dolgroups " , LOG_DEBUG );
2019-11-08 15:51:54 +01:00
$resql = $this -> db -> query ( $sql );
2021-02-23 22:03:23 +01:00
if ( $resql ) {
2017-10-07 13:09:31 +02:00
// Enhance with select2
2019-11-08 15:51:54 +01:00
include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php' ;
2021-02-23 22:03:23 +01:00
$out .= ajax_combobox ( $htmlname );
2011-08-31 16:55:54 +02:00
2020-05-10 21:07:49 +02:00
$out .= '<select class="flat minwidth200' . ( $morecss ? ' ' . $morecss : '' ) . '" id="' . $htmlname . '" name="' . $htmlname . ( $multiple ? '[]' : '' ) . '" ' . ( $multiple ? 'multiple' : '' ) . ' ' . ( $disabled ? ' disabled' : '' ) . '>' ;
2010-11-08 20:04:52 +01:00
2017-10-07 13:09:31 +02:00
$num = $this -> db -> num_rows ( $resql );
$i = 0 ;
2021-02-23 22:03:23 +01:00
if ( $num ) {
if ( $show_empty && ! $multiple ) {
$out .= '<option value="-1"' . ( in_array ( - 1 , $selected ) ? ' selected' : '' ) . '> </option>' . " \n " ;
}
2010-11-18 23:17:44 +01:00
2021-02-23 22:03:23 +01:00
while ( $i < $num ) {
2017-10-07 13:09:31 +02:00
$obj = $this -> db -> fetch_object ( $resql );
2019-11-08 15:51:54 +01:00
$disableline = 0 ;
2021-02-23 22:03:23 +01:00
if ( is_array ( $enableonly ) && count ( $enableonly ) && ! in_array ( $obj -> rowid , $enableonly )) {
$disableline = 1 ;
}
2010-11-18 23:17:44 +01:00
2019-11-08 15:51:54 +01:00
$out .= '<option value="' . $obj -> rowid . '"' ;
2021-02-23 22:03:23 +01:00
if ( $disableline ) {
$out .= ' disabled' ;
}
if (( is_object ( $selected [ 0 ]) && $selected [ 0 ] -> id == $obj -> rowid ) || ( ! is_object ( $selected [ 0 ]) && in_array ( $obj -> rowid , $selected ))) {
2019-11-08 15:51:54 +01:00
$out .= ' selected' ;
2017-10-07 13:09:31 +02:00
}
2019-11-08 15:51:54 +01:00
$out .= '>' ;
2010-11-08 20:04:52 +01:00
2019-11-08 15:51:54 +01:00
$out .= $obj -> name ;
2021-02-23 22:03:23 +01:00
if ( ! empty ( $conf -> multicompany -> enabled ) && empty ( $conf -> global -> MULTICOMPANY_TRANSVERSE_MODE ) && $conf -> entity == 1 ) {
2019-11-08 15:51:54 +01:00
$out .= " ( " . $obj -> label . " ) " ;
2017-10-07 13:09:31 +02:00
}
2010-11-18 23:17:44 +01:00
2019-11-08 15:51:54 +01:00
$out .= '</option>' ;
2017-10-07 13:09:31 +02:00
$i ++ ;
}
2020-05-21 15:05:19 +02:00
} else {
2021-02-23 22:03:23 +01:00
if ( $show_empty ) {
$out .= '<option value="-1"' . ( in_array ( - 1 , $selected ) ? ' selected' : '' ) . '></option>' . " \n " ;
}
2019-11-08 15:51:54 +01:00
$out .= '<option value="" disabled>' . $langs -> trans ( " NoUserGroupDefined " ) . '</option>' ;
2017-10-07 13:09:31 +02:00
}
2019-11-08 15:51:54 +01:00
$out .= '</select>' ;
2020-05-21 15:05:19 +02:00
} else {
2017-10-07 13:09:31 +02:00
dol_print_error ( $this -> db );
}
2017-05-25 08:48:59 +02:00
2017-10-07 13:09:31 +02:00
return $out ;
}
2017-05-25 08:48:59 +02:00
2017-03-28 17:12:15 +02:00
2017-10-07 13:09:31 +02:00
/**
* Return HTML to show the search and clear seach button
*
* @ return string
*/
2020-09-07 10:18:17 +02:00
public function showFilterButtons ()
2017-10-07 13:09:31 +02:00
{
2021-06-15 01:18:17 +02:00
$out = '<div class="nowraponall">' ;
2019-11-08 15:51:54 +01:00
$out .= '<button type="submit" class="liste_titre button_search" name="button_search_x" value="x"><span class="fa fa-search"></span></button>' ;
$out .= '<button type="submit" class="liste_titre button_removefilter" name="button_removefilter_x" value="x"><span class="fa fa-remove"></span></button>' ;
$out .= '</div>' ;
2017-05-25 08:48:59 +02:00
2017-10-07 13:09:31 +02:00
return $out ;
}
/**
2020-09-08 04:24:27 +02:00
* Return HTML to show the search and clear search button
2017-10-07 13:09:31 +02:00
*
* @ param string $cssclass CSS class
* @ param int $calljsfunction 0 = default . 1 = call function initCheckForSelect () after changing status of checkboxes
2020-09-08 21:27:28 +02:00
* @ param string $massactionname Mass action button name that will launch an action on the selected items
2017-10-07 13:09:31 +02:00
* @ return string
*/
2020-09-08 21:27:28 +02:00
public function showCheckAddButtons ( $cssclass = 'checkforaction' , $calljsfunction = 0 , $massactionname = " massaction " )
2017-10-07 13:09:31 +02:00
{
global $conf , $langs ;
2019-11-08 15:51:54 +01:00
$out = '' ;
2020-10-01 18:08:46 +02:00
2021-02-23 22:03:23 +01:00
if ( ! empty ( $conf -> use_javascript_ajax )) {
$out .= '<div class="inline-block checkallactions"><input type="checkbox" id="' . $cssclass . 's" name="' . $cssclass . 's" class="checkallactions"></div>' ;
}
2019-11-08 15:51:54 +01:00
$out .= ' < script >
2017-03-28 17:12:15 +02:00
$ ( document ) . ready ( function () {
2020-09-07 10:18:17 +02:00
$ ( " #' . $cssclass .'s " ) . click ( function () {
2017-03-28 17:12:15 +02:00
if ( $ ( this ) . is ( \ ' : checked\ ' )){
2020-11-01 14:34:29 +01:00
console . log ( " We check all '. $cssclass .' and trigger the change method " );
2018-09-04 11:54:13 +02:00
$ ( " .'. $cssclass .' " ) . prop ( \ ' checked\ ' , true ) . trigger ( \ ' change\ ' );
2017-03-28 17:12:15 +02:00
}
else
{
console . log ( " We uncheck all " );
2018-09-04 11:54:13 +02:00
$ ( " .'. $cssclass .' " ) . prop ( \ ' checked\ ' , false ) . trigger ( \ ' change\ ' );
2017-03-28 17:12:15 +02:00
} ' . " \n " ;
2021-02-23 22:03:23 +01:00
if ( $calljsfunction ) {
$out .= 'if (typeof initCheckForSelect == \'function\') { initCheckForSelect(0, "' . $massactionname . '", "' . $cssclass . '"); } else { console.log("No function initCheckForSelect found. Call won\'t be done."); }' ;
}
2019-11-08 15:51:54 +01:00
$out .= ' });
2020-10-01 18:08:46 +02:00
$ ( " .' . $cssclass .' " ) . change ( function () {
$ ( this ) . closest ( " tr " ) . toggleClass ( " highlight " , this . checked );
});
});
</ script > ' ;
2017-03-28 17:12:15 +02:00
2017-10-07 13:09:31 +02:00
return $out ;
}
/**
* Return HTML to show the search and clear seach button
*
* @ param int $addcheckuncheckall Add the check all / uncheck all checkbox ( use javascript ) and code to manage this
* @ param string $cssclass CSS class
* @ param int $calljsfunction 0 = default . 1 = call function initCheckForSelect () after changing status of checkboxes
2020-09-07 10:18:17 +02:00
* @ param string $massactionname Mass action name
2017-10-07 13:09:31 +02:00
* @ return string
*/
2020-09-07 10:18:17 +02:00
public function showFilterAndCheckAddButtons ( $addcheckuncheckall = 0 , $cssclass = 'checkforaction' , $calljsfunction = 0 , $massactionname = " massaction " )
2017-10-07 13:09:31 +02:00
{
2019-11-08 15:51:54 +01:00
$out = $this -> showFilterButtons ();
2021-02-23 22:03:23 +01:00
if ( $addcheckuncheckall ) {
2020-05-02 06:42:12 +02:00
$out .= $this -> showCheckAddButtons ( $cssclass , $calljsfunction , $massactionname );
2017-10-07 13:09:31 +02:00
}
return $out ;
}
2017-08-01 01:25:30 +02:00
2017-06-15 11:08:53 +02:00
/**
2018-10-30 14:27:14 +01:00
* Return HTML to show the select of expense categories
2017-08-01 01:25:30 +02:00
*
2017-06-15 11:08:53 +02:00
* @ param string $selected preselected category
2017-10-07 13:09:31 +02:00
* @ param string $htmlname name of HTML select list
* @ param integer $useempty 1 = Add empty line
* @ param array $excludeid id to exclude
* @ param string $target htmlname of target select to bind event
* @ param int $default_selected default category to select if fk_c_type_fees change = EX_KME
* @ param array $params param to give
2020-09-08 11:51:36 +02:00
* @ param int $info_admin Show the tooltip help picto to setup list
2017-10-07 13:09:31 +02:00
* @ return string
2017-06-15 11:08:53 +02:00
*/
2020-09-08 11:51:36 +02:00
public function selectExpenseCategories ( $selected = '' , $htmlname = 'fk_c_exp_tax_cat' , $useempty = 0 , $excludeid = array (), $target = '' , $default_selected = 0 , $params = array (), $info_admin = 1 )
2017-06-15 11:08:53 +02:00
{
2020-09-08 04:24:27 +02:00
global $db , $langs , $user ;
2017-08-01 01:25:30 +02:00
2020-09-07 10:18:17 +02:00
$out = '' ;
$sql = 'SELECT rowid, label FROM ' . MAIN_DB_PREFIX . 'c_exp_tax_cat WHERE active = 1' ;
2019-11-08 15:51:54 +01:00
$sql .= ' AND entity IN (0,' . getEntity ( 'exp_tax_cat' ) . ')' ;
2021-02-23 22:03:23 +01:00
if ( ! empty ( $excludeid )) {
2021-03-22 12:00:41 +01:00
$sql .= ' AND rowid NOT IN (' . $this -> db -> sanitize ( implode ( ',' , $excludeid )) . ')' ;
2021-02-23 22:03:23 +01:00
}
2019-11-08 15:51:54 +01:00
$sql .= ' ORDER BY label' ;
2017-08-01 01:25:30 +02:00
2017-06-15 11:08:53 +02:00
$resql = $db -> query ( $sql );
2021-02-23 22:03:23 +01:00
if ( $resql ) {
2020-09-08 12:00:14 +02:00
$out = '<select id="select_' . $htmlname . '" name="' . $htmlname . '" class="' . $htmlname . ' flat minwidth75imp maxwidth200">' ;
2021-02-23 22:03:23 +01:00
if ( $useempty ) {
$out .= '<option value="0"> </option>' ;
}
2017-08-01 01:25:30 +02:00
2021-02-23 22:03:23 +01:00
while ( $obj = $db -> fetch_object ( $resql )) {
2019-11-08 15:51:54 +01:00
$out .= '<option ' . ( $selected == $obj -> rowid ? 'selected="selected"' : '' ) . ' value="' . $obj -> rowid . '">' . $langs -> trans ( $obj -> label ) . '</option>' ;
2017-06-15 11:08:53 +02:00
}
2019-11-08 15:51:54 +01:00
$out .= '</select>' ;
2020-09-08 11:51:36 +02:00
$out .= ajax_combobox ( 'select_' . $htmlname );
2021-02-23 22:03:23 +01:00
if ( ! empty ( $htmlname ) && $user -> admin && $info_admin ) {
$out .= ' ' . info_admin ( $langs -> trans ( " YouCanChangeValuesForThisListFromDictionarySetup " ), 1 );
}
2017-08-01 01:25:30 +02:00
2021-02-23 22:03:23 +01:00
if ( ! empty ( $target )) {
2017-06-15 11:08:53 +02:00
$sql = " SELECT c.id FROM " . MAIN_DB_PREFIX . " c_type_fees as c WHERE c.code = 'EX_KME' AND c.active = 1 " ;
$resql = $db -> query ( $sql );
2021-02-23 22:03:23 +01:00
if ( $resql ) {
if ( $db -> num_rows ( $resql ) > 0 ) {
2017-06-15 11:08:53 +02:00
$obj = $db -> fetch_object ( $resql );
2019-11-08 15:51:54 +01:00
$out .= ' < script >
2017-06-15 11:08:53 +02:00
$ ( function () {
$ ( " select[name='. $target .'] " ) . on ( " change " , function () {
var current_val = $ ( this ) . val ();
if ( current_val == '.$obj->id.' ) { ' ;
2021-02-23 22:03:23 +01:00
if ( ! empty ( $default_selected ) || ! empty ( $selected )) {
$out .= '$("select[name=' . $htmlname . ']").val("' . ( $default_selected > 0 ? $default_selected : $selected ) . '");' ;
}
2017-08-01 01:25:30 +02:00
2019-11-08 15:51:54 +01:00
$out .= '
2017-06-15 11:08:53 +02:00
$ ( " select[name='. $htmlname .'] " ) . change ();
}
});
$ ( " select[name='. $htmlname .'] " ) . change ( function () {
2017-08-01 01:25:30 +02:00
2017-06-15 11:08:53 +02:00
if ( $ ( " select[name='. $target .'] " ) . val () == '.$obj->id.' ) {
// get price of kilometer to fill the unit price
$ . ajax ({
method : " POST " ,
dataType : " json " ,
2021-06-17 03:37:52 +02:00
data : { fk_c_exp_tax_cat : $ ( this ) . val (), token : \ '' . currentToken () . ' \ ' },
url : " '.(DOL_URL_ROOT.'/expensereport/ajax/ajaxik.php?'. $params ).' " ,
2017-06-15 11:08:53 +02:00
}) . done ( function ( data , textStatus , jqXHR ) {
console . log ( data );
if ( typeof data . up != " undefined " ) {
$ ( " input[name=value_unit] " ) . val ( data . up );
$ ( " select[name='. $htmlname .'] " ) . attr ( " title " , data . title );
} else {
$ ( " input[name=value_unit] " ) . val ( " " );
$ ( " select[name='. $htmlname .'] " ) . attr ( " title " , " " );
}
});
}
});
});
</ script > ' ;
}
2017-08-01 01:25:30 +02:00
}
2017-06-15 11:08:53 +02:00
}
2020-05-21 15:05:19 +02:00
} else {
2017-06-15 11:08:53 +02:00
dol_print_error ( $db );
}
2017-08-01 01:25:30 +02:00
2017-06-15 11:08:53 +02:00
return $out ;
}
2017-08-01 01:25:30 +02:00
2017-06-15 11:08:53 +02:00
/**
* Return HTML to show the select ranges of expense range
2017-08-01 01:25:30 +02:00
*
2017-06-15 11:08:53 +02:00
* @ param string $selected preselected category
2017-10-07 13:09:31 +02:00
* @ param string $htmlname name of HTML select list
* @ param integer $useempty 1 = Add empty line
* @ return string
2017-06-15 11:08:53 +02:00
*/
2020-09-07 10:18:17 +02:00
public function selectExpenseRanges ( $selected = '' , $htmlname = 'fk_range' , $useempty = 0 )
2017-06-15 11:08:53 +02:00
{
2019-11-08 15:51:54 +01:00
global $db , $conf , $langs ;
2017-08-01 01:25:30 +02:00
2020-09-07 10:18:17 +02:00
$out = '' ;
2017-07-07 10:22:37 +02:00
$sql = 'SELECT rowid, range_ik FROM ' . MAIN_DB_PREFIX . 'c_exp_tax_range' ;
2019-11-08 15:51:54 +01:00
$sql .= ' WHERE entity = ' . $conf -> entity . ' AND active = 1' ;
2017-08-01 01:25:30 +02:00
2017-06-15 11:08:53 +02:00
$resql = $db -> query ( $sql );
2021-02-23 22:03:23 +01:00
if ( $resql ) {
2018-12-07 17:28:31 +01:00
$out = '<select id="select_' . $htmlname . '" name="' . $htmlname . '" class="' . $htmlname . ' flat minwidth75imp">' ;
2021-02-23 22:03:23 +01:00
if ( $useempty ) {
$out .= '<option value="0"></option>' ;
}
2017-08-01 01:25:30 +02:00
2021-02-23 22:03:23 +01:00
while ( $obj = $db -> fetch_object ( $resql )) {
2019-11-08 15:51:54 +01:00
$out .= '<option ' . ( $selected == $obj -> rowid ? 'selected="selected"' : '' ) . ' value="' . $obj -> rowid . '">' . price ( $obj -> range_ik , 0 , $langs , 1 , 0 ) . '</option>' ;
2017-06-15 11:08:53 +02:00
}
2019-11-08 15:51:54 +01:00
$out .= '</select>' ;
2020-05-21 15:05:19 +02:00
} else {
2017-06-15 11:08:53 +02:00
dol_print_error ( $db );
}
2017-08-01 01:25:30 +02:00
2017-06-15 11:08:53 +02:00
return $out ;
}
2017-08-01 01:25:30 +02:00
2017-06-15 11:08:53 +02:00
/**
* Return HTML to show a select of expense
2017-08-01 01:25:30 +02:00
*
2017-06-15 11:08:53 +02:00
* @ param string $selected preselected category
2017-10-07 13:09:31 +02:00
* @ param string $htmlname name of HTML select list
* @ param integer $useempty 1 = Add empty choice
2017-06-15 11:08:53 +02:00
* @ param integer $allchoice 1 = Add all choice
* @ param integer $useid 0 = use 'code' as key , 1 = use 'id' as key
2017-10-07 13:09:31 +02:00
* @ return string
2017-06-15 11:08:53 +02:00
*/
2020-09-07 10:18:17 +02:00
public function selectExpense ( $selected = '' , $htmlname = 'fk_c_type_fees' , $useempty = 0 , $allchoice = 1 , $useid = 0 )
2017-06-15 11:08:53 +02:00
{
2019-11-08 15:51:54 +01:00
global $db , $langs ;
2010-05-03 10:22:35 +02:00
2020-09-07 10:18:17 +02:00
$out = '' ;
2017-06-15 11:08:53 +02:00
$sql = 'SELECT id, code, label FROM ' . MAIN_DB_PREFIX . 'c_type_fees' ;
2019-11-08 15:51:54 +01:00
$sql .= ' WHERE active = 1' ;
2017-08-01 01:25:30 +02:00
2017-06-15 11:08:53 +02:00
$resql = $db -> query ( $sql );
2021-02-23 22:03:23 +01:00
if ( $resql ) {
2018-12-07 17:28:31 +01:00
$out = '<select id="select_' . $htmlname . '" name="' . $htmlname . '" class="' . $htmlname . ' flat minwidth75imp">' ;
2021-02-23 22:03:23 +01:00
if ( $useempty ) {
$out .= '<option value="0"></option>' ;
}
if ( $allchoice ) {
$out .= '<option value="-1">' . $langs -> trans ( 'AllExpenseReport' ) . '</option>' ;
}
2017-08-01 01:25:30 +02:00
2017-06-15 11:08:53 +02:00
$field = 'code' ;
2021-02-23 22:03:23 +01:00
if ( $useid ) {
$field = 'id' ;
}
2017-08-01 01:25:30 +02:00
2021-02-23 22:03:23 +01:00
while ( $obj = $db -> fetch_object ( $resql )) {
2017-06-15 11:08:53 +02:00
$key = $langs -> trans ( $obj -> code );
2019-11-08 15:51:54 +01:00
$out .= '<option ' . ( $selected == $obj -> { $field } ? 'selected="selected"' : '' ) . ' value="' . $obj -> { $field } . '">' . ( $key != $obj -> code ? $key : $obj -> label ) . '</option>' ;
2017-06-15 11:08:53 +02:00
}
2019-11-08 15:51:54 +01:00
$out .= '</select>' ;
2020-05-21 15:05:19 +02:00
} else {
2017-06-15 11:08:53 +02:00
dol_print_error ( $db );
}
2017-08-01 01:25:30 +02:00
2020-09-07 10:18:17 +02:00
return $out ;
}
2020-01-02 14:59:53 +01:00
/**
* Output a combo list with invoices qualified for a third party
*
* @ param int $socid Id third party ( - 1 = all , 0 = only projects not linked to a third party , id = projects not linked or linked to third party id )
* @ param int $selected Id invoice preselected
* @ param string $htmlname Name of HTML select
* @ param int $maxlength Maximum length of label
* @ param int $option_only Return only html options lines without the select tag
* @ param string $show_empty Add an empty line ( '1' or string to show for empty line )
* @ param int $discard_closed Discard closed projects ( 0 = Keep , 1 = hide completely , 2 = Disable )
2020-09-07 10:18:17 +02:00
* @ param int $forcefocus Force focus on field ( works with javascript only )
* @ param int $disabled Disabled
2020-01-02 14:59:53 +01:00
* @ param string $morecss More css added to the select component
* @ param string $projectsListId '' = Automatic filter on project allowed . List of id = Filter on project ids .
* @ param string $showproject 'all' = Show project info , '' = Hide project info
* @ param User $usertofilter User object to use for filtering
* @ return int Nbr of project if OK , < 0 if KO
*/
2020-09-07 10:18:17 +02:00
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 )
2020-01-02 14:59:53 +01:00
{
2020-01-18 16:17:07 +01:00
global $user , $conf , $langs ;
2020-01-02 14:59:53 +01:00
require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php' ;
2021-02-23 22:03:23 +01:00
if ( is_null ( $usertofilter )) {
2020-01-02 14:59:53 +01:00
$usertofilter = $user ;
}
2020-01-18 16:17:07 +01:00
$out = '' ;
2020-01-02 14:59:53 +01:00
$hideunselectables = false ;
2021-02-23 22:03:23 +01:00
if ( ! empty ( $conf -> global -> PROJECT_HIDE_UNSELECTABLES )) {
$hideunselectables = true ;
}
2020-01-02 14:59:53 +01:00
2021-02-23 22:03:23 +01:00
if ( empty ( $projectsListId )) {
if ( empty ( $usertofilter -> rights -> projet -> all -> lire )) {
2020-01-18 16:17:07 +01:00
$projectstatic = new Project ( $this -> db );
2020-01-02 14:59:53 +01:00
$projectsListId = $projectstatic -> getProjectsAuthorizedForUser ( $usertofilter , 0 , 1 );
}
}
// Search all projects
2021-05-17 18:34:23 +02:00
$sql = " SELECT f.rowid, f.ref as fref, 'nolabel' as flabel, p.rowid as pid, f.ref,
p . title , p . fk_soc , p . fk_statut , p . public , " ;
2020-01-18 16:17:07 +01:00
$sql .= ' s.nom as name' ;
$sql .= ' FROM ' . MAIN_DB_PREFIX . 'projet as p' ;
$sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'societe as s ON s.rowid = p.fk_soc,' ;
$sql .= ' ' . MAIN_DB_PREFIX . 'facture as f' ;
$sql .= " WHERE p.entity IN ( " . getEntity ( 'project' ) . " ) " ;
$sql .= " AND f.fk_projet = p.rowid AND f.fk_statut=0 " ; //Brouillons seulement
2021-03-22 12:47:23 +01:00
//if ($projectsListId) $sql.= " AND p.rowid IN (".$this->db->sanitize($projectsListId).")";
2020-01-02 14:59:53 +01:00
//if ($socid == 0) $sql.= " AND (p.fk_soc=0 OR p.fk_soc IS NULL)";
//if ($socid > 0) $sql.= " AND (p.fk_soc=".$socid." OR p.fk_soc IS NULL)";
2021-05-18 12:44:56 +02:00
$sql .= " ORDER BY p.ref, f.ref ASC " ;
2020-01-02 14:59:53 +01:00
2020-01-18 16:17:07 +01:00
$resql = $this -> db -> query ( $sql );
2021-02-23 22:03:23 +01:00
if ( $resql ) {
2020-01-02 14:59:53 +01:00
// Use select2 selector
2021-02-23 22:03:23 +01:00
if ( ! empty ( $conf -> use_javascript_ajax )) {
2020-01-18 16:17:07 +01:00
include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php' ;
2021-02-23 22:03:23 +01:00
$comboenhancement = ajax_combobox ( $htmlname , '' , 0 , $forcefocus );
2020-09-07 10:18:17 +02:00
$out .= $comboenhancement ;
$morecss = 'minwidth200imp maxwidth500' ;
2020-01-02 14:59:53 +01:00
}
if ( empty ( $option_only )) {
2020-01-18 16:17:07 +01:00
$out .= '<select class="valignmiddle flat' . ( $morecss ? ' ' . $morecss : '' ) . '"' . ( $disabled ? ' disabled="disabled"' : '' ) . ' id="' . $htmlname . '" name="' . $htmlname . '">' ;
2020-01-02 14:59:53 +01:00
}
2020-01-18 16:17:07 +01:00
if ( ! empty ( $show_empty )) {
$out .= '<option value="0" class="optiongrey">' ;
2021-02-23 22:03:23 +01:00
if ( ! is_numeric ( $show_empty )) {
$out .= $show_empty ;
} else {
$out .= ' ' ;
}
2020-01-18 16:17:07 +01:00
$out .= '</option>' ;
2020-01-02 14:59:53 +01:00
}
$num = $this -> db -> num_rows ( $resql );
$i = 0 ;
2021-02-23 22:03:23 +01:00
if ( $num ) {
while ( $i < $num ) {
2020-01-02 14:59:53 +01:00
$obj = $this -> db -> fetch_object ( $resql );
// 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.
2021-02-23 22:03:23 +01:00
if ( $socid > 0 && ( empty ( $obj -> fk_soc ) || $obj -> fk_soc == $socid ) && empty ( $usertofilter -> rights -> societe -> lire )) {
2020-01-02 14:59:53 +01:00
// Do nothing
2020-05-21 15:05:19 +02:00
} else {
2021-02-23 22:03:23 +01:00
if ( $discard_closed == 1 && $obj -> fk_statut == Project :: STATUS_CLOSED ) {
2020-01-02 14:59:53 +01:00
$i ++ ;
continue ;
}
$labeltoshow = '' ;
2021-02-23 22:03:23 +01:00
if ( $showproject == 'all' ) {
2020-01-18 16:17:07 +01:00
$labeltoshow .= dol_trunc ( $obj -> ref , 18 ); // Invoice ref
2021-02-23 22:03:23 +01:00
if ( $obj -> name ) {
$labeltoshow .= ' - ' . $obj -> name ; // Soc name
}
2020-01-02 14:59:53 +01:00
2020-01-18 16:17:07 +01:00
$disabled = 0 ;
2021-02-23 22:03:23 +01:00
if ( $obj -> fk_statut == Project :: STATUS_DRAFT ) {
2020-01-18 16:17:07 +01:00
$disabled = 1 ;
$labeltoshow .= ' - ' . $langs -> trans ( " Draft " );
2021-02-23 22:03:23 +01:00
} elseif ( $obj -> fk_statut == Project :: STATUS_CLOSED ) {
if ( $discard_closed == 2 ) {
$disabled = 1 ;
}
2020-01-18 16:17:07 +01:00
$labeltoshow .= ' - ' . $langs -> trans ( " Closed " );
2021-02-23 22:03:23 +01:00
} elseif ( $socid > 0 && ( ! empty ( $obj -> fk_soc ) && $obj -> fk_soc != $socid )) {
2020-01-18 16:17:07 +01:00
$disabled = 1 ;
$labeltoshow .= ' - ' . $langs -> trans ( " LinkedToAnotherCompany " );
2020-01-02 14:59:53 +01:00
}
}
2021-02-23 22:03:23 +01:00
if ( ! empty ( $selected ) && $selected == $obj -> rowid ) {
2020-01-18 16:17:07 +01:00
$out .= '<option value="' . $obj -> rowid . '" selected' ;
2020-01-02 14:59:53 +01:00
//if ($disabled) $out.=' disabled'; // with select2, field can't be preselected if disabled
2020-01-18 16:17:07 +01:00
$out .= '>' . $labeltoshow . '</option>' ;
2020-05-21 15:05:19 +02:00
} else {
2021-02-23 22:03:23 +01:00
if ( $hideunselectables && $disabled && ( $selected != $obj -> rowid )) {
2020-01-18 16:17:07 +01:00
$resultat = '' ;
2020-05-21 15:05:19 +02:00
} else {
2020-01-18 16:17:07 +01:00
$resultat = '<option value="' . $obj -> rowid . '"' ;
2021-02-23 22:03:23 +01:00
if ( $disabled ) {
$resultat .= ' disabled' ;
}
2020-01-02 14:59:53 +01:00
//if ($obj->public) $labeltoshow.=' ('.$langs->trans("Public").')';
//else $labeltoshow.=' ('.$langs->trans("Private").')';
2020-01-18 16:17:07 +01:00
$resultat .= '>' ;
$resultat .= $labeltoshow ;
$resultat .= '</option>' ;
2020-01-02 14:59:53 +01:00
}
2020-01-18 16:17:07 +01:00
$out .= $resultat ;
2020-01-02 14:59:53 +01:00
}
}
$i ++ ;
}
}
if ( empty ( $option_only )) {
2020-01-18 16:17:07 +01:00
$out .= '</select>' ;
2020-01-02 14:59:53 +01:00
}
print $out ;
$this -> db -> free ( $resql );
return $num ;
2020-05-21 15:05:19 +02:00
} else {
2020-01-02 14:59:53 +01:00
dol_print_error ( $this -> db );
return - 1 ;
}
}
2020-01-26 22:02:31 +01:00
/**
* Output the component to make advanced search criteries
*
2020-01-31 14:53:47 +01:00
* @ param array $arrayofcriterias Array of available search criterias . Example : array ( $object -> element => $object -> fields , 'otherfamily' => otherarrayoffields , ... )
* @ param array $search_component_params Array of selected search criterias
* @ param array $arrayofinputfieldsalreadyoutput Array of input fields already inform . The component will not generate a hidden input field if it is in this list .
* @ return string HTML component for advanced search
2020-01-26 22:02:31 +01:00
*/
2020-01-31 18:03:45 +01:00
public function searchComponent ( $arrayofcriterias , $search_component_params , $arrayofinputfieldsalreadyoutput = array ())
2020-01-26 22:02:31 +01:00
{
2020-09-08 04:24:27 +02:00
global $langs ;
2020-01-26 22:02:31 +01:00
2020-01-30 23:28:50 +01:00
$ret = '' ;
2020-01-26 22:02:31 +01:00
2020-01-30 23:28:50 +01:00
$ret .= '<div class="nowrap centpercent">' ;
//$ret .= '<button type="submit" class="liste_titre button_removefilter" name="button_removefilter_x" value="x"><span class="fa fa-remove"></span></button>';
2020-01-31 14:53:47 +01:00
$ret .= '<a href="#" class="dropdownsearch-toggle unsetcolor paddingright">' ;
2020-01-30 23:28:50 +01:00
$ret .= '<span class="fas fa-filter linkobject boxfilter" title="Filter" id="idsubimgproductdistribution"></span>' ;
$ret .= $langs -> trans ( " Filters " );
$ret .= '</a>' ;
2020-01-31 14:53:47 +01:00
//$ret .= '<button type="submit" class="liste_titre button_search paddingleftonly" name="button_search_x" value="x"><span class="fa fa-search"></span></button>';
2020-03-12 12:01:40 +01:00
$ret .= '<div name="search_component_params" class="search_component_params inline-block minwidth500 maxwidth300onsmartphone valignmiddle">' ;
$texttoshow = '<div class="opacitymedium inline-block search_component_searchtext">' . $langs -> trans ( " Search " ) . '</div>' ;
$ret .= '<div class="search_component inline-block valignmiddle">' . $texttoshow . '</div>' ;
2020-01-31 14:53:47 +01:00
$ret .= '</div>' ;
2020-03-12 12:01:40 +01:00
$ret .= '<input type="hidden" name="search_component_params_hidden" class="search_component_params_hidden" value="' . GETPOST ( " search_component_params_hidden " ) . '">' ;
// For compatibility with forms that show themself the search criteria in addition of this component, we output the fields
2020-02-13 12:36:05 +01:00
foreach ( $arrayofcriterias as $criterias ) {
2020-09-07 10:18:17 +02:00
foreach ( $criterias as $criteriafamilykey => $criteriafamilyval ) {
2021-02-23 22:03:23 +01:00
if ( in_array ( 'search_' . $criteriafamilykey , $arrayofinputfieldsalreadyoutput )) {
continue ;
}
if ( in_array ( $criteriafamilykey , array ( 'rowid' , 'ref_ext' , 'entity' , 'extraparams' ))) {
continue ;
}
2020-09-07 10:18:17 +02:00
if ( in_array ( $criteriafamilyval [ 'type' ], array ( 'date' , 'datetime' , 'timestamp' ))) {
$ret .= '<input type="hidden" name="search_' . $criteriafamilykey . '_start">' ;
$ret .= '<input type="hidden" name="search_' . $criteriafamilykey . '_startyear">' ;
$ret .= '<input type="hidden" name="search_' . $criteriafamilykey . '_startmonth">' ;
$ret .= '<input type="hidden" name="search_' . $criteriafamilykey . '_startday">' ;
$ret .= '<input type="hidden" name="search_' . $criteriafamilykey . '_end">' ;
$ret .= '<input type="hidden" name="search_' . $criteriafamilykey . '_endyear">' ;
$ret .= '<input type="hidden" name="search_' . $criteriafamilykey . '_endmonth">' ;
$ret .= '<input type="hidden" name="search_' . $criteriafamilykey . '_endday">' ;
} else {
2020-01-31 19:01:31 +01:00
$ret .= '<input type="hidden" name="search_' . $criteriafamilykey . '">' ;
2020-09-07 10:18:17 +02:00
}
}
2020-01-31 14:53:47 +01:00
}
2020-09-07 10:18:17 +02:00
$ret .= '</div>' ;
2020-01-26 22:02:31 +01:00
return $ret ;
}
2020-08-25 17:26:32 +02:00
2020-08-29 04:55:24 +02:00
/**
2020-08-30 03:00:35 +02:00
* selectModelMail
2020-08-29 04:55:24 +02:00
*
2020-12-08 20:32:37 +01:00
* @ param string $prefix Prefix
* @ param string $modelType Model type
* @ param int $default 1 = Show also Default mail template
* @ param int $addjscombo Add js combobox
* @ return string HTML select string
2020-08-29 04:55:24 +02:00
*/
2020-12-08 20:32:37 +01:00
public function selectModelMail ( $prefix , $modelType = '' , $default = 0 , $addjscombo = 0 )
2020-09-08 21:27:28 +02:00
{
global $langs , $db , $user ;
2020-08-25 17:26:32 +02:00
2020-09-08 21:27:28 +02:00
$retstring = '' ;
2020-08-25 17:26:32 +02:00
2020-09-08 21:27:28 +02:00
$TModels = array ();
2020-08-25 17:26:32 +02:00
2020-09-08 21:27:28 +02:00
include_once DOL_DOCUMENT_ROOT . '/core/class/html.formmail.class.php' ;
$formmail = new FormMail ( $db );
2020-09-14 04:30:04 +02:00
$result = $formmail -> fetchAllEMailTemplate ( $modelType , $user , $langs );
2020-08-25 17:26:32 +02:00
2021-02-23 22:03:23 +01:00
if ( $default ) {
$TModels [ 0 ] = $langs -> trans ( 'DefaultMailModel' );
}
2020-09-08 21:27:28 +02:00
if ( $result > 0 ) {
2020-09-14 04:30:04 +02:00
foreach ( $formmail -> lines_model as $model ) {
2020-09-08 21:27:28 +02:00
$TModels [ $model -> id ] = $model -> label ;
}
}
2020-08-25 17:26:32 +02:00
2020-09-08 21:27:28 +02:00
$retstring .= '<select class="flat" id="select_' . $prefix . 'model_mail" name="' . $prefix . 'model_mail">' ;
2020-08-25 17:26:32 +02:00
2021-02-23 22:03:23 +01:00
foreach ( $TModels as $id_model => $label_model ) {
2020-09-08 21:27:28 +02:00
$retstring .= '<option value="' . $id_model . '"' ;
$retstring .= " > " . $label_model . " </option> " ;
}
2020-08-25 17:26:32 +02:00
2020-09-08 21:27:28 +02:00
$retstring .= " </select> " ;
2020-08-25 17:26:32 +02:00
2021-02-23 22:03:23 +01:00
if ( $addjscombo ) {
$retstring .= ajax_combobox ( 'select_' . $prefix . 'model_mail' );
}
2020-12-08 20:32:37 +01:00
2020-09-08 21:27:28 +02:00
return $retstring ;
}
2010-05-03 10:22:35 +02:00
}