? autoassignrole5-dev.txt Index: .project =================================================================== RCS file: .project diff -N .project --- .project 31 Jan 2008 22:57:36 -0000 1.1 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,22 +0,0 @@ - - - autoassignrole - - - - - - org.eclipse.php.core.PhpIncrementalProjectBuilder - - - - - org.eclipse.wst.validation.validationbuilder - - - - - - org.eclipse.php.core.PHPNature - - Index: autoassignrole.info =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/autoassignrole/autoassignrole.info,v retrieving revision 1.3 diff -u -p -r1.3 autoassignrole.info --- autoassignrole.info 12 Feb 2008 17:27:58 -0000 1.3 +++ autoassignrole.info 24 Mar 2008 13:45:35 -0000 @@ -1,4 +1,3 @@ ; $Id: autoassignrole.info,v 1.3 2008/02/12 17:27:58 cyberswat Exp $ name = "Auto Assign Role" description = "Designate a role to assign all new users to." - Index: autoassignrole.install =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/autoassignrole/autoassignrole.install,v retrieving revision 1.7 diff -u -p -r1.7 autoassignrole.install --- autoassignrole.install 12 Feb 2008 17:27:58 -0000 1.7 +++ autoassignrole.install 24 Mar 2008 13:45:35 -0000 @@ -4,8 +4,8 @@ * Implementation of hook_uninstall(). */ function autoassignrole_uninstall() { - $vars = db_query("select name from variable where name like 'AUTOASSIGNROLE_%%'"); - while ($var = db_fetch_object($vars)) { - variable_del($var->name); - } + $vars = db_query("SELECT name FROM {variable} WHERE name LIKE 'AUTOASSIGNROLE_%%'"); + while ($var = db_fetch_object($vars)) { + variable_del($var->name); + } } \ No newline at end of file Index: autoassignrole.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/autoassignrole/autoassignrole.module,v retrieving revision 1.9 diff -u -p -r1.9 autoassignrole.module --- autoassignrole.module 12 Feb 2008 17:27:58 -0000 1.9 +++ autoassignrole.module 24 Mar 2008 13:45:36 -0000 @@ -1,13 +1,15 @@ 'admin/user/autoassignrole', - 'title' => t('Auto assign role'), - 'description' => t('Auto Assign Role Settings.'), - 'callback' => 'drupal_get_form', - 'callback arguments' => 'autoassignrole_settings', - 'access' => user_access('administer autoassignrole'), + 'path' => 'admin/user/autoassignrole', + 'title' => t('Auto assign role'), + 'description' => t('Auto Assign Role Settings.'), + 'callback' => 'drupal_get_form', + 'callback arguments' => 'autoassignrole_settings', + 'access' => user_access('administer autoassignrole'), ); } return $items; } function autoassignrole_settings() { $form['autoassignrole_settings_auto'] = array( - '#type' => 'fieldset', - '#title' => t('Automatic Role Assignment'), - '#collapsible' => TRUE, - '#collapsed' => TRUE, + '#type' => 'fieldset', + '#title' => t('Automatic Role Assignment'), + '#collapsible' => TRUE, + '#collapsed' => TRUE, ); $form['autoassignrole_settings_auto']['AUTOASSIGNROLE_ROLE_ACTIVE'] = array( '#type' => 'radios', '#title' => t('Automatic role assignment'), '#description' => t('Automatic role assignment occurs when the user first logins to the account. This happens without the users knowledge.'), - '#default_value' => variable_get('AUTOASSIGNROLE_ROLE_ACTIVE',0), + '#default_value' => variable_get('AUTOASSIGNROLE_ROLE_ACTIVE', AUTOASSIGNROLE_ROLE_ACTIVE), '#options' => array(1 => t('Enabled'), 0 => t('Disabled')), ); $form['autoassignrole_settings_auto']['AUTOASSIGNROLE_ROLE'] = array( '#type' => 'checkboxes', '#title' => t('Role'), - '#default_value' => variable_get('AUTOASSIGNROLE_ROLE',''), + '#default_value' => variable_get('AUTOASSIGNROLE_ROLE', AUTOASSIGNROLE_ROLE), '#options' => user_roles(), '#description' => t('Select the roles to assign new users.'), ); $form['autoassignrole_settings_user'] = array( - '#type' => 'fieldset', - '#title' => t('User Role Assignment'), - '#collapsible' => TRUE, - '#collapsed' => TRUE, + '#type' => 'fieldset', + '#title' => t('User Role Assignment'), + '#collapsible' => TRUE, + '#collapsed' => TRUE, ); $form['autoassignrole_settings_user']['AUTOASSIGNROLE_ROLE_USER_ACTIVE'] = array( '#type' => 'radios', '#title' => t('User Role Assignment'), '#description' => t('The end user will be allowed to select the following roes when they log in.'), - '#default_value' => variable_get('AUTOASSIGNROLE_ROLE_USER_ACTIVE',0), + '#default_value' => variable_get('AUTOASSIGNROLE_ROLE_USER_ACTIVE', AUTOASSIGNROLE_ROLE_USER_ACTIVE), '#options' => array(1 => t('Enabled'), 0 => t('Disabled')), ); $form['autoassignrole_settings_user']['AUTOASSIGNROLE_ROLE_USER'] = array( '#type' => 'checkboxes', '#title' => t('Role'), - '#default_value' => variable_get('AUTOASSIGNROLE_ROLE_USER',''), + '#default_value' => variable_get('AUTOASSIGNROLE_ROLE_USER', AUTOASSIGNROLE_ROLE_USER), '#options' => user_roles(), '#description' => t('Select the roles that are offered to new users.'), ); @@ -73,45 +75,45 @@ function autoassignrole_settings() { '#type' => 'radios', '#title' => t('User Role Selection'), '#description' => t('Should the end user be allowed to choose a single role or can they choose multiple roles?'), - '#default_value' => variable_get('AUTOASSIGNROLE_ROLE_USER_MULTIPLE',0), + '#default_value' => variable_get('AUTOASSIGNROLE_ROLE_USER_MULTIPLE', AUTOASSIGNROLE_ROLE_USER_MULTIPLE), '#options' => array(0 => t('Single Role'), 1 => t('Multiple Roles')), ); $form['autoassignrole_settings_user']['AUTOASSIGNROLE_ROLE_USER_REQUIRED'] = array( '#type' => 'checkbox', '#title' => t('Required'), '#description' => t('Should the end user be required to choose a role?'), - '#default_value' => variable_get('AUTOASSIGNROLE_ROLE_USER_REQUIRED',0), + '#default_value' => variable_get('AUTOASSIGNROLE_ROLE_USER_REQUIRED', AUTOASSIGNROLE_ROLE_USER_REQUIRED), ); $form['autoassignrole_settings_user']['AUTOASSIGNROLE_ROLE_SORT'] = array( '#type' => 'select', '#title' => t('Sorting'), '#description' => t('Default sort order of roles the user will see.'), - '#default_value' => variable_get('AUTOASSIGNROLE_ROLE_SORT','SORT_ASC'), + '#default_value' => variable_get('AUTOASSIGNROLE_ROLE_SORT', AUTOASSIGNROLE_ROLE_SORT), '#options' => array('SORT_ASC' => t('Ascending'), 'SORT_DESC' => t('Descending')), ); $form['autoassignrole_settings_user']['AUTOASSIGNROLE_ROLE_USER_FIELDSET'] = array( '#type' => 'textfield', '#title' => t('User Role Fieldset Title'), '#description' => t('The title of the fieldset that contains role options.'), - '#default_value' => variable_get('AUTOASSIGNROLE_ROLE_USER_FIELDSET', 'User Role Selection'), + '#default_value' => variable_get('AUTOASSIGNROLE_ROLE_USER_FIELDSET', AUTOASSIGNROLE_ROLE_USER_FIELDSET), '#size' => 60, - '#maxlength' => 128, + '#maxlength' => 128, '#required' => FALSE, ); $form['autoassignrole_settings_user']['AUTOASSIGNROLE_ROLE_USER_TITLE'] = array( '#type' => 'textfield', '#title' => t('User Role Title'), '#description' => t('The title of the field that contains the role options the end user sees during registration.'), - '#default_value' => variable_get('AUTOASSIGNROLE_ROLE_USER_TITLE',""), + '#default_value' => variable_get('AUTOASSIGNROLE_ROLE_USER_TITLE', AUTOASSIGNROLE_ROLE_USER_TITLE), '#size' => 60, - '#maxlength' => 128, + '#maxlength' => 128, '#required' => FALSE, ); $form['autoassignrole_settings_user']['AUTOASSIGNROLE_ROLE_USER_DESCRIPTION'] = array( '#type' => 'textarea', '#title' => t('User Role Description'), '#description' => t('The description displayed to the end user when they are selecting thier role during registration.'), - '#default_value' => variable_get('AUTOASSIGNROLE_ROLE_USER_DESCRIPTION',""), + '#default_value' => variable_get('AUTOASSIGNROLE_ROLE_USER_DESCRIPTION', AUTOASSIGNROLE_ROLE_USER_DESCRIPTION), '#required' => FALSE, ); return system_settings_form($form); @@ -130,83 +132,87 @@ function autoassignrole_perm() { function autoassignrole_user($type, &$edit, &$user, $category = NULL) { switch ($type) { case 'insert': - if(variable_get('AUTOASSIGNROLE_ROLE_ACTIVE','0') == 1) { - $roles = variable_get('AUTOASSIGNROLE_ROLE','0'); - if(is_array($roles)) { - $sql = 'INSERT INTO {users_roles} (uid, rid) values (%d, %d)'; - foreach($roles as $key => $value) { - if($value > 0) { + if (variable_get('AUTOASSIGNROLE_ROLE_ACTIVE', AUTOASSIGNROLE_ROLE_ACTIVE) == 1) { + $roles = variable_get('AUTOASSIGNROLE_ROLE', AUTOASSIGNROLE_ROLE); + if (is_array($roles)) { + $sql = 'INSERT INTO {users_roles} (uid, rid) VALUES (%d, %d)'; + foreach ($roles as $key => $value) { + if ($value > 0) { db_query($sql, $user->uid, $value); } } } } - if(variable_get('AUTOASSIGNROLE_ROLE_USER_ACTIVE','0') == 1) { - $sql = 'INSERT INTO {users_roles} (uid, rid) values (%d, %d)'; - if(is_array($edit['AUTOASSIGNROLE_ROLE_USER'])) { - foreach($edit['AUTOASSIGNROLE_ROLE_USER'] as $key => $value) { - if($value > 0) { + if (variable_get('AUTOASSIGNROLE_ROLE_USER_ACTIVE', AUTOASSIGNROLE_ROLE_USER_ACTIVE) == 1) { + $sql = 'INSERT INTO {users_roles} (uid, rid) VALUES (%d, %d)'; + if (is_array($edit['AUTOASSIGNROLE_ROLE_USER'])) { + foreach ($edit['AUTOASSIGNROLE_ROLE_USER'] as $key => $value) { + if ($value > 0) { db_query($sql, $user->uid, $value); } } - } else { + } + else { db_query($sql, $user->uid, $edit['AUTOASSIGNROLE_ROLE_USER']); } } - break; + break; } } function autoassignrole_form_alter($form_id, &$form) { - if ($form_id == "user_register" && variable_get('AUTOASSIGNROLE_ROLE_USER_ACTIVE','0') == 1) { + if ($form_id == 'user_register' && variable_get('AUTOASSIGNROLE_ROLE_USER_ACTIVE', AUTOASSIGNROLE_ROLE_USER_ACTIVE) == 1 && !user_access('administer access control')) { $form['autoassignrole_user'] = array( - '#type' => 'fieldset', - '#title' => variable_get('AUTOASSIGNROLE_ROLE_USER_FIELDSET','User Role Selection'), - '#collapsible' => FALSE, - '#collapsed' => FALSE, + '#type' => 'fieldset', + '#title' => variable_get('AUTOASSIGNROLE_ROLE_USER_FIELDSET', AUTOASSIGNROLE_ROLE_USER_FIELDSET), + '#collapsible' => FALSE, + '#collapsed' => FALSE, ); $form['autoassignrole_user']['AUTOASSIGNROLE_ROLE_USER'] = array( '#type' => _autoassignrole_user_input('type'), - '#title' => variable_get('AUTOASSIGNROLE_ROLE_USER_TITLE',""), + '#title' => variable_get('AUTOASSIGNROLE_ROLE_USER_TITLE', AUTOASSIGNROLE_ROLE_USER_TITLE), '#options' => _autoassignrole_intersect(), '#required' => _autoassignrole_user_input('required'), - '#description' => variable_get('AUTOASSIGNROLE_ROLE_USER_DESCRIPTION',""), + '#description' => variable_get('AUTOASSIGNROLE_ROLE_USER_DESCRIPTION', AUTOASSIGNROLE_ROLE_USER_DESCRIPTION), ); } } function _autoassignrole_user_input($args) { switch ($args) { case 'type': - if(variable_get('AUTOASSIGNROLE_ROLE_USER_MULTIPLE',0) == 0) { + if (variable_get('AUTOASSIGNROLE_ROLE_USER_MULTIPLE', AUTOASSIGNROLE_ROLE_USER_MULTIPLE) == 0) { $type = 'radios'; - } else { + } + else { $type = 'checkboxes'; } return $type; break; case 'required': - if(variable_get('AUTOASSIGNROLE_ROLE_USER_REQUIRED',0) == 0) { + if (variable_get('AUTOASSIGNROLE_ROLE_USER_REQUIRED', AUTOASSIGNROLE_ROLE_USER_REQUIRED) == 0) { $required = FALSE; - } else { + } + else { $required = TRUE; } return $required; break; - } + } } function _autoassignrole_intersect() { - $autoassignrole_roles = variable_get("AUTOASSIGNROLE_ROLE_USER",""); - foreach($autoassignrole_roles as $key => $value) { - if($value == 0) { + $autoassignrole_roles = variable_get('AUTOASSIGNROLE_ROLE_USER', AUTOASSIGNROLE_ROLE_USER); + foreach ($autoassignrole_roles as $key => $value) { + if ($value == 0) { unset($autoassignrole_roles[$key]); } } $result = _autoassignrole_array_intersect_key(user_roles(), $autoassignrole_roles); - if(variable_get("AUTOASSIGNROLE_ROLE_SORT", "SORT_ASC") == "SORT_ASC") { - array_multisort($result,SORT_ASC); - } else { - array_multisort($result,SORT_DESC); + if (variable_get('AUTOASSIGNROLE_ROLE_SORT', AUTOASSIGNROLE_ROLE_SORT) == 'SORT_ASC') { + asort($result); + } + else { + arsort($result); } return $result; } @@ -222,7 +228,8 @@ function _autoassignrole_array_intersect } } return $isec; - } else { + } + else { $res = array(); foreach (array_keys($isec) as $key) { if (isset($keys[$key])) {