Setting up the member ref_dest hidden field
authorSteve Sutton <steve@gaslightmedia.com>
Fri, 21 Oct 2016 20:59:45 +0000 (16:59 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Fri, 21 Oct 2016 20:59:45 +0000 (16:59 -0400)
Setting up hidden fields for when member contact is logged in and
submits an event.

models/front/events/frontAdd.php
setup/shortcodes.php
views/front/events/frontAdd.html

index 0143a25..a08cde5 100644 (file)
@@ -117,27 +117,17 @@ class GLmMembersFront_events_frontAdd extends GlmDataEvents
         $endTime        = 0;
         $status         = false;
         $memberOnly     = false;
+        $memberContact  = false;
 
         echo '<br style="clear: right;">';
         echo '<pre>$actionData: ' . print_r( $actionData, true ) . '</pre>';
 
-        if ( isset( $actionData['request']['memberOnly'] )
-            && $memberOnly = filter_var( $actionData['request']['memberOnly'], FILTER_VALIDATE_BOOLEAN ) ) {
+        if ( isset( $actionData['request']['member_only'] )
+            && $memberOnly = filter_var( $actionData['request']['member_only'], FILTER_VALIDATE_BOOLEAN ) ) {
 
-            $config = apply_filters( 'glm_associate_config', '' );
-            $contact_user = ( isset( $config['loggedInUser']['contactUser'] ) ) ? $config['loggedInUser']['contactUser']: null;
-            if ( !$contact_user ) {
-
-                return array(
-                    'status'           => $status,
-                    'menuItemRedirect' => false,
-                    'modelRedirect'    => false,
-                    'view'             => 'front/events/error.html',
-                    'data'             => array(),
-                );
-            }
-            echo '<br style="clear: right;">';
-            echo '<pre>$contact_user: ' . print_r( $contact_user, true ) . '</pre>';
+            $config        = apply_filters( 'glm_associate_config', '' );
+            $memberContact = ( isset( $config['loggedInUser']['contactUser'] ) ) ? $config['loggedInUser']['contactUser']: null;
+            echo '<pre>$memberContact: ' . print_r( $memberContact, true ) . '</pre>';
         }
 
         if( ! wp_script_is( 'jquery-ui', 'enqueued' ) ){
@@ -148,8 +138,8 @@ class GLmMembersFront_events_frontAdd extends GlmDataEvents
         $view = 'frontAdd';
         // populate category dropdown
         $categories = new GlmDataEventsCategories($this->wpdb, $this->config);
-        $emailInfo = new GlmDataEventsManagement($this->wpdb, $this->config);
-        $emailInfo = $emailInfo->getEntry(1);
+        $emailInfo  = new GlmDataEventsManagement($this->wpdb, $this->config);
+        $emailInfo  = $emailInfo->getEntry(1);
 
         // get and validate recipient email address, put into an array to pass to wp_mail
         $toEmail = $emailInfo['to_email'];
@@ -349,25 +339,25 @@ class GLmMembersFront_events_frontAdd extends GlmDataEvents
                 }
                 // mySql transactions
                 $eventData = array(
-                    'status'            => '20',
-                    'created'           => $date,
-                    'updated'           => $date,
-                    'name'              => $name,
-                    'intro'             => $intro,
-                    'descr'             => $descr,
-                    'image'             => $imageName,
-                    'file1'             => $fileName,
-                    'file1_descr'       => $fileDescr,
-                    'cost'              => $cost,
-                    'free'              => $free,
-                    'url'               => $url,
-                    'contact_phone'     => $contactPhone,
-                    'admin_name'        => $admin_name,
-                    'admin_phone'       => $adminPhone,
-                    'admin_email'       => $adminEmail,
-                    'contact_name'      => $contactFirst . " " . $contactLast,
-                    'contact_email'     => $contactEmail,
-                    'admin_org'         => $admin_org
+                    'status'        => '20',
+                    'created'       => $date,
+                    'updated'       => $date,
+                    'name'          => $name,
+                    'intro'         => $intro,
+                    'descr'         => $descr,
+                    'image'         => $imageName,
+                    'file1'         => $fileName,
+                    'file1_descr'   => $fileDescr,
+                    'cost'          => $cost,
+                    'free'          => $free,
+                    'url'           => $url,
+                    'contact_phone' => $contactPhone,
+                    'admin_name'    => $admin_name,
+                    'admin_phone'   => $adminPhone,
+                    'admin_email'   => $adminEmail,
+                    'contact_name'  => $contactFirst . " " . $contactLast,
+                    'contact_email' => $contactEmail,
+                    'admin_org'     => $admin_org
                 );
                 $eventDataFormat = array(
                      '%d',
@@ -390,6 +380,12 @@ class GLmMembersFront_events_frontAdd extends GlmDataEvents
                      '%s',
                      '%s'
                 );
+                if ( $memberOnly && $memberContact ) {
+                    $eventData['ref_type'] = $memberContact['ref_type'];
+                    $eventData['ref_dest'] = $memberContact['ref_dest'];
+                    $eventDataFormat[] = '%d';
+                    $eventDataFormat[] = '%d';
+                }
                 $this->wpdb->insert(
                     GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . 'events',
                     $eventData,
@@ -557,19 +553,21 @@ class GLmMembersFront_events_frontAdd extends GlmDataEvents
             : ( $this->config['settings']['event_default_state'] ) ? $this->config['settings']['event_default_state']: 'MI';
         // Compile template data
         $templateData = array(
-            'states'       => $this->config['states'],
-            'state_def'    => $default_state,
-            'siteBaseUrl'  => GLM_MEMBERS_EVENTS_SITE_BASE_URL,
-            'currentUrl'   => $_SERVER['HTTP_REFERER'],
-            'categories'   => $eventCategories,
-            'fromDate'     => $fromDate,
-            'event'        => $newEvent,
-            'permalink'    => $permalink,
-            'title'        => $title,
-            'to_email'     => $to_email,
-            'from_email'   => $fromEmail,
-            'notification' => $emailNotification,
-            'mainImgUrl'   => GLM_MEMBERS_PLUGIN_MEDIA_URL . '/images/large/'
+            'memberOnly'    => $memberOnly,
+            'memberContact' => $memberContact,
+            'states'        => $this->config['states'],
+            'state_def'     => $default_state,
+            'siteBaseUrl'   => GLM_MEMBERS_EVENTS_SITE_BASE_URL,
+            'currentUrl'    => $_SERVER['HTTP_REFERER'],
+            'categories'    => $eventCategories,
+            'fromDate'      => $fromDate,
+            'event'         => $newEvent,
+            'permalink'     => $permalink,
+            'title'         => $title,
+            'to_email'      => $to_email,
+            'from_email'    => $fromEmail,
+            'notification'  => $emailNotification,
+            'mainImgUrl'    => GLM_MEMBERS_PLUGIN_MEDIA_URL . '/images/large/'
         );
 
         //error_reporting(E_ALL ^ E_NOTICE);
index be21c89..759a6c8 100644 (file)
@@ -125,7 +125,7 @@ $glmMembersEventsShortcodes = array(
         'table'      => false,
         'attributes' => array(
             'id'         => false,
-            'memberOnly' => false,
+            'member_only' => false,
         )
 
     ),
index b0345d8..a7e5e65 100644 (file)
@@ -3,6 +3,10 @@
 <h2> Add Your Event </h2>
 
 <form action="{$thisUrl}" method="post" enctype="multipart/form-data" name="frontAddForm" id="frontForm">
+    {if $memberOnly && $memberContact}
+    <input type="hidden" name="ref_type" value="{$memberContact.ref_type}" />
+    <input type="hidden" name="ref_dest" value="{$memberContact.ref_dest}" />
+    {/if}
     <table id="glm-table-descr" class="glm-admin-table glm-event-table">
         <tr id="glmRealEmail">
             <td>Real Email</td>