-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathheaderFunctions.php
71 lines (54 loc) · 1.63 KB
/
headerFunctions.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
<?php
$publicPages = array(
'index.php' => true,
'login.php' => true,
'logout.php' => true,
'signup.php' => true,
'about.php' => true);
function loggedIn() {
return strlen($_COOKIE['auth']) > 0;
}
function redirect($page) {
$host = $_SERVER['HTTP_HOST'];
$uri = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
header("Location: http://$host$uri/$page");
exit;
}
function getCurrentUserId() {
if(loggedIn()) {
$conn = dbConnect();
$passwordHash = $_COOKIE['auth'];
$stmt = $conn->prepare('select id from appusers where passwordHash = :passwordHash');
$stmt->bindParam(':passwordHash', $passwordHash, PDO::PARAM_STR);
$stmt->execute();
$results = $stmt->fetchAll(PDO::FETCH_ASSOC); //retreive the rows as an associative array
dbDisconnect($conn);
foreach ($results as $user) {
extract($user);
}
return $id;
}
}
function getProjectsForUser($userId, $searchString)
{
$searchString = "%" . $searchString . "%";
$query = <<<STR
Select name, projectId
From project
Where id = $userId
and name like '$searchString'
order by lower(name)
STR;
return executeQuery($query);
}
function money_format($value) {
return "$ " . number_format($value, 2);
}
// check and see if we are on a public page
$currentPage = rtrim(basename($_SERVER['PHP_SELF']));
if(! loggedIn()) {
if(! array_key_exists($currentPage, $publicPages)) {
redirect('login.php');
}
}
?>