diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php
index 7ad467eb329..a6147a78791 100644
--- a/htdocs/core/class/html.form.class.php
+++ b/htdocs/core/class/html.form.class.php
@@ -40,1742 +40,1754 @@
*/
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;
-
-
- /**
- * Constructor
- * @param $DB Database handler
- */
- function Form($DB)
- {
- $this->db = $DB;
- }
-
- /**
- * 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 paramvalue Value of parameter
- * @param perm Permission to allow button to edit parameter
- * @param typeofdata Type of data (string by default, email, ...)
- * @return string HTML edit field
- */
- function editfieldkey($text,$htmlname,$preselected,$paramkey,$paramvalue,$perm,$typeofdata='string')
- {
- global $langs;
- $ret='';
- $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, ...)
- * \return string HTML edit field
- */
- 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 = ''."\n";
- $s.= $text;
- $s.= '
'."\n";
- $s.= ''."\n";
- $s.= $htmltext."\n";
- $s.= '
'."\n";
- $s.= ''."\n";
- }
- else
- {
- if ($conf->use_javascript_ajax)
- {
- $htmltext=str_replace('"',""",$htmltext);
- if ($tooltipon==1 || $tooltipon==3)
- {
- $paramfortooltiptext.=' onmouseover="showtip(\''.$htmltext.'\')"';
- $paramfortooltiptext.=' onMouseout="hidetip()"';
- }
- if ($tooltipon==2 || $tooltipon==3)
- {
- $paramfortooltippicto.=' onmouseover="showtip(\''.$htmltext.'\')"';
- $paramfortooltippicto.=' onMouseout="hidetip()"';
- }
- }
-
- $s="";
- $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 Return combo list of activated countries, into language of user
- * \param selected Id or Code or Label of preselected country
- * \param htmlname Name of html select object
- * \param htmloption Options html on select object
- * \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";
- $sql.= " ORDER BY code ASC";
-
- dol_syslog("Form::select_pays sql=".$sql);
- $resql=$this->db->query($sql);
- if ($resql)
- {
- print '';
- $num = $this->db->num_rows($resql);
- $i = 0;
- if ($num)
- {
- $foundselected=false;
- while ($i < $num)
- {
- $obj = $this->db->fetch_object($resql);
- if ($selected && $selected != '-1' &&
- ($selected == $obj->rowid || $selected == $obj->code || $selected == $obj->libelle) )
- {
- $foundselected=true;
- print '';
- }
- else
- {
- print ' ';
- }
- // Si traduction existe, on l'utilise, sinon on prend le libelle par defaut
- 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 ' ';
- $i++;
- }
- }
- 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 '';
- $num = count($type_available);
- $i = 0;
- if ($num)
- {
- while ($i < $num)
- {
- if ($selected == $type_available[$i])
- {
- print ''.$langs->trans("BankType".$type_available[$i]).' ';
- }
- else
- {
- print ''.$langs->trans("BankType".$type_available[$i]).' ';
- }
- $i++;
- }
- }
- print ' ';
- }
-
-
- /**
- * \brief Return list of social contributions.
- * \remarks Use mysoc->pays_id or mysoc->pays_code so they must be defined.
- * \param selected Preselected type
- * \param htmlname Name of field in form
- * \param useempty Set to 1 if we want an empty value
- * \param maxlen Max length of text in combo box
- * \param help Add or not the admin help picto
- */
- function select_type_socialcontrib($selected='',$htmlname='actioncode', $useempty=0, $maxlen=40, $help=1)
- {
- global $db,$langs,$user,$mysoc;
-
- if (empty($mysoc->pays_id) && empty($mysoc->pays_code))
- {
- dol_print_error('','Call to select_type_socialcontrib with mysoc country not yet defined');
- exit;
- }
-
- if (! empty($mysoc->pays_id))
- {
- $sql = "SELECT c.id, c.libelle as type";
- $sql.= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c";
- $sql.= " WHERE c.active = 1";
- $sql.= " AND c.fk_pays = ".$mysoc->pays_id;
- $sql.= " ORDER BY c.libelle ASC";
- }
- else
- {
- $sql = "SELECT c.id, c.libelle as type";
- $sql.= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c, ".MAIN_DB_PREFIX."c_pays as p";
- $sql.= " WHERE c.active = 1 AND c.fk_pays = p.rowid";
- $sql.= " AND p.code = '".$mysoc->pays_code."'";
- $sql.= " ORDER BY c.libelle ASC";
- }
-
- dol_syslog("Form::select_type_socialcontrib sql=".$sql, LOG_DEBUG);
- $resql=$db->query($sql);
- if ($resql)
- {
- $num = $db->num_rows($resql);
- if ($num)
- {
- print '';
- $i = 0;
-
- if ($useempty) print ' ';
- while ($i < $num)
- {
- $obj = $db->fetch_object($resql);
- print 'id == $selected) print ' selected="true"';
- print '>'.dol_trunc($obj->type,$maxlen);
- $i++;
- }
- 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->product->enabled && $conf->service->enabled)
- || (empty($conf->product->enabled) && empty($conf->service->enabled)))
- {
- if (empty($hidetext)) print $langs->trans("Type").': ';
- print '';
- if ($showempty)
- {
- print ' ';
- }
-
- print ''.$langs->trans("Product");
-
- print ' '.$langs->trans("Service");
-
- print ' ';
- //if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionnarySetup"),1);
- }
- if (! $forceall && empty($conf->product->enabled) && $conf->service->enabled)
- {
- print ' ';
- }
- if (! $forceall && $conf->product->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 ($showempty)
- {
- print ' ';
- }
-
- $sql = "SELECT c.code, c.libelle as type FROM ".MAIN_DB_PREFIX."c_type_fees as c";
- $sql.= " ORDER BY lower(c.libelle) ASC";
- $resql=$db->query($sql);
- if ($resql)
- {
- $num = $db->num_rows($resql);
- $i = 0;
-
- while ($i < $num)
- {
- $obj = $db->fetch_object($resql);
- print '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 ' ';
- 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 '';
- if ($showempty) print ' ';
- $num = $this->db->num_rows($resql);
- $i = 0;
- if ($num)
- {
- while ($i < $num)
- {
- $obj = $this->db->fetch_object($resql);
- $label=$obj->nom;
- if ($showtype)
- {
- if ($obj->client || $obj->fournisseur) $label.=' (';
- if ($obj->client == 1 || $obj->client == 3) $label.=$langs->trans("Customer");
- if ($obj->client == 2 || $obj->client == 3) $label.=($obj->client==3?', ':'').$langs->trans("Prospect");
- if ($obj->fournisseur) $label.=($obj->client?', ':'').$langs->trans("Supplier");
- if ($obj->client || $obj->fournisseur) $label.=')';
- }
- if ($selected > 0 && $selected == $obj->rowid)
- {
- print ''.$label.' ';
- }
- else
- {
- print ''.$label.' ';
- }
- $i++;
- }
- }
- 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 '';
- $num = $this->db->num_rows($resql);
-
- $qualifiedlines=$num;
-
- $i = 0;
- if ($num)
- {
- print ' ';
- while ($i < $num)
- {
- $obj = $this->db->fetch_object($resql);
- $desc=dol_trunc($obj->description,40);
- if ($desc=='(CREDIT_NOTE)') $desc=$langs->trans("CreditNote");
- if ($desc=='(DEPOSIT)') $desc=$langs->trans("Deposit");
-
- $selectstring='';
- if ($selected > 0 && $selected == $obj->rowid) $selectstring=' selected="true"';
-
- $disabled='';
- if ($maxvalue && $obj->amount_ttc > $maxvalue)
- {
- $qualifiedlines--;
- $disabled=' disabled="true"';
- }
-
- print ''.$desc.' ('.price($obj->amount_ht).' '.$langs->trans("HT").' - '.price($obj->amount_ttc).' '.$langs->trans("TTC").') ';
- $i++;
- }
- }
- 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 '';
- if ($showempty) print ' ';
- $num = $this->db->num_rows($resql);
- $i = 0;
- if ($num)
- {
- while ($i < $num)
- {
- $obj = $this->db->fetch_object($resql);
- if ($htmlname != 'none')
- {
- $disabled=0;
- if (is_array($limitto) && sizeof($limitto) && ! in_array($obj->rowid,$limitto)) $disabled=1;
- if ($selected && $selected == $obj->rowid)
- {
- print ''.$obj->name.' '.$obj->firstname.' ';
- }
- else
- {
- print ''.$obj->name.' '.$obj->firstname.' ';
- }
- }
- else
- {
- if ($selected == $obj->rowid) print $obj->name.' '.$obj->firstname;
- }
- $i++;
- }
- }
- 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, u.admin";
- $sql.= " FROM ".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 '';
- if ($show_empty) print ' '."\n";
- $num = $this->db->num_rows($resql);
- $i = 0;
- if ($num)
- {
- while ($i < $num)
- {
- $obj = $this->db->fetch_object($resql);
- $disableline=0;
- if (is_array($enableonly) && sizeof($enableonly) && ! in_array($obj->rowid,$enableonly)) $disableline=1;
-
- if ((is_object($selected) && $selected->id == $obj->rowid) || (! is_object($selected) && $selected == $obj->rowid))
- {
- print '';
- }
- else
- {
- print ' ';
- }
- print $obj->name.($obj->name && $obj->firstname?' ':'').$obj->firstname;
- //if ($obj->admin) print ' *';
- if ($conf->global->MAIN_SHOW_LOGIN) print ' ('.$obj->login.')';
- print ' ';
- $i++;
- }
- }
- 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 ''.$langs->trans("RefOrLabel").': ';
- print ' ';
- print '
';
- }
- else
- {
- 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 filterkey Filter on product
- * \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,$filterkey='',$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";
- // Multilang : we add translation
- if ($conf->global->MAIN_MULTILANGS)
- {
- $sql.= ", pl.label as label_translated";
- }
- $sql.= " FROM ".MAIN_DB_PREFIX."product as p";
- // Multilang : we add translation
- if ($conf->global->MAIN_MULTILANGS)
- {
- $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product_lang as pl ON pl.fk_product = p.rowid AND pl.lang='". $langs->getDefaultLang() ."'";
- }
- $sql.= " WHERE p.entity = ".$conf->entity;
- if (empty($user->rights->produit->hidden) && empty($user->rights->service->hidden)) $sql.=' AND p.hidden=0';
- else
- {
- if (empty($user->rights->produit->hidden)) $sql.=' AND (p.hidden=0 OR p.fk_product_type != 0)';
- if (empty($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.tosell = ".$status;
- }
- elseif($status >= 0)
- {
- $sql.= " AND p.tosell = ".$status;
- }
- if (strval($filtertype) != '') $sql.=" AND p.fk_product_type=".$filtertype;
- // Add criteria on ref/label
- if (! empty($conf->global->PRODUCT_DONOTSEARCH_ANYWHERE))
- {
- if ($filterkey && $filterkey != '')
- {
- $sql.=" AND (p.ref like '".$filterkey."%' OR p.label like '".$filterkey."%'";
- if ($conf->global->MAIN_MULTILANGS) $sql.=" OR pl.label like '".$filterkey."%'";
- $sql.=")";
- }
- }
- else
- {
- if ($filterkey && $filterkey != '')
- {
- $sql.=" AND (p.ref like '%".$filterkey."%' OR p.label like '%".$filterkey."%'";
- if ($conf->global->MAIN_MULTILANGS) $sql.=" OR pl.label like '%".$filterkey."%'";
- $sql.=")";
- }
- }
- $sql.= $db->order("p.ref");
- $sql.= $db->plimit($limit);
-
- dol_syslog("Form::select_produits_do search product sql=".$sql, LOG_DEBUG);
- $result=$this->db->query($sql);
- if (! $result) dol_print_error($this->db);
-
- if ($result)
- {
- $num = $this->db->num_rows($result);
-
- if ($conf->use_javascript_ajax)
- {
- if (! $num)
- {
- print '';
- print '-- '.$langs->trans("NoProductMatching").' -- ';
- }
- else
- {
- print 'global->PRODUIT_USE_SEARCH_TO_SELECT) print ' onchange="publish_selvalue(this);"';
- print '>';
- print '-- '.$langs->trans("MatchingProducts").' -- ';
- }
- }
- else
- {
- print '';
- print ' ';
- }
-
- $i = 0;
- while ($num && $i < $num)
- {
- $objp = $this->db->fetch_object($result);
-
- $label=$objp->label;
- if (! empty($objp->label_translated)) $label=$objp->label_translated;
-
- $opt = 'rowid == $selected)?' selected="true"':'';
- 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;"';
- }
- }
- $opt.= '>'.$objp->ref.' - ';
- $opt.= dol_trunc($label,32).' - ';
-
- $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
-
- // Multiprice
- if ($price_level >= 1) // If we need a particular price level (from 1 to 6)
- {
- $sql= "SELECT price, price_ttc, price_base_type ";
- $sql.= "FROM ".MAIN_DB_PREFIX."product_price ";
- $sql.= "WHERE fk_product='".$objp->rowid."'";
- $sql.= " AND price_level=".$price_level;
- $sql.= " ORDER BY date_price";
- $sql.= " DESC limit 1";
-
- dol_syslog("Form::select_produits_do search price for level '.$price_level.' sql=".$sql);
- $result2 = $this->db->query($sql);
- if ($result2)
- {
- $objp2 = $this->db->fetch_object($result2);
- if ($objp2)
- {
- $found=1;
- if ($objp2->price_base_type == 'HT')
- $opt.= price($objp2->price,1).' '.$currencytext.' '.$langs->trans("HT");
- else
- $opt.= price($objp2->price_ttc,1).' '.$currencytext.' '.$langs->trans("TTC");
- }
- }
- else
- {
- dol_print_error($this->db);
- }
- }
-
- // If level no defined or multiprice not found, we used the default price
- if (! $found)
- {
- if ($objp->price_base_type == 'HT')
- $opt.= price($objp->price,1).' '.$currencytext.' '.$langs->trans("HT");
- else
- $opt.= price($objp->price_ttc,1).' '.$currencytext.' '.$langs->trans("TTC");
- }
-
- if ($conf->stock->enabled && isset($objp->stock) && $objp->fk_product_type == 0)
- {
- $opt.= ' - '.$langs->trans("Stock").':'.$objp->stock;
- }
-
- 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]);
- }
-
- $opt.= " \n";
- print $opt;
- $i++;
- }
-
- print ' ';
-
- $this->db->free($result);
- }
- else
- {
- dol_print_error($db);
- }
- }
-
- /**
- * \brief Return list of products for customer in Ajax if Ajax activated or go to select_produits_fournisseurs_do
- * \param socid Id third party
- * \param selected Preselected product
- * \param htmlname Name of HTML Select
- * \param filtertype Filter on product type (''=nofilter, 0=product, 1=service)
- * \param filtre For a SQL filter
- */
- function select_produits_fournisseurs($socid,$selected='',$htmlname='productid',$filtertype='',$filtre)
- {
- global $langs,$conf;
- if ($conf->global->PRODUIT_USE_SEARCH_TO_SELECT)
- {
- print $langs->trans("RefOrLabel").' : ';
- print ajax_updater($htmlname,'keysearch',DOL_URL_ROOT.'/product/ajaxproducts.php','&socid='.$socid.'&type='.$filtertype.'&mode=2','working');
- }
- else
- {
- $this->select_produits_fournisseurs_do($socid,$selected,$htmlname,$filtertype,$filtre,'');
- }
- }
-
- /**
- * \brief Retourne la liste des produits de fournisseurs
- * \param socid Id societe fournisseur (0 pour aucun filtre)
- * \param selected Produit pre-selectionne
- * \param htmlname Nom de la zone select
- * \param filtertype Filter on product type (''=nofilter, 0=product, 1=service)
- * \param filtre Pour filtre sql
- * \param filterkey Filtre des produits si ajax est utilise
- */
- function select_produits_fournisseurs_do($socid,$selected='',$htmlname='productid',$filtertype='',$filtre='',$filterkey='')
- {
- global $langs,$conf;
-
- $langs->load('stocks');
-
- $sql = "SELECT p.rowid, p.label, p.ref, p.price, p.duration,";
- $sql.= " pf.ref_fourn,";
- $sql.= " pfp.rowid as idprodfournprice, pfp.price as fprice, pfp.quantity, pfp.unitprice,";
- $sql.= " s.nom";
- $sql.= " FROM ".MAIN_DB_PREFIX."product as p";
- $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product_fournisseur as pf ON p.rowid = pf.fk_product";
- $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON pf.fk_soc = s.rowid";
- $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product_fournisseur_price as pfp ON pf.rowid = pfp.fk_product_fournisseur";
- $sql.= " WHERE p.entity = ".$conf->entity;
- $sql.= " AND p.tobuy = 1";
- if ($socid) $sql.= " AND pf.fk_soc = ".$socid;
- if (strval($filtertype) != '') $sql.=" AND p.fk_product_type=".$filtertype;
- if (! empty($filtre)) $sql.=" ".$filtre;
- // Add criteria on ref/label
- if (! empty($conf->global->PRODUCT_DONOTSEARCH_ANYWHERE))
- {
- if ($filterkey && $filterkey != '') $sql.=" AND (pf.ref_fourn like '%".$filterkey."%' OR p.ref like '%".$filterkey."%' OR p.label like '%".$filterkey."%')";
- }
- else
- {
- if ($filterkey && $filterkey != '') $sql.=" AND (pf.ref_fourn like '".$filterkey."%' OR p.ref like '".$filterkey."%' OR p.label like '".$filterkey."%')";
- }
- $sql.= " ORDER BY pf.ref_fourn DESC";
-
- dol_syslog("Form::select_produits_fournisseurs_do sql=".$sql,LOG_DEBUG);
- $result=$this->db->query($sql);
- if ($result)
- {
-
- $num = $this->db->num_rows($result);
-
- if ($conf->use_javascript_ajax)
- {
- if (! $num)
- {
- print '';
- print '-- '.$langs->trans("NoProductMatching").' -- ';
- }
- else
- {
- print '';
- print '-- '.$langs->trans("MatchingProducts").' -- ';
- }
- }
- else
- {
- print '';
- if (! $selected) print ' ';
- else print ' ';
- }
-
- $i = 0;
- while ($i < $num)
- {
- $objp = $this->db->fetch_object($result);
-
- $opt = 'idprodfournprice) $opt.= ' selected="true"';
- if ($objp->fprice == '') $opt.=' disabled="disabled"';
- $opt.= '>'.$objp->ref.' ('.$objp->ref_fourn.') - ';
- $opt.= dol_trunc($objp->label,18).' - ';
- if ($objp->fprice != '') // Keep != ''
- {
- $currencytext=$langs->trans("Currency".$conf->monnaie);
- if (strlen($currencytext) > 10) $currencytext=$conf->monnaie; // If text is too long, we use the short code
-
- $opt.= price($objp->fprice);
- $opt.= ' '.$currencytext."/".$objp->quantity;
- if ($objp->quantity == 1)
- {
- $opt.= strtolower($langs->trans("Unit"));
- }
- else
- {
- $opt.= strtolower($langs->trans("Units"));
- }
- if ($objp->quantity >= 1)
- {
- $opt.=" (";
- $opt.= price($objp->unitprice).' '.$currencytext."/".strtolower($langs->trans("Unit"));
- $opt.=")";
- }
- if ($objp->duration) $opt .= " - ".$objp->duration;
- if (! $socid) $opt .= " - ".dol_trunc($objp->nom,8);
- }
- else
- {
- $opt.= $langs->trans("NoPriceDefinedForThisSupplier");
- }
- $opt .= " \n";
-
- print $opt;
- $i++;
- }
- print ' ';
-
- $this->db->free($result);
- }
- else
- {
- dol_print_error($db);
- }
- }
-
- /**
- * \brief Retourn list of suppliers prices for a product
- * \param productid Id of product
- */
- function select_product_fourn_price($productid,$htmlname='productfournpriceid')
- {
- global $langs,$conf;
-
- $langs->load('stocks');
-
- $sql = "SELECT p.rowid, p.label, p.ref, p.price, p.duration,";
- $sql.= " pf.ref_fourn,";
- $sql.= " pfp.rowid as idprodfournprice, pfp.price as fprice, pfp.quantity, pfp.unitprice,";
- $sql.= " s.nom";
- $sql.= " FROM ".MAIN_DB_PREFIX."product as p";
- $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product_fournisseur as pf ON p.rowid = pf.fk_product";
- $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = pf.fk_soc";
- $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product_fournisseur_price as pfp ON pf.rowid = pfp.fk_product_fournisseur";
- $sql.= " WHERE p.tobuy = 1";
- $sql.= " AND s.fournisseur = 1";
- $sql.= " AND p.rowid = ".$productid;
- $sql.= " ORDER BY s.nom, pf.ref_fourn DESC";
-
- dol_syslog("Form::select_product_fourn_price sql=".$sql,LOG_DEBUG);
- $result=$this->db->query($sql);
-
- if ($result)
- {
- $num = $this->db->num_rows($result);
-
- $form = '';
-
- if (! $num)
- {
- $form.= '-- '.$langs->trans("NoSupplierPriceDefinedForThisProduct").' -- ';
- }
- else
- {
- $form.= ' ';
-
- $i = 0;
- while ($i < $num)
- {
- $objp = $this->db->fetch_object($result);
-
- $opt = ''.$objp->nom.' - '.$objp->ref_fourn.' - ';
-
- if ($objp->quantity == 1)
- {
- $opt.= price($objp->fprice);
- $opt.= $langs->trans("Currency".$conf->monnaie)."/";
- }
-
- $opt.= $objp->quantity.' ';
-
- if ($objp->quantity == 1)
- {
- $opt.= strtolower($langs->trans("Unit"));
- }
- else
- {
- $opt.= strtolower($langs->trans("Units"));
- }
- if ($objp->quantity > 1)
- {
- $opt.=" - ";
- $opt.= price($objp->unitprice).$langs->trans("Currency".$conf->monnaie)."/".strtolower($langs->trans("Unit"));
- }
- if ($objp->duration) $opt .= " - ".$objp->duration;
- $opt .= " \n";
-
- $form.= $opt;
- $i++;
- }
- $form.= ' ';
-
- $this->db->free($result);
- }
- return $form;
- }
- else
- {
- dol_print_error($db);
- }
- }
-
- /**
- * \brief Retourne la liste deroulante des adresses
- * \param selected Id contact pre-selectionn
- * \param htmlname Nom champ formulaire
- */
- function select_address($selected='', $socid, $htmlname='address_id',$showempty=0)
- {
- // On recherche les utilisateurs
- $sql = "SELECT a.rowid, a.label";
- $sql .= " FROM ".MAIN_DB_PREFIX ."societe_address as a";
- $sql .= " WHERE a.fk_soc = ".$socid;
- $sql .= " ORDER BY a.label ASC";
-
- dol_syslog("Form::select_address sql=".$sql);
- $resql=$this->db->query($sql);
- if ($resql)
- {
- print '';
- if ($showempty) print ' ';
- $num = $this->db->num_rows($resql);
- $i = 0;
- if ($num)
- {
- while ($i < $num)
- {
- $obj = $this->db->fetch_object($resql);
-
- if ($selected && $selected == $obj->rowid)
- {
- print ''.$obj->label.' ';
- }
- else
- {
- print ''.$obj->label.' ';
- }
- $i++;
- }
- }
- print ' ';
- return $num;
- }
- else
- {
- dol_print_error($this->db);
- }
- }
-
-
- /**
- * \brief Charge dans cache la liste des conditions de paiements possibles
- * \return int Nb lignes chargees, 0 si deja chargees, <0 si ko
- */
- function load_cache_conditions_paiements()
- {
- global $langs;
-
- if (sizeof($this->cache_conditions_paiements)) return 0; // Cache deja charge
-
- $sql = "SELECT rowid, code, libelle";
- $sql.= " FROM ".MAIN_DB_PREFIX."cond_reglement";
- $sql.= " WHERE active=1";
- $sql.= " ORDER BY sortorder";
- dol_syslog('Form::load_cache_conditions_paiements sql='.$sql,LOG_DEBUG);
- $resql = $this->db->query($sql);
- if ($resql)
- {
- $num = $this->db->num_rows($resql);
- $i = 0;
- while ($i < $num)
- {
- $obj = $this->db->fetch_object($resql);
-
- // Si traduction existe, on l'utilise, sinon on prend le libelle par defaut
- $libelle=($langs->trans("PaymentConditionShort".$obj->code)!=("PaymentConditionShort".$obj->code)?$langs->trans("PaymentConditionShort".$obj->code):($obj->libelle!='-'?$obj->libelle:''));
- $this->cache_conditions_paiements[$obj->rowid]['code'] =$obj->code;
- $this->cache_conditions_paiements[$obj->rowid]['label']=$libelle;
- $i++;
- }
- return 1;
- }
- else {
- dol_print_error($this->db);
- return -1;
- }
- }
-
- /**
- * \brief Charge dans cache la liste des types de paiements possibles
- * \return int Nb lignes chargees, 0 si deja chargees, <0 si ko
- */
- function load_cache_types_paiements()
- {
- global $langs;
-
- if (sizeof($this->cache_types_paiements)) return 0; // Cache deja charge
-
- $sql = "SELECT id, code, libelle, type";
- $sql.= " FROM ".MAIN_DB_PREFIX."c_paiement";
- $sql.= " WHERE active > 0";
- $sql.= " ORDER BY id";
- dol_syslog('Form::load_cache_types_paiements sql='.$sql,LOG_DEBUG);
- $resql = $this->db->query($sql);
- if ($resql)
- {
- $num = $this->db->num_rows($resql);
- $i = 0;
- while ($i < $num)
- {
- $obj = $this->db->fetch_object($resql);
-
- // Si traduction existe, on l'utilise, sinon on prend le libelle par defaut
- $libelle=($langs->trans("PaymentTypeShort".$obj->code)!=("PaymentTypeShort".$obj->code)?$langs->trans("PaymentTypeShort".$obj->code):($obj->libelle!='-'?$obj->libelle:''));
- $this->cache_types_paiements[$obj->id]['code'] =$obj->code;
- $this->cache_types_paiements[$obj->id]['label']=$libelle;
- $this->cache_types_paiements[$obj->id]['type'] =$obj->type;
- $i++;
- }
- return $num;
- }
- else {
- dol_print_error($this->db);
- return -1;
- }
- }
-
-
- /**
- * \brief Retourne la liste des types de paiements possibles
- * \param selected Id du type de paiement pre-selectionne
- * \param htmlname Nom de la zone select
- * \param filtertype Pour filtre
- * \param addempty Ajoute entree vide
- */
- function select_conditions_paiements($selected='',$htmlname='condid',$filtertype=-1,$addempty=0)
- {
- global $langs,$user;
-
- $this->load_cache_conditions_paiements();
-
- print '';
- if ($addempty) print ' ';
- foreach($this->cache_conditions_paiements as $id => $arrayconditions)
- {
- if ($selected == $id)
- {
- print '';
- }
- else
- {
- print ' ';
- }
- print $arrayconditions['label'];
- print ' ';
- }
- print ' ';
- if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionnarySetup"),1);
- }
-
-
- /**
- * \brief Retourne la liste des modes de paiements possibles
- * \param selected Id du mode de paiement pre-selectionne
- * \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;
-
- dol_syslog("Form::select_type_paiements $selected, $htmlname, $filtertype, $format",LOG_DEBUG);
-
- $filterarray=array();
- if ($filtertype == 'CRDT') $filterarray=array(0,2);
- elseif ($filtertype == 'DBIT') $filterarray=array(1,2);
- elseif ($filtertype != '' && $filtertype != '-1') $filterarray=explode(',',$filtertype);
-
- $this->load_cache_types_paiements();
-
- print '';
- if ($empty) print ' ';
- foreach($this->cache_types_paiements as $id => $arraytypes)
- {
- // On passe si on a demande de filtrer sur des modes de paiments particuliers
- if (sizeof($filterarray) && ! in_array($arraytypes['type'],$filterarray)) continue;
-
- if ($format == 0) print '';
- if ($format == 0) $value=$arraytypes['label'];
- if ($format == 1) $value=$arraytypes['code'];
- if ($format == 2) $value=$arraytypes['label'];
- print $value?$value:' ';
- print ' ';
- }
- print ' ';
- if ($user->admin && ! $noadmininfo) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionnarySetup"),1);
- }
-
- /**
- * \brief Selection HT ou TTC
- * \param selected Id pre-selectionne
- * \param htmlname Nom de la zone select
- */
- function select_PriceBaseType($selected='',$htmlname='price_base_type')
- {
- print $this->load_PriceBaseType($selected,$htmlname);
- }
-
- /**
- * \brief Selection HT ou TTC
- * \param selected Id pre-selectionne
- * \param htmlname Nom de la zone select
- */
- function load_PriceBaseType($selected='',$htmlname='price_base_type')
- {
- global $langs;
-
- $return='';
-
- $return.= '';
- $options = array(
+ var $db;
+ var $error;
+
+ // Cache arrays
+ var $cache_types_paiements=array();
+ var $cache_conditions_paiements=array();
+
+ var $tva_taux_value;
+ var $tva_taux_libelle;
+
+
+ /**
+ * Constructor
+ * @param $DB Database handler
+ */
+ function Form($DB)
+ {
+ $this->db = $DB;
+ }
+
+ /**
+ * 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 paramvalue Value of parameter
+ * @param perm Permission to allow button to edit parameter
+ * @param typeofdata Type of data (string by default, email, ...)
+ * @return string HTML edit field
+ */
+ function editfieldkey($text,$htmlname,$preselected,$paramkey,$paramvalue,$perm,$typeofdata='string')
+ {
+ global $langs;
+ $ret='';
+ $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, ...)
+ * \return string HTML edit field
+ */
+ 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 = ''."\n";
+ $s.= $text;
+ $s.= '
'."\n";
+ $s.= ''."\n";
+ $s.= $htmltext."\n";
+ $s.= '
'."\n";
+ $s.= ''."\n";
+ }
+ else
+ {
+ if ($conf->use_javascript_ajax)
+ {
+ $htmltext=str_replace('"',""",$htmltext);
+ if ($tooltipon==1 || $tooltipon==3)
+ {
+ $paramfortooltiptext.=' onmouseover="showtip(\''.$htmltext.'\')"';
+ $paramfortooltiptext.=' onMouseout="hidetip()"';
+ }
+ if ($tooltipon==2 || $tooltipon==3)
+ {
+ $paramfortooltippicto.=' onmouseover="showtip(\''.$htmltext.'\')"';
+ $paramfortooltippicto.=' onMouseout="hidetip()"';
+ }
+ }
+
+ $s="";
+ $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 Return combo list of activated countries, into language of user
+ * \param selected Id or Code or Label of preselected country
+ * \param htmlname Name of html select object
+ * \param htmloption Options html on select object
+ * \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";
+ $sql.= " ORDER BY code ASC";
+
+ dol_syslog("Form::select_pays sql=".$sql);
+ $resql=$this->db->query($sql);
+ if ($resql)
+ {
+ print '';
+ $num = $this->db->num_rows($resql);
+ $i = 0;
+ if ($num)
+ {
+ $foundselected=false;
+ while ($i < $num)
+ {
+ $obj = $this->db->fetch_object($resql);
+ if ($selected && $selected != '-1' &&
+ ($selected == $obj->rowid || $selected == $obj->code || $selected == $obj->libelle) )
+ {
+ $foundselected=true;
+ print '';
+ }
+ else
+ {
+ print ' ';
+ }
+ // Si traduction existe, on l'utilise, sinon on prend le libelle par defaut
+ 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 ' ';
+ $i++;
+ }
+ }
+ 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 '';
+ $num = count($type_available);
+ $i = 0;
+ if ($num)
+ {
+ while ($i < $num)
+ {
+ if ($selected == $type_available[$i])
+ {
+ print ''.$langs->trans("BankType".$type_available[$i]).' ';
+ }
+ else
+ {
+ print ''.$langs->trans("BankType".$type_available[$i]).' ';
+ }
+ $i++;
+ }
+ }
+ print ' ';
+ }
+
+
+ /**
+ * \brief Return list of social contributions.
+ * \remarks Use mysoc->pays_id or mysoc->pays_code so they must be defined.
+ * \param selected Preselected type
+ * \param htmlname Name of field in form
+ * \param useempty Set to 1 if we want an empty value
+ * \param maxlen Max length of text in combo box
+ * \param help Add or not the admin help picto
+ */
+ function select_type_socialcontrib($selected='',$htmlname='actioncode', $useempty=0, $maxlen=40, $help=1)
+ {
+ global $db,$langs,$user,$mysoc;
+
+ if (empty($mysoc->pays_id) && empty($mysoc->pays_code))
+ {
+ dol_print_error('','Call to select_type_socialcontrib with mysoc country not yet defined');
+ exit;
+ }
+
+ if (! empty($mysoc->pays_id))
+ {
+ $sql = "SELECT c.id, c.libelle as type";
+ $sql.= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c";
+ $sql.= " WHERE c.active = 1";
+ $sql.= " AND c.fk_pays = ".$mysoc->pays_id;
+ $sql.= " ORDER BY c.libelle ASC";
+ }
+ else
+ {
+ $sql = "SELECT c.id, c.libelle as type";
+ $sql.= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c, ".MAIN_DB_PREFIX."c_pays as p";
+ $sql.= " WHERE c.active = 1 AND c.fk_pays = p.rowid";
+ $sql.= " AND p.code = '".$mysoc->pays_code."'";
+ $sql.= " ORDER BY c.libelle ASC";
+ }
+
+ dol_syslog("Form::select_type_socialcontrib sql=".$sql, LOG_DEBUG);
+ $resql=$db->query($sql);
+ if ($resql)
+ {
+ $num = $db->num_rows($resql);
+ if ($num)
+ {
+ print '';
+ $i = 0;
+
+ if ($useempty) print ' ';
+ while ($i < $num)
+ {
+ $obj = $db->fetch_object($resql);
+ print 'id == $selected) print ' selected="true"';
+ print '>'.dol_trunc($obj->type,$maxlen);
+ $i++;
+ }
+ 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->product->enabled && $conf->service->enabled)
+ || (empty($conf->product->enabled) && empty($conf->service->enabled)))
+ {
+ if (empty($hidetext)) print $langs->trans("Type").': ';
+ print '';
+ if ($showempty)
+ {
+ print ' ';
+ }
+
+ print ''.$langs->trans("Product");
+
+ print ' '.$langs->trans("Service");
+
+ print ' ';
+ //if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionnarySetup"),1);
+ }
+ if (! $forceall && empty($conf->product->enabled) && $conf->service->enabled)
+ {
+ print ' ';
+ }
+ if (! $forceall && $conf->product->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 ($showempty)
+ {
+ print ' ';
+ }
+
+ $sql = "SELECT c.code, c.libelle as type FROM ".MAIN_DB_PREFIX."c_type_fees as c";
+ $sql.= " ORDER BY lower(c.libelle) ASC";
+ $resql=$db->query($sql);
+ if ($resql)
+ {
+ $num = $db->num_rows($resql);
+ $i = 0;
+
+ while ($i < $num)
+ {
+ $obj = $db->fetch_object($resql);
+ print '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 ' ';
+ 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 '';
+ if ($showempty) print ' ';
+ $num = $this->db->num_rows($resql);
+ $i = 0;
+ if ($num)
+ {
+ while ($i < $num)
+ {
+ $obj = $this->db->fetch_object($resql);
+ $label=$obj->nom;
+ if ($showtype)
+ {
+ if ($obj->client || $obj->fournisseur) $label.=' (';
+ if ($obj->client == 1 || $obj->client == 3) $label.=$langs->trans("Customer");
+ if ($obj->client == 2 || $obj->client == 3) $label.=($obj->client==3?', ':'').$langs->trans("Prospect");
+ if ($obj->fournisseur) $label.=($obj->client?', ':'').$langs->trans("Supplier");
+ if ($obj->client || $obj->fournisseur) $label.=')';
+ }
+ if ($selected > 0 && $selected == $obj->rowid)
+ {
+ print ''.$label.' ';
+ }
+ else
+ {
+ print ''.$label.' ';
+ }
+ $i++;
+ }
+ }
+ 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 '';
+ $num = $this->db->num_rows($resql);
+
+ $qualifiedlines=$num;
+
+ $i = 0;
+ if ($num)
+ {
+ print ' ';
+ while ($i < $num)
+ {
+ $obj = $this->db->fetch_object($resql);
+ $desc=dol_trunc($obj->description,40);
+ if ($desc=='(CREDIT_NOTE)') $desc=$langs->trans("CreditNote");
+ if ($desc=='(DEPOSIT)') $desc=$langs->trans("Deposit");
+
+ $selectstring='';
+ if ($selected > 0 && $selected == $obj->rowid) $selectstring=' selected="true"';
+
+ $disabled='';
+ if ($maxvalue && $obj->amount_ttc > $maxvalue)
+ {
+ $qualifiedlines--;
+ $disabled=' disabled="true"';
+ }
+
+ print ''.$desc.' ('.price($obj->amount_ht).' '.$langs->trans("HT").' - '.price($obj->amount_ttc).' '.$langs->trans("TTC").') ';
+ $i++;
+ }
+ }
+ 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 '';
+ if ($showempty) print ' ';
+ $num = $this->db->num_rows($resql);
+ $i = 0;
+ if ($num)
+ {
+ while ($i < $num)
+ {
+ $obj = $this->db->fetch_object($resql);
+ if ($htmlname != 'none')
+ {
+ $disabled=0;
+ if (is_array($limitto) && sizeof($limitto) && ! in_array($obj->rowid,$limitto)) $disabled=1;
+ if ($selected && $selected == $obj->rowid)
+ {
+ print ''.$obj->name.' '.$obj->firstname.' ';
+ }
+ else
+ {
+ print ''.$obj->name.' '.$obj->firstname.' ';
+ }
+ }
+ else
+ {
+ if ($selected == $obj->rowid) print $obj->name.' '.$obj->firstname;
+ }
+ $i++;
+ }
+ }
+ 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, u.admin";
+ $sql.= " FROM ".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 '';
+ if ($show_empty) print ' '."\n";
+ $num = $this->db->num_rows($resql);
+ $i = 0;
+ if ($num)
+ {
+ while ($i < $num)
+ {
+ $obj = $this->db->fetch_object($resql);
+ $disableline=0;
+ if (is_array($enableonly) && sizeof($enableonly) && ! in_array($obj->rowid,$enableonly)) $disableline=1;
+
+ if ((is_object($selected) && $selected->id == $obj->rowid) || (! is_object($selected) && $selected == $obj->rowid))
+ {
+ print '';
+ }
+ else
+ {
+ print ' ';
+ }
+ print $obj->name.($obj->name && $obj->firstname?' ':'').$obj->firstname;
+ //if ($obj->admin) print ' *';
+ if ($conf->global->MAIN_SHOW_LOGIN) print ' ('.$obj->login.')';
+ print ' ';
+ $i++;
+ }
+ }
+ 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 seletc field (must be unique in page)
+ * \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('',$htmlname,DOL_URL_ROOT.'/product/ajaxproducts.php','&price_level='.$price_level.'&type='.$filtertype.'&mode=1&status='.$status.'&finished='.$finished,'');
+
+ print '';
+ print ''.$langs->trans("RefOrLabel").': ';
+ print ' ';
+ print '
';
+ }
+ else
+ {
+ 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 filterkey Filter on product
+ * \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,$filterkey='',$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";
+ // Multilang : we add translation
+ if ($conf->global->MAIN_MULTILANGS)
+ {
+ $sql.= ", pl.label as label_translated";
+ }
+ $sql.= " FROM ".MAIN_DB_PREFIX."product as p";
+ // Multilang : we add translation
+ if ($conf->global->MAIN_MULTILANGS)
+ {
+ $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product_lang as pl ON pl.fk_product = p.rowid AND pl.lang='". $langs->getDefaultLang() ."'";
+ }
+ $sql.= " WHERE p.entity = ".$conf->entity;
+ if (empty($user->rights->produit->hidden) && empty($user->rights->service->hidden)) $sql.=' AND p.hidden=0';
+ else
+ {
+ if (empty($user->rights->produit->hidden)) $sql.=' AND (p.hidden=0 OR p.fk_product_type != 0)';
+ if (empty($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.tosell = ".$status;
+ }
+ elseif($status >= 0)
+ {
+ $sql.= " AND p.tosell = ".$status;
+ }
+ if (strval($filtertype) != '') $sql.=" AND p.fk_product_type=".$filtertype;
+ // Add criteria on ref/label
+ if (! empty($conf->global->PRODUCT_DONOTSEARCH_ANYWHERE))
+ {
+ if ($filterkey && $filterkey != '')
+ {
+ $sql.=" AND (p.ref like '".$filterkey."%' OR p.label like '".$filterkey."%'";
+ if ($conf->global->MAIN_MULTILANGS) $sql.=" OR pl.label like '".$filterkey."%'";
+ $sql.=")";
+ }
+ }
+ else
+ {
+ if ($filterkey && $filterkey != '')
+ {
+ $sql.=" AND (p.ref like '%".$filterkey."%' OR p.label like '%".$filterkey."%'";
+ if ($conf->global->MAIN_MULTILANGS) $sql.=" OR pl.label like '%".$filterkey."%'";
+ $sql.=")";
+ }
+ }
+ $sql.= $db->order("p.ref");
+ $sql.= $db->plimit($limit);
+
+
+ // Build output string
+ $outselect='';
+ $outjson='';
+
+ dol_syslog("Form::select_produits_do search product sql=".$sql, LOG_DEBUG);
+ $result=$this->db->query($sql);
+ if ($result)
+ {
+ $num = $this->db->num_rows($result);
+
+ $outselect.='use_javascript_ajax && $num && $conf->global->PRODUIT_USE_SEARCH_TO_SELECT) $outselect.=' onchange="publish_selvalue(this);"';
+ $outselect.='>';
+
+ if ($conf->use_javascript_ajax)
+ {
+ if (! $num)
+ {
+ $outselect.='-- '.$langs->trans("NoProductMatching").' -- ';
+ }
+ else
+ {
+ $outselect.='-- '.$langs->trans("MatchingProducts").' -- ';
+ }
+ }
+ else
+ {
+ $outselect.=' ';
+ }
+
+ $i = 0;
+ while ($num && $i < $num)
+ {
+ $objp = $this->db->fetch_object($result);
+
+ $label=$objp->label;
+ if (! empty($objp->label_translated)) $label=$objp->label_translated;
+
+ $opt = 'rowid == $selected)?' selected="true"':'';
+ 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;"';
+ }
+ }
+ $opt.= '>'.$objp->ref.' - ';
+ $opt.= dol_trunc($label,32).' - ';
+
+ $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
+
+ // Multiprice
+ if ($price_level >= 1) // If we need a particular price level (from 1 to 6)
+ {
+ $sql= "SELECT price, price_ttc, price_base_type ";
+ $sql.= "FROM ".MAIN_DB_PREFIX."product_price ";
+ $sql.= "WHERE fk_product='".$objp->rowid."'";
+ $sql.= " AND price_level=".$price_level;
+ $sql.= " ORDER BY date_price";
+ $sql.= " DESC limit 1";
+
+ dol_syslog("Form::select_produits_do search price for level '.$price_level.' sql=".$sql);
+ $result2 = $this->db->query($sql);
+ if ($result2)
+ {
+ $objp2 = $this->db->fetch_object($result2);
+ if ($objp2)
+ {
+ $found=1;
+ if ($objp2->price_base_type == 'HT')
+ $opt.= price($objp2->price,1).' '.$currencytext.' '.$langs->trans("HT");
+ else
+ $opt.= price($objp2->price_ttc,1).' '.$currencytext.' '.$langs->trans("TTC");
+ }
+ }
+ else
+ {
+ dol_print_error($this->db);
+ }
+ }
+
+ // If level no defined or multiprice not found, we used the default price
+ if (! $found)
+ {
+ if ($objp->price_base_type == 'HT')
+ $opt.= price($objp->price,1).' '.$currencytext.' '.$langs->trans("HT");
+ else
+ $opt.= price($objp->price_ttc,1).' '.$currencytext.' '.$langs->trans("TTC");
+ }
+
+ if ($conf->stock->enabled && isset($objp->stock) && $objp->fk_product_type == 0)
+ {
+ $opt.= ' - '.$langs->trans("Stock").':'.$objp->stock;
+ }
+
+ 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]);
+ }
+
+ $opt.= " \n";
+ $outselect.=$opt;
+ $i++;
+ }
+
+ $outselect.=' ';
+
+ $this->db->free($result);
+
+ print $outselect;
+ }
+ else
+ {
+ dol_print_error($db);
+ }
+ }
+
+ /**
+ * \brief Return list of products for customer in Ajax if Ajax activated or go to select_produits_fournisseurs_do
+ * \param socid Id third party
+ * \param selected Preselected product
+ * \param htmlname Name of HTML Select
+ * \param filtertype Filter on product type (''=nofilter, 0=product, 1=service)
+ * \param filtre For a SQL filter
+ */
+ function select_produits_fournisseurs($socid,$selected='',$htmlname='productid',$filtertype='',$filtre)
+ {
+ global $langs,$conf;
+ if ($conf->global->PRODUIT_USE_SEARCH_TO_SELECT)
+ {
+ print $langs->trans("RefOrLabel").' : ';
+ print ajax_updater($htmlname,'keysearch',DOL_URL_ROOT.'/product/ajaxproducts.php','&socid='.$socid.'&type='.$filtertype.'&mode=2','working');
+ }
+ else
+ {
+ $this->select_produits_fournisseurs_do($socid,$selected,$htmlname,$filtertype,$filtre,'');
+ }
+ }
+
+ /**
+ * \brief Retourne la liste des produits de fournisseurs
+ * \param socid Id societe fournisseur (0 pour aucun filtre)
+ * \param selected Produit pre-selectionne
+ * \param htmlname Nom de la zone select
+ * \param filtertype Filter on product type (''=nofilter, 0=product, 1=service)
+ * \param filtre Pour filtre sql
+ * \param filterkey Filtre des produits si ajax est utilise
+ */
+ function select_produits_fournisseurs_do($socid,$selected='',$htmlname='productid',$filtertype='',$filtre='',$filterkey='')
+ {
+ global $langs,$conf;
+
+ $langs->load('stocks');
+
+ $sql = "SELECT p.rowid, p.label, p.ref, p.price, p.duration,";
+ $sql.= " pf.ref_fourn,";
+ $sql.= " pfp.rowid as idprodfournprice, pfp.price as fprice, pfp.quantity, pfp.unitprice,";
+ $sql.= " s.nom";
+ $sql.= " FROM ".MAIN_DB_PREFIX."product as p";
+ $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product_fournisseur as pf ON p.rowid = pf.fk_product";
+ $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON pf.fk_soc = s.rowid";
+ $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product_fournisseur_price as pfp ON pf.rowid = pfp.fk_product_fournisseur";
+ $sql.= " WHERE p.entity = ".$conf->entity;
+ $sql.= " AND p.tobuy = 1";
+ if ($socid) $sql.= " AND pf.fk_soc = ".$socid;
+ if (strval($filtertype) != '') $sql.=" AND p.fk_product_type=".$filtertype;
+ if (! empty($filtre)) $sql.=" ".$filtre;
+ // Add criteria on ref/label
+ if (! empty($conf->global->PRODUCT_DONOTSEARCH_ANYWHERE))
+ {
+ if ($filterkey && $filterkey != '') $sql.=" AND (pf.ref_fourn like '%".$filterkey."%' OR p.ref like '%".$filterkey."%' OR p.label like '%".$filterkey."%')";
+ }
+ else
+ {
+ if ($filterkey && $filterkey != '') $sql.=" AND (pf.ref_fourn like '".$filterkey."%' OR p.ref like '".$filterkey."%' OR p.label like '".$filterkey."%')";
+ }
+ $sql.= " ORDER BY pf.ref_fourn DESC";
+
+ // Build output string
+ $outselect='';
+ $outjson='';
+
+ dol_syslog("Form::select_produits_fournisseurs_do sql=".$sql,LOG_DEBUG);
+ $result=$this->db->query($sql);
+ if ($result)
+ {
+
+ $num = $this->db->num_rows($result);
+
+ $outselect.='use_javascript_ajax && $num) $outselect.=' onchange="publish_selvalue(this);"';
+ $outselect.='>';
+
+ if ($conf->use_javascript_ajax)
+ {
+ if (! $num)
+ {
+ $outselect.='-- '.$langs->trans("NoProductMatching").' -- ';
+ }
+ else
+ {
+ $outselect.='-- '.$langs->trans("MatchingProducts").' -- ';
+ }
+ }
+ else
+ {
+ if (! $selected) $outselect.=' ';
+ else $outselect.=' ';
+ }
+
+ $i = 0;
+ while ($i < $num)
+ {
+ $objp = $this->db->fetch_object($result);
+
+ $opt = 'idprodfournprice) $opt.= ' selected="true"';
+ if ($objp->fprice == '') $opt.=' disabled="disabled"';
+ $opt.= '>'.$objp->ref.' ('.$objp->ref_fourn.') - ';
+ $opt.= dol_trunc($objp->label,18).' - ';
+ if ($objp->fprice != '') // Keep != ''
+ {
+ $currencytext=$langs->trans("Currency".$conf->monnaie);
+ if (strlen($currencytext) > 10) $currencytext=$conf->monnaie; // If text is too long, we use the short code
+
+ $opt.= price($objp->fprice);
+ $opt.= ' '.$currencytext."/".$objp->quantity;
+ if ($objp->quantity == 1)
+ {
+ $opt.= strtolower($langs->trans("Unit"));
+ }
+ else
+ {
+ $opt.= strtolower($langs->trans("Units"));
+ }
+ if ($objp->quantity >= 1)
+ {
+ $opt.=" (";
+ $opt.= price($objp->unitprice).' '.$currencytext."/".strtolower($langs->trans("Unit"));
+ $opt.=")";
+ }
+ if ($objp->duration) $opt .= " - ".$objp->duration;
+ if (! $socid) $opt .= " - ".dol_trunc($objp->nom,8);
+ }
+ else
+ {
+ $opt.= $langs->trans("NoPriceDefinedForThisSupplier");
+ }
+ $opt .= " \n";
+
+ $outselect.=$opt;
+
+ $i++;
+ }
+ $outselect.=' ';
+
+ $this->db->free($result);
+
+ print $outselect;
+ }
+ else
+ {
+ dol_print_error($db);
+ }
+ }
+
+ /**
+ * \brief Retourn list of suppliers prices for a product
+ * \param productid Id of product
+ */
+ function select_product_fourn_price($productid,$htmlname='productfournpriceid')
+ {
+ global $langs,$conf;
+
+ $langs->load('stocks');
+
+ $sql = "SELECT p.rowid, p.label, p.ref, p.price, p.duration,";
+ $sql.= " pf.ref_fourn,";
+ $sql.= " pfp.rowid as idprodfournprice, pfp.price as fprice, pfp.quantity, pfp.unitprice,";
+ $sql.= " s.nom";
+ $sql.= " FROM ".MAIN_DB_PREFIX."product as p";
+ $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product_fournisseur as pf ON p.rowid = pf.fk_product";
+ $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = pf.fk_soc";
+ $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product_fournisseur_price as pfp ON pf.rowid = pfp.fk_product_fournisseur";
+ $sql.= " WHERE p.tobuy = 1";
+ $sql.= " AND s.fournisseur = 1";
+ $sql.= " AND p.rowid = ".$productid;
+ $sql.= " ORDER BY s.nom, pf.ref_fourn DESC";
+
+ dol_syslog("Form::select_product_fourn_price sql=".$sql,LOG_DEBUG);
+ $result=$this->db->query($sql);
+
+ if ($result)
+ {
+ $num = $this->db->num_rows($result);
+
+ $form = '';
+
+ if (! $num)
+ {
+ $form.= '-- '.$langs->trans("NoSupplierPriceDefinedForThisProduct").' -- ';
+ }
+ else
+ {
+ $form.= ' ';
+
+ $i = 0;
+ while ($i < $num)
+ {
+ $objp = $this->db->fetch_object($result);
+
+ $opt = ''.$objp->nom.' - '.$objp->ref_fourn.' - ';
+
+ if ($objp->quantity == 1)
+ {
+ $opt.= price($objp->fprice);
+ $opt.= $langs->trans("Currency".$conf->monnaie)."/";
+ }
+
+ $opt.= $objp->quantity.' ';
+
+ if ($objp->quantity == 1)
+ {
+ $opt.= strtolower($langs->trans("Unit"));
+ }
+ else
+ {
+ $opt.= strtolower($langs->trans("Units"));
+ }
+ if ($objp->quantity > 1)
+ {
+ $opt.=" - ";
+ $opt.= price($objp->unitprice).$langs->trans("Currency".$conf->monnaie)."/".strtolower($langs->trans("Unit"));
+ }
+ if ($objp->duration) $opt .= " - ".$objp->duration;
+ $opt .= " \n";
+
+ $form.= $opt;
+ $i++;
+ }
+ $form.= ' ';
+
+ $this->db->free($result);
+ }
+ return $form;
+ }
+ else
+ {
+ dol_print_error($db);
+ }
+ }
+
+ /**
+ * \brief Retourne la liste deroulante des adresses
+ * \param selected Id contact pre-selectionn
+ * \param htmlname Nom champ formulaire
+ */
+ function select_address($selected='', $socid, $htmlname='address_id',$showempty=0)
+ {
+ // On recherche les utilisateurs
+ $sql = "SELECT a.rowid, a.label";
+ $sql .= " FROM ".MAIN_DB_PREFIX ."societe_address as a";
+ $sql .= " WHERE a.fk_soc = ".$socid;
+ $sql .= " ORDER BY a.label ASC";
+
+ dol_syslog("Form::select_address sql=".$sql);
+ $resql=$this->db->query($sql);
+ if ($resql)
+ {
+ print '';
+ if ($showempty) print ' ';
+ $num = $this->db->num_rows($resql);
+ $i = 0;
+ if ($num)
+ {
+ while ($i < $num)
+ {
+ $obj = $this->db->fetch_object($resql);
+
+ if ($selected && $selected == $obj->rowid)
+ {
+ print ''.$obj->label.' ';
+ }
+ else
+ {
+ print ''.$obj->label.' ';
+ }
+ $i++;
+ }
+ }
+ print ' ';
+ return $num;
+ }
+ else
+ {
+ dol_print_error($this->db);
+ }
+ }
+
+
+ /**
+ * \brief Charge dans cache la liste des conditions de paiements possibles
+ * \return int Nb lignes chargees, 0 si deja chargees, <0 si ko
+ */
+ function load_cache_conditions_paiements()
+ {
+ global $langs;
+
+ if (sizeof($this->cache_conditions_paiements)) return 0; // Cache deja charge
+
+ $sql = "SELECT rowid, code, libelle";
+ $sql.= " FROM ".MAIN_DB_PREFIX."cond_reglement";
+ $sql.= " WHERE active=1";
+ $sql.= " ORDER BY sortorder";
+ dol_syslog('Form::load_cache_conditions_paiements sql='.$sql,LOG_DEBUG);
+ $resql = $this->db->query($sql);
+ if ($resql)
+ {
+ $num = $this->db->num_rows($resql);
+ $i = 0;
+ while ($i < $num)
+ {
+ $obj = $this->db->fetch_object($resql);
+
+ // Si traduction existe, on l'utilise, sinon on prend le libelle par defaut
+ $libelle=($langs->trans("PaymentConditionShort".$obj->code)!=("PaymentConditionShort".$obj->code)?$langs->trans("PaymentConditionShort".$obj->code):($obj->libelle!='-'?$obj->libelle:''));
+ $this->cache_conditions_paiements[$obj->rowid]['code'] =$obj->code;
+ $this->cache_conditions_paiements[$obj->rowid]['label']=$libelle;
+ $i++;
+ }
+ return 1;
+ }
+ else {
+ dol_print_error($this->db);
+ return -1;
+ }
+ }
+
+ /**
+ * \brief Charge dans cache la liste des types de paiements possibles
+ * \return int Nb lignes chargees, 0 si deja chargees, <0 si ko
+ */
+ function load_cache_types_paiements()
+ {
+ global $langs;
+
+ if (sizeof($this->cache_types_paiements)) return 0; // Cache deja charge
+
+ $sql = "SELECT id, code, libelle, type";
+ $sql.= " FROM ".MAIN_DB_PREFIX."c_paiement";
+ $sql.= " WHERE active > 0";
+ $sql.= " ORDER BY id";
+ dol_syslog('Form::load_cache_types_paiements sql='.$sql,LOG_DEBUG);
+ $resql = $this->db->query($sql);
+ if ($resql)
+ {
+ $num = $this->db->num_rows($resql);
+ $i = 0;
+ while ($i < $num)
+ {
+ $obj = $this->db->fetch_object($resql);
+
+ // Si traduction existe, on l'utilise, sinon on prend le libelle par defaut
+ $libelle=($langs->trans("PaymentTypeShort".$obj->code)!=("PaymentTypeShort".$obj->code)?$langs->trans("PaymentTypeShort".$obj->code):($obj->libelle!='-'?$obj->libelle:''));
+ $this->cache_types_paiements[$obj->id]['code'] =$obj->code;
+ $this->cache_types_paiements[$obj->id]['label']=$libelle;
+ $this->cache_types_paiements[$obj->id]['type'] =$obj->type;
+ $i++;
+ }
+ return $num;
+ }
+ else {
+ dol_print_error($this->db);
+ return -1;
+ }
+ }
+
+
+ /**
+ * \brief Retourne la liste des types de paiements possibles
+ * \param selected Id du type de paiement pre-selectionne
+ * \param htmlname Nom de la zone select
+ * \param filtertype Pour filtre
+ * \param addempty Ajoute entree vide
+ */
+ function select_conditions_paiements($selected='',$htmlname='condid',$filtertype=-1,$addempty=0)
+ {
+ global $langs,$user;
+
+ $this->load_cache_conditions_paiements();
+
+ print '';
+ if ($addempty) print ' ';
+ foreach($this->cache_conditions_paiements as $id => $arrayconditions)
+ {
+ if ($selected == $id)
+ {
+ print '';
+ }
+ else
+ {
+ print ' ';
+ }
+ print $arrayconditions['label'];
+ print ' ';
+ }
+ print ' ';
+ if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionnarySetup"),1);
+ }
+
+
+ /**
+ * \brief Retourne la liste des modes de paiements possibles
+ * \param selected Id du mode de paiement pre-selectionne
+ * \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;
+
+ dol_syslog("Form::select_type_paiements $selected, $htmlname, $filtertype, $format",LOG_DEBUG);
+
+ $filterarray=array();
+ if ($filtertype == 'CRDT') $filterarray=array(0,2);
+ elseif ($filtertype == 'DBIT') $filterarray=array(1,2);
+ elseif ($filtertype != '' && $filtertype != '-1') $filterarray=explode(',',$filtertype);
+
+ $this->load_cache_types_paiements();
+
+ print '';
+ if ($empty) print ' ';
+ foreach($this->cache_types_paiements as $id => $arraytypes)
+ {
+ // On passe si on a demande de filtrer sur des modes de paiments particuliers
+ if (sizeof($filterarray) && ! in_array($arraytypes['type'],$filterarray)) continue;
+
+ if ($format == 0) print '';
+ if ($format == 0) $value=$arraytypes['label'];
+ if ($format == 1) $value=$arraytypes['code'];
+ if ($format == 2) $value=$arraytypes['label'];
+ print $value?$value:' ';
+ print ' ';
+ }
+ print ' ';
+ if ($user->admin && ! $noadmininfo) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionnarySetup"),1);
+ }
+
+ /**
+ * \brief Selection HT ou TTC
+ * \param selected Id pre-selectionne
+ * \param htmlname Nom de la zone select
+ */
+ function select_PriceBaseType($selected='',$htmlname='price_base_type')
+ {
+ print $this->load_PriceBaseType($selected,$htmlname);
+ }
+
+ /**
+ * \brief Selection HT ou TTC
+ * \param selected Id pre-selectionne
+ * \param htmlname Nom de la zone select
+ */
+ function load_PriceBaseType($selected='',$htmlname='price_base_type')
+ {
+ global $langs;
+
+ $return='';
+
+ $return.= '';
+ $options = array(
'HT'=>$langs->trans("HT"),
'TTC'=>$langs->trans("TTC")
- );
- foreach($options as $id => $value)
- {
- if ($selected == $id)
- {
- $return.= ''.$value;
- }
- else
- {
- $return.= ' '.$value;
- }
- $return.= ' ';
- }
- $return.= ' ';
+ );
+ foreach($options as $id => $value)
+ {
+ if ($selected == $id)
+ {
+ $return.= ''.$value;
+ }
+ else
+ {
+ $return.= ' '.$value;
+ }
+ $return.= ' ';
+ }
+ $return.= ' ';
- return $return;
- }
+ return $return;
+ }
- /**
- * \brief Retourne la liste deroulante des differents etats d'une propal.
- * Les valeurs de la liste sont les id de la table c_propalst
- * \param selected etat pre-selectionne
- */
- function select_propal_statut($selected='')
- {
- $sql = "SELECT id, code, label, active FROM ".MAIN_DB_PREFIX."c_propalst";
- $sql .= " WHERE active = 1";
+ /**
+ * \brief Retourne la liste deroulante des differents etats d'une propal.
+ * Les valeurs de la liste sont les id de la table c_propalst
+ * \param selected etat pre-selectionne
+ */
+ function select_propal_statut($selected='')
+ {
+ $sql = "SELECT id, code, label, active FROM ".MAIN_DB_PREFIX."c_propalst";
+ $sql .= " WHERE active = 1";
- dol_syslog("Form::select_propal_statut sql=".$sql);
- $resql=$this->db->query($sql);
- if ($resql)
- {
- print '';
- print ' ';
- $num = $this->db->num_rows($resql);
- $i = 0;
- if ($num)
- {
- while ($i < $num)
- {
- $obj = $this->db->fetch_object($resql);
- if ($selected == $obj->id)
- {
- print '';
- }
- else
- {
- print ' ';
- }
- print $obj->label;
- print ' ';
- $i++;
- }
- }
- print ' ';
- }
- else
- {
- dol_print_error($this->db);
- }
- }
+ dol_syslog("Form::select_propal_statut sql=".$sql);
+ $resql=$this->db->query($sql);
+ if ($resql)
+ {
+ print '';
+ print ' ';
+ $num = $this->db->num_rows($resql);
+ $i = 0;
+ if ($num)
+ {
+ while ($i < $num)
+ {
+ $obj = $this->db->fetch_object($resql);
+ if ($selected == $obj->id)
+ {
+ print '';
+ }
+ else
+ {
+ print ' ';
+ }
+ print $obj->label;
+ print ' ';
+ $i++;
+ }
+ }
+ print ' ';
+ }
+ else
+ {
+ dol_print_error($this->db);
+ }
+ }
- /**
- * \brief Retourne la liste des comptes
- * \param selected Id compte pre-selectionne
- * \param htmlname Nom de la zone select
- * \param statut Statut des comptes recherches (0=open, 1=closed)
- * \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)
- {
- global $langs, $conf;
+ /**
+ * \brief Retourne la liste des comptes
+ * \param selected Id compte pre-selectionne
+ * \param htmlname Nom de la zone select
+ * \param statut Statut des comptes recherches (0=open, 1=closed)
+ * \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)
+ {
+ global $langs, $conf;
- $langs->load("admin");
+ $langs->load("admin");
- $sql = "SELECT rowid, label, bank";
- $sql.= " FROM ".MAIN_DB_PREFIX."bank_account";
- $sql.= " WHERE clos = '".$statut."'";
- $sql.= " AND entity = ".$conf->entity;
- if ($filtre) $sql.=" AND ".$filtre;
- $sql.= " ORDER BY rowid";
+ $sql = "SELECT rowid, label, bank";
+ $sql.= " FROM ".MAIN_DB_PREFIX."bank_account";
+ $sql.= " WHERE clos = '".$statut."'";
+ $sql.= " AND entity = ".$conf->entity;
+ if ($filtre) $sql.=" AND ".$filtre;
+ $sql.= " ORDER BY rowid";
- dol_syslog("Form::select_comptes sql=".$sql);
- $result = $this->db->query($sql);
- if ($result)
- {
- $num = $this->db->num_rows($result);
- $i = 0;
- if ($num)
- {
- print '';
- if ($useempty)
- {
- print ' ';
- }
+ dol_syslog("Form::select_comptes sql=".$sql);
+ $result = $this->db->query($sql);
+ if ($result)
+ {
+ $num = $this->db->num_rows($result);
+ $i = 0;
+ if ($num)
+ {
+ print '';
+ if ($useempty)
+ {
+ print ' ';
+ }
- while ($i < $num)
- {
- $obj = $this->db->fetch_object($result);
- if ($selected == $obj->rowid)
- {
- print '';
- }
- else
- {
- print ' ';
- }
- print $obj->label;
- print ' ';
- $i++;
- }
- print " ";
- }
- else
- {
- print $langs->trans("NoActiveBankAccountDefined");
- }
- }
- else {
- dol_print_error($this->db);
- }
- }
+ while ($i < $num)
+ {
+ $obj = $this->db->fetch_object($result);
+ if ($selected == $obj->rowid)
+ {
+ print '';
+ }
+ else
+ {
+ print ' ';
+ }
+ print $obj->label;
+ print ' ';
+ $i++;
+ }
+ print " ";
+ }
+ else
+ {
+ print $langs->trans("NoActiveBankAccountDefined");
+ }
+ }
+ else {
+ dol_print_error($this->db);
+ }
+ }
- /**
- * \brief Retourne la liste des categories du type choisi
- * \param type Type de categories (0=produit, 1=fournisseur, 2=client)
- * \param selected Id categorie preselectionnee
- * \param select_name Nom formulaire HTML
- */
- function select_all_categories($type,$selected='',$select_name="",$maxlength=64)
- {
- global $langs;
- $langs->load("categories");
+ /**
+ * \brief Retourne la liste des categories du type choisi
+ * \param type Type de categories (0=produit, 1=fournisseur, 2=client)
+ * \param selected Id categorie preselectionnee
+ * \param select_name Nom formulaire HTML
+ */
+ function select_all_categories($type,$selected='',$select_name="",$maxlength=64)
+ {
+ global $langs;
+ $langs->load("categories");
- if ($select_name=="") $select_name="catMere";
+ if ($select_name=="") $select_name="catMere";
- $cat = new Categorie($this->db);
- $cate_arbo = $cat->get_full_arbo($type);
+ $cat = new Categorie($this->db);
+ $cate_arbo = $cat->get_full_arbo($type);
- $output = '';
- if (is_array($cate_arbo))
- {
- if (! sizeof($cate_arbo)) $output.= ''.$langs->trans("NoCategoriesDefined").' ';
- else
- {
- $output.= ' ';
- foreach($cate_arbo as $key => $value)
- {
- if ($cate_arbo[$key]['id'] == $selected)
- {
- $add = 'selected="true" ';
- }
- else
- {
- $add = '';
- }
- $output.= ''.dol_trunc($cate_arbo[$key]['fulllabel'],$maxlength,'middle').' ';
- }
- }
- }
- $output.= ' ';
- $output.= "\n";
- return $output;
- }
+ $output = '';
+ if (is_array($cate_arbo))
+ {
+ if (! sizeof($cate_arbo)) $output.= ''.$langs->trans("NoCategoriesDefined").' ';
+ else
+ {
+ $output.= ' ';
+ foreach($cate_arbo as $key => $value)
+ {
+ if ($cate_arbo[$key]['id'] == $selected)
+ {
+ $add = 'selected="true" ';
+ }
+ else
+ {
+ $add = '';
+ }
+ $output.= ''.dol_trunc($cate_arbo[$key]['fulllabel'],$maxlength,'middle').' ';
+ }
+ }
+ }
+ $output.= ' ';
+ $output.= "\n";
+ return $output;
+ }
- /**
- * Show a confirmation HTML form or AJAX popup
- * @param page Url of page to call if confirmation is OK
- * @param title title
- * @param question question
- * @param action action
- * @param formquestion an array with forms complementary inputs
- * @param selectedchoice "" or "no" or "yes"
- * @param useajax 0=No, 1=Yes, 2=Yes but submit page with &confirm=no if choice is No
- * @return string 'ajax' if a confirm ajax popup is shown, 'html' if it's an html form
- */
- function form_confirm($page, $title, $question, $action, $formquestion='', $selectedchoice="", $useajax=0)
- {
- global $langs,$conf;
+ /**
+ * Show a confirmation HTML form or AJAX popup
+ * @param page Url of page to call if confirmation is OK
+ * @param title title
+ * @param question question
+ * @param action action
+ * @param formquestion an array with forms complementary inputs
+ * @param selectedchoice "" or "no" or "yes"
+ * @param useajax 0=No, 1=Yes, 2=Yes but submit page with &confirm=no if choice is No
+ * @return string 'ajax' if a confirm ajax popup is shown, 'html' if it's an html form
+ */
+ function form_confirm($page, $title, $question, $action, $formquestion='', $selectedchoice="", $useajax=0)
+ {
+ global $langs,$conf;
- $more='';
- if ($formquestion)
- {
- $more.=''."\n";
- $more.=''."\n";
- $more.=' '."\n";
- }
+ $more='';
+ if ($formquestion)
+ {
+ $more.=''."\n";
+ $more.=''."\n";
+ $more.=' '."\n";
+ }
- print "\n\n";
+ print "\n\n";
- if ($useajax && $conf->use_javascript_ajax && $conf->global->MAIN_CONFIRM_AJAX)
- {
- $pageyes=$page.'&action='.$action.'&confirm=yes';
- $pageno=($useajax == 2?$page.'&confirm=no':'');
+ if ($useajax && $conf->use_javascript_ajax && $conf->global->MAIN_CONFIRM_AJAX)
+ {
+ $pageyes=$page.'&action='.$action.'&confirm=yes';
+ $pageno=($useajax == 2?$page.'&confirm=no':'');
- // New code using jQuery only
- print '';
- print img_help('','').' '.$more.$question;
- print '
'."\n";
- print '';
- print "\n";
- $ret='ajax';
- }
- else
- {
- print '\n";
- $ret='html';
- }
-
- print "\n";
- return $ret;
- }
-
-
- /**
- * \brief Affiche formulaire de selection de projet
- * \param page Page
- * \param socid Id societe
- * \param selected Id projet pre-selectionne
- * \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 '';
- }
- else
- {
- if ($selected) {
- $projet = new Project($this->db);
- $projet->fetch($selected);
- //print ''.$projet->title.' ';
- print $projet->getNomUrl(0);
- } else {
- print " ";
- }
- }
- }
-
- /**
- * \brief Affiche formulaire de selection de conditions de paiement
- * \param page Page
- * \param selected Id condition pre-selectionne
- * \param htmlname Name of select html field
- * \param addempty Ajoute entree vide
- */
- function form_conditions_reglement($page, $selected='', $htmlname='cond_reglement_id', $addempty=0)
- {
- global $langs;
- if ($htmlname != "none")
- {
- print '';
- }
- else
- {
- if ($selected)
- {
- $this->load_cache_conditions_paiements();
- print $this->cache_conditions_paiements[$selected]['label'];
- } else {
- print " ";
- }
- }
- }
-
-
- /**
- * \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;
-
- if ($htmlname != "none")
- {
- print '';
- }
- else
- {
- if ($selected)
- {
- $this->load_cache_types_paiements();
- print $this->cache_types_paiements[$selected]['label'];
- } else {
- print " ";
- }
- }
- }
-
-
- /**
- * \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
- */
- function form_users($page, $selected='', $htmlname='userid', $exclude='', $include='')
- {
- global $langs;
-
- if ($htmlname != "none")
- {
- print '';
- }
- else
- {
- if ($selected)
- {
- require_once(DOL_DOCUMENT_ROOT ."/user/class/user.class.php");
- //$this->load_cache_contacts();
- //print $this->cache_contacts[$selected];
- $theuser=new User($this->db);
- $theuser->fetch($selected);
- print $theuser->getNomUrl(1);
- } else {
- print " ";
- }
- }
- }
-
-
- /**
- * \brief Affiche formulaire de selection des modes de reglement
- * \param page Page
- * \param selected Id mode pre-selectionne
- * \param htmlname Name of select html field
- */
- function form_modes_reglement($page, $selected='', $htmlname='mode_reglement_id')
- {
- global $langs;
- if ($htmlname != "none")
- {
- print '';
- }
- 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 '';
- }
- else
- {
- if ($selected)
- {
- print $selected;
- }
- else
- {
- print "0";
- }
- }
- }
-
-
- /**
- * \brief Affiche formulaire de selection des contacts
- * \param page Page
- * \param selected Id contact pre-selectionne
- * \param htmlname Nom du formulaire select
- */
- function form_contacts($page, $societe, $selected='', $htmlname='contactidp')
- {
- global $langs;
- if ($htmlname != "none")
- {
- print '';
- }
- else
- {
- if ($selected)
- {
- require_once(DOL_DOCUMENT_ROOT ."/contact/class/contact.class.php");
- //$this->load_cache_contacts();
- //print $this->cache_contacts[$selected];
- $contact=new Contact($this->db);
- $contact->fetch($selected);
- print $contact->getFullName($langs);
- } else {
- print " ";
- }
- }
- }
-
- /**
- * \brief Affiche formulaire de selection de l'adresse
- * \param page Page
- * \param selected Id condition pre-selectionne
- * \param htmlname Nom du formulaire select
- * \param origin Origine de l'appel pour pouvoir creer un retour
- * \param originid Id de l'origine
- */
- function form_address($page, $selected='', $socid, $htmlname='address_id', $origin='', $originid='')
- {
- global $langs,$conf;
- if ($htmlname != "none")
- {
- print '';
- }
- else
- {
- if ($selected)
- {
- require_once(DOL_DOCUMENT_ROOT ."/societe/class/address.class.php");
- $address=new Address($this->db);
- $result=$address->fetch_address($selected);
- print 'socid.'&id='.$address->id.'&action=edit&origin='.$origin.'&originid='.$originid.'>'.$address->label.' ';
- }
- else
- {
- print " ";
- }
- }
- }
-
- /**
- * \brief Retourne la liste des devises, dans la langue de l'utilisateur
- * \param selected code devise pre-selectionne
- * \param htmlname nom de la liste deroulante
- * \todo trier liste sur noms apres traduction plutot que avant
- */
- function select_currency($selected='',$htmlname='currency_id')
- {
- global $conf,$langs,$user;
- $langs->load("dict");
-
- if ($selected=='euro' || $selected=='euros') $selected='EUR'; // Pour compatibilite
-
- $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 '';
- $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 '';
- }
- else
- {
- print ' ';
- }
- if ($obj->code_iso) { print $obj->code_iso . ' - '; }
- // Si traduction existe, on l'utilise, sinon on prend le libelle par defaut
- 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 ' ';
- $i++;
- }
- }
- print ' ';
- if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionnarySetup"),1);
- return 0;
- }
- else {
- dol_print_error($this->db);
- return 1;
- }
- }
-
- /**
- * \brief Output an HTML select vat rate
- * \param name Nom champ html
- * \param selectedrate Forcage du taux tva pre-selectionne. Mettre '' pour aucun forcage.
- * \param societe_vendeuse Objet societe vendeuse
- * \param societe_acheteuse Objet societe acheteuse
- * \param taux_produit Taux par defaut du produit vendu
- * \param info_bits Miscellanous information on line
- * \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.
- */
- function select_tva($name='tauxtva', $selectedrate='', $societe_vendeuse='', $societe_acheteuse='', $taux_produit='', $info_bits=0)
- {
- print $this->load_tva($name, $selectedrate, $societe_vendeuse, $societe_acheteuse, $taux_produit, $info_bits);
- }
-
-
- /**
- * \brief Output an HTML select vat rate
- * \param name Nom champ html
- * \param selectedrate Forcage du taux tva pre-selectionne. Mettre '' pour aucun forcage.
- * \param societe_vendeuse Objet societe vendeuse
- * \param societe_acheteuse Objet societe acheteuse
- * \param idprod Id product
- * \param info_bits Miscellanous information on line
- * \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.
- */
- function load_tva($name='tauxtva', $selectedrate='', $societe_vendeuse='', $societe_acheteuse='', $idprod=0, $info_bits=0)
- {
- global $langs,$conf,$mysoc;
-
- $return='';
-
- $txtva=array();
- $libtva=array();
- $nprtva=array();
-
- // Define defaultnpr and defaultttx
- $defaultnpr=($info_bits & 0x01);
- $defaultnpr=(preg_match('/\*/',$selectedrate) ? 1 : $defaultnpr);
- $defaulttx=str_replace('*','',$selectedrate);
-
- //print $societe_vendeuse."-".$societe_acheteuse;
- if (is_object($societe_vendeuse) && ! $societe_vendeuse->pays_code)
- {
- if ($societe_vendeuse->id == $mysoc->id)
- {
- $return.= ''.$langs->trans("ErrorYourCountryIsNotDefined").'';
- }
- 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,$idprod);
- $defaultnpr=get_default_npr($societe_vendeuse,$societe_acheteuse,$idprod);
- }
- // Si taux par defaut n'a pu etre determine, on prend dernier de la liste.
- // Comme ils sont tries par ordre croissant, dernier = plus eleve = taux courant
- if ($defaulttx < 0 || 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.= ''.vatrate($libtva[$i]);
- $return.= $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 html string but return it
- * @param disabled Disable input fields
- * @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, $disabled=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
- if (! $disabled)
- {
- $retstring.=''.img_object($langs->trans("SelectDate"),'calendar').' ';
- }
-
- $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.="$day";
- }
- else
- {
- $retstring.=" $day";
- }
- $retstring.=" ";
- }
-
- $retstring.=" ";
-
- $retstring.='';
- if ($empty || $set_time == -1)
- {
- $retstring.=' ';
- }
-
- // Month
- for ($month = 1 ; $month <= 12 ; $month++)
- {
- $retstring.='';
- $retstring.=dol_print_date(mktime(12,0,0,$month,1,2000),"%b");
- $retstring.=" ";
- }
- $retstring.=" ";
-
- // Year
- if ($empty || $set_time == -1)
- {
- $retstring.=' ';
- }
- else
- {
- $retstring.='';
-
- for ($year = $syear - 5; $year < $syear + 10 ; $year++)
- {
- if ($year == $syear)
- {
- $retstring.="".$year;
- }
- else
- {
- $retstring.=" ".$year;
- }
- $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.="$hour ";
- }
- else
- {
- $retstring.="$hour ";
- }
- }
- $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.="$min ";
- }
- else
- {
- $retstring.="$min ";
- }
- }
- $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.='';
- $retstring.=$langs->trans("Now");
- //print img_refresh($langs->trans("Now"));
- $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 '".$hour." ";
- }
- print " ";
- print "H ";
- print '';
- for ($min = 0; $min <= 55; $min=$min+5)
- {
- print ''.$min.' ';
- }
- 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 option Valeur de l'option en fonction du type choisi
- * \param translate Traduire la valeur
- * \param maxlen Length maximum for labels
- * \param disabled Html select box is disabled
- * \return string HTML select string
- */
- function selectarray($htmlname, $array, $id='', $show_empty=0, $key_in_label=0, $value_as_key=0, $option='', $translate=0, $maxlen=0, $disabled=0)
- {
- global $langs;
-
- $out='';
-
- $out.='';
-
- if ($show_empty)
- {
- $out.=' '."\n";
- }
-
- if (is_array($array))
- {
- while (list($key, $value) = each ($array))
- {
- $out.='';
-
- if ($key_in_label)
- {
- $newval=($translate?$langs->trans($value):$value);
- $selectOptionValue = $key.' - '.($maxlen?dol_trunc($newval,$maxlen):$newval);
- $out.=$selectOptionValue;
- }
- else
- {
- $newval=($translate?$langs->trans($value):$value);
- $selectOptionValue = ($maxlen?dol_trunc($newval,$maxlen):$newval);
- if ($value == '' || $value == '-') { $selectOptionValue=' '; }
- $out.=$selectOptionValue;
- }
- $out.=" \n";
- }
- }
-
- $out.=" ";
- return $out;
- }
-
- /**
- * Show a select form from an array
- * @deprecated Use selectarray instead
- */
- function select_array($htmlname, $array, $id='', $show_empty=0, $key_in_label=0, $value_as_key=0, $option='', $translate=0, $maxlen=0)
- {
- print $this->selectarray($htmlname, $array, $id, $show_empty, $key_in_label, $value_as_key, $option, $translate, $maxlen);
- }
-
-
- /**
- * \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 .= ''.$langs->trans("Yes").' '."\n";
- $resultyesno .= ''.$langs->trans("No").' '."\n";
- }
- else
- {
- $resultyesno .= ''.$langs->trans("Yes").' '."\n";
- $resultyesno .= ''.$langs->trans("No").' '."\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 '';
- }
- else
- {
- print ' ';
- }
- print $obj->label;
- 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 .= '';
- }
- else
- {
- $select_week .= ' ';
- }
- $select_week .= $val;
- }
- $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 .= '';
- }
- else
- {
- $select_month .= ' ';
- }
- $select_month .= $val;
- }
- $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 "$y";
- print " ";
- }
- print " \n";
- }
-
- /**
- * Return a HTML area with the reference of object and a naviagation bar for a business object
+ print "\n";
+ $ret='ajax';
+ }
+ else
+ {
+ print '\n";
+ $ret='html';
+ }
+
+ print "\n";
+ return $ret;
+ }
+
+
+ /**
+ * \brief Affiche formulaire de selection de projet
+ * \param page Page
+ * \param socid Id societe
+ * \param selected Id projet pre-selectionne
+ * \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 '';
+ }
+ else
+ {
+ if ($selected) {
+ $projet = new Project($this->db);
+ $projet->fetch($selected);
+ //print ''.$projet->title.' ';
+ print $projet->getNomUrl(0);
+ } else {
+ print " ";
+ }
+ }
+ }
+
+ /**
+ * \brief Affiche formulaire de selection de conditions de paiement
+ * \param page Page
+ * \param selected Id condition pre-selectionne
+ * \param htmlname Name of select html field
+ * \param addempty Ajoute entree vide
+ */
+ function form_conditions_reglement($page, $selected='', $htmlname='cond_reglement_id', $addempty=0)
+ {
+ global $langs;
+ if ($htmlname != "none")
+ {
+ print '';
+ }
+ else
+ {
+ if ($selected)
+ {
+ $this->load_cache_conditions_paiements();
+ print $this->cache_conditions_paiements[$selected]['label'];
+ } else {
+ print " ";
+ }
+ }
+ }
+
+
+ /**
+ * \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;
+
+ if ($htmlname != "none")
+ {
+ print '';
+ }
+ else
+ {
+ if ($selected)
+ {
+ $this->load_cache_types_paiements();
+ print $this->cache_types_paiements[$selected]['label'];
+ } else {
+ print " ";
+ }
+ }
+ }
+
+
+ /**
+ * \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
+ */
+ function form_users($page, $selected='', $htmlname='userid', $exclude='', $include='')
+ {
+ global $langs;
+
+ if ($htmlname != "none")
+ {
+ print '';
+ }
+ else
+ {
+ if ($selected)
+ {
+ require_once(DOL_DOCUMENT_ROOT ."/user/class/user.class.php");
+ //$this->load_cache_contacts();
+ //print $this->cache_contacts[$selected];
+ $theuser=new User($this->db);
+ $theuser->fetch($selected);
+ print $theuser->getNomUrl(1);
+ } else {
+ print " ";
+ }
+ }
+ }
+
+
+ /**
+ * \brief Affiche formulaire de selection des modes de reglement
+ * \param page Page
+ * \param selected Id mode pre-selectionne
+ * \param htmlname Name of select html field
+ */
+ function form_modes_reglement($page, $selected='', $htmlname='mode_reglement_id')
+ {
+ global $langs;
+ if ($htmlname != "none")
+ {
+ print '';
+ }
+ 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 '';
+ }
+ else
+ {
+ if ($selected)
+ {
+ print $selected;
+ }
+ else
+ {
+ print "0";
+ }
+ }
+ }
+
+
+ /**
+ * \brief Affiche formulaire de selection des contacts
+ * \param page Page
+ * \param selected Id contact pre-selectionne
+ * \param htmlname Nom du formulaire select
+ */
+ function form_contacts($page, $societe, $selected='', $htmlname='contactidp')
+ {
+ global $langs;
+ if ($htmlname != "none")
+ {
+ print '';
+ }
+ else
+ {
+ if ($selected)
+ {
+ require_once(DOL_DOCUMENT_ROOT ."/contact/class/contact.class.php");
+ //$this->load_cache_contacts();
+ //print $this->cache_contacts[$selected];
+ $contact=new Contact($this->db);
+ $contact->fetch($selected);
+ print $contact->getFullName($langs);
+ } else {
+ print " ";
+ }
+ }
+ }
+
+ /**
+ * \brief Affiche formulaire de selection de l'adresse
+ * \param page Page
+ * \param selected Id condition pre-selectionne
+ * \param htmlname Nom du formulaire select
+ * \param origin Origine de l'appel pour pouvoir creer un retour
+ * \param originid Id de l'origine
+ */
+ function form_address($page, $selected='', $socid, $htmlname='address_id', $origin='', $originid='')
+ {
+ global $langs,$conf;
+ if ($htmlname != "none")
+ {
+ print '';
+ }
+ else
+ {
+ if ($selected)
+ {
+ require_once(DOL_DOCUMENT_ROOT ."/societe/class/address.class.php");
+ $address=new Address($this->db);
+ $result=$address->fetch_address($selected);
+ print 'socid.'&id='.$address->id.'&action=edit&origin='.$origin.'&originid='.$originid.'>'.$address->label.' ';
+ }
+ else
+ {
+ print " ";
+ }
+ }
+ }
+
+ /**
+ * \brief Retourne la liste des devises, dans la langue de l'utilisateur
+ * \param selected code devise pre-selectionne
+ * \param htmlname nom de la liste deroulante
+ * \todo trier liste sur noms apres traduction plutot que avant
+ */
+ function select_currency($selected='',$htmlname='currency_id')
+ {
+ global $conf,$langs,$user;
+ $langs->load("dict");
+
+ if ($selected=='euro' || $selected=='euros') $selected='EUR'; // Pour compatibilite
+
+ $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 '';
+ $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 '';
+ }
+ else
+ {
+ print ' ';
+ }
+ if ($obj->code_iso) { print $obj->code_iso . ' - '; }
+ // Si traduction existe, on l'utilise, sinon on prend le libelle par defaut
+ 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 ' ';
+ $i++;
+ }
+ }
+ print ' ';
+ if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionnarySetup"),1);
+ return 0;
+ }
+ else {
+ dol_print_error($this->db);
+ return 1;
+ }
+ }
+
+ /**
+ * \brief Output an HTML select vat rate
+ * \param name Nom champ html
+ * \param selectedrate Forcage du taux tva pre-selectionne. Mettre '' pour aucun forcage.
+ * \param societe_vendeuse Objet societe vendeuse
+ * \param societe_acheteuse Objet societe acheteuse
+ * \param taux_produit Taux par defaut du produit vendu
+ * \param info_bits Miscellanous information on line
+ * \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.
+ */
+ function select_tva($name='tauxtva', $selectedrate='', $societe_vendeuse='', $societe_acheteuse='', $taux_produit='', $info_bits=0)
+ {
+ print $this->load_tva($name, $selectedrate, $societe_vendeuse, $societe_acheteuse, $taux_produit, $info_bits);
+ }
+
+
+ /**
+ * \brief Output an HTML select vat rate
+ * \param name Nom champ html
+ * \param selectedrate Forcage du taux tva pre-selectionne. Mettre '' pour aucun forcage.
+ * \param societe_vendeuse Objet societe vendeuse
+ * \param societe_acheteuse Objet societe acheteuse
+ * \param idprod Id product
+ * \param info_bits Miscellanous information on line
+ * \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.
+ */
+ function load_tva($name='tauxtva', $selectedrate='', $societe_vendeuse='', $societe_acheteuse='', $idprod=0, $info_bits=0)
+ {
+ global $langs,$conf,$mysoc;
+
+ $return='';
+
+ $txtva=array();
+ $libtva=array();
+ $nprtva=array();
+
+ // Define defaultnpr and defaultttx
+ $defaultnpr=($info_bits & 0x01);
+ $defaultnpr=(preg_match('/\*/',$selectedrate) ? 1 : $defaultnpr);
+ $defaulttx=str_replace('*','',$selectedrate);
+
+ //print $societe_vendeuse."-".$societe_acheteuse;
+ if (is_object($societe_vendeuse) && ! $societe_vendeuse->pays_code)
+ {
+ if ($societe_vendeuse->id == $mysoc->id)
+ {
+ $return.= ''.$langs->trans("ErrorYourCountryIsNotDefined").'';
+ }
+ 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,$idprod);
+ $defaultnpr=get_default_npr($societe_vendeuse,$societe_acheteuse,$idprod);
+ }
+ // Si taux par defaut n'a pu etre determine, on prend dernier de la liste.
+ // Comme ils sont tries par ordre croissant, dernier = plus eleve = taux courant
+ if ($defaulttx < 0 || 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.= ''.vatrate($libtva[$i]);
+ $return.= $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 html string but return it
+ * @param disabled Disable input fields
+ * @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, $disabled=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
+ if (! $disabled)
+ {
+ $retstring.=''.img_object($langs->trans("SelectDate"),'calendar').' ';
+ }
+
+ $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.="$day";
+ }
+ else
+ {
+ $retstring.=" $day";
+ }
+ $retstring.=" ";
+ }
+
+ $retstring.=" ";
+
+ $retstring.='';
+ if ($empty || $set_time == -1)
+ {
+ $retstring.=' ';
+ }
+
+ // Month
+ for ($month = 1 ; $month <= 12 ; $month++)
+ {
+ $retstring.='';
+ $retstring.=dol_print_date(mktime(12,0,0,$month,1,2000),"%b");
+ $retstring.=" ";
+ }
+ $retstring.=" ";
+
+ // Year
+ if ($empty || $set_time == -1)
+ {
+ $retstring.=' ';
+ }
+ else
+ {
+ $retstring.='';
+
+ for ($year = $syear - 5; $year < $syear + 10 ; $year++)
+ {
+ if ($year == $syear)
+ {
+ $retstring.="".$year;
+ }
+ else
+ {
+ $retstring.=" ".$year;
+ }
+ $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.="$hour ";
+ }
+ else
+ {
+ $retstring.="$hour ";
+ }
+ }
+ $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.="$min ";
+ }
+ else
+ {
+ $retstring.="$min ";
+ }
+ }
+ $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.='';
+ $retstring.=$langs->trans("Now");
+ //print img_refresh($langs->trans("Now"));
+ $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 '".$hour." ";
+ }
+ print " ";
+ print "H ";
+ print '';
+ for ($min = 0; $min <= 55; $min=$min+5)
+ {
+ print ''.$min.' ';
+ }
+ 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 option Valeur de l'option en fonction du type choisi
+ * \param translate Traduire la valeur
+ * \param maxlen Length maximum for labels
+ * \param disabled Html select box is disabled
+ * \return string HTML select string
+ */
+ function selectarray($htmlname, $array, $id='', $show_empty=0, $key_in_label=0, $value_as_key=0, $option='', $translate=0, $maxlen=0, $disabled=0)
+ {
+ global $langs;
+
+ $out='';
+
+ $out.='';
+
+ if ($show_empty)
+ {
+ $out.=' '."\n";
+ }
+
+ if (is_array($array))
+ {
+ while (list($key, $value) = each ($array))
+ {
+ $out.='';
+
+ if ($key_in_label)
+ {
+ $newval=($translate?$langs->trans($value):$value);
+ $selectOptionValue = $key.' - '.($maxlen?dol_trunc($newval,$maxlen):$newval);
+ $out.=$selectOptionValue;
+ }
+ else
+ {
+ $newval=($translate?$langs->trans($value):$value);
+ $selectOptionValue = ($maxlen?dol_trunc($newval,$maxlen):$newval);
+ if ($value == '' || $value == '-') { $selectOptionValue=' '; }
+ $out.=$selectOptionValue;
+ }
+ $out.=" \n";
+ }
+ }
+
+ $out.=" ";
+ return $out;
+ }
+
+ /**
+ * Show a select form from an array
+ * @deprecated Use selectarray instead
+ */
+ function select_array($htmlname, $array, $id='', $show_empty=0, $key_in_label=0, $value_as_key=0, $option='', $translate=0, $maxlen=0)
+ {
+ print $this->selectarray($htmlname, $array, $id, $show_empty, $key_in_label, $value_as_key, $option, $translate, $maxlen);
+ }
+
+
+ /**
+ * \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 .= ''.$langs->trans("Yes").' '."\n";
+ $resultyesno .= ''.$langs->trans("No").' '."\n";
+ }
+ else
+ {
+ $resultyesno .= ''.$langs->trans("Yes").' '."\n";
+ $resultyesno .= ''.$langs->trans("No").' '."\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 '';
+ }
+ else
+ {
+ print ' ';
+ }
+ print $obj->label;
+ 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 .= '';
+ }
+ else
+ {
+ $select_week .= ' ';
+ }
+ $select_week .= $val;
+ }
+ $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 .= '';
+ }
+ else
+ {
+ $select_month .= ' ';
+ }
+ $select_month .= $val;
+ }
+ $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 "$y";
+ print " ";
+ }
+ print " \n";
+ }
+
+ /**
+ * Return a HTML area with the reference of object and a naviagation bar for a business object
* To add a particular filter on select, you must set $object->next_prev_filter to SQL criteria.
- * @param object Object to show
- * @param paramid Name of parameter to use to name the id into the URL link
- * @param morehtml More html content to output just before the nav bar
- * @param shownav Show Condition (navigation is shown if value is 1)
- * @param fieldid Nom du champ en base a utiliser pour select next et previous
- * @param fieldref Nom du champ objet ref (object->ref) a utiliser pour select next et previous
- * @param morehtmlref Code html supplementaire a afficher apres ref
- * @param moreparam More param to add in nav link url.
- * @return string Portion HTML avec ref + boutons nav
- */
- function showrefnav($object,$paramid,$morehtml='',$shownav=1,$fieldid='rowid',$fieldref='ref',$morehtmlref='',$moreparam='')
- {
- $ret='';
+ * @param object Object to show
+ * @param paramid Name of parameter to use to name the id into the URL link
+ * @param morehtml More html content to output just before the nav bar
+ * @param shownav Show Condition (navigation is shown if value is 1)
+ * @param fieldid Nom du champ en base a utiliser pour select next et previous
+ * @param fieldref Nom du champ objet ref (object->ref) a utiliser pour select next et previous
+ * @param morehtmlref Code html supplementaire a afficher apres ref
+ * @param moreparam More param to add in nav link url.
+ * @return string Portion HTML avec ref + boutons nav
+ */
+ function showrefnav($object,$paramid,$morehtml='',$shownav=1,$fieldid='rowid',$fieldref='ref',$morehtmlref='',$moreparam='')
+ {
+ $ret='';
- //print "$paramid,$morehtml,$shownav,$fieldid,$fieldref,$morehtmlref,$moreparam";
- $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 "$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.='';
- }
+ //print "xx".$previous_ref."x".$next_ref;
+ if ($previous_ref || $next_ref || $morehtml) {
+ $ret.='';
+ }
- $ret.=$object->$fieldref;
- if ($morehtmlref) {
- $ret.=' '.$morehtmlref;
- }
+ $ret.=$object->$fieldref;
+ if ($morehtmlref) {
+ $ret.=' '.$morehtmlref;
+ }
- if ($morehtml) {
- $ret.=' '.$morehtml;
- }
- if ($shownav && ($previous_ref || $next_ref)) {
- $ret.=' '.$previous_ref.' ';
- $ret.=''.$next_ref;
- }
- if ($previous_ref || $next_ref || $morehtml)
- {
- $ret.='
';
- }
- return $ret;
- }
+ if ($morehtml) {
+ $ret.=' '.$morehtml;
+ }
+ if ($shownav && ($previous_ref || $next_ref)) {
+ $ret.=' '.$previous_ref.' ';
+ $ret.=''.$next_ref;
+ }
+ if ($previous_ref || $next_ref || $morehtml)
+ {
+ $ret.='
';
+ }
+ return $ret;
+ }
- /**
- * \brief Return HTML code to output a photo
- * \param modulepart Id to define module concerned
- * \param object Object containing data to retrieve file name
- * \param width Width of photo
- * \return string HTML code to output photo
- */
- function showphoto($modulepart,$object,$width=100)
- {
- global $conf;
+ /**
+ * \brief Return HTML code to output a photo
+ * \param modulepart Id to define module concerned
+ * \param object Object containing data to retrieve file name
+ * \param width Width of photo
+ * \return string HTML code to output photo
+ */
+ function showphoto($modulepart,$object,$width=100)
+ {
+ global $conf;
- $ret='';$dir='';$file='';$email='';
+ $ret='';$dir='';$file='';$email='';
- if ($modulepart=='userphoto')
- {
- $dir=$conf->user->dir_output;
- $file=get_exdir($object->id,2).$object->photo;
- $altfile=$object->id.".jpg"; // For backward compatibility
- $email=$object->email;
- }
- if ($modulepart=='memberphoto')
- {
- $dir=$conf->adherent->dir_output;
- $file=get_exdir($object->id,2).$object->photo;
- $altfile=$object->id.".jpg"; // For backward compatibility
- $email=$object->email;
- }
+ if ($modulepart=='userphoto')
+ {
+ $dir=$conf->user->dir_output;
+ $file=get_exdir($object->id,2).$object->photo;
+ $altfile=$object->id.".jpg"; // For backward compatibility
+ $email=$object->email;
+ }
+ if ($modulepart=='memberphoto')
+ {
+ $dir=$conf->adherent->dir_output;
+ $file=get_exdir($object->id,2).$object->photo;
+ $altfile=$object->id.".jpg"; // For backward compatibility
+ $email=$object->email;
+ }
- if ($dir && $file)
- {
- if (file_exists($dir."/".$file))
- {
- $ret.=' ';
- }
- else if (file_exists($dir."/".$altfile))
- {
- $ret.=' ';
- }
- else
- {
- if ($conf->gravatar->enabled)
- {
- global $dolibarr_main_url_root;
- $ret.='';
- $ret.=' ';
- }
- else
- {
- $ret.=' ';
- }
- }
- }
- else
- {
- dol_print_error('','Call to showrefnav with wrong parameters');
- }
+ if ($dir && $file)
+ {
+ if (file_exists($dir."/".$file))
+ {
+ $ret.=' ';
+ }
+ else if (file_exists($dir."/".$altfile))
+ {
+ $ret.=' ';
+ }
+ else
+ {
+ if ($conf->gravatar->enabled)
+ {
+ global $dolibarr_main_url_root;
+ $ret.='';
+ $ret.=' ';
+ }
+ else
+ {
+ $ret.=' ';
+ }
+ }
+ }
+ else
+ {
+ dol_print_error('','Call to showrefnav with wrong parameters');
+ }
- return $ret;
- }
+ return $ret;
+ }
}
?>
diff --git a/htdocs/lib/ajax.lib.php b/htdocs/lib/ajax.lib.php
index 22869708c00..9c8b254bcef 100644
--- a/htdocs/lib/ajax.lib.php
+++ b/htdocs/lib/ajax.lib.php
@@ -147,9 +147,11 @@ function ajax_autocompleter($selected='',$htmlname,$url,$indicator='working')
}
/**
- * \brief Get value of field, do Ajax process and return result
- * \param htmlname nom et id du champ
- * \param url chemin du fichier de reponse : /chemin/fichier.php
+ * \brief Get value of field, do Ajax process and return result. Use jQuery.
+ * \param selected Preselected value
+ * \param htmlname Name of html field
+ * \param url Path of source file to get values: /path/ajaxpage.php
+ * \param option Not used
* \return string script complet
*/
function ajax_autocompleter2($selected='', $htmlname, $url, $option='')
@@ -157,15 +159,20 @@ function ajax_autocompleter2($selected='', $htmlname, $url, $option='')
$script = ' ';
$script.= '';
return $script;
diff --git a/htdocs/product/ajaxproducts.php b/htdocs/product/ajaxproducts.php
index 6272ac0fe70..937053187c8 100644
--- a/htdocs/product/ajaxproducts.php
+++ b/htdocs/product/ajaxproducts.php
@@ -24,19 +24,16 @@
* \version $Id$
*/
-if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER','1');
-//if (! defined('NOREQUIREDB')) define('NOREQUIREDB','1');
-if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1');
-//if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1');
-if (! defined('NOCSRFCHECK')) define('NOCSRFCHECK','1');
-if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL','1'); // Disables token renewal
+if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL',1); // Disables token renewal
if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU','1');
-if (empty($_GET['keysearch']) && ! defined('NOREQUIREHTML')) define('NOREQUIREHTML','1');
+if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML','1');
if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX','1');
-if (! defined("NOLOGIN")) define("NOLOGIN",'1');
-
+if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1');
+if (! defined('NOCSRFCHECK')) define('NOCSRFCHECK','1');
+if (empty($_GET['keysearch']) && ! defined('NOREQUIREHTML')) define('NOREQUIREHTML','1');
require('../main.inc.php');
+require_once(DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php');
$langs->load("products");
$langs->load("main");
@@ -46,6 +43,12 @@ $langs->load("main");
* View
*/
+// Ajout directives pour resoudre bug IE
+//header('Cache-Control: Public, must-revalidate');
+//header('Pragma: public');
+
+//print ''."\n";
+
//top_htmlhead("", "", 1); // Disabled. An ajax return must not include html header.
//print ''."\n";
diff --git a/htdocs/societe/ajaxcompanies.php b/htdocs/societe/ajaxcompanies.php
index 8cbb5f5b83a..1598f2701d4 100644
--- a/htdocs/societe/ajaxcompanies.php
+++ b/htdocs/societe/ajaxcompanies.php
@@ -25,13 +25,12 @@
* \version $Id$
*/
-if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL','1'); // Disables token renewal
+if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL',1); // Disables token renewal
if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU','1');
if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML','1');
if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX','1');
if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1');
if (! defined('NOCSRFCHECK')) define('NOCSRFCHECK','1');
-if (! defined("NOLOGIN")) define("NOLOGIN",'1');
require('../main.inc.php');
@@ -40,6 +39,12 @@ require('../main.inc.php');
* View
*/
+// Ajout directives pour resoudre bug IE
+header('Cache-Control: Public, must-revalidate');
+header('Pragma: public');
+
+print ''."\n";
+
//top_htmlhead("", "", 1, 1); // Disabled. An ajax return must not include html header.
//print '';
diff --git a/htdocs/societe/ajaxcountries.php b/htdocs/societe/ajaxcountries.php
index 4812b1bc1eb..b865532db97 100644
--- a/htdocs/societe/ajaxcountries.php
+++ b/htdocs/societe/ajaxcountries.php
@@ -23,11 +23,12 @@
* \version $Id$
*/
-if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL','1'); // Disables token renewal
+if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL',1); // Disables token renewal
if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU','1');
if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML','1');
if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX','1');
if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1');
+if (! defined('NOCSRFCHECK')) define('NOCSRFCHECK','1');
require('../main.inc.php');
@@ -36,6 +37,12 @@ require('../main.inc.php');
* View
*/
+// Ajout directives pour resoudre bug IE
+header('Cache-Control: Public, must-revalidate');
+header('Pragma: public');
+
+print ''."\n";
+
//top_htmlhead("", "", 1, 1); // Disabled. An ajax return must not include html header.
//print '';