home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 April / CMCD0404.ISO / Software / Freeware / Programare / groupoffice-com-2.01 / modules / filesystem / treeview.inc < prev    next >
Text File  |  2004-03-08  |  8KB  |  268 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. $image['mlastnode'] = '<img src="'.$GO_THEME->images['mlastnode'].'" border="0" height="22" width="16" />';
  14. $image['emptylastnode'] = '<img src="'.$GO_THEME->images['emptylastnode'].'" border="0" height="22" width="16" />';
  15. $image['plastnode'] = '<img src="'.$GO_THEME->images['plastnode'].'" border="0" height="22" width="16" />';
  16. $image['mnode'] = '<img src="'.$GO_THEME->images['mnode'].'" border="0" height="22" width="16" />';
  17. $image['emptynode'] = '<img src="'.$GO_THEME->images['emptynode'].'" border="0" height="22" width="16" />';
  18. $image['pnode'] = '<img src="'.$GO_THEME->images['pnode'].'" border="0" height="22" width="16" />';
  19. $image['vertline'] = '<img src="'.$GO_THEME->images['vertline'].'" border="0" height="22" width="16" />';
  20. $image['blank'] = '<img src="'.$GO_THEME->images['blank'].'" border="0" height="22" width="16" />';
  21. $image['group'] = '<img src="'.$GO_THEME->images['workgroup'].'" border="0" height="22" width="24" />';
  22. $image['user'] = '<img src="'.$GO_THEME->images['workstation'].'" border="0" height="22" width="20" />';
  23.  
  24. $image['opened_folder'] = '<img src="'.$GO_THEME->images['folderopen'].'" border="0" height="22" width="24" />';
  25. $image['closed_folder'] = '<img src="'.$GO_THEME->images['folderclosed'].'" border="0" height="22" width="24" />';
  26. $image['opened_folder_shared'] = '<img src="'.$GO_THEME->images['shared_folder_open'].'" border="0" height="22" width="24" />';
  27. $image['closed_folder_shared'] = '<img src="'.$GO_THEME->images['shared_folder_closed'].'" border="0" height="22" width="24" />';
  28. function print_filesystem($folders, $images='', $arguments='')
  29. {
  30.     global $image, $path, $GO_SECURITY;
  31.  
  32.     $fs = new filesystem();
  33.  
  34.     $count = count($folders);
  35.     for ($i=0;$i<$count;$i++)
  36.     {
  37.         if ($fs->has_read_permission($GO_SECURITY->user_id, $folders[$i]['path']))
  38.         {
  39.             $subfolders = $fs->get_folders($folders[$i]['path']);
  40.             $subfolders_count = count($subfolders);
  41.             $open = in_array($folders[$i]['path'], $_SESSION['expanded']);
  42.         }else
  43.         {
  44.             $subfolders = array();
  45.             $subfolders_count = 0;
  46.             $open = false;
  47.         }
  48.  
  49.         if ($subfolders_count > 0)
  50.         {
  51.             if ($i < ($count-1))
  52.             {
  53.                 $new_image = $image['vertline'];
  54.                 $node = $open ? $image['mnode'] : $image['pnode'];
  55.  
  56.             }else
  57.             {
  58.                 $new_image = $image['blank'];
  59.                 $node = $open ? $image['mlastnode'] : $image['plastnode'];
  60.             }
  61.         }else
  62.         {
  63.             if ($i < ($count-1))
  64.             {
  65.                 $new_image = $image['vertline'];
  66.                 $node = $image['emptynode'];
  67.             }else
  68.             {
  69.                 $new_image = $image['blank'];
  70.                 $node = $image['emptylastnode'];
  71.             }
  72.         }
  73.  
  74.         if ($folders[$i]['path'] == $path)
  75.         {
  76.             if($fs->get_share($folders[$i]['path']))
  77.             {
  78.                 $folder_image = $image['opened_folder_shared'];
  79.             }else
  80.             {
  81.                 $folder_image = $image['opened_folder'];
  82.             }
  83.         }else
  84.         {
  85.             if($fs->get_share($folders[$i]['path']))
  86.             {
  87.                 $folder_image = $image['closed_folder_shared'];
  88.             }else
  89.             {
  90.                 $folder_image = $image['closed_folder'];
  91.             }
  92.  
  93.         }
  94.  
  95.         $short_name = cut_string($folders[$i]['name'], 30);
  96.         echo '<table border="0" cellpadding="0" cellspacing="0">';
  97.         echo '<tr><td nowrap><a href="'.$_SERVER['PHP_SELF'].'?path='.urlencode($path).'&expand_path='.urlencode($folders[$i]['path']).$arguments.'">'.$images.$node.'</a>'.$folder_image.'</td>';
  98.         echo '<td nowrap><a href="'.$_SERVER['PHP_SELF'].'?path='.urlencode($folders[$i]['path']).$arguments.'" title="'.$folders[$i]['name'].'">'.$short_name.'</a></td></tr></table>';
  99.  
  100.         if ($open)
  101.         {
  102.             print_filesystem($subfolders, $images.$new_image, $arguments);
  103.         }
  104.     }
  105.     unset($fs);
  106. }
  107.  
  108.  
  109. if (!isset($_SESSION['expanded']))
  110. {
  111.     $_SESSION['expanded'][]=-1;
  112. }
  113.  
  114. //expand or collaps the expand id which is passed when a user clicks a node
  115. if (isset($_REQUEST['expand_path']))
  116. {
  117.     $expand_path = smartstrip($_REQUEST['expand_path']);
  118.     $key = array_search($expand_path, $_SESSION['expanded']);
  119.     if (!$key)
  120.     {
  121.         $_SESSION['expanded'][] = $expand_path;
  122.     }else
  123.     {
  124.         unset($_SESSION['expanded'][$key]);
  125.     }
  126. }else
  127. {
  128.     //always expand folder clicks
  129.     if (isset($path))
  130.     {
  131.         $key = array_search($path, $_SESSION['expanded']);
  132.         if (!$key)
  133.         {
  134.             $_SESSION['expanded'][] = $path;
  135.         }
  136.  
  137.     }
  138. }
  139.  
  140. //stay in search mode if search is clicked
  141. if ($task == 'search')
  142. {
  143.     $arguments = '&task=search';
  144. }else
  145. {
  146.     $arguments = '';
  147. }
  148.  
  149. echo '<table border="0" cellpadding="0" cellspacing="0">';
  150. echo '<tr><td nowrap><a href="'.$_SERVER['PHP_SELF'].'?path='.urlencode($home_path).$arguments.'">'.$image['user'].'</a></td>';
  151. echo '<td nowrap><a href="'.$_SERVER['PHP_SELF'].'?path='.urlencode($home_path).$arguments.'">home</a></td></tr></table>';
  152.  
  153. $folder = array();
  154. $folder['path'] = $home_path;
  155. $folder['name'] = basename($folder['path']);
  156. print_filesystem(array($folder),'',$arguments);
  157.  
  158. require_once($GO_CONFIG->class_path.'users.class.inc');
  159. $users = new users();
  160. $users_array = array();
  161.  
  162. foreach ( $fs->get_my_shares() as $sharer )
  163. {
  164.     $users->get_user( $sharer );
  165.  
  166.     if ($users->f('id') != $GO_SECURITY->user_id)
  167.     {
  168.  
  169.         $user['id'] = $users->f('id');
  170.         $user['username'] = $users->f('username');
  171.         $middle_name = $users->f('middle_name') == '' ? '' : $users->f('middle_name').' ';
  172.         $user['name'] = $users->f('first_name').' '.$middle_name.$users->f('last_name');
  173.  
  174.         $shared_folders = array();
  175.  
  176.         if($open = in_array($sharer, $_SESSION['expanded']))
  177.         {
  178.             $share_count = $fs->get_shares($users->f('id'));
  179.  
  180.             $shared_folders = array();
  181.             $had_permission = false;
  182.             while ($fs->next_record())
  183.             {
  184.                 if (file_exists($fs->f('path')))
  185.                 {
  186.                     if (is_dir($fs->f('path')))
  187.                     {
  188.                         $is_sub_dir = isset($last_folder) ? $fs->is_sub_dir($fs->f('path'), $last_folder) : false;
  189.  
  190.                         if (!$had_permission || !$is_sub_dir)
  191.                         {
  192.                             if ($GO_SECURITY->has_permission($GO_SECURITY->user_id, $fs->f('acl_read')) || $GO_SECURITY->has_permission($GO_SECURITY->user_id, $fs->f('acl_write')))
  193.                             {
  194.                                 $folder['path'] = $fs->f('path');
  195.                                 $folder['name'] = basename($folder['path']);
  196.                                 $folder['share_path'] = $folder['path'];
  197.                                 $shared_folders[] = $folder;
  198.                                 $had_permission = true;
  199.                             }else
  200.                             {
  201.                                 $had_permission = false;
  202.                                 $share_count--;
  203.                             }
  204.                         }else
  205.                         {
  206.                             $share_count--;
  207.                         }
  208.                     }else
  209.                     {
  210.                         $share_count--;
  211.                     }
  212.                 }else
  213.                 {
  214.                     $fs2 = new filesystem();
  215.                     $fs2->delete_share($fs->f('path'));
  216.                     $share_count--;
  217.                 }
  218.                 if (!$is_sub_dir)
  219.                 {
  220.                     $last_folder = $fs->f('path');
  221.                 }
  222.             }
  223.         }
  224.  
  225.         $user['shared_folders'] = $shared_folders;
  226.         $users_array[] = $user;
  227.     }
  228. }
  229.  
  230. $counter = $count = count($users_array);
  231.  
  232. if ($count > 0)
  233. {
  234.     echo '<table border="0" cellpadding="0" cellspacing="0">';
  235.     echo '<tr><td>'.$image['group'].'</td>';
  236.     echo '<td>'.$fbShares.'</td></tr></table>';
  237.  
  238.     while($user = array_shift($users_array))
  239.     {
  240.         $open = in_array($user['id'], $_SESSION['expanded']);
  241.         $sign = $open ? 'm' : 'p';
  242.  
  243.         $share_count = count($user['shared_folders']);
  244.  
  245.         if ($counter > 1)
  246.         {    $leftside = $image['vertline'];
  247.             $node = $image[$sign.'node'];
  248.         }else
  249.         {
  250.             $leftside = $image['blank'];
  251.             $node = $image[$sign.'lastnode'];
  252.         }
  253.         $short_name = cut_string($user['name'], 30);
  254.         echo '<table border="0" cellpadding="0" cellspacing="0">';
  255.         echo '<tr><td nowrap><a href="'.$_SERVER['PHP_SELF'].'?path='.urlencode($path).'&expand_path='.urlencode($user['id']).$arguments.'" title="'.$user['name'].'">'.$node.$image['user'].'</a></td>';
  256.         echo '<td nowrap><a href="'.$_SERVER['PHP_SELF'].'?path='.urlencode($path).'&expand_path='.urlencode($user['id']).$arguments.'" title="'.$user['name'].'">'.$short_name.'</a></td></tr></table>';
  257.  
  258.  
  259.         if($open)
  260.         {
  261.             print_filesystem($user['shared_folders'], $leftside,$arguments);
  262.         }
  263.  
  264.         $counter--;
  265.     }
  266. }
  267. ?>
  268.