summaryrefslogtreecommitdiffstats
path: root/includes
diff options
context:
space:
mode:
authorHarald Eilertsen <haraldei@anduin.net>2022-03-09 21:41:54 +0100
committerHarald Eilertsen <haraldei@anduin.net>2022-03-09 21:41:54 +0100
commit4ceb50835b38f74b68a4d1d1e0d3a32baeeb8b89 (patch)
tree1cf0a87c65b9b3970a775e51848dae1affb90f34 /includes
parent82a3901a6d68f088aff335a1bc88b9878e17e990 (diff)
parente1ac66aade5c2d5d2d9f6c6db501fccd9db9be0a (diff)
downloadgigologadmin-4ceb50835b38f74b68a4d1d1e0d3a32baeeb8b89.tar.gz
gigologadmin-4ceb50835b38f74b68a4d1d1e0d3a32baeeb8b89.tar.bz2
gigologadmin-4ceb50835b38f74b68a4d1d1e0d3a32baeeb8b89.zip
Merge remote-tracking branch 'andrea/andreaschanges' into dev
And fixup most whitespace issues while at it.
Diffstat (limited to 'includes')
-rw-r--r--includes/admin/views/_concerts_table.php28
-rw-r--r--includes/admin/views/_edit_concert_form.php2
-rw-r--r--includes/admin/views/giglog_import_gigs.php79
-rw-r--r--includes/ical_export.php79
-rw-r--r--includes/venue.php2
5 files changed, 163 insertions, 27 deletions
diff --git a/includes/admin/views/_concerts_table.php b/includes/admin/views/_concerts_table.php
index 7b4338c..091bf83 100644
--- a/includes/admin/views/_concerts_table.php
+++ b/includes/admin/views/_concerts_table.php
@@ -41,13 +41,14 @@ if (!class_exists("GiglogAdmin_ConcertsTable"))
private function render_concert_table_header() : string
{
- $content =
- '<div style="overflow-x:auto;"><table class="assignit">'
- . '<tr class="assignithrow">'
- . ' <th>CITY</th><th>DATE</th><th>NAME</th><th>VENUE</th>';
+ $content = '<div style="overflow-x:auto;"><table class="assignit">';
+ $content.= '<span style="font-size:0.8em;font-style: italic;"> Note: the iCal link will download a file with extension .ical which can be used to add the event to your calendar. For convenience, we set all events with start time at 19:00 but please check the actual event for the correct time.</span>';
+
+ $content.= '<tr class="assignithrow">';
+ $content.= '<th>CITY</th><th>DATE</th><th>NAME</th><th>VENUE</th>';
if (!is_admin()) {
- $content .= '<th>EVENT</th><th>TICKETS</th>';
+ $content .= '<th>EVENT</th><th>TICKETS</th><th>Calendar</th>';
}
else {
$content .= '<th></th><th>PHOTO1</th><th>PHOTO2</th><th>TEXT1</th><th>TEXT2</th><th>STATUS</th>';
@@ -85,7 +86,7 @@ if (!class_exists("GiglogAdmin_ConcertsTable"))
$this->filter['currentuser'] = $this->username;
}
- if (isset($_GET['page_no']) && $_GET['page_no'] != "" && is_numeric($_GET['page_no'])) {
+ if (isset($_GET['page_no']) && $_GET['page_no'] != "" && is_numeric($_GET['page_no']) && isset($_GET['page_no']) == $this->page_no ) {
$this->page_no = intval($_GET['page_no']);
} else {
$this->page_no = 1;
@@ -104,6 +105,11 @@ if (!class_exists("GiglogAdmin_ConcertsTable"))
$this->previous_page = $this->page_no - 1;
$this->next_page = $this->page_no + 1;
+
+ if ($this->page_no > $this->total_no_of_pages ) {
+ $this->page_no = 1;
+ }
+
$this->filter['offset'] = $offset;
$this->filter['recperpage'] = $total_records_per_page;
@@ -200,6 +206,7 @@ if (!class_exists("GiglogAdmin_ConcertsTable"))
$content .= "<td><a target=\"_blank\" href=\"{$concert->tickets()}\">Tickets</a></td>";
}
+ $content .= '<td> <a href="'.get_admin_url().'admin-ajax.php?action=giglog_export_ical&evid='.$concert->id().'">iCal</td>';
$content .= '</tr>';
$last_city = $concert->venue()->city();
}
@@ -233,11 +240,10 @@ if (!class_exists("GiglogAdmin_ConcertsTable"))
$cty = $this->get_filter('city');
$select .= \EternalTerror\ViewHelpers\select_field(
- "city",
- array_map(fn($city) => [$city, $city], GiglogAdmin_Venue::all_cities()),
- $cty,
- "Select city...");
-
+ "city",
+ array_map(fn($city) => [$city, $city], GiglogAdmin_Venue::all_cities()),
+ $cty,
+ "Select city...");
if ( !empty($cty) ) {
//second drop down for venue
diff --git a/includes/admin/views/_edit_concert_form.php b/includes/admin/views/_edit_concert_form.php
index c7b8780..d17ef2d 100644
--- a/includes/admin/views/_edit_concert_form.php
+++ b/includes/admin/views/_edit_concert_form.php
@@ -53,7 +53,7 @@ if (!class_exists("GiglogAdmin_EditConcertForm"))
.'<label for="cname">Concert Name:</label><textarea id="cname" name="cname" value="'.$c->cname().'">'.$c->cname().'</textarea><br>'
.'<label for="venue">Venue:</label>' . $this->get_venue_selector($c->venue()) . '<br>'
//date has to be formatted else it is not red in the date field of html form
- .'<label for="cdate">Date:</label><input type="date" id="cdate" name="cdate" value="'.strftime('%d/%m/%Y',strtotime($c->cdate())).'"><br>'
+ .'<label for="cdate">Date:</label><input type="date" id="cdate" name="cdate" value="'.date('Y-m-d',strtotime($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>'
.'</fieldset>';
diff --git a/includes/admin/views/giglog_import_gigs.php b/includes/admin/views/giglog_import_gigs.php
index 62717c6..ed6f978 100644
--- a/includes/admin/views/giglog_import_gigs.php
+++ b/includes/admin/views/giglog_import_gigs.php
@@ -56,32 +56,83 @@ if ( !class_exists( 'GiglogAdmin_ImportGigsPage' ) ) {
* @param array<mixed>
*/
static function process_upload(array $file): void {
+ global $wpdb;
$newconcert= [];
$fo = new SplFileObject($file['tmp_name']);
-
+ $importerrors = '';
+ $rid=0;
foreach ($fo as $line) {
+ $rid++;
$line = trim( $line );
if ( empty($line) ) {
// Skip empty lines
continue;
}
-
$resultArray = explode("\t", $line);
- $cname = trim($resultArray[0]);
- $venue = trim($resultArray[1]);
-
- if (is_numeric($venue)) {
- $venue = GiglogAdmin_Venue::get($venue);
- }
- else {
- $venue = GiglogAdmin_Venue::find_or_create($venue,'Oslo');
+ //unsure if this is needed, considering we are also checking if each individual important field is missing. But if they are not replaced by tabs, then everything gets shifted so probably best to check if a //value is empty and NOT replaced by tab
+ if (count($resultArray)<6)
+ {
+ $importerrors.= 'Row '.$rid.' is missing a field!'."<br>";
+ continue;
}
+ else{
+ //Below only checks if the date field is made of 4-2-2 digits, irregardless of their values. Actual date check is lower
+ if( ! preg_match("/\d{4}\-\d{2}-\d{2}/",$resultArray[3]))
+ {
+ $importerrors.= 'Row '.$rid.' has invalid date!'.$resultArray[3]."<br>";
- $condate = date('Y-m-d', strtotime($resultArray[2]));
- $ticketlink = trim($resultArray[3]);
- $eventlink = trim($resultArray[4]);
+ continue;
+ }
+ else {
+ if (empty(trim($resultArray[0]))) {
+ $importerrors.= 'Row '.$rid.' is missing concert name!'."<br>";
+ continue;
+ }
+ elseif (empty(trim($resultArray[1]))) {
+ $importerrors.= 'Row '.$rid.' is missing venue name!'."<br>";
+ continue;
+ }
+ elseif (empty(trim($resultArray[2]))) {
+ $importerrors.= 'Row '.$rid.' is missing city name!' ."<br>";
+ continue;
+ }
+ else {
+ $condate = date('Y-m-d', strtotime($resultArray[3]));
+ if ($condate<date("Y-m-d")) {
+ $importerrors.= 'Row '.$rid.' has date in the past!' .$resultArray[3]."<br>";
+ continue;
+ }
+ else {
+ $cname = trim($resultArray[0]);
+ $venue = trim($resultArray[1]);
- GiglogAdmin_Concert::create($cname, $venue->id(), $condate, $ticketlink, $eventlink);
+ if (is_numeric($venue)) {
+ $venue = GiglogAdmin_Venue::get($venue);
+ }
+ else {
+ $venue = GiglogAdmin_Venue::find_or_create($venue,trim($resultArray[2]));
+ }
+
+ $ticketlink = trim($resultArray[4]);
+ $eventlink = trim($resultArray[5]);
+
+ try {
+ GiglogAdmin_Concert::create($cname, $venue->id(), $condate, $ticketlink, $eventlink);
+ }
+ catch(Exception $e) {
+ $importerrors.= 'Row '.$rid.' is duplicate (or failed due unknown error)!'."<br>";
+ }
+ }
+ }
+ }
+ }
+ }
+
+ if (!empty($importerrors)) {
+ echo ($importerrors);
+ }
+ else {
+ echo ('All rows imported ok');
}
}
}
diff --git a/includes/ical_export.php b/includes/ical_export.php
new file mode 100644
index 0000000..c56e349
--- /dev/null
+++ b/includes/ical_export.php
@@ -0,0 +1,79 @@
+<?php
+
+// SPDX-FileCopyrightText: 2022 Andrea Chirulescu <andrea.chirulescu@gmail.com>
+// SPDX-FileCopyrightText: 2022 Harald Eilertsen <haraldei@anduin.net>
+//
+// SPDX-License-Identifier: AGPL-3.0-or-later
+
+use Kigkonsult\Icalcreator\Vcalendar;
+
+if ( ! class_exists( "GiglogAdmin_IcalExport" ) )
+{
+ class Giglogadmin_IcalExport
+ {
+ public static function export_ical()
+
+ {
+ $evid = $_GET['evid'];
+
+ $concert = GiglogAdmin_Concert::get($evid);
+ $cfullname = $concert->cname().' live at '. $concert->venue()->name() .', '.$concert->venue()->city();
+ $fdate = strtotime($concert->cdate());
+ $newformat = date('Ymd',$fdate);
+ // create a new calendar
+ $vcalendar = Vcalendar::factory( [ Vcalendar::UNIQUE_ID => "kigkonsult.se", ] )
+ // with calendaring info
+ ->setMethod( Vcalendar::PUBLISH )
+ ->setXprop(
+ Vcalendar::X_WR_CALNAME,
+ "Calendar Sample"
+ )
+ ->setXprop(
+ Vcalendar::X_WR_CALDESC,
+ "Concert ".$cfullname . ""
+ )
+ ->setXprop(
+ Vcalendar::X_WR_RELCALID,
+ "3E26604A-50F4-4449-8B3E-E4F4932D05B5"
+ )
+ ->setXprop(
+ Vcalendar::X_WR_TIMEZONE,
+ "Europe/Oslo"
+ );
+
+ // create a new event
+ $event1 = $vcalendar->newVevent()
+ ->setTransp( Vcalendar::OPAQUE )
+ ->setClass( Vcalendar::P_BLIC )
+ ->setSequence( 1 )
+ // describe the event
+ ->setSummary("".$cfullname."" )
+ ->setDescription("".$cfullname."" )
+ ->setComment ("".$cfullname."" )
+ // place the event
+ ->setLocation( "".$concert->venue()->name() .', '.$concert->venue()->city() ."" )
+ // set the time
+ ->setDtstart(
+ new DateTime(
+ $newformat.'T190000',
+ new DateTimezone( 'Europe/Oslo' )
+ )
+ )
+ ->setDuration ("PT4H")
+
+ ;
+ $vcalendarString =
+ // apply appropriate Vtimezone with Standard/DayLight components
+ $vcalendar->vtimezonePopulate()
+ // and create the (string) calendar
+ ->createCalendar();
+
+ header( 'Content-Type: text/calendar' );
+ echo $vcalendarString;
+ die();
+ }
+ }
+
+ add_action( 'wp_ajax_nopriv_giglog_export_ical', [ 'GiglogAdmin_IcalExport', 'export_ical' ] );
+ add_action( 'wp_ajax_giglog_export_ical', [ 'GiglogAdmin_IcalExport', 'export_ical' ] );
+ }
diff --git a/includes/venue.php b/includes/venue.php
index 177ba2d..5e9ecf9 100644
--- a/includes/venue.php
+++ b/includes/venue.php
@@ -75,7 +75,7 @@ if ( !class_exists('GiglogAdmin_Venue') ) {
{
global $wpdb;
$venuesql = "SELECT * FROM {$wpdb->prefix}giglogadmin_venues "
- . $wpdb->prepare("WHERE upper(wpgvenue_name)=upper(%s) and wpgvenue_city=%s", $name, $city);
+ . $wpdb->prepare("WHERE upper(wpgvenue_name)=upper(%s) and upper(wpgvenue_city)=upper(%s)", $name, $city);
$results = $wpdb->get_results($venuesql);