forms
authorSteve Sutton <steve@gaslightmedia.com>
Thu, 5 Mar 2015 17:14:59 +0000 (12:14 -0500)
committerSteve Sutton <steve@gaslightmedia.com>
Thu, 5 Mar 2015 17:16:36 +0000 (12:16 -0500)
Working on passport form

Toolkit/Contacts/Admin/EditContact.php
Toolkit/Contacts/ContactUs.php
Toolkit/Contacts/Database/tables/contact.sql
Toolkit/Contacts/ENewsSignup.php
Toolkit/Contacts/PassPort.php
Toolkit/Contacts/VacationPlanner.php
Toolkit/Contacts/templates/contactForm.html
js/PassportForm.js

index 92f5b8c..9ac7a12 100644 (file)
@@ -544,6 +544,14 @@ class Toolkit_Contacts_Admin_EditContact
             'opts'    => 'Yes',
             'val'     => array(0, 1)
         );
+        $e[] = array(
+            'type'    => 'advcheckbox',
+            'req'     => false,
+            'name'    => 'golfvacation',
+            'display' => '',
+            'opts'    => 'Golf Vacation Planner',
+            'val'     => array(0, 1)
+        );
         if (is_array($this->interestsGroups)) {
             foreach ($this->interestsGroups as $group => $gData) {
                 $this->myGroups[] = $gData;
index 09857ab..caf773b 100755 (executable)
@@ -1181,7 +1181,7 @@ class Toolkit_Contacts_ContactUs
         }
         return $output;
     }
-
+   
     /**
      * Return the existing contact/customer contact_type
      *
index fd43ab4..cf60465 100644 (file)
@@ -32,6 +32,10 @@ CREATE TABLE contacts.contact
  verify_password text,
  gift_cert BOOLEAN DEFAULT FALSE,
  members BOOLEAN DEFAULT FALSE,
+ big_giveaway BOOLEAN DEFAULT FALSE,
+ giveaway BOOLEAN DEFAULT FALSE,
+ eclub BOOLEAN DEFAULT FALSE,
+ golfvacation BOOLEAN DEFAULT FALSE,
  PRIMARY KEY (id));
 
 CREATE INDEX contact_create_date_indx ON contacts.contact USING btree(create_date);
index c85873f..28dbba0 100755 (executable)
@@ -118,7 +118,7 @@ class Toolkit_Contacts_ENewsSignup
             $attributes,
             $trackSubmit
         );
-        $this->email = false;//ENEWS_EMAIL;
+        $this->email = ENEWS_EMAIL;
     }
 
     /**
@@ -132,9 +132,9 @@ class Toolkit_Contacts_ENewsSignup
     public function configureConstants()
     {
         $constants = array(
-            'user_agent' => $_SERVER['HTTP_USER_AGENT'],
+            'user_agent'  => $_SERVER['HTTP_USER_AGENT'],
             'remote_addr' => $_SERVER['REMOTE_ADDR'],
-            'mail_ok' => 1
+            'mail_ok'     => 1
         );
         $this->setupConstants($constants);
     }
index 493e441..3fe3884 100755 (executable)
@@ -153,6 +153,11 @@ class Toolkit_Contacts_PassPort
             'req'  => false,
             'name' => 'remote_addr'
         );
+        $e[] = array(
+            'type'    => 'hidden',
+            'req'     => false,
+            'name'    => 'mail_ok',
+        );
         $e[] = array(
             'type'    => 'header',
             'name'    => 'firstHdr_rmv',
@@ -256,20 +261,16 @@ class Toolkit_Contacts_PassPort
             'req'     => true,
             'name'    => 'qty',
             'display' => 'Passports',
-            'opts'    => array(''=>'') + $qty
+            'opts'    => array(''=>'') + $qty,
+            'att'    => array('style' => 'width: 70px;margin-left: 50px;')
         );
         $e[] = array(
             'type'    => 'static',
             'req'     => false,
-            'name'    => 'postage',
-            'display' => 'Postage and Handling $3.00'
-        );
-        $e[] = array(
-            'type'    => 'text',
-            'req'     => false,
-            'name'    => 'total_price',
-            'display' => 'Total Price',
-            'opts'    => array('id' => 'passport_total')
+            'display' => '</label><table role="grid">'
+            . '<tr><td>Postage and Handling</td><td><input type="text" readonly value="3" style="width: 50px;"></td></tr>'
+            . '<tr><td>Total Price</td><td><input type="text" id="passport_total" name="total_price" readonly value="0" style="width: 50px;"></td></tr>'
+            . '</table></label>'
         );
 
         if ($this->hasAuthNetAcc) {
@@ -383,17 +384,6 @@ class Toolkit_Contacts_PassPort
             'reset'      => true,
             'force'      => false
         );
-        /*
-        $r[] = array(
-            'element'    => 'state',
-            'message'    => 'ERROR: Invalid State!',
-            'type'       => 'numeric',
-            'format'     => null,
-            'validation' => $this->validationType,
-            'reset'      => true,
-            'force'      => false
-        );
-        */
         $r[] = array(
             'element'    => 'phone',
             'message'    => 'ERROR: Invalid number (xxx) xxx-xxxx!',
@@ -412,17 +402,6 @@ class Toolkit_Contacts_PassPort
             'reset'      => true,
             'force'      => false
         );
-        /*
-        $r[] = array(
-            'element'    => 'zip',
-            'message'    => 'ERROR: Invalid Zip!',
-            'type'       => 'zip',
-            'format'     => array('requireDBCheck' => false),
-            'validation' => $this->validationType,
-            'reset'      => true,
-            'force'      => false
-        );
-        */
         $r[] = array(
             'element'    => 'mail_ok',
             'message'    => 'ERROR: Invalid Value!',
@@ -460,6 +439,15 @@ class Toolkit_Contacts_PassPort
                 'reset'      => false,
                 'force'      => false
             );
+            $r[] = array(
+                'element'    => 'cc_exp',
+                'message'    => 'ERROR: Card has expired!',
+                'type'       => 'callback',
+                'format'     => array(&$this, 'checkExpireDate'),
+                'validation' => $this->validationType,
+                'reset'      => false,
+                'force'      => false
+            );
         }
 
         $this->setupRules($r);
@@ -546,6 +534,18 @@ class Toolkit_Contacts_PassPort
     }
 
     //    }}}
+    public function checkExpireDate($value)
+    {
+        $month = filter_var($value['m'], FILTER_VALIDATE_INT);
+        $year  = filter_var($value['Y'], FILTER_VALIDATE_INT);
+        if (!($month && $year)) {
+            return false;
+        }
+        $firstDay = mktime(0, 0, 0, $month, 1, $year);
+        $lastDay  = mktime(0, 0, 0, $month, date('t', $firstDay), $year);
+        $today    = mktime(0, 0, 0, date('m'), date('d'), date('Y'));
+        return ($today < $lastDay);
+    }
     //    {{{    checkNumber()
 
     /**
@@ -571,4 +571,173 @@ class Toolkit_Contacts_PassPort
     }
 
     //    }}}
+    //    {{{    processAuthNet()
+
+    /**
+     * Send payment to auth.net
+     *
+     * Test Cards
+     * Card Number      Card Type
+     * ===============  ===============
+     * 370000000000002  American Express
+     * 6011000000000012 Discover Card
+     * 5424000000000015 MasterCard
+     * 4000000000000000 Visa
+     *
+     * @param array $values Submitted values from the form
+     *
+     * @return array Auth.net response
+     * @access protected
+     */
+    protected function processAuthNet($values)
+    {
+        $authNetLoginId = AUTH_LOGIN;
+        $authNetTranKey = AUTH_TRAN_KEY;
+        $authNetUrl     = "https://secure.authorize.net/gateway/transact.dll";
+
+        $authNetValues = array(
+            'x_login'          => $authNetLoginId,
+            'x_version'        => '3.1',
+            'x_delim_char'     => '|',
+            'x_delim_data'     => 'TRUE',
+            'x_type'           => 'AUTH_CAPTURE',
+            'x_method'         => 'CC',
+            "x_test_request"   => DEVELOPMENT ? "TRUE" : "FALSE",
+            'x_tran_key'       => $authNetTranKey,
+            'x_relay_response' => 'FALSE',
+            'x_card_num'       => $values['cc_num'],
+            'x_exp_date'       => implode('/', $values['cc_exp']),
+            'x_amount'         => $values['total_price'],
+            'x_first_name'     => $values['fname'],
+            'x_last_name'      => $values['lname'],
+        );
+
+        $fields = '';
+        foreach ($authNetValues as $i => $j) {
+            $fields .= "$i=" . urlencode($j) . '&';
+        }
+
+        $ch = curl_init($authNetUrl);
+        //    set to 0 to elimindate header info from response
+        curl_setopt($ch, CURLOPT_HEADER, 0);
+        //    Returns response data instead of TRUE(1)
+        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
+        //    Use HTTP POST to send form data
+            curl_setopt($ch, CURLOPT_POSTFIELDS, rtrim($fields, "& "));
+        //    Uncomment this line if you get no gateway response. ###
+        //    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
+        //    Execute post and get results
+        $resp = curl_exec($ch);
+        curl_close($ch);
+
+        $res = explode('|', $resp);
+        return $res;
+    }
+
+    //    }}}
+    public function processData($values)
+    {
+        $res = parent::processData($values);
+        if ($res) {
+            $res2 = $this->processAuthNet($values);
+//            echo '<pre>'.print_r($res2, true).'</pre>';exit;
+            if (is_array($res2) && !empty($res2)) {
+                if ($res2[0] == 1) {
+                    //    CC was Accepted.
+                    return true;
+                } elseif ($res2[0] == 2) {
+                    //    CC was Declined.
+                    return 2;
+                } else {
+                    //    There was a CC processing error.
+                    return $res2[0];
+                }
+            } else {
+                //    There was a CC processing error.
+                return false;
+            }
+        }
+        echo '<pre>'.print_r($res, true).'</pre>';
+        echo '<pre>'.print_r($values, true).'</pre>';
+        exit;
+
+    }
+
+    /**
+     * Handles how to display the current step the user is at in the form
+     *
+     * destroying and resetting the captcha value dis-allows someone from
+     * re-sending a form on a previous captcha.
+     *
+     * @return string form HTML state
+     * @access public
+     */
+    public function toHtml()
+    {
+        if ($this->validate()) {
+            $res = $this->process(
+                array(&$this, 'processData'),
+                $this->mergeFiles
+            );
+            if ($res === true) {
+                $this->cleanForm();
+                $this->freeze();
+                $this->emailOwner();
+                if (method_exists($this, 'confirmation')) {
+                    $this->confirmation();
+                }
+                $output = $this->successMsg;
+                $rem = array(
+                    'cc_cvv',
+                    'cc_type',
+                    'captcha_question',
+                );
+                foreach ($rem as $i) {
+                    if ($this->elementExists($i)) {
+                        $this->removeElement($i);
+                    }
+                }
+
+                if ($this->elementExists('cc_num')) {
+                    //    Obscure th CC Num so its not displayed.
+                    $e = $this->getElement('cc_num');
+                    $ccNum = $e->getValue();
+                    $newCCNum = preg_replace(
+                        '/\d/',
+                        '*',
+                        $ccNum,
+                        strlen($ccNum) - 4
+                    );
+                    $e->setValue($newCCNum);
+                }
+            } elseif ($res == 2) {
+                $this->_errors['cc_num'] = 'ERROR: Your credit card has been declined!';
+                $this->captchaQuestion->destroy();
+                $this->captchaAnswer->setValue('');
+                $this->setupRenderers();
+                $output  = $this->errorMsg;
+                $output .= $this->template->bufferedOutputObject($this->view);
+            } else {
+                $this->_errors['cc_num'] = 'ERROR: There was an error processing your credit card!';
+                $this->captchaQuestion->destroy();
+                $this->captchaAnswer->setValue('');
+                $this->setupRenderers();
+                $output  = $this->errorMsg;
+                $output .= $this->template->bufferedOutputObject($this->view);
+            }
+            $this->sent = true;
+        } elseif ($this->isSubmitted()) {
+            $this->captchaQuestion->destroy();
+            $this->captchaAnswer->setValue('');
+            $this->setupRenderers();
+            $output  = $this->errorMsg;
+            $output .= $this->template->bufferedOutputObject($this->view);
+        } else {
+            $this->captchaQuestion->destroy();
+            $this->captchaAnswer->setValue('');
+            $this->setupRenderers();
+            $output .= $this->template->bufferedOutputObject($this->view);
+        }
+        return $output;
+    }
 }
index b55572d..3cd416d 100644 (file)
@@ -132,8 +132,9 @@ class Toolkit_Contacts_VacationPlanner
     public function configureConstants()
     {
         $constants = array(
-            'user_agent' => $_SERVER['HTTP_USER_AGENT'],
-            'remote_addr' => $_SERVER['REMOTE_ADDR']
+            'user_agent'  => $_SERVER['HTTP_USER_AGENT'],
+            'remote_addr' => $_SERVER['REMOTE_ADDR'],
+            'mail_ok'     => 1
         );
         $this->setupConstants($constants);
     }
index da3e1bb..60f03df 100644 (file)
@@ -30,7 +30,6 @@
                         {elem.html:h}
                         {if:elem.error}<small class="error">{elem.error}</small>{end:}
                         </label>
-
                     {else:}
                         {if:elem.isType(#CAPTCHA_Image#)}
                             {if:elem.required}<label><span class="req">*</span>{else:}<label class="req glmCaptchaImg">{end:}
@@ -52,7 +51,7 @@
                                     <label>{elem.label:h}</label>
                                 {end:}
                                 {foreach:elem.elements,gitem}
-                                {gitem.html:h}
+                                    {gitem.html:h}
                                     {if:gitem.required}<div class="req">*</div>{end:}
                                     <?php
                                     preg_match('%id="(.*)"%', $gitem->html, $matches);
                                 {if:elem.error}<small class="error">{elem.error}</small>{end:}
                             {else:}
                                 {if:elem.required}
+                                    {if:elem.isType(#date#)}
+                                    <label class="req"><span class="req">*</span></label>{elem.label:h}{elem.html:h}
+                                    {else:}
                                     <label class="req"><span class="req">*</span>{elem.label:h}{elem.html:h}</label>
+                                    {end:}
                                 {else:}
                                     {if:elem.isType(#checkbox#)}
                                         {elem.label:h}{elem.html:h}
index 6a9a9c2..4a506b6 100644 (file)
@@ -8,8 +8,13 @@ function setPassportPrice(){
     $('#passport_total').val(PassportForm.passport_total);
 }
 function getTotalPrice(){
-    PassportForm.passport_total
-        = PassportForm.pass_type * PassportForm.qty;
+    if (PassportForm.qty == 0) {
+        PassportForm.passport_total = 0;
+    } else {
+        PassportForm.passport_total
+            = (PassportForm.pass_type * PassportForm.qty) + 3;
+    }
+
 }
 $(document).ready(function () {
     var pass_type = $('input[name="pass_type"]');