-
Notifications
You must be signed in to change notification settings - Fork 1
/
allocateuser.php
164 lines (148 loc) · 6.32 KB
/
allocateuser.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
<!--
### STOCKHAWK ###
allocateuser.php :
Allocates all the new users who donot have any Portfolio manager assigned to them.
-->
<html>
<?php require_once dirname(__FILE__).DIRECTORY_SEPARATOR.'header.html' ?>
<body>
<?php
/*
Check if the existing session expired or not. If expired, redirect to index.php.
*/
session_start();
if(empty($_SESSION['login_user'])){
header("location: land.php");exit();
}
if($_SESSION['user_type']=='user'){
header("location: land.php");exit();
}
require_once './config.php';
$con = mysqli_connect($hostname, $username, $password, $databasename); // Setup connection with the database.
if (mysqli_connect_errno()) {
//die("Failed to connect");
header("location: error.html");exit();
}
if(isset($_GET['Message'])){
$msg=$_GET['Message'];
unset($_GET['Message']);
echo '<script type="text/javascript">alert("'.$msg.'");</script>';
}
if($_SERVER["REQUEST_METHOD"]=="POST"){
$uname=$_POST['uname'];
$aname=$_POST['aname'];
allocate($con,$uname,$aname);
}
/*
Method - allocate
Allocates a manager to an unallocated user one at a time.
Arguements -
$con - Connection Variable. Checks if the connection is broken or not.
$uname - Name of user who donot have any Manager alloted to them.
$aname - Name of Manager who will be assigned to the present user.
Returns -
Null
*/
function allocate($con,$uname,$aname){
$q0="select uemail from user where uemail='$aname' and isAdmin=true or isPM=true";
$rs0=mysqli_query($con,$q0);
$cnt=mysqli_num_rows($rs0);
if($cnt>0){
$q1="update user set allotedto='$aname' where uemail='$uname'";
$rs1=mysqli_query($con,$q1);
if(mysqli_errno($con)){header("location: error.php");exit();}
$rowCount=mysqli_num_rows($rs1);
if($rowCount==0){
$msg="Invalid Username or Admin";
header("location:allocateuser.php?Message=".urlencode($msg));exit();
}
}else{
$msg="No Such Admin";
header("location:allocateuser.php?Message=".urlencode($msg));exit();
}
}
?>
<div class="demo-layout mdl-layout mdl-js-layout mdl-layout--fixed-drawer mdl-layout--fixed-header">
<?php require_once dirname(__FILE__).DIRECTORY_SEPARATOR.'header_bar.html' ?>
<?php require_once dirname(__FILE__).DIRECTORY_SEPARATOR.'sidebar.php' ?>
<!-- design here. call the allocate on clicking submit -->
<main class="mdl-layout__content mdl-color--grey-100">
<div class="mdl-grid demo--content">
</div>
<div class="demo-charts mdl-shadow--2dp mdl-color--white mdl-cell mdl-cell--12-col">
<div class="mdl-card__supporting-text mdl-color-text--teal-500">
<h2>Unalloted Users</h2>
<table class="mdl-data-table mdl-js-data-table" id="allocate_table">
<thead>
<tr>
<th class="mdl-data-table__cell--non-numeric">Email</th>
<th class="mdl-data-table__cell--non-numeric">Name</th>
</tr>
</thead>
<tbody>
<?php
/*
List all the unallocated users.
*/
$q1="select uemail,uname from user where allotedto='no'";
$rs1=mysqli_query($con,$q1);
if(mysqli_errno($con)){
header("location: error.php");exit();
}
while($r1=mysqli_fetch_array($rs1)){
echo '<tr>
<td class="mdl-data-table__cell--non-numeric">'.$r1[0].'</td>
<td>'.$r1[1].'</td>
</tr>';
}
echo "</tbody>
</table>";?>
</div>
</div>
<div class="demo-separator mdl-cell--1-col"></div>
<div class="demo-options mdl-card mdl-color--white-500 mdl-shadow--2dp mdl-cell mdl-cell--4-col mdl-cell--3-col-tablet mdl-cell--12-col-desktop">
<div class="mdl-card__supporting-text mdl-color-text--teal-500">
<h3>Allocate User</h3>
<!-- Simple Textfield -->
<form method="post">
<div class="mdl-textfield mdl-js-textfield">
<input class="mdl-textfield__input" type="text" id="cname" name="uname">
<label class="mdl-textfield__label" for="sample1">User ID</label>
</div>
<div class="mdl-textfield mdl-js-textfield">
<input class="mdl-textfield__input" type="text" id="newval" name="aname">
<label class="mdl-textfield__label" for="sample1">Admin/PM ID</label>
</div>
<div class="mdl-card__actions mdl-card--border">
<button type="submit" class="mdl-button mdl-button--raised mdl-js-button mdl-js-ripple-effect mdl-color-text--teal-500" name="allot">Allocate</button>
<div class="mdl-layout-spacer"></div>
</div>
</form>
</div>
</div>
<script type="text/javascript">
function addRowHandlers() {
var table = document.getElementById("allocate_table");
var rows = table.getElementsByTagName("tr");
var customerAllocate = document.getElementById("cname");
for (i = 0; i < rows.length; i++) {
var currentRow = table.rows[i];
var createClickHandler =
function(row)
{
return function() {
var cell = row.getElementsByTagName("td")[0];
var id = cell.innerHTML;
customerAllocate.value = id;
};
};
currentRow.onclick = createClickHandler(currentRow);
}
}
window.onload = addRowHandlers();
</script>
</main>
</div>
<script src="../../material.min.js"></script>
</body>
</html>