[TASK] Remove trailing newlines from EOF
[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 * [CLASS/FUNCTION INDEX of SCRIPT]
43 *
44 *
45 *
46 * 89: class SC_db_list
47 * 125: function init()
48 * 160: function menuConfig()
49 * 181: function clearCache()
50 * 195: function main()
51 * 451: function printContent()
52 *
53 * TOTAL FUNCTIONS: 5
54 * (This index is automatically created/updated by the extension "extdeveval")
55 *
56 */
57
58
59 $LANG->includeLLFile('EXT:lang/locallang_mod_web_list.xml');
60 require_once ($BACK_PATH.'class.db_list.inc');
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
124 // Setting module configuration / page select clause
125 $this->MCONF = $GLOBALS['MCONF'];
126 $this->perms_clause = $GLOBALS['BE_USER']->getPagePermsClause(1);
127
128 // GPvars:
129 $this->id = t3lib_div::_GP('id');
130 $this->pointer = t3lib_div::_GP('pointer');
131 $this->imagemode = t3lib_div::_GP('imagemode');
132 $this->table = t3lib_div::_GP('table');
133 $this->search_field = t3lib_div::_GP('search_field');
134 $this->search_levels = t3lib_div::_GP('search_levels');
135 $this->showLimit = t3lib_div::_GP('showLimit');
136 $this->returnUrl = t3lib_div::sanitizeLocalUrl(t3lib_div::_GP('returnUrl'));
137
138 $this->clear_cache = t3lib_div::_GP('clear_cache');
139 $this->cmd = t3lib_div::_GP('cmd');
140 $this->cmd_table = t3lib_div::_GP('cmd_table');
141
142 // Initialize menu
143 $this->menuConfig();
144
145 // Inclusions?
146 if ($this->clear_cache || $this->cmd=='delete') {
147 $this->include_once[]=PATH_t3lib.'class.t3lib_tcemain.php';
148 }
149 }
150
151 /**
152 * Initialize function menu array
153 *
154 * @return void
155 */
156 function menuConfig() {
157
158 // MENU-ITEMS:
159 $this->MOD_MENU = array(
160 'bigControlPanel' => '',
161 'clipBoard' => '',
162 'localization' => ''
163 );
164
165 // Loading module configuration:
166 $this->modTSconfig = t3lib_BEfunc::getModTSconfig($this->id,'mod.'.$this->MCONF['name']);
167
168 // Clean up settings:
169 $this->MOD_SETTINGS = t3lib_BEfunc::getModuleData($this->MOD_MENU, t3lib_div::_GP('SET'), $this->MCONF['name']);
170 }
171
172 /**
173 * Clears page cache for the current id, $this->id
174 *
175 * @return void
176 */
177 function clearCache() {
178 if ($this->clear_cache) {
179 $tce = t3lib_div::makeInstance('t3lib_TCEmain');
180 $tce->stripslashes_values=0;
181 $tce->start(Array(),Array());
182 $tce->clear_cacheCmd($this->id);
183 }
184 }
185
186 /**
187 * Main function, starting the rendering of the list.
188 *
189 * @return void
190 */
191 function main() {
192 // Start document template object:
193 $this->doc = t3lib_div::makeInstance('template');
194 $this->doc->backPath = $GLOBALS['BACK_PATH'];
195 $this->doc->setModuleTemplate('templates/db_list.html');
196
197 // Loading current page record and checking access:
198 $this->pageinfo = t3lib_BEfunc::readPageAccess($this->id,$this->perms_clause);
199 $access = is_array($this->pageinfo) ? 1 : 0;
200
201 // Apply predefined values for hidden checkboxes
202 // Set predefined value for DisplayBigControlPanel:
203 if ($this->modTSconfig['properties']['enableDisplayBigControlPanel'] === 'activated') {
204 $this->MOD_SETTINGS['bigControlPanel'] = TRUE;
205 } elseif ($this->modTSconfig['properties']['enableDisplayBigControlPanel'] === 'deactivated') {
206 $this->MOD_SETTINGS['bigControlPanel'] = FALSE;
207 }
208
209 // Set predefined value for Clipboard:
210 if ($this->modTSconfig['properties']['enableClipBoard'] === 'activated') {
211 $this->MOD_SETTINGS['clipBoard'] = TRUE;
212 } elseif ($this->modTSconfig['properties']['enableClipBoard'] === 'deactivated') {
213 $this->MOD_SETTINGS['clipBoard'] = FALSE;
214 }
215
216 // Set predefined value for LocalizationView:
217 if ($this->modTSconfig['properties']['enableLocalizationView'] === 'activated') {
218 $this->MOD_SETTINGS['localization'] = TRUE;
219 } elseif ($this->modTSconfig['properties']['enableLocalizationView'] === 'deactivated') {
220 $this->MOD_SETTINGS['localization'] = FALSE;
221 }
222
223 // Initialize the dblist object:
224 $dblist = t3lib_div::makeInstance('localRecordList');
225 $dblist->backPath = $GLOBALS['BACK_PATH'];
226 $dblist->script = t3lib_BEfunc::getModuleUrl('web_list', array(), '');
227 $dblist->calcPerms = $GLOBALS['BE_USER']->calcPerms($this->pageinfo);
228 $dblist->thumbs = $GLOBALS['BE_USER']->uc['thumbnailsByDefault'];
229 $dblist->returnUrl=$this->returnUrl;
230 $dblist->allFields = ($this->MOD_SETTINGS['bigControlPanel'] || $this->table) ? 1 : 0;
231 $dblist->localizationView = $this->MOD_SETTINGS['localization'];
232 $dblist->showClipboard = 1;
233 $dblist->disableSingleTableView = $this->modTSconfig['properties']['disableSingleTableView'];
234 $dblist->listOnlyInSingleTableMode = $this->modTSconfig['properties']['listOnlyInSingleTableView'];
235 $dblist->hideTables = $this->modTSconfig['properties']['hideTables'];
236 $dblist->tableTSconfigOverTCA = $this->modTSconfig['properties']['table.'];
237 $dblist->clickTitleMode = $this->modTSconfig['properties']['clickTitleMode'];
238 $dblist->alternateBgColors=$this->modTSconfig['properties']['alternateBgColors']?1:0;
239 $dblist->allowedNewTables = t3lib_div::trimExplode(',', $this->modTSconfig['properties']['allowedNewTables'], 1);
240 $dblist->deniedNewTables = t3lib_div::trimExplode(',', $this->modTSconfig['properties']['deniedNewTables'], 1);
241 $dblist->newWizards=$this->modTSconfig['properties']['newWizards']?1:0;
242 $dblist->pageRow = $this->pageinfo;
243 $dblist->counter++;
244 $dblist->MOD_MENU = array('bigControlPanel' => '', 'clipBoard' => '', 'localization' => '');
245 $dblist->modTSconfig = $this->modTSconfig;
246
247 // Clipboard is initialized:
248 $dblist->clipObj = t3lib_div::makeInstance('t3lib_clipboard'); // Start clipboard
249 $dblist->clipObj->initializeClipboard(); // Initialize - reads the clipboard content from the user session
250
251 // Clipboard actions are handled:
252 $CB = t3lib_div::_GET('CB'); // CB is the clipboard command array
253 if ($this->cmd=='setCB') {
254 // 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
255 // This is set to the 'el' array of the CB after being parsed so only the table in question is registered.
256 $CB['el'] = $dblist->clipObj->cleanUpCBC(array_merge((array)t3lib_div::_POST('CBH'),(array)t3lib_div::_POST('CBC')),$this->cmd_table);
257 }
258 if (!$this->MOD_SETTINGS['clipBoard']) $CB['setP']='normal'; // If the clipboard is NOT shown, set the pad to 'normal'.
259 $dblist->clipObj->setCmd($CB); // Execute commands.
260 $dblist->clipObj->cleanCurrent(); // Clean up pad
261 $dblist->clipObj->endClipboard(); // Save the clipboard content
262
263 // This flag will prevent the clipboard panel in being shown.
264 // It is set, if the clickmenu-layer is active AND the extended view is not enabled.
265 $dblist->dontShowClipControlPanels = $GLOBALS['CLIENT']['FORMSTYLE'] && !$this->MOD_SETTINGS['bigControlPanel']
266 && $dblist->clipObj->current=='normal' && !$GLOBALS['BE_USER']->uc['disableCMlayers']
267 && !$this->modTSconfig['properties']['showClipControlPanelsDespiteOfCMlayers'];
268
269
270
271 // If there is access to the page, then render the list contents and set up the document template object:
272 if ($access) {
273
274 // Deleting records...:
275 // 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.
276 if ($this->cmd=='delete') {
277 $items = $dblist->clipObj->cleanUpCBC(t3lib_div::_POST('CBC'),$this->cmd_table,1);
278 if (count($items)) {
279 $cmd=array();
280 foreach ($items as $iK => $value) {
281 $iKParts = explode('|',$iK);
282 $cmd[$iKParts[0]][$iKParts[1]]['delete']=1;
283 }
284 $tce = t3lib_div::makeInstance('t3lib_TCEmain');
285 $tce->stripslashes_values=0;
286 $tce->start(array(),$cmd);
287 $tce->process_cmdmap();
288
289 if (isset($cmd['pages'])) {
290 t3lib_BEfunc::setUpdateSignal('updatePageTree');
291 }
292
293 $tce->printLogErrorMessages(t3lib_div::getIndpEnv('REQUEST_URI'));
294 }
295 }
296
297 // Initialize the listing object, dblist, for rendering the list:
298 $this->pointer = t3lib_div::intInRange($this->pointer,0,100000);
299 $dblist->start($this->id,$this->table,$this->pointer,$this->search_field,$this->search_levels,$this->showLimit);
300 $dblist->setDispFields();
301
302 // Render versioning selector:
303 if (t3lib_extMgm::isLoaded('version')) {
304 $dblist->HTMLcode .= $this->doc->getVersionSelector($this->id);
305 }
306
307 // Render the list of tables:
308 $dblist->generateList();
309
310 // Write the bottom of the page:
311 $dblist->writeBottom();
312 $listUrl = substr($dblist->listURL(), strlen($GLOBALS['BACK_PATH']));
313 // Add JavaScript functions to the page:
314 $this->doc->JScode=$this->doc->wrapScriptTags('
315 function jumpToUrl(URL) { //
316 window.location.href = URL;
317 return false;
318 }
319 function jumpExt(URL,anchor) { //
320 var anc = anchor?anchor:"";
321 window.location.href = URL+(T3_THIS_LOCATION?"&returnUrl="+T3_THIS_LOCATION:"")+anc;
322 return false;
323 }
324 function jumpSelf(URL) { //
325 window.location.href = URL+(T3_RETURN_URL?"&returnUrl="+T3_RETURN_URL:"");
326 return false;
327 }
328
329 function setHighlight(id) { //
330 top.fsMod.recentIds["web"]=id;
331 top.fsMod.navFrameHighlightedID["web"]="pages"+id+"_"+top.fsMod.currentBank; // For highlighting
332
333 if (top.content && top.content.nav_frame && top.content.nav_frame.refresh_nav) {
334 top.content.nav_frame.refresh_nav();
335 }
336 }
337 ' . $this->doc->redirectUrls($listUrl) . '
338 '.$dblist->CBfunctions().'
339 function editRecords(table,idList,addParams,CBflag) { //
340 window.location.href="' . $GLOBALS['BACK_PATH'] . 'alt_doc.php?returnUrl=' . rawurlencode(t3lib_div::getIndpEnv('REQUEST_URI')) .
341 '&edit["+table+"]["+idList+"]=edit"+addParams;
342 }
343 function editList(table,idList) { //
344 var list="";
345
346 // Checking how many is checked, how many is not
347 var pointer=0;
348 var pos = idList.indexOf(",");
349 while (pos!=-1) {
350 if (cbValue(table+"|"+idList.substr(pointer,pos-pointer))) {
351 list+=idList.substr(pointer,pos-pointer)+",";
352 }
353 pointer=pos+1;
354 pos = idList.indexOf(",",pointer);
355 }
356 if (cbValue(table+"|"+idList.substr(pointer))) {
357 list+=idList.substr(pointer)+",";
358 }
359
360 return list ? list : idList;
361 }
362
363 if (top.fsMod) top.fsMod.recentIds["web"] = '.intval($this->id).';
364 ');
365
366 // Setting up the context sensitive menu:
367 $this->doc->getContextMenuCode();
368 } // access
369
370 // Begin to compile the whole page, starting out with page header:
371 $this->body='';
372 $this->body.= '<form action="'.htmlspecialchars($dblist->listURL()).'" method="post" name="dblistForm">';
373 $this->body.= $dblist->HTMLcode;
374 $this->body.= '<input type="hidden" name="cmd_table" /><input type="hidden" name="cmd" /></form>';
375
376 // If a listing was produced, create the page footer with search form etc:
377 if ($dblist->HTMLcode) {
378
379 // Making field select box (when extended view for a single table is enabled):
380 if ($dblist->table) {
381 $this->body.=$dblist->fieldSelectBox($dblist->table);
382 }
383
384 // Adding checkbox options for extended listing and clipboard display:
385 $this->body.='
386
387 <!--
388 Listing options for extended view, clipboard and localization view
389 -->
390 <div id="typo3-listOptions">
391 <form action="" method="post">';
392
393 // Add "display bigControlPanel" checkbox:
394 if ($this->modTSconfig['properties']['enableDisplayBigControlPanel'] === 'selectable') {
395 $this->body .= t3lib_BEfunc::getFuncCheck(
396 $this->id,
397 'SET[bigControlPanel]',
398 $this->MOD_SETTINGS['bigControlPanel'],
399 '',
400 ($this->table ? '&table=' . $this->table : ''),
401 'id="checkLargeControl"'
402 );
403 $this->body .= '<label for="checkLargeControl">' .
404 t3lib_BEfunc::wrapInHelp(
405 'xMOD_csh_corebe',
406 'list_options',
407 $GLOBALS['LANG']->getLL('largeControl', TRUE)
408 ) . '</label><br />';
409 }
410
411 // Add "clipboard" checkbox:
412 if ($this->modTSconfig['properties']['enableClipBoard'] === 'selectable') {
413 if ($dblist->showClipboard) {
414 $this->body .= t3lib_BEfunc::getFuncCheck(
415 $this->id,
416 'SET[clipBoard]',
417 $this->MOD_SETTINGS['clipBoard'],
418 '',
419 ($this->table ? '&table=' . $this->table : ''),
420 'id="checkShowClipBoard"'
421 );
422 $this->body .= '<label for="checkShowClipBoard">' .
423 t3lib_BEfunc::wrapInHelp(
424 'xMOD_csh_corebe',
425 'list_options',
426 $GLOBALS['LANG']->getLL('showClipBoard', TRUE)
427 ) . '</label><br />';
428 }
429 }
430
431 // Add "localization view" checkbox:
432 if ($this->modTSconfig['properties']['enableLocalizationView'] === 'selectable') {
433 $this->body .= t3lib_BEfunc::getFuncCheck(
434 $this->id,
435 'SET[localization]',
436 $this->MOD_SETTINGS['localization'],
437 '',
438 ($this->table ? '&table=' . $this->table : ''),
439 'id="checkLocalization"'
440 );
441 $this->body .= '<label for="checkLocalization">' .
442 t3lib_BEfunc::wrapInHelp(
443 'xMOD_csh_corebe',
444 'list_options',
445 $GLOBALS['LANG']->getLL('localization', TRUE)
446 ) . '</label><br />';
447 }
448
449 $this->body.='
450 </form>
451 </div>';
452
453 // Printing clipboard if enabled:
454 if ($this->MOD_SETTINGS['clipBoard'] && $dblist->showClipboard) {
455 $this->body.= $dblist->clipObj->printClipboard();
456 }
457
458 // Search box:
459 if (!$this->modTSconfig['properties']['disableSearchBox']) {
460 $sectionTitle = t3lib_BEfunc::wrapInHelp('xMOD_csh_corebe', 'list_searchbox', $GLOBALS['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
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 ?>