8 $app = Dataface_Application::getInstance();
9 $query = $app->getQuery();
11 if ( @$_POST[
'--opt-in'] ){
14 $this->
optIn(@$_POST[
'--email-id']);
17 }
else if ( @$_POST[
'--opt-out'] ){
19 $this->
optOut(@$_POST[
'--email-id']);
26 $mod = Dataface_ModuleTool::getInstance()->loadModule(
'modules_Email');
28 Dataface_JavascriptTool::getInstance()->import(
'xataface/modules/Email/email_opt_out.js');
30 if ( !@$query[
'email'] or !$addr){
32 df_display(array(),
'xataface/modules/email/email_opt_out_error.html');
35 $context = array(
'emailId'=>$query[
'email'],
'emailAddress'=> $addr);
39 $context[
'currentlyBlackListed'] = 1;
42 $context[
'currentlyBlackListed'] = 0;
44 df_display($context,
'xataface/modules/email/email_opt_out.html');
59 df_q(
"delete from dataface__email_blacklist where email='".addslashes($addr).
"'");
60 $app = Dataface_Application::getInstance();
61 $del = $app->getDelegate();
62 $method =
'Email__afterOptIn';
63 if ( isset($del) and method_exists($del, $method) ){
68 'message' =>
'Opt-in successful. Thank you for your participation.'
71 throw new Exception(
'You have already opted into our mail list and should be able to receive our mailouts.', self::ADDRESS_NOT_FOUND);
76 }
catch (Exception $ex){
78 if ( $ex->getCode() > 8000 and $ex->getCode() < 9000 ){
80 'code' => intval($ex->getCode()-8000),
81 'message' => $ex->getMessage()
91 error_log(
"Opting out $emailId");
95 df_q(
"insert into dataface__email_blacklist (email) values ('".addslashes($addr).
"')");
96 $app = Dataface_Application::getInstance();
97 $del = $app->getDelegate();
98 $method =
'Email__afterOptOut';
99 if ( isset($del) and method_exists($del, $method) ){
100 $del->$method($addr);
104 'message' =>
'Opt-out successful. You will no longer receive emails from us.'
107 throw new Exception(
'You have already opted out. You should no longer receive any email from us.', self::ADDRESS_ALREADY_FOUND);
112 }
catch (Exception $ex){
114 if ( $ex->getCode() > 8000 and $ex->getCode() < 9000 ){
116 'code' => intval($ex->getCode()-8000),
117 'message' => $ex->getMessage()
126 $res = df_q(
"select recipient_email from xataface__email_log where `uniqid`='".addslashes($emailId).
"'");
127 if ( mysql_num_rows($res) == 0 )
return null;
128 list($addr) = mysql_fetch_row($res);
129 @mysql_free_result($res);
139 $res = df_q(
"select email from dataface__email_blacklist where `email`='".addslashes($addr).
"' limit 1");
140 if ( mysql_num_rows($res) == 0 ){
141 @mysql_free_result($res);
144 @mysql_free_result($res);
151 header(
'Content-type: text/json; charset="'.Dataface_Application::getInstance()->_conf[
'oe'].
'"');
152 echo json_encode($out);