-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathselect_user.php
203 lines (163 loc) · 4.9 KB
/
select_user.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
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
<?php
/*
* select_user.php
*
* Allows admin users to assume another user's identity for submitting jobs
*
*/
include_once 'checkinstance.php';
if ( ($_SESSION['userlevel'] < 3) ) // super, admin and super admin only
{
header('Location: index.php');
exit();
}
include 'config.php';
include 'db.php';
include 'lib/selectboxes.php';
// ini_set('display_errors', 'On');
// Start displaying page
$page_title = "Select Another User";
include 'header.php';
?>
<!-- Begin page content -->
<div id='content'>
<h1 class="title">Select Another User</h1>
<!-- Place page content here -->
<?php
if ( isset( $_POST['personID'] ) )
{
$text = person_select( $link, 'personID', $_POST['personID'] );
$text .= change_person_info( $link, $_POST['personID'] );
}
else if ( isset( $_GET['restore'] ) &&
$_GET['restore'] == 'true' )
{
$text = person_select( $link, 'personID', $_SESSION['loginID'] );
$text .= restore_info($link);
}
else
$text = person_select( $link, 'personID', $_SESSION['id'] );
echo $text;
echo "<p><a href='{$_SERVER['PHP_SELF']}?restore=true'>Restore my own info</a></p>\n";
?>
</div>
<?php
include 'footer.php';
exit();
// Function to clear the queue to prevent modelPerson corruption
function clear_queue() {
unset( $_SESSION['request'] );
unset( $_SESSION['cells'] );
unset( $_SESSION['experimentID'] );
unset( $_SESSION['new_noise'] );
}
// Function to update user session variables and display info
function change_person_info( $link, $personID )
{
clear_queue();
$query = "SELECT fname, lname, phone, clusterAuthorizations " .
"FROM people " .
"WHERE personID = ? ";
// Prepared statement
if ($stmt = mysqli_prepare($link, $query)) {
$stmt->bind_param('i', $personID);
$stmt->execute();
$stmt->store_result();
$num_of_rows = $stmt->num_rows;
$stmt->bind_result($fname, $lname, $phone, $clusterAuthorizations);
$stmt->fetch();
$stmt->free_result();
$stmt->close();
}
/* This code was replace by the prepared statement above
$result = mysqli_query($link, $query)
or die( "Query failed : $query<br />\n" . mysqli_error($link) );
$row = mysqli_fetch_assoc($result);
// Register the variables:
foreach( $row AS $key => $val )
{
$$key = stripslashes( $val );
}
*/
// The loginID, email and userlevel don't change, even if working
// on behalf of another
$_SESSION['id'] = $personID;
$_SESSION['firstname'] = $fname;
$_SESSION['lastname'] = $lname;
$_SESSION['phone'] = $phone;
// Set cluster authorizations
$loginID = $_SESSION['loginID'];
$query = "SELECT clusterAuthorizations " .
"FROM people " .
"WHERE personID = $loginID ";
$result = mysqli_query($link, $query)
or die( "Query failed : $query<br />\n" . mysqli_error($link) );
$row = mysqli_fetch_assoc($result);
foreach( $row AS $key => $val )
{
$$key = stripslashes( $val );
}
$clusterAuth = array();
$clusterAuth = explode(":", $clusterAuthorizations );
$_SESSION['clusterAuth'] = $clusterAuth;
// Allow for display of this information
$clusterText = implode( ", ", $clusterAuth );
$text = <<<HTML
<pre>
User identity assumed.
Name: $lname, $fname
Login User Cluster Authorizations: $clusterText
</pre>
HTML;
return $text;
}
// Function to restore user session variables and display info to login values
function restore_info($link)
{
clear_queue();
$personID = $_SESSION['loginID'];
$query = "SELECT fname, lname, phone, clusterAuthorizations " .
"FROM people " .
"WHERE personID = ? ";
// Prepared statement
if ($stmt = mysqli_prepare($link, $query)) {
$stmt->bind_param('i', $personID);
$stmt->execute();
$stmt->store_result();
$num_of_rows = $stmt->num_rows;
$stmt->bind_result($fname, $lname, $phone, $clusterAuthorizations);
$stmt->fetch();
$stmt->free_result();
$stmt->close();
}
/* This code was replace by the prepared statement above
$result = mysqli_query($link, $query)
or die( "Query failed : $query<br />\n" . mysqli_error($link) );
$row = mysqli_fetch_assoc($result);
// Register the variables:
foreach( $row AS $key => $val )
{
$$key = stripslashes( $val );
}
*/
// The loginID, email and userlevel don't change, even if working
// on behalf of another
$_SESSION['id'] = $personID;
$_SESSION['firstname'] = $fname;
$_SESSION['lastname'] = $lname;
$_SESSION['phone'] = $phone;
// Set cluster authorizations
$clusterAuth = array();
$clusterAuth = explode(":", $clusterAuthorizations );
$_SESSION['clusterAuth'] = $clusterAuth;
// Allow for display of this information
$clusterText = implode( ", ", $clusterAuth );
$text = <<<HTML
<pre>
User identity restored.
Name: $lname, $fname
Cluster Authorizations: $clusterText
</pre>
HTML;
return $text;
}