From 77eef82764b2ffc6f50faf6340fde98c8c92ae61 Mon Sep 17 00:00:00 2001 From: Edsel Date: Tue, 30 May 2017 12:50:43 +0530 Subject: [PATCH] Added support for opt out --- proxy/mailing/optout.php | 77 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 74 insertions(+), 3 deletions(-) diff --git a/proxy/mailing/optout.php b/proxy/mailing/optout.php index bedff1d..9b6a88d 100644 --- a/proxy/mailing/optout.php +++ b/proxy/mailing/optout.php @@ -10,10 +10,81 @@ ini_set('include_path', dirname(dirname(__FILE__))); require_once "proxy.php"; -// see if mail open tracking is enabled -if (!$mail_subscription_user_key) civiproxy_http_error("Feature disabled", 405); +// see if mailing optout feature is enabled +if (empty($mail_subscription_user_key)) civiproxy_http_error("Feature disabled", 405); // basic check civiproxy_security_check('mail-optout'); -civiproxy_http_error("Sorry, opt-out not yet implemented", 405); +// basic restraints +$valid_parameters = array( 'jid' => 'int', + 'qid' => 'int', + 'h' => 'hex'); +$parameters = civiproxy_get_parameters($valid_parameters); + +// check if parameters specified +if (empty($parameters['jid'])) civiproxy_http_error("Missing/invalid parameter 'jid'."); +if (empty($parameters['qid'])) civiproxy_http_error("Missing/invalid parameter 'qid'."); +if (empty($parameters['h'])) civiproxy_http_error("Missing/invalid parameter 'h'."); + +// PERFORM OPT OUT +$group_query = civicrm_api3('MailingEventUnsubscribe', 'create', + array( 'job_id' => $parameters['jid'], + 'event_queue_id' => $parameters['qid'], + 'hash' => $parameters['h'], + 'org_unsubscribe'=> TRUE, + 'api_key' => $mail_subscription_user_key, + )); +if (!empty($group_query['is_error'])) { + civiproxy_http_error($group_query['error_message'], 500); +} +?> + + + + + + + CiviProxy Version <?php echo $civiproxy_version;?> + + + + +
+
+ +
+
+

Thank you. You have been successfully opted out of all mailings. +

+
+ + \ No newline at end of file