function restrict_by_ip_form_user_admin_perm_alter in Restrict Login or Role Access by IP Address 6.2
Hook to the admin_permissions form
File
- ./
restrict_by_ip.module, line 63 - Allows the admin to select which ip addresses role or a user can login from for this site Some of the code below is taken from the cck_ipaddress_module
Code
function restrict_by_ip_form_user_admin_perm_alter(&$form, $form_state) {
$rid = arg(3);
//check to make sure its a single role we are editing
//and that it is not a annonymous user or simply an "authenticated user"
//we could change this later?
if (isset($rid) && intval($rid) > 2) {
$roledata_restrict_by_ip_type = "0";
// Grab the current restrict by ip data if it exists
$found = db_result(db_query('SELECT count(*) FROM {restrict_by_ip} WHERE rid = %d', intval($rid)));
if ($found) {
$roledata = db_fetch_object(db_query('SELECT * FROM {restrict_by_ip} WHERE rid = %d', intval($rid)));
$roledata_restrict_by_ip_type = "1";
$roledata_restrict_by_ip_address = $roledata->restrict_by_ip_address;
}
$form['rip'] = array(
'#type' => 'fieldset',
'#attributes' => array(
'class' => 'restrict-by-ip',
),
'#title' => t('Restrict by IP settings'),
'#collapsible' => FALSE,
);
$form['rip']['rid'] = array(
'#type' => 'value',
'#value' => $rid,
);
$form['rip']['restrict_by_ip_type'] = array(
'#type' => 'radios',
'#title' => t('Restrict By IP'),
'#default_value' => $roledata_restrict_by_ip_type,
'#options' => array(
t('No'),
t('Yes'),
),
);
$form['rip']['restrict_by_ip_address'] = array(
'#type' => 'textfield',
'#default_value' => $roledata_restrict_by_ip_address,
'#size' => 128,
'#maxlength' => 128,
'#description' => t('Enter IP Address Ranges in CIDR Notation seperated with semi-colons, with no trailing semi-colon. E.G. 10.20.30.0/24;192.168.199.1/32;1.0.0.0/8<br />For more information on CIDR notation <a href="http://www.brassy.net/2007/mar/cidr_basic_subnetting" target="_blank">click here</a>.'),
);
$form['#submit'] = array(
'restrict_by_ip_user_admin_perm_submit',
'user_admin_perm_submit',
);
$form['#validate'] = array(
'restrict_by_ip_user_admin_perm_validate',
);
//unset the submit just so we can add the button again
//this way restrict ip does not show up at bottom of page
//I do not know any other way to do this?
unset($form['submit']);
$form['submit'] = array(
'#type' => 'submit',
'#value' => 'Save Permissions',
);
}
}