e59-website/include/functions.php
2024-03-13 22:24:54 +00:00

56 lines
1.5 KiB
PHP

<?php
session_start();
if(!isset($_SESSION['accreditation'])) {
$_SESSION['accreditation'] = 0;
}
if(!isset($_SESSION['role'])) {
$_SESSION['role'] = 0;
}
if(!isset($_COOKIE['theme'])) {
setcookie('theme', 0, time()+10*60*60);
$theme_dark = $themes_dark[0];
$theme_light = $themes_light[0];
}
if(isset($_GET['theme'])) {
setcookie('theme', (int)$_GET['theme'] % 2);
$theme_dark = $themes_dark[$_GET['theme']];
$theme_light = $themes_light[$_GET['theme']];
} else if(isset($_COOKIE['theme'])){
$theme_dark = $themes_dark[$_COOKIE['theme']];
$theme_light = $themes_light[$_COOKIE['theme']];
}
function nav($nav) {
foreach($nav as $name => $url) {
echo "<a href='$url'><div class='navitem'>$name</div></a>";
}
if($_SESSION['role'] >= 3) {
echo "<a href='admin.php'><div class='navitem'>Admin</div></a>";
}
if (isset($_SESSION['userid'])) {
echo "<a href='compte.php'><div class='navitem'>Profil</div></a><a href='logout.php'><div class='navitem'>Déconnexion</div></a>";
} else {
echo "<a href='login.php'><div class='navitem'>Connexion</div></a>";
}
}
function connect($dbhost, $dbname, $dbuser, $dbpass) {
try
{
$bdd = new PDO('mysql:host=' . $dbhost . ';dbname=' . $dbname . ';charset=UTF8mb4',$dbuser,$dbpass);
$bdd->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch(Exception $e)
{
die('Erreur : '.$e->getMessage());
}
return $bdd;
}
?>