/**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new AssignedAllowedListId();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['AssignedAllowedListId'])) {
         $model->attributes = $_POST['AssignedAllowedListId'];
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $this->render('create', array('model' => $model));
 }
Ejemplo n.º 2
0
 public function actionIndex()
 {
     $model = new User();
     $model->superuser = 0;
     //not super user
     $model->status = User::STATUS_ACTIVE;
     $profile = new Profile();
     $this->performAjaxValidation(array($model, $profile));
     $assignedListId = "";
     if (isset($_POST['User'])) {
         $model->attributes = $_POST['User'];
         $model->activkey = Yii::app()->getModule("user")->encrypting(microtime() . $model->password);
         $profile->attributes = $_POST['Profile'];
         $profile->user_id = 0;
         if ($model->validate() && $profile->validate()) {
             $model->password = Yii::app()->getModule("user")->encrypting($model->password);
             if ($model->save()) {
                 $profile->user_id = $model->id;
                 $profile->save();
                 // To prevent having empty id for object model
                 // Save the  assigned listid*/
                 $listOfListId = explode(",", $_POST['assignedListId']);
                 foreach ($listOfListId as $key => $value) {
                     $listidModel = ListId::model()->findByAttributes(array('list_id_value' => $value));
                     if ($listidModel) {
                         $newAssignment = new AssignedAllowedListId();
                         $newAssignment->list_id = $listidModel->id;
                         $newAssignment->user_id = $model->id;
                         $newAssignment->save();
                     }
                 }
             }
             $assignedListId = $_POST['assignedListId'];
             Yii::app()->user->setFlash("success", "Success! New user created ");
             $this->redirect(array('/ManageUser'));
         } else {
             $profile->validate();
         }
     }
     $this->render('create', array('model' => $model, 'profile' => $profile, 'selectedAllowedId' => $assignedListId));
 }
Ejemplo n.º 3
0
 public function actionAssignNewList($user_id, $new_list_id)
 {
     /*check if exists*/
     $listIdModel = ListId::model()->findByAttributes(array('list_id_value' => $new_list_id));
     $currentUserModel = User::model()->findByAttributes(array('id' => $user_id));
     if (!$listIdModel) {
         $addNewListIdLink = CHtml::link('Yes', array('/listId/newListId', 'listId' => $new_list_id), array('class' => "btn btn-primary"));
         Yii::app()->user->setFlash("info", "Sorry we can't find this <strong>{$new_list_id}</strong> in the database. Would you like to add it in the database ? " . $addNewListIdLink);
         //return to referrer url
         $this->redirect(Yii::app()->request->getUrlReferrer());
     }
     $criteria = new CDbCriteria();
     $criteria->compare('list_id', $listIdModel->id);
     $criteria->compare('user_id', $user_id);
     if (!AssignedAllowedListId::model()->exists($criteria)) {
         /*create new assignment id*/
         $newassignment = new AssignedAllowedListId();
         $newassignment->list_id = $listIdModel->id;
         $newassignment->user_id = $user_id;
         $newassignment->save();
     }
     Yii::app()->user->setFlash("success", "Success : Assignment saved");
     $this->redirect(array('/assigned/view', 'username' => $currentUserModel->username));
 }