Advertisement
darrenscrawford

OAP Days Between

Aug 13th, 2013
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. <?php
  2. /*
  3. Days Between Date Events
  4.  
  5. Get the variables from the URL
  6. $contact_id (oap contact id)
  7. $date_a (first event date)
  8. $date_b (last event date)
  9.  
  10. date1 = YYYY-MM-DD
  11.  
  12. Calculate the number of calendar days between events.
  13.  
  14. Setup your PING URL Like this:
  15. http://yourdomain.com/daysbetween.php?contact_id=[contact_id]&date1=[First Event Date]&date2=[Last Event Date]
  16.  
  17. */
  18.  
  19. //GET variables from URL
  20. $contact_id = $_GET["contact_id"];
  21. $date_a = $_GET["date1"];
  22. $date_b = $_GET["date2"];
  23.  
  24. //String to Time
  25. $date_a = strtotime($date_a);
  26. $date_b = strtotime($date_b);
  27.  
  28. //Do math - difference in time between dates in days
  29. $interval = $date_b - $date_a; //Interval in seconds
  30. $interval = ($interval / 86400); //Interval in days
  31.  
  32. //Pass the interval back to OAP. Change the group and field names as appropriate.
  33. $data = <<<STRING
  34. //You must pass the contact ID as an argument to indicate which contact is being updated
  35. <contact id="$contact_id">
  36. <Group_Tag name="Days Between">
  37. <field name="Added Video 1 Watched">$interval</field>
  38. </Group_Tag>
  39. </contact>
  40. STRING;
  41.  
  42. $data = urlencode(urlencode($data));
  43.  
  44. // Replace the strings with your API credentials located in Admin > OfficeAutoPilot API Instructions and Key Manager
  45. $appid = "XXXX";
  46. $key = "XXXX";
  47.  
  48. $reqType= "update";
  49. $postargs = "appid=".$appid."&key=".$key."&return_id=1&reqType=".$reqType. "&data=" . $data;
  50. $request = "https://api.moon-ray.com/cdata.php";
  51.  
  52. $session = curl_init($request);
  53. curl_setopt ($session, CURLOPT_POST, true);
  54. curl_setopt ($session, CURLOPT_POSTFIELDS, $postargs);
  55. curl_setopt($session, CURLOPT_HEADER, false);
  56. curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
  57. $response = curl_exec($session);
  58. curl_close($session);
  59. header("Content-Type: text/xml");
  60. echo $response;
  61.  
  62.  
  63.  
  64.  
  65. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement