summaryrefslogtreecommitdiffstats
path: root/includes
diff options
context:
space:
mode:
authorHarald Eilertsen <haraldei@anduin.net>2021-09-04 10:58:07 +0200
committerHarald Eilertsen <haraldei@anduin.net>2021-09-04 10:58:07 +0200
commitf57acecbae89a2782acf6f6b539025385c198366 (patch)
tree3ef5130f4229d248d55e44aa0caa8bb1ab1dc6cd /includes
parent4f7cfd164d8200d586334fdc5d6eada2a219565e (diff)
downloadgigologadmin-f57acecbae89a2782acf6f6b539025385c198366.tar.gz
gigologadmin-f57acecbae89a2782acf6f6b539025385c198366.tar.bz2
gigologadmin-f57acecbae89a2782acf6f6b539025385c198366.zip
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.
Diffstat (limited to 'includes')
-rw-r--r--includes/admin/views/giglog_admin_page.php28
-rw-r--r--includes/concert.php5
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' ) ) {
.'<label for="venue">Venue:</label>' . $this->get_venue_selector($c->venue()) . '<br>'
.'<label for="cdate">Date:</label><input type="date" id="cdate" name="cdate" value="'.$c->cdate().'"><br>'
.'<label for="ticket">Tickets:</label><input type="text" id="ticket" name="ticket" value="'.$c->tickets().'"><br>'
- .'<label for="eventurl">Event link:</label><input type="text" id="eventurl" name="eventurl" value="'.$c->eventlink().'"><br>'
+ .'<label for="eventurl">Event link:</label><input type="text" id="eventurl" name="eventurl" value="'.$c->eventlink().'"><br>'
.'</fieldset>';
// 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 = '<form class="unassignit" method="POST" action="">'
- . ' <input type="hidden" name="cid" value="{$cconcert->id()}" />'
- . ' <input type="hidden" name="pid" value="{$role}" />'
+ . ' <input type="hidden" name="cid" value="' . $concert->id() . '" />'
+ . ' <input type="hidden" name="pid" value="' . $role . '" />'
. ' <input type="submit" name="unassignitem" value="Your"/>'
. '</form>';
}
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);
+ }
}
}
?>