X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=blobdiff_plain;f=admin%2Fdb%2Fusers_db.inc;h=00acb48e2dc71c1919a2a4c1d3fabf6b48943961;hb=380ae03e2df9602d07d156ae93b87cbe59b01b3a;hp=496f18acc5304f7fae4e2d9222757fc1d2132c96;hpb=891fe0dc1e5f4da99e74565e41f0eb3b179127f0;p=fa-stable.git diff --git a/admin/db/users_db.inc b/admin/db/users_db.inc index 496f18ac..00acb48e 100644 --- a/admin/db/users_db.inc +++ b/admin/db/users_db.inc @@ -54,35 +54,15 @@ function update_user($id, $user_id, $real_name, $phone, $email, $role_id, //----------------------------------------------------------------------------------------------- -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"); } //----------------------------------------------------------------------------------------------- @@ -163,4 +143,57 @@ function check_user_activity($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