Index: profile_setup.module
===================================================================
--- profile_setup.module	(revision 150)
+++ profile_setup.module	(working copy)
@@ -16,6 +16,7 @@
       'profile_picture' => 'profile_setup.page_profile_picture',  // multiple page types can be in the same include file
       'username_change' => 'profile_setup.page_username_change',
       'account_category' => 'profile_setup.page_account_category',
+      'registration_account_category' => 'profile_setup.page_registration_account_category',
     )
   );
 }
Index: profile_setup.page_registration_account_category.inc
===================================================================
--- profile_setup.page_registration_account_category.inc	(revision 0)
+++ profile_setup.page_registration_account_category.inc	(revision 0)
@@ -0,0 +1,206 @@
+<?php
+// $Id: profile_setup.page_account_category.inc,v 1.1.2.1.4.5 2009/10/12 21:08:42 thomjjames Exp $
+
+/**
+ * @file
+ * Page user registration type
+ */
+
+include_once(drupal_get_path('module', 'pageroute') .'/pageroute.route.inc');
+
+class profilesetupPageregistration_account_category extends PageroutePage {
+
+  public function getForm(&$form, &$form_state, &$args) {
+    $form = array();
+    if ($args && isset($args['uid'])) {
+      $account = user_load(array('uid' => $args['uid']));
+    }
+    else {
+      $account = user_load(array('uid' => pageroute_page_get_uid($this, 'administer users')));
+    }
+    $current_page_name = $form_state['storage']['route']->pageDataCurrent->name;
+    $page_index = $form_state['storage']['route']->pageIndex;
+    $num_pages = count($page_index);
+    $current_index = $page_index[$current_page_name];
+    if ($current_index == 0) {
+      $form_state['storage']['processed_categories'] = array();
+    }
+    $form_state['storage']['pageroute_last_page'] = FALSE;
+    if ($current_index == ($num_pages-1)) {
+      $form_state['storage']['pageroute_last_page'] = TRUE;
+    }
+
+  
+    // Anonymous users.
+    if (user_register_access()) {
+      $args['hide_pageroute_buttons'] = FALSE;
+      $args['default_target'] = PAGEROUTE_FORWARD;
+
+      $this->options += array(
+        'category' => 'account'
+      );
+      $form_state['storage']['processed_categories'][] = $this->options['category'];
+           
+      $form['description'] = array(
+        '#value' => $this->options['description'],
+        '#weight' => -100
+      );
+      $form['account_category'] = array(
+        '#value' => $this->options['category']
+      );
+    
+      //option to use content profile user categories too
+      // @TODO
+      if (profile_setup_page_is_content_profile_type($this->options['category'])) {
+/* @TODO
+        $type = $this->options['category'];
+        $node = content_profile_load($type, $account->uid);
+        if (!$node) {
+          $node = array('uid' => $account->uid, 'name' => (isset($account->name) ? $account->name : ''), 'type' => $type, 'language' => '');
+        }
+        $form += drupal_retrieve_form($type .'_node_form', $form_state, $node);
+        drupal_prepare_form($type .'_node_form', $form, $form_state);
+*/
+      }
+      // Core profile module.
+      else {
+        $form += drupal_retrieve_form('user_register', $form_state);
+        foreach (element_children($form) as $child) {
+          if ($child != $this->options['category']) {
+            // If not last page, just show category requested.
+            if (!$form_state['storage']['pageroute_last_page']) {
+              unset($form[$child]);
+            }
+            // If last page, show requested category and all others which have
+            // yet to be displayed.
+            elseif (in_array($child, $form_state['storage']['processed_categories'])) {
+              unset($form[$child]);
+            }
+          }
+        }
+      }
+    
+      $this->unsetForm($form);
+    }
+    else {
+      drupal_access_denied();
+      pageroute_exit_now();
+    }
+  }
+
+  public function getAdminForm($page, &$form) {
+    $categories = array();
+    foreach (_user_categories(false) as $category) {
+      $categories[$category['name']] = $category['title'];
+    }
+    $form['options']['category'] = array(
+      '#type' => 'select',
+      '#title' => t('Category'),
+      '#description' => t('The form of the chosen category will be used for this page.'),
+      '#required' => TRUE,
+      '#default_value' => isset($page->options['category']) ? $page->options['category'] : '',
+      '#weight' => 2,
+      '#options' => $categories,
+    );
+    $form['options']['description'] = array(
+      '#type' => 'textarea',
+      '#title' => t('Form description'),
+      '#default_value' => $page->options['description'],
+      '#description' => t('You can optionally input a description or message that will appear at the top of this form.')
+    );
+  }
+
+  public static function help() {
+    $help[] = t('This page type is provided by the profile_setup module to allow users to edit their profile "edit" categories which can be created using the profile or content profile modules.');
+    $help[] = t('<strong>Using Content Profile Module:</strong> If you are using Content Profile you much select <em>Show a secondary tab below the user\'s edit tab</em> under <em>Profile edit tab</em> in the content profile content type tab per content type.');
+    $help[] = t('<strong>Using Profile Module:</strong> If you are using core Profile account categories are automatically created as you create profile fields.');
+    return implode('<br />', $help);
+  }
+
+  public static function info() {
+    return array('name' => t('User account registration form'));
+  }
+  
+  public function unsetForm(&$form) {
+    if (profile_setup_page_is_content_profile_type($this->options['category'])) {
+      unset($form['buttons']['delete'], $form['buttons']['submit'], $form['buttons']['preview']);
+    }
+    else {
+      unset($form['delete'], $form['submit']);
+    }
+  }  
+
+  public function formSubmitted(&$form_state) {
+  }
+
+  public function setUp() {
+    include_once(drupal_get_path('module', 'node') .'/node.pages.inc');
+    include_once(drupal_get_path('module', 'user') .'/user.pages.inc');
+    include_once(drupal_get_path('module', 'profile_setup') .'/profile_setup.admin.inc');
+  }
+  
+  public static function getDefaultValidateHandler($form) {
+    if (!profile_setup_page_is_content_profile_type($form['account_category']['#value'])) {
+      $handlers = array('profile_setup_user_register_validate');
+      if (is_array($form['#validate'])) {
+        foreach ($form['#validate'] as $handler) {
+          if ($handler != 'user_register_validate') {
+            $handlers[] = $handler;
+          }
+        }
+      }
+      return $handlers;
+    }
+/* @TODO
+    else {
+      return 'node_form_validate';
+    }
+*/
+  }
+ 
+  public static function getDefaultSubmitHandler($form) {
+    if (!profile_setup_page_is_content_profile_type($form['account_category']['#value'])) {
+      $handlers = array('profile_setup_user_register_submit');
+      if (is_array($form['#submit'])) {
+        foreach ($form['#submit'] as $handler) {
+          if ($handler != 'user_register_submit') {
+            $handlers[] = $handler;
+          }
+        }
+      }
+      return $handlers;
+    }
+/* @TODO
+    else {
+      return 'node_form_submit';
+    }
+*/
+  }    
+}
+
+function profile_setup_user_register_validate($form, &$form_state) {
+  if ($form_state['storage']['pageroute_last_page']) {
+    $values = $form_state['storage']['pageroute_register_user_tmp'];
+    $form_state['values'] = empty($values) ? $form_state['values'] : $values + $form_state['values'];
+    return user_register_validate($form, &$form_state);
+  }
+  // not sure about this... 
+  elseif ($form_state['storage']['route']->pageDataCurrent->options['category'] != 'account') {
+    return user_profile_form_validate($form, &$form_state);
+  }
+}
+
+function profile_setup_user_register_submit($form, &$form_state) {
+  if (!isset($form_state['storage']['pageroute_register_user_tmp'])) {
+    $form_state['storage']['pageroute_register_user_tmp'] = $form_state['values'];
+  }
+  else {
+    $form_state['storage']['pageroute_register_user_tmp'] += $form_state['values'];
+  }
+  if ($form_state['storage']['pageroute_last_page']) {
+    $form_state['values'] = $form_state['storage']['pageroute_register_user_tmp'];
+    unset($form_state['storage']['pageroute_register_user_tmp']);
+    return user_register_submit($form, &$form_state);
+  }
+}
+
