//-----------------------------------------------------------------------------------------------
-function update_user_display_prefs($id, $price_dec, $qty_dec, $exrate_dec,
- $percent_dec, $showgl, $showcodes, $date_format, $date_sep, $tho_sep,
- $dec_sep, $theme, $pagesize, $show_hints, $profile, $rep_popup, $query_size,
- $graphic_links, $lang, $stickydate, $startup_tab)
+function update_user_prefs($id, $prefs)
{
- $sql = "UPDATE ".TB_PREF."users SET
- prices_dec=".db_escape($price_dec).",
- qty_dec=".db_escape($qty_dec).",
- rates_dec=".db_escape($exrate_dec).",
- percent_dec=".db_escape($percent_dec).",
- show_gl=".db_escape($showgl).",
- show_codes=".db_escape($showcodes).",
- date_format=".db_escape($date_format).",
- date_sep=".db_escape($date_sep).",
- tho_sep=".db_escape($tho_sep).",
- dec_sep=".db_escape($dec_sep).",
- theme=".db_escape($theme).",
- page_size=".db_escape($pagesize).",
- show_hints=".db_escape($show_hints).",
- print_profile=".db_escape($profile).",
- rep_popup=".db_escape($rep_popup).",
- query_size=".db_escape($query_size).",
- graphic_links=".db_escape($graphic_links).",
- language=".db_escape($lang).",
- sticky_doc_date=".db_escape($stickydate).",
- startup_tab=".db_escape($startup_tab)."
- WHERE id = ".db_escape($id);
-
- db_query($sql, "could not update user display prefs for $id");
+ $sql = "UPDATE ".TB_PREF."users SET ";
+ foreach($prefs as $name => $value) {
+ $prefs[$name] = $name.'='. db_escape($value);
+ }
+ $sql .= implode(',', $prefs) . " WHERE id=".db_escape($id);
+
+ return db_query($sql, "could not update user display prefs for $id");
}
//-----------------------------------------------------------------------------------------------
return $ret[0];
}
+
+//-----------------------------------------------------------------------------------------------
+function show_users_online()
+{
+ global $show_users_online;
+
+ if (!isset($show_users_online) || $show_users_online == 0 || !defined('TB_PREF') || !isset($_SESSION['get_text']))
+ return "";
+ $result = db_query("SHOW TABLES LIKE '".TB_PREF."useronline'");
+ if (db_num_rows($result) == 1)
+ {
+ $timeoutseconds = 120;
+
+ $timestamp=time();
+ $timeout=$timestamp-$timeoutseconds;
+ /*
+ This will find out if user is from behind proxy server.
+ In that case, the script would count them all as 1 user.
+ This function tryes to get real IP address.
+ */
+ if (isset($_SERVER['HTTP_CLIENT_IP'])) {
+ $ip = $_SERVER['HTTP_CLIENT_IP'];
+ }
+ elseif (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
+ $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
+ }
+ elseif (isset($_SERVER['HTTP_X_FORWARDED'])) {
+ $ip = $_SERVER['HTTP_X_FORWARDED'];
+ }
+ elseif (isset($_SERVER['HTTP_FORWARDED_FOR'])) {
+ $ip = $_SERVER['HTTP_FORWARDED_FOR'];
+ }
+ elseif (isset($_SERVER['HTTP_FORWARDED'])) {
+ $ip = $_SERVER['HTTP_FORWARDED'];
+ }
+ else {
+ $ip = $_SERVER['REMOTE_ADDR'];
+ }
+
+ // Add user to database
+ db_query("INSERT INTO ".TB_PREF."useronline (timestamp, ip, file) VALUES ('". $timestamp ."','". $ip ."','". $_SERVER['PHP_SELF'] ."')");
+ //Remove users that were not online within $timeoutseconds.
+ db_query("DELETE FROM ".TB_PREF."useronline WHERE timestamp<". $timeout);
+
+ // Select online users
+ $result = db_query("SELECT DISTINCT ip FROM ".TB_PREF."useronline");
+ $users = db_num_rows($result);
+ }
+ else
+ $users = 1;
+ return "$users ".($users == 1 ? _("user online") : _("users online"));
+
+}
?>
\ No newline at end of file