-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd_assignment.php
159 lines (145 loc) · 4.98 KB
/
add_assignment.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
<?php
session_start();
error_reporting(0);
if(!isset($_SESSION['username']))
{
header("location:index.php");
}
elseif($_SESSION['usertype']=='admin')
{
header("location:index.php");
}
$host="localhost";
$user="root";
$password="";
$db="sgs";
$conn=mysqli_connect($host,$user,$password,$db);
if(isset($_POST['create']))
{
$assign_name=mysqli_real_escape_string($conn,$_POST['assign_name']);
$result=mysqli_query($conn,"SHOW TABLES LIKE '".$assign_name."'");
$subject=$_POST['subject'];
$date=$_POST['date'];
if($result->num_rows==1)
{
echo '<script language="javascript">';
echo 'alert("Assignment Already Exists, please try again")';
echo '</script>';
}
else{
/*---------------------------------------File Upload--------------------------------------------------------*/
$type=$_FILES['file']['type'];
$name=$_FILES['file']['name'];
$tmp_name=$_FILES['file']['tmp_name'];
$fileExtension=explode(".",$name);
$fileExtension=end($fileExtension);
$n1=rand(1000,10000);
$n2=date("ymd");
$n3=time();
@$newName=$n1.$n2.$n3.".".$fileExtension;
$upload_dir='assignment/';
$filePath=$upload_dir.$newName;
move_uploaded_file($tmp_name,$filePath);
/*-----------------------------------------------------------------------------------------------------------*/
$create_assign="CREATE TABLE $assign_name(id INT(10) UNSIGNED AUTO_INCREMENT PRIMARY KEY,enroll INT(10),submited DATE,marks INT(10),file VARCHAR(100))";
$sql="INSERT INTO assignment(assignment,subject,duedate,file) VALUES('$assign_name','$subject','$date','$newName')";
$result2=mysqli_query($conn,$create_assign);
$result3=mysqli_query($conn,$sql);
echo '<script language="javascript">';
echo 'alert("Assignment Added Successfully")';
echo '</script>';
}
}
?>
<html>
<head>
<title>Teacher panel</title>
<link rel="stylesheet" type="text/css" href="css/admin-style.css">
<style type="text/css">
label
{
display: inline-block;
text-align: right;
width: 140px;
padding-top: 5px;
padding-bottom: 5px;
font-size: 16px;
}
select,input[type='date']
{
width: 35%;
}
input[type='file']
{
width: 40%;
}
.btn
{
padding: 5px 10px;
background: #fff;
border-color: #de3163;
border-radius: 30px;
}
.btn:hover{
background: #de3163;
color: #fff;
border-radius: 30px;
}
.div_deg
{
background-color: #fcf4a3;
width: 500px;
padding-top: 70px;
padding-bottom: 50px;
border-radius: 40px;
}
</style>
<!----------------------------------------sidebar code------------------------------------->
<?php
include 'teacher_sidebar.php';
?>
<!------------------------------------------------------------------------------------------>
</head>
<body>
<div class="content">
<center>
<h1>Add Assignment</h1>
<div class="div_deg">
<form method="POST" action="#" enctype="multipart/form-data">
<div>
<label>Assignment Name</label>
<input type="text" name="assign_name" required>
</div>
<br>
<div>
<label>Subject</label>
<select name="subject" required>
<option>Select Subject</option>
<option>English</option>
<option>Science</option>
<option>Maths</option>
<option>Hindi</option>
<option>Social Science</option>
<option>Sanskrit</option>
<option>Computer</option>
</select>
</div>
<br>
<div>
<label>Due Date</label>
<input type="date" name="date" required>
</div>
<br>
<div>
<input type="file" name="file" required>
</div>
<br>
<div>
<input type="submit" class="btn" name="create" value="Add">
</div>
</form>
</div>
</center>
</div>
</body>
</html>