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