X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=blobdiff_plain;f=admin%2Fdb%2Fusers_db.inc;h=d9e3dae33251e749bcac37a92d7e040c73e755be;hb=510d6e1925c4d1621ae3efd85e117cc9bb4320f0;hp=1f0703dd8b339694964f899e45a2ba6028631a62;hpb=902f1015d874c33bd7946b17de2ad80b4f2144b6;p=fa-stable.git diff --git a/admin/db/users_db.inc b/admin/db/users_db.inc index 1f0703dd..d9e3dae3 100644 --- a/admin/db/users_db.inc +++ b/admin/db/users_db.inc @@ -16,9 +16,10 @@ function add_user($user_id, $real_name, $password, $phone, $email, $role_id, $sql = "INSERT INTO ".TB_PREF."users (user_id, real_name, password" .", phone, email, role_id, language, pos, print_profile, rep_popup) VALUES (".db_escape($user_id).", - ".db_escape($real_name).", ".db_escape($password) .",".db_escape($phone).", - ".db_escape($email).", $role_id, ".db_escape($language).", - $pos,".db_escape($profile).",$rep_popup)"; + ".db_escape($real_name).", ".db_escape($password) .",".db_escape($phone) + .",".db_escape($email).", ".db_escape($role_id).", ".db_escape($language) + .", ".db_escape($pos).",".db_escape($profile).",".db_escape($rep_popup) + ." )"; db_query($sql, "could not add user for $user_id"); } @@ -41,11 +42,11 @@ function update_user($id, $user_id, $real_name, $phone, $email, $role_id, $sql = "UPDATE ".TB_PREF."users SET real_name=".db_escape($real_name). ", phone=".db_escape($phone).", email=".db_escape($email).", - role_id=$role_id, + role_id=".db_escape($role_id).", language=".db_escape($language).", print_profile=".db_escape($profile).", - rep_popup=$rep_popup, - pos=$pos, + rep_popup=".db_escape($rep_popup).", + pos=".db_escape($pos).", user_id = " . db_escape($user_id) . " WHERE id=" . db_escape($id); db_query($sql, "could not update user for $user_id"); @@ -71,11 +72,11 @@ function update_user_display_prefs($id, $price_dec, $qty_dec, $exrate_dec, dec_sep=".db_escape($dec_sep).", theme=".db_escape($theme).", page_size=".db_escape($pagesize).", - show_hints=$show_hints, + show_hints=".db_escape($show_hints).", print_profile=".db_escape($profile).", - rep_popup=$rep_popup, - query_size=$query_size, - graphic_links=$graphic_links, + 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)." @@ -136,8 +137,8 @@ function get_user_for_login($user_id, $password) // do not exclude inactive records or you lost access after source upgrade // on sites using pre 2.2 database - $sql = "SELECT * FROM ".TB_PREF."users WHERE user_id = '$user_id' AND" - ." password='$password'"; + $sql = "SELECT * FROM ".TB_PREF."users WHERE user_id = ".db_escape($user_id)." AND" + ." password=".db_escape($password); return db_query($sql, "could not get validate user login for $user_id"); } @@ -162,4 +163,56 @@ 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) + return ""; + if (db_num_rows(db_query("SHOW TABLES LIKE '".TB_PREF."useronline'")) == 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