* Copyright (C) 2004-2011 Laurent Destailleur * Copyright (C) 2004 Benoit Mortier * Copyright (C) 2004 Sebastien Di Cintio * Copyright (C) 2004 Eric Seigne * Copyright (C) 2005-2011 Regis Houssin * Copyright (C) 2006 Andre Cianfarani * Copyright (C) 2006 Marc Barilley/Ocebo * Copyright (C) 2007 Franky Van Liedekerke * Copyright (C) 2007 Patrick Raguin * Copyright (C) 2010 Juanjo Menent * Copyright (C) 2010 Philippe Grand * Copyright (C) 2011 Herve Prot * * 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 . */ /** * \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.= '
'; $ret.= $langs->trans($text); $ret.= '
'."\n"; } else { $ret.= $langs->trans($text); } } else { $ret.=''; if (GETPOST('action') != 'edit'.$htmlname && $perm) $ret.=''; $ret.='
'; $ret.=$langs->trans($text); $ret.='id.'">'.img_edit($langs->trans('Edit'),1).'
'; } 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.='
'; $ret.=''; $ret.=''; $ret.=''; $ret.=''; $ret.=''; if ($typeofdata != 'day' && $typeofdata != 'datepicker') $ret.=''; $ret.='
'; if (preg_match('/^(string|email|numeric)/',$typeofdata)) { $tmp=explode(':',$typeofdata); $ret.=''; } else if ($typeofdata == 'text' || $typeofdata == 'textarea' || $typeofdata == 'note') { $ret.=''; } 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.='
'."\n"; $ret.='
'."\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('/
.*/','',$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.= ''."\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.= ''."\n"; } else { $inputType = 'textarea'; } } $out.= ''."\n"; $out.= ''."\n"; $out.= ''."\n"; $out.= ''."\n"; $out.= ''."\n"; $out.= ''."\n"; //$out.= ''."\n"; //$out.= ''."\n"; $out.= '
'.$value.'
'."\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.=''; 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.''; } } if (empty($notabs)) $s.='
'; return $s; } /** * Show a text with a picto and a tooltip on picto * * @param string $text Text to show * @param string $htmltooltip Content of tooltip * @param int $direction 1=Icon is after text, -1=Icon is before text, 0=no icon * @param string $type Type of picto (info, help, warning, superadmin...) * @param string $extracss Add a CSS style to td tags * @param int $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.= ''; } 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 ''; } /** * Return list of social contributions. * Use mysoc->country_id or mysoc->country_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->country_id) && empty($mysoc->country_code)) { dol_print_error('','Call to select_type_socialcontrib with mysoc country not yet defined'); exit; } if (! empty($mysoc->country_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->country_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->country_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 ''; if ($user->admin && $help) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionnarySetup"),1); } else { print $langs->trans("ErrorNoSocialContributionForSellerCountry",$mysoc->country_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 ''; //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 ''; } } /** * 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 ''; 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 IN (".getEntity('societe', 1).")"; 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.= ''; } 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 ''; 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 as 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(get_class($this)."::select_contacts sql=".$sql); $resql=$this->db->query($sql); if ($resql) { $num=$this->db->num_rows($resql); if ($num == 0) return 0; if ($htmlname != 'none') print ''; } return $num; } else { dol_print_error($this->db); return -1; } } /** * 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 as lastname, 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.= ''; $out.= ''; } $out.= ''; } 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 ''; } else { $this->select_produits_do($selected,$htmlname,$filtertype,$limit,$price_level,'',$status,$finished,0); } print '
'; } /** * 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 ('.getEntity('product', 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 ($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.=''; $this->db->free($result); if (empty($disableout)) print $outselect; return $outjson; } else { dol_print_error($db); } } /** * Return list of products for customer in Ajax if Ajax activated or go to select_produits_fournisseurs_do * * @param int $socid Id third party * @param string $selected Preselected product * @param string $htmlname Name of HTML Select * @param string $filtertype Filter on product type (''=nofilter, 0=product, 1=service) * @param string $filtre For a SQL filter * @return void */ function select_produits_fournisseurs($socid,$selected='',$htmlname='productid',$filtertype='',$filtre) { global $langs,$conf; global $price_level, $status, $finished; if ($conf->global->PRODUIT_USE_SEARCH_TO_SELECT) { // mode=2 means suppliers products print ajax_autocompleter('', $htmlname, DOL_URL_ROOT.'/product/ajaxproducts.php', ($socid > 0?'socid='.$socid.'&':'').'htmlname='.$htmlname.'&outjson=1&price_level='.$price_level.'&type='.$filtertype.'&mode=2&status='.$status.'&finished='.$finished, $conf->global->PRODUIT_USE_SEARCH_TO_SELECT); print $langs->trans("RefOrLabel").' : '; print '
'; } else { $this->select_produits_fournisseurs_do($socid,$selected,$htmlname,$filtertype,$filtre,'',-1,0); } } /** * 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 * @param status -1=Return all products, 0=Products not on sell, 1=Products on sell * @param disableout Disable print output * @return array Array of keys for json */ function select_produits_fournisseurs_do($socid,$selected='',$htmlname='productid',$filtertype='',$filtre='',$filterkey='',$statut=-1,$disableout=0) { global $langs,$conf; $langs->load('stocks'); $sql = "SELECT p.rowid, p.label, p.ref, p.price, p.duration,"; $sql.= " pfp.ref_fourn, 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_price as pfp ON p.rowid = pfp.fk_product"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON pfp.fk_soc = s.rowid"; $sql.= " WHERE p.entity = ".$conf->entity; $sql.= " AND p.tobuy = 1"; if ($socid) $sql.= " AND pfp.fk_soc = ".$socid; if (strval($filtertype) != '') $sql.=" AND p.fk_product_type=".$filtertype; if (! empty($filtre)) $sql.=" ".$filtre; // Add criteria on ref/label if ($filterkey && $filterkey != '') { if (! empty($conf->global->PRODUCT_DONOTSEARCH_ANYWHERE)) { $sql.=" AND (pfp.ref_fourn LIKE '".$filterkey."%' OR p.ref LIKE '".$filterkey."%' OR p.label LIKE '".$filterkey."%')"; } else { $sql.=" AND (pfp.ref_fourn LIKE '%".$filterkey."%' OR p.ref LIKE '%".$filterkey."%' OR p.label LIKE '%".$filterkey."%')"; } } $sql.= " ORDER BY pfp.ref_fourn DESC"; // Build output string $outselect=''; $outjson=array(); dol_syslog(get_class($this)."::select_produits_fournisseurs_do sql=".$sql,LOG_DEBUG); $result=$this->db->query($sql); if ($result) { $num = $this->db->num_rows($result); $outselect.=''; $this->db->free($result); if (empty($disableout)) print $outselect; return $outjson; } else { dol_print_error($this->db); } } /** * Return list of suppliers prices for a product * * @param int $productid Id of product * @param string $htmlname Name of HTML field * @return void */ 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.= " pfp.ref_fourn, 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_price as pfp ON p.rowid = pfp.fk_product"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON pfp.fk_soc = s.rowid"; $sql.= " WHERE p.entity = ".$conf->entity; $sql.= " AND p.tobuy = 1"; $sql.= " AND s.fournisseur = 1"; $sql.= " AND p.rowid = ".$productid; $sql.= " ORDER BY s.nom, pfp.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 = ''; $this->db->free($result); } return $form; } else { dol_print_error($this->db); } } /** * Return list of delivery address * * @param string $selected Id contact pre-selectionn * @param int $socid Id of company * @param string $htmlname Name of HTML field * @param int $showempty Add an empty field * @return void */ 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 ''; return $num; } else { dol_print_error($this->db); } } /** * 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 (count($this->cache_conditions_paiements)) return 0; // Cache deja charge $sql = "SELECT rowid, code, libelle"; $sql.= " FROM ".MAIN_DB_PREFIX.'c_payment_term'; $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; } } /** * Charge dans cache la liste des délais de livraison possibles * * @return int Nb lignes chargees, 0 si deja chargees, <0 si ko */ function load_cache_availability() { global $langs; if (count($this->cache_availability)) return 0; // Cache deja charge $sql = "SELECT rowid, code, label"; $sql.= " FROM ".MAIN_DB_PREFIX.'c_availability'; $sql.= " WHERE active=1"; $sql.= " ORDER BY rowid"; dol_syslog('Form::load_cache_availability 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=($langs->trans("AvailabilityType".$obj->code)!=("AvailabilityType".$obj->code)?$langs->trans("AvailabilityType".$obj->code):($obj->label!='-'?$obj->label:'')); $this->cache_availability[$obj->rowid]['code'] =$obj->code; $this->cache_availability[$obj->rowid]['label']=$label; $i++; } return 1; } else { dol_print_error($this->db); return -1; } } /** * Retourne la liste des types de delais de livraison possibles * * @param selected Id du type de delais pre-selectionne * @param htmlname Nom de la zone select * @param filtertype To add a filter * @param addempty Add empty entry */ function select_availability($selected='',$htmlname='availid',$filtertype='',$addempty=0) { global $langs,$user; $this->load_cache_availability(); print ''; if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionnarySetup"),1); } /** * Load into cache cache_demand_reason, array of input reasons * * @return int Nb of lines loaded, 0 if already loaded, <0 if ko */ function load_cache_demand_reason() { global $langs; if (count($this->cache_demand_reason)) return 0; // Cache already loaded $sql = "SELECT rowid, code, label"; $sql.= " FROM ".MAIN_DB_PREFIX.'c_input_reason'; $sql.= " WHERE active=1"; $sql.= " ORDER BY rowid"; dol_syslog('Form::load_cache_demand_reason sql='.$sql,LOG_DEBUG); $resql = $this->db->query($sql); if ($resql) { $num = $this->db->num_rows($resql); $i = 0; $tmparray=array(); while ($i < $num) { $obj = $this->db->fetch_object($resql); // Si traduction existe, on l'utilise, sinon on prend le libelle par defaut $label=($langs->trans("DemandReasonType".$obj->code)!=("DemandReasonType".$obj->code)?$langs->trans("DemandReasonType".$obj->code):($obj->label!='-'?$obj->label:'')); $tmparray[$obj->rowid]['id'] =$obj->rowid; $tmparray[$obj->rowid]['code'] =$obj->code; $tmparray[$obj->rowid]['label']=$label; $i++; } $this->cache_demand_reason=dol_sort_array($tmparray,'label', $order='asc'); unset($tmparray); return 1; } else { dol_print_error($this->db); return -1; } } /** * Return list of events that triggered an object creation * * @param selected Id du type d'origine pre-selectionne * @param htmlname Nom de la zone select * @param exclude To exclude a code value (Example: SRC_PROP) * @param addempty Add an empty entry */ function select_demand_reason($selected='',$htmlname='demandreasonid',$exclude='',$addempty=0) { global $langs,$user; $this->load_cache_demand_reason(); print ''; if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionnarySetup"),1); } /** * 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 (count($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; } } /** * 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 ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionnarySetup"),1); } /** * Return list of payment methods * * @param selected Id du mode de paiement pre-selectionne * @param htmlname Nom de la zone select * @param filtertype To filter on field type in llx_c_paiement (array('code'=>xx,'label'=>zz)) * @param format 0=id+libelle, 1=code+code, 2=code+libelle, 3=id+code * @param empty 1=peut etre vide, 0 sinon * @param noadmininfo 0=Add admin info, 1=Disable admin info * @param maxlength Max length of label */ function select_types_paiements($selected='',$htmlname='paiementtype',$filtertype='',$format=0, $empty=0, $noadmininfo=0,$maxlength=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 ($user->admin && ! $noadmininfo) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionnarySetup"),1); } /** * Selection HT or 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); } /** * Selection HT or 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.= ''; return $return; } /** * Return combo list of differents status of a proposal * Values are id of table c_propalst * * @param selected etat pre-selectionne * @param short Use short labels */ function select_propal_statut($selected='',$short=0) { global $langs; $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 ''; } else { dol_print_error($this->db); } } /** * Return a HTML select list of bank accounts * * @param selected Id account pre-selected * @param htmlname Name of select zone * @param statut Status of searched accounts (0=open, 1=closed) * @param filtre To filter list * @param useempty 1=Add an empty value in list, 2=Add an empty value in list only if there is more than 2 entries. * @param moreattrib To add more attribute on select */ function select_comptes($selected='',$htmlname='accountid',$statut=0,$filtre='',$useempty=0,$moreattrib='') { global $langs, $conf; $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 label"; 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 '"; } else { print $langs->trans("NoActiveBankAccountDefined"); } } else { dol_print_error($this->db); } } /** * Return list of categories having choosed type * * @param type Type de categories (0=product, 1=supplier, 2=customer, 3=member) * @param selected Id of category preselected * @param select_name HTML field name * @param maxlength Maximum length for labels * @param excludeafterid Exclude all categories after this leaf in category tree. */ function select_all_categories($type, $selected='', $select_name="", $maxlength=64, $excludeafterid=0) { global $langs; $langs->load("categories"); if ($select_name=="") $select_name="catMere"; $cat = new Categorie($this->db); $cate_arbo = $cat->get_full_arbo($type,$excludeafterid); $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 * @param height Force height of box * @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, $height=170, $width=500) { print $this->formconfirm($page, $title, $question, $action, $formquestion, $selectedchoice, $useajax, $height, $width); } /** * Show a confirmation HTML form or AJAX popup * * @param string $page Url of page to call if confirmation is OK * @param string $title Title * @param string $question Question * @param string $action Action * @param array $formquestion An array with complementary inputs to add into forms: array(array('label'=> ,'type'=> , )) * @param string $selectedchoice "" or "no" or "yes" * @param int $useajax 0=No, 1=Yes, 2=Yes but submit page with &confirm=no if choice is No, 'xxx'=preoutput confirm box with div id=dialog-confirm-xxx * @param int $height Force height of box * @return string 'ajax' if a confirm ajax popup is shown, 'html' if it's an html form */ function formconfirm($page, $title, $question, $action, $formquestion='', $selectedchoice="", $useajax=0, $height=170, $width=500) { global $langs,$conf; $more=''; $formconfirm=''; $inputarray=array(); if (is_array($formquestion) && count($formquestion) > 0) { $more.=''."\n"; $more.=''."\n"; foreach ($formquestion as $key => $input) { if (is_array($input)) { if ($input['type'] == 'text') { $more.=''."\n"; } else if ($input['type'] == 'password') { $more.=''."\n"; } else if ($input['type'] == 'select') { $more.=''."\n"; } else if ($input['type'] == 'checkbox') { $more.=''; $more.=''; if ($i==0) $more.=''; else $more.=''; $more.=''."\n"; } array_push($inputarray,$input['name']); } } $more.='
'.$formquestion['text'].'
'.$input['label'].'
'.$input['label'].'
'; if (! empty($input['label'])) $more.=$input['label'].''; $more.=$this->selectarray($input['name'],$input['values'],$input['default'],1); $more.='
'.$input['label'].' '; $more.=' $selval) { $more.='
'.$input['label'].' '; $more.=$input['value']; $more.='
'."\n"; } $formconfirm.= "\n\n"; if ($useajax && $conf->use_javascript_ajax) { $autoOpen=true; $dialogconfirm='dialog-confirm'; if (! is_int($useajax)) { $button=$useajax; $useajax=1; $autoOpen=false; $dialogconfirm.='-'.$button; } $pageyes=$page.'&action='.$action.'&confirm=yes'; $pageno=($useajax == 2?$page.'&confirm=no':''); // New code using jQuery only $formconfirm.= ''."\n"; $formconfirm.= ''; $formconfirm.= "\n"; } else { $formconfirm.= '
'."\n"; $formconfirm.= ''; $formconfirm.= ''."\n"; $formconfirm.= ''."\n"; // Ligne titre $formconfirm.= ''."\n"; // Ligne formulaire if ($more) { $formconfirm.=''."\n"; } // Ligne message $formconfirm.= ''; $formconfirm.= ''; $formconfirm.= ''; $formconfirm.= ''; $formconfirm.= ''."\n"; $formconfirm.= '
'.img_picto('','recent').' '.$title.'
'."\n"; $formconfirm.=$more; $formconfirm.='
'.$question.''; $newselectedchoice=empty($selectedchoice)?"no":$selectedchoice; $formconfirm.= $this->selectyesno("confirm",$newselectedchoice); $formconfirm.= '
'."\n"; if (is_array($formquestion)) { foreach ($formquestion as $key => $input) { if ($input['type'] == 'hidden') $formconfirm.= ''; } } $formconfirm.= "
\n"; $formconfirm.= '
'; } $formconfirm.= "\n"; return $formconfirm; } /** * Show a form to select a project * * @param int $page Page * @param int $socid Id third party * @param int $selected Id pre-selected project * @param string $htmlname Name of select field * @return void */ function form_project($page, $socid, $selected='', $htmlname='projectid') { global $langs; require_once(DOL_DOCUMENT_ROOT."/core/lib/project.lib.php"); $langs->load("project"); if ($htmlname != "none") { print '
'; print ''; print ''; print ''; print ''; print ''; print '
'; //print "$socid,$selected,$htmlname"; select_projects($socid,$selected,$htmlname); print '
'; } else { if ($selected) { $projet = new Project($this->db); $projet->fetch($selected); //print ''.$projet->title.''; print $projet->getNomUrl(0,'',1); } else { print " "; } } } /** * Show a form to select payment conditions * * @param page Page * @param selected Id condition pre-selectionne * @param htmlname Name of select html field * @param addempty Ajoute entree vide * @return void */ function form_conditions_reglement($page, $selected='', $htmlname='cond_reglement_id', $addempty=0) { global $langs; if ($htmlname != "none") { print '
'; print ''; print ''; print ''; print ''; print ''; print '
'; $this->select_conditions_paiements($selected,$htmlname,-1,$addempty); print '
'; } else { if ($selected) { $this->load_cache_conditions_paiements(); print $this->cache_conditions_paiements[$selected]['label']; } else { print " "; } } } /** * Show a form to select a delivery delay * * @param page Page * @param selected Id condition pre-selectionne * @param htmlname Name of select html field * @param addempty Ajoute entree vide * @return void */ function form_availability($page, $selected='', $htmlname='availability', $addempty=0) { global $langs; if ($htmlname != "none") { print '
'; print ''; print ''; print ''; print ''; print ''; print '
'; $this->select_availability($selected,$htmlname,-1,$addempty); print '
'; } else { if ($selected) { $this->load_cache_availability(); print $this->cache_availability[$selected]['label']; } else { print " "; } } } /** * Show a select form to select origin * * @param page Page * @param selected Id condition pre-selectionne * @param htmlname Name of select html field * @param addempty Add empty entry * @return void */ function form_demand_reason($page, $selected='', $htmlname='demandreason', $addempty=0) { global $langs; if ($htmlname != "none") { print '
'; print ''; print ''; print ''; print ''; print ''; print '
'; $this->select_demand_reason($selected,$htmlname,-1,$addempty); print '
'; } else { if ($selected) { $this->load_cache_demand_reason(); foreach ($this->cache_demand_reason as $key => $val) { if ($val['id'] == $selected) { print $val['label']; break; } } } else { print " "; } } } /** * Show a form to select a date * * @param page Page * @param selected Date preselected * @param htmlname Name of input html field * @return void */ function form_date($page, $selected='', $htmlname) { global $langs; if ($htmlname != "none") { print '
'; print ''; print ''; print ''; print ''; print ''; print '
'; print $this->select_date($selected,$htmlname,0,0,1,'form'.$htmlname); print '
'; } else { if ($selected) { $this->load_cache_types_paiements(); print $this->cache_types_paiements[$selected]['label']; } else { print " "; } } } /** * Show a select form to choose a user * * @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 * @return void */ function form_users($page, $selected='', $htmlname='userid', $exclude='', $include='') { global $langs; if ($htmlname != "none") { print '
'; print ''; print ''; print ''; print ''; print ''; print '
'; print $this->select_users($selected,$htmlname,1,$exclude,0,$include); 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 " "; } } } /** * Affiche formulaire de selection des modes de reglement * * @param page Page * @param selected Id mode pre-selectionne * @param htmlname Name of select html field * @return void */ function form_modes_reglement($page, $selected='', $htmlname='mode_reglement_id') { global $langs; if ($htmlname != "none") { print '
'; print ''; print ''; print ''; print ''; print ''; print '
'; $this->select_types_paiements($selected,$htmlname); print '
'; } else { if ($selected) { $this->load_cache_types_paiements(); print $this->cache_types_paiements[$selected]['label']; } else { print " "; } } } /** * Show a select box with available absolute discounts * * @param string $page Page URL where form is shown * @param int $selected Value pre-selected * @param string $htmlname Nom du formulaire select. Si none, non modifiable * @param int $socid Third party id * @param float $amount Total amount available * @param string $filter SQL filter on discounts * @param int $maxvalue Max value for lines that can be selected * @param string $more More string to add * @return void */ function form_remise_dispo($page, $selected='', $htmlname='remise_id',$socid, $amount, $filter='', $maxvalue=0, $more='') { global $conf,$langs; if ($htmlname != "none") { print '
'; print ''; print ''; print ''; print ''; print ''; print '
'; if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) { if (! $filter || $filter=="fk_facture_source IS NULL") print $langs->trans("CompanyHasAbsoluteDiscount",price($amount),$langs->transnoentities("Currency".$conf->currency)).': '; // If we want deposit to be substracted to payments only and not to total of final invoice else print $langs->trans("CompanyHasCreditNote",price($amount),$langs->transnoentities("Currency".$conf->currency)).': '; } else { if (! $filter || $filter=="fk_facture_source IS NULL OR (fk_facture_source IS NOT NULL AND description='(DEPOSIT)')") print $langs->trans("CompanyHasAbsoluteDiscount",price($amount),$langs->transnoentities("Currency".$conf->currency)).': '; else print $langs->trans("CompanyHasCreditNote",price($amount),$langs->transnoentities("Currency".$conf->currency)).': '; } $newfilter='fk_facture IS NULL AND fk_facture_line IS NULL'; // Remises disponibles if ($filter) $newfilter.=' AND ('.$filter.')'; $nbqualifiedlines=$this->select_remises($selected,$htmlname,$newfilter,$socid,$maxvalue); print ''; if ($nbqualifiedlines > 0) { print '   '; } if ($more) print $more; print '
'; } else { if ($selected) { print $selected; } else { print "0"; } } } /** * Affiche formulaire de selection des contacts * * @param page Page * @param selected Id contact pre-selectionne * @param htmlname Nom du formulaire select * @return void */ function form_contacts($page, $societe, $selected='', $htmlname='contactidp') { global $langs; if ($htmlname != "none") { print '
'; print ''; print ''; print ''; print ''; print ''; print '
'; $num=$this->select_contacts($societe->id, $selected, $htmlname); if ($num==0) { print 'Cette societe n\'a pas de contact, veuillez en cr�er un avant de faire votre proposition commerciale
'; print ''.$langs->trans('AddContact').''; } 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 " "; } } } /** * Affiche formulaire de selection des tiers * * @param page Page * @param selected Id contact pre-selectionne * @param htmlname Nom du formulaire select * @return void */ function form_thirdparty($page, $selected='', $htmlname='socid') { global $langs; if ($htmlname != "none") { print '
'; print ''; print ''; print ''; print ''; print ''; print '
'; $num=$this->select_societes($selected , $htmlname); print '
'; } else { if ($selected) { require_once(DOL_DOCUMENT_ROOT ."/societe/class/societe.class.php"); $soc = new Societe($this->db); $soc->fetch($selected); print $soc->getNomUrl($langs); } else { print " "; } } } /** * Show form to select addresse * * @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 * @return void * @deprecated */ function form_address($page, $selected='', $socid, $htmlname='address_id', $origin='', $originid='') { global $langs,$conf; if ($htmlname != "none") { print '
'; print ''; print ''; print ''; print ''; print '
'; $this->select_address($selected, $socid, $htmlname, 1); print ''; $langs->load("companies"); print '   '.$langs->trans("AddAddress").''; 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 ''.$address->label.''; } else { print " "; } } } /** * Retourne la liste des devises, dans la langue de l'utilisateur * * @param selected code devise pre-selectionne * @param htmlname nom de la liste deroulante * @return void */ function select_currency($selected='',$htmlname='currency_id') { print $this->selectcurrency($selected,$htmlname); } /** * Retourne la liste des devises, dans la langue de l'utilisateur * * @param selected code devise pre-selectionne * @param htmlname nom de la liste deroulante */ function selectcurrency($selected='',$htmlname='currency_id') { global $conf,$langs,$user; $langs->load("dict"); $out=''; $currencyArray=array(); $label=array(); if ($selected=='euro' || $selected=='euros') $selected='EUR'; // Pour compatibilite $sql = "SELECT code_iso, label"; $sql.= " FROM ".MAIN_DB_PREFIX."c_currencies"; $sql.= " WHERE active = 1"; $sql.= " ORDER BY code_iso ASC"; $resql=$this->db->query($sql); if ($resql) { $out.= ''; if ($user->admin) $out.= info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionnarySetup"),1); return $out; } else { dol_print_error($this->db); } } /** * Output an HTML select vat rate * * @param htmlname 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 Miscellaneous information on line * @param type ''=Unknown, 0=Product, 1=Service (Used if idprod not defined) * 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. * @deprecated * @return void */ function select_tva($htmlname='tauxtva', $selectedrate='', $societe_vendeuse='', $societe_acheteuse='', $idprod=0, $info_bits=0, $type='') { print $this->load_tva($htmlname, $selectedrate, $societe_vendeuse, $societe_acheteuse, $idprod, $info_bits, $type); } /** * Output an HTML select vat rate * * @param htmlname 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 Miscellaneous information on line (1 for NPR) * @param type ''=Unknown, 0=Product, 1=Service (Used if idprod not defined) * 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. * @return void */ function load_tva($htmlname='tauxtva', $selectedrate='', $societe_vendeuse='', $societe_acheteuse='', $idprod=0, $info_bits=0, $type='') { 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); // Check parameters if (is_object($societe_vendeuse) && ! $societe_vendeuse->country_code) { if ($societe_vendeuse->id == $mysoc->id) { $return.= ''.$langs->trans("ErrorYourCountryIsNotDefined").''; } else { $return.= ''.$langs->trans("ErrorSupplierCountryIsNotDefined").''; } return $return; } //var_dump($societe_acheteuse); //print "name=$name, selectedrate=$selectedrate, seller=".$societe_vendeuse->country_code." buyer=".$societe_acheteuse->country_code." buyer is company=".$societe_acheteuse->isACompany()." idprod=$idprod, info_bits=$info_bits type=$type"; //exit; // Get list of all VAT rates to show // First we defined code_pays to use to find list if (is_object($societe_vendeuse)) { $code_pays="'".$societe_vendeuse->country_code."'"; } else { $code_pays="'".$mysoc->country_code."'"; // Pour compatibilite ascendente } if (! empty($conf->global->SERVICE_ARE_ECOMMERCE_200238EC)) // If option to have vat for end customer for services is on { if (! $societe_vendeuse->isInEEC() && $societe_acheteuse->isInEEC() && ! $societe_acheteuse->isACompany()) { // We also add the buyer if (is_numeric($type)) { if ($type == 1) // We know product is a service { $code_pays.=",'".$societe_acheteuse->country_code."'"; } } else if (! $idprod) // We don't know type of product { $code_pays.=",'".$societe_acheteuse->country_code."'"; } else { $prodstatic=new Product($this->db); $prodstatic->fetch($idprod); if ($prodstatic->type == 1) // We know product is a service { $code_pays.=",'".$societe_acheteuse->country_code."'"; } } } } // Now we get list $sql = "SELECT DISTINCT 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"; $sql.= " AND t.active = 1"; $sql.= " AND p.code in (".$code_pays.")"; $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 || dol_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 || dol_strlen($defaulttx) == 0) { $defaulttx = $txtva[count($txtva)-1]; } $nbdetaux = count($txtva); if ($nbdetaux > 0) { $return.= ''; } return $return; } /** * Show a HTML widget to input a date or combo list for day, month, years and optionnaly hours and minutes * Fields are preselected with : * - set_time date (Local PHP server timestamps or date format YYYY-MM-DD or YYYY-MM-DD HH:MM) * - local date of PHP server if set_time is '' * - Empty (fields empty) if set_time is -1 (in this case, parameter empty must also have value 1) * * @param set_time Pre-selected date (must be a local PHP server timestamp) * @param prefix Prefix for fields name * @param h 1=Show also hours * @param m 1=Show also minutes * @param empty 0=Fields required, 1=Empty input is allowed * @param form_name Form name. Used by popup dates. * @param d 1=Show days, month, years * @param addnowbutton Add a button "Now" * @param nooutput Do not output html string but return it * @param disabled Disable input fields * @param fullday When a checkbox with this html name is on, hour and day are set with 00:00 or 23:59 * @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, $fullday='') { 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 = dol_now('tzuser'); // Analysis of the pre-selection date if (preg_match('/^([0-9]+)\-([0-9]+)\-([0-9]+)\s?([0-9]+)?:?([0-9]+)?/',$set_time,$reg)) { // Date format 'YYYY-MM-DD' or '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) { // Show date with popup if ($conf->use_javascript_ajax && (empty($conf->global->MAIN_POPUP_CALENDAR) || $conf->global->MAIN_POPUP_CALENDAR != "none")) { //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); $formated_date=dol_print_date($set_time,$langs->trans("FormatDateShort")); // FormatDateShort for dol_print_date/FormatDateShortJava that is same for javascript } // Calendrier popup version eldy if (empty($conf->global->MAIN_POPUP_CALENDAR) || $conf->global->MAIN_POPUP_CALENDAR == "eldy") { // Zone de saisie manuelle de la date $retstring.='trans("FormatDateShortJava").'\'); "'; // FormatDateShort for dol_print_date/FormatDateShortJava that is same for javascript $retstring.='>'; // Icone calendrier if (! $disabled) { $retstring.=''; } $retstring.=''."\n"; $retstring.=''."\n"; $retstring.=''."\n"; } else { print "Bad value of calendar"; } } // Show date with combo selects if (empty($conf->use_javascript_ajax) || $conf->global->MAIN_POPUP_CALENDAR == "none") { // Day $retstring.=''; if ($empty || $set_time == -1) { $retstring.=''; } for ($day = 1 ; $day <= 31; $day++) { if ($day == $sday) { $retstring.=""; } $retstring.=""; $retstring.=''; if ($empty || $set_time == -1) { $retstring.=''; } // Month for ($month = 1 ; $month <= 12 ; $month++) { $retstring.='"; } $retstring.=""; // Year if ($empty || $set_time == -1) { $retstring.=''; } else { $retstring.=''; for ($year = $syear - 5; $year < $syear + 10 ; $year++) { if ($year == $syear) { $retstring.=""; } $retstring.="\n"; } } } if ($d && $h) $retstring.=' '; if ($h) { // Show hour $retstring.=''; if ($empty) $retstring.=''; for ($hour = 0; $hour < 24; $hour++) { if (dol_strlen($hour) < 2) { $hour = "0" . $hour; } if ($hour == $shour) { $retstring.=""; } else { $retstring.=""; } } $retstring.=""; $retstring.="H\n"; } if ($m) { // Show minutes $retstring.=''; if ($empty) $retstring.=''; for ($min = 0; $min < 60 ; $min++) { if (dol_strlen($min) < 2) { $min = "0" . $min; } if ($min == $smin) { $retstring.=""; } else { $retstring.=""; } } $retstring.=""; $retstring.="M\n"; } // Add a "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 (empty($conf->global->MAIN_POPUP_CALENDAR) || $conf->global->MAIN_POPUP_CALENDAR == "eldy") { $base=DOL_URL_ROOT.'/core/lib/'; $reset_scripts .= 'resetDP(\''.$base.'\',\''.$prefix.'\',\''.$langs->trans("FormatDateShortJava").'\',\''.$langs->defaultlang.'\');'; } 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) { if ($fullday) $reset_scripts .= " if (jQuery('#fullday:checked').val() == null) {"; $reset_scripts .= 'this.form.elements[\''.$prefix.'hour\'].value=formatDate(new Date(), \'HH\'); '; if ($fullday) $reset_scripts .= ' } '; } // Generate the minute part if ($m) { if ($fullday) $reset_scripts .= " if (jQuery('#fullday:checked').val() == null) {"; $reset_scripts .= 'this.form.elements[\''.$prefix.'min\'].value=formatDate(new Date(), \'mm\'); '; if ($fullday) $reset_scripts .= ' } '; } // If reset_scripts is not empty, print the button with the reset_scripts in OnClick if ($reset_scripts) { $retstring.=' '; } } if (! empty($nooutput)) return $retstring; print $retstring; return; } /** * Function to show a form to select a duration on a page * * @param string $prefix prefix * @param int $iSecond Default preselected duration (number of seconds) * @param int $disabled Disable the combo box * @return void */ function select_duration($prefix,$iSecond='',$disabled=0) { if ($iSecond) { require_once(DOL_DOCUMENT_ROOT."/core/lib/date.lib.php"); $hourSelected = ConvertSecondToTime($iSecond,'hour'); $minSelected = ConvertSecondToTime($iSecond,'min'); } print '"; print "H  "; print '"; print "M "; } /** * Show a select form from an array * * @param htmlname Name of html select area * @param array Array with key+value * @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 Translate and encode value * @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='"; return $out; } /** * Show a select form from an array * * @deprecated Use selectarray instead * @return void */ 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); } /** * Return an html string with a select combo box to choose yes or no * * @param string $name Name of html select field * @param string $value Pre-selected value * @param int $option 0 return yes/no, 1 return 1/0 * @param bool $disabled true or false * @return mixed See option */ function selectyesno($htmlname,$value='',$option=0,$disabled=false) { global $langs; $yes="yes"; $no="no"; if ($option) { $yes="1"; $no="0"; } $disabled = ($disabled ? ' disabled="disabled"' : ''); $resultyesno = ''."\n"; return $resultyesno; } /** * Return list of export templates * * @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 * @return void */ 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 '"; } else { dol_print_error($this->db); } } /** * Return a HTML area with the reference of object and a navigation 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=''; //print "$paramid,$morehtml,$shownav,$fieldid,$fieldref,$morehtmlref,$moreparam"; $object->load_previous_next_ref((isset($object->next_prev_filter)?$object->next_prev_filter:''),$fieldid); $previous_ref = $object->ref_previous?''.img_previous().'':''; $next_ref = $object->ref_next?''.img_next().'':''; //print "xx".$previous_ref."x".$next_ref; if ($previous_ref || $next_ref || $morehtml) { $ret.=''; $ret.='
'; } $ret.=$object->$fieldref; if ($morehtmlref) { $ret.=' '.$morehtmlref; } if ($morehtml) { $ret.=''.$morehtml; } if ($shownav && ($previous_ref || $next_ref)) { $ret.=''.$previous_ref.''.$next_ref; } if ($previous_ref || $next_ref || $morehtml) { $ret.='
'; } return $ret; } /** * Return HTML code to output a barcode * * @param Object &$object Object containing data to retrieve file name * @param int $width Width of photo * @return string HTML code to output barcode */ function showbarcode(&$object,$width=100) { global $conf; if (empty($object->barcode)) return ''; // Complete object if not complete if (empty($object->barcode_type_code) || empty($object->barcode_type_coder)) { $object->fetch_barcode(); } // Barcode image $url=DOL_URL_ROOT.'/viewimage.php?modulepart=barcode&generator='.urlencode($object->barcode_type_coder).'&code='.urlencode($object->barcode).'&encoding='.urlencode($object->barcode_type_code); $out =''; $out.=''; return $out; } /** * Return HTML code to output a photo * * @param string $modulepart Key to define module concerned ('societe', 'userphoto', 'memberphoto') * @param Object $object Object containing data to retrieve file name * @param int $width Width of photo * @return string HTML code to output photo */ function showphoto($modulepart,$object,$width=100) { global $conf; $ret='';$dir='';$file='';$altfile='';$email=''; if ($modulepart=='societe') { $dir=$conf->societe->dir_output; $smallfile=$object->logo; $smallfile=preg_replace('/(\.png|\.gif|\.jpg|\.jpeg|\.bmp)/i','_small\\1',$smallfile); if ($object->logo) $file=$object->id.'/logos/thumbs/'.$smallfile; } else if ($modulepart=='userphoto') { $dir=$conf->user->dir_output; if ($object->photo) $file=get_exdir($object->id,2).$object->photo; if (! empty($conf->global->MAIN_OLD_IMAGE_LINKS)) $altfile=$object->id.".jpg"; // For backward compatibility $email=$object->email; } else if ($modulepart=='memberphoto') { $dir=$conf->adherent->dir_output; if ($object->photo) $file=get_exdir($object->id,2).'photos/'.$object->photo; if (! empty($conf->global->MAIN_OLD_IMAGE_LINKS)) $altfile=$object->id.".jpg"; // For backward compatibility $email=$object->email; } if ($dir) { $cache='0'; if ($file && file_exists($dir."/".$file)) { // TODO Link to large image $ret.=''; $ret.=''; $ret.=''; } else if ($altfile && file_exists($dir."/".$altfile)) { $ret.=''; $ret.=''; $ret.=''; } else { if ($conf->gravatar->enabled && $email) { global $dolibarr_main_url_root; $ret.=''; $ret.='Photo found on Gravatar'; } else { $ret.='No photo'; } } } else dol_print_error('','Call of showphoto with wrong parameters'); /* Disabled. lightbox seems to not work. I don't know why. $ret.="\n\n"; $ret.="\n\n"; */ return $ret; } /** * Return select list of groups * * @param string $selected Id group preselected * @param string $htmlname Field name in form * @param int $show_empty 0=liste sans valeur nulle, 1=ajoute valeur inconnue * @param string $exclude Array list of groups id to exclude * @param int $disabled If select list must be disabled * @param string $include Array list of groups id to include * @param int $enableonly Array list of groups id to be enabled. All other must be disabled * @param int $force_entity Possibility to force entity * @return void */ function select_dolgroups($selected='',$htmlname='groupid',$show_empty=0,$exclude='',$disabled=0,$include='',$enableonly='',$force_entity='') { global $conf,$user,$langs; // Permettre l'exclusion de groupes if (is_array($exclude)) $excludeGroups = implode("','",$exclude); // Permettre l'inclusion de groupes if (is_array($include)) $includeGroups = implode("','",$include); $out=''; // On recherche les groupes $sql = "SELECT ug.rowid, ug.nom "; if(! empty($conf->multicompany->enabled) && $conf->entity == 1 && $user->admin && ! $user->entity) { $sql.= ", e.label"; } $sql.= " FROM ".MAIN_DB_PREFIX."usergroup as ug "; if(! empty($conf->multicompany->enabled) && $conf->entity == 1 && $user->admin && ! $user->entity) { $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."entity as e on e.rowid=ug.entity"; if ($force_entity) $sql.= " WHERE ug.entity IN (0,".$force_entity.")"; else $sql.= " WHERE ug.entity IS NOT NULL"; } else { $sql.= " WHERE ug.entity IN (0,".$conf->entity.")"; } if (is_array($exclude) && $excludeGroups) $sql.= " AND ug.rowid NOT IN ('".$excludeGroups."')"; if (is_array($include) && $includeGroups) $sql.= " AND ug.rowid IN ('".$includeGroups."')"; $sql.= " ORDER BY ug.nom ASC"; dol_syslog("Form::select_dolgroups sql=".$sql); $resql=$this->db->query($sql); if ($resql) { $num = $this->db->num_rows($resql); $i = 0; if ($num) { $out.= ''; $out.= ''; } $out.= ''; } else { dol_print_error($this->db); } return $out; } } ?>