Initial revision
[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 t3lib_positionMap {
34 var $checkNewPageCache=Array();
35 var $R_URI="";
36 var $elUid="";
37 var $moveUid="";
38 var $moveOrCopy="move";
39 var $l_insertNewPageHere = "insertNewPageHere";
40 var $l_insertNewRecordHere = "insertNewRecordHere";
41 var $dontPrintPageInsertIcons=0;
42 var $backPath="";
43 var $cur_sys_language;
44
45 function positionTree($id,$pageinfo,$perms_clause,$R_URI) {
46 global $LANG;
47 $t3lib_pageTree = t3lib_div::makeInstance("localPageTree");
48 $t3lib_pageTree->init(" AND ".$perms_clause);
49 $t3lib_pageTree->addField("pid");
50 $this->R_URI = $R_URI;
51 $this->elUid = $id;
52
53 $depth=2;
54 $t3lib_pageTree->getTree($pageinfo["pid"], $depth);
55 if (!$this->dontPrintPageInsertIcons) $code.=$this->JSimgFunc();
56 reset($t3lib_pageTree->tree);
57
58 $saveBlankLineState=array();
59 $saveLatestUid=array();
60 $latestInvDepth=$depth;
61
62 while(list($cc,$dat)=each($t3lib_pageTree->tree)) {
63 // Make link + parameters.
64 $latestInvDepth=$dat["invertedDepth"];
65 $saveLatestUid[$latestInvDepth]=$dat;
66 if (isset($t3lib_pageTree->tree[$cc-1])) {
67 $prev_dat = $t3lib_pageTree->tree[$cc-1];
68 // If current page, subpage?
69 if ($prev_dat["row"]["uid"]==$id) {
70 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...
71 // $params='&edit[pages]['.$id.']=new&returnNewPageId=1';
72 $code.='<nobr>'.$this->insertQuadLines($dat["blankLineCode"]).'<img src=clear.gif width=18 height=8 align=top><a href="#" onClick="'.$this->onClickEvent($id).'" 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>';
73 }
74 }
75
76 if ($prev_dat["invertedDepth"]>$t3lib_pageTree->tree[$cc]["invertedDepth"]) { // If going down
77 $prevPid = $t3lib_pageTree->tree[$cc]["row"]["pid"];
78 } elseif ($prev_dat["invertedDepth"]<$t3lib_pageTree->tree[$cc]["invertedDepth"]) { // If going up
79 // First of all the previous level should have an icon:
80 if (!$this->dontPrintPageInsertIcons && $this->checkNewPageInPid($prev_dat["row"]["pid"])) {
81 $prevPid = (-$prev_dat["row"]["uid"]);
82 // $params='&edit[pages]['.$prevPid.']=new&returnNewPageId=1';
83 $code.='<nobr>'.$this->insertQuadLines($dat["blankLineCode"]).'<img src=clear.gif width=18 height=1 align=top><a href="#" onClick="'.$this->onClickEvent($prevPid).'" 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>';
84 }
85
86 // Then set the current prevPid
87 $prevPid = -$prev_dat["row"]["pid"];
88 } else {
89 $prevPid = -$prev_dat["row"]["uid"]; // In on the same level
90 }
91 } else {
92 $prevPid = $dat["row"]["pid"]; // First in the tree
93 }
94 if (!$this->dontPrintPageInsertIcons && $this->checkNewPageInPid($dat["row"]["pid"])) {
95 // $params='&edit[pages]['.$prevPid.']=new&returnNewPageId=1';
96 $code.='<nobr>'.$this->insertQuadLines($dat["blankLineCode"]).'<a href="#" onClick="'.$this->onClickEvent($prevPid).'" 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>';
97 }
98
99 // The line with the icon and title:
100 $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>";
101 $code.=$t_code;
102 }
103
104 // If the current page was the last in the tree:
105 $prev_dat = end($t3lib_pageTree->tree);
106 if ($prev_dat["row"]["uid"]==$id) {
107 if (!$this->dontPrintPageInsertIcons && $this->checkNewPageInPid($id)) {
108 // $params='&edit[pages]['.$id.']=new&returnNewPageId=1';
109 $code.='<nobr>'.$this->insertQuadLines($saveLatestUid[$latestInvDepth]["blankLineCode"],1).'<img src=clear.gif width=18 height=8 align=top><a href="#" onClick="'.$this->onClickEvent($id).'" 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>';
110 }
111 }
112
113 for ($a=$latestInvDepth;$a<=$depth;$a++) {
114 $dat = $saveLatestUid[$a];
115 $prevPid = (-$dat["row"]["uid"]);
116 if (!$this->dontPrintPageInsertIcons && $this->checkNewPageInPid($dat["row"]["pid"])) {
117 $code.='<nobr>'.$this->insertQuadLines($dat["blankLineCode"],1).'<a href="#" onClick="'.$this->onClickEvent($prevPid).'" 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>';
118 }
119 }
120
121 return $code;
122 }
123 function JSimgFunc($prefix="") {
124 $code.='
125 <script language="javascript" type="text/javascript">
126 var img_newrecord_marker=new Image();
127 img_newrecord_marker.src = "gfx/newrecord'.$prefix.'_marker.gif";
128
129 var img_newrecord_marker_d=new Image();
130 img_newrecord_marker_d.src = "gfx/newrecord'.$prefix.'_marker_d.gif";
131
132 function changeImg(name,d) {
133 if (document[name]) {
134 if (d) {
135 document[name].src = img_newrecord_marker_d.src;
136 } else {
137 document[name].src = img_newrecord_marker.src;
138 }
139 }
140 }
141 </script>
142 ';
143 return $code;
144 }
145 function boldTitle($t_code,$dat,$id) {
146 if ($dat["row"]["uid"]==$id) {
147 $t_code='<strong>'.$t_code.'</strong>';
148 }
149 return $t_code;
150 }
151 function onClickEvent($pid) {
152 $params='&edit[pages]['.$pid.']=new&returnNewPageId=1';
153 return t3lib_BEfunc::editOnClick($params,"",$this->R_URI);
154 }
155 function insertlabel() {
156 global $LANG;
157 return $LANG->getLL($this->l_insertNewPageHere);
158 }
159 function linkPageTitle($str,$rec) {
160 return $str;
161 }
162 function checkNewPageInPid($pid) {
163 global $BE_USER;
164 if (!isset($this->checkNewPageCache[$pid])) {
165 $pidInfo = t3lib_BEfunc::getRecord("pages",$pid);
166 $this->checkNewPageCache[$pid] = ($BE_USER->isAdmin() || $BE_USER->doesUserHaveAccess($pidInfo,8));
167 }
168 return $this->checkNewPageCache[$pid];
169 }
170 function insertQuadLines($codes,$allBlank=0) {
171 $codeA = t3lib_div::trimExplode(",",$codes.",line",1);
172
173 $lines=array();
174 while(list(,$code)=each($codeA)) {
175 if ($code=="blank" || $allBlank) {
176 $lines[]='<img src="clear.gif" width="18" height="8" align=top>';
177 } else {
178 $lines[]='<img src="gfx/ol/halfline.gif" width="18" height="8" align=top>';
179 }
180 }
181 return implode("",$lines);
182 }
183
184
185
186
187
188
189
190
191 function printContentElementColumns($pid,$moveUid,$colPosList,$showHidden,$R_URI) {
192 $this->R_URI = $R_URI;
193 $this->moveUid = $moveUid;
194 $colPosArray = t3lib_div::trimExplode(",",$colPosList,1);
195
196 $lines=array();
197 while(list($kk,$vv)=each($colPosArray)) {
198 $query = "SELECT * FROM tt_content WHERE pid=".intval($pid).
199 ($showHidden ? "" : t3lib_BEfunc::BEenableFields("tt_content")).
200 " AND colPos=".$vv.
201 (strcmp($this->cur_sys_language,"") ? " AND sys_language_uid=".intval($this->cur_sys_language) : "").
202 t3lib_BEfunc::deleteClause("tt_content").
203 " ORDER BY sorting";
204 $res = mysql(TYPO3_db,$query);
205
206 $lines[$kk]=array();
207 $lines[$kk][]=$this->insertPositionIcon("",$vv,$kk,$moveUid,$pid);
208 while($row=mysql_fetch_assoc($res)) {
209 $lines[$kk][]=$this->wrapRecordHeader($this->getRecordHeader($row),$row);
210 $lines[$kk][]=$this->insertPositionIcon($row,$vv,$kk,$moveUid,$pid);
211 }
212 }
213 return $this->printRecordMap($lines,$colPosArray);
214 }
215 function printRecordMap($lines,$colPosArray) {
216 $row1="";
217 $row2="";
218 reset($colPosArray);
219 while(list($kk,$vv)=each($colPosArray)) {
220 $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>';
221 $row2.='<td valign=top nowrap>'.implode('<BR>',$lines[$kk]).'</td>';
222 }
223 $table = '<table border=0 cellpadding=0 cellspacing=1>
224 <tr bgColor="'.$GLOBALS["SOBE"]->doc->bgColor5.'">'.$row1.'</tr>
225 <tr>'.$row2.'</tr>
226 </table>';
227 return $this->JSimgFunc("2").$table;
228 }
229 function wrapColumnHeader($str,$vv) {
230 return $str;
231 }
232 function insertPositionIcon($row,$vv,$kk,$moveUid,$pid) {
233 $cc = hexdec(substr(md5($row["uid"]."-".$vv."-".$kk),0,4));
234 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>';
235 }
236 function onClickInsertRecord($row,$vv,$moveUid,$pid,$sys_lang=0) {
237 $table="tt_content";
238 if (is_array($row)) {
239 $location="tce_db.php?cmd[".$table."][".$moveUid."][".$this->moveOrCopy."]=-".$row["uid"].'&prErr=1&uPT=1&vC='.$GLOBALS["BE_USER"]->veriCode();
240 } else {
241 $location="tce_db.php?cmd[".$table."][".$moveUid."][".$this->moveOrCopy."]=".$pid."&data[".$table."][".$moveUid."][colPos]=".$vv.'&prErr=1&vC='.$GLOBALS["BE_USER"]->veriCode();
242 }
243 // $location.='&redirect='.rawurlencode($this->R_URI); // returns to prev. page
244 $location.='&uPT=1&redirect='.rawurlencode(t3lib_div::getIndpEnv("REQUEST_URI")); // This redraws screen
245
246 return 'document.location=\''.$location.'\';return false;';
247 }
248 function wrapRecordHeader($str,$row) {
249 return $str;
250 }
251 function getRecordHeader($row) {
252 $line = t3lib_iconWorks::getIconImage("tt_content",$row,$this->backPath,t3lib_BEfunc::titleAttrib(t3lib_BEfunc::getRecordIconAltText($row,"tt_content"),1).' align=top');
253 $line.= t3lib_BEfunc::getRecordTitle("tt_content",$row,1);
254 return $this->wrapRecordTitle($line,$row);
255 }
256 function wrapRecordTitle($str,$row) {
257 return '<a href="'.t3lib_div::linkThisScript(array("uid"=>intval($row["uid"]),"moveUid"=>"")).'">'.$str.'</a>';
258 }
259 }
260
261 if (defined("TYPO3_MODE") && $TYPO3_CONF_VARS[TYPO3_MODE]["XCLASS"]["t3lib/class.t3lib_positionmap.php"]) {
262 include_once($TYPO3_CONF_VARS[TYPO3_MODE]["XCLASS"]["t3lib/class.t3lib_positionmap.php"]);
263 }
264 ?>