-
Notifications
You must be signed in to change notification settings - Fork 0
/
descriptionpost.php
111 lines (78 loc) · 2.79 KB
/
descriptionpost.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
<?php
//EDIT HERE FOR EVERY ASSIGNMENT, TEST, ETC.
$savecontent = $_POST['description'];
$course = $_POST["course"];
//EDIT HERE FOR EVERY ASSIGNMENT, TEST, ETC.
$loadcontent = $course."/info/description.txt";
$savecontent = stripslashes($savecontent);
$fp = fopen($loadcontent, "w");
fwrite($fp, $savecontent);
fclose($fp);
$course = $_POST["course"];
if($_FILES['savefile']['name'] != ""){
//ADD FILE
$target_dir = $course."/assignments/".$_FILES["savefile"]["name"];
$ext = pathinfo($_FILES["savefile"]["name"], PATHINFO_EXTENSION);
// Check if image file is a PNG image
if($ext == "doc" || $ext == "docx" || $ext == "xls" || $ext == "ppt"){
//ERROR
$trimCourse = preg_replace('/\s+/', '', $course);
//$target_file = $target_dir .".". $ext;
$target_file = $target_dir;
//WRITE TO XML FILE THE FILE NAME
$xml= simplexml_load_file("courses.xml") or die("Error: Cannot create object");
$courseArray = $xml->course;
for($i = 0; $i < count($courseArray); $i++){
$theCourse = $courseArray[$i]['name'];
if($theCourse != $trimCourse){
continue;
}
else{
//APPEND COURSE
//SYNTAX -- $xml->ELEMENT->CHILD
// Add a file name to the file element
if( empty($xml->course[$i]->file) ){
//EDIT HERE FOR EVERY ASSIGNMENT, TEST, ETC.
$xml->course[$i]->addChild("file", $target_file)->addAttribute("id", "description");
}
else{
$xml->course[$i]->file[0] = $target_file;
}
$dom = new DOMDocument('1.0');
$dom->preserveWhiteSpace = false;
$dom->formatOutput = true;
$dom->loadXML($xml->asXML());
echo $dom->saveXML();
$dom->save("courses.xml");
}
}
if(move_uploaded_file($_FILES["savefile"]["tmp_name"], $target_file) ){
echo '<script>
function checkFile(){
var msg = document.getElementById("message");
message.style.backgroundColor = "#5fa918";
msg.innerHTML = "Yes! File uploaded successfully"
}
window.checkFile();
</script>
';
}
else{
echo '<script>
function checkFile(){
var msg = document.getElementById("message");
message.style.backgroundColor = "#a94442";
msg.innerHTML = "Sorry, there was an error uploading the file."
}
window.checkFile();
</script>
';
}
}
else{
echo "Your file must be a .doc, .docx, .xls or .ppt.";
}
}
$location = "editcourse.php?key=".$course;
echo '<META HTTP-EQUIV="Refresh" Content="0; URL='.$location.'" />';
?>