Skip to content

Commit

Permalink
Création projet
Browse files Browse the repository at this point in the history
  • Loading branch information
FrenchDilettante committed Jun 11, 2011
0 parents commit f5150cb
Show file tree
Hide file tree
Showing 31 changed files with 1,094 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .buildpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<buildpath>
<buildpathentry kind="src" path="fragments"/>
<buildpathentry kind="src" path="model"/>
<buildpathentry kind="src" path="root"/>
<buildpathentry kind="src" path="www"/>
<buildpathentry kind="con" path="org.eclipse.php.core.LANGUAGE"/>
</buildpath>
22 changes: 22 additions & 0 deletions .project
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>pqjep</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.wst.validation.validationbuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.dltk.core.scriptbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.php.core.PHPNature</nature>
</natures>
</projectDescription>
3 changes: 3 additions & 0 deletions .settings/org.eclipse.php.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#Sat Jun 11 18:54:52 CEST 2011
eclipse.preferences.version=1
include_path=0;/pqjep
27 changes: 27 additions & 0 deletions fragments/fortune.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?
$selection = isset($_SESSION["selection"]) ? $_SESSION["selection"] : array("nom" => "", "liste" => array());
$select = false;
foreach ($selection["liste"] as $s) {
$select = $s == $c["id"];
if ($select) break;
}
?>

<div class="fortune" data-id="<? echo $c['id'] ?>" id="fortune-<? echo $c["id"] ?>">
<span class="texte"><? echo $c['fortune'] ?></span>
<div class="actions">
<span class="select">
<? if ($select) {?>
&#9733;Sélectionné <a href="" onclick="deselect(<? echo $c["id"] ?>); return false;">(Retirer)</a>
<? } else {?>
<a href="" onclick="select(<? echo $c["id"] ?>); return false;">&#9734;Sélectionner</a>
<? }?>
</span>
<span class="votes">
<a href="" onclick="voter(<? echo $c["id"] ?>, 1); return false;">+<? echo $c["vote_p"] ?></a>/
<a href="" onclick="voter(<? echo $c["id"] ?>, -1); return false;">-<? echo $c["vote_m"] ?></a>
</span>
<span class="signaler"><a href="" onclick="signaler(<? echo $c['id'] ?>); return false;">Signaler</a></span>
<a href="index.php?id=<? echo $c['id'] ?>">Raison #<? echo $c['id'] ?></a>
</div>
</div>
33 changes: 33 additions & 0 deletions fragments/includes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<link rel="stylesheet" type="text/css" href="main.css" />
<link href='http://fonts.googleapis.com/css?family=Playfair+Display' rel='stylesheet' type='text/css'>
<script language="javascript" src="http://code.jquery.com/jquery-1.6.1.min.js"></script>
<script language="javascript" src="fortune.js"></script>
<script language="javascript">
function update() {
restant = 500 - $("[name=fortune]").val().length;
$("#carmax").html(restant + " caractères restants.");
}
</script>
<!-- Piwik -->
<script type="text/javascript">
var pkBaseURL = (("https:" == document.location.protocol) ? "https://dev.wmginfo.com/piwik/" : "http://dev.wmginfo.com/piwik/");
document.write(unescape("%3Cscript src='" + pkBaseURL + "piwik.js' type='text/javascript'%3E%3C/script%3E"));
</script><script type="text/javascript">
try {
var piwikTracker = Piwik.getTracker(pkBaseURL + "piwik.php", 6);
piwikTracker.trackPageView();
piwikTracker.enableLinkTracking();
} catch( err ) {}
</script><noscript><p><img src="http://dev.wmginfo.com/piwik/piwik.php?idsite=6" style="border:0" alt="" /></p></noscript>
<!-- End Piwik Tracking Code -->
<script type="text/javascript">
/* <![CDATA[ */
(function() {
var s = document.createElement('script'), t = document.getElementsByTagName('script')[0];
s.type = 'text/javascript';
s.async = true;
s.src = 'http://api.flattr.com/js/0.6/load.js?mode=auto';
t.parentNode.insertBefore(s, t);
})();
/* ]]> */
</script>
3 changes: 3 additions & 0 deletions model/db.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?
$db_username="";
$db_password="";
39 changes: 39 additions & 0 deletions model/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?
require_once "../model/db.php";

try {
$db = new PDO("mysql:host=localhost;dbname=pqjep", $db_username, $db_password);

$c = array();

if (isset($_GET['id'])) {
$stmt = $db->prepare("SELECT f.id id, SUM(vote_p) vote_p, SUM(vote_m) vote_m, fortune "
."FROM fortune f "
."LEFT OUTER JOIN vote v ON v.id_fortune = f.id "
."WHERE f.id = :id "
."GROUP BY f.id ");
$stmt->bindParam(":id", $_GET["id"]);
$stmt->execute();
while ($row = $stmt->fetch()) {
$c["id"] = $row["id"];
$c["fortune"] = $row["fortune"];
$c["vote_p"] = $row["vote_p"] == null ? 0 : $row["vote_p"];
$c["vote_m"] = $row["vote_m"] == null ? 0 : $row["vote_m"];
}
} else {
$query = "SELECT f.id id, SUM(vote_p) vote_p, SUM(vote_m) vote_m, fortune "
."FROM fortune f "
."LEFT OUTER JOIN vote v ON v.id_fortune = f.id "
."GROUP BY f.id "
."ORDER BY RAND() "
."LIMIT 1";
foreach ($db->query($query) as $row) {
$c["id"] = $row["id"];
$c["fortune"] = $row["fortune"];
$c["vote_p"] = $row["vote_p"] == null ? 0 : $row["vote_p"];
$c["vote_m"] = $row["vote_m"] == null ? 0 : $row["vote_m"];
}
}
} catch (PDOException $e) {
die("Erreur de base de données. D'oh.");
}
34 changes: 34 additions & 0 deletions model/liste.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?
require_once "../model/db.php";

try {
$db = new PDO("mysql:host=localhost;dbname=pqjep", $db_username, $db_password);

foreach ($db->query("SELECT COUNT(*) nb FROM fortune") as $row) {
$count = round($row["nb"] / 10, 0);
}

$p = isset($_GET['p']) ? mysql_escape_string($_GET['p']) : 0;
$p *= 10;
if ($p < 0) {
$p = 0;
}

$confessions = array();
$query = "SELECT f.id id, SUM(vote_p) vote_p, SUM(vote_m) vote_m, fortune "
."FROM fortune f "
."LEFT OUTER JOIN vote v ON v.id_fortune = f.id "
."GROUP BY f.id "
."ORDER BY date_ajout DESC "
."LIMIT $p, 10";
foreach ($db->query($query) as $row) {
$conf = array();
$conf['id'] = $row["id"];
$conf['fortune'] = $row["fortune"];
$conf["vote_p"] = $row["vote_p"] == null ? 0 : $row["vote_p"];
$conf["vote_m"] = $row["vote_m"] == null ? 0 : $row["vote_m"];
array_push($confessions, $conf);
}
} catch (PDOException $e) {
die("Erreur de base de données. D'oh.");
}
35 changes: 35 additions & 0 deletions model/selection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?
require_once "../model/db.php";

$selection = isset($_SESSION["selection"]) ? $_SESSION["selection"] : array("nom" => "", "liste" => array());

try {
$db = new PDO("mysql:host=localhost;dbname=pqjep", $db_username, $db_password);

$confessions = array();
$query = "SELECT f.id id, SUM(vote_p) vote_p, SUM(vote_m) vote_m, fortune "
."FROM fortune f "
."LEFT OUTER JOIN vote v ON v.id_fortune = f.id "
."WHERE f.id = :id "
."GROUP BY f.id ";

$stmt = $db->prepare($query);

foreach ($selection["liste"] as $s) {
$stmt->bindParam(":id", $s);
$stmt->execute();

if ($row = $stmt->fetch()) {
$conf = array();
$conf['id'] = $row["id"];
$conf['fortune'] = $row["fortune"];
$conf["vote_p"] = $row["vote_p"] == null ? 0 : $row["vote_p"];
$conf["vote_m"] = $row["vote_m"] == null ? 0 : $row["vote_m"];
array_push($confessions, $conf);
}
}

$count = round(count($confessions) / 10);
} catch (PDOException $e) {
die("Erreur de base de données. D'oh.");
}
34 changes: 34 additions & 0 deletions model/top.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?
require_once "../model/db.php";

try {
$db = new PDO("mysql:host=localhost;dbname=pqjep", $db_username, $db_password);

foreach ($db->query("SELECT COUNT(*) nb FROM fortune") as $row) {
$count = round($row["nb"] / 10, 0);
}

$p = isset($_GET['p']) ? mysql_escape_string($_GET['p']) : 0;
$p *= 10;
if ($p < 0) {
$p = 0;
}

$confessions = array();
$query = "SELECT f.id id, SUM(vote_p) vote_p, SUM(vote_m) vote_m, fortune "
."FROM fortune f "
."LEFT OUTER JOIN vote v ON v.id_fortune = f.id "
."GROUP BY f.id "
."ORDER BY SUM(vote_p) DESC, date_ajout DESC "
."LIMIT $p, 10";
foreach ($db->query($query) as $row) {
$conf = array();
$conf['id'] = $row["id"];
$conf['fortune'] = $row["fortune"];
$conf["vote_p"] = $row["vote_p"] == null ? 0 : $row["vote_p"];
$conf["vote_m"] = $row["vote_m"] == null ? 0 : $row["vote_m"];
array_push($confessions, $conf);
}
} catch (PDOException $e) {
die("Erreur de base de données. D'oh.");
}
47 changes: 47 additions & 0 deletions model/view_select.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?
require_once "../model/db.php";

if (!isset($_GET["ids"])) {
header("Location: liste.php");
}
$ids = $_GET["ids"];

try {
$db = new PDO("mysql:host=localhost;dbname=pqjep", $db_username, $db_password);

$selection = array("nom" => "", "liste" => array());

$query = "SELECT nom "
."FROM selection "
."WHERE id = :id";
$stmt = $db->prepare($query);
$stmt->bindParam(":id", $ids);
$stmt->execute();
if ($row = $stmt->fetch()) {
$selection["nom"] = $row["nom"];
}

$query = "SELECT f.id id, SUM(vote_p) vote_p, SUM(vote_m) vote_m, fortune "
."FROM fortune f "
."LEFT OUTER JOIN vote v ON v.id_fortune = f.id "
."INNER JOIN fortune_selection fs ON f.id = fs.id_fortune "
."WHERE fs.id_selection = :ids "
."GROUP BY f.id "
."ORDER BY date_ajout DESC ";
$stmt = $db->prepare($query);
$stmt->bindParam(":ids", $ids);
$stmt->execute();
$liste = array();
while($row = $stmt->fetch()) {
$conf = array();
$conf['id'] = $row["id"];
$conf['fortune'] = $row["fortune"];
$conf["vote_p"] = $row["vote_p"] == null ? 0 : $row["vote_p"];
$conf["vote_m"] = $row["vote_m"] == null ? 0 : $row["vote_m"];
array_push($liste, $conf);
}

$selection["liste"] = $liste;
} catch (PDOException $e) {
die("Erreur de base de données. D'oh.");
}
30 changes: 30 additions & 0 deletions root/ajax/fortune.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?
require_once '../model/db.php';

$id = $_GET["id"];

try {
$db = new PDO("mysql:host=localhost;dbname=pqjep", $db_username, $db_password);

$c = array();

$query = "SELECT f.id id, SUM(vote_p) vote_p, SUM(vote_m) vote_m, fortune "
."FROM fortune f "
."LEFT OUTER JOIN vote v ON v.id_fortune = f.id "
."WHERE f.id = :id "
."GROUP BY f.id";
$stmt = $db->prepare($query);
$stmt->bindParam(":id", $id);
$stmt->execute();
while ($row = $stmt->fetch()) {
$c["id"] = $row["id"];
$c["fortune"] = $row["fortune"];
$c["vote_p"] = $row["vote_p"] == null ? 0 : $row["vote_p"];
$c["vote_m"] = $row["vote_m"] == null ? 0 : $row["vote_m"];
}

include "../../fragments/fortune.php";
} catch (PDOException $e) {
die("Erreur de base de données. D'oh.");
}
?>
26 changes: 26 additions & 0 deletions root/ajax/random.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?
require_once '../model/db.php';

try {
$db = new PDO("mysql:host=localhost;dbname=pqjep", $db_username, $db_password);

$c = array();

$query = "SELECT f.id id, SUM(vote_p) vote_p, SUM(vote_m) vote_m, fortune "
."FROM fortune f "
."LEFT OUTER JOIN vote v ON v.id_fortune = f.id "
."GROUP BY f.id "
."ORDER BY RAND() "
."LIMIT 1";
foreach ($db->query($query) as $row) {
$c["id"] = $row["id"];
$c["fortune"] = $row["fortune"];
$c["vote_p"] = $row["vote_p"] == null ? 0 : $row["vote_p"];
$c["vote_m"] = $row["vote_m"] == null ? 0 : $row["vote_m"];
}

include "../../fragments/fortune.php";
} catch (PDOException $e) {
die("Erreur de base de données. D'oh.");
}
?>
Loading

0 comments on commit f5150cb

Please sign in to comment.