--- taxonomy_multi_edit.module	2007-01-14 11:56:51.000000000 -0500
+++ taxonomy_multi_edit1.module	2007-01-14 11:56:12.000000000 -0500
@@ -1,60 +1,190 @@
-<?php
-// $Id: taxonomy_multi_edit.module,v 1.10.2.1 2005/04/15 18:56:50 weitzman Exp $
-
-function taxonomy_multi_edit_help($section = "admin/help#taxonomy_multi_edit") {
-  $output = "";
-  switch ($section) {
-    case 'admin/modules#description':
-      $output = t("Apply multiple category assignments at once.");
-      break;
-    case 'admin/node/taxonomy_multi_edit':
-      return t('Attach  categories to your posts, and then click the <b>Submit</b> button.');
-  }
-  return $output;
-}
-
-function taxonomy_multi_edit_menu($may_cache) {
-  if ($may_cache) {
-    $items[] = array('path' => 'admin/node/taxonomy_multi_edit', 'title' => t('assign categories'),
-    'callback' => 'taxonomy_multi_edit_overview',
-    'access' => user_access('administer nodes'),
-    'weight' => 5,
-    'type' => MENU_LOCAL_TASK);
-    return $items;
-  }
-}
-
-function taxonomy_multi_edit_overview() {
-  if ($edit = $_POST['edit']) {
-    foreach ($edit as $nid => $terms) {
-      if (!$tax = $terms['taxonomy']) {
-        $tax = $terms['tags'];
-      }
-      taxonomy_node_save($nid, $tax);
-    }
-    drupal_set_message(t('categories updated.'));
-  }
-
-  $numselects = 4;
-  $header = array(
-    array("data" => t('title'), ),
-    array("data" => t("vocabularies"), "colspan" => $numselects)
-  );
-  $sql = "SELECT n.nid, title, teaser, type FROM {node} n ORDER BY changed DESC";
-  $result = pager_query(db_rewrite_sql($sql), 200);
-  while ($node = db_fetch_object($result)) {
-    if ($selects = taxonomy_node_form($node->type, $node, NULL, "$node->nid][taxonomy")) {
-      $selects = array_pad($selects, $numselects, '&nbsp;');
-      array_unshift($selects, l($node->title, "node/$node->nid", array('title' => substr(strip_tags($node->teaser), 0, 80))));
-      $rows[] = $selects;
-    }
-  }
-  $form = theme('table', $header, $rows);
-  $form .= form_button('Submit');
-  if ($pager = theme("pager", NULL, 200, 0, tablesort_pager())) {
-    $form .= array(array("data" => $pager, "colspan" => $numselects+1));
-  }
-  print theme('page', form($form));
-}
-
-?>
+<?php
+// $Id: taxonomy_multi_edit.module,v 1.10.2.1 2005/04/15 18:56:50 weitzman Exp $
+// References: 
+//   http://drupal.org/node/47582  "Writing forms in tables"
+//   Perhaps this should mimic the admin/node page in node.module??
+function taxonomy_multi_edit_help($section = "admin/help#taxonomy_multi_edit"){
+  $output = "";
+  switch ($section) 
+  {
+    case 'admin/modules#description':
+      $output = t("Apply multiple category assignments at once.");
+      break;
+    case 'admin/node/taxonomy_multi_edit':
+      return t('Attach  categories to your posts, and then click the <b>Submit</b> button.');
+  }
+  return $output;
+}
+
+function taxonomy_multi_edit_menu($may_cache){
+  if ($may_cache){
+    $items[] = array(
+    'path'     => 'admin/node/taxonomy_multi_edit',
+    'title'    => t('assign categories'),
+    'callback' => 'taxonomy_multi_edit_overview',
+    'access'   => user_access('administer nodes'),
+    'weight'   => 5,
+    'type'     => MENU_LOCAL_TASK);
+    return $items;
+  }
+}
+
+function taxonomy_multi_edit_overview(){
+
+  //See node.module 1116
+  global $form_values;
+  
+  
+  $filter = node_build_filter_query();
+  
+  $result =  pager_query(
+  'SELECT n.*, u.name, u.uid FROM {node} n '. $filter['join'] .' INNER JOIN {users} u ON n.uid = u.uid '. $filter['where'] .' ORDER BY n.changed DESC', 20, 0, NULL,$filter['args']);
+  $form['taxonomy'] = array( '#tree' => TRUE);
+  while($node = db_fetch_object($result))
+	{
+  		$nodes[$node->nid] = '';
+  		$form['title'][$node->nid] = array('#value' => l($node->title, 'node/'.$node->nid) . ' ' . theme('mark', node_mark($node->nid, $node->changed)));
+  		$vocabularies = taxonomy_get_vocabularies($node->type);
+  		foreach( $vocabularies as $vocabulary )
+  		{
+  			$tree = taxonomy_get_tree($vocabulary->vid);
+  			$node_vocab_terms = taxonomy_node_get_terms_by_vocabulary($node->nid, $vocabulary->vid);
+  			$options = array();
+  			$selected = array();
+  			if ($tree)
+  			{
+  				foreach($tree as $term)
+  				{
+  					$options[$term->tid] = _taxonomy_depth($term->depth, '-') . $term->name;
+  					if ($node_vocab_terms[$term->tid]->name == $term->name)
+					{
+						$selected[$term->tid] = $term->tid;
+  
+          		}
+        		}
+    		}
+			$multiple = $vocabulary->multiple;
+    		$form['taxonomy'][$node->nid][$vocabulary->vid] = array(
+    		'#type'			=> 'select',
+    		'#title'		=> t($vocabulary->name),
+    		'#default_value'=> $selected,
+    		'#options'		=> $options,
+    		'#multiple'		=> $multiple,
+    		'#required'		=> $vocabulary->required,
+    		'#size'			=> $multiple ? min(9, count($options)) : 0,
+    		'#description'	=> t('vocabulary terms associated with node')
+    		);
+   		}
+   		$form['name'][$node->nid] = array(
+   		'#value'           => node_get_name($node)
+   		);
+   		$form['username'][$node->nid] = array(
+   		'#value'           => theme('username', $node)
+		);
+	}
+	$form['nodes'] = array (
+	'#type'              => 'checkboxes',
+	'#options'           => $nodes
+	);
+	$form['button'] = array (
+	'#type'              => 'submit',
+	'#value'             => t('Submit')
+	);
+	$form['button2'] = array (
+	'#type'              => 'submit',
+	'#value'             => t('Submit')
+	);	
+	$form['pager'] = array(
+	'#value'             => theme('pager', NULL, 20, 0)
+	);
+	//print_r($form);
+	$output = node_filter_form();
+	$output .= drupal_get_form('taxonomy_multi_edit_page', $form);
+	return $output;
+}
+
+
+/**
+ * Theme taxonomy_multi_edit_page administration overview.
+ */
+function theme_taxonomy_multi_edit_page($form){
+	$header = array(
+	'',
+	t('Title'),
+	t('Terms'),
+	t('Type'),
+	t('Author')
+	);
+	
+
+	$output .= form_render($form['button']);
+	if (isset($form['title']) && is_array($form['title'])) 
+	{
+		foreach (element_children($form['title']) as $key)
+		{
+			$row = array();
+			$row[] = form_render($form['nodes'][$key]);
+			$row[] = form_render($form['title'][$key]);
+			$row[] = form_render($form['taxonomy'][$key]);
+			$row[] = form_render($form['name'][$key]);
+			$row[] = form_render($form['username'][$key]);
+			$rows[] = $row;
+		}
+	}
+	else
+	{
+		$rows[] = array (
+		array(
+		'data' => t('No posts available.'),
+		'colspan' => '4')
+		);
+	}
+	
+	$output .= theme('table', $header, $rows);
+	if ($form['pager']['#value'])
+	{
+		$output .= form_render($form['pager']);
+	}
+	$output .= form_render($form['button2']);
+	$output .= form_render($form);
+	//print_r($form);
+	return $output;
+}
+
+function taxonomy_multi_edit_page_submit($form_id, $edit){
+//$edit['nodes'] = array_diff($edit['nodes'], array(0));
+foreach ($edit['nodes'] as $nid => $node)
+	{
+	//print "[nid] " . $nid;
+    taxonomy_node_delete($nid);
+	if (is_array($edit['taxonomy'][$nid]))
+		{
+			//Check to see if there is a vocabulary assigned
+			foreach ($edit['taxonomy'][$nid] as $vid => $term)
+			{
+				//print "<br>[vid => tid] " . $vid . "=>" . $term;
+				if (is_array($term))
+				{
+					foreach ($term as $tid)
+					{
+						if ($tid)
+						{
+							db_query('INSERT INTO {term_node} (nid, tid) VALUES (%d, %d)', $nid, $tid);
+						}
+					}
+				}
+				else if (is_object($term))
+				{
+					db_query('INSERT INTO {term_node} (nid, tid) VALUES (%d, %d)', $nid, $term->tid);
+				}
+				else if ($term)
+				{
+					db_query('INSERT INTO {term_node} (nid, tid) VALUES (%d, %d)', $nid, $term);
+				}
+			}
+			//print "<br>----<br>";
+		}
+	}
+	drupal_set_message(t('The update has been performed.'));
+	}
+?>
