Fix for rolesignup test code for D6

  1. <?php
  2. /* $Id: rolesignup.module,v 1.2.4.1 2007/01/20 21:49:48 sym Exp $ */
  3.  
  4. /********************************************************************
  5. * Drupal Hooks
  6. ********************************************************************/
  7. /**
  8.  * Implementation of module_enable()
  9.  */
  10. function rolesignup_enable() {
  11.         cache_clear_all();
  12.         menu_cache_clear();
  13.         menu_rebuild();
  14. }
  15.  
  16. /**
  17.  * Implementation of module_disable()
  18.  */
  19. function rolesignup_disable() {
  20.         cache_clear_all();
  21.         menu_cache_clear();
  22.         menu_rebuild();
  23. }
  24.  
  25. /**
  26.  * Implementation of hook_menu()
  27.  */
  28. function rolesignup_menu() {
  29.   return array(
  30.     'user/register/role/%' => array(
  31.         'page callback' => 'role_register_page',
  32.         'page arguments' => array(3),
  33.         'title' => t('Register'),
  34.         'type' => MENU_LOCAL_TASK
  35.     )
  36.   );
  37. }
  38.  
  39. /**
  40.  * Implementation of hook_perm()
  41.  */
  42. function rolesignup_perm() {
  43.   return array('register for role');
  44. }
  45.  
  46. function role_register_page($string = NULL) {
  47.   $roles = user_roles(1, 'register for role');
  48.   drupal_set_title("Please select your Role below");
  49.   return drupal_get_form('rolelist_form', $roles, $string);
  50. }
  51.  
  52. /**
  53.  * Implementation of hook_user()
  54.  */
  55. function rolesignup_user($op, &$edit, &$account, $category = NULL) {
  56.   switch ($op) {
  57.     case 'insert':
  58.     $roles = user_roles(1,'register for role');
  59.     if ($roles[$_SESSION['role']]) {
  60.       if(!isset($edit["roles"]) || !is_array($edit["roles"])) {
  61.         $edit["roles"] = array($_SESSION['role'] => $roles[$_SESSION['role']]);
  62.       } else {
  63.         $edit["roles"][$_SESSION['role']] = $roles[$_SESSION['role']];
  64.       }
  65.     }
  66.     break;
  67.     case 'register':
  68.             if(!$category || $category == "account") {
  69.                         if (!$_SESSION['role']) {
  70.                                 drupal_goto('user/register/role/invalid', drupal_get_destination());
  71.                         }
  72.                         $roles = user_roles();
  73.                         $rolename = $roles[$_SESSION['role']];
  74.                         $form = array();
  75.                         $form["#prefix"] = "<p class='messages role_select'>You are registering for the '".ucwords(strtolower($rolename))."' Role.<br/></p>";
  76.                         $form["back"] = array(
  77.                                 "#type" => "submit"
  78.                                 ,"#submit" => array("rolesignup_goto_role_selection")
  79.                                 ,"#value" => "Change Role"
  80.                         );
  81.                         return $form;
  82.             }
  83.     break;
  84.   }
  85. }
  86.  
  87. function rolesignup_goto_role_selection($form, &$form_state) {
  88.         $url = 'user/register/role/'.$_SESSION['role'];
  89.         unset($_SESSION['role']);
  90.         drupal_goto($url, drupal_get_destination());
  91. }
  92.  
  93. function rolelist_form($form_state = NULL, $roles, $string) {
  94.   $rids = array_keys($roles);
  95.   if(in_array($string, $rids)) {
  96.         $rid = $string;
  97.   } else {
  98.         $rid = $rids[0];
  99.   }
  100.   $form = array();
  101.   $form["role"] = array(
  102.         "#type" => "select"
  103.         ,"#options" => $roles
  104.         ,"#default_value" => $rid
  105.         ,"#description" => "roles define the behaviour of your account."
  106.         ,"#required" => TRUE
  107.   );
  108.   $form["next"] = array(
  109.         "#type" => "submit"
  110.         ,"#value" => "Next"
  111.   );
  112.   return $form;
  113. }
  114.  
  115. function rolelist_form_submit($form, &$form_state) {
  116.         $_SESSION['role'] = $form_state["values"]["role"];
  117.         drupal_goto('user/register');
  118. }