You are here

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

Update and insert function Update or create new restrict by ip database entry from the form data

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

File

./restrict_by_ip.module, line 294
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_update($uid, &$edit) {
  if (user_access('administer site configuration') || user_access('administer restrict by ip')) {
    $form = array();
    if ($edit['restrict_by_ip_type']) {
      if (db_result(db_query('SELECT uid FROM {restrict_by_ip} WHERE uid = %d', $uid))) {
        db_query("UPDATE {restrict_by_ip} SET restrict_by_ip_type = %d, restrict_by_ip_address = '%s' WHERE uid = %d", intval($edit['restrict_by_ip_type']), $edit['restrict_by_ip_address'], $uid);
      }
      else {
        db_query("INSERT INTO {restrict_by_ip} (uid, restrict_by_ip_type, restrict_by_ip_address) VALUES ( %d ,%d ,'%s')", $uid, intval($edit['restrict_by_ip_type']), $edit['restrict_by_ip_address']);
      }
    }
    else {
      db_query("DELETE FROM {restrict_by_ip} WHERE uid=%d", $uid);

      // Attempting here to get the form to delete the ip address data if 'no' to restrict by ip address is selected
      // Not working needs more investigation
      if (isset($form['rip'])) {
        $form['newform'] = array(
          '#type' => 'textfield',
          '#default_value' => t(''),
          '#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['rip']['restrict_by_ip_address'] = $form['newform'];
        unset($form['newform']);
      }
    }
    unset($edit['restrict_by_ip_type']);
    unset($edit['restrict_by_ip_address']);
    return TRUE;
  }
  else {
    return FALSE;
  }
}