/** * 添加/编辑内容 */ public function action() { $field = \Model\Field::fieldList($this->model['model_id'], '1'); $id = $this->g('id'); if (empty($id)) { $this->assign('method', 'POST'); $this->assign('title', "{$GLOBALS['_LANG']['CONTENT']['ADD']} - {$this->model['lang_key']}"); } else { $content = \Model\Content::findContent($this->table, $id, "{$this->fieldPrefix}id"); if (empty($content)) { $this->error($GLOBALS['_LANG']['CONTENT']['NOT_EXIST_CONTENT']); } $this->assign($content); $this->assign('method', 'PUT'); $this->assign('id', $id); $this->assign('title', "{$GLOBALS['_LANG']['CONTENT']['EDIT']} - {$this->model['lang_key']}"); foreach ($field as $key => $value) { $field[$key] = $value; $field[$key]['value'] = $content["{$this->fieldPrefix}{$value['field_name']}"]; } } $this->assign('field', $field); $this->assign('form', new \Expand\Form\Form()); $this->layout(is_file(THEME . '/' . GROUP . "/{$this->theme['value']}/" . MODULE . "_action.php") ? MODULE . "_action" : 'Content_action'); }
/** * 添加/编辑内容 */ public function action() { $field = \Model\Field::fieldList($this->model['model_id'], array('field_status' => '1')); $id = $this->g('id'); if (empty($id)) { $this->assign('method', 'POST'); $this->assign('title', "添加 - {$this->model['lang_key']}"); } else { $content = \Model\Content::findContent($this->table, $id, "{$this->fieldPrefix}id"); if (empty($content)) { $this->error('不存在的内容'); } $this->assign($content); $this->assign('method', 'PUT'); $this->assign('id', $id); $this->assign('title', "编辑 - {$this->model['lang_key']}"); foreach ($field as $key => $value) { $field[$key] = $value; $field[$key]['value'] = $content["{$this->fieldPrefix}{$value['field_name']}"]; } } $this->assign('field', $field); $this->assign('form', new \Expand\Form\Form()); $this->display(is_file(THEME . '/' . GROUP . "/{$this->theme}/" . MODULE . '/' . MODULE . "_action.php") ? MODULE . "_action" : 'Content_action'); }
/** * 更新路由规则 * @description 在非操作路由规则新增/更新,程序将仅判断文件是否存在,不存在则创建。反之则更新路由规则 */ public function after() { //路由规则文件 $routeFileName = md5(\Core\Func\CoreFunc::loadConfig('PRIVATE_KEY')) . '_route.php'; $routePath = PES_PATH . "/Config/Route/{$routeFileName}"; $routeUrl = PES_PATH . "/Config/RouteUrl/{$routeFileName}"; //检查路由规则文件是否存在。文件不存在则创建。只有在路由规则编辑中才会触发更新 if (is_file($routeUrl) && is_file($routeUrl) && (GROUP != self::MATCH_GROUP || MODULE != 'Route' || ACTION != 'action')) { return true; } $route = \Model\Content::listContent(['table' => 'route', 'condition' => 'route_status = 1', 'order' => 'route_listsort ASC, route_id DESC']); if (empty($route)) { unlink($routePath); unlink($routeUrl); } else { $routeStr['route'] = $routeStr['url'] = "<?php\r\n return array(\r\n"; foreach ($route as $key => $value) { $routeStr['route'] .= " '{$value['route_rule']}' => '{$value['route_controller']}', \r\n"; $routeStr['url'] .= " '{$value['route_hash']}' => '{$value['route_rule']}', \r\n"; } $routeStr['route'] .= ");\r\n"; $routeStr['url'] .= ");\r\n"; //写入自定义路由规则 $routeFopen = fopen($routePath, 'w+'); fwrite($routeFopen, $routeStr['route']); fclose($routeFopen); //写入\Core\Func\Core::url()方法使用的匹配路由规则 $urlFopen = fopen($routeUrl, 'w+'); fwrite($urlFopen, $routeStr['url']); fclose($urlFopen); } }
/** * 生成后台菜单 */ public static function menu($groupId = '') { $condition = ""; if (!empty($groupId) && $_SESSION['admin']['user_id'] > '1') { $group = \Model\Content::findContent('user_group', $groupId, 'user_group_id'); $condition .= "m.menu_id in ({$group['user_group_menu']})"; } $result = self::db('menu AS m')->field("m.*, IF(parent.top_id IS NULL, m.menu_id, parent.top_id) AS top_id, IF(parent.top_listsort IS NULL, '0', parent.top_listsort) AS top_listsort, IF(parent.top_name IS NULL, m.menu_name, top_name) AS top_name, menu_icon")->join("(SELECT `menu_id` AS top_id, `menu_name` AS top_name, `menu_pid` AS top_pid, `menu_listsort` AS top_listsort FROM `" . self::$modelPrefix . "menu` where menu_pid = 0) AS parent ON parent.top_id = m.menu_pid")->where($condition)->order('top_listsort ASC, m.menu_listsort ASC, m.menu_id DESC')->select(); foreach ($result as $key => $value) { if ($value['menu_pid'] == 0) { $menu[$value['top_name']]['menu_id'] = $value['top_id']; $menu[$value['top_name']]['menu_name'] = $value['top_name']; $menu[$value['top_name']]['menu_link'] = $value['menu_link']; $menu[$value['top_name']]['menu_icon'] = $value['menu_icon']; $menu[$value['top_name']]['menu_listsort'] = $value['menu_listsort']; $menu[$value['top_name']]['menu_type'] = $value['menu_type']; } } foreach ($result as $key => $value) { if (!empty($menu[$value['top_name']]) && $value['menu_pid'] != 0) { $menu[$value['top_name']]['menu_child'][] = $value; } } return $menu; }
/** * 添加/编辑内容 */ public function action() { $id = $this->g('id'); if (empty($id)) { $this->assign('method', 'POST'); $this->assign('title', "添加 - {$this->model['model_title']}"); } else { $content = \Model\Content::findContent($this->table, $id, "{$this->fieldPrefix}id"); if (empty($content)) { $this->error('不存在的内容'); } $this->assign($content); $this->assign('method', 'PUT'); $this->assign('id', $id); $this->assign('title', "编辑 - {$this->model['model_title']}"); foreach ($this->field as $key => $value) { $this->field[$key] = $value; $this->field[$key]['field_option'] = $value['field_option']; $this->field[$key]['value'] = $content["{$this->fieldPrefix}{$value['field_name']}"]; } } $this->assign('field', $this->field); $this->assign('form', new \Expand\Form\Form()); $this->layout(is_file("{$this->modelThemePrefixPath}_action.php") ? MODULE . "_action" : 'Content_action'); }
/** * 添加/编辑分类 */ public function action() { $categoryId = $this->g('id'); if (empty($categoryId)) { $this->assign('method', 'POST'); if ($parent = $this->g('parent')) { $this->assign('category_parent', $parent); $this->assign('title', '添加子分类'); } else { $this->assign('title', '添加分类'); } $tree = \Model\Category::getSelectCate(array($parent)); } else { $category = \Model\Category::listCategory($categoryId); if (empty($category)) { $this->error('分类不存在'); } $tree = \Model\Category::getSelectCate(array($category['category_parent'])); $this->assign('method', 'PUT'); $this->assign($category); $this->assign('title', '编辑分类'); } $this->assign('model', \Model\Content::listContent(['table' => 'model', 'condition' => 'model_attr = 1'])); $this->assign('tree', $tree); $this->layout(); }
/** * 更新模型字段中,绑定了用户组ID的字段选项 */ public function after() { $userGroupList = \Model\Content::listContent(['table' => 'user_group']); $userGroup = []; foreach ($userGroupList as $value) { $userGroup[$value['user_group_name']] = $value['user_group_id']; } $this->db('field')->where('field_name = :field_name')->update(['field_option' => json_encode($userGroup), 'noset' => ['field_name' => 'group_id']]); }
/** * 获取系统更新信息 * @return boolean 返回抓去结果 */ public static function getUpdate() { $version = \Model\Option::findOption('version')['value']; $findUpdate = \Model\Content::findContent('update_list', $version, 'update_list_pre_version'); if (empty($findUpdate)) { $update = \Model\Extra::getUpdate($version); return $update['status']; } }
/** * 更新系统 */ public function upgrade() { \Model\Option::getUpdate(); $version = \Model\Option::findOption('version')['value']; $content = \Model\Content::findContent('update_list', $version, 'update_list_pre_version'); $this->assign($content); $this->assign('title', \Model\Menu::getTitleWithMenu()); $this->layout(); }
public function action($jump = TRUE, $commit = TRUE) { if ($_POST['parent'] == '0') { $_POST['value'] = (string) ucfirst(strtolower($_POST['value'])); } else { $controller = \Model\Content::findContent('node', $_POST['parent'], 'node_id'); $_POST['check_value'] = GROUP . $_POST['method_type'] . $controller['node_value'] . $_POST['value']; } parent::action(); }
/** * 部门添加/编辑 */ public function action() { $userList = \Model\Content::listContent('user'); $this->assign('user', $userList); foreach ($userList as $key => $value) { $findUser[$value['user_id']] = $value['user_name']; } $this->assign('findUser', $findUser); parent::action(); }
public function before() { if (in_array(METHOD, ['POST', 'PUT'])) { if ($_POST['controller'] == '0' || $_POST['controller'] == '-1') { $_POST['value'] = (string) ucfirst(strtolower($_POST['value'])); } else { $controller = \Model\Content::findContent('node', $_POST['controller'], 'node_id'); $_POST['check_value'] = GROUP . $_POST['method_type'] . $controller['node_value'] . $_POST['value']; } } }
/** * 流程处理 * * @return boolean * @throws \Lib\Exception */ public function process() { if ($this->_state === false) { if (\Lib\Params::getInstance()->showHelp() === true) { $this->getHelp(); } return false; } $db = $this->getDbResponse(); $op = \Lib\Options::getInstance(); if (empty($this->_dbname)) { \Lib\State::error('The database is not specified'); } \Lib\State::notice('Scanning the database table...'); $tables = $op->getTable(); if (empty($tables)) { $tables = $db->findTables(); } else { foreach ($tables as $table) { if ($db->isExistTable($table) === false) { \Lib\State::warning('Unkown table \'' . $table . '\''); } } } if (empty($tables)) { \Lib\State::warning('Not found any tables'); } \Lib\State::notice('Found ' . sizeof($tables) . ' table(s)'); $modelFile = \Model\File::getInstance(); $modelContents = \Model\Content::getInstance(); $replaceArr = $op->getReplace() ?: []; foreach ($tables as $table) { $tableName = \Lib\Func::uc($table); $className = $tableName; if (!empty($replaceArr['source']) && !empty($replaceArr['target'])) { $className = str_ireplace($replaceArr['source'], ucfirst($replaceArr['target']), $className); } if (preg_match('/^[0-9]+/', $tableName)) { $tableName = ltrim(preg_replace('/^[0-9]+/', '', $tableName), '_'); } \Lib\State::notice('-----------------'); \Lib\State::notice('Processing [' . $table . ']'); $modelContents->setTableInfo($db->findTableInfo($table)); $modelContents->setClassName($className); $modelContents->setTableName($tableName); $modelContents->setColumns($db->findCols($table)); $modelContents->build(); \Lib\State::notice('Done'); $modelFile->setFileName($className)->build(); $modelContents->reset(); $modelFile->reset(); } return true; }
public function before() { if (METHOD == 'POST') { $this->isP('password', '请填写密码'); } if (empty($_POST['password'])) { $_POST['password'] = \Model\Content::findContent('user', $_POST['id'], 'user_id')['user_password']; } else { $_POST['password'] = (string) \Core\Func\CoreFunc::generatePwd($this->p('password')); } }
/** * 查找当前的分类ID */ private function getCurrentCatid() { $this->catid = (int) $_GET['id']; if (MODULE != 'Page' && ACTION == 'view') { $model = strtolower(MODULE); $checkModel = \Model\ModelManage::findModel($model, 'model_name'); if (!empty($checkModel)) { $content = \Model\Content::findContent($model, $this->catid, "{$model}_id"); $this->catid = $content["{$model}_catid"]; } } $this->assign('catid', $this->catid); }
/** * 删除文档指定内容 */ public function deleteContent() { $id = $this->isG('id', '请选择您要删除的文档内容'); $check = \Model\Content::findContent('doc_content', $id, 'doc_content_id'); if (empty($check)) { $this->error('不存在的文档内容'); } $resul = $this->db('doc_content')->where('doc_content_id = :doc_content_id')->update(array('doc_content_delete' => '1', 'noset' => array('doc_content_id' => $id))); if ($resul === false) { $this->error('删除失败'); } $this->success('删除文档内容成功'); }
public function before() { if ($_SESSION['admin']['user_id'] == '1') { return true; } $findNode = \Model\Content::findContent('node', GROUP . METHOD . MODULE . ACTION, 'node_check_value'); if (empty($findNode)) { return true; } $list = \Model\Content::listContent(['table' => 'node_group', 'condition' => 'user_group_id = :user_group_id AND node_id = :node_id', 'param' => ['user_group_id' => $_SESSION['ticket']['user_group_id'], 'node_id' => $findNode['node_id']]]); if (empty($list)) { $this->error(empty($findNode['node_msg']) ? '您的权限不足' : $findNode['node_msg']); } }
public function dologin() { $mark = $this->isG('mark', '非法请求'); $check = \Model\Content::findContent('dologin', $mark, 'dologin_mark'); if (empty($check)) { $this->error('不存在的记录'); } if ($check['dologin_createtime'] <= time() - 30 && $check['dologin_status'] == '0') { $this->error('登录超时,请重新运行软件'); } $this->db('dologin')->where('dologin_id = :dologin_id')->update(array('dologin_status' => '1', 'noset' => array('dologin_id' => $check['dologin_id']))); $_SESSION['admin'] = json_decode($check['dologin_session'], true); $this->success('登录成功!', $this->url(GROUP . '-Index-index')); }
/** * 提取报表 */ public function extract() { $head = explode(',', \Model\Content::findContent('department', $_SESSION['team']['user_department_id'], 'department_id')['department_header']); if (!in_array($_SESSION['team']['user_id'], $head) && ACTION == 'extract') { $this->error('您不是部门负责人,无权访问'); } $condition = "r.report_date BETWEEN :begin AND :end "; $param = array(); //allExtract将移除此限制 if (ACTION == 'extract') { $condition .= " AND r.department_id = :department_id"; $param['department_id'] = $_SESSION['team']['user_department_id']; } if (!empty($_GET['begin']) && !empty($_GET['end'])) { $param['begin'] = $_GET['begin']; $param['end'] = $_GET['end']; } else { $param['begin'] = date('Y-m-d'); $param['end'] = date('Y-m-d'); } if (!empty($_GET['user'])) { $condition .= " AND r.user_id = :user_id"; $param['user_id'] = $this->g('user'); } $result = $this->db('report AS r ')->join("{$this->prefix}report_content AS rc ON rc.report_id = r.report_id")->where($condition)->order('report_date DESC')->select($param); //是否导出excel if (!empty($_GET['excel'])) { $label = new \Expand\Label(); $excelTitle = array('日期/用户', '报表内容'); foreach ($result as $key => $value) { $list[$value['report_date']][$value['report_date']] = $value['report_date']; $list[$value['report_date'] . $value['user_id']][$value['user_id']] = $label->findUser('user', 'user_id', $value['user_id'])['user_name']; $list[$value['report_date'] . $value['user_id']][] = strip_tags(htmlspecialchars_decode($value['report_content'])); } $excel = new \Expand\Excel\Excel(); $excel->export(date('YmdHis') . '提取报表', $excelTitle, $list); } else { foreach ($result as $key => $value) { $list[$value['report_date']][$value['user_id']][] = $value; } } $this->assign('list', $list); $userList = \Model\Content::listContent('user'); $this->assign('user', $userList); $this->assign('begin', $param['begin']); $this->assign('end', $param['end']); $this->assign('title', '提取报表'); $this->layout('Report_extract'); }
/** * 更新用户 */ public function action($jump = TRUE, $commit = TRUE) { $user = \Model\Content::findContent('user', (int) $_POST['id'], 'user_id'); if (empty($user)) { $this->error('不存在的用户'); } if ($this->p('password')) { $password = $this->p('password'); if ($password != $this->p('confirm_password')) { $this->error('两次输入的密码不一致'); } $_POST['password'] = (string) \Core\Func\CoreFunc::generatePwd($this->isP('account', '请提交帐号') . $password, 'PRIVATE_KEY'); } parent::action(); }
/** * 设置权限 */ public function setAuth() { $id = $this->isG('id', '请提交用户组'); $record = []; $recordList = \Model\Content::listContent(['table' => 'node_group', 'condition' => 'user_group_id = :user_group_id', 'param' => ['user_group_id' => $id]]); if (!empty($recordList)) { foreach ($recordList as $value) { $record[] = $value['node_id']; } } $this->assign('record', json_encode($record)); $this->assign('list', \Model\Node::nodeList()); $this->assign('prefix', 'node_'); $this->display('User_group_setting'); }
/** * 更新节点模型字段中,父类的字段选项值 */ public function after() { $nodeList = \Model\Content::listContent(['table' => 'node', 'order' => 'node_listsort ASC, node_id DESC']); $parent = ['请选择' => '', '顶层菜单' => '0']; $controller = ['请选择' => '', '顶层节点' => '0', '非权限节点' => '-1']; foreach ($nodeList as $value) { if ($value['node_parent'] == '0') { $parent[$value['node_name']] = $value['node_id']; } if ($value['node_controller'] == '0') { $controller[$value['node_name']] = $value['node_id']; } } $this->db('field')->where(' field_model_id = 13 AND field_name = :parent')->update(['field_option' => json_encode($parent), 'noset' => ['parent' => 'parent']]); $this->db('field')->where(' field_model_id = 13 AND field_name = :controller')->update(['field_option' => json_encode($controller), 'noset' => ['controller' => 'controller']]); }
/** * 更新内容 * @param type $jump 是否跳转.当继承本类时,若不跳转,提交false * @param type $commit 是否提交事务.默认提交.若想继承者继续在本事务中操作,请提交false */ public function action($jump = TRUE, $commit = TRUE) { $this->db()->transaction(); $updateResult = \Model\Content::updateContent(); if (!empty($_POST['back_url'])) { $url = base64_decode($_POST['back_url']); } else { $url = $this->url(GROUP . '-' . MODULE . '-index'); } if ($commit === TRUE) { $this->db()->commit(); } if ($jump === TRUE) { $this->success('更新内容成功', $url); } }
/** * 添加内容 */ public function action() { $this->db()->transaction(); $addResult = \Model\Content::addContent(); if ($addResult['status'] == false) { $this->db()->rollBack(); $this->error($addResult['mes']); } $this->db()->commit(); if (!empty($_POST['back_url'])) { $url = $_POST['back_url']; } else { $url = $this->url('Team-' . MODULE . '-index'); } $this->success($GLOBALS['_LANG']['CONTENT']['ADD_CONTENT_SUCCESS'], $url); }
/** * 更新内容 * @param type $jump 是否跳转.当继承本类时,若不跳转,提交false * @param type $commit 是否提交事务.默认提交.若想继承者继续在本事务中操作,请提交false */ public function action($jump = TRUE, $commit = TRUE) { $this->db()->transaction(); $updateResult = \Model\Content::updateContent(); if (!empty($_POST['back_url'])) { $url = $_POST['back_url']; } else { $url = '/d/manage'; } if ($commit === TRUE) { $this->db()->commit(); } if ($jump === TRUE) { $this->success('更新内容成功', $url); } }
/** * 设置节点 */ public function setNode() { $id = $this->isG('id', '请选择用户组'); $group = \Model\Content::findContent('user_group', $id, 'user_group_id'); if (empty($group)) { $this->error('用户组不存在'); } $nodeList = $this->db('node_group')->where('user_group_id = :user_group_id')->select(array('user_group_id' => $id)); foreach ($nodeList as $key => $value) { $groupNode[] = $value['node_id']; } $this->assign('groupNode', $groupNode); $this->assign($group); $this->assign('node', \Model\Node::nodeList()); $this->assign('title', "设置'{$group['user_group_name']}'用户组权限节点"); $this->layout(); }
/** * 验证用户节点 * @todo 若没有添加节点,是否需要严重权限呢? * 应该在设置中添加一个选项,开启严格的权限检测和欢送检测。 */ protected function checkNode() { //登录,上传,下载文件为权限验证特例。以后看需要再更改吧 if (in_array(MODULE, array('Login', 'Upload', 'SaveFile'))) { return true; } $findNode = \Model\Content::findContent('node', GROUP . METHOD . MODULE . ACTION, 'node_check_value'); $nodeType = \Model\Content::findContent('option', 'node_type', 'option_name'); //没加节点,则表示不验证权限 if (empty($findNode) && $nodeType['value'] == '0') { return true; } $checkNode = $this->db('node_group')->where('user_group_id = :user_group_id AND node_id = :node_id')->find(array('user_group_id' => $_SESSION['team']['user_group_id'], 'node_id' => $findNode['node_id'])); if (empty($checkNode)) { $this->error(empty($findNode['node_msg']) ? '您的权限不足' : $findNode['node_msg']); } }
public function setNode() { $id = $this->isP('id', '请选择用户组'); if (empty($_POST['node'])) { $this->error('请选择该用户组的权限节点'); } $group = \Model\Content::findContent('user_group', $id, 'user_group_id'); if (empty($group)) { $this->error('用户组不存在'); } //移除所有节点 $this->db('node_group')->where('user_group_id = :user_group_id')->delete(array('user_group_id' => $id)); foreach ($_POST['node'] as $key => $value) { $this->db('node_group')->insert(array('user_group_id' => $id, 'node_id' => $value)); } $this->success('设置用户组权限节点成功!', $this->url('Team-User_group-index')); }
/** * 添加新内容 */ public function addContent() { $id = $this->isG('id', '丢失日志'); $content = $this->isP('content', '请填写内容'); $checkDoc = $this->db('doc')->where("doc_id = :doc_id AND doc_delete = '0'")->find(array('doc_id' => $id)); $checkTree = \Model\Content::findContent('tree', $checkDoc['doc_tree_id'], 'tree_id'); $this->db()->transaction(); $time = time(); $updateTime = $this->db()->query("UPDATE {$this->prefix}doc SET doc_updatetime = '{$time}' WHERE doc_id = :doc_id ", array('doc_id' => $id)); if ($updateTime === FALSE) { $this->db()->rollBack(); $this->error('更新时间出错'); } \Model\Doc\Doc::addContent(array('doc_id' => $id, 'user_id' => $_SESSION['user']['user_id'], 'doc_content' => $content, 'doc_content_createtime' => $time)); $this->db()->commit(); $this->success('添加内容成功!', $this->url("/d/v/{$checkTree['tree_parent']}/{$id}", true)); }
public function index() { $id = $this->isG('id', '请选择要下载的文件'); $model = strtolower($this->isG('model', '请选择下载的模块')); //要下载文件的字段,缺省值为file $field = empty($_GET['field']) ? "{$model}_file" : $model . "_" . $this->g('field'); /** * 多个文件下载的判断,如果存放文件的字段有多个文件存在时 * 则根据提交过来的num参数,进行获取文件。 * 由于拆分的文件,数组键值是从0开始的。所以需要减1 */ $num = $this->isG('num', '请选择要下载的文件序号'); $res = \Model\Content::findContent($model, $id, "{$model}_id"); if (empty($res)) { echo '<script>alert("文件已丢失或者地址不正确")</script>'; exit; } $arrayFile = explode(',', $res[$field]); //确保下载的文件次序在范围内。 if ($num > count($arrayFile)) { echo '<script>alert("文件已丢失或者地址不正确")</script>'; exit; } $file = PES_PATH . $arrayFile[$num]; $path_parts = pathinfo($file); \Core\Func\CoreFunc::$defaultPath = false; if (class_exists('\\finfo')) { $finfo = new \finfo(FILEINFO_MIME); $array = explode(';', $finfo->file($file)); $mimetypes = $array[0]; } elseif (function_exists('mime_content_type')) { $mimetypes = mime_content_type($file); } else { $mimetypes = $this->mimetypes[$path_parts['extension']]; if (empty($mimetypes)) { echo '<script>alert("系统无法获知文件类型")</script>'; exit; } } $name = empty($res["{$model}_title"]) ? '附件' : $res["{$model}_title"]; header("Content-type: {$mimetypes}"); header('Content-Disposition: attachment; filename="' . $name . "_{$num}" . '.' . $path_parts['extension'] . '"'); readfile($file); exit; }