Example #1
0
 public function indexAction()
 {
     // action body
     $this->_helper->layout()->disableLayout();
     /* set this to login page to change the character charset of browsers to Utf-8  ...*/
     $this->_helper->layout()->disableLayout();
     $form = new Application_Form_FrmLogin();
     $form->setAction('index');
     $form->setMethod('post');
     $form->setAttrib('accept-charset', 'utf-8');
     $this->view->form = $form;
     $key = new Application_Model_DbTable_DbKeycode();
     $this->view->data = $key->getKeyCodeMiniInv(TRUE);
     if ($this->getRequest()->isPost()) {
         $formdata = $this->getRequest()->getPost();
         if ($form->isValid($formdata)) {
             $session_lang = new Zend_Session_Namespace('lang');
             $session_lang->lang_id = $formdata["lang"];
             //for creat session
             Application_Form_FrmLanguages::getCurrentlanguage($session_lang->lang_id);
             //for choose lang for when login
             $user_name = $form->getValue('txt_user_name');
             $password = $form->getValue('txt_password');
             $db_user = new Application_Model_DbTable_DbUsers();
             if ($db_user->userAuthenticate($user_name, $password)) {
                 // 					$this->view->msg = 'Authentication Sucessful!';
                 // 					$this->view->err="0";
                 $session_user = new Zend_Session_Namespace('auth');
                 $user_id = $db_user->getUserID($user_name);
                 $user_info = $db_user->getUserInfo($user_id);
                 $arr_acl = $db_user->getArrAcl($user_info['user_type']);
                 $session_user->user_id = $user_id;
                 $session_user->user_name = $user_name;
                 $session_user->pwd = $password;
                 $session_user->level = $user_info['user_type'];
                 $session_user->last_name = $user_info['last_name'];
                 $session_user->first_name = $user_info['first_name'];
                 $session_user->theme_style = $db_user->getThemeByUserId($user_id);
                 $a_i = 0;
                 $arr_actin = array();
                 for ($i = 0; $i < count($arr_acl); $i++) {
                     $arr_module[$i] = $arr_acl[$i]['module'];
                     if ($arr_acl[$i]['module'] == 'exchange') {
                         if ($arr_acl[$i]['action'] == "index" || $arr_acl[$i]['action'] == "add" || $arr_acl[$i]['action'] == "edited") {
                             continue;
                         }
                         $arr_actin[$a_i++] = $arr_acl[$i]['action'];
                     }
                 }
                 $arr_module = $this->sortMenu($arr_module);
                 // 					print_r($arr_module); exit;
                 $session_user->arr_acl = $arr_acl;
                 $session_user->arr_module = $arr_module;
                 $session_user->arr_actin = $arr_actin;
                 $session_user->lock();
                 $log = new Application_Model_DbTable_DbUserLog();
                 $log->insertLogin($user_id);
                 foreach ($arr_module as $i => $d) {
                     if ($d !== 'user') {
                         $url = '/' . @$arr_module[2];
                     } else {
                         $url = self::REDIRECT_URL;
                         break;
                     }
                 }
                 Application_Form_FrmMessage::redirectUrl("/home");
             } else {
                 $this->view->msg = 'ឈ្មោះ​អ្នក​ប្រើ​ប្រាស់ និង ពាក្យ​​សំងាត់ មិន​ត្រឺម​ត្រូវ​ទេ ';
             }
         } else {
             $this->view->msg = 'លោកអ្នកមិនមានសិទ្ធិប្រើប្រាស់ទេ!';
         }
     }
 }
Example #2
0
 public function indexAction()
 {
     // action body
     $this->_helper->layout()->disableLayout();
     /* set this to login page to change the character charset of browsers to Utf-8  ...*/
     $this->_helper->layout()->disableLayout();
     $form = new Application_Form_FrmLogin();
     $form->setAction('index');
     $form->setMethod('post');
     $form->setAttrib('accept-charset', 'utf-8');
     $this->view->form = $form;
     $key = new Application_Model_DbTable_DbKeycode();
     $this->view->data = $key->getKeyCodeMiniInv(TRUE);
     if ($this->getRequest()->isPost()) {
         $formdata = $this->getRequest()->getPost();
         if ($form->isValid($formdata)) {
             $session_lang = new Zend_Session_Namespace('lang');
             $session_lang->lang_id = $formdata["lang"];
             //for creat session
             Application_Form_FrmLanguages::getCurrentlanguage($session_lang->lang_id);
             //for choose lang for when login
             $user_name = $form->getValue('txt_user_name');
             $password = $form->getValue('txt_password');
             $db_user = new Application_Model_DbTable_DbUsers();
             if ($db_user->userAuthenticate($user_name, $password)) {
                 // 					$this->view->msg = 'Authentication Sucessful!';
                 // 					$this->view->err="0";
                 $session_user = new Zend_Session_Namespace('auth');
                 $user_id = $db_user->getUserID($user_name);
                 $user_info = $db_user->getUserInfo($user_id);
                 $arr_acl = $db_user->getArrAcl($user_info['user_type']);
                 $session_user->user_id = $user_id;
                 $session_user->user_name = $user_name;
                 $session_user->pwd = $password;
                 $session_user->level = $user_info['user_type'];
                 $session_user->last_name = $user_info['last_name'];
                 $session_user->first_name = $user_info['first_name'];
                 $session_user->theme_style = $db_user->getThemeByUserId($user_id);
                 $a_i = 0;
                 $arr_actin = array();
                 // 					print_r($arr_acl);
                 for ($i = 0; $i < count($arr_acl); $i++) {
                     $arr_module[$i] = $arr_acl[$i]['module'];
                     // 						if($arr_acl[$i]['module'] == 'exchange'){
                     // 							if($arr_acl[$i]['action'] == "index" || $arr_acl[$i]['action'] == "add" || $arr_acl[$i]['action'] == "edit" ) {
                     // 								continue;
                     // 							}
                     $arr_actin[$a_i++] = $arr_acl[$i]['module'] . '/' . $arr_acl[$i]['controller'] . '/' . $arr_acl[$i]['action'];
                     // 						}
                 }
                 // 					print_r($arr_actin);exit();
                 $arr_module = array_unique($arr_module);
                 $arr_actin = array_unique($arr_actin);
                 // 					print_r($arr_module);	echo "<br />============<br />";
                 $arr_module = $this->sortMenu($arr_module);
                 // 					print_r($arr_module);exit();
                 // 					print_r($arr_module); exit;
                 $session_user->arr_acl = $arr_acl;
                 $session_user->arr_module = $arr_module;
                 $session_user->arr_actin = $arr_actin;
                 $session_user->lock();
                 $log = new Application_Model_DbTable_DbUserLog();
                 $log->insertLogin($user_id);
                 foreach ($arr_module as $i => $d) {
                     if ($d !== 'user') {
                         $url = '/' . @$arr_module[2];
                     } else {
                         $url = self::REDIRECT_URL;
                         break;
                     }
                 }
                 Application_Form_FrmMessage::redirectUrl("/home");
             } else {
                 $this->view->msg = 'ឈ្មោះ​អ្នក​ប្រើ​ប្រាស់ និង ពាក្យ​​សំងា�់ មិន​�្រឺម​�្រូវ​ទ� ';
             }
         } else {
             $this->view->msg = 'លោកអ្នកមិនមានសិទ្ធិប្រើប្រាស់ទ�!';
         }
     }
 }