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