2010-05-03 10:22:35 +02:00
< ? php
/* Copyright ( c ) 2002 - 2007 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
2012-02-06 17:29:19 +01:00
* Copyright ( C ) 2004 - 2012 Laurent Destailleur < eldy @ users . sourceforge . net >
2010-05-03 10:22:35 +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 >
2013-10-12 11:58:38 +02:00
* Copyright ( C ) 2005 - 2013 Regis Houssin < regis . houssin @ capnetworks . com >
2010-05-03 10:22:35 +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 >
2010-07-10 01:49:41 +02:00
* Copyright ( C ) 2007 Patrick Raguin < patrick . raguin @ gmail . com >
2010-08-16 15:13:15 +02:00
* Copyright ( C ) 2010 Juanjo Menent < jmenent @ 2 byte . es >
2014-03-05 09:57:36 +01:00
* Copyright ( C ) 2010 - 2014 Philippe Grand < philippe . grand @ atoo - net . com >
2011-08-19 09:22:17 +02:00
* Copyright ( C ) 2011 Herve Prot < herve . prot @ symeos . com >
2012-09-10 22:51:54 +02:00
* Copyright ( C ) 2012 Marcos García < marcosgdf @ gmail . com >
2014-03-05 09:57:36 +01:00
* Copyright ( C ) 2013 Raphaël Doursenaud < rdoursenaud @ gpcsolutions . fr >
2010-05-03 10:22:35 +02:00
*
* This program is free software ; you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
2013-01-16 15:36:08 +01:00
* the Free Software Foundation ; either version 3 of the License , or
2010-05-03 10:22:35 +02:00
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
2011-08-01 01:45:11 +02:00
* along with this program . If not , see < http :// www . gnu . org / licenses />.
2010-05-03 10:22:35 +02:00
*/
/**
2010-06-08 01:52:43 +02:00
* \file htdocs / core / class / html . form . class . php
2010-11-22 10:18:53 +01:00
* \ingroup core
2010-07-10 01:49:41 +02:00
* \brief File of class with all html predefined components
2010-05-03 10:22:35 +02:00
*/
/**
2012-02-21 10:47:08 +01:00
* Class to manage generation of HTML components
* Only common components must be here .
2010-05-03 10:22:35 +02:00
*/
class Form
{
2012-02-21 10:47:08 +01:00
var $db ;
var $error ;
2012-03-18 14:06:55 +01:00
var $num ;
2012-02-21 10:47:08 +01:00
// Cache arrays
var $cache_types_paiements = array ();
var $cache_conditions_paiements = array ();
var $cache_availability = array ();
var $cache_demand_reason = array ();
2012-07-26 11:34:43 +02:00
var $cache_types_fees = array ();
2012-03-15 11:01:29 +01:00
var $cache_vatrates = array ();
2012-02-21 10:47:08 +01:00
var $tva_taux_value ;
var $tva_taux_libelle ;
/**
* Constructor
*
* @ param DoliDB $db Database handler
*/
public function __construct ( $db )
{
$this -> db = $db ;
}
/**
* Output key field for an editable field
*
* @ param string $text Text of label or key to translate
* @ param string $htmlname Name of select field
* @ param string $preselected Name of Value to show / edit ( not used in this function )
* @ param object $object Object
* @ param boolean $perm Permission to allow button to edit parameter
2012-10-17 17:19:28 +02:00
* @ param string $typeofdata Type of data ( 'string' by default , 'email' , 'numeric:99' , 'text' or 'textarea:rows:cols' , 'day' or 'datepicker' , 'ckeditor:dolibarr_zzz:width:height:savemethod:1:rows:cols' , 'select;xxx[:class]' ... )
2012-03-18 02:01:23 +01:00
* @ param string $moreparam More param to add on a href URL
2012-02-21 10:47:08 +01:00
* @ return string HTML edit field
*/
2012-03-18 02:01:23 +01:00
function editfieldkey ( $text , $htmlname , $preselected , $object , $perm , $typeofdata = 'string' , $moreparam = '' )
2012-02-21 10:47:08 +01:00
{
global $conf , $langs ;
$ret = '' ;
2012-03-15 22:51:02 +01:00
2012-03-04 09:43:56 +01:00
// TODO change for compatibility
if ( ! empty ( $conf -> global -> MAIN_USE_JQUERY_JEDITABLE ) && ! preg_match ( '/^select;/' , $typeofdata ))
2012-02-21 10:47:08 +01:00
{
2012-10-25 11:41:55 +02:00
if ( ! empty ( $perm ))
2012-02-21 10:47:08 +01:00
{
$tmp = explode ( ':' , $typeofdata );
2012-07-08 23:22:22 +02:00
$ret .= '<div class="editkey_' . $tmp [ 0 ] . ( ! empty ( $tmp [ 1 ]) ? ' ' . $tmp [ 1 ] : '' ) . '" id="' . $htmlname . '">' ;
2012-02-21 10:47:08 +01:00
$ret .= $langs -> trans ( $text );
$ret .= '</div>' . " \n " ;
}
else
{
$ret .= $langs -> trans ( $text );
}
}
else
{
2013-04-25 01:13:13 +02:00
$ret .= '<table class="nobordernopadding" width="100%"><tr><td class="nowrap">' ;
2012-02-21 10:47:08 +01:00
$ret .= $langs -> trans ( $text );
$ret .= '</td>' ;
2012-03-18 02:01:23 +01:00
if ( GETPOST ( 'action' ) != 'edit' . $htmlname && $perm ) $ret .= '<td align="right"><a href="' . $_SERVER [ " PHP_SELF " ] . '?action=edit' . $htmlname . '&id=' . $object -> id . $moreparam . '">' . img_edit ( $langs -> trans ( 'Edit' ), 1 ) . '</a></td>' ;
2012-02-21 10:47:08 +01:00
$ret .= '</tr></table>' ;
}
return $ret ;
}
/**
* Output val field for an editable field
*
* @ param string $text Text of label ( not used in this function )
* @ param string $htmlname Name of select field
* @ param string $value Value to show / edit
* @ param object $object Object
* @ param boolean $perm Permission to allow button to edit parameter
2013-11-16 12:00:08 +01:00
* @ param string $typeofdata Type of data ( 'string' by default , 'amount' , 'email' , 'numeric:99' , 'text' or 'textarea:rows:cols' , 'day' or 'datepicker' , 'ckeditor:dolibarr_zzz:width:height:savemethod:toolbarstartexpanded:rows:cols' , 'select:xxx' ... )
2014-01-10 00:57:17 +01:00
* @ param string $editvalue When in edit mode , use this value as $value instead of value ( for example , you can provide here a formated price instead of value ) . Use '' to use same than $value
2012-02-21 10:47:08 +01:00
* @ param object $extObject External object
* @ param string $success Success message
2012-03-18 02:01:23 +01:00
* @ param string $moreparam More param to add on a href URL
2012-02-21 10:47:08 +01:00
* @ return string HTML edit field
*/
2012-03-18 02:01:23 +01:00
function editfieldval ( $text , $htmlname , $value , $object , $perm , $typeofdata = 'string' , $editvalue = '' , $extObject = null , $success = null , $moreparam = '' )
2012-02-21 10:47:08 +01:00
{
global $conf , $langs , $db ;
$ret = '' ;
2013-11-16 12:00:08 +01:00
// Check parameters
if ( empty ( $typeofdata )) return 'ErrorBadParameter' ;
2013-11-16 14:26:42 +01:00
2012-02-21 10:47:08 +01:00
// When option to edit inline is activated
2013-12-15 14:26:27 +01:00
if ( ! empty ( $conf -> global -> MAIN_USE_JQUERY_JEDITABLE ) && ! preg_match ( '/^select;|datehourpicker/' , $typeofdata )) // TODO add jquery timepicker
2012-02-21 10:47:08 +01:00
{
2012-02-22 15:04:06 +01:00
$ret .= $this -> editInPlace ( $object , $value , $htmlname , $perm , $typeofdata , $editvalue , $extObject , $success );
2012-02-21 10:47:08 +01:00
}
else
{
if ( GETPOST ( 'action' ) == 'edit' . $htmlname )
{
$ret .= " \n " ;
2012-03-18 02:01:23 +01:00
$ret .= '<form method="post" action="' . $_SERVER [ " PHP_SELF " ] . ( $moreparam ? '?' . $moreparam : '' ) . '">' ;
2012-02-21 10:47:08 +01:00
$ret .= '<input type="hidden" name="action" value="set' . $htmlname . '">' ;
$ret .= '<input type="hidden" name="token" value="' . $_SESSION [ 'newtoken' ] . '">' ;
$ret .= '<input type="hidden" name="id" value="' . $object -> id . '">' ;
$ret .= '<table class="nobordernopadding" cellpadding="0" cellspacing="0">' ;
$ret .= '<tr><td>' ;
2013-11-16 12:00:08 +01:00
if ( preg_match ( '/^(string|email|numeric|amount)/' , $typeofdata ))
2012-02-21 10:47:08 +01:00
{
$tmp = explode ( ':' , $typeofdata );
$ret .= '<input type="text" id="' . $htmlname . '" name="' . $htmlname . '" value="' . ( $editvalue ? $editvalue : $value ) . '"' . ( $tmp [ 1 ] ? ' size="' . $tmp [ 1 ] . '"' : '' ) . '>' ;
}
2012-03-17 23:27:53 +01:00
else if ( preg_match ( '/^text/' , $typeofdata ) || preg_match ( '/^note/' , $typeofdata ))
2012-02-21 10:47:08 +01:00
{
2012-03-17 23:27:53 +01:00
$tmp = explode ( ':' , $typeofdata );
$ret .= '<textarea id="' . $htmlname . '" name="' . $htmlname . '" wrap="soft" rows="' . ( $tmp [ 1 ] ? $tmp [ 1 ] : '20' ) . '" cols="' . ( $tmp [ 2 ] ? $tmp [ 2 ] : '100' ) . '">' . ( $editvalue ? $editvalue : $value ) . '</textarea>' ;
2012-02-21 10:47:08 +01:00
}
else if ( $typeofdata == 'day' || $typeofdata == 'datepicker' )
{
$ret .= $this -> form_date ( $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id , $value , $htmlname );
}
2012-12-01 15:45:05 +01:00
else if ( $typeofdata == 'datehourpicker' )
{
$ret .= $this -> form_date ( $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id , $value , $htmlname , 1 , 1 );
}
2012-03-04 01:41:36 +01:00
else if ( preg_match ( '/^select;/' , $typeofdata ))
{
$arraydata = explode ( ',' , preg_replace ( '/^select;/' , '' , $typeofdata ));
foreach ( $arraydata as $val )
{
$tmp = explode ( ':' , $val );
$arraylist [ $tmp [ 0 ]] = $tmp [ 1 ];
}
$ret .= $this -> selectarray ( $htmlname , $arraylist , $value );
}
2012-02-21 10:47:08 +01:00
else if ( preg_match ( '/^ckeditor/' , $typeofdata ))
{
$tmp = explode ( ':' , $typeofdata );
2012-08-22 23:11:24 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/class/doleditor.class.php' ;
2012-03-18 11:22:28 +01:00
$doleditor = new DolEditor ( $htmlname , ( $editvalue ? $editvalue : $value ), ( $tmp [ 2 ] ? $tmp [ 2 ] : '' ), ( $tmp [ 3 ] ? $tmp [ 3 ] : '100' ), ( $tmp [ 1 ] ? $tmp [ 1 ] : 'dolibarr_notes' ), 'In' , ( $tmp [ 5 ] ? $tmp [ 5 ] : 0 ), true , true , ( $tmp [ 6 ] ? $tmp [ 6 ] : '20' ), ( $tmp [ 7 ] ? $tmp [ 7 ] : '100' ));
2012-02-21 10:47:08 +01:00
$ret .= $doleditor -> Create ( 1 );
}
$ret .= '</td>' ;
2014-01-10 00:57:17 +01:00
if ( $typeofdata != 'day' && $typeofdata != 'datepicker' && $typeofdata != 'datehourpicker' )
{
2014-05-29 19:56:15 +02:00
$ret .= '<td align="left">' ;
$ret .= '<input type="submit" class="button" name="modify" value="' . $langs -> trans ( " Modify " ) . '">' ;
$ret .= '<br>' . " \n " ;
2014-01-11 13:33:30 +01:00
$ret .= '<input type="submit" class="button" name="cancel" value="' . $langs -> trans ( " Cancel " ) . '">' ;
2014-01-10 00:57:17 +01:00
$ret .= '</td>' ;
}
2012-02-21 10:47:08 +01:00
$ret .= '</tr></table>' . " \n " ;
$ret .= '</form>' . " \n " ;
}
else
2013-11-16 14:26:42 +01:00
{
2013-11-28 15:54:12 +01:00
if ( $typeofdata == 'email' ) $ret .= dol_print_email ( $value , 0 , 0 , 0 , 0 , 1 );
2014-04-11 19:20:11 +02:00
elseif ( $typeofdata == 'amount' ) $ret .= ( $value != '' ? price ( $value , '' , $langs , 0 , 0 , - 1 , $conf -> currency ) : '' );
2012-04-20 13:36:51 +02:00
elseif ( preg_match ( '/^text/' , $typeofdata ) || preg_match ( '/^note/' , $typeofdata )) $ret .= dol_htmlentitiesbr ( $value );
2012-02-21 10:47:08 +01:00
elseif ( $typeofdata == 'day' || $typeofdata == 'datepicker' ) $ret .= dol_print_date ( $value , 'day' );
2012-12-01 15:45:05 +01:00
elseif ( $typeofdata == 'datehourpicker' ) $ret .= dol_print_date ( $value , 'dayhour' );
2012-03-04 01:41:36 +01:00
else if ( preg_match ( '/^select;/' , $typeofdata ))
{
$arraydata = explode ( ',' , preg_replace ( '/^select;/' , '' , $typeofdata ));
foreach ( $arraydata as $val )
{
$tmp = explode ( ':' , $val );
$arraylist [ $tmp [ 0 ]] = $tmp [ 1 ];
}
$ret .= $arraylist [ $value ];
}
2012-02-21 10:47:08 +01:00
else if ( preg_match ( '/^ckeditor/' , $typeofdata ))
{
$tmpcontent = dol_htmlentitiesbr ( $value );
2012-03-22 00:21:45 +01:00
if ( ! empty ( $conf -> global -> MAIN_DISABLE_NOTES_TAB ))
{
$firstline = preg_replace ( '/<br>.*/' , '' , $tmpcontent );
$firstline = preg_replace ( '/[\n\r].*/' , '' , $firstline );
$tmpcontent = $firstline . (( strlen ( $firstline ) != strlen ( $tmpcontent )) ? '...' : '' );
}
$ret .= $tmpcontent ;
2012-02-21 10:47:08 +01:00
}
else $ret .= $value ;
}
}
return $ret ;
}
/**
* Output edit in place form
*
2011-11-08 23:10:31 +01:00
* @ param object $object Object
2011-11-05 15:12:37 +01:00
* @ param string $value Value to show / edit
* @ param string $htmlname DIV ID ( field name )
* @ param int $condition Condition to edit
2012-03-18 12:48:07 +01:00
* @ param string $inputType Type of input ( 'numeric' , 'datepicker' , 'textarea:rows:cols' , 'ckeditor:dolibarr_zzz:width:height:?:1:rows:cols' , 'select:xxx' )
2012-02-22 15:04:06 +01:00
* @ param string $editvalue When in edit mode , use this value as $value instead of value
2011-11-09 16:54:34 +01:00
* @ param object $extObject External object
2012-03-04 01:41:36 +01:00
* @ param string $success Success message
2011-11-05 15:12:37 +01:00
* @ return string HTML edit in place
2011-10-27 10:15:49 +02:00
*/
2012-02-22 15:04:06 +01:00
private function editInPlace ( $object , $value , $htmlname , $condition , $inputType = 'textarea' , $editvalue = null , $extObject = null , $success = null )
2012-02-21 10:47:08 +01:00
{
global $conf ;
$out = '' ;
// Check parameters
if ( $inputType == 'textarea' ) $value = dol_nl2br ( $value );
else if ( preg_match ( '/^numeric/' , $inputType )) $value = price ( $value );
else if ( $inputType == 'datepicker' ) $value = dol_print_date ( $value , 'day' );
if ( $condition )
{
2012-02-22 15:04:06 +01:00
$element = false ;
$table_element = false ;
$fk_element = false ;
$loadmethod = false ;
$savemethod = false ;
$ext_element = false ;
$button_only = false ;
2012-02-21 10:47:08 +01:00
if ( is_object ( $object ))
{
$element = $object -> element ;
$table_element = $object -> table_element ;
$fk_element = $object -> id ;
}
if ( is_object ( $extObject ))
{
$ext_element = $extObject -> element ;
}
if ( preg_match ( '/^(string|email|numeric)/' , $inputType ))
{
$tmp = explode ( ':' , $inputType );
2012-07-08 23:22:22 +02:00
$inputType = $tmp [ 0 ];
if ( ! empty ( $tmp [ 1 ])) $inputOption = $tmp [ 1 ];
2012-02-21 10:47:08 +01:00
if ( ! empty ( $tmp [ 2 ])) $savemethod = $tmp [ 2 ];
}
2012-12-01 15:45:05 +01:00
else if (( preg_match ( '/^datepicker/' , $inputType )) || ( preg_match ( '/^datehourpicker/' , $inputType )))
2012-02-21 10:47:08 +01:00
{
$tmp = explode ( ':' , $inputType );
2012-07-11 18:13:41 +02:00
$inputType = $tmp [ 0 ];
if ( ! empty ( $tmp [ 1 ])) $inputOption = $tmp [ 1 ];
2012-02-21 10:47:08 +01:00
if ( ! empty ( $tmp [ 2 ])) $savemethod = $tmp [ 2 ];
$out .= '<input id="timestamp" type="hidden"/>' . " \n " ; // Use for timestamp format
}
2012-03-12 16:02:50 +01:00
else if ( preg_match ( '/^(select|autocomplete)/' , $inputType ))
2012-02-21 10:47:08 +01:00
{
$tmp = explode ( ':' , $inputType );
$inputType = $tmp [ 0 ]; $loadmethod = $tmp [ 1 ];
if ( ! empty ( $tmp [ 2 ])) $savemethod = $tmp [ 2 ];
2012-02-22 15:04:06 +01:00
if ( ! empty ( $tmp [ 3 ])) $button_only = true ;
2012-02-21 10:47:08 +01:00
}
2012-07-02 19:30:37 +02:00
else if ( preg_match ( '/^textarea/' , $inputType ))
{
$tmp = explode ( ':' , $inputType );
2012-03-18 11:13:01 +01:00
$inputType = $tmp [ 0 ];
2012-10-23 23:49:16 +02:00
$rows = ( empty ( $tmp [ 1 ]) ? '8' : $tmp [ 1 ]);
$cols = ( empty ( $tmp [ 2 ]) ? '80' : $tmp [ 2 ]);
2012-03-18 11:13:01 +01:00
}
2012-02-21 10:47:08 +01:00
else if ( preg_match ( '/^ckeditor/' , $inputType ))
{
$tmp = explode ( ':' , $inputType );
$inputType = $tmp [ 0 ]; $toolbar = $tmp [ 1 ];
if ( ! empty ( $tmp [ 2 ])) $width = $tmp [ 2 ];
if ( ! empty ( $tmp [ 3 ])) $heigth = $tmp [ 3 ];
if ( ! empty ( $tmp [ 4 ])) $savemethod = $tmp [ 4 ];
if ( ! empty ( $conf -> fckeditor -> enabled ))
{
$out .= '<input id="ckeditor_toolbar" value="' . $toolbar . '" type="hidden"/>' . " \n " ;
}
else
{
$inputType = 'textarea' ;
}
}
$out .= '<input id="element_' . $htmlname . '" value="' . $element . '" type="hidden"/>' . " \n " ;
$out .= '<input id="table_element_' . $htmlname . '" value="' . $table_element . '" type="hidden"/>' . " \n " ;
$out .= '<input id="fk_element_' . $htmlname . '" value="' . $fk_element . '" type="hidden"/>' . " \n " ;
$out .= '<input id="loadmethod_' . $htmlname . '" value="' . $loadmethod . '" type="hidden"/>' . " \n " ;
2012-03-12 16:02:50 +01:00
if ( ! empty ( $savemethod )) $out .= '<input id="savemethod_' . $htmlname . '" value="' . $savemethod . '" type="hidden"/>' . " \n " ;
if ( ! empty ( $ext_element )) $out .= '<input id="ext_element_' . $htmlname . '" value="' . $ext_element . '" type="hidden"/>' . " \n " ;
if ( ! empty ( $success )) $out .= '<input id="success_' . $htmlname . '" value="' . $success . '" type="hidden"/>' . " \n " ;
2012-10-23 09:30:48 +02:00
if ( $inputType == 'textarea' ) {
$out .= '<input id="textarea_' . $htmlname . '_rows" value="' . $rows . '" type="hidden"/>' . " \n " ;
$out .= '<input id="textarea_' . $htmlname . '_cols" value="' . $cols . '" type="hidden"/>' . " \n " ;
}
2012-03-04 01:41:36 +01:00
2012-07-26 11:34:43 +02:00
$out .= '<span id="viewval_' . $htmlname . '" class="viewval_' . $inputType . ( $button_only ? ' inactive' : ' active' ) . '">' . $value . '</span>' . " \n " ;
$out .= '<span id="editval_' . $htmlname . '" class="editval_' . $inputType . ( $button_only ? ' inactive' : ' active' ) . ' hideobject">' . ( ! empty ( $editvalue ) ? $editvalue : $value ) . '</span>' . " \n " ;
2012-02-21 10:47:08 +01:00
}
else
{
$out = $value ;
}
return $out ;
}
/**
* Show a text and picto with tooltip on text or picto
*
* @ param string $text Text to show
2013-04-22 10:33:06 +02:00
* @ param string $htmltext HTML content of tooltip . Must be HTML / UTF8 encoded .
2013-09-03 18:08:50 +02:00
* @ param int $tooltipon 1 = tooltip on text , 2 = tooltip on image , 3 = tooltip sur les 2
* @ param int $direction - 1 = image is before , 0 = no image , 1 = image is after
* @ param string $img Html code for image ( use img_xxx () function to get it )
2012-02-21 10:47:08 +01:00
* @ param string $extracss Add a CSS style to td tags
2012-08-26 13:44:42 +02:00
* @ param int $notabs 0 = Include table and tr tags , 1 = Do not include table and tr tags , 2 = use div , 3 = use span
2012-02-21 10:47:08 +01:00
* @ param string $incbefore Include code before the text
* @ param int $noencodehtmltext Do not encode into html entity the htmltext
* @ return string Code html du tooltip ( texte + picto )
* @ see Use function textwithpicto if you can .
*/
2012-07-30 22:36:43 +02:00
function textwithtooltip ( $text , $htmltext , $tooltipon = 1 , $direction = 0 , $img = '' , $extracss = '' , $notabs = 0 , $incbefore = '' , $noencodehtmltext = 0 )
2012-02-21 10:47:08 +01:00
{
global $conf ;
if ( $incbefore ) $text = $incbefore . $text ;
if ( ! $htmltext ) return $text ;
2012-08-22 17:42:40 +02:00
$tag = 'td' ;
if ( $notabs == 2 ) $tag = 'div' ;
if ( $notabs == 3 ) $tag = 'span' ;
2012-02-21 10:47:08 +01:00
// Sanitize tooltip
$htmltext = str_replace ( " \\ " , " \\ \\ " , $htmltext );
$htmltext = str_replace ( " \r " , " " , $htmltext );
$htmltext = str_replace ( " \n " , " " , $htmltext );
$htmltext = str_replace ( '"' , " " " , $htmltext );
if ( $tooltipon == 2 || $tooltipon == 3 ) $paramfortooltipimg = ' class="classfortooltip' . ( $extracss ? ' ' . $extracss : '' ) . '" title="' . ( $noencodehtmltext ? $htmltext : dol_escape_htmltag ( $htmltext , 1 )) . '"' ; // Attribut to put on td img tag to store tooltip
else $paramfortooltipimg = ( $extracss ? ' class="' . $extracss . '"' : '' ); // Attribut to put on td text tag
if ( $tooltipon == 1 || $tooltipon == 3 ) $paramfortooltiptd = ' class="classfortooltip' . ( $extracss ? ' ' . $extracss : '' ) . '" title="' . ( $noencodehtmltext ? $htmltext : dol_escape_htmltag ( $htmltext , 1 )) . '"' ; // Attribut to put on td tag to store tooltip
else $paramfortooltiptd = ( $extracss ? ' class="' . $extracss . '"' : '' ); // Attribut to put on td text tag
$s = " " ;
2012-09-13 10:02:45 +02:00
if ( empty ( $notabs )) $s .= '<table class="nobordernopadding" summary=""><tr>' ;
2012-09-15 09:02:20 +02:00
if ( $direction < 0 ) $s .= '<' . $tag . $paramfortooltipimg . ' valign="top" width="14">' . $img . '</' . $tag . '>' ;
2012-12-07 13:48:11 +01:00
// Use another method to help avoid having a space in value in order to use this value with jquery
// TODO add this in css
//if ($text != '') $s.='<'.$tag.$paramfortooltiptd.'>'.(($direction < 0)?' ':'').$text.(($direction > 0)?' ':'').'</'.$tag.'>';
$paramfortooltiptd .= (( $direction < 0 ) ? ' style="padding-left: 3px !important;"' : '' );
$paramfortooltiptd .= (( $direction > 0 ) ? ' style="padding-right: 3px !important;"' : '' );
2013-04-22 10:33:06 +02:00
if (( string ) $text != '' ) $s .= '<' . $tag . $paramfortooltiptd . '>' . $text . '</' . $tag . '>' ;
2012-09-13 16:13:12 +02:00
if ( $direction > 0 ) $s .= '<' . $tag . $paramfortooltipimg . ' valign="top" width="14">' . $img . '</' . $tag . '>' ;
2012-09-13 10:02:45 +02:00
if ( empty ( $notabs )) $s .= '</tr></table>' ;
2012-02-21 10:47:08 +01:00
return $s ;
}
2010-08-22 17:46:34 +02:00
/**
2010-10-23 15:01:48 +02:00
* Show a text with a picto and a tooltip on picto
2011-08-31 23:02:55 +02:00
*
2012-02-01 09:29:26 +01:00
* @ param string $text Text to show
2012-03-19 17:18:11 +01:00
* @ param string $htmltext Content of tooltip
2012-02-01 09:29:26 +01:00
* @ param int $direction 1 = Icon is after text , - 1 = Icon is before text , 0 = no icon
* @ param string $type Type of picto ( info , help , warning , superadmin ... )
* @ param string $extracss Add a CSS style to td tags
* @ param int $noencodehtmltext Do not encode into html entity the htmltext
2012-09-13 09:52:03 +02:00
* @ param int $notabs 0 = Include table and tr tags , 1 = Do not include table and tr tags , 2 = use div , 3 = use span
2012-02-01 09:29:26 +01:00
* @ return string HTML code of text , picto , tooltip
2010-08-22 17:46:34 +02:00
*/
2012-09-13 09:52:03 +02:00
function textwithpicto ( $text , $htmltext , $direction = 1 , $type = 'help' , $extracss = '' , $noencodehtmltext = 0 , $notabs = 0 )
2010-08-22 17:46:34 +02:00
{
global $conf ;
2012-07-30 22:36:43 +02:00
$alt = '' ;
//For backwards compatibility
if ( $type == '0' ) $type = 'info' ;
elseif ( $type == '1' ) $type = 'help' ;
2010-08-22 17:46:34 +02:00
// If info or help with no javascript, show only text
if ( empty ( $conf -> use_javascript_ajax ))
{
if ( $type == 'info' || $type == 'help' ) return $text ;
2012-07-30 22:36:43 +02:00
else
{
$alt = $htmltext ;
$htmltext = '' ;
2012-02-21 10:47:08 +01:00
}
2010-08-22 17:46:34 +02:00
}
2013-04-03 15:20:56 +02:00
// If info or help with smartphone, show only text (tooltip can't works)
if ( ! empty ( $conf -> dol_no_mouse_hover ))
2010-08-22 17:46:34 +02:00
{
if ( $type == 'info' || $type == 'help' ) return $text ;
}
2012-08-05 14:37:45 +02:00
2012-07-30 22:36:43 +02:00
if ( $type == 'info' ) $img = img_help ( 0 , $alt );
elseif ( $type == 'help' ) $img = img_help ( 1 , $alt );
elseif ( $type == 'superadmin' ) $img = img_picto ( $alt , 'redstar' );
elseif ( $type == 'admin' ) $img = img_picto ( $alt , 'star' );
elseif ( $type == 'warning' ) $img = img_warning ( $alt );
2012-09-13 09:52:03 +02:00
return $this -> textwithtooltip ( $text , $htmltext , 2 , $direction , $img , $extracss , $notabs , '' , $noencodehtmltext );
2010-08-22 17:46:34 +02:00
}
2010-09-02 21:31:18 +02:00
2010-09-01 22:51:10 +02:00
/**
2012-02-21 10:47:08 +01:00
* Return combo list of activated countries , into language of user
2011-10-01 21:55:40 +02:00
*
2012-02-21 10:47:08 +01:00
* @ param string $selected Id or Code or Label of preselected country
* @ param string $htmlname Name of html select object
* @ param string $htmloption Options html on select object
2012-10-15 23:13:28 +02:00
* @ param string $maxlength Max length for labels ( 0 = no limit )
2012-02-21 10:47:08 +01:00
* @ return string HTML string with select
2010-09-01 22:51:10 +02:00
*/
2013-02-25 09:17:38 +01:00
function select_country ( $selected = '' , $htmlname = 'country_id' , $htmloption = '' , $maxlength = 0 )
2010-08-22 17:46:34 +02:00
{
global $conf , $langs ;
2011-03-19 03:17:05 +01:00
2010-08-22 17:46:34 +02:00
$langs -> load ( " dict " );
2010-09-02 21:31:18 +02:00
2010-09-01 22:51:10 +02:00
$out = '' ;
2011-03-10 13:09:59 +01:00
$countryArray = array ();
$label = array ();
2010-08-22 17:46:34 +02:00
2014-08-14 01:04:15 +02:00
$sql = " SELECT rowid, code as code_iso, code_iso as code_iso3, label " ;
2014-08-10 13:37:39 +02:00
$sql .= " FROM " . MAIN_DB_PREFIX . " c_country " ;
2010-08-22 17:46:34 +02:00
$sql .= " WHERE active = 1 " ;
2013-08-08 20:06:56 +02:00
//$sql.= " ORDER BY code ASC";
2010-08-22 17:46:34 +02:00
2014-06-12 11:31:53 +02:00
dol_syslog ( get_class ( $this ) . " ::select_country " , LOG_DEBUG );
2010-08-22 17:46:34 +02:00
$resql = $this -> db -> query ( $sql );
if ( $resql )
{
2014-08-10 13:37:39 +02:00
$out .= '<select id="select' . $htmlname . '" class="flat selectcountry" name="' . $htmlname . '" ' . $htmloption . '>' ;
2010-08-22 17:46:34 +02:00
$num = $this -> db -> num_rows ( $resql );
$i = 0 ;
if ( $num )
{
$foundselected = false ;
2011-03-19 03:17:05 +01:00
2012-02-21 10:47:08 +01:00
while ( $i < $num )
{
2010-08-22 17:46:34 +02:00
$obj = $this -> db -> fetch_object ( $resql );
2011-03-10 13:09:59 +01:00
$countryArray [ $i ][ 'rowid' ] = $obj -> rowid ;
$countryArray [ $i ][ 'code_iso' ] = $obj -> code_iso ;
2014-08-13 19:19:36 +02:00
$countryArray [ $i ][ 'code_iso3' ] = $obj -> code_iso3 ;
2011-10-19 02:45:42 +02:00
$countryArray [ $i ][ 'label' ] = ( $obj -> code_iso && $langs -> transnoentitiesnoconv ( " Country " . $obj -> code_iso ) != " Country " . $obj -> code_iso ? $langs -> transnoentitiesnoconv ( " Country " . $obj -> code_iso ) : ( $obj -> label != '-' ? $obj -> label : '' ));
2013-08-08 20:06:56 +02:00
$label [ $i ] = dol_string_unaccent ( $countryArray [ $i ][ 'label' ]);
2011-03-10 13:09:59 +01:00
$i ++ ;
}
array_multisort ( $label , SORT_ASC , $countryArray );
2011-11-01 04:57:45 +01:00
2011-03-19 03:17:05 +01:00
foreach ( $countryArray as $row )
{
2012-02-21 10:47:08 +01:00
//print 'rr'.$selected.'-'.$row['label'].'-'.$row['code_iso'].'<br>';
2014-08-13 19:19:36 +02:00
if ( $selected && $selected != '-1' && ( $selected == $row [ 'rowid' ] || $selected == $row [ 'code_iso' ] || $selected == $row [ 'code_iso3' ] || $selected == $row [ 'label' ]) )
2012-02-21 10:47:08 +01:00
{
$foundselected = true ;
2011-03-10 13:09:59 +01:00
$out .= '<option value="' . $row [ 'rowid' ] . '" selected="selected">' ;
2011-10-19 02:45:42 +02:00
}
else
2013-08-08 20:06:56 +02:00
{
2011-03-10 13:09:59 +01:00
$out .= '<option value="' . $row [ 'rowid' ] . '">' ;
2010-08-22 17:46:34 +02:00
}
2012-10-15 23:13:28 +02:00
$out .= dol_trunc ( $row [ 'label' ], $maxlength , 'middle' );
2011-03-19 03:17:05 +01:00
if ( $row [ 'code_iso' ]) $out .= ' (' . $row [ 'code_iso' ] . ')' ;
2010-09-01 22:51:10 +02:00
$out .= '</option>' ;
2010-08-22 17:46:34 +02:00
}
}
2010-09-01 22:51:10 +02:00
$out .= '</select>' ;
2010-08-22 17:46:34 +02:00
}
else
2013-08-08 20:06:56 +02:00
{
2010-08-22 17:46:34 +02:00
dol_print_error ( $this -> db );
}
2010-09-02 21:31:18 +02:00
2010-09-01 22:51:10 +02:00
return $out ;
2010-08-22 17:46:34 +02:00
}
/**
2012-02-21 10:47:08 +01:00
* Return list of types of lines ( product or service )
* Example : 0 = product , 1 = service , 9 = other ( for external module )
2011-10-01 21:55:40 +02:00
*
2012-02-21 10:47:08 +01:00
* @ param string $selected Preselected type
* @ param string $htmlname Name of field in html form
* @ param int $showempty Add an empty field
2014-07-19 21:14:56 +02:00
* @ param int $hidetext Do not show label 'Type' before combo box ( used only if there is at least 2 choices to select )
2014-07-19 22:05:35 +02:00
* @ param string $forceall 1 = Force to show products and services in combo list , whatever are activated modules , 0 = No force , - 1 = Force none ( and set hidden field to 'service' )
2012-02-21 10:47:08 +01:00
* @ return void
2010-08-22 17:46:34 +02:00
*/
function select_type_of_lines ( $selected = '' , $htmlname = 'type' , $showempty = 0 , $hidetext = 0 , $forceall = 0 )
{
global $db , $langs , $user , $conf ;
// If product & services are enabled or both disabled.
2014-07-19 22:05:35 +02:00
if ( $forceall > 0 || ( empty ( $forceall ) && ! empty ( $conf -> product -> enabled ) && ! empty ( $conf -> service -> enabled ))
|| ( empty ( $forceall ) && empty ( $conf -> product -> enabled ) && empty ( $conf -> service -> enabled )) )
2010-08-22 17:46:34 +02:00
{
if ( empty ( $hidetext )) print $langs -> trans ( " Type " ) . ': ' ;
2012-08-22 17:42:40 +02:00
print '<select class="flat" id="select_' . $htmlname . '" name="' . $htmlname . '">' ;
2010-08-22 17:46:34 +02:00
if ( $showempty )
{
print '<option value="-1"' ;
2010-11-01 17:00:38 +01:00
if ( $selected == - 1 ) print ' selected="selected"' ;
2010-08-22 17:46:34 +02:00
print '> </option>' ;
}
print '<option value="0"' ;
2010-11-01 17:00:38 +01:00
if ( 0 == $selected ) print ' selected="selected"' ;
2010-08-22 17:46:34 +02:00
print '>' . $langs -> trans ( " Product " );
print '<option value="1"' ;
2010-11-01 17:00:38 +01:00
if ( 1 == $selected ) print ' selected="selected"' ;
2010-08-22 17:46:34 +02:00
print '>' . $langs -> trans ( " Service " );
print '</select>' ;
2014-02-05 17:53:30 +01:00
//if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
2010-08-22 17:46:34 +02:00
}
2014-07-19 22:05:35 +02:00
if ( empty ( $forceall ) && empty ( $conf -> product -> enabled ) && ! empty ( $conf -> service -> enabled ))
2010-08-22 17:46:34 +02:00
{
2014-07-19 21:14:56 +02:00
print $langs -> trans ( " Service " );
2010-08-22 17:46:34 +02:00
print '<input type="hidden" name="' . $htmlname . '" value="1">' ;
}
2014-07-19 22:05:35 +02:00
if ( empty ( $forceall ) && ! empty ( $conf -> product -> enabled ) && empty ( $conf -> service -> enabled ))
2010-08-22 17:46:34 +02:00
{
2014-07-19 21:14:56 +02:00
print $langs -> trans ( " Product " );
2010-08-22 17:46:34 +02:00
print '<input type="hidden" name="' . $htmlname . '" value="0">' ;
}
2014-07-19 22:05:35 +02:00
if ( $forceall < 0 ) // This should happened only for contracts when both predefined product and service are disabled.
{
print '<input type="hidden" name="' . $htmlname . '" value="1">' ; // By default we set on service for contract. If CONTRACT_SUPPORT_PRODUCTS is set, forceall should be 1 not -1
}
2010-08-22 17:46:34 +02:00
}
2011-11-01 04:57:45 +01:00
2011-10-31 11:49:47 +01:00
/**
* Load into cache cache_types_fees , array of types of fees
*
* @ return int Nb of lines loaded , 0 if already loaded , < 0 if ko
* TODO move in DAO class
*/
function load_cache_types_fees ()
{
2012-02-21 10:47:08 +01:00
global $langs ;
$langs -> load ( " trips " );
if ( count ( $this -> cache_types_fees )) return 0 ; // Cache already load
2014-08-10 20:41:52 +02:00
$sql = " SELECT c.code, c.label " ;
2012-02-21 10:47:08 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " c_type_fees as c " ;
$sql .= " ORDER BY lower(c.libelle) ASC " ;
2014-06-13 01:34:39 +02:00
dol_syslog ( get_class ( $this ) . '::load_cache_types_fees' , LOG_DEBUG );
2012-02-21 10:47:08 +01:00
$resql = $this -> db -> query ( $sql );
if ( $resql )
{
$num = $this -> db -> num_rows ( $resql );
$i = 0 ;
while ( $i < $num )
{
$obj = $this -> db -> fetch_object ( $resql );
// Si traduction existe, on l'utilise, sinon on prend le libelle par defaut
$label = ( $obj -> code != $langs -> trans ( $obj -> code ) ? $langs -> trans ( $obj -> code ) : $langs -> trans ( $obj -> label ));
$this -> cache_types_fees [ $obj -> code ] = $label ;
$i ++ ;
}
return $num ;
}
else
{
dol_print_error ( $this -> db );
return - 1 ;
}
2011-10-31 11:49:47 +01:00
}
2010-08-22 17:46:34 +02:00
/**
2011-10-31 11:49:47 +01:00
* Return list of types of notes
2011-09-15 01:15:38 +02:00
*
2012-02-21 10:47:08 +01:00
* @ param string $selected Preselected type
* @ param string $htmlname Name of field in form
* @ param int $showempty Add an empty field
* @ return void
2010-08-22 17:46:34 +02:00
*/
function select_type_fees ( $selected = '' , $htmlname = 'type' , $showempty = 0 )
{
2011-10-31 11:49:47 +01:00
global $user , $langs ;
2011-11-01 04:57:45 +01:00
2011-10-31 11:49:47 +01:00
dol_syslog ( get_class ( $this ) . " ::select_type_fees " . $selected . " , " . $htmlname , LOG_DEBUG );
2011-11-01 04:57:45 +01:00
2011-10-31 11:49:47 +01:00
$this -> load_cache_types_fees ();
2010-08-22 17:46:34 +02:00
print '<select class="flat" name="' . $htmlname . '">' ;
if ( $showempty )
{
print '<option value="-1"' ;
2010-11-01 17:00:38 +01:00
if ( $selected == - 1 ) print ' selected="selected"' ;
2010-08-22 17:46:34 +02:00
print '> </option>' ;
}
2011-11-01 04:57:45 +01:00
2011-10-31 11:49:47 +01:00
foreach ( $this -> cache_types_fees as $key => $value )
2010-08-22 17:46:34 +02:00
{
2012-02-21 10:47:08 +01:00
print '<option value="' . $key . '"' ;
if ( $key == $selected ) print ' selected="selected"' ;
print '>' ;
print $value ;
print '</option>' ;
2010-08-22 17:46:34 +02:00
}
2011-10-31 11:49:47 +01:00
2010-08-22 17:46:34 +02:00
print '</select>' ;
2014-02-05 17:53:30 +01:00
if ( $user -> admin ) print info_admin ( $langs -> trans ( " YouCanChangeValuesForThisListFromDictionarySetup " ), 1 );
2010-08-22 17:46:34 +02:00
}
2010-11-18 23:17:44 +01:00
2013-06-05 22:01:35 +02:00
2013-06-06 18:31:33 +02:00
/**
2014-02-03 20:05:56 +01:00
* Return HTML code to select a company .
2013-06-06 18:31:33 +02:00
*
* @ param int $selected Preselected products
2014-06-29 02:45:55 +02:00
* @ param string $htmlname Name of HTML select field ( must be unique in page )
2013-06-06 18:31:33 +02:00
* @ param int $filter Filter on thirdparty
* @ param int $limit Limit on number of returned lines
* @ param array $ajaxoptions Options for ajax_autocompleter
2013-06-05 22:27:02 +02:00
* @ param int $forcecombo Force to use combo box
2014-02-03 20:05:56 +01:00
* @ return string Return select box for thirdparty .
2013-06-06 18:31:33 +02:00
*/
2014-08-13 19:19:36 +02:00
function select_thirdparty ( $selected = '' , $htmlname = 'socid' , $filter = '' , $limit = 20 , $ajaxoptions = array (), $forcecombo = 0 )
2013-06-06 18:31:33 +02:00
{
global $langs , $conf ;
2014-02-03 20:05:56 +01:00
$out = '' ;
2014-02-04 20:49:07 +01:00
/* TODO Use ajax_autocompleter like for products ( not finished )
2013-06-06 18:31:33 +02:00
if ( ! empty ( $conf -> use_javascript_ajax ) && ! empty ( $conf -> global -> COMPANY_USE_SEARCH_TO_SELECT ) && ! $forcecombo )
{
$placeholder = '' ;
if ( $selected && empty ( $selected_input_value ))
{
2014-02-04 20:49:07 +01:00
require_once DOL_DOCUMENT_ROOT . '/societe/ajaxcompanies.php' ;
2013-06-06 18:31:33 +02:00
$societe = new Societe ( $this -> db );
$societe -> fetch ( $selected );
$selected_input_value = $societe -> ref ;
}
// mode=1 means customers products
$urloption = 'htmlname=' . $htmlname . '&outjson=1&price_level=' . $price_level . '&type=' . $filtertype . '&mode=1&status=' . $status . '&finished=' . $finished ;
print ajax_autocompleter ( $selected , $htmlname , DOL_URL_ROOT . '/societe/ajax/company.php' , $urloption , $conf -> global -> COMPANY_USE_SEARCH_TO_SELECT , 0 , $ajaxoptions );
if ( empty ( $hidelabel )) print $langs -> trans ( " RefOrLabel " ) . ' : ' ;
else if ( $hidelabel > 1 ) {
if ( ! empty ( $conf -> global -> MAIN_HTML5_PLACEHOLDER )) $placeholder = ' placeholder="' . $langs -> trans ( " RefOrLabel " ) . '"' ;
else $placeholder = ' title="' . $langs -> trans ( " RefOrLabel " ) . '"' ;
if ( $hidelabel == 2 ) {
print img_picto ( $langs -> trans ( " Search " ), 'search' );
}
}
print '<input type="text" size="20" name="search_' . $htmlname . '" id="search_' . $htmlname . '" value="' . $selected_input_value . '"' . $placeholder . ' />' ;
if ( $hidelabel == 3 ) {
print img_picto ( $langs -> trans ( " Search " ), 'search' );
}
}
else
{ */
2014-02-03 20:05:56 +01:00
$out .= $this -> select_thirdparty_list ( $selected , $htmlname , $filter , 1 , 0 , $forcecombo , array (), '' , 0 , $limit );
2013-06-06 18:31:33 +02:00
//}
2014-02-03 20:05:56 +01:00
return $out ;
2013-06-05 22:01:35 +02:00
}
2013-06-06 18:31:33 +02:00
/**
* Output html form to select a third party
*
* @ param string $selected Preselected type
* @ param string $htmlname Name of field in form
2014-03-05 09:57:36 +01:00
* @ param string $filter optional filters criteras ( example : 's.rowid <> x' )
2013-06-06 18:31:33 +02:00
* @ param int $showempty Add an empty field
* @ param int $showtype Show third party type in combolist ( customer , prospect or supplier )
* @ param int $forcecombo Force to use combo box
2014-02-04 20:49:07 +01:00
* @ param array $events Event options . Example : array ( array ( 'method' => 'getContacts' , 'url' => dol_buildpath ( '/core/ajax/contacts.php' , 1 ), 'htmlname' => 'contactid' , 'params' => array ( 'add-customer-contact' => 'disabled' )))
2014-03-31 02:41:15 +02:00
* @ param int $limit Maximum number of elements
2013-06-05 22:01:35 +02:00
* @ return string HTML string with
2013-06-06 18:31:33 +02:00
* @ deprecated Use select_thirdparty instead
*/
2014-03-26 20:46:17 +01:00
function select_company ( $selected = '' , $htmlname = 'socid' , $filter = '' , $showempty = 0 , $showtype = 0 , $forcecombo = 0 , $events = array (), $limit = 0 )
2013-06-05 22:01:35 +02:00
{
2014-03-26 20:46:17 +01:00
return $this -> select_thirdparty_list ( $selected , $htmlname , $filter , $showempty , $showtype , $forcecombo , $events , '' , 0 , $limit );
2013-06-05 22:01:35 +02:00
}
2010-08-22 17:46:34 +02:00
/**
2012-02-21 10:47:08 +01:00
* Output html form to select a third party
2011-10-01 21:55:40 +02:00
*
2012-02-21 10:47:08 +01:00
* @ param string $selected Preselected type
* @ param string $htmlname Name of field in form
2014-03-05 09:57:36 +01:00
* @ param string $filter optional filters criteras ( example : 's.rowid <> x' )
2012-02-21 10:47:08 +01:00
* @ param int $showempty Add an empty field
* @ param int $showtype Show third party type in combolist ( customer , prospect or supplier )
* @ param int $forcecombo Force to use combo box
2014-02-04 20:49:07 +01:00
* @ param array $events Event options . Example : array ( array ( 'method' => 'getContacts' , 'url' => dol_buildpath ( '/core/ajax/contacts.php' , 1 ), 'htmlname' => 'contactid' , 'params' => array ( 'add-customer-contact' => 'disabled' )))
2013-06-05 22:01:35 +02:00
* @ param string $filterkey Filter on key value
* @ param int $outputmode 0 = HTML select string , 1 = Array
* @ param int $limit Limit number of answers
2012-02-21 10:47:08 +01:00
* @ return string HTML string with
2010-11-03 12:39:40 +01:00
*/
2014-03-26 20:46:17 +01:00
function select_thirdparty_list ( $selected = '' , $htmlname = 'socid' , $filter = '' , $showempty = 0 , $showtype = 0 , $forcecombo = 0 , $events = array (), $filterkey = '' , $outputmode = 0 , $limit = 0 )
2010-08-22 17:46:34 +02:00
{
global $conf , $user , $langs ;
2010-11-18 23:17:44 +01:00
2014-04-16 00:06:16 +02:00
$out = '' ; $num = 0 ;
2013-06-05 22:01:35 +02:00
$outarray = array ();
2010-08-22 17:46:34 +02:00
// On recherche les societes
$sql = " SELECT s.rowid, s.nom, s.client, s.fournisseur, s.code_client, s.code_fournisseur " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " societe as s " ;
if ( ! $user -> rights -> societe -> client -> voir && ! $user -> societe_id ) $sql .= " , " . MAIN_DB_PREFIX . " societe_commerciaux as sc " ;
2012-02-01 11:32:55 +01:00
$sql .= " WHERE s.entity IN ( " . getEntity ( 'societe' , 1 ) . " ) " ;
2012-07-26 18:24:54 +02:00
if ( ! empty ( $user -> societe_id )) $sql .= " AND s.rowid = " . $user -> societe_id ;
2013-03-23 12:33:25 +01:00
if ( $filter ) $sql .= " AND ( " . $filter . " ) " ;
2010-08-22 17:46:34 +02:00
if ( ! $user -> rights -> societe -> client -> voir && ! $user -> societe_id ) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " . $user -> id ;
2013-05-11 17:10:11 +02:00
if ( ! empty ( $conf -> global -> COMPANY_HIDE_INACTIVE_IN_COMBOBOX )) $sql .= " AND s.status<>0 " ;
2013-06-06 18:31:33 +02:00
// Add criteria
if ( $filterkey && $filterkey != '' )
2013-06-05 22:01:35 +02:00
{
$sql .= " AND ( " ;
2013-06-06 18:31:33 +02:00
if ( ! empty ( $conf -> global -> COMPANY_DONOTSEARCH_ANYWHERE )) // Can use index
{
2014-03-26 20:46:17 +01:00
$sql .= " (s.name LIKE ' " . $this -> db -> escape ( $filterkey ) . " %') " ;
2013-06-05 22:01:35 +02:00
}
2013-06-06 18:31:33 +02:00
else
{
// For natural search
$scrit = explode ( ' ' , $filterkey );
foreach ( $scrit as $crit ) {
2014-03-26 20:46:17 +01:00
$sql .= " AND (s.name LIKE '% " . $this -> db -> escape ( $crit ) . " %') " ;
2013-06-06 18:31:33 +02:00
}
}
if ( ! empty ( $conf -> barcode -> enabled ))
{
2014-03-26 20:46:17 +01:00
$sql .= " OR s.barcode LIKE ' " . $this -> db -> escape ( $filterkey ) . " %' " ;
2013-06-06 18:31:33 +02:00
}
$sql .= " ) " ;
2013-06-05 22:01:35 +02:00
}
2014-03-26 20:46:17 +01:00
$sql .= $this -> db -> order ( " nom " , " ASC " );
if ( $limit > 0 ) $sql .= $this -> db -> plimit ( $limit );
2014-04-02 14:53:42 +02:00
2014-06-12 11:31:53 +02:00
dol_syslog ( get_class ( $this ) . " ::select_thirdparty_list " , LOG_DEBUG );
2010-08-22 17:46:34 +02:00
$resql = $this -> db -> query ( $sql );
if ( $resql )
{
2014-07-29 19:45:48 +02:00
if ( ! empty ( $conf -> use_javascript_ajax ) && ! empty ( $conf -> global -> COMPANY_USE_SEARCH_TO_SELECT ) && ! $forcecombo )
2010-08-22 17:46:34 +02:00
{
2014-03-26 16:02:22 +01:00
include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php' ;
$out .= ajax_combobox ( $htmlname , $events , $conf -> global -> COMPANY_USE_SEARCH_TO_SELECT );
2010-08-22 17:46:34 +02:00
}
2011-05-01 20:22:58 +02:00
2013-06-05 22:01:35 +02:00
// Construct $out and $outarray
2013-06-07 13:41:32 +02:00
$out .= '<select id="' . $htmlname . '" class="flat" name="' . $htmlname . '">' . " \n " ;
if ( $showempty ) $out .= '<option value="-1"></option>' . " \n " ;
2011-04-25 16:24:43 +02:00
$num = $this -> db -> num_rows ( $resql );
$i = 0 ;
if ( $num )
{
while ( $i < $num )
2010-08-22 17:46:34 +02:00
{
2011-04-25 16:24:43 +02:00
$obj = $this -> db -> fetch_object ( $resql );
2013-10-23 11:25:42 +02:00
$label = '' ;
2013-08-30 18:18:58 +02:00
if ( $conf -> global -> SOCIETE_ADD_REF_IN_LIST ) {
if (( $obj -> client ) && ( ! empty ( $obj -> code_client ))) {
$label = $obj -> code_client . ' - ' ;
}
if (( $obj -> fournisseur ) && ( ! empty ( $obj -> code_fournisseur ))) {
$label .= $obj -> code_fournisseur . ' - ' ;
}
$label .= ' ' . $obj -> nom ;
}
else
{
$label = $obj -> nom ;
}
2013-10-12 11:58:38 +02:00
2011-04-25 16:24:43 +02:00
if ( $showtype )
{
if ( $obj -> client || $obj -> fournisseur ) $label .= ' (' ;
if ( $obj -> client == 1 || $obj -> client == 3 ) $label .= $langs -> trans ( " Customer " );
if ( $obj -> client == 2 || $obj -> client == 3 ) $label .= ( $obj -> client == 3 ? ', ' : '' ) . $langs -> trans ( " Prospect " );
if ( $obj -> fournisseur ) $label .= ( $obj -> client ? ', ' : '' ) . $langs -> trans ( " Supplier " );
if ( $obj -> client || $obj -> fournisseur ) $label .= ')' ;
}
if ( $selected > 0 && $selected == $obj -> rowid )
{
$out .= '<option value="' . $obj -> rowid . '" selected="selected">' . $label . '</option>' ;
}
else
2013-06-05 22:01:35 +02:00
{
2011-04-25 16:24:43 +02:00
$out .= '<option value="' . $obj -> rowid . '">' . $label . '</option>' ;
2010-08-22 17:46:34 +02:00
}
2013-06-05 22:01:35 +02:00
array_push ( $outarray , array ( 'key' => $obj -> rowid , 'value' => $obj -> name , 'label' => $obj -> name ));
2011-04-25 16:24:43 +02:00
$i ++ ;
2013-06-07 13:41:32 +02:00
if (( $i % 10 ) == 0 ) $out .= " \n " ;
2010-08-22 17:46:34 +02:00
}
2011-04-25 16:24:43 +02:00
}
2013-06-07 13:41:32 +02:00
$out .= '</select>' . " \n " ;
2010-08-22 17:46:34 +02:00
}
else
{
dol_print_error ( $this -> db );
}
2010-11-18 23:17:44 +01:00
2014-04-16 00:06:16 +02:00
$this -> result = array ( 'nbofthirdparties' => $num );
2013-06-05 22:01:35 +02:00
if ( $outputmode ) return $outarray ;
2010-11-03 12:39:40 +01:00
return $out ;
2010-08-22 17:46:34 +02:00
}
/**
2011-05-10 00:19:14 +02:00
* Return HTML combo list of absolute discounts
2011-10-01 21:55:40 +02:00
*
2012-03-12 15:09:46 +01:00
* @ param string $selected Id remise fixe pre - selectionnee
* @ param string $htmlname Nom champ formulaire
* @ param string $filter Criteres optionnels de filtre
* @ param int $socid Id of thirdparty
* @ param int $maxvalue Max value for lines that can be selected
* @ return int Return number of qualifed lines in list
2010-08-22 17:46:34 +02:00
*/
2012-03-12 15:09:46 +01:00
function select_remises ( $selected , $htmlname , $filter , $socid , $maxvalue = 0 )
2010-08-22 17:46:34 +02:00
{
global $langs , $conf ;
// On recherche les remises
$sql = " SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc, " ;
$sql .= " re.description, re.fk_facture_source " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " societe_remise_except as re " ;
$sql .= " WHERE fk_soc = " . $socid ;
if ( $filter ) $sql .= " AND " . $filter ;
$sql .= " ORDER BY re.description ASC " ;
2014-06-12 11:31:53 +02:00
dol_syslog ( get_class ( $this ) . " ::select_remises " , LOG_DEBUG );
2010-08-22 17:46:34 +02:00
$resql = $this -> db -> query ( $sql );
if ( $resql )
{
print '<select class="flat" name="' . $htmlname . '">' ;
$num = $this -> db -> num_rows ( $resql );
$qualifiedlines = $num ;
$i = 0 ;
if ( $num )
{
print '<option value="0"> </option>' ;
while ( $i < $num )
{
$obj = $this -> db -> fetch_object ( $resql );
$desc = dol_trunc ( $obj -> description , 40 );
if ( $desc == '(CREDIT_NOTE)' ) $desc = $langs -> trans ( " CreditNote " );
if ( $desc == '(DEPOSIT)' ) $desc = $langs -> trans ( " Deposit " );
$selectstring = '' ;
2010-11-01 17:00:38 +01:00
if ( $selected > 0 && $selected == $obj -> rowid ) $selectstring = ' selected="selected"' ;
2010-08-22 17:46:34 +02:00
$disabled = '' ;
2011-11-17 20:56:47 +01:00
if ( $maxvalue > 0 && $obj -> amount_ttc > $maxvalue )
2010-08-22 17:46:34 +02:00
{
$qualifiedlines -- ;
2011-08-31 17:12:09 +02:00
$disabled = ' disabled="disabled"' ;
2010-08-22 17:46:34 +02:00
}
print '<option value="' . $obj -> rowid . '"' . $selectstring . $disabled . '>' . $desc . ' (' . price ( $obj -> amount_ht ) . ' ' . $langs -> trans ( " HT " ) . ' - ' . price ( $obj -> amount_ttc ) . ' ' . $langs -> trans ( " TTC " ) . ')</option>' ;
$i ++ ;
}
}
print '</select>' ;
return $qualifiedlines ;
}
else
{
dol_print_error ( $this -> db );
return - 1 ;
}
}
2012-07-02 19:30:37 +02:00
/**
* Return list of all contacts ( for a third party or all )
*
* @ param int $socid Id ot third party or 0 for all
* @ param string $selected Id contact pre - selectionne
* @ param string $htmlname Name of HTML field ( 'none' for a not editable field )
* @ param int $showempty 0 = no empty value , 1 = add an empty value
* @ param string $exclude List of contacts id to exclude
* @ param string $limitto Disable answers that are not id in this array list
* @ param string $showfunction Add function into label
* @ param string $moreclass Add more class to class style
2012-08-02 10:12:32 +02:00
* @ param string $showsoc Add company into label
2013-02-12 09:49:27 +01:00
* @ param int $forcecombo Force to use combo box
2014-02-04 20:49:07 +01:00
* @ param array $events Event options . Example : array ( array ( 'method' => 'getContacts' , 'url' => dol_buildpath ( '/core/ajax/contacts.php' , 1 ), 'htmlname' => 'contactid' , 'params' => array ( 'add-customer-contact' => 'disabled' )))
2013-02-22 15:34:20 +01:00
* @ param bool $options_only Return options only ( for ajax treatment )
2012-07-02 19:30:37 +02:00
* @ return int < 0 if KO , Nb of contact in list if OK
*/
2014-02-04 20:49:07 +01:00
function select_contacts ( $socid , $selected = '' , $htmlname = 'contactid' , $showempty = 0 , $exclude = '' , $limitto = '' , $showfunction = 0 , $moreclass = '' , $showsoc = 0 , $forcecombo = 0 , $events = array (), $options_only = false )
2012-03-18 14:06:55 +01:00
{
2014-02-04 20:49:07 +01:00
print $this -> selectcontacts ( $socid , $selected , $htmlname , $showempty , $exclude , $limitto , $showfunction , $moreclass , $options_only , $showsoc , $forcecombo , $events );
2012-03-18 14:25:39 +01:00
return $this -> num ;
2012-03-18 14:06:55 +01:00
}
2010-08-22 17:46:34 +02:00
/**
2012-03-18 14:06:55 +01:00
* Return list of all contacts ( for a third party or all )
2011-10-01 21:55:40 +02:00
*
2012-03-18 14:06:55 +01:00
* @ param int $socid Id ot third party or 0 for all
* @ param string $selected Id contact pre - selectionne
* @ param string $htmlname Name of HTML field ( 'none' for a not editable field )
2013-01-02 14:35:16 +01:00
* @ param int $showempty 0 = no empty value , 1 = add an empty value , 2 = add line 'Internal' ( used by user edit )
2012-03-18 14:06:55 +01:00
* @ param string $exclude List of contacts id to exclude
* @ param string $limitto Disable answers that are not id in this array list
* @ param string $showfunction Add function into label
* @ param string $moreclass Add more class to class style
* @ param bool $options_only Return options only ( for ajax treatment )
2012-08-02 10:12:32 +02:00
* @ param string $showsoc Add company into label
2013-02-12 09:49:27 +01:00
* @ param int $forcecombo Force to use combo box
2014-02-04 20:49:07 +01:00
* @ param array $events Event options . Example : array ( array ( 'method' => 'getContacts' , 'url' => dol_buildpath ( '/core/ajax/contacts.php' , 1 ), 'htmlname' => 'contactid' , 'params' => array ( 'add-customer-contact' => 'disabled' )))
* @ return int < 0 if KO , Nb of contact in list if OK
2010-08-22 17:46:34 +02:00
*/
2014-02-04 20:49:07 +01:00
function selectcontacts ( $socid , $selected = '' , $htmlname = 'contactid' , $showempty = 0 , $exclude = '' , $limitto = '' , $showfunction = 0 , $moreclass = '' , $options_only = false , $showsoc = 0 , $forcecombo = 0 , $events = array ())
2010-08-22 17:46:34 +02:00
{
2011-02-13 13:17:43 +01:00
global $conf , $langs ;
2012-03-19 17:18:11 +01:00
2012-03-18 14:06:55 +01:00
$langs -> load ( 'companies' );
2012-03-19 17:18:11 +01:00
2012-03-18 14:06:55 +01:00
$out = '' ;
2011-02-09 20:22:40 +01:00
2010-08-22 17:46:34 +02:00
// On recherche les societes
2013-07-18 09:41:37 +02:00
$sql = " SELECT sp.rowid, sp.lastname, sp.statut, sp.firstname, sp.poste " ;
2012-08-02 10:12:32 +02:00
if ( $showsoc > 0 ) {
$sql .= " , s.nom as company " ;
}
2012-02-11 08:03:26 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " socpeople as sp " ;
2012-08-02 10:12:32 +02:00
if ( $showsoc > 0 ) {
$sql .= " LEFT OUTER JOIN " . MAIN_DB_PREFIX . " societe as s ON s.rowid=sp.fk_soc " ;
}
2012-02-11 08:03:26 +01:00
$sql .= " WHERE sp.entity IN ( " . getEntity ( 'societe' , 1 ) . " ) " ;
if ( $socid > 0 ) $sql .= " AND sp.fk_soc= " . $socid ;
2013-10-30 12:24:51 +01:00
if ( ! empty ( $conf -> global -> CONTACT_HIDE_INACTIVE_IN_COMBOBOX )) $sql .= " AND sp.statut<>0 " ;
2013-02-23 17:01:10 +01:00
$sql .= " ORDER BY sp.lastname ASC " ;
2010-08-22 17:46:34 +02:00
2014-06-12 11:31:53 +02:00
dol_syslog ( get_class ( $this ) . " ::select_contacts " , LOG_DEBUG );
2010-08-22 17:46:34 +02:00
$resql = $this -> db -> query ( $sql );
if ( $resql )
{
$num = $this -> db -> num_rows ( $resql );
2013-02-16 21:06:15 +01:00
2013-02-22 15:34:20 +01:00
if ( $conf -> use_javascript_ajax && $conf -> global -> CONTACT_USE_SEARCH_TO_SELECT && ! $forcecombo && ! $options_only )
2013-02-12 09:49:27 +01:00
{
2014-07-29 19:45:48 +02:00
include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php' ;
2014-02-04 20:49:07 +01:00
$out .= ajax_combobox ( $htmlname , $events , $conf -> global -> CONTACT_USE_SEARCH_TO_SELECT );
2013-02-12 09:49:27 +01:00
}
2010-08-22 17:46:34 +02:00
2012-03-18 14:06:55 +01:00
if ( $htmlname != 'none' || $options_only ) $out .= '<select class="flat' . ( $moreclass ? ' ' . $moreclass : '' ) . '" id="' . $htmlname . '" name="' . $htmlname . '">' ;
2013-01-02 14:35:16 +01:00
if ( $showempty == 1 ) $out .= '<option value="0"' . ( $selected == '0' ? ' selected="selected"' : '' ) . '></option>' ;
if ( $showempty == 2 ) $out .= '<option value="0"' . ( $selected == '0' ? ' selected="selected"' : '' ) . '>' . $langs -> trans ( " Internal " ) . '</option>' ;
2010-08-22 17:46:34 +02:00
$num = $this -> db -> num_rows ( $resql );
$i = 0 ;
if ( $num )
{
2012-08-23 02:04:35 +02:00
include_once DOL_DOCUMENT_ROOT . '/contact/class/contact.class.php' ;
2011-02-09 19:20:00 +01:00
$contactstatic = new Contact ( $this -> db );
2010-08-22 17:46:34 +02:00
while ( $i < $num )
{
$obj = $this -> db -> fetch_object ( $resql );
2011-02-09 19:20:00 +01:00
$contactstatic -> id = $obj -> rowid ;
2013-03-09 20:34:38 +01:00
$contactstatic -> lastname = $obj -> lastname ;
2011-02-09 19:20:00 +01:00
$contactstatic -> firstname = $obj -> firstname ;
2013-08-22 10:06:57 +02:00
if ( $obj -> statut == 1 ){
2010-08-22 17:46:34 +02:00
if ( $htmlname != 'none' )
{
$disabled = 0 ;
2011-09-17 21:49:50 +02:00
if ( is_array ( $exclude ) && count ( $exclude ) && in_array ( $obj -> rowid , $exclude )) $disabled = 1 ;
if ( is_array ( $limitto ) && count ( $limitto ) && ! in_array ( $obj -> rowid , $limitto )) $disabled = 1 ;
2010-08-22 17:46:34 +02:00
if ( $selected && $selected == $obj -> rowid )
{
2012-03-18 14:06:55 +01:00
$out .= '<option value="' . $obj -> rowid . '"' ;
if ( $disabled ) $out .= ' disabled="disabled"' ;
$out .= ' selected="selected">' ;
$out .= $contactstatic -> getFullName ( $langs );
if ( $showfunction && $obj -> poste ) $out .= ' (' . $obj -> poste . ')' ;
2012-08-02 10:12:32 +02:00
if (( $showsoc > 0 ) && $obj -> company ) $out .= ' - (' . $obj -> company . ')' ;
2012-03-18 14:06:55 +01:00
$out .= '</option>' ;
2010-08-22 17:46:34 +02:00
}
else
{
2012-03-18 14:06:55 +01:00
$out .= '<option value="' . $obj -> rowid . '"' ;
if ( $disabled ) $out .= ' disabled="disabled"' ;
$out .= '>' ;
$out .= $contactstatic -> getFullName ( $langs );
if ( $showfunction && $obj -> poste ) $out .= ' (' . $obj -> poste . ')' ;
2012-08-02 10:12:32 +02:00
if (( $showsoc > 0 ) && $obj -> company ) $out .= ' - (' . $obj -> company . ')' ;
2012-03-18 14:06:55 +01:00
$out .= '</option>' ;
2010-08-22 17:46:34 +02:00
}
}
else
2013-01-02 14:35:16 +01:00
{
2011-02-09 19:20:00 +01:00
if ( $selected == $obj -> rowid )
{
2012-03-18 14:06:55 +01:00
$out .= $contactstatic -> getFullName ( $langs );
if ( $showfunction && $obj -> poste ) $out .= ' (' . $obj -> poste . ')' ;
2012-08-02 10:12:32 +02:00
if (( $showsoc > 0 ) && $obj -> company ) $out .= ' - (' . $obj -> company . ')' ;
2011-02-09 19:20:00 +01:00
}
2010-08-22 17:46:34 +02:00
}
2013-07-18 09:41:37 +02:00
}
2010-08-22 17:46:34 +02:00
$i ++ ;
}
}
2012-03-18 12:18:23 +01:00
else
2013-01-02 14:35:16 +01:00
{
$out .= '<option value="-1"' . ( $showempty == 2 ? '' : ' selected="selected"' ) . ' disabled="disabled">' . $langs -> trans ( $socid ? " NoContactDefinedForThirdParty " : " NoContactDefined " ) . '</option>' ;
2012-03-18 12:18:23 +01:00
}
2012-03-18 14:06:55 +01:00
if ( $htmlname != 'none' || $options_only )
2010-08-22 17:46:34 +02:00
{
2012-03-18 14:06:55 +01:00
$out .= '</select>' ;
2010-08-22 17:46:34 +02:00
}
2012-03-19 17:18:11 +01:00
2012-03-18 14:06:55 +01:00
$this -> num = $num ;
return $out ;
2010-08-22 17:46:34 +02:00
}
else
{
dol_print_error ( $this -> db );
return - 1 ;
}
}
2010-09-02 21:31:18 +02:00
2010-08-22 17:46:34 +02:00
/**
2011-03-19 20:06:15 +01:00
* Return select list of users
2011-08-20 15:18:54 +02:00
*
2012-03-12 15:09:46 +01:00
* @ param string $selected Id user preselected
* @ param string $htmlname Field name in form
* @ param int $show_empty 0 = liste sans valeur nulle , 1 = ajoute valeur inconnue
* @ param array $exclude Array list of users id to exclude
* @ param int $disabled If select list must be disabled
* @ param array $include Array list of users id to include
* @ param int $enableonly Array list of users id to be enabled . All other must be disabled
2013-02-16 21:06:15 +01:00
* @ param int $force_entity 0 or Id of environment to force
2012-03-12 15:09:46 +01:00
* @ return void
2013-07-27 14:21:47 +02:00
* @ deprecated
2010-08-22 17:46:34 +02:00
*/
2013-02-16 21:06:15 +01:00
function select_users ( $selected = '' , $htmlname = 'userid' , $show_empty = 0 , $exclude = '' , $disabled = 0 , $include = '' , $enableonly = '' , $force_entity = 0 )
2010-09-01 22:51:10 +02:00
{
2012-02-21 10:47:08 +01:00
print $this -> select_dolusers ( $selected , $htmlname , $show_empty , $exclude , $disabled , $include , $enableonly , $force_entity );
2010-09-01 22:51:10 +02:00
}
/**
2011-03-19 20:06:15 +01:00
* Return select list of users
2011-08-20 15:18:54 +02:00
*
2012-03-12 15:09:46 +01:00
* @ param string $selected User id or user object of user preselected . If - 1 , we use id of current user .
* @ param string $htmlname Field name in form
* @ param int $show_empty 0 = liste sans valeur nulle , 1 = ajoute valeur inconnue
* @ param array $exclude Array list of users id to exclude
* @ param int $disabled If select list must be disabled
2014-08-11 10:54:32 +02:00
* @ param array $include Array list of users id to include or 'hierarchy' to have only supervised users
2013-06-23 18:33:03 +02:00
* @ param array $enableonly Array list of users id to be enabled . All other must be disabled
2013-02-16 21:06:15 +01:00
* @ param int $force_entity 0 or Id of environment to force
2013-06-23 18:33:03 +02:00
* @ param int $maxlength Maximum length of string into list ( 0 = no limit )
2013-07-27 14:45:55 +02:00
* @ param int $showstatus 0 = show user status only if status is disabled , 1 = always show user status into label , - 1 = never show user status
2014-08-11 10:54:32 +02:00
* @ param string $morefilter Add more filters into sql request
2012-03-12 15:09:46 +01:00
* @ return string HTML select string
2014-06-28 19:47:51 +02:00
* @ see select_dolgroups
2010-09-01 22:51:10 +02:00
*/
2014-08-11 11:38:17 +02:00
function select_dolusers ( $selected = '' , $htmlname = 'userid' , $show_empty = 0 , $exclude = '' , $disabled = 0 , $include = '' , $enableonly = '' , $force_entity = 0 , $maxlength = 0 , $showstatus = 0 , $morefilter = '' )
2010-08-22 17:46:34 +02:00
{
2011-02-13 17:01:00 +01:00
global $conf , $user , $langs ;
2011-02-06 23:23:03 +01:00
// If no preselected user defined, we take current user
2013-02-15 18:39:27 +01:00
if (( is_numeric ( $selected ) && ( $selected < - 1 || empty ( $selected ))) && empty ( $conf -> global -> SOCIETE_DISABLE_DEFAULT_SALESREPRESENTATIVE )) $selected = $user -> id ;
2010-08-22 17:46:34 +02:00
// Permettre l'exclusion d'utilisateurs
if ( is_array ( $exclude )) $excludeUsers = implode ( " ',' " , $exclude );
// Permettre l'inclusion d'utilisateurs
if ( is_array ( $include )) $includeUsers = implode ( " ',' " , $include );
2014-08-14 01:04:15 +02:00
else if ( $include == 'hierarchy' )
2014-08-11 10:54:32 +02:00
{
// Build list includeUsers to have only hierarchy
$userid = $user -> id ;
$include = array ();
if ( empty ( $user -> users ) || ! is_array ( $user -> users )) $user -> get_full_tree ();
foreach ( $user -> users as $key => $val )
{
if ( preg_match ( '/_' . $userid . '/' , $val [ 'fullpath' ])) $include [] = $val [ 'id' ];
}
$includeUsers = implode ( " ',' " , $include );
//var_dump($includeUsers);exit;
//var_dump($user->users);exit;
}
2014-08-14 01:04:15 +02:00
2010-09-01 22:51:10 +02:00
$out = '' ;
2010-08-22 17:46:34 +02:00
// On recherche les utilisateurs
2013-07-22 11:17:45 +02:00
$sql = " SELECT DISTINCT u.rowid, u.lastname as lastname, u.firstname, u.statut, u.login, u.admin, u.entity " ;
2012-09-04 11:09:17 +02:00
if ( ! empty ( $conf -> multicompany -> enabled ) && $conf -> entity == 1 && $user -> admin && ! $user -> entity )
2011-08-20 00:15:22 +02:00
{
2012-02-21 10:47:08 +01:00
$sql .= " , e.label " ;
2011-08-20 00:15:22 +02:00
}
2010-08-22 17:46:34 +02:00
$sql .= " FROM " . MAIN_DB_PREFIX . " user as u " ;
2012-07-06 20:25:00 +02:00
if ( ! empty ( $conf -> multicompany -> enabled ) && $conf -> entity == 1 && $user -> admin && ! $user -> entity )
2011-08-19 09:22:17 +02:00
{
2012-07-06 20:25:00 +02:00
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " entity as e ON e.rowid=u.entity " ;
2011-08-20 11:03:38 +02:00
if ( $force_entity ) $sql .= " WHERE u.entity IN (0, " . $force_entity . " ) " ;
else $sql .= " WHERE u.entity IS NOT NULL " ;
2011-08-19 09:22:17 +02:00
}
else
2011-08-20 00:15:22 +02:00
{
2012-09-04 11:09:17 +02:00
if ( ! empty ( $conf -> multicompany -> transverse_mode ))
{
2012-09-07 17:23:16 +02:00
$sql .= " , " . MAIN_DB_PREFIX . " usergroup_user as ug " ;
2012-09-04 11:09:17 +02:00
$sql .= " WHERE ug.fk_user = u.rowid " ;
$sql .= " AND ug.entity = " . $conf -> entity ;
}
else
{
$sql .= " WHERE u.entity IN (0, " . $conf -> entity . " ) " ;
}
2011-08-20 00:15:22 +02:00
}
2012-07-26 18:24:54 +02:00
if ( ! empty ( $user -> societe_id )) $sql .= " AND u.fk_societe = " . $user -> societe_id ;
2010-08-22 17:46:34 +02:00
if ( is_array ( $exclude ) && $excludeUsers ) $sql .= " AND u.rowid NOT IN (' " . $excludeUsers . " ') " ;
if ( is_array ( $include ) && $includeUsers ) $sql .= " AND u.rowid IN (' " . $includeUsers . " ') " ;
2014-08-11 10:54:32 +02:00
if ( ! empty ( $conf -> global -> USER_HIDE_INACTIVE_IN_COMBOBOX )) $sql .= " AND u.statut <> 0 " ;
if ( ! empty ( $morefilter )) $sql .= $morefilter ;
2013-02-23 12:30:01 +01:00
$sql .= " ORDER BY u.lastname ASC " ;
2010-08-22 17:46:34 +02:00
2014-06-12 11:31:53 +02:00
dol_syslog ( get_class ( $this ) . " ::select_dolusers " , LOG_DEBUG );
2010-08-22 17:46:34 +02:00
$resql = $this -> db -> query ( $sql );
if ( $resql )
{
$num = $this -> db -> num_rows ( $resql );
$i = 0 ;
if ( $num )
{
2012-02-21 10:47:08 +01:00
$out .= '<select class="flat" id="' . $htmlname . '" name="' . $htmlname . '"' . ( $disabled ? ' disabled="disabled"' : '' ) . '>' ;
2013-02-15 18:39:27 +01:00
if ( $show_empty ) $out .= '<option value="-1"' . (( empty ( $selected ) || $selected ==- 1 ) ? ' selected="selected"' : '' ) . '> </option>' . " \n " ;
2011-08-31 16:55:54 +02:00
2012-02-21 10:47:08 +01:00
$userstatic = new User ( $this -> db );
2011-02-09 19:20:00 +01:00
2010-08-22 17:46:34 +02:00
while ( $i < $num )
{
$obj = $this -> db -> fetch_object ( $resql );
2011-02-09 19:20:00 +01:00
$userstatic -> id = $obj -> rowid ;
2012-01-09 00:53:31 +01:00
$userstatic -> lastname = $obj -> lastname ;
$userstatic -> firstname = $obj -> firstname ;
2011-02-09 19:20:00 +01:00
2010-08-22 17:46:34 +02:00
$disableline = 0 ;
2011-09-17 21:49:50 +02:00
if ( is_array ( $enableonly ) && count ( $enableonly ) && ! in_array ( $obj -> rowid , $enableonly )) $disableline = 1 ;
2010-08-22 17:46:34 +02:00
if (( is_object ( $selected ) && $selected -> id == $obj -> rowid ) || ( ! is_object ( $selected ) && $selected == $obj -> rowid ))
{
2010-09-01 22:51:10 +02:00
$out .= '<option value="' . $obj -> rowid . '"' ;
2011-08-31 17:12:09 +02:00
if ( $disableline ) $out .= ' disabled="disabled"' ;
2010-11-01 17:00:38 +01:00
$out .= ' selected="selected">' ;
2010-08-22 17:46:34 +02:00
}
else
{
2010-09-01 22:51:10 +02:00
$out .= '<option value="' . $obj -> rowid . '"' ;
2011-08-31 17:12:09 +02:00
if ( $disableline ) $out .= ' disabled="disabled"' ;
2010-09-01 22:51:10 +02:00
$out .= '>' ;
2010-08-22 17:46:34 +02:00
}
2013-06-23 18:33:03 +02:00
$out .= $userstatic -> getFullName ( $langs , 0 , 0 , $maxlength );
2013-07-27 14:45:55 +02:00
// Complete name with more info
$moreinfo = 0 ;
if ( ! empty ( $conf -> global -> MAIN_SHOW_LOGIN ))
2013-07-22 11:17:45 +02:00
{
2013-07-27 14:45:55 +02:00
$out .= ( $moreinfo ? ' - ' : ' (' ) . $obj -> login ;
$moreinfo ++ ;
}
if ( $showstatus >= 0 )
{
if ( $obj -> statut == 1 && $showstatus == 1 )
{
$out .= ( $moreinfo ? ' - ' : ' (' ) . $langs -> trans ( 'Enabled' );
$moreinfo ++ ;
}
if ( $obj -> statut == 0 )
{
$out .= ( $moreinfo ? ' - ' : ' (' ) . $langs -> trans ( 'Disabled' );
$moreinfo ++ ;
}
2013-07-22 11:17:45 +02:00
}
2012-07-06 20:25:00 +02:00
if ( ! empty ( $conf -> multicompany -> enabled ) && empty ( $conf -> multicompany -> transverse_mode ) && $conf -> entity == 1 && $user -> admin && ! $user -> entity )
2011-08-20 00:15:22 +02:00
{
2013-07-27 14:45:55 +02:00
if ( $obj -> admin && ! $obj -> entity )
{
$out .= ( $moreinfo ? ' - ' : ' (' ) . $langs -> trans ( " AllEntities " );
$moreinfo ++ ;
}
else
{
$out .= ( $moreinfo ? ' - ' : ' (' ) . $obj -> label ;
$moreinfo ++ ;
}
2011-08-20 00:15:22 +02:00
}
2013-07-27 14:45:55 +02:00
$out .= ( $moreinfo ? ')' : '' );
2010-09-01 22:51:10 +02:00
$out .= '</option>' ;
2013-07-27 14:21:47 +02:00
2010-08-22 17:46:34 +02:00
$i ++ ;
}
2011-08-21 02:20:43 +02:00
}
2012-02-21 10:47:08 +01:00
else
2011-08-21 02:20:43 +02:00
{
2012-02-21 10:47:08 +01:00
$out .= '<select class="flat" name="' . $htmlname . '" disabled="disabled">' ;
$out .= '<option value="">' . $langs -> trans ( " None " ) . '</option>' ;
2010-08-22 17:46:34 +02:00
}
2010-09-01 22:51:10 +02:00
$out .= '</select>' ;
2010-08-22 17:46:34 +02:00
}
else
{
dol_print_error ( $this -> db );
}
2010-09-02 21:31:18 +02:00
2010-09-01 22:51:10 +02:00
return $out ;
2010-08-22 17:46:34 +02:00
}
/**
2013-06-05 22:01:35 +02:00
* Return list of products for customer in Ajax if Ajax activated or go to select_produits_list
2011-10-01 21:55:40 +02:00
*
2011-10-03 22:48:10 +02:00
* @ param int $selected Preselected products
2014-05-28 06:17:09 +02:00
* @ param string $htmlname Name of HTML select field ( must be unique in page )
2011-10-03 22:48:10 +02:00
* @ param int $filtertype Filter on product type ( '' = nofilter , 0 = product , 1 = service )
* @ param int $limit Limit on number of returned lines
* @ param int $price_level Level of price to show
* @ param int $status - 1 = Return all products , 0 = Products not on sell , 1 = Products on sell
* @ param int $finished 2 = all , 1 = finished , 0 = raw material
* @ param string $selected_input_value Value of preselected input text ( with ajax )
2012-08-22 17:42:40 +02:00
* @ param int $hidelabel Hide label ( 0 = no , 1 = yes , 2 = show search icon ( before ) and placeholder , 3 search icon after )
2012-08-18 19:05:59 +02:00
* @ param array $ajaxoptions Options for ajax_autocompleter
2014-05-28 06:17:09 +02:00
* @ param int $socid Thirdparty Id
2011-10-03 22:48:10 +02:00
* @ return void
2010-08-22 17:46:34 +02:00
*/
2014-02-23 16:16:47 +01:00
function select_produits ( $selected = '' , $htmlname = 'productid' , $filtertype = '' , $limit = 20 , $price_level = 0 , $status = 1 , $finished = 2 , $selected_input_value = '' , $hidelabel = 0 , $ajaxoptions = array (), $socid = 0 )
2010-08-22 17:46:34 +02:00
{
global $langs , $conf ;
2011-08-31 17:12:09 +02:00
2011-08-30 19:51:12 +02:00
$price_level = ( ! empty ( $price_level ) ? $price_level : 0 );
2010-08-22 17:46:34 +02:00
2012-08-18 19:05:59 +02:00
if ( ! empty ( $conf -> use_javascript_ajax ) && ! empty ( $conf -> global -> PRODUIT_USE_SEARCH_TO_SELECT ))
2010-08-22 17:46:34 +02:00
{
2012-08-22 17:42:40 +02:00
$placeholder = '' ;
2012-02-21 10:47:08 +01:00
if ( $selected && empty ( $selected_input_value ))
{
2012-08-22 23:11:24 +02:00
require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php' ;
2012-02-21 10:47:08 +01:00
$product = new Product ( $this -> db );
$product -> fetch ( $selected );
$selected_input_value = $product -> ref ;
}
2010-10-11 12:28:08 +02:00
// mode=1 means customers products
2012-08-18 19:05:59 +02:00
$urloption = 'htmlname=' . $htmlname . '&outjson=1&price_level=' . $price_level . '&type=' . $filtertype . '&mode=1&status=' . $status . '&finished=' . $finished ;
2014-02-23 16:16:47 +01:00
//Price by customer
if ( ! empty ( $conf -> global -> PRODUIT_CUSTOMER_PRICES ) && ! empty ( $socid )) {
$urloption .= '&socid=' . $socid ;
}
2012-08-18 19:05:59 +02:00
print ajax_autocompleter ( $selected , $htmlname , DOL_URL_ROOT . '/product/ajax/products.php' , $urloption , $conf -> global -> PRODUIT_USE_SEARCH_TO_SELECT , 0 , $ajaxoptions );
2012-08-22 17:42:40 +02:00
if ( empty ( $hidelabel )) print $langs -> trans ( " RefOrLabel " ) . ' : ' ;
else if ( $hidelabel > 1 ) {
if ( ! empty ( $conf -> global -> MAIN_HTML5_PLACEHOLDER )) $placeholder = ' placeholder="' . $langs -> trans ( " RefOrLabel " ) . '"' ;
else $placeholder = ' title="' . $langs -> trans ( " RefOrLabel " ) . '"' ;
2012-08-25 15:21:34 +02:00
if ( $hidelabel == 2 ) {
print img_picto ( $langs -> trans ( " Search " ), 'search' );
2012-08-22 17:42:40 +02:00
}
}
print '<input type="text" size="20" name="search_' . $htmlname . '" id="search_' . $htmlname . '" value="' . $selected_input_value . '"' . $placeholder . ' />' ;
if ( $hidelabel == 3 ) {
print img_picto ( $langs -> trans ( " Search " ), 'search' );
}
2010-08-22 17:46:34 +02:00
}
else
2013-06-05 22:01:35 +02:00
{
2014-02-23 16:16:47 +01:00
print $this -> select_produits_list ( $selected , $htmlname , $filtertype , $limit , $price_level , '' , $status , $finished , 0 , $socid );
2010-08-22 17:46:34 +02:00
}
}
/**
2011-02-05 09:12:11 +01:00
* Return list of products for a customer
2011-09-15 01:15:38 +02:00
*
2011-10-03 22:48:10 +02:00
* @ param int $selected Preselected product
* @ param string $htmlname Name of select html
* @ param string $filtertype Filter on product type ( '' = nofilter , 0 = product , 1 = service )
2014-05-28 06:17:09 +02:00
* @ param int $limit Limit on number of returned lines
2011-10-03 22:48:10 +02:00
* @ param int $price_level Level of price to show
* @ param string $filterkey Filter on product
* @ param int $status - 1 = Return all products , 0 = Products not on sell , 1 = Products on sell
* @ param int $finished Filter on finished field : 2 = No filter
2013-06-05 22:01:35 +02:00
* @ param int $outputmode 0 = HTML select string , 1 = Array
2014-05-28 06:17:09 +02:00
* @ param int $socid Thirdparty Id
2011-10-03 22:48:10 +02:00
* @ return array Array of keys for json
2010-08-22 17:46:34 +02:00
*/
2014-02-23 16:16:47 +01:00
function select_produits_list ( $selected = '' , $htmlname = 'productid' , $filtertype = '' , $limit = 20 , $price_level = 0 , $filterkey = '' , $status = 1 , $finished = 2 , $outputmode = 0 , $socid = 0 )
2010-08-22 17:46:34 +02:00
{
global $langs , $conf , $user , $db ;
2013-06-06 18:31:33 +02:00
$out = '' ;
$outarray = array ();
2013-06-05 22:01:35 +02:00
2010-08-22 17:46:34 +02:00
$sql = " SELECT " ;
2012-08-29 17:40:13 +02:00
$sql .= " p.rowid, p.label, p.ref, p.description, p.fk_product_type, p.price, p.price_ttc, p.price_base_type, p.tva_tx, p.duration, p.stock " ;
2014-02-23 16:16:47 +01:00
//Price by customer
if ( ! empty ( $conf -> global -> PRODUIT_CUSTOMER_PRICES ) && ! empty ( $socid )) {
$sql .= ' ,pcp.rowid as idprodcustprice, pcp.price as custprice, pcp.price_ttc as custprice_ttc,' ;
$sql .= ' pcp.price_base_type as custprice_base_type, pcp.tva_tx as custtva_tx' ;
}
2014-04-02 14:53:42 +02:00
2010-08-22 17:46:34 +02:00
// Multilang : we add translation
2012-08-18 19:05:59 +02:00
if ( ! empty ( $conf -> global -> MAIN_MULTILANGS ))
2010-08-22 17:46:34 +02:00
{
$sql .= " , pl.label as label_translated " ;
}
2012-10-26 01:00:03 +02:00
// Price by quantity
2013-02-04 10:21:59 +01:00
if ( ! empty ( $conf -> global -> PRODUIT_CUSTOMER_PRICES_BY_QTY ))
2012-10-26 01:00:03 +02:00
{
$sql .= " , (SELECT pp.rowid FROM " . MAIN_DB_PREFIX . " product_price as pp WHERE pp.fk_product = p.rowid " ;
2014-02-23 16:16:47 +01:00
if ( $price_level >= 1 && ! empty ( $conf -> global -> PRODUIT_MULTIPRICES )) $sql .= " AND price_level= " . $price_level ;
2012-10-26 01:00:03 +02:00
$sql .= " ORDER BY date_price " ;
$sql .= " DESC LIMIT 1) as price_rowid " ;
$sql .= " , (SELECT pp.price_by_qty FROM " . MAIN_DB_PREFIX . " product_price as pp WHERE pp.fk_product = p.rowid " ;
2014-02-23 16:16:47 +01:00
if ( $price_level >= 1 && ! empty ( $conf -> global -> PRODUIT_MULTIPRICES )) $sql .= " AND price_level= " . $price_level ;
2012-10-26 01:00:03 +02:00
$sql .= " ORDER BY date_price " ;
$sql .= " DESC LIMIT 1) as price_by_qty " ;
}
2010-08-22 17:46:34 +02:00
$sql .= " FROM " . MAIN_DB_PREFIX . " product as p " ;
2014-02-23 16:16:47 +01:00
//Price by customer
if ( ! empty ( $conf -> global -> PRODUIT_CUSTOMER_PRICES ) && ! empty ( $socid )) {
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " product_customer_price as pcp ON pcp.fk_soc= " . $socid . " AND pcp.fk_product=p.rowid " ;
}
2010-08-22 17:46:34 +02:00
// Multilang : we add translation
2012-08-18 19:05:59 +02:00
if ( ! empty ( $conf -> global -> MAIN_MULTILANGS ))
2010-08-22 17:46:34 +02:00
{
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " product_lang as pl ON pl.fk_product = p.rowid AND pl.lang=' " . $langs -> getDefaultLang () . " ' " ;
}
2012-01-11 14:14:14 +01:00
$sql .= ' WHERE p.entity IN (' . getEntity ( 'product' , 1 ) . ')' ;
2011-10-03 22:48:10 +02:00
if ( $finished == 0 )
2010-08-22 17:46:34 +02:00
{
$sql .= " AND p.finished = " . $finished ;
}
2011-10-03 22:48:10 +02:00
elseif ( $finished == 1 )
2010-08-22 17:46:34 +02:00
{
$sql .= " AND p.finished = " . $finished ;
if ( $status >= 0 ) $sql .= " AND p.tosell = " . $status ;
}
2011-10-03 22:48:10 +02:00
elseif ( $status >= 0 )
2010-08-22 17:46:34 +02:00
{
$sql .= " AND p.tosell = " . $status ;
}
if ( strval ( $filtertype ) != '' ) $sql .= " AND p.fk_product_type= " . $filtertype ;
// Add criteria on ref/label
2013-06-08 22:29:18 +02:00
if ( $filterkey != '' )
2010-08-22 17:46:34 +02:00
{
2013-06-09 03:10:31 +02:00
$sql .= ' AND (' ;
$prefix = empty ( $conf -> global -> PRODUCT_DONOTSEARCH_ANYWHERE ) ? '%' : '' ; // Can use index if PRODUCT_DONOTSEARCH_ANYWHERE is on
// For natural search
$scrit = explode ( ' ' , $filterkey );
$i = 0 ;
if ( count ( $scrit ) > 1 ) $sql .= " ( " ;
foreach ( $scrit as $crit )
2012-02-21 10:47:08 +01:00
{
2013-06-09 03:10:31 +02:00
if ( $i > 0 ) $sql .= " AND " ;
$sql .= " (p.ref LIKE ' " . $prefix . $crit . " %' OR p.label LIKE ' " . $prefix . $crit . " %' " ;
if ( ! empty ( $conf -> global -> MAIN_MULTILANGS )) $sql .= " OR pl.label LIKE ' " . $prefix . $crit . " %' " ;
2012-02-21 10:47:08 +01:00
$sql .= " ) " ;
2013-06-09 03:10:31 +02:00
$i ++ ;
2012-02-21 10:47:08 +01:00
}
2013-06-09 03:10:31 +02:00
if ( count ( $scrit ) > 1 ) $sql .= " ) " ;
if ( ! empty ( $conf -> barcode -> enabled )) $sql .= " OR p.barcode LIKE ' " . $prefix . $filterkey . " %' " ;
$sql .= ')' ;
2010-08-22 17:46:34 +02:00
}
$sql .= $db -> order ( " p.ref " );
$sql .= $db -> plimit ( $limit );
// Build output string
2014-06-12 11:31:53 +02:00
dol_syslog ( get_class ( $this ) . " ::select_produits_list search product " , LOG_DEBUG );
2010-08-22 17:46:34 +02:00
$result = $this -> db -> query ( $sql );
if ( $result )
{
$num = $this -> db -> num_rows ( $result );
2013-06-05 22:01:35 +02:00
$out .= '<select class="flat" name="' . $htmlname . '" id="' . $htmlname . '">' ;
$out .= '<option value="0" selected="selected"> </option>' ;
2011-02-05 18:25:56 +01:00
2010-08-22 17:46:34 +02:00
$i = 0 ;
while ( $num && $i < $num )
{
2012-10-26 01:00:03 +02:00
$opt = '' ;
$optJson = array ();
$objp = $this -> db -> fetch_object ( $result );
2012-12-07 13:48:11 +01:00
2014-02-23 16:16:47 +01:00
if ( ! empty ( $objp -> price_by_qty ) && $objp -> price_by_qty == 1 && ! empty ( $conf -> global -> PRODUIT_CUSTOMER_PRICES_BY_QTY ))
2013-06-05 22:01:35 +02:00
{ // Price by quantity will return many prices for the same product
2012-11-07 00:38:53 +01:00
$sql = " SELECT rowid, quantity, price, unitprice, remise_percent, remise " ;
2012-10-26 01:00:03 +02:00
$sql .= " FROM " . MAIN_DB_PREFIX . " product_price_by_qty " ;
$sql .= " WHERE fk_product_price= " . $objp -> price_rowid ;
2012-11-07 00:38:53 +01:00
$sql .= " ORDER BY quantity ASC " ;
2012-12-07 13:48:11 +01:00
2014-06-12 11:31:53 +02:00
dol_syslog ( get_class ( $this ) . " ::select_produits_list search price by qty " , LOG_DEBUG );
2012-10-26 01:00:03 +02:00
$result2 = $this -> db -> query ( $sql );
if ( $result2 )
{
$nb_prices = $this -> db -> num_rows ( $result2 );
$j = 0 ;
while ( $nb_prices && $j < $nb_prices ) {
$objp2 = $this -> db -> fetch_object ( $result2 );
2012-12-07 13:48:11 +01:00
2012-11-07 00:38:53 +01:00
$objp -> quantity = $objp2 -> quantity ;
2012-10-26 01:00:03 +02:00
$objp -> price = $objp2 -> price ;
2012-11-07 00:38:53 +01:00
$objp -> unitprice = $objp2 -> unitprice ;
2012-10-26 01:00:03 +02:00
$objp -> remise_percent = $objp2 -> remise_percent ;
$objp -> remise = $objp2 -> remise ;
$objp -> price_by_qty_rowid = $objp2 -> rowid ;
2012-12-07 13:48:11 +01:00
2013-07-31 10:08:33 +02:00
$this -> constructProductListOption ( $objp , $opt , $optJson , 0 , $selected );
2012-12-07 13:48:11 +01:00
2012-10-26 01:00:03 +02:00
$j ++ ;
2012-12-07 13:48:11 +01:00
2012-10-26 01:00:03 +02:00
// Add new entry
// "key" value of json key array is used by jQuery automatically as selected value
// "label" value of json key array is used by jQuery automatically as text for combo box
2013-06-05 22:01:35 +02:00
$out .= $opt ;
array_push ( $outarray , $optJson );
2012-10-26 01:00:03 +02:00
}
}
2013-06-05 22:01:35 +02:00
}
else
{
2013-07-31 10:08:33 +02:00
$this -> constructProductListOption ( $objp , $opt , $optJson , $price_level , $selected );
2012-10-26 01:00:03 +02:00
// Add new entry
// "key" value of json key array is used by jQuery automatically as selected value
// "label" value of json key array is used by jQuery automatically as text for combo box
2013-06-05 22:01:35 +02:00
$out .= $opt ;
array_push ( $outarray , $optJson );
2012-10-26 01:00:03 +02:00
}
2010-10-20 00:52:32 +02:00
2012-10-26 01:00:03 +02:00
$i ++ ;
}
2010-08-22 17:46:34 +02:00
2013-06-05 22:01:35 +02:00
$out .= '</select>' ;
2010-08-22 17:46:34 +02:00
2012-10-26 01:00:03 +02:00
$this -> db -> free ( $result );
2010-08-22 17:46:34 +02:00
2013-06-05 22:01:35 +02:00
if ( empty ( $outputmode )) return $out ;
return $outarray ;
2012-10-26 01:00:03 +02:00
}
else
2013-06-05 22:01:35 +02:00
{
2012-10-26 01:00:03 +02:00
dol_print_error ( $db );
}
}
2010-08-22 17:46:34 +02:00
2013-05-02 13:10:39 +02:00
/**
2013-07-07 13:14:32 +02:00
* constructProductListOption
2013-06-05 22:01:35 +02:00
*
2013-07-07 13:14:32 +02:00
* @ param resultset & $objp Resultset of fetch
* @ param string & $opt Option
* @ param string & $optJson Option
2013-05-02 13:10:39 +02:00
* @ param int $price_level Price level
* @ param string $selected Preselected value
2013-07-07 13:14:32 +02:00
* @ return void
2013-05-02 13:10:39 +02:00
*/
2013-07-07 13:14:32 +02:00
private function constructProductListOption ( & $objp , & $opt , & $optJson , $price_level , $selected )
2013-05-02 13:10:39 +02:00
{
2012-10-26 01:00:03 +02:00
global $langs , $conf , $user , $db ;
2012-12-07 13:48:11 +01:00
2012-10-26 01:00:03 +02:00
$outkey = '' ;
$outval = '' ;
$outref = '' ;
$outlabel = '' ;
$outdesc = '' ;
$outtype = '' ;
$outprice_ht = '' ;
$outprice_ttc = '' ;
$outpricebasetype = '' ;
$outtva_tx = '' ;
$outqty = 1 ;
$outdiscount = 0 ;
$label = $objp -> label ;
if ( ! empty ( $objp -> label_translated )) $label = $objp -> label_translated ;
2013-05-02 13:10:39 +02:00
if ( ! empty ( $filterkey ) && $filterkey != '' ) $label = preg_replace ( '/(' . preg_quote ( $filterkey ) . ')/i' , '<strong>$1</strong>' , $label , 1 );
2012-10-26 01:00:03 +02:00
$outkey = $objp -> rowid ;
$outref = $objp -> ref ;
$outlabel = $objp -> label ;
$outdesc = $objp -> description ;
$outtype = $objp -> fk_product_type ;
$opt = '<option value="' . $objp -> rowid . '"' ;
$opt .= ( $objp -> rowid == $selected ) ? ' selected="selected"' : '' ;
$opt .= ( ! empty ( $objp -> price_by_qty_rowid ) && $objp -> price_by_qty_rowid > 0 ) ? ' pbq="' . $objp -> price_by_qty_rowid . '"' : '' ;
if ( ! empty ( $conf -> stock -> enabled ) && $objp -> fk_product_type == 0 && isset ( $objp -> stock ))
{
2012-11-07 00:38:53 +01:00
if ( $objp -> stock > 0 ) $opt .= ' class="product_line_stock_ok"' ;
else if ( $objp -> stock <= 0 ) $opt .= ' class="product_line_stock_too_low"' ;
2012-10-26 01:00:03 +02:00
}
$opt .= '>' ;
$opt .= $objp -> ref . ' - ' . dol_trunc ( $label , 32 ) . ' - ' ;
$objRef = $objp -> ref ;
2013-05-02 13:10:39 +02:00
if ( ! empty ( $filterkey ) && $filterkey != '' ) $objRef = preg_replace ( '/(' . preg_quote ( $filterkey ) . ')/i' , '<strong>$1</strong>' , $objRef , 1 );
2012-10-26 01:00:03 +02:00
$outval .= $objRef . ' - ' . dol_trunc ( $label , 32 ) . ' - ' ;
$found = 0 ;
2010-08-22 17:46:34 +02:00
2012-10-26 01:00:03 +02:00
// Multiprice
2014-02-23 16:16:47 +01:00
if ( $price_level >= 1 && $conf -> global -> PRODUIT_MULTIPRICES ) // If we need a particular price level (from 1 to 6)
2012-10-26 01:00:03 +02:00
{
$sql = " SELECT price, price_ttc, price_base_type, tva_tx " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " product_price " ;
$sql .= " WHERE fk_product=' " . $objp -> rowid . " ' " ;
2013-06-24 17:10:11 +02:00
$sql .= " AND entity IN ( " . getEntity ( 'productprice' , 1 ) . " ) " ;
2012-10-26 01:00:03 +02:00
$sql .= " AND price_level= " . $price_level ;
$sql .= " ORDER BY date_price " ;
$sql .= " DESC LIMIT 1 " ;
2014-06-13 01:34:39 +02:00
dol_syslog ( get_class ( $this ) . '::constructProductListOption search price for level ' . $price_level . '' , LOG_DEBUG );
2012-10-26 01:00:03 +02:00
$result2 = $this -> db -> query ( $sql );
if ( $result2 )
{
$objp2 = $this -> db -> fetch_object ( $result2 );
if ( $objp2 )
2010-08-22 17:46:34 +02:00
{
2012-10-26 01:00:03 +02:00
$found = 1 ;
if ( $objp2 -> price_base_type == 'HT' )
2010-08-22 17:46:34 +02:00
{
2013-06-17 11:58:55 +02:00
$opt .= price ( $objp2 -> price , 1 , $langs , 0 , 0 , - 1 , $conf -> currency ) . ' ' . $langs -> trans ( " HT " );
$outval .= price ( $objp2 -> price , 0 , $langs , 0 , 0 , - 1 , $conf -> currency ) . ' ' . $langs -> transnoentities ( " HT " );
2010-08-22 17:46:34 +02:00
}
else
{
2013-06-17 11:58:55 +02:00
$opt .= price ( $objp2 -> price_ttc , 1 , $langs , 0 , 0 , - 1 , $conf -> currency ) . ' ' . $langs -> trans ( " TTC " );
$outval .= price ( $objp2 -> price_ttc , 0 , $langs , 0 , 0 , - 1 , $conf -> currency ) . ' ' . $langs -> transnoentities ( " TTC " );
2010-08-22 17:46:34 +02:00
}
2012-10-26 01:00:03 +02:00
$outprice_ht = price ( $objp2 -> price );
$outprice_ttc = price ( $objp2 -> price_ttc );
$outpricebasetype = $objp2 -> price_base_type ;
$outtva_tx = $objp2 -> tva_tx ;
2010-08-22 17:46:34 +02:00
}
}
2012-10-26 01:00:03 +02:00
else
{
dol_print_error ( $this -> db );
}
}
2010-08-22 17:46:34 +02:00
2012-10-26 01:00:03 +02:00
// Price by quantity
2014-02-23 16:16:47 +01:00
if ( ! empty ( $objp -> quantity ) && $objp -> quantity >= 1 && $conf -> global -> PRODUIT_CUSTOMER_PRICES_BY_QTY )
2013-06-05 22:01:35 +02:00
{
2012-10-26 01:00:03 +02:00
$found = 1 ;
$outqty = $objp -> quantity ;
$outdiscount = $objp -> remise_percent ;
if ( $objp -> quantity == 1 )
{
2013-06-17 11:58:55 +02:00
$opt .= price ( $objp -> unitprice , 1 , $langs , 0 , 0 , - 1 , $conf -> currency ) . " / " ;
$outval .= price ( $objp -> unitprice , 0 , $langs , 0 , 0 , - 1 , $conf -> currency ) . " / " ;
2012-10-26 01:00:03 +02:00
$opt .= $langs -> trans ( " Unit " ); // Do not use strtolower because it breaks utf8 encoding
$outval .= $langs -> transnoentities ( " Unit " );
}
else
{
2013-06-17 11:58:55 +02:00
$opt .= price ( $objp -> price , 1 , $langs , 0 , 0 , - 1 , $conf -> currency ) . " / " . $objp -> quantity ;
$outval .= price ( $objp -> price , 0 , $langs , 0 , 0 , - 1 , $conf -> currency ) . " / " . $objp -> quantity ;
2012-10-26 01:00:03 +02:00
$opt .= $langs -> trans ( " Units " ); // Do not use strtolower because it breaks utf8 encoding
$outval .= $langs -> transnoentities ( " Units " );
}
2012-12-07 13:48:11 +01:00
2012-11-07 00:38:53 +01:00
$outprice_ht = price ( $objp -> unitprice );
$outprice_ttc = price ( $objp -> unitprice * ( 1 + ( $objp -> tva_tx / 100 )));
2012-10-26 01:00:03 +02:00
$outpricebasetype = $objp -> price_base_type ;
$outtva_tx = $objp -> tva_tx ;
}
if ( ! empty ( $objp -> quantity ) && $objp -> quantity >= 1 )
{
2013-06-17 11:58:55 +02:00
$opt .= " ( " . price ( $objp -> unitprice , 1 , $langs , 0 , 0 , - 1 , $conf -> currency ) . " / " . $langs -> trans ( " Unit " ) . " ) " ; // Do not use strtolower because it breaks utf8 encoding
$outval .= " ( " . price ( $objp -> unitprice , 0 , $langs , 0 , 0 , - 1 , $conf -> currency ) . " / " . $langs -> transnoentities ( " Unit " ) . " ) " ; // Do not use strtolower because it breaks utf8 encoding
2012-10-26 01:00:03 +02:00
}
if ( ! empty ( $objp -> remise_percent ) && $objp -> remise_percent >= 1 )
{
$opt .= " - " . $langs -> trans ( " Discount " ) . " : " . vatrate ( $objp -> remise_percent ) . ' %' ;
$outval .= " - " . $langs -> transnoentities ( " Discount " ) . " : " . vatrate ( $objp -> remise_percent ) . ' %' ;
}
2014-04-02 14:53:42 +02:00
2014-02-23 16:16:47 +01:00
//Price by customer
if ( ! empty ( $conf -> global -> PRODUIT_CUSTOMER_PRICES )) {
if ( ! empty ( $objp -> idprodcustprice )) {
$found = 1 ;
2014-04-02 14:53:42 +02:00
2014-02-23 16:16:47 +01:00
if ( $objp -> custprice_base_type == 'HT' )
{
2014-04-11 18:00:58 +02:00
$opt .= price ( $objp -> custprice , 1 , $langs , 0 , 0 , - 1 , $conf -> currency ) . ' ' . $langs -> trans ( " HT " );
$outval .= price ( $objp -> custprice , 0 , $langs , 0 , 0 , - 1 , $conf -> currency ) . ' ' . $langs -> transnoentities ( " HT " );
2014-02-23 16:16:47 +01:00
}
else
{
2014-04-11 18:00:58 +02:00
$opt .= price ( $objp -> custprice_ttc , 1 , $langs , 0 , 0 , - 1 , $conf -> currency ) . ' ' . $langs -> trans ( " TTC " );
$outval .= price ( $objp -> custprice_ttc , 0 , $langs , 0 , 0 , - 1 , $conf -> currency ) . ' ' . $langs -> transnoentities ( " TTC " );
2014-02-23 16:16:47 +01:00
}
2014-04-02 14:53:42 +02:00
2014-02-23 16:16:47 +01:00
$outprice_ht = price ( $objp -> custprice );
$outprice_ttc = price ( $objp -> custprice_ttc );
$outpricebasetype = $objp -> custprice_base_type ;
$outtva_tx = $objp -> custtva_tx ;
}
}
2012-10-26 01:00:03 +02:00
// If level no defined or multiprice not found, we used the default price
if ( ! $found )
{
if ( $objp -> price_base_type == 'HT' )
{
2013-06-17 11:58:55 +02:00
$opt .= price ( $objp -> price , 1 , $langs , 0 , 0 , - 1 , $conf -> currency ) . ' ' . $langs -> trans ( " HT " );
$outval .= price ( $objp -> price , 0 , $langs , 0 , 0 , - 1 , $conf -> currency ) . ' ' . $langs -> transnoentities ( " HT " );
2012-10-26 01:00:03 +02:00
}
else
{
2013-06-17 11:58:55 +02:00
$opt .= price ( $objp -> price_ttc , 1 , $langs , 0 , 0 , - 1 , $conf -> currency ) . ' ' . $langs -> trans ( " TTC " );
$outval .= price ( $objp -> price_ttc , 0 , $langs , 0 , 0 , - 1 , $conf -> currency ) . ' ' . $langs -> transnoentities ( " TTC " );
2012-10-26 01:00:03 +02:00
}
$outprice_ht = price ( $objp -> price );
$outprice_ttc = price ( $objp -> price_ttc );
$outpricebasetype = $objp -> price_base_type ;
$outtva_tx = $objp -> tva_tx ;
}
2010-08-22 17:46:34 +02:00
2012-10-26 01:00:03 +02:00
if ( ! empty ( $conf -> stock -> enabled ) && isset ( $objp -> stock ) && $objp -> fk_product_type == 0 )
{
$opt .= ' - ' . $langs -> trans ( " Stock " ) . ':' . $objp -> stock ;
$outval .= ' - ' . $langs -> transnoentities ( " Stock " ) . ':' . $objp -> stock ;
2010-08-22 17:46:34 +02:00
}
2012-10-26 01:00:03 +02:00
if ( $objp -> duration )
2010-08-22 17:46:34 +02:00
{
2012-10-26 01:00:03 +02:00
$duration_value = substr ( $objp -> duration , 0 , dol_strlen ( $objp -> duration ) - 1 );
$duration_unit = substr ( $objp -> duration , - 1 );
if ( $duration_value > 1 )
{
$dur = array ( " h " => $langs -> trans ( " Hours " ), " d " => $langs -> trans ( " Days " ), " w " => $langs -> trans ( " Weeks " ), " m " => $langs -> trans ( " Months " ), " y " => $langs -> trans ( " Years " ));
}
else
{
$dur = array ( " h " => $langs -> trans ( " Hour " ), " d " => $langs -> trans ( " Day " ), " w " => $langs -> trans ( " Week " ), " m " => $langs -> trans ( " Month " ), " y " => $langs -> trans ( " Year " ));
}
$opt .= ' - ' . $duration_value . ' ' . $langs -> trans ( $dur [ $duration_unit ]);
$outval .= ' - ' . $duration_value . ' ' . $langs -> transnoentities ( $dur [ $duration_unit ]);
2010-08-22 17:46:34 +02:00
}
2012-10-26 01:00:03 +02:00
$opt .= " </option> \n " ;
$optJson = array ( 'key' => $outkey , 'value' => $outref , 'label' => $outval , 'label2' => $outlabel , 'desc' => $outdesc , 'type' => $outtype , 'price_ht' => $outprice_ht , 'price_ttc' => $outprice_ttc , 'pricebasetype' => $outpricebasetype , 'tva_tx' => $outtva_tx , 'qty' => $outqty , 'discount' => $outdiscount );
}
2010-08-22 17:46:34 +02:00
/**
2013-06-05 22:01:35 +02:00
* Return list of products for customer ( in Ajax if Ajax activated or go to select_produits_fournisseurs_list )
2011-09-15 01:15:38 +02:00
*
2011-11-09 21:42:46 +01:00
* @ param int $socid Id third party
2012-03-19 17:18:11 +01:00
* @ param string $selected Preselected product
* @ param string $htmlname Name of HTML Select
* @ param string $filtertype Filter on product type ( '' = nofilter , 0 = product , 1 = service )
* @ param string $filtre For a SQL filter
2012-08-17 16:58:57 +02:00
* @ param array $ajaxoptions Options for ajax_autocompleter
2014-05-05 17:59:43 +02:00
* @ param int $hidelabel Hide label ( 0 = no , 1 = yes )
2011-11-09 21:42:46 +01:00
* @ return void
2010-08-22 17:46:34 +02:00
*/
2014-05-05 17:59:43 +02:00
function select_produits_fournisseurs ( $socid , $selected = '' , $htmlname = 'productid' , $filtertype = '' , $filtre = '' , $ajaxoptions = array (), $hidelabel = 0 )
2010-08-22 17:46:34 +02:00
{
global $langs , $conf ;
2011-12-05 18:36:54 +01:00
global $price_level , $status , $finished ;
2011-12-07 15:06:29 +01:00
2012-08-18 19:05:59 +02:00
if ( ! empty ( $conf -> use_javascript_ajax ) && ! empty ( $conf -> global -> PRODUIT_USE_SEARCH_TO_SELECT ))
2010-08-22 17:46:34 +02:00
{
2010-10-11 12:28:08 +02:00
// mode=2 means suppliers products
2012-08-17 16:58:57 +02:00
$urloption = ( $socid > 0 ? 'socid=' . $socid . '&' : '' ) . 'htmlname=' . $htmlname . '&outjson=1&price_level=' . $price_level . '&type=' . $filtertype . '&mode=2&status=' . $status . '&finished=' . $finished ;
print ajax_autocompleter ( '' , $htmlname , DOL_URL_ROOT . '/product/ajax/products.php' , $urloption , $conf -> global -> PRODUIT_USE_SEARCH_TO_SELECT , 0 , $ajaxoptions );
2014-05-05 17:59:43 +02:00
print ( $hidelabel ? '' : $langs -> trans ( " RefOrLabel " ) . ' : ' ) . '<input type="text" size="16" name="search_' . $htmlname . '" id="search_' . $htmlname . '">' ;
2010-08-22 17:46:34 +02:00
}
else
{
2013-06-05 22:01:35 +02:00
print $this -> select_produits_fournisseurs_list ( $socid , $selected , $htmlname , $filtertype , $filtre , '' , - 1 , 0 );
2010-08-22 17:46:34 +02:00
}
}
/**
2012-03-12 15:09:46 +01:00
* Return list of suppliers products
2011-09-15 01:15:38 +02:00
*
2012-03-22 09:39:18 +01:00
* @ param int $socid Id societe fournisseur ( 0 pour aucun filtre )
* @ param int $selected Produit pre - selectionne
* @ param string $htmlname Nom de la zone select
* @ param string $filtertype Filter on product type ( '' = nofilter , 0 = product , 1 = service )
* @ param string $filtre Pour filtre sql
* @ param string $filterkey Filtre des produits
* @ param int $statut - 1 = Return all products , 0 = Products not on sell , 1 = Products on sell
2013-06-05 22:01:35 +02:00
* @ param int $outputmode 0 = HTML select string , 1 = Array
2012-03-22 09:39:18 +01:00
* @ return array Array of keys for json
2010-08-22 17:46:34 +02:00
*/
2013-06-05 22:01:35 +02:00
function select_produits_fournisseurs_list ( $socid , $selected = '' , $htmlname = 'productid' , $filtertype = '' , $filtre = '' , $filterkey = '' , $statut =- 1 , $outputmode = 0 )
2010-08-22 17:46:34 +02:00
{
global $langs , $conf ;
2013-06-05 22:01:35 +02:00
$out = '' ;
$outarray = array ();
2010-08-22 17:46:34 +02:00
$langs -> load ( 'stocks' );
$sql = " SELECT p.rowid, p.label, p.ref, p.price, p.duration, " ;
2012-10-01 11:45:28 +02:00
$sql .= " pfp.ref_fourn, pfp.rowid as idprodfournprice, pfp.price as fprice, pfp.quantity, pfp.remise_percent, pfp.remise, pfp.unitprice, " ;
2010-08-22 17:46:34 +02:00
$sql .= " s.nom " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " product as p " ;
2011-10-04 01:26:07 +02:00
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " product_fournisseur_price as pfp ON p.rowid = pfp.fk_product " ;
2012-07-25 11:27:25 +02:00
if ( $socid ) $sql .= " AND pfp.fk_soc = " . $socid ;
2011-10-04 01:26:07 +02:00
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " societe as s ON pfp.fk_soc = s.rowid " ;
2012-02-11 10:18:09 +01:00
$sql .= " WHERE p.entity IN ( " . getEntity ( 'product' , 1 ) . " ) " ;
2010-08-22 17:46:34 +02:00
$sql .= " AND p.tobuy = 1 " ;
if ( strval ( $filtertype ) != '' ) $sql .= " AND p.fk_product_type= " . $filtertype ;
if ( ! empty ( $filtre )) $sql .= " " . $filtre ;
// Add criteria on ref/label
2013-06-09 03:10:31 +02:00
if ( $filterkey != '' )
2010-08-22 17:46:34 +02:00
{
2013-06-12 11:59:55 +02:00
$sql .= ' AND (' ;
$prefix = empty ( $conf -> global -> PRODUCT_DONOTSEARCH_ANYWHERE ) ? '%' : '' ; // Can use index if PRODUCT_DONOTSEARCH_ANYWHERE is on
// For natural search
$scrit = explode ( ' ' , $filterkey );
$i = 0 ;
if ( count ( $scrit ) > 1 ) $sql .= " ( " ;
foreach ( $scrit as $crit )
{
if ( $i > 0 ) $sql .= " AND " ;
$sql .= " (pfp.ref_fourn LIKE ' " . $prefix . $crit . " %' OR p.ref LIKE ' " . $prefix . $crit . " %' OR p.label LIKE ' " . $prefix . $crit . " %') " ;
$i ++ ;
}
if ( count ( $scrit ) > 1 ) $sql .= " ) " ;
if ( ! empty ( $conf -> barcode -> enabled )) $sql .= " OR p.barcode LIKE ' " . $prefix . $filterkey . " %' " ;
$sql .= ')' ;
2010-08-22 17:46:34 +02:00
}
2012-10-01 11:45:28 +02:00
$sql .= " ORDER BY pfp.ref_fourn DESC, pfp.quantity ASC " ;
2010-08-22 17:46:34 +02:00
// Build output string
2014-06-12 11:31:53 +02:00
dol_syslog ( get_class ( $this ) . " ::select_produits_fournisseurs_list " , LOG_DEBUG );
2010-08-22 17:46:34 +02:00
$result = $this -> db -> query ( $sql );
if ( $result )
{
$num = $this -> db -> num_rows ( $result );
2013-06-05 22:01:35 +02:00
//$out.='<select class="flat" id="select'.$htmlname.'" name="'.$htmlname.'">'; // remove select to have id same with combo and ajax
$out .= '<select class="flat" id="' . $htmlname . '" name="' . $htmlname . '">' ;
if ( ! $selected ) $out .= '<option value="0" selected="selected"> </option>' ;
else $out .= '<option value="0"> </option>' ;
2010-08-22 17:46:34 +02:00
$i = 0 ;
while ( $i < $num )
{
$objp = $this -> db -> fetch_object ( $result );
2010-08-22 20:02:32 +02:00
$outkey = $objp -> idprodfournprice ;
$outref = $objp -> ref ;
2011-11-09 21:42:46 +01:00
$outval = '' ;
2012-08-17 18:17:15 +02:00
$outqty = 1 ;
2012-10-01 11:45:28 +02:00
$outdiscount = 0 ;
2010-08-22 20:02:32 +02:00
2010-08-22 17:46:34 +02:00
$opt = '<option value="' . $objp -> idprodfournprice . '"' ;
2012-08-07 18:55:55 +02:00
if ( $selected && $selected == $objp -> idprodfournprice ) $opt .= ' selected="selected"' ;
2012-08-17 15:13:10 +02:00
if ( empty ( $objp -> idprodfournprice )) $opt .= ' disabled="disabled"' ;
2010-08-22 20:02:32 +02:00
$opt .= '>' ;
2010-10-20 00:52:32 +02:00
2010-10-12 14:56:31 +02:00
$objRef = $objp -> ref ;
if ( $filterkey && $filterkey != '' ) $objRef = preg_replace ( '/(' . preg_quote ( $filterkey ) . ')/i' , '<strong>$1</strong>' , $objRef , 1 );
$objRefFourn = $objp -> ref_fourn ;
if ( $filterkey && $filterkey != '' ) $objRefFourn = preg_replace ( '/(' . preg_quote ( $filterkey ) . ')/i' , '<strong>$1</strong>' , $objRefFourn , 1 );
$label = $objp -> label ;
if ( $filterkey && $filterkey != '' ) $label = preg_replace ( '/(' . preg_quote ( $filterkey ) . ')/i' , '<strong>$1</strong>' , $label , 1 );
2010-08-22 20:02:32 +02:00
2012-11-07 00:38:53 +01:00
$opt .= $objp -> ref ;
if ( ! empty ( $objp -> idprodfournprice )) $opt .= ' (' . $objp -> ref_fourn . ')' ;
$opt .= ' - ' ;
$outval .= $objRef ;
if ( ! empty ( $objp -> idprodfournprice )) $outval .= ' (' . $objRefFourn . ')' ;
$outval .= ' - ' ;
2011-12-07 18:10:24 +01:00
$opt .= dol_trunc ( $objp -> label , 18 ) . ' - ' ;
2010-10-12 14:56:31 +02:00
$outval .= dol_trunc ( $label , 18 ) . ' - ' ;
2012-10-23 09:30:48 +02:00
2012-08-17 15:13:10 +02:00
if ( ! empty ( $objp -> idprodfournprice ))
2010-08-22 17:46:34 +02:00
{
2012-08-17 18:17:15 +02:00
$outqty = $objp -> quantity ;
2012-10-01 11:45:28 +02:00
$outdiscount = $objp -> remise_percent ;
2010-08-22 17:46:34 +02:00
if ( $objp -> quantity == 1 )
{
2013-06-17 11:58:55 +02:00
$opt .= price ( $objp -> fprice , 1 , $langs , 0 , 0 , - 1 , $conf -> currency ) . " / " ;
$outval .= price ( $objp -> fprice , 0 , $langs , 0 , 0 , - 1 , $conf -> currency ) . " / " ;
2012-10-18 16:30:12 +02:00
$opt .= $langs -> trans ( " Unit " ); // Do not use strtolower because it breaks utf8 encoding
$outval .= $langs -> transnoentities ( " Unit " );
2010-08-22 17:46:34 +02:00
}
else
{
2013-06-17 11:58:55 +02:00
$opt .= price ( $objp -> fprice , 1 , $langs , 0 , 0 , - 1 , $conf -> currency ) . " / " . $objp -> quantity ;
$outval .= price ( $objp -> fprice , 0 , $langs , 0 , 0 , - 1 , $conf -> currency ) . " / " . $objp -> quantity ;
2013-09-15 13:04:38 +02:00
$opt .= ' ' . $langs -> trans ( " Units " ); // Do not use strtolower because it breaks utf8 encoding
$outval .= ' ' . $langs -> transnoentities ( " Units " );
2010-08-22 17:46:34 +02:00
}
2012-10-23 09:30:48 +02:00
2010-08-22 17:46:34 +02:00
if ( $objp -> quantity >= 1 )
{
2013-06-17 11:58:55 +02:00
$opt .= " ( " . price ( $objp -> unitprice , 1 , $langs , 0 , 0 , - 1 , $conf -> currency ) . " / " . $langs -> trans ( " Unit " ) . " ) " ; // Do not use strtolower because it breaks utf8 encoding
$outval .= " ( " . price ( $objp -> unitprice , 0 , $langs , 0 , 0 , - 1 , $conf -> currency ) . " / " . $langs -> transnoentities ( " Unit " ) . " ) " ; // Do not use strtolower because it breaks utf8 encoding
2012-10-01 11:45:28 +02:00
}
if ( $objp -> remise_percent >= 1 )
{
$opt .= " - " . $langs -> trans ( " Discount " ) . " : " . vatrate ( $objp -> remise_percent ) . ' %' ;
$outval .= " - " . $langs -> transnoentities ( " Discount " ) . " : " . vatrate ( $objp -> remise_percent ) . ' %' ;
2010-08-22 20:02:32 +02:00
}
if ( $objp -> duration )
{
$opt .= " - " . $objp -> duration ;
$outval .= " - " . $objp -> duration ;
}
if ( ! $socid )
{
$opt .= " - " . dol_trunc ( $objp -> nom , 8 );
$outval .= " - " . dol_trunc ( $objp -> nom , 8 );
2010-08-22 17:46:34 +02:00
}
}
else
{
$opt .= $langs -> trans ( " NoPriceDefinedForThisSupplier " );
2010-08-22 20:02:32 +02:00
$outval .= $langs -> transnoentities ( " NoPriceDefinedForThisSupplier " );
2010-08-22 17:46:34 +02:00
}
$opt .= " </option> \n " ;
2012-10-23 09:30:48 +02:00
2010-08-22 20:02:32 +02:00
// Add new entry
// "key" value of json key array is used by jQuery automatically as selected value
// "label" value of json key array is used by jQuery automatically as text for combo box
2013-06-05 22:01:35 +02:00
$out .= $opt ;
array_push ( $outarray , array ( 'key' => $outkey , 'value' => $outref , 'label' => $outval , 'qty' => $outqty , 'discount' => $outdiscount , 'disabled' => ( empty ( $objp -> idprodfournprice ) ? true : false )));
// Exemple of var_dump $outarray
2012-10-18 16:30:12 +02:00
// array(1) {[0]=>array(6) {[key"]=>string(1) "2" ["value"]=>string(3) "ppp"
// ["label"]=>string(76) "ppp (<strong>f</strong>ff2) - ppp - 20,00 Euros/1unité (20,00 Euros/unité)"
2012-10-28 13:57:21 +01:00
// ["qty"]=>string(1) "1" ["discount"]=>string(1) "0" ["disabled"]=>bool(false)
2012-10-18 16:30:12 +02:00
//}
//var_dump($outval); var_dump(utf8_check($outval)); var_dump(json_encode($outval));
2012-10-28 13:57:21 +01:00
//$outval=array('label'=>'ppp (<strong>f</strong>ff2) - ppp - 20,00 Euros/ Unité (20,00 Euros/unité)');
2012-10-18 16:30:12 +02:00
//var_dump($outval); var_dump(utf8_check($outval)); var_dump(json_encode($outval));
2012-10-23 09:30:48 +02:00
2010-08-22 17:46:34 +02:00
$i ++ ;
}
2013-06-05 22:01:35 +02:00
$out .= '</select>' ;
2010-08-22 17:46:34 +02:00
$this -> db -> free ( $result );
2013-06-05 22:01:35 +02:00
if ( empty ( $outputmode )) return $out ;
return $outarray ;
2010-08-22 17:46:34 +02:00
}
else
{
2011-12-05 18:36:54 +01:00
dol_print_error ( $this -> db );
2010-08-22 17:46:34 +02:00
}
}
/**
2011-05-10 00:19:14 +02:00
* Return list of suppliers prices for a product
2011-09-15 01:15:38 +02:00
*
* @ param int $productid Id of product
* @ param string $htmlname Name of HTML field
* @ return void
2010-08-22 17:46:34 +02:00
*/
2013-07-30 10:24:37 +02:00
function select_product_fourn_price ( $productid , $htmlname = 'productfournpriceid' )
2010-08-22 17:46:34 +02:00
{
global $langs , $conf ;
$langs -> load ( 'stocks' );
$sql = " SELECT p.rowid, p.label, p.ref, p.price, p.duration, " ;
2011-10-04 01:26:07 +02:00
$sql .= " pfp.ref_fourn, pfp.rowid as idprodfournprice, pfp.price as fprice, pfp.quantity, pfp.unitprice, " ;
2010-08-22 17:46:34 +02:00
$sql .= " s.nom " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " product as p " ;
2011-10-04 01:26:07 +02:00
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " product_fournisseur_price as pfp ON p.rowid = pfp.fk_product " ;
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " societe as s ON pfp.fk_soc = s.rowid " ;
2012-02-11 10:18:09 +01:00
$sql .= " WHERE p.entity IN ( " . getEntity ( 'product' , 1 ) . " ) " ;
2011-10-04 01:26:07 +02:00
$sql .= " AND p.tobuy = 1 " ;
2010-08-22 17:46:34 +02:00
$sql .= " AND s.fournisseur = 1 " ;
$sql .= " AND p.rowid = " . $productid ;
2011-10-04 01:26:07 +02:00
$sql .= " ORDER BY s.nom, pfp.ref_fourn DESC " ;
2010-08-22 17:46:34 +02:00
2014-06-12 11:31:53 +02:00
dol_syslog ( get_class ( $this ) . " ::select_product_fourn_price " , LOG_DEBUG );
2010-08-22 17:46:34 +02:00
$result = $this -> db -> query ( $sql );
if ( $result )
{
$num = $this -> db -> num_rows ( $result );
$form = '<select class="flat" name="' . $htmlname . '">' ;
if ( ! $num )
{
$form .= '<option value="0">-- ' . $langs -> trans ( " NoSupplierPriceDefinedForThisProduct " ) . ' --</option>' ;
}
else
{
2013-07-30 10:24:37 +02:00
$form .= '<option value="0"> </option>' ;
2010-08-22 17:46:34 +02:00
$i = 0 ;
while ( $i < $num )
{
$objp = $this -> db -> fetch_object ( $result );
$opt = '<option value="' . $objp -> idprodfournprice . '"' ;
2013-07-30 10:24:37 +02:00
//if there is only one supplier, preselect it
if ( $num == 1 ) {
$opt .= ' selected="selected"' ;
}
2010-08-22 17:46:34 +02:00
$opt .= '>' . $objp -> nom . ' - ' . $objp -> ref_fourn . ' - ' ;
if ( $objp -> quantity == 1 )
{
2013-06-17 11:58:55 +02:00
$opt .= price ( $objp -> fprice , 1 , $langs , 0 , 0 , - 1 , $conf -> currency ) . " / " ;
2010-08-22 17:46:34 +02:00
}
$opt .= $objp -> quantity . ' ' ;
if ( $objp -> quantity == 1 )
{
2013-06-17 11:58:55 +02:00
$opt .= $langs -> trans ( " Unit " );
2010-08-22 17:46:34 +02:00
}
else
{
2013-06-17 11:58:55 +02:00
$opt .= $langs -> trans ( " Units " );
2010-08-22 17:46:34 +02:00
}
if ( $objp -> quantity > 1 )
{
$opt .= " - " ;
2013-06-17 11:58:55 +02:00
$opt .= price ( $objp -> unitprice , 1 , $langs , 0 , 0 , - 1 , $conf -> currency ) . " / " . $langs -> trans ( " Unit " );
2010-08-22 17:46:34 +02:00
}
if ( $objp -> duration ) $opt .= " - " . $objp -> duration ;
$opt .= " </option> \n " ;
$form .= $opt ;
$i ++ ;
}
$form .= '</select>' ;
$this -> db -> free ( $result );
}
return $form ;
}
else
{
2011-12-05 18:36:54 +01:00
dol_print_error ( $this -> db );
2010-08-22 17:46:34 +02:00
}
}
/**
2011-08-20 17:11:31 +02:00
* Return list of delivery address
2011-10-01 21:55:40 +02:00
*
2011-09-15 01:15:38 +02:00
* @ param string $selected Id contact pre - selectionn
* @ param int $socid Id of company
* @ param string $htmlname Name of HTML field
* @ param int $showempty Add an empty field
* @ return void
2010-08-22 17:46:34 +02:00
*/
2012-03-19 17:18:11 +01:00
function select_address ( $selected , $socid , $htmlname = 'address_id' , $showempty = 0 )
2010-08-22 17:46:34 +02:00
{
// On recherche les utilisateurs
$sql = " SELECT a.rowid, a.label " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " societe_address as a " ;
$sql .= " WHERE a.fk_soc = " . $socid ;
$sql .= " ORDER BY a.label ASC " ;
2014-06-12 11:31:53 +02:00
dol_syslog ( get_class ( $this ) . " ::select_address " , LOG_DEBUG );
2010-08-22 17:46:34 +02:00
$resql = $this -> db -> query ( $sql );
if ( $resql )
{
print '<select class="flat" name="' . $htmlname . '">' ;
if ( $showempty ) print '<option value="0"> </option>' ;
$num = $this -> db -> num_rows ( $resql );
$i = 0 ;
if ( $num )
{
while ( $i < $num )
{
$obj = $this -> db -> fetch_object ( $resql );
if ( $selected && $selected == $obj -> rowid )
{
2010-11-01 17:00:38 +01:00
print '<option value="' . $obj -> rowid . '" selected="selected">' . $obj -> label . '</option>' ;
2010-08-22 17:46:34 +02:00
}
else
{
print '<option value="' . $obj -> rowid . '">' . $obj -> label . '</option>' ;
}
$i ++ ;
}
}
print '</select>' ;
return $num ;
}
else
{
dol_print_error ( $this -> db );
}
}
/**
2011-05-10 00:19:14 +02:00
* Charge dans cache la liste des conditions de paiements possibles
2011-10-01 21:55:40 +02:00
*
2011-05-10 00:19:14 +02:00
* @ return int Nb lignes chargees , 0 si deja chargees , < 0 si ko
2010-08-22 17:46:34 +02:00
*/
function load_cache_conditions_paiements ()
{
global $langs ;
2011-09-15 01:15:38 +02:00
if ( count ( $this -> cache_conditions_paiements )) return 0 ; // Cache deja charge
2010-08-22 17:46:34 +02:00
$sql = " SELECT rowid, code, libelle " ;
2010-09-06 01:39:37 +02:00
$sql .= " FROM " . MAIN_DB_PREFIX . 'c_payment_term' ;
2010-08-22 17:46:34 +02:00
$sql .= " WHERE active=1 " ;
$sql .= " ORDER BY sortorder " ;
2014-06-13 01:34:39 +02:00
dol_syslog ( get_class ( $this ) . '::load_cache_conditions_paiements' , LOG_DEBUG );
2010-08-22 17:46:34 +02:00
$resql = $this -> db -> query ( $sql );
if ( $resql )
{
$num = $this -> db -> num_rows ( $resql );
$i = 0 ;
while ( $i < $num )
{
$obj = $this -> db -> fetch_object ( $resql );
// Si traduction existe, on l'utilise, sinon on prend le libelle par defaut
$libelle = ( $langs -> trans ( " PaymentConditionShort " . $obj -> code ) != ( " PaymentConditionShort " . $obj -> code ) ? $langs -> trans ( " PaymentConditionShort " . $obj -> code ) : ( $obj -> libelle != '-' ? $obj -> libelle : '' ));
$this -> cache_conditions_paiements [ $obj -> rowid ][ 'code' ] = $obj -> code ;
$this -> cache_conditions_paiements [ $obj -> rowid ][ 'label' ] = $libelle ;
$i ++ ;
}
return 1 ;
}
else {
dol_print_error ( $this -> db );
return - 1 ;
}
}
2011-05-10 00:19:14 +02:00
/**
* Charge dans cache la liste des délais de livraison possibles
2011-10-01 21:55:40 +02:00
*
2011-05-10 00:19:14 +02:00
* @ return int Nb lignes chargees , 0 si deja chargees , < 0 si ko
2011-04-01 12:04:49 +02:00
*/
2011-04-01 12:49:57 +02:00
function load_cache_availability ()
2011-04-01 12:04:49 +02:00
{
global $langs ;
2011-09-15 01:15:38 +02:00
if ( count ( $this -> cache_availability )) return 0 ; // Cache deja charge
2011-04-01 12:04:49 +02:00
2011-04-01 12:49:57 +02:00
$sql = " SELECT rowid, code, label " ;
$sql .= " FROM " . MAIN_DB_PREFIX . 'c_availability' ;
2011-04-01 12:04:49 +02:00
$sql .= " WHERE active=1 " ;
$sql .= " ORDER BY rowid " ;
2014-06-13 01:34:39 +02:00
dol_syslog ( get_class ( $this ) . '::load_cache_availability' , LOG_DEBUG );
2011-04-01 12:04:49 +02:00
$resql = $this -> db -> query ( $sql );
if ( $resql )
{
$num = $this -> db -> num_rows ( $resql );
$i = 0 ;
while ( $i < $num )
{
$obj = $this -> db -> fetch_object ( $resql );
// Si traduction existe, on l'utilise, sinon on prend le libelle par defaut
2011-04-01 12:49:57 +02:00
$label = ( $langs -> trans ( " AvailabilityType " . $obj -> code ) != ( " AvailabilityType " . $obj -> code ) ? $langs -> trans ( " AvailabilityType " . $obj -> code ) : ( $obj -> label != '-' ? $obj -> label : '' ));
$this -> cache_availability [ $obj -> rowid ][ 'code' ] = $obj -> code ;
$this -> cache_availability [ $obj -> rowid ][ 'label' ] = $label ;
2011-04-01 12:04:49 +02:00
$i ++ ;
}
return 1 ;
}
else {
dol_print_error ( $this -> db );
return - 1 ;
}
}
2012-02-21 10:47:08 +01:00
/**
2011-05-10 00:19:14 +02:00
* Retourne la liste des types de delais de livraison possibles
2011-10-01 21:55:40 +02:00
*
2012-03-12 15:09:46 +01:00
* @ param int $selected Id du type de delais pre - selectionne
* @ param string $htmlname Nom de la zone select
* @ param string $filtertype To add a filter
* @ param int $addempty Add empty entry
* @ return void
2011-04-01 12:04:49 +02:00
*/
2014-04-02 14:53:42 +02:00
function selectAvailabilityDelay ( $selected = '' , $htmlname = 'availid' , $filtertype = '' , $addempty = 0 )
2011-04-01 12:04:49 +02:00
{
global $langs , $user ;
2011-04-01 12:49:57 +02:00
$this -> load_cache_availability ();
2011-04-01 12:04:49 +02:00
print '<select class="flat" name="' . $htmlname . '">' ;
if ( $addempty ) print '<option value="0"> </option>' ;
2011-04-01 12:49:57 +02:00
foreach ( $this -> cache_availability as $id => $arrayavailability )
2011-04-01 12:04:49 +02:00
{
if ( $selected == $id )
{
print '<option value="' . $id . '" selected="selected">' ;
}
else
{
print '<option value="' . $id . '">' ;
}
2011-04-01 12:49:57 +02:00
print $arrayavailability [ 'label' ];
2011-04-01 12:04:49 +02:00
print '</option>' ;
}
print '</select>' ;
2014-02-05 17:53:30 +01:00
if ( $user -> admin ) print info_admin ( $langs -> trans ( " YouCanChangeValuesForThisListFromDictionarySetup " ), 1 );
2011-04-01 12:04:49 +02:00
}
2012-02-21 10:47:08 +01:00
/**
2011-05-07 13:36:47 +02:00
* Load into cache cache_demand_reason , array of input reasons
2011-10-01 21:55:40 +02:00
*
2011-05-07 13:36:47 +02:00
* @ return int Nb of lines loaded , 0 if already loaded , < 0 if ko
2011-04-18 22:56:10 +02:00
*/
2014-04-02 14:53:42 +02:00
function loadCacheInputReason ()
2011-04-18 22:56:10 +02:00
{
global $langs ;
2011-09-15 01:15:38 +02:00
if ( count ( $this -> cache_demand_reason )) return 0 ; // Cache already loaded
2011-04-18 22:56:10 +02:00
$sql = " SELECT rowid, code, label " ;
2011-05-07 13:36:47 +02:00
$sql .= " FROM " . MAIN_DB_PREFIX . 'c_input_reason' ;
2011-04-18 22:56:10 +02:00
$sql .= " WHERE active=1 " ;
$sql .= " ORDER BY rowid " ;
2014-06-12 11:31:53 +02:00
dol_syslog ( get_class ( $this ) . " ::loadCacheInputReason " , LOG_DEBUG );
2011-04-18 22:56:10 +02:00
$resql = $this -> db -> query ( $sql );
if ( $resql )
{
$num = $this -> db -> num_rows ( $resql );
$i = 0 ;
2011-05-07 13:36:47 +02:00
$tmparray = array ();
2011-04-18 22:56:10 +02:00
while ( $i < $num )
{
$obj = $this -> db -> fetch_object ( $resql );
// Si traduction existe, on l'utilise, sinon on prend le libelle par defaut
2011-04-26 22:59:45 +02:00
$label = ( $langs -> trans ( " DemandReasonType " . $obj -> code ) != ( " DemandReasonType " . $obj -> code ) ? $langs -> trans ( " DemandReasonType " . $obj -> code ) : ( $obj -> label != '-' ? $obj -> label : '' ));
2011-05-07 13:36:47 +02:00
$tmparray [ $obj -> rowid ][ 'id' ] = $obj -> rowid ;
$tmparray [ $obj -> rowid ][ 'code' ] = $obj -> code ;
$tmparray [ $obj -> rowid ][ 'label' ] = $label ;
2011-04-18 22:56:10 +02:00
$i ++ ;
}
2012-03-22 09:39:18 +01:00
$this -> cache_demand_reason = dol_sort_array ( $tmparray , 'label' , 'asc' );
2011-05-09 15:39:23 +02:00
2011-05-07 13:36:47 +02:00
unset ( $tmparray );
2011-04-18 22:56:10 +02:00
return 1 ;
}
else {
dol_print_error ( $this -> db );
return - 1 ;
}
}
2012-02-21 10:47:08 +01:00
/**
2014-04-02 14:53:42 +02:00
* Return list of input reason ( events that triggered an object creation , like after sending an emailing , making an advert , ... )
* List found into table c_input_reason loaded by loadCacheInputReason
2011-10-01 21:55:40 +02:00
*
2014-04-02 14:53:42 +02:00
* @ param int $selected Id or code of type origin to select by default
* @ param string $htmlname Nom de la zone select
* @ param string $exclude To exclude a code value ( Example : SRC_PROP )
* @ param int $addempty Add an empty entry
* @ return void
2011-04-18 22:56:10 +02:00
*/
2014-04-02 14:53:42 +02:00
function selectInputReason ( $selected = '' , $htmlname = 'demandreasonid' , $exclude = '' , $addempty = 0 )
2011-04-18 22:56:10 +02:00
{
global $langs , $user ;
2014-04-02 14:53:42 +02:00
$this -> loadCacheInputReason ();
2011-04-18 22:56:10 +02:00
print '<select class="flat" name="' . $htmlname . '">' ;
2011-05-07 13:36:47 +02:00
if ( $addempty ) print '<option value="0"' . ( empty ( $selected ) ? ' selected="selected"' : '' ) . '> </option>' ;
2011-04-26 22:59:45 +02:00
foreach ( $this -> cache_demand_reason as $id => $arraydemandreason )
2011-04-18 22:56:10 +02:00
{
2011-05-07 13:36:47 +02:00
if ( $arraydemandreason [ 'code' ] == $exclude ) continue ;
2012-12-27 18:02:36 +01:00
if ( $selected && ( $selected == $arraydemandreason [ 'id' ] || $selected == $arraydemandreason [ 'code' ]))
2011-04-18 22:56:10 +02:00
{
2011-05-07 13:36:47 +02:00
print '<option value="' . $arraydemandreason [ 'id' ] . '" selected="selected">' ;
2011-04-18 22:56:10 +02:00
}
else
{
2011-05-07 13:36:47 +02:00
print '<option value="' . $arraydemandreason [ 'id' ] . '">' ;
2011-04-18 22:56:10 +02:00
}
2011-04-26 22:59:45 +02:00
print $arraydemandreason [ 'label' ];
2011-04-18 22:56:10 +02:00
print '</option>' ;
}
print '</select>' ;
2014-02-05 17:53:30 +01:00
if ( $user -> admin ) print info_admin ( $langs -> trans ( " YouCanChangeValuesForThisListFromDictionarySetup " ), 1 );
2011-04-18 22:56:10 +02:00
}
2010-08-22 17:46:34 +02:00
/**
2011-05-10 00:19:14 +02:00
* Charge dans cache la liste des types de paiements possibles
2011-10-01 21:55:40 +02:00
*
2011-05-10 00:19:14 +02:00
* @ return int Nb lignes chargees , 0 si deja chargees , < 0 si ko
2010-08-22 17:46:34 +02:00
*/
function load_cache_types_paiements ()
{
global $langs ;
2011-09-15 01:15:38 +02:00
if ( count ( $this -> cache_types_paiements )) return 0 ; // Cache deja charge
2010-08-22 17:46:34 +02:00
$sql = " SELECT id, code, libelle, type " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " c_paiement " ;
$sql .= " WHERE active > 0 " ;
$sql .= " ORDER BY id " ;
2014-06-12 11:31:53 +02:00
dol_syslog ( get_class ( $this ) . " ::load_cache_types_paiements " , LOG_DEBUG );
2010-08-22 17:46:34 +02:00
$resql = $this -> db -> query ( $sql );
if ( $resql )
{
$num = $this -> db -> num_rows ( $resql );
$i = 0 ;
while ( $i < $num )
{
$obj = $this -> db -> fetch_object ( $resql );
// Si traduction existe, on l'utilise, sinon on prend le libelle par defaut
$libelle = ( $langs -> trans ( " PaymentTypeShort " . $obj -> code ) != ( " PaymentTypeShort " . $obj -> code ) ? $langs -> trans ( " PaymentTypeShort " . $obj -> code ) : ( $obj -> libelle != '-' ? $obj -> libelle : '' ));
$this -> cache_types_paiements [ $obj -> id ][ 'code' ] = $obj -> code ;
$this -> cache_types_paiements [ $obj -> id ][ 'label' ] = $libelle ;
$this -> cache_types_paiements [ $obj -> id ][ 'type' ] = $obj -> type ;
$i ++ ;
}
return $num ;
}
2011-10-31 11:49:47 +01:00
else
{
2010-08-22 17:46:34 +02:00
dol_print_error ( $this -> db );
return - 1 ;
}
}
/**
2011-08-12 23:29:29 +02:00
* Retourne la liste des types de paiements possibles
*
2012-03-12 15:09:46 +01:00
* @ param string $selected Id du type de paiement pre - selectionne
* @ param string $htmlname Nom de la zone select
* @ param string $filtertype Pour filtre
* @ param int $addempty Ajoute entree vide
* @ return void
2010-08-22 17:46:34 +02:00
*/
function select_conditions_paiements ( $selected = '' , $htmlname = 'condid' , $filtertype =- 1 , $addempty = 0 )
{
global $langs , $user ;
$this -> load_cache_conditions_paiements ();
print '<select class="flat" name="' . $htmlname . '">' ;
if ( $addempty ) print '<option value="0"> </option>' ;
foreach ( $this -> cache_conditions_paiements as $id => $arrayconditions )
{
if ( $selected == $id )
{
2010-11-01 17:00:38 +01:00
print '<option value="' . $id . '" selected="selected">' ;
2010-08-22 17:46:34 +02:00
}
else
{
print '<option value="' . $id . '">' ;
}
print $arrayconditions [ 'label' ];
print '</option>' ;
}
print '</select>' ;
2014-02-05 17:53:30 +01:00
if ( $user -> admin ) print info_admin ( $langs -> trans ( " YouCanChangeValuesForThisListFromDictionarySetup " ), 1 );
2010-08-22 17:46:34 +02:00
}
/**
2011-02-26 12:10:51 +01:00
* Return list of payment methods
2011-08-12 23:29:29 +02:00
*
2012-03-12 15:09:46 +01:00
* @ param string $selected Id du mode de paiement pre - selectionne
* @ param string $htmlname Nom de la zone select
* @ param string $filtertype To filter on field type in llx_c_paiement ( array ( 'code' => xx , 'label' => zz ))
* @ param int $format 0 = id + libelle , 1 = code + code , 2 = code + libelle , 3 = id + code
* @ param int $empty 1 = peut etre vide , 0 sinon
* @ param int $noadmininfo 0 = Add admin info , 1 = Disable admin info
* @ param int $maxlength Max length of label
* @ return void
2010-08-22 17:46:34 +02:00
*/
2011-05-01 20:22:58 +02:00
function select_types_paiements ( $selected = '' , $htmlname = 'paiementtype' , $filtertype = '' , $format = 0 , $empty = 0 , $noadmininfo = 0 , $maxlength = 0 )
2010-08-22 17:46:34 +02:00
{
global $langs , $user ;
2012-03-12 15:09:46 +01:00
dol_syslog ( get_class ( $this ) . " ::select_type_paiements " . $selected . " , " . $htmlname . " , " . $filtertype . " , " . $format , LOG_DEBUG );
2010-08-22 17:46:34 +02:00
$filterarray = array ();
if ( $filtertype == 'CRDT' ) $filterarray = array ( 0 , 2 );
elseif ( $filtertype == 'DBIT' ) $filterarray = array ( 1 , 2 );
elseif ( $filtertype != '' && $filtertype != '-1' ) $filterarray = explode ( ',' , $filtertype );
$this -> load_cache_types_paiements ();
2010-08-29 18:47:17 +02:00
print '<select id="select' . $htmlname . '" class="flat selectpaymenttypes" name="' . $htmlname . '">' ;
2010-08-22 17:46:34 +02:00
if ( $empty ) print '<option value=""> </option>' ;
foreach ( $this -> cache_types_paiements as $id => $arraytypes )
{
// On passe si on a demande de filtrer sur des modes de paiments particuliers
2011-09-17 21:49:50 +02:00
if ( count ( $filterarray ) && ! in_array ( $arraytypes [ 'type' ], $filterarray )) continue ;
2010-08-22 17:46:34 +02:00
2010-08-29 23:11:42 +02:00
// We discard empty line if showempty is on because an empty line has already been output.
if ( $empty && empty ( $arraytypes [ 'code' ])) continue ;
2010-08-22 17:46:34 +02:00
if ( $format == 0 ) print '<option value="' . $id . '"' ;
if ( $format == 1 ) print '<option value="' . $arraytypes [ 'code' ] . '"' ;
if ( $format == 2 ) print '<option value="' . $arraytypes [ 'code' ] . '"' ;
2011-05-01 20:22:58 +02:00
if ( $format == 3 ) print '<option value="' . $id . '"' ;
2010-08-22 17:46:34 +02:00
// Si selected est text, on compare avec code, sinon avec id
2010-11-01 17:00:38 +01:00
if ( preg_match ( '/[a-z]/i' , $selected ) && $selected == $arraytypes [ 'code' ]) print ' selected="selected"' ;
elseif ( $selected == $id ) print ' selected="selected"' ;
2010-08-22 17:46:34 +02:00
print '>' ;
2011-05-01 20:22:58 +02:00
if ( $format == 0 ) $value = ( $maxlength ? dol_trunc ( $arraytypes [ 'label' ], $maxlength ) : $arraytypes [ 'label' ]);
2010-08-22 17:46:34 +02:00
if ( $format == 1 ) $value = $arraytypes [ 'code' ];
2011-05-01 20:22:58 +02:00
if ( $format == 2 ) $value = ( $maxlength ? dol_trunc ( $arraytypes [ 'label' ], $maxlength ) : $arraytypes [ 'label' ]);
if ( $format == 3 ) $value = $arraytypes [ 'code' ];
2010-08-22 17:46:34 +02:00
print $value ? $value : ' ' ;
print '</option>' ;
}
print '</select>' ;
2014-02-05 17:53:30 +01:00
if ( $user -> admin && ! $noadmininfo ) print info_admin ( $langs -> trans ( " YouCanChangeValuesForThisListFromDictionarySetup " ), 1 );
2010-08-22 17:46:34 +02:00
}
2011-08-12 23:29:29 +02:00
2010-08-22 17:46:34 +02:00
/**
2011-08-12 23:29:29 +02:00
* Selection HT or TTC
*
2012-03-12 15:09:46 +01:00
* @ param string $selected Id pre - selectionne
* @ param string $htmlname Nom de la zone select
* @ return void
2010-08-22 17:46:34 +02:00
*/
function select_PriceBaseType ( $selected = '' , $htmlname = 'price_base_type' )
{
print $this -> load_PriceBaseType ( $selected , $htmlname );
}
2011-08-12 23:29:29 +02:00
2010-08-22 17:46:34 +02:00
/**
2011-08-12 23:29:29 +02:00
* Selection HT or TTC
*
2012-03-12 15:09:46 +01:00
* @ param string $selected Id pre - selectionne
* @ param string $htmlname Nom de la zone select
* @ return void
2010-08-22 17:46:34 +02:00
*/
function load_PriceBaseType ( $selected = '' , $htmlname = 'price_base_type' )
{
global $langs ;
$return = '' ;
$return .= '<select class="flat" name="' . $htmlname . '">' ;
$options = array (
2012-03-12 15:09:46 +01:00
'HT' => $langs -> trans ( " HT " ),
'TTC' => $langs -> trans ( " TTC " )
2010-08-22 17:46:34 +02:00
);
foreach ( $options as $id => $value )
{
if ( $selected == $id )
{
2010-11-01 17:00:38 +01:00
$return .= '<option value="' . $id . '" selected="selected">' . $value ;
2010-08-22 17:46:34 +02:00
}
else
{
$return .= '<option value="' . $id . '">' . $value ;
}
$return .= '</option>' ;
}
$return .= '</select>' ;
return $return ;
}
2014-07-24 18:08:08 +02:00
/**
* Return a HTML select list of shipping mode
*
* @ param string $selected Id shipping mode pre - selected
* @ param string $htmlname Name of select zone
* @ param string $filtre To filter list
* @ param int $useempty 1 = Add an empty value in list , 2 = Add an empty value in list only if there is more than 2 entries .
* @ param string $moreattrib To add more attribute on select
* @ return void
*/
2014-07-25 23:20:19 +02:00
function selectShippingMethod ( $selected = '' , $htmlname = 'shipping_method_id' , $filtre = '' , $useempty = 0 , $moreattrib = '' )
2014-07-24 18:08:08 +02:00
{
global $langs , $conf , $user ;
$langs -> load ( " admin " );
$langs -> load ( " deliveries " );
$sql = " SELECT rowid, code, libelle " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " c_shipment_mode " ;
$sql .= " WHERE active = 1 " ;
if ( $filtre ) $sql .= " AND " . $filtre ;
$sql .= " ORDER BY libelle ASC " ;
2014-08-14 01:04:15 +02:00
2014-07-24 18:08:08 +02:00
dol_syslog ( get_class ( $this ) . " ::selectShippingMode " , LOG_DEBUG );
$result = $this -> db -> query ( $sql );
if ( $result ) {
$num = $this -> db -> num_rows ( $result );
$i = 0 ;
if ( $num ) {
print '<select id="select' . $htmlname . '" class="flat selectshippingmethod" name="' . $htmlname . '"' . ( $moreattrib ? ' ' . $moreattrib : '' ) . '>' ;
if ( $useempty == 1 || ( $useempty == 2 && $num > 1 )) {
print '<option value="-1"> </option>' ;
}
while ( $i < $num ) {
$obj = $this -> db -> fetch_object ( $result );
if ( $selected == $obj -> rowid ) {
print '<option value="' . $obj -> rowid . '" selected="selected">' ;
} else {
print '<option value="' . $obj -> rowid . '">' ;
}
print $langs -> trans ( " SendingMethod " . strtoupper ( $obj -> code ));
print '</option>' ;
$i ++ ;
}
print " </select> " ;
if ( $user -> admin ) print info_admin ( $langs -> trans ( " YouCanChangeValuesForThisListFromDictionnarySetup " ), 1 );
} else {
print $langs -> trans ( " NoShippingMethodDefined " );
}
} else {
dol_print_error ( $this -> db );
}
}
2014-08-14 01:04:15 +02:00
2014-07-24 18:08:08 +02:00
/**
* Display form to select shipping mode
*
* @ param string $page Page
* @ param int $selected Id of shipping mode
* @ param string $htmlname Name of select html field
* @ param int $addempty 1 = Add an empty value in list , 2 = Add an empty value in list only if there is more than 2 entries .
* @ return void
*/
2014-07-25 23:20:19 +02:00
function formSelectShippingMethod ( $page , $selected = '' , $htmlname = 'shipping_method_id' , $addempty = 0 )
2014-07-24 18:08:08 +02:00
{
global $langs , $db ;
$langs -> load ( " deliveries " );
if ( $htmlname != " none " ) {
print '<form method="POST" action="' . $page . '">' ;
print '<input type="hidden" name="action" value="setshippingmethod">' ;
print '<input type="hidden" name="token" value="' . $_SESSION [ 'newtoken' ] . '">' ;
print '<table class="nobordernopadding" cellpadding="0" cellspacing="0">' ;
print '<tr><td>' ;
$this -> selectShippingMethod ( $selected , $htmlname , '' , $addempty );
print '</td>' ;
print '<td align="left"><input type="submit" class="button" value="' . $langs -> trans ( " Modify " ) . '"></td>' ;
print '</tr></table></form>' ;
} else {
if ( $selected ) {
$code = $langs -> getLabelFromKey ( $db , $selected , 'c_shipment_mode' , 'rowid' , 'code' );
print $langs -> trans ( " SendingMethod " . strtoupper ( $code ));
} else {
print " " ;
}
}
}
2010-08-22 17:46:34 +02:00
/**
2012-03-12 15:09:46 +01:00
* Return a HTML select list of bank accounts
2011-08-12 23:29:29 +02:00
*
2012-03-12 15:09:46 +01:00
* @ param string $selected Id account pre - selected
* @ param string $htmlname Name of select zone
2014-02-26 15:29:40 +01:00
* @ param int $statut Status of searched accounts ( 0 = open , 1 = closed , 2 = both )
2012-03-12 15:09:46 +01:00
* @ param string $filtre To filter list
* @ param int $useempty 1 = Add an empty value in list , 2 = Add an empty value in list only if there is more than 2 entries .
* @ param string $moreattrib To add more attribute on select
2012-03-15 22:51:02 +01:00
* @ return void
2010-08-22 17:46:34 +02:00
*/
2011-02-07 17:27:19 +01:00
function select_comptes ( $selected = '' , $htmlname = 'accountid' , $statut = 0 , $filtre = '' , $useempty = 0 , $moreattrib = '' )
2010-08-22 17:46:34 +02:00
{
global $langs , $conf ;
$langs -> load ( " admin " );
2014-02-26 15:29:40 +01:00
$sql = " SELECT rowid, label, bank, clos as status " ;
2010-08-22 17:46:34 +02:00
$sql .= " FROM " . MAIN_DB_PREFIX . " bank_account " ;
2014-02-26 15:29:40 +01:00
$sql .= " WHERE entity IN ( " . getEntity ( 'bank_account' , 1 ) . " ) " ;
if ( $statut != 2 ) $sql .= " AND clos = ' " . $statut . " ' " ;
2010-08-22 17:46:34 +02:00
if ( $filtre ) $sql .= " AND " . $filtre ;
2010-08-28 15:41:55 +02:00
$sql .= " ORDER BY label " ;
2010-08-22 17:46:34 +02:00
2014-06-12 11:31:53 +02:00
dol_syslog ( get_class ( $this ) . " ::select_comptes " , LOG_DEBUG );
2010-08-22 17:46:34 +02:00
$result = $this -> db -> query ( $sql );
if ( $result )
{
$num = $this -> db -> num_rows ( $result );
$i = 0 ;
if ( $num )
{
2011-02-07 17:27:19 +01:00
print '<select id="select' . $htmlname . '" class="flat selectbankaccount" name="' . $htmlname . '"' . ( $moreattrib ? ' ' . $moreattrib : '' ) . '>' ;
2011-02-05 18:25:56 +01:00
if ( $useempty == 1 || ( $useempty == 2 && $num > 1 ))
2010-08-22 17:46:34 +02:00
{
2012-08-18 19:05:59 +02:00
print '<option value="-1"> </option>' ;
2010-08-22 17:46:34 +02:00
}
while ( $i < $num )
{
$obj = $this -> db -> fetch_object ( $result );
if ( $selected == $obj -> rowid )
{
2010-11-01 17:00:38 +01:00
print '<option value="' . $obj -> rowid . '" selected="selected">' ;
2010-08-22 17:46:34 +02:00
}
else
{
print '<option value="' . $obj -> rowid . '">' ;
}
print $obj -> label ;
2014-02-26 15:29:40 +01:00
if ( $statut == 2 && $obj -> status == 1 ) print ' (' . $langs -> trans ( " Closed " ) . ')' ;
2010-08-22 17:46:34 +02:00
print '</option>' ;
$i ++ ;
}
print " </select> " ;
}
else
{
print $langs -> trans ( " NoActiveBankAccountDefined " );
}
}
else {
dol_print_error ( $this -> db );
}
}
2014-07-06 20:49:34 +02:00
/**
* Display form to select bank account
*
* @ param string $page Page
* @ param int $selected Id of bank account
* @ param string $htmlname Name of select html field
* @ param int $addempty 1 = Add an empty value in list , 2 = Add an empty value in list only if there is more than 2 entries .
* @ return void
*/
2014-07-07 20:54:41 +02:00
function formSelectAccount ( $page , $selected = '' , $htmlname = 'fk_account' , $addempty = 0 )
2014-07-06 20:49:34 +02:00
{
global $langs ;
2014-07-07 20:54:41 +02:00
if ( $htmlname != " none " ) {
2014-07-06 20:49:34 +02:00
print '<form method="POST" action="' . $page . '">' ;
print '<input type="hidden" name="action" value="setbankaccount">' ;
print '<input type="hidden" name="token" value="' . $_SESSION [ 'newtoken' ] . '">' ;
print '<table class="nobordernopadding" cellpadding="0" cellspacing="0">' ;
print '<tr><td>' ;
$this -> select_comptes ( $selected , $htmlname , 0 , '' , $addempty );
print '</td>' ;
print '<td align="left"><input type="submit" class="button" value="' . $langs -> trans ( " Modify " ) . '"></td>' ;
print '</tr></table></form>' ;
2014-07-07 20:54:41 +02:00
} else {
if ( $selected ) {
2014-07-06 20:49:34 +02:00
require_once DOL_DOCUMENT_ROOT . '/compta/bank/class/account.class.php' ;
$bankstatic = new Account ( $this -> db );
$bankstatic -> fetch ( $selected );
2014-07-23 09:49:58 +02:00
print $this -> textwithpicto ( $bankstatic -> label , $langs -> trans ( " AccountCurrency " ) . ' ' . $bankstatic -> currency_code );
2014-07-06 20:49:34 +02:00
} else {
print " " ;
}
}
}
2010-08-22 17:46:34 +02:00
/**
2010-10-20 00:52:32 +02:00
* Return list of categories having choosed type
2011-08-12 23:29:29 +02:00
*
2012-03-12 15:09:46 +01:00
* @ param int $type Type de categories ( 0 = product , 1 = supplier , 2 = customer , 3 = member )
2013-08-21 13:02:33 +02:00
* @ param string $selected Id of category preselected or 'auto' ( autoselect category if there is only one element )
2012-10-08 19:27:02 +02:00
* @ param string $htmlname HTML field name
2012-03-12 15:09:46 +01:00
* @ param int $maxlength Maximum length for labels
* @ param int $excludeafterid Exclude all categories after this leaf in category tree .
2012-03-19 17:18:11 +01:00
* @ return void
2010-08-22 17:46:34 +02:00
*/
2012-10-08 19:27:02 +02:00
function select_all_categories ( $type , $selected = '' , $htmlname = " parent " , $maxlength = 64 , $excludeafterid = 0 )
2010-08-22 17:46:34 +02:00
{
global $langs ;
$langs -> load ( " categories " );
$cat = new Categorie ( $this -> db );
2010-10-20 00:52:32 +02:00
$cate_arbo = $cat -> get_full_arbo ( $type , $excludeafterid );
2010-08-22 17:46:34 +02:00
2012-10-08 19:27:02 +02:00
$output = '<select class="flat" name="' . $htmlname . '">' ;
2010-08-22 17:46:34 +02:00
if ( is_array ( $cate_arbo ))
{
2011-09-15 01:15:38 +02:00
if ( ! count ( $cate_arbo )) $output .= '<option value="-1" disabled="disabled">' . $langs -> trans ( " NoCategoriesDefined " ) . '</option>' ;
2010-08-22 17:46:34 +02:00
else
{
$output .= '<option value="-1"> </option>' ;
foreach ( $cate_arbo as $key => $value )
{
2013-08-21 13:02:33 +02:00
if ( $cate_arbo [ $key ][ 'id' ] == $selected || ( $selected == 'auto' && count ( $cate_arbo ) == 1 ))
2010-08-22 17:46:34 +02:00
{
2010-11-01 17:00:38 +01:00
$add = 'selected="selected" ' ;
2010-08-22 17:46:34 +02:00
}
else
{
$add = '' ;
}
$output .= '<option ' . $add . 'value="' . $cate_arbo [ $key ][ 'id' ] . '">' . dol_trunc ( $cate_arbo [ $key ][ 'fulllabel' ], $maxlength , 'middle' ) . '</option>' ;
}
}
}
$output .= '</select>' ;
$output .= " \n " ;
return $output ;
}
2010-09-02 21:31:18 +02:00
2012-02-21 10:47:08 +01:00
/**
2010-09-01 09:48:33 +02:00
* Show a confirmation HTML form or AJAX popup
2011-08-12 23:29:29 +02:00
*
2012-03-12 15:09:46 +01:00
* @ param string $page Url of page to call if confirmation is OK
* @ param string $title Title
* @ param string $question Question
* @ param string $action Action
* @ param array $formquestion An array with forms complementary inputs
* @ param string $selectedchoice " " or " no " or " yes "
2013-09-06 11:51:24 +02:00
* @ param int $useajax 0 = No , 1 = Yes , 2 = Yes but submit page with & confirm = no if choice is No , 'xxx' = preoutput confirm box with div id = dialog - confirm - xxx
2012-03-12 15:09:46 +01:00
* @ param int $height Force height of box
2012-03-22 09:39:18 +01:00
* @ param int $width Force width of box
2012-03-12 15:09:46 +01:00
* @ return void
2013-09-06 11:51:24 +02:00
* @ deprecated
2010-09-01 09:48:33 +02:00
*/
2011-04-25 22:18:09 +02:00
function form_confirm ( $page , $title , $question , $action , $formquestion = '' , $selectedchoice = " " , $useajax = 0 , $height = 170 , $width = 500 )
2010-09-02 21:31:18 +02:00
{
2012-02-21 10:47:08 +01:00
print $this -> formconfirm ( $page , $title , $question , $action , $formquestion , $selectedchoice , $useajax , $height , $width );
2010-09-01 09:48:33 +02:00
}
2010-08-22 17:46:34 +02:00
/**
2013-09-06 11:51:24 +02:00
* Show a confirmation HTML form or AJAX popup .
2013-10-12 11:58:38 +02:00
* Easiest way to use this is with useajax = 1.
* If you use useajax = 'xxx' , you must also add jquery code to trigger opening of box ( with correct parameters )
* just after calling this method . For example :
2013-09-06 11:51:24 +02:00
* print '<script type="text/javascript">' . " \n " ;
* print 'jQuery(document).ready(function() {' . " \n " ;
* print 'jQuery(".xxxlink").click(function(e) { jQuery("#aparamid").val(jQuery(this).attr("rel")); jQuery("#dialog-confirm-xxx").dialog("open"); return false; });' . " \n " ;
* print '});' . " \n " ;
* print '</script>' . " \n " ;
2011-08-12 23:29:29 +02:00
*
2012-03-12 15:09:46 +01:00
* @ param string $page Url of page to call if confirmation is OK
* @ param string $title Title
* @ param string $question Question
* @ param string $action Action
* @ param array $formquestion An array with complementary inputs to add into forms : array ( array ( 'label' => , 'type' => , ))
* @ param string $selectedchoice " " or " no " or " yes "
2013-10-26 18:46:07 +02:00
* @ param int $useajax 0 = No , 1 = Yes , 2 = Yes but submit page with & confirm = no if choice is No , 'xxx' = Yes and preoutput confirm box with div id = dialog - confirm - xxx
2012-03-12 15:09:46 +01:00
* @ param int $height Force height of box
2012-03-22 09:39:18 +01:00
* @ param int $width Force width of bow
2012-04-11 13:29:23 +02:00
* @ return string HTML ajax code if a confirm ajax popup is required , Pure HTML code if it ' s an html form
2010-08-22 17:46:34 +02:00
*/
2011-04-25 16:12:03 +02:00
function formconfirm ( $page , $title , $question , $action , $formquestion = '' , $selectedchoice = " " , $useajax = 0 , $height = 170 , $width = 500 )
2010-08-22 17:46:34 +02:00
{
global $langs , $conf ;
2012-06-08 23:48:53 +02:00
global $useglobalvars ;
2010-08-22 17:46:34 +02:00
$more = '' ;
2010-09-01 09:48:33 +02:00
$formconfirm = '' ;
2012-05-23 23:23:57 +02:00
$inputok = array ();
$inputko = array ();
2010-09-02 21:31:18 +02:00
2012-11-20 12:23:32 +01:00
// Clean parameters
2012-12-01 15:45:05 +01:00
$newselectedchoice = empty ( $selectedchoice ) ? " no " : $selectedchoice ;
2012-12-07 13:48:11 +01:00
2012-07-10 22:10:12 +02:00
if ( is_array ( $formquestion ) && ! empty ( $formquestion ))
2010-08-22 17:46:34 +02:00
{
2014-01-05 18:30:35 +01:00
// First add hidden fields and value
foreach ( $formquestion as $key => $input )
{
if ( is_array ( $input ) && ! empty ( $input ))
{
if ( $input [ 'type' ] == 'hidden' )
{
$more .= '<input type="hidden" id="' . $input [ 'name' ] . '" name="' . $input [ 'name' ] . '" value="' . dol_escape_htmltag ( $input [ 'value' ]) . '">' . " \n " ;
}
}
}
// Now add questions
2012-02-21 10:47:08 +01:00
$more .= '<table class="paddingrightonly" width="100%">' . " \n " ;
2012-07-10 22:10:12 +02:00
$more .= '<tr><td colspan="3" valign="top">' . ( ! empty ( $formquestion [ 'text' ]) ? $formquestion [ 'text' ] : '' ) . '</td></tr>' . " \n " ;
2010-08-22 17:46:34 +02:00
foreach ( $formquestion as $key => $input )
{
2012-07-10 22:10:12 +02:00
if ( is_array ( $input ) && ! empty ( $input ))
2012-02-21 10:47:08 +01:00
{
2012-07-10 22:10:12 +02:00
$size = ( ! empty ( $input [ 'size' ]) ? ' size="' . $input [ 'size' ] . '"' : '' );
2012-02-21 10:47:08 +01:00
if ( $input [ 'type' ] == 'text' )
{
2012-07-10 22:10:12 +02:00
$more .= '<tr><td valign="top">' . $input [ 'label' ] . '</td><td valign="top" colspan="2" align="left"><input type="text" class="flat" id="' . $input [ 'name' ] . '" name="' . $input [ 'name' ] . '"' . $size . ' value="' . $input [ 'value' ] . '" /></td></tr>' . " \n " ;
2012-02-21 10:47:08 +01:00
}
else if ( $input [ 'type' ] == 'password' )
{
2012-07-10 22:10:12 +02:00
$more .= '<tr><td valign="top">' . $input [ 'label' ] . '</td><td valign="top" colspan="2" align="left"><input type="password" class="flat" id="' . $input [ 'name' ] . '" name="' . $input [ 'name' ] . '"' . $size . ' value="' . $input [ 'value' ] . '" /></td></tr>' . " \n " ;
2012-02-21 10:47:08 +01:00
}
else if ( $input [ 'type' ] == 'select' )
{
$more .= '<tr><td valign="top" style="padding: 4px !important;">' ;
if ( ! empty ( $input [ 'label' ])) $more .= $input [ 'label' ] . '</td><td valign="top" colspan="2" align="left" style="padding: 4px !important;">' ;
$more .= $this -> selectarray ( $input [ 'name' ], $input [ 'values' ], $input [ 'default' ], 1 );
$more .= '</td></tr>' . " \n " ;
}
else if ( $input [ 'type' ] == 'checkbox' )
{
$more .= '<tr>' ;
$more .= '<td valign="top">' . $input [ 'label' ] . ' </td><td valign="top" align="left">' ;
$more .= '<input type="checkbox" class="flat" id="' . $input [ 'name' ] . '" name="' . $input [ 'name' ] . '"' ;
if ( ! is_bool ( $input [ 'value' ]) && $input [ 'value' ] != 'false' ) $more .= ' checked="checked"' ;
if ( is_bool ( $input [ 'value' ]) && $input [ 'value' ]) $more .= ' checked="checked"' ;
2012-07-23 16:10:54 +02:00
if ( isset ( $input [ 'disabled' ])) $more .= ' disabled="disabled"' ;
2012-02-21 10:47:08 +01:00
$more .= ' /></td>' ;
$more .= '<td valign="top" align="left"> </td>' ;
$more .= '</tr>' . " \n " ;
}
else if ( $input [ 'type' ] == 'radio' )
{
$i = 0 ;
foreach ( $input [ 'values' ] as $selkey => $selval )
{
$more .= '<tr>' ;
if ( $i == 0 ) $more .= '<td valign="top">' . $input [ 'label' ] . '</td>' ;
else $more .= '<td> </td>' ;
$more .= '<td valign="top" width="20"><input type="radio" class="flat" id="' . $input [ 'name' ] . '" name="' . $input [ 'name' ] . '" value="' . $selkey . '"' ;
if ( $input [ 'disabled' ]) $more .= ' disabled="disabled"' ;
$more .= ' /></td>' ;
$more .= '<td valign="top" align="left">' ;
$more .= $selval ;
$more .= '</td></tr>' . " \n " ;
$i ++ ;
}
}
else if ( $input [ 'type' ] == 'other' )
{
$more .= '<tr><td valign="top">' ;
if ( ! empty ( $input [ 'label' ])) $more .= $input [ 'label' ] . '</td><td valign="top" colspan="2" align="left">' ;
$more .= $input [ 'value' ];
$more .= '</td></tr>' . " \n " ;
}
}
2010-08-22 17:46:34 +02:00
}
$more .= '</table>' . " \n " ;
}
2013-10-12 11:58:38 +02:00
// JQUI method dialog is broken with jmobile, we use standard HTML.
2013-10-26 18:46:07 +02:00
// Note: When using dol_use_jmobile or no js, you must also check code for button use a GET url with action=xxx and check that you also output the confirm code when action=xxx
// See page product/fiche.php for example
2013-10-12 11:58:38 +02:00
if ( ! empty ( $conf -> dol_use_jmobile )) $useajax = 0 ;
2013-10-26 18:46:07 +02:00
if ( empty ( $conf -> use_javascript_ajax )) $useajax = 0 ;
2013-08-01 04:20:08 +02:00
2013-10-26 18:46:07 +02:00
if ( $useajax )
2010-08-22 17:46:34 +02:00
{
2012-02-21 10:47:08 +01:00
$autoOpen = true ;
$dialogconfirm = 'dialog-confirm' ;
2012-06-06 23:12:33 +02:00
$button = '' ;
2014-06-09 15:21:20 +02:00
if ( ! is_numeric ( $useajax ))
2012-02-21 10:47:08 +01:00
{
$button = $useajax ;
$useajax = 1 ;
$autoOpen = false ;
$dialogconfirm .= '-' . $button ;
}
2012-10-28 02:14:08 +02:00
$pageyes = $page . ( preg_match ( '/\?/' , $page ) ? '&' : '?' ) . 'action=' . $action . '&confirm=yes' ;
$pageno = ( $useajax == 2 ? $page . ( preg_match ( '/\?/' , $page ) ? '&' : '?' ) . 'confirm=no' : '' );
2012-05-23 23:23:57 +02:00
// Add input fields into list of fields to read during submit (inputok and inputko)
2012-05-09 16:03:15 +02:00
if ( is_array ( $formquestion ))
{
foreach ( $formquestion as $key => $input )
{
2012-07-08 23:22:22 +02:00
if ( isset ( $input [ 'name' ])) array_push ( $inputok , $input [ 'name' ]);
if ( isset ( $input [ 'inputko' ]) && $input [ 'inputko' ] == 1 ) array_push ( $inputko , $input [ 'name' ]);
2012-05-09 16:03:15 +02:00
}
}
2010-08-22 17:46:34 +02:00
2012-08-16 15:46:36 +02:00
// Show JQuery confirm box. Note that global var $useglobalvars is used inside this template
2012-08-17 15:13:10 +02:00
$formconfirm .= '<div id="' . $dialogconfirm . '" title="' . dol_escape_htmltag ( $title ) . '" style="display: none;">' ;
2012-08-16 15:46:36 +02:00
if ( ! empty ( $more )) {
$formconfirm .= '<p>' . $more . '</p>' ;
}
$formconfirm .= img_help ( '' , '' ) . ' ' . $question ;
$formconfirm .= '</div>' ;
2012-08-17 15:13:10 +02:00
$formconfirm .= '<script type="text/javascript">' ;
$formconfirm .= '
$ ( function () {
$ ( " #'. $dialogconfirm .' " ) . dialog ({
2012-11-20 12:23:32 +01:00
autoOpen : '.($autoOpen ? "true" : "false").' , ' ;
if ( $newselectedchoice == 'no' )
{
$formconfirm .= '
open : function () {
$ ( this ) . parent () . find ( " button.ui-button:eq(1) " ) . focus ();
}, ' ;
}
$formconfirm .= '
2012-08-17 15:13:10 +02:00
resizable : false ,
height : " '. $height .' " ,
width : " '. $width .' " ,
modal : true ,
closeOnEscape : false ,
buttons : {
" '.dol_escape_js( $langs->transnoentities ( " Yes " )).' " : function () {
var options = " " ;
var inputok = '.json_encode($inputok).' ;
var pageyes = " '.dol_escape_js(! empty( $pageyes )? $pageyes :'').' " ;
if ( inputok . length > 0 ) {
$ . each ( inputok , function ( i , inputname ) {
var more = " " ;
if ( $ ( " # " + inputname ) . attr ( " type " ) == " checkbox " ) { more = " :checked " ; }
2013-07-10 13:10:32 +02:00
if ( $ ( " # " + inputname ) . attr ( " type " ) == " radio " ) { more = " :checked " ; }
2012-08-17 15:13:10 +02:00
var inputvalue = $ ( " # " + inputname + more ) . val ();
if ( typeof inputvalue == " undefined " ) { inputvalue = " " ; }
options += " & " + inputname + " = " + inputvalue ;
});
}
var urljump = pageyes + ( pageyes . indexOf ( " ? " ) < 0 ? " ? " : " " ) + options ;
//alert(urljump);
if ( pageyes . length > 0 ) { location . href = urljump ; }
$ ( this ) . dialog ( " close " );
},
" '.dol_escape_js( $langs->transnoentities ( " No " )).' " : function () {
var options = " " ;
var inputko = '.json_encode($inputko).' ;
var pageno = " '.dol_escape_js(! empty( $pageno )? $pageno :'').' " ;
if ( inputko . length > 0 ) {
$ . each ( inputko , function ( i , inputname ) {
var more = " " ;
if ( $ ( " # " + inputname ) . attr ( " type " ) == " checkbox " ) { more = " :checked " ; }
var inputvalue = $ ( " # " + inputname + more ) . val ();
if ( typeof inputvalue == " undefined " ) { inputvalue = " " ; }
options += " & " + inputname + " = " + inputvalue ;
});
}
var urljump = pageno + ( pageno . indexOf ( " ? " ) < 0 ? " ? " : " " ) + options ;
//alert(urljump);
if ( pageno . length > 0 ) { location . href = urljump ; }
$ ( this ) . dialog ( " close " );
}
}
});
var button = " '. $button .' " ;
2013-08-01 04:20:08 +02:00
if ( button . length > 0 ) {
2012-08-17 15:13:10 +02:00
$ ( " # " + button ) . click ( function () {
$ ( " #'. $dialogconfirm .' " ) . dialog ( " open " );
2012-11-20 12:23:32 +01:00
});
2012-08-17 15:13:10 +02:00
}
});
2012-08-16 15:46:36 +02:00
</ script > ' ;
2010-08-22 17:46:34 +02:00
}
else
{
2012-06-08 18:03:00 +02:00
$formconfirm .= " \n <!-- begin form_confirm page= " . $page . " --> \n " ;
2012-06-08 23:48:53 +02:00
2011-04-24 22:24:50 +02:00
$formconfirm .= '<form method="POST" action="' . $page . '" class="notoptoleftroright">' . " \n " ;
2010-09-01 09:48:33 +02:00
$formconfirm .= '<input type="hidden" name="action" value="' . $action . '">' ;
$formconfirm .= '<input type="hidden" name="token" value="' . $_SESSION [ 'newtoken' ] . '">' . " \n " ;
2010-08-22 17:46:34 +02:00
2010-09-01 09:48:33 +02:00
$formconfirm .= '<table width="100%" class="valid">' . " \n " ;
2010-08-22 17:46:34 +02:00
2012-05-09 16:03:15 +02:00
// Line title
2010-09-01 09:48:33 +02:00
$formconfirm .= '<tr class="validtitre"><td class="validtitre" colspan="3">' . img_picto ( '' , 'recent' ) . ' ' . $title . '</td></tr>' . " \n " ;
2010-08-22 17:46:34 +02:00
2012-05-09 16:03:15 +02:00
// Line form fields
2010-12-13 19:40:04 +01:00
if ( $more )
{
$formconfirm .= '<tr class="valid"><td class="valid" colspan="3">' . " \n " ;
$formconfirm .= $more ;
$formconfirm .= '</td></tr>' . " \n " ;
}
2010-08-22 17:46:34 +02:00
2012-05-09 16:03:15 +02:00
// Line with question
2010-09-01 09:48:33 +02:00
$formconfirm .= '<tr class="valid">' ;
$formconfirm .= '<td class="valid">' . $question . '</td>' ;
$formconfirm .= '<td class="valid">' ;
$formconfirm .= $this -> selectyesno ( " confirm " , $newselectedchoice );
$formconfirm .= '</td>' ;
$formconfirm .= '<td class="valid" align="center"><input class="button" type="submit" value="' . $langs -> trans ( " Validate " ) . '"></td>' ;
$formconfirm .= '</tr>' . " \n " ;
2010-08-22 17:46:34 +02:00
2010-09-01 09:48:33 +02:00
$formconfirm .= '</table>' . " \n " ;
2010-08-22 17:46:34 +02:00
2010-09-01 09:48:33 +02:00
$formconfirm .= " </form> \n " ;
$formconfirm .= '<br>' ;
2012-06-08 23:48:53 +02:00
2012-06-08 18:03:00 +02:00
$formconfirm .= " <!-- end form_confirm --> \n " ;
2010-08-22 17:46:34 +02:00
}
2010-09-01 09:48:33 +02:00
return $formconfirm ;
2010-08-22 17:46:34 +02:00
}
/**
2011-05-07 13:47:38 +02:00
* Show a form to select a project
2011-08-12 23:29:29 +02:00
*
2011-10-09 20:12:05 +02:00
* @ param int $page Page
2014-08-06 16:46:04 +02:00
* @ param int $socid Id third party ( - 1 = all , 0 = only projects not linked to a third party , id = projects not linked or linked to third party id )
2011-10-09 20:12:05 +02:00
* @ param int $selected Id pre - selected project
* @ param string $htmlname Name of select field
2011-09-15 01:15:38 +02:00
* @ return void
2010-08-22 17:46:34 +02:00
*/
function form_project ( $page , $socid , $selected = '' , $htmlname = 'projectid' )
{
global $langs ;
2012-08-22 23:11:24 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/project.lib.php' ;
2013-06-14 22:33:01 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formprojet.class.php' ;
2013-06-23 18:33:03 +02:00
2013-06-14 22:33:01 +02:00
$formproject = new FormProjets ( $this -> db );
2010-08-22 17:46:34 +02:00
$langs -> load ( " project " );
if ( $htmlname != " none " )
{
print '<form method="post" action="' . $page . '">' ;
print '<input type="hidden" name="action" value="classin">' ;
print '<input type="hidden" name="token" value="' . $_SESSION [ 'newtoken' ] . '">' ;
print '<table class="nobordernopadding" cellpadding="0" cellspacing="0">' ;
print '<tr><td>' ;
//print "$socid,$selected,$htmlname";
2013-06-14 22:33:01 +02:00
$formproject -> select_projects ( $socid , $selected , $htmlname );
2010-08-22 17:46:34 +02:00
print '</td>' ;
print '<td align="left"><input type="submit" class="button" value="' . $langs -> trans ( " Modify " ) . '"></td>' ;
print '</tr></table></form>' ;
}
else
{
2011-10-09 20:12:05 +02:00
if ( $selected )
{
2010-08-22 17:46:34 +02:00
$projet = new Project ( $this -> db );
$projet -> fetch ( $selected );
//print '<a href="'.DOL_URL_ROOT.'/projet/fiche.php?id='.$selected.'">'.$projet->title.'</a>';
2011-10-09 20:12:05 +02:00
print $projet -> getNomUrl ( 0 , '' , 1 );
}
else
{
2010-08-22 17:46:34 +02:00
print " " ;
}
}
}
/**
2012-03-12 15:09:46 +01:00
* Show a form to select payment conditions
2011-08-12 23:29:29 +02:00
*
2012-03-12 15:09:46 +01:00
* @ param int $page Page
* @ param string $selected Id condition pre - selectionne
* @ param string $htmlname Name of select html field
* @ param int $addempty Ajoute entree vide
* @ return void
2010-08-22 17:46:34 +02:00
*/
function form_conditions_reglement ( $page , $selected = '' , $htmlname = 'cond_reglement_id' , $addempty = 0 )
{
global $langs ;
if ( $htmlname != " none " )
{
print '<form method="post" action="' . $page . '">' ;
print '<input type="hidden" name="action" value="setconditions">' ;
print '<input type="hidden" name="token" value="' . $_SESSION [ 'newtoken' ] . '">' ;
print '<table class="nobordernopadding" cellpadding="0" cellspacing="0">' ;
print '<tr><td>' ;
$this -> select_conditions_paiements ( $selected , $htmlname , - 1 , $addempty );
print '</td>' ;
print '<td align="left"><input type="submit" class="button" value="' . $langs -> trans ( " Modify " ) . '"></td>' ;
print '</tr></table></form>' ;
}
else
{
if ( $selected )
{
$this -> load_cache_conditions_paiements ();
print $this -> cache_conditions_paiements [ $selected ][ 'label' ];
} else {
print " " ;
}
}
}
2012-02-21 10:47:08 +01:00
/**
* Show a form to select a delivery delay
2011-08-12 23:29:29 +02:00
*
2012-02-21 10:47:08 +01:00
* @ param int $page Page
* @ param string $selected Id condition pre - selectionne
* @ param string $htmlname Name of select html field
* @ param int $addempty Ajoute entree vide
* @ return void
2011-04-01 12:04:49 +02:00
*/
2011-04-25 11:27:25 +02:00
function form_availability ( $page , $selected = '' , $htmlname = 'availability' , $addempty = 0 )
2011-04-01 12:04:49 +02:00
{
global $langs ;
if ( $htmlname != " none " )
{
print '<form method="post" action="' . $page . '">' ;
2011-04-01 12:49:57 +02:00
print '<input type="hidden" name="action" value="setavailability">' ;
2011-04-01 12:04:49 +02:00
print '<input type="hidden" name="token" value="' . $_SESSION [ 'newtoken' ] . '">' ;
print '<table class="nobordernopadding" cellpadding="0" cellspacing="0">' ;
print '<tr><td>' ;
2014-04-02 14:53:42 +02:00
$this -> selectAvailabilityDelay ( $selected , $htmlname , - 1 , $addempty );
2011-04-01 12:04:49 +02:00
print '</td>' ;
print '<td align="left"><input type="submit" class="button" value="' . $langs -> trans ( " Modify " ) . '"></td>' ;
print '</tr></table></form>' ;
}
else
{
if ( $selected )
{
2011-04-01 12:49:57 +02:00
$this -> load_cache_availability ();
print $this -> cache_availability [ $selected ][ 'label' ];
2011-04-01 12:04:49 +02:00
} else {
print " " ;
}
}
}
2012-02-21 10:47:08 +01:00
/**
2014-04-02 14:53:42 +02:00
* Output HTML form to select list of input reason ( events that triggered an object creation , like after sending an emailing , making an advert , ... )
* List found into table c_input_reason loaded by loadCacheInputReason
2011-08-12 23:29:29 +02:00
*
2012-03-12 15:09:46 +01:00
* @ param string $page Page
* @ param string $selected Id condition pre - selectionne
* @ param string $htmlname Name of select html field
* @ param int $addempty Add empty entry
* @ return void
2011-04-18 22:56:10 +02:00
*/
2014-04-02 14:53:42 +02:00
function formInputReason ( $page , $selected = '' , $htmlname = 'demandreason' , $addempty = 0 )
2011-04-18 22:56:10 +02:00
{
global $langs ;
if ( $htmlname != " none " )
{
print '<form method="post" action="' . $page . '">' ;
2011-04-26 22:59:45 +02:00
print '<input type="hidden" name="action" value="setdemandreason">' ;
2011-04-18 22:56:10 +02:00
print '<input type="hidden" name="token" value="' . $_SESSION [ 'newtoken' ] . '">' ;
print '<table class="nobordernopadding" cellpadding="0" cellspacing="0">' ;
print '<tr><td>' ;
2014-04-02 14:53:42 +02:00
$this -> selectInputReason ( $selected , $htmlname , - 1 , $addempty );
2011-04-18 22:56:10 +02:00
print '</td>' ;
print '<td align="left"><input type="submit" class="button" value="' . $langs -> trans ( " Modify " ) . '"></td>' ;
print '</tr></table></form>' ;
}
else
{
if ( $selected )
{
2014-04-02 14:53:42 +02:00
$this -> loadCacheInputReason ();
2011-05-07 13:36:47 +02:00
foreach ( $this -> cache_demand_reason as $key => $val )
{
if ( $val [ 'id' ] == $selected )
{
print $val [ 'label' ];
break ;
}
}
2011-04-18 22:56:10 +02:00
} else {
print " " ;
}
}
}
2011-05-07 13:47:38 +02:00
2010-08-22 17:46:34 +02:00
/**
2014-03-29 04:26:44 +01:00
* Show a form + html select a date
2011-08-12 23:29:29 +02:00
*
2012-03-12 15:09:46 +01:00
* @ param string $page Page
* @ param string $selected Date preselected
2014-03-29 04:26:44 +01:00
* @ param string $htmlname Html name of date input fields or 'none'
2012-12-01 15:45:05 +01:00
* @ param int $displayhour Display hour selector
* @ param int $displaymin Display minutes selector
2011-09-15 01:15:38 +02:00
* @ return void
2014-03-29 04:26:44 +01:00
* @ see select_date
2010-08-22 17:46:34 +02:00
*/
2014-03-29 04:26:44 +01:00
function form_date ( $page , $selected , $htmlname , $displayhour = 0 , $displaymin = 0 )
2010-08-22 17:46:34 +02:00
{
global $langs ;
if ( $htmlname != " none " )
{
print '<form method="post" action="' . $page . '" name="form' . $htmlname . '">' ;
print '<input type="hidden" name="action" value="set' . $htmlname . '">' ;
print '<input type="hidden" name="token" value="' . $_SESSION [ 'newtoken' ] . '">' ;
print '<table class="nobordernopadding" cellpadding="0" cellspacing="0">' ;
print '<tr><td>' ;
2012-12-01 15:45:05 +01:00
print $this -> select_date ( $selected , $htmlname , $displayhour , $displaymin , 1 , 'form' . $htmlname );
2010-08-22 17:46:34 +02:00
print '</td>' ;
print '<td align="left"><input type="submit" class="button" value="' . $langs -> trans ( " Modify " ) . '"></td>' ;
print '</tr></table></form>' ;
}
else
{
if ( $selected )
{
$this -> load_cache_types_paiements ();
print $this -> cache_types_paiements [ $selected ][ 'label' ];
} else {
print " " ;
}
}
}
/**
2012-03-12 15:09:46 +01:00
* Show a select form to choose a user
2011-08-12 23:29:29 +02:00
*
2012-03-12 15:09:46 +01:00
* @ param string $page Page
* @ param string $selected Id of user preselected
* @ param string $htmlname Name of input html field
* @ param array $exclude List of users id to exclude
* @ param array $include List of users id to include
* @ return void
2010-08-22 17:46:34 +02:00
*/
function form_users ( $page , $selected = '' , $htmlname = 'userid' , $exclude = '' , $include = '' )
{
global $langs ;
if ( $htmlname != " none " )
{
2010-09-07 03:32:20 +02:00
print '<form method="POST" action="' . $page . '" name="form' . $htmlname . '">' ;
2010-08-22 17:46:34 +02:00
print '<input type="hidden" name="action" value="set' . $htmlname . '">' ;
print '<input type="hidden" name="token" value="' . $_SESSION [ 'newtoken' ] . '">' ;
print '<table class="nobordernopadding" cellpadding="0" cellspacing="0">' ;
print '<tr><td>' ;
print $this -> select_users ( $selected , $htmlname , 1 , $exclude , 0 , $include );
print '</td>' ;
print '<td align="left"><input type="submit" class="button" value="' . $langs -> trans ( " Modify " ) . '"></td>' ;
print '</tr></table></form>' ;
}
else
{
if ( $selected )
{
2012-08-22 23:11:24 +02:00
require_once DOL_DOCUMENT_ROOT . '/user/class/user.class.php' ;
2010-08-22 17:46:34 +02:00
//$this->load_cache_contacts();
//print $this->cache_contacts[$selected];
$theuser = new User ( $this -> db );
$theuser -> fetch ( $selected );
print $theuser -> getNomUrl ( 1 );
} else {
print " " ;
}
}
}
/**
2011-08-12 23:29:29 +02:00
* Affiche formulaire de selection des modes de reglement
*
2012-03-12 15:09:46 +01:00
* @ param string $page Page
* @ param int $selected Id mode pre - selectionne
* @ param string $htmlname Name of select html field
2011-09-15 01:15:38 +02:00
* @ return void
2010-08-22 17:46:34 +02:00
*/
function form_modes_reglement ( $page , $selected = '' , $htmlname = 'mode_reglement_id' )
{
global $langs ;
if ( $htmlname != " none " )
{
2010-09-07 03:32:20 +02:00
print '<form method="POST" action="' . $page . '">' ;
2010-08-22 17:46:34 +02:00
print '<input type="hidden" name="action" value="setmode">' ;
print '<input type="hidden" name="token" value="' . $_SESSION [ 'newtoken' ] . '">' ;
print '<table class="nobordernopadding" cellpadding="0" cellspacing="0">' ;
print '<tr><td>' ;
$this -> select_types_paiements ( $selected , $htmlname );
print '</td>' ;
print '<td align="left"><input type="submit" class="button" value="' . $langs -> trans ( " Modify " ) . '"></td>' ;
print '</tr></table></form>' ;
}
else
{
if ( $selected )
{
$this -> load_cache_types_paiements ();
print $this -> cache_types_paiements [ $selected ][ 'label' ];
} else {
print " " ;
}
}
}
/**
2011-11-13 00:49:40 +01:00
* Show a select box with available absolute discounts
2011-08-12 23:29:29 +02:00
*
2011-11-13 00:49:40 +01:00
* @ param string $page Page URL where form is shown
* @ param int $selected Value pre - selected
2012-03-19 17:18:11 +01:00
* @ param string $htmlname Nom du formulaire select . Si 'none' , non modifiable . Example 'remise_id' .
2011-11-13 00:49:40 +01:00
* @ param int $socid Third party id
* @ param float $amount Total amount available
* @ param string $filter SQL filter on discounts
* @ param int $maxvalue Max value for lines that can be selected
2011-11-16 18:58:11 +01:00
* @ param string $more More string to add
2011-11-13 00:49:40 +01:00
* @ return void
2010-08-22 17:46:34 +02:00
*/
2012-03-19 17:18:11 +01:00
function form_remise_dispo ( $page , $selected , $htmlname , $socid , $amount , $filter = '' , $maxvalue = 0 , $more = '' )
2010-08-22 17:46:34 +02:00
{
global $conf , $langs ;
if ( $htmlname != " none " )
{
print '<form method="post" action="' . $page . '">' ;
print '<input type="hidden" name="action" value="setabsolutediscount">' ;
print '<input type="hidden" name="token" value="' . $_SESSION [ 'newtoken' ] . '">' ;
print '<table class="nobordernopadding" cellpadding="0" cellspacing="0">' ;
2013-04-25 01:13:13 +02:00
print '<tr><td class="nowrap">' ;
2012-01-08 23:43:32 +01:00
if ( ! empty ( $conf -> global -> FACTURE_DEPOSITS_ARE_JUST_PAYMENTS ))
{
2014-04-06 21:17:35 +02:00
if ( ! $filter || $filter == " fk_facture_source IS NULL " ) print $langs -> trans ( " CompanyHasAbsoluteDiscount " , price ( $amount , 0 , $langs , 0 , 0 , - 1 , $conf -> currency )) . ': ' ; // If we want deposit to be substracted to payments only and not to total of final invoice
else print $langs -> trans ( " CompanyHasCreditNote " , price ( $amount , 0 , $langs , 0 , 0 , - 1 , $conf -> currency )) . ': ' ;
2012-01-08 23:43:32 +01:00
}
else
{
2014-04-06 21:17:35 +02:00
if ( ! $filter || $filter == " fk_facture_source IS NULL OR (fk_facture_source IS NOT NULL AND description='(DEPOSIT)') " ) print $langs -> trans ( " CompanyHasAbsoluteDiscount " , price ( $amount , 0 , $langs , 0 , 0 , - 1 , $conf -> currency )) . ': ' ;
else print $langs -> trans ( " CompanyHasCreditNote " , price ( $amount , 0 , $langs , 0 , 0 , - 1 , $conf -> currency )) . ': ' ;
2012-01-08 23:43:32 +01:00
}
2010-08-22 17:46:34 +02:00
$newfilter = 'fk_facture IS NULL AND fk_facture_line IS NULL' ; // Remises disponibles
2011-11-16 18:58:11 +01:00
if ( $filter ) $newfilter .= ' AND (' . $filter . ')' ;
2011-11-13 00:49:40 +01:00
$nbqualifiedlines = $this -> select_remises ( $selected , $htmlname , $newfilter , $socid , $maxvalue );
2010-08-22 17:46:34 +02:00
print '</td>' ;
2013-04-25 01:13:13 +02:00
print '<td class="nowrap">' ;
2010-08-22 17:46:34 +02:00
if ( $nbqualifiedlines > 0 )
{
2012-10-13 17:00:38 +02:00
print ' <input type="submit" class="button" value="' . dol_escape_htmltag ( $langs -> trans ( " UseLine " )) . '"' ;
if ( $filter && $filter != " fk_facture_source IS NULL OR (fk_facture_source IS NOT NULL AND description='(DEPOSIT)') " ) print ' title="' . $langs -> trans ( " UseCreditNoteInInvoicePayment " ) . '"' ;
print '>' ;
2010-08-22 17:46:34 +02:00
}
2011-02-19 13:15:17 +01:00
if ( $more ) print $more ;
2010-08-22 17:46:34 +02:00
print '</td>' ;
print '</tr></table></form>' ;
}
else
{
if ( $selected )
{
print $selected ;
}
else
{
print " 0 " ;
}
}
}
/**
2011-08-12 23:29:29 +02:00
* Affiche formulaire de selection des contacts
*
2012-03-22 09:39:18 +01:00
* @ param string $page Page
* @ param Societe $societe Third party
* @ param int $selected Id contact pre - selectionne
* @ param string $htmlname Nom du formulaire select
2011-09-15 01:15:38 +02:00
* @ return void
2010-08-22 17:46:34 +02:00
*/
function form_contacts ( $page , $societe , $selected = '' , $htmlname = 'contactidp' )
{
2014-04-23 14:31:39 +02:00
global $langs , $conf ;
2011-02-13 17:01:00 +01:00
2010-08-22 17:46:34 +02:00
if ( $htmlname != " none " )
{
print '<form method="post" action="' . $page . '">' ;
print '<input type="hidden" name="action" value="set_contact">' ;
print '<input type="hidden" name="token" value="' . $_SESSION [ 'newtoken' ] . '">' ;
print '<table class="nobordernopadding" cellpadding="0" cellspacing="0">' ;
print '<tr><td>' ;
$num = $this -> select_contacts ( $societe -> id , $selected , $htmlname );
if ( $num == 0 )
{
2012-03-14 15:04:55 +01:00
$addcontact = ( ! empty ( $conf -> global -> SOCIETE_ADDRESSES_MANAGEMENT ) ? $langs -> trans ( " AddContact " ) : $langs -> trans ( " AddContactAddress " ));
2010-08-22 17:46:34 +02:00
print '<font class="error">Cette societe n\'a pas de contact, veuillez en cr<63> er un avant de faire votre proposition commerciale</font><br>' ;
2012-03-14 15:04:55 +01:00
print '<a href="' . DOL_URL_ROOT . '/contact/fiche.php?socid=' . $societe -> id . '&action=create&backtoreferer=1">' . $addcontact . '</a>' ;
2010-08-22 17:46:34 +02:00
}
print '</td>' ;
print '<td align="left"><input type="submit" class="button" value="' . $langs -> trans ( " Modify " ) . '"></td>' ;
print '</tr></table></form>' ;
}
else
{
if ( $selected )
{
2012-08-22 23:11:24 +02:00
require_once DOL_DOCUMENT_ROOT . '/contact/class/contact.class.php' ;
2010-08-22 17:46:34 +02:00
//$this->load_cache_contacts();
//print $this->cache_contacts[$selected];
$contact = new Contact ( $this -> db );
$contact -> fetch ( $selected );
print $contact -> getFullName ( $langs );
} else {
print " " ;
}
}
}
2011-07-04 13:33:22 +02:00
2012-02-21 10:47:08 +01:00
/**
2012-10-27 00:23:16 +02:00
* Output html select to select thirdparty
2011-08-12 23:29:29 +02:00
*
2012-10-27 00:23:16 +02:00
* @ param string $page Page
* @ param string $selected Id preselected
* @ param string $htmlname Name of HTML select
2014-03-05 09:57:36 +01:00
* @ param string $filter optional filters criteras
2012-07-18 15:22:45 +02:00
* @ param int $showempty Add an empty field
* @ param int $showtype Show third party type in combolist ( customer , prospect or supplier )
* @ param int $forcecombo Force to use combo box
2014-02-04 20:49:07 +01:00
* @ param array $events Event options . Example : array ( array ( 'method' => 'getContacts' , 'url' => dol_buildpath ( '/core/ajax/contacts.php' , 1 ), 'htmlname' => 'contactid' , 'params' => array ( 'add-customer-contact' => 'disabled' )))
2012-10-27 00:23:16 +02:00
* @ return void
2011-06-29 17:48:02 +02:00
*/
2014-02-04 20:49:07 +01:00
function form_thirdparty ( $page , $selected = '' , $htmlname = 'socid' , $filter = '' , $showempty = 0 , $showtype = 0 , $forcecombo = 0 , $events = array ())
2011-06-29 17:48:02 +02:00
{
global $langs ;
if ( $htmlname != " none " )
{
print '<form method="post" action="' . $page . '">' ;
print '<input type="hidden" name="action" value="set_thirdparty">' ;
print '<input type="hidden" name="token" value="' . $_SESSION [ 'newtoken' ] . '">' ;
print '<table class="nobordernopadding" cellpadding="0" cellspacing="0">' ;
print '<tr><td>' ;
2014-02-04 20:49:07 +01:00
print $this -> select_company ( $selected , $htmlname , $filter , $showempty , $showtype , $forcecombo , $events );
2011-06-29 17:48:02 +02:00
print '</td>' ;
print '<td align="left"><input type="submit" class="button" value="' . $langs -> trans ( " Modify " ) . '"></td>' ;
print '</tr></table></form>' ;
}
else
{
if ( $selected )
{
2012-08-22 23:11:24 +02:00
require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php' ;
2011-06-29 17:48:02 +02:00
$soc = new Societe ( $this -> db );
$soc -> fetch ( $selected );
print $soc -> getNomUrl ( $langs );
2012-02-20 12:41:12 +01:00
}
else
{
2011-06-29 17:48:02 +02:00
print " " ;
}
}
}
2010-08-22 17:46:34 +02:00
2010-10-21 15:34:31 +02:00
/**
* Retourne la liste des devises , dans la langue de l ' utilisateur
2011-08-12 23:29:29 +02:00
*
2012-03-12 15:09:46 +01:00
* @ param string $selected preselected currency code
* @ param string $htmlname name of HTML select list
2011-09-15 01:15:38 +02:00
* @ return void
2010-10-21 15:34:31 +02:00
*/
function select_currency ( $selected = '' , $htmlname = 'currency_id' )
{
2012-02-21 10:47:08 +01:00
print $this -> selectcurrency ( $selected , $htmlname );
2010-10-21 15:34:31 +02:00
}
2012-03-15 22:51:02 +01:00
2010-08-22 17:46:34 +02:00
/**
2012-03-12 15:09:46 +01:00
* Retourne la liste des devises , dans la langue de l ' utilisateur
2011-08-12 23:29:29 +02:00
*
2012-03-12 15:09:46 +01:00
* @ param string $selected preselected currency code
* @ param string $htmlname name of HTML select list
2012-03-15 22:51:02 +01:00
* @ return void
2010-08-22 17:46:34 +02:00
*/
2014-04-02 14:53:42 +02:00
function selectCurrency ( $selected = '' , $htmlname = 'currency_id' )
2010-08-22 17:46:34 +02:00
{
global $conf , $langs , $user ;
2011-03-19 03:17:05 +01:00
2014-05-14 12:19:45 +02:00
$langs -> loadCacheCurrencies ( '' );
2010-10-22 10:11:51 +02:00
2010-10-21 15:34:31 +02:00
$out = '' ;
2010-08-22 17:46:34 +02:00
if ( $selected == 'euro' || $selected == 'euros' ) $selected = 'EUR' ; // Pour compatibilite
2014-07-12 14:45:09 +02:00
$out .= '<select class="flat" name="' . $htmlname . '" id="' . $htmlname . '">' ;
2013-01-28 14:57:37 +01:00
foreach ( $langs -> cache_currencies as $code_iso => $currency )
2012-03-05 15:50:47 +01:00
{
2012-03-07 00:28:10 +01:00
if ( $selected && $selected == $code_iso )
2012-03-05 15:50:47 +01:00
{
2012-03-07 00:28:10 +01:00
$out .= '<option value="' . $code_iso . '" selected="selected">' ;
2012-03-05 15:50:47 +01:00
}
else
{
2012-03-07 00:28:10 +01:00
$out .= '<option value="' . $code_iso . '">' ;
2012-03-05 15:50:47 +01:00
}
2012-03-08 11:49:38 +01:00
$out .= $currency [ 'label' ];
2013-01-18 15:57:11 +01:00
$out .= ' (' . $langs -> getCurrencySymbol ( $code_iso ) . ')' ;
2012-03-05 15:50:47 +01:00
$out .= '</option>' ;
}
$out .= '</select>' ;
2014-02-05 17:53:30 +01:00
if ( $user -> admin ) $out .= info_admin ( $langs -> trans ( " YouCanChangeValuesForThisListFromDictionarySetup " ), 1 );
2012-03-05 15:50:47 +01:00
return $out ;
2010-08-22 17:46:34 +02:00
}
2012-03-15 22:51:02 +01:00
2012-07-02 19:30:37 +02:00
/**
2012-03-15 11:01:29 +01:00
* Load into the cache vat rates of a country
*
2012-07-02 19:30:37 +02:00
* @ param string $country_code Country code
* @ return int Nb of loaded lines , 0 if already loaded , < 0 if KO
2012-03-15 11:01:29 +01:00
*/
2012-07-02 19:30:37 +02:00
function load_cache_vatrates ( $country_code )
2012-04-11 16:26:45 +02:00
{
global $langs ;
2012-05-23 23:23:57 +02:00
2012-07-02 19:30:37 +02:00
$num = count ( $this -> cache_vatrates );
2012-05-22 18:35:14 +02:00
if ( $num > 0 ) return $num ; // Cache deja charge
2012-03-15 22:51:02 +01:00
2012-07-02 19:30:37 +02:00
$sql = " SELECT DISTINCT t.taux, t.recuperableonly " ;
2014-08-10 13:37:39 +02:00
$sql .= " FROM " . MAIN_DB_PREFIX . " c_tva as t, " . MAIN_DB_PREFIX . " c_country as c " ;
$sql .= " WHERE t.fk_pays = c.rowid " ;
2012-07-02 19:30:37 +02:00
$sql .= " AND t.active = 1 " ;
2014-08-10 13:37:39 +02:00
$sql .= " AND c.code IN ( " . $country_code . " ) " ;
2012-07-02 19:30:37 +02:00
$sql .= " ORDER BY t.taux ASC, t.recuperableonly ASC " ;
$resql = $this -> db -> query ( $sql );
if ( $resql )
{
$num = $this -> db -> num_rows ( $resql );
if ( $num )
{
for ( $i = 0 ; $i < $num ; $i ++ )
2012-03-15 11:01:29 +01:00
{
$obj = $this -> db -> fetch_object ( $resql );
$this -> cache_vatrates [ $i ][ 'txtva' ] = $obj -> taux ;
$this -> cache_vatrates [ $i ][ 'libtva' ] = $obj -> taux . '%' ;
$this -> cache_vatrates [ $i ][ 'nprtva' ] = $obj -> recuperableonly ;
}
2012-03-15 22:51:02 +01:00
2012-03-15 11:01:29 +01:00
return $num ;
}
else
{
2012-04-20 15:48:48 +02:00
$this -> error = '<font class="error">' . $langs -> trans ( " ErrorNoVATRateDefinedForSellerCountry " , $country_code ) . '</font>' ;
2012-03-15 11:01:29 +01:00
return - 1 ;
}
}
else
{
$this -> error = '<font class="error">' . $this -> db -> error () . '</font>' ;
return - 2 ;
2012-07-02 19:30:37 +02:00
}
2012-03-15 11:01:29 +01:00
}
2010-08-22 17:46:34 +02:00
/**
2012-03-12 15:09:46 +01:00
* Output an HTML select vat rate
2011-08-12 23:29:29 +02:00
*
2012-03-12 15:09:46 +01:00
* @ param string $htmlname Nom champ html
* @ param float $selectedrate Forcage du taux tva pre - selectionne . Mettre '' pour aucun forcage .
* @ param Societe $societe_vendeuse Objet societe vendeuse
* @ param Societe $societe_acheteuse Objet societe acheteuse
* @ param int $idprod Id product
* @ param int $info_bits Miscellaneous information on line ( 1 for NPR )
* @ param int $type '' = Unknown , 0 = Product , 1 = Service ( Used if idprod not defined )
* Si vendeur non assujeti a TVA , TVA par defaut = 0. Fin de regle .
* Si le ( pays vendeur = pays acheteur ) alors la TVA par defaut = TVA du produit vendu . Fin de regle .
* Si ( vendeur et acheteur dans Communaute europeenne ) et bien vendu = moyen de transports neuf ( auto , bateau , avion ), TVA par defaut = 0 ( La TVA doit etre paye par l 'acheteur au centre d' impots de son pays et non au vendeur ) . Fin de regle .
2013-10-22 00:30:55 +02:00
* Si vendeur et acheteur dans Communauté européenne et acheteur = particulier alors TVA par défaut = TVA du produit vendu . Fin de règle .
* Si vendeur et acheteur dans Communauté européenne et acheteur = entreprise alors TVA par défaut = 0. Fin de règle .
2012-03-12 15:09:46 +01:00
* Sinon la TVA proposee par defaut = 0. Fin de regle .
2012-03-15 16:52:18 +01:00
* @ param bool $options_only Return options only ( for ajax treatment )
2012-03-12 15:09:46 +01:00
* @ return void
2010-08-22 17:46:34 +02:00
*/
2012-03-15 16:52:18 +01:00
function load_tva ( $htmlname = 'tauxtva' , $selectedrate = '' , $societe_vendeuse = '' , $societe_acheteuse = '' , $idprod = 0 , $info_bits = 0 , $type = '' , $options_only = false )
2010-08-22 17:46:34 +02:00
{
global $langs , $conf , $mysoc ;
$return = '' ;
$txtva = array ();
$libtva = array ();
$nprtva = array ();
// Define defaultnpr and defaultttx
$defaultnpr = ( $info_bits & 0x01 );
$defaultnpr = ( preg_match ( '/\*/' , $selectedrate ) ? 1 : $defaultnpr );
$defaulttx = str_replace ( '*' , '' , $selectedrate );
2010-09-15 15:29:17 +02:00
// Check parameters
2011-12-29 18:07:41 +01:00
if ( is_object ( $societe_vendeuse ) && ! $societe_vendeuse -> country_code )
2010-08-22 17:46:34 +02:00
{
if ( $societe_vendeuse -> id == $mysoc -> id )
{
$return .= '<font class="error">' . $langs -> trans ( " ErrorYourCountryIsNotDefined " ) . '</div>' ;
}
else
{
$return .= '<font class="error">' . $langs -> trans ( " ErrorSupplierCountryIsNotDefined " ) . '</div>' ;
}
return $return ;
}
2010-09-15 15:29:17 +02:00
//var_dump($societe_acheteuse);
2011-12-29 18:07:41 +01:00
//print "name=$name, selectedrate=$selectedrate, seller=".$societe_vendeuse->country_code." buyer=".$societe_acheteuse->country_code." buyer is company=".$societe_acheteuse->isACompany()." idprod=$idprod, info_bits=$info_bits type=$type";
2010-09-15 15:29:17 +02:00
//exit;
2013-01-13 18:53:52 +01:00
// Define list of countries to use to search VAT rates to show
2014-08-10 13:37:39 +02:00
// First we defined code_country to use to find list
2010-08-22 17:46:34 +02:00
if ( is_object ( $societe_vendeuse ))
{
2014-08-10 13:37:39 +02:00
$code_country = " ' " . $societe_vendeuse -> country_code . " ' " ;
2010-09-15 15:29:17 +02:00
}
else
2013-01-13 18:53:52 +01:00
{
2014-08-10 13:37:39 +02:00
$code_country = " ' " . $mysoc -> country_code . " ' " ; // Pour compatibilite ascendente
2010-09-15 15:29:17 +02:00
}
2010-09-15 16:11:43 +02:00
if ( ! empty ( $conf -> global -> SERVICE_ARE_ECOMMERCE_200238EC )) // If option to have vat for end customer for services is on
2010-09-15 15:29:17 +02:00
{
2013-01-13 18:53:52 +01:00
if ( ! $societe_vendeuse -> isInEEC () && ( ! is_object ( $societe_acheteuse ) || ( $societe_acheteuse -> isInEEC () && ! $societe_acheteuse -> isACompany ())))
2010-09-15 15:51:31 +02:00
{
2010-09-15 16:11:43 +02:00
// We also add the buyer
if ( is_numeric ( $type ))
2010-09-15 15:51:31 +02:00
{
2010-09-15 16:11:43 +02:00
if ( $type == 1 ) // We know product is a service
{
2014-08-10 13:37:39 +02:00
$code_country .= " ,' " . $societe_acheteuse -> country_code . " ' " ;
2010-09-15 16:11:43 +02:00
}
2010-09-15 15:51:31 +02:00
}
2010-09-15 16:11:43 +02:00
else if ( ! $idprod ) // We don't know type of product
2010-09-15 15:29:17 +02:00
{
2014-08-10 13:37:39 +02:00
$code_country .= " ,' " . $societe_acheteuse -> country_code . " ' " ;
2010-09-15 15:29:17 +02:00
}
2010-09-15 16:11:43 +02:00
else
{
$prodstatic = new Product ( $this -> db );
$prodstatic -> fetch ( $idprod );
if ( $prodstatic -> type == 1 ) // We know product is a service
{
2014-08-10 13:37:39 +02:00
$code_country .= " ,' " . $societe_acheteuse -> country_code . " ' " ;
2010-09-15 16:11:43 +02:00
}
}
2010-08-22 17:46:34 +02:00
}
}
2012-03-15 22:51:02 +01:00
2010-09-15 15:29:17 +02:00
// Now we get list
2014-08-10 13:37:39 +02:00
$num = $this -> load_cache_vatrates ( $code_country );
2012-03-15 11:01:29 +01:00
if ( $num > 0 )
{
2012-07-02 19:30:37 +02:00
// Definition du taux a pre-selectionner (si defaulttx non force et donc vaut -1 ou '')
if ( $defaulttx < 0 || dol_strlen ( $defaulttx ) == 0 )
{
$defaulttx = get_default_tva ( $societe_vendeuse , $societe_acheteuse , $idprod );
$defaultnpr = get_default_npr ( $societe_vendeuse , $societe_acheteuse , $idprod );
}
// Si taux par defaut n'a pu etre determine, on prend dernier de la liste.
// Comme ils sont tries par ordre croissant, dernier = plus eleve = taux courant
if ( $defaulttx < 0 || dol_strlen ( $defaulttx ) == 0 )
{
2013-09-28 13:24:58 +02:00
if ( empty ( $conf -> global -> MAIN_VAT_DEFAULT_IF_AUTODETECT_FAILS )) $defaulttx = $this -> cache_vatrates [ $num - 1 ][ 'txtva' ];
else $defaulttx = $conf -> global -> MAIN_VAT_DEFAULT_IF_AUTODETECT_FAILS ;
2012-03-15 11:01:29 +01:00
}
2012-03-15 22:51:02 +01:00
2012-08-31 01:00:18 +02:00
// Disabled if seller is not subject to VAT
2012-08-30 22:14:18 +02:00
$disabled = false ; $title = '' ;
2013-10-12 11:58:38 +02:00
if ( is_object ( $societe_vendeuse ) && $societe_vendeuse -> id == $mysoc -> id && $societe_vendeuse -> tva_assuj == " 0 " )
2013-09-28 13:24:58 +02:00
{
2012-08-30 22:14:18 +02:00
$title = ' title="' . $langs -> trans ( 'VATIsNotUsed' ) . '"' ;
$disabled = true ;
}
if ( ! $options_only ) $return .= '<select class="flat" id="' . $htmlname . '" name="' . $htmlname . '"' . ( $disabled ? ' disabled="disabled"' : '' ) . $title . '>' ;
2012-03-15 22:51:02 +01:00
2012-03-15 11:01:29 +01:00
foreach ( $this -> cache_vatrates as $rate )
{
2012-08-31 01:00:18 +02:00
// Keep only 0 if seller is not subject to VAT
2012-08-30 22:14:18 +02:00
if ( $disabled && $rate [ 'txtva' ] != 0 ) continue ;
2012-07-02 19:30:37 +02:00
$return .= '<option value="' . $rate [ 'txtva' ];
$return .= $rate [ 'nprtva' ] ? '*' : '' ;
2012-03-15 11:01:29 +01:00
$return .= '"' ;
if ( $rate [ 'txtva' ] == $defaulttx && $rate [ 'nprtva' ] == $defaultnpr )
{
$return .= ' selected="selected"' ;
2012-07-02 19:30:37 +02:00
}
$return .= '>' . vatrate ( $rate [ 'libtva' ]);
2012-03-15 11:01:29 +01:00
$return .= $rate [ 'nprtva' ] ? ' *' : '' ;
$return .= '</option>' ;
2012-03-15 22:51:02 +01:00
2012-03-15 11:01:29 +01:00
$this -> tva_taux_value [] = $rate [ 'txtva' ];
$this -> tva_taux_libelle [] = $rate [ 'libtva' ];
$this -> tva_taux_npr [] = $rate [ 'nprtva' ];
}
2012-03-15 22:51:02 +01:00
2012-03-15 16:52:18 +01:00
if ( ! $options_only ) $return .= '</select>' ;
2010-08-22 17:46:34 +02:00
}
else
{
2012-03-15 11:01:29 +01:00
$return .= $this -> error ;
2010-08-22 17:46:34 +02:00
}
2012-03-19 17:18:11 +01:00
2012-03-18 14:17:10 +01:00
$this -> num = $num ;
2010-08-22 17:46:34 +02:00
return $return ;
}
/**
2014-03-31 00:44:45 +02:00
* Show a HTML widget to input a date or combo list for day , month , years and optionaly hours and minutes .
2012-03-12 15:09:46 +01:00
* Fields are preselected with :
2014-03-29 04:26:44 +01:00
* - set_time date ( must be a local PHP server timestamp or string date with format 'YYYY-MM-DD' or 'YYYY-MM-DD HH:MM' )
* - local date in user area , if set_time is '' ( so if set_time is '' , output may differs when done from two different location )
* - Empty ( fields empty ), if set_time is - 1 ( in this case , parameter empty must also have value 1 )
2011-08-12 23:29:29 +02:00
*
2014-03-29 04:26:44 +01:00
* @ param timestamp $set_time Pre - selected date ( must be a local PHP server timestamp ), - 1 to keep date not preselected , '' to use current date .
2012-03-12 15:09:46 +01:00
* @ param string $prefix Prefix for fields name
* @ param int $h 1 = Show also hours
* @ param int $m 1 = Show also minutes
* @ param int $empty 0 = Fields required , 1 = Empty input is allowed
2012-09-23 22:02:44 +02:00
* @ param string $form_name Not used
2012-03-12 15:09:46 +01:00
* @ param int $d 1 = Show days , month , years
* @ param int $addnowbutton Add a button " Now "
* @ param int $nooutput Do not output html string but return it
* @ param int $disabled Disable input fields
* @ param int $fullday When a checkbox with this html name is on , hour and day are set with 00 : 00 or 23 : 59
* @ return mixed Nothing or string if nooutput is 1
2014-03-29 04:26:44 +01:00
* @ see form_date
2010-08-22 17:46:34 +02:00
*/
2010-11-18 23:17:44 +01:00
function select_date ( $set_time = '' , $prefix = 're' , $h = 0 , $m = 0 , $empty = 0 , $form_name = " " , $d = 1 , $addnowbutton = 0 , $nooutput = 0 , $disabled = 0 , $fullday = '' )
2010-08-22 17:46:34 +02:00
{
global $conf , $langs ;
$retstring = '' ;
if ( $prefix == '' ) $prefix = 're' ;
if ( $h == '' ) $h = 0 ;
if ( $m == '' ) $m = 0 ;
if ( $empty == '' ) $empty = 0 ;
2011-05-01 20:22:58 +02:00
2014-04-02 14:53:42 +02:00
if ( $set_time === '' && $empty == 0 )
2014-03-29 04:26:44 +01:00
{
include_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php' ;
$set_time = dol_now ( 'tzuser' ) - ( getServerTimeZoneInt ( 'now' ) * 3600 ); // set_time must be relative to PHP server timezone
}
2010-08-22 17:46:34 +02:00
2011-05-30 11:16:33 +02:00
// Analysis of the pre-selection date
2010-08-22 17:46:34 +02:00
if ( preg_match ( '/^([0-9]+)\-([0-9]+)\-([0-9]+)\s?([0-9]+)?:?([0-9]+)?/' , $set_time , $reg ))
{
2011-05-30 11:16:33 +02:00
// Date format 'YYYY-MM-DD' or 'YYYY-MM-DD HH:MM:SS'
2012-07-23 16:10:54 +02:00
$syear = ( ! empty ( $reg [ 1 ]) ? $reg [ 1 ] : '' );
$smonth = ( ! empty ( $reg [ 2 ]) ? $reg [ 2 ] : '' );
$sday = ( ! empty ( $reg [ 3 ]) ? $reg [ 3 ] : '' );
$shour = ( ! empty ( $reg [ 4 ]) ? $reg [ 4 ] : '' );
$smin = ( ! empty ( $reg [ 5 ]) ? $reg [ 5 ] : '' );
2010-08-22 17:46:34 +02:00
}
elseif ( strval ( $set_time ) != '' && $set_time != - 1 )
{
// set_time est un timestamps (0 possible)
$syear = dol_print_date ( $set_time , " %Y " );
$smonth = dol_print_date ( $set_time , " %m " );
$sday = dol_print_date ( $set_time , " %d " );
$shour = dol_print_date ( $set_time , " %H " );
$smin = dol_print_date ( $set_time , " %M " );
}
else
{
// Date est '' ou vaut -1
$syear = '' ;
$smonth = '' ;
$sday = '' ;
$shour = '' ;
$smin = '' ;
}
2013-04-14 14:45:23 +02:00
$usecalendar = 'combo' ;
if ( ! empty ( $conf -> use_javascript_ajax ) && ( empty ( $conf -> global -> MAIN_POPUP_CALENDAR ) || $conf -> global -> MAIN_POPUP_CALENDAR != " none " )) $usecalendar = empty ( $conf -> global -> MAIN_POPUP_CALENDAR ) ? 'eldy' : $conf -> global -> MAIN_POPUP_CALENDAR ;
if ( $conf -> browser -> phone ) $usecalendar = 'combo' ;
2010-08-22 17:46:34 +02:00
if ( $d )
{
2011-03-20 15:38:54 +01:00
// Show date with popup
2013-04-05 22:26:41 +02:00
if ( $usecalendar != 'combo' )
2010-08-22 17:46:34 +02:00
{
2012-07-10 22:10:12 +02:00
$formated_date = '' ;
2010-08-22 17:46:34 +02:00
//print "e".$set_time." t ".$conf->format_date_short;
if ( strval ( $set_time ) != '' && $set_time != - 1 )
{
2010-08-28 01:42:10 +02:00
//$formated_date=dol_print_date($set_time,$conf->format_date_short);
2013-04-18 19:37:50 +02:00
$formated_date = dol_print_date ( $set_time , $langs -> trans ( " FormatDateShortInput " )); // FormatDateShortInput for dol_print_date / FormatDateShortJavaInput that is same for javascript
2010-08-22 17:46:34 +02:00
}
// Calendrier popup version eldy
2013-04-05 22:26:41 +02:00
if ( $usecalendar == " eldy " )
2010-08-22 17:46:34 +02:00
{
// Zone de saisie manuelle de la date
$retstring .= '<input id="' . $prefix . '" name="' . $prefix . '" type="text" size="9" maxlength="11" value="' . $formated_date . '"' ;
2011-08-31 17:12:09 +02:00
$retstring .= ( $disabled ? ' disabled="disabled"' : '' );
2013-04-18 19:37:50 +02:00
$retstring .= ' onChange="dpChangeDay(\'' . $prefix . '\',\'' . $langs -> trans ( " FormatDateShortJavaInput " ) . '\'); "' ; // FormatDateShortInput for dol_print_date / FormatDateShortJavaInput that is same for javascript
2010-08-22 17:46:34 +02:00
$retstring .= '>' ;
// Icone calendrier
if ( ! $disabled )
{
$retstring .= '<button id="' . $prefix . 'Button" type="button" class="dpInvisibleButtons"' ;
2011-10-24 10:29:33 +02:00
$base = DOL_URL_ROOT . '/core/' ;
2013-04-18 19:37:50 +02:00
$retstring .= ' onClick="showDP(\'' . $base . '\',\'' . $prefix . '\',\'' . $langs -> trans ( " FormatDateShortJavaInput " ) . '\',\'' . $langs -> defaultlang . '\');">' . img_object ( $langs -> trans ( " SelectDate " ), 'calendarday' , 'class="datecallink"' ) . '</button>' ;
2010-08-22 17:46:34 +02:00
}
2012-02-21 10:47:08 +01:00
else $retstring .= '<button id="' . $prefix . 'Button" type="button" class="dpInvisibleButtons">' . img_object ( $langs -> trans ( " Disabled " ), 'calendarday' , 'class="datecallink"' ) . '</button>' ;
2010-08-22 17:46:34 +02:00
$retstring .= '<input type="hidden" id="' . $prefix . 'day" name="' . $prefix . 'day" value="' . $sday . '">' . " \n " ;
$retstring .= '<input type="hidden" id="' . $prefix . 'month" name="' . $prefix . 'month" value="' . $smonth . '">' . " \n " ;
$retstring .= '<input type="hidden" id="' . $prefix . 'year" name="' . $prefix . 'year" value="' . $syear . '">' . " \n " ;
}
else
2013-04-18 19:37:50 +02:00
{
2013-04-05 22:26:41 +02:00
print " Bad value of MAIN_POPUP_CALENDAR " ;
2010-08-22 17:46:34 +02:00
}
}
2011-03-20 15:38:54 +01:00
// Show date with combo selects
2013-04-05 22:26:41 +02:00
else
{
2011-05-30 11:16:33 +02:00
// Day
2011-08-31 17:12:09 +02:00
$retstring .= '<select' . ( $disabled ? ' disabled="disabled"' : '' ) . ' class="flat" name="' . $prefix . 'day">' ;
2010-08-22 17:46:34 +02:00
if ( $empty || $set_time == - 1 )
{
2010-11-01 17:00:38 +01:00
$retstring .= '<option value="0" selected="selected"> </option>' ;
2010-08-22 17:46:34 +02:00
}
for ( $day = 1 ; $day <= 31 ; $day ++ )
{
2013-04-05 22:26:41 +02:00
$retstring .= '<option value="' . $day . '"' . ( $day == $sday ? ' selected="selected"' : '' ) . '>' . $day . '</option>' ;
2010-08-22 17:46:34 +02:00
}
$retstring .= " </select> " ;
2011-08-31 17:12:09 +02:00
$retstring .= '<select' . ( $disabled ? ' disabled="disabled"' : '' ) . ' class="flat" name="' . $prefix . 'month">' ;
2010-08-22 17:46:34 +02:00
if ( $empty || $set_time == - 1 )
{
2010-11-01 17:00:38 +01:00
$retstring .= '<option value="0" selected="selected"> </option>' ;
2010-08-22 17:46:34 +02:00
}
// Month
for ( $month = 1 ; $month <= 12 ; $month ++ )
{
2010-11-01 17:00:38 +01:00
$retstring .= '<option value="' . $month . '"' . ( $month == $smonth ? ' selected="selected"' : '' ) . '>' ;
2010-08-22 17:46:34 +02:00
$retstring .= dol_print_date ( mktime ( 12 , 0 , 0 , $month , 1 , 2000 ), " %b " );
$retstring .= " </option> " ;
}
$retstring .= " </select> " ;
// Year
if ( $empty || $set_time == - 1 )
{
2013-06-26 14:38:56 +02:00
$retstring .= '<input' . ( $disabled ? ' disabled="disabled"' : '' ) . ' placeholder="' . dol_escape_htmltag ( $langs -> trans ( " Year " )) . '" class="flat" type="text" size="3" maxlength="4" name="' . $prefix . 'year" value="' . $syear . '">' ;
2010-08-22 17:46:34 +02:00
}
else
{
2011-08-31 17:12:09 +02:00
$retstring .= '<select' . ( $disabled ? ' disabled="disabled"' : '' ) . ' class="flat" name="' . $prefix . 'year">' ;
2010-08-22 17:46:34 +02:00
for ( $year = $syear - 5 ; $year < $syear + 10 ; $year ++ )
{
2013-04-05 22:26:41 +02:00
$retstring .= '<option value="' . $year . '"' . ( $year == $syear ? ' selected="true"' : '' ) . '>' . $year . '</option>' ;
2010-08-22 17:46:34 +02:00
}
$retstring .= " </select> \n " ;
}
}
}
if ( $d && $h ) $retstring .= ' ' ;
if ( $h )
{
2011-03-20 15:38:54 +01:00
// Show hour
2012-02-21 10:47:08 +01:00
$retstring .= '<select' . ( $disabled ? ' disabled="disabled"' : '' ) . ' class="flat ' . ( $fullday ? $fullday . 'hour' : '' ) . '" name="' . $prefix . 'hour">' ;
2010-08-22 17:46:34 +02:00
if ( $empty ) $retstring .= '<option value="-1"> </option>' ;
for ( $hour = 0 ; $hour < 24 ; $hour ++ )
{
2013-04-05 22:26:41 +02:00
if ( strlen ( $hour ) < 2 ) $hour = " 0 " . $hour ;
$retstring .= '<option value="' . $hour . '"' . (( $hour == $shour ) ? ' selected="true"' : '' ) . '>' . $hour . ( empty ( $conf -> dol_optimize_smallscreen ) ? '' : 'H' ) . '</option>' ;
2010-08-22 17:46:34 +02:00
}
2013-04-05 22:26:41 +02:00
$retstring .= '</select>' ;
if ( empty ( $conf -> dol_optimize_smallscreen )) $retstring .= " : " ;
2010-08-22 17:46:34 +02:00
}
if ( $m )
{
2011-03-20 15:38:54 +01:00
// Show minutes
2011-08-31 17:12:09 +02:00
$retstring .= '<select' . ( $disabled ? ' disabled="disabled"' : '' ) . ' class="flat ' . ( $fullday ? $fullday . 'min' : '' ) . '" name="' . $prefix . 'min">' ;
2010-08-22 17:46:34 +02:00
if ( $empty ) $retstring .= '<option value="-1"> </option>' ;
for ( $min = 0 ; $min < 60 ; $min ++ )
{
2013-04-05 22:26:41 +02:00
if ( strlen ( $min ) < 2 ) $min = " 0 " . $min ;
$retstring .= '<option value="' . $min . '"' . (( $min == $smin ) ? ' selected="true"' : '' ) . '>' . $min . ( empty ( $conf -> dol_optimize_smallscreen ) ? '' : '' ) . '</option>' ;
2010-08-22 17:46:34 +02:00
}
2013-04-05 22:26:41 +02:00
$retstring .= '</select>' ;
2010-08-22 17:46:34 +02:00
}
2010-11-18 23:17:44 +01:00
// Add a "Now" button
2010-08-22 17:46:34 +02:00
if ( $conf -> use_javascript_ajax && $addnowbutton )
{
// Script which will be inserted in the OnClick of the "Now" button
$reset_scripts = " " ;
// Generate the date part, depending on the use or not of the javascript calendar
2013-04-14 14:45:23 +02:00
if ( $usecalendar == " eldy " )
2010-08-22 17:46:34 +02:00
{
2012-07-26 17:04:50 +02:00
$base = DOL_URL_ROOT . '/core/' ;
2013-04-18 19:37:50 +02:00
$reset_scripts .= 'resetDP(\'' . $base . '\',\'' . $prefix . '\',\'' . $langs -> trans ( " FormatDateShortJavaInput " ) . '\',\'' . $langs -> defaultlang . '\');' ;
2010-08-22 17:46:34 +02:00
}
else
{
$reset_scripts .= 'this.form.elements[\'' . $prefix . 'day\'].value=formatDate(new Date(), \'d\'); ' ;
$reset_scripts .= 'this.form.elements[\'' . $prefix . 'month\'].value=formatDate(new Date(), \'M\'); ' ;
$reset_scripts .= 'this.form.elements[\'' . $prefix . 'year\'].value=formatDate(new Date(), \'yyyy\'); ' ;
}
// Generate the hour part
if ( $h )
{
2010-11-18 23:17:44 +01:00
if ( $fullday ) $reset_scripts .= " if (jQuery('#fullday:checked').val() == null) { " ;
2010-08-22 17:46:34 +02:00
$reset_scripts .= 'this.form.elements[\'' . $prefix . 'hour\'].value=formatDate(new Date(), \'HH\'); ' ;
2010-11-18 23:17:44 +01:00
if ( $fullday ) $reset_scripts .= ' } ' ;
2010-08-22 17:46:34 +02:00
}
// Generate the minute part
if ( $m )
{
2010-11-18 23:17:44 +01:00
if ( $fullday ) $reset_scripts .= " if (jQuery('#fullday:checked').val() == null) { " ;
2010-08-22 17:46:34 +02:00
$reset_scripts .= 'this.form.elements[\'' . $prefix . 'min\'].value=formatDate(new Date(), \'mm\'); ' ;
2010-11-18 23:17:44 +01:00
if ( $fullday ) $reset_scripts .= ' } ' ;
2010-08-22 17:46:34 +02:00
}
// If reset_scripts is not empty, print the button with the reset_scripts in OnClick
2013-04-14 16:11:55 +02:00
if ( $reset_scripts && empty ( $conf -> dol_optimize_smallscreen ))
2010-08-22 17:46:34 +02:00
{
2013-04-06 16:43:26 +02:00
$retstring .= ' <button class="dpInvisibleButtons datenowlink" id="' . $prefix . 'ButtonNow" type="button" name="_useless" value="Now" onClick="' . $reset_scripts . '">' ;
2010-08-22 17:46:34 +02:00
$retstring .= $langs -> trans ( " Now " );
$retstring .= '</button> ' ;
}
}
if ( ! empty ( $nooutput )) return $retstring ;
print $retstring ;
return ;
}
/**
2011-03-20 15:38:54 +01:00
* Function to show a form to select a duration on a page
2011-08-12 23:29:29 +02:00
*
2014-06-21 16:06:59 +02:00
* @ param string $prefix Prefix
* @ param int $iSecond Default preselected duration ( number of seconds )
* @ param int $disabled Disable the combo box
* @ param string $typehour If 'select' then input hour and input min is a combo , if 'text' input hour is in text and input min is a combo
* @ param string $minunderhours If 1 , show minutes selection under the hours
2011-09-15 01:15:38 +02:00
* @ return void
2010-08-22 17:46:34 +02:00
*/
2014-06-21 16:06:59 +02:00
function select_duration ( $prefix , $iSecond = '' , $disabled = 0 , $typehour = 'select' , $minunderhours = 0 )
2010-08-22 17:46:34 +02:00
{
2013-05-15 14:19:16 +02:00
global $langs ;
2013-06-05 22:01:35 +02:00
2013-10-30 21:44:04 +01:00
$hourSelected = 0 ; $minSelected = 0 ;
2010-08-22 17:46:34 +02:00
if ( $iSecond )
{
2012-08-22 23:11:24 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php' ;
2010-08-22 17:46:34 +02:00
2013-10-30 21:44:04 +01:00
$hourSelected = convertSecondToTime ( $iSecond , 'allhour' );
2012-02-07 10:25:58 +01:00
$minSelected = convertSecondToTime ( $iSecond , 'min' );
2010-08-22 17:46:34 +02:00
}
2013-06-05 22:01:35 +02:00
if ( $typehour == 'select' )
2010-08-22 17:46:34 +02:00
{
2013-05-15 14:19:16 +02:00
print '<select class="flat" name="' . $prefix . 'hour"' . ( $disabled ? ' disabled="disabled"' : '' ) . '>' ;
2013-11-05 13:11:36 +01:00
for ( $hour = 0 ; $hour < 25 ; $hour ++ ) // For a duration, we allow 24 hours
2013-05-15 14:19:16 +02:00
{
print '<option value="' . $hour . '"' ;
if ( $hourSelected == $hour )
{
print " selected= \" true \" " ;
}
print " > " . $hour . " </option> " ;
}
print " </select> " ;
2010-08-22 17:46:34 +02:00
}
2013-06-05 22:01:35 +02:00
elseif ( $typehour == 'text' )
2013-05-15 14:19:16 +02:00
{
2014-08-07 11:08:36 +02:00
print '<input type="text" size="3" name="' . $prefix . 'hour"' . ( $disabled ? ' disabled="disabled"' : '' ) . ' class="flat" value="' . (( int ) $hourSelected ) . '">' ;
2013-05-15 14:19:16 +02:00
}
2014-06-21 16:06:59 +02:00
print $langs -> trans ( 'Hours' );
if ( $minunderhours ) print '<br>' ;
else print " " ;
2011-08-31 17:12:09 +02:00
print '<select class="flat" name="' . $prefix . 'min"' . ( $disabled ? ' disabled="disabled"' : '' ) . '>' ;
2010-08-22 17:46:34 +02:00
for ( $min = 0 ; $min <= 55 ; $min = $min + 5 )
{
print '<option value="' . $min . '"' ;
2010-11-01 17:00:38 +01:00
if ( $minSelected == $min ) print ' selected="selected"' ;
2010-08-22 17:46:34 +02:00
print '>' . $min . '</option>' ;
}
print " </select> " ;
2013-05-15 14:19:16 +02:00
print $langs -> trans ( 'Minutes' ) . " " ;
2010-08-22 17:46:34 +02:00
}
/**
2014-05-01 16:26:57 +02:00
* Return a HTML select string , built from an array of key + value .
2011-08-12 23:29:29 +02:00
*
2012-03-12 15:09:46 +01:00
* @ param string $htmlname Name of html select area
* @ param array $array Array with key + value
2014-02-23 16:16:47 +01:00
* @ param string $id Preselected key
2012-03-12 15:09:46 +01:00
* @ param int $show_empty 1 si il faut ajouter une valeur vide dans la liste , 0 sinon
* @ param int $key_in_label 1 pour afficher la key dans la valeur " [key] value "
* @ param int $value_as_key 1 to use value as key
* @ param string $option Valeur de l ' option en fonction du type choisi
* @ param int $translate Translate and encode value
* @ param int $maxlen Length maximum for labels
* @ param int $disabled Html select box is disabled
2013-10-28 02:13:07 +01:00
* @ param int $sort 'ASC' or 'DESC' = Sort on label , '' or 'NONE' = Do not sort
2014-01-26 18:30:45 +01:00
* @ param string $morecss Add more class to css styles
2012-03-12 15:09:46 +01:00
* @ return string HTML select string
2010-08-22 17:46:34 +02:00
*/
2014-05-01 16:26:57 +02:00
static function selectarray ( $htmlname , $array , $id = '' , $show_empty = 0 , $key_in_label = 0 , $value_as_key = 0 , $option = '' , $translate = 0 , $maxlen = 0 , $disabled = 0 , $sort = '' , $morecss = '' )
2010-08-22 17:46:34 +02:00
{
global $langs ;
2012-04-11 13:29:23 +02:00
2012-03-24 12:49:11 +01:00
if ( $value_as_key ) $array = array_combine ( $array , $array );
2010-08-22 17:46:34 +02:00
2014-01-26 18:30:45 +01:00
$out = '<select id="' . $htmlname . '" ' . ( $disabled ? 'disabled="disabled" ' : '' ) . 'class="flat' . ( $morecss ? ' ' . $morecss : '' ) . '" name="' . $htmlname . '" ' . ( $option != '' ? $option : '' ) . '>' ;
2010-08-22 17:46:34 +02:00
if ( $show_empty )
{
2010-11-01 17:00:38 +01:00
$out .= '<option value="-1"' . ( $id ==- 1 ? ' selected="selected"' : '' ) . '> </option>' . " \n " ;
2010-08-22 17:46:34 +02:00
}
if ( is_array ( $array ))
{
2013-10-28 02:13:07 +01:00
// Translate
if ( $translate )
{
foreach ( $array as $key => $value ) $array [ $key ] = $langs -> trans ( $value );
}
// Sort
if ( $sort == 'ASC' ) asort ( $array );
elseif ( $sort == 'DESC' ) arsort ( $array );
2011-06-15 22:21:25 +02:00
foreach ( $array as $key => $value )
2010-08-22 17:46:34 +02:00
{
2012-03-24 12:49:11 +01:00
$out .= '<option value="' . $key . '"' ;
2013-10-28 02:13:07 +01:00
if ( $id != '' && $id == $key ) $out .= ' selected="selected"' ; // To preselect a value
2010-08-22 17:46:34 +02:00
$out .= '>' ;
2012-04-11 13:29:23 +02:00
2010-08-22 17:46:34 +02:00
if ( $key_in_label )
{
2013-10-28 02:13:07 +01:00
$selectOptionValue = dol_htmlentitiesbr ( $key . ' - ' . ( $maxlen ? dol_trunc ( $value , $maxlen ) : $value ));
2010-08-22 17:46:34 +02:00
}
else
{
2013-10-28 02:13:07 +01:00
$selectOptionValue = dol_htmlentitiesbr ( $maxlen ? dol_trunc ( $value , $maxlen ) : $value );
if ( $value == '' || $value == '-' ) $selectOptionValue = ' ' ;
2010-08-22 17:46:34 +02:00
}
2012-03-22 12:46:29 +01:00
$out .= $selectOptionValue ;
2010-08-22 17:46:34 +02:00
$out .= " </option> \n " ;
}
}
$out .= " </select> " ;
return $out ;
}
2012-04-11 13:29:23 +02:00
2012-07-02 19:30:37 +02:00
/**
* Show a multiselect form from an array .
*
2012-03-24 12:49:11 +01:00
* @ param string $htmlname Name of select
2012-07-02 19:30:37 +02:00
* @ param array $array Array with key + value
2012-03-24 12:49:11 +01:00
* @ param array $selected Preselected keys
* @ param int $key_in_label 1 pour afficher la key dans la valeur " [key] value "
* @ param int $value_as_key 1 to use value as key
* @ param string $option Valeur de l ' option en fonction du type choisi
2012-07-02 19:30:37 +02:00
* @ param int $translate Translate and encode value
* @ return string HTML multiselect string
*/
function multiselectarray ( $htmlname , $array , $selected = array (), $key_in_label = 0 , $value_as_key = 0 , $option = '' , $translate = 0 )
{
2012-03-24 12:49:11 +01:00
global $conf , $langs ;
2012-07-02 19:30:37 +02:00
$out = '<select id="' . $htmlname . '" class="multiselect" multiple="multiple" name="' . $htmlname . '[]"' . $option . '>' . " \n " ;
if ( is_array ( $array ) && ! empty ( $array ))
2012-03-24 12:49:11 +01:00
{
if ( $value_as_key ) $array = array_combine ( $array , $array );
2012-07-02 19:30:37 +02:00
if ( ! empty ( $conf -> global -> MAIN_USE_JQUERY_MULTISELECT ) && is_array ( $selected ) && ! empty ( $selected ))
2012-03-24 12:49:11 +01:00
{
foreach ( $selected as $selected_value )
{
foreach ( $array as $key => $value )
{
2012-07-02 19:30:37 +02:00
if ( $selected_value == $key )
{
$value = $array [ $selected_value ];
$out .= '<option value="' . $key . '" selected="selected">' ;
$newval = ( $translate ? $langs -> trans ( ucfirst ( $value )) : $value );
$newval = ( $key_in_label ? $key . ' - ' . $newval : $newval );
$out .= dol_htmlentitiesbr ( $newval );
$out .= '</option>' . " \n " ;
unset ( $array [ $key ]);
2012-03-24 12:49:11 +01:00
}
}
}
2012-04-11 13:29:23 +02:00
2012-03-24 12:49:11 +01:00
if ( ! empty ( $array ))
{
2012-07-02 19:30:37 +02:00
foreach ( $array as $key => $value )
2012-03-24 12:49:11 +01:00
{
2012-07-02 19:30:37 +02:00
$out .= '<option value="' . $key . '">' ;
$newval = ( $translate ? $langs -> trans ( ucfirst ( $value )) : $value );
$newval = ( $key_in_label ? $key . ' - ' . $newval : $newval );
$out .= dol_htmlentitiesbr ( $newval );
$out .= '</option>' . " \n " ;
2012-03-24 12:49:11 +01:00
}
}
}
else
{
2012-07-02 19:30:37 +02:00
foreach ( $array as $key => $value )
{
$out .= '<option value="' . $key . '"' ;
if ( is_array ( $selected ) && ! empty ( $selected ) && in_array ( $key , $selected ))
{
$out .= ' selected="selected"' ;
}
$out .= '>' ;
$newval = ( $translate ? $langs -> trans ( ucfirst ( $value )) : $value );
$newval = ( $key_in_label ? $key . ' - ' . $newval : $newval );
$out .= dol_htmlentitiesbr ( $newval );
$out .= '</option>' . " \n " ;
2012-03-24 12:49:11 +01:00
}
2012-07-02 19:30:37 +02:00
}
}
$out .= '</select>' . " \n " ;
return $out ;
2012-03-24 12:49:11 +01:00
}
2010-08-22 17:46:34 +02:00
/**
2011-12-28 10:17:33 +01:00
* Return an html string with a select combo box to choose yes or no
2011-08-12 23:29:29 +02:00
*
2012-03-19 17:18:11 +01:00
* @ param string $htmlname Name of html select field
2011-12-28 10:17:33 +01:00
* @ param string $value Pre - selected value
* @ param int $option 0 return yes / no , 1 return 1 / 0
* @ param bool $disabled true or false
* @ return mixed See option
2010-08-22 17:46:34 +02:00
*/
2011-12-28 10:17:33 +01:00
function selectyesno ( $htmlname , $value = '' , $option = 0 , $disabled = false )
2010-08-22 17:46:34 +02:00
{
global $langs ;
$yes = " yes " ; $no = " no " ;
if ( $option )
{
$yes = " 1 " ;
$no = " 0 " ;
}
2011-12-29 23:50:02 +01:00
2011-12-28 10:17:33 +01:00
$disabled = ( $disabled ? ' disabled="disabled"' : '' );
2010-08-22 17:46:34 +02:00
2011-12-28 10:17:33 +01:00
$resultyesno = '<select class="flat" id="' . $htmlname . '" name="' . $htmlname . '"' . $disabled . '>' . " \n " ;
2010-08-22 17:46:34 +02:00
if (( " $value " == 'yes' ) || ( $value == 1 ))
{
2010-11-01 17:00:38 +01:00
$resultyesno .= '<option value="' . $yes . '" selected="selected">' . $langs -> trans ( " Yes " ) . '</option>' . " \n " ;
2010-08-22 17:46:34 +02:00
$resultyesno .= '<option value="' . $no . '">' . $langs -> trans ( " No " ) . '</option>' . " \n " ;
}
else
{
$resultyesno .= '<option value="' . $yes . '">' . $langs -> trans ( " Yes " ) . '</option>' . " \n " ;
2010-11-01 17:00:38 +01:00
$resultyesno .= '<option value="' . $no . '" selected="selected">' . $langs -> trans ( " No " ) . '</option>' . " \n " ;
2010-08-22 17:46:34 +02:00
}
$resultyesno .= '</select>' . " \n " ;
return $resultyesno ;
}
/**
2012-03-12 15:09:46 +01:00
* Return list of export templates
2011-08-12 23:29:29 +02:00
*
2012-03-12 15:09:46 +01:00
* @ param string $selected Id modele pre - selectionne
* @ param string $htmlname Name of HTML select
* @ param string $type Type of searched templates
* @ param int $useempty Affiche valeur vide dans liste
2011-09-15 01:15:38 +02:00
* @ return void
2010-08-22 17:46:34 +02:00
*/
function select_export_model ( $selected = '' , $htmlname = 'exportmodelid' , $type = '' , $useempty = 0 )
{
$sql = " SELECT rowid, label " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " export_model " ;
$sql .= " WHERE type = ' " . $type . " ' " ;
$sql .= " ORDER BY rowid " ;
$result = $this -> db -> query ( $sql );
if ( $result )
{
print '<select class="flat" name="' . $htmlname . '">' ;
if ( $useempty )
{
print '<option value="-1"> </option>' ;
}
$num = $this -> db -> num_rows ( $result );
$i = 0 ;
while ( $i < $num )
{
$obj = $this -> db -> fetch_object ( $result );
if ( $selected == $obj -> rowid )
{
2010-11-01 17:00:38 +01:00
print '<option value="' . $obj -> rowid . '" selected="selected">' ;
2010-08-22 17:46:34 +02:00
}
else
{
print '<option value="' . $obj -> rowid . '">' ;
}
print $obj -> label ;
print '</option>' ;
$i ++ ;
}
print " </select> " ;
}
else {
dol_print_error ( $this -> db );
}
}
/**
2010-12-29 11:17:41 +01:00
* Return a HTML area with the reference of object and a navigation bar for a business object
2010-08-22 15:40:44 +02:00
* To add a particular filter on select , you must set $object -> next_prev_filter to SQL criteria .
2011-08-12 23:29:29 +02:00
*
2013-11-07 21:23:29 +01:00
* @ param object $object Object to show
2012-06-27 23:45:58 +02:00
* @ param string $paramid Name of parameter to use to name the id into the URL link
* @ param string $morehtml More html content to output just before the nav bar
2012-02-21 10:47:08 +01:00
* @ param int $shownav Show Condition ( navigation is shown if value is 1 )
2012-06-27 23:45:58 +02:00
* @ param string $fieldid Nom du champ en base a utiliser pour select next et previous
* @ param string $fieldref Nom du champ objet ref ( object -> ref ) a utiliser pour select next et previous
* @ param string $morehtmlref Code html supplementaire a afficher apres ref
* @ param string $moreparam More param to add in nav link url .
2014-04-09 13:19:31 +02:00
* @ param int $nodbprefix Do not include DB prefix to forge table name
2012-06-27 23:45:58 +02:00
* @ return tring Portion HTML avec ref + boutons nav
2010-08-22 17:46:34 +02:00
*/
2014-04-09 13:19:31 +02:00
function showrefnav ( $object , $paramid , $morehtml = '' , $shownav = 1 , $fieldid = 'rowid' , $fieldref = 'ref' , $morehtmlref = '' , $moreparam = '' , $nodbprefix = 0 )
2010-08-22 17:46:34 +02:00
{
2013-04-24 15:49:43 +02:00
global $langs , $conf ;
2010-08-22 17:46:34 +02:00
$ret = '' ;
2012-06-27 23:45:58 +02:00
if ( empty ( $fieldid )) $fieldid = 'rowid' ;
if ( empty ( $fieldref )) $fieldref = 'ref' ;
2010-08-22 17:46:34 +02:00
2012-02-21 10:47:08 +01:00
//print "paramid=$paramid,morehtml=$morehtml,shownav=$shownav,$fieldid,$fieldref,$morehtmlref,$moreparam";
2014-04-09 13:19:31 +02:00
$object -> load_previous_next_ref (( isset ( $object -> next_prev_filter ) ? $object -> next_prev_filter : '' ), $fieldid , $nodbprefix );
2013-04-24 15:49:43 +02:00
$previous_ref = $object -> ref_previous ? '<a data-role="button" data-icon="arrow-l" data-iconpos="left" href="' . $_SERVER [ " PHP_SELF " ] . '?' . $paramid . '=' . urlencode ( $object -> ref_previous ) . $moreparam . '">' . ( empty ( $conf -> dol_use_jmobile ) ? img_picto ( $langs -> trans ( " Previous " ), 'previous.png' ) : ' ' ) . '</a>' : '' ;
$next_ref = $object -> ref_next ? '<a data-role="button" data-icon="arrow-r" data-iconpos="right" href="' . $_SERVER [ " PHP_SELF " ] . '?' . $paramid . '=' . urlencode ( $object -> ref_next ) . $moreparam . '">' . ( empty ( $conf -> dol_use_jmobile ) ? img_picto ( $langs -> trans ( " Next " ), 'next.png' ) : ' ' ) . '</a>' : '' ;
2010-08-22 17:46:34 +02:00
//print "xx".$previous_ref."x".$next_ref;
if ( $previous_ref || $next_ref || $morehtml ) {
$ret .= '<table class="nobordernopadding" width="100%"><tr class="nobordernopadding"><td class="nobordernopadding">' ;
}
2014-07-28 14:04:55 +02:00
$ret .= dol_htmlentities ( $object -> $fieldref );
2012-02-21 10:47:08 +01:00
if ( $morehtmlref )
{
2010-08-22 17:46:34 +02:00
$ret .= ' ' . $morehtmlref ;
}
2012-02-21 10:47:08 +01:00
if ( $morehtml )
{
2014-04-02 18:45:59 +02:00
$ret .= '</td><td class="paddingrightonly" align="right">' . $morehtml ;
2010-08-22 17:46:34 +02:00
}
2012-02-21 10:47:08 +01:00
if ( $shownav && ( $previous_ref || $next_ref ))
{
2010-08-22 17:46:34 +02:00
$ret .= '</td><td class="nobordernopadding" align="center" width="20">' . $previous_ref . '</td>' ;
$ret .= '<td class="nobordernopadding" align="center" width="20">' . $next_ref ;
}
if ( $previous_ref || $next_ref || $morehtml )
{
$ret .= '</td></tr></table>' ;
}
return $ret ;
}
2011-12-07 15:06:29 +01:00
/**
2012-02-21 10:47:08 +01:00
* Return HTML code to output a barcode
*
* @ param Object & $object Object containing data to retrieve file name
* @ param int $width Width of photo
* @ return string HTML code to output barcode
*/
2011-12-07 15:06:29 +01:00
function showbarcode ( & $object , $width = 100 )
{
global $conf ;
2012-09-11 14:27:41 +02:00
//Check if barcode is filled in the card
2011-12-07 15:06:29 +01:00
if ( empty ( $object -> barcode )) return '' ;
// Complete object if not complete
if ( empty ( $object -> barcode_type_code ) || empty ( $object -> barcode_type_coder ))
{
2014-05-25 17:14:33 +02:00
$result = $object -> fetch_barcode ();
//Check if fetch_barcode() failed
2012-09-11 15:49:46 +02:00
if ( $result < 1 ) return '<!-- ErrorFetchBarcode -->' ;
2011-12-07 15:06:29 +01:00
}
2014-05-29 19:56:15 +02:00
2011-12-07 15:06:29 +01:00
// Barcode image
$url = DOL_URL_ROOT . '/viewimage.php?modulepart=barcode&generator=' . urlencode ( $object -> barcode_type_coder ) . '&code=' . urlencode ( $object -> barcode ) . '&encoding=' . urlencode ( $object -> barcode_type_code );
$out = '<!-- url barcode = ' . $url . ' -->' ;
$out .= '<img src="' . $url . '">' ;
return $out ;
}
2010-08-22 17:46:34 +02:00
/**
2011-05-10 00:19:14 +02:00
* Return HTML code to output a photo
2011-08-12 23:29:29 +02:00
*
2011-12-07 15:06:29 +01:00
* @ param string $modulepart Key to define module concerned ( 'societe' , 'userphoto' , 'memberphoto' )
* @ param Object $object Object containing data to retrieve file name
* @ param int $width Width of photo
* @ return string HTML code to output photo
2010-08-22 17:46:34 +02:00
*/
function showphoto ( $modulepart , $object , $width = 100 )
{
global $conf ;
2012-12-13 11:42:59 +01:00
$entity = ( ! empty ( $object -> entity ) ? $object -> entity : $conf -> entity );
$id = ( ! empty ( $object -> id ) ? $object -> id : $object -> rowid );
2011-06-11 22:58:08 +02:00
$ret = '' ; $dir = '' ; $file = '' ; $altfile = '' ; $email = '' ;
2010-08-22 17:46:34 +02:00
2011-06-11 16:14:27 +02:00
if ( $modulepart == 'societe' )
{
2012-12-13 11:42:59 +01:00
$dir = $conf -> societe -> multidir_output [ $entity ];
2011-06-11 16:14:27 +02:00
$smallfile = $object -> logo ;
$smallfile = preg_replace ( '/(\.png|\.gif|\.jpg|\.jpeg|\.bmp)/i' , '_small\\1' , $smallfile );
2012-12-13 11:42:59 +01:00
if ( $object -> logo ) $file = $id . '/logos/thumbs/' . $smallfile ;
2011-06-11 16:14:27 +02:00
}
2011-06-11 16:26:30 +02:00
else if ( $modulepart == 'userphoto' )
2010-08-22 17:46:34 +02:00
{
$dir = $conf -> user -> dir_output ;
2012-12-13 11:42:59 +01:00
if ( $object -> photo ) $file = get_exdir ( $id , 2 ) . $object -> photo ;
2011-06-11 22:58:08 +02:00
if ( ! empty ( $conf -> global -> MAIN_OLD_IMAGE_LINKS )) $altfile = $object -> id . " .jpg " ; // For backward compatibility
2010-08-22 17:46:34 +02:00
$email = $object -> email ;
}
2011-06-11 16:26:30 +02:00
else if ( $modulepart == 'memberphoto' )
2010-08-22 17:46:34 +02:00
{
$dir = $conf -> adherent -> dir_output ;
2012-12-13 11:42:59 +01:00
if ( $object -> photo ) $file = get_exdir ( $id , 2 ) . 'photos/' . $object -> photo ;
2011-06-11 22:58:08 +02:00
if ( ! empty ( $conf -> global -> MAIN_OLD_IMAGE_LINKS )) $altfile = $object -> id . " .jpg " ; // For backward compatibility
2010-08-22 17:46:34 +02:00
$email = $object -> email ;
2013-05-21 14:52:39 +02:00
} else {
$dir = $conf -> $modulepart -> dir_output ;
if ( $object -> photo ) $file = get_exdir ( $id , 2 ) . 'photos/' . $object -> photo ;
if ( ! empty ( $conf -> global -> MAIN_OLD_IMAGE_LINKS )) $altfile = $object -> id . " .jpg " ; // For backward compatibility
$email = $object -> email ;
2010-08-22 17:46:34 +02:00
}
2011-06-11 22:58:08 +02:00
if ( $dir )
2010-08-22 17:46:34 +02:00
{
2011-06-13 00:13:05 +02:00
$cache = '0' ;
2011-06-11 22:58:08 +02:00
if ( $file && file_exists ( $dir . " / " . $file ))
2010-08-22 17:46:34 +02:00
{
2011-06-13 00:13:05 +02:00
// TODO Link to large image
2012-12-13 11:42:59 +01:00
$ret .= '<a href="' . DOL_URL_ROOT . '/viewimage.php?modulepart=' . $modulepart . '&entity=' . $entity . '&file=' . urlencode ( $file ) . '&cache=' . $cache . '">' ;
$ret .= '<img alt="Photo" id="photologo' . ( preg_replace ( '/[^a-z]/i' , '_' , $file )) . '" class="photologo" border="0" width="' . $width . '" src="' . DOL_URL_ROOT . '/viewimage.php?modulepart=' . $modulepart . '&entity=' . $entity . '&file=' . urlencode ( $file ) . '&cache=' . $cache . '">' ;
2011-06-13 00:13:05 +02:00
$ret .= '</a>' ;
2010-08-22 17:46:34 +02:00
}
2011-06-11 16:14:27 +02:00
else if ( $altfile && file_exists ( $dir . " / " . $altfile ))
2010-08-22 17:46:34 +02:00
{
2012-12-13 11:42:59 +01:00
$ret .= '<a href="' . DOL_URL_ROOT . '/viewimage.php?modulepart=' . $modulepart . '&entity=' . $entity . '&file=' . urlencode ( $file ) . '&cache=' . $cache . '">' ;
$ret .= '<img alt="Photo alt" id="photologo' . ( preg_replace ( '/[^a-z]/i' , '_' , $file )) . '" class="photologo" border="0" width="' . $width . '" src="' . DOL_URL_ROOT . '/viewimage.php?modulepart=' . $modulepart . '&entity=' . $entity . '&file=' . urlencode ( $altfile ) . '&cache=' . $cache . '">' ;
2011-06-13 00:13:05 +02:00
$ret .= '</a>' ;
2010-08-22 17:46:34 +02:00
}
else
{
2012-07-10 13:20:53 +02:00
if ( ! empty ( $conf -> gravatar -> enabled ) && $email )
2010-08-22 17:46:34 +02:00
{
global $dolibarr_main_url_root ;
$ret .= '<!-- Put link to gravatar -->' ;
2012-03-19 17:18:11 +01:00
$ret .= '<img alt="Photo found on Gravatar" title="Photo Gravatar.com - email ' . $email . '" border="0" width="' . $width . '" src="http://www.gravatar.com/avatar/' . dol_hash ( $email ) . '?s=' . $width . '&d=' . urlencode ( dol_buildpath ( '/theme/common/nophoto.jpg' , 2 )) . '">' ;
2010-08-22 17:46:34 +02:00
}
else
{
2011-06-13 00:13:05 +02:00
$ret .= '<img alt="No photo" border="0" width="' . $width . '" src="' . DOL_URL_ROOT . '/theme/common/nophoto.jpg">' ;
2010-08-22 17:46:34 +02:00
}
}
}
2011-06-11 16:26:30 +02:00
else dol_print_error ( '' , 'Call of showphoto with wrong parameters' );
2010-08-22 17:46:34 +02:00
return $ret ;
}
2010-11-18 23:17:44 +01:00
2010-11-08 20:04:52 +01:00
/**
* Return select list of groups
2011-08-12 23:29:29 +02:00
*
2013-02-16 21:06:15 +01:00
* @ param string $selected Id group preselected
* @ param string $htmlname Field name in form
* @ param int $show_empty 0 = liste sans valeur nulle , 1 = ajoute valeur inconnue
* @ param string $exclude Array list of groups id to exclude
2011-09-15 01:15:38 +02:00
* @ param int $disabled If select list must be disabled
2013-02-16 21:06:15 +01:00
* @ param string $include Array list of groups id to include
2011-09-15 01:15:38 +02:00
* @ param int $enableonly Array list of groups id to be enabled . All other must be disabled
2013-02-16 21:06:15 +01:00
* @ param int $force_entity 0 or Id of environment to force
2011-09-15 01:15:38 +02:00
* @ return void
2014-06-28 19:47:51 +02:00
* @ see select_dolusers
2010-11-08 20:04:52 +01:00
*/
2013-02-16 21:06:15 +01:00
function select_dolgroups ( $selected = '' , $htmlname = 'groupid' , $show_empty = 0 , $exclude = '' , $disabled = 0 , $include = '' , $enableonly = '' , $force_entity = 0 )
2010-11-08 20:04:52 +01:00
{
2011-08-21 02:20:43 +02:00
global $conf , $user , $langs ;
2010-11-08 20:04:52 +01:00
// Permettre l'exclusion de groupes
if ( is_array ( $exclude )) $excludeGroups = implode ( " ',' " , $exclude );
// Permettre l'inclusion de groupes
if ( is_array ( $include )) $includeGroups = implode ( " ',' " , $include );
$out = '' ;
// On recherche les groupes
$sql = " SELECT ug.rowid, ug.nom " ;
2012-07-06 20:25:00 +02:00
if ( ! empty ( $conf -> multicompany -> enabled ) && $conf -> entity == 1 && $user -> admin && ! $user -> entity )
2011-08-20 00:15:22 +02:00
{
2012-02-21 10:47:08 +01:00
$sql .= " , e.label " ;
2011-08-20 00:15:22 +02:00
}
2011-08-19 09:22:17 +02:00
$sql .= " FROM " . MAIN_DB_PREFIX . " usergroup as ug " ;
2012-07-06 20:25:00 +02:00
if ( ! empty ( $conf -> multicompany -> enabled ) && $conf -> entity == 1 && $user -> admin && ! $user -> entity )
2011-08-19 09:22:17 +02:00
{
2012-07-06 20:25:00 +02:00
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " entity as e ON e.rowid=ug.entity " ;
2011-08-21 02:20:43 +02:00
if ( $force_entity ) $sql .= " WHERE ug.entity IN (0, " . $force_entity . " ) " ;
else $sql .= " WHERE ug.entity IS NOT NULL " ;
2011-08-19 09:22:17 +02:00
}
else
2011-08-20 00:15:22 +02:00
{
2012-02-21 10:47:08 +01:00
$sql .= " WHERE ug.entity IN (0, " . $conf -> entity . " ) " ;
2011-08-20 00:15:22 +02:00
}
if ( is_array ( $exclude ) && $excludeGroups ) $sql .= " AND ug.rowid NOT IN (' " . $excludeGroups . " ') " ;
2010-11-08 20:04:52 +01:00
if ( is_array ( $include ) && $includeGroups ) $sql .= " AND ug.rowid IN (' " . $includeGroups . " ') " ;
2012-02-21 10:47:08 +01:00
$sql .= " ORDER BY ug.nom ASC " ;
2010-11-08 20:04:52 +01:00
2014-06-12 11:31:53 +02:00
dol_syslog ( get_class ( $this ) . " ::select_dolgroups " , LOG_DEBUG );
2010-11-08 20:04:52 +01:00
$resql = $this -> db -> query ( $sql );
if ( $resql )
{
$num = $this -> db -> num_rows ( $resql );
$i = 0 ;
if ( $num )
{
2014-06-28 20:49:10 +02:00
$out .= '<select class="flat" id="' . $htmlname . '" name="' . $htmlname . '"' . ( $disabled ? ' disabled="disabled"' : '' ) . '>' ;
2012-02-21 10:47:08 +01:00
if ( $show_empty ) $out .= '<option value="-1"' . ( $selected ==- 1 ? ' selected="selected"' : '' ) . '> </option>' . " \n " ;
2011-08-31 16:55:54 +02:00
2010-11-08 20:04:52 +01:00
while ( $i < $num )
{
$obj = $this -> db -> fetch_object ( $resql );
$disableline = 0 ;
2011-09-15 01:15:38 +02:00
if ( is_array ( $enableonly ) && count ( $enableonly ) && ! in_array ( $obj -> rowid , $enableonly )) $disableline = 1 ;
2010-11-08 20:04:52 +01:00
$out .= '<option value="' . $obj -> rowid . '"' ;
2011-08-31 17:12:09 +02:00
if ( $disableline ) $out .= ' disabled="disabled"' ;
2010-11-08 20:04:52 +01:00
if (( is_object ( $selected ) && $selected -> id == $obj -> rowid ) || ( ! is_object ( $selected ) && $selected == $obj -> rowid ))
{
$out .= ' selected="selected"' ;
}
$out .= '>' ;
2010-11-18 23:17:44 +01:00
2010-11-08 20:04:52 +01:00
$out .= $obj -> nom ;
2012-07-06 20:25:00 +02:00
if ( ! empty ( $conf -> multicompany -> enabled ) && empty ( $conf -> multicompany -> transverse_mode ) && $conf -> entity == 1 )
2011-08-20 00:15:22 +02:00
{
2012-02-21 10:47:08 +01:00
$out .= " ( " . $obj -> label . " ) " ;
2011-08-20 00:15:22 +02:00
}
2010-11-18 23:17:44 +01:00
2010-11-08 20:04:52 +01:00
$out .= '</option>' ;
$i ++ ;
}
}
2011-08-21 02:20:43 +02:00
else
{
2012-02-21 10:47:08 +01:00
$out .= '<select class="flat" name="' . $htmlname . '" disabled="disabled">' ;
$out .= '<option value="">' . $langs -> trans ( " None " ) . '</option>' ;
2011-08-21 02:20:43 +02:00
}
2010-11-08 20:04:52 +01:00
$out .= '</select>' ;
}
else
{
dol_print_error ( $this -> db );
}
return $out ;
}
2010-11-18 23:17:44 +01:00
2010-05-03 10:22:35 +02:00
}