Added output of E-Mails to owner and registrants. Still need to fix merge and add...
authorChuck Scott <cscott@gaslightmedia.com>
Thu, 4 Jan 2018 16:31:54 +0000 (11:31 -0500)
committerChuck Scott <cscott@gaslightmedia.com>
Thu, 4 Jan 2018 16:31:54 +0000 (11:31 -0500)
classes/regCartSupport.php
models/front/registrations/checkoutProcess.php
models/front/registrations/list.php
views/admin/settings/registrationsMisc.html

index c1a02c2..b7d8d29 100644 (file)
@@ -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 "<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)
      *
@@ -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 ****
+        ");
+
+
+
+    }
+
 }
index adf5d4a..776af18 100644 (file)
@@ -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;
-
-    }
-
-
-
  }
index a1ea012..3339429 100644 (file)
         $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);
             }
         }
 
+
+
         $view = 'list';
 
         switch ( $option ) {
index 8ab1e6e..c48fce7 100644 (file)
@@ -5,7 +5,7 @@
     <a href="{$thisUrl}?page=glm-members-admin-menu-settings&glm_action=registrationsMisc" class="glm-settings-tab nav-tab nav-tab-active">Misc. Settings</a>
 </h2>
 
-<table class="glm-admin-table glm-settings-table">
+<table class="glm-admin-table glm-settings-table" width="100%">
     <tr>
         <td colspan="2">
             {if $miscUpdated}<h2 class="glm-notice glm-flash-updated glm-right">Settings Updated</h2>{/if}
                         </td>
                     </tr>
                     <tr>
-                        <th {if $regMisc.fieldRequired.instr_notify_subject}class="glm-required"{/if}>Subject of notification E-Mail to {$terms.reg_term_instructor}:</th>
+                        <th {if $regMisc.fieldRequired.instr_notify_subject}class="glm-required"{/if}>Subject of notification E-Mail to contacts listed in Event:</th>
                         <td {if $regMisc.fieldFail.instr_notify_subject}class="glm-form-bad-input"{/if}>
                             <input type="text" name="instr_notify_subject" value="{$regMisc.fieldData.instr_notify_subject}" class="glm-form-text-input-medium">
                             {if $regMisc.fieldFail.instr_notify_subject}<p>{$regMisc.fieldFail.instr_notify_subject}</p>{/if}
                         </td>
                     </tr>
                     <tr>
-                        <th {if $regMisc.fieldRequired.instr_notify_text}class="glm-required"{/if}>Notification E-Mail text for {$terms.reg_term_instructor}:</th>
+                        <th {if $regMisc.fieldRequired.instr_notify_text}class="glm-required"{/if}>Notification E-Mail text for contact listed in Event:</th>
                          <td {if $regMisc.fieldFail.instr_notify_text}class="glm-form-bad-input"{/if}>
                             {php} 
                                 wp_editor('{$regMisc.fieldData.instr_notify_text|escape:quotes}', 'glm_reg_instr_notify_text', array(