-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdtcourse.php
executable file
·43 lines (40 loc) · 1.24 KB
/
updtcourse.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
<?php
$oldshort = $_POST['oldshort'];
$short = $_POST['short'];
$name = $_POST['name'];
$tenure = $_POST['tenure'];
$var = 1;
$xml = new DOMDocument();
$xml -> load("courseList.xml");
$courseL = $xml -> getElementsByTagName("course");
if($short == "") {
foreach($courseL as $course) {
if($course -> getAttribute('short') == $oldshort) {
$course -> parentNode -> removeChild($course);
}
}
}
else {
$var = 0;
foreach($courseL as $course) {
if($course -> getAttribute('short') == $oldshort) {
$course -> setAttribute('short', $short);
$course -> setAttribute('name', $name);
$course -> setAttribute('period', $tenure);
$var = 1;
}
}
}
if($var == 0) { //if course doesn't previously exist
foreach($xml -> getElementsByTagName("courseList") as $courseL) {
$course = $xml -> createElement('course');
$course -> setAttribute('short', $short);
$course -> setAttribute('name', $name);
$course -> setAttribute('period', $tenure);
$courseL -> appendChild($course);
}
}
print $xml -> save("courseList.xml");
if(isset($_GET['redirectto'])) $redirect = $_GET['redirectto']; else $redirect = "dashboard.php";
header('Location:' . $redirect);
?>