<?php

class Subscribe extends CAction {

    public $layout;

    public function run() {

        $model = new NewsletterSubscriber;


//        $model->email = uniqid() . "@gmail.com";


        if (isset($_POST['NewsletterSubscriber'])) {

            $model->attributes = $_POST['NewsletterSubscriber'];

            if ($model->save()) {
                $flashMessage = Yii::t('admin', 'You have successfully subscribed to the newsletter.');
                $flashMessage = '<div class="successMessage">' . $flashMessage . '</div>';
                $response = array(
                    'status' => 'success',
                    'message' => $flashMessage,
                    'id' => $model->id,
                );
            } else {
                $response = array(
                    'status' => 'error',
                    'message' => CHtml::error($model, 'email'),
                );
            }
//            echo CJSON::encode($response);
//            Yii::app()->end();
        }
        $this->controller->renderPartial($this->layout, array('model' => $model));
    }

}
