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 >
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
2010-05-03 10:43:32 +02:00
* \brief Fichier de la classe des fonctions predefinie de composants html autre
*/
/**
2012-01-27 15:17:36 +01:00
* Classe permettant la generation de composants html autre
* Only common components are here .
2010-05-03 10:43:32 +02:00
*/
class FormOther
{
2017-01-16 21:40:13 +01:00
private $db ;
2018-09-02 16:45:03 +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
2012-02-25 16:24:36 +01:00
/**
* Constructor
*
* @ param DoliDB $db Database handler
*/
2019-02-27 20:45:07 +01:00
public function __construct ( $db )
2012-02-25 16:24:36 +01:00
{
$this -> db = $db ;
}
2010-05-03 10:43:32 +02:00
2019-02-27 20:45:07 +01:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2012-02-25 16:24:36 +01:00
/**
2011-05-21 19:14:07 +02:00
* Return HTML select list of export models
2012-01-15 17:40:44 +01:00
*
2012-02-25 16:24:36 +01:00
* @ param string $selected Id modele pre - selectionne
* @ param string $htmlname Nom de la zone select
* @ param string $type Type des modeles recherches
2019-03-26 12:12:16 +01:00
* @ param int $useempty Show an empty value in list
* @ param int $fk_user User that has created the template ( this is set to null to get all export model when EXPORTS_SHARE_MODELS is on )
2012-02-25 16:24:36 +01:00
* @ return void
*/
2019-02-27 20:45:07 +01:00
public function select_export_model ( $selected = '' , $htmlname = 'exportmodelid' , $type = '' , $useempty = 0 , $fk_user = null )
2012-02-25 16:24:36 +01:00
{
2018-09-05 18:49:06 +02:00
// phpcs:enable
2019-12-23 12:24:27 +01:00
global $conf , $langs , $user ;
2019-12-23 13:49:13 +01:00
$sql = " SELECT rowid, label, fk_user " ;
2019-11-13 19:37:08 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " export_model " ;
2019-12-23 13:49:13 +01:00
$sql .= " WHERE type = ' " . $this -> db -> escape ( $type ) . " ' " ;
2019-11-13 19:37:08 +01:00
if ( ! empty ( $fk_user )) $sql .= " AND fk_user IN (0, " . $fk_user . " ) " ; // An export model
2020-04-22 18:26:26 +02:00
$sql .= " ORDER BY label " ;
2012-02-25 16:24:36 +01:00
$result = $this -> db -> query ( $sql );
if ( $result )
{
2019-12-23 12:24:27 +01:00
print '<select class="flat minwidth200" name="' . $htmlname . '" id="' . $htmlname . '">' ;
2012-02-25 16:24:36 +01:00
if ( $useempty )
{
print '<option value="-1"> </option>' ;
}
$num = $this -> db -> num_rows ( $result );
$i = 0 ;
while ( $i < $num )
{
$obj = $this -> db -> fetch_object ( $result );
2019-12-23 12:24:27 +01:00
$label = $obj -> label ;
2019-12-23 13:02:30 +01:00
if ( $obj -> fk_user == 0 ) {
$label .= ' <span class="opacitymedium">(' . $langs -> trans ( " Everybody " ) . ')</span>' ;
}
2020-03-12 12:45:44 +01:00
elseif ( ! empty ( $conf -> global -> EXPORTS_SHARE_MODELS ) && empty ( $fk_user ) && is_object ( $user ) && $user -> id != $obj -> fk_user ) {
2019-12-23 12:24:27 +01:00
$tmpuser = new User ( $this -> db );
$tmpuser -> fetch ( $obj -> fk_user );
2019-12-23 13:02:30 +01:00
$label .= ' <span class="opacitymedium">(' . $tmpuser -> getFullName ( $langs ) . ')</span>' ;
2019-12-23 12:24:27 +01:00
}
2012-02-25 16:24:36 +01:00
if ( $selected == $obj -> rowid )
{
2019-12-23 12:24:27 +01:00
print '<option value="' . $obj -> rowid . '" selected data-html="' . dol_escape_htmltag ( $label ) . '">' ;
2012-02-25 16:24:36 +01:00
}
else
{
2019-12-23 12:24:27 +01:00
print '<option value="' . $obj -> rowid . '" data-html="' . dol_escape_htmltag ( $label ) . '">' ;
2019-12-23 13:49:13 +01:00
}
2019-12-23 12:24:27 +01:00
print $label ;
2012-02-25 16:24:36 +01:00
print '</option>' ;
$i ++ ;
}
print " </select> " ;
2019-12-23 12:24:27 +01:00
print ajax_combobox ( $htmlname );
2012-02-25 16:24:36 +01:00
}
else {
dol_print_error ( $this -> db );
}
}
2019-02-27 20:45:07 +01:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2012-02-25 16:24:36 +01:00
/**
2011-05-21 19:14:07 +02:00
* Return list of export models
2012-01-15 17:40:44 +01:00
*
2012-02-25 16:24:36 +01:00
* @ 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
2019-12-23 13:02:30 +01:00
* @ param int $fk_user User that has created the template ( this is set to null to get all export model when EXPORTS_SHARE_MODELS is on )
2012-02-25 16:24:36 +01:00
* @ return void
*/
2019-12-23 13:02:30 +01:00
public function select_import_model ( $selected = '' , $htmlname = 'importmodelid' , $type = '' , $useempty = 0 , $fk_user = null )
2012-02-25 16:24:36 +01:00
{
2018-09-05 18:49:06 +02:00
// phpcs:enable
2019-12-23 13:02:30 +01:00
global $conf , $langs , $user ;
$sql = " SELECT rowid, label, fk_user " ;
2019-11-13 19:37:08 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " import_model " ;
2019-12-23 13:02:30 +01:00
$sql .= " WHERE type = ' " . $this -> db -> escape ( $type ) . " ' " ;
if ( ! empty ( $fk_user )) $sql .= " AND fk_user IN (0, " . $fk_user . " ) " ; // An export model
2019-11-13 19:37:08 +01:00
$sql .= " ORDER BY rowid " ;
2012-02-25 16:24:36 +01:00
$result = $this -> db -> query ( $sql );
if ( $result )
{
2019-12-23 12:24:27 +01:00
print '<select class="flat minwidth200" name="' . $htmlname . '" id="' . $htmlname . '">' ;
2012-02-25 16:24:36 +01:00
if ( $useempty )
{
print '<option value="-1"> </option>' ;
}
$num = $this -> db -> num_rows ( $result );
$i = 0 ;
while ( $i < $num )
{
$obj = $this -> db -> fetch_object ( $result );
2019-12-23 13:02:30 +01:00
$label = $obj -> label ;
if ( $obj -> fk_user == 0 ) {
$label .= ' <span class="opacitymedium">(' . $langs -> trans ( " Everybody " ) . ')</span>' ;
}
2020-03-12 12:45:44 +01:00
elseif ( ! empty ( $conf -> global -> EXPORTS_SHARE_MODELS ) && empty ( $fk_user ) && is_object ( $user ) && $user -> id != $obj -> fk_user ) {
2019-12-23 13:02:30 +01:00
$tmpuser = new User ( $this -> db );
$tmpuser -> fetch ( $obj -> fk_user );
$label .= ' <span class="opacitymedium">(' . $tmpuser -> getFullName ( $langs ) . ')</span>' ;
}
2012-02-25 16:24:36 +01:00
if ( $selected == $obj -> rowid )
{
2019-12-23 13:02:30 +01:00
print '<option value="' . $obj -> rowid . '" selected data-html="' . dol_escape_htmltag ( $label ) . '">' ;
2012-02-25 16:24:36 +01:00
}
else
{
2019-12-23 13:02:30 +01:00
print '<option value="' . $obj -> rowid . '" data-html="' . dol_escape_htmltag ( $label ) . '">' ;
2012-02-25 16:24:36 +01:00
}
2019-12-23 13:02:30 +01:00
print $label ;
2012-02-25 16:24:36 +01:00
print '</option>' ;
$i ++ ;
}
print " </select> " ;
2019-12-23 12:24:27 +01:00
print ajax_combobox ( $htmlname );
2012-02-25 16:24:36 +01:00
}
else {
dol_print_error ( $this -> db );
}
}
2019-02-27 20:45:07 +01:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2012-02-25 16:24:36 +01:00
/**
2013-03-24 00:35:40 +01:00
* Return list of ecotaxes with label
2012-02-25 16:24:36 +01:00
*
2013-03-24 00:35:40 +01:00
* @ param string $selected Preselected ecotaxes
* @ param string $htmlname Name of combo list
2015-03-06 03:10:01 +01:00
* @ return integer
2012-02-25 16:24:36 +01:00
*/
2019-02-27 20:45:07 +01:00
public function select_ecotaxes ( $selected = '' , $htmlname = 'ecotaxe_id' )
2012-02-25 16:24:36 +01:00
{
2018-09-05 18:49:06 +02:00
// phpcs:enable
2012-02-25 16:24:36 +01:00
global $langs ;
2018-06-25 09:10:24 +02:00
$sql = " SELECT e.rowid, e.code, e.label, e.price, e.organization, " ;
2019-11-13 19:37:08 +01:00
$sql .= " c.label as country " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " c_ecotaxe as e, " . MAIN_DB_PREFIX . " c_country as c " ;
$sql .= " WHERE e.active = 1 AND e.fk_pays = c.rowid " ;
$sql .= " ORDER BY country, e.organization ASC, e.code ASC " ;
2010-05-03 10:43:32 +02:00
2014-06-13 01:34:39 +02:00
dol_syslog ( get_class ( $this ) . '::select_ecotaxes' , LOG_DEBUG );
2019-11-13 19:37:08 +01:00
$resql = $this -> db -> query ( $sql );
2012-02-25 16:24:36 +01:00
if ( $resql )
{
print '<select class="flat" name="' . $htmlname . '">' ;
$num = $this -> db -> num_rows ( $resql );
$i = 0 ;
print '<option value="-1"> </option>' . " \n " ;
if ( $num )
{
while ( $i < $num )
{
$obj = $this -> db -> fetch_object ( $resql );
if ( $selected && $selected == $obj -> rowid )
{
2015-05-07 12:20:20 +02:00
print '<option value="' . $obj -> rowid . '" selected>' ;
2012-02-25 16:24:36 +01:00
}
else
{
print '<option value="' . $obj -> rowid . '">' ;
2018-06-25 09:10:24 +02:00
//print '<option onmouseover="showtip(\''.$obj->label.'\')" onMouseout="hidetip()" value="'.$obj->rowid.'">';
2012-02-25 16:24:36 +01:00
}
2018-06-25 13:02:07 +02:00
$selectOptionValue = $obj -> code . ' - ' . $obj -> label . ' : ' . price ( $obj -> price ) . ' ' . $langs -> trans ( " HT " ) . ' (' . $obj -> organization . ')' ;
2012-02-25 16:24:36 +01:00
print $selectOptionValue ;
print '</option>' ;
$i ++ ;
}
}
print '</select>' ;
return 0 ;
}
else
{
dol_print_error ( $this -> db );
return 1 ;
}
}
2013-03-24 00:35:40 +01:00
2019-02-27 20:45:07 +01:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2013-03-30 14:27:13 +01:00
/**
* Return list of revenue stamp for country
*
2013-04-04 13:58:33 +02:00
* @ 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
2013-03-30 14:27:13 +01:00
*/
2019-02-27 20:45:07 +01:00
public function select_revenue_stamp ( $selected = '' , $htmlname = 'revenuestamp' , $country_code = '' )
2013-03-30 14:27:13 +01:00
{
2018-09-05 18:49:06 +02:00
// phpcs:enable
2013-03-30 14:27:13 +01:00
global $langs ;
2020-04-22 21:29:15 +02:00
2019-11-13 19:37:08 +01:00
$out = '' ;
2013-03-24 00:35:40 +01:00
2017-12-18 12:43:03 +01:00
$sql = " SELECT r.taux, r.revenuestamp_type " ;
2019-11-13 19:37:08 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " c_revenuestamp as r, " . MAIN_DB_PREFIX . " c_country as c " ;
$sql .= " WHERE r.active = 1 AND r.fk_pays = c.rowid " ;
$sql .= " AND c.code = ' " . $country_code . " ' " ;
2013-03-30 14:27:13 +01:00
2014-06-13 01:34:39 +02:00
dol_syslog ( get_class ( $this ) . '::select_revenue_stamp' , LOG_DEBUG );
2019-11-13 19:37:08 +01:00
$resql = $this -> db -> query ( $sql );
2013-03-30 14:27:13 +01:00
if ( $resql )
{
2019-11-13 19:37:08 +01:00
$out .= '<select class="flat" name="' . $htmlname . '">' ;
2013-03-30 14:27:13 +01:00
$num = $this -> db -> num_rows ( $resql );
$i = 0 ;
2019-11-13 19:37:08 +01:00
$out .= '<option value="0"> </option>' . " \n " ;
2013-03-30 14:27:13 +01:00
if ( $num )
{
while ( $i < $num )
{
$obj = $this -> db -> fetch_object ( $resql );
if (( $selected && $selected == $obj -> taux ) || $num == 1 )
{
2019-11-13 19:37:08 +01:00
$out .= '<option value="' . $obj -> taux . ( $obj -> revenuestamp_type == 'percent' ? '%' : '' ) . '"' . ( $obj -> revenuestamp_type == 'percent' ? ' data-type="percent"' : '' ) . ' selected>' ;
2013-03-30 14:27:13 +01:00
}
else
{
2019-11-13 19:37:08 +01:00
$out .= '<option value="' . $obj -> taux . ( $obj -> revenuestamp_type == 'percent' ? '%' : '' ) . '"' . ( $obj -> revenuestamp_type == 'percent' ? ' data-type="percent"' : '' ) . '>' ;
2013-03-30 14:27:13 +01:00
//print '<option onmouseover="showtip(\''.$obj->libelle.'\')" onMouseout="hidetip()" value="'.$obj->rowid.'">';
}
2019-11-13 19:37:08 +01:00
$out .= $obj -> taux . ( $obj -> revenuestamp_type == 'percent' ? '%' : '' );
$out .= '</option>' ;
2013-03-30 14:27:13 +01:00
$i ++ ;
}
}
2019-11-13 19:37:08 +01:00
$out .= '</select>' ;
2013-03-30 14:27:13 +01:00
return $out ;
}
else
{
dol_print_error ( $this -> db );
return '' ;
}
2013-03-24 00:35:40 +01:00
}
2019-02-27 20:45:07 +01:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2012-02-25 16:24:36 +01:00
/**
* Return a HTML select list to select a percent
*
2015-03-06 03:10:01 +01:00
* @ param integer $selected pourcentage pre - selectionne
2012-02-25 16:24:36 +01:00
* @ 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
2017-05-18 11:35:12 +02:00
* @ param int $showempty Add also an empty line
2012-02-25 16:24:36 +01:00
* @ return string HTML select string
*/
2019-02-27 20:45:07 +01:00
public function select_percent ( $selected = 0 , $htmlname = 'percent' , $disabled = 0 , $increment = 5 , $start = 0 , $end = 100 , $showempty = 0 )
2012-02-25 16:24:36 +01:00
{
2018-09-05 18:49:06 +02:00
// phpcs:enable
2019-11-13 19:37:08 +01:00
$return = '<select class="flat" name="' . $htmlname . '" ' . ( $disabled ? 'disabled' : '' ) . '>' ;
if ( $showempty ) $return .= '<option value="-1"' . (( $selected == - 1 || $selected == '' ) ? ' selected' : '' ) . '> </option>' ;
2012-02-25 16:24:36 +01:00
2019-11-13 19:37:08 +01:00
for ( $i = $start ; $i <= $end ; $i += $increment )
2012-02-25 16:24:36 +01:00
{
2017-05-18 11:35:12 +02:00
if ( $selected != '' && ( int ) $selected == $i )
2012-02-25 16:24:36 +01:00
{
2019-11-13 19:37:08 +01:00
$return .= '<option value="' . $i . '" selected>' ;
2012-02-25 16:24:36 +01:00
}
else
{
2019-11-13 19:37:08 +01:00
$return .= '<option value="' . $i . '">' ;
2012-02-25 16:24:36 +01:00
}
2019-11-13 19:37:08 +01:00
$return .= $i . ' % ' ;
$return .= '</option>' ;
2012-02-25 16:24:36 +01:00
}
2019-11-13 19:37:08 +01:00
$return .= '</select>' ;
2012-02-25 16:24:36 +01:00
return $return ;
}
2019-02-27 20:45:07 +01:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2012-02-25 16:24:36 +01:00
/**
2012-07-18 00:20:33 +02:00
* Return select list for categories ( to use in form search selectors )
2012-02-25 16:24:36 +01:00
*
2016-05-22 16:36:48 +02:00
* @ param int $type Type of category ( 'customer' , 'supplier' , 'contact' , 'product' , 'member' ) . Old mode ( 0 , 1 , 2 , ... ) is deprecated .
2015-08-20 04:07:07 +02:00
* @ param integer $selected Preselected value
* @ param string $htmlname Name of combo list
2012-07-18 00:20:33 +02:00
* @ param int $nocateg Show also an entry " Not categorized "
2015-08-20 04:07:07 +02:00
* @ param int $showempty Add also an empty line
2017-06-14 11:28:42 +02:00
* @ param string $morecss More CSS
* @ return string Html combo list code
2019-04-04 18:33:12 +02:00
* @ see select_all_categories ()
2012-02-25 16:24:36 +01:00
*/
2019-02-27 20:45:07 +01:00
public function select_categories ( $type , $selected = 0 , $htmlname = 'search_categ' , $nocateg = 0 , $showempty = 1 , $morecss = '' )
2012-02-25 16:24:36 +01:00
{
2018-09-05 18:49:06 +02:00
// phpcs:enable
2014-12-28 15:17:54 +01:00
global $conf , $langs ;
2012-08-22 23:11:24 +02:00
require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php' ;
2012-02-25 16:24:36 +01:00
2016-05-22 16:36:48 +02:00
// For backward compatibility
if ( is_numeric ( $type ))
{
2019-11-13 19:37:08 +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
}
2017-06-12 14:09:00 +02:00
2012-02-25 16:24:36 +01:00
// Load list of "categories"
$static_categs = new Categorie ( $this -> db );
$tab_categs = $static_categs -> get_full_arbo ( $type );
2014-12-28 15:17:54 +01:00
$moreforfilter = '' ;
// Enhance with select2
if ( $conf -> use_javascript_ajax )
{
2019-11-13 19:37:08 +01:00
include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php' ;
2015-01-31 19:25:26 +01:00
$comboenhancement = ajax_combobox ( 'select_categ_' . $htmlname );
2019-11-13 19:37:08 +01:00
$moreforfilter .= $comboenhancement ;
2014-12-28 15:17:54 +01:00
}
2012-02-25 16:24:36 +01:00
// Print a select with each of them
2019-11-13 19:37:08 +01:00
$moreforfilter .= '<select class="flat minwidth100' . ( $morecss ? ' ' . $morecss : '' ) . '" id="select_categ_' . $htmlname . '" name="' . $htmlname . '">' ;
if ( $showempty ) $moreforfilter .= '<option value="0"> </option>' ; // Should use -1 to say nothing
2012-08-05 21:06:48 +02:00
2012-02-25 16:24:36 +01:00
if ( is_array ( $tab_categs ))
{
foreach ( $tab_categs as $categ )
{
2019-11-13 19:37:08 +01:00
$moreforfilter .= '<option value="' . $categ [ 'id' ] . '"' ;
if ( $categ [ 'id' ] == $selected ) $moreforfilter .= ' selected' ;
$moreforfilter .= '>' . dol_trunc ( $categ [ 'fulllabel' ], 50 , 'middle' ) . '</option>' ;
2012-02-25 16:24:36 +01:00
}
}
2012-08-05 21:06:48 +02:00
if ( $nocateg )
2012-07-18 00:20:33 +02:00
{
$langs -> load ( " categories " );
2019-11-13 19:37:08 +01:00
$moreforfilter .= '<option value="-2"' . ( $selected == - 2 ? ' selected' : '' ) . '>- ' . $langs -> trans ( " NotCategorized " ) . ' -</option>' ;
2012-07-18 00:20:33 +02:00
}
2019-11-13 19:37:08 +01:00
$moreforfilter .= '</select>' ;
2012-02-25 16:24:36 +01:00
return $moreforfilter ;
}
2019-02-27 20:45:07 +01:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2012-02-25 16:24:36 +01:00
/**
* Return select list for categories ( to use in form search selectors )
*
2019-11-08 13:43:26 +01:00
* @ param string $selected Preselected value
* @ 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
* @ param int $showempty 1 = show also an empty value
* @ param string $morecss More CSS
* @ param int $norepresentative Show also an entry " Not categorized "
* @ return string Html combo list code
2012-02-25 16:24:36 +01:00
*/
2019-11-08 13:43:26 +01:00
public function select_salesrepresentatives ( $selected , $htmlname , $user , $showstatus = 0 , $showempty = 1 , $morecss = '' , $norepresentative = 0 )
2012-02-25 16:24:36 +01:00
{
2018-09-05 18:49:06 +02:00
// phpcs:enable
2020-03-16 11:49:03 +01:00
global $conf , $langs , $hookmanager ;
2019-06-13 12:11:31 +02:00
2013-07-22 11:17:45 +02:00
$langs -> load ( 'users' );
2012-02-25 16:24:36 +01:00
2014-12-23 16:42:05 +01:00
$out = '' ;
// Enhance with select2
if ( $conf -> use_javascript_ajax )
{
2020-03-12 12:45:44 +01:00
include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php' ;
2015-04-18 04:18:59 +02:00
2015-01-31 19:25:26 +01:00
$comboenhancement = ajax_combobox ( $htmlname );
2015-04-18 04:18:59 +02:00
if ( $comboenhancement )
2015-04-15 18:14:26 +02:00
{
2020-03-12 12:45:44 +01:00
$out .= $comboenhancement ;
2015-04-15 18:14:26 +02:00
}
2014-12-23 16:42:05 +01:00
}
2020-03-16 11:49:03 +01:00
$reshook = $hookmanager -> executeHooks ( 'addSQLWhereFilterOnSelectSalesRep' , array (), $this , $action );
2012-02-25 16:24:36 +01:00
// Select each sales and print them in a select input
2020-03-12 12:45:44 +01:00
$out .= '<select class="flat' . ( $morecss ? ' ' . $morecss : '' ) . '" id="' . $htmlname . '" name="' . $htmlname . '">' ;
if ( $showempty ) $out .= '<option value="0"> </option>' ;
2012-02-25 16:24:36 +01:00
// Get list of users allowed to be viewed
2013-09-14 14:41:12 +02:00
$sql_usr = " SELECT u.rowid, u.lastname, u.firstname, u.statut, u.login " ;
2020-03-12 12:45:44 +01:00
$sql_usr .= " FROM " . MAIN_DB_PREFIX . " user as u " ;
2019-04-16 10:16:20 +02:00
2020-03-12 12:45:44 +01:00
if ( ! empty ( $conf -> global -> MULTICOMPANY_TRANSVERSE_MODE ))
2019-04-16 10:16:20 +02:00
{
2020-03-12 12:45:44 +01:00
if ( ! empty ( $user -> admin ) && empty ( $user -> entity ) && $conf -> entity == 1 ) {
$sql_usr .= " WHERE u.entity IS NOT NULL " ; // Show all users
2019-04-16 10:16:20 +02:00
} else {
2020-03-12 12:45:44 +01:00
$sql_usr .= " WHERE EXISTS (SELECT ug.fk_user FROM " . MAIN_DB_PREFIX . " usergroup_user as ug WHERE u.rowid = ug.fk_user AND ug.entity IN ( " . getEntity ( 'usergroup' ) . " )) " ;
$sql_usr .= " OR u.entity = 0 " ; // Show always superadmin
2019-04-16 10:16:20 +02:00
}
}
else
{
2020-03-12 12:45:44 +01:00
$sql_usr .= " WHERE u.entity IN ( " . getEntity ( 'user' ) . " ) " ;
2019-04-16 10:16:20 +02:00
}
2020-03-12 12:45:44 +01:00
if ( empty ( $user -> rights -> user -> user -> lire )) $sql_usr .= " AND u.rowid = " . $user -> id ;
if ( ! empty ( $user -> socid )) $sql_usr .= " AND u.fk_soc = " . $user -> socid ;
2020-03-16 11:49:03 +01:00
//Add hook to filter on user (for exemple on usergroup define in custom modules)
if ( ! empty ( $reshook )) $sql_usr .= $hookmanager -> resArray [ 0 ];
2013-09-14 14:34:45 +02:00
// Add existing sales representatives of thirdparty of external user
2019-04-16 10:16:20 +02:00
if ( empty ( $user -> rights -> user -> user -> lire ) && $user -> socid )
2012-02-25 16:24:36 +01:00
{
2020-03-12 12:45:44 +01:00
$sql_usr .= " UNION " ;
$sql_usr .= " SELECT u2.rowid, u2.lastname, u2.firstname, u2.statut, u2.login " ;
$sql_usr .= " FROM " . MAIN_DB_PREFIX . " user as u2, " . MAIN_DB_PREFIX . " societe_commerciaux as sc " ;
2019-04-16 10:16:20 +02:00
2020-03-12 12:45:44 +01:00
if ( ! empty ( $conf -> global -> MULTICOMPANY_TRANSVERSE_MODE ))
2019-04-16 10:16:20 +02:00
{
2020-03-12 12:45:44 +01:00
if ( ! empty ( $user -> admin ) && empty ( $user -> entity ) && $conf -> entity == 1 ) {
$sql_usr .= " WHERE u2.entity IS NOT NULL " ; // Show all users
2019-04-16 10:16:20 +02:00
} else {
2020-03-12 12:45:44 +01:00
$sql_usr .= " WHERE EXISTS (SELECT ug2.fk_user FROM " . MAIN_DB_PREFIX . " usergroup_user as ug2 WHERE u2.rowid = ug2.fk_user AND ug2.entity IN ( " . getEntity ( 'usergroup' ) . " )) " ;
2019-04-16 10:16:20 +02:00
}
}
else
{
2020-03-12 12:45:44 +01:00
$sql_usr .= " WHERE u2.entity IN ( " . getEntity ( 'user' ) . " ) " ;
2019-04-16 10:16:20 +02:00
}
2020-03-12 12:45:44 +01:00
$sql_usr .= " AND u2.rowid = sc.fk_user AND sc.fk_soc= " . $user -> socid ;
2020-03-16 11:49:03 +01:00
//Add hook to filter on user (for exemple on usergroup define in custom modules)
if ( ! empty ( $reshook )) $sql_usr .= $hookmanager -> resArray [ 1 ];
2012-02-25 16:24:36 +01:00
}
2020-03-12 12:45:44 +01:00
$sql_usr .= " ORDER BY statut DESC, lastname ASC " ; // Do not use 'ORDER BY u.statut' here, not compatible with the UNION.
2010-09-19 14:50:53 +02:00
//print $sql_usr;exit;
2010-05-03 10:43:32 +02:00
2010-09-19 14:50:53 +02:00
$resql_usr = $this -> db -> query ( $sql_usr );
2012-02-25 16:24:36 +01:00
if ( $resql_usr )
{
while ( $obj_usr = $this -> db -> fetch_object ( $resql_usr ))
{
2020-03-12 12:45:44 +01:00
$out .= '<option value="' . $obj_usr -> rowid . '"' ;
2014-12-23 16:42:05 +01:00
2020-03-12 12:45:44 +01:00
if ( $obj_usr -> rowid == $selected ) $out .= ' selected' ;
2012-02-25 16:24:36 +01:00
2020-03-12 12:45:44 +01:00
$out .= '>' ;
$out .= dolGetFirstLastname ( $obj_usr -> firstname , $obj_usr -> lastname );
2013-07-27 14:45:55 +02:00
// Complete name with more info
2020-03-12 12:45:44 +01:00
$moreinfo = 0 ;
if ( ! empty ( $conf -> global -> MAIN_SHOW_LOGIN ))
2013-07-27 14:21:47 +02:00
{
2020-03-12 12:45:44 +01:00
$out .= ( $moreinfo ? ' - ' : ' (' ) . $obj_usr -> login ;
2014-12-23 16:42:05 +01:00
$moreinfo ++ ;
2013-07-27 14:45:55 +02:00
}
if ( $showstatus >= 0 )
{
if ( $obj_usr -> statut == 1 && $showstatus == 1 )
{
2020-03-12 12:45:44 +01:00
$out .= ( $moreinfo ? ' - ' : ' (' ) . $langs -> trans ( 'Enabled' );
2013-07-27 14:45:55 +02:00
$moreinfo ++ ;
}
if ( $obj_usr -> statut == 0 )
{
2020-03-12 12:45:44 +01:00
$out .= ( $moreinfo ? ' - ' : ' (' ) . $langs -> trans ( 'Disabled' );
2013-07-27 14:45:55 +02:00
$moreinfo ++ ;
}
2013-07-22 11:17:45 +02:00
}
2020-03-12 12:45:44 +01:00
$out .= ( $moreinfo ? ')' : '' );
$out .= '</option>' ;
2012-02-25 16:24:36 +01:00
}
$this -> db -> free ( $resql_usr );
}
else
{
dol_print_error ( $this -> db );
}
2019-11-08 13:43:26 +01:00
if ( $norepresentative )
{
$langs -> load ( " companies " );
2020-03-12 12:45:44 +01:00
$out .= '<option value="-2"' . ( $selected == - 2 ? ' selected' : '' ) . '>- ' . $langs -> trans ( " NoSalesRepresentativeAffected " ) . ' -</option>' ;
2019-11-08 13:43:26 +01:00
}
2020-03-12 12:45:44 +01:00
$out .= '</select>' ;
2012-02-25 16:24:36 +01:00
2014-12-23 16:42:05 +01:00
return $out ;
2012-02-25 16:24:36 +01:00
}
/**
* Return list of project and tasks
*
2014-04-26 21:36:58 +02:00
* @ 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 )
* @ param string $morecss More css
2012-02-25 16:24:36 +01:00
* @ return void
*/
2019-02-27 20:45:07 +01:00
public function selectProjectTasks ( $selectedtask = '' , $projectid = 0 , $htmlname = 'task_parent' , $modeproject = 0 , $modetask = 0 , $mode = 0 , $useempty = 0 , $disablechildoftaskid = 0 , $filteronprojstatus = '' , $morecss = '' )
2012-02-25 16:24:36 +01:00
{
global $user , $langs ;
2012-08-22 23:11:24 +02:00
require_once DOL_DOCUMENT_ROOT . '/projet/class/task.class.php' ;
2012-02-25 16:24:36 +01:00
//print $modeproject.'-'.$modetask;
2019-11-13 19:37:08 +01:00
$task = new Task ( $this -> db );
$tasksarray = $task -> getTasksArray ( $modetask ? $user : 0 , $modeproject ? $user : 0 , $projectid , 0 , $mode , '' , $filteronprojstatus );
2012-02-25 16:24:36 +01:00
if ( $tasksarray )
{
2019-11-13 19:37:08 +01:00
print '<select class="flat' . ( $morecss ? ' ' . $morecss : '' ) . '" name="' . $htmlname . '" id="' . $htmlname . '">' ;
2012-02-25 16:24:36 +01:00
if ( $useempty ) print '<option value="0"> </option>' ;
2019-11-13 19:37:08 +01:00
$j = 0 ;
$level = 0 ;
2014-04-26 21:36:58 +02:00
$this -> _pLineSelect ( $j , 0 , $tasksarray , $level , $selectedtask , $projectid , $disablechildoftaskid );
2012-02-25 16:24:36 +01:00
print '</select>' ;
2018-01-04 10:45:48 +01:00
print ajax_combobox ( $htmlname );
2012-02-25 16:24:36 +01:00
}
else
{
print '<div class="warning">' . $langs -> trans ( " NoProject " ) . '</div>' ;
}
}
/**
2014-04-26 21:36:58 +02:00
* Write lines of a project ( all lines of a project if parent = 0 )
2012-02-25 16:24:36 +01:00
*
2014-09-27 16:00:11 +02:00
* @ param int $inc Cursor counter
2014-04-26 21:36:58 +02:00
* @ param int $parent Id of parent task we want to see
* @ param array $lines Array of task lines
2012-02-25 16:24:36 +01:00
* @ param int $level Level
* @ param int $selectedtask Id selected task
* @ param int $selectedproject Id selected project
2014-04-26 21:36:58 +02:00
* @ param int $disablechildoftaskid 1 = Disable task that are child of the provided task id
2012-02-25 16:24:36 +01:00
* @ return void
*/
2019-01-27 15:20:16 +01:00
private function _pLineSelect ( & $inc , $parent , $lines , $level = 0 , $selectedtask = 0 , $selectedproject = 0 , $disablechildoftaskid = 0 )
2012-02-25 16:24:36 +01:00
{
global $langs , $user , $conf ;
2019-11-13 19:37:08 +01:00
$lastprojectid = 0 ;
2012-02-25 16:24:36 +01:00
2019-11-13 19:37:08 +01:00
$numlines = count ( $lines );
for ( $i = 0 ; $i < $numlines ; $i ++ ) {
2019-02-27 20:45:07 +01:00
if ( $lines [ $i ] -> fk_parent == $parent ) {
//var_dump($selectedproject."--".$selectedtask."--".$lines[$i]->fk_project."_".$lines[$i]->id); // $lines[$i]->id may be empty if project has no lines
2014-03-11 20:38:29 +01:00
2012-02-25 16:24:36 +01:00
// Break on a new project
2014-04-26 21:36:58 +02:00
if ( $parent == 0 ) // We are on a task at first level
2012-02-25 16:24:36 +01:00
{
2014-04-26 21:36:58 +02:00
if ( $lines [ $i ] -> fk_project != $lastprojectid ) // Break found on project
2012-02-25 16:24:36 +01:00
{
2015-05-07 11:57:23 +02:00
if ( $i > 0 ) print '<option value="0" disabled>----------</option>' ;
2012-02-25 16:24:36 +01:00
print '<option value="' . $lines [ $i ] -> fk_project . '_0"' ;
2015-05-07 12:20:20 +02:00
if ( $selectedproject == $lines [ $i ] -> fk_project ) print ' selected' ;
2019-11-13 19:37:08 +01:00
print '>' ; // Project -> Task
2012-02-25 16:24:36 +01:00
print $langs -> trans ( " Project " ) . ' ' . $lines [ $i ] -> projectref ;
if ( empty ( $lines [ $i ] -> public ))
{
print ' (' . $langs -> trans ( " Visibility " ) . ': ' . $langs -> trans ( " PrivateProject " ) . ')' ;
}
else
{
print ' (' . $langs -> trans ( " Visibility " ) . ': ' . $langs -> trans ( " SharedProject " ) . ')' ;
}
//print '-'.$parent.'-'.$lines[$i]->fk_project.'-'.$lastprojectid;
print " </option> \n " ;
2019-11-13 19:37:08 +01:00
$lastprojectid = $lines [ $i ] -> fk_project ;
2012-02-25 16:24:36 +01:00
$inc ++ ;
}
}
2019-11-13 19:37:08 +01:00
$newdisablechildoftaskid = $disablechildoftaskid ;
2014-04-26 21:36:58 +02:00
2012-02-25 16:24:36 +01:00
// Print task
2014-05-09 17:14:40 +02: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
2012-02-25 16:24:36 +01:00
{
2014-04-26 21:36:58 +02:00
// Check if we must disable entry
2019-11-13 19:37:08 +01:00
$disabled = 0 ;
2014-04-26 21:36:58 +02:00
if ( $disablechildoftaskid && (( $lines [ $i ] -> id == $disablechildoftaskid || $lines [ $i ] -> fk_parent == $disablechildoftaskid )))
{
$disabled ++ ;
2019-11-13 19:37:08 +01:00
if ( $lines [ $i ] -> fk_parent == $disablechildoftaskid ) $newdisablechildoftaskid = $lines [ $i ] -> id ; // If task is child of a disabled parent, we will propagate id to disable next child too
2014-04-26 21:36:58 +02:00
}
2012-02-25 16:24:36 +01:00
print '<option value="' . $lines [ $i ] -> fk_project . '_' . $lines [ $i ] -> id . '"' ;
2015-05-07 12:20:20 +02:00
if (( $lines [ $i ] -> id == $selectedtask ) || ( $lines [ $i ] -> fk_project . '_' . $lines [ $i ] -> id == $selectedtask )) print ' selected' ;
2015-05-07 11:57:23 +02:00
if ( $disabled ) print ' disabled' ;
2012-02-25 16:24:36 +01:00
print '>' ;
print $langs -> trans ( " Project " ) . ' ' . $lines [ $i ] -> projectref ;
2018-06-21 18:47:02 +02:00
print ' ' . $lines [ $i ] -> projectlabel ;
2012-02-25 16:24:36 +01:00
if ( empty ( $lines [ $i ] -> public ))
{
print ' (' . $langs -> trans ( " Visibility " ) . ': ' . $langs -> trans ( " PrivateProject " ) . ')' ;
}
else
{
print ' (' . $langs -> trans ( " Visibility " ) . ': ' . $langs -> trans ( " SharedProject " ) . ')' ;
}
if ( $lines [ $i ] -> id ) print ' > ' ;
2019-11-13 19:37:08 +01:00
for ( $k = 0 ; $k < $level ; $k ++ )
2012-02-25 16:24:36 +01:00
{
print " " ;
}
2016-07-08 17:06:12 +02:00
print $lines [ $i ] -> ref . ' ' . $lines [ $i ] -> label . " </option> \n " ;
2012-02-25 16:24:36 +01:00
$inc ++ ;
}
$level ++ ;
2014-04-26 21:36:58 +02:00
if ( $lines [ $i ] -> id ) $this -> _pLineSelect ( $inc , $lines [ $i ] -> id , $lines , $level , $selectedtask , $selectedproject , $newdisablechildoftaskid );
2012-02-25 16:24:36 +01:00
$level -- ;
}
}
}
2015-06-26 16:21:09 +02:00
/**
2019-02-27 20:45:07 +01:00
* Output a HTML thumb of color or a text if not defined .
2015-06-26 16:21:09 +02:00
*
2019-02-27 20:45:07 +01:00
* @ param string $color String with hex ( FFFFFF ) or comma RGB ( '255,255,255' )
* @ param string $textifnotdefined Text to show if color not defined
* @ return string HTML code for color thumb
2019-04-04 18:33:12 +02:00
* @ see selectColor ()
2015-06-26 16:21:09 +02:00
*/
2019-02-27 20:45:07 +01:00
public static function showColor ( $color , $textifnotdefined = '' )
2015-06-26 16:21:09 +02:00
{
2019-11-13 19:37:08 +01:00
$textcolor = 'FFF' ;
2015-06-26 16:21:09 +02:00
include_once DOL_DOCUMENT_ROOT . '/core/lib/functions2.lib.php' ;
2019-11-13 19:37:08 +01:00
if ( colorIsLight ( $color )) $textcolor = '000' ;
2017-09-13 10:43:44 +02:00
2019-01-27 11:55:16 +01:00
$color = colorArrayToHex ( colorStringToArray ( $color , array ()), '' );
2017-06-12 14:09:00 +02:00
2016-01-10 00:11:49 +01:00
if ( $color ) print '<input type="text" class="colorthumb" disabled style="padding: 1px; margin-top: 0; margin-bottom: 0; color: #' . $textcolor . '; background-color: #' . $color . '" value="' . $color . '">' ;
2015-06-26 16:21:09 +02:00
else print $textifnotdefined ;
}
2019-02-27 20:45:07 +01:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2012-07-08 12:24:13 +02:00
/**
2019-02-27 20:45:07 +01:00
* Output a HTML code to select a color
2012-07-08 12:24:13 +02:00
*
2019-02-27 20:45:07 +01:00
* @ 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
* @ param array $arrayofcolors Array of colors . Example : array ( '29527A' , '5229A3' , 'A32929' , '7A367A' , 'B1365F' , '0D7813' )
* @ return void
* @ deprecated Use instead selectColor
* @ see selectColor ()
2012-07-08 12:24:13 +02:00
*/
2019-02-27 20:45:07 +01:00
public function select_color ( $set_color = '' , $prefix = 'f_color' , $form_name = '' , $showcolorbox = 1 , $arrayofcolors = '' )
2012-07-07 10:46:05 +02:00
{
2018-09-05 18:49:06 +02:00
// phpcs:enable
2012-07-07 12:26:46 +02:00
print $this -> selectColor ( $set_color , $prefix , $form_name , $showcolorbox , $arrayofcolors );
2012-07-07 10:46:05 +02:00
}
2012-02-25 16:24:36 +01:00
/**
2019-02-27 20:45:07 +01:00
* Output a HTML code to select a color . Field will return an hexa color like '334455' .
2012-02-25 16:24:36 +01:00
*
2019-02-27 20:45:07 +01:00
* @ 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
* @ param array $arrayofcolors Array of colors . Example : array ( '29527A' , '5229A3' , 'A32929' , '7A367A' , 'B1365F' , '0D7813' )
* @ param string $morecss Add css style into input field
* @ return string
2019-04-04 18:33:12 +02:00
* @ see showColor ()
2012-02-25 16:24:36 +01:00
*/
2019-02-27 20:45:07 +01:00
public static function selectColor ( $set_color = '' , $prefix = 'f_color' , $form_name = '' , $showcolorbox = 1 , $arrayofcolors = '' , $morecss = '' )
2012-02-25 16:24:36 +01:00
{
2019-02-27 20:45:07 +01:00
// Deprecation warning
if ( $form_name ) {
2019-11-13 19:37:08 +01:00
dol_syslog ( __METHOD__ . " : form_name parameter is deprecated " , LOG_WARNING );
2019-02-27 20:45:07 +01:00
}
2015-04-23 23:21:06 +02:00
2019-11-13 19:37:08 +01:00
global $langs , $conf ;
2012-07-07 10:46:05 +02:00
2019-11-13 19:37:08 +01:00
$out = '' ;
2012-07-07 10:46:05 +02:00
2019-11-13 19:37:08 +01:00
if ( ! is_array ( $arrayofcolors ) || count ( $arrayofcolors ) < 1 )
2012-02-25 16:24:36 +01:00
{
$langs -> load ( " other " );
2020-02-26 15:22:23 +01:00
if ( empty ( $conf -> dol_use_jmobile ) && ! empty ( $conf -> use_javascript_ajax ))
2013-05-26 05:01:28 +02:00
{
2019-11-13 19:37:08 +01:00
$out .= '<link rel="stylesheet" media="screen" type="text/css" href="' . DOL_URL_ROOT . '/includes/jquery/plugins/jpicker/css/jPicker-1.1.6.css" />' ;
$out .= '<script type="text/javascript" src="' . DOL_URL_ROOT . '/includes/jquery/plugins/jpicker/jpicker-1.1.6.js"></script>' ;
$out .= ' < script type = " text/javascript " >
2013-05-26 05:01:28 +02:00
jQuery ( document ) . ready ( function (){
$ ( \ '#colorpicker' . $prefix . ' \ ' ) . jPicker ( {
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 " )) . ' \ ' ,
ok : \ '' . dol_escape_js ( $langs -> trans ( " Save " )) . ' \ ' ,
cancel : \ '' . dol_escape_js ( $langs -> trans ( " Cancel " )) . ' \ '
}
}
} ); });
</ script > ' ;
}
2019-11-14 21:30:16 +01:00
$out .= '<input id="colorpicker' . $prefix . '" name="' . $prefix . '" size="6" maxlength="7" class="flat' . ( $morecss ? ' ' . $morecss : '' ) . '" type="text" value="' . dol_escape_htmltag ( $set_color ) . '" />' ;
2012-02-25 16:24:36 +01:00
}
else // In most cases, this is not used. We used instead function with no specific list of colors
{
2020-02-26 15:22:23 +01:00
if ( empty ( $conf -> dol_use_jmobile ) && ! empty ( $conf -> use_javascript_ajax ))
2013-05-26 05:01:28 +02:00
{
2019-11-13 19:37:08 +01:00
$out .= '<link rel="stylesheet" href="' . DOL_URL_ROOT . '/includes/jquery/plugins/colorpicker/jquery.colorpicker.css" type="text/css" media="screen" />' ;
$out .= '<script src="' . DOL_URL_ROOT . '/includes/jquery/plugins/colorpicker/jquery.colorpicker.js" type="text/javascript"></script>' ;
$out .= ' < script 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 > ' ;
}
2019-11-13 19:37:08 +01:00
$out .= '<select id="colorpicker' . $prefix . '" class="flat' . ( $morecss ? ' ' . $morecss : '' ) . '" name="' . $prefix . '">' ;
2012-02-25 16:24:36 +01:00
//print '<option value="-1"> </option>';
foreach ( $arrayofcolors as $val )
{
2019-11-13 19:37:08 +01:00
$out .= '<option value="' . $val . '"' ;
if ( $set_color == $val ) $out .= ' selected' ;
$out .= '>' . $val . '</option>' ;
2012-02-25 16:24:36 +01:00
}
2019-11-13 19:37:08 +01:00
$out .= '</select>' ;
2012-02-25 16:24:36 +01:00
}
2012-07-07 10:46:05 +02:00
return $out ;
2012-02-25 16:24:36 +01:00
}
2019-02-27 20:45:07 +01:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2012-02-25 16:24:36 +01:00
/**
* Creation d ' un icone de couleur
*
* @ param string $color Couleur de l ' image
* @ param string $module Nom du module
* @ param string $name Nom de l ' image
* @ param int $x Largeur de l ' image en pixels
* @ param int $y Hauteur de l ' image en pixels
* @ return void
*/
2019-02-27 20:45:07 +01:00
public function CreateColorIcon ( $color , $module , $name , $x = '12' , $y = '12' )
2012-02-25 16:24:36 +01:00
{
2018-09-05 18:49:06 +02:00
// phpcs:enable
2012-02-25 16:24:36 +01:00
global $conf ;
$file = $conf -> $module -> dir_temp . '/' . $name . '.png' ;
// On cree le repertoire contenant les icones
2019-11-13 19:37:08 +01:00
if ( ! file_exists ( $conf -> $module -> dir_temp ))
2012-02-25 16:24:36 +01:00
{
dol_mkdir ( $conf -> $module -> dir_temp );
}
// On cree l'image en vraies couleurs
2019-01-27 11:55:16 +01:00
$image = imagecreatetruecolor ( $x , $y );
2012-02-25 16:24:36 +01:00
2019-01-27 11:55:16 +01:00
$color = substr ( $color , 1 , 6 );
2012-02-25 16:24:36 +01:00
2019-01-27 11:55:16 +01:00
$rouge = hexdec ( substr ( $color , 0 , 2 )); //conversion du canal rouge
$vert = hexdec ( substr ( $color , 2 , 2 )); //conversion du canal vert
$bleu = hexdec ( substr ( $color , 4 , 2 )); //conversion du canal bleu
2012-02-25 16:24:36 +01:00
2019-01-27 11:55:16 +01:00
$couleur = imagecolorallocate ( $image , $rouge , $vert , $bleu );
2012-02-25 16:24:36 +01:00
//print $rouge.$vert.$bleu;
2019-01-27 11:55:16 +01:00
imagefill ( $image , 0 , 0 , $couleur ); //on remplit l'image
2012-02-25 16:24:36 +01:00
// On cree la couleur et on l'attribue a une variable pour ne pas la perdre
2019-01-27 11:55:16 +01:00
ImagePng ( $image , $file ); //renvoie une image sous format png
2012-02-25 16:24:36 +01:00
ImageDestroy ( $image );
}
2011-05-21 19:14:07 +02:00
2019-02-27 20:45:07 +01:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2011-05-20 17:59:18 +02:00
/**
* Return HTML combo list of week
2012-01-15 17:40:44 +01:00
*
2011-12-12 00:28:04 +01:00
* @ param string $selected Preselected value
* @ param string $htmlname Nom de la zone select
* @ param int $useempty Affiche valeur vide dans liste
2015-02-10 10:52:48 +01:00
* @ return string
2011-05-20 17:59:18 +02:00
*/
2019-02-27 20:45:07 +01:00
public function select_dayofweek ( $selected = '' , $htmlname = 'weekid' , $useempty = 0 )
2011-05-20 17:59:18 +02:00
{
2018-09-05 18:49:06 +02:00
// phpcs:enable
2011-05-20 17:59:18 +02:00
global $langs ;
2018-09-05 18:49:06 +02:00
$week = array (
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 " )
);
2011-05-20 17:59:18 +02:00
$select_week = '<select class="flat" name="' . $htmlname . '">' ;
if ( $useempty )
{
$select_week .= '<option value="-1"> </option>' ;
}
foreach ( $week as $key => $val )
{
if ( $selected == $key )
{
2015-05-07 12:20:20 +02:00
$select_week .= '<option value="' . $key . '" selected>' ;
2011-05-20 17:59:18 +02:00
}
else
{
$select_week .= '<option value="' . $key . '">' ;
}
$select_week .= $val ;
2016-04-23 20:17:45 +02:00
$select_week .= '</option>' ;
2011-05-20 17:59:18 +02:00
}
$select_week .= '</select>' ;
return $select_week ;
}
2019-02-27 20:45:07 +01:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2011-05-20 17:59:18 +02:00
/**
2015-05-03 06:18:21 +02:00
* Return HTML combo list of month
2012-01-15 17:40:44 +01:00
*
2018-03-16 16:10:04 +01:00
* @ 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
2015-05-03 06:25:50 +02:00
* @ return string
2011-05-20 17:59:18 +02:00
*/
2019-03-25 09:14:28 +01:00
public function select_month ( $selected = '' , $htmlname = 'monthid' , $useempty = 0 , $longlabel = 0 , $morecss = 'maxwidth50imp valignmiddle' )
2011-05-20 17:59:18 +02:00
{
2018-09-05 18:49:06 +02:00
// phpcs:enable
2012-02-25 16:24:36 +01:00
global $langs ;
2012-02-20 12:20:56 +01:00
2012-08-22 23:11:24 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php' ;
2011-08-17 18:07:41 +02:00
2019-11-13 19:37:08 +01:00
if ( $longlabel ) $montharray = monthArray ( $langs , 0 ); // Get array
2015-05-03 06:16:28 +02:00
else $montharray = monthArray ( $langs , 1 );
2011-05-20 17:59:18 +02:00
2019-11-13 19:37:08 +01:00
$select_month = '<select class="flat' . ( $morecss ? ' ' . $morecss : '' ) . '" name="' . $htmlname . '" id="' . $htmlname . '">' ;
2011-05-20 17:59:18 +02:00
if ( $useempty )
{
$select_month .= '<option value="0"> </option>' ;
}
2012-01-24 09:19:28 +01:00
foreach ( $montharray as $key => $val )
2011-05-20 17:59:18 +02:00
{
if ( $selected == $key )
{
2015-05-07 12:20:20 +02:00
$select_month .= '<option value="' . $key . '" selected>' ;
2011-05-20 17:59:18 +02:00
}
else
{
$select_month .= '<option value="' . $key . '">' ;
}
$select_month .= $val ;
2016-04-23 20:17:45 +02:00
$select_month .= '</option>' ;
2011-05-20 17:59:18 +02:00
}
$select_month .= '</select>' ;
return $select_month ;
}
2019-02-27 20:45:07 +01:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2011-05-20 17:59:18 +02:00
/**
2012-02-25 16:24:36 +01:00
* Return HTML combo list of years
2012-01-15 17:40:44 +01:00
*
2012-02-25 16:24:36 +01:00
* @ 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
2018-03-06 11:54:05 +01:00
* @ param string $morecss More CSS
2015-02-10 13:17:37 +01:00
* @ return string
2011-05-20 17:59:18 +02:00
*/
2019-03-25 09:14:28 +01:00
public function select_year ( $selected = '' , $htmlname = 'yearid' , $useempty = 0 , $min_year = 10 , $max_year = 5 , $offset = 0 , $invert = 0 , $option = '' , $morecss = 'valignmiddle maxwidth75imp' )
2011-05-20 17:59:18 +02:00
{
2018-09-05 18:49:06 +02:00
// phpcs:enable
2019-01-27 11:55:16 +01:00
print $this -> selectyear ( $selected , $htmlname , $useempty , $min_year , $max_year , $offset , $invert , $option , $morecss );
2011-06-26 11:32:13 +02:00
}
2011-08-17 18:07:41 +02:00
2011-06-26 11:32:13 +02:00
/**
2012-02-25 16:24:36 +01:00
* Return HTML combo list of years
2012-01-15 17:40:44 +01:00
*
2012-02-25 16:24:36 +01:00
* @ 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
2018-03-01 16:48:12 +01:00
* @ param string $morecss More css
2015-03-06 03:10:01 +01:00
* @ return string
2011-06-26 11:32:13 +02:00
*/
2019-03-25 09:14:28 +01:00
public function selectyear ( $selected = '' , $htmlname = 'yearid' , $useempty = 0 , $min_year = 10 , $max_year = 5 , $offset = 0 , $invert = 0 , $option = '' , $morecss = 'valignmiddle maxwidth75imp' )
2011-06-26 11:32:13 +02:00
{
2019-11-13 19:37:08 +01:00
$out = '' ;
2011-08-17 18:07:41 +02:00
2019-11-13 19:37:08 +01:00
$currentyear = date ( " Y " ) + $offset ;
$max_year = $currentyear + $max_year ;
$min_year = $currentyear - $min_year ;
if ( empty ( $selected ) && empty ( $useempty )) $selected = $currentyear ;
2011-05-20 17:59:18 +02:00
2019-11-13 19:37:08 +01:00
$out .= '<select class="flat' . ( $morecss ? ' ' . $morecss : '' ) . '" id="' . $htmlname . '" name="' . $htmlname . '"' . $option . ' >' ;
if ( $useempty )
2011-05-20 17:59:18 +02:00
{
2019-11-13 19:37:08 +01:00
$selected_html = '' ;
2015-05-07 12:20:20 +02:00
if ( $selected == '' ) $selected_html = ' selected' ;
2019-11-13 19:37:08 +01:00
$out .= '<option value=""' . $selected_html . '> </option>' ;
2011-05-20 17:59:18 +02:00
}
2019-11-13 19:37:08 +01:00
if ( ! $invert )
2011-05-20 17:59:18 +02:00
{
2012-02-25 16:24:36 +01:00
for ( $y = $max_year ; $y >= $min_year ; $y -- )
{
2019-11-13 19:37:08 +01:00
$selected_html = '' ;
2015-05-07 12:20:20 +02:00
if ( $selected > 0 && $y == $selected ) $selected_html = ' selected' ;
2019-11-13 19:37:08 +01:00
$out .= '<option value="' . $y . '"' . $selected_html . ' >' . $y . '</option>' ;
2012-02-25 16:24:36 +01:00
}
2011-05-20 17:59:18 +02:00
}
else
{
2012-02-25 16:24:36 +01:00
for ( $y = $min_year ; $y <= $max_year ; $y ++ )
{
2019-11-13 19:37:08 +01:00
$selected_html = '' ;
2015-05-07 12:20:20 +02:00
if ( $selected > 0 && $y == $selected ) $selected_html = ' selected' ;
2019-11-13 19:37:08 +01:00
$out .= '<option value="' . $y . '"' . $selected_html . ' >' . $y . '</option>' ;
2012-02-25 16:24:36 +01:00
}
2011-05-20 17:59:18 +02:00
}
2019-11-13 19:37:08 +01:00
$out .= " </select> \n " ;
2011-08-17 18:07:41 +02:00
2011-06-26 11:32:13 +02:00
return $out ;
2011-05-20 17:59:18 +02:00
}
2010-05-03 10:43:32 +02:00
2012-03-19 15:51:55 +01:00
/**
2016-02-07 13:10:36 +01:00
* Get array with HTML tabs with boxes of a particular area including personalized choices of user .
2014-05-01 16:26:57 +02:00
* Class ' Form ' must be known .
2012-03-19 15:51:55 +01:00
*
* @ param User $user Object User
2019-10-02 08:58:25 +02:00
* @ param String $areacode Code of area for pages - 0 = Home page ... See getListOfPagesForBoxes ()
2019-09-23 20:42:50 +02:00
* @ return array array ( 'selectboxlist' => , 'boxactivated' => , 'boxlista' => , 'boxlistb' => )
2012-03-19 15:51:55 +01:00
*/
2019-02-27 20:45:07 +01:00
public static function getBoxesArea ( $user , $areacode )
2012-03-19 15:51:55 +01:00
{
2019-11-13 19:37:08 +01:00
global $conf , $langs , $db ;
2012-03-19 15:51:55 +01:00
2012-08-23 02:04:35 +02:00
include_once DOL_DOCUMENT_ROOT . '/core/class/infobox.class.php' ;
2012-03-19 15:51:55 +01:00
2019-11-13 19:37:08 +01:00
$confuserzone = 'MAIN_BOXES_' . $areacode ;
2013-01-18 15:57:11 +01:00
2016-02-07 02:22:10 +01:00
// $boxactivated will be array of boxes enabled into global setup
// $boxidactivatedforuser will be array of boxes choosed by user
2017-06-12 14:09:00 +02:00
2019-11-13 19:37:08 +01:00
$selectboxlist = '' ;
$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)
2017-06-12 14:09:00 +02:00
2019-11-13 19:37:08 +01:00
$boxidactivatedforuser = array ();
foreach ( $boxactivated as $box )
2013-01-15 11:35:10 +01:00
{
2019-11-13 19:37:08 +01:00
if ( empty ( $user -> conf -> $confuserzone ) || $box -> fk_user == $user -> id ) $boxidactivatedforuser [ $box -> id ] = $box -> id ; // We keep only boxes to show for user
2013-01-15 11:35:10 +01:00
}
2017-06-12 14:09:00 +02:00
2016-02-07 13:10:36 +01:00
// Define selectboxlist
2019-11-13 19:37:08 +01:00
$arrayboxtoactivatelabel = array ();
if ( ! empty ( $user -> conf -> $confuserzone ))
2012-03-19 15:51:55 +01:00
{
2019-11-13 19:37:08 +01:00
$boxorder = '' ;
$langs -> load ( " boxes " ); // Load label of boxes
foreach ( $boxactivated as $box )
2013-01-16 15:54:07 +01:00
{
2019-11-13 19:37:08 +01:00
if ( ! empty ( $boxidactivatedforuser [ $box -> id ])) continue ; // Already visible for user
$label = $langs -> transnoentitiesnoconv ( $box -> boxlabel );
2017-10-26 20:06:23 +02:00
//if (preg_match('/graph/',$box->class)) $label.=' ('.$langs->trans("Graph").')';
2019-01-27 11:55:16 +01:00
if ( preg_match ( '/graph/' , $box -> class ) && $conf -> browser -> layout != 'phone' )
2018-01-10 13:14:30 +01:00
{
2019-11-13 19:37:08 +01:00
$label = $label . ' <span class="fa fa-bar-chart"></span>' ;
2018-01-10 13:14:30 +01:00
}
2019-11-13 19:37:08 +01:00
$arrayboxtoactivatelabel [ $box -> id ] = $label ; // We keep only boxes not shown for user, to show into combo list
2013-01-16 15:54:07 +01:00
}
2019-11-13 19:37:08 +01:00
foreach ( $boxidactivatedforuser as $boxid )
2014-07-29 00:50:57 +02:00
{
2019-11-13 19:37:08 +01:00
if ( empty ( $boxorder )) $boxorder .= 'A:' ;
$boxorder .= $boxid . ',' ;
2014-07-29 00:50:57 +02:00
}
//var_dump($boxidactivatedforuser);
// Class Form must have been already loaded
2019-11-13 19:37:08 +01:00
$selectboxlist .= '<!-- Form with select box list -->' . " \n " ;
$selectboxlist .= '<form id="addbox" name="addbox" method="POST" action="' . $_SERVER [ " PHP_SELF " ] . '">' ;
$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 . '">' ;
$selectboxlist .= Form :: selectarray ( 'boxcombo' , $arrayboxtoactivatelabel , - 1 , $langs -> trans ( " ChooseBoxToAdd " ) . '...' , 0 , 0 , '' , 0 , 0 , 0 , 'ASC' , 'maxwidth150onsmartphone' , 0 , 'hidden selected' , 0 , 1 );
if ( empty ( $conf -> use_javascript_ajax )) $selectboxlist .= ' <input type="submit" class="button" value="' . $langs -> trans ( " AddBox " ) . '">' ;
$selectboxlist .= '</form>' ;
if ( ! empty ( $conf -> use_javascript_ajax ))
2017-11-14 15:10:46 +01:00
{
2019-11-13 19:37:08 +01:00
include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php' ;
$selectboxlist .= ajax_combobox ( " boxcombo " );
2017-11-14 15:10:46 +01:00
}
2012-03-19 15:51:55 +01:00
}
2013-04-19 14:51:39 +02:00
// Javascript code for dynamic actions
2019-11-13 19:37:08 +01:00
if ( ! empty ( $conf -> use_javascript_ajax ))
2012-08-05 21:06:48 +02:00
{
2019-11-13 19:37:08 +01:00
$selectboxlist .= ' < script type = " text/javascript " language = " 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 ({
2017-03-15 11:58:13 +01:00
url : \ '' . DOL_URL_ROOT . '/core/ajax/box.php?closing=0&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
2019-01-27 11:55:16 +01:00
window . location . search = \ 'mainmenu=' . GETPOST ( " mainmenu " , " aZ09 " ) . '&leftmenu=' . GETPOST ( 'leftmenu' , " aZ09 " ) . ' & action = delbox\ ' ;
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 ) {
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 ({
url : \ '' . DOL_URL_ROOT . '/core/ajax/box.php?boxorder=\'+boxorder+\'&boxid=\'+boxid+\'&zone=' . $areacode . '&userid=' . $user -> id . ' \ ' ,
async : false
2012-08-05 21:06:48 +02:00
});
2019-01-27 11:55:16 +01:00
window . location . search = \ 'mainmenu=' . GETPOST ( " mainmenu " , " aZ09 " ) . '&leftmenu=' . GETPOST ( 'leftmenu' , " aZ09 " ) . ' & action = addbox & boxid = \ ' + boxid ;
2012-08-05 21:06:48 +02:00
}
}); ' ;
2019-11-13 19:37:08 +01:00
if ( ! count ( $arrayboxtoactivatelabel )) $selectboxlist .= 'jQuery("#boxcombo").hide();' ;
$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 ) {
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
2013-04-19 15:26:53 +02:00
var boxid = self . id . substring ( 8 );
2013-06-05 16:24:32 +02:00
var label = jQuery ( \ ' #boxlabelentry\'+boxid).val();
2017-10-26 20:06:23 +02:00
console . log ( " We close box " + boxid );
2013-04-19 15:26:53 +02:00
jQuery ( \ ' #boxto_\'+boxid).remove();
2013-04-25 01:35:33 +02:00
if ( boxid > 0 ) jQuery ( \ ' #boxcombo\').append(new Option(label, boxid));
2017-03-15 11:58:13 +01:00
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
2019-11-13 19:37:08 +01:00
$selectboxlist .= '</script>' . " \n " ;
2012-08-05 21:06:48 +02:00
}
2012-03-19 15:51:55 +01:00
2016-02-07 13:10:36 +01:00
// Define boxlista and boxlistb
2019-11-13 19:37:08 +01:00
$nbboxactivated = count ( $boxidactivatedforuser );
2012-03-19 15:51:55 +01:00
2012-09-06 10:22:33 +02:00
if ( $nbboxactivated )
2012-03-19 15:51:55 +01:00
{
2018-09-17 09:31:32 +02:00
// Load translation files required by the page
2019-11-13 19:37:08 +01:00
$langs -> loadLangs ( array ( " boxes " , " projects " ));
2013-01-17 17:40:27 +01:00
2019-11-13 19:37:08 +01:00
$emptybox = new ModeleBoxes ( $db );
2013-01-15 11:35:10 +01:00
2019-11-13 19:37:08 +01:00
$boxlista .= " \n <!-- Box left container --> \n " ;
2012-03-19 15:51:55 +01:00
// Define $box_max_lines
2019-11-13 19:37:08 +01:00
$box_max_lines = 5 ;
if ( ! empty ( $conf -> global -> MAIN_BOXES_MAXLINES )) $box_max_lines = $conf -> global -> MAIN_BOXES_MAXLINES ;
2012-03-19 15:51:55 +01:00
2019-11-13 19:37:08 +01:00
$ii = 0 ;
2012-03-19 15:51:55 +01:00
foreach ( $boxactivated as $key => $box )
{
2019-11-13 19:37:08 +01:00
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
2019-01-27 11:55:16 +01:00
if ( preg_match ( '/^A/i' , $box -> box_order )) // column A
2012-03-19 15:51:55 +01:00
{
$ii ++ ;
//print 'box_id '.$boxactivated[$ii]->box_id.' ';
//print 'box_order '.$boxactivated[$ii]->box_order.'<br>';
2016-02-07 13:10:36 +01:00
// Show box
2012-03-19 15:51:55 +01:00
$box -> loadBox ( $box_max_lines );
2019-11-13 19:37:08 +01:00
$boxlista .= $box -> outputBox ();
2012-03-19 15:51:55 +01:00
}
}
2018-09-02 16:45:03 +02:00
if ( $conf -> browser -> layout != 'phone' )
2013-05-26 05:01:28 +02:00
{
2019-11-13 19:37:08 +01:00
$emptybox -> box_id = 'A' ;
$emptybox -> info_box_head = array ();
$emptybox -> info_box_contents = array ();
$boxlista .= $emptybox -> outputBox ( array (), array ());
2013-05-10 12:48:11 +02:00
}
2019-11-13 19:37:08 +01:00
$boxlista .= " <!-- End box left container --> \n " ;
2012-03-19 15:51:55 +01:00
2019-11-13 19:37:08 +01:00
$boxlistb .= " \n <!-- Box right container --> \n " ;
2012-03-19 15:51:55 +01:00
2019-11-13 19:37:08 +01:00
$ii = 0 ;
2012-03-19 15:51:55 +01:00
foreach ( $boxactivated as $key => $box )
{
2019-11-13 19:37:08 +01:00
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
2019-01-27 11:55:16 +01:00
if ( preg_match ( '/^B/i' , $box -> box_order )) // colonne B
2012-03-19 15:51:55 +01:00
{
$ii ++ ;
//print 'box_id '.$boxactivated[$ii]->box_id.' ';
//print 'box_order '.$boxactivated[$ii]->box_order.'<br>';
2016-02-07 13:10:36 +01:00
// Show box
2012-03-19 15:51:55 +01:00
$box -> loadBox ( $box_max_lines );
2019-11-13 19:37:08 +01:00
$boxlistb .= $box -> outputBox ();
2012-03-19 15:51:55 +01:00
}
}
2018-09-02 16:45:03 +02:00
if ( $conf -> browser -> layout != 'phone' )
2013-05-26 05:01:28 +02:00
{
2019-11-13 19:37:08 +01:00
$emptybox -> box_id = 'B' ;
$emptybox -> info_box_head = array ();
$emptybox -> info_box_contents = array ();
$boxlistb .= $emptybox -> outputBox ( array (), array ());
2013-05-10 12:48:11 +02:00
}
2018-01-16 16:15:49 +01:00
2019-11-13 19:37:08 +01:00
$boxlistb .= " <!-- End box right container --> \n " ;
2012-03-19 15:51:55 +01:00
}
2019-11-13 19:37:08 +01:00
return array ( 'selectboxlist' => count ( $boxactivated ) ? $selectboxlist : '' , 'boxactivated' => $boxactivated , 'boxlista' => $boxlista , 'boxlistb' => $boxlistb );
2012-03-19 15:51:55 +01:00
}
2019-02-27 20:45:07 +01:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2013-09-22 23:54:01 +02:00
/**
2018-02-19 19:47:42 +01:00
* Return a HTML select list of a dictionary
2013-09-22 23:54:01 +02:00
*
* @ param string $htmlname Name of select zone
2014-02-10 01:30:48 +01:00
* @ param string $dictionarytable Dictionary table
2013-09-22 23:54:01 +02:00
* @ param string $keyfield Field for key
* @ param string $labelfield Label field
2013-09-23 09:35:16 +02:00
* @ param string $selected Selected value
2013-09-22 23:54:01 +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 .
2014-04-23 14:47:02 +02:00
* @ param string $moreattrib More attributes on HTML select tag
2013-09-22 23:54:01 +02:00
* @ return void
*/
2019-02-27 20:45:07 +01:00
public function select_dictionary ( $htmlname , $dictionarytable , $keyfield = 'code' , $labelfield = 'label' , $selected = '' , $useempty = 0 , $moreattrib = '' )
2013-09-22 23:54:01 +02:00
{
2018-09-05 18:49:06 +02:00
// phpcs:enable
2013-09-22 23:54:01 +02:00
global $langs , $conf ;
$langs -> load ( " admin " );
$sql = " SELECT rowid, " . $keyfield . " , " . $labelfield ;
2019-11-13 19:37:08 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . $dictionarytable ;
$sql .= " ORDER BY " . $labelfield ;
2013-09-22 23:54:01 +02:00
2014-06-12 11:31:53 +02:00
dol_syslog ( get_class ( $this ) . " ::select_dictionary " , LOG_DEBUG );
2013-09-22 23:54:01 +02:00
$result = $this -> db -> query ( $sql );
if ( $result )
{
$num = $this -> db -> num_rows ( $result );
$i = 0 ;
if ( $num )
{
2019-11-13 19:37:08 +01:00
print '<select id="select' . $htmlname . '" class="flat selectdictionary" name="' . $htmlname . '"' . ( $moreattrib ? ' ' . $moreattrib : '' ) . '>' ;
2013-09-22 23:54:01 +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 || $selected == $obj -> $keyfield )
{
2015-05-07 12:20:20 +02:00
print '<option value="' . $obj -> $keyfield . '" selected>' ;
2013-09-22 23:54:01 +02:00
}
else
{
print '<option value="' . $obj -> $keyfield . '">' ;
}
print $obj -> $labelfield ;
print '</option>' ;
$i ++ ;
}
print " </select> " ;
2019-02-27 20:45:07 +01:00
} else {
2014-02-05 17:53:30 +01:00
print $langs -> trans ( " DictionaryEmpty " );
2013-09-22 23:54:01 +02:00
}
}
else {
dol_print_error ( $this -> db );
}
}
2019-04-04 18:33:12 +02:00
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
*/
2019-03-31 19:28:45 +02:00
public function selectAutoManual ( $htmlname , $value = '' , $option = 0 , $disabled = false , $useempty = 0 )
2019-03-31 19:26:40 +02:00
{
global $langs ;
2019-11-13 19:37:08 +01:00
$automatic = " automatic " ; $manual = " manual " ;
2019-03-31 19:26:40 +02: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 " ;
2019-11-13 19:37:08 +01:00
if ( $useempty ) $resultautomanual .= '<option value="-1"' . (( $value < 0 ) ? ' selected' : '' ) . '> </option>' . " \n " ;
2019-03-31 19:26:40 +02:00
if (( " $value " == 'automatic' ) || ( $value == 1 ))
{
$resultautomanual .= '<option value="' . $automatic . '" selected>' . $langs -> trans ( " Automatic " ) . '</option>' . " \n " ;
$resultautomanual .= '<option value="' . $manual . '">' . $langs -> trans ( " Manual " ) . '</option>' . " \n " ;
}
else
2019-10-27 11:18:36 +01:00
{
2020-03-12 12:45:44 +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
*
* @ param mixed $object Object analyzed
* @ param array $search_groupby Array of preselected fields
* @ param array $arrayofgroupby Array of groupby to fill
* @ return string HTML string component
*/
2020-03-09 18:55:47 +01:00
public function selectGroupByField ( $object , $search_groupby , & $arrayofgroupby )
{
2020-03-06 17:13:51 +01:00
global $langs , $extrafields , $form ;
2020-03-12 12:45:44 +01:00
$YYYY = substr ( $langs -> trans ( " Year " ), 0 , 1 ) . substr ( $langs -> trans ( " Year " ), 0 , 1 ) . substr ( $langs -> trans ( " Year " ), 0 , 1 ) . substr ( $langs -> trans ( " Year " ), 0 , 1 );
$MM = substr ( $langs -> trans ( " Month " ), 0 , 1 ) . substr ( $langs -> trans ( " Month " ), 0 , 1 );
$DD = substr ( $langs -> trans ( " Day " ), 0 , 1 ) . substr ( $langs -> trans ( " Day " ), 0 , 1 );
$HH = substr ( $langs -> trans ( " Hour " ), 0 , 1 ) . substr ( $langs -> trans ( " Hour " ), 0 , 1 );
$MI = substr ( $langs -> trans ( " Minute " ), 0 , 1 ) . substr ( $langs -> trans ( " Minute " ), 0 , 1 );
$SS = substr ( $langs -> trans ( " Second " ), 0 , 1 ) . substr ( $langs -> trans ( " Second " ), 0 , 1 );
2020-03-06 17:13:51 +01:00
foreach ( $object -> fields as $key => $val ) {
if ( ! $val [ 'measure' ]) {
if ( in_array ( $key , array (
'id' , 'ref_int' , 'ref_ext' , 'rowid' , 'entity' , 'last_main_doc' , 'logo' , 'logo_squarred' , 'extraparams' ,
'parent' , 'photo' , 'socialnetworks' , 'webservices_url' , 'webservices_key' ))) continue ;
if ( isset ( $val [ 'enabled' ]) && ! dol_eval ( $val [ 'enabled' ], 1 )) continue ;
if ( isset ( $val [ 'visible' ]) && ! dol_eval ( $val [ 'visible' ], 1 )) continue ;
if ( preg_match ( '/^fk_/' , $key ) && ! preg_match ( '/^fk_statu/' , $key )) continue ;
if ( preg_match ( '/^pass/' , $key )) continue ;
if ( in_array ( $val [ 'type' ], array ( 'html' , 'text' ))) continue ;
if ( in_array ( $val [ 'type' ], array ( 'timestamp' , 'date' , 'datetime' ))) {
$arrayofgroupby [ 't.' . $key . '-year' ] = array ( 'label' => $langs -> trans ( $val [ 'label' ]) . ' (' . $YYYY . ')' , 'position' => $val [ 'position' ] . '-y' );
$arrayofgroupby [ 't.' . $key . '-month' ] = array ( 'label' => $langs -> trans ( $val [ 'label' ]) . ' (' . $YYYY . '-' . $MM . ')' , 'position' => $val [ 'position' ] . '-m' );
$arrayofgroupby [ 't.' . $key . '-day' ] = array ( 'label' => $langs -> trans ( $val [ 'label' ]) . ' (' . $YYYY . '-' . $MM . '-' . $DD . ')' , 'position' => $val [ 'position' ] . '-d' );
} else {
$arrayofgroupby [ 't.' . $key ] = array ( 'label' => $langs -> trans ( $val [ 'label' ]), 'position' => ( int ) $val [ 'position' ]);
}
}
}
// Add extrafields to Group by
if ( $object -> isextrafieldmanaged ) {
foreach ( $extrafields -> attributes [ $object -> table_element ][ 'label' ] as $key => $val ) {
if ( $extrafields -> attributes [ $object -> table_element ][ 'type' ][ $key ] == 'separate' ) continue ;
if ( ! empty ( $extrafields -> attributes [ $object -> table_element ][ 'totalizable' ][ $key ])) continue ;
$arrayofgroupby [ 'te.' . $key ] = array ( 'label' => $langs -> trans ( $extrafields -> attributes [ $object -> table_element ][ 'label' ][ $key ]), 'position' => 1000 + ( int ) $extrafields -> attributes [ $object -> table_element ][ 'pos' ][ $key ]);
}
}
2020-03-08 19:25:00 +01:00
$arrayofgroupby = dol_sort_array ( $arrayofgroupby , 'position' , 'asc' , 0 , 0 , 1 );
2020-03-06 17:13:51 +01:00
$arrayofgroupbylabel = array ();
foreach ( $arrayofgroupby as $key => $val ) {
$arrayofgroupbylabel [ $key ] = $val [ 'label' ];
}
$result = $form -> selectarray ( 'search_groupby' , $arrayofgroupbylabel , $search_groupby , 1 , 0 , 0 , '' , 0 , 0 , 0 , '' , 'minwidth250' , 1 );
return $result ;
}
/**
* Return HTML select list to select a group by field
*
* @ param mixed $object Object analyzed
* @ param array $search_xaxis Array of preselected fields
* @ param array $arrayofxaxis Array of groupby to fill
* @ return string HTML string component
*/
2020-03-09 18:55:47 +01:00
public function selectXAxisField ( $object , $search_xaxis , & $arrayofxaxis )
{
2020-03-06 17:13:51 +01:00
global $langs , $extrafields , $form ;
2020-03-12 12:45:44 +01:00
$YYYY = substr ( $langs -> trans ( " Year " ), 0 , 1 ) . substr ( $langs -> trans ( " Year " ), 0 , 1 ) . substr ( $langs -> trans ( " Year " ), 0 , 1 ) . substr ( $langs -> trans ( " Year " ), 0 , 1 );
$MM = substr ( $langs -> trans ( " Month " ), 0 , 1 ) . substr ( $langs -> trans ( " Month " ), 0 , 1 );
$DD = substr ( $langs -> trans ( " Day " ), 0 , 1 ) . substr ( $langs -> trans ( " Day " ), 0 , 1 );
$HH = substr ( $langs -> trans ( " Hour " ), 0 , 1 ) . substr ( $langs -> trans ( " Hour " ), 0 , 1 );
$MI = substr ( $langs -> trans ( " Minute " ), 0 , 1 ) . substr ( $langs -> trans ( " Minute " ), 0 , 1 );
$SS = substr ( $langs -> trans ( " Second " ), 0 , 1 ) . substr ( $langs -> trans ( " Second " ), 0 , 1 );
2020-03-06 17:13:51 +01:00
foreach ( $object -> fields as $key => $val ) {
if ( ! $val [ 'measure' ]) {
if ( in_array ( $key , array (
'id' , 'ref_int' , 'ref_ext' , 'rowid' , 'entity' , 'last_main_doc' , 'logo' , 'logo_squarred' , 'extraparams' ,
'parent' , 'photo' , 'socialnetworks' , 'webservices_url' , 'webservices_key' ))) continue ;
if ( isset ( $val [ 'enabled' ]) && ! dol_eval ( $val [ 'enabled' ], 1 )) continue ;
if ( isset ( $val [ 'visible' ]) && ! dol_eval ( $val [ 'visible' ], 1 )) continue ;
if ( preg_match ( '/^fk_/' , $key ) && ! preg_match ( '/^fk_statu/' , $key )) continue ;
if ( preg_match ( '/^pass/' , $key )) continue ;
if ( in_array ( $val [ 'type' ], array ( 'html' , 'text' ))) continue ;
if ( in_array ( $val [ 'type' ], array ( 'timestamp' , 'date' , 'datetime' ))) {
$arrayofxaxis [ 't.' . $key . '-year' ] = array ( 'label' => $langs -> trans ( $val [ 'label' ]) . ' (' . $YYYY . ')' , 'position' => $val [ 'position' ] . '-y' );
$arrayofxaxis [ 't.' . $key . '-month' ] = array ( 'label' => $langs -> trans ( $val [ 'label' ]) . ' (' . $YYYY . '-' . $MM . ')' , 'position' => $val [ 'position' ] . '-m' );
$arrayofxaxis [ 't.' . $key . '-day' ] = array ( 'label' => $langs -> trans ( $val [ 'label' ]) . ' (' . $YYYY . '-' . $MM . '-' . $DD . ')' , 'position' => $val [ 'position' ] . '-d' );
} else {
2020-03-08 19:25:00 +01:00
$arrayofxaxis [ 't.' . $key ] = array ( 'label' => $langs -> trans ( $val [ 'label' ]), 'position' => ( int ) $val [ 'position' ]);
2020-03-06 17:13:51 +01:00
}
}
}
2020-03-07 16:45:28 +01:00
2020-03-06 17:13:51 +01:00
// Add extrafields to X-Axis
if ( $object -> isextrafieldmanaged ) {
foreach ( $extrafields -> attributes [ $object -> table_element ][ 'label' ] as $key => $val ) {
if ( $extrafields -> attributes [ $object -> table_element ][ 'type' ][ $key ] == 'separate' ) continue ;
if ( ! empty ( $extrafields -> attributes [ $object -> table_element ][ 'totalizable' ][ $key ])) continue ;
2020-03-07 16:45:28 +01:00
$arrayofxaxis [ 'te.' . $key ] = array ( 'label' => $langs -> trans ( $extrafields -> attributes [ $object -> table_element ][ 'label' ][ $key ]), 'position' => 1000 + ( int ) $extrafields -> attributes [ $object -> table_element ][ 'pos' ][ $key ]);
2020-03-06 17:13:51 +01:00
}
}
2020-03-08 19:25:00 +01:00
$arrayofxaxis = dol_sort_array ( $arrayofxaxis , 'position' , 'asc' , 0 , 0 , 1 );
2020-03-06 17:13:51 +01:00
$arrayofxaxislabel = array ();
foreach ( $arrayofxaxis as $key => $val ) {
$arrayofxaxislabel [ $key ] = $val [ 'label' ];
}
2020-03-07 16:45:28 +01:00
$result = $form -> selectarray ( 'search_xaxis' , $arrayofxaxislabel , $search_xaxis , 1 , 0 , 0 , '' , 0 , 0 , 0 , '' , 'minwidth250' , 1 );
2020-03-06 17:13:51 +01:00
return $result ;
}
2010-05-03 10:43:32 +02:00
}