/**
  * Create permission form
  */
 public function actionCreate($type = null)
 {
     // Check Access
     checkAccessThrowException('op_permission_create');
     $model = new AuthItem();
     if (isset($_POST['AuthItem'])) {
         $model->setAttributes($_POST['AuthItem']);
         if ($model->save()) {
             fok(at('Permission Created!'));
             // Log Message
             alog(at("New permission created: '{name}'.", array('{name}' => $model->name)));
             $this->redirect(array('index'));
         }
     } else {
         if ($type !== null) {
             $model->type = $type;
         }
     }
     // Add Breadcrumb
     $this->addBreadCrumb(at('Create Permission'));
     $this->title[] = at('Create Permission');
     $this->render('form', array('model' => $model));
 }
	/**
	* Create a new auth item.
	*/
	public function actionCreate($type) {
		if (!array_key_exists($type, $this->types))
			throw new CHttpException(404, Yii::t('RbamModule.rbam','Invalid authorisation item type.'));

		$authItem = new AuthItem('create'); // $authItem is a CFormModel
		$authItem->setAttributes(compact('type'));
		$form = $authItem->getForm();
		if ($form->submitted($form->uniqueId)) {
			$response = array();
			if ($authItem->save()) {
				$response['content'] = Yii::t('RbamModule.rbam','"{item}" {type} created.', array(
					'{item}'=>$authItem->name,
					'{type}'=>$this->type($type, true)
				));
				$response['redirect'] = $this->createUrl('manage', array('item'=>$authItem->name));
			}
			else {
				$errors = array();
				foreach ($authItem->getErrors() as $attribute=>$attributeErrors)
					foreach ($attributeErrors as $error)
						$errors[] = array(
							'attribute'=>$attribute,
							'label'=>$authItem->getAttributeLabel($attribute),
							'error'=>$error
						);
				$response = compact('errors');
			}
			header('Content-type: application/json');
			echo CJSON::encode($response);
	  	Yii::app()->end();
		}

		$this->pageTitle = $this->_pageTitle($this->action->id, array(
			'{type}'=>$this->type($type, true, true)
		));
		$this->breadcrumbs = array(
			'RBAM'=>array('rbam/index'),
			$this->_pageTitle('index')=>array('index'),
			$this->pageTitle
		);

		$this->render('form', compact('form', 'type'));
	}