<?php
/**
 * Created by JetBrains PhpStorm.
 * User: yzxh24
 * Date: 12-2-5
 * Time: 下午4:37
 * To change this template use File | Settings | File Templates.
 */
class UsergroupAction extends BaseAction
{
    public function run()
    {
        $uid = Yii::app()->request->getQuery('uid');
        $member = Member::model()->findByPk($uid);

        $this->performAjaxValidation($member, 'ugroup');

        if (isset($_POST['Member']) && Yii::app()->request->isAjaxRequest)
        {
            $member->oldGid = $member->groupid;
            $member->attributes = $_POST['Member'];
            // 放在before里貌似有BUG，先丢这
            $member->groupexpiry && $member->groupexpiry = strtotime($member->groupexpiry);
            if ($member->save())
            {
                $member->save();
                echo CJSON::encode(1);
            }
            else
            {
                echo CActiveForm::validate($member);
            }
            Yii::app()->end();
        }
        $groups = UserGroup::model()->findAll();

        $this->getController()->renderPartial('usergroup', array('member'=>$member, 'groups' => $groups), false, true);
    }
}
