-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathinsertdata.php
366 lines (334 loc) · 14.8 KB
/
insertdata.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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<?php require_once("includes/session.php"); ?>
<?php require_once("includes/functions.php"); ?>
<?php require("includes/connection.php"); ?>
<html>
<head>
<title>ADMIN PAGE</title>
<style type="text/css">
#input[type="button"] {
width : 200px;
margin: 2;
-webkit-box-sizing: border-box; /* For legacy WebKit based browsers */
-moz-box-sizing: border-box; /* For all Gecko based browsers */
box-sizing: border-box;
}
input[type="button"]
{
border-right: #a9a9a9 2px solid;
padding-right: 2px;
border-top: #a9a9a9 2px solid;
padding-left: 2px;
padding-bottom: 2px;
border-left: #a9a9a9 2px solid;
padding-top: 2px;
border-bottom: #a9a9a9 2px solid;
}
input
{
border: 2px Solid White;
-webkit-box-shadow:
inset 0 0 8px rgba(0,0,0,0.1),
0 0 16px rgba(0,0,0,0.1);
-moz-box-shadow:
inset 0 0 8px rgba(0,0,0,0.1),
0 0 16px rgba(0,0,0,0.1);
box-shadow:
inset 0 0 8px rgba(0,0,0,0.1),
0 0 16px rgba(0,0,0,0.1);
padding: 5px;
background: rgba(255,255,255,0.5);
margin: 0 0 10px 0;
}
select
{
border: 2px Solid White;
-webkit-box-shadow:
inset 0 0 8px rgba(0,0,0,0.1),
0 0 16px rgba(0,0,0,0.1);
-moz-box-shadow:
inset 0 0 8px rgba(0,0,0,0.1),
0 0 16px rgba(0,0,0,0.1);
box-shadow:
inset 0 0 8px rgba(0,0,0,0.1),
0 0 16px rgba(0,0,0,0.1);
padding: 5px;
background: rgba(255,255,255,0.5);
margin: 0 0 10px 0;
}
</style>
</head>
<body bgcolor="#00FFFF">
<h1 align="center" style="color:#306">DATABASE Adminstrator</h1>
<?php /*include("includes/header.php"); */?>
<?php
//*************************************************************************************************************************************************
//code to insert students in student table initially
if (isset($_POST['upload'])) {
$dept = $_POST['dept'];
$semester = $_POST['semester'];
$section = $_POST['section'];
if($_FILES['csv']['size'] > 0){
if(notnull($semester) && notnull($dept) && notnull($section)){
//get the csv file
$file = $_FILES['csv']['tmp_name'];
$handle = fopen($file,"r");
//loop through the csv file and insert into database
do
{
if (isset($data[0])) {
$sid = mysql_real_escape_string($data[0]);
$password = $data[1];
//echo $sid;
$query = mysql_query("insert into student values('{$sid}','{$password}','','','','','','','','','','','','','','','','{$dept}','{$section}','{$semester}','')");
//***************************************************************
//query for complete student details while reporting college
//$query = mysql_query("insert into student values('{$sid}','{$password}','{$data[2]}','','{$data[3]}','{$data[4]}','','{$data[5]}','{$data[6]}','{$data[7]}','{$data[8]}','{$data[9]}','','','{$data[10]}','{$dept}','{$section}','{$semester}','')");
}
}while ($data = fgetcsv($handle,1000));
if(!empty($data))
$message = "Insert Successful..!";
}
else
{
$message = "Kindly select all fields..!";
}
}
else $message = "Please choose a file to upload..!";
}
//************************************************************************************************************************************************
//code to update student semeter value{once in a semester starting} (department, semester, section, no file needed)
if (isset($_POST['updatesem'])) {
$dept = $_POST['dept'];
$semester = $_POST['semester'];
$section = $_POST['section'];
if(notnull($semester) && notnull($dept) && notnull($section)){
$student = mysql_query("select * from student where dept = '{$dept}' and semester = '{$semester}' and section = '{$section}'");
if($student)
{
$sem = $semester + 1;
while($suid = mysql_fetch_array($subject))
{
$query = mysql_query("update student set semester = '{$sem}' where dept = '{$dept}' and section = '{$section}' ");
}
$message = "Insert Successful..!";
}
else $message = "Updation Failed..!";
}
else
{
$message = "Kindly select all fields..!";
}
//}
//else $message = "Please choose a file to upload..!";
}
//*************************************************************************************************************************************************
//code to insert staff data only once. You can add new staff details at any time (staff id, password, department)
if (isset($_POST['staffupload'])) {
$dept = $_POST['dept'];
if($_FILES['csv']['size'] > 0){
if(notnull($dept)){
//get the csv file
$file = $_FILES['csv']['tmp_name'];
$handle = fopen($file,"r");
//loop through the csv file and insert into database
do
{
if (isset($data[0])) {
$fid = mysql_real_escape_string($data[0]);
$password = $data[1];
//echo $fid;
$query = mysql_query("insert into staff values('{$fid}','{$password}','{$data[2]}','{$data[3]}','','','','','','{$dept}','','')");
}
}while ($data = fgetcsv($handle,1000));
$message = "Insert Successful..!";
}
else
{
$message = "Kindly select all fields..!";
}
}
else $message = "Please choose a file to upload..!";
}
//************************************************************************************************************************************************
//code to update student semeter value{once in a semester starting} (department, semester, section, no file needed)
if (isset($_POST['insertnotify'])) {
$dept = $_POST['dept'];
$semester = $_POST['semester'];
$section = $_POST['section'];
if(notnull($semester) && notnull($dept) && notnull($section)){
$subject = mysql_query("select * from subject where dept = '{$dept}' and semester = '{$semester}' and section = '{$section}'");
if($subject)
{
while($suid = mysql_fetch_array($subject))
{
$query = mysql_query("insert into notify values('','{$suid['suid']}','{$suid['short']}','{$suid['fid']}','{$semester}','{$dept}','{$section}','')");
}
$message = "Insert Successful..!";
}
else $message = "Updation Failed..!";
}
else
{
$message = "Kindly select all fields..!";
}
//}
//else $message = "Please choose a file to upload..!";
}
//************************************************************************************************************************************************
//code to insert 8 subjects for each student of a particular class. (department, semester, section, data from student table)
if (isset($_POST['insertsub'])) {
$dept = $_POST['dept'];
$semester = $_POST['semester'];
$section = $_POST['section'];
//if($_FILES['csv']['size'] > 0){
if(notnull($semester) && notnull($dept) && notnull($section)){
//get the csv file
// $file = $_FILES['csv']['tmp_name'];
//$handle = fopen($file,"r");
//loop through the csv file and insert into database
$student = mysql_query("select * from student where dept = '{$dept}' and semester = '{$semester}' and section = '{$section}'");
if($student)
{
while($sid = mysql_fetch_array($student))
{
$subject = mysql_query("select * from subject where dept = '{$dept}' and semester = '{$semester}' and section = '{$section}'");
if($subject)
{
while($suid = mysql_fetch_array($subject))
$query = mysql_query("insert into marks values('','{$semester}','{$dept}','{$section}','{$suid['suid']}','{$suid['fid']}','{$sid['sid']}','','','','','','','','','','','')");
}
}
$message = "Insert Successful..!";
}
}
else
{
$message = "Kindly select all fields..!";
}
//}
//else $message = "Please choose a file to upload..!";
}
//*************************************************************************************************************************************************
//code to insert attendance for 8 subjects of each student (department, semester, section, data from student table)
if (isset($_POST['insertattendance'])) {
$dept = $_POST['dept'];
$semester = $_POST['semester'];
$section = $_POST['section'];
//if($_FILES['csv']['size'] > 0){
if(notnull($semester) && notnull($dept) && notnull($section)){
//get the csv file
// $file = $_FILES['csv']['tmp_name'];
//$handle = fopen($file,"r");
//loop through the csv file and insert into database
$student = mysql_query("select * from student where dept = '{$dept}' and semester = '{$semester}' and section = '{$section}'");
if($student)
{
while($sid = mysql_fetch_array($student))
{
$subject = mysql_query("select * from subject where dept = '{$dept}' and semester = '{$semester}' and section = '{$section}'");
if($subject)
{
while($suid = mysql_fetch_array($subject))
$query = mysql_query("insert into attendance values('','{$dept}','{$semester}','{$section}','{$suid['suid']}','{$suid['fid']}','{$sid['sid']}','','','','')");
}
}
$message = "Insert Successful..!";
}
}
else
{
$message = "Kindly select all fields..!";
}
//}
//else $message = "Please choose a file to upload..!";
}
//*************************************************************************************************************************************************
//code to insert subject allocated to certain faculty. inserted for every semeter starting.
if (isset($_POST['insertsubject'])) {
//$dept = $_POST['dept'];
//$semester = $_POST['semester'];
//$section = $_POST['section'];
if($_FILES['csv']['size'] > 0){
//if(notnull($semester) && notnull($dept) && notnull($section)){
//get the csv file
$file = $_FILES['csv']['tmp_name'];
$handle = fopen($file,"r");
//loop through the csv file and insert into database
do
{
if (isset($data[0])) {
$suid = mysql_real_escape_string($data[1]);
$sname = mysql_real_escape_string($data[2]);
$credits = mysql_real_escape_string($data[3]);
$fid = mysql_real_escape_string($data[5]);
$semester = mysql_real_escape_string($data[4]);
$section = mysql_real_escape_string($data[6]);
$dept = mysql_real_escape_string($data[7]);
echo $suid;
$query = mysql_query("insert into subject values('','{$suid}','{$sname}','{$credits}','{$semester}','{$fid}','{$section}','{$dept}')");
}
}while ($data = fgetcsv($handle,1000));
if(!empty($data))
$message = "Insert Successful..!";
/*}
else
{
$message = "Kindly select all fields..!";
}*/
}
else $message = "Please choose a file to upload..!";
}
?>
<table width="100%">
<tr>
<td><fieldset><legend>Admin Panel</legend>
<form action="insertdata.php" method="post" enctype="multipart/form-data">
<table><tr><td>
<table><tr><td>
<select name="dept" >
<option <?php if (isset($dept) && $dept=="") echo "selected";?> value="">--Branch--</option>
<option <?php if (isset($dept) && $dept=="CSE") echo "selected";?>>CSE</option>
<option <?php if (isset($dept) && $dept=="CHE") echo "selected";?>>Chemical</option>
<option <?php if (isset($dept) && $dept=="CIV") echo "selected";?>>Civil</option>
<option <?php if (isset($dept) && $dept=="ECE") echo "selected";?>>ECE</option>
<option <?php if (isset($dept) && $dept=="EEE") echo "selected";?>>EEE</option>
<option <?php if (isset($dept) && $dept=="IT") echo "selected";?>>It</option>
<option <?php if (isset($dept) && $dept=="MECH") echo "selected";?>>Mechanical</option>
</select>
</td><td><==></td><td>
<select name="semester">
<option <?php if (isset($semester) && $semester=="") echo "selected";?> value="">--semester--</option>
<option <?php if (isset($semester) && $semester=="1") echo "selected";?>>1</option>
<option <?php if (isset($semester) && $semester=="2") echo "selected";?>>2</option>
<option <?php if (isset($semester) && $semester=="3") echo "selected";?>>3</option>
<option <?php if (isset($semester) && $semester=="4") echo "selected";?>>4</option>
<option <?php if (isset($semester) && $semester=="5") echo "selected";?>>5</option>
<option <?php if (isset($semester) && $semester=="6") echo "selected";?>>6</option>
<option <?php if (isset($semester) && $semester=="7") echo "selected";?>>7</option>
<option <?php if (isset($semester) && $semester=="8") echo "selected";?>>8</option>
</select>
<td><==></td><td>
<select name="section">
<option <?php if (isset($section) && $section == "") echo "selected";?> value="">--section--</option>
<option <?php if (isset($section) && $section == "1") echo "selected";?>>1</option>
<option <?php if (isset($section) && $section == "2") echo "selected";?>>2</option>
<option <?php if (isset($section) && $section == "3") echo "selected";?>>3</option>
<option <?php if (isset($section) && $section == "4") echo "selected";?>>4</option>
</select>
</td><td><=></td>
<td colspan="2"><input type="file" name="csv" id="csv" /></td>
<!--<td><h1> </h1></td><td colspan="2"><input type="submit" name="export" value="Export To Excel" /></td>-->
</tr></table></td></tr>
<tr><td>To Insert Students Initially only once when joining<b>(dept, semester, section and .CSV File)</b></td><td><input type="submit" name="upload" value="Insert" /></td></tr>
<tr><td>To Insert Subjects for every semester all students each with 8 tuples<b>(dept, semester, section)</b></td><td><input type="submit" name="insertsub" value="Insert subjects" /></td></tr>
<tr><td>To Insert Staff Initially only once when joining<b>(dept, and .CSV File)</b></td><td><input type="submit" name="staffupload" value="Insert staff" /></td></tr>
<tr><td>To Insert Subjects with respective faculty Initially for every semester<b>(dept, semester, section and .CSV File)</b></td><td><input type="submit" name="insertsubject" value="Insert subject" /></td></tr>
<tr><td>To Insert Attendance tuples for every student needs 8 tuples for each Initially for every semester<b>(dept, semester, section)</b></td><td><input type="submit" name="insertattendance" value="Insert Attendance" /></td></tr>
<tr><td>To update semester-number of each Student Initially for every semester<b>(dept, completed-semester(not current), section)</b></td><td><input type="submit" name="updatesem" value="Update Semester" /></td></tr>
<tr><td>To Insert notification tuple for each staff of respective class Initially for every semester<b>(dept, semester, section)</b></td><td><input type="submit" name="insertnotify" value="Insert Notify" /></td></tr>
</table></fieldset>
<?php if (!empty($message)) {echo "<tr><td><p id='err' class=\"message\">" . $message . "</p></td></tr>";} ?>
</td></tr></table>
</body>
</html>