-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrecommend.php
executable file
·128 lines (109 loc) · 4.76 KB
/
recommend.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
<form action="feedback.php" method="POST">
<br><label for="filter">Filter: *</label><br>
<input type="text" id="filter" name="filter" placeholder="Name of the Employee">
<input type="submit" id="filterbutton" name="filterbutton" value="Filter"></input><br><br>
<textarea rows="4" cols="50" id="endorsement" name="endorsement" placeholder="Endorse the employee"></textarea><br>
<input type="number" id="employeeid" name="employeeid" min="1" max="5000" placeholder="EmpID">
<input type="submit" id="commentbutton" name="commentbutton" value="Comment">
<input type="submit" id="showbutton" name="showbutton" value="Show Endorsements"><br><br>
</form>
<?php
if (isset($_POST["showbutton"])) {
$employeeid = $_POST['employeeid'];
if (($handle = fopen("endorsements.csv", "r")) !== FALSE) {
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
$num = count($data);
for ($c = 1; $c < $num; $c++) {
if ($data[0] == $employeeid) {
print("$c. " . $data[$c] . '<br>');
}
}
}
fclose($handle);
}
}
if (isset($_POST["commentbutton"])) {
$endorsement = $_POST['endorsement'] . " (written by user:" . $_SESSION["username"] . ")";
$employeeid = $_POST['employeeid'];
$newCsvData = array();
if (($handle = fopen("endorsements.csv", "a+")) !== FALSE) {
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
if ($data[0] == $employeeid) {
array_push($data, $endorsement);
$newCsvData[] = $data;
} else {
$newCsvData[] = $data;
}
}
fclose($handle);
$handle2 = fopen("endorsements.csv", "w");
foreach ($newCsvData as $row) {
fputcsv($handle2, $row);
}
}
}
if (isset($_POST["filterbutton"])) {
$filterstr = $_REQUEST['filter'];
if ($filterstr == ""){
getTable();
}
else{
echo '<table id="table" border="0" cellspacing="2" cellpadding="2">
<tr>
<th> <font face="Arial">ID</font> </th>
<th> <font face="Arial">First Name</font> </th>
<th> <font face="Arial">Middle Name</font> </th>
<th> <font face="Arial">Last Name</font> </th>
</tr>
<br><br>';
if (($handle = fopen("data.csv", "r")) !== FALSE) {
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
$num = count($data);
if (
stristr ($data[1], $filterstr) ||
stristr ($data[2], $filterstr) ||
stristr ($data[3], $filterstr)
) {
for ($c = 0; $c < $num; $c++) {
${'field' . $c} = $data[$c];
}
echo "<tr>
<td>$field0</td>
<td>$field1</td>
<td>$field2</td>
<td>$field3</td>
</tr>";
}
}
fclose($handle);
}
}}
else {
getTable();
}
function getTable() {
echo '<table id="table" border="0" cellspacing="2" cellpadding="2">
<tr>
<th> <font face="Arial">ID</font> </th>
<th> <font face="Arial">First Name</font> </th>
<th> <font face="Arial">Middle Name</font> </th>
<th> <font face="Arial">Last Name</font> </th>
</tr>
<br><br>';
if (($handle = fopen("data.csv", "r")) !== FALSE) {
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
$num = count($data);
for ($c = 0; $c < $num; $c++) {
${'field' . $c} = $data[$c];
}
echo "<tr>
<td>$field0</td>
<td>$field1</td>
<td>$field2</td>
<td>$field3</td>
</tr>";
}
fclose($handle);
}
}
?>