2019-09-09 23:48:52 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Config options
|
|
|
|
*/
|
|
|
|
|
2019-09-23 22:20:35 +00:00
|
|
|
$YEAR = getenv("CORRES2MATH_YEAR");
|
|
|
|
$URL_BASE = getenv("CORRES2MATH_URL_BASE");
|
|
|
|
$LOCAL_PATH = getenv("CORRES2MATH_LOCAL_PATH");
|
|
|
|
$MAIL_DOMAIN = getenv("CORRES2MATH_MAIL_DOMAIN");
|
2019-09-09 23:48:52 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* DB infos
|
|
|
|
*/
|
|
|
|
|
2019-09-23 22:20:35 +00:00
|
|
|
$DB_HOST = getenv("CORRES2MATH_DB_HOST");
|
|
|
|
$DB_NAME = getenv("CORRES2MATH_DB_NAME");
|
|
|
|
$DB_USER = getenv("CORRES2MATH_DB_USER");
|
|
|
|
$DB_PASSWORD = getenv("CORRES2MATH_DB_PASSWORD");
|
2019-09-09 23:48:52 +00:00
|
|
|
|
|
|
|
try {
|
|
|
|
$DB = new PDO("mysql:host=$DB_HOST;dbname=$DB_NAME;charset=utf8", "$DB_USER", "$DB_PASSWORD", array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
|
|
|
|
}
|
|
|
|
catch (Exception $ex) {
|
|
|
|
die("Erreur lors de la connexion à la base de données : " . $ex->getMessage());
|
|
|
|
}
|
|
|
|
|
2019-09-12 10:18:15 +00:00
|
|
|
$CONFIG = new Config();
|
|
|
|
$CONFIG->initDB();
|
|
|
|
$CONFIG->loadConfigValues();
|
|
|
|
|
|
|
|
class Config
|
|
|
|
{
|
|
|
|
private $inscription_date;
|
|
|
|
private $start_phase1_date;
|
|
|
|
private $end_phase1_date;
|
|
|
|
private $start_phase2_date;
|
|
|
|
private $end_phase2_date;
|
|
|
|
private $start_phase3_date;
|
|
|
|
private $end_phase3_date;
|
|
|
|
private $start_phase4_date;
|
|
|
|
private $end_phase4_date;
|
2019-10-16 22:35:06 +00:00
|
|
|
private $index_page;
|
2019-09-12 10:18:15 +00:00
|
|
|
|
|
|
|
public function initDB()
|
|
|
|
{
|
2019-10-22 12:55:33 +00:00
|
|
|
global $DB, $LOCAL_PATH, $YEAR;
|
2019-10-16 22:35:06 +00:00
|
|
|
|
|
|
|
$index_template_page = htmlspecialchars(file_get_contents($LOCAL_PATH . "/server_files/views/index.html"));
|
2019-09-12 10:18:15 +00:00
|
|
|
|
|
|
|
$DB->exec("SET GLOBAL time_zone = 'Europe/Paris';");
|
2019-10-22 12:55:33 +00:00
|
|
|
$DB->prepare("INSERT IGNORE INTO `config`(`key`, `value`)
|
|
|
|
VALUES ('inscription_date_$YEAR', CURRENT_TIMESTAMP + INTERVAL 2 DAY),
|
|
|
|
('start_phase1_date_$YEAR', CURRENT_TIMESTAMP + INTERVAL 1 DAY),
|
|
|
|
('end_phase1_date_$YEAR', CURRENT_TIMESTAMP + INTERVAL 3 DAY),
|
|
|
|
('start_phase2_date_$YEAR', CURRENT_TIMESTAMP + INTERVAL 4 DAY),
|
|
|
|
('end_phase2_date_$YEAR', CURRENT_TIMESTAMP + INTERVAL 5 DAY),
|
|
|
|
('start_phase3_date_$YEAR', CURRENT_TIMESTAMP + INTERVAL 6 DAY),
|
|
|
|
('end_phase3_date_$YEAR', CURRENT_TIMESTAMP + INTERVAL 7 DAY),
|
|
|
|
('start_phase4_date_$YEAR', CURRENT_TIMESTAMP + INTERVAL 8 DAY),
|
|
|
|
('end_phase4_date_$YEAR', CURRENT_TIMESTAMP + INTERVAL 9 DAY),
|
|
|
|
('index_page_$YEAR', ?);")->execute([$index_template_page]);
|
2019-09-12 10:18:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function loadConfigValues()
|
|
|
|
{
|
2019-10-22 12:55:33 +00:00
|
|
|
global $DB, $YEAR;
|
2019-09-12 10:18:15 +00:00
|
|
|
|
2019-10-22 12:55:33 +00:00
|
|
|
$req = $DB->query("SELECT * FROM `config` WHERE `key` REGEXP '$YEAR';");
|
2019-09-12 10:18:15 +00:00
|
|
|
|
|
|
|
while (($data = $req->fetch()) !== false) {
|
2019-10-22 12:55:33 +00:00
|
|
|
$key = substr($data["key"], 0, -5);
|
2019-09-12 10:18:15 +00:00
|
|
|
$this->$key = $data["value"];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getInscriptionDate()
|
|
|
|
{
|
|
|
|
return $this->inscription_date;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setInscriptionDate($inscription_date)
|
|
|
|
{
|
2019-10-22 12:55:33 +00:00
|
|
|
global $DB, $YEAR;
|
|
|
|
$DB->exec("UPDATE `config` SET `value` = '$inscription_date' WHERE `key` = 'inscription_date_$YEAR'");
|
2019-09-12 10:18:15 +00:00
|
|
|
|
|
|
|
$this->inscription_date = $inscription_date;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getStartPhase1Date()
|
|
|
|
{
|
|
|
|
return $this->start_phase1_date;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setStartPhase1Date($start_phase1_date)
|
|
|
|
{
|
2019-10-22 12:55:33 +00:00
|
|
|
global $DB, $YEAR;
|
|
|
|
$DB->exec("UPDATE `config` SET `value` = '$start_phase1_date' WHERE `key` = 'start_phase1_date_$YEAR'");
|
2019-09-12 10:18:15 +00:00
|
|
|
|
|
|
|
$this->start_phase1_date = $start_phase1_date;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getEndPhase1Date()
|
|
|
|
{
|
|
|
|
return $this->end_phase1_date;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setEndPhase1Date($end_phase1_date)
|
|
|
|
{
|
2019-10-22 12:55:33 +00:00
|
|
|
global $DB, $YEAR;
|
|
|
|
$DB->exec("UPDATE `config` SET `value` = '$end_phase1_date' WHERE `key` = 'end_phase1_date_$YEAR'");
|
2019-09-12 10:18:15 +00:00
|
|
|
|
|
|
|
$this->end_phase1_date = $end_phase1_date;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getStartPhase2Date()
|
|
|
|
{
|
|
|
|
return $this->start_phase2_date;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setStartPhase2Date($start_phase2_date)
|
|
|
|
{
|
2019-10-22 12:55:33 +00:00
|
|
|
global $DB, $YEAR;
|
|
|
|
$DB->exec("UPDATE `config` SET `value` = '$start_phase2_date' WHERE `key` = 'start_phase2_date_$YEAR'");
|
2019-09-12 10:18:15 +00:00
|
|
|
|
|
|
|
$this->start_phase2_date = $start_phase2_date;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getEndPhase2Date()
|
|
|
|
{
|
|
|
|
return $this->end_phase2_date;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setEndPhase2Date($end_phase2_date)
|
|
|
|
{
|
2019-10-22 12:55:33 +00:00
|
|
|
global $DB, $YEAR;
|
|
|
|
$DB->exec("UPDATE `config` SET `value` = '$end_phase2_date' WHERE `key` = 'end_phase2_date_$YEAR'");
|
2019-09-12 10:18:15 +00:00
|
|
|
|
|
|
|
$this->end_phase2_date = $end_phase2_date;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getStartPhase3Date()
|
|
|
|
{
|
|
|
|
return $this->start_phase3_date;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setStartPhase3Date($start_phase3_date)
|
|
|
|
{
|
2019-10-22 12:55:33 +00:00
|
|
|
global $DB, $YEAR;
|
|
|
|
$DB->exec("UPDATE `config` SET `value` = '$start_phase3_date' WHERE `key` = 'start_phase3_date_$YEAR'");
|
2019-09-12 10:18:15 +00:00
|
|
|
|
|
|
|
$this->start_phase3_date = $start_phase3_date;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getEndPhase3Date()
|
|
|
|
{
|
|
|
|
return $this->end_phase3_date;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setEndPhase3Date($end_phase3_date)
|
|
|
|
{
|
2019-10-22 12:55:33 +00:00
|
|
|
global $DB, $YEAR;
|
|
|
|
$DB->exec("UPDATE `config` SET `value` = '$end_phase3_date' WHERE `key` = 'end_phase3_date_$YEAR'");
|
2019-09-12 10:18:15 +00:00
|
|
|
|
|
|
|
$this->end_phase3_date = $end_phase3_date;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getStartPhase4Date()
|
|
|
|
{
|
|
|
|
return $this->start_phase4_date;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setStartPhase4Date($start_phase4_date)
|
|
|
|
{
|
2019-10-22 12:55:33 +00:00
|
|
|
global $DB, $YEAR;
|
|
|
|
$DB->exec("UPDATE `config` SET `value` = '$start_phase4_date' WHERE `key` = 'start_phase4_date_$YEAR'");
|
2019-09-12 10:18:15 +00:00
|
|
|
|
|
|
|
$this->start_phase4_date = $start_phase4_date;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getEndPhase4Date()
|
|
|
|
{
|
|
|
|
return $this->end_phase4_date;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setEndPhase4Date($end_phase4_date)
|
|
|
|
{
|
2019-10-22 12:55:33 +00:00
|
|
|
global $DB, $YEAR;
|
|
|
|
$DB->exec("UPDATE `config` SET `value` = '$end_phase4_date' WHERE `key` = 'end_phase4_date_$YEAR'");
|
2019-09-12 10:18:15 +00:00
|
|
|
|
|
|
|
$this->end_phase4_date = $end_phase4_date;
|
|
|
|
}
|
2019-10-16 22:35:06 +00:00
|
|
|
|
|
|
|
public function getIndexPage()
|
|
|
|
{
|
|
|
|
return $this->index_page;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setIndexPage($index_page)
|
|
|
|
{
|
2019-10-22 12:55:33 +00:00
|
|
|
global $DB, $YEAR;
|
|
|
|
$DB->prepare("UPDATE `config` SET `value` = ? WHERE `key` = 'index_page_$YEAR'")->execute([$index_page]);
|
2019-10-16 22:35:06 +00:00
|
|
|
|
|
|
|
$this->index_page = $index_page;
|
|
|
|
}
|
2019-09-12 10:18:15 +00:00
|
|
|
}
|
|
|
|
|
2019-09-09 23:48:52 +00:00
|
|
|
session_start();
|
|
|
|
setlocale(LC_ALL, "fr_FR.utf8");
|
2019-09-12 10:18:15 +00:00
|
|
|
date_default_timezone_set("Europe/Paris");
|