PageRenderTime 40ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/new88li/core/include/adminCore.php

http://phpfor.googlecode.com/
PHP | 237 lines | 200 code | 27 blank | 10 comment | 34 complexity | c47a00d7abd4b6ec04eee2b7cdc3e80d MD5 | raw file
  1. <?php
  2. require(CORE_DIR.'/kernel.php');
  3. require(CORE_DIR.'/func_ext.php');
  4. class adminCore extends kernel{
  5. var $_base_url;
  6. var $_err = array();
  7. var $ErrorSet = array();
  8. var $op_id = false;
  9. var $op_is_super = null;
  10. var $op_is_disabled = null;
  11. var $_op_config_modified = false;
  12. var $__old_session_str = null;
  13. function adminCore(){
  14. define('PHP_SELF',dirname($_SERVER['PHP_SELF'] ? $_SERVER['PHP_SELF'] : $_SERVER['SCRIPT_NAME']));
  15. parent::kernel();
  16. if(file_exists(BASE_DIR.'/upgrade.php')){
  17. $upgrade = $this->loadModel('system/upgrade');
  18. $upgrade->exec($_GET['act']);
  19. }elseif($_POST['api_url'] == 'time_auth'){
  20. header("Content-type:text/html;charset=utf-8");
  21. $this->shopex_auth=$this->loadModel('service/certificate');
  22. if($this->shopex_auth->check_api()){
  23. require(CORE_INCLUDE_DIR.'/shop/core.time_auth.php');
  24. core_time_auth($this);
  25. exit;
  26. }
  27. }else{
  28. define('__ADMIN__','admin');
  29. require('adminPage.php');
  30. $mod = $_GET['ctl']?$_GET['ctl']:'default';
  31. $act = $_GET['act']?$_GET['act']:'index';
  32. $this->request = array('action'=>array('controller'=>$mod,'method'=>$act));
  33. $this->request['action']['ident'] = strtolower('admin:'.
  34. $this->request['action']['controller'].
  35. ':'.$this->request['action']['method']);
  36. $this->db = &$this->database();
  37. $this->__session_start();
  38. if($_POST['_DTYPE_DATE']){
  39. foreach($_POST['_DTYPE_DATE'] as $k){
  40. $_POST[$k] = empty($_POST[$k])?$_POST[$k]:strtotime($_POST[$k]); //php4?php5?strtotime('')????????????
  41. }
  42. $_POST['_DTYPE_DATE'] = null;
  43. unset($_POST['_DTYPE_DATE']);
  44. }
  45. if($_POST['_DTYPE_BOOL']){
  46. foreach($_POST['_DTYPE_BOOL'] as $k){
  47. $_POST[$k] = $_POST[$k]!='false';
  48. }
  49. $_POST['_DTYPE_BOOL'] = null;
  50. unset($_POST['_DTYPE_BOOL']);
  51. }
  52. if($_POST['_DTYPE_TIME']){
  53. foreach($_POST['_DTYPE_TIME'] as $k){
  54. if($_POST[$k]){
  55. $_POST[$k] = empty($_POST[$k])?$_POST[$k]:strtotime($_POST[$k]); //php4?php5?strtotime('')????????????
  56. if(isset($_POST['_DTIME_']['H'][$k])){
  57. $_POST[$k]+=$_POST['_DTIME_']['H'][$k]*3600+$_POST['_DTIME_']['M'][$k]*60;
  58. }
  59. }
  60. unset($_POST['_DTIME_']['H'][$k],$_POST['_DTIME_']['M'][$k]);
  61. }
  62. $_POST['_DTYPE_TIME'] = null;
  63. unset($_POST['_DTYPE_TIME']);
  64. }
  65. /* foreach($_POST['_DTIME_']['H'] as $t=>$h){
  66. $_POST[$k] .= $h.':'.$_POST['_DTIME_']['M'][$t];
  67. }*/
  68. unset($_POST['_DTIME_']);
  69. $controller = &$this->getController($mod);
  70. $this->ctl = &$controller;
  71. if(!is_object($controller)){
  72. $this->responseCode(404);
  73. exit();
  74. }
  75. if(!$this->callAction($controller,$act,$_GET['p'])){
  76. $this->responseCode(404);
  77. exit();
  78. }
  79. }
  80. }
  81. function __session_start(){
  82. if(isset($_GET['sess_id'])){
  83. $this->sess_id = $_GET['sess_id'];
  84. if($_COOKIE['SHOPEX_SID']!=$_GET['sess_id'])
  85. setcookie('SHOPEX_SID',$this->sess_id);
  86. }elseif($_COOKIE['SHOPEX_SID']){
  87. $this->sess_id = $_COOKIE['SHOPEX_SID'];
  88. }else{
  89. $this->sess_id = md5(microtime().remote_addr().mt_rand(0,9999));
  90. setcookie('SHOPEX_SID',$this->sess_id);
  91. }
  92. if(!($row = $this->db->selectrow('SELECT s.op_id,s.sess_data,o.name,o.username,o.super,o.status,o.disabled,o.config
  93. FROM sdb_op_sessions s
  94. left join sdb_operators o
  95. on o.op_id = s.op_id
  96. WHERE s.sess_id = \''.$this->sess_id.'\'',true,true))
  97. || !($_SESSION = unserialize($row['sess_data'])) ){
  98. $_SESSION = array();
  99. }else{
  100. $this->__old_session_str = md5($row['sess_data']);
  101. }
  102. if($row['op_id']){
  103. $this->op_id = $row['op_id'];
  104. $this->op_is_super = $row['super'];
  105. $this->op_name = $row['name']?$row['name']:$row['username'];
  106. $this->op_is_disabled = ( $row['disabled']=='true' || $row['status']!=1 );
  107. if($row['brand_id']){// ?????????? 2012-2-13
  108. define('OP_BRAND_ID',$row['brand_id']);
  109. }
  110. if(($this->op_config = unserialize($row['config'])) && isset($this->op_config['timezone'])){
  111. $GLOBALS['user_timezone'] = $this->op_config['timezone'];
  112. }else{
  113. $GLOBALS['user_timezone'] = $this->getConf('system.timezone.default');
  114. }
  115. }
  116. register_shutdown_function(array(&$this,'__session_close'));
  117. }
  118. function __session_close($writeBack = true){
  119. if($this->__session_closed){
  120. return;
  121. }
  122. $this->__session_closed = true;
  123. if(!$writeBack){
  124. return;
  125. }
  126. if($this->_op_config_modified && $this->op_id){
  127. $aRs = $this->db->exec('select config from sdb_operators where op_id='.intval($this->op_id));
  128. $sql = $this->db->GetUpdateSql($aRs,array('config'=>$this->op_config));
  129. if($sql){
  130. $this->db->exec($sql,true,true);
  131. }
  132. }
  133. $aRs = $this->db->exec("SELECT * FROM sdb_op_sessions WHERE sess_id='".$this->sess_id."'",true,true);
  134. if($this->op_id){
  135. $status = 1;
  136. }else{
  137. $status = 0;
  138. }
  139. $sess = serialize($_SESSION);
  140. $aTemp = array(
  141. 'sess_id'=>$this->sess_id,
  142. 'op_id'=>$this->op_id+0,
  143. 'last_time'=>time(),
  144. 'sess_data'=>$sess,
  145. 'status'=>$status,
  146. 'ip'=>remote_addr(),
  147. );
  148. if($this->__old_session_str == md5($sess)){
  149. unset($aTemp['sess_data']);
  150. }
  151. $sess=null;
  152. unset($sess);
  153. $sql = $this->db->GetUpdateSql($aRs,$aTemp,true);
  154. if(!$sql || $this->db->exec($sql,true,true)){
  155. return true;
  156. }else{
  157. return false;
  158. }
  159. }
  160. function setExpries($time){;}
  161. /**
  162. * &getController
  163. *
  164. * @param mixed $mod
  165. * @access public
  166. * @return void
  167. */
  168. function &getController($mod,$args=null){
  169. if(!class_exists('pageFactory')){
  170. require('pageFactory.php');
  171. }
  172. $baseName = basename($mod,$args);
  173. $dirName = dirname($mod);
  174. if($dirName=='plugins'){
  175. $addon = &$this->loadModel('system/addons');
  176. $object = &$addon->load($baseName,'admin');
  177. $object->template_dir = dirname($object->plugin_path).'/';
  178. $object->db = &$this->database();
  179. }else{
  180. if (defined('CUSTOM_CORE_DIR') && file_exists($cusfname = CUSTOM_CORE_DIR.'/'.__ADMIN__.'/controller/'.$dirName.'/cct.'.$baseName.'.php')){
  181. $fname = $cusfname;
  182. $mod_name='cct_'.$baseName;
  183. }else{
  184. $fname = CORE_DIR.'/admin/controller/'.$dirName.'/ctl.'.$baseName.'.php';
  185. $mod_name = 'ctl_'.$baseName;
  186. }
  187. $loaded = @require($fname);
  188. if(!$loaded)
  189. return false;
  190. $object = new $mod_name($this);
  191. }
  192. $object->system = &$this;
  193. $object->controller = $mod;
  194. return $object;
  195. }
  196. function get_op_conf($key){
  197. return $this->op_config[$key];
  198. }
  199. function set_op_conf($key,$value){
  200. $this->op_config[$key] = $value;
  201. $this->_op_config_modified = true;
  202. }
  203. function mkUrl(){
  204. return 'javascript:void(0);';
  205. }
  206. function sfile($file,$file_bak=null,$use=false){
  207. $this->__session_close();
  208. parent::sfile($file,$file_bak,$use);
  209. }
  210. }