home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 April / CMCD0404.ISO / Software / Freeware / Programare / groupoffice-com-2.01 / modules / cms / treeview.inc < prev    next >
Text File  |  2004-03-08  |  5KB  |  149 lines

  1. <?php
  2. /*
  3. Copyright Intermesh 2003
  4. Author: Merijn Schering <mschering@intermesh.nl>
  5. Version: 1.0 Release date: 08 July 2003
  6.  
  7. This program is free software; you can redistribute it and/or modify it
  8. under the terms of the GNU General Public License as published by the
  9. Free Software Foundation; either version 2 of the License, or (at your
  10. option) any later version.
  11. */
  12.  
  13. //start of treeview code
  14. $image['mlastnode'] = '<img src="'.$GO_THEME->images['mlastnode'].'" border="0" height="22" width="16" />';
  15. $image['emptylastnode'] = '<img src="'.$GO_THEME->images['emptylastnode'].'" border="0" height="22" width="16" />';
  16. $image['plastnode'] = '<img src="'.$GO_THEME->images['plastnode'].'" border="0" height="22" width="16" />';
  17. $image['mnode'] = '<img src="'.$GO_THEME->images['mnode'].'" border="0" height="22" width="16" />';
  18. $image['emptynode'] = '<img src="'.$GO_THEME->images['emptynode'].'" border="0" height="22" width="16" />';
  19. $image['pnode'] = '<img src="'.$GO_THEME->images['pnode'].'" border="0" height="22" width="16" />';
  20. $image['vertline'] = '<img src="'.$GO_THEME->images['vertline'].'" border="0" height="22" width="16" />';
  21. $image['blank'] = '<img src="'.$GO_THEME->images['blank'].'" border="0" height="22" width="16" />';
  22. $image['group'] = '<img src="'.$GO_THEME->images['workgroup'].'" border="0" height="22" width="24" />';
  23. $image['user'] = '<img src="'.$GO_THEME->images['workstation'].'" border="0" height="22" width="20" />';
  24.  
  25. $image['opened_folder'] = '<img src="'.$GO_THEME->images['folderopen'].'" border="0" height="22" width="24" />';
  26. $image['closed_folder'] = '<img src="'.$GO_THEME->images['folderclosed'].'" border="0" height="22" width="24" />';
  27.  
  28. /*
  29. prints the folders in a tree
  30. $folders is an array of associve arrays containing an 'id' and 'name'
  31. */
  32. function print_tree($folders, $images='')
  33. {
  34.     global $image, $cms, $folder_id, $site_id;
  35.  
  36.     $count = count($folders);
  37.     for ($i=0;$i<$count;$i++)
  38.     {
  39.         //for each folder check if there are subfolders and
  40.         //add them to an array for the next instance of this recursive function
  41.         $subfolders = array();
  42.         $subfolders_count = $cms->get_folders($folders[$i]['id']);
  43.         while($cms->next_record())
  44.         {
  45.             $subfolders[] = $cms->Record;
  46.         }
  47.         //is this folder opened inthe tree?
  48.         $open = in_array($folders[$i]['id'], $_SESSION['expanded']);
  49.  
  50.         //determine the image and node to display
  51.         if ($subfolders_count > 0)
  52.         {
  53.             if ($i < ($count-1))
  54.             {
  55.                 $new_image = $image['vertline'];
  56.                 $node = $open ? $image['mnode'] : $image['pnode'];
  57.  
  58.             }else
  59.             {
  60.                 $new_image = $image['blank'];
  61.                 $node = $open ? $image['mlastnode'] : $image['plastnode'];
  62.             }
  63.         }else
  64.         {
  65.             if ($i < ($count-1))
  66.             {
  67.                 $new_image = $image['vertline'];
  68.                 $node = $image['emptynode'];
  69.             }else
  70.             {
  71.                 $new_image = $image['blank'];
  72.                 $node = $image['emptylastnode'];
  73.             }
  74.         }
  75.  
  76.         //if the current folder is the current opened folder then show an opened folder
  77.         if ($folders[$i]['id'] == $folder_id)
  78.         {
  79.             $folder_image = $image['opened_folder'];
  80.         }else
  81.         {
  82.             $folder_image = $image['closed_folder'];
  83.         }
  84.  
  85.         //actually print the current folder
  86.         $short_name = cut_string($folders[$i]['name'], 30);
  87.         echo '<table border="0" cellpadding="0" cellspacing="0">';
  88.         echo '<tr><td nowrap><a href="'.$_SERVER['PHP_SELF'].'?site_id='.$site_id.'&expand_id='.$folders[$i]['id'].'&folder_id='.$folder_id.'">'.$images.$node.$folder_image.'</a></td>';
  89.         echo '<td nowrap><a href="'.$_SERVER['PHP_SELF'].'?site_id='.$site_id.'&folder_id='.$folders[$i]['id'].'" title="'.$folders[$i]['name'].'">'.$short_name.'</a></td></tr></table>';
  90.  
  91.         if ($open)
  92.         {
  93.             print_tree($subfolders, $images.$new_image);
  94.         }
  95.     }
  96. }
  97.  
  98. //fill the first value of the expanded with -1 because of key 0
  99. //results into false at the array_search() function and behaves differently at different PHP versions
  100. if (!isset($_SESSION['expanded']))
  101. {
  102.     $_SESSION['expanded'][]=-1;
  103. }
  104.  
  105. //expand or collaps the expand id which is passed when a user clicks a node
  106. if (isset($_REQUEST['expand_id']))
  107. {
  108.     $expand_id = smartstrip($_REQUEST['expand_id']);
  109.     $key = array_search($expand_path, $_SESSION['expanded']);
  110.     if (!$key)
  111.     {
  112.         $_SESSION['expanded'][] = $expand_id;
  113.     }else
  114.     {
  115.         unset($_SESSION['expanded'][$key]);
  116.     }
  117. }else
  118. {
  119.     //always expand folder clicks
  120.     $key = array_search($folder_id, $_SESSION['expanded']);
  121.     if (!$key)
  122.     {
  123.         $_SESSION['expanded'][] = $folder_id;
  124.     }
  125. }
  126.  
  127. //end of treeview code
  128.  
  129. //print the first folder as the site
  130.  
  131. if($folder = $cms->get_folder($site['root_folder_id']))
  132. {
  133.     $short_name = cut_string($folder['name'], 30);
  134.     echo '<table border="0" cellpadding="0" cellspacing="0">';
  135.     echo '<tr><td width="20" nowrap><a href="'.$_SERVER['PHP_SELF'].'?expand_id='.$site['root_folder_id'].'"><img src="'.$GO_THEME->images['site'].'" border="0" widht="16" height="16" /></a></td>';
  136.     echo '<td nowrap><a href="'.$_SERVER['PHP_SELF'].'?site_id='.$site_id.'&folder_id='.$site['root_folder_id'].'" title="'.$folder['name'].'">'.$short_name.'</a></td></tr></table>';
  137.  
  138.     $cms->get_folders($site['root_folder_id']);
  139.     $folders = array();
  140.     while($cms->next_record())
  141.     {
  142.         $folders[] = $cms->Record;
  143.     }
  144.  
  145.     print_tree($folders);
  146. }
  147.  
  148.  
  149. ?>