Fixed bug #6703: $TCA[table]['ctrl']['hideTable'] not implemented
[Packages/TYPO3.CMS.git] / typo3 / db_list.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2005 Kasper Skaarhoj (kasperYYYY@typo3.com)
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 * A copy is found in the textfile GPL.txt and important notices to the license
17 * from the author is found in LICENSE.txt distributed with these scripts.
18 *
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27 /**
28 * Module: Web>List
29 *
30 * Listing database records from the tables configured in $TCA as they are related to the current page or root.
31 *
32 * Notice: This module and Web>Page (db_layout.php) module has a special status since they
33 * are NOT located in their actual module directories (fx. mod/web/list/) but in the
34 * backend root directory. This has some historical and practical causes.
35 *
36 * $Id$
37 * Revised for TYPO3 3.6 November/2003 by Kasper Skaarhoj
38 * XHTML compliant
39 *
40 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
41 */
42 /**
43 * [CLASS/FUNCTION INDEX of SCRIPT]
44 *
45 *
46 *
47 * 89: class SC_db_list
48 * 125: function init()
49 * 160: function menuConfig()
50 * 181: function clearCache()
51 * 195: function main()
52 * 451: function printContent()
53 *
54 * TOTAL FUNCTIONS: 5
55 * (This index is automatically created/updated by the extension "extdeveval")
56 *
57 */
58
59
60 unset($MCONF);
61 require ('mod/web/list/conf.php');
62 require ('init.php');
63 require ('template.php');
64 $LANG->includeLLFile('EXT:lang/locallang_mod_web_list.xml');
65 require_once (PATH_t3lib.'class.t3lib_page.php');
66 require_once (PATH_t3lib.'class.t3lib_pagetree.php');
67 require_once (PATH_t3lib.'class.t3lib_recordlist.php');
68 require_once (PATH_t3lib.'class.t3lib_clipboard.php');
69 require_once ($BACK_PATH.'class.db_list.inc');
70 require_once ($BACK_PATH.'class.db_list_extra.inc');
71 $BE_USER->modAccess($MCONF,1);
72
73 t3lib_BEfunc::lockRecords();
74
75
76
77
78
79
80
81
82 /**
83 * Script Class for the Web > List module; rendering the listing of records on a page
84 *
85 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
86 * @package TYPO3
87 * @subpackage core
88 */
89 class SC_db_list {
90
91 // Internal, GPvars:
92 var $id; // Page Id for which to make the listing
93 var $pointer; // Pointer - for browsing list of records.
94 var $imagemode; // Thumbnails or not
95 var $table; // Which table to make extended listing for
96 var $search_field; // Search-fields
97 var $search_levels; // Search-levels
98 var $showLimit; // Show-limit
99 var $returnUrl; // Return URL
100
101 var $clear_cache; // Clear-cache flag - if set, clears page cache for current id.
102 var $cmd; // Command: Eg. "delete" or "setCB" (for TCEmain / clipboard operations)
103 var $cmd_table; // Table on which the cmd-action is performed.
104
105 // Internal, static:
106 var $perms_clause; // Page select perms clause
107 var $modTSconfig; // Module TSconfig
108 var $pageinfo; // Current ids page record
109
110 /**
111 * Document template object
112 *
113 * @var template
114 */
115 var $doc;
116
117 var $MCONF=array(); // Module configuration
118 var $MOD_MENU=array(); // Menu configuration
119 var $MOD_SETTINGS=array(); // Module settings (session variable)
120 var $include_once=array(); // Array, where files to include is accumulated in the init() function
121
122 // Internal, dynamic:
123 var $content; // Module output accumulation
124
125
126 /**
127 * Initializing the module
128 *
129 * @return void
130 */
131 function init() {
132 global $BE_USER;
133
134 // Setting module configuration / page select clause
135 $this->MCONF = $GLOBALS['MCONF'];
136 $this->perms_clause = $BE_USER->getPagePermsClause(1);
137
138 // GPvars:
139 $this->id = t3lib_div::_GP('id');
140 $this->pointer = t3lib_div::_GP('pointer');
141 $this->imagemode = t3lib_div::_GP('imagemode');
142 $this->table = t3lib_div::_GP('table');
143 $this->search_field = t3lib_div::_GP('search_field');
144 $this->search_levels = t3lib_div::_GP('search_levels');
145 $this->showLimit = t3lib_div::_GP('showLimit');
146 $this->returnUrl = t3lib_div::_GP('returnUrl');
147
148 $this->clear_cache = t3lib_div::_GP('clear_cache');
149 $this->cmd = t3lib_div::_GP('cmd');
150 $this->cmd_table = t3lib_div::_GP('cmd_table');
151
152 // Initialize menu
153 $this->menuConfig();
154
155 // Inclusions?
156 if ($this->clear_cache || $this->cmd=='delete') {
157 $this->include_once[]=PATH_t3lib.'class.t3lib_tcemain.php';
158 }
159 }
160
161 /**
162 * Initialize function menu array
163 *
164 * @return void
165 */
166 function menuConfig() {
167
168 // MENU-ITEMS:
169 $this->MOD_MENU = array(
170 'bigControlPanel' => '',
171 'clipBoard' => '',
172 'localization' => ''
173 );
174
175 // Loading module configuration:
176 $this->modTSconfig = t3lib_BEfunc::getModTSconfig($this->id,'mod.'.$this->MCONF['name']);
177
178 // Clean up settings:
179 $this->MOD_SETTINGS = t3lib_BEfunc::getModuleData($this->MOD_MENU, t3lib_div::_GP('SET'), $this->MCONF['name']);
180 }
181
182 /**
183 * Clears page cache for the current id, $this->id
184 *
185 * @return void
186 */
187 function clearCache() {
188 if ($this->clear_cache) {
189 $tce = t3lib_div::makeInstance('t3lib_TCEmain');
190 $tce->stripslashes_values=0;
191 $tce->start(Array(),Array());
192 $tce->clear_cacheCmd($this->id);
193 }
194 }
195
196 /**
197 * Main function, starting the rendering of the list.
198 *
199 * @return void
200 */
201 function main() {
202 global $BE_USER,$LANG,$BACK_PATH,$CLIENT;
203
204 // Start document template object:
205 $this->doc = t3lib_div::makeInstance('template');
206 $this->doc->backPath = $BACK_PATH;
207 $this->doc->docType='xhtml_trans';
208
209 // Loading current page record and checking access:
210 $this->pageinfo = t3lib_BEfunc::readPageAccess($this->id,$this->perms_clause);
211 $access = is_array($this->pageinfo) ? 1 : 0;
212
213 // Initialize the dblist object:
214 $dblist = t3lib_div::makeInstance('localRecordList');
215 $dblist->backPath = $BACK_PATH;
216 $dblist->calcPerms = $BE_USER->calcPerms($this->pageinfo);
217 $dblist->thumbs = $BE_USER->uc['thumbnailsByDefault'];
218 $dblist->returnUrl=$this->returnUrl;
219 $dblist->allFields = ($this->MOD_SETTINGS['bigControlPanel'] || $this->table) ? 1 : 0;
220 $dblist->localizationView = $this->MOD_SETTINGS['localization'];
221 $dblist->showClipboard = 1;
222 $dblist->disableSingleTableView = $this->modTSconfig['properties']['disableSingleTableView'];
223 $dblist->listOnlyInSingleTableMode = $this->modTSconfig['properties']['listOnlyInSingleTableView'];
224 $dblist->hideTables = $this->modTSconfig['properties']['hideTables'];
225 $dblist->tableTSconfigOverTCA = $this->modTSconfig['properties']['table.'];
226 $dblist->clickTitleMode = $this->modTSconfig['properties']['clickTitleMode'];
227 $dblist->alternateBgColors=$this->modTSconfig['properties']['alternateBgColors']?1:0;
228 $dblist->allowedNewTables = t3lib_div::trimExplode(',',$this->modTSconfig['properties']['allowedNewTables'],1);
229 $dblist->newWizards=$this->modTSconfig['properties']['newWizards']?1:0;
230
231
232
233 // Clipboard is initialized:
234 $dblist->clipObj = t3lib_div::makeInstance('t3lib_clipboard'); // Start clipboard
235 $dblist->clipObj->initializeClipboard(); // Initialize - reads the clipboard content from the user session
236
237 // Clipboard actions are handled:
238 $CB = t3lib_div::_GET('CB'); // CB is the clipboard command array
239 if ($this->cmd=='setCB') {
240 // CBH is all the fields selected for the clipboard, CBC is the checkbox fields which were checked. By merging we get a full array of checked/unchecked elements
241 // This is set to the 'el' array of the CB after being parsed so only the table in question is registered.
242 $CB['el'] = $dblist->clipObj->cleanUpCBC(array_merge((array)t3lib_div::_POST('CBH'),(array)t3lib_div::_POST('CBC')),$this->cmd_table);
243 }
244 if (!$this->MOD_SETTINGS['clipBoard']) $CB['setP']='normal'; // If the clipboard is NOT shown, set the pad to 'normal'.
245 $dblist->clipObj->setCmd($CB); // Execute commands.
246 $dblist->clipObj->cleanCurrent(); // Clean up pad
247 $dblist->clipObj->endClipboard(); // Save the clipboard content
248
249 // This flag will prevent the clipboard panel in being shown.
250 // It is set, if the clickmenu-layer is active AND the extended view is not enabled.
251 $dblist->dontShowClipControlPanels = $CLIENT['FORMSTYLE'] && !$this->MOD_SETTINGS['bigControlPanel'] && $dblist->clipObj->current=='normal' && !$BE_USER->uc['disableCMlayers'] && !$this->modTSconfig['properties']['showClipControlPanelsDespiteOfCMlayers'];
252
253
254
255 // If there is access to the page, then render the list contents and set up the document template object:
256 if ($access) {
257
258 // Deleting records...:
259 // Has not to do with the clipboard but is simply the delete action. The clipboard object is used to clean up the submitted entries to only the selected table.
260 if ($this->cmd=='delete') {
261 $items = $dblist->clipObj->cleanUpCBC(t3lib_div::_POST('CBC'),$this->cmd_table,1);
262 if (count($items)) {
263 $cmd=array();
264 reset($items);
265 while(list($iK)=each($items)) {
266 $iKParts = explode('|',$iK);
267 $cmd[$iKParts[0]][$iKParts[1]]['delete']=1;
268 }
269 $tce = t3lib_div::makeInstance('t3lib_TCEmain');
270 $tce->stripslashes_values=0;
271 $tce->start(array(),$cmd);
272 $tce->process_cmdmap();
273
274 if (isset($cmd['pages'])) {
275 t3lib_BEfunc::getSetUpdateSignal('updatePageTree');
276 }
277
278 $tce->printLogErrorMessages(t3lib_div::getIndpEnv('REQUEST_URI'));
279 }
280 }
281
282 // Initialize the listing object, dblist, for rendering the list:
283 $this->pointer = t3lib_div::intInRange($this->pointer,0,100000);
284 $dblist->start($this->id,$this->table,$this->pointer,$this->search_field,$this->search_levels,$this->showLimit);
285 $dblist->setDispFields();
286
287 // Render the page header:
288 $dblist->writeTop($this->pageinfo);
289
290 // Render versioning selector:
291 $dblist->HTMLcode.= $this->doc->getVersionSelector($this->id);
292
293 // Render the list of tables:
294 $dblist->generateList();
295
296 // Write the bottom of the page:
297 $dblist->writeBottom();
298
299 // Add JavaScript functions to the page:
300 $this->doc->JScode=$this->doc->wrapScriptTags('
301 function jumpToUrl(URL) { //
302 window.location.href = URL;
303 return false;
304 }
305 function jumpExt(URL,anchor) { //
306 var anc = anchor?anchor:"";
307 window.location.href = URL+(T3_THIS_LOCATION?"&returnUrl="+T3_THIS_LOCATION:"")+anc;
308 return false;
309 }
310 function jumpSelf(URL) { //
311 window.location.href = URL+(T3_RETURN_URL?"&returnUrl="+T3_RETURN_URL:"");
312 return false;
313 }
314
315 function setHighlight(id) { //
316 top.fsMod.recentIds["web"]=id;
317 top.fsMod.navFrameHighlightedID["web"]="pages"+id+"_"+top.fsMod.currentBank; // For highlighting
318
319 if (top.content && top.content.nav_frame && top.content.nav_frame.refresh_nav) {
320 top.content.nav_frame.refresh_nav();
321 }
322 }
323 '.$this->doc->redirectUrls($dblist->listURL()).'
324 '.$dblist->CBfunctions().'
325 function editRecords(table,idList,addParams,CBflag) { //
326 window.location.href="'.$BACK_PATH.'alt_doc.php?returnUrl='.rawurlencode(t3lib_div::getIndpEnv('REQUEST_URI')).
327 '&edit["+table+"]["+idList+"]=edit"+addParams;
328 }
329 function editList(table,idList) { //
330 var list="";
331
332 // Checking how many is checked, how many is not
333 var pointer=0;
334 var pos = idList.indexOf(",");
335 while (pos!=-1) {
336 if (cbValue(table+"|"+idList.substr(pointer,pos-pointer))) {
337 list+=idList.substr(pointer,pos-pointer)+",";
338 }
339 pointer=pos+1;
340 pos = idList.indexOf(",",pointer);
341 }
342 if (cbValue(table+"|"+idList.substr(pointer))) {
343 list+=idList.substr(pointer)+",";
344 }
345
346 return list ? list : idList;
347 }
348
349 if (top.fsMod) top.fsMod.recentIds["web"] = '.intval($this->id).';
350 ');
351
352 // Setting up the context sensitive menu:
353 $this->doc->getContextMenuCode();
354 } // access
355
356
357
358 // Begin to compile the whole page, starting out with page header:
359 $this->content='';
360 $this->content.=$this->doc->startPage('DB list');
361 $this->content.= '<form action="'.htmlspecialchars($dblist->listURL()).'" method="post" name="dblistForm">';
362
363 // List Module CSH:
364 if (!strlen($this->id)) {
365 $this->content.= t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'list_module_noId', $GLOBALS['BACK_PATH'],'<br/>|');
366 } elseif (!$this->id) { // zero...:
367 $this->content.= t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'list_module_root', $GLOBALS['BACK_PATH'],'<br/>|');
368 }
369
370 // Add listing HTML code:
371 $this->content.= $dblist->HTMLcode;
372 $this->content.= '<input type="hidden" name="cmd_table" /><input type="hidden" name="cmd" /></form>';
373
374 // List Module CSH:
375 if ($this->id) {
376 $this->content.= t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'list_module', $GLOBALS['BACK_PATH'],'<br/>|');
377 }
378
379
380 // If a listing was produced, create the page footer with search form etc:
381 if ($dblist->HTMLcode) {
382
383 // Making field select box (when extended view for a single table is enabled):
384 if ($dblist->table) {
385 $this->content.=$dblist->fieldSelectBox($dblist->table);
386 }
387
388 // Adding checkbox options for extended listing and clipboard display:
389 $this->content.='
390
391 <!--
392 Listing options for clipboard and thumbnails
393 -->
394 <div id="typo3-listOptions">
395 <form action="" method="post">';
396
397 $this->content.=t3lib_BEfunc::getFuncCheck($this->id,'SET[bigControlPanel]',$this->MOD_SETTINGS['bigControlPanel'],'db_list.php',($this->table?'&table='.$this->table:''),'id="checkLargeControl"').' <label for="checkLargeControl">'.$LANG->getLL('largeControl',1).'</label><br />';
398 if ($dblist->showClipboard) {
399 $this->content.=t3lib_BEfunc::getFuncCheck($this->id,'SET[clipBoard]',$this->MOD_SETTINGS['clipBoard'],'db_list.php',($this->table?'&table='.$this->table:''),'id="checkShowClipBoard"').' <label for="checkShowClipBoard">'.$LANG->getLL('showClipBoard',1).'</label><br />';
400 }
401 $this->content.=t3lib_BEfunc::getFuncCheck($this->id,'SET[localization]',$this->MOD_SETTINGS['localization'],'db_list.php',($this->table?'&table='.$this->table:''),'id="checkLocalization"').' <label for="checkLocalization">'.$LANG->getLL('localization',1).'</label><br />';
402 $this->content.='
403 </form>
404 </div>';
405 $this->content.= t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'list_options', $GLOBALS['BACK_PATH']);
406
407 // Printing clipboard if enabled:
408 if ($this->MOD_SETTINGS['clipBoard'] && $dblist->showClipboard) {
409 $this->content.= $dblist->clipObj->printClipboard();
410 $this->content.= t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'list_clipboard', $GLOBALS['BACK_PATH']);
411 }
412
413 // Link for creating new records:
414 if (!$this->modTSconfig['properties']['noCreateRecordsLink']) {
415 $this->content.='
416
417 <!--
418 Link for creating a new record:
419 -->
420 <div id="typo3-newRecordLink">
421 <a href="'.htmlspecialchars($this->doc->backPath . 'db_new.php?id='.$this->id.'&returnUrl='.rawurlencode(t3lib_div::getIndpEnv('REQUEST_URI'))).'">'.
422 '<img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/new_el.gif','width="11" height="12"').' alt="" />'.
423 $LANG->getLL('newRecordGeneral',1).
424 '</a>
425 </div>';
426 }
427
428 // Search box:
429 $this->content.=$dblist->getSearchBox();
430
431 // Display sys-notes, if any are found:
432 $this->content.=$dblist->showSysNotesForPage();
433
434 // ShortCut:
435 if ($BE_USER->mayMakeShortcut()) {
436 $this->content.='<br/>'.$this->doc->makeShortcutIcon('id,imagemode,pointer,table,search_field,search_levels,showLimit,sortField,sortRev',implode(',',array_keys($this->MOD_MENU)),$this->MCONF['name']);
437 }
438 }
439
440 // Finally, close off the page:
441 $this->content.= $this->doc->endPage();
442 }
443
444 /**
445 * Outputting the accumulated content to screen
446 *
447 * @return void
448 */
449 function printContent() {
450 echo $this->content;
451 }
452 }
453
454 // Include extension?
455 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/db_list.php']) {
456 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/db_list.php']);
457 }
458
459
460
461
462
463
464
465
466
467
468
469
470 // Make instance:
471 $SOBE = t3lib_div::makeInstance('SC_db_list');
472 $SOBE->init();
473
474 // Include files?
475 foreach($SOBE->include_once as $INC_FILE) include_once($INC_FILE);
476
477 $SOBE->clearCache();
478 $SOBE->main();
479 $SOBE->printContent();
480 ?>