summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Eilertsen <haraldei@anduin.net>2021-01-17 21:25:08 +0100
committerHarald Eilertsen <haraldei@anduin.net>2021-01-17 21:49:52 +0100
commit540b1b93817378550aeeb02370ca845d97430534 (patch)
treee0f2a35fde50af19f7056a111a96ae2c83217941
parent6554ae2e81a9aef9d55ddacb3eaf6014f88f8502 (diff)
downloadgigologadmin-540b1b93817378550aeeb02370ca845d97430534.tar.gz
gigologadmin-540b1b93817378550aeeb02370ca845d97430534.tar.bz2
gigologadmin-540b1b93817378550aeeb02370ca845d97430534.zip
Add shortcodes to display (public) concert list.
-rw-r--r--giglogadmin.php9
-rw-r--r--includes/public/shortcodes/giglog_bands.php114
2 files changed, 123 insertions, 0 deletions
diff --git a/giglogadmin.php b/giglogadmin.php
index 977acbd..b5c45f9 100644
--- a/giglogadmin.php
+++ b/giglogadmin.php
@@ -18,8 +18,15 @@
*/
if ( !class_exists( 'GiglogAdmin_Plugin' ) ) {
+ require_once __DIR__ . '/includes/public/shortcodes/giglog_bands.php';
+
class GiglogAdmin_Plugin
{
+ static public function init() {
+ add_shortcode('giglog_cities', 'giglogadmin_getfilters');
+ add_shortcode('giglog_bands', 'giglogadmin_getconcerts');
+ }
+
static function activate() {
require_once __DIR__ . '/includes/admin/register_db_tables.php';
}
@@ -30,5 +37,7 @@ if ( !class_exists( 'GiglogAdmin_Plugin' ) ) {
register_activation_hook( __FILE__, array( 'GiglogAdmin_Plugin', 'activate' ));
register_deactivation_hook( __FILE__, array( 'GiglogAdmin_Plugin', 'deactivate' ));
+
+ GiglogAdmin_Plugin::init();
}
?>
diff --git a/includes/public/shortcodes/giglog_bands.php b/includes/public/shortcodes/giglog_bands.php
new file mode 100644
index 0000000..226af14
--- /dev/null
+++ b/includes/public/shortcodes/giglog_bands.php
@@ -0,0 +1,114 @@
+<?php
+/*
+ * code used for giglogadmin for the open page where everyone sees the list of
+ * concerts. First function displays filters by city, venue and the second one
+ * builds the table with concerts
+ */
+
+function giglogadmin_getfilters()
+{
+ global $wpdb;
+
+ //echo (var_dump($_POST["selectvenue"]));
+
+ $results = $wpdb->get_results('select distinct wpgvenue_city from wpg_venues');
+ $select = '<form method="POST" action=""><select name="selectcity">';
+ $select .= '<option value="ALL" ';
+ if (isset($_POST["selectcity"]) && $_POST["selectcity"] == "ALL") {
+ $select .= ' selected = "selected"';
+ }
+ $select .= '> All cities</option>';
+ foreach ($results AS $row) {
+ $select .= '<option value="' . $row->wpgvenue_city . '"';
+ if (isset($_POST["selectcity"]) && $_POST["selectcity"] == $row->wpgvenue_city) {
+ $select .= ' selected = "selected"';
+ }
+ $select .= ' >' . $row->wpgvenue_city . '</option>';
+ }
+
+ if (isset($_POST["selectcity"]) && $_POST["selectcity"] != "ALL") {
+ $select .= '</select>';
+ //second drop down for venue
+
+ $vquery = "select id, wpgvenue_name from wpg_venues";
+ $vquery .= " where wpgvenue_city='" . $_POST["selectcity"] . "'";
+ $resultsv = $wpdb->get_results($vquery);
+ $select .= '<select name="selectvenue">';
+ $select .= '<option value="0" ';
+ if (isset($_POST["selectvenue"]) && $_POST["selectvenue"] == "0") {
+ $select .= ' selected = "selected"';
+ }
+ $select .= '> All venues</option>';
+
+ foreach ($resultsv AS $rowv) {
+ $select .= '<option value="' . $rowv->id . '"';
+ if (isset($_POST["selectvenue"]) && $_POST["selectvenue"] == $rowv->id) {
+ $select .= ' selected = "selected"';
+ }
+ $select .= ' >' . $rowv->wpgvenue_name . '</option>';
+ }
+ //end IF that checks if city was selected
+ }
+ $select .= '</select><input type="submit" value="Filter"></form>';
+ return $select;
+}
+
+
+function giglogadmin_getconcerts()
+{
+ global $wpdb;
+ // Shortcodes RETURN content, so store in a variable to return
+ $content = '<table>';
+ // $content .= '</tr><th>CITY</th><th>ID</th><th>BAND</th><th>VENUE</th><th>DATE</th><th>TICKETS</th><th>EVENT</th></tr>';
+ $content .= '</tr><th>CITY</th><th>BAND</th><th>VENUE</th><th>DATE</th><th>TICKETS</th><th>EVENT</th></tr>';
+ // Use the submitted "city" if any. Otherwise, use the default/static value.
+ $cty = filter_input(INPUT_POST, 'selectcity');
+ $cty = $cty ? $cty : 'ALL';
+
+ $venue = filter_input(INPUT_POST, 'selectvenue');
+ //echo($_POST['selectvenue']);
+ $venue = $venue ? $venue : '0';
+
+
+ $query = "SELECT wpgc.id, wpgb.wpgband_name as band ,wpgv.wpgvenue_name as venue ,wpgc.wpgconcert_date, wpgc.wpgconcert_tickets, wpgc.wpgconcert_event, wpgv.wpgvenue_city, wpgv.wpgvenue_webpage
+ FROM wpg_concerts wpgc, wpg_bands wpgb, wpg_venues wpgv
+where wpgc.band=wpgb.id
+and wpgc.venue = wpgv.id
+and wpgconcert_date >= CURDATE()";
+ $query .= ($cty == "ALL") ? "" : " and wpgv.wpgvenue_city='" . $cty . "'";
+ $query .= ($venue == "0") ? "" : " and wpgv.id='" . $venue . "'";
+ $query .= " order by wpgv.wpgvenue_city, wpgconcert_date";
+ //echo($query);
+ $results = $wpdb->get_results($query);
+
+
+ $lastType = '';
+ foreach ($results AS $row) {
+ $content .= '<tr>';
+
+ if ($lastType != '' && $lastType != $row->wpgvenue_city) {
+ $content .= '<td>' . $row->wpgvenue_city . '</td></tr><tr>';
+ }
+
+ if ($lastType == '') {
+ $content .= '<td>' . $row->wpgvenue_city . '</td></tr><tr>';
+ }
+ // Modify these to match the database structure
+ // $content .= '<td>' . $row->id. '</td>';
+ $content .= '<td></td>';
+ $content .= '<td>' . $row->band . '</td>';
+ $content .= '<td>' . $row->venue . '</td>';
+ $fdate = strtotime($row->wpgconcert_date);
+ $newformat = date('d.M.Y', $fdate);
+
+ //$content .= DATE_FORMAT($fdate,'%d.%b.%Y');
+ $content .= '<td>' . $newformat . '</td>';
+ $content .= '<td><a href="' . $row->wpgconcert_tickets . '" target="_blank">Tickets</a></td>';
+ $content .= '<td><a href="' . $row->wpgconcert_event . '" target="_blank">Event link</a></td>';
+ $content .= '</tr>';
+ $lastType = $row->wpgvenue_city;
+ }
+ $content .= '</table>';
+ // return the table
+ return $content;
+}