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