Merge pull request #2103 from AndreasK79/backup_adif_api
这个提交包含在:
		
						当前提交
						07a6025e99
					
				
					共有  3 个文件被更改,包括 30 次插入 和 10 次删除
				
			
		|  | @ -20,16 +20,23 @@ class Backup extends CI_Controller { | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	/* Gets all QSOs and Dumps them to logbook.adi */ | 	/* Gets all QSOs and Dumps them to logbook.adi */ | ||||||
| 	public function adif(){  | 	public function adif($key = null){  | ||||||
|  | 		if ($key == null) { | ||||||
|  | 			$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'); } | ||||||
|  | 		} | ||||||
|  | 
 | ||||||
| 		$this->load->helper('file'); | 		$this->load->helper('file'); | ||||||
| 		// Set memory limit to unlimited to allow heavy usage
 | 		// Set memory limit to unlimited to allow heavy usage
 | ||||||
| 		ini_set('memory_limit', '-1'); | 		ini_set('memory_limit', '-1'); | ||||||
| 		 | 		 | ||||||
| 		$this->load->model('adif_data'); | 		$this->load->model('adif_data'); | ||||||
| 
 | 
 | ||||||
| 		$data['qsos'] = $this->adif_data->export_all(); | 		$data['qsos'] = $this->adif_data->export_all($key); | ||||||
| 
 | 
 | ||||||
| 		if ( ! write_file('backup/logbook.adi', $this->load->view('backup/exportall', $data, true))) | 		$data['filename'] = 'backup/logbook'. date('_Y_m_d_H_i_s') .'.adi'; | ||||||
|  | 		 | ||||||
|  | 		if ( ! write_file($data['filename'], $this->load->view('backup/exportall', $data, true))) | ||||||
| 		{ | 		{ | ||||||
| 		     $data['status'] = false; | 		     $data['status'] = false; | ||||||
| 		} | 		} | ||||||
|  | @ -40,6 +47,7 @@ class Backup extends CI_Controller { | ||||||
| 
 | 
 | ||||||
| 		$data['page_title'] = "ADIF - Backup"; | 		$data['page_title'] = "ADIF - Backup"; | ||||||
| 		 | 		 | ||||||
|  | 
 | ||||||
| 		$this->load->view('interface_assets/header', $data); | 		$this->load->view('interface_assets/header', $data); | ||||||
| 		$this->load->view('backup/adif_view'); | 		$this->load->view('backup/adif_view'); | ||||||
| 		$this->load->view('interface_assets/footer'); | 		$this->load->view('interface_assets/footer'); | ||||||
|  |  | ||||||
|  | @ -2,13 +2,25 @@ | ||||||
| 
 | 
 | ||||||
| class adif_data extends CI_Model { | class adif_data extends CI_Model { | ||||||
| 
 | 
 | ||||||
|     function export_all() { |     function export_all($api_key = null) { | ||||||
|         $this->load->model('stations'); |         $CI =& get_instance(); | ||||||
|         $active_station_id = $this->stations->find_active(); |         $CI->load->model('logbooks_model'); | ||||||
|  |         if ($api_key != null) { | ||||||
|  |             $CI->load->model('api_model'); | ||||||
|  |             if (strpos($this->api_model->access($api_key), 'r') !== false) { | ||||||
|  |                 $this->api_model->update_last_used($api_key); | ||||||
|  |                 $user_id = $this->api_model->key_userid($api_key); | ||||||
|  |                 $active_station_logbook = $CI->logbooks_model->find_active_station_logbook_from_userid($user_id); | ||||||
|  |                 $logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($active_station_logbook); | ||||||
|  |             } | ||||||
|  |         } else { | ||||||
|  |             $logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook')); | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|         $this->db->select($this->config->item('table_name').'.*, station_profile.*, dxcc_entities.name as station_country'); |         $this->db->select($this->config->item('table_name').'.*, station_profile.*, dxcc_entities.name as station_country'); | ||||||
|         $this->db->where($this->config->item('table_name').'.station_id', $active_station_id); |  | ||||||
|         $this->db->order_by("COL_TIME_ON", "ASC"); |         $this->db->order_by("COL_TIME_ON", "ASC"); | ||||||
|         $this->db->join('station_profile', 'station_profile.station_id = '.$this->config->item('table_name').'.station_id'); |         $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->join('dxcc_entities', 'station_profile.station_dxcc = dxcc_entities.adif'); |         $this->db->join('dxcc_entities', 'station_profile.station_dxcc = dxcc_entities.adif'); | ||||||
|         $query = $this->db->get($this->config->item('table_name')); |         $query = $this->db->get($this->config->item('table_name')); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -4,7 +4,7 @@ | ||||||
| 
 | 
 | ||||||
| <?php if($status == true) { ?>
 | <?php if($status == true) { ?>
 | ||||||
| 
 | 
 | ||||||
| <p>The backup of your log completed successfully. The output can be found at: <a href="<?php echo base_url(); ?>backup/logbook.adi"><?php echo base_url(); ?>backup/logbook.adi</a></a></p>
 | <p>The backup of your log completed successfully. The output can be found at: <a href="<?php echo base_url().$filename; ?>"><?php echo base_url() . $filename; ?></a></p>
 | ||||||
| 
 | 
 | ||||||
| <p>You could automate this process by making it a cronjob.</p> | <p>You could automate this process by making it a cronjob.</p> | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		正在加载…
	
		在新工单中引用