<?php
class GroupAction extends BaseAction
{
    public function run()
    {
        if (Yii::app()->request->isPostRequest)
        {
            set_time_limit(0);
            try
            {
                Messages::model()->create($_POST['subject'],$_POST['message'],$_POST['msgto'],$_POST['group']);
            }
            catch (Exception $exce)
            {
                throw new CHttpException(500, $exce->getMessage());
            }

            if (Yii::app()->request->isAjaxRequest)
            {
                echo CJSON::encode(1);
                Yii::app()->end();
            }
            $this->getController()->redirect(array('index'));
        }
        
        $this->getController()->render('group');
    }
}