Add interests/events page (close #12)

master
Skylar Ittner 5 years ago
parent 1dd87ab62a
commit f256415fc0

@ -211,4 +211,25 @@ switch ($VARS['action']) {
returnToSender("family_doesnt_exist");
}
break;
case "editevents":
if (!(new User($_SESSION['uid']))->hasPermission("HACHEPORTAL_EDIT")) {
returnToSender("no_permission");
}
foreach ($_POST['events'] as $k => $v) {
if ($database->has("events", ["eventid" => $k])) {
if (empty($v)) {
$database->delete("interests", ["eventid" => $k]);
$database->delete("events", ["eventid" => $k]);
continue;
}
$database->update("events", ["event" => $v], ["eventid" => $k]);
} else {
if (empty($v)) {
continue;
}
$database->insert("events", ["event" => $v]);
}
}
returnToSender("events_updated");
}

@ -23,5 +23,8 @@
"Adding Family": "Adding Family",
"Editing Family": "Editing {family} Family",
"Recent Payments": "Recent Payments",
"Interests": "Interests"
"Interests": "Interests",
"Event List": "Event List",
"Popularity": "Popularity",
"Event": "Event"
}

@ -6,5 +6,6 @@
"Are you sure you want to delete this family?": "Are you sure you want to delete this family?",
"This action cannot be undone! All information about this family, including payment history, will be purged forever.": "This action cannot be undone! All information about this family, including payment history, will be purged forever.",
"To remove a child, delete the contents of the Name box.": "To remove a child, delete the contents of the Name box.",
"No interests selected.": "No interests selected."
"No interests selected.": "No interests selected.",
"Events updated.": "Events updated."
}

@ -4,5 +4,6 @@
"Members": "Members",
"View Family": "View Family",
"Family": "Family",
"Delete Family": "Delete Family"
"Delete Family": "Delete Family",
"Events": "Events"
}

@ -32,5 +32,9 @@ define("MESSAGES", [
"family_deleted" => [
"string" => "Family deleted.",
"type" => "success"
],
"events_updated" => [
"string" => "Events updated.",
"type" => "success"
]
]);

@ -36,6 +36,14 @@ define("PAGES", [
"confirmdelete" => [
"title" => "Delete Family"
],
"events" => [
"title" => "Events",
"navbar" => true,
"icon" => "fas fa-volleyball-ball",
"scripts" => [
"static/js/events.js"
],
],
"404" => [
"title" => "404 error"
]

@ -0,0 +1,128 @@
<?php
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
redirectIfNotLoggedIn();
$user = new User($_SESSION['uid']);
if (!$user->hasPermission("HACHEPORTAL_VIEW")) {
header("Location: ./app.php?msg=no_permission");
die();
}
$editpermission = $user->hasPermission("HACHEPORTAL_EDIT");
$editable = ($editpermission && !empty($_GET['edit']));
$events = $database->select('events', ['eventid (id)', 'event (name)']);
?>
<div class="row">
<div class="col-sm-6">
<div class="card">
<div class="card-header">
<h4>
<i class="fas fa-sort-amount-up"></i>
<?php $Strings->get("Popularity"); ?>
</h4>
</div>
<ul class="list-group list-group-flush">
<li class="list-group-item d-flex justify-content-between">
<b><?php $Strings->get("Event"); ?></b>
<b><?php $Strings->get("Families"); ?></b>
</li>
<?php
$interests = $database->select("interests", ["[>]events" => ['eventid' => 'eventid']], ['interests.eventid (id)', 'events.event (name)']);
$ranking = [];
$rankingtitles = [];
foreach ($interests as $ev) {
if (empty($ranking[$ev['id']])) {
$ranking[$ev['id']] = 1;
$rankingtitles[$ev['id']] = $ev['name'];
} else {
$ranking[$ev['id']] ++;
}
}
arsort($ranking);
foreach ($ranking as $k => $v) {
?>
<li class="list-group-item d-flex justify-content-between">
<span><?php echo $rankingtitles[$k]; ?></span>
<span><?php echo $v; ?></span>
</li>
<?php
}
?>
</ul>
</div>
</div>
<div class="col-sm-6">
<?php if ($editable) { ?>
<form action="action.php" method="POST">
<input type="hidden" name="action" value="editevents" />
<input type="hidden" name="source" value="events" />
<?php } ?>
<div class="card">
<div class="card-header">
<h4 class="d-flex justify-content-between">
<span>
<i class="fas fa-list-ul"></i>
<?php $Strings->get("Event List"); ?>
</span>
<?php if ($editpermission && !$editable) { ?>
<span>
<a class="btn btn-primary btn-sm" href="./app.php?page=events&edit=1">
<i class="fas fa-edit"></i>
<?php $Strings->get("Edit"); ?>
</a>
</span>
<?php } ?>
</h4>
</div>
<ul class="list-group list-group-flush">
<?php
foreach ($events as $ev) {
?>
<li class="list-group-item py-0 px-1">
<?php
if ($editable) {
?>
<input type="text" class="form-control form-control-sm" name="events[<?php echo $ev['id']; ?>]" value="<?php echo htmlspecialchars($ev['name']); ?>" />
<?php
} else {
echo $ev['name'];
}
?>
</li>
<?php
}
?>
<?php
if ($editable) {
for ($i = 0; $i < 5; $i++) {
?>
<li class="list-group-item py-0 px-1">
<input type="text" class="form-control form-control-sm" name="events[]" value="" />
</li>
<?php
}
}
?>
</ul>
<?php if ($editable) { ?>
<div class="card-footer">
<button type="submit" class="btn btn-success"><i class="fas fa-save"></i> <?php $Strings->get("Save"); ?></button>
</div>
<?php } ?>
</div>
<?php if ($editable) { ?>
</form>
<?php } ?>
</div>
</div>
Loading…
Cancel
Save