public function loginAction()
 {
     $auth = Zend_Auth::getInstance();
     $this->_layout->setLayout('admin_login');
     $this->view->message = $this->_flashMessenger->getMessages();
     $form = new Admin_Form_LoginForm();
     $form->setMethod('post')->setAction($this->view->rootUrl('/admin/index/login'));
     $this->view->form = $form;
     $flashMessenger = $this->_helper->getHelper('FlashMessenger');
     if ($this->getRequest()->isPost()) {
         $username = $this->_getParam('username');
         $password = md5($this->_getParam('password'));
         if (empty($username) || empty($password)) {
             $flashMessenger->addMessage('Field Cannot Empty');
         } else {
             $db = Zend_Db_Table::getDefaultAdapter();
             $authAdapter = new Zend_Auth_Adapter_DbTable($db, 'admin_account', 'username', 'password');
             $authAdapter->setIdentity($username);
             $authAdapter->setCredential($password);
             $result = $authAdapter->authenticate();
             if ($result->isValid()) {
                 $auth = Zend_Auth::getInstance();
                 $storage = $auth->getStorage();
                 $storage->write($authAdapter->getResultRowObject(array('admin_id', 'username', 'email', 'role_id')));
                 $identity = $auth->getIdentity();
                 //set auth session expired
                 $auth_sess = new Zend_Session_Namespace($auth->getStorage()->getNamespace());
                 $auth_sess->setExpirationSeconds(strtotime('30 day', 0));
                 //store user information on session
                 Zend_Session::namespaceUnset('userInfo');
                 $userInfo = new Zend_Session_Namespace('userInfo');
                 $userInfo->id = $identity->admin_id;
                 $userInfo->name = $identity->username;
                 $userInfo->email = $identity->email;
                 $userInfo->role_id = $identity->role_id;
                 //set user allowed module list
                 $table_adminAccount = new Model_DbTable_AdminAccount();
                 $module_list = $table_adminAccount->getUserInformation($identity->admin_id);
                 $userInfo->module_list = explode(',', $module_list['allowed_module']);
                 $userInfo->canApprove = in_array(47, $userInfo->module_list);
                 //get module list from the database
                 Zend_Session::namespaceUnset('moduleList');
                 $moduleList = new Zend_Session_Namespace('moduleList');
                 $table_module = new Model_DbTable_AdminModule();
                 $module = $table_module->getAllModuleId();
                 $moduleList->module = $module;
                 //redirecting to the dashboard
                 $this->_redirect($this->view->rootUrl('/admin/index'));
             } else {
                 $flashMessenger->addMessage('Login Failed');
             }
         }
     }
 }
 /**
  * IS: -
  * FS: -
  * Desc: Mengembalikan 'isi' tree role admin yang dapat dipilih
  */
 protected function generateTree(Model_DbTable_AdminModule $table_adminModule, Model_DbTable_AdminModuleCategory $table_adminModule_Category)
 {
     $exception = "contact";
     $treeCategory = $table_adminModule_Category->getAllModuleCategory();
     $treeModule = $table_adminModule->getAllModule($exception);
     $data = array();
     /** if category data is not empty */
     if (!empty($treeCategory)) {
         /** refining data and form a tree in array */
         $treeDataList = array();
         /** convert the tree module to ASSOC array */
         foreach ($treeCategory as $value) {
             $treeDataList[$value['category_id']]['name'] = $value['category_name'];
         }
         $temp = array();
         if (!empty($treeModule)) {
             foreach ($treeModule as $value) {
                 $treeDataList[$value['category_id']]['modules'][$value['module_id']] = $value->toArray();
             }
         }
     }
     return $treeDataList;
 }