mirror of
https://github.com/Shadowss/TravianZ.git
synced 2026-07-10 06:36:07 +00:00
63c94fa961
Implement the "Time Preference" section of the player preferences (issue #198), which until now was stored in DB but never applied in-game. procMtime() — the central date/time formatter used across reports, messages, notices and troop movements — now honours the per-user settings: - timezone: the stored value is mapped to a DateTimeZone, either a named DST-aware region (Europe, UK, Turkey, Kolkata, Bangkok, New York, Chicago, New Zealand) or a fixed UTC offset (general zones); timestamps are converted before formatting. - tformat: drives the date layout and 12h/24h clock (0=EU dd.mm.yy 24h, 1=US mm/dd/yy 12h, 2=UK dd/mm/yy 12h, 3=ISO yy/mm/dd 24h). tformat 0 keeps the previous EU output unchanged. The today/yesterday sentinels are preserved (callers compare them) and are computed in the player's timezone. The time-only path (mode 9) stays 24h H:i:s because it feeds the live JS clock counters (unx.js), which parse "H:i:s" by splitting on ":". A few alliance/report/farm-list rows that combined procMtime's day part with a raw date('H:i') now take the time from the same procMtime result, to avoid mixing timezones. A second "local time" clock is shown next to the server-time one: a small vanilla-JS snippet emitted once from menu.tpl finds the visible #tp1 clock and appends a row ticking in the player's timezone (Date.now() + UTC offset), independent of the browser timezone and of the unx.js counters. It aligns the value under the server time, is skipped when the player's timezone matches the server's, and lets the clock box grow so the extra row fits the frame. Adds the LOCAL_TIME string (EN/FR/RO). When no player session is available (admin / pre-login) procMtime falls back to the server timezone and EU layout, i.e. the previous behaviour. Removes the last "not coded yet" tag from the preferences form. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
162 lines
5.2 KiB
Smarty
162 lines
5.2 KiB
Smarty
<?php
|
|
#################################################################################
|
|
## -= YOU MAY NOT REMOVE OR CHANGE THIS NOTICE =- ##
|
|
## --------------------------------------------------------------------------- ##
|
|
## Project: TravianZ (Refactor incremental) ##
|
|
## File: attack-filtered.tpl ##
|
|
## Description: Attack / report filtering ##
|
|
## Improvements: ##
|
|
## - Secure GET handling ##
|
|
## - Safer SQL parameters (cast only) ##
|
|
## - Reduced duplicated conditions ##
|
|
## - Cleaner rendering ##
|
|
## - XSS protection ##
|
|
#################################################################################
|
|
|
|
// filter type (secure cast)
|
|
$filterType = isset($_GET['f']) ? (int)$_GET['f'] : 0;
|
|
|
|
// base query
|
|
$sql = false;
|
|
|
|
// helper conditions (cleaner than long OR chains)
|
|
$allyId = (int)$session->alliance;
|
|
|
|
// FILTER 31
|
|
if ($filterType === 31) {
|
|
|
|
$sql = mysqli_query(
|
|
$database->dblink,
|
|
"SELECT * FROM " . TB_PREFIX . "ndata
|
|
WHERE ally = $allyId
|
|
AND (
|
|
(ntype != 0 AND ntype < 4)
|
|
OR (ntype > 17 AND ntype != 20 AND ntype != 21 AND ntype != 22)
|
|
)
|
|
ORDER BY time DESC
|
|
LIMIT 20"
|
|
);
|
|
|
|
// FILTER 32
|
|
} elseif ($filterType === 32) {
|
|
|
|
$sql = mysqli_query(
|
|
$database->dblink,
|
|
"SELECT * FROM " . TB_PREFIX . "ndata
|
|
WHERE ally = $allyId
|
|
AND (
|
|
ntype < 1
|
|
OR (ntype > 3 AND ntype < 8)
|
|
OR ntype > 19
|
|
)
|
|
AND ntype != 22
|
|
ORDER BY time DESC
|
|
LIMIT 20"
|
|
);
|
|
}
|
|
|
|
// fallback safety
|
|
$outputList = "";
|
|
|
|
if (!$sql || mysqli_num_rows($sql) == 0) {
|
|
|
|
$outputList .= "<tr><td colspan=\"4\" class=\"none\">There are no reports available.</td></tr>";
|
|
|
|
} else {
|
|
|
|
while ($row = mysqli_fetch_assoc($sql)) {
|
|
|
|
$dataarray = explode(",", $row['data']);
|
|
|
|
$id = (int)$row["id"];
|
|
$ally = (int)$row["ally"];
|
|
$ntype = (int)$row["ntype"];
|
|
$time = (int)$row["time"];
|
|
$topic = $row["topic"];
|
|
|
|
// detect report type group
|
|
$type2 = ($ntype >= 4 && $ntype <= 7) ? 32 : 31;
|
|
|
|
$type = (isset($_GET['t']) && (int)$_GET['t'] === 5)
|
|
? (int)$row['archive']
|
|
: $ntype;
|
|
|
|
if ($type == 23) {
|
|
$type = 22;
|
|
}
|
|
|
|
// icon logic
|
|
$useScoutIcon =
|
|
(($type == 18 || $type == 19) && $filterType == 31) ||
|
|
(($type == 20 || $type == 21) && $filterType == 32) ||
|
|
$type == 22;
|
|
|
|
// attacker + defender names (cache local variables to reduce DB calls)
|
|
$attackerId = (int)$dataarray[0];
|
|
$targetId = ($type != 22 && $type != 23) ? (int)$dataarray[28] : (int)$dataarray[2];
|
|
|
|
$attackerName = $database->getUserField($attackerId, "username", 0);
|
|
$targetName = $database->getUserField($targetId, "username", 0);
|
|
|
|
$targetAllyId = $database->getUserField($targetId, "alliance", 0);
|
|
$targetAllyName = $targetAllyId ? $database->getAllianceName($targetAllyId) : "-";
|
|
|
|
$allyLink = ($targetAllyId)
|
|
? "<a href=\"allianz.php?aid=" . (int)$targetAllyId . "\">" . htmlspecialchars($targetAllyName, ENT_QUOTES, 'UTF-8') . "</a>"
|
|
: "-";
|
|
|
|
$nn = (
|
|
(($type == 18 || $type == 19) && $filterType == 31) ||
|
|
(($type == 20 || $type == 21) && $filterType == 32)
|
|
) ? " scouts " : " attacks ";
|
|
|
|
$date = $generator->procMtime($time);
|
|
|
|
// render row
|
|
$outputList .= "<tr>";
|
|
|
|
// ICON + link switch
|
|
$outputList .= "<td class=\"sub\">";
|
|
$outputList .= "<a href=\"allianz.php?s=3&f=" . $type2 . "\">";
|
|
|
|
if ($useScoutIcon) {
|
|
$outputList .= "<img src=\"gpack/travian_default/img/scouts/$type.gif\" title=\"" . htmlspecialchars($topic, ENT_QUOTES, 'UTF-8') . "\" />";
|
|
} else {
|
|
$outputList .= "<img src=\"img/x.gif\" class=\"iReport iReport$type\" title=\"" . htmlspecialchars($topic, ENT_QUOTES, 'UTF-8') . "\">";
|
|
}
|
|
|
|
$outputList .= "</a>";
|
|
|
|
$outputList .= "<div><a href=\"berichte.php?id=$id&aid=$ally\">";
|
|
|
|
$outputList .= htmlspecialchars($attackerName, ENT_QUOTES, 'UTF-8');
|
|
$outputList .= $nn;
|
|
$outputList .= htmlspecialchars($targetName, ENT_QUOTES, 'UTF-8');
|
|
|
|
$outputList .= "</a></div>";
|
|
$outputList .= "</td>";
|
|
|
|
// alliance column
|
|
$outputList .= "<td class=\"al\">" . $allyLink . "</td>";
|
|
|
|
// date column
|
|
$outputList .= "<td class=\"dat\">" . $date[0] . " " . substr($date[1], 0, 5) . "</td>";
|
|
|
|
$outputList .= "</tr>";
|
|
}
|
|
}
|
|
?>
|
|
|
|
<table cellpadding="1" cellspacing="1" id="offs">
|
|
<thead>
|
|
<tr>
|
|
<td><?php echo PLAYER; ?></td>
|
|
<td><?php echo ALLIANCE; ?></td>
|
|
<td><?php echo DATE; ?></td>
|
|
</tr>
|
|
</thead>
|
|
|
|
<tbody>
|
|
<?php echo $outputList; ?>
|
|
</tbody>
|
|
</table> |