* Copyright (C) 2007-2012 Regis Houssin * Copyright (C) 2012 Christophe Battarel * * 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 . * or see http://www.gnu.org/ */ /** * \file htdocs/core/lib/ajax.lib.php * \brief Page called by Ajax request for produts */ /** * Get value of an HTML field, do Ajax process and show result. * The HTML field must be an input text with id=search_$htmlname. * * @param string $selected Preselecte value * @param string $htmlname HTML name of input field * @param string $url Url for request: /chemin/fichier.php * @param string $urloption More parameters on URL request * @param int $minLength Minimum number of chars to trigger that Ajax search * @param int $autoselect Automatic selection if just one value * @param array $ajaxoptions Multiple options array (Ex: array('update'=>array('field1','field2'...)) will reset field1 and field2 once select done * @return string Script */ function ajax_autocompleter($selected, $htmlname, $url, $urloption='', $minLength=2, $autoselect=0, $ajaxoptions=array()) { if (empty($minLength)) $minLength=1; $script = ''; $script.= ''; return $script; } /** * Get value of field, do Ajax process and return result * * @param string $htmlname Name of field * @param string $fields other fields to autocomplete * @param string $url Chemin du fichier de reponse : /chemin/fichier.php * @param string $option More parameters on URL request * @param int $minLength Minimum number of chars to trigger that Ajax search * @param int $autoselect Automatic selection if just one value * @return string Script */ function ajax_multiautocompleter($htmlname,$fields,$url,$option='',$minLength=2,$autoselect=0) { $script = ''."\n"; $script.= ''; return $script; } /** * Show an ajax dialog * * @param string $title Title of dialog box * @param string $message Message of dialog box * @param int $w Width of dialog box * @param int $h height of dialog box * @return void */ function ajax_dialog($title,$message,$w=350,$h=150) { global $langs; $msg.= '
'; $msg.= $message; $msg.= '
'."\n"; $msg.= ''; $msg.= "\n"; return $msg; } /** * Convert a html select field into an ajax combobox. * Use ajax_combobox() only for small combo list! If not, use instead ajax_autocompleter(). * TODO: It is used when COMPANY_USE_SEARCH_TO_SELECT and CONTACT_USE_SEARCH_TO_SELECT are set by html.formcompany.class.php. Should use ajax_autocompleter instead like done by html.form.class.php for select_produits. * * @param string $htmlname Name of html select field * @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 int $minLengthToAutocomplete Minimum length of input string to start autocomplete * @return string Return html string to convert a select field into a combo */ function ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0) { global $conf; if (! empty($conf->browser->phone)) return ''; // combobox disabled for smartphones (does not works) if (! empty($conf->global->MAIN_DISABLE_AJAX_COMBOX)) return ''; /* Some properties for combobox: minLengthToAutocomplete: 2, comboboxContainerClass: "comboboxContainer", comboboxValueContainerClass: "comboboxValueContainer", comboboxValueContentClass: "comboboxValueContent", comboboxDropDownClass: "comboboxDropDownContainer", comboboxDropDownButtonClass: "comboboxDropDownButton", comboboxDropDownItemClass: "comboboxItem", comboboxDropDownItemHoverClass: "comboboxItemHover", comboboxDropDownGroupItemHeaderClass: "comboboxGroupItemHeader", comboboxDropDownGroupItemContainerClass: "comboboxGroupItemContainer", animationType: "slide", width: "500px" */ $msg = '\n"; return $msg; } /** * On/off button for constant * * @param string $code Name of constant * @param array $input Array of type->list of CSS element to switch. Example: array('disabled'=>array(0=>'cssid')) * @param int $entity Entity to set * @param int $revertonoff Revert on/off * @return void */ function ajax_constantonoff($code, $input=array(), $entity=null, $revertonoff=0) { global $conf, $langs; $entity = ((isset($entity) && is_numeric($entity) && $entity >= 0) ? $entity : $conf->entity); $out= "\n".' '."\n"; $out.= ''; $out.= ''.($revertonoff?img_picto($langs->trans("Enabled"),'switch_on'):img_picto($langs->trans("Disabled"),'switch_off')).''; $out.= ''.($revertonoff?img_picto($langs->trans("Disabled"),'switch_off'):img_picto($langs->trans("Enabled"),'switch_on')).''; $out.="\n"; return $out; } ?>