Initial revision
[Packages/TYPO3.CMS.git] / typo3 / db_list.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2003 Kasper Skårhøj (kasper@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 * @author Kasper Skårhøj <kasper@typo3.com>
37 * @package TYPO3
38 * @subpackage core
39 *
40 */
41
42
43 unset($MCONF);
44 require ("mod/web/list/conf.php");
45 require ("init.php");
46 require ("template.php");
47 $LANG->includeLLFile("EXT:lang/locallang_mod_web_list.php");
48 require_once (PATH_t3lib."class.t3lib_page.php");
49 require_once (PATH_t3lib."class.t3lib_pagetree.php");
50 require_once (PATH_t3lib."class.t3lib_recordlist.php");
51 require_once (PATH_t3lib."class.t3lib_clipboard.php");
52 require_once ("class.db_list.inc");
53 require_once ("class.db_list_extra.inc");
54 $BE_USER->modAccess($MCONF,1);
55
56 t3lib_BEfunc::lockRecords();
57
58
59
60 // ***************************
61 // Script Classes
62 // ***************************
63 class SC_db_list {
64 var $MCONF=array();
65 var $MOD_MENU=array();
66 var $MOD_SETTINGS=array();
67
68 var $include_once=array();
69 var $content;
70
71 var $perms_clause;
72 var $modTSconfig;
73 var $pointer;
74 var $pageinfo;
75 var $imagemode;
76 var $table;
77 var $id;
78 var $doc;
79
80 function init() {
81 global $BE_USER,$LANG,$BACK_PATH,$TCA_DESCR,$TCA,$HTTP_GET_VARS,$HTTP_POST_VARS,$CLIENT,$TYPO3_CONF_VARS;
82 $this->MCONF = $GLOBALS["MCONF"];
83 $this->id = t3lib_div::GPvar("id");
84
85 $this->perms_clause = $BE_USER->getPagePermsClause(1);
86 $this->pointer = t3lib_div::GPvar("pointer");
87 $this->imagemode = t3lib_div::GPvar("imagemode");
88 $this->table = t3lib_div::GPvar("table");
89 $this->menuConfig();
90
91 if (t3lib_div::GPvar("clear_cache") || t3lib_div::GPvar("cmd")=="delete") {
92 $this->include_once[]=PATH_t3lib."class.t3lib_tcemain.php";
93 }
94 }
95 function menuConfig() {
96 global $BE_USER,$LANG,$BACK_PATH,$TCA_DESCR,$TCA,$HTTP_GET_VARS,$HTTP_POST_VARS,$CLIENT,$TYPO3_CONF_VARS;
97
98 // MENU-ITEMS:
99 // If array, then it's a selector box menu
100 // If empty string it's just a variable, that'll be saved.
101 // Values NOT in this array will not be saved in the settings-array for the module.
102 $this->MOD_MENU = array(
103 "bigControlPanel" => "",
104 "clipBoard" => ""
105 );
106
107 $this->modTSconfig = t3lib_BEfunc::getModTSconfig($this->id,"mod.".$this->MCONF["name"]);
108
109 // CLEANSE SETTINGS
110 $this->MOD_SETTINGS = t3lib_BEfunc::getModuleData($this->MOD_MENU, t3lib_div::GPvar("SET"), $this->MCONF["name"]);
111 }
112 function clearCache() {
113 if (t3lib_div::GPvar("clear_cache")) {
114 $tce = t3lib_div::makeInstance("t3lib_TCEmain");
115 $tce->start(Array(),Array());
116 $tce->clear_cacheCmd($this->id);
117 }
118 }
119 function main() {
120 global $BE_USER,$LANG,$BACK_PATH,$TCA_DESCR,$TCA,$HTTP_GET_VARS,$HTTP_POST_VARS,$CLIENT,$TYPO3_CONF_VARS;
121
122 $this->doc = t3lib_div::makeInstance("template");
123 $this->doc->backPath = $BACK_PATH;
124
125
126 $this->pageinfo = t3lib_BEfunc::readPageAccess($this->id,$this->perms_clause);
127 $access = is_array($this->pageinfo) ? 1 : 0;
128
129 $dblist = t3lib_div::makeInstance("localRecordList");
130 $dblist->backPath = $BACK_PATH;
131 $dblist->calcPerms = $BE_USER->calcPerms($this->pageinfo);
132 $dblist->thumbs = $BE_USER->uc["thumbnailsByDefault"];
133 $dblist->returnUrl=t3lib_div::GPvar("returnUrl");
134 $dblist->allFields = ($this->MOD_SETTINGS["bigControlPanel"] || $this->table) ? 1 : 0;
135 $dblist->showClipboard = 1;
136 $dblist->disableSingleTableView = $this->modTSconfig["properties"]["disableSingleTableView"];
137 $dblist->alternateBgColors=$this->modTSconfig["properties"]["alternateBgColors"]?1:0;
138 $dblist->allowedNewTables = t3lib_div::trimExplode(",",$this->modTSconfig["properties"]["allowedNewTables"],1);
139 $dblist->newWizards=$this->modTSconfig["properties"]["newWizards"]?1:0;
140
141 // ***********************
142 // CLipboard things...
143 // ***********************
144 $dblist->clipObj = t3lib_div::makeInstance("t3lib_clipboard"); // Start clipboard
145 $dblist->clipObj->initializeClipboard(); // Initialize - reads the clipboard content from the user session
146
147 $CB = $HTTP_GET_VARS["CB"]; // CB is the clipboard command array
148 if (t3lib_div::GPvar("cmd")=="setCB") {
149 // 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
150 // This is set to the "el" array of the CB after being parsed so only the table in question is registered.
151 $CB["el"] = $dblist->clipObj->cleanUpCBC(array_merge($HTTP_POST_VARS["CBH"],$HTTP_POST_VARS["CBC"]),t3lib_div::GPvar("cmd_table"));
152 }
153 if (!$this->MOD_SETTINGS["clipBoard"]) $CB["setP"]="normal"; // If the clipboard is NOT shown, set the pad to "normal".
154 $dblist->clipObj->setCmd($CB); // Execute commands.
155 $dblist->clipObj->cleanCurrent(); // Clean up pad
156 $dblist->clipObj->endClipboard(); // Save the clipboard content
157
158
159 // This flag will prevent the
160 // It is set, if the clickmenu-layer is active AND the extended view is not enabled.
161 $dblist->dontShowClipControlPanels = $CLIENT["FORMSTYLE"] && !$this->MOD_SETTINGS["bigControlPanel"] && $dblist->clipObj->current=="normal" && !$BE_USER->uc["disableCMlayers"] && !$this->modTSconfig["properties"]["showClipControlPanelsDespiteOfCMlayers"];
162
163
164
165 if ($access) {
166
167 // 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.
168 if (t3lib_div::GPvar("cmd")=="delete") {
169 $items = $dblist->clipObj->cleanUpCBC($HTTP_POST_VARS["CBC"],t3lib_div::GPvar("cmd_table"),1);
170 if (count($items)) {
171 $cmd=array();
172 reset($items);
173 while(list($iK)=each($items)) {
174 $iKParts = explode("|",$iK);
175 $cmd[$iKParts[0]][$iKParts[1]]["delete"]=1;
176 }
177 $tce = t3lib_div::makeInstance("t3lib_TCEmain");
178 $tce->start(array(),$cmd);
179 $tce->process_cmdmap();
180
181 if (isset($cmd["pages"])) {
182 t3lib_BEfunc::getSetUpdateSignal("updatePageTree");
183 }
184
185 $tce->printLogErrorMessages(t3lib_div::getIndpEnv("REQUEST_URI"));
186 }
187 }
188
189 $this->pointer = t3lib_div::intInRange($this->pointer,0,100000);
190 $dblist->start($this->id,$this->table,$this->pointer,
191 t3lib_div::GPvar("search_field"),
192 t3lib_div::GPvar("search_levels"),
193 t3lib_div::GPvar("showLimit")
194 );
195 $dblist->setDispFields();
196 $dblist->writeTop($this->pageinfo,t3lib_BEfunc::getRecordPath (intval($this->pageinfo["uid"]),$this->perms_clause,15));
197 $dblist->generateList($this->id,$this->table);
198 $dblist->writeBottom();
199
200 $this->doc->JScode='
201 <script language="javascript" type="text/javascript">
202 function jumpToUrl(URL) {
203 // alert("jumpToUrl: "+URL);
204 document.location = URL;
205 return false;
206 }
207 function jumpExt(URL,anchor) {
208 var anc = anchor?anchor:"";
209 // alert("jumpExt: "+URL+(T3_THIS_LOCATION?"&returnUrl="+T3_THIS_LOCATION:"")+anc);
210 document.location = URL+(T3_THIS_LOCATION?"&returnUrl="+T3_THIS_LOCATION:"")+anc;
211 return false;
212 }
213 function jumpSelf(URL) {
214 // alert("jumpSelf: "+URL+(T3_RETURN_URL?"&returnUrl="+T3_RETURN_URL:""));
215 document.location = URL+(T3_RETURN_URL?"&returnUrl="+T3_RETURN_URL:"");
216 return false;
217 }
218 '.$this->doc->redirectUrls($dblist->listURL()).'
219 '.$dblist->CBfunctions().'
220 function editRecords(table,idList,addParams,CBflag) {
221 document.location="'.$backPath.'alt_doc.php?returnUrl='.rawurlencode(t3lib_div::getIndpEnv("REQUEST_URI")).
222 '&edit["+table+"]["+idList+"]=edit"+addParams;
223 }
224 function editList(table,idList) {
225 var list="";
226
227 // Checking how many is checked, how many is not
228 var pointer=0;
229 var pos = idList.indexOf(",");
230 while (pos!=-1) {
231 if (cbValue(table+"|"+idList.substr(pointer,pos-pointer))) {
232 list+=idList.substr(pointer,pos-pointer)+",";
233 }
234 pointer=pos+1;
235 pos = idList.indexOf(",",pointer);
236 }
237 if (cbValue(table+"|"+idList.substr(pointer))) {
238 list+=idList.substr(pointer)+",";
239 }
240
241 return list ? list : idList;
242 }
243
244 if (top.fsMod) top.fsMod.recentIds["web"] = '.intval($this->id).';
245 </script>
246 ';
247
248 $CMparts=$this->doc->getContextMenuCode();
249 $this->doc->bodyTagAdditions = $CMparts[1];
250 $this->doc->JScode.=$CMparts[0];
251 $this->doc->postCode.= $CMparts[2];
252 } // access
253
254
255
256 $this->content="";
257 $this->content.=$this->doc->startPage("DB list");
258 $this->content.= '<form action="'.$dblist->listURL().'" method="POST" name="dblistForm">';
259 $this->content.= $dblist->HTMLcode;
260 $this->content.= '<input type="hidden" name="cmd_table"><input type="hidden" name="cmd"></form>';
261
262 if ($dblist->HTMLcode) { // Making search form:
263 if ($dblist->table) { // Making search form:
264 $sBoxPre = $dblist->spaceSearchBoxFromLeft;
265 $dblist->spaceSearchBoxFromLeft=$sBoxPre;
266 $this->content.=$dblist->fieldSelectBox($dblist->table);
267 $dblist->spaceSearchBoxFromLeft=$sBoxPre;
268 $this->content.="";
269 }
270
271 $this->content.='<form action="" method="POST">';
272 $this->content.=t3lib_BEfunc::getFuncCheck($this->id,"SET[bigControlPanel]",$this->MOD_SETTINGS["bigControlPanel"],"db_list.php","")." ".$LANG->getLL("largeControl")."<BR>";
273 if ($dblist->showClipboard) $this->content.=t3lib_BEfunc::getFuncCheck($this->id,"SET[clipBoard]",$this->MOD_SETTINGS["clipBoard"],"db_list.php","").' '.$LANG->getLL("showClipBoard");
274 $this->content.='</form>';
275
276 // Printing clipboard if selected for.
277 if ($this->MOD_SETTINGS["clipBoard"] && $dblist->showClipboard) $this->content.=$dblist->clipObj->printClipboard();
278
279
280 if (!$this->modTSconfig["properties"]["noCreateRecordsLink"]) $this->content.='<a href="db_new.php?id='.$this->id.'&returnUrl='.rawurlencode(t3lib_div::getIndpEnv("REQUEST_URI")).'"><img src="gfx/new_el.gif" width="11" height="12" hspace=4 border="0" align=top><strong>'.$LANG->getLL("newRecordGeneral").'</strong></a><BR><BR>';
281 $this->content.=$dblist->getSearchBox();
282 $this->content.="<BR>".$dblist->showSysNotesForPage();
283
284
285 // ShortCut
286 if ($BE_USER->mayMakeShortcut()) {
287 $this->content.=$this->doc->makeShortcutIcon("id,imagemode,pointer,table,search_field,search_levels,showLimit,sortField,sortRev",implode(",",array_keys($this->MOD_MENU)),$this->MCONF["name"]);
288 }
289 }
290 }
291 function printContent() {
292 global $BE_USER,$LANG,$BACK_PATH,$TCA_DESCR,$TCA,$HTTP_GET_VARS,$HTTP_POST_VARS,$CLIENT,$TYPO3_CONF_VARS;
293
294 $this->content.= $this->doc->endPage();
295 echo $this->content;
296
297 // echo strlen($this->content)."<BR>";
298 }
299 }
300
301 // Include extension?
302 if (defined("TYPO3_MODE") && $TYPO3_CONF_VARS[TYPO3_MODE]["XCLASS"]["typo3/db_list.php"]) {
303 include_once($TYPO3_CONF_VARS[TYPO3_MODE]["XCLASS"]["typo3/db_list.php"]);
304 }
305
306
307
308
309
310
311
312
313
314
315
316
317 // Make instance:
318 $SOBE = t3lib_div::makeInstance("SC_db_list");
319 $SOBE->init();
320
321 // Include files?
322 reset($SOBE->include_once);
323 while(list(,$INC_FILE)=each($SOBE->include_once)) {include_once($INC_FILE);}
324
325 $SOBE->clearCache();
326 $SOBE->main();
327 $SOBE->printContent();
328 ?>