Add new LeadManager for MailChimp
authorSteve Sutton <steve@gaslightmedia.com>
Thu, 27 Jun 2013 15:58:48 +0000 (15:58 +0000)
committerSteve Sutton <steve@gaslightmedia.com>
Thu, 27 Jun 2013 15:58:48 +0000 (15:58 +0000)
Now the admin edit contact form and front contact form extending from
the ContactUs class use MailChimp.

Toolkit/Contacts/Admin/EditContact.php
Toolkit/Contacts/ContactUs.php
Toolkit/LeadManager/MailChimp.php
config/application.ini
example.php [deleted file]
static/5.phtml [new file with mode: 0644]

index 3159c3f..95568c6 100644 (file)
@@ -840,6 +840,10 @@ class Toolkit_Contacts_Admin_EditContact
                 && CONSTANT_CONTACT) {
                 $contact->attach(new Toolkit_LeadManager_ConstantContact());
             }
+            if (    defined('MAILCHIMP_APP')
+                && MAILCHIMP_APP) {
+                $contact->attach(new Toolkit_LeadManager_MailChimp());
+            }
         }
 
         $contact->save($this->dbh, false);
index f07a726..6d6c307 100755 (executable)
@@ -995,6 +995,10 @@ class Toolkit_Contacts_ContactUs
                 && CONSTANT_CONTACT) {
                 $contact->attach(new Toolkit_LeadManager_ConstantContact());
             }
+            if (    defined('MAILCHIMP_APP')
+                && MAILCHIMP_APP) {
+                $contact->attach(new Toolkit_LeadManager_MailChimp());
+            }
         }
         $contact->save($this->dbh, false);
         return true;
index ce6a722..dce8e05 100644 (file)
@@ -56,6 +56,24 @@ class Toolkit_LeadManager_MailChimp
             $values['address_line_1'] = $subject->getAdd1();
             $values['address_line_2'] = $subject->getAdd2();
         }
+
+        $testEmail = 'steve@gaslightmedia.com';
+        $api       = new MCAPI(MAILCHIMP_APIKEY);
+        try {
+            $retVal = $api->listSubscribe(
+                MAILCHIMP_LISTID,
+                $subject->getEmail(),
+                array(
+                    'FNAME' => $subject->getFname(),
+                    'LNAME' => $subject->getLname()
+                )
+            );
+            if ($api->errorCode) {
+                throw new Exception($api->errorMessage, $api->errorCode);
+            }
+        } catch (Exception $e) {
+            Toolkit_Common::handleError($e);
+        }
     }
 
 
index 2175994..54670d2 100644 (file)
@@ -46,9 +46,9 @@ constantcontact.list.0 = Off
 ; MAILCHIMP API
 contactdb.mcapi.application = On
 ; Mailchimp API key
-contactdb.mcapi.apikey = "008fe0f365c71f5ea08aed546da40242-us6"
-; Mailchimp List Id
-contactdb.mcapi.listId = "8ed24143f7"
+contactdb.mcapi.apikey = "4d8c4804158e77b6ee61795f07807c4e-us1"
+; Mailchimp List Id (Michigan TrailMaps.com List)
+contactdb.mcapi.listId = "b919fdbef4"
 
 ; Turn the coupon application On or Off
 coupons.application = Off
diff --git a/example.php b/example.php
deleted file mode 100644 (file)
index 3be8a28..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-<?php
-require_once 'setup.phtml';
-require_once GLM_APP_BASE . 'Common/LeadManager/Affiliates/MCAPI.class.php';
-$testEmail = 'steve@gaslightmedia.com';
-//var_dump(MAILCHIMP_APIKEY);
-//var_dump(MAILCHIMP_APP);
-//var_dump(MAILCHIMP_LISTID);
-//var_dump($testEmail);
-//exit;
-$api = new MCAPI(MAILCHIMP_APIKEY);
-
-// get lists
-$ret = $api->lists();
-echo print_r($ret);
-exit;
-$mergVars = array(
-    'FNAME' => 'Test',
-    'LNAME' => 'Account',
-//    'GROUPINGS' => array(
-//        array('name' => 'Your Interests:', 'groups'=>'Bananas,Apples')
-//    )
-);
-$retVal = $api->listSubscribe(MAILCHIMP_LISTID, $testEmail, $mergVars);
-
-if ($api->errorCode) {
-    echo "Unable to load listSubscribe()!\n";
-    echo "\tCode=" . $api->errorCode. "\n";
-    echo "\tMsg=" . $api->errorMessage. "\n";
-} else {
-    echo "Subscribed - look for the confirmation email!\n";
-}
-
diff --git a/static/5.phtml b/static/5.phtml
new file mode 100644 (file)
index 0000000..705e836
--- /dev/null
@@ -0,0 +1,12 @@
+<?php
+if ($catid = filter_input(INPUT_GET, 'catid', FILTER_VALIDATE_INT)) {
+       $cf = new Toolkit_Contacts_ContactUs(
+               Toolkit_Database::getInstance(),
+               'contact_form',
+               'post',
+               BASE_URL . "index.php?catid=$catid"
+       );
+       $cf->configureForm();
+       $cf->useCaptcha(true);
+       echo $cf->toHtml();
+}