function get_records($filters = array()) { $result = array(); $this->db->flush_cache(); $this->db->from('guest_ip_address_ranges'); $this->db->join('clients', 'clients.client_id = guest_ip_address_ranges.client_id', 'inner'); $filter_values = array('select' => '*', 'where' => array('guest_ip_address_range_id' => 'guest_ip_address_ranges.guest_ip_address_range_id', 'client_id' => 'guest_ip_address_ranges.client_id'), 'order_by' => 'guest_ip_address_ranges.guest_ip_address_range_id', 'order_direction' => 'asc'); $this->generate_query($filter_values, $filters, $this->table_name); if (isset($filters['ip_address']) && !empty($filters['ip_address'])) { $this->db->where('guest_ip_address_ranges.start_ip_address <= ' . ip_to_long($filters['ip_address']) . ' ' . 'and guest_ip_address_ranges.end_ip_address >= ' . ip_to_long($filters['ip_address']), '', false); } $query = $this->db->get(); $result = $query->result_array(); return $result; }
function client() { $this->_secure(); $user = $this->session->all_userdata(); $this->load->model('model_clients'); $this->load->model('model_users'); $this->load->model('model_guest_ip_address_ranges'); $this->load->library('form_validation'); $this->form_validation->set_rules('data[client_id]', 'client id', 'trim|required|xss_clean'); $this->form_validation->set_rules('data[client_name]', 'client name', 'trim|required|xss_clean'); $this->form_validation->set_rules('data[client_site_title]', 'site title', 'trim|xss_clean'); $this->form_validation->set_rules('data[allow_guest_by_ip_flag]', 'allow guest by IP', 'trim|required|xss_clean'); // $this->form_validation->set_rules('data[guest_email_domains]','guest email domains','trim|xss_clean'); $this->form_validation->set_rules('data[default_order_by_attribute_index]', 'default order by', 'trim|xss_clean'); $this->form_validation->set_rules('data[default_order_by_direction]', 'default order by direction', 'trim|xss_clean'); $this->form_validation->set_rules('data[client_logo_file]', 'logo', 'trim|xss_clean'); $this->form_validation->set_rules('data[client_theme_id]', 'theme', 'trim|xss_clean'); $this->form_validation->set_error_delimiters('<div><div class="error"><span>', '</span></div></div>'); if ($this->form_validation->run() == false) { $client = $this->model_clients->get_records(array('client_id' => $user['client_id'])); $data = array(); $data['data'] = $client[0]; $data['guest_ip_address_ranges'] = $this->model_guest_ip_address_ranges->get_records(array('client_id' => $user['client_id'])); $data['javascripts'] = array('/javascript/admin_account_control'); $data['action_view'] = 'users/admin/client'; $this->load->view('layouts/default/default', $data); } else { $post_data = $this->input->post('data'); // Pick up any existing guest users for this client (should only be 1) $guest_users = $this->model_users->get_records(array('client_id' => $user['client_id'], 'user_guest_flag' => '1')); $this->model_guest_ip_address_ranges->delete(array('client_id' => $user['client_id'])); if (isset($post_data['allow_guest_by_ip_flag']) && $post_data['allow_guest_by_ip_flag'] == '1') { if (!empty($post_data['guest_ip_address_range_id']) && !empty($post_data['start_ip_address']) && !empty($post_data['end_ip_address'])) { for ($i = 0; $i < sizeof($post_data['guest_ip_address_range_id']); $i++) { $guest_ip_address_range = array(); $guest_ip_address_range['client_id'] = $user['client_id']; $guest_ip_address_range['start_ip_address'] = ip_to_long($post_data['start_ip_address'][$i]); $guest_ip_address_range['end_ip_address'] = ip_to_long($post_data['end_ip_address'][$i]); $this->model_guest_ip_address_ranges->save($guest_ip_address_range); } } $guest_user = array(); $guest_user['user_first_name'] = $post_data['client_name'] . ' Visitor'; if (empty($guest_users)) { $guest_user['client_id'] = $user['client_id']; $guest_user['user_guest_flag'] = '1'; $guest_user['user_security_level'] = '5'; } else { $guest_user['user_id'] = $guest_users[0]['user_id']; } $this->model_users->save($guest_user); } else { $this->model_users->delete(array('client_id' => $user['client_id'], 'user_guest_flag' => '1'), false); } if (isset($post_data['client_logo_remove']) && $post_data['client_logo_remove'] == '1') { $post_data['client_logo'] = ''; } else { if (isset($_FILES['userfile']) && !empty($_FILES['userfile']) && isset($_FILES['userfile']['name']) && !empty($_FILES['userfile']['name'])) { $upload_result = $this->do_upload_logo(); if (isset($upload_result['error_message'])) { $this->session->set_flashdata('flash_error', $upload_result['error_message']); redirect('/users/admin/client'); } else { if (!empty($upload_result['upload_data'])) { if (file_exists($upload_result['upload_data']['full_path'])) { $post_data['client_logo'] = $upload_result['upload_data']['full_path']; } } } } } $client = $this->model_clients->save($post_data); $this->session->set_flashdata('flash_message', 'Your changes have been saved.'); redirect('/users/admin/client'); } }