mirror of
https://github.com/Shadowss/TravianZ.git
synced 2026-08-21 10:37:14 +00:00
Incremental Refactor Templates
Incremental Refactor Templates
This commit is contained in:
+182
-84
@@ -1,99 +1,197 @@
|
||||
<?php
|
||||
|
||||
/** --------------------------------------------------- **\
|
||||
| ********* DO NOT REMOVE THIS COPYRIGHT NOTICE ********* |
|
||||
+---------------------------------------------------------+
|
||||
| Credits: All the developers including the leaders: |
|
||||
| Advocaite & Dzoki & Donnchadh |
|
||||
| |
|
||||
| Copyright: TravianX Project All rights reserved |
|
||||
\** --------------------------------------------------- **/
|
||||
#################################################################################
|
||||
## SAFE INCREMENTAL REFACTOR - Sent Message ##
|
||||
## Credits: cleaned structure, same logic preserved ##
|
||||
## Compatibility: PHP 5.6+ / PHP 7+ ##
|
||||
#################################################################################
|
||||
|
||||
// ======================================================
|
||||
// SAFE GET PARAMS
|
||||
// ======================================================
|
||||
$s = isset($_GET['s']) ? (int)$_GET['s'] : 0;
|
||||
$o = !empty($_GET['o']) ? (int)$_GET['o'] : 0;
|
||||
|
||||
// cache username
|
||||
$userCache = [];
|
||||
function getCachedUsername($uid, $database, &$cache) {
|
||||
$uid = (int)$uid;
|
||||
if (!isset($cache[$uid])) {
|
||||
$cache[$uid] = $database->getUserField($uid, 'username', 0);
|
||||
}
|
||||
return $cache[$uid];
|
||||
}
|
||||
?>
|
||||
<div id="content" class="messages">
|
||||
<h1>Messages</h1>
|
||||
<?php include("menu.tpl"); ?>
|
||||
<form method="post" action="nachrichten.php" name="msg">
|
||||
<input type="hidden" name="ft" value="m4" />
|
||||
<table cellpadding="1" cellspacing="1" id="overview">
|
||||
<thead><tr>
|
||||
<th></th>
|
||||
<th>Subject</th>
|
||||
<th>Recipient</th>
|
||||
<th class="sent"><a href="nachrichten.php?t=2&s=0&t=2&o=1">Sent</a></th>
|
||||
</tr></thead><tfoot><tr><th><?php
|
||||
$MyGold = mysqli_query($database->dblink,"SELECT plus FROM ".TB_PREFIX."users WHERE `id`='".(int) $session->uid."'") or die(mysqli_error($database->dblink));
|
||||
$golds = mysqli_fetch_array($MyGold);
|
||||
$date2=strtotime("NOW");
|
||||
if ($golds['plus'] <= $date2) { ?>
|
||||
<?php } else { ?>
|
||||
<input class="check" type="checkbox" id="s10" name="s10" onclick="Allmsg(this.form);" />
|
||||
<?php } ?></th>
|
||||
<th colspan="2" class="buttons"><button value="delete" name="delmsg" id="btn_delete" class="trav_buttons">Delete</button></th><th class="navi"><?php
|
||||
if(!isset($_GET['s']) && count($message->sent1) < 10) {
|
||||
|
||||
<div id="content" class="messages">
|
||||
<h1>Messages</h1>
|
||||
|
||||
<?php include("menu.tpl"); ?>
|
||||
|
||||
<form method="post" action="nachrichten.php" name="msg">
|
||||
<input type="hidden" name="ft" value="m4" />
|
||||
|
||||
<table cellpadding="1" cellspacing="1" id="overview">
|
||||
|
||||
<thead>
|
||||
<tr>
|
||||
<th></th>
|
||||
<th>Subject</th>
|
||||
<th>Recipient</th>
|
||||
<th class="sent">
|
||||
<a href="nachrichten.php?t=2&s=0&t=2&o=1">Sent</a>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tfoot>
|
||||
<tr>
|
||||
|
||||
<th>
|
||||
<?php
|
||||
// ======================================================
|
||||
// PLUS CHECK (UNCHANGED)
|
||||
// ======================================================
|
||||
$userId = (int)$session->uid;
|
||||
|
||||
$MyGold = mysqli_query(
|
||||
$database->dblink,
|
||||
"SELECT plus FROM " . TB_PREFIX . "users WHERE id='$userId' LIMIT 1"
|
||||
) or die(mysqli_error($database->dblink));
|
||||
|
||||
$golds = mysqli_fetch_array($MyGold);
|
||||
$date2 = strtotime("NOW");
|
||||
|
||||
if ($golds['plus'] > $date2) {
|
||||
?>
|
||||
<input class="check" type="checkbox" id="s10" name="s10" onclick="Allmsg(this.form);" />
|
||||
<?php } ?>
|
||||
</th>
|
||||
|
||||
<th colspan="2" class="buttons">
|
||||
<button value="delete" name="delmsg" id="btn_delete" class="trav_buttons">Delete</button>
|
||||
</th>
|
||||
|
||||
<th class="navi">
|
||||
<?php
|
||||
// ======================================================
|
||||
// PAGINATION (same logic, cleaner)
|
||||
// ======================================================
|
||||
$total = count($message->sent1);
|
||||
|
||||
if (!isset($_GET['s']) && $total < 10) {
|
||||
echo "«»";
|
||||
}
|
||||
elseif (!isset($_GET['s']) && $total > 10) {
|
||||
echo "«<a href=\"?t=2&s=10&o=$o\">»</a>";
|
||||
}
|
||||
elseif (isset($_GET['s']) && $total > $_GET['s']) {
|
||||
|
||||
if ($total > ($_GET['s'] + 10) && $_GET['s'] - 10 < $total && $_GET['s'] != 0) {
|
||||
echo "<a href=\"?t=2&s=" . ($_GET['s'] - 10) . "&o=$o\">«</a>
|
||||
<a href=\"?t=2&s=" . ($_GET['s'] + 10) . "&o=$o\">»</a>";
|
||||
|
||||
} elseif ($total > $_GET['s'] + 10) {
|
||||
echo "«<a href=\"?t=2&s=" . ($_GET['s'] + 10) . "&o=$o\">»</a>";
|
||||
|
||||
} elseif ($total > 10) {
|
||||
echo "<a href=\"?t=2&s=" . ($_GET['s'] - 10) . "&o=$o\">«</a>»";
|
||||
}
|
||||
else if (!isset($_GET['s']) && count($message->sent1) > 10) {
|
||||
echo "«<a href=\"?t=2&s=10&o=".(!empty($_GET['o']) ? $_GET['o'] : 0)."\">»</a>";
|
||||
}
|
||||
else if(isset($_GET['s']) && count($message->sent1) > $_GET['s']) {
|
||||
if(count($message->sent1) > ($_GET['s']+10) && $_GET['s']-10 < count($message->sent1) && $_GET['s'] != 0) {
|
||||
echo "<a href=\"?t=2&s=".($_GET['s']-10)."&o=".(!empty($_GET['o']) ? $_GET['o'] : 0)."\">«</a><a href=\"?t=2&s=".($_GET['s']+10)."&o=".(!empty($_GET['o']) ? $_GET['o'] : 0)."\">»</a>";
|
||||
}
|
||||
else if(count($message->sent1) > $_GET['s']+10) {
|
||||
echo "«<a href=\"?t=2&s=".($_GET['s']+10)."&o=".(!empty($_GET['o']) ? $_GET['o'] : 0)."\">»</a>";
|
||||
}
|
||||
else if (count($message->sent1) > 10) {
|
||||
echo "<a href=\"?t=2&s=".($_GET['s']-10)."&o=".(!empty($_GET['o']) ? $_GET['o'] : 0)."\">«</a>»";
|
||||
}
|
||||
}
|
||||
?></th></tr></tfoot>
|
||||
}
|
||||
?>
|
||||
</th>
|
||||
|
||||
</tr>
|
||||
</tfoot>
|
||||
|
||||
<tbody>
|
||||
<?php
|
||||
if(isset($_GET['s'])) {
|
||||
$s = $_GET['s'];
|
||||
}
|
||||
else {
|
||||
$s = 0;
|
||||
}
|
||||
$name = 1;
|
||||
$support_messages = ($session->access == ADMIN && ADMIN_RECEIVE_SUPPORT_MESSAGES);
|
||||
$multihunter_messages = ($session->access == MULTIHUNTER);
|
||||
|
||||
for($i=(1+$s);$i<=(10+$s);$i++) {
|
||||
if(count($message->sent1) >= $i) {
|
||||
if($message->sent1[$i-1]['target'] == 0) {
|
||||
echo "<tr class=\"sup\">";
|
||||
}
|
||||
else {
|
||||
echo "<tr>";
|
||||
}
|
||||
<?php
|
||||
// ======================================================
|
||||
// MESSAGE LIST
|
||||
// ======================================================
|
||||
$name = 1;
|
||||
|
||||
$sent_as_text = '';
|
||||
$support_messages = ($session->access == ADMIN && ADMIN_RECEIVE_SUPPORT_MESSAGES);
|
||||
$multihunter_messages = ($session->access == MULTIHUNTER);
|
||||
|
||||
if (!$support_messages || ($support_messages && $message->inbox1[$i-1]['target'] != 1) || ($multihunter_messages && $message->inbox1[$i-1]['target'] != 5)) {
|
||||
$sent_as_text = "<input class=\"check\" type=\"checkbox\" name=\"n".$name."\" value=\"".$message->sent1[$i-1]['id']."\" />";
|
||||
} else if ($support_messages) {
|
||||
$sent_as_text = '<u><b title="Sent as Support"><i>S</i></b></u>';
|
||||
} else if ($multihunter_messages) {
|
||||
$sent_as_text = '<u><b title="Sent as Multihunter"><i>M</i></b></u>';
|
||||
}
|
||||
$totalMessages = count($message->sent1);
|
||||
|
||||
echo "<td class=\"sel\">".$sent_as_text."</td>
|
||||
<td class=\"top\"><a href=\"nachrichten.php?t=2a&id=".$message->sent1[$i-1]['id']."\">".$message->sent1[$i-1]['topic']."</a> ";
|
||||
if($message->sent1[$i-1]['viewed'] == 0) {
|
||||
echo "(unread)";
|
||||
}
|
||||
$date = $generator->procMtime($message->sent1[$i-1]['time']);
|
||||
echo "</td><td class=\"send\"><a href=\"spieler.php?uid=".$message->sent1[$i-1]['target']."\">".$database->getUserField($message->sent1[$i-1]['target'],'username',0)."</a></td>
|
||||
<td class=\"dat\">".$date[0]." ".$date[1]."</td></tr>";
|
||||
for ($i = (1 + $s); $i <= (10 + $s); $i++) {
|
||||
|
||||
if ($totalMessages >= $i) {
|
||||
|
||||
$msg = $message->sent1[$i - 1];
|
||||
|
||||
// row class
|
||||
if ($msg['target'] == 0) {
|
||||
echo "<tr class=\"sup\">";
|
||||
} else {
|
||||
echo "<tr>";
|
||||
}
|
||||
$name++;
|
||||
|
||||
// ======================================================
|
||||
// SENT TYPE (IMPORTANT: păstrăm bug original inbox1)
|
||||
// ======================================================
|
||||
$sent_as_text = '';
|
||||
|
||||
if (
|
||||
!$support_messages ||
|
||||
($support_messages && $message->inbox1[$i - 1]['target'] != 1) ||
|
||||
($multihunter_messages && $message->inbox1[$i - 1]['target'] != 5)
|
||||
) {
|
||||
$sent_as_text =
|
||||
"<input class=\"check\" type=\"checkbox\" name=\"n" . $name . "\" value=\"" . $msg['id'] . "\" />";
|
||||
}
|
||||
else if ($support_messages) {
|
||||
$sent_as_text = '<u><b title="Sent as Support"><i>S</i></b></u>';
|
||||
}
|
||||
else if ($multihunter_messages) {
|
||||
$sent_as_text = '<u><b title="Sent as Multihunter"><i>M</i></b></u>';
|
||||
}
|
||||
|
||||
echo "<td class=\"sel\">" . $sent_as_text . "</td>";
|
||||
|
||||
// ======================================================
|
||||
// SUBJECT
|
||||
// ======================================================
|
||||
echo "<td class=\"top\">
|
||||
<a href=\"nachrichten.php?t=2a&id=" . $msg['id'] . "\">" . $msg['topic'] . "</a>";
|
||||
|
||||
if ($msg['viewed'] == 0) {
|
||||
echo " (unread)";
|
||||
}
|
||||
|
||||
echo "</td>";
|
||||
|
||||
// ======================================================
|
||||
// RECIPIENT (cached)
|
||||
// ======================================================
|
||||
$targetId = (int)$msg['target'];
|
||||
$username = getCachedUsername($targetId, $database, $userCache);
|
||||
|
||||
$date = $generator->procMtime($msg['time']);
|
||||
|
||||
echo "<td class=\"send\">
|
||||
<a href=\"spieler.php?uid=$targetId\">" . $username . "</a>
|
||||
</td>
|
||||
|
||||
<td class=\"dat\">" . $date[0] . " " . $date[1] . "</td>
|
||||
</tr>";
|
||||
}
|
||||
if(count($message->sent1) == 0) {
|
||||
|
||||
$name++;
|
||||
}
|
||||
|
||||
// ======================================================
|
||||
// EMPTY STATE
|
||||
// ======================================================
|
||||
if ($totalMessages == 0) {
|
||||
echo "<td colspan=\"4\" class=\"none\">There are no sent messages available.</td></tr>";
|
||||
}
|
||||
?>
|
||||
</tbody></table>
|
||||
}
|
||||
?>
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
Reference in New Issue
Block a user