| 
									
										
										
										
											2020-10-29 06:20:03 +08:00
										 |  |  | <?php | 
					
						
							| 
									
										
										
										
											2024-03-18 22:45:08 +08:00
										 |  |  | class Qsl_model extends CI_Model | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     function getQsoWithQslList() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $CI = &get_instance(); | 
					
						
							| 
									
										
										
										
											2021-11-15 00:50:11 +08:00
										 |  |  |         $CI->load->model('logbooks_model'); | 
					
						
							|  |  |  |         $logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook')); | 
					
						
							| 
									
										
										
										
											2020-10-29 06:20:03 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-18 22:25:30 +08:00
										 |  |  |         if (is_array($logbooks_locations_array) && !empty($logbooks_locations_array)) { | 
					
						
							|  |  |  |             $this->db->select('*'); | 
					
						
							|  |  |  |             $this->db->from($this->config->item('table_name')); | 
					
						
							|  |  |  |             $this->db->join('qsl_images', 'qsl_images.qsoid = ' . $this->config->item('table_name') . '.col_primary_key'); | 
					
						
							|  |  |  |             $this->db->where_in('station_id', $logbooks_locations_array); | 
					
						
							|  |  |  |             $this->db->order_by("id", "desc"); | 
					
						
							| 
									
										
										
										
											2024-03-18 22:45:08 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-18 22:25:30 +08:00
										 |  |  |             return $this->db->get(); | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             return false; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2020-10-29 06:20:03 +08:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-18 22:45:08 +08:00
										 |  |  |     function getQslForQsoId($id) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2020-10-29 06:20:03 +08:00
										 |  |  |         // Clean ID
 | 
					
						
							|  |  |  |         $clean_id = $this->security->xss_clean($id); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-15 00:50:11 +08:00
										 |  |  |         // be sure that QSO belongs to user
 | 
					
						
							| 
									
										
										
										
											2024-03-18 22:45:08 +08:00
										 |  |  |         $CI = &get_instance(); | 
					
						
							| 
									
										
										
										
											2021-11-15 00:50:11 +08:00
										 |  |  |         $CI->load->model('logbook_model'); | 
					
						
							|  |  |  |         if (!$CI->logbook_model->check_qso_is_accessible($clean_id)) { | 
					
						
							|  |  |  |             return; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-29 06:20:03 +08:00
										 |  |  |         $this->db->select('*'); | 
					
						
							|  |  |  |         $this->db->from('qsl_images'); | 
					
						
							|  |  |  |         $this->db->where('qsoid', $clean_id); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return $this->db->get()->result(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-18 22:45:08 +08:00
										 |  |  |     function saveQsl($qsoid, $filename) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2021-11-15 00:50:11 +08:00
										 |  |  |         // Clean ID
 | 
					
						
							|  |  |  |         $clean_id = $this->security->xss_clean($qsoid); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // be sure that QSO belongs to user
 | 
					
						
							| 
									
										
										
										
											2024-03-18 22:45:08 +08:00
										 |  |  |         $CI = &get_instance(); | 
					
						
							| 
									
										
										
										
											2021-11-15 00:50:11 +08:00
										 |  |  |         $CI->load->model('logbook_model'); | 
					
						
							|  |  |  |         if (!$CI->logbook_model->check_qso_is_accessible($clean_id)) { | 
					
						
							|  |  |  |             return; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-29 06:20:03 +08:00
										 |  |  |         $data = array( | 
					
						
							| 
									
										
										
										
											2021-11-15 00:50:11 +08:00
										 |  |  |             'qsoid' => $clean_id, | 
					
						
							| 
									
										
										
										
											2020-10-29 06:20:03 +08:00
										 |  |  |             'filename' => $filename | 
					
						
							|  |  |  |         ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $this->db->insert('qsl_images', $data); | 
					
						
							| 
									
										
										
										
											2020-11-01 19:36:02 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |         return $this->db->insert_id(); | 
					
						
							| 
									
										
										
										
											2020-10-29 06:20:03 +08:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-18 22:45:08 +08:00
										 |  |  |     function deleteQsl($id) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2020-10-29 06:20:03 +08:00
										 |  |  |         // Clean ID
 | 
					
						
							|  |  |  |         $clean_id = $this->security->xss_clean($id); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-15 00:50:11 +08:00
										 |  |  |         // be sure that QSO belongs to user
 | 
					
						
							| 
									
										
										
										
											2024-03-18 22:45:08 +08:00
										 |  |  |         $CI = &get_instance(); | 
					
						
							| 
									
										
										
										
											2021-11-15 00:50:11 +08:00
										 |  |  |         $CI->load->model('logbook_model'); | 
					
						
							| 
									
										
										
										
											2022-12-29 04:58:09 +08:00
										 |  |  |         $this->db->select('qsoid'); | 
					
						
							|  |  |  |         $this->db->from('qsl_images'); | 
					
						
							|  |  |  |         $this->db->where('id', $clean_id); | 
					
						
							|  |  |  |         $qsoid = $this->db->get()->row()->qsoid; | 
					
						
							|  |  |  |         if (!$CI->logbook_model->check_qso_is_accessible($qsoid)) { | 
					
						
							| 
									
										
										
										
											2021-11-15 00:50:11 +08:00
										 |  |  |             return; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-29 06:20:03 +08:00
										 |  |  |         // Delete Mode
 | 
					
						
							|  |  |  |         $this->db->delete('qsl_images', array('id' => $clean_id)); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-18 22:45:08 +08:00
										 |  |  |     function getFilename($id) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2020-10-29 06:20:03 +08:00
										 |  |  |         // Clean ID
 | 
					
						
							|  |  |  |         $clean_id = $this->security->xss_clean($id); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-15 00:50:11 +08:00
										 |  |  |         // be sure that QSO belongs to user
 | 
					
						
							| 
									
										
										
										
											2024-03-18 22:45:08 +08:00
										 |  |  |         $CI = &get_instance(); | 
					
						
							| 
									
										
										
										
											2021-11-15 00:50:11 +08:00
										 |  |  |         $CI->load->model('logbook_model'); | 
					
						
							| 
									
										
										
										
											2022-12-29 04:58:09 +08:00
										 |  |  |         $this->db->select('qsoid'); | 
					
						
							|  |  |  |         $this->db->from('qsl_images'); | 
					
						
							|  |  |  |         $this->db->where('id', $clean_id); | 
					
						
							|  |  |  |         $qsoid = $this->db->get()->row()->qsoid; | 
					
						
							|  |  |  |         if (!$CI->logbook_model->check_qso_is_accessible($qsoid)) { | 
					
						
							| 
									
										
										
										
											2021-11-15 00:50:11 +08:00
										 |  |  |             return; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-29 06:20:03 +08:00
										 |  |  |         $this->db->select('filename'); | 
					
						
							|  |  |  |         $this->db->from('qsl_images'); | 
					
						
							|  |  |  |         $this->db->where('id', $clean_id); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return $this->db->get(); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-07-22 13:55:34 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-18 22:45:08 +08:00
										 |  |  |     function searchQsos($callsign) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $CI = &get_instance(); | 
					
						
							| 
									
										
										
										
											2021-11-15 00:50:11 +08:00
										 |  |  |         $CI->load->model('logbooks_model'); | 
					
						
							|  |  |  |         $logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook')); | 
					
						
							| 
									
										
										
										
											2021-07-22 13:55:34 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-18 22:45:08 +08:00
										 |  |  |         $this->db->select('*'); | 
					
						
							|  |  |  |         $this->db->from($this->config->item('table_name')); | 
					
						
							|  |  |  |         $this->db->where_in('station_id', $logbooks_locations_array); | 
					
						
							|  |  |  |         $this->db->where('col_call', $callsign); | 
					
						
							| 
									
										
										
										
											2021-07-22 13:55:34 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-18 22:45:08 +08:00
										 |  |  |         return $this->db->get(); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-07-22 13:55:34 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-18 22:45:08 +08:00
										 |  |  |     function addQsotoQsl($qsoid, $filename) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $clean_qsoid = $this->security->xss_clean($qsoid); | 
					
						
							|  |  |  |         $clean_filename = $this->security->xss_clean($filename); | 
					
						
							| 
									
										
										
										
											2021-07-22 13:55:34 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-18 22:45:08 +08:00
										 |  |  |         // be sure that QSO belongs to user
 | 
					
						
							|  |  |  |         $CI = &get_instance(); | 
					
						
							|  |  |  |         $CI->load->model('logbook_model'); | 
					
						
							|  |  |  |         if (!$CI->logbook_model->check_qso_is_accessible($clean_qsoid)) { | 
					
						
							|  |  |  |             return; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2021-11-15 00:50:11 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-18 22:45:08 +08:00
										 |  |  |         $data = array( | 
					
						
							|  |  |  |             'qsoid' => $clean_qsoid, | 
					
						
							|  |  |  |             'filename' => $filename | 
					
						
							|  |  |  |         ); | 
					
						
							| 
									
										
										
										
											2021-07-22 13:55:34 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-18 22:45:08 +08:00
										 |  |  |         $this->db->insert('qsl_images', $data); | 
					
						
							| 
									
										
										
										
											2021-07-22 13:55:34 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-18 22:45:08 +08:00
										 |  |  |         return $this->db->insert_id(); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-07-22 13:55:34 +08:00
										 |  |  | } |