1
0
mirror of https://gitlab.com/animath/si/plateforme-corres2math.git synced 2024-12-25 18:22:21 +00:00
plateforme-corres2math/server_files/config.php

205 lines
5.3 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;
private $index_page;
public function initDB()
{
global $DB, $LOCAL_PATH;
$index_template_page = htmlspecialchars(file_get_contents($LOCAL_PATH . "/server_files/views/index.html"));
$DB->exec("SET GLOBAL time_zone = 'Europe/Paris';");
$DB->prepare("INSERT IGNORE INTO `config` VALUES ('inscription_date', CURRENT_TIMESTAMP + INTERVAL 2 DAY),
('start_phase1_date', CURRENT_TIMESTAMP + INTERVAL 1 DAY), ('end_phase1_date', CURRENT_TIMESTAMP + INTERVAL 3 DAY),
('start_phase2_date', CURRENT_TIMESTAMP + INTERVAL 4 DAY), ('end_phase2_date', CURRENT_TIMESTAMP + INTERVAL 5 DAY),
('start_phase3_date', CURRENT_TIMESTAMP + INTERVAL 6 DAY), ('end_phase3_date', CURRENT_TIMESTAMP + INTERVAL 7 DAY),
('start_phase4_date', CURRENT_TIMESTAMP + INTERVAL 8 DAY), ('end_phase4_date', CURRENT_TIMESTAMP + INTERVAL 9 DAY),
('index_page', ?);")->execute([$index_template_page]);
}
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;
}
public function getIndexPage()
{
return $this->index_page;
}
public function setIndexPage($index_page)
{
global $DB;
$DB->prepare("UPDATE `config` SET `value` = ? WHERE `key` = 'index_page';")->execute([$index_page]);
$this->index_page = $index_page;
}
}
session_start();
setlocale(LC_ALL, "fr_FR.utf8");
date_default_timezone_set("Europe/Paris");