2010-05-03 10:43:32 +02:00
< ? php
/* Copyright ( c ) 2002 - 2007 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
2012-01-27 15:17:36 +01:00
* Copyright ( C ) 2004 - 2012 Laurent Destailleur < eldy @ users . sourceforge . net >
2010-05-03 10:43:32 +02:00
* 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 - 2012 Regis Houssin < regis . houssin @ inodbox . com >
2010-05-03 10:43:32 +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 >
2019-03-31 19:26:40 +02:00
* Copyright ( C ) 2019 Thibault FOUCART < support @ ptibogxiv . net >
2024-02-28 23:42:23 +01:00
* Copyright ( C ) 2024 Frédéric France < frederic . france @ free . fr >
2024-03-21 22:26:56 +01:00
* Copyright ( C ) 2024 MDW < mdeweerd @ users . noreply . github . com >
2010-05-03 10:43:32 +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:43:32 +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:43:32 +02:00
*/
/**
2010-06-08 01:52:43 +02:00
* \file htdocs / core / class / html . formother . class . php
2010-11-22 10:18:53 +01:00
* \ingroup core
2024-01-13 19:48:20 +01:00
* \brief Fichier de la class des functions predefinie de composants html autre
2010-05-03 10:43:32 +02:00
*/
/**
2024-01-13 19:48:20 +01:00
* Class permettant la generation de composants html autre
2012-01-27 15:17:36 +01:00
* Only common components are here .
2010-05-03 10:43:32 +02:00
*/
class FormOther
{
2024-09-28 12:09:35 +02:00
/**
* @ var DoliDB
*/
2020-10-07 15:01:28 +02:00
private $db ;
2018-09-02 16:45:03 +02:00
2020-10-07 15:01:28 +02:00
/**
2018-08-23 11:34:55 +02:00
* @ var string Error code ( or message )
*/
public $error ;
2010-05-03 10:43:32 +02:00
2020-10-07 15:01:28 +02:00
/**
* Constructor
*
* @ param DoliDB $db Database handler
*/
public function __construct ( $db )
{
$this -> db = $db ;
}
2021-05-12 09:07:36 +02:00
/**
2021-12-19 17:05:57 +01:00
* Return the HTML code for scanner tool .
2021-05-12 09:27:04 +02:00
* This must be called into an existing < form >
2021-05-12 09:07:36 +02:00
*
2021-12-19 17:05:57 +01:00
* @ param string $jstoexecuteonadd Name of javascript function to call once the barcode scanning session is complete and user has click on " Add " .
2021-12-19 03:45:36 +01:00
* @ param string $mode 'all' ( both product and lot barcode ) or 'product' ( product barcode only ) or 'lot' ( lot number only )
2023-10-10 19:34:54 +02:00
* @ param int $warehouseselect 0 ( disable warehouse select ) or 1 ( enable warehouse select )
2021-05-12 09:07:36 +02:00
* @ return string HTML component
*/
2023-10-10 19:34:54 +02:00
public function getHTMLScannerForm ( $jstoexecuteonadd = 'barcodescannerjs' , $mode = 'all' , $warehouseselect = 0 )
2021-05-12 09:07:36 +02:00
{
global $langs ;
$out = '' ;
$out .= '<!-- Popup for mass barcode scanning -->' . " \n " ;
$out .= '<div class="div-for-modal-topright" style="padding: 15px">' ;
2021-12-19 17:05:57 +01:00
$out .= '<center>' . img_picto ( '' , 'barcode' , 'class="pictofixedwidth"' ) . '<strong>Barcode scanner tool...</strong></center><br>' ;
2021-05-12 09:07:36 +02:00
2021-12-19 03:45:36 +01:00
if ( $mode == 'product' ) {
$out .= '<input type="hidden" name="barcodemode" value="barcodeforproduct" id="barcodeforproduct">' ;
} elseif ( $mode == 'lot' ) {
$out .= '<input type="hidden" name="barcodemode" value="barcodeforlotserial" id="barcodeforlotserial">' ;
} else { // $mode = 'all'
$out .= '<input type="radio" name="barcodemode" value="barcodeforautodetect" id="barcodeforautodetect" checked="checked"> <label for="barcodeforautodetect">Autodetect if we scan a product barcode or a lot/serial barcode</label><br>' ;
$out .= '<input type="radio" name="barcodemode" value="barcodeforproduct" id="barcodeforproduct"> <label for="barcodeforproduct">Scan a product barcode</label><br>' ;
$out .= '<input type="radio" name="barcodemode" value="barcodeforlotserial" id="barcodeforlotserial"> <label for="barcodeforlotserial">Scan a product lot or serial number</label><br>' ;
}
2021-10-21 18:08:20 +02:00
$stringaddbarcode = $langs -> trans ( " QtyToAddAfterBarcodeScan " , " tmphtml " );
2021-10-21 18:07:54 +02:00
$htmltoreplaceby = '<select name="selectaddorreplace"><option selected value="add">' . $langs -> trans ( " Add " ) . '</option><option value="replace">' . $langs -> trans ( " ToReplace " ) . '</option></select>' ;
2021-10-21 18:08:20 +02:00
$stringaddbarcode = str_replace ( " tmphtml " , $htmltoreplaceby , $stringaddbarcode );
2023-10-18 13:50:21 +02:00
$out .= $stringaddbarcode . ': <input type="text" name="barcodeproductqty" class="width40 right" value="1"><br>' ;
2023-10-10 19:34:54 +02:00
if ( $warehouseselect > 0 ) {
require_once DOL_DOCUMENT_ROOT . '/product/class/html.formproduct.class.php' ;
$formproduct = new FormProduct ( $this -> db );
$formproduct -> loadWarehouses ();
2023-10-18 13:50:21 +02:00
$out .= img_picto ( '' , 'stock' , 'class="pictofixedwidth"' );
2023-10-10 19:34:54 +02:00
$out .= $formproduct -> selectWarehouses ( '' , " warehousenew " , '' , 0 , 0 , 0 , '' , 0 , 1 );
$out .= '<br>' ;
$out .= '<br>' ;
}
2022-03-17 00:12:05 +01:00
$out .= '<textarea type="text" name="barcodelist" class="centpercent" autofocus rows="' . ROWS_3 . '" placeholder="' . dol_escape_htmltag ( $langs -> trans ( " ScanOrTypeOrCopyPasteYourBarCodes " )) . '"></textarea>' ;
2021-05-12 09:07:36 +02:00
/* print '<br>' . $langs -> trans ( " or " ) . '<br>' ;
print '<br>' ;
print '<input type="text" name="barcodelotserial" class="width200"> Qty <input type="text" name="barcodelotserialqty" class="width50 right" value="1"><br>' ;
*/
$out .= '<br>' ;
$out .= '<center>' ;
2021-12-19 16:02:28 +01:00
$out .= '<input type="submit" class="button marginleftonly marginrightonly" id ="exec' . dol_escape_js ( $jstoexecuteonadd ) . '" name="addscan" value="' . dol_escape_htmltag ( $langs -> trans ( " Add " )) . '">' ;
$out .= '<input type="submit" class="button marginleftonly marginrightonly" name="cancel" value="' . dol_escape_htmltag ( $langs -> trans ( " CloseWindow " )) . '">' ;
2021-12-19 03:36:25 +01:00
$out .= '</center>' ;
2021-05-12 09:07:36 +02:00
$out .= '<br>' ;
2021-12-19 03:36:25 +01:00
$out .= '<div type="text" id="scantoolmessage" class="scantoolmessage ok nopadding"></div>' ;
2021-05-12 09:07:36 +02:00
2023-02-18 15:10:05 +01:00
$out .= '<script nonce="' . getNonce () . '">' ;
2021-12-19 03:36:25 +01:00
$out .= 'jQuery("#barcodeforautodetect, #barcodeforproduct, #barcodeforlotserial").click(function(){' ;
$out .= 'console.log("select choice");' ;
$out .= 'jQuery("#scantoolmessage").text("");' ;
$out .= '});' . " \n " ;
2021-07-19 13:43:48 +02:00
$out .= '$("#exec' . dol_escape_js ( $jstoexecuteonadd ) . ' " ).click(function() {
2022-03-17 00:12:05 +01:00
console . log ( " We call js to execute \ ''.dol_escape_js( $jstoexecuteonadd ).' \ ' " );
2021-07-19 13:43:48 +02:00
'.dol_escape_js($jstoexecuteonadd).' ();
2021-12-19 03:36:25 +01:00
return false ; /* We want to stay on the scan tool */
2021-07-19 13:43:48 +02:00
}) ' ;
$out .= '</script>' ;
2021-05-12 09:07:36 +02:00
$out .= '</center>' ;
$out .= '</div>' ;
return $out ;
}
2020-10-07 15:01:28 +02:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Return HTML select list of export models
*
* @ param string $selected Id modele pre - selectionne
* @ param string $htmlname Nom de la zone select
* @ param string $type Type des modeles recherches
* @ param int $useempty Show an empty value in list
2021-06-21 15:03:45 +02:00
* @ param int $fk_user User we want templates
2020-10-07 15:01:28 +02:00
* @ return void
*/
public function select_export_model ( $selected = '' , $htmlname = 'exportmodelid' , $type = '' , $useempty = 0 , $fk_user = null )
{
// phpcs:enable
global $conf , $langs , $user ;
$sql = " SELECT rowid, label, fk_user " ;
2022-01-27 10:19:35 +01:00
$sql .= " FROM " . $this -> db -> prefix () . " export_model " ;
2020-10-07 15:01:28 +02:00
$sql .= " WHERE type = ' " . $this -> db -> escape ( $type ) . " ' " ;
2023-11-27 11:24:19 +01:00
if ( ! getDolGlobalString ( 'EXPORTS_SHARE_MODELS' )) { // EXPORTS_SHARE_MODELS means all templates are visible, whatever is owner.
2021-06-21 15:03:45 +02:00
$sql .= " AND fk_user IN (0, " . (( int ) $fk_user ) . " ) " ;
2021-02-23 22:03:23 +01:00
}
2020-10-07 15:01:28 +02:00
$sql .= " ORDER BY label " ;
$result = $this -> db -> query ( $sql );
2021-02-23 22:03:23 +01:00
if ( $result ) {
2020-10-07 15:01:28 +02:00
print '<select class="flat minwidth200" name="' . $htmlname . '" id="' . $htmlname . '">' ;
2021-02-23 22:03:23 +01:00
if ( $useempty ) {
2020-10-07 15:01:28 +02:00
print '<option value="-1"> </option>' ;
}
2021-06-21 15:03:45 +02:00
$tmpuser = new User ( $this -> db );
2020-10-07 15:01:28 +02:00
$num = $this -> db -> num_rows ( $result );
$i = 0 ;
2021-02-23 22:03:23 +01:00
while ( $i < $num ) {
2020-10-07 15:01:28 +02:00
$obj = $this -> db -> fetch_object ( $result );
$label = $obj -> label ;
if ( $obj -> fk_user == 0 ) {
$label .= ' <span class="opacitymedium">(' . $langs -> trans ( " Everybody " ) . ')</span>' ;
2021-06-21 15:03:45 +02:00
} elseif ( $obj -> fk_user > 0 ) {
2020-10-07 15:01:28 +02:00
$tmpuser -> fetch ( $obj -> fk_user );
$label .= ' <span class="opacitymedium">(' . $tmpuser -> getFullName ( $langs ) . ')</span>' ;
}
2021-02-23 22:03:23 +01:00
if ( $selected == $obj -> rowid ) {
2020-10-07 15:01:28 +02:00
print '<option value="' . $obj -> rowid . '" selected data-html="' . dol_escape_htmltag ( $label ) . '">' ;
} else {
print '<option value="' . $obj -> rowid . '" data-html="' . dol_escape_htmltag ( $label ) . '">' ;
}
print $label ;
print '</option>' ;
$i ++ ;
}
print " </select> " ;
print ajax_combobox ( $htmlname );
} else {
dol_print_error ( $this -> db );
}
}
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Return list of export models
*
* @ param string $selected Id modele pre - selectionne
* @ param string $htmlname Nom de la zone select
* @ param string $type Type des modeles recherches
* @ param int $useempty Affiche valeur vide dans liste
2021-06-21 15:03:45 +02:00
* @ param int $fk_user User that has created the template
2020-10-07 15:01:28 +02:00
* @ return void
*/
public function select_import_model ( $selected = '' , $htmlname = 'importmodelid' , $type = '' , $useempty = 0 , $fk_user = null )
{
// phpcs:enable
global $conf , $langs , $user ;
$sql = " SELECT rowid, label, fk_user " ;
2022-01-27 10:19:35 +01:00
$sql .= " FROM " . $this -> db -> prefix () . " import_model " ;
2020-10-07 15:01:28 +02:00
$sql .= " WHERE type = ' " . $this -> db -> escape ( $type ) . " ' " ;
2023-11-27 11:24:19 +01:00
if ( ! getDolGlobalString ( 'EXPORTS_SHARE_MODELS' )) { // EXPORTS_SHARE_MODELS means all templates are visible, whatever is owner.
2021-06-21 15:03:45 +02:00
$sql .= " AND fk_user IN (0, " . (( int ) $fk_user ) . " ) " ;
2021-02-23 22:03:23 +01:00
}
2021-06-21 15:03:45 +02:00
$sql .= " ORDER BY label " ;
2020-10-07 15:01:28 +02:00
$result = $this -> db -> query ( $sql );
2021-02-23 22:03:23 +01:00
if ( $result ) {
2020-10-07 15:01:28 +02:00
print '<select class="flat minwidth200" name="' . $htmlname . '" id="' . $htmlname . '">' ;
2021-02-23 22:03:23 +01:00
if ( $useempty ) {
2020-10-07 15:01:28 +02:00
print '<option value="-1"> </option>' ;
}
2021-06-21 15:03:45 +02:00
$tmpuser = new User ( $this -> db );
2020-10-07 15:01:28 +02:00
$num = $this -> db -> num_rows ( $result );
$i = 0 ;
2021-02-23 22:03:23 +01:00
while ( $i < $num ) {
2020-10-07 15:01:28 +02:00
$obj = $this -> db -> fetch_object ( $result );
$label = $obj -> label ;
if ( $obj -> fk_user == 0 ) {
$label .= ' <span class="opacitymedium">(' . $langs -> trans ( " Everybody " ) . ')</span>' ;
2021-06-21 15:03:45 +02:00
} elseif ( $obj -> fk_user > 0 ) {
2020-10-07 15:01:28 +02:00
$tmpuser -> fetch ( $obj -> fk_user );
$label .= ' <span class="opacitymedium">(' . $tmpuser -> getFullName ( $langs ) . ')</span>' ;
}
2021-02-23 22:03:23 +01:00
if ( $selected == $obj -> rowid ) {
2020-10-07 15:01:28 +02:00
print '<option value="' . $obj -> rowid . '" selected data-html="' . dol_escape_htmltag ( $label ) . '">' ;
} else {
print '<option value="' . $obj -> rowid . '" data-html="' . dol_escape_htmltag ( $label ) . '">' ;
}
print $label ;
print '</option>' ;
$i ++ ;
}
print " </select> " ;
print ajax_combobox ( $htmlname );
} else {
dol_print_error ( $this -> db );
}
}
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Return list of ecotaxes with label
*
* @ param string $selected Preselected ecotaxes
* @ param string $htmlname Name of combo list
* @ return integer
*/
public function select_ecotaxes ( $selected = '' , $htmlname = 'ecotaxe_id' )
{
// phpcs:enable
global $langs ;
$sql = " SELECT e.rowid, e.code, e.label, e.price, e.organization, " ;
$sql .= " c.label as country " ;
2022-01-27 10:19:35 +01:00
$sql .= " FROM " . $this -> db -> prefix () . " c_ecotaxe as e, " . $this -> db -> prefix () . " c_country as c " ;
2020-10-07 15:01:28 +02:00
$sql .= " WHERE e.active = 1 AND e.fk_pays = c.rowid " ;
$sql .= " ORDER BY country, e.organization ASC, e.code ASC " ;
dol_syslog ( get_class ( $this ) . '::select_ecotaxes' , LOG_DEBUG );
$resql = $this -> db -> query ( $sql );
2021-02-23 22:03:23 +01:00
if ( $resql ) {
2020-10-07 15:01:28 +02:00
print '<select class="flat" name="' . $htmlname . '">' ;
$num = $this -> db -> num_rows ( $resql );
$i = 0 ;
print '<option value="-1"> </option>' . " \n " ;
2021-02-23 22:03:23 +01:00
if ( $num ) {
while ( $i < $num ) {
2020-10-07 15:01:28 +02:00
$obj = $this -> db -> fetch_object ( $resql );
2021-02-23 22:03:23 +01:00
if ( $selected && $selected == $obj -> rowid ) {
2020-10-07 15:01:28 +02:00
print '<option value="' . $obj -> rowid . '" selected>' ;
} else {
print '<option value="' . $obj -> rowid . '">' ;
//print '<option onmouseover="showtip(\''.$obj->label.'\')" onMouseout="hidetip()" value="'.$obj->rowid.'">';
}
$selectOptionValue = $obj -> code . ' - ' . $obj -> label . ' : ' . price ( $obj -> price ) . ' ' . $langs -> trans ( " HT " ) . ' (' . $obj -> organization . ')' ;
print $selectOptionValue ;
print '</option>' ;
$i ++ ;
}
}
print '</select>' ;
return 0 ;
} else {
dol_print_error ( $this -> db );
return 1 ;
}
}
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Return list of revenue stamp for country
*
* @ param string $selected Value of preselected revenue stamp
* @ param string $htmlname Name of combo list
* @ param string $country_code Country Code
* @ return string HTML select list
*/
public function select_revenue_stamp ( $selected = '' , $htmlname = 'revenuestamp' , $country_code = '' )
{
// phpcs:enable
global $langs ;
$out = '' ;
$sql = " SELECT r.taux, r.revenuestamp_type " ;
2022-01-27 10:19:35 +01:00
$sql .= " FROM " . $this -> db -> prefix () . " c_revenuestamp as r, " . $this -> db -> prefix () . " c_country as c " ;
2020-10-07 15:01:28 +02:00
$sql .= " WHERE r.active = 1 AND r.fk_pays = c.rowid " ;
$sql .= " AND c.code = ' " . $this -> db -> escape ( $country_code ) . " ' " ;
dol_syslog ( get_class ( $this ) . '::select_revenue_stamp' , LOG_DEBUG );
$resql = $this -> db -> query ( $sql );
2021-02-23 22:03:23 +01:00
if ( $resql ) {
2020-10-07 15:01:28 +02:00
$out .= '<select class="flat" name="' . $htmlname . '">' ;
$num = $this -> db -> num_rows ( $resql );
$i = 0 ;
$out .= '<option value="0"> </option>' . " \n " ;
2021-02-23 22:03:23 +01:00
if ( $num ) {
while ( $i < $num ) {
2020-10-07 15:01:28 +02:00
$obj = $this -> db -> fetch_object ( $resql );
2021-02-23 22:03:23 +01:00
if (( $selected && $selected == $obj -> taux ) || $num == 1 ) {
2020-10-07 15:01:28 +02:00
$out .= '<option value="' . $obj -> taux . ( $obj -> revenuestamp_type == 'percent' ? '%' : '' ) . '"' . ( $obj -> revenuestamp_type == 'percent' ? ' data-type="percent"' : '' ) . ' selected>' ;
} else {
$out .= '<option value="' . $obj -> taux . ( $obj -> revenuestamp_type == 'percent' ? '%' : '' ) . '"' . ( $obj -> revenuestamp_type == 'percent' ? ' data-type="percent"' : '' ) . '>' ;
}
$out .= $obj -> taux . ( $obj -> revenuestamp_type == 'percent' ? '%' : '' );
$out .= '</option>' ;
$i ++ ;
}
}
$out .= '</select>' ;
return $out ;
} else {
dol_print_error ( $this -> db );
return '' ;
}
}
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Return a HTML select list to select a percent
*
* @ param integer $selected pourcentage pre - selectionne
* @ param string $htmlname nom de la liste deroulante
* @ param int $disabled Disabled or not
* @ param int $increment increment value
* @ param int $start start value
* @ param int $end end value
* @ param int $showempty Add also an empty line
* @ return string HTML select string
*/
public function select_percent ( $selected = 0 , $htmlname = 'percent' , $disabled = 0 , $increment = 5 , $start = 0 , $end = 100 , $showempty = 0 )
{
// phpcs:enable
2023-11-20 11:41:02 +01:00
$return = '<select class="flat maxwidth75 right" name="' . $htmlname . '" ' . ( $disabled ? 'disabled' : '' ) . '>' ;
2021-02-23 22:03:23 +01:00
if ( $showempty ) {
$return .= '<option value="-1"' . (( $selected == - 1 || $selected == '' ) ? ' selected' : '' ) . '> </option>' ;
}
2020-10-07 15:01:28 +02:00
2021-02-23 22:03:23 +01:00
for ( $i = $start ; $i <= $end ; $i += $increment ) {
if ( $selected != '' && ( int ) $selected == $i ) {
2020-10-07 15:01:28 +02:00
$return .= '<option value="' . $i . '" selected>' ;
} else {
$return .= '<option value="' . $i . '">' ;
}
$return .= $i . ' % ' ;
$return .= '</option>' ;
}
$return .= '</select>' ;
return $return ;
}
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Return select list for categories ( to use in form search selectors )
*
2024-09-12 21:16:42 +02:00
* @ param string $type Type of category ( 'customer' , 'supplier' , 'contact' , 'product' , 'member' ) . Old mode ( 0 , 1 , 2 , ... ) is deprecated .
2021-02-06 00:05:24 +01:00
* @ param integer $selected Preselected value
* @ param string $htmlname Name of combo list
* @ param int $nocateg Show also an entry " Not categorized "
* @ param int | string $showempty Add also an empty line
* @ param string $morecss More CSS
* @ return string Html combo list code
2020-10-07 15:01:28 +02:00
* @ see select_all_categories ()
*/
public function select_categories ( $type , $selected = 0 , $htmlname = 'search_categ' , $nocateg = 0 , $showempty = 1 , $morecss = '' )
{
// phpcs:enable
global $conf , $langs ;
require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php' ;
// For backward compatibility
2021-02-23 22:03:23 +01:00
if ( is_numeric ( $type )) {
2020-10-07 15:01:28 +02:00
dol_syslog ( __METHOD__ . ': using numeric value for parameter type is deprecated. Use string code instead.' , LOG_WARNING );
}
// Load list of "categories"
$static_categs = new Categorie ( $this -> db );
$tab_categs = $static_categs -> get_full_arbo ( $type );
$moreforfilter = '' ;
// Print a select with each of them
$moreforfilter .= '<select class="flat minwidth100' . ( $morecss ? ' ' . $morecss : '' ) . '" id="select_categ_' . $htmlname . '" name="' . $htmlname . '">' ;
2021-02-06 00:05:24 +01:00
if ( $showempty ) {
$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 ( $showempty )) {
$textforempty = $showempty ;
}
2023-04-08 00:37:46 +02:00
$moreforfilter .= '<option class="optiongrey" value="' . ( $showempty < 0 ? $showempty : - 1 ) . '"' . ( $selected == $showempty ? ' selected' : '' );
//$moreforfilter .= ' data-html="'.dol_escape_htmltag($textforempty).'"';
$moreforfilter .= '>' . dol_escape_htmltag ( $textforempty ) . '</option>' . " \n " ;
2021-02-06 00:05:24 +01:00
}
2020-10-07 15:01:28 +02:00
2021-02-23 22:03:23 +01:00
if ( is_array ( $tab_categs )) {
foreach ( $tab_categs as $categ ) {
2020-10-07 15:01:28 +02:00
$moreforfilter .= '<option value="' . $categ [ 'id' ] . '"' ;
2021-02-23 22:03:23 +01:00
if ( $categ [ 'id' ] == $selected ) {
$moreforfilter .= ' selected' ;
}
2022-10-31 08:13:11 +01:00
$moreforfilter .= ' data-html="' . dol_escape_htmltag ( img_picto ( '' , 'category' , 'class="pictofixedwidth" style="color: #' . $categ [ 'color' ] . '"' ) . dol_trunc ( $categ [ 'fulllabel' ], 50 , 'middle' )) . '"' ;
2020-10-07 15:01:28 +02:00
$moreforfilter .= '>' . dol_trunc ( $categ [ 'fulllabel' ], 50 , 'middle' ) . '</option>' ;
}
}
2021-02-23 22:03:23 +01:00
if ( $nocateg ) {
2020-10-07 15:01:28 +02:00
$langs -> load ( " categories " );
$moreforfilter .= '<option value="-2"' . ( $selected == - 2 ? ' selected' : '' ) . '>- ' . $langs -> trans ( " NotCategorized " ) . ' -</option>' ;
}
$moreforfilter .= '</select>' ;
2023-06-27 20:24:08 +02:00
// Enhance with select2
if ( $conf -> use_javascript_ajax ) {
include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php' ;
$comboenhancement = ajax_combobox ( 'select_categ_' . $htmlname );
$moreforfilter .= $comboenhancement ;
}
2020-10-07 15:01:28 +02:00
return $moreforfilter ;
}
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Return select list for categories ( to use in form search selectors )
*
2024-04-19 13:34:48 +02:00
* @ param int | string $selected Preselected value
2021-02-06 00:05:24 +01:00
* @ param string $htmlname Name of combo list ( example : 'search_sale' )
* @ param User $user Object user
* @ param int $showstatus 0 = show user status only if status is disabled , 1 = always show user status into label , - 1 = never show user status
2022-02-14 12:25:48 +01:00
* @ param int | string $showempty 1 = show also an empty value or text to show for empty
2021-02-06 00:05:24 +01:00
* @ param string $morecss More CSS
* @ param int $norepresentative Show also an entry " Not categorized "
* @ return string Html combo list code
2020-10-07 15:01:28 +02:00
*/
public function select_salesrepresentatives ( $selected , $htmlname , $user , $showstatus = 0 , $showempty = 1 , $morecss = '' , $norepresentative = 0 )
{
// phpcs:enable
global $conf , $langs , $hookmanager ;
2023-08-26 12:02:19 +02:00
global $action ;
2020-10-07 15:01:28 +02:00
$langs -> load ( 'users' );
$out = '' ;
$reshook = $hookmanager -> executeHooks ( 'addSQLWhereFilterOnSelectSalesRep' , array (), $this , $action );
// Select each sales and print them in a select input
$out .= '<select class="flat' . ( $morecss ? ' ' . $morecss : '' ) . '" id="' . $htmlname . '" name="' . $htmlname . '">' ;
2021-02-06 00:05:24 +01:00
if ( $showempty ) {
$textforempty = ' ' ;
2021-02-23 22:03:23 +01:00
if ( ! is_numeric ( $showempty )) {
$textforempty = $showempty ;
}
2022-02-14 12:25:48 +01:00
if ( ! empty ( $conf -> use_javascript_ajax ) && $textforempty == ' ' ) {
$textforempty = ' ' ; // If we use ajaxcombo, we need here to avoid to have an empty element that is too small.
}
2021-02-06 00:05:24 +01:00
$out .= '<option class="optiongrey" value="' . ( $showempty < 0 ? $showempty : - 1 ) . '"' . ( $selected == $showempty ? ' selected' : '' ) . '>' . $textforempty . '</option>' . " \n " ;
}
2020-10-07 15:01:28 +02:00
// Get list of users allowed to be viewed
2020-11-10 15:03:35 +01:00
$sql_usr = " SELECT u.rowid, u.lastname, u.firstname, u.statut as status, u.login, u.photo, u.gender, u.entity, u.admin " ;
2022-01-27 10:19:35 +01:00
$sql_usr .= " FROM " . $this -> db -> prefix () . " user as u " ;
2020-10-07 15:01:28 +02:00
2023-10-11 11:38:56 +02:00
if ( getDolGlobalInt ( 'MULTICOMPANY_TRANSVERSE_MODE' )) {
2020-10-07 15:01:28 +02:00
if ( ! empty ( $user -> admin ) && empty ( $user -> entity ) && $conf -> entity == 1 ) {
$sql_usr .= " WHERE u.entity IS NOT NULL " ; // Show all users
} else {
2022-01-27 10:19:35 +01:00
$sql_usr .= " WHERE EXISTS (SELECT ug.fk_user FROM " . $this -> db -> prefix () . " usergroup_user as ug WHERE u.rowid = ug.fk_user AND ug.entity IN ( " . getEntity ( 'usergroup' ) . " )) " ;
2020-10-07 15:01:28 +02:00
$sql_usr .= " OR u.entity = 0 " ; // Show always superadmin
}
} else {
$sql_usr .= " WHERE u.entity IN ( " . getEntity ( 'user' ) . " ) " ;
}
2023-10-15 15:32:35 +02:00
if ( ! $user -> hasRight ( 'user' , 'user' , 'lire' )) {
2021-08-23 18:56:46 +02:00
$sql_usr .= " AND u.rowid = " . (( int ) $user -> id );
2021-02-23 22:03:23 +01:00
}
if ( ! empty ( $user -> socid )) {
2021-08-23 17:41:11 +02:00
$sql_usr .= " AND u.fk_soc = " . (( int ) $user -> socid );
2021-02-23 22:03:23 +01:00
}
2024-09-19 14:12:07 +02:00
if ( getDolUserString ( 'USER_HIDE_NONEMPLOYEE_IN_COMBOBOX' , getDolGlobalString ( 'USER_HIDE_NONEMPLOYEE_IN_COMBOBOX' ))) {
2023-08-30 17:08:57 +02:00
$sql_usr .= " AND u.employee <> 0 " ;
}
2024-09-19 14:12:07 +02:00
if ( getDolUserString ( 'USER_HIDE_EXTERNAL_IN_COMBOBOX' , getDolGlobalString ( 'USER_HIDE_EXTERNAL_IN_COMBOBOX' ))) {
2023-09-05 14:34:21 +02:00
$sql_usr .= " AND u.fk_soc IS NULL " ;
}
2024-09-19 14:12:07 +02:00
if ( getDolUserString ( 'USER_HIDE_INACTIVE_IN_COMBOBOX' , getDolGlobalString ( 'USER_HIDE_INACTIVE_IN_COMBOBOX' ))) { // Can be set in setup of module User.
2023-08-30 17:08:57 +02:00
$sql_usr .= " AND u.statut <> 0 " ;
}
2020-10-07 15:01:28 +02:00
2024-01-13 19:48:20 +01:00
//Add hook to filter on user (for example on usergroup define in custom modules)
2021-02-23 22:03:23 +01:00
if ( ! empty ( $reshook )) {
$sql_usr .= $hookmanager -> resArray [ 0 ];
}
2020-10-07 15:01:28 +02:00
// Add existing sales representatives of thirdparty of external user
2023-10-15 15:32:35 +02:00
if ( ! $user -> hasRight ( 'user' , 'user' , 'lire' ) && $user -> socid ) {
2020-10-07 15:01:28 +02:00
$sql_usr .= " UNION " ;
2020-11-10 15:03:35 +01:00
$sql_usr .= " SELECT u2.rowid, u2.lastname, u2.firstname, u2.statut as status, u2.login, u2.photo, u2.gender, u2.entity, u2.admin " ;
2022-01-27 10:19:35 +01:00
$sql_usr .= " FROM " . $this -> db -> prefix () . " user as u2, " . $this -> db -> prefix () . " societe_commerciaux as sc " ;
2020-10-07 15:01:28 +02:00
2023-10-11 11:38:56 +02:00
if ( getDolGlobalInt ( 'MULTICOMPANY_TRANSVERSE_MODE' )) {
2020-10-07 15:01:28 +02:00
if ( ! empty ( $user -> admin ) && empty ( $user -> entity ) && $conf -> entity == 1 ) {
$sql_usr .= " WHERE u2.entity IS NOT NULL " ; // Show all users
} else {
2022-01-27 10:19:35 +01:00
$sql_usr .= " WHERE EXISTS (SELECT ug2.fk_user FROM " . $this -> db -> prefix () . " usergroup_user as ug2 WHERE u2.rowid = ug2.fk_user AND ug2.entity IN ( " . getEntity ( 'usergroup' ) . " )) " ;
2020-10-07 15:01:28 +02:00
}
} else {
$sql_usr .= " WHERE u2.entity IN ( " . getEntity ( 'user' ) . " ) " ;
}
2021-08-23 18:56:46 +02:00
$sql_usr .= " AND u2.rowid = sc.fk_user AND sc.fk_soc = " . (( int ) $user -> socid );
2020-10-07 15:01:28 +02:00
2024-01-13 19:48:20 +01:00
//Add hook to filter on user (for example on usergroup define in custom modules)
2021-02-23 22:03:23 +01:00
if ( ! empty ( $reshook )) {
$sql_usr .= $hookmanager -> resArray [ 1 ];
}
2020-10-07 15:01:28 +02:00
}
2021-03-29 11:58:51 +02:00
2023-11-27 11:24:19 +01:00
if ( ! getDolGlobalString ( 'MAIN_FIRSTNAME_NAME_POSITION' )) { // MAIN_FIRSTNAME_NAME_POSITION is 0 means firstname+lastname
2021-03-29 21:47:31 +02:00
$sql_usr .= " ORDER BY status DESC, firstname ASC, lastname ASC " ;
2021-03-29 11:58:51 +02:00
} else {
2021-03-29 21:47:31 +02:00
$sql_usr .= " ORDER BY status DESC, lastname ASC, firstname ASC " ;
2021-03-29 11:58:51 +02:00
}
2020-10-07 15:01:28 +02:00
//print $sql_usr;exit;
$resql_usr = $this -> db -> query ( $sql_usr );
2021-02-23 22:03:23 +01:00
if ( $resql_usr ) {
2020-11-10 15:03:35 +01:00
$userstatic = new User ( $this -> db );
2021-02-23 22:03:23 +01:00
while ( $obj_usr = $this -> db -> fetch_object ( $resql_usr )) {
2020-11-10 15:03:35 +01:00
$userstatic -> id = $obj_usr -> rowid ;
$userstatic -> lastname = $obj_usr -> lastname ;
$userstatic -> firstname = $obj_usr -> firstname ;
$userstatic -> photo = $obj_usr -> photo ;
2024-03-28 20:34:33 +01:00
$userstatic -> status = $obj_usr -> status ;
2020-11-10 15:03:35 +01:00
$userstatic -> entity = $obj_usr -> entity ;
$userstatic -> admin = $obj_usr -> admin ;
$labeltoshow = dolGetFirstLastname ( $obj_usr -> firstname , $obj_usr -> lastname );
2021-02-23 22:03:23 +01:00
if ( empty ( $obj_usr -> firstname ) && empty ( $obj_usr -> lastname )) {
$labeltoshow = $obj_usr -> login ;
}
2020-10-07 15:01:28 +02:00
2020-11-10 15:03:35 +01:00
$out .= '<option value="' . $obj_usr -> rowid . '"' ;
2021-02-23 22:03:23 +01:00
if ( $obj_usr -> rowid == $selected ) {
$out .= ' selected' ;
}
2020-11-10 15:03:35 +01:00
$out .= ' data-html="' ;
2021-02-06 00:05:24 +01:00
$outhtml = $userstatic -> getNomUrl ( - 3 , '' , 0 , 1 , 24 , 1 , 'login' , '' , 1 ) . ' ' ;
2021-02-23 22:03:23 +01:00
if ( $showstatus >= 0 && $obj_usr -> status == 0 ) {
$outhtml .= '<strike class="opacitymediumxxx">' ;
}
2020-11-10 15:03:35 +01:00
$outhtml .= $labeltoshow ;
2021-02-23 22:03:23 +01:00
if ( $showstatus >= 0 && $obj_usr -> status == 0 ) {
$outhtml .= '</strike>' ;
}
2020-11-10 15:03:35 +01:00
$out .= dol_escape_htmltag ( $outhtml );
$out .= '">' ;
2020-10-07 15:01:28 +02:00
2020-11-10 15:03:35 +01:00
$out .= $labeltoshow ;
2020-10-07 15:01:28 +02:00
// Complete name with more info
$moreinfo = 0 ;
2023-11-27 11:24:19 +01:00
if ( getDolGlobalString ( 'MAIN_SHOW_LOGIN' )) {
2020-10-07 15:01:28 +02:00
$out .= ( $moreinfo ? ' - ' : ' (' ) . $obj_usr -> login ;
$moreinfo ++ ;
}
2021-02-23 22:03:23 +01:00
if ( $showstatus >= 0 ) {
if ( $obj_usr -> status == 1 && $showstatus == 1 ) {
2020-03-12 12:45:44 +01:00
$out .= ( $moreinfo ? ' - ' : ' (' ) . $langs -> trans ( 'Enabled' );
2020-10-07 15:01:28 +02:00
$moreinfo ++ ;
2013-07-27 14:45:55 +02:00
}
2021-02-23 22:03:23 +01:00
if ( $obj_usr -> status == 0 ) {
2020-03-12 12:45:44 +01:00
$out .= ( $moreinfo ? ' - ' : ' (' ) . $langs -> trans ( 'Disabled' );
2020-10-07 15:01:28 +02:00
$moreinfo ++ ;
2013-07-27 14:45:55 +02:00
}
2013-07-22 11:17:45 +02:00
}
2020-03-12 12:45:44 +01:00
$out .= ( $moreinfo ? ')' : '' );
2020-10-07 15:01:28 +02:00
$out .= '</option>' ;
}
$this -> db -> free ( $resql_usr );
} else {
dol_print_error ( $this -> db );
}
2021-02-23 22:03:23 +01:00
if ( $norepresentative ) {
2020-10-07 15:01:28 +02:00
$langs -> load ( " companies " );
$out .= '<option value="-2"' . ( $selected == - 2 ? ' selected' : '' ) . '>- ' . $langs -> trans ( " NoSalesRepresentativeAffected " ) . ' -</option>' ;
}
$out .= '</select>' ;
2022-02-25 21:45:29 +01:00
// Enhance with select2
if ( $conf -> use_javascript_ajax ) {
include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php' ;
$comboenhancement = ajax_combobox ( $htmlname );
if ( $comboenhancement ) {
$out .= $comboenhancement ;
}
}
2020-10-07 15:01:28 +02:00
return $out ;
}
/**
* Return list of project and tasks
*
* @ param int $selectedtask Pre - selected task
* @ param int $projectid Project id
* @ param string $htmlname Name of html select
* @ param int $modeproject 1 to restrict on projects owned by user
* @ param int $modetask 1 to restrict on tasks associated to user
* @ param int $mode 0 = Return list of tasks and their projects , 1 = Return projects and tasks if exists
* @ param int $useempty 0 = Allow empty values
* @ param int $disablechildoftaskid 1 = Disable task that are child of the provided task id
2018-06-21 18:47:02 +02:00
* @ param string $filteronprojstatus Filter on project status ( '-1' = no filter , '0,1' = Draft + Validated status )
2020-10-07 15:01:28 +02:00
* @ param string $morecss More css
* @ return void
*/
2024-02-28 23:42:23 +01:00
public function selectProjectTasks ( $selectedtask = 0 , $projectid = 0 , $htmlname = 'task_parent' , $modeproject = 0 , $modetask = 0 , $mode = 0 , $useempty = 0 , $disablechildoftaskid = 0 , $filteronprojstatus = '' , $morecss = '' )
2020-10-07 15:01:28 +02:00
{
global $user , $langs ;
require_once DOL_DOCUMENT_ROOT . '/projet/class/task.class.php' ;
//print $modeproject.'-'.$modetask;
$task = new Task ( $this -> db );
$tasksarray = $task -> getTasksArray ( $modetask ? $user : 0 , $modeproject ? $user : 0 , $projectid , 0 , $mode , '' , $filteronprojstatus );
2021-02-23 22:03:23 +01:00
if ( $tasksarray ) {
2020-10-07 15:01:28 +02:00
print '<select class="flat' . ( $morecss ? ' ' . $morecss : '' ) . '" name="' . $htmlname . '" id="' . $htmlname . '">' ;
2021-02-23 22:03:23 +01:00
if ( $useempty ) {
print '<option value="0"> </option>' ;
}
2020-10-07 15:01:28 +02:00
$j = 0 ;
$level = 0 ;
$this -> _pLineSelect ( $j , 0 , $tasksarray , $level , $selectedtask , $projectid , $disablechildoftaskid );
print '</select>' ;
print ajax_combobox ( $htmlname );
} else {
print '<div class="warning">' . $langs -> trans ( " NoProject " ) . '</div>' ;
}
}
/**
* Write lines of a project ( all lines of a project if parent = 0 )
*
* @ param int $inc Cursor counter
* @ param int $parent Id of parent task we want to see
2024-09-28 12:09:35 +02:00
* @ param Task [] $lines Array of task lines
2020-10-07 15:01:28 +02:00
* @ param int $level Level
* @ param int $selectedtask Id selected task
* @ param int $selectedproject Id selected project
* @ param int $disablechildoftaskid 1 = Disable task that are child of the provided task id
* @ return void
*/
private function _pLineSelect ( & $inc , $parent , $lines , $level = 0 , $selectedtask = 0 , $selectedproject = 0 , $disablechildoftaskid = 0 )
{
global $langs , $user , $conf ;
$lastprojectid = 0 ;
$numlines = count ( $lines );
for ( $i = 0 ; $i < $numlines ; $i ++ ) {
2023-06-29 16:30:34 +02:00
if ( $lines [ $i ] -> fk_task_parent == $parent ) {
2020-10-07 15:01:28 +02:00
//var_dump($selectedproject."--".$selectedtask."--".$lines[$i]->fk_project."_".$lines[$i]->id); // $lines[$i]->id may be empty if project has no lines
// Break on a new project
2021-02-23 22:03:23 +01:00
if ( $parent == 0 ) { // We are on a task at first level
if ( $lines [ $i ] -> fk_project != $lastprojectid ) { // Break found on project
if ( $i > 0 ) {
print '<option value="0" disabled>----------</option>' ;
}
2020-10-07 15:01:28 +02:00
print '<option value="' . $lines [ $i ] -> fk_project . '_0"' ;
2021-02-23 22:03:23 +01:00
if ( $selectedproject == $lines [ $i ] -> fk_project ) {
print ' selected' ;
}
2020-12-08 11:58:47 +01:00
2022-06-21 11:11:28 +02:00
$labeltoshow = $lines [ $i ] -> projectref ;
//$labeltoshow .= ' '.$lines[$i]->projectlabel;
2020-12-08 11:58:47 +01:00
if ( empty ( $lines [ $i ] -> public )) {
2022-06-21 11:11:28 +02:00
//$labeltoshow .= ' <span class="opacitymedium">('.$langs->trans("Visibility").': '.$langs->trans("PrivateProject").')</span>';
$labeltoshow = img_picto ( $lines [ $i ] -> projectlabel , 'project' , 'class="pictofixedwidth"' ) . $labeltoshow ;
2020-10-07 15:01:28 +02:00
} else {
2022-06-21 11:11:28 +02:00
//$labeltoshow .= ' <span class="opacitymedium">('.$langs->trans("Visibility").': '.$langs->trans("SharedProject").')</span>';
$labeltoshow = img_picto ( $lines [ $i ] -> projectlabel , 'projectpub' , 'class="pictofixedwidth"' ) . $labeltoshow ;
2020-10-07 15:01:28 +02:00
}
2020-12-08 11:58:47 +01:00
print ' data-html="' . dol_escape_htmltag ( $labeltoshow ) . '"' ;
print '>' ; // Project -> Task
print $labeltoshow ;
2020-10-07 15:01:28 +02:00
print " </option> \n " ;
$lastprojectid = $lines [ $i ] -> fk_project ;
$inc ++ ;
}
}
$newdisablechildoftaskid = $disablechildoftaskid ;
// Print task
2021-02-23 22:03:23 +01:00
if ( isset ( $lines [ $i ] -> id )) { // We use isset because $lines[$i]->id may be null if project has no task and are on root project (tasks may be caught by a left join). We enter here only if '0' or >0
2020-10-07 15:01:28 +02:00
// Check if we must disable entry
$disabled = 0 ;
2023-06-29 16:30:34 +02:00
if ( $disablechildoftaskid && (( $lines [ $i ] -> id == $disablechildoftaskid || $lines [ $i ] -> fk_task_parent == $disablechildoftaskid ))) {
2021-02-23 22:03:23 +01:00
$disabled ++ ;
2023-06-29 16:30:34 +02:00
if ( $lines [ $i ] -> fk_task_parent == $disablechildoftaskid ) {
2021-02-23 22:03:23 +01:00
$newdisablechildoftaskid = $lines [ $i ] -> id ; // If task is child of a disabled parent, we will propagate id to disable next child too
}
2020-10-07 15:01:28 +02:00
}
print '<option value="' . $lines [ $i ] -> fk_project . '_' . $lines [ $i ] -> id . '"' ;
2021-02-23 22:03:23 +01:00
if (( $lines [ $i ] -> id == $selectedtask ) || ( $lines [ $i ] -> fk_project . '_' . $lines [ $i ] -> id == $selectedtask )) {
print ' selected' ;
}
if ( $disabled ) {
print ' disabled' ;
}
2020-12-08 11:58:47 +01:00
2022-06-21 11:11:28 +02:00
$labeltoshow = $lines [ $i ] -> projectref ;
//$labeltoshow .= ' '.$lines[$i]->projectlabel;
2021-02-23 22:03:23 +01:00
if ( empty ( $lines [ $i ] -> public )) {
2022-06-21 11:11:28 +02:00
//$labeltoshow .= ' <span class="opacitymedium">('.$langs->trans("Visibility").': '.$langs->trans("PrivateProject").')</span>';
$labeltoshow = img_picto ( $lines [ $i ] -> projectlabel , 'project' , 'class="pictofixedwidth"' ) . $labeltoshow ;
2020-10-07 15:01:28 +02:00
} else {
2022-06-21 11:11:28 +02:00
//$labeltoshow .= ' <span class="opacitymedium">('.$langs->trans("Visibility").': '.$langs->trans("SharedProject").')</span>';
$labeltoshow = img_picto ( $lines [ $i ] -> projectlabel , 'projectpub' , 'class="pictofixedwidth"' ) . $labeltoshow ;
2020-10-07 15:01:28 +02:00
}
2021-02-23 22:03:23 +01:00
if ( $lines [ $i ] -> id ) {
$labeltoshow .= ' > ' ;
}
for ( $k = 0 ; $k < $level ; $k ++ ) {
2020-12-08 11:58:47 +01:00
$labeltoshow .= " " ;
2020-10-07 15:01:28 +02:00
}
2020-12-08 11:58:47 +01:00
$labeltoshow .= $lines [ $i ] -> ref . ' ' . $lines [ $i ] -> label ;
print ' data-html="' . dol_escape_htmltag ( $labeltoshow ) . '"' ;
print '>' ;
print $labeltoshow ;
print " </option> \n " ;
2020-10-07 15:01:28 +02:00
$inc ++ ;
}
$level ++ ;
2021-02-23 22:03:23 +01:00
if ( $lines [ $i ] -> id ) {
$this -> _pLineSelect ( $inc , $lines [ $i ] -> id , $lines , $level , $selectedtask , $selectedproject , $newdisablechildoftaskid );
}
2020-10-07 15:01:28 +02:00
$level -- ;
}
}
}
/**
* Output a HTML thumb of color or a text if not defined .
*
* @ param string $color String with hex ( FFFFFF ) or comma RGB ( '255,255,255' )
* @ param string $textifnotdefined Text to show if color not defined
2023-05-01 19:16:46 +02:00
* @ return string Show color string
2020-10-07 15:01:28 +02:00
* @ see selectColor ()
*/
public static function showColor ( $color , $textifnotdefined = '' )
{
$textcolor = 'FFF' ;
include_once DOL_DOCUMENT_ROOT . '/core/lib/functions2.lib.php' ;
2021-02-23 22:03:23 +01:00
if ( colorIsLight ( $color )) {
$textcolor = '000' ;
}
2020-10-07 15:01:28 +02:00
$color = colorArrayToHex ( colorStringToArray ( $color , array ()), '' );
2017-06-12 14:09:00 +02:00
2021-02-23 22:03:23 +01:00
if ( $color ) {
2023-05-01 19:16:46 +02:00
return '<input type="text" class="colorthumb" disabled style="padding: 1px; margin-top: 0; margin-bottom: 0; color: #' . $textcolor . '; background-color: #' . $color . '" value="' . $color . '">' ;
2021-02-23 22:03:23 +01:00
} else {
2023-05-01 19:16:46 +02:00
return $textifnotdefined ;
2021-02-23 22:03:23 +01:00
}
2020-10-07 15:01:28 +02:00
}
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Output a HTML code to select a color
*
* @ param string $set_color Pre - selected color
* @ param string $prefix Name of HTML field
* @ param string $form_name Deprecated . Not used .
* @ param int $showcolorbox 1 = Show color code and color box , 0 = Show only color code
2024-09-28 12:09:35 +02:00
* @ param string [] $arrayofcolors Array of colors . Example : array ( '29527A' , '5229A3' , 'A32929' , '7A367A' , 'B1365F' , '0D7813' )
2020-10-07 15:01:28 +02:00
* @ return void
2024-09-28 12:09:35 +02:00
* @ deprecated Use selectColor ()
2020-10-07 15:01:28 +02:00
* @ see selectColor ()
*/
2024-02-28 16:07:02 +01:00
public function select_color ( $set_color = '' , $prefix = 'f_color' , $form_name = '' , $showcolorbox = 1 , $arrayofcolors = [])
2020-10-07 15:01:28 +02:00
{
// phpcs:enable
print $this -> selectColor ( $set_color , $prefix , $form_name , $showcolorbox , $arrayofcolors );
}
/**
* Output a HTML code to select a color . Field will return an hexa color like '334455' .
*
2023-09-08 15:25:50 +02:00
* @ param string $set_color Pre - selected color with format '#......'
2023-07-31 21:44:03 +02:00
* @ param string $prefix Name of HTML field
2024-09-18 03:27:25 +02:00
* @ param null | '' $form_name Deprecated . Not used .
2023-07-31 21:44:03 +02:00
* @ param int $showcolorbox 1 = Show color code and color box , 0 = Show only color code
2024-09-18 03:27:25 +02:00
* @ param string [] $arrayofcolors Array of possible colors to choose in the selector . All colors are possible if empty . Example : array ( '29527A' , '5229A3' , 'A32929' , '7A367A' , 'B1365F' , '0D7813' )
2023-07-31 21:44:03 +02:00
* @ param string $morecss Add css style into input field
2024-01-27 12:08:28 +01:00
* @ param string $setpropertyonselect Set this CSS property after selecting a color
2023-07-31 21:44:03 +02:00
* @ param string $default Default color
2020-10-07 15:01:28 +02:00
* @ return string
* @ see showColor ()
*/
2024-02-28 16:07:02 +01:00
public static function selectColor ( $set_color = '' , $prefix = 'f_color' , $form_name = '' , $showcolorbox = 1 , $arrayofcolors = [], $morecss = '' , $setpropertyonselect = '' , $default = '' )
2020-10-07 15:01:28 +02:00
{
// Deprecation warning
if ( $form_name ) {
dol_syslog ( __METHOD__ . " : form_name parameter is deprecated " , LOG_WARNING );
}
global $langs , $conf ;
$out = '' ;
2021-02-23 22:03:23 +01:00
if ( ! is_array ( $arrayofcolors ) || count ( $arrayofcolors ) < 1 ) {
2023-07-31 20:16:49 +02:00
// Case of selection of any color
2020-10-07 15:01:28 +02:00
$langs -> load ( " other " );
2023-08-01 14:14:54 +02:00
if ( empty ( $conf -> dol_use_jmobile ) && ! empty ( $conf -> use_javascript_ajax ) && ! getDolGlobalInt ( 'MAIN_USE_HTML5_COLOR_SELECTOR' )) {
2020-10-07 15:01:28 +02:00
$out .= '<link rel="stylesheet" media="screen" type="text/css" href="' . DOL_URL_ROOT . '/includes/jquery/plugins/jpicker/css/jPicker-1.1.6.css" />' ;
2023-02-18 15:10:05 +01:00
$out .= '<script nonce="' . getNonce () . '" type="text/javascript" src="' . DOL_URL_ROOT . '/includes/jquery/plugins/jpicker/jpicker-1.1.6.js"></script>' ;
$out .= '<script nonce="' . getNonce () . ' " type= " text / javascript " >
2013-05-26 05:01:28 +02:00
jQuery ( document ) . ready ( function (){
2022-01-02 16:34:46 +01:00
var originalhex = null ;
2013-05-26 05:01:28 +02:00
$ ( \ '#colorpicker' . $prefix . ' \ ' ) . jPicker ( {
2020-10-15 13:16:17 +02:00
window : {
title : \ '' . dol_escape_js ( $langs -> trans ( " SelectAColor " )) . ' \ ' , /* any title for the jPicker window itself - displays "Drag Markers To Pick A Color" if left null */
effects :
{
type : \ ' show\ ' , /* effect used to show/hide an expandable picker. Acceptable values "slide", "show", "fade" */
speed :
{
show : \ ' fast\ ' , /* duration of "show" effect. Acceptable values are "fast", "slow", or time in ms */
hide : \ ' fast\ ' /* duration of "hide" effect. Acceptable values are "fast", "slow", or time in ms */
}
},
position :
{
x : \ ' screenCenter\ ' , /* acceptable values "left", "center", "right", "screenCenter", or relative px value */
y : \ ' center\ ' /* acceptable values "top", "bottom", "center", or relative px value */
},
},
images : {
clientPath : \ '' . DOL_URL_ROOT . ' / includes / jquery / plugins / jpicker / images / \ ' ,
picker : { file : \ ' ../../../../../ theme / common / colorpicker . png\ ' , width : 14 , height : 14 }
},
localization : // alter these to change the text presented by the picker (e.g. different language)
{
text :
{
title : \ '' . dol_escape_js ( $langs -> trans ( " SelectAColor " )) . ' \ ' ,
newColor : \ '' . dol_escape_js ( $langs -> trans ( " New " )) . ' \ ' ,
currentColor : \ '' . dol_escape_js ( $langs -> trans ( " Current " )) . ' \ ' ,
2022-01-02 16:34:46 +01:00
ok : \ '' . dol_escape_js ( $langs -> trans ( " Validate " )) . ' \ ' ,
2020-10-15 13:16:17 +02:00
cancel : \ '' . dol_escape_js ( $langs -> trans ( " Cancel " )) . ' \ '
}
}
},
2022-01-02 16:34:46 +01:00
function ( color , context ) { console . log ( " close color selector " ); },
2021-10-04 04:14:31 +02:00
function ( color , context ) { var hex = color . val ( \ 'hex\'); console.log("new color selected in jpicker "+hex+" setpropertyonselect=' . dol_escape_js ( $setpropertyonselect ) . '");' ;
2021-02-23 22:03:23 +01:00
if ( $setpropertyonselect ) {
2022-01-02 16:34:46 +01:00
$out .= 'if (originalhex == null) {' ;
$out .= ' originalhex = getComputedStyle(document.querySelector(":root")).getPropertyValue(\'--' . dol_escape_js ( $setpropertyonselect ) . '\');' ;
$out .= ' console.log("original color is saved into originalhex = "+originalhex);' ;
$out .= '}' ;
$out .= 'if (hex != null) {' ;
$out .= ' document.documentElement.style.setProperty(\'--' . dol_escape_js ( $setpropertyonselect ) . '\', \'#\'+hex);' ;
$out .= '}' ;
2021-02-23 22:03:23 +01:00
}
2022-01-02 16:34:46 +01:00
$out .= ' },
function ( color , context ) {
console . log ( " cancel selection of color " ); ' ;
if ( $setpropertyonselect ) {
$out .= ' if ( originalhex != null ) {
console . log ( " Restore old color " + originalhex );
document . documentElement . style . setProperty ( \ '--' . dol_escape_js ( $setpropertyonselect ) . ' \ ' , originalhex );
} ' ;
}
$out .= '
}
2020-10-15 13:16:17 +02:00
);
});
2013-05-26 05:01:28 +02:00
</ script > ' ;
2023-07-31 21:44:03 +02:00
$out .= '<input id="colorpicker' . $prefix . '" name="' . $prefix . '" size="6" maxlength="7" class="flat valignmiddle' . ( $morecss ? ' ' . $morecss : '' ) . '" type="text" value="' . dol_escape_htmltag ( $set_color ) . '" />' ;
2023-07-31 20:16:49 +02:00
} else {
2023-09-08 15:25:50 +02:00
$color = ( $set_color !== '' ? $set_color : ( $default !== '' ? $default : 'FFFFFF' ));
$out .= '<input id="colorpicker' . $prefix . '" name="' . $prefix . '" size="6" maxlength="7" class="flat input-nobottom colorselector valignmiddle ' . ( $morecss ? ' ' . $morecss : '' ) . '" type="color" data-default="' . $default . '" value="' . dol_escape_htmltag ( preg_match ( '/^#/' , $color ) ? $color : '#' . $color ) . '" />' ;
2023-07-31 20:16:49 +02:00
$out .= '<script nonce="' . getNonce () . ' " type= " text / javascript " >
jQuery ( document ) . ready ( function (){
var originalhex = null ;
jQuery ( " #colorpicker'. $prefix .' " ) . on ( \ ' change\ ' , function () {
var hex = jQuery ( " #colorpicker'. $prefix .' " ) . val ();
console . log ( " new color selected in input color " + hex + " setpropertyonselect='.dol_escape_js( $setpropertyonselect ).' " ); ' ;
if ( $setpropertyonselect ) {
$out .= 'if (originalhex == null) {' ;
$out .= ' originalhex = getComputedStyle(document.querySelector(":root")).getPropertyValue(\'--' . dol_escape_js ( $setpropertyonselect ) . '\');' ;
$out .= ' console.log("original color is saved into originalhex = "+originalhex);' ;
$out .= '}' ;
$out .= 'if (hex != null) {' ;
$out .= ' document.documentElement.style.setProperty(\'--' . dol_escape_js ( $setpropertyonselect ) . '\', hex);' ;
$out .= '}' ;
}
$out .= '
});
});
</ script > ' ;
2020-10-07 15:01:28 +02:00
}
2023-07-31 20:16:49 +02:00
} else {
// In most cases, this is not used. We used instead function with no specific list of colors
2021-02-23 22:03:23 +01:00
if ( empty ( $conf -> dol_use_jmobile ) && ! empty ( $conf -> use_javascript_ajax )) {
2020-10-07 15:01:28 +02:00
$out .= '<link rel="stylesheet" href="' . DOL_URL_ROOT . '/includes/jquery/plugins/colorpicker/jquery.colorpicker.css" type="text/css" media="screen" />' ;
2023-02-18 15:10:05 +01:00
$out .= '<script nonce="' . getNonce () . '" src="' . DOL_URL_ROOT . '/includes/jquery/plugins/colorpicker/jquery.colorpicker.js" type="text/javascript"></script>' ;
$out .= '<script nonce="' . getNonce () . ' " type= " text / javascript " >
2013-05-26 05:01:28 +02:00
jQuery ( document ) . ready ( function (){
jQuery ( \ '#colorpicker' . $prefix . ' \ ' ) . colorpicker ({
size : 14 ,
label : \ ' \ ' ,
hide : true
});
});
</ script > ' ;
2020-10-07 15:01:28 +02:00
}
$out .= '<select id="colorpicker' . $prefix . '" class="flat' . ( $morecss ? ' ' . $morecss : '' ) . '" name="' . $prefix . '">' ;
//print '<option value="-1"> </option>';
2021-02-23 22:03:23 +01:00
foreach ( $arrayofcolors as $val ) {
2020-10-07 15:01:28 +02:00
$out .= '<option value="' . $val . '"' ;
2021-02-23 22:03:23 +01:00
if ( $set_color == $val ) {
$out .= ' selected' ;
}
2020-10-07 15:01:28 +02:00
$out .= '>' . $val . '</option>' ;
}
$out .= '</select>' ;
}
return $out ;
}
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
2024-02-09 15:58:49 +01:00
* Create an image for color
2020-10-07 15:01:28 +02:00
*
2022-01-02 16:34:46 +01:00
* @ param string $color Color of image
* @ param string $module Name of module
* @ param string $name Name of image
2020-10-07 15:01:28 +02:00
* @ param int $x Largeur de l ' image en pixels
* @ param int $y Hauteur de l ' image en pixels
* @ return void
*/
2024-02-28 23:42:23 +01:00
public function CreateColorIcon ( $color , $module , $name , $x = 12 , $y = 12 )
2020-10-07 15:01:28 +02:00
{
// phpcs:enable
global $conf ;
$file = $conf -> $module -> dir_temp . '/' . $name . '.png' ;
2023-11-14 20:59:31 +01:00
// We create temp directory
2021-02-23 22:03:23 +01:00
if ( ! file_exists ( $conf -> $module -> dir_temp )) {
2020-10-07 15:01:28 +02:00
dol_mkdir ( $conf -> $module -> dir_temp );
}
// On cree l'image en vraies couleurs
$image = imagecreatetruecolor ( $x , $y );
$color = substr ( $color , 1 , 6 );
2024-01-13 19:48:20 +01:00
$red = hexdec ( substr ( $color , 0 , 2 )); // Red channel conversion
$green = hexdec ( substr ( $color , 2 , 2 )); // Green channel conversion
$blue = hexdec ( substr ( $color , 4 , 2 )); // Blue channel conversion
2020-10-07 15:01:28 +02:00
2024-01-13 19:48:20 +01:00
$couleur = imagecolorallocate ( $image , $red , $green , $blue );
//print $red.$green.$blue;
imagefill ( $image , 0 , 0 , $couleur ); // Fill the image
// Create the colr and store it in a variable to maintain it
imagepng ( $image , $file ); // Returns an image in PNG format
2024-01-12 20:40:34 +01:00
imagedestroy ( $image );
2020-10-07 15:01:28 +02:00
}
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Return HTML combo list of week
*
* @ param string $selected Preselected value
* @ param string $htmlname Nom de la zone select
* @ param int $useempty Affiche valeur vide dans liste
* @ return string
*/
public function select_dayofweek ( $selected = '' , $htmlname = 'weekid' , $useempty = 0 )
{
// phpcs:enable
global $langs ;
$week = array (
2024-03-21 22:26:56 +01:00
0 => $langs -> trans ( " Day0 " ),
1 => $langs -> trans ( " Day1 " ),
2 => $langs -> trans ( " Day2 " ),
3 => $langs -> trans ( " Day3 " ),
4 => $langs -> trans ( " Day4 " ),
5 => $langs -> trans ( " Day5 " ),
6 => $langs -> trans ( " Day6 " )
2020-10-07 15:01:28 +02:00
);
2022-05-01 13:39:22 +02:00
$select_week = '<select class="flat" name="' . $htmlname . '" id="' . $htmlname . '">' ;
2021-02-23 22:03:23 +01:00
if ( $useempty ) {
2020-10-07 15:01:28 +02:00
$select_week .= '<option value="-1"> </option>' ;
}
2021-02-23 22:03:23 +01:00
foreach ( $week as $key => $val ) {
if ( $selected == $key ) {
2020-10-07 15:01:28 +02:00
$select_week .= '<option value="' . $key . '" selected>' ;
} else {
$select_week .= '<option value="' . $key . '">' ;
}
$select_week .= $val ;
$select_week .= '</option>' ;
}
$select_week .= '</select>' ;
2022-05-01 13:39:22 +02:00
$select_week .= ajax_combobox ( $htmlname );
2020-10-07 15:01:28 +02:00
return $select_week ;
}
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Return HTML combo list of month
*
* @ param string $selected Preselected value
* @ param string $htmlname Name of HTML select object
* @ param int $useempty Show empty in list
* @ param int $longlabel Show long label
* @ param string $morecss More Css
2020-12-04 14:53:52 +01:00
* @ param bool $addjscombo Add js combo
2020-10-07 15:01:28 +02:00
* @ return string
*/
2020-12-04 14:53:52 +01:00
public function select_month ( $selected = '' , $htmlname = 'monthid' , $useempty = 0 , $longlabel = 0 , $morecss = 'minwidth50 maxwidth75imp valignmiddle' , $addjscombo = false )
2020-10-07 15:01:28 +02:00
{
// phpcs:enable
global $langs ;
require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php' ;
2021-02-23 22:03:23 +01:00
if ( $longlabel ) {
$montharray = monthArray ( $langs , 0 ); // Get array
} else {
$montharray = monthArray ( $langs , 1 );
}
2020-10-07 15:01:28 +02:00
$select_month = '<select class="flat' . ( $morecss ? ' ' . $morecss : '' ) . '" name="' . $htmlname . '" id="' . $htmlname . '">' ;
2021-02-23 22:03:23 +01:00
if ( $useempty ) {
2020-10-07 15:01:28 +02:00
$select_month .= '<option value="0"> </option>' ;
}
2021-02-23 22:03:23 +01:00
foreach ( $montharray as $key => $val ) {
if ( $selected == $key ) {
2020-10-07 15:01:28 +02:00
$select_month .= '<option value="' . $key . '" selected>' ;
} else {
$select_month .= '<option value="' . $key . '">' ;
}
$select_month .= $val ;
$select_month .= '</option>' ;
}
$select_month .= '</select>' ;
2020-12-04 14:53:52 +01:00
// Add code for jquery to use multiselect
2021-02-23 22:03:23 +01:00
if ( $addjscombo ) {
2020-12-04 14:53:52 +01:00
// Enhance with select2
include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php' ;
$select_month .= ajax_combobox ( $htmlname );
}
2020-10-07 15:01:28 +02:00
return $select_month ;
}
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Return HTML combo list of years
*
* @ param string $selected Preselected value ( '' = current year , - 1 = none , year otherwise )
* @ param string $htmlname Name of HTML select object
* @ param int $useempty Affiche valeur vide dans liste
* @ param int $min_year Offset of minimum year into list ( by default current year - 10 )
* @ param int $max_year Offset of maximum year into list ( by default current year + 5 )
* @ param int $offset Offset
* @ param int $invert Invert
* @ param string $option Option
* @ param string $morecss More CSS
2022-05-02 20:10:42 +02:00
* @ param bool $addjscombo Add js combo
2023-05-01 17:21:00 +02:00
* @ return void
2022-05-02 20:10:42 +02:00
* @ deprecated
2020-10-07 15:01:28 +02:00
*/
2022-05-02 20:10:42 +02:00
public function select_year ( $selected = '' , $htmlname = 'yearid' , $useempty = 0 , $min_year = 10 , $max_year = 5 , $offset = 0 , $invert = 0 , $option = '' , $morecss = 'valignmiddle maxwidth75imp' , $addjscombo = false )
2020-10-07 15:01:28 +02:00
{
// phpcs:enable
2022-05-02 20:10:42 +02:00
print $this -> selectyear ( $selected , $htmlname , $useempty , $min_year , $max_year , $offset , $invert , $option , $morecss , $addjscombo );
2020-10-07 15:01:28 +02:00
}
/**
* Return HTML combo list of years
*
* @ param string $selected Preselected value ( '' = current year , - 1 = none , year otherwise )
* @ param string $htmlname Name of HTML select object
* @ param int $useempty Affiche valeur vide dans liste
* @ param int $min_year Offset of minimum year into list ( by default current year - 10 )
* @ param int $max_year Offset of maximum year into list ( by default current year + 5 )
* @ param int $offset Offset
* @ param int $invert Invert
* @ param string $option Option
* @ param string $morecss More css
2020-10-08 10:30:09 +02:00
* @ param bool $addjscombo Add js combo
2020-10-07 15:01:28 +02:00
* @ return string
*/
2020-12-04 14:53:52 +01:00
public function selectyear ( $selected = '' , $htmlname = 'yearid' , $useempty = 0 , $min_year = 10 , $max_year = 5 , $offset = 0 , $invert = 0 , $option = '' , $morecss = 'valignmiddle width75' , $addjscombo = false )
2020-10-07 15:01:28 +02:00
{
$out = '' ;
2024-03-21 22:26:56 +01:00
$currentyear = idate ( " Y " ) + $offset ;
2020-10-07 15:01:28 +02:00
$max_year = $currentyear + $max_year ;
$min_year = $currentyear - $min_year ;
2021-02-23 22:03:23 +01:00
if ( empty ( $selected ) && empty ( $useempty )) {
$selected = $currentyear ;
}
2020-10-07 15:01:28 +02:00
$out .= '<select class="flat' . ( $morecss ? ' ' . $morecss : '' ) . '" id="' . $htmlname . '" name="' . $htmlname . '"' . $option . ' >' ;
2021-02-23 22:03:23 +01:00
if ( $useempty ) {
2020-10-07 15:01:28 +02:00
$selected_html = '' ;
2021-02-23 22:03:23 +01:00
if ( $selected == '' ) {
$selected_html = ' selected' ;
}
2020-10-07 15:01:28 +02:00
$out .= '<option value=""' . $selected_html . '> </option>' ;
}
2021-02-23 22:03:23 +01:00
if ( ! $invert ) {
for ( $y = $max_year ; $y >= $min_year ; $y -- ) {
2020-10-07 15:01:28 +02:00
$selected_html = '' ;
2021-02-23 22:03:23 +01:00
if ( $selected > 0 && $y == $selected ) {
$selected_html = ' selected' ;
}
2020-10-07 15:01:28 +02:00
$out .= '<option value="' . $y . '"' . $selected_html . ' >' . $y . '</option>' ;
}
} else {
2021-02-23 22:03:23 +01:00
for ( $y = $min_year ; $y <= $max_year ; $y ++ ) {
2020-10-07 15:01:28 +02:00
$selected_html = '' ;
2021-02-23 22:03:23 +01:00
if ( $selected > 0 && $y == $selected ) {
$selected_html = ' selected' ;
}
2020-10-07 15:01:28 +02:00
$out .= '<option value="' . $y . '"' . $selected_html . ' >' . $y . '</option>' ;
}
}
$out .= " </select> \n " ;
2020-12-04 14:53:52 +01:00
// Add code for jquery to use multiselect
2021-02-23 22:03:23 +01:00
if ( $addjscombo ) {
2020-12-04 14:53:52 +01:00
// Enhance with select2
include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php' ;
$out .= ajax_combobox ( $htmlname );
}
2020-10-07 15:01:28 +02:00
return $out ;
}
/**
2024-09-19 13:29:07 +02:00
* Get array with HTML tabs with widgets / boxes of a particular area including personalized choices of user .
2020-10-07 15:01:28 +02:00
* Class ' Form ' must be known .
*
* @ param User $user Object User
2024-02-09 11:26:20 +01:00
* @ param string $areacode Code of area for pages - 0 = Home page ... See getListOfPagesForBoxes ()
2024-09-28 12:09:35 +02:00
* @ return array { selectboxlist : string , boxactivated : ModeleBoxes [], boxlista : string , boxlistb : string }
2020-10-07 15:01:28 +02:00
*/
public static function getBoxesArea ( $user , $areacode )
{
global $conf , $langs , $db ;
include_once DOL_DOCUMENT_ROOT . '/core/class/infobox.class.php' ;
2024-09-28 12:09:35 +02:00
// From include
'
@ phan - var - force ModeleBoxes [] $boxactivated
@ phan - var - force int [] $boxidactivatedforuser
' ;
2020-10-07 15:01:28 +02:00
$confuserzone = 'MAIN_BOXES_' . $areacode ;
2024-09-28 12:09:35 +02:00
2020-10-07 15:01:28 +02:00
// $boxactivated will be array of boxes enabled into global setup
2024-01-13 19:48:20 +01:00
// $boxidactivatedforuser will be array of boxes chose by user
2020-10-07 15:01:28 +02:00
$selectboxlist = '' ;
2023-12-04 12:04:36 +01:00
$boxactivated = InfoBox :: listBoxes ( $db , 'activated' , $areacode , ( empty ( $user -> conf -> $confuserzone ) ? null : $user ), array (), 0 ); // Search boxes of common+user (or common only if user has no specific setup)
2020-10-07 15:01:28 +02:00
$boxidactivatedforuser = array ();
2021-02-23 22:03:23 +01:00
foreach ( $boxactivated as $box ) {
if ( empty ( $user -> conf -> $confuserzone ) || $box -> fk_user == $user -> id ) {
$boxidactivatedforuser [ $box -> id ] = $box -> id ; // We keep only boxes to show for user
}
2024-09-19 13:29:07 +02:00
if ( ! empty ( $box -> lang )) {
$langs -> loadLangs ( array ( $box -> lang ));
$box -> boxlabel = $langs -> transnoentitiesnoconv ( $box -> boxlabel );
}
2020-10-07 15:01:28 +02:00
}
2024-09-19 13:29:07 +02:00
2020-10-07 15:01:28 +02:00
// Define selectboxlist
$arrayboxtoactivatelabel = array ();
2021-02-23 22:03:23 +01:00
if ( ! empty ( $user -> conf -> $confuserzone )) {
2020-10-07 15:01:28 +02:00
$boxorder = '' ;
$langs -> load ( " boxes " ); // Load label of boxes
2021-02-23 22:03:23 +01:00
foreach ( $boxactivated as $box ) {
if ( ! empty ( $boxidactivatedforuser [ $box -> id ])) {
continue ; // Already visible for user
}
2024-09-19 13:29:07 +02:00
2020-10-07 15:01:28 +02:00
$label = $langs -> transnoentitiesnoconv ( $box -> boxlabel );
//if (preg_match('/graph/',$box->class)) $label.=' ('.$langs->trans("Graph").')';
2021-02-23 22:03:23 +01:00
if ( preg_match ( '/graph/' , $box -> class ) && $conf -> browser -> layout != 'phone' ) {
2024-08-07 02:53:45 +02:00
$label .= ' <span class="fas fa-chart-bar"></span>' ;
2020-10-07 15:01:28 +02:00
}
2024-09-23 12:46:29 +02:00
$arrayboxtoactivatelabel [ $box -> id ] = array ( 'label' => $label , 'data-html' => img_picto ( '' , $box -> boximg , 'class="pictofixedwidth valignmiddle"' ) . '<span class="valignmiddle">' . $langs -> trans ( $label ) . '</span>' ); // We keep only boxes not shown for user, to show into combo list
2020-10-07 15:01:28 +02:00
}
2021-02-23 22:03:23 +01:00
foreach ( $boxidactivatedforuser as $boxid ) {
if ( empty ( $boxorder )) {
$boxorder .= 'A:' ;
}
$boxorder .= $boxid . ',' ;
2020-10-07 15:01:28 +02:00
}
2014-07-29 00:50:57 +02:00
2020-10-07 15:01:28 +02:00
//var_dump($boxidactivatedforuser);
2014-07-29 00:50:57 +02:00
2020-10-07 15:01:28 +02:00
// Class Form must have been already loaded
$selectboxlist .= '<!-- Form with select box list -->' . " \n " ;
2019-11-13 19:37:08 +01:00
$selectboxlist .= '<form id="addbox" name="addbox" method="POST" action="' . $_SERVER [ " PHP_SELF " ] . '">' ;
2020-09-24 16:19:24 +02:00
$selectboxlist .= '<input type="hidden" name="token" value="' . newToken () . '">' ;
2019-11-13 19:37:08 +01:00
$selectboxlist .= '<input type="hidden" name="addbox" value="addbox">' ;
$selectboxlist .= '<input type="hidden" name="userid" value="' . $user -> id . '">' ;
$selectboxlist .= '<input type="hidden" name="areacode" value="' . $areacode . '">' ;
$selectboxlist .= '<input type="hidden" name="boxorder" value="' . $boxorder . '">' ;
2024-03-23 16:01:41 +01:00
$selectboxlist .= Form :: selectarray ( 'boxcombo' , $arrayboxtoactivatelabel , - 1 , $langs -> trans ( " ChooseBoxToAdd " ) . '...' , 0 , 0 , '' , 0 , 0 , 0 , 'ASC' , 'maxwidth300 hideonprint' , 0 , 'hidden selected' , 0 , 0 );
2021-02-23 22:03:23 +01:00
if ( empty ( $conf -> use_javascript_ajax )) {
$selectboxlist .= ' <input type="submit" class="button" value="' . $langs -> trans ( " AddBox " ) . '">' ;
}
2020-10-07 15:01:28 +02:00
$selectboxlist .= '</form>' ;
2021-02-23 22:03:23 +01:00
if ( ! empty ( $conf -> use_javascript_ajax )) {
2020-10-07 15:01:28 +02:00
include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php' ;
$selectboxlist .= ajax_combobox ( " boxcombo " );
}
}
// Javascript code for dynamic actions
2021-02-23 22:03:23 +01:00
if ( ! empty ( $conf -> use_javascript_ajax )) {
2023-02-18 15:10:05 +01:00
$selectboxlist .= '<script nonce="' . getNonce () . ' " type= " text / javascript " >
2013-04-23 16:18:26 +02:00
2013-04-19 14:51:39 +02:00
// To update list of activated boxes
function updateBoxOrder ( closing ) {
2018-01-16 16:15:49 +01:00
var left_list = cleanSerialize ( jQuery ( " #boxhalfleft " ) . sortable ( " serialize " ));
var right_list = cleanSerialize ( jQuery ( " #boxhalfright " ) . sortable ( " serialize " ));
2013-04-19 14:51:39 +02:00
var boxorder = \ ' A : \ ' + left_list + \ ' - B : \ ' + right_list ;
if ( boxorder == \ ' A : A - B : B\ ' && closing == 1 ) // There is no more boxes on screen, and we are after a delete of a box so we must hide title
{
jQuery . ajax ({
2021-03-11 10:10:20 +01:00
url : \ '' . DOL_URL_ROOT . '/core/ajax/box.php?closing=1&boxorder=\'+boxorder+\'&zone=' . $areacode . '&userid=\'+' . $user -> id . ' ,
2013-04-19 14:51:39 +02:00
async : false
});
// We force reload to be sure to get all boxes into list
2021-09-07 14:43:37 +02:00
window . location . search = \ 'mainmenu=' . GETPOST ( " mainmenu " , " aZ09 " ) . '&leftmenu=' . GETPOST ( 'leftmenu' , " aZ09 " ) . '&action=delbox&token=' . newToken () . ' \ ' ;
2013-04-19 14:51:39 +02:00
}
else
{
jQuery . ajax ({
2017-03-10 11:30:46 +01:00
url : \ '' . DOL_URL_ROOT . '/core/ajax/box.php?closing=\'+closing+\'&boxorder=\'+boxorder+\'&zone=' . $areacode . '&userid=\'+' . $user -> id . ' ,
2013-04-19 14:51:39 +02:00
async : true
});
}
}
2013-04-23 16:18:26 +02:00
2012-08-05 21:06:48 +02:00
jQuery ( document ) . ready ( function () {
jQuery ( " #boxcombo " ) . change ( function () {
var boxid = jQuery ( " #boxcombo " ) . val ();
if ( boxid > 0 ) {
2021-04-29 10:13:43 +02:00
console . log ( " A box widget has been selected for addition, we call ajax page to add it. " )
2018-01-16 16:15:49 +01:00
var left_list = cleanSerialize ( jQuery ( " #boxhalfleft " ) . sortable ( " serialize " ));
var right_list = cleanSerialize ( jQuery ( " #boxhalfright " ) . sortable ( " serialize " ));
2012-08-05 21:06:48 +02:00
var boxorder = \ ' A : \ ' + left_list + \ ' - B : \ ' + right_list ;
2012-08-27 21:16:26 +02:00
jQuery . ajax ({
2021-04-29 10:13:43 +02:00
url : \ '' . DOL_URL_ROOT . '/core/ajax/box.php?boxorder=\'+boxorder+\'&boxid=\'+boxid+\'&zone=' . $areacode . '&userid=' . $user -> id . ' \ '
}) . done ( function () {
window . location . search = \ 'mainmenu=' . GETPOST ( " mainmenu " , " aZ09 " ) . '&leftmenu=' . GETPOST ( 'leftmenu' , " aZ09 " ) . ' \ ' ;
});
2012-08-05 21:06:48 +02:00
}
}); ' ;
2021-02-23 22:03:23 +01:00
if ( ! count ( $arrayboxtoactivatelabel )) {
$selectboxlist .= 'jQuery("#boxcombo").hide();' ;
}
2023-12-04 12:04:36 +01:00
$selectboxlist .= '
2013-04-23 16:18:26 +02:00
2018-01-16 16:15:49 +01:00
jQuery ( " #boxhalfleft, #boxhalfright " ) . sortable ({
2013-06-05 16:24:32 +02:00
handle : \ ' . boxhandle\ ' ,
revert : \ ' invalid\ ' ,
2018-01-16 16:15:49 +01:00
items : \ ' . boxdraggable\ ' ,
containment : \ ' document\ ' ,
connectWith : \ ' #boxhalfleft, #boxhalfright\',
2013-06-05 16:24:32 +02:00
stop : function ( event , ui ) {
2023-03-27 11:52:56 +02:00
console . log ( " We moved box so we call updateBoxOrder with ajax actions " );
2017-03-15 11:58:13 +01:00
updateBoxOrder ( 1 ); /* 1 to avoid message after a move */
2013-06-05 16:24:32 +02:00
}
2013-04-19 14:51:39 +02:00
});
2013-06-05 16:24:32 +02:00
jQuery ( " .boxclose " ) . click ( function () {
var self = this ; // because JQuery can modify this
2023-03-27 11:52:56 +02:00
var boxid = self . id . substring ( 8 );
if ( boxid > 0 ) {
var label = jQuery ( \ ' #boxlabelentry\'+boxid).val();
console . log ( " We close box " + boxid );
jQuery ( \ ' #boxto_\'+boxid).remove();
jQuery ( \ ' #boxcombo\').append(new Option(label, boxid));
updateBoxOrder ( 1 ); /* 1 to avoid message after a remove */
}
2013-06-05 16:24:32 +02:00
});
2013-04-23 16:18:26 +02:00
2013-06-05 16:24:32 +02:00
}); ' . " \n " ;
2013-04-23 16:18:26 +02:00
2020-10-07 15:01:28 +02:00
$selectboxlist .= '</script>' . " \n " ;
}
2012-03-19 15:51:55 +01:00
2020-10-07 15:01:28 +02:00
// Define boxlista and boxlistb
2021-03-01 20:37:16 +01:00
$boxlista = '' ;
$boxlistb = '' ;
2020-10-07 15:01:28 +02:00
$nbboxactivated = count ( $boxidactivatedforuser );
2012-03-19 15:51:55 +01:00
2021-02-23 22:03:23 +01:00
if ( $nbboxactivated ) {
2020-10-07 15:01:28 +02:00
// Load translation files required by the page
$langs -> loadLangs ( array ( " boxes " , " projects " ));
2013-01-17 17:40:27 +01:00
2020-10-07 15:01:28 +02:00
$emptybox = new ModeleBoxes ( $db );
2013-01-15 11:35:10 +01:00
2020-10-07 15:01:28 +02:00
$boxlista .= " \n <!-- Box left container --> \n " ;
2012-03-19 15:51:55 +01:00
2020-10-07 15:01:28 +02:00
// Define $box_max_lines
2024-04-30 10:20:40 +02:00
$box_max_lines = getDolUserInt ( 'MAIN_SIZE_SHORTLIST_LIMIT' , getDolGlobalInt ( 'MAIN_SIZE_SHORTLIST_LIMIT' , 5 ));
2012-03-19 15:51:55 +01:00
2020-10-07 15:01:28 +02:00
$ii = 0 ;
2021-02-23 22:03:23 +01:00
foreach ( $boxactivated as $key => $box ) {
if (( ! empty ( $user -> conf -> $confuserzone ) && $box -> fk_user == 0 ) || ( empty ( $user -> conf -> $confuserzone ) && $box -> fk_user != 0 )) {
continue ;
}
if ( empty ( $box -> box_order ) && $ii < ( $nbboxactivated / 2 )) {
$box -> box_order = 'A' . sprintf ( " %02d " , ( $ii + 1 )); // When box_order was not yet set to Axx or Bxx and is still 0
}
if ( preg_match ( '/^A/i' , $box -> box_order )) { // column A
2020-10-07 15:01:28 +02:00
$ii ++ ;
//print 'box_id '.$boxactivated[$ii]->box_id.' ';
//print 'box_order '.$boxactivated[$ii]->box_order.'<br>';
// Show box
$box -> loadBox ( $box_max_lines );
$boxlista .= $box -> showBox ( null , null , 1 );
}
}
2021-02-23 22:03:23 +01:00
if ( $conf -> browser -> layout != 'phone' ) {
2020-10-07 15:01:28 +02:00
$emptybox -> box_id = 'A' ;
$emptybox -> info_box_head = array ();
$emptybox -> info_box_contents = array ();
$boxlista .= $emptybox -> showBox ( array (), array (), 1 );
}
$boxlista .= " <!-- End box left container --> \n " ;
$boxlistb .= " \n <!-- Box right container --> \n " ;
$ii = 0 ;
2021-02-23 22:03:23 +01:00
foreach ( $boxactivated as $key => $box ) {
if (( ! empty ( $user -> conf -> $confuserzone ) && $box -> fk_user == 0 ) || ( empty ( $user -> conf -> $confuserzone ) && $box -> fk_user != 0 )) {
continue ;
}
if ( empty ( $box -> box_order ) && $ii < ( $nbboxactivated / 2 )) {
$box -> box_order = 'B' . sprintf ( " %02d " , ( $ii + 1 )); // When box_order was not yet set to Axx or Bxx and is still 0
}
if ( preg_match ( '/^B/i' , $box -> box_order )) { // colonne B
2020-10-07 15:01:28 +02:00
$ii ++ ;
//print 'box_id '.$boxactivated[$ii]->box_id.' ';
//print 'box_order '.$boxactivated[$ii]->box_order.'<br>';
// Show box
$box -> loadBox ( $box_max_lines );
$boxlistb .= $box -> showBox ( null , null , 1 );
}
}
2021-02-23 22:03:23 +01:00
if ( $conf -> browser -> layout != 'phone' ) {
2020-10-07 15:01:28 +02:00
$emptybox -> box_id = 'B' ;
$emptybox -> info_box_head = array ();
$emptybox -> info_box_contents = array ();
$boxlistb .= $emptybox -> showBox ( array (), array (), 1 );
}
$boxlistb .= " <!-- End box right container --> \n " ;
}
2024-03-21 22:26:56 +01:00
return array ( 'selectboxlist' => count ( $boxactivated ) ? $selectboxlist : '' , 'boxactivated' => $boxactivated , 'boxlista' => $boxlista , 'boxlistb' => $boxlistb );
2020-10-07 15:01:28 +02:00
}
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Return a HTML select list of a dictionary
*
* @ param string $htmlname Name of select zone
* @ param string $dictionarytable Dictionary table
* @ param string $keyfield Field for key
* @ param string $labelfield Label field
* @ param string $selected Selected value
* @ 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 More attributes on HTML select tag
* @ return void
*/
public function select_dictionary ( $htmlname , $dictionarytable , $keyfield = 'code' , $labelfield = 'label' , $selected = '' , $useempty = 0 , $moreattrib = '' )
{
// phpcs:enable
global $langs , $conf ;
$langs -> load ( " admin " );
$sql = " SELECT rowid, " . $keyfield . " , " . $labelfield ;
2022-01-27 10:19:35 +01:00
$sql .= " FROM " . $this -> db -> prefix () . $dictionarytable ;
2020-10-07 15:01:28 +02:00
$sql .= " ORDER BY " . $labelfield ;
dol_syslog ( get_class ( $this ) . " ::select_dictionary " , LOG_DEBUG );
$result = $this -> db -> query ( $sql );
2021-02-23 22:03:23 +01:00
if ( $result ) {
2020-10-07 15:01:28 +02:00
$num = $this -> db -> num_rows ( $result );
$i = 0 ;
2021-02-23 22:03:23 +01:00
if ( $num ) {
2020-10-07 15:01:28 +02:00
print '<select id="select' . $htmlname . '" class="flat selectdictionary" name="' . $htmlname . '"' . ( $moreattrib ? ' ' . $moreattrib : '' ) . '>' ;
2021-02-23 22:03:23 +01:00
if ( $useempty == 1 || ( $useempty == 2 && $num > 1 )) {
2020-10-07 15:01:28 +02:00
print '<option value="-1"> </option>' ;
}
2021-02-23 22:03:23 +01:00
while ( $i < $num ) {
2020-10-07 15:01:28 +02:00
$obj = $this -> db -> fetch_object ( $result );
2021-11-19 14:27:29 +01:00
if ( $selected == $obj -> rowid || $selected == $obj -> { $keyfield }) {
print '<option value="' . $obj -> { $keyfield } . '" selected>' ;
2020-10-07 15:01:28 +02:00
} else {
2021-11-19 14:27:29 +01:00
print '<option value="' . $obj -> { $keyfield } . '">' ;
2020-10-07 15:01:28 +02:00
}
2023-12-27 12:12:20 +01:00
$label = ( $langs -> trans ( $dictionarytable . $obj -> { $keyfield }) != $dictionarytable . $obj -> { $labelfield } ? $langs -> trans ( $dictionarytable . $obj -> { $keyfield }) : $obj -> { $labelfield });
2021-11-19 14:30:33 +01:00
print $label ;
2020-10-07 15:01:28 +02:00
print '</option>' ;
$i ++ ;
}
print " </select> " ;
} else {
print $langs -> trans ( " DictionaryEmpty " );
}
} else {
dol_print_error ( $this -> db );
}
}
/**
2019-03-31 19:26:40 +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 automatic / manual , 1 return 1 / 0
* @ param bool $disabled true or false
* @ param int $useempty 1 = Add empty line
* @ return string See option
*/
2020-10-07 15:01:28 +02:00
public function selectAutoManual ( $htmlname , $value = '' , $option = 0 , $disabled = false , $useempty = 0 )
2019-03-31 19:26:40 +02:00
{
global $langs ;
2021-03-01 20:37:16 +01:00
$automatic = " automatic " ;
$manual = " manual " ;
2021-02-23 22:03:23 +01:00
if ( $option ) {
2019-11-13 19:37:08 +01:00
$automatic = " 1 " ;
$manual = " 0 " ;
2019-03-31 19:26:40 +02:00
}
$disabled = ( $disabled ? ' disabled' : '' );
$resultautomanual = '<select class="flat width100" id="' . $htmlname . '" name="' . $htmlname . '"' . $disabled . '>' . " \n " ;
2021-02-23 22:03:23 +01:00
if ( $useempty ) {
$resultautomanual .= '<option value="-1"' . (( $value < 0 ) ? ' selected' : '' ) . '> </option>' . " \n " ;
}
if (( " $value " == 'automatic' ) || ( $value == 1 )) {
2019-03-31 19:26:40 +02:00
$resultautomanual .= '<option value="' . $automatic . '" selected>' . $langs -> trans ( " Automatic " ) . '</option>' . " \n " ;
$resultautomanual .= '<option value="' . $manual . '">' . $langs -> trans ( " Manual " ) . '</option>' . " \n " ;
2020-05-21 15:05:19 +02:00
} else {
2021-02-23 22:03:23 +01:00
$selected = (( $useempty && $value != '0' && $value != 'manual' ) ? '' : ' selected' );
2019-03-31 19:26:40 +02:00
$resultautomanual .= '<option value="' . $automatic . '">' . $langs -> trans ( " Automatic " ) . '</option>' . " \n " ;
$resultautomanual .= '<option value="' . $manual . '"' . $selected . '>' . $langs -> trans ( " Manual " ) . '</option>' . " \n " ;
}
$resultautomanual .= '</select>' . " \n " ;
return $resultautomanual ;
}
2020-03-06 17:13:51 +01:00
/**
* Return HTML select list to select a group by field
*
2024-09-28 12:09:35 +02:00
* @ param mixed $object Object analyzed
* @ param string [] $search_groupby Array of preselected fields
* @ param array < string , array { label : string } > $arrayofgroupby Array of groupby to fill
* @ param string $morecss More CSS
* @ param string $showempty '1' or 'text'
* @ return string HTML string component
2020-03-06 17:13:51 +01:00
*/
2022-02-15 11:03:48 +01:00
public function selectGroupByField ( $object , $search_groupby , & $arrayofgroupby , $morecss = 'minwidth200 maxwidth250' , $showempty = '1' )
2020-03-09 18:55:47 +01:00
{
2020-03-06 17:13:51 +01:00
global $langs , $extrafields , $form ;
$arrayofgroupbylabel = array ();
foreach ( $arrayofgroupby as $key => $val ) {
$arrayofgroupbylabel [ $key ] = $val [ 'label' ];
}
2022-02-15 11:03:48 +01:00
$result = $form -> selectarray ( 'search_groupby' , $arrayofgroupbylabel , $search_groupby , $showempty , 0 , 0 , '' , 0 , 0 , 0 , '' , $morecss , 1 );
2020-03-06 17:13:51 +01:00
return $result ;
}
/**
* Return HTML select list to select a group by field
*
* @ param mixed $object Object analyzed
2024-09-28 12:09:35 +02:00
* @ param string [] $search_xaxis Array of preselected fields
* @ param array < string , array { label : string } > $arrayofxaxis Array of groupby to fill
2022-02-15 11:03:48 +01:00
* @ param string $showempty '1' or 'text'
2022-07-18 14:51:03 +02:00
* @ param string $morecss More css
2022-02-15 11:03:48 +01:00
* @ return string HTML string component
2020-03-06 17:13:51 +01:00
*/
2022-07-18 14:51:03 +02:00
public function selectXAxisField ( $object , $search_xaxis , & $arrayofxaxis , $showempty = '1' , $morecss = 'minwidth250 maxwidth500' )
2020-03-09 18:55:47 +01:00
{
2022-02-21 19:09:26 +01:00
global $form ;
2020-03-08 19:25:00 +01:00
2020-03-06 17:13:51 +01:00
$arrayofxaxislabel = array ();
foreach ( $arrayofxaxis as $key => $val ) {
$arrayofxaxislabel [ $key ] = $val [ 'label' ];
}
2022-07-18 14:51:03 +02:00
$result = $form -> selectarray ( 'search_xaxis' , $arrayofxaxislabel , $search_xaxis , $showempty , 0 , 0 , '' , 0 , 0 , 0 , '' , $morecss , 1 );
2020-03-06 17:13:51 +01:00
return $result ;
}
2010-05-03 10:43:32 +02:00
}