| 
									
										
										
										
											2011-08-17 23:12:41 +08:00
										 |  |  | <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class Contest extends CI_Controller { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Displays available contests
 | 
					
						
							|  |  |  | 	public function index() | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2011-08-20 05:10:53 +08:00
										 |  |  | 		$this->load->model('logbook_model'); | 
					
						
							|  |  |  | 		$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-08-20 01:24:56 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-08-19 00:08:04 +08:00
										 |  |  | 		// Load database items
 | 
					
						
							| 
									
										
										
										
											2011-08-17 23:12:41 +08:00
										 |  |  | 		$this->load->model('contests'); | 
					
						
							|  |  |  | 		$data['contests'] = $this->contests->list_contests(); | 
					
						
							|  |  |  | 		 | 
					
						
							| 
									
										
										
										
											2011-08-19 00:08:04 +08:00
										 |  |  | 		// Load views
 | 
					
						
							| 
									
										
										
										
											2011-08-17 23:12:41 +08:00
										 |  |  | 		$this->load->view('layout/header'); | 
					
						
							|  |  |  | 		$this->load->view('contest/main', $data); | 
					
						
							|  |  |  | 		$this->load->view('layout/footer'); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2011-08-19 00:08:04 +08:00
										 |  |  | 	/* | 
					
						
							|  |  |  | 		Displays contest logging view based on the ID provided, allowing users to log in contest mode giving them serial numbers and scoring information. | 
					
						
							|  |  |  | 	*/ | 
					
						
							| 
									
										
										
										
											2011-08-17 23:12:41 +08:00
										 |  |  | 	public function view($id) { | 
					
						
							| 
									
										
										
										
											2011-08-20 05:10:53 +08:00
										 |  |  | 		$this->load->model('logbook_model'); | 
					
						
							|  |  |  | 		$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-08-19 00:08:04 +08:00
										 |  |  | 		 | 
					
						
							|  |  |  | 		// Load database information
 | 
					
						
							| 
									
										
										
										
											2011-08-17 23:12:41 +08:00
										 |  |  | 		$this->load->model('contests'); | 
					
						
							| 
									
										
										
										
											2011-08-19 00:08:04 +08:00
										 |  |  | 		 | 
					
						
							| 
									
										
										
										
											2011-08-17 23:12:41 +08:00
										 |  |  | 		$data['info'] = $this->contests->information($id); | 
					
						
							| 
									
										
										
										
											2011-08-19 00:08:04 +08:00
										 |  |  | 		$data['log'] = $this->contests->contest_log_view($data['info']->start, $data['info']->end, $data['info']); | 
					
						
							|  |  |  | 		$data['summary'] = $this->contests->contest_summary_bands($data['info']->start, $data['info']->end, $data['info']); | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		// Run validation checks on QSO submission
 | 
					
						
							|  |  |  | 		$this->load->library('form_validation'); | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		$this->form_validation->set_rules('start_time', 'Time', 'required'); | 
					
						
							|  |  |  | 		$this->form_validation->set_rules('callsign', 'Callsign', 'required'); | 
					
						
							|  |  |  | 		$this->form_validation->set_rules('sent_serial', 'Sent Serial Number', 'required'); | 
					
						
							|  |  |  | 		$this->form_validation->set_rules('rst_recv', 'Recevied RST', 'required'); | 
					
						
							|  |  |  | 		$this->form_validation->set_rules('recv_serial', 'Received Serial Number', 'required'); | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		if($data['info']->qra == "Y") { | 
					
						
							|  |  |  | 			$this->form_validation->set_rules('locator', 'Received QRA', 'required'); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		// Load Views
 | 
					
						
							|  |  |  | 		if ($this->form_validation->run() == FALSE) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			$this->load->view('layout/header'); | 
					
						
							|  |  |  | 			$this->load->view('contest/log', $data); | 
					
						
							|  |  |  | 			$this->load->view('layout/footer'); | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			$contest_id = $id; | 
					
						
							|  |  |  | 			// Add QSO
 | 
					
						
							|  |  |  | 			$this->contests->add($contest_id); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			// Store Basic QSO Info for reuse
 | 
					
						
							|  |  |  | 			$this->session->set_userdata('band', $this->input->post('band')); | 
					
						
							|  |  |  | 			$this->session->set_userdata('freq', $this->input->post('freq')); | 
					
						
							|  |  |  | 			$this->session->set_userdata('mode', $this->input->post('mode')); | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 			$data['info'] = $this->contests->information($id); | 
					
						
							|  |  |  | 			$data['log'] = $this->contests->contest_log_view($data['info']->start, $data['info']->end, $data['info']); | 
					
						
							| 
									
										
										
										
											2011-08-17 23:12:41 +08:00
										 |  |  | 			 | 
					
						
							| 
									
										
										
										
											2011-08-19 00:08:04 +08:00
										 |  |  | 			// Set Any Notice Messages
 | 
					
						
							|  |  |  | 			$data['notice'] = "QSO Added"; | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 			$this->load->view('layout/header'); | 
					
						
							|  |  |  | 			$this->load->view('contest/log', $data); | 
					
						
							|  |  |  | 			$this->load->view('layout/footer'); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2011-08-17 23:12:41 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2011-08-19 00:08:04 +08:00
										 |  |  | 	/* | 
					
						
							|  |  |  | 		Create a contest, these are linked to templates for scoring information. contests are per entry like a weekly RSGB Club contest etc. | 
					
						
							|  |  |  | 	*/ | 
					
						
							| 
									
										
										
										
											2011-08-17 23:12:41 +08:00
										 |  |  | 	public function create() { | 
					
						
							| 
									
										
										
										
											2011-08-20 05:10:53 +08:00
										 |  |  | 		$this->load->model('logbook_model'); | 
					
						
							| 
									
										
										
										
											2011-08-20 00:12:13 +08:00
										 |  |  | 		$this->load->model('user_model'); | 
					
						
							| 
									
										
										
										
											2011-08-20 05:31:41 +08:00
										 |  |  | 		$this->load->model('contests'); | 
					
						
							| 
									
										
										
										
											2011-08-20 00:12:13 +08:00
										 |  |  | 		if(!$this->user_model->authorize(2)) { $this->session->set_flashdata('notice', 'You\'re not allowed to do that!'); redirect('dashboard'); } | 
					
						
							| 
									
										
										
										
											2011-08-20 05:10:53 +08:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2011-08-17 23:12:41 +08:00
										 |  |  | 		$data['templates'] = $this->contests->list_templates(); | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		$this->load->helper(array('form', 'url')); | 
					
						
							| 
									
										
										
										
											2011-08-19 00:08:04 +08:00
										 |  |  | 		 | 
					
						
							|  |  |  | 		// Run Validation
 | 
					
						
							| 
									
										
										
										
											2011-08-17 23:12:41 +08:00
										 |  |  | 		$this->load->library('form_validation'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		$this->form_validation->set_rules('contest_name', 'Contest Name', 'required'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if ($this->form_validation->run() == FALSE) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			$this->load->view('layout/header'); | 
					
						
							|  |  |  | 			$this->load->view('contest/create', $data); | 
					
						
							|  |  |  | 			$this->load->view('layout/footer'); | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			$this->load->model('contests'); | 
					
						
							|  |  |  | 			$this->contests->create_contest(); | 
					
						
							|  |  |  | 			redirect('contest'); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2011-08-19 00:08:04 +08:00
										 |  |  | 	/* | 
					
						
							|  |  |  | 		Create a template, Contest Templates are sets of parameters for a series or single contest selecting items like scoring, bands and modes available. | 
					
						
							|  |  |  | 	*/ | 
					
						
							| 
									
										
										
										
											2011-08-17 23:12:41 +08:00
										 |  |  | 	public function add_template() { | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2011-08-20 00:12:13 +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-08-20 05:10:53 +08:00
										 |  |  | 		 | 
					
						
							| 
									
										
										
										
											2011-08-17 23:12:41 +08:00
										 |  |  | 		$this->load->helper(array('form', 'url')); | 
					
						
							|  |  |  | 		$this->load->library('form_validation'); | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 		$this->form_validation->set_rules('contest_name', 'Contest Name', 'required'); | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 		if ($this->form_validation->run() == FALSE) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			$this->load->view('layout/header'); | 
					
						
							|  |  |  | 			$this->load->view('contest/add_template'); | 
					
						
							|  |  |  | 			$this->load->view('layout/footer'); | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			$this->load->model('contests'); | 
					
						
							|  |  |  | 			$this->contests->create_template(); | 
					
						
							|  |  |  | 			redirect('contest'); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2011-08-20 00:12:13 +08:00
										 |  |  | } |