Index: modules/profile/profile.admin.inc
===================================================================
RCS file: modules/profile/profile.admin.inc
diff -N modules/profile/profile.admin.inc
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ modules/profile/profile.admin.inc	13 Nov 2007 00:55:25 -0000
@@ -0,0 +1,281 @@
+<?php
+// $Id: $
+
+/**
+ * @file
+ * Administrative page callbacks for the profile module.
+ */
+
+/**
+ * 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();
+  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'));
+  }
+
+  $header = array(t('Title'), t('Name'), t('Type'), t('Category'), array('data' => t('Operations'), 'colspan' => '2'));
+
+  $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>';
+  }
+  $output .= '</ul>';
+
+  return $output;
+}
+
+/**
+ * Menu callback: Generate a form to add/edit a user profile field.
+ * 
+ * @ingroup forms
+ * @see profile_field_form_validate().
+ * @see profile_field_form_submit().
+ */
+function profile_field_form(&$form_state, $arg = NULL) {
+  if (arg(3) == 'edit') {
+    if (is_numeric($arg)) {
+      $fid = $arg;
+
+      $edit = db_fetch_array(db_query('SELECT * FROM {profile_fields} WHERE fid = %d', $fid));
+
+      if (!$edit) {
+        drupal_not_found();
+        return;
+      }
+      drupal_set_title(t('edit %title', array('%title' => $edit['title'])));
+      $form['fid'] = array('#type' => 'value',
+        '#value' => $fid,
+      );
+      $type = $edit['type'];
+    }
+    else {
+      drupal_not_found();
+      return;
+    }
+  }
+  else {
+    $types = _profile_field_types();
+    if (!isset($types[$arg])) {
+      drupal_not_found();
+      return;
+    }
+    $type = $arg;
+    drupal_set_title(t('add new %type', array('%type' => $types[$type])));
+    $edit = array('name' => 'profile_');
+    $form['type'] = array('#type' => 'value', '#value' => $type);
+  }
+  $edit += array(
+    'category' => '',
+    'title' => '',
+    'explanation' => '',
+    'weight' => 0,
+    'page' => '',
+    'autocomplete' => '',
+    'required' => '',
+    'register' => '',
+  );
+  $form['fields'] = array('#type' => 'fieldset',
+    '#title' => t('Field settings'),
+  );
+  $form['fields']['category'] = array('#type' => 'textfield',
+    '#title' => t('Category'),
+    '#default_value' => $edit['category'],
+    '#autocomplete_path' => 'admin/user/profile/autocomplete',
+    '#description' => t('The category the new field should be part of. Categories are used to group fields logically. An example category is "Personal information".'),
+    '#required' => TRUE,
+  );
+  $form['fields']['title'] = array('#type' => 'textfield',
+    '#title' => t('Title'),
+    '#default_value' => $edit['title'],
+    '#description' => t('The title of the new field. The title will be shown to the user. An example title is "Favorite color".'),
+    '#required' => TRUE,
+  );
+  $form['fields']['name'] = array('#type' => 'textfield',
+    '#title' => t('Form name'),
+    '#default_value' => $edit['name'],
+    '#description' => t('The name of the field. The form name is not shown to the user but used internally in the HTML code and URLs.
+Unless you know what you are doing, it is highly recommended that you prefix the form name with <code>profile_</code> to avoid name clashes with other fields. Spaces or any other special characters except dash (-) and underscore (_) are not allowed. An example name is "profile_favorite_color" or perhaps just "profile_color".'),
+    '#required' => TRUE,
+  );
+  $form['fields']['explanation'] = array('#type' => 'textarea',
+    '#title' => t('Explanation'),
+    '#default_value' => $edit['explanation'],
+    '#description' => t('An optional explanation to go with the new field. The explanation will be shown to the user.'),
+  );
+  if ($type == 'selection') {
+    $form['fields']['options'] = array('#type' => 'textarea',
+      '#title' => t('Selection options'),
+      '#default_value' => isset($edit['options']) ? $edit['options'] : '',
+      '#description' => t('A list of all options. Put each option on a separate line. Example options are "red", "blue", "green", etc.'),
+    );
+  }
+  $form['fields']['weight'] = array('#type' => 'weight',
+    '#title' => t('Weight'),
+    '#default_value' => $edit['weight'],
+    '#delta' => 5,
+    '#description' => t('The weights define the order in which the form fields are shown. Lighter fields "float up" towards the top of the category.'),
+  );
+  $form['fields']['visibility'] = array('#type' => 'radios',
+    '#title' => t('Visibility'),
+    '#default_value' => isset($edit['visibility']) ? $edit['visibility'] : PROFILE_PUBLIC,
+    '#options' => array(PROFILE_HIDDEN => t('Hidden profile field, only accessible by administrators, modules and themes.'), PROFILE_PRIVATE => t('Private field, content only available to privileged users.'), PROFILE_PUBLIC => t('Public field, content shown on profile page but not used on member list pages.'), PROFILE_PUBLIC_LISTINGS => t('Public field, content shown on profile page and on member list pages.')),
+  );
+  if ($type == 'selection' || $type == 'list' || $type == 'textfield') {
+    $form['fields']['page'] = array('#type' => 'textfield',
+      '#title' => t('Page title'),
+      '#default_value' => $edit['page'],
+      '#description' => t('To enable browsing this field by value, enter a title for the resulting page. The word <code>%value</code> will be substituted with the corresponding value. An example page title is "People whose favorite color is %value". This is only applicable for a public field.'),
+    );
+  }
+  else if ($type == 'checkbox') {
+    $form['fields']['page'] = array('#type' => 'textfield',
+      '#title' => t('Page title'),
+      '#default_value' => $edit['page'],
+      '#description' => t('To enable browsing this field by value, enter a title for the resulting page. An example page title is "People who are employed". This is only applicable for a public field.'),
+    );
+  }
+  $form['fields']['autocomplete'] = array('#type' => 'checkbox',
+    '#title' => t('Form will auto-complete while user is typing.'),
+    '#default_value' => $edit['autocomplete'],
+  );
+  $form['fields']['required'] = array('#type' => 'checkbox',
+    '#title' => t('The user must enter a value.'),
+    '#default_value' => $edit['required'],
+  );
+  $form['fields']['register'] = array('#type' => 'checkbox',
+    '#title' => t('Visible in user registration form.'),
+    '#default_value' => $edit['register'],
+  );
+  $form['submit'] = array('#type' => 'submit',
+    '#value' => t('Save field'),
+  );
+  return $form;
+}
+
+/**
+ * Validate profile_field_form submissions.
+ */
+function profile_field_form_validate($form, &$form_state) {
+  // Validate the 'field name':
+  if (preg_match('/[^a-zA-Z0-9_-]/', $form_state['values']['name'])) {
+    form_set_error('name', t('The specified form name contains one or more illegal characters. Spaces or any other special characters except dash (-) and underscore (_) are not allowed.'));
+  }
+
+  if (in_array($form_state['values']['name'], user_fields())) {
+    form_set_error('name', t('The specified form name is reserved for use by Drupal.'));
+  }
+  // Validate the category:
+  if (!$form_state['values']['category']) {
+    form_set_error('category', t('You must enter a category.'));
+  }
+  if ($form_state['values']['category'] == 'account') {
+    form_set_error('category', t('The specified category name is reserved for use by Drupal.'));
+  }
+  $args1 = array($form_state['values']['title'], $form_state['values']['category']);
+  $args2 = array($form_state['values']['name']);
+  $query_suffix = '';
+
+  if (isset($form_state['values']['fid'])) {
+    $args1[] = $args2[] = $form_state['values']['fid'];
+    $query_suffix = ' AND fid != %d';
+  }
+
+  if (db_result(db_query("SELECT fid FROM {profile_fields} WHERE title = '%s' AND category = '%s'". $query_suffix, $args1))) {
+    form_set_error('title', t('The specified title is already in use.'));
+  }
+  if (db_result(db_query("SELECT fid FROM {profile_fields} WHERE name = '%s'". $query_suffix, $args2))) {
+    form_set_error('name', t('The specified name is already in use.'));
+  }
+  if ($form_state['values']['visibility'] == PROFILE_HIDDEN) {
+    if ($form_state['values']['required']) {
+      form_set_error('required', t('A hidden field cannot be required.'));
+    }
+    if ($form_state['values']['register']) {
+      form_set_error('register', t('A hidden field cannot be set to visible on the user registration form.'));
+    }
+  }
+}
+
+/**
+ * Process profile_field_form submissions.
+ */
+function profile_field_form_submit($form, &$form_state) {
+  if (!isset($form_state['values']['options'])) {
+    $form_state['values']['options'] = '';
+  }
+  if (!isset($form_state['values']['page'])) {
+    $form_state['values']['page'] = '';
+  }
+  if (!isset($form_state['values']['fid'])) {
+    db_query("INSERT INTO {profile_fields} (title, name, explanation, category, type, weight, required, register, visibility, autocomplete, options, page) VALUES ('%s', '%s', '%s', '%s', '%s', %d, %d, %d, %d, %d, '%s', '%s')", $form_state['values']['title'], $form_state['values']['name'], $form_state['values']['explanation'], $form_state['values']['category'], $form_state['values']['type'], $form_state['values']['weight'], $form_state['values']['required'], $form_state['values']['register'], $form_state['values']['visibility'], $form_state['values']['autocomplete'], $form_state['values']['options'], $form_state['values']['page']);
+
+    drupal_set_message(t('The field has been created.'));
+    watchdog('profile', 'Profile field %field added under category %category.', array('%field' => $form_state['values']['title'], '%category' => $form_state['values']['category']), WATCHDOG_NOTICE, l(t('view'), 'admin/user/profile'));
+  }
+  else {
+    db_query("UPDATE {profile_fields} SET title = '%s', name = '%s', explanation = '%s', category = '%s', weight = %d, required = %d, register = %d, visibility = %d, autocomplete = %d, options = '%s', page = '%s' WHERE fid = %d", $form_state['values']['title'], $form_state['values']['name'], $form_state['values']['explanation'], $form_state['values']['category'], $form_state['values']['weight'], $form_state['values']['required'], $form_state['values']['register'], $form_state['values']['visibility'], $form_state['values']['autocomplete'], $form_state['values']['options'], $form_state['values']['page'], $form_state['values']['fid']);
+
+    drupal_set_message(t('The field has been updated.'));
+  }
+  cache_clear_all();
+  menu_rebuild();
+
+  $form_state['redirect'] = 'admin/user/profile';
+  return;
+}
+
+/**
+ * Menu callback; deletes a field from all user profiles.
+ */
+function profile_field_delete(&$form_state, $fid) {
+  $field = db_fetch_object(db_query("SELECT title FROM {profile_fields} WHERE fid = %d", $fid));
+  if (!$field) {
+    drupal_not_found();
+    return;
+  }
+  $form['fid'] = array('#type' => 'value', '#value' => $fid);
+  $form['title'] = array('#type' => 'value', '#value' => $field->title);
+
+  return confirm_form($form,
+    t('Are you sure you want to delete the field %field?', array('%field' => $field->title)), 'admin/user/profile',
+    t('This action cannot be undone. If users have entered values into this field in their profile, these entries will also be deleted. If you want to keep the user-entered data, instead of deleting the field you may wish to <a href="@edit-field">edit this field</a> and change it to a hidden profile field so that it may only be accessed by administrators.', array('@edit-field' => url('admin/user/profile/edit/'. $fid))),
+    t('Delete'), t('Cancel'));
+}
+
+/**
+ * Process a field delete form submission.
+ */
+function profile_field_delete_submit($form, &$form_state) {
+  db_query('DELETE FROM {profile_fields} WHERE fid = %d', $form_state['values']['fid']);
+  db_query('DELETE FROM {profile_values} WHERE fid = %d', $form_state['values']['fid']);
+
+  cache_clear_all();
+
+  drupal_set_message(t('The field %field has been deleted.', array('%field' => $form_state['values']['title'])));
+  watchdog('profile', 'Profile field %field deleted.', array('%field' => $form_state['values']['title']), WATCHDOG_NOTICE, l(t('view'), 'admin/user/profile'));
+
+  $form_state['redirect'] = 'admin/user/profile';
+  return;
+}
+
+/**
+ * Retrieve a pipe delimited string of autocomplete suggestions for profile categories
+ */
+function profile_admin_settings_autocomplete($string) {
+  $matches = array();
+  $result = db_query_range("SELECT category FROM {profile_fields} WHERE LOWER(category) LIKE LOWER('%s%%')", $string, 0, 10);
+  while ($data = db_fetch_object($result)) {
+    $matches[$data->category] = check_plain($data->category);
+  }
+  print drupal_to_js($matches);
+  exit();
+}
Index: modules/profile/profile.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/profile/profile.module,v
retrieving revision 1.222
diff -u -p -r1.222 profile.module
--- modules/profile/profile.module	24 Oct 2007 13:27:12 -0000	1.222
+++ modules/profile/profile.module	13 Nov 2007 00:55:26 -0000
@@ -80,40 +80,47 @@ function profile_menu() {
     'page callback' => 'profile_browse',
     'access arguments' => array('access user profiles'),
     'type' => MENU_SUGGESTED_ITEM,
+    'file' => 'profile.pages.inc',
   );
   $items['admin/user/profile'] = array(
     'title' => 'Profiles',
     'description' => 'Create customizable fields for your users.',
     'page callback' => 'profile_admin_overview',
+    'file' => 'profile.admin.inc',
   );
   $items['admin/user/profile/add'] = array(
     'title' => 'Add field',
     'page callback' => 'drupal_get_form',
     'page arguments' => array('profile_field_form'),
     'type' => MENU_CALLBACK,
+    'file' => 'profile.admin.inc',
   );
   $items['admin/user/profile/autocomplete'] = array(
     'title' => 'Profile category autocomplete',
     'page callback' => 'profile_admin_settings_autocomplete',
     'type' => MENU_CALLBACK,
+    'file' => 'profile.admin.inc',
   );
   $items['admin/user/profile/edit'] = array(
     'title' => 'Edit field',
     'page callback' => 'drupal_get_form',
     'page arguments' => array('profile_field_form'),
     'type' => MENU_CALLBACK,
+    'file' => 'profile.admin.inc',
   );
   $items['admin/user/profile/delete'] = array(
     'title' => 'Delete field',
     'page callback' => 'drupal_get_form',
     'page arguments' => array('profile_field_delete'),
     'type' => MENU_CALLBACK,
+    'file' => 'profile.admin.inc',
   );
   $items['profile/autocomplete'] = array(
     'title' => 'Profile autocomplete',
     'page callback' => 'profile_autocomplete',
     'access arguments' => array('access user profiles'),
     'type' => MENU_CALLBACK,
+    'file' => 'profile.pages.inc',
   );
   return $items;
 }
@@ -211,361 +218,6 @@ function profile_user($type, &$edit, &$u
   }
 }
 
-/**
- * Menu callback: Generate a form to add/edit a user profile field.
- */
-function profile_field_form(&$form_state, $arg = NULL) {
-  if (arg(3) == 'edit') {
-    if (is_numeric($arg)) {
-      $fid = $arg;
-
-      $edit = db_fetch_array(db_query('SELECT * FROM {profile_fields} WHERE fid = %d', $fid));
-
-      if (!$edit) {
-        drupal_not_found();
-        return;
-      }
-      drupal_set_title(t('edit %title', array('%title' => $edit['title'])));
-      $form['fid'] = array('#type' => 'value',
-        '#value' => $fid,
-      );
-      $type = $edit['type'];
-    }
-    else {
-      drupal_not_found();
-      return;
-    }
-  }
-  else {
-    $types = _profile_field_types();
-    if (!isset($types[$arg])) {
-      drupal_not_found();
-      return;
-    }
-    $type = $arg;
-    drupal_set_title(t('add new %type', array('%type' => $types[$type])));
-    $edit = array('name' => 'profile_');
-    $form['type'] = array('#type' => 'value', '#value' => $type);
-  }
-  $edit += array(
-    'category' => '',
-    'title' => '',
-    'explanation' => '',
-    'weight' => 0,
-    'page' => '',
-    'autocomplete' => '',
-    'required' => '',
-    'register' => '',
-  );
-  $form['fields'] = array('#type' => 'fieldset',
-    '#title' => t('Field settings'),
-  );
-  $form['fields']['category'] = array('#type' => 'textfield',
-    '#title' => t('Category'),
-    '#default_value' => $edit['category'],
-    '#autocomplete_path' => 'admin/user/profile/autocomplete',
-    '#description' => t('The category the new field should be part of. Categories are used to group fields logically. An example category is "Personal information".'),
-    '#required' => TRUE,
-  );
-  $form['fields']['title'] = array('#type' => 'textfield',
-    '#title' => t('Title'),
-    '#default_value' => $edit['title'],
-    '#description' => t('The title of the new field. The title will be shown to the user. An example title is "Favorite color".'),
-    '#required' => TRUE,
-  );
-  $form['fields']['name'] = array('#type' => 'textfield',
-    '#title' => t('Form name'),
-    '#default_value' => $edit['name'],
-    '#description' => t('The name of the field. The form name is not shown to the user but used internally in the HTML code and URLs.
-Unless you know what you are doing, it is highly recommended that you prefix the form name with <code>profile_</code> to avoid name clashes with other fields. Spaces or any other special characters except dash (-) and underscore (_) are not allowed. An example name is "profile_favorite_color" or perhaps just "profile_color".'),
-    '#required' => TRUE,
-  );
-  $form['fields']['explanation'] = array('#type' => 'textarea',
-    '#title' => t('Explanation'),
-    '#default_value' => $edit['explanation'],
-    '#description' => t('An optional explanation to go with the new field. The explanation will be shown to the user.'),
-  );
-  if ($type == 'selection') {
-    $form['fields']['options'] = array('#type' => 'textarea',
-      '#title' => t('Selection options'),
-      '#default_value' => isset($edit['options']) ? $edit['options'] : '',
-      '#description' => t('A list of all options. Put each option on a separate line. Example options are "red", "blue", "green", etc.'),
-    );
-  }
-  $form['fields']['weight'] = array('#type' => 'weight',
-    '#title' => t('Weight'),
-    '#default_value' => $edit['weight'],
-    '#delta' => 5,
-    '#description' => t('The weights define the order in which the form fields are shown. Lighter fields "float up" towards the top of the category.'),
-  );
-  $form['fields']['visibility'] = array('#type' => 'radios',
-    '#title' => t('Visibility'),
-    '#default_value' => isset($edit['visibility']) ? $edit['visibility'] : PROFILE_PUBLIC,
-    '#options' => array(PROFILE_HIDDEN => t('Hidden profile field, only accessible by administrators, modules and themes.'), PROFILE_PRIVATE => t('Private field, content only available to privileged users.'), PROFILE_PUBLIC => t('Public field, content shown on profile page but not used on member list pages.'), PROFILE_PUBLIC_LISTINGS => t('Public field, content shown on profile page and on member list pages.')),
-  );
-  if ($type == 'selection' || $type == 'list' || $type == 'textfield') {
-    $form['fields']['page'] = array('#type' => 'textfield',
-      '#title' => t('Page title'),
-      '#default_value' => $edit['page'],
-      '#description' => t('To enable browsing this field by value, enter a title for the resulting page. The word <code>%value</code> will be substituted with the corresponding value. An example page title is "People whose favorite color is %value". This is only applicable for a public field.'),
-    );
-  }
-  else if ($type == 'checkbox') {
-    $form['fields']['page'] = array('#type' => 'textfield',
-      '#title' => t('Page title'),
-      '#default_value' => $edit['page'],
-      '#description' => t('To enable browsing this field by value, enter a title for the resulting page. An example page title is "People who are employed". This is only applicable for a public field.'),
-    );
-  }
-  $form['fields']['autocomplete'] = array('#type' => 'checkbox',
-    '#title' => t('Form will auto-complete while user is typing.'),
-    '#default_value' => $edit['autocomplete'],
-  );
-  $form['fields']['required'] = array('#type' => 'checkbox',
-    '#title' => t('The user must enter a value.'),
-    '#default_value' => $edit['required'],
-  );
-  $form['fields']['register'] = array('#type' => 'checkbox',
-    '#title' => t('Visible in user registration form.'),
-    '#default_value' => $edit['register'],
-  );
-  $form['submit'] = array('#type' => 'submit',
-    '#value' => t('Save field'),
-  );
-  return $form;
-}
-
-/**
- * Validate profile_field_form submissions.
- */
-function profile_field_form_validate($form, &$form_state) {
-  // Validate the 'field name':
-  if (preg_match('/[^a-zA-Z0-9_-]/', $form_state['values']['name'])) {
-    form_set_error('name', t('The specified form name contains one or more illegal characters. Spaces or any other special characters except dash (-) and underscore (_) are not allowed.'));
-  }
-
-  if (in_array($form_state['values']['name'], user_fields())) {
-    form_set_error('name', t('The specified form name is reserved for use by Drupal.'));
-  }
-  // Validate the category:
-  if (!$form_state['values']['category']) {
-    form_set_error('category', t('You must enter a category.'));
-  }
-  if ($form_state['values']['category'] == 'account') {
-    form_set_error('category', t('The specified category name is reserved for use by Drupal.'));
-  }
-  $args1 = array($form_state['values']['title'], $form_state['values']['category']);
-  $args2 = array($form_state['values']['name']);
-  $query_suffix = '';
-
-  if (isset($form_state['values']['fid'])) {
-    $args1[] = $args2[] = $form_state['values']['fid'];
-    $query_suffix = ' AND fid != %d';
-  }
-
-  if (db_result(db_query("SELECT fid FROM {profile_fields} WHERE title = '%s' AND category = '%s'". $query_suffix, $args1))) {
-    form_set_error('title', t('The specified title is already in use.'));
-  }
-  if (db_result(db_query("SELECT fid FROM {profile_fields} WHERE name = '%s'". $query_suffix, $args2))) {
-    form_set_error('name', t('The specified name is already in use.'));
-  }
-  if ($form_state['values']['visibility'] == PROFILE_HIDDEN) {
-    if ($form_state['values']['required']) {
-      form_set_error('required', t('A hidden field cannot be required.'));
-    }
-    if ($form_state['values']['register']) {
-      form_set_error('register', t('A hidden field cannot be set to visible on the user registration form.'));
-    }
-  }
-}
-
-/**
- * Process profile_field_form submissions.
- */
-function profile_field_form_submit($form, &$form_state) {
-  if (!isset($form_state['values']['options'])) {
-    $form_state['values']['options'] = '';
-  }
-  if (!isset($form_state['values']['page'])) {
-    $form_state['values']['page'] = '';
-  }
-  if (!isset($form_state['values']['fid'])) {
-    db_query("INSERT INTO {profile_fields} (title, name, explanation, category, type, weight, required, register, visibility, autocomplete, options, page) VALUES ('%s', '%s', '%s', '%s', '%s', %d, %d, %d, %d, %d, '%s', '%s')", $form_state['values']['title'], $form_state['values']['name'], $form_state['values']['explanation'], $form_state['values']['category'], $form_state['values']['type'], $form_state['values']['weight'], $form_state['values']['required'], $form_state['values']['register'], $form_state['values']['visibility'], $form_state['values']['autocomplete'], $form_state['values']['options'], $form_state['values']['page']);
-
-    drupal_set_message(t('The field has been created.'));
-    watchdog('profile', 'Profile field %field added under category %category.', array('%field' => $form_state['values']['title'], '%category' => $form_state['values']['category']), WATCHDOG_NOTICE, l(t('view'), 'admin/user/profile'));
-  }
-  else {
-    db_query("UPDATE {profile_fields} SET title = '%s', name = '%s', explanation = '%s', category = '%s', weight = %d, required = %d, register = %d, visibility = %d, autocomplete = %d, options = '%s', page = '%s' WHERE fid = %d", $form_state['values']['title'], $form_state['values']['name'], $form_state['values']['explanation'], $form_state['values']['category'], $form_state['values']['weight'], $form_state['values']['required'], $form_state['values']['register'], $form_state['values']['visibility'], $form_state['values']['autocomplete'], $form_state['values']['options'], $form_state['values']['page'], $form_state['values']['fid']);
-
-    drupal_set_message(t('The field has been updated.'));
-  }
-  cache_clear_all();
-  menu_rebuild();
-
-  $form_state['redirect'] = 'admin/user/profile';
-  return;
-}
-
-/**
- * Menu callback; deletes a field from all user profiles.
- */
-function profile_field_delete(&$form_state, $fid) {
-  $field = db_fetch_object(db_query("SELECT title FROM {profile_fields} WHERE fid = %d", $fid));
-  if (!$field) {
-    drupal_not_found();
-    return;
-  }
-  $form['fid'] = array('#type' => 'value', '#value' => $fid);
-  $form['title'] = array('#type' => 'value', '#value' => $field->title);
-
-  return confirm_form($form,
-    t('Are you sure you want to delete the field %field?', array('%field' => $field->title)), 'admin/user/profile',
-    t('This action cannot be undone. If users have entered values into this field in their profile, these entries will also be deleted. If you want to keep the user-entered data, instead of deleting the field you may wish to <a href="@edit-field">edit this field</a> and change it to a hidden profile field so that it may only be accessed by administrators.', array('@edit-field' => url('admin/user/profile/edit/'. $fid))),
-    t('Delete'), t('Cancel'));
-}
-
-/**
- * Process a field delete form submission.
- */
-function profile_field_delete_submit($form, &$form_state) {
-  db_query('DELETE FROM {profile_fields} WHERE fid = %d', $form_state['values']['fid']);
-  db_query('DELETE FROM {profile_values} WHERE fid = %d', $form_state['values']['fid']);
-
-  cache_clear_all();
-
-  drupal_set_message(t('The field %field has been deleted.', array('%field' => $form_state['values']['title'])));
-  watchdog('profile', 'Profile field %field deleted.', array('%field' => $form_state['values']['title']), WATCHDOG_NOTICE, l(t('view'), 'admin/user/profile'));
-
-  $form_state['redirect'] = 'admin/user/profile';
-  return;
-}
-
-/**
- * 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();
-  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'));
-  }
-
-  $header = array(t('Title'), t('Name'), t('Type'), t('Category'), array('data' => t('Operations'), 'colspan' => '2'));
-
-  $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>';
-  }
-  $output .= '</ul>';
-
-  return $output;
-}
-
-/**
- * Menu callback; display a list of user information.
- */
-function profile_browse() {
-  // Ensure that the path is converted to 3 levels always.
-  list(, $name, $value) = array_pad(explode('/', $_GET['q'], 3), 3, '');
-
-  $field = db_fetch_object(db_query("SELECT DISTINCT(fid), type, title, page, visibility FROM {profile_fields} WHERE name = '%s'", $name));
-
-  if ($name && $field->fid) {
-    // Only allow browsing of fields that have a page title set.
-    if (empty($field->page)) {
-      drupal_not_found();
-      return;
-    }
-    // Do not allow browsing of private and hidden fields by non-admins.
-    if (!user_access('administer users') && ($field->visibility == PROFILE_PRIVATE || $field->visibility == PROFILE_HIDDEN)) {
-       drupal_access_denied();
-       return;
-    }
-
-    // Compile a list of fields to show.
-    $fields = array();
-    $result = db_query('SELECT name, title, type, weight, page FROM {profile_fields} WHERE fid != %d AND visibility = %d ORDER BY weight', $field->fid, PROFILE_PUBLIC_LISTINGS);
-    while ($record = db_fetch_object($result)) {
-      $fields[] = $record;
-    }
-
-    // Determine what query to use:
-    $arguments = array($field->fid);
-    switch ($field->type) {
-      case 'checkbox':
-        $query = 'v.value = 1';
-        break;
-      case 'textfield':
-      case 'selection':
-        $query = "v.value = '%s'";
-        $arguments[] = $value;
-        break;
-      case 'list':
-        $query = "v.value LIKE '%%%s%%'";
-        $arguments[] = $value;
-        break;
-      default:
-        drupal_not_found();
-        return;
-    }
-
-    // Extract the affected users:
-    $result = pager_query("SELECT u.uid, u.access FROM {users} u INNER JOIN {profile_values} v ON u.uid = v.uid WHERE v.fid = %d AND $query AND u.access != 0 AND u.status != 0 ORDER BY u.access DESC", 20, 0, NULL, $arguments);
-
-    $content = '';
-    while ($account = db_fetch_object($result)) {
-      $account = user_load(array('uid' => $account->uid));
-      $profile = _profile_update_user_fields($fields, $account);
-      $content .= theme('profile_listing', $account, $profile);
-    }
-    $output = theme('profile_wrapper', $content);
-    $output .= theme('pager', NULL, 20);
-
-    if ($field->type == 'selection' || $field->type == 'list' || $field->type == 'textfield') {
-      $title = strtr(check_plain($field->page), array('%value' => theme('placeholder', $value)));
-    }
-    else {
-      $title = check_plain($field->page);
-    }
-
-    drupal_set_title($title);
-    return $output;
-  }
-  else if ($name && !$field->fid) {
-    drupal_not_found();
-  }
-  else {
-    // Compile a list of fields to show.
-    $fields = array();
-    $result = db_query('SELECT name, title, type, weight, page FROM {profile_fields} WHERE visibility = %d ORDER BY category, weight', PROFILE_PUBLIC_LISTINGS);
-    while ($record = db_fetch_object($result)) {
-      $fields[] = $record;
-    }
-
-    // Extract the affected users:
-    $result = pager_query('SELECT uid, access FROM {users} WHERE uid > 0 AND status != 0 AND access != 0 ORDER BY access DESC', 20, 0, NULL);
-
-    $content = '';
-    while ($account = db_fetch_object($result)) {
-      $account = user_load(array('uid' => $account->uid));
-      $profile = _profile_update_user_fields($fields, $account);
-      $content .= theme('profile_listing', $account, $profile);
-    }
-    $output = theme('profile_wrapper', $content);
-    $output .= theme('pager', NULL, 20);
-
-    drupal_set_title(t('User list'));
-    return $output;
-  }
-}
-
 function profile_load_profile(&$user) {
   $result = db_query('SELECT f.name, f.type, v.value FROM {profile_fields} f INNER JOIN {profile_values} v ON f.fid = v.fid WHERE uid = %d', $user->uid);
   while ($field = db_fetch_object($result)) {
@@ -760,21 +412,6 @@ function profile_form_profile($edit, $us
 }
 
 /**
- * Callback to allow autocomplete of profile text fields.
- */
-function profile_autocomplete($field, $string) {
-  $matches = array();
-  if (db_result(db_query("SELECT COUNT(*) FROM {profile_fields} WHERE fid = %d AND autocomplete = 1", $field))) {
-    $result = db_query_range("SELECT value FROM {profile_values} WHERE fid = %d AND LOWER(value) LIKE LOWER('%s%%') GROUP BY value ORDER BY value ASC", $field, $string, 0, 10);
-    while ($data = db_fetch_object($result)) {
-      $matches[$data->value] = check_plain($data->value);
-    }
-  }
-
-  drupal_json($matches);
-}
-
-/**
  * Helper function: update an array of user fields by calling profile_view_field
  */
 function _profile_update_user_fields($fields, $account) {
@@ -913,15 +550,3 @@ function _profile_get_fields($category, 
   return db_query($sql, $args);
 }
 
-/**
- * Retrieve a pipe delimited string of autocomplete suggestions for profile categories
- */
-function profile_admin_settings_autocomplete($string) {
-  $matches = array();
-  $result = db_query_range("SELECT category FROM {profile_fields} WHERE LOWER(category) LIKE LOWER('%s%%')", $string, 0, 10);
-  while ($data = db_fetch_object($result)) {
-    $matches[$data->category] = check_plain($data->category);
-  }
-  print drupal_to_js($matches);
-  exit();
-}
Index: modules/profile/profile.pages.inc
===================================================================
RCS file: modules/profile/profile.pages.inc
diff -N modules/profile/profile.pages.inc
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ modules/profile/profile.pages.inc	13 Nov 2007 00:55:26 -0000
@@ -0,0 +1,120 @@
+<?php
+// $Id: $
+
+/**
+ * @file
+ * User page callbacks for the profile module.
+ */
+
+/**
+ * Menu callback; display a list of user information.
+ */
+function profile_browse() {
+  // Ensure that the path is converted to 3 levels always.
+  list(, $name, $value) = array_pad(explode('/', $_GET['q'], 3), 3, '');
+
+  $field = db_fetch_object(db_query("SELECT DISTINCT(fid), type, title, page, visibility FROM {profile_fields} WHERE name = '%s'", $name));
+
+  if ($name && $field->fid) {
+    // Only allow browsing of fields that have a page title set.
+    if (empty($field->page)) {
+      drupal_not_found();
+      return;
+    }
+    // Do not allow browsing of private and hidden fields by non-admins.
+    if (!user_access('administer users') && ($field->visibility == PROFILE_PRIVATE || $field->visibility == PROFILE_HIDDEN)) {
+       drupal_access_denied();
+       return;
+    }
+
+    // Compile a list of fields to show.
+    $fields = array();
+    $result = db_query('SELECT name, title, type, weight, page FROM {profile_fields} WHERE fid != %d AND visibility = %d ORDER BY weight', $field->fid, PROFILE_PUBLIC_LISTINGS);
+    while ($record = db_fetch_object($result)) {
+      $fields[] = $record;
+    }
+
+    // Determine what query to use:
+    $arguments = array($field->fid);
+    switch ($field->type) {
+      case 'checkbox':
+        $query = 'v.value = 1';
+        break;
+      case 'textfield':
+      case 'selection':
+        $query = "v.value = '%s'";
+        $arguments[] = $value;
+        break;
+      case 'list':
+        $query = "v.value LIKE '%%%s%%'";
+        $arguments[] = $value;
+        break;
+      default:
+        drupal_not_found();
+        return;
+    }
+
+    // Extract the affected users:
+    $result = pager_query("SELECT u.uid, u.access FROM {users} u INNER JOIN {profile_values} v ON u.uid = v.uid WHERE v.fid = %d AND $query AND u.access != 0 AND u.status != 0 ORDER BY u.access DESC", 20, 0, NULL, $arguments);
+
+    $content = '';
+    while ($account = db_fetch_object($result)) {
+      $account = user_load(array('uid' => $account->uid));
+      $profile = _profile_update_user_fields($fields, $account);
+      $content .= theme('profile_listing', $account, $profile);
+    }
+    $output = theme('profile_wrapper', $content);
+    $output .= theme('pager', NULL, 20);
+
+    if ($field->type == 'selection' || $field->type == 'list' || $field->type == 'textfield') {
+      $title = strtr(check_plain($field->page), array('%value' => theme('placeholder', $value)));
+    }
+    else {
+      $title = check_plain($field->page);
+    }
+
+    drupal_set_title($title);
+    return $output;
+  }
+  else if ($name && !$field->fid) {
+    drupal_not_found();
+  }
+  else {
+    // Compile a list of fields to show.
+    $fields = array();
+    $result = db_query('SELECT name, title, type, weight, page FROM {profile_fields} WHERE visibility = %d ORDER BY category, weight', PROFILE_PUBLIC_LISTINGS);
+    while ($record = db_fetch_object($result)) {
+      $fields[] = $record;
+    }
+
+    // Extract the affected users:
+    $result = pager_query('SELECT uid, access FROM {users} WHERE uid > 0 AND status != 0 AND access != 0 ORDER BY access DESC', 20, 0, NULL);
+
+    $content = '';
+    while ($account = db_fetch_object($result)) {
+      $account = user_load(array('uid' => $account->uid));
+      $profile = _profile_update_user_fields($fields, $account);
+      $content .= theme('profile_listing', $account, $profile);
+    }
+    $output = theme('profile_wrapper', $content);
+    $output .= theme('pager', NULL, 20);
+
+    drupal_set_title(t('User list'));
+    return $output;
+  }
+}
+
+/**
+ * Callback to allow autocomplete of profile text fields.
+ */
+function profile_autocomplete($field, $string) {
+  $matches = array();
+  if (db_result(db_query("SELECT COUNT(*) FROM {profile_fields} WHERE fid = %d AND autocomplete = 1", $field))) {
+    $result = db_query_range("SELECT value FROM {profile_values} WHERE fid = %d AND LOWER(value) LIKE LOWER('%s%%') GROUP BY value ORDER BY value ASC", $field, $string, 0, 10);
+    while ($data = db_fetch_object($result)) {
+      $matches[$data->value] = check_plain($data->value);
+    }
+  }
+
+  drupal_json($matches);
+}
