--- C:/original/indexpage.module	Tue Oct 21 18:08:16 2008
+++ C:/modified/indexpage.module	Wed Oct 22 14:54:12 2008
@@ -146,7 +146,16 @@
         '#title' => t('Show vocabulary filters for this node type'),
         '#return_value' => 1,
         '#default_value' => variable_get($var_prefix .'_vocfilter', 1),
-        );
+        );
+
+       // Add treeview Support
+       $form[$set][$var_prefix .'_treeview'] = array(
+        '#type' => 'checkbox',
+        '#title' => t('Show vocabulary filters within a Tree View'),
+        '#return_value' => 1,
+        '#default_value' => variable_get($var_prefix .'_treeview', 1),
+        );
+        
     }
     else {
       $form[$set][$var_prefix .'_vocfilter'] = array(
@@ -222,9 +231,30 @@
 }
 
 function indexpage_page($type, $op = NULL) {
-  global $user;
+  global $user;
+  
+  // if there is only one type, go directly to it!!
+  if ( !arg(1) ){
+  	$how_much_to_show = 0;
+  	$the_type = "";
+    $types = node_get_types('names');
+    foreach ($types as $type => $name) {
+      if (variable_get('indexpage_'. $type .'_enable', 1)) {
+        $how_much_to_show += 1;
+        $the_type = $type;
+      }
+    }
+    
+    if ($how_much_to_show == 1)
+    	$arg_1 = $the_type;
+    	$arg_2 = arg(2);
+  } else {
+  	$arg_1 = arg(1);
+    $arg_2 = arg(2);
+  }
+   
   // Is this the overview index?
-  if (!arg(1)) {
+  if (!$arg_1) {
     $output .= '<div class="content">';
     $output .= nl2br(variable_get('indexpage_description', ''));
     $output .= '<ul>';
@@ -243,14 +273,14 @@
     // Do the index for a specific type.
     $access = _node_access_where_sql();
 //    $exist_type = @db_result(db_query(_indexpage_check_status("SELECT COUNT(n.type) FROM {node} n, {node_access} na WHERE n.type = '%s'") . ($access ? ' AND '. $access : ''), arg(1)));
-    $exist_type = @db_result(db_query(_indexpage_check_status("SELECT COUNT(DISTINCT(n.nid)) FROM {node} n, {node_access} na WHERE n.type = '%s'") . ($access ? ' AND '. $access : ''), arg(1)));
-    if ($exist_type && variable_get('indexpage_'. arg(1) .'_enable', 1)) {
+    $exist_type = @db_result(db_query(_indexpage_check_status("SELECT COUNT(DISTINCT(n.nid)) FROM {node} n, {node_access} na WHERE n.type = '%s'") . ($access ? ' AND '. $access : ''), $arg_1));
+    if ($exist_type && variable_get('indexpage_'. $arg_1 .'_enable', 1)) {
 //      if (!arg(2)) {
       if (empty($op) && $op !== '0') {
-        return indexpage_page_index(arg(1), $exist_type);
+        return indexpage_page_index($arg_1, $exist_type);
       }
       else {
-        return indexpage_page_list(arg(1), arg(2));
+        return indexpage_page_list($arg_1, $arg_2);
       }
     }
     else {
@@ -321,28 +351,67 @@
       }
       $term_list = array();
       $voc_list[$voc['vid']] = check_plain($voc['name']);
-      $output .= '<div class="indexpage-filter-'. $voc['vid'] .'">';
       $voc_count = 0;
-
-      $terms = db_query('SELECT name, tid FROM {term_data} WHERE vid=%d ORDER BY weight, name', $voc['vid']);
-      while ($term = db_fetch_object($terms)) {
-        $sql = _indexpage_check_status("SELECT COUNT(n.nid) FROM {node} n LEFT JOIN {term_node} t on n.nid=t.nid WHERE type='%s' AND t.tid=%d");
-        $how_many = db_result(db_query($sql, $type, $term->tid));
-        if ($how_many) {
-          $term_list[] = l($term->name, "indexpage/$type/$term->tid") . ($show_count ? ' ('. $how_many .')' : NULL);
-          $voc_count += $how_many;
-        }
-        else {
-          if (!$suppress_unused) {
-            $term_list[] = check_plain($term->name);
-          }
-        }
-      }
-      if ($term_list) {
-        $stuff = implode(' | ', $term_list);
-      }
-      else {
-        $stuff = t('None found');
+
+      // Check if Tree View checkbox is checked
+      if (variable_get('indexpage_'. $type .'_treeview', 1)) {
+		  // Include css and js needed to manage the treeview
+		  $path_tax_man = drupal_get_path('module', 'taxonomy_manager');
+		  drupal_add_css($path_tax_man.'/css/taxonomy_manager.css');
+		  drupal_add_js($path_tax_man.'/js/tree.js');
+		  drupal_add_js(array('taxonomy_manager' => array('modulePath' => (url($module_path) == $module_path) ? $module_path : (base_path() . $module_path))), 'setting');
+		  drupal_add_js(array('taxonomytree' => array('id' => 'IndexPage-TreeView', 'vid' => $voc['vid'])), 'setting');
+
+		  $output .= '<div id="IndexPage-TreeView" class="indexpage-filter-'. $voc['vid'] .'">';		  
+		  
+		  // Query with Hierarchy structure
+	      $sql = "SELECT td.tid, td.vid, td.name"
+	         . "  FROM {term_data} td"
+	         . "  JOIN {term_hierarchy} th on th.tid = td.tid"
+	         . " WHERE th.parent = %d"
+	         . "   AND td.vid = %d"
+	         . " ORDER BY td.weight, td.name";
+	      $terms = db_query($sql, 0, $voc['vid']);
+	      
+	      $stuff = "";
+	      while ($avoc = db_fetch_object($terms)) {
+	    	$child_content = get_child_terms($avoc->tid, $voc['vid']);
+	    	if ( $child_content === '' )
+	    		$li_type = "";
+	    	else
+	    		$li_type = "class='expandable '";
+	    	
+	        $stuff .= "<li $li_type>\n".pre_li();
+	        $stuff .=  " "
+	                .  l("$avoc->name", "taxonomy/term/$avoc->tid/all") . " ("
+	                .  taxonomy_term_count_nodes($avoc->tid).")"
+	                .  $child_content
+	                .  post_li()                
+	                .  "</li>\n";
+		  }
+	      $stuff = ($stuff != "") ? "<ul>\n". $stuff ."</ul>\n" : t('None found');      	
+      } else {
+      	  $output .= '<div class="indexpage-filter-'. $voc['vid'] .'">';
+	      $terms = db_query('SELECT name, tid FROM {term_data} WHERE vid=%d ORDER BY weight, name', $voc['vid']);
+	      while ($term = db_fetch_object($terms)) {
+	        $sql = _indexpage_check_status("SELECT COUNT(n.nid) FROM {node} n LEFT JOIN {term_node} t on n.nid=t.nid WHERE type='%s' AND t.tid=%d");
+	        $how_many = db_result(db_query($sql, $type, $term->tid));
+	        if ($how_many) {
+	          $term_list[] = l($term->name, "indexpage/$type/$term->tid") . ($show_count ? ' ('. $how_many .')' : NULL);
+	          $voc_count += $how_many;
+	        }
+	        else {
+	          if (!$suppress_unused) {
+	            $term_list[] = check_plain($term->name);
+	          }
+	        }
+	      }
+	      if ($term_list) {
+	        $stuff = implode(' | ', $term_list);
+	      }
+	      else {
+	        $stuff = t('None found');
+	      }
       }
       $fieldset = array(
         '#title' => t('List by !s terms', array('!s' => $voc['name'])) . ($show_count ? ' ('. $voc_count .')' : NULL),
@@ -577,3 +646,48 @@
   $output .= theme('table', $header, $rows) . theme('pager', NULL, $max_results, 0);
   return $output .'</div>';
 }
+
+
+/*
+ * New functions to support Tree View
+ * Based on code :
+ * http://drupal.org/node/53085
+ */
+
+function pre_li(){
+  	return "   <div class='term-line'>\n"
+		.  "	   <div class='term-item'>\n";
+  }
+  
+  function post_li(){
+  	return  "</div>\n" 
+		 .  "   </div>\n";;
+  }
+  
+  function get_child_terms($parent, $vid) {
+      $sql = "SELECT td.tid, td.vid, td.name"
+         . "  FROM {term_data} td"
+         . "  JOIN {term_hierarchy} th on th.tid = td.tid"
+         . " WHERE th.parent = %d"
+         . "   AND td.vid = %d"
+         . " ORDER BY td.weight, td.name";
+    $terms = db_query($sql, $parent, $vid);
+    $output = "";
+    while ($aterm = db_fetch_object($terms)) {
+    	$child_content = get_child_terms($aterm->tid, $vid);
+    	if ( $child_content === '' )
+    		$li_type = "";
+    	else
+    		$li_type = "class='expandable '";
+    	
+        $output .= "<li $li_type>\n".pre_li();
+        $output .=  " "
+                .  l("$aterm->name", "taxonomy/term/$aterm->tid/all") . " ("
+                .  taxonomy_term_count_nodes($aterm->tid).")"
+                .  $child_content
+                .  post_li()                
+                .  "</li>\n";
+
+    }
+    return ($output != "") ? "<ul>\n". $output ."</ul>\n" : "";
+  }
\ No newline at end of file
