00001 <?php
00002
00007 class oxAdminList extends oxAdminView
00008 {
00014 protected $_sListClass = null;
00015
00021 protected $_sListType = 'oxlist';
00022
00028 protected $_oList = null;
00029
00035 protected $_iCurrListPos = 0;
00036
00042 protected $_iListSize = 0;
00043
00049 protected $_aWhere = null;
00050
00056 protected $_sDefSort = null;
00057
00063 protected $_aSort = array();
00064
00070 protected $_blDesc = false;
00071
00077 protected $_blEmployMultilanguage = null;
00078
00084 protected $_iOverPos = null;
00085
00091 public function __construct()
00092 {
00093 parent::__construct();
00094
00095 $myConfig = $this->getConfig();
00096
00097
00098 if ( $aProfile = oxSession::getVar( 'profile' ) ) {
00099 if (isset($aProfile[1]))
00100 $myConfig->setConfigParam( 'iAdminListSize', (int) $aProfile[1] );
00101 }
00102
00103 if ( !$myConfig->getConfigParam( 'iAdminListSize' ) )
00104 $myConfig->setConfigParam( 'iAdminListSize', 10 );
00105
00106
00107 if ( !is_int( $myConfig->getConfigParam( 'iAdminListSize' ) ) )
00108 $myConfig->setConfigParam( 'iAdminListSize', 10 );
00109 }
00110
00116 public function init()
00117 {
00118 parent::init();
00119
00120 $myConfig = $this->getConfig();
00121
00122 if ( $this->_sListClass ) {
00123
00124 $this->_oList = oxNew( $this->_sListType, 'core' );
00125 $this->_oList->clear();
00126 $this->_oList->init( $this->_sListClass );
00127
00128
00129 $this->_oList->setObjectCallback( array( &$this, 'isOx' ) );
00130
00131 $aWhere = $this->buildWhere();
00132
00133 $oListObject = $this->_oList->getBaseObject();
00134
00135 oxSession::setVar( 'tabelle', $this->_sListClass );
00136 $this->_aViewData['listTable'] = getViewName( $oListObject->getCoreTableName() );
00137 $myConfig->setGlobalParameter( 'ListCoreTable', $oListObject->getCoreTableName() );
00138
00139 if ( $oListObject->isMultilang() ) {
00140 $oListObject->setLanguage( oxLang::getInstance()->getBaseLanguage() );
00141
00142 if ( isset( $this->_blEmployMultilanguage ) ) {
00143 $oListObject->setEnableMultilang( $this->_blEmployMultilanguage );
00144 }
00145 }
00146
00147 $sSql = $this->_buildSelectString( $oListObject );
00148 $sSql = $this->_prepareWhereQuery( $aWhere, $sSql );
00149 $sSql = $this->_prepareOrderByQuery( $sSql );
00150 $sSql = $this->_changeselect( $sSql );
00151
00152
00153 $this->_calcListItemsCount( $sSql );
00154
00155
00156 $this->_setCurrentListPosition( oxConfig::getParameter( 'jumppage' ) );
00157
00158
00159 $this->_oList->setSqlLimit( $this->_iCurrListPos, $myConfig->getConfigParam( 'iAdminListSize' ) );
00160
00161 $this->_oList->selectString( $sSql );
00162 }
00163 }
00164
00170 public function render()
00171 {
00172 $sReturn = parent::render();
00173
00174
00175 if ( $this->_oList ) {
00176 $this->_aViewData['mylist'] = $this->_oList;
00177 }
00178
00179
00180 $aWhere = oxConfig::getParameter( 'where' );
00181
00182 $myConfig = $this->getConfig();
00183 $sListTable = $myConfig->getGlobalParameter( 'ListCoreTable' );
00184
00185 $oSearchKeys = new oxStdClass();
00186 $sWhereParam = "";
00187 if ( is_array( $aWhere ) ) {
00188 while ( list( $sName, $sValue ) = each( $aWhere ) ) {
00189 $sWhereParam .= "&where[".$sName."]=".$sValue;
00190 $sFieldName = str_replace( array( getViewName( $sListTable ) . '.', $sListTable . '.' ), $sListTable . '.', $sName );
00191 $sFieldName = oxUtils::getInstance()->getArrFldName( $sFieldName );
00192 $oSearchKeys->$sFieldName = $sValue;
00193 }
00194 $this->_aViewData['where'] = $oSearchKeys;
00195 $this->_aViewData['whereparam'] = $sWhereParam;
00196 }
00197
00198
00199 $this->_setListNavigationParams();
00200
00201
00202 $this->_aSort[0] = oxConfig::getParameter( 'sort' );
00203 if ( !isset( $this->_aSort[0]) || !$this->_aSort[0] )
00204 $this->_aSort[0] = $this->_sDefSort;
00205
00206 $this->_aViewData['sort'] = $this->_aSort[0];
00207
00208 return $sReturn;
00209 }
00210
00218 public function isOx( $oObject )
00219 {
00220 $sOxId = $oObject->getId();
00221 if ( $sOxId[0] == 'o' && $sOxId[1] == 'x' ) {
00222 $oObject->isinternal = true;
00223 }
00224
00225 return $oObject;
00226 }
00227
00233 public function deleteEntry()
00234 {
00235 $oDelete = oxNew( $this->_sListClass );
00236
00237
00238 $blDelete = $oDelete->delete( oxConfig::getParameter( 'oxid' ) );
00239
00240
00241 if ( $blDelete && isset( $_POST['oxid'] ) ) {
00242 $_POST['oxid'] = -1;
00243 }
00244
00245
00246 $this->init();
00247 }
00248
00256 protected function _calcListItemsCount( $sSql )
00257 {
00258
00259 $sSql = preg_replace( '/select .* from/', 'select count(*) from ', $sSql );
00260
00261
00262 $sSql = preg_replace( '/order by .*$/', '', $sSql );
00263
00264
00265 $this->_iListSize = oxDb::getDb()->getOne( $sSql );
00266
00267
00268 oxSession::setVar( 'iArtCnt', $this->_iListSize );
00269 }
00270
00278 protected function _setCurrentListPosition( $sPage = null )
00279 {
00280 $iAdminListSize = (int) $this->getConfig()->getConfigParam( 'iAdminListSize' );
00281
00282 $iJumpTo = $sPage?( (int) $sPage):( (int) ( (int) oxConfig::getParameter( 'lstrt' ) ) / $iAdminListSize );
00283 $iJumpTo = ( $sPage && $iJumpTo )?( $iJumpTo - 1 ):$iJumpTo;
00284
00285 $iJumpTo = $iJumpTo * $iAdminListSize;
00286 if ( $iJumpTo < 1 ) {
00287 $iJumpTo = 0;
00288 } elseif ( $iJumpTo >= $this->_iListSize ) {
00289 $iJumpTo = floor( $this->_iListSize / $iAdminListSize - 1 ) * $iAdminListSize;
00290 }
00291
00292 $this->_iCurrListPos = $this->_iOverPos = (int) $iJumpTo;
00293 }
00294
00302 protected function _prepareOrderByQuery( $sSql = null )
00303 {
00304
00305 $this->_aSort[0] = oxConfig::getParameter( 'sort' );
00306
00307 if ( !isset( $this->_aSort[0]) || !$this->_aSort[0] )
00308 $this->_aSort[0] = $this->_sDefSort;
00309
00310 $blSortDesc = $this->_blDesc;
00311
00312
00313 if ( $this->_aSort && isset($this->_aSort[0] ) ) {
00314
00315 $blSortDesc = oxConfig::getParameter( 'adminorder' );
00316
00317 if ( !isset( $blSortDesc ) ) {
00318 $blSortDesc = $this->_blDesc;
00319 }
00320
00321
00322 $sSql .= ' order by ';
00323 $blSep = false;
00324 $iLang = null;
00325
00326 $oListObject = $this->_oList->getBaseObject();
00327
00328 if ( $oListObject->isMultilang() ) {
00329 $iLang = $oListObject->getLanguage();
00330 }
00331
00332 $sTable = $oListObject->getCoreTableName();
00333 $sViewName = getViewName( $sTable );
00334
00335 foreach ( $this->_aSort as $orderColumn ) {
00336
00337
00338 if ( $orderColumn == "oxactive" ) {
00339 $blSortDesc = true;
00340 }
00341
00342
00343 if ( $iLang ) {
00344 $sObjectField = "{$sTable}__{$orderColumn}";
00345 if ( $oListObject instanceof oxI18n ) {
00346 if ( $oListObject->isMultilingualField($orderColumn) ) {
00347 $orderColumn .= "_{$iLang}";
00348 }
00349 }
00350 }
00351
00352
00353 if ( strpos( $orderColumn, '.' ) === false ) {
00354 $orderColumn = $sViewName . '.' . $orderColumn;
00355 }
00356
00357 $sSql .= ( ( ( $blSep ) ? ', ' : '' ) ) . $orderColumn;
00358 $blSep = true;
00359 }
00360
00361 if ( $blSortDesc ) {
00362 $sSql .= ' desc ';
00363 }
00364 }
00365
00366 return $sSql;
00367 }
00368
00376 protected function _buildSelectString( $oListObject = null )
00377 {
00378 $sSql = '';
00379
00380 if ( $oListObject ) {
00381 $oBase = oxNew( 'oxBase' );
00382 $oBase->init( $oListObject->getCoreTableName() );
00383 $sSql = $oBase->buildSelectString( null );
00384 }
00385
00386 return $sSql;
00387 }
00388
00389
00400 protected function _processFilter( $sFieldValue )
00401 {
00402
00403 $sFieldValue = preg_replace( "/^%|%$/", "", trim( $sFieldValue ) );
00404 return preg_replace( "/\s+/", " ", $sFieldValue);
00405 }
00406
00415 protected function _buildFilter( $sVal, $blIsSearchValue )
00416 {
00417 if ( $blIsSearchValue ) {
00418
00419 $sQ = " like '%{$sVal}%' ";
00420 } else {
00421
00422 $sQ = " = ".oxDb::getDb()->quote( $sVal )." ";
00423 }
00424
00425 return $sQ;
00426 }
00427
00435 protected function _isSearchValue( $sFieldValue )
00436 {
00437
00438 $blIsSearchValue = false;
00439 if ( preg_match( '/^%/', $sFieldValue ) && preg_match( '/%$/', $sFieldValue ) ) {
00440 $blIsSearchValue = true;
00441 }
00442
00443
00444 return $blIsSearchValue;
00445 }
00446
00457 protected function _prepareWhereQuery( $aWhere, $sqlFull )
00458 {
00459 if ( count($aWhere) ) {
00460
00461 while ( list($sFieldName, $sFieldValue) = each( $aWhere ) ) {
00462 $sFieldValue = trim( $sFieldValue );
00463
00464
00465 $blIsSearchValue = $this->_isSearchValue( $sFieldValue );
00466
00467
00468 $sFieldValue = $this->_processFilter( $sFieldValue );
00469
00470 if ( strlen($sFieldValue) ) {
00471 $aVal = explode( ' ', $sFieldValue );
00472
00473
00474 $sSqlBoolAction = ' and (';
00475
00476 foreach ( $aVal as $sVal) {
00477
00478 $sqlFull .= " {$sSqlBoolAction} {$sFieldName} ";
00479
00480
00481 $sSqlBoolAction = ' and ';
00482
00483 $sqlFull .= $this->_buildFilter( $sVal, $blIsSearchValue );
00484
00485
00486
00487 $sUml = oxUtilsString::getInstance()->prepareStrForSearch( $sVal );
00488 if ( $sUml ) {
00489 $sqlFull .= " or {$sFieldName} ";
00490
00491 $sqlFull .= $this->_buildFilter( $sUml, $blIsSearchValue );
00492 }
00493
00494 }
00495
00496
00497 $sqlFull .= ' ) ';
00498 }
00499 }
00500 }
00501
00502 return $sqlFull;
00503 }
00504
00512 protected function _changeselect( $sSql )
00513 {
00514 return $sSql;
00515 }
00516
00517
00523 public function buildWhere()
00524 {
00525 $myConfig = $this->getConfig();
00526 $this->_aWhere = array();
00527
00528 $iLanguage = oxLang::getInstance()->getBaseLanguage();
00529 $aWhere = oxConfig::getParameter( 'where' );
00530
00531 if ( !$this->_oList )
00532 return $this->_aWhere;
00533
00534 $sTable = $this->_oList->getBaseObject()->getCoreTableName();
00535 $sViewName = getViewName( $sTable );
00536
00537 if ( $this->_oList && is_array( $aWhere ) ) {
00538
00539 foreach ( $aWhere as $sName => $sValue ) {
00540 if ( $sValue || '0' === ( string ) $sValue ) {
00541
00542 if ( strpos( $sName, '.' ) === false ) {
00543
00544 $sName = "{$sTable}.{$sName}";
00545 }
00546
00547
00548
00549 if ( ( $oObj = $this->_oList->getBaseObject() ) instanceof oxI18n ) {
00550 $sFldName = strtolower( preg_replace('/(.+)\./', '', $sName ) );
00551 if ( $oObj->isMultilingualField( $sFldName ) && $iLanguage ) {
00552 $sName .= "_$iLanguage";
00553 }
00554 }
00555
00556 $this->_aWhere[$sName] = "%{$sValue}%";
00557 }
00558 }
00559 }
00560
00561 return $this->_aWhere;
00562 }
00563
00569 protected function _setListNavigationParams()
00570 {
00571 $myConfig = $this->getConfig();
00572
00573
00574 $blShowNavigation = false;
00575 $iAdminListSize = (int) $myConfig->getConfigParam( 'iAdminListSize' );
00576 $iAdminListSize = $iAdminListSize ? $iAdminListSize : 1;
00577
00578 if ( $this->_iListSize > $iAdminListSize ) {
00579
00580 $pagenavigation = new oxStdClass();
00581 $pagenavigation->pages = round( ( ( $this->_iListSize - 1 ) / $iAdminListSize ) + 0.5, 0 );
00582 $pagenavigation->actpage = ($pagenavigation->actpage > $pagenavigation->pages)? $pagenavigation->pages : round( ( $this->_iCurrListPos / $iAdminListSize ) + 0.5, 0 );
00583 $pagenavigation->lastlink = ( $pagenavigation->pages - 1 ) * $iAdminListSize;
00584 $pagenavigation->nextlink = null;
00585 $pagenavigation->backlink = null;
00586
00587 $iPos = $this->_iCurrListPos + $iAdminListSize;
00588 if ( $iPos < $this->_iListSize ) {
00589 $pagenavigation->nextlink = $iPos = $this->_iCurrListPos + $iAdminListSize;
00590 }
00591
00592 if ( ( $this->_iCurrListPos - $iAdminListSize ) >= 0 ) {
00593 $pagenavigation->backlink = $iPos = $this->_iCurrListPos - $iAdminListSize;
00594 }
00595
00596
00597 $iStart = $pagenavigation->actpage - 5;
00598 $iStart = ( $iStart <= 0 ) ? 1 : $iStart;
00599
00600
00601 $iEnd = $pagenavigation->actpage + 5;
00602 $iEnd = ( $iEnd < $iStart + 10) ? $iStart + 10 : $iEnd;
00603 $iEnd = ( $iEnd > $pagenavigation->pages ) ? $pagenavigation->pages : $iEnd;
00604
00605
00606 $iStart = ( $iEnd - 10 > 0 ) ? $iEnd - 10 : $iStart;
00607 $iStart = ( $pagenavigation->pages <= 11) ? 1 : $iStart;
00608
00609
00610 for ( $i = $iStart; $i <= $iEnd; $i++ ) {
00611 $page = new Oxstdclass();
00612 $page->selected = 0;
00613 if ( $i == $pagenavigation->actpage ) {
00614 $page->selected = 1;
00615 }
00616 $pagenavigation->changePage[$i] = $page;
00617 }
00618
00619 $this->_aViewData['pagenavi'] = $pagenavigation;
00620
00621 if ( isset( $this->_iOverPos)) {
00622 $iPos = $this->_iOverPos;
00623 $this->_iOverPos = null;
00624 } else {
00625 $iPos = oxConfig::getParameter( 'lstrt' );
00626 }
00627
00628 if ( !$iPos ) {
00629 $iPos = 0;
00630 }
00631
00632 $this->_aViewData['lstrt'] = $iPos;
00633 $this->_aViewData['listsize'] = $this->_iListSize;
00634 $blShowNavigation = true;
00635 }
00636
00637
00638 $iShowListSize = $this->_iListSize - $this->_iCurrListPos;
00639 $iAdminListSize = (int) $myConfig->getConfigParam( 'iAdminListSize' );
00640 $iNotUsed = $iAdminListSize - min( $iShowListSize, $iAdminListSize );
00641 $iSpace = $iNotUsed * 15;
00642
00643 if ( !$blShowNavigation ) {
00644 $iSpace += 20;
00645 }
00646
00647 $this->_aViewData['iListFillsize'] = $iSpace;
00648 }
00649
00657 protected function _setupNavigation( $sNode )
00658 {
00659
00660 if ( $sNode ) {
00661
00662 $myAdminNavig = $this->getNavigation();
00663
00664 $sOxId = oxConfig::getParameter( 'oxid' );
00665
00666 if( $sOxId == -1) {
00667
00668 $iActTab = $this->_iDefEdit;
00669 } else {
00670
00671 $iActTab = oxConfig::getParameter( 'actedit' );
00672 $iActTab = $iActTab ? $iActTab : $this->_iDefEdit;
00673 }
00674
00675
00676 $this->_aViewData['editnavi'] = $myAdminNavig->getTabs( $sNode, $iActTab );
00677
00678
00679 $this->_aViewData['actlocation'] = $myAdminNavig->getActiveTab( $sNode, $iActTab );
00680
00681
00682 $this->_aViewData['default_edit'] = $myAdminNavig->getActiveTab( $sNode, $this->_iDefEdit );
00683
00684
00685 $this->_aViewData['actedit'] = $iActTab;
00686 }
00687 }
00688 }