From: Chuck Scott Date: Tue, 21 Nov 2017 20:57:20 +0000 (-0500) Subject: Added reg event delete capability. X-Git-Tag: v1.0.0^2~248 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=ef148774542e04911965e87b3f61710c70cd32bb;p=WP-Plugins%2Fglm-member-db-registrations.git Added reg event delete capability. Added reg event delete capability to events.php Added delete button and confirmation dialog to eventDashboard.html Added getEventRegistrantCounts() to dataRegEvent.php Added deleteRegEvent() to dataRegEvent.php --- diff --git a/classes/data/dataRegEvent.php b/classes/data/dataRegEvent.php index 6955b14..458ff47 100644 --- a/classes/data/dataRegEvent.php +++ b/classes/data/dataRegEvent.php @@ -402,25 +402,136 @@ class GlmDataRegistrationsRegEvent extends GlmDataAbstract } + // If we're asked to get registrant counts if ($this->postProcAddRegistrantsCount) { - // Get sum of all attendee counts - $counts = $this->wpdb->get_row(" + $counts = $this->getEventRegistrantCounts($result_data['id']); + + // If we have counts, add them to the result + if ($counts && is_array($counts)) { + $result_data = array_merge($result_data, $counts); + } + + } + + return $result_data; + } + + /* + * Get registrant count summary for an event + * + * @param integer $eventId ID of the reg_event record + * + * @return array Summary array of event counts + * + */ + public function getEventRegistrantCounts($eventId = false) + { + + // Get sum of all attendee counts + $countsData = $this->wpdb->get_row(" SELECT SUM(attendee_max) AS total, SUM(attendee_count) AS registered, SUM(attendees_pending) AS cartHold, SUM(attendees_available) AS curAvail FROM ".GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX."reg_time - WHERE reg_event = ".$result_data['id'] - , ARRAY_A); + WHERE reg_event = $eventId + ;", ARRAY_A); + + $counts = array( + 'total' => $countsData['total'], + 'registered' => $countsData['registered'], + 'cartHold' => $countsData['cartHold'], + 'curAvail' => $countsData['curAvail'], + 'totalAvail' => $countsData['cartHold'] + $countsData['curAvail'] + ); + + return $counts; - $result_data['total'] = $counts['total']; - $result_data['registered'] = $counts['registered']; - $result_data['cartHold'] = $counts['cartHold']; - $result_data['curAvail'] = $counts['curAvail']; - $result_data['totalAvail'] = $counts['cartHold'] + $counts['curAvail']; + } + + /* + * Completely remove registrations for a specific event + * + * WARNING: This function will completely remove any trace of registrations for + * an event. It does nothing to confirm that this should happen. The code calling + * this function is responsible for all necessary confirmation that this should + * be done. + * + * @param integer $eventId ID of the reg_event record + * + * @return boolean True if delete was successful + * + */ + public function deleteRegEvent($eventId = false) + { + if (!$eventId) { + trigger_error("deleteRegEvent(): Called without ID", E_USER_NOTICE); + return false; } + $eventId = ($eventId - 0); + if ($eventId <= 0) { + trigger_error("deleteRegEvent(): Called with bad ID: $eventId", E_USER_NOTICE); + return false; + } + + // Make sure we have a reg_event record for this event + $eventData = $this->getEntry($eventId); + if (!$eventData || !is_array($eventData)) { + trigger_error("deleteRegEvent(): Unable to find reg_event entry for ID: $eventId", E_USER_NOTICE); + return false; + } + + // List of SQL queries to delete all table entries for this registration event + $deleteSql = array( + "DELETE FROM ".GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX . "reg_request_registrant WHERE reg_event = $eventId", + "DELETE FROM ".GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX . "reg_request_rate WHERE reg_event = $eventId", + "DELETE FROM ".GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX . "reg_request_rate WHERE reg_event = $eventId", + "DELETE FROM ".GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX . "reg_request_event WHERE reg_event = $eventId", + "DELETE FROM ".GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX . "reg_rate WHERE reg_event = $eventId", + "DELETE FROM ".GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX . "reg_class WHERE reg_event = $eventId", + "DELETE FROM ".GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX . "reg_time_pending WHERE reg_event = $eventId", + "DELETE FROM ".GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX . "reg_time WHERE reg_event = $eventId", + "DELETE FROM ".GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX . "reg_event WHERE id = $eventId", + ); + + $this->wpdb->query("START TRANSACTION"); + + + $fail = false; + + // Run each delete query in sequence + foreach ($deleteSql as $sql) { + + // If there hasn't been a failure yet (we don't want to run additional queries if there's already been a problem) + if (!$fail) { + + // run this query + $res = $this->wpdb->query($sql); + + /* + * Check if it failed. + * + * We need to test specifically against FALSE since wpdb->query() + * returns the number of records deleted, which could be 0. + */ + if ($res === false) { + $fail = true; + trigger_error('deleteRegEvent(); Error deleting a reg_event: '.$this->wpdb->last_error, E_USER_NOTICE); + } + + } + } + + // If there was a failure, roll back all changes, otherwise complete the transaction. + if ($fail) { + $this->wpdb->query("ROLLBACK"); + return false; + } else { + $this->wpdb->query("COMMIT"); + } + + return true; - return $result_data; } /* diff --git a/models/admin/registrations/events.php b/models/admin/registrations/events.php index 877e640..e06301c 100644 --- a/models/admin/registrations/events.php +++ b/models/admin/registrations/events.php @@ -115,6 +115,7 @@ class GlmMembersAdmin_registrations_events extends GlmDataRegistrationsRegEvent $regEventJSON = false; $regClassesJSON = false; $regTimesJSON = false; + $regEventDeleted = false; // Get any provided option if (isset($_REQUEST['option'])) { @@ -308,6 +309,54 @@ class GlmMembersAdmin_registrations_events extends GlmDataRegistrationsRegEvent break; + case 'delete': + + $regEventDeleted = false; + + // If we don't have a registration Event ID + if (!$regEventID) { + $messages[] = 'Request to delete registrations for an event but ID for this was not supplied.'; + } else { + + // Check if we received a confirmation override to delete a reg event that has completed registrations + if (isset($_REQUEST['deleteConfirmation']) && $_REQUEST['deleteConfirmation'] == 'DELETE') { + + // Check that we have reg_event entry for this ID + $regEvent = $this->getEntry($regEventID); + + if (!$regEvent) { + $messages[] = 'Request to delete registrations for an event but unable to find registration setup for this event.'; + } else { + + // Delete registrations for this event + $regEventDeleted = $this->deleteRegEvent($regEventID); + + if (!$regEventDeleted) { + $messages[] = 'Attempt to delete registrations for this event failed. Nothing has been deleted'; + } + } + + } else { + + } + + } + + if ($regEventDeleted) { + + // Return status, any suggested view, and any data to controller + return array( + 'status' => true, + 'modelRedirect' => false, + 'view' => 'admin/registrations/registrationEventDeleted.html', + 'data' => array() + ); + break; + + } + + // Registration event was not deleted so falling through to eventDashboard to display reasons or ask for confirmation + case 'eventDashboard': $regEvent = $this->getEventConfig($regEventID, true, false, true); @@ -330,6 +379,10 @@ class GlmMembersAdmin_registrations_events extends GlmDataRegistrationsRegEvent break; + + + break; + case 'dashboard': default: diff --git a/views/admin/registrations/eventDashboard.html b/views/admin/registrations/eventDashboard.html index 712587d..2dc700d 100644 --- a/views/admin/registrations/eventDashboard.html +++ b/views/admin/registrations/eventDashboard.html @@ -3,7 +3,7 @@

{$regEvent.event_name}

{if $haveMessages} -
+
Please Note:
    {foreach $messages as $m} @@ -47,6 +47,7 @@
+ {if $regEvent.total > 0}

Maximum Attendees:

@@ -55,6 +56,7 @@ {$regEvent.total}
+ {/if}

Registered:

@@ -63,6 +65,7 @@ {$regEvent.registered}
+ {if $regEvent.total > 0}

Cart Hold:

@@ -87,6 +90,7 @@ {$regEvent.totalAvail}
+ {/if}
{if apply_filters('glm_members_menu_members', true)} @@ -98,6 +102,53 @@ {if is_array($r_link)} Edit {$r_link.title} {/if} + +
Delete Registration Event
+
+
+

WARNING!

+

*** Entirely removes an Event from Registrations ***

+
+

+ Continuing with this action will permanently remove this event from registrations including all configuration associated with it. + This will not remove the event listing, only the information on registrations for this event. +

+

+ This action is + NOT REVERSABLE! After deletion, you will be required to re-enter all registration related + configuration information in order to have registrations for this event. +

+ {if $regEvent.registered > 0} +
+

ALSO NOTE!

+

There have been {$regEvent.registered} registrations submitted for this event.

+
+

+ Continuing with this action will delete all registrations for this event. + This will also remove these registrations from all reports. It's important that you print all reports and other information + you want to preserve for registrations for this event prior to deletion. +

+

+ The only exception is that the registration request records will remain along with the summary that was displayed after checkout + for those requests. After this action, that will be the only historic record the the submission took place and it will not be + possible to search for these requests by event. +

+ {/if} +
+ + + + +
+

Event: {$regEvent.event_name}

+

To delete registrations for this event, enter exactly "DELETE" in the field below.

+ +

Then click this button

+ +
+
+
+ @@ -179,7 +230,7 @@ var fullCalendarLoaded = false; // If this is a time specific event, then display the calendar - if ({$regEvent.time_specific.value}) { + if ({$regEvent.time_specific.value} +0) { /* * Initialize the Full Calendar @@ -295,10 +346,24 @@ } - + + // Delete Dialog Box + $("#regEventDeleteDialog").dialog({ + autoOpen: false, + width: 600, + resizable: true + }); + + // Delete Event Registrations Button + $('#regEventDeleteButton').on('click', function() { + $('#regEventDeleteDialog').dialog('open'); + }); + + // Flash certain elements for a short time after display $(".glm-flash-updated").fadeOut(500).fadeIn(500).fadeOut(500).fadeIn(500).fadeOut(500).fadeIn(500).fadeOut(500).fadeIn(500).fadeOut(500).fadeIn(500).fadeOut(500); + }); diff --git a/views/admin/registrations/registrationEventDeleted.html b/views/admin/registrations/registrationEventDeleted.html new file mode 100644 index 0000000..f78c391 --- /dev/null +++ b/views/admin/registrations/registrationEventDeleted.html @@ -0,0 +1,6 @@ +{include file='admin/registrations/eventHeader.html'} + +

Event removed from registrations.

+ +{include file='admin/footer.html'} +