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