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