00001 <?php
00002
00006 class oxAdminList extends oxAdminView
00007 {
00013 protected $_sListClass = null;
00014
00020 protected $_sListType = 'oxlist';
00021
00027 protected $_oList = null;
00028
00034 protected $_iCurrListPos = 0;
00035
00041 protected $_iListSize = 0;
00042
00048 protected $_aWhere = null;
00049
00055 protected $_sDefSort = null;
00056
00062 protected $_aSort = array();
00063
00069 protected $_blDesc = false;
00070
00076 protected $_blEmployMultilanguage = null;
00077
00083 protected $_iOverPos = null;
00084
00090 public function __construct()
00091 {
00092 parent::__construct();
00093
00094 $myConfig = $this->getConfig();
00095
00096
00097 if ( $aProfile = oxSession::getVar( 'profile' ) ) {
00098 if (isset($aProfile[1]))
00099 $myConfig->setConfigParam( 'iAdminListSize', (int) $aProfile[1] );
00100 }
00101
00102 if ( !$myConfig->getConfigParam( 'iAdminListSize' ) )
00103 $myConfig->setConfigParam( 'iAdminListSize', 10 );
00104
00105
00106 if ( !is_int( $myConfig->getConfigParam( 'iAdminListSize' ) ) )
00107 $myConfig->setConfigParam( 'iAdminListSize', 10 );
00108 }
00109
00115 public function init()
00116 {
00117 parent::init();
00118
00119 $myConfig = $this->getConfig();
00120
00121 if ( $this->_sListClass ) {
00122
00123 $this->_oList = oxNew( $this->_sListType, 'core' );
00124 $this->_oList->clear();
00125 $this->_oList->init( $this->_sListClass );
00126
00127 $aWhere = $this->buildWhere();
00128
00129 $oListObject = $this->_oList->getBaseObject();
00130
00131 oxSession::setVar( 'tabelle', $this->_sListClass );
00132 $this->_aViewData['listTable'] = getViewName( $oListObject->getCoreTableName() );
00133 $myConfig->setGlobalParameter( 'ListCoreTable', $oListObject->getCoreTableName() );
00134
00135 if ( $oListObject->isMultilang() ) {
00136 $oListObject->setLanguage( oxLang::getInstance()->getBaseLanguage() );
00137
00138 if ( isset( $this->_blEmployMultilanguage ) ) {
00139 $oListObject->setEnableMultilang( $this->_blEmployMultilanguage );
00140 }
00141 }
00142
00143 $sSql = $this->_buildSelectString( $oListObject );
00144 $sSql = $this->_prepareWhereQuery( $aWhere, $sSql );
00145 $sSql = $this->_prepareOrderByQuery( $sSql );
00146 $sSql = $this->_changeselect( $sSql );
00147
00148
00149 $this->_calcListItemsCount( $sSql );
00150
00151
00152 $this->_setCurrentListPosition( oxConfig::getParameter( 'jumppage' ) );
00153
00154
00155 $this->_oList->setSqlLimit( $this->_iCurrListPos, $myConfig->getConfigParam( 'iAdminListSize' ) );
00156
00157 $this->_oList->selectString( $sSql );
00158 }
00159 }
00160
00166 public function render()
00167 {
00168 $sReturn = parent::render();
00169
00170
00171 if ( $this->_oList ) {
00172 $this->_aViewData['mylist'] = $this->_oList;
00173 }
00174
00175
00176 $aWhere = oxConfig::getParameter( 'where' );
00177
00178 $myConfig = $this->getConfig();
00179 $myUtils = oxUtils::getInstance();
00180 $sListTable = $myConfig->getGlobalParameter( 'ListCoreTable' );
00181
00182 $oSearchKeys = new oxStdClass();
00183 $sWhereParam = "";
00184 if ( is_array( $aWhere ) ) {
00185 while ( list( $sName, $sValue ) = each( $aWhere ) ) {
00186 $sWhereParam .= "&where[".$sName."]=".$sValue;
00187 $sFieldName = str_replace( array( getViewName( $sListTable ) . '.', $sListTable . '.' ), $sListTable . '.', $sName );
00188 $sFieldName = $myUtils->getArrFldName( $sFieldName );
00189 $oSearchKeys->$sFieldName = $sValue;
00190 }
00191 $this->_aViewData['where'] = $oSearchKeys;
00192
00193 $sChosenCat = oxConfig::getParameter( "art_category");
00194 if ( $sChosenCat ) {
00195 $sWhereParam .= "&art_category=".$sChosenCat;
00196 }
00197 $this->_aViewData['whereparam'] = $sWhereParam;
00198 }
00199
00200
00201 $this->_setListNavigationParams();
00202
00203
00204 $this->_aSort[0] = oxConfig::getParameter( 'sort' );
00205 if ( !isset( $this->_aSort[0]) || !$this->_aSort[0] )
00206 $this->_aSort[0] = $this->_sDefSort;
00207
00208 $this->_aViewData['sort'] = $this->_aSort[0];
00209
00210 return $sReturn;
00211 }
00212
00218 public function deleteEntry()
00219 {
00220 $oDelete = oxNew( $this->_sListClass );
00221
00222
00223 $blDelete = $oDelete->delete( oxConfig::getParameter( 'oxid' ) );
00224
00225
00226 if ( $blDelete && isset( $_POST['oxid'] ) ) {
00227 $_POST['oxid'] = -1;
00228 }
00229
00230
00231 $this->init();
00232 }
00233
00241 protected function _calcListItemsCount( $sSql )
00242 {
00243
00244 $sSql = preg_replace( '/select .* from/', 'select count(*) from ', $sSql );
00245
00246
00247 $sSql = preg_replace( '/order by .*$/', '', $sSql );
00248
00249
00250 $this->_iListSize = oxDb::getDb()->getOne( $sSql );
00251
00252
00253 oxSession::setVar( 'iArtCnt', $this->_iListSize );
00254 }
00255
00263 protected function _setCurrentListPosition( $sPage = null )
00264 {
00265 $iAdminListSize = (int) $this->getConfig()->getConfigParam( 'iAdminListSize' );
00266
00267 $iJumpTo = $sPage?( (int) $sPage):( (int) ( (int) oxConfig::getParameter( 'lstrt' ) ) / $iAdminListSize );
00268 $iJumpTo = ( $sPage && $iJumpTo )?( $iJumpTo - 1 ):$iJumpTo;
00269
00270 $iJumpTo = $iJumpTo * $iAdminListSize;
00271 if ( $iJumpTo < 1 ) {
00272 $iJumpTo = 0;
00273 } elseif ( $iJumpTo >= $this->_iListSize ) {
00274 $iJumpTo = floor( $this->_iListSize / $iAdminListSize - 1 ) * $iAdminListSize;
00275 }
00276
00277 $this->_iCurrListPos = $this->_iOverPos = (int) $iJumpTo;
00278 }
00279
00287 protected function _prepareOrderByQuery( $sSql = null )
00288 {
00289
00290 $this->_aSort[0] = oxConfig::getParameter( 'sort' );
00291
00292 if ( !isset( $this->_aSort[0]) || !$this->_aSort[0] )
00293 $this->_aSort[0] = $this->_sDefSort;
00294
00295 $blSortDesc = $this->_blDesc;
00296
00297
00298 if ( $this->_aSort && isset($this->_aSort[0] ) ) {
00299
00300 $blSortDesc = oxConfig::getParameter( 'adminorder' );
00301
00302 if ( !isset( $blSortDesc ) ) {
00303 $blSortDesc = $this->_blDesc;
00304 }
00305
00306
00307 $sSql .= ' order by ';
00308 $blSep = false;
00309 $iLang = null;
00310
00311 $oListObject = $this->_oList->getBaseObject();
00312
00313 if ( $oListObject->isMultilang() ) {
00314 $iLang = $oListObject->getLanguage();
00315 }
00316
00317 $sTable = $oListObject->getCoreTableName();
00318 $sViewName = getViewName( $sTable );
00319
00320 foreach ( $this->_aSort as $orderColumn ) {
00321
00322
00323 if ( $orderColumn == "oxactive" ) {
00324 $blSortDesc = true;
00325 }
00326
00327
00328 if ( $iLang ) {
00329 $sObjectField = "{$sTable}__{$orderColumn}";
00330 if ( $oListObject instanceof oxI18n ) {
00331 if ( $oListObject->isMultilingualField($orderColumn) ) {
00332 $orderColumn .= "_{$iLang}";
00333 }
00334 }
00335 }
00336
00337
00338 if ( strpos( $orderColumn, '.' ) === false ) {
00339 $orderColumn = $sViewName . '.' . $orderColumn;
00340 }
00341
00342 $sSql .= ( ( ( $blSep ) ? ', ' : '' ) ) . $orderColumn;
00343 $blSep = true;
00344 }
00345
00346 if ( $blSortDesc ) {
00347 $sSql .= ' desc ';
00348 }
00349 }
00350
00351 return $sSql;
00352 }
00353
00361 protected function _buildSelectString( $oListObject = null )
00362 {
00363 $sSql = '';
00364
00365 if ( $oListObject ) {
00366 $oBase = oxNew( 'oxBase' );
00367 $oBase->init( $oListObject->getCoreTableName() );
00368 $sSql = $oBase->buildSelectString( null );
00369 }
00370
00371 return $sSql;
00372 }
00373
00374
00385 protected function _processFilter( $sFieldValue )
00386 {
00387
00388 $sFieldValue = preg_replace( "/^%|%$/", "", trim( $sFieldValue ) );
00389 return preg_replace( "/\s+/", " ", $sFieldValue);
00390 }
00391
00400 protected function _buildFilter( $sVal, $blIsSearchValue )
00401 {
00402 if ( $blIsSearchValue ) {
00403
00404 $sQ = " like '%{$sVal}%' ";
00405 } else {
00406
00407 $sQ = " = ".oxDb::getDb()->quote( $sVal )." ";
00408 }
00409
00410 return $sQ;
00411 }
00412
00420 protected function _isSearchValue( $sFieldValue )
00421 {
00422
00423 $blIsSearchValue = false;
00424 if ( preg_match( '/^%/', $sFieldValue ) && preg_match( '/%$/', $sFieldValue ) ) {
00425 $blIsSearchValue = true;
00426 }
00427
00428
00429 return $blIsSearchValue;
00430 }
00431
00442 protected function _prepareWhereQuery( $aWhere, $sqlFull )
00443 {
00444 if ( count($aWhere) ) {
00445 $myUtilsString = oxUtilsString::getInstance();
00446 while ( list($sFieldName, $sFieldValue) = each( $aWhere ) ) {
00447 $sFieldValue = trim( $sFieldValue );
00448
00449
00450 $blIsSearchValue = $this->_isSearchValue( $sFieldValue );
00451
00452
00453 $sFieldValue = $this->_processFilter( $sFieldValue );
00454
00455 if ( strlen($sFieldValue) ) {
00456 $aVal = explode( ' ', $sFieldValue );
00457
00458
00459 $sSqlBoolAction = ' and (';
00460
00461 foreach ( $aVal as $sVal) {
00462
00463 $sqlFull .= " {$sSqlBoolAction} {$sFieldName} ";
00464
00465
00466 $sSqlBoolAction = ' and ';
00467
00468 $sqlFull .= $this->_buildFilter( $sVal, $blIsSearchValue );
00469
00470
00471
00472 $sUml = $myUtilsString->prepareStrForSearch( $sVal );
00473 if ( $sUml ) {
00474 $sqlFull .= " or {$sFieldName} ";
00475
00476 $sqlFull .= $this->_buildFilter( $sUml, $blIsSearchValue );
00477 }
00478 }
00479
00480
00481 $sqlFull .= ' ) ';
00482 }
00483 }
00484 }
00485
00486 return $sqlFull;
00487 }
00488
00496 protected function _changeselect( $sSql )
00497 {
00498 return $sSql;
00499 }
00500
00501
00507 public function buildWhere()
00508 {
00509 $myConfig = $this->getConfig();
00510 $this->_aWhere = array();
00511
00512 $iLanguage = oxLang::getInstance()->getBaseLanguage();
00513 $aWhere = oxConfig::getParameter( 'where' );
00514
00515 if ( !$this->_oList )
00516 return $this->_aWhere;
00517
00518 $oListObject = $this->_oList->getBaseObject();
00519 $sTable = $oListObject->getCoreTableName();
00520 $sViewName = getViewName( $sTable );
00521
00522 if ( $this->_oList && is_array( $aWhere ) ) {
00523
00524 foreach ( $aWhere as $sName => $sValue ) {
00525 if ( $sValue || '0' === ( string ) $sValue ) {
00526
00527 if ( strpos( $sName, '.' ) === false ) {
00528
00529 $sName = "{$sTable}.{$sName}";
00530 }
00531
00532
00533
00534 if ( $oListObject instanceof oxI18n ) {
00535 $sFldName = strtolower( preg_replace('/(.+)\./', '', $sName ) );
00536 if ( $oListObject->isMultilingualField( $sFldName ) && $iLanguage ) {
00537 $sName .= "_$iLanguage";
00538 }
00539 }
00540
00541 $this->_aWhere[$sName] = "%{$sValue}%";
00542 }
00543 }
00544 }
00545
00546 return $this->_aWhere;
00547 }
00548
00554 protected function _setListNavigationParams()
00555 {
00556 $myConfig = $this->getConfig();
00557
00558
00559 $blShowNavigation = false;
00560 $iAdminListSize = (int) $myConfig->getConfigParam( 'iAdminListSize' );
00561 $iAdminListSize = $iAdminListSize ? $iAdminListSize : 1;
00562
00563 if ( $this->_iListSize > $iAdminListSize ) {
00564
00565 $pagenavigation = new oxStdClass();
00566 $pagenavigation->pages = round( ( ( $this->_iListSize - 1 ) / $iAdminListSize ) + 0.5, 0 );
00567 $pagenavigation->actpage = ($pagenavigation->actpage > $pagenavigation->pages)? $pagenavigation->pages : round( ( $this->_iCurrListPos / $iAdminListSize ) + 0.5, 0 );
00568 $pagenavigation->lastlink = ( $pagenavigation->pages - 1 ) * $iAdminListSize;
00569 $pagenavigation->nextlink = null;
00570 $pagenavigation->backlink = null;
00571
00572 $iPos = $this->_iCurrListPos + $iAdminListSize;
00573 if ( $iPos < $this->_iListSize ) {
00574 $pagenavigation->nextlink = $iPos = $this->_iCurrListPos + $iAdminListSize;
00575 }
00576
00577 if ( ( $this->_iCurrListPos - $iAdminListSize ) >= 0 ) {
00578 $pagenavigation->backlink = $iPos = $this->_iCurrListPos - $iAdminListSize;
00579 }
00580
00581
00582 $iStart = $pagenavigation->actpage - 5;
00583 $iStart = ( $iStart <= 0 ) ? 1 : $iStart;
00584
00585
00586 $iEnd = $pagenavigation->actpage + 5;
00587 $iEnd = ( $iEnd < $iStart + 10) ? $iStart + 10 : $iEnd;
00588 $iEnd = ( $iEnd > $pagenavigation->pages ) ? $pagenavigation->pages : $iEnd;
00589
00590
00591 $iStart = ( $iEnd - 10 > 0 ) ? $iEnd - 10 : $iStart;
00592 $iStart = ( $pagenavigation->pages <= 11) ? 1 : $iStart;
00593
00594
00595 for ( $i = $iStart; $i <= $iEnd; $i++ ) {
00596 $page = new Oxstdclass();
00597 $page->selected = 0;
00598 if ( $i == $pagenavigation->actpage ) {
00599 $page->selected = 1;
00600 }
00601 $pagenavigation->changePage[$i] = $page;
00602 }
00603
00604 $this->_aViewData['pagenavi'] = $pagenavigation;
00605
00606 if ( isset( $this->_iOverPos)) {
00607 $iPos = $this->_iOverPos;
00608 $this->_iOverPos = null;
00609 } else {
00610 $iPos = oxConfig::getParameter( 'lstrt' );
00611 }
00612
00613 if ( !$iPos ) {
00614 $iPos = 0;
00615 }
00616
00617 $this->_aViewData['lstrt'] = $iPos;
00618 $this->_aViewData['listsize'] = $this->_iListSize;
00619 $blShowNavigation = true;
00620 }
00621
00622
00623 $iShowListSize = $this->_iListSize - $this->_iCurrListPos;
00624 $iAdminListSize = (int) $myConfig->getConfigParam( 'iAdminListSize' );
00625 $iNotUsed = $iAdminListSize - min( $iShowListSize, $iAdminListSize );
00626 $iSpace = $iNotUsed * 15;
00627
00628 if ( !$blShowNavigation ) {
00629 $iSpace += 20;
00630 }
00631
00632 $this->_aViewData['iListFillsize'] = $iSpace;
00633 }
00634
00642 protected function _setupNavigation( $sNode )
00643 {
00644
00645 if ( $sNode ) {
00646
00647 $myAdminNavig = $this->getNavigation();
00648
00649 $sOxId = oxConfig::getParameter( 'oxid' );
00650
00651 if( $sOxId == -1) {
00652
00653 $iActTab = $this->_iDefEdit;
00654 } else {
00655
00656 $iActTab = oxConfig::getParameter( 'actedit' );
00657 $iActTab = $iActTab ? $iActTab : $this->_iDefEdit;
00658 }
00659
00660
00661 $this->_aViewData['editnavi'] = $myAdminNavig->getTabs( $sNode, $iActTab );
00662
00663
00664 $this->_aViewData['actlocation'] = $myAdminNavig->getActiveTab( $sNode, $iActTab );
00665
00666
00667 $this->_aViewData['default_edit'] = $myAdminNavig->getActiveTab( $sNode, $this->_iDefEdit );
00668
00669
00670 $this->_aViewData['actedit'] = $iActTab;
00671 }
00672 }
00673 }