Added $Id$ keywords, cleaned up comment tags
[Packages/TYPO3.CMS.git] / t3lib / class.t3lib_positionmap.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2003 Kasper Skaarhoj (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 * Contains class for creating a position map.
29 *
30 * $Id$
31 *
32 * @author Kasper Skaarhoj <kasper@typo3.com>
33 */
34 /**
35 * [CLASS/FUNCTION INDEX of SCRIPT]
36 *
37 *
38 *
39 * 79: class t3lib_positionMap
40 * 101: function positionTree($id,$pageinfo,$perms_clause,$R_URI)
41 * 184: function JSimgFunc($prefix='')
42 * 193: function changeImg(name,d)
43 * 213: function boldTitle($t_code,$dat,$id)
44 * 225: function onClickEvent($pid,$newPagePID)
45 * 242: function insertlabel()
46 * 252: function linkPageTitle($str,$rec)
47 * 260: function checkNewPageInPid($pid)
48 * 273: function getModConfig($pid)
49 * 287: function insertQuadLines($codes,$allBlank=0)
50 * 317: function printContentElementColumns($pid,$moveUid,$colPosList,$showHidden,$R_URI)
51 * 347: function printRecordMap($lines,$colPosArray)
52 * 367: function wrapColumnHeader($str,$vv)
53 * 379: function insertPositionIcon($row,$vv,$kk,$moveUid,$pid)
54 * 392: function onClickInsertRecord($row,$vv,$moveUid,$pid,$sys_lang=0)
55 * 410: function wrapRecordHeader($str,$row)
56 * 418: function getRecordHeader($row)
57 * 429: function wrapRecordTitle($str,$row)
58 *
59 * TOTAL FUNCTIONS: 18
60 * (This index is automatically created/updated by the extension "extdeveval")
61 *
62 */
63
64
65
66
67
68
69
70
71
72 /**
73 * Position map class.
74 *
75 * @author Kasper Skaarhoj <kasper@typo3.com>
76 * @package TYPO3
77 * @subpackage t3lib
78 */
79 class t3lib_positionMap {
80 var $getModConfigCache=array();
81 var $checkNewPageCache=Array();
82
83 var $R_URI='';
84 var $elUid='';
85 var $moveUid='';
86 var $moveOrCopy='move';
87 var $l_insertNewPageHere = 'insertNewPageHere';
88 var $l_insertNewRecordHere = 'insertNewRecordHere';
89 var $dontPrintPageInsertIcons=0;
90 var $backPath='';
91 var $modConfigStr='mod.web_list.newPageWiz';
92 var $cur_sys_language;
93
94 /**
95 * @param [type] $id: ...
96 * @param [type] $pageinfo: ...
97 * @param [type] $perms_clause: ...
98 * @param [type] $R_URI: ...
99 * @return [type] ...
100 */
101 function positionTree($id,$pageinfo,$perms_clause,$R_URI) {
102 global $LANG;
103 $t3lib_pageTree = t3lib_div::makeInstance('localPageTree');
104 $t3lib_pageTree->init(' AND '.$perms_clause);
105 $t3lib_pageTree->addField('pid');
106 $this->R_URI = $R_URI;
107 $this->elUid = $id;
108
109 $depth=2;
110 $t3lib_pageTree->getTree($pageinfo['pid'], $depth);
111 if (!$this->dontPrintPageInsertIcons) $code.=$this->JSimgFunc();
112 reset($t3lib_pageTree->tree);
113
114 $saveBlankLineState=array();
115 $saveLatestUid=array();
116 $latestInvDepth=$depth;
117
118 while(list($cc,$dat)=each($t3lib_pageTree->tree)) {
119 // Make link + parameters.
120 $latestInvDepth=$dat['invertedDepth'];
121 $saveLatestUid[$latestInvDepth]=$dat;
122 if (isset($t3lib_pageTree->tree[$cc-1])) {
123 $prev_dat = $t3lib_pageTree->tree[$cc-1];
124 // If current page, subpage?
125 if ($prev_dat['row']['uid']==$id) {
126 if (!$this->dontPrintPageInsertIcons && $this->checkNewPageInPid($id) && !($prev_dat['invertedDepth']>$t3lib_pageTree->tree[$cc]['invertedDepth'])) { // 1) It must be allowed to create a new page and 2) If there are subpages there is no need to render a subpage icon here - it'll be done over the subpages...
127 // $params='&edit[pages]['.$id.']=new&returnNewPageId=1';
128 $code.='<nobr>'.$this->insertQuadLines($dat['blankLineCode']).'<img src=clear.gif width=18 height=8 align=top><a href="#" onClick="'.$this->onClickEvent($id,$id,1).'" onmouseover="changeImg(\'mImgSubpage'.$cc.'\',0);" onmouseout="changeImg(\'mImgSubpage'.$cc.'\',1);"><img name="mImgSubpage'.$cc.'" src="gfx/newrecord_marker_d.gif" width="281" height="8" border="0" title="'.$this->insertlabel().'" align=top></a><nobr><BR>';
129 }
130 }
131
132 if ($prev_dat['invertedDepth']>$t3lib_pageTree->tree[$cc]['invertedDepth']) { // If going down
133 $prevPid = $t3lib_pageTree->tree[$cc]['row']['pid'];
134 } elseif ($prev_dat['invertedDepth']<$t3lib_pageTree->tree[$cc]['invertedDepth']) { // If going up
135 // First of all the previous level should have an icon:
136 if (!$this->dontPrintPageInsertIcons && $this->checkNewPageInPid($prev_dat['row']['pid'])) {
137 $prevPid = (-$prev_dat['row']['uid']);
138 // $params='&edit[pages]['.$prevPid.']=new&returnNewPageId=1';
139 $code.='<nobr>'.$this->insertQuadLines($dat['blankLineCode']).'<img src=clear.gif width=18 height=1 align=top><a href="#" onClick="'.$this->onClickEvent($prevPid,$prev_dat['row']['pid'],2).'" onmouseover="changeImg(\'mImgAfter'.$cc.'\',0);" onmouseout="changeImg(\'mImgAfter'.$cc.'\',1);"><img name="mImgAfter'.$cc.'" src="gfx/newrecord_marker_d.gif" width="281" height="8" border="0" title="'.$this->insertlabel().'" align=top></a><nobr><BR>';
140 }
141
142 // Then set the current prevPid
143 $prevPid = -$prev_dat['row']['pid'];
144 } else {
145 $prevPid = -$prev_dat['row']['uid']; // In on the same level
146 }
147 } else {
148 $prevPid = $dat['row']['pid']; // First in the tree
149 }
150 if (!$this->dontPrintPageInsertIcons && $this->checkNewPageInPid($dat['row']['pid'])) {
151 // $params='&edit[pages]['.$prevPid.']=new&returnNewPageId=1';
152 $code.='<nobr>'.$this->insertQuadLines($dat['blankLineCode']).'<a href="#" onClick="'.$this->onClickEvent($prevPid,$dat['row']['pid'],3).'" onmouseover="changeImg(\'mImg'.$cc.'\',0);" onmouseout="changeImg(\'mImg'.$cc.'\',1);"><img name="mImg'.$cc.'" src="gfx/newrecord_marker_d.gif" width="281" height="8" border="0" title="'.$this->insertlabel().'" align=top></a><nobr><BR>';
153 }
154
155 // The line with the icon and title:
156 $t_code='<nobr>'.$dat['HTML'].$this->linkPageTitle($this->boldTitle(htmlspecialchars(t3lib_div::fixed_lgd($dat['row']['title'],$BE_USER->uc['titleLen'])),$dat,$id),$dat['row']).'<nobr><BR>';
157 $code.=$t_code;
158 }
159
160 // If the current page was the last in the tree:
161 $prev_dat = end($t3lib_pageTree->tree);
162 if ($prev_dat['row']['uid']==$id) {
163 if (!$this->dontPrintPageInsertIcons && $this->checkNewPageInPid($id)) {
164 // $params='&edit[pages]['.$id.']=new&returnNewPageId=1';
165 $code.='<nobr>'.$this->insertQuadLines($saveLatestUid[$latestInvDepth]['blankLineCode'],1).'<img src=clear.gif width=18 height=8 align=top><a href="#" onClick="'.$this->onClickEvent($id,$id,4).'" onmouseover="changeImg(\'mImgSubpage'.$cc.'\',0);" onmouseout="changeImg(\'mImgSubpage'.$cc.'\',1);"><img name="mImgSubpage'.$cc.'" src="gfx/newrecord_marker_d.gif" width="281" height="8" border="0" title="'.$this->insertlabel().'" align=top></a><nobr><BR>';
166 }
167 }
168
169 for ($a=$latestInvDepth;$a<=$depth;$a++) {
170 $dat = $saveLatestUid[$a];
171 $prevPid = (-$dat['row']['uid']);
172 if (!$this->dontPrintPageInsertIcons && $this->checkNewPageInPid($dat['row']['pid'])) {
173 $code.='<nobr>'.$this->insertQuadLines($dat['blankLineCode'],1).'<a href="#" onClick="'.$this->onClickEvent($prevPid,$dat['row']['pid'],5).'" onmouseover="changeImg(\'mImgEnd'.$a.'\',0);" onmouseout="changeImg(\'mImgEnd'.$a.'\',1);"><img name="mImgEnd'.$a.'" src="gfx/newrecord_marker_d.gif" width="281" height="8" border="0" title="'.$this->insertlabel().'" align=top></a><nobr><BR>';
174 }
175 }
176
177 return $code;
178 }
179
180 /**
181 * @param [type] $prefix: ...
182 * @return [type] ...
183 */
184 function JSimgFunc($prefix='') {
185 $code.='
186 <script language="javascript" type="text/javascript">
187 var img_newrecord_marker=new Image();
188 img_newrecord_marker.src = "gfx/newrecord'.$prefix.'_marker.gif";
189
190 var img_newrecord_marker_d=new Image();
191 img_newrecord_marker_d.src = "gfx/newrecord'.$prefix.'_marker_d.gif";
192
193 function changeImg(name,d) {
194 if (document[name]) {
195 if (d) {
196 document[name].src = img_newrecord_marker_d.src;
197 } else {
198 document[name].src = img_newrecord_marker.src;
199 }
200 }
201 }
202 </script>
203 ';
204 return $code;
205 }
206
207 /**
208 * @param [type] $t_code: ...
209 * @param [type] $dat: ...
210 * @param [type] $id: ...
211 * @return [type] ...
212 */
213 function boldTitle($t_code,$dat,$id) {
214 if ($dat['row']['uid']==$id) {
215 $t_code='<strong>'.$t_code.'</strong>';
216 }
217 return $t_code;
218 }
219
220 /**
221 * @param [type] $pid: ...
222 * @param [type] $newPagePID: ...
223 * @return [type] ...
224 */
225 function onClickEvent($pid,$newPagePID) {
226 $TSconfigProp = $this->getModConfig($newPagePID);
227
228 if ($TSconfigProp['useTemplaVoila']) {
229 if (t3lib_extMgm::isLoaded('templavoila')) {
230 $onclick = "document.location='".t3lib_extMgm::extRelPath('templavoila')."mod1/index.php?cmd=crPage&positionPid=".$pid."';";
231 return $onclick;
232 }
233 }
234
235 $params='&edit[pages]['.$pid.']=new&returnNewPageId=1';
236 return t3lib_BEfunc::editOnClick($params,'',$this->R_URI);
237 }
238
239 /**
240 * @return [type] ...
241 */
242 function insertlabel() {
243 global $LANG;
244 return $LANG->getLL($this->l_insertNewPageHere);
245 }
246
247 /**
248 * @param [type] $str: ...
249 * @param [type] $rec: ...
250 * @return [type] ...
251 */
252 function linkPageTitle($str,$rec) {
253 return $str;
254 }
255
256 /**
257 * @param [type] $pid: ...
258 * @return [type] ...
259 */
260 function checkNewPageInPid($pid) {
261 global $BE_USER;
262 if (!isset($this->checkNewPageCache[$pid])) {
263 $pidInfo = t3lib_BEfunc::getRecord('pages',$pid);
264 $this->checkNewPageCache[$pid] = ($BE_USER->isAdmin() || $BE_USER->doesUserHaveAccess($pidInfo,8));
265 }
266 return $this->checkNewPageCache[$pid];
267 }
268
269 /**
270 * @param [type] $pid: ...
271 * @return [type] ...
272 */
273 function getModConfig($pid) {
274 global $BE_USER;
275 if (!isset($this->getModConfigCache[$pid])) {
276 // Acquiring TSconfig for this PID:
277 $this->getModConfigCache[$pid] = t3lib_BEfunc::getModTSconfig($pid,$this->modConfigStr);
278 }
279 return $this->getModConfigCache[$pid]['properties'];
280 }
281
282 /**
283 * @param [type] $codes: ...
284 * @param [type] $allBlank: ...
285 * @return [type] ...
286 */
287 function insertQuadLines($codes,$allBlank=0) {
288 $codeA = t3lib_div::trimExplode(',',$codes.",line",1);
289
290 $lines=array();
291 while(list(,$code)=each($codeA)) {
292 if ($code=="blank" || $allBlank) {
293 $lines[]='<img src="clear.gif" width="18" height="8" align=top>';
294 } else {
295 $lines[]='<img src="gfx/ol/halfline.gif" width="18" height="8" align="top">';
296 }
297 }
298 return implode('',$lines);
299 }
300
301
302
303
304
305
306
307
308
309 /**
310 * @param [type] $pid: ...
311 * @param [type] $moveUid: ...
312 * @param [type] $colPosList: ...
313 * @param [type] $showHidden: ...
314 * @param [type] $R_URI: ...
315 * @return [type] ...
316 */
317 function printContentElementColumns($pid,$moveUid,$colPosList,$showHidden,$R_URI) {
318 $this->R_URI = $R_URI;
319 $this->moveUid = $moveUid;
320 $colPosArray = t3lib_div::trimExplode(',',$colPosList,1);
321
322 $lines=array();
323 while(list($kk,$vv)=each($colPosArray)) {
324 $query = 'SELECT * FROM tt_content WHERE pid='.intval($pid).
325 ($showHidden ? "" : t3lib_BEfunc::BEenableFields('tt_content')).
326 ' AND colPos='.$vv.
327 (strcmp($this->cur_sys_language,'') ? " AND sys_language_uid=".intval($this->cur_sys_language) : "").
328 t3lib_BEfunc::deleteClause('tt_content').
329 ' ORDER BY sorting';
330 $res = mysql(TYPO3_db,$query);
331
332 $lines[$kk]=array();
333 $lines[$kk][]=$this->insertPositionIcon('',$vv,$kk,$moveUid,$pid);
334 while($row=mysql_fetch_assoc($res)) {
335 $lines[$kk][]=$this->wrapRecordHeader($this->getRecordHeader($row),$row);
336 $lines[$kk][]=$this->insertPositionIcon($row,$vv,$kk,$moveUid,$pid);
337 }
338 }
339 return $this->printRecordMap($lines,$colPosArray);
340 }
341
342 /**
343 * @param [type] $lines: ...
344 * @param [type] $colPosArray: ...
345 * @return [type] ...
346 */
347 function printRecordMap($lines,$colPosArray) {
348 $row1='';
349 $row2='';
350 reset($colPosArray);
351 while(list($kk,$vv)=each($colPosArray)) {
352 $row1.='<td align=center width="'.round(100/count($colPosArray)).'%"><strong>'.$this->wrapColumnHeader(t3lib_div::danish_strtoupper($GLOBALS['LANG']->sL(t3lib_BEfunc::getLabelFromItemlist('tt_content','colPos',$vv))),$vv).'</strong></td>';
353 $row2.='<td valign=top nowrap>'.implode('<BR>',$lines[$kk]).'</td>';
354 }
355 $table = '<table border=0 cellpadding=0 cellspacing=1>
356 <tr bgColor="'.$GLOBALS['SOBE']->doc->bgColor5.'">'.$row1.'</tr>
357 <tr>'.$row2.'</tr>
358 </table>';
359 return $this->JSimgFunc('2').$table;
360 }
361
362 /**
363 * @param [type] $str: ...
364 * @param [type] $vv: ...
365 * @return [type] ...
366 */
367 function wrapColumnHeader($str,$vv) {
368 return $str;
369 }
370
371 /**
372 * @param [type] $row: ...
373 * @param [type] $vv: ...
374 * @param [type] $kk: ...
375 * @param [type] $moveUid: ...
376 * @param [type] $pid: ...
377 * @return [type] ...
378 */
379 function insertPositionIcon($row,$vv,$kk,$moveUid,$pid) {
380 $cc = hexdec(substr(md5($row['uid'].'-'.$vv.'-'.$kk),0,4));
381 return '<a href="#" onClick="'.$this->onClickInsertRecord($row,$vv,$moveUid,$pid,$this->cur_sys_language).'" onmouseover="changeImg(\'mImg'.$cc.'\',0);" onmouseout="changeImg(\'mImg'.$cc.'\',1);"><img name="mImg'.$cc.'" src="gfx/newrecord2_marker_d.gif" width="100" height="8" border="0" title="'.$GLOBALS['LANG']->getLL($this->l_insertNewRecordHere).'" align=top></a>';
382 }
383
384 /**
385 * @param [type] $row: ...
386 * @param [type] $vv: ...
387 * @param [type] $moveUid: ...
388 * @param [type] $pid: ...
389 * @param [type] $sys_lang: ...
390 * @return [type] ...
391 */
392 function onClickInsertRecord($row,$vv,$moveUid,$pid,$sys_lang=0) {
393 $table='tt_content';
394 if (is_array($row)) {
395 $location='tce_db.php?cmd['.$table.']['.$moveUid.']['.$this->moveOrCopy.']=-'.$row['uid'].'&prErr=1&uPT=1&vC='.$GLOBALS['BE_USER']->veriCode();
396 } else {
397 $location='tce_db.php?cmd['.$table.']['.$moveUid.']['.$this->moveOrCopy.']='.$pid.'&data['.$table.']['.$moveUid.'][colPos]='.$vv.'&prErr=1&vC='.$GLOBALS['BE_USER']->veriCode();
398 }
399 // $location.='&redirect='.rawurlencode($this->R_URI); // returns to prev. page
400 $location.='&uPT=1&redirect='.rawurlencode(t3lib_div::getIndpEnv('REQUEST_URI')); // This redraws screen
401
402 return 'document.location=\''.$location.'\';return false;';
403 }
404
405 /**
406 * @param [type] $str: ...
407 * @param [type] $row: ...
408 * @return [type] ...
409 */
410 function wrapRecordHeader($str,$row) {
411 return $str;
412 }
413
414 /**
415 * @param [type] $row: ...
416 * @return [type] ...
417 */
418 function getRecordHeader($row) {
419 $line = t3lib_iconWorks::getIconImage('tt_content',$row,$this->backPath,t3lib_BEfunc::titleAttrib(t3lib_BEfunc::getRecordIconAltText($row,'tt_content'),1).' align=top');
420 $line.= t3lib_BEfunc::getRecordTitle('tt_content',$row,1);
421 return $this->wrapRecordTitle($line,$row);
422 }
423
424 /**
425 * @param [type] $str: ...
426 * @param [type] $row: ...
427 * @return [type] ...
428 */
429 function wrapRecordTitle($str,$row) {
430 return '<a href="'.t3lib_div::linkThisScript(array('uid'=>intval($row['uid']),'moveUid'=>'')).'">'.$str.'</a>';
431 }
432 }
433
434 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_positionmap.php']) {
435 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_positionmap.php']);
436 }
437 ?>