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