-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsettings.php
305 lines (217 loc) · 8.33 KB
/
settings.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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
<?php
error_reporting(0);
session_start();
if(isset($_SESSION['username']) && !empty($_SESSION['username'])){
$session = $_SESSION['username'];
} else {
header('Location: index.php?error=login');
}
require_once('inc/functions.php');
require_once('inc/config.php');
if (!file_exists('sc_projects') || empty($dbName) || !tablesExist($pdo)) {
header('Location: install.php');
exit();
}
$sectionsInUse = getSectionsInUse($pdo);
$allSections = getAllSections($pdo);
$sectionsNotInUse = [];
foreach ($allSections as $section){
$inUse = false;
foreach ($sectionsInUse as $sec){
if($sec['section_name'] === $section['section_name']){
$inUse = true;
}
}
if(!$inUse){
array_push($sectionsNotInUse, $section);
}
}
$projectsWithoutSections = getProjectsWithoutSections($pdo);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<title>Settings | ShowCase</title>
<?php require_once('inc/inc.php'); ?>
</head>
<body>
<?php require_once('inc/msg.php'); ?>
<div class="container">
<header>
<h2>Settings</h2>
<nav>
<?php if(!empty($admin)){
if(isset($session) && !empty($session)){ ?>
<a href="manage.php?method=add">manage projects</a>
<a class="active" href="settings.php">settings</a>
<a href="logout.php">logout</a>
<?php } else { ?>
<a class="login-btn" href="#">login</a>
<?php } ?>
<?php } ?>
</nav>
<span class="back-to-link">
<a href="index.php"><i class="fa fa-long-arrow-left"></i> back to ShowCase</a>
</span>
<hr>
</header>
<div class="col col-md-4">
<div class="showcase-box settings-box">
<span class="showcase-tooltip">
<i class="fa fa-info-circle add-edit-tt pull-right"></i>
<span class="tooltip-text project-order-tt-text pull-right">
<i class="fa fa-times pull-right close-edit-tt"></i>
Move your projects and sections up/down
</span>
</span>
<h3>Project Order</h3>
<?php
if(isset($sectionsInUse) && !empty($sectionsInUse)){
$lastSectionId = false;
$topSection = true;
$lastSection = false;
$sectionCount = 0;
foreach($sectionsInUse as $section){
$sectionCount++;
if(!$lastSectionId){
$topSection = true;
} else {
$topSection = false;
}
if($sectionCount === sizeof($sectionsInUse)){
$lastSection = true;
$nextSectionPos = false;
} else {
$nextSectionPos = $sectionsInUse[$sectionCount]['section_pos'];
}
echo '<h4 class="section-header">' . $section['section_name'] . '</h4>';
echo (!$topSection) ? "<a class='move-up-button' title='Move " . $section['section_name'] . " Section Up' href='inc/settings.php?method=section_swap&swap=". $section['section_pos'] . "&with=$lastSectionId'><i class='fa fa-chevron-up'></i></a>" : '';
echo (!$lastSection) ? "<a class='move-down-button' title='Move " . $section['section_name'] . " Section Down' href='inc/settings.php?method=section_swap&swap=". $section['section_pos'] . "&with=$nextSectionPos'><i class='fa fa-chevron-down'></i></a>" : '';
$lastSectionId = $section['section_pos'];
$projects = getProjectsBySection($section['section_id'], $pdo);
$lastId = false;
$top = true;
$last = false;
$count = 0;
foreach($projects as $project){
$count++;
if(!$lastId){
$top = true;
} else {
$top = false;
}
if($count === sizeof($projects)){
$last = true;
$nextId = false;
} else {
$nextId = $projects[$count]['pos'];
}
echo '<div>' . $project['name'];
echo (!$top) ? "<a class='move-up-button' title='Move " . $project['name'] . " Up' href='inc/settings.php?method=project_swap&swap=". $project['pos'] . "&with=$lastId'><i class='fa fa-chevron-up'></i></a>" : '';
echo (!$last) ? "<a class='move-down-button' title='Move " . $project['name'] . " Down' href='inc/settings.php?method=project_swap&swap=". $project['pos'] . "&with=$nextId'><i class='fa fa-chevron-down'></i></a>" : '';
echo '</div>';
$lastId = $project['pos'];
} // end foreach each project without sections
if($sectionCount !== sizeof($sectionsInUse)){
echo '<hr>';
}
} // end for each section in use
} // end if sections in use
if(isset($projectsWithoutSections) && !empty($projectsWithoutSections)){
echo '<hr>';
if(isset($sectionsInUse) && !empty($sectionsInUse)){
echo '<h4>Other</h4>';
}
if(sizeof($projectsWithoutSections) === 1){
echo '<div>' . $projectsWithoutSections[0]['name'] . '</div>';
} else {
$lastId = false;
$top = true;
$last = false;
$count = 0;
foreach($projectsWithoutSections as $project){
$count++;
if(!$lastId){
$top = true;
} else {
$top = false;
}
if($count === sizeof($projectsWithoutSections)){
$last = true;
$nextId = false;
} else {
$nextId = $projectsWithoutSections[$count]['pos'];
}
echo '<div>' . $project['name'];
echo (!$top) ? "<a class='move-up-button' title='Move " . $project['name'] . " Up' href='inc/settings.php?method=project_swap&swap=". $project['pos'] . "&with=$lastId'><i class='fa fa-chevron-up'></i></a>" : '';
echo (!$last) ? "<a class='move-down-button' title='Move " . $project['name'] . " Down' href='inc/settings.php?method=project_swap&swap=". $project['pos'] . "&with=$nextId'><i class='fa fa-chevron-down'></i></a>" : '';
echo '</div>';
$lastId = $project['pos'];
} // end foreach each project without sections
}
}
/*
If no projects in use at all!
*/
if(empty($projectsWithoutSections) && empty($sectionsInUse)){
echo '<span class="light-gray">You have no projects in your ShowCase</span>';
}
?>
</div> <!-- end showcase box -->
</div>
<div class="col col-md-4 col-md-offset-4">
<div class="showcase-box settings-box">
<span class="showcase-tooltip pull-right">
<i class="fa fa-info-circle pull-right add-edit-tt"></i>
<span class=" tooltip-text delete-section-tt pull-left">
<i class="fa fa-times pull-right close-edit-tt"></i>
Deleting sections here will only remove the section name
<br> --- <br>
It will not delete any projects from your ShowCase
</span>
</span>
<h4>Manage Sections</h4>
<p>
Sections in use:
</p>
<?php if(isset($sectionsInUse) && !empty($sectionsInUse)){ ?>
<ul>
<?php foreach($sectionsInUse as $section){ ?>
<li>
<?php echo $section['section_name'];?> <a title="Delete <?php echo $section['section_name'];?> Section" class="red-link delete-section-link" href="inc/settings.php?method=delete_section§ion_id=<?php echo $section['section_id'];?>">
<i class="fa fa-trash-o delete"></i>
</a>
</li>
<?php } // end foreach sections ?>
</ul>
<?php } else { // end if $sectionsInUse set?>
<span class="light-gray">You are not using any sections</span>
<?php } // end else $sectionsInUse not set?>
<hr>
<p>
Sections not in use:
</p>
<?php if(isset($sectionsNotInUse) && !empty($sectionsNotInUse)){ ?>
<ul>
<?php foreach($sectionsNotInUse as $section){ ?>
<li>
<?php echo $section['section_name'];?> <a title="Delete <?php echo $section['section_name'];?> Section" class="red-link delete-section-link" href="inc/settings.php?method=delete_section§ion_id=<?php echo $section['id'];?>">
<i class="fa fa-trash-o delete"></i></a>
</li>
<?php } // end foreach sections ?>
</ul>
<?php } else { // end if $sections set?>
<span class="light-gray">You have no unused sections.</span>
<?php } // end else $sections not set?>
</div> <!-- end showcase box -->
</div>
<?php require_once('inc/footer.php'); ?>
</div> <!-- end container -->
<?php require_once('inc/login_box.php'); ?>
</body>
</html>