//   Public License along with this program; if not, write to the Free
//   Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
//   MA 02110-1301, USA.
//
// This source file is part of the eZ publish (tm) Open Source Content
// Management System.
//
// ## END COPYRIGHT, LICENSE AND WARRANTY NOTICE ##
//
/*! \file edit_subscription.php
*/
$Module = $Params['Module'];
$http = eZHTTPTool::instance();
$warnings = array();
$subscriptionID = $Params['SubscriptionID'];
$subscription = eZSubscription::fetchDraft($subscriptionID);
if (!$subscription) {
    $subscription = eZSubscription::create();
}
if (!$subscription) {
    return $Module->handleError(eZError::KERNEL_NOT_AVAILABLE, 'kernel');
}
if ($http->hasPostVariable('StoreButton') || $http->hasPostVariable('ProfileButton') || $http->hasPostVariable('BrowseUserButton') || $http->hasPostVariable('UnsetUserButton')) {
    if (!eZRobinsonListEntry::inList($http->postVariable('Email')) && !eZRobinsonListEntry::inList($http->postVariable('Mobile'))) {
        if (!eZMail::validate($http->postVariable('Email'))) {
            $warnings[] = ezpI18n::tr('eznewsletter/newsletter/edit_subscription', 'You must provide a valid email address.');
        } else {
            $subscription->setAttribute('email', $http->postVariable('Email'));
        }
        $subscription->setAttribute('firstname', $http->postVariable('Firstname'));
        $subscription->setAttribute('name', $http->postVariable('Name'));
 function removeDraft()
 {
     $subscriptionDraft = eZSubscription::fetchDraft($this->attribute('id'));
     if ($subscriptionListDraft) {
         $subscriptionListDraft->remove();
     }
 }