summaryrefslogtreecommitdiffstats
path: root/includes
diff options
context:
space:
mode:
Diffstat (limited to 'includes')
-rw-r--r--includes/admin/views/giglog_admin_page.php90
-rw-r--r--includes/admin/views/giglog_import_gigs.php24
-rw-r--r--includes/concert.php236
3 files changed, 214 insertions, 136 deletions
diff --git a/includes/admin/views/giglog_admin_page.php b/includes/admin/views/giglog_admin_page.php
index 9322c9a..8deba81 100644
--- a/includes/admin/views/giglog_admin_page.php
+++ b/includes/admin/views/giglog_admin_page.php
@@ -41,8 +41,8 @@ if ( !class_exists( 'GiglogAdmin_AdminPage' ) ) {
<p><?php echo GiglogAdmin_AdminPage::get_filters() ?></p>
<p><?php echo GiglogAdmin_AdminPage::get_concerts() ?></p>
- </div>
- <?php
+ </div>
+ <?php
if (current_user_can('administrator'))
echo(GiglogAdmin_AdminPage::editforms()); //not sure why it doesn't show without the echo?
}
@@ -84,7 +84,7 @@ if ( !class_exists( 'GiglogAdmin_AdminPage' ) ) {
$select .= '</select>';
return($select);
}
-
+
static function get_filters()
{
$cities = array_merge(["ALL"], GiglogAdmin_Venue::all_cities());
@@ -133,48 +133,36 @@ if ( !class_exists( 'GiglogAdmin_AdminPage' ) ) {
return $select;
}
-
+
static function editforms()
{ global $wpdb;
- $cid = filter_input(INPUT_POST, "cid");
- if(($_POST['edit']=="EDIT")&&!empty($cid))
- {
- $query = "SELECT * FROM wpg_concerts where id = ".$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;
- }
-
- }
+ $cid = filter_input(INPUT_POST, "cid");
+ $c = GiglogAdmin_Concert::find_or_create($cid,'','','','','');
+
$content='<form method="POST" action="" class="concedit" > Form to create/edit concerts, bands, venues<br>'
- .'<input type="hidden" name="pid" value="' .$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=='') //actions differ if we update or create a concert, hence two buttons needed
+ .'<input type="hidden" name="pid" value="' .$c->id(). '" />'
+ .'<label for="band">Band:</label>'.GiglogAdmin_AdminPage::get_allbands($c->band()).'<br>'
+ .'<label for="venue">Venue:</label>'.GiglogAdmin_AdminPage::get_allvenues($c->venue()).'<br>'
+ .'<label for="cdate">Date:</label><input type="date" id="cdate" name="cdate" value="'.$c->cdate().'"><br>'
+ .'<label for="ticket">Tickets:</label><input type="text" id="ticket" name="ticket" value="'.$c->tickets().'"><br>'
+ .'<label for="eventurl">Event link:</label><input type="text" id="eventurl" name="eventurl" value="'.$c->eventlink().'"><br>';
+ if ($c->band()=='') //actions differ if we update or create a concert, hence two buttons needed
$content.='<p><input type="submit" name="newconcert" value="Create New Concert"></p>';
- else
+ 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>';
+ .'</form>';
return $content;
}
@@ -302,7 +290,7 @@ if ( !class_exists( 'GiglogAdmin_AdminPage' ) ) {
// return the table
return $content;
}
-
+
static function update()
{
@@ -342,49 +330,49 @@ if ( !class_exists( 'GiglogAdmin_AdminPage' ) ) {
//$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
- {
+ 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
- {
+ 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
+ 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']);
+ 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']);
+ 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/admin/views/giglog_import_gigs.php b/includes/admin/views/giglog_import_gigs.php
index 04b2351..d0520e7 100644
--- a/includes/admin/views/giglog_import_gigs.php
+++ b/includes/admin/views/giglog_import_gigs.php
@@ -85,7 +85,7 @@ if ( !class_exists( 'GiglogAdmin_ImportGigsPage' ) ) {
if (is_numeric($venue))
$newconcert[1] = $venue;
else {
- $v = GiglogAdmin_Venue::find_or_create($venue,'Oslo');
+ $v = GiglogAdmin_Venue::find_or_create($venue,'Oslo'); //phase 666 of the project should maybe consider both city and band country when creating concerts/importing files
$newconcert[1] = $v->id();
}
@@ -98,22 +98,34 @@ if ( !class_exists( 'GiglogAdmin_ImportGigsPage' ) ) {
. ', VENUE ' . $venue . ' with venue ID ' . $newconcert[1]
. ', CONCERTDATE ' . $condate);
} else {
- $id = GiglogAdmin_Concert::create(
+ $id = GiglogAdmin_Concert::find_or_create(
+ '',
$newconcert[0],
$newconcert[1],
$condate,
$ticketlink,
- $eventlink);
-
+ $eventlink);
+
error_log( 'NEW CONCERT ADDED: '
- . ' ID: ' . $id
+ . ' ID: ' . $id->id()
. ' BAND ' . $band . ' with band ID ' . $newconcert[0]
. ', VENUE ' . $venue . ' with venue ID ' . $newconcert[1]
. ', CONCERTDATE ' . $condate
. ', Ticket LINK ' . $ticketlink
. ', Event LINK ' . $eventlink);
- GiglogAdmin_Concertlogs::add($id);
+ GiglogAdmin_Concertlogs::add($id->id());
+
+ /*the last line can be replaced by a trigger
+ CREATE TRIGGER `insertIntoPhotoLogs` AFTER INSERT ON `wpg_concerts`
+ FOR EACH ROW INSERT INTO wpg_concertlogs (
+ wpg_concertlogs.id,
+ wpg_concertlogs.wpgcl_concertid,
+ wpg_concertlogs.wpgcl_status)
+
+ VALUES
+ (null, new.id, 1)
+ */
}
}
}
diff --git a/includes/concert.php b/includes/concert.php
index 774b72a..5c50d43 100644
--- a/includes/concert.php
+++ b/includes/concert.php
@@ -1,79 +1,157 @@
-<?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);
- }
- }
-}
-?>
+<?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
+ {
+ private $id;
+ private $band;
+ private $venue;
+ private $cdate;
+ private $tickets;
+ private $eventlink;
+
+ /*
+ * Constructs a new venue object from an array of attributes.
+ * The attributes are expected to be named as in the database,
+ * so this constructor can be used to construct the object
+ * directly from the database row.
+ */
+ private function __construct($attrs)
+ {
+ $this->id = isset($attrs->id) ? $attrs->id : NULL;
+ $this->band = isset($attrs->band) ? $attrs->band : NULL;
+ $this->venue = isset($attrs->venue) ? $attrs->venue : NULL;
+ $this->cdate = isset($attrs->wpgconcert_date) ? $attrs->wpgconcert_date : NULL;
+ $this->tickets = isset($attrs->wpgconcert_tickets) ? $attrs->wpgconcert_tickets : NULL;
+ $this->eventlink = isset($attrs->wpgconcert_event) ? $attrs->wpgconcert_event : NULL;
+ }
+
+ static function find_or_create($id,$band, $venue, $cdate, $ticketlink, $eventlink)
+ {
+ global $wpdb;
+ if($id)
+ {
+ $csql = 'SELECT * FROM wpg_concerts WHERE id="' . $id . '"';
+ $results = $wpdb->get_results($csql);
+
+ if ($results)
+ return new GiglogAdmin_Concert($results[0]);
+ }
+ else {
+
+ return GiglogAdmin_Concert::create($band, $venue, $cdate, $ticketlink, $eventlink);
+ }
+ }
+
+ public static function create($band, $venue, $cdate, $ticketlink, $eventlink)
+ {
+ $attrs = new stdClass();
+ $attrs->id = '';
+ $attrs->band = $band;
+ $attrs->venue = $venue;
+ $attrs->wpgconcert_date = $cdate;
+ $attrs->wpgconcert_tickets = $ticketlink;
+ $attrs->wpgconcert_event = $eventlink;
+ $cid = new GiglogAdmin_Concert($attrs);
+ $cid->save();
+
+ return $cid;
+ }
+
+
+ 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);
+ }
+
+ public function save()
+ {
+ global $wpdb;
+
+ $wpdb->insert('wpg_concerts', array(
+ 'id' => '',
+ 'band' => $this->band,
+ 'venue' => $this->venue,
+ 'wpgconcert_date' => $this->cdate,
+ 'wpgconcert_tickets' => $this->tickets,
+ 'wpgconcert_event' => $this->eventlink
+ ));
+
+ $this->id = $wpdb->insert_id;
+ }
+
+ public function id()
+ {
+ return $this->id;
+ }
+
+ public function band()
+ {
+ return $this->band;
+ }
+ public function venue()
+ {
+ return $this->venue;
+ }
+ public function cdate()
+ {
+ return $this->cdate;
+ }
+ public function tickets()
+ {
+ return $this->tickets;
+ }
+ public function eventlink()
+ {
+ return $this->eventlink;
+ }
+ }
+}
+?> \ No newline at end of file