1
0
Fork 0
This repository has been archived on 2024-02-17. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
Accommodation_Management/src/func.php
p1907961 240492d94f ok
2021-01-05 17:53:26 +01:00

57 lines
1.6 KiB
PHP

<?php
/*
* Getters
*/
function getGet($name, $default = NULL){
if(isset($_GET[$name])){
return $_GET[$name];
}
return $default;
}
function getPost($name, $default = NULL){
if(isset($_POST[$name])){
return $_POST[$name];
}
return $default;
}
/*
* URL & Redirection
*/
function genURL($route = WEBSITE_DEFAULT_PATH){
return $_SERVER["REQUEST_SCHEME"] . '://' . $_SERVER["SERVER_NAME"] . WEBSITE_PATH . $route;
}
function redirect($route = WEBSITE_DEFAULT_PATH){
header('Location: ' . genURL($route));
}
/*
* Front-end render
*/
# Assets path generator
function assetsPath($path, $level = 0){
return str_repeat('../', $level) . $path;
}
# Alert generator
function alert($status , $msg){
switch($status){
case 'primary':
case 'secondary':
case 'success':
case 'danger':
case 'warning':
case 'info':
case 'light':
case 'dark':
return "<div class='alert alert-" .$status. "' role='alert'>" .htmlspecialchars($msg). "</div>";
break;
default:
throw new \Exception("Status d'alerte invalide");
}
}
# Navbar button render
function navItem($name, $path){
$acc = '';
if(($_SERVER['REQUEST_URI'] === WEBSITE_PATH . $path) || ($path === ($_SERVER["REQUEST_SCHEME"] . '://' . $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"]))){
$acc = 'active';
}
return '<li class="nav-item"><a class="nav-link ' .$acc. '" aria-current="page" href="' .htmlspecialchars($path). '">' .htmlspecialchars($name). '</a></li>';
}