public function recordsAction() { $this->_helper->layout->disableLayout(); $this->_helper->viewRenderer->setNoRender(true); $this->getResponse()->setHeader('Content-Type', 'application/json'); // require_once APPLICATION_PATH . '/modules/asset/models/DbTable/Loan.php'; $loan = new Asset_Model_DbTable_Loan(); $sort_column = $this->_getParam('sortname', 'Ma_tai_san'); # 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', 'Ma_tai_san'); $search_for = $this->_getParam('query', ''); $mode = (int) $this->_getParam('mode', 2); switch ($mode) { case 1: // list all item $select = $loan->select(Zend_Db_Table::SELECT_WITH_FROM_PART)->setIntegrityCheck(false)->join(array('u' => 'memberinfor'), 'loaninfor.UserID = u.UserID', array('Username' => 'u.Username'))->join(array('i' => 'iteminfor'), 'loaninfor.Ma_tai_san = i.Ma_tai_san', array('ItemID' => 'i.ItemID', 'Ten_tai_san' => 'i.Ten_tai_san', 'Description' => 'i.Description', 'Type' => 'i.Type', 'StartDate' => 'i.StartDate', 'Price' => 'i.Price', 'WarrantyTime' => 'i.WarrantyTime', 'Status' => 'i.Status', 'Place' => 'i.Place'))->order("{$sort_column} {$sort_order}")->limit($limit, $offset); break; case 2: // list all item user dang muon // list all item user dang muon default: $uid = Zend_Auth::getInstance()->getIdentity()->UserID; $select = $loan->select(Zend_Db_Table::SELECT_WITH_FROM_PART)->setIntegrityCheck(false)->join(array('u' => 'memberinfor'), 'loaninfor.UserID = u.UserID', array('Username' => 'u.Username'))->join(array('i' => 'iteminfor'), 'loaninfor.Ma_tai_san = i.Ma_tai_san', array('ItemID' => 'i.ItemID', 'Ten_tai_san' => 'i.Ten_tai_san', 'Description' => 'i.Description', 'Type' => 'i.Type', 'StartDate' => 'i.StartDate', 'Price' => 'i.Price', 'WarrantyTime' => 'i.WarrantyTime', 'Status' => 'i.Status', 'Place' => 'i.Place'))->where("loaninfor.UserID = '{$uid}'")->order("{$sort_column} {$sort_order}")->limit($limit, $offset); break; } 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(); $total = $pager->getTotalItemCount(); if ($total == 0) { echo Zend_Json::encode(array('page' => $page, 'total' => $total, 'rows' => NULL)); exit; } 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. if (isset($record['Type']) && isset($record['Status'])) { switch ($record['Type']) { case 0: $record['Type'] = 'Bảo mật cao'; break; case 1: $record['Type'] = 'Bảo mật thấp'; break; default: $record['Type'] = '-'; break; } switch ($record['Status']) { case 0: $record['Status'] = 'Có thể mượn'; break; case 1: $record['Status'] = 'Đang cho mượn'; break; case 2: $record['Status'] = 'Hỏng'; break; default: $record['Status'] = '-'; break; } } $rows[] = array('id' => $record['Ma_tai_san'], 'cell' => $record->toArray()); } $jsonData = array('page' => $page, 'total' => $total, 'rows' => $rows); echo Zend_Json::encode($jsonData); }
public function deleteAction() { $this->_helper->layout->disableLayout(); $this->_helper->viewRenderer->setNoRender(true); if ($this->getRequest()->isPost()) { $UserID = (int) $this->getRequest()->getPost('UserID', -1); if ($UserID > 0) { require_once APPLICATION_PATH . '/modules/user/models/DbTable/Member.php'; require_once APPLICATION_PATH . '/modules/asset/models/DbTable/Loan.php'; $member = new User_Model_DbTable_Member(); $loan = new Asset_Model_DbTable_Loan(); if ($loan->fetchRow("UserID = '{$UserID}'")) { $status = 'error'; $msg = 'User van con muon TS'; } else { $member->deleteMember($UserID); $status = 'success'; $msg = 'Delete user success'; } } else { $status = 'error'; $msg = 'Not found this user.'; } } else { $status = 'error'; $msg = 'Not found POST value.'; } echo Zend_Json::encode(array('status' => $status, 'msg' => $msg)); }
public function addAction() { //user gui di $this->_helper->layout->disableLayout(); $this->_helper->viewRenderer->setNoRender(true); // require_once APPLICATION_PATH . '/modules/asset/forms/request.php'; // require_once APPLICATION_PATH . '/modules/asset/models/DbTable/Request.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_Request(); if ($this->getRequest()->isPost()) { $formData = $this->getRequest()->getPost(); if ($form->isValid($formData)) { $MaTS = $form->getValue('MaTS'); $Type = (int) $form->getValue('Type'); $Date = date('Y-m-d'); $Detail = $form->getValue('Detail'); $request = new Asset_Model_DbTable_Request(); $item = new Asset_Model_DbTable_Item(); $uInfo = (array) Zend_Auth::getInstance()->getIdentity(); $itemInfo = $item->getItemFromMa($MaTS); if ($itemInfo != NULL) { if ($Type == 1) { $loan = new Asset_Model_DbTable_Loan(); $loInfo = $loan->getLoanFromMa($MaTS); if ($loInfo != NULL && $loInfo['UserID'] == $uInfo['UserID']) { if ($uInfo['Role'] == 2) { $status = 'Error'; $msg = 'You cannot request upgrade item.'; echo Zend_Json::encode(array('status' => $status, 'msg' => $msg)); exit; } $request->addRequest($uInfo['UserID'], $MaTS, $Type, $Detail, $Date, '0'); $status = 'Success'; $msg = 'Request success'; } else { $status = 'Error'; $msg = 'Bạn không thể yêu cầu nâng cấp tài sản bạn đang không sở hữu.'; } } else { if ($itemInfo['Status'] != 2) { $request->addRequest($uInfo['UserID'], $MaTS, $Type, $Detail, $Date, '0'); $status = 'Success'; $msg = 'Request success'; } else { $status = 'Error'; $msg = 'Tài sản đang hỏng.'; } } } 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)); }