diff --git a/Application/Admin/Builder/AdminConfigBuilder.class.php b/Application/Admin/Builder/AdminConfigBuilder.class.php index e44edcb549b41774c6ceb32db3d434a34d1b134d..68069369ad0258500948a60c8b5601423bedd8c7 100644 --- a/Application/Admin/Builder/AdminConfigBuilder.class.php +++ b/Application/Admin/Builder/AdminConfigBuilder.class.php @@ -71,6 +71,39 @@ class AdminConfigBuilder extends AdminBuilder { return $this->key($name, $title, $subtitle, 'hidden'); } + + /** + + * 级联选择组件 + + * @param string $name 字段名 + + * @param string $title 字段标题 + + * @param string $subtitle 字段子标题 + + * @param string $options 首个下拉框选项数组 + + * @param string $url ajax查询网址 + + * @param array $selects select标签信息(array('select标签id属性值'=>'option选中项的值')) + + * @return AdminConfigBuilder + + * @author swh + + */ + public function keyRelationSelect($name, $title, $subtitle = null, $options, $url = null, $selects = array()) { + if (empty($selects)) { + list($url, $selects) = explode('#', $url, 2); + parse_str($selects, $selects); + } + return $this->key($name, $title, $subtitle, 'relationSelect', array( + 'opt' => $options, + 'url' => $url, + 'selects' => $selects, + )); + } /**只读文本 * @param $name @@ -141,7 +174,7 @@ class AdminConfigBuilder extends AdminBuilder public function keySelect($name, $title, $subtitle = null, $options) { - return $this->key($name, $title, $subtitle, 'select', $options); + return $this->key($name, $title, $subtitle, 'select', $options ); } public function keyRadio($name, $title, $subtitle = null, $options) diff --git a/Application/Admin/Builder/AdminListBuilder.class.php b/Application/Admin/Builder/AdminListBuilder.class.php index a9e02eb9d40c15ff38e82b2693e83dcd7c11128c..3f076820c45e6e963b49afa2f941385c9c3681f6 100644 --- a/Application/Admin/Builder/AdminListBuilder.class.php +++ b/Application/Admin/Builder/AdminListBuilder.class.php @@ -1,875 +1,850 @@ -_title = $title; - $this->meta_title = $title; - return $this; - } - - /** - * suggest 页面标题边上的提示信息 - * @param $suggest - * @return $this - * @author:xjw129xjt(肖骏涛) xjt@ourstu.com - */ - public function suggest($suggest) - { - $this->_suggest = $suggest; - return $this; - } - - /** - * @param $url string 已被U函数解析的地址 - * @return $this - */ - public function setStatusUrl($url) - { - $this->_setStatusUrl = $url; - return $this; - } - - /**设置回收站根据ids彻底删除的URL - * @param $url - * @return $this - * @author 郑钟良 - */ - public function setDeleteTrueUrl($url) - { - $this->_setDeleteTrueUrl = $url; - return $this; - } - - /** - * 筛选下拉选择url - * @param $url string 已被U函数解析的地址 - * @return $this - * @author 郑钟良 - */ - public function setSelectPostUrl($url) - { - $this->_selectPostUrl = $url; - return $this; - } - - /**设置搜索提交表单的URL - * @param $url - * @return $this - * @auth 陈一枭 - */ - /**原@auth 陈一枭 - *public function setSearchPostUrl($url) - *{ - * $this->_searchPostUrl = $url; - * return $this; - *} - */ - /**更新筛选搜索功能 ,修正连续提交多出N+个GET参数的BUG - * @param $url 提交的getURL - */ - public function setSearchPostUrl($url) - { - $this->_searchPostUrl = $url; - return $this; - } - - /**加入一个按钮 - * @param $title - * @param $attr - * @return $this - * @auth 陈一枭 - */ - - public function button($title, $attr) - { - $this->_buttonList[] = array('title' => $title, 'attr' => $attr); - return $this; - } - - /**加入新增按钮 - * @param $href - * @param string $title - * @param array $attr - * @return AdminListBuilder - * @auth 陈一枭 - */ - public function buttonNew($href, $title = '新增', $attr = array()) - { - $attr['href'] = $href; - $attr['class']='btn btn-ajax btn-success'; - return $this->button($title, $attr); - } - - public function ajaxButton($url, $params, $title, $attr = array()) - { - $attr['class'] = 'btn ajax-post'; - $attr['url'] = $this->addUrlParam($url, $params); - $attr['target-form'] = 'ids'; - return $this->button($title, $attr); - } - - /**加入模态弹窗按钮 - * @param $url - * @param $params - * @param $title - * @param array $attr - * @return $this - * @author 郑钟良 - */ - public function buttonModalPopup($url, $params, $title, $attr = array()) - { - //$attr中可选参数,data-title:模态框标题,target-form:要传输的数据 - $attr['modal-url'] = $this->addUrlParam($url, $params); - $attr['data-role'] = 'modal_popup'; - return $this->button($title, $attr); - } - - public function buttonSetStatus($url, $status, $title, $attr) - { - - $attr['class'] = isset($attr['class']) ? $attr['class'] : 'btn ajax-post'; - $attr['url'] = $this->addUrlParam($url, array('status' => $status)); - $attr['target-form'] = 'ids'; - return $this->button($title, $attr); - - } - - public function buttonDisable($url = null, $title = '禁用', $attr = array()) - { - if (!$url) $url = $this->_setStatusUrl; - $attr['class']='btn ajax-post btn-warning'; - return $this->buttonSetStatus($url, 0, $title, $attr); - } - - public function buttonEnable($url = null, $title = '启用', $attr = array()) - { - if (!$url) $url = $this->_setStatusUrl; - $attr['class']='btn ajax-post btn-info'; - return $this->buttonSetStatus($url, 1, $title, $attr); - } - /** - * 删除到回收站 - */ - public function buttonDelete($url = null, $title = '删除', $attr = array()) - { - if (!$url) $url = $this->_setStatusUrl; - $attr['class']='btn ajax-post btn-danger'; - return $this->buttonSetStatus($url, -1, $title, $attr); - } - - public function buttonRestore($url = null, $title = '还原', $attr = array()) - { - if (!$url) $url = $this->_setStatusUrl; - return $this->buttonSetStatus($url, 1, $title, $attr); - } - - /**清空回收站 - * @param null $model - * @return $this - * @author 陈一枭 - */ - public function buttonClear($model = null) - { - return $this->button(L('_CLEAR_OUT_'), array('class' => 'btn ajax-post tox-confirm', 'data-confirm' => L('_CONFIRM_CLEAR_OUT_'), 'url' => U('', array('model' => $model)), 'target-form' => 'ids', 'hide-data' => 'true')); - } - - /**彻底删除 - * @param null $url - * @return $this - * @author 郑钟良 - */ - public function buttonDeleteTrue($url = null) - { - if (!$url) $url = $this->_setDeleteTrueUrl; - $attr['class'] = 'btn ajax-post tox-confirm'; - $attr['data-confirm'] = L('_CONFIRM_DELETE_COMPLETELY_'); - $attr['url'] = $url; - $attr['target-form'] = 'ids'; - return $this->button(L('_DELETE_COMPLETELY_'), $attr); - } - - public function buttonSort($href, $title = '排序', $attr = array()) - { - $attr['href'] = $href; - return $this->button($title, $attr); - } - - /**搜索 - * @param string $title 标题 - * @param string $name 键名 - * @param string $type 类型,默认文本 - * @param string $des 描述 - * @param $attr 标签文本 - * @return $this - * @auth 陈一枭 - */ - /**原@auth 陈一枭 - * public function search($title = '搜索', $name = 'key', $type = 'text', $des = '', $attr ) - * { - * $this->_search[] = array('title' => $title, 'name' => $name, 'type' => $type, 'des' => $des, 'attr' => $attr); - * return $this; - * } - */ - - /**更新筛选搜索功能 ,修正连续提交多出N+个GET参数的BUG - * @param string $title 标题 - * @param string $name 键名 - * @param string $type 类型,默认文本 - * @param string $des 描述 - * @param $attr 标签文本 - * @param string $arrdb 择筛选项数据来源 - * @param string $arrvalue 筛选数据(包含ID 和value的数组:array(array('id'=>1,'value'=>'系统'),array('id'=>2,'value'=>'项目'),array('id'=>3,'value'=>'机构'));) - * @return $this - * @auth MingYang - */ - public function search($title = '搜索', $name = 'key', $type = 'text', $des = '', $attr, $arrdb = '', $arrvalue = null) - { - - if (empty($type) && $type = 'text') { - $this->_search[] = array('title' => $title, 'name' => $name, 'type' => $type, 'des' => $des, 'attr' => $attr); -// $this->setSearchPostUrl(''); - } else { - if (empty($arrdb)) { - $this->_search[] = array('title' => $title, 'name' => $name, 'type' => $type, 'des' => $des, 'attr' => $attr, 'field' => $field, 'table' => $table, 'arrvalue' => $arrvalue); - $this->setSearchPostUrl(''); - } else { - //TODO:呆完善如果$arrdb存在的就把当前数据表的$name字段的信息全部查询出来供筛选。 - } - } - return $this; - } - - /** - * 添加筛选功能 - * @param string $title 标题 - * @param string $name 键名 - * @param string $type 类型,默认文本 - * @param string $des 描述 - * @param $attr 标签文本 - * @param string $arrdb 择筛选项数据来源 - * @param string $arrvalue 筛选数据(包含ID 和value的数组:array(array('id'=>1,'value'=>'系统'),array('id'=>2,'value'=>'项目'),array('id'=>3,'value'=>'机构'));) - * @return $this - * @author 郑钟良 - */ - public function select($title = '筛选', $name = 'key', $type = 'select', $des = '', $attr, $arrdb = '', $arrvalue = null) - { - - if (empty($arrdb)) { - $this->_select[] = array('title' => $title, 'name' => $name, 'type' => $type, 'des' => $des, 'attr' => $attr, 'arrvalue' => $arrvalue); - } else { - //TODO:呆完善如果$arrdb存在的就把当前数据表的$name字段的信息全部查询出来供筛选。 - } - return $this; - } - public function selectPlateForm($id,$method,$action) - { - $this->_form[]=array('id'=>$id,'method'=>$method,'action'=>$action); - return $this; - } - public function key($name, $title, $type, $opt = null, $width = '150px') - { - $key = array('name' => $name, 'title' => $title, 'type' => $type, 'opt' => $opt, 'width' => $width); - $this->_keyList[] = $key; - return $this; - } - - /**显示纯文本 - * @param $name 键名 - * @param $title 标题 - * @return AdminListBuilder - * @auth 陈一枭 - */ - public function keyText($name, $title) - { - return $this->key($name, text($title), 'text'); - } - - /**显示html - * @param $name 键名 - * @param $title 标题 - * @return AdminListBuilder - * @auth 陈一枭 - */ - public function keyHtml($name, $title, $width = '150px') - { - return $this->key($name, op_h($title), 'html', null, $width); - } - - public function keyMap($name, $title, $map) - { - return $this->key($name, $title, 'map', $map); - } - - public function keyId($name = 'id', $title = 'ID') - { - return $this->keyText($name, $title); - } - - /** - * 图标展示 - * @param string $name - * @param string $title - * @return $this - * @author 郑钟良 - */ - public function keyIcon($name = 'icon', $title = '图标') - { - return $this->key($name, $title, 'icon'); - } - - /** - * @param $name - * @param $title - * @param $getUrl Closure|string - * 可以是函数或U函数解析的字符串。如果是字符串,该函数将附带一个id参数 - * - * @return $this - */ - public function keyLink($name, $title, $getUrl) - { - //如果getUrl是一个字符串,则表示getUrl是一个U函数解析的字符串 - if (is_string($getUrl)) { - $getUrl = $this->createDefaultGetUrlFunction($getUrl); - } - - //修整添加多个空字段时显示不正常的BUG@mingyangliu - if (empty($name)) { - $name = $title; - } - - //添加key - return $this->key($name, $title, 'link', $getUrl); - } - - public function keyStatus($name = 'status', $title = '状态') - { - $map = array(-1 => L('_DELETE_'), 0 => L('_DISABLE_'), 1 => L('_ENABLE_'), 2 => L('_UNAUDITED_')); - return $this->key($name, $title, 'status', $map); - } - - public function keyYesNo($name, $title) - { - $map = array(0 => L('_NO_'), 1 => L('_YES_')); - return $this->keymap($name, $title, $map); - } - - public function keyBool($name, $title) - { - return $this->keyYesNo($name, $title); - } - - public function keyImage($name, $title) - { - return $this->key($name, $title, 'image'); - } - - public function keyTime($name, $title) - { - return $this->key($name, $title, 'time'); - } - - public function keyCreateTime($name = 'create_time', $title = '创建时间') - { - return $this->keyTime($name, $title); - } - - public function keyUpdateTime($name = 'update_time', $title = '更新时间') - { - return $this->keyTime($name, $title); - } - - public function keyUid($name = 'uid', $title = '用户') - { - return $this->key($name, $title, 'uid'); - } - - public function keyNickname($name = 'uid', $title, $subtitle = null) - { - return $this->key($name, $title, $subtitle, 'nickname'); - } - - public function keyTitle($name = 'title', $title = '标题') - { - return $this->keyText($name, $title); - } - - //关联表字段显示+URL连接 - public function keyJoin($name, $title, $mate, $return, $model, $url = '') - { - $map = array('mate' => $mate, 'return' => $return, 'model' => $model, 'url' => $url); - return $this->key($name, $title, 'Join', $map); - } - - /** - * 模态弹窗 - * @param $getUrl - * @param $text - * @param $title - * @param array $attr - * @return $this - * @author 郑钟良 - */ - public function keyDoActionModalPopup($getUrl, $text, $title, $attr = array()) - { - //attr中需要设置data-title,用于设置模态弹窗标题 - $attr['data-role'] = 'modal_popup'; - //获取默认getUrl函数 - if (is_string($getUrl)) { - $getUrl = $this->createDefaultGetUrlFunction($getUrl); - } - //确认已经创建了DOACTIONS字段 - $doActionKey = null; - foreach ($this->_keyList as $key) { - if ($key['name'] === 'DOACTIONS') { - $doActionKey = $key; - break; - } - } - if (!$doActionKey) { - $this->key('DOACTIONS', $title, 'doaction', $attr); - } - - //找出第一个DOACTIONS字段 - $doActionKey = null; - foreach ($this->_keyList as &$key) { - if ($key['name'] == 'DOACTIONS') { - $doActionKey = &$key; - break; - } - } - - //在DOACTIONS中增加action - $doActionKey['opt']['actions'][] = array('text' => $text, 'get_url' => $getUrl, 'opt' => $attr); - return $this; - } - - public function keyDoAction($getUrl, $text, $title = '操作') - { - //获取默认getUrl函数 - if (is_string($getUrl)) { - $getUrl = $this->createDefaultGetUrlFunction($getUrl); - } - - //确认已经创建了DOACTIONS字段 - $doActionKey = null; - foreach ($this->_keyList as $key) { - if ($key['name'] === 'DOACTIONS') { - $doActionKey = $key; - break; - } - } - if (!$doActionKey) { - $this->key('DOACTIONS', $title, 'doaction', array()); - } - - //找出第一个DOACTIONS字段 - $doActionKey = null; - foreach ($this->_keyList as &$key) { - if ($key['name'] == 'DOACTIONS') { - $doActionKey = &$key; - break; - } - } - - //在DOACTIONS中增加action - $doActionKey['opt']['actions'][] = array('text' => $text, 'get_url' => $getUrl); - return $this; - } - - public function keyDoActionEdit($getUrl, $text = '编辑') - { - return $this->keyDoAction($getUrl, $text); - } - - public function keyDoActionRestore($text = '还原') - { - $that = $this; - $setStatusUrl = $this->_setStatusUrl; - $getUrl = function () use ($that, $setStatusUrl) { - return $that->addUrlParam($setStatusUrl, array('status' => 1)); - }; - return $this->keyDoAction($getUrl, $text, array('class' => 'ajax-get')); - } - - public function keyTruncText($name, $title, $length) - { - return $this->key($name, $title, 'trunktext', $length); - } - - /** - * 不要给listRows默认值,因为开发人员很可能忘记填写listRows导致翻页不正确 - * @param $totalCount - * @param $listRows - * @return $this - */ - public function pagination($totalCount, $listRows) - { - $this->_pagination = array('totalCount' => $totalCount, 'listRows' => $listRows); - return $this; - } - - public function data($list) - { - $this->_data = $list; - return $this; - } - - /** - * $solist 判断是否属于选择返回数据的列表页,如果是在列表页->display('admin_solist');@mingyangliu - * */ - public function display($solist = '') - { - //key类型的等价转换 - //map转换成text - $this->convertKey('map', 'text', function ($value, $key) { - return $key['opt'][$value]; - }); - - //uid转换成text - $this->convertKey('uid', 'text', function ($value) { - $value = query_user(array('nickname', 'uid', 'space_url'), $value); - return "[{$value[uid]}]" . $value['nickname'] . ''; - }); - - //nickname转换成text - $this->convertKey('nickname', 'text', function ($value) { - $value = query_user(array('nickname', 'uid', 'space_url'), $value); - return "[{$value[uid]}]" . $value['nickname'] . ''; - }); - - //time转换成text - $this->convertKey('time', 'text', function ($value) { - if ($value != 0) { - return time_format($value); - } else { - return '-'; - } - }); - - //trunctext转换成text - $this->convertKey('trunktext', 'text', function ($value, $key) { - $length = $key['opt']; - return msubstr($value, 0, $length); - }); - - //text转换成html - $this->convertKey('text', 'html', function ($value) { - return $value; - }); - - //link转换为html - $this->convertKey('link', 'html', function ($value, $key, $item) { - $value = htmlspecialchars($value); - $getUrl = $key['opt']; - $url = $getUrl($item); - //允许字段为空,如果字段名为空将标题名填充到A变现里 - if (!$value) { - return "" . $key['title'] . ""; - } else { - return "$value"; - } - }); - - //如果icon为空 - $this->convertKey('icon', 'html', function ($value, $key, $item) { - $value = htmlspecialchars($value); - if ($value == '') { - $html = L('_NONE_'); - } else { - $html = " $value"; - } - return $html; - }); - - //image转换为图片 - - $this->convertKey('image', 'html', function ($value, $key, $item) { - if (intval($value)) {//value是图片id - $value = htmlspecialchars($value); - $sc_src = get_cover($value, 'path'); - - $src = getThumbImageById($value, 80, 80); - $sc_src = $sc_src == '' ? $src : $sc_src; - $html = ""; - } else {//value是图片路径 - $sc_src = $value; - $html = ""; - } - return $html; - }); - - //doaction转换为html - $this->convertKey('doaction', 'html', function ($value, $key, $item) { - $actions = $key['opt']['actions']; - $result = array(); - foreach ($actions as $action) { - $getUrl = $action['get_url']; - $linkText = $action['text']; - $url = $getUrl($item); - if (isset($action['opt'])) { - $content = array(); - foreach ($action['opt'] as $key => $value) { - $value = htmlspecialchars($value); - $content[] = "$key=\"$value\""; - } - $content = implode(' ', $content); - if (isset($action['opt']['data-role']) && $action['opt']['data-role'] == "modal_popup") {//模态弹窗 - $result[] = "$linkText"; - } else { - $result[] = "$linkText"; - } - } else { - $result[] = "$linkText"; - } - } - return implode(' ', $result); - }); - - //Join转换为html - $this->convertKey('Join', 'html', function ($value, $key) { - if ($value != 0) { - $val = get_table_field($value, $key['opt']['mate'], $key['opt']['return'], $key['opt']['model']); - if (!$key['opt']['url']) { - return $val; - } else { - $urld = U($key['opt']['url'], array($key['opt']['return'] => $value)); - return "$val"; - } - } else { - return '-'; - } - }); - - //status转换为html - $setStatusUrl = $this->_setStatusUrl; - $that = &$this; - $this->convertKey('status', 'html', function ($value, $key, $item) use ($setStatusUrl, $that) { - //如果没有设置修改状态的URL,则直接返回文字 - $map = $key['opt']; - $text = $map[$value]; - if (!$setStatusUrl) { - return $text; - } - - //返回带链接的文字 - $switchStatus = $value == 1 ? 0 : 1; - $url = $that->addUrlParam($setStatusUrl, array('status' => $switchStatus, 'ids' => $item['id'])); - return "$text"; - }); - - //如果html为空 - $this->convertKey('html', 'html', function ($value) { - if ($value === '') { - return '' . L('_EMPTY_BRACED_') . ''; - } - return $value; - }); - - - //编译buttonList中的属性 - foreach ($this->_buttonList as &$button) { - $button['tag'] = isset($button['attr']['href']) ? 'a' : 'button'; - $this->addDefaultCssClass($button); - $button['attr'] = $this->compileHtmlAttr($button['attr']); - } - - //生成翻页HTML代码 - C('VAR_PAGE', 'page'); - $pager = new \Think\Page($this->_pagination['totalCount'], $this->_pagination['listRows'], $_REQUEST); - $pager->setConfig('theme', '%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END% %HEADER%'); - $paginationHtml = $pager->show(); - - //显示页面 - $this->assign('title', $this->_title); - $this->assign('suggest', $this->_suggest); - $this->assign('keyList', $this->_keyList); - $this->assign('buttonList', $this->_buttonList); - $this->assign('pagination', $paginationHtml); - $this->assign('list', $this->_data); - /*加入搜索 陈一枭*/ - $this->assign('searches', $this->_search); - $this->assign('searchPostUrl', $this->_searchPostUrl); - - /*加入筛选select 郑钟良*/ - $this->assign('selects', $this->_select); - $this->assign('selectPostUrl', $this->_selectPostUrl); - //如果是选择返回数据的列表页就调用admin_solist模板文件,否则编译原有模板 - if ($solist) { - parent::display('admin_solist'); - } else { - parent::display('admin_list'); - } - } - - public function doSetStatus($model, $ids, $status = 1) - { - $id = array_unique((array)$ids); - $rs = M($model)->where(array('id' => array('in', $id)))->save(array('status' => $status)); - if ($rs === false) { - $this->error(L('_ERROR_SETTING_') . L('_PERIOD_')); - } - $this->success(L('_SUCCESS_SETTING_'), $_SERVER['HTTP_REFERER']); - } - - - private function convertKey($from, $to, $convertFunction) - { - foreach ($this->_keyList as &$key) { - if ($key['type'] == $from) { - $key['type'] = $to; - foreach ($this->_data as &$data) { - $value = &$data[$key['name']]; - $value = $convertFunction($value, $key, $data); - unset($value); - } - unset($data); - } - } - unset($key); - } - - private function addDefaultCssClass(&$button) - { - if (!isset($button['attr']['class'])) { - $button['attr']['class'] = 'btn'; - } else { - $button['attr']['class'] .= ' btn'; - } - } - - /** - * @param $pattern U函数解析的URL字符串,例如 Admin/Test/index?test_id=### - * Admin/Test/index?test_id={other_id} - * ###将被id替换 - * {other_id}将被替换 - * @return callable - */ - private function createDefaultGetUrlFunction($pattern) - { - $explode = explode('|', $pattern); - $pattern = $explode[0]; - $fun = empty($explode[1]) ? 'U' : $explode[1]; - return function ($item) use ($pattern, $fun) { - $pattern = str_replace('###', $item['id'], $pattern); - //调用ThinkPHP中的解析引擎解析变量 - $view = new \Think\View(); - $view->assign($item); - $pattern = $view->fetch('', $pattern); - return $fun($pattern); - }; - } - - public function addUrlParam($url, $params) - { - if (strpos($url, '?') === false) { - $seperator = '?'; - } else { - $seperator = '&'; - } - $params = http_build_query($params); - return $url . $seperator . $params; - } - - /**自动处理清空回收站 - * @param string $model 要清空的模型 - * @auth 陈一枭 - */ - public function clearTrash($model = '') - { - if (IS_POST) { - if ($model != '') { - $aIds = I('post.ids', array()); - if (!empty($aIds)) { - $map['id'] = array('in', $aIds); - } else { - $map['status'] = -1; - } - - $result = D($model)->where($map)->delete(); - if ($result) { - $this->success(L('_SUCCESS_TRASH_CLEARED_', array('result' => $result))); - } - $this->error(L('_TRASH_ALREADY_EMPTY_')); - } else { - $this->error(L('_TRASH_SELECT_')); - } - } - } - - /**执行彻底删除数据,只适用于无关联的数据表 - * @param $model - * @param $ids - * @author 郑钟良 - */ - public function doDeleteTrue($model, $ids) - { - $ids = is_array($ids) ? $ids : explode(',', $ids); - M($model)->where(array('id' => array('in', $ids)))->delete(); - $this->success(L('_SUCCESS_DELETE_COMPLETELY_'), $_SERVER['HTTP_REFERER']); - } - - /** - * keyLinkByFlag 带替换表示的链接 - * @param $name - * @param $title - * @param $getUrl - * @param string $flag - * @return $this - * @author:xjw129xjt xjt@ourstu.com - */ - public function keyLinkByFlag($name, $title, $getUrl, $flag = 'id') - { - - //如果getUrl是一个字符串,则表示getUrl是一个U函数解析的字符串 - if (is_string($getUrl)) { - $getUrl = $this->ParseUrl($getUrl, $flag); - } - - //添加key - return $this->key($name, $title, 'link', $getUrl); - } - - /**解析Url - * @param $pattern URL文本 - * @param $flag - * @return callable - * @auth 陈一枭 - */ - private function ParseUrl($pattern, $flag) - { - return function ($item) use ($pattern, $flag) { - - $pattern = str_replace('###', $item[$flag], $pattern); - //调用ThinkPHP中的解析引擎解析变量 - $view = new \Think\View(); - $view->assign($item); - $pattern = $view->fetch('', $pattern); - return U($pattern); - }; - } - +_title = $title; + $this->meta_title = $title; + return $this; + } + + /** + * suggest 页面标题边上的提示信息 + * @param $suggest + * @return $this + * @author:xjw129xjt(肖骏涛) xjt@ourstu.com + */ + public function suggest($suggest) + { + $this->_suggest = $suggest; + return $this; + } + + /** + * @param $url string 已被U函数解析的地址 + * @return $this + */ + public function setStatusUrl($url) + { + $this->_setStatusUrl = $url; + return $this; + } + + /**设置回收站根据ids彻底删除的URL + * @param $url + * @return $this + * @author 郑钟良 + */ + public function setDeleteTrueUrl($url) + { + $this->_setDeleteTrueUrl = $url; + return $this; + } + + /** + * 筛选下拉选择url + * @param $url string 已被U函数解析的地址 + * @return $this + * @author 郑钟良 + */ + public function setSelectPostUrl($url) + { + $this->_selectPostUrl = $url; + return $this; + } + + + /** + * 更新筛选搜索功能 ,修正连续提交多出N+个GET参数的BUG + * @param $url 提交的getURL + * @param $param GET参数 + * @param $val GET值 + * @return $this + */ + public function setSearchPostUrl($url, $param = null, $val = null) { + $this->_searchPostUrl = $param === null ? U($url) : U($url, array($param => $val)); + return $this; + } + + /**加入一个按钮 + * @param $title + * @param $attr + * @return $this + * @auth 陈一枭 + */ + + public function button($title, $attr) + { + $this->_buttonList[] = array('title' => $title, 'attr' => $attr); + return $this; + } + + /**加入新增按钮 + * @param $href + * @param string $title + * @param array $attr + * @return AdminListBuilder + * @auth 陈一枭 + */ + public function buttonNew($href, $title = '新增', $attr = array()) + { + $attr['href'] = $href; + $attr['class']='btn btn-ajax btn-success'; + return $this->button($title, $attr); + } + + public function ajaxButton($url, $params, $title, $attr = array()) + { + $attr['class'] = 'btn ajax-post'; + $attr['url'] = $this->addUrlParam($url, $params); + $attr['target-form'] = 'ids'; + return $this->button($title, $attr); + } + + /**加入模态弹窗按钮 + * @param $url + * @param $params + * @param $title + * @param array $attr + * @return $this + * @author 郑钟良 + */ + public function buttonModalPopup($url, $params, $title, $attr = array()) + { + //$attr中可选参数,data-title:模态框标题,target-form:要传输的数据 + $attr['modal-url'] = $this->addUrlParam($url, $params); + $attr['data-role'] = 'modal_popup'; + return $this->button($title, $attr); + } + + public function buttonSetStatus($url, $status, $title, $attr) + { + + $attr['class'] = isset($attr['class']) ? $attr['class'] : 'btn ajax-post'; + $attr['url'] = $this->addUrlParam($url, array('status' => $status)); + $attr['target-form'] = 'ids'; + return $this->button($title, $attr); + + } + + public function buttonDisable($url = null, $title = '禁用', $attr = array()) + { + if (!$url) $url = $this->_setStatusUrl; + $attr['class']='btn ajax-post btn-warning'; + return $this->buttonSetStatus($url, 0, $title, $attr); + } + + public function buttonEnable($url = null, $title = '启用', $attr = array()) + { + if (!$url) $url = $this->_setStatusUrl; + $attr['class']='btn ajax-post btn-info'; + return $this->buttonSetStatus($url, 1, $title, $attr); + } + /** + * 删除到回收站 + */ + public function buttonDelete($url = null, $title = '删除', $attr = array()) + { + if (!$url) $url = $this->_setStatusUrl; + $attr['class']='btn ajax-post btn-danger'; + return $this->buttonSetStatus($url, -1, $title, $attr); + } + + public function buttonRestore($url = null, $title = '还原', $attr = array()) + { + if (!$url) $url = $this->_setStatusUrl; + return $this->buttonSetStatus($url, 1, $title, $attr); + } + + /**清空回收站 + * @param null $model + * @return $this + * @author 陈一枭 + */ + public function buttonClear($model = null) + { + return $this->button(L('_CLEAR_OUT_'), array('class' => 'btn ajax-post tox-confirm', 'data-confirm' => L('_CONFIRM_CLEAR_OUT_'), 'url' => U('', array('model' => $model)), 'target-form' => 'ids', 'hide-data' => 'true')); + } + + /**彻底删除 + * @param null $url + * @return $this + * @author 郑钟良 + */ + public function buttonDeleteTrue($url = null) + { + if (!$url) $url = $this->_setDeleteTrueUrl; + $attr['class'] = 'btn ajax-post tox-confirm'; + $attr['data-confirm'] = L('_CONFIRM_DELETE_COMPLETELY_'); + $attr['url'] = $url; + $attr['target-form'] = 'ids'; + return $this->button(L('_DELETE_COMPLETELY_'), $attr); + } + + public function buttonSort($href, $title = '排序', $attr = array()) + { + $attr['href'] = $href; + return $this->button($title, $attr); + } + + /** + * 更新筛选搜索功能 ,修正连续提交多出N+个GET参数的BUG + * @param string $title 标题 + * @param string $name 键名 + * @param string $type 类型,默认文本 + * @param string $des 描述 + * @param $attr 标签文本 + * @param string $arrdb 择筛选项数据来源 + * @param string $arrvalue 筛选数据(包含ID 和value的数组:array(array('id'=>1,'value'=>'系统'),array('id'=>2,'value'=>'项目'),array('id'=>3,'value'=>'机构'));) + * @return $this + * @auth MingYang + */ + public function search($title = '搜索', $name = 'key', $type = 'text', $des = '', $attr, $arrdb = '', $arrvalue = null) { + + if (empty($type) && $type = 'text') { + $this->_search[] = array('title' => $title, 'name' => $name, 'type' => $type, 'des' => $des, 'attr' => $attr); + $this->setSearchPostUrl('', $name, $_GET[$name]); + } else { + if (empty($arrdb)) { + $this->_search[] = array('title' => $title, 'name' => $name, 'type' => $type, 'des' => $des, 'attr' => $attr, 'field' => $field, 'table' => $table, 'arrvalue' => $arrvalue); + $this->setSearchPostUrl('', $field, $_GET[$field]); + } else { + //TODO:待完善如果$arrdb存在的就把当前数据表的$name字段的信息全部查询出来供筛选。 + } + } + return $this; + } + + /** + * 添加筛选功能 + * @param string $title 标题 + * @param string $name 键名 + * @param string $type 类型,默认文本 + * @param string $des 描述 + * @param $attr 标签文本 + * @param string $arrdb 择筛选项数据来源 + * @param string $arrvalue 筛选数据(包含ID 和value的数组:array(array('id'=>1,'value'=>'系统'),array('id'=>2,'value'=>'项目'),array('id'=>3,'value'=>'机构'));) + * @return $this + * @author 郑钟良 + */ + public function select($title = '筛选', $name = 'key', $type = 'select', $des = '', $attr, $arrdb = '', $arrvalue = null) + { + + if (empty($arrdb)) { + $this->_select[] = array('title' => $title, 'name' => $name, 'type' => $type, 'des' => $des, 'attr' => $attr, 'arrvalue' => $arrvalue); + } else { + //TODO:呆完善如果$arrdb存在的就把当前数据表的$name字段的信息全部查询出来供筛选。 + } + return $this; + } + public function selectPlateForm($id,$method,$action) + { + $this->_form[]=array('id'=>$id,'method'=>$method,'action'=>$action); + return $this; + } + public function key($name, $title, $type, $opt = null, $width = '150px') + { + $key = array('name' => $name, 'title' => $title, 'type' => $type, 'opt' => $opt, 'width' => $width); + $this->_keyList[] = $key; + return $this; + } + + /**显示纯文本 + * @param $name 键名 + * @param $title 标题 + * @return AdminListBuilder + * @auth 陈一枭 + */ + public function keyText($name, $title) + { + return $this->key($name, text($title), 'text'); + } + + /**显示html + * @param $name 键名 + * @param $title 标题 + * @return AdminListBuilder + * @auth 陈一枭 + */ + public function keyHtml($name, $title, $width = '150px') + { + return $this->key($name, op_h($title), 'html', null, $width); + } + + public function keyMap($name, $title, $map) + { + return $this->key($name, $title, 'map', $map); + } + + public function keyId($name = 'id', $title = 'ID') + { + return $this->keyText($name, $title); + } + + /** + * 图标展示 + * @param string $name + * @param string $title + * @return $this + * @author 郑钟良 + */ + public function keyIcon($name = 'icon', $title = '图标') + { + return $this->key($name, $title, 'icon'); + } + + /** + * @param $name + * @param $title + * @param $getUrl Closure|string + * 可以是函数或U函数解析的字符串。如果是字符串,该函数将附带一个id参数 + * + * @return $this + */ + public function keyLink($name, $title, $getUrl) + { + //如果getUrl是一个字符串,则表示getUrl是一个U函数解析的字符串 + if (is_string($getUrl)) { + $getUrl = $this->createDefaultGetUrlFunction($getUrl); + } + + //修整添加多个空字段时显示不正常的BUG@mingyangliu + if (empty($name)) { + $name = $title; + } + + //添加key + return $this->key($name, $title, 'link', $getUrl); + } + + public function keyStatus($name = 'status', $title = '状态') + { + $map = array(-1 => L('_DELETE_'), 0 => L('_DISABLE_'), 1 => L('_ENABLE_'), 2 => L('_UNAUDITED_')); + return $this->key($name, $title, 'status', $map); + } + + public function keyYesNo($name, $title) + { + $map = array(0 => L('_NO_'), 1 => L('_YES_')); + return $this->keymap($name, $title, $map); + } + + public function keyBool($name, $title) + { + return $this->keyYesNo($name, $title); + } + + public function keyImage($name, $title) + { + return $this->key($name, $title, 'image'); + } + + public function keyTime($name, $title) + { + return $this->key($name, $title, 'time'); + } + + public function keyCreateTime($name = 'create_time', $title = '创建时间') + { + return $this->keyTime($name, $title); + } + + public function keyUpdateTime($name = 'update_time', $title = '更新时间') + { + return $this->keyTime($name, $title); + } + + public function keyUid($name = 'uid', $title = '用户') + { + return $this->key($name, $title, 'uid'); + } + + public function keyNickname($name = 'uid', $title, $subtitle = null) + { + return $this->key($name, $title, $subtitle, 'nickname'); + } + + public function keyTitle($name = 'title', $title = '标题') + { + return $this->keyText($name, $title); + } + + //关联表字段显示+URL连接 + public function keyJoin($name, $title, $mate, $return, $model, $url = '') + { + $map = array('mate' => $mate, 'return' => $return, 'model' => $model, 'url' => $url); + return $this->key($name, $title, 'Join', $map); + } + + /** + * 模态弹窗 + * @param $getUrl + * @param $text + * @param $title + * @param array $attr + * @return $this + * @author 郑钟良 + */ + public function keyDoActionModalPopup($getUrl, $text, $title, $attr = array()) + { + //attr中需要设置data-title,用于设置模态弹窗标题 + $attr['data-role'] = 'modal_popup'; + //获取默认getUrl函数 + if (is_string($getUrl)) { + $getUrl = $this->createDefaultGetUrlFunction($getUrl); + } + //确认已经创建了DOACTIONS字段 + $doActionKey = null; + foreach ($this->_keyList as $key) { + if ($key['name'] === 'DOACTIONS') { + $doActionKey = $key; + break; + } + } + if (!$doActionKey) { + $this->key('DOACTIONS', $title, 'doaction', $attr); + } + + //找出第一个DOACTIONS字段 + $doActionKey = null; + foreach ($this->_keyList as &$key) { + if ($key['name'] == 'DOACTIONS') { + $doActionKey = &$key; + break; + } + } + + //在DOACTIONS中增加action + $doActionKey['opt']['actions'][] = array('text' => $text, 'get_url' => $getUrl, 'opt' => $attr); + return $this; + } + + public function keyDoAction($getUrl, $text, $title = '操作') + { + //获取默认getUrl函数 + if (is_string($getUrl)) { + $getUrl = $this->createDefaultGetUrlFunction($getUrl); + } + + //确认已经创建了DOACTIONS字段 + $doActionKey = null; + foreach ($this->_keyList as $key) { + if ($key['name'] === 'DOACTIONS') { + $doActionKey = $key; + break; + } + } + if (!$doActionKey) { + $this->key('DOACTIONS', $title, 'doaction', array()); + } + + //找出第一个DOACTIONS字段 + $doActionKey = null; + foreach ($this->_keyList as &$key) { + if ($key['name'] == 'DOACTIONS') { + $doActionKey = &$key; + break; + } + } + + //在DOACTIONS中增加action + $doActionKey['opt']['actions'][] = array('text' => $text, 'get_url' => $getUrl); + return $this; + } + + public function keyDoActionEdit($getUrl, $text = '编辑') + { + return $this->keyDoAction($getUrl, $text); + } + + public function keyDoActionRestore($text = '还原') + { + $that = $this; + $setStatusUrl = $this->_setStatusUrl; + $getUrl = function () use ($that, $setStatusUrl) { + return $that->addUrlParam($setStatusUrl, array('status' => 1)); + }; + return $this->keyDoAction($getUrl, $text, array('class' => 'ajax-get')); + } + + public function keyTruncText($name, $title, $length) + { + return $this->key($name, $title, 'trunktext', $length); + } + + /** + * 不要给listRows默认值,因为开发人员很可能忘记填写listRows导致翻页不正确 + * @param $totalCount + * @param $listRows + * @return $this + */ + public function pagination($totalCount, $listRows) + { + $this->_pagination = array('totalCount' => $totalCount, 'listRows' => $listRows); + return $this; + } + + public function data($list) + { + $this->_data = $list; + return $this; + } + + /** + * $solist 判断是否属于选择返回数据的列表页,如果是在列表页->display('admin_solist');@mingyangliu + * */ + public function display($solist = '') + { + //key类型的等价转换 + //map转换成text + $this->convertKey('map', 'text', function ($value, $key) { + return $key['opt'][$value]; + }); + + //uid转换成text + $this->convertKey('uid', 'text', function ($value) { + $value = query_user(array('nickname', 'uid', 'space_url'), $value); + return "[{$value[uid]}]" . $value['nickname'] . ''; + }); + + //nickname转换成text + $this->convertKey('nickname', 'text', function ($value) { + $value = query_user(array('nickname', 'uid', 'space_url'), $value); + return "[{$value[uid]}]" . $value['nickname'] . ''; + }); + + //time转换成text + $this->convertKey('time', 'text', function ($value) { + if ($value != 0) { + return time_format($value); + } else { + return '-'; + } + }); + + //trunctext转换成text + $this->convertKey('trunktext', 'text', function ($value, $key) { + $length = $key['opt']; + return msubstr($value, 0, $length); + }); + + //text转换成html + $this->convertKey('text', 'html', function ($value) { + return $value; + }); + + //link转换为html + $this->convertKey('link', 'html', function ($value, $key, $item) { + $value = htmlspecialchars($value); + $getUrl = $key['opt']; + $url = $getUrl($item); + //允许字段为空,如果字段名为空将标题名填充到A变现里 + if (!$value) { + return "" . $key['title'] . ""; + } else { + return "$value"; + } + }); + + //如果icon为空 + $this->convertKey('icon', 'html', function ($value, $key, $item) { + $value = htmlspecialchars($value); + if ($value == '') { + $html = L('_NONE_'); + } else { + $html = " $value"; + } + return $html; + }); + + //image转换为图片 + + $this->convertKey('image', 'html', function ($value, $key, $item) { + if (intval($value)) {//value是图片id + $value = htmlspecialchars($value); + $sc_src = get_cover($value, 'path'); + + $src = getThumbImageById($value, 80, 80); + $sc_src = $sc_src == '' ? $src : $sc_src; + $html = ""; + } else {//value是图片路径 + $sc_src = $value; + $html = ""; + } + return $html; + }); + + //doaction转换为html + $this->convertKey('doaction', 'html', function ($value, $key, $item) { + $actions = $key['opt']['actions']; + $result = array(); + foreach ($actions as $action) { + $getUrl = $action['get_url']; + $linkText = $action['text']; + $url = $getUrl($item); + if (isset($action['opt'])) { + $content = array(); + foreach ($action['opt'] as $key => $value) { + $value = htmlspecialchars($value); + $content[] = "$key=\"$value\""; + } + $content = implode(' ', $content); + if (isset($action['opt']['data-role']) && $action['opt']['data-role'] == "modal_popup") {//模态弹窗 + $result[] = "$linkText"; + } else { + $result[] = "$linkText"; + } + } else { + $result[] = "$linkText"; + } + } + return implode(' ', $result); + }); + + //Join转换为html + $this->convertKey('Join', 'html', function ($value, $key) { + if ($value != 0) { + $val = get_table_field($value, $key['opt']['mate'], $key['opt']['return'], $key['opt']['model']); + if (!$key['opt']['url']) { + return $val; + } else { + $urld = U($key['opt']['url'], array($key['opt']['return'] => $value)); + return "$val"; + } + } else { + return '-'; + } + }); + + //status转换为html + $setStatusUrl = $this->_setStatusUrl; + $that = &$this; + $this->convertKey('status', 'html', function ($value, $key, $item) use ($setStatusUrl, $that) { + //如果没有设置修改状态的URL,则直接返回文字 + $map = $key['opt']; + $text = $map[$value]; + if (!$setStatusUrl) { + return $text; + } + + //返回带链接的文字 + $switchStatus = $value == 1 ? 0 : 1; + $url = $that->addUrlParam($setStatusUrl, array('status' => $switchStatus, 'ids' => $item['id'])); + return "$text"; + }); + + //如果html为空 + $this->convertKey('html', 'html', function ($value) { + if ($value === '') { + return '' . L('_EMPTY_BRACED_') . ''; + } + return $value; + }); + + + //编译buttonList中的属性 + foreach ($this->_buttonList as &$button) { + $button['tag'] = isset($button['attr']['href']) ? 'a' : 'button'; + $this->addDefaultCssClass($button); + $button['attr'] = $this->compileHtmlAttr($button['attr']); + } + + //生成翻页HTML代码 + C('VAR_PAGE', 'page'); + $pager = new \Think\Page($this->_pagination['totalCount'], $this->_pagination['listRows'], $_REQUEST); + $pager->setConfig('theme', '%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END% %HEADER%'); + $paginationHtml = $pager->show(); + + //显示页面 + $this->assign('title', $this->_title); + $this->assign('suggest', $this->_suggest); + $this->assign('keyList', $this->_keyList); + $this->assign('buttonList', $this->_buttonList); + $this->assign('pagination', $paginationHtml); + $this->assign('list', $this->_data); + /*加入搜索 陈一枭*/ + $this->assign('searches', $this->_search); + $this->assign('searchPostUrl', $this->_searchPostUrl); + + /*加入筛选select 郑钟良*/ + $this->assign('selects', $this->_select); + $this->assign('selectPostUrl', $this->_selectPostUrl); + //如果是选择返回数据的列表页就调用admin_solist模板文件,否则编译原有模板 + if ($solist) { + parent::display('admin_solist'); + } else { + parent::display('admin_list'); + } + } + + public function doSetStatus($model, $ids, $status = 1) + { + $id = array_unique((array)$ids); + $rs = M($model)->where(array('id' => array('in', $id)))->save(array('status' => $status)); + if ($rs === false) { + $this->error(L('_ERROR_SETTING_') . L('_PERIOD_')); + } + $this->success(L('_SUCCESS_SETTING_'), $_SERVER['HTTP_REFERER']); + } + + + private function convertKey($from, $to, $convertFunction) + { + foreach ($this->_keyList as &$key) { + if ($key['type'] == $from) { + $key['type'] = $to; + foreach ($this->_data as &$data) { + $value = &$data[$key['name']]; + $value = $convertFunction($value, $key, $data); + unset($value); + } + unset($data); + } + } + unset($key); + } + + private function addDefaultCssClass(&$button) + { + if (!isset($button['attr']['class'])) { + $button['attr']['class'] = 'btn'; + } else { + $button['attr']['class'] .= ' btn'; + } + } + + /** + * @param $pattern U函数解析的URL字符串,例如 Admin/Test/index?test_id=### + * Admin/Test/index?test_id={other_id} + * ###将被id替换 + * {other_id}将被替换 + * @return callable + */ + private function createDefaultGetUrlFunction($pattern) + { + $explode = explode('|', $pattern); + $pattern = $explode[0]; + $fun = empty($explode[1]) ? 'U' : $explode[1]; + return function ($item) use ($pattern, $fun) { + $pattern = str_replace('###', $item['id'], $pattern); + //调用ThinkPHP中的解析引擎解析变量 + $view = new \Think\View(); + $view->assign($item); + $pattern = $view->fetch('', $pattern); + return $fun($pattern); + }; + } + + public function addUrlParam($url, $params) + { + if (strpos($url, '?') === false) { + $seperator = '?'; + } else { + $seperator = '&'; + } + $params = http_build_query($params); + return $url . $seperator . $params; + } + + /**自动处理清空回收站 + * @param string $model 要清空的模型 + * @auth 陈一枭 + */ + public function clearTrash($model = '') + { + if (IS_POST) { + if ($model != '') { + $aIds = I('post.ids', array()); + if (!empty($aIds)) { + $map['id'] = array('in', $aIds); + } else { + $map['status'] = -1; + } + + $result = D($model)->where($map)->delete(); + if ($result) { + $this->success(L('_SUCCESS_TRASH_CLEARED_', array('result' => $result))); + } + $this->error(L('_TRASH_ALREADY_EMPTY_')); + } else { + $this->error(L('_TRASH_SELECT_')); + } + } + } + + /**执行彻底删除数据,只适用于无关联的数据表 + * @param $model + * @param $ids + * @author 郑钟良 + */ + public function doDeleteTrue($model, $ids) + { + $ids = is_array($ids) ? $ids : explode(',', $ids); + M($model)->where(array('id' => array('in', $ids)))->delete(); + $this->success(L('_SUCCESS_DELETE_COMPLETELY_'), $_SERVER['HTTP_REFERER']); + } + + /** + * keyLinkByFlag 带替换表示的链接 + * @param $name + * @param $title + * @param $getUrl + * @param string $flag + * @return $this + * @author:xjw129xjt xjt@ourstu.com + */ + public function keyLinkByFlag($name, $title, $getUrl, $flag = 'id') + { + + //如果getUrl是一个字符串,则表示getUrl是一个U函数解析的字符串 + if (is_string($getUrl)) { + $getUrl = $this->ParseUrl($getUrl, $flag); + } + + //添加key + return $this->key($name, $title, 'link', $getUrl); + } + + /**解析Url + * @param $pattern URL文本 + * @param $flag + * @return callable + * @auth 陈一枭 + */ + private function ParseUrl($pattern, $flag) + { + return function ($item) use ($pattern, $flag) { + + $pattern = str_replace('###', $item[$flag], $pattern); + //调用ThinkPHP中的解析引擎解析变量 + $view = new \Think\View(); + $view->assign($item); + $pattern = $view->fetch('', $pattern); + return U($pattern); + }; + } + } \ No newline at end of file diff --git a/Application/Admin/View/default/Builder/_key.html b/Application/Admin/View/default/Builder/_key.html index 96f83426b54e892f73f57bd84dae0a1e7068c24d..61a2aa30bf3c351c88384bbd2a30f01aed4e3eea 100644 --- a/Application/Admin/View/default/Builder/_key.html +++ b/Application/Admin/View/default/Builder/_key.html @@ -26,6 +26,36 @@ style="width: 400px" placeholder={:L("_NO_NEED_TO_FILL_IN_WITH_DOUBLE_")} readonly/>

{$field.value}

+ + + $url=$field['opt']['url']; + $elements=$field['opt']['selects']; + $firstSelectOpts=''; + foreach ($field['opt']['opt'] as $key => $value){ + $selected = $field['value']==$key ? ' selected' : ''; + $firstSelectOpts.=''; + } + //dump($field['name']); + + + + + + $ids = implode('","',array_keys($elements)); + + @@ -41,7 +71,7 @@ $selected = $field['value']==$key ? 'selected' : ''; + {$selected} >{$option|htmlspecialchars} @@ -307,7 +337,7 @@ -
- - -
- -
- -
-
- - -
- -
- -
- - -
- - - - - - - $col=10; - - $col=12; - -
- -
-    {:L('_VERSION_UPDATE_',array('href'=> '' ))} - -
-
- -
- - - - - - - - -
- -
- -
-
-
-
-
- - - -if($report){ -
-
- 1 -
- - - - - - - - -} - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + {$meta_title} + + + + + + + + + + + + + + + + + + + + + + +
+ + +
+ +
+ +
+
+ + +
+ +
+ +
+ + +
+ + + + + + + $col=10; + + $col=12; + +
+ +
+    {:L('_VERSION_UPDATE_',array('href'=> '' ))} + +
+
+ +
+ + + + + + + + +
+ +
+ +
+
+
+
+
+ + + +if($report){ +
+
+ 1 +
+ + + + + + + + +} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Application/Admin/View/default/Public/exception.html b/Application/Admin/View/default/Public/exception.html index 59071453d53b205281247d623c121f28309c2137..88c6e92ef96d2ef1a86cb605111a47a1c8b3a9c4 100644 --- a/Application/Admin/View/default/Public/exception.html +++ b/Application/Admin/View/default/Public/exception.html @@ -1,53 +1,50 @@ - - - -系统发生错误 - - - -
-

:(

-

-
- -
-
-

错误地址:

-
-
-

FILE:  LINE:

-
-
- - -
-
-

TRACE

-
-
-

-
-
- -
-
- - + + + +系统发生错误 + + + +
+

:(

+

+
+ +
+
+

错误地址:

+
+
+

FILE:  LINE:

+
+
+ + +
+
+

TRACE

+
+
+

+
+
+ +
+
+ \ No newline at end of file diff --git a/Application/Common/Common/function.php b/Application/Common/Common/function.php index ac34b09490f45ac9724dd87b9352c1044d6af135..5a221d2adfb71875b1ba325d036c88934744ed5d 100644 --- a/Application/Common/Common/function.php +++ b/Application/Common/Common/function.php @@ -29,6 +29,7 @@ require_once(APP_PATH . '/Common/Common/limit.php'); require_once(APP_PATH . '/Common/Common/role.php'); require_once(APP_PATH . '/Common/Common/ext_parse.php'); require_once(APP_PATH . '/Common/Common/collect.php'); +require_once(APP_PATH . '/Common/Common/heatfly.php'); /*require_once(APP_PATH . '/Common/Common/extend.php');*/ diff --git a/Application/Common/Common/heatfly.php b/Application/Common/Common/heatfly.php new file mode 100644 index 0000000000000000000000000000000000000000..6404bda900bca29742461a210e1f778b0ced634d --- /dev/null +++ b/Application/Common/Common/heatfly.php @@ -0,0 +1,47 @@ + -// +---------------------------------------------------------------------- -namespace Think; -/** - * ThinkPHP 控制器基类 抽象类 - */ -abstract class Controller -{ - - /** - * 视图实例对象 - * @var view - * @access protected - */ - protected $view = null; - - /** - * 控制器参数 - * @var config - * @access protected - */ - protected $config = array(); - - /*OpenSNS新增部分*/ - /**seo参数 陈一枭 OpenSNS - * @var array - */ - public $_seo = array(); - - public function setTitle($title) - { - $this->_seo['title'] = $title; - $this->assign('seo', $this->_seo); - } - - public function setKeywords($keywords) - { - $this->_seo['keywords'] = $keywords; - $this->assign('seo', $this->_seo); - } - - public function setDescription($description) - { - $this->_seo['description'] = $description; - $this->assign('seo', $this->_seo); - } - - - - - /*OpenSNS新增部分end*/ - - - /** - * 架构函数 取得模板对象实例 - * @access public - */ - public function __construct() - { - if (is_file('./Conf/user.php')) {//已经安装了 - - $moduleModel = D('Common/Module'); - /*读取站点配置*/ - $config = api('Config/lists'); - C($config); //添加配置 - $module =$moduleModel->getModule(MODULE_NAME); - - - if (strtolower(MODULE_NAME) != 'install' && strtolower(MODULE_NAME) != 'admin') { - if (!C('WEB_SITE_CLOSE')) { - header("Content-Type: text/html; charset=utf-8"); - exit('站点已经关闭,请稍后访问~'); - } - - if (strtolower(MODULE_NAME) != 'install' && strtolower(MODULE_NAME) != 'admin') { - $moduleModel->checkCanVisit(MODULE_NAME); - } - } - } - - - Hook::listen('action_begin', $this->config); - //实例化视图类 - $this->view = Think::instance('Think\View'); - if(!empty($module)){ - $this->view->assign('MODULE_INFO', $module); - $this->view->assign('MODULE_ALIAS', $module['alias']); - } - - //控制器初始化 - if (method_exists($this, '_initialize')) - $this->_initialize(); - } - - /** - * 模板显示 调用内置的模板引擎显示方法, - * @access protected - * @param string $templateFile 指定要调用的模板文件 - * 默认为空 由系统自动定位模板文件 - * @param string $charset 输出编码 - * @param string $contentType 输出类型 - * @param string $content 输出内容 - * @param string $prefix 模板缓存前缀 - * @return void - */ - protected function display($templateFile = '', $charset = '', $contentType = '', $content = '', $prefix = '') - { - - $this->view->display($templateFile, $charset, $contentType, $content, $prefix); - } - - /** - * 输出内容文本可以包括Html 并支持内容解析 - * @access protected - * @param string $content 输出内容 - * @param string $charset 模板输出字符集 - * @param string $contentType 输出类型 - * @param string $prefix 模板缓存前缀 - * @return mixed - */ - protected function show($content, $charset = '', $contentType = '', $prefix = '') - { - $this->view->display('', $charset, $contentType, $content, $prefix); - } - - /** - * 获取输出页面内容 - * 调用内置的模板引擎fetch方法, - * @access protected - * @param string $templateFile 指定要调用的模板文件 - * 默认为空 由系统自动定位模板文件 - * @param string $content 模板输出内容 - * @param string $prefix 模板缓存前缀* - * @return string - */ - protected function fetch($templateFile = '', $content = '', $prefix = '') - { - return $this->view->fetch($templateFile, $content, $prefix); - } - - /** - * 创建静态页面 - * @access protected - * @htmlfile 生成的静态文件名称 - * @htmlpath 生成的静态文件路径 - * @param string $templateFile 指定要调用的模板文件 - * 默认为空 由系统自动定位模板文件 - * @return string - */ - protected function buildHtml($htmlfile = '', $htmlpath = '', $templateFile = '') - { - $content = $this->fetch($templateFile); - $htmlpath = !empty($htmlpath) ? $htmlpath : HTML_PATH; - $htmlfile = $htmlpath . $htmlfile . C('HTML_FILE_SUFFIX'); - Storage::put($htmlfile, $content, 'html'); - return $content; - } - - /** - * 模板主题设置 - * @access protected - * @param string $theme 模版主题 - * @return Action - */ - protected function theme($theme) - { - $this->view->theme($theme); - return $this; - } - - /** - * 模板变量赋值 - * @access protected - * @param mixed $name 要显示的模板变量 - * @param mixed $value 变量的值 - * @return Action - */ - protected function assign($name, $value = '') - { - $this->view->assign($name, $value); - return $this; - } - - public function __set($name, $value) - { - $this->assign($name, $value); - } - - /** - * 取得模板显示变量的值 - * @access protected - * @param string $name 模板显示变量 - * @return mixed - */ - public function get($name = '') - { - return $this->view->get($name); - } - - public function __get($name) - { - return $this->get($name); - } - - /** - * 检测模板变量的值 - * @access public - * @param string $name 名称 - * @return boolean - */ - public function __isset($name) - { - return $this->get($name); - } - - /** - * 魔术方法 有不存在的操作的时候执行 - * @access public - * @param string $method 方法名 - * @param array $args 参数 - * @return mixed - */ - public function __call($method, $args) - { - if (0 === strcasecmp($method, ACTION_NAME . C('ACTION_SUFFIX'))) { - if (method_exists($this, '_empty')) { - // 如果定义了_empty操作 则调用 - $this->_empty($method, $args); - } elseif (file_exists_case($this->view->parseTemplate())) { - // 检查是否存在默认模版 如果有直接输出模版 - $this->display(); - } else { - E(L('_ERROR_ACTION_') . ':' . ACTION_NAME,815); - } - } else { - E(__CLASS__ . ':' . $method . L('_METHOD_NOT_EXIST_')); - return; - } - } - - /** - * 操作错误跳转的快捷方法 - * @access protected - * @param string $message 错误信息 - * @param string $jumpUrl 页面跳转地址 - * @param mixed $ajax 是否为Ajax方式 当数字时指定跳转时间 - * @return void - */ - protected function error($message = '', $jumpUrl = '', $ajax = false) - { - $this->dispatchJump($message, 0, $jumpUrl, $ajax); - } - - /** - * 操作成功跳转的快捷方法 - * @access protected - * @param string $message 提示信息 - * @param string $jumpUrl 页面跳转地址 - * @param mixed $ajax 是否为Ajax方式 当数字时指定跳转时间 - * @return void - */ - protected function success($message = '', $jumpUrl = '', $ajax = false) - { - $this->dispatchJump($message, 1, $jumpUrl, $ajax); - } - - /** - * Ajax方式返回数据到客户端 - * @access protected - * @param mixed $data 要返回的数据 - * @param String $type AJAX返回数据格式 - * @return void - */ - protected function ajaxReturn($data, $type = '') - { - if (empty($type)) $type = C('DEFAULT_AJAX_RETURN'); - switch (strtoupper($type)) { - case 'JSON' : - // 返回JSON数据格式到客户端 包含状态信息 - header('Content-Type:application/json; charset=utf-8'); - exit(json_encode($data)); - case 'XML' : - // 返回xml格式数据 - header('Content-Type:text/xml; charset=utf-8'); - exit(xml_encode($data)); - case 'JSONP': - // 返回JSON数据格式到客户端 包含状态信息 - header('Content-Type:application/json; charset=utf-8'); - $handler = isset($_GET[C('VAR_JSONP_HANDLER')]) ? $_GET[C('VAR_JSONP_HANDLER')] : C('DEFAULT_JSONP_HANDLER'); - exit($handler . '(' . json_encode($data) . ');'); - case 'EVAL' : - // 返回可执行的js脚本 - header('Content-Type:text/html; charset=utf-8'); - exit($data); - default : - // 用于扩展其他返回格式数据 - Hook::listen('ajax_return', $data); - } - } - - /** - * Action跳转(URL重定向) 支持指定模块和延时跳转 - * @access protected - * @param string $url 跳转的URL表达式 - * @param array $params 其它URL参数 - * @param integer $delay 延时跳转的时间 单位为秒 - * @param string $msg 跳转提示信息 - * @return void - */ - protected function redirect($url, $params = array(), $delay = 0, $msg = '') - { - $url = U($url, $params); - redirect($url, $delay, $msg); - } - - /** - * 默认跳转操作 支持错误导向和正确跳转 - * 调用模板显示 默认为public目录下面的success页面 - * 提示页面为可配置 支持模板标签 - * @param string $message 提示信息 - * @param Boolean $status 状态 - * @param string $jumpUrl 页面跳转地址 - * @param mixed $ajax 是否为Ajax方式 当数字时指定跳转时间 - * @access private - * @return void - */ - private function dispatchJump($message, $status = 1, $jumpUrl = '', $ajax = false) - { - if (true === $ajax || IS_AJAX) {// AJAX提交 - $data = is_array($ajax) ? $ajax : array(); - $data['info'] = $message; - $data['status'] = $status; - $data['url'] = $jumpUrl; - $this->ajaxReturn($data); - } - if (is_int($ajax)) $this->assign('waitSecond', $ajax); - if (!empty($jumpUrl)) $this->assign('jumpUrl', $jumpUrl); - // 提示标题 - $this->assign('msgTitle', $status ? L('_OPERATION_SUCCESS_') : L('_OPERATION_FAIL_')); - //如果设置了关闭窗口,则提示完毕后自动关闭窗口 - if ($this->get('closeWin')) $this->assign('jumpUrl', 'javascript:window.close();'); - $this->assign('status', $status); // 状态 - //保证输出不受静态缓存影响 - C('HTML_CACHE_ON', false); - if ($status) { //发送成功信息 - $this->assign('success_message', $message);// 提示信息 - // 成功操作后默认停留1秒 - if (!isset($this->waitSecond)) $this->assign('waitSecond', modC('SUCCESS_WAIT_TIME','2','config')); - // 默认操作成功自动返回操作前页面 - if (!isset($this->jumpUrl)) $this->assign("jumpUrl", $_SERVER["HTTP_REFERER"]); - $this->display(C('TMPL_ACTION_SUCCESS')); - exit; - } else { - $this->assign('error_message', $message);// 提示信息 - //发生错误时候默认停留3秒 - if (!isset($this->waitSecond)) $this->assign('waitSecond', modC('ERROR_WAIT_TIME','10','config')); - // 默认发生错误的话自动返回上页 - if (!isset($this->jumpUrl)) $this->assign('jumpUrl', "javascript:history.back(-1);"); - $this->display(C('TMPL_ACTION_ERROR')); - // 中止执行 避免出错后继续执行 - exit; - } - } - - /** - * 析构方法 - * @access public - */ - public function __destruct() - { - // 执行后续操作 - Hook::listen('action_end'); - } - - /** - * checkRule 检查权限 - * @author:xjw129xjt(肖骏涛) xjt@ourstu.com - */ - public function checkAuth($rule ='',$except_uid =-1,$msg = ''){ - if (!check_auth($rule,$except_uid)) { - $this->error(empty($msg)?'您无操作权限。':$msg); - } - } - - /** - * check_action_limit 行为限制 - * @param null $action - * @param null $model - * @param null $record_id - * @param null $user_id - * @param bool $ip - * @author 郑钟良 - */ - public function checkActionLimit($action = null, $model = null, $record_id = null, $user_id = null, $ip = false,$url = false){ - $return = check_action_limit($action, $model, $record_id, $user_id, $ip); - if ($return && !$return['state']) { - if($url === true){ - $url = $return['url']; - }elseif($url === false){ - $url = ''; - } - $this->error($return['info'],$url); - } - } - -} - -// 设置控制器别名 便于升级 + +// +---------------------------------------------------------------------- +namespace Think; +/** + * ThinkPHP 控制器基类 抽象类 + */ +abstract class Controller +{ + + /** + * 视图实例对象 + * @var view + * @access protected + */ + protected $view = null; + + /** + * 控制器参数 + * @var config + * @access protected + */ + protected $config = array(); + + /*OpenSNS新增部分*/ + /**seo参数 陈一枭 OpenSNS + * @var array + */ + public $_seo = array(); + + public function setTitle($title) + { + $this->_seo['title'] = $title; + $this->assign('seo', $this->_seo); + } + + public function setKeywords($keywords) + { + $this->_seo['keywords'] = $keywords; + $this->assign('seo', $this->_seo); + } + + public function setDescription($description) + { + $this->_seo['description'] = $description; + $this->assign('seo', $this->_seo); + } + + + + + /*OpenSNS新增部分end*/ + + + /** + * 架构函数 取得模板对象实例 + * @access public + */ + public function __construct() + { + if (is_file('./Conf/user.php')) {//已经安装了 + + $moduleModel = D('Common/Module'); + /*读取站点配置*/ + $config = api('Config/lists'); + C($config); //添加配置 + $module =$moduleModel->getModule(MODULE_NAME); + + + if (strtolower(MODULE_NAME) != 'install' && strtolower(MODULE_NAME) != 'admin') { + if (!C('WEB_SITE_CLOSE')) { + header("Content-Type: text/html; charset=utf-8"); + exit(C('WEB_SITE_CLOSE_HINT')); + } + + if (strtolower(MODULE_NAME) != 'install' && strtolower(MODULE_NAME) != 'admin') { + $moduleModel->checkCanVisit(MODULE_NAME); + } + } + } + + + Hook::listen('action_begin', $this->config); + //实例化视图类 + $this->view = Think::instance('Think\View'); + if(!empty($module)){ + $this->view->assign('MODULE_INFO', $module); + $this->view->assign('MODULE_ALIAS', $module['alias']); + } + + //控制器初始化 + if (method_exists($this, '_initialize')) + $this->_initialize(); + } + + /** + * 模板显示 调用内置的模板引擎显示方法, + * @access protected + * @param string $templateFile 指定要调用的模板文件 + * 默认为空 由系统自动定位模板文件 + * @param string $charset 输出编码 + * @param string $contentType 输出类型 + * @param string $content 输出内容 + * @param string $prefix 模板缓存前缀 + * @return void + */ + protected function display($templateFile = '', $charset = '', $contentType = '', $content = '', $prefix = '') + { + + $this->view->display($templateFile, $charset, $contentType, $content, $prefix); + } + + /** + * 输出内容文本可以包括Html 并支持内容解析 + * @access protected + * @param string $content 输出内容 + * @param string $charset 模板输出字符集 + * @param string $contentType 输出类型 + * @param string $prefix 模板缓存前缀 + * @return mixed + */ + protected function show($content, $charset = '', $contentType = '', $prefix = '') + { + $this->view->display('', $charset, $contentType, $content, $prefix); + } + + /** + * 获取输出页面内容 + * 调用内置的模板引擎fetch方法, + * @access protected + * @param string $templateFile 指定要调用的模板文件 + * 默认为空 由系统自动定位模板文件 + * @param string $content 模板输出内容 + * @param string $prefix 模板缓存前缀* + * @return string + */ + protected function fetch($templateFile = '', $content = '', $prefix = '') + { + return $this->view->fetch($templateFile, $content, $prefix); + } + + /** + * 创建静态页面 + * @access protected + * @htmlfile 生成的静态文件名称 + * @htmlpath 生成的静态文件路径 + * @param string $templateFile 指定要调用的模板文件 + * 默认为空 由系统自动定位模板文件 + * @return string + */ + protected function buildHtml($htmlfile = '', $htmlpath = '', $templateFile = '') + { + $content = $this->fetch($templateFile); + $htmlpath = !empty($htmlpath) ? $htmlpath : HTML_PATH; + $htmlfile = $htmlpath . $htmlfile . C('HTML_FILE_SUFFIX'); + Storage::put($htmlfile, $content, 'html'); + return $content; + } + + /** + * 模板主题设置 + * @access protected + * @param string $theme 模版主题 + * @return Action + */ + protected function theme($theme) + { + $this->view->theme($theme); + return $this; + } + + /** + * 模板变量赋值 + * @access protected + * @param mixed $name 要显示的模板变量 + * @param mixed $value 变量的值 + * @return Action + */ + protected function assign($name, $value = '') + { + $this->view->assign($name, $value); + return $this; + } + + public function __set($name, $value) + { + $this->assign($name, $value); + } + + /** + * 取得模板显示变量的值 + * @access protected + * @param string $name 模板显示变量 + * @return mixed + */ + public function get($name = '') + { + return $this->view->get($name); + } + + public function __get($name) + { + return $this->get($name); + } + + /** + * 检测模板变量的值 + * @access public + * @param string $name 名称 + * @return boolean + */ + public function __isset($name) + { + return $this->get($name); + } + + /** + * 魔术方法 有不存在的操作的时候执行 + * @access public + * @param string $method 方法名 + * @param array $args 参数 + * @return mixed + */ + public function __call($method, $args) + { + if (0 === strcasecmp($method, ACTION_NAME . C('ACTION_SUFFIX'))) { + if (method_exists($this, '_empty')) { + // 如果定义了_empty操作 则调用 + $this->_empty($method, $args); + } elseif (file_exists_case($this->view->parseTemplate())) { + // 检查是否存在默认模版 如果有直接输出模版 + $this->display(); + } else { + E(L('_ERROR_ACTION_') . ':' . ACTION_NAME,815); + } + } else { + E(__CLASS__ . ':' . $method . L('_METHOD_NOT_EXIST_')); + return; + } + } + + /** + * 操作错误跳转的快捷方法 + * @access protected + * @param string $message 错误信息 + * @param string $jumpUrl 页面跳转地址 + * @param mixed $ajax 是否为Ajax方式 当数字时指定跳转时间 + * @return void + */ + protected function error($message = '', $jumpUrl = '', $ajax = false) + { + $this->dispatchJump($message, 0, $jumpUrl, $ajax); + } + + /** + * 操作成功跳转的快捷方法 + * @access protected + * @param string $message 提示信息 + * @param string $jumpUrl 页面跳转地址 + * @param mixed $ajax 是否为Ajax方式 当数字时指定跳转时间 + * @return void + */ + protected function success($message = '', $jumpUrl = '', $ajax = false) + { + $this->dispatchJump($message, 1, $jumpUrl, $ajax); + } + + /** + * Ajax方式返回数据到客户端 + * @access protected + * @param mixed $data 要返回的数据 + * @param String $type AJAX返回数据格式 + * @return void + */ + protected function ajaxReturn($data, $type = '') + { + if (empty($type)) $type = C('DEFAULT_AJAX_RETURN'); + switch (strtoupper($type)) { + case 'JSON' : + // 返回JSON数据格式到客户端 包含状态信息 + header('Content-Type:application/json; charset=utf-8'); + exit(json_encode($data)); + case 'XML' : + // 返回xml格式数据 + header('Content-Type:text/xml; charset=utf-8'); + exit(xml_encode($data)); + case 'JSONP': + // 返回JSON数据格式到客户端 包含状态信息 + header('Content-Type:application/json; charset=utf-8'); + $handler = isset($_GET[C('VAR_JSONP_HANDLER')]) ? $_GET[C('VAR_JSONP_HANDLER')] : C('DEFAULT_JSONP_HANDLER'); + exit($handler . '(' . json_encode($data) . ');'); + case 'EVAL' : + // 返回可执行的js脚本 + header('Content-Type:text/html; charset=utf-8'); + exit($data); + default : + // 用于扩展其他返回格式数据 + Hook::listen('ajax_return', $data); + } + } + + /** + * Action跳转(URL重定向) 支持指定模块和延时跳转 + * @access protected + * @param string $url 跳转的URL表达式 + * @param array $params 其它URL参数 + * @param integer $delay 延时跳转的时间 单位为秒 + * @param string $msg 跳转提示信息 + * @return void + */ + protected function redirect($url, $params = array(), $delay = 0, $msg = '') + { + $url = U($url, $params); + redirect($url, $delay, $msg); + } + + /** + * 默认跳转操作 支持错误导向和正确跳转 + * 调用模板显示 默认为public目录下面的success页面 + * 提示页面为可配置 支持模板标签 + * @param string $message 提示信息 + * @param Boolean $status 状态 + * @param string $jumpUrl 页面跳转地址 + * @param mixed $ajax 是否为Ajax方式 当数字时指定跳转时间 + * @access private + * @return void + */ + private function dispatchJump($message, $status = 1, $jumpUrl = '', $ajax = false) + { + if (true === $ajax || IS_AJAX) {// AJAX提交 + $data = is_array($ajax) ? $ajax : array(); + $data['info'] = $message; + $data['status'] = $status; + $data['url'] = $jumpUrl; + $this->ajaxReturn($data); + } + if (is_int($ajax)) $this->assign('waitSecond', $ajax); + if (!empty($jumpUrl)) $this->assign('jumpUrl', $jumpUrl); + // 提示标题 + $this->assign('msgTitle', $status ? L('_OPERATION_SUCCESS_') : L('_OPERATION_FAIL_')); + //如果设置了关闭窗口,则提示完毕后自动关闭窗口 + if ($this->get('closeWin')) $this->assign('jumpUrl', 'javascript:window.close();'); + $this->assign('status', $status); // 状态 + //保证输出不受静态缓存影响 + C('HTML_CACHE_ON', false); + if ($status) { //发送成功信息 + $this->assign('success_message', $message);// 提示信息 + // 成功操作后默认停留1秒 + if (!isset($this->waitSecond)) $this->assign('waitSecond', modC('SUCCESS_WAIT_TIME','2','config')); + // 默认操作成功自动返回操作前页面 + if (!isset($this->jumpUrl)) $this->assign("jumpUrl", $_SERVER["HTTP_REFERER"]); + $this->display(C('TMPL_ACTION_SUCCESS')); + exit; + } else { + $this->assign('error_message', $message);// 提示信息 + //发生错误时候默认停留3秒 + if (!isset($this->waitSecond)) $this->assign('waitSecond', modC('ERROR_WAIT_TIME','10','config')); + // 默认发生错误的话自动返回上页 + if (!isset($this->jumpUrl)) $this->assign('jumpUrl', "javascript:history.back(-1);"); + $this->display(C('TMPL_ACTION_ERROR')); + // 中止执行 避免出错后继续执行 + exit; + } + } + + /** + * 析构方法 + * @access public + */ + public function __destruct() + { + // 执行后续操作 + Hook::listen('action_end'); + } + + /** + * checkRule 检查权限 + * @author:xjw129xjt(肖骏涛) xjt@ourstu.com + */ + public function checkAuth($rule ='',$except_uid =-1,$msg = ''){ + if (!check_auth($rule,$except_uid)) { + $this->error(empty($msg)?'您无操作权限。':$msg); + } + } + + /** + * check_action_limit 行为限制 + * @param null $action + * @param null $model + * @param null $record_id + * @param null $user_id + * @param bool $ip + * @author 郑钟良 + */ + public function checkActionLimit($action = null, $model = null, $record_id = null, $user_id = null, $ip = false,$url = false){ + $return = check_action_limit($action, $model, $record_id, $user_id, $ip); + if ($return && !$return['state']) { + if($url === true){ + $url = $return['url']; + }elseif($url === false){ + $url = ''; + } + $this->error($return['info'],$url); + } + } + +} + +// 设置控制器别名 便于升级 class_alias('Think\Controller', 'Think\Action'); \ No newline at end of file diff --git a/index.php b/index.php index fa28e5511fb7c1164538f9034e93bb1733e1b50d..736a895a27a9046bf6259f3ab892dcd4c9b8f15c 100644 --- a/index.php +++ b/index.php @@ -1,83 +1,83 @@ - -// +---------------------------------------------------------------------- - -function reset_session_path() -{ - $root = str_replace("\\", '/', dirname(__FILE__)); - $savePath = $root . "/tmp/"; - if (!file_exists($savePath)) - @mkdir($savePath, 0777); - session_save_path($savePath); -} - -//reset_session_path(); //如果您的服务器无法安装或者无法登陆,又或者后台验证码无限错误,请尝试取消本行起始两条左斜杠,让本行代码生效,以修改session存储的路径 - - -if (version_compare(PHP_VERSION, '5.3.0', '<')) die('require PHP > 5.3.0 !'); - -/*移除magic_quotes_gpc参数影响*/ -if (get_magic_quotes_gpc()) { - function stripslashes_deep($value) - { - $value = is_array($value) ? array_map('stripslashes_deep', $value) : stripslashes($value); - return $value; - } - - $_POST = array_map('stripslashes_deep', $_POST); - $_GET = array_map('stripslashes_deep', $_GET); - $_COOKIE = array_map('stripslashes_deep', $_COOKIE); - $_REQUEST = array_map('stripslashes_deep', $_REQUEST); -} -/*移除magic_quotes_gpc参数影响end*/ - - - - -/** - * 系统调试设置 - * 项目正式部署后请设置为false - */ -define ('APP_DEBUG', true); - -define ('APP_PATH', './Application/'); - -/** - * 主题目录 OpenCenter模板地址 (与ThinkPHP中的THEME_PATH不同) - * @author 郑钟良 - */ -define ('OS_THEME_PATH', './Theme/'); - -if (!is_file( 'Conf/user.php')) { - header('Location: ./install.php'); - exit; -} - -/** - * 缓存目录设置 - * 此目录必须可写,建议移动到非WEB目录 - */ -define ('RUNTIME_PATH', './Runtime/'); - -/** - * 引入核心入口 - * ThinkPHP亦可移动到WEB以外的目录 - */ -try{ - require './ThinkPHP/ThinkPHP.php'; -}catch (\Exception $exception){ - if($exception->getCode()==815){ - send_http_status(404); - $string=file_get_contents('./404.html'); - $string=str_replace('$ERROR_MESSAGE',$exception->getMessage(),$string); - $string=str_replace('HTTP_HOST','http://'.$_SERVER['HTTP_HOST'],$string); - echo $string; - }else{ - E($exception->getMessage(),$exception->getCode()); - } -} + +// +---------------------------------------------------------------------- + +function reset_session_path() +{ + $root = str_replace("\\", '/', dirname(__FILE__)); + $savePath = $root . "/tmp/"; + if (!file_exists($savePath)) + @mkdir($savePath, 0777); + session_save_path($savePath); +} + +//reset_session_path(); //如果您的服务器无法安装或者无法登陆,又或者后台验证码无限错误,请尝试取消本行起始两条左斜杠,让本行代码生效,以修改session存储的路径 + + +if (version_compare(PHP_VERSION, '5.3.0', '<')) die('require PHP > 5.3.0 !'); + +/*移除magic_quotes_gpc参数影响*/ +if (get_magic_quotes_gpc()) { + function stripslashes_deep($value) + { + $value = is_array($value) ? array_map('stripslashes_deep', $value) : stripslashes($value); + return $value; + } + + $_POST = array_map('stripslashes_deep', $_POST); + $_GET = array_map('stripslashes_deep', $_GET); + $_COOKIE = array_map('stripslashes_deep', $_COOKIE); + $_REQUEST = array_map('stripslashes_deep', $_REQUEST); +} +/*移除magic_quotes_gpc参数影响end*/ + + + + +/** + * 系统调试设置 + * 项目正式部署后请设置为false + */ +define ('APP_DEBUG', true); + +define ('APP_PATH', './Application/'); +define ('ADMIN_NAME','XX后台管理系统');//命名后台管理系统名称 +/** + * 主题目录 OpenCenter模板地址 (与ThinkPHP中的THEME_PATH不同) + * @author 郑钟良 + */ +define ('OS_THEME_PATH', './Theme/'); + +if (!is_file( 'Conf/user.php')) { + header('Location: ./install.php'); + exit; +} + +/** + * 缓存目录设置 + * 此目录必须可写,建议移动到非WEB目录 + */ +define ('RUNTIME_PATH', './Runtime/'); + +/** + * 引入核心入口 + * ThinkPHP亦可移动到WEB以外的目录 + */ +try{ + require './ThinkPHP/ThinkPHP.php'; +}catch (\Exception $exception){ + if($exception->getCode()==815){ + send_http_status(404); + $string=file_get_contents('./404.html'); + $string=str_replace('$ERROR_MESSAGE',$exception->getMessage(),$string); + $string=str_replace('HTTP_HOST','http://'.$_SERVER['HTTP_HOST'],$string); + echo $string; + }else{ + E($exception->getMessage(),$exception->getCode()); + } +} \ No newline at end of file