Skip to content

Commit

Permalink
Top OK
Browse files Browse the repository at this point in the history
  • Loading branch information
FrenchDilettante committed Jun 13, 2011
1 parent 20d5bb2 commit ff91d1b
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 17 deletions.
16 changes: 9 additions & 7 deletions model/top.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

$plage = isset($_COOKIE["top-plage"]) ? $_COOKIE["top-plage"] : "24h";
$plage = isset($_GET["from"]) ? $_GET["from"] : $plage;
$_COOKIE["top-plage"] = $plage;
setcookie("top-plage", $plage);

try {
$db = new PDO("mysql:host=localhost;dbname=pqjep", $db_username, $db_password);
Expand All @@ -12,12 +12,13 @@

switch ($plage) {
case "3j":
$where_clause = "WHERE date_vote >= DATE_SUB(CURRENT_TIMESTAMP, INTERVAL 4 DAY) ";
$where_clause = "WHERE date_vote >= DATE_SUB(CURRENT_TIMESTAMP, INTERVAL 3 DAY) ";
break;
case "1s":
$where_clause = "WHERE date_vote >= DATE_SUB(CURRENT_TIMESTAMP, INTERVAL 1 WEEK) ";
break;
case "all":
$where_clause = "";
break;

default:
Expand All @@ -26,7 +27,7 @@
}

$count = 0;
foreach ($db->query("SELECT COUNT(*) nb FROM fortune $where_clause") as $row) {
foreach ($db->query("SELECT COUNT(DISTINCT f.id) nb FROM fortune f LEFT OUTER JOIN vote v ON f.id = v.id_fortune $where_clause") as $row) {
$count = round($row["nb"] / 10, 0);
}

Expand All @@ -37,13 +38,14 @@
}

$confessions = array();
$query = "SELECT id id, vote_p, vote_m, fortune "
$query = "SELECT f.id id, f.vote_p, f.vote_m, fortune "
."FROM fortune f "
."ORDER BY vote_p DESC, date_ajout DESC "
."LEFT OUTER JOIN vote v ON f.id = v.id_fortune "
.$where_clause
."GROUP BY f.id "
."ORDER BY SUM(v.vote_p) DESC, date_ajout DESC "
."LIMIT $p, 10";

echo $query;

foreach ($db->query($query) as $row) {
$conf = array();
$conf['id'] = $row["id"];
Expand Down
2 changes: 1 addition & 1 deletion root/ajax/signaler.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?
require_once '../model/db.php';
require_once '../../model/db.php';

$id_fortune = $_POST["id"];
$ip_from = $_SERVER["REMOTE_ADDR"];
Expand Down
2 changes: 1 addition & 1 deletion root/fragments/pages.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
1 &lt;&lt;
<? } ?>
</li>
<? for ($i=($curpage-$ecart > 1 ? $curpage-$ecart+1 : 1); $i<($curpage+$ecart < $count + 1 ? $curpage+$ecart: $count-1); $i++) { ?>
<? for ($i=($curpage-$ecart > 1 ? $curpage-$ecart+1 : 1); $i<($curpage+$ecart < $count + 1 ? $curpage+$ecart: $count); $i++) { ?>
<li>
<? if ($i == ($curpage)) { ?>
<? echo $i + 1; ?>
Expand Down
4 changes: 4 additions & 0 deletions root/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ a:hover {
display: inline;
}

.top-plages a.select {
color: black;
}

fieldset {
border: none;
}
Expand Down
18 changes: 10 additions & 8 deletions root/top.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,19 @@
</div>

<div id="content">
<div class="top-plages">
<ul>
<li><a href="top.php?from=24h">24h</a></li>
<li><a href="top.php?from=3j">3j</a></li>
<li><a href="top.php?from=1s">1s</a></li>
</ul>
</div>

<a id="aveu" style="margin: 0" href="avouer.php">Dis-nous pourquoi tu pirates !</a>
<a id="aveu" href="avouer.php">Dis-nous pourquoi tu pirates !</a>

<div class="main">
<div class="top-plages">
<ul>
<li><a href="top.php?from=24h" class="<? echo $plage == "24h" ? "select" : "" ?>">24h</a></li>
<li><a href="top.php?from=3j" class="<? echo $plage == "3j" ? "select" : "" ?>">3j</a></li>
<li><a href="top.php?from=1s" class="<? echo $plage == "1s" ? "select" : "" ?>">1s</a></li>
<li><a href="top.php?from=all" class="<? echo $plage == "all" ? "select" : "" ?>">Tout</a></li>
</ul>
</div>

<h1>Les plus pires fourbonneries (quelque part entre fourbe et forban)</h1>
<? include "fragments/pages.php" ?>

Expand Down

0 comments on commit ff91d1b

Please sign in to comment.