Added initial support for workspaces in core.
[Packages/TYPO3.CMS.git] / typo3 / db_list.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2005 Kasper Skaarhoj (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 $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 * $Id$
37 * Revised for TYPO3 3.6 November/2003 by Kasper Skaarhoj
38 * XHTML compliant
39 *
40 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
41 */
42 /**
43 * [CLASS/FUNCTION INDEX of SCRIPT]
44 *
45 *
46 *
47 * 89: class SC_db_list
48 * 125: function init()
49 * 160: function menuConfig()
50 * 181: function clearCache()
51 * 195: function main()
52 * 435: function printContent()
53 *
54 * TOTAL FUNCTIONS: 5
55 * (This index is automatically created/updated by the extension "extdeveval")
56 *
57 */
58
59
60 unset($MCONF);
61 require ('mod/web/list/conf.php');
62 require ('init.php');
63 require ('template.php');
64 $LANG->includeLLFile('EXT:lang/locallang_mod_web_list.xml');
65 require_once (PATH_t3lib.'class.t3lib_page.php');
66 require_once (PATH_t3lib.'class.t3lib_pagetree.php');
67 require_once (PATH_t3lib.'class.t3lib_recordlist.php');
68 require_once (PATH_t3lib.'class.t3lib_clipboard.php');
69 require_once ('class.db_list.inc');
70 require_once ('class.db_list_extra.inc');
71 $BE_USER->modAccess($MCONF,1);
72
73 t3lib_BEfunc::lockRecords();
74
75
76
77
78
79
80
81
82 /**
83 * Script Class for the Web > List module; rendering the listing of records on a page
84 *
85 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
86 * @package TYPO3
87 * @subpackage core
88 */
89 class SC_db_list {
90
91 // Internal, GPvars:
92 var $id; // Page Id for which to make the listing
93 var $pointer; // Pointer - for browsing list of records.
94 var $imagemode; // Thumbnails or not
95 var $table; // Which table to make extended listing for
96 var $search_field; // Search-fields
97 var $search_levels; // Search-levels
98 var $showLimit; // Show-limit
99 var $returnUrl; // Return URL
100
101 var $clear_cache; // Clear-cache flag - if set, clears page cache for current id.
102 var $cmd; // Command: Eg. "delete" or "setCB" (for TCEmain / clipboard operations)
103 var $cmd_table; // Table on which the cmd-action is performed.
104
105 // Internal, static:
106 var $perms_clause; // Page select perms clause
107 var $modTSconfig; // Module TSconfig
108 var $pageinfo; // Current ids page record
109 var $doc; // Document template object
110
111 var $MCONF=array(); // Module configuration
112 var $MOD_MENU=array(); // Menu configuration
113 var $MOD_SETTINGS=array(); // Module settings (session variable)
114 var $include_once=array(); // Array, where files to include is accumulated in the init() function
115
116 // Internal, dynamic:
117 var $content; // Module output accumulation
118
119
120 /**
121 * Initializing the module
122 *
123 * @return void
124 */
125 function init() {
126 global $BE_USER;
127
128 // Setting module configuration / page select clause
129 $this->MCONF = $GLOBALS['MCONF'];
130 $this->perms_clause = $BE_USER->getPagePermsClause(1);
131
132 // GPvars:
133 $this->id = t3lib_div::_GP('id');
134 $this->pointer = t3lib_div::_GP('pointer');
135 $this->imagemode = t3lib_div::_GP('imagemode');
136 $this->table = t3lib_div::_GP('table');
137 $this->search_field = t3lib_div::_GP('search_field');
138 $this->search_levels = t3lib_div::_GP('search_levels');
139 $this->showLimit = t3lib_div::_GP('showLimit');
140 $this->returnUrl = t3lib_div::_GP('returnUrl');
141
142 $this->clear_cache = t3lib_div::_GP('clear_cache');
143 $this->cmd = t3lib_div::_GP('cmd');
144 $this->cmd_table = t3lib_div::_GP('cmd_table');
145
146 // Initialize menu
147 $this->menuConfig();
148
149 // Inclusions?
150 if ($this->clear_cache || $this->cmd=='delete') {
151 $this->include_once[]=PATH_t3lib.'class.t3lib_tcemain.php';
152 }
153 }
154
155 /**
156 * Initialize function menu array
157 *
158 * @return void
159 */
160 function menuConfig() {
161
162 // MENU-ITEMS:
163 $this->MOD_MENU = array(
164 'bigControlPanel' => '',
165 'clipBoard' => '',
166 'localization' => ''
167 );
168
169 // Loading module configuration:
170 $this->modTSconfig = t3lib_BEfunc::getModTSconfig($this->id,'mod.'.$this->MCONF['name']);
171
172 // Clean up settings:
173 $this->MOD_SETTINGS = t3lib_BEfunc::getModuleData($this->MOD_MENU, t3lib_div::_GP('SET'), $this->MCONF['name']);
174 }
175
176 /**
177 * Clears page cache for the current id, $this->id
178 *
179 * @return void
180 */
181 function clearCache() {
182 if ($this->clear_cache) {
183 $tce = t3lib_div::makeInstance('t3lib_TCEmain');
184 $tce->stripslashes_values=0;
185 $tce->start(Array(),Array());
186 $tce->clear_cacheCmd($this->id);
187 }
188 }
189
190 /**
191 * Main function, starting the rendering of the list.
192 *
193 * @return void
194 */
195 function main() {
196 global $BE_USER,$LANG,$BACK_PATH,$CLIENT;
197
198 // Start document template object:
199 $this->doc = t3lib_div::makeInstance('template');
200 $this->doc->backPath = $BACK_PATH;
201 $this->doc->docType='xhtml_trans';
202
203 // Loading current page record and checking access:
204 $this->pageinfo = t3lib_BEfunc::readPageAccess($this->id,$this->perms_clause);
205 $access = is_array($this->pageinfo) ? 1 : 0;
206
207 // Initialize the dblist object:
208 $dblist = t3lib_div::makeInstance('localRecordList');
209 $dblist->backPath = $BACK_PATH;
210 $dblist->calcPerms = $BE_USER->calcPerms($this->pageinfo);
211 $dblist->thumbs = $BE_USER->uc['thumbnailsByDefault'];
212 $dblist->returnUrl=$this->returnUrl;
213 $dblist->allFields = ($this->MOD_SETTINGS['bigControlPanel'] || $this->table) ? 1 : 0;
214 $dblist->localizationView = $this->MOD_SETTINGS['localization'];
215 $dblist->showClipboard = 1;
216 $dblist->disableSingleTableView = $this->modTSconfig['properties']['disableSingleTableView'];
217 $dblist->listOnlyInSingleTableMode = $this->modTSconfig['properties']['listOnlyInSingleTableView'];
218 $dblist->clickTitleMode = $this->modTSconfig['properties']['clickTitleMode'];
219 $dblist->alternateBgColors=$this->modTSconfig['properties']['alternateBgColors']?1:0;
220 $dblist->allowedNewTables = t3lib_div::trimExplode(',',$this->modTSconfig['properties']['allowedNewTables'],1);
221 $dblist->newWizards=$this->modTSconfig['properties']['newWizards']?1:0;
222
223
224
225 // Clipboard is initialized:
226 $dblist->clipObj = t3lib_div::makeInstance('t3lib_clipboard'); // Start clipboard
227 $dblist->clipObj->initializeClipboard(); // Initialize - reads the clipboard content from the user session
228
229 // Clipboard actions are handled:
230 $CB = t3lib_div::_GET('CB'); // CB is the clipboard command array
231 if ($this->cmd=='setCB') {
232 // CBH is all the fields selected for the clipboard, CBC is the checkbox fields which were checked. By merging we get a full array of checked/unchecked elements
233 // This is set to the 'el' array of the CB after being parsed so only the table in question is registered.
234 $CB['el'] = $dblist->clipObj->cleanUpCBC(array_merge((array)t3lib_div::_POST('CBH'),(array)t3lib_div::_POST('CBC')),$this->cmd_table);
235 }
236 if (!$this->MOD_SETTINGS['clipBoard']) $CB['setP']='normal'; // If the clipboard is NOT shown, set the pad to 'normal'.
237 $dblist->clipObj->setCmd($CB); // Execute commands.
238 $dblist->clipObj->cleanCurrent(); // Clean up pad
239 $dblist->clipObj->endClipboard(); // Save the clipboard content
240
241 // This flag will prevent the clipboard panel in being shown.
242 // It is set, if the clickmenu-layer is active AND the extended view is not enabled.
243 $dblist->dontShowClipControlPanels = $CLIENT['FORMSTYLE'] && !$this->MOD_SETTINGS['bigControlPanel'] && $dblist->clipObj->current=='normal' && !$BE_USER->uc['disableCMlayers'] && !$this->modTSconfig['properties']['showClipControlPanelsDespiteOfCMlayers'];
244
245
246
247 // If there is access to the page, then render the list contents and set up the document template object:
248 if ($access) {
249
250 // Deleting records...:
251 // 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.
252 if ($this->cmd=='delete') {
253 $items = $dblist->clipObj->cleanUpCBC(t3lib_div::_POST('CBC'),$this->cmd_table,1);
254 if (count($items)) {
255 $cmd=array();
256 reset($items);
257 while(list($iK)=each($items)) {
258 $iKParts = explode('|',$iK);
259 $cmd[$iKParts[0]][$iKParts[1]]['delete']=1;
260 }
261 $tce = t3lib_div::makeInstance('t3lib_TCEmain');
262 $tce->stripslashes_values=0;
263 $tce->start(array(),$cmd);
264 $tce->process_cmdmap();
265
266 if (isset($cmd['pages'])) {
267 t3lib_BEfunc::getSetUpdateSignal('updatePageTree');
268 }
269
270 $tce->printLogErrorMessages(t3lib_div::getIndpEnv('REQUEST_URI'));
271 }
272 }
273
274 // Initialize the listing object, dblist, for rendering the list:
275 $this->pointer = t3lib_div::intInRange($this->pointer,0,100000);
276 $dblist->start($this->id,$this->table,$this->pointer,$this->search_field,$this->search_levels,$this->showLimit);
277 $dblist->setDispFields();
278
279 // Render the page header:
280 $dblist->writeTop($this->pageinfo);
281
282 // Render versioning selector:
283 $dblist->HTMLcode.= $this->doc->getVersionSelector($this->id);
284
285 // Render the list of tables:
286 $dblist->generateList();
287
288 // Write the bottom of the page:
289 $dblist->writeBottom();
290
291 // Add JavaScript functions to the page:
292 $this->doc->JScode=$this->doc->wrapScriptTags('
293 function jumpToUrl(URL) { //
294 document.location = URL;
295 return false;
296 }
297 function jumpExt(URL,anchor) { //
298 var anc = anchor?anchor:"";
299 document.location = URL+(T3_THIS_LOCATION?"&returnUrl="+T3_THIS_LOCATION:"")+anc;
300 return false;
301 }
302 function jumpSelf(URL) { //
303 document.location = URL+(T3_RETURN_URL?"&returnUrl="+T3_RETURN_URL:"");
304 return false;
305 }
306 '.$this->doc->redirectUrls($dblist->listURL()).'
307 '.$dblist->CBfunctions().'
308 function editRecords(table,idList,addParams,CBflag) { //
309 document.location="'.$backPath.'alt_doc.php?returnUrl='.rawurlencode(t3lib_div::getIndpEnv('REQUEST_URI')).
310 '&edit["+table+"]["+idList+"]=edit"+addParams;
311 }
312 function editList(table,idList) { //
313 var list="";
314
315 // Checking how many is checked, how many is not
316 var pointer=0;
317 var pos = idList.indexOf(",");
318 while (pos!=-1) {
319 if (cbValue(table+"|"+idList.substr(pointer,pos-pointer))) {
320 list+=idList.substr(pointer,pos-pointer)+",";
321 }
322 pointer=pos+1;
323 pos = idList.indexOf(",",pointer);
324 }
325 if (cbValue(table+"|"+idList.substr(pointer))) {
326 list+=idList.substr(pointer)+",";
327 }
328
329 return list ? list : idList;
330 }
331
332 if (top.fsMod) top.fsMod.recentIds["web"] = '.intval($this->id).';
333 ');
334
335 // Setting up the context sensitive menu:
336 $CMparts=$this->doc->getContextMenuCode();
337 $this->doc->bodyTagAdditions = $CMparts[1];
338 $this->doc->JScode.=$CMparts[0];
339 $this->doc->postCode.= $CMparts[2];
340 } // access
341
342
343
344 // Begin to compile the whole page, starting out with page header:
345 $this->content='';
346 $this->content.=$this->doc->startPage('DB list');
347 $this->content.= '<form action="'.htmlspecialchars($dblist->listURL()).'" method="post" name="dblistForm">';
348
349 // List Module CSH:
350 if (!strlen($this->id)) {
351 $this->content.= t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'list_module_noId', $GLOBALS['BACK_PATH'],'<br/>|');
352 } elseif (!$this->id) { // zero...:
353 $this->content.= t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'list_module_root', $GLOBALS['BACK_PATH'],'<br/>|');
354 }
355
356 // Add listing HTML code:
357 $this->content.= $dblist->HTMLcode;
358 $this->content.= '<input type="hidden" name="cmd_table" /><input type="hidden" name="cmd" /></form>';
359
360 // List Module CSH:
361 if ($this->id) {
362 $this->content.= t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'list_module', $GLOBALS['BACK_PATH'],'<br/>|');
363 }
364
365
366 // If a listing was produced, create the page footer with search form etc:
367 if ($dblist->HTMLcode) {
368
369 // Making field select box (when extended view for a single table is enabled):
370 if ($dblist->table) {
371 $this->content.=$dblist->fieldSelectBox($dblist->table);
372 }
373
374 // Adding checkbox options for extended listing and clipboard display:
375 $this->content.='
376
377 <!--
378 Listing options for clipboard and thumbnails
379 -->
380 <div id="typo3-listOptions">
381 <form action="" method="post">';
382
383 $this->content.=t3lib_BEfunc::getFuncCheck($this->id,'SET[bigControlPanel]',$this->MOD_SETTINGS['bigControlPanel'],'db_list.php','').' '.$LANG->getLL('largeControl',1).'<br />';
384 if ($dblist->showClipboard) {
385 $this->content.=t3lib_BEfunc::getFuncCheck($this->id,'SET[clipBoard]',$this->MOD_SETTINGS['clipBoard'],'db_list.php','').' '.$LANG->getLL('showClipBoard',1).'<br />';
386 }
387 $this->content.=t3lib_BEfunc::getFuncCheck($this->id,'SET[localization]',$this->MOD_SETTINGS['localization'],'db_list.php','').' '.$LANG->getLL('localization',1).'<br />';
388 $this->content.='
389 </form>
390 </div>';
391 $this->content.= t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'list_options', $GLOBALS['BACK_PATH']);
392
393 // Printing clipboard if enabled:
394 if ($this->MOD_SETTINGS['clipBoard'] && $dblist->showClipboard) {
395 $this->content.= $dblist->clipObj->printClipboard();
396 $this->content.= t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'list_clipboard', $GLOBALS['BACK_PATH']);
397 }
398
399 // Link for creating new records:
400 if (!$this->modTSconfig['properties']['noCreateRecordsLink']) {
401 $this->content.='
402
403 <!--
404 Link for creating a new record:
405 -->
406 <div id="typo3-newRecordLink">
407 <a href="'.htmlspecialchars('db_new.php?id='.$this->id.'&returnUrl='.rawurlencode(t3lib_div::getIndpEnv('REQUEST_URI'))).'">'.
408 '<img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/new_el.gif','width="11" height="12"').' alt="" />'.
409 $LANG->getLL('newRecordGeneral',1).
410 '</a>
411 </div>';
412 }
413
414 // Search box:
415 $this->content.=$dblist->getSearchBox();
416
417 // Display sys-notes, if any are found:
418 $this->content.=$dblist->showSysNotesForPage();
419
420 // ShortCut:
421 if ($BE_USER->mayMakeShortcut()) {
422 $this->content.='<br/>'.$this->doc->makeShortcutIcon('id,imagemode,pointer,table,search_field,search_levels,showLimit,sortField,sortRev',implode(',',array_keys($this->MOD_MENU)),$this->MCONF['name']);
423 }
424 }
425
426 // Finally, close off the page:
427 $this->content.= $this->doc->endPage();
428 }
429
430 /**
431 * Outputting the accumulated content to screen
432 *
433 * @return void
434 */
435 function printContent() {
436 echo $this->content;
437 }
438 }
439
440 // Include extension?
441 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/db_list.php']) {
442 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/db_list.php']);
443 }
444
445
446
447
448
449
450
451
452
453
454
455
456 // Make instance:
457 $SOBE = t3lib_div::makeInstance('SC_db_list');
458 $SOBE->init();
459
460 // Include files?
461 foreach($SOBE->include_once as $INC_FILE) include_once($INC_FILE);
462
463 $SOBE->clearCache();
464 $SOBE->main();
465 $SOBE->printContent();
466 ?>