This repository has been archived by the owner on Jan 21, 2024. It is now read-only.
/
view_profile.php
77 lines (70 loc) · 2.42 KB
/
view_profile.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
<?php
/**
* File defines the ViewProfileController PageController class
* @package PageController
*/
/**
*/
$current_dir = dirname (__FILE__);
require_once ($current_dir . DIRECTORY_SEPARATOR . "shared" . DIRECTORY_SEPARATOR . "bootstrap.php");
require_once (joinPath (INCLUDES_DIR, "Session.php"));
/**
* MEMBERS ONLY. View user profile page
*
* Read in the specified profile from the database. Check if the current visitor is a valid user
* and redirect if the user is not. If the user is valid,
* display profile details in the page. Available to members only
* @package PageController
*/
class ViewProfileController implements Controller {
/**
* PageTemplate object used to render page
* @access protected
* @var PageTemplate
*/
protected $template;
/**
* Constructor. Create instance of PageTemplate using default index_tpl.php file
* @access public
*/
public function __construct () {
$this->template = new PageTemplate ();
}
/**
* Run method with main page logic
*
* Read in the specified profile from the database. Check if the current visitor is a valid user
* and redirect if the user is not. If the user is valid,
* populate template and display profile details in the page. Available to members only
* @access public
*/
public function run () {
$session = Session::getInstance ();
$user = $session->getUser ();
// Check for a valid user
if ($user == null || !$user->validUser ()) {
$session->setMessage ("Do not have permission to access", Session::MESSAGE_ERROR);
header ("Location: " . BASE_URL);
return;
}
$userDAO = UserDAO::getInstance ();
$user = null;
$title = "";
if (!empty ($_GET["id"]) && is_numeric ($_GET["id"])) {
$user_id = intval ($_GET["id"]);
$user = $userDAO->load ($user_id);
if ($user) {
$title .= " - {$user->getUserName ()}";
}
}
$this->template->render (array (
"title" => "View Profile" . $title,
"main_page" => "view_profile_tpl.php",
"user" => $user,
"session" => $session,
));
}
}
$controller = new ViewProfileController ();
$controller->run ();
?>