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/views/giglog_admin_page.php') 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