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