25327e3302
[events.php](/Users/tyemeclifford/Documents/GH/MyKeyser/events.php) and [admin/events.php](/Users/tyemeclifford/Documents/GH/MyKeyser/admin/events.php): event image uploads. [menu.php](/Users/tyemeclifford/Documents/GH/MyKeyser/menu.php), [admin/menus.php](/Users/tyemeclifford/Documents/GH/MyKeyser/admin/menus.php), and [business.php](/Users/tyemeclifford/Documents/GH/MyKeyser/business.php): one configurable menu item image slot. [account.php](/Users/tyemeclifford/Documents/GH/MyKeyser/account.php): circular avatar upload and crop controls. [forum.php](/Users/tyemeclifford/Documents/GH/MyKeyser/forum.php), [admin/forum.php](/Users/tyemeclifford/Documents/GH/MyKeyser/admin/forum.php), [.htaccess](/Users/tyemeclifford/Documents/GH/MyKeyser/.htaccess), and [forum/index.php](/Users/tyemeclifford/Documents/GH/MyKeyser/forum/index.php): forum, categories, topic/reply uploads, permalinks, toggle/moderation. [includes/db.php](/Users/tyemeclifford/Documents/GH/MyKeyser/includes/db.php) and [includes/functions.php](/Users/tyemeclifford/Documents/GH/MyKeyser/includes/functions.php): schema upgrades and shared upload/image helpers. [assets/css/style.css](/Users/tyemeclifford/Documents/GH/MyKeyser/assets/css/style.css): neon styling for forum, images, avatars, attachments.
145 lines
11 KiB
PHP
145 lines
11 KiB
PHP
<?php
|
||
require_once dirname(__DIR__).'/includes/boot.php';
|
||
requireAdmin();
|
||
$adminTitle = 'Events';
|
||
|
||
if (isPost()) {
|
||
csrfCheck();
|
||
$act = p('_act');
|
||
|
||
if ($act === 'approve') { qrun("UPDATE events SET status='approved' WHERE id=?",[(int)p('id')]); flash('Event approved!','success'); go('/admin/events.php'); }
|
||
if ($act === 'reject') { qrun("UPDATE events SET status='rejected' WHERE id=?",[(int)p('id')]); flash('Event rejected.','success'); go('/admin/events.php'); }
|
||
if ($act === 'delete') { qrun("DELETE FROM events WHERE id=?",[(int)p('id')]); flash('Event deleted.','success'); go('/admin/events.php'); }
|
||
if ($act === 'feature') { qrun("UPDATE events SET is_featured=1-is_featured WHERE id=?",[(int)p('id')]); go('/admin/events.php'); }
|
||
|
||
if ($act === 'add' || $act === 'edit') {
|
||
$id = (int)p('id');
|
||
$existing = $act === 'edit' ? qone("SELECT image_path FROM events WHERE id=?", [$id]) : null;
|
||
$imagePath = (string)($existing['image_path'] ?? '');
|
||
if (p('remove_image','0') === '1') $imagePath = '';
|
||
$upload = storeSingleUpload(
|
||
'event_image',
|
||
'events',
|
||
imageExts(),
|
||
mbToBytes(setting('event_upload_max_mb','5'), 5),
|
||
[
|
||
'image_only' => true,
|
||
'resize_over_bytes' => mbToBytes(setting('forum_image_resize_threshold_mb','1'), 1),
|
||
'image_max_width' => (int)setting('forum_image_max_width','1600'),
|
||
'image_quality' => (int)setting('forum_image_quality','82'),
|
||
]
|
||
);
|
||
if (!$upload['ok']) { flash($upload['error'], 'error'); go('/admin/events.php'.($id ? '?edit='.$id : '')); }
|
||
if (!empty($upload['path'])) $imagePath = (string)$upload['path'];
|
||
|
||
$f=['title'=>ps('title'),'description'=>ps('description'),'venue'=>ps('venue'),'address'=>ps('address'),
|
||
'event_date'=>ps('event_date'),'event_time'=>ps('event_time'),'end_date'=>ps('end_date')?:null,
|
||
'end_time'=>ps('end_time'),'cost'=>ps('cost'),'website'=>ps('website'),'contact_name'=>ps('contact_name'),
|
||
'contact_email'=>ps('contact_email'),'contact_phone'=>ps('contact_phone'),'image_path'=>$imagePath,
|
||
'status'=>p('status','approved'),'is_featured'=>(int)p('is_featured',0)];
|
||
if (!$f['title'] || !$f['event_date']) { flash('Title and date required.','error'); go('/admin/events.php'); }
|
||
if ($act === 'add') {
|
||
qrun("INSERT INTO events(title,description,venue,address,event_date,event_time,end_date,end_time,cost,website,contact_name,contact_email,contact_phone,image_path,status,is_featured,submitted_by)VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)",array_merge(array_values($f),[uid()]));
|
||
flash('Event added!','success');
|
||
} else {
|
||
qrun("UPDATE events SET title=?,description=?,venue=?,address=?,event_date=?,event_time=?,end_date=?,end_time=?,cost=?,website=?,contact_name=?,contact_email=?,contact_phone=?,image_path=?,status=?,is_featured=? WHERE id=?",array_merge(array_values($f),[$id]));
|
||
flash('Event updated!','success');
|
||
}
|
||
go('/admin/events.php');
|
||
}
|
||
}
|
||
|
||
$filter = gs('filter') ?: 'all';
|
||
$editId = iget('edit');
|
||
$editing = $editId ? qone("SELECT * FROM events WHERE id=?",[$editId]) : null;
|
||
$where = match($filter) { 'pending'=>"WHERE status='pending'",'approved'=>"WHERE status='approved'", default=>"" };
|
||
$events = qall("SELECT e.*,u.username FROM events e LEFT JOIN users u ON u.id=e.submitted_by $where ORDER BY CASE status WHEN 'pending' THEN 0 ELSE 1 END,event_date DESC");
|
||
include __DIR__.'/admin_header.php';
|
||
?>
|
||
<?php adminTitle('Manage Events') ?>
|
||
|
||
<div class="ibox" style="border-color:var(--gold-d);margin-bottom:2rem">
|
||
<div class="ibox-title"><?=$editing ? '✏️ EDIT EVENT: '.strtoupper(e($editing['title'])) : '➕ ADD EVENT'?></div>
|
||
<form method="POST" enctype="multipart/form-data"><?=csrfField()?><input type="hidden" name="_act" value="<?=$editing?'edit':'add'?>">
|
||
<?php if($editing): ?><input type="hidden" name="id" value="<?=$editing['id']?>"><?php endif; ?>
|
||
<div class="fg"><label class="flabel">TITLE *</label><input type="text" name="title" class="finput" value="<?=e($editing['title']??'')?>" required></div>
|
||
<div class="fg"><label class="flabel">DESCRIPTION</label><textarea name="description" class="ftextarea" style="min-height:80px"><?=e($editing['description']??'')?></textarea></div>
|
||
<div class="form-row">
|
||
<div class="fg"><label class="flabel">VENUE</label><input type="text" name="venue" class="finput" value="<?=e($editing['venue']??'')?>"></div>
|
||
<div class="fg"><label class="flabel">ADDRESS</label><input type="text" name="address" class="finput" value="<?=e($editing['address']??'')?>"></div>
|
||
</div>
|
||
<div class="form-row">
|
||
<div class="fg"><label class="flabel">START DATE *</label><input type="date" name="event_date" class="finput" value="<?=e($editing['event_date']??'')?>" required></div>
|
||
<div class="fg"><label class="flabel">START TIME</label><input type="text" name="event_time" class="finput" value="<?=e($editing['event_time']??'')?>" placeholder="e.g. 7:00 PM"></div>
|
||
</div>
|
||
<div class="form-row">
|
||
<div class="fg"><label class="flabel">END DATE</label><input type="date" name="end_date" class="finput" value="<?=e($editing['end_date']??'')?>"></div>
|
||
<div class="fg"><label class="flabel">END TIME</label><input type="text" name="end_time" class="finput" value="<?=e($editing['end_time']??'')?>"></div>
|
||
</div>
|
||
<div class="form-row">
|
||
<div class="fg"><label class="flabel">COST</label><input type="text" name="cost" class="finput" value="<?=e($editing['cost']??'Free')?>"></div>
|
||
<div class="fg"><label class="flabel">WEBSITE</label><input type="text" name="website" class="finput" value="<?=e($editing['website']??'')?>"></div>
|
||
</div>
|
||
<div class="fg">
|
||
<label class="flabel">EVENT IMAGE</label>
|
||
<?php if(!empty($editing['image_path'])): ?>
|
||
<div class="event-admin-image">
|
||
<img src="<?=e($editing['image_path'])?>" alt="<?=e($editing['title'] ?? 'Event image')?>">
|
||
<label style="display:flex;align-items:center;gap:.45rem;font-size:.85rem;color:var(--text-m);cursor:pointer">
|
||
<input type="checkbox" name="remove_image" value="1"> Remove current image
|
||
</label>
|
||
</div>
|
||
<?php endif; ?>
|
||
<input type="file" name="event_image" class="finput" accept="image/*">
|
||
<div class="fhint">Optional JPG, PNG, GIF, or WebP. Max <?=e(setting('event_upload_max_mb','5'))?> MB.</div>
|
||
</div>
|
||
<div class="form-row">
|
||
<div class="fg"><label class="flabel">CONTACT NAME</label><input type="text" name="contact_name" class="finput" value="<?=e($editing['contact_name']??'')?>"></div>
|
||
<div class="fg"><label class="flabel">CONTACT PHONE</label><input type="text" name="contact_phone" class="finput" value="<?=e($editing['contact_phone']??'')?>"></div>
|
||
</div>
|
||
<div class="fg"><label class="flabel">CONTACT EMAIL</label><input type="email" name="contact_email" class="finput" value="<?=e($editing['contact_email']??'')?>"></div>
|
||
<div class="form-row">
|
||
<div class="fg"><label class="flabel">STATUS</label><select name="status" class="fselect"><option value="approved"<?=($editing['status']??'approved')==='approved'?' selected':''?>>Approved (public)</option><option value="pending"<?=($editing['status']??'')==='pending'?' selected':''?>>Pending review</option><option value="rejected"<?=($editing['status']??'')==='rejected'?' selected':''?>>Rejected</option></select></div>
|
||
<div class="fg"><label class="flabel">FEATURED</label><select name="is_featured" class="fselect"><option value="0"<?=!($editing['is_featured']??0)?' selected':''?>>Normal</option><option value="1"<?=($editing['is_featured']??0)?' selected':''?>>★ Featured</option></select></div>
|
||
</div>
|
||
<div class="flex-row">
|
||
<button type="submit" class="btn btn-primary"><?=$editing?'Update Event':'Add Event'?></button>
|
||
<?php if($editing): ?><a href="/admin/events.php" class="btn btn-secondary">Cancel</a><?php endif; ?>
|
||
</div>
|
||
</form>
|
||
</div>
|
||
|
||
<div style="display:flex;align-items:center;justify-content:space-between;flex-wrap:wrap;gap:.5rem;margin-bottom:.75rem">
|
||
<div class="admin-sec-title" style="margin-bottom:0">ALL EVENTS (<?=count($events)?>)</div>
|
||
<div class="flex-row" style="gap:.4rem">
|
||
<?php foreach(['all'=>'All','pending'=>'Pending','approved'=>'Approved'] as $k=>$lbl): ?>
|
||
<a href="/admin/events.php?filter=<?=$k?>" class="btn btn-xs<?=$filter===$k?' btn-primary':' btn-outline'?>"><?=$lbl?></a>
|
||
<?php endforeach; ?>
|
||
</div>
|
||
</div>
|
||
<div class="tbl-wrap">
|
||
<table class="dtbl">
|
||
<thead><tr><th>TITLE</th><th>DATE</th><th>SUBMITTED BY</th><th>STATUS</th><th>FEATURED</th><th>ACTIONS</th></tr></thead>
|
||
<tbody>
|
||
<?php foreach($events as $ev): ?>
|
||
<tr>
|
||
<td class="td-name" style="max-width:220px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap"><?=e($ev['title'])?><?=!empty($ev['image_path'])?' <span class="badge badge-blue">Image</span>':''?></td>
|
||
<td style="font-size:.8rem"><?=fdate($ev['event_date'])?></td>
|
||
<td style="font-size:.8rem"><?=e($ev['username']??'Admin')?></td>
|
||
<td><?php $sc=['approved'=>'badge-green','pending'=>'badge-gold','rejected'=>'badge-red']; ?><span class="badge <?=$sc[$ev['status']]??"badge-gray"?>"><?=strtoupper($ev['status'])?></span></td>
|
||
<td><?=$ev['is_featured']?'<span class="badge badge-gold">★</span>':'—'?></td>
|
||
<td>
|
||
<div class="flex-row" style="gap:.3rem">
|
||
<a href="/admin/events.php?edit=<?=$ev['id']?>" class="btn btn-xs btn-outline">✏️</a>
|
||
<?php if($ev['status']==='pending'): ?><form method="POST" style="display:inline"><?=csrfField()?><input type="hidden" name="_act" value="approve"><input type="hidden" name="id" value="<?=$ev['id']?>"><button class="btn btn-xs btn-success">Approve</button></form><form method="POST" style="display:inline"><?=csrfField()?><input type="hidden" name="_act" value="reject"><input type="hidden" name="id" value="<?=$ev['id']?>"><button class="btn btn-xs btn-secondary">Reject</button></form><?php endif; ?>
|
||
<form method="POST" style="display:inline"><?=csrfField()?><input type="hidden" name="_act" value="feature"><input type="hidden" name="id" value="<?=$ev['id']?>"><button class="btn btn-xs btn-secondary"><?=$ev['is_featured']?'Unfeature':'Feature'?></button></form>
|
||
<form method="POST" style="display:inline"><?=csrfField()?><input type="hidden" name="_act" value="delete"><input type="hidden" name="id" value="<?=$ev['id']?>"><button class="btn btn-xs btn-danger" data-confirm="Delete event?">🗑️</button></form>
|
||
</div>
|
||
</td>
|
||
</tr>
|
||
<?php endforeach; ?>
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
<?php include __DIR__.'/admin_footer.php'; ?>
|