You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

102 lines
5.1 KiB

<?php
/*
* Created on 31.05.2011
*
* @copyright (c) 2011 animegame.eu
* @license http://www.gnu.org/licenses/gpl-3.0.html GNU General Public Licence
*
*/
?>
<?php
function displayNPC($action, $task, $charid, $table, $page, $data){
echo '<form action="'.$_SERVER['PHP_SELF'].'" method="POST">'."\n";
echo "\t".'<input type="hidden" name="choose" value="items"></input>'."\n";
echo "\t".'<table width="80%">'."\n";
if($action == 'edit'){
$d_array = array('charakter', 'name', 'zeit_rec', 'lvlmin', 'lvlmax');
$desc_array = array('ID', 'Name', 'Kampfdauer in Sekunden', 'Min-Level', 'Max-Level');
$sql = 'SELECT * FROM chars c inner join npc_item ni on ni.charakter = c.id inner join kampf_list kl on ni.charakter = kl.charakter WHERE c.id ='.$charid;
$qry = mysql_query($sql);
$row = mysql_fetch_assoc($qry);
$colspan = 2;
echo "\t".'<tr><td colspan="'.$colspan.'"><h1 style="text-align:center">NPC bearbeiten</h1></td></tr>'."\n";
echo "\t\t".'<tr><td>'.$desc_array[0].'</td><td style="text-align:center">'.$row[$d_array[0]].'</td></tr>'."\n";
for($i = 1;$i<count($d_array);$i++){
echo "\t\t".'<tr><td>'.$desc_array[$i].'</td><td style="text-align:center"><input name="data['.$d_array[$i].']" value="'.debbcode($row[$d_array[$i]]).'"></input></td></tr>'."\n";
}
echo "\t".'<tr><td colspan="'.$colspan.'" style="text-align:center"><a href="'.$_SERVER['PHP_SELF'].'?choose=npc">NPC Übersicht</a></td></tr>'."\n";
} else if($action == 'create'){
$colspan = 1;
echo "\t".'<tr><td colspan="'.$colspan.'"><h1 style="text-align:center">NPC erstellen</h1></td></tr>'."\n";;
echo "\t".'<tr><td colspan="'.$colspan.'" style="text-align:center"><a href="'.$_SERVER['PHP_SELF'].'?choose=npc">NPC Übersicht</a></td></tr>'."\n";
} else if($action == 'delete'){
$colspan = 1;
$sql = 'SELECT * FROM chars WHERE id = '.$charid;
$qry = mysql_query($sql);
$row = mysql_fetch_assoc($qry);
echo "\t".'<tr><td colspan="'.$colspan.'"><h1 style="text-align:center">NPC löschen</h1></td></tr>'."\n";;
if(is_null($task)){
echo "\t".'<tr><td colspan="'.$colspan.'" style="text-align:center">Soll der NPC '.$row['name'].' wirklich gelöscht werden</td></tr>'."\n";;
echo "\t".'<tr><td style="text-align:center"><a href="'.$_SERVER['PHP_SELF'].'?choose=npc&action=delete&task=do&charid='.$charid.'">ja</a>, <a href="'.$_SERVER['PHP_SELF'].'?choose=npc&action=">nein</a>, <a href="'.$_SERVER['PHP_SELF'].'?choose=npc&action=delete&charid='.$charid.'">vielleicht</a></td></tr>'."\n";
} else {
$sql = 'DELETE c,ni,kl,l FROM chars c inner join npc_item ni on ni.charakter = c.id inner join kampf_list kl on ni.charakter = kl.charakter inner join lernen l on l.besitzer = c.id where c.id = '.$charid;
// echo $sql.'<br>';
$qry = mysql_query($sql);
if($qry === FALSE || mysql_affected_rows() <= 0){
echo "\t".'<tr><td colspan="'.$colspan.'" style="text-align:center;color:red">Der NPC '.$row['name'].' konnte nicht gelöscht werden!</td></tr>'."\n";;
} else {
echo "\t".'<tr><td colspan="'.$colspan.'" style="text-align:center">Der NPC '.$row['name'].' wurde gelöscht!</td></tr>'."\n";;
}
// SELECT * FROM chars c inner join npc_item ni on ni.charakter = c.id inner join kampf_list kl on ni.charakter = kl.charakter
}
echo "\t".'<tr><td colspan="'.$colspan.'" style="text-align:center"><a href="'.$_SERVER['PHP_SELF'].'?choose=npc">NPC Übersicht</a></td></tr>'."\n";
} else{
$d_array = array('id', 'name', 'level');
$desc_array = array('id', 'Name', 'Level');
$sql = 'SELECT '.join($d_array,',').' from chars where rasse = \'NPC\' ORDER BY level';
$qry = mysql_query($sql.' LIMIT '.($page*20).', 20');
$anzahlSeiten = ceil(mysql_num_rows(mysql_query($sql))/20);
$colspan = count($d_array);
echo "\t".'<tr><td colspan="'.$colspan.'"><h1 style="text-align:center">Übersicht</h1></td></tr>'."\n";;
echo "\t".'<tr>'."\n";
for($i=1;$i<count($d_array);$i++){
echo "\t\t".'<td>'.$desc_array[$i].'</td>'."\n";
}
echo "\t\t".'<td style="text-align:center">Bearbeiten</td>'."\n";
echo "\t".'</tr>'."\n";
echo "\t".'<tr><td colspan="'.$colspan.'"><hr></td></tr>'."\n";
while($row = mysql_fetch_assoc($qry)){
echo "\t".'<tr>'."\n";
for($i=1;$i<count($d_array);$i++){
echo "\t\t".'<td>'.$row[$d_array[$i]].'</td>'."\n";
}
echo "\t\t".'<td style="text-align:center">'."\n";
// Echo the delete and the edit button :)
echo "\t\t\t".'<a href="'.$_SERVER['PHP_SELF'].'?choose=npc&action=edit&charid='.$row[$d_array[0]].'">Edit</a>, '."\n";
echo "\t\t\t".'<a href="'.$_SERVER['PHP_SELF'].'?choose=npc&action=delete&charid='.$row[$d_array[0]].'">Delete</a>'."\n";
echo "\t\t".'</td>'."\n";
echo "\t".'</tr>'."\n";
}
echo "\t".'<tr><td colspan="'.$colspan.'" style="text-align:center"><a href="'.$_SERVER['PHP_SELF'].'?choose=npc&action=create">Create a new NPC</a></td></tr>'."\n";
echo "\t".'<tr><td colspan="'.$colspan.'" style="text-align:center"><hr></td></tr>'."\n";
}
echo "\t".'<tr><td colspan="'.$colspan.'" style="text-align:center"><a href="'.$_SERVER['PHP_SELF'].'">Zum Hauptmenu</a></td></tr>'."\n";
echo "\t".'</table>'."\n";
echo '</form>'."\n";
}
?>