-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
166 lines (129 loc) · 4.35 KB
/
index.php
File metadata and controls
166 lines (129 loc) · 4.35 KB
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
<?php
// TODO: Remove commented code where it isn't needed.
require_once 'autoload.php';
PSU::session_start(); // force ssl + start a session
$GLOBALS['BASE_URL'] = '/webapp/training-tracker';
$GLOBALS['BASE_DIR'] = __DIR__;
$GLOBALS['TITLE'] = 'Training Tracker';
$GLOBALS['TEMPLATES'] = $GLOBALS['BASE_DIR'] . '/templates';
includes_psu_register( 'TrainingTracker', $GLOBALS['BASE_DIR'] . '/includes' );
require_once $GLOBALS['BASE_DIR'] . '/API.php';
require_once 'klein/klein.php';
require_once $GLOBALS['BASE_DIR'] . '/includes/TrainingTrackerAPI.class.php';
if( file_exists( $GLOBALS['BASE_DIR'] . '/debug.php' ) ) {
include $GLOBALS['BASE_DIR'] . '/debug.php';
}
IDMObject::authN();
//if( ! IDMObject::authZ('permission', 'mis') ) {
// die('You do not have access to this application.');
//}
/**
* Routing provided by klein.php (https://github.com/chriso/klein.php)
* Make some objects available elsewhere.
*/
//Catch all
respond( function( $request, $response, $app ) {
// get the logged in user
$app->user = PSUPerson::get( $_SESSION['wp_id'] );
$memcache = new \PSUMemcache('training-tracker_teams');
if ( ! ($cached_results = $memcache->get('is_admin'))){
$staff_collection = new TrainingTracker\StaffCollection();
$staff_collection->load();
$valid_users = $staff_collection->valid_users();
$is_valid = false;
$is_mentor = false;
$is_admin = false;
foreach ($valid_users as $user){
if ($app->user->wpid == $user->wpid){
$is_valid = true;
}
}
if (!$is_valid){
die('You do not have access to this app.');
}
$teams_data = TrainingTracker::get_teams();
$has_team = false;
$wpid = $app->user->wpid;
if (isset($teams_data["$wpid"])){
$has_team = true;
}
$admins = $staff_collection->admins();
$mentors = $staff_collection->mentors();
foreach ($admins as $admin){
if ($app->user->wpid == $admin->wpid){
$is_admin = true;
$is_mentor = true;
}
}
if (!$is_mentor){
foreach ($mentors as $mentor){
if ($app->user->wpid == $mentor->wpid){
$is_mentor = true;
}
}
}
$active_user_parameters['wpid'] = $wpid;
$active_user = new TrainingTracker\Staff($active_user_parameters);
$memcache->set( 'active_user', $active_user, MEMCACHE_COMPRESSED, 60 * 5 );
$memcache->set( 'has_team', $has_team, MEMCACHE_COMPRESSED, 60 * 5 );
$memcache->set( 'is_admin', $is_admin, MEMCACHE_COMPRESSED, 60 * 5 );
$memcache->set( 'is_mentor', $is_mentor, MEMCACHE_COMPRESSED, 60 * 5 );
$memcache->set( 'is_valid', $is_valid, MEMCACHE_COMPRESSED, 60 * 5 );
}
else{
$active_user = $memcache->get('active_user');
$has_team = $memcache->get('has_team');
$is_admin = $memcache->get('is_admin');
$is_mentor = $memcache->get('is_mentor');
$is_valid = $memcache->get('is_mentor');
}
if (!$is_valid){
die('You do not have access to this app.');
}
$app->active_user = $active_user;
$app->is_admin = $is_admin;
$app->is_mentor = $is_mentor;
// initialize the template
$app->tpl = new PSUTemplate;
// assign user to template
$app->tpl->assign('active_user', $active_user);
$app->tpl->assign('user', $app->user);
$app->tpl->assign('has_team', $has_team);
$app->tpl->assign('wpid', $wpid);
$app->tpl->assign('is_admin', $is_admin);
$app->tpl->assign('is_mentor', $is_mentor);
});
// the person select page
respond( '/?', function( $request, $response, $app ) {
if ($app->is_mentor){
$staff_collection = new TrainingTracker\StaffCollection();
$staff_collection->load();
$staff = $staff_collection->staff();
}
else{
$current_user_parameter["wpid"] = $app->user->wpid;
$person = new TrainingTracker\Staff($current_user_parameter);
$person->privileges = TrainingTracker::get_user_level($person->wpid);
$staff[0] = $person;
}
foreach ($staff as $person){
$pidm = $person->person()->pidm;
$type = TrainingTracker::checklist_type($person->privileges);
if (!TrainingTracker::checklist_exists($pidm, $type, 0)){
//get tybe based off of a persons privileges
$type = TrainingTracker::checklist_type($person->privileges);
//insert new checklist (pidm, type)
TrainingTracker::checklist_insert($pidm, $type);
}
}
$app->tpl->assign('staff', $staff);
$app->tpl->display('index.tpl');
});
$app_routes = array(
'staff',
'team'
);
foreach( $app_routes as $base ) {
with( "/{$base}", $GLOBALS['BASE_DIR'] . "/routes/{$base}.php" );
}//end foreach
dispatch( $_SERVER['PATH_INFO'] );