Fixed bug #15686: Call the list module through the dispatcher instead directly (Thank...
[Packages/TYPO3.CMS.git] / typo3 / sysext / list / mod1 / db_list.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2010 Kasper Skårhøj (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 Skårhøj
38 * XHTML compliant
39 *
40 * @author Kasper Skårhøj <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 $LANG->includeLLFile('EXT:lang/locallang_mod_web_list.xml');
61 require_once ($BACK_PATH.'class.db_list.inc');
62 require_once ($BACK_PATH.'class.db_list_extra.inc');
63 $BE_USER->modAccess($MCONF,1);
64
65 t3lib_BEfunc::lockRecords();
66
67
68
69
70
71
72
73
74 /**
75 * Script Class for the Web > List module; rendering the listing of records on a page
76 *
77 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
78 * @package TYPO3
79 * @subpackage core
80 */
81 class SC_db_list {
82
83 // Internal, GPvars:
84 var $id; // Page Id for which to make the listing
85 var $pointer; // Pointer - for browsing list of records.
86 var $imagemode; // Thumbnails or not
87 var $table; // Which table to make extended listing for
88 var $search_field; // Search-fields
89 var $search_levels; // Search-levels
90 var $showLimit; // Show-limit
91 var $returnUrl; // Return URL
92
93 var $clear_cache; // Clear-cache flag - if set, clears page cache for current id.
94 var $cmd; // Command: Eg. "delete" or "setCB" (for TCEmain / clipboard operations)
95 var $cmd_table; // Table on which the cmd-action is performed.
96
97 // Internal, static:
98 var $perms_clause; // Page select perms clause
99 var $modTSconfig; // Module TSconfig
100 var $pageinfo; // Current ids page record
101
102 /**
103 * Document template object
104 *
105 * @var template
106 */
107 var $doc;
108
109 var $MCONF=array(); // Module configuration
110 var $MOD_MENU=array(); // Menu configuration
111 var $MOD_SETTINGS=array(); // Module settings (session variable)
112 var $include_once=array(); // Array, where files to include is accumulated in the init() function
113
114 // Internal, dynamic:
115 var $content; // Module output accumulation
116
117
118 /**
119 * Initializing the module
120 *
121 * @return void
122 */
123 function init() {
124 global $BE_USER;
125
126 // Setting module configuration / page select clause
127 $this->MCONF = $GLOBALS['MCONF'];
128 $this->perms_clause = $BE_USER->getPagePermsClause(1);
129
130 // GPvars:
131 $this->id = t3lib_div::_GP('id');
132 $this->pointer = t3lib_div::_GP('pointer');
133 $this->imagemode = t3lib_div::_GP('imagemode');
134 $this->table = t3lib_div::_GP('table');
135 $this->search_field = t3lib_div::_GP('search_field');
136 $this->search_levels = t3lib_div::_GP('search_levels');
137 $this->showLimit = t3lib_div::_GP('showLimit');
138 $this->returnUrl = t3lib_div::sanitizeLocalUrl(t3lib_div::_GP('returnUrl'));
139
140 $this->clear_cache = t3lib_div::_GP('clear_cache');
141 $this->cmd = t3lib_div::_GP('cmd');
142 $this->cmd_table = t3lib_div::_GP('cmd_table');
143
144 // Initialize menu
145 $this->menuConfig();
146
147 // Inclusions?
148 if ($this->clear_cache || $this->cmd=='delete') {
149 $this->include_once[]=PATH_t3lib.'class.t3lib_tcemain.php';
150 }
151 }
152
153 /**
154 * Initialize function menu array
155 *
156 * @return void
157 */
158 function menuConfig() {
159
160 // MENU-ITEMS:
161 $this->MOD_MENU = array(
162 'bigControlPanel' => '',
163 'clipBoard' => '',
164 'localization' => ''
165 );
166
167 // Loading module configuration:
168 $this->modTSconfig = t3lib_BEfunc::getModTSconfig($this->id,'mod.'.$this->MCONF['name']);
169
170 // Clean up settings:
171 $this->MOD_SETTINGS = t3lib_BEfunc::getModuleData($this->MOD_MENU, t3lib_div::_GP('SET'), $this->MCONF['name']);
172 }
173
174 /**
175 * Clears page cache for the current id, $this->id
176 *
177 * @return void
178 */
179 function clearCache() {
180 if ($this->clear_cache) {
181 $tce = t3lib_div::makeInstance('t3lib_TCEmain');
182 $tce->stripslashes_values=0;
183 $tce->start(Array(),Array());
184 $tce->clear_cacheCmd($this->id);
185 }
186 }
187
188 /**
189 * Main function, starting the rendering of the list.
190 *
191 * @return void
192 */
193 function main() {
194 global $BE_USER,$LANG,$BACK_PATH,$CLIENT;
195
196 // Start document template object:
197 $this->doc = t3lib_div::makeInstance('template');
198 $this->doc->backPath = $BACK_PATH;
199 $this->doc->setModuleTemplate('templates/db_list.html');
200
201 // Loading current page record and checking access:
202 $this->pageinfo = t3lib_BEfunc::readPageAccess($this->id,$this->perms_clause);
203 $access = is_array($this->pageinfo) ? 1 : 0;
204
205 // Apply predefined values for hidden checkboxes
206 // Set predefined value for DisplayBigControlPanel:
207 if ($this->modTSconfig['properties']['enableDisplayBigControlPanel'] === 'activated') {
208 $this->MOD_SETTINGS['bigControlPanel'] = TRUE;
209 } elseif ($this->modTSconfig['properties']['enableDisplayBigControlPanel'] === 'deactivated') {
210 $this->MOD_SETTINGS['bigControlPanel'] = FALSE;
211 }
212
213 // Set predefined value for Clipboard:
214 if ($this->modTSconfig['properties']['enableClipBoard'] === 'activated') {
215 $this->MOD_SETTINGS['clipBoard'] = TRUE;
216 } elseif ($this->modTSconfig['properties']['enableClipBoard'] === 'deactivated') {
217 $this->MOD_SETTINGS['clipBoard'] = FALSE;
218 }
219
220 // Set predefined value for LocalizationView:
221 if ($this->modTSconfig['properties']['enableLocalizationView'] === 'activated') {
222 $this->MOD_SETTINGS['localization'] = TRUE;
223 } elseif ($this->modTSconfig['properties']['enableLocalizationView'] === 'deactivated') {
224 $this->MOD_SETTINGS['localization'] = FALSE;
225 }
226
227 // Initialize the dblist object:
228 $dblist = t3lib_div::makeInstance('localRecordList');
229 $dblist->backPath = $BACK_PATH;
230 $dblist->script = t3lib_BEfunc::getModuleUrl('web_list', array(), '');
231 $dblist->calcPerms = $BE_USER->calcPerms($this->pageinfo);
232 $dblist->thumbs = $BE_USER->uc['thumbnailsByDefault'];
233 $dblist->returnUrl=$this->returnUrl;
234 $dblist->allFields = ($this->MOD_SETTINGS['bigControlPanel'] || $this->table) ? 1 : 0;
235 $dblist->localizationView = $this->MOD_SETTINGS['localization'];
236 $dblist->showClipboard = 1;
237 $dblist->disableSingleTableView = $this->modTSconfig['properties']['disableSingleTableView'];
238 $dblist->listOnlyInSingleTableMode = $this->modTSconfig['properties']['listOnlyInSingleTableView'];
239 $dblist->hideTables = $this->modTSconfig['properties']['hideTables'];
240 $dblist->tableTSconfigOverTCA = $this->modTSconfig['properties']['table.'];
241 $dblist->clickTitleMode = $this->modTSconfig['properties']['clickTitleMode'];
242 $dblist->alternateBgColors=$this->modTSconfig['properties']['alternateBgColors']?1:0;
243 $dblist->allowedNewTables = t3lib_div::trimExplode(',', $this->modTSconfig['properties']['allowedNewTables'], 1);
244 $dblist->deniedNewTables = t3lib_div::trimExplode(',', $this->modTSconfig['properties']['deniedNewTables'], 1);
245 $dblist->newWizards=$this->modTSconfig['properties']['newWizards']?1:0;
246 $dblist->pageRow = $this->pageinfo;
247 $dblist->counter++;
248 $dblist->MOD_MENU = array('bigControlPanel' => '', 'clipBoard' => '', 'localization' => '');
249 $dblist->modTSconfig = $this->modTSconfig;
250
251 // Clipboard is initialized:
252 $dblist->clipObj = t3lib_div::makeInstance('t3lib_clipboard'); // Start clipboard
253 $dblist->clipObj->initializeClipboard(); // Initialize - reads the clipboard content from the user session
254
255 // Clipboard actions are handled:
256 $CB = t3lib_div::_GET('CB'); // CB is the clipboard command array
257 if ($this->cmd=='setCB') {
258 // 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
259 // This is set to the 'el' array of the CB after being parsed so only the table in question is registered.
260 $CB['el'] = $dblist->clipObj->cleanUpCBC(array_merge((array)t3lib_div::_POST('CBH'),(array)t3lib_div::_POST('CBC')),$this->cmd_table);
261 }
262 if (!$this->MOD_SETTINGS['clipBoard']) $CB['setP']='normal'; // If the clipboard is NOT shown, set the pad to 'normal'.
263 $dblist->clipObj->setCmd($CB); // Execute commands.
264 $dblist->clipObj->cleanCurrent(); // Clean up pad
265 $dblist->clipObj->endClipboard(); // Save the clipboard content
266
267 // This flag will prevent the clipboard panel in being shown.
268 // It is set, if the clickmenu-layer is active AND the extended view is not enabled.
269 $dblist->dontShowClipControlPanels = $CLIENT['FORMSTYLE'] && !$this->MOD_SETTINGS['bigControlPanel'] && $dblist->clipObj->current=='normal' && !$BE_USER->uc['disableCMlayers'] && !$this->modTSconfig['properties']['showClipControlPanelsDespiteOfCMlayers'];
270
271
272
273 // If there is access to the page, then render the list contents and set up the document template object:
274 if ($access) {
275
276 // Deleting records...:
277 // 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.
278 if ($this->cmd=='delete') {
279 $items = $dblist->clipObj->cleanUpCBC(t3lib_div::_POST('CBC'),$this->cmd_table,1);
280 if (count($items)) {
281 $cmd=array();
282 foreach ($items as $iK => $value) {
283 $iKParts = explode('|',$iK);
284 $cmd[$iKParts[0]][$iKParts[1]]['delete']=1;
285 }
286 $tce = t3lib_div::makeInstance('t3lib_TCEmain');
287 $tce->stripslashes_values=0;
288 $tce->start(array(),$cmd);
289 $tce->process_cmdmap();
290
291 if (isset($cmd['pages'])) {
292 t3lib_BEfunc::setUpdateSignal('updatePageTree');
293 }
294
295 $tce->printLogErrorMessages(t3lib_div::getIndpEnv('REQUEST_URI'));
296 }
297 }
298
299 // Initialize the listing object, dblist, for rendering the list:
300 $this->pointer = t3lib_div::intInRange($this->pointer,0,100000);
301 $dblist->start($this->id,$this->table,$this->pointer,$this->search_field,$this->search_levels,$this->showLimit);
302 $dblist->setDispFields();
303
304 // Render versioning selector:
305 if (t3lib_extMgm::isLoaded('version')) {
306 $dblist->HTMLcode .= $this->doc->getVersionSelector($this->id);
307 }
308
309 // Render the list of tables:
310 $dblist->generateList();
311
312 // Write the bottom of the page:
313 $dblist->writeBottom();
314 $listUrl = substr($dblist->listURL(), strlen($GLOBALS['BACK_PATH']));
315 // Add JavaScript functions to the page:
316 $this->doc->JScode=$this->doc->wrapScriptTags('
317 function jumpToUrl(URL) { //
318 window.location.href = URL;
319 return false;
320 }
321 function jumpExt(URL,anchor) { //
322 var anc = anchor?anchor:"";
323 window.location.href = URL+(T3_THIS_LOCATION?"&returnUrl="+T3_THIS_LOCATION:"")+anc;
324 return false;
325 }
326 function jumpSelf(URL) { //
327 window.location.href = URL+(T3_RETURN_URL?"&returnUrl="+T3_RETURN_URL:"");
328 return false;
329 }
330
331 function setHighlight(id) { //
332 top.fsMod.recentIds["web"]=id;
333 top.fsMod.navFrameHighlightedID["web"]="pages"+id+"_"+top.fsMod.currentBank; // For highlighting
334
335 if (top.content && top.content.nav_frame && top.content.nav_frame.refresh_nav) {
336 top.content.nav_frame.refresh_nav();
337 }
338 }
339 ' . $this->doc->redirectUrls($listUrl) . '
340 '.$dblist->CBfunctions().'
341 function editRecords(table,idList,addParams,CBflag) { //
342 window.location.href="'.$BACK_PATH.'alt_doc.php?returnUrl='.rawurlencode(t3lib_div::getIndpEnv('REQUEST_URI')).
343 '&edit["+table+"]["+idList+"]=edit"+addParams;
344 }
345 function editList(table,idList) { //
346 var list="";
347
348 // Checking how many is checked, how many is not
349 var pointer=0;
350 var pos = idList.indexOf(",");
351 while (pos!=-1) {
352 if (cbValue(table+"|"+idList.substr(pointer,pos-pointer))) {
353 list+=idList.substr(pointer,pos-pointer)+",";
354 }
355 pointer=pos+1;
356 pos = idList.indexOf(",",pointer);
357 }
358 if (cbValue(table+"|"+idList.substr(pointer))) {
359 list+=idList.substr(pointer)+",";
360 }
361
362 return list ? list : idList;
363 }
364
365 if (top.fsMod) top.fsMod.recentIds["web"] = '.intval($this->id).';
366 ');
367
368 // Setting up the context sensitive menu:
369 $this->doc->getContextMenuCode();
370 } // access
371
372 // Begin to compile the whole page, starting out with page header:
373 $this->body='';
374 $this->body.= '<form action="'.htmlspecialchars($dblist->listURL()).'" method="post" name="dblistForm">';
375 $this->body.= $dblist->HTMLcode;
376 $this->body.= '<input type="hidden" name="cmd_table" /><input type="hidden" name="cmd" /></form>';
377
378 // If a listing was produced, create the page footer with search form etc:
379 if ($dblist->HTMLcode) {
380
381 // Making field select box (when extended view for a single table is enabled):
382 if ($dblist->table) {
383 $this->body.=$dblist->fieldSelectBox($dblist->table);
384 }
385
386 // Adding checkbox options for extended listing and clipboard display:
387 $this->body.='
388
389 <!--
390 Listing options for extended view, clipboard and localization view
391 -->
392 <div id="typo3-listOptions">
393 <form action="" method="post">';
394
395 // Add "display bigControlPanel" checkbox:
396 if ($this->modTSconfig['properties']['enableDisplayBigControlPanel'] === 'selectable') {
397 $this->body .= t3lib_BEfunc::getFuncCheck(
398 $this->id,
399 'SET[bigControlPanel]',
400 $this->MOD_SETTINGS['bigControlPanel'],
401 '',
402 ($this->table ? '&table=' . $this->table : ''),
403 'id="checkLargeControl"'
404 );
405 $this->body .= '<label for="checkLargeControl">' .
406 t3lib_BEfunc::wrapInHelp(
407 'xMOD_csh_corebe',
408 'list_options',
409 $GLOBALS['LANG']->getLL('largeControl', TRUE)
410 ) . '</label><br />';
411 }
412
413 // Add "clipboard" checkbox:
414 if ($this->modTSconfig['properties']['enableClipBoard'] === 'selectable') {
415 if ($dblist->showClipboard) {
416 $this->body .= t3lib_BEfunc::getFuncCheck(
417 $this->id,
418 'SET[clipBoard]',
419 $this->MOD_SETTINGS['clipBoard'],
420 '',
421 ($this->table ? '&table=' . $this->table : ''),
422 'id="checkShowClipBoard"'
423 );
424 $this->body .= '<label for="checkShowClipBoard">' .
425 t3lib_BEfunc::wrapInHelp(
426 'xMOD_csh_corebe',
427 'list_options',
428 $GLOBALS['LANG']->getLL('showClipBoard', TRUE)
429 ) . '</label><br />';
430 }
431 }
432
433 // Add "localization view" checkbox:
434 if ($this->modTSconfig['properties']['enableLocalizationView'] === 'selectable') {
435 $this->body .= t3lib_BEfunc::getFuncCheck(
436 $this->id,
437 'SET[localization]',
438 $this->MOD_SETTINGS['localization'],
439 '',
440 ($this->table ? '&table=' . $this->table : ''),
441 'id="checkLocalization"'
442 );
443 $this->body .= '<label for="checkLocalization">' .
444 t3lib_BEfunc::wrapInHelp(
445 'xMOD_csh_corebe',
446 'list_options',
447 $GLOBALS['LANG']->getLL('localization', TRUE)
448 ) . '</label><br />';
449 }
450
451 $this->body.='
452 </form>
453 </div>';
454
455 // Printing clipboard if enabled:
456 if ($this->MOD_SETTINGS['clipBoard'] && $dblist->showClipboard) {
457 $this->body.= $dblist->clipObj->printClipboard();
458 }
459
460 // Search box:
461 $sectionTitle = t3lib_BEfunc::wrapInHelp('xMOD_csh_corebe', 'list_searchbox', $LANG->sL('LLL:EXT:lang/locallang_core.php:labels.search', TRUE));
462 $this->body .= $this->doc->section(
463 $sectionTitle,
464 $dblist->getSearchBox(),
465 FALSE, TRUE, FALSE, TRUE
466 );
467
468 // Display sys-notes, if any are found:
469 $this->body.=$dblist->showSysNotesForPage();
470 }
471
472 // Setting up the buttons and markers for docheader
473 $docHeaderButtons = $dblist->getButtons();
474 $markers = array(
475 'CSH' => $docHeaderButtons['csh'],
476 'CONTENT' => $this->body
477 );
478
479 // Build the <body> for the module
480 $this->content = $this->doc->moduleBody($this->pageinfo, $docHeaderButtons, $markers);
481 // Renders the module page
482 $this->content = $this->doc->render(
483 'DB list',
484 $this->content
485 );
486 }
487
488 /**
489 * Outputting the accumulated content to screen
490 *
491 * @return void
492 */
493 function printContent() {
494 echo $this->content;
495 }
496
497 }
498
499
500 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/db_list.php'])) {
501 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/db_list.php']);
502 }
503
504
505
506 // Make instance:
507 $SOBE = t3lib_div::makeInstance('SC_db_list');
508 $SOBE->init();
509
510 // Include files?
511 foreach($SOBE->include_once as $INC_FILE) include_once($INC_FILE);
512
513 $SOBE->clearCache();
514 $SOBE->main();
515 $SOBE->printContent();
516
517 ?>