| 
									
										
										
										
											2019-09-12 00:38:09 +08:00
										 |  |  | <?php | 
					
						
							|  |  |  | if ( ! defined('BASEPATH')) exit('No direct script access allowed'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* | 
					
						
							| 
									
										
										
										
											2021-10-08 03:42:19 +08:00
										 |  |  | 	This controller contains features for contesting | 
					
						
							| 
									
										
										
										
											2019-09-12 00:38:09 +08:00
										 |  |  | */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class Contesting extends CI_Controller { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-08 03:42:19 +08:00
										 |  |  | 	function __construct() { | 
					
						
							| 
									
										
										
										
											2021-01-06 00:14:50 +08:00
										 |  |  | 		parent::__construct(); | 
					
						
							|  |  |  | 		$this->lang->load('contesting'); | 
					
						
							| 
									
										
										
										
											2021-02-13 06:27:08 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-06 00:14:50 +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'); } | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-08 03:42:19 +08:00
										 |  |  |     public function index() { | 
					
						
							| 
									
										
										
										
											2020-11-08 17:46:08 +08:00
										 |  |  |         $this->load->model('cat'); | 
					
						
							|  |  |  |         $this->load->model('stations'); | 
					
						
							|  |  |  |         $this->load->model('modes'); | 
					
						
							| 
									
										
										
										
											2021-02-13 06:27:08 +08:00
										 |  |  | 		$this->load->model('contesting_model'); | 
					
						
							| 
									
										
										
										
											2020-11-08 17:46:08 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-08 03:42:19 +08:00
										 |  |  | 		$data['my_gridsquare'] = $this->stations->find_gridsquare(); | 
					
						
							| 
									
										
										
										
											2021-10-12 19:10:54 +08:00
										 |  |  | 		$data['my_dok'] = ""; // For now, this is set to blank, but need function to get
 | 
					
						
							| 
									
										
										
										
											2020-11-08 17:46:08 +08:00
										 |  |  |         $data['radios'] = $this->cat->radios(); | 
					
						
							|  |  |  |         $data['modes'] = $this->modes->active(); | 
					
						
							| 
									
										
										
										
											2021-02-13 06:27:08 +08:00
										 |  |  | 		$data['contestnames'] = $this->contesting_model->getActivecontests(); | 
					
						
							| 
									
										
										
										
											2020-11-08 17:46:08 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-08 03:42:19 +08:00
										 |  |  | 		$this->load->library('form_validation'); | 
					
						
							| 
									
										
										
										
											2020-11-08 17:46:08 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |         $this->form_validation->set_rules('start_date', 'Date', 'required'); | 
					
						
							|  |  |  |         $this->form_validation->set_rules('start_time', 'Time', 'required'); | 
					
						
							|  |  |  |         $this->form_validation->set_rules('callsign', 'Callsign', 'required'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-08 03:42:19 +08:00
										 |  |  | 		$data['page_title'] = "Contest Logging"; | 
					
						
							| 
									
										
										
										
											2020-11-08 17:46:08 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-08 03:42:19 +08:00
										 |  |  | 		$this->load->view('interface_assets/header', $data); | 
					
						
							|  |  |  | 		$this->load->view('contesting/index'); | 
					
						
							|  |  |  | 		$this->load->view('interface_assets/footer'); | 
					
						
							| 
									
										
										
										
											2020-11-08 17:46:08 +08:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-12-29 02:55:51 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     public function getSessionQsos() { | 
					
						
							|  |  |  |         //load model
 | 
					
						
							|  |  |  |         $this->load->model('Contesting_model'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $qso = $this->input->post('qso'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // get QSOs to fill the table
 | 
					
						
							|  |  |  |         $data = $this->Contesting_model->getSessionQsos($qso); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return json_encode($data); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-02-13 06:27:08 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-08 03:42:19 +08:00
										 |  |  | 	public function create() { | 
					
						
							| 
									
										
										
										
											2021-02-13 06:27:08 +08:00
										 |  |  | 		$this->load->model('Contesting_model'); | 
					
						
							|  |  |  | 		$this->load->library('form_validation'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		$this->form_validation->set_rules('name', 'Contest Name', 'required'); | 
					
						
							|  |  |  | 		$this->form_validation->set_rules('adifname', 'Contest Adif Name', 'required'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if ($this->form_validation->run() == FALSE) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			$data['page_title'] = "Create Mode"; | 
					
						
							|  |  |  | 			$this->load->view('contesting/create', $data); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		else | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			$this->Contesting_model->add(); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	public function add() { | 
					
						
							|  |  |  | 		$this->load->model('Contesting_model'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		$data['contests'] = $this->Contesting_model->getAllContests(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// Render Page
 | 
					
						
							|  |  |  | 		$data['page_title'] = "Contests"; | 
					
						
							|  |  |  | 		$this->load->view('interface_assets/header', $data); | 
					
						
							|  |  |  | 		$this->load->view('contesting/add'); | 
					
						
							|  |  |  | 		$this->load->view('interface_assets/footer'); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-08 03:42:19 +08:00
										 |  |  | 	public function edit($id) { | 
					
						
							| 
									
										
										
										
											2021-02-13 06:27:08 +08:00
										 |  |  | 		$this->load->library('form_validation'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		$this->load->model('Contesting_model'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		$item_id_clean = $this->security->xss_clean($id); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		$data['contest'] = $this->Contesting_model->contest($item_id_clean); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		$data['page_title'] = "Edit Contest"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		$this->form_validation->set_rules('name', 'Contest Name', 'required'); | 
					
						
							|  |  |  | 		$this->form_validation->set_rules('adifname', 'Adif Contest Name', 'required'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if ($this->form_validation->run() == FALSE) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			$this->load->view('interface_assets/header', $data); | 
					
						
							|  |  |  | 			$this->load->view('contesting/edit'); | 
					
						
							|  |  |  | 			$this->load->view('interface_assets/footer'); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		else | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			$this->Contesting_model->edit($item_id_clean); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			$data['notice'] = "Contest ".$this->security->xss_clean($this->input->post('name', true))." Updated"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			redirect('contesting/add'); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	public function delete() { | 
					
						
							|  |  |  | 		$id = $this->input->post('id'); | 
					
						
							|  |  |  | 		$this->load->model('Contesting_model'); | 
					
						
							|  |  |  | 		$this->Contesting_model->delete($id); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	public function activate() { | 
					
						
							|  |  |  | 		$id = $this->input->post('id'); | 
					
						
							|  |  |  | 		$this->load->model('Contesting_model'); | 
					
						
							|  |  |  | 		$this->Contesting_model->activate($id); | 
					
						
							|  |  |  | 		header('Content-Type: application/json'); | 
					
						
							|  |  |  | 		echo json_encode(array('message' => 'OK')); | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	public function deactivate() { | 
					
						
							|  |  |  | 		$id = $this->input->post('id'); | 
					
						
							|  |  |  | 		$this->load->model('Contesting_model'); | 
					
						
							|  |  |  | 		$this->Contesting_model->deactivate($id); | 
					
						
							|  |  |  | 		header('Content-Type: application/json'); | 
					
						
							|  |  |  | 		echo json_encode(array('message' => 'OK')); | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } |