function down_position() { $min = new menu(); $min->select_min('position'); $min->where('position >', $this->position); $min->get(); $o = new menu(); $o->where('position', $min->position); $o->get(); if ($o->result_count() > 0) { $tg = $this->position; $this->position = $o->position; $o->position = $tg; $o->save(); $this->save(); return true; } else { return false; } }
function active($id = 0, $value) { $menu = new menu($id); if (!$menu->exists()) { show_404(); } $menu->active = ($menu->active + 1) % 2; $menu->save(); flash_message('success', "Kích hoạt thành công."); redirect($this->admin . 'menus/list_all/'); }
function run() { global $user; global $layout; global $DB; $out = ''; $item = new menu(); switch ($_REQUEST['act']) { case 'json': case 1: // json data retrieval & operations switch ($_REQUEST['oper']) { case 'del': // remove rows $ids = $_REQUEST['ids']; foreach ($ids as $id) { $item->load($id); $item->delete(); } echo json_encode(true); break; default: // list or search $page = intval($_REQUEST['page']); $max = intval($_REQUEST['rows']); $offset = ($page - 1) * $max; $orderby = $_REQUEST['sidx'] . ' ' . $_REQUEST['sord']; $where = " 1=1 "; if ($_REQUEST['_search'] == 'true' || isset($_REQUEST['quicksearch'])) { if (isset($_REQUEST['quicksearch'])) { $where .= $item->quicksearch($_REQUEST['quicksearch']); } else { if (isset($_REQUEST['filters'])) { $where .= navitable::jqgridsearch($_REQUEST['filters']); } else { // single search $where .= ' AND ' . navitable::jqgridcompare($_REQUEST['searchField'], $_REQUEST['searchOper'], $_REQUEST['searchString']); } } } $DB->queryLimit('id,lid,codename,icon,enabled', 'nv_menus', $where, $orderby, $offset, $max); $dataset = $DB->result(); $total = $DB->foundRows(); //echo $DB->get_last_error(); $out = array(); for ($i = 0; $i < count($dataset); $i++) { $out[$i] = array(0 => $dataset[$i]['id'], 1 => $dataset[$i]['codename'], 2 => '<img src="' . NAVIGATE_URL . '/' . $dataset[$i]['icon'] . '" />', 3 => '[' . $dataset[$i]['lid'] . '] ' . t($dataset[$i]['lid'], $dataset[$i]['lid']), 4 => $dataset[$i]['enabled'] == 1 ? '<img src="img/icons/silk/accept.png" />' : '<img src="img/icons/silk/cancel.png" />'); } navitable::jqgridJson($out, $page, $offset, $max, $total); break; } session_write_close(); exit; break; case 'edit': case 2: // edit/new form if (!empty($_REQUEST['id'])) { $item->load(intval($_REQUEST['id'])); } if (isset($_REQUEST['form-sent'])) { $item->load_from_post(); try { $item->save(); $layout->navigate_notification(t(53, "Data saved successfully."), false, false, 'fa fa-check'); } catch (Exception $e) { $layout->navigate_notification($e->getMessage(), true, true); } } $out = functions_form($item); break; case 'delete': case 4: // remove if (!empty($_REQUEST['id'])) { $item->load(intval($_REQUEST['id'])); if ($item->delete() > 0) { $layout->navigate_notification(t(55, 'Item removed successfully.'), false); $out = functions_list(); } else { $layout->navigate_notification(t(56, 'Unexpected error.'), false); $out = functions_form($item); } } break; case 'list': case 0: // list / search result // list / search result default: $out = functions_list(); break; } return $out; }