PageRenderTime 46ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/b2b/core/include/adminPage.php

http://phpfor.googlecode.com/
PHP | 355 lines | 268 code | 44 blank | 43 comment | 38 complexity | b93e6b6306591f193e3d001552ce98ad MD5 | raw file
  1. <?php
  2. /**
  3. * pagefactory
  4. *
  5. * @package
  6. * @version $Id: adminPage.php 1903 2008-04-24 07:06:22Z ever $
  7. * @copyright 2003-2007 ShopEx
  8. * @author Wanglei <flaboy@zovatech.com>
  9. * @license Commercial
  10. */
  11. require('pageFactory.php');
  12. class adminPage extends pageFactory{
  13. var $__tmpl;
  14. var $pagedata;
  15. var $ajaxdata;
  16. var $pagePrompt = true;
  17. var $transaction_start = false;
  18. var $path = array();
  19. /**
  20. * pagefactory
  21. *
  22. * @access public
  23. * @return void
  24. */
  25. function adminPage(){
  26. $this->system = &$GLOBALS['system'];
  27. $smarty = &$this->system->loadModel('system/frontend');
  28. $smarty->ctl = &$this;
  29. array_unshift($smarty->plugins_dir,CORE_DIR.'/admin/smartyplugin');
  30. $smarty->default_resource_type = 'admin';
  31. $this->message = &$_SESSION['message'];
  32. $this->in = &$this->system->incomming();
  33. $this->pagedata=array();
  34. if(DEBUG_TEMPLETE){
  35. $o = $this->system->loadModel('system/template');
  36. $theme=$this->system->getConf('system.ui.current_theme');
  37. $o->resetTheme($theme);
  38. }
  39. if($_GET['_ajax']){
  40. if(!defined('IN_AJAX')){
  41. define('IN_AJAX',true);
  42. $this->ajaxdata=array();
  43. ob_start();
  44. }
  45. }else{
  46. define('IN_AJAX',false);
  47. }
  48. if($_GET['ctl']!='passport'){
  49. //??shopex???
  50. $Certi=$this->system->loadModel('service/certificate');
  51. /* ???? by yangbing 2012-2-6
  52. if(!$Certi->getCerti() && (!$Certi->getIdentifier() || !$Certi->getPassword())) {
  53. $this->notAuth('noaccount');
  54. }*/
  55. if(!$_SESSION['profile'] || $this->system->session->isNotlocked()){
  56. $this->notAuth();
  57. }else{
  58. $this->op = &$_SESSION['profile'];
  59. //echo "<pre>";
  60. //error_log(print_r($this->op->system->_in,true),3,"D:/2.txt");
  61. $oOpt = &$this->system->loadModel('admin/operator','config');
  62. $data = $oOpt->instance($this->op->opid);
  63. if(!$this->op->is_super && !$oOpt->check_role($this->op->opid,$this->workground,$this->op->system->request)){
  64. $this->system->responseCode(403);
  65. exit;
  66. }
  67. $GLOBALS['op'] = &$this->op;
  68. $config = unserialize($data['config']);
  69. if(isset($config['timezone'])){
  70. $GLOBALS['user_timezone'] = $config['timezone'];
  71. }else{
  72. $GLOBALS['user_timezone'] = $this->system->getConf('system.timezone.default');
  73. }
  74. }
  75. }
  76. }
  77. function notAuth($type=null,$return=null){
  78. if(IN_AJAX){
  79. $this->system->responseCode(401);
  80. exit();
  81. }else{
  82. if($type=='noaccount'){
  83. echo $url = 'index.php?ctl=passport&act=loginaccount';exit;
  84. }else{
  85. $url = 'index.php?ctl=passport&act=login';
  86. }
  87. $output =<<<EOF
  88. <script>
  89. var href = top.location.href;
  90. var pos = href.indexOf('#') + 1;
  91. window.location.href="$url"+(pos ? ('&return='+encodeURIComponent(href.substr(pos))) : '');
  92. </script>
  93. EOF;
  94. echo $output;
  95. exit();
  96. }
  97. }
  98. function runTemplete(){
  99. /*- templete-begin -*/
  100. $data = Array('bG9naW4uaHRtbA=='=>'0477f6fd13e73d8567f5e140491d836f',
  101. 'ZGFzaGJvYXJkLmh0bWw='=>'328e2e1c3778566153a4c32eabc3317c',
  102. 'aW5kZXguaHRtbA=='=>'c9fb707e2f1e6daf6cb8add62317f473',
  103. 'c3lzdGVtL3Rvb2xzL2Fib3V0Lmh0bWw='=>'0ff7ff4fd1d69b39c9581c74d15ac9a3',
  104. );
  105. /*- templete-end -*/
  106. return $data;
  107. }
  108. function output(){
  109. $output = &$this->system->loadModel('system/frontend');
  110. $output->clear_all_assign();
  111. if($this->pagedata){
  112. foreach ($this->pagedata as $key=>$data){
  113. $output->assign($key,$data);
  114. }
  115. }
  116. header('Content-Type: text/html;charset=utf-8');
  117. $display = $output->fetch($this->__tmpl);
  118. $this->display($display);
  119. }
  120. function page($view,$onePage=false){
  121. if(!isset($_GET['_ajax'])){
  122. header('Location: index.php#'.$_SERVER['QUERY_STRING']);
  123. }
  124. $this->pagedata['_PAGE_'] = $view;
  125. $this->pagedata['_inurl'] = ($p = strpos($_SERVER['REQUEST_URI'],'&_ajax='))?substr($_SERVER['REQUEST_URI'],0,$p):$_SERVER['REQUEST_URI'];
  126. $this->pagedata['_ONE_PAGE_'] = $onePage;
  127. $smarty = &$this->system->loadModel('system/frontend');
  128. $smarty->clear_all_assign();
  129. $smarty->assign('message',$this->message);
  130. $this->message='';
  131. $this->pagedata['_path_'] = $this->path;
  132. if($this->pagedata){
  133. foreach ($this->pagedata as $key=>$data){
  134. $smarty->assign($key,$data);
  135. }
  136. }
  137. $output = $smarty->fetch('page.html');
  138. //print_r($_GET['ctl']);exit;
  139. if(!isset($this->workground)){
  140. if($p = strpos('/',$_GET['ctl'])){
  141. }else{
  142. $this->workground = substr(get_class($this),4);
  143. }
  144. }
  145. if($_GET['_wg']!=$this->workground && $this->workground){
  146. $smarty->clear_all_assign();
  147. //$new_workground = $_GET['ctl'].'-'.$_GET['act'];
  148. //print_r($this->workground);exit;
  149. $menus = $this->op->getMenu($this->workground,$this->op->is_super);
  150. $trees = array();
  151. foreach($menus as $k=>$m){
  152. if($m['type']=='tree'){
  153. $o = $this->system->loadModel($menus[$k]['model']);
  154. $menus[$k] = array_merge($menus[$k], $o->treeOptions());
  155. $trees[] = array('model'=>$menus[$k]['model'],'actions'=>json_encode($menus[$k]['actions']));
  156. $menus[$k]['items'] = $o->getNodes();
  157. unset($o,$opt);
  158. }
  159. }
  160. $smarty->assign('trees',$trees);
  161. $smarty->assign('menus',$menus);
  162. $smarty->assign('workground',$this->workground);
  163. $output .= $smarty->fetch('sidemenu.html');
  164. }
  165. $this->display($output);
  166. }
  167. function display(&$output){
  168. $etag = crc32($output);
  169. header("Cache-Control:no-store, no-cache, must-revalidate"); // HTTP/1.1
  170. header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");// ????etag
  171. header('Etag: '.$etag);
  172. header('Progma: no-cache');
  173. if(isset($_SERVER['HTTP_IF_NONE_MATCH']) && ($_SERVER['HTTP_IF_NONE_MATCH'] == $etag)){
  174. header('HTTP/1.1 304 Not Modified',true,304);
  175. exit(0);
  176. }else{
  177. header('Content-Type: text/html; charset=utf-8');
  178. echo $output;
  179. }
  180. exit(0);
  181. }
  182. function splash($status='success',$jumpto=null,$msg='????',$errinfo=array(),$wait=3,$js=null){
  183. header("Cache-Control:no-store, no-cache, must-revalidate"); // HTTP/1.1
  184. header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");// ????etag
  185. header('Progma: no-cache');
  186. if(!$msg){
  187. $msg = __('????');
  188. }
  189. if($_FILES){
  190. header('Content-Type: text/html; charset=utf-8');
  191. if ($errinfo['fenxiao_success']) {
  192. echo "<script>parent.W.page.bind(parent.W)('index.php?ctl=supplier/fenxiao&act=showSuccess',{method:'post',data:'show=1'});</script>";
  193. }else{
  194. echo '<script>parent.W.page.bind(parent.W)("index.php?ctl=default&act=uploadSplash",{method:"post",update:parent.upload_rs_el,data:'.json_encode(func_get_args()).'});</script>';
  195. }
  196. }else{
  197. $this->pagedata['status'] = $status;
  198. $this->pagedata['msg'] = $msg;
  199. $this->pagedata['jscript'] = $js;
  200. $this->pagedata['errinfo'] = $errinfo;
  201. $this->pagedata['jumpto'] = $jumpto;
  202. $this->pagedata['wait'] = $status=='success'?0.2:10;
  203. $this->pagedata['debug_code'] = defined('DEBUG_CODE')?DEBUG_CODE:false;
  204. $err_valve = (defined('DEBUG_CODE')?DEBUG_CODE:false)?0:1;
  205. if(count($this->system->_err)>$err_valve){
  206. $this->pagedata['error_info'] = $this->system->_err;
  207. }
  208. // if($_REQUEST['inContent']=='true'){
  209. $this->setview('splash/'.$status.'.html');
  210. $this->output();
  211. // }else{
  212. // $this->page('splash/'.$status.'.html');
  213. // }
  214. }
  215. }
  216. /**
  217. * jump_to
  218. *
  219. * @param string $act
  220. * @param string $ctl
  221. * @param array $args
  222. * @access public
  223. * @return void
  224. */
  225. function jumpTo($act='index',$ctl=null,$args=null){
  226. $_GET['act'] = $act;
  227. if($ctl) $_GET['ctl'] = $ctl;
  228. if($args) $_GET['p'] = $args;
  229. if(!is_null($ctl)){
  230. if($pos=strpos($_GET['ctl'],'/')){
  231. $domain = substr($_GET['ctl'],0,$pos);
  232. }else{
  233. $domain = $_GET['ctl'];
  234. }
  235. $this->system->set_mo_pkg($domain);
  236. $ctl = &$this->system->getController($ctl);
  237. $ctl->message = $this->message;
  238. $ctl->pagedata = &$this->pagedata;
  239. $ctl->ajaxdata = &$this->ajaxdata;
  240. $this->system->callAction($ctl,$act,$args);
  241. }else{
  242. $this->system->callAction($this,$act,$args);
  243. }
  244. }
  245. function begin($url=null,$errAction=null,$shutHandle=null){
  246. set_error_handler(array(&$this,'_errorHandler'));
  247. if($this->transaction_start) trigger_error('The transaction has been started',E_USER_ERROR);
  248. if(!$url)trigger_error('The transaction has been started',E_USER_ERROR);
  249. $this->transaction_start = true;
  250. $this->_shutHandle = $shutHandle?$shutHandle:(E_USER_ERROR | E_ERROR);
  251. $this->_action_url = $url;
  252. $this->_errAction = $errAction;
  253. $this->_err = array();
  254. }
  255. function end($result=true,$message=null,$url=null,$showNotice=false){
  256. if(!$this->transaction_start) trigger_error('The transaction has not started yet',E_USER_ERROR);
  257. $this->transaction_start = false;
  258. restore_error_handler();
  259. if(is_null($url)){
  260. $url = $this->_action_url;
  261. }
  262. if($result){
  263. $status = "success";
  264. $message = ($message=='' ? __('?????') : __('?????').$message);
  265. }else{
  266. $status = "failed";
  267. $message = __("????: ???,??????????");
  268. }
  269. $this->splash($status,$url,$message,$showNotice?$this->_err:null);
  270. }
  271. function end_only(){
  272. if(!$this->transaction_start) trigger_error('The transaction has not started yet',E_USER_ERROR);
  273. $this->transaction_start = false;
  274. restore_error_handler();
  275. }
  276. function setError($errorno=0,$jumpto='back',$msg='',$links=array(),$time=3,$js=null){
  277. $this->system->ErrorSet = array('errorno'=>$errorno,'message'=>$msg,'jumpto'=>$jumpto,'links'=>$links,'time'=>$time,'js'=>$js);
  278. }
  279. function _errorHandler($errno, $errstr, $errfile, $errline){
  280. $errorlevels = array(
  281. 2048 => 'Notice',
  282. 1024 => 'Notice',
  283. 512 => 'Warning',
  284. 256 => 'Error',
  285. 128 => 'Warning',
  286. 64 => 'Error',
  287. 32 => 'Warning',
  288. 16 => 'Error',
  289. 8 => 'Notice',
  290. 4 => 'Error',
  291. 2 => 'Warning',
  292. 1 => 'Error');
  293. $this->_err[] = array('code'=>$errno, 'string'=>$errstr, 'file'=>$errfile, 'line'=>$errline,'codeinfo'=>$errorlevels[$errno]);
  294. if(isset($this->system->ErrorSet['errorno']) && isset($this->_errAction[$this->system->ErrorSet['errorno']])){
  295. $this->splash('failed',$this->_errAction[$this->system->ErrorSet['errorno']],$errstr);
  296. }else{
  297. switch($errno){
  298. case $errno & ( E_NOTICE | E_USER_NOTICE | E_WARNING):
  299. break;
  300. case $errno & ( $this->_shutHandle ):
  301. restore_error_handler();
  302. $this->splash('failed',$this->_action_url,'&nbsp;'.$errstr,$this->_err);
  303. /*default:
  304. restore_error_handler();
  305. $this->splash('failed',$this->_action_url,$errstr,$this->_err);*/
  306. }
  307. }
  308. return true;
  309. }
  310. }
  311. ?>