public function actionAddPaid($id = 0, $withDate = 0) { $model = new AddToUserForm(); $tariffs = TariffPlans::getAllTariffPlans(true, true); $tariffsArray = CHtml::listData($tariffs, 'id', 'name'); $request = Yii::app()->request; $data = $request->getPost('AddToUserForm'); if ($data) { $userId = $request->getPost('user_id'); $withDate = $request->getPost('withDate'); $model->attributes = $data; if ($model->validate()) { $user = User::model()->findByPk($userId); $tariff = TariffPlans::getFullTariffInfoById($model->tariff_id); if (!$tariff || !$user) { throw new CException('Not valid data'); } if (TariffPlans::applyToUser($userId, $tariff['id'], $model->date_end, null, true)) { echo CJSON::encode(array('status' => 'ok', 'userId' => $userId, 'html' => TariffPlans::getTariffPlansHtml($withDate, true, $user))); Yii::app()->end(); } } else { echo CJSON::encode(array('status' => 'err', 'html' => $this->renderPartial('_add_to_user', array('id' => $userId, 'model' => $model, 'withDate' => $withDate, 'tariffsArray' => $tariffsArray), true))); Yii::app()->end(); } } $renderData = array('id' => $id, 'model' => $model, 'withDate' => $withDate, 'tariffsArray' => $tariffsArray); if (Yii::app()->request->isAjaxRequest) { $this->renderPartial('_add_to_user', $renderData); } else { $this->render('_add_to_user', $renderData); } }