if ($mode == 'add_subscriber') { if (empty($_REQUEST['subscribe_email']) || fn_validate_email($_REQUEST['subscribe_email']) == false) { fn_set_notification('E', __('error'), __('error_invalid_emails', array('[emails]' => $_REQUEST['subscribe_email']))); } else { // First check if subscriber's email already in the list $subscriber = db_get_row("SELECT * FROM ?:subscribers WHERE email = ?s", $_REQUEST['subscribe_email']); if (empty($subscriber)) { $_data = array('email' => $_REQUEST['subscribe_email'], 'timestamp' => TIME); $subscriber_id = db_query("INSERT INTO ?:subscribers ?e", $_data); $subscriber = db_get_row("SELECT * FROM ?:subscribers WHERE subscriber_id = ?i", $subscriber_id); } else { $subscriber_id = $subscriber['subscriber_id']; } // update subscription data. If there is no any registration autoresponders, we set confirmed=1 // so user doesn't need to activate subscription list($lists) = fn_get_mailing_lists(); fn_update_subscriptions($subscriber_id, array_keys($lists), NULL, fn_get_notification_rules(true)); fn_set_notification('N', __('congratulations'), __('text_subscriber_added')); fn_emails_provide_coupon(); /*} else { fn_set_notification('E', __('error'), __('error_email_already_subscribed')); }*/ } } return array(CONTROLLER_STATUS_REDIRECT); } if ($mode == 'unsubscribe') { if (!empty($_REQUEST['key']) && !empty($_REQUEST['list_id']) && !empty($_REQUEST['s_id'])) { if (!empty($_REQUEST['list_id'])) { $num = db_get_field("SELECT COUNT(*) FROM ?:user_mailing_lists WHERE unsubscribe_key = ?s AND list_id = ?i AND subscriber_id = ?i", $_REQUEST['key'], $_REQUEST['list_id'], $_REQUEST['s_id']); if (!empty($num)) {
/** * Save user mailing lists settings. * * @param int $subscriber_id * @param array $user_list_ids * @param mixed $confirmed - if passed, subscription status set to passed value, if null, depends on autoresponder * @param boolean $notify * @param string $lang_code */ function fn_update_subscriptions($subscriber_id, $user_list_ids = array(), $confirmed = NULL, $force_notification = array(), $lang_code = CART_LANGUAGE) { if (!empty($user_list_ids)) { list($lists) = fn_get_mailing_lists(); $subscriber = db_get_row("SELECT * FROM ?:subscribers WHERE subscriber_id = ?i", $subscriber_id); // to prevent user from subscribing to hidden and disabled mailing lists by manual link edit if (AREA != 'A') { foreach ($user_list_ids as $k => $l_id) { if ($lists[$l_id]['status'] != 'A') { unset($user_list_ids[$k]); } } } foreach ($user_list_ids as $list_id) { $subscribed = db_get_array("SELECT confirmed FROM ?:user_mailing_lists WHERE subscriber_id = ?i AND list_id = ?i", $subscriber_id, $list_id); $already_confirmed = !empty($subscribed['confirmed']) ? true : false; $already_subscribed = !empty($subscribed) ? true : false; if ($already_confirmed) { $_confirmed = 1; } else { if (is_array($confirmed)) { $_confirmed = !empty($confirmed[$list_id]['confirmed']) ? $confirmed[$list_id]['confirmed'] : 0; } else { $_confirmed = !empty($lists[$list_id]['register_autoresponder']) ? 0 : 1; } } if ($already_subscribed && $already_confirmed == $_confirmed) { continue; } $_data = array('subscriber_id' => $subscriber_id, 'list_id' => $list_id, 'activation_key' => md5(uniqid(rand())), 'unsubscribe_key' => md5(uniqid(rand())), 'email' => $subscriber['email'], 'timestamp' => TIME, 'lang_code' => $lang_code, 'confirmed' => $_confirmed); db_query("REPLACE INTO ?:user_mailing_lists ?e", $_data); // send confirmation email for each mailing list if (empty($_confirmed)) { fn_send_confirmation_email($subscriber_id, $list_id, $subscriber['email'], $lang_code); } } } // Delete unchecked mailing lists if (!empty($user_list_ids)) { $lists_to_delete = db_get_field("SELECT list_id FROM ?:user_mailing_lists WHERE subscriber_id = ?i AND list_id NOT IN (?n)", $subscriber_id, $user_list_ids); if (!empty($lists_to_delete)) { db_query("DELETE FROM ?:user_mailing_lists WHERE subscriber_id = ?i AND list_id IN (?n)", $subscriber_id, $lists_to_delete); // Delete subscriber in the frontend if all lists are unchecked if (AREA == 'C') { $c = db_get_field("SELECT COUNT(*) FROM ?:user_mailing_lists WHERE subscriber_id = ?i", $subscriber_id); if (empty($c)) { db_query("DELETE FROM ?:subscribers WHERE subscriber_id = ?i", $subscriber_id); } } } // Delete subscriber in the frontend area if all lists are unchecked } else { fn_delete_subscribers(array($subscriber_id), AREA == 'C'); } }
if ($_SERVER['REQUEST_METHOD'] == "POST") { if ($mode == 'place_order' || $mode == 'subscribe_customer') { $subscriber = db_get_row("SELECT * FROM ?:subscribers WHERE email = ?s", $_SESSION['cart']['user_data']['email']); if (!empty($_REQUEST['mailing_lists']) && !fn_is_empty($_REQUEST['mailing_lists'])) { if (empty($subscriber)) { $_data = array('email' => $_SESSION['cart']['user_data']['email'], 'timestamp' => TIME); $subscriber_id = db_query("INSERT INTO ?:subscribers ?e", $_data); } else { $subscriber_id = $subscriber['subscriber_id']; } fn_update_subscriptions($subscriber_id, $_REQUEST['mailing_lists'], NULL, fn_get_notification_rules(true)); } elseif (isset($_REQUEST['mailing_lists'])) { if (!empty($subscriber)) { fn_delete_subscribers($subscriber['subscriber_id']); } } } if ($mode == 'subscribe_customer') { return array(CONTROLLER_STATUS_REDIRECT, 'onestepcheckout.checkout'); } } if ($mode == 'checkout') { $email = db_get_field("SELECT email FROM ?:users WHERE user_id = ?i", $_SESSION['auth']['user_id']); if ((empty($email) || $_SESSION['auth']['user_id'] == 0) && !empty($_SESSION['cart']['user_data']['email'])) { $email = $_SESSION['cart']['user_data']['email']; } $mailing_lists = db_get_hash_array("SELECT * FROM ?:subscribers INNER JOIN ?:user_mailing_lists ON ?:subscribers.subscriber_id = ?:user_mailing_lists.subscriber_id WHERE ?:subscribers.email = ?s", 'list_id', $email); Registry::get('view')->assign('user_mailing_lists', $mailing_lists); list($page_mailing_lists) = fn_get_mailing_lists(); Registry::get('view')->assign('page_mailing_lists', $page_mailing_lists); }
if (empty($_mailing_lists)) { Registry::get('view')->display('addons/news_and_emails/views/mailing_lists/manage.tpl'); } } exit; } return array(CONTROLLER_STATUS_OK, 'mailing_lists.manage'); } if ($mode == 'update') { list($autoresponders) = fn_get_newsletters(array('type' => NEWSLETTER_TYPE_AUTORESPONDER, 'only_available' => false), 0, DESCR_SL); Registry::get('view')->assign('autoresponders', $autoresponders); Registry::get('view')->assign('mailing_list', fn_get_mailing_list_data($_REQUEST['list_id'], DESCR_SL)); } elseif ($mode == 'manage') { $params = $_REQUEST; $params['only_available'] = false; list($mailing_lists) = fn_get_mailing_lists($params, 0, DESCR_SL); $subscribers = db_get_hash_array("SELECT * FROM ?:subscribers", 'subscriber_id'); foreach ($mailing_lists as &$list) { $list['subscribers_num'] = db_get_field("SELECT COUNT(*) FROM ?:user_mailing_lists WHERE list_id = ?i", $list['list_id']); } list($autoresponders) = fn_get_newsletters(array('type' => NEWSLETTER_TYPE_AUTORESPONDER, 'only_available' => false), 0, DESCR_SL); Registry::get('view')->assign('mailing_lists', $mailing_lists); Registry::get('view')->assign('autoresponders', $autoresponders); Registry::get('view')->assign('subscribers', $subscribers); fn_newsletters_generate_sections('mailing_lists'); } function fn_update_mailing_list($mailing_list_data, $list_id, $lang_code = DESCR_SL) { if (empty($list_id)) { $list_id = db_query("INSERT INTO ?:mailing_lists ?e", $mailing_list_data); $_data = $mailing_list_data;
} return array(CONTROLLER_STATUS_OK, "mailing_lists.manage"); } if ($mode == 'update') { fn_add_breadcrumb(fn_get_lang_var('newsletters'), "newsletters.manage"); $view->assign('autoresponders', fn_get_newsletters(array('type' => NEWSLETTER_TYPE_AUTORESPONDER, 'only_available' => false), DESCR_SL)); $view->assign('mailing_list', fn_get_mailing_list_data($_REQUEST['list_id'], DESCR_SL)); } elseif ($mode == 'delete') { if (!empty($_REQUEST['list_id'])) { db_query("DELETE FROM ?:common_descriptions WHERE object_id = ?i AND object_holder='mailing_lists'", $_REQUEST['list_id']); db_query("DELETE FROM ?:mailing_lists WHERE list_id = ?i", $_REQUEST['list_id']); db_query("DELETE FROM ?:user_mailing_lists WHERE list_id = ?i", $_REQUEST['list_id']); $_mailing_lists = fn_get_mailing_lists(array('only_available' => false, 'limit' => $limit), DESCR_SL); if (empty($_mailing_lists)) { $view->display('addons/news_and_emails/views/mailing_lists/manage.tpl'); } } exit; } elseif ($mode == 'manage') { $total_pages = db_get_field("SELECT COUNT(*) FROM ?:mailing_lists"); $limit = fn_paginate(@$_REQUEST['page'], $total_pages, Registry::get('settings.Appearance.admin_elements_per_page')); $mailing_lists = fn_get_mailing_lists(array('only_available' => false, 'limit' => $limit), DESCR_SL); $subscribers = db_get_hash_array("SELECT * FROM ?:subscribers", 'subscriber_id'); foreach ($mailing_lists as &$list) { $list['subscribers_num'] = db_get_field("SELECT COUNT(*) FROM ?:user_mailing_lists WHERE list_id={$list['list_id']}"); } $view->assign('mailing_lists', $mailing_lists); $view->assign('autoresponders', fn_get_newsletters(array('type' => NEWSLETTER_TYPE_AUTORESPONDER, 'only_available' => false), DESCR_SL)); $view->assign('subscribers', $subscribers); } /** /Body **/
die('Access denied'); } if ($_SERVER['REQUEST_METHOD'] == "POST") { if ($mode == 'customer_info' || $mode == 'update_steps' && isset($_REQUEST['update_step']) && $_REQUEST['update_step'] == 'step_one' || $mode == 'add_profile') { $subscriber = db_get_row("SELECT * FROM ?:subscribers WHERE email = ?s", $_REQUEST['user_data']['email']); if (!empty($_REQUEST['mailing_lists']) && !fn_is_empty($_REQUEST['mailing_lists'])) { if (empty($subscriber)) { $_data = array('email' => $_REQUEST['user_data']['email'], 'timestamp' => TIME); $subscriber_id = db_query("INSERT INTO ?:subscribers ?e", $_data); } else { $subscriber_id = $subscriber['subscriber_id']; } fn_update_subscriptions($subscriber_id, $_REQUEST['mailing_lists'], $_REQUEST['newsletter_format'], NEWSLETTER_SAVE_UNCHECKED, NULL, fn_get_notification_rules(true)); } else { if (!empty($subscriber)) { fn_delete_subscribers($subscriber['subscriber_id']); } } } return true; } if ($mode == 'checkout' || $mode == 'customer_info') { $view->assign('page_mailing_lists', fn_get_mailing_lists(array('checkout' => true))); $email = db_get_field("SELECT email FROM ?:users WHERE user_id = ?i", $_SESSION['auth']['user_id']); $mailing_lists = db_get_hash_array("SELECT * FROM ?:subscribers INNER JOIN ?:user_mailing_lists ON ?:subscribers.subscriber_id = ?:user_mailing_lists.subscriber_id WHERE ?:subscribers.email = ?s", 'list_id', $email); $view->assign('user_mailing_lists', $mailing_lists); // on customer info page we show only one "format" selectbox. so we take active format from // first active newsletter from this user. $first = array_shift($mailing_lists); $view->assign('newsletter_format', $first['format']); }
/** * Save user mailing lists settings. * * @param int $subscriber_id * @param array $user_lists_ids * @param int $format - newsletters format for that user * @param int $mode - updating mode for $user_lists_ids. We need this to disable unchecked mailing lists if user disables them on profile, but we don't need that for subscription block (we just subscribe to checked there) * NEWSLETTER_SAVE_UNCHECKED - for sidebar mode * NEWSLETTER_DELETE_UNCHECKED - for user profile mode * NEWSLETTER_ONLY_CHECKED - for admin user picker mode, when all $user_lists_ids are enabled * @param mixed $confirmed - if passed, subscription status set to passed value, if null, depends on autoresponder * @param boolean $notify * @param string $lang_code */ function fn_update_subscriptions($subscriber_id, $user_lists_ids = array(), $format = NEWSLETTER_FORMAT_TXT, $mode = NEWSLETTER_SAVE_UNCHECKED, $confirmed = NULL, $force_notification = array(), $lang_code = CART_LANGUAGE) { $lists = fn_get_mailing_lists(); $subscriber = db_get_row("SELECT * FROM ?:subscribers WHERE subscriber_id = ?i", $subscriber_id); $exising_subscriptions = db_get_fields("SELECT list_id FROM ?:user_mailing_lists WHERE subscriber_id = ?i", $subscriber_id); // to prevent user from subscribing to hidden and disabled mailing lists by manual link edit if (AREA != 'A') { $_statuses = array('D', 'H'); $denied = db_get_fields("SELECT list_id FROM ?:mailing_lists WHERE status in (?a)", 'list_id', $_statuses); foreach ($denied as $denied_list_id) { unset($user_lists_ids[$denied_list_id]); } } $checked_lists_ids = array(); $unchecked_lists_ids = array(); // if array with list ids as values passed if ($mode == NEWSLETTER_ONLY_CHECKED) { $checked_lists_ids = $user_lists_ids; // if array with list_id => enabled pairs passed } else { foreach ((array) $user_lists_ids as $list_id => $enabled) { if ($enabled) { $checked_lists_ids[] = $list_id; } else { $unchecked_lists_ids[] = $list_id; } } } foreach ($checked_lists_ids as $list_id) { $_data = array('subscriber_id' => $subscriber_id, 'list_id' => $list_id, 'activation_key' => md5(uniqid(rand())), 'unsubscribe_key' => md5(uniqid(rand())), 'email' => $subscriber['email'], 'timestamp' => TIME, 'lang_code' => $lang_code, 'confirmed' => $confirmed == NULL ? !empty($lists[$list_id]['register_autoresponder']) ? 0 : 1 : ($confirmed ? 1 : 0), 'format' => intval($format)); db_query("REPLACE INTO ?:user_mailing_lists ?e", $_data); // send confirmation email for each mailing list if (!empty($force_notification['C'])) { fn_send_confirmation_email($subscriber_id, $list_id, $subscriber['email'], $format, $lang_code); } } if ($mode == NEWSLETTER_DELETE_UNCHECKED && !empty($unchecked_lists_ids)) { db_query("DELETE FROM ?:user_mailing_lists WHERE subscriber_id=?i AND list_id IN (?n)", $subscriber_id, $unchecked_lists_ids); $c = db_get_field("SELECT COUNT(*) FROM ?:user_mailing_lists WHERE subscriber_id = ?i", $subscriber_id); if (empty($c)) { db_query("DELETE FROM ?:subscribers WHERE subscriber_id = ?i", $subscriber_id); } } }
<?php /*************************************************************************** * * * Copyright (c) 2004 Simbirsk Technologies Ltd. All rights reserved. * * * * This is commercial software, only users who have purchased a valid * * license and accept to the terms of the License Agreement can install * * and use this program. * * * **************************************************************************** * PLEASE READ THE FULL TEXT OF THE SOFTWARE LICENSE AGREEMENT IN THE * * "copyright.txt" FILE PROVIDED WITH THIS DISTRIBUTION PACKAGE. * ****************************************************************************/ // // $Id: init.post.php 10229 2010-07-27 14:21:39Z 2tl $ // if (!defined('AREA')) { die('Access denied'); } if ($_SERVER['REQUEST_METHOD'] == 'POST') { return; } // // get active mailing lists // $mailing_lists = fn_get_mailing_lists(array('sidebar' => true)); $view->assign('mailing_lists', $mailing_lists);
if ($_SERVER['REQUEST_METHOD'] == "POST") { if ($mode == 'add' || $mode == 'update') { $subscriber = db_get_row("SELECT * FROM ?:subscribers WHERE email = ?s", $_REQUEST['user_data']['email']); if (!empty($_REQUEST['mailing_lists']) && !fn_is_empty($_REQUEST['mailing_lists'])) { if (empty($subscriber)) { $_data = array('email' => $_REQUEST['user_data']['email'], 'timestamp' => TIME); $subscriber_id = db_query("INSERT INTO ?:subscribers ?e", $_data); } else { $subscriber_id = $subscriber['subscriber_id']; } fn_update_subscriptions($subscriber_id, $_REQUEST['mailing_lists'], $_REQUEST['newsletter_format'], NEWSLETTER_DELETE_UNCHECKED, NULL, fn_get_notification_rules(true)); } else { if (!empty($subscriber)) { fn_delete_subscribers($subscriber['subscriber_id']); } } } return; } if ($mode == 'add' || $mode == 'update') { $view->assign('page_mailing_lists', fn_get_mailing_lists(array('registration' => true))); } if ($mode == 'update') { $email = db_get_field("SELECT email FROM ?:users WHERE user_id = ?i", $_SESSION['auth']['user_id']); $mailing_lists = db_get_hash_array("SELECT * FROM ?:subscribers INNER JOIN ?:user_mailing_lists ON ?:subscribers.subscriber_id = ?:user_mailing_lists.subscriber_id WHERE ?:subscribers.email = ?s", 'list_id', $email); $view->assign('user_mailing_lists', $mailing_lists); // on profile page we show only one "format" selectbox. so we take active format from // first active newsletter from this user. $first = array_shift($mailing_lists); $view->assign('newsletter_format', $first['format']); }
$view->assign('newsletter', $newsletter_data); $view->assign('newsletter_templates', fn_get_newsletters(array('type' => NEWSLETTER_TYPE_TEMPLATE, 'only_available' => false), DESCR_SL)); $view->assign('newsletter_type', $newsletter_data['type']); $view->assign('placeholders', $placeholders[$newsletter_data['type']]); $view->assign('mailing_lists', db_get_hash_array("SELECT * FROM ?:mailing_lists m INNER JOIN ?:common_descriptions d ON m.list_id = d.object_id WHERE d.object_holder = 'mailing_lists' AND d.lang_code = ?s", 'list_id', DESCR_SL)); $view->assign('newsletter_users', db_get_fields("SELECT user_id FROM ?:users WHERE user_id IN(?n) ", explode(',', $newsletter_data['users']))); // newsletter creation page } elseif ($mode == 'add') { $newsletter_type = !empty($_REQUEST['type']) ? $_REQUEST['type'] : NEWSLETTER_TYPE_NEWSLETTER; fn_newsletters_breadcrumb($newsletter_type); $campaigns = db_get_array("SELECT * FROM ?:newsletter_campaigns n INNER JOIN ?:common_descriptions d ON n.campaign_id = d.object_id AND d.lang_code = ?s WHERE d.object_holder='newsletter_campaigns'", DESCR_SL); $view->assign('newsletter_campaigns', $campaigns); $view->assign('newsletter_templates', fn_get_newsletters(array('type' => NEWSLETTER_TYPE_TEMPLATE, 'only_available' => false), DESCR_SL)); $view->assign('newsletter_type', $newsletter_type); $view->assign('placeholders', $placeholders[$newsletter_type]); $view->assign('mailing_lists', fn_get_mailing_lists(array('only_available' => false))); // newsletter creation page } elseif ($mode == 'preview_popup') { $view->display('addons/news_and_emails/views/newsletters/components/preview_popup.tpl'); exit; // newsletter manage page } elseif ($mode == 'manage') { // do we list newsletters or templates or autoresponders? $newsletter_type = !empty($_REQUEST['type']) ? $_REQUEST['type'] : NEWSLETTER_TYPE_NEWSLETTER; // Use pagination for a newsletters $params = array(); if ($newsletter_type == NEWSLETTER_TYPE_NEWSLETTER) { $params = array('paginate' => true, 'page' => empty($_REQUEST['page']) ? 1 : $_REQUEST['page']); } $view->assign('newsletter_type', $newsletter_type); $view->assign('newsletters', fn_get_newsletters(fn_array_merge(array('type' => $newsletter_type, 'only_available' => false), $params), DESCR_SL));