* Copyright (C) 2004-2012 Laurent Destailleur * Copyright (C) 2004 Benoit Mortier * Copyright (C) 2004 Sebastien Di Cintio * Copyright (C) 2004 Eric Seigne * Copyright (C) 2005-2014 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-2014 Philippe Grand * Copyright (C) 2011 Herve Prot * Copyright (C) 2012-2014 Marcos García * Copyright (C) 2012 Cedric Salvador * Copyright (C) 2012-2015 Raphaël Doursenaud * Copyright (C) 2014 Alexandre Spangaro * * 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 3 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 to manage generation of HTML components * Only common components must be here. * * TODO Merge all function load_cache_* and loadCache* (except load_cache_vatrates) into one generic function loadCacheTable */ class Form { var $db; var $error; var $num; // Cache arrays var $cache_types_paiements=array(); var $cache_conditions_paiements=array(); var $cache_availability=array(); var $cache_demand_reason=array(); var $cache_types_fees=array(); var $cache_vatrates=array(); /** * 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 ('edit' prefix will be added) * @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:rows:cols', 'day' or 'datepicker', 'ckeditor:dolibarr_zzz:width:height:savemethod:1:rows:cols', 'select;xxx[:class]'...) * @param string $moreparam More param to add on a href URL * @return string HTML edit field */ function editfieldkey($text, $htmlname, $preselected, $object, $perm, $typeofdata='string', $moreparam='') { global $conf,$langs; $ret=''; // TODO change for compatibility if (! empty($conf->global->MAIN_USE_JQUERY_JEDITABLE) && ! preg_match('/^select;/',$typeofdata)) { if (! empty($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.$moreparam.'">'.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, 'amount', 'email', 'numeric:99', 'text' or 'textarea:rows:cols', 'day' or 'datepicker', 'ckeditor:dolibarr_zzz:width:height:savemethod:toolbarstartexpanded:rows:cols', 'select:xxx'...) * @param string $editvalue When in edit mode, use this value as $value instead of value (for example, you can provide here a formated price instead of value). Use '' to use same than $value * @param object $extObject External object * @param mixed $custommsg String or Array of custom messages : eg array('success' => 'MyMessage', 'error' => 'MyMessage') * @param string $moreparam More param to add on a href URL * @return string HTML edit field */ function editfieldval($text, $htmlname, $value, $object, $perm, $typeofdata='string', $editvalue='', $extObject=null, $custommsg=null, $moreparam='') { global $conf,$langs,$db; $ret=''; // Check parameters if (empty($typeofdata)) return 'ErrorBadParameter'; // When option to edit inline is activated if (! empty($conf->global->MAIN_USE_JQUERY_JEDITABLE) && ! preg_match('/^select;|datehourpicker/',$typeofdata)) // TODO add jquery timepicker { $ret.=$this->editInPlace($object, $value, $htmlname, $perm, $typeofdata, $editvalue, $extObject, $custommsg); } else { if (GETPOST('action') == 'edit'.$htmlname) { $ret.="\n"; $ret.='
'; $ret.=''; $ret.=''; $ret.=''; $ret.=''; $ret.=''; //if ($typeofdata != 'day' && $typeofdata != 'dayhour' && $typeofdata != 'datepicker' && $typeofdata != 'datehourpicker') //{ $ret.=''; //} $ret.='
'; if (preg_match('/^(string|email|numeric|amount)/',$typeofdata)) { $tmp=explode(':',$typeofdata); $ret.=''; } else if (preg_match('/^text/',$typeofdata) || preg_match('/^note/',$typeofdata)) { $tmp=explode(':',$typeofdata); $ret.=''; } else if ($typeofdata == 'day' || $typeofdata == 'datepicker') { $ret.=$this->select_date($value,$htmlname,0,0,1,'form'.$htmlname,1,0,1); } else if ($typeofdata == 'dayhour' || $typeofdata == 'datehourpicker') { $ret.=$this->select_date($value,$htmlname,1,1,1,'form'.$htmlname,1,0,1); } else if (preg_match('/^select;/',$typeofdata)) { $arraydata=explode(',',preg_replace('/^select;/','',$typeofdata)); foreach($arraydata as $val) { $tmp=explode(':',$val); $arraylist[$tmp[0]]=$tmp[1]; } $ret.=$this->selectarray($htmlname,$arraylist,$value); } 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', ($tmp[5]?$tmp[5]:0), true, true, ($tmp[6]?$tmp[6]:'20'), ($tmp[7]?$tmp[7]:'100')); $ret.=$doleditor->Create(1); } $ret.=''; $ret.=''; if (preg_match('/ckeditor|textarea/',$typeofdata)) $ret.='
'."\n"; $ret.=''; $ret.='
'."\n"; $ret.='
'."\n"; } else { if ($typeofdata == 'email') $ret.=dol_print_email($value,0,0,0,0,1); elseif ($typeofdata == 'amount') $ret.=($value != '' ? price($value,'',$langs,0,-1,-1,$conf->currency) : ''); elseif (preg_match('/^text/',$typeofdata) || preg_match('/^note/',$typeofdata)) $ret.=dol_htmlentitiesbr($value); elseif ($typeofdata == 'day' || $typeofdata == 'datepicker') $ret.=dol_print_date($value,'day'); elseif ($typeofdata == 'dayhour' || $typeofdata == 'datehourpicker') $ret.=dol_print_date($value,'dayhour'); else if (preg_match('/^select;/',$typeofdata)) { $arraydata=explode(',',preg_replace('/^select;/','',$typeofdata)); foreach($arraydata as $val) { $tmp=explode(':',$val); $arraylist[$tmp[0]]=$tmp[1]; } $ret.=$arraylist[$value]; } else if (preg_match('/^ckeditor/',$typeofdata)) { $tmpcontent=dol_htmlentitiesbr($value); if (! empty($conf->global->MAIN_DISABLE_NOTES_TAB)) { $firstline=preg_replace('/
.*/','',$tmpcontent); $firstline=preg_replace('/[\n\r].*/','',$firstline); $tmpcontent=$firstline.((strlen($firstline) != strlen($tmpcontent))?'...':''); } $ret.=$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:rows:cols', 'ckeditor:dolibarr_zzz:width:height:?:1:rows:cols', 'select:xxx') * @param string $editvalue When in edit mode, use this value as $value instead of value * @param object $extObject External object * @param mixed $custommsg String or Array of custom messages : eg array('success' => 'MyMessage', 'error' => 'MyMessage') * @return string HTML edit in place */ private function editInPlace($object, $value, $htmlname, $condition, $inputType='textarea', $editvalue=null, $extObject=null, $custommsg=null) { 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; $button_only = 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; } if (preg_match('/^(string|email|numeric)/',$inputType)) { $tmp=explode(':',$inputType); $inputType=$tmp[0]; if (! empty($tmp[1])) $inputOption=$tmp[1]; if (! empty($tmp[2])) $savemethod=$tmp[2]; } else if ((preg_match('/^datepicker/',$inputType)) || (preg_match('/^datehourpicker/',$inputType))) { $tmp=explode(':',$inputType); $inputType=$tmp[0]; if (! empty($tmp[1])) $inputOption=$tmp[1]; if (! empty($tmp[2])) $savemethod=$tmp[2]; $out.= ''."\n"; // Use for timestamp format } else if (preg_match('/^(select|autocomplete)/',$inputType)) { $tmp=explode(':',$inputType); $inputType=$tmp[0]; $loadmethod=$tmp[1]; if (! empty($tmp[2])) $savemethod=$tmp[2]; if (! empty($tmp[3])) $button_only=true; } else if (preg_match('/^textarea/',$inputType)) { $tmp=explode(':',$inputType); $inputType=$tmp[0]; $rows=(empty($tmp[1])?'8':$tmp[1]); $cols=(empty($tmp[2])?'80':$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"; if (! empty($savemethod)) $out.= ''."\n"; if (! empty($ext_element)) $out.= ''."\n"; if (! empty($custommsg)) { if (is_array($custommsg)) { if (!empty($custommsg['success'])) $out.= ''."\n"; if (!empty($custommsg['error'])) $out.= ''."\n"; } else $out.= ''."\n"; } if ($inputType == 'textarea') { $out.= ''."\n"; $out.= ''."\n"; } $out.= ''.$value.''."\n"; $out.= ''.(! empty($editvalue) ? $editvalue : $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 HTML content of tooltip. Must be HTML/UTF8 encoded. * @param int $tooltipon 1=tooltip on text, 2=tooltip on image, 3=tooltip sur les 2 * @param int $direction -1=image is before, 0=no image, 1=image is after * @param string $img Html code for image (use img_xxx() function to get it) * @param string $extracss Add a CSS style to td tags * @param int $notabs 0=Include table and tr tags, 1=Do not include table and tr tags, 2=use div, 3=use span * @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 = 2, $incbefore = '', $noencodehtmltext = 0) { global $conf; if ($incbefore) $text = $incbefore.$text; if (! $htmltext) return $text; $tag='td'; if ($notabs == 2) $tag='div'; if ($notabs == 3) $tag='span'; // Sanitize tooltip $htmltext=str_replace("\\","\\\\",$htmltext); $htmltext=str_replace("\r","",$htmltext); $htmltext=str_replace("\n","",$htmltext); $extrastyle=''; if ($direction < 0) { $extracss=($extracss?$extracss.' ':'').'inline-block'; $extrastyle='padding: 0px; padding-left: 3px !important;'; } if ($direction > 0) { $extracss=($extracss?$extracss.' ':'').'inline-block'; $extrastyle='padding: 0px; padding-right: 3px !important;'; } $htmltext=str_replace('"',""",$htmltext); if ($tooltipon == 2 || $tooltipon == 3) $paramfortooltipimg=' class="classfortooltip inline-block'.($extracss?' '.$extracss:'').'" style="padding: 0px;'.($extrastyle?' '.$extrastyle:'').'" title="'.($noencodehtmltext?$htmltext:dol_escape_htmltag($htmltext,1)).'"'; // Attribut to put on td img tag to store tooltip else $paramfortooltipimg =($extracss?' class="'.$extracss.'"':'').($extrastyle?' style="'.$extrastyle.'"':''); // Attribut to put on td text tag if ($tooltipon == 1 || $tooltipon == 3) $paramfortooltiptd=' class="classfortooltip inline-block'.($extracss?' '.$extracss:'').'" style="padding: 0px;'.($extrastyle?' '.$extrastyle:'').'" title="'.($noencodehtmltext?$htmltext:dol_escape_htmltag($htmltext,1)).'"'; // Attribut to put on td tag to store tooltip else $paramfortooltiptd =($extracss?' class="'.$extracss.'"':'').($extrastyle?' style="'.$extrastyle.'"':''); // Attribut to put on td text tag $s=""; if (empty($notabs)) $s.=''; elseif ($notabs == 2) $s.='
'; // Define value if value is before if ($direction < 0) { $s.='<'.$tag.$paramfortooltipimg; if ($tag == 'td') { $s .= ' valign="top" width="14"'; } $s.= '>'.$img.''; } // Use another method to help avoid having a space in value in order to use this value with jquery // Define label if ((string) $text != '') $s.='<'.$tag.$paramfortooltiptd.'>'.$text.''; // Define value if value is after if ($direction > 0) { $s.='<'.$tag.$paramfortooltipimg; if ($tag == 'td') $s .= ' valign="middle" width="14"'; $s.= '>'.$img.''; } if (empty($notabs)) $s.='
'; elseif ($notabs == 2) $s.=''; return $s; } /** * Show a text with a picto and a tooltip on picto * * @param string $text Text to show * @param string $htmltext 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 * @param int $notabs 0=Include table and tr tags, 1=Do not include table and tr tags, 2=use div, 3=use span * @return string HTML code of text, picto, tooltip */ function textwithpicto($text, $htmltext, $direction = 1, $type = 'help', $extracss = '', $noencodehtmltext = 0, $notabs = 2) { global $conf; $alt = ''; //For backwards compatibility if ($type == '0') $type = 'info'; elseif ($type == '1') $type = 'help'; // 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 (tooltip can't works) if (! empty($conf->dol_no_mouse_hover)) { if ($type == 'info' || $type == 'help') return $text; } if ($type == 'info') $img = img_help(0, $alt); elseif ($type == 'help') $img = img_help(1, $alt); elseif ($type == 'superadmin') $img = img_picto($alt, 'redstar'); elseif ($type == 'admin') $img = img_picto($alt, 'star'); elseif ($type == 'warning') $img = img_warning($alt); return $this->textwithtooltip($text, $htmltext, 2, $direction, $img, $extracss, $notabs, '', $noencodehtmltext); } /** * Return combo list of activated countries, into language of user * * @param string $selected Id or Code or Label of preselected country * @param string $htmlname Name of html select object * @param string $htmloption Options html on select object * @param integer $maxlength Max length for labels (0=no limit) * @return string HTML string with select */ function select_country($selected='',$htmlname='country_id',$htmloption='',$maxlength=0) { global $conf,$langs; $langs->load("dict"); $out=''; $countryArray=array(); $favorite=array(); $label=array(); $atleastonefavorite=0; $sql = "SELECT rowid, code as code_iso, code_iso as code_iso3, label, favorite"; $sql.= " FROM ".MAIN_DB_PREFIX."c_country"; $sql.= " WHERE active > 0"; //$sql.= " ORDER BY code ASC"; dol_syslog(get_class($this)."::select_country", LOG_DEBUG); $resql=$this->db->query($sql); if ($resql) { $out.= ''; } else { dol_print_error($this->db); } // Make select dynamic include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php'; $out .= ajax_combobox('select'.$htmlname); return $out; } /** * Return select list of incoterms * * @param string $selected Id or Code of preselected incoterm * @param string $location_incoterms Value of input location * @param string $page Defined the form action * @param string $htmlname Name of html select object * @param string $htmloption Options html on select object * @param int $forcecombo Force to use combo box * @param array $events Event options to run on change. Example: array(array('method'=>'getContacts', 'url'=>dol_buildpath('/core/ajax/contacts.php',1), 'htmlname'=>'contactid', 'params'=>array('add-customer-contact'=>'disabled'))) * @return string HTML string with select and input */ function select_incoterms($selected='', $location_incoterms='', $page='',$htmlname='incoterm_id',$htmloption='', $forcecombo=0, $events=array()) { global $conf,$langs; $langs->load("dict"); $out=''; $incotermArray=array(); $sql = "SELECT rowid, code"; $sql.= " FROM ".MAIN_DB_PREFIX."c_incoterms"; $sql.= " WHERE active > 0"; $sql.= " ORDER BY code ASC"; dol_syslog(get_class($this)."::select_incoterm", LOG_DEBUG); $resql=$this->db->query($sql); if ($resql) { if (!$forcecombo) { include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php'; $out .= ajax_combobox($htmlname, $events); } if (!empty($page)) { $out .= '
'; $out .= ''; $out .= ''; } $out.= ''; $out .= ''; if (!empty($page)) { $out .= '
'; } } else { dol_print_error($this->db); } return $out; } /** * Return list of types of lines (product or service) * Example: 0=product, 1=service, 9=other (for external module) * * @param string $selected Preselected type * @param string $htmlname Name of field in html form * @param int $showempty Add an empty field * @param int $hidetext Do not show label 'Type' before combo box (used only if there is at least 2 choices to select) * @param integer $forceall 1=Force to show products and services in combo list, whatever are activated modules, 0=No force, -1=Force none (and set hidden field to 'service') * @return void */ 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 > 0 || (empty($forceall) && ! empty($conf->product->enabled) && ! empty($conf->service->enabled)) || (empty($forceall) && empty($conf->product->enabled) && empty($conf->service->enabled)) ) { if (empty($hidetext)) print $langs->trans("Type").': '; print ''; //if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1); } if (empty($forceall) && empty($conf->product->enabled) && ! empty($conf->service->enabled)) { print $langs->trans("Service"); print ''; } if (empty($forceall) && ! empty($conf->product->enabled) && empty($conf->service->enabled)) { print $langs->trans("Product"); print ''; } if ($forceall < 0) // This should happened only for contracts when both predefined product and service are disabled. { print ''; // By default we set on service for contract. If CONTRACT_SUPPORT_PRODUCTS is set, forceall should be 1 not -1 } } /** * Load into cache cache_types_fees, array of types of fees * * @return int Nb of lines loaded, <0 if KO */ function load_cache_types_fees() { global $langs; $num = count($this->cache_types_fees); if ($num > 0) return 0; // Cache already loaded dol_syslog(__METHOD__, LOG_DEBUG); $langs->load("trips"); $sql = "SELECT c.code, c.label"; $sql.= " FROM ".MAIN_DB_PREFIX."c_type_fees as c"; $sql.= " WHERE active > 0"; $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++; } asort($this->cache_types_fees); 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(__METHOD__." selected=".$selected.", htmlname=".$htmlname, LOG_DEBUG); $this->load_cache_types_fees(); print ''; if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1); } /** * Return HTML code to select a company. * * @param int $selected Preselected products * @param string $htmlname Name of HTML select field (must be unique in page) * @param int $filter Filter on thirdparty * @param int $limit Limit on number of returned lines * @param array $ajaxoptions Options for ajax_autocompleter * @param int $forcecombo Force to use combo box * @return string Return select box for thirdparty. * @deprecated 3.8 Use select_company instead. For exemple $form->select_thirdparty(GETPOST('socid'),'socid','',0) => $form->select_company(GETPOST('socid'),'socid','',1,0,0,array(),0) */ function select_thirdparty($selected='', $htmlname='socid', $filter='', $limit=20, $ajaxoptions=array(), $forcecombo=0) { return $this->select_thirdparty_list($selected,$htmlname,$filter,1,0,$forcecombo,array(),'',0,$limit); } /** * Output html form to select a third party * * @param string $selected Preselected type * @param string $htmlname Name of field in form * @param string $filter optional filters criteras (example: 's.rowid <> x') * @param int $showempty Add an empty field * @param int $showtype Show third party type in combolist (customer, prospect or supplier) * @param int $forcecombo Force to use combo box * @param array $events Ajax event options to run on change. Example: array(array('method'=>'getContacts', 'url'=>dol_buildpath('/core/ajax/contacts.php',1), 'htmlname'=>'contactid', 'params'=>array('add-customer-contact'=>'disabled'))) * @param int $limit Maximum number of elements * @return string HTML string with select box for thirdparty. */ function select_company($selected='', $htmlname='socid', $filter='', $showempty=0, $showtype=0, $forcecombo=0, $events=array(), $limit=0) { $out=''; /* TODO Use ajax_autocompleter like for products (not finished) if (! empty($conf->use_javascript_ajax) && ! empty($conf->global->COMPANY_USE_SEARCH_TO_SELECT) && ! $forcecombo) { $placeholder=''; if ($selected && empty($selected_input_value)) { require_once DOL_DOCUMENT_ROOT.'/societe/ajaxcompanies.php'; $societe = new Societe($this->db); $societe->fetch($selected); $selected_input_value=$societe->ref; } // mode=1 means customers products $urloption='htmlname='.$htmlname.'&outjson=1&price_level='.$price_level.'&type='.$filtertype.'&mode=1&status='.$status.'&finished='.$finished; print ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT.'/societe/ajax/company.php', $urloption, $conf->global->COMPANY_USE_SEARCH_TO_SELECT, 0, $ajaxoptions); if (empty($hidelabel)) print $langs->trans("RefOrLabel").' : '; else if ($hidelabel > 1) { if (! empty($conf->global->MAIN_HTML5_PLACEHOLDER)) $placeholder=' placeholder="'.$langs->trans("RefOrLabel").'"'; else $placeholder=' title="'.$langs->trans("RefOrLabel").'"'; if ($hidelabel == 2) { print img_picto($langs->trans("Search"), 'search'); } } print ''; if ($hidelabel == 3) { print img_picto($langs->trans("Search"), 'search'); } } else {*/ $out.=$this->select_thirdparty_list($selected, $htmlname, $filter, $showempty, $showtype, $forcecombo, $events, '', 0, $limit); //} return $out; } /** * Output html form to select a third party * * @param string $selected Preselected type * @param string $htmlname Name of field in form * @param string $filter optional filters criteras (example: 's.rowid <> x', 's.client in (1,3)') * @param int $showempty Add an empty field * @param int $showtype Show third party type in combolist (customer, prospect or supplier) * @param int $forcecombo Force to use combo box * @param array $events Event options. Example: array(array('method'=>'getContacts', 'url'=>dol_buildpath('/core/ajax/contacts.php',1), 'htmlname'=>'contactid', 'params'=>array('add-customer-contact'=>'disabled'))) * @param string $filterkey Filter on key value * @param int $outputmode 0=HTML select string, 1=Array * @param int $limit Limit number of answers * @return string HTML string with */ function select_thirdparty_list($selected='',$htmlname='socid',$filter='',$showempty=0, $showtype=0, $forcecombo=0, $events=array(), $filterkey='', $outputmode=0, $limit=0) { global $conf,$user,$langs; $out=''; $num=0; $outarray=array(); // On recherche les societes $sql = "SELECT s.rowid, s.nom as name, 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 (! empty($user->societe_id)) $sql.= " AND s.rowid = ".$user->societe_id; 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; if (! empty($conf->global->COMPANY_HIDE_INACTIVE_IN_COMBOBOX)) $sql.= " AND s.status <> 0"; // Add criteria if ($filterkey && $filterkey != '') { $sql.=" AND ("; if (! empty($conf->global->COMPANY_DONOTSEARCH_ANYWHERE)) // Can use index { $sql.="(s.name LIKE '".$this->db->escape($filterkey)."%')"; } else { // For natural search $scrit = explode(' ', $filterkey); foreach ($scrit as $crit) { $sql.=" AND (s.name LIKE '%".$this->db->escape($crit)."%')"; } } if (! empty($conf->barcode->enabled)) { $sql .= " OR s.barcode LIKE '".$this->db->escape($filterkey)."%'"; } $sql.=")"; } $sql.=$this->db->order("nom","ASC"); if ($limit > 0) $sql.=$this->db->plimit($limit); dol_syslog(get_class($this)."::select_thirdparty_list", LOG_DEBUG); $resql=$this->db->query($sql); if ($resql) { if ($conf->use_javascript_ajax && ! $forcecombo) { include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php'; $comboenhancement =ajax_combobox($htmlname, $events, $conf->global->COMPANY_USE_SEARCH_TO_SELECT); $out.= $comboenhancement; $nodatarole=($comboenhancement?' data-role="none"':''); } // Construct $out and $outarray $out.= ''."\n"; } else { dol_print_error($this->db); } $this->result=array('nbofthirdparties'=>$num); if ($outputmode) return $outarray; return $out; } /** * Return HTML combo list of absolute discounts * * @param string $selected Id remise fixe pre-selectionnee * @param string $htmlname Nom champ formulaire * @param string $filter Criteres optionnels de filtre * @param int $socid Id of thirdparty * @param int $maxvalue Max value for lines that can be selected * @return int Return number of qualifed lines in list */ function select_remises($selected, $htmlname, $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(get_class($this)."::select_remises", LOG_DEBUG); $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 int $socid Id ot third party or 0 for all * @param string $selected Id contact pre-selectionne * @param string $htmlname Name of HTML field ('none' for a not editable field) * @param int $showempty 0=no empty value, 1=add an empty value * @param string $exclude List of contacts id to exclude * @param string $limitto Disable answers that are not id in this array list * @param integer $showfunction Add function into label * @param string $moreclass Add more class to class style * @param integer $showsoc Add company into label * @param int $forcecombo Force to use combo box * @param array $events Event options. Example: array(array('method'=>'getContacts', 'url'=>dol_buildpath('/core/ajax/contacts.php',1), 'htmlname'=>'contactid', 'params'=>array('add-customer-contact'=>'disabled'))) * @param bool $options_only Return options only (for ajax treatment) * @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='', $showsoc=0, $forcecombo=0, $events=array(), $options_only=false) { print $this->selectcontacts($socid,$selected,$htmlname,$showempty,$exclude,$limitto,$showfunction, $moreclass, $options_only, $showsoc, $forcecombo, $events); return $this->num; } /** * Return list of all contacts (for a third party or all) * * @param int $socid Id ot third party or 0 for all * @param string $selected Id contact pre-selectionne * @param string $htmlname Name of HTML field ('none' for a not editable field) * @param int $showempty 0=no empty value, 1=add an empty value, 2=add line 'Internal' (used by user edit) * @param string $exclude List of contacts id to exclude * @param string $limitto Disable answers that are not id in this array list * @param integer $showfunction Add function into label * @param string $moreclass Add more class to class style * @param bool $options_only Return options only (for ajax treatment) * @param integer $showsoc Add company into label * @param int $forcecombo Force to use combo box * @param array $events Event options. Example: array(array('method'=>'getContacts', 'url'=>dol_buildpath('/core/ajax/contacts.php',1), 'htmlname'=>'contactid', 'params'=>array('add-customer-contact'=>'disabled'))) * @return int <0 if KO, Nb of contact in list if OK */ function selectcontacts($socid,$selected='',$htmlname='contactid',$showempty=0,$exclude='',$limitto='',$showfunction=0, $moreclass='', $options_only=false, $showsoc=0, $forcecombo=0, $events=array()) { global $conf,$langs; $langs->load('companies'); $out=''; // On recherche les societes $sql = "SELECT sp.rowid, sp.lastname, sp.statut, sp.firstname, sp.poste"; if ($showsoc > 0) $sql.= " , s.nom as company"; $sql.= " FROM ".MAIN_DB_PREFIX ."socpeople as sp"; if ($showsoc > 0) $sql.= " LEFT OUTER JOIN ".MAIN_DB_PREFIX ."societe as s ON s.rowid=sp.fk_soc"; $sql.= " WHERE sp.entity IN (".getEntity('societe', 1).")"; if ($socid > 0) $sql.= " AND sp.fk_soc=".$socid; if (! empty($conf->global->CONTACT_HIDE_INACTIVE_IN_COMBOBOX)) $sql.= " AND sp.statut <> 0"; $sql.= " ORDER BY sp.lastname ASC"; dol_syslog(get_class($this)."::select_contacts", LOG_DEBUG); $resql=$this->db->query($sql); if ($resql) { $num=$this->db->num_rows($resql); if ($conf->use_javascript_ajax && ! $forcecombo && ! $options_only) { include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php'; $comboenhancement = ajax_combobox($htmlname, $events, $conf->global->CONTACT_USE_SEARCH_TO_SELECT); $out.= $comboenhancement; $nodatarole=($comboenhancement?' data-role="none"':''); } if ($htmlname != 'none' || $options_only) $out.= ''; } $this->num = $num; return $out; } else { dol_print_error($this->db); return -1; } } /** * Return select list of users * * @param string $selected Id user preselected * @param string $htmlname Field name in form * @param int $show_empty 0=liste sans valeur nulle, 1=ajoute valeur inconnue * @param array $exclude Array list of users id to exclude * @param int $disabled If select list must be disabled * @param array $include Array list of users id to include * @param int $enableonly Array list of users id to be enabled. All other must be disabled * @param int $force_entity 0 or Id of environment to force * @return void * @deprecated * @see select_dolusers() */ 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 string $selected User id or user object of user preselected. If -1, we use id of current user. * @param string $htmlname Field name in form * @param int $show_empty 0=list with no empty value, 1=add also an empty value into list * @param array $exclude Array list of users id to exclude * @param int $disabled If select list must be disabled * @param array $include Array list of users id to include or 'hierarchy' to have only supervised users * @param array $enableonly Array list of users id to be enabled. All other must be disabled * @param int $force_entity 0 or Id of environment to force * @param int $maxlength Maximum length of string into list (0=no limit) * @param int $showstatus 0=show user status only if status is disabled, 1=always show user status into label, -1=never show user status * @param string $morefilter Add more filters into sql request * @param string $show_every 0=default list, 1=add also a value "Everybody" at beginning of list * @param string $enableonlytext If option $enableonly is set, we use this text to explain into label why record is disabled. Not used if enableonly is empty. * @return string HTML select string * @see select_dolgroups */ function select_dolusers($selected='', $htmlname='userid', $show_empty=0, $exclude='', $disabled=0, $include='', $enableonly='', $force_entity=0, $maxlength=0, $showstatus=0, $morefilter='', $show_every=0, $enableonlytext='') { global $conf,$user,$langs; // If no preselected user defined, we take current user if ((is_numeric($selected) && ($selected < -2 || empty($selected))) && empty($conf->global->SOCIETE_DISABLE_DEFAULT_SALESREPRESENTATIVE)) $selected=$user->id; $excludeUsers=null; $includeUsers=null; // Permettre l'exclusion d'utilisateurs if (is_array($exclude)) $excludeUsers = implode("','",$exclude); // Permettre l'inclusion d'utilisateurs if (is_array($include)) $includeUsers = implode("','",$include); else if ($include == 'hierarchy') { // Build list includeUsers to have only hierarchy $userid=$user->id; $include=array(); if (empty($user->users) || ! is_array($user->users)) $user->get_full_tree(); foreach($user->users as $key => $val) { if (preg_match('/_'.$userid.'/',$val['fullpath'])) $include[]=$val['id']; } $includeUsers = implode("','",$include); //var_dump($includeUsers);exit; //var_dump($user->users);exit; } $out=''; // On recherche les utilisateurs $sql = "SELECT DISTINCT u.rowid, u.lastname as lastname, u.firstname, u.statut, 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 { if (! empty($conf->multicompany->transverse_mode)) { $sql.= ", ".MAIN_DB_PREFIX."usergroup_user as ug"; $sql.= " WHERE ug.fk_user = u.rowid"; $sql.= " AND ug.entity = ".$conf->entity; } else { $sql.= " WHERE u.entity IN (0,".$conf->entity.")"; } } if (! empty($user->societe_id)) $sql.= " AND u.fk_soc = ".$user->societe_id; if (is_array($exclude) && $excludeUsers) $sql.= " AND u.rowid NOT IN ('".$excludeUsers."')"; if (is_array($include) && $includeUsers) $sql.= " AND u.rowid IN ('".$includeUsers."')"; if (! empty($conf->global->USER_HIDE_INACTIVE_IN_COMBOBOX)) $sql.= " AND u.statut <> 0"; if (! empty($morefilter)) $sql.=" ".$morefilter; $sql.= " ORDER BY u.lastname ASC"; dol_syslog(get_class($this)."::select_dolusers", LOG_DEBUG); $resql=$this->db->query($sql); if ($resql) { $num = $this->db->num_rows($resql); $i = 0; if ($num) { // Enhance with select2 $nodatarole=''; if ($conf->use_javascript_ajax) { include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php'; $comboenhancement = ajax_combobox($htmlname); $out.=$comboenhancement; $nodatarole=($comboenhancement?' data-role="none"':''); } $out.= ''; $out.= ''; } $out.= ''; } else { dol_print_error($this->db); } return $out; } /** * Return select list of users. Selected users are stored into session. * List of users are provided into $_SESSION['assignedtouser']. * * @param string $action Value for $action * @param string $htmlname Field name in form * @param int $show_empty 0=liste sans valeur nulle, 1=ajoute valeur inconnue * @param array $exclude Array list of users id to exclude * @param int $disabled If select list must be disabled * @param array $include Array list of users id to include or 'hierarchy' to have only supervised users * @param array $enableonly Array list of users id to be enabled. All other must be disabled * @param int $force_entity 0 or Id of environment to force * @param int $maxlength Maximum length of string into list (0=no limit) * @param int $showstatus 0=show user status only if status is disabled, 1=always show user status into label, -1=never show user status * @param string $morefilter Add more filters into sql request * @return string HTML select string * @see select_dolgroups */ function select_dolusers_forevent($action='', $htmlname='userid', $show_empty=0, $exclude='', $disabled=0, $include='', $enableonly='', $force_entity=0, $maxlength=0, $showstatus=0, $morefilter='') { global $conf,$user,$langs; $userstatic=new User($this->db); $out=''; // Method with no ajax //$out.='
'; if ($action == 'view') { $out.=''; } else { $out.=''; $out.=''; $out.=$this->select_dolusers('', $htmlname, $show_empty, $exclude, $disabled, $include, $enableonly, $force_entity, $maxlength, $showstatus, $morefilter); $out.=' '; } $assignedtouser=array(); if (!empty($_SESSION['assignedtouser'])) { $assignedtouser=json_decode($_SESSION['assignedtouser'], true); } $nbassignetouser=count($assignedtouser); if ($nbassignetouser && $action != 'view') $out.='
'; $i=0; $ownerid=0; foreach($assignedtouser as $key => $value) { if ($value['id'] == $ownerid) continue; $userstatic->fetch($value['id']); $out.=$userstatic->getNomUrl(1); if ($i == 0) { $ownerid = $value['id']; $out.=' ('.$langs->trans("Owner").')'; } if ($nbassignetouser > 1 && $action != 'view') $out.=' '; //$out.=' '.($value['mandatory']?$langs->trans("Mandatory"):$langs->trans("Optional")); //$out.=' '.($value['transparency']?$langs->trans("Busy"):$langs->trans("NotBusy")); $out.='
'; $i++; } //$out.='
'; return $out; } /** * Return list of products for customer in Ajax if Ajax activated or go to select_produits_list * * @param int $selected Preselected products * @param string $htmlname Name of HTML select 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 (for use with ajax) * @param int $hidelabel Hide label (0=no, 1=yes, 2=show search icon (before) and placeholder, 3 search icon after) * @param array $ajaxoptions Options for ajax_autocompleter * @param int $socid Thirdparty Id * @return void */ function select_produits($selected='', $htmlname='productid', $filtertype='', $limit=20, $price_level=0, $status=1, $finished=2, $selected_input_value='', $hidelabel=0, $ajaxoptions=array(), $socid=0) { global $langs,$conf; $price_level = (! empty($price_level) ? $price_level : 0); if (! empty($conf->use_javascript_ajax) && ! empty($conf->global->PRODUIT_USE_SEARCH_TO_SELECT)) { $placeholder=''; if ($selected && empty($selected_input_value)) { require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; $producttmpselect = new Product($this->db); $producttmpselect->fetch($selected); $selected_input_value=$producttmpselect->ref; unset($producttmpselect); } // mode=1 means customers products $urloption='htmlname='.$htmlname.'&outjson=1&price_level='.$price_level.'&type='.$filtertype.'&mode=1&status='.$status.'&finished='.$finished; //Price by customer if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES) && !empty($socid)) { $urloption.='&socid='.$socid; } print ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT.'/product/ajax/products.php', $urloption, $conf->global->PRODUIT_USE_SEARCH_TO_SELECT, 0, $ajaxoptions); if (empty($hidelabel)) print $langs->trans("RefOrLabel").' : '; else if ($hidelabel > 1) { if (! empty($conf->global->MAIN_HTML5_PLACEHOLDER)) $placeholder=' placeholder="'.$langs->trans("RefOrLabel").'"'; else $placeholder=' title="'.$langs->trans("RefOrLabel").'"'; if ($hidelabel == 2) { print img_picto($langs->trans("Search"), 'search'); } } print ''; if ($hidelabel == 3) { print img_picto($langs->trans("Search"), 'search'); } } else { print $this->select_produits_list($selected,$htmlname,$filtertype,$limit,$price_level,'',$status,$finished,0,$socid); } } /** * 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 Limit on number of returned lines * @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 $outputmode 0=HTML select string, 1=Array * @param int $socid Thirdparty Id * @return array Array of keys for json */ function select_produits_list($selected='',$htmlname='productid',$filtertype='',$limit=20,$price_level=0,$filterkey='',$status=1,$finished=2,$outputmode=0,$socid=0) { global $langs,$conf,$user,$db; $out=''; $outarray=array(); $sql = "SELECT "; $sql.= " p.rowid, p.label, p.ref, p.description, p.fk_product_type, p.price, p.price_ttc, p.price_base_type, p.tva_tx, p.duration, p.stock, p.fk_price_expression"; //Price by customer if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES) && !empty($socid)) { $sql.=' ,pcp.rowid as idprodcustprice, pcp.price as custprice, pcp.price_ttc as custprice_ttc,'; $sql.=' pcp.price_base_type as custprice_base_type, pcp.tva_tx as custtva_tx'; } // Multilang : we add translation if (! empty($conf->global->MAIN_MULTILANGS)) { $sql.= ", pl.label as label_translated"; } // Price by quantity if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY)) { $sql.= ", (SELECT pp.rowid FROM ".MAIN_DB_PREFIX."product_price as pp WHERE pp.fk_product = p.rowid"; if ($price_level >= 1 && !empty($conf->global->PRODUIT_MULTIPRICES)) $sql.= " AND price_level=".$price_level; $sql.= " ORDER BY date_price"; $sql.= " DESC LIMIT 1) as price_rowid"; $sql.= ", (SELECT pp.price_by_qty FROM ".MAIN_DB_PREFIX."product_price as pp WHERE pp.fk_product = p.rowid"; if ($price_level >= 1 && !empty($conf->global->PRODUIT_MULTIPRICES)) $sql.= " AND price_level=".$price_level; $sql.= " ORDER BY date_price"; $sql.= " DESC LIMIT 1) as price_by_qty"; } $sql.= " FROM ".MAIN_DB_PREFIX."product as p"; //Price by customer if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES) && !empty($socid)) { $sql.=" LEFT JOIN ".MAIN_DB_PREFIX."product_customer_price as pcp ON pcp.fk_soc=".$socid." AND pcp.fk_product=p.rowid"; } // Multilang : we add translation if (! empty($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 != '') { $sql.=' AND ('; $prefix=empty($conf->global->PRODUCT_DONOTSEARCH_ANYWHERE)?'%':''; // Can use index if PRODUCT_DONOTSEARCH_ANYWHERE is on // For natural search $scrit = explode(' ', $filterkey); $i=0; if (count($scrit) > 1) $sql.="("; foreach ($scrit as $crit) { if ($i > 0) $sql.=" AND "; $sql.="(p.ref LIKE '".$prefix.$crit."%' OR p.label LIKE '".$prefix.$crit."%'"; if (! empty($conf->global->MAIN_MULTILANGS)) $sql.=" OR pl.label LIKE '".$prefix.$crit."%'"; $sql.=")"; $i++; } if (count($scrit) > 1) $sql.=")"; if (! empty($conf->barcode->enabled)) $sql.= " OR p.barcode LIKE '".$prefix.$filterkey."%'"; $sql.=')'; } $sql.= $db->order("p.ref"); $sql.= $db->plimit($limit); // Build output string dol_syslog(get_class($this)."::select_produits_list search product", LOG_DEBUG); $result=$this->db->query($sql); if ($result) { require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; require_once DOL_DOCUMENT_ROOT.'/product/dynamic_price/class/price_parser.class.php'; $num = $this->db->num_rows($result); $out.=''; $this->db->free($result); if (empty($outputmode)) return $out; return $outarray; } else { dol_print_error($db); } } /** * constructProductListOption * * @param resultset $objp Resultset of fetch * @param string $opt Option * @param string $optJson Option * @param int $price_level Price level * @param string $selected Preselected value * @return void */ private function constructProductListOption(&$objp, &$opt, &$optJson, $price_level, $selected) { global $langs,$conf,$user,$db; $outkey=''; $outval=''; $outref=''; $outlabel=''; $outdesc=''; $outtype=''; $outprice_ht=''; $outprice_ttc=''; $outpricebasetype=''; $outtva_tx=''; $outqty=1; $outdiscount=0; $maxlengtharticle=(empty($conf->global->PRODUCT_MAX_LENGTH_COMBO)?48:$conf->global->PRODUCT_MAX_LENGTH_COMBO); $label=$objp->label; if (! empty($objp->label_translated)) $label=$objp->label_translated; if (! empty($filterkey) && $filterkey != '') $label=preg_replace('/('.preg_quote($filterkey).')/i','$1',$label,1); $outkey=$objp->rowid; $outref=$objp->ref; $outlabel=$objp->label; $outdesc=$objp->description; $outtype=$objp->fk_product_type; $opt = '\n"; $optJson = array('key'=>$outkey, 'value'=>$outref, 'label'=>$outval, 'label2'=>$outlabel, 'desc'=>$outdesc, 'type'=>$outtype, 'price_ht'=>$outprice_ht, 'price_ttc'=>$outprice_ttc, 'pricebasetype'=>$outpricebasetype, 'tva_tx'=>$outtva_tx, 'qty'=>$outqty, 'discount'=>$outdiscount); } /** * Return list of products for customer (in Ajax if Ajax activated or go to select_produits_fournisseurs_list) * * @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 * @param array $ajaxoptions Options for ajax_autocompleter * @param int $hidelabel Hide label (0=no, 1=yes) * @return void */ function select_produits_fournisseurs($socid, $selected='', $htmlname='productid', $filtertype='', $filtre='', $ajaxoptions=array(), $hidelabel=0) { global $langs,$conf; global $price_level, $status, $finished; if (! empty($conf->use_javascript_ajax) && ! empty($conf->global->PRODUIT_USE_SEARCH_TO_SELECT)) { // mode=2 means suppliers products $urloption=($socid > 0?'socid='.$socid.'&':'').'htmlname='.$htmlname.'&outjson=1&price_level='.$price_level.'&type='.$filtertype.'&mode=2&status='.$status.'&finished='.$finished; print ajax_autocompleter('', $htmlname, DOL_URL_ROOT.'/product/ajax/products.php', $urloption, $conf->global->PRODUIT_USE_SEARCH_TO_SELECT, 0, $ajaxoptions); print ($hidelabel?'':$langs->trans("RefOrLabel").' : ').''; } else { print $this->select_produits_fournisseurs_list($socid,$selected,$htmlname,$filtertype,$filtre,'',-1,0); } } /** * Return list of suppliers products * * @param int $socid Id societe fournisseur (0 pour aucun filtre) * @param int $selected Produit pre-selectionne * @param string $htmlname Nom de la zone select * @param string $filtertype Filter on product type (''=nofilter, 0=product, 1=service) * @param string $filtre Pour filtre sql * @param string $filterkey Filtre des produits * @param int $statut -1=Return all products, 0=Products not on sell, 1=Products on sell * @param int $outputmode 0=HTML select string, 1=Array * @param int $limit Limit of line number * @return array Array of keys for json */ function select_produits_fournisseurs_list($socid,$selected='',$htmlname='productid',$filtertype='',$filtre='',$filterkey='',$statut=-1,$outputmode=0,$limit=100) { global $langs,$conf,$db; $out=''; $outarray=array(); $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.remise_percent, pfp.remise, pfp.unitprice,"; $sql.= " pfp.fk_supplier_price_expression, pfp.fk_product, pfp.tva_tx, s.nom as name"; $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"; if ($socid) $sql.= " AND pfp.fk_soc = ".$socid; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON pfp.fk_soc = s.rowid"; $sql.= " WHERE p.entity IN (".getEntity('product', 1).")"; $sql.= " AND p.tobuy = 1"; if (strval($filtertype) != '') $sql.=" AND p.fk_product_type=".$filtertype; if (! empty($filtre)) $sql.=" ".$filtre; // Add criteria on ref/label if ($filterkey != '') { $sql.=' AND ('; $prefix=empty($conf->global->PRODUCT_DONOTSEARCH_ANYWHERE)?'%':''; // Can use index if PRODUCT_DONOTSEARCH_ANYWHERE is on // For natural search $scrit = explode(' ', $filterkey); $i=0; if (count($scrit) > 1) $sql.="("; foreach ($scrit as $crit) { if ($i > 0) $sql.=" AND "; $sql.="(pfp.ref_fourn LIKE '".$prefix.$crit."%' OR p.ref LIKE '".$prefix.$crit."%' OR p.label LIKE '".$prefix.$crit."%')"; $i++; } if (count($scrit) > 1) $sql.=")"; if (! empty($conf->barcode->enabled)) $sql.= " OR p.barcode LIKE '".$prefix.$filterkey."%'"; $sql.=')'; } $sql.= " ORDER BY pfp.ref_fourn DESC, pfp.quantity ASC"; $sql.= $db->plimit($limit); // Build output string dol_syslog(get_class($this)."::select_produits_fournisseurs_list", LOG_DEBUG); $result=$this->db->query($sql); if ($result) { require_once DOL_DOCUMENT_ROOT.'/product/dynamic_price/class/price_parser.class.php'; $num = $this->db->num_rows($result); //$out.=''; if (! $selected) $out.=''; else $out.=''; $i = 0; while ($i < $num) { $objp = $this->db->fetch_object($result); $outkey=$objp->idprodfournprice; $outref=$objp->ref; $outval=''; $outqty=1; $outdiscount=0; $opt = '\n"; // Add new entry // "key" value of json key array is used by jQuery automatically as selected value // "label" value of json key array is used by jQuery automatically as text for combo box $out.=$opt; array_push($outarray, array('key'=>$outkey, 'value'=>$outref, 'label'=>$outval, 'qty'=>$outqty, 'discount'=>$outdiscount, 'disabled'=>(empty($objp->idprodfournprice)?true:false))); // Exemple of var_dump $outarray // array(1) {[0]=>array(6) {[key"]=>string(1) "2" ["value"]=>string(3) "ppp" // ["label"]=>string(76) "ppp (fff2) - ppp - 20,00 Euros/1unité (20,00 Euros/unité)" // ["qty"]=>string(1) "1" ["discount"]=>string(1) "0" ["disabled"]=>bool(false) //} //var_dump($outval); var_dump(utf8_check($outval)); var_dump(json_encode($outval)); //$outval=array('label'=>'ppp (fff2) - ppp - 20,00 Euros/ Unité (20,00 Euros/unité)'); //var_dump($outval); var_dump(utf8_check($outval)); var_dump(json_encode($outval)); $i++; } $out.=''; $this->db->free($result); if (empty($outputmode)) return $out; return $outarray; } 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.= " pfp.fk_supplier_price_expression, pfp.fk_product, pfp.tva_tx, s.nom as name"; $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 IN (".getEntity('product', 1).")"; $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(get_class($this)."::select_product_fourn_price", 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(get_class($this)."::select_address", LOG_DEBUG); $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 of lines loaded, <0 if KO */ function load_cache_conditions_paiements() { global $langs; $num = count($this->cache_conditions_paiements); if ($num > 0) return 0; // Cache already loaded dol_syslog(__METHOD__, LOG_DEBUG); $sql = "SELECT rowid, code, libelle as label"; $sql.= " FROM ".MAIN_DB_PREFIX.'c_payment_term'; $sql.= " WHERE active > 0"; $sql.= " ORDER BY sortorder"; $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("PaymentConditionShort".$obj->code)!=("PaymentConditionShort".$obj->code)?$langs->trans("PaymentConditionShort".$obj->code):($obj->label!='-'?$obj->label:'')); $this->cache_conditions_paiements[$obj->rowid]['code'] =$obj->code; $this->cache_conditions_paiements[$obj->rowid]['label']=$label; $i++; } //$this->cache_conditions_paiements=dol_sort_array($this->cache_conditions_paiements, 'label'); // We use the sortorder return $num; } else { dol_print_error($this->db); return -1; } } /** * Charge dans cache la liste des délais de livraison possibles * * @return int Nb of lines loaded, <0 if KO */ function load_cache_availability() { global $langs; $num = count($this->cache_availability); if ($num > 0) return 0; // Cache already loaded dol_syslog(__METHOD__, LOG_DEBUG); $sql = "SELECT rowid, code, label"; $sql.= " FROM ".MAIN_DB_PREFIX.'c_availability'; $sql.= " WHERE active > 0"; $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++; } $this->cache_availability = dol_sort_array($this->cache_availability, 'label'); return $num; } else { dol_print_error($this->db); return -1; } } /** * Retourne la liste des types de delais de livraison possibles * * @param int $selected Id du type de delais pre-selectionne * @param string $htmlname Nom de la zone select * @param string $filtertype To add a filter * @param int $addempty Add empty entry * @return void */ function selectAvailabilityDelay($selected='',$htmlname='availid',$filtertype='',$addempty=0) { global $langs,$user; $this->load_cache_availability(); dol_syslog(__METHOD__." selected=".$selected.", htmlname=".$htmlname, LOG_DEBUG); print ''; if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1); } /** * Load into cache cache_demand_reason, array of input reasons * * @return int Nb of lines loaded, <0 if KO */ function loadCacheInputReason() { global $langs; $num = count($this->cache_demand_reason); if ($num > 0) return 0; // Cache already loaded $sql = "SELECT rowid, code, label"; $sql.= " FROM ".MAIN_DB_PREFIX.'c_input_reason'; $sql.= " WHERE active > 0"; $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', 'asc'); unset($tmparray); return $num; } else { dol_print_error($this->db); return -1; } } /** * Return list of input reason (events that triggered an object creation, like after sending an emailing, making an advert, ...) * List found into table c_input_reason loaded by loadCacheInputReason * * @param int $selected Id or code of type origin to select by default * @param string $htmlname Nom de la zone select * @param string $exclude To exclude a code value (Example: SRC_PROP) * @param int $addempty Add an empty entry * @return void */ function selectInputReason($selected='',$htmlname='demandreasonid',$exclude='',$addempty=0) { global $langs,$user; $this->loadCacheInputReason(); print ''; if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1); } /** * Charge dans cache la liste des types de paiements possibles * * @return int Nb of lines loaded, <0 if KO */ function load_cache_types_paiements() { global $langs; $num=count($this->cache_types_paiements); if ($num > 0) return $num; // Cache already loaded dol_syslog(__METHOD__, LOG_DEBUG); $sql = "SELECT id, code, libelle, type"; $sql.= " FROM ".MAIN_DB_PREFIX."c_paiement"; $sql.= " WHERE active > 0"; $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("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']=$label; $this->cache_types_paiements[$obj->id]['type'] =$obj->type; $i++; } $this->cache_types_paiements = dol_sort_array($this->cache_types_paiements, 'label'); return $num; } else { dol_print_error($this->db); return -1; } } /** * Retourne la liste des types de paiements possibles * * @param string $selected Id du type de paiement pre-selectionne * @param string $htmlname Nom de la zone select * @param string $filtertype Pour filtre * @param int $addempty Ajoute entree vide * @return void */ function select_conditions_paiements($selected='',$htmlname='condid',$filtertype=-1,$addempty=0) { global $langs,$user; dol_syslog(__METHOD__." selected=".$selected.", htmlname=".$htmlname, LOG_DEBUG); $this->load_cache_conditions_paiements(); print ''; if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1); } /** * Return list of payment methods * * @param string $selected Id du mode de paiement pre-selectionne * @param string $htmlname Nom de la zone select * @param string $filtertype To filter on field type in llx_c_paiement (array('code'=>xx,'label'=>zz)) * @param int $format 0=id+libelle, 1=code+code, 2=code+libelle, 3=id+code * @param int $empty 1=peut etre vide, 0 sinon * @param int $noadmininfo 0=Add admin info, 1=Disable admin info * @param int $maxlength Max length of label * @return void */ function select_types_paiements($selected='',$htmlname='paiementtype',$filtertype='',$format=0, $empty=0, $noadmininfo=0,$maxlength=0) { global $langs,$user; dol_syslog(__METHOD__." ".$selected.", ".$htmlname.", ".$filtertype.", ".$format, LOG_DEBUG); $filterarray=array(); if ($filtertype == 'CRDT') $filterarray=array(0,2,3); elseif ($filtertype == 'DBIT') $filterarray=array(1,2,3); elseif ($filtertype != '' && $filtertype != '-1') $filterarray=explode(',',$filtertype); $this->load_cache_types_paiements(); print ''; if ($user->admin && ! $noadmininfo) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1); } /** * Selection HT or TTC * * @param string $selected Id pre-selectionne * @param string $htmlname Nom de la zone select * @return string Code of HTML select to chose tax or not */ function selectPriceBaseType($selected='',$htmlname='price_base_type') { global $langs; $return=''; $return.= ''; return $return; } /** * Return a HTML select list of shipping mode * * @param string $selected Id shipping mode pre-selected * @param string $htmlname Name of select zone * @param string $filtre To filter list * @param int $useempty 1=Add an empty value in list, 2=Add an empty value in list only if there is more than 2 entries. * @param string $moreattrib To add more attribute on select * @return void */ function selectShippingMethod($selected='',$htmlname='shipping_method_id',$filtre='',$useempty=0,$moreattrib='') { global $langs, $conf, $user; $langs->load("admin"); $langs->load("deliveries"); $sql = "SELECT rowid, code, libelle as label"; $sql.= " FROM ".MAIN_DB_PREFIX."c_shipment_mode"; $sql.= " WHERE active > 0"; if ($filtre) $sql.=" AND ".$filtre; $sql.= " ORDER BY libelle ASC"; dol_syslog(get_class($this)."::selectShippingMode", LOG_DEBUG); $result = $this->db->query($sql); if ($result) { $num = $this->db->num_rows($result); $i = 0; if ($num) { print '"; if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1); } else { print $langs->trans("NoShippingMethodDefined"); } } else { dol_print_error($this->db); } } /** * Display form to select shipping mode * * @param string $page Page * @param int $selected Id of shipping mode * @param string $htmlname Name of select html field * @param int $addempty 1=Add an empty value in list, 2=Add an empty value in list only if there is more than 2 entries. * @return void */ function formSelectShippingMethod($page, $selected='', $htmlname='shipping_method_id', $addempty=0) { global $langs, $db; $langs->load("deliveries"); if ($htmlname != "none") { print '
'; print ''; print ''; print ''; print ''; print ''; print '
'; $this->selectShippingMethod($selected, $htmlname, '', $addempty); print '
'; } else { if ($selected) { $code=$langs->getLabelFromKey($db, $selected, 'c_shipment_mode', 'rowid', 'code'); print $langs->trans("SendingMethod".strtoupper($code)); } else { print " "; } } } /** * Creates HTML last in cycle situation invoices selector * * @param string $selected Preselected ID * @param int $socid Company ID * * @return string HTML select */ function selectSituationInvoices($selected = '', $socid = 0) { global $langs; $langs->load('bills'); $opt = ''; $sql = 'SELECT rowid, facnumber, situation_cycle_ref, situation_counter, situation_final, fk_soc FROM ' . MAIN_DB_PREFIX . 'facture WHERE situation_counter>=1'; $sql.= ' ORDER by situation_cycle_ref, situation_counter desc'; $resql = $this->db->query($sql); if ($resql && $this->db->num_rows($resql) > 0) { // Last seen cycle $ref = 0; while ($res = $this->db->fetch_array($resql, MYSQL_NUM)) { //Same company ? if ($socid == $res[5]) { //Same cycle ? if ($res[2] != $ref) { // Just seen this cycle $ref = $res[2]; //not final ? if ($res[4] != 1) { //Not prov? if (substr($res[1], 1, 4) != 'PROV') { if ($selected == $res[0]) { $opt .= ''; } else { $opt .= ''; } } } } } } } else { dol_syslog("Error sql=" . $sql . ", error=" . $this->error, LOG_ERR); } if ($opt == '') { $opt = ''; } return $opt; } /** * Creates HTML units selector (code => label) * * @param string $selected Preselected Unit ID * @param string $htmlname Select name * @param int $showempty Add a nempty line * @return string HTML select */ function selectUnits($selected = '', $htmlname = 'units', $showempty=0) { global $langs; $langs->load('products'); $return= ''; } return $return; } /** * Return a HTML select list of bank accounts * * @param string $selected Id account pre-selected * @param string $htmlname Name of select zone * @param int $statut Status of searched accounts (0=open, 1=closed, 2=both) * @param string $filtre To filter list * @param int $useempty 1=Add an empty value in list, 2=Add an empty value in list only if there is more than 2 entries. * @param string $moreattrib To add more attribute on select * @return void */ function select_comptes($selected='',$htmlname='accountid',$statut=0,$filtre='',$useempty=0,$moreattrib='') { global $langs, $conf; $langs->load("admin"); $sql = "SELECT rowid, label, bank, clos as status"; $sql.= " FROM ".MAIN_DB_PREFIX."bank_account"; $sql.= " WHERE entity IN (".getEntity('bank_account', 1).")"; if ($statut != 2) $sql.= " AND clos = '".$statut."'"; if ($filtre) $sql.=" AND ".$filtre; $sql.= " ORDER BY label"; dol_syslog(get_class($this)."::select_comptes", LOG_DEBUG); $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); } } /** * Display form to select bank account * * @param string $page Page * @param int $selected Id of bank account * @param string $htmlname Name of select html field * @param int $addempty 1=Add an empty value in list, 2=Add an empty value in list only if there is more than 2 entries. * @return void */ function formSelectAccount($page, $selected='', $htmlname='fk_account', $addempty=0) { global $langs; if ($htmlname != "none") { print '
'; print ''; print ''; print ''; print ''; print ''; print '
'; $this->select_comptes($selected, $htmlname, 0, '', $addempty); print '
'; } else { if ($selected) { require_once DOL_DOCUMENT_ROOT .'/compta/bank/class/account.class.php'; $bankstatic=new Account($this->db); $bankstatic->fetch($selected); print $this->textwithpicto($bankstatic->label,$langs->trans("AccountCurrency").' '.$bankstatic->currency_code); } else { print " "; } } } /** * Return list of categories having choosed type * * @param int $type Type de categories (0=product, 1=supplier, 2=customer, 3=member) * @param string $selected Id of category preselected or 'auto' (autoselect category if there is only one element) * @param string $htmlname HTML field name * @param int $maxlength Maximum length for labels * @param int $excludeafterid Exclude all categories after this leaf in category tree. * @param int $outputmode 0=HTML select string, 1=Array * @return string * @see select_categories */ function select_all_categories($type, $selected='', $htmlname="parent", $maxlength=64, $excludeafterid=0, $outputmode=0) { global $langs; $langs->load("categories"); $cat = new Categorie($this->db); $cate_arbo = $cat->get_full_arbo($type,$excludeafterid); $output = ''; $output.= "\n"; if ($outputmode) return $outarray; return $output; } /** * 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 forms complementary inputs * @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 * @param int $width Force width of box * @return void * @deprecated * @see formconfirm() */ 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. * Easiest way to use this is with useajax=1. * If you use useajax='xxx', you must also add jquery code to trigger opening of box (with correct parameters) * just after calling this method. For example: * print ''."\n"; * * @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'=Yes and preoutput confirm box with div id=dialog-confirm-xxx * @param int $height Force height of box * @param int $width Force width of bow * @return string HTML ajax code if a confirm ajax popup is required, Pure HTML code if it's an html form */ function formconfirm($page, $title, $question, $action, $formquestion='', $selectedchoice="", $useajax=0, $height=170, $width=500) { global $langs,$conf; global $useglobalvars; $more=''; $formconfirm=''; $inputok=array(); $inputko=array(); // Clean parameters $newselectedchoice=empty($selectedchoice)?"no":$selectedchoice; if (is_array($formquestion) && ! empty($formquestion)) { // First add hidden fields and value foreach ($formquestion as $key => $input) { if (is_array($input) && ! empty($input)) { if ($input['type'] == 'hidden') { $more.=''."\n"; } } } // Now add questions $more.=''."\n"; $more.=''."\n"; foreach ($formquestion as $key => $input) { if (is_array($input) && ! empty($input)) { $size=(! empty($input['size'])?' size="'.$input['size'].'"':''); 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"; } } } $more.='
'.(! empty($formquestion['text'])?$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"; } // JQUI method dialog is broken with jmobile, we use standard HTML. // Note: When using dol_use_jmobile or no js, you must also check code for button use a GET url with action=xxx and check that you also output the confirm code when action=xxx // See page product/card.php for example if (! empty($conf->dol_use_jmobile)) $useajax=0; if (empty($conf->use_javascript_ajax)) $useajax=0; if ($useajax) { $autoOpen=true; $dialogconfirm='dialog-confirm'; $button=''; if (! is_numeric($useajax)) { $button=$useajax; $useajax=1; $autoOpen=false; $dialogconfirm.='-'.$button; } $pageyes=$page.(preg_match('/\?/',$page)?'&':'?').'action='.$action.'&confirm=yes'; $pageno=($useajax == 2 ? $page.(preg_match('/\?/',$page)?'&':'?').'confirm=no':''); // Add input fields into list of fields to read during submit (inputok and inputko) if (is_array($formquestion)) { foreach ($formquestion as $key => $input) { if (isset($input['name'])) array_push($inputok,$input['name']); if (isset($input['inputko']) && $input['inputko'] == 1) array_push($inputko,$input['name']); } } // Show JQuery confirm box. Note that global var $useglobalvars is used inside this template $formconfirm.= ''."\n"; $formconfirm.= "\n\n"; $formconfirm.= ''; $formconfirm.= "\n"; } else { $formconfirm.= "\n\n"; $formconfirm.= '
'."\n"; $formconfirm.= ''."\n"; $formconfirm.= ''."\n"; $formconfirm.= ''."\n"; // Line title $formconfirm.= ''."\n"; // Line form fields if ($more) { $formconfirm.=''."\n"; } // Line with question $formconfirm.= ''; $formconfirm.= ''; $formconfirm.= ''; $formconfirm.= ''; $formconfirm.= ''."\n"; $formconfirm.= '
'.img_picto('','recent').' '.$title.'
'."\n"; $formconfirm.=$more; $formconfirm.='
'.$question.''; $formconfirm.= $this->selectyesno("confirm",$newselectedchoice); $formconfirm.= '
'."\n"; $formconfirm.= "
\n"; $formconfirm.= '
'; $formconfirm.= "\n"; } return $formconfirm; } /** * Show a form to select a project * * @param int $page Page * @param int $socid Id third party (-1=all, 0=only projects not linked to a third party, id=projects not linked or linked to third party id) * @param int $selected Id pre-selected project * @param string $htmlname Name of select field * @param int $discard_closed Discard closed projects (0=Keep,1=hide completely,2=Disable) * @param int $maxlength Max length * @param int $forcefocus Force focus on field (works with javascript only) * @return void */ function form_project($page, $socid, $selected='', $htmlname='projectid', $discard_closed=0, $maxlength=20, $forcefocus=0) { global $langs; require_once DOL_DOCUMENT_ROOT.'/core/lib/project.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php'; $formproject=new FormProjets($this->db); $langs->load("project"); if ($htmlname != "none") { print "\n"; print '
'; print ''; print ''; print ''; print ''; print ''; print '
'; $formproject->select_projects($socid,$selected,$htmlname,$maxlength,0,1,$discard_closed, $forcefocus); 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 int $page Page * @param string $selected Id condition pre-selectionne * @param string $htmlname Name of select html field * @param int $addempty Add empty entry * @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 int $page Page * @param string $selected Id condition pre-selectionne * @param string $htmlname Name of select html field * @param int $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->selectAvailabilityDelay($selected,$htmlname,-1,$addempty); print '
'; } else { if ($selected) { $this->load_cache_availability(); print $this->cache_availability[$selected]['label']; } else { print " "; } } } /** * Output HTML form to select list of input reason (events that triggered an object creation, like after sending an emailing, making an advert, ...) * List found into table c_input_reason loaded by loadCacheInputReason * * @param string $page Page * @param string $selected Id condition pre-selectionne * @param string $htmlname Name of select html field * @param int $addempty Add empty entry * @return void */ function formInputReason($page, $selected='', $htmlname='demandreason', $addempty=0) { global $langs; if ($htmlname != "none") { print '
'; print ''; print ''; print ''; print ''; print ''; print '
'; $this->selectInputReason($selected,$htmlname,-1,$addempty); print '
'; } else { if ($selected) { $this->loadCacheInputReason(); foreach ($this->cache_demand_reason as $key => $val) { if ($val['id'] == $selected) { print $val['label']; break; } } } else { print " "; } } } /** * Show a form + html select a date * * @param string $page Page * @param string $selected Date preselected * @param string $htmlname Html name of date input fields or 'none' * @param int $displayhour Display hour selector * @param int $displaymin Display minutes selector * @param int $nooutput 1=No print output, return string * @return void * @see select_date */ function form_date($page, $selected, $htmlname, $displayhour=0, $displaymin=0, $nooutput=0) { global $langs; $ret=''; if ($htmlname != "none") { $ret.='
'; $ret.=''; $ret.=''; $ret.=''; $ret.=''; $ret.=''; $ret.='
'; $ret.=$this->select_date($selected,$htmlname,$displayhour,$displaymin,1,'form'.$htmlname); $ret.='
'; } else { if ($displayhour) $ret.=dol_print_date($selected,'dayhour'); else $ret.=dol_print_date($selected,'day'); } if (empty($nooutput)) print $ret; return $ret; } /** * Show a select form to choose a user * * @param string $page Page * @param string $selected Id of user preselected * @param string $htmlname Name of input html field. If 'none', we just output the user link. * @param array $exclude List of users id to exclude * @param array $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'; $theuser=new User($this->db); $theuser->fetch($selected); print $theuser->getNomUrl(1); } else { print " "; } } } /** * Affiche formulaire de selection des modes de reglement * * @param string $page Page * @param int $selected Id mode pre-selectionne * @param string $htmlname Name of select html field * @param string $filtertype To filter on field type in llx_c_paiement (array('code'=>xx,'label'=>zz)) * @return void */ function form_modes_reglement($page, $selected='', $htmlname='mode_reglement_id', $filtertype='') { global $langs; if ($htmlname != "none") { print '
'; print ''; print ''; print ''; print ''; print ''; print '
'; $this->select_types_paiements($selected,$htmlname,$filtertype); 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. Example 'remise_id'. * @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, $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,0,$langs,0,0,-1,$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,0,$langs,0,0,-1,$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,0,$langs,0,0,-1,$conf->currency)).': '; else print $langs->trans("CompanyHasCreditNote",price($amount,0,$langs,0,0,-1,$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"; } } } /** * Show forms to select a contact * * @param string $page Page * @param Societe $societe Filter on third party * @param int $selected Id contact pre-selectionne * @param string $htmlname Name of HTML select. If 'none', we just show contact link. * @return void */ function form_contacts($page, $societe, $selected='', $htmlname='contactid') { global $langs, $conf; if ($htmlname != "none") { print '
'; print ''; print ''; print ''; print ''; print ''; print '
'; $num=$this->select_contacts($societe->id, $selected, $htmlname); if ($num==0) { $addcontact = (! empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) ? $langs->trans("AddContact") : $langs->trans("AddContactAddress")); print 'Cette societe n\'a pas de contact, veuillez en cr�er un avant de faire votre proposition commerciale
'; print ''.$addcontact.''; } print '
'; } else { if ($selected) { require_once DOL_DOCUMENT_ROOT .'/contact/class/contact.class.php'; $contact=new Contact($this->db); $contact->fetch($selected); print $contact->getFullName($langs); } else { print " "; } } } /** * Output html select to select thirdparty * * @param string $page Page * @param string $selected Id preselected * @param string $htmlname Name of HTML select * @param string $filter optional filters criteras * @param int $showempty Add an empty field * @param int $showtype Show third party type in combolist (customer, prospect or supplier) * @param int $forcecombo Force to use combo box * @param array $events Event options. Example: array(array('method'=>'getContacts', 'url'=>dol_buildpath('/core/ajax/contacts.php',1), 'htmlname'=>'contactid', 'params'=>array('add-customer-contact'=>'disabled'))) * @return void */ function form_thirdparty($page, $selected='', $htmlname='socid', $filter='',$showempty=0, $showtype=0, $forcecombo=0, $events=array()) { global $langs; if ($htmlname != "none") { print '
'; print ''; print ''; print ''; print ''; print ''; print '
'; print $this->select_company($selected, $htmlname, $filter, $showempty, $showtype, $forcecombo, $events); 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 " "; } } } /** * Retourne la liste des devises, dans la langue de l'utilisateur * * @param string $selected preselected currency code * @param string $htmlname name of HTML select list * @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 string $selected preselected currency code * @param string $htmlname name of HTML select list * @return string */ function selectCurrency($selected='',$htmlname='currency_id') { global $conf,$langs,$user; $langs->loadCacheCurrencies(''); $out=''; if ($selected=='euro' || $selected=='euros') $selected='EUR'; // Pour compatibilite $out.= ''; if ($user->admin) $out.= info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1); return $out; } /** * Load into the cache vat rates of a country * * @param string $country_code Country code * @return int Nb of loaded lines, 0 if already loaded, <0 if KO */ function load_cache_vatrates($country_code) { global $langs; $num = count($this->cache_vatrates); if ($num > 0) return $num; // Cache already loaded dol_syslog(__METHOD__, LOG_DEBUG); $sql = "SELECT DISTINCT t.taux, t.recuperableonly"; $sql.= " FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_country as c"; $sql.= " WHERE t.fk_pays = c.rowid"; $sql.= " AND t.active > 0"; $sql.= " AND c.code IN (".$country_code.")"; $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); $this->cache_vatrates[$i]['txtva'] = $obj->taux; $this->cache_vatrates[$i]['libtva'] = $obj->taux.'%'; $this->cache_vatrates[$i]['nprtva'] = $obj->recuperableonly; } return $num; } else { $this->error = ''.$langs->trans("ErrorNoVATRateDefinedForSellerCountry",$country_code).''; return -1; } } else { $this->error = ''.$this->db->error().''; return -2; } } /** * Output an HTML select vat rate. * The name of this function should be selectVat. We keep bad name for compatibility purpose. * * @param string $htmlname Name of html select field * @param float $selectedrate Force preselected vat rate. Use '' for no forcing. * @param Societe $societe_vendeuse Thirdparty seller * @param Societe $societe_acheteuse Thirdparty buyer * @param int $idprod Id product * @param int $info_bits Miscellaneous information on line (1 for NPR) * @param int $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 Communauté européenne et acheteur= particulier alors TVA par défaut=TVA du produit vendu. Fin de règle. * Si vendeur et acheteur dans Communauté européenne et acheteur= entreprise alors TVA par défaut=0. Fin de règle. * Sinon la TVA proposee par defaut=0. Fin de regle. * @param bool $options_only Return options only (for ajax treatment) * @return string */ function load_tva($htmlname='tauxtva', $selectedrate='', $societe_vendeuse='', $societe_acheteuse='', $idprod=0, $info_bits=0, $type='', $options_only=false) { global $langs,$conf,$mysoc; $return=''; // 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; // Define list of countries to use to search VAT rates to show // First we defined code_country to use to find list if (is_object($societe_vendeuse)) { $code_country="'".$societe_vendeuse->country_code."'"; } else { $code_country="'".$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() && (! is_object($societe_acheteuse) || ($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_country.=",'".$societe_acheteuse->country_code."'"; } } else if (! $idprod) // We don't know type of product { $code_country.=",'".$societe_acheteuse->country_code."'"; } else { $prodstatic=new Product($this->db); $prodstatic->fetch($idprod); if ($prodstatic->type == Product::TYPE_SERVICE) // We know product is a service { $code_country.=",'".$societe_acheteuse->country_code."'"; } } } } // Now we get list $num = $this->load_cache_vatrates($code_country); if ($num > 0) { // 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) { if (empty($conf->global->MAIN_VAT_DEFAULT_IF_AUTODETECT_FAILS)) $defaulttx = $this->cache_vatrates[$num-1]['txtva']; else $defaulttx=($conf->global->MAIN_VAT_DEFAULT_IF_AUTODETECT_FAILS == 'none' ? '' : $conf->global->MAIN_VAT_DEFAULT_IF_AUTODETECT_FAILS); } // Disabled if seller is not subject to VAT $disabled=false; $title=''; if (is_object($societe_vendeuse) && $societe_vendeuse->id == $mysoc->id && $societe_vendeuse->tva_assuj == "0") { $title=' title="'.$langs->trans('VATIsNotUsed').'"'; $disabled=true; } if (! $options_only) $return.= 'trans("FormatDateShortJavaInput").'\'); "'; // FormatDateShortInput for dol_print_date / FormatDateShortJavaInput that is same for javascript $retstring.='>'; // Icone calendrier if (! $disabled) { $retstring.=''; } else $retstring.=''; $retstring.=''."\n"; $retstring.=''."\n"; $retstring.=''."\n"; } else { print "Bad value of MAIN_POPUP_CALENDAR"; } } // Show date with combo selects else { // Day $retstring.=''; if ($emptydate || $set_time == -1) { $retstring.=''; } for ($day = 1 ; $day <= 31; $day++) { $retstring.=''; } $retstring.=""; $retstring.=''; if ($emptydate || $set_time == -1) { $retstring.=''; } // Month for ($month = 1 ; $month <= 12 ; $month++) { $retstring.='"; } $retstring.=""; // Year if ($emptydate || $set_time == -1) { $retstring.=''; } else { $retstring.=''; for ($year = $syear - 5; $year < $syear + 10 ; $year++) { $retstring.=''; } $retstring.="\n"; } } } if ($d && $h) $retstring.=' '; if ($h) { // Show hour $retstring.=''; if ($emptyhours) $retstring.=''; for ($hour = 0; $hour < 24; $hour++) { if (strlen($hour) < 2) $hour = "0" . $hour; $retstring.=''; } $retstring.=''; if (empty($conf->dol_optimize_smallscreen)) $retstring.=":"; } if ($m) { // Show minutes $retstring.=''; if ($emptyhours) $retstring.=''; for ($min = 0; $min < 60 ; $min++) { if (strlen($min) < 2) $min = "0" . $min; $retstring.=''; } $retstring.=''; } // 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 ($usecalendar == "eldy") { $base=DOL_URL_ROOT.'/core/'; $reset_scripts .= 'resetDP(\''.$base.'\',\''.$prefix.'\',\''.$langs->trans("FormatDateShortJavaInput").'\',\''.$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 && empty($conf->dol_optimize_smallscreen)) { $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 for input fields * @param int $iSecond Default preselected duration (number of seconds or '') * @param int $disabled Disable the combo box * @param string $typehour If 'select' then input hour and input min is a combo, if 'text' input hour is in text and input min is a combo * @param string $minunderhours If 1, show minutes selection under the hours * @param int $nooutput Do not output html string but return it * @return void */ function select_duration($prefix, $iSecond='', $disabled=0, $typehour='select', $minunderhours=0, $nooutput=0) { global $langs; $retstring=''; $hourSelected=0; $minSelected=0; // Hours if ($iSecond != '') { require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; $hourSelected = convertSecondToTime($iSecond,'allhour'); $minSelected = convertSecondToTime($iSecond,'min'); } if ($typehour=='select') { $retstring.='"; } elseif ($typehour=='text') { $retstring.=''; } else return 'BadValueForParameterTypeHour'; $retstring.=' '.$langs->trans('HourShort'); // Minutes if ($minunderhours) $retstring.='
'; else $retstring.=" "; if ($typehour=='select') { $retstring.='"; } elseif ($typehour=='text') { $retstring.=''; } $retstring.=' '.$langs->trans('MinuteShort'); $retstring.=" "; if (! empty($nooutput)) return $retstring; print $retstring; return; } /** * Return a HTML select string, built from an array of key+value. * Note: Do not apply langs->trans function on returned content, content may be entity encoded twice. * * @param string $htmlname Name of html select area. Must start with "multi" if this is a multiselect * @param array $array Array with key+value * @param string|string[] $id Preselected key or preselected keys for multiselect * @param int $show_empty 0 no empty value allowed, 1 to add an empty value into list (value is '' or ' '). * @param int $key_in_label 1 pour afficher la key dans la valeur "[key] value" * @param int $value_as_key 1 to use value as key * @param string $moreparam Add more parameters onto the select tag * @param int $translate Translate and encode value * @param int $maxlen Length maximum for labels * @param int $disabled Html select box is disabled * @param int $sort 'ASC' or 'DESC' = Sort on label, '' or 'NONE' = Do not sort * @param string $morecss Add more class to css styles * @param int $addjscombo Add js combo * @return string HTML select string. * @see multiselectarray */ static function selectarray($htmlname, $array, $id='', $show_empty=0, $key_in_label=0, $value_as_key=0, $moreparam='', $translate=0, $maxlen=0, $disabled=0, $sort='', $morecss='', $addjscombo=0) { global $conf, $langs; // Do we want a multiselect ? $multiselect = 0; if (preg_match('/^multi/',$htmlname)) $multiselect = 1; if ($value_as_key) $array=array_combine($array, $array); $out=''; // Add code for jquery to use multiselect if ($addjscombo && empty($conf->dol_use_jmobile) && $multiselect) { $tmpplugin=empty($conf->global->MAIN_USE_JQUERY_MULTISELECT)?constant('REQUIRE_JQUERY_MULTISELECT')?constant('REQUIRE_JQUERY_MULTISELECT'):'select2':$conf->global->MAIN_USE_JQUERY_MULTISELECT; $out.=' '; } $out.=''."\n"; if (is_array($array) && ! empty($array)) { if ($value_as_key) $array=array_combine($array, $array); if (! empty($array)) { foreach ($array as $key => $value) { $out.= ''."\n"; } } } $out.= ''."\n"; return $out; } /** * Render list of categories linked to object with id $id and type $type * * @param int $id Id of object * @param string $type Type of category ('member', 'customer', 'supplier', 'product', 'contact'). Old mode (0, 1, 2, ...) is deprecated. * @param int $rendermode 0=Default, use multiselect. 1=Use text with link * @return mixed Array of category objects or < 0 if KO */ function showCategories($id, $type, $rendermode=0) { global $db; $cat = new Categorie($db); $categories = $cat->containing($id, $type); if ($rendermode == 1) { $toprint = array(); foreach($categories as $c) { $ways = $c->print_all_ways(); foreach($ways as $way) { $toprint[] = img_object('','category').' '.$way; } } return implode('
', $toprint); } if ($rendermode == 0) { $cate_arbo = $this->select_all_categories(Categorie::TYPE_PRODUCT, '', 'parent', 64, 0, 1); foreach($categories as $c) { $arrayselected[] = $c->id; } return $this->multiselectarray('categories', $cate_arbo, $arrayselected, '', 0, '', 0, '100%', 'disabled', 'category'); } return 'ErrorBadValueForParameterRenderMode'; // Should not happened } /** * Show linked object block. * * @param CommonObject $object Object we want to show links to * @return int <0 if KO, >0 if OK */ function showLinkedObjectBlock($object) { global $conf,$langs,$hookmanager; global $bc; $object->fetchObjectLinked(); // Bypass the default method $hookmanager->initHooks(array('commonobject')); $parameters=array(); $reshook=$hookmanager->executeHooks('showLinkedObjectBlock',$parameters,$object,$action); // Note that $action and $object may have been modified by hook if (empty($reshook)) { $num = count($object->linkedObjects); foreach($object->linkedObjects as $objecttype => $objects) { $tplpath = $element = $subelement = $objecttype; if (preg_match('/^([^_]+)_([^_]+)/i',$objecttype,$regs)) { $element = $regs[1]; $subelement = $regs[2]; $tplpath = $element.'/'.$subelement; } // To work with non standard path if ($objecttype == 'facture') { $tplpath = 'compta/'.$element; if (empty($conf->facture->enabled)) continue; // Do not show if module disabled } else if ($objecttype == 'propal') { $tplpath = 'comm/'.$element; if (empty($conf->propal->enabled)) continue; // Do not show if module disabled } else if ($objecttype == 'askpricesupplier') { $tplpath = 'comm/'.$element; if (empty($conf->askpricesupplier->enabled)) continue; // Do not show if module disabled } else if ($objecttype == 'shipping' || $objecttype == 'shipment') { $tplpath = 'expedition'; if (empty($conf->expedition->enabled)) continue; // Do not show if module disabled } else if ($objecttype == 'delivery') { $tplpath = 'livraison'; if (empty($conf->expedition->enabled)) continue; // Do not show if module disabled } else if ($objecttype == 'invoice_supplier') { $tplpath = 'fourn/facture'; } else if ($objecttype == 'order_supplier') { $tplpath = 'fourn/commande'; } global $linkedObjectBlock; $linkedObjectBlock = $objects; // Output template part (modules that overwrite templates must declare this into descriptor) $dirtpls=array_merge($conf->modules_parts['tpl'],array('/'.$tplpath.'/tpl')); foreach($dirtpls as $reldir) { $res=@include dol_buildpath($reldir.'/linkedobjectblock.tpl.php'); if ($res) break; } } return $num; } } /** * Show block with links to link to other objects. * * @param CommonObject $object Object we want to show links to * @param array $restrictlinksto Restrict links to some elements, for exemple array('order') or array('supplier_order') * @return int <0 if KO, >0 if OK */ function showLinkToObjectBlock($object, $restrictlinksto=array()) { global $conf, $langs, $hookmanager; global $bc; $linktoelem=''; if (! is_object($object->thirdparty)) $object->fetch_thirdparty(); if (((! is_array($restrictlinksto)) || in_array('order',$restrictlinksto)) && ! empty($conf->commande->enabled)) { $linktoelem.=($linktoelem?'   ':'').'' . $langs->trans('LinkedOrder') . ''; print ' '; print '
global->MAIN_OPTIMIZEFORTEXTBROWSER)?' style="display:none"':'').'>'; $sql = "SELECT s.rowid as socid, s.nom as name, s.client, c.rowid, c.ref, c.ref_client, c.total_ht"; $sql .= " FROM " . MAIN_DB_PREFIX . "societe as s"; $sql .= ", " . MAIN_DB_PREFIX . "commande as c"; $sql .= ' WHERE c.fk_soc = s.rowid AND c.fk_soc = ' . $object->thirdparty->id . ''; $resqlorderlist = $this->db->query($sql); if ($resqlorderlist) { $num = $this->db->num_rows($resqlorderlist); $i = 0; print '
'; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; while ($i < $num) { $objp = $this->db->fetch_object($resqlorderlist); $var = ! $var; print ''; print ''; print ''; print ''; print ''; print ''; print ''; $i ++; } print '
' . $langs->trans("Ref") . '' . $langs->trans("RefCustomer") . '' . $langs->trans("AmountHTShort") . '' . $langs->trans("Company") . '
'; print ''; print '' . $objp->ref . '' . $objp->ref_client . '' . price($objp->total_ht) . '' . $objp->name . '
'; print '
     
'; print '
'; $this->db->free($resqlorderlist); } else { dol_print_error($this->db); } print '
'; } if (((! is_array($restrictlinksto)) || in_array('supplier_order',$restrictlinksto)) && ! empty($conf->fournisseur->enabled)) { $linktoelem.=($linktoelem?'   ':'').'' . $langs->trans('LinkedOrder') . ''; print ' '; print '
global->MAIN_OPTIMIZEFORTEXTBROWSER)?' style="display:none"':'').'>'; $sql = "SELECT s.rowid as socid, s.nom as name, s.client, c.rowid, c.ref, c.ref_supplier, c.total_ht"; $sql .= " FROM " . MAIN_DB_PREFIX . "societe as s"; $sql .= ", " . MAIN_DB_PREFIX . "commande_fournisseur as c"; $sql .= ' WHERE c.fk_soc = s.rowid AND c.fk_soc = ' . $object->thirdparty->id; $resqlorderlist = $this->db->query($sql); if ($resqlorderlist) { $num = $this->db->num_rows($resqlorderlist); $i = 0; print '
'; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; while ($i < $num) { $objp = $this->db->fetch_object($resqlorderlist); if ($objp->socid == $societe->id) { $var = ! $var; print ''; print ''; print ''; print ''; print ''; print ''; print ''; } $i ++; } print '
' . $langs->trans("Ref") . '' . $langs->trans("RefSupplier") . '' . $langs->trans("AmountHTShort") . '' . $langs->trans("Company") . '
'; print ''; print '' . $objp->ref . '' . $objp->ref_supplier . '' . price($objp->total_ht) . '' . $objp->name . '
'; print '
 
'; print '
'; $this->db->free($resqlorderlist); } else { dol_print_error($this->db); } print '
'; } return $linktoelem; } /** * Return an html string with a select combo box to choose yes or no * * @param string $htmlname 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 * @param useempty $useempty 1=Add empty line * @return mixed See option */ function selectyesno($htmlname,$value='',$option=0,$disabled=false,$useempty='') { global $langs; $yes="yes"; $no="no"; if ($option) { $yes="1"; $no="0"; } $disabled = ($disabled ? ' disabled' : ''); $resultyesno = ''."\n"; return $resultyesno; } /** * Return list of export templates * * @param string $selected Id modele pre-selectionne * @param string $htmlname Name of HTML select * @param string $type Type of searched templates * @param int $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 Object to show * @param string $paramid Name of parameter to use to name the id into the URL link * @param string $morehtml More html content to output just before the nav bar * @param int $shownav Show Condition (navigation is shown if value is 1) * @param string $fieldid Nom du champ en base a utiliser pour select next et previous * @param string $fieldref Nom du champ objet ref (object->ref) a utiliser pour select next et previous * @param string $morehtmlref Code html supplementaire a afficher apres ref * @param string $moreparam More param to add in nav link url. * @param int $nodbprefix Do not include DB prefix to forge table name * @return string Portion HTML avec ref + boutons nav */ function showrefnav($object,$paramid,$morehtml='',$shownav=1,$fieldid='rowid',$fieldref='ref',$morehtmlref='',$moreparam='',$nodbprefix=0) { global $langs,$conf; $ret=''; if (empty($fieldid)) $fieldid='rowid'; if (empty($fieldref)) $fieldref='ref'; //print "paramid=$paramid,morehtml=$morehtml,shownav=$shownav,$fieldid,$fieldref,$morehtmlref,$moreparam"; $object->load_previous_next_ref((isset($object->next_prev_filter)?$object->next_prev_filter:''),$fieldid,$nodbprefix); //$previous_ref = $object->ref_previous?''.(empty($conf->dol_use_jmobile)?img_picto($langs->trans("Previous"),'previous.png'):' ').'':''; //$next_ref = $object->ref_next?''.(empty($conf->dol_use_jmobile)?img_picto($langs->trans("Next"),'next.png'):' ').'':''; $previous_ref = $object->ref_previous?''.(empty($conf->dol_use_jmobile)?'<':' ').'':''; $next_ref = $object->ref_next?''.(empty($conf->dol_use_jmobile)?'>':' ').'':''; //print "xx".$previous_ref."x".$next_ref; //if ($previous_ref || $next_ref || $morehtml) { //$ret.=''; //$ret.='
'; $ret.='
'; //} $ret.=dol_htmlentities($object->$fieldref); if ($morehtmlref) { $ret.=' '.$morehtmlref; } $ret.='
'; if ($previous_ref || $next_ref || $morehtml) { $ret.='
'.$morehtml; $ret.='
  • '.$morehtml.'
  • '; } if ($shownav && ($previous_ref || $next_ref)) { //$ret.='
    '.$previous_ref.''.$next_ref; $ret.=''; $ret.=''; } if ($previous_ref || $next_ref || $morehtml) { //$ret.='
    '; $ret.=''; } $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; //Check if barcode is filled in the card if (empty($object->barcode)) return ''; // Complete object if not complete if (empty($object->barcode_type_code) || empty($object->barcode_type_coder)) { $result = $object->fetch_barcode(); //Check if fetch_barcode() failed if ($result < 1) return ''; } // 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 * @param int $height Height of photo (auto if 0) * @param int $caneditfield Add edit fields * @param string $cssclass CSS name to use on img for photo * @return string HTML code to output photo */ static function showphoto($modulepart, $object, $width=100, $height=0, $caneditfield=0, $cssclass='photowithmargin') { global $conf,$langs; $entity = (! empty($object->entity) ? $object->entity : $conf->entity); $id = (! empty($object->id) ? $object->id : $object->rowid); $ret='';$dir='';$file='';$altfile='';$email=''; if ($modulepart=='societe') { $dir=$conf->societe->multidir_output[$entity]; $smallfile=$object->logo; $smallfile=preg_replace('/(\.png|\.gif|\.jpg|\.jpeg|\.bmp)/i','_small\\1',$smallfile); if ($object->logo) $file=$id.'/logos/thumbs/'.$smallfile; } else if ($modulepart=='userphoto') { $dir=$conf->user->dir_output; if ($object->photo) $file=get_exdir($id, 2, 0, 0, $object, 'user').$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($id, 2, 0, 0, $object, 'invoice_supplier').'photos/'.$object->photo; if (! empty($conf->global->MAIN_OLD_IMAGE_LINKS)) $altfile=$object->id.".jpg"; // For backward compatibility $email=$object->email; } else { $dir=$conf->$modulepart->dir_output; if ($object->photo) $file=get_exdir($id, 2, 0, 0, $adherent, 'member').'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)) { $ret.=''; $ret.='Photo'; $ret.=''; } else if ($altfile && file_exists($dir."/".$altfile)) { $ret.=''; $ret.='Photo alt'; $ret.=''; } else { $nophoto='/theme/common/nophoto.jpg'; if (in_array($modulepart,array('userphoto','contact'))) // For module thar are "physical" users { $nophoto='/theme/common/user_anonymous.png'; if ($object->gender == 'man') $nophoto='/theme/common/user_man.png'; if ($object->gender == 'woman') $nophoto='/theme/common/user_woman.png'; } if (! empty($conf->gravatar->enabled) && $email) { global $dolibarr_main_url_root; $ret.=''; $ret.='Photo found on Gravatar'; // gravatar need md5 hash } else { $ret.='No photo'; } } if ($caneditfield) { if ($object->photo) $ret.="
    \n"; $ret.=''; if ($object->photo) $ret.=''; $ret.=''; $ret.=''; $ret.='
    '.$langs->trans("Delete").'

    '.$langs->trans("PhotoFile").'
    '; } } else dol_print_error('','Call of showphoto with wrong parameters'); 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 0 or Id of environment to force * @return void * @see select_dolusers */ function select_dolgroups($selected='', $htmlname='groupid', $show_empty=0, $exclude='', $disabled=0, $include='', $enableonly='', $force_entity=0) { 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 as name"; 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(get_class($this)."::select_dolgroups", LOG_DEBUG); $resql=$this->db->query($sql); if ($resql) { // Enhance with select2 if ($conf->use_javascript_ajax) { include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php'; $comboenhancement = ajax_combobox($htmlname); $out.= $comboenhancement; $nodatarole=($comboenhancement?' data-role="none"':''); } $out.= ''; } else { dol_print_error($this->db); } return $out; } }