lang->load(array(
			'contesting',
			'qslcard',
			'lotw',
			'eqsl',
			'qso'
		));
	}
	function index()
	{
		// Check if users logged in
		$this->load->model('user_model');
		if($this->user_model->validate_session() == 0) {
			// user is not logged in
			redirect('user/login');
		}
		$this->load->model('stations');
		// If environment is set to development then show the debug toolbar
		if(ENVIRONMENT == 'development') {
            $this->output->enable_profiler(TRUE);
        }
		$this->load->model('logbook_model');
		$this->load->library('pagination');
		$config['base_url'] = base_url().'index.php/logbook/index/';
		$config['total_rows'] = $this->logbook_model->total_qsos();
		$config['per_page'] = '25';
		$config['num_links'] = 6;
		$config['full_tag_open'] = '';
		$config['full_tag_close'] = '';
		$config['cur_tag_open'] = '';
		$config['cur_tag_close'] = '';
		$this->pagination->initialize($config);
		//load the model and get results
		$data['results'] = $this->logbook_model->get_qsos($config['per_page'],$this->uri->segment(3));
		if(!$data['results']) {
			$this->session->set_flashdata('notice', lang('error_no_logbook_found') . ' Station Logbooks');
		}
		// Calculate Lat/Lng from Locator to use on Maps
		if($this->session->userdata('user_locator')) {
				$this->load->library('qra');
				$qra_position = $this->qra->qra2latlong($this->session->userdata('user_locator'));
				if (isset($qra_position[0]) and isset($qra_position[1])) {
					$data['qra'] = "set";
					$data['qra_lat'] = $qra_position[0];
					$data['qra_lng'] = $qra_position[1];
				} else {
					$data['qra'] = "none";
				}
		} else {
				$data['qra'] = "none";
		}
		// load the view
		$data['page_title'] = "Logbook";
		$this->load->view('interface_assets/header', $data);
		$this->load->view('view_log/index');
		$this->load->view('interface_assets/footer');
	}
	function jsonentity($adif) {
        $this->load->model('user_model');
        if(!$this->user_model->authorize($this->config->item('auth_mode'))) { return; }
        $return['dxcc'] = $this->getentity($adif);
        header('Content-Type: application/json');
        echo json_encode($return, JSON_PRETTY_PRINT);
    }
	function json($tempcallsign, $temptype, $tempband, $tempmode, $tempstation_id = null)
	{
		// Cleaning for security purposes
		$callsign = $this->security->xss_clean($tempcallsign);
		$type = $this->security->xss_clean($temptype);
		$band = $this->security->xss_clean($tempband);
		$mode = $this->security->xss_clean($tempmode);
		$station_id = $this->security->xss_clean($tempstation_id);
		$this->load->model('user_model');
		if(!$this->user_model->authorize($this->config->item('auth_mode'))) { return; }
		// Convert - in Callsign to / Used for URL processing
		$callsign = str_replace("-","/",$callsign);
		$callsign = str_replace("Ø","0",$callsign);
		// Check if callsign is an LoTW User
		// Check Database for all other data
		$this->load->model('logbook_model');
		$lotw_days=$this->logbook_model->check_last_lotw($callsign);
		if ($lotw_days != null) {
			$lotw_member="active";
		} else {
			$lotw_member="not found";
		}
		$return = [
			"callsign" => strtoupper($callsign),
			"dxcc" => false,
			"callsign_name" => "",
			"callsign_qra"  => "",
			"callsign_distance"  => 0,
			"callsign_qth"  => "",
			"callsign_iota" => "",
			"callsign_state" => "",
			"callsign_us_county" => "",
			"qsl_manager" => "",
			"bearing" 		=> "",
			"workedBefore" => false,
			"lotw_member" => $lotw_member,
			"lotw_days" => $lotw_days,
			"image" => "",
		];
		$return['dxcc'] = $this->dxcheck($callsign);
		$split_callsign=explode('/',$callsign);
		if (isset($split_callsign[1]) && ($split_callsign[1] != "")) {	// Do we have "/" in Call?
			if (strlen($split_callsign[1])>3) {			// Last Element longer than 3 chars? Take that as call
				$lookupcall = $split_callsign[1];
			} else {						// Last Element up to 3 Chars? Take first element as Call
				$lookupcall = $split_callsign[0];
			}
		} else {
			$lookupcall=$callsign;
		}
		$return['partial'] = $this->partial($lookupcall);
		$callbook = $this->logbook_model->loadCallBook($callsign, $this->config->item('use_fullname'));
		if ($this->session->userdata('user_measurement_base') == NULL) {
			$measurement_base = $this->config->item('measurement_base');
		} else {
			$measurement_base = $this->session->userdata('user_measurement_base');
		}
		$return['callsign_name'] 		= $this->nval($callbook['name'] ?? '', $this->logbook_model->call_name($callsign));
		$return['callsign_qra'] 		= $this->nval($callbook['gridsquare'] ?? '',  $this->logbook_model->call_qra($callsign));
		$return['callsign_distance'] 	= $this->distance($return['callsign_qra']);
		$return['callsign_qth'] 		= $this->nval($callbook['city'] ?? '', $this->logbook_model->call_qth($callsign));
		$return['callsign_iota'] 		= $this->nval($callbook['iota'] ?? '', $this->logbook_model->call_iota($callsign));
		$return['qsl_manager'] 			= $this->nval($callbook['qslmgr'] ?? '', $this->logbook_model->call_qslvia($callsign));
		$return['callsign_state'] 		= $this->nval($callbook['state'] ?? '', $this->logbook_model->call_state($callsign));
		$return['callsign_us_county'] 	= $this->nval($callbook['us_county'] ?? '', $this->logbook_model->call_us_county($callsign));
		$return['workedBefore'] 		= $this->worked_grid_before($return['callsign_qra'], $type, $band, $mode);
		$return['confirmed'] 		= $this->confirmed_grid_before($return['callsign_qra'], $type, $band, $mode);
		if ($this->session->userdata('user_show_profile_image')) {
			if (isset($callbook) && isset($callbook['image'])) {
				if ($callbook['image'] == "") {
					$return['image'] = "n/a";
				} else {
					$return['image'] = $callbook['image'];
				}
			} else {
				$return['image'] = "n/a";
			}
		}
		if ($return['callsign_qra'] != "") {
			$return['latlng'] = $this->qralatlng($return['callsign_qra']);
			$return['bearing'] = $this->bearing($return['callsign_qra'], $measurement_base, $station_id);
		}
		echo json_encode($return, JSON_PRETTY_PRINT);
		return;
	}
	// Returns $val2 first if it has value, even if it is null or empty string, if not return $val1.
	function nval($val1, $val2) {
		return (($val2 ?? "") === "" ? ($val1 ?? "") : ($val2 ?? ""));
	}
	function confirmed_grid_before($gridsquare, $type, $band, $mode) {
		if (strlen($gridsquare) < 4)
			return false;
		$CI =& get_instance();
		$CI->load->model('logbooks_model');
		$logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook'));
		$user_default_confirmation = $this->session->userdata('user_default_confirmation');
		if(!empty($logbooks_locations_array)) {
			$extrawhere='';
			if (isset($user_default_confirmation) && strpos($user_default_confirmation, 'Q') !== false) {
				$extrawhere="COL_QSL_RCVD='Y'"; 
			}
			if (isset($user_default_confirmation) && strpos($user_default_confirmation, 'L') !== false) {
				if ($extrawhere!='') {
					$extrawhere.=" OR";
				}
				$extrawhere.=" COL_LOTW_QSL_RCVD='Y'";
			}
			if (isset($user_default_confirmation) && strpos($user_default_confirmation, 'E') !== false) {
				if ($extrawhere!='') {
					$extrawhere.=" OR";
				}
				$extrawhere.=" COL_EQSL_QSL_RCVD='Y'";
			}
			if($type == "SAT") {
				$this->db->where('COL_PROP_MODE', 'SAT');
				if ($extrawhere != '') {
					$this->db->where('('.$extrawhere.')');
				} else {
					$this->db->where("1=0");
				}
			} else {
				$CI->load->model('logbook_model');
				$this->db->where('COL_MODE', $CI->logbook_model->get_main_mode_from_mode($mode));
				$this->db->where('COL_BAND', $band);
				$this->db->where('COL_PROP_MODE !=','SAT');
				if ($extrawhere != '') {
					$this->db->where('('.$extrawhere.')');
				} else {
					$this->db->where("1=0");
				}
			}
			$this->db->where_in('station_id', $logbooks_locations_array);
			$this->db->like('SUBSTRING(COL_GRIDSQUARE, 1, 4)', substr($gridsquare, 0, 4));
			$this->db->order_by($this->config->item('table_name').".COL_TIME_ON", "desc");
			$this->db->limit(1);
			$query = $this->db->get($this->config->item('table_name'));
			foreach ($query->result() as $workedBeforeRow) {
				return true;
			}
		}
		return false;
	}
function worked_grid_before($gridsquare, $type, $band, $mode)
	{
		if (strlen($gridsquare) < 4)
			return false;
		$CI =& get_instance();
		$CI->load->model('logbooks_model');
		$logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook'));
		if(!empty($logbooks_locations_array)) {
			if($type == "SAT") {
				$this->db->where('COL_PROP_MODE', 'SAT');
			} else {
				$this->db->where('COL_MODE', $this->logbook_model->get_main_mode_from_mode($mode));
				$this->db->where('COL_BAND', $band);
				$this->db->where('COL_PROP_MODE !=','SAT');
			}
			$this->db->where_in('station_id', $logbooks_locations_array);
			$this->db->like('SUBSTRING(COL_GRIDSQUARE, 1, 4)', substr($gridsquare, 0, 4));
			$this->db->order_by($this->config->item('table_name').".COL_TIME_ON", "desc");
			$this->db->limit(1);
			$query = $this->db->get($this->config->item('table_name'));
			foreach ($query->result() as $workedBeforeRow)
			{
				return true;
			}
		}
		return false;
	}
	/*
	*	Function: jsonlookupgrid
	*
	* 	Usage: Used to look up gridsquares when creating a QSO to check whether its needed or not
	*	the $type variable is only used for satellites, set this to SAT.
	*
	*/
	function jsonlookupgrid($gridsquare, $type, $band, $mode) {
		$return = [
			"workedBefore" => false,
			"confirmed" => false,
		];
		$user_default_confirmation = $this->session->userdata('user_default_confirmation');
		$CI =& get_instance();
        $CI->load->model('logbooks_model');
        $logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook'));
		if($type == "SAT") {
			$this->db->where('COL_PROP_MODE', 'SAT');
		} else {
			$CI->load->model('logbook_model');
			$this->db->where('COL_MODE', $CI->logbook_model->get_main_mode_from_mode($mode));
			$this->db->where('COL_BAND', $band);
			$this->db->where('COL_PROP_MODE !=','SAT');
		}
		$this->db->where_in('station_id', $logbooks_locations_array);
		$this->db->like('SUBSTRING(COL_GRIDSQUARE, 1, 4)', substr($gridsquare, 0, 4));
		$query = $this->db->get($this->config->item('table_name'), 1, 0);
		foreach ($query->result() as $workedBeforeRow)
		{
			$return['workedBefore'] = true;
		}
		
		$extrawhere='';
		if (isset($user_default_confirmation) && strpos($user_default_confirmation, 'Q') !== false) {
			$extrawhere="COL_QSL_RCVD='Y'"; 
		}
		if (isset($user_default_confirmation) && strpos($user_default_confirmation, 'L') !== false) {
			if ($extrawhere!='') {
				$extrawhere.=" OR";
			}
			$extrawhere.=" COL_LOTW_QSL_RCVD='Y'";
		}
		if (isset($user_default_confirmation) && strpos($user_default_confirmation, 'E') !== false) {
			if ($extrawhere!='') {
				$extrawhere.=" OR";
			}
			$extrawhere.=" COL_EQSL_QSL_RCVD='Y'";
		}
		if($type == "SAT") {
			$this->db->where('COL_PROP_MODE', 'SAT');
			if ($extrawhere != '') {
				$this->db->where('('.$extrawhere.')');
			} else {
				$this->db->where("1=0");
			}
		} else {
			$CI->load->model('logbook_model');
			$this->db->where('COL_MODE', $CI->logbook_model->get_main_mode_from_mode($mode));
			$this->db->where('COL_BAND', $band);
			$this->db->where('COL_PROP_MODE !=','SAT');
			if ($extrawhere != '') {
				$this->db->where('('.$extrawhere.')');
			} else {
				$this->db->where("1=0");
			}
		}
		$this->db->where_in('station_id', $logbooks_locations_array);
		$this->db->like('SUBSTRING(COL_GRIDSQUARE, 1, 4)', substr($gridsquare, 0, 4));
		$query = $this->db->get($this->config->item('table_name'), 1, 0);
		foreach ($query->result() as $workedBeforeRow) {
			$return['confirmed']=true;
		}
		header('Content-Type: application/json');
		echo json_encode($return, JSON_PRETTY_PRINT);
		return;
	}
	function jsonlookupdxcc($country, $type, $band, $mode) {
		$return = [
			"workedBefore" => false,
			"confirmed" => false,
		];
		$user_default_confirmation = $this->session->userdata('user_default_confirmation');
		$CI =& get_instance();
		$CI->load->model('logbooks_model');
		$logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook'));
		$CI->load->model('logbook_model');
		if(!empty($logbooks_locations_array)) {
			if($type == "SAT") {
				$this->db->where('COL_PROP_MODE', 'SAT');
			} else {
				$this->db->where('COL_MODE', $this->logbook_model->get_main_mode_from_mode($mode));
				$this->db->where('COL_BAND', $band);
				$this->db->where('COL_PROP_MODE !=','SAT');
			}
			$this->db->where_in('station_id', $logbooks_locations_array);
			$this->db->where('COL_COUNTRY', urldecode($country));
			$query = $this->db->get($this->config->item('table_name'), 1, 0);
			foreach ($query->result() as $workedBeforeRow)
			{
				$return['workedBefore'] = true;
			}
			$extrawhere='';
			if (isset($user_default_confirmation) && strpos($user_default_confirmation, 'Q') !== false) {
				$extrawhere="COL_QSL_RCVD='Y'"; 
			}
			if (isset($user_default_confirmation) && strpos($user_default_confirmation, 'L') !== false) {
				if ($extrawhere!='') {
					$extrawhere.=" OR";
				}
				$extrawhere.=" COL_LOTW_QSL_RCVD='Y'";
			}
			if (isset($user_default_confirmation) && strpos($user_default_confirmation, 'E') !== false) {
				if ($extrawhere!='') {
					$extrawhere.=" OR";
				}
				$extrawhere.=" COL_EQSL_QSL_RCVD='Y'";
			}
			if($type == "SAT") {
				$this->db->where('COL_PROP_MODE', 'SAT');
				if ($extrawhere != '') {
					$this->db->where('('.$extrawhere.')');
				} else {
					$this->db->where("1=0");
				}
			} else {
				$CI->load->model('logbook_model');
				$this->db->where('COL_MODE', $CI->logbook_model->get_main_mode_from_mode($mode));
				$this->db->where('COL_BAND', $band);
				$this->db->where('COL_PROP_MODE !=','SAT');
				if ($extrawhere != '') {
					$this->db->where('('.$extrawhere.')');
				} else {
					$this->db->where("1=0");
				}
			}
			$this->db->where_in('station_id', $logbooks_locations_array);
			$this->db->where('COL_COUNTRY', urldecode($country));
			$query = $this->db->get($this->config->item('table_name'), 1, 0);
			foreach ($query->result() as $workedBeforeRow) {
				$return['confirmed']=true;
			}
			header('Content-Type: application/json');
			echo json_encode($return, JSON_PRETTY_PRINT);
			return;
		} else {
			$return['workedBefore'] = false;
			$return['confirmed'] = false;
			header('Content-Type: application/json');
			echo json_encode($return, JSON_PRETTY_PRINT);
			return;
		}
	}
	function jsonlookupcallsign($callsign, $type, $band, $mode) {
		// Convert - in Callsign to / Used for URL processing
		$callsign = str_replace("-","/",$callsign);
		$return = [
			"workedBefore" => false,
			"confirmed" => false,
		];
		$user_default_confirmation = $this->session->userdata('user_default_confirmation');
		$CI =& get_instance();
		$CI->load->model('logbooks_model');
		$logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook'));
		$CI->load->model('logbook_model');
		if(!empty($logbooks_locations_array)) {
			if($type == "SAT") {
				$this->db->where('COL_PROP_MODE', 'SAT');
			} else {
				$this->db->where('COL_MODE', $this->logbook_model->get_main_mode_from_mode($mode));
				$this->db->where('COL_BAND', $band);
				$this->db->where('COL_PROP_MODE !=','SAT');
			}
			$this->db->where_in('station_id', $logbooks_locations_array);
			$this->db->where('COL_CALL', strtoupper($callsign));
			$query = $this->db->get($this->config->item('table_name'), 1, 0);
			foreach ($query->result() as $workedBeforeRow)
			{
				$return['workedBefore'] = true;
			}
			$extrawhere='';
			if (isset($user_default_confirmation) && strpos($user_default_confirmation, 'Q') !== false) {
				$extrawhere="COL_QSL_RCVD='Y'"; 
			}
			if (isset($user_default_confirmation) && strpos($user_default_confirmation, 'L') !== false) {
				if ($extrawhere!='') {
					$extrawhere.=" OR";
				}
				$extrawhere.=" COL_LOTW_QSL_RCVD='Y'";
			}
			if (isset($user_default_confirmation) && strpos($user_default_confirmation, 'E') !== false) {
				if ($extrawhere!='') {
					$extrawhere.=" OR";
				}
				$extrawhere.=" COL_EQSL_QSL_RCVD='Y'";
			}
			if($type == "SAT") {
				$this->db->where('COL_PROP_MODE', 'SAT');
				if ($extrawhere != '') {
					$this->db->where('('.$extrawhere.')');
				} else {
					$this->db->where("1=0");
				}
			} else {
				$CI->load->model('logbook_model');
				$this->db->where('COL_MODE', $CI->logbook_model->get_main_mode_from_mode($mode));
				$this->db->where('COL_BAND', $band);
				$this->db->where('COL_PROP_MODE !=','SAT');
				if ($extrawhere != '') {
					$this->db->where('('.$extrawhere.')');
				} else {
					$this->db->where("1=0");
				}
			}
			$this->db->where_in('station_id', $logbooks_locations_array);
			$this->db->where('COL_CALL', strtoupper($callsign));
			$query = $this->db->get($this->config->item('table_name'), 1, 0);
			foreach ($query->result() as $workedBeforeRow) {
				$return['confirmed'] = true;
			}
			header('Content-Type: application/json');
			echo json_encode($return, JSON_PRETTY_PRINT);
			return;
		} else {
			$return['workedBefore'] = false;
			$return['confirmed'] = false;
			header('Content-Type: application/json');
			echo json_encode($return, JSON_PRETTY_PRINT);
			return;
		}
	}
	/* Used to generate maps for displaying on /logbook/ */
	function qso_map() {
		header('Content-Type: application/json; charset=utf-8');
		$this->load->model('logbook_model');
		$this->load->library('qra');
		$data['qsos'] = $this->logbook_model->get_qsos($this->uri->segment(3),$this->uri->segment(4));
		echo "{\"markers\": [";
		$count = 1;
		foreach ($data['qsos']->result() as $row) {
			if($row->COL_GRIDSQUARE != null) {
				$stn_loc = $this->qra->qra2latlong($row->COL_GRIDSQUARE);
				if($count != 1) {
					echo ",";
				}
				if($row->COL_SAT_NAME != null) {
						echo "{\"lat\":\"".$stn_loc[0]."\",\"lng\":\"".$stn_loc[1]."\", \"html\":\"Callsign: ".$row->COL_CALL."
Date/Time: ".$row->COL_TIME_ON."
SAT: ".$row->COL_SAT_NAME."
Mode: ";
						echo $row->COL_SUBMODE==null?$row->COL_MODE:$row->COL_SUBMODE;
						echo "\",\"label\":\"".$row->COL_CALL."\"}";
				} else {
						echo "{\"lat\":\"".$stn_loc[0]."\",\"lng\":\"".$stn_loc[1]."\", \"html\":\"Callsign: ".$row->COL_CALL."
Date/Time: ".$row->COL_TIME_ON."
Band: ".$row->COL_BAND."
Mode: ";
						echo $row->COL_SUBMODE==null?$row->COL_MODE:$row->COL_SUBMODE;
						echo "\",\"label\":\"".$row->COL_CALL."\"}";
				}
				$count++;
			}elseif($row->COL_VUCC_GRIDS != null) {
				$grids = explode(",", $row->COL_VUCC_GRIDS);
				if (count($grids) == 2) {
					$grid1 = $this->qra->qra2latlong(trim($grids[0]));
					$grid2 = $this->qra->qra2latlong(trim($grids[1]));
					$coords[]=array('lat' => $grid1[0],'lng'=> $grid1[1]);
					$coords[]=array('lat' => $grid2[0],'lng'=> $grid2[1]);
					$stn_loc = $this->qra->get_midpoint($coords);
				}
				if (count($grids) == 4) {
					$grid1 = $this->qra->qra2latlong(trim($grids[0]));
					$grid2 = $this->qra->qra2latlong(trim($grids[1]));
					$grid3 = $this->qra->qra2latlong(trim($grids[2]));
					$grid4 = $this->qra->qra2latlong(trim($grids[3]));
					$coords[]=array('lat' => $grid1[0],'lng'=> $grid1[1]);
					$coords[]=array('lat' => $grid2[0],'lng'=> $grid2[1]);
					$coords[]=array('lat' => $grid3[0],'lng'=> $grid3[1]);
					$coords[]=array('lat' => $grid4[0],'lng'=> $grid4[1]);
					$stn_loc = $this->qra->get_midpoint($coords);
				}
				if($count != 1) {
					echo ",";
				}
				if($row->COL_SAT_NAME != null) {
					echo "{\"lat\":\"".$stn_loc[0]."\",\"lng\":\"".$stn_loc[1]."\", \"html\":\"Callsign: ".$row->COL_CALL."
Date/Time: ".$row->COL_TIME_ON."
SAT: ".$row->COL_SAT_NAME."
Mode: ";
					echo $row->COL_SUBMODE==null?$row->COL_MODE:$row->COL_SUBMODE;
					echo "\",\"label\":\"".$row->COL_CALL."\"}";
				} else {
					echo "{\"lat\":\"".$stn_loc[0]."\",\"lng\":\"".$stn_loc[1]."\", \"html\":\"Callsign: ".$row->COL_CALL."
Date/Time: ".$row->COL_TIME_ON."
Band: ".$row->COL_BAND."
Mode: ";
					echo $row->COL_SUBMODE==null?$row->COL_MODE:$row->COL_SUBMODE;
					echo "\",\"label\":\"".$row->COL_CALL."\"}";
				}
				$count++;
			} else {
				if($count != 1) {
					echo ",";
				}
				$result = $this->logbook_model->dxcc_lookup($row->COL_CALL, $row->COL_TIME_ON);
				if(isset($result)) {
					$lat = $result['lat'];
					$lng = $result['long'];
				}
				echo "{\"lat\":\"".$lat."\",\"lng\":\"".$lng."\", \"html\":\"Callsign: ".$row->COL_CALL."
Date/Time: ".$row->COL_TIME_ON."
Band: ".$row->COL_BAND."
Mode: ";
				echo $row->COL_SUBMODE==null?$row->COL_MODE:$row->COL_SUBMODE;
				echo "\",\"label\":\"".$row->COL_CALL."\"}";
				$count++;
			}
		}
		echo "]";
		echo "}";
	}
	function view($id) {
		$this->load->model('user_model');
		if(!$this->user_model->authorize($this->config->item('auth_mode'))) { return; }
		$this->load->library('qra');
		$this->load->model('logbook_model');
		$data['query'] = $this->logbook_model->get_qso($id);
        if ($this->session->userdata('user_measurement_base') == NULL) {
            $data['measurement_base'] = $this->config->item('measurement_base');
        }
        else {
            $data['measurement_base'] = $this->session->userdata('user_measurement_base');
        }
        $this->load->model('Qsl_model');
        $data['qslimages'] = $this->Qsl_model->getQslForQsoId($id);
		$data['max_upload'] = ini_get('upload_max_filesize');
		$this->load->view('interface_assets/mini_header', $data);
		$this->load->view('view_log/qso');
		$this->load->view('interface_assets/footer');
	}
	function partial($id) {
		$this->load->model('user_model');
		if(!$this->user_model->authorize($this->config->item('auth_mode'))) { return; }
		$CI =& get_instance();
		$CI->load->model('logbooks_model');
		$logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook'));
		$html = "";
		if(!empty($logbooks_locations_array)) {
			$this->db->select(''.$this->config->item('table_name').'.COL_CALL, '.$this->config->item('table_name').'.COL_BAND, '.$this->config->item('table_name').'.COL_FREQ, '.$this->config->item('table_name').'.COL_TIME_ON, '.$this->config->item('table_name').'.COL_RST_RCVD, '.$this->config->item('table_name').'.COL_RST_SENT, '.$this->config->item('table_name').'.COL_MODE, '.$this->config->item('table_name').'.COL_SUBMODE, '.$this->config->item('table_name').'.COL_PRIMARY_KEY, '.$this->config->item('table_name').'.COL_SAT_NAME, '.$this->config->item('table_name').'.COL_GRIDSQUARE, '.$this->config->item('table_name').'.COL_QSL_RCVD, '.$this->config->item('table_name').'.COL_EQSL_QSL_RCVD, '.$this->config->item('table_name').'.COL_EQSL_QSL_SENT, '.$this->config->item('table_name').'.COL_QSL_SENT, '.$this->config->item('table_name').'.COL_STX, '.$this->config->item('table_name').'.COL_STX_STRING, '.$this->config->item('table_name').'.COL_SRX, '.$this->config->item('table_name').'.COL_SRX_STRING, '.$this->config->item('table_name').'.COL_LOTW_QSL_SENT, '.$this->config->item('table_name').'.COL_LOTW_QSL_RCVD, '.$this->config->item('table_name').'.COL_VUCC_GRIDS, '.$this->config->item('table_name').'.COL_MY_GRIDSQUARE, '.$this->config->item('table_name').'.COL_CONTEST_ID, '.$this->config->item('table_name').'.COL_STATE, station_profile.*');
			$this->db->from($this->config->item('table_name'));
			$this->db->join('station_profile', 'station_profile.station_id = '.$this->config->item('table_name').'.station_id');
			$this->db->where_in('station_profile.station_id', $logbooks_locations_array);
			$this->db->order_by(''.$this->config->item('table_name').'.COL_TIME_ON', "desc");
			$this->db->like($this->config->item('table_name').'.COL_CALL', $id);
			$this->db->order_by($this->config->item('table_name').".COL_TIME_ON", "desc");
			$this->db->limit(5);
			$query = $this->db->get();
		}
		if (!empty($logbooks_locations_array) && $query->num_rows() > 0)
		{
			$html .= "
| Date"; $html .= " | Callsign"; $html .= $this->part_table_header_col($this, $this->session->userdata('user_column1')==""?'Mode':$this->session->userdata('user_column1')); $html .= $this->part_table_header_col($this, $this->session->userdata('user_column2')==""?'RSTS':$this->session->userdata('user_column2')); $html .= $this->part_table_header_col($this, $this->session->userdata('user_column3')==""?'RSTR':$this->session->userdata('user_column3')); $html .= $this->part_table_header_col($this, $this->session->userdata('user_column4')==""?'Band':$this->session->userdata('user_column4')); switch($this->session->userdata('user_previous_qsl_type')) { case 0: $html .= " | ".lang('gen_hamradio_qsl').""; break; case 1: $html .= " | ".lang('lotw_short').""; break; case 2: $html .= " | ".lang('eqsl_short').""; break; default: $html .= " | ".lang('gen_hamradio_qsl').""; break; } $html .= " | "; $html .= " | 
|---|---|---|---|---|---|---|
| ".date($custom_date_format, $timestamp). date(' H:i',strtotime($row->COL_TIME_ON)) . ""; $html .= " | " . str_replace('0','Ø',strtoupper($row->COL_CALL)) . ""; $html .= $this->part_table_col($row, $this->session->userdata('user_column1')==""?'Mode':$this->session->userdata('user_column1')); $html .= $this->part_table_col($row, $this->session->userdata('user_column2')==""?'RSTS':$this->session->userdata('user_column2')); $html .= $this->part_table_col($row, $this->session->userdata('user_column3')==""?'RSTR':$this->session->userdata('user_column3')); $html .= $this->part_table_col($row, $this->session->userdata('user_column4')==""?'Band':$this->session->userdata('user_column4')); if ($this->session->userdata('user_previous_qsl_type') == 1) { $html .= " | "; $html .= "COL_LOTW_QSL_SENT) { case "Y": $html .= "green"; break; default: $html .= "red"; } $html .= "\">▲"; $html .= "COL_LOTW_QSL_RCVD) { case "Y": $html .= "green"; break; default: $html .= "red"; } $html .= "\">▼"; $html .= ""; } else if ($this->session->userdata('user_previous_qsl_type') == 2) { $html .= " | "; $html .= "COL_EQSL_QSL_SENT) { case "Y": $html .= "green"; break; default: $html .= "red"; } $html .= "\">▲"; $html .= "COL_EQSL_QSL_RCVD) { case "Y": $html .= "green"; break; default: $html .= "red"; } $html .= "\">▼"; $html .= ""; } else { $html .= " | "; $html .= "COL_QSL_SENT) { case "Y": $html .= "green"; break; case "Q": $html .= "yellow"; break; case "R": $html .= "yellow"; break; case "I": $html .= "grey"; break; default: $html .= "red"; } $html .= "\">▲"; $html .= "COL_QSL_RCVD) { case "Y": $html .= "green"; break; case "Q": $html .= "yellow"; break; case "R": $html .= "yellow"; break; case "I": $html .= "grey"; break; default: $html .= "red"; } $html .= "\">▼"; $html .= ""; } $html .= " | ".$row->station_callsign.""; $html .= " |