PDA

View Full Version : Fatal Error...


Tequila
11-08-2011, 08:01 PM
Probably my fault for playing with creating new pages. :madnoes:

Here's my problem:
Fatal error: Cannot redeclare runquery() in /home/enddayne/public_html/crystalhollow.com/inc/functions.php on line 107

Now I haven't made that many modifications to my functions file, but here it is in whole:
<?php



// File ID: functions.php

// Purpose: Provides basic sitewide functions



include("config.php");



$GLOBALS['dbhost'] = $dbhost; //DB Hostname

$GLOBALS['dbuser'] = $dbuser; //DB User

$GLOBALS['dbpass'] = $dbpass; //DB Password

$GLOBALS['dbname'] = $dbname; //Your database name

$GLOBALS['domain'] = $domain; //Your domain name (No http, www or . )

$GLOBALS['scriptpath'] = $scriptpath; //The folder you installed this script in

$GLOBALS['prefix'] = $prefix;



include("lang/lang.php");



//Connect to the database first

connect();

startup();

session_start();



// clean all our data

$_POST = array_map('secure',$_POST);

$_GET = array_map('secure',$_GET);



$session = session_id();

$time = time();

$time_check = $time - 300; // Time check, delete after 300 seconds (5 minutes)

$result = runquery("SELECT * FROM {$GLOBALS['prefix']}online WHERE `session` = '{$session}'");

$count = mysql_num_rows($result);

$result2 = runquery("SELECT * FROM {$GLOBALS['prefix']}online WHERE `username` = '{$loggedinname}'");

$count2 = mysql_num_rows($result2);

if($isloggedin != "yes")

{

$loggedinname = "Visitor";

}

if($count == 0 and $count2 == 0)

{

runquery("INSERT INTO {$GLOBALS['prefix']}online VALUES('$loggedinname', '$session', '$time')");

}

else

{

runquery("UPDATE ".$GLOBALS['prefix']."online SET time=".$time.", session ='".$session."', username='".$loggedinname."' WHERE session = '".$session."'");

}

// if over 5 minute, delete session

$sql4="DELETE FROM ".$GLOBALS['prefix']."online WHERE time < ".$time_check;

$result4=runquery($sql4);







// Begin functions definition:



function runquery($query) {

// next three lines may be commented out if debugging is unnessecary

// $arr = debug_backtrace();

// $GLOBALS['queries'] .= "<br /><strong>{$query}</strong> on line {$arr[0]["line"]} of {$arr[0]["file"]}.";

// $GLOBALS['numberofqueries']++;

$result = mysql_query($query);

return $result;

}


function changecash($amount, $user, $startamount) {
$newamount = $startamount + $amount;
if ($newamount >= 0) {
$GLOBALS['money'] = $newamount;
runquery("UPDATE {$GLOBALS['prefix']}users SET `money` = '{$newamount}' WHERE `username` = '{$user}'");
return true;
}
return false;
}


function clickreward($amount, $user, $startamount) {

$addamount = explode(",",$amount);

$randamount = rand($addamount[0], $addamount[1]);

return $randamount;

}



function connect() {

//This function simply connects us to the database

$conn = mysql_connect($GLOBALS['dbhost'], $GLOBALS['dbuser'], $GLOBALS['dbpass']) or die ('Error connecting to MySQL');

mysql_select_db($GLOBALS['dbname']);

}



function secure($data) {

//This function performs security checks on all incoming form data

if(is_array($data)) {

die("Hacking Attempt!");

}

$data = htmlentities($data);

$data = mysql_real_escape_string($data);

$data = strip_tags($data, '');

return $data;

}



function getsitecontent($page) {

$query = "SELECT * FROM ".$GLOBALS['prefix']."content WHERE page = '$page'";

$result = @runquery($query);

$num = @mysql_num_rows($result);

$title=@mysql_result($result,0,"title");

$content=@mysql_result($result,0,"content");

$title = stripslashes($title);

$content = stripslashes($content);

$value[content] = $content;

$value[title] = $title;

return $value;

}



function replace($old, $new, $template) {

//This function replaces template values

$template = str_replace($old, $new, $template);

return $template;

}

function uidtousername ($id) {



$query = "SELECT * FROM ".$GLOBALS['prefix']."users WHERE uid='$id'";

$result = mysql_query($query);

$username=@mysql_result($result,0,"username");

return $username;

}



function usernametouid ($name) {



$query = "SELECT * FROM ".$GLOBALS['prefix']."users WHERE username='$name'";

$result = mysql_query($query);

$uid=@mysql_result($result,0,"uid");



return $uid;

}

// NOTE - make sure this is only run once in a whole page load - not multiple times!

function logincheck() {

//Set up our login info...

$uid = "";

$password = "";



//Check for cookie

if (isset($_COOKIE['auid']) and isset($_COOKIE['apass'])) {

$uid = $_COOKIE['auid'];

$password = $_COOKIE['apass'];

$uid = secure($uid);

$password = secure($password);



//Run login operation

$query = "SELECT * FROM ".$GLOBALS['prefix']."users, ".$GLOBALS['prefix']."groups WHERE uid = '$uid' LIMIT 1";

$result = runquery($query);



$GLOBALS['usersettings'] = mysql_fetch_array($result);

$luid=@mysql_result($result, 0, $GLOBALS['prefix']."users.uid");

$lpass=@mysql_result($result, 0, $GLOBALS['prefix']."users.password");

$usergroup=@mysql_result($result, 0, $GLOBALS['prefix']."users.usergroup");



if($uid == $luid and $password == $lpass) {

$isloggedin = "yes";

}

else{

if (isset($_COOKIE['auser'])) {

$past = time() - 10;

setcookie("auid", $uid, $past);

}

if (isset($_COOKIE['apass'])) {

$past = time() - 10;

setcookie("apass", $password, $past);

}

$isloggedin = "no";

}

}

else {

$isloggedin = "no";

}

// return our user data

$username = uidtousername($uid);

$GLOBALS['isloggedin'] = $isloggedin;

$GLOBALS['username'] = $username;

$GLOBALS['loggedinname'] = $username; // MESSY - I'm unsure of which {username/loggedinname} is the correct one to use.

$GLOBALS['money'] = $GLOBALS['usersettings']['money'];

$GLOBALS['group'] = $usergroup;

}



function passencr($username, $password){

$pepper = '2/Fd4o42mMj*4P60s8N7';
$salt = grabanysetting("saltcode");

$password = md5($password);
$newpassword = sha1($username.$password);
$finalpassword = hash('sha512', $pepper.$newpassword.$salt);
return $finalpassword;
}

function updatepass($username, $password){

$pepper = '2/Fd4o42mMj*4P60s8N7';
$salt = grabanysetting("saltcode");

$newpassword = sha1($username.$password);
$finalpassword = hash('sha512', $pepper.$newpassword.$salt);

return $finalpassword;
}

function getcash($loggedinname){



//First we see if we are logged in or not



$isloggedin = $GLOBALS['isloggedin'];

$loggedinname = $GLOBALS['username'];



$query = "SELECT * FROM ".$GLOBALS['prefix']."users WHERE username = '$loggedinname'";

$result = runquery($query);

$num = mysql_num_rows($result);

$mycash=@mysql_result($result,0,"money");



return $mycash;



}





function grabanysetting($where) {

$value = stripslashes($GLOBALS['settings'][$where]);

return $value;

}



function getlinks() {

$links = "";



$query = "SELECT * FROM ".$GLOBALS['prefix']."links ORDER BY id ASC";

$result = runquery($query);

$num = mysql_num_rows($result);



//Loop out code

$i=0;

while ($i < $num) {

$linktext=@mysql_result($result, $i,"linktext");

$linkurl=@mysql_result($result, $i,"linkurl");

$linktext = stripslashes($linktext);

$links .= "<li><a href='".$linkurl."'>".$linktext."</a></li>";

$i++;

}

return $links;

}



function getsidebar() {

//This function determines what shows in the side bar of the template

$isloggedin = $GLOBALS['isloggedin'];

$loggedinname = $GLOBALS['loggedinname'];

if($isloggedin == "yes") {

$msgctr = "<a href='messages.php'>Archive</a>";

$query = "SELECT * FROM ".$GLOBALS['prefix']."messages WHERE touser='".$loggedinname."' and status='unread'";

$result = runquery($query);

$num = mysql_num_rows($result);

if($num > 0) {

$msgctr = "<a href='messages.php'>Scrolls <b>(".$num.")</b></a>";

}

$sidebar = "You have {$GLOBALS['money']}<img src='http://i42.tinypic.com/1zwp1mf.jpg'>.<br />

<a href='donate.php'>Donate money to friends</a><br />

<br /><strong>Your links:</strong><br />

<ul><li><a href='adopt.php'>Gather Eggs</a></li>

<li><a href='myadopts.php'>My Familiars</a></li>

<li><a href='account.php'>My Account</a></li>

<li>".$msgctr."

<li><a href='starterpack.php'>Get Starter Pack</a></li>
<li><a href='profile.php'>Make Friends</a></li>
<li><a href='logout.php'>Log Out</a></li>";



$query = "SELECT * FROM ".$GLOBALS['prefix']."users WHERE username='".$loggedinname."' and usergroup='1'";

$result = runquery($query);

$usercancp = mysql_num_rows($result);



if($usercancp != 0) {

$sidebar .= "<li><a href='admin.php'>Admin Center</a></li><br />";

}



$query1 = runquery("SELECT * FROM ".$GLOBALS['prefix']."online WHERE username != 'Visitor'");

$total1 = mysql_num_rows($query1);

$query2 = runquery("SELECT * FROM ".$GLOBALS['prefix']."online WHERE username = 'Visitor'");

$total2 = mysql_num_rows($query2);



$sidebar .= "</ul>";

}

else {

$sidebar = "<b><u>Member Login:</u></b><br />

<form name='form1' method='post' action='login.php'>

<p>Username:

<input name='username' type='text' id='username'>

</p>

<p>Password:

<input name='password' type='password' id='password'>

</p>

<p>

<input type='submit' name='Submit' value='Log In'>

</p>

</form>Don't have an account?<br /><a href='register.php'>Register Free</a><br /><a href='forgotpass.php'>Forgot Password?</a>";

$query1 = runquery("SELECT * FROM ".$GLOBALS['prefix']."online WHERE username != 'Visitor'");

$total1 = mysql_num_rows($query1);

$query2 = runquery("SELECT * FROM ".$GLOBALS['prefix']."online WHERE username = 'Visitor'");

$total2 = mysql_num_rows($query2);

$sidebar .= "<br />This site currently has ".$total1." members and ".$total2." guests.";



}

return $sidebar;

}



function dologin($username, $password) {

$query = "SELECT * FROM ".$GLOBALS['prefix']."users WHERE username = '$username'";

$result = @runquery($query);

$num = @mysql_num_rows($result);



$luser=@mysql_result($result, 0,"username");

$lpass=@mysql_result($result, 0,"password");

$uid = usernametouid ($username);


if($username == $luser and $password == $lpass) {

$status = "success";

//If the cookie already exists for some reason, delete it

if (isset($_COOKIE['auid']) and isset($_COOKIE['apass'])) {

$past = time() - 10;

setcookie("auid", $uid, $past);

setcookie("apass", $password, $past);

}

// Set the cookie

$Month = 2592000 + time();

setcookie("auid", $uid, $Month);

setcookie("apass", $password, $Month);

}



else{

$status = "error";

}



return $status;

}



function getgroup() {

$isloggedin = $GLOBALS['isloggedin'];

$loggedinname = $GLOBALS['username'];



if($isloggedin == "yes") {



$query = "SELECT * FROM ".$GLOBALS['prefix']."users WHERE username = '$loggedinname'";

$result = @mysql_query($query);

$num = @mysql_num_rows($result);

$group=@mysql_result($result,0,"usergroup");

return $group;

}

else {

return 0;

}

}



function cancp($usergroup) {

//This function determines if a usergroup is allowed to access the Admin CP



$query = "SELECT * FROM ".$GLOBALS['prefix']."groups WHERE gid = '$usergroup'";

$result = @mysql_query($query);

$num = @mysql_num_rows($result);

$cancp=@mysql_result($result,0,"cancp");





if($cancp == "" or $usergroup == 0) {

$cancp = "no";

}



return $cancp;

}



function getadmlinks() {

//This function shows special links to the site admin



$links = "<li><a href='index.php'>Home</a></li>

<li><a href='admin.php?set=adopts'>Change Adoptables</a></li>

<li><a href='admin.php?set=content'>Change Content</a></li>

<li><a href='admin.php?set=users'>Change Users</a></li>

<li><a href='admin.php?set=settings'>Site Settings</a></li>

<li><a href='admin.php?set=ads'>Manage Ads</a></li>";



return $links;

}



function cando($usergroup, $do) {

//This function determines if a usergroup is allowed to do a specific task

$cando = $GLOBALS['usersettings'][$do];



if($cando == "" or $usergroup == 0) {

$cando = "no";

}



return $cando;

}



// QUERYPROBLEM

function canadopt($aid, $cond, $promocode, $row) {

// This function determines if a user can adopt a specific adoptable...

$isloggedin = $GLOBALS['isloggedin'];

$loggedinname = $GLOBALS['username'];



if($isloggedin != "yes" and $cond != "showing") {

return "no";

}



// Now we check if our usergroup has permission to adopt the adoptable...

$group = getgroup();

$dbcanadpt = cando($group, "canadopt");



if($dbcanadpt != "yes" and $cond != "showing") {

return "no";

}



// Now we check if the adoptable requires a promo code and if the promo code submitted is correct...

if($row['whenisavail'] == "promo" and $promocode != $row['promocode']) {

return "no";

}



// Now we check those three conditions we have in the Admin CP

if($row['whenisavail'] == "conditions") {

// If we have a restriction on the number of times this can be adopted...

if($row['freqcond'] == "enabled") {

// Select from the database and determine how many times this adoptable type has been adopted

$num = 0;



$query = "SELECT * FROM ".$GLOBALS['prefix']."owned_adoptables WHERE type='$type'"; // QUERYPROBLEM

$result = runquery($query);

$num = mysql_num_rows($result);



if($num > $number) {

return "no";

}

}



// Begin the date restriction check

$today = date('Y-m-d');



if($row['datecond'] == "enabled" and $row['date'] != $today) {

return "no";

}



// We are checking to see how many of this adoptable a user owns

// If they own more than the specifed number, they cannot adopt...

if($row['moreless'] == "enabled") {

$num = 0;



$query = "SELECT * FROM ".$GLOBALS['prefix']."owned_adoptables WHERE owner='$loggedinname' and type='$type'";

$result = runquery($query);

$num = mysql_num_rows($result);



if($num > $row['morelessnum']) {

return "no";

}

}





// Check if the user is of a specified usergroup...

if($row['levelgrle'] == "enabled") {

$ourgid = getgroup();



// If the two numbers do not match, do not allow the adoption...

if($ourgid != $row['grlelevel']) {

return "no";

}

}

} // end conditions

return "yes";

}



// MESSY

function getaltstatus($parentid, $childid, $childlevel) {

// This function determines if we will use alternate images...

$altstatus = "no";

$run = "no";



// First we need to see if this adoptable type has alternate images enabled...

$query = "SELECT * FROM ".$GLOBALS['prefix']."adoptables WHERE id='$parentid'";

$result = runquery($query);

$num = mysql_num_rows($result);



$alternates=@mysql_result($result, 0,"alternates");

$altoutlevel=@mysql_result($result, 0,"altoutlevel");

$altchance=@mysql_result($result, 0,"altchance");



// Let's see if the level we are on is the level that requires alternates

if($alternates == "enabled") {

if($childlevel == $altoutlevel) {

$run = "yes";

}

}



if($run == "yes") {

$randnum = rand(1, $altchance);

if( $randnum == 1) {

$altstatus = "yes"; // If we pull a 1 as the random number, we use the alternate images :)

}

}

return $altstatus;

}



// MESSY / QUERYPROBLEM

function getcurrentimage($id) {

// This function determines which image we should use for a given adoptable...

$image = "";



// First we select the adoptable from the database and get some basic information...

$query = "SELECT * FROM ".$GLOBALS['prefix']."owned_adoptables WHERE aid='$id'";

$result = runquery($query);

$num = mysql_num_rows($result);



$type=@mysql_result($result, 0,"type");

$currentlevel=@mysql_result($result, 0,"currentlevel");

$imageurl=@mysql_result($result, 0,"imageurl");

$usealternates=@mysql_result($result, 0,"usealternates");



if($imageurl != "") {

// If we are using a custom image for this adoptable, use that

$image = $imageurl;

}

else {

// There is no custom image, so we must see if we are using an egg or a level image.

if($currentlevel == 0 or $currentlevel == "0") {

// Let's see what the egg image is...

$query = "SELECT * FROM ".$GLOBALS['prefix']."adoptables WHERE type='$type'";

$result = runquery($query);

$num = mysql_num_rows($result);



$eggimage=@mysql_result($result, 0, "eggimage");



$image = $eggimage; // Set the image URL equal to the egg image...

}

else {

// We don't know the level or the image - we must find both.



$query = "SELECT * FROM ".$GLOBALS['prefix']."levels WHERE adoptiename='$type' and thisislevel='$currentlevel'";

$result = runquery($query);

$num = mysql_num_rows($result);



$primaryimage=@mysql_result($result, 0,"primaryimage");

$alternateimage=@mysql_result($result, 0,"alternateimage");



// If alternate images are enabled and an alternate image exists, use it

if($usealternates == "yes" and $alternateimage != "") {

$image = $alternateimage; // Use the alternate image

}

else{

$image = $primaryimage; // Set the image equal to the primary image for the level

}

}



}



if($type == "" or $image == "") {

// We did not settle on an image, so we show an error image...

$image = "http://www.".$GLOBALS['domain']."".$GLOBALS['scriptpath']."/templates/icons/delete.gif";

}

return $image;

}



// QUERYPROBLEM - when is getcurrentlevel() actually used?

function getcurrentlevel($id) {

// This function gets the current level of an adoptable...



$query = "SELECT * FROM ".$GLOBALS['prefix']."owned_adoptables WHERE aid='$id'";

$result = runquery($query);

$num = mysql_num_rows($result);



$currentlevel=@mysql_result($result, 0,"currentlevel");



if($currentlevel == "") {

$currentlevel = "error"; // If the adoptable does not have a current level or does not exist, we return an error...

}



// Return the level

return $currentlevel;

}



function getnextlevelexists($type, $currentlevel) {

// This function determines if a higher level exists for an adopt, or if it is at max level.



$query = "SELECT * FROM ".$GLOBALS['prefix']."levels WHERE adoptiename='$type' and thisislevel > '$currentlevel'";

$result = runquery($query);

$num = mysql_num_rows($result);



if($num > 0) {

return "true";

}

return "false";

}



function convertidtotype($id) {

// This function takes in an adoptable's ID and returns the type of adoptable it is...



$query = "SELECT * FROM ".$GLOBALS['prefix']."owned_adoptables WHERE aid='$id'";

$result = runquery($query);

$num = mysql_num_rows($result);



$type=@mysql_result($result, 0,"type");



if($type == "") {

return "error";

}



return $type;

}



// MESSY - I have no idea what this function is supposed to do.

function converttypetoparentid($type) {

// This function takes in an adoptable type and returns the ID of the parent



$query = "SELECT * FROM ".$GLOBALS['prefix']."adoptables WHERE type='$type'";

$result = runquery($query);

$num = mysql_num_rows($result);



$id=@mysql_result($result, 0, "id");



if($id == "") {

$id = "error";

}



return $id;

}



// QUERYPROBLEM - this is being called (I believe) on every click page, and uses many too many queries.

function reward($id, $type, $currentlevel, $owner) {

// This function determines if we are giving the user a reward or not...

$query = "SELECT * FROM ".$GLOBALS['prefix']."levels WHERE adoptiename='$type' and thisislevel='$currentlevel'";

$result = runquery($query);

$num = mysql_num_rows($result);



$rewarduser=@mysql_result($result, 0,"rewarduser");

$promocode=@mysql_result($result, 0,"promocode");



if($rewarduser == "yes" and $promocode != "") {

// We are sending out a reward...



$mtitle = "You have received a reward!";

$mtext = "Congratulations! You have received a reward because one of your adoptables leveled up and the site admin has chosen to reward you for this.<br /><br />

<b><u>Your reward is the following promo code:</u></b> ".$promocode."<br /><br />

You may use this promo code on the <a href='promo.php?promocode=".$promocode."'>Promo Code Page</a> to receive a special exclusive or limited edition adoptable!<br /><br />

Congratulations on your reward!";



$mtext = mysql_real_escape_string($mtext);



$date = date('Y-m-d');

$query = "INSERT INTO ".$GLOBALS['prefix']."messages VALUES ('', 'SYSTEM', '$owner','unread','$date','$mtitle', '$mtext')";

runquery($query);



// Now we check if we are sending out an email to the user alerting them of the message...

$query = "SELECT * FROM ".$GLOBALS['prefix']."users WHERE username='".$owner."'";

$result = runquery($query);

$num = mysql_num_rows($result);



$newmessagenotify=@mysql_result($result, 0,"newmessagenotify");

$email=@mysql_result($result, 0,"email");



if($newmessagenotify == 1) {

// We are sending this user an email about the new message...

$systememail = grabanysetting("systememail"); // QUERYPROBLEM - we should get the settings at the beginning so we never need to call for them after that.



$headers = "From: ".$systememail."";



$site_name = grabanysetting("sitename"); // QUERYPROBLEM - see, two queries for this message alone.



$message = "Hello ".$owner.";\n\nYou have received a new Private Message from SYSTEM at ".$site_name." with the title ".$mtitle.".\n

You can read this message at: http://www.".$GLOBALS['domain']."".$GLOBALS['scriptpath']."/messages.php\n

Thank You. The ".$site_name." team.";



mail($email, $site_name." - You Have Received a Reward", $message, $headers);

}

}

return $rewardstatus; // MESSY - where is the variable $rewardstatus used before this?

}



// MESSY - what is this function for?

function getadmimages() {

$formcontent = "";



$query = "SELECT * FROM ".$GLOBALS['prefix']."filesmap";

$result = runquery($query);

$num = mysql_num_rows($result);



$i=0;

while ($i < $num) {

$wwwpath=@mysql_result($result, $i,"wwwpath");

$friendlyname=@mysql_result($result, $i,"friendlyname");

$formcontent = $formcontent."<option value='".$wwwpath."'>".$friendlyname."</option>";

$i++;

}

return $formcontent;

}



function deleteuser($user) {

//This function deletes a user from the system...



$user = secure($user);



$query = "DELETE FROM ".$GLOBALS['prefix']."users WHERE username = '".$user."'";

$result = runquery($query);



$query = "DELETE FROM ".$GLOBALS['prefix']."owned_adoptables WHERE owner = '".$user."'";

$result = runquery($query);

}



// MESSY - I believe this still runs if there are no ads. There should be an option to turn it off.

function getads($page) {

// Function to display site advertisements



if($page == "any") {

$page = "";

}



$query = "SELECT * FROM ".$GLOBALS['prefix']."ads WHERE page = '".$page."' and status = 'active' ORDER BY RAND() LIMIT 1";

$result = @runquery($query);

$num = @mysql_num_rows($result);



if($num > 0) {

$value=@mysql_result($result, 0,"text");

$value = stripslashes($value);

$aid=@mysql_result($result, 0,"id");

$actualimpressions=@mysql_result($result, 0,"actualimpressions");

$impressions=@mysql_result($result, 0,"impressions");



if($impressions == "") {

$impressions = 0;

}



$actualimpressions = $actualimpressions + 1;



//Update the impressions count

$query = "UPDATE ".$GLOBALS['prefix']."ads SET actualimpressions='".$actualimpressions."' WHERE id='".$aid."'";

runquery($query);



//Check that ad is not over max impressions...

if ($actualimpressions >= $impressions and $impressions != 0) {

$query = "UPDATE ".$GLOBALS['prefix']."ads SET status='inactive' WHERE id='".$aid."'";

runquery($query);

}

}

else{

$value = "";

}

return $value;

}



// NEW - mainly by Hall of Famer

function getabandonedimage($id) {

// This function determines which image we should use for a given adoptable (which has been abandoned).

$image = "";



// First we select the adoptable from the database and get some basic information...

$query = "SELECT * FROM ".$GLOBALS['prefix']."abandoned WHERE aid='$id'";

$result = runquery($query);

$num = mysql_num_rows($result);



$type=@mysql_result($result, 0,"type");

$currentlevel=@mysql_result($result, 0,"currentlevel");

$imageurl=@mysql_result($result, 0,"imageurl");

$usealternates=@mysql_result($result, 0,"usealternates");



if($imageurl != "") {

// If we are using a custom image for this adoptable, use that

$image = $imageurl;

}

else {

// There is no custom image, so we must see if we are using an egg or a level image.

if($currentlevel == 0 or $currentlevel == "0") {

// Let's see what the egg image is...

$query = "SELECT * FROM ".$GLOBALS['prefix']."adoptables WHERE type='$type'";

$result = runquery($query);

$num = mysql_num_rows($result);



$eggimage=@mysql_result($result, 0, "eggimage");



$image = $eggimage; // Set the image URL equal to the egg image...

}

else {

// We don't know the level or the image - we must find both.



$query = "SELECT * FROM ".$GLOBALS['prefix']."levels WHERE adoptiename='$type' and thisislevel='$currentlevel'";

$result = runquery($query);

$num = mysql_num_rows($result);



$primaryimage=@mysql_result($result, 0,"primaryimage");

$alternateimage=@mysql_result($result, 0,"alternateimage");



// If alternate images are enabled and an alternate image exists, use it

if($usealternates == "yes" and $alternateimage != "") {

$image = $alternateimage; // Use the alternate image

}

else{

$image = $primaryimage; // Set the image equal to the primary image for the level

}

}



}



if($type == "" or $image == "") {

// We did not settle on an image, so we show an error image...

$image = "http://www.".$GLOBALS['domain']."".$GLOBALS['scriptpath']."/templates/icons/delete.gif";

}

return $image;

}



// NEW - again, I think by Hall of Famer

function canadoptab($aid, $cond, $promocode){

$canadopt = "yes"; // The default status is that we CAN adopt, unless proven false...



$isloggedin = $GLOBALS['isloggedin'];

$loggedinname = $GLOBALS['username'];



if($isloggedin != "yes" and $cond != "showing"){

$canadopt = "no";

}



// Now we check if our usergroup has permission to adopt the adoptable...

$group = getgroup();

$dbcanadopt = cando($group, "canadopt");



if($dbcanadopt != "yes" and $cond != "showing"){

$canadopt = "no";

}



return $canadopt;

}





// NEW - a function to set everything up on start so we don't need to keep using queries to get stuff

function startup() {

// get all of our default settings, like title and stuff

$result = runquery("SELECT * FROM ".$GLOBALS['prefix']."settings");

while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {

$GLOBALS['settings'][$row['name']] = $row['value'];

}

// set up our log in stuff so we always have it

logincheck();

}



// NEW - a function to get a page from the database

function getpage($name) {

$query = "SELECT * FROM ".$GLOBALS['prefix']."content WHERE page='{$name}' LIMIT 1";

$result = runquery($query);

$row = mysql_fetch_array($result);

$GLOBALS['article_content'] = $row['content'];

$GLOBALS['article_title'] = $row['title'];

$GLOBALS['date'] = $row['date'];

return;

}



// NEW - a function to show the page

function showpage($title, $content, $date) {
$theme = $GLOBALS['usersettings']['theme'];
if ($theme == '') {
$theme = grabanysetting("theme");
}
$acpthemeurl = "templates/acp/template.html";
$themeurl = "templates/{$theme}/template.html";
$patterns = array("/:ARTICLETITLE:/","/:ARTICLECONTENT:/", "/:ARTICLEDATE:/", "/:BROWSERTITLE:/", "/:SITENAME:/", "/:SLOGAN:/", "/:LINKSBAR:/", "/:SIDEFEED:/", "/:ADS:/");
// if we have said we are in an admin area, don't show ads and show admin links
if ($GLOBALS['admin']==true) {
$replacements = array($title, $content, $date, grabanysetting("browsertitle")." ".$title, grabanysetting("sitename"), grabanysetting("slogan"), getadmlinks(), getsidebar(), "");
$template = file_get_contents($acpthemeurl);
}
else {
$replacements = array($title, $content, $date, grabanysetting("browsertitle")." ".$title, grabanysetting("sitename"), grabanysetting("slogan"), getlinks(), getsidebar(), getads("any"));
$template = file_get_contents($themeurl);
}
// now that we have our stuff, let's start making it all into a webpage

$template = preg_replace($patterns, $replacements, $template);
$template .= "<div style='position: fixed; bottom: 0; left: 0; color: white; font-size: 10px; width: 380px; '>A total of {$GLOBALS['numberofqueries']} queries were used in this page. They were: {$GLOBALS['queries']}</div>";
return $template;
}



function getpostbar ($name) {

$query = "SELECT * FROM ".$GLOBALS['prefix']."users WHERE username='$name'";

$result = runquery($query);

$num = mysql_num_rows($result);



$membersince=@mysql_result($result, 0,"membersince");

$dollar=@mysql_result($result, 0,"money");

$avatar=@mysql_result($result, 0,"avatar");

$bio=@mysql_result($result, 0,"profile");

$gender=@mysql_result($result, 0,"gender");

$nickname=@mysql_result($result, 0,"nickname");



$postbar = "

<table>

<span class='smalltext'>

<tr>

<td>

<img src='{$avatar}'>

</td>

<td>

<b>Member Since: </b><br>{$membersince}<br>

<b>Bio:</b><br>{$bio}<br>

</td>

<td>

<b>Nickname:</b> {$nickname}<br>

<b>Gender:</b> {$gender}<br>

<b>Cash:</b> <a href='forum.php?do=donate&from={$uid}&am={$dollar}'>{$dollar}</a><br>

</td>

</span>

</table>

";



return $postbar;







}



function getonlinestatus($name) {



$query = "SELECT * FROM ".$GLOBALS['prefix']."online WHERE username='$name'";

$result = mysql_query($query);

$num = mysql_num_rows($result);





if($num == 0){

$onlinestatus = "<img src='templates/icons/user_offline.gif'>";

}

else{

$onlinestatus = "<img src='templates/icons/user_online.gif'>";

}



return $onlinestatus;

}



function getfriendgender($name) {



$query = "SELECT * FROM ".$GLOBALS['prefix']."users WHERE username='$name'";

$result = mysql_query($query);

$gender=@mysql_result($result,0,"gender");





if($gender == "Male"){

$friendgender = "<img src='picuploads/m.png'>";

}

else if($gender == "Female"){

$friendgender = "<img src='picuploads/f.png'>";

}

else{

$friendgender = "";

}



return $friendgender;

}



function getfriendid ($name) {



$query = "SELECT * FROM ".$GLOBALS['prefix']."users WHERE username='$name'";

$result = mysql_query($query);

$friendid=@mysql_result($result,0,"friends"); //friendlist



$friendidlist = explode(",",$friendid);

return $friendidlist;



}



function getfriendnum ($name) {



$friendidlist = getfriendid ($name);



$query = "SELECT * FROM ".$GLOBALS['prefix']."users WHERE username='$name'";

$result = mysql_query($query);

$friendid=@mysql_result($result,0,"friends"); //friendlist



if($friendid == ""){

$friendnum = "0";

}

else{

$friendnum = count($friendidlist);

}



return $friendnum;



}



function deletefriend($id){

$friendidlist = getfriendid ($loggedinname);

foreach($friendidlist as $friend){

if($friend != $id){

$newfriendidlist[] = $friend;

}

}



$newfriendid = implode(",", $newfriendidlist);

return $newfriendid;



}



?>

And here's my new page:
<?php

include("inc/functions.php");
include("inc/bbcode.php");

//***************//
// START SCRIPT //
//***************//

// Card Page MOD by tequila

if (isset($_GET['id'])) {
if (strpos($_GET['id'], "/")) {
$dir = substr(str_replace('..', '', $_GET['id']), 0, strpos($_GET['id'], "/")) . "/";

$file = substr(strrchr($_GET['id'], "/"), 1);
if (file_exists($dir.$file.".html")) {
include($dir.$file.".html");
} else {
include("nope.php");

}
} else {
if (file_exists(basename($_GET['id']).".html")) {
include(basename($_GET['id']).".html");
} else {
include("nope.php");

}
}
} else {
include("nope.php");
}

//***************//
// OUTPUT PAGE //
//***************//

echo showpage($article_title, $article_content, $date);

?>



Any ideas? Or should I look into a different way to force decks to display all cards at once (without coding them one by one)?

Tequila
11-08-2011, 08:28 PM
Also, an idea of how I currently feel about this error:
http://mthruf.files.wordpress.com/2011/11/job-fails-tech-support-in-its-natural-posture.jpg (http://work.failblog.org/2011/11/07/job-fails-tech-support-in-its-natural-posture/)
Look, I'm just like the Tech Support Guiz! :colonu:

Hall of Famer
11-09-2011, 01:24 AM
Well this often occurs when you accidentally declares a function repeatedly in one script file, if you include script files incorrectly. Chances are you declared the function runquery() inside the $dir.$file.".html" or basename($_GET['id']).".html" files but did not happen to realize it. I dont see the two html files so I cant tell why it happened atm.

Tequila
11-09-2011, 02:14 PM
I figured it out! I called these two lines in both the deckview.php and nope.php files:
include("inc/functions.php");
include("inc/bbcode.php");

Lesson learned, watch what you copy and paste. Now I have to get it to call the right names and card images when loaded...

SilverDragonTears
11-09-2011, 02:34 PM
Also, an idea of how I currently feel about this error:
http://mthruf.files.wordpress.com/2011/11/job-fails-tech-support-in-its-natural-posture.jpg (http://work.failblog.org/2011/11/07/job-fails-tech-support-in-its-natural-posture/)
Look, I'm just like the Tech Support Guiz! :colonu:

Hahahahahahaha!

Tequila
11-09-2011, 03:11 PM
So I got my problem fixed. Now it won't pull the deck name to show the page... ugh...
See... (http://crystalhollow.com/viewdeck.php?id=arcanetools)

<?php


//***************//
// START SCRIPT //
//***************//

// Card Page MOD by tequila

$deck = $_GET["deckname"];

$query = "SELECT * FROM {$prefix}cards WHERE deckname = '{$deck}'";
$result = runquery($query);
$row = mysql_fetch_array($result);

if($row['deckname'] == $deck)
{
$article_title = "{$row['deckname']}";
$article_content = "<p>{$row['deckdescription']}</p>
<center>
<img src='cards/{$row['deckname']}01.png' /><img src='cards/{$row['deckname']}02.png' /><img src='cards/{$row['deckname']}03.png' /><img src='cards/{$row['deckname']}04.png' /><img src='cards/{$row['deckname']}05.png' /><br />
<img src='cards/{$row['deckname']}06.png' /><img src='cards/{$row['deckname']}07.png' /><img src='cards/{$row['deckname']}08.png' /><img src='cards/{$row['deckname']}09.png' /><img src='cards/{$row['deckname']}10.png' />
<br /><img src='cards/{$row['deckname']}11.png' /><img src='cards/{$row['deckname']}12.png' /><img src='cards/{$row['deckname']}13.png' /><img src='cards/{$row['deckname']}14.png' /><img src='cards/{$row['deckname']}15.png' />
</center>";

$article_content .= "</table><img src='cards/{$row['deckname']}-master.png' style='float:left;'/><p>The following users have astered this deck.</p><p>{$row['deckmasters']}</p>";
}
else {
$article_content .= "<p>Sorry, you did not specify a deck. Please <a href='cards.php'>go back</a> and pick again.</p>";
}
//***************//
// OUTPUT PAGE //
//***************//

echo showpage($article_title, $article_content, $date);

?>

^ Is the code used for the page. I may try to remake it after viewing the codes behind the profile page better.

Hall of Famer
11-09-2011, 03:30 PM
Well yeah, such problems do occur if you are including files that also include other files. Both of them include functions.php, which causes the problem. One possible way to fix this is to use include_once() instead of include(), this will not generate any error message but will cause the program to run slower. What a trade-off!

Tequila
11-09-2011, 03:37 PM
I may just code the card page similar to the profile page. It'll work.

Now I just have to finish integrating the login portion to the rest of the site.

Edit
So I changed the way I want this to work, and have made my own version of profile.php to display cards.
It doesn't quite work...
http://crystalhollow.com/cards.php?deck=goodluckcharms

Any ideas where to fix this?
<?php

include("inc/functions.php");
include("inc/bbcode.php");

//***************//
// START SCRIPT //
//***************//

// Card Page Modification

$deck = $_GET["deckname"];
$page = $_GET["page"];

if($deck != "")
{

// We have specified a deck to view.
// See if the user exists...

$query = "SELECT * FROM {$prefix}cards WHERE deckname = '{$deck}'";
$result = runquery($query);
$row = mysql_fetch_array($result);

if($row['deckname'] == $deck)
{

$article_title = "{$row['deckname']}";
$article_content = "<p>{$row['deckdescription']}</p>
<center>
<img src='cards/{$row['deckname']}01.png' /><img src='cards/{$row['deckname']}02.png' /><img src='cards/{$row['deckname']}03.png' /><img src='cards/{$row['deckname']}04.png' /><img src='cards/{$row['deckname']}05.png' /><br />
<img src='cards/{$row['deckname']}06.png' /><img src='cards/{$row['deckname']}07.png' /><img src='cards/{$row['deckname']}08.png' /><img src='cards/{$row['deckname']}09.png' /><img src='cards/{$row['deckname']}10.png' />
<br /><img src='cards/{$row['deckname']}11.png' /><img src='cards/{$row['deckname']}12.png' /><img src='cards/{$row['deckname']}13.png' /><img src='cards/{$row['deckname']}14.png' /><img src='cards/{$row['deckname']}15.png' />
</center>";

$article_content .= "</table><img src='cards/{$row['deckname']}-master.png' style='float:left;'/><p>The following users have mastered this deck.</p><p>{$row['deckmasters']}</p>";
}
else
{

// Not a deck

$article_title = "Error!";
$article_content = "Sorry but there is not a deck available under that name. Please try again.";

}

}
else
{

// We did not specify a deck, so show the card list

$article_title = "Decks to Collect";
$article_content = "<table cellpadding='0' cellspacing='0' width='100%'>
<tr><th class='head'>deck name</th><th class='head'>description</th><th class='head'>class</th></tr>";

$query = "SELECT COUNT(*) as cards FROM {$prefix}cards ORDER BY deckname ASC";
$result = runquery($query);
$total = mysql_fetch_array($result);

$rowsperpage = 50;
$totalpages = ceil($total['cards'] / $rowsperpage);

if(is_numeric($page))
{
$currentpage = $page;
}
else
{
$currentpage = 1;
}
if($currentpage > $totalpages)
{
$currentpage = $totalpages;
}
if($currentpage < 1)
{
$currentpage = 1;
}
$offset = ($currentpage - 1) * $rowsperpage;

$query = "SELECT * FROM {$prefix}cards ORDER BY deckname ASC LIMIT {$offset}, {$rowsperpage}";
$result = runquery($query);

while ($row = mysql_fetch_array($result))


$article_content .= "<tr><td class='row'><a href='cards.php?deck={$row['deckname']}'>{$row['deckname']}</a></td><td class='row'>{$row['deckdescription']}</td><td class='row'>{$row['deckclass']}</td></tr>
";




$article_content .= "</table><br />";
if($currentpage > 1)
{
$newpage = $currentpage - 1;
$article_content .= "<strong><a href='profile.php?page={$newpage}'><img src='templates/icons/prev.gif' border=0> Previous Page</a></strong> ";
}
else
{
$article_content .= "<strong><img src='templates/icons/prev.gif' border=0> Previous Page</strong> ";
}
if($currentpage < $totalpages)
{
$newpage = $currentpage + 1;
$article_content .= " :: <strong><a href='profile.php?page={$newpage}'>Next Page <img src='templates/icons/next.gif' border=0></a></strong> ";
}
else
{
$article_content .= " :: <strong>Next Page <img src='templates/icons/next.gif' border=0></strong>";
}

}

//***************//
// OUTPUT PAGE //
//***************//

echo showpage($article_title, $article_content, $date);

?>

Tequila
11-11-2011, 08:12 PM
Taking a break from the Card Display page. Now I can't get my lotto game to play. 3;

Here's my error:
Parse error: syntax error, unexpected '=', expecting '}' in /home/enddayne/public_html/crystalhollow.com/games_lotto.php on line 59

And my code:
<?php

include('inc/functions.php');
include('inc/bbcode.php');
include('games/rewards.php');

//***************//
// START SCRIPT //
//***************//


// Games Page
// Freebies

$article_title = "Whysper's Guild of Magic<span>Numerology Report</span>";
$article_content = "

<!--script-->
<script>
function process(){
var checkednums=0;
var x=0;
for(i=0; i<15; i++) {
if(document.lottery_ticket.number[i].checked==true){
x=x+1;
if(document.lottery_ticket.number[i].value=='1'){
checkednums=checkednums+1;
} //end if right and less than limit
} // end search checked
} // end for
if(x!=4){alert('You have chosen " + x + " numbers. Please select 4.');}
else{
if(checkednums==0){alert('Sorry, you didn't get any of the numbers.');}
if(checkednums==1){alert('You got 1 number correct, take any two cards you'd like.');}
if(checkednums==2){alert('You got 2 numbers correct, take any three cards you'd like.');}
if(checkednums==3){alert('You got 3 numbers correct, take any four cards you'd like.');}
if(checkednums==4){alert('You got 4 numbers correct, take all five cards and the choice coupon!');}
} // end else
} // end function
</script>


<!--lotto update code-->

<?php
$min='1';
$max='15';
$numbers = range($min, $max);
shuffle($numbers);

$random_1 = $numbers[0]; // first random number
$random_2 = $numbers[1]; // next random, non repeating
$random_3 = $numbers[2]; // next random, non repeating
$random_4 = $numbers[3]; // next random, non repeating


if ($random_1=='1' || $random_2=='1' || $random_3=='1' || $random_4=='1'){
$v1='1'; }
else {$v1='0'; }

if($random_1=='2' || $random_2=='2' || $random_3=='2' || $random_4=='2'){
$v2='1';}
else {$v2='0'; }

if($random_1=='3' || $random_2=='3' || $random_3=='3' || $random_4=='3'){
$v3='1';}
else {$v3='0'; }

if($random_1=='4' || $random_2=='4' || $random_3=='4' || $random_4=='4'){
$v4='1';}
else {$v4='0'; }

if($random_1=='5' || $random_2=='5' || $random_3=='5' || $random_4=='5'){
$v5='1';}
else {$v5='0'; }

if($random_1=='6' || $random_2=='6' || $random_3=='6' || $random_4=='6'){
$v6='1';}
else {$v6='0'; }

if($random_1=='7' || $random_2=='7' || $random_3=='7' || $random_4=='7'){
$v7='1';}
else {$v7='0'; }

if($random_1=='8' || $random_2=='8' || $random_3=='8' || $random_4=='8'){
$v8='1';}
else {$v8='0'; }

if($random_1=='9' || $random_2=='9' || $random_3=='9' || $random_4=='9'){
$v9='1';}
else {$v9='0'; }

if ($random_1=='10' || $random_2=='10' || $random_3=='10' || $random_4=='10'){
$v10='1'; }
else {$v10='0'; }

if ($random_1=='11' || $random_2=='11' || $random_3=='11' || $random_4=='11'){
$v11='1'; }
else {$v11='0'; }

if ($random_1=='12' || $random_2=='12' || $random_3=='12' || $random_4=='12'){
$v12='1'; }
else {$v12='0'; }

if ($random_1=='13' || $random_2=='13' || $random_3=='13' || $random_4=='13'){
$v13='1'; }
else {$v13='0'; }

if ($random_1=='14' || $random_2=='14' || $random_3=='14' || $random_4=='14'){
$v14='1'; }
else {$v14='0'; }

if ($random_1=='15' || $random_2=='15' || $random_3=='15' || $random_4=='15'){
$v15='1'; }
else {$v15='0'; }
?>


<!--lotto table with values-->
<form name="lottery_ticket" action="javascript:process()">
<table>

<tr>
<td><input type="checkbox" name="number" value="<?php echo "$v1"; ?>">1</td>
<td><input type="checkbox" name="number" value="<?php echo "$v2"; ?>">2</td>
<td><input type="checkbox" name="number" value="<?php echo "$v3"; ?>">3</td>
<td><input type="checkbox" name="number" value="<?php echo "$v4"; ?>">4</td>
<td><input type="checkbox" name="number" value="<?php echo "$v5"; ?>">5</td>
</tr>

<tr>
<td><input type="checkbox" name="number" value="<?php echo "$v6"; ?>">6</td>
<td><input type="checkbox" name="number" value="<?php echo "$v7"; ?>">7</td>
<td><input type="checkbox" name="number" value="<?php echo "$v8"; ?>">8</td>
<td><input type="checkbox" name="number" value="<?php echo "$v9"; ?>">9</td>
<td><input type="checkbox" name="number" value="<?php echo "$v10"; ?>">10</td>
</tr>

<tr>
<td><input type="checkbox" name="number" value="<?php echo "$v11"; ?>">11</td>
<td><input type="checkbox" name="number" value="<?php echo "$v12"; ?>">12</td>
<td><input type="checkbox" name="number" value="<?php echo "$v13"; ?>">13</td>
<td><input type="checkbox" name="number" value="<?php echo "$v14"; ?>">14</td>
<td><input type="checkbox" name="number" value="<?php echo "$v15"; ?>">15</td>
</tr>


<tr>
<td colspan=5 align=center>
<input type="submit" value="Check My Calculations!">
</td>
</tr>
<tr><td>
<p>Please save cards to your trade post according to how many you got correct!</p>
<center><img src=" . $regular[array_rand($regular,1)] . $digits[array_rand($digits,1)] . "><img src=" . $regular[array_rand($regular,1)] . $digits[array_rand($digits,1)] . "><img src=" . $regular[array_rand($regular,1)] . $digits[array_rand($digits,1)] . "><img src=" . $regular[array_rand($regular,1)] . $digits[array_rand($digits,1)] . "><img src=" . $regular[array_rand($regular,1)] . $digits[array_rand($digits,1)] . "><img src='media/coupon.png'>
</table>
</p>

</form>

";

//***************//
// OUTPUT PAGE //
//***************//

echo showpage($article_title, $article_content, $date);

?>
(Also attached)

What is going wrong with this? I may just scrap it if I can't get help (this and card pages).

SilverDragonTears
11-11-2011, 08:22 PM
Can you show me line 59? My eyes are too bad to count to find it ;)

Tequila
11-12-2011, 07:24 AM
Can you show me line 59? My eyes are too bad to count to find it ;)

Sure:
else {$v1='0'; }

There is a bunch of code like that in the script. Here (http://clavis-sama.com/toolkit.php?lottery) is where I got the script if you want to see what it's supposed to do.

Hall of Famer
11-12-2011, 03:01 PM
For some reason the script wont run while I was betatesting it(not even giving errors, just all blank). I'd rewrite your codes in this way:


if ($random_1=='1' || $random_2=='1' || $random_3=='1' || $random_4=='1') $v1='1';
else $v1='0';
The brackets in if statement can be tricky. I am assuming you are using a shortcut since you only have one line of codes following if and else, but the best way to handle this is to get rid of the bracket. Once you have brackets in your if statement, you will have to write separate lines like this:



if ($random_1=='1' || $random_2=='1' || $random_3=='1' || $random_4=='1'){
$v1='1';
}
else {
$v1='0';
}
Hopefully this solves your problem. I cannot test your script on my site there is no guarantee that I make no mistakes. Also it seems that you are trying to utilize a part of PHP and javascript codes?

Tequila
11-12-2011, 09:29 PM
For some reason the script wont run while I was betatesting it(not even giving errors, just all blank). I'd rewrite your codes in this way:


if ($random_1=='1' || $random_2=='1' || $random_3=='1' || $random_4=='1') $v1='1';
else $v1='0';
The brackets in if statement can be tricky. I am assuming you are using a shortcut since you only have one line of codes following if and else, but the best way to handle this is to get rid of the bracket. Once you have brackets in your if statement, you will have to write separate lines like this:



if ($random_1=='1' || $random_2=='1' || $random_3=='1' || $random_4=='1'){
$v1='1';
}
else {
$v1='0';
}
Hopefully this solves your problem. I cannot test your script on my site there is no guarantee that I make no mistakes. Also it seems that you are trying to utilize a part of PHP and javascript codes?

I'll try that tomorrow afternoon (once I'm out of work). I hate closing and opening the next morning. :/

In other news, I should be able to give my won't be here notice for Turkey Day (volunteered for 8 hours) and That Evil Shopping Day (volunteered for 12 hours) after shortly.

Hall of Famer
11-13-2011, 04:30 PM
Alright, good luck then Nyxi. Again I hope this will work out for you, give a try on your site and lemme know if you encounter any other problems.

Tequila
11-13-2011, 06:09 PM
Will do. :3

Tequila
11-15-2011, 01:16 PM
I think I'll skip this lotto script, and go back to my Tic Tac Toe game instead. I'll have to come up with a new way to run a lottery.