<?php
/**
* 对关键词的增删改查
* ======================================================
* 代码生产日期:2016-05-07 21:19
* @author: Abner
* @qq: 346882795
* @website: www.liyanzhi.com
* ======================================================
*
* */
define('IN_ECS', true);
require(dirname(__FILE__) . '/includes/init.php');
include_once(ROOT_PATH . '/includes/cls_image.php');
$exc = new exchange($ecs->table('keyword_url'), $db, 'key_id', 'title');
/* 允许上传的文件类型 */
$allow_file_types = '|GIF|JPG|PNG|BMP|SWF|DOC|XLS|PPT|MID|WAV|ZIP|RAR|PDF|CHM|RM|TXT|';
/**
*************************关键词列表*************************
**/
if ($_REQUEST['act'] == 'list')
{
/* 检查权限 */
admin_priv('keyword');
/* 取得过滤条件 */
$keyword = get_keywordlist();
$smarty->assign('article_list', $keyword['arr']);
$smarty->assign('filter', $keyword['filter']);
$smarty->assign('record_count', $keyword['record_count']);
$smarty->assign('page_count', $keyword['page_count']);
$smarty->assign('full_page', 1);
$smarty->assign('cat_select', article_cat_list(0));
$smarty->assign('action_link', array('text' => $_LANG['02_key_add'], 'href' => 'keyword.php?act=add'));
assign_query_info();
$smarty->display('keyword.htm');
}
/*------------------------------------------------------ */
//-- 添加文章
/*------------------------------------------------------ */
if ($_REQUEST['act'] == 'add')
{
/* 权限判断 */
admin_priv('keyword');
/*初始化*/
$article = array();
$article['is_open'] = 1;
$smarty->assign('article', $article);
$smarty->assign('ur_here', $_LANG['02_key_add']);
$smarty->assign('action_link', array('text' => $_LANG['01_key_list'], 'href' => 'keyword.php?act=list'));
$smarty->assign('form_action', 'insert');
assign_query_info();
$smarty->display('keyword_info.htm');
}
elseif ($_REQUEST['act'] == 'insert')
{
/* 权限判断 */
admin_priv('keyword');
/*检查是否重复*/
// $is_only = $exc->is_only('title', $_POST['title'],0, " cat_id ='$_POST[article_cat]'");
// if (!$is_only)
// {
// sys_msg(sprintf($_LANG['title_exist'], stripslashes($_POST['title'])), 1);
// }
//处理接收来的数据
if(!empty($_POST))
{
$arr = array();
foreach($_POST['title'] as $k => $v){
$arr[] = array(
'title' => $v,
'url' => $_POST['url'][$k],
'num' => $_POST['num'][$k]
);
}
}
/* 拼接数据 */
$val = '';
foreach($arr as $k2 => $v2)
{
$val .= "('{$v2['title']}', '{$v2['url']}', '{$v2['num']}'),";
}
$val = rtrim($val, ',');
$sql = "INSERT INTO " .$ecs->table('keyword_url'). "(`title`, `url`, `num`) VALUES " .$val;
$db->query($sql);
$link[0]['text'] = $_LANG['continue_add'];
$link[0]['href'] = 'keyword.php?act=add';
$link[1]['text'] = $_LANG['back_list'];
$link[1]['href'] = 'keyword.php?act=list';
admin_log($_POST['title'],'add','keyword');
clear_cache_files(); // 清除相关的缓存文件
sys_msg('添加成功',0, $link);
}
/*------------------------------------------------------ */
//-- 编辑字
/*------------------------------------------------------ */
elseif ($_REQUEST['act'] == 'edit_title')
{
check_authz_json('keyword');
$id = intval($_POST['id']);
$title = json_str_iconv(trim($_POST['val']));
/* 检查文章标题是否重复 */
if ($exc->num("title", $title, $id) != 0)
{
make_json_error(sprintf($_LANG['title_exist'], $title));
}
else
{
if ($exc->edit("title = '$title'", $id))
{
clear_cache_files();
admin_log($title, 'edit', 'keyword');
make_json_result(stripslashes($title));
}
else
{
make_json_error($db->error());
}
}
}
/*------------------------------------------------------ */
//-- 编辑url
/*------------------------------------------------------ */
elseif ($_REQUEST['act'] == 'edit_url')
{
check_authz_json('keyword');
$id = intval($_POST['id']);
$url = json_str_iconv(trim($_POST['val']));
/* 检查文章标题是否重复 */
if ($exc->num("title", $title, $id) != 0)
{
make_json_error(sprintf($_LANG['title_exist'], $title));
}
else
{
if ($exc->edit("url = '$url'", $id))
{
clear_cache_files();
admin_log($url, 'edit', 'keyword');
make_json_result(stripslashes($url));
}
else
{
make_json_error($db->error());
}
}
}
/*------------------------------------------------------ */
//-- 编辑数量
/*------------------------------------------------------ */
elseif ($_REQUEST['act'] == 'edit_num')
{
check_authz_json('keyword');
$id = intval($_POST['id']);
$num = json_str_iconv(trim($_POST['val']));
/* 检查文章标题是否重复 */
if ($exc->num("num", $title, $id) != 0)
{
make_json_error(sprintf($_LANG['title_exist'], $title));
}
else
{
if ($exc->edit("num = '$num'", $id))
{
clear_cache_files();
admin_log($num, 'edit', 'keyword');
make_json_result(stripslashes($num));
}
else
{
make_json_error($db->error());
}
}
}
//获得关键字列表
function get_keywordlist()
{
$result = get_filter();
if ($result === false)
{
$filter = array();
$filter['keyword'] = empty($_REQUEST['keyword']) ? '' : trim($_REQUEST['keyword']);
if (isset($_REQUEST['is_ajax']) && $_REQUEST['is_ajax'] == 1)
{
$filter['keyword'] = json_str_iconv($filter['keyword']);
}
$filter['sort_by'] = empty($_REQUEST['sort_by']) ? 'key_id' : trim($_REQUEST['sort_by']);
$filter['sort_order'] = empty($_REQUEST['sort_order']) ? 'DESC' : trim($_REQUEST['sort_order']);
$where = '';
if (!empty($filter['keyword']))
{
$where = " AND a.title LIKE '%" . mysql_like_quote($filter['keyword']) . "%'";
}
/* 关键字总数 */
$sql = 'SELECT COUNT(*) FROM ' .$GLOBALS['ecs'] -> table('keyword_url').' WHERE 1 '.$where;
$filter['record_count'] = $GLOBALS['db'] -> getOne($sql);
$filter = page_and_size($filter);
// var_dump($filter);
/* 获取关键字数据 */
$sql = 'SELECT * FROM ' .$GLOBALS['ecs'] -> table('keyword_url'). ' WHERE 1' .$where. ' ORDER BY ' .$filter['sort_by'].' '.$filter['sort_order'];;
$filter['keyword'] = stripslashes($filter['keyword']);
set_filter($filter, $sql);
}
else
{
$sql = $result['sql'];
$filter = $result['filter'];
}
// var_dump($filter);
$arr = array();
$res = $GLOBALS['db']->selectLimit($sql, $filter['page_size'], $filter['start']);
while ($rows = $GLOBALS['db']->fetchRow($res))
{
$rows['date'] = local_date($GLOBALS['_CFG']['time_format'], $rows['add_time']);
$arr[] = $rows;
}
return array('arr' => $arr, 'filter' => $filter, 'page_count' => $filter['page_count'], 'record_count' => $filter['record_count']);
}