File: /home/awaldron/_domains/pennhillscdc.org/wp-content/themes/phcdc/admin/aw_events_edit.php
<?php
if ($action == 'edit') {
$events = $db->get_results("
SELECT e.*, d.*
FROM events as e
LEFT JOIN event_date as d ON e.event_id=d.event_id AND d.start > '" . date('Y-m-d H:i:s') . "'
WHERE e.event_id=" . $eid . "
ORDER BY d.start ASC", ARRAY_A);
$event = $events[0];
$dates = $events;
}
$locations = array(
array('-- SELECT A LOCATION --', '0'),
array('Penn Hills Library', '1037 Stotler Rd, Penn Hills, PA 15235'),
array('Penn Hills Library - Lincoln Park', '7300 Ridgeview Ave, Penn Hills, PA 15235'),
array('3 Lakes Golf Course', '6700 Saltsburg Rd, Pittsburgh, PA 15235'),
array('Griff\'s Grounds Coffè', '1817 Leechburg Rd., Penn Hills, PA 15235'),
array('Humane Animal Rescue Wildlife Center', '6000 Verona Rd, Verona, PA 15147'),
array('Lincoln Park Community Center', '7300 Ridgeview Ave, Penn Hills, PA 15235'),
array('Linton Middle School', '250 Aster St, Pittsburgh, PA 15235'),
array('McKinley Citizens Center', '1110 Center Ave, Verona, PA 15147'),
array('Penn Forest Natural Burial Park', '227 Kansas Street, Verona PA 15147'),
array('Penn Hebron Garden Club', '237 Jefferson Rd. Pittsburgh, PA 15235'),
array('Penn Hills Community Park', '120 Colorado St, Verona, PA 15147'),
array('Penn Hills Elementary School', '1079 Jefferson Road, Pittsburgh, PA 15235'),
array('Penn Hills Garden Center', '200 Jefferson Rd, Penn Hills, PA 15235'),
array('Penn Hills Government Center', '102 Duff Rd, Penn Hills, PA 15235'),
array('Penn Hills High School', '309 Collins Dr, Penn Hills, PA 15235'),
array('Penn Hills No.7 VFD', '125 Universal Rd, Pittsburgh, PA 15235'),
array('Penn Hills Senior Center', '147 Jefferson Road, Pittsburgh PA 15235'),
array('Returning Home Farm', '227 Kansas St, Verona PA 15147'),
array('Rose Funeral Home', '10940 Frankstown Rd., Pittsburgh, PA 15235'),
array('Rosedale Beach Club', '5401 3rd St, Verona, PA 15147'),
array('Steel Goat Marketplace', '200 Jefferson Rd, Pittsburgh, PA 15235'),
array('Turner Friendship Park', '1340 Hunter Rd, Verona, PA 15147'),
array('Universal Park', '1 Memorial Park Ln, Penn Hills, PA 15235'),
array('Verona Railroad Park', '736 E. Railroad Ave, Verona PA, 15147'),
array('Other', '0'),
);
//echo '<pre>', print_r($_REQUEST), '</pre>', $eid; //exit;
?>
<div class="wrap">
<h1 class="wp-heading"><?= ($action == 'create' ? '<b>Create New Event</b>' : '<b>Edit Event</b> - '.$event['title']) ?></h1><br><br>
</div>
<form action="/wp-admin/admin.php?page=aw_events&action=<?=($action == 'create' ? 'new_event' : 'upd_event')?>" method="post">
<div class="container">
<?php if (!empty($message)): ?>
<div class="row">
<div class="col-sm-12">
<div class="alert alert-success"><?=$message?> - <a href="/wp-admin/admin.php?page=aw_events">Back to Events List</a></div>
</div>
</div>
<?php endif; ?>
<div class="row">
<div class="col-sm-6">
<input type="hidden" name="event_id" id="event_id" value="<?=($action=='create' ? 'new' : $eid)?>">
<div class="form-group">
<label for="title">Event Title</label>
<input type="text" class="form-control" id="title" name="title" value="<?= $event['title'] ?>"/>
</div>
<div class="form-group">
<label for="event_cat_id">Event Category</label>
<select class="form-control" name="event_cat_id">
<option value="0">-- SELECT A CATEGORY --</option>
<option value="4"<?= ($event['event_cat_id'] == 4 ? ' selected="selected"' : '') ?>>Children</option>
<option value="4"<?= ($event['event_cat_id'] == 11 ? ' selected="selected"' : '') ?>>Teens</option>
<option value="4"<?= ($event['event_cat_id'] == 12 ? ' selected="selected"' : '') ?>>Adult</option>
<option value="1"<?= ($event['event_cat_id'] == 1 ? ' selected="selected"' : '') ?>>Government</option>
<option value="2"<?= ($event['event_cat_id'] == 2 ? ' selected="selected"' : '') ?>>Education</option>
<option value="3"<?= ($event['event_cat_id'] == 3 ? ' selected="selected"' : '') ?>>Community</option>
<option value="5"<?= ($event['event_cat_id'] == 5 ? ' selected="selected"' : '') ?>>Business</option>
<option value="6"<?= ($event['event_cat_id'] == 6 ? ' selected="selected"' : '') ?>>Athletics</option>
</select>
</div>
<div class="form-group">
<label for="location_select">Location</label>
<select name="location_select" id="location_select" class="form-control">
<?php
$match = false;
$other_match = false;
$selected = $event['location'] . '||' . $event['address'];
foreach ($locations as $loc) {
$value = $loc[0] . '||' . $loc[1];
$this_match = ($value == $selected);
if ($this_match) $match = true;
$other_match = ($loc[0] == 'Other' && $action == 'edit' && !$match);
echo '<option value="' . $value . '"' . ($this_match || $other_match ? ' selected="selected"' : '') . '>' . $loc[0] . '</option>';
}
?>
</select>
</div>
<div class="form-group" id="location-field" style="display: none;">
<label for="location">Location Title</label>
<input type="text" class="form-control" id="location" name="location" value="<?= $event['location'] ?>">
</div>
<div class="form-group" id="address-field" style="display: none;">
<label for="address">Location Address</label>
<input type="text" class="form-control" id="address" name="address" value="<?= $event['address'] ?>">
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<label for="contact_name">Contact Name</label>
<input type="text" class="form-control" id="contact_name" name="contact_name"
value="<?= $event['contact_name'] ?>">
</div>
<div class="form-group">
<label for="contact_email">Contact Email</label>
<input type="email" class="form-control" id="contact_email" name="contact_email"
value="<?= $event['contact_email'] ?>">
</div>
<div class="form-group">
<label for="contact_phone">Contact Phone</label>
<input type="text" class="form-control" id="contact_phone" name="contact_phone"
value="<?= $event['contact_phone'] ?>">
</div>
<div class="form-group">
<label for="event_cat_id">Private Event?</label>
<select class="form-control" name="event_private">
<option value="0"<?= ($event['event_private'] == 0 ? ' selected="selected"' : '') ?>>No</option>
<option value="1"<?= ($event['event_private'] == 1 ? ' selected="selected"' : '') ?>>Yes</option>
</select>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-12">
<div class="form-group">
<label for="description">Description</label>
<textarea class="form-control" id="rte-editor" name="description"
rows="4"><?=$event['description']?></textarea>
</div>
</div>
</div>
<br/>
<div class="row">
<div class="col-sm-12">
<h4><b>Event Dates</b></h4><br/>
<div class="row">
<div class="col-sm-3"><b>Event Start</b></div>
<div class="col-sm-3"><b>Event End</b></div>
<div class="col-sm-1"><b>Seats</b></div>
<div class="col-sm-2"><b>Actions</b></div>
</div>
<div id="date-rows">
<?php
if (empty($dates[0]['event_date_id'])) {
$dates = array(array('start'=>0,'end'=>0,'seats'=>0));
} else {
$dates[] = array(array('start'=>0,'end'=>0,'seats'=>0));
}
foreach ($dates as $date): ?>
<div class="row row-hover date-row">
<div class="col-sm-3">
<div class="form-group-pad">
<div class='input-group date datetime'>
<input type='text' class="form-control" name="start<?=(empty($date['event_date_id'])?'[]':'_'.$date['event_date_id'])?>" value="<?=($date['start']==0?'':date('m/d/Y h:i A',strtotime($date['start'])))?>"/>
<span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span></span>
</div>
</div>
</div>
<div class="col-sm-3">
<div class="form-group-pad">
<div class='input-group date datetime'>
<input type='text' class="form-control" name="end<?=(empty($date['event_date_id'])?'[]':'_'.$date['event_date_id'])?>" value="<?=($date['end']==0?'':date('m/d/Y h:i A',strtotime($date['end'])))?>"/>
<span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span></span>
</div>
</div>
</div>
<div class="col-sm-1">
<div class="form-group-pad">
<input type="text" class="form-control" style="text-align:center;" name="seats<?=(empty($date['event_date_id'])?'[]':'_'.$date['event_date_id'])?>" value="<?=$date['seats']?>" />
</div>
</div>
<div class="col-sm-2">
<div class="form-group-pad">
<a class="btn btn-danger btn-sm delete-date"><i class="fas fa-times"></i></a>
</div>
</div>
</div>
<?php endforeach; ?>
</div>
<div class="row">
<div class="col-sm-12">
<div class="form-group-pad">
<a class="btn btn-success btn-sm" id="add-date"><i class="fas fa-plus-circle"></i> Add Another Date</a>
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-12">
<br/><hr><br>
<input type="submit" value="Submit Event" class="btn btn-success" />
<a href="/wp-admin/admin.php?page=aw_events" class="btn btn-link" style="color:#999;">Cancel Changes</a>
</div>
</div>
</div>
</form>
<script>
jQuery(document).ready(function () {
jQuery('#rte-editor').summernote({
minHeight: 300,
toolbar: [
// [groupName, [list of button]]
['style', ['bold', 'italic', 'underline', 'strikethrough']],
['para', ['ul', 'ol', 'paragraph']],
['insert', ['link', 'picture', 'video', 'hr']],
['view', ['codeview', 'clear', 'help']],
]
});
let locSelected = jQuery('#location_select').val();
if (locSelected == 'Other||0') {
jQuery('#location-field, #address-field').show();
}
jQuery('#location_select').change(function() {
let locSelected = jQuery('#location_select').val();
if (locSelected == 'Other||0') {
jQuery('#location-field, #address-field').show();
} else {
jQuery('#location-field, #address-field').hide();
}
});
jQuery('.datetime').datetimepicker();
jQuery('.delete-date').click(function () {
jQuery(this).closest('.row').addClass('deleting').animate({opacity:1},250).animate({opacity:0},500, function () {
jQuery(this).remove()
});
return false;
});
jQuery('#add-date').click(function () {
jQuery('.date-row:last-child').clone().appendTo('#date-rows').addClass('newdate');
jQuery('.datetime').datetimepicker();
jQuery('.delete-date').click(function () {
jQuery(this).closest('.row').addClass('deleting').animate({opacity:1},250).animate({opacity:0},500, function () {
jQuery(this).remove()
});
});
return false;
});
jQuery('.alert-success').animate({opacity:1},5000).slideUp();
});
</script>