From 1c4207622ee0deb83aa759206fe56739b1c19918 Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Mon, 5 Apr 2021 09:24:22 +0200 Subject: Make concert table buttons work. Moved processing of POST requests to it's own method, and added a visual clue that a slot has been selected. Also moved relevant code into the AdminPage class. --- giglogadmin.php | 2 + includes/admin/views/giglog_admin_page.php | 168 +++++++++++++++++++++++++++-- 2 files changed, 161 insertions(+), 9 deletions(-) diff --git a/giglogadmin.php b/giglogadmin.php index d610fe8..8c040aa 100644 --- a/giglogadmin.php +++ b/giglogadmin.php @@ -65,6 +65,8 @@ if ( !class_exists( 'GiglogAdmin_Plugin' ) ) { 'dashicons-tickets-alt', // Icon url 11); // Position, just below 'Media' + add_action( 'load-' . $top, array( 'GiglogAdmin_AdminPage', 'update' ) ); + $import_hook = add_submenu_page( "giglog", // parent slug "Import gigs", // page title diff --git a/includes/admin/views/giglog_admin_page.php b/includes/admin/views/giglog_admin_page.php index 0f8df53..47075fb 100644 --- a/includes/admin/views/giglog_admin_page.php +++ b/includes/admin/views/giglog_admin_page.php @@ -142,10 +142,10 @@ if ( !class_exists( 'GiglogAdmin_AdminPage' ) ) { //$content .= DATE_FORMAT($fdate,'%d.%b.%Y'); $content .= '' .$newformat. ''; $content .= ''; //.giglogadmin_getpublishstatus($row->id ).''; - $content .= ''.giglogadmin_returnuser('photo1', $row->id ).''; - $content .= ''.giglogadmin_returnuser('photo2', $row->id ).''; - $content .= ''.giglogadmin_returnuser('rev1', $row->id ).''; - $content .= ''.giglogadmin_returnuser('rev2', $row->id ).''; + $content .= ''.GiglogAdmin_AdminPage::returnuser('photo1', $row->id ).''; + $content .= ''.GiglogAdmin_AdminPage::returnuser('photo2', $row->id ).''; + $content .= ''.GiglogAdmin_AdminPage::returnuser('rev1', $row->id ).''; + $content .= ''.GiglogAdmin_AdminPage::returnuser('rev2', $row->id ).''; $content .= ''.$row -> wpgs_name; if (current_user_can('administrator')) //($hf_username == 'etadmin') $content .= '
@@ -156,9 +156,26 @@ if ( !class_exists( 'GiglogAdmin_AdminPage' ) ) { } $content .= ''; + + // return the table + return $content; + } + + static function update() + { + 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'])) { - echo (giglogadmin_assignconcert($_POST['pid'],$_POST['cid'])); + GiglogAdmin_AdminPage::assignconcert($_POST['pid'],$_POST['cid']); $url2=$_SERVER['REQUEST_URI']; header("Refresh: 1; URL=$url2"); //reload page @@ -166,7 +183,7 @@ if ( !class_exists( 'GiglogAdmin_AdminPage' ) ) { if(isset($_POST['unassignitem'])) { - echo (giglogadmin_unassignconcert($_POST['pid'],$_POST['cid'])); + GiglogAdmin_AdminPage::unassignconcert($_POST['pid'],$_POST['cid']); $url3=$_SERVER['REQUEST_URI']; header("Refresh: 1; URL=$url3"); //reload page @@ -174,7 +191,7 @@ if ( !class_exists( 'GiglogAdmin_AdminPage' ) ) { if(isset($_POST['reqsent'])) { - echo (giglogadmin_assignconcert($_POST['pid'],$_POST['cid'])); + GiglogAdmin_AdminPage::assignconcert($_POST['pid'],$_POST['cid']); $usql = "UPDATE wpg_concertlogs SET wpgcl_status=2 WHERE wpgcl_concertid=".$_POST['cid']; $uresults = $wpdb->get_results($usql); $url2=$_SERVER['REQUEST_URI']; @@ -216,9 +233,142 @@ if ( !class_exists( 'GiglogAdmin_AdminPage' ) ) { $url2=$_SERVER['REQUEST_URI']; header("Refresh: 1; URL=$url2"); //reload page } + } + + static function assignconcert($p1, $c) + { + global $wpdb; + + $hf_user = wp_get_current_user(); + $hf_username = $hf_user->user_login; + $to = 'live@eternal-terror.com'; + $subject = $hf_username.' has taken '.$p1. 'for a concert with id '.$c; + $body = 'The email body content'; + $headers = array('Content-Type: text/html; charset=UTF-8'); + + + + if ($p1 == 'photo1') $usql = "UPDATE wpg_concertlogs SET wpgcl_photo1='".$hf_username."' WHERE wpgcl_concertid=".$c; + if ($p1 == 'photo2') $usql = "UPDATE wpg_concertlogs SET wpgcl_photo2='".$hf_username."' WHERE wpgcl_concertid=".$c; + if ($p1 == 'rev1') $usql = "UPDATE wpg_concertlogs SET wpgcl_rev1='".$hf_username."' WHERE wpgcl_concertid=".$c; + if ($p1 == 'rev2') $usql = "UPDATE wpg_concertlogs SET wpgcl_rev2='".$hf_username."' WHERE wpgcl_concertid=".$c; + + $uresults = $wpdb->get_results($usql); + $wpdb->insert( 'wpg_logchanges', array ( + 'id' => '', + 'userid' => $hf_username, + 'action' => 'assigned '.$p1, + 'concertid' => $c)); + echo ($wpdb->last_error ); + wp_mail( $to, $subject, $body, $headers ); + + + } + + static function unassignconcert($p1, $c) + { + global $wpdb; + + $hf_user = wp_get_current_user(); + $hf_username = $hf_user->user_login; + $to = 'live@eternal-terror.com'; + $subject = $hf_username.' has UNASSINED '.$p1. 'for a concert with id '.$c; + $body = 'The email body content'; + $headers = array('Content-Type: text/html; charset=UTF-8'); + + + + if ($p1 == 'photo1') $usql = "UPDATE wpg_concertlogs SET wpgcl_photo1='' WHERE wpgcl_concertid=".$c; + if ($p1 == 'photo2') $usql = "UPDATE wpg_concertlogs SET wpgcl_photo2='' WHERE wpgcl_concertid=".$c; + if ($p1 == 'rev1') $usql = "UPDATE wpg_concertlogs SET wpgcl_rev1='' WHERE wpgcl_concertid=".$c; + if ($p1 == 'rev2') $usql = "UPDATE wpg_concertlogs SET wpgcl_rev2='' WHERE wpgcl_concertid=".$c; + + + $uresults = $wpdb->get_results($usql); + $wpdb->insert( 'wpg_logchanges', array ( + 'id' => '', + 'userid' => $hf_username, + 'action' => 'unassigned '.$p1, + 'concertid' => $c)); + echo ($wpdb->last_error ); + wp_mail( $to, $subject, $body, $headers ); + + + } + + static function returnuser($p1, $c) + { + global $wpdb; + $hf_user = wp_get_current_user(); + $hf_username = $hf_user->user_login; + + //PHOTO1 + if ($p1 == 'photo1') + { + //checking if taken + $vquery0 = "select wpgcl_photo1 from wpg_concertlogs where wpgcl_concertid=".$c ; + $results = $wpdb->get_results($vquery0); + foreach ( $results AS $row ) $x= $row -> wpgcl_photo1; + if ($x !='' and $x!=$hf_username) { return ('Taken by '.$x); } + else + if ($x==$hf_username) //if current user + return (' +
'); + else //not taken by anyone + return ('
+
'); + } + //PHOTO2 + if ($p1 == 'photo2') + { + $vquery0 = "select wpgcl_photo2 from wpg_concertlogs where wpgcl_concertid=".$c ; + $results = $wpdb->get_results($vquery0); + foreach ( $results AS $row ) $x= $row -> wpgcl_photo2; + if ($x !='' and $x!=$hf_username) { return ('Taken by '.$x); } + else + if ($x==$hf_username) //if current user + return ('
+
'); + + else //not taken by anyone + return ('
+
'); + + } + //TEXT1 + if ($p1 == 'rev1') + { + $vquery0 = "select wpgcl_rev1 from wpg_concertlogs where wpgcl_concertid=".$c ; + $results = $wpdb->get_results($vquery0); + foreach ( $results AS $row ) $x= $row -> wpgcl_rev1; + if ($x !='' and $x!=$hf_username) { return ('Taken by '.$x); } + else + if ($x==$hf_username) //if current user + return ('
+
'); + else //not taken by anyone + return ('
+
'); + + } + //TEXT2 + if ($p1 == 'rev2') + { + $vquery0 = "select wpgcl_rev2 from wpg_concertlogs where wpgcl_concertid=".$c ; + $results = $wpdb->get_results($vquery0); + foreach ( $results AS $row ) $x= $row -> wpgcl_rev2; + if ($x !='' and $x!=$hf_username) { return ('Taken by '.$x); } + else + if ($x==$hf_username) //if current user + return ('
+
'); + else //not taken by anyone + return ('
+
'); + + } + - // return the table - return $content; } } } -- cgit v1.2.3