// lib.php :: Common functions used throughout the program.
// Dragon Scourge
//
// Program authors: Jamin Blount
// Copyright (C) 2007 by renderse7en
// Script Version 1.0 Beta 5 Build 20
// You may not distribute this program in any manner, modified or
// otherwise, without the express, written consent from
// renderse7en.
//
// You may make modifications, but only for your own use and
// within the confines of the Dragon Scourge License Agreement
// (see our website for that).
//if (file_exists("install.php")) { die("Please remove the <b>install.php</b> and <b>install.sql</b> files from your game directory before continuing."); }
//if (file_exists("install.sql")) { die("Please remove the install.php file from your game directory before continuing."); }
// Setup for superglobal stuff that can't go in globals.php.
$starttime=getmicrotime();
$numqueries=0;
$link=opendb();
$version="Beta 5";
$bnumber="20";
$bname="Consolation Prize Part Deux";
$bdate="9.2.2007";
include("lib2.php");
// Handling for servers with magic_quotes turned on.
if($controlrow["debug"]==1){die(mysql_error()."<br /><br />".$query);}else{die("A MySQL query error occurred. Please contact the game administrator for more help.");}
}
$numqueries++;
return$sqlquery;
}
functiondorow($sqlquery,$force=""){// Abstraction layer part deux.
switch(mysql_num_rows($sqlquery)){
case0:
$row=false;
break;
case1:
if($force==""){
$row=mysql_fetch_assoc($sqlquery);
}else{
$temprow=mysql_fetch_assoc($sqlquery);
$row[$temprow[$force]]=$temprow;
}
break;
default:
if($force==""){
while($temprow=mysql_fetch_assoc($sqlquery)){
$row[]=$temprow;
}
}else{
while($temprow=mysql_fetch_assoc($sqlquery)){
$row[$temprow[$force]]=$temprow;
}
}
break;
}
return$row;
}
functiongettemplate($templatename){// SQL query for the template.
$filename="templates/".$templatename.".php";
include("$filename");
return$template;
}
functionparsetemplate($template,$array){// Replace template with proper content. Also does languages.
foreach($arrayas$a=>$b){
$template=str_replace("{{{$a}}}",$b,$template);
}
return$template;
}
functiongetmicrotime(){// Used for timing script operations.
list($usec,$sec)=explode("",microtime());
return((float)$usec+(float)$sec);
}
functionis_email($email){// Thanks to "mail(at)philipp-louis.de" from php.net!
functionmymail($to,$title,$body,$from=''){// thanks to arto dot PLEASE dot DO dot NOT dot SPAM at artoaaltonen dot fi.
global$controlrow;
extract($controlrow);
$from=trim($from);
if(!$from){
$from="<$adminemail>";
}
$rp=$adminemail;
$org="$gameurl";
$mailer="PHP";
$head="";
$head.="Content-Type: text/plain \r\n";
$head.="Date: ".date('r')."\r\n";
$head.="Return-Path: $rp\r\n";
$head.="From: $from\r\n";
$head.="Sender: $from\r\n";
$head.="Reply-To: $from\r\n";
$head.="Organization: $org\r\n";
$head.="X-Sender: $from\r\n";
$head.="X-Priority: 3 \r\n";
$head.="X-Mailer: $mailer\r\n";
$body=str_replace("\r\n","\n",$body);
$body=str_replace("\n","\r\n",$body);
returnmail($to,$title,$body,$head);
}
functionerr($error,$system=false,$panels=true){// Basic little error handler.
$errmsg="One or more errors have occurred:<br /><br /><b>$error</b><br /><br />Please <a href=\"javascript:history.go(-1);\">go back</a> and try again.";
display("Error",$errmsg,$panels);
}
functiondisplay($title,$content,$panels=true){// Finalize page and output to browser.