-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeliverc.php
58 lines (54 loc) · 1.85 KB
/
deliverc.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
<!--
+Description: PHP script that, most notably, allows easy editing of requests file.
+Created by : Chris Daves
+Created on : 14 DEC 2017
+Modified by: Sarah Barkley
+-->
<?php
// function: return in file of requests, return associative array of those requests.
function readRequests($fileName)
{
$request;
$fp = fopen($fileName, 'r'); //open the file for reading
$line = fgets($fp); // read lines
$count = 0;
while (!feof($fp)) {
$l = explode(";", $line);
$request[$count]['user'] = $l[0];
$request[$count]['food'] = $l[1];
$request[$count]['comment'] = $l[2];
$request[$count]['time'] = $l[3];
$request[$count]['stat'] = $l[4];
$request[$count]['doneBy'] = $l[5];
$line = fgets($fp);
$count++;
}
fclose($fp);
//close the file
return $request;
}
// function: streamlined way of updated a given request within requests file without leaving function
function updateRequests($user,$time,$requests){
$f = fopen("requests.txt", 'w');
fclose($f);
foreach ($requests as $key => $value) {
$file = fopen("requests.txt","a");
if($requests[$key]["user"]==$user && $requests[$key]["time"]==$time){
$order = $requests[$key]['user'].";".$requests[$key]['food'].";".$requests[$key]["comment"].";".$time.";complete;".$_COOKIE["user"]."\n";
fwrite($file, $order);
fclose($file);
}
else{
$order = $requests[$key]['user'].";".$requests[$key]['food'].";".$requests[$key]["comment"].";".$requests[$key]["time"].";".$requests[$key]["stat"].";".$requests[$key]["doneBy"];
fwrite($file, $order);
fclose($file);
}
}
fclose($file);
}
$r = readRequests("requests.txt");
if(isset($_GET["user"])){
updateRequests($_GET["user"],$_GET["time"],$r);
}
header("location: companyfeed.php");
?>