diff --git a/module/product/control.php b/module/product/control.php index 9a42ce8a53..c2b475cd9d 100644 --- a/module/product/control.php +++ b/module/product/control.php @@ -47,7 +47,7 @@ class product extends control * @access public * @return void */ - public function index($locate = 'yes', $productID = 0, $orderBy = 'code_asc', $recTotal = 0, $recPerPage = 10, $pageID = 1) + public function index($locate = 'yes', $productID = 0, $orderBy = 'order_asc', $recTotal = 0, $recPerPage = 10, $pageID = 1) { if($locate == 'yes') $this->locate($this->createLink($this->moduleName, 'browse')); @@ -529,7 +529,7 @@ class product extends control $this->view->module = $module; $this->view->method = $method; $this->view->extra = $extra; - $this->view->products = $this->dao->select('*')->from(TABLE_PRODUCT)->where('id')->in(array_keys($this->products))->orderBy('code')->fetchAll(); + $this->view->products = $this->dao->select('*')->from(TABLE_PRODUCT)->where('id')->in(array_keys($this->products))->orderBy('`order`')->fetchAll(); $this->display(); } @@ -545,7 +545,7 @@ class product extends control */ public function ajaxGetMatchedItems($keywords, $module, $method, $extra) { - $products = $this->dao->select('*')->from(TABLE_PRODUCT)->where('deleted')->eq(0)->andWhere('name')->like("%$keywords%")->orderBy('code')->fetchAll(); + $products = $this->dao->select('*')->from(TABLE_PRODUCT)->where('deleted')->eq(0)->andWhere('name')->like("%$keywords%")->orderBy('`order`')->fetchAll(); foreach($products as $key => $product) { if(!$this->product->checkPriv($product)) unset($products[$key]); @@ -556,4 +556,25 @@ class product extends control $this->view->keywords = $keywords; $this->display(); } + + /** + * Ajax order. + * + * @access public + * @return void + */ + public function ajaxOrder() + { + $idList = explode(',', trim($this->post->products, ',')); + $orderBy = $this->post->orderBy; + if(strpos($orderBy, 'order') === false) return false; + + $products = $this->dao->select('id,`order`')->from(TABLE_PRODUCT)->where('id')->in($idList)->orderBy($orderBy)->fetchPairs('order', 'id'); + foreach($products as $order => $id) + { + $newID = array_shift($idList); + if($id == $newID) continue; + $this->dao->update(TABLE_PRODUCT)->set('`order`')->eq($order)->where('id')->eq($newID)->exec(); + } + } } diff --git a/module/product/js/index.js b/module/product/js/index.js index df7cd88c73..db9a024a2b 100644 --- a/module/product/js/index.js +++ b/module/product/js/index.js @@ -3,5 +3,8 @@ $(function() $('#productTableList').on('sort.sortable', function(e, data) { // TODO: save order to server. + var list = ''; + for(i = 0; i < data.list.length; i++) list += $(data.list[i]).find('td').eq(1).find('input').val() + ','; + $.post(createLink('product', 'ajaxOrder'), {'products' : list, 'orderBy' : orderBy}); }); }); diff --git a/module/product/model.php b/module/product/model.php index 9c4ea820c2..59b3685928 100644 --- a/module/product/model.php +++ b/module/product/model.php @@ -135,7 +135,7 @@ class productModel extends model ->beginIF($status = 'noclosed')->andWhere('status')->ne('closed')->fi() ->beginIF($status != 'all' and $status != 'noclosed')->andWhere('status')->in($status)->fi() ->beginIF($limit > 0)->limit($limit)->fi() - ->orderBy('code') + ->orderBy('`order`') ->fetchAll('id'); } @@ -461,7 +461,7 @@ class productModel extends model * @access public * @return array */ - public function getStats($orderBy = 'code_asc', $pager = null) + public function getStats($orderBy = 'order_asc', $pager = null) { $this->loadModel('report'); $this->loadModel('story'); diff --git a/module/product/view/index.html.php b/module/product/view/index.html.php index 2c9926a05c..1088f7b276 100644 --- a/module/product/view/index.html.php +++ b/module/product/view/index.html.php @@ -36,7 +36,9 @@ recTotal}&recPerPage={$pager->recPerPage}&pageID={$pager->pageID}";?> - ');?> + + ');?> + idAB);?> product->name);?> story->statusList['active'] . $lang->story->common;?> @@ -54,7 +56,9 @@ + + @@ -76,7 +80,7 @@ - + '>
" . html::selectButton() . '
';?> @@ -91,4 +95,5 @@ + diff --git a/module/project/control.php b/module/project/control.php index 2c8976786e..3577afc85d 100644 --- a/module/project/control.php +++ b/module/project/control.php @@ -37,7 +37,7 @@ class project extends control * @access public * @return void */ - public function index($locate = 'yes', $status = 'undone', $projectID = 0, $orderBy = 'code_asc', $recTotal = 0, $recPerPage = 10, $pageID = 1) + public function index($locate = 'yes', $status = 'undone', $projectID = 0, $orderBy = 'order_asc', $recTotal = 0, $recPerPage = 10, $pageID = 1) { if($locate == 'yes') $this->locate($this->createLink('project', 'task')); @@ -1692,7 +1692,7 @@ class project extends control $this->view->module = $module; $this->view->method = $method; $this->view->extra = $extra; - $this->view->projects = $this->dao->select('*')->from(TABLE_PROJECT)->where('id')->in(array_keys($this->projects))->orderBy('code')->fetchAll(); + $this->view->projects = $this->dao->select('*')->from(TABLE_PROJECT)->where('id')->in(array_keys($this->projects))->orderBy('order')->fetchAll(); $this->display(); } @@ -1708,7 +1708,7 @@ class project extends control */ public function ajaxGetMatchedItems($keywords, $module, $method, $extra) { - $projects = $this->dao->select('*')->from(TABLE_PROJECT)->where('deleted')->eq(0)->andWhere('name')->like("%$keywords%")->orderBy('code')->fetchAll(); + $projects = $this->dao->select('*')->from(TABLE_PROJECT)->where('deleted')->eq(0)->andWhere('name')->like("%$keywords%")->orderBy('order')->fetchAll(); foreach($projects as $key => $project) { if(!$this->project->checkPriv($project)) unset($projects[$key]); @@ -1719,4 +1719,25 @@ class project extends control $this->view->keywords = $keywords; $this->display(); } + + /** + * Ajax order. + * + * @access public + * @return void + */ + public function ajaxOrder() + { + $idList = explode(',', trim($this->post->projects, ',')); + $orderBy = $this->post->orderBy; + if(strpos($orderBy, 'order') === false) return false; + + $projects = $this->dao->select('id,`order`')->from(TABLE_PROJECT)->where('id')->in($idList)->orderBy($orderBy)->fetchPairs('order', 'id'); + foreach($projects as $order => $id) + { + $newID = array_shift($idList); + if($id == $newID) continue; + $this->dao->update(TABLE_PROJECT)->set('`order`')->eq($order)->where('id')->eq($newID)->exec(); + } + } } diff --git a/module/project/js/index.js b/module/project/js/index.js index 9db9150f86..205cde1b3e 100644 --- a/module/project/js/index.js +++ b/module/project/js/index.js @@ -3,5 +3,8 @@ $(function() $('#projectTableList').on('sort.sortable', function(e, data) { // TODO: save order to server. + var list = ''; + for(i = 0; i < data.list.length; i++) list += $(data.list[i]).find('td').eq(1).find('input').val() + ','; + $.post(createLink('project', 'ajaxOrder'), {'projects' : list, 'orderBy' : orderBy}); }); }); diff --git a/module/project/model.php b/module/project/model.php index 01e7766462..b79b648f1c 100644 --- a/module/project/model.php +++ b/module/project/model.php @@ -547,7 +547,7 @@ class projectModel extends model ->beginIF($status == 'undone')->andWhere('t2.status')->ne('done')->fi() ->beginIF($status == 'isdoing')->andWhere('t2.status')->ne('done')->andWhere('t2.status')->ne('suspended')->fi() ->beginIF($status != 'all' and $status != 'isdoing' and $status != 'undone')->andWhere('status')->in($status)->fi() - ->orderBy('code') + ->orderBy('order') ->beginIF($limit)->limit($limit)->fi() ->fetchAll('id'); } @@ -558,7 +558,7 @@ class projectModel extends model ->beginIF($status == 'isdoing')->andWhere('status')->ne('done')->andWhere('status')->ne('suspended')->fi() ->beginIF($status != 'all' and $status != 'isdoing' and $status != 'undone')->andWhere('status')->in($status)->fi() ->andWhere('deleted')->eq(0) - ->orderBy('code') + ->orderBy('order') ->beginIF($limit)->limit($limit)->fi() ->fetchAll('id'); } @@ -612,7 +612,7 @@ class projectModel extends model * @access public * @return void */ - public function getProjectStats($status = 'undone', $productID = 0, $itemCounts = 30, $orderBy = 'code', $pager = null) + public function getProjectStats($status = 'undone', $productID = 0, $itemCounts = 30, $orderBy = 'order', $pager = null) { /* Init vars. */ $projects = $this->getList($status, 0, $productID); diff --git a/module/project/view/index.html.php b/module/project/view/index.html.php index debe8805b4..1f0718e130 100644 --- a/module/project/view/index.html.php +++ b/module/project/view/index.html.php @@ -30,7 +30,9 @@ recTotal}&recPerPage={$pager->recPerPage}&pageID={$pager->pageID}";?> - ');?> + + ');?> + idAB);?> project->name);?> project->code);?> @@ -48,7 +50,9 @@ + + @@ -73,7 +77,7 @@ - + '>
" . html::selectButton() . '
';?> @@ -87,4 +91,5 @@ + diff --git a/module/upgrade/model.php b/module/upgrade/model.php index 0732e85930..257f67b306 100644 --- a/module/upgrade/model.php +++ b/module/upgrade/model.php @@ -117,6 +117,9 @@ class upgradeModel extends model case '6_4': case '7_0': $this->execSQL($this->getUpgradeFile('7.0')); + case '7_1': + $this->execSQL($this->getUpgradeFile('7.1')); + $this->initOrder(); default: if(!$this->isError()) $this->setting->updateVersion($this->config->version); } @@ -183,6 +186,7 @@ class upgradeModel extends model case '6_3': case '6_4': case '7_0': $confirmContent .= file_get_contents($this->getUpgradeFile('7.0')); + case '7_1': $confirmContent .= file_get_contents($this->getUpgradeFile('7.1')); } return str_replace('zt_', $this->config->db->prefix, $confirmContent); } @@ -914,6 +918,25 @@ class upgradeModel extends model return true; } + /** + * Init order. + * + * @access public + * @return bool + */ + public function initOrder() + { + $dataList = $this->dao->select('id')->from(TABLE_PRODUCT)->orderBy('code_asc')->fetchAll(); + $i = 1; + foreach($dataList as $data) $this->dao->update(TABLE_PRODUCT)->set('`order`')->eq($i++)->where('id')->eq($data->id)->exec(); + + $dataList = $this->dao->select('id')->from(TABLE_PROJECT)->orderBy('code_asc')->fetchAll(); + $i = 1; + foreach($dataList as $data) $this->dao->update(TABLE_PROJECT)->set('`order`')->eq($i++)->where('id')->eq($data->id)->exec(); + + return true; + } + /** * Judge any error occers. *