-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmembers.php
201 lines (186 loc) · 8.72 KB
/
members.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
<?php include 'includes/head.php' ?>
<body>
<?php
require_once 'config.php';
include 'includes/navbar.php';
include 'includes/setup.php';
?>
<div id='banner_wrapper' class='section_wrapper'>
<!-- Image adapted from http://www.icfsne.com/2016/home -->
<img src='images/banner.jpg' alt='banner'>
</div>
<?php
include 'includes/login.php';
?>
<div id="executives_wrapper" class='section_wrapper'>
<h1>Executive Board</h1>
<?php
if(isset($_POST['add_member']) && isset($_FILES['newphoto'])) {
$new_file = $_FILES['newphoto'];
$original_name = $new_file['name'];
if($new_file['error'] == 0) {
$temp_name = $new_file['tmp_name'];
move_uploaded_file($temp_name, "images/$original_name");
unset($_POST['add_member']);
$field_array = array();
foreach($_POST as $key => $value) {
if(!empty($value)) {
$filtered_value = filter_input(INPUT_POST, "$key", FILTER_SANITIZE_STRING);
$field_array[$key] = "'$filtered_value'";
}
}
$field_name_array = array_keys($field_array);
$field_list = implode(',', $field_name_array);
$field_list .= ",image_url";
$value_list = implode(',', $field_array);
$value_list .= ",'$original_name'";
$sql = "INSERT INTO executives ($field_list) VALUES ($value_list);";
if($mysqli->query($sql)) {
$new_id = $mysqli->insert_id;
echo "<p class='status'>A new member has been added!</p><br>";
}
}
else {
echo "<p class='status'>Error: new member has not been added!</p><br>";
}
}
else if(isset($_POST['edit_member'])) {
$id = filter_input(INPUT_POST, 'select_edit', FILTER_SANITIZE_STRING);
unset($_POST['edit_member']);
unset($_POST['select_edit']);
unset($_POST['newphoto']);
$field_array = array();
foreach($_POST as $key => $value) {
if(!empty($value)) {
$filtered_value = filter_input(INPUT_POST, "$key", FILTER_SANITIZE_STRING);
array_push($field_array, "$key = '$filtered_value'");
}
}
$value_list = implode(',', $field_array);
if(isset($_FILES['newphoto'])) {
$new_file = $_FILES['newphoto'];
$original_name = $new_file['name'];
if($new_file['error'] == 0) {
$temp_name = $new_file['tmp_name'];
move_uploaded_file($temp_name, "images/$original_name");
if($value_list != '') {
$value_list .= ', ';
}
$value_list .= "image_url = '$original_name'";
}
else {
echo "<p class='status'>Error: failed to update photo!</p><br>";
}
}
$sql = "UPDATE executives SET $value_list WHERE id = $id;";
if($mysqli->query($sql)) {
echo "<p class='status'>Member has been updated!</p><br>";
}
else {
echo "<p class='status'>Error: member has not been updated!</p><br>";
}
}
else if(isset($_POST['delete_member'])) {
$id = filter_input(INPUT_POST, 'select_delete', FILTER_SANITIZE_STRING);
$sql = "DELETE FROM executives WHERE id = '$id'";
$result = $mysqli->query($sql);
if($result) {
echo "<p class='status'>A member has been deleted!</p><br>";
}
else {
"<p class='status'>Error: member has not been deleted!</p><br>";
}
}
$query = 'SELECT * FROM executives';
$result = $mysqli->query($query);
$names = array();
$column_count = 0;
echo "<div class='table'><div class='table_row'>";
while($row = $result->fetch_assoc()) {
if($column_count === 3) {
$column_count = 0;
echo "</div><div class='table_row'>";
}
$id = $row['id'];
$name = $row['executive'];
$names[$id] = $name;
$title = $row['title'];
$year = $row['grad_year'];
$description = $row['description'];
$image_url = 'images/' . $row['image_url'];
echo "<div id='$id' class='profile_wrapper'>
<img src='$image_url' alt='$name'>
<h2>$name</h2>
<h3>$title</h3>
<h4>Class of $year</h4>
<div class='description_wrapper'>$description</div>
</div>";
$column_count++;
}
echo "</div></div>";
if(isset($_SESSION['logged_user'])) {
echo "</div><div class='table_row'>
<div class='profile_wrapper'>
<form method='post' enctype='multipart/form-data'>
<input type='file' name='newphoto' required>
<p>Warning: only upload square photos</p>
<input type='text' name='executive' placeholder='Name' required>
<input type='text' name='title' placeholder='Position' required>
<input type='text' name='grad_year' placeholder='Graduation Year (ex. 2019)' required>
<textarea name='description' placeholder='Description'></textarea>
<input type='submit' name='add_member' value='Add Member'>
</form>
</div>
<div class='profile_wrapper'>
<form method='post' enctype='multipart/form-data'>
<select name='select_edit'>";
foreach($names as $id => $name) {
echo "<option value='$id'>$name</option>";
}
echo " </select>
<input type='file' name='newphoto'>
<p>Warning: only upload square photos</p>
<input type='text' name='executive' placeholder='Name'>
<input type='text' name='title' placeholder='Position'>
<input type='text' name='grad_year' placeholder='Graduation Year (ex. 2019)'>
<textarea name='description' placeholder='Description'></textarea>
<input type='submit' name='edit_member' value='Edit Member'>
</form>
</div>
<div class='profile_wrapper'>
<form method='post'>
<select name='select_delete'>";
foreach($names as $id => $name) {
echo "<option value='$id'>$name</option>";
}
echo " </select>
<input type='submit' name='delete_member' value='Delete Member'>
</form>
</div>";
}
echo '</div></div>';
/* mobile version single list */
$result = $mysqli->query($query);
$names = array();
echo "<div id='mobile_members'>";
while($row = $result->fetch_assoc()) {
$id = $row['id'];
$name = $row['executive'];
$names[$id] = $name;
$title = $row['title'];
$year = $row['grad_year'];
$description = $row['description'];
$image_url = 'images/' . $row['image_url'];
echo "<div id='$id' class='mobile_profile_wrapper'>
<img src='$image_url' alt='$name'>
<h2>$name</h2>
<h3>$title</h3>
<h4>Class of $year</h4>
<div class='mobile_description_wrapper'>$description</div>
</div>";
}
echo '</div>';
include 'includes/footer.php';
?>
</body>
</html>