mainController.php 2.83 KB
Newer Older
Corentin Bettiol's avatar
Corentin Bettiol committed
1
<?php
Corentin Bettiol's avatar
Corentin Bettiol committed
2

3 4
require_once("site/model/config.php");
require_once("site/model/Base.php");
Corentin Bettiol's avatar
Corentin Bettiol committed
5
require_once("site/model/AdminManager.php");
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
require_once("site/model/BlogManager.php");
require_once("site/model/ProjectsManager.php");

function getPageName(){
	if(isset($_GET['action'])){
		switch ($_GET['action']) {
		case 'contact':
			return ["Contact", "contact"];
			break;
		case 'about':
			return ["À Propos", "about"];
			break;
		case 'projects':
			return ["Projets", "projects"];
			break;
		case 'changelog':
			return ["Changelog", "changelog"];
			break;
		case 'rss':
			return ["Rss", "rss"];
			break;
		case '404':
			return ["Erreur 404 - File not found", "404"];
			break;
		case 'article':
			return [$_GET['title'], $_GET['title']];
			break;
Corentin Bettiol's avatar
Corentin Bettiol committed
33 34 35 36 37 38
		case 'patate':
			return ["Administration", "administration"];
			break;
		case 'eplucher':
			return ["prout hihi", "eplucher"];
			break;
39 40 41 42 43 44 45 46 47 48 49 50 51
		default:
			return ["Blog", "blog"];
			break;
		}
	}
	else{
		return ["Blog", "blog"];
	}
}

function writeMenu($pageName){
?>
	<ul id="listMenu">
Corentin Bettiol's avatar
Corentin Bettiol committed
52
		<?php if($pageName == "Administration"){ ?><li><h2><a href="/eplucher" class="selected">🔧</a></h2></li><?php } ?>
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
		<li><h2><a href="/" title="Blog" <?php if($pageName == "Blog"){ ?>class="selected"<?php } ?>>Blog</a></h2></li>
		<li><h2><a href="/about" title="À propos" <?php if($pageName == "À Propos"){ ?>class="selected"<?php } ?>>À propos</a></h2></li>
		<li><h2><a href="/projects" title="Projets" <?php if($pageName == "Projets"){ ?>class="selected"<?php } ?>>Projets</a></h2></li>
		<li><h2><a href="/contact" title="Contact" <?php if($pageName == "Contact"){ ?>class="selected"<?php } ?>>Contact</a></h2></li>
	</ul>
<?php }

function writeBlogPage($pageName){
	if($pageName[1] == "blog"){
		
		$blog = new BlogManager();
		
		if(isset($_GET['title'])){
			$title = $_GET['title'];
			$blogpost = $blog->getBlogPost($title);
			if($blogpost != false)
				require("site/view/public/blogPostView.php");
			else
				header("Location:/404");
		}
		else{
Corentin Bettiol's avatar
Corentin Bettiol committed
74
			$blogposts = $blog->getBlog(0);
75 76 77 78 79 80 81 82
			require("site/view/public/blogView.php");
		}
	}
}

function writeProjectsPage($pageName){
	$projects = new ProjectManager();

83
	$projects = $projects->getProjects();
84 85 86 87

	require("site/view/public/projectsView.php");
}

Corentin Bettiol's avatar
Corentin Bettiol committed
88 89 90 91 92 93 94 95 96 97 98 99
function loginAdminPage($pageName){
	if(password_verify($_POST['pass'], pass) && $_POST['user'] == user){
		$_SESSION['user'] = $_POST['user'];
		$_SESSION['pass'] = $_POST['pass'];
		header("Location:/patate");
	}
	else
		echo "nan";
}


function writeAdminPage($pageName){
Corentin Bettiol's avatar
Corentin Bettiol committed
100 101 102 103 104 105
	$admin = new AdminManager();
	if($admin->verifyAdminConnect()){
		
		$blogposts = $admin->getBlogPosts();
		$projects = $admin->getProjects();

Corentin Bettiol's avatar
Corentin Bettiol committed
106 107
		require("site/view/private/admin.php");
	}
Corentin Bettiol's avatar
Corentin Bettiol committed
108 109
	else
		require("site/view/private/loginFormView.php");
Corentin Bettiol's avatar
Corentin Bettiol committed
110 111 112 113 114 115
}

function decoAdminPage(){
	$_SESSION = array();
	header("Location:/");
}
116 117


Corentin Bettiol's avatar
Corentin Bettiol committed
118
$pageName = getPageName();