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