添加操作。。。
<?php
/*** 對關(guān)鍵詞的增刪改查* ======================================================* 代碼生產(chǎn)日期: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|';/***************************關(guān)鍵詞列表***************************/if ($_REQUEST['act'] == 'list')
{/* 檢查權(quán)限 */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')
{/* 權(quán)限判斷 */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')
{/* 權(quán)限判斷 */admin_priv('keyword');/*檢查是否重復(fù)*/
// $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);
// }//處理接收來的數(shù)據(jù)if(!empty($_POST)){$arr = array();foreach($_POST['title'] as $k => $v){$arr[] = array('title' => $v,'url' => $_POST['url'][$k],'num' => $_POST['num'][$k]);}}/* 拼接數(shù)據(jù) */$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(); // 清除相關(guān)的緩存文件sys_msg('添加成功',0, $link);}/*------------------------------------------------------ */
//-- 編輯字
/*------------------------------------------------------ */elseif ($_REQUEST['act'] == 'edit_title')
{check_authz_json('keyword');$id = intval($_POST['id']);$title = json_str_iconv(trim($_POST['val']));/* 檢查文章標(biāo)題是否重復(fù) */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']));/* 檢查文章標(biāo)題是否重復(fù) */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());}}}/*------------------------------------------------------ */
//-- 編輯數(shù)量
/*------------------------------------------------------ */
elseif ($_REQUEST['act'] == 'edit_num')
{check_authz_json('keyword');$id = intval($_POST['id']);$num = json_str_iconv(trim($_POST['val']));/* 檢查文章標(biāo)題是否重復(fù) */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());}}}//獲得關(guān)鍵字列表
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']) . "%'";}/* 關(guān)鍵字總數(shù) */$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);/* 獲取關(guān)鍵字?jǐn)?shù)據(jù) */$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']);
}
轉(zhuǎn)載于:https://www.cnblogs.com/Abner3721/p/5472164.html
總結(jié)
- 上一篇: 【C#公共帮助类】JsonHelper
- 下一篇: 分析与设计数据库模型的简单过程