/**
  * Creates a new User Login.
  * If creation is successful, the browser will be redirected to the 'index' page.
  * quthor wawan
  */
 public function actionCreateUser()
 {
     $model = new Userlogin();
     $model->scenario = 'createuser';
     if ($model->load(Yii::$app->request->post())) {
         $post = Yii::$app->request->post();
         $datapostion = $post['Userlogin']['POSITION_LOGIN'];
         if ($datapostion == 1) {
             $auth = "SALESMAN";
             // auth key untuk salesmen
         } else {
             $auth = "SALES PROMOTION";
             // auth key untuk sales promotion
         }
         $model->POSITION_LOGIN = $datapostion;
         $model->POSITION_SITE = "CRM";
         // untuk login crm
         $pass = $model->password_hash;
         $security = Yii::$app->security->generatePasswordHash($pass);
         $authkey = Yii::$app->security->generatePasswordHash($auth);
         $model->password_hash = $security;
         $model->auth_key = $authkey;
         $model->save();
         return $this->redirect(['index']);
     } else {
         return $this->renderAjax('create', ['model' => $model]);
     }
 }
 /**
  * Creates a new User Login.
  * If creation is successful, the browser will be redirected to the 'index' page.
  * author wawan
  */
 public function actionCreateUser()
 {
     $model = new Userlogin();
     $user_profile = new UserProfile();
     //componen user option
     $profile = Yii::$app->getUserOpt->Profile_user();
     $usercreate = $profile->username;
     $model->scenario = Userlogin::SCENARIO_USER;
     if ($model->load(Yii::$app->request->post()) && $user_profile->load(Yii::$app->request->post())) {
         $post = Yii::$app->request->post();
         $datapostion = $post['Userlogin']['POSITION_LOGIN'];
         if ($datapostion == 1) {
             $auth = "SALESMAN";
             // auth key untuk salesmen
         } elseif ($datapostion == 2) {
             $auth = "SALES PROMOTION";
             // auth key untuk sales promotion
         } elseif ($datapostion == 3) {
             $auth = "CUSTOMER";
             // auth key untuk Customers
         } elseif ($datapostion == 4) {
             $auth = "DISTRIBUTOR";
             // auth key untuk Customers
         } elseif ($datapostion == 5) {
             $auth = "FACTORY PABRIK";
             // auth key untuk Customers
         } elseif ($datapostion == 6) {
             $auth = "OUTSOURCE";
             // auth key untuk Customers
         }
         $model->POSITION_LOGIN = $datapostion;
         $model->POSITION_SITE = "CRM";
         // untuk login crm
         $pass = $model->password_hash;
         $security = Yii::$app->security->generatePasswordHash($pass);
         $authkey = Yii::$app->security->generatePasswordHash($auth);
         $model->password_hash = $security;
         $model->auth_key = $authkey;
         $model->save();
         $user_profile->ID_USER = $model->id;
         $user_profile->CREATED_BY = $usercreate;
         $user_profile->CREATED_AT = date("Y-m-d H:i:s");
         $user_profile->save();
         return $this->redirect(['index?tab=4']);
     } else {
         return $this->renderAjax('_usercreate', ['model' => $model, 'user_profile' => $user_profile]);
     }
 }
 /**
  * Creates a new Mdlpermission model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     if (!self::getPermission()->BTN_CREATE) {
         //PERMISSION CHECK - RETURN INDEX -ptr.nov--
         $this->redirect(['/sistem/modul-permission', 'msg' => 'alert']);
     } else {
         $model = new Userlogin();
         $model->scenario = 'createuser';
         $data = ArrayHelper::map(Employe::find()->orderBy('EMP_NM')->asArray()->all(), 'EMP_ID', 'EMP_NM');
         if ($model->load(Yii::$app->request->post())) {
             $hash = Yii::$app->getSecurity()->generatePasswordHash($model->password_hash);
             $model->password_hash = $hash;
             $model->created_at = strtotime(date('Y-m-d'));
             if ($model->save()) {
                 $data = Modulerp::find()->asArray()->all();
                 foreach ($data as $hasil) {
                     $connection = Yii::$app->db;
                     $connection->createCommand()->batchInsert('modul_permission', ['USER_ID', 'MODUL_ID'], [[$model->id, $hasil['MODUL_ID']]])->execute();
                 }
             }
             return $this->redirect('index');
         } else {
             return $this->renderAjax('create', ['model' => $model, 'data' => $data]);
         }
     }
 }