2011-06-17 12:52:00 +00:00
|
|
|
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
|
|
|
|
|
|
|
class Search extends CI_Controller {
|
|
|
|
|
2019-09-04 22:12:45 +00:00
|
|
|
|
|
|
|
function __construct()
|
|
|
|
{
|
|
|
|
parent::__construct();
|
|
|
|
|
|
|
|
$this->load->helper(array('form', 'url'));
|
2021-02-09 17:52:23 +00:00
|
|
|
if($this->optionslib->get_option('global_search') != "true") {
|
2019-09-11 16:35:31 +00:00
|
|
|
$this->load->model('user_model');
|
|
|
|
if(!$this->user_model->authorize(2)) { $this->session->set_flashdata('notice', 'You\'re not allowed to do that!'); redirect('dashboard'); }
|
|
|
|
}
|
2019-09-04 22:12:45 +00:00
|
|
|
}
|
|
|
|
|
2011-06-17 12:52:00 +00:00
|
|
|
public function index()
|
|
|
|
{
|
2011-11-04 17:32:03 +00:00
|
|
|
$data['page_title'] = "Search";
|
|
|
|
|
2019-05-14 10:52:11 +00:00
|
|
|
$this->load->view('interface_assets/header', $data);
|
2011-06-17 12:52:00 +00:00
|
|
|
$this->load->view('search/main');
|
2019-05-14 10:52:11 +00:00
|
|
|
$this->load->view('interface_assets/footer');
|
2011-06-17 12:52:00 +00:00
|
|
|
}
|
2019-09-04 22:12:45 +00:00
|
|
|
|
|
|
|
// Filter is for advanced searching and filtering of the logbook
|
|
|
|
public function filter() {
|
|
|
|
$data['page_title'] = "Search & Filter Logbook";
|
|
|
|
|
|
|
|
$this->load->library('form_validation');
|
|
|
|
|
2019-09-04 22:42:11 +00:00
|
|
|
$this->load->model('Search_filter');
|
|
|
|
|
|
|
|
$data['get_table_names'] = $this->Search_filter->get_table_columns();
|
2021-09-25 15:40:15 +00:00
|
|
|
$data['stored_queries'] = $this->Search_filter->get_stored_queries();
|
2019-09-04 22:42:11 +00:00
|
|
|
|
|
|
|
//print_r($this->Search_filter->get_table_columns());
|
|
|
|
|
2019-09-04 22:12:45 +00:00
|
|
|
if ($this->form_validation->run() == FALSE)
|
|
|
|
{
|
|
|
|
$this->load->view('interface_assets/header', $data);
|
|
|
|
$this->load->view('search/filter');
|
|
|
|
$this->load->view('interface_assets/footer');
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$this->load->view('interface_assets/header', $data);
|
|
|
|
$this->load->view('search/filter');
|
|
|
|
$this->load->view('interface_assets/footer');
|
|
|
|
}
|
|
|
|
}
|
2019-09-11 23:53:39 +00:00
|
|
|
|
|
|
|
function json_result() {
|
|
|
|
if(isset($_POST['search'])) {
|
2021-09-25 15:40:15 +00:00
|
|
|
$result = $this->fetchQueryResult($_POST['search'], false);
|
2021-09-23 18:18:47 +00:00
|
|
|
echo json_encode($result->result_array());
|
2021-09-25 16:08:31 +00:00
|
|
|
}
|
2021-09-23 18:18:47 +00:00
|
|
|
}
|
|
|
|
|
2021-09-25 15:40:15 +00:00
|
|
|
function get_stored_queries() {
|
|
|
|
$this->load->model('Search_filter');
|
|
|
|
$data['result'] = $this->Search_filter->get_stored_queries();
|
|
|
|
$this->load->view('search/stored_queries', $data);
|
|
|
|
}
|
|
|
|
|
|
|
|
function search_result() {
|
|
|
|
if(isset($_POST['search'])) {
|
|
|
|
$data['results'] = $this->fetchQueryResult($_POST['search'], false);
|
|
|
|
$this->load->view('search/search_result_ajax', $data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-23 18:18:47 +00:00
|
|
|
function export_to_adif() {
|
|
|
|
if(isset($_POST['search'])) {
|
2021-09-25 15:40:15 +00:00
|
|
|
$data['qsos'] = $this->fetchQueryResult($_POST['search'], false);
|
2021-09-23 18:18:47 +00:00
|
|
|
$this->load->view('adif/data/exportall', $data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-25 15:40:15 +00:00
|
|
|
function export_stored_query_to_adif() {
|
|
|
|
$this->db->where('id', xss_clean($this->input->post('id')));
|
|
|
|
$sql = $this->db->get('queries')->result();
|
|
|
|
|
|
|
|
$data['qsos'] = $this->db->query($sql[0]->query);
|
|
|
|
$this->load->view('adif/data/exportall', $data);
|
|
|
|
}
|
|
|
|
|
|
|
|
function run_query() {
|
|
|
|
$this->db->where('id', xss_clean($this->input->post('id')));
|
|
|
|
$sql = $this->db->get('queries')->result();
|
2021-09-25 17:49:28 +00:00
|
|
|
$sql = $sql[0]->query;
|
2021-09-25 15:40:15 +00:00
|
|
|
|
2021-09-25 17:49:28 +00:00
|
|
|
if (stristr($sql, 'select', ) && !stristr($sql, 'delete') && !stristr($sql, 'update')) {
|
|
|
|
$data['results'] = $this->db->query($sql);
|
2021-09-25 15:40:15 +00:00
|
|
|
|
2021-09-25 17:49:28 +00:00
|
|
|
$this->load->view('search/search_result_ajax', $data);
|
|
|
|
}
|
2021-09-25 15:40:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function save_query() {
|
|
|
|
if(isset($_POST['search'])) {
|
|
|
|
$query = $this->fetchQueryResult($_POST['search'], true);
|
|
|
|
|
|
|
|
$data = array(
|
|
|
|
'userid' => xss_clean($this->session->userdata('user_id')),
|
|
|
|
'query' => $query,
|
|
|
|
'description' => xss_clean($_POST['description'])
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->db->insert('queries', $data);
|
2021-09-25 16:08:31 +00:00
|
|
|
$last_id = $this->db->insert_id();
|
|
|
|
header('Content-Type: application/json');
|
|
|
|
echo json_encode(array('id' => $last_id, 'description' => xss_clean($_POST['description'])));
|
2021-09-25 15:40:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function delete_query() {
|
|
|
|
$id = xss_clean($this->input->post('id'));
|
|
|
|
$this->load->model('search_filter');
|
|
|
|
$this->search_filter->delete_query($id);
|
|
|
|
}
|
|
|
|
|
|
|
|
function edit_query() {
|
|
|
|
$data = array(
|
|
|
|
'cat' => xss_clean($this->input->post('category')),
|
|
|
|
'title' => xss_clean($this->input->post('title')),
|
|
|
|
'note' => xss_clean($this->input->post('content'))
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->db->where('id', xss_clean($this->input->post('id')));
|
|
|
|
$this->db->update('notes', $data);
|
|
|
|
}
|
|
|
|
|
|
|
|
function fetchQueryResult($json, $returnquery) {
|
2021-09-23 18:18:47 +00:00
|
|
|
|
|
|
|
$search_items = json_decode($json, true);
|
|
|
|
|
|
|
|
$search_type = "";
|
|
|
|
|
|
|
|
foreach($search_items as $key=>$value){
|
|
|
|
|
|
|
|
|
|
|
|
if($value == "AND") {
|
|
|
|
$search_type = "AND";
|
|
|
|
}
|
|
|
|
if ($value == "OR") {
|
|
|
|
$search_type = "OR";
|
|
|
|
}
|
|
|
|
|
|
|
|
if(is_array($value)) {
|
|
|
|
foreach($value as $values)
|
|
|
|
{
|
|
|
|
|
|
|
|
if(isset($values['rules'])) {
|
|
|
|
if($values['condition'] == "AND") {
|
|
|
|
$this->db->group_start();
|
|
|
|
} else {
|
|
|
|
$this->db->or_group_start();
|
|
|
|
}
|
|
|
|
foreach($values['rules'] as $group_value)
|
|
|
|
{
|
|
|
|
if($group_value['operator'] == "equal") {
|
|
|
|
if($values['condition'] == "AND") {
|
|
|
|
$this->db->where($group_value['field'], $group_value['value']);
|
2019-10-09 16:57:55 +00:00
|
|
|
} else {
|
2021-09-23 18:18:47 +00:00
|
|
|
$this->db->or_where($group_value['field'], $group_value['value']);
|
2019-10-09 16:57:55 +00:00
|
|
|
}
|
|
|
|
}
|
2021-09-23 18:18:47 +00:00
|
|
|
|
|
|
|
if($group_value['operator'] == "not_equal") {
|
|
|
|
if($values['condition'] == "AND") {
|
|
|
|
$this->db->where($group_value['field'].' !=', $group_value['value']);
|
2019-10-09 16:57:55 +00:00
|
|
|
} else {
|
2021-09-23 18:18:47 +00:00
|
|
|
$this->db->or_where($group_value['field'].' !=', $group_value['value']);
|
2019-10-09 16:57:55 +00:00
|
|
|
}
|
|
|
|
}
|
2021-09-23 18:18:47 +00:00
|
|
|
|
|
|
|
if($group_value['operator'] == "begins_with") {
|
|
|
|
if($values['condition'] == "AND") {
|
|
|
|
$this->db->where($group_value['field'].' like ', $group_value['value']."%");
|
2019-10-09 16:57:55 +00:00
|
|
|
} else {
|
2021-09-23 18:18:47 +00:00
|
|
|
$this->db->or_where($group_value['field'].' like ', $group_value['value']."%");
|
2019-10-09 16:57:55 +00:00
|
|
|
}
|
|
|
|
}
|
2021-09-23 18:18:47 +00:00
|
|
|
|
|
|
|
if($group_value['operator'] == "contains") {
|
|
|
|
if($values['condition'] == "AND") {
|
|
|
|
$this->db->where($group_value['field'].' like ', "%".$group_value['value']."%");
|
2019-10-09 16:57:55 +00:00
|
|
|
} else {
|
2021-09-23 18:18:47 +00:00
|
|
|
$this->db->or_where($group_value['field'].' like ', "%".$group_value['value']."%");
|
2019-10-09 16:57:55 +00:00
|
|
|
}
|
|
|
|
}
|
2021-09-23 18:18:47 +00:00
|
|
|
|
|
|
|
if($group_value['operator'] == "ends_with") {
|
|
|
|
if($values['condition'] == "AND") {
|
|
|
|
$this->db->where($group_value['field'].' like ', "%".$group_value['value']);
|
2019-10-09 16:57:55 +00:00
|
|
|
} else {
|
2021-09-23 18:18:47 +00:00
|
|
|
$this->db->or_where($group_value['field'].' like ', "%".$group_value['value']);
|
2019-10-09 16:57:55 +00:00
|
|
|
}
|
|
|
|
}
|
2021-09-23 18:18:47 +00:00
|
|
|
|
|
|
|
if($group_value['operator'] == "is_empty") {
|
|
|
|
if($values['condition'] == "AND") {
|
|
|
|
$this->db->where($group_value['field'], "''");
|
2019-10-09 16:57:55 +00:00
|
|
|
} else {
|
2021-09-23 18:18:47 +00:00
|
|
|
$this->db->or_where($group_value['field'], "''");
|
2019-10-09 16:57:55 +00:00
|
|
|
}
|
|
|
|
}
|
2021-09-23 18:18:47 +00:00
|
|
|
|
|
|
|
if($group_value['operator'] == "is_not_empty") {
|
|
|
|
if($values['condition'] == "AND") {
|
|
|
|
$this->db->where($group_value['field'].' !=', "''");
|
2019-10-09 16:57:55 +00:00
|
|
|
} else {
|
2021-09-23 18:18:47 +00:00
|
|
|
$this->db->or_where($group_value['field'].' !=', "''");
|
2019-10-09 16:57:55 +00:00
|
|
|
}
|
|
|
|
}
|
2019-09-14 17:00:41 +00:00
|
|
|
|
2021-09-23 18:18:47 +00:00
|
|
|
if($group_value['operator'] == "is_null") {
|
|
|
|
if($values['condition'] == "AND") {
|
|
|
|
$this->db->where($group_value['field'].' is ', NULL);
|
|
|
|
} else {
|
|
|
|
$this->db->or_where($group_value['field'].' is ', NULL);
|
|
|
|
}
|
|
|
|
}
|
2019-09-11 23:53:39 +00:00
|
|
|
|
2021-09-23 18:18:47 +00:00
|
|
|
if($group_value['operator'] == "is_not_null") {
|
|
|
|
if($values['condition'] == "AND") {
|
|
|
|
$this->db->where($group_value['field'].' is not ', NULL);
|
|
|
|
} else {
|
|
|
|
$this->db->or_where($group_value['field'].' is not ', NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if($group_value['operator'] == "less") {
|
|
|
|
if($values['condition'] == "AND") {
|
|
|
|
$this->db->where($group_value['field'].' <', $group_value['value']);
|
|
|
|
} else {
|
|
|
|
$this->db->or_where($group_value['field'].' <', $group_value['value']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if($group_value['operator'] == "less_or_equal") {
|
|
|
|
if($values['condition'] == "AND") {
|
|
|
|
$this->db->where($group_value['field'].' <=', $group_value['value']);
|
|
|
|
} else {
|
|
|
|
$this->db->or_where($group_value['field'].' <=', $group_value['value']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if($group_value['operator'] == "greater") {
|
|
|
|
if($values['condition'] == "AND") {
|
|
|
|
$this->db->where($group_value['field'].' >', $group_value['value']);
|
|
|
|
} else {
|
|
|
|
$this->db->or_where($group_value['field'].' >', $group_value['value']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if($group_value['operator'] == "greater_or_equal") {
|
|
|
|
if($values['condition'] == "AND") {
|
|
|
|
$this->db->where($group_value['field'].' >=', $group_value['value']);
|
|
|
|
} else {
|
|
|
|
$this->db->or_where($group_value['field'].' >=', $group_value['value']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
$this->db->group_end();
|
|
|
|
} else {
|
|
|
|
//print_r($values['field']);
|
|
|
|
if(isset($values['operator'])) {
|
|
|
|
|
|
|
|
}
|
|
|
|
if($values['operator'] == "equal") {
|
|
|
|
if($search_type == "AND") {
|
|
|
|
$this->db->where($values['field'], $values['value']);
|
|
|
|
} else {
|
|
|
|
$this->db->or_where($values['field'], $values['value']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if($values['operator'] == "not_equal") {
|
|
|
|
if($search_type == "AND") {
|
|
|
|
$this->db->where($values['field'].' !=', $values['value']);
|
|
|
|
} else {
|
|
|
|
$this->db->or_where($values['field'].' !=', $values['value']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if($values['operator'] == "begins_with") {
|
|
|
|
if($search_type == "AND") {
|
|
|
|
$this->db->where($values['field'].' like ', $values['value']."%");
|
|
|
|
} else {
|
|
|
|
$this->db->or_where($values['field'].' like ', $values['value']."%");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if($values['operator'] == "contains") {
|
|
|
|
if($search_type == "AND") {
|
|
|
|
$this->db->where($values['field'].' like ', "%".$values['value']."%");
|
|
|
|
} else {
|
|
|
|
$this->db->or_where($values['field'].' like ', "%".$values['value']."%");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if($values['operator'] == "ends_with") {
|
|
|
|
if($search_type == "AND") {
|
|
|
|
$this->db->where($values['field'].' like ', "%".$values['value']);
|
|
|
|
} else {
|
|
|
|
$this->db->or_where($values['field'].' like ', "%".$values['value']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if($values['operator'] == "is_empty") {
|
|
|
|
if($search_type == "AND") {
|
|
|
|
$this->db->where($values['field'], "");
|
|
|
|
} else {
|
|
|
|
$this->db->or_where($values['field'], "");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if($values['operator'] == "is_not_empty") {
|
|
|
|
if($search_type == "AND") {
|
|
|
|
$this->db->where($values['field'].' !=', "");
|
|
|
|
} else {
|
|
|
|
$this->db->or_where($values['field'].' !=', "");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if($values['operator'] == "is_null") {
|
|
|
|
if($search_type == "AND") {
|
|
|
|
$this->db->where($values['field'].' is ', NULL);
|
|
|
|
} else {
|
|
|
|
$this->db->or_where($values['field'].' is ', NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if($values['operator'] == "is_not_null") {
|
|
|
|
if($search_type == "AND") {
|
|
|
|
$this->db->where($values['field'].' is not ', NULL);
|
|
|
|
} else {
|
|
|
|
$this->db->or_where($values['field'].' is not ', NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if($values['operator'] == "less") {
|
|
|
|
if($search_type == "AND") {
|
|
|
|
$this->db->where($values['field'].' <', $values['value']);
|
|
|
|
} else {
|
|
|
|
$this->db->or_where($values['field'].' <', $values['value']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if($values['operator'] == "less_or_equal") {
|
|
|
|
if($search_type == "AND") {
|
|
|
|
$this->db->where($values['field'].' <=', $values['value']);
|
|
|
|
} else {
|
|
|
|
$this->db->or_where($values['field'].' <=', $values['value']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if($values['operator'] == "greater") {
|
|
|
|
if($search_type == "AND") {
|
|
|
|
$this->db->where($values['field'].' >', $values['value']);
|
|
|
|
} else {
|
|
|
|
$this->db->or_where($values['field'].' >', $values['value']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if($values['operator'] == "greater_or_equal") {
|
|
|
|
if($search_type == "AND") {
|
|
|
|
$this->db->where($values['field'].' >=', $values['value']);
|
|
|
|
} else {
|
|
|
|
$this->db->or_where($values['field'].' >=', $values['value']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-09-25 15:40:15 +00:00
|
|
|
|
2021-09-23 18:18:47 +00:00
|
|
|
$this->db->order_by('COL_TIME_ON', 'DESC');
|
|
|
|
$this->db->join('station_profile', 'station_profile.station_id = '.$this->config->item('table_name').'.station_id');
|
2021-09-25 15:40:15 +00:00
|
|
|
|
|
|
|
if ($returnquery) {
|
|
|
|
$query = $this->db->get_compiled_select($this->config->item('table_name'));
|
|
|
|
} else {
|
|
|
|
$query = $this->db->get($this->config->item('table_name'));
|
|
|
|
}
|
2021-09-23 18:18:47 +00:00
|
|
|
return $query;
|
|
|
|
}
|
2011-08-19 17:24:56 +00:00
|
|
|
}
|