From 742ef8ee58b5b2dd59e17648f31f2f8ed9d4f3d0 Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Fri, 3 Sep 2021 09:14:56 +0200 Subject: emove dependency on ConcertLogs in gig import code. --- includes/admin/views/giglog_import_gigs.php | 2 -- 1 file changed, 2 deletions(-) (limited to 'includes/admin') diff --git a/includes/admin/views/giglog_import_gigs.php b/includes/admin/views/giglog_import_gigs.php index aeaf974..4bd59da 100644 --- a/includes/admin/views/giglog_import_gigs.php +++ b/includes/admin/views/giglog_import_gigs.php @@ -6,9 +6,7 @@ // SPDX-License-Identifier: AGPL-3.0-or-later if ( !class_exists( 'GiglogAdmin_ImportGigsPage' ) ) { - // require_once __DIR__ . '/../../band.php'; require_once __DIR__ . '/../../concert.php'; - require_once __DIR__ . '/../../concertlogs.php'; require_once __DIR__ . '/../../venue.php'; class GiglogAdmin_ImportGigsPage { -- cgit v1.2.3 From 74b06505888d69602b32d792ba4a815cd604ae41 Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Fri, 3 Sep 2021 09:15:46 +0200 Subject: Redo concert list to use the Concert class. Instead of directly accessing the database with a custom query, we now just use the Concert::find_concerts method to fetch the concerts that are to be displayed. This became much easier now that we don't rely on the extra concertlogs table. There's still stuff missing to be functionally equivalent to the old code, but this should be a lot easier to get in place now. --- includes/admin/views/giglog_admin_page.php | 70 ++++++++++++++---------------- 1 file changed, 32 insertions(+), 38 deletions(-) (limited to 'includes/admin') diff --git a/includes/admin/views/giglog_admin_page.php b/includes/admin/views/giglog_admin_page.php index 6c1f059..5a16b66 100644 --- a/includes/admin/views/giglog_admin_page.php +++ b/includes/admin/views/giglog_admin_page.php @@ -115,7 +115,7 @@ if ( !class_exists( 'GiglogAdmin_AdminPage' ) ) { if ($editing && !empty($cid)) //A bit overdoing with the checks if concert ID is empty both here and in find_cid. But based on that, things are NULL or not. Better ideas? $c = GiglogAdmin_Concert::get($cid); else - $c = new GiglogAdmin_Concert(); + $c = new GiglogAdmin_Concert((object)[]); $content='

Form to create/edit concerts and venues


'; $content.='
' @@ -204,63 +204,58 @@ if ( !class_exists( 'GiglogAdmin_AdminPage' ) ) { $content .= 'AdminOptions'; $content .= ''; + $filter = []; + // 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'; + if ($cty) $filter['city'] = $cty; $venue = filter_input( INPUT_POST, 'selectvenue', FILTER_SANITIZE_SPECIAL_CHARS ); - $venue = $venue ? $venue : '0'; + if ($venue) $filter['venue_id'] = $venue; + $concerts = GiglogAdmin_Concert::find_concerts($filter); - $query = "SELECT wpgc.id, wpgconcert_name, wpgv.wpgvenue_name as venue, wpgc.wpgconcert_date, wpgc.wpgconcert_tickets, wpgc.wpgconcert_event, wpgv.wpgvenue_city, wpgv.wpgvenue_webpage, wpgps.wpgs_name - FROM wpg_concerts wpgc, wpg_venues wpgv, wpg_pressstatus wpgps, wpg_concertlogs wpgcl - where wpgc.venue = wpgv.id - and wpgconcert_date >= CURDATE() - and wpgps.id = wpgcl.wpgcl_status - and wpgcl.wpgcl_concertid=wpgc.id"; - - $query .= ($cty == "ALL") ? "" : " and wpgv.wpgvenue_city='" .$cty ."'"; - $query .= ($venue == "0") ? "" : " and wpgv.id='" .$venue ."'"; - $query.= (empty($_POST['my_checkbox'])) ? "": " and (wpgcl_photo1 ='".$this->username."' or wpgcl_photo2 ='".$this->username."' or wpgcl_rev1 ='".$this->username."' or wpgcl_rev2 ='".$this->username."')"; - $query .=" order by wpgv.wpgvenue_city, wpgconcert_date, wpgc.id" ; - $results = $wpdb->get_results($query); $lastType = ''; - foreach ( $results AS $row ) { + foreach ( $concerts AS $concert ) { $content .= ''; - if($lastType != '' && $lastType != $row->wpgvenue_city) { - $content .= ''.$row->wpgvenue_city.''; + if ($lastType != '' && $lastType != $concert->venue()->city()) { + $content .= '' . $concert->city() . ''; } if ($lastType == '' ) { - $content .= ''.$row->wpgvenue_city.''; + $content .= '' . $concert->venue()->city() . ''; } // Modify these to match the database structure // $content .= '' . $row->id. ''; $content .= ''; - $content .= '' . $row->wpgconcert_name. ''; - $content .= '' . $row->venue. ''; - $fdate = strtotime($row->wpgconcert_date); + $content .= '' . $concert->cname() . ''; + $content .= '' . $concert->venue()->name() . ''; + $fdate = strtotime($concert->cdate()); $newformat = date('d.M.Y',$fdate); //$content .= DATE_FORMAT($fdate,'%d.%b.%Y'); - $content .= '' .$newformat. ''; - $content .= ''.$this->getpublishstatus($row->id ).''; - $content .= ''.$this->returnuser('photo1', $row->id ).''; - $content .= ''.$this->returnuser('photo2', $row->id ).''; - $content .= ''.$this->returnuser('rev1', $row->id ).''; - $content .= ''.$this->returnuser('rev2', $row->id ).''; - $content .= ''.$row -> wpgs_name.''; - - if (current_user_can('administrator')) { - $content .= - '' - . $this->adminactions($row->id) - . ''; - } + $content .= '' . $newformat . ''; + $content .= '' . /* $concert->isnew() */ '' . ''; + + $roles = $concert->roles(); + + $content .= '' . (array_key_exists('photo1', $roles) ? $roles['photo1'] : '') . ''; + $content .= '' . (array_key_exists('photo1', $roles) ? $roles['photo2'] : '') . ''; + $content .= '' . (array_key_exists('rev1', $roles) ? $roles['rev1'] : '') . ''; + $content .= '' . (array_key_exists('rev2', $roles) ? $roles['rev2'] : '') . ''; + + $content .= '' . $concert->status() . ''; + + // if (current_user_can('administrator')) { + // $content .= + // '' + // . $this->adminactions($row->id) + // . ''; + // } $content .= ''; - $lastType = $row->wpgvenue_city; + $lastType = $concert->venue()->city(); } $content .= ''; @@ -395,7 +390,6 @@ if ( !class_exists( 'GiglogAdmin_AdminPage' ) ) { return null; } - $cl = GiglogAdmin_Concertlogs::get($c); $role = $cl->get_assigned_role( $this->username ); $assigned_user = $cl->assigned_user( $p1 ); -- cgit v1.2.3 From ce7584bd6362d4eed9160c361498e624aede6a06 Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Fri, 3 Sep 2021 11:40:59 +0200 Subject: Render adminactions in concert list view. Clicking the buttons don't work quite yet. --- includes/admin/views/giglog_admin_page.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'includes/admin') diff --git a/includes/admin/views/giglog_admin_page.php b/includes/admin/views/giglog_admin_page.php index 5a16b66..3fe3237 100644 --- a/includes/admin/views/giglog_admin_page.php +++ b/includes/admin/views/giglog_admin_page.php @@ -150,7 +150,7 @@ if ( !class_exists( 'GiglogAdmin_AdminPage' ) ) { return $content; } - private function adminactions( int $concert_id ) : string + private function adminactions( GiglogAdmin_Concert $concert ) : string { global $wpdb; $query = "SELECT id,wpgs_name from wpg_pressstatus" ; @@ -158,11 +158,11 @@ if ( !class_exists( 'GiglogAdmin_AdminPage' ) ) { return '' - . '' + . '' . \EternalTerror\ViewHelpers\select_field( 'selectstatus', array_map(fn($status) => [ $status->id, $status->wpgs_name ], $statuses), - GiglogAdmin_Concertlogs::get_status($concert_id)) + $concert->status()) . '' . '' . ''; @@ -248,12 +248,12 @@ if ( !class_exists( 'GiglogAdmin_AdminPage' ) ) { $content .= '' . $concert->status() . ''; - // if (current_user_can('administrator')) { - // $content .= - // '' - // . $this->adminactions($row->id) - // . ''; - // } + if (current_user_can('administrator')) { + $content .= + '' + . $this->adminactions($concert) + . ''; + } $content .= ''; $lastType = $concert->venue()->city(); } -- cgit v1.2.3 From c09de43860ac6d57c6af31c971424e9c957e75c2 Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Fri, 3 Sep 2021 13:12:43 +0200 Subject: Drop query to press status table in adminactions. Replace the table with hardcoded strings in the AdminPage class. This makes it a pure presentation issue, while the statuses themselves are just mnemonics. There's one smell here, and that is that the status values and their textual representation is split across two modules. (Values in Concert, and textual representation in AdminPage.) This should probably be addressed later by refactoring both into a separate AccredStatus class or something. --- includes/admin/views/giglog_admin_page.php | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'includes/admin') diff --git a/includes/admin/views/giglog_admin_page.php b/includes/admin/views/giglog_admin_page.php index 3fe3237..7490122 100644 --- a/includes/admin/views/giglog_admin_page.php +++ b/includes/admin/views/giglog_admin_page.php @@ -11,6 +11,15 @@ if ( !class_exists( 'GiglogAdmin_AdminPage' ) ) { 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; @@ -152,16 +161,12 @@ if ( !class_exists( 'GiglogAdmin_AdminPage' ) ) { private function adminactions( GiglogAdmin_Concert $concert ) : string { - global $wpdb; - $query = "SELECT id,wpgs_name from wpg_pressstatus" ; - $statuses = $wpdb->get_results($query); - return '
' . '' . \EternalTerror\ViewHelpers\select_field( 'selectstatus', - array_map(fn($status) => [ $status->id, $status->wpgs_name ], $statuses), + array_map(fn($i) => [ $i, self::STATUS_LABELS[$i] ], range(1, count(self::STATUS_LABELS) - 1)), $concert->status()) . '' . '' @@ -246,7 +251,7 @@ if ( !class_exists( 'GiglogAdmin_AdminPage' ) ) { $content .= '' . (array_key_exists('rev1', $roles) ? $roles['rev1'] : '') . ''; $content .= '' . (array_key_exists('rev2', $roles) ? $roles['rev2'] : '') . ''; - $content .= '' . $concert->status() . ''; + $content .= '' . self::STATUS_LABELS[$concert->status()] . ''; if (current_user_can('administrator')) { $content .= -- cgit v1.2.3 From 2ca81303a9b892e179a790dc9e4ed14c08307610 Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Fri, 3 Sep 2021 14:37:37 +0200 Subject: Drop ref to ConcertLogs in AdminPage::get_user method. --- includes/admin/views/giglog_admin_page.php | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'includes/admin') diff --git a/includes/admin/views/giglog_admin_page.php b/includes/admin/views/giglog_admin_page.php index 7490122..0db72b2 100644 --- a/includes/admin/views/giglog_admin_page.php +++ b/includes/admin/views/giglog_admin_page.php @@ -68,16 +68,18 @@ if ( !class_exists( 'GiglogAdmin_AdminPage' ) ) { } - private function get_user( ?int $cid, string $ctype): string + private function get_user( GiglogAdmin_Concert $concert, string $role): string { $users = array_map( fn($usr) => $usr->user_login, get_users( array( 'fields' => array( 'user_login' ) ) ) ); - $current_user = $cid ? GiglogAdmin_Concertlogs::get_assigned_user( $cid, $ctype ) : null; + $roles = $concert->roles(); + + $current_user = array_key_exists($role, $roles) ? $roles[$role] : NULL; return \EternalTerror\ViewHelpers\select_field( - $ctype, + $role, array_map( fn($user) => [ $user, $user ], $users ), $current_user); } @@ -143,11 +145,12 @@ if ( !class_exists( 'GiglogAdmin_AdminPage' ) ) { $content.='

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

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

' -- cgit v1.2.3 From 60af9af46e4c80db1bd41d77991e2cf24ed69641 Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Fri, 3 Sep 2021 15:04:58 +0200 Subject: Rename AdminPage::get_user -> user_dropdown_for_role The original name did not make much sense. The function didn't return a user, but a dropdown list of users, where the user currently holding the given role for the given concert was preselected in the list. --- includes/admin/views/giglog_admin_page.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'includes/admin') diff --git a/includes/admin/views/giglog_admin_page.php b/includes/admin/views/giglog_admin_page.php index 0db72b2..248f175 100644 --- a/includes/admin/views/giglog_admin_page.php +++ b/includes/admin/views/giglog_admin_page.php @@ -68,7 +68,7 @@ if ( !class_exists( 'GiglogAdmin_AdminPage' ) ) { } - private function get_user( GiglogAdmin_Concert $concert, string $role): string + private function user_dropdown_for_role( GiglogAdmin_Concert $concert, string $role): string { $users = array_map( fn($usr) => $usr->user_login, @@ -147,10 +147,10 @@ if ( !class_exists( 'GiglogAdmin_AdminPage' ) ) { $content.='
'; $content.='
ASSIGNMENT DETAILS

' - .''.$this->get_user($c,'photo1').'
' - .''.$this->get_user($c,'photo2').'
' - .''.$this->get_user($c,'rev1').'
' - .''.$this->get_user($c,'rev2').'
'; + .''.$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

' -- cgit v1.2.3 From c9d80308ccb63a74f7dab723dd4e73a67b7fb597 Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Fri, 3 Sep 2021 15:07:40 +0200 Subject: Handle updating concert status again. --- includes/admin/views/giglog_admin_page.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'includes/admin') diff --git a/includes/admin/views/giglog_admin_page.php b/includes/admin/views/giglog_admin_page.php index 248f175..4cb7dad 100644 --- a/includes/admin/views/giglog_admin_page.php +++ b/includes/admin/views/giglog_admin_page.php @@ -305,13 +305,14 @@ if ( !class_exists( 'GiglogAdmin_AdminPage' ) ) { header("Refresh: 1; URL=$url3"); //reload page } - //handling the admin drop down menu - if(isset($_POST['selectstatus']) && (isset($_POST['edit']) && $_POST['edit']!="EDIT") && !empty($_POST['cid'])) + // handle the status drop down + if (isset($_POST['selectstatus']) && !empty($_POST['selectstatus']) && !empty($_POST['cid'])) { - $usql = "UPDATE wpg_concertlogs SET wpgcl_status=".$_POST['selectstatus']." WHERE wpgcl_concertid=".$_POST['cid']; - $uresults = $wpdb->get_results($usql); - //$url2=$_SERVER['REQUEST_URI']; //doesn't seem to be needed actually, leaving here just in case - //header("Refresh: 1; URL=$url2"); //reload page + 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'])) { -- cgit v1.2.3 From 74d39366640683914ab44db039ab48959c7dc91b Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Fri, 3 Sep 2021 19:32:28 +0200 Subject: Editing concerts now work again. --- includes/admin/views/giglog_admin_page.php | 32 ++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) (limited to 'includes/admin') diff --git a/includes/admin/views/giglog_admin_page.php b/includes/admin/views/giglog_admin_page.php index 4cb7dad..56376a8 100644 --- a/includes/admin/views/giglog_admin_page.php +++ b/includes/admin/views/giglog_admin_page.php @@ -331,15 +331,31 @@ if ( !class_exists( 'GiglogAdmin_AdminPage' ) ) { 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 ''; + $roles = array_reduce( + ['photo1', 'photo1', 'rev1', 'rev2'], + function($roles, $r) { + if (isset($_POST[$r])) { + $roles[$r] = sanitize_user($_POST[$r]); + } + return $roles; + }, + [] + ); + + $attributes = [ + 'wpgconcert_name' => sanitize_text_field($_POST['cname']), + 'venue' => intval($_POST['selectvenueadmin']), + 'wpgconcert_date' => sanitize_text_field($_POST['cdate']), + 'wpgconcert_ticket' => esc_url_raw($_POST['ticket']), + 'wpgconcert_event' => esc_url_raw($_POST['eventurl']), + 'wpgconcert_roles' => $roles, + ]; + + $concert = GiglogAdmin_Concert::get(intval($_POST['pid'])); + if ($concert->update((object) $attributes)) { + // let user know the concert was updated. + // Look into admin_notices } - } -- cgit v1.2.3 From c5e16119e6315ba1e05f85103206238898e50803 Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Sat, 4 Sep 2021 10:35:30 +0200 Subject: Make click to assign concert/role to self work again. --- includes/admin/views/giglog_admin_page.php | 54 ++++++++++++++---------------- 1 file changed, 25 insertions(+), 29 deletions(-) (limited to 'includes/admin') diff --git a/includes/admin/views/giglog_admin_page.php b/includes/admin/views/giglog_admin_page.php index 56376a8..dd21a32 100644 --- a/includes/admin/views/giglog_admin_page.php +++ b/includes/admin/views/giglog_admin_page.php @@ -249,10 +249,10 @@ if ( !class_exists( 'GiglogAdmin_AdminPage' ) ) { $roles = $concert->roles(); - $content .= '' . (array_key_exists('photo1', $roles) ? $roles['photo1'] : '') . ''; - $content .= '' . (array_key_exists('photo1', $roles) ? $roles['photo2'] : '') . ''; - $content .= '' . (array_key_exists('rev1', $roles) ? $roles['rev1'] : '') . ''; - $content .= '' . (array_key_exists('rev2', $roles) ? $roles['rev2'] : '') . ''; + $content .= '' . $this->returnuser('photo1', $concert) . ''; + $content .= '' . $this->returnuser('photo2', $concert) . ''; + $content .= '' . $this->returnuser('rev1', $concert) . ''; + $content .= '' . $this->returnuser('rev2', $concert) . ''; $content .= '' . self::STATUS_LABELS[$concert->status()] . ''; @@ -291,7 +291,12 @@ if ( !class_exists( 'GiglogAdmin_AdminPage' ) ) { if(isset($_POST['assignitem'])) { - GiglogAdmin_AdminPage::assignconcert($_POST['pid'],$_POST['cid']); + $concert = GiglogAdmin_Concert::get(intval($_POST['cid'])); + $role = sanitize_text_field($_POST['pid']); + + if ($concert) { + GiglogAdmin_AdminPage::assignconcert($role, $concert); + } $url2=$_SERVER['REQUEST_URI']; header("Refresh: 1; URL=$url2"); //reload page @@ -371,22 +376,17 @@ if ( !class_exists( 'GiglogAdmin_AdminPage' ) ) { } } - static function assignconcert($p1, $c): void + static function assignconcert($p1, GiglogAdmin_Concert $concert): void { - global $wpdb; + $username = wp_get_current_user()->user_login; + $concert->assign_role($p1, $username); + $concert->save(); $to = 'live@eternal-terror.com'; - $subject = $this->username.' has taken '.$p1. 'for a concert with id '.$c; + $subject = $username.' has taken '.$p1. 'for a concert with id '.$concert->id(); $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 ); } @@ -409,20 +409,16 @@ if ( !class_exists( 'GiglogAdmin_AdminPage' ) ) { wp_mail( $to, $subject, $body, $headers ); } - private function returnuser(string $p1, ?int $c) : ?string + private function returnuser(string $role, GiglogAdmin_Concert $concert) : ?string { - if (!$c) { - return null; - } - - $role = $cl->get_assigned_role( $this->username ); - $assigned_user = $cl->assigned_user( $p1 ); + $roles = $concert->roles(); + $assigned_user = array_key_exists($role, $roles) ? $roles[$role] : NULL; //first check if current slot is taken by current user - if ( $role == $p1 ) { + if ( $assigned_user == $this->username ) { $f = '' - . ' ' - . ' ' + . ' ' + . ' ' . ' ' . ''; } @@ -430,14 +426,14 @@ if ( !class_exists( 'GiglogAdmin_AdminPage' ) ) { $f = 'Taken' . '
Taken by ' . $assigned_user . '
'; } - elseif ( $role ) { + elseif ( array_search($this->username, $roles) ) { // other slots for this concert are taken by user $f = '-'; } else { //not taken by anyone $f = '
' - . ' ' - . ' ' + . ' ' + . ' ' . ' ' . '
'; } -- cgit v1.2.3 From 4f7cfd164d8200d586334fdc5d6eada2a219565e Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Sat, 4 Sep 2021 10:40:08 +0200 Subject: Rename AdminPage::returnuser to assign_role_for_user_form. It did not return any users, but a form so name it for what it does. --- includes/admin/views/giglog_admin_page.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'includes/admin') diff --git a/includes/admin/views/giglog_admin_page.php b/includes/admin/views/giglog_admin_page.php index dd21a32..7c77b2a 100644 --- a/includes/admin/views/giglog_admin_page.php +++ b/includes/admin/views/giglog_admin_page.php @@ -249,10 +249,10 @@ if ( !class_exists( 'GiglogAdmin_AdminPage' ) ) { $roles = $concert->roles(); - $content .= '' . $this->returnuser('photo1', $concert) . ''; - $content .= '' . $this->returnuser('photo2', $concert) . ''; - $content .= '' . $this->returnuser('rev1', $concert) . ''; - $content .= '' . $this->returnuser('rev2', $concert) . ''; + $content .= '' . $this->assign_role_for_user_form('photo1', $concert) . ''; + $content .= '' . $this->assign_role_for_user_form('photo2', $concert) . ''; + $content .= '' . $this->assign_role_for_user_form('rev1', $concert) . ''; + $content .= '' . $this->assign_role_for_user_form('rev2', $concert) . ''; $content .= '' . self::STATUS_LABELS[$concert->status()] . ''; @@ -409,7 +409,7 @@ if ( !class_exists( 'GiglogAdmin_AdminPage' ) ) { wp_mail( $to, $subject, $body, $headers ); } - private function returnuser(string $role, GiglogAdmin_Concert $concert) : ?string + 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; -- cgit v1.2.3 From f57acecbae89a2782acf6f6b539025385c198366 Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Sat, 4 Sep 2021 10:58:07 +0200 Subject: Make click to unassign from concert work again. As a user can only be assigned to one role at the time, we remove the current user from any role that they may have when clearing the assignment. --- includes/admin/views/giglog_admin_page.php | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) (limited to 'includes/admin') diff --git a/includes/admin/views/giglog_admin_page.php b/includes/admin/views/giglog_admin_page.php index 7c77b2a..0f8fe76 100644 --- a/includes/admin/views/giglog_admin_page.php +++ b/includes/admin/views/giglog_admin_page.php @@ -136,7 +136,7 @@ if ( !class_exists( 'GiglogAdmin_AdminPage' ) ) { .'' . $this->get_venue_selector($c->venue()) . '
' .'
' .'
' - .'
' + .'
' .''; // actions differ if we update or create a concert, hence two buttons needed if ($editing) @@ -304,7 +304,10 @@ if ( !class_exists( 'GiglogAdmin_AdminPage' ) ) { if(isset($_POST['unassignitem'])) { - GiglogAdmin_AdminPage::unassignconcert($_POST['pid'],$_POST['cid']); + $concert = GiglogAdmin_Concert::get(intval($_POST['cid'])); + $role = sanitize_text_field($_POST['pid']); + + GiglogAdmin_AdminPage::unassignconcert($role, $concert); $url3=$_SERVER['REQUEST_URI']; header("Refresh: 1; URL=$url3"); //reload page @@ -390,22 +393,17 @@ if ( !class_exists( 'GiglogAdmin_AdminPage' ) ) { wp_mail( $to, $subject, $body, $headers ); } - static function unassignconcert($p1, $c): void + static function unassignconcert($p1, GiglogAdmin_Concert $concert): void { - global $wpdb; + $username = wp_get_current_user()->user_login; + $concert->remove_user_from_roles($username); + $concert->save(); $to = 'live@eternal-terror.com'; - $subject = $this->username.' has UNASSINED '.$p1. 'for a concert with id '.$c; + $subject = $username.' has UNASSINED '.$p1. 'for a concert with id '.$concert->id(); $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 ); } @@ -417,8 +415,8 @@ if ( !class_exists( 'GiglogAdmin_AdminPage' ) ) { //first check if current slot is taken by current user if ( $assigned_user == $this->username ) { $f = '
' - . ' ' - . ' ' + . ' ' + . ' ' . ' ' . '
'; } -- cgit v1.2.3 From 64f4141378ea6fb524df015abdef5393d8d589bb Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Sat, 4 Sep 2021 14:47:03 +0200 Subject: Add timestamp columns to concerts and venues. To keep track of creation and modification times for each record. --- includes/admin/register_db_tables.php | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'includes/admin') diff --git a/includes/admin/register_db_tables.php b/includes/admin/register_db_tables.php index 64123d9..8c6dc98 100644 --- a/includes/admin/register_db_tables.php +++ b/includes/admin/register_db_tables.php @@ -260,7 +260,7 @@ if ( !function_exists( "giglog_register_db_tables") ) function giglog_register_db_tables() { $db_version = get_option('giglogadmin_db_version'); - if ($db_version == 6) { + if ($db_version == 8) { return; } @@ -459,7 +459,22 @@ if ( !function_exists( "giglog_register_db_tables") ) wpgconcert_roles JSON CHECK (JSON_VALID(wpgconcert_roles)))"); } - update_option("giglogadmin_db_version", 6); + if ($db_version == NULL || $db_version < 8) + { + // Add automatically updated `created` and `updated` colomns to keep + // track of creation time and modification times for a record. + $wpdb->query( + "ALTER TABLE `wpg_concerts` ADD COLUMN IF NOT ExISTS ( + created TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + updated TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP)"); + + $wpdb->query( + "ALTER TABLE `wpg_venues` ADD COLUMN IF NOT ExISTS ( + created TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + updated TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP)"); + } + + update_option("giglogadmin_db_version", 8); } giglog_register_db_tables(); -- cgit v1.2.3 From 57c9ed78112fb33f8a552e9b76d4fedac14f08d9 Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Sat, 4 Sep 2021 15:25:13 +0200 Subject: Mark recently added concerts as new again. --- includes/admin/views/giglog_admin_page.php | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) (limited to 'includes/admin') diff --git a/includes/admin/views/giglog_admin_page.php b/includes/admin/views/giglog_admin_page.php index 0f8fe76..447dcb2 100644 --- a/includes/admin/views/giglog_admin_page.php +++ b/includes/admin/views/giglog_admin_page.php @@ -180,27 +180,21 @@ if ( !class_exists( 'GiglogAdmin_AdminPage' ) ) { /** * @return null|string */ - private function getpublishstatus(int $concert_id) + private function getpublishstatus(GiglogAdmin_Concert $concert) : string { - 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"); + $now = new DateTime(); + $new_entry = $now->diff($concert->created())->days <= 10; + if ($new_entry) { + return 'NEW'; + } + else { + return ''; } - - if ($dd <= 10) return ('NEW'); } private function get_concerts(): string { - global $wpdb; - $content = ''; // $content .= ''; @@ -245,9 +239,7 @@ if ( !class_exists( 'GiglogAdmin_AdminPage' ) ) { //$content .= DATE_FORMAT($fdate,'%d.%b.%Y'); $content .= ''; - $content .= ''; - - $roles = $concert->roles(); + $content .= ''; $content .= ''; $content .= ''; -- cgit v1.2.3 From 2b54c76bec008bed8b910183cf4e98795c7a446a Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Sat, 4 Sep 2021 16:07:48 +0200 Subject: Remove dangling $wpdb ref in AdminPage. AdminPage now references the database only through the Concert (and Venue) models. --- includes/admin/views/giglog_admin_page.php | 2 -- 1 file changed, 2 deletions(-) (limited to 'includes/admin') diff --git a/includes/admin/views/giglog_admin_page.php b/includes/admin/views/giglog_admin_page.php index 447dcb2..dfea3fd 100644 --- a/includes/admin/views/giglog_admin_page.php +++ b/includes/admin/views/giglog_admin_page.php @@ -269,8 +269,6 @@ if ( !class_exists( 'GiglogAdmin_AdminPage' ) ) { */ static function update() { - global $wpdb; - if ('POST' !== $_SERVER['REQUEST_METHOD']) return; -- cgit v1.2.3 From f9f97dc3eae4980d63ce78ccc56b73aeab28af84 Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Sat, 4 Sep 2021 16:22:44 +0200 Subject: Drop obsolete database tables. These tables are no longer being used, so let's remove them and the code to add them. --- includes/admin/register_db_tables.php | 103 ++-------------------------------- 1 file changed, 6 insertions(+), 97 deletions(-) (limited to 'includes/admin') diff --git a/includes/admin/register_db_tables.php b/includes/admin/register_db_tables.php index 8c6dc98..8080578 100644 --- a/includes/admin/register_db_tables.php +++ b/includes/admin/register_db_tables.php @@ -259,35 +259,17 @@ if ( !function_exists( "giglog_register_db_tables") ) */ function giglog_register_db_tables() { + global $wpdb; + + // Clean out obsolete tables if they exist. + $wpdb->query("DROP TABLE IF EXISTS " + . "wpg_bands, wpg_concertlogs, wpg_files, wpg_logchanges, wpg_pressstatus"); + $db_version = get_option('giglogadmin_db_version'); if ($db_version == 8) { return; } - $bands_table = - "CREATE TABLE IF NOT EXISTS `wpg_bands` ( - `id` int(11) NOT NULL AUTO_INCREMENT, - `wpgband_name` varchar(500) NOT NULL, - `wpgband_country` varchar(4) DEFAULT 'NO', - PRIMARY KEY (`id`), - KEY `wpgband_country` (`wpgband_country`) - ) ENGINE=InnoDB DEFAULT CHARSET=utf8;"; - - $concertlogs_table = - "CREATE TABLE IF NOT EXISTS `wpg_concertlogs` ( - `id` int(11) NOT NULL AUTO_INCREMENT, - `wpgcl_concertid` int(11) NOT NULL, - `wpgcl_photo1` varchar(200) DEFAULT NULL, - `wpgcl_photo2` varchar(200) DEFAULT NULL, - `wpgcl_rev1` varchar(200) DEFAULT NULL, - `wpgcl_rev2` varchar(200) DEFAULT NULL, - `wpgcl_int` varchar(200) DEFAULT NULL, - `wpgcl_status` int(11) DEFAULT 1, - PRIMARY KEY (`id`), - KEY `wpglog_status` (`wpgcl_status`), - KEY `wpglog_concerts` (`wpgcl_concertid`) - ) ENGINE=InnoDB DEFAULT CHARSET=utf8;"; - $concerts_table = "CREATE TABLE IF NOT EXISTS `wpg_concerts` ( `id` int(11) NOT NULL AUTO_INCREMENT, @@ -311,35 +293,6 @@ if ( !function_exists( "giglog_register_db_tables") ) PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;"; - $files_table = - "CREATE TABLE IF NOT EXISTS `wpg_files` ( - `id` int(11) NOT NULL AUTO_INCREMENT, - `filename` varchar(2000) NOT NULL, - `filedate` datetime NOT NULL DEFAULT current_timestamp(), - `rowid` int(11) NOT NULL, - `rowcontent` text NOT NULL, - `processed` char(1) NOT NULL DEFAULT 'N', - `wpgc_id` int(11) NOT NULL, - PRIMARY KEY (`id`) - ) ENGINE=InnoDB DEFAULT CHARSET=utf8;"; - - $logchanges_table = - "CREATE TABLE IF NOT EXISTS `wpg_logchanges` ( - `id` int(11) NOT NULL AUTO_INCREMENT, - `userid` varchar(500) NOT NULL, - `action` varchar(500) NOT NULL, - `actiondate` date NOT NULL DEFAULT current_timestamp(), - `concertid` int(11) NOT NULL, - PRIMARY KEY (`id`) - ) ENGINE=InnoDB DEFAULT CHARSET=utf8;"; - - $pressstatus_table = - "CREATE TABLE IF NOT EXISTS `wpg_pressstatus` ( - `id` int(11) NOT NULL AUTO_INCREMENT, - `wpgs_name` varchar(50) NOT NULL, - PRIMARY KEY (`id`) - ) ENGINE=InnoDB DEFAULT CHARSET=utf8;"; - $venues_table = "CREATE TABLE IF NOT EXISTS `wpg_venues` ( `id` int(11) NOT NULL AUTO_INCREMENT, @@ -350,15 +303,9 @@ if ( !function_exists( "giglog_register_db_tables") ) PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;"; - global $wpdb; $tables = array( - $bands_table, - $concertlogs_table, $concerts_table, $countries_table, - $files_table, - $logchanges_table, - $pressstatus_table, $venues_table); foreach($tables as $tabledef) { @@ -377,51 +324,13 @@ if ( !function_exists( "giglog_register_db_tables") ) ADD FULLTEXT KEY `id` (`id`,`wpgc_fullname`,`wpgcountry_name`,`wpgc_iso3`,`wpgc_numcode`);"); - $wpdb->query( - "ALTER TABLE `wpg_bands` - ADD CONSTRAINT `wpgband_country` - FOREIGN KEY (`wpgband_country`) - REFERENCES `wpg_countries` (`id`) ON DELETE NO ACTION;"); - - $wpdb->query( - "ALTER TABLE `wpg_concertlogs` - ADD CONSTRAINT `wpglog_concerts` - FOREIGN KEY (`wpgcl_concertid`) - REFERENCES `wpg_concerts` (`id`) ON DELETE CASCADE ON UPDATE NO ACTION, - ADD CONSTRAINT `wpglog_status` - FOREIGN KEY (`wpgcl_status`) - REFERENCES `wpg_pressstatus` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION;"); - $wpdb->query( "ALTER TABLE `wpg_concerts` - ADD CONSTRAINT `wpgconcert_band` - FOREIGN KEY (`band`) - REFERENCES `wpg_bands` (`id`) ON DELETE NO ACTION, ADD CONSTRAINT `wpgconcert_venue` FOREIGN KEY (`venue`) REFERENCES `wpg_venues` (`id`) ON DELETE NO ACTION;"); } - if ($db_version == NULL || $db_version < 2) - { - $wpdb->query( - "INSERT INTO `wpg_pressstatus` (`id`, `wpgs_name`) VALUES - (1, ' '), - (2, 'Accred Requested'), - (3, 'Photo Approved'), - (4, 'Text Approved'), - (5, 'Photo and Text approved'), - (6, 'Rejected');"); - } - - if ($db_version == NULL || $db_version < 3) - { - $wpdb->query( - "ALTER TABLE `wpg_concertlogs` - ADD COLUMN IF NOT EXISTS - `wpgcl_createddate` date NOT NULL DEFAULT current_timestamp();"); - } - if ($db_version == NULL || $db_version < 4) { $wpdb->query( -- cgit v1.2.3
CITYIDBANDVENUEDATE
' . $newformat . '' . /* $concert->isnew() */ '' . '' . $this->getpublishstatus($concert) . '' . $this->assign_role_for_user_form('photo1', $concert) . '' . $this->assign_role_for_user_form('photo2', $concert) . '