/*
* 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
*
}
+ /*
+ * 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 "<pre>".print_r($this->config['settings'],1)."</pre>";
+
+
+
+ require_once GLM_MEMBERS_REGISTRATIONS_PLUGIN_CLASS_PATH.'/data/dataMisc.php';
+ $RegMisc = new GlmDataRegistrationsMisc($this->wpdb, $this->config);
+ $regMisc = $RegMisc->getEntry(1);
+
+//echo "<pre>".print_r($this->cart,1)."</pre>";
+
+
+
+ /*
+ * 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 "<p>E-Mail to site owner</p><hr>$emailMsg<hr>";
+ }
+
+
+ /*
+ * 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 "<p>E-Mail to person submitting registrations</p><hr>$emailMsg<hr>";
+ } else {
+//echo "<hr><p>No email address for person submitting registrations.<p><hr>";
+ }
+ }
+
+
+ // 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 "<pre>".print_r($registrant,1)."</pre>";
+ $emailMsg = $this->generateHTML($viewData, nl2br($regMisc['registrant_notify_text']), true);
+ mail($emailAddr, $regMisc['registrant_notify_subject'], $emailMsg);
+//echo "<p>E-Mail to registrant: ".$registrant['fname']." ".$registrant['lname']."</p><hr>$emailMsg<hr>";
+ } else {
+//echo "<hr><p>No email address for this registrant.<p><hr>";
+ }
+
+ }
+
+
+ $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)
*
}
+
+ /*
+ * 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 ****
+ ");
+
+
+
+ }
+
}
);
// 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,
$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) {
);
}
+
/*
* 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';
}
-
-
-
-
- /**
- * 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;
-
- }
-
-
-
}