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/History.php'; $history = new Asset_Model_DbTable_History(); $sort_column = $this->_getParam('sortname', 'Date'); # 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', 'ItemID'); $search_for = $this->_getParam('query', ''); $uIfno = (array) Zend_Auth::getInstance()->getIdentity(); $uRole = $uIfno['Role']; $uid = $uIfno['UserID']; if ($uRole == 0 || $uRole == 1) { $select = $history->select(Zend_Db_Table::SELECT_WITH_FROM_PART)->setIntegrityCheck(false)->join(array('lu' => 'memberinfor'), 'historyinfor.LUserID = lu.UserID', array('LUsername' => 'lu.Username'))->join(array('ru' => 'memberinfor'), 'historyinfor.RUserID = ru.UserID', array('RUsername' => 'ru.Username'))->join('iteminfor', 'historyinfor.ItemID = iteminfor.ItemID', array('Ma_tai_san', 'Ten_tai_san'))->order("{$sort_column} {$sort_order}")->limit($limit, $offset); } else { $select = $history->select(Zend_Db_Table::SELECT_WITH_FROM_PART)->setIntegrityCheck(false)->join(array('lu' => 'memberinfor'), 'historyinfor.LUserID = lu.UserID', array('LUsername' => 'lu.Username'))->join(array('ru' => 'memberinfor'), 'historyinfor.RUserID = ru.UserID', array('RUsername' => 'ru.Username'))->join('iteminfor', 'historyinfor.ItemID = iteminfor.ItemID', array('Ma_tai_san', 'Ten_tai_san'))->where("historyinfor.LUserID = '{$uid}' OR historyinfor.RUserID = '{$uid}'")->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(); $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. $rows[] = array('id' => $record['HistoryID'], '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()) { $MaTS = $this->getRequest()->getPost('MaTS'); // require_once APPLICATION_PATH . '/modules/asset/models/DbTable/Loan.php'; // require_once APPLICATION_PATH . '/modules/asset/models/DBTable/History.php'; // require_once APPLICATION_PATH . '/modules/asset/models/DBTable/Item.php'; $loan = new Asset_Model_DbTable_Loan(); $history = new Asset_Model_DbTable_History(); $item = new Asset_Model_DbTable_Item(); $loanInfo = $loan->getLoanFromMa($MaTS); if ($loanInfo != NULL) { $itemInfo = $item->getItemFromMa($MaTS); if ($itemInfo != NULL) { //Zend_Debug::dump($item->editItem($itemInfo['ItemID'], $MaTS, $itemInfo['Ten_tai_san'], $itemInfo['Description'], $itemInfo['Type'], $itemInfo['StartDate'], $itemInfo['Price'], $itemInfo['WarrantyTime'], 0, 'Kho'));exit; if ($history->addHistory($loanInfo['UserID'], Zend_Auth::getInstance()->getIdentity()->UserID, $itemInfo['ItemID'], 'Tra thiet bi', date('Y-m-d')) && $item->editItem($itemInfo['ItemID'], $MaTS, $itemInfo['Ten_tai_san'], $itemInfo['Description'], $itemInfo['Type'], $itemInfo['StartDate'], $itemInfo['Price'], $itemInfo['WarrantyTime'], 0, 'Kho') == 1 && $loan->deleteLoan($MaTS) != NULL) { $status = 'Success'; $msg = 'Update database success.'; } else { $status = 'Error'; $msg = 'Update database fail.'; } } else { $status = 'Error'; $msg = 'Not found record'; } } else { $status = 'Error'; $msg = 'Not found record'; } } else { $status = 'Error'; $msg = 'Not found POST value.'; } echo Zend_Json::encode(array('status' => $status, 'msg' => $msg)); }