/htdocs/core/class/html.form.class.php
PHP | 3852 lines | 2695 code | 371 blank | 786 comment | 790 complexity | 4cf4b83662b932defac5e6b03335469a MD5 | raw file
Possible License(s): LGPL-2.0
Large files files are truncated, but you can click here to view the full file
- <?php
- /* Copyright (c) 2002-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
- * Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
- * Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
- * Copyright (C) 2004 Sebastien Di Cintio <sdicintio@ressource-toi.org>
- * Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
- * Copyright (C) 2005-2011 Regis Houssin <regis@dolibarr.fr>
- * Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr>
- * Copyright (C) 2006 Marc Barilley/Ocebo <marc@ocebo.com>
- * Copyright (C) 2007 Franky Van Liedekerke <franky.van.liedekerker@telenet.be>
- * Copyright (C) 2007 Patrick Raguin <patrick.raguin@gmail.com>
- * Copyright (C) 2010 Juanjo Menent <jmenent@2byte.es>
- * Copyright (C) 2010 Philippe Grand <philippe.grand@atoo-net.com>
- * Copyright (C) 2011 Herve Prot <herve.prot@symeos.com>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- /**
- * \file htdocs/core/class/html.form.class.php
- * \ingroup core
- * \brief File of class with all html predefined components
- */
- /**
- * \class Form
- * \brief Class to manage generation of HTML components
- * \remarks Only common components must be here.
- */
- class Form
- {
- var $db;
- var $error;
- // Cache arrays
- var $cache_types_paiements=array();
- var $cache_conditions_paiements=array();
- var $cache_availability=array();
- var $cache_demand_reason=array();
- var $cache_type_fees=array();
- var $tva_taux_value;
- var $tva_taux_libelle;
- /**
- * Constructor
- *
- * @param DoliDB $db Database handler
- */
- public function __construct($db)
- {
- $this->db = $db;
- }
- /**
- * Output key field for an editable field
- *
- * @param string $text Text of label or key to translate
- * @param string $htmlname Name of select field
- * @param string $preselected Name of Value to show/edit (not used in this function)
- * @param object $object Object
- * @param boolean $perm Permission to allow button to edit parameter
- * @param string $typeofdata Type of data ('string' by default, 'email', 'numeric:99', 'text' or 'textarea', 'day' or 'datepicker', 'ckeditor:dolibarr_zzz:width:height', 'select:xxx'...)
- * @return string HTML edit field
- */
- function editfieldkey($text,$htmlname,$preselected,$object,$perm,$typeofdata='string')
- {
- global $conf,$langs;
- $ret='';
- if (! empty($conf->global->MAIN_USE_JQUERY_JEDITABLE))
- {
- if ($perm)
- {
- $tmp=explode(':',$typeofdata);
- $ret.= '<div class="editkey_'.$tmp[0].'" id="'.$htmlname.'">';
- $ret.= $langs->trans($text);
- $ret.= '</div>'."\n";
- }
- else
- {
- $ret.= $langs->trans($text);
- }
- }
- else
- {
- $ret.='<table class="nobordernopadding" width="100%"><tr><td nowrap="nowrap">';
- $ret.=$langs->trans($text);
- $ret.='</td>';
- if (GETPOST('action') != 'edit'.$htmlname && $perm) $ret.='<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=edit'.$htmlname.'&id='.$object->id.'">'.img_edit($langs->trans('Edit'),1).'</a></td>';
- $ret.='</tr></table>';
- }
- return $ret;
- }
- /**
- * Output val field for an editable field
- *
- * @param string $text Text of label (not used in this function)
- * @param string $htmlname Name of select field
- * @param string $value Value to show/edit
- * @param object $object Object
- * @param boolean $perm Permission to allow button to edit parameter
- * @param string $typeofdata Type of data ('string' by default, 'email', 'numeric:99', 'text' or 'textarea', 'day' or 'datepicker', 'ckeditor:dolibarr_zzz:width:height', 'select:xxx'...)
- * @param string $editvalue When in edit mode, use this value as $value instead of value
- * @param object $extObject External object
- * @return string HTML edit field
- */
- function editfieldval($text,$htmlname,$value,$object,$perm,$typeofdata='string',$editvalue='',$extObject=false)
- {
- global $conf,$langs,$db;
- $ret='';
- // When option to edit inline is activated
- if (! empty($conf->global->MAIN_USE_JQUERY_JEDITABLE))
- {
- $ret.=$this->editInPlace($object, $value, $htmlname, $perm, $typeofdata, $extObject);
- }
- else
- {
- if (GETPOST('action') == 'edit'.$htmlname)
- {
- $ret.="\n";
- $ret.='<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
- $ret.='<input type="hidden" name="action" value="set'.$htmlname.'">';
- $ret.='<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
- $ret.='<input type="hidden" name="id" value="'.$object->id.'">';
- $ret.='<table class="nobordernopadding" cellpadding="0" cellspacing="0">';
- $ret.='<tr><td>';
- if (preg_match('/^(string|email|numeric)/',$typeofdata))
- {
- $tmp=explode(':',$typeofdata);
- $ret.='<input type="text" id="'.$htmlname.'" name="'.$htmlname.'" value="'.($editvalue?$editvalue:$value).'"'.($tmp[1]?' size="'.$tmp[1].'"':'').'>';
- }
- else if ($typeofdata == 'text' || $typeofdata == 'textarea' || $typeofdata == 'note')
- {
- $ret.='<textarea id="'.$htmlname.'" name="'.$htmlname.'" wrap="soft" cols="70">'.($editvalue?$editvalue:$value).'</textarea>';
- }
- else if ($typeofdata == 'day' || $typeofdata == 'datepicker')
- {
- $ret.=$this->form_date($_SERVER['PHP_SELF'].'?id='.$object->id,$value,$htmlname);
- }
- else if (preg_match('/^ckeditor/',$typeofdata))
- {
- $tmp=explode(':',$typeofdata);
- require_once(DOL_DOCUMENT_ROOT."/core/class/doleditor.class.php");
- $doleditor=new DolEditor($htmlname,($editvalue?$editvalue:$value),($tmp[2]?$tmp[2]:''),($tmp[3]?$tmp[3]:'100'),($tmp[1]?$tmp[1]:'dolibarr_notes'),'In',false,true,true);
- $ret.=$doleditor->Create(1);
- }
- $ret.='</td>';
- if ($typeofdata != 'day' && $typeofdata != 'datepicker') $ret.='<td align="left"><input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>';
- $ret.='</tr></table>'."\n";
- $ret.='</form>'."\n";
- }
- else
- {
- if ($typeofdata == 'email') $ret.=dol_print_email($value,0,0,0,0,1);
- elseif ($typeofdata == 'day' || $typeofdata == 'datepicker') $ret.=dol_print_date($value,'day');
- elseif ($typeofdata == 'text' || $typeofdata == 'textarea') $ret.=dol_htmlentitiesbr($value);
- else if (preg_match('/^ckeditor/',$typeofdata))
- {
- $tmpcontent=dol_htmlentitiesbr($value);
- $firstline=preg_replace('/<br>.*/','',$tmpcontent);
- $firstline=preg_replace('/[\n\r].*/','',$firstline);
- $ret.=$firstline.((strlen($firstline) != strlen($tmpcontent))?'...':'');
- }
- else $ret.=$value;
- }
- }
- return $ret;
- }
- /**
- * Output edit in place form
- *
- * @param object $object Object
- * @param string $value Value to show/edit
- * @param string $htmlname DIV ID (field name)
- * @param int $condition Condition to edit
- * @param string $inputType Type of input ('numeric', 'datepicker', 'textarea', 'ckeditor:dolibarr_zzz', 'select:xxx')
- * @param object $extObject External object
- * @return string HTML edit in place
- */
- private function editInPlace($object, $value, $htmlname, $condition, $inputType='textarea', $extObject=false)
- {
- global $conf;
- $out='';
- // Check parameters
- if ($inputType == 'textarea') $value = dol_nl2br($value);
- else if (preg_match('/^numeric/',$inputType)) $value = price($value);
- else if ($inputType == 'datepicker') $value = dol_print_date($value, 'day');
- if ($condition)
- {
- $element = false;
- $table_element = false;
- $fk_element = false;
- $loadmethod = false;
- $savemethod = false;
- $ext_element = false;
- //$ext_table_element = false;
- //$ext_fk_element = false;
- if (is_object($object))
- {
- $element = $object->element;
- $table_element = $object->table_element;
- $fk_element = $object->id;
- }
- if (is_object($extObject))
- {
- $ext_element = $extObject->element;
- //$ext_table_element = $extObject->table_element;
- //$ext_fk_element = $extObject->id;
- }
- if (preg_match('/^(string|email|numeric)/',$inputType))
- {
- $tmp=explode(':',$inputType);
- $inputType=$tmp[0]; $inputOption=$tmp[1];
- if (! empty($tmp[2])) $savemethod=$tmp[2];
- }
- if (preg_match('/^datepicker/',$inputType))
- {
- $tmp=explode(':',$inputType);
- $inputType=$tmp[0]; $inputOption=$tmp[1];
- if (! empty($tmp[2])) $savemethod=$tmp[2];
- $out.= '<input id="timestamp" type="hidden"/>'."\n"; // Use for timestamp format
- }
- else if (preg_match('/^select/',$inputType))
- {
- $tmp=explode(':',$inputType);
- $inputType=$tmp[0]; $loadmethod=$tmp[1];
- if (! empty($tmp[2])) $savemethod=$tmp[2];
- }
- else if (preg_match('/^ckeditor/',$inputType))
- {
- $tmp=explode(':',$inputType);
- $inputType=$tmp[0]; $toolbar=$tmp[1];
- if (! empty($tmp[2])) $width=$tmp[2];
- if (! empty($tmp[3])) $heigth=$tmp[3];
- if (! empty($tmp[4])) $savemethod=$tmp[4];
- if (! empty($conf->fckeditor->enabled))
- {
- $out.= '<input id="ckeditor_toolbar" value="'.$toolbar.'" type="hidden"/>'."\n";
- }
- else
- {
- $inputType = 'textarea';
- }
- }
- $out.= '<input id="element_'.$htmlname.'" value="'.$element.'" type="hidden"/>'."\n";
- $out.= '<input id="table_element_'.$htmlname.'" value="'.$table_element.'" type="hidden"/>'."\n";
- $out.= '<input id="fk_element_'.$htmlname.'" value="'.$fk_element.'" type="hidden"/>'."\n";
- $out.= '<input id="loadmethod_'.$htmlname.'" value="'.$loadmethod.'" type="hidden"/>'."\n";
- $out.= '<input id="savemethod_'.$htmlname.'" value="'.$savemethod.'" type="hidden"/>'."\n";
- $out.= '<input id="ext_element_'.$htmlname.'" value="'.$ext_element.'" type="hidden"/>'."\n";
- //$out.= '<input id="ext_table_element_'.$htmlname.'" value="'.$ext_table_element.'" type="hidden"/>'."\n";
- //$out.= '<input id="ext_fk_element_'.$htmlname.'" value="'.$ext_fk_element.'" type="hidden"/>'."\n";
- $out.= '<div id="val_'.$htmlname.'" class="editval_'.$inputType.'">'.$value.'</div>'."\n";
- }
- else
- {
- $out = $value;
- }
- return $out;
- }
- /**
- * Show a text and picto with tooltip on text or picto
- *
- * @param string $text Text to show
- * @param string $htmltext Content html of tooltip. Must be HTML/UTF8 encoded.
- * @param int $tooltipon 1=tooltip sur texte, 2=tooltip sur picto, 3=tooltip sur les 2
- * @param int $direction -1=Le picto est avant, 0=pas de picto, 1=le picto est apres
- * @param string $img Code img du picto (use img_xxx() function to get it)
- * @param string $extracss Add a CSS style to td tags
- * @param int $notabs Do not include table and tr tags
- * @param string $incbefore Include code before the text
- * @param int $noencodehtmltext Do not encode into html entity the htmltext
- * @return string Code html du tooltip (texte+picto)
- * @see Use function textwithpicto if you can.
- */
- function textwithtooltip($text,$htmltext,$tooltipon=1,$direction=0,$img='',$extracss='',$notabs=0,$incbefore='',$noencodehtmltext=0)
- {
- global $conf;
- if ($incbefore) $text = $incbefore.$text;
- if (! $htmltext) return $text;
- // Sanitize tooltip
- $htmltext=str_replace("\\","\\\\",$htmltext);
- $htmltext=str_replace("\r","",$htmltext);
- $htmltext=str_replace("\n","",$htmltext);
- $htmltext=str_replace('"',""",$htmltext);
- if ($tooltipon == 2 || $tooltipon == 3) $paramfortooltipimg=' class="classfortooltip'.($extracss?' '.$extracss:'').'" title="'.($noencodehtmltext?$htmltext:dol_escape_htmltag($htmltext,1)).'"'; // Attribut to put on td img tag to store tooltip
- else $paramfortooltipimg =($extracss?' class="'.$extracss.'"':''); // Attribut to put on td text tag
- if ($tooltipon == 1 || $tooltipon == 3) $paramfortooltiptd=' class="classfortooltip'.($extracss?' '.$extracss:'').'" title="'.($noencodehtmltext?$htmltext:dol_escape_htmltag($htmltext,1)).'"'; // Attribut to put on td tag to store tooltip
- else $paramfortooltiptd =($extracss?' class="'.$extracss.'"':''); // Attribut to put on td text tag
- $s="";
- if (empty($notabs)) $s.='<table class="nobordernopadding" summary=""><tr>';
- if ($direction > 0)
- {
- if ($text != '')
- {
- $s.='<td'.$paramfortooltiptd.'>'.$text;
- if ($direction) $s.=' ';
- $s.='</td>';
- }
- if ($direction) $s.='<td'.$paramfortooltipimg.' valign="top" width="14">'.$img.'</td>';
- }
- else
- {
- if ($direction) $s.='<td'.$paramfortooltipimg.' valign="top" width="14">'.$img.'</td>';
- if ($text != '')
- {
- $s.='<td'.$paramfortooltiptd.'>';
- if ($direction) $s.=' ';
- $s.=$text.'</td>';
- }
- }
- if (empty($notabs)) $s.='</tr></table>';
- return $s;
- }
- /**
- * 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, 0=no icon
- * @param type Type of picto (info, help, warning, superadmin...)
- * @param extracss Add a CSS style to td tags
- * @param noencodehtmltext Do not encode into html entity the htmltext
- * @return string HTML code of text, picto, tooltip
- */
- function textwithpicto($text,$htmltext,$direction=1,$type='help',$extracss='',$noencodehtmltext=0)
- {
- 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_picto($alt,"redstar");
- if ($type == 'admin') $img=img_picto($alt,"star");
- // Warnings
- if ($type == 'warning') $img=img_warning($alt);
- return $this->textwithtooltip($text,$htmltext,2,$direction,$img,$extracss,0,'',$noencodehtmltext);
- }
- /**
- * 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
- */
- function select_pays($selected='',$htmlname='pays_id',$htmloption='')
- {
- print $this->select_country($selected,$htmlname,$htmloption);
- }
- /**
- * 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
- * @return string HTML string with select
- */
- function select_country($selected='',$htmlname='pays_id',$htmloption='')
- {
- global $conf,$langs;
- $langs->load("dict");
- $out='';
- $countryArray=array();
- $label=array();
- $sql = "SELECT rowid, code as code_iso, libelle as label";
- $sql.= " FROM ".MAIN_DB_PREFIX."c_pays";
- $sql.= " WHERE active = 1";
- $sql.= " ORDER BY code ASC";
- dol_syslog("Form::select_country sql=".$sql);
- $resql=$this->db->query($sql);
- if ($resql)
- {
- $out.= '<select id="select'.$htmlname.'" class="flat selectpays" name="'.$htmlname.'" '.$htmloption.'>';
- $num = $this->db->num_rows($resql);
- $i = 0;
- if ($num)
- {
- $foundselected=false;
- while ($i < $num)
- {
- $obj = $this->db->fetch_object($resql);
- $countryArray[$i]['rowid'] = $obj->rowid;
- $countryArray[$i]['code_iso'] = $obj->code_iso;
- $countryArray[$i]['label'] = ($obj->code_iso && $langs->transnoentitiesnoconv("Country".$obj->code_iso)!="Country".$obj->code_iso?$langs->transnoentitiesnoconv("Country".$obj->code_iso):($obj->label!='-'?$obj->label:''));
- $label[$i] = $countryArray[$i]['label'];
- $i++;
- }
- array_multisort($label, SORT_ASC, $countryArray);
- foreach ($countryArray as $row)
- {
- //print 'rr'.$selected.'-'.$row['label'].'-'.$row['code_iso'].'<br>';
- if ($selected && $selected != '-1' && ($selected == $row['rowid'] || $selected == $row['code_iso'] || $selected == $row['label']) )
- {
- $foundselected=true;
- $out.= '<option value="'.$row['rowid'].'" selected="selected">';
- }
- else
- {
- $out.= '<option value="'.$row['rowid'].'">';
- }
- $out.= $row['label'];
- if ($row['code_iso']) $out.= ' ('.$row['code_iso'] . ')';
- $out.= '</option>';
- }
- }
- $out.= '</select>';
- }
- else
- {
- dol_print_error($this->db);
- }
- return $out;
- }
- /**
- * 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 '<select class="flat" name="'.$htmlname.'">';
- $num = count($type_available);
- $i = 0;
- if ($num)
- {
- while ($i < $num)
- {
- if ($selected == $type_available[$i])
- {
- print '<option value="'.$type_available[$i].'" selected="selected">'.$langs->trans("BankType".$type_available[$i]).'</option>';
- }
- else
- {
- print '<option value="'.$type_available[$i].'">'.$langs->trans("BankType".$type_available[$i]).'</option>';
- }
- $i++;
- }
- }
- print '</select>';
- }
- /**
- * Return list of social contributions.
- * Use mysoc->pays_id or mysoc->pays_code so they must be defined.
- *
- * @param selected Preselected type
- * @param htmlname Name of field in form
- * @param useempty Set to 1 if we want an empty value
- * @param maxlen Max length of text in combo box
- * @param help Add or not the admin help picto
- */
- function select_type_socialcontrib($selected='',$htmlname='actioncode', $useempty=0, $maxlen=40, $help=1)
- {
- global $db,$langs,$user,$mysoc;
- if (empty($mysoc->pays_id) && empty($mysoc->pays_code))
- {
- dol_print_error('','Call to select_type_socialcontrib with mysoc country not yet defined');
- exit;
- }
- if (! empty($mysoc->pays_id))
- {
- $sql = "SELECT c.id, c.libelle as type";
- $sql.= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c";
- $sql.= " WHERE c.active = 1";
- $sql.= " AND c.fk_pays = ".$mysoc->pays_id;
- $sql.= " ORDER BY c.libelle ASC";
- }
- else
- {
- $sql = "SELECT c.id, c.libelle as type";
- $sql.= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c, ".MAIN_DB_PREFIX."c_pays as p";
- $sql.= " WHERE c.active = 1 AND c.fk_pays = p.rowid";
- $sql.= " AND p.code = '".$mysoc->pays_code."'";
- $sql.= " ORDER BY c.libelle ASC";
- }
- dol_syslog("Form::select_type_socialcontrib sql=".$sql, LOG_DEBUG);
- $resql=$db->query($sql);
- if ($resql)
- {
- $num = $db->num_rows($resql);
- if ($num)
- {
- print '<select class="flat" name="'.$htmlname.'">';
- $i = 0;
- if ($useempty) print '<option value="0"> </option>';
- while ($i < $num)
- {
- $obj = $db->fetch_object($resql);
- print '<option value="'.$obj->id.'"';
- if ($obj->id == $selected) print ' selected="selected"';
- print '>'.dol_trunc($obj->type,$maxlen);
- $i++;
- }
- print '</select>';
- if ($user->admin && $help) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionnarySetup"),1);
- }
- else
- {
- print $langs->trans("ErrorNoSocialContributionForSellerCountry",$mysoc->pays_code);
- }
- }
- else
- {
- dol_print_error($db,$db->lasterror());
- }
- }
- /**
- * Return list of types of lines (product or service)
- * Example: 0=product, 1=service, 9=other (for external module)
- *
- * @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 '<select class="flat" name="'.$htmlname.'">';
- if ($showempty)
- {
- print '<option value="-1"';
- if ($selected == -1) print ' selected="selected"';
- print '> </option>';
- }
- print '<option value="0"';
- if (0 == $selected) print ' selected="selected"';
- print '>'.$langs->trans("Product");
- print '<option value="1"';
- if (1 == $selected) print ' selected="selected"';
- print '>'.$langs->trans("Service");
- print '</select>';
- //if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionnarySetup"),1);
- }
- if (! $forceall && empty($conf->product->enabled) && $conf->service->enabled)
- {
- print '<input type="hidden" name="'.$htmlname.'" value="1">';
- }
- if (! $forceall && $conf->product->enabled && empty($conf->service->enabled))
- {
- print '<input type="hidden" name="'.$htmlname.'" value="0">';
- }
- }
- /**
- * Load into cache cache_types_fees, array of types of fees
- *
- * @return int Nb of lines loaded, 0 if already loaded, <0 if ko
- * TODO move in DAO class
- */
- function load_cache_types_fees()
- {
- global $langs;
- $langs->load("trips");
- if (count($this->cache_types_fees)) return 0; // Cache already load
- $sql = "SELECT c.code, c.libelle as label";
- $sql.= " FROM ".MAIN_DB_PREFIX."c_type_fees as c";
- $sql.= " ORDER BY lower(c.libelle) ASC";
- dol_syslog(get_class($this).'::load_cache_types_fees 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
- $label=($obj->code != $langs->trans($obj->code) ? $langs->trans($obj->code) : $langs->trans($obj->label));
- $this->cache_types_fees[$obj->code] = $label;
- $i++;
- }
- return $num;
- }
- else
- {
- dol_print_error($this->db);
- return -1;
- }
- }
- /**
- * Return list of types of notes
- *
- * @param string $selected Preselected type
- * @param string $htmlname Name of field in form
- * @param int $showempty Add an empty field
- * @return void
- */
- function select_type_fees($selected='',$htmlname='type',$showempty=0)
- {
- global $user, $langs;
- dol_syslog(get_class($this)."::select_type_fees ".$selected.", ".$htmlname, LOG_DEBUG);
- $this->load_cache_types_fees();
- print '<select class="flat" name="'.$htmlname.'">';
- if ($showempty)
- {
- print '<option value="-1"';
- if ($selected == -1) print ' selected="selected"';
- print '> </option>';
- }
- foreach($this->cache_types_fees as $key => $value)
- {
- print '<option value="'.$key.'"';
- if ($key == $selected) print ' selected="selected"';
- print '>';
- print $value;
- print '</option>';
- }
- print '</select>';
- if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionnarySetup"),1);
- }
- /**
- * 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)
- {
- print $this->select_company($selected,$htmlname,$filter,$showempty,$showtype,$forcecombo);
- }
- /**
- * Output html form to select a third party
- *
- * @param selected Preselected type
- * @param htmlname Name of field in form
- * @param filter Optionnal filters criteras
- * @param showempty Add an empty field
- * @param showtype Show third party type in combolist (customer, prospect or supplier)
- * @param forcecombo Force to use combo box
- */
- function select_company($selected='',$htmlname='socid',$filter='',$showempty=0, $showtype=0, $forcecombo=0)
- {
- global $conf,$user,$langs;
- $out='';
- // On recherche les societes
- $sql = "SELECT s.rowid, s.nom, s.client, s.fournisseur, s.code_client, s.code_fournisseur";
- $sql.= " FROM ".MAIN_DB_PREFIX ."societe as s";
- if (!$user->rights->societe->client->voir && !$user->societe_id) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
- $sql.= " WHERE s.entity = ".$conf->entity;
- if ($filter) $sql.= " AND ".$filter;
- if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
- $sql.= " ORDER BY nom ASC";
- dol_syslog("Form::select_societes sql=".$sql);
- $resql=$this->db->query($sql);
- if ($resql)
- {
- if ($conf->use_javascript_ajax && $conf->global->COMPANY_USE_SEARCH_TO_SELECT && ! $forcecombo)
- {
- //$minLength = (is_numeric($conf->global->COMPANY_USE_SEARCH_TO_SELECT)?$conf->global->COMPANY_USE_SEARCH_TO_SELECT:2);
- $out.= ajax_combobox($htmlname);
- }
- $out.= '<select id="'.$htmlname.'" class="flat" name="'.$htmlname.'">';
- if ($showempty) $out.= '<option value="-1"> </option>';
- $num = $this->db->num_rows($resql);
- $i = 0;
- if ($num)
- {
- while ($i < $num)
- {
- $obj = $this->db->fetch_object($resql);
- $label=$obj->nom;
- if ($showtype)
- {
- if ($obj->client || $obj->fournisseur) $label.=' (';
- if ($obj->client == 1 || $obj->client == 3) $label.=$langs->trans("Customer");
- if ($obj->client == 2 || $obj->client == 3) $label.=($obj->client==3?', ':'').$langs->trans("Prospect");
- if ($obj->fournisseur) $label.=($obj->client?', ':'').$langs->trans("Supplier");
- if ($obj->client || $obj->fournisseur) $label.=')';
- }
- if ($selected > 0 && $selected == $obj->rowid)
- {
- $out.= '<option value="'.$obj->rowid.'" selected="selected">'.$label.'</option>';
- }
- else
- {
- $out.= '<option value="'.$obj->rowid.'">'.$label.'</option>';
- }
- $i++;
- }
- }
- $out.= '</select>';
- }
- else
- {
- dol_print_error($this->db);
- }
- return $out;
- }
- /**
- * 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 '<select class="flat" name="'.$htmlname.'">';
- $num = $this->db->num_rows($resql);
- $qualifiedlines=$num;
- $i = 0;
- if ($num)
- {
- print '<option value="0"> </option>';
- while ($i < $num)
- {
- $obj = $this->db->fetch_object($resql);
- $desc=dol_trunc($obj->description,40);
- if ($desc=='(CREDIT_NOTE)') $desc=$langs->trans("CreditNote");
- if ($desc=='(DEPOSIT)') $desc=$langs->trans("Deposit");
- $selectstring='';
- if ($selected > 0 && $selected == $obj->rowid) $selectstring=' selected="selected"';
- $disabled='';
- if ($maxvalue > 0 && $obj->amount_ttc > $maxvalue)
- {
- $qualifiedlines--;
- $disabled=' disabled="disabled"';
- }
- print '<option value="'.$obj->rowid.'"'.$selectstring.$disabled.'>'.$desc.' ('.price($obj->amount_ht).' '.$langs->trans("HT").' - '.price($obj->amount_ttc).' '.$langs->trans("TTC").')</option>';
- $i++;
- }
- }
- print '</select>';
- return $qualifiedlines;
- }
- else
- {
- dol_print_error($this->db);
- return -1;
- }
- }
- /**
- * Return list of all contacts (for a third party or all)
- *
- * @param socid Id ot third party or 0 for all
- * @param selected Id contact pre-selectionne
- * @param htmlname Name of HTML field ('none' for a not editable field)
- * @param show_empty 0=no empty value, 1=add an empty value
- * @param exclude List of contacts id to exclude
- * @param limitto Disable answers that are not id in this array list
- * @param showfunction Add function into label
- * @param moreclass Add more class to class style
- * @return int <0 if KO, Nb of contact in list if OK
- */
- function select_contacts($socid,$selected='',$htmlname='contactid',$showempty=0,$exclude='',$limitto='',$showfunction=0, $moreclass='')
- {
- global $conf,$langs;
- // On recherche les societes
- $sql = "SELECT s.rowid, s.name, s.firstname, s.poste FROM";
- $sql.= " ".MAIN_DB_PREFIX ."socpeople as s";
- $sql.= " WHERE entity = ".$conf->entity;
- if ($socid > 0) $sql.= " AND fk_soc=".$socid;
- $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 '<select class="flat'.($moreclass?' '.$moreclass:'').'" id="'.$htmlname.'" name="'.$htmlname.'">';
- if ($showempty) print '<option value="0"></option>';
- $num = $this->db->num_rows($resql);
- $i = 0;
- if ($num)
- {
- include_once(DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php');
- $contactstatic=new Contact($this->db);
- while ($i < $num)
- {
- $obj = $this->db->fetch_object($resql);
- $contactstatic->id=$obj->rowid;
- $contactstatic->name=$obj->name;
- $contactstatic->firstname=$obj->firstname;
- if ($htmlname != 'none')
- {
- $disabled=0;
- if (is_array($exclude) && count($exclude) && in_array($obj->rowid,$exclude)) $disabled=1;
- if (is_array($limitto) && count($limitto) && ! in_array($obj->rowid,$limitto)) $disabled=1;
- if ($selected && $selected == $obj->rowid)
- {
- print '<option value="'.$obj->rowid.'"';
- if ($disabled) print ' disabled="disabled"';
- print ' selected="selected">';
- print $contactstatic->getFullName($langs);
- if ($showfunction && $obj->poste) print ' ('.$obj->poste.')';
- print '</option>';
- }
- else
- {
- print '<option value="'.$obj->rowid.'"';
- if ($disabled) print ' disabled="disabled"';
- print '>';
- print $contactstatic->getFullName($langs);
- if ($showfunction && $obj->poste) print ' ('.$obj->poste.')';
- print '</option>';
- }
- }
- else
- {
- if ($selected == $obj->rowid)
- {
- print $contactstatic->getFullName($langs);
- if ($showfunction && $obj->poste) print ' ('.$obj->poste.')';
- }
- }
- $i++;
- }
- }
- if ($htmlname != 'none')
- {
- print '</select>';
- }
- return $num;
- }
- else
- {
- dol_print_error($this->db);
- return -1;
- }
- }
- /**
- * 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
- * @param force_entity Possibility to force entity
- */
- function select_users($selected='',$htmlname='userid',$show_empty=0,$exclude='',$disabled=0,$include='',$enableonly='',$force_entity=0)
- {
- print $this->select_dolusers($selected,$htmlname,$show_empty,$exclude,$disabled,$include,$enableonly,$force_entity);
- }
- /**
- * Return select list of users
- *
- * @param selected User id or user object of user preselected. If -1, we use id of current user.
- * @param htmlname Field name in form
- * @param show_empty 0=liste sans valeur nulle, 1=ajoute valeur inconnue
- * @param exclude Array list of users id to exclude
- * @param disabled If select list must be disabled
- * @param include Array list of users id to include
- * @param enableonly Array list of users id to be enabled. All other must be disabled
- * @param force_entity Possibility to force entity
- */
- function select_dolusers($selected='',$htmlname='userid',$show_empty=0,$exclude='',$disabled=0,$include='',$enableonly='',$force_entity=0)
- {
- global $conf,$user,$langs;
- // If no preselected user defined, we take current user
- if ($selected < -1 && empty($conf->global->SOCIETE_DISABLE_DEFAULT_SALESREPRESENTATIVE)) $selected=$user->id;
- // Permettre l'exclusion d'utilisateurs
- if (is_array($exclude)) $excludeUsers = implode("','",$exclude);
- // Permettre l'inclusion d'utilisateurs
- if (is_array($include)) $includeUsers = implode("','",$include);
- $out='';
- // On recherche les utilisateurs
- $sql = "SELECT u.rowid, u.name, u.firstname, u.login, u.admin, u.entity";
- if(! empty($conf->multicompany->enabled) && $conf->entity == 1 && $user->admin && ! $user->entity)
- {
- $sql.= ", e.label";
- }
- $sql.= " FROM ".MAIN_DB_PREFIX ."user as u";
- if(! empty($conf->multicompany->enabled) && $conf->entity == 1 && $user->admin && ! $user->entity)
- {
- $sql.= " LEFT JOIN ".MAIN_DB_PREFIX ."entity as e on e.rowid=u.entity";
- if ($force_entity) $sql.= " WHERE u.entity IN (0,".$force_entity.")";
- else $sql.= " WHERE u.entity IS NOT NULL";
- }
- else
- {
- $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_dolusers sql=".$sql);
- $resql=$this->db->query($sql);
- if ($resql)
- {
- $num = $this->db->num_rows($resql);
- $i = 0;
- if ($num)
- {
- $out.= '<select class="flat" id="'.$htmlname.'" name="'.$htmlname.'"'.($disabled?' disabled="disabled"':'').'>';
- if ($show_empty) $out.= '<option value="-1"'.($id==-1?' selected="selected"':'').'> </option>'."\n";
- $userstatic=new User($this->db);
- while ($i < $num)
- {
- $obj = $this->db->fetch_object($resql);
- $userstatic->id=$obj->rowid;
- $userstatic->nom=$obj->name;
- $userstatic->prenom=$obj->firstname;
- $disableline=0;
- if (is_array($enableonly) && count($enableonly) && ! in_array($obj->rowid,$enableonly)) $disableline=1;
- if ((is_object($selected) && $selected->id == $obj->rowid) || (! is_object($selected) && $selected == $obj->rowid))
- {
- $out.= '<option value="'.$obj->rowid.'"';
- if ($disableline) $out.= ' disabled="disabled"';
- $out.= ' selected="selected">';
- }
- else
- {
- $out.= '<option value="'.$obj->rowid.'"';
- if ($disableline) $out.= ' disabled="disabled"';
- $out.= '>';
- }
- $out.= $userstatic->getFullName($langs);
- if(! empty($conf->multicompany->enabled) && empty($conf->multicompany->transverse_mode) && $conf->entity == 1 && $user->admin && ! $user->entity)
- {
- if ($obj->admin && ! $obj->entity) $out.=" (".$langs->trans("AllEntities").")";
- else $out.=" (".$obj->label.")";
- }
- //if ($obj->admin) $out.= ' *';
- if ($conf->global->MAIN_SHOW_LOGIN) $out.= ' ('.$obj->login.')';
- $out.= '</option>';
- $i++;
- }
- }
- else
- {
- $out.= '<select class="flat" name="'.$htmlname.'" disabled="disabled">';
- $out.= '<option value="">'.$langs->trans("None").'</option>';
- }
- $out.= '</select>';
- }
- else
- {
- dol_print_error($this->db);
- }
- return $out;
- }
- /**
- * Return list of products for customer in Ajax if Ajax activated or go to select_produits_do
- *
- * @param int $selected Preselected products
- * @param string $htmlname Name of HTML seletc field (must be unique in page)
- * @param int $filtertype Filter on product type (''=nofilter, 0=product, 1=service)
- * @param int $limit Limit on number of returned lines
- * @param int $price_level Level of price to show
- * @param int $status -1=Return all products, 0=Products not on sell, 1=Products on sell
- * @param int $finished 2=all, 1=finished, 0=raw material
- * @param string $selected_input_value Value of preselected input text (with ajax)
- * @return void
- */
- function select_produits($selected='',$htmlname='productid',$filtertype='',$limit=20,$price_level=0,$status=1,$finished=2,$selected_input_value='',$hidelabel=0)
- {
- global $langs,$conf;
- $price_level = (! empty($price_level) ? $price_level : 0);
- if ($conf->global->PRODUIT_USE_SEARCH_TO_SELECT)
- {
- if ($selected && empty($selected_input_value))
- {
- require_once(DOL_DOCUMENT_ROOT."/product/class/product.class.php");
- $product = new Product($this->db);
- $product->fetch($selected);
- $selected_input_value=$product->ref;
- }
- // mode=1 means customers products
- print ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT.'/product/ajaxproducts.php', 'htmlname='.$htmlname.'&outjson=1&price_level='.$price_level.'&type='.$filtertype.'&mode=1&status='.$status.'&finished='.$finished, $conf->global->PRODUIT_USE_SEARCH_TO_SELECT);
- if (! $hidelabel) print $langs->trans("RefOrLabel").' : ';
- print '<input type="text" size="20" name="search_'.$htmlname.'" id="search_'.$htmlname.'" value="'.$selected_input_value.'" />';
- }
- else
- {
- $this->select_produits_do($selected,$htmlname,$filtertype,$limit,$price_level,'',$status,$finished,0);
- }
- print '<br>';
- }
- /**
- * Return list of products for a customer
- *
- * @param int $selected Preselected product
- * @param string $htmlname Name of select html
- * @param string $filtertype Filter on product type (''=nofilter, 0=product, 1=service)
- * @param int $limit Limite sur le nombre de lignes retournees
- * @param int $price_level Level of price to show
- * @param string $filterkey Filter on product
- * @param int $status -1=Return all products, 0=Products not on sell, 1=Products on sell
- * @param int $finished Filter on finished field: 2=No filter
- * @param int $disableout Disable print output
- * @return array Array of keys for json
- */
- function select_produits_do($selected='',$htmlname='productid',$filtertype='',$limit=20,$price_level=0,$filterkey='',$status=1,$finished=2,$disableout=0)
- {
- 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 IN (0,'.(! empty($conf->entities['product']) ? $conf->entities['product'] : $conf->entity).')';
- 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 ($filterkey && $filterkey != '')
- {
- if (! empty($conf->global->PRODUCT_DONOTSEARCH_ANYWHERE)) // Can use index
- {
- $sql.=" AND (p.ref LIKE '".$filterkey."%' OR p.label LIKE '".$filterkey."%'";
- if ($conf->global->MAIN_MULTILANGS) $sql.=" OR pl.label LIKE '".$filterkey."%'";
- $sql.=")";
- }
- else
- {
- $sql.=" AND (p.ref LIKE '%".$filterkey."%' OR p.label LIKE '%".$filterkey."%'";
- if ($conf->global->MAIN_MULTILANGS) $sql.=" OR pl.label LIKE '%".$filterkey."%'";
- $sql.=")";
- }
- }
- $sql.= $db->order("p.ref");
- $sql.= $db->plimit($limit);
- // Build output string
- $outselect='';
- $outjson=array();
- 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.='<select class="flat" name="'.$htmlname.'" id="'.$htmlname.'">';
- $outselect.='<option value="0" selected="selected"> </option>';
- $i = 0;
- while ($num && $i < $num)
- {
- $outkey='';
- $outval='';
- $outref='';
- $objp = $this->db->fetch_object($result);
- $label=$objp->label;
- if (! empty($objp->label_translated)) $label=$objp->label_translated;
- if ($filterkey && $filterkey != '') $label=preg_replace('/('.preg_quote($filterkey).')/i','<strong>$1</strong>',$label,1);
- $outkey=$objp->rowid;
- $outref=$objp->ref;
- $opt = '<option value="'.$objp->rowid.'"';
- $opt.= ($objp->rowid == $selected)?' selected="selected"':'';
- 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.= '>';
- $opt.= $langs->convToOutputCharset($objp->ref).' - '.$langs->convToOutputCharset(dol_trunc($label,32)).' - ';
- $objRef = $objp->ref;
- if ($filterkey && $filterkey != '') $objRef=preg_replace('/('.preg_quote($filterkey).')/i','<strong>$1</strong>',$objRef,1);
- $outval.=$objRef.' - '.dol_trunc($label,32).' - ';
- $found=0;
- $currencytext=$langs->trans("Currency".$conf->monnaie);
- $currencytextnoent=$langs->transnoentities("Currency".$conf->monnaie);
- if (dol_strlen($currencytext) > 10) $currencytext=$conf->monnaie; // If text is too long, we use the short code
- if (dol_strlen($currencytextnoent) > 10) $currencytextnoent=$conf->monnaie; // If text is too long, we use the short code
- // Multiprice
- if ($price_level …
Large files files are truncated, but you can click here to view the full file