/trunk/demo/ucenter/Lib/Action/InitController.class.php
PHP | 570 lines | 280 code | 189 blank | 101 comment | 35 complexity | 6c0615c647c7ec9841ecf67e16ddd1f3 MD5 | raw file
- <?php
- /**
- // DoYouHaoBaby-X Ucenter ( DoYouHaoBaby-X ?? )
- // +---------------------------------------------------------------------
- //
- // Copyright
- // +---------------------------------------------------------------------
- // | (C) 2010 - 2011 http://doyouhaobaby.net All rights reserved.
- // | This is not a free software, use is subject to license terms
- // +---------------------------------------------------------------------
- //
- // About This File
- // +---------------------------------------------------------------------
- // | Ucenter ?????
- // +---------------------------------------------------------------------
- */
- !defined( 'DYHB_PATH' ) && exit;
- class InitController extends Controller{
- /**
- * ??????
- *
- * @var array
- */
- public $_arrOptions = array();
- /**
- * ????
- */
- public function __construct( ){
- parent::__construct();
- // ????????
- $arrOptions = OptionModel::optionData( );
- if( $arrOptions===false ){
- $this->E( G::L( '??????????????????????????' ) );
- }
- $this->_arrOptions = $arrOptions;
- }
- /**
- * ??????
- */
- public function init__( ){
- // ???????????
- UserModel::M()->authData( );
- if( UserModel::M()->isBehaviorError() ){// ????
- $this->E ( UserModel::M()->getBehaviorErrorMessage() );
- }
- // ??Rbac??
- UserModel::M()->checkRbac( );
- // ????Rbac???????
- if( UserModel::M()->isBehaviorError() ){
- $this->E ( UserModel::M()->getBehaviorErrorMessage() );
- }
- }
- /**
- * ????
- */
- public function index( ) {
- // ????Map??
- $arrMap = $this->map( );
- // ??????????
- // ??????????
- if ( method_exists ( $this, 'filter_' ) ) {
- $this->filter_ ( $arrMap );
- }
- $sModel = ucfirst( MODULE_NAME ).'Model';
- $oSelect = '';
- eval( '$oSelect = '.$sModel.'::F( );' );
- // ????????
- $this->get_list( $oSelect,$arrMap );
- $this->display ();
- }
- /**
- * ??????
- */
- protected function map( $sName = '' ) {
- // ??????
- if ( empty ( $sName ) ) {
- $sName = MODULE_NAME;
- }
- $sName = ucfirst( $sName ).'Model';
- // ????????????
- $arrField =array();
- eval( '$arrField = '.$sName.'::M( )->_arrFieldToProp;' );
- $arrMap = array ();
- foreach ( $arrField as $sField => $sProp ) {
- if ( isset ( $_REQUEST [ $sField ] ) &&
- !empty( $_REQUEST [ $sField ] ) ) {
- $arrMap[ $sField ] = $_REQUEST [ $sField ];
- }
- }
- return $arrMap;
- }
- /**
- * ????????
- */
- protected function get_list( $oSelect,$arrMap ){
- // ?????
- $sParameter='';
- $sSortUrl='';
- $sName = MODULE_NAME;
- // ??????
- $nTotalRecord = $oSelect->where( $arrMap )->all()->getCount( );
- // ??????
- $nEverynum = $this->_arrOptions['admineverynum'];
- // ?????????????/
- foreach ( $arrMap as $sKey => $sVal ) {
- if ( !is_array ( $sVal ) ) {
- $sParameter .= $sKey.'=' . urlencode ( $sVal ) .'&';
- $sSortUrl .= '/'.$sKey.'/' . urlencode ( $sVal );
- }
- }
- // ????
- $sSortBy = strtoupper( Safe::getGpc( 'sort_' ) ) == 'ASC' ? 'ASC' :'DESC' ;
- $sOrder = Safe::getGpc( 'order_' ) ? Safe::getGpc( 'order_' ) : $sName.'_id';
- $this->assign( 'sSortByUrl', $sSortBy == 'DESC'? 'ASC' : 'DESC' );
- $this->assign( 'sSortByDescription',$sSortBy == 'DESC' ? G::L( '??') : G::L( '??' ) );
- $this->assign( 'sOrder',$sOrder );
- $this->assign( 'sSortUrl',__ACTION__.$sSortUrl);
- // ?????
- $oPage = Page::RUN( $nTotalRecord,$nEverynum, Safe::getGpc( G::C('PAGE_VAR_NAME') ) );
- $oPage->setParameter ( $sParameter );
- $sPageNavbar = $oPage->P( );
- // ??????
- $arrList = $oSelect
- ->where( $arrMap )
- ->all()
- ->order( $sOrder.' '.$sSortBy )
- ->limit( $oPage->returnPageStart( ), $nEverynum )
- ->asArray()
- ->query();
- $this->assign( 'sPageNavbar',$sPageNavbar );
- $this->assign( 'arrList',$arrList );
- }
- /**
- * Ajax???????
- */
- public function input_change_ajax( ){
- $sModel = MODULE_NAME;
- $oModelMeta = null;
- eval( '$oModelMeta = '.ucwords( $sModel ).'Model::M( );' );
- $sPk = reset( $oModelMeta->_arrIdName );
- $nInputAjaxId = Safe::getGpc( 'input_ajax_id' );
- $sInputAjaxField = Safe::getGpc( 'input_ajax_field' );
- $sInputAjaxVal = Safe::getGpc( 'input_ajax_val' );
- $arrData = array(
- $sPk => $nInputAjaxId,
- $sInputAjaxField => $sInputAjaxVal,
- );
- // badword ????
- if( $sModel =='badword' && $sInputAjaxField=='badword_find' ){
- $arrData['badword_findpattern']= '/'.$sInputAjaxVal.'/is';
- }
- if( $sInputAjaxField=='badword_find' ){
- $this->input_change_unique();
- }
- $oModelMeta->updateDbWhere( $arrData );
- // ????Meta?????????????
- if( $oModelMeta->isError( ) ){
- $this->E( $oModelMeta->getErrorMessage() );
- }
- else{
- $arrVo = array(
- 'id' => $sInputAjaxField.'_'.$nInputAjaxId,
- 'value' => $sInputAjaxVal,
- );
- $this->A( $arrVo, G::L( '???????') );
- }
- }
- /**
- * ?????( Ajax???? )
- */
- public function input_change_unique( ){
- $sModel = ucfirst( MODULE_NAME );
- $oModelMeta = null;
- eval( '$oModelMeta = '.$sModel.'Model::M( );' );
- $nId = Safe::getGpc( 'input_ajax_id' );
- $sField = Safe::getGpc( 'input_ajax_field' );
- $sName = Safe::getGpc( 'input_ajax_val' );
- $sInfo = '';
- if( $nId ){
- $oModel = null;
- eval( '$oModel = '.$sModel.'Model::F( \''.MODULE_NAME.'_id=?\','.$nId.' )->query( );' );
- $arrInfo = $oModel->toArray();
- $sInfo = $arrInfo[ $sField ];
- }
- if( $sName != $sInfo ){
- $oSelect =null;
- eval( '$oSelect = '.$sModel.'Model::F( );' );
- $sFunc ='getBy'.$sField;
- $arrResult = $oSelect->{$sFunc}( $sName )->toArray();
- if( !empty( $arrResult[ $sField ] ) ) {
- $this->E( G::L( '?????????' ) );
- }
- }
- }
- /**
- * ?????
- */
- public function seccode( ){
- Safe::seccode( );
- }
- /**
- * ????????
- */
- public function insert( ){
- // ????
- $oModel = null;
- eval( '$oModel = new '.ucfirst( MODULE_NAME ).'Model( );' );
- // ????
- $oModel->save( );
- // ??????
- if( !$oModel->isError( ) ) {
- if( 'user'!==MODULE_NAME ){
- $this->A( $oModel->toArray( ),G::L( '???????' ),1 );
- }
- else{
- $arrUser = $oModel->toArray( );
- $nId = reset( $arrUser );
- $this->assign('__JumpUrl__', G::U( MODULE_NAME.'/edit?id='.$nId ) );
- $this->S( G::L( '???????' ) );
- }
- }
- else{
- $this->E( $oModel->getErrorMessage( ) );
- }
- }
- /**
- * ???????
- */
- public function edit( ){
- $nId = Safe::getGpc( 'id','G' );
- // ?????????
- if( !empty( $nId ) ) {
- $oModel = null;
- eval( '$oModel = '.ucfirst( MODULE_NAME ).'Model::F( \''.MODULE_NAME.'_id=?\','.$nId.' )->query( );' );
- if( $oModel ) {
- $this->assign( 'arrValue',$oModel->toArray() );
- $this->assign( 'nId',$nId );
- $this->display( MODULE_NAME.'+add' );
- }
- else{
- $this->E( G::L( '?????????????????????' ) );
- }
- }
- else{
- $this->E( G::L( '???????' ) );
- }
- }
- /**
- * ??????
- */
- public function update( ){
- $nId = Safe::getGpc( 'id' );
- $oModel = null;
- eval( '$oModel = '.ucfirst( MODULE_NAME ).'Model::F( \''.MODULE_NAME.'_id=?\','.$nId.' )->query( );' );
- $oModel->save( 'update' );
- if( $oModel->getErrorMessage( )=='zero-effect' ){
- $this->E( G::L( '????????' ) );
- }
- // ??????????
- if( !$oModel->isError( ) ) {
- $this->S( G::L( '???????' ) );
- }
- else{
- $this->E( $oModel->getErrorMessage( ) );
- }
- }
- /**
- * ???????
- */
- public function foreverdelete(){
- $sModel = MODULE_NAME;
- $sId = Safe::getGpc( 'id' ,'G' );
- if( !empty( $sId ) ) {
- $oModelMeta = null;
- eval( '$oModelMeta = '.ucfirst( $sModel ).'Model::M( );' );
- $sPk = reset( $oModelMeta->_arrIdName );
- // ????
- $oModelMeta->deleteWhere( array( $sPk=> array( 'in',$sId ) ) );
- // ????Meta?????????????
- if( $oModelMeta->isError( ) ){
- $this->E( $oModelMeta->getErrorMessage() );
- }
- else{
- $this->A( '',G::L( '???????' ),1 );
- }
- }
- else{
- $this->E( G::L( '???????' ) );
- }
- }
- /**
- * ???????
- */
- public function forbid( ){
- $sModel = MODULE_NAME;
- $sId = Safe::getGpc( 'id' ,'G' );
- if( !empty( $sId ) ) {
- $oModelMeta = null;
- eval( '$oModelMeta = '.ucfirst( $sModel ).'Model::M( );' );
- $sPk = reset( $oModelMeta->_arrIdName );
- // ????
- $oModelMeta->updateDbWhere( array( $sModel.'_status'=>0 ),array( $sPk=>$sId ) );
- // ????Meta?????????????
- if( $oModelMeta->isError( ) ){
- $this->E( $oModelMeta->getErrorMessage() );
- }
- else{
- $this->assign('__JumpUrl__',G::U($sModel.'/index'));
- $this->S( G::L( '?????' ) );
- }
- }
- else{
- $this->E( G::L( '???????' ) );
- }
- }
- /**
- * ????
- */
- public function resume( ){
- $sModel = MODULE_NAME;
- $sId = Safe::getGpc( 'id' ,'G' );
- if( !empty( $sId ) ) {
- $oModelMeta = null;
- eval( '$oModelMeta = '.ucfirst( $sModel ).'Model::M( );' );
- $sPk = reset( $oModelMeta->_arrIdName );
- // ????
- $oModelMeta->updateDbWhere( array( $sModel.'_status'=>1 ),array( $sPk=>$sId ) );
- // ????Meta?????????????
- if( $oModelMeta->isError( ) ){
- $this->E( $oModelMeta->getErrorMessage() );
- }
- else{
- $this->assign('__JumpUrl__',G::U($sModel.'/index'));
- $this->S( G::L( '?????' ) );
- }
- }
- else{
- $this->E( G::L( '???????' ) );
- }
- }
- /**
- * ??????
- */
- public function save_sort() {
- $sMoveResult = Safe::getGpc( 'moveResult','P' );
- if ( !empty ( $sMoveResult ) ) {
- $oModel = null;
- eval( '$oModel = new '.ucfirst( MODULE_NAME ).'Model( );' );
- $oDb = $oModel->getDb();
- // ??????
- $arrCol = explode ( ',', $sMoveResult );
- // ????
- $oDb->getConnect( )->startTransaction();
- foreach ( $arrCol as $val ) {
- $val = explode ( ':', $val );
- $oModel = null;
- eval( '$oModel = '.ucfirst( MODULE_NAME ).'Model::F( \''.MODULE_NAME.'_id=?\','.$val[0].' )->query( );' );
- $oModel->{MODULE_NAME.'_sort'} = $val[1];
- $bResult = $oModel->save( 'update' );
- if ( !$bResult ) {
- break;
- }
- }
- // ????
- $oDb->getConnect()->commit();
- if ( $bResult !==false ) {
- $this->S( G::L( '????') );
- }
- else {
- // ????
- $oDb->getConnect()->rollback( );
- $this->E( $oModel->getErrorMessage( ) );
- }
- }
- else{
- $this->E( G::L( '??????????') );
- }
- }
- }