AdminbaseController.class.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. <?php
  2. /**
  3. * 洛阳赤炎鹰网络科技有限公司
  4. * https://www.cyyvip.com
  5. * Copyright (c) 2022 赤店商城 All rights reserved.
  6. */
  7. namespace Common\Controller;
  8. use Common\Controller\AppframeController;
  9. class AdminbaseController extends AppframeController {
  10. public function __construct() {
  11. $admintpl_path=C("SP_ADMIN_TMPL_PATH").C("SP_ADMIN_DEFAULT_THEME")."/";
  12. C("TMPL_ACTION_SUCCESS",$admintpl_path.C("SP_ADMIN_TMPL_ACTION_SUCCESS"));
  13. C("TMPL_ACTION_ERROR",$admintpl_path.C("SP_ADMIN_TMPL_ACTION_ERROR"));
  14. parent::__construct();
  15. $time=time();
  16. $this->assign("js_debug",APP_DEBUG?"?v=$time":"");
  17. }
  18. function _initialize(){
  19. parent::_initialize();
  20. $this->load_app_admin_menu_lang();
  21. if(isset($_SESSION['ADMIN_ID'])){
  22. $users_obj= M("Users");
  23. $id=$_SESSION['ADMIN_ID'];
  24. $user=$users_obj->where("id=$id")->find();
  25. if(!$this->check_access($id)){
  26. $this->error("您没有访问权限!");
  27. exit();
  28. }
  29. $this->assign("admin",$user);
  30. }else{
  31. //$this->error("您还没有登录!",U("admin/public/login"));
  32. if(IS_AJAX){
  33. $this->error("您还没有登录!",U("admin/public/login"));
  34. }else{
  35. header("Location:".U("admin/public/login"));
  36. exit();
  37. }
  38. }
  39. }
  40. /**
  41. * 初始化后台菜单
  42. */
  43. public function initMenu() {
  44. $Menu = F("Menu");
  45. if (!$Menu) {
  46. $Menu=D("Common/Menu")->menu_cache();
  47. }
  48. return $Menu;
  49. }
  50. /**
  51. * 消息提示
  52. * @param type $message
  53. * @param type $jumpUrl
  54. * @param type $ajax
  55. */
  56. public function success($message = '', $jumpUrl = '', $ajax = false) {
  57. parent::success($message, $jumpUrl, $ajax);
  58. }
  59. /**
  60. * 模板显示
  61. * @param type $templateFile 指定要调用的模板文件
  62. * @param type $charset 输出编码
  63. * @param type $contentType 输出类型
  64. * @param string $content 输出内容
  65. * 此方法作用在于实现后台模板直接存放在各自项目目录下。例如Admin项目的后台模板,直接存放在Admin/Tpl/目录下
  66. */
  67. public function display($templateFile = '', $charset = '', $contentType = '', $content = '', $prefix = '') {
  68. parent::display($this->parseTemplate($templateFile), $charset, $contentType);
  69. }
  70. /**
  71. * 获取输出页面内容
  72. * 调用内置的模板引擎fetch方法,
  73. * @access protected
  74. * @param string $templateFile 指定要调用的模板文件
  75. * 默认为空 由系统自动定位模板文件
  76. * @param string $content 模板输出内容
  77. * @param string $prefix 模板缓存前缀*
  78. * @return string
  79. */
  80. public function fetch($templateFile='',$content='',$prefix=''){
  81. $templateFile = empty($content)?$this->parseTemplate($templateFile):'';
  82. return parent::fetch($templateFile,$content,$prefix);
  83. }
  84. /**
  85. * 自动定位模板文件
  86. * @access protected
  87. * @param string $template 模板文件规则
  88. * @return string
  89. */
  90. public function parseTemplate($template='') {
  91. $tmpl_path=C("SP_ADMIN_TMPL_PATH");
  92. define("SP_TMPL_PATH", $tmpl_path);
  93. // 获取当前主题名称
  94. $theme = C('SP_ADMIN_DEFAULT_THEME');
  95. if(is_file($template)) {
  96. // 获取当前主题的模版路径
  97. define('THEME_PATH', $tmpl_path.$theme."/");
  98. return $template;
  99. }
  100. $depr = C('TMPL_FILE_DEPR');
  101. $template = str_replace(':', $depr, $template);
  102. // 获取当前模块
  103. $module = MODULE_NAME."/";
  104. if(strpos($template,'@')){ // 跨模块调用模版文件
  105. list($module,$template) = explode('@',$template);
  106. }
  107. // 获取当前主题的模版路径
  108. define('THEME_PATH', $tmpl_path.$theme."/");
  109. // 分析模板文件规则
  110. if('' == $template) {
  111. // 如果模板文件名为空 按照默认规则定位
  112. $template = CONTROLLER_NAME . $depr . ACTION_NAME;
  113. }elseif(false === strpos($template, '/')){
  114. $template = CONTROLLER_NAME . $depr . $template;
  115. }
  116. C("TMPL_PARSE_STRING.__TMPL__",__ROOT__."/".THEME_PATH);
  117. C('SP_VIEW_PATH',$tmpl_path);
  118. C('DEFAULT_THEME',$theme);
  119. define("SP_CURRENT_THEME", $theme);
  120. $file = sp_add_template_file_suffix(THEME_PATH.$module.$template);
  121. $file= str_replace("//",'/',$file);
  122. if(!file_exists_case($file)) E(L('_TEMPLATE_NOT_EXIST_').':'.$file);
  123. return $file;
  124. }
  125. /**
  126. * 排序 排序字段为listorders数组 POST 排序字段为:listorder
  127. */
  128. protected function _listorders($model) {
  129. if (!is_object($model)) {
  130. return false;
  131. }
  132. $pk = $model->getPk(); //获取主键名称
  133. $ids = $_POST['listorders'];
  134. foreach ($ids as $key => $r) {
  135. $data['listorder'] = $r;
  136. $model->where(array($pk => $key))->save($data);
  137. }
  138. return true;
  139. }
  140. /**
  141. * 后台分页
  142. *
  143. */
  144. protected function page($total_size = 1, $page_size = 0, $current_page = 1, $listRows = 6, $pageParam = '', $pageLink = '', $static = FALSE) {
  145. if ($page_size == 0) {
  146. $page_size = C("PAGE_LISTROWS");
  147. }
  148. if (empty($pageParam)) {
  149. $pageParam = C("VAR_PAGE");
  150. }
  151. $Page = new \Page($total_size, $page_size, $current_page, $listRows, $pageParam, $pageLink, $static);
  152. $Page->SetPager('Admin', '{first}{prev}&nbsp;{liststart}{list}{listend}&nbsp;{next}{last}', array("listlong" => "9", "first" => "首页", "last" => "尾页", "prev" => "上一页", "next" => "下一页", "list" => "*", "disabledclass" => ""));
  153. return $Page;
  154. }
  155. private function check_access($uid){
  156. //如果用户角色是1,则无需判断
  157. if($uid == 1){
  158. return true;
  159. }
  160. $rule=MODULE_NAME.CONTROLLER_NAME.ACTION_NAME;
  161. $no_need_check_rules=array("AdminIndexindex","AdminMainindex");
  162. if( !in_array($rule,$no_need_check_rules) ){
  163. return sp_auth_check($uid);
  164. }else{
  165. return true;
  166. }
  167. }
  168. private function load_app_admin_menu_lang(){
  169. if (C('LANG_SWITCH_ON',null,false)){
  170. $admin_menu_lang_file=SPAPP.MODULE_NAME."/Lang/".LANG_SET."/admin_menu.php";
  171. if(is_file($admin_menu_lang_file)){
  172. $lang=include $admin_menu_lang_file;
  173. L($lang);
  174. }
  175. }
  176. }
  177. }