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. /**
  47.  * Implementation of hook_form_alter()
  48.  */
  49. //function rolesignup_form_alter(&$form, $form_state, $form_id) {
  50. //  if ($form_id == "user_register") {
  51. //    global $user;
  52. //    if (!user_access('administer users') && !$_SESSION['role']) {
  53. //      drupal_goto('user/register/role', drupal_get_destination());
  54. //    } else {
  55. //      $form['role'] = array(
  56. //        '#type' => 'value',
  57. //        '#value' => $_SESSION['role'],
  58. //        );
  59. //    }
  60. //    $form['rolelink'] = array(
  61. //      '#value' => theme('select_role'),
  62. //      '#weight' => -11,      
  63. //      );
  64. //  }
  65. //}
  66.  
  67. function role_register_page($string = NULL) {
  68.   $roles = user_roles(1, 'register for role');
  69.   drupal_set_title("Please select your Role below");
  70.   return drupal_get_form('rolelist_form', $roles, $string);
  71. }
  72.  
  73. /**
  74.  * Implementation of hook_user()
  75.  */
  76. function rolesignup_user($op, &$edit, &$account, $category = NULL) {
  77.   switch ($op) {
  78.     case 'insert':
  79.     $roles = user_roles(1,'register for role');
  80.     if ($roles[$_SESSION['role']] && !in_array($_SESSION['role'], array(DRUPAL_ANONYMOUS_RID, DRUPAL_AUTHENTICATED_RID))) {
  81.       drupal_set_message($account->uid);
  82.       drupal_set_message($_SESSION['role']);
  83.       db_query('INSERT INTO {users_roles} (uid, rid) VALUES (%d, %d)', $account->uid, $_SESSION['role']);
  84.     }
  85.     break;
  86.     case 'register':
  87.             if(!$category || $category == "account") {
  88.                         if (!$_SESSION['role']) {
  89.                                 drupal_goto('user/register/role/invalid', drupal_get_destination());
  90.                         }
  91.                         $roles = user_roles();
  92.                         $rolename = $roles[$_SESSION['role']];
  93.                         $form = array();
  94.                         $form["#prefix"] = "<p class='messages role_select'>You are registering for the '".ucwords(strtolower($rolename))."' Role.<br/></p>";
  95.                         $form["back"] = array(
  96.                                 "#type" => "submit"
  97.                                 ,"#submit" => array("rolesignup_goto_role_selection")
  98.                                 ,"#value" => "Change Role"
  99.                         );
  100.                         return $form;
  101.             }
  102.     break;
  103.   }
  104. }
  105.  
  106. function rolesignup_goto_role_selection($form, &$form_state) {
  107.         $url = 'user/register/role/'.$_SESSION['role'];
  108.         unset($_SESSION['role']);
  109.         drupal_goto($url, drupal_get_destination());
  110. }
  111.  
  112. /**********************************************************************************/
  113. /*
  114. mysql> select * from web_watchdog\G
  115. *************************** 1. row ***************************
  116.       wid: 2186
  117.       uid: 1
  118.      type: actions
  119.   message: One orphaned action (<em>comment_unpublish_action</em>) exists in the actions table. <a href="/click_to_call/?q=admin/build/actions/orphan">Remove orphaned actions</a>
  120. variables: a:0:{}
  121.  severity: 5
  122.      link:
  123.  location: http://localhost/click_to_call/?q=admin/build/modules/list/confirm
  124.   referer: http://localhost/click_to_call/?q=admin/build/modules
  125.  hostname: 127.0.0.1
  126. timestamp: 1201784818
  127. *************************** 2. row ***************************
  128.       wid: 2187
  129.       uid: 1
  130.      type: user
  131.   message: Session closed for %name.
  132. variables: a:1:{s:5:"%name";s:11:"clicktocall";}
  133.  severity: 5
  134.      link:
  135.  location: http://localhost/click_to_call/?q=logout
  136.   referer: http://localhost/click_to_call/?q=admin/build/modules
  137.  hostname: 127.0.0.1
  138. timestamp: 1201784826
  139. *************************** 3. row ***************************
  140.       wid: 2188
  141.       uid: 0
  142.      type: user
  143.   message: New user: %name (%email).
  144. variables: a:2:{s:5:"%name";s:5:"dssdf";s:6:"%email";s:15:"asdfa@sdfsd.csd";}
  145.  severity: 5
  146.      link: <a href="/click_to_call/?q=user/17/edit">edit</a>
  147.  location: http://localhost/click_to_call/?q=user/register
  148.   referer: http://localhost/click_to_call/?q=user/register
  149.  hostname: 127.0.0.1
  150. timestamp: 1201784843
  151. 3 rows in set (0.00 sec)
  152.  
  153. */
  154.  
  155.  
  156. function rolelist_form($form_state = NULL, $roles, $string) {
  157.   $rids = array_keys($roles);
  158.   if(in_array($string, $rids)) {
  159.         $rid = $string;
  160.   } else {
  161.         $rid = $rids[0];
  162.   }
  163.   $form = array();
  164.   $form["role"] = array(
  165.         "#type" => "select"
  166.         ,"#options" => $roles
  167.         ,"#default_value" => $rid
  168.         ,"#description" => "roles define the behaviour of your account."
  169.         ,"#required" => TRUE
  170.   );
  171.   $form["next"] = array(
  172.         "#type" => "submit"
  173.         ,"#value" => "Next"
  174.   );
  175.   return $form;
  176. }
  177.  
  178. function rolelist_form_submit($form, &$form_state) {
  179.         $_SESSION['role'] = $form_state["values"]["role"];
  180.         drupal_goto('user/register');
  181. }