<?php

# $Id: action.preferences_add_edit.php 1 2011-06-12 15:25:27Z arnoud $ 

#BEGIN_LICENSE
#-------------------------------------------------------------------------
# Module: UpCoupon (c) 2011 by Arnoud van Susteren (arnoud@upservice.nl)
#
# An addon module for CMS Made Simple to setup a Coupon Codes Lottery
# 
#-------------------------------------------------------------------------
# CMS - CMS Made Simple is (c) 2005 by Ted Kulp (wishy@cmsmadesimple.org)
# This project's homepage is: http://www.cmsmadesimple.org
#
#-------------------------------------------------------------------------
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# However, as a special exception to the GPL, this software is distributed
# as an addon module to CMS Made Simple.  You may not use this software
# in any Non GPL version of CMS Made simple, or in any version of CMS
# Made simple that does not indicate clearly and obviously in its admin 
# section that the site was built with CMS Made simple.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
# Or read it online: http://www.gnu.org/licenses/licenses.html#GPL
#
#-------------------------------------------------------------------------
#END_LICENSE

if(!is_object(cmsms())) exit;

###############################################################################
# CheckPermission
###############################################################################

if (!$this->CheckPermission('Modify Templates')) {
    echo $this->ShowErrors($this->Lang('accessdenied', array('preferences')));
    return;
}

###############################################################################
# Redirect on cancel
###############################################################################

if (isset($params['cancel'])) {
    $params = array('active_tab' => 'preferences');
    $this->Redirect($id, 'defaultadmin', $returnid, $params);
}

###############################################################################
# program
###############################################################################

$email_registered_check = isset($params['email_registered_check']) ? 1 : 0;

$email_registered_subject = trim(preg_replace('/[^A-Za-z0-9\s-]/', '', $params['email_registered_subject']));

$email_registered_address_email = is_email(trim($params['email_registered_address_email']))  ? trim($params['email_registered_address_email']) : '';

$email_registered_address_name = trim(preg_replace('/[^A-Za-z0-9\s-]/', '', $params['email_registered_address_name']));

$email_registered_message = trim($params['email_registered_message']);

$email_registered_message_winner = trim($params['email_registered_message_winner']);

$this->SetPreference('email_registered_check', $email_registered_check);
$this->SetPreference('email_registered_subject', $email_registered_subject);
$this->SetPreference('email_registered_address_email', $email_registered_address_email);
$this->SetPreference('email_registered_address_name', $email_registered_address_name);
$this->SetTemplate('email_registered_message', $email_registered_message);
$this->SetTemplate('email_registered_message_winner', $email_registered_message_winner);

if ( ($email_registered_check == 1 ) &&
     ($email_registered_subject != '') &&
     ($email_registered_address_email != '') &&
     ($email_registered_address_name != '') &&
     ($email_registered_message != '') &&
     ($email_registered_message_winner != '') ) {
    $this->SetPreference('email_registered_true_false', 1);
} else {
    $this->SetPreference('email_registered_true_false', 0); 
}

// based on the new settings we might trigger some actions

@$this->SendEvent('UpCouponPreferencesEdited', $params);
$params = array('preferences_message'=> 's_edited,preferences_s', 'active_tab' => 'preferences');
$this->Redirect($id, 'defaultadmin', '', $params);

#
# EOF
#
?>
