public function editAction()
 {
     if (Zend_Auth::getInstance()->hasIdentity()) {
         $userInfo = Zend_Auth::getInstance()->getIdentity();
     } else {
         $this->_helper->getHelper('FlashMessenger')->addMessage("You haven't permission.");
         $this->_redirect('/front/auth/nopermission');
     }
     include_once APPLICATION_PATH . '/modules/user/forms/Profile.php';
     $form = new User_Form_Profile();
     //$form->submit->setLabel('Save');
     $this->view->form = $form;
     include_once APPLICATION_PATH . '/modules/user/models/DbTable/Member.php';
     if ($this->getRequest()->isPost()) {
         $formData = $this->getRequest()->getPost();
         if ($form->isValid($formData)) {
             $UserID = (int) $form->getValue('UserID');
             if ($UserID != $userInfo->UserID) {
                 $this->_helper->getHelper('FlashMessenger')->addMessage("You haven't permission.");
                 $this->_redirect('/front/auth/nopermission');
             }
             $username = $form->getValue('Username');
             $password = $form->getValue('Password');
             $repassword = $form->getValue('RePassword');
             $role = $userInfo->Role;
             $fullname = $form->getValue('FullName');
             $email = $form->getValue('Email');
             $birthday = $form->getValue('Birthday');
             $group = $form->getValue('Group');
             $phone = $form->getValue('Phone');
             $address = $form->getValue('Address');
             if ($password == $repassword) {
                 $password = $this->encodePassword($repassword);
                 $member = new User_Model_DbTable_Member();
                 $return = $member->editMember($UserID, $username, $password, $role, $email, $birthday, $fullname, $group, $phone, $address);
                 switch ($return) {
                     case -1:
                         // loi email da ton tai
                         break;
                     case -2:
                         // loi user da ton tai
                         break;
                     case 0:
                         // loi ko update dc
                         break;
                     default:
                         // update thanh cong
                         $this->_redirect('/user/profile/detail/UserID/' . $UserID);
                         break;
                 }
             }
         } else {
             $form->populate($formData);
         }
     } else {
         $member = new User_Model_DbTable_Member();
         $form->populate($member->getMember($userInfo->UserID));
     }
 }
 public function addAction()
 {
     $this->_helper->layout->disableLayout();
     $this->_helper->viewRenderer->setNoRender(true);
     //        require_once APPLICATION_PATH . '/modules/asset/forms/Upgrade.php';
     //        require_once APPLICATION_PATH . '/modules/asset/models/DbTable/Upgrade.php';
     //        require_once APPLICATION_PATH . '/modules/asset/models/DbTable/Item.php';
     //        require_once APPLICATION_PATH . '/modules/user/models/DbTable/Member.php';
     $form = new Asset_Form_Upgrade();
     if ($this->getRequest()->isPost()) {
         $formData = $this->getRequest()->getPost();
         if ($form->isValid($formData)) {
             $UpgradeID = $form->getValue('UpgradeID');
             $MaTS = $form->getValue('MaTS');
             $Username = $form->getValue('Username');
             $Manager = $form->getValue('Manager');
             $Date = $form->getValue('Date');
             $Detail = $form->getValue('Detail');
             $upgrade = new Asset_Model_DbTable_Upgrade();
             $item = new Asset_Model_DbTable_Item();
             $user = new User_Model_DbTable_Member();
             $itemInfo = $item->getItemFromMa($MaTS);
             if ($itemInfo != NULL) {
                 $uname = $user->getMemberFromUsername($Username);
                 if ($uname == NULL) {
                     $status = 'Error';
                     $msg = 'Not found Username.';
                     echo Zend_Json::encode(array('status' => $status, 'msg' => $msg));
                     exit;
                 }
                 $umana = $user->getMemberFromUsername($Manager);
                 if ($umana == NULL) {
                     $status = 'Error';
                     $msg = 'Not found Manager.';
                     echo Zend_Json::encode(array('status' => $status, 'msg' => $msg));
                     exit;
                 }
                 $upgrade->addUpgrade($uname['UserID'], $umana['UserID'], $itemInfo['ItemID'], $Detail, $Date);
                 $status = 'Success';
                 $msg = 'Upgrade success';
             } else {
                 $status = 'Error';
                 $msg = 'Not found item.';
             }
         } else {
             $status = 'Error';
             $msg = 'POST value format inaild.';
         }
     } else {
         $status = 'Error';
         $msg = 'Not found POST value.';
     }
     echo Zend_Json::encode(array('status' => $status, 'msg' => $msg));
 }
 public function addAction()
 {
     $this->_helper->layout->disableLayout();
     $this->_helper->viewRenderer->setNoRender(true);
     if ($this->getRequest()->isPost()) {
         $from = Zend_Auth::getInstance()->getIdentity()->UserID;
         $touser = $this->getRequest()->getPost('To');
         $title = $this->getRequest()->getPost('Title');
         $detail = $this->getRequest()->getPost('Detail');
         //            require_once APPLICATION_PATH . '/modules/user/models/DbTable/Member.php';
         $us = new User_Model_DbTable_Member();
         if ($us->getMemberFromUsername($touser) == NULL) {
             $toUserInfo = $us->getMemberFromUsername($touser);
             // ko ton tai to use
             $status = 'Error';
             $msg = 'Not found to member';
             echo Zend_Json::encode(array('status' => $status, 'msg' => $msg));
             exit;
         }
         $toUserInfo = $us->getMemberFromUsername($touser);
         $to = $toUserInfo['UserID'];
         $me = new Asset_Model_DbTable_Message();
         if ($me->addMessage($from, $to, $title, $detail)) {
             // success
             $status = 'Success';
             $msg = 'Create success';
         } else {
             // fail
             $status = 'Error';
             $msg = 'Not create new message.';
         }
     } else {
         $status = 'Error';
         $msg = 'Not found POST value.';
     }
     echo Zend_Json::encode(array('status' => $status, 'msg' => $msg));
 }
 public function recordsAction()
 {
     $this->_helper->layout->disableLayout();
     $this->_helper->viewRenderer->setNoRender(true);
     require_once APPLICATION_PATH . '/modules/user/models/DbTable/Member.php';
     $members = new User_Model_DbTable_Member();
     $sort_column = $this->_getParam('sortname', 'UserID');
     # this will default to undefined
     $sort_order = $this->_getParam('sortorder', 'desc');
     # this will default to undefined
     $page = $this->_getParam('page', 1);
     $limit = $this->_getParam('rp', 10);
     $offset = ($page - 1) * $limit;
     $search_column = $this->_getParam('qtype', 'Username');
     $search_for = $this->_getParam('query', '');
     $select = $members->select()->order("{$sort_column} {$sort_order}")->limit($limit, $offset);
     if (!empty($search_column) && !empty($search_for)) {
         $select->where($search_column . ' LIKE ?', '%' . $search_for . '%');
     }
     $pager = Zend_Paginator::factory($select);
     $pager->setCurrentPageNumber($page);
     $pager->setItemCountPerPage($limit);
     $records = $pager->getIterator();
     foreach ($records as $record) {
         //If cell's elements have named keys, they must match column names
         //Only cell's with named keys and matching columns are order independent.
         switch ($record['Role']) {
             case 0:
                 $record['Role'] = 'SuperAdmin';
                 break;
             case 1:
                 $record['Role'] = 'Admin';
                 break;
             case 2:
                 $record['Role'] = 'IT';
                 break;
             case 3:
                 $record['Role'] = 'User';
                 break;
             default:
                 $record['Role'] = '-';
                 break;
         }
         $rows[] = array('id' => $record['UserID'], 'cell' => $record->toArray());
     }
     $this->getResponse()->setHeader('Content-Type', 'application/json');
     $jsonData = array('page' => $page, 'total' => $pager->getTotalItemCount(), 'rows' => $rows);
     echo Zend_Json::encode($jsonData);
 }
 public function detailAction()
 {
     $this->_helper->layout->disableLayout();
     $this->_helper->viewRenderer->setNoRender(true);
     if ($this->getRequest()->isPost()) {
         $MaTS = $this->getRequest()->getPost('MaTS', -1);
         //        $MaTS = $this->getRequest()->getParam('MaTS',-1);
         if ($MaTS != -1) {
             //                require_once APPLICATION_PATH . '/modules/asset/models/DbTable/Item.php';
             $loan = new Asset_Model_DbTable_Loan();
             $ts = new Asset_Model_DbTable_Item();
             $usi = new User_Model_DbTable_Member();
             $status = 'success';
             $data1 = (array) $loan->getLoanFromMa($MaTS);
             $data2 = (array) $ts->getItemFromMa($MaTS);
             $data3 = (array) $usi->getMember($data1['UserID']);
             $data = array('MaTS' => $MaTS, 'TenTS' => $data2['Ten_tai_san'], 'Nguoi_muon' => $data3['FullName'], 'Username' => $data3['Username'], 'Ngay_muon' => $data1['Date'], 'Chi_tiet' => $data1['Detail']);
             echo Zend_Json::encode(array('status' => $status, 'data' => $data));
         } else {
             $status = 'error';
             $msg = 'Not found this item.';
             echo Zend_Json::encode(array('status' => $status, 'msg' => $msg));
         }
     } else {
         $status = 'error';
         $msg = 'Not found POST value.';
         echo Zend_Json::encode(array('status' => $status, 'msg' => $msg));
     }
 }