/** * Редактирование данных * * @param $user_id */ public function actionEditData($user_id) { $userModel = $this->loadModel($user_id); $formModel = new EditUserForm(); $formModel->role = $userModel->role; $formModel->activated = $userModel->activated; $formModel->vote_balance = $userModel->profile->vote_balance; $formModel->balance = $userModel->profile->balance; $formModel->phone = $userModel->profile->phone; if ($userModel->profile->protected_ip && is_array($userModel->profile->protected_ip)) { $formModel->protected_ip = implode("\r\n", $userModel->profile->protected_ip); } if (request()->isPostRequest && isset($_POST['EditUserForm'])) { $formModel->setAttributes($_POST['EditUserForm']); if ($errors = ActiveForm::validate($formModel)) { $this->ajax['msg'] = $errors; } else { $transaction = db()->beginTransaction(); try { $userModel->role = $formModel->role; $userModel->activated = $formModel->activated; $userModel->profile->vote_balance = $formModel->vote_balance; $userModel->profile->balance = $formModel->balance; $userModel->profile->phone = $formModel->phone; $userModel->profile->protected_ip = $formModel->protected_ip; $userModel->save(FALSE); $userModel->profile->save(FALSE); $transaction->commit(); $this->ajax['status'] = TRUE; $this->ajax['msg'] = Yii::t('backend', 'Данные сохранены'); } catch (Exception $e) { $transaction->rollback(); $this->ajax['msg'] = $e->getMessage(); } } } else { // get $this->ajax['status'] = TRUE; $this->ajax['view'] = $this->renderPartial('//users/view/edit-data-form', array('formModel' => $formModel, 'userModel' => $userModel), TRUE); } echo json_encode($this->ajax); }
public function actionEditUser($iduser) { if (UsersDao::getInstance()->validToken() && Yii::app()->session['isadmin']) { $this->layout = "tplLogin"; $message = ''; $model = new EditUserForm(); try { $userData = UsersDao::getInstance()->getUserDataById($iduser); $model->email = $userData['email']; $model->idusers = $userData['idusers']; $model->codes_idcodes = $userData['codes_idcodes']; $model->name = $userData['name']; $model->lastname = $userData['lastname']; $model->password = $userData['password']; $model->activation_code = $userData['activation_code']; $model->account_active = $userData['account_active']; $model->activation_date = $userData['activation_date']; $model->authToken = $userData['authToken']; $model->change_password_code = $userData['change_password_code']; $model->lastlogin = $userData['lastlogin']; $model->createdon = $userData['createdon']; $model->isadmin = $userData['isadmin']; $model->duration = $userData['duration']; if (isset($_POST['EditUserForm'])) { $model->attributes = $_POST['EditUserForm']; if ($model->validate()) { UsersDao::getInstance()->updateUserData($model); Yii::app()->user->setFlash('enterCodes', Constants::SUCCESS_USER_DATA_UPDATE); $this->refresh(); } } } catch (Exception $e) { Yii::app()->user->setFlash('enterCodes', $e->getMessage()); $this->refresh(); } $this->render('editUser', array('model' => $model, "errorSummary" => $message)); } else { //Yii::log("Entro a login y fue false","warning"); //Yii::app()->runController('Site/login'); UtilsFunctions::destroySession(); } }