<?php
/**
* @name XERCMS
* @author Arno <XerCMS@163.com> [QQ:1328013]
* @version 1.0.0
* @link http://www.XerCMS.com
*/
!defined('XERCMS') && exit('Access Denied');
libs('#XerCMS_base');
class Service_admin_index extends admin
{
function xercms() {
$this->index();
}
function domains() {
Act('domains')->parent = $this;
Act('domains')->load();
}
function vote() {
Act('vote')->parent = $this;
Act('vote')->load();
}
function logout() {
session_destroy();
$this->tips('退出成功',X::$G['urlpath'].'index.php?s=admin');
}
function sql() {
$sql = p('sql');X::$G['do'] = g('d');
if(X::$G['do'] == 'query') {
$sql = stripcslashes($sql);
$sql = explode(";\r\n",$sql);$result = '';
foreach($sql as $val) {
if(empty($val)) {
continue;
}
DB::$debug = true;
$res = DB::query($val);
$result .= '语句:'.$val.'<br/>执行结果:'.($res ? 'OK (影响了 <font style="color:red;font-weight:800">'.DB::affected_rows().'</font> 行)' : mysql_error()).'<br>';
$resultSet = DB::fetch($res);
if(is_array($resultSet)) {
$result .= '<table cellspacing="1" cellpadding="0" class="tab" style="color:#666" ><tbody>';
$result .= '<tr>';
foreach($resultSet as $k=>$v) {
$result .= '<th>'.$k.'</th>';
}
$result .= '</tr>';
$result .= '<tr>';
foreach($resultSet as $k=>$v) {
$result .= '<td>'.$v.'</td>';
}
$result .= '</tr>';$max = 15;$count = 1;
while($res && $resultSet = DB::fetch($res)) {
$result .= '<tr>';
foreach($resultSet as $k=>$v) {
$result .= '<td>'.$v.'</td>';
}
$result .= '</tr>'; $count++;
if($count >= $max)break;
}
$result .= '</tbody></table>';
$result .= '注:最多显示15条结果数。';
}
}
$sql = implode(";\r\n",$sql);X::$G['do'] = '';
}
include_once($this->tpl('xercms.htm'));
}
function player() {
X::$G['do'] = g('d');
if(X::$G['do'] == 'update') {
$id = g('id');
$data[$id] = p('player');
if(!is_numeric($data[$id][2]) || !is_numeric($data[$id][3])) {
$this->tips('请正确填写宽高!');
}
ini('player',$data);
$script = dfile('Assets/player/'.$id.'.default.js');
$player = '';
foreach($data[$id] as $k=>$v) {
$player .= 'xercmsplayer['.$k.'] = \''.strtr($v,array('\\'=>'\\\\','\''=>'\\\'')).'\';'."\r\n";
}
dfile('Assets/player/'.$id.'.config.js',strtr($script,array('{xercms$player}'=>$player)));
$this->tips(11,'?s=admin&a=player&player='.$id);
} else {
$player = g('player','video');
$data = ini('player');
include_once($this->tpl('xercms.htm'));
}
}
function slides() {
$page = (int)g('page');$number = (int)g('number');
$page = $page < 1 ? 1 : $page;$number = ($number < 1 || $number > 30) ? 20 : $number;
$slides = DB::fetch_all('SELECT * FROM xercms_slides ORDER BY mtime DESC LIMIT '.(($page - 1)*$number).','.$number);
include_once($this->tpl('xercms.htm'));
}
function insertSlides() {
$data = p('data');
$data['title'] = strfilter($data['title']);
$data['img'] = strfilter($data['img']);
$data['sign'] = strfilter($data['sign']);
$data['url'] = strtr($data['url'],array('\''=>''));
DB::insert('xercms_slides',array('uid'=>X::$G['uid'],'ctime'=>X::$G['time'],'mtime'=>X::$G['time'],'title'=>$data['title'],'url'=>$data['url'],'img'=>$data['img'],'sign'=>$data['sign']));
$this->tips('操作成功',dreferer());
}
function delSlides() {
$id = (int)g('id');
if($id) {
DB::delete('xercms_slides',array('id'=>$id));
$this->tips('操作成功',dreferer());
} else $this->tips('错误的ID!');
}
function updateSlides() {
$id = (int)g('id');$data = p('data');
$data['title'] = strfilter($data['title']);
$data['img'] = strfilter($data['img']);
$data['extra'] = strfilter($data['extra']);
$data['mtime'] = X::$G['time'];
$data['url'] = strtr($data['url'],array('\''=>''));
DB::update('xercms_slides',$data,'id = '.$id);
$this->tips('操作成功',dreferer());
}
function bakloading() {
$tables = BAK::tables();
$total = 0;
foreach($tables as $v) {
$total += $v['count'];
}
foreach($_POST['bak'] as $k=>$v) {
$bak[] = array('name'=>$k,'count'=>$v);
}
$bak = json_encode($bak);
$time = time();
include_once($this->tpl('xercms.htm'));
}
function bakrestoring() {
$tables = BAK::tables();
$time = (int)$_GET['time'];
$total = 0;
$log = BAK::log($time);
foreach($log as $k=>$v) {
$bak[] = array('name'=>$k,'count'=>$v);
$total += $v;
}
$total += count($bak);
$bak = json_encode($bak);
include_once($this->tpl('xercms.htm'));
}
function bakrestore() {
$name = g('name');$id = g('start');
$dir = (int)$_GET['time'];
$result['msg'] = BAK::restore($name,$id,$dir)? 'OK' : DB::$error;
$result['state'] = 1;
exit(json_encode($result));
}
function bakdel() {
$dir = (int)$_GET['time'];
DIR::del('XerCMS/Data/backup/'.$dir.'/');
$this->tips(11,'?s=admin&a=baklist');
}
function bakload() {
$name = g('name');$start = g('start');
$dir = (int)$_GET['time'];
$result['count'] = BAK::table($name,$start,$dir);
$result['state'] = 1;
exit(json_encode($result));
}
function bak() {
$tables = BAK::tables();
include_once($this->tpl('xercms.htm'));
}
function baklist() {
$baklist = DIR::read('XerCMS/Data/backup');
include_once($this->tpl('xercms.htm'));
}
function nav(){
$act = g('act');
$page = g('page',0);
switch($act) {
case 'del':
$id = (int)g('id');
$nav = DB::result('SELECT * FROM xercms_nav WHERE id = '.$id);
if($nav['parent']) {
$nav['son'] = $nav['son'] < 1 ? 0 : $nav['son'] - 1;
DB::update('xercms_nav',array('son'=>$nav['son']),array('id'=>$nav['parent']));
}
DB::query('DELETE FROM xercms_nav WHERE id = '.$id);
$this->tips(11,'?s=admin&a=nav');
break;
case 'editnavname':
$nav = p('nav');
foreach($nav as $k=>$v) {
if(!empty($v['name'])) {
DB::update('xercms_nav',array('name'=>$v['name'],'order'=>$v['order'],'url'=>$v['url']),'id = '.$k);
}
}
$this->tips(11,'?s=admin&a=nav&parent='.$nav['parent']);
break;
case 'editnav':
$id = (int)g('id');
$parent_nav = DB::select('xercms_nav',array('parent'=>'0'));
$nav = DB::select_first('xercms_nav',array('id'=>$id));
break;
case 'hidenav':
$id = g('id');
DB::update('xercms_nav',array('display'=>0),'id = '.$id);
$this->tips(11);
break;
case 'shownav':
$id = g('id');
DB::update('xercms_nav',array('display'=>1),'id = '.$id);
$this->tips(11);
break;
case 'editsave':
$id = g('id');
$nav = p('nav');
if($id) {
DB::update('xercms_nav',$nav,'id = '.$id);
} else {
DB::insert('xercms_nav',$nav);
if($nav['parent']) {
DB::query('UPDATE xercms_nav SET son = son + 1 WHERE id = \''.$nav['parent'].'\'');
}
}
$this->tips(11,'?s=admin&a=nav&parent='.$nav['parent']);
break;
default:
$parent = (int)g('parent');$parentParent = 0;
if($parent) {