Location: PHPKode > projects > VampMan: V:tR Character Manager > vampman-1.0.2/phpnuke/modules/charactersheet/admin/charactersheet/xprequest.php
<?php
if (!eregi("admin.php", $PHP_SELF)){
  die (_accessdirectly);
}

if($mode2 == "submit" && isset($charid) && ctype_digit($charid) && isset($xpid) && ctype_digit($xpid))
{
	$stcomments = addslashes(stripslashes($stcomments));
	
	$queryxp = "select xp from ".$prefix."_character_characters where charid='$charid'";
	$xpresult = sql_query($queryxp,$dbi);
	if((list($formerxp) = sql_fetch_array($xpresult)) === false)
			die(_nocharacter);
	
	
	
	$query = "UPDATE ".$prefix."_character_characters, ".$prefix."_character_xp 
	SET ".$prefix."_character_xp.stxp = '$stxp', ".$prefix."_character_xp.stcomments = '$stcomments',
	".$prefix."_character_xp.status = 'resolved',
	".$prefix."_character_characters.xp = '".($stxp + $formerxp)."'
	where ".$prefix."_character_characters.charid = '$charid'  and ".$prefix."_character_xp.id = '$xpid'
	and ".$prefix."_character_xp.status = 'pending'";
	sql_query($query, $dbi);

	$query = "select vxp,potency,maxvitae from ".$prefix."_character_characters where charid = '$charid'";
        $result = sql_query($query,$dbi);
        $line = sql_fetch_array($result);
        $vxp = $line['vxp'];
        $potency = $line['potency'];
	$maxvitae = $line['maxvitae'];
        if($vxp != -1 )
        {
                $xpdiff = $vxp - $stxp;
		if($xpdiff > 0)
		{
			$vxp = $xpdiff;
		}
		else
		{
			$potency++;
			switch($potency)
			{	
				case 0:
				        $maxvitae = 0;
				        break;
				case 1:
				        $maxvitae = 10;
				        break;
				case 2:
				        $maxvitae = 11;
				        break;
				case 3:
				        $maxvitae = 12;
				        break;
				case 4:
				        $maxvitae = 13;
				        break;
				case 5:
				        $maxvitae = 14;
				        break;
				case 6:
				        $maxvitae = 15;
				        break;
				case 7:
				        $maxvitae = 20;
				        break;
				case 8:
				        $maxvitae = 30;
				        break;
				case 9:
				        $maxvitae = 50;
				        break;
				case 10:
				        $maxvitae = 100;
				        break;
			}


			$vxpquery = "select xp from ".$prefix."_character_bp where bp = '$potency'";
			$result = sql_query($vxpquery,$dbi);

			if(!sql_num_rows($result))
			{
			        $vxp = -1;
				break;
			}
			else
			{
		        	list($vxp) = sql_fetch_array($result);
				$vxp += $xpdiff;
			}
		}
		$query = "UPDATE ".$prefix."_character_characters SET potency = '$potency', vxp = '$vxp', maxvitae = '$maxvitae' where charid = '$charid'";
		sql_query($query, $dbi);

        }	

}

if(isset($mode2) && $mode2 != "all")
{
	echo "<a href=\"admin.php?op=character_xprequest\">"._PendingXPRequests."</a> | ";
	echo "<a href=\"admin.php?op=character_xprequest&mode2=all\">"._AllXPRequest."</a><br><br>";
}



if($mode2 == "view" && isset($charid) && ctype_digit($charid) && isset($xpid) && ctype_digit($xpid))
{

	$query = "select id,charid,xpdate,xp,details,status,stxp,stcomments from ".$prefix."_character_xp where charid = '$charid' and id='$xpid'";
	$result = sql_query($query, $dbi) or die(_notresource);

	if(!sql_num_rows($result))
	{
		echo _xprequestnotfound;
	}
	else
	{

		$line = sql_fetch_array($result);

		$querychar = "select charname,charid from ".$prefix."_character_characters where charid= '$line[charid]'";
		$resultchar = sql_query($querychar,$dbi);
		if(!list($charname,$charid) = sql_fetch_array($resultchar))
			$charname = "";

		echo date("F j, Y, g:i a T",strtotime($line[xpdate]))."<br>
		"._character.": <a href=\"admin.php?op=character_viewcharacter&charid=$charid&firstload=1\">$charname</a>
		 (<a target=\"_new\" href=\"admin.php?op=character_viewcharacter&charid=$charid&firstload=1\">"._newwindow."</a>)<br>
		"._xprequested.": $line[xp]<br>
		"._details.": $line[details]<br>
		"._xpstatus." ".constant("_".$line[status]);
		if($line['status'] == "resolved")
		{
			echo "<br>"._xpgiven.": $line[stxp]";
			echo "<br>"._stcomments.": $line[stcomments]";
		}
		else
		{
			echo "<br><br>
			<form action=\"admin.php?op=character_xprequest&mode2=submit\" method=\"post\">
			"._xpgive.": ".make_selectbox_num("stxp","",0,6)."<br>
			"._stcomments.": <textarea name=\"stcomments\" cols=\"100\" rows=\"4\"></textarea> <br>
			<input type = \"hidden\" name=\"charid\" value = \"$charid\">
			<input type = \"hidden\" name=\"xpid\" value=\"$xpid\">
			<input type=\"submit\" name=\"submit\" value=\""._resolvexp."\"></form>";
		}
	}




}

else if($mode2 == "all")
{
	$query = "select id,charid,xpdate,xp,details,status,stxp from ".$prefix."_character_xp order by status asc, xpdate asc";
	$result = sql_query($query, $dbi) or die(_notresource);

	echo "<div align = center>"._AllXPRequest.":";
	if(!sql_num_rows($result))
	{
		echo _noxp."<br><br>";
	}
	else
	{


		echo "<table width=400><tr>
		<th>"._character."</th><th>"._date."</th><th>"._xp."</th><th>"._status."</th></tr>";
		while($line = sql_fetch_array($result))
		{
			$querychar = "select charname,charid from ".$prefix."_character_characters where charid= '$line[charid]'";
			$resultchar = sql_query($querychar,$dbi);
			if(!list($charname,$charid) = sql_fetch_array($resultchar))
				$charname = "";
			echo "<tr><td align=\"center\"><a href=\"admin.php?op=character_viewcharacter&charid=$charid&firstload=1\">$charname</a></td><td align =\"left\">";
			echo "<a href=\"admin.php?op=character_xprequest&mode2=view&charid=$line[charid]&xpid=$line[id]\">$line[xpdate]</a></td><td align=\"center\">".$line['xp']."</td><td align = \"center\">";
			if($line['status'] == "pending")
				echo _pending;
			else
				echo "<b>"._resolved."</b>";
			echo "</td></tr>";
		}

		echo "</table><br><br>";
	}




}

else
{
	$query = "select id,charid,xpdate,xp,details,status,stxp from ".$prefix."_character_xp where status = 'pending' order by xpdate asc";
	$result = sql_query($query, $dbi) or die("resource not available");

	echo "<div align = center>Pending XP Requests: (<a href=\"admin.php?op=character_xprequest&mode2=all\">All XP Requests</a>)";
	if(!sql_num_rows($result))
	{
		echo "<br>No Pending XP Requests<br><br>";
	}
	else
	{


		echo "<table width=400><tr>
		<th>Character</th><th>Date</th><th>XP</th><th>Status</th></tr>";
		while($line = sql_fetch_array($result))
		{
			$querychar = "select charname,charid from ".$prefix."_character_characters where charid= '$line[charid]'";
			$resultchar = sql_query($querychar,$dbi);
			if(!list($charname,$charid) = sql_fetch_array($resultchar))
				$charname = "";
			echo "<tr><td align=\"center\"><a href=\"admin.php?op=character_viewcharacter&charid=$charid&firstload=1\">$charname</a></td><td align =\"left\">";
			echo "<a href=\"admin.php?op=character_xprequest&mode2=view&charid=$line[charid]&xpid=$line[id]\">$line[xpdate]</a></td><td align=\"center\">".$line['xp']."</td><td align = \"center\">$line[status]";

			echo "</td></tr>";
		}

		echo "</table><br><br>";
	}
}
?>
Return current item: VampMan: V:tR Character Manager