* Copyright (C) 2007-2011 Regis Houssin * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * or see http://www.gnu.org/ */ /** * \file htdocs/lib/ajax.lib.php * \brief Page called by Ajax request for produts * \version $Id: ajax.lib.php,v 1.59 2011/07/28 18:57:23 eldy Exp $ */ /** * Get value of an HTML field, do Ajax process and show result * @param selected Preselecte value * @param htmlname HTML name of input field * @param url Url for request: /chemin/fichier.php * @param option More parameters on URL request * @param minLength Minimum number of chars to trigger that Ajax search * @param autoselect Automatic selection if just one value * @return string script complet */ function ajax_autocompleter($selected='',$htmlname,$url,$option='',$minLength=2,$autoselect=0) { if (empty($minLength)) $minLength=1; $script = ''; $script.= ''; return $script; } /** * Get value of field, do Ajax process and return result * @param htmlname nom et id du champ * @param fields other fields to autocomplete * @param url chemin du fichier de reponse : /chemin/fichier.php * @param option More parameters on URL request * @param minLength Minimum number of chars to trigger that Ajax search * @param autoselect Automatic selection if just one value * @return string script complet */ function ajax_multiautocompleter($htmlname,$fields,$url,$option='',$minLength=2,$autoselect=0) { $script=''; $fields = php2js($fields); $script.= ''."\n"; $script.= ''; return $script; } /** * Show an ajax dialog * @param title Title of dialog box * @param message Message of dialog box * @param w Width of dialog box * @param h height of dialog box */ function ajax_dialog($title,$message,$w=350,$h=150) { global $langs; $msg.= '
'; $msg.= $message; $msg.= '
'."\n"; $msg.= ''; $msg.= "\n"; return $msg; } /** * Convert a select html field into an ajax combobox * * @param htmlname Name of html field * @return string Return html string to convert a select field into a combo */ function ajax_combobox($htmlname) { $msg.= ''; $msg.= "\n"; return $msg; } /** * On/off button for constant * * @param code Name of constant * @param input Input element * TODO add different method for other input (show/hide, disable, ..) */ function ajax_constantonoff($code,$input=array()) { global $conf, $langs; $out= ''; $out.= ''.img_picto($langs->trans("Disabled"),'switch_off').''; $out.= ''.img_picto($langs->trans("Enabled"),'switch_on').''; return $out; } /** * Convert a PHP array into a js array * @param $var * @return String with js array or false if error */ function php2js($var) { if (is_array($var)) { $res = "["; $array = array(); foreach ($var as $a_var) { $array[] = php2js($a_var); } return "[" . join(",", $array) . "]"; } elseif (is_bool($var)) { return $var ? "true" : "false"; } elseif (is_int($var) || is_integer($var) || is_double($var) || is_float($var)) { return $var; } elseif (is_string($var)) { return "\"" . addslashes(stripslashes($var)) . "\""; } // autres cas: objets, on ne les gère pas return false; } ?>