--- apply_for_role.module	Sat Mar 15 11:56:46 2008
+++ apply_for_role.multi.module	Fri Mar 14 14:20:18 2008
@@ -19,7 +19,7 @@
 	function apply_for_role_menu($may_cache) {
 	  global $user;
 	  $items = array();
-	
+		
 	  if ($may_cache) {
 	    $items[] = array('path' => 'admin/settings/apply_for_role',
 	    								 'title' => t('Apply for role administration'),
@@ -79,6 +79,13 @@
 	    '#description' => t('A list of roles users can apply for.'),
 	    '#required' => TRUE,
 	  );
+	  $form['multiple'] = array('#type' => 'checkboxes',
+	    '#title' => t('Multiple role selection'),
+	    '#default_value' => variable_get('users_apply_roles_multiple', array()),
+	    '#options' => array('multiple' => t('Allow user to select multiple roles')),
+	    '#description' => t('By checking this checkbox, you allow site user to apply for several roles at the same time.'),
+	    '#required' => FALSE,
+	  );
 	
 	  $form['submit'] = array('#type' => 'submit', '#value' => t('Submit'));
 	  return $form;
@@ -92,6 +99,7 @@
 				}
 			}
 			variable_set('users_apply_roles', $selected_roles);
+			variable_set('users_apply_roles_multiple', $form['multiple']);
 			drupal_set_message(t('Apply to roles settings has been saved.'));
 			return 'admin/settings/apply_for_role';
 	}
@@ -205,31 +213,53 @@
 			}
 		}
 		
+		$multiple = variable_get('users_apply_roles_multiple', array());
+		drupal_set_message('<pre>'.print_r($filter_roles, true).'</pre>');
  	  if (is_array($filter_roles)) {
-	       $form['rid'] = array(
-	       '#type' => 'select',
-	       '#title' => t('Which role do you want to apply for?'),
-	       '#default_value' => '',
-	       '#options' => $filter_roles,
-	     );
-	
+			if ($multiple['multiple']) {
+				$form['rid'] = array(
+					'#type' => 'checkboxes',
+					'#title' => t('Which role do you want to apply for?'),
+					'#default_value' => '',
+					'#options' => $filter_roles,
+				);
+			} else {
+				$form['rid'] = array(
+					'#type' => 'select',
+					'#title' => t('Which role do you want to apply for?'),
+					'#default_value' => '',
+					'#options' => $filter_roles,
+				);
+			}
 	     $form['submit'] = array(
 	       '#type' => 'submit',
 	       '#value' => t('Apply')
 	     );
-	
 	     return $form;
      } else {
-       drupal_set_message('No roles are available at this time.', 'notice');
+       drupal_set_message(t('No roles are available at this time.'), 'notice');
      }
 	}
 	
 	function apply_for_role_apply_form_submit($form_id, $form_values){
 		global $user;	
-		if(apply_for_role_add_apply($user->uid, $form_values['rid'])){
-			drupal_set_message(t('Your application has been recieved and will be approved by administrator.'));
-		}else{
-			drupal_set_message(t('Your application has NOT been recieved.'), 'error');
+		$roles = user_roles(1);
+		if(is_array($form_values['rid'])) {
+			foreach($form_values['rid'] as $rid) {
+				if($rid != 0) {
+					if(apply_for_role_add_apply($user->uid, $rid)){
+						drupal_set_message(t('Your application for the role "%role" has been recieved and will be approved by administrator.', array('%role' => $roles[$rid])));
+					}else{
+						drupal_set_message(t('Your application for the role "%role" has not been received.', array('%role' => $roles[$rid])), 'error');
+					}
+				}
+			}
+		} else {
+			if(apply_for_role_add_apply($user->uid, $form_values['rid'])){
+						drupal_set_message(t('Your application for the role "%role" has been recieved and will be approved by administrator.', array('%role' => $form_values['rid'])));
+			}else{
+						drupal_set_message(t('Your application for the role "%role" has not been received.', array('%role' => $form_values['rid'])), 'error');
+			}
 		}
 	  return 'user/' . $user->uid;
 	}
@@ -264,28 +294,24 @@
 	
 	function apply_for_role_approve_apply($uid, $rid){
 		if(!apply_for_role_check_role_exist($uid, $rid)){
-			
 			$res = db_query("SELECT uid, rid, approved FROM {users_roles_apply} WHERE uid = %d AND rid = %d", $uid, $rid);
 			if(db_num_rows($res)){
 				$row = db_fetch_object($res);
-				
 				if($row->approved == 0){
 					apply_for_role_add_role($uid, $rid);
 					db_query("UPDATE {users_roles_apply} SET approved = 1, approve_date = %d WHERE uid = %d AND rid = %d", time(), $uid, $rid);
 					return true;
 				}
-				
 			}
-			
 		}
 	}
 	
 	function apply_for_role_remove_apply($uid, $rid){
 		$res = db_query("SELECT uid, rid, approved FROM {users_roles_apply} WHERE uid = %d AND rid = %d", $uid, $rid);
 		if(db_num_rows($res)){
-				apply_for_role_delete_role($uid, $rid);
-				db_query("DELETE FROM {users_roles_apply} WHERE uid = %d AND rid = %d", $uid, $rid);
-				return true;
+			apply_for_role_delete_role($uid, $rid);
+			db_query("DELETE FROM {users_roles_apply} WHERE uid = %d AND rid = %d", $uid, $rid);
+			return true;
 		}
 	}
 	
