/***************************************************************************
* copyright : (C) 2001,2002 Advanced Internet Designs Inc.
* email : forum@prohost.org
*
* $Id: root_index.php.t,v 1.4 2002/06/19 00:08:19 hackie Exp $
****************************************************************************
****************************************************************************
*
* 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.
*
***************************************************************************/
include_once "GLOBALS.php";
if ( !function_exists('error_handler') ) fud_use('err.inc');
if ( !defined('_db_connection_ok_') ) {
$connect_func = ( $GLOBALS['MYSQL_PERSIST'] == 'Y' ) ? 'mysql_pconnect' : 'mysql_connect';
if ( !($GLOBALS['__DB_INC__']['SQL_LINK']=$connect_func($GLOBALS['MYSQL_SERVER'], $GLOBALS['MYSQL_LOGIN'], $GLOBALS['MYSQL_PASSWORD'])) ) {
error_handler("db.inc", "unable to establish mysql connection on ".$GLOBALS['MYSQL_SERVER'], 0);
}
if ( !@mysql_select_db($GLOBALS['MYSQL_DB'],$GLOBALS['__DB_INC__']['SQL_LINK']) ) {
error_handler("db.inc", "unable to connect to database", 0);
}
define('_db_connection_ok_', 1);
}
function yn($val)
{
return ( strlen($val) && strtolower($val) != 'n' ) ? 'Y' : 'N';
}
function intnull($val)
{
return ( strlen($val) ) ? $val : 'NULL';
}
function intzero($val)
{
return ( !empty($val) ) ? $val : '0';
}
function ifnull($val, $alt)
{
return ( strlen($val) ) ? "'".$val."'" : $alt;
}
function strnull($val)
{
return ( strlen($val) ) ? "'".$val."'" : 'NULL';
}
function db_lock($tables)
{
if ( !empty($GLOBALS['__DB_INC_INTERNALS__']['db_locked']) ) {
exit("recursive lock");
}
$tables = str_replace("\t", '', $tables);
$tbl_arr = explode(',', $tables);
$tbl_n = count($tbl_arr);
$sql_str='';
for ( $i=0; $i<$tbl_n; $i++ ) {
$tbl_arr[$i] = trim($tbl_arr[$i]);
if ( substr($tbl_arr[$i], -1) == '+' ) {
$mode = ' WRITE';
$tbl_arr[$i] = substr($tbl_arr[$i], 0, strlen($tbl_arr[$i])-1);
}
else {
$mode = ' READ';
}
$sql_str .= ' '.$tbl_arr[$i].$mode.',';
}
$sql_str = substr($sql_str, 0, strlen($sql_str)-1);
$query = "LOCK TABLES".$sql_str;
if ( !q($query) ) {
exit("db_lock() error (".mysql_error($GLOBALS['__DB_INC__']['SQL_LINK']).")\n");
}
$GLOBALS['__DB_INC_INTERNALS__']['db_locked'] = 1;
}
function db_unlock()
{
if ( !q('UNLOCK TABLES',$GLOBALS['__DB_INC__']['SQL_LINK']) ) {
exit("DB_UNLOCK FAILED\n");
}
if ( !isset($GLOBALS['__DB_INC_INTERNALS__']['db_locked']) ) {
exit("DB_UNLOCK: no previous lock established\n");
}
if ( --$GLOBALS['__DB_INC_INTERNALS__']['db_locked'] < 0 ) {
exit("DB_UNLOCK: unlock overcalled\n");
}
}
function db_locked()
{
return isset($GLOBALS['__DB_INC_INTERNALS__']['db_locked'])?$GLOBALS['__DB_INC_INTERNALS__']['db_locked']:NULL;
}
function db_affected()
{
return mysql_affected_rows($GLOBALS['__DB_INC__']['SQL_LINK']);
}
function q($query)
{
if ( !isset($GLOBALS['__DB_INC_INTERNALS__']['query_count']) )
$GLOBALS['__DB_INC_INTERNALS__']['query_count'] = 1;
else
++$GLOBALS['__DB_INC_INTERNALS__']['query_count'];
if ( !isset($GLOBALS['__DB_INC_INTERNALS__']['total_sql_time']) ) $GLOBALS['__DB_INC_INTERNALS__']['total_sql_time'] = 0;
$ts = db_getmicrotime();
if ( !($result=mysql_query($query,$GLOBALS['__DB_INC__']['SQL_LINK'])) ) {
$error_reason = mysql_error($GLOBALS['__DB_INC__']['SQL_LINK']);
error_handler("db.inc", "query failed: %( $query )% because %( $error_reason )%", 1);
echo "Query Failed: ".htmlspecialchars($query)."
\nReason: ".$error_reason."
\nFrom: ".$GLOBALS['SCRIPT_FILENAME']."
\nServer Version: ".q_singleval("SELECT VERSION()")."
\n";
if( db_locked() ) db_unlock();
exit;
}
$te = db_getmicrotime();
$GLOBALS['__DB_INC_INTERNALS__']['last_time'] = $te-$ts;
$GLOBALS['__DB_INC_INTERNALS__']['total_sql_time'] += $GLOBALS['__DB_INC_INTERNALS__']['last_time'];
$GLOBALS['__DB_INC_INTERNALS__']['last_query'] = $query;
return $result;
}
function qf($result)
{
mysql_free_result($result);
}
function query_count()
{
return $GLOBALS['__DB_INC_INTERNALS__']['query_count'];
}
function last_query($filter='')
{
if ( $filter )
return str_replace("\t", "", str_replace("\n", " ", $GLOBALS['__DB_INC_INTERNALS__']['last_query']));
else
return $GLOBALS['__DB_INC_INTERNALS__']['last_query'];
}
function last_time()
{
return $GLOBALS['__DB_INC_INTERNALS__']['last_time'];
}
function total_time()
{
return $GLOBALS['__DB_INC_INTERNALS__']['total_sql_time'];
}
function db_count($result)
{
if ( $n=@mysql_num_rows($result) )
return $n;
else
return 0;
}
function db_lastid()
{
return mysql_insert_id($GLOBALS['__DB_INC__']['SQL_LINK']);
}
function db_seek($result,$pos)
{
return mysql_data_seek($result,$pos);
}
function db_rowobj($result)
{
return mysql_fetch_object($result);
}
function db_rowarr($result)
{
return mysql_fetch_row($result);
}
function bq($query)
{
$res = q($query);
if ( is_result($res) ) { qf($res); return 1; }
return 0;
}
function qobj($qry, &$obj)
{
$r = q($qry);
$robj = db_singleobj($r);
if ( !$robj ) return;
reset($robj);
while ( list($k, $v) = each($robj) ) {
$obj->{$k} = $v;
}
return $robj;
}
function is_result($res)
{
if ( db_count($res) )
return $res;
qf($res);
return;
}
function db_singleobj($res)
{
$obj = db_rowobj($res);
qf($res);
return $obj;
}
function db_singlearr($res)
{
$arr = db_rowarr($res);
qf($res);
return $arr;
}
function q_singleval($query)
{
$r = q($query);
if( !is_result($r) ) return;
list($val) = db_singlearr($r);
return $val;
}class fud_session
{
var $id=NULL;
var $ses_id=NULL;
var $tm=NULL;
var $user_id=NULL;
var $data=NULL;
var $action=NULL;
var $sys_id=NULL;
function update($str='')
{
if ( strlen($str) ) $this->action = $str;
q("UPDATE oamc_ses SET time_sec=".__request_timestamp__.", action=".strnull(addslashes($this->action))." WHERE id=".$this->id);
}
function putvar($name, $val)
{
$this->data[$name] = $val;
}
function getvar($name)
{
return $this->data[$name];
}
function rmvar($name)
{
unset($this->data[$name]);
}
function save_session($user_id='',$not_use_cookie='')
{
if ( !empty($user_id) ) $this->user_id = $user_id;
if( is_array($this->data) && count($this->data) ) {
reset($this->data);
$db_str = '$this->data = array(';
while ( list($key, $val) = each($this->data) ) {
$db_str .= "'".addcslashes($key,"'")."'=>'".addcslashes($val,"'")."',";;
}
$db_str = substr($db_str, 0, -1).');';
}
$this->tm = __request_timestamp__;
if ( empty($this->id) ) {
if ( !empty($this->user_id) && $this->user_id<2000000000 )
q("DELETE FROM oamc_ses WHERE user_id=".$this->user_id);
else
$this->user_id=0;
db_lock('oamc_ses+');
while ( bq("SELECT id FROM oamc_ses WHERE ses_id='".($ses_id = md5(get_random_value(128)))."'") );
if( empty($this->user_id) ) $this->user_id = q_singleval("SELECT IF(MAX(user_id)>2000000000,MAX(user_id)+1,2000000001) FROM oamc_ses");
q("INSERT INTO oamc_ses (ses_id,time_sec,data,sys_id,user_id) VALUES('".$ses_id."',".$this->tm.",'".addslashes($db_str)."', '".md5($GLOBALS["HTTP_SERVER_VARS"]["HTTP_USER_AGENT"].$GLOBALS["HTTP_SERVER_VARS"]["REMOTE_ADDR"].$GLOBALS["HTTP_SERVER_VARS"]["HTTP_X_FORWARDED_FOR"])."',".$this->user_id.")");
$this->id = db_lastid();
db_unlock();
$this->ses_id = $ses_id;
}
else {
if ( !empty($this->user_id) && $this->user_id<2000000000 ) {
q("DELETE FROM oamc_ses WHERE user_id=".$this->user_id." AND ses_id!='".$this->ses_id."'");
$usr_id_fld = ' user_id='.$this->user_id.',';
}
if( empty($GLOBALS['HTTP_COOKIE_VARS'][$GLOBALS['COOKIE_NAME']]) || $not_use_cookie )
$sys_id = md5($GLOBALS["HTTP_SERVER_VARS"]["HTTP_USER_AGENT"].$GLOBALS["HTTP_SERVER_VARS"]["REMOTE_ADDR"].$GLOBALS["HTTP_SERVER_VARS"]["HTTP_X_FORWARDED_FOR"]);
else
$sys_id = 0;
q("UPDATE oamc_ses SET sys_id='".$sys_id."', ".$usr_id_fld." time_sec=".$this->tm.", data='".addslashes($db_str)."' WHERE id=".$this->id);
}
if( empty($not_use_cookie) ) $this->cookie_set_session($this->ses_id);
return $this->ses_id;
}
function restore_session($ses_id)
{
if( empty($this->sys_id) )
qobj("SELECT * FROM oamc_ses WHERE ses_id='".$ses_id."'", $this);
else
qobj("SELECT * FROM oamc_ses WHERE ses_id='".$ses_id."' AND sys_id='".$this->sys_id."'", $this);
if( empty($this->id) ) return;
if( !empty($this->data) ) eval($this->data);
return $this->ses_id;
}
function delete_session()
{
if ( empty($this->id) ) return;
q("DELETE FROM oamc_ses WHERE id=".$this->id." OR ses_id='".$this->ses_id."'");
$this->user_id = $this->ses_id = $this->id = $this->data = $this->action = NULL;
clear_cookie();
return 1;
}
function cookie_set_session($ses_id)
{
setcookie($GLOBALS['COOKIE_NAME'], $ses_id, __request_timestamp__+$GLOBALS['COOKIE_TIMEOUT'], $GLOBALS['COOKIE_PATH'], $GLOBALS['COOKIE_DOMAIN']);
}
function cookie_get_session()
{
if( !empty($GLOBALS['HTTP_COOKIE_VARS'][$GLOBALS['COOKIE_NAME']]) )
return $this->restore_session($GLOBALS['HTTP_COOKIE_VARS'][$GLOBALS['COOKIE_NAME']]);
else if( !empty($GLOBALS["HTTP_GET_VARS"]["S"]) || !empty($GLOBALS["HTTP_POST_VARS"]["S"]) ) {
$this->sys_id = md5($GLOBALS["HTTP_SERVER_VARS"]["HTTP_USER_AGENT"].$GLOBALS["HTTP_SERVER_VARS"]["REMOTE_ADDR"].$GLOBALS["HTTP_SERVER_VARS"]["HTTP_X_FORWARDED_FOR"]);
return $this->restore_session((!empty($GLOBALS["HTTP_GET_VARS"]["S"])?$GLOBALS["HTTP_GET_VARS"]["S"]:$GLOBALS["HTTP_POST_VARS"]["S"]));
}
else
return;
}
function countvar()
{
return count($this->data);
}
function resetvar()
{
if ( is_array($this->data) ) reset($this->data);
}
function nextvar()
{
list($RET['key'], $RET['val']) = each($this->data);
return $RET;
}
}
function clear_cookie()
{
setcookie($GLOBALS['COOKIE_NAME'], 0, __request_timestamp__-100000, $GLOBALS['COOKIE_PATH'], $GLOBALS['COOKIE_DOMAIN']);
}
function set_referer_cookie($id)
{
setcookie('frm_referer_id', $id, __request_timestamp__+31536000, $GLOBALS['COOKIE_PATH'], $GLOBALS['COOKIE_DOMAIN']);
}
function clear_old_sessions()
{
q("DELETE FROM oamc_ses WHERE time_sec<".($tm_sample-$GLOBALS['COOKIE_TIMEOUT'])." OR (time_sec<".(__request_timestamp__-$GLOBALS['SESSION_TIMEOUT'])." AND sys_id!=0)");
}class fud_user
{
var $id=NULL;
var $login=NULL;
var $passwd=NULL;
var $plaintext_passwd=NULL;
var $name=NULL;
var $email=NULL;
var $location=NULL;
var $occupation=NULL;
var $interests=NULL;
var $display_email=NULL;
var $notify=NULL;
var $notify_method=NULL;
var $email_messages=NULL;
var $gender=NULL;
var $icq=NULL;
var $aim=NULL;
var $yahoo=NULL;
var $msnm=NULL;
var $jabber=NULL;
var $avatar=NULL;
var $avatar_loc=NULL;
var $avatar_approved=NULL;
var $append_sig=NULL;
var $show_sigs=NULL;
var $show_avatars=NULL;
var $posts_ppg=NULL;
var $time_zone=NULL;
var $invisible_mode=NULL;
var $ignore_admin=NULL;
var $bday=NULL;
var $blocked=NULL;
var $home_page=NULL;
var $sig=NULL;
var $bio=NULL;
var $posted_msg_count=NULL;
var $last_visit=NULL;
var $last_event=NULL;
var $email_conf=NULL;
var $conf_key=NULL;
var $coppa=NULL;
var $user_image=NULL;
var $join_date=NULL;
var $theme=NULL;
var $last_read=NULL;
var $default_view=NULL;
var $mod_list=NULL;
var $mod_cur=NULL;
var $is_mod=NULL;
var $level_id=NULL;
var $u_last_post_id=NULL;
function get_user_by_id($id)
{
qobj("SELECT * FROM oamc_users WHERE id=".$id, $this);
if( empty($this->id) ) return;
return $this->id;
}
function set_post_count($val, $mid='')
{
if( !db_locked() ) {
db_lock('oamc_users+, oamc_level+, oamc_msg+');
$local_lock=1;
}
if( empty($mid) ) $mid = q_singleval("SELECT MAX(id) FROM oamc_msg WHERE poster_id=".$this->id." AND approved='Y'");
$pcount = q_singleval("SELECT posted_msg_count FROM oamc_users WHERE id=".$this->id)+$val;
$level_id = q_singleval("SELECT id FROM oamc_level WHERE post_count<=".$pcount." ORDER BY post_count DESC LIMIT 1");
q("UPDATE oamc_users SET u_last_post_id=".intzero($mid).", posted_msg_count=posted_msg_count+".intzero($val).",level_id=".intzero($level_id)." WHERE id=".$this->id);
if( $local_lock ) db_unlock();
}
function register_thread_view($thread_id, $msg_id='')
{
$r = q("SELECT * FROM oamc_read WHERE thread_id=".$thread_id." AND user_id=".$this->id);
$obj = db_singleobj($r);
if ( $obj ) {
$msg_id = ( $msg_id > $obj->msg_id ) ? $msg_id : $obj->msg_id;
q("UPDATE oamc_read SET last_view=".__request_timestamp__.", msg_id=".intzero($msg_id)." WHERE id=".$obj->id);
}
else {
q("INSERT INTO oamc_read(thread_id, user_id, msg_id, last_view) VALUES(".$thread_id.", ".$this->id.", ".intzero($msg_id).", ".__request_timestamp__.")");
}
}
function register_forum_view($frm_id)
{
$id = q_singleval("SELECT id FROM oamc_forum_read WHERE forum_id=".$frm_id." AND user_id=".$this->id);
if ( $id )
q("UPDATE oamc_forum_read SET last_view=".__request_timestamp__." WHERE id=".$id);
else
q("INSERT INTO oamc_forum_read(forum_id, user_id, last_view) VALUES(".$frm_id.", ".$this->id.",".__request_timestamp__.")");
}
function mark_all_read()
{
q("UPDATE oamc_users SET last_read=".__request_timestamp__." WHERE id=".$this->id);
}
}
function user_copy_object($osrc, &$odst)
{
reset($osrc);
while ( list($k, $v) = each($osrc) ) {
$odst->{$k} = $v;
}
}
function init_user()
{
$s = new fud_session;
$u = new fud_user;
$s->cookie_get_session();
if ( $s->user_id && $s->user_id<2000000000 ) {
if ( !$u->get_user_by_id($s->user_id) ) {
$u=NULL;
$s->delete_session();
}
/* else NOP */
}
else $u = NULL;
if ( empty($u) && empty($s->id) ) $s->save_session();
$rv[0] = $s;
if( !empty($u) ) {
set_tz($u->time_zone);
define('d_thread_view', $u->default_view);
q("UPDATE oamc_users SET last_visit=".__request_timestamp__." WHERE id=".$u->id);
$rv[1] = $u;
}
else {
set_tz($GLOBALS["SERVER_TZ"]);
define('d_thread_view', $GLOBALS['DEFAULT_THREAD_VIEW']);
$rv[1] = NULL;
if( !empty($GLOBALS["rid"]) && empty($GLOBALS["HTTP_COOKIE_VARS"]["frm_referer_id"]) ) set_referer_cookie($GLOBALS["rid"]);
}
define('s', $s->ses_id);
define('_rsid', 'rid='.$u->id.'&S='.s);
define('_hs', '');
define('_uid', (($u->email_conf == 'Y')?$u->id:0));
return $rv;
}
if ( defined('admin_form') ) { fud_use('users_reg.inc'); fud_use('users_adm.inc'); }
if ( !defined('forum_debug') ) list($GLOBALS['ses'], $GLOBALS['usr']) = init_user();function set_tz($timezone)
{
@putenv("TZ=".$timezone);
}function cache_buster()
{
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
}
function trim_show_len($text,$type)
{
if( strlen($text)>$GLOBALS["MAX_".$type."_SHOW"] ) $text = substr($text,0,$GLOBALS["MAX_".$type."_SHOW"]).'...';
return $text;
}
function prepad($val, $to, $chr)
{
$ln_pad = $to - strlen($val);
for ( $i=0; $i<$ln_pad; $i++ ) $val = $chr.$val;
return $val;
}/*
* if severity is >0 the error handler will merely output the error the file
* however if the error severity is 0, the the function will terminate the script.
*/
function error_handler($function_name, $error_message, $severity)
{
if( !($fp = fopen($GLOBALS['ERROR_PATH'].'errors.inc', 'ab')) )
exit('
Unable to open error file
');
unset($error_msg);
$err = gmdate("Y-m-d-H-i-s", __request_timestamp__);
$err .= ' [s:'.$GLOBALS["HTTP_SERVER_VARS"]["SCRIPT_FILENAME"].'@'.$function_name.'] '.str_replace("\r", ' ', str_replace("\n", ' ', $GLOBALS["HTTP_SERVER_VARS"]["REMOTE_ADDR"].' "'.$GLOBALS["HTTP_SERVER_VARS"]["PATH_TRANSLATED"].'" "'.$GLOBALS["HTTP_SERVER_VARS"]["HTTP_USER_AGENT"].'" '.$error_message))."\n";
$error_msg = "\n--------------------------------------\n";
$error_msg .= "Error in function/script: ".$function_name."\n";
$error_msg .= "has caused the following error: ".$error_message."\n";
$error_msg .= "while processing script name: ".$GLOBALS["HTTP_SERVER_VARS"]["SCRIPT_FILENAME"]."\n";
$error_msg .= "the error occured at: ".gmdate("d/m/Y H:i:s T")."\n";
$error_msg .= "Browser: ".$GLOBALS["HTTP_SERVER_VARS"]["HTTP_USER_AGENT"]."\nUser Ip: ".$GLOBALS["HTTP_SERVER_VARS"]["REMOTE_ADDR"]."\nScript Accessed: ".$GLOBALS["HTTP_SERVER_VARS"]["PATH_TRANSLATED"]."\n\n";
echo nl2br($error_msg);
fwrite($fp, $err);
fclose($fp);
@chmod($GLOBALS['ERROR_PATH'].'errors.inc', 0600);
if( !$severity ) exit;
}
function error_dialog($title, $msg, $returnto, $level='', $ses=NULL)
{
if ( empty($ses) ) $ses = $GLOBALS['ses'];
$level = ( empty($level) ) ? 'WARN' : strtoupper($level);
$ref = !empty($GLOBALS["HTTP_SERVER_VARS"]["HTTP_REFERER"]) ? $GLOBALS["HTTP_SERVER_VARS"]["HTTP_REFERER"] : '';
if ( $level == 'FATAL' ) {
$err_str = gmdate("Y-m-d-H-i-s", __request_timestamp__);
$err_str .= " [d:$level]";
$err_str .= ' '.strip_tags(str_replace("\n", ' ', str_replace("\r", ' ', $title.':'.$msg.':'.$returnto.':'.$ref))).':'.$GLOBALS['HTTP_SERVER_VARS']['REMOTE_ADDR'].':'.$GLOBALS['HTTP_SERVER_VARS']['REQUEST_URI']."\n";
$fp = fopen($GLOBALS['ERROR_PATH'].'error_dialog.log', 'ab');
fwrite($fp, $err_str);
fflush($fp);
fclose($fp);
@chmod($GLOBALS['ERROR_PATH'].'error_dialog.log',0600);
}
$err_id = md5(get_random_value(128).__request_timestamp__);
$ses->putvar('err_id', $err_id);
$ses->putvar('er_msg', $msg);
$ses->putvar('err_t', $title);
$ses->putvar('ret_to', base64_encode($returnto));
$ses->save_session();
header('Location: https://www.factspot.com/oamc/forum/index.php?t=error&'._rsid.'&err_id='.$err_id);
exit;
}
function std_error($type)
{
$err_array = array(
'ERR_login'=>array('ERROR: You are not logged in ', 'You are not logged in, please do so
If you would like to register go to the registration form
If you would like to login please go to the login form', 'https://www.factspot.com/oamc/forum/index.php?t=login&'._rsid),
'ERR_disabled'=>array('Disabled feature', 'This feature has been disabled by the system administrator', $HTTP_SERVER_VARS['HTTP_REFERER'].'?'._rsid),
'ERR_access'=>array('ERROR: Insufficient Permissions', 'You do not have the required permissions to perform this action', $HTTP_SERVER_VARS['HTTP_REFERER'].'?'._rsid),
'ERR_registration_disabled'=>array('Registration Disabled', 'The administrator has disabled registration, please try again later', 'https://www.factspot.com/oamc/forum/index.php?t=index&'._rsid),
'ERR_emailconf'=>array('ERROR: Your account is not yet confirmed', 'You have not confirmed you account via email yet
|