| 
									
										
										
										
											2021-08-13 03:17:18 +08:00
										 |  |  | <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* | 
					
						
							|  |  |  | 	Handles Displaying of information for Station Logbooks | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class Logbooks extends CI_Controller { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	function __construct() | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		parent::__construct(); | 
					
						
							|  |  |  | 		$this->load->helper(array('form', 'url')); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		$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'); } | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     function index() { | 
					
						
							|  |  |  | 		$this->load->model('logbooks_model'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		$data['my_logbooks'] = $this->logbooks_model->show_all(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// Render Page
 | 
					
						
							|  |  |  | 		$data['page_title'] = "Station Logbooks"; | 
					
						
							|  |  |  | 		$this->load->view('interface_assets/header', $data); | 
					
						
							|  |  |  | 		$this->load->view('logbooks/index'); | 
					
						
							|  |  |  | 		$this->load->view('interface_assets/footer'); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-13 03:36:01 +08:00
										 |  |  |     public function create()  | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		$this->load->library('form_validation'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		$this->form_validation->set_rules('stationLogbook_Name', 'Station Logbook Name', 'required'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if ($this->form_validation->run() == FALSE) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			$data['page_title'] = "Create Station Logbook"; | 
					
						
							|  |  |  | 			$this->load->view('interface_assets/header', $data); | 
					
						
							|  |  |  | 			$this->load->view('logbooks/create'); | 
					
						
							|  |  |  | 			$this->load->view('interface_assets/footer'); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		else | 
					
						
							|  |  |  | 		{	 | 
					
						
							|  |  |  |             $this->load->model('logbooks_model'); | 
					
						
							|  |  |  | 			$this->logbooks_model->add(); | 
					
						
							|  |  |  | 			 | 
					
						
							|  |  |  | 			redirect('logbooks'); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-13 04:10:43 +08:00
										 |  |  |     public function edit($id) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		$this->load->library('form_validation'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-31 16:56:45 +08:00
										 |  |  | 		$this->load->model('logbooks_model'); | 
					
						
							| 
									
										
										
										
											2021-08-24 00:34:00 +08:00
										 |  |  | 		$this->load->model('stations'); | 
					
						
							| 
									
										
										
										
											2021-08-13 04:10:43 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		$station_logbook_id = $this->security->xss_clean($id); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		$station_logbook_details_query = $this->logbooks_model->logbook($station_logbook_id); | 
					
						
							| 
									
										
										
										
											2021-09-08 00:42:35 +08:00
										 |  |  | 		$data['station_locations_array'] = $this->logbooks_model->list_logbook_relationships($station_logbook_id); | 
					
						
							| 
									
										
										
										
											2021-08-13 04:10:43 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		$data['station_logbook_details'] = $station_logbook_details_query->row(); | 
					
						
							| 
									
										
										
										
											2021-10-31 16:56:45 +08:00
										 |  |  | 		$data['station_locations_list'] = $this->stations->all_of_user(); | 
					
						
							| 
									
										
										
										
											2021-10-12 22:19:39 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		$data['station_locations_linked'] = $this->logbooks_model->list_logbooks_linked($station_logbook_id); | 
					
						
							| 
									
										
										
										
											2021-08-13 04:10:43 +08:00
										 |  |  | 		 | 
					
						
							|  |  |  | 		$data['page_title'] = "Edit Station Logbook"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-12 22:19:39 +08:00
										 |  |  | 		$this->form_validation->set_rules('station_logbook_id', 'Station Logbook Name', 'required'); | 
					
						
							| 
									
										
										
										
											2021-08-13 04:10:43 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if ($this->form_validation->run() == FALSE) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |         	$this->load->view('interface_assets/header', $data); | 
					
						
							|  |  |  |             $this->load->view('logbooks/edit'); | 
					
						
							|  |  |  |             $this->load->view('interface_assets/footer'); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         else | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             $data['notice'] = "Station Logbooks ".$this->security->xss_clean($this->input->post('station_logbook_name', true))." Updated"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-12 22:19:39 +08:00
										 |  |  | 			if($this->input->post('SelectedStationLocation') != "") { | 
					
						
							|  |  |  | 				if($this->logbooks_model->relationship_exists($this->input->post('station_logbook_id'), $this->input->post('SelectedStationLocation')) != TRUE) { | 
					
						
							| 
									
										
										
										
											2021-09-08 00:42:35 +08:00
										 |  |  | 					// If no link exisits create
 | 
					
						
							| 
									
										
										
										
											2021-10-12 22:19:39 +08:00
										 |  |  | 					$this->logbooks_model->create_logbook_location_link($this->input->post('station_logbook_id'), $this->input->post('SelectedStationLocation')); | 
					
						
							| 
									
										
										
										
											2021-09-08 00:42:35 +08:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2021-10-12 22:19:39 +08:00
										 |  |  | 			} else { | 
					
						
							|  |  |  | 				$this->logbooks_model->edit(); | 
					
						
							| 
									
										
										
										
											2021-08-24 04:56:18 +08:00
										 |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-12 22:19:39 +08:00
										 |  |  |             redirect('logbooks/edit/'.$this->input->post('station_logbook_id')); | 
					
						
							| 
									
										
										
										
											2021-08-13 04:10:43 +08:00
										 |  |  |         } | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-08 01:07:48 +08:00
										 |  |  | 	public function set_active($id) { | 
					
						
							|  |  |  | 		$this->load->model('logbooks_model'); | 
					
						
							|  |  |  | 		$this->logbooks_model->set_logbook_active($id); | 
					
						
							|  |  |  | 		$this->user_model->update_session($this->session->userdata('user_id')); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		redirect('logbooks'); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-13 03:36:01 +08:00
										 |  |  |     public function delete($id) { | 
					
						
							|  |  |  | 		$this->load->model('logbooks_model'); | 
					
						
							|  |  |  | 		$this->logbooks_model->delete($id); | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		redirect('logbooks'); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2021-08-13 03:17:18 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-12 22:19:39 +08:00
										 |  |  | 	public function delete_relationship($logbook_id, $station_id) { | 
					
						
							|  |  |  | 		$this->load->model('logbooks_model'); | 
					
						
							|  |  |  | 		$this->logbooks_model->delete_relationship($logbook_id, $station_id); | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		redirect('logbooks/edit/'.$logbook_id); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-10 06:29:29 +08:00
										 |  |  | 	public function publicslug_validate() { | 
					
						
							|  |  |  | 		$this->load->model('logbooks_model'); | 
					
						
							|  |  |  | 		$result = $this->logbooks_model->is_public_slug_available($this->input->post('public_slug')); | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		if($result == true) { | 
					
						
							|  |  |  | 			$data['slugAvailable'] = true; | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			$data['slugAvailable'] = false; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		$this->load->view('logbooks/components/publicSlugInputValidation', $data); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-10 06:51:46 +08:00
										 |  |  | 	public function save_publicslug() { | 
					
						
							| 
									
										
										
										
											2022-02-10 06:29:29 +08:00
										 |  |  | 		$this->load->model('logbooks_model'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-11 19:23:33 +08:00
										 |  |  | 		$this->load->library('form_validation'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		$this->form_validation->set_rules('public_slug', 'Public Slug', 'required|alpha_numeric'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if ($this->form_validation->run() == FALSE) | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2022-02-10 06:51:46 +08:00
										 |  |  | 			echo "<div class=\"alert alert-danger\" role=\"alert\">Oops! This Public Slug is unavailable</div>"; | 
					
						
							| 
									
										
										
										
											2022-02-11 19:23:33 +08:00
										 |  |  | 			echo validation_errors(); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		else | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			$this->load->model('logbooks_model'); | 
					
						
							|  |  |  | 			$result = $this->logbooks_model->is_public_slug_available($this->input->post('public_slug')); | 
					
						
							|  |  |  | 			 | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 			if($result == true) { | 
					
						
							|  |  |  | 				$returndata = $this->logbooks_model->save_public_slug($this->input->post('public_slug'), $this->input->post('logbook_id')); | 
					
						
							|  |  |  | 				echo "<div class=\"alert alert-success\" role=\"alert\">Public Slug Saved</div>"; | 
					
						
							|  |  |  | 			} else { | 
					
						
							|  |  |  | 				echo "<div class=\"alert alert-danger\" role=\"alert\">Oops! This Public Slug is unavailable</div>"; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2022-02-10 06:51:46 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		 | 
					
						
							| 
									
										
										
										
											2022-02-10 06:29:29 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-10 06:51:46 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-13 03:17:18 +08:00
										 |  |  | } |