summaryrefslogtreecommitdiffstats
path: root/includes/admin/views
diff options
context:
space:
mode:
Diffstat (limited to 'includes/admin/views')
-rw-r--r--includes/admin/views/_concerts_cal_dld.php162
-rw-r--r--includes/admin/views/_concerts_table.php268
-rw-r--r--includes/admin/views/_edit_concert_form.php2
-rw-r--r--includes/admin/views/giglog_import_gigs.php102
4 files changed, 209 insertions, 325 deletions
diff --git a/includes/admin/views/_concerts_cal_dld.php b/includes/admin/views/_concerts_cal_dld.php
deleted file mode 100644
index f306a69..0000000
--- a/includes/admin/views/_concerts_cal_dld.php
+++ /dev/null
@@ -1,162 +0,0 @@
-<?php
-
- // Fix PHP headers
- ob_start();
-
-use Kigkonsult\Icalcreator\Vcalendar;
-use DateTime;
-use DateTimezone;
-
-
- function icalvalue(): string
- {
- $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,
- "This is a demo calendar"
- )
- ->setXprop(
- Vcalendar::X_WR_RELCALID,
- "3E26604A-50F4-4449-8B3E-E4F4932D05B5"
- )
- ->setXprop(
- Vcalendar::X_WR_TIMEZONE,
- "Europe/Stockholm"
- );
-
- // create a new event
-$event1 = $vcalendar->newVevent()
- ->setTransp( Vcalendar::OPAQUE )
- ->setClass( Vcalendar::P_BLIC )
- ->setSequence( 1 )
- // describe the event
- ->setSummary( 'Scheduled meeting with five occurrences' )
- ->setDescription(
- 'Agenda for the the meeting...',
- [ Vcalendar::ALTREP =>
- 'CID:<FFFF__=0ABBE548DFE235B58f9e8a93d@coffeebean.com>' ]
- )
- ->setComment( 'It\'s going to be fun..' )
- // place the event
- ->setLocation( 'Kafé Ekorren Stockholm' )
- ->setGeo( '59.32206', '18.12485' )
- // set the time
- ->setDtstart(
- new DateTime(
- '20220421T090000',
- new DateTimezone( 'Europe/Stockholm' )
- )
- )
- ->setDtend(
- new DateTime(
- '20220421T100000',
- new DateTimezone( 'Europe/Stockholm' )
- )
- )
- // with recurrence rule
-
-
-;
-
- // add alarm for the event
-$alarm = $event1->newValarm()
- ->setAction( Vcalendar::DISPLAY )
- // copy description from event
- ->setDescription( $event1->getDescription())
- // fire off the alarm one day before
- ->setTrigger( '-P1D' );
-
- // alter day and time for one event in recurrence set
-$event2 = $vcalendar->newVevent()
- ->setTransp( Vcalendar::OPAQUE )
- ->setClass( Vcalendar::P_BLIC )
- // reference to event in recurrence set
- ->setUid( $event1->getUid())
- ->setSequence( 2 )
- // pointer to event in the recurrence set
- ->setRecurrenceid( '20220505T090000 Europe/Stockholm' )
- // reason text
- ->setDescription(
- 'Altered day and time for event 2022-05-05',
- [ Vcalendar::ALTREP =>
- 'CID:<FFFF__=0ABBE548DFE235B58f9e8a93d@coffeebean.com>' ]
- )
- ->setComment( 'Now we are working hard for two hours' )
- // the altered day and time with duration
- ->setDtstart(
- new DateTime(
- '20220504T100000',
- new DateTimezone( 'Europe/Stockholm' )
- )
- )
- ->setDuration( 'PT2H' )
- // add alarm (copy from event1)
- ->setComponent(
- $event1->getComponent( Vcalendar::VALARM )
- );
-
-$vcalendarString =
- // apply appropriate Vtimezone with Standard/DayLight components
- $vcalendar->vtimezonePopulate()
- // and create the (string) calendar
- ->createCalendar();
-
-return($vcalendarString);
- }
-
-
-
-function dldCal()
-{
-
-
-if(isset($_POST['download'])){
- $file = "test.ical";
- $txt = fopen($file, "w") or die("Unable to open file!");
-fwrite($txt, icalvalue());
-fclose($txt);
-
- $filename = "myzipfile.zip";
-
- if (file_exists($file)) {
- header('Content-Type: application/zip');
- header('Content-Disposition: attachment; filename="'.basename($file).'"');
- header('Content-Length: ' . filesize($file));
- ob_clean();
- flush();
- echo readfile($file);
- // delete file
- // unlink($file);
-
- }
-}
-/*
-
-
-
-
-header('Content-Type: text/calendar');
-header('Content-Disposition: attachment; filename="'.basename($file).'"');
-header('Content-Transfer-Encoding: binary');
-header('Expires: 0');
-header('Content-Length:'. filesize($file));
-header('Pragma: public');
-ob_clean();
-//flush();
-readfile('test.ical');
-//echo file_get_contents($file);
-
-*/
-
-
-
-
-}
-
diff --git a/includes/admin/views/_concerts_table.php b/includes/admin/views/_concerts_table.php
index 8d38eab..066e14c 100644
--- a/includes/admin/views/_concerts_table.php
+++ b/includes/admin/views/_concerts_table.php
@@ -34,18 +34,21 @@ if (!class_exists("GiglogAdmin_ConcertsTable"))
public function render(): string
{
return $this->render_filters()
- . $this->render_concerts_table();
+ . $this->render_concerts_table();
}
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>';
@@ -121,42 +124,42 @@ if (!class_exists("GiglogAdmin_ConcertsTable"))
private function render_pagination() : string
{
$content =
- '<div id="pagtextbox" style="display:flex">'
- . '<span class="alignleft" style="text-align:left;flex:auto;">';
+ '<div id="pagtextbox" style="display:flex">'
+ . '<span class="alignleft" style="text-align:left;flex:auto;">';
if($this->page_no > 1) {
$content .=
- '<span>'
- . '<a href="'. add_query_arg( 'page_no', 1 ) . '">'
- . 'First Page</a> -'
- . '</span>'
- . '<span>'
- . '<a href="' . add_query_arg( 'page_no', $this->previous_page ) . '">'
- . ' Previous</a></span>';
+ '<span>'
+ . '<a href="'. add_query_arg( 'page_no', 1 ) . '">'
+ . 'First Page</a> -'
+ . '</span>'
+ . '<span>'
+ . '<a href="' . add_query_arg( 'page_no', $this->previous_page ) . '">'
+ . ' Previous</a></span>';
}
$content .= '</span>'
- . '<span class="aligncenter" style="text-align:center;flex:auto">'
- . '<strong>Page ' . $this->page_no . ' of ' . $this->total_no_of_pages . '</strong>'
- . '</span>';
+ . '<span class="aligncenter" style="text-align:center;flex:auto">'
+ . '<strong>Page ' . $this->page_no . ' of ' . $this->total_no_of_pages . '</strong>'
+ . '</span>';
$content .= '<span class="alignright" style="text-align:right;flex:auto;float:none">';
if ($this->page_no < $this->total_no_of_pages) {
$content .=
- '<span>'
- . '<a href="' . add_query_arg( 'page_no', $this->next_page ) . '">'
- . 'Next</a> - '
- . '</span>'
- . '<span>'
- . '<a href="' . add_query_arg( 'page_no', $this->total_no_of_pages ) .'">'
- . 'Last Page</a>'
- . '</span>';
+ '<span>'
+ . '<a href="' . add_query_arg( 'page_no', $this->next_page ) . '">'
+ . 'Next</a> - '
+ . '</span>'
+ . '<span>'
+ . '<a href="' . add_query_arg( 'page_no', $this->total_no_of_pages ) .'">'
+ . 'Last Page</a>'
+ . '</span>';
}
$content .=
- '</span>'
- . '</div>';
+ '</span>'
+ . '</div>';
return $content;
}
@@ -209,10 +212,11 @@ if (!class_exists("GiglogAdmin_ConcertsTable"))
if (current_user_can('administrator')) {
$content .= '<td class="adminbuttons">'
- . $this->adminactions($concert)
- . '</td>';
+ . $this->adminactions($concert)
+ . '</td>';
}
}
+ $content .= '<td> <a href="'.get_admin_url().'admin-ajax.php?action=giglog_export_ical&evid='.$concert->id().'">iCal</td>';
$content .= '</tr>';
$lastType = $concert->venue()->city();
}
@@ -240,116 +244,116 @@ if (!class_exists("GiglogAdmin_ConcertsTable"))
}
$select .= '<input type="hidden" name="' . esc_attr( $name )
- . '" value="' . esc_attr( $val ) . '">';
+ . '" value="' . esc_attr( $val ) . '">';
}
$cty = $this->get_filter('city');
$select .= \EternalTerror\ViewHelpers\select_field(
- "city",
- array_map(fn($city) => [$city, $city], GiglogAdmin_Venue::all_cities()),
- $cty,
- "Select city...");
-
-
- if ( !empty($cty) ) {
- //second drop down for venue
- $select .= \EternalTerror\ViewHelpers\select_field(
- "venue",
- array_map(
- fn($venue) => [$venue->id(), $venue->name()],
- GiglogAdmin_Venue::venues_in_city($cty)
- ),
- $this->get_filter('venue_id'),
- "Select venue...");
- }
-
- $select .= \EternalTerror\ViewHelpers\select_field(
- "month",
- array_map(
- fn($m) => [ $m, $wp_locale->get_month( $m ) ],
- range( 1, 12 )
- ),
- $this->get_filter('month'),
- "Select month...");
-
- $select.='</select>';
-
- if(is_admin()) {
- //option to select own concerts only
- $select .= '<input name="only_mine" class="ownconc" type="checkbox" value="1"'
- . checked( $this->get_filter( 'current_user' ) )
- . '><label for="ownconcerts">Show own concerts only</label>';
+ "city",
+ array_map(fn($city) => [$city, $city], GiglogAdmin_Venue::all_cities()),
+ $cty,
+ "Select city...");
+
+
+ if ( !empty($cty) ) {
+ //second drop down for venue
+ $select .= \EternalTerror\ViewHelpers\select_field(
+ "venue",
+ array_map(
+ fn($venue) => [$venue->id(), $venue->name()],
+ GiglogAdmin_Venue::venues_in_city($cty)
+ ),
+ $this->get_filter('venue_id'),
+ "Select venue...");
+ }
- }
- //NOTE that I remvoed </form></p> and mvoed them up to render_concerts_table function
- $select .= '<input class="applybutton" type="submit" value="Apply Filters">';
+ $select .= \EternalTerror\ViewHelpers\select_field(
+ "month",
+ array_map(
+ fn($m) => [ $m, $wp_locale->get_month( $m ) ],
+ range( 1, 12 )
+ ),
+ $this->get_filter('month'),
+ "Select month...");
- return $select;
- }
+ $select.='</select>';
- private function adminactions( GiglogAdmin_Concert $concert ) : string
- {
- return
- '<form class="adminactions" method="POST" action="">'
- . '<input type="hidden" name="cid" value="' . $concert->id() . '" />'
- . \EternalTerror\ViewHelpers\select_field(
- 'selectstatus',
- array_map(fn($i) => [ $i, self::STATUS_LABELS[$i] ], range(1, count(self::STATUS_LABELS) - 1)),
- $concert->status())
- . '<input type="submit" value="SetStatus">'
- . '<input type="submit" name ="edit" value="EDIT">'
- . '</form>';
- }
+ if(is_admin()) {
+ //option to select own concerts only
+ $select .= '<input name="only_mine" class="ownconc" type="checkbox" value="1"'
+ . checked( $this->get_filter( 'current_user' ) )
+ . '><label for="ownconcerts">Show own concerts only</label>';
- /**
- * Display a mark on the concert if it is new.
- * I.e. imported/created within the last ten days.
- *
- * @return null|string
- */
- private function mark_new_concert(GiglogAdmin_Concert $concert) : string
- {
- $now = new DateTime();
- $new_entry = $now->diff($concert->created())->days <= 10;
- if ($new_entry) {
- return '<span style="color:green">NEW</span>';
- }
- else {
- return '';
- }
- }
+ }
+ //NOTE that I remvoed </form></p> and mvoed them up to render_concerts_table function
+ $select .= '<input class="applybutton" type="submit" value="Apply Filters">';
- private function assign_role_for_user_form(string $role, GiglogAdmin_Concert $concert) : ?string
- {
- $roles = $concert->roles();
- $assigned_user = array_key_exists($role, $roles) ? $roles[$role] : NULL;
-
- //first check if current slot is taken by current user
- if ( $assigned_user == $this->username ) {
- $f = '<form class="unassign_concert" method="POST" action="">'
- . ' <input type="hidden" name="cid" value="' . $concert->id() . '" />'
- . ' <input type="hidden" name="pid" value="' . $role . '" />'
- . ' <input type="submit" name="unassignitem" value=""/>'
- . '</form>';
- }
- elseif ( $assigned_user ) { //check if slot is taken by another user
- $f = '<span class="takenby">Taken</span>'
- . '<div class="takenby">Taken by ' . $assigned_user . '</div>';
- }
- elseif ( array_search($this->username, $roles) ) {
- // other slots for this concert are taken by user
- $f = '<span class="taken_by_self">-</span>';
- }
- else { //not taken by anyone
- $f = '<form class="assign_concert" method="POST" action="">'
- . ' <input type="hidden" name="cid" value="' . $concert->id() . '" />'
- . ' <input type="hidden" name="pid" value="' . $role. '" />'
- . ' <input type="submit" name="assignitem" value=""/>'
- . '</form>';
- }
+ return $select;
+ }
- return $f;
- }
- }
-}
+ private function adminactions( GiglogAdmin_Concert $concert ) : string
+ {
+ return
+ '<form class="adminactions" method="POST" action="">'
+ . '<input type="hidden" name="cid" value="' . $concert->id() . '" />'
+ . \EternalTerror\ViewHelpers\select_field(
+ 'selectstatus',
+ array_map(fn($i) => [ $i, self::STATUS_LABELS[$i] ], range(1, count(self::STATUS_LABELS) - 1)),
+ $concert->status())
+ . '<input type="submit" value="SetStatus">'
+ . '<input type="submit" name ="edit" value="EDIT">'
+ . '</form>';
+ }
+
+ /**
+ * Display a mark on the concert if it is new.
+ * I.e. imported/created within the last ten days.
+ *
+ * @return null|string
+ */
+ private function mark_new_concert(GiglogAdmin_Concert $concert) : string
+ {
+ $now = new DateTime();
+ $new_entry = $now->diff($concert->created())->days <= 10;
+ if ($new_entry) {
+ return '<span style="color:green">NEW</span>';
+ }
+ else {
+ return '';
+ }
+ }
+
+ private function assign_role_for_user_form(string $role, GiglogAdmin_Concert $concert) : ?string
+ {
+ $roles = $concert->roles();
+ $assigned_user = array_key_exists($role, $roles) ? $roles[$role] : NULL;
+
+ //first check if current slot is taken by current user
+ if ( $assigned_user == $this->username ) {
+ $f = '<form class="unassign_concert" method="POST" action="">'
+ . ' <input type="hidden" name="cid" value="' . $concert->id() . '" />'
+ . ' <input type="hidden" name="pid" value="' . $role . '" />'
+ . ' <input type="submit" name="unassignitem" value=""/>'
+ . '</form>';
+ }
+ elseif ( $assigned_user ) { //check if slot is taken by another user
+ $f = '<span class="takenby">Taken</span>'
+ . '<div class="takenby">Taken by ' . $assigned_user . '</div>';
+ }
+ elseif ( array_search($this->username, $roles) ) {
+ // other slots for this concert are taken by user
+ $f = '<span class="taken_by_self">-</span>';
+ }
+ else { //not taken by anyone
+ $f = '<form class="assign_concert" method="POST" action="">'
+ . ' <input type="hidden" name="cid" value="' . $concert->id() . '" />'
+ . ' <input type="hidden" name="pid" value="' . $role. '" />'
+ . ' <input type="submit" name="assignitem" value=""/>'
+ . '</form>';
+ }
+
+ return $f;
+ }
+ }
+ }
diff --git a/includes/admin/views/_edit_concert_form.php b/includes/admin/views/_edit_concert_form.php
index 6e4f5e5..9bddfba 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 1a72fe1..e523dee 100644
--- a/includes/admin/views/giglog_import_gigs.php
+++ b/includes/admin/views/giglog_import_gigs.php
@@ -38,51 +38,93 @@ if ( !class_exists( 'GiglogAdmin_ImportGigsPage' ) ) {
}
/**
- * Imports concert data from a file with tab separated values.
- *
- * The file must contain the following columns each separated by _one_
- * tab character:
- *
- * 1. Concertname
- * 2. Venuename or numeric venue id
- * 3. Concert date
- * 4. Ticket link
- * 5. Event info link
- *
- * Empty lines are ignored.
- *
- * @return void
- *
- * @param array<int, mixed>
- */
+ * Imports concert data from a file with tab separated values.
+ *
+ * The file must contain the following columns each separated by _one_
+ * tab character:
+ *
+ * 1. Concertname
+ * 2. Venuename or numeric venue id
+ * 3. Concert date
+ * 4. Ticket link
+ * 5. Event info link
+ *
+ * Empty lines are ignored.
+ *
+ * @return void
+ *
+ * @param array<int, 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 (empty(trim($resultArray[0])))
+ { $importerrors.= 'Row '.$rid.' is missing concert name!'."<br>";
+ continue;
+ }
+ else if (empty(trim($resultArray[1])))
+ { $importerrors.= 'Row '.$rid.' is missing venue name!'."<br>";
+ continue;
+ }
- if (is_numeric($venue)) {
- $venue = GiglogAdmin_Venue::get($venue);
+ else if (empty(trim($resultArray[2])))
+ { $importerrors.= 'Row '.$rid.' is missing city name!' ."<br>";
+ continue;
}
+
else {
- $venue = GiglogAdmin_Venue::find_or_create($venue,'Oslo');
- }
+ $condate = date('Y-m-d', strtotime($resultArray[3]));
+ if ($condate<date("Y-m-d"))
+ {$importerrors.= 'Row '.$rid.' has date in the past!' ."<br>";
+ continue; }
+
+ else {
+
+
+ $cname = trim($resultArray[0]);
+ $venue = trim($resultArray[1]);
- $condate = date('Y-m-d', strtotime($resultArray[2]));
- $ticketlink = trim($resultArray[3]);
- $eventlink = trim($resultArray[4]);
- 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');
}
}
}
-}