| 
									
										
										
										
											2020-02-18 17:49:27 +08:00
										 |  |  | <?php | 
					
						
							|  |  |  | defined('BASEPATH') OR exit('No direct script access allowed'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class Distances extends CI_Controller { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     function __construct() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         parent::__construct(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $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'); } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function index() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         // Render Page
 | 
					
						
							|  |  |  |         $data['page_title'] = "Distances worked"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         function js_str($s) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             return '"' . addcslashes($s, "\0..\37\"\\") . '"'; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         function js_array($array) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             $temp = array_map('js_str', $array); | 
					
						
							|  |  |  |             return '[' . implode(',', $temp) . ']'; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $data['bands_available'] = js_array($this->config->item('bands_available')); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $this->load->view('interface_assets/header', $data); | 
					
						
							|  |  |  |         $this->load->view('distances/index'); | 
					
						
							|  |  |  |         $this->load->view('interface_assets/footer'); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function get_distances(){ | 
					
						
							|  |  |  |         // POST data
 | 
					
						
							|  |  |  |         $postData = $this->input->post(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         //load model
 | 
					
						
							|  |  |  |         $this->load->model('Distances_model'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-20 18:55:55 +08:00
										 |  |  |         if ($this->session->userdata('user_measurement_base') == NULL) { | 
					
						
							|  |  |  |             $measurement_base = $this->config->item('measurement_base'); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         else { | 
					
						
							|  |  |  |             $measurement_base = $this->session->userdata('user_measurement_base'); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-18 17:49:27 +08:00
										 |  |  |         // get data
 | 
					
						
							| 
									
										
										
										
											2020-11-20 18:55:55 +08:00
										 |  |  |         $data = $this->Distances_model->get_distances($postData, $measurement_base); | 
					
						
							| 
									
										
										
										
											2020-02-18 17:49:27 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |         return json_encode($data); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } |