public function actionCreate() { $model = new DomainUser(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['DomainUser'])) { $model->attributes = $_POST['DomainUser']; // TODO: check if link already exists before inserting if ($model->save()) { Yii::app()->audit->log('Linked domain ' . $model->domain_id . ' to user ' . $model->user_id); } // if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser if (!isset($_GET['ajax'])) { $this->redirect($_GET['returnUrl']); } } else { throw new CHttpException(400, 'Invalid request. Please do not repeat this request again.'); } }
/** * Creates a deep copy of a domain and it's associated records. */ public function actionCopy($id) { $oldmodel = $this->loadModel($id); $model = new Domain(); $model->name = $oldmodel->name; $model->master = $oldmodel->master; $model->last_check = $oldmodel->last_check; $model->type = $oldmodel->type; $model->notified_serial = $oldmodel->notified_serial; $model->account = $oldmodel->account; // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Domain'])) { $model->attributes = $_POST['Domain']; if ($model->save()) { // copy records if ($model->copy_records == 1) { foreach ($oldmodel->records as $or) { $record = new Record(); $record->domain_id = $model->id; $record->name = $or->name; $record->type = $or->type; $record->content = $or->content; $record->ttl = $or->ttl; $record->prio = $or->prio; $record->change_date = $or->change_date; $record->save(); } } // copy permissions if ($model->copy_permissions == 1) { foreach ($oldmodel->users as $user) { $perm = new DomainUser(); $perm->domain_id = $model->id; $perm->user_id = $user->id; $perm->save(); } } Yii::app()->audit->log('Copied domain: ' . $model->id); $this->redirect(array('update', 'id' => $model->id)); } } $this->render('copy', array('model' => $model)); }