'register_redirect', 'title' => t('RegisterRedirect'), 'callback' => 'register_redirect_handle', 'access' => user_access('reg_redirect') ); return $items; } // this method changes the role of the user from pre-auth to auth so that // we can have a fully authenticated user. we also do this // so that only the pre-auth user can access this module and the only time // that the user is in the pre-auth state is right after they gave registered. function reg_redirect_roles_alter(&$user) { $preauth_id = logintoboggan_validating_id(); $in_pre_auth_role = in_array($preauth_id, array_keys($user->roles)); if ($user->uid && $in_pre_auth_role) { unset($user->roles[$preauth_id]); $roles = user_roles(1); $user->roles[DRUPAL_AUTHENTICATED_RID] = $roles[DRUPAL_AUTHENTICATED_RID]; user_save($user,array('roles' => $user->roles)); cache_clear_all('menu:'. $user->uid, TRUE); } } /* this is the meat of the register_redirect basically what happens is: we check to see if the user wants to sign up for a free or paid membership if free, then we redirect them to their profile if paid we redirect them to the membership page where they can choose to sign up */ function register_redirect_handle() { if (!module_exist('civicrm')) return; global $user,$base_url; civicrm_initialize(TRUE); $prop_name = variable_get('reg_redirect_custom_field', ''); // by default we will redirect to the user page // this is changed below if the user has chosen // to become a paid member $reg_successful_msg = variable_get('reg_redirect_free_successful_msg',''); $redirect_url = variable_get('reg_redirect_free_mem_url', ''); $newsletter_signup_fieldname = variable_get('newsletter_signup_fieldname',''); $return_properties = array($prop_name => 1, $newsletter_signup_fieldname => 1); $lookup_params = array(email => $user->mail); list($cividata,$dontCare) = crm_contact_search( $lookup_params, $return_properties ); if ( ! is_a( $cividata, 'CRM_Core_Error' ) ) { if(count($cividata) > 1){ // setting the error here we really drupal_set_message(t("more than one member with the email: ").$user->mail,'error'); } // here we are interested in the only element in the array returned by // crm_contact_search $cividata = array_shift($cividata); $wants_paid_membership = $cividata[$prop_name]; if($wants_paid_membership){ $reg_successful_msg = variable_get('reg_redirect_paid_successful_msg',''); $redirect_url = variable_get('reg_redirect_paid_mem_url', 'user'); } // if the newsletter sign up field is present and positive // then we add the user to the default newsletter group if($newsletter_signup_fieldname && isset($cividata[$newsletter_signup_fieldname]) && $cividata[$newsletter_signup_fieldname]){ newsletter_add_user_to_list($user->mail); } // set the user to the authenticated user role reg_redirect_roles_alter($user); // clear the message queue // by caling the get_messages function // ridiculous! drupal_get_messages(); drupal_set_message($reg_successful_msg); drupal_goto($redirect_url); } else { die( t("Contact data not found").' : '.$user->mail); } } function reg_redirect_settings() { $form['reg_redirect_heading'] = array( '#type' => 'markup', '#value' => t('
Register Redirect Settings