diff --git a/app/controllers/AdminController.php b/app/controllers/AdminController.php index 93b947b8e..945376e39 100755 --- a/app/controllers/AdminController.php +++ b/app/controllers/AdminController.php @@ -9,7 +9,7 @@ public function accessRules() { ], [ 'allow', // allow authenticated user to perform 'create' and 'update' actions 'actions' => [ - 'import', 'export', 'clearDB', 'acl', 'backup', 'data', 'exportStudentIdentify', 'syncExport', + 'import', 'export', 'update', 'manageUsers', 'clearDB', 'acl', 'backup', 'data', 'exportStudentIdentify', 'syncExport', 'syncImport', 'exportToMaster', 'clearMaster', 'importFromMaster' ], 'users' => ['@'], ], @@ -446,6 +446,70 @@ public function actionExportMaster(){ unlink($fileName); } } -} -?> + public function actionManageUsers() { + $filter = new Users('search'); + $filter->unsetAttributes(); + if (isset($_GET['Users'])) { + $filter->attributes = $_GET['Users']; + } + $criteria = new CDbCriteria; + $criteria->condition = "username != 'admin'"; + $dataProvider = new CActiveDataProvider('Users', array( + 'criteria' => $criteria, + 'pagination' => array( + 'pageSize' => 12, + ) + )); + $this->render('manageUsers', array( + 'dataProvider' => $dataProvider, + 'filter' => $filter, + )); + } + + public function actionUpdate($id) { + $model = Users::model()->findByPk($id); + $actual_role = $model->getRole(); + $userSchools = UsersSchool::model()->findAllByAttributes(array('user_fk' => $id)); + if (isset($_POST['Users'], $_POST['Confirm'])) { + $model->attributes = $_POST['Users']; + if ($model->validate()) { + $password = md5($_POST['Users']['password']); + $confirm = md5($_POST['Confirm']); + if ($password == $confirm) { + $model->password = $password; + if ($model->save()) { + $save = TRUE; + foreach ($_POST['schools'] as $school) { + $userSchool = UsersSchool::model()->findByAttributes(array('school_fk' => $school, 'user_fk' => $model->id)); + if( $userSchool == null) { + $userSchool = new UsersSchool; + $userSchool->user_fk = $model->id; + $userSchool->school_fk = $school; + $save = $save && $userSchool->validate() && $userSchool->save(); + } + } + if ($save) { + $auth = Yii::app()->authManager; + $auth->revoke($_POST['Role'], $model->id); + $auth->assign($_POST['Role'], $model->id); + Yii::app()->user->setFlash('success', Yii::t('default', 'Usuário alterado com sucesso!')); + $this->redirect(['index']); + } + } + } else { + $model->addError('password', Yii::t('default', 'Confirm Password') . ': ' . Yii::t('help', 'Confirm')); + } + } + } + + $result = []; + $i = 0; + foreach ($userSchools as $scholl){ + $result[$i] = $scholl->school_fk; + $i++; + } + + $this->render('_form', ['model' => $model, 'actual_role' => $actual_role, 'userSchools' => $result]); + } +} diff --git a/app/messages/pt_br/default.php b/app/messages/pt_br/default.php index 824321baa..01a0231d4 100755 --- a/app/messages/pt_br/default.php +++ b/app/messages/pt_br/default.php @@ -721,6 +721,7 @@ 'Password' => 'Senha', 'Confirm Password' => 'Confirmar Senha', 'Username' => 'Usuário', + 'Active' => 'Ativo', 'Month' => 'Mês', //Abas @@ -788,6 +789,7 @@ 'Update StudentIdentification' => 'Atualizar Aluno', 'Update SchoolIdentification' => 'Atualizar Escola', 'Update InstructorIdentification' => 'Atualizar Professor', + 'Update User' => 'Atualizar Usuário', //Erros 'already enrolled in this classroom.' =>'já matriculado na turma.', diff --git a/app/models/Users.php b/app/models/Users.php index 53534e7b4..c4f45af91 100755 --- a/app/models/Users.php +++ b/app/models/Users.php @@ -91,7 +91,7 @@ public function search() // @todo Please modify the following code to remove attributes that should not be searched. $criteria=new CDbCriteria; - + $criteria->condition = "username != 'admin'"; $criteria->compare('id',$this->id); $criteria->compare('name',$this->name,true); $criteria->compare('username',$this->username,true); @@ -113,4 +113,21 @@ public static function model($className=__CLASS__) { return parent::model($className); } + + public function getRole() + { + + $role = Yii::app()->db->createCommand() + + ->select('itemname') + + ->from('auth_assignment') + + ->where('userid=:id', array(':id'=>$this->id)) + + ->queryScalar(); + + + return $role; + } } diff --git a/js/admin/form/_initialization.js b/js/admin/form/_initialization.js new file mode 100644 index 000000000..8018906b5 --- /dev/null +++ b/js/admin/form/_initialization.js @@ -0,0 +1 @@ +$('#Users_password').attr('value', ''); \ No newline at end of file diff --git a/themes/default/views/admin/_form.php b/themes/default/views/admin/_form.php index 9f6fbf32b..94e3b0108 100755 --- a/themes/default/views/admin/_form.php +++ b/themes/default/views/admin/_form.php @@ -10,6 +10,7 @@ $baseUrl = Yii::app()->baseUrl; $cs = Yii::app()->getClientScript(); $cs->registerScriptFile($baseUrl . '/js/admin/form/validations.js', CClientScript::POS_END); +$cs->registerScriptFile($baseUrl . '/js/admin/form/_initialization.js', CClientScript::POS_END); $form = $this->beginWidget('CActiveForm', array( 'id' => 'users-createUser-form', @@ -100,13 +101,19 @@ foreach ($roles as $key => $value) { $roles[$key] = Yii::t('default',$value); } - echo CHtml::dropDownList('Role','', $roles ,array('class'=>'select-search-off')); ?> + echo CHtml::dropDownList('Role',$actual_role, $roles ,array('class'=>'select-search-off')); ?>