From c67af067b3ec144cd558540176064e9b78d82287 Mon Sep 17 00:00:00 2001 From: Keplyx Date: Fri, 15 Jun 2018 09:33:29 +0200 Subject: [PATCH] Added online stats editor --- assets/css/stats.css | 112 +++++++++++++++++++++++++++++++ classes/dao.php | 53 +++++++++++++++ edit_score/.htaccess | 1 + edit_score/edit_template.php | 114 ++++++++++++++++++++++++++++++++ edit_score/statsManager.js | 45 +++++++++++++ edit_score/urss/.htaccess | 4 ++ edit_score/urss/edit.php | 7 ++ edit_score/urss/post_scores.php | 6 ++ edit_score/usa/.htaccess | 4 ++ edit_score/usa/edit.php | 7 ++ edit_score/usa/post_scores.php | 6 ++ includes/.htpassurss | 1 + includes/.htpassusa | 1 + includes/score_counter.php | 18 ++--- schema.sql | 9 +++ stats.php | 103 +++++++++++++++++------------ usa.php | 50 +++++++------- 17 files changed, 463 insertions(+), 78 deletions(-) create mode 100644 classes/dao.php create mode 100644 edit_score/.htaccess create mode 100644 edit_score/edit_template.php create mode 100644 edit_score/statsManager.js create mode 100644 edit_score/urss/.htaccess create mode 100644 edit_score/urss/edit.php create mode 100644 edit_score/urss/post_scores.php create mode 100644 edit_score/usa/.htaccess create mode 100644 edit_score/usa/edit.php create mode 100644 edit_score/usa/post_scores.php create mode 100644 includes/.htpassurss create mode 100644 includes/.htpassusa create mode 100644 schema.sql diff --git a/assets/css/stats.css b/assets/css/stats.css index f0b0937..8ff3d49 100644 --- a/assets/css/stats.css +++ b/assets/css/stats.css @@ -75,4 +75,116 @@ .stats-table { width: 100%; } +} + +.edit-button-container { + border: none; +} + +.edit-button { + width: auto; + background: #fafafa; + color: #000; + border-radius: 5px; + padding: 5px; + box-shadow: 0 0 5px #000000; +} + +.edit-button:hover { + color: #fafafa; +} + +#button-urss:hover { + background: #ee293d; +} + +#button-usa:hover { + background: #1a5dad; +} + +.stats-button-container { + display: inline-flex; +} + +.stats-button { + width: auto; + background: #fafafa; + color: #000; + border-radius: 5px; + padding: 15px; + box-shadow: 0 0 5px #000000; +} + +.stats-button:hover { + color: #fafafa; + background: #1a1a1a; +} + +.edit-stats { + width: 100%; +} + +input { + text-align: center; + background: #1a1a1a; + color: #fafafa; + width: 100%; + border: none; + font-family: inherit; + font-size: inherit; +} + +.remove-line { + color: #ff1200; + cursor: pointer; + transition: 0.3s; +} + +.remove-line svg { + pointer-events: none; +} + +.remove-line:hover { + color: #ff4000; +} + +.add-line{ + font-size: 30px; + color: #fafafa; + cursor: pointer; + transition: 0.3s; + margin: 1% 1% 1% 1%; + width: 100%; + border-radius: 5px; +} + +#add-line-usa { + background: #3a7eaa; +} + +.add-line#add-line-usa:hover { + background: #53bbfc; +} + +#add-line-urss { + background: #d72229; +} + +.add-line#add-line-urss:hover { + background: #ee293d; +} + +.save-score { + background: #21aa08; + font-size: 30px; + color: #fafafa; + cursor: pointer; + transition: 0.3s; + margin: 30px 1% 1% 1%; + width: 100%; + border-radius: 5px; +} + +.save-score:hover { + background: #2ce20b; } \ No newline at end of file diff --git a/classes/dao.php b/classes/dao.php new file mode 100644 index 0000000..01b5279 --- /dev/null +++ b/classes/dao.php @@ -0,0 +1,53 @@ +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){ + die($e->getMessage()); + } + } + + private function read_password($path_to_password){ + $file = fopen($path_to_password."includes/.htpassdb", "r") or die("Unable to open file!");; + $password = fgets($file); + fclose($file); + return $password; + } + + 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){ +// var_dump($scores_json); +// var_dump($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]); + } + + } + +} + + + diff --git a/edit_score/.htaccess b/edit_score/.htaccess new file mode 100644 index 0000000..5a928f6 --- /dev/null +++ b/edit_score/.htaccess @@ -0,0 +1 @@ +Options -Indexes diff --git a/edit_score/edit_template.php b/edit_score/edit_template.php new file mode 100644 index 0000000..2114095 --- /dev/null +++ b/edit_score/edit_template.php @@ -0,0 +1,114 @@ + + + + + + + + + + + + + + + + + + + Score <?= strtoupper($team) ?> | ADMIN | INSAT Accueil 2018 + + + + + + +
+ +
+
+

Administration

+
+
+
+ + Retour sur le site + +
+
+
+
+

Editer Score

+

+ +

+ + + + + + + + + + +
LogPoints
+ +
+ +
+ +
+ Enregistrer +
+
+ +
+
+
+ + + +get_score_team($team) as $row) { + $text = $row['text']; + $points = $row['points']; + ?> + + + + + + " + + "" + + "" + + "" + + "" + + "" + + "" + + ""); + }); + $(".stats-table").on("click", ".remove-line", function (elem) { + $(elem.target).parent().remove(); + console.log("clicked") + }); + $(".save-score").click(function () { + let lines = get_lines(); + let object = {"array": lines}; + let ajaxurl = 'post_scores.php'; + let data = {'data': JSON.stringify(object)}; + $.post(ajaxurl, data, function (data, status) { + alert("\nStatus: " + status); + }); + }); +}); + +function get_lines() { + let elements = $(".entry").map(function () { + return this; + }).get(); + let array = []; + for (let i = 0; i < elements.length; i++) { + let fields = $(elements[i]).find('input'); + let values = {"text": "", "points": 0}; + for (let j = 0; j < fields.length; j++) { + if ($(fields[j]).attr("type") === "text") + values.text = $(fields[j]).prop("value"); + if ($(fields[j]).attr("type") === "number") + values.points = parseInt($(fields[j]).prop("value")); + } + array.push(values); + } + return array; +} \ No newline at end of file diff --git a/edit_score/urss/.htaccess b/edit_score/urss/.htaccess new file mode 100644 index 0000000..e831044 --- /dev/null +++ b/edit_score/urss/.htaccess @@ -0,0 +1,4 @@ +AuthName "Generals Only" +AuthType Basic +AuthUserFile /home_clubs/accueil_insa/public_html/includes/.htpassurss +require valid-user diff --git a/edit_score/urss/edit.php b/edit_score/urss/edit.php new file mode 100644 index 0000000..f323579 --- /dev/null +++ b/edit_score/urss/edit.php @@ -0,0 +1,7 @@ +save_scores($_POST['data'], 'urss'); + diff --git a/edit_score/usa/.htaccess b/edit_score/usa/.htaccess new file mode 100644 index 0000000..be7a90e --- /dev/null +++ b/edit_score/usa/.htaccess @@ -0,0 +1,4 @@ +AuthName "Generals Only" +AuthType Basic +AuthUserFile /home_clubs/accueil_insa/public_html/includes/.htpassusa +require valid-user diff --git a/edit_score/usa/edit.php b/edit_score/usa/edit.php new file mode 100644 index 0000000..5c32364 --- /dev/null +++ b/edit_score/usa/edit.php @@ -0,0 +1,7 @@ +save_scores($_POST['data'], 'usa'); + diff --git a/includes/.htpassurss b/includes/.htpassurss new file mode 100644 index 0000000..60433d8 --- /dev/null +++ b/includes/.htpassurss @@ -0,0 +1 @@ +urss:$apr1$be3lzprv$6ML9yz0HALe/oI9DRKEaw0 \ No newline at end of file diff --git a/includes/.htpassusa b/includes/.htpassusa new file mode 100644 index 0000000..d245213 --- /dev/null +++ b/includes/.htpassusa @@ -0,0 +1 @@ +usa:$apr1$53morzy0$GxlXNPAdPtiin1/7/xQo4/ \ No newline at end of file diff --git a/includes/score_counter.php b/includes/score_counter.php index fa48704..8fe99b9 100644 --- a/includes/score_counter.php +++ b/includes/score_counter.php @@ -1,15 +1,11 @@ get_score_team($team) as $row) { + $points += $row['points']; } return $points; } @@ -23,9 +19,9 @@ function get_total_points($is_urss) -
+
/
-
+
diff --git a/schema.sql b/schema.sql new file mode 100644 index 0000000..c96c80a --- /dev/null +++ b/schema.sql @@ -0,0 +1,9 @@ +drop table if exists scores; +create table scores( + `ID` bigint primary key auto_increment, + `text` text not null, + `points` int not null, + `team` varchar(4) not null +) + DEFAULT CHARACTER SET utf8 + COLLATE utf8_general_ci; \ No newline at end of file diff --git a/stats.php b/stats.php index 3512758..d91bb78 100644 --- a/stats.php +++ b/stats.php @@ -1,52 +1,72 @@ 0) - echo ""; + +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 - echo ""; - echo "".$v['text'].""; - echo "".$v['points'].""; - echo ""; + $id = "negative"; + ?> + + + + + -

Stats

-

- Les stats de la semaine. -
- Remporte le plus de points possible pour faire gagner ton équipe, mais attention à ne pas lui en faire perdre ! -

-
- - - - - - - - - -
USA
LogPoints
- - - - - - - - - -
URSS
LogPoints
-
+

Stats

+

+ Les stats de la semaine. +
+ Remporte le plus de points possible pour faire gagner ton équipe, mais attention à ne pas lui en faire perdre ! +

+ +
+ + + + + + + + + + + + +
+ + Éditer les scores + +
USA
LogPoints
+ + + + + + + + + + + + +
+ + Éditer les scores + +
URSS
LogPoints
+
\ No newline at end of file diff --git a/usa.php b/usa.php index fdbe316..4031b67 100644 --- a/usa.php +++ b/usa.php @@ -1,35 +1,35 @@ -

- Make INSA great again! -

-

- You have joined the greatest nation on the surface of the earth, and you will help us conquer outer space! As a - young patriot, your mission, if you choose to accept it, is to crush the Reds under the command of the most - competent General of the US! -

-

- Join the fight at Facebook, and ask to join the - special forces. -

-

- Here is your General -

- -
- - Music - - +

+ Make INSA great again! +

+

+ You have joined the greatest nation on the surface of the earth, and you will help us conquer outer space! As a + young patriot, your mission, if you choose to accept it, is to crush the Reds under the command of the most + competent General of the US! +

+

+ Join the fight at Facebook, and ask to join the + special forces. +

+

+ Here is your General +

+ +
+ + Music + + - Team USA | Semaine d'Accueil 2018 +Team USA | Semaine d'Accueil 2018