function setAttribute($attr, $value) { switch ($attr) { case 'email': $emailExists = eZUserSubscriptionData::fetch($value); if (!$emailExists) { // Fetch the list of subscriptions the user identified by email $subscriptionList = eZSubscription::fetchListByEmail($this->attribute('email'), false, false); foreach ($subscriptionList as $subscription) { $subscription->setAttribute('email', $value); $subscription->sync(); } eZPersistentObject::setAttribute($attr, $value); } break; default: eZPersistentObject::setAttribute($attr, $value); break; } }
if ($emailExists) { $warning = ezpI18n::tr('eznewsletter/modify_subscription', 'The given email address is already in use. Please use another.'); } else { $userData->setAttribute('email', $http->postVariable('Email')); } } if ($http->hasPostVariable('Password1') && $http->postVariable('Password1') != 'password') { if ($http->postVariable('Password1') === $http->postVariable('Password2') && strlen(trim($http->postVariable('Password1'))) > 0) { $userData->setVariable('password', md5($http->postVariable('Password1'))); } else { $warning = ezpI18n::tr('eznewsletter/modify_subscription', 'Password did not match'); } } $userData->sync(); //get new Data inmemory $userData = eZUserSubscriptionData::fetch($http->postVariable('original_email')); } else { //create new $userData = eZUserSubscriptionData::create($http->postVariable('FirstName'), $http->postVariable('Name'), $http->postVariable('Mobile'), $http->postVariable('Email')); //redirect to self if ($userData) { return $Module->redirectTo('/newsletter/modify_subscription/' . $userData->attribute('hash')); } } } if ($Params['hash'] != "") { $userData = eZUserSubscriptionData::fetchByHash($Params['hash']); if (!$userData) { $tpl = eZNewsletterTemplateWrapper::templateInit(); $Result = array(); $Result['left_menu'] = 'design:parts/content/eznewsletter_menu.tpl';
function sendConfirmation($email, $subscription, $subscribe) { //send mail $res = eZTemplateDesignResource::instance(); $ini = eZINI::instance(); $hostname = eZSys::hostname(); if ($subscribe) { $template = 'design:eznewsletter/sendout/subscription.tpl'; } else { $template = 'design:eznewsletter/sendout/unsubscription.tpl'; } $tpl = eZNewsletterTemplateWrapper::templateInit(); $tpl->setVariable('userData', eZUserSubscriptionData::fetch($email)); $tpl->setVariable('hostname', $hostname); $tpl->setVariable('subscription', $subscription); $subscriptionList = eZSubscriptionList::fetch($subscription->attribute('subscriptionlist_id'), eZSubscriptionList::StatusPublished, true, true); $tpl->setVariable('subscriptionList', $subscriptionList); $templateResult = $tpl->fetch($template); if ($tpl->hasVariable('subject')) { $subject = $tpl->variable('subject'); } $mail = new eZMail(); $mail->setSender($ini->variable('MailSettings', 'EmailSender')); $mail->setReceiver($email); $mail->setBody($templateResult); $mail->setSubject($subject); eZMailTransport::send($mail); }
$subscriptionList = eZSubscription::fetchListByEmail($userData->attribute('email'), eZSubscription::VersionStatusPublished, array(array(eZSubscription::StatusPending, eZSubscription::StatusApproved, eZSubscription::StatusConfirmed, eZSubscription::StatusRemovedSelf, eZSubscription::StatusRemovedAdmin))); foreach ($subscriptionList as $subscription) { eZSubscription::removeAll($subscription->Attribute('id')); } eZUserSubscriptionData::removeAll($subscriptionID); } } } if ($http->hasPostVariable('searchString') && trim($http->postVariable('searchString')) != "") { $search = trim(strtolower($http->postVariable('searchString'))); $db = eZDB::instance(); $searchSQL = "SELECT email FROM ezsubscriptionuserdata WHERE LOWER(firstname) LIKE '%" . $db->escapeString($search) . "%' or LOWER(name) LIKE '%" . $db->escapeString($search) . "%' or LOWER(email) LIKE '%" . $db->escapeString($search) . "%' group by email LIMIT 50"; $searchResult = $db->arrayQuery($searchSQL); $subscriberList = array(); foreach ($searchResult as $email) { $subscriberList[] = eZUserSubscriptionData::fetch($email['email']); } $countSQL = "SELECT id FROM ezsubscriptionuserdata WHERE LOWER(firstname) LIKE '%" . $db->escapeString($search) . "%' or LOWER(name) LIKE '%" . $db->escapeString($search) . "%' or LOWER(email) LIKE '%" . $db->escapeString($search) . "%' group by email"; $countResult = $db->arrayQuery($countSQL); $subscriberCount = count($countResult); } $tpl = eZNewsletterTemplateWrapper::templateInit(); if ($http->hasPostVariable('searchString')) { $tpl->setVariable('searchString', $http->postVariable('searchString')); } else { $tpl->setVariable('searchString', ''); } if (isset($subscriberList)) { $tpl->setVariable('subscriberList', $subscriberList); $tpl->setVariable('subscriberCount', $subscriberCount); } else {
function onPublish($attribute, $contentObject, $publishedNodes) { $http = eZHTTPTool::instance(); $userID = $attribute->attribute('contentobject_id'); $data = unserialize($attribute->attribute('data_text')); $avialable = array_merge($data['unregister'], $data['register']); foreach ($avialable as $id) { $subscription = eZSubscription::fetchByUserSubscriptionListID($userID, $id); if (isset($subscription) and $subscription->attribute('status') == eZSubscription::StatusApproved and in_array($id, $data['unregister'])) { $subscription->unsubscribe(); } elseif (isset($subscription) and $subscription->attribute('status') == eZSubscription::StatusRemovedSelf and in_array($id, $data['register'])) { $subscription->setAttribute('status', eZSubscription::StatusApproved); $subscription->sync(); } elseif (!isset($subscription) and in_array($id, $data['register'])) { $list = eZSubscriptionList::fetch($id, eZSubscriptionList::StatusPublished, true, true); if ($list) { $subscription = $list->registerUser($userID); } } if ($subscription) { $version = eZContentObjectVersion::fetchVersion($attribute->attribute('version'), $attribute->attribute('contentobject_id')); $user = eZUser::fetch($attribute->attribute('contentobject_id')); $userData = eZUserSubscriptionData::fetch($user->attribute('email')); $dm = $version->attribute('data_map'); if (!$userData) { $userData = eZUserSubscriptionData::create('', '', '', $user->attribute('email')); } if ($user->attribute('email')) { $userData->updateAttribute('email', $user->attribute('email')); $userData->store(); } if (isset($dm['last_name'])) { $userData->setAttribute('name', $dm['last_name']->attribute('data_text')); $userData->store(); } if (isset($dm['first_name'])) { $userData->setAttribute('firstname', $dm['first_name']->attribute('data_text')); $userData->store(); } if (isset($dm['mobile'])) { $userData->setAttribute('mobile', $dm['mobile']->attribute('data_text')); $userData->store(); } } } $http->removeSessionVariable('register_subscription'); $http->removeSessionVariable('unregister_subscription'); }
function &userData() { $retVal = false; $subscription = eZSubscription::fetch($this->attribute('subscription_id')); if ($subscription) { $userSubscription = eZUserSubscriptionData::fetch($subscription->attribute('email')); if (!$userSubscription) { eZDebug::writeError("User subscription not found for: " . $subscription->attribute('email'), 'eZSendNewsletterItem::userData'); return false; } else { $generic_hash = $userSubscription->attribute('hash'); $retVal = array('firstname' => $subscription->attribute('firstname'), 'name' => $subscription->attribute('name'), 'email' => $subscription->attribute('email'), 'mobile' => $subscription->attribute('mobile'), 'output_format' => $subscription->attribute('output_format'), 'userhash' => $this->attribute('hash'), 'generic_userhash' => $generic_hash); } } return $retVal; }
static function create($subscriptionListID, $firstname = '', $name = '', $mobile = '', $email = '', $userID = false) { if (!isset($subscriptionListID)) { return false; } $rows = array('created' => time(), 'creator_id' => eZUser::currentUserID(), 'hash' => md5(mt_rand() . '-' . mt_rand()), 'mobile' => $mobile, 'email' => $email, 'subscriptionlist_id' => $subscriptionListID, 'status' => eZSubscription::VersionStatusDraft); if ($userID !== false) { $rows['user_id'] = $userID; } else { $userData = eZUserSubscriptionData::fetch($email); if (!$userData && $email) { eZUserSubscriptionData::create($firstname, $name, $mobile, $email); } } $subscription = new eZSubscription($rows); $subscription->store(); return $subscription; }