init
This commit is contained in:
303
apps/admin/controller/system/AreaController.php
Normal file
303
apps/admin/controller/system/AreaController.php
Normal file
@@ -0,0 +1,303 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright (C)2016-2099 Hnaoyun Inc.
|
||||
* @author XingMeng
|
||||
* @email hnxsh@foxmail.com
|
||||
* @date 2017年4月3日
|
||||
* 区域控制器
|
||||
*/
|
||||
namespace app\admin\controller\system;
|
||||
|
||||
use core\basic\Controller;
|
||||
use app\admin\model\system\AreaModel;
|
||||
|
||||
class AreaController extends Controller
|
||||
{
|
||||
|
||||
private $count;
|
||||
|
||||
private $blank;
|
||||
|
||||
private $outData = array();
|
||||
|
||||
private $model;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->model = new AreaModel();
|
||||
}
|
||||
|
||||
// 区域列表
|
||||
public function index()
|
||||
{
|
||||
$this->assign('list', true);
|
||||
$area_tree = $this->model->getList();
|
||||
$areas = $this->makeAreaList($area_tree);
|
||||
$this->assign('areas', $areas);
|
||||
|
||||
// 区域下拉表
|
||||
$area_tree = $this->model->getSelect();
|
||||
$area_select = $this->makeAreaSelect($area_tree);
|
||||
$this->assign('area_select', $area_select);
|
||||
|
||||
$this->display('system/area.html');
|
||||
}
|
||||
|
||||
// 生成无限级区域列表
|
||||
private function makeAreaList($tree)
|
||||
{
|
||||
// 循环生成
|
||||
foreach ($tree as $value) {
|
||||
$this->count ++;
|
||||
$this->outData[$this->count] = new \stdClass();
|
||||
$this->outData[$this->count]->id = $value->id;
|
||||
$this->outData[$this->count]->blank = $this->blank;
|
||||
$this->outData[$this->count]->name = $value->name;
|
||||
$this->outData[$this->count]->domain = $value->domain;
|
||||
$this->outData[$this->count]->acode = $value->acode;
|
||||
$this->outData[$this->count]->pcode = $value->pcode;
|
||||
$this->outData[$this->count]->is_default = $value->is_default;
|
||||
$this->outData[$this->count]->create_user = $value->create_user;
|
||||
$this->outData[$this->count]->update_user = $value->update_user;
|
||||
$this->outData[$this->count]->create_time = $value->create_time;
|
||||
$this->outData[$this->count]->update_time = $value->update_time;
|
||||
|
||||
if ($value->son) {
|
||||
$this->outData[$this->count]->son = true;
|
||||
} else {
|
||||
$this->outData[$this->count]->son = false;
|
||||
}
|
||||
|
||||
// 子菜单处理
|
||||
if ($value->son) {
|
||||
$this->blank .= ' ';
|
||||
$this->makeAreaList($value->son);
|
||||
}
|
||||
}
|
||||
|
||||
// 循环完后回归缩进位置
|
||||
$this->blank = substr($this->blank, 6);
|
||||
return $this->outData;
|
||||
}
|
||||
|
||||
// 区域增加
|
||||
public function add()
|
||||
{
|
||||
if ($_POST) {
|
||||
// 获取数据
|
||||
$acode = post('acode', 'var');
|
||||
$pcode = post('pcode', 'var');
|
||||
$name = post('name');
|
||||
$domain = post('domain');
|
||||
$is_default = post('is_default');
|
||||
|
||||
if (! $acode) {
|
||||
alert_back('编码不能为空!');
|
||||
}
|
||||
|
||||
if (! $pcode) { // 父编码默认为0
|
||||
$pcode = 0;
|
||||
}
|
||||
|
||||
if (! $name) {
|
||||
alert_back('区域名称不能为空!');
|
||||
}
|
||||
|
||||
if ($domain) {
|
||||
$reg = '{^(https://|http://)?([\w\-.]+)([\/]+)?$}';
|
||||
if (preg_match($reg, $domain)) {
|
||||
$domain = preg_replace($reg, '$2', $domain);
|
||||
} else {
|
||||
alert_back('要绑定的域名输入有错!');
|
||||
}
|
||||
|
||||
// 检查绑定
|
||||
if ($this->model->checkArea("domain='$domain'")) {
|
||||
alert_back('该域名已经绑定其他区域,不能再使用!');
|
||||
}
|
||||
}
|
||||
|
||||
// 检查编码
|
||||
if ($this->model->checkArea("acode='$acode'")) {
|
||||
alert_back('该区域编号已经存在,不能再使用!');
|
||||
}
|
||||
|
||||
// 构建数据
|
||||
$data = array(
|
||||
'acode' => $acode,
|
||||
'pcode' => $pcode,
|
||||
'name' => $name,
|
||||
'domain' => $domain,
|
||||
'is_default' => $is_default,
|
||||
'create_user' => session('username'),
|
||||
'update_user' => session('username')
|
||||
);
|
||||
|
||||
// 执行添加
|
||||
if ($this->model->addArea($data)) {
|
||||
if (session('ucode') == '10001') {
|
||||
$acodes = session('acodes');
|
||||
$acodes[] = $acode;
|
||||
session('acodes', $acodes); // 更新管理员管理区域
|
||||
$model = model('Index');
|
||||
$areas = $model->getAreas();
|
||||
session('area_map', get_mapping($areas, 'name', 'acode')); // 更新区域代码名称映射表
|
||||
session('area_tree', $model->getUserAreaTree($areas, 0, 'acode', 'pcode', 'son', $acodes)); // 更新当前用户的区域树
|
||||
}
|
||||
$this->log('新增数据区域' . $acode . '成功!');
|
||||
path_delete(RUN_PATH . '/config'); // 清理缓存的配置文件
|
||||
if (! ! $backurl = get('backurl')) {
|
||||
success('新增成功!', base64_decode($backurl));
|
||||
} else {
|
||||
success('新增成功!', url('/admin/Area/index'));
|
||||
}
|
||||
} else {
|
||||
$this->log('新增数据区域' . $acode . '失败!');
|
||||
error('新增失败!', - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 生成区域选择
|
||||
private function makeAreaSelect($tree, $selectid = null)
|
||||
{
|
||||
$list_html = '';
|
||||
foreach ($tree as $value) {
|
||||
// 默认选择项
|
||||
if ($selectid == $value->acode) {
|
||||
$select = "selected='selected'";
|
||||
} else {
|
||||
$select = '';
|
||||
}
|
||||
if (get('acode') != $value->acode) { // 不显示本身,避免出现自身为自己的父节点
|
||||
$list_html .= "<option value='{$value->acode}' $select>{$this->blank}{$value->acode} {$value->name}</option>";
|
||||
}
|
||||
// 子菜单处理
|
||||
if ($value->son) {
|
||||
$this->blank .= ' ';
|
||||
$list_html .= $this->makeAreaSelect($value->son, $selectid);
|
||||
}
|
||||
}
|
||||
// 循环完后回归位置
|
||||
$this->blank = substr($this->blank, 0, - 6);
|
||||
return $list_html;
|
||||
}
|
||||
|
||||
// 区域删除
|
||||
public function del()
|
||||
{
|
||||
if (! $acode = get('acode', 'var')) {
|
||||
error('传递的参数值错误!', - 1);
|
||||
}
|
||||
|
||||
if ($acode == 'cn') {
|
||||
error('系统内置区域不允许删除!', - 1);
|
||||
}
|
||||
|
||||
if ($this->model->delArea($acode)) {
|
||||
path_delete(RUN_PATH . '/config'); // 清理缓存的配置文件
|
||||
$this->log('删除数据区域' . $acode . '成功!');
|
||||
session_unset();
|
||||
success('删除成功,请重新登录', url('/admin/Index/index'));
|
||||
} else {
|
||||
$this->log('删除数据区域' . $acode . '失败!');
|
||||
error('删除失败,请核对是否为默认区域!', - 1);
|
||||
}
|
||||
}
|
||||
|
||||
// 区域修改
|
||||
public function mod()
|
||||
{
|
||||
if (! $acode = get('acode', 'var')) {
|
||||
error('传递的参数值错误!', - 1);
|
||||
}
|
||||
|
||||
// 修改操作
|
||||
if ($_POST) {
|
||||
// 获取数据
|
||||
$acode_new = post('acode', 'var');
|
||||
$pcode = post('pcode', 'var');
|
||||
$name = post('name');
|
||||
$domain = post('domain');
|
||||
$is_default = post('is_default');
|
||||
|
||||
if (! $acode_new) {
|
||||
alert_back('编码不能为空!');
|
||||
}
|
||||
|
||||
if (! $pcode) { // 父编码默认为0
|
||||
$pcode = 0;
|
||||
}
|
||||
|
||||
if (! $name) {
|
||||
alert_back('区域名称不能为空!');
|
||||
}
|
||||
|
||||
if ($domain) {
|
||||
$reg = '{^(https://|http://)?([\w\-.]+)([\/]+)?$}';
|
||||
if (preg_match($reg, $domain)) {
|
||||
$domain = preg_replace($reg, '$2', $domain);
|
||||
} else {
|
||||
alert_back('要绑定的域名输入有错!');
|
||||
}
|
||||
|
||||
// 检查绑定
|
||||
if ($this->model->checkArea("domain='$domain' AND acode<>'$acode'")) {
|
||||
alert_back('该域名已经绑定其他区域,不能再使用!');
|
||||
}
|
||||
}
|
||||
|
||||
// 检查编码
|
||||
if ($this->model->checkArea("acode='$acode_new' AND acode<>'$acode'")) {
|
||||
alert_back('该区域编号已经存在,不能再使用!');
|
||||
}
|
||||
|
||||
// 构建数据
|
||||
$data = array(
|
||||
'acode' => $acode_new,
|
||||
'pcode' => $pcode,
|
||||
'name' => $name,
|
||||
'domain' => $domain,
|
||||
'is_default' => $is_default,
|
||||
'update_user' => session('username')
|
||||
);
|
||||
|
||||
// 执行添加
|
||||
if ($this->model->modArea($acode, $data)) {
|
||||
if (session('ucode') == '10001') {
|
||||
$acodes = session('acodes');
|
||||
$acodes[] = $acode_new;
|
||||
session('acodes', $acodes); // 更新管理员管理区域
|
||||
$model = model('Index');
|
||||
$areas = $model->getAreas();
|
||||
session('area_map', get_mapping($areas, 'name', 'acode')); // 更新区域代码名称映射表
|
||||
session('area_tree', $model->getUserAreaTree($areas, 0, 'acode', 'pcode', 'son', $acodes)); // 更新当前用户的区域树
|
||||
}
|
||||
$this->log('修改数据区域' . $acode . '成功!');
|
||||
path_delete(RUN_PATH . '/config'); // 清理缓存的配置文件
|
||||
if (! ! $backurl = get('backurl')) {
|
||||
success('修改成功!', base64_decode($backurl));
|
||||
} else {
|
||||
success('修改成功!', url('/admin/Area/index'));
|
||||
}
|
||||
} else {
|
||||
location(- 1);
|
||||
}
|
||||
} else { // 调取修改内容
|
||||
$this->assign('mod', true);
|
||||
|
||||
$area = $this->model->getArea($acode);
|
||||
if (! $area) {
|
||||
error('编辑的内容已经不存在!', - 1);
|
||||
}
|
||||
$this->assign('area', $area);
|
||||
|
||||
// 父编码下拉选择
|
||||
$area_tree = $this->model->getSelect();
|
||||
$area_select = $this->makeAreaSelect($area_tree, $area->pcode);
|
||||
$this->assign('area_select', $area_select);
|
||||
|
||||
$this->display('system/area.html');
|
||||
}
|
||||
}
|
||||
}
|
||||
226
apps/admin/controller/system/ConfigController.php
Normal file
226
apps/admin/controller/system/ConfigController.php
Normal file
@@ -0,0 +1,226 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright (C)2016-2099 Hnaoyun Inc.
|
||||
* @author XingMeng
|
||||
* @email hnxsh@foxmail.com
|
||||
* @date 2018年01月03日
|
||||
* 应用配置控制器
|
||||
*/
|
||||
namespace app\admin\controller\system;
|
||||
|
||||
use core\basic\Controller;
|
||||
use app\admin\model\system\ConfigModel;
|
||||
use core\basic\Config;
|
||||
|
||||
class ConfigController extends Controller
|
||||
{
|
||||
|
||||
private $model;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->model = new ConfigModel();
|
||||
}
|
||||
|
||||
// 应用配置列表
|
||||
public function index()
|
||||
{
|
||||
if (! ! $action = get('action')) {
|
||||
switch ($action) {
|
||||
case 'sendemail':
|
||||
$rs = sendmail($this->config(), get('to'), '【PbootCMS】测试邮件', '欢迎您使用PbootCMS网站开发管理系统!');
|
||||
if ($rs === true) {
|
||||
alert_back('测试邮件发送成功!');
|
||||
} else {
|
||||
error('发送失败:' . $rs);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// 修改参数配置
|
||||
if ($_POST) {
|
||||
unset($_POST['upload']); // 去除上传组件
|
||||
foreach ($_POST as $key => $value) {
|
||||
if (! preg_match('/^[\w\-]+$/', $key)) {
|
||||
continue;
|
||||
}
|
||||
$config = array(
|
||||
'debug',
|
||||
'sn',
|
||||
'sn_user',
|
||||
'pagenum',
|
||||
'tpl_html_cache',
|
||||
'tpl_html_cache_time',
|
||||
'session_in_sitepath'
|
||||
);
|
||||
if (in_array($key, $config)) {
|
||||
if ($key == 'tpl_html_cache_time' && ! $value) {
|
||||
$value = 900;
|
||||
} else {
|
||||
$value = post($key);
|
||||
}
|
||||
$this->modConfig($key, $value);
|
||||
} else {
|
||||
$this->modDbConfig($key);
|
||||
}
|
||||
}
|
||||
|
||||
$this->log('修改参数配置成功!');
|
||||
path_delete(RUN_PATH . '/config'); // 清理缓存的配置文件
|
||||
|
||||
switch (post('submit')) {
|
||||
case 'email':
|
||||
success('修改成功!', url('/admin/Config/index' . get_tab('t2'), false));
|
||||
break;
|
||||
case 'baidu':
|
||||
success('修改成功!', url('/admin/Config/index' . get_tab('t3'), false));
|
||||
break;
|
||||
case 'api':
|
||||
success('修改成功!', url('/admin/Config/index' . get_tab('t4'), false));
|
||||
break;
|
||||
case 'watermark':
|
||||
success('修改成功!', url('/admin/Config/index' . get_tab('t5'), false));
|
||||
break;
|
||||
case 'security':
|
||||
success('修改成功!', url('/admin/Config/index' . get_tab('t6'), false));
|
||||
break;
|
||||
case 'urlrule':
|
||||
success('修改成功!', url('/admin/Config/index' . get_tab('t7'), false));
|
||||
break;
|
||||
case 'pagetitle':
|
||||
success('修改成功!', url('/admin/Config/index' . get_tab('t8'), false));
|
||||
break;
|
||||
case 'member':
|
||||
success('修改成功!', url('/admin/Config/index' . get_tab('t9'), false));
|
||||
break;
|
||||
case 'upgrade':
|
||||
success('修改成功!', url('/admin/Upgrade/index' . get_tab('t2'), false));
|
||||
break;
|
||||
default:
|
||||
success('修改成功!', url('/admin/Config/index', false));
|
||||
}
|
||||
}
|
||||
$configs = $this->model->getList();
|
||||
$configs['debug']['value'] = $this->config('debug');
|
||||
$configs['sn']['value'] = $this->config('sn');
|
||||
$configs['sn_user']['value'] = $this->config('sn_user');
|
||||
$configs['session_in_sitepath']['value'] = $this->config('session_in_sitepath');
|
||||
$configs['pagenum']['value'] = $this->config('pagenum');
|
||||
$configs['url_type']['value'] = $this->config('url_type');
|
||||
$configs['tpl_html_cache']['value'] = $this->config('tpl_html_cache');
|
||||
$configs['tpl_html_cache_time']['value'] = $this->config('tpl_html_cache_time');
|
||||
$this->assign('configs', $configs);
|
||||
|
||||
$this->assign('groups', model('admin.member.MemberGroup')->getSelect());
|
||||
|
||||
$this->display('system/config.html');
|
||||
}
|
||||
|
||||
// 修改配置文件
|
||||
private function modConfig($key, $value)
|
||||
{
|
||||
$value = str_replace(' ', '', $value); // 去除空格
|
||||
$value = str_replace(',', ',', $value); // 转换可能输入的中文逗号
|
||||
if (! preg_match('/^[\w\s\,\-]+$/', $value)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$config = file_get_contents(CONF_PATH . '/config.php');
|
||||
if (preg_match("'$key'", $config)) {
|
||||
if (preg_match('/^[0-9]+$/', $value)) {
|
||||
$config = preg_replace('/(\'' . $key . '\'([\s]+)?=>([\s]+)?)[\w\'\"\s,]+,/', '${1}' . $value . ',', $config);
|
||||
} else {
|
||||
$config = preg_replace('/(\'' . $key . '\'([\s]+)?=>([\s]+)?)[\w\'\"\s,]+,/', '${1}\'' . $value . '\',', $config);
|
||||
}
|
||||
} else {
|
||||
$config = preg_replace('/(return array\()/', "$1\r\n\r\n\t'$key' => '$value',", $config); // 自动新增配置
|
||||
}
|
||||
return file_put_contents(CONF_PATH . '/config.php', $config);
|
||||
}
|
||||
|
||||
// 修改数据库配置
|
||||
private function modDbConfig($key)
|
||||
{
|
||||
$value = post($key);
|
||||
|
||||
// 如果开启伪静态时自动拷贝文件
|
||||
if ($key == 'url_rule_type' && $value == 2) {
|
||||
$soft = get_server_soft();
|
||||
if ($soft == 'iis') {
|
||||
if (! file_exists(ROOT_PATH . '/web.config')) {
|
||||
copy(ROOT_PATH . '/rewrite/web.config', ROOT_PATH . '/web.config');
|
||||
}
|
||||
} elseif ($soft == 'apache') {
|
||||
if (! file_exists(ROOT_PATH . '/web.config')) {
|
||||
copy(ROOT_PATH . '/rewrite/.htaccess', ROOT_PATH . '/.htaccess');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 模板目录修改
|
||||
if (($key == 'tpl_html_dir') && $value) {
|
||||
|
||||
// 不允许特殊字符
|
||||
if (! preg_match('/^\w+$/', $value)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$value = basename($value);
|
||||
$htmldir = $this->config('tpl_html_dir');
|
||||
$tpl_path = ROOT_PATH . current($this->config('tpl_dir')) . '/' . model('admin.content.ContentSort')->getTheme();
|
||||
|
||||
if (! $htmldir || ! file_exists($tpl_path . '/' . $htmldir)) {
|
||||
if (! check_dir($tpl_path . '/' . $value, true)) {
|
||||
return;
|
||||
} // 原来没有目录时只创建目录,创建失败时直接不修改
|
||||
} else {
|
||||
if ($value != $htmldir) {
|
||||
if (file_exists($tpl_path . '/' . $value)) {
|
||||
if (dir_copy($tpl_path . '/' . $htmldir, $tpl_path . '/' . $value)) {
|
||||
path_delete($tpl_path . '/' . $htmldir, true); // 删除原来的
|
||||
} else {
|
||||
return; // 修改失败
|
||||
}
|
||||
} else {
|
||||
if (! rename($tpl_path . '/' . $htmldir, $tpl_path . '/' . $value)) {
|
||||
return; // 修改失败
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($key == 'home_upload_ext') {
|
||||
// 不允许特殊扩展
|
||||
if (preg_match('/(php|jsp|asp|exe|sh|cmd|vb|vbs|phtml)/i', $value)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// 数据分割处理
|
||||
$hander = array(
|
||||
'content_keyword_replace',
|
||||
'ip_deny',
|
||||
'ip_allow'
|
||||
);
|
||||
if (in_array($key, $hander) && $value) {
|
||||
$value = str_replace("\r\n", ",", $value); // 替换回车
|
||||
$value = str_replace(",", ",", $value); // 替换中文逗号分割符
|
||||
}
|
||||
|
||||
if ($this->model->checkConfig("name='$key'")) {
|
||||
$this->model->modValue($key, $value);
|
||||
} elseif ($key != 'submit' && $key != 'formcheck') {
|
||||
// 自动新增配置项
|
||||
$data = array(
|
||||
'name' => $key,
|
||||
'value' => $value,
|
||||
'type' => 2,
|
||||
'sorting' => 255,
|
||||
'description' => ''
|
||||
);
|
||||
return $this->model->addConfig($data);
|
||||
}
|
||||
}
|
||||
}
|
||||
248
apps/admin/controller/system/DatabaseController.php
Normal file
248
apps/admin/controller/system/DatabaseController.php
Normal file
@@ -0,0 +1,248 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright (C)2016-2099 Hnaoyun Inc.
|
||||
* @author XingMeng
|
||||
* @email hnxsh@foxmail.com
|
||||
* @date 2017年5月9日
|
||||
* 数据库管理,只支持MySQL
|
||||
*/
|
||||
namespace app\admin\controller\system;
|
||||
|
||||
use core\basic\Controller;
|
||||
use app\admin\model\system\DatabaseModel;
|
||||
|
||||
class DatabaseController extends Controller
|
||||
{
|
||||
|
||||
private $model;
|
||||
|
||||
private $dbauth;
|
||||
|
||||
function __construct()
|
||||
{
|
||||
$this->model = new DatabaseModel();
|
||||
$this->dbauth = $this->config('database');
|
||||
}
|
||||
|
||||
// 数据库管理
|
||||
public function index()
|
||||
{
|
||||
switch ($this->dbauth['type']) {
|
||||
case 'mysqli':
|
||||
case 'pdo_mysql':
|
||||
$this->assign('db', 'mysql');
|
||||
$this->assign('tables', $this->model->getList());
|
||||
break;
|
||||
case 'sqlite':
|
||||
case 'pdo_sqlite':
|
||||
$this->assign('db', 'sqlite');
|
||||
break;
|
||||
default:
|
||||
error('当前配置的数据库类型不支持在线管理!');
|
||||
}
|
||||
$this->display('system/database.html');
|
||||
}
|
||||
|
||||
// 数据库修改
|
||||
public function mod()
|
||||
{
|
||||
if (! $_POST) {
|
||||
alert_back('非法访问!', - 1);
|
||||
}
|
||||
|
||||
$submit = post('submit', 'letter', true);
|
||||
|
||||
switch ($submit) {
|
||||
case 'yh':
|
||||
$tables = self::getTableList();
|
||||
if (! $tables)
|
||||
alert_back('请选择数据表!');
|
||||
if ($this->model->optimize(implode(',', $tables))) {
|
||||
// $this->log('优化数据库表成功!');
|
||||
success('优化成功!', - 1);
|
||||
} else {
|
||||
// $this->log('优化数据库表失败!');
|
||||
error('优化失败!', - 1);
|
||||
}
|
||||
break;
|
||||
case 'xf':
|
||||
$tables = self::getTableList();
|
||||
if (! $tables)
|
||||
alert_back('请选择数据表!');
|
||||
if ($this->model->repair(implode(',', $tables))) {
|
||||
// $this->log('修复数据库表成功!');
|
||||
success('修复成功!', - 1);
|
||||
} else {
|
||||
// $this->log('修复数据库表失败!');
|
||||
error('修复失败!', - 1);
|
||||
}
|
||||
break;
|
||||
case 'bf':
|
||||
$tables = self::getTableList();
|
||||
if (! $tables)
|
||||
alert_back('请选择数据表!');
|
||||
if ($this->backupTable($tables)) {
|
||||
$this->log('备份数据库表成功!');
|
||||
success('备份表成功!', - 1);
|
||||
} else {
|
||||
$this->log('备份数据库表失败!');
|
||||
error('备份失败!', - 1);
|
||||
}
|
||||
break;
|
||||
case 'bfdb':
|
||||
if ($this->backupDB()) {
|
||||
$this->log('备份数据库成功!');
|
||||
success('备份数据库成功!', - 1);
|
||||
} else {
|
||||
$this->log('备份数据库失败!');
|
||||
error('备份失败!', - 1);
|
||||
}
|
||||
break;
|
||||
case 'bfsqlite':
|
||||
if (copy(DOC_PATH . $this->dbauth['dbname'], DOC_PATH . STATIC_DIR . '/backup/sql/' . get_uniqid() . '_' . date('YmdHis') . '.db')) {
|
||||
$this->log('备份数据库成功!');
|
||||
success('备份数据库成功!', - 1);
|
||||
} else {
|
||||
$this->log('备份数据库失败!');
|
||||
error('备份失败!', - 1);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// 备份数据表
|
||||
public function backupTable($tables)
|
||||
{
|
||||
$backdir = date('YmdHis');
|
||||
foreach ($tables as $table) {
|
||||
$sql = '';
|
||||
$sql .= $this->header(); // 备份文件头部说明
|
||||
$sql .= $this->tableSql($table); // 表结构信息
|
||||
$fields = $this->model->getFields($table); // 表字段
|
||||
$field_num = $this->model->getFieldNum($table); // 字段数量
|
||||
$all_data = $this->model->getAll($table); // 读取全部数据
|
||||
$sql .= $this->dataSql($table, $fields, $field_num, $all_data); // 生成语句
|
||||
$filename = $backdir . "/" . get_uniqid() . "_" . $backdir . "_" . $table . '.sql'; // 写入文件
|
||||
$result = $this->writeFile($filename, $sql);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
// 备份整个数据库
|
||||
public function backupDB()
|
||||
{
|
||||
$sql = '';
|
||||
$sql .= $this->header(); // 备份文件头部说明
|
||||
$sql .= $this->dbSql(); // 数据库创建语句
|
||||
|
||||
$tables = $this->model->getTables(); // 获取所有表
|
||||
foreach ($tables as $table) { // 表结构及数据
|
||||
$sql .= $this->tableSql($table); // 表结构信息
|
||||
$fields = $this->model->getFields($table); // 表字段
|
||||
$field_num = $this->model->getFieldNum($table); // 字段数量
|
||||
$all_data = $this->model->getAll($table); // 读取全部数据
|
||||
if ($all_data) {
|
||||
$sql .= $this->dataSql($table, $fields, $field_num, $all_data); // 生成数据语句
|
||||
}
|
||||
$sql .= '-- --------------------------------------------------------' . PHP_EOL . PHP_EOL;
|
||||
}
|
||||
// 写入文件
|
||||
$filename = get_uniqid() . '_' . date('YmdHis') . '_' . $this->dbauth['dbname'] . '.sql';
|
||||
return $this->writeFile($filename, $sql);
|
||||
}
|
||||
|
||||
// 插入数据库备份基础信息
|
||||
private function header()
|
||||
{
|
||||
$sql = '-- Online Database Management SQL Dump' . PHP_EOL;
|
||||
$sql .= '-- 数据库名: ' . $this->dbauth['dbname'] . PHP_EOL;
|
||||
$sql .= '-- 生成日期: ' . date('Y-m-d H:i:s') . PHP_EOL;
|
||||
$sql .= '-- PHP 版本: ' . phpversion() . PHP_EOL . PHP_EOL;
|
||||
|
||||
$sql .= 'SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";' . PHP_EOL;
|
||||
$sql .= 'SET time_zone = "+08:00";' . PHP_EOL;
|
||||
$sql .= 'SET NAMES utf8;' . PHP_EOL . PHP_EOL;
|
||||
|
||||
$sql .= '-- --------------------------------------------------------' . PHP_EOL . PHP_EOL;
|
||||
return $sql;
|
||||
}
|
||||
|
||||
// 数据库创建语句
|
||||
private function dbSql()
|
||||
{
|
||||
$sql = '';
|
||||
$sql .= "--" . PHP_EOL;
|
||||
$sql .= "-- 数据库名 `" . $this->dbauth['dbname'] . '`' . PHP_EOL;
|
||||
$sql .= "--" . PHP_EOL . PHP_EOL;
|
||||
|
||||
// 如果数据库不存在则创建
|
||||
$sql .= "CREATE DATABASE IF NOT EXISTS `" . $this->dbauth['dbname'] . '` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;' . PHP_EOL;
|
||||
// 选择数据库
|
||||
$sql .= "USE `" . $this->dbauth['dbname'] . "`;" . PHP_EOL . PHP_EOL;
|
||||
$sql .= '-- --------------------------------------------------------' . PHP_EOL . PHP_EOL;
|
||||
return $sql;
|
||||
}
|
||||
|
||||
// 表结构语句
|
||||
private function tableSql($table)
|
||||
{
|
||||
$sql = '';
|
||||
$sql .= "--" . PHP_EOL;
|
||||
$sql .= "-- 表的结构 `" . $table . '`' . PHP_EOL;
|
||||
$sql .= "--" . PHP_EOL . PHP_EOL;
|
||||
|
||||
$sql .= $this->model->tableStru($table); // 表创建语句
|
||||
return $sql;
|
||||
}
|
||||
|
||||
// 数据语句
|
||||
private function dataSql($table, $fields, $fieldNnum, $data)
|
||||
{
|
||||
if (! $data)
|
||||
return;
|
||||
$sql = '';
|
||||
$sql .= "--" . PHP_EOL;
|
||||
$sql .= "-- 转存表中的数据 `" . $table . "`" . PHP_EOL;
|
||||
$sql .= "--" . PHP_EOL;
|
||||
$sql .= PHP_EOL;
|
||||
|
||||
// 循环每个字段下面的内容
|
||||
|
||||
$sql .= "INSERT INTO `" . $table . "` (" . implode(',', $fields) . ") VALUES" . PHP_EOL;
|
||||
$brackets = "(";
|
||||
foreach ($data as $value) {
|
||||
$sql .= $brackets;
|
||||
$comma = "";
|
||||
for ($i = 0; $i < $fieldNnum; $i ++) {
|
||||
$sql .= ($comma . "'" . decode_string($value[$i]) . "'");
|
||||
$comma = ",";
|
||||
}
|
||||
$sql .= ")";
|
||||
$brackets = "," . PHP_EOL . "(";
|
||||
}
|
||||
$sql .= ';' . PHP_EOL . PHP_EOL;
|
||||
return $sql;
|
||||
}
|
||||
|
||||
// 写入文件
|
||||
private function writeFile($filename, $content)
|
||||
{
|
||||
$sqlfile = DOC_PATH . STATIC_DIR . '/backup/sql/' . $filename;
|
||||
check_file($sqlfile, true);
|
||||
if (file_put_contents($sqlfile, $content)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// 获取并检查表名称
|
||||
private function getTableList()
|
||||
{
|
||||
$list = post('list');
|
||||
foreach ($list as $key => $value) {
|
||||
if (! preg_match('/^[\w]+$/', $value)) {
|
||||
unset($list[$key]);
|
||||
}
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
}
|
||||
275
apps/admin/controller/system/MenuController.php
Normal file
275
apps/admin/controller/system/MenuController.php
Normal file
@@ -0,0 +1,275 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright (C)2016-2099 Hnaoyun Inc.
|
||||
* @author XingMeng
|
||||
* @email hnxsh@foxmail.com
|
||||
* @date 2017年4月3日
|
||||
* 菜单控制器
|
||||
*/
|
||||
namespace app\admin\controller\system;
|
||||
|
||||
use core\basic\Controller;
|
||||
use app\admin\model\system\MenuModel;
|
||||
|
||||
class MenuController extends Controller
|
||||
{
|
||||
|
||||
private $count;
|
||||
|
||||
private $blank;
|
||||
|
||||
private $outData = array();
|
||||
|
||||
private $model;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->model = new MenuModel();
|
||||
}
|
||||
|
||||
// 菜单列表
|
||||
public function index()
|
||||
{
|
||||
$this->assign('list', true);
|
||||
$menus = $this->model->getList();
|
||||
$this->assign('menus', $this->makeMenuList($menus));
|
||||
|
||||
// 菜单下拉列表
|
||||
$menus = $this->model->getSelect();
|
||||
$this->assign('menu_select', $this->makeMenuSelect($menus));
|
||||
|
||||
// 获取菜单按钮
|
||||
$this->assign('actions', get_type('T101'));
|
||||
|
||||
$this->display('system/menu.html');
|
||||
}
|
||||
|
||||
// 生成无限级菜单管理列表
|
||||
private function makeMenuList($tree)
|
||||
{
|
||||
// 循环生成
|
||||
foreach ($tree as $value) {
|
||||
$this->count ++;
|
||||
$this->outData[$this->count] = new \stdClass();
|
||||
$this->outData[$this->count]->id = $value->id;
|
||||
$this->outData[$this->count]->blank = $this->blank;
|
||||
$this->outData[$this->count]->name = $value->name;
|
||||
$this->outData[$this->count]->mcode = $value->mcode;
|
||||
$this->outData[$this->count]->pcode = $value->pcode;
|
||||
$this->outData[$this->count]->sorting = $value->sorting;
|
||||
$this->outData[$this->count]->url = $value->url;
|
||||
$this->outData[$this->count]->status = $value->status;
|
||||
$this->outData[$this->count]->shortcut = $value->shortcut;
|
||||
$this->outData[$this->count]->ico = $value->ico;
|
||||
$this->outData[$this->count]->create_user = $value->create_user;
|
||||
$this->outData[$this->count]->update_user = $value->update_user;
|
||||
$this->outData[$this->count]->create_time = $value->create_time;
|
||||
$this->outData[$this->count]->update_time = $value->update_time;
|
||||
|
||||
if ($value->son) {
|
||||
$this->outData[$this->count]->son = true;
|
||||
} else {
|
||||
$this->outData[$this->count]->son = false;
|
||||
}
|
||||
// 子菜单处理
|
||||
if ($value->son) {
|
||||
$this->blank .= ' ';
|
||||
$this->makeMenuList($value->son);
|
||||
}
|
||||
}
|
||||
// 循环完后回归缩进位置
|
||||
$this->blank = substr($this->blank, 0, - 6);
|
||||
return $this->outData;
|
||||
}
|
||||
|
||||
// 菜单增加
|
||||
public function add()
|
||||
{
|
||||
if ($_POST) {
|
||||
// 获取数据
|
||||
$mcode = get_auto_code($this->model->getLastCode()); // 自动编码
|
||||
$pcode = post('pcode', 'var');
|
||||
$name = post('name');
|
||||
$url = post('url');
|
||||
$sorting = post('sorting', 'int');
|
||||
$status = post('status', 'int');
|
||||
$shortcut = post('shortcut', 'int');
|
||||
$ico = post('ico');
|
||||
$actions = post('actions', 'array', false, '菜单按钮', array());
|
||||
|
||||
if (! $mcode) {
|
||||
alert_back('编码不能为空!');
|
||||
}
|
||||
if (! $pcode) {
|
||||
$pcode = 0; // 父编码默认为0
|
||||
}
|
||||
if (! $name) {
|
||||
alert_back('菜单名称不能为空!');
|
||||
}
|
||||
|
||||
if ($this->model->checkMenu("mcode='$mcode'")) {
|
||||
alert_back('该菜单编号已经存在,不能再使用!');
|
||||
}
|
||||
|
||||
// 菜单地址自动填充
|
||||
if (! $url) {
|
||||
$url = '/' . M . '/' . $mcode . '/index';
|
||||
}
|
||||
|
||||
// 构建数据
|
||||
$data = array(
|
||||
'mcode' => $mcode,
|
||||
'pcode' => $pcode,
|
||||
'name' => $name,
|
||||
'url' => $url,
|
||||
'sorting' => $sorting,
|
||||
'status' => $status,
|
||||
'shortcut' => $shortcut,
|
||||
'ico' => $ico,
|
||||
'create_user' => session('username'),
|
||||
'update_user' => session('username')
|
||||
);
|
||||
|
||||
// 执行添加
|
||||
if ($this->model->addMenu($data, $actions)) {
|
||||
$this->log('新增菜单' . $mcode . '成功!');
|
||||
if (! ! $backurl = get('backurl')) {
|
||||
success('新增成功!', base64_decode($backurl));
|
||||
} else {
|
||||
success('新增成功!', url('admin/Menu/index'));
|
||||
}
|
||||
} else {
|
||||
$this->log('新增菜单' . $mcode . '失败!');
|
||||
error('新增失败!', - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 生成菜单下拉列表
|
||||
private function makeMenuSelect($tree, $selectid = null)
|
||||
{
|
||||
// 初始化
|
||||
$menu_html = '';
|
||||
// 循环生成
|
||||
foreach ($tree as $value) {
|
||||
// 默认选择项
|
||||
if ($selectid == $value->mcode) {
|
||||
$select = "selected='selected'";
|
||||
} else {
|
||||
$select = '';
|
||||
}
|
||||
if (get('mcode') != $value->mcode) { // 不显示本身,避免出现自身为自己的父节点
|
||||
$menu_html .= "<option value='{$value->mcode}' $select />{$this->blank}{$value->mcode} {$value->name}";
|
||||
}
|
||||
// 子菜单处理
|
||||
if ($value->son) {
|
||||
$this->blank .= ' ';
|
||||
$menu_html .= $this->makeMenuSelect($value->son, $selectid);
|
||||
}
|
||||
}
|
||||
// 循环完后回归位置
|
||||
$this->blank = substr($this->blank, 0, - 6);
|
||||
return $menu_html;
|
||||
}
|
||||
|
||||
// 菜单删除
|
||||
public function del()
|
||||
{
|
||||
if (! $mcode = get('mcode', 'var')) {
|
||||
error('传递的参数值错误!', - 1);
|
||||
}
|
||||
if ($this->model->delMenu($mcode)) {
|
||||
$this->log('删除菜单' . $mcode . '成功!');
|
||||
success('删除成功!', - 1);
|
||||
} else {
|
||||
$this->log('删除菜单' . $mcode . '失败!');
|
||||
error('删除失败!', - 1);
|
||||
}
|
||||
}
|
||||
|
||||
// 菜单修改
|
||||
public function mod()
|
||||
{
|
||||
if (! $mcode = get('mcode', 'var')) {
|
||||
error('传递的参数值错误!', - 1);
|
||||
}
|
||||
|
||||
// 单独修改状态
|
||||
if (($field = get('field', 'var')) && ! is_null($value = get('value', 'var'))) {
|
||||
if ($this->model->modMenu($mcode, "$field='$value',update_user='" . session('username') . "'")) {
|
||||
$this->log('修改菜单' . $mcode . '状态' . $value . '成功!');
|
||||
location(- 1);
|
||||
} else {
|
||||
$this->log('修改菜单' . $mcode . '状态' . $value . '失败!');
|
||||
alert_back('修改失败!');
|
||||
}
|
||||
}
|
||||
|
||||
// 修改操作
|
||||
if ($_POST) {
|
||||
// 获取数据
|
||||
$pcode = post('pcode', 'var');
|
||||
$name = post('name');
|
||||
$sorting = post('sorting', 'int');
|
||||
$url = post('url');
|
||||
$status = post('status', 'int');
|
||||
$shortcut = post('shortcut', 'int');
|
||||
$ico = post('ico');
|
||||
$actions = post('actions', 'array', false, '菜单按钮', array());
|
||||
|
||||
if (! $pcode) {
|
||||
$pcode = 0; // 父编码默认为0
|
||||
}
|
||||
if (! $name) {
|
||||
alert_back('菜单名称不能为空!');
|
||||
}
|
||||
// 菜单地址自动填充
|
||||
if (! $url) {
|
||||
$url = '/' . M . '/' . $mcode . '/index';
|
||||
}
|
||||
|
||||
// 构建数据
|
||||
$data = array(
|
||||
'pcode' => $pcode,
|
||||
'name' => $name,
|
||||
'sorting' => $sorting,
|
||||
'url' => $url,
|
||||
'status' => $status,
|
||||
'shortcut' => $shortcut,
|
||||
'ico' => $ico,
|
||||
'update_user' => session('username')
|
||||
);
|
||||
|
||||
// 执行修改
|
||||
if ($this->model->modMenu($mcode, $data, $actions)) {
|
||||
$this->log('修改菜单' . $mcode . '成功!');
|
||||
if (! ! $backurl = get('backurl')) {
|
||||
success('修改成功!', base64_decode($backurl));
|
||||
} else {
|
||||
success('修改成功!', url('admin/Menu/index'));
|
||||
}
|
||||
} else {
|
||||
location(- 1);
|
||||
}
|
||||
} else { // 调取修改内容
|
||||
|
||||
$this->assign('mod', true);
|
||||
|
||||
$result = $this->model->getMenu($mcode);
|
||||
if (! $result) {
|
||||
error('编辑的内容已经不存在!', - 1);
|
||||
}
|
||||
$this->assign('menu', $result); // 菜单信息
|
||||
|
||||
// 获取菜单按钮组
|
||||
$this->assign('actions', get_type('T101'));
|
||||
|
||||
// 菜单下拉列表
|
||||
$menus = $this->model->getSelect();
|
||||
$this->assign('menu_select', $this->makeMenuSelect($menus, $result->pcode));
|
||||
|
||||
// 显示
|
||||
$this->display('system/menu.html');
|
||||
}
|
||||
}
|
||||
}
|
||||
249
apps/admin/controller/system/RoleController.php
Normal file
249
apps/admin/controller/system/RoleController.php
Normal file
@@ -0,0 +1,249 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright (C)2016-2099 Hnaoyun Inc.
|
||||
* @author XingMeng
|
||||
* @email hnxsh@foxmail.com
|
||||
* @date 2017年4月3日
|
||||
* 角色控制器
|
||||
*/
|
||||
namespace app\admin\controller\system;
|
||||
|
||||
use core\basic\Controller;
|
||||
use app\admin\model\system\RoleModel;
|
||||
|
||||
class RoleController extends Controller
|
||||
{
|
||||
|
||||
private $blank;
|
||||
|
||||
private $model;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->model = new RoleModel();
|
||||
}
|
||||
|
||||
// 角色列表
|
||||
public function index()
|
||||
{
|
||||
$this->assign('list', true);
|
||||
$this->assign('roles', $this->model->getList());
|
||||
|
||||
// 数据区域选择
|
||||
$area_model = model('admin.system.Area');
|
||||
$area_tree = $area_model->getSelect();
|
||||
$area_checkbox = $this->makeAreaCheckbox($area_tree);
|
||||
$this->assign('area_checkbox', $area_checkbox);
|
||||
|
||||
// 菜单权限表
|
||||
$menu_model = model('admin.system.Menu');
|
||||
$menu_level = $menu_model->getMenuLevel();
|
||||
$menus = $menu_model->getSelect();
|
||||
$menu_list = $this->makeLevelList($menus, $menu_level);
|
||||
$this->assign('menu_list', $menu_list);
|
||||
|
||||
$this->display('system/role.html');
|
||||
}
|
||||
|
||||
// 角色增加
|
||||
public function add()
|
||||
{
|
||||
if ($_POST) {
|
||||
// 获取数据
|
||||
$rcode = get_auto_code($this->model->getLastCode()); // 自动编码
|
||||
$name = post('name');
|
||||
$description = post('description');
|
||||
$acodes = post('acodes', 'array', false, '角色数据区域', array()); // 区域
|
||||
$levels = post('levels', 'array', false, '角色权限', array()); // 权限
|
||||
|
||||
if (! $rcode) {
|
||||
alert_back('编码不能为空!');
|
||||
}
|
||||
|
||||
if (! $name) {
|
||||
alert_back('角色名不能为空!');
|
||||
}
|
||||
|
||||
// 检查编码
|
||||
if ($this->model->checkRole("rcode='$rcode'")) {
|
||||
alert_back('该角色编号已经存在,不能再使用!');
|
||||
}
|
||||
|
||||
// 构建数据
|
||||
$data = array(
|
||||
'rcode' => $rcode,
|
||||
'name' => $name,
|
||||
'description' => $description,
|
||||
'create_user' => session('username'),
|
||||
'update_user' => session('username')
|
||||
);
|
||||
|
||||
// 执行添加
|
||||
if ($this->model->addRole($data, $acodes, $levels)) {
|
||||
$this->log('修改角色' . $rcode . '成功!');
|
||||
if (! ! $backurl = get('backurl')) {
|
||||
success('新增成功!', base64_decode($backurl));
|
||||
} else {
|
||||
success('新增成功!', url('admin/Role/index'));
|
||||
}
|
||||
} else {
|
||||
$this->log('修改角色' . $rcode . '失败!');
|
||||
error('新增失败!', - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 生成区域选择,无限制
|
||||
private function makeAreaCheckbox($tree, $checkeds = array())
|
||||
{
|
||||
$list_html = '';
|
||||
foreach ($tree as $values) {
|
||||
if (in_array($values->acode, $checkeds)) {
|
||||
$checked = 'checked="checked"';
|
||||
} else {
|
||||
$checked = '';
|
||||
}
|
||||
if (! $values->son) { // 没有子类才显示选择框
|
||||
$list_html .= "<input type='checkbox' $checked name='acodes[]' value='{$values->acode}' title='{$values->acode}-{$values->name}'>";
|
||||
} else {
|
||||
$list_html .= $this->makeAreaCheckbox($values->son, $checkeds);
|
||||
}
|
||||
}
|
||||
return $list_html;
|
||||
}
|
||||
|
||||
// 生成无限级菜单权限列表
|
||||
private function makeLevelList($menus, $menu_level, $checkeds = array())
|
||||
{
|
||||
$menu_html = '';
|
||||
foreach ($menus as $value) {
|
||||
$string = '';
|
||||
// 根据是否有子栏目生成图标
|
||||
if ($value->son) {
|
||||
$ico = "<i class='fa fa-folder-open-o' aria-hidden='true'></i>";
|
||||
} else {
|
||||
$ico = "<i class='fa fa-folder-o' aria-hidden='true'></i>";
|
||||
}
|
||||
|
||||
// 选中状态
|
||||
if (in_array($value->url, $checkeds)) {
|
||||
$checked = 'checked="checked"';
|
||||
} else {
|
||||
$checked = '';
|
||||
}
|
||||
|
||||
// 获取模块及控制器路径
|
||||
if ($value->url) {
|
||||
$pre_url = substr($value->url, 0, get_strpos($value->url, '/', 3) + 1);
|
||||
} else {
|
||||
error('"' . $value->name . '"菜单地址为空,请核对!');
|
||||
}
|
||||
|
||||
$string = "<input type='checkbox' $checked class='checkbox' lay-skin='primary' name='levels[]' value='" . $value->url . "' title='浏览'>";
|
||||
$mcode = $value->mcode;
|
||||
if (array_key_exists($mcode, $menu_level)) {
|
||||
foreach ($menu_level[$mcode] as $key2 => $value2) {
|
||||
$url = $pre_url . $value2->value;
|
||||
if (in_array($url, $checkeds)) {
|
||||
$checked = 'checked="checked"';
|
||||
} else {
|
||||
$checked = '';
|
||||
}
|
||||
$string .= "<input type='checkbox' $checked class='checkbox'lay-skin='primary' name='levels[]' value='$url' title='{$value2->item}'>";
|
||||
}
|
||||
}
|
||||
|
||||
// 生成菜单html
|
||||
$menu_html .= "<div class='layui-row'><div class='layui-col-md3 layui-col-lg2' style='margin-top:10px;'>{$this->blank} $ico {$value->name}</div><div class='layui-col-md9'>$string</div></div>";
|
||||
|
||||
// 子菜单处理
|
||||
if ($value->son) {
|
||||
$this->blank .= ' ';
|
||||
$menu_html .= $this->makeLevelList($value->son, $menu_level, $checkeds);
|
||||
}
|
||||
}
|
||||
|
||||
// 循环完后回归缩进位置
|
||||
$this->blank = substr($this->blank, 0, - 6);
|
||||
return $menu_html;
|
||||
}
|
||||
|
||||
// 角色删除
|
||||
public function del()
|
||||
{
|
||||
if (! $rcode = get('rcode', 'var')) {
|
||||
error('传递的参数值错误!', - 1);
|
||||
}
|
||||
if ($this->model->delRole($rcode)) {
|
||||
$this->log('删除角色' . $rcode . '成功!');
|
||||
success('删除成功!', - 1);
|
||||
} else {
|
||||
$this->log('删除角色' . $rcode . '失败!');
|
||||
error('删除失败!', - 1);
|
||||
}
|
||||
}
|
||||
|
||||
// 角色修改
|
||||
public function mod()
|
||||
{
|
||||
if (! $rcode = get('rcode', 'var')) {
|
||||
error('传递的参数值错误!', - 1);
|
||||
}
|
||||
|
||||
// 修改操作
|
||||
if ($_POST) {
|
||||
// 获取数据
|
||||
$name = post('name');
|
||||
$description = post('description');
|
||||
$acodes = post('acodes', 'array', false, '角色数据区域', array()); // 区域
|
||||
$levels = post('levels', 'array', false, '角色权限', array()); // 权限
|
||||
|
||||
if (! $name) {
|
||||
alert_back('角色名不能为空!');
|
||||
}
|
||||
|
||||
// 构建数据
|
||||
$data = array(
|
||||
'name' => $name,
|
||||
'description' => $description,
|
||||
'update_user' => session('username')
|
||||
);
|
||||
|
||||
// 执行修改
|
||||
if ($this->model->modRole($rcode, $data, $acodes, $levels)) {
|
||||
$this->log('修改角色' . $rcode . '成功!');
|
||||
if (! ! $backurl = get('backurl')) {
|
||||
success('修改成功!', base64_decode($backurl));
|
||||
} else {
|
||||
success('修改成功!', url('admin/Role/index'));
|
||||
}
|
||||
} else {
|
||||
location(- 1);
|
||||
}
|
||||
} else {
|
||||
$this->assign('mod', true);
|
||||
|
||||
// 调取修改内容
|
||||
$result = $this->model->getRole($rcode);
|
||||
if (! $result) {
|
||||
error('编辑的内容已经不存在!', - 1);
|
||||
}
|
||||
$this->assign('role', $result);
|
||||
|
||||
// 数据区域选择
|
||||
$area_model = model('admin.system.Area');
|
||||
$area_tree = $area_model->getSelect();
|
||||
$area_checkbox = $this->makeAreaCheckbox($area_tree, $result->acodes);
|
||||
$this->assign('area_checkbox', $area_checkbox);
|
||||
|
||||
// 菜单权限表
|
||||
$menu_model = model('admin.system.Menu');
|
||||
$menu_level = $menu_model->getMenuLevel();
|
||||
$menus = $menu_model->getSelect();
|
||||
$menu_list = $this->makeLevelList($menus, $menu_level, $result->levels);
|
||||
$this->assign('menu_list', $menu_list);
|
||||
|
||||
$this->display('system/role.html');
|
||||
}
|
||||
}
|
||||
}
|
||||
40
apps/admin/controller/system/SyslogController.php
Normal file
40
apps/admin/controller/system/SyslogController.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright (C)2016-2099 Hnaoyun Inc.
|
||||
* @author XingMeng
|
||||
* @email hnxsh@foxmail.com
|
||||
* @date 2017年3月29日
|
||||
* 系统日志控制器
|
||||
*/
|
||||
namespace app\admin\controller\system;
|
||||
|
||||
use core\basic\Controller;
|
||||
use app\admin\model\system\SyslogModel;
|
||||
|
||||
class SyslogController extends Controller
|
||||
{
|
||||
|
||||
private $model;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->model = new SyslogModel();
|
||||
}
|
||||
|
||||
// 日志列表
|
||||
public function index()
|
||||
{
|
||||
$this->assign('syslogs', $this->model->getList());
|
||||
$this->display('system/syslog.html');
|
||||
}
|
||||
|
||||
// 清理日志
|
||||
public function clear()
|
||||
{
|
||||
if ($this->model->clearLog()) {
|
||||
alert_location('清空成功!', url('/admin/Syslog/index'));
|
||||
} else {
|
||||
alert_location('清空失败!', url('/admin/Syslog/index'));
|
||||
}
|
||||
}
|
||||
}
|
||||
172
apps/admin/controller/system/TypeController.php
Normal file
172
apps/admin/controller/system/TypeController.php
Normal file
@@ -0,0 +1,172 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright (C)2016-2099 Hnaoyun Inc.
|
||||
* @author XingMeng
|
||||
* @email hnxsh@foxmail.com
|
||||
* @date 2017年4月13日
|
||||
* 类型控制器
|
||||
*/
|
||||
namespace app\admin\controller\system;
|
||||
|
||||
use core\basic\Controller;
|
||||
use app\admin\model\system\TypeModel;
|
||||
|
||||
class TypeController extends Controller
|
||||
{
|
||||
|
||||
private $model;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->model = new TypeModel();
|
||||
}
|
||||
|
||||
// 类型列表
|
||||
public function index()
|
||||
{
|
||||
$this->assign('list', true);
|
||||
if (! ! ($field = get('field', 'var')) && ! ! ($keyword = get('keyword', 'vars'))) {
|
||||
$result = $this->model->findType($field, $keyword);
|
||||
} else {
|
||||
$result = $this->model->getList();
|
||||
}
|
||||
|
||||
$this->assign('types', $result);
|
||||
|
||||
// 类型选择
|
||||
$this->assign('type_select', $this->model->getSelect());
|
||||
|
||||
$this->display('system/type.html');
|
||||
}
|
||||
|
||||
// 类型增加
|
||||
public function add()
|
||||
{
|
||||
if ($_POST) {
|
||||
// 获取数据
|
||||
$tcode = post('tcode', 'var');
|
||||
$name = post('name');
|
||||
$item = post('item');
|
||||
$value = post('value', 'var');
|
||||
$sorting = post('sorting', 'int');
|
||||
|
||||
if (! $tcode) {
|
||||
$tcode = get_auto_code($this->model->getLastCode()); // 自动编码
|
||||
}
|
||||
|
||||
if (! $name) {
|
||||
alert_back('类型名不能为空!');
|
||||
}
|
||||
|
||||
if (! $item) {
|
||||
alert_back('类型项名称不能为空!');
|
||||
}
|
||||
|
||||
if (is_null($value)) {
|
||||
alert_back('类型项值不能为空!');
|
||||
}
|
||||
|
||||
// 构建数据
|
||||
$data = array(
|
||||
'tcode' => $tcode,
|
||||
'name' => $name,
|
||||
'item' => $item,
|
||||
'value' => $value,
|
||||
'sorting' => $sorting,
|
||||
'create_user' => session('username'),
|
||||
'update_user' => session('username')
|
||||
);
|
||||
|
||||
// 执行添加
|
||||
if ($this->model->addType($data)) {
|
||||
$this->log('新增类型' . $tcode . '-' . $item . '成功!');
|
||||
if (! ! $backurl = get('backurl')) {
|
||||
success('新增成功!', base64_decode($backurl));
|
||||
} else {
|
||||
success('新增成功!', url('/admin/Type/index'));
|
||||
}
|
||||
} else {
|
||||
$this->log('新增类型' . $tcode . '-' . $item . '失败!');
|
||||
error('新增失败!', - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 类型删除
|
||||
public function del()
|
||||
{
|
||||
if (! $id = get('id', 'int')) {
|
||||
error('传递的参数值错误!', - 1);
|
||||
}
|
||||
if ($id < 7) {
|
||||
alert_back('该类型不允许删除!');
|
||||
}
|
||||
|
||||
if ($this->model->delType($id)) {
|
||||
$this->log('删除类型项' . $id . '成功!');
|
||||
success('删除成功!', - 1);
|
||||
} else {
|
||||
$this->log('删除类型项' . $id . '失败!');
|
||||
error('删除失败!', - 1);
|
||||
}
|
||||
}
|
||||
|
||||
// 类型修改
|
||||
public function mod()
|
||||
{
|
||||
if (! $id = get('id', 'int')) {
|
||||
error('传递的参数值错误!', - 1);
|
||||
}
|
||||
|
||||
// 修改操作
|
||||
if ($_POST) {
|
||||
// 获取数据
|
||||
$name = post('name');
|
||||
$item = post('item');
|
||||
$value = post('value', 'var');
|
||||
$sorting = post('sorting', 'int');
|
||||
|
||||
if (! $name) {
|
||||
alert_back('类型名不能为空!');
|
||||
}
|
||||
|
||||
if (! $item) {
|
||||
alert_back('类型项名称不能为空!');
|
||||
}
|
||||
|
||||
if (is_null($value)) {
|
||||
alert_back('类型项值不能为空!');
|
||||
}
|
||||
|
||||
// 构建数据
|
||||
$data = array(
|
||||
'name' => $name,
|
||||
'item' => $item,
|
||||
'value' => $value,
|
||||
'sorting' => $sorting,
|
||||
'update_user' => session('username')
|
||||
);
|
||||
|
||||
// 执行添加
|
||||
if ($this->model->modType($id, $data)) {
|
||||
$this->log('修改类型项' . $id . '成功!');
|
||||
if (! ! $backurl = get('backurl')) {
|
||||
success('修改成功!', base64_decode($backurl));
|
||||
} else {
|
||||
success('修改成功!', url('/admin/Type/index'));
|
||||
}
|
||||
} else {
|
||||
location(- 1);
|
||||
}
|
||||
} else {
|
||||
// 调取修改内容
|
||||
$this->assign('mod', true);
|
||||
|
||||
if (! $result = $this->model->getType($id)) {
|
||||
error('编辑的内容已经不存在!', - 1);
|
||||
}
|
||||
$this->assign('type', $result);
|
||||
$this->display('system/type.html');
|
||||
}
|
||||
}
|
||||
}
|
||||
391
apps/admin/controller/system/UpgradeController.php
Normal file
391
apps/admin/controller/system/UpgradeController.php
Normal file
@@ -0,0 +1,391 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright (C)2016-2099 Hnaoyun Inc.
|
||||
* @author XingMeng
|
||||
* @email hnxsh@foxmail.com
|
||||
* @date 2018年8月14日
|
||||
* 在线更新
|
||||
*/
|
||||
namespace app\admin\controller\system;
|
||||
|
||||
use core\basic\Controller;
|
||||
use core\basic\Model;
|
||||
|
||||
class UpgradeController extends Controller
|
||||
{
|
||||
|
||||
// 服务器地址
|
||||
private $server = 'https://www.pbootcms.com';
|
||||
|
||||
// 更新分支
|
||||
private $branch;
|
||||
|
||||
// 强制同步文件
|
||||
private $force;
|
||||
|
||||
// 修改版本
|
||||
private $revise;
|
||||
|
||||
// 文件列表
|
||||
public $files = array();
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
error_reporting(0);
|
||||
$this->branch = $this->config('upgrade_branch') == '3.X.dev' ? '3.X.dev' : '3.X';
|
||||
$this->force = $this->config('upgrade_force') ?: 0;
|
||||
$this->revise = $this->config('revise_version') ?: 0;
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
switch (get('action')) {
|
||||
case 'local':
|
||||
$upfile = $this->local();
|
||||
break;
|
||||
default:
|
||||
$upfile = array();
|
||||
}
|
||||
$this->assign('upfile', $upfile);
|
||||
$this->assign('branch', $this->branch);
|
||||
$this->assign('force', $this->force);
|
||||
$this->assign('revise', $this->revise);
|
||||
$this->assign('snuser', $this->config('sn_user') ?: 0);
|
||||
$this->assign('site', get_http_url());
|
||||
$this->display('system/upgrade.html');
|
||||
}
|
||||
|
||||
// 检查更新
|
||||
public function check()
|
||||
{
|
||||
// 清理目录,检查下载目录及备份目录
|
||||
path_delete(RUN_PATH . '/upgrade', true);
|
||||
if (! check_dir(RUN_PATH . '/upgrade', true)) {
|
||||
json(0, '目录写入权限不足,无法正常升级!' . RUN_PATH . '/upgrade');
|
||||
}
|
||||
check_dir(DOC_PATH . STATIC_DIR . '/backup/upgrade', true);
|
||||
|
||||
$files = $this->getServerList();
|
||||
$db = get_db_type();
|
||||
foreach ($files as $key => $value) {
|
||||
// 过滤掉相对路径
|
||||
$value->path = preg_replace_r('{\.\.(\/|\\\\)}', '', $value->path);
|
||||
$file = ROOT_PATH . $value->path;
|
||||
if (@md5_file($file) != $value->md5) {
|
||||
// 筛选数据库更新脚本
|
||||
if (preg_match('/([\w]+)-([\w\.]+)-update\.sql/i', $file, $matches)) {
|
||||
if ($matches[1] != $db || ! $this->compareVersion($matches[2], APP_VERSION . '.' . RELEASE_TIME . '.' . $this->revise)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (file_exists($file)) {
|
||||
$files[$key]->type = '<span style="color:Red">覆盖</span>';
|
||||
$files[$key]->ltime = date('Y-m-d H:i:s', filemtime($file));
|
||||
} else {
|
||||
$files[$key]->type = '新增';
|
||||
$files[$key]->ltime = '无';
|
||||
}
|
||||
$files[$key]->ctime = date('Y-m-d H:i:s', $files[$key]->ctime);
|
||||
$upfile[] = $files[$key];
|
||||
}
|
||||
}
|
||||
if (! $upfile) {
|
||||
json(1, '您的系统无任何文件需要更新!');
|
||||
} else {
|
||||
json(1, $upfile);
|
||||
}
|
||||
}
|
||||
|
||||
// 执行下载
|
||||
public function down()
|
||||
{
|
||||
if (! ! $list = get('list')) {
|
||||
if (! is_array($list)) { // 单个文件转换为数组
|
||||
$list = array(
|
||||
$list
|
||||
);
|
||||
}
|
||||
$len = count($list) ?: 0;
|
||||
foreach ($list as $value) {
|
||||
// 过滤掉相对路径
|
||||
$value = preg_replace_r('{\.\.(\/|\\\\)}', '', $value);
|
||||
// 本地存储路径
|
||||
$path = RUN_PATH . '/upgrade' . $value;
|
||||
// 自动创建目录
|
||||
if (! check_dir(dirname($path), true)) {
|
||||
json(0, '目录写入权限不足,无法下载升级文件!' . dirname($path));
|
||||
}
|
||||
|
||||
// 定义执行下载的类型
|
||||
$types = '.zip|.rar|.doc|.docx|.ppt|.pptx|.xls|.xlsx|.chm|.ttf|.otf|';
|
||||
$pathinfo = explode(".", basename($path));
|
||||
$ext = end($pathinfo); // 获取扩展
|
||||
if (preg_match('/\.' . $ext . '\|/i', $types)) {
|
||||
$result = $this->getServerDown('/release/' . $this->branch . $value, $path);
|
||||
} else {
|
||||
$result = $this->getServerFile($value, $path);
|
||||
}
|
||||
}
|
||||
if ($len == 1) {
|
||||
json(1, "更新文件 " . basename($value) . " 下载成功!");
|
||||
} else {
|
||||
json(1, "更新文件" . basename($value) . "等文件全部下载成功!");
|
||||
}
|
||||
} else {
|
||||
json(0, '请选择要下载的文件!');
|
||||
}
|
||||
}
|
||||
|
||||
// 执行更新
|
||||
public function update()
|
||||
{
|
||||
if ($_POST) {
|
||||
if (! ! $list = post('list')) {
|
||||
$list = explode(',', $list);
|
||||
$backdir = date('YmdHis');
|
||||
|
||||
// 分离文件
|
||||
foreach ($list as $value) {
|
||||
// 过滤掉相对路径
|
||||
$value = preg_replace_r('{\.\.(\/|\\\\)}', '', $value);
|
||||
|
||||
if (stripos($value, '/script/') === 0 && preg_match('/\.sql$/i', $value)) {
|
||||
$sqls[] = $value;
|
||||
} else {
|
||||
$path = RUN_PATH . '/upgrade' . $value;
|
||||
$des_path = ROOT_PATH . $value;
|
||||
$back_path = DOC_PATH . STATIC_DIR . '/backup/upgrade/' . $backdir . $value;
|
||||
if (! check_dir(dirname($des_path), true)) {
|
||||
json(0, '目录写入权限不足,无法正常升级!' . dirname($des_path));
|
||||
}
|
||||
if (file_exists($des_path)) { // 文件存在时执行备份
|
||||
check_dir(dirname($back_path), true);
|
||||
copy($des_path, $back_path);
|
||||
}
|
||||
|
||||
// 如果后台入口文件修改过名字,则自动适配
|
||||
if (stripos($path, 'admin.php') !== false && stripos($_SERVER['SCRIPT_FILENAME'], 'admin.php') === false) {
|
||||
if (file_exists($_SERVER['SCRIPT_FILENAME'])) {
|
||||
$des_path = $_SERVER['SCRIPT_FILENAME'];
|
||||
}
|
||||
}
|
||||
|
||||
$files[] = array(
|
||||
'sfile' => $path,
|
||||
'dfile' => $des_path
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// 更新数据库
|
||||
if (isset($sqls)) {
|
||||
$db = new DatabaseController();
|
||||
switch (get_db_type()) {
|
||||
case 'sqlite':
|
||||
copy(DOC_PATH . $this->config('database.dbname'), DOC_PATH . STATIC_DIR . '/backup/sql/' . date('YmdHis') . '_' . basename($this->config('database.dbname')));
|
||||
break;
|
||||
case 'mysql':
|
||||
$db->backupDB();
|
||||
break;
|
||||
}
|
||||
sort($sqls); // 排序
|
||||
foreach ($sqls as $value) {
|
||||
$path = RUN_PATH . '/upgrade' . $value;
|
||||
if (file_exists($path)) {
|
||||
$sql = file_get_contents($path);
|
||||
if (! $this->upsql($sql)) {
|
||||
$this->log("数据库 $value 更新失败!");
|
||||
json(0, "数据库" . basename($value) . " 更新失败!");
|
||||
}
|
||||
} else {
|
||||
json(0, "数据库文件" . basename($value) . "不存在!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 替换文件
|
||||
if (isset($files)) {
|
||||
foreach ($files as $value) {
|
||||
if (! copy($value['sfile'], $value['dfile'])) {
|
||||
$this->log("文件 " . $value['dfile'] . " 更新失败!");
|
||||
json(0, "文件 " . basename($value['dfile']) . " 更新失败,请重试!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 清理缓存
|
||||
path_delete(RUN_PATH . '/upgrade', true);
|
||||
path_delete(RUN_PATH . '/cache');
|
||||
path_delete(RUN_PATH . '/complite');
|
||||
path_delete(RUN_PATH . '/config');
|
||||
|
||||
$this->log("系统更新成功!");
|
||||
json(1, '系统更新成功!');
|
||||
} else {
|
||||
json(0, '请选择要更新的文件!');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 缓存文件
|
||||
private function local()
|
||||
{
|
||||
$files = $this->getLoaclList(RUN_PATH . '/upgrade');
|
||||
$files = json_decode(json_encode($files));
|
||||
foreach ($files as $key => $value) {
|
||||
$file = ROOT_PATH . $value->path;
|
||||
if (file_exists($file)) {
|
||||
$files[$key]->type = '<span style="color:Red">覆盖</span>';
|
||||
$files[$key]->ltime = date('Y-m-d H:i:s', filemtime($file));
|
||||
} else {
|
||||
$files[$key]->type = '新增';
|
||||
$files[$key]->ltime = '无';
|
||||
}
|
||||
$files[$key]->ctime = date('Y-m-d H:i:s', $files[$key]->ctime);
|
||||
$upfile[] = $files[$key];
|
||||
}
|
||||
return $upfile;
|
||||
}
|
||||
|
||||
// 执行更新数据库
|
||||
private function upsql($sql)
|
||||
{
|
||||
$sql = explode(';', $sql);
|
||||
$model = new Model();
|
||||
foreach ($sql as $value) {
|
||||
$value = trim($value);
|
||||
if ($value) {
|
||||
$model->amd($value);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// 获取列表
|
||||
private function getServerList()
|
||||
{
|
||||
$param = array(
|
||||
'version' => APP_VERSION . '.' . RELEASE_TIME . '.' . $this->revise,
|
||||
'branch' => $this->branch,
|
||||
'force' => $this->force,
|
||||
'site' => get_http_url(),
|
||||
'snuser' => $this->config('sn_user')
|
||||
);
|
||||
$url = $this->server . '/index.php?p=/upgrade/getlist&' . http_build_query($param);
|
||||
if (! ! $rs = json_decode(get_url($url, '', '', true))) {
|
||||
if ($rs->code) {
|
||||
if (is_array($rs->data)) {
|
||||
return $rs->data;
|
||||
} else {
|
||||
json(1, $rs->data);
|
||||
}
|
||||
} else {
|
||||
json(0, $rs->data);
|
||||
}
|
||||
} else {
|
||||
$this->log('连接更新服务器发生错误,请稍后再试!');
|
||||
json(0, '连接更新服务器发生错误,请稍后再试!');
|
||||
}
|
||||
}
|
||||
|
||||
// 获取文件
|
||||
private function getServerFile($source, $des)
|
||||
{
|
||||
$url = $this->server . '/index.php?p=/upgrade/getFile&branch=' . $this->branch;
|
||||
$data['path'] = $source;
|
||||
$file = basename($source);
|
||||
if (! ! $rs = json_decode(get_url($url, $data, '', true))) {
|
||||
if ($rs->code) {
|
||||
if (! file_put_contents($des, base64_decode($rs->data))) {
|
||||
$this->log("更新文件 " . $file . " 下载失败!");
|
||||
json(0, "更新文件 " . $file . " 下载失败!");
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
json(0, $rs->data);
|
||||
}
|
||||
} else {
|
||||
$this->log("更新文件 " . $file . " 获取失败!");
|
||||
json(0, "更新文件 " . $file . " 获取失败!");
|
||||
}
|
||||
}
|
||||
|
||||
// 获取非文本文件
|
||||
private function getServerDown($source, $des)
|
||||
{
|
||||
$url = $this->server . $source;
|
||||
$file = basename($source);
|
||||
if (($sfile = fopen($url, "rb")) && ($dfile = fopen($des, "wb"))) {
|
||||
while (! feof($sfile)) {
|
||||
$fwrite = fwrite($dfile, fread($sfile, 1024 * 8), 1024 * 8);
|
||||
if ($fwrite === false) {
|
||||
$this->log("更新文件 " . $file . " 下载失败!");
|
||||
json(0, "更新文件 " . $file . " 下载失败!");
|
||||
}
|
||||
}
|
||||
if ($sfile) {
|
||||
fclose($sfile);
|
||||
}
|
||||
if ($dfile) {
|
||||
fclose($dfile);
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
$this->log("更新文件 " . $file . " 获取失败!");
|
||||
json(0, "更新文件 " . $file . " 获取失败!");
|
||||
}
|
||||
}
|
||||
|
||||
// 获取文件列表
|
||||
private function getLoaclList($path)
|
||||
{
|
||||
$files = scandir($path);
|
||||
foreach ($files as $value) {
|
||||
if ($value != '.' && $value != '..') {
|
||||
if (is_dir($path . '/' . $value)) {
|
||||
$this->getLoaclList($path . '/' . $value);
|
||||
} else {
|
||||
$file = $path . '/' . $value;
|
||||
|
||||
// 避免中文乱码
|
||||
if (! mb_check_encoding($file, 'utf-8')) {
|
||||
$out_path = mb_convert_encoding($file, 'UTF-8', 'GBK');
|
||||
} else {
|
||||
$out_path = $file;
|
||||
}
|
||||
|
||||
$out_path = str_replace(RUN_PATH . '/upgrade', '', $out_path);
|
||||
|
||||
$this->files[] = array(
|
||||
'path' => $out_path,
|
||||
'md5' => md5_file($file),
|
||||
'ctime' => filemtime($file)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $this->files;
|
||||
}
|
||||
|
||||
// 比较程序本号
|
||||
private function compareVersion($sv, $cv)
|
||||
{
|
||||
if (empty($sv) || $sv == $cv) {
|
||||
return 0;
|
||||
}
|
||||
$sv = explode('.', $sv);
|
||||
$cv = explode('.', $cv);
|
||||
$len = count($sv) > count($cv) ? count($sv) : count($cv);
|
||||
for ($i = 0; $i < $len; $i ++) {
|
||||
$n1 = $sv[$i] or 0;
|
||||
$n2 = $cv[$i] or 0;
|
||||
if ($n1 > $n2) {
|
||||
return 1;
|
||||
} elseif ($n1 < $n2) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
227
apps/admin/controller/system/UserController.php
Normal file
227
apps/admin/controller/system/UserController.php
Normal file
@@ -0,0 +1,227 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright (C)2016-2099 Hnaoyun Inc.
|
||||
* @author XingMeng
|
||||
* @email hnxsh@foxmail.com
|
||||
* @date 2017年4月3日
|
||||
* 用户控制器
|
||||
*/
|
||||
namespace app\admin\controller\system;
|
||||
|
||||
use core\basic\Controller;
|
||||
use app\admin\model\system\UserModel;
|
||||
|
||||
class UserController extends Controller
|
||||
{
|
||||
|
||||
private $model;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->model = new UserModel();
|
||||
}
|
||||
|
||||
// 用户列表
|
||||
public function index()
|
||||
{
|
||||
$this->assign('list', true);
|
||||
if ((! ! $field = get('field', 'var')) && (! ! $keyword = get('keyword', 'vars'))) {
|
||||
$result = $this->model->findUser($field, $keyword);
|
||||
} else {
|
||||
$result = $this->model->getList();
|
||||
}
|
||||
$this->assign('users', $result);
|
||||
// 角色列表
|
||||
$role_model = model('admin.system.Role');
|
||||
$this->assign('roles', $role_model->getSelect());
|
||||
|
||||
$this->display('system/user.html');
|
||||
}
|
||||
|
||||
// 用户新增
|
||||
public function add()
|
||||
{
|
||||
if ($_POST) {
|
||||
// 获取数据
|
||||
$ucode = get_auto_code($this->model->getLastCode());
|
||||
$username = post('username');
|
||||
$realname = post('realname');
|
||||
$password = post('password');
|
||||
$rpassword = post('rpassword');
|
||||
$status = post('status', 'int');
|
||||
$roles = post('roles', 'array', true, '用户角色', array()); // 用户角色
|
||||
|
||||
if (! $ucode) {
|
||||
alert_back('编码不能为空!');
|
||||
}
|
||||
if (! $username) {
|
||||
alert_back('用户名不能为空!');
|
||||
}
|
||||
if (! $realname) {
|
||||
alert_back('真实名字不能为空!');
|
||||
}
|
||||
if (! $password) {
|
||||
alert_back('密码不能为空!');
|
||||
}
|
||||
if (! $rpassword) {
|
||||
alert_back('确认密码不能为空!');
|
||||
}
|
||||
if ($password != $rpassword) {
|
||||
alert_back('确认密码不正确!');
|
||||
}
|
||||
|
||||
if (! preg_match('/^[\x{4e00}-\x{9fa5}\w\-\.@]+$/u', $username)) {
|
||||
alert_back('用户名含有不允许的特殊字符!');
|
||||
}
|
||||
|
||||
// 检查编码重复
|
||||
if ($this->model->checkUser("ucode='$ucode'")) {
|
||||
alert_back('该用户编号已经存在,不能再使用!');
|
||||
}
|
||||
|
||||
// 检查用户名重复
|
||||
if ($this->model->checkUser("username='$username'")) {
|
||||
alert_back('该用户名已经存在,不能再使用!');
|
||||
}
|
||||
|
||||
// 构建数据
|
||||
$data = array(
|
||||
'ucode' => $ucode,
|
||||
'username' => $username,
|
||||
'realname' => $realname,
|
||||
'password' => encrypt_string($password),
|
||||
'status' => $status,
|
||||
'login_count' => 0,
|
||||
'last_login_ip' => 0,
|
||||
'create_user' => session('username'),
|
||||
'update_user' => session('username'),
|
||||
'create_time' => get_datetime(),
|
||||
'update_time' => '0000-00-00 00:00:00'
|
||||
);
|
||||
|
||||
// 执行添加
|
||||
if ($this->model->addUser($data, $roles)) {
|
||||
$this->log('新增用户' . $ucode . '成功!');
|
||||
if (! ! $backurl = get('backurl')) {
|
||||
success('新增成功!', base64_decode($backurl));
|
||||
} else {
|
||||
success('新增成功!', url('/admin/User/index'));
|
||||
}
|
||||
} else {
|
||||
$this->log('新增用户' . $ucode . '失败!');
|
||||
error('新增失败', - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 用户删除
|
||||
public function del()
|
||||
{
|
||||
if (! $ucode = get('ucode', 'var')) {
|
||||
error('传递的参数值错误!', - 1);
|
||||
}
|
||||
|
||||
if ($ucode == '10001') {
|
||||
error('内置管理员不允许删除!', - 1);
|
||||
}
|
||||
|
||||
if ($this->model->delUser($ucode)) {
|
||||
$this->log('删除用户' . $ucode . '成功!');
|
||||
success('删除成功!', - 1);
|
||||
} else {
|
||||
$this->log('删除用户' . $ucode . '失败!');
|
||||
error('删除失败', - 1);
|
||||
}
|
||||
}
|
||||
|
||||
// 用户修改
|
||||
public function mod()
|
||||
{
|
||||
if (! $ucode = get('ucode', 'var')) {
|
||||
error('传递的参数值错误!', - 1);
|
||||
}
|
||||
|
||||
if ($ucode == '10001') {
|
||||
error('内置管理员不允许此操作!', - 1);
|
||||
}
|
||||
|
||||
// 单独修改状态
|
||||
if (($field = get('field', 'var')) && ! is_null($value = get('value', 'var'))) {
|
||||
if ($this->model->modUser($ucode, "$field='$value',update_user='" . session('username') . "'")) {
|
||||
location(- 1);
|
||||
} else {
|
||||
alert_back('修改失败!');
|
||||
}
|
||||
}
|
||||
|
||||
// 修改操作
|
||||
if ($_POST) {
|
||||
// 获取数据
|
||||
$username = post('username');
|
||||
$realname = post('realname');
|
||||
$password = post('password');
|
||||
$rpassword = post('rpassword');
|
||||
$status = post('status', 'int');
|
||||
$roles = post('roles', 'array', true, '用户角色', array()); // 用户角色
|
||||
|
||||
if (! $username) {
|
||||
alert_back('用户名不能为空!');
|
||||
}
|
||||
if (! $realname) {
|
||||
alert_back('真实名字不能为空!');
|
||||
}
|
||||
|
||||
if (! preg_match('/^[\x{4e00}-\x{9fa5}\w\-\.@]+$/u', $username)) {
|
||||
alert_back('用户名含有不允许的特殊字符!');
|
||||
}
|
||||
|
||||
// 检查用户名重复
|
||||
if ($this->model->checkUser("username='$username' AND ucode<>'$ucode'")) {
|
||||
alert_back('该用户名已经存在,不能再使用!');
|
||||
}
|
||||
|
||||
// 构建数据
|
||||
$data = array(
|
||||
'username' => $username,
|
||||
'realname' => $realname,
|
||||
'status' => $status,
|
||||
'update_user' => session('username')
|
||||
);
|
||||
|
||||
if ($password) {
|
||||
if (! $rpassword) {
|
||||
alert_back('确认密码不能为空!');
|
||||
}
|
||||
if ($password != $rpassword) {
|
||||
alert_back('确认密码不正确!');
|
||||
}
|
||||
$data['password'] = encrypt_string($password);
|
||||
}
|
||||
|
||||
// 执行添加
|
||||
if ($this->model->modUser($ucode, $data, $roles)) {
|
||||
$this->log('修改用户' . $ucode . '成功!');
|
||||
if (! ! $backurl = get('backurl')) {
|
||||
success('修改成功!', base64_decode($backurl));
|
||||
} else {
|
||||
success('修改成功!', url('/admin/User/index'));
|
||||
}
|
||||
} else {
|
||||
location(- 1);
|
||||
}
|
||||
} else { // 调取修改内容
|
||||
$this->assign('mod', true);
|
||||
|
||||
$result = $this->model->getUser($ucode);
|
||||
if (! $result) {
|
||||
error('编辑的内容已经不存在!', - 1);
|
||||
}
|
||||
$this->assign('user', $result);
|
||||
|
||||
// 角色列表
|
||||
$role_model = model('admin.system.Role');
|
||||
$this->assign('roles', $role_model->getSelect());
|
||||
$this->display('system/user.html');
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user