summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndreaChirulescu <andrea.chirulescu@gmail.com>2021-04-11 22:51:03 +0200
committerAndreaChirulescu <andrea.chirulescu@gmail.com>2021-04-11 22:51:03 +0200
commit50ab799d1789d666dc1bea546701bc0ee8f8bc31 (patch)
tree650dc0494b318a0567b9f16bde22e6298d089907
parent029f4d7a5b9aff1f7b35f060d172611ef81a2943 (diff)
downloadgigologadmin-50ab799d1789d666dc1bea546701bc0ee8f8bc31.tar.gz
gigologadmin-50ab799d1789d666dc1bea546701bc0ee8f8bc31.tar.bz2
gigologadmin-50ab799d1789d666dc1bea546701bc0ee8f8bc31.zip
Added small forms to add new venue and band
Made form for concert both functional to edit existing concert or add new concert
-rw-r--r--includes/admin/views/giglog_admin_page.php136
-rw-r--r--includes/band.php24
-rw-r--r--includes/concert.php134
-rw-r--r--includes/venue.php11
4 files changed, 217 insertions, 88 deletions
diff --git a/includes/admin/views/giglog_admin_page.php b/includes/admin/views/giglog_admin_page.php
index 5fdcc6b..205cdd3 100644
--- a/includes/admin/views/giglog_admin_page.php
+++ b/includes/admin/views/giglog_admin_page.php
@@ -41,44 +41,50 @@ if ( !class_exists( 'GiglogAdmin_AdminPage' ) ) {
<p><?php echo GiglogAdmin_AdminPage::get_filters() ?></p>
<p><?php echo GiglogAdmin_AdminPage::get_concerts() ?></p>
- </div>
-
-
- <form method="POST" action="" class="concedit" > Here Be Dragons <br>
- <label for="band">Band:</label><?php echo GiglogAdmin_AdminPage::get_allbands() ?><br>
- <label for="venue">Venue:</label><?php echo GiglogAdmin_AdminPage::get_allvenues() ?><br>
- <label for="cdate">Date:</label><input type="date" id="cdate" name="cdate"><br>
- <label for="ticket">Tickets:</label><input type="text" id="ticket" name="ticket"><br>
- <label for="eventurl">Event link:</label><input type="text" id="eventurl" name="eventurl"><br>
-
- <p><button>Submit</button></p>
- </form>
- <?php //currnet comment and above form can be removed once we decide how to...form. The form is meant to allow adding single concerts or editing one in the table.
+ </div>
+ <?php
+ if (current_user_can('administrator'))
+ echo(GiglogAdmin_AdminPage::editforms()); //not sure why it doesn't show without the echo?
}
- static function get_allvenues()
+ static function get_allvenues($invenue)
{
- $select = '<select name="selectvenue">';
+ $select = '<select name="selectvenueadmin">';
+ $select .= '<option value="">Please Select..</option>';
foreach ( GiglogAdmin_Venue::all_venues() AS $venue ) {
- $select .= '<option value="' . $venue->id() . '">'. $venue->name();
+ if($invenue==$venue ->id() ) $select .= '<option value="' . $venue -> id(). '" selected="selected">'.$venue->name();
+ else $select .= '<option value="' . $venue->id() . '">'. $venue->name();
$select .='</option>';
}
$select .= '</select>';
return($select);
}
- static function get_allbands()
+ static function get_allbands($inband)
{
$select = '<select name="selectband">';
-
+ $select .= '<option value="">Please Select..</option>';
foreach ( GiglogAdmin_Band::all_bands() AS $band ) {
- $select .= '<option value="' . $band -> id. '">'.$band->vname;
+ if($inband==$band ->id) $select .= '<option value="' . $band -> id. '" selected="selected">'.$band->vname;
+ else $select .= '<option value="' . $band -> id. '">'.$band->vname;
$select .='</option>';
}
$select .= '</select>';
return($select);
}
+ static function get_countries()
+ {
+ $select = '<select name="selectcountry">';
+ $select .= '<option value="">Please Select..</option>';
+ foreach ( GiglogAdmin_Band::all_countries() AS $country ) {
+ $select .= '<option value="' . $country->id. '">'. $country->cname;
+ $select .='</option>';
+ }
+ $select .= '</select>';
+ return($select);
+ }
+
static function get_filters()
{
$cities = array_merge(["ALL"], GiglogAdmin_Venue::all_cities());
@@ -127,6 +133,49 @@ if ( !class_exists( 'GiglogAdmin_AdminPage' ) ) {
return $select;
}
+
+ static function editforms()
+ { global $wpdb;
+ if($_POST['edit']="EDIT")
+ {
+ $query = "SELECT * FROM wpg_concerts where id = ".$_POST['cid'];
+ $results = $wpdb->get_results($query);
+ foreach($results as $row)
+ {
+ $band = $row -> band;
+ $venue = $row-> venue;
+ $cdate = $row ->wpgconcert_date;
+ $ticket = $row->wpgconcert_tickets;
+ $link = $row->wpgconcert_event;
+ }
+
+ }
+ $content='<form method="POST" action="" class="concedit" > Form to create/edit concerts, bands, venues<br>'
+ .'<input type="hidden" name="pid" value="' .$_POST['cid']. '" />'
+ .'<label for="band">Band:</label>'.GiglogAdmin_AdminPage::get_allbands($band).'<br>'
+ .'<label for="venue">Venue:</label>'.GiglogAdmin_AdminPage::get_allvenues($venue).'<br>'
+ .'<label for="cdate">Date:</label><input type="date" id="cdate" name="cdate" value="'.$cdate.'"><br>'
+ .'<label for="ticket">Tickets:</label><input type="text" id="ticket" name="ticket" value="'.$ticket.'"><br>'
+ .'<label for="eventurl">Event link:</label><input type="text" id="eventurl" name="eventurl" value="'.$link.'"><br>';
+ if ($band=='')
+ $content.='<p><input type="submit" name="newconcert" value="Create New Concert"></p>';
+ else
+ $content.='<p><input type="submit" name="editconcert" value="Edit Concert"></p>';
+ $content.='</form>';
+
+ $content.='<form method="POST" action="" class="bandedit" ><br>'
+ .'<label for="bandname">Band Name:</label><input type="text" id="bandname" name="bandname"><br>'
+ .'<label for="eventurl">Band Country:</label>'.GiglogAdmin_AdminPage::get_countries().'<br>'
+ .'<p><input type="submit" name="newband" value="Create New Band"></p>'
+ .'</form>';
+
+ $content.='<form method="POST" action="" class="bandedit" ><br>'
+ .'<label for="bandname">Venue Name:</label><input type="text" id="venuename" name="venuename"><br>'
+ .'<label for="eventurl">Venue City:</label><input type="text" id="venuecity" name="venuecity"><br>'
+ .'<p><input type="submit" name="newvenue" value="Create New Venue"></p>'
+ .'</form>';
+ return $content;
+ }
static function adminactions($concert_id)
{
@@ -145,7 +194,8 @@ if ( !class_exists( 'GiglogAdmin_AdminPage' ) ) {
$select .=
'</select>'
- . '<input type="submit" value="Set status">'
+ . '<input type="submit" value="SetStatus">'
+ . '<input type="submit" name ="edit" value="EDIT">'
. '</form>';
return $select;
@@ -251,6 +301,7 @@ if ( !class_exists( 'GiglogAdmin_AdminPage' ) ) {
// return the table
return $content;
}
+
static function update()
{
@@ -283,13 +334,56 @@ if ( !class_exists( 'GiglogAdmin_AdminPage' ) ) {
}
//handling the admin drop down menu
- if(isset($_POST['selectstatus']))
+ if(isset($_POST['selectstatus']) && $_POST['edit']!="EDIT")
{
$usql = "UPDATE wpg_concertlogs SET wpgcl_status=".$_POST['selectstatus']." WHERE wpgcl_concertid=".$_POST['cid'];
$uresults = $wpdb->get_results($usql);
//$url2=$_SERVER['REQUEST_URI']; //doesn't seem to be needed actually, leaving here just in case
//header("Refresh: 1; URL=$url2"); //reload page
}
+
+ if(isset($_POST['newconcert']))
+ {
+ IF (empty($_POST['selectband']) || empty($_POST['selectvenueadmin']) || empty($_POST['cdate']) || empty($_POST['ticket']) || empty($_POST['eventurl']))
+ echo '<script language="javascript">alert("You are missing a value, concert was not created"); </script>';
+ else
+ {
+ GiglogAdmin_Concert::create($_POST['selectband'], $_POST['selectvenueadmin'], $_POST['cdate'], $_POST['ticket'], $_POST['eventurl']);
+ echo '<script language="javascript">alert("Yey, concert created"); </script>';
+ }
+ }
+ if(isset($_POST['editconcert']))
+ {
+ IF (empty($_POST['selectband']) || empty($_POST['selectvenueadmin']) || empty($_POST['cdate']) || empty($_POST['ticket']) || empty($_POST['eventurl']))
+ echo '<script language="javascript">alert("You are missing a value, concert was not updated"); </script>';
+ else
+ {
+ GiglogAdmin_Concert::updatec($_POST['pid'],$_POST['selectband'], $_POST['selectvenueadmin'], $_POST['cdate'], $_POST['ticket'], $_POST['eventurl']);
+ echo '<script language="javascript">alert("Yey, concert updated"); </script>';
+ }
+ }
+
+ if(isset($_POST['newband']))
+ {
+ IF (empty($_POST['bandname'])) //country is not checked as it is set to Norway by default
+ echo '<script language="javascript">alert("You are missing a value, band was not created"); </script>';
+ else
+ {
+ GiglogAdmin_Band::create($_POST['bandname'],$_POST['selectcountry']);
+ echo '<script language="javascript">alert("Yey, band created"); </script>';
+ }
+ }
+
+ if(isset($_POST['newvenue']))
+ {
+ IF (empty($_POST['venuename']) || empty($_POST['venuecity']))
+ echo '<script language="javascript">alert("You are missing a value, venue was not created"); </script>';
+ else
+ {
+ GiglogAdmin_Venue::create($_POST['venuename'],$_POST['venuecity']);
+ echo '<script language="javascript">alert("Yey, venue created"); </script>';
+ }
+ }
}
static function assignconcert($p1, $c)
diff --git a/includes/band.php b/includes/band.php
index 9ed7a53..72af425 100644
--- a/includes/band.php
+++ b/includes/band.php
@@ -19,26 +19,27 @@
if ( !class_exists('GiglogAdmin_Band') ) {
class GiglogAdmin_Band
{
- static function create($name)
+ static function create($name, $country)
{
global $wpdb;
-
+ if (empty($country)) $country = 'NO';
$wpdb->insert('wpg_bands', array(
'id' => '',
- 'wpgband_name' => $name
+ 'wpgband_name' => $name,
+ 'wpgband_country' => $country
));
return $wpdb->insert_id;
}
- static function find_or_create($name)
+ static function find_or_create($name, $country)
{
global $wpdb;
-
+ if(empty($country)) $country = 'NO';
$bandsql = 'SELECT id FROM wpg_bands WHERE upper(wpgband_name)="' . $name . '"';
- $results = $wpdb->get_results($bandsql);
+ $results = $wpdb->get_results($bandsql);
- return $results ? $results[0]->id : GiglogAdmin_Band::create($name);
+ return $results ? $results[0]->id : GiglogAdmin_Band::create($name, $country);
}
static function all_bands()
@@ -49,6 +50,15 @@ if ( !class_exists('GiglogAdmin_Band') ) {
return ($results);
}
+
+ static function all_countries()
+ {
+ global $wpdb;
+
+ $results = $wpdb->get_results("select id, wpgcountry_name as cname from wpg_countries order by id");
+
+ return ($results);
+ }
}
}
diff --git a/includes/concert.php b/includes/concert.php
index 7672c96..8719663 100644
--- a/includes/concert.php
+++ b/includes/concert.php
@@ -1,55 +1,79 @@
-<?php
-/*
- * Copyright (C) 2021 Harald Eilertsen, Andrea Chirulescu
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-if ( !class_exists('GiglogAdmin_Concert') ) {
- class GiglogAdmin_Concert
- {
- public static function create($band, $venue, $date, $ticketlink, $eventlink)
- {
- global $wpdb;
-
- $res = $wpdb->insert('wpg_concerts', array(
- 'band' => $band,
- 'venue' => $venue,
- 'wpgconcert_date' => $date,
- 'wpgconcert_tickets' => $ticketlink,
- 'wpgconcert_event' => $eventlink
- ));
-
- if ( !$res ) {
- error_log( __CLASS__ . '::' . __FUNCTION__ . ": {$wpdb->last_error}");
- die;
- }
-
- return $wpdb->insert_id;
- }
-
- public static function get($band, $venue, $date)
- {
- global $wpdb;
-
- $sql = 'SELECT id from wpg_concerts'
- . ' where band = ' . $band
- . ' and venue = ' . $venue
- . ' and wpgconcert_date ="' . $date . '"';
-
- error_log(__CLASS__ . '::' . __FUNCTION__ . ": {$sql}");
- return $wpdb->get_results($sql);
- }
- }
-}
+<?php
+/*
+ * Copyright (C) 2021 Harald Eilertsen, Andrea Chirulescu
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+if ( !class_exists('GiglogAdmin_Concert') ) {
+ class GiglogAdmin_Concert
+ {
+ public static function create($band, $venue, $date, $ticketlink, $eventlink)
+ {
+ global $wpdb;
+
+ $res = $wpdb->insert('wpg_concerts', array(
+ 'band' => $band,
+ 'venue' => $venue,
+ 'wpgconcert_date' => $date,
+ 'wpgconcert_tickets' => $ticketlink,
+ 'wpgconcert_event' => $eventlink
+ ));
+
+ if ( !$res ) {
+ error_log( __CLASS__ . '::' . __FUNCTION__ . ": {$wpdb->last_error}");
+ die;
+ }
+
+ return $wpdb->insert_id;
+ }
+
+ public static function updatec($id, $band, $venue, $cdate, $ticketlink, $eventlink)
+ {
+ global $wpdb;
+
+ $res = $wpdb->update('wpg_concerts', array(
+ 'band' => $band,
+ 'venue' => $venue,
+ 'wpgconcert_date' => $cdate,
+ 'wpgconcert_tickets' => $ticketlink,
+ 'wpgconcert_event' => $eventlink
+ ),
+ array('id' => $id)
+ );
+
+ if ( !$res ) {
+ // exit( var_dump( $wpdb->last_query ) ); //for onscreen debugging when needed
+ error_log( __CLASS__ . '::' . __FUNCTION__ . ": {$wpdb->last_error}");
+ die;
+ }
+
+ return ($wpdb->last_error); //not sure what to return here?
+ }
+
+ public static function get($band, $venue, $date)
+ {
+ global $wpdb;
+
+ $sql = 'SELECT id from wpg_concerts'
+ . ' where band = ' . $band
+ . ' and venue = ' . $venue
+ . ' and wpgconcert_date ="' . $date . '"';
+
+ error_log(__CLASS__ . '::' . __FUNCTION__ . ": {$sql}");
+ return $wpdb->get_results($sql);
+ }
+ }
+}
+?> \ No newline at end of file
diff --git a/includes/venue.php b/includes/venue.php
index 08e8bb5..08ab3da 100644
--- a/includes/venue.php
+++ b/includes/venue.php
@@ -40,20 +40,21 @@ if ( !class_exists('GiglogAdmin_Venue') ) {
$this->webpage = isset($attrs->wpgvenue_webpage) ? $attrs->wpgvenue_webpage : NULL;
}
- static function create($name)
- {
+ static function create($name,$city)
+ { if(empty($city)) $city='Oslo';
$attrs = new stdClass();
$attrs->wpgvenue_name = $name;
+ $attrs->wpgvenue_city = $city;
$venue = new GiglogAdmin_Venue($attrs);
$venue->save();
return $venue;
}
- static function find_or_create($name)
+ static function find_or_create($name, $city)
{
global $wpdb;
-
+ if(empty($city)) $city='Oslo';
$venuesql = 'SELECT * FROM wpg_venues WHERE upper(wpgvenue_name)="' . $name . '"';
$results = $wpdb->get_results($venuesql);
@@ -61,7 +62,7 @@ if ( !class_exists('GiglogAdmin_Venue') ) {
return new GiglogAdmin_Venue($results[0]);
}
else {
- return GiglogAdmin_Venue::create($name);
+ return GiglogAdmin_Venue::create($name, $city);
}
}