summaryrefslogtreecommitdiffstats
path: root/includes/public/shortcodes/giglog_bands.php
blob: 226af14a4621ecb7a8988ee3fc5512668d77511a (plain) (blame)
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
<?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;
}