-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathajax_calls.php
More file actions
199 lines (189 loc) · 5.7 KB
/
Copy pathajax_calls.php
File metadata and controls
199 lines (189 loc) · 5.7 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
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
<?php
include 'database.php';
session_start();
error_reporting(0);
if($_POST['action'] == 'login_form')
{
$email1 = $_POST['email'];
$password1 = $_POST['password'];
$_SESSION["login"] = $email1;
$encrypt = md5($password1);
if(!empty($email1) && !empty($encrypt))
{
$query1 = "SELECT * FROM credentials WHERE email='".$email1."' AND password='".$encrypt."'";
$result1 = mysqli_query($conn,$query1);
$count = mysqli_fetch_assoc($result1);
if(mysqli_num_rows($result1)>0)
{
if($count['email']=='admin')
{
$msg1 = "admin";
}
else
{
$msg1 = "student";
}
}
else
{
$msg1 = "Check Your Details";
}
}
echo json_encode($msg1);
}
if($_POST['action'] == 'update_password')
{
$old = $_POST['old'];
$newpassword = $_POST['newpassword'];
$encryptold = md5($old);
$encryptnew = md5($newpassword);
if(!empty($encryptold) && !empty($encryptnew))
{
$result = mysqli_query($conn, "SELECT * from studata WHERE email='" . $_SESSION["login"] . "'");
$row = mysqli_fetch_array($result);
if ($encryptold == $row["password"]) {
mysqli_query($conn, "UPDATE studata set password='" . $encryptnew . "' WHERE email='" . $_SESSION["login"] . "'");
mysqli_query($conn, "UPDATE credentials set password='" . $encryptnew . "' WHERE email='" . $_SESSION["login"] . "'");
$message = "success";
}
else {
$message = "failure";
}
}
echo json_encode($message);
}
if($_POST['action'] == 'add_form')
{
$name = $_POST['name'];
$regno = $_POST['regno'];
$appno = $_POST['appno'];
$sem = $_POST['sem'];
$cgpa = $_POST['cgpa'];
$rollno = $_POST['rollno'];
$sec = $_POST['sec'];
$email = $_POST['email'];
$tgnum = $_POST['tgnum'];
$tgname = $_POST['tgname'];
$encryptpass = md5($regno);
if ($encryptpass) {
mysqli_query($conn, "INSERT INTO studata (names,regno,appno,sem,cgpa,rollno,sec,email,tgnum,tgname,password) VALUES ('$name','$regno','$appno','$sem','$cgpa','$rollno','$sec','$email','$tgnum','$tgname','$encryptpass')");
mysqli_query($conn, "INSERT INTO credentials (email,password) VALUES ('$email','$encryptpass')");
$message = "success";
}
else {
$message = "failure";
}
echo json_encode($message);
}
if($_POST['action'] == 'details')
{
$regno = $_POST['regno'];
if(!empty($regno)){
$row = mysqli_query($conn, "SELECT * from studata WHERE regno='" . $regno . "'");
$result = mysqli_fetch_array($row);
$a = [];
$a[] = $result['id'];
$a[] = $result['names'];
$a[] = $result['regno'];
$a[] = $result['appno'];
$a[] = $result['sem'];
$a[] = $result['cgpa'];
$a[] = $result['rollno'];
$a[] = $result['sec'];
$a[] = $result['email'];
$a[] = $result['tgnum'];
$a[] = $result['tgname'];
echo json_encode($a);
}
}
if($_POST['action'] == 'updatedetails')
{
$id = $_POST['id'];
$name = $_POST['name'];
$regno = $_POST['regno'];
$appno = $_POST['appno'];
$sem = $_POST['sem'];
$cgpa = $_POST['cgpa'];
$rollno = $_POST['rollno'];
$sec = $_POST['sec'];
$email = $_POST['email'];
$tgnum = $_POST['tgnum'];
$tgname = $_POST['tgname'];
$encryptpass = md5($regno);
if ($encryptpass) {
mysqli_query($conn, "UPDATE studata SET names='" . $name . "',regno='" . $regno . "',appno='" . $appno . "',sem='" . $sem . "',cgpa='" . $cgpa . "',rollno='" . $rollno . "',sec='" . $sec . "',email='" . $email . "',tgnum='" . $tgnum . "',tgname='" . $tgname . "',password='" . $encryptpass . "' WHERE id='" . $id . "'");
mysqli_query($conn, "UPDATE credentials SET email='" . $email . "',password='" . $encryptpass . "' WHERE id='" . $id . "'");
$message = "success";
}
else {
$message = "failure";
}
echo json_encode($message);
}
if($_GET['action']=='student_event')
{
$sql = "SELECT subjects.sub as title,events.start,events.end FROM events join subjects on events.sub_id=subjects.sub_id where resourceId=(select sections.id from sections where sections.title=(select sec from studata where email='".$_SESSION["login"]."'))";
$result = mysqli_query($conn,$sql);
$myArray = array();
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
$myArray[] = $row;
}
}
else
{
echo "0 results";
}
echo json_encode($myArray);
}
if($_GET['action']=='admin_resource')
{
$sql = "SELECT sections.id,sections.title FROM sections";
$result = mysqli_query($conn,$sql);
$myArray = array();
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
$myArray[] = $row;
}
}
else
{
echo "0 results";
}
echo json_encode($myArray);
}
if($_GET['action']=='admin_events')
{
$sql = "SELECT events.id,events.resourceId,events.start,events.end,sections.title as sec,subjects.sub as title FROM events join sections on events.resourceId=sections.id join subjects on events.sub_id= subjects.sub_id;";
$result = mysqli_query($conn,$sql);
$myArray = array();
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
$myArray[] = $row;
}
}
else
{
echo "0 results";
}
echo json_encode($myArray);
}
if($_POST['action'] == 'add_event')
{
$starttime = $_POST['starttime'];
$resourceid = $_POST['resourceid'];
$eventid = $_POST['eventid'];
$endtime = $_POST['endtime'];
if ($endtime) {
mysqli_query($conn, "INSERT INTO events (resourceId,start,end,sub_id) VALUES ('$resourceid','$starttime','$endtime','$eventid');");
$message = "success";
}
else {
$message = "failure";
}
echo json_encode($message);
}
?>