2010-05-03 10:22:35 +02:00
< ? php
/* Copyright ( c ) 2002 - 2007 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
2011-03-20 15:38:54 +01:00
* Copyright ( C ) 2004 - 2011 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 >
* Copyright ( C ) 2005 - 2010 Regis Houssin < regis @ dolibarr . fr >
* 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 >
2011-04-18 22:56:10 +02:00
* Copyright ( C ) 2010 Philippe Grand < philippe . grand @ atoo - net . com >
2011-08-19 09:22:17 +02:00
* Copyright ( C ) 2011 Herve Prot < herve . prot @ symeos . com >
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
* the Free Software Foundation ; either version 2 of the License , or
* ( 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
*/
/**
* \class Form
2010-08-04 18:33:03 +02:00
* \brief Class to manage generation of HTML components
2010-05-03 10:22:35 +02:00
* \remarks Only common components must be here .
*/
class Form
{
2010-08-22 17:46:34 +02:00
var $db ;
var $error ;
// Cache arrays
var $cache_types_paiements = array ();
var $cache_conditions_paiements = array ();
2011-04-01 13:00:02 +02:00
var $cache_availability = array ();
2011-04-26 22:59:45 +02:00
var $cache_demand_reason = array ();
2010-08-22 17:46:34 +02:00
var $tva_taux_value ;
var $tva_taux_libelle ;
/**
2011-09-11 20:35:38 +02:00
* Constructor
*
* @ param DoliDB $DB Database handler
2010-08-22 17:46:34 +02:00
*/
function Form ( $DB )
{
$this -> db = $DB ;
}
/**
* Output key field for an editable field
2011-09-11 20:35:38 +02:00
*
2010-08-22 17:46:34 +02:00
* @ param text Text of label
* @ param htmlname Name of select field
* @ param preselected Preselected value for parameter
* @ param paramkey Key of parameter ( unique if there is several parameter to show )
* @ param paramvalue Value of parameter
* @ param perm Permission to allow button to edit parameter
* @ param typeofdata Type of data ( string by default , email , ... )
* @ return string HTML edit field
2011-05-09 15:47:37 +02:00
* TODO no GET or POST in class file , use a param
2010-08-22 17:46:34 +02:00
*/
function editfieldkey ( $text , $htmlname , $preselected , $paramkey , $paramvalue , $perm , $typeofdata = 'string' )
{
global $langs ;
$ret = '' ;
$ret .= '<table class="nobordernopadding" width="100%"><tr><td nowrap="nowrap">' ;
$ret .= $langs -> trans ( $text );
$ret .= '</td>' ;
2011-05-09 15:47:37 +02:00
if ( GETPOST ( 'action' ) != 'edit' . $htmlname && $perm ) $ret .= '<td align="right"><a href="' . $_SERVER [ " PHP_SELF " ] . '?action=edit' . $htmlname . '&' . $paramkey . '=' . $paramvalue . '">' . img_edit ( $langs -> trans ( 'Edit' ), 1 ) . '</a></td>' ;
2010-08-22 17:46:34 +02:00
$ret .= '</tr></table>' ;
return $ret ;
}
/**
2011-03-06 18:03:27 +01:00
* Output val field for an editable field
* @ param text Text of label ( not used in this function )
* @ param htmlname Name of select field
* @ param preselected Preselected value for parameter
* @ param paramkey Key of parameter ( unique if there is several parameter to show )
* @ param perm Permission to allow button to edit parameter
* @ param typeofdata Type of data ( 'string' by default , 'email' , 'text' , ... )
2011-05-25 18:53:39 +02:00
* @ param editvalue Use this value instead $preselected
2011-03-06 18:03:27 +01:00
* @ return string HTML edit field
2011-05-09 15:47:37 +02:00
* TODO no GET or POST in class file , use a param
2010-08-22 17:46:34 +02:00
*/
2011-05-25 18:53:39 +02:00
function editfieldval ( $text , $htmlname , $preselected , $paramkey , $paramvalue , $perm , $typeofdata = 'string' , $editvalue = '' )
2010-08-22 17:46:34 +02:00
{
global $langs ;
$ret = '' ;
2011-05-09 15:47:37 +02:00
if ( GETPOST ( 'action' ) == 'edit' . $htmlname )
2010-08-22 17:46:34 +02:00
{
$ret .= " \n " ;
$ret .= '<form method="post" action="' . $_SERVER [ " PHP_SELF " ] . '">' ;
$ret .= '<input type="hidden" name="action" value="set' . $htmlname . '">' ;
$ret .= '<input type="hidden" name="token" value="' . $_SESSION [ 'newtoken' ] . '">' ;
$ret .= '<input type="hidden" name="' . $paramkey . '" value="' . $paramvalue . '">' ;
$ret .= '<table class="nobordernopadding" cellpadding="0" cellspacing="0">' ;
$ret .= '<tr><td>' ;
2011-03-06 18:03:27 +01:00
if ( in_array ( $typeofdata , array ( 'string' , 'email' )))
{
2011-05-25 18:53:39 +02:00
$ret .= '<input type="text" name="' . $htmlname . '" value="' . ( $editvalue ? $editvalue : $preselected ) . '">' ;
2011-03-06 18:03:27 +01:00
}
else if ( $typeofdata == 'text' )
{
2011-05-25 18:53:39 +02:00
$ret .= '<textarea name="' . $htmlname . '">' . ( $editvalue ? $editvalue : $preselected ) . '</textarea>' ;
2011-03-06 18:03:27 +01:00
}
2010-08-22 17:46:34 +02:00
$ret .= '</td>' ;
$ret .= '<td align="left"><input type="submit" class="button" value="' . $langs -> trans ( " Modify " ) . '"></td>' ;
$ret .= '</tr></table>' . " \n " ;
$ret .= '</form>' . " \n " ;
}
else
{
if ( $typeofdata == 'email' ) $ret .= dol_print_email ( $preselected , 0 , 0 , 0 , 0 , 1 );
else $ret .= $preselected ;
}
return $ret ;
}
/**
2010-08-29 14:54:39 +02:00
* Show a text and picto with tooltip on text or picto
2010-09-30 21:28:31 +02:00
* @ param text Text to show
2011-07-22 00:55:06 +02:00
* @ param htmltext Content html of tooltip . Must be HTML / UTF8 encoded .
2010-10-22 01:42:18 +02:00
* @ param tooltipon 1 = tooltip sur texte , 2 = tooltip sur picto , 3 = tooltip sur les 2
2010-08-29 14:54:39 +02:00
* @ param direction - 1 = Le picto est avant , 0 = pas de picto , 1 = le picto est apres
* @ param img Code img du picto ( use img_xxx () function to get it )
2011-02-03 23:01:11 +01:00
* @ param extracss Add a CSS style to td tags
2011-04-07 12:18:41 +02:00
* @ param notabs Do not include table and tr tags
* @ param incbefore Include code before the text
2011-07-22 00:55:06 +02:00
* @ param noencodehtmltext Do not encode into html entity the htmltext
2010-08-29 14:54:39 +02:00
* @ return string Code html du tooltip ( texte + picto )
* @ see Use function textwithpicto if you can .
2010-08-22 17:46:34 +02:00
*/
2011-07-22 00:55:06 +02:00
function textwithtooltip ( $text , $htmltext , $tooltipon = 1 , $direction = 0 , $img = '' , $extracss = '' , $notabs = 0 , $incbefore = '' , $noencodehtmltext = 0 )
2010-08-22 17:46:34 +02:00
{
global $conf ;
2011-05-01 20:22:58 +02:00
2011-04-07 12:18:41 +02:00
if ( $incbefore ) $text = $incbefore . $text ;
2010-08-22 17:46:34 +02:00
if ( ! $htmltext ) return $text ;
// Sanitize tooltip
$htmltext = str_replace ( " \\ " , " \\ \\ " , $htmltext );
$htmltext = str_replace ( " \r " , " " , $htmltext );
$htmltext = str_replace ( " \n " , " " , $htmltext );
2010-10-22 21:18:45 +02:00
$htmltext = str_replace ( '"' , " " " , $htmltext );
2011-08-01 01:45:11 +02:00
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
2010-10-22 21:18:45 +02:00
$s = " " ;
2011-02-03 23:01:11 +01:00
if ( empty ( $notabs )) $s .= '<table class="nobordernopadding" summary=""><tr>' ;
2010-10-22 01:42:18 +02:00
if ( $direction > 0 )
{
if ( $text != '' )
{
2011-07-04 09:28:11 +02:00
$s .= '<td' . $paramfortooltiptd . '>' . $text ;
2010-10-22 01:42:18 +02:00
if ( $direction ) $s .= ' ' ;
$s .= '</td>' ;
}
2011-07-04 09:28:11 +02:00
if ( $direction ) $s .= '<td' . $paramfortooltipimg . ' valign="top" width="14">' . $img . '</td>' ;
2010-10-22 01:42:18 +02:00
}
else
{
2011-07-04 09:28:11 +02:00
if ( $direction ) $s .= '<td' . $paramfortooltipimg . ' valign="top" width="14">' . $img . '</td>' ;
2010-10-22 01:42:18 +02:00
if ( $text != '' )
{
2011-07-04 09:28:11 +02:00
$s .= '<td' . $paramfortooltiptd . '>' ;
2010-10-22 01:42:18 +02:00
if ( $direction ) $s .= ' ' ;
$s .= $text . '</td>' ;
}
}
2011-02-03 23:01:11 +01:00
if ( empty ( $notabs )) $s .= '</tr></table>' ;
2010-10-22 01:42:18 +02:00
2010-08-22 17:46:34 +02:00
return $s ;
}
/**
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
*
2010-10-23 15:01:48 +02:00
* @ param text Text to show
* @ param htmltooltip Content of tooltip
2011-08-31 23:02:55 +02:00
* @ param direction 1 = Icon is after text , - 1 = Icon is before text , 0 = no icon
2010-10-23 15:01:48 +02:00
* @ param type Type of picto ( info , help , warning , superadmin ... )
2011-07-04 09:28:11 +02:00
* @ param extracss Add a CSS style to td tags
2011-07-22 00:55:06 +02:00
* @ param noencodehtmltext Do not encode into html entity the htmltext
2010-10-23 15:01:48 +02:00
* @ return string HTML code of text , picto , tooltip
2010-08-22 17:46:34 +02:00
*/
2011-07-22 00:55:06 +02:00
function textwithpicto ( $text , $htmltext , $direction = 1 , $type = 'help' , $extracss = '' , $noencodehtmltext = 0 )
2010-08-22 17:46:34 +02:00
{
global $conf ;
if ( " $type " == " 0 " ) $type = 'info' ; // For backward compatibility
$alt = '' ;
// If info or help with no javascript, show only text
if ( empty ( $conf -> use_javascript_ajax ))
{
if ( $type == 'info' || $type == 'help' ) return $text ;
else { $alt = $htmltext ; $htmltext = '' ; }
}
// If info or help with smartphone, show only text
if ( ! empty ( $conf -> browser -> phone ))
{
if ( $type == 'info' || $type == 'help' ) return $text ;
}
// Info or help
if ( $type == 'info' ) $img = img_help ( 0 , $alt );
if ( $type == 'help' || $type == 1 ) $img = img_help ( 1 , $alt );
2011-08-17 17:56:22 +02:00
if ( $type == 'superadmin' ) $img = img_picto ( $alt , " redstar " );
2011-05-16 21:56:43 +02:00
if ( $type == 'admin' ) $img = img_picto ( $alt , " star " );
2010-08-22 17:46:34 +02:00
// Warnings
if ( $type == 'warning' ) $img = img_warning ( $alt );
2011-07-22 00:55:06 +02:00
return $this -> textwithtooltip ( $text , $htmltext , 2 , $direction , $img , $extracss , 0 , '' , $noencodehtmltext );
2010-08-22 17:46:34 +02:00
}
2010-09-02 21:31:18 +02:00
2010-08-22 17:46:34 +02:00
/**
2010-10-28 00:41:40 +02:00
* Return combo list of activated countries , into language of user
* @ param selected Id or Code or Label of preselected country
* @ param htmlname Name of html select object
* @ param htmloption Options html on select object
2010-08-22 17:46:34 +02:00
*/
function select_pays ( $selected = '' , $htmlname = 'pays_id' , $htmloption = '' )
2010-09-01 22:51:10 +02:00
{
print $this -> select_country ( $selected , $htmlname , $htmloption );
}
/**
2010-10-28 00:41:40 +02:00
* Return combo list of activated countries , into language of user
* @ param selected Id or Code or Label of preselected country
* @ param htmlname Name of html select object
* @ param htmloption Options html on select object
2011-03-19 03:17:05 +01:00
* @ return string HTML string with select
2010-09-01 22:51:10 +02:00
*/
function select_country ( $selected = '' , $htmlname = 'pays_id' , $htmloption = '' )
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
2011-03-10 13:09:59 +01:00
$sql = " SELECT rowid, code as code_iso, libelle as label " ;
2010-08-22 17:46:34 +02:00
$sql .= " FROM " . MAIN_DB_PREFIX . " c_pays " ;
$sql .= " WHERE active = 1 " ;
$sql .= " ORDER BY code ASC " ;
2011-03-19 03:17:05 +01:00
dol_syslog ( " Form::select_country sql= " . $sql );
2010-08-22 17:46:34 +02:00
$resql = $this -> db -> query ( $sql );
if ( $resql )
{
2010-09-01 22:51:10 +02:00
$out .= '<select id="select' . $htmlname . '" class="flat selectpays" 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
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 ;
2011-03-19 03:17:05 +01:00
$countryArray [ $i ][ 'label' ] = ( $obj -> code_iso && $langs -> trans ( " Country " . $obj -> code_iso ) != " Country " . $obj -> code_iso ? $langs -> trans ( " Country " . $obj -> code_iso ) : ( $obj -> label != '-' ? $obj -> label : '' ));
2011-03-10 13:09:59 +01:00
$label [ $i ] = $countryArray [ $i ][ 'label' ];
$i ++ ;
}
array_multisort ( $label , SORT_ASC , $countryArray );
2011-03-19 03:17:05 +01:00
foreach ( $countryArray as $row )
{
2011-03-10 13:09:59 +01:00
if ( $selected && $selected != '-1' && ( $selected == $row [ 'rowid' ] || $selected == $row [ 'code_iso' ] || $selected == $row [ 'label' ]) ) {
2010-08-22 17:46:34 +02:00
$foundselected = true ;
2011-03-10 13:09:59 +01:00
$out .= '<option value="' . $row [ 'rowid' ] . '" selected="selected">' ;
} else {
$out .= '<option value="' . $row [ 'rowid' ] . '">' ;
2010-08-22 17:46:34 +02:00
}
2011-03-10 13:09:59 +01:00
$out .= $row [ 'label' ];
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
{
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
}
/**
2011-03-20 15:38:54 +01:00
* Retourne la liste des types de comptes financiers
* @ param selected Type pre - selectionne
* @ param htmlname Nom champ formulaire
2010-08-22 17:46:34 +02:00
*/
function select_type_comptes_financiers ( $selected = 1 , $htmlname = 'type' )
{
global $langs ;
$langs -> load ( " banks " );
$type_available = array ( 0 , 1 , 2 );
print '<select class="flat" name="' . $htmlname . '">' ;
$num = count ( $type_available );
$i = 0 ;
if ( $num )
{
while ( $i < $num )
{
if ( $selected == $type_available [ $i ])
{
2010-11-01 17:00:38 +01:00
print '<option value="' . $type_available [ $i ] . '" selected="selected">' . $langs -> trans ( " BankType " . $type_available [ $i ]) . '</option>' ;
2010-08-22 17:46:34 +02:00
}
else
{
print '<option value="' . $type_available [ $i ] . '">' . $langs -> trans ( " BankType " . $type_available [ $i ]) . '</option>' ;
}
$i ++ ;
}
}
print '</select>' ;
}
/**
2011-03-20 15:38:54 +01:00
* Return list of social contributions .
* Use mysoc -> pays_id or mysoc -> pays_code so they must be defined .
* @ param selected Preselected type
* @ param htmlname Name of field in form
* @ param useempty Set to 1 if we want an empty value
* @ param maxlen Max length of text in combo box
* @ param help Add or not the admin help picto
2010-08-22 17:46:34 +02:00
*/
function select_type_socialcontrib ( $selected = '' , $htmlname = 'actioncode' , $useempty = 0 , $maxlen = 40 , $help = 1 )
{
global $db , $langs , $user , $mysoc ;
if ( empty ( $mysoc -> pays_id ) && empty ( $mysoc -> pays_code ))
{
dol_print_error ( '' , 'Call to select_type_socialcontrib with mysoc country not yet defined' );
exit ;
}
if ( ! empty ( $mysoc -> pays_id ))
{
$sql = " SELECT c.id, c.libelle as type " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " c_chargesociales as c " ;
$sql .= " WHERE c.active = 1 " ;
$sql .= " AND c.fk_pays = " . $mysoc -> pays_id ;
$sql .= " ORDER BY c.libelle ASC " ;
}
else
{
$sql = " SELECT c.id, c.libelle as type " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " c_chargesociales as c, " . MAIN_DB_PREFIX . " c_pays as p " ;
$sql .= " WHERE c.active = 1 AND c.fk_pays = p.rowid " ;
$sql .= " AND p.code = ' " . $mysoc -> pays_code . " ' " ;
$sql .= " ORDER BY c.libelle ASC " ;
}
dol_syslog ( " Form::select_type_socialcontrib sql= " . $sql , LOG_DEBUG );
$resql = $db -> query ( $sql );
if ( $resql )
{
$num = $db -> num_rows ( $resql );
if ( $num )
{
print '<select class="flat" name="' . $htmlname . '">' ;
$i = 0 ;
if ( $useempty ) print '<option value="0"> </option>' ;
while ( $i < $num )
{
$obj = $db -> fetch_object ( $resql );
print '<option value="' . $obj -> id . '"' ;
2010-11-01 17:00:38 +01:00
if ( $obj -> id == $selected ) print ' selected="selected"' ;
2010-08-22 17:46:34 +02:00
print '>' . dol_trunc ( $obj -> type , $maxlen );
$i ++ ;
}
print '</select>' ;
if ( $user -> admin && $help ) print info_admin ( $langs -> trans ( " YouCanChangeValuesForThisListFromDictionnarySetup " ), 1 );
}
else
{
print $langs -> trans ( " ErrorNoSocialContributionForSellerCountry " , $mysoc -> pays_code );
}
}
else
{
dol_print_error ( $db , $db -> lasterror ());
}
}
/**
2010-09-07 14:44:15 +02:00
* Return list of types of lines ( product or service )
2010-10-28 00:41:40 +02:00
* Example : 0 = product , 1 = service , 9 = other ( for external module )
2010-09-07 14:44:15 +02:00
* @ param selected Preselected type
* @ param htmlname Name of field in html form
* @ param showempty Add an empty field
* @ param hidetext Do not show label before combo box
* @ param forceall Force to show products and services in combo list , whatever are activated modules
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.
if ( $forceall || ( $conf -> product -> enabled && $conf -> service -> enabled )
|| ( empty ( $conf -> product -> enabled ) && empty ( $conf -> service -> enabled )))
{
if ( empty ( $hidetext )) print $langs -> trans ( " Type " ) . ': ' ;
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>' ;
}
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>' ;
//if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionnarySetup"),1);
}
if ( ! $forceall && empty ( $conf -> product -> enabled ) && $conf -> service -> enabled )
{
print '<input type="hidden" name="' . $htmlname . '" value="1">' ;
}
if ( ! $forceall && $conf -> product -> enabled && empty ( $conf -> service -> enabled ))
{
print '<input type="hidden" name="' . $htmlname . '" value="0">' ;
}
}
/**
2011-05-10 00:19:14 +02:00
* Return list of types of notes
* @ param selected Preselected type
* @ param htmlname Name of field in form
* @ param showempty Add an empty field
2010-08-22 17:46:34 +02:00
*/
function select_type_fees ( $selected = '' , $htmlname = 'type' , $showempty = 0 )
{
global $db , $langs , $user ;
$langs -> load ( " trips " );
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>' ;
}
$sql = " SELECT c.code, c.libelle as type FROM " . MAIN_DB_PREFIX . " c_type_fees as c " ;
$sql .= " ORDER BY lower(c.libelle) ASC " ;
$resql = $db -> query ( $sql );
if ( $resql )
{
$num = $db -> num_rows ( $resql );
$i = 0 ;
while ( $i < $num )
{
$obj = $db -> fetch_object ( $resql );
print '<option value="' . $obj -> code . '"' ;
2010-11-01 17:00:38 +01:00
if ( $obj -> code == $selected ) print ' selected="selected"' ;
2010-08-22 17:46:34 +02:00
print '>' ;
if ( $obj -> code != $langs -> trans ( $obj -> code )) print $langs -> trans ( $obj -> code );
else print $langs -> trans ( $obj -> type );
$i ++ ;
}
}
print '</select>' ;
if ( $user -> admin ) print info_admin ( $langs -> trans ( " YouCanChangeValuesForThisListFromDictionnarySetup " ), 1 );
}
2010-11-18 23:17:44 +01:00
2010-08-22 17:46:34 +02:00
/**
2010-11-03 12:39:40 +01:00
* Output html form to select a third party
* @ param selected Preselected type
* @ param htmlname Name of field in form
* @ param filter Optionnal filters criteras
* @ param showempty Add an empty field
* @ param showtype Show third party type in combolist ( customer , prospect or supplier )
* @ param forcecombo Force to use combo box
2010-08-22 17:46:34 +02:00
*/
2010-10-10 19:44:34 +02:00
function select_societes ( $selected = '' , $htmlname = 'socid' , $filter = '' , $showempty = 0 , $showtype = 0 , $forcecombo = 0 )
2010-11-03 12:39:40 +01:00
{
print $this -> select_company ( $selected , $htmlname , $filter , $showempty , $showtype , $forcecombo );
}
/**
* Output html form to select a third party
* @ param selected Preselected type
* @ param htmlname Name of field in form
* @ param filter Optionnal filters criteras
* @ param showempty Add an empty field
* @ param showtype Show third party type in combolist ( customer , prospect or supplier )
* @ param forcecombo Force to use combo box
*/
function select_company ( $selected = '' , $htmlname = 'socid' , $filter = '' , $showempty = 0 , $showtype = 0 , $forcecombo = 0 )
2010-08-22 17:46:34 +02:00
{
global $conf , $user , $langs ;
2010-11-18 23:17:44 +01:00
2010-11-03 12:39:40 +01:00
$out = '' ;
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 " ;
$sql .= " WHERE s.entity = " . $conf -> entity ;
if ( $filter ) $sql .= " AND " . $filter ;
if ( ! $user -> rights -> societe -> client -> voir && ! $user -> societe_id ) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " . $user -> id ;
$sql .= " ORDER BY nom ASC " ;
dol_syslog ( " Form::select_societes sql= " . $sql );
$resql = $this -> db -> query ( $sql );
if ( $resql )
{
if ( $conf -> use_javascript_ajax && $conf -> global -> COMPANY_USE_SEARCH_TO_SELECT && ! $forcecombo )
{
2011-04-25 16:24:43 +02:00
//$minLength = (is_numeric($conf->global->COMPANY_USE_SEARCH_TO_SELECT)?$conf->global->COMPANY_USE_SEARCH_TO_SELECT:2);
2011-05-01 20:22:58 +02:00
2011-04-25 16:24:43 +02:00
$out .= ajax_combobox ( $htmlname );
2010-08-22 17:46:34 +02:00
}
2011-05-01 20:22:58 +02:00
2011-04-25 16:24:43 +02:00
$out .= '<select id="' . $htmlname . '" class="flat" name="' . $htmlname . '">' ;
if ( $showempty ) $out .= '<option value="-1"> </option>' ;
$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 );
$label = $obj -> nom ;
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
2010-08-22 17:46:34 +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
}
2011-04-25 16:24:43 +02:00
$i ++ ;
2010-08-22 17:46:34 +02:00
}
2011-04-25 16:24:43 +02:00
}
$out .= '</select>' ;
2010-08-22 17:46:34 +02:00
}
else
{
dol_print_error ( $this -> db );
}
2010-11-18 23:17:44 +01:00
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
* @ param selected Id remise fixe pre - selectionnee
* @ param htmlname Nom champ formulaire
* @ param filter Criteres optionnels de filtre
* @ param 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
*/
function select_remises ( $selected = '' , $htmlname = 'remise_id' , $filter = '' , $socid , $maxvalue = 0 )
{
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 " ;
dol_syslog ( " Form::select_remises sql= " . $sql );
$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 = '' ;
if ( $maxvalue && $obj -> amount_ttc > $maxvalue )
{
$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 ;
}
}
/**
2011-02-09 20:22:40 +01:00
* Return list of all contacts ( for a third party or all )
* @ param socid Id ot third party or 0 for all
* @ param selected Id contact pre - selectionne
2011-03-26 14:31:22 +01:00
* @ param htmlname Name of HTML field ( 'none' for a not editable field )
* @ param show_empty 0 = no empty value , 1 = add an empty value
* @ param exclude List of contacts id to exclude
2011-02-09 20:22:40 +01:00
* @ param limitto Disable answers that are not id in this array list
2011-03-26 14:31:22 +01:00
* @ param showfunction Add function into label
2011-04-05 00:14:41 +02:00
* @ param moreclass Add more class to class style
2011-02-09 20:22:40 +01:00
* @ return int < 0 if KO , Nb of contact in list if OK
2010-08-22 17:46:34 +02:00
*/
2011-04-05 00:14:41 +02:00
function select_contacts ( $socid , $selected = '' , $htmlname = 'contactid' , $showempty = 0 , $exclude = '' , $limitto = '' , $showfunction = 0 , $moreclass = '' )
2010-08-22 17:46:34 +02:00
{
2011-02-13 13:17:43 +01:00
global $conf , $langs ;
2011-02-09 20:22:40 +01:00
2010-08-22 17:46:34 +02:00
// On recherche les societes
2011-03-26 14:31:22 +01:00
$sql = " SELECT s.rowid, s.name, s.firstname, s.poste FROM " ;
2010-08-22 17:46:34 +02:00
$sql .= " " . MAIN_DB_PREFIX . " socpeople as s " ;
2011-02-09 20:22:40 +01:00
$sql .= " WHERE entity = " . $conf -> entity ;
2011-07-28 01:37:01 +02:00
if ( $socid > 0 ) $sql .= " AND fk_soc= " . $socid ;
2010-08-22 17:46:34 +02:00
$sql .= " ORDER BY s.name ASC " ;
dol_syslog ( " Form::select_contacts sql= " . $sql );
$resql = $this -> db -> query ( $sql );
if ( $resql )
{
$num = $this -> db -> num_rows ( $resql );
if ( $num == 0 ) return 0 ;
2011-04-05 00:14:41 +02:00
if ( $htmlname != 'none' ) print '<select class="flat' . ( $moreclass ? ' ' . $moreclass : '' ) . '" id="' . $htmlname . '" name="' . $htmlname . '">' ;
2011-02-13 13:17:43 +01:00
if ( $showempty ) print '<option value="0"></option>' ;
2010-08-22 17:46:34 +02:00
$num = $this -> db -> num_rows ( $resql );
$i = 0 ;
if ( $num )
{
2011-04-04 01:06:23 +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 ;
$contactstatic -> name = $obj -> name ;
$contactstatic -> firstname = $obj -> firstname ;
2010-08-22 17:46:34 +02:00
if ( $htmlname != 'none' )
{
$disabled = 0 ;
2011-04-26 15:49:41 +02:00
if ( is_array ( $exclude ) && sizeof ( $exclude ) && in_array ( $obj -> rowid , $exclude )) $disabled = 1 ;
2010-08-22 17:46:34 +02:00
if ( is_array ( $limitto ) && sizeof ( $limitto ) && ! in_array ( $obj -> rowid , $limitto )) $disabled = 1 ;
if ( $selected && $selected == $obj -> rowid )
{
print '<option value="' . $obj -> rowid . '"' ;
2011-08-31 17:12:09 +02:00
if ( $disabled ) print ' disabled="disabled"' ;
2011-02-09 19:20:00 +01:00
print ' selected="selected">' ;
2011-02-13 13:17:43 +01:00
print $contactstatic -> getFullName ( $langs );
2011-03-26 14:31:22 +01:00
if ( $showfunction && $obj -> poste ) print ' (' . $obj -> poste . ')' ;
2011-02-09 19:20:00 +01:00
print '</option>' ;
2010-08-22 17:46:34 +02:00
}
else
{
print '<option value="' . $obj -> rowid . '"' ;
2011-08-31 17:12:09 +02:00
if ( $disabled ) print ' disabled="disabled"' ;
2011-02-09 19:20:00 +01:00
print '>' ;
2011-02-13 13:17:43 +01:00
print $contactstatic -> getFullName ( $langs );
2011-03-26 14:31:22 +01:00
if ( $showfunction && $obj -> poste ) print ' (' . $obj -> poste . ')' ;
2011-02-09 19:20:00 +01:00
print '</option>' ;
2010-08-22 17:46:34 +02:00
}
}
else
{
2011-02-09 19:20:00 +01:00
if ( $selected == $obj -> rowid )
{
2011-02-13 14:34:05 +01:00
print $contactstatic -> getFullName ( $langs );
2011-03-26 14:31:22 +01:00
if ( $showfunction && $obj -> poste ) print ' (' . $obj -> poste . ')' ;
2011-02-09 19:20:00 +01:00
}
2010-08-22 17:46:34 +02:00
}
$i ++ ;
}
}
if ( $htmlname != 'none' )
{
print '</select>' ;
}
return $num ;
}
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
*
2011-03-19 20:06:15 +01:00
* @ param selected Id user preselected
* @ param htmlname Field name in form
* @ param show_empty 0 = liste sans valeur nulle , 1 = ajoute valeur inconnue
* @ param exclude Array list of users id to exclude
* @ param disabled If select list must be disabled
* @ param include Array list of users id to include
* @ param enableonly Array list of users id to be enabled . All other must be disabled
2011-08-20 11:03:38 +02:00
* @ param force_entity Possibility to force entity
2010-08-22 17:46:34 +02:00
*/
2011-08-20 11:03:38 +02: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
{
2011-08-20 11:03:38 +02: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
*
2011-03-19 20:06:15 +01:00
* @ param selected User id or user object of user preselected . If - 1 , we use id of current user .
* @ param htmlname Field name in form
* @ param show_empty 0 = liste sans valeur nulle , 1 = ajoute valeur inconnue
* @ param exclude Array list of users id to exclude
* @ param disabled If select list must be disabled
* @ param include Array list of users id to include
* @ param enableonly Array list of users id to be enabled . All other must be disabled
2011-08-20 11:03:38 +02:00
* @ param force_entity Possibility to force entity
2010-09-01 22:51:10 +02:00
*/
2011-08-20 11:03:38 +02:00
function select_dolusers ( $selected = '' , $htmlname = 'userid' , $show_empty = 0 , $exclude = '' , $disabled = 0 , $include = '' , $enableonly = '' , $force_entity = 0 )
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
2011-03-19 20:06:15 +01:00
if ( $selected < - 1 && 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 );
2010-09-02 21:31:18 +02:00
2010-09-01 22:51:10 +02:00
$out = '' ;
2010-08-22 17:46:34 +02:00
// On recherche les utilisateurs
2011-08-20 00:15:22 +02:00
$sql = " SELECT u.rowid, u.name, u.firstname, u.login, u.admin, u.entity " ;
2011-08-21 12:01:36 +02:00
if ( ! empty ( $conf -> multicompany -> enabled ) && $conf -> entity == 1 && $user -> admin && ! $user -> entity )
2011-08-20 00:15:22 +02:00
{
$sql .= " , e.label " ;
}
2010-08-22 17:46:34 +02:00
$sql .= " FROM " . MAIN_DB_PREFIX . " user as u " ;
2011-08-21 12:01:36 +02:00
if ( ! empty ( $conf -> multicompany -> enabled ) && $conf -> entity == 1 && $user -> admin && ! $user -> entity )
2011-08-19 09:22:17 +02:00
{
2011-08-20 00:15:22 +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
{
$sql .= " WHERE u.entity IN (0, " . $conf -> entity . " ) " ;
}
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 . " ') " ;
$sql .= " ORDER BY u.name ASC " ;
2010-11-08 20:04:52 +01:00
dol_syslog ( " Form::select_dolusers sql= " . $sql );
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 )
{
2011-08-31 17:12:09 +02:00
$out .= '<select class="flat" id="' . $htmlname . '" name="' . $htmlname . '"' . ( $disabled ? ' disabled="disabled"' : '' ) . '>' ;
2011-08-21 02:20:43 +02:00
if ( $show_empty ) $out .= '<option value="-1"' . ( $id ==- 1 ? ' selected="selected"' : '' ) . '> </option>' . " \n " ;
2011-08-31 16:55:54 +02:00
2011-08-21 02:20:43 +02: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 ;
$userstatic -> nom = $obj -> name ;
$userstatic -> prenom = $obj -> firstname ;
2010-08-22 17:46:34 +02:00
$disableline = 0 ;
if ( is_array ( $enableonly ) && sizeof ( $enableonly ) && ! in_array ( $obj -> rowid , $enableonly )) $disableline = 1 ;
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
}
2011-02-13 14:34:05 +01:00
$out .= $userstatic -> getFullName ( $langs );
2011-08-20 17:11:31 +02:00
2011-08-21 12:01:36 +02:00
if ( ! empty ( $conf -> multicompany -> enabled ) && empty ( $conf -> global -> MULTICOMPANY_TRANSVERSE_MODE ) && $conf -> entity == 1 && $user -> admin && ! $user -> entity )
2011-08-20 00:15:22 +02:00
{
if ( $obj -> admin && ! $obj -> entity ) $out .= " ( " . $langs -> trans ( " AllEntities " ) . " ) " ;
else $out .= " ( " . $obj -> label . " ) " ;
}
2011-02-09 19:20:00 +01:00
2010-09-01 22:51:10 +02:00
//if ($obj->admin) $out.= ' *';
if ( $conf -> global -> MAIN_SHOW_LOGIN ) $out .= ' (' . $obj -> login . ')' ;
$out .= '</option>' ;
2010-08-22 17:46:34 +02:00
$i ++ ;
}
2011-08-21 02:20:43 +02:00
}
else
{
$out .= '<select class="flat" name="' . $htmlname . '" disabled="disabled">' ;
$out .= '<option value="">' . $langs -> trans ( " EmptyList " ) . '</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
}
/**
2011-02-05 09:12:11 +01:00
* Return list of products for customer in Ajax if Ajax activated or go to select_produits_do
2011-03-11 11:15:18 +01:00
* @ param selected Preselected products
* @ param htmlname Name of HTML seletc field ( must be unique in page )
* @ param filtertype Filter on product type ( '' = nofilter , 0 = product , 1 = service )
* @ param limit Limit on number of returned lines
* @ param price_level Level of price to show
* @ param status - 1 = Return all products , 0 = Products not on sell , 1 = Products on sell
* @ param finished 2 = all , 1 = finished , 0 = raw material
* @ param $selected_input_value Value of preselected input text ( with ajax )
2010-08-22 17:46:34 +02:00
*/
2011-05-23 12:10:16 +02:00
function select_produits ( $selected = '' , $htmlname = 'productid' , $filtertype = '' , $limit = 20 , $price_level = 0 , $status = 1 , $finished = 2 , $selected_input_value = '' , $hidelabel = 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
if ( $conf -> global -> PRODUIT_USE_SEARCH_TO_SELECT )
{
2011-05-23 12:10:16 +02:00
if ( $selected && empty ( $selected_input_value ))
{
require_once ( DOL_DOCUMENT_ROOT . " /product/class/product.class.php " );
$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
2011-07-10 19:28:09 +02:00
print ajax_autocompleter ( $selected , $htmlname , DOL_URL_ROOT . '/product/ajaxproducts.php' , 'htmlname=' . $htmlname . '&outjson=1&price_level=' . $price_level . '&type=' . $filtertype . '&mode=1&status=' . $status . '&finished=' . $finished , $conf -> global -> PRODUIT_USE_SEARCH_TO_SELECT );
2011-05-23 12:10:16 +02:00
if ( ! $hidelabel ) print $langs -> trans ( " RefOrLabel " ) . ' : ' ;
print '<input type="text" size="20" name="search_' . $htmlname . '" id="search_' . $htmlname . '" value="' . $selected_input_value . '" />' ;
2010-08-22 17:46:34 +02:00
}
else
{
2010-08-22 20:02:32 +02:00
$this -> select_produits_do ( $selected , $htmlname , $filtertype , $limit , $price_level , '' , $status , $finished , 0 );
2010-08-22 17:46:34 +02:00
}
2011-08-31 17:12:09 +02:00
2011-08-31 17:30:56 +02:00
print '<br>' ;
2010-08-22 17:46:34 +02:00
}
/**
2011-02-05 09:12:11 +01:00
* Return list of products for a customer
* @ param selected Preselected product
* @ param htmlname Name of select html
* @ param filtertype Filter on product type ( '' = nofilter , 0 = product , 1 = service )
* @ param limit Limite sur le nombre de lignes retournees
* @ param price_level Level of price to show
* @ param filterkey Filter on product
* @ param status - 1 = Return all products , 0 = Products not on sell , 1 = Products on sell
* @ param finished Filter on finished field : 2 = No filter
* @ param disableout Disable print output
* @ return array Array of keys for json
2010-08-22 17:46:34 +02:00
*/
2010-08-22 20:02:32 +02:00
function select_produits_do ( $selected = '' , $htmlname = 'productid' , $filtertype = '' , $limit = 20 , $price_level = 0 , $filterkey = '' , $status = 1 , $finished = 2 , $disableout = 0 )
2010-08-22 17:46:34 +02:00
{
global $langs , $conf , $user , $db ;
$sql = " SELECT " ;
$sql .= " p.rowid, p.label, p.ref, p.fk_product_type, p.price, p.price_ttc, p.price_base_type, p.duration, p.stock " ;
// Multilang : we add translation
if ( $conf -> global -> MAIN_MULTILANGS )
{
$sql .= " , pl.label as label_translated " ;
}
$sql .= " FROM " . MAIN_DB_PREFIX . " product as p " ;
// Multilang : we add translation
if ( $conf -> global -> MAIN_MULTILANGS )
{
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " product_lang as pl ON pl.fk_product = p.rowid AND pl.lang=' " . $langs -> getDefaultLang () . " ' " ;
}
2011-04-18 17:06:23 +02:00
$sql .= ' WHERE p.entity IN (0,' . ( ! empty ( $conf -> entities [ 'product' ]) ? $conf -> entities [ 'product' ] : $conf -> entity ) . ')' ;
2010-08-22 17:46:34 +02:00
if ( $finished == 0 )
{
$sql .= " AND p.finished = " . $finished ;
}
elseif ( $finished == 1 )
{
$sql .= " AND p.finished = " . $finished ;
if ( $status >= 0 ) $sql .= " AND p.tosell = " . $status ;
}
elseif ( $status >= 0 )
{
$sql .= " AND p.tosell = " . $status ;
}
if ( strval ( $filtertype ) != '' ) $sql .= " AND p.fk_product_type= " . $filtertype ;
// Add criteria on ref/label
2011-06-16 10:55:59 +02:00
if ( $filterkey && $filterkey != '' )
2010-08-22 17:46:34 +02:00
{
2011-06-16 10:55:59 +02:00
if ( ! empty ( $conf -> global -> PRODUCT_DONOTSEARCH_ANYWHERE )) // Can use index
{
$sql .= " AND (p.ref LIKE ' " . $filterkey . " %' OR p.label LIKE ' " . $filterkey . " %' " ;
if ( $conf -> global -> MAIN_MULTILANGS ) $sql .= " OR pl.label LIKE ' " . $filterkey . " %' " ;
$sql .= " ) " ;
}
else
{
$sql .= " AND (p.ref LIKE '% " . $filterkey . " %' OR p.label LIKE '% " . $filterkey . " %' " ;
if ( $conf -> global -> MAIN_MULTILANGS ) $sql .= " OR pl.label LIKE '% " . $filterkey . " %' " ;
$sql .= " ) " ;
}
2010-08-22 17:46:34 +02:00
}
$sql .= $db -> order ( " p.ref " );
$sql .= $db -> plimit ( $limit );
// Build output string
$outselect = '' ;
2010-08-22 20:02:32 +02:00
$outjson = array ();
2010-08-22 17:46:34 +02:00
dol_syslog ( " Form::select_produits_do search product sql= " . $sql , LOG_DEBUG );
$result = $this -> db -> query ( $sql );
if ( $result )
{
$num = $this -> db -> num_rows ( $result );
2011-02-05 09:12:11 +01:00
$outselect .= '<select class="flat" name="' . $htmlname . '">' ;
$outselect .= '<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 )
{
2010-08-22 20:02:32 +02:00
$outkey = '' ;
$outval = '' ;
$outref = '' ;
2010-08-22 17:46:34 +02:00
$objp = $this -> db -> fetch_object ( $result );
$label = $objp -> label ;
if ( ! empty ( $objp -> label_translated )) $label = $objp -> label_translated ;
2010-10-12 14:56:31 +02:00
if ( $filterkey && $filterkey != '' ) $label = preg_replace ( '/(' . preg_quote ( $filterkey ) . ')/i' , '<strong>$1</strong>' , $label , 1 );
2010-08-22 17:46:34 +02:00
2010-08-22 20:02:32 +02:00
$outkey = $objp -> rowid ;
$outref = $objp -> ref ;
2010-08-22 17:46:34 +02:00
$opt = '<option value="' . $objp -> rowid . '"' ;
2010-11-01 17:00:38 +01:00
$opt .= ( $objp -> rowid == $selected ) ? ' selected="selected"' : '' ;
2010-08-22 17:46:34 +02:00
if ( $conf -> stock -> enabled && $objp -> fk_product_type == 0 && isset ( $objp -> stock ))
{
if ( $objp -> stock > 0 )
{
$opt .= ' style="background-color:#32CD32; color:#F5F5F5;"' ;
}
else if ( $objp -> stock <= 0 )
{
$opt .= ' style="background-color:#FF0000; color:#F5F5F5;"' ;
}
}
2010-08-22 20:02:32 +02:00
$opt .= '>' ;
$opt .= $langs -> convToOutputCharset ( $objp -> ref ) . ' - ' . $langs -> convToOutputCharset ( dol_trunc ( $label , 32 )) . ' - ' ;
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 );
$outval .= $objRef . ' - ' . dol_trunc ( $label , 32 ) . ' - ' ;
2010-08-22 17:46:34 +02:00
$found = 0 ;
$currencytext = $langs -> trans ( " Currency " . $conf -> monnaie );
2010-08-22 20:02:32 +02:00
$currencytextnoent = $langs -> transnoentities ( " Currency " . $conf -> monnaie );
2010-08-24 16:42:18 +02:00
if ( dol_strlen ( $currencytext ) > 10 ) $currencytext = $conf -> monnaie ; // If text is too long, we use the short code
if ( dol_strlen ( $currencytextnoent ) > 10 ) $currencytextnoent = $conf -> monnaie ; // If text is too long, we use the short code
2010-08-22 17:46:34 +02:00
// Multiprice
if ( $price_level >= 1 ) // If we need a particular price level (from 1 to 6)
{
$sql = " SELECT price, price_ttc, price_base_type " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " product_price " ;
$sql .= " WHERE fk_product=' " . $objp -> rowid . " ' " ;
$sql .= " AND price_level= " . $price_level ;
$sql .= " ORDER BY date_price " ;
$sql .= " DESC limit 1 " ;
dol_syslog ( " Form::select_produits_do search price for level '. $price_level .' sql= " . $sql );
$result2 = $this -> db -> query ( $sql );
if ( $result2 )
{
$objp2 = $this -> db -> fetch_object ( $result2 );
if ( $objp2 )
{
$found = 1 ;
if ( $objp2 -> price_base_type == 'HT' )
2010-08-22 20:02:32 +02:00
{
$opt .= price ( $objp2 -> price , 1 ) . ' ' . $currencytext . ' ' . $langs -> trans ( " HT " );
$outval .= price ( $objp2 -> price , 1 ) . ' ' . $currencytextnoent . ' ' . $langs -> transnoentities ( " HT " );
}
2010-08-22 17:46:34 +02:00
else
2010-08-22 20:02:32 +02:00
{
$opt .= price ( $objp2 -> price_ttc , 1 ) . ' ' . $currencytext . ' ' . $langs -> trans ( " TTC " );
$outval .= price ( $objp2 -> price_ttc , 1 ) . ' ' . $currencytextnoent . ' ' . $langs -> transnoentities ( " TTC " );
}
2010-08-22 17:46:34 +02:00
}
}
else
{
dol_print_error ( $this -> db );
}
}
// If level no defined or multiprice not found, we used the default price
if ( ! $found )
{
if ( $objp -> price_base_type == 'HT' )
2010-08-22 20:02:32 +02:00
{
$opt .= price ( $objp -> price , 1 ) . ' ' . $currencytext . ' ' . $langs -> trans ( " HT " );
$outval .= price ( $objp -> price , 1 ) . ' ' . $currencytextnoent . ' ' . $langs -> transnoentities ( " HT " );
}
2010-08-22 17:46:34 +02:00
else
2010-08-22 20:02:32 +02:00
{
$opt .= price ( $objp -> price_ttc , 1 ) . ' ' . $currencytext . ' ' . $langs -> trans ( " TTC " );
$outval .= price ( $objp -> price_ttc , 1 ) . ' ' . $currencytextnoent . ' ' . $langs -> transnoentities ( " TTC " );
}
2010-08-22 17:46:34 +02:00
}
if ( $conf -> stock -> enabled && isset ( $objp -> stock ) && $objp -> fk_product_type == 0 )
{
$opt .= ' - ' . $langs -> trans ( " Stock " ) . ':' . $objp -> stock ;
2010-08-22 20:02:32 +02:00
$outval .= ' - ' . $langs -> transnoentities ( " Stock " ) . ':' . $objp -> stock ;
2010-08-22 17:46:34 +02:00
}
if ( $objp -> duration )
{
2010-08-24 16:42:18 +02:00
$duration_value = substr ( $objp -> duration , 0 , dol_strlen ( $objp -> duration ) - 1 );
2010-08-22 17:46:34 +02:00
$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 ]);
2010-08-22 20:02:32 +02:00
$outval .= ' - ' . $duration_value . ' ' . $langs -> transnoentities ( $dur [ $duration_unit ]);
2010-08-22 17:46:34 +02:00
}
$opt .= " </option> \n " ;
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
2010-08-22 17:46:34 +02:00
$outselect .= $opt ;
2010-08-22 20:02:32 +02:00
array_push ( $outjson , array ( 'key' => $outkey , 'value' => $outref , 'label' => $outval ));
2010-08-22 17:46:34 +02:00
$i ++ ;
}
$outselect .= '</select>' ;
$this -> db -> free ( $result );
2010-08-22 20:02:32 +02:00
if ( empty ( $disableout )) print $outselect ;
return $outjson ;
2010-08-22 17:46:34 +02:00
}
else
{
dol_print_error ( $db );
}
}
/**
2011-02-05 09:12:11 +01:00
* Return list of products for customer in Ajax if Ajax activated or go to select_produits_fournisseurs_do
* @ param socid Id third party
* @ param selected Preselected product
* @ param htmlname Name of HTML Select
* @ param filtertype Filter on product type ( '' = nofilter , 0 = product , 1 = service )
* @ param filtre For a SQL filter
2010-08-22 17:46:34 +02:00
*/
function select_produits_fournisseurs ( $socid , $selected = '' , $htmlname = 'productid' , $filtertype = '' , $filtre )
{
global $langs , $conf ;
if ( $conf -> global -> PRODUIT_USE_SEARCH_TO_SELECT )
{
2010-10-11 12:28:08 +02:00
// mode=2 means suppliers products
2011-07-10 19:28:09 +02:00
print ajax_autocompleter ( '' , $htmlname , DOL_URL_ROOT . '/product/ajaxproducts.php' , 'htmlname=' . $htmlname . '&outjson=1&price_level=' . $price_level . '&type=' . $filtertype . '&mode=2&status=' . $status . '&finished=' . $finished , $conf -> global -> PRODUIT_USE_SEARCH_TO_SELECT );
2010-10-11 12:28:08 +02:00
print $langs -> trans ( " RefOrLabel " ) . ' : <input type="text" size="16" name="search_' . $htmlname . '" id="search_' . $htmlname . '">' ;
print '<br>' ;
2010-08-22 17:46:34 +02:00
}
else
{
2010-08-22 20:02:32 +02:00
$this -> select_produits_fournisseurs_do ( $socid , $selected , $htmlname , $filtertype , $filtre , '' , - 1 , 0 );
2010-08-22 17:46:34 +02:00
}
}
/**
2011-02-05 09:12:11 +01:00
* Retourne la liste des produits de fournisseurs
* @ param socid Id societe fournisseur ( 0 pour aucun filtre )
* @ param selected Produit pre - selectionne
* @ param htmlname Nom de la zone select
* @ param filtertype Filter on product type ( '' = nofilter , 0 = product , 1 = service )
* @ param filtre Pour filtre sql
* @ param filterkey Filtre des produits
* @ param status - 1 = Return all products , 0 = Products not on sell , 1 = Products on sell
* @ param disableout Disable print output
* @ return array Array of keys for json
2010-08-22 17:46:34 +02:00
*/
2010-08-22 20:02:32 +02:00
function select_produits_fournisseurs_do ( $socid , $selected = '' , $htmlname = 'productid' , $filtertype = '' , $filtre = '' , $filterkey = '' , $statut =- 1 , $disableout = 0 )
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, " ;
$sql .= " pf.ref_fourn, " ;
$sql .= " pfp.rowid as idprodfournprice, pfp.price as fprice, pfp.quantity, pfp.unitprice, " ;
$sql .= " s.nom " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " product as p " ;
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " product_fournisseur as pf ON p.rowid = pf.fk_product " ;
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " societe as s ON pf.fk_soc = s.rowid " ;
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " product_fournisseur_price as pfp ON pf.rowid = pfp.fk_product_fournisseur " ;
$sql .= " WHERE p.entity = " . $conf -> entity ;
$sql .= " AND p.tobuy = 1 " ;
if ( $socid ) $sql .= " AND pf.fk_soc = " . $socid ;
if ( strval ( $filtertype ) != '' ) $sql .= " AND p.fk_product_type= " . $filtertype ;
if ( ! empty ( $filtre )) $sql .= " " . $filtre ;
// Add criteria on ref/label
2011-06-16 10:55:59 +02:00
if ( $filterkey && $filterkey != '' )
2010-08-22 17:46:34 +02:00
{
2011-06-16 10:55:59 +02:00
if ( ! empty ( $conf -> global -> PRODUCT_DONOTSEARCH_ANYWHERE ))
{
$sql .= " AND (pf.ref_fourn LIKE ' " . $filterkey . " %' OR p.ref LIKE ' " . $filterkey . " %' OR p.label LIKE ' " . $filterkey . " %') " ;
}
else
{
$sql .= " AND (pf.ref_fourn LIKE '% " . $filterkey . " %' OR p.ref LIKE '% " . $filterkey . " %' OR p.label LIKE '% " . $filterkey . " %') " ;
}
2010-08-22 17:46:34 +02:00
}
$sql .= " ORDER BY pf.ref_fourn DESC " ;
// Build output string
$outselect = '' ;
2010-08-22 20:02:32 +02:00
$outjson = array ();
2010-08-22 17:46:34 +02:00
dol_syslog ( " Form::select_produits_fournisseurs_do sql= " . $sql , LOG_DEBUG );
$result = $this -> db -> query ( $sql );
if ( $result )
{
$num = $this -> db -> num_rows ( $result );
2011-02-05 09:12:11 +01:00
$outselect .= '<select class="flat" id="select' . $htmlname . '" name="' . $htmlname . '">' ;
if ( ! $selected ) $outselect .= '<option value="0" selected="selected"> </option>' ;
else $outselect .= '<option value="0"> </option>' ;
2010-08-22 17:46:34 +02:00
$i = 0 ;
while ( $i < $num )
{
2010-08-22 20:02:32 +02:00
$outkey = '' ;
$outval = '' ;
$outref = '' ;
2010-08-22 17:46:34 +02:00
$objp = $this -> db -> fetch_object ( $result );
2010-08-22 20:02:32 +02:00
$outkey = $objp -> idprodfournprice ;
$outref = $objp -> ref ;
2010-08-22 17:46:34 +02:00
$opt = '<option value="' . $objp -> idprodfournprice . '"' ;
2010-11-01 17:00:38 +01:00
if ( $selected == $objp -> idprodfournprice ) $opt .= ' selected="selected"' ;
2010-08-22 17:46:34 +02:00
if ( $objp -> fprice == '' ) $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
$opt .= $langs -> convToOutputCharset ( $objp -> ref ) . ' (' . $langs -> convToOutputCharset ( $objp -> ref_fourn ) . ') - ' ;
2010-10-12 14:56:31 +02:00
$outval .= $objRef . ' (' . $objRefFourn . ') - ' ;
2010-08-22 20:02:32 +02:00
$opt .= $langs -> convToOutputCharset ( dol_trunc ( $objp -> label , 18 )) . ' - ' ;
2010-10-12 14:56:31 +02:00
$outval .= dol_trunc ( $label , 18 ) . ' - ' ;
2010-08-22 20:02:32 +02:00
2010-08-22 17:46:34 +02:00
if ( $objp -> fprice != '' ) // Keep != ''
{
$currencytext = $langs -> trans ( " Currency " . $conf -> monnaie );
2010-08-22 20:02:32 +02:00
$currencytextnoent = $langs -> transnoentities ( " Currency " . $conf -> monnaie );
2010-08-24 16:42:18 +02:00
if ( dol_strlen ( $currencytext ) > 10 ) $currencytext = $conf -> monnaie ; // If text is too long, we use the short code
if ( dol_strlen ( $currencytextnoent ) > 10 ) $currencytextnoent = $conf -> monnaie ; // If text is too long, we use the short code
2010-08-22 17:46:34 +02:00
2010-08-22 20:02:32 +02:00
$opt .= price ( $objp -> fprice ) . ' ' . $currencytext . " / " . $objp -> quantity ;
$outval .= price ( $objp -> fprice ) . ' ' . $currencytextnoent . " / " . $objp -> quantity ;
2010-08-22 17:46:34 +02:00
if ( $objp -> quantity == 1 )
{
$opt .= strtolower ( $langs -> trans ( " Unit " ));
2010-08-22 20:02:32 +02:00
$outval .= strtolower ( $langs -> transnoentities ( " Unit " ));
2010-08-22 17:46:34 +02:00
}
else
{
$opt .= strtolower ( $langs -> trans ( " Units " ));
2010-08-22 20:02:32 +02:00
$outval .= strtolower ( $langs -> transnoentities ( " Units " ));
2010-08-22 17:46:34 +02:00
}
if ( $objp -> quantity >= 1 )
{
2010-08-22 20:02:32 +02:00
$opt .= " ( " . price ( $objp -> unitprice ) . ' ' . $currencytext . " / " . strtolower ( $langs -> trans ( " Unit " )) . " ) " ;
$outval .= " ( " . price ( $objp -> unitprice ) . ' ' . $currencytextnoent . " / " . strtolower ( $langs -> transnoentities ( " Unit " )) . " ) " ;
}
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 " ;
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
2010-08-22 17:46:34 +02:00
$outselect .= $opt ;
2010-08-22 20:02:32 +02:00
array_push ( $outjson , array ( 'key' => $outkey , 'value' => $outref , 'label' => $outval ));
2010-08-22 17:46:34 +02:00
$i ++ ;
}
$outselect .= '</select>' ;
$this -> db -> free ( $result );
2010-08-22 20:02:32 +02:00
if ( empty ( $disableout )) print $outselect ;
return $outjson ;
2010-08-22 17:46:34 +02:00
}
else
{
dol_print_error ( $db );
}
}
/**
2011-05-10 00:19:14 +02:00
* Return list of suppliers prices for a product
* @ param productid Id of product
* @ param htmlname Name of HTML field
2010-08-22 17:46:34 +02:00
*/
function select_product_fourn_price ( $productid , $htmlname = 'productfournpriceid' )
{
global $langs , $conf ;
$langs -> load ( 'stocks' );
$sql = " SELECT p.rowid, p.label, p.ref, p.price, p.duration, " ;
$sql .= " pf.ref_fourn, " ;
$sql .= " pfp.rowid as idprodfournprice, pfp.price as fprice, pfp.quantity, pfp.unitprice, " ;
$sql .= " s.nom " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " product as p " ;
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " product_fournisseur as pf ON p.rowid = pf.fk_product " ;
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " societe as s ON s.rowid = pf.fk_soc " ;
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " product_fournisseur_price as pfp ON pf.rowid = pfp.fk_product_fournisseur " ;
$sql .= " WHERE p.tobuy = 1 " ;
$sql .= " AND s.fournisseur = 1 " ;
$sql .= " AND p.rowid = " . $productid ;
$sql .= " ORDER BY s.nom, pf.ref_fourn DESC " ;
dol_syslog ( " Form::select_product_fourn_price sql= " . $sql , LOG_DEBUG );
$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
{
$form .= '<option value="0"> </option>' ;
$i = 0 ;
while ( $i < $num )
{
$objp = $this -> db -> fetch_object ( $result );
$opt = '<option value="' . $objp -> idprodfournprice . '"' ;
$opt .= '>' . $objp -> nom . ' - ' . $objp -> ref_fourn . ' - ' ;
if ( $objp -> quantity == 1 )
{
$opt .= price ( $objp -> fprice );
$opt .= $langs -> trans ( " Currency " . $conf -> monnaie ) . " / " ;
}
$opt .= $objp -> quantity . ' ' ;
if ( $objp -> quantity == 1 )
{
$opt .= strtolower ( $langs -> trans ( " Unit " ));
}
else
{
$opt .= strtolower ( $langs -> trans ( " Units " ));
}
if ( $objp -> quantity > 1 )
{
$opt .= " - " ;
$opt .= price ( $objp -> unitprice ) . $langs -> trans ( " Currency " . $conf -> monnaie ) . " / " . strtolower ( $langs -> trans ( " Unit " ));
}
if ( $objp -> duration ) $opt .= " - " . $objp -> duration ;
$opt .= " </option> \n " ;
$form .= $opt ;
$i ++ ;
}
$form .= '</select>' ;
$this -> db -> free ( $result );
}
return $form ;
}
else
{
dol_print_error ( $db );
}
}
/**
2011-08-20 17:11:31 +02:00
* Return list of delivery address
2011-05-10 00:19:14 +02:00
* @ param selected Id contact pre - selectionn
* @ param socid
* @ param htmlname Name of HTML field
* @ param showempty Add an empty field
2010-08-22 17:46:34 +02:00
*/
function select_address ( $selected = '' , $socid , $htmlname = 'address_id' , $showempty = 0 )
{
// 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 " ;
dol_syslog ( " Form::select_address sql= " . $sql );
$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
* @ 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 ;
if ( sizeof ( $this -> cache_conditions_paiements )) return 0 ; // Cache deja charge
$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 " ;
dol_syslog ( 'Form::load_cache_conditions_paiements sql=' . $sql , LOG_DEBUG );
$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
* @ 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-04-01 12:49:57 +02:00
if ( sizeof ( $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 " ;
2011-04-01 12:49:57 +02:00
dol_syslog ( 'Form::load_cache_availability sql=' . $sql , 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 ;
}
}
/**
2011-05-10 00:19:14 +02:00
* Retourne la liste des types de delais de livraison possibles
* @ param selected Id du type de delais pre - selectionne
* @ param htmlname Nom de la zone select
2011-07-17 21:01:26 +02:00
* @ param filtertype To add a filter
* @ param addempty Add empty entry
2011-04-01 12:04:49 +02:00
*/
2011-04-25 16:08:40 +02:00
function select_availability ( $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>' ;
if ( $user -> admin ) print info_admin ( $langs -> trans ( " YouCanChangeValuesForThisListFromDictionnarySetup " ), 1 );
}
2011-04-18 22:56:10 +02:00
/**
2011-05-07 13:36:47 +02:00
* Load into cache cache_demand_reason , array of input reasons
* @ return int Nb of lines loaded , 0 if already loaded , < 0 if ko
2011-04-18 22:56:10 +02:00
*/
2011-04-26 22:59:45 +02:00
function load_cache_demand_reason ()
2011-04-18 22:56:10 +02:00
{
global $langs ;
2011-05-07 13:36:47 +02:00
if ( sizeof ( $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 " ;
2011-04-26 22:59:45 +02:00
dol_syslog ( 'Form::load_cache_demand_reason sql=' . $sql , 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 ++ ;
}
2011-05-09 15:22:10 +02:00
$this -> cache_demand_reason = dol_sort_array ( $tmparray , 'label' , $order = 'asc' , $natsort , $case_sensitive );
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 ;
}
}
/**
2011-05-07 13:36:47 +02:00
* Return list of events that triggered an object creation
* @ param selected Id du type d ' origine pre - selectionne
* @ param htmlname Nom de la zone select
* @ param exclude To exclude a code value ( Example : SRC_PROP )
* @ param addempty Add an empty entry
2011-04-18 22:56:10 +02:00
*/
2011-05-07 13:36:47 +02:00
function select_demand_reason ( $selected = '' , $htmlname = 'demandreasonid' , $exclude = '' , $addempty = 0 )
2011-04-18 22:56:10 +02:00
{
global $langs , $user ;
2011-04-26 22:59:45 +02:00
$this -> load_cache_demand_reason ();
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 ;
if ( $selected == $arraydemandreason [ 'id' ])
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>' ;
if ( $user -> admin ) print info_admin ( $langs -> trans ( " YouCanChangeValuesForThisListFromDictionnarySetup " ), 1 );
}
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
* @ 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 ;
if ( sizeof ( $this -> cache_types_paiements )) return 0 ; // Cache deja charge
$sql = " SELECT id, code, libelle, type " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " c_paiement " ;
$sql .= " WHERE active > 0 " ;
$sql .= " ORDER BY id " ;
dol_syslog ( 'Form::load_cache_types_paiements sql=' . $sql , LOG_DEBUG );
$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 ;
}
else {
dol_print_error ( $this -> db );
return - 1 ;
}
}
/**
2011-08-12 23:29:29 +02:00
* Retourne la liste des types de paiements possibles
*
* @ param selected Id du type de paiement pre - selectionne
* @ param htmlname Nom de la zone select
* @ param filtertype Pour filtre
* @ param addempty Ajoute entree vide
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>' ;
if ( $user -> admin ) print info_admin ( $langs -> trans ( " YouCanChangeValuesForThisListFromDictionnarySetup " ), 1 );
}
/**
2011-02-26 12:10:51 +01:00
* Return list of payment methods
2011-08-12 23:29:29 +02:00
*
2011-02-26 12:10:51 +01:00
* @ param selected Id du mode de paiement pre - selectionne
* @ param htmlname Nom de la zone select
2011-05-01 20:22:58 +02:00
* @ param filtertype To filter on field type in llx_c_paiement ( array ( 'code' => xx , 'label' => zz ))
* @ param format 0 = id + libelle , 1 = code + code , 2 = code + libelle , 3 = id + code
2011-02-26 12:10:51 +01:00
* @ param empty 1 = peut etre vide , 0 sinon
* @ param noadmininfo 0 = Add admin info , 1 = Disable admin info
2011-05-01 20:22:58 +02:00
* @ param maxlength Max length of label
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 ;
dol_syslog ( " Form::select_type_paiements $selected , $htmlname , $filtertype , $format " , LOG_DEBUG );
$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
if ( sizeof ( $filterarray ) && ! in_array ( $arraytypes [ 'type' ], $filterarray )) continue ;
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>' ;
if ( $user -> admin && ! $noadmininfo ) print info_admin ( $langs -> trans ( " YouCanChangeValuesForThisListFromDictionnarySetup " ), 1 );
}
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
*
* @ param selected Id pre - selectionne
* @ param htmlname Nom de la zone select
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
*
* @ param selected Id pre - selectionne
* @ param htmlname Nom de la zone select
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 (
2010-05-03 10:22:35 +02: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 ;
}
2011-08-12 23:29:29 +02:00
2010-08-22 17:46:34 +02:00
/**
2011-07-13 16:03:15 +02:00
* Return combo list of differents status of a proposal
* Values are id of table c_propalst
2011-08-12 23:29:29 +02:00
*
* @ param selected etat pre - selectionne
* @ param short Use short labels
2010-08-22 17:46:34 +02:00
*/
2011-08-12 23:29:29 +02:00
function select_propal_statut ( $selected = '' , $short = 0 )
2010-08-22 17:46:34 +02:00
{
2011-07-13 16:03:15 +02:00
global $langs ;
2010-08-22 17:46:34 +02:00
$sql = " SELECT id, code, label, active FROM " . MAIN_DB_PREFIX . " c_propalst " ;
$sql .= " WHERE active = 1 " ;
dol_syslog ( " Form::select_propal_statut sql= " . $sql );
$resql = $this -> db -> query ( $sql );
if ( $resql )
{
print '<select class="flat" name="propal_statut">' ;
print '<option value=""> </option>' ;
$num = $this -> db -> num_rows ( $resql );
$i = 0 ;
if ( $num )
{
while ( $i < $num )
{
$obj = $this -> db -> fetch_object ( $resql );
if ( $selected == $obj -> id )
{
2010-11-01 17:00:38 +01:00
print '<option value="' . $obj -> id . '" selected="selected">' ;
2010-08-22 17:46:34 +02:00
}
else
{
print '<option value="' . $obj -> id . '">' ;
}
2011-08-12 23:29:29 +02:00
$key = $obj -> code ;
if ( $langs -> trans ( " PropalStatus " . $key . ( $short ? 'Short' : '' )) != " PropalStatus " . $key . ( $short ? 'Short' : '' ))
{
print $langs -> trans ( " PropalStatus " . $key . ( $short ? 'Short' : '' ));
}
else
{
$conv_to_new_code = array ( 'PR_DRAFT' => 'Draft' , 'PR_OPEN' => 'Opened' , 'PR_CLOSED' => 'Closed' , 'PR_SIGNED' => 'Signed' , 'PR_NOTSIGNED' => 'NotSigned' , 'PR_FAC' => 'Billed' );
if ( ! empty ( $conv_to_new_code [ $obj -> code ])) $key = $conv_to_new_code [ $obj -> code ];
print ( $langs -> trans ( " PropalStatus " . $key . ( $short ? 'Short' : '' )) != " PropalStatus " . $key . ( $short ? 'Short' : '' )) ? $langs -> trans ( " PropalStatus " . $key . ( $short ? 'Short' : '' )) : $obj -> label ;
}
2010-08-22 17:46:34 +02:00
print '</option>' ;
$i ++ ;
}
}
print '</select>' ;
}
else
{
dol_print_error ( $this -> db );
}
}
/**
2011-05-25 14:45:27 +02:00
* Return a HTML select list of bank accounts
2011-08-12 23:29:29 +02:00
*
2010-08-29 23:11:42 +02:00
* @ param selected Id account pre - selected
* @ param htmlname Name of select zone
* @ param statut Status of searched accounts ( 0 = open , 1 = closed )
* @ param filtre To filter list
2011-02-05 18:25:56 +01:00
* @ param useempty 1 = Add an empty value in list , 2 = Add an empty value in list only if there is more than 2 entries .
2011-02-07 17:27:19 +01:00
* @ param moreattrib To add more attribute on select
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 " );
$sql = " SELECT rowid, label, bank " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " bank_account " ;
$sql .= " WHERE clos = ' " . $statut . " ' " ;
$sql .= " AND entity = " . $conf -> entity ;
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
dol_syslog ( " Form::select_comptes sql= " . $sql );
$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
{
print '<option value="' . $obj -> rowid . '"> </option>' ;
}
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
{
print $langs -> trans ( " NoActiveBankAccountDefined " );
}
}
else {
dol_print_error ( $this -> db );
}
}
/**
2010-10-20 00:52:32 +02:00
* Return list of categories having choosed type
2011-08-12 23:29:29 +02:00
*
2010-10-20 00:52:32 +02:00
* @ param type Type de categories ( 0 = product , 1 = supplier , 2 = customer , 3 = member )
* @ param selected Id of category preselected
* @ param select_name HTML field name
* @ param maxlength Maximum length for labels
* @ param excludeafterid Exclude all categories after this leaf in category tree .
2010-08-22 17:46:34 +02:00
*/
2010-10-20 00:52:32 +02:00
function select_all_categories ( $type , $selected = '' , $select_name = " " , $maxlength = 64 , $excludeafterid = 0 )
2010-08-22 17:46:34 +02:00
{
global $langs ;
$langs -> load ( " categories " );
if ( $select_name == " " ) $select_name = " catMere " ;
$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
$output = '<select class="flat" name="' . $select_name . '">' ;
if ( is_array ( $cate_arbo ))
{
2011-08-31 17:12:09 +02:00
if ( ! sizeof ( $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 )
{
if ( $cate_arbo [ $key ][ 'id' ] == $selected )
{
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
2010-09-01 09:48:33 +02:00
/**
* Show a confirmation HTML form or AJAX popup
2011-08-12 23:29:29 +02:00
*
2010-09-01 09:48:33 +02:00
* @ param page Url of page to call if confirmation is OK
* @ param title title
* @ param question question
* @ param action action
* @ param formquestion an array with forms complementary inputs
* @ param selectedchoice " " or " no " or " yes "
* @ param useajax 0 = No , 1 = Yes , 2 = Yes but submit page with & confirm = no if choice is No
2010-12-13 19:40:04 +01:00
* @ param height Force height of box
2010-09-01 09:48:33 +02:00
* @ return string 'ajax' if a confirm ajax popup is shown , 'html' if it ' s an html form
*/
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
{
2011-04-25 22:18:09 +02: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
/**
* Show a confirmation HTML form or AJAX popup
2011-08-12 23:29:29 +02:00
*
2010-08-22 17:46:34 +02:00
* @ param page Url of page to call if confirmation is OK
* @ param title title
* @ param question question
* @ param action action
2011-01-29 18:41:26 +01:00
* @ param formquestion an array with complementary inputs to add into forms : array ( array ( 'label' => , 'type' => , ))
2010-08-22 17:46:34 +02:00
* @ param selectedchoice " " or " no " or " yes "
* @ param useajax 0 = No , 1 = Yes , 2 = Yes but submit page with & confirm = no if choice is No
2010-12-13 19:40:04 +01:00
* @ param height Force height of box
2010-08-22 17:46:34 +02:00
* @ return string 'ajax' if a confirm ajax popup is shown , 'html' if it ' s an html form
*/
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 ;
$more = '' ;
2010-09-01 09:48:33 +02:00
$formconfirm = '' ;
2011-04-24 22:24:50 +02:00
$inputarray = array ();
2010-09-02 21:31:18 +02:00
2010-08-22 17:46:34 +02:00
if ( $formquestion )
{
2011-04-25 11:27:25 +02:00
$more .= '<table class="nobordernopadding" width="100%">' . " \n " ;
2010-08-22 17:46:34 +02:00
$more .= '<tr><td colspan="3" valign="top">' . $formquestion [ 'text' ] . '</td></tr>' . " \n " ;
foreach ( $formquestion as $key => $input )
{
2011-04-25 22:18:09 +02:00
if ( is_array ( $input ))
{
if ( $input [ 'type' ] == 'text' )
{
$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="' . $input [ 'size' ] . '" value="' . $input [ 'value' ] . '" /></td></tr>' . " \n " ;
}
else if ( $input [ 'type' ] == 'password' )
{
$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="' . $input [ 'size' ] . '" value="' . $input [ 'value' ] . '" /></td></tr>' . " \n " ;
}
else if ( $input [ 'type' ] == 'select' )
{
$more .= '<tr><td valign="top">' ;
if ( ! empty ( $input [ 'label' ])) $more .= $input [ 'label' ] . '</td><td valign="top" colspan="2" align="left">' ;
2011-05-25 14:05:18 +02:00
$more .= $this -> selectarray ( $input [ 'name' ], $input [ 'values' ], $input [ 'default' ], 1 );
2011-04-25 22:18:09 +02:00
$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' ] . '"' ;
2011-08-31 16:55:54 +02:00
if ( ! is_bool ( $input [ 'value' ]) && $input [ 'value' ] != 'false' ) $more .= ' checked="checked"' ;
if ( is_bool ( $input [ 'value' ]) && $input [ 'value' ]) $more .= ' checked="checked"' ;
2011-08-31 17:12:09 +02:00
if ( $input [ 'disabled' ]) $more .= ' disabled="disabled"' ;
2011-04-25 22:18:09 +02: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 . '"' ;
2011-08-31 17:12:09 +02:00
if ( $input [ 'disabled' ]) $more .= ' disabled="disabled"' ;
2011-04-25 22:18:09 +02:00
$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 " ;
}
array_push ( $inputarray , $input [ 'name' ]);
}
2010-08-22 17:46:34 +02:00
}
$more .= '</table>' . " \n " ;
}
2010-09-01 09:48:33 +02:00
$formconfirm .= " \n <!-- begin form_confirm --> \n " ;
2010-08-22 17:46:34 +02:00
2011-05-18 14:07:38 +02:00
if ( $useajax && $conf -> use_javascript_ajax )
2010-08-22 17:46:34 +02:00
{
2011-05-14 11:21:24 +02:00
$autoOpen = true ;
$dialogconfirm = 'dialog-confirm' ;
if ( ! is_int ( $useajax )) {
2011-05-14 16:07:07 +02:00
$button = $useajax ;
$useajax = 1 ;
2011-05-14 11:21:24 +02:00
$autoOpen = false ;
$dialogconfirm .= '-' . $button ;
}
2010-08-22 17:46:34 +02:00
$pageyes = $page . '&action=' . $action . '&confirm=yes' ;
$pageno = ( $useajax == 2 ? $page . '&confirm=no' : '' );
// New code using jQuery only
2011-05-14 16:07:07 +02:00
$formconfirm .= '<div id="' . $dialogconfirm . '" title="' . dol_escape_htmltag ( $title ) . '" style="display: none;">' ;
2011-04-25 11:27:25 +02:00
if ( ! empty ( $more )) $formconfirm .= '<p>' . $more . '</p>' ;
2011-04-25 16:08:40 +02:00
$formconfirm .= img_help ( '' , '' ) . ' ' . $question ;
2010-09-01 09:48:33 +02:00
$formconfirm .= '</div>' . " \n " ;
$formconfirm .= ' < script type = " text/javascript " >
2011-05-14 11:21:24 +02:00
$ ( function () {
2010-08-18 21:00:57 +02:00
var choice = \ ' ko\ ' ;
2011-04-24 22:24:50 +02:00
var $inputarray = '.json_encode($inputarray).' ;
2011-05-14 13:34:15 +02:00
var button = \ '' . $button . ' \ ' ;
var dialogconfirm = \ '' . $dialogconfirm . ' \ ' ;
2011-05-18 13:57:33 +02:00
2011-05-14 13:34:15 +02:00
$ ( " # " + dialogconfirm ) . dialog ({
2011-05-14 11:21:24 +02:00
autoOpen : '.($autoOpen?' true ':' false ').' ,
2010-08-18 21:00:57 +02:00
resizable : false ,
2010-12-13 19:40:04 +01:00
height : '.$height.' ,
2011-04-25 16:08:40 +02:00
width : '.$width.' ,
2010-08-18 21:00:57 +02:00
modal : true ,
closeOnEscape : false ,
close : function ( event , ui ) {
2011-04-24 22:24:50 +02:00
if ( choice == \ ' ok\ ' ) {
var options = " " ;
if ( $inputarray . length > 0 ) {
$ . each ( $inputarray , function () {
var inputname = this ;
var inputvalue = $ ( " # " + this ) . val ();
options += \ ' & \ ' + inputname + \ ' = \ ' + inputvalue ;
});
//alert( options );
}
location . href = \ '' . $pageyes . ' \ ' + options ;
}
2010-08-18 21:00:57 +02:00
'.($pageno?' if ( choice == \ 'ko\') location.href=\'' . $pageno . '\';' : '' ) . '
},
buttons : {
2010-08-19 21:04:49 +02:00
\ '' . dol_escape_js ( $langs -> transnoentities ( " Yes " )) . ' \ ' : function () {
2011-05-14 11:21:24 +02:00
choice = \ ' ok\ ' ;
$ ( this ) . dialog ( \ ' close\ ' );
2010-08-18 21:00:57 +02:00
},
2010-08-19 21:04:49 +02:00
\ '' . dol_escape_js ( $langs -> transnoentities ( " No " )) . ' \ ' : function () {
2011-05-14 11:21:24 +02:00
choice = \ ' ko\ ' ;
$ ( this ) . dialog ( \ ' close\ ' );
2010-08-18 21:00:57 +02:00
}
}
});
2011-05-18 13:57:33 +02:00
2011-05-14 13:34:15 +02:00
if ( button . length > 0 ) {
$ ( " # " + button ) . click ( function () {
$ ( " # " + dialogconfirm ) . dialog ( \ ' open\ ' );
});
}
2011-05-14 11:21:24 +02:00
});
2010-08-18 21:00:57 +02:00
</ script > ' ;
2010-05-03 10:22:35 +02:00
2010-09-01 09:48:33 +02:00
$formconfirm .= " \n " ;
2010-08-22 17:46:34 +02:00
}
else
{
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
// Ligne titre
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
// Ligne formulaire
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
// Ligne message
2010-09-01 09:48:33 +02:00
$formconfirm .= '<tr class="valid">' ;
$formconfirm .= '<td class="valid">' . $question . '</td>' ;
$formconfirm .= '<td class="valid">' ;
2010-08-22 17:46:34 +02:00
$newselectedchoice = empty ( $selectedchoice ) ? " no " : $selectedchoice ;
2010-09-01 09:48:33 +02:00
$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
if ( is_array ( $formquestion ))
{
foreach ( $formquestion as $key => $input )
{
2010-09-01 09:48:33 +02:00
if ( $input [ 'type' ] == 'hidden' ) $formconfirm .= '<input type="hidden" name="' . $input [ 'name' ] . '" value="' . $input [ 'value' ] . '">' ;
2010-08-22 17:46:34 +02:00
}
}
2010-09-01 09:48:33 +02:00
$formconfirm .= " </form> \n " ;
$formconfirm .= '<br>' ;
2010-08-22 17:46:34 +02:00
}
2010-09-01 09:48:33 +02:00
$formconfirm .= " <!-- end form_confirm --> \n " ;
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-05-07 13:47:38 +02:00
* @ param page Page
* @ param socid Id societe
* @ param selected Id projet pre - selectionne
* @ param htmlname Nom du formulaire select
2010-08-22 17:46:34 +02:00
*/
function form_project ( $page , $socid , $selected = '' , $htmlname = 'projectid' )
{
global $langs ;
require_once ( DOL_DOCUMENT_ROOT . " /lib/project.lib.php " );
$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";
select_projects ( $socid , $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 ) {
$projet = new Project ( $this -> db );
$projet -> fetch ( $selected );
//print '<a href="'.DOL_URL_ROOT.'/projet/fiche.php?id='.$selected.'">'.$projet->title.'</a>';
print $projet -> getNomUrl ( 0 );
} else {
print " " ;
}
}
}
/**
2011-05-07 13:47:38 +02:00
* Show a form to select payment conditions
2011-08-12 23:29:29 +02:00
*
2011-05-07 13:47:38 +02:00
* @ param page Page
* @ param selected Id condition pre - selectionne
* @ param htmlname Name of select html field
* @ param addempty Ajoute entree vide
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 " " ;
}
}
}
2011-04-01 12:04:49 +02:00
/**
2011-05-07 13:47:38 +02:00
* Show a form to select a delivery delay
2011-08-12 23:29:29 +02:00
*
2011-05-07 13:47:38 +02:00
* @ param page Page
* @ param selected Id condition pre - selectionne
* @ param htmlname Name of select html field
* @ param addempty Ajoute entree vide
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>' ;
2011-04-01 12:49:57 +02:00
$this -> select_availability ( $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 " " ;
}
}
}
2011-04-18 22:56:10 +02:00
/**
2011-05-07 13:47:38 +02:00
* Show a select form to select origin
2011-08-12 23:29:29 +02:00
*
2011-05-07 13:36:47 +02:00
* @ param page Page
* @ param selected Id condition pre - selectionne
* @ param htmlname Name of select html field
2011-05-07 13:47:38 +02:00
* @ param addempty Add empty entry
2011-04-18 22:56:10 +02:00
*/
2011-04-26 22:59:45 +02:00
function form_demand_reason ( $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>' ;
2011-04-26 22:59:45 +02:00
$this -> select_demand_reason ( $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 )
{
2011-04-26 22:59:45 +02:00
$this -> load_cache_demand_reason ();
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
/**
2011-05-07 13:47:38 +02:00
* Show a form to select a date
2011-08-12 23:29:29 +02:00
*
2011-05-07 13:47:38 +02:00
* @ param page Page
* @ param selected Date preselected
* @ param htmlname Name of input html field
2010-08-22 17:46:34 +02:00
*/
function form_date ( $page , $selected = '' , $htmlname )
{
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>' ;
print $this -> select_date ( $selected , $htmlname , 0 , 0 , 1 , 'form' . $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-05-07 13:47:38 +02:00
* Show a select form to choose a user
2011-08-12 23:29:29 +02:00
*
2011-05-07 13:47:38 +02:00
* @ param page Page
* @ param selected Id of user preselected
* @ param htmlname Name of input html field
* @ param exclude List of users id to exclude
* @ param include List of users id to include
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 )
{
require_once ( DOL_DOCUMENT_ROOT . " /user/class/user.class.php " );
//$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
*
* @ param page Page
* @ param selected Id mode pre - selectionne
* @ param htmlname Name of select html field
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-02-19 13:15:17 +01:00
* Show a select box with available absolute discounts
2011-08-12 23:29:29 +02:00
*
2011-02-19 13:15:17 +01:00
* @ param page Page URL where form is shown
* @ param selected Value pre - selected
* @ param htmlname Nom du formulaire select . Si none , non modifiable
* @ param socid Third party id
* @ param amount Total amount available
* @ param filter SQL filter on discounts
* @ param maxvalue Max value for lines that can be selected
* @ param more More string to add
2010-08-22 17:46:34 +02:00
*/
2011-02-19 13:15:17 +01:00
function form_remise_dispo ( $page , $selected = '' , $htmlname = 'remise_id' , $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">' ;
2011-02-19 13:15:17 +01:00
print '<tr><td nowrap="nowrap">' ;
2010-08-22 17:46:34 +02:00
if ( ! $filter || $filter == 'fk_facture_source IS NULL' ) print $langs -> trans ( " CompanyHasAbsoluteDiscount " , price ( $amount ), $langs -> transnoentities ( " Currency " . $conf -> monnaie )) . ': ' ;
else print $langs -> trans ( " CompanyHasCreditNote " , price ( $amount ), $langs -> transnoentities ( " Currency " . $conf -> monnaie )) . ': ' ;
// print $langs->trans("AvailableGlobalDiscounts").': ';
$newfilter = 'fk_facture IS NULL AND fk_facture_line IS NULL' ; // Remises disponibles
if ( $filter ) $newfilter .= ' AND ' . $filter ;
$nbqualifiedlines = $this -> select_remises ( '' , $htmlname , $newfilter , $socid , $maxvalue );
print '</td>' ;
2011-02-19 13:15:17 +01:00
print '<td>' ;
2010-08-22 17:46:34 +02:00
if ( $nbqualifiedlines > 0 )
{
print ' <input type="submit" class="button" value="' ;
if ( ! $filter || $filter == 'fk_facture_source IS NULL' ) print $langs -> trans ( " UseDiscount " );
else print $langs -> trans ( " UseCredit " );
print '" title="' . $langs -> trans ( " UseCreditNoteInInvoicePayment " ) . '">' ;
}
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
*
* @ param page Page
* @ param selected Id contact pre - selectionne
* @ param htmlname Nom du formulaire select
2010-08-22 17:46:34 +02:00
*/
function form_contacts ( $page , $societe , $selected = '' , $htmlname = 'contactidp' )
{
global $langs ;
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 )
{
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>' ;
print '<a href="' . DOL_URL_ROOT . '/contact/fiche.php?socid=' . $societe -> id . '&action=create&backtoreferer=1">' . $langs -> trans ( 'AddContact' ) . '</a>' ;
}
print '</td>' ;
print '<td align="left"><input type="submit" class="button" value="' . $langs -> trans ( " Modify " ) . '"></td>' ;
print '</tr></table></form>' ;
}
else
{
if ( $selected )
{
require_once ( DOL_DOCUMENT_ROOT . " /contact/class/contact.class.php " );
//$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
2011-06-29 17:48:02 +02:00
/**
2011-08-12 23:29:29 +02:00
* Affiche formulaire de selection des tiers
*
* @ param page Page
* @ param selected Id contact pre - selectionne
* @ param htmlname Nom du formulaire select
2011-06-29 17:48:02 +02:00
*/
function form_thirdparty ( $page , $selected = '' , $htmlname = 'socid' )
{
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>' ;
$num = $this -> select_societes ( $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 )
{
require_once ( DOL_DOCUMENT_ROOT . " /societe/class/societe.class.php " );
$soc = new Societe ( $this -> db );
$soc -> fetch ( $selected );
print $soc -> getNomUrl ( $langs );
} else {
print " " ;
}
}
}
2010-08-22 17:46:34 +02:00
/**
2011-08-12 23:29:29 +02:00
* Affiche formulaire de selection de l ' adresse
*
* @ param page Page
* @ param selected Id condition pre - selectionne
* @ param htmlname Nom du formulaire select
* @ param origin Origine de l ' appel pour pouvoir creer un retour
* @ param originid Id de l ' origine
2010-08-22 17:46:34 +02:00
*/
function form_address ( $page , $selected = '' , $socid , $htmlname = 'address_id' , $origin = '' , $originid = '' )
{
global $langs , $conf ;
if ( $htmlname != " none " )
{
print '<form method="post" action="' . $page . '">' ;
print '<input type="hidden" name="action" value="setaddress">' ;
print '<input type="hidden" name="token" value="' . $_SESSION [ 'newtoken' ] . '">' ;
print '<table class="nobordernopadding" cellpadding="0" cellspacing="0">' ;
print '<tr><td>' ;
$this -> select_address ( $selected , $socid , $htmlname , 1 );
print '</td>' ;
print '<td align="left"><input type="submit" class="button" value="' . $langs -> trans ( " Modify " ) . '">' ;
$langs -> load ( " companies " );
print ' <a href=' . DOL_URL_ROOT . '/comm/address.php?socid=' . $socid . '&action=create&origin=' . $origin . '&originid=' . $originid . '>' . $langs -> trans ( " AddAddress " ) . '</a>' ;
print '</td></tr></table></form>' ;
}
else
{
if ( $selected )
{
require_once ( DOL_DOCUMENT_ROOT . " /societe/class/address.class.php " );
$address = new Address ( $this -> db );
$result = $address -> fetch_address ( $selected );
print '<a href=' . DOL_URL_ROOT . '/comm/address.php?socid=' . $address -> socid . '&id=' . $address -> id . '&action=edit&origin=' . $origin . '&originid=' . $originid . '>' . $address -> label . '</a>' ;
}
else
{
print " " ;
}
}
}
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
*
2010-10-21 15:34:31 +02:00
* @ param selected code devise pre - selectionne
* @ param htmlname nom de la liste deroulante
*/
function select_currency ( $selected = '' , $htmlname = 'currency_id' )
{
print $this -> selectcurrency ( $selected , $htmlname );
}
2010-10-22 10:11:51 +02:00
2010-08-22 17:46:34 +02:00
/**
2011-03-10 12:49:46 +01:00
* Retourne la liste des devises , dans la langue de l ' utilisateur
2011-08-12 23:29:29 +02:00
*
2011-03-10 12:49:46 +01:00
* @ param selected code devise pre - selectionne
* @ param htmlname nom de la liste deroulante
2010-08-22 17:46:34 +02:00
*/
2010-10-21 15:34:31 +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
2010-08-22 17:46:34 +02:00
$langs -> load ( " dict " );
2010-10-22 10:11:51 +02:00
2010-10-21 15:34:31 +02:00
$out = '' ;
2011-03-10 12:49:46 +01:00
$currencyArray = array ();
$label = array ();
2010-08-22 17:46:34 +02:00
if ( $selected == 'euro' || $selected == 'euros' ) $selected = 'EUR' ; // Pour compatibilite
2011-03-10 12:49:46 +01:00
$sql = " SELECT code_iso, label " ;
2010-08-22 17:46:34 +02:00
$sql .= " FROM " . MAIN_DB_PREFIX . " c_currencies " ;
$sql .= " WHERE active = 1 " ;
$sql .= " ORDER BY code_iso ASC " ;
$resql = $this -> db -> query ( $sql );
if ( $resql )
{
2010-10-21 15:34:31 +02:00
$out .= '<select class="flat" name="' . $htmlname . '">' ;
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
2011-03-10 12:49:46 +01:00
while ( $i < $num ) {
2010-08-22 17:46:34 +02:00
$obj = $this -> db -> fetch_object ( $resql );
2011-03-10 12:49:46 +01:00
$currencyArray [ $i ][ 'code_iso' ] = $obj -> code_iso ;
$currencyArray [ $i ][ 'label' ] = ( $obj -> code_iso && $langs -> trans ( " Currency " . $obj -> code_iso ) != " Currency " . $obj -> code_iso ? $langs -> trans ( " Currency " . $obj -> code_iso ) : ( $obj -> label != '-' ? $obj -> label : '' ));
$label [ $i ] = $currencyArray [ $i ][ 'label' ];
$i ++ ;
}
array_multisort ( $label , SORT_ASC , $currencyArray );
2011-03-19 03:17:05 +01:00
2011-03-10 12:49:46 +01:00
foreach ( $currencyArray as $row ) {
if ( $selected && $selected == $row [ 'code_iso' ]) {
2010-08-22 17:46:34 +02:00
$foundselected = true ;
2011-03-10 12:49:46 +01:00
$out .= '<option value="' . $row [ 'code_iso' ] . '" selected="selected">' ;
} else {
$out .= '<option value="' . $row [ 'code_iso' ] . '">' ;
2010-08-22 17:46:34 +02:00
}
2011-03-10 13:09:59 +01:00
$out .= $row [ 'label' ];
2011-03-19 11:37:50 +01:00
if ( $row [ 'code_iso' ]) $out .= ' (' . $row [ 'code_iso' ] . ')' ;
2010-10-21 15:34:31 +02:00
$out .= '</option>' ;
2010-08-22 17:46:34 +02:00
}
}
2010-10-21 15:34:31 +02:00
$out .= '</select>' ;
if ( $user -> admin ) $out .= info_admin ( $langs -> trans ( " YouCanChangeValuesForThisListFromDictionnarySetup " ), 1 );
return $out ;
2010-08-22 17:46:34 +02:00
}
2010-10-21 15:34:31 +02:00
else
{
2010-08-22 17:46:34 +02:00
dol_print_error ( $this -> db );
}
}
/**
2011-08-12 23:29:29 +02:00
* Output an HTML select vat rate
*
* @ param htmlname Nom champ html
* @ param selectedrate Forcage du taux tva pre - selectionne . Mettre '' pour aucun forcage .
* @ param societe_vendeuse Objet societe vendeuse
* @ param societe_acheteuse Objet societe acheteuse
* @ param idprod Id product
2011-09-05 13:09:33 +02:00
* @ param info_bits Miscellaneous information on line
2011-08-12 23:29:29 +02:00
* @ param type '' = Unknown , 0 = Product , 1 = Service ( Used if idprod not defined )
* Si vendeur non assujeti a TVA , TVA par defaut = 0. Fin de regle .
2010-08-22 17:46:34 +02:00
* Si le ( pays vendeur = pays acheteur ) alors la TVA par defaut = TVA du produit vendu . Fin de regle .
* Si ( vendeur et acheteur dans Communaute europeenne ) et bien vendu = moyen de transports neuf ( auto , bateau , avion ), TVA par defaut = 0 ( La TVA doit etre paye par l 'acheteur au centre d' impots de son pays et non au vendeur ) . Fin de regle .
* Si ( vendeur et acheteur dans Communaute europeenne ) et bien vendu autre que transport neuf alors la TVA par defaut = TVA du produit vendu . Fin de regle .
* Sinon la TVA proposee par defaut = 0. Fin de regle .
2011-08-04 23:46:50 +02:00
* @ deprecated
2010-08-22 17:46:34 +02:00
*/
2011-02-05 10:26:33 +01:00
function select_tva ( $htmlname = 'tauxtva' , $selectedrate = '' , $societe_vendeuse = '' , $societe_acheteuse = '' , $idprod = 0 , $info_bits = 0 , $type = '' )
2010-08-22 17:46:34 +02:00
{
2011-02-05 10:26:33 +01:00
print $this -> load_tva ( $htmlname , $selectedrate , $societe_vendeuse , $societe_acheteuse , $idprod , $info_bits , $type );
2010-08-22 17:46:34 +02:00
}
/**
2011-08-12 23:29:29 +02:00
* Output an HTML select vat rate
*
* @ param htmlname Nom champ html
* @ param selectedrate Forcage du taux tva pre - selectionne . Mettre '' pour aucun forcage .
* @ param societe_vendeuse Objet societe vendeuse
* @ param societe_acheteuse Objet societe acheteuse
* @ param idprod Id product
2011-09-05 13:09:33 +02:00
* @ param info_bits Miscellaneous information on line
2011-08-12 23:29:29 +02:00
* @ param type '' = Unknown , 0 = Product , 1 = Service ( Used if idprod not defined )
* Si vendeur non assujeti a TVA , TVA par defaut = 0. Fin de regle .
2010-08-22 17:46:34 +02:00
* Si le ( pays vendeur = pays acheteur ) alors la TVA par defaut = TVA du produit vendu . Fin de regle .
* Si ( vendeur et acheteur dans Communaute europeenne ) et bien vendu = moyen de transports neuf ( auto , bateau , avion ), TVA par defaut = 0 ( La TVA doit etre paye par l 'acheteur au centre d' impots de son pays et non au vendeur ) . Fin de regle .
* Si ( vendeur et acheteur dans Communaute europeenne ) et bien vendu autre que transport neuf alors la TVA par defaut = TVA du produit vendu . Fin de regle .
* Sinon la TVA proposee par defaut = 0. Fin de regle .
*/
2011-02-05 10:26:33 +01:00
function load_tva ( $htmlname = 'tauxtva' , $selectedrate = '' , $societe_vendeuse = '' , $societe_acheteuse = '' , $idprod = 0 , $info_bits = 0 , $type = '' )
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
2010-08-22 17:46:34 +02:00
if ( is_object ( $societe_vendeuse ) && ! $societe_vendeuse -> pays_code )
{
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);
2010-09-15 16:11:43 +02:00
//print "name=$name, selectedrate=$selectedrate, seller=".$societe_vendeuse->pays_code." buyer=".$societe_acheteuse->pays_code." buyer is company=".$societe_acheteuse->isACompany()." idprod=$idprod, info_bits=$info_bits type=$type";
2010-09-15 15:29:17 +02:00
//exit;
// Get list of all VAT rates to show
// First we defined code_pays to use to find list
2010-08-22 17:46:34 +02:00
if ( is_object ( $societe_vendeuse ))
{
2010-09-15 15:29:17 +02:00
$code_pays = " ' " . $societe_vendeuse -> pays_code . " ' " ;
}
else
{
$code_pays = " ' " . $mysoc -> pays_code . " ' " ; // Pour compatibilite ascendente
}
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
{
2010-09-15 16:11:43 +02:00
if ( ! $societe_vendeuse -> isInEEC () && $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
{
$code_pays .= " ,' " . $societe_acheteuse -> pays_code . " ' " ;
}
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
{
$code_pays .= " ,' " . $societe_acheteuse -> pays_code . " ' " ;
}
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
{
$code_pays .= " ,' " . $societe_acheteuse -> pays_code . " ' " ;
}
}
2010-08-22 17:46:34 +02:00
}
}
2010-09-15 15:29:17 +02:00
// Now we get list
$sql = " SELECT DISTINCT t.taux, t.recuperableonly " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " c_tva as t, " . MAIN_DB_PREFIX . " c_pays as p " ;
$sql .= " WHERE t.fk_pays = p.rowid " ;
$sql .= " AND t.active = 1 " ;
$sql .= " AND p.code in ( " . $code_pays . " ) " ;
$sql .= " ORDER BY t.taux ASC, t.recuperableonly ASC " ;
2010-08-22 17:46:34 +02:00
$resql = $this -> db -> query ( $sql );
if ( $resql )
{
$num = $this -> db -> num_rows ( $resql );
if ( $num )
{
for ( $i = 0 ; $i < $num ; $i ++ )
{
$obj = $this -> db -> fetch_object ( $resql );
$txtva [ $i ] = $obj -> taux ;
$libtva [ $i ] = $obj -> taux . '%' ;
$nprtva [ $i ] = $obj -> recuperableonly ;
}
}
else
{
$return .= '<font class="error">' . $langs -> trans ( " ErrorNoVATRateDefinedForSellerCountry " , $code_pays ) . '</font>' ;
}
}
else
{
$return .= '<font class="error">' . $this -> db -> error () . '</font>' ;
}
// Definition du taux a pre-selectionner (si defaulttx non force et donc vaut -1 ou '')
2010-08-24 16:42:18 +02:00
if ( $defaulttx < 0 || dol_strlen ( $defaulttx ) == 0 )
2010-08-22 17:46:34 +02:00
{
$defaulttx = get_default_tva ( $societe_vendeuse , $societe_acheteuse , $idprod );
$defaultnpr = get_default_npr ( $societe_vendeuse , $societe_acheteuse , $idprod );
}
2011-08-04 23:46:50 +02:00
2010-08-22 17:46:34 +02:00
// Si taux par defaut n'a pu etre determine, on prend dernier de la liste.
// Comme ils sont tries par ordre croissant, dernier = plus eleve = taux courant
2010-08-24 16:42:18 +02:00
if ( $defaulttx < 0 || dol_strlen ( $defaulttx ) == 0 )
2010-08-22 17:46:34 +02:00
{
$defaulttx = $txtva [ sizeof ( $txtva ) - 1 ];
}
$nbdetaux = sizeof ( $txtva );
2010-09-15 15:29:17 +02:00
if ( $nbdetaux > 0 )
2010-08-22 17:46:34 +02:00
{
2011-02-05 10:26:33 +01:00
$return .= '<select class="flat" id="' . $htmlname . '" name="' . $htmlname . '">' ;
2010-08-22 17:46:34 +02:00
for ( $i = 0 ; $i < $nbdetaux ; $i ++ )
{
//print "xxxxx".$txtva[$i]."-".$nprtva[$i];
$return .= '<option value="' . $txtva [ $i ];
$return .= $nprtva [ $i ] ? '*' : '' ;
$return .= '"' ;
if ( $txtva [ $i ] == $defaulttx && $nprtva [ $i ] == $defaultnpr )
{
2010-11-01 17:00:38 +01:00
$return .= ' selected="selected"' ;
2010-08-22 17:46:34 +02:00
}
$return .= '>' . vatrate ( $libtva [ $i ]);
$return .= $nprtva [ $i ] ? ' *' : '' ;
$return .= '</option>' ;
$this -> tva_taux_value [ $i ] = $txtva [ $i ];
$this -> tva_taux_libelle [ $i ] = $libtva [ $i ];
$this -> tva_taux_npr [ $i ] = $nprtva [ $i ];
}
$return .= '</select>' ;
}
return $return ;
}
/**
2011-05-30 11:16:33 +02:00
* Show a HTML widget to input a date or combo list for day , month , years and optionnaly hours and minutes
2010-11-18 23:17:44 +01:00
* Fields are preselected with :
2011-05-30 11:16:33 +02:00
* - set_time date ( Local PHP server timestamps or date format YYYY - MM - DD or YYYY - MM - DD HH : MM )
2010-11-18 23:17:44 +01:00
* - local date of PHP server if set_time is ''
* - 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
*
2010-08-22 17:46:34 +02:00
* @ param set_time Pre - selected date ( must be a local PHP server timestamp )
2010-11-18 23:17:44 +01:00
* @ param prefix Prefix for fields name
* @ param h 1 = Show also hours
* @ param m 1 = Show also minutes
* @ param empty 0 = Fields required , 1 = Empty input is allowed
* @ param form_name Form name . Used by popup dates .
* @ param d 1 = Show days , month , years
2010-08-22 17:46:34 +02:00
* @ param addnowbutton Add a button " Now "
* @ param nooutput Do not output html string but return it
* @ param disabled Disable input fields
2010-11-18 23:17:44 +01:00
* @ param fullday When a checkbox with this html name is on , hour and day are set with 00 : 00 or 23 : 59
2010-08-22 17:46:34 +02:00
* @ return nothing or string if nooutput is 1
*/
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
2011-04-08 11:32:24 +02:00
if ( ! $set_time && $empty == 0 ) $set_time = dol_now ( 'tzuser' );
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'
2010-08-22 17:46:34 +02:00
$syear = $reg [ 1 ];
$smonth = $reg [ 2 ];
$sday = $reg [ 3 ];
$shour = $reg [ 4 ];
$smin = $reg [ 5 ];
}
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 = '' ;
}
if ( $d )
{
2011-03-20 15:38:54 +01:00
// Show date with popup
2011-05-18 13:57:33 +02:00
if ( $conf -> use_javascript_ajax && ( empty ( $conf -> global -> MAIN_POPUP_CALENDAR ) || $conf -> global -> MAIN_POPUP_CALENDAR != " none " ))
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);
$formated_date = dol_print_date ( $set_time , $langs -> trans ( " FormatDateShort " )); // FormatDateShort for dol_print_date/FormatDateShortJava that is same for javascript
2010-08-22 17:46:34 +02:00
}
// Calendrier popup version eldy
2011-05-18 13:57:33 +02:00
if ( empty ( $conf -> global -> MAIN_POPUP_CALENDAR ) || $conf -> global -> MAIN_POPUP_CALENDAR == " 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"' : '' );
2010-08-28 01:42:10 +02:00
$retstring .= ' onChange="dpChangeDay(\'' . $prefix . '\',\'' . $langs -> trans ( " FormatDateShortJava " ) . '\'); "' ; // FormatDateShort for dol_print_date/FormatDateShortJava 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"' ;
$base = DOL_URL_ROOT . '/lib/' ;
2011-03-20 15:38:54 +01:00
$retstring .= ' onClick="showDP(\'' . $base . '\',\'' . $prefix . '\',\'' . $langs -> trans ( " FormatDateShortJava " ) . '\',\'' . $langs -> defaultlang . '\');">' . img_object ( $langs -> trans ( " SelectDate " ), 'calendarday' ) . '</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
{
2010-08-28 01:42:10 +02:00
print " Bad value of calendar " ;
2010-08-22 17:46:34 +02:00
}
}
2011-03-20 15:38:54 +01:00
// Show date with combo selects
2011-05-18 13:57:33 +02:00
if ( empty ( $conf -> use_javascript_ajax ) || $conf -> global -> MAIN_POPUP_CALENDAR == " none " )
2010-08-22 17:46:34 +02:00
{
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 ++ )
{
if ( $day == $sday )
{
2010-11-01 17:00:38 +01:00
$retstring .= " <option value= \" $day\ " selected = \ " selected \" > $day " ;
2010-08-22 17:46:34 +02:00
}
else
{
$retstring .= " <option value= \" $day\ " > $day " ;
}
$retstring .= " </option> " ;
}
$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 )
{
2011-08-31 17:12:09 +02:00
$retstring .= '<input' . ( $disabled ? ' disabled="disabled"' : '' ) . ' 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 ++ )
{
if ( $year == $syear )
{
$retstring .= " <option value= \" $year\ " selected = \ " true \" > " . $year ;
}
else
{
$retstring .= " <option value= \" $year\ " > " . $year ;
}
$retstring .= " </option> " ;
}
$retstring .= " </select> \n " ;
}
}
}
if ( $d && $h ) $retstring .= ' ' ;
if ( $h )
{
2011-03-20 15:38:54 +01:00
// Show hour
2011-08-31 17:12:09 +02: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 ++ )
{
2010-08-24 16:42:18 +02:00
if ( dol_strlen ( $hour ) < 2 )
2010-08-22 17:46:34 +02:00
{
$hour = " 0 " . $hour ;
}
if ( $hour == $shour )
{
$retstring .= " <option value= \" $hour\ " selected = \ " true \" > $hour </option> " ;
}
else
{
$retstring .= " <option value= \" $hour\ " > $hour </ option > " ;
}
}
$retstring .= " </select> " ;
$retstring .= " H \n " ;
}
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 ++ )
{
2010-08-24 16:42:18 +02:00
if ( dol_strlen ( $min ) < 2 )
2010-08-22 17:46:34 +02:00
{
$min = " 0 " . $min ;
}
if ( $min == $smin )
{
$retstring .= " <option value= \" $min\ " selected = \ " true \" > $min </option> " ;
}
else
{
$retstring .= " <option value= \" $min\ " > $min </ option > " ;
}
}
$retstring .= " </select> " ;
$retstring .= " M \n " ;
}
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
2011-05-18 13:57:33 +02:00
if ( empty ( $conf -> global -> MAIN_POPUP_CALENDAR ) || $conf -> global -> MAIN_POPUP_CALENDAR == " eldy " )
2010-08-22 17:46:34 +02:00
{
$base = DOL_URL_ROOT . '/lib/' ;
2010-08-28 01:42:10 +02:00
$reset_scripts .= 'resetDP(\'' . $base . '\',\'' . $prefix . '\',\'' . $langs -> trans ( " FormatDateShortJava " ) . '\',\'' . $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
if ( $reset_scripts )
{
2010-11-18 23:17:44 +01:00
$retstring .= '<button class="dpInvisibleButtons" 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
*
2011-03-20 15:38:54 +01:00
* @ param prefix prefix
* @ param iSecond Default preselected duration ( number of seconds )
* @ param disabled Disable the combo box
2010-08-22 17:46:34 +02:00
*/
function select_duration ( $prefix , $iSecond = '' , $disabled = 0 )
{
if ( $iSecond )
{
require_once ( DOL_DOCUMENT_ROOT . " /lib/date.lib.php " );
$hourSelected = ConvertSecondToTime ( $iSecond , 'hour' );
$minSelected = ConvertSecondToTime ( $iSecond , 'min' );
}
2011-08-31 17:12:09 +02:00
print '<select class="flat" name="' . $prefix . 'hour"' . ( $disabled ? ' disabled="disabled"' : '' ) . '>' ;
2010-08-22 17:46:34 +02:00
for ( $hour = 0 ; $hour < 24 ; $hour ++ )
{
print '<option value="' . $hour . '"' ;
if ( $hourSelected == $hour )
{
print " selected= \" true \" " ;
}
print " > " . $hour . " </option> " ;
}
print " </select> " ;
print " H " ;
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> " ;
print " M " ;
}
/**
2010-10-22 10:11:51 +02:00
* Show a select form from an array
2011-08-12 23:29:29 +02:00
*
2010-10-22 10:11:51 +02:00
* @ param htmlname Name of html select area
* @ param array Array with key + value
* @ param id Preselected key
* @ param show_empty 1 si il faut ajouter une valeur vide dans la liste , 0 sinon
* @ param key_in_label 1 pour afficher la key dans la valeur " [key] value "
* @ param value_as_key 1 to use value as key
* @ param option Valeur de l ' option en fonction du type choisi
2011-07-10 18:50:40 +02:00
* @ param translate Translate and encode value
2010-10-22 10:11:51 +02:00
* @ param maxlen Length maximum for labels
* @ param disabled Html select box is disabled
* @ return string HTML select string
2010-08-22 17:46:34 +02:00
*/
function selectarray ( $htmlname , $array , $id = '' , $show_empty = 0 , $key_in_label = 0 , $value_as_key = 0 , $option = '' , $translate = 0 , $maxlen = 0 , $disabled = 0 )
{
global $langs ;
2011-08-31 17:12:09 +02:00
$out = '<select id="' . $htmlname . '" ' . ( $disabled ? 'disabled="disabled" ' : '' ) . 'class="flat" 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 ))
{
2011-06-15 22:21:25 +02:00
foreach ( $array as $key => $value )
2010-08-22 17:46:34 +02:00
{
$out .= '<option value="' . ( $value_as_key ? $value : $key ) . '"' ;
// Si il faut pre-selectionner une valeur
if ( $id != '' && ( $id == $key || $id == $value ))
{
2010-11-01 17:00:38 +01:00
$out .= ' selected="selected"' ;
2010-08-22 17:46:34 +02:00
}
$out .= '>' ;
if ( $key_in_label )
{
$newval = ( $translate ? $langs -> trans ( $value ) : $value );
2011-07-10 18:50:40 +02:00
$selectOptionValue = dol_htmlentitiesbr ( $key . ' - ' . ( $maxlen ? dol_trunc ( $newval , $maxlen ) : $newval ));
2010-08-22 17:46:34 +02:00
$out .= $selectOptionValue ;
}
else
{
$newval = ( $translate ? $langs -> trans ( $value ) : $value );
2011-07-10 18:50:40 +02:00
$selectOptionValue = dol_htmlentitiesbr ( $maxlen ? dol_trunc ( $newval , $maxlen ) : $newval );
2010-08-22 17:46:34 +02:00
if ( $value == '' || $value == '-' ) { $selectOptionValue = ' ' ; }
$out .= $selectOptionValue ;
}
$out .= " </option> \n " ;
}
}
$out .= " </select> " ;
return $out ;
}
/**
* Show a select form from an array
2011-08-12 23:29:29 +02:00
*
2010-08-22 17:46:34 +02:00
* @ deprecated Use selectarray instead
*/
function select_array ( $htmlname , $array , $id = '' , $show_empty = 0 , $key_in_label = 0 , $value_as_key = 0 , $option = '' , $translate = 0 , $maxlen = 0 )
{
print $this -> selectarray ( $htmlname , $array , $id , $show_empty , $key_in_label , $value_as_key , $option , $translate , $maxlen );
}
/**
2010-11-01 13:41:32 +01:00
* Return an html string with a select combo box to choose yes or no
2011-08-12 23:29:29 +02:00
*
2010-11-01 13:41:32 +01:00
* @ param name Name of html select field
* @ param value Pre - selected value
* @ param option 0 return yes / no , 1 return 1 / 0
* @ return int or string See option
2010-08-22 17:46:34 +02:00
*/
function selectyesno ( $htmlname , $value = '' , $option = 0 )
{
global $langs ;
$yes = " yes " ; $no = " no " ;
if ( $option )
{
$yes = " 1 " ;
$no = " 0 " ;
}
2011-03-25 23:07:35 +01:00
$resultyesno = '<select class="flat" id="' . $htmlname . '" name="' . $htmlname . '">' . " \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 ;
}
/**
2011-08-12 23:29:29 +02:00
* Return list of export templates
*
2011-05-10 00:19:14 +02:00
* @ param selected Id modele pre - selectionne
* @ param htmlname Nom de la zone select
* @ param type Type des modeles recherches
* @ param useempty Affiche valeur vide dans liste
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
*
2010-08-22 17:46:34 +02:00
* @ param object Object to show
* @ param paramid Name of parameter to use to name the id into the URL link
* @ param morehtml More html content to output just before the nav bar
* @ param shownav Show Condition ( navigation is shown if value is 1 )
* @ param fieldid Nom du champ en base a utiliser pour select next et previous
* @ param fieldref Nom du champ objet ref ( object -> ref ) a utiliser pour select next et previous
* @ param morehtmlref Code html supplementaire a afficher apres ref
* @ param moreparam More param to add in nav link url .
* @ return string Portion HTML avec ref + boutons nav
*/
function showrefnav ( $object , $paramid , $morehtml = '' , $shownav = 1 , $fieldid = 'rowid' , $fieldref = 'ref' , $morehtmlref = '' , $moreparam = '' )
{
$ret = '' ;
//print "$paramid,$morehtml,$shownav,$fieldid,$fieldref,$morehtmlref,$moreparam";
2011-06-09 01:10:42 +02:00
$object -> load_previous_next_ref (( isset ( $object -> next_prev_filter ) ? $object -> next_prev_filter : '' ), $fieldid );
2010-08-22 17:46:34 +02:00
$previous_ref = $object -> ref_previous ? '<a href="' . $_SERVER [ " PHP_SELF " ] . '?' . $paramid . '=' . urlencode ( $object -> ref_previous ) . $moreparam . '">' . img_previous () . '</a>' : '' ;
$next_ref = $object -> ref_next ? '<a href="' . $_SERVER [ " PHP_SELF " ] . '?' . $paramid . '=' . urlencode ( $object -> ref_next ) . $moreparam . '">' . img_next () . '</a>' : '' ;
//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">' ;
}
$ret .= $object -> $fieldref ;
if ( $morehtmlref ) {
$ret .= ' ' . $morehtmlref ;
}
if ( $morehtml ) {
$ret .= '</td><td class="nobordernopadding" align="right">' . $morehtml ;
}
if ( $shownav && ( $previous_ref || $next_ref )) {
$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-05-10 00:19:14 +02:00
* Return HTML code to output a photo
2011-08-12 23:29:29 +02:00
*
2011-06-11 16:26:30 +02:00
* @ param modulepart Key to define module concerned ( 'societe' , 'userphoto' , 'memberphoto' )
2011-05-10 00:19:14 +02:00
* @ param object Object containing data to retrieve file name
* @ param 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 ;
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' )
{
$dir = $conf -> societe -> dir_output ;
$smallfile = $object -> logo ;
$smallfile = preg_replace ( '/(\.png|\.gif|\.jpg|\.jpeg|\.bmp)/i' , '_small\\1' , $smallfile );
2011-06-11 22:58:08 +02:00
if ( $object -> logo ) $file = $object -> 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 ;
2011-06-11 22:58:08 +02:00
if ( $object -> photo ) $file = get_exdir ( $object -> id , 2 ) . $object -> photo ;
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 ;
2011-06-11 22:58:08 +02:00
if ( $object -> photo ) $file = get_exdir ( $object -> id , 2 ) . 'photos/' . $object -> photo ;
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 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
$ret .= '<a href="' . DOL_URL_ROOT . '/viewimage.php?modulepart=' . $modulepart . '&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 . '&file=' . urlencode ( $file ) . '&cache=' . $cache . '">' ;
$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
{
2011-06-13 00:13:05 +02:00
$ret .= '<a href="' . DOL_URL_ROOT . '/viewimage.php?modulepart=' . $modulepart . '&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 . '&file=' . urlencode ( $altfile ) . '&cache=' . $cache . '">' ;
$ret .= '</a>' ;
2010-08-22 17:46:34 +02:00
}
else
{
2011-06-11 16:14:27 +02:00
if ( $conf -> gravatar -> enabled && $email )
2010-08-22 17:46:34 +02:00
{
global $dolibarr_main_url_root ;
$ret .= '<!-- Put link to gravatar -->' ;
2011-09-06 08:53:52 +02: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
2011-06-13 00:13:05 +02:00
/* Disabled . lightbox seems to not work . I don ' t know why .
$ret .= " \n <script type= \" text/javascript \" >
jQuery ( function () {
jQuery ( '.photologo' ) . lightBox ();
});
</ script > \n " ;
$ret .= " \n <script type= \" text/javascript \" >
jQuery ( function () {
jQuery ( '.photologo' ) . lightBox ({
overlayBgColor : '#FFF' ,
overlayOpacity : 0.6 ,
imageLoading : '".DOL_URL_ROOT."/includes/jquery/plugins/lightbox/images/lightbox-ico-loading.gif' ,
imageBtnClose : '".DOL_URL_ROOT."/includes/jquery/plugins/lightbox/images/lightbox-btn-close.gif' ,
imageBtnPrev : '".DOL_URL_ROOT."/includes/jquery/plugins/lightbox/images/lightbox-btn-prev.gif' ,
imageBtnNext : '".DOL_URL_ROOT."/includes/jquery/plugins/lightbox/images/lightbox-btn-next.gif' ,
containerResizeSpeed : 350 ,
txtImage : 'Imagem' ,
txtOf : 'de'
});
});
</ script > \n " ;
*/
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
*
2010-11-08 20:04:52 +01:00
* @ param selected Id group preselected
* @ param htmlname Field name in form
* @ param show_empty 0 = liste sans valeur nulle , 1 = ajoute valeur inconnue
* @ param exclude Array list of groups id to exclude
* @ param disabled If select list must be disabled
* @ param include Array list of groups id to include
* @ param enableonly Array list of groups id to be enabled . All other must be disabled
2011-08-21 02:20:43 +02:00
* @ param force_entity Possibility to force entity
2010-11-08 20:04:52 +01:00
*/
2011-08-24 16:01:21 +02:00
function select_dolgroups ( $selected = '' , $htmlname = 'groupid' , $show_empty = 0 , $exclude = '' , $disabled = 0 , $include = '' , $enableonly = '' , $force_entity = '' )
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 " ;
2011-08-21 12:01:36 +02:00
if ( ! empty ( $conf -> multicompany -> enabled ) && $conf -> entity == 1 && $user -> admin && ! $user -> entity )
2011-08-20 00:15:22 +02:00
{
$sql .= " , e.label " ;
}
2011-08-19 09:22:17 +02:00
$sql .= " FROM " . MAIN_DB_PREFIX . " usergroup as ug " ;
2011-08-21 12:01:36 +02:00
if ( ! empty ( $conf -> multicompany -> enabled ) && $conf -> entity == 1 && $user -> admin && ! $user -> entity )
2011-08-19 09:22:17 +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
{
$sql .= " WHERE ug.entity IN (0, " . $conf -> entity . " ) " ;
}
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 . " ') " ;
$sql .= " ORDER BY ug.nom ASC " ;
dol_syslog ( " Form::select_dolgroups sql= " . $sql );
$resql = $this -> db -> query ( $sql );
if ( $resql )
{
$num = $this -> db -> num_rows ( $resql );
$i = 0 ;
if ( $num )
{
2011-08-31 17:12:09 +02:00
$out .= '<select class="flat" name="' . $htmlname . '"' . ( $disabled ? ' disabled="disabled"' : '' ) . '>' ;
2011-08-21 02:20:43 +02:00
if ( $show_empty ) $out .= '<option value="-1"' . ( $id ==- 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 ;
if ( is_array ( $enableonly ) && sizeof ( $enableonly ) && ! in_array ( $obj -> rowid , $enableonly )) $disableline = 1 ;
$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 ;
2011-08-21 12:01:36 +02:00
if ( ! empty ( $conf -> multicompany -> enabled ) && empty ( $conf -> global -> MULTICOMPANY_TRANSVERSE_MODE ) && $conf -> entity == 1 )
2011-08-20 00:15:22 +02:00
{
$out .= " ( " . $obj -> label . " ) " ;
}
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
{
$out .= '<select class="flat" name="' . $htmlname . '" disabled="disabled">' ;
$out .= '<option value="">' . $langs -> trans ( " EmptyList " ) . '</option>' ;
}
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
}
?>