-
Notifications
You must be signed in to change notification settings - Fork 7
/
account.php
112 lines (98 loc) · 4.03 KB
/
account.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
106
107
108
109
110
111
112
<?php
require_once( 'components/system/Preload.php' );
$allowed = array(
0 => 'Anyone who is logged in',
);
$page = new \render\Page('Account Management', 'account', $allowed);
$tmpl = new \backbone\Template();
$doctrineFactory = new \model\Access();
$em = $doctrineFactory->getEntityManager();
$userRepo = $em->getRepository( 'model\entities\User' );
$roleRepo = $em->getRepository( 'model\entities\Role' );
$page->run();
$tmpl->self = $page->self;
$tmpl->code = isset( $_GET['code'] ) ? $_GET['code'] : -1;
$userid = isset( $_GET['uid'] ) ? $_GET['uid'] : $_SESSION['userid'];
$tmpl->action = isset( $_GET['a'] ) ? $_GET['a'] : 'manage';
if( $userid == $_SESSION['userid'] ){
$user = $userRepo->find( $userid );
}
else{
$attempt = $userRepo->find( $userid );
if( $tmpl->self->getAuthentication()->getRole()->getId() == 1 ){
$user = $attempt;
}
else{
$user = $tmpl->self;
}
}
//form fields
$data['fname'] = isset($_GET['fname']) ? ($_GET['fname'] != null ? $_GET['fname'] : ($tmpl->action == 'manage' ? $user->getFname() : null)) : ($tmpl->action == 'manage' ? $user->getFname() : null);
$data['lname'] = isset($_GET['lname']) ? ($_GET['lname'] != null ? $_GET['lname'] : ($tmpl->action == 'manage' ? $user->getLname() : null)) : ($tmpl->action == 'manage' ? $user->getLname() : null);
$data['gender'] = isset($_GET['gender']) ? ($_GET['gender'] != null ? $_GET['gender'] : ($tmpl->action == 'manage' ? $user->getGender() : null)) : ($tmpl->action == 'manage' ? $user->getGender() : null);
$data['email'] = isset($_GET['email']) ? ($_GET['email'] != null ? $_GET['email'] : ($tmpl->action == 'manage' ? $user->getContacts()[0]->getEmail() : ($tmpl->action == 'login' ? $user->getAuthentication()->getIdentity() : null))) : ($tmpl->action == 'manage' ? $user->getContacts()[0]->getEmail() : ($tmpl->action == 'login' ? $user->getAuthentication()->getIdentity() : null));
$data['phone'] = isset($_GET['phone']) ? ($_GET['phone'] != null ? $_GET['phone'] : ($tmpl->action == 'manage' ? $user->getContacts()[0]->getFriendlyPhone() : null)) : ($tmpl->action == 'manage' ? $user->getContacts()[0]->getFriendlyPhone() : null);
//end form fields
switch( $tmpl->code ){
case 0:
// Account updated successfully
$tmpl->alert['type'] = "okay";
$tmpl->alert['message'] = "The account was updated successfully.";
break;
case 1:
// An unknown error occurred (account update)
$tmpl->alert['type'] = "error";
$tmpl->alert['message'] = "An unknown error occurred while attempting to save the changes.";
break;
case 2:
// The required fields for adding a new user weren't completed
$tmpl->alert['type'] = "error";
$tmpl->alert['message'] = "You must complete all of the fields in the \"Required Information\" set.";
break;
case 3:
// The new account identity is already in use
$tmpl->alert['type'] = "error";
$tmpl->alert['message'] = "That identity is invalid. Please choose another one.";
break;
case 4:
// The passwords (changing password) didn't match
$tmpl->alert['type'] = "error";
$tmpl->alert['message'] = "The \"New Password\" and \"Verify New Password\" fields must match.";
break;
case 5:
// User is required to change their password
$tmpl->alert['type'] = "alert";
$tmpl->alert['message'] = "You must change your password before continuing.";
break;
case -1:
default:
break;
}
switch( strtolower( $user->getGender() ) ){
case 'm':
$tmpl->icon = 'user';
break;
case 'f':
$tmpl->icon = 'user-female';
break;
default:
$tmpl->icon = 'user-silhouette';
break;
}
$tmpl->user = $user;
$tmpl->data = $data;
$tmpl->roles = $roleRepo->findAll();
$html = $tmpl->build('account.html');
$css = $tmpl->build('account.css');
$js = $tmpl->build('account.js');
$appContent = array(
'html' => $html,
'css' => array( 'code' => $css,
'link' => 'account'
),
'js' => array( 'code' => $js,
'link' => 'account'
)
);
echo $page->build($appContent);
?>