-
Notifications
You must be signed in to change notification settings - Fork 0
/
addstudent.php
175 lines (118 loc) · 4.51 KB
/
addstudent.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
<?php include 'header.php' ?>
<div id = "content">
<h1><?php if(isset($course)){ echo $course;} ?></h1>
<br/><br/>
<form method="post" class="form" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>">
<h1>Add The Student</h1>
<br/><br/>
Student ID: <select name="id" required ><br/><br/>
<option value="">Choose..</option>
<option value="1">Khalil Greenidge</option>
<option value="2">Scott Henry</option>
<!--?php
$con = mysql_connect("localhost", "root", "");
$db = mysql_select_db("sis");
$division = $_SESSION["division"];
$rs = mysql_query("SELECT * FROM students WHERE division_id1=$division OR division_id2=$division");
if(!$con || !$db || !$rs){
die('Error: '.mysql_error());
}
else{
//PRINT MESSAGE
while($row = mysql_fetch_array($rs)){
echo "<option value=' ".$row["id"]."'>".$row["id"]."</option>
";
}
}
?-->
</select><br/>
<div id="bubble" class="bubble" style="margin: 15px;">
<p id="message" class="message" style="padding: 10px; text-align: center; color: white; border-radius: 15px" ></p>
</div><br/><br/>
<input type="hidden" name="course" value="<?php echo $course; ?>"/>
<input type="submit" value="Save"/> <input type="reset" value="Reset" /><br/>
</form>
<?php
$msg = $id = $firstname = $lastname = $error = "";
if($_SERVER["REQUEST_METHOD"] == "POST"){
//GET FORM DATA
$id = $_POST["id"];
$course = $_POST["course"];
//WRITE TO STUDENT XML FILE -- USED FOR STUDENTS MENU
$xml= simplexml_load_file("students.xml") or die("Error: Cannot create object");
print_r($xml);
$studentArray = $xml->student;
for($i = 0; $i < count($studentArray); $i++){
$theStudent = $studentArray[$i]['id'];
if($theStudent != $id){
continue;
}
else{
//APPEND COURSE
//$xml->ELEMENT->CHILD
// Add a child element(called course) to the student element
$xml->student[$i]->addChild("course",$course);
$dom = new DOMDocument('1.0');
$dom->preserveWhiteSpace = false;
$dom->formatOutput = true;
$dom->loadXML($xml->asXML());
echo $dom->saveXML();
$dom->save("students.xml");
echo '<div id="ani" class="success"><img src="imgs/tick.png"/>Success, student added to your '.$course.'! </div>';
}
}
//REFRESH
$location = 'addstudent.php?key='.$course;
//echo '<META HTTP-EQUIV="Refresh" Content="7; URL='.$location.'" />';
/*
//ESTABLISH CONNECTION
$con = mysql_connect("localhost", "root", "");
//CONNECT TO DB
$db = mysql_select_db("sis");
$trimCourse = preg_replace('/\s+/', '', $course);
//EXTRACT RESULTSET
$rs = mysql_query("SELECT student_id FROM $trimCourse WHERE student_id=$id ");
if(!$con || !$db || !$rs ){
die('Error: '.mysql_error());
}
else{
if(mysql_num_rows($rs) == 0){
$rs = mysql_query("INSERT INTO $trimCourse(student_id) values($id) ") or die('Error: '.mysql_error());
//WRITE TO STUDENT XML FILE -- USED FOR STUDENTS MENU
$xml= simplexml_load_file("students.xml") or die("Error: Cannot create object");
$studentArray = $xml->student;
for($i = 0; $i < count($studentArray); $i++){
$theStudent = $studentArray[$i]['id'];
if($theStudent != $id){
continue;
}
else{
//APPEND COURSE
//$xml->ELEMENT->CHILD
// Add a child element(called course) to the student element
$xml->student[$i]->addChild("course",$course);
$dom = new DOMDocument('1.0');
$dom->preserveWhiteSpace = false;
$dom->formatOutput = true;
$dom->loadXML($xml->asXML());
$dom->saveXML();
$dom->save("students.xml");
echo '<div id="ani" class="success"><img src="imgs/tick.png"/>Success, student added to your '.$course.'! </div>';
}
}
//REFRESH
$location = 'addstudent.php?key='.$course;
echo '<META HTTP-EQUIV="Refresh" Content="7; URL='.$location.'" />';
}
else{
//REFRESH
$location = 'addstudent.php?key='.$course;
echo '<div id="ani" class="error"><img src="imgs/x.png"/>Error, student already added to your class.</div>';
echo '<META HTTP-EQUIV="Refresh" Content="7; URL='.$location.'" />';
}
}
*/
}
?>
</div>
<?php include 'footer.php';?>