table("pt_keyword"), $db, 'id', 'name'); /* act操作项的初始化 */ if (empty($_REQUEST['act'])) { $_REQUEST['act'] = 'list'; } else { $_REQUEST['act'] = trim($_REQUEST['act']); } /*------------------------------------------------------ */ //-- 商品分类列表 /*------------------------------------------------------ */ if ($_REQUEST['act'] == 'list') { /* 获取分类列表 */ $search_list = search_list(); /* 模板赋值 */ $smarty->assign('ur_here', '搜尋字串清單'); $smarty->assign('action_link', array('href' => 'search.php?act=add', 'text' => '新增搜尋字串')); $smarty->assign('full_page', 1); $smarty->assign('search_list', $search_list['search_list']); /* 列表页面 */ assign_query_info(); $smarty->display('search_list.htm'); } /*------------------------------------------------------ */ //-- 排序、分页、查询 /*------------------------------------------------------ */ elseif ($_REQUEST['act'] == 'query') { $search_list = search_list(); $smarty->assign('search_list', $search_list['search_list']); make_json_result($smarty->fetch('search_list.htm')); } /*------------------------------------------------------ */ //-- 添加商品分类 /*------------------------------------------------------ */ if ($_REQUEST['act'] == 'add') { /* 权限检查 */ // admin_priv('cat_manage'); /* 模板赋值 */ $smarty->assign('ur_here', '新增搜尋字串'); $smarty->assign('action_link', array('href' => 'search.php?act=list', 'text' => '搜尋字串清單')); // $smarty->assign('cat_select', cat_list(0, 0, true)); $smarty->assign('form_act', 'insert'); $smarty->assign('search', array('enable' => 1,'sort_order'=>50,'id'=>0)); /* 显示页面 */ assign_query_info(); $smarty->display('search_info.htm'); } /*------------------------------------------------------ */ //-- 新增處理 /*------------------------------------------------------ */ if ($_REQUEST['act'] == 'insert') { /* 权限检查 */ // admin_priv('cat_manage'); /* 初始化变量 */ $search['id'] = !empty($_POST['id']) ? intval($_POST['id']): 0; $search['sort_order'] = !empty($_POST['sort_order']) ? intval($_POST['sort_order']) : 0; $search['name'] = !empty($_POST['name']) ? trim($_POST['name']) : ''; $search['keyword'] = !empty($_POST['keyword']) ? trim($_POST['keyword']) : ''; $search['mdesc'] = !empty($_POST['mdesc']) ? trim($_POST['mdesc']) : ''; $search['enable'] = !empty($_POST['enable']) ? intval($_POST['enable']) : 0; /* 入库的操作 */ if ($db->autoExecute($ecs->table('pt_keyword'), $search) !== false) { $id = $db->insert_id(); admin_log($_POST['name'], 'add', 'search'); // 记录管理员操作 clear_cache_files(); // 清除缓存 /*添加链接*/ $link[0]['text'] = '繼續新增'; $link[0]['href'] = 'search.php?act=add'; $link[1]['text'] = '搜尋字串清單'; $link[1]['href'] = 'search.php?act=list'; sys_msg('新增成功', 0, $link); } } /*------------------------------------------------------ */ //-- 编辑商品分类信息 /*------------------------------------------------------ */ if ($_REQUEST['act'] == 'edit') { // admin_priv('cat_manage'); // 权限检查 $id = intval($_REQUEST['id']); $search_info = get_search_info($id); // 查询分类信息数据 /* 模板赋值 */ $smarty->assign('ur_here', '編輯設施'); $smarty->assign('action_link', array('text' => '搜尋字串清單', 'href' => 'search.php?act=list')); //分类是否存在首页推荐 $smarty->assign('search', $search_info); $smarty->assign('form_act', 'update'); /* 显示页面 */ assign_query_info(); $smarty->display('search_info.htm'); } /*------------------------------------------------------ */ //-- 编辑商品分类信息 /*------------------------------------------------------ */ if ($_REQUEST['act'] == 'update') { /* 权限检查 */ // admin_priv('cat_manage'); /* 初始化变量 */ $id = !empty($_POST['id']) ? intval($_POST['id']) : 0; $search['sort_order'] = !empty($_POST['sort_order']) ? intval($_POST['sort_order']) : 0; $search['name'] = !empty($_POST['name']) ? trim($_POST['name']) : ''; $search['keyword'] = !empty($_POST['keyword']) ? trim($_POST['keyword']) : ''; $search['mdesc'] = !empty($_POST['mdesc']) ? trim($_POST['mdesc']) : ''; $search['enable'] = !empty($_POST['enable']) ? intval($_POST['enable']) : 0; if ($db->autoExecute($ecs->table('pt_keyword'), $search, 'UPDATE', "id='$id'")) { /* 更新分类信息成功 */ clear_cache_files(); // 清除缓存 admin_log($_POST['name'], 'edit', 'search'); // 记录管理员操作 /* 提示信息 */ $link[] = array('text' => '搜尋字串清單', 'href' => 'search.php?act=list'); sys_msg('修改成功', 0, $link); } } /*------------------------------------------------------ */ //-- 编辑排序序号 /*------------------------------------------------------ */ if ($_REQUEST['act'] == 'edit_sort_order') { // check_authz_json('cat_manage'); $id = intval($_POST['id']); $val = intval($_POST['val']); if (search_update($id, array('sort_order' => $val))) { clear_cache_files(); // 清除缓存 make_json_result($val); } else { make_json_error($db->error()); } } /*------------------------------------------------------ */ //-- 切换是否显示 /*------------------------------------------------------ */ if ($_REQUEST['act'] == 'toggle_enable') { // check_authz_json('cat_manage'); $id = intval($_POST['id']); $val = intval($_POST['val']); if (search_update($id, array('enable' => $val)) != false) { clear_cache_files(); make_json_result($val); } else { make_json_error($db->error()); } } /*------------------------------------------------------ */ //-- 删除商品分类 /*------------------------------------------------------ */ if ($_REQUEST['act'] == 'remove') { // check_authz_json('cat_manage'); /* 初始化分类ID并取得分类名称 */ $id = intval($_GET['id']); $cat_name = $db->getOne('SELECT name FROM ' .$ecs->table('pt_keyword'). " WHERE id='$id'"); /* 如果不存在下级子分类和商品,则删除之 */ /* 删除分类 */ $sql = 'DELETE FROM ' .$ecs->table('pt_keyword'). " WHERE id = '$id'"; if ($db->query($sql)) { clear_cache_files(); admin_log($name, 'remove', 'search'); } $url = 'search.php?act=query&' . str_replace('act=remove', '', $_SERVER['QUERY_STRING']); ecs_header("Location: $url\n"); exit; } function get_search_info($id) { $sql = "SELECT * FROM " .$GLOBALS['ecs']->table('pt_keyword'). " WHERE id='$id' LIMIT 1"; return $GLOBALS['db']->getRow($sql); } function search_list() { $result = get_filter(); if ($result === false) { /* 过滤条件 */ $filter['keywords'] = empty($_REQUEST['keywords']) ? '' : trim($_REQUEST['keywords']); if (isset($_REQUEST['is_ajax']) && $_REQUEST['is_ajax'] == 1) { $filter['keywords'] = json_str_iconv($filter['keywords']); } $filter['sort_by'] = empty($_REQUEST['sort_by']) ? 'sort_order,id' : trim($_REQUEST['sort_by']); $filter['sort_order'] = empty($_REQUEST['sort_order']) ? 'ASC' : trim($_REQUEST['sort_order']); $ex_where = ' WHERE 1 '; if ($filter['keywords']) { /* keyword判斷行動電話或帳號 */ $ex_where .= " AND (user_name LIKE '%" . mysql_like_quote($filter['keywords']) . "%' or name LIKE '%" . mysql_like_quote($filter['keywords']) . "%' or tel like '%" . mysql_like_quote($filter['keywords']) . "%' )"; } // $filter['record_count'] = $GLOBALS['db']->getOne("SELECT COUNT(*) FROM " . $GLOBALS['ecs']->table('facility') . $ex_where); /* 分页大小 */ // $filter = page_and_size($filter); $sql = "SELECT * ". " FROM " . $GLOBALS['ecs']->table('pt_keyword') . $ex_where . " ORDER by " . $filter['sort_by'] . ' ' . $filter['sort_order'] ; // " LIMIT " . $filter['start'] . ',' . $filter['page_size']; //互亿无线代码 $filter['keywords'] = stripslashes($filter['keywords']); set_filter($filter, $sql); } else { $sql = $result['sql']; $filter = $result['filter']; } $search_list = $GLOBALS['db']->getAll($sql); // $count = count($fac_list); // for ($i=0; $i<$count; $i++) // { // } $arr = array('search_list' => $search_list); return $arr; } function search_update($id, $args) { if (empty($args) || empty($id)) { return false; } return $GLOBALS['db']->autoExecute($GLOBALS['ecs']->table('pt_keyword'), $args, 'update', "id='$id'"); } ?>