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