From c56f82ffd642352be15945fa0f535958babf4e78 Mon Sep 17 00:00:00 2001 From: Keplyx Date: Thu, 16 May 2019 07:28:02 +0200 Subject: [PATCH] Edited project for debug local use --- .htaccess | 11 +++++++ classes/dao.php | 69 +++++++++++++++++++++------------------ edit_score/urss/.htaccess | 8 ++--- edit_score/usa/.htaccess | 8 ++--- index.php | 8 ++--- sponsors.php | 13 -------- stats.php | 30 ++++++++--------- template.php | 9 +++-- 8 files changed, 79 insertions(+), 77 deletions(-) create mode 100644 .htaccess delete mode 100755 sponsors.php diff --git a/.htaccess b/.htaccess new file mode 100644 index 0000000..e7de07c --- /dev/null +++ b/.htaccess @@ -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] diff --git a/classes/dao.php b/classes/dao.php index ecacc0d..5cf98a6 100755 --- a/classes/dao.php +++ b/classes/dao.php @@ -1,56 +1,61 @@ read_password($path_to_password); - $dsn = 'mysql:dbname=accueil_insa;host=127.0.0.1'; + if ($this->debug) { + $username = 'phpmyadmin'; + $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 { $this->conn = new PDO($dsn, $username, $password, [PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8']); - } - catch (PDOException $e){ - $this->debug = true; + } catch (PDOException $e) { + echo $e; } } - private function read_password($path_to_password){ - $file = fopen($path_to_password."includes/.htpassdb", "r") or die("Unable to open file!");; + private function read_password($path_to_password) + { + 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); fclose($file); return $password; } - public function get_score_team($team){ - if (!$this->debug) - { - $sql = 'SELECT text, points FROM scores WHERE team = ?'; - $cursor = $this->conn->prepare($sql); - $cursor->execute([$team]); - return $cursor->fetchAll(PDO::FETCH_ASSOC); - } - else - return 0; + public function get_score_team($team) + { + $sql = 'SELECT text, points FROM scores WHERE team = ?'; + $cursor = $this->conn->prepare($sql); + $cursor->execute([$team]); + return $cursor->fetchAll(PDO::FETCH_ASSOC); } - public function save_scores($scores_json, $team){ - if (!$this->debug) - { - $sql = 'DELETE FROM scores WHERE team = ?'; - $cursor = $this->conn->prepare($sql); - $cursor->execute([$team]); + public function save_scores($scores_json, $team) + { + $sql = 'DELETE FROM scores WHERE team = ?'; + $cursor = $this->conn->prepare($sql); + $cursor->execute([$team]); - $array = json_decode($scores_json)->array; - foreach ($array as $value){ - $sql = 'INSERT INTO scores (text, points, team) VALUES (?, ?, ?)'; - $cursor = $this->conn->prepare($sql); - $cursor->execute([$value->text, $value->points, $team]); - } + $array = json_decode($scores_json)->array; + foreach ($array as $value) { + $sql = 'INSERT INTO scores (text, points, team) VALUES (?, ?, ?)'; + $cursor = $this->conn->prepare($sql); + $cursor->execute([$value->text, $value->points, $team]); } } diff --git a/edit_score/urss/.htaccess b/edit_score/urss/.htaccess index e831044..75f6483 100755 --- a/edit_score/urss/.htaccess +++ b/edit_score/urss/.htaccess @@ -1,4 +1,4 @@ -AuthName "Generals Only" -AuthType Basic -AuthUserFile /home_clubs/accueil_insa/public_html/includes/.htpassurss -require valid-user +#AuthName "Generals Only" +#AuthType Basic +#AuthUserFile /home_clubs/accueil_insa/public_html/includes/.htpassurss +#require valid-user diff --git a/edit_score/usa/.htaccess b/edit_score/usa/.htaccess index be7a90e..2088dbc 100755 --- a/edit_score/usa/.htaccess +++ b/edit_score/usa/.htaccess @@ -1,4 +1,4 @@ -AuthName "Generals Only" -AuthType Basic -AuthUserFile /home_clubs/accueil_insa/public_html/includes/.htpassusa -require valid-user +#AuthName "Generals Only" +#AuthType Basic +#AuthUserFile /home_clubs/accueil_insa/public_html/includes/.htpassusa +#require valid-user diff --git a/index.php b/index.php index cfa2bfe..97d83ff 100755 --- a/index.php +++ b/index.php @@ -2,11 +2,11 @@ require_once 'classes/dao.php'; function get_total_points($team) { -// $dao = new Dao(''); + $dao = new Dao(''); $points = 0; -// foreach ($dao->get_score_team($team) as $row) { -// $points += $row['points']; -// } + foreach ($dao->get_score_team($team) as $row) { + $points += $row['points']; + } return $points; } diff --git a/sponsors.php b/sponsors.php deleted file mode 100755 index 071911a..0000000 --- a/sponsors.php +++ /dev/null @@ -1,13 +0,0 @@ - -

Sponsors

-

- Apparemment on a des sponsors. -

- - diff --git a/stats.php b/stats.php index 3570623..f2ea84c 100755 --- a/stats.php +++ b/stats.php @@ -6,21 +6,21 @@ ob_start(); // Start reading html function get_stats($team) { -// $dao = new Dao(''); -// foreach ($dao->get_score_team($team) as $row) { -// $text = $row['text']; -// $points = $row['points']; -// if ($points > 0) -// $id = "positive"; -// else -// $id = "negative"; -// ?> - - - - -get_score_team($team) as $row) { + $text = $row['text']; + $points = $row['points']; + if ($points > 0) + $id = "positive"; + else + $id = "negative"; + ?> + + + + + diff --git a/template.php b/template.php index b8c0c37..c8b9fba 100755 --- a/template.php +++ b/template.php @@ -2,17 +2,16 @@ require_once 'classes/dao.php'; function get_total_points($team) { -// $dao = new Dao(''); + $dao = new Dao(''); $points = 0; -// foreach ($dao->get_score_team($team) as $row) { -// $points += $row['points']; -// } + foreach ($dao->get_score_team($team) as $row) { + $points += $row['points']; + } return $points; } $scoreUSA = get_total_points('usa'); $scoreURSS = get_total_points('urss'); -$pageMeta = ""; ?>