diff -crB --exclude .svn apply_for_role.orig/apply_for_role.admin.inc apply_for_role/apply_for_role.admin.inc
*** apply_for_role.orig/apply_for_role.admin.inc	2009-07-15 09:45:37.000000000 +0300
--- apply_for_role/apply_for_role.admin.inc	2010-03-06 19:59:12.000000000 +0200
***************
*** 7,12 ****
--- 7,41 ----
   */
  
  /**
+  * Display option settings.
+  * 
+  * @return array()
+  */
+ function _afr_disp_options() {
+   return array(
+     APPLY_FOR_ROLE_PENDING + 1  => t('Pending'),
+     APPLY_FOR_ROLE_APPROVED + 1 => t('Approved'),
+     APPLY_FOR_ROLE_DENIED + 1   => t('Denied'),
+     APPLY_FOR_ROLE_GRANTED + 1  => t('Granted'),
+   );
+ }
+ 
+ /**
+  * The display options from the variable 'apply_for_role_display_state'
+  * with 1 based index keys for form checkboxes. 
+  * 
+  * @return array()
+  */
+ function _afr_selected_disp_options() {
+   $disp_options = array();
+   $saved_options = variable_get('apply_for_role_display_state', array());
+   foreach ($saved_options as $key => $value) {
+     $disp_options[$key + 1] = $value;
+   }
+   return $disp_options;
+ }
+ 
+ /**
   * Module settings page.
   */
  function apply_for_role_settings_form(&$form_state) {
***************
*** 36,47 ****
      '#description' => t("Choosing 'optional' will allow users to apply for roles when creating a new account. Choosing 'required' will require users to apply for roles when creating a new account."),
      '#required' => TRUE,
    );
!   $form['options']['display_approved'] = array(
!     '#type' => 'radios',
!     '#title' => t('Display approved roles in an application form'),
!     '#options' => array(t('No'), t('Yes')),
!     '#default_value' => variable_get('apply_for_role_display_approved', 0),
!     '#description' => t("Choosing 'yes' will allow a user to see which role applications where approved."),
      '#required' => TRUE,
    );
    $roles = (user_roles(TRUE));
--- 65,76 ----
      '#description' => t("Choosing 'optional' will allow users to apply for roles when creating a new account. Choosing 'required' will require users to apply for roles when creating a new account."),
      '#required' => TRUE,
    );
!   $form['options']['display_state'] = array(
!     '#type' => 'checkboxes',
!     '#title' => t('Display options for roles in an application form'),
!     '#options' => _afr_disp_options(),
!     '#default_value' => _afr_selected_disp_options(),
!     '#description' => t("Choose for which role states the user is allowed to see."),
      '#required' => TRUE,
    );
    $roles = (user_roles(TRUE));
***************
*** 73,79 ****
    variable_set('users_apply_roles', $selected_roles);
    variable_set('apply_for_role_multiple', $form['options']['multiple']['#value']);
    variable_set('apply_for_role_register', $form['options']['register']['#value']);
!   variable_set('apply_for_role_display_approved', $form_state['values']['display_approved']);
    drupal_set_message(t('Apply for role settings have been saved.'));
  
    $form_state['redirect'] = 'admin/settings/apply_for_role';
--- 102,114 ----
    variable_set('users_apply_roles', $selected_roles);
    variable_set('apply_for_role_multiple', $form['options']['multiple']['#value']);
    variable_set('apply_for_role_register', $form['options']['register']['#value']);
!   
!   foreach ($form_state['values']['display_state'] as $key => $value) {
!     // make keys 0 based to match with APPLY_FOR_ROLE_* constants.
!     $disp_options[$key - 1] = $value;
!   }
!   variable_set('apply_for_role_display_state', $disp_options);
! 
    drupal_set_message(t('Apply for role settings have been saved.'));
  
    $form_state['redirect'] = 'admin/settings/apply_for_role';
diff -crB --exclude .svn apply_for_role.orig/apply_for_role.module apply_for_role/apply_for_role.module
*** apply_for_role.orig/apply_for_role.module	2009-07-15 09:45:37.000000000 +0300
--- apply_for_role/apply_for_role.module	2010-03-06 20:20:18.000000000 +0200
***************
*** 9,14 ****
--- 9,19 ----
  define('APPLY_FOR_ROLE_PENDING', 0);
  define('APPLY_FOR_ROLE_APPROVED', 1);
  define('APPLY_FOR_ROLE_DENIED', 2);
+ /// the roles that the user is granted
+ /// which do not appear in users_roles_apply table
+ /// (either pre-assigned or admin deleted role application
+ ///  after approval)
+ define('APPLY_FOR_ROLE_GRANTED', 3);
  
  if (module_exists('token')) {
    module_load_include('inc', 'apply_for_role', 'apply_for_role.token');
***************
*** 52,59 ****
   */
  function apply_for_role_menu() {
    $items['admin/settings/apply_for_role'] = array(
!     'title' => t('Apply for role administration'),
!     'description' => t('Administer which roles users can apply for.'),
      'page callback' => 'drupal_get_form',
      'page arguments' => array('apply_for_role_settings_form'),
      'access arguments' => array('administer apply for role'),
--- 57,64 ----
   */
  function apply_for_role_menu() {
    $items['admin/settings/apply_for_role'] = array(
!     'title' => 'Apply for role administration',
!     'description' => 'Administer which roles users can apply for.',
      'page callback' => 'drupal_get_form',
      'page arguments' => array('apply_for_role_settings_form'),
      'access arguments' => array('administer apply for role'),
***************
*** 61,68 ****
    );
  
    $items['admin/user/apply_for_role'] = array(
!     'title' => t('Manage role applications'),
!     'description' => t('View, approve and delete role applications.'),
      'page callback' => 'drupal_get_form',
      'page arguments' => array('apply_for_role_admin_form'),
      'access arguments' => array('approve role applications'),
--- 66,73 ----
    );
  
    $items['admin/user/apply_for_role'] = array(
!     'title' => 'Manage role applications',
!     'description' => 'View, approve and delete role applications.',
      'page callback' => 'drupal_get_form',
      'page arguments' => array('apply_for_role_admin_form'),
      'access arguments' => array('approve role applications'),
***************
*** 70,76 ****
    );
  
    $items['admin/user/apply_for_role/approve/%user/%'] = array(
!     'title' => t('Approve role application'),
      'page callback' => 'drupal_get_form',
      'page arguments' => array('apply_for_role_approve_form', 4, 5),
      'access arguments' => array('approve role applications'),
--- 75,81 ----
    );
  
    $items['admin/user/apply_for_role/approve/%user/%'] = array(
!     'title' => 'Approve role application',
      'page callback' => 'drupal_get_form',
      'page arguments' => array('apply_for_role_approve_form', 4, 5),
      'access arguments' => array('approve role applications'),
***************
*** 79,85 ****
    );
  
    $items['admin/user/apply_for_role/deny/%user/%'] = array(
!     'title' => t('Deny role application'),
      'page callback' => 'drupal_get_form',
      'page arguments' => array('apply_for_role_deny_form', 4, 5),
      'access arguments' => array('approve role applications'),
--- 84,90 ----
    );
  
    $items['admin/user/apply_for_role/deny/%user/%'] = array(
!     'title' => 'Deny role application',
      'page callback' => 'drupal_get_form',
      'page arguments' => array('apply_for_role_deny_form', 4, 5),
      'access arguments' => array('approve role applications'),
***************
*** 88,94 ****
    );
  
    $items['admin/user/apply_for_role/remove/%user/%'] = array(
!     'title' => t('Remove role application'),
      'page callback' => 'drupal_get_form',
      'page arguments' => array('apply_for_role_remove_form', 4, 5),
      'access arguments' => array('approve role applications'),
--- 93,99 ----
    );
  
    $items['admin/user/apply_for_role/remove/%user/%'] = array(
!     'title' => 'Remove role application',
      'page callback' => 'drupal_get_form',
      'page arguments' => array('apply_for_role_remove_form', 4, 5),
      'access arguments' => array('approve role applications'),
***************
*** 97,103 ****
    );
  
    $items['user/%user/apply_for_role'] = array(
!     'title' => t('Apply for role'),
      'page callback' => 'drupal_get_form',
      'page arguments' => array('apply_for_role_apply_form', 1),
      'access callback' => 'apply_for_role_apply_access',
--- 102,108 ----
    );
  
    $items['user/%user/apply_for_role'] = array(
!     'title' => 'Apply for role',
      'page callback' => 'drupal_get_form',
      'page arguments' => array('apply_for_role_apply_form', 1),
      'access callback' => 'apply_for_role_apply_access',
***************
*** 131,148 ****
    $form = array();
  
    $filter_roles = apply_for_role_available_roles($user);
    if (count($filter_roles)) {
      $form['user'] = array(
        '#type' => 'value',
        '#value' => $user,
      );
-     // List of roles that were already approved.
-     $approved = apply_for_role_approved_roles($user);
-     if (variable_get('apply_for_role_display_approved', 0) && count($approved)) {
-       $form['approved'] = array(
-         '#value' => theme('item_list', $approved, t('You have applied for these roles and were approved:')),
-       );
-     }
      $form['rid'] = array(
        '#type' => variable_get('apply_for_role_multiple', 0) ? 'checkboxes' : 'select',
        '#title' => variable_get('apply_for_role_multiple', 0) ? t('Select a role or roles') : t('Select a role'),
--- 136,177 ----
    $form = array();
  
    $filter_roles = apply_for_role_available_roles($user);
+ 
+   $disp_options  = variable_get('apply_for_role_display_state', array());
+ 
+   if ($disp_options[APPLY_FOR_ROLE_PENDING] || 
+       $disp_options[APPLY_FOR_ROLE_APPROVED] || 
+       $disp_options[APPLY_FOR_ROLE_DENIED] || 
+       $disp_options[APPLY_FOR_ROLE_GRANTED] ) {
+         
+     $used_roles = apply_for_role_used_roles($user);
+     
+     if ($disp_options[APPLY_FOR_ROLE_GRANTED] && count($used_roles[APPLY_FOR_ROLE_GRANTED])) {
+       $form['granted'] = array(
+         '#value' => theme('item_list', $used_roles[APPLY_FOR_ROLE_GRANTED], t('You are granted these roles:')),
+       );
+     }
+     if ($disp_options[APPLY_FOR_ROLE_APPROVED] && count($used_roles[APPLY_FOR_ROLE_APPROVED])) {
+       $form['approved'] = array(
+         '#value' => theme('item_list', $used_roles[APPLY_FOR_ROLE_APPROVED], t('You have applied for these roles and were approved:')),
+       );
+     }
+     if ($disp_options[APPLY_FOR_ROLE_PENDING] && count($used_roles[APPLY_FOR_ROLE_PENDING])) {
+       $form['pending'] = array(
+         '#value' => theme('item_list', $used_roles[APPLY_FOR_ROLE_PENDING], t('You have applied for these roles and they are pending approval:')),
+       );
+     }
+     if ($disp_options[APPLY_FOR_ROLE_DENIED] && count($used_roles[APPLY_FOR_ROLE_DENIED])) {
+       $form['denied'] = array(
+         '#value' => theme('item_list', $used_roles[APPLY_FOR_ROLE_DENIED], t('You have applied for these roles and were denied:')),
+       );
+     }
+   }
    if (count($filter_roles)) {
      $form['user'] = array(
        '#type' => 'value',
        '#value' => $user,
      );
      $form['rid'] = array(
        '#type' => variable_get('apply_for_role_multiple', 0) ? 'checkboxes' : 'select',
        '#title' => variable_get('apply_for_role_multiple', 0) ? t('Select a role or roles') : t('Select a role'),
***************
*** 163,169 ****
  function apply_for_role_apply_form_submit($form, &$form_state) {
    global $user;
    apply_for_role_process_applications($form_state['values']['user'], $form_state['values']['rid']);
!   $form_state['redirect'] = 'user/'. $user->uid;
  }
  
  
--- 192,198 ----
  function apply_for_role_apply_form_submit($form, &$form_state) {
    global $user;
    apply_for_role_process_applications($form_state['values']['user'], $form_state['values']['rid']);
!   $form_state['redirect'] = 'user/'. $user->uid.'/apply_for_role';
  }
  
  
***************
*** 512,541 ****
    }
  
    if (!empty($received)) {
!     drupal_set_message(t('%message %roles', array('%message' => format_plural(count($received), t('Your application was received for the following role:'), t('Your applications were received for the following roles:')), '%roles' => implode(', ', $received))));
    }
    if (!empty($not_received)) {
!     drupal_set_message(t('%message %roles', array('%message' => format_plural(count($not_received), t('There was a problem processing your application for the following role:'), t('There was a problem processing your applications for the following roles:')), '%roles' => implode(', ', $not_received))), 'error');
    }
  }
  
  /**
!  * Return an array of roles that were approved for this user.
   *
   * @param $user User object.
   */
! function apply_for_role_approved_roles(&$user) {
!   $approved = array();
! 
    $roles = user_roles(TRUE);
  
!   $result = db_query("SELECT rid FROM {users_roles_apply} WHERE uid = %d and approved = %d", $user->uid, APPLY_FOR_ROLE_APPROVED);
    while ($row = db_fetch_object($result)) {
!     if (isset($roles[$row->rid]) && isset($user->roles[$row->rid]))
!       $approved[$row->rid] = $roles[$row->rid];
!     else
!       continue;
    }
  
!   return $approved;
  }
--- 541,584 ----
    }
  
    if (!empty($received)) {
!     drupal_set_message(t('%message %roles', array('%message' => format_plural(count($received), 'Your application was received for the following role:', 'Your applications were received for the following roles:'), '%roles' => implode(', ', $received))));
    }
    if (!empty($not_received)) {
!     drupal_set_message(t('%message %roles', array('%message' => format_plural(count($not_received), 'There was a problem processing your application for the following role:', 'There was a problem processing your applications for the following roles:'), '%roles' => implode(', ', $not_received))), 'error');
    }
  }
  
  /**
!  * Return an array of approval state for each role  
!  * that was previously applied for by this user
!  * and the roles that the user is granted (above authenticated)
!  * for which there is no application on record.
   *
   * @param $user User object.
+  * @return array(approval_state => array(role_id, ...))
   */
! function apply_for_role_used_roles(&$user) {
!   // roles for which there's application state
!   $used_roles = array();
!   // available roles
    $roles = user_roles(TRUE);
+   // this user's roles
+   $granted_roles = $user->roles;
  
!   $result = db_query("SELECT rid, approved FROM {users_roles_apply} WHERE uid = %d", $user->uid);
    while ($row = db_fetch_object($result)) {
!     $used_roles[$row->approved][] = $roles[$row->rid];
!     if ($row->approved == APPLY_FOR_ROLE_APPROVED) {
!       unset($granted_roles[$row->rid]);
!     }
    }
  
!   // add granted roles above authenticated (rid == 2)
!   foreach($granted_roles as $rid => $name) {
!     if ($rid > 2) {
!       $used_roles[APPLY_FOR_ROLE_GRANTED][] = $name;
!     }
!   }
!   
!   return $used_roles;
  }
Only in apply_for_role/translations: he.po
