forked from vergnet/site-accueil-insa
Edited project for debug local use
This commit is contained in:
parent
248b9b4a94
commit
c56f82ffd6
8 changed files with 79 additions and 77 deletions
11
.htaccess
Normal file
11
.htaccess
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
# Turn mod_rewrite on
|
||||||
|
RewriteEngine On
|
||||||
|
RewriteBase /
|
||||||
|
|
||||||
|
# To externally redirect /dir/foo.php to /dir/foo
|
||||||
|
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
|
||||||
|
RewriteRule ^ %1 [R,L,NC]
|
||||||
|
|
||||||
|
## To internally redirect /dir/foo to /dir/foo.php
|
||||||
|
RewriteCond %{REQUEST_FILENAME}.php -f [NC]
|
||||||
|
RewriteRule ^ %{REQUEST_URI}.php [L]
|
|
@ -1,56 +1,61 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
class Dao {
|
class Dao
|
||||||
|
{
|
||||||
|
|
||||||
private $conn;
|
private $conn;
|
||||||
|
|
||||||
private $debug = false;
|
private $debug = true;
|
||||||
|
|
||||||
public function __construct($path_to_password)
|
public function __construct($path_to_password)
|
||||||
{
|
{
|
||||||
$username = 'accueil_insa';
|
if ($this->debug) {
|
||||||
$password = $this->read_password($path_to_password);
|
$username = 'phpmyadmin';
|
||||||
$dsn = 'mysql:dbname=accueil_insa;host=127.0.0.1';
|
$password = $this->read_password($path_to_password);
|
||||||
|
$dsn = 'mysql:dbname=phpmyadmin;host=127.0.0.1';
|
||||||
|
} else {
|
||||||
|
$username = 'accueil_insa';
|
||||||
|
$password = $this->read_password($path_to_password);
|
||||||
|
$dsn = 'mysql:dbname=accueil_insa;host=127.0.0.1';
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
$this->conn = new PDO($dsn, $username, $password, [PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8']);
|
$this->conn = new PDO($dsn, $username, $password, [PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8']);
|
||||||
}
|
} catch (PDOException $e) {
|
||||||
catch (PDOException $e){
|
echo $e;
|
||||||
$this->debug = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function read_password($path_to_password){
|
private function read_password($path_to_password)
|
||||||
$file = fopen($path_to_password."includes/.htpassdb", "r") or die("Unable to open file!");;
|
{
|
||||||
|
if ($this->debug)
|
||||||
|
$real_path = $path_to_password . "includes/.htpassdb_debug";
|
||||||
|
else
|
||||||
|
$real_path = $path_to_password . "includes/.htpassdb";
|
||||||
|
$file = fopen($real_path, "r") or die("Unable to open file!");;
|
||||||
$password = fgets($file);
|
$password = fgets($file);
|
||||||
fclose($file);
|
fclose($file);
|
||||||
return $password;
|
return $password;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function get_score_team($team){
|
public function get_score_team($team)
|
||||||
if (!$this->debug)
|
{
|
||||||
{
|
$sql = 'SELECT text, points FROM scores WHERE team = ?';
|
||||||
$sql = 'SELECT text, points FROM scores WHERE team = ?';
|
$cursor = $this->conn->prepare($sql);
|
||||||
$cursor = $this->conn->prepare($sql);
|
$cursor->execute([$team]);
|
||||||
$cursor->execute([$team]);
|
return $cursor->fetchAll(PDO::FETCH_ASSOC);
|
||||||
return $cursor->fetchAll(PDO::FETCH_ASSOC);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function save_scores($scores_json, $team){
|
public function save_scores($scores_json, $team)
|
||||||
if (!$this->debug)
|
{
|
||||||
{
|
$sql = 'DELETE FROM scores WHERE team = ?';
|
||||||
$sql = 'DELETE FROM scores WHERE team = ?';
|
$cursor = $this->conn->prepare($sql);
|
||||||
$cursor = $this->conn->prepare($sql);
|
$cursor->execute([$team]);
|
||||||
$cursor->execute([$team]);
|
|
||||||
|
|
||||||
$array = json_decode($scores_json)->array;
|
$array = json_decode($scores_json)->array;
|
||||||
foreach ($array as $value){
|
foreach ($array as $value) {
|
||||||
$sql = 'INSERT INTO scores (text, points, team) VALUES (?, ?, ?)';
|
$sql = 'INSERT INTO scores (text, points, team) VALUES (?, ?, ?)';
|
||||||
$cursor = $this->conn->prepare($sql);
|
$cursor = $this->conn->prepare($sql);
|
||||||
$cursor->execute([$value->text, $value->points, $team]);
|
$cursor->execute([$value->text, $value->points, $team]);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
AuthName "Generals Only"
|
#AuthName "Generals Only"
|
||||||
AuthType Basic
|
#AuthType Basic
|
||||||
AuthUserFile /home_clubs/accueil_insa/public_html/includes/.htpassurss
|
#AuthUserFile /home_clubs/accueil_insa/public_html/includes/.htpassurss
|
||||||
require valid-user
|
#require valid-user
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
AuthName "Generals Only"
|
#AuthName "Generals Only"
|
||||||
AuthType Basic
|
#AuthType Basic
|
||||||
AuthUserFile /home_clubs/accueil_insa/public_html/includes/.htpassusa
|
#AuthUserFile /home_clubs/accueil_insa/public_html/includes/.htpassusa
|
||||||
require valid-user
|
#require valid-user
|
||||||
|
|
|
@ -2,11 +2,11 @@
|
||||||
require_once 'classes/dao.php';
|
require_once 'classes/dao.php';
|
||||||
function get_total_points($team)
|
function get_total_points($team)
|
||||||
{
|
{
|
||||||
// $dao = new Dao('');
|
$dao = new Dao('');
|
||||||
$points = 0;
|
$points = 0;
|
||||||
// foreach ($dao->get_score_team($team) as $row) {
|
foreach ($dao->get_score_team($team) as $row) {
|
||||||
// $points += $row['points'];
|
$points += $row['points'];
|
||||||
// }
|
}
|
||||||
return $points;
|
return $points;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
13
sponsors.php
13
sponsors.php
|
@ -1,13 +0,0 @@
|
||||||
<?php
|
|
||||||
ob_start(); // Start reading html
|
|
||||||
?>
|
|
||||||
<h1>Sponsors</h1>
|
|
||||||
<p>
|
|
||||||
Apparemment on a des sponsors.
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<?php
|
|
||||||
$pageContent = ob_get_clean(); // Store html content in variable
|
|
||||||
$pageTitle = "Info";
|
|
||||||
include("template.php"); // Display template with variable content
|
|
||||||
?>
|
|
30
stats.php
30
stats.php
|
@ -6,21 +6,21 @@ ob_start(); // Start reading html
|
||||||
|
|
||||||
function get_stats($team)
|
function get_stats($team)
|
||||||
{
|
{
|
||||||
// $dao = new Dao('');
|
$dao = new Dao('');
|
||||||
// foreach ($dao->get_score_team($team) as $row) {
|
foreach ($dao->get_score_team($team) as $row) {
|
||||||
// $text = $row['text'];
|
$text = $row['text'];
|
||||||
// $points = $row['points'];
|
$points = $row['points'];
|
||||||
// if ($points > 0)
|
if ($points > 0)
|
||||||
// $id = "positive";
|
$id = "positive";
|
||||||
// else
|
else
|
||||||
// $id = "negative";
|
$id = "negative";
|
||||||
// ?>
|
?>
|
||||||
<!-- <tr id="--><?//= $id ?><!--">-->
|
<tr id="<?= $id ?>">
|
||||||
<!-- <td>--><?//= htmlspecialchars($text) ?><!--</td>-->
|
<td><?= htmlspecialchars($text) ?></td>
|
||||||
<!-- <td>--><?//= $points ?><!--</td>-->
|
<td><?= $points ?></td>
|
||||||
<!-- </tr>-->
|
</tr>
|
||||||
<!-- --><?php
|
<?php
|
||||||
// }
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
|
@ -2,17 +2,16 @@
|
||||||
require_once 'classes/dao.php';
|
require_once 'classes/dao.php';
|
||||||
function get_total_points($team)
|
function get_total_points($team)
|
||||||
{
|
{
|
||||||
// $dao = new Dao('');
|
$dao = new Dao('');
|
||||||
$points = 0;
|
$points = 0;
|
||||||
// foreach ($dao->get_score_team($team) as $row) {
|
foreach ($dao->get_score_team($team) as $row) {
|
||||||
// $points += $row['points'];
|
$points += $row['points'];
|
||||||
// }
|
}
|
||||||
return $points;
|
return $points;
|
||||||
}
|
}
|
||||||
|
|
||||||
$scoreUSA = get_total_points('usa');
|
$scoreUSA = get_total_points('usa');
|
||||||
$scoreURSS = get_total_points('urss');
|
$scoreURSS = get_total_points('urss');
|
||||||
$pageMeta = "";
|
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
|
|
Loading…
Reference in a new issue