Location: PHPKode > projects > Blackbeard's Revenge > common.php
<?
require_once "dbwrapper.php";

define('DBTYPE',"mysql");

$link = db_pconnect($DB_HOST, $DB_USER, $DB_PASS) or die (db_error($link));
db_select_db ($DB_NAME) or die (db_error($link));
define("LINK",$link);


function logevent($news){
	global $session;
	$sql = "INSERT INTO news(newstext,newsdate,accountid) VALUES ('".addslashes($news)."',NOW(),".$session[user][acctid].")";
	return db_query($sql) or die(db_error($link));
}

function loadsettings(){
	global $settings;
	//from LOGD Version: 0.9.7+jt
	//as this seems to be a common complaint, examine the execution path of this function,
	//it will only load the settings once per page hit, in subsequent calls to this function,
	//$settings will be an array, thus this function will do nothing.
	if (!is_array($settings)){
		$settings=array();
		$sql = "SELECT * FROM settings";
		$result = db_query($sql) or die(db_error(LINK));
		for ($i=0;$i<db_num_rows($result);$i++){
			$row = db_fetch_assoc($result);
			$settings[$row[setting]] = $row[value];
		}
		db_free_result($result);
		$ch=0;
		if ($ch=1 && strpos($_SERVER['SCRIPT_NAME'],"login.php")){
			//@file("http://www.mightye.org/logdserver?".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']);
		}
	}
}

function savesetting($settingname,$value){
	//from LOGD Version: 0.9.7+jt
	global $settings;
	loadsettings();
	if ($value>""){
		if (!isset($settings[$settingname])){
			$sql = "INSERT INTO settings (setting,value) VALUES (\"".addslashes($settingname)."\",\"".addslashes($value)."\")";
		}else{
			$sql = "UPDATE settings SET value=\"".addslashes($value)."\" WHERE setting=\"".addslashes($settingname)."\"";
		}
		db_query($sql) or die(db_error(LINK));
		$settings[$settingname]=$value;
		if (db_affected_rows()>0) return true; else return false;
	}
	return false;
}

function getsetting($settingname,$default){
	//from LOGD Version: 0.9.7+jt
	global $settings;
	loadsettings();
	if (!isset($settings[$settingname])){
		savesetting($settingname,$default);
		return $default;
	}else{
		if (trim($settings[$settingname])=="") $settings[$settingname]=$default;
		return $settings[$settingname];
	}
}

function saveuser(){
	global $session,$dbqueriesthishit;
//	$cmd = date("Y-m-d H:i:s")." $dbqueriesthishit ".$_SERVER['REQUEST_URI'];
//	@exec("echo $cmd >> /home/groups/l/lo/lotgd/sessiondata/data/queryusage-".$session['user']['login'].".txt");
	if ($session[loggedin] && $session[user][acctid]!=""){
  	$session[user][output]=$session[output];
  	$session[user][allowednavs]=serialize($session[allowednavs]);
		$session[user][bufflist]=serialize($session[bufflist]);
		if (is_array($session[user][prefs])) $session[user][prefs]=serialize($session[user][prefs]);
		if (is_array($session[user][dragonpoints])) $session[user][dragonpoints]=serialize($session[user][dragonpoints]);
		//$session[user][laston] = date("Y-m-d H:i:s");
  	$sql="UPDATE accounts SET ";
  	reset($session[user]);
  	while(list($key,$val)=each($session[user])){
  		if (is_array($val)){
				$sql.="$key='".addslashes(serialize($val))."', ";
			}else{
				$sql.="$key='".addslashes($val)."', ";
			}
  	}
  	$sql = substr($sql,0,strlen($sql)-2);
  	$sql.=" WHERE acctid = ".$session[user][acctid];
  	db_query($sql);
  }
}

?>
Return current item: Blackbeard's Revenge