Last active
December 31, 2015 19:39
-
-
Save ksnider/8035184 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // Connect to Infusionsoft | |
| require_once("isdk.php"); | |
| $app = new iSDK; | |
| $app->cfgCon("connectionName"); | |
| // Get ContactID and email from POST variable | |
| $contactId = $_POST['contactId']; | |
| $email = $_POST['email']; | |
| // Create your own test contact and hard code here when testing. be sure to comment out | |
| // the two $POST variables above. These are either-or. | |
| //$contactId = 18853; | |
| //$email = '[email protected]'; | |
| // webinar dates | |
| $webinar1 = date_create("2013-12-19 16:30:00",timezone_open("America/New_York")); | |
| $webinar2 = date_create("2014-01-02 16:30:00",timezone_open("America/New_York")); | |
| $webinar3 = date_create("2014-01-16 16:30:00",timezone_open("America/New_York")); | |
| $webinar4 = date_create("2014-01-30 16:30:00",timezone_open("America/New_York")); | |
| // PlusThis POST URLs | |
| $ptPostURL1 = "https://my.plusthis.com/p/453f41ecdd84897c3d8dc5cbb838e7178f1d44e9"; | |
| $ptPostURL2 = "https://my.plusthis.com/p/6778c0aab7be2cc5532db5a9fd1d6f0c5dd54877"; | |
| $ptPostURL3 = "https://my.plusthis.com/p/64d66947de48cfd28f4b2c7b83faac1e8ae599a4"; | |
| $ptPostURL4 = "https://my.plusthis.com/p/aeee0fa60586364b408dacf377ff24eb137daa0a"; | |
| // NOTE: Do not forget to set up the bitly link to the handout in the | |
| //format http://bit.ly/exis-YYYYMMDD | |
| // Add webinars to a 1 based array | |
| $webinar = array(1 => $webinar1, $webinar2, $webinar3, $webinar4); | |
| $count = 1; | |
| // Add Post URLs to a 1 based array | |
| $ptPostURL = array(1 => $ptPostURL1, $ptPostURL2, $ptPostURL3, $ptPostURL4); | |
| $count = 1; | |
| // Loop through the webinar dates | |
| foreach ($webinar as &$value) { | |
| // If this is first webinar in array, set previous equal to first webinar | |
| if($count > 1) | |
| $previousDate = $webinar[$count-1]; | |
| else | |
| $previousDate = $webinar[1]; | |
| // Compare today's date to the current webinar date | |
| // If today is before this webinar, this is the next webinar | |
| if(new DateTime() < $value) { | |
| // Assign date values, the PlusThis URL and archive URL | |
| $tagDate = date_format($value, 'Ymd'); // 20131220 Event Registered | |
| $dateOnly = date_format($value, "Y-m-d\TH:i:s"); // 2013-12-20T16:30:00 | |
| $humanDate = date_format($value, "F jS"); // December 20th | |
| $humanTime = date_format($value, "g:i A T"); // returns 4:30 EST | |
| $previous = date_format($previousDate, "Y-m-d\TH:i:s"); // 2013-12-19T16:30:00 | |
| $archiveDate = date_format($previousDate, 'Ymd'); // 20131219 | |
| $plusThis = $ptPostURL[$count]; | |
| $archive ='http://trainandsimple.com/'.$archiveDate. '-extending-infusionsoft-webinar-archive/'; | |
| $handout = 'http://bit.ly/exis-'.$tagDate; // This is new since the webinar. | |
| // Find the ID of the Event Registered tag for this date | |
| $returnFields = array('Id'); | |
| $query = array('GroupCategoryId' => 31, | |
| 'GroupName' => $tagDate.'%'); | |
| $return = $app->dsQuery("ContactGroup",10,0,$query,$returnFields); | |
| // If a matching tag doesn't exist already ... | |
| if(!isset($return[0]['Id'])) { | |
| //Create the tag | |
| $tag = array('GroupName' => $tagDate.' Extending IS', | |
| 'GroupCategoryId' => 33); | |
| $theTag = $app->dsAdd("ContactGroup", $tag); | |
| // If it does exist ... | |
| } else { | |
| // Grab that tag's ID so we can use it | |
| $theTag = $return[0]['Id']; | |
| } | |
| // Whether we found it or created it, now we set it | |
| $set = $app->grpAssign($contactId, $theTag); | |
| // After all this gets set, break out of this loop | |
| break; | |
| } | |
| $count++; // This increments the counter for the loop by one | |
| } | |
| unset($value); | |
| echo $previous; | |
| // Set Upcoming Webinar Date Only, Webinare Time, Human Date and PlusThis URL for this webinar and Archive Page URL and Previous Date for the last webinar | |
| // Note, these are my custom field names. Yours will most likly be different. | |
| // Also remember to preceed all custom fields with a _ | |
| $new = array('_NextWebinarDate' => $dateOnly, | |
| '_Yourwebinardatehumanform' => $humanDate, | |
| '_Yourwebinaretime' => $humanTime, | |
| '_ThisWebinarDateOnly' => $previous, | |
| '_PlusThisPOSTURL' => $plusThis, | |
| '_ArchivePage' => $archive, | |
| '_LinkToHandout' => $handout); // This dynamically sets the link to the handout | |
| $update = $app->dsUpdate("Contact", $contactId, $new); | |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note: This has been revised since the webinar to create a new tag when one is not found that matches and make the link to the handout in the 1 hour reminder email dynamic so I don't have to touch that email template each time.