Index: modules/profile/profile.admin.inc
===================================================================
RCS file: /cvs/drupal/drupal/modules/profile/profile.admin.inc,v
retrieving revision 1.2
diff -u -r1.2 profile.admin.inc
--- modules/profile/profile.admin.inc 26 Nov 2007 08:30:19 -0000 1.2
+++ modules/profile/profile.admin.inc 26 Nov 2007 21:16:23 -0000
@@ -9,27 +9,90 @@
/**
* 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 = 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"));
+ // Collect all category information
+ $categories[] = $field->category;
+
+ // Save all field information
+ $form[$field->fid]['name'] = array('#value' => check_plain($field->name));
+ $form[$field->fid]['title'] = array('#value' => check_plain($field->title));
+ $form[$field->fid]['type'] = array('#value' => $field->type);
+ $form[$field->fid]['category'] = array('#type' => 'select', '#default_value' => $field->category, '#options' => array());
+ $form[$field->fid]['weight'] = array('#type' => 'weight', '#default_value' => $field->weight);
+ $form[$field->fid]['operations'] = array('#value' => l(t('edit'), "admin/user/profile/edit/$field->fid") .' '. l(t('delete'), "admin/user/profile/delete/$field->fid"));
+ }
+
+ // Format the categories correctly for the category selection
+ $categories = array_unique($categories);
+ foreach($form as $fid => $field) {
+ foreach($categories as $cat => $category) {
+ $form[$fid]['category']['#options'][$category] = $category;
+ }
}
- if (count($rows) == 0) {
- $rows[] = array(array('data' => t('No fields defined.'), 'colspan' => '6'));
+
+ $form['#tree'] = TRUE;
+ $form['submit'] = array('#type' => 'submit', '#value' => t('Save configuration'));
+
+ $addnewfields = '
'. t('Add new field') .'
';
+ $addnewfields .= '';
+ foreach (_profile_field_types() as $key => $value) {
+ $addnewfields .= '- '. l($value, "admin/user/profile/add/$key") .'
';
}
+ $addnewfields .= '
';
+ $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 .= ''. t('Add new field') .'
';
- $output .= '';
- foreach (_profile_field_types() as $key => $value) {
- $output .= '- '. l($value, "admin/user/profile/add/$key") .'
';
+function profile_admin_overview_submit($form, &$form_state) {
+ foreach (element_children($form_state['values']) as $fid) {
+ if (is_numeric($fid)) {
+ $weight = $form_state['values'][$fid]['weight'];
+ $category = $form_state['values'][$fid]['category'];
+ 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) {
+
+ drupal_add_tabledrag('profile-admin-overview', 'order', 'sibling', 'profile-admin-overview-weight', NULL, NULL, FALSE);
+
+ $rows = array();
+ foreach (element_children($form) as $key) {
+ // Don't take form control structures.
+ if (array_key_exists('category', $form[$key])) {
+ $field = &$form[$key];
+
+ $field['weight']['#attributes']['class'] = 'profile-admin-overview-weight';
+ $field['category']['#attributes']['class'] = "profile-admin-overview-weight profile-admin-overview-weight-". $field['category']['#default_value'];
+
+ $row = array();
+ $row[] = drupal_render($field['title']);
+ $row[] = drupal_render($field['name']);
+ $row[] = drupal_render($field['type']);
+ $row[] = drupal_render($field['category']);
+ $row[] = drupal_render($field['weight']);
+ $row[] = drupal_render($field['operations']);
+ $rows[] = array('data' => $row, 'class' => 'draggable');
+ }
+ }
+ if (empty($rows)) {
+ $rows[] = array(array('data' => t('No fields available.'), 'colspan' => '6'));
}
- $output .= '
';
+ $header = array(t('Title'), t('Name'), t('Type'), t('Category'), t('Weight'), t('Operations'));
+ $output = theme('table', $header, $rows, array('id' => 'profile-admin-overview'));
+ $output .= drupal_render($form);
+
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 26 Nov 2007 18:42:23 -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(