Index: links.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/links/links.module,v
retrieving revision 1.3
diff -u -r1.3 links.module
--- links.module	14 Nov 2005 03:21:43 -0000	1.3
+++ links.module	5 Dec 2005 21:14:50 -0000
@@ -241,18 +241,84 @@
 }
 
 function links_admin_links() {
-  $output = '';
+  // Do the overview query
+  $query = "select * from {links} order by link_title, url";
+  $result = pager_query($query, 10);
+  $disabled = !db_num_rows($result);
+  $destination = drupal_get_destination();
+	
+  // Provide the mass update form
   $operations = array(
     '' => array(t('(Select operation)'), ''),
     'delete' => array(t('Delete the selected links'), ''),
-    'check'  => array(t('Mark for validity check'), '')
+    'check'  => array(t('Mark for validity check'), ''),
+	);
+  $options = array();
+  foreach ($operations as $key => $value) {
+    $options[$key] = $value[0];
+  }
+
+  $form = array();
+  $form['update_options'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Update options'),
+  );
+  $form['update_options']['operation'] = array(
+    '#type' => 'select',
+    '#options' => $options,
+    '#default_value' => $disabled ? 'disabled="disabled"' : '',
+  );
+  $form['update_options']['submit'] = array(
+    '#type' => 'submit',
+    '#title' => t('Update'),
+    '#return_value' => $disabled ? array('disabled' => 'disabled') : array(),
   );
 
-  // Handle operations
+	$form['links'] = array(
+		'#tree' => TRUE,
+	);
+	
+  while ($link = db_fetch_object($result)) {
+		$form['links'][$link->lid]['checked'] = array(
+			'#type' => 'checkbox',
+			'#default_value' =>  0,
+			'#return_value' => 1,
+		);
+		$form['links'][$link->lid]['title'] = array(
+			'#type' => 'item',
+			'#value' => $link->link_title,
+		);
+		$form['links'][$link->lid]['url'] = array(
+			'#type' => 'item',
+			'#value' => $link->url,
+		);
+		$form['links'][$link->lid]['changed'] = array(
+			'#type' => 'item',
+			'#value' => format_date($link->changed),
+		);
+		$form['links'][$link->lid]['operations'] = array(
+			'#type' => 'markup',
+			'#value' => l(t('edit'), 'admin/links/'. $link->lid .'/edit', array(), $destination) .' '.
+				l(t('references'), 'admin/links/'. $link->lid . '/nodes', array(), $destination) .' '.
+				l(t('monitor'), 'admin/links/'. $link->lid . '/monitor', array(), $destination),
+		);
+  }
+
+  if (!$rows) {
+    $rows[] = array(array('data' => t('No links available.'), 'colspan' => '7'));
+  }
+	
+  return drupal_get_form('links_admin_links', $form);
+}
+
+function links_admin_links_execute($form_id, $edit)  {
+	// Handle operations
   $op = $_POST['op'];
   $edit = $_POST['edit'];
   if (($op == t('Update') || $op == t('Delete all')) && isset($edit['operation']) && isset($edit['links'])) {
     $edit['links'] = array_diff($edit['links'], array(0));
+// TODO: NEED TO FINISH MOVING THIS CODE...
+/*
     if (count($edit['links']) == 0) {
       form_set_error('', t('Please select some links on which to perform the update.'));
     } else {
@@ -305,72 +371,46 @@
         }
       }
     }
+*/
   }
+}
 
-  // Provide the mass update form
-  $options = array();
-  foreach ($operations as $key => $value) {
-    $options[$key] = $value[0];
-  }
-
-  $form = array();
-  $form['update_options'] = array(
-    '#type' => 'fieldset',
-    '#title' => t('Update options'),
-  );
-  $form['update_options']['operation'] = array(
-    '#type' => 'select',
-    '#options' => $options,
-    '#default_value' => $disabled ? 'disabled="disabled"' : '',
-  );
-  $form['update_options']['op'] = array(
-    '#type' => 'submit',
-    '#title' => t('Update'),
-    '#return_value' => $disabled ? array('disabled' => 'disabled') : array(),
-  );
-
-//  $form = form_select(NULL, 'operation', '', $options, NULL, ($disabled ? 'disabled="disabled"' : ''));
-//  $form .= form_submit(t('Update'), 'op', ($disabled ? array('disabled' => 'disabled') : array()));
-//  $output .= form_group(t('Update options'), "<div class=\"container-inline\">$form</div>");
-
-  $output .= drupal_get_form('links_update_options', $form);
-
-//STUB
-return $output;
-
-// TODO:  Find a way to integrate this table into the form directly above.
-//        For now, this is intentionally dead code to the end of this function.
-
-  // Do the overview query
-  $query = "select * from {links} order by link_title, url";
-  $result = pager_query($query, 10);
-  $disabled = !db_num_rows($result);
-  $header = array(t('Select'), t('Title'), t('URL'), t('Changed'), NULL, t('Operations'), NULL);
-  $destination = drupal_get_destination();
-  while ($link = db_fetch_object($result)) {
-    $rows[] = array(form_checkbox(NULL, 'links]['. $link->lid, 1, 0),
-                    $link->link_title,
-                    l($link->url, $link->url, array('target'=>'_blank')),
-                    format_date($link->changed),
-                    l(t('edit'), 'admin/links/'. $link->lid .'/edit', array(), $destination),
-                    l(t('references'), 'admin/links/'. $link->lid . '/nodes', array(), $destination),
-                    l(t('monitor'), 'admin/links/'. $link->lid . '/monitor', array(), $destination));
+function theme_links_admin_links($form) {
+	// convert the form data into a rows for a table
+	$rows = array();
+  foreach (element_children($form['links']) as $key) {
+    $row = array();
+    if (is_array($form['htmlarea_toolbar'][$key]['desc'])) {
+      $row[] = form_render($form['links'][$key]['checked']) . form_render($form['links'][$key]['title']);
+      $row[] = form_render($form['links'][$key]['url']);
+			$row[] = form_render($form['links'][$key]['changed']);
+      $row[] = form_render($form['links'][$key]['operations']);
+    }
+    $rows[] = $row;
   }
+  $header = array(t('Title'), t('URL'), t('Changed'), t('Operations'));
 
+	// add a pager... not sure if this really works...
   // $tags 0=>first, 1=>previous, 2=>list, 3=>next, 4=>last
   if ($pager = theme('pager', NULL, 10)) {
-    $rows[] = array(array('data' => $pager, 'colspan' => '7'));
+    $rows[] = array(array('data' => $pager, 'colspan' => '4'));
   }
 
+	// check for no rows
   if (!$rows) {
-    $rows[] = array(array('data' => t('No links available.'), 'colspan' => '7'));
+    $rows[] = array(array('data' => t('No links available.'), 'colspan' => '4'));
   }
 
+	// render there the top form...
+	$output = form_render($form['update_options']);
+	// then the table
   $output .= theme('table', $header, $rows);
- 
-  return form($output, 'post', url('admin/links'));
+	// then anything left over
+  $output .= form_render($form);
+  return $output;
 }
 
+
 function links_menu_goto() {
   $nid = arg(2);
   $lid = arg(3);

