From 277fedffc624f55c6ecc8bd80ed8db370134e47e Mon Sep 17 00:00:00 2001
From: Harald Eilertsen
Date: Fri, 20 Jan 2023 20:22:06 +0100
Subject: Rename and reorganize more source files.
---
includes/admin/views/_concerts_table.php | 448 ---------------------
includes/admin/views/_edit_concert_form.php | 138 -------
includes/admin/views/_new_venue_form.php | 46 ---
.../admin/views/class-giglogadmin-adminpage.php | 96 +++++
.../views/class-giglogadmin-importgigspage.php | 138 +++++++
includes/admin/views/giglog_admin_page.php | 91 -----
includes/admin/views/giglog_import_gigs.php | 133 ------
7 files changed, 234 insertions(+), 856 deletions(-)
delete mode 100644 includes/admin/views/_concerts_table.php
delete mode 100644 includes/admin/views/_edit_concert_form.php
delete mode 100644 includes/admin/views/_new_venue_form.php
create mode 100644 includes/admin/views/class-giglogadmin-adminpage.php
create mode 100644 includes/admin/views/class-giglogadmin-importgigspage.php
delete mode 100644 includes/admin/views/giglog_admin_page.php
delete mode 100644 includes/admin/views/giglog_import_gigs.php
(limited to 'includes/admin/views')
diff --git a/includes/admin/views/_concerts_table.php b/includes/admin/views/_concerts_table.php
deleted file mode 100644
index 4f9b3c9..0000000
--- a/includes/admin/views/_concerts_table.php
+++ /dev/null
@@ -1,448 +0,0 @@
-
-// SPDX-FileCopyrightText: 2021 Harald Eilertsen
-//
-// SPDX-License-Identifier: AGPL-3.0-or-later
-
-require_once __DIR__ . '/../../view-helpers/select_field.php';
-
-if ( ! class_exists( 'GiglogAdmin_ConcertsTable' ) ) {
- class GiglogAdmin_ConcertsTable {
-
- const STATUS_LABELS = array(
- '',
- 'Accred Requested',
- 'Photo Approved',
- 'Text Approved',
- 'Photo and Text Approved',
- 'Rejected',
- );
-
- const FILTER_KEYS = array(
- 'city',
- 'venue',
- 'month',
- 'only_mine',
- );
-
- private string $username;
- private array $filter;
-
- private int $page_no = 1;
- private int $total_no_of_pages = 1;
- private int $previous_page = 0;
- private int $next_page = 0;
-
- private string $nonce;
-
- public static function update() : void {
- //
- // Check that we get a nonce, and that it is valid to prevent CSRF attacks.
- //
- if ( ! isset( $_POST['nonce'] ) || ! wp_verify_nonce( $_POST['nonce'], 'concerts-table' ) ) {
- wp_die( 'You are not allowed to do that.', 403 );
- exit();
- }
-
- if ( isset( $_POST['assignitem'] ) ) {
- $concert = GiglogAdmin_Concert::get( intval( $_POST['cid'] ) );
-
- if ( $concert ) {
- $role = sanitize_text_field( $_POST['pid'] );
- self::assignconcert( $role, $concert );
- }
-
- return;
- }
-
- if ( isset( $_POST['unassignitem'] ) ) {
- $concert = GiglogAdmin_Concert::get( intval( $_POST['cid'] ) );
-
- if ( $concert ) {
- $role = sanitize_text_field( $_POST['pid'] );
- self::unassignconcert( $role, $concert );
- }
-
- return;
- }
-
- // handle the status drop down
- if ( isset( $_POST['selectstatus'] ) && ! empty( $_POST['selectstatus'] ) && ! empty( $_POST['cid'] ) ) {
- if ( $_POST['selectstatus'] > 0 && $_POST['selectstatus'] < count( self::STATUS_LABELS ) ) {
- $concert = GiglogAdmin_Concert::get( intval( $_POST['cid'] ) );
- if ( $concert ) {
- $concert->set_status( intval( $_POST['selectstatus'] ) );
- $concert->save();
- self::emailuser( $concert, intval( $_POST['selectstatus'] ) );
- }
- }
- }
- }
-
- static function assignconcert( string $p1, GiglogAdmin_Concert $concert ): void {
- $username = wp_get_current_user()->user_login;
- $concert->assign_role( $p1, $username );
- $concert->save();
-
- $cuser = get_user_by( 'login', 'etadmin' );
-
- if ( $cuser ) {
- $dest = $cuser->user_email;
- $subject = 'WP-GIGLOG ' . $username . ' has taken ' . $p1 . 'for concert ' . $concert->cname();
- $body = 'WP-GIGLOG ' . $username . ' has taken ' . $p1 . 'for concert ' . $concert->cname() . ', concert with ID ' . $concert->id();
- $headers = array( 'Content-Type: text/html; charset=UTF-8' );
-
- wp_mail( $dest, $subject, $body );
- }
- }
-
- static function unassignconcert( string $p1, GiglogAdmin_Concert $concert ): void {
- $username = wp_get_current_user()->user_login;
- $concert->remove_user_from_roles( $username );
- $concert->save();
-
- $cuser = get_user_by( 'login', 'etadmin' );
-
- if ( $cuser ) {
- $dest = $cuser->user_email;
- $subject = 'WP-GIGLOG ' . $username . ' has UNASSIGNED ' . $p1 . 'for concert ' . $concert->cname();
- $body = 'WP-GIGLOG ' . $username . ' has UNASSIGNED ' . $p1 . 'for concert ' . $concert->cname() . ', concert with ID ' . $concert->id();
- $headers = array( 'Content-Type: text/html; charset=UTF-8' );
-
- wp_mail( $dest, $subject, $body );
- }
- }
-
- static function emailuser( GiglogAdmin_Concert $concert, string $cstatus ): void {
- $username = wp_get_current_user()->user_login;
- $useremail = 'live@eternal-terror.com';
- $dest = '';
- $roles = $concert->roles();
- $x = '';
-
- foreach ( $roles as $role ) {
- if ( $role ) {
- $cuser = get_user_by( 'login', $role );
-
- if ( $cuser ) {
- $dest .= $cuser->user_email . ',';
- }
- }
- }
-
- $subject = 'Message from GIGLOG: Concert ' . $concert->cname() . ' has a new status ' . $cstatus . '.';
- $body = 'You receive this message because you have assigned one of the roles for Concert ' . $concert->cname() . '.';
- $body .= '\r\n This is to inform you that there is a new status for the acreditation ' . $cstatus . '.';
- $body .= '\r\n Should you no longer want to receive updates about this concert, please log in to Giglog and remove yourself from the concert. Thanks!';
- $headers = array( 'Content-Type: text/plain; charset=UTF-8' ); // it is text by default so no need for headers actually
-
- wp_mail( $dest, $subject, $body );
- }
-
- public function __construct() {
- $this->username = wp_get_current_user()->user_login;
-
- // Set the nonce we use to check for CSRF attacks.
- $this->nonce = wp_create_nonce( 'concerts-table' );
- $this->get_args();
- }
-
- public function render(): string {
- return $this->render_filters()
- . $this->render_concerts_table();
- }
-
- private function render_concert_table_header() : string {
- $content = '
';
- $content .= '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.';
-
- $content .= '
The available slots are marked with the green checkbox.
+ If you click on it, it will be assigned to you and if you no longer
+ wish to cover that concert, click on the red icon and you will be
+ unassigned. A mail should be sent to the admin when this happens,
+ but in order for the accreditation request to be sent, you have to
+ mail live@eternal-terror.com with the template containing concert
+ information. There might be some exceptions, but those are discussed
+ case by case. So whenever you want a concert, assign yourself and send
+ the template no later than 3 weeks before the concert.
+
+
Admin will try to keep the concert status updated so that you know
+ what the accreditation status is. You will get personal message if this
+ is really close to the concert date.
+ $file
+ */
+ static function process_upload( array $file ): void {
+ $fo = new SplFileObject( $file['tmp_name'] );
+ $importerrors = array();
+ $rid = 0;
+
+ foreach ( $fo as $line ) {
+ $rid++;
+ $line = trim( $line );
+ if ( ! empty( $line ) ) {
+ try {
+ self::process_line( $line );
+ } catch ( Exception $e ) {
+ $importerrors[] = "Error importing line {$rid}: {$e->getMessage()}";
+ }
+ }
+ }
+
+ if ( ! empty( $importerrors ) ) {
+ echo implode( ' ', $importerrors );
+ } else {
+ echo ( 'All rows imported ok' );
+ }
+ }
+
+ static function process_line( string $line ) : void {
+ $resultArray = explode( "\t", $line );
+
+ // 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 ) {
+ throw new Exception( 'missing a field' );
+ }
+
+ if ( ! preg_match( '/\d{4}\-\d{2}-\d{2}/', $resultArray[3] ) ) {
+ throw new Exception( 'invalid date: ' . esc_html( $resultArray[3] ) );
+ }
+
+ if ( empty( trim( $resultArray[0] ) ) ) {
+ throw new Exception( 'missing concert name' );
+ }
+
+ if ( empty( trim( $resultArray[1] ) ) ) {
+ throw new Exception( 'missing venue' );
+ }
+
+ if ( empty( trim( $resultArray[2] ) ) ) {
+ throw new Exception( 'missing city' );
+ }
+
+ $condate = date( 'Y-m-d', strtotime( $resultArray[3] ) );
+
+ if ( $condate < date( 'Y-m-d' ) ) {
+ throw new Exception( 'has date in the past: ' . esc_html( $resultArray[3] ) );
+ }
+
+ $cname = trim( $resultArray[0] );
+ $venue = trim( $resultArray[1] );
+
+ if ( is_numeric( $venue ) ) {
+ $venue = GiglogAdmin_Venue::get( intval( $venue ) );
+ if ( ! $venue ) {
+ throw new Exception( "invalid venue id: {$venue}" );
+ }
+ } else {
+ $venue = GiglogAdmin_Venue::find_or_create( $venue, trim( $resultArray[2] ) );
+ }
+
+ $ticketlink = trim( $resultArray[4] );
+ $eventlink = trim( $resultArray[5] );
+
+ GiglogAdmin_Concert::create( $cname, $venue->id(), $condate, $ticketlink, $eventlink );
+ }
+ }
+}
diff --git a/includes/admin/views/giglog_admin_page.php b/includes/admin/views/giglog_admin_page.php
deleted file mode 100644
index acd0172..0000000
--- a/includes/admin/views/giglog_admin_page.php
+++ /dev/null
@@ -1,91 +0,0 @@
-
-// SPDX-FileCopyrightText: 2021 Harald Eilertsen
-//
-// SPDX-License-Identifier: AGPL-3.0-or-later
-
-if ( ! class_exists( 'GiglogAdmin_AdminPage' ) ) {
- require_once __DIR__ . '/../../class-giglogadmin-venue.php';
- require_once __DIR__ . '/_concerts_table.php';
- require_once __DIR__ . '/_edit_concert_form.php';
- require_once __DIR__ . '/_new_venue_form.php';
-
- class GiglogAdmin_AdminPage {
-
- const STATUS_LABELS = array(
- '',
- 'Accred Requested',
- 'Photo Approved',
- 'Text Approved',
- 'Photo and Text Approved',
- 'Rejected',
- );
-
- public static function render_html() : void {
- $page = new self();
- $page->render_page();
- }
-
- private function render_page() : void {
- $concerts = new GiglogAdmin_ConcertsTable();
- ?>
-
-
Giglog Admin
-
-
The available slots are marked with the green checkbox.
- If you click on it, it will be assigned to you and if you no longer
- wish to cover that concert, click on the red icon and you will be
- unassigned. A mail should be sent to the admin when this happens,
- but in order for the accreditation request to be sent, you have to
- mail live@eternal-terror.com with the template containing concert
- information. There might be some exceptions, but those are discussed
- case by case. So whenever you want a concert, assign yourself and send
- the template no later than 3 weeks before the concert.
-
-
Admin will try to keep the concert status updated so that you know
- what the accreditation status is. You will get personal message if this
- is really close to the concert date.