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