public function validationBeforeDelete()
 {
     $usedInModule = array();
     $this->onDeleteMessage = 'Cannot delete "' . $this->name . '", data already used in (';
     $criteria = new CDbCriteria();
     $criteria->compare('p_id', $this->id);
     $models = UserLevel::model()->findAll($criteria);
     if (isset($this->modulePrivilages) && count($this->modulePrivilages) > 0) {
         $usedInModule[] = 'Module';
     }
     if (isset($this->users) && count($this->users) > 0) {
         $usedInModule[] = 'User';
     }
     if (count($models) > 0) {
         $usedInModule[] = 'User Level';
     }
     if (count($usedInModule) > 0) {
         sort($usedInModule);
         foreach ($usedInModule as $value) {
             $this->onDeleteMessage .= $value . ', ';
         }
         $this->onDeleteMessage = substr($this->onDeleteMessage, 0, strlen($this->onDeleteMessage) - 2);
         $this->onDeleteMessage .= '). Please delete related data first before delete it!';
         return false;
     } else {
         return true;
     }
 }
 /**
  * Updates a particular model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id the ID of the model to be updated
  */
 public function actionUpdate($id)
 {
     $model = $this->loadModel($id);
     $userLevel = UserLevel::model()->findAll();
     $preCheckedArray = array();
     if (isset($model->modulePrivilages)) {
         foreach ($model->modulePrivilages as $value) {
             $preCheckedArray[] = $value->user_level_id;
         }
     }
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Module'])) {
         if (isset($_POST['privilages'])) {
             $preCheckedArray = Yii::app()->request->getPost('privilages');
         } else {
             $preCheckedArray = array();
         }
         $model->attributes = $_POST['Module'];
         $model->arrPrivilages = Yii::app()->request->getPost('privilages');
         if ($model->p_id == 0 || count($model->arrPrivilages)) {
             $model->hasPrivilage = true;
         }
         if ($model->save()) {
             Yii::app()->user->setFlash('success', 'Module "' . $model->name . '" updated!');
             $model = $this->loadModel($model->id);
         }
     }
     $this->render('update', array('model' => $model, 'userLevel' => $userLevel, 'preCheckedArray' => $preCheckedArray));
 }
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer the ID of the model to be loaded
  */
 public function loadModel($id)
 {
     $model = UserLevel::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
	<div class="row">
		<?php 
echo $form->label($model, 'email');
?>
		<?php 
echo $form->textField($model, 'email', array('size' => 50, 'maxlength' => 50));
?>
	</div>

	<div class="row">
		<?php 
echo $form->label($model, 'user_level_id');
?>
		<?php 
echo $form->dropDownList($model, 'user_level_id', CHtml::listData(UserLevel::model()->findAll(), 'id', 'name'), array('empty' => ""));
?>
	</div>

	<div class="row">
		<?php 
echo $form->label($model, 'last_ip_address');
?>
		<?php 
echo $form->textField($model, 'last_ip_address', array('size' => 60, 'maxlength' => 255));
?>
	</div>

	<div class="row buttons">
		<?php 
echo CHtml::submitButton('Search');
Exemple #5
0
echo $form->labelEx($model, 'description');
?>
		<?php 
echo $form->textField($model, 'description', array('size' => 50, 'maxlength' => 50));
?>
		<?php 
echo $form->error($model, 'description');
?>
	</div>

	<div class="row">
		<?php 
echo $form->labelEx($model, 'p_id');
?>
		<?php 
echo $form->dropDownList($model, 'p_id', array('0' => 'Parent') + CHtml::listData(UserLevel::model()->findAll(), 'id', 'name'), NULL);
?>
		<?php 
echo $form->error($model, 'p_id');
?>
	</div>

	<div class="row buttons">
		<?php 
echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save');
?>
	</div>

<?php 
$this->endWidget();
?>
 public function actionDelete($id)
 {
     UserLevel::model()->deleteByPk($id);
     Yii::app()->user->setFlash('success', "Data deleted.");
     $this->redirect(array('index'));
 }
Exemple #7
0
echo $form->labelEx($model, 'email');
?>
		<?php 
echo $form->textField($model, 'email', array('size' => 50, 'maxlength' => 50));
?>
		<?php 
echo $form->error($model, 'email');
?>
	</div>

	<div class="row">
		<?php 
echo $form->labelEx($model, 'user_level_id');
?>
		<?php 
echo $form->dropDownList($model, 'user_level_id', CHtml::listData(UserLevel::model()->findAll(), 'id', 'name'), NULL);
?>
        
		<?php 
echo $form->error($model, 'user_level_id');
?>
	</div>
    
    
    <?php 
if (!$model->isNewRecord) {
    ?>
        </br>
        <div class="row">
            <p class="note">Optional</p>
        </div>