<?php
require_once ("data_class.php");
class Create extends Data {
function FetchCreatures() {
$fq = mysql_query(
"
SELECT
*
FROM
creatures_data
"
);
$i = 1;
$m = mysql_num_rows($fq);
if (isset($_GET["cid"])) {
$cu_id = mysql_real_escape_string($_GET["cid"]);
} else {
$cu_id = 1;
}
echo "
<select name='crid'
onchange=\"if (this.selectedIndex >= 0) document.location.href='?p=create&cid=' + this.value;\">
";
while ($i <= $m) {
$this->cdata[$i] = mysql_fetch_assoc($fq);
if ($cu_id == $this->cdata[$i][id]) {
echo "<option selected='selected' value='".$this->cdata[$i][id]."'>".$this->cdata[$i][cclass]."</option>";
} else {
echo "<option value='".$this->cdata[$i][id]."'>".$this->cdata[$i][cclass]."</option>";
}
$i++;
}
echo "</select>";
}
function CreateC() {
$this->GetUserData();
if (isset($_POST["cr_creature"])) {
$cuid = $_POST["cr_id"];
$n = $_POST["nm_creature"];
$cq3 = mysql_query("SELECT * FROM creatures_data WHERE id = '$cuid'");
$insert = mysql_fetch_assoc($cq3);
$cnq = mysql_query("
INSERT INTO player_creatures (
id ,
user_id ,
creature_id ,
name ,
type ,
description ,
hp ,
speed ,
att ,
def ,
level ,
exp ,
gold ,
skillpoints ,
head ,
amulet ,
armor ,
hands ,
legs ,
weapon ,
current_action
)
VALUES (
NULL ,
'".$_SESSION["id"]."',
'".$insert[id]."',
'$n',
'".$insert[cclass]."',
'".$insert[description]."',
'".$insert[hp]."',
'".$insert[speed]."',
'".$insert[att]."',
'".$insert[def]."',
'1',
'0',
'200',
'0',
'0',
'0',
'0',
'0',
'0',
'0',
'Doing nothing special...'
);
");
echo "<table align='left' width='560' border='0'>";
echo "<tr><td valign='top'>Creature created! Proceed to game by selecting one of menu items above.</td></tr>";
echo "</table>";
} else {
if (!isset($_GET["cid"]) OR preg_match("/[^0-9]+/", $_GET["cid"])) {
$cuid = 1;
} else {
$cuid = $_GET["cid"];
}
$cq2 = mysql_query("SELECT * FROM creatures_data WHERE id = '$cuid'");
$this->ccreature = mysql_fetch_assoc($cq2);
echo "<table align='left' width='560' border='0'>";
echo "<tr><td valign='top'>Select creature:</td><td>";
$this->FetchCreatures();
echo "</td></tr>";
echo "<tr><td colspan='2'><br /><br /><br /></td></tr>";
echo "<tr><td valign='top' width='150'>Creature Class:</td><td width='350' valign='top'><b>".$this->ccreature[cclass]."</b></td></tr>";
echo "<tr><td valign='top' width='150'>Creature Description:</td><td width='350' valign='top'>".$this->ccreature[description]."</td></tr>";
echo "<tr><td colspan='2'><br /><br /><br /></td></tr>";
echo "<tr><td valign='top' width='150'>Hit Points</td><td width='350' valign='top'>".$this->ccreature[hp]."</td></tr>";
echo "<tr><td valign='top' width='150'>Speed</td><td width='350' valign='top'>".$this->ccreature[speed]."</td></tr>";
echo "<tr><td valign='top' width='150'>Attack / Defence</td><td width='350' valign='top'>".$this->ccreature[att]." / ".$this->ccreature[def]."</td></tr>";
echo "<tr><td><br />
<form action='?p=create' method='POST'>
Name:
<input type='text' name='nm_creature' />
<input type='hidden' name='cr_id' value='$cuid' />
</td><td>
<input type='submit' name='cr_creature' value='Choose this creature' />
</form>
</td></tr>";
echo "</table>";
}
}
}
?>