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 +++++++++++++--------------- includes/concert.php | 5 +++++ 2 files changed, 18 insertions(+), 15 deletions(-) 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 = '
' - . ' ' - . ' ' + . ' ' + . ' ' . ' ' . '
'; } diff --git a/includes/concert.php b/includes/concert.php index f0c69c8..dce15f0 100644 --- a/includes/concert.php +++ b/includes/concert.php @@ -299,6 +299,11 @@ if ( !class_exists('GiglogAdmin_Concert') ) { { $this->roles[$role] = $username; } + + public function remove_user_from_roles( string $username ) : void + { + $this->roles = array_filter($this->roles, fn($u) => $u != $username); + } } } ?> -- cgit v1.2.3