2006-05-04 00:02:32 +02:00
< ? php
2009-04-27 22:37:50 +02:00
/* Copyright ( c ) 2002 - 2007 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
2009-05-04 21:02:32 +02:00
* Copyright ( C ) 2004 - 2009 Laurent Destailleur < eldy @ users . sourceforge . net >
2009-04-27 22:37:50 +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 >
2010-01-28 09:52:41 +01:00
* Copyright ( C ) 2005 - 2010 Regis Houssin < regis @ dolibarr . fr >
2009-04-27 22:37:50 +02:00
* Copyright ( C ) 2006 Andre Cianfarani < acianfa @ free . fr >
* Copyright ( C ) 2006 Marc Barilley / Ocebo < marc @ ocebo . com >
2007-01-06 15:59:34 +01:00
* Copyright ( C ) 2007 Franky Van Liedekerke < franky . van . liedekerker @ telenet . be >
2009-04-27 22:37:50 +02:00
* Copyright ( C ) 2007 Patrick Raguin < patrick . raguin @ gmail . com >
2006-02-09 18:36:09 +01: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
* along with this program ; if not , write to the Free Software
* Foundation , Inc . , 59 Temple Place - Suite 330 , Boston , MA 02111 - 1307 , USA .
*/
/**
2008-10-06 23:31:05 +02:00
* \file htdocs / html . form . class . php
2009-06-08 20:24:16 +02:00
* \brief Fichier de la classe des fonctions predefinie de composants html
2008-10-06 23:31:05 +02:00
* \version $Id $
2008-10-01 23:16:35 +02:00
*/
2006-02-09 18:36:09 +01:00
/**
2008-10-06 23:31:05 +02:00
* \class Form
2009-06-08 20:24:16 +02:00
* \brief Classe permettant la generation de composants html
2008-10-06 23:31:05 +02:00
* \remarks Only common components must be here .
2008-10-01 23:16:35 +02:00
*/
2006-02-09 18:36:09 +01:00
class Form
{
2008-01-11 17:52:42 +01:00
var $db ;
var $error ;
2008-10-01 23:16:35 +02:00
2008-01-11 17:52:42 +01:00
// Cache arrays
var $cache_types_paiements = array ();
var $cache_conditions_paiements = array ();
2006-02-09 18:36:09 +01:00
2008-01-11 17:52:42 +01:00
var $tva_taux_value ;
var $tva_taux_libelle ;
2008-10-01 23:16:35 +02:00
/**
2009-05-04 21:02:32 +02:00
* \brief Constructor
* \param DB Database handler
2008-10-01 23:16:35 +02:00
*/
function Form ( $DB )
{
$this -> db = $DB ;
return 1 ;
}
2010-03-20 19:39:32 +01:00
/**
2010-04-17 11:47:25 +02:00
* \brief Output key field for an editable field
* \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 perm Permission to allow button to edit parameter
* \param typeofdata Type of data ( string by default , email , ... )
2010-03-20 19:39:32 +01:00
*/
2010-04-17 11:47:25 +02:00
function editfieldkey ( $text , $htmlname , $preselected , $paramkey , $paramvalue , $perm , $typeofdata = 'string' )
2010-03-20 19:39:32 +01:00
{
global $langs ;
$ret = '' ;
$ret .= '<table class="nobordernopadding" width="100%"><tr><td nowrap="nowrap">' ;
$ret .= $langs -> trans ( $text );
$ret .= '</td>' ;
if ( $_GET [ '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>' ;
$ret .= '</tr></table>' ;
return $ret ;
}
/**
2010-04-17 11:47:25 +02:00
* \brief 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 , ... )
2010-03-20 19:39:32 +01:00
*/
2010-04-17 11:47:25 +02:00
function editfieldval ( $text , $htmlname , $preselected , $paramkey , $paramvalue , $perm , $typeofdata = 'string' )
2010-03-20 19:39:32 +01:00
{
global $langs ;
$ret = '' ;
if ( $_GET [ 'action' ] == 'edit' . $htmlname )
{
$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>' ;
$ret .= '<input type="text" name="' . $htmlname . '" value="' . $preselected . '">' ;
$ret .= '</td>' ;
$ret .= '<td align="left"><input type="submit" class="button" value="' . $langs -> trans ( " Modify " ) . '"></td>' ;
$ret .= '</tr></table>' . " \n " ;
$ret .= '</form>' . " \n " ;
}
2010-04-17 11:47:25 +02:00
else
{
if ( $typeofdata == 'email' ) $ret .= dol_print_email ( $preselected , 0 , 0 , 0 , 0 , 1 );
else $ret .= $preselected ;
}
2010-03-20 19:39:32 +01:00
return $ret ;
}
2008-10-01 23:16:35 +02:00
2009-08-22 14:32:44 +02:00
/**
* \brief Old version of textwithtooltip . Kept for backward compatibility with modules for 2.6 .
* \deprecated
*/
function textwithhelp ( $text , $htmltext , $tooltipon = 1 )
{
return $this -> textwithtooltip ( $text , $htmltext , $tooltipon );
}
2008-03-31 05:31:08 +02:00
/**
2009-09-28 22:06:15 +02:00
* \brief Show a text and picto with tooltip on text or picto
2009-10-20 14:45:52 +02:00
* \param text Texte to show
2009-09-28 22:06:15 +02:00
* \param htmltext Contenu html du tooltip , code en Html / UTF8
2009-06-08 20:24:16 +02:00
* \param tooltipon 1 = tooltip sur texte , 2 = tooltip sur picto , 3 = tooltip sur les 2 , 4 = tooltip sur les 2 et force en Ajax
* \param direction - 1 = Le picto est avant , 0 = pas de picto , 1 = le picto est apres
2009-02-09 01:04:34 +01:00
* \param img Code img du picto
2009-05-27 03:15:44 +02:00
* \param i Numero of tooltip
2009-07-07 17:11:59 +02:00
* \param width Width of tooltip
* \param shiftX Shift of tooltip
2009-02-09 01:04:34 +01:00
* \return string Code html du tooltip ( texte + picto )
2009-10-20 14:45:52 +02:00
* \remarks Use function textwithpicto if you can .
2009-02-09 01:04:34 +01:00
*/
2008-03-31 05:31:08 +02:00
function textwithtooltip ( $text , $htmltext , $tooltipon = 1 , $direction = 0 , $img = '' , $i = 1 , $width = '200' , $shiftX = '10' )
{
global $conf ;
2008-10-01 23:16:35 +02:00
2007-05-21 20:21:43 +02:00
if ( ! $htmltext ) return $text ;
2008-10-01 23:16:35 +02:00
2007-07-30 11:01:27 +02:00
$paramfortooltiptext = '' ;
2008-10-01 23:16:35 +02:00
$paramfortooltippicto = '' ;
2009-01-18 18:07:27 +01:00
2008-10-01 23:16:35 +02:00
// Sanitize tooltip
2009-09-28 22:06:15 +02:00
$htmltext = str_replace ( " \\ " , " \\ \\ " , $htmltext );
$htmltext = str_replace ( " ' " , " \ ' " , $htmltext );
$htmltext = str_replace ( " ' " , " \ ' " , $htmltext );
$htmltext = str_replace ( " \r " , " " , $htmltext );
$htmltext = str_replace ( " <br> \n " , " <br> " , $htmltext );
$htmltext = str_replace ( " \n " , " " , $htmltext );
2008-10-01 23:16:35 +02:00
if ( $conf -> use_javascript_ajax && $tooltipon == 4 )
{
$s = '<div id="tip' . $i . '">' . " \n " ;
$s .= $text ;
$s .= '</div>' . " \n " ;
$s .= '<div id="tooltip_content" style="display:none">' . " \n " ;
$s .= $htmltext . " \n " ;
$s .= '</div>' . " \n " ;
$s .= '<script type=\'text/javascript\'>' . " \n " ;
2009-09-15 13:24:00 +02:00
$s .= 'TooltipManager.init("","",{width:' . dol_size ( $width , 'width' ) . ', shiftX:' . $shiftX . '});' . " \n " ;
2008-03-31 05:31:08 +02:00
$s .= 'TooltipManager.addHTML("tip' . $i . '", "tooltip_content");' . " \n " ;
2008-10-01 23:16:35 +02:00
$s .= '</script>' . " \n " ;
}
else
{
if ( $conf -> use_javascript_ajax )
{
2009-10-21 16:02:14 +02:00
$htmltext = str_replace ( '"' , " " " , $htmltext );
2008-10-01 23:16:35 +02:00
if ( $tooltipon == 1 || $tooltipon == 3 )
{
2008-03-31 05:31:08 +02:00
$paramfortooltiptext .= ' onmouseover="showtip(\'' . $htmltext . '\')"' ;
$paramfortooltiptext .= ' onMouseout="hidetip()"' ;
}
if ( $tooltipon == 2 || $tooltipon == 3 )
{
$paramfortooltippicto .= ' onmouseover="showtip(\'' . $htmltext . '\')"' ;
$paramfortooltippicto .= ' onMouseout="hidetip()"' ;
}
2008-10-01 23:16:35 +02:00
}
2006-02-09 18:36:09 +01:00
2008-05-20 02:09:11 +02:00
$s = " " ;
2009-05-28 03:56:48 +02:00
$s .= '<table class="nobordernopadding" summary=""><tr>' ;
2008-05-20 02:09:11 +02:00
if ( $direction > 0 )
2007-05-21 20:21:43 +02:00
{
2008-05-20 02:09:11 +02:00
if ( $text )
{
$s .= '<td' . $paramfortooltiptext . '>' . $text ;
if ( $direction ) $s .= ' ' ;
$s .= '</td>' ;
}
if ( $direction ) $s .= '<td' . $paramfortooltippicto . ' valign="top" width="14">' . $img . '</td>' ;
2007-05-21 20:21:43 +02:00
}
2008-05-20 02:09:11 +02:00
else
2007-05-21 20:21:43 +02:00
{
2008-05-20 02:09:11 +02:00
if ( $direction ) $s .= '<td' . $paramfortooltippicto . ' valign="top" width="14">' . $img . '</td>' ;
if ( $text )
{
$s .= '<td' . $paramfortooltiptext . '>' ;
if ( $direction ) $s .= ' ' ;
$s .= $text . '</td>' ;
}
2007-05-21 20:21:43 +02:00
}
2008-05-20 02:09:11 +02:00
$s .= '</tr></table>' ;
2006-08-20 04:17:52 +02:00
}
2008-05-20 02:09:11 +02:00
return $s ;
2007-07-30 11:01:27 +02:00
}
2007-05-21 20:21:43 +02:00
/**
2009-05-04 20:45:56 +02:00
* \brief Show a text with a picto and a tooltip on picto
2009-05-04 20:38:01 +02:00
* \param text Text to show
* \param htmltooltip Content of tooltip
* \param direction 1 = Icon is after text , - 1 = Icon is before text
2009-05-04 21:02:32 +02:00
* \param type Type of picto ( info , help , warning , superadmin ... )
2009-05-04 20:38:01 +02:00
* \return string HTML code of text , picto , tooltip
2008-10-01 23:16:35 +02:00
*/
2009-05-04 20:45:56 +02:00
function textwithpicto ( $text , $htmltext , $direction = 1 , $type = 'help' )
2008-10-01 23:16:35 +02:00
{
2009-03-02 17:06:52 +01:00
global $conf ;
2009-05-04 21:02:32 +02:00
if ( " $type " == " 0 " ) $type = 'info' ; // For backward compatibility
2009-03-02 17:06:52 +01:00
$alt = '' ;
2009-10-07 19:36:51 +02:00
// If info or help with no javascript, show only text
if ( empty ( $conf -> use_javascript_ajax ))
{
if ( $type == 'info' || $type == 'help' ) return $text ;
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 ;
}
2009-10-08 23:49:55 +02:00
// Info or help
2009-05-04 21:02:32 +02:00
if ( $type == 'info' ) $img = img_help ( 0 , $alt );
if ( $type == 'help' || $type == 1 ) $img = img_help ( 1 , $alt );
if ( $type == 'superadmin' ) $img = img_redstar ( $alt );
2009-10-07 19:36:51 +02:00
// Warnings
if ( $type == 'warning' ) $img = img_warning ( $alt );
2009-05-04 20:38:01 +02:00
return $this -> textwithtooltip ( $text , $htmltext , 2 , $direction , $img );
2009-05-04 16:58:40 +02:00
}
2008-10-01 23:16:35 +02:00
/**
2009-06-08 20:24:16 +02:00
* \brief Retourne la liste deroulante des pays actifs , dans la langue de l ' utilisateur
* \param selected Id ou Code pays ou Libelle pays pre - selectionne
2006-03-18 20:58:33 +01:00
* \param htmlname Nom de la liste deroulante
* \param htmloption Options html sur le select
2009-06-08 20:24:16 +02:00
* \todo trier liste sur noms apres traduction plutot que avant
2006-03-18 20:58:33 +01:00
*/
function select_pays ( $selected = '' , $htmlname = 'pays_id' , $htmloption = '' )
{
2006-08-12 00:56:54 +02:00
global $conf , $langs ;
$langs -> load ( " dict " );
$sql = " SELECT rowid, code, libelle, active " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " c_pays " ;
$sql .= " WHERE active = 1 " ;
2008-01-06 16:24:23 +01:00
// \TODO A virer
if ( $conf -> use_javascript_ajax && $conf -> global -> CODE_DE_TEST )
2007-04-24 23:03:12 +02:00
{
if ( is_numeric ( $selected ))
{
$sql .= " AND rowid = " . $selected ;
}
else
{
$sql .= " AND code = ' " . $selected . " ' " ;
}
}
2008-01-11 18:16:46 +01:00
$sql .= " ORDER BY code ASC " ;
2007-04-24 23:03:12 +02:00
2009-02-20 23:53:15 +01:00
dol_syslog ( " Form::select_pays sql= " . $sql );
2006-11-26 08:00:14 +01:00
$resql = $this -> db -> query ( $sql );
if ( $resql )
2006-08-12 00:56:54 +02:00
{
2008-01-06 16:24:23 +01:00
// \TODO A virer
if ( $conf -> use_javascript_ajax && $conf -> global -> CODE_DE_TEST )
2006-08-12 00:56:54 +02:00
{
2007-04-03 15:28:34 +02:00
$langs -> load ( " companies " );
2007-02-11 21:04:10 +01:00
$obj = $this -> db -> fetch_object ( $resql );
$pays_id = $obj -> rowid ? $obj -> rowid : '' ;
2008-10-01 23:16:35 +02:00
2007-02-12 13:27:48 +01:00
// On applique un delai d'execution pour le bon fonctionnement
2007-02-12 13:50:33 +01:00
$mode_create = substr ( $htmloption , - 9 , 6 );
$mode_edit = substr ( $htmloption , - 7 , 4 );
$mode_company = substr ( $htmloption , - 10 , 7 );
if ( $mode_create == 'create' )
2007-02-12 13:27:48 +01:00
{
2009-08-28 00:20:01 +02:00
$htmloption = 'onChange="ac_delay(\'company_save_refresh_create()\',\'500\')"' ;
2007-02-12 13:27:48 +01:00
}
2007-02-12 13:50:33 +01:00
else if ( $mode_edit == 'edit' )
2007-02-12 13:27:48 +01:00
{
2009-08-28 00:20:01 +02:00
$htmloption = 'onChange="ac_delay(\'company_save_refresh_edit()\',\'500\')"' ;
2007-02-12 13:27:48 +01:00
}
2007-02-12 13:50:33 +01:00
else if ( $mode_company == 'refresh' )
{
$htmloption = 'onChange="ac_delay(\'company_save_refresh()\',\'500\')"' ;
}
2007-06-23 09:03:20 +02:00
2007-02-08 12:00:18 +01:00
print '<div>' ;
2007-04-03 15:28:34 +02:00
if ( $obj -> rowid == 0 )
{
print '<input type="text" size="45" id="pays" name="pays" value="' . $langs -> trans ( " SelectCountry " ) . '" ' . $htmloption . ' />' ;
}
else
{
print '<input type="text" size="45" id="pays" name="pays" value="' . $obj -> libelle . '" ' . $htmloption . ' />' ;
}
2008-10-01 23:16:35 +02:00
2009-08-28 00:20:01 +02:00
print ajax_indicator ( $htmlname , 'working' );
2009-08-28 01:31:50 +02:00
print ajax_autocompleter ( $pays_id , 'pays' , DOL_URL_ROOT . '/societe/ajaxcountries.php' , '' );
2006-08-12 00:56:54 +02:00
}
2007-02-08 12:00:18 +01:00
else
{
print '<select class="flat" name="' . $htmlname . '" ' . $htmloption . '>' ;
$num = $this -> db -> num_rows ( $resql );
2008-02-17 16:20:47 +01:00
$i = 0 ;
if ( $num )
{
$foundselected = false ;
while ( $i < $num )
{
$obj = $this -> db -> fetch_object ( $resql );
if ( $selected && $selected != '-1' &&
2008-10-01 23:16:35 +02:00
( $selected == $obj -> rowid || $selected == $obj -> code || $selected == $obj -> libelle ) )
2008-02-17 16:20:47 +01:00
{
$foundselected = true ;
print '<option value="' . $obj -> rowid . '" selected="true">' ;
}
else
{
print '<option value="' . $obj -> rowid . '">' ;
}
2009-06-08 20:24:16 +02:00
// Si traduction existe, on l'utilise, sinon on prend le libelle par defaut
2008-02-17 16:20:47 +01:00
if ( $obj -> code ) { print $obj -> code . ' - ' ; }
print ( $obj -> code && $langs -> trans ( " Country " . $obj -> code ) != " Country " . $obj -> code ? $langs -> trans ( " Country " . $obj -> code ) : ( $obj -> libelle != '-' ? $obj -> libelle : ' ' ));
print '</option>' ;
$i ++ ;
}
}
print '</select>' ;
return 0 ;
}
2008-10-01 23:16:35 +02:00
}
else
{
2009-02-20 23:53:15 +01:00
dol_print_error ( $this -> db );
2006-08-12 00:56:54 +02:00
return 1 ;
}
}
2006-02-09 18:36:09 +01:00
2008-10-01 23:16:35 +02:00
/**
* \brief Retourne la liste des types de comptes financiers
2009-06-08 20:24:16 +02:00
* \param selected Type pre - selectionne
2008-10-01 23:16:35 +02:00
* \param htmlname Nom champ formulaire
*/
2008-01-11 11:25:26 +01:00
function select_type_comptes_financiers ( $selected = 1 , $htmlname = 'type' )
{
global $langs ;
$langs -> load ( " banks " );
2008-10-01 23:16:35 +02:00
2008-01-11 11:25:26 +01:00
$type_available = array ( 0 , 1 , 2 );
2008-10-01 23:16:35 +02:00
2008-01-11 11:25:26 +01:00
print '<select class="flat" name="' . $htmlname . '">' ;
$num = count ( $type_available );
$i = 0 ;
if ( $num )
2007-06-11 09:29:37 +02:00
{
2008-01-11 11:25:26 +01:00
while ( $i < $num )
2007-06-11 09:29:37 +02:00
{
2008-01-11 11:25:26 +01:00
if ( $selected == $type_available [ $i ])
{
print '<option value="' . $type_available [ $i ] . '" selected="true">' . $langs -> trans ( " BankType " . $type_available [ $i ]) . '</option>' ;
}
else
{
print '<option value="' . $type_available [ $i ] . '">' . $langs -> trans ( " BankType " . $type_available [ $i ]) . '</option>' ;
}
$i ++ ;
2007-06-11 09:29:37 +02:00
}
}
print '</select>' ;
2008-01-11 11:25:26 +01:00
}
2008-10-01 23:16:35 +02:00
2008-03-16 15:52:31 +01:00
/**
2008-05-26 01:46:19 +02:00
* \brief Return list of social contributions
* \param selected Preselected type
* \param htmlname Name of field in form
2009-03-03 00:43:17 +01:00
* \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
2008-05-26 01:46:19 +02:00
*/
2009-03-03 00:43:17 +01:00
function select_type_socialcontrib ( $selected = '' , $htmlname = 'actioncode' , $useempty = 0 , $maxlen = 40 , $help = 1 )
2008-03-16 15:52:31 +01:00
{
2009-10-25 21:48:44 +01:00
global $db , $langs , $user , $mysoc ;
2008-03-16 15:52:31 +01:00
2008-06-09 22:06:50 +02:00
$sql = " SELECT c.id, c.libelle as type " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " c_chargesociales as c " ;
2008-10-01 23:16:35 +02:00
$sql .= " WHERE active = 1 " ;
2009-10-25 21:48:44 +01:00
$sql .= " AND fk_pays = " . $mysoc -> pays_id ;
2008-06-09 22:06:50 +02:00
$sql .= " ORDER BY c.libelle ASC " ;
2009-02-20 23:53:15 +01:00
dol_syslog ( " Form::select_type_socialcontrib sql= " . $sql , LOG_DEBUG );
2008-06-09 22:06:50 +02:00
$resql = $db -> query ( $sql );
2008-03-16 15:52:31 +01:00
if ( $resql )
2008-10-01 23:16:35 +02:00
{
$num = $db -> num_rows ( $resql );
2009-10-25 21:48:44 +01:00
if ( $num )
{
print '<select class="flat" name="' . $htmlname . '">' ;
$i = 0 ;
2009-03-03 00:43:17 +01:00
2009-10-25 21:48:44 +01:00
if ( $useempty ) print '<option value="0"> </option>' ;
while ( $i < $num )
{
$obj = $db -> fetch_object ( $resql );
print '<option value="' . $obj -> id . '"' ;
if ( $obj -> id == $selected ) print ' selected="true"' ;
print '>' . dol_trunc ( $obj -> type , $maxlen );
$i ++ ;
}
print '</select>' ;
if ( $user -> admin && $help ) print info_admin ( $langs -> trans ( " YouCanChangeValuesForThisListFromDictionnarySetup " ), 1 );
}
else
2008-10-01 23:16:35 +02:00
{
2009-10-25 21:48:44 +01:00
print $langs -> trans ( " ErrorNoSocialContributionForSellerCountry " , $mysoc -> pays_code );
2008-10-01 23:16:35 +02:00
}
}
else
{
2009-02-20 23:53:15 +01:00
dol_print_error ( $db , $db -> lasterror ());
2008-10-01 23:16:35 +02:00
}
2008-03-16 15:52:31 +01:00
}
2008-10-01 23:16:35 +02:00
2009-03-09 22:59:29 +01:00
/**
* \brief Return list of types of lines ( product or service )
* \param selected Preselected type
2010-02-09 12:33:13 +01:00
* \param htmlname Name of field in html form
2009-03-09 22:59:29 +01:00
* \param showempty Add an empty field
2010-02-09 12:33:13 +01:00
* \param hidetext Do not show label before combo box
* \param forceall Force to show products and services in combo list , whatever are activated modules
2009-03-09 22:59:29 +01:00
*/
2010-02-09 12:33:13 +01:00
function select_type_of_lines ( $selected = '' , $htmlname = 'type' , $showempty = 0 , $hidetext = 0 , $forceall = 0 )
2009-03-09 22:59:29 +01:00
{
global $db , $langs , $user , $conf ;
2009-04-21 00:42:39 +02:00
// If product & services are enabled or both disabled.
2010-02-09 12:33:13 +01:00
if ( $forceall || ( $conf -> produit -> enabled && $conf -> service -> enabled )
2009-04-21 00:42:39 +02:00
|| ( empty ( $conf -> produit -> enabled ) && empty ( $conf -> service -> enabled )))
2009-03-09 22:59:29 +01:00
{
2009-04-21 21:24:12 +02:00
if ( empty ( $hidetext )) print $langs -> trans ( " Type " ) . ': ' ;
2009-03-09 22:59:29 +01:00
print '<select class="flat" name="' . $htmlname . '">' ;
if ( $showempty )
{
print '<option value="-1"' ;
if ( $selected == - 1 ) print ' selected="true"' ;
print '> </option>' ;
}
print '<option value="0"' ;
if ( 0 == $selected ) print ' selected="true"' ;
print '>' . $langs -> trans ( " Product " );
print '<option value="1"' ;
if ( 1 == $selected ) print ' selected="true"' ;
print '>' . $langs -> trans ( " Service " );
print '</select>' ;
//if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionnarySetup"),1);
}
2010-02-09 12:33:13 +01:00
if ( ! $forceall && empty ( $conf -> produit -> enabled ) && $conf -> service -> enabled )
2009-03-09 22:59:29 +01:00
{
print '<input type="hidden" name="' . $htmlname . '" value="1">' ;
}
2010-02-09 12:33:13 +01:00
if ( ! $forceall && $conf -> produit -> enabled && empty ( $conf -> service -> enabled ))
2009-03-09 22:59:29 +01:00
{
print '<input type="hidden" name="' . $htmlname . '" value="0">' ;
}
}
2008-05-26 01:46:19 +02:00
/**
* \brief Return list of types of notes
* \param selected Preselected type
* \param htmlname Name of field in form
* \param showempty Add an empty field
*/
function select_type_fees ( $selected = '' , $htmlname = 'type' , $showempty = 0 )
{
global $db , $langs , $user ;
$langs -> load ( " trips " );
2008-10-01 23:16:35 +02:00
print '<select class="flat" name="' . $htmlname . '">' ;
if ( $showempty )
{
print '<option value="-1"' ;
if ( $selected == - 1 ) print ' selected="true"' ;
print '> </option>' ;
}
2009-01-18 18:07:27 +01:00
2008-10-01 23:16:35 +02:00
$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 );
2008-05-26 01:46:19 +02:00
if ( $resql )
2008-10-01 23:16:35 +02:00
{
$num = $db -> num_rows ( $resql );
$i = 0 ;
while ( $i < $num )
{
$obj = $db -> fetch_object ( $resql );
print '<option value="' . $obj -> code . '"' ;
if ( $obj -> code == $selected ) print ' selected="true"' ;
print '>' ;
if ( $obj -> code != $langs -> trans ( $obj -> code )) print $langs -> trans ( $obj -> code );
else print $langs -> trans ( $obj -> type );
$i ++ ;
}
}
print '</select>' ;
2008-05-26 01:46:19 +02:00
if ( $user -> admin ) print info_admin ( $langs -> trans ( " YouCanChangeValuesForThisListFromDictionnarySetup " ), 1 );
}
2008-03-16 15:52:31 +01:00
/**
2008-02-25 17:30:43 +01:00
* \brief Output html form to select a third party
2008-05-26 01:46:19 +02:00
* \param selected Preselected type
* \param htmlname Name of field in form
2009-07-27 02:08:49 +02:00
* \param filter Optionnal filters criteras
2008-02-25 17:30:43 +01:00
* \param showempty Add an empty field
2009-08-05 18:58:18 +02:00
* \param showtype Show if third party is customer , prospect or supplier
2009-09-11 15:24:47 +02:00
* \param forcecombo Force to use combo box
2006-06-04 00:01:38 +02:00
*/
2009-09-11 15:24:47 +02:00
function select_societes ( $selected = '' , $htmlname = 'socid' , $filter = '' , $showempty = 0 , $showtype = 0 , $forcecombo = 0 )
2008-01-11 18:16:46 +01:00
{
2009-08-05 18:58:18 +02:00
global $conf , $user , $langs ;
2008-10-01 23:16:35 +02:00
// On recherche les societes
2009-08-05 18:58:18 +02:00
$sql = " SELECT s.rowid, s.nom, s.client, s.fournisseur, s.code_client, s.code_fournisseur " ;
2008-10-01 23:16:35 +02:00
$sql .= " FROM " . MAIN_DB_PREFIX . " societe as s " ;
2008-03-01 02:26:41 +01:00
if ( ! $user -> rights -> societe -> client -> voir && ! $user -> societe_id ) $sql .= " , " . MAIN_DB_PREFIX . " societe_commerciaux as sc " ;
2009-04-27 22:37:50 +02:00
$sql .= " WHERE s.entity = " . $conf -> entity ;
2008-02-25 17:30:43 +01:00
if ( $filter ) $sql .= " AND " . $filter ;
2009-09-11 15:24:47 +02:00
if ( is_numeric ( $selected ) && $conf -> use_javascript_ajax && $conf -> global -> COMPANY_USE_SEARCH_TO_SELECT ) $sql .= " AND s.rowid = " . $selected ;
2009-04-27 22:37:50 +02:00
if ( ! $user -> rights -> societe -> client -> voir && ! $user -> societe_id ) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " . $user -> id ;
2008-02-25 17:30:43 +01:00
$sql .= " ORDER BY nom ASC " ;
2008-10-01 23:16:35 +02:00
2009-02-20 23:53:15 +01:00
dol_syslog ( " Form::select_societes sql= " . $sql );
2008-10-01 23:16:35 +02:00
$resql = $this -> db -> query ( $sql );
if ( $resql )
{
2009-09-11 15:24:47 +02:00
if ( $conf -> use_javascript_ajax && $conf -> global -> COMPANY_USE_SEARCH_TO_SELECT && ! $forcecombo )
2008-10-01 23:16:35 +02:00
{
$socid = 0 ;
if ( $selected )
{
$obj = $this -> db -> fetch_object ( $resql );
$socid = $obj -> rowid ? $obj -> rowid : '' ;
}
2009-08-28 00:20:01 +02:00
// We call a page after a small delay when a new input has been selected
//$javaScript = "window.location=\'...\'";
//$htmloption = 'onChange="ac_delay(\''.$javaScript.'\',\'500\')"';
$htmloption = '' ;
2009-08-28 01:31:50 +02:00
print " \n " . '<!-- Input text for third party with Ajax.Autocompleter (select_societes) -->' . " \n " ;
2008-10-01 23:16:35 +02:00
print '<table class="nobordernopadding"><tr class="nocellnopadd">' ;
print '<td class="nobordernopadding">' ;
if ( $socid == 0 )
{
2009-08-28 03:14:35 +02:00
//$langs->load("companies");
print '<input type="text" size="30" id="' . $htmlname . '" name="' . $htmlname . '" value="" ' . $htmloption . ' />' ;
2008-10-01 23:16:35 +02:00
}
else
{
2009-08-28 00:20:01 +02:00
print '<input type="text" size="30" id="' . $htmlname . '" name="' . $htmlname . '" value="' . $obj -> nom . '" ' . $htmloption . ' />' ;
2008-10-01 23:16:35 +02:00
}
2009-08-28 01:31:50 +02:00
print ajax_autocompleter (( $socid ? $socid :- 1 ), $htmlname , DOL_URL_ROOT . '/societe/ajaxcompanies.php?filter=' . urlencode ( $filter ), '' );
2008-10-01 23:16:35 +02:00
print '</td>' ;
print '<td class="nobordernopadding" align="left" width="16">' ;
print ajax_indicator ( $htmlname , 'working' );
print '</td></tr>' ;
print '</table>' ;
}
else
{
print '<select class="flat" name="' . $htmlname . '">' ;
if ( $showempty ) print '<option value="-1"> </option>' ;
$num = $this -> db -> num_rows ( $resql );
$i = 0 ;
if ( $num )
{
while ( $i < $num )
{
$obj = $this -> db -> fetch_object ( $resql );
2009-08-05 18:58:18 +02:00
$label = $obj -> nom ;
if ( $showtype )
{
if ( $obj -> client || $obj -> fournisseur ) $label .= ' (' ;
2010-01-10 23:16:25 +01:00
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 " );
2009-08-05 18:58:18 +02:00
if ( $obj -> fournisseur ) $label .= ( $obj -> client ? ', ' : '' ) . $langs -> trans ( " Supplier " );
if ( $obj -> client || $obj -> fournisseur ) $label .= ')' ;
}
2008-10-01 23:16:35 +02:00
if ( $selected > 0 && $selected == $obj -> rowid )
{
2009-08-05 18:58:18 +02:00
print '<option value="' . $obj -> rowid . '" selected="true">' . $label . '</option>' ;
2008-10-01 23:16:35 +02:00
}
else
{
2009-08-05 18:58:18 +02:00
print '<option value="' . $obj -> rowid . '">' . $label . '</option>' ;
2008-10-01 23:16:35 +02:00
}
$i ++ ;
}
}
print '</select>' ;
}
}
else
{
2009-02-20 23:53:15 +01:00
dol_print_error ( $this -> db );
2008-10-01 23:16:35 +02:00
}
}
2006-06-04 00:01:38 +02:00
/**
2009-03-02 19:17:19 +01:00
* \brief Return HTML combo list of absolute discounts
2009-06-08 20:24:16 +02:00
* \param selected Id remise fixe pre - selectionnee
2008-08-09 00:12:27 +02:00
* \param htmlname Nom champ formulaire
* \param filter Criteres optionnels de filtre
2008-10-01 23:16:35 +02:00
* \param maxvalue Max value for lines that can be selected
* \return int Return number of qualifed lines in list
2006-06-04 00:01:38 +02:00
*/
2008-08-09 00:12:27 +02:00
function select_remises ( $selected = '' , $htmlname = 'remise_id' , $filter = '' , $socid , $maxvalue = 0 )
2008-10-01 23:16:35 +02:00
{
global $langs , $conf ;
// On recherche les remises
$sql = " SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc, " ;
2007-09-13 21:48:28 +02:00
$sql .= " re.description, re.fk_facture_source " ;
2007-04-03 01:45:50 +02:00
$sql .= " FROM " . MAIN_DB_PREFIX . " societe_remise_except as re " ;
2008-10-01 23:16:35 +02:00
$sql .= " WHERE fk_soc = " . $socid ;
if ( $filter ) $sql .= " AND " . $filter ;
$sql .= " ORDER BY re.description ASC " ;
2009-02-20 23:53:15 +01:00
dol_syslog ( " Form::select_remises sql= " . $sql );
2008-10-01 23:16:35 +02:00
$resql = $this -> db -> query ( $sql );
if ( $resql )
{
print '<select class="flat" name="' . $htmlname . '">' ;
$num = $this -> db -> num_rows ( $resql );
$qualifiedlines = $num ;
$i = 0 ;
if ( $num )
{
print '<option value="0"> </option>' ;
while ( $i < $num )
{
$obj = $this -> db -> fetch_object ( $resql );
2009-02-20 23:53:15 +01:00
$desc = dol_trunc ( $obj -> description , 40 );
2009-02-27 19:35:17 +01:00
if ( $desc == '(CREDIT_NOTE)' ) $desc = $langs -> trans ( " CreditNote " );
if ( $desc == '(DEPOSIT)' ) $desc = $langs -> trans ( " Deposit " );
2009-01-18 18:07:27 +01:00
2008-08-09 00:12:27 +02:00
$selectstring = '' ;
if ( $selected > 0 && $selected == $obj -> rowid ) $selectstring = ' selected="true"' ;
$disabled = '' ;
2008-10-01 23:16:35 +02:00
if ( $maxvalue && $obj -> amount_ttc > $maxvalue )
{
$qualifiedlines -- ;
$disabled = ' disabled="true"' ;
}
2008-08-09 00:12:27 +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>' ;
2008-10-01 23:16:35 +02:00
$i ++ ;
}
}
print '</select>' ;
return $qualifiedlines ;
}
else
{
2009-02-20 23:53:15 +01:00
dol_print_error ( $this -> db );
2008-10-01 23:16:35 +02:00
return - 1 ;
}
}
/**
2009-06-08 20:24:16 +02:00
* \brief Retourne la liste deroulante des contacts d ' une societe donnee
* \param socid Id de la societe
* \param selected Id contact pre - selectionne
2008-10-01 23:16:35 +02:00
* \param htmlname Nom champ formulaire ( 'none' pour champ non editable )
* \param show_empty 0 = liste sans valeur nulle , 1 = ajoute valeur inconnue
2009-06-08 20:24:16 +02:00
* \param exclude Liste des id contacts a exclure
2008-10-01 23:16:35 +02:00
* \return int < 0 if KO , Nb of contact in list if OK
*/
function select_contacts ( $socid , $selected = '' , $htmlname = 'contactid' , $showempty = 0 , $exclude = '' )
2007-11-04 19:34:16 +01:00
{
// Permettre l'exclusion de contacts
if ( is_array ( $exclude ))
{
$excludeContacts = implode ( " ',' " , $exclude );
}
2008-10-01 23:16:35 +02:00
2007-11-04 19:34:16 +01:00
// On recherche les societes
$sql = " SELECT s.rowid, s.name, s.firstname FROM " ;
$sql .= " " . MAIN_DB_PREFIX . " socpeople as s " ;
$sql .= " WHERE fk_soc= " . $socid ;
if ( is_array ( $exclude ) && $excludeContacts ) $sql .= " AND s.rowid NOT IN (' " . $excludeContacts . " ') " ;
$sql .= " ORDER BY s.name ASC " ;
2008-10-01 23:16:35 +02:00
2009-02-20 23:53:15 +01:00
dol_syslog ( " Form::select_contacts sql= " . $sql );
2007-11-04 19:34:16 +01:00
$resql = $this -> db -> query ( $sql );
if ( $resql )
{
$num = $this -> db -> num_rows ( $resql );
if ( $num == 0 ) return 0 ;
2009-01-18 18:07:27 +01:00
2007-11-04 19:34:16 +01:00
if ( $htmlname != 'none' ) print '<select class="flat" name="' . $htmlname . '">' ;
2007-11-22 19:20:20 +01:00
if ( $showempty ) print '<option value="0"> </option>' ;
2007-11-04 19:34:16 +01:00
$num = $this -> db -> num_rows ( $resql );
$i = 0 ;
if ( $num )
{
while ( $i < $num )
{
$obj = $this -> db -> fetch_object ( $resql );
if ( $htmlname != 'none' )
{
if ( $selected && $selected == $obj -> rowid )
{
print '<option value="' . $obj -> rowid . '" selected="true">' . $obj -> name . ' ' . $obj -> firstname . '</option>' ;
}
2006-02-18 23:04:32 +01:00
else
{
2007-11-04 19:34:16 +01:00
print '<option value="' . $obj -> rowid . '">' . $obj -> name . ' ' . $obj -> firstname . '</option>' ;
2006-02-18 23:04:32 +01:00
}
2007-10-29 21:22:55 +01:00
}
2007-11-04 19:34:16 +01:00
else
{
if ( $selected == $obj -> rowid ) print $obj -> name . ' ' . $obj -> firstname ;
}
$i ++ ;
2007-10-29 21:22:55 +01:00
}
}
2008-04-04 14:04:25 +02:00
if ( $htmlname != 'none' )
{
print '</select>' ;
}
2007-11-04 19:34:16 +01:00
return $num ;
}
else
{
2009-02-20 23:53:15 +01:00
dol_print_error ( $this -> db );
2007-11-04 19:34:16 +01:00
return - 1 ;
}
}
2008-10-01 23:16:35 +02:00
/**
2009-07-27 02:08:49 +02:00
* \brief Return select list of users
2008-10-01 23:16:35 +02: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 List of users id to exclude
* \param disabled If select list must be disabled
2009-07-27 02:08:49 +02:00
* \param include List of users id to include
2008-10-01 23:16:35 +02:00
*/
2009-07-27 02:08:49 +02:00
function select_users ( $selected = '' , $htmlname = 'userid' , $show_empty = 0 , $exclude = '' , $disabled = 0 , $include = '' )
2008-10-01 23:16:35 +02:00
{
2009-04-27 22:37:50 +02:00
global $conf ;
2009-05-04 20:38:01 +02:00
2008-10-01 23:16:35 +02:00
// Permettre l'exclusion d'utilisateurs
2009-04-27 22:37:50 +02:00
if ( is_array ( $exclude )) $excludeUsers = implode ( " ',' " , $exclude );
2009-07-27 02:08:49 +02:00
// Permettre l'inclusion d'utilisateurs
if ( is_array ( $include )) $includeUsers = implode ( " ',' " , $include );
2008-10-01 23:16:35 +02:00
2007-10-31 13:55:01 +01:00
// On recherche les utilisateurs
2009-07-18 18:17:56 +02:00
$sql = " SELECT u.rowid, u.name, u.firstname, u.login FROM " ;
2008-12-03 22:43:30 +01:00
$sql .= " " . MAIN_DB_PREFIX . " user as u " ;
2009-04-27 22:37:50 +02:00
$sql .= " WHERE u.entity IN (0, " . $conf -> entity . " ) " ;
if ( is_array ( $exclude ) && $excludeUsers ) $sql .= " AND u.rowid NOT IN (' " . $excludeUsers . " ') " ;
2009-07-27 02:08:49 +02:00
if ( is_array ( $include ) && $includeUsers ) $sql .= " AND u.rowid IN (' " . $includeUsers . " ') " ;
2007-10-31 13:55:01 +01:00
$sql .= " ORDER BY u.name ASC " ;
2007-10-29 21:22:55 +01:00
2009-02-20 23:53:15 +01:00
dol_syslog ( " Form::select_users sql= " . $sql );
2009-07-27 02:08:49 +02:00
$resql = $this -> db -> query ( $sql );
if ( $resql )
2007-10-31 13:55:01 +01:00
{
2008-03-02 19:47:42 +01:00
print '<select class="flat" name="' . $htmlname . '"' . ( $disabled ? ' disabled="true"' : '' ) . '>' ;
2007-10-31 13:55:01 +01:00
if ( $show_empty ) print '<option value="-1"' . ( $id ==- 1 ? ' selected="true"' : '' ) . '> </option>' . " \n " ;
2009-07-27 02:08:49 +02:00
$num = $this -> db -> num_rows ( $resql );
2007-10-31 13:55:01 +01:00
$i = 0 ;
if ( $num )
{
while ( $i < $num )
{
2009-07-27 02:08:49 +02:00
$obj = $this -> db -> fetch_object ( $resql );
2009-01-18 18:07:27 +01:00
2008-12-03 22:43:30 +01:00
if (( is_object ( $selected ) && $selected -> id == $obj -> rowid ) || ( ! is_object ( $selected ) && $selected == $obj -> rowid ))
2007-10-31 13:55:01 +01:00
{
2009-07-18 18:17:56 +02:00
print '<option value="' . $obj -> rowid . '" selected="true">' ;
2007-10-31 13:55:01 +01:00
}
else
{
2009-07-18 18:17:56 +02:00
print '<option value="' . $obj -> rowid . '">' ;
2007-10-31 13:55:01 +01:00
}
2009-07-18 18:17:56 +02:00
print $obj -> name . ( $obj -> name && $obj -> firstname ? ' ' : '' ) . $obj -> firstname ;
2010-03-10 20:27:29 +01:00
if ( $conf -> global -> MAIN_SHOW_LOGIN ) print ' (' . $obj -> login . ')' ;
2009-07-18 18:17:56 +02:00
print '</option>' ;
2007-10-31 13:55:01 +01:00
$i ++ ;
}
}
print '</select>' ;
}
else
{
2009-02-20 23:53:15 +01:00
dol_print_error ( $this -> db );
2007-10-31 13:55:01 +01:00
}
2007-05-26 01:24:21 +02:00
}
2008-10-01 23:16:35 +02:00
/**
2009-03-28 20:00:13 +01:00
* \brief Return list of products for customer in Ajax if Ajax activated or go to select_produits_do
* \param selected Preselected products
* \param htmlname Name of HTML select
2008-10-01 23:16:35 +02:00
* \param filtertype Filter on product type ( '' = nofilter , 0 = product , 1 = service )
2009-06-08 20:24:16 +02:00
* \param limit Limit sur le nombre de lignes retournees
2009-03-28 20:00:13 +01:00
* \param price_level Level of price to show
2008-12-07 22:38:33 +01:00
* \param status - 1 = Return all products , 0 = Products not on sell , 1 = Products on sell
* \param finished 2 = all , 1 = finished , 0 = raw material
2008-10-01 23:16:35 +02:00
*/
2008-12-07 22:38:33 +01:00
function select_produits ( $selected = '' , $htmlname = 'productid' , $filtertype = '' , $limit = 20 , $price_level = 0 , $status = 1 , $finished = 2 )
2008-10-01 23:16:35 +02:00
{
global $langs , $conf ;
if ( $conf -> global -> PRODUIT_USE_SEARCH_TO_SELECT )
{
2010-03-04 09:28:30 +01:00
if ( $conf -> global -> MAIN_USE_JQUERY )
{
print ajax_autocompleter2 ( '' , 'keysearch' , DOL_URL_ROOT . '/product/ajaxproducts.php' , '&price_level=' . $price_level . '&type=' . $filtertype . '&mode=1&status=' . $status . '&finished=' . $finished , '' );
2010-03-13 00:40:39 +01:00
2010-03-04 09:28:30 +01:00
print '<div class="ui-widget">' ;
print '<label for="birds">' . $langs -> trans ( " RefOrLabel " ) . ':</label>' ;
print '<input id="birds" />' ;
print '</div>' ;
}
else
{
print '<table class="nobordernopadding" width="100%"><tr class="nocellnopadd">' ;
print '<td class="nobordernopadding" nowrap="nowrap" width="80">' ;
print $langs -> trans ( " RefOrLabel " ) . ':</td>' ;
print '<td class="nobordernopadding" width="16">' ;
print ajax_indicator ( $htmlname , 'working' ); // Indicator is et here
print '</td>' ;
print '<td><input type="text" size="16" name="keysearch' . $htmlname . '" id="keysearch' . $htmlname . '"></td>' ;
print '</tr>' ;
print '<tr class="nocellnopadd">' ;
print '<td class="nobordernopadding" colspan="3">' ;
print ajax_updater ( $htmlname , 'keysearch' , DOL_URL_ROOT . '/product/ajaxproducts.php' , '&price_level=' . $price_level . '&type=' . $filtertype . '&mode=1&status=' . $status . '&finished=' . $finished , '' ); // Indicator is '' to disable it as it is alreay output
print '</td></tr>' ;
print '</table>' ;
2010-03-13 00:40:39 +01:00
}
2008-10-01 23:16:35 +02:00
}
else
{
2008-12-07 22:38:33 +01:00
$this -> select_produits_do ( $selected , $htmlname , $filtertype , $limit , $price_level , '' , $status , $finished );
2008-10-01 23:16:35 +02:00
}
}
2007-05-26 01:24:21 +02:00
/**
2009-03-28 20:00:13 +01:00
* \brief Return list of products for a customer
* \param selected Preselected product
* \param htmlname Name of select html
2008-08-06 15:06:58 +02:00
* \param filtertype Filter on product type ( '' = nofilter , 0 = product , 1 = service )
2009-06-08 20:24:16 +02:00
* \param limit Limite sur le nombre de lignes retournees
2009-03-28 20:00:13 +01:00
* \param price_level Level of price to show
* \param ajaxkeysearch Filter on product if ajax is used
2008-08-06 15:06:58 +02:00
* \param status - 1 = Return all products , 0 = Products not on sell , 1 = Products on sell
*/
2008-12-07 22:38:33 +01:00
function select_produits_do ( $selected = '' , $htmlname = 'productid' , $filtertype = '' , $limit = 20 , $price_level = 0 , $ajaxkeysearch = '' , $status = 1 , $finished = 2 )
2007-05-26 01:24:21 +02:00
{
2010-03-13 22:53:44 +01:00
global $langs , $conf , $user , $db ;
2008-10-01 23:16:35 +02:00
2007-05-26 01:24:21 +02:00
$sql = " SELECT " ;
2009-05-27 18:11:33 +02:00
$sql .= " p.rowid, p.label, p.ref, p.fk_product_type, p.price, p.price_ttc, p.price_base_type, p.duration, p.stock " ;
2007-05-26 01:24:21 +02:00
$sql .= " FROM " . MAIN_DB_PREFIX . " product as p " ;
2009-04-30 11:54:57 +02:00
$sql .= " WHERE p.entity = " . $conf -> entity ;
2010-03-13 22:53:44 +01:00
if ( ! $user -> rights -> produit -> hidden ) $sql .= ' AND (p.hidden=0 OR p.fk_product_type != 0)' ;
if ( ! $user -> rights -> service -> hidden ) $sql .= ' AND (p.hidden=0 OR p.fk_product_type != 1)' ;
2009-05-04 20:38:01 +02:00
2008-12-07 22:38:33 +01:00
if ( $finished == 0 )
2009-01-18 18:07:27 +01:00
{
2009-04-27 22:37:50 +02:00
$sql .= " AND p.finished = " . $finished ;
2008-12-07 22:38:33 +01:00
}
elseif ( $finished == 1 )
{
2009-04-27 22:37:50 +02:00
$sql .= " AND p.finished = " . $finished ;
2008-12-07 22:38:33 +01:00
if ( $status >= 0 ) $sql .= " AND p.envente = " . $status ;
}
elseif ( $status >= 0 )
{
2009-04-27 22:37:50 +02:00
$sql .= " AND p.envente = " . $status ;
2008-12-07 22:38:33 +01:00
}
2008-08-06 15:06:58 +02:00
if ( strval ( $filtertype ) != '' ) $sql .= " AND p.fk_product_type= " . $filtertype ;
2008-07-10 23:50:23 +02:00
if ( $ajaxkeysearch && $ajaxkeysearch != '' ) $sql .= " AND (p.ref like '% " . $ajaxkeysearch . " %' OR p.label like '% " . $ajaxkeysearch . " %') " ;
2010-03-13 22:53:44 +01:00
$sql .= $db -> order ( " p.ref " );
$sql .= $db -> plimit ( $limit );
2008-10-01 23:16:35 +02:00
2009-02-20 23:53:15 +01:00
dol_syslog ( " Form::select_produits_do sql= " . $sql , LOG_DEBUG );
2007-05-26 01:24:21 +02:00
$result = $this -> db -> query ( $sql );
2009-02-20 23:53:15 +01:00
if ( ! $result ) dol_print_error ( $this -> db );
2008-10-01 23:16:35 +02:00
2009-06-08 13:03:37 +02:00
// Multilang : on construit une liste des traductions des produits listes
2007-05-26 01:24:21 +02:00
if ( $conf -> global -> MAIN_MULTILANGS )
{
$sqld = " SELECT d.fk_product, d.label " ;
2010-02-18 10:04:55 +01:00
$sqld .= " FROM " . MAIN_DB_PREFIX . " product as p " ;
$sqld .= " , " . MAIN_DB_PREFIX . " product_lang as d " ;
2009-04-30 11:54:57 +02:00
$sqld .= " WHERE d.fk_product = p.rowid " ;
$sqld .= " AND p.entity = " . $conf -> entity ;
$sqld .= " AND p.envente = 1 " ;
$sqld .= " AND d.lang=' " . $langs -> getDefaultLang () . " ' " ;
2008-10-07 22:19:04 +02:00
$sqld .= " ORDER BY p.ref " ;
2008-01-11 18:16:46 +01:00
2009-02-20 23:53:15 +01:00
dol_syslog ( " Form::select_produits_do sql= " . $sql , LOG_DEBUG );
2006-06-14 01:55:33 +02:00
$resultd = $this -> db -> query ( $sqld );
}
2008-10-01 23:16:35 +02:00
2007-05-08 15:33:22 +02:00
if ( $result )
{
$num = $this -> db -> num_rows ( $result );
2009-01-18 18:07:27 +01:00
2008-01-06 16:24:23 +01:00
if ( $conf -> use_javascript_ajax )
2007-05-08 15:33:22 +02:00
{
2006-06-14 01:55:33 +02:00
if ( ! $num )
{
2006-08-02 03:39:27 +02:00
print '<select class="flat" name="' . $htmlname . '">' ;
print '<option value="0">-- ' . $langs -> trans ( " NoProductMatching " ) . ' --</option>' ;
2006-06-14 01:55:33 +02:00
}
2006-08-02 03:39:27 +02:00
else
{
2008-10-01 23:16:35 +02:00
print '<select class="flat" name="' . $htmlname . '"' ;
if ( $conf -> global -> PRODUIT_USE_SEARCH_TO_SELECT ) print ' onchange="publish_selvalue(this);"' ;
print '>' ;
2007-05-26 01:24:21 +02:00
print '<option value="0" selected="true">-- ' . $langs -> trans ( " MatchingProducts " ) . ' --</option>' ;
2006-08-02 03:39:27 +02:00
}
2006-06-14 01:55:33 +02:00
}
2006-05-11 11:00:11 +02:00
else
2006-06-14 01:55:33 +02:00
{
2006-05-11 11:00:11 +02:00
print '<select class="flat" name="' . $htmlname . '">' ;
2007-05-26 01:24:21 +02:00
print '<option value="0" selected="true"> </option>' ;
}
2009-01-18 18:07:27 +01:00
2007-05-26 01:24:21 +02:00
$i = 0 ;
while ( $num && $i < $num )
{
$objp = $this -> db -> fetch_object ( $result );
2008-10-01 23:16:35 +02:00
2009-06-08 13:03:37 +02:00
// Multilangs : modification des donnees si une traduction existe
2006-03-22 00:47:01 +01:00
if ( $conf -> global -> MAIN_MULTILANGS )
2006-06-14 01:55:33 +02:00
{
2009-06-08 12:56:54 +02:00
if ( $resultd ) $objtp = $this -> db -> fetch_object ( $resultd );
2006-02-27 17:15:07 +01:00
if ( $objp -> rowid == $objtp -> fk_product ) // si on a une traduction
{
if ( $objtp -> label != '' ) $objp -> label = $objtp -> label ;
}
2006-06-14 01:55:33 +02:00
}
2009-05-15 13:02:54 +02:00
$opt = '<option value="' . $objp -> rowid . '"' ;
$opt .= ( $objp -> rowid == $selected ) ? ' selected="true"' : '' ;
2009-12-07 21:53:22 +01: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;"' ;
}
}
2009-05-15 13:02:54 +02:00
$opt .= '>' . $objp -> ref . ' - ' ;
2009-02-20 23:53:15 +01:00
$opt .= dol_trunc ( $objp -> label , 32 ) . ' - ' ;
2007-07-16 00:26:29 +02:00
2009-06-19 09:32:39 +02:00
$found = 0 ;
$currencytext = $langs -> trans ( " Currency " . $conf -> monnaie );
if ( strlen ( $currencytext ) > 10 ) $currencytext = $conf -> monnaie ; // If text is too long, we use the short code
2009-07-07 17:11:59 +02:00
2009-03-28 20:00:13 +01:00
// Multiprice
2009-06-19 09:32:39 +02:00
if ( $price_level >= 1 ) // If we need a particular price level (from 1 to 6)
2006-02-09 18:36:09 +01:00
{
2007-06-22 00:56:17 +02:00
$sql = " SELECT price, price_ttc, price_base_type " ;
2007-05-26 01:24:21 +02:00
$sql .= " FROM " . MAIN_DB_PREFIX . " product_price " ;
2009-06-16 20:41:01 +02:00
$sql .= " WHERE fk_product=' " . $objp -> rowid . " ' " ;
2009-04-30 11:54:57 +02:00
$sql .= " AND price_level= " . $price_level ;
$sql .= " ORDER BY date_price " ;
$sql .= " DESC limit 1 " ;
2008-01-11 18:16:46 +01:00
2009-02-20 23:53:15 +01:00
dol_syslog ( " Form::select_produits_do sql= " . $sql );
2007-07-16 00:26:29 +02:00
$result2 = $this -> db -> query ( $sql );
2009-06-08 12:56:54 +02:00
if ( $result2 )
2007-07-16 00:26:29 +02:00
{
2009-06-08 12:56:54 +02:00
$objp2 = $this -> db -> fetch_object ( $result2 );
if ( $objp2 )
{
2009-06-19 09:32:39 +02:00
$found = 1 ;
2009-06-08 12:56:54 +02:00
if ( $objp2 -> price_base_type == 'HT' )
2009-06-19 09:32:39 +02:00
$opt .= price ( $objp2 -> price , 1 ) . ' ' . $currencytext . ' ' . $langs -> trans ( " HT " );
2009-06-08 12:56:54 +02:00
else
2009-06-19 09:32:39 +02:00
$opt .= price ( $objp2 -> price_ttc , 1 ) . ' ' . $currencytext . ' ' . $langs -> trans ( " TTC " );
2009-06-08 12:56:54 +02:00
}
2008-10-01 23:16:35 +02:00
}
2009-06-16 20:41:01 +02:00
else
{
dol_print_error ( $this -> db );
}
2006-02-09 18:36:09 +01:00
}
2009-06-19 09:32:39 +02:00
// If level no defined or multiprice not found, we used the default price
if ( ! $found )
2007-05-08 15:33:22 +02:00
{
2007-06-22 00:56:17 +02:00
if ( $objp -> price_base_type == 'HT' )
2009-06-19 09:32:39 +02:00
$opt .= price ( $objp -> price , 1 ) . ' ' . $currencytext . ' ' . $langs -> trans ( " HT " );
2007-06-22 00:56:17 +02:00
else
2009-06-19 09:32:39 +02:00
$opt .= price ( $objp -> price_ttc , 1 ) . ' ' . $currencytext . ' ' . $langs -> trans ( " TTC " );
2007-05-08 15:33:22 +02:00
}
2008-10-01 23:16:35 +02:00
2009-05-27 18:11:33 +02:00
if ( $conf -> stock -> enabled && isset ( $objp -> stock ) && $objp -> fk_product_type == 0 )
{
$opt .= ' - ' . $langs -> trans ( " Stock " ) . ':' . $objp -> stock ;
}
2007-09-09 14:46:21 +02:00
if ( $objp -> duration )
{
$duration_value = substr ( $objp -> duration , 0 , strlen ( $objp -> duration ) - 1 );
$duration_unit = substr ( $objp -> duration , - 1 );
if ( $duration_value > 1 )
{
$dur = array ( " h " => $langs -> trans ( " Hours " ), " d " => $langs -> trans ( " Days " ), " w " => $langs -> trans ( " Weeks " ), " m " => $langs -> trans ( " Months " ), " y " => $langs -> trans ( " Years " ));
}
else
{
$dur = array ( " h " => $langs -> trans ( " Hour " ), " d " => $langs -> trans ( " Day " ), " w " => $langs -> trans ( " Week " ), " m " => $langs -> trans ( " Month " ), " y " => $langs -> trans ( " Year " ));
}
$opt .= ' - ' . $duration_value . ' ' . $langs -> trans ( $dur [ $duration_unit ]);
}
2008-10-01 23:16:35 +02:00
2007-05-08 15:33:22 +02:00
$opt .= " </option> \n " ;
2007-05-26 01:24:21 +02:00
print $opt ;
$i ++ ;
}
2009-01-18 18:07:27 +01:00
2008-10-01 23:16:35 +02:00
print '</select>' ;
2009-01-18 18:07:27 +01:00
2007-05-26 01:24:21 +02:00
$this -> db -> free ( $result );
}
else
{
2009-02-20 23:53:15 +01:00
dol_print_error ( $db );
2007-05-26 01:24:21 +02:00
}
}
2008-10-01 23:16:35 +02:00
2007-07-08 14:41:24 +02:00
/**
2009-03-28 20:00:13 +01:00
* \brief Return list of products for customer in Ajax if Ajax activated or go to select_produits_fournisseurs_do
2008-08-06 15:06:58 +02:00
* \param socid Id third party
2009-03-28 20:00:13 +01:00
* \param selected Preselected product
* \param htmlname Name of HTML Select
2008-08-06 15:06:58 +02:00
* \param filtertype Filter on product type ( '' = nofilter , 0 = product , 1 = service )
2009-03-28 20:00:13 +01:00
* \param filtre For a SQL filter
2008-08-06 15:06:58 +02:00
*/
function select_produits_fournisseurs ( $socid , $selected = '' , $htmlname = 'productid' , $filtertype = '' , $filtre )
2007-07-08 14:41:24 +02:00
{
global $langs , $conf ;
if ( $conf -> global -> PRODUIT_USE_SEARCH_TO_SELECT )
{
print $langs -> trans ( " RefOrLabel " ) . ' : <input type="text" size="16" name="keysearch' . $htmlname . '" id="keysearch' . $htmlname . '">' ;
2009-08-28 01:31:50 +02:00
print ajax_updater ( $htmlname , 'keysearch' , DOL_URL_ROOT . '/product/ajaxproducts.php' , '&socid=' . $socid . '&type=' . $filtertype . '&mode=2' , 'working' );
2007-07-08 14:41:24 +02:00
}
else
{
2008-08-06 15:06:58 +02:00
$this -> select_produits_fournisseurs_do ( $socid , $selected , $htmlname , $filtertype , $filtre , '' );
2008-10-01 23:16:35 +02:00
}
2007-07-08 14:41:24 +02:00
}
2008-10-01 23:16:35 +02:00
2007-04-02 01:04:24 +02:00
/**
2008-08-06 15:06:58 +02:00
* \brief Retourne la liste des produits de fournisseurs
2009-06-08 13:03:37 +02:00
* \param socid Id societe fournisseur ( 0 pour aucun filtre )
* \param selected Produit pre - selectionne
2008-08-06 15:06:58 +02:00
* \param htmlname Nom de la zone select
* \param filtertype Filter on product type ( '' = nofilter , 0 = product , 1 = service )
* \param filtre Pour filtre sql
2009-06-08 13:03:37 +02:00
* \param ajaxkeysearch Filtre des produits si ajax est utilise
2008-08-06 15:06:58 +02:00
*/
function select_produits_fournisseurs_do ( $socid , $selected = '' , $htmlname = 'productid' , $filtertype = '' , $filtre = '' , $ajaxkeysearch = '' )
2007-04-02 01:04:24 +02:00
{
global $langs , $conf ;
2008-10-01 23:16:35 +02:00
2007-09-05 00:22:14 +02:00
$langs -> load ( 'stocks' );
2008-10-01 23:16:35 +02:00
2007-07-09 00:23:03 +02:00
$sql = " SELECT p.rowid, p.label, p.ref, p.price, p.duration, " ;
2008-03-16 15:52:31 +01:00
$sql .= " pf.ref_fourn, " ;
$sql .= " pfp.rowid as idprodfournprice, pfp.price as fprice, pfp.quantity, pfp.unitprice, " ;
$sql .= " s.nom " ;
2007-04-02 01:04:24 +02:00
$sql .= " FROM " . MAIN_DB_PREFIX . " product as p " ;
2007-09-04 20:19:06 +02:00
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " product_fournisseur as pf ON p.rowid = pf.fk_product " ;
2008-03-16 15:52:31 +01:00
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " societe as s ON pf.fk_soc = s.rowid " ;
2007-09-04 20:19:06 +02:00
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " product_fournisseur_price as pfp ON pf.rowid = pfp.fk_product_fournisseur " ;
2009-07-22 14:09:19 +02:00
$sql .= " WHERE p.entity = " . $conf -> entity ;
$sql .= " AND p.envente = 1 " ;
2007-09-04 20:19:06 +02:00
if ( $socid ) $sql .= " AND pf.fk_soc = " . $socid ;
2008-08-06 15:06:58 +02:00
if ( strval ( $filtertype ) != '' ) $sql .= " AND p.fk_product_type= " . $filtertype ;
2008-07-10 23:50:23 +02:00
if ( ! empty ( $filtre )) $sql .= " " . $filtre ;
2009-02-14 01:52:30 +01:00
if ( $ajaxkeysearch && $ajaxkeysearch != '' ) $sql .= " AND (pf.ref_fourn like '% " . $ajaxkeysearch . " %' OR p.ref like '% " . $ajaxkeysearch . " %' OR p.label like '% " . $ajaxkeysearch . " %') " ;
2007-09-04 20:19:06 +02:00
$sql .= " ORDER BY pf.ref_fourn DESC " ;
2009-02-20 23:53:15 +01:00
dol_syslog ( " Form::select_produits_fournisseurs_do sql= " . $sql , LOG_DEBUG );
2007-04-02 01:04:24 +02:00
$result = $this -> db -> query ( $sql );
if ( $result )
{
2009-01-18 18:07:27 +01:00
2007-04-02 01:04:24 +02:00
$num = $this -> db -> num_rows ( $result );
2009-01-18 18:07:27 +01:00
2008-01-06 16:24:23 +01:00
if ( $conf -> use_javascript_ajax )
2007-07-08 14:41:24 +02:00
{
if ( ! $num )
{
print '<select class="flat" name="' . $htmlname . '">' ;
print '<option value="0">-- ' . $langs -> trans ( " NoProductMatching " ) . ' --</option>' ;
}
else
{
print '<select class="flat" name="' . $htmlname . '" onchange="publish_selvalue(this);">' ;
print '<option value="0" selected="true">-- ' . $langs -> trans ( " MatchingProducts " ) . ' --</option>' ;
}
}
else
{
print '<select class="flat" name="' . $htmlname . '">' ;
if ( ! $selected ) print '<option value="0" selected="true"> </option>' ;
else print '<option value="0"> </option>' ;
}
2009-01-18 18:07:27 +01:00
2007-04-02 01:04:24 +02:00
$i = 0 ;
while ( $i < $num )
{
$objp = $this -> db -> fetch_object ( $result );
2008-10-01 23:16:35 +02:00
2007-09-04 20:19:06 +02:00
$opt = '<option value="' . $objp -> idprodfournprice . '"' ;
if ( $selected == $objp -> idprodfournprice ) $opt .= ' selected="true"' ;
2007-07-08 14:41:24 +02:00
if ( $objp -> fprice == '' ) $opt .= ' disabled="disabled"' ;
2008-09-04 22:03:15 +02:00
$opt .= '>' . $objp -> ref . ' (' . $objp -> ref_fourn . ') - ' ;
2009-02-20 23:53:15 +01:00
$opt .= dol_trunc ( $objp -> label , 18 ) . ' - ' ;
2008-03-16 15:52:31 +01:00
if ( $objp -> fprice != '' ) // Keep != ''
2007-07-08 14:41:24 +02:00
{
2009-07-10 01:47:59 +02:00
$currencytext = $langs -> trans ( " Currency " . $conf -> monnaie );
if ( strlen ( $currencytext ) > 10 ) $currencytext = $conf -> monnaie ; // If text is too long, we use the short code
2007-07-09 00:23:03 +02:00
$opt .= price ( $objp -> fprice );
2009-07-10 01:47:59 +02:00
$opt .= ' ' . $currencytext . " / " . $objp -> quantity ;
2007-09-05 00:22:14 +02:00
if ( $objp -> quantity == 1 )
{
$opt .= strtolower ( $langs -> trans ( " Unit " ));
}
else
{
$opt .= strtolower ( $langs -> trans ( " Units " ));
}
2008-07-27 22:47:13 +02:00
if ( $objp -> quantity >= 1 )
2007-07-08 14:41:24 +02:00
{
2008-03-16 15:52:31 +01:00
$opt .= " ( " ;
2009-07-10 01:47:59 +02:00
$opt .= price ( $objp -> unitprice ) . ' ' . $currencytext . " / " . strtolower ( $langs -> trans ( " Unit " ));
2008-03-16 15:52:31 +01:00
$opt .= " ) " ;
2007-07-08 14:41:24 +02:00
}
if ( $objp -> duration ) $opt .= " - " . $objp -> duration ;
2009-02-20 23:53:15 +01:00
if ( ! $socid ) $opt .= " - " . dol_trunc ( $objp -> nom , 8 );
2007-07-08 14:41:24 +02:00
}
else
2007-04-02 01:04:24 +02:00
{
2007-07-08 14:41:24 +02:00
$opt .= $langs -> trans ( " NoPriceDefinedForThisSupplier " );
2007-04-02 01:04:24 +02:00
}
$opt .= " </option> \n " ;
2008-10-01 23:16:35 +02:00
2007-04-02 01:04:24 +02:00
print $opt ;
$i ++ ;
}
print '</select>' ;
2009-01-18 18:07:27 +01:00
2007-04-02 01:04:24 +02:00
$this -> db -> free ( $result );
}
else
{
2009-02-20 23:53:15 +01:00
dol_print_error ( $db );
2007-04-02 01:04:24 +02:00
}
}
2008-10-01 23:16:35 +02:00
2007-09-05 11:18:06 +02:00
/**
2008-07-27 22:47:13 +02:00
\brief Retourne la liste des tarifs fournisseurs pour un produit
\param productid Id product
2008-10-01 23:16:35 +02:00
*/
2007-09-05 11:20:18 +02:00
function select_product_fourn_price ( $productid , $htmlname = 'productfournpriceid' )
2007-09-05 11:18:06 +02:00
{
global $langs , $conf ;
2008-10-01 23:16:35 +02:00
2007-09-05 11:18:06 +02:00
$langs -> load ( 'stocks' );
2008-10-01 23:16:35 +02:00
2007-09-05 11:18:06 +02:00
$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.envente = 1 " ;
$sql .= " AND s.fournisseur = 1 " ;
$sql .= " AND p.rowid = " . $productid ;
$sql .= " ORDER BY s.nom, pf.ref_fourn DESC " ;
2009-02-20 23:53:15 +01:00
dol_syslog ( " Form::select_product_fourn_price sql= " . $sql , LOG_DEBUG );
2007-09-05 11:18:06 +02:00
$result = $this -> db -> query ( $sql );
2008-10-01 23:16:35 +02:00
2007-09-05 11:18:06 +02:00
if ( $result )
{
$num = $this -> db -> num_rows ( $result );
2009-01-18 18:07:27 +01:00
2007-09-06 22:59:41 +02:00
$form = '<select class="flat" name="' . $htmlname . '">' ;
2009-01-18 18:07:27 +01:00
2007-09-05 11:18:06 +02:00
if ( ! $num )
{
2007-09-06 22:59:41 +02:00
$form .= '<option value="0">-- ' . $langs -> trans ( " NoSupplierPriceDefinedForThisProduct " ) . ' --</option>' ;
2007-09-05 11:18:06 +02:00
}
else
{
2007-09-06 22:59:41 +02:00
$form .= '<option value="0"> </option>' ;
2008-10-01 23:16:35 +02:00
2007-09-05 11:18:06 +02:00
$i = 0 ;
while ( $i < $num )
{
$objp = $this -> db -> fetch_object ( $result );
2009-01-18 18:07:27 +01:00
2007-09-05 11:18:06 +02:00
$opt = '<option value="' . $objp -> idprodfournprice . '"' ;
$opt .= '>' . $objp -> nom . ' - ' . $objp -> ref_fourn . ' - ' ;
2009-01-18 18:07:27 +01:00
2007-09-05 13:14:20 +02:00
if ( $objp -> quantity == 1 )
2007-09-05 11:18:06 +02:00
{
2007-09-05 13:14:20 +02:00
$opt .= price ( $objp -> fprice );
$opt .= $langs -> trans ( " Currency " . $conf -> monnaie ) . " / " ;
}
2008-10-01 23:16:35 +02:00
2007-09-06 22:59:41 +02:00
$opt .= $objp -> quantity . ' ' ;
2008-10-01 23:16:35 +02:00
2007-09-05 13:14:20 +02:00
if ( $objp -> quantity == 1 )
{
$opt .= strtolower ( $langs -> trans ( " Unit " ));
2007-09-05 11:18:06 +02:00
}
else
{
2007-09-05 13:14:20 +02:00
$opt .= strtolower ( $langs -> trans ( " Units " ));
2007-09-05 11:18:06 +02:00
}
2007-09-05 13:14:20 +02:00
if ( $objp -> quantity > 1 )
{
$opt .= " - " ;
$opt .= price ( $objp -> unitprice ) . $langs -> trans ( " Currency " . $conf -> monnaie ) . " / " . strtolower ( $langs -> trans ( " Unit " ));
}
if ( $objp -> duration ) $opt .= " - " . $objp -> duration ;
2007-09-05 11:18:06 +02:00
$opt .= " </option> \n " ;
2009-01-18 18:07:27 +01:00
2007-09-06 22:59:41 +02:00
$form .= $opt ;
2007-09-05 11:18:06 +02:00
$i ++ ;
}
2007-09-06 22:59:41 +02:00
$form .= '</select>' ;
2008-10-01 23:16:35 +02:00
2007-09-05 11:18:06 +02:00
$this -> db -> free ( $result );
}
2007-09-06 22:59:41 +02:00
return $form ;
2007-09-05 11:18:06 +02:00
}
else
{
2009-02-20 23:53:15 +01:00
dol_print_error ( $db );
2007-09-05 11:18:06 +02:00
}
}
2006-02-09 18:36:09 +01:00
2008-10-01 23:16:35 +02:00
/**
2009-06-08 13:03:37 +02:00
* \brief Retourne la liste deroulante des adresses de livraison
* \param selected Id contact pre - selectionn
2008-10-01 23:16:35 +02:00
* \param htmlname Nom champ formulaire
*/
function select_adresse_livraison ( $selected = '' , $socid , $htmlname = 'adresse_livraison_id' , $showempty = 0 )
{
// On recherche les utilisateurs
$sql = " SELECT a.rowid, a.label " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " societe_adresse_livraison as a " ;
$sql .= " WHERE a.fk_societe = " . $socid ;
$sql .= " ORDER BY a.label ASC " ;
2006-08-15 19:33:56 +02:00
2009-02-20 23:53:15 +01:00
dol_syslog ( " Form::select_adresse_livraison sql= " . $sql );
2008-10-01 23:16:35 +02:00
if ( $this -> db -> query ( $sql ))
2006-03-13 17:44:13 +01:00
{
2008-10-01 23:16:35 +02:00
print '<select class="flat" name="' . $htmlname . '">' ;
if ( $showempty ) print '<option value="0"> </option>' ;
$num = $this -> db -> num_rows ();
$i = 0 ;
if ( $num )
2006-04-07 23:04:14 +02:00
{
2008-10-01 23:16:35 +02:00
while ( $i < $num )
2006-08-15 19:33:56 +02:00
{
2008-10-01 23:16:35 +02:00
$obj = $this -> db -> fetch_object ();
if ( $selected && $selected == $obj -> rowid )
2007-08-26 20:52:03 +02:00
{
2008-10-01 23:16:35 +02:00
print '<option value="' . $obj -> rowid . '" selected="true">' . $obj -> label . '</option>' ;
2007-08-26 20:52:03 +02:00
}
else
{
2008-10-01 23:16:35 +02:00
print '<option value="' . $obj -> rowid . '">' . $obj -> label . '</option>' ;
2007-08-26 20:52:03 +02:00
}
2008-10-01 23:16:35 +02:00
$i ++ ;
2006-08-15 19:33:56 +02:00
}
2006-04-07 23:04:14 +02:00
}
2008-10-01 23:16:35 +02:00
print '</select>' ;
return $num ;
2006-03-13 17:44:13 +01:00
}
2008-10-01 23:16:35 +02:00
else
{
2009-02-20 23:53:15 +01:00
dol_print_error ( $this -> db );
2006-11-11 01:46:15 +01:00
}
2006-11-10 01:28:39 +01:00
}
2008-10-01 23:16:35 +02:00
/**
* \brief Charge dans cache la liste des conditions de paiements possibles
2009-06-08 13:03:37 +02:00
* \return int Nb lignes chargees , 0 si deja chargees , < 0 si ko
2008-10-01 23:16:35 +02:00
*/
function load_cache_conditions_paiements ()
{
global $langs ;
2009-06-08 13:03:37 +02:00
if ( sizeof ( $this -> cache_conditions_paiements )) return 0 ; // Cache deja charge
2008-10-01 23:16:35 +02:00
$sql = " SELECT rowid, code, libelle " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " cond_reglement " ;
$sql .= " WHERE active=1 " ;
$sql .= " ORDER BY sortorder " ;
2009-02-20 23:53:15 +01:00
dol_syslog ( 'Form::load_cache_conditions_paiements sql=' . $sql , LOG_DEBUG );
2008-10-01 23:16:35 +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 );
2009-06-08 13:03:37 +02:00
// Si traduction existe, on l'utilise, sinon on prend le libelle par defaut
2008-10-01 23:16:35 +02:00
$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 {
2009-02-20 23:53:15 +01:00
dol_print_error ( $this -> db );
2008-10-01 23:16:35 +02:00
return - 1 ;
}
}
/**
* \brief Charge dans cache la liste des types de paiements possibles
2009-06-08 13:03:37 +02:00
* \return int Nb lignes chargees , 0 si deja chargees , < 0 si ko
2008-10-01 23:16:35 +02:00
*/
function load_cache_types_paiements ()
{
global $langs ;
2009-06-08 13:03:37 +02:00
if ( sizeof ( $this -> cache_types_paiements )) return 0 ; // Cache deja charge
2008-10-01 23:16:35 +02:00
$sql = " SELECT id, code, libelle, type " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " c_paiement " ;
$sql .= " WHERE active > 0 " ;
$sql .= " ORDER BY id " ;
2009-02-20 23:53:15 +01:00
dol_syslog ( 'Form::load_cache_types_paiements sql=' . $sql , LOG_DEBUG );
2008-10-01 23:16:35 +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 );
2009-06-08 13:03:37 +02:00
// Si traduction existe, on l'utilise, sinon on prend le libelle par defaut
2008-10-01 23:16:35 +02:00
$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 {
2009-02-20 23:53:15 +01:00
dol_print_error ( $this -> db );
2008-10-01 23:16:35 +02:00
return - 1 ;
}
}
/**
* \brief Retourne la liste des types de paiements possibles
2009-06-08 13:03:37 +02:00
* \param selected Id du type de paiement pre - selectionne
2008-10-01 23:16:35 +02:00
* \param htmlname Nom de la zone select
* \param filtertype Pour filtre
2009-06-08 13:03:37 +02:00
* \param addempty Ajoute entree vide
2008-10-01 23:16:35 +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 )
{
print '<option value="' . $id . '" selected="true">' ;
}
else
{
print '<option value="' . $id . '">' ;
}
print $arrayconditions [ 'label' ];
print '</option>' ;
}
print '</select>' ;
if ( $user -> admin ) print info_admin ( $langs -> trans ( " YouCanChangeValuesForThisListFromDictionnarySetup " ), 1 );
}
/**
* \brief Retourne la liste des modes de paiements possibles
2009-06-08 13:03:37 +02:00
* \param selected Id du mode de paiement pre - selectionne
2008-10-01 23:16:35 +02:00
* \param htmlname Nom de la zone select
* \param filtertype Pour filtre
* \param format 0 = id + libelle , 1 = code + code , 2 = code + libelle
* \param empty 1 = peut etre vide , 0 sinon
* \param noadmininfo 0 = Add admin info , 1 = Disable admin info
*/
function select_types_paiements ( $selected = '' , $htmlname = 'paiementtype' , $filtertype = '' , $format = 0 , $empty = 0 , $noadmininfo = 0 )
{
global $langs , $user ;
2009-02-20 23:53:15 +01:00
dol_syslog ( " Form::select_type_paiements $selected , $htmlname , $filtertype , $format " , LOG_DEBUG );
2008-10-01 23:16:35 +02:00
$filterarray = array ();
if ( $filtertype == 'CRDT' ) $filterarray = array ( 0 , 2 );
elseif ( $filtertype == 'DBIT' ) $filterarray = array ( 1 , 2 );
2009-10-20 15:14:44 +02:00
elseif ( $filtertype != '' && $filtertype != '-1' ) $filterarray = explode ( ',' , $filtertype );
2008-10-01 23:16:35 +02:00
$this -> load_cache_types_paiements ();
print '<select class="flat" name="' . $htmlname . '">' ;
if ( $empty ) print '<option value=""> </option>' ;
foreach ( $this -> cache_types_paiements as $id => $arraytypes )
{
2009-10-28 21:42:58 +01:00
// On passe si on a demande de filtrer sur des modes de paiments particuliers
2008-10-01 23:16:35 +02:00
if ( sizeof ( $filterarray ) && ! in_array ( $arraytypes [ 'type' ], $filterarray )) continue ;
if ( $format == 0 ) print '<option value="' . $id . '"' ;
if ( $format == 1 ) print '<option value="' . $arraytypes [ 'code' ] . '"' ;
if ( $format == 2 ) print '<option value="' . $arraytypes [ 'code' ] . '"' ;
// Si selected est text, on compare avec code, sinon avec id
2009-10-24 08:10:00 +02:00
if ( preg_match ( '/[a-z]/i' , $selected ) && $selected == $arraytypes [ 'code' ]) print ' selected="true"' ;
2008-10-01 23:16:35 +02:00
elseif ( $selected == $id ) print ' selected="true"' ;
print '>' ;
if ( $format == 0 ) $value = $arraytypes [ 'label' ];
if ( $format == 1 ) $value = $arraytypes [ 'code' ];
if ( $format == 2 ) $value = $arraytypes [ 'label' ];
print $value ? $value : ' ' ;
print '</option>' ;
}
print '</select>' ;
if ( $user -> admin && ! $noadmininfo ) print info_admin ( $langs -> trans ( " YouCanChangeValuesForThisListFromDictionnarySetup " ), 1 );
}
/**
* \brief Selection HT ou TTC
2009-06-08 13:03:37 +02:00
* \param selected Id pre - selectionne
2008-10-01 23:16:35 +02:00
* \param htmlname Nom de la zone select
*/
function select_PriceBaseType ( $selected = '' , $htmlname = 'price_base_type' )
{
global $langs ;
print '<select class="flat" name="' . $htmlname . '">' ;
$options = array (
'HT' => $langs -> trans ( " HT " ),
'TTC' => $langs -> trans ( " TTC " )
);
foreach ( $options as $id => $value )
{
if ( $selected == $id )
{
print '<option value="' . $id . '" selected="true">' . $value ;
}
else
{
print '<option value="' . $id . '">' . $value ;
}
print '</option>' ;
}
print '</select>' ;
}
/**
2009-06-08 13:03:37 +02:00
* \brief Retourne la liste deroulante des differents etats d ' une propal .
2008-10-01 23:16:35 +02:00
* Les valeurs de la liste sont les id de la table c_propalst
2009-06-08 13:03:37 +02:00
* \param selected etat pre - selectionne
2008-10-01 23:16:35 +02:00
*/
function select_propal_statut ( $selected = '' )
{
$sql = " SELECT id, code, label, active FROM " . MAIN_DB_PREFIX . " c_propalst " ;
$sql .= " WHERE active = 1 " ;
2009-02-20 23:53:15 +01:00
dol_syslog ( " Form::select_propal_statut sql= " . $sql );
2008-10-01 23:16:35 +02:00
if ( $this -> db -> query ( $sql ))
{
print '<select class="flat" name="propal_statut">' ;
print '<option value=""> </option>' ;
$num = $this -> db -> num_rows ();
$i = 0 ;
if ( $num )
{
while ( $i < $num )
{
$obj = $this -> db -> fetch_object ();
if ( $selected == $obj -> id )
{
print '<option value="' . $obj -> id . '" selected="true">' ;
}
else
{
print '<option value="' . $obj -> id . '">' ;
}
print $obj -> label ;
print '</option>' ;
$i ++ ;
}
}
print '</select>' ;
}
else
{
2009-02-20 23:53:15 +01:00
dol_print_error ( $this -> db );
2008-10-01 23:16:35 +02:00
}
}
/**
* \brief Retourne la liste des comptes
2009-06-08 13:03:37 +02:00
* \param selected Id compte pre - selectionne
2008-10-01 23:16:35 +02:00
* \param htmlname Nom de la zone select
2009-06-08 13:03:37 +02:00
* \param statut Statut des comptes recherches ( 0 = open , 1 = closed )
2008-10-01 23:16:35 +02:00
* \param filtre Pour filtre sur la liste
* \param useempty Affiche valeur vide dans liste
*/
function select_comptes ( $selected = '' , $htmlname = 'accountid' , $statut = 0 , $filtre = '' , $useempty = 0 )
{
2009-04-27 22:37:50 +02:00
global $langs , $conf ;
2009-05-04 20:38:01 +02:00
2009-04-27 22:37:50 +02:00
$langs -> load ( " admin " );
2008-10-01 23:16:35 +02:00
$sql = " SELECT rowid, label, bank " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " bank_account " ;
$sql .= " WHERE clos = ' " . $statut . " ' " ;
2009-04-27 22:37:50 +02:00
$sql .= " AND entity = " . $conf -> entity ;
2008-10-01 23:16:35 +02:00
if ( $filtre ) $sql .= " AND " . $filtre ;
$sql .= " ORDER BY rowid " ;
2009-02-20 23:53:15 +01:00
dol_syslog ( " Form::select_comptes sql= " . $sql );
2008-10-01 23:16:35 +02:00
$result = $this -> db -> query ( $sql );
if ( $result )
{
$num = $this -> db -> num_rows ( $result );
$i = 0 ;
2009-04-27 22:37:50 +02:00
if ( $num )
2008-10-01 23:16:35 +02:00
{
2009-04-27 22:37:50 +02:00
print '<select class="flat" name="' . $htmlname . '">' ;
if ( $useempty )
2008-10-01 23:16:35 +02:00
{
2009-04-27 22:37:50 +02:00
print '<option value="' . $obj -> rowid . '"> </option>' ;
2008-10-01 23:16:35 +02:00
}
2009-05-04 20:38:01 +02:00
2009-04-27 22:37:50 +02:00
while ( $i < $num )
2008-10-01 23:16:35 +02:00
{
2009-04-27 22:37:50 +02:00
$obj = $this -> db -> fetch_object ( $result );
if ( $selected == $obj -> rowid )
{
print '<option value="' . $obj -> rowid . '" selected="true">' ;
}
else
{
print '<option value="' . $obj -> rowid . '">' ;
}
print $obj -> label ;
print '</option>' ;
$i ++ ;
2008-10-01 23:16:35 +02:00
}
2009-04-27 22:37:50 +02:00
print " </select> " ;
}
else
{
print $langs -> trans ( " NoActiveBankAccountDefined " );
2008-10-01 23:16:35 +02:00
}
}
else {
2009-02-20 23:53:15 +01:00
dol_print_error ( $this -> db );
2008-10-01 23:16:35 +02:00
}
}
2009-01-18 18:07:27 +01:00
2008-10-01 23:16:35 +02:00
/**
2009-06-08 13:03:37 +02:00
* \brief Retourne la liste des categories du type choisi
2008-10-01 23:16:35 +02:00
* \param type Type de categories ( 0 = produit , 1 = fournisseur , 2 = client )
* \param selected Id categorie preselectionnee
* \param select_name Nom formulaire HTML
*/
2009-07-30 01:45:33 +02:00
function select_all_categories ( $type , $selected = '' , $select_name = " " , $maxlength = 64 )
2008-10-01 23:16:35 +02:00
{
global $langs ;
2008-12-05 12:51:16 +01:00
$langs -> load ( " categories " );
2008-10-01 23:16:35 +02:00
if ( $select_name == " " ) $select_name = " catMere " ;
$cat = new Categorie ( $this -> db );
$cate_arbo = $cat -> get_full_arbo ( $type );
$output = '<select class="flat" name="' . $select_name . '">' ;
if ( is_array ( $cate_arbo ))
{
if ( ! sizeof ( $cate_arbo )) $output .= '<option value="-1" disabled="true">' . $langs -> trans ( " NoCategoriesDefined " ) . '</option>' ;
else
{
$output .= '<option value="-1"> </option>' ;
foreach ( $cate_arbo as $key => $value )
{
if ( $cate_arbo [ $key ][ 'id' ] == $selected )
{
$add = 'selected="true" ' ;
}
else
{
$add = '' ;
}
2009-07-30 01:45:33 +02:00
$output .= '<option ' . $add . 'value="' . $cate_arbo [ $key ][ 'id' ] . '">' . dol_trunc ( $cate_arbo [ $key ][ 'fulllabel' ], $maxlength , 'middle' ) . '</option>' ;
2008-10-01 23:16:35 +02:00
}
}
}
$output .= '</select>' ;
$output .= " \n " ;
return $output ;
}
/**
2009-05-06 15:39:43 +02:00
* \brief Show a confirmation HTML form or AJAX popup
* \param page page Url of page to call if confirmation is OK
2008-11-10 15:20:02 +01:00
* \param title title
* \param question question
* \param action action
* \param formquestion an array with forms complementary inputs
* \param selectedchoice " " or " no " or " yes "
2009-05-06 17:45:50 +02:00
* \param useajax 0 = No , 1 = Yes , 2 = Yes but submit page with & confirm = no if choice is No
2009-05-06 15:39:43 +02:00
* \param string 'ajax' if a confirm ajax popup is shown , 'html' if it ' s an html form
2008-10-01 23:16:35 +02:00
*/
2009-05-06 17:45:50 +02:00
function form_confirm ( $page , $title , $question , $action , $formquestion = '' , $selectedchoice = " " , $useajax = 0 )
2008-10-01 23:16:35 +02:00
{
2009-05-06 15:39:43 +02:00
global $langs , $conf ;
2008-10-01 23:16:35 +02:00
2009-05-06 17:45:50 +02:00
$more = '' ;
if ( $formquestion )
{
2009-12-10 12:01:16 +01:00
$more .= '<tr class="valid"><td class="valid" colspan="3">' . " \n " ;
$more .= '<table class="nobordernopadding" width="100%">' . " \n " ;
$more .= '<tr><td colspan="3" valign="top">' . $formquestion [ 'text' ] . '</td></tr>' . " \n " ;
2009-05-06 17:45:50 +02:00
foreach ( $formquestion as $key => $input )
{
if ( $input [ 'type' ] == 'text' )
{
2009-12-10 12:01:16 +01:00
$more .= '<tr><td valign="top">' . $input [ 'label' ] . '</td><td valign="top" colspan="2" align="left"><input type="text" class="flat" name="' . $input [ 'name' ] . '" size="' . $input [ 'size' ] . '" value="' . $input [ 'value' ] . '"></td></tr>' . " \n " ;
2009-05-06 17:45:50 +02:00
}
if ( $input [ 'type' ] == 'select' )
{
$more .= '<tr><td valign="top">' ;
2009-05-06 20:07:34 +02:00
$more .= $this -> selectarray ( $input [ 'name' ], $input [ 'values' ], '' , 1 );
2009-12-10 12:01:16 +01:00
$more .= '</td></tr>' . " \n " ;
2009-05-06 17:45:50 +02:00
}
if ( $input [ 'type' ] == 'checkbox' )
{
$more .= '<tr>' ;
2009-12-10 12:01:16 +01:00
//$more.='<td valign="top">'.$input['label'].' ';
$more .= '<td valign="top">' . $input [ 'label' ] . ' </td><td valign="top" align="left">' ;
2009-05-06 17:45:50 +02:00
$more .= '<input type="checkbox" class="flat" name="' . $input [ 'name' ] . '"' ;
2009-10-08 23:49:55 +02:00
if ( ! is_bool ( $input [ 'value' ]) && $input [ 'value' ] != 'false' ) $more .= ' checked="true"' ;
if ( is_bool ( $input [ 'value' ]) && $input [ 'value' ]) $more .= ' checked="true"' ;
2009-05-06 17:45:50 +02:00
if ( $input [ 'disabled' ]) $more .= ' disabled="true"' ;
2009-12-10 12:01:16 +01:00
$more .= '>' ;
$more .= '</td>' ;
//$more.='<td valign="top" align="left"> </td>';
2009-05-06 17:45:50 +02:00
$more .= '<td valign="top" align="left"> </td>' ;
2009-12-10 12:01:16 +01:00
$more .= '</tr>' . " \n " ;
2009-05-06 17:45:50 +02:00
}
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" name="' . $input [ 'name' ] . '" value="' . $selkey . '"' ;
if ( $input [ 'disabled' ]) $more .= ' disabled="true"' ;
$more .= '></td>' ;
$more .= '<td valign="top" align="left">' ;
$more .= $selval ;
2009-12-10 12:01:16 +01:00
$more .= '</td></tr>' . " \n " ;
2009-05-06 17:45:50 +02:00
$i ++ ;
}
}
}
2009-12-10 12:01:16 +01:00
$more .= '</table>' . " \n " ;
$more .= '</td></tr>' . " \n " ;
2009-05-06 17:45:50 +02:00
}
2008-12-17 19:34:47 +01:00
print " \n <!-- begin form_confirm --> \n " ;
2008-10-01 23:16:35 +02:00
2009-05-06 17:45:50 +02:00
if ( $useajax && $conf -> use_javascript_ajax && $conf -> global -> MAIN_CONFIRM_AJAX )
2009-05-06 15:39:43 +02:00
{
$pageyes = $page . '&action=' . $action . '&confirm=yes' ;
2009-05-06 17:45:50 +02:00
$pageno = ( $useajax == 2 ? $page . '&confirm=no' : '' );
// Note: Title is not used by dialogConfirm function
2009-05-08 21:27:39 +02:00
print '<script type="text/javascript">window.onload = function(){ dialogConfirm(\'' . $title . '\',\'' . $pageyes . '\',\'' . $pageno . '\',\'' . dol_escape_js ( '<b>' . $title . '</b><br>' . $more . $question ) . '\',\'' . $langs -> trans ( " Yes " ) . '\',\'' . $langs -> trans ( " No " ) . '\',\'validate\'); }</script>' ;
// print '<script id="eee" type="text/javascript">dialogConfirm(\'aaa\',\'bbb\',\'ccc\',\'eee\',\'yyy\',\'zzz\',\'validate\')</script>';
2009-05-06 15:39:43 +02:00
print " \n " ;
$ret = 'ajax' ;
}
else
{
2009-12-10 12:01:16 +01:00
print '<form method="post" action="' . $page . '" class="notoptoleftroright">' . " \n " ;
2009-05-06 15:39:43 +02:00
print '<input type="hidden" name="action" value="' . $action . '">' ;
2009-12-10 12:01:16 +01:00
print '<input type="hidden" name="token" value="' . $_SESSION [ 'newtoken' ] . '">' . " \n " ;
2009-05-06 15:39:43 +02:00
2009-12-10 12:01:16 +01:00
print '<table width="100%" class="valid">' . " \n " ;
2008-10-01 23:16:35 +02:00
2009-05-06 15:39:43 +02:00
// Ligne titre
2009-12-10 12:01:16 +01:00
print '<tr class="validtitre"><td class="validtitre" colspan="3">' . img_picto ( '' , 'recent' ) . ' ' . $title . '</td></tr>' . " \n " ;
2008-10-01 23:16:35 +02:00
2009-05-06 15:39:43 +02:00
// Ligne formulaire
2009-05-06 17:45:50 +02:00
print $more ;
2008-10-01 23:16:35 +02:00
2009-05-06 15:39:43 +02:00
// Ligne message
print '<tr class="valid">' ;
print '<td class="valid">' . $question . '</td>' ;
print '<td class="valid">' ;
$newselectedchoice = empty ( $selectedchoice ) ? " no " : $selectedchoice ;
print $this -> selectyesno ( " confirm " , $newselectedchoice );
print '</td>' ;
print '<td class="valid" align="center"><input class="button" type="submit" value="' . $langs -> trans ( " Validate " ) . '"></td>' ;
2009-12-10 12:01:16 +01:00
print '</tr>' . " \n " ;
2008-10-01 23:16:35 +02:00
2009-12-10 12:01:16 +01:00
print '</table>' . " \n " ;
2008-10-01 23:16:35 +02:00
2009-05-06 15:39:43 +02:00
if ( is_array ( $formquestion ))
2008-10-01 23:16:35 +02:00
{
2009-05-06 15:39:43 +02:00
foreach ( $formquestion as $key => $input )
{
if ( $input [ 'type' ] == 'hidden' ) print '<input type="hidden" name="' . $input [ 'name' ] . '" value="' . $input [ 'value' ] . '">' ;
}
2008-10-01 23:16:35 +02:00
}
2009-05-06 15:39:43 +02:00
print " </form> \n " ;
$ret = 'html' ;
}
2008-12-17 19:34:47 +01:00
2009-05-06 15:39:43 +02:00
print " <!-- end form_confirm --> \n " ;
return $ret ;
2008-10-01 23:16:35 +02:00
}
/**
* \brief Affiche formulaire de selection de projet
* \param page Page
* \param socid Id societe
2009-06-08 13:03:37 +02:00
* \param selected Id projet pre - selectionne
2008-10-01 23:16:35 +02:00
* \param htmlname Nom du formulaire select
*/
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">' ;
2009-05-17 10:01:54 +02:00
print '<input type="hidden" name="token" value="' . $_SESSION [ 'newtoken' ] . '">' ;
2009-07-08 12:10:35 +02:00
print '<table class="nobordernopadding" cellpadding="0" cellspacing="0">' ;
2008-10-01 23:16:35 +02:00
print '<tr><td>' ;
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 );
2009-01-23 18:18:19 +01:00
//print '<a href="'.DOL_URL_ROOT.'/projet/fiche.php?id='.$selected.'">'.$projet->title.'</a>';
2009-02-18 16:00:34 +01:00
print $projet -> getNomUrl ( 0 );
2008-10-01 23:16:35 +02:00
} else {
print " " ;
}
}
}
/**
* \brief Affiche formulaire de selection de conditions de paiement
* \param page Page
2009-06-08 13:03:37 +02:00
* \param selected Id condition pre - selectionne
2008-11-20 22:30:23 +01:00
* \param htmlname Name of select html field
2009-06-08 13:03:37 +02:00
* \param addempty Ajoute entree vide
2008-10-01 23:16:35 +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">' ;
2009-05-17 10:01:54 +02:00
print '<input type="hidden" name="token" value="' . $_SESSION [ 'newtoken' ] . '">' ;
2009-07-08 12:10:35 +02:00
print '<table class="nobordernopadding" cellpadding="0" cellspacing="0">' ;
2008-10-01 23:16:35 +02:00
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 " " ;
}
}
}
2008-11-20 22:30:23 +01:00
/**
* \brief Affiche formulaire de selection d ' une date
* \param page Page
* \param selected Date preselected
* \param htmlname Name of input html field
*/
function form_date ( $page , $selected = '' , $htmlname )
{
global $langs ;
2009-01-18 18:07:27 +01:00
2008-11-20 22:30:23 +01:00
if ( $htmlname != " none " )
{
print '<form method="post" action="' . $page . '" name="form' . $htmlname . '">' ;
print '<input type="hidden" name="action" value="set' . $htmlname . '">' ;
2009-05-17 10:01:54 +02:00
print '<input type="hidden" name="token" value="' . $_SESSION [ 'newtoken' ] . '">' ;
2009-07-08 12:10:35 +02:00
print '<table class="nobordernopadding" cellpadding="0" cellspacing="0">' ;
2008-11-20 22:30:23 +01:00
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 " " ;
}
}
}
2009-01-18 18:07:27 +01:00
2008-11-20 22:30:23 +01:00
2009-07-18 18:17:56 +02:00
/**
2009-07-27 02:08:49 +02:00
* \brief Affiche formulaire de selection d ' un utilisateur
* \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
2009-07-18 18:17:56 +02:00
*/
2009-07-27 02:08:49 +02:00
function form_users ( $page , $selected = '' , $htmlname = 'userid' , $exclude = '' , $include = '' )
2009-07-18 18:17:56 +02:00
{
global $langs ;
if ( $htmlname != " none " )
{
print '<form method="post" action="' . $page . '" name="form' . $htmlname . '">' ;
print '<input type="hidden" name="action" value="set' . $htmlname . '">' ;
print '<input type="hidden" name="token" value="' . $_SESSION [ 'newtoken' ] . '">' ;
print '<table class="nobordernopadding" cellpadding="0" cellspacing="0">' ;
print '<tr><td>' ;
2009-07-27 02:08:49 +02:00
print $this -> select_users ( $selected , $htmlname , 1 , $exclude , 0 , $include );
2009-07-18 18:17:56 +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 )
{
2010-03-23 22:17:18 +01:00
require_once ( DOL_DOCUMENT_ROOT . " /user/user.class.php " );
2009-07-18 18:17:56 +02:00
//$this->load_cache_contacts();
//print $this->cache_contacts[$selected];
$theuser = new User ( $this -> db );
$theuser -> id = $selected ;
$theuser -> fetch ();
print $theuser -> getNomUrl ( 1 );
} else {
print " " ;
}
}
}
2008-10-01 23:16:35 +02:00
/**
* \brief Affiche formulaire de selection des modes de reglement
* \param page Page
2009-06-08 13:03:37 +02:00
* \param selected Id mode pre - selectionne
2008-11-20 22:30:23 +01:00
* \param htmlname Name of select html field
2008-10-01 23:16:35 +02:00
*/
function form_modes_reglement ( $page , $selected = '' , $htmlname = 'mode_reglement_id' )
{
global $langs ;
if ( $htmlname != " none " )
{
print '<form method="post" action="' . $page . '">' ;
print '<input type="hidden" name="action" value="setmode">' ;
2009-05-17 10:01:54 +02:00
print '<input type="hidden" name="token" value="' . $_SESSION [ 'newtoken' ] . '">' ;
2009-07-08 12:10:35 +02:00
print '<table class="nobordernopadding" cellpadding="0" cellspacing="0">' ;
2008-10-01 23:16:35 +02:00
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 " " ;
}
}
}
/**
* \brief Affiche formulaire de selection de la remise fixe
* \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
*/
function form_remise_dispo ( $page , $selected = '' , $htmlname = 'remise_id' , $socid , $amount , $filter = '' , $maxvalue = 0 )
{
global $conf , $langs ;
if ( $htmlname != " none " )
{
print '<form method="post" action="' . $page . '">' ;
print '<input type="hidden" name="action" value="setabsolutediscount">' ;
2009-05-17 10:01:54 +02:00
print '<input type="hidden" name="token" value="' . $_SESSION [ 'newtoken' ] . '">' ;
2008-10-01 23:16:35 +02:00
print '<table class="nobordernopadding" cellpadding="0" cellspacing="0">' ;
print '<tr><td>' ;
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>' ;
print '<td align="left">' ;
if ( $nbqualifiedlines > 0 )
{
2009-03-02 19:17:19 +01:00
print ' <input type="submit" class="button" value="' ;
2008-10-01 23:16:35 +02:00
if ( ! $filter || $filter == 'fk_facture_source IS NULL' ) print $langs -> trans ( " UseDiscount " );
2009-03-02 19:17:19 +01:00
else print $langs -> trans ( " UseCredit " );
print '" title="' . $langs -> trans ( " UseCreditNoteInInvoicePayment " ) . '">' ;
2008-10-01 23:16:35 +02:00
}
print '</td>' ;
print '</tr></table></form>' ;
}
else
{
if ( $selected )
{
print $selected ;
}
else
{
print " 0 " ;
}
}
}
/**
* \brief Affiche formulaire de selection des contacts
* \param page Page
2009-06-08 13:03:37 +02:00
* \param selected Id contact pre - selectionne
2008-10-01 23:16:35 +02:00
* \param htmlname Nom du formulaire select
*/
function form_contacts ( $page , $societe , $selected = '' , $htmlname = 'contactidp' )
{
global $langs ;
if ( $htmlname != " none " )
{
print '<form method="post" action="' . $page . '">' ;
print '<input type="hidden" name="action" value="set_contact">' ;
2009-05-17 10:01:54 +02:00
print '<input type="hidden" name="token" value="' . $_SESSION [ 'newtoken' ] . '">' ;
2009-07-08 12:10:35 +02:00
print '<table class="nobordernopadding" cellpadding="0" cellspacing="0">' ;
2008-10-01 23:16:35 +02:00
print '<tr><td>' ;
$num = $this -> select_contacts ( $societe -> id , $selected , $htmlname );
if ( $num == 0 )
{
2009-06-08 13:03:37 +02:00
print '<font class="error">Cette societe n\'a pas de contact, veuillez en cr<63> er un avant de faire votre proposition commerciale</font><br>' ;
2008-10-01 23:16:35 +02:00
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 )
{
2010-03-25 14:51:24 +01:00
require_once ( DOL_DOCUMENT_ROOT . " /contact/contact.class.php " );
2008-10-01 23:16:35 +02:00
//$this->load_cache_contacts();
//print $this->cache_contacts[$selected];
$contact = new Contact ( $this -> db );
$contact -> fetch ( $selected );
print $contact -> nom . ' ' . $contact -> prenom ;
} else {
print " " ;
}
}
}
/**
* \brief Affiche formulaire de selection de l ' adresse de livraison
* \param page Page
2009-06-08 13:03:37 +02:00
* \param selected Id condition pre - selectionne
2008-10-01 23:16:35 +02:00
* \param htmlname Nom du formulaire select
2009-06-08 13:03:37 +02:00
* \param origin Origine de l ' appel pour pouvoir creer un retour
2008-10-01 23:16:35 +02:00
* \param originid Id de l ' origine
*/
function form_adresse_livraison ( $page , $selected = '' , $socid , $htmlname = 'adresse_livraison_id' , $origin = '' , $originid = '' )
{
global $langs , $conf ;
if ( $htmlname != " none " )
{
print '<form method="post" action="' . $page . '">' ;
print '<input type="hidden" name="action" value="setdeliveryadress">' ;
2009-05-17 10:01:54 +02:00
print '<input type="hidden" name="token" value="' . $_SESSION [ 'newtoken' ] . '">' ;
2009-07-08 12:10:35 +02:00
print '<table class="nobordernopadding" cellpadding="0" cellspacing="0">' ;
2008-10-01 23:16:35 +02:00
print '<tr><td>' ;
$this -> select_adresse_livraison ( $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/adresse_livraison.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 . " /comm/adresse_livraison.class.php " );
$livraison = new AdresseLivraison ( $this -> db );
2009-07-21 13:37:40 +02:00
$result = $livraison -> fetch_adresse ( $selected );
2009-07-08 14:02:36 +02:00
print '<a href=' . DOL_URL_ROOT . '/comm/adresse_livraison.php?socid=' . $livraison -> socid . '&id=' . $livraison -> id . '&action=edit&origin=' . $origin . '&originid=' . $originid . '>' . $livraison -> label . '</a>' ;
2008-10-01 23:16:35 +02:00
}
else
{
print " " ;
}
}
}
/**
* \brief Retourne la liste des devises , dans la langue de l ' utilisateur
2009-06-18 10:43:16 +02:00
* \param selected code devise pre - selectionne
2008-10-01 23:16:35 +02:00
* \param htmlname nom de la liste deroulante
2009-06-18 10:43:16 +02:00
* \todo trier liste sur noms apres traduction plutot que avant
2008-10-01 23:16:35 +02:00
*/
function select_currency ( $selected = '' , $htmlname = 'currency_id' )
{
global $conf , $langs , $user ;
$langs -> load ( " dict " );
2009-06-18 10:43:16 +02:00
if ( $selected == 'euro' || $selected == 'euros' ) $selected = 'EUR' ; // Pour compatibilite
2008-10-01 23:16:35 +02:00
$sql = " SELECT code, code_iso, label, active " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " c_currencies " ;
$sql .= " WHERE active = 1 " ;
$sql .= " ORDER BY code_iso ASC " ;
$resql = $this -> db -> query ( $sql );
if ( $resql )
{
print '<select class="flat" name="' . $htmlname . '">' ;
$num = $this -> db -> num_rows ( $resql );
$i = 0 ;
if ( $num )
{
$foundselected = false ;
while ( $i < $num )
{
$obj = $this -> db -> fetch_object ( $resql );
if ( $selected && $selected == $obj -> code_iso )
{
$foundselected = true ;
print '<option value="' . $obj -> code_iso . '" selected="true">' ;
}
else
{
print '<option value="' . $obj -> code_iso . '">' ;
}
if ( $obj -> code_iso ) { print $obj -> code_iso . ' - ' ; }
2009-06-18 10:43:16 +02:00
// Si traduction existe, on l'utilise, sinon on prend le libelle par defaut
2008-10-01 23:16:35 +02:00
print ( $obj -> code_iso && $langs -> trans ( " Currency " . $obj -> code_iso ) != " Currency " . $obj -> code_iso ? $langs -> trans ( " Currency " . $obj -> code_iso ) : ( $obj -> label != '-' ? $obj -> label : '' ));
print '</option>' ;
$i ++ ;
}
}
print '</select>' ;
if ( $user -> admin ) print info_admin ( $langs -> trans ( " YouCanChangeValuesForThisListFromDictionnarySetup " ), 1 );
return 0 ;
}
else {
2009-02-20 23:53:15 +01:00
dol_print_error ( $this -> db );
2008-10-01 23:16:35 +02:00
return 1 ;
}
}
/**
2008-10-25 19:27:15 +02:00
* \brief Output an HTML select vat rate
2008-10-01 23:16:35 +02:00
* \param name Nom champ html
2009-06-18 10:43:16 +02:00
* \param selectedrate Forcage du taux tva pre - selectionne . Mettre '' pour aucun forcage .
* \param societe_vendeuse Objet societe vendeuse
* \param societe_acheteuse Objet societe acheteuse
2008-10-01 23:16:35 +02:00
* \param taux_produit Taux par defaut du produit vendu
* \param info_bits Miscellanous information on line
2009-06-18 10:43:16 +02:00
* \remarks Si vendeur non assujeti a TVA , TVA par defaut = 0. Fin de regle .
* Si le ( pays vendeur = pays acheteur ) alors la TVA par defaut = TVA du produit vendu . Fin de regle .
* Si ( vendeur et acheteur dans Communaute europeenne ) et bien vendu = moyen de transports neuf ( auto , bateau , avion ), TVA par defaut = 0 ( La TVA doit etre paye par l 'acheteur au centre d' impots de son pays et non au vendeur ) . Fin de regle .
* Si ( vendeur et acheteur dans 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 .
2008-10-01 23:16:35 +02:00
*/
function select_tva ( $name = 'tauxtva' , $selectedrate = '' , $societe_vendeuse = '' , $societe_acheteuse = '' , $taux_produit = '' , $info_bits = 0 )
{
global $langs , $conf , $mysoc ;
$txtva = array ();
$libtva = array ();
$nprtva = array ();
// Define defaultnpr and defaultttx
$defaultnpr = ( $info_bits & 0x01 );
2009-10-21 16:02:14 +02:00
$defaultnpr = ( preg_match ( '/\*/' , $selectedrate ) ? 1 : $defaultnpr );
$defaulttx = str_replace ( '*' , '' , $selectedrate );
2008-10-01 23:16:35 +02:00
//print $societe_vendeuse."-".$societe_acheteuse;
if ( is_object ( $societe_vendeuse ) && ! $societe_vendeuse -> pays_code )
{
if ( $societe_vendeuse -> id == $mysoc -> id )
{
print '<font class="error">' . $langs -> trans ( " ErrorYourCountryIsNotDefined " ) . '</div>' ;
}
else
{
print '<font class="error">' . $langs -> trans ( " ErrorSupplierCountryIsNotDefined " ) . '</div>' ;
}
return ;
}
if ( is_object ( $societe_vendeuse ))
{
2010-02-10 15:04:44 +01:00
if ( $societe_vendeuse -> isInEEC () && ( ! empty ( $societe_vendeuse -> tva_intra ))
&& preg_match ( '/^([A-Z][A-Z])/' , $societe_vendeuse -> tva_intra , $reg ))
{
$code_pays = $reg [ 1 ];
}
else
{
$code_pays = $societe_vendeuse -> pays_code ;
}
2008-10-01 23:16:35 +02:00
}
else
{
$code_pays = $mysoc -> pays_code ; // Pour compatibilite ascendente
}
// Recherche liste des codes TVA du pays vendeur
$sql = " SELECT 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 AND p.code = ' " . $code_pays . " ' " ;
$sql .= " AND t.active = 1 " ;
$sql .= " ORDER BY t.taux ASC, t.recuperableonly ASC " ;
$resql = $this -> db -> query ( $sql );
if ( $resql )
{
$num = $this -> db -> num_rows ( $resql );
if ( $num )
2007-01-30 02:20:16 +01:00
{
2007-07-13 01:24:47 +02:00
for ( $i = 0 ; $i < $num ; $i ++ )
{
$obj = $this -> db -> fetch_object ( $resql );
2008-02-22 00:15:55 +01:00
$txtva [ $i ] = $obj -> taux ;
$libtva [ $i ] = $obj -> taux . '%' ;
$nprtva [ $i ] = $obj -> recuperableonly ;
2007-07-13 01:24:47 +02:00
}
}
else
{
print '<font class="error">' . $langs -> trans ( " ErrorNoVATRateDefinedForSellerCountry " , $code_pays ) . '</font>' ;
2007-01-30 02:20:16 +01:00
}
}
else
{
2007-07-13 01:24:47 +02:00
print '<font class="error">' . $this -> db -> error () . '</font>' ;
2008-10-01 23:16:35 +02:00
}
2009-06-18 10:43:16 +02:00
// Definition du taux a pre-selectionner (si defaulttx non force et donc vaut -1 ou '')
2007-10-29 12:20:50 +01:00
if ( $defaulttx < 0 || strlen ( $defaulttx ) == 0 )
{
$defaulttx = get_default_tva ( $societe_vendeuse , $societe_acheteuse , $taux_produit );
2008-02-22 00:15:55 +01:00
$defaultnpr = get_default_npr ( $societe_vendeuse , $societe_acheteuse , $taux_produit );
2007-10-29 12:20:50 +01:00
}
2009-06-18 10:43:16 +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
2007-10-29 12:20:50 +01:00
if ( $defaulttx < 0 || strlen ( $defaulttx ) == 0 )
{
$defaulttx = $txtva [ sizeof ( $txtva ) - 1 ];
}
2008-10-01 23:16:35 +02:00
2007-01-30 02:20:16 +01:00
$nbdetaux = sizeof ( $txtva );
2008-10-01 23:16:35 +02:00
2007-07-13 01:24:47 +02:00
if ( sizeof ( $txtva ))
2007-01-30 02:20:16 +01:00
{
2007-07-13 01:24:47 +02:00
print '<select class="flat" name="' . $name . '">' ;
2009-01-18 18:07:27 +01:00
2007-07-13 01:24:47 +02:00
for ( $i = 0 ; $i < $nbdetaux ; $i ++ )
2007-01-30 02:20:16 +01:00
{
2008-02-22 00:15:55 +01:00
//print "xxxxx".$txtva[$i]."-".$nprtva[$i];
print '<option value="' . $txtva [ $i ];
print $nprtva [ $i ] ? '*' : '' ;
print '"' ;
if ( $txtva [ $i ] == $defaulttx && $nprtva [ $i ] == $defaultnpr )
2007-07-13 01:24:47 +02:00
{
print ' selected="true"' ;
}
2008-02-22 00:15:55 +01:00
print '>' . vatrate ( $libtva [ $i ]);
print $nprtva [ $i ] ? ' *' : '' ;
print '</option>' ;
2008-10-01 23:16:35 +02:00
2007-07-13 01:24:47 +02:00
$this -> tva_taux_value [ $i ] = $txtva [ $i ];
$this -> tva_taux_libelle [ $i ] = $libtva [ $i ];
2008-02-22 00:15:55 +01:00
$this -> tva_taux_npr [ $i ] = $nprtva [ $i ];
2007-01-30 02:20:16 +01:00
}
2007-07-13 01:24:47 +02:00
print '</select>' ;
2007-01-30 02:20:16 +01:00
}
2006-12-09 19:09:02 +01:00
}
2006-12-12 17:53:34 +01:00
2008-10-01 23:16:35 +02:00
/**
2008-10-02 00:24:31 +02:00
* Affiche zone de selection de date
* Liste deroulante pour les jours , mois , annee et eventuellement heurs et minutes
2009-06-18 10:43:16 +02:00
* Les champs sont pre - selectionnes avec :
2010-02-03 03:22:15 +01:00
* - La date set_time ( Local PHP server timestamps ou date au format YYYY - MM - DD ou YYYY - MM - DD HH : MM )
* - La date local du server PHP si set_time vaut ''
2008-10-01 23:16:35 +02:00
* - Aucune date ( champs vides ) si set_time vaut - 1 ( dans ce cas empty doit valoir 1 )
2010-02-03 03:22:15 +01:00
* @ param set_time Pre - selected date ( must be a local PHP server timestamp )
2008-10-02 00:24:31 +02:00
* @ param prefix Prefix pour nom champ
* @ param h 1 = Affiche aussi les heures
* @ param m 1 = Affiche aussi les minutes
* @ param empty 0 = Champ obligatoire , 1 = Permet une saisie vide
2009-06-18 10:43:16 +02:00
* @ param form_name Nom du formulaire de provenance . Utilise pour les dates en popup .
2008-10-02 00:24:31 +02:00
* @ param d 1 = Affiche aussi les jours , mois , annees
2008-12-03 22:43:30 +01:00
* @ param addnowbutton Add a button " Now "
2010-01-12 00:25:54 +01:00
* @ param nooutput Do not output zone but return it
2010-01-12 10:22:05 +01:00
* @ return nothing or string if nooutput is 1
2008-10-01 23:16:35 +02:00
*/
2010-01-12 00:25:54 +01:00
function select_date ( $set_time = '' , $prefix = 're' , $h = 0 , $m = 0 , $empty = 0 , $form_name = " " , $d = 1 , $addnowbutton = 0 , $nooutput = 0 )
2008-10-01 23:16:35 +02:00
{
global $conf , $langs ;
2007-08-27 23:39:01 +02:00
2010-01-12 00:25:54 +01:00
$retstring = '' ;
2008-10-01 23:16:35 +02:00
if ( $prefix == '' ) $prefix = 're' ;
2006-03-02 09:39:40 +01:00
if ( $h == '' ) $h = 0 ;
if ( $m == '' ) $m = 0 ;
if ( $empty == '' ) $empty = 0 ;
2008-10-01 23:16:35 +02:00
if ( ! $set_time && $empty == 0 ) $set_time = time ();
2009-10-24 08:10:00 +02:00
// Analyse de la date de pre-selection
if ( preg_match ( '/^([0-9]+)\-([0-9]+)\-([0-9]+)\s?([0-9]+)?:?([0-9]+)?/' , $set_time , $reg ))
2008-10-01 23:16:35 +02:00
{
// Date au format 'YYYY-MM-DD' ou 'YYYY-MM-DD HH:MM:SS'
$syear = $reg [ 1 ];
$smonth = $reg [ 2 ];
$sday = $reg [ 3 ];
$shour = $reg [ 4 ];
$smin = $reg [ 5 ];
}
elseif ( strval ( $set_time ) != '' && $set_time != - 1 )
{
2010-02-03 00:57:05 +01:00
// set_time est un timestamps (0 possible)
2010-02-03 03:22:15 +01:00
$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 " );
2008-10-01 23:16:35 +02:00
}
else
{
// Date est '' ou vaut -1
$syear = '' ;
$smonth = '' ;
$sday = '' ;
$shour = '' ;
$smin = '' ;
}
if ( $d )
{
/*
* Affiche date en popup
*/
2008-01-06 16:24:23 +01:00
if ( $conf -> use_javascript_ajax && $conf -> use_popup_calendar )
2008-10-01 23:16:35 +02:00
{
2007-08-27 23:39:01 +02:00
//print "e".$set_time." t ".$conf->format_date_short;
2008-07-29 09:45:08 +02:00
if ( strval ( $set_time ) != '' && $set_time != - 1 )
2007-08-27 23:39:01 +02:00
{
2009-02-20 23:53:15 +01:00
$formated_date = dol_print_date ( $set_time , $conf -> format_date_short );
2007-01-05 21:42:44 +01:00
}
2008-10-01 23:16:35 +02:00
2007-01-05 21:42:44 +01:00
// Calendrier popup version eldy
if ( " $conf->use_popup_calendar " == " eldy " ) // Laisser conf->use_popup_calendar entre quote
{
2007-03-20 13:12:51 +01:00
// Zone de saisie manuelle de la date
2010-01-12 10:22:05 +01:00
$retstring .= '<input id="' . $prefix . '" name="' . $prefix . '" type="text" size="9" maxlength="11" value="' . $formated_date . '"' ;
2010-01-12 00:25:54 +01:00
$retstring .= ' onChange="dpChangeDay(\'' . $prefix . '\',\'' . $conf -> format_date_short_java . '\'); "' ;
$retstring .= '>' ;
2009-01-18 18:07:27 +01:00
2007-01-05 21:42:44 +01:00
// Icone calendrier
2010-01-12 00:25:54 +01:00
$retstring .= '<button id="' . $prefix . 'Button" type="button" class="dpInvisibleButtons"' ;
2007-03-20 13:12:51 +01:00
$base = DOL_URL_ROOT . '/lib/' ;
2010-01-12 00:25:54 +01:00
$retstring .= ' onClick="showDP(\'' . $base . '\',\'' . $prefix . '\',\'' . $conf -> format_date_short_java . '\');">' . img_object ( $langs -> trans ( " SelectDate " ), 'calendar' ) . '</button>' ;
2009-01-18 18:07:27 +01:00
2010-01-12 00:25:54 +01:00
$retstring .= '<input type="hidden" id="' . $prefix . 'day" name="' . $prefix . 'day" value="' . $sday . '">' . " \n " ;
$retstring .= '<input type="hidden" id="' . $prefix . 'month" name="' . $prefix . 'month" value="' . $smonth . '">' . " \n " ;
$retstring .= '<input type="hidden" id="' . $prefix . 'year" name="' . $prefix . 'year" value="' . $syear . '">' . " \n " ;
2006-03-12 00:03:05 +01:00
}
else
2008-10-01 23:16:35 +02:00
{
2007-01-05 21:42:44 +01:00
// Calendrier popup version defaut
if ( $langs -> defaultlang != " " )
2007-08-27 23:39:01 +02:00
{
2010-01-12 00:25:54 +01:00
$retstring .= '<script type="text/javascript">' ;
$retstring .= 'selectedLanguage = "' . substr ( $langs -> defaultlang , 0 , 2 ) . '"' ;
$retstring .= '</script>' ;
2007-01-05 21:42:44 +01:00
}
2010-01-12 00:25:54 +01:00
$retstring .= '<script type="text/javascript" src="' . DOL_URL_ROOT . '/lib/lib_calendar.js"></script>' ;
$retstring .= '<input id="' . $prefix . '" type="text" name="' . $prefix . '" size="9" value="' . $formated_date . '"' ;
$retstring .= ' onChange="dpChangeDay(\'' . $prefix . '\',\'' . $conf -> format_date_short_java . '\')"' ;
$retstring .= '> ' ;
$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 " ;
2008-11-16 02:09:04 +01:00
if ( $form_name == " " )
{
2010-01-12 00:25:54 +01:00
$retstring .= '<a href="javascript:showCalendar(document.forms[3].' . $prefix . ')">' ;
$retstring .= '<img style="vertical-align:middle" src="' . DOL_URL_ROOT . '/theme/' . $conf -> theme . '/img/calendar.png" border="0" alt="" title="">' ;
$retstring .= '</a>' ;
2008-11-16 02:09:04 +01:00
}
2007-01-05 21:42:44 +01:00
else
2008-11-16 02:09:04 +01:00
{
2010-01-12 00:25:54 +01:00
$retstring .= '<a href="javascript:showCalendar(document.forms[\'' . $form_name . '\'].' . $prefix . ')">' ;
$retstring .= '<img style="vertical-align:middle" src="' . DOL_URL_ROOT . '/theme/' . $conf -> theme . '/img/calendar.png" border="0" alt="" title="">' ;
$retstring .= '</a>' ;
2008-11-16 02:09:04 +01:00
}
2007-01-05 21:42:44 +01:00
}
2008-10-01 23:16:35 +02:00
}
2009-01-18 18:07:27 +01:00
2008-10-01 23:16:35 +02:00
/*
* Affiche date en select
*/
if ( ! $conf -> use_javascript_ajax || ! $conf -> use_popup_calendar )
{
// Jour
2010-01-12 00:25:54 +01:00
$retstring .= '<select class="flat" name="' . $prefix . 'day">' ;
2009-01-18 18:07:27 +01:00
2008-10-01 23:16:35 +02:00
if ( $empty || $set_time == - 1 )
{
2010-01-12 00:25:54 +01:00
$retstring .= '<option value="0" selected="true"> </option>' ;
2008-10-01 23:16:35 +02:00
}
for ( $day = 1 ; $day <= 31 ; $day ++ )
{
if ( $day == $sday )
{
2010-01-12 00:25:54 +01:00
$retstring .= " <option value= \" $day\ " selected = \ " true \" > $day " ;
2008-10-01 23:16:35 +02:00
}
else
{
2010-01-12 00:25:54 +01:00
$retstring .= " <option value= \" $day\ " > $day " ;
2008-10-01 23:16:35 +02:00
}
2010-01-12 00:25:54 +01:00
$retstring .= " </option> " ;
2008-10-01 23:16:35 +02:00
}
2009-01-18 18:07:27 +01:00
2010-01-12 00:25:54 +01:00
$retstring .= " </select> " ;
2009-01-18 18:07:27 +01:00
2010-01-12 00:25:54 +01:00
$retstring .= '<select class="flat" name="' . $prefix . 'month">' ;
2008-10-01 23:16:35 +02:00
if ( $empty || $set_time == - 1 )
{
2010-01-12 00:25:54 +01:00
$retstring .= '<option value="0" selected="true"> </option>' ;
2008-10-01 23:16:35 +02:00
}
2009-01-18 18:07:27 +01:00
2010-02-03 03:22:15 +01:00
// Month
2008-10-01 23:16:35 +02:00
for ( $month = 1 ; $month <= 12 ; $month ++ )
{
2010-01-12 00:25:54 +01:00
$retstring .= '<option value="' . $month . '"' . ( $month == $smonth ? ' selected="true"' : '' ) . '>' ;
2010-02-03 03:22:15 +01:00
$retstring .= dol_print_date ( mktime ( 12 , 0 , 0 , $month , 1 , 2000 ), " %b " );
2010-01-12 00:25:54 +01:00
$retstring .= " </option> " ;
2008-10-01 23:16:35 +02:00
}
2010-01-12 00:25:54 +01:00
$retstring .= " </select> " ;
2009-01-18 18:07:27 +01:00
2010-02-03 03:22:15 +01:00
// Year
2008-10-01 23:16:35 +02:00
if ( $empty || $set_time == - 1 )
{
2010-01-12 00:25:54 +01:00
$retstring .= '<input class="flat" type="text" size="3" maxlength="4" name="' . $prefix . 'year" value="' . $syear . '">' ;
2008-10-01 23:16:35 +02:00
}
else
{
2010-01-12 00:25:54 +01:00
$retstring .= '<select class="flat" name="' . $prefix . 'year">' ;
2009-01-18 18:07:27 +01:00
2008-10-01 23:16:35 +02:00
for ( $year = $syear - 5 ; $year < $syear + 10 ; $year ++ )
{
if ( $year == $syear )
{
2010-01-12 00:25:54 +01:00
$retstring .= " <option value= \" $year\ " selected = \ " true \" > " . $year ;
2008-10-01 23:16:35 +02:00
}
else
{
2010-01-12 00:25:54 +01:00
$retstring .= " <option value= \" $year\ " > " . $year ;
2008-10-01 23:16:35 +02:00
}
2010-01-12 00:25:54 +01:00
$retstring .= " </option> " ;
2008-10-01 23:16:35 +02:00
}
2010-01-12 00:25:54 +01:00
$retstring .= " </select> \n " ;
2008-10-01 23:16:35 +02:00
}
}
}
2010-01-12 00:25:54 +01:00
if ( $d && $h ) $retstring .= ' ' ;
2008-10-01 23:16:35 +02:00
if ( $h )
{
/*
* Affiche heure en select
*/
2010-01-12 00:25:54 +01:00
$retstring .= '<select class="flat" name="' . $prefix . 'hour">' ;
if ( $empty ) $retstring .= '<option value="-1"> </option>' ;
2008-10-01 23:16:35 +02:00
for ( $hour = 0 ; $hour < 24 ; $hour ++ )
{
if ( strlen ( $hour ) < 2 )
{
$hour = " 0 " . $hour ;
}
if ( $hour == $shour )
{
2010-01-12 00:25:54 +01:00
$retstring .= " <option value= \" $hour\ " selected = \ " true \" > $hour </option> " ;
2008-10-01 23:16:35 +02:00
}
else
{
2010-01-12 00:25:54 +01:00
$retstring .= " <option value= \" $hour\ " > $hour </ option > " ;
2008-10-01 23:16:35 +02:00
}
}
2010-01-12 00:25:54 +01:00
$retstring .= " </select> " ;
$retstring .= " H \n " ;
2008-10-01 23:16:35 +02:00
}
2009-01-18 18:07:27 +01:00
2008-10-01 23:16:35 +02:00
if ( $m )
{
/*
* Affiche min en select
*/
2010-01-12 00:25:54 +01:00
$retstring .= '<select class="flat" name="' . $prefix . 'min">' ;
if ( $empty ) $retstring .= '<option value="-1"> </option>' ;
2008-10-01 23:16:35 +02:00
for ( $min = 0 ; $min < 60 ; $min ++ )
{
if ( strlen ( $min ) < 2 )
{
$min = " 0 " . $min ;
}
if ( $min == $smin )
{
2010-01-12 00:25:54 +01:00
$retstring .= " <option value= \" $min\ " selected = \ " true \" > $min </option> " ;
2008-10-01 23:16:35 +02:00
}
else
{
2010-01-12 00:25:54 +01:00
$retstring .= " <option value= \" $min\ " > $min </ option > " ;
2008-10-01 23:16:35 +02:00
}
}
2010-01-12 00:25:54 +01:00
$retstring .= " </select> " ;
$retstring .= " M \n " ;
2008-10-01 23:16:35 +02:00
}
2008-12-03 22:43:30 +01:00
// Added by Matelli http://matelli.fr/showcases/patchs-dolibarr/update-date-input-in-action-form.html)
// "Now" button
if ( $conf -> use_javascript_ajax && $addnowbutton )
{
// Script which will be inserted in the OnClick of the "Now" button
$reset_scripts = " " ;
2009-01-18 18:07:27 +01:00
2008-12-03 22:43:30 +01:00
// Generate the date part, depending on the use or not of the javascript calendar
if ( $conf -> use_popup_calendar )
{
$base = DOL_URL_ROOT . '/lib/' ;
$reset_scripts .= 'resetDP(\'' . $base . '\',\'' . $prefix . '\',\'' . $conf -> format_date_short_java . '\');' ;
}
else
{
2009-08-09 21:25:17 +02:00
$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\'); ' ;
2008-12-03 22:43:30 +01:00
}
// Generate the hour part
if ( $h )
{
2009-08-09 21:25:17 +02:00
$reset_scripts .= 'this.form.elements[\'' . $prefix . 'hour\'].value=formatDate(new Date(), \'HH\'); ' ;
2008-12-03 22:43:30 +01:00
}
// Generate the minute part
if ( $m )
{
2009-08-09 21:25:17 +02:00
$reset_scripts .= 'this.form.elements[\'' . $prefix . 'min\'].value=formatDate(new Date(), \'mm\'); ' ;
2008-12-03 22:43:30 +01:00
}
// If reset_scripts is not empty, print the button with the reset_scripts in OnClick
if ( $reset_scripts )
2009-01-18 18:07:27 +01:00
{
2010-01-12 00:25:54 +01:00
$retstring .= '<button class="dpInvisibleButtons" id="' . $prefix . 'ButtonNow" type="button" name="_useless" value="Maintenant" onClick="' . $reset_scripts . '">' ;
$retstring .= $langs -> trans ( " Now " );
2008-12-03 22:43:30 +01:00
//print img_refresh($langs->trans("Now"));
2010-01-12 00:25:54 +01:00
$retstring .= '</button> ' ;
2008-12-03 22:43:30 +01:00
}
}
2009-01-18 18:07:27 +01:00
2010-01-12 00:25:54 +01:00
if ( ! empty ( $nooutput )) return $retstring ;
2010-01-12 10:22:05 +01:00
print $retstring ;
2010-01-12 00:25:54 +01:00
return ;
2008-10-01 23:16:35 +02:00
}
2006-09-10 15:46:25 +02:00
/**
2010-03-02 09:45:49 +01:00
* \brief Function to show a form to select a duration on a page
2008-12-03 22:43:30 +01:00
* \param prefix prefix
2010-03-02 09:45:49 +01:00
* \param iSecond Default preselected duration ( number of seconds )
* \param disabled Disable the combo box
2008-10-01 23:16:35 +02:00
*/
2010-03-02 09:45:49 +01:00
function select_duration ( $prefix , $iSecond = '' , $disabled = 0 )
2006-09-10 15:46:25 +02:00
{
2007-08-28 09:44:17 +02:00
if ( $iSecond )
{
2008-04-09 20:13:45 +02:00
require_once ( DOL_DOCUMENT_ROOT . " /lib/date.lib.php " );
2009-01-18 18:07:27 +01:00
2007-08-28 09:44:17 +02:00
$hourSelected = ConvertSecondToTime ( $iSecond , 'hour' );
$minSelected = ConvertSecondToTime ( $iSecond , 'min' );
}
2008-10-01 23:16:35 +02:00
2010-03-01 20:36:58 +01:00
print '<select class="flat" name="' . $prefix . 'hour"' . ( $disabled ? ' disabled="true"' : '' ) . '>' ;
2008-03-20 22:54:56 +01:00
for ( $hour = 0 ; $hour < 24 ; $hour ++ )
2006-09-10 15:46:25 +02:00
{
2007-08-28 09:44:17 +02:00
print '<option value="' . $hour . '"' ;
2010-03-02 09:45:49 +01:00
if ( $hourSelected == $hour )
2007-08-28 09:44:17 +02:00
{
print " selected= \" true \" " ;
2008-10-01 23:16:35 +02:00
}
2007-08-28 09:44:17 +02:00
print " > " . $hour . " </option> " ;
2006-09-10 15:46:25 +02:00
}
print " </select> " ;
print " H " ;
2010-03-01 20:36:58 +01:00
print '<select class="flat" name="' . $prefix . 'min"' . ( $disabled ? ' disabled="true"' : '' ) . '>' ;
2008-03-20 22:54:56 +01:00
for ( $min = 0 ; $min <= 55 ; $min = $min + 5 )
2006-09-10 15:46:25 +02:00
{
2007-08-28 09:44:17 +02:00
print '<option value="' . $min . '"' ;
if ( $minSelected == $min ) print ' selected="true"' ;
print '>' . $min . '</option>' ;
2006-09-10 15:46:25 +02:00
}
print " </select> " ;
print " M " ;
}
2008-10-01 23:16:35 +02:00
/**
2008-10-25 17:53:16 +02:00
* \brief Show a select form from an array
* \param htmlname Nom de la zone select
* \param array Tableau de key + valeur
* \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 "
2009-03-13 16:17:34 +01:00
* \param value_as_key 1 to use value as key
2008-10-25 17:53:16 +02:00
* \param optionType Type de l ' option : 1 pour des fonctions javascript
* \param option Valeur de l ' option en fonction du type choisi
* \param translate Traduire la valeur
2008-11-15 01:10:42 +01:00
* \param maxlen Length maximum for labels
2010-02-07 03:39:01 +01:00
* \return string HTML select string
2008-10-01 23:16:35 +02:00
*/
2009-05-06 20:07:34 +02:00
function selectarray ( $htmlname , $array , $id = '' , $show_empty = 0 , $key_in_label = 0 , $value_as_key = 0 , $optionType = 0 , $option = '' , $translate = 0 , $maxlen = 0 )
2008-10-01 23:16:35 +02:00
{
global $langs ;
2009-05-06 20:07:34 +02:00
$out = '' ;
2008-10-01 23:16:35 +02:00
// \TODO Simplify optionType and option (only one should be necessary)
if ( $optionType == 1 && $option != '' )
{
2009-05-06 20:07:34 +02:00
$out .= '<select class="flat" name="' . $htmlname . '" ' . $option . '>' ;
2008-10-01 23:16:35 +02:00
}
else
{
2009-05-06 20:07:34 +02:00
$out .= '<select class="flat" name="' . $htmlname . '">' ;
2008-10-01 23:16:35 +02:00
}
if ( $show_empty )
{
2009-05-06 20:07:34 +02:00
$out .= '<option value="-1"' . ( $id ==- 1 ? ' selected="true"' : '' ) . '> </option>' . " \n " ;
2008-10-01 23:16:35 +02:00
}
2009-01-22 23:55:51 +01:00
if ( is_array ( $array ))
2008-10-01 23:16:35 +02:00
{
2009-01-22 23:55:51 +01:00
while ( list ( $key , $value ) = each ( $array ))
2008-10-01 23:16:35 +02:00
{
2009-05-06 20:07:34 +02:00
$out .= '<option value="' . ( $value_as_key ? $value : $key ) . '"' ;
2009-06-18 10:43:16 +02:00
// Si il faut pre-selectionner une valeur
2009-01-22 23:55:51 +01:00
if ( $id != '' && ( $id == $key || $id == $value ))
{
2009-05-06 20:07:34 +02:00
$out .= ' selected="true"' ;
2009-01-22 23:55:51 +01:00
}
2009-01-23 18:18:19 +01:00
2009-05-06 20:07:34 +02:00
$out .= '>' ;
2009-01-23 18:18:19 +01:00
2009-01-22 23:55:51 +01:00
if ( $key_in_label )
{
$newval = ( $translate ? $langs -> trans ( $value ) : $value );
2009-02-20 23:53:15 +01:00
$selectOptionValue = $key . ' - ' . ( $maxlen ? dol_trunc ( $newval , $maxlen ) : $newval );
2009-05-06 20:07:34 +02:00
$out .= $selectOptionValue ;
2009-01-22 23:55:51 +01:00
}
else
{
$newval = ( $translate ? $langs -> trans ( $value ) : $value );
2009-02-20 23:53:15 +01:00
$selectOptionValue = ( $maxlen ? dol_trunc ( $newval , $maxlen ) : $newval );
2009-01-22 23:55:51 +01:00
if ( $value == '' || $value == '-' ) { $selectOptionValue = ' ' ; }
2009-05-06 20:07:34 +02:00
$out .= $selectOptionValue ;
2009-01-22 23:55:51 +01:00
}
2009-05-06 20:07:34 +02:00
$out .= " </option> \n " ;
2008-10-01 23:16:35 +02:00
}
}
2009-01-23 18:18:19 +01:00
2009-05-06 20:07:34 +02:00
$out .= " </select> " ;
return $out ;
}
/**
* \brief Show a select form from an array
* \param htmlname Nom de la zone select
* \param array Tableau de key + valeur
* \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 optionType Type de l ' option : 1 pour des fonctions javascript
* \param option Valeur de l ' option en fonction du type choisi
* \param translate Traduire la valeur
* \param maxlen Length maximum for labels
* \deprecated Use selectarray instead
*/
function select_array ( $htmlname , $array , $id = '' , $show_empty = 0 , $key_in_label = 0 , $value_as_key = 0 , $optionType = 0 , $option = '' , $translate = 0 , $maxlen = 0 )
{
print $this -> selectarray ( $htmlname , $array , $id , $show_empty , $key_in_label , $value_as_key , $optionType , $option , $translate , $maxlen );
2008-10-01 23:16:35 +02:00
}
/**
2010-01-13 12:22:26 +01:00
* \brief Return an html string with a select combo box to choose yes or no
* \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
2008-10-01 23:16:35 +02:00
*/
2009-01-18 18:07:27 +01:00
function selectyesno ( $htmlname , $value = '' , $option = 0 )
2008-10-01 23:16:35 +02:00
{
global $langs ;
$yes = " yes " ; $no = " no " ;
if ( $option )
{
$yes = " 1 " ;
$no = " 0 " ;
}
2009-01-18 18:07:27 +01:00
$resultyesno = '<select class="flat" name="' . $htmlname . '">' . " \n " ;
2008-10-01 23:16:35 +02:00
if (( " $value " == 'yes' ) || ( $value == 1 ))
{
2009-08-07 02:49:43 +02:00
$resultyesno .= '<option value="' . $yes . '" selected="true">' . $langs -> trans ( " Yes " ) . '</option>' . " \n " ;
$resultyesno .= '<option value="' . $no . '">' . $langs -> trans ( " No " ) . '</option>' . " \n " ;
2008-10-01 23:16:35 +02:00
}
else
{
2009-08-07 02:49:43 +02:00
$resultyesno .= '<option value="' . $yes . '">' . $langs -> trans ( " Yes " ) . '</option>' . " \n " ;
$resultyesno .= '<option value="' . $no . '" selected="true">' . $langs -> trans ( " No " ) . '</option>' . " \n " ;
2008-10-01 23:16:35 +02:00
}
$resultyesno .= '</select>' . " \n " ;
return $resultyesno ;
}
/**
2009-06-18 10:43:16 +02:00
* \brief Retourne la liste des modeles d ' export
* \param selected Id modele pre - selectionne
2008-10-01 23:16:35 +02:00
* \param htmlname Nom de la zone select
2009-06-18 10:43:16 +02:00
* \param type Type des modeles recherches
2008-10-01 23:16:35 +02:00
* \param useempty Affiche valeur vide dans liste
*/
function select_export_model ( $selected = '' , $htmlname = 'exportmodelid' , $type = '' , $useempty = 0 )
{
2009-01-18 18:07:27 +01:00
2008-10-01 23:16:35 +02:00
$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 )
{
print '<option value="' . $obj -> rowid . '" selected="true">' ;
}
else
{
print '<option value="' . $obj -> rowid . '">' ;
}
print $obj -> label ;
print '</option>' ;
$i ++ ;
}
print " </select> " ;
}
else {
2009-02-20 23:53:15 +01:00
dol_print_error ( $this -> db );
2008-10-01 23:16:35 +02:00
}
}
/**
2009-09-29 19:14:52 +02:00
* \brief Return HTML combo list of week
* \param selected Preselected value
* \param htmlname Nom de la zone select
* \param useempty Affiche valeur vide dans liste
* TODO Move into html . formother
*/
function select_dayofweek ( $selected = '' , $htmlname = 'weekid' , $useempty = 0 )
{
global $langs ;
$week = array ( 0 => $langs -> trans ( " Day0 " ),
1 => $langs -> trans ( " Day1 " ),
2 => $langs -> trans ( " Day2 " ),
3 => $langs -> trans ( " Day3 " ),
4 => $langs -> trans ( " Day4 " ),
5 => $langs -> trans ( " Day5 " ),
6 => $langs -> trans ( " Day6 " ));
2009-10-04 14:16:45 +02:00
2009-09-29 19:14:52 +02:00
$select_week = '<select class="flat" name="' . $htmlname . '">' ;
if ( $useempty )
{
$select_week .= '<option value="-1"> </option>' ;
}
foreach ( $week as $key => $val )
{
if ( $selected == $key )
{
$select_week .= '<option value="' . $key . '" selected="true">' ;
}
else
{
$select_week .= '<option value="' . $key . '">' ;
}
$select_week .= $val ;
}
$select_week .= '</select>' ;
return $select_week ;
}
2009-10-04 14:16:45 +02:00
2009-09-29 19:14:52 +02:00
/**
* \brief Return HTML combo list of month
* \param selected Preselected value
* \param htmlname Nom de la zone select
* \param useempty Affiche valeur vide dans liste
* TODO Move into html . formother
2008-10-01 23:16:35 +02:00
*/
function select_month ( $selected = '' , $htmlname = 'monthid' , $useempty = 0 )
{
$month = monthArrayOrSelected ( - 1 ); // Get array
$select_month = '<select class="flat" name="' . $htmlname . '">' ;
if ( $useempty )
{
$select_month .= '<option value="0"> </option>' ;
}
foreach ( $month as $key => $val )
{
if ( $selected == $key )
{
$select_month .= '<option value="' . $key . '" selected="true">' ;
}
else
{
$select_month .= '<option value="' . $key . '">' ;
}
$select_month .= $val ;
}
$select_month .= '</select>' ;
return $select_month ;
}
2009-10-04 14:16:45 +02:00
2008-10-01 23:16:35 +02:00
/**
2009-09-29 19:14:52 +02:00
* \brief Return HTML combo list of years
* \param selected Preselected value
* \param htmlname Name of HTML select object
* \param useempty Affiche valeur vide dans liste
* \param $min_year Valeur minimum de l ' annee dans la liste ( par defaut annee courante - 10 )
* \param $max_year Valeur maximum de l ' annee dans la liste ( par defaut annee courante + 5 )
* TODO Move into html . formother
2008-10-01 23:16:35 +02:00
*/
function select_year ( $selected = '' , $htmlname = 'yearid' , $useempty = 0 , $min_year = '' , $max_year = '' )
{
if ( $max_year == '' )
$max_year = date ( " Y " ) + 5 ;
if ( $min_year == '' )
$min_year = date ( " Y " ) - 10 ;
2006-05-06 23:09:26 +02:00
2008-10-01 23:16:35 +02:00
print '<select class="flat" name="' . $htmlname . '">' ;
if ( $useempty )
{
if ( $selected == '' )
$selected_html = 'selected="true"' ;
print '<option value="" ' . $selected_html . ' > </option>' ;
}
for ( $y = $max_year ; $y >= $min_year ; $y -- )
{
$selected_html = '' ;
if ( $y == $selected )
{
$selected_html = 'selected="true"' ;
}
print " <option value= \" $y\ " $selected_html > $y " ;
print " </option> " ;
}
print " </select> \n " ;
}
2006-11-19 05:56:10 +01:00
2008-01-11 11:25:26 +01:00
/**
2008-10-01 23:16:35 +02:00
* \brief Affiche tableau avec ref et bouton navigation pour un objet metier
* \param object Object to show
* \param paramid Nom du parametre a utiliser pour nommer id dans liens URL
* \param morehtml Code html supplementaire a afficher avant barre nav
2008-11-05 23:34:14 +01:00
* \param shownav Show Condition
* \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
2009-01-02 14:20:55 +01:00
* \param moreparam More param to ad in nav link url .
2008-10-25 23:18:53 +02:00
* \return string Portion HTML avec ref + boutons nav
2008-10-01 23:16:35 +02:00
*/
2009-01-02 14:20:55 +01:00
function showrefnav ( $object , $paramid , $morehtml = '' , $shownav = 1 , $fieldid = 'rowid' , $fieldref = 'ref' , $morehtmlref = '' , $moreparam = '' )
2007-07-29 12:18:31 +02:00
{
$ret = '' ;
2009-10-04 14:16:45 +02:00
//print "$paramid,$morehtml,$shownav,$fieldid,$fieldref,$morehtmlref,$moreparam";
2008-10-01 23:16:35 +02:00
$object -> load_previous_next_ref ( $object -> next_prev_filter , $fieldid );
2009-01-02 14:20:55 +01: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>' : '' ;
2007-07-29 12:18:31 +02:00
2008-02-24 15:41:07 +01:00
//print "xx".$previous_ref."x".$next_ref;
2007-07-29 13:09:04 +02:00
if ( $previous_ref || $next_ref || $morehtml ) {
$ret .= '<table class="nobordernopadding" width="100%"><tr class="nobordernopadding"><td class="nobordernopadding">' ;
}
2008-10-01 23:16:35 +02:00
2008-02-24 15:41:07 +01:00
$ret .= $object -> $fieldref ;
2008-11-05 23:34:14 +01:00
if ( $morehtmlref ) {
$ret .= ' ' . $morehtmlref ;
}
2009-01-18 18:07:27 +01:00
2007-07-29 13:09:04 +02:00
if ( $morehtml ) {
$ret .= '</td><td class="nobordernopadding" align="right">' . $morehtml ;
}
2007-09-01 00:06:14 +02:00
if ( $shownav && ( $previous_ref || $next_ref )) {
2007-07-29 12:18:31 +02:00
$ret .= '</td><td class="nobordernopadding" align="center" width="20">' . $previous_ref . '</td>' ;
2007-07-29 13:09:04 +02:00
$ret .= '<td class="nobordernopadding" align="center" width="20">' . $next_ref ;
}
if ( $previous_ref || $next_ref || $morehtml )
{
$ret .= '</td></tr></table>' ;
2007-07-29 12:18:31 +02:00
}
2008-10-01 23:16:35 +02:00
return $ret ;
2007-09-28 20:15:19 +02:00
}
2008-10-01 23:16:35 +02:00
2009-07-19 18:34:13 +02:00
/**
* \brief Return HTML code to output a photo
* \param modulepart Id to define module concerned
2010-02-13 23:20:32 +01:00
* \param object Object containing data to retrieve file name
2009-07-19 18:34:13 +02:00
* \param width Width of photo
* \return string HTML code to output photo
*/
function showphoto ( $modulepart , $object , $width = 100 )
{
global $conf ;
2009-07-19 18:58:34 +02:00
$ret = '' ; $dir = '' ; $file = '' ; $email = '' ;
2009-07-19 18:34:13 +02:00
if ( $modulepart == 'userphoto' )
{
$dir = $conf -> user -> dir_output ;
2010-02-13 23:20:32 +01:00
$file = get_exdir ( $object -> id , 2 ) . $object -> photo ;
$altfile = $object -> id . " .jpg " ; // For backward compatibility
2009-07-19 18:58:34 +02:00
$email = $object -> email ;
2009-07-19 18:34:13 +02:00
}
2009-12-30 12:51:41 +01:00
if ( $modulepart == 'memberphoto' )
2009-07-19 18:34:13 +02:00
{
$dir = $conf -> adherent -> dir_output ;
2010-02-13 23:20:32 +01:00
$file = get_exdir ( $object -> id , 2 ) . $object -> photo ;
$altfile = $object -> id . " .jpg " ; // For backward compatibility
2009-07-19 18:58:34 +02:00
$email = $object -> email ;
2009-07-19 18:34:13 +02:00
}
if ( $dir && $file )
{
if ( file_exists ( $dir . " / " . $file ))
{
$ret .= '<img alt="Photo" width="' . $width . '" src="' . DOL_URL_ROOT . '/viewimage.php?modulepart=' . $modulepart . '&file=' . urlencode ( $file ) . '">' ;
2010-02-13 23:20:32 +01:00
}
else if ( file_exists ( $dir . " / " . $altfile ))
{
$ret .= '<img alt="Photo" width="' . $width . '" src="' . DOL_URL_ROOT . '/viewimage.php?modulepart=' . $modulepart . '&file=' . urlencode ( $altfile ) . '">' ;
2009-07-19 18:34:13 +02:00
}
else
{
2009-07-19 18:58:34 +02:00
if ( $conf -> gravatar -> enabled )
{
global $dolibarr_main_url_root ;
$ret .= '<!-- Put link to gravatar -->' ;
2009-07-23 01:55:09 +02:00
$ret .= '<img alt="Photo found on Gravatar" title="Photo Gravatar.com - email ' . $email . '" width="' . $width . '" src="http://www.gravatar.com/avatar/' . md5 ( $email ) . '?s=' . $width . '&d=' . urlencode ( $dolibarr_main_url_root . '/theme/common/nophoto.jpg' ) . '">' ;
2009-07-19 18:58:34 +02:00
}
else
{
$ret .= '<img alt="No photo" width="' . $width . '" src="' . DOL_URL_ROOT . '/theme/common/nophoto.jpg">' ;
}
2009-07-19 18:34:13 +02:00
}
}
else
{
dol_print_error ( '' , 'Call to showrefnav with wrong parameters' );
}
return $ret ;
}
2006-02-09 18:36:09 +01:00
}
2006-02-09 09:36:22 +01:00
?>