-
Notifications
You must be signed in to change notification settings - Fork 1
/
ims.php
executable file
·185 lines (173 loc) · 5.11 KB
/
ims.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
<?php
session_start();
include"auth.php";
$mess = '';
include("sett.php");
if(isset($_POST['step']) && $_POST['step'] != ''){ $step = $_POST['step']; }else{ $step = "0"; }
if(isset($_POST['name']) && $_POST['name'] != ''){ $step = '1'; }else{ $step = "0";if(isset($_POST['step'])){ if($_POST['step'] == '1'){$mess = "<div align='center' class='errd'>subject cannot be left blank!</div>"; }}}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Import students into a subject</title>
<style type="text/css">
.chk {
width: 25px;
height: 25px;
background-color:#FFCCCC;
color:Green;
border:0px dotted #00f;
}
.chk2 {
width: 25px;
height: 25px;
background-color:#FFCCCC;
color:Red;
border:0px dotted #00f;
font-size:34px;
font-weight:bold;
}
body{
background-color:#FFCCFF;
font-family:Arial, Helvetica, sans-serif;
}
.tb2{
background-color: #FFCCFF;
border:#FF66FF dashed 2px;
padding:20px;
}
.btns{
background:#FF66FF;
font-weight:bold;
border:#FF99FF double 2px;
padding:5px;
}
.btns:hover{
background: #FF33FF;
cursor:pointer;
}
.tb3{
background:#FFCCCC;
padding:20px;
border: dashed #FF00CC 3px;
}
.errd{
color:#FF0000;
font-size:large;
}
.tds{
border:#FF6699 1px solid;
padding:4px;
}
.tds:hover{
border:#FF6699 2px solid;
padding:3px;
}
</style>
</head>
<body bgcolor="#FFFF99">
<?php if($step == "0"){ ?>
<h1><center>Import Students</center></h1><hr />
You are here: <a href="index.php">Home</a> > <a href="ims.php">Import students</a> ><b> Step 1</b>
<hr />
<?php echo($mess); ?>
<form action="" method="POST" enctype="multipart/form-data">
<table width="600" border="0" align="center" class="tb2">
<tr>
<td><b>Subject</b></td>
<td><b> : </b></td>
<td><select name="name">
<option></option>
<?php
$con = mysql_connect($host,$user,$pass);
if (!$con)
{
die('Could not connect contact admin!');
}
mysql_select_db($db, $con);
if($_SESSION['usid'] == 'admin'){
$result = mysql_query("SELECT * FROM cou");
while($row = mysql_fetch_array($result))
{
$sun = $row['name'];
list($user, $asscads) = explode("vinaycksproject",$sun);
echo("<option value=\"".$sun."\">Faculty:".$user." Sub:".$asscads."</option>");
}} else {
$result = mysql_query("SELECT * FROM cou");
while($row = mysql_fetch_array($result))
{
$sun = $row['name'];
list($user, $asscads) = explode("vinaycksproject",$sun);
if($asscads != '' && $user == $_SESSION['usid']){
echo("<option value=\"".$sun."\">".$asscads."</option>");
}}}
mysql_close($con);
?>
</select>
</td>
</tr>
<tr>
<td><b>Students Data File</b></td>
<td><b> : </b></td>
<td><input type="file" name="file" id="file" /></td>
</tr>
<tr>
<td colspan="3"><center><input type="hidden" name="step" value="1" />
<input class="btns" type="submit" /></center></td>
</tr>
</table>
</form>
<?php } else if($step == "1") { echo($mess);
$name = $_POST['name'];
$con = mysql_connect($host,$user,$pass);
if (!$con)
{
die('Could not connect. contact admin!');
}
mysql_select_db($db, $con);
//start of upload
if($_FILES["file"]["error"] > 0){
die("<div align='center' class='errd'>No such file found!</div>");
}
$filea = $_FILES["file"]["tmp_name"];
$row = 1;
if (($handle = fopen($filea, "r")) !== FALSE) {
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
$num = count($data);
if($num != '3'){die("<div align='center' class='errd'>invalid csv excel file!</div>");}
$rn = $data[0];
$us = $data[1];
$nm = $data[2];
$int="INSERT INTO ".$name." (srn, rollnum, usn, name) VALUES ('$row' ,'$rn','$us', '$nm')";
$row++;
if(!mysql_query($int)){die("error! there is no subject like that!<br /><a href='index.php'>Home</a>");}
}
fclose($handle);
}
$row--;
if($row <= 0){echo("<div align='center' class='errd'>No such file found!<br /><a href='index.php'>Home</a></div>");}else{
?>
<h1><center>Import Students</center></h1><hr />
You are here: <a href="index.php">Home</a> > <a href="ims.php">Import students</a> ><b> Success</b>
<hr />
<div align="center"><h3>Successfully Imported <?php echo $row; ?> students from the excel!</h1><br /><a href='index.php'>Home</a></div>
<?php
mysql_query("UPDATE num SET num = '$row' WHERE name = '$name'");
}
mysql_close($con);
?>
<?php }else{?>
<h1><center>Import Students</center></h1><hr />
You are here: <a href="index.php">Home</a> > <a href="ims.php">Import students</a> ><b> Error</b>
<hr />
<div align="center" class="errd">
<h1>Error encountered please try again. Sorry!</h1><br />
<a href="index.php">Home</a></div>
<?php } ?>
<br />
<br />
<hr />
<center><a style="text-decoration:none;" href="credits.html">----[ © VINAY C K ] [ Developed by VINAY C K ] [[email protected]]----</a></center>
</body>
</html>