PageRenderTime 49ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/application/controllers/geofence_mgnt_ctrl.php

https://bitbucket.org/tonygeorge2017/icat2
PHP | 199 lines | 140 code | 25 blank | 34 comment | 13 complexity | c48608a32b7030cd265437b87eb7aaf3 MD5 | raw file
Possible License(s): LGPL-2.1
  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2. class Geofence_mgnt_ctrl extends CI_Controller {
  3. /*
  4. * class constructor
  5. */
  6. public function __construct()
  7. {
  8. parent::__construct();
  9. $this->load->library('pagination');
  10. $this->load->model('common_model');
  11. $this->load->model('geofence_mgnt_model');
  12. $this->load->helper(array('form', 'url'));
  13. $GLOBALS['clientList']=array();
  14. $GLOBALS['vehicleGroupList']=array();
  15. $GLOBALS['vehicleList']=array();
  16. $GLOBALS['routeList']=array();
  17. $GLOBALS['vhRouteList']=array();
  18. $GLOBALS['editrouteList']=array();
  19. $GLOBALS['vhID']=null;
  20. $GLOBALS['vehicleGroupID']=null;
  21. $GLOBALS['deviceID']=null;
  22. $GLOBALS['editVhID']=null;
  23. $GLOBALS['routeID']=array();
  24. $GLOBALS['outcome']=null;
  25. $GLOBALS['pageLink']=null;
  26. //whether event log is required or not(i.e. 'N' not required, 'Y' required)
  27. //to get user ip and host name
  28. $host_name = exec("hostname"); //to get "hostname"
  29. $host_name = trim($host_name); //remove any spaces before and after
  30. $ip = gethostbyname($host_name);
  31. $GLOBALS['ip']= $host_name."[".$ip."]";
  32. }
  33. /*
  34. * This function call automatically when call this ctrl
  35. */
  36. public function index()
  37. {
  38. $this->table_pagination();
  39. }
  40. /*
  41. * This function is used to validate the posted values
  42. * before store.
  43. */
  44. public function vh_route_validation(){
  45. $this->form_validation->set_message('required', '%s required');
  46. $GLOBALS['deviceID']=(null!=($this->input->post('Device'))?$this->input->post('Device'):null);
  47. $GLOBALS['routeID']=(null!=($this->input->post('RouteArr'))?$this->input->post('RouteArr'):null);
  48. $routeArray=$GLOBALS['routeID'];
  49. //log_message('debug',"********testtest".print_r($GLOBALS,true));
  50. //log_message('debug','RouteArray'.print_r($routeArray,true));
  51. $fence_data=array();
  52. foreach ($routeArray as $indx=>$value)
  53. {
  54. $fence_data[$indx]["vh_rt_device_id"]=$GLOBALS['deviceID'];
  55. $fence_data[$indx]["vh_rt_route_id"]=$value;
  56. $temp=$this->input->post('AlertType_'.$value);
  57. $fence_data[$indx]["vh_rt_alert_type"]=$temp[0];
  58. }
  59. //log_message('debug','RouteArray'.print_r($fence_data,true));
  60. $this->form_validation->set_rules('Device', 'Device', 'required');
  61. $this->form_validation->set_rules('RouteArr', 'Route', 'required');
  62. if ($this->form_validation->run() != FALSE)
  63. {
  64. //log_message("debug","#####test1");
  65. //$data['vh_rt_vehicle_id']=$GLOBALS['deviceID'];
  66. //$data['vh_rt_route_id']=$GLOBALS['routeID'];
  67. if($GLOBALS['vhID']==null)//insert
  68. {
  69. //log_message("debug","#####test2");
  70. if($this->geofence_mgnt_model->insert_edit_vhroute($fence_data))
  71. {
  72. $GLOBALS['outcome']='<div style="color: green;">Route assigning succeed.</div>';
  73. $this->clear_all();
  74. }
  75. else{
  76. $GLOBALS['outcome']='<div style="color: red;">Route assigning failed.</div>';
  77. }
  78. }
  79. else {//edit
  80. //log_message("debug","#####test3");
  81. if($this->geofence_mgnt_model->insert_edit_vhroute($fence_data, $GLOBALS['vhID'], "edit"))
  82. {
  83. $GLOBALS['outcome']='<div style="color: green;">Updation succeed.</div>';
  84. $this->clear_all();
  85. }
  86. else{
  87. $GLOBALS['outcome']='<div style="color: red;">Updation failed.</div>';
  88. }
  89. }
  90. }
  91. $this->table_pagination();
  92. }
  93. private function clear_all()
  94. {
  95. $GLOBALS['vhID']=null;
  96. $GLOBALS['vehicleGroupID']=null;
  97. $GLOBALS['deviceID']=null;
  98. $GLOBALS['routeID']=null;
  99. }
  100. /* This function is used to get the vehicle for the selected vehicle group and return back the list of
  101. * vehicles in JSON format with out refresh the page.
  102. * $vhGrp - vehicel group id
  103. * Return type - JSON string
  104. */
  105. public function get_vhl_grp_vehicle($vhGrp=null, $vhID=0)
  106. {
  107. $vhl_grp_vehicle=null;
  108. if($vhGrp!=null)
  109. {
  110. $vhl_grp_vehicle=json_encode($this->geofence_mgnt_model->get_all_vhGp_vehicle($vhGrp, $vhID));
  111. }
  112. echo($vhl_grp_vehicle);
  113. }
  114. /*
  115. * This function is used to edit the route details
  116. */
  117. public function edit_routedetails($vhRouteOrVehicleID, $opt='edit')
  118. {
  119. $delete=($opt==md5('delete'))?true:false;
  120. $result=$this->geofence_mgnt_model->get_VhRouteList( null, null, $vhRouteOrVehicleID, $delete);
  121. print_r($result);
  122. if($result!=null)
  123. {
  124. $GLOBALS['clientID']=isset($result[0]['route_client_id'])?$result[0]['route_client_id']:null;
  125. if($opt=='edit')
  126. {
  127. $GLOBALS['vhID']=isset($result[0]['vh_rt_device_id'])?$result[0]['vh_rt_device_id']:null;
  128. $GLOBALS['editVhID']=$GLOBALS['deviceID']=isset($result[0]['vh_rt_device_id'])?$result[0]['vh_rt_device_id']:null;
  129. $GLOBALS['routeID']=isset($result[0]['vh_rt_route_id'])?$result[0]['vh_rt_route_id']:null;
  130. foreach ($result as $row)
  131. $GLOBALS['editrouteList'][$row["vh_rt_route_id"]]=$row["alert_type"];
  132. }
  133. else if($opt==md5('delete'))
  134. {
  135. if($this->geofence_mgnt_model->insert_edit_vhroute(null, $vhRouteOrVehicleID, 'delete'))
  136. {
  137. $GLOBALS['outcome']='<div style="color: green;">Removed successfully.</div>';
  138. }
  139. else
  140. {
  141. $GLOBALS['outcome']='<div style="color: red;">Removal failed.</div>';
  142. }
  143. }
  144. }
  145. $this->table_pagination();
  146. }
  147. /*
  148. * This function is used to perform the pagination.
  149. */
  150. public function table_pagination($pageNo=0)
  151. {
  152. $device_id=($GLOBALS['deviceID']!=null)? $GLOBALS['editVhID']:0;
  153. $GLOBALS['device_list']=$this->geofence_mgnt_model->get_all_device($device_id);
  154. $GLOBALS['routeList']=$this->geofence_mgnt_model->get_RouteList();
  155. $GLOBALS['vhRouteList']=$this->geofence_mgnt_model->get_VhRouteList( ROW_PER_PAGE, $pageNo);
  156. $config['uri_segment']=URI_SEGMENT_FOR_FOUR;
  157. $config['base_url'] = base_url("index.php/geofence_mgnt_ctrl/table_pagination");
  158. $config['total_rows'] = count($this->geofence_mgnt_model->get_VhRouteList());
  159. $config['per_page']=ROW_PER_PAGE;
  160. $this->pagination->initialize($config);
  161. $GLOBALS['pageLink']= $this->pagination->create_links();
  162. $this->display();
  163. }
  164. /*
  165. * This function is used to render the view
  166. */
  167. private function display()
  168. {
  169. $this->common_model->menu_display();
  170. $this->load->view('header_footer/header',$GLOBALS);
  171. $this->load->view('geofence_mgnt_view',$GLOBALS);
  172. $this->load->view('header_footer/footer');
  173. }
  174. }