// SPDX-FileCopyrightText: 2021 Harald Eilertsen // // SPDX-License-Identifier: AGPL-3.0-or-later if ( !class_exists( 'GiglogAdmin_AdminPage' ) ) { require_once __DIR__ . '/../../venue.php'; class GiglogAdmin_AdminPage { private string $username; const STATUS_LABELS = [ '', 'Accred Requested', 'Photo Approved', 'Text Approved', 'Photo and Text Approved', 'Rejected' ]; public function __construct() { $this->username = wp_get_current_user()->user_login; } public static function render_html() : void { $page = new self(); $page->render_page(); } public function render_page() : void { ?>

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.

get_filters() ?>

get_concerts() ?>

[$venue->id(), $venue->name()], GiglogAdmin_Venue::all_venues()), $invenue ? $invenue->id() : null); } private function user_dropdown_for_role( GiglogAdmin_Concert $concert, string $role): string { $users = array_map( fn($usr) => $usr->user_login, get_users( array( 'fields' => array( 'user_login' ) ) ) ); $roles = $concert->roles(); $current_user = array_key_exists($role, $roles) ? $roles[$role] : NULL; return \EternalTerror\ViewHelpers\select_field( $role, array_map( fn($user) => [ $user, $user ], $users ), $current_user); } private function get_filters() : string { $cty = filter_input(INPUT_POST, 'selectcity', FILTER_SANITIZE_SPECIAL_CHARS); $select = '
FILTER DATA:'; $select .= \EternalTerror\ViewHelpers\select_field( "selectcity", 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( "selectvenue", array_map( fn($venue) => [$venue->id(), $venue->name()], GiglogAdmin_Venue::venues_in_city($cty) ), filter_input(INPUT_POST, 'selectvenue', FILTER_SANITIZE_SPECIAL_CHARS), "Select venue..."); } //option to select own concerts only $select .= 'CONCERT DETAILS

' .'' .'
' .'' . $this->get_venue_selector($c->venue()) . '
' .'
' .'
' .'
' .'
'; // actions differ if we update or create a concert, hence two buttons needed if ($editing) $content.='

'; else $content.='

'; $content.=''; $content.='
ASSIGNMENT DETAILS

' .''.$this->user_dropdown_for_role($c,'photo1').'
' .''.$this->user_dropdown_for_role($c,'photo2').'
' .''.$this->user_dropdown_for_role($c,'rev1').'
' .''.$this->user_dropdown_for_role($c,'rev2').'
'; $content.='
'; $content.='
VENUE DETAILS

' .'

' .'
' .'

' .'
'; $content.=''; return $content; } private function adminactions( GiglogAdmin_Concert $concert ) : string { return '
' . '' . \EternalTerror\ViewHelpers\select_field( 'selectstatus', array_map(fn($i) => [ $i, self::STATUS_LABELS[$i] ], range(1, count(self::STATUS_LABELS) - 1)), $concert->status()) . '' . '' . '
'; } //function to calculate if the concert has been added in the past 10 days or before that and show a green NEW for the newest rows /** * @return null|string */ private function getpublishstatus(int $concert_id) { global $wpdb; $date1 = new DateTime("now"); $dsql = "select wpgcl_createddate from wpg_concertlogs where wpgcl_concertid=".$concert_id; $results = $wpdb->get_results($dsql); foreach ( $results AS $row ) { //$x = strtotime($row -> filedate); $x= date('Y-m-d H:i:s', strtotime($row -> wpgcl_createddate)); $date2 = new DateTime($x, new DateTimeZone('Europe/London')); $dd = $date2 -> diff($date1) ->format("%a"); } if ($dd <= 10) return ('NEW'); } private function get_concerts(): string { global $wpdb; $content = ''; // $content .= ''; $content .= ''; if (current_user_can('administrator')) $content .= ''; $content .= ''; $filter = []; // Use the submitted "city" if any. Otherwise, use the default/static value. $cty = filter_input( INPUT_POST, 'selectcity', FILTER_SANITIZE_SPECIAL_CHARS ); if ($cty) $filter['city'] = $cty; $venue = filter_input( INPUT_POST, 'selectvenue', FILTER_SANITIZE_SPECIAL_CHARS ); if ($venue) $filter['venue_id'] = $venue; $concerts = GiglogAdmin_Concert::find_concerts($filter); $lastType = ''; foreach ( $concerts AS $concert ) { $content .= ''; if ($lastType != '' && $lastType != $concert->venue()->city()) { $content .= ''; } if ($lastType == '' ) { $content .= ''; } // Modify these to match the database structure // $content .= ''; $content .= ''; $content .= ''; $content .= ''; $fdate = strtotime($concert->cdate()); $newformat = date('d.M.Y',$fdate); //$content .= DATE_FORMAT($fdate,'%d.%b.%Y'); $content .= ''; $content .= ''; $roles = $concert->roles(); $content .= ''; $content .= ''; $content .= ''; $content .= ''; $content .= ''; if (current_user_can('administrator')) { $content .= ''; } $content .= ''; $lastType = $concert->venue()->city(); } $content .= '
CITYIDBANDVENUEDATE
CITYNAMEVENUEDATE PHOTO1PHOTO2TEXT1TEXT2 STATUSAdminOptions
' . $concert->city() . '
' . $concert->venue()->city() . '
' . $row->id. '' . $concert->cname() . '' . $concert->venue()->name() . '' . $newformat . '' . /* $concert->isnew() */ '' . '' . (array_key_exists('photo1', $roles) ? $roles['photo1'] : '') . '' . (array_key_exists('photo1', $roles) ? $roles['photo2'] : '') . '' . (array_key_exists('rev1', $roles) ? $roles['rev1'] : '') . '' . (array_key_exists('rev2', $roles) ? $roles['rev2'] : '') . '' . self::STATUS_LABELS[$concert->status()] . '' . $this->adminactions($concert) . '
'; // return the table return $content; } /** * @return void */ static function update() { global $wpdb; if ('POST' !== $_SERVER['REQUEST_METHOD']) return; // Use the submitted "city" if any. Otherwise, use the default/static value. $cty = filter_input( INPUT_POST, 'selectcity', FILTER_SANITIZE_SPECIAL_CHARS ); $cty = $cty ? $cty: 'ALL'; $venue = filter_input( INPUT_POST, 'selectvenue', FILTER_SANITIZE_SPECIAL_CHARS ); $venue = $venue ? $venue : '0'; if(isset($_POST['assignitem'])) { GiglogAdmin_AdminPage::assignconcert($_POST['pid'],$_POST['cid']); $url2=$_SERVER['REQUEST_URI']; header("Refresh: 1; URL=$url2"); //reload page } if(isset($_POST['unassignitem'])) { GiglogAdmin_AdminPage::unassignconcert($_POST['pid'],$_POST['cid']); $url3=$_SERVER['REQUEST_URI']; header("Refresh: 1; URL=$url3"); //reload page } // 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'])); $concert->set_status(intval($_POST['selectstatus'])); $concert->save(); } } if(isset($_POST['newconcert'])) { if (empty($_POST['cname']) || empty($_POST['selectvenueadmin']) || empty($_POST['cdate']) || empty($_POST['ticket']) || empty($_POST['eventurl'])) { echo ''; } else { if (GiglogAdmin_Concert::create($_POST['cname'], $_POST['selectvenueadmin'], $_POST['cdate'], $_POST['ticket'], $_POST['eventurl'])) { echo ''; } else { echo ''; } } } if(isset($_POST['editconcert'])) { IF (empty($_POST['cname']) || empty($_POST['selectvenueadmin']) || empty($_POST['cdate']) || empty($_POST['ticket']) || empty($_POST['eventurl'])) echo ''; else { GiglogAdmin_Concert::update_concert($_POST['pid'],$_POST['cname'], $_POST['selectvenueadmin'], $_POST['cdate'], $_POST['ticket'], $_POST['eventurl']); GiglogAdmin_Concertlogs::update($_POST['pid'],$_POST['photo1'], $_POST['photo2'], $_POST['rev1'], $_POST['rev2']); echo ''; } } if(isset($_POST['newvenue'])) { IF (empty($_POST['venuename']) || empty($_POST['venuecity'])) echo ''; else { GiglogAdmin_Venue::create($_POST['venuename'],$_POST['venuecity']); echo ''; } } } static function assignconcert($p1, $c): void { global $wpdb; $to = 'live@eternal-terror.com'; $subject = $this->username.' has taken '.$p1. 'for a concert with id '.$c; $body = 'The email body content'; $headers = array('Content-Type: text/html; charset=UTF-8'); $usql = "UPDATE wpg_concertlogs SET wpgcl_".$p1."='".$this->username."' WHERE wpgcl_concertid=".$c; $uresults = $wpdb->get_results($usql); $wpdb->insert( 'wpg_logchanges', array ( 'id' => '', 'userid' => $this->username, 'action' => 'assigned '.$p1, 'concertid' => $c)); echo ($wpdb->last_error ); wp_mail( $to, $subject, $body, $headers ); } static function unassignconcert($p1, $c): void { global $wpdb; $to = 'live@eternal-terror.com'; $subject = $this->username.' has UNASSINED '.$p1. 'for a concert with id '.$c; $body = 'The email body content'; $headers = array('Content-Type: text/html; charset=UTF-8'); $usql = "UPDATE wpg_concertlogs SET wpgcl_".$p1."='' WHERE wpgcl_concertid=".$c; $uresults = $wpdb->get_results($usql); $wpdb->insert( 'wpg_logchanges', array ( 'id' => '', 'userid' => $this->username, 'action' => 'unassigned '.$p1, 'concertid' => $c)); echo ($wpdb->last_error ); wp_mail( $to, $subject, $body, $headers ); } private function returnuser(string $p1, ?int $c) : ?string { if (!$c) { return null; } $role = $cl->get_assigned_role( $this->username ); $assigned_user = $cl->assigned_user( $p1 ); //first check if current slot is taken by current user if ( $role == $p1 ) { $f = '
' . ' ' . ' ' . ' ' . '
'; } elseif ( $assigned_user ) { //check if slot is taken by another user $f = 'Taken' . '
Taken by ' . $assigned_user . '
'; } elseif ( $role ) { // other slots for this concert are taken by user $f = '-'; } else { //not taken by anyone $f = '
' . ' ' . ' ' . ' ' . '
'; } return $f; } } } ?>