';
// List of actions on element
- include_once(DOL_DOCUMENT_ROOT.'/html.formactions.class.php');
+ include_once(DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php');
$formactions=new FormActions($db);
$somethingshown=$formactions->showactions($propal,'propal',$socid);
diff --git a/htdocs/commande/fiche.php b/htdocs/commande/fiche.php
index ae8b55f4fb1..aaa12fd902a 100644
--- a/htdocs/commande/fiche.php
+++ b/htdocs/commande/fiche.php
@@ -2259,7 +2259,7 @@ else
print '
';
// List of actions on element
- include_once(DOL_DOCUMENT_ROOT.'/html.formactions.class.php');
+ include_once(DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php');
$formactions=new FormActions($db);
$somethingshown=$formactions->showactions($commande,'order',$socid);
diff --git a/htdocs/compta/commande/fiche.php b/htdocs/compta/commande/fiche.php
index 6779667564c..7775f208413 100644
--- a/htdocs/compta/commande/fiche.php
+++ b/htdocs/compta/commande/fiche.php
@@ -592,7 +592,7 @@ if ($id > 0 || ! empty($ref))
print '
';
// List of actions on element
- include_once(DOL_DOCUMENT_ROOT.'/html.formactions.class.php');
+ include_once(DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php');
$formactions=new FormActions($db);
$somethingshown=$formactions->showactions($commande,'order',$socid);
diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php
index 75d7e19370e..33a63020cd0 100644
--- a/htdocs/compta/facture.php
+++ b/htdocs/compta/facture.php
@@ -3387,7 +3387,7 @@ else
print ' ';
// List of actions on element
- include_once(DOL_DOCUMENT_ROOT.'/html.formactions.class.php');
+ include_once(DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php');
$formactions=new FormActions($db);
$somethingshown=$formactions->showactions($fac,'invoice',$socid);
diff --git a/htdocs/compta/propal.php b/htdocs/compta/propal.php
index 835c13ac2dc..3858083b65b 100644
--- a/htdocs/compta/propal.php
+++ b/htdocs/compta/propal.php
@@ -546,7 +546,7 @@ if ($id > 0 || ! empty($ref))
print '
';
// List of actions on element
- include_once(DOL_DOCUMENT_ROOT.'/html.formactions.class.php');
+ include_once(DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php');
$formactions=new FormActions($db);
$somethingshown=$formactions->showactions($propal,'propal',$socid);
diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php
new file mode 100644
index 00000000000..0656714ea61
--- /dev/null
+++ b/htdocs/core/class/html.form.class.php
@@ -0,0 +1,3081 @@
+
+ * Copyright (C) 2004-2009 Laurent Destailleur
+ * Copyright (C) 2004 Benoit Mortier
+ * Copyright (C) 2004 Sebastien Di Cintio
+ * Copyright (C) 2004 Eric Seigne
+ * Copyright (C) 2005-2010 Regis Houssin
+ * Copyright (C) 2006 Andre Cianfarani
+ * Copyright (C) 2006 Marc Barilley/Ocebo
+ * Copyright (C) 2007 Franky Van Liedekerke
+ * Copyright (C) 2007 Patrick Raguin
+ *
+ * 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.
+ */
+
+/**
+ * \file htdocs/html.form.class.php
+ * \brief Fichier de la classe des fonctions predefinie de composants html
+ * \version $Id$
+ */
+
+
+/**
+ * \class Form
+ * \brief Classe permettant la generation de composants html
+ * \remarks Only common components must be here.
+ */
+class Form
+{
+ var $db;
+ var $error;
+
+ // Cache arrays
+ var $cache_types_paiements=array();
+ var $cache_conditions_paiements=array();
+
+ var $tva_taux_value;
+ var $tva_taux_libelle;
+
+
+ /**
+ * \brief Constructor
+ * \param DB Database handler
+ */
+ function Form($DB)
+ {
+ $this->db = $DB;
+
+ return 1;
+ }
+
+ /**
+ * \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, ...)
+ */
+ function editfieldkey($text,$htmlname,$preselected,$paramkey,$paramvalue,$perm,$typeofdata='string')
+ {
+ global $langs;
+ $ret='';
+ $ret.='
';
+ $ret.=$langs->trans($text);
+ $ret.='
';
+ if ($_GET['action'] != 'edit'.$htmlname && $perm) $ret.='
';
+ return $ret;
+ }
+
+ /**
+ * \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, ...)
+ */
+ function editfieldval($text,$htmlname,$preselected,$paramkey,$paramvalue,$perm,$typeofdata='string')
+ {
+ global $langs;
+ $ret='';
+ if ($_GET['action'] == 'edit'.$htmlname)
+ {
+ $ret.="\n";
+ $ret.=''."\n";
+ }
+ else
+ {
+ if ($typeofdata == 'email') $ret.=dol_print_email($preselected,0,0,0,0,1);
+ else $ret.=$preselected;
+ }
+ return $ret;
+ }
+
+ /**
+ * \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);
+ }
+
+ /**
+ * \brief Show a text and picto with tooltip on text or picto
+ * \param text Texte to show
+ * \param htmltext Contenu html du tooltip, code en Html / UTF8
+ * \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
+ * \param img Code img du picto
+ * \param i Numero of tooltip
+ * \param width Width of tooltip
+ * \param shiftX Shift of tooltip
+ * \return string Code html du tooltip (texte+picto)
+ * \remarks Use function textwithpicto if you can.
+ */
+ function textwithtooltip($text,$htmltext,$tooltipon=1,$direction=0,$img='',$i=1,$width='200',$shiftX='10')
+ {
+ global $conf;
+
+ if (! $htmltext) return $text;
+
+ $paramfortooltiptext ='';
+ $paramfortooltippicto ='';
+
+ // Sanitize tooltip
+ $htmltext=str_replace("\\","\\\\",$htmltext);
+ $htmltext=str_replace("'","\'",$htmltext);
+ $htmltext=str_replace("'","\'",$htmltext);
+ $htmltext=str_replace("\r","",$htmltext);
+ $htmltext=str_replace(" \n"," ",$htmltext);
+ $htmltext=str_replace("\n","",$htmltext);
+
+ if ($conf->use_javascript_ajax && $tooltipon == 4)
+ {
+ $s = '
';
+ if ($direction > 0)
+ {
+ if ($text)
+ {
+ $s.='
'.$text;
+ if ($direction) $s.=' ';
+ $s.='
';
+ }
+ if ($direction) $s.='
'.$img.'
';
+ }
+ else
+ {
+ if ($direction) $s.='
'.$img.'
';
+ if ($text)
+ {
+ $s.='
';
+ if ($direction) $s.=' ';
+ $s.=$text.'
';
+ }
+ }
+ $s.='
';
+ }
+ return $s;
+ }
+
+ /**
+ * \brief Show a text with a picto and a tooltip on picto
+ * \param text Text to show
+ * \param htmltooltip Content of tooltip
+ * \param direction 1=Icon is after text, -1=Icon is before text
+ * \param type Type of picto (info, help, warning, superadmin...)
+ * \return string HTML code of text, picto, tooltip
+ */
+ function textwithpicto($text,$htmltext,$direction=1,$type='help')
+ {
+ global $conf;
+
+ if ("$type" == "0") $type='info'; // For backward compatibility
+
+ $alt='';
+ // If info or help with no javascript, show only text
+ if (empty($conf->use_javascript_ajax))
+ {
+ if ($type == 'info' || $type == 'help') return $text;
+ else { $alt=$htmltext; $htmltext=''; }
+ }
+ // If info or help with smartphone, show only text
+ if (! empty($conf->browser->phone))
+ {
+ if ($type == 'info' || $type == 'help') return $text;
+ }
+ // Info or help
+ if ($type == 'info') $img=img_help(0,$alt);
+ if ($type == 'help' || $type ==1) $img=img_help(1,$alt);
+ if ($type == 'superadmin') $img=img_redstar($alt);
+ // Warnings
+ if ($type == 'warning') $img=img_warning($alt);
+
+ return $this->textwithtooltip($text,$htmltext,2,$direction,$img);
+ }
+
+
+ /**
+ * \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
+ * \param htmlname Nom de la liste deroulante
+ * \param htmloption Options html sur le select
+ * \todo trier liste sur noms apres traduction plutot que avant
+ */
+ function select_pays($selected='',$htmlname='pays_id',$htmloption='')
+ {
+ global $conf,$langs;
+ $langs->load("dict");
+
+ $sql = "SELECT rowid, code, libelle, active";
+ $sql.= " FROM ".MAIN_DB_PREFIX."c_pays";
+ $sql.= " WHERE active = 1";
+ // \TODO A virer
+ if ($conf->use_javascript_ajax && $conf->global->CODE_DE_TEST)
+ {
+ if (is_numeric($selected))
+ {
+ $sql.= " AND rowid = ".$selected;
+ }
+ else
+ {
+ $sql.= " AND code = '".$selected."'";
+ }
+ }
+ $sql.= " ORDER BY code ASC";
+
+ dol_syslog("Form::select_pays sql=".$sql);
+ $resql=$this->db->query($sql);
+ if ($resql)
+ {
+ // \TODO A virer
+ if ($conf->use_javascript_ajax && $conf->global->CODE_DE_TEST)
+ {
+ $langs->load("companies");
+ $obj = $this->db->fetch_object($resql);
+ $pays_id = $obj->rowid?$obj->rowid:'';
+
+ // On applique un delai d'execution pour le bon fonctionnement
+ $mode_create = substr($htmloption,-9,6);
+ $mode_edit = substr($htmloption,-7,4);
+ $mode_company = substr($htmloption,-10,7);
+ if ($mode_create == 'create')
+ {
+ $htmloption = 'onChange="ac_delay(\'company_save_refresh_create()\',\'500\')"';
+ }
+ else if ($mode_edit == 'edit')
+ {
+ $htmloption = 'onChange="ac_delay(\'company_save_refresh_edit()\',\'500\')"';
+ }
+ else if ($mode_company == 'refresh')
+ {
+ $htmloption = 'onChange="ac_delay(\'company_save_refresh()\',\'500\')"';
+ }
+
+ print '
';
+ if ($obj->rowid == 0)
+ {
+ print '';
+ }
+ else
+ {
+ print '';
+ }
+
+ print ajax_indicator($htmlname,'working');
+ print ajax_autocompleter($pays_id,'pays',DOL_URL_ROOT.'/societe/ajaxcountries.php','');
+ }
+ else
+ {
+ print '';
+ return 0;
+ }
+ }
+ else
+ {
+ dol_print_error($this->db);
+ return 1;
+ }
+ }
+
+
+ /**
+ * \brief Retourne la liste des types de comptes financiers
+ * \param selected Type pre-selectionne
+ * \param htmlname Nom champ formulaire
+ */
+ function select_type_comptes_financiers($selected=1,$htmlname='type')
+ {
+ global $langs;
+ $langs->load("banks");
+
+ $type_available=array(0,1,2);
+
+ print '';
+ }
+
+
+ /**
+ * \brief Return list of social contributions
+ * \param selected Preselected type
+ * \param htmlname Name of field in form
+ * \param useempty Set to 1 if we want an empty value
+ * \param maxlen Max length of text in combo box
+ * \param help Add or not the admin help picto
+ */
+ function select_type_socialcontrib($selected='',$htmlname='actioncode', $useempty=0, $maxlen=40, $help=1)
+ {
+ global $db,$langs,$user,$mysoc;
+
+ $sql = "SELECT c.id, c.libelle as type";
+ $sql.= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c";
+ $sql.= " WHERE active = 1";
+ $sql.= " AND fk_pays = ".$mysoc->pays_id;
+ $sql.= " ORDER BY c.libelle ASC";
+
+ dol_syslog("Form::select_type_socialcontrib sql=".$sql, LOG_DEBUG);
+ $resql=$db->query($sql);
+ if ($resql)
+ {
+ $num = $db->num_rows($resql);
+ if ($num)
+ {
+ print '';
+ if ($user->admin && $help) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionnarySetup"),1);
+ }
+ else
+ {
+ print $langs->trans("ErrorNoSocialContributionForSellerCountry",$mysoc->pays_code);
+ }
+ }
+ else
+ {
+ dol_print_error($db,$db->lasterror());
+ }
+ }
+
+ /**
+ * \brief Return list of types of lines (product or service)
+ * \param selected Preselected type
+ * \param htmlname Name of field in html form
+ * \param showempty Add an empty field
+ * \param hidetext Do not show label before combo box
+ * \param forceall Force to show products and services in combo list, whatever are activated modules
+ */
+ function select_type_of_lines($selected='',$htmlname='type',$showempty=0,$hidetext=0,$forceall=0)
+ {
+ global $db,$langs,$user,$conf;
+
+ // If product & services are enabled or both disabled.
+ if ($forceall || ($conf->produit->enabled && $conf->service->enabled)
+ || (empty($conf->produit->enabled) && empty($conf->service->enabled)))
+ {
+ if (empty($hidetext)) print $langs->trans("Type").': ';
+ print '';
+ //if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionnarySetup"),1);
+ }
+ if (! $forceall && empty($conf->produit->enabled) && $conf->service->enabled)
+ {
+ print '';
+ }
+ if (! $forceall && $conf->produit->enabled && empty($conf->service->enabled))
+ {
+ print '';
+ }
+
+ }
+
+ /**
+ * \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");
+
+ print '';
+ if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionnarySetup"),1);
+ }
+
+ /**
+ * \brief Output html form to select a third party
+ * \param selected Preselected type
+ * \param htmlname Name of field in form
+ * \param filter Optionnal filters criteras
+ * \param showempty Add an empty field
+ * \param showtype Show third party type in combolist (customer, prospect or supplier)
+ * \param forcecombo Force to use combo box
+ */
+ function select_societes($selected='',$htmlname='socid',$filter='',$showempty=0, $showtype=0, $forcecombo=0)
+ {
+ global $conf,$user,$langs;
+
+ // On recherche les societes
+ $sql = "SELECT s.rowid, s.nom, s.client, s.fournisseur, s.code_client, s.code_fournisseur";
+ $sql.= " FROM ".MAIN_DB_PREFIX ."societe as s";
+ if (!$user->rights->societe->client->voir && !$user->societe_id) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
+ $sql.= " WHERE s.entity = ".$conf->entity;
+ if ($filter) $sql.= " AND ".$filter;
+ if (is_numeric($selected) && $conf->use_javascript_ajax && $conf->global->COMPANY_USE_SEARCH_TO_SELECT) $sql.= " AND s.rowid = ".$selected;
+ if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
+ $sql.= " ORDER BY nom ASC";
+
+ dol_syslog("Form::select_societes sql=".$sql);
+ $resql=$this->db->query($sql);
+ if ($resql)
+ {
+ if ($conf->use_javascript_ajax && $conf->global->COMPANY_USE_SEARCH_TO_SELECT && ! $forcecombo)
+ {
+ $socid = 0;
+ if ($selected)
+ {
+ $obj = $this->db->fetch_object($resql);
+ $socid = $obj->rowid?$obj->rowid:'';
+ }
+
+ // 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='';
+
+ print "\n".''."\n";
+ print '
';
+ }
+ else
+ {
+ print '';
+ }
+ }
+ else
+ {
+ dol_print_error($this->db);
+ }
+ }
+
+
+ /**
+ * \brief Return HTML combo list of absolute discounts
+ * \param selected Id remise fixe pre-selectionnee
+ * \param htmlname Nom champ formulaire
+ * \param filter Criteres optionnels de filtre
+ * \param maxvalue Max value for lines that can be selected
+ * \return int Return number of qualifed lines in list
+ */
+ function select_remises($selected='',$htmlname='remise_id',$filter='',$socid, $maxvalue=0)
+ {
+ global $langs,$conf;
+
+ // On recherche les remises
+ $sql = "SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,";
+ $sql.= " re.description, re.fk_facture_source";
+ $sql.= " FROM ".MAIN_DB_PREFIX ."societe_remise_except as re";
+ $sql.= " WHERE fk_soc = ".$socid;
+ if ($filter) $sql.= " AND ".$filter;
+ $sql.= " ORDER BY re.description ASC";
+
+ dol_syslog("Form::select_remises sql=".$sql);
+ $resql=$this->db->query($sql);
+ if ($resql)
+ {
+ print '';
+ return $qualifiedlines;
+ }
+ else
+ {
+ dol_print_error($this->db);
+ return -1;
+ }
+ }
+
+
+ /**
+ * \brief Retourne la liste deroulante des contacts d'une societe donnee
+ * \param socid Id de la societe
+ * \param selected Id contact pre-selectionne
+ * \param htmlname Nom champ formulaire ('none' pour champ non editable)
+ * \param show_empty 0=liste sans valeur nulle, 1=ajoute valeur inconnue
+ * \param exclude Liste des id contacts a exclure
+ * \param limitto Disable answers that are not id in this array list
+ * \return int <0 if KO, Nb of contact in list if OK
+ */
+ function select_contacts($socid,$selected='',$htmlname='contactid',$showempty=0,$exclude='',$limitto='')
+ {
+ // Permettre l'exclusion de contacts
+ if (is_array($exclude))
+ {
+ $excludeContacts = implode("','",$exclude);
+ }
+
+ // 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";
+
+ dol_syslog("Form::select_contacts sql=".$sql);
+ $resql=$this->db->query($sql);
+ if ($resql)
+ {
+ $num=$this->db->num_rows($resql);
+ if ($num == 0) return 0;
+
+ if ($htmlname != 'none') print '';
+ }
+ return $num;
+ }
+ else
+ {
+ dol_print_error($this->db);
+ return -1;
+ }
+ }
+
+
+ /**
+ * \brief Return select list of users
+ * \param selected Id user preselected
+ * \param htmlname Field name in form
+ * \param show_empty 0=liste sans valeur nulle, 1=ajoute valeur inconnue
+ * \param exclude Array list of users id to exclude
+ * \param disabled If select list must be disabled
+ * \param include Array list of users id to include
+ * \param enableonly Array list of users id to be enabled. All other must be disabled
+ */
+ function select_users($selected='',$htmlname='userid',$show_empty=0,$exclude='',$disabled=0,$include='',$enableonly='')
+ {
+ global $conf;
+
+ // Permettre l'exclusion d'utilisateurs
+ if (is_array($exclude)) $excludeUsers = implode("','",$exclude);
+ // Permettre l'inclusion d'utilisateurs
+ if (is_array($include)) $includeUsers = implode("','",$include);
+
+ // On recherche les utilisateurs
+ $sql = "SELECT u.rowid, u.name, u.firstname, u.login FROM";
+ $sql.= " ".MAIN_DB_PREFIX ."user as u";
+ $sql.= " WHERE u.entity IN (0,".$conf->entity.")";
+ if (is_array($exclude) && $excludeUsers) $sql.= " AND u.rowid NOT IN ('".$excludeUsers."')";
+ if (is_array($include) && $includeUsers) $sql.= " AND u.rowid IN ('".$includeUsers."')";
+ $sql.= " ORDER BY u.name ASC";
+
+ dol_syslog("Form::select_users sql=".$sql);
+ $resql=$this->db->query($sql);
+ if ($resql)
+ {
+ print '';
+ }
+ else
+ {
+ dol_print_error($this->db);
+ }
+ }
+
+
+ /**
+ * \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
+ * \param filtertype Filter on product type (''=nofilter, 0=product, 1=service)
+ * \param limit Limit sur le nombre de lignes retournees
+ * \param price_level Level of price to show
+ * \param status -1=Return all products, 0=Products not on sell, 1=Products on sell
+ * \param finished 2=all, 1=finished, 0=raw material
+ */
+ function select_produits($selected='',$htmlname='productid',$filtertype='',$limit=20,$price_level=0,$status=1,$finished=2)
+ {
+ global $langs,$conf;
+
+ if ($conf->global->PRODUIT_USE_SEARCH_TO_SELECT)
+ {
+ 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,'');
+
+ print '
';
+ print '';
+ print '';
+ print '
';
+ }
+ else
+ {
+ print '
';
+ print '
';
+ print $langs->trans("RefOrLabel").':
';
+ print '
';
+ print ajax_indicator($htmlname,'working'); // Indicator is et here
+ print '
';
+ print '
';
+ print '
';
+ print '
';
+ print '
';
+ 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 '
';
+ print '
';
+ }
+ }
+ else
+ {
+ $this->select_produits_do($selected,$htmlname,$filtertype,$limit,$price_level,'',$status,$finished);
+ }
+ }
+
+ /**
+ * \brief Return list of products for a customer
+ * \param selected Preselected product
+ * \param htmlname Name of select html
+ * \param filtertype Filter on product type (''=nofilter, 0=product, 1=service)
+ * \param limit Limite sur le nombre de lignes retournees
+ * \param price_level Level of price to show
+ * \param ajaxkeysearch Filter on product if ajax is used
+ * \param status -1=Return all products, 0=Products not on sell, 1=Products on sell
+ */
+ function select_produits_do($selected='',$htmlname='productid',$filtertype='',$limit=20,$price_level=0,$ajaxkeysearch='',$status=1,$finished=2)
+ {
+ global $langs,$conf,$user,$db;
+
+ $sql = "SELECT ";
+ $sql.= " p.rowid, p.label, p.ref, p.fk_product_type, p.price, p.price_ttc, p.price_base_type, p.duration, p.stock";
+ $sql.= " FROM ".MAIN_DB_PREFIX."product as p ";
+ $sql.= " WHERE p.entity = ".$conf->entity;
+ 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)';
+
+ if($finished == 0)
+ {
+ $sql.= " AND p.finished = ".$finished;
+ }
+ elseif($finished == 1)
+ {
+ $sql.= " AND p.finished = ".$finished;
+ if ($status >= 0) $sql.= " AND p.envente = ".$status;
+ }
+ elseif($status >= 0)
+ {
+ $sql.= " AND p.envente = ".$status;
+ }
+ if (strval($filtertype) != '') $sql.=" AND p.fk_product_type=".$filtertype;
+ if ($ajaxkeysearch && $ajaxkeysearch != '') $sql.=" AND (p.ref like '%".$ajaxkeysearch."%' OR p.label like '%".$ajaxkeysearch."%')";
+ $sql.= $db->order("p.ref");
+ $sql.= $db->plimit($limit);
+
+ dol_syslog("Form::select_produits_do sql=".$sql, LOG_DEBUG);
+ $result=$this->db->query($sql);
+ if (! $result) dol_print_error($this->db);
+
+ // Multilang : on construit une liste des traductions des produits listes
+ if ($conf->global->MAIN_MULTILANGS)
+ {
+ $sqld = "SELECT d.fk_product, d.label";
+ $sqld.= " FROM ".MAIN_DB_PREFIX."product as p";
+ $sqld.= ", ".MAIN_DB_PREFIX."product_lang as d";
+ $sqld.= " WHERE d.fk_product = p.rowid";
+ $sqld.= " AND p.entity = ".$conf->entity;
+ $sqld.= " AND p.envente = 1";
+ $sqld.= " AND d.lang='". $langs->getDefaultLang() ."'";
+ $sqld.= " ORDER BY p.ref";
+
+ dol_syslog("Form::select_produits_do sql=".$sql, LOG_DEBUG);
+ $resultd = $this->db->query($sqld);
+ }
+
+ if ($result)
+ {
+ $num = $this->db->num_rows($result);
+
+ if ($conf->use_javascript_ajax)
+ {
+ if (! $num)
+ {
+ print '
';
+ }
+ else
+ {
+ $return.= ''.$langs->trans("ErrorSupplierCountryIsNotDefined").'';
+ }
+ return $return;
+ }
+
+ if (is_object($societe_vendeuse))
+ {
+ 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;
+ }
+ }
+ 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)
+ {
+ for ($i = 0; $i < $num; $i++)
+ {
+ $obj = $this->db->fetch_object($resql);
+ $txtva[$i] = $obj->taux;
+ $libtva[$i] = $obj->taux.'%';
+ $nprtva[$i] = $obj->recuperableonly;
+ }
+ }
+ else
+ {
+ $return.= ''.$langs->trans("ErrorNoVATRateDefinedForSellerCountry",$code_pays).'';
+ }
+ }
+ else
+ {
+ $return.= ''.$this->db->error().'';
+ }
+
+ // Definition du taux a pre-selectionner (si defaulttx non force et donc vaut -1 ou '')
+ if ($defaulttx < 0 || strlen($defaulttx) == 0)
+ {
+ $defaulttx=get_default_tva($societe_vendeuse,$societe_acheteuse,$taux_produit);
+ $defaultnpr=get_default_npr($societe_vendeuse,$societe_acheteuse,$taux_produit);
+ }
+ // Si taux par defaut n'a pu etre determine, on prend dernier de la liste.
+ // Comme ils sont tries par ordre croissant, dernier = plus eleve = taux courant
+ if ($defaulttx < 0 || strlen($defaulttx) == 0)
+ {
+ $defaulttx = $txtva[sizeof($txtva)-1];
+ }
+
+ $nbdetaux = sizeof($txtva);
+
+ if (sizeof($txtva))
+ {
+ $return.= '';
+
+ for ($i = 0 ; $i < $nbdetaux ; $i++)
+ {
+ //print "xxxxx".$txtva[$i]."-".$nprtva[$i];
+ $return.= '';
+
+ $this->tva_taux_value[$i] = $txtva[$i];
+ $this->tva_taux_libelle[$i] = $libtva[$i];
+ $this->tva_taux_npr[$i] = $nprtva[$i];
+ }
+ $return.= '';
+ }
+
+ return $return;
+ }
+
+
+ /**
+ * Affiche zone de selection de date
+ * Liste deroulante pour les jours, mois, annee et eventuellement heurs et minutes
+ * Les champs sont pre-selectionnes avec:
+ * - 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 ''
+ * - Aucune date (champs vides) si set_time vaut -1 (dans ce cas empty doit valoir 1)
+ * @param set_time Pre-selected date (must be a local PHP server timestamp)
+ * @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
+ * @param form_name Nom du formulaire de provenance. Utilise pour les dates en popup.
+ * @param d 1=Affiche aussi les jours, mois, annees
+ * @param addnowbutton Add a button "Now"
+ * @param nooutput Do not output zone but return it
+ * @return nothing or string if nooutput is 1
+ */
+ function select_date($set_time='', $prefix='re', $h=0, $m=0, $empty=0, $form_name="", $d=1, $addnowbutton=0, $nooutput=0)
+ {
+ global $conf,$langs;
+
+ $retstring='';
+
+ if($prefix=='') $prefix='re';
+ if($h == '') $h=0;
+ if($m == '') $m=0;
+ if($empty == '') $empty=0;
+
+ if (! $set_time && $empty == 0) $set_time = time();
+
+ // Analyse de la date de pre-selection
+ if (preg_match('/^([0-9]+)\-([0-9]+)\-([0-9]+)\s?([0-9]+)?:?([0-9]+)?/',$set_time,$reg))
+ {
+ // 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)
+ {
+ // set_time est un timestamps (0 possible)
+ $syear = dol_print_date($set_time, "%Y");
+ $smonth = dol_print_date($set_time, "%m");
+ $sday = dol_print_date($set_time, "%d");
+ $shour = dol_print_date($set_time, "%H");
+ $smin = dol_print_date($set_time, "%M");
+ }
+ else
+ {
+ // Date est '' ou vaut -1
+ $syear = '';
+ $smonth = '';
+ $sday = '';
+ $shour = '';
+ $smin = '';
+ }
+
+ if ($d)
+ {
+ /*
+ * Affiche date en popup
+ */
+ if ($conf->use_javascript_ajax && $conf->use_popup_calendar)
+ {
+ //print "e".$set_time." t ".$conf->format_date_short;
+ if (strval($set_time) != '' && $set_time != -1)
+ {
+ $formated_date=dol_print_date($set_time,$conf->format_date_short);
+ }
+
+ // Calendrier popup version eldy
+ if ("$conf->use_popup_calendar" == "eldy") // Laisser conf->use_popup_calendar entre quote
+ {
+ // Zone de saisie manuelle de la date
+ $retstring.='';
+
+ // Icone calendrier
+ $retstring.='';
+
+ $retstring.=''."\n";
+ $retstring.=''."\n";
+ $retstring.=''."\n";
+ }
+ else
+ {
+ // Calendrier popup version defaut
+ if ($langs->defaultlang != "")
+ {
+ $retstring.='';
+ }
+ $retstring.='';
+ $retstring.=' ';
+ $retstring.=''."\n";
+ $retstring.=''."\n";
+ $retstring.=''."\n";
+ if ($form_name =="")
+ {
+ $retstring.='';
+ $retstring.='';
+ $retstring.='';
+ }
+ else
+ {
+ $retstring.='';
+ $retstring.='';
+ $retstring.='';
+ }
+ }
+ }
+
+ /*
+ * Affiche date en select
+ */
+ if (! $conf->use_javascript_ajax || ! $conf->use_popup_calendar)
+ {
+ // Jour
+ $retstring.='';
+
+ if ($empty || $set_time == -1)
+ {
+ $retstring.='';
+ }
+
+ for ($day = 1 ; $day <= 31; $day++)
+ {
+ if ($day == $sday)
+ {
+ $retstring.="";
+ }
+
+ $retstring.="";
+
+ $retstring.='';
+ if ($empty || $set_time == -1)
+ {
+ $retstring.='';
+ }
+
+ // Month
+ for ($month = 1 ; $month <= 12 ; $month++)
+ {
+ $retstring.='";
+ }
+ $retstring.="";
+
+ // Year
+ if ($empty || $set_time == -1)
+ {
+ $retstring.='';
+ }
+ else
+ {
+ $retstring.='';
+
+ for ($year = $syear - 5; $year < $syear + 10 ; $year++)
+ {
+ if ($year == $syear)
+ {
+ $retstring.="";
+ }
+ $retstring.="\n";
+ }
+ }
+ }
+
+ if ($d && $h) $retstring.=' ';
+
+ if ($h)
+ {
+ /*
+ * Affiche heure en select
+ */
+ $retstring.='';
+ if ($empty) $retstring.='';
+ for ($hour = 0; $hour < 24; $hour++)
+ {
+ if (strlen($hour) < 2)
+ {
+ $hour = "0" . $hour;
+ }
+ if ($hour == $shour)
+ {
+ $retstring.="";
+ }
+ else
+ {
+ $retstring.="";
+ }
+ }
+ $retstring.="";
+ $retstring.="H\n";
+ }
+
+ if ($m)
+ {
+ /*
+ * Affiche min en select
+ */
+ $retstring.='';
+ if ($empty) $retstring.='';
+ for ($min = 0; $min < 60 ; $min++)
+ {
+ if (strlen($min) < 2)
+ {
+ $min = "0" . $min;
+ }
+ if ($min == $smin)
+ {
+ $retstring.="";
+ }
+ else
+ {
+ $retstring.="";
+ }
+ }
+ $retstring.="";
+ $retstring.="M\n";
+ }
+
+ // 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 = "";
+
+ // 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
+ {
+ $reset_scripts .= 'this.form.elements[\''.$prefix.'day\'].value=formatDate(new Date(), \'d\'); ';
+ $reset_scripts .= 'this.form.elements[\''.$prefix.'month\'].value=formatDate(new Date(), \'M\'); ';
+ $reset_scripts .= 'this.form.elements[\''.$prefix.'year\'].value=formatDate(new Date(), \'yyyy\'); ';
+ }
+ // Generate the hour part
+ if ($h)
+ {
+ $reset_scripts .= 'this.form.elements[\''.$prefix.'hour\'].value=formatDate(new Date(), \'HH\'); ';
+ }
+ // Generate the minute part
+ if ($m)
+ {
+ $reset_scripts .= 'this.form.elements[\''.$prefix.'min\'].value=formatDate(new Date(), \'mm\'); ';
+ }
+ // If reset_scripts is not empty, print the button with the reset_scripts in OnClick
+ if ($reset_scripts)
+ {
+ $retstring.=' ';
+ }
+ }
+
+ if (! empty($nooutput)) return $retstring;
+
+ print $retstring;
+ return;
+ }
+
+ /**
+ * \brief Function to show a form to select a duration on a page
+ * \param prefix prefix
+ * \param iSecond Default preselected duration (number of seconds)
+ * \param disabled Disable the combo box
+ */
+ function select_duration($prefix,$iSecond='',$disabled=0)
+ {
+ if ($iSecond)
+ {
+ require_once(DOL_DOCUMENT_ROOT."/lib/date.lib.php");
+
+ $hourSelected = ConvertSecondToTime($iSecond,'hour');
+ $minSelected = ConvertSecondToTime($iSecond,'min');
+ }
+
+ print '';
+ for ($hour = 0; $hour < 24; $hour++)
+ {
+ print '";
+ }
+ print "";
+ print "H ";
+ print '';
+ for ($min = 0; $min <= 55; $min=$min+5)
+ {
+ print '';
+ }
+ print "";
+ print "M ";
+ }
+
+
+ /**
+ * \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
+ * \return string HTML select string
+ */
+ function selectarray($htmlname, $array, $id='', $show_empty=0, $key_in_label=0, $value_as_key=0, $optionType=0, $option='', $translate=0, $maxlen=0)
+ {
+ global $langs;
+
+ $out='';
+
+ // \TODO Simplify optionType and option (only one should be necessary)
+ if ($optionType == 1 && $option != '')
+ {
+ $out.='';
+ }
+ else
+ {
+ $out.='';
+ }
+
+ if ($show_empty)
+ {
+ $out.=''."\n";
+ }
+
+ if (is_array($array))
+ {
+ while (list($key, $value) = each ($array))
+ {
+ $out.='\n";
+ }
+ }
+
+ $out.="";
+ 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);
+ }
+
+
+ /**
+ * \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
+ */
+ function selectyesno($htmlname,$value='',$option=0)
+ {
+ global $langs;
+
+ $yes="yes"; $no="no";
+
+ if ($option)
+ {
+ $yes="1";
+ $no="0";
+ }
+
+ $resultyesno = ''."\n";
+ if (("$value" == 'yes') || ($value == 1))
+ {
+ $resultyesno .= ''."\n";
+ $resultyesno .= ''."\n";
+ }
+ else
+ {
+ $resultyesno .= ''."\n";
+ $resultyesno .= ''."\n";
+ }
+ $resultyesno .= ''."\n";
+ return $resultyesno;
+ }
+
+
+
+ /**
+ * \brief Retourne la liste des modeles d'export
+ * \param selected Id modele pre-selectionne
+ * \param htmlname Nom de la zone select
+ * \param type Type des modeles recherches
+ * \param useempty Affiche valeur vide dans liste
+ */
+ function select_export_model($selected='',$htmlname='exportmodelid',$type='',$useempty=0)
+ {
+
+ $sql = "SELECT rowid, label";
+ $sql.= " FROM ".MAIN_DB_PREFIX."export_model";
+ $sql.= " WHERE type = '".$type."'";
+ $sql.= " ORDER BY rowid";
+ $result = $this->db->query($sql);
+ if ($result)
+ {
+ print '';
+ if ($useempty)
+ {
+ print '';
+ }
+
+ $num = $this->db->num_rows($result);
+ $i = 0;
+ while ($i < $num)
+ {
+ $obj = $this->db->fetch_object($result);
+ if ($selected == $obj->rowid)
+ {
+ print '';
+ $i++;
+ }
+ print "";
+ }
+ else {
+ dol_print_error($this->db);
+ }
+ }
+
+ /**
+ * \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"));
+
+ $select_week = '';
+ if ($useempty)
+ {
+ $select_week .= '';
+ }
+ foreach ($week as $key => $val)
+ {
+ if ($selected == $key)
+ {
+ $select_week .= '';
+ return $select_week;
+ }
+
+ /**
+ * \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
+ */
+ function select_month($selected='',$htmlname='monthid',$useempty=0)
+ {
+ $month = monthArrayOrSelected(-1); // Get array
+
+ $select_month = '';
+ if ($useempty)
+ {
+ $select_month .= '';
+ }
+ foreach ($month as $key => $val)
+ {
+ if ($selected == $key)
+ {
+ $select_month .= '';
+ return $select_month;
+ }
+
+ /**
+ * \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
+ */
+ 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;
+
+ print '';
+ if($useempty)
+ {
+ if($selected == '')
+ $selected_html = 'selected="true"';
+ print '';
+ }
+ for ($y = $max_year; $y >= $min_year; $y--)
+ {
+ $selected_html='';
+ if ($y == $selected)
+ {
+ $selected_html = 'selected="true"';
+ }
+ print "";
+ }
+ print "\n";
+ }
+
+ /**
+ * \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
+ * \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
+ * \param moreparam More param to ad in nav link url.
+ * \return string Portion HTML avec ref + boutons nav
+ */
+ function showrefnav($object,$paramid,$morehtml='',$shownav=1,$fieldid='rowid',$fieldref='ref',$morehtmlref='',$moreparam='')
+ {
+ $ret='';
+
+ //print "$paramid,$morehtml,$shownav,$fieldid,$fieldref,$morehtmlref,$moreparam";
+ $object->load_previous_next_ref($object->next_prev_filter,$fieldid);
+ $previous_ref = $object->ref_previous?'ref_previous).$moreparam.'">'.img_previous().'':'';
+ $next_ref = $object->ref_next?'ref_next).$moreparam.'">'.img_next().'':'';
+
+ //print "xx".$previous_ref."x".$next_ref;
+ if ($previous_ref || $next_ref || $morehtml) {
+ $ret.='