<?php
class NF_Query_search extends CI_Input {
	function save_query($query_array) {
		
		if(!isset($CI))
			$CI =& get_instance();
		
		$user_id= $CI->session->userdata('user_id');
		$added_by_type = 'admin';
		$added_by_id =$user_id;//$sess['admin_id'];
		$module_id = $CI->session->userdata('session_current_module_id');
		$CI->db->insert('query_search', array('query_string' => http_build_query($query_array),'module_id' => $module_id,'added_by_type' => $added_by_type, 'added_by_id' => $added_by_id));
		$insert_id=$CI->db->insert_id();
		unset($CI);		
		return $insert_id;
	}
	
	function load_query($query_id) {
	//dumpEX($query_id);
		if(!isset($CI))
			$CI =& get_instance();
		$rows = $CI->db->get_where('query_search', array('query_search_id' => $query_id))->result();
		
		$new_array = array();
		if (isset($rows[0])) {
			parse_str($rows[0]->query_string, $new_array);		
		}
		if(is_array($new_array) && !empty($new_array)){
			foreach($new_array as $k=>$v){
				$_GET[str_replace('amp;','',$k)] = $v;
			}
		}
		unset($CI);		
	}
	
}
