| 
									
										
										
										
											2012-04-08 00:36:38 +08:00
										 |  |  | <?php | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	class Cat extends CI_Model { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-29 00:18:04 +08:00
										 |  |  | 		function update($result, $user_id) { | 
					
						
							| 
									
										
										
										
											2021-09-20 21:03:35 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-30 05:06:06 +08:00
										 |  |  | 			$timestamp = gmdate("Y-m-d H:i:s"); | 
					
						
							| 
									
										
										
										
											2022-01-15 03:22:18 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-27 21:21:56 +08:00
										 |  |  | 			if (isset($result['prop_mode'])) { | 
					
						
							|  |  |  | 				$prop_mode = $result['prop_mode']; | 
					
						
							| 
									
										
										
										
											2022-09-30 05:32:08 +08:00
										 |  |  | 			// For backward compatibility, SatPC32 does not set propergation mode
 | 
					
						
							|  |  |  | 			} else if (isset($result['sat_name'])) { | 
					
						
							|  |  |  | 				$prop_mode = "SAT"; | 
					
						
							| 
									
										
										
										
											2022-08-27 21:21:56 +08:00
										 |  |  | 			} else { | 
					
						
							| 
									
										
										
										
											2022-09-30 05:32:08 +08:00
										 |  |  | 				$prop_mode = NULL; | 
					
						
							| 
									
										
										
										
											2022-08-27 21:21:56 +08:00
										 |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-20 21:03:35 +08:00
										 |  |  | 			$this->db->where('radio', $result['radio']); | 
					
						
							| 
									
										
										
										
											2021-09-29 00:18:04 +08:00
										 |  |  | 			$this->db->where('user_id', $user_id); | 
					
						
							| 
									
										
										
										
											2012-04-08 00:36:38 +08:00
										 |  |  | 			$query = $this->db->get('cat'); | 
					
						
							| 
									
										
										
										
											2021-09-20 21:03:35 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-29 08:12:28 +08:00
										 |  |  | 			// Let's keep uplink_freq, downlink_freq, uplink_mode and downlink_mode for backward compatibility
 | 
					
						
							|  |  |  | 			$data = array( | 
					
						
							|  |  |  | 				'prop_mode' => $prop_mode, | 
					
						
							| 
									
										
										
										
											2022-09-30 05:32:08 +08:00
										 |  |  | 				'power' => $result['power'] ?? NULL, | 
					
						
							| 
									
										
										
										
											2022-09-30 05:06:06 +08:00
										 |  |  | 				'sat_name' => $result['sat_name'] ?? NULL, | 
					
						
							| 
									
										
										
										
											2022-08-29 08:12:28 +08:00
										 |  |  | 				'timestamp' => $timestamp, | 
					
						
							|  |  |  | 			); | 
					
						
							| 
									
										
										
										
											2022-09-30 05:06:06 +08:00
										 |  |  | 			if (isset($result['frequency']) && $result['frequency'] != "NULL") { | 
					
						
							|  |  |  | 				$data['frequency'] = $result['frequency']; | 
					
						
							|  |  |  | 			} else { | 
					
						
							|  |  |  | 				$data['frequency'] = $result['uplink_freq']; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			if (isset($result['mode']) && $result['mode'] != "NULL") { | 
					
						
							|  |  |  | 				$data['mode'] = $result['mode']; | 
					
						
							|  |  |  | 			} else { | 
					
						
							|  |  |  | 				$data['mode'] = $result['uplink_mode']; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			if (isset($result['frequency_rx'])) { | 
					
						
							| 
									
										
										
										
											2022-09-30 07:24:10 +08:00
										 |  |  | 				$data['frequency_rx'] = $result['frequency_rx']; | 
					
						
							| 
									
										
										
										
											2022-10-01 00:12:48 +08:00
										 |  |  | 			} else if (isset($result['downlink_freq']) && $result['downlink_freq'] != "NULL") { | 
					
						
							| 
									
										
										
										
											2022-09-30 07:24:10 +08:00
										 |  |  | 				$data['frequency_rx'] = $result['downlink_freq']; | 
					
						
							| 
									
										
										
										
											2022-09-30 05:06:06 +08:00
										 |  |  | 			} else { | 
					
						
							| 
									
										
										
										
											2022-09-30 07:24:10 +08:00
										 |  |  | 				$data['frequency_rx'] = NULL; | 
					
						
							| 
									
										
										
										
											2022-09-30 05:06:06 +08:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			if (isset($result['mode_rx'])) { | 
					
						
							| 
									
										
										
										
											2022-09-30 07:24:10 +08:00
										 |  |  | 				$data['mode_rx'] = $result['mode_rx']; | 
					
						
							| 
									
										
										
										
											2022-10-01 00:12:48 +08:00
										 |  |  | 			} else if (isset($result['downlink_mode']) && $result['downlink_mode'] != "NULL") { | 
					
						
							| 
									
										
										
										
											2022-09-30 07:24:10 +08:00
										 |  |  | 				$data['mode_rx'] = $result['downlink_mode']; | 
					
						
							| 
									
										
										
										
											2022-09-30 05:06:06 +08:00
										 |  |  | 			} else { | 
					
						
							| 
									
										
										
										
											2022-09-30 07:24:10 +08:00
										 |  |  | 				$data['mode_rx'] = NULL; | 
					
						
							| 
									
										
										
										
											2022-09-30 05:06:06 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2022-08-28 01:00:23 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-08 00:36:38 +08:00
										 |  |  | 			if ($query->num_rows() > 0) | 
					
						
							|  |  |  | 			{ | 
					
						
							| 
									
										
										
										
											2022-08-27 21:21:56 +08:00
										 |  |  | 				// Update the record
 | 
					
						
							|  |  |  | 				foreach ($query->result() as $row) | 
					
						
							|  |  |  | 				{ | 
					
						
							|  |  |  | 					$radio_id = $row->id; | 
					
						
							| 
									
										
										
										
											2021-09-20 21:03:35 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-27 21:21:56 +08:00
										 |  |  | 					$this->db->where('id', $radio_id); | 
					
						
							|  |  |  | 					$this->db->where('user_id', $user_id); | 
					
						
							|  |  |  | 					$this->db->update('cat', $data); | 
					
						
							| 
									
										
										
										
											2012-04-08 00:36:38 +08:00
										 |  |  | 				} | 
					
						
							|  |  |  | 			} else { | 
					
						
							|  |  |  | 				// Add a new record
 | 
					
						
							| 
									
										
										
										
											2022-08-28 01:00:23 +08:00
										 |  |  | 				$data['radio'] = $result['radio']; | 
					
						
							|  |  |  | 				$data['user_id'] = $user_id; | 
					
						
							| 
									
										
										
										
											2012-04-08 00:36:38 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-20 21:03:35 +08:00
										 |  |  | 				$this->db->insert('cat', $data); | 
					
						
							| 
									
										
										
										
											2012-04-08 00:36:38 +08:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2021-09-20 21:03:35 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-08 00:36:38 +08:00
										 |  |  | 		function status() { | 
					
						
							| 
									
										
										
										
											2021-09-20 21:03:35 +08:00
										 |  |  | 			//$this->db->where('radio', $result['radio']);
 | 
					
						
							|  |  |  | 			$this->db->where('user_id', $this->session->userdata('user_id')); | 
					
						
							| 
									
										
										
										
											2012-04-08 20:17:14 +08:00
										 |  |  | 			$query = $this->db->get('cat'); | 
					
						
							| 
									
										
										
										
											2021-09-20 21:03:35 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-08 23:47:18 +08:00
										 |  |  | 			return $query; | 
					
						
							| 
									
										
										
										
											2012-04-08 00:36:38 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-03 21:06:56 +08:00
										 |  |  | 		function recent_status() { | 
					
						
							| 
									
										
										
										
											2021-09-20 21:03:35 +08:00
										 |  |  | 			$this->db->where('user_id', $this->session->userdata('user_id')); | 
					
						
							| 
									
										
										
										
											2021-12-28 01:18:27 +08:00
										 |  |  | 			$this->db->where("timestamp > date_sub(UTC_TIMESTAMP(), interval 15 minute)", NULL, FALSE); | 
					
						
							| 
									
										
										
										
											2021-05-03 21:06:56 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			$query = $this->db->get('cat'); | 
					
						
							|  |  |  | 			return $query; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-08 20:17:14 +08:00
										 |  |  | 		/* Return list of radios */ | 
					
						
							|  |  |  | 		function radios() { | 
					
						
							|  |  |  | 			$this->db->select('id, radio'); | 
					
						
							| 
									
										
										
										
											2021-09-20 21:03:35 +08:00
										 |  |  | 			$this->db->where('user_id', $this->session->userdata('user_id')); | 
					
						
							| 
									
										
										
										
											2012-04-08 20:17:14 +08:00
										 |  |  | 			$query = $this->db->get('cat'); | 
					
						
							| 
									
										
										
										
											2021-09-20 21:03:35 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-08 20:17:14 +08:00
										 |  |  | 			return $query; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2019-09-06 23:55:13 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		function radio_status($id) { | 
					
						
							| 
									
										
										
										
											2022-07-24 00:27:45 +08:00
										 |  |  | 			$sql = 'SELECT * FROM `cat` WHERE id = ' . $id . ' and user_id =' . $this->session->userdata('user_id'); | 
					
						
							| 
									
										
										
										
											2021-09-20 21:03:35 +08:00
										 |  |  | 			return $this->db->query($sql); | 
					
						
							| 
									
										
										
										
											2019-09-06 23:55:13 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-14 04:14:39 +08:00
										 |  |  | 		function delete($id) { | 
					
						
							|  |  |  | 			$this->db->where('id', $id); | 
					
						
							| 
									
										
										
										
											2021-09-20 21:03:35 +08:00
										 |  |  | 			$this->db->where('user_id', $this->session->userdata('user_id')); | 
					
						
							|  |  |  | 			$this->db->delete('cat'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-14 04:14:39 +08:00
										 |  |  | 			return true; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2012-04-08 00:36:38 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2021-07-06 03:23:35 +08:00
										 |  |  | ?>
 |