From: Chuck Scott Date: Thu, 4 Jan 2018 16:31:54 +0000 (-0500) Subject: Added output of E-Mails to owner and registrants. Still need to fix merge and add... X-Git-Tag: v1.0.0^2~96 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=908cf547db1693ce169ee07f8916bca0e4e0d142;p=WP-Plugins%2Fglm-member-db-registrations.git Added output of E-Mails to owner and registrants. Still need to fix merge and add E-mail to event contacts. --- diff --git a/classes/regCartSupport.php b/classes/regCartSupport.php index c1a02c2..b7d8d29 100644 --- a/classes/regCartSupport.php +++ b/classes/regCartSupport.php @@ -139,7 +139,7 @@ class GlmRegCartSupport /* * Retrieve a complete cart * - * This function starts by clearing any expored holds (reg_time_pending records) + * This function starts by clearing any expired holds (reg_time_pending records) * * Structure of returned data * @@ -1161,6 +1161,220 @@ class GlmRegCartSupport } + /* + * Update inventory and send notifications for a cart + * Used after successful checkout to update inventory + * + * This method also removes holds associated with this request. + * + * The reason inventory update and notify are both in this method is that they both + * happen at the same time and they both require walking through the cart data. + * + * @param string $summary HTML Summary of checkout for sending to owner and requesting address + * @param integer $requestId Specify the request ID - not requeired if cart is already loaded + * + * @return null + * + * @access public + */ + public function checkoutUpdateInventoryAndNotify($summary = '', $requestId = false) + { + + // If a request ID is supplied, load that cart + if ($requestId) { + getRegistrationCart($requestId, false, true); + } + +//echo "
".print_r($this->config['settings'],1)."
"; + + + + require_once GLM_MEMBERS_REGISTRATIONS_PLUGIN_CLASS_PATH.'/data/dataMisc.php'; + $RegMisc = new GlmDataRegistrationsMisc($this->wpdb, $this->config); + $regMisc = $RegMisc->getEntry(1); + +//echo "
".print_r($this->cart,1)."
"; + + + + /* + * Send notification to site owner + */ + $emailAddr = $this->config['settings']['reg_org_internal_email']; + if (trim($emailAddr) != '' && trim($summary) != '') { + $viewData = array( + 'summary' => $summary + ); + $emailMsg = nl2br($regMisc['notify_text'])."\n\n".$summary; + mail($emailAddr, $regMisc['notify_subject'], $emailMsg); +//echo "

E-Mail to site owner


$emailMsg
"; + } + + + /* + * Send notification to person submitting request + */ + $accountId = $this->cart['request']['account']; + if (isset($this->cart['accounts'][$accountId])) { + $emailAddr = ''; + if (trim($this->cart['accounts'][$accountId]['email']) != '') { + $emailAddr = $this->cart['accounts'][$accountId]['email']; + } elseif (trim($this->cart['accounts'][$accountId]['contact_email']) != '') { + $emailAddr = $this->cart['accounts'][$accountId]['contact_email']; + } + if ($emailAddr != '') { + $viewData = array( + 'summary' => $summary + ); + $emailMsg = nl2br($regMisc['submission_notify_text'])."\n\n".$summary; + mail($emailAddr, $regMisc['submission_notify_subject'], $emailMsg); +//echo "

E-Mail to person submitting registrations


$emailMsg
"; + } else { +//echo "

No email address for person submitting registrations.


"; + } + } + + + // For each event + foreach ($this->cart[events] as $event) { + + /* + * Send notifications to contcts listed in event + */ + // Need to add contact addresses + + + // For each class + foreach ($event['classes'] as $class) { + + // For each rate + foreach ($class['rates'] as $rate) { + + // For each registrant + foreach ($rate['registrants'] as $registrant) { +/* + // Adjust the inventory and hold numbers + $this->updateTimeEntryCounts($registrant['reg_time'], -1, 1); + + // Remove the hold record + $this->wpdb->delete( + GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX."reg_time_pending", + array( + 'registrant' => $registrant['id'] + ) + ); +*/ + // Send registrant a confirmation + $accountId = $registrant['account']; + if (isset($this->cart['accounts'][$accountId])) { + $emailAddr = ''; + if (trim($this->cart['accounts'][$accountId]['email']) != '') { + $emailAddr = $this->cart['accounts'][$accountId]['email']; + } elseif (trim($this->cart['accounts'][$accountId]['contact_email']) != '') { + $emailAddr = $this->cart['accounts'][$accountId]['contact_email']; + } + if ($emailAddr != '') { + $viewData = $registrant; +//echo "
".print_r($registrant,1)."
"; + $emailMsg = $this->generateHTML($viewData, nl2br($regMisc['registrant_notify_text']), true); + mail($emailAddr, $regMisc['registrant_notify_subject'], $emailMsg); +//echo "

E-Mail to registrant: ".$registrant['fname']." ".$registrant['lname']."


$emailMsg
"; + } else { +//echo "

No email address for this registrant.


"; + } + + } + + + $registrantEmail = $this->config['settings']['?????']; + + } + } + } + } + + } + + /** + * Merge template and data to produce HTML + * + * Checks the theme's view directories and the view directories for + * this plugin for a matching view file. + * + * Note that $view needs to have the proper view directory path + * includes. (i.e. "/views/front/registrations/summary.html") + * + * $view may also be a template as a string if $viewIsString is true. + * + * @param $data array Array of data to merge with the template + * @param $view string Name of view file (see above)) + * @param $viewIsString boolean If true, $view is a string containing the view. + * + * @access public + * @return void + */ + function generateHTML($data, $view, $viewIsString = false) + { + + // Load Smarty Template support + $smarty = new smartyTemplateSupport(); + + // Add standard parameters + require GLM_MEMBERS_PLUGIN_SETUP_PATH.'/standardTemplateParams.php'; + + // Add data from model to Smarty template + if (is_array($data) && count($data) > 0) { + foreach ($data as $k => $d) { + $smarty->templateAssign($k, $d); + } + } + + + // If is supplied as a string + if ($viewIsString) { + + $out = $smarty->template->fetch('eval:'.$view); + + // Otherwise $view is a file name + } else { + + // Get the specified view file - check theme first + $viewPath = GLM_MEMBERS_PLUGIN_CURRENT_THEME_DIR."/views"; + $viewPath2 = GLM_MEMBERS_WORDPRESS_PLUGIN_PATH . "views"; // Save default + + // If the view is not found in the theme, fall back to views in the plugin + if (!is_file($viewPath.'/'.$view)) { + + // Next try the plugin/add-on + $viewPath = GLM_MEMBERS_REGISTRATIONS_PLUGIN_PATH . "/views"; + + if (!is_file($viewPath.'/'.$view)) { + + if (GLM_MEMBERS_PLUGIN_FRONT_DEBUG) { + trigger_error("Bad or missing view file when generating checkout HTML: $viewPath/$view", E_USER_NOTICE); + } + + } + + } + + // Update the Smarty view path + $smarty->template->setTemplateDir($viewPath); + + // If the view path doesn't match the default, add the default (using theme view) + if ($viewPath2 != $viewPath) { + $smarty->template->addTemplateDir($viewPath2); + } + + // Generate output from model data and view + $out = $smarty->template->fetch($view); + + } + + return $out; + + } + /* * Get a quick summary of a registration request (cart) * @@ -1247,4 +1461,30 @@ class GlmRegCartSupport } + + /* + * Purge old carts and incomplete accounts + * + * @return null + * + * @access public + */ + public function purgeOldData() + { +echo "NOT PURGING YET"; +return; // Not ready for use yet + + $RegRequest = new GlmDataRegistrationsRegRequest($this->wpdb, $this->config); + + // Check for pending carts that have not been touched for 1 week. + // $expireDate = date("Y-m-d H:i:s", )), + $oldReq = $RegRequest->getList(" + T.status = ".$this->config['submission_status_numb']['CART']." AND + T.last_update **** NEED TO GET THE EXPIRE DATE CREATED FIRST **** + "); + + + + } + } diff --git a/models/front/registrations/checkoutProcess.php b/models/front/registrations/checkoutProcess.php index adf5d4a..776af18 100644 --- a/models/front/registrations/checkoutProcess.php +++ b/models/front/registrations/checkoutProcess.php @@ -521,7 +521,7 @@ class GlmMembersFront_registrations_checkoutProcess extends GlmRegCartSupport ); // If COMPLETE, save date, pay method, status, total - if ($cartStatus == $this->config['submission_status_numb']['COMPLETE']) { + if ($cartStatus == $this->config['submission_status_numb']['COMPLETE'] && $billing['addr2'] != '*** DO NOT CLEAR ***') { $reqData = array_merge( $reqData, @@ -612,40 +612,8 @@ class GlmMembersFront_registrations_checkoutProcess extends GlmRegCartSupport $account = $Account->getEntry($request['account']); - - if (count($messages) == 0) { - - // Produce HTML for storage and checkout page and add to request - $summaryData = array( - 'cart' => $this->cart, - 'request' => $request, - 'account' => $account, - 'payMethodsNumb' => $this->config['payment_method_numb'], - 'status' => $this->config['submission_status'], - 'misc' => $misc - ); - $summary = $this->generateCheckoutConfHTML($summaryData, 'front/registrations/summaryStore.html'); - $updated = $this->wpdb->update( - GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX.'reg_request', - array( - 'summary' => $summary - ), - array( 'id' => $requestId ), - array('%s') - ); - - } - - if (count($messages) == 0) { - - // Removed inventory holds - - // Update inventory totals - - } - /* - * If all is done correctly, use model redirect to go to Step 4 - Dispaly summary + * If there's been a problem, use model redirect to go back to the checkout page */ if (count($messages) != 0) { @@ -673,22 +641,46 @@ class GlmMembersFront_registrations_checkoutProcess extends GlmRegCartSupport ); } + /* * Successful checkout */ + // Produce HTML for storage and checkout page and add to request + $summaryData = array( + 'cart' => $this->cart, + 'request' => $request, + 'account' => $account, + 'payMethodsNumb' => $this->config['payment_method_numb'], + 'status' => $this->config['submission_status'], + 'misc' => $misc + ); + $summary = $this->generateHTML($summaryData, 'front/registrations/summaryStore.html'); + $updated = $this->wpdb->update( + GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX.'reg_request', + array( + 'summary' => $summary + ), + array( 'id' => $requestId ), + array('%s') + ); + + // Update inventory totals and send notifications + if ($billing['addr2'] != '*** DO NOT CLEAR ***') { + $this->checkoutUpdateInventoryAndNotify($summary); + } + // Send acknowledgement to person submitting request mail($request['email'], $misc['submission_ack_subject'], $summary); - // Send notice to all registrants that have E-Mail addresses - reset($this->cart); - /*** NEED TO DO THIS ***/ - /* * Remove cart from session */ - unset($_SESSION['glm_reg_cart_id']); + + if ($billing['addr2'] != '*** DO NOT CLEAR ***') { + unset($_SESSION['glm_reg_cart_id']); + } $view = 'summary'; @@ -713,81 +705,4 @@ class GlmMembersFront_registrations_checkoutProcess extends GlmRegCartSupport } - - - - - /** - * Merge template and data to produce HTML - * - * Checks the theme's view directories and the view directories for - * this plugin for a matching view file. - * - * Note that $viewFile needs to have the proper view directory path - * includes. (i.e. "/views/front/registrations/summary.html") - * - * @param $data array Array of data to merge with the template - * @param $view string Path added to - * - * @access public - * @return void - */ - function generateCheckoutConfHTML($data, $viewFile) - { - - // If a view file is specified - if ($viewFile) { - - // Get the specified view file - check theme first - $viewPath = GLM_MEMBERS_PLUGIN_CURRENT_THEME_DIR."/views"; - $viewPath2 = GLM_MEMBERS_WORDPRESS_PLUGIN_PATH . "views"; // Save default - - // If the view is not found in the theme, fall back to views in the plugin - if (!is_file($viewPath.'/'.$viewFile)) { - - // Next try the plugin/add-on - $viewPath = GLM_MEMBERS_REGISTRATIONS_PLUGIN_PATH . "/views"; - - if (!is_file($viewPath.'/'.$viewFile)) { - - if (GLM_MEMBERS_PLUGIN_FRONT_DEBUG) { - trigger_error("Bad or missing view file when generating checkout HTML: $viewPath/$viewFile", E_USER_NOTICE); - } - - } - - } - - } - - // Load Smarty Template support - $smarty = new smartyTemplateSupport(); - - // Add standard parameters - require GLM_MEMBERS_PLUGIN_SETUP_PATH.'/standardTemplateParams.php'; - - // Add data from model to Smarty template - if (is_array($data) && count($data) > 0) { - foreach ($data as $k => $d) { - $smarty->templateAssign($k, $d); - } - } - - // Update the Smarty view path - $smarty->template->setTemplateDir($viewPath); - - // If the view path doesn't match the default, add the default (using theme view) - if ($viewPath2 != $viewPath) { - $smarty->template->addTemplateDir($viewPath2); - } - - // Generate output from model data and view - $out = $smarty->template->fetch($viewFile); - - return $out; - - } - - - } diff --git a/models/front/registrations/list.php b/models/front/registrations/list.php index a1ea012..3339429 100644 --- a/models/front/registrations/list.php +++ b/models/front/registrations/list.php @@ -74,6 +74,22 @@ $haveRegEvents = false; $regEventsCount = false; + // Start by checking if we need to purge any old data - Once per hour + $lastPurgeTime = get_option('glmMembersRegistrationsPluginLastPurgeTime'); + if (!$lastPurgeTime && (time() - $lastPurgeTime) > 3600) { + + // Update last purge time to stop any other users from triggering this + update_option('glmMembersRegistrationsPluginLastPurgeTime', time()); + + // Call purge method + require_once GLM_MEMBERS_REGISTRATIONS_PLUGIN_CLASS_PATH.'/regCartSupport.php'; + $CartSupport = new GlmRegCartSupport($this->wpdb, $this->config); + $CartSupport->purgeOldData(); + + } + + + // Get misc texts require_once GLM_MEMBERS_REGISTRATIONS_PLUGIN_CLASS_PATH.'/data/dataMisc.php'; $Misc = new GlmDataRegistrationsMisc($this->wpdb, $this->config); @@ -95,6 +111,8 @@ } } + + $view = 'list'; switch ( $option ) { diff --git a/views/admin/settings/registrationsMisc.html b/views/admin/settings/registrationsMisc.html index 8ab1e6e..c48fce7 100644 --- a/views/admin/settings/registrationsMisc.html +++ b/views/admin/settings/registrationsMisc.html @@ -5,7 +5,7 @@ Misc. Settings - +
- + - +
{if $miscUpdated}

Settings Updated

{/if} @@ -124,14 +124,14 @@
Subject of notification E-Mail to {$terms.reg_term_instructor}:Subject of notification E-Mail to contacts listed in Event: {if $regMisc.fieldFail.instr_notify_subject}

{$regMisc.fieldFail.instr_notify_subject}

{/if}
Notification E-Mail text for {$terms.reg_term_instructor}:Notification E-Mail text for contact listed in Event: {php} wp_editor('{$regMisc.fieldData.instr_notify_text|escape:quotes}', 'glm_reg_instr_notify_text', array(