2002-12-19 19:55:38 +01:00
< ? PHP
2005-01-05 16:34:24 +01:00
/* Copyright ( c ) 2002 - 2005 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
2004-01-28 01:25:15 +01:00
* Copyright ( C ) 2004 Laurent Destailleur < eldy @ users . sourceforge . net >
2004-07-17 19:16:42 +02:00
* Copyright ( C ) 2004 Benoit Mortier < benoit . mortier @ opensides . be >
2004-09-01 23:23:20 +02:00
* Copyright ( C ) 2004 Sebastien Di Cintio < sdicintio @ ressource - toi . org >
2004-12-22 21:07:14 +01:00
* Copyright ( C ) 2004 Eric Seigne < eric . seigne @ ryxeo . com >
2004-06-16 15:21:13 +02:00
*
2002-12-19 19:55:38 +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 .
*
* $Id $
* $Source $
*/
2005-01-05 16:34:24 +01:00
/*!
\file htdocs / html . form . class . php
\brief Fichier de la classe des fonctions pr<EFBFBD> d<EFBFBD> finie de composants html
\version $Revision $
2004-09-18 18:36:33 +02:00
*/
2005-01-05 16:34:24 +01:00
/*!
\class Form
\brief Classe permettant la g<EFBFBD> n<EFBFBD> ration de composants html
2004-09-18 18:36:33 +02:00
*/
2004-07-21 10:43:48 +02:00
class Form
{
2002-12-19 19:55:38 +01:00
var $db ;
var $errorstr ;
2004-09-02 22:28:56 +02:00
2004-10-20 23:06:45 +02:00
/*! \brief Constructeur
2005-01-05 16:34:24 +01:00
\param DB handler d ' acc<EFBFBD> s base de donn<EFBFBD> e
2004-10-20 23:06:45 +02:00
*/
2004-08-07 20:51:54 +02:00
function Form ( $DB )
2004-07-21 10:43:48 +02:00
{
$this -> db = $DB ;
return 1 ;
}
2004-02-17 10:43:59 +01:00
/*
2004-10-23 16:27:26 +02:00
* \brief Retourne la liste d<EFBFBD> roulante des d<EFBFBD> partements / province / cantons
* avec un affichage avec rupture sur le pays
* \remarks La cle de la liste est le code ( il peut y avoir plusieurs entr<EFBFBD> e pour
* un code donn<EFBFBD> e mais dans ce cas , le champ pays et lang diff<EFBFBD> re ) .
* Ainsi les liens avec les d<EFBFBD> partements se font sur un d<EFBFBD> partement
* independemment de nom som .
2004-02-17 10:43:59 +01:00
*/
2004-10-20 23:06:45 +02:00
2004-08-08 20:20:28 +02:00
function select_departement ( $selected = '' , $htmlname = 'departement_id' )
2004-07-21 10:43:48 +02:00
{
2004-09-18 18:36:33 +02:00
global $conf , $langs ;
$langs -> load ( " dict " );
2004-07-21 10:43:48 +02:00
// On recherche les d<> partements/cantons/province active d'une region et pays actif
$sql = " SELECT d.rowid, d.code_departement as code , d.nom, d.active, p.libelle as libelle_pays, p.code as code_pays FROM " ;
$sql .= MAIN_DB_PREFIX . " c_departements as d, " . MAIN_DB_PREFIX . " c_regions as r, " . MAIN_DB_PREFIX . " c_pays as p " ;
$sql .= " WHERE d.fk_region=r.code_region and r.fk_pays=p.rowid " ;
$sql .= " AND d.active = 1 AND r.active = 1 AND p.active = 1 " ;
$sql .= " ORDER BY code_pays, code ASC " ;
2004-06-10 02:26:07 +02:00
2004-07-21 10:43:48 +02:00
if ( $this -> db -> query ( $sql ))
2005-01-05 16:34:24 +01:00
{
2004-09-18 18:36:33 +02:00
print '<select name="' . $htmlname . '">' ;
$num = $this -> db -> num_rows ();
$i = 0 ;
if ( $num )
2005-01-05 16:34:24 +01:00
{
2004-09-18 18:36:33 +02:00
$pays = '' ;
while ( $i < $num )
2005-01-05 16:34:24 +01:00
{
2004-10-23 23:02:56 +02:00
$obj = $this -> db -> fetch_object ();
2004-09-18 18:36:33 +02:00
if ( $obj -> code == 0 ) {
2005-01-05 16:34:24 +01:00
print '<option value="0"> </option>' ;
2004-09-18 18:36:33 +02:00
}
else {
2005-01-05 16:34:24 +01:00
if ( $pays == '' || $pays != $obj -> libelle_pays ) {
// Affiche la rupture
print '<option value="-1">----- ' . $obj -> libelle_pays . " -----</option> \n " ;
$pays = $obj -> libelle_pays ;
}
2004-09-18 18:36:33 +02:00
2005-01-05 16:34:24 +01:00
if ( $selected > 0 && $selected == $obj -> rowid )
2004-09-18 18:36:33 +02:00
{
2005-01-05 16:34:24 +01:00
print '<option value="' . $obj -> rowid . '" selected>' ;
2004-09-18 18:36:33 +02:00
}
2005-01-05 16:34:24 +01:00
else
2004-09-18 18:36:33 +02:00
{
2005-01-05 16:34:24 +01:00
print '<option value="' . $obj -> rowid . '">' ;
2004-09-18 18:36:33 +02:00
}
2005-01-05 16:34:24 +01:00
// Si traduction existe, on l'utilise, sinon on prend le libell<6C> par d<> faut
print $obj -> code . ' - ' . ( $langs -> trans ( $obj -> code ) != $obj -> code ? $langs -> trans ( $obj -> code ) : ( $obj -> nom != '-' ? $obj -> nom : '' ));
print '</option>' ;
2004-09-18 18:36:33 +02:00
}
$i ++ ;
2005-01-05 16:34:24 +01:00
}
}
2004-09-18 18:36:33 +02:00
print '</select>' ;
2005-01-05 16:34:24 +01:00
}
2004-07-21 10:43:48 +02:00
else {
2005-01-05 16:34:24 +01:00
dolibarr_print_error ( $this -> db );
2004-06-10 02:26:07 +02:00
}
2005-01-05 16:34:24 +01:00
}
2004-07-21 10:43:48 +02:00
/*
2004-10-23 16:27:26 +02:00
* \brief Retourne la liste d<EFBFBD> roulante des regions actives dont le pays est actif
* \remarks La cle de la liste est le code ( il peut y avoir plusieurs entr<EFBFBD> e pour
* un code donn<EFBFBD> e mais dans ce cas , le champ pays et lang diff<EFBFBD> re ) .
* Ainsi les liens avec les regions se font sur une region independemment
* de nom som .
2004-08-08 20:20:28 +02:00
*/
2004-10-20 23:06:45 +02:00
2004-08-08 20:20:28 +02:00
function select_region ( $selected = '' , $htmlname = 'region_id' )
{
2004-09-18 18:36:33 +02:00
global $conf , $langs ;
$langs -> load ( " dict " );
2004-08-08 20:20:28 +02:00
$sql = " SELECT r.rowid, r.code_region as code, r.nom as libelle, r.active, p.libelle as libelle_pays FROM " . MAIN_DB_PREFIX . " c_regions as r, " . MAIN_DB_PREFIX . " c_pays as p " ;
$sql .= " WHERE r.fk_pays=p.rowid AND r.active = 1 and p.active = 1 ORDER BY libelle_pays, libelle ASC " ;
if ( $this -> db -> query ( $sql ))
{
2005-01-05 16:34:24 +01:00
print '<select name="' . $htmlname . '">' ;
2004-08-08 20:20:28 +02:00
$num = $this -> db -> num_rows ();
$i = 0 ;
if ( $num )
{
$pays = '' ;
while ( $i < $num )
{
2004-10-23 23:02:56 +02:00
$obj = $this -> db -> fetch_object ();
2004-08-08 20:20:28 +02:00
if ( $obj -> code == 0 ) {
print '<option value="0"> </option>' ;
}
else {
if ( $pays == '' || $pays != $obj -> libelle_pays ) {
// Affiche la rupture
print '<option value="-1">----- ' . $obj -> libelle_pays . " -----</option> \n " ;
$pays = $obj -> libelle_pays ;
}
if ( $selected > 0 && $selected == $obj -> code )
{
print '<option value="' . $obj -> code . '" selected>' . $obj -> libelle . '</option>' ;
}
else
{
print '<option value="' . $obj -> code . '">' . $obj -> libelle . '</option>' ;
}
}
$i ++ ;
}
}
2005-01-05 16:34:24 +01:00
print '</select>' ;
2004-08-08 20:20:28 +02:00
}
else {
dolibarr_print_error ( $this -> db );
}
}
/*
2004-10-23 16:27:26 +02:00
* \brief Retourne la liste d<EFBFBD> roulante des pays actifs , dans la langue de l ' utilisateur
* \param selected code pays pr<EFBFBD> - s<EFBFBD> lectionn<EFBFBD>
* \param htmlname nom de la liste deroulante
* \todo trier liste sur noms apr<EFBFBD> s traduction plutot que avant
2004-02-17 11:03:22 +01:00
*/
2004-10-20 23:06:45 +02:00
2004-08-08 20:20:28 +02:00
function select_pays ( $selected = '' , $htmlname = 'pays_id' )
2004-02-17 11:03:22 +01:00
{
2004-09-18 18:36:33 +02:00
global $conf , $langs ;
$langs -> load ( " dict " );
$sql = " SELECT rowid, libelle, code, active FROM " . MAIN_DB_PREFIX . " c_pays " ;
$sql .= " WHERE active = 1 " ;
2004-09-18 18:44:52 +02:00
$sql .= " ORDER BY code ASC; " ;
2004-09-18 18:36:33 +02:00
2004-02-17 11:03:22 +01:00
if ( $this -> db -> query ( $sql ))
2005-01-05 16:34:24 +01:00
{
2004-09-18 18:36:33 +02:00
print '<select name="' . $htmlname . '">' ;
$num = $this -> db -> num_rows ();
$i = 0 ;
if ( $num )
2005-01-05 16:34:24 +01:00
{
2004-09-18 18:36:33 +02:00
$foundselected = false ;
while ( $i < $num )
2005-01-05 16:34:24 +01:00
{
2004-10-23 23:02:56 +02:00
$obj = $this -> db -> fetch_object ();
2004-09-18 18:36:33 +02:00
if ( $selected > 0 && $selected == $obj -> rowid )
2005-01-05 16:34:24 +01:00
{
2004-09-18 18:36:33 +02:00
$foundselected = true ;
print '<option value="' . $obj -> rowid . '" selected>' ;
2005-01-05 16:34:24 +01:00
}
2004-09-18 18:36:33 +02:00
else
2005-01-05 16:34:24 +01:00
{
2004-09-18 18:36:33 +02:00
print '<option value="' . $obj -> rowid . '">' ;
2005-01-05 16:34:24 +01:00
}
2004-12-22 21:07:14 +01:00
// Si traduction existe, on l'utilise, sinon on prend le libell<6C> par d<> faut
if ( $obj -> code ) { print $obj -> code . ' - ' ; }
2004-09-18 19:11:10 +02:00
print ( $obj -> code && $langs -> trans ( " Country " . $obj -> code ) != " Country " . $obj -> code ? $langs -> trans ( " Country " . $obj -> code ) : ( $obj -> libelle != '-' ? $obj -> libelle : '' ));
2004-09-18 18:36:33 +02:00
print '</option>' ;
$i ++ ;
2005-01-05 16:34:24 +01:00
}
}
2004-09-18 18:36:33 +02:00
print '</select>' ;
return 0 ;
2005-01-05 16:34:24 +01:00
}
2004-09-18 18:36:33 +02:00
else {
2005-01-05 16:34:24 +01:00
dolibarr_print_error ( $this -> db );
return 1 ;
2004-09-18 18:36:33 +02:00
}
2004-02-17 11:03:22 +01:00
}
2004-08-08 20:20:28 +02:00
/*
2004-10-23 16:27:26 +02:00
* \brief Retourne la liste d<EFBFBD> roulante des langues disponibles
* \param
2004-08-08 20:20:28 +02:00
*/
2004-10-20 23:06:45 +02:00
2004-08-08 20:20:28 +02:00
function select_lang ( $selected = '' , $htmlname = 'lang_id' )
{
global $langs ;
$langs_available = $langs -> get_available_languages ();
print '<select name="' . $htmlname . '">' ;
2005-01-05 16:34:24 +01:00
$num = count ( $langs_available );
$i = 0 ;
if ( $num )
{
while ( $i < $num )
2004-08-08 20:20:28 +02:00
{
2005-01-05 16:34:24 +01:00
if ( $selected == $langs_available [ $i ])
2004-08-08 20:20:28 +02:00
{
2005-01-05 16:34:24 +01:00
print '<option value="' . $langs_available [ $i ] . '" selected>' . $langs_available [ $i ] . '</option>' ;
2004-08-08 20:20:28 +02:00
}
2005-01-05 16:34:24 +01:00
else
{
print '<option value="' . $langs_available [ $i ] . '">' . $langs_available [ $i ] . '</option>' ;
}
$i ++ ;
2004-08-08 20:20:28 +02:00
}
2005-01-05 16:34:24 +01:00
}
2004-08-08 20:20:28 +02:00
print '</select>' ;
}
2004-07-24 00:28:30 +02:00
/*
2004-10-23 16:27:26 +02:00
* \brief Retourne la liste d<EFBFBD> roulante des soci<EFBFBD> t<EFBFBD> s
* \param
2004-07-24 00:28:30 +02:00
*/
2004-10-20 23:06:45 +02:00
2004-08-07 20:51:54 +02:00
function select_societes ( $selected = '' , $htmlname = 'soc_id' )
2004-07-24 00:28:30 +02:00
{
// On recherche les societes
$sql = " SELECT s.idp, s.nom FROM " ;
$sql .= MAIN_DB_PREFIX . " societe as s " ;
$sql .= " ORDER BY nom ASC " ;
if ( $this -> db -> query ( $sql ))
{
2005-01-05 16:34:24 +01:00
print '<select name="' . $htmlname . '">' ;
2004-07-24 00:28:30 +02:00
$num = $this -> db -> num_rows ();
$i = 0 ;
if ( $num )
{
while ( $i < $num )
{
2004-10-23 23:02:56 +02:00
$obj = $this -> db -> fetch_object ();
2005-01-05 16:34:24 +01:00
if ( $selected > 0 && $selected == $obj -> idp )
{
print '<option value="' . $obj -> idp . '" selected>' . $obj -> nom . '</option>' ;
}
else
{
print '<option value="' . $obj -> idp . '">' . $obj -> nom . '</option>' ;
}
2004-07-24 00:28:30 +02:00
$i ++ ;
}
}
2005-01-05 16:34:24 +01:00
print '</select>' ;
2004-07-24 00:28:30 +02:00
}
else {
2004-08-07 01:39:22 +02:00
dolibarr_print_error ( $this -> db );
2004-07-24 00:28:30 +02:00
}
2004-08-07 01:39:22 +02:00
}
/*
2004-10-23 16:27:26 +02:00
* \brief Retourne la liste d<EFBFBD> roulante des contacts d ' une soci<EFBFBD> t<EFBFBD> donn<EFBFBD> e
2004-08-07 01:39:22 +02:00
*
*/
2004-10-20 23:06:45 +02:00
2004-08-07 20:51:54 +02:00
function select_contacts ( $socid , $selected = '' , $htmlname = 'contactid' )
2004-08-07 01:39:22 +02:00
{
// On recherche les societes
$sql = " SELECT s.idp, s.name, s.firstname FROM " ;
$sql .= MAIN_DB_PREFIX . " socpeople as s " ;
$sql .= " WHERE fk_soc= " . $socid ;
$sql .= " ORDER BY s.name ASC " ;
if ( $this -> db -> query ( $sql ))
{
2005-01-05 16:34:24 +01:00
print '<select name="' . $htmlname . '">' ;
2004-08-07 01:39:22 +02:00
$num = $this -> db -> num_rows ();
$i = 0 ;
if ( $num )
{
while ( $i < $num )
{
2005-01-05 16:34:24 +01:00
$obj = $this -> db -> fetch_object ();
2004-08-07 01:39:22 +02:00
2005-01-05 16:34:24 +01:00
if ( $selected && $selected == $obj -> idp )
{
print '<option value="' . $obj -> idp . '" selected>' . $obj -> name . ' ' . $obj -> firstname . '</option>' ;
}
else
{
print '<option value="' . $obj -> idp . '">' . $obj -> name . ' ' . $obj -> firstname . '</option>' ;
}
2004-08-07 01:39:22 +02:00
$i ++ ;
}
}
2005-01-05 16:34:24 +01:00
print '</select>' ;
}
else
{
dolibarr_print_error ( $this -> db );
2004-08-07 01:39:22 +02:00
}
2004-07-24 00:28:30 +02:00
}
2005-01-05 16:34:24 +01:00
2004-07-24 00:28:30 +02:00
2004-07-21 10:43:48 +02:00
/*
2004-10-23 16:27:26 +02:00
* \brief Retourne le nom d ' un pays
* \param id id du pays
2004-07-21 10:43:48 +02:00
*/
2004-10-20 23:06:45 +02:00
2004-08-07 20:51:54 +02:00
function pays_name ( $id )
2004-07-21 10:43:48 +02:00
{
$sql = " SELECT rowid, libelle FROM " . MAIN_DB_PREFIX . " c_pays " ;
2004-09-02 22:28:56 +02:00
$sql .= " WHERE rowid= $id ; " ;
2004-07-21 10:43:48 +02:00
if ( $this -> db -> query ( $sql ))
{
$num = $this -> db -> num_rows ();
2004-09-02 22:28:56 +02:00
2004-07-21 10:43:48 +02:00
if ( $num )
{
2004-10-23 23:02:56 +02:00
$obj = $this -> db -> fetch_object ();
2004-08-07 01:39:22 +02:00
return $obj -> libelle ;
2004-07-21 10:43:48 +02:00
}
else
{
2004-10-23 16:27:26 +02:00
return " Non d<> fini " ;
2004-07-21 10:43:48 +02:00
}
}
2004-09-02 22:28:56 +02:00
2004-07-21 10:43:48 +02:00
}
2004-08-08 21:23:55 +02:00
/*
2004-10-23 16:27:26 +02:00
* \brief Retourne la liste d<EFBFBD> roulante des civilite actives
* \param selected civilite pr<EFBFBD> - s<EFBFBD> lectionn<EFBFBD> e
2004-06-16 15:21:13 +02:00
*/
2004-08-07 20:51:54 +02:00
function select_civilite ( $selected = '' )
2004-06-16 15:21:13 +02:00
{
2004-09-18 18:36:33 +02:00
global $conf , $langs ;
$langs -> load ( " dict " );
2004-08-08 21:23:55 +02:00
$sql = " SELECT rowid, code, civilite, active FROM " . MAIN_DB_PREFIX . " c_civilite " ;
2004-06-16 15:21:13 +02:00
$sql .= " WHERE active = 1 " ;
2004-09-18 18:36:33 +02:00
2004-06-16 15:21:13 +02:00
if ( $this -> db -> query ( $sql ))
2005-01-05 16:34:24 +01:00
{
2004-09-18 18:36:33 +02:00
print '<select name="civilite_id">' ;
2004-12-25 19:31:51 +01:00
print '<option value=""> </option>' ;
2004-09-18 18:36:33 +02:00
$num = $this -> db -> num_rows ();
$i = 0 ;
if ( $num )
2005-01-05 16:34:24 +01:00
{
2004-09-18 18:36:33 +02:00
while ( $i < $num )
2005-01-05 16:34:24 +01:00
{
2004-10-23 23:02:56 +02:00
$obj = $this -> db -> fetch_object ();
2004-12-25 19:31:51 +01:00
if ( $selected == $obj -> code )
2005-01-05 16:34:24 +01:00
{
2004-09-18 18:36:33 +02:00
print '<option value="' . $obj -> code . '" selected>' ;
2005-01-05 16:34:24 +01:00
}
2004-09-18 18:36:33 +02:00
else
2005-01-05 16:34:24 +01:00
{
2004-09-18 18:36:33 +02:00
print '<option value="' . $obj -> code . '">' ;
2005-01-05 16:34:24 +01:00
}
2004-12-22 21:07:14 +01:00
// Si traduction existe, on l'utilise, sinon on prend le libell<6C> par d<> faut
2004-09-18 18:36:33 +02:00
print ( $langs -> trans ( $obj -> code ) != $obj -> code ? $langs -> trans ( $obj -> code ) : ( $obj -> civilite != '-' ? $obj -> civilite : '' ));
print '</option>' ;
$i ++ ;
2005-01-05 16:34:24 +01:00
}
}
2004-09-18 18:36:33 +02:00
print '</select>' ;
2005-01-05 16:34:24 +01:00
}
2004-08-07 01:39:22 +02:00
else {
2005-01-05 16:34:24 +01:00
dolibarr_print_error ( $this -> db );
2004-09-18 18:36:33 +02:00
}
2004-06-16 15:21:13 +02:00
}
2004-06-10 19:34:33 +02:00
/*
2004-10-23 16:27:26 +02:00
* \brief Retourne la liste d<EFBFBD> roulante des formes juridiques avec un affichage avec rupture sur le pays
2004-06-10 19:34:33 +02:00
*
*/
2004-10-20 23:06:45 +02:00
2004-09-18 18:36:33 +02:00
function select_forme_juridique ( $selected = '' )
{
global $conf , $langs ;
$langs -> load ( " dict " );
// On recherche les formes juridiques actives des pays actifs
$sql = " SELECT f.rowid, f.code as code , f.libelle as nom, f.active, p.libelle as libelle_pays, p.code as code_pays FROM llx_c_forme_juridique as f, llx_c_pays as p " ;
$sql .= " WHERE f.fk_pays=p.rowid " ;
$sql .= " AND f.active = 1 AND p.active = 1 ORDER BY code_pays, code ASC " ;
if ( $this -> db -> query ( $sql ))
2005-01-05 16:34:24 +01:00
{
2004-09-18 18:36:33 +02:00
print '<select name="forme_juridique_code">' ;
$num = $this -> db -> num_rows ();
$i = 0 ;
if ( $num )
2005-01-05 16:34:24 +01:00
{
2004-09-18 18:36:33 +02:00
$pays = '' ;
while ( $i < $num )
2005-01-05 16:34:24 +01:00
{
2004-10-23 23:02:56 +02:00
$obj = $this -> db -> fetch_object ();
2004-09-18 18:36:33 +02:00
if ( $obj -> code == 0 ) {
2005-01-05 16:34:24 +01:00
print '<option value="0"> </option>' ;
2004-09-18 18:36:33 +02:00
}
else {
2005-01-05 16:34:24 +01:00
if ( $pays == '' || $pays != $obj -> libelle_pays ) {
// Affiche la rupture
print '<option value="0">----- ' . $obj -> libelle_pays . " -----</option> \n " ;
$pays = $obj -> libelle_pays ;
}
2004-09-18 18:36:33 +02:00
2005-01-05 16:34:24 +01:00
if ( $selected > 0 && $selected == $obj -> code )
2004-09-18 18:36:33 +02:00
{
2005-01-05 16:34:24 +01:00
print '<option value="' . $obj -> code . '" selected>' ;
2004-09-18 18:36:33 +02:00
}
2005-01-05 16:34:24 +01:00
else
2004-09-18 18:36:33 +02:00
{
2005-01-05 16:34:24 +01:00
print '<option value="' . $obj -> code . '">' ;
2004-09-18 18:36:33 +02:00
}
2005-01-05 16:34:24 +01:00
// Si traduction existe, on l'utilise, sinon on prend le libell<6C> par d<> faut
print $obj -> code . ' - ' . ( $langs -> trans ( $obj -> code ) != $obj -> code ? $langs -> trans ( $obj -> code ) : ( $obj -> nom != '-' ? $obj -> nom : '' ));
print '</option>' ;
2004-06-10 19:34:33 +02:00
}
2004-09-18 18:36:33 +02:00
$i ++ ;
2005-01-05 16:34:24 +01:00
}
}
2004-09-18 18:36:33 +02:00
print '</select>' ;
2005-01-05 16:34:24 +01:00
}
2004-09-18 18:36:33 +02:00
else {
2005-01-05 16:34:24 +01:00
dolibarr_print_error ( $this -> db );
2004-06-10 19:34:33 +02:00
}
2004-09-18 18:36:33 +02:00
}
2004-07-21 10:05:56 +02:00
2002-12-19 19:55:38 +01:00
/*
2004-09-18 18:36:33 +02:00
* \brief Affiche formulaire de demande de confirmation
* \param page page
* \param title title
* \param question question
* \param action action
2002-12-19 19:55:38 +01:00
*/
2004-10-20 23:06:45 +02:00
2004-08-07 20:51:54 +02:00
function form_confirm ( $page , $title , $question , $action )
2003-03-25 18:43:25 +01:00
{
2004-07-28 00:37:51 +02:00
global $langs ;
2003-03-25 18:43:25 +01:00
print '<form method="post" action="' . $page . '">' ;
2003-09-12 15:00:02 +02:00
print '<input type="hidden" name="action" value="' . $action . '">' ;
2004-10-23 23:02:56 +02:00
print '<table class="border" width="100%">' ;
2003-03-25 18:43:25 +01:00
print '<tr><td colspan="3">' . $title . '</td></tr>' ;
print '<tr><td class="valid">' . $question . '</td><td class="valid">' ;
$this -> selectyesno ( " confirm " , " no " );
print " </td> \n " ;
2004-07-28 00:37:51 +02:00
print '<td class="valid" align="center"><input type="submit" value="' . $langs -> trans ( " Confirm " ) . '"</td></tr>' ;
2003-03-25 18:43:25 +01:00
print '</table>' ;
print " </form> \n " ;
}
2004-10-20 23:06:45 +02:00
2003-03-25 18:43:25 +01:00
/*
2004-10-23 16:27:26 +02:00
* \brief Selection du taux de tva
2003-03-25 18:43:25 +01:00
*
*/
2004-10-20 23:06:45 +02:00
2004-08-07 20:51:54 +02:00
function select_tva ( $name = '' , $defaulttx = '' )
2003-03-12 19:59:53 +01:00
{
if ( ! strlen ( trim ( $name )))
2005-01-05 16:34:24 +01:00
{
$name = " tauxtva " ;
}
2003-03-12 19:59:53 +01:00
2003-10-08 16:56:20 +02:00
$file = DOL_DOCUMENT_ROOT . " /conf/tva.local.php " ;
if ( is_readable ( $file ))
{
include $file ;
}
else
{
$txtva [ 0 ] = '19.6' ;
$txtva [ 1 ] = '5.5' ;
$txtva [ 2 ] = '0' ;
}
2003-09-07 20:21:09 +02:00
2003-10-09 00:43:59 +02:00
if ( $defaulttx == '' )
{
$defaulttx = $txtva [ 0 ];
}
2003-09-07 20:21:09 +02:00
$taille = sizeof ( $txtva );
2003-03-12 19:59:53 +01:00
print '<select name="' . $name . '">' ;
2003-09-07 20:21:09 +02:00
for ( $i = 0 ; $i < $taille ; $i ++ )
{
print '<option value="' . $txtva [ $i ] . '"' ;
if ( $txtva [ $i ] == $defaulttx )
{
print ' SELECTED>' . $txtva [ $i ] . ' %</option>' ;
}
else
{
print '>' . $txtva [ $i ] . ' %</option>' ;
}
}
2003-03-12 19:59:53 +01:00
print '</select>' ;
}
2004-07-17 19:16:42 +02:00
/*
2004-10-23 16:27:26 +02:00
* \brief Affiche zone de selection de date
* Liste deroulante pour les jours , mois , annee et eventuellement heurs et minutes
* Les champs sont pr<EFBFBD> s<EFBFBD> lectionn<EFBFBD> es avec :
* - La date set_time ( timestamps ou date au format YYYY - MM - DD ou YYYY - MM - DD HH : MM )
* - La date du jour si set_time vaut ''
* - Aucune date ( champs vides ) si set_time vaut - 1
2004-07-17 19:16:42 +02:00
*/
2004-08-07 20:51:54 +02:00
function select_date ( $set_time = '' , $prefix = 're' , $h = 0 , $m = 0 , $empty = 0 )
2003-03-12 19:59:53 +01:00
{
2004-07-17 19:16:42 +02:00
if ( ! $set_time && ! $empty )
2003-03-12 19:59:53 +01:00
{
2005-01-05 16:34:24 +01:00
$set_time = time ();
2003-03-12 19:59:53 +01:00
}
2002-12-19 19:55:38 +01:00
2003-03-12 19:59:53 +01:00
$strmonth [ 1 ] = " Janvier " ;
$strmonth [ 2 ] = " Février " ;
$strmonth [ 3 ] = " Mars " ;
$strmonth [ 4 ] = " Avril " ;
$strmonth [ 5 ] = " Mai " ;
$strmonth [ 6 ] = " Juin " ;
$strmonth [ 7 ] = " Juillet " ;
$strmonth [ 8 ] = " Août " ;
$strmonth [ 9 ] = " Septembre " ;
$strmonth [ 10 ] = " Octobre " ;
$strmonth [ 11 ] = " Novembre " ;
$strmonth [ 12 ] = " Décembre " ;
2004-12-22 21:07:14 +01:00
// Analyse de la date de pr<70> selection
2004-07-17 19:16:42 +02:00
if ( eregi ( '^([0-9]+)\-([0-9]+)\-([0-9]+)\s?([0-9]+)?:?([0-9]+)?' , $set_time , $reg )) {
2005-01-05 16:34:24 +01: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 ];
2004-07-17 19:16:42 +02:00
}
else {
2005-01-05 16:34:24 +01:00
// Date est un timestamps
$syear = date ( " Y " , $set_time );
$smonth = date ( " n " , $set_time );
$sday = date ( " d " , $set_time );
$shour = date ( " H " , $set_time );
$smin = date ( " i " , $set_time );
2004-07-17 19:16:42 +02:00
}
2003-03-12 19:59:53 +01:00
2003-08-03 14:20:14 +02:00
print '<select name="' . $prefix . 'day">' ;
2004-02-08 16:14:16 +01:00
2004-07-17 19:16:42 +02:00
if ( $empty || $set_time == - 1 )
2004-02-08 16:14:16 +01:00
{
2004-07-17 19:16:42 +02:00
$sday = 0 ;
$smonth = 0 ;
$syear = 0 ;
$shour = 0 ;
$smin = 0 ;
2004-02-08 16:14:16 +01:00
2004-07-17 19:16:42 +02:00
print '<option value="0" selected>' ;
2004-02-08 16:14:16 +01:00
}
2003-03-12 19:59:53 +01:00
2004-07-17 19:16:42 +02:00
for ( $day = 1 ; $day <= 31 ; $day ++ )
2003-03-12 19:59:53 +01:00
{
2004-07-17 19:16:42 +02:00
if ( $day == $sday )
2003-03-12 19:59:53 +01:00
{
2004-07-17 19:16:42 +02:00
print " <option value= \" $day\ " selected > $day " ;
2003-03-12 19:59:53 +01:00
}
else
{
print " <option value= \" $day\ " > $day " ;
}
}
print " </select> " ;
2003-08-03 14:20:14 +02:00
print '<select name="' . $prefix . 'month">' ;
2004-07-17 19:16:42 +02:00
if ( $empty || $set_time == - 1 )
2004-02-08 16:14:16 +01:00
{
2004-07-17 19:16:42 +02:00
print '<option value="0" selected>' ;
2004-02-08 16:14:16 +01:00
}
2004-07-17 19:16:42 +02:00
for ( $month = 1 ; $month <= 12 ; $month ++ )
2003-03-12 19:59:53 +01:00
{
2004-07-17 19:16:42 +02:00
if ( $month == $smonth )
2003-03-12 19:59:53 +01:00
{
2004-07-17 19:16:42 +02:00
print " <option value= \" $month\ " selected > " . $strmonth[$month] ;
2003-03-12 19:59:53 +01:00
}
else
{
print " <option value= \" $month\ " > " . $strmonth[$month] ;
}
}
print " </select> " ;
2004-02-08 16:14:16 +01:00
2004-07-17 19:16:42 +02:00
if ( $empty || $set_time == - 1 )
2003-03-12 19:59:53 +01:00
{
2004-02-08 16:14:16 +01:00
print '<input type="text" size="5" maxlength="4" name="' . $prefix . 'year">' ;
}
else
{
print '<select name="' . $prefix . 'year">' ;
2004-07-17 19:16:42 +02:00
for ( $year = $syear - 3 ; $year < $syear + 5 ; $year ++ )
2003-03-12 19:59:53 +01:00
{
2004-02-08 16:14:16 +01:00
if ( $year == $syear )
{
2004-07-17 19:16:42 +02:00
print " <option value= \" $year\ " selected > $year " ;
2004-02-08 16:14:16 +01:00
}
else
{
print " <option value= \" $year\ " > $year " ;
}
2003-03-12 19:59:53 +01:00
}
2004-02-08 16:14:16 +01:00
print " </select> \n " ;
2003-03-12 19:59:53 +01:00
}
2004-02-08 16:14:16 +01:00
2003-08-03 13:56:34 +02:00
if ( $h )
{
2003-08-03 14:20:14 +02:00
print '<select name="' . $prefix . 'hour">' ;
2003-08-03 13:56:34 +02:00
for ( $hour = 0 ; $hour < 24 ; $hour ++ )
{
if ( strlen ( $hour ) < 2 )
{
$hour = " 0 " . $hour ;
}
if ( $hour == $shour )
{
2004-07-17 19:16:42 +02:00
print " <option value= \" $hour\ " selected > $hour " ;
2003-08-03 13:56:34 +02:00
}
else
{
print " <option value= \" $hour\ " > $hour " ;
}
}
print " </select>H \n " ;
if ( $m )
{
2003-08-03 14:20:14 +02:00
print '<select name="' . $prefix . 'min">' ;
2003-08-03 13:56:34 +02:00
for ( $min = 0 ; $min < 60 ; $min ++ )
{
if ( strlen ( $min ) < 2 )
{
$min = " 0 " . $min ;
}
if ( $min == $smin )
{
2004-07-17 19:16:42 +02:00
print " <option value= \" $min\ " selected > $min " ;
2003-08-03 13:56:34 +02:00
}
else
{
print " <option value= \" $min\ " > $min " ;
}
}
print " </select>M \n " ;
}
}
2003-03-12 19:59:53 +01:00
}
2004-10-20 23:06:45 +02:00
2003-03-12 19:59:53 +01:00
/*
2004-10-23 16:27:26 +02:00
* \brief Affiche liste d<EFBFBD> roulante
2003-03-12 19:59:53 +01:00
*
*/
2004-08-07 20:51:54 +02:00
function select ( $name , $sql , $id = '' )
2005-01-05 16:34:24 +01:00
{
2002-12-19 19:55:38 +01:00
2005-01-05 16:34:24 +01:00
$result = $this -> db -> query ( $sql );
if ( $result )
{
2002-12-19 19:55:38 +01:00
2005-01-05 16:34:24 +01:00
print '<select name="' . $name . '">' ;
2002-12-19 19:55:38 +01:00
2005-01-05 16:34:24 +01:00
$num = $this -> db -> num_rows ();
$i = 0 ;
2002-12-19 19:55:38 +01:00
2005-01-05 16:34:24 +01:00
if ( strlen ( " $id " ))
{
while ( $i < $num )
{
$row = $this -> db -> fetch_row ( $i );
print " <option value= \" $row[0] \" " ;
if ( $id == $row [ 0 ])
{
print " selected " ;
}
print " > $row[1] </option> \n " ;
$i ++ ;
}
}
else
{
while ( $i < $num )
{
$row = $this -> db -> fetch_row ( $i );
print " <option value= \" $row[0] \" > $row[1] </option> \n " ;
$i ++ ;
}
}
2002-12-19 19:55:38 +01:00
2005-01-05 16:34:24 +01:00
print " </select> " ;
}
else
{
print $this -> db -> error ();
}
2002-12-19 19:55:38 +01:00
2005-01-05 16:34:24 +01:00
}
2004-08-05 04:14:46 +02:00
2005-01-05 16:34:24 +01:00
/*!
\brief Affiche un select <EFBFBD> partir d ' un tableau
\param name nom de la zone select
\param array tableau de key + valeur
\param id key pr<EFBFBD> s<EFBFBD> lectionn<EFBFBD> e
\param empty 1 si il faut un valeur " " dans la liste , 0 sinon
\param key_libelle 1 pour afficher la key dans la valeur " [key] value "
*/
2004-10-20 23:06:45 +02:00
2004-08-07 20:51:54 +02:00
function select_array ( $name , $array , $id = '' , $empty = 0 , $key_libelle = 0 )
2005-01-05 16:34:24 +01:00
{
print '<select name="' . $name . '">' ;
2004-12-25 20:03:22 +01:00
2005-01-05 16:34:24 +01:00
$i = 0 ;
2004-12-25 20:03:22 +01:00
2005-01-05 16:34:24 +01:00
if ( strlen ( $id )) {
if ( $empty == 1 )
{
$array [ 0 ] = " " ;
}
reset ( $array );
}
2004-12-25 20:03:22 +01:00
2005-01-05 16:34:24 +01:00
while ( list ( $key , $value ) = each ( $array ))
{
print " <option value= \" $key\ " " ;
// Si il faut pr<70> s<EFBFBD> lectionner une valeur
if ( $id && $id == $key )
{
print " selected " ;
}
if ( $key_libelle )
{
print " >[ $key ] $value </option> \n " ;
}
else
{
if ( $value == " - " ) { $value = " " ; }
print " > $value </option> \n " ;
}
}
2004-12-25 20:03:22 +01:00
2005-01-05 16:34:24 +01:00
print " </select> " ;
}
2002-12-22 21:04:24 +01:00
/*
2004-10-23 16:27:26 +02:00
* \brief Renvoie la cha<EFBFBD> ne de caract<EFBFBD> re d<EFBFBD> crivant l ' erreur
2002-12-19 19:55:38 +01:00
*
*/
2004-10-20 23:06:45 +02:00
2004-08-07 20:51:54 +02:00
function error ()
2005-01-05 16:34:24 +01:00
{
return $this -> errorstr ;
}
2004-10-23 16:27:26 +02:00
2002-12-30 16:13:28 +01:00
/*
2004-10-23 23:02:56 +02:00
* \brief Selection de oui / non en caractere ( renvoi yes / no )
* \param name nom du select
* \param value valeur pr<EFBFBD> s<EFBFBD> lectionn<EFBFBD> e
* \param option 0 retourne yes / no , 1 retourne 1 / 0
2002-12-30 16:13:28 +01:00
*/
2004-10-23 16:27:26 +02:00
function selectyesno ( $name , $value = '' , $option = 0 )
2002-12-30 16:13:28 +01:00
{
2004-07-25 19:43:23 +02:00
global $langs ;
2004-10-23 16:27:26 +02:00
$yes = " yes " ; $no = " no " ;
2004-11-24 12:17:27 +01:00
if ( $option )
{
$yes = " 1 " ;
$no = " 0 " ;
}
2004-11-24 11:49:32 +01:00
2004-11-24 12:17:27 +01:00
print '<select name="' . $name . '">' . " \n " ;
2002-12-30 16:13:28 +01:00
2004-11-24 11:49:32 +01:00
if ( $value == 'no' || $value == 0 )
2002-12-30 16:13:28 +01:00
{
2004-11-24 12:17:27 +01:00
print '<option value="' . $yes . '">' . $langs -> trans ( " yes " ) . '</option>' . " \n " ;
print '<option value="' . $no . '" selected>' . $langs -> trans ( " no " ) . '</option>' . " \n " ;
2002-12-30 16:13:28 +01:00
}
else
{
2004-11-24 12:17:27 +01:00
print '<option value="' . $yes . '" selected>' . $langs -> trans ( " yes " ) . '</option>' . " \n " ;
print '<option value="' . $no . '">' . $langs -> trans ( " no " ) . '</option>' . " \n " ;
2002-12-30 16:13:28 +01:00
}
2004-11-24 12:17:27 +01:00
print '</select>' . " \n " ;
2002-12-30 16:13:28 +01:00
}
2004-10-20 23:06:45 +02:00
2003-02-03 14:13:02 +01:00
/*
2004-10-23 23:02:56 +02:00
* \brief Selection de oui / non en chiffre ( renvoi 1 / 0 )
* \param name nom du select
* \param value valeur pr<EFBFBD> s<EFBFBD> lectionn<EFBFBD> e
2003-02-03 14:13:02 +01:00
*/
2004-08-07 20:51:54 +02:00
function selectyesnonum ( $name , $value = '' )
2003-02-03 14:13:02 +01:00
{
2004-10-23 23:52:50 +02:00
$this -> selectyesno ( $name , $value , 1 );
2003-02-03 14:13:02 +01:00
}
2004-10-20 23:06:45 +02:00
2003-02-20 18:40:42 +01:00
/*
2004-10-23 16:27:26 +02:00
* \brief Checkbox
2003-02-20 18:40:42 +01:00
*
*/
2004-08-07 20:51:54 +02:00
function checkbox ( $name , $checked = 0 , $value = 1 )
2005-01-05 16:34:24 +01:00
{
if ( $checked == 1 ){
print " <input type= \" checkbox \" name= \" $name\ " value = \ " $value\ " checked /> \n " ;
} else {
print " <input type= \" checkbox \" name= \" $name\ " value = \ " $value\ " /> \n " ;
2003-02-20 18:40:42 +01:00
}
2005-01-05 16:34:24 +01:00
}
2004-10-23 16:27:26 +02:00
2002-12-19 19:55:38 +01:00
}
?>