forked from LahiruSen/OOSD
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstudent_submit_notification.php
More file actions
169 lines (81 loc) · 2.92 KB
/
Copy pathstudent_submit_notification.php
File metadata and controls
169 lines (81 loc) · 2.92 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
<?php
/**
* Created by PhpStorm.
* User: BlackLion
* Date: 4/6/2018
* Time: 8:19 AM
*/
require 'validator.php';
require 'db.php';
if (session_status() == PHP_SESSION_NONE) { session_start();}
// CHECK THERE IS A LOGNG[SESSION VARIABLE WERE ONLY CREATED DURING LOGIN] &&&& CHECK USER TYPE = ADMINISTRATOR
if(isset($_SESSION['email']))
{
$user_id = $_SESSION['user_id'];
if($_SESSION['two_step'] == 0)
{
$_SESSION['message'] = "You are not completed 2nd step of registration";
header("location:error.php");
}
if($_SESSION['types'] == 2 )
{
$_SESSION['message'] = "You cannot access this page";
header("location:error.php");
}
}else
{
$_SESSION['message'] = "This session has expired. Please login again!!!";
header("location:error.php");
}
if(isset($_POST['student_id']) && isset($_POST['title'])&& isset($_POST['description']))
{
$title = $_POST['title'];
$description = $_POST['description'];
$student_id = $_POST['student_id'];
$sender = $_SESSION['user_id'];
$number_of_rec = count($student_id);
$sent_count =0;
if($number_of_rec>0){
$date_of_create= $mysqli->escape_string( date("Y-m-d H:i:s"));
$date_of_update= $mysqli->escape_string( date("Y-m-d H:i:s"));
for($p=0;$p<$number_of_rec;$p++)
{
$sql = "INSERT INTO notifications (title, description, target_user_ids,date_of_create,"
." date_of_update,sender_id,is_seen,types) "
. "VALUES ('$title','$description','$student_id[$p]','$date_of_create','$date_of_update','$sender','0','2')";
if($mysqli->query($sql))
{
$sent_count++;
}else
{
$_SESSION['message'] = "Something went terribly wrong";
header("location:error.php");
die();
}
}
if($sent_count == $number_of_rec)
{
$_SESSION['message'] = "All the notification has sent";
header("location:success.php");
}else
{
$_SESSION['message'] = "Something went wrong";
header("location:error.php");
}
}else{
$_SESSION['message'] = "You have to select at least one student as a receiver";
header("location:error.php");
}
//insert query
}else
{
if(!isset($_POST['student_id']))
{
$_SESSION['message'] = "You have to select at least one student as a receiver";
header("location:error.php");
}else
{
$_SESSION['message'] = "Parameters are missing";
header("location:error.php");
}
}