You are here

function _restrict_by_ip_form in Restrict Login or Role Access by IP Address 6.2

Form and register function Insert the restrict by ip form into the user settings and new user forms for authorised users

1 call to _restrict_by_ip_form()
restrict_by_ip_user in ./restrict_by_ip.module
Implementation of hook_user()

File

./restrict_by_ip.module, line 246
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($uid) {
  global $user;

  //new code here
  if (user_access('administer site configuration') || user_access('administer restrict by ip')) {
    $form = array();
    drupal_add_css(drupal_get_path('module', 'restrict_by_ip') . '/restrict_by_ip.css', 'module', 'screen', FALSE);
    $usrdata_restrict_by_ip_type = "0";
    $usrdata_restrict_by_ip_address = "";

    // Grab the current restrict by ip data if it exists
    $found = db_result(db_query('SELECT count(*) FROM {restrict_by_ip} WHERE uid = %d', $uid));
    if ($found) {
      $usrdata = db_fetch_object(db_query('SELECT * FROM {restrict_by_ip} WHERE uid = %d', $uid));
      $usrdata_restrict_by_ip_type = "1";
      $usrdata_restrict_by_ip_address = $usrdata->restrict_by_ip_address;
    }
    $form['#multistep'] = TRUE;
    $form['#redirect'] = FALSE;
    $form['rip'] = array(
      '#type' => 'fieldset',
      '#attributes' => array(
        'class' => 'restrict-by-ip',
      ),
      '#title' => t('Restrict by IP settings'),
      '#weight' => 5,
      '#collapsible' => FALSE,
    );
    $form['rip']['restrict_by_ip_type'] = array(
      '#type' => 'radios',
      '#title' => t('Restrict By IP'),
      '#default_value' => t($usrdata_restrict_by_ip_type),
      '#options' => array(
        t('No'),
        t('Yes'),
      ),
    );
    $form['rip']['restrict_by_ip_address'] = array(
      '#type' => 'textfield',
      '#default_value' => t($usrdata_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>.'),
    );
    return $form;
  }
  else {
    return FALSE;
  }
}