public function actionPermissions($id) { //$model= DatabasesPerm::model()->findByPk($id); $model = new DatabasesPerm('search'); $model->unsetAttributes(); // clear any default values $model->database_id = $id; $user = new DatabasesPerm(); $user->database_id = $id; // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['DatabasesPerm'])) { $user->attributes = $_POST['DatabasesPerm']; $user->save(); //if($model->save()) // $this->redirect(array('index')); } $this->render('permissions', array('model' => $model, 'user' => $user)); }
public function save($runValidation = true, $attributes = NULL) { $a = parent::save($runValidation, $attributes); if ($this->prefix == '') { $this->string = Yii::app()->dbMain->connectionString; //$chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; $this->prefix = "CA" . $this->id . "_"; //got prefix $a = parent::save($runValidation, $attributes); } //if tables config notexsits Yii::app()->db->setActive(false); Yii::app()->db->connectionString = $this->string; Yii::app()->db->tablePrefix = $this->prefix; Yii::app()->db->setActive(true); //needs to clear accounts if (Yii::app()->db->schema->getTable('{{config}}') === null) { // //create tables $this->createDb(); Yii::app()->db->setActive(false); Yii::app()->db->connectionString = $this->string; Yii::app()->db->tablePrefix = $this->prefix; Yii::app()->db->setActive(true); $a = Settings::model()->findByPk('company.path'); //update path by prefix $a->value = $this->prefix; $a->save(); //$yiiBasepath = Yii::app()->basePath; $folder = Yii::app()->params["filePath"] . $this->prefix . DIRECTORY_SEPARATOR; mkdir($folder); mkdir($folder . "settings"); //settings mkdir($folder . "cert"); //cert mkdir($folder . "docs"); //docs mkdir($folder . "items"); //items mkdir($folder . "openformat"); //openformat mkdir($folder . "files"); //openformat mkdir($folder . "backup"); //backup //add permisstions } else { //else //table version //upgrade } $perm = new DatabasesPerm(); $perm->user_id = Yii::app()->user->id; $perm->database_id = $this->id; $perm->level_id = 1; $perm->save(); return $a; }