<?php
//功能模块
/**
* 获取栏目列表
* @param string $mode 索引方式(id 或 pid)默认返回两种格式
* @return array 整理后的栏目数组
*/
function module_category($mode='all'){
static $result = []; //缓存查询结果
//当第一次调用函数时,获取数据
if(empty($result)){
//先从文件中取出数据缓存
$result = F('get', 'category');
//如果缓存不存在,则到数据库中取出数据
if(!$result){
//定义数组用于保存结果
$result = ['id'=>[], 'pid'=>[[]]];
//到数据库中取出所有的栏目数据
$data = db_fetch(DB_ALL, 'SELECT `id`,`name`,`pid`,`sort` FROM `cms_category` ORDER BY `pid` ASC, `sort` ASC');
//整理数组格式,方便查找
foreach($data as $v){
//基于ID索引
$result['id'][$v['id']] = $v;
//基于PID索引
$result['pid'][$v['pid']][$v['id']] = $v;
}
//将数据保存到缓存
F('save', 'category', $result);
}
}
return isset($result[$mode]) ? $result[$mode] : $result;
}
/**
* 根据栏目ID获取栏目名称
* @param int $id 栏目ID
* @return string 栏目名称,如果不存在返回空字符串
*/
function module_category_name($id){
$data = module_category('id');
return isset($data[$id]) ? $data[$id]['name'] : '';
}
/**
* 根据栏目ID获取子栏目
* @param int $id 栏目ID
* @return string 包括栏目ID、子栏目的字符串列表,用逗号分隔
*/
function module_category_sub($id){
$data = module_category('pid');
$sub = isset($data[$id]) ? array_keys($data[$id]) : [];
array_unshift($sub, $id); //将$id放入数组开头
return implode(',', $sub);
}
/**
* 获取文章列表(仅前台)
* @param int $cid 所属栏目ID,0表示所有
* @param int $page 当前页码
* @param int $limit 限制取出的个数
* @return array 文章数组
*/
function module_article($cid=0, $page=1, $limit=12){
$sql_where = ' WHERE ';
$sql_where .= $cid ? '`cid` IN ('.module_category_sub($cid).')' : '1=1';
$sql_where .= " AND `show`='yes' ";
$sql_limit = ' LIMIT '.page_sql($page, $limit);
//获取总页数
$total = db_fetch(DB_COLUMN, "SELECT COUNT(*) FROM `cms_article` $sql_where");
//查询并返回
return[
'title' => module_category_name($cid),
'data' => db_fetch(DB_ALL, 'SELECT `id`,`title`,`time`,`author`,`thumb`,`description`'
. " FROM `cms_article` $sql_where ORDER BY `id` DESC $sql_limit"),
'page_html' => page_html($total, $page, $limit)
];
}
/**
* 根据ID获取文章内容(仅前台)
*/
function module_article_show($id){
return db_fetch(DB_ROW, 'SELECT `cid`,`title`,`time`,`views`,`keywords`,`thumb`,`author`,`description`,`content` FROM `cms_article` WHERE `id`=? AND `show`=\'yes\'', 'i', $id);
}
function module_results_show(){
return db_fetch(DB_ALL, 'SELECT `name`,`results` FROM `cms_student`');
}
/**
* 获取导航条栏目(仅前台)
* @param string $limit 限制取出的个数
* @return array 查询结果
*/
function module_category_nav($limit=4){
$data = module_category('pid');
return isset($data[0]) ? array_slice($data[0], 0, $limit) : [];
}
/**
* 获取侧边栏 栏目(仅前台)
* @param int $id 栏目ID
* @return array 存在子栏目时,返回子栏目,不存在时返回同级栏目
*/
function module_category_sidebar($id=0){
$data = module_category();
//获取PID
$pid = isset($data['id'][$id]) ? $data['id'][$id]['pid'] : 0;
//如果有子栏目,返回子栏目,没有子栏目,返回同级栏目
return isset($data['pid'][$id]) ? $data['pid'][$id] :
(isset($data['pid'][$pid]) ? $data['pid'][$pid] : []);
}
/**
* 获取栏目的顶级栏目ID
*/
function module_category_top($id){
$data = module_category('id');
$pid = isset($data[$id]) ? $data[$id]['pid'] : 0;
return $pid ? : $id;
}
/**
* 获取浏览历史(仅前台)
* @param array $current 浏览过的文章ID,为false表示不保存
* @param int $limit 限制取出的个数
* return array 历史记录数组
*/
function module_history($current=false, $limit=10){
$result = []; //保存历史记录数组
//如果Cookie中存在历史记录,先取出记录
if(isset($_COOKIE['cms_history'])){
//获取Cookie,将字符串分割成数组,并限制分割次数
$result = explode(',', $_COOKIE['cms_history'], $limit);
//将数组中的每个元素转换为整数
$result = array_map('intval', $result);
}
//将当前文章ID保持到历史记录中
if($current){
//如果当前ID在数组中已经存在,则删除
if(false !== ($del = array_search($current, $result))){
unset($result[$del]);
}
//将当前文章ID添加到数组开始
array_unshift($result, $current);
//当数组元素达到限制时,删除最后一个元素
if(isset($result[$limit])){
unset($result[$limit]);
}
}
if(!empty($result)){
//保存到Cookie并返回
$sql_in = implode(',', $result);
setcookie('cms_history', $sql_in);
return db_fetch(DB_ALL, "SELECT `id`,`title` FROM `cms_article` WHERE `id` IN($sql_in) AND `show`='yes' ORDER BY FIELD(`id`,$sql_in)");
}
return [];
}
/**
* 获取最热文章(仅前台)
*/
function module_hot($limit=10){
return db_fetch(DB_ALL, "SELECT `id`,`title` FROM `cms_article` WHERE `show`='yes' ORDER BY `views` DESC LIMIT 0,$limit");
}
没有合适的资源?快使用搜索试试~ 我知道了~
网站开发-基于PHP的在线考试系统的设计与实现
共430个文件
js:223个
png:62个
php:41个
需积分: 0 2 下载量 3 浏览量
2023-02-01
15:23:14
上传
评论
收藏 2.87MB RAR 举报
温馨提示
PHP在线考试系统针对的用户主要有学生、教师、系统管理员,他们都具有一定的计算机应用基础,可以比较熟练的操作计算机,系统管理员为计算机专业人员,需要熟悉数据库、操作系统、网络维护工作。 ● 学生:登录系统、选取试卷、答卷、查看成绩; ● 教师:对试卷进行增删改查、统计汇总学生成绩; ● 系统管理员:对系统进行整体的维护和管理。 本系统的运行环境,包括: ● 操作系统:Windows7、8、10版本的操作系统; ● 数据库管理系统:My SQL,配置TCP/IP协议; ● Web浏览器:火狐、谷歌等主流浏览器; ● 编辑器:sublime; ● PhpStudy。
资源推荐
资源详情
资源评论
收起资源包目录
网站开发-基于PHP的在线考试系统的设计与实现 (430个子文件)
.buildpath 174B
editor_ie7.css 45KB
editor_iequirks.css 44KB
editor_ie8.css 43KB
editor_ie.css 43KB
editor_gecko.css 42KB
editor.css 42KB
dashicons.css 36KB
dialog_ie7.css 15KB
dialog_ie8.css 14KB
dialog_iequirks.css 14KB
dialog_ie.css 14KB
dialog.css 13KB
style.css 7KB
style.css 7KB
style.css 4KB
layout.css 3KB
contents.css 2KB
templates.css 2KB
toolbar.css 1KB
wsc.css 1KB
colordialog.css 772B
category.dat 213B
dashicons.eot 41KB
spinner.gif 3KB
angel_smile.gif 1KB
devil_smile.gif 1KB
shades_smile.gif 1KB
angry_smile.gif 1KB
tongue_smile.gif 1KB
tounge_smile.gif 1KB
regular_smile.gif 1KB
wink_smile.gif 1KB
confused_smile.gif 1KB
teeth_smile.gif 1KB
omg_smile.gif 820B
cry_smile.gif 795B
embarrassed_smile.gif 786B
embaressed_smile.gif 786B
sad_smile.gif 782B
whatchutalkingabout_smile.gif 775B
broken_heart.gif 732B
thumbs_down.gif 715B
thumbs_up.gif 714B
heart.gif 692B
kiss.gif 683B
lightbulb.gif 660B
envelope.gif 506B
template3.gif 422B
template1.gif 375B
template2.gif 333B
hiddenfield.gif 178B
pagebreak.gif 99B
test.html 6KB
login.html 4KB
student.html 4KB
teacher.html 4KB
category.html 3KB
article.html 3KB
article_edit.html 2KB
tmpFrameset.html 2KB
ciframe.html 2KB
layout.html 1KB
layout.html 1KB
total.html 1KB
module_show.html 1KB
teacher_edit.html 1KB
student_edit.html 1KB
module_sidebar.html 1KB
category_edit.html 1KB
module_list.html 1014B
index.html 866B
module_about.html 841B
index.html 730B
notFound.html 569B
module_slide.html 379B
preview.html 259B
favicon.ico 3KB
favicon.ico 3KB
22.jpg 685KB
20.jpg 258KB
21.jpg 224KB
9a501be21d32a8cd63461aec1377e3c9.jpg 36KB
ckeditor.js 552KB
jquery.min.js 95KB
jquery.min.js 95KB
jquery.min.js 95KB
jquery-1.11.1.min.js 94KB
wsc.js 47KB
ka.js 32KB
km.js 32KB
gu.js 29KB
th.js 28KB
el.js 27KB
ru.js 27KB
uk.js 26KB
ug.js 25KB
ku.js 25KB
si.js 24KB
bg.js 24KB
共 430 条
- 1
- 2
- 3
- 4
- 5
资源评论
有点菜的程序猿
- 粉丝: 0
- 资源: 10
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功