diff --git a/module/program/control.php b/module/program/control.php index 334c4968ea..6ac6926b41 100644 --- a/module/program/control.php +++ b/module/program/control.php @@ -59,7 +59,7 @@ class program extends control * @access public * @return void */ - public function PGMBrowse($status = 'all', $orderBy = 'id_asc,order_desc', $recTotal = 0, $recPerPage = 50, $pageID = 1) + public function PGMBrowse($status = 'all', $orderBy = 'order_asc', $recTotal = 0, $recPerPage = 50, $pageID = 1) { $this->lang->navGroup->program = 'program'; $this->lang->program->switcherMenu = $this->program->getPGMCommonAction(); @@ -610,6 +610,26 @@ class program extends control } } + /** + * Update program order. + * + * @access public + * @return string + */ + public function updateOrder() + { + $programs = $this->post->programs; + foreach($programs as $id => $order) + { + $this->dao->update(TABLE_PROJECT) + ->set('`order`')->eq($order) + ->where('id')->eq($id) + ->exec(); + } + + $this->send(array('result' => 'success')); + } + /** * Project index view. * diff --git a/module/program/view/pgmbrowsebylist.html.php b/module/program/view/pgmbrowsebylist.html.php index 86bed936bd..c5c7c99046 100644 --- a/module/program/view/pgmbrowsebylist.html.php +++ b/module/program/view/pgmbrowsebylist.html.php @@ -136,7 +136,7 @@ $(function() var newOrder = ordersList[index]; orders[item.id] = typeof newOrder === 'number' ? newOrder : item.order * 5; }); - $.post(createLink('project', 'updateOrder'), {'projects' : orders, 'orderBy' : orderBy}); + $.post(createLink('program', 'updateOrder'), {'programs' : orders, 'orderBy' : orderBy}); var $thead = $list.closest('table').children('thead'); $thead.find('.headerSortDown, .headerSortUp').removeClass('headerSortDown headerSortUp').addClass('header'); diff --git a/module/project/control.php b/module/project/control.php index 79ac78fbe0..6e72a625ce 100644 --- a/module/project/control.php +++ b/module/project/control.php @@ -2335,29 +2335,17 @@ class project extends control */ public function updateOrder() { - $orderBy = $this->post->orderBy; - if(strpos($orderBy, 'order') === false) - { - return $this->send(array('result' => 'fail')); - } - $idList = explode(',', trim($this->post->projects, ',')); - $projects = $this->dao->select('id, `order`')->from(TABLE_PROJECT) - ->where('id')->in($idList) - ->fetchPairs('id', 'order'); + $orderBy = $this->post->orderBy; + if(strpos($orderBy, 'order') === false) return false; - foreach($projects as $id => $order) + $projects = $this->dao->select('id,`order`')->from(TABLE_PROJECT)->where('id')->in($idList)->orderBy($orderBy)->fetchPairs('order', 'id'); + foreach($projects as $order => $id) { - $newOrder = $orders[$id]; - if($order != $newOrder) - { - $this->dao->update(TABLE_PROJECT) - ->set('`order`')->eq($newOrder) - ->where('id')->eq($id) - ->exec(); - } + $newID = array_shift($idList); + if($id == $newID) continue; + $this->dao->update(TABLE_PROJECT)->set('`order`')->eq($order)->where('id')->eq($newID)->exec(); } - $this->send(array('result' => 'success')); } /**