Skip to content

Commit

Permalink
[2.1.61] Added time left on all opened predictions
Browse files Browse the repository at this point in the history
  • Loading branch information
MarioSwitch committed Oct 23, 2024
1 parent 421ebc6 commit 2bba400
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 36 deletions.
2 changes: 1 addition & 1 deletion views/about.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@
</table>
<br>
<p>
<i>Version 2.1.60 du 17 octobre 2024</i>
<i>Version 2.1.61 du 23 octobre 2024</i>
</p>
<?php include_once "time.js.php"; ?>
<script>document.getElementById("localTime").innerHTML = " (" + displayTime(0, 0) + " selon votre fuseau horaire)";</script>
65 changes: 35 additions & 30 deletions views/home.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,47 +27,53 @@
Échangez avec la communauté, discutez des prédictions, proposez des idées d'amélioration et bien plus encore, en rejoignant le serveur Discord officiel du site !<br>
Lien d'invitation : <a href=\"https://discord.gg/PCKx4qf9XZ\">https://discord.gg/PCKx4qf9XZ</a>
<hr>";
$predictions = arraySQL("SELECT `id`, `title` FROM `predictions` WHERE `ended` > NOW() ORDER BY `ended` ASC;");
$predictions_count = $predictions?count($predictions):0;
echo "<h2>" . getString("predictions_ongoing") . " (" . displayInt($predictions_count) . ")</h2>";
$predictions = arraySQL("SELECT `id`, `title`, `ended` FROM `predictions` WHERE `ended` > NOW() ORDER BY `ended` ASC;");
$predictionsCount = $predictions?count($predictions):0;
$predictionsEnded = [];
if($predictions){
foreach($predictions as $prediction){
$id = $prediction["id"];
$ended = $prediction["ended"];
$predictionsEnded[$id] = $ended;
}
}
echo "<h2>" . getString("predictions_ongoing") . " (" . displayInt($predictionsCount) . ")</h2>";
if(isConnected()){
// Predictions not participated
$predictionsNotParticipated = arraySQL("SELECT `predictions`.`id`, `predictions`.`title`, `predictions`.`ended` FROM `predictions` WHERE `predictions`.`ended` > NOW() AND `predictions`.`id` NOT IN (SELECT `predictions`.`id` FROM `predictions` JOIN `choices` ON `choices`.`prediction` = `predictions`.`id` JOIN `votes` ON `votes`.`choice` = `choices`.`id` WHERE `votes`.`user` = ? AND `answer` IS NULL) ORDER BY `predictions`.`ended` ASC;", [$_COOKIE["username"]]);
$predictionsNotParticipated = arraySQL("SELECT `predictions`.`id`, `predictions`.`title` FROM `predictions` WHERE `predictions`.`ended` > NOW() AND `predictions`.`id` NOT IN (SELECT `predictions`.`id` FROM `predictions` JOIN `choices` ON `choices`.`prediction` = `predictions`.`id` JOIN `votes` ON `votes`.`choice` = `choices`.`id` WHERE `votes`.`user` = ? AND `answer` IS NULL) ORDER BY `predictions`.`ended` ASC;", [$_COOKIE["username"]]);
$predictionsNotParticipatedCount = $predictionsNotParticipated?count($predictionsNotParticipated):0;
if($predictionsNotParticipatedCount){
$predictionsNotParticipatedEndDates = [];
foreach($predictionsNotParticipated as $prediction){
foreach($prediction as $key => $value){
if($key == "ended"){
array_push($predictionsNotParticipatedEndDates, $value);
}
}
}
}
echo "<h3>" . getString("home_bet_waiting") . " (" . displayInt($predictionsNotParticipatedCount) . ")</h3>";
if(!$predictionsNotParticipated){
echo "<p>" . getString("predictions_none") . "</p>";
}else{
for ($i=0; $i < count($predictionsNotParticipated); $i++){
$link = "index.php?view=prediction&id=" . $predictionsNotParticipated[$i]["id"];
echo "<a href=\"$link\">" . $predictionsNotParticipated[$i]["title"] . "</a>";
echo "<p>" . getString("bets_end") . " <abbr id='ended_$i'>" . $predictionsNotParticipatedEndDates[$i] . "</abbr></p><br>";
foreach($predictionsNotParticipated as $prediction){
$id = $prediction["id"];
$title = $prediction["title"];
$link = "index.php?view=prediction&id=" . $id;
echo "<a href=\"$link\">" . $title . "</a>";
echo "<p>" . getString("bets_end") . " <abbr id='ended_$id'>" . $predictionsEnded[$id] . "</abbr></p><br>";
}
}

// Separator
echo "<hr class=\"mini\">";

// Predictions participated
$predictionsParticipated = arraySQL("SELECT `predictions`.`id`, `predictions`.`title`, `predictions`.`ended`, `choices`.`name`, `votes`.`points` FROM `predictions` JOIN `choices` ON `choices`.`prediction` = `predictions`.`id` JOIN `votes` ON `votes`.`choice` = `choices`.`id` WHERE `votes`.`user` = ? AND NOW() < `ended` AND `answer` IS NULL ORDER BY `predictions`.`ended` ASC;", [$_COOKIE["username"]]);
$predictionsParticipated = arraySQL("SELECT `predictions`.`id`, `predictions`.`title`, `choices`.`name`, `votes`.`points` FROM `predictions` JOIN `choices` ON `choices`.`prediction` = `predictions`.`id` JOIN `votes` ON `votes`.`choice` = `choices`.`id` WHERE `votes`.`user` = ? AND NOW() < `ended` AND `answer` IS NULL ORDER BY `predictions`.`ended` ASC;", [$_COOKIE["username"]]);
$predictionsParticipatedCount = $predictionsParticipated?count($predictionsParticipated):0;
echo "<h3>" . getString("home_bet_already") . " (" . displayInt($predictionsParticipatedCount) . ")</h3>";
if(!$predictionsParticipated){
echo "<p>" . getString("predictions_none") . "</p>";
}else{
for ($i=0; $i < count($predictionsParticipated); $i++){
$link = "index.php?view=prediction&id=" . $predictionsParticipated[$i]["id"];
echo "<a href=\"$link\">" . $predictionsParticipated[$i]["title"] . "</a><p>" . getString("prediction_bet_info", [$predictionsParticipated[$i]["name"], displayInt($predictionsParticipated[$i]["points"])]) . "</p><br/>";
foreach($predictionsParticipated as $prediction){
$id = $prediction["id"];
$title = $prediction["title"];
$choice = $prediction["name"];
$points = $prediction["points"];
$link = "index.php?view=prediction&id=" . $id;
echo "<a href=\"$link\">" . $title . "</a>";
echo "<p>" . getString("prediction_bet_info", [$choice, displayInt($points)]) . "</p>";
echo "<p>" . getString("bets_end") . " <abbr id='ended_$id'>" . $predictionsEnded[$id] . "</abbr></p><br>";
}
}
}else{
Expand All @@ -76,16 +82,15 @@
echo "<p>" . getString("predictions_none") . "</p>";
die("");
}
for($i = 0; $i < count($predictions); $i++){
$id = $predictions[$i]["id"];
$title = $predictions[$i]["title"];
echo "<a href='?view=prediction&id=" . $id . "'>" . $title . "</a><br>";
foreach($predictions as $prediction){
$id = $prediction["id"];
$title = $prediction["title"];
echo "<a href='?view=prediction&id=" . $id . "'>" . $title . "</a>";
echo "<p>" . getString("bets_end") . " <abbr id='ended_$id'>" . $predictionsEnded[$id] . "</abbr></p><br>";
}
}

include_once "time.js.php";
if(isset($predictionsNotParticipatedCount)){
for ($i=0; $i < $predictionsNotParticipatedCount; $i++){
echo "<script>displayDateTime(\"" . $predictionsNotParticipatedEndDates[$i] . "\",\"ended_$i\");</script>";
}
foreach($predictionsEnded as $id => $ended){
echo "<script>displayDateTime(\"" . $ended . "\",\"ended_$id\");</script>";
}
6 changes: 3 additions & 3 deletions views/leaderboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@
$previousBottom = $tableBottom - $sqlLimit;
if($previousTop < 1) $previousTop = 1;
if($previousBottom < 1) $previousBottom = 1;
if($previousTop != $previousBottom) echo "<a href='?view=leaderboard&start=$previousTop&end=$previousBottom'>◄ " . getString("ranks") . " " . displayInt($previousTop, false) . "" . displayInt($previousBottom, false) . "</a><br>";
if($previousTop != $previousBottom) echo "<a href='?view=leaderboard&start=$previousTop&end=$previousBottom'>◄ " . getString("ranks") . " " . displayInt($previousTop, false) . "" . displayInt($previousBottom, false) . "</a>";
$nextTop = $tableTop + $sqlLimit;
$nextBottom = $tableBottom + $sqlLimit;
echo "<a href='?view=leaderboard&start=$nextTop&end=$nextBottom'>" . getString("ranks") . " " . displayInt($nextTop, false) . "" . displayInt($nextBottom, false) . " ►</a><br>";
echo "<a href='?view=leaderboard&start=$nextTop&end=$nextBottom'>" . getString("ranks") . " " . displayInt($nextTop, false) . "" . displayInt($nextBottom, false) . " ►</a>";
if(!is_null($myTableTop)){
echo "<a href='?view=leaderboard&start=$myTableTop&end=$myTableBottom'>" . getString("leaderboard_my_page") . " <small>(" . getString("ranks") . " " . displayInt($myTableTop, false) . "" . displayInt($myTableBottom, false) . ")</small></a>";
echo "<br><a href='?view=leaderboard&start=$myTableTop&end=$myTableBottom'>" . getString("leaderboard_my_page") . " <small>(" . getString("ranks") . " " . displayInt($myTableTop, false) . "" . displayInt($myTableBottom, false) . ")</small></a>";
}
echo "</td></tr></table>";
6 changes: 4 additions & 2 deletions views/prediction.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
ob_start();
if(array_key_exists("error",$_REQUEST)){
echo "<p class='error'>";
switch($_REQUEST["error"]){
Expand Down Expand Up @@ -120,7 +121,7 @@
}
$dropdownMenu = $dropdownMenu . "</select>";

$pointsMax = intSQL("SELECT `points` FROM `users` WHERE `username` = ?;", [$_COOKIE["username"]]);
$pointsMax = isConnected()?intSQL("SELECT `points` FROM `users` WHERE `username` = ?;", [$_COOKIE["username"]]):0;
$pointsField = "<input type='number' name='points' min='1' max='" . $pointsMax . "' required='required'>";

//Display
Expand Down Expand Up @@ -218,4 +219,5 @@
echo "<script>displayDateTime(\"$prediEnd\",\"endedCountdown\");</script>";
if($prediAnswered != NULL){
echo "<script>displayDateTime(\"$prediAnswered\",\"answeredCountdown\");</script>";
}
}
ob_end_flush();

0 comments on commit 2bba400

Please sign in to comment.