Stripped the blank lines after ending php tag! (Caused "header already sent" errors)
[Packages/TYPO3.CMS.git] / t3lib / class.t3lib_treeview.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2002 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 * Base class for creating a page/folder tree in HTML
29 *
30 * Revised for TYPO3 3.6 August/2003 by Kasper Skårhøj
31 *
32 * @author Kasper Skårhøj <kasper@typo3.com>
33 * @coauthor René Fritz <r.fritz@colorcube.de>
34 * Maintained by René Fritz
35 */
36 /**
37 * [CLASS/FUNCTION INDEX of SCRIPT]
38 *
39 *
40 *
41 * 104: class t3lib_treeView
42 * 251: function init($clause='')
43 * 268: function reset()
44 * 282: function getBrowsableTree($addClause='')
45 * 356: function printTree($treeArr='')
46 * 396: function PMicon(&$row,$a,$c,$nextCount,$exp)
47 * 418: function PM_ATagWrap($icon,$cmd,$bMark='')
48 * 436: function wrapTitle($title,$v)
49 * 449: function wrapIcon($icon,&$row)
50 * 474: function wrapStop($str,&$row)
51 * 487: function getCount($uid)
52 * 508: function addField($field,$noCheck=0)
53 * 524: function expandNext($id)
54 * 534: function savePosition()
55 *
56 * SECTION: functions that might be overwritten by extended classes
57 * 551: function getRootRecord($uid)
58 * 561: function getRootIcon($rec)
59 * 571: function getRecord($uid)
60 * 585: function getId($v)
61 * 595: function getJumpToParm($v)
62 * 605: function getIcon(&$row)
63 * 619: function getTitleStr(&$row)
64 * 630: function getTitleAttrib(&$row)
65 *
66 * SECTION: data handling
67 * 663: function getTree($uid, $depth=999, $depthData='',$blankLineCode='')
68 * 737: function getDataInit($uid)
69 * 768: function getDataCount($res)
70 * 783: function getDataNext($res)
71 * 798: function getDataFree($res)
72 * 816: function setDataFromArray($dataArr,$recursive=0,$parent=0,$icount=1)
73 *
74 * TOTAL FUNCTIONS: 27
75 * (This index is automatically created/updated by the extension "extdeveval")
76 *
77 */
78
79
80
81
82
83
84
85
86
87
88
89 require_once (PATH_t3lib.'class.t3lib_iconworks.php');
90 require_once (PATH_t3lib.'class.t3lib_befunc.php');
91 require_once (PATH_t3lib.'class.t3lib_div.php');
92
93 /**
94 * Base class for creating a page/folder tree in HTML
95 *
96 * @author Kasper Skårhøj <kasper@typo3.com>
97 * @coauthor René Fritz <r.fritz@colorcube.de>
98 * @see t3lib_browsetree
99 * @see t3lib_pagetree
100 * @see t3lib_foldertree
101 * @package TYPO3
102 * @subpackage t3lib
103 */
104 class t3lib_treeView {
105
106 /*
107 * Needs to be initialized with $GLOBALS['BE_USER']
108 */
109 var $BE_USER='';
110
111 /*
112 * Needs to be initialized with e.g. $GLOBALS['WEBMOUNTS']
113 */
114 var $MOUNTS='';
115
116 /**
117 * A prefix for table cell id's which will be wrapped around an item.
118 * Can be used for highlighting by JavaScript.
119 * Needs to be unique if multiple pages are on one HTML page.
120 */
121 var $domIdPrefix = 'row';
122
123 /*
124 * Database table to get the tree data from.
125 * Leave blank if data comes from an array.
126 */
127 var $table='';
128
129 /*
130 * Defines the field of $table which is the parent id field (like pid for table pages).
131 */
132 var $parentField='pid';
133
134 /*
135 * Unique name for the tree.
136 * Used as key for storing the tree into the BE users settings.
137 * Used as key to pass parameters in links.
138 * etc.
139 */
140 var $treeName = '';
141
142 /*
143 * Icon file name for item icons.
144 */
145 var $iconName = 'default.gif';
146
147 /*
148 * Icon file path.
149 */
150 var $iconPath = '';
151
152 /**
153 * Back path for icons
154 */
155 var $backPath;
156
157
158 /**
159 * If true, HTML code is also accumulated in ->tree array during rendering of the tree.
160 */
161 var $makeHTML=1;
162
163 /**
164 * If true, records as selected will be stored internally in the ->recs array
165 */
166 var $setRecs = 0;
167
168 /**
169 * WHERE clause used for selecting records for the tree. Is set by function init
170 * @see init()
171 */
172 var $clause=' AND NOT deleted';
173
174
175 /**
176 * Default set of fields selected from the tree table.
177 * @see addField()
178 */
179 var $fieldArray = Array('uid','title');
180
181 /**
182 * List of other fields which are ALLOWED to set
183 * @see addField()
184 */
185 var $defaultList = 'uid,pid,tstamp,sorting,deleted,perms_userid,perms_groupid,perms_user,perms_group,perms_everybody,crdate,cruser_id';
186
187
188 // *********
189 // internal
190 // *********
191 // For record trees:
192 var $ids = Array(); // one-dim array of the id's selected.
193 var $ids_hierarchy = array(); // The hierarchy of page ids
194 var $buffer_idH = array(); // Temporary, internal array
195
196 // For FOLDER trees:
197 var $specUIDmap=array(); // Special UIDs for folders (integer-hashes of paths)
198
199 // For both types
200 var $tree = Array(); // Tree is accumulated in this variable
201
202
203
204
205
206 /**
207 * The tree array. Stored for the BE user.
208 */
209 var $stored = array();
210
211
212 var $bank=0;
213 var $thisScript='';
214 var $expandAll=0;
215 var $expandFirst=0;
216
217
218
219
220
221
222
223 // which HTML attribute to use: alt/title
224 var $titleAttrib = 'title';
225
226 // $ext_IconMode = $BE_USER->getTSConfigVal("options.pageTree.disableIconLinkToContextmenu");
227 var $ext_IconMode = false;
228
229 var $addSelfId = 0;
230
231 // used if the tree is made of records (not folders for ex.)
232 var $title='no title';
233
234 var $data = array();
235 var $currData = array();
236 var $currDataC = 0;
237
238 // internal
239 var $recs = array();
240
241 var $dbres;
242
243
244 /**
245 * Initialize the tree class. Needs to be overwritten
246 * Will set ->fieldsArray, ->backPath and ->clause
247 *
248 * @param string record select clause
249 * @return void
250 */
251 function init($clause='') {
252 $this->BE_USER = $GLOBALS['BE_USER'];
253 $this->titleAttrib = t3lib_BEfunc::titleAttrib();
254 $this->backPath = $GLOBALS['BACK_PATH'];
255
256 $this->clause = $clause ? $clause : $this->clause;
257
258 if(!is_array($this->MOUNTS)){
259 $this->MOUNTS = array(0 => 0); // dummy
260 }
261 }
262
263 /**
264 * Resets the tree, recs, ids, and ids_hierarchy internal variables
265 *
266 * @return void
267 */
268 function reset() {
269 $this->tree = array();
270 $this->recs = array();
271 $this->ids = array();
272 $this->ids_hierarchy = array();
273 }
274
275 /**
276 * Will create and return the HTML code for a browsable tree
277 * Is based on the mounts found in the internal array ->MOUNTS (set in the constructor)
278 *
279 * @param string Additional WHERE clause (this is additional clauses you can set!)
280 * @return string HTML code for the browsable tree
281 */
282 function getBrowsableTree($addClause='') {
283 #TODO: $this->init($addClause);
284 #TODO: $this->init(' AND '.$this->permsC().$addClause);
285
286 // Get stored tree structure:
287 $this->stored=unserialize($this->BE_USER->uc[$this->treeName]);
288 #debug($this->stored);
289 // PM action
290 // (If an plus/minus icon has been clicked, the PM GET var is sent and we must update the stored positions in the tree):
291 $PM = explode('_',t3lib_div::GPvar('PM'));
292 #debug($PM);
293
294 if (count($PM)==4 && $PM[3]==$this->treeName) {
295 if (isset($this->MOUNTS[$PM[0]])) {
296 if ($PM[1]) { // set
297 $this->stored[$PM[0]][$PM[2]]=1;
298 $this->savePosition();
299 } else { // clear
300 unset($this->stored[$PM[0]][$PM[2]]);
301 $this->savePosition();
302 }
303 }
304 }
305
306 // traverse mounts:
307 $titleLen=intval($this->BE_USER->uc['titleLen']);
308 $treeArr=array();
309 reset($this->MOUNTS);
310 while(list($idx,$uid)=each($this->MOUNTS)) {
311 // Set first:
312 $this->bank=$idx;
313 $isOpen = $this->stored[$idx][$uid] || $this->expandFirst;
314
315 $curIds = $this->ids; // save ids
316 $this->reset();
317 $this->ids = $curIds;
318
319 // Set PM icon:
320 $cmd=$this->bank.'_'.($isOpen?"0_":"1_").$uid.'_'.$this->treeName;
321 $icon='<img src="'.$this->backPath.'t3lib/gfx/ol/'.($isOpen?'minus':'plus').'only.gif" width="18" height="16" align="top" border="0" alt="" />';
322 $firstHtml= $this->PM_ATagWrap($icon,$cmd);
323
324 // Preparing rootRec for the mount
325 if ($uid>0) {
326 $rootRec=$this->getRecord($uid);
327 $firstHtml.=$this->getIcon($rootRec);
328 } else {
329 // Artificial record for the tree root, id=0
330 $rootRec=$this->getRootRecord($uid);
331 $firstHtml.=$this->getRootIcon($rootRec);
332 }
333
334 // Add the root of the mount to ->tree
335 $this->tree[]=array('HTML'=>$firstHtml,'row'=>$rootRec);
336
337 // If the mount is expanded, go down:
338 if ($isOpen) {
339 // Set depth:
340 $depthD='<img src="'.$this->backPath.'t3lib/gfx/ol/blank.gif" width="18" height="16" align="top" alt="" />';
341 if ($this->addSelfId) $this->ids[] = $uid;
342 $this->getTree($uid,999,$depthD);
343 }
344
345 // Add tree:
346 $treeArr=array_merge($treeArr,$this->tree);
347 }
348 return $this->printTree($treeArr);
349 }
350
351 /**
352 * Compiles the HTML code for displaying the structure found inside the ->tree array
353 *
354 * @param array "tree-array" - if blank string, the internal ->tree array is used.
355 * @return string The HTML code for the tree
356 */
357 function printTree($treeArr='') {
358 $titleLen=intval($this->BE_USER->uc['titleLen']);
359 if (!is_array($treeArr)) $treeArr=$this->tree;
360 reset($treeArr);
361 $out='';
362
363 // put a table around it with IDs to access the rows from JS
364 // not a problem if you don't need it
365 // In XHTML there is no "name" attribute of <td> elements - but Mozilla will not be able to highlight rows if the name attribute is NOT there.
366 $out .= '<table cellpadding="0" cellspacing="0" border="0" width="100%">';
367 while(list($k,$v)=each($treeArr)) {
368 $idAttr = htmlspecialchars($this->domIdPrefix.$this->getId($v['row']));
369 $out.='
370 <tr>
371 <td name="'.$idAttr.'" id="'.$idAttr.'" nowrap="nowrap">'.
372 $v['HTML'].
373 $this->wrapTitle(t3lib_div::fixed_lgd($this->getTitleStr($v['row']),$titleLen),$v['row']).
374 '</td>
375 </tr>
376 ';
377 }
378 $out .= '</table>';
379 return $out;
380 }
381
382
383
384 /**
385 * Generate the plus/minus icon for the browsable tree.
386 * Extending parent function
387 *
388 * @param array record for the entry
389 * @param integer The current entry number
390 * @param integer The total number of entries. If equal to $a, a "bottom" element is returned.
391 * @param integer The number of sub-elements to the current element.
392 * @param boolean The element was expanded to render subelements if this flag is set.
393 * @return string Image tag with the plus/minus icon.
394 * @access private
395 * @see t3lib_pageTree::PMicon()
396 */
397 function PMicon(&$row,$a,$c,$nextCount,$exp) {
398 $PM = $nextCount ? ($exp?'minus':'plus') : 'join';
399 $BTM = ($a==$c)?'bottom':'';
400 $icon = '<img src="'.$this->backPath.'t3lib/gfx/ol/'.$PM.$BTM.'.gif" width="18" height="16" align="top" border="0" alt="" />';
401
402 if ($nextCount) {
403 $cmd=$this->bank.'_'.($exp?'0_':'1_').$row['uid'].'_'.$this->treeName;
404 $bMark=($this->bank.'_'.$row['uid']);
405 $icon = $this->PM_ATagWrap($icon,$cmd,$bMark);
406 }
407 return $icon;
408 }
409
410 /**
411 * Wrap the plus/minus icon in a link
412 *
413 * @param string HTML string to wrap, probably an image tag.
414 * @param string Command for 'PM' get var
415 * @param boolean If set, the link will have a anchor point (=$bMark) and a name attribute (=$bMark)
416 * @return string Link-wrapped input string
417 * @access private
418 */
419 function PM_ATagWrap($icon,$cmd,$bMark='') {
420 if ($bMark) {
421 $anchor = '#'.$bMark;
422 $name=' name="'.$bMark.'"';
423 }
424 $aUrl = $this->thisScript.'?PM='.$cmd.$anchor;
425 return '<a href="'.htmlspecialchars($aUrl).'"'.$name.'>'.$icon.'</a>';
426 }
427
428 /**
429 * Wrapping $title in a-tags.
430 * $v is the array with item and other info.
431 *
432 * @param string Title string
433 * @param string Not used, ignore
434 * @return string Either htmlspecialchar()'ed version of input value OR (if input was empty) a label like "[no title]"
435 * @access private
436 */
437 function wrapTitle($title,$v) {
438 $aOnClick = 'return jumpTo('.$this->getJumpToParm($v).',this);';
439 return '<a href="#" onclick="'.htmlspecialchars($aOnClick).'">'.$title.'</a>';
440 }
441
442 /**
443 * Wrapping the image tag, $icon, for the row, $row
444 *
445 * @param string The image tag for the icon
446 * @param array The row for the current element
447 * @return string The processed icon input value.
448 * @access private
449 */
450 function wrapIcon($icon,&$row) {
451 // Add title attribute to input icon tag
452 $lockIcon='';
453 $theIcon = substr($icon,0,-1);
454 $theIcon .= $this->titleAttrib? (' '.$this->titleAttrib.'="'.$this->getTitleAttrib($row)).'"' : '';
455 $theIcon .= ' border="0" />';
456
457 // Wrap icon in click-menu link.
458 if (!$this->ext_IconMode) {
459 $theIcon = $GLOBALS['TBE_TEMPLATE']->wrapClickMenuOnIcon($theIcon,$this->treeName,$this->getId($row),0);
460 } elseif (!strcmp($this->ext_IconMode,'titlelink')) {
461 $aOnClick = 'return jumpTo('.$this->getJumpToParm($row).',this);';
462 $theIcon='<a href="#" onclick="'.htmlspecialchars($aOnClick).'">'.$theIcon.'</a>';
463 }
464 return $theIcon.$lockIcon;
465 }
466
467 /**
468 * Adds a red "+" to the input string, $str, if the field "php_tree_stop" in the $row (pages) is set
469 *
470 * @param string Input string, like a page title for the tree
471 * @param array record row with "php_tree_stop" field
472 * @return string Modified string
473 * @access private
474 */
475 function wrapStop($str,&$row) {
476 if ($row['php_tree_stop']) {
477 $str.='<span class="typo3-red">+ </span>';
478 }
479 return $str;
480 }
481 /**
482 * Returns the number of records having the parent id, $uid
483 *
484 * @param integer id to count subitems for
485 * @return integer
486 * @access private
487 */
488 function getCount($uid) {
489 if ($this->table) {
490 $query = 'SELECT count(*) FROM '.$this->table.
491 ' WHERE '.$this->parentField.'="'.addslashes($uid).'"'.
492 $this->clause;
493 $res = mysql(TYPO3_db, $query);
494 $row=mysql_fetch_row($res);
495 return $row[0];
496 } else {
497 $res = $this->getDataInit($uid);
498 return $this->getDataCount($res);
499 }
500 }
501
502 /**
503 * Adds a fieldname to the internal array ->fieldArray
504 *
505 * @param string Field name to
506 * @param boolean If set, the fieldname will be set no matter what. Otherwise the field name must either be found as key in $TCA['pages']['columns'] or in the list ->defaultList
507 * @return void
508 */
509 function addField($field,$noCheck=0) {
510 global $TCA;
511 if ($noCheck || is_array($TCA[$this->table]['columns'][$field]) || t3lib_div::inList($this->defaultList,$field)) {
512 $this->fieldArray[]=$field;
513 }
514 }
515
516 /**
517 * Returns true/false if the next level for $id should be expanded - based on data in $this->stored[][] and ->expandAll flag.
518 * Extending parent function
519 *
520 * @param integer record id/key
521 * @return boolean
522 * @access private
523 * @see t3lib_pageTree::expandNext()
524 */
525 function expandNext($id) {
526 return ($this->stored[$this->bank][$id] || $this->expandAll)? 1 : 0;
527 }
528
529 /**
530 * Saves the content of ->stored (keeps track of expanded positions in the tree)
531 * $this->treeName will be used as key for BE_USER->uc[] to store it in
532 *
533 * @return void
534 */
535 function savePosition() {
536 $this->BE_USER->uc[$this->treeName] = serialize($this->stored);
537 $this->BE_USER->writeUC();
538 }
539
540
541
542 /******************************
543 *
544 * functions that might be overwritten by extended classes
545 *
546 ********************************/
547
548 /**
549 * @param [type] $uid: ...
550 * @return [type] ...
551 */
552 function getRootRecord($uid) {
553 return array( 'title'=>$this->title, 'uid'=>0 );
554 }
555
556 /**
557 * [Describe function...]
558 *
559 * @param [type] $rec: ...
560 * @return [type] ...
561 */
562 function getRootIcon($rec) {
563 return $this->wrapIcon('<img src="'.$this->backPath.'gfx/i/_icon_website.gif" width="18" height="16" align="top" alt="" />',$rec);
564 }
565
566 /**
567 * [Describe function...]
568 *
569 * @param [type] $uid: ...
570 * @return [type] ...
571 */
572 function getRecord($uid) {
573 if($this->table) {
574 return t3lib_befunc::getRecord($this->table,$uid);
575 } else {
576 return $this->data[$uid];
577 }
578 }
579
580 /**
581 * [Describe function...]
582 *
583 * @param [type] $v: ...
584 * @return [type] ...
585 */
586 function getId($v) {
587 return $v['uid'];
588 }
589
590 /**
591 * [Describe function...]
592 *
593 * @param [type] $v: ...
594 * @return [type] ...
595 */
596 function getJumpToParm($v) {
597 return "'".$this->getId($v)."'";
598 }
599
600 /**
601 * [Describe function...]
602 *
603 * @param [type] $$row: ...
604 * @return [type] ...
605 */
606 function getIcon(&$row) {
607 if ($this->iconPath && $this->iconName) {
608 return '<img src="'.$this->iconPath.$this->iconName.'" width="18" height="16" align="top" alt="" />';
609 } else {
610 // rene[290903]: removed $this->wrapIcon() here, I don't think it have some side effects
611 return '<img src="'.$this->backPath.t3lib_iconWorks::getIcon($this->table,$row).'" width="18" height="16" align="top" alt="" />';
612 }
613 }
614
615 /**
616 * [Describe function...]
617 *
618 * @param [type] $$row: ...
619 * @return [type] ...
620 */
621 function getTitleStr(&$row) {
622 $title = (!strcmp(trim($row['title']),'')) ? '<em>['.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.no_title',1).']</em>' : htmlspecialchars($row['title']);
623 return $title;
624 }
625
626 /**
627 * [Describe function...]
628 *
629 * @param [type] $$row: ...
630 * @return [type] ...
631 */
632 function getTitleAttrib(&$row) {
633 return $row['title'];
634 }
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649 /********************************
650 *
651 * data handling
652 * works with records and arrays
653 *
654 ********************************/
655
656 /**
657 * fetches the data for the tree
658 *
659 * @param integer item id for which to select subitems.
660 * @param integer Max depth (recursivity limit)
661 * @param string HTML-code prefix for recursive calls.
662 * @param string ? (internal)
663 * @return integer The count of pages on the level
664 */
665 function getTree($uid, $depth=999, $depthData='',$blankLineCode='') {
666 // Buffer for id hierarchy is reset:
667 $this->buffer_idH=array();
668
669 // Init vars
670 $depth=intval($depth);
671 $HTML='';
672 $a=0;
673
674 $res = $this->getDataInit($uid);
675 $c = $this->getDataCount($res);
676
677 // Traverse the records:
678 while ($row = $this->getDataNext($res)) {
679 $a++;
680
681 $newID =$row['uid'];
682 $this->tree[]=array(); // Reserve space.
683 end($this->tree);
684 $treeKey = key($this->tree); // Get the key for this space
685 $LN = ($a==$c)?'blank':'line';
686
687 // If records should be accumulated, do so
688 if ($this->setRecs) {
689 $this->recs[$row['uid']] = $row;
690 }
691
692 // accumulate the id of the page in the internal arrays
693 $this->ids[]=$idH[$row['uid']]['uid']=$row['uid'];
694 $this->ids_hierarchy[$depth][]=$row['uid'];
695
696 // Make a recursive call to the next level
697 if ($depth>1 && $this->expandNext($newID) && !$row['php_tree_stop']) {
698 $nextCount=$this->getTree(
699 $newID,
700 $depth-1,
701 $this->makeHTML?$depthData.'<img src="'.$this->backPath.'t3lib/gfx/ol/'.$LN.'.gif" width="18" height="16" align="top" alt="" />':'',
702 $blankLineCode.','.$LN
703 );
704 if (count($this->buffer_idH)) $idH[$row['uid']]['subrow']=$this->buffer_idH;
705 $exp=1; // Set "did expanded" flag
706 } else {
707 $nextCount=$this->getCount($newID);
708 $exp=0; // Clear "did expanded" flag
709 }
710 // Set HTML-icons, if any:
711 if ($this->makeHTML) {
712 $HTML = $depthData.$this->PMicon($row,$a,$c,$nextCount,$exp);
713 $HTML.=$this->wrapStop($this->wrapIcon($this->getIcon($row),$row),$row);
714 }
715
716 // Finally, add the row/HTML content to the ->tree array in the reserved key.
717 $this->tree[$treeKey] = Array(
718 'row'=>$row,
719 'HTML'=>$HTML,
720 'invertedDepth'=>$depth,
721 'blankLineCode'=>$blankLineCode
722 );
723
724 }
725
726 $this->getDataFree($res);
727 $this->buffer_idH=$idH;
728 return $c;
729 }
730
731
732 /**
733 * getting the tree data: init
734 *
735 * @param integer parent item id
736 * @return mixed data handle
737 */
738 function getDataInit($parentId) {
739 if ($this->table) {
740 $query = 'SELECT '.implode($this->fieldArray,',').' FROM '.$this->table.
741 ' WHERE '.$this->parentField.'="'.addslashes($parentId).'"'.
742 $this->clause;
743 $res = mysql(TYPO3_db, $query);
744 if (mysql_error()) {
745 echo mysql_error();
746 debug($query);
747 }
748 return $res;
749 } else {
750 if (!is_array($this->dataLookup[$parentId]['subLevel'])) {
751 $parentId = -1;
752 } else {
753 reset($this->dataLookup[$parentId]['subLevel']);
754 }
755 return $parentId;
756 }
757 }
758
759 /**
760 * getting the tree data: count
761 *
762 * @param mixed data handle
763 * @return integer number of items
764 */
765 function getDataCount($res) {
766 if ($this->table) {
767 $c=mysql_num_rows($res);
768 return $c;
769 } else {
770 return count($this->dataLookup[$res]['subLevel']);
771 }
772 }
773
774 /**
775 * getting the tree data: next entry
776 *
777 * @param mixed data handle
778 * @return array item data array
779 */
780 function getDataNext($res){
781 if ($this->table) {
782 return @mysql_fetch_assoc($res);
783 } else {
784 if ($res<0) {
785 $row=FALSE;
786 } else {
787 list(,$row) = each($this->dataLookup[$res]['subLevel']);
788 }
789 return $row;
790 }
791 }
792
793 /**
794 * getting the tree data: frees data handle
795 *
796 * @param mixed data handle
797 * @return void
798 */
799 function getDataFree($res){
800 if ($this->table) {
801 mysql_free_result($res);
802 } else {
803 # unset();
804 }
805 }
806
807
808
809 function setDataFromArray(&$dataArr,$traverse=FALSE,$pid=0) {
810
811 if (!$traverse) {
812 $this->data = &$dataArr;
813 $this->dataLookup=array();
814 // add root
815 $this->dataLookup[0]['subLevel']=&$dataArr;
816 }
817
818 foreach($dataArr as $uid => $val) {
819
820 $dataArr[$uid]['uid']=$uid;
821 $dataArr[$uid]['pid']=$pid;
822
823 // gives quick access to id's
824 $this->dataLookup[$uid] = &$dataArr[$uid];
825
826 if (is_array($val['subLevel'])) {
827 $this->setDataFromArray($dataArr[$uid]['subLevel'],TRUE,$uid);
828 }
829 }
830 }
831
832
833 /*
834 array(
835 [id1] => array(
836 'title'=>'title...',
837 'id' => 'id1',
838 'icon' => 'icon ref, relative to typo3/ folder...'
839 ),
840 [id2] => array(
841 'title'=>'title...',
842 'id' => 'id2',
843 'icon' => 'icon ref, relative to typo3/ folder...'
844 ),
845 [id3] => array(
846 'title'=>'title...',
847 'id' => 'id3',
848 'icon' => 'icon ref, relative to typo3/ folder...'
849 'subLevel' => array(
850 [id3_asdf#1] => array(
851 'title'=>'title...',
852 'id' => 'asdf#1',
853 'icon' => 'icon ref, relative to typo3/ folder...'
854 ),
855 [5] => array(
856 'title'=>'title...',
857 'id' => 'id...',
858 'icon' => 'icon ref, relative to typo3/ folder...'
859 ),
860 [6] => array(
861 'title'=>'title...',
862 'id' => 'id...',
863 'icon' => 'icon ref, relative to typo3/ folder...'
864 ),
865 )
866 ),
867 )
868 */
869
870
871
872
873
874 }
875
876
877 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_treeview.php']) {
878 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_treeview.php']);
879 }
880 ?>