187 lines
4.6 KiB
PHP
187 lines
4.6 KiB
PHP
<?php
|
|
/**
|
|
* Config options
|
|
*/
|
|
|
|
$YEAR = getenv("CORRES2MATH_YEAR");
|
|
$URL_BASE = getenv("CORRES2MATH_URL_BASE");
|
|
$LOCAL_PATH = getenv("CORRES2MATH_LOCAL_PATH");
|
|
$MAIL_DOMAIN = getenv("CORRES2MATH_MAIL_DOMAIN");
|
|
|
|
/**
|
|
* DB infos
|
|
*/
|
|
|
|
$DB_HOST = getenv("CORRES2MATH_DB_HOST");
|
|
$DB_NAME = getenv("CORRES2MATH_DB_NAME");
|
|
$DB_USER = getenv("CORRES2MATH_DB_USER");
|
|
$DB_PASSWORD = getenv("CORRES2MATH_DB_PASSWORD");
|
|
|
|
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());
|
|
}
|
|
|
|
$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;
|
|
|
|
public function initDB()
|
|
{
|
|
global $DB;
|
|
|
|
$DB->exec("SET GLOBAL time_zone = 'Europe/Paris';");
|
|
$DB->exec("INSERT IGNORE INTO `config` VALUES ('inscription_date', CURRENT_TIMESTAMP), ('start_phase1_date', CURRENT_TIMESTAMP), ('end_phase1_date', CURRENT_TIMESTAMP),
|
|
('start_phase2_date', CURRENT_TIMESTAMP), ('end_phase2_date', CURRENT_TIMESTAMP),
|
|
('start_phase3_date', CURRENT_TIMESTAMP), ('end_phase3_date', CURRENT_TIMESTAMP),
|
|
('start_phase4_date', CURRENT_TIMESTAMP), ('end_phase4_date', CURRENT_TIMESTAMP);");
|
|
}
|
|
|
|
public function loadConfigValues()
|
|
{
|
|
global $DB;
|
|
|
|
$req = $DB->query("SELECT * FROM `config`;");
|
|
|
|
while (($data = $req->fetch()) !== false) {
|
|
$key = $data["key"];
|
|
$this->$key = $data["value"];
|
|
}
|
|
}
|
|
|
|
public function getInscriptionDate()
|
|
{
|
|
return $this->inscription_date;
|
|
}
|
|
|
|
public function setInscriptionDate($inscription_date)
|
|
{
|
|
global $DB;
|
|
$DB->exec("UPDATE `config` SET `value` = '$inscription_date' WHERE `key` = 'inscription_date';");
|
|
|
|
$this->inscription_date = $inscription_date;
|
|
}
|
|
|
|
public function getStartPhase1Date()
|
|
{
|
|
return $this->start_phase1_date;
|
|
}
|
|
|
|
public function setStartPhase1Date($start_phase1_date)
|
|
{
|
|
global $DB;
|
|
$DB->exec("UPDATE `config` SET `value` = '$start_phase1_date' WHERE `key` = 'start_phase1_date';");
|
|
|
|
$this->start_phase1_date = $start_phase1_date;
|
|
}
|
|
|
|
public function getEndPhase1Date()
|
|
{
|
|
return $this->end_phase1_date;
|
|
}
|
|
|
|
public function setEndPhase1Date($end_phase1_date)
|
|
{
|
|
global $DB;
|
|
$DB->exec("UPDATE `config` SET `value` = '$end_phase1_date' WHERE `key` = 'end_phase1_date';");
|
|
|
|
$this->end_phase1_date = $end_phase1_date;
|
|
}
|
|
|
|
public function getStartPhase2Date()
|
|
{
|
|
return $this->start_phase2_date;
|
|
}
|
|
|
|
public function setStartPhase2Date($start_phase2_date)
|
|
{
|
|
global $DB;
|
|
$DB->exec("UPDATE `config` SET `value` = '$start_phase2_date' WHERE `key` = 'start_phase2_date';");
|
|
|
|
$this->start_phase2_date = $start_phase2_date;
|
|
}
|
|
|
|
public function getEndPhase2Date()
|
|
{
|
|
return $this->end_phase2_date;
|
|
}
|
|
|
|
public function setEndPhase2Date($end_phase2_date)
|
|
{
|
|
global $DB;
|
|
$DB->exec("UPDATE `config` SET `value` = '$end_phase2_date' WHERE `key` = 'end_phase2_date';");
|
|
|
|
$this->end_phase2_date = $end_phase2_date;
|
|
}
|
|
|
|
public function getStartPhase3Date()
|
|
{
|
|
return $this->start_phase3_date;
|
|
}
|
|
|
|
public function setStartPhase3Date($start_phase3_date)
|
|
{
|
|
global $DB;
|
|
$DB->exec("UPDATE `config` SET `value` = '$start_phase3_date' WHERE `key` = 'start_phase3_date';");
|
|
|
|
$this->start_phase3_date = $start_phase3_date;
|
|
}
|
|
|
|
public function getEndPhase3Date()
|
|
{
|
|
return $this->end_phase3_date;
|
|
}
|
|
|
|
public function setEndPhase3Date($end_phase3_date)
|
|
{
|
|
global $DB;
|
|
$DB->exec("UPDATE `config` SET `value` = '$end_phase3_date' WHERE `key` = 'end_phase3_date';");
|
|
|
|
$this->end_phase3_date = $end_phase3_date;
|
|
}
|
|
|
|
public function getStartPhase4Date()
|
|
{
|
|
return $this->start_phase4_date;
|
|
}
|
|
|
|
public function setStartPhase4Date($start_phase4_date)
|
|
{
|
|
global $DB;
|
|
$DB->exec("UPDATE `config` SET `value` = '$start_phase4_date' WHERE `key` = 'start_phase4_date';");
|
|
|
|
$this->start_phase4_date = $start_phase4_date;
|
|
}
|
|
|
|
public function getEndPhase4Date()
|
|
{
|
|
return $this->end_phase4_date;
|
|
}
|
|
|
|
public function setEndPhase4Date($end_phase4_date)
|
|
{
|
|
global $DB;
|
|
$DB->exec("UPDATE `config` SET `value` = '$end_phase4_date' WHERE `key` = 'end_phase4_date';");
|
|
|
|
$this->end_phase4_date = $end_phase4_date;
|
|
}
|
|
}
|
|
|
|
session_start();
|
|
setlocale(LC_ALL, "fr_FR.utf8");
|
|
date_default_timezone_set("Europe/Paris");
|