| 
									
										
										
										
											2011-09-21 21:30:01 +08:00
										 |  |  | <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class adif extends CI_Controller { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Controls ADIF Import/Export Functions */ | 
					
						
							| 
									
										
										
										
											2014-09-26 06:09:44 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-11-20 06:28:05 +08:00
										 |  |  | 	function __construct() | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		parent::__construct(); | 
					
						
							|  |  |  | 		$this->load->helper(array('form', 'url')); | 
					
						
							| 
									
										
										
										
											2014-09-26 06:09:44 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-20 06:24:10 +08: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'); } | 
					
						
							| 
									
										
										
										
											2011-11-20 06:28:05 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-21 21:30:01 +08:00
										 |  |  | 	/* Shows Export Views */ | 
					
						
							|  |  |  | 	public function export() { | 
					
						
							| 
									
										
										
										
											2011-11-05 01:32:03 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		$data['page_title'] = "ADIF Export"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		$this->load->view('layout/header', $data); | 
					
						
							| 
									
										
										
										
											2011-09-21 21:30:01 +08:00
										 |  |  | 		$this->load->view('adif/main'); | 
					
						
							|  |  |  | 		$this->load->view('layout/footer'); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-09-26 06:09:44 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-21 21:30:01 +08:00
										 |  |  | 	// Export all QSO Data in ASC Order of Date.
 | 
					
						
							|  |  |  | 	public function exportall() | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2011-09-24 01:15:47 +08:00
										 |  |  | 		// Set memory limit to unlimited to allow heavy usage
 | 
					
						
							|  |  |  | 		ini_set('memory_limit', '-1'); | 
					
						
							| 
									
										
										
										
											2014-09-26 06:09:44 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-21 21:30:01 +08:00
										 |  |  | 		$this->load->model('adif_data'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		$data['qsos'] = $this->adif_data->export_all(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		$this->load->view('adif/data/exportall', $data); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-09-26 06:09:44 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-08 00:58:23 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// Export all QSO Data in ASC Order of Date.
 | 
					
						
							|  |  |  | 	public function exportsat() | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		// Set memory limit to unlimited to allow heavy usage
 | 
					
						
							|  |  |  | 		ini_set('memory_limit', '-1'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		$this->load->model('adif_data'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		$data['qsos'] = $this->adif_data->export_all(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		$this->load->view('adif/data/exportsat', $data); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-21 21:30:01 +08:00
										 |  |  | 	public function export_custom() { | 
					
						
							| 
									
										
										
										
											2014-09-26 06:09:44 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-24 01:15:47 +08:00
										 |  |  | 		// Set memory limit to unlimited to allow heavy usage
 | 
					
						
							|  |  |  | 		ini_set('memory_limit', '-1'); | 
					
						
							| 
									
										
										
										
											2014-09-26 06:09:44 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-21 21:30:01 +08:00
										 |  |  | 		$this->load->model('adif_data'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		$data['qsos'] = $this->adif_data->export_custom($this->input->post('from'), $this->input->post('to')); | 
					
						
							| 
									
										
										
										
											2014-09-26 06:09:44 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-21 21:30:01 +08:00
										 |  |  | 		$this->load->view('adif/data/exportall', $data); | 
					
						
							| 
									
										
										
										
											2014-09-26 06:09:44 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-21 21:30:01 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-05 12:57:29 +08:00
										 |  |  | 	public function export_lotw() | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		// Set memory limit to unlimited to allow heavy usage
 | 
					
						
							|  |  |  | 		ini_set('memory_limit', '-1'); | 
					
						
							| 
									
										
										
										
											2014-09-26 06:09:44 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-05 12:57:29 +08:00
										 |  |  | 		$this->load->model('adif_data'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		$data['qsos'] = $this->adif_data->export_lotw(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		$this->load->view('adif/data/exportall', $data); | 
					
						
							| 
									
										
										
										
											2014-09-26 06:09:44 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-07 13:31:19 +08:00
										 |  |  | 		foreach ($data['qsos']->result() as $qso) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			$this->adif_data->mark_lotw_sent($qso->COL_PRIMARY_KEY); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2013-03-05 12:57:29 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-09-26 06:09:44 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-17 23:24:16 +08:00
										 |  |  | 	public function import() { | 
					
						
							| 
									
										
										
										
											2014-09-26 06:09:44 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-11-20 06:28:05 +08:00
										 |  |  | 		$data['page_title'] = "ADIF Import"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-18 15:41:17 +08:00
										 |  |  | 		$config['upload_path'] = './uploads/'; | 
					
						
							| 
									
										
										
										
											2016-02-13 00:31:29 +08:00
										 |  |  | 		$config['allowed_types'] = 'adi|ADI|adif|ADIF'; | 
					
						
							| 
									
										
										
										
											2011-11-20 06:28:05 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		$this->load->library('upload', $config); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if ( ! $this->upload->do_upload()) | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2016-02-13 00:31:29 +08:00
										 |  |  | 		    //print $this->upload->display_errors();
 | 
					
						
							|  |  |  | 		    //exit(0);
 | 
					
						
							| 
									
										
										
										
											2011-11-20 06:28:05 +08:00
										 |  |  | 			$data['error'] = $this->upload->display_errors(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-14 03:11:46 +08:00
										 |  |  | 			$this->load->view('interface_assets/header', $data); | 
					
						
							| 
									
										
										
										
											2011-11-20 06:28:05 +08:00
										 |  |  | 			$this->load->view('adif/import'); | 
					
						
							| 
									
										
										
										
											2019-01-14 03:11:46 +08:00
										 |  |  | 			$this->load->view('interface_assets/footer'); | 
					
						
							| 
									
										
										
										
											2011-11-20 06:28:05 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		else | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			$data = array('upload_data' => $this->upload->data()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			ini_set('memory_limit', '-1'); | 
					
						
							|  |  |  | 			set_time_limit(0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			$this->load->model('logbook_model'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			$this->load->library('adif_parser'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			$this->adif_parser->load_from_file('./uploads/'.$data['upload_data']['file_name']); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			$this->adif_parser->initialize(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			while($record = $this->adif_parser->get_record()) | 
					
						
							|  |  |  | 			{ | 
					
						
							|  |  |  | 				if(count($record) == 0) | 
					
						
							|  |  |  | 				{ | 
					
						
							|  |  |  | 					break; | 
					
						
							|  |  |  | 				}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				$this->logbook_model->import($record); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			unlink('./uploads/'.$data['upload_data']['file_name']); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			$data['page_title'] = "ADIF Imported"; | 
					
						
							| 
									
										
										
										
											2019-01-14 03:11:46 +08:00
										 |  |  | 			$this->load->view('interface_assets/header', $data); | 
					
						
							| 
									
										
										
										
											2011-11-20 06:28:05 +08:00
										 |  |  | 			$this->load->view('adif/import_success'); | 
					
						
							| 
									
										
										
										
											2019-01-14 03:11:46 +08:00
										 |  |  | 			$this->load->view('interface_assets/footer'); | 
					
						
							| 
									
										
										
										
											2011-11-20 06:28:05 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2011-09-21 21:30:01 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-26 06:09:44 +08:00
										 |  |  | /* End of file adif.php */ |