spells page: Fixed errors when spells is not installed by admin.

This commit is contained in:
Znote 2017-02-15 18:27:14 +01:00
parent bc2a6e2c01
commit 96802cb348

View File

@ -94,28 +94,29 @@ if (user_logged_in() && is_admin($user_data)) {
}
// End loading spell list
// Preparing data
$configVoc = $config['vocations'];
$types = array_keys($spells);
$itemServer = 'http://'.$config['shop']['imageServer'].'/';
if ($spells) {
// Preparing data
$configVoc = $config['vocations'];
$types = array_keys($spells);
$itemServer = 'http://'.$config['shop']['imageServer'].'/';
// Filter spells by vocation
$getVoc = (isset($_GET['vocation'])) ? getValue($_GET['vocation']) : 'all';
if ($getVoc !== 'all') {
// Filter spells by vocation
$getVoc = (isset($_GET['vocation'])) ? getValue($_GET['vocation']) : 'all';
if ($getVoc !== 'all') {
$getVoc = (int)$getVoc;
foreach ($types as $type)
foreach ($spells[$type] as $name => $spell)
if (!empty($spell['vocations']))
if (!in_array($getVoc, $spell['vocations']))
unset($spells[$type][$name]);
}
}
// Render HTML
?>
// Render HTML
?>
<h1 id="spells">Spells<?php if ($getVoc !== 'all') echo ' ('.$configVoc[$getVoc]['name'].')';?></h1>
<h1 id="spells">Spells<?php if ($getVoc !== 'all') echo ' ('.$configVoc[$getVoc]['name'].')';?></h1>
<form action="#spells" class="filter_spells">
<form action="#spells" class="filter_spells">
<label for="vocation">Filter vocation:</label>
<select id="vocation" name="vocation">
<option value="all">All</option>
@ -124,18 +125,18 @@ if ($getVoc !== 'all') {
<?php endforeach; ?>
</select>
<input type="submit" value="Search">
</form>
</form>
<h2>Spell types:</h2>
<ul>
<h2>Spell types:</h2>
<ul>
<?php foreach ($types as $type): ?>
<li><a href="#spell_<?php echo $type; ?>"><?php echo ucfirst($type); ?></a></li>
<?php endforeach; ?>
</ul>
</ul>
<h2 id="spell_instant">Instant Spells</h2>
<a href="#spells">Jump to top</a>
<table class="table tbl-hover">
<h2 id="spell_instant">Instant Spells</h2>
<a href="#spells">Jump to top</a>
<table class="table tbl-hover">
<tbody>
<tr class="yellow">
<td>Name</td>
@ -163,11 +164,11 @@ if ($getVoc !== 'all') {
</tr>
<?php endforeach; ?>
</tbody>
</table>
</table>
<h2 id="spell_rune">Magical Runes</h2>
<a href="#spells">Jump to top</a>
<table class="table tbl-hover">
<h2 id="spell_rune">Magical Runes</h2>
<a href="#spells">Jump to top</a>
<table class="table tbl-hover">
<tbody>
<tr class="yellow">
<td>Name</td>
@ -195,11 +196,11 @@ if ($getVoc !== 'all') {
</tr>
<?php endforeach; ?>
</tbody>
</table>
</table>
<h2 id="spell_conjure">Conjure Spells</h2>
<a href="#spells">Jump to top</a>
<table class="table tbl-hover">
<h2 id="spell_conjure">Conjure Spells</h2>
<a href="#spells">Jump to top</a>
<table class="table tbl-hover">
<tbody>
<tr class="yellow">
<td>Name</td>
@ -233,9 +234,16 @@ if ($getVoc !== 'all') {
</tr>
<?php endforeach; ?>
</tbody>
</table>
<a href="#spells">Jump to top</a>
<?php
</table>
<a href="#spells">Jump to top</a>
<?php
} else {
?>
<h1>Spells</h1>
<p>Spells have currently not been loaded into the website by the server admin.</p>
<?php
}
/* Debug tests
foreach ($spells as $type => $spells) {
data_dump($spells, false, "Type: $type");