PageRenderTime 53ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/trunk/demo/ucenter/Lib/Action/InitController.class.php

http://mycaptain.googlecode.com/
PHP | 570 lines | 280 code | 189 blank | 101 comment | 35 complexity | 6c0615c647c7ec9841ecf67e16ddd1f3 MD5 | raw file
  1. <?php
  2. /**
  3. // DoYouHaoBaby-X Ucenter ( DoYouHaoBaby-X ?? )
  4. // +---------------------------------------------------------------------
  5. //
  6. // “Copyright”
  7. // +---------------------------------------------------------------------
  8. // | (C) 2010 - 2011 http://doyouhaobaby.net All rights reserved.
  9. // | This is not a free software, use is subject to license terms
  10. // +---------------------------------------------------------------------
  11. //
  12. // “About This File”
  13. // +---------------------------------------------------------------------
  14. // | Ucenter ?????
  15. // +---------------------------------------------------------------------
  16. */
  17. !defined( 'DYHB_PATH' ) && exit;
  18. class InitController extends Controller{
  19. /**
  20. * ??????
  21. *
  22. * @var array
  23. */
  24. public $_arrOptions = array();
  25. /**
  26. * ????
  27. */
  28. public function __construct( ){
  29. parent::__construct();
  30. // ????????
  31. $arrOptions = OptionModel::optionData( );
  32. if( $arrOptions===false ){
  33. $this->E( G::L( '??????????????????????????' ) );
  34. }
  35. $this->_arrOptions = $arrOptions;
  36. }
  37. /**
  38. * ??????
  39. */
  40. public function init__( ){
  41. // ???????????
  42. UserModel::M()->authData( );
  43. if( UserModel::M()->isBehaviorError() ){// ????
  44. $this->E ( UserModel::M()->getBehaviorErrorMessage() );
  45. }
  46. // ??Rbac??
  47. UserModel::M()->checkRbac( );
  48. // ????Rbac???????
  49. if( UserModel::M()->isBehaviorError() ){
  50. $this->E ( UserModel::M()->getBehaviorErrorMessage() );
  51. }
  52. }
  53. /**
  54. * ????
  55. */
  56. public function index( ) {
  57. // ????Map??
  58. $arrMap = $this->map( );
  59. // ??????????
  60. // ??????????
  61. if ( method_exists ( $this, 'filter_' ) ) {
  62. $this->filter_ ( $arrMap );
  63. }
  64. $sModel = ucfirst( MODULE_NAME ).'Model';
  65. $oSelect = '';
  66. eval( '$oSelect = '.$sModel.'::F( );' );
  67. // ????????
  68. $this->get_list( $oSelect,$arrMap );
  69. $this->display ();
  70. }
  71. /**
  72. * ??????
  73. */
  74. protected function map( $sName = '' ) {
  75. // ??????
  76. if ( empty ( $sName ) ) {
  77. $sName = MODULE_NAME;
  78. }
  79. $sName = ucfirst( $sName ).'Model';
  80. // ????????????
  81. $arrField =array();
  82. eval( '$arrField = '.$sName.'::M( )->_arrFieldToProp;' );
  83. $arrMap = array ();
  84. foreach ( $arrField as $sField => $sProp ) {
  85. if ( isset ( $_REQUEST [ $sField ] ) &&
  86. !empty( $_REQUEST [ $sField ] ) ) {
  87. $arrMap[ $sField ] = $_REQUEST [ $sField ];
  88. }
  89. }
  90. return $arrMap;
  91. }
  92. /**
  93. * ????????
  94. */
  95. protected function get_list( $oSelect,$arrMap ){
  96. // ?????
  97. $sParameter='';
  98. $sSortUrl='';
  99. $sName = MODULE_NAME;
  100. // ??????
  101. $nTotalRecord = $oSelect->where( $arrMap )->all()->getCount( );
  102. // ??????
  103. $nEverynum = $this->_arrOptions['admineverynum'];
  104. // ?????????????/
  105. foreach ( $arrMap as $sKey => $sVal ) {
  106. if ( !is_array ( $sVal ) ) {
  107. $sParameter .= $sKey.'=' . urlencode ( $sVal ) .'&';
  108. $sSortUrl .= '/'.$sKey.'/' . urlencode ( $sVal );
  109. }
  110. }
  111. // ????
  112. $sSortBy = strtoupper( Safe::getGpc( 'sort_' ) ) == 'ASC' ? 'ASC' :'DESC' ;
  113. $sOrder = Safe::getGpc( 'order_' ) ? Safe::getGpc( 'order_' ) : $sName.'_id';
  114. $this->assign( 'sSortByUrl', $sSortBy == 'DESC'? 'ASC' : 'DESC' );
  115. $this->assign( 'sSortByDescription',$sSortBy == 'DESC' ? G::L( '??') : G::L( '??' ) );
  116. $this->assign( 'sOrder',$sOrder );
  117. $this->assign( 'sSortUrl',__ACTION__.$sSortUrl);
  118. // ?????
  119. $oPage = Page::RUN( $nTotalRecord,$nEverynum, Safe::getGpc( G::C('PAGE_VAR_NAME') ) );
  120. $oPage->setParameter ( $sParameter );
  121. $sPageNavbar = $oPage->P( );
  122. // ??????
  123. $arrList = $oSelect
  124. ->where( $arrMap )
  125. ->all()
  126. ->order( $sOrder.' '.$sSortBy )
  127. ->limit( $oPage->returnPageStart( ), $nEverynum )
  128. ->asArray()
  129. ->query();
  130. $this->assign( 'sPageNavbar',$sPageNavbar );
  131. $this->assign( 'arrList',$arrList );
  132. }
  133. /**
  134. * Ajax???????
  135. */
  136. public function input_change_ajax( ){
  137. $sModel = MODULE_NAME;
  138. $oModelMeta = null;
  139. eval( '$oModelMeta = '.ucwords( $sModel ).'Model::M( );' );
  140. $sPk = reset( $oModelMeta->_arrIdName );
  141. $nInputAjaxId = Safe::getGpc( 'input_ajax_id' );
  142. $sInputAjaxField = Safe::getGpc( 'input_ajax_field' );
  143. $sInputAjaxVal = Safe::getGpc( 'input_ajax_val' );
  144. $arrData = array(
  145. $sPk => $nInputAjaxId,
  146. $sInputAjaxField => $sInputAjaxVal,
  147. );
  148. // badword ????
  149. if( $sModel =='badword' && $sInputAjaxField=='badword_find' ){
  150. $arrData['badword_findpattern']= '/'.$sInputAjaxVal.'/is';
  151. }
  152. if( $sInputAjaxField=='badword_find' ){
  153. $this->input_change_unique();
  154. }
  155. $oModelMeta->updateDbWhere( $arrData );
  156. // ????Meta?????????????
  157. if( $oModelMeta->isError( ) ){
  158. $this->E( $oModelMeta->getErrorMessage() );
  159. }
  160. else{
  161. $arrVo = array(
  162. 'id' => $sInputAjaxField.'_'.$nInputAjaxId,
  163. 'value' => $sInputAjaxVal,
  164. );
  165. $this->A( $arrVo, G::L( '???????') );
  166. }
  167. }
  168. /**
  169. * ?????( Ajax???? )
  170. */
  171. public function input_change_unique( ){
  172. $sModel = ucfirst( MODULE_NAME );
  173. $oModelMeta = null;
  174. eval( '$oModelMeta = '.$sModel.'Model::M( );' );
  175. $nId = Safe::getGpc( 'input_ajax_id' );
  176. $sField = Safe::getGpc( 'input_ajax_field' );
  177. $sName = Safe::getGpc( 'input_ajax_val' );
  178. $sInfo = '';
  179. if( $nId ){
  180. $oModel = null;
  181. eval( '$oModel = '.$sModel.'Model::F( \''.MODULE_NAME.'_id=?\','.$nId.' )->query( );' );
  182. $arrInfo = $oModel->toArray();
  183. $sInfo = $arrInfo[ $sField ];
  184. }
  185. if( $sName != $sInfo ){
  186. $oSelect =null;
  187. eval( '$oSelect = '.$sModel.'Model::F( );' );
  188. $sFunc ='getBy'.$sField;
  189. $arrResult = $oSelect->{$sFunc}( $sName )->toArray();
  190. if( !empty( $arrResult[ $sField ] ) ) {
  191. $this->E( G::L( '?????????' ) );
  192. }
  193. }
  194. }
  195. /**
  196. * ?????
  197. */
  198. public function seccode( ){
  199. Safe::seccode( );
  200. }
  201. /**
  202. * ????????
  203. */
  204. public function insert( ){
  205. // ????
  206. $oModel = null;
  207. eval( '$oModel = new '.ucfirst( MODULE_NAME ).'Model( );' );
  208. // ????
  209. $oModel->save( );
  210. // ??????
  211. if( !$oModel->isError( ) ) {
  212. if( 'user'!==MODULE_NAME ){
  213. $this->A( $oModel->toArray( ),G::L( '???????' ),1 );
  214. }
  215. else{
  216. $arrUser = $oModel->toArray( );
  217. $nId = reset( $arrUser );
  218. $this->assign('__JumpUrl__', G::U( MODULE_NAME.'/edit?id='.$nId ) );
  219. $this->S( G::L( '???????' ) );
  220. }
  221. }
  222. else{
  223. $this->E( $oModel->getErrorMessage( ) );
  224. }
  225. }
  226. /**
  227. * ???????
  228. */
  229. public function edit( ){
  230. $nId = Safe::getGpc( 'id','G' );
  231. // ?????????
  232. if( !empty( $nId ) ) {
  233. $oModel = null;
  234. eval( '$oModel = '.ucfirst( MODULE_NAME ).'Model::F( \''.MODULE_NAME.'_id=?\','.$nId.' )->query( );' );
  235. if( $oModel ) {
  236. $this->assign( 'arrValue',$oModel->toArray() );
  237. $this->assign( 'nId',$nId );
  238. $this->display( MODULE_NAME.'+add' );
  239. }
  240. else{
  241. $this->E( G::L( '?????????????????????' ) );
  242. }
  243. }
  244. else{
  245. $this->E( G::L( '???????' ) );
  246. }
  247. }
  248. /**
  249. * ??????
  250. */
  251. public function update( ){
  252. $nId = Safe::getGpc( 'id' );
  253. $oModel = null;
  254. eval( '$oModel = '.ucfirst( MODULE_NAME ).'Model::F( \''.MODULE_NAME.'_id=?\','.$nId.' )->query( );' );
  255. $oModel->save( 'update' );
  256. if( $oModel->getErrorMessage( )=='zero-effect' ){
  257. $this->E( G::L( '????????' ) );
  258. }
  259. // ??????????
  260. if( !$oModel->isError( ) ) {
  261. $this->S( G::L( '???????' ) );
  262. }
  263. else{
  264. $this->E( $oModel->getErrorMessage( ) );
  265. }
  266. }
  267. /**
  268. * ???????
  269. */
  270. public function foreverdelete(){
  271. $sModel = MODULE_NAME;
  272. $sId = Safe::getGpc( 'id' ,'G' );
  273. if( !empty( $sId ) ) {
  274. $oModelMeta = null;
  275. eval( '$oModelMeta = '.ucfirst( $sModel ).'Model::M( );' );
  276. $sPk = reset( $oModelMeta->_arrIdName );
  277. // ????
  278. $oModelMeta->deleteWhere( array( $sPk=> array( 'in',$sId ) ) );
  279. // ????Meta?????????????
  280. if( $oModelMeta->isError( ) ){
  281. $this->E( $oModelMeta->getErrorMessage() );
  282. }
  283. else{
  284. $this->A( '',G::L( '???????' ),1 );
  285. }
  286. }
  287. else{
  288. $this->E( G::L( '???????' ) );
  289. }
  290. }
  291. /**
  292. * ???????
  293. */
  294. public function forbid( ){
  295. $sModel = MODULE_NAME;
  296. $sId = Safe::getGpc( 'id' ,'G' );
  297. if( !empty( $sId ) ) {
  298. $oModelMeta = null;
  299. eval( '$oModelMeta = '.ucfirst( $sModel ).'Model::M( );' );
  300. $sPk = reset( $oModelMeta->_arrIdName );
  301. // ????
  302. $oModelMeta->updateDbWhere( array( $sModel.'_status'=>0 ),array( $sPk=>$sId ) );
  303. // ????Meta?????????????
  304. if( $oModelMeta->isError( ) ){
  305. $this->E( $oModelMeta->getErrorMessage() );
  306. }
  307. else{
  308. $this->assign('__JumpUrl__',G::U($sModel.'/index'));
  309. $this->S( G::L( '?????' ) );
  310. }
  311. }
  312. else{
  313. $this->E( G::L( '???????' ) );
  314. }
  315. }
  316. /**
  317. * ????
  318. */
  319. public function resume( ){
  320. $sModel = MODULE_NAME;
  321. $sId = Safe::getGpc( 'id' ,'G' );
  322. if( !empty( $sId ) ) {
  323. $oModelMeta = null;
  324. eval( '$oModelMeta = '.ucfirst( $sModel ).'Model::M( );' );
  325. $sPk = reset( $oModelMeta->_arrIdName );
  326. // ????
  327. $oModelMeta->updateDbWhere( array( $sModel.'_status'=>1 ),array( $sPk=>$sId ) );
  328. // ????Meta?????????????
  329. if( $oModelMeta->isError( ) ){
  330. $this->E( $oModelMeta->getErrorMessage() );
  331. }
  332. else{
  333. $this->assign('__JumpUrl__',G::U($sModel.'/index'));
  334. $this->S( G::L( '?????' ) );
  335. }
  336. }
  337. else{
  338. $this->E( G::L( '???????' ) );
  339. }
  340. }
  341. /**
  342. * ??????
  343. */
  344. public function save_sort() {
  345. $sMoveResult = Safe::getGpc( 'moveResult','P' );
  346. if ( !empty ( $sMoveResult ) ) {
  347. $oModel = null;
  348. eval( '$oModel = new '.ucfirst( MODULE_NAME ).'Model( );' );
  349. $oDb = $oModel->getDb();
  350. // ??????
  351. $arrCol = explode ( ',', $sMoveResult );
  352. // ????
  353. $oDb->getConnect( )->startTransaction();
  354. foreach ( $arrCol as $val ) {
  355. $val = explode ( ':', $val );
  356. $oModel = null;
  357. eval( '$oModel = '.ucfirst( MODULE_NAME ).'Model::F( \''.MODULE_NAME.'_id=?\','.$val[0].' )->query( );' );
  358. $oModel->{MODULE_NAME.'_sort'} = $val[1];
  359. $bResult = $oModel->save( 'update' );
  360. if ( !$bResult ) {
  361. break;
  362. }
  363. }
  364. // ????
  365. $oDb->getConnect()->commit();
  366. if ( $bResult !==false ) {
  367. $this->S( G::L( '????') );
  368. }
  369. else {
  370. // ????
  371. $oDb->getConnect()->rollback( );
  372. $this->E( $oModel->getErrorMessage( ) );
  373. }
  374. }
  375. else{
  376. $this->E( G::L( '??????????') );
  377. }
  378. }
  379. }