This repository has been archived by the owner on Dec 16, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
loginas.php
79 lines (77 loc) · 2.95 KB
/
loginas.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
<?php
session_start();
if(!isset($_SESSION['user_id']) || !isset($_SESSION['user_name'])){
header("Location: login");
exit;
}
?>
<?php include_once(dirname(__FILE__).'/Controller/DutyController.php');?>
<?php include_once(dirname(__FILE__).'/Controller/UserController.php');?>
<?php
$dutyController = DutyController::getInstance();
$userController = UserController::getInstance();
$userID = $_SESSION['user_id'];
if (!isset($_SESSION['original_login']) && $userController->isAdmin($userID) == 0) {
header("Location: index");
exit;
}
if (isset($_SESSION['original_login'])) {
$_SESSION['user_id'] = $_SESSION['original_login'];
$_SESSION['user_name'] = $userController->getUserName($_SESSION['user_id']);
unset($_SESSION['original_login']);
}
if(isset($_SESSION['error'])){
echo '<div class="alert alert-danger">'.$_SESSION['error'].'</div>';
unset($_SESSION['error']);
}
if(isset($_SESSION['success'])){
echo '<div class="alert alert-success">'.$_SESSION['success'].'</div>';
unset($_SESSION['success']);
}
if (isset($_POST['loginas']) && $_POST['loginas'] != 'unset') {
$_SESSION['original_login'] = $_SESSION['user_id'];
$_SESSION['user_id'] = $_POST['loginas'];
$_SESSION['user_name'] = $userController->getUserName($_SESSION['user_id']);
header("Location: index");
exit;
}
?>
<html>
<head>
<title>NUSSU commIT</title>
<link href="includes/css/bootstrap.min.css" rel="stylesheet">
<link href="includes/css/bootstrap-theme.min.css" rel="stylesheet">
<link href="includes/css/style.css" rel="stylesheet">
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
<script src="includes/js/bootstrap.min.js"></script>
</head>
<body>
<?php $page = "loginas"; ?>
<?php include(dirname(__FILE__).'/includes/header.php');?>
<div class="container">
<div align="center" class="row">
<h1>Login as</h1>
</div>
<div class="row">
<form action="loginas" method="post">
<p align="center">
<select id="loginas" name="loginas">
<?php
$allUsers = $userController->getAllUser();
usort($allUsers, function($a, $b) {
return strcmp($a['name'], $b['name']);
});
echo "<option value='unset'>Choose wisely</option>";
for ($i = 0; $i < count($allUsers); ++$i) {
echo "<option value='".$allUsers[$i]['id']."'>".$allUsers[$i]['name']."</option>";
}
?>
</select>
<input type='submit' class='btn btn-primary'/>
</p>
</form>
</div>
</div>
<?php include(dirname(__FILE__).'/includes/footer.php');?>
</body>
</html>