<?php 
// Set flag that this is a parent file
	define( '_FEXEC', 1 );

/*osCommerce, Open Source E-Commerce Solutions http://www.oscommerce.com Copyright (c) 2003 osCommerce osCommRes, Services Oline http://www.oscommres.com Copyright (c) 2005 osCommRes Freeway eCommerce http://www.zac-ware.com/freeway Copyright (c) 2007 ZacWareReleased under the GNU General Public License*/ 
 //require('includes/application_top.php');    if (!tep_session_is_registered('customer_id')) {    $navigation->set_snapshot();    tep_redirect(tep_href_link(FILENAME_LOGIN, '', 'SSL'));  }// needs to be included earlier to set the success message in the messageStack  require(DIR_WS_LANGUAGES . $language . '/' . FILENAME_ACCOUNT_NEWSLETTERS);  $newsletter_query = tep_db_query("select customers_subscription_newsletter,customers_reserve_newsletter,customers_newsletter from " . TABLE_CUSTOMERS . " where customers_id = '" . (int)$customer_id . "'");  $newsletter = tep_db_fetch_array($newsletter_query);  if (isset($HTTP_POST_VARS['action']) 
 
  require('includes/application_top.php');
	  
  if (!tep_session_is_registered('customer_id')) {
    $navigation->set_snapshot();
    tep_redirect(tep_href_link(FILENAME_LOGIN, '', 'SSL'));
  }

// needs to be included earlier to set the success message in the messageStack
  require(DIR_WS_LANGUAGES . $language . '/' . FILENAME_ACCOUNT_NEWSLETTERS);

  $newsletter_query = tep_db_query("select customers_subscription_newsletter,customers_reserve_newsletter,customers_newsletter from " . TABLE_CUSTOMERS . " where customers_id = '" . (int)$customer_id . "'");
  $newsletter = tep_db_fetch_array($newsletter_query);
  if (isset($HTTP_POST_VARS['action']) && ($HTTP_POST_VARS['action'] == 'process')) {
	$sql_array=array();
	if(ACCOUNT_NEWSLETTER=='true'){
     if (isset($HTTP_POST_VARS['newsletter_general']) && is_numeric($HTTP_POST_VARS['newsletter_general'])){
   	   $sql_array["customers_newsletter"]="1";
     } else {
		$sql_array["customers_newsletter"]="0";
	 }
	}
	if(ACCOUNT_RESERVATION_NEWSLETTER=='true'){
	  if(isset($HTTP_POST_VARS['newsletter_reserve']) && is_numeric($HTTP_POST_VARS['newsletter_reserve'])){
		$sql_array["customers_reserve_newsletter"]="1";
	  } else {
		$sql_array["customers_reserve_newsletter"]="0";
	  }
	}
	if(ACCOUNT_SUBSCRIPTION_NEWSLETTER=='true'){
	  	if (isset($HTTP_POST_VARS['subscription_newsletter']) && is_numeric($HTTP_POST_VARS['subscription_newsletter'])) {
		$sql_array["customers_subscription_newsletter"]="1";
	  } else {
		$sql_array["customers_subscription_newsletter"]="0";
	  }
	 }
	 if (count($sql_array)>0){
		 tep_db_perform(TABLE_CUSTOMERS,$sql_array,"update","customers_id='" . (int)$customer_id . "'");
	}

    $messageStack->add_session('account', SUCCESS_NEWSLETTER_UPDATED, 'success');

    tep_redirect(tep_href_link(FILENAME_ACCOUNT, '', 'SSL'));
  }

  $breadcrumb->add(NAVBAR_TITLE_1, tep_href_link(FILENAME_ACCOUNT, '', 'SSL'));
  $breadcrumb->add(NAVBAR_TITLE_2, tep_href_link(FILENAME_ACCOUNT_NEWSLETTERS, '', 'SSL'));

  $content = CONTENT_ACCOUNT_NEWSLETTERS;
  $javascript = $content . '.js';

  require(DIR_WS_TEMPLATES . TEMPLATE_NAME . '/' . TEMPLATENAME_MAIN_PAGE);

  require(DIR_WS_INCLUDES . 'application_bottom.php');
?>