-
Notifications
You must be signed in to change notification settings - Fork 1
/
template.php
105 lines (94 loc) · 2.24 KB
/
template.php
1
2
3
4
5
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<?php
require_once(__DIR__ . '/model/connection.php');
abstract class Template
{
protected $conn;
public function __construct()
{
$connection = Connection::get_instance();
$this->conn = $connection->get_connection();
}
public function render($title)
{
echo "
<html>
<head>
<title>$title</title>
";
foreach ($this->get_css_files() as $css_path)
{
echo "<link rel='stylesheet' type='text/css' href='./include/css/" . $css_path ."'>";
}
foreach ($this->get_js_files() as $js_path)
{
echo "<script src='./include/js/" . $js_path . "'></script>";
}
echo "
</head>
<body>
<ul class='navigation'>
<li class='main-logo'><a href='alumni.php'>Alumni.edu</a></li>
<li><a href=''>Store</a></li>
<li><a href='alumni.php?page=communicate'>Communicate</a></li>
<li><a href='alumni.php?page=register'>Register</a></li>
";
if (isset($_SESSION['username']) && isset($_SESSION['password']))
{
$username = $_SESSION['username'];
echo "
<li>$username</li>
<li><a href='alumni.php?page=edit&username=$username'>Edit profile</a></li>
<li><a href='alumni.php?page=logout'>Log out</a></li>
";
}
else
{
echo "
<li><a href='alumni.php?page=login'>Log in</a></li>
";
}
echo "
</ul>
<div class='content'>
";
$this->render_body();
echo "
</div>
</body>
</html>
";
}
abstract protected function render_body();
protected function get_css_files()
{
return array();
}
protected function get_js_files()
{
return array('jquery1.11.3.min.js');
}
protected function redirect_to_main_page()
{
// redirect to the main page
$host = $_SERVER['HTTP_HOST'];
$uri = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
$page = 'alumni.php';
header("Location: http://$host$uri/$page");
}
public function sanitize_string($string)
{
$string = stripcslashes($string);
$string = $this->conn->real_escape_string($string);
return htmlentities($string);
}
public function sanitize_array($array)
{
$sanitized_array = array();
foreach($array as $key => $value)
{
$sanitized_array[$key] = $this->sanitize_string($value);
}
return $sanitized_array;
}
}
?>