Documentation TYPO3 par Ameos |
00001 <?php 00002 /*************************************************************** 00003 * Copyright notice 00004 * 00005 * (c) 1999-2005 Kasper Skaarhoj (kasperYYYY@typo3.com) 00006 * All rights reserved 00007 * 00008 * This script is part of the TYPO3 project. The TYPO3 project is 00009 * free software; you can redistribute it and/or modify 00010 * it under the terms of the GNU General Public License as published by 00011 * the Free Software Foundation; either version 2 of the License, or 00012 * (at your option) any later version. 00013 * 00014 * The GNU General Public License can be found at 00015 * http://www.gnu.org/copyleft/gpl.html. 00016 * A copy is found in the textfile GPL.txt and important notices to the license 00017 * from the author is found in LICENSE.txt distributed with these scripts. 00018 * 00019 * 00020 * This script is distributed in the hope that it will be useful, 00021 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00022 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00023 * GNU General Public License for more details. 00024 * 00025 * This copyright notice MUST APPEAR in all copies of the script! 00026 ***************************************************************/ 00084 class recordList extends t3lib_recordList { 00085 00086 // External, static: 00087 var $tableList=''; // Specify a list of tables which are the only ones allowed to be displayed. 00088 var $returnUrl=''; // Return URL 00089 var $thumbs = 0; // Boolean. Thumbnails on records containing files (pictures) 00090 var $itemsLimitPerTable = 20; // default Max items shown per table in "multi-table mode", may be overridden by tables.php 00091 var $itemsLimitSingleTable = 100; // default Max items shown per table in "single-table mode", may be overridden by tables.php 00092 var $widthGif = '<img src="clear.gif" width="1" height="4" hspace="160" alt="" />'; 00093 var $script = 'db_list.php'; // Current script name 00094 var $allFields=0; // Indicates if all available fields for a user should be selected or not. 00095 var $localizationView=FALSE; // Whether to show localization view or not. 00096 00097 // Internal, static: GPvar: 00098 var $csvOutput=FALSE; // If set, csvList is outputted. 00099 var $sortField; // Field, to sort list by 00100 var $sortRev; // Field, indicating to sort in reverse order. 00101 var $displayFields; // Array, containing which fields to display in extended mode 00102 var $duplicateField; // String, can contain the field name from a table which must have duplicate values marked. 00103 00104 // Internal, static: 00105 var $id; // Page id 00106 var $table=''; // Tablename if single-table mode 00107 var $listOnlyInSingleTableMode=FALSE; // If true, records are listed only if a specific table is selected. 00108 var $firstElementNumber=0; // Pointer for browsing list 00109 var $searchString=''; // Search string 00110 var $searchLevels=''; // Levels to search down. 00111 var $showLimit=0; // Number of records to show 00112 var $pidSelect=''; // List of ids from which to select/search etc. (when search-levels are set high). See start() 00113 var $perms_clause=''; // Page select permissions 00114 var $calcPerms=0; // Some permissions... 00115 var $clickTitleMode = ''; // Mode for what happens when a user clicks the title of a record. 00116 var $modSharedTSconfig = array(); // Shared module configuration, used by localization features 00117 00118 // Internal, dynamic: 00119 var $JScode = ''; // JavaScript code accumulation 00120 var $HTMLcode = ''; // HTML output 00121 var $iLimit=0; // "LIMIT " in SQL... 00122 var $eCounter=0; // Counting the elements no matter what... 00123 var $totalItems=''; // Set to the total number of items for a table when selecting. 00124 var $recPath_cache=array(); // Cache for record path 00125 var $setFields=array(); // Fields to display for the current table 00126 var $currentTable = array(); // Used for tracking next/prev uids 00127 var $duplicateStack=array(); // Used for tracking duplicate values of fields 00128 00129 00130 00131 00132 00144 function start($id,$table,$pointer,$search="",$levels="",$showLimit=0) { 00145 global $TCA; 00146 00147 // Setting internal variables: 00148 $this->id=intval($id); // sets the parent id 00149 if ($TCA[$table]) $this->table=$table; // Setting single table mode, if table exists: 00150 $this->firstElementNumber=$pointer; 00151 $this->searchString=trim($search); 00152 $this->searchLevels=trim($levels); 00153 $this->showLimit=t3lib_div::intInRange($showLimit,0,10000); 00154 00155 // Setting GPvars: 00156 $this->csvOutput = t3lib_div::_GP('csv') ? TRUE : FALSE; 00157 $this->sortField = t3lib_div::_GP('sortField'); 00158 $this->sortRev = t3lib_div::_GP('sortRev'); 00159 $this->displayFields = t3lib_div::_GP('displayFields'); 00160 $this->duplicateField = t3lib_div::_GP('duplicateField'); 00161 00162 // If thumbnails are disabled, set the "notfound" icon as default: 00163 if (!$GLOBALS['TYPO3_CONF_VARS']['GFX']['thumbnails']) { 00164 $this->thumbScript='gfx/notfound_thumb.gif'; 00165 } 00166 00167 // Init dynamic vars: 00168 $this->counter=0; 00169 $this->JScode=''; 00170 $this->HTMLcode=''; 00171 00172 // Set select levels: 00173 $sL=intval($this->searchLevels); 00174 $this->perms_clause = $GLOBALS['BE_USER']->getPagePermsClause(1); 00175 if ($sL>0) { 00176 $tree = $this->getTreeObject($id,$sL,$this->perms_clause); 00177 $this->pidSelect = 'pid IN ('.implode(',',$tree->ids).')'; 00178 } else { 00179 $this->pidSelect = 'pid='.intval($id); 00180 } 00181 00182 // Initialize languages: 00183 if ($this->localizationView) { 00184 $this->initializeLanguages(); 00185 } 00186 } 00187 00195 function generateList() { 00196 global $TCA; 00197 00198 // Traverse the TCA table array: 00199 reset($TCA); 00200 while (list($tableName)=each($TCA)) { 00201 00202 // Checking if the table should be rendered: 00203 if ((!$this->table || $tableName==$this->table) && (!$this->tableList || t3lib_div::inList($this->tableList,$tableName)) && $GLOBALS['BE_USER']->check('tables_select',$tableName)) { // Checks that we see only permitted/requested tables: 00204 00205 // Load full table definitions: 00206 t3lib_div::loadTCA($tableName); 00207 00208 // iLimit is set depending on whether we're in single- or multi-table mode 00209 if ($this->table) { 00210 $this->iLimit=(isset($TCA[$tableName]['interface']['maxSingleDBListItems'])?intval($TCA[$tableName]['interface']['maxSingleDBListItems']):$this->itemsLimitSingleTable); 00211 } else { 00212 $this->iLimit=(isset($TCA[$tableName]['interface']['maxDBListItems'])?intval($TCA[$tableName]['interface']['maxDBListItems']):$this->itemsLimitPerTable); 00213 } 00214 if ($this->showLimit) $this->iLimit = $this->showLimit; 00215 00216 // Setting fields to select: 00217 if ($this->allFields) { 00218 $fields = $this->makeFieldList($tableName); 00219 $fields[]='_PATH_'; 00220 $fields[]='_CONTROL_'; 00221 if (is_array($this->setFields[$tableName])) { 00222 $fields = array_intersect($fields,$this->setFields[$tableName]); 00223 } else { 00224 $fields = array(); 00225 } 00226 } else { 00227 $fields = array(); 00228 } 00229 00230 // Finally, render the list: 00231 $this->HTMLcode.=$this->getTable($tableName, $this->id,implode(',',$fields)); 00232 } 00233 } 00234 } 00235 00242 function getSearchBox($formFields=1) { 00243 00244 // Setting form-elements, if applicable: 00245 $formElements=array('',''); 00246 if ($formFields) { 00247 $formElements=array('<form action="'.htmlspecialchars($this->listURL()).'" method="post">','</form>'); 00248 } 00249 00250 // Make level selector: 00251 $opt=array(); 00252 $parts = explode('|',$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.enterSearchLevels')); 00253 while(list($kv,$label)=each($parts)) { 00254 $opt[] = '<option value="'.$kv.'"'.($kv==intval($this->searchLevels)?' selected="selected"':'').'>'.htmlspecialchars($label).'</option>'; 00255 } 00256 $lMenu = '<select name="search_levels">'.implode('',$opt).'</select>'; 00257 00258 // Table with the search box: 00259 $content.= ' 00260 '.$formElements[0].' 00261 00262 <!-- 00263 Search box: 00264 --> 00265 <table border="0" cellpadding="0" cellspacing="0" class="bgColor4" id="typo3-dblist-search"> 00266 <tr> 00267 <td>'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.enterSearchString',1).'<input type="text" name="search_field" value="'.htmlspecialchars($this->searchString).'"'.$GLOBALS['TBE_TEMPLATE']->formWidth(10).' /></td> 00268 <td>'.$lMenu.'</td> 00269 <td><input type="submit" name="search" value="'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.search',1).'" /></td> 00270 </tr> 00271 <tr> 00272 <td colspan="3">'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.showRecords',1).':<input type="text" name="showLimit" value="'.htmlspecialchars($this->showLimit?$this->showLimit:'').'"'.$GLOBALS['SOBE']->doc->formWidth(4).' /></td> 00273 </tr> 00274 </table> 00275 '.$formElements[1]; 00276 $content.=t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'list_searchbox', $GLOBALS['BACK_PATH'],'|<br/>'); 00277 return $content; 00278 } 00279 00286 function showSysNotesForPage() { 00287 global $TCA; 00288 00289 $out=''; 00290 00291 // Checking if extension is loaded: 00292 if (!t3lib_extMgm::isLoaded('sys_note')) return ''; 00293 00294 // Create query for selecting the notes: 00295 $result = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*','sys_note','pid IN ('.$this->id.') AND (personal=0 OR cruser='.intval($GLOBALS['BE_USER']->user['uid']).')'.t3lib_BEfunc::deleteClause('sys_note')); 00296 00297 // Executing query: 00298 $dbCount = $GLOBALS['TYPO3_DB']->sql_num_rows($result); 00299 00300 // If some notes were found, render them: 00301 if ($dbCount) { 00302 $cat = array(); 00303 00304 // Load full table description: 00305 t3lib_div::loadTCA('sys_note'); 00306 00307 // Traverse note-types and get labels: 00308 if ($TCA['sys_note'] && $TCA['sys_note']['columns']['category'] && is_array($TCA['sys_note']['columns']['category']['config']['items'])) { 00309 foreach($TCA['sys_note']['columns']['category']['config']['items'] as $el) { 00310 $cat[$el[1]]=$GLOBALS['LANG']->sL($el[0]); 00311 } 00312 } 00313 00314 // For each note found, make rendering: 00315 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result)) { 00316 00317 // Create content: 00318 $iconImg = t3lib_iconWorks::getIconImage('sys_note',$row,$this->backPath,''); 00319 $subject = htmlspecialchars($row['subject']); 00320 $fields = array(); 00321 $fields['Author:'] = htmlspecialchars($row['author'].($row['email'] && $row['author'] ? ', ':'').$row['email']); 00322 $fields['Category:'] = htmlspecialchars($cat[$row['category']]); 00323 $fields['Note:'] = nl2br(htmlspecialchars($row['message'])); 00324 00325 // Compile content: 00326 $out.=' 00327 00328 00329 <!-- 00330 Sys-notes for the db_list.php: 00331 --> 00332 <table border="0" cellpadding="1" cellspacing="1" id="typo3-dblist-sysnotes"> 00333 <tr><td colspan="2" class="bgColor2">'.$iconImg.'<strong>'.$subject.'</strong></td></tr> 00334 <tr><td class="bgColor4">'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.category',1).'</td><td class="bgColor4">'.$fields['Category:'].'</td></tr> 00335 <tr><td class="bgColor4">'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.author',1).'</td><td class="bgColor4">'.$fields['Author:'].'</td></tr> 00336 <tr><td class="bgColor4">'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.note',1).'</td><td class="bgColor4">'.$fields['Note:'].'</td></tr> 00337 </table> 00338 '; 00339 } 00340 } 00341 return $out; 00342 } 00343 00344 00345 00346 00347 00348 00349 00350 00351 /****************************** 00352 * 00353 * Various helper functions 00354 * 00355 ******************************/ 00356 00363 function setDispFields() { 00364 00365 // Getting from session: 00366 $dispFields = $GLOBALS['BE_USER']->getModuleData('db_list.php/displayFields'); 00367 00368 // If fields has been inputted, then set those as the value and push it to session variable: 00369 if (is_array($this->displayFields)) { 00370 reset($this->displayFields); 00371 $tKey = key($this->displayFields); 00372 $dispFields[$tKey]=$this->displayFields[$tKey]; 00373 $GLOBALS['BE_USER']->pushModuleData('db_list.php/displayFields',$dispFields); 00374 } 00375 00376 // Setting result: 00377 $this->setFields=$dispFields; 00378 } 00379 00388 function thumbCode($row,$table,$field) { 00389 return t3lib_BEfunc::thumbCode($row,$table,$field,$this->backPath,$this->thumbScript); 00390 } 00391 00401 function makeQueryArray($table, $id, $addWhere="",$fieldList='*') { 00402 global $TCA; 00403 00404 // Set ORDER BY: 00405 $orderBy = ($TCA[$table]['ctrl']['sortby']) ? 'ORDER BY '.$TCA[$table]['ctrl']['sortby'] : $TCA[$table]['ctrl']['default_sortby']; 00406 if ($this->sortField) { 00407 if (in_array($this->sortField,$this->makeFieldList($table,1))) { 00408 $orderBy = 'ORDER BY '.$this->sortField; 00409 if ($this->sortRev) $orderBy.=' DESC'; 00410 } 00411 } 00412 00413 // Set LIMIT: 00414 $limit = $this->iLimit ? ($this->firstElementNumber ? $this->firstElementNumber.',' : '').($this->iLimit+1) : ''; 00415 00416 // Filtering on displayable pages (permissions): 00417 $pC = ($table=='pages' && $this->perms_clause)?' AND '.$this->perms_clause:''; 00418 00419 // Adding search constraints: 00420 $search = $this->makeSearchString($table); 00421 00422 // Compiling query array: 00423 $queryParts = array( 00424 'SELECT' => $fieldList, 00425 'FROM' => $table, 00426 'WHERE' => $this->pidSelect.' '.$pC.t3lib_BEfunc::deleteClause($table).' '.$addWhere.' '.$search, 00427 'GROUPBY' => '', 00428 'ORDERBY' => $GLOBALS['TYPO3_DB']->stripOrderBy($orderBy), 00429 'LIMIT' => $limit 00430 ); 00431 00432 // Return query: 00433 return $queryParts; 00434 } 00435 00443 function setTotalItems($queryParts) { 00444 $result = $GLOBALS['TYPO3_DB']->exec_SELECTquery( 00445 'count(*)', 00446 $queryParts['FROM'], 00447 $queryParts['WHERE'] 00448 ); 00449 list($rCount) = $GLOBALS['TYPO3_DB']->sql_fetch_row($result); 00450 $this->totalItems = $rCount; 00451 } 00452 00459 function makeSearchString($table) { 00460 global $TCA; 00461 00462 // Make query, only if table is valid and a search string is actually defined: 00463 if ($TCA[$table] && $this->searchString) { 00464 00465 // Loading full table description - we need to traverse fields: 00466 t3lib_div::loadTCA($table); 00467 00468 // Initialize field array: 00469 $sfields=array(); 00470 $sfields[]='uid'; // Adding "uid" by default. 00471 00472 // Traverse the configured columns and add all columns that can be searched: 00473 foreach($TCA[$table]['columns'] as $fieldName => $info) { 00474 if ($info['config']['type']=='text' || ($info['config']['type']=='input' && !ereg('date|time|int',$info['config']['eval']))) { 00475 $sfields[]=$fieldName; 00476 } 00477 } 00478 00479 // If search-fields were defined (and there always are) we create the query: 00480 if (count($sfields)) { 00481 $like = ' LIKE \'%'.$GLOBALS['TYPO3_DB']->quoteStr($this->searchString, $table).'%\''; // Free-text searching... 00482 $queryPart = ' AND ('.implode($like.' OR ',$sfields).$like.')'; 00483 00484 // Return query: 00485 return $queryPart; 00486 } 00487 } 00488 } 00489 00498 function linkWrapTable($table,$code) { 00499 if ($this->table!=$table) { 00500 return '<a href="'.htmlspecialchars($this->listURL('',$table)).'">'.$code.'</a>'; 00501 } else { 00502 return '<a href="'.htmlspecialchars($this->listURL('','','sortField,sortRev,table')).'">'.$code.'</a>'; 00503 } 00504 } 00505 00515 function linkWrapItems($table,$uid,$code,$row) { 00516 global $TCA, $LANG; 00517 00518 // If the title is blank, make a "no title" label: 00519 if (!strcmp($code,'')) { 00520 $code = '<i>['.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.no_title',1).']</i> - '.htmlspecialchars(t3lib_div::fixed_lgd_cs(t3lib_BEfunc::getRecordTitle($table,$row),$GLOBALS['BE_USER']->uc['titleLen'])); 00521 } else { 00522 $code = htmlspecialchars(t3lib_div::fixed_lgd_cs($code,$this->fixedL)); 00523 } 00524 00525 switch((string)$this->clickTitleMode) { 00526 case 'edit': 00527 // If the listed table is 'pages' we have to request the permission settings for each page: 00528 if ($table=='pages') { 00529 $localCalcPerms = $GLOBALS['BE_USER']->calcPerms(t3lib_BEfunc::getRecord('pages',$row['uid'])); 00530 $permsEdit = $localCalcPerms&2; 00531 } else { 00532 $permsEdit = $this->calcPerms&16; 00533 } 00534 00535 // "Edit" link: ( Only if permissions to edit the page-record of the content of the parent page ($this->id) 00536 if ($permsEdit) { 00537 $params='&edit['.$table.']['.$row['uid'].']=edit'; 00538 $code = '<a href="#" onclick="'.htmlspecialchars(t3lib_BEfunc::editOnClick($params,'',-1)).'" title="'.$LANG->getLL('edit',1).'">'. 00539 $code. 00540 '</a>'; 00541 } 00542 break; 00543 case 'show': 00544 // "Show" link (only pages and tt_content elements) 00545 if ($table=='pages' || $table=='tt_content') { 00546 $code = '<a href="#" onclick="'.htmlspecialchars(t3lib_BEfunc::viewOnClick($table=='tt_content'?$this->id.'#'.$row['uid']:$row['uid'])).'" title="'.$LANG->sL('LLL:EXT:lang/locallang_core.php:labels.showPage',1).'">'. 00547 $code. 00548 '</a>'; 00549 } 00550 break; 00551 case 'info': 00552 // "Info": (All records) 00553 $code = '<a href="#" onclick="'.htmlspecialchars('top.launchView(\''.$table.'\', \''.$row['uid'].'\'); return false;').'" title="'.$LANG->getLL('showInfo',1).'">'. 00554 $code. 00555 '</a>'; 00556 break; 00557 default: 00558 // Output the label now: 00559 if ($table=='pages') { 00560 $code = '<a href="'.htmlspecialchars($this->listURL($uid,'')).'">'.$code.'</a>'; 00561 } 00562 break; 00563 } 00564 00565 return $code; 00566 } 00567 00578 function listURL($altId='',$table=-1,$exclList='') { 00579 return $this->script. 00580 '?id='.(strcmp($altId,'')?$altId:$this->id). 00581 '&table='.rawurlencode($table==-1?$this->table:$table). 00582 ($this->thumbs?'&imagemode='.$this->thumbs:''). 00583 ($this->returnUrl?'&returnUrl='.rawurlencode($this->returnUrl):''). 00584 ($this->searchString?'&search_field='.rawurlencode($this->searchString):''). 00585 ($this->searchLevels?'&search_levels='.rawurlencode($this->searchLevels):''). 00586 ($this->showLimit?'&showLimit='.rawurlencode($this->showLimit):''). 00587 ((!$exclList || !t3lib_div::inList($exclList,'sortField')) && $this->sortField?'&sortField='.rawurlencode($this->sortField):''). 00588 ((!$exclList || !t3lib_div::inList($exclList,'sortRev')) && $this->sortRev?'&sortRev='.rawurlencode($this->sortRev):'') 00589 ; 00590 } 00591 00597 function requestUri() { 00598 return $this->listURL(); 00599 } 00600 00608 function makeFieldList($table,$dontCheckUser=0) { 00609 global $TCA,$BE_USER; 00610 00611 // Init fieldlist array: 00612 $fieldListArr = array(); 00613 00614 // Check table: 00615 if (is_array($TCA[$table])) { 00616 t3lib_div::loadTCA($table); 00617 00618 // Traverse configured columns and add them to field array, if available for user. 00619 foreach($TCA[$table]['columns'] as $fN => $fieldValue) { 00620 if ($dontCheckUser || 00621 ((!$fieldValue['exclude'] || $BE_USER->check('non_exclude_fields',$table.':'.$fN)) && $fieldValue['config']['type']!='passthrough')) { 00622 $fieldListArr[]=$fN; 00623 } 00624 } 00625 00626 // Add special fields: 00627 if ($dontCheckUser || $BE_USER->isAdmin()) { 00628 $fieldListArr[]='uid'; 00629 $fieldListArr[]='pid'; 00630 if ($TCA[$table]['ctrl']['tstamp']) $fieldListArr[]=$TCA[$table]['ctrl']['tstamp']; 00631 if ($TCA[$table]['ctrl']['crdate']) $fieldListArr[]=$TCA[$table]['ctrl']['crdate']; 00632 if ($TCA[$table]['ctrl']['cruser_id']) $fieldListArr[]=$TCA[$table]['ctrl']['cruser_id']; 00633 if ($TCA[$table]['ctrl']['sortby']) $fieldListArr[]=$TCA[$table]['ctrl']['sortby']; 00634 if ($TCA[$table]['ctrl']['versioning']) $fieldListArr[]='t3ver_id'; 00635 } 00636 } 00637 return $fieldListArr; 00638 } 00639 00648 function getTreeObject($id,$depth,$perms_clause) { 00649 $tree = t3lib_div::makeInstance('t3lib_pageTree'); 00650 $tree->init('AND '.$perms_clause); 00651 $tree->makeHTML=0; 00652 $tree->fieldArray = Array('uid','php_tree_stop'); 00653 if ($depth) { 00654 $tree->getTree($id, $depth, ''); 00655 } 00656 $tree->ids[]=$id; 00657 return $tree; 00658 } 00659 } 00660 00661 00662 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/class.db_list.inc']) { 00663 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/class.db_list.inc']); 00664 } 00665 ?>