forked from vergnet/site-accueil-insa
Added online stats editor
This commit is contained in:
parent
00b67002b9
commit
c67af067b3
17 changed files with 463 additions and 78 deletions
|
@ -76,3 +76,115 @@
|
|||
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;
|
||||
}
|
53
classes/dao.php
Normal file
53
classes/dao.php
Normal file
|
@ -0,0 +1,53 @@
|
|||
<?php
|
||||
|
||||
class Dao {
|
||||
|
||||
private $conn;
|
||||
|
||||
public function __construct($path_to_password)
|
||||
{
|
||||
$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){
|
||||
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]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
1
edit_score/.htaccess
Normal file
1
edit_score/.htaccess
Normal file
|
@ -0,0 +1 @@
|
|||
Options -Indexes
|
114
edit_score/edit_template.php
Normal file
114
edit_score/edit_template.php
Normal file
|
@ -0,0 +1,114 @@
|
|||
<?php
|
||||
require_once '../../classes/dao.php';
|
||||
if (!isset($team))
|
||||
$team = 'usa';
|
||||
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="fr">
|
||||
<head>
|
||||
<meta charset='utf-8'>
|
||||
<meta http-equiv="X-UA-Compatible" content="chrome=1">
|
||||
<meta name="viewport" content="width=device-width,maximum-scale=2">
|
||||
<script defer src="https://use.fontawesome.com/releases/v5.0.13/js/all.js"></script>
|
||||
<link rel="stylesheet" type="text/css" media="screen" href="../../assets/css/style.css">
|
||||
<link rel="stylesheet" type="text/css" media="screen" href="../../assets/css/sidenav.css">
|
||||
<link rel="stylesheet" type="text/css" media="screen" href="../../assets/css/score.css">
|
||||
<link rel="stylesheet" type="text/css" media="screen" href="../../assets/css/hamburger.css">
|
||||
<link rel="stylesheet" type="text/css" media="screen" href="../../assets/css/stats.css"/>
|
||||
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/hammer.js/2.0.8/hammer.js"></script>
|
||||
<script src="../statsManager.js"></script>
|
||||
<link href="https://fonts.googleapis.com/css?family=Montserrat|Raleway|Russo+One" rel="stylesheet">
|
||||
<link rel="shortcut icon" href="../favicon.ico">
|
||||
<title>Score <?= strtoupper($team) ?> | ADMIN | INSAT Accueil 2018</title>
|
||||
<?= $pageMeta // Additional metadata ?>
|
||||
<!-- Matomo -->
|
||||
<script type="text/javascript">
|
||||
var _paq = _paq || [];
|
||||
/* tracker methods like "setCustomDimension" should be called before "trackPageView" */
|
||||
_paq.push(['disableCookies']);
|
||||
_paq.push(['trackPageView']);
|
||||
_paq.push(['enableLinkTracking']);
|
||||
(function () {
|
||||
var u = "//etud.insa-toulouse.fr/~accueil_insa/analytics/";
|
||||
_paq.push(['setTrackerUrl', u + 'piwik.php']);
|
||||
_paq.push(['setSiteId', '1']);
|
||||
var d = document, g = d.createElement('script'), s = d.getElementsByTagName('script')[0];
|
||||
g.type = 'text/javascript';
|
||||
g.async = true;
|
||||
g.defer = true;
|
||||
g.src = u + 'piwik.js';
|
||||
s.parentNode.insertBefore(g, s);
|
||||
})();
|
||||
</script>
|
||||
<!-- End Matomo Code -->
|
||||
</head>
|
||||
<body id="main">
|
||||
<div class="background"></div>
|
||||
|
||||
<div id="header-wrap" class="outer">
|
||||
<header class="inner">
|
||||
<h1 id="title">Administration</h1>
|
||||
</header>
|
||||
</div>
|
||||
<div class="stats-button-container">
|
||||
<a href="../../stats.php" class="stats-button">
|
||||
Retour sur le site
|
||||
</a>
|
||||
</div>
|
||||
<div id="main-fading-top-edge"></div>
|
||||
<div id="main-content-wrap" class="outer">
|
||||
<section id="main-content" class="inner">
|
||||
<h1>Editer Score <?= strtoupper($team) ?></h1>
|
||||
<p>
|
||||
<?= $description ?>
|
||||
</p>
|
||||
<table class="stats-table edit-stats" id="stats-<?= $team ?>">
|
||||
<tr>
|
||||
<th colspan="3"><?= strtoupper($team) ?></th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="stat-log">Log</td>
|
||||
<td class="stat-points">Points</td>
|
||||
<td class="stat-points"><i class='fas fa-trash'></i></td>
|
||||
</tr>
|
||||
<?php get_stats($team) ?>
|
||||
</table>
|
||||
|
||||
<div class="add-line" id="add-line-<?= $team ?>">
|
||||
<i class="fas fa-plus"></i>
|
||||
</div>
|
||||
|
||||
<div class="save-score">
|
||||
<i class="fas fa-save"></i> Enregistrer
|
||||
</div>
|
||||
<br>
|
||||
<div class="stats-button-container">
|
||||
<a href="../../stats.php" class="stats-button">
|
||||
Retour sur le site
|
||||
</a>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
<div id="main-fading-bottom-edge"></div>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
<?php
|
||||
|
||||
function get_stats($team)
|
||||
{
|
||||
$dao = new Dao('../../');
|
||||
foreach ($dao->get_score_team($team) as $row) {
|
||||
$text = $row['text'];
|
||||
$points = $row['points'];
|
||||
?>
|
||||
<tr class="entry">
|
||||
<td class><input type='text' value="<?= $text ?>"/></td>
|
||||
<td><input type='number' value="<?= $points ?>"/></td>
|
||||
<td class='remove-line'><i class="fas fa-trash"></td>
|
||||
</tr>
|
||||
<?php
|
||||
}
|
||||
}
|
45
edit_score/statsManager.js
Normal file
45
edit_score/statsManager.js
Normal file
|
@ -0,0 +1,45 @@
|
|||
$(document).ready(function () {
|
||||
$(".add-line").click(function () {
|
||||
$(".stats-table")
|
||||
.append("<tr class='entry'>" +
|
||||
"<td>" +
|
||||
"<input type='text' value='text''></td>" +
|
||||
"<td><input type='number' value='0'></td>" +
|
||||
"<td class='remove-line'>" +
|
||||
"<i class='fas fa-trash'></i>" +
|
||||
"</td>" +
|
||||
"</tr>");
|
||||
});
|
||||
$(".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;
|
||||
}
|
4
edit_score/urss/.htaccess
Normal file
4
edit_score/urss/.htaccess
Normal file
|
@ -0,0 +1,4 @@
|
|||
AuthName "Generals Only"
|
||||
AuthType Basic
|
||||
AuthUserFile /home_clubs/accueil_insa/public_html/includes/.htpassurss
|
||||
require valid-user
|
7
edit_score/urss/edit.php
Normal file
7
edit_score/urss/edit.php
Normal file
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
$description = 'Whoa t\'es admin ! Ici tu peux éditer le score pour les rouges, mais essaie de pas abuser sur les points stp.';
|
||||
$team = 'urss';
|
||||
include '../edit_template.php'; // Display template with variable content
|
||||
|
||||
|
||||
|
6
edit_score/urss/post_scores.php
Normal file
6
edit_score/urss/post_scores.php
Normal file
|
@ -0,0 +1,6 @@
|
|||
<?php
|
||||
require_once '../../classes/dao.php';
|
||||
|
||||
$dao = new Dao('../../');
|
||||
$dao->save_scores($_POST['data'], 'urss');
|
||||
|
4
edit_score/usa/.htaccess
Normal file
4
edit_score/usa/.htaccess
Normal file
|
@ -0,0 +1,4 @@
|
|||
AuthName "Generals Only"
|
||||
AuthType Basic
|
||||
AuthUserFile /home_clubs/accueil_insa/public_html/includes/.htpassusa
|
||||
require valid-user
|
7
edit_score/usa/edit.php
Normal file
7
edit_score/usa/edit.php
Normal file
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
$description = 'Whoa t\'es admin ! Ici tu peux éditer le score pour les riquains, mais essaie de pas abuser sur les points stp.';
|
||||
$team = 'usa';
|
||||
include '../edit_template.php'; // Display template with variable content
|
||||
|
||||
|
||||
|
6
edit_score/usa/post_scores.php
Normal file
6
edit_score/usa/post_scores.php
Normal file
|
@ -0,0 +1,6 @@
|
|||
<?php
|
||||
require_once '../../classes/dao.php';
|
||||
|
||||
$dao = new Dao('../../');
|
||||
$dao->save_scores($_POST['data'], 'usa');
|
||||
|
1
includes/.htpassurss
Normal file
1
includes/.htpassurss
Normal file
|
@ -0,0 +1 @@
|
|||
urss:$apr1$be3lzprv$6ML9yz0HALe/oI9DRKEaw0
|
1
includes/.htpassusa
Normal file
1
includes/.htpassusa
Normal file
|
@ -0,0 +1 @@
|
|||
usa:$apr1$53morzy0$GxlXNPAdPtiin1/7/xQo4/
|
|
@ -1,15 +1,11 @@
|
|||
<?php
|
||||
|
||||
function get_total_points($is_urss)
|
||||
require_once 'classes/dao.php';
|
||||
function get_total_points($team)
|
||||
{
|
||||
$json_source = file_get_contents('https://raw.githubusercontent.com/Keplyx/site-accueil-insa/master/historique.json');
|
||||
$json_data = json_decode($json_source, true);
|
||||
$root = "usa";
|
||||
if ($is_urss)
|
||||
$root = "urss";
|
||||
$dao = new Dao('');
|
||||
$points = 0;
|
||||
foreach ($json_data[$root] as $v) {
|
||||
$points += $v['points'];
|
||||
foreach ($dao->get_score_team($team) as $row) {
|
||||
$points += $row['points'];
|
||||
}
|
||||
return $points;
|
||||
}
|
||||
|
@ -23,9 +19,9 @@ function get_total_points($is_urss)
|
|||
<img class="score-logo" src="assets/images/usa_logo.png">
|
||||
</a>
|
||||
<a href="stats.php">
|
||||
<div id="score-usa"><?php echo get_total_points(false) ?></div>
|
||||
<div id="score-usa"><?= get_total_points('usa') ?></div>
|
||||
<div id="score-separator">/</div>
|
||||
<div id="score-urss"><?php echo get_total_points(true) ?></div>
|
||||
<div id="score-urss"><?= get_total_points('urss') ?></div>
|
||||
</a>
|
||||
<a href="urss.php">
|
||||
<img class="score-logo" src="assets/images/urss_logo.png">
|
||||
|
|
9
schema.sql
Normal file
9
schema.sql
Normal file
|
@ -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;
|
51
stats.php
51
stats.php
|
@ -1,20 +1,25 @@
|
|||
<?php
|
||||
require_once 'classes/dao.php';
|
||||
|
||||
ob_start(); // Start reading html
|
||||
|
||||
function get_stats($is_urss){
|
||||
$json_source = file_get_contents('https://raw.githubusercontent.com/Keplyx/site-accueil-insa/master/historique.json');
|
||||
$json_data = json_decode($json_source, true);
|
||||
$root = "usa";
|
||||
if ($is_urss)
|
||||
$root = "urss";
|
||||
foreach($json_data[$root] as $v){
|
||||
if ($v['points'] > 0)
|
||||
echo "<tr id='positive'>";
|
||||
|
||||
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 "<tr id='negative'>";
|
||||
echo "<td>".$v['text']."</td>";
|
||||
echo "<td>".$v['points']."</td>";
|
||||
echo "</tr>";
|
||||
$id = "negative";
|
||||
?>
|
||||
<tr id="<?= $id ?>">
|
||||
<td><?= $text ?></td>
|
||||
<td><?= $points ?></td>
|
||||
</tr>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -25,8 +30,16 @@ function get_stats($is_urss){
|
|||
<br>
|
||||
Remporte le plus de points possible pour faire gagner ton équipe, mais attention à ne pas lui en faire perdre !
|
||||
</p>
|
||||
|
||||
<div id="stats-container">
|
||||
<table class="stats-table" id="stats-usa">
|
||||
<tr>
|
||||
<td colspan="2" class="edit-button-container">
|
||||
<a href="edit_score/usa/edit.php" class="edit-button" id="button-usa">
|
||||
Éditer les scores
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th colspan="2">USA</th>
|
||||
</tr>
|
||||
|
@ -34,9 +47,16 @@ function get_stats($is_urss){
|
|||
<td class="stat-log">Log</td>
|
||||
<td class="stat-points">Points</td>
|
||||
</tr>
|
||||
<?php get_stats(false) ?>
|
||||
<?php get_stats('usa') ?>
|
||||
</table>
|
||||
<table class="stats-table" id="stats-urss">
|
||||
<tr>
|
||||
<td colspan="2" class="edit-button-container">
|
||||
<a href="edit_score/urss/edit.php" class="edit-button" id="button-urss">
|
||||
Éditer les scores
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th colspan="2">URSS</th>
|
||||
</tr>
|
||||
|
@ -44,7 +64,7 @@ function get_stats($is_urss){
|
|||
<td class="stat-log">Log</td>
|
||||
<td class="stat-points">Points</td>
|
||||
</tr>
|
||||
<?php get_stats(true) ?>
|
||||
<?php get_stats('urss') ?>
|
||||
</table>
|
||||
</div>
|
||||
<?php
|
||||
|
@ -56,4 +76,3 @@ ob_start(); // Start reading html
|
|||
<?php
|
||||
$pageMeta = ob_get_clean(); // Store html content in variable
|
||||
include("template.php"); // Display template with variable content
|
||||
?>
|
Loading…
Reference in a new issue