Index: modules/profile/profile.admin.inc
===================================================================
RCS file: /cvs/drupal/drupal/modules/profile/profile.admin.inc,v
retrieving revision 1.1
diff -u -r1.1 profile.admin.inc
--- modules/profile/profile.admin.inc	13 Nov 2007 12:28:36 -0000	1.1
+++ modules/profile/profile.admin.inc	21 Nov 2007 03:34:08 -0000
@@ -9,27 +9,87 @@
 /**
  * Menu callback; display a listing of all editable profile fields.
  */
-function profile_admin_overview() {
-
-  $result = db_query('SELECT title, name, type, category, fid FROM {profile_fields} ORDER BY category, weight');
-  $rows = array();
+function profile_admin_overview(&$form_state) {
+  $result = db_query('SELECT title, name, type, category, fid, weight FROM {profile_fields} ORDER BY category, weight');
+  
+  $form['weights'] = array('#tree' => TRUE);
+  $form['categories'] = array('#tree' => TRUE);
   while ($field = db_fetch_object($result)) {
-    $rows[] = array(check_plain($field->title), $field->name, _profile_field_types($field->type), $field->category, l(t('edit'), "admin/user/profile/edit/$field->fid"), l(t('delete'), "admin/user/profile/delete/$field->fid"));
-  }
-  if (count($rows) == 0) {
-    $rows[] = array(array('data' => t('No fields defined.'), 'colspan' => '6'));
+    // Collect all category information
+    $categories[] = $field->category;
+    
+    // Save all field information
+    $form['names'][$field->fid] = array('#value' => check_plain($field->name.$field->fid));
+    $form['titles'][$field->fid] = array('#value' => check_plain($field->title));
+    $form['types'][$field->fid] = array('#value' => $field->type);
+    $form['categories'][$field->fid] = array('#type' => 'select', '#default_value' => $field->category);
+    $form['weights'][$field->fid] = array('#type' => 'weight', '#default_value' => $field->weight);
+    $form['edit'][$field->fid] = array('#value' => l(t('Edit'), "admin/user/profile/edit/$field->fid"));
+    $form['delete'][$field->fid] = array('#value' => l(t('Delete'), "admin/user/profile/delete/$field->fid"));
+  }
+  
+  // Format the categories correctly for the category selection
+  $categories = array_unique($categories);
+  foreach($categories as $index => $category) {
+    $categoryoptions[$category] = $category;
+  }
+  foreach($form['categories'] as $index => $value) {
+    $form['categories'][$index]['#options'] = $categoryoptions;
+  }
+  
+  $form['submit'] = array('#type' => 'submit', '#value' => t('Save configuration'));
+  
+  $addnewfields = '<h2>'. t('Add new field') .'</h2>';
+  $addnewfields .= '<ul>';
+  foreach (_profile_field_types() as $key => $value) {
+    $addnewfields .= '<li>'. l($value, "admin/user/profile/add/$key") .'</li>';
   }
+  $addnewfields .= '</ul>';
+  $form['addnewfields'] = array('#value' => $addnewfields);
 
-  $header = array(t('Title'), t('Name'), t('Type'), t('Category'), array('data' => t('Operations'), 'colspan' => '2'));
+  return $form;
+}
 
-  $output  = theme('table', $header, $rows);
-  $output .= '<h2>'. t('Add new field') .'</h2>';
-  $output .= '<ul>';
-  foreach (_profile_field_types() as $key => $value) {
-    $output .= '<li>'. l($value, "admin/user/profile/add/$key") .'</li>';
+function profile_admin_overview_submit($form, &$form_state) {
+  foreach (element_children($form_state['values']['weights']) as $fid) {
+    $weight = $form_state['values']['weights'][$fid];
+    $category = $form_state['values']['categories'][$fid];
+    db_query("UPDATE {profile_fields} SET weight = %d, category = '%s' WHERE fid = %d", $weight, $category, $fid);
+  }
+  
+  drupal_set_message(t('The fields have all been updated.'));
+  cache_clear_all();
+  menu_rebuild();
+}
+
+function theme_profile_admin_overview($form) {
+  $header = array(t('Title'), t('Name'), t('Type'), t('Category'), t('Weight'), t('Edit'), t('Delete'));
+  $rows = array();
+  foreach (element_children($form['names']) as $id) {
+    // Don't take form control structures.
+    if (is_array($form['names'][$id])) {
+      $form['weights'][$id]['#attributes']['class'] = 'profile-admin-overview-weight';
+      $form['categories'][$id]['#attributes']['class'] = "profile-admin-overview-weight profile-admin-overview-weight-". $form['categories'][$id]['#default_value'];
+      $rows[] = array(
+        'data' => array(
+          drupal_render($form['titles'][$id]),
+          drupal_render($form['names'][$id]),
+          drupal_render($form['types'][$id]),
+          drupal_render($form['categories'][$id]),
+          drupal_render($form['weights'][$id]),
+          drupal_render($form['edit'][$id]),
+          drupal_render($form['delete'][$id]),
+        ),
+        'class' => 'draggable',
+      );
+    }
   }
-  $output .= '</ul>';
 
+  $output = theme('table', $header, $rows, array('id' => 'profile-admin-overview'));
+  $output .= drupal_render($form);
+
+  drupal_add_tabledrag('profile-admin-overview', 'order', 'sibling', 'profile-admin-overview-weight', NULL, NULL, FALSE);
+  
   return $output;
 }
 
Index: modules/profile/profile.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/profile/profile.module,v
retrieving revision 1.225
diff -u -r1.225 profile.module
--- modules/profile/profile.module	20 Nov 2007 11:39:48 -0000	1.225
+++ modules/profile/profile.module	21 Nov 2007 03:34:27 -0000
@@ -67,6 +67,10 @@
     'profile_wrapper' => array(
       'arguments' => array('content' => NULL),
       'template' => 'profile-wrapper',
+    ),
+    'profile_admin_overview' => array(
+      'arguments' => array('form' => NULL),
+      'file' => 'profile.admin.inc',
     )
   );
 }
@@ -85,7 +89,8 @@
   $items['admin/user/profile'] = array(
     'title' => 'Profiles',
     'description' => 'Create customizable fields for your users.',
-    'page callback' => 'profile_admin_overview',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('profile_admin_overview'),
     'file' => 'profile.admin.inc',
   );
   $items['admin/user/profile/add'] = array(
