-
Notifications
You must be signed in to change notification settings - Fork 0
/
upload.php
221 lines (198 loc) · 5.92 KB
/
upload.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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
<?php
session_start();
$usernameSession=$_SESSION['username'];
$url = parse_url(getenv("CLEARDB_DATABASE_URL"));
$server = $url["host"];
$username = $url["user"];
$password = $url["pass"];
$db = substr($url["path"], 1);
$location = null;
$error = false;
try {
$database = new PDO("mysql:host=$server;dbname=$db", $username, $password);
// set the PDO error mode to exception
$database->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch(PDOException $e) {
if ($e -> getcode() == 23000) {
echo "The username has already exist.";
}
else {
print($e->getMessage());
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title></title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<?php
//function to print an editing schedule table.
function printEditingSchedule($array){
echo "<form action='showedited.php' method='post' enctype='multipart/form-data'>";
echo "<table>";
echo "<tr>"; // start of headers
echo "<td class='header'></td>";
foreach($array["Monday"]as $subkey=>$subvalue){
echo "<td class='header'>".$subkey."</td>";
}
echo"</tr>";
foreach($array as $day=>$value){
//start of printing the values
echo "<tr>";
echo "<td class='day'>".$day."</td>"; // print day
foreach($value as $subkey=>$subvalue){
if($subvalue==0){
echo "<td class='free'><input type='checkbox' name='userinput[$day][$subkey]' value={$day}T$subkey></td>";
} else {
echo "<td class='busy'>BUSY!</td>";
}
}
echo "</tr>";
}
echo "</table>";
echo "<input type='submit' value='Submit'>";
}
require_once("main_ics_processer.php");
$user = array(); // Creating an array of user object. 0 index indicates the first user in the array.
$target_dir = "uploads/";
// Count # of uploaded files in array
$total = count($_FILES['fileToUpload']['name']);
// Loop through each file
for($i=0; $i<$total; $i++) {
//Get the temp file path
$tmpFilePath = $_FILES['fileToUpload']['tmp_name'][$i];
//Make sure we have a filepath
if ($tmpFilePath != ""){
//Setup our new file path
$temp = explode(".", $_FILES["fileToUpload"]["name"][$i]);
$date = date_create();
$newfilename = date_timestamp_get($date).$_FILES['fileToUpload']['name'][$i];
$newFilePath = "uploads/" . $newfilename;
}
}
//$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]["index"]);
$uploadOk = 1;
$FileType = pathinfo($newFilePath,PATHINFO_EXTENSION);
// Check if the file is .ics
if(isset($_POST["submit"])) {
if($FileType == "ics") {
$uploadOk = 1;
} else {
echo "File is not a calendar file (.ics).";
$uploadOk = 0;
}
}
// Check file size
// repeat for all files
for($i=0; $i<$total; $i++) {
//Get the temp file path
$tmpFilePath = $_FILES['fileToUpload']['tmp_name'][$i];
if ($tmpFilePath != ""){
//Setup our new file path
$temp = explode(".", $_FILES["fileToUpload"]["name"][$i]);
$date = date_create();
$newfilename = date_timestamp_get($date).$_FILES['fileToUpload']['name'][$i] . '.' . end($temp);
$newFilePath = "uploads/" . $newfilename;
}
if ($_FILES["fileToUpload"]["size"][$i] > 500000) {
echo "Sorry, your file is too large.";
$uploadOk = 0;
}
}
// Check if $uploadOk is set to 0 by an error
// repeat or all the files
for($i=0; $i<$total; $i++) {
//Get the temp file path
$tmpFilePath = $_FILES['fileToUpload']['tmp_name'][$i];
if ($tmpFilePath != ""){
//Setup our new file path
$temp = explode(".", $_FILES["fileToUpload"]["name"][$i]);
$date = date_create();
$newfilename = date_timestamp_get($date).$_FILES['fileToUpload']['name'][$i];
$newFilePath = "uploads/" . $newfilename;
}
if ($uploadOk == 0) {
echo "Sorry, your file was not uploaded.";
echo "<h2> Click <a href='dashboard.php'>here</a> to go back</h2>";
exit();//Prevent the code from continue running.
// if everything is ok, try to upload file
} else {
if (
move_uploaded_file($tmpFilePath, $newFilePath)) {
echo "The file ". basename( $_FILES["fileToUpload"]["name"][$i]). " has been uploaded.";
//Updating the file name in SQL.
$sql="UPDATE userid SET filename= '$newfilename' WHERE username='$usernameSession'";
$stmt = $database->prepare($sql);
$stmt->execute();
} else {
echo "Sorry, there was an error uploading your file.";
}}
if(isset($newFilePath)){
$user[$i]= new user($newFilePath);
$user[$i]->allfunctionsprocessing();
}
}
//Creating freeTimeArray
$dayArray = array(
"0600"=>0,
"0630"=>0,
"0700"=>0,
"0730"=>0,
"0800"=>0,
"0830"=>0,
"0900"=>0,
"0930"=>0,
"1000"=>0,
"1030"=>0,
"1100"=>0,
"1130"=>0,
"1200"=>0,
"1230"=>0,
"1300"=>0,
"1330"=>0,
"1400"=>0,
"1430"=>0,
"1500"=>0,
"1530"=>0,
"1600"=>0,
"1630"=>0,
"1700"=>0,
"1730"=>0,
"1800"=>0,
"1830"=>0,
"1900"=>0,
"1930"=>0,
"2000"=>0,
"2030"=>0,
"2100"=>0,
"2130"=>0,
"2200"=>0,
"2230"=>0,
"2300"=>0,
"2330"=>0);
// Array for the weekArray
$freeTimeArray = array(
"Monday" => $dayArray,
"Tuesday" => $dayArray,
"Wednesday" => $dayArray,
"Thursday" => $dayArray,
"Friday" => $dayArray,
"Saturday" => $dayArray,
"Sunday" => $dayArray);
for($j=0;$j<$total;$j++){
comparison($user[$j]->weekArray, $freeTimeArray);
}
/*
echo "<br><br>=======Free Time Array=======<br><br>";
printTableArray($freeTimeArray);*/
//To print a table for editing schedule.
echo "<br><br>=======Table to edit time=======<br><br>";
printEditingSchedule($freeTimeArray);
//Editing Schedule!
?>
<h2> Click <a href="index.php">here</a> to go back</h2>
</body>
</html>