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

/application/modules/group_movement/controllers/Group_movement.php

https://bitbucket.org/bo_hmb/bo_hmb
PHP | 323 lines | 247 code | 57 blank | 19 comment | 25 complexity | c3a443951598c2cfc07e8d832b25aabc MD5 | raw file
Possible License(s): Apache-2.0, MIT, LGPL-2.1, MPL-2.0-no-copyleft-exception, GPL-2.0
  1. <?php defined('BASEPATH') OR exit('No direct script access allowed');
  2. class Group_movement extends AdminController {
  3. public function __construct()
  4. {
  5. parent::__construct();
  6. $this->tanggal = date("Y-m-d");
  7. $this->jam = date("H:i:s");
  8. $this->bulan = date('m');
  9. $this->tahun = date('Y');
  10. // Module components
  11. $this->data['module'] = 'Group Movement';
  12. $this->data['pluginCss'] = $this->load->view('assets/_pluginCss', $this->data, true);
  13. $this->data['pluginJs'] = $this->load->view('assets/_pluginJs', $this->data, true);
  14. $this->load->model('M_group_movement');
  15. $this->load->model('M_schedule');
  16. // $this->output->enable_profiler(TRUE);
  17. if($this->cekCurrentUser > 0) {
  18. $this->group = $this->ion_auth->get_users_groups( $this->currentUser->id)->result();
  19. foreach ($this->group as $key => $value) {
  20. $userGroup[$value->name] = $value->description;
  21. }
  22. $this->userLevel = $userGroup;
  23. }
  24. }
  25. public function schedule()
  26. {
  27. // Page components
  28. // $this->data['userGroup'] = $this->userLevel;
  29. $this->data['pageTitle'] = 'Group Movement';
  30. $this->data['pageCss'] = $this->load->view('assets/_pageCss', $this->data, true);;
  31. $this->data['pageJs'] = $this->load->view('assets/_pageJs', $this->data, true);
  32. // $this->data['id_data'] = $this->uri->segment(3);
  33. $this->data['jadwal'] = $this->M_schedule->get_where(array('id' => $this->uri->segment(3)))->row();
  34. $this->data['cek'] = count($this->M_group_movement->get_where(array('id_jadwal' => $this->uri->segment(3)))->result());
  35. $this->data['content'] = $this->load->view('main', $this->data, true);
  36. // Render page
  37. $this->renderPage();
  38. }
  39. public function load_data($id)
  40. {
  41. $tour_code = $this->input->post('tour_code',TRUE);
  42. $arrival_date = $this->input->post('arrival_date',TRUE);
  43. $departure_date = $this->input->post('departure_date',TRUE);
  44. $carrier = $this->input->post('carrier',TRUE);
  45. $person_in_charge = $this->input->post('person_in_charge',TRUE);
  46. $contact_no = $this->input->post('contact_no',TRUE);
  47. $email_addres = $this->input->post('email_addres',TRUE);
  48. $hotel_madinah = $this->input->post('hotel_madinah',TRUE);
  49. $hotel_mekkah = $this->input->post('hotel_mekkah',TRUE);
  50. $land_transport = $this->input->post('land_transport',TRUE);
  51. $total_passengers = $this->input->post('total_passengers',TRUE);
  52. $guide_request = $this->input->post('guide_request',TRUE);
  53. $cols = array();
  54. //if (!empty($id_jadwal)) { $cols['id_jadwal'] = $id_jadwal; }
  55. if (!empty($tour_code)) { $cols['tour_code'] = $tour_code; }
  56. if (!empty($arrival_date)) { $cols['arrival_date'] = $arrival_date; }
  57. if (!empty($departure_date)) { $cols['departure_date'] = $departure_date; }
  58. if (!empty($carrier)) { $cols['carrier'] = $carrier; }
  59. if (!empty($person_in_charge)) { $cols['person_in_charge'] = $person_in_charge; }
  60. if (!empty($contact_no)) { $cols['contact_no'] = $contact_no; }
  61. if (!empty($email_addres)) { $cols['email_addres'] = $email_addres; }
  62. if (!empty($hotel_madinah)) { $cols['hotel_madinah'] = $hotel_madinah; }
  63. if (!empty($hotel_mekkah)) { $cols['hotel_mekkah'] = $hotel_mekkah; }
  64. if (!empty($land_transport)) { $cols['land_transport'] = $land_transport; }
  65. if (!empty($total_passengers)) { $cols['total_passengers'] = $total_passengers; }
  66. if (!empty($guide_request)) { $cols['guide_request'] = $guide_request; }
  67. if(array_key_exists('Super Admin', $this->userLevel)) {
  68. $where = "group_movement.active = '1' AND group_movement.id_jadwal = '".$id."'";
  69. } else {
  70. $where = "group_movement.active = '1' AND group_movement.id_jadwal = '".$id."'";
  71. }
  72. $list = $this->M_group_movement->get_datatables($where, $cols);
  73. $last_query = $this->db->last_query();
  74. // die(print_r($last_query));
  75. $iTotalRecords = $this->M_group_movement->count_all($where);
  76. $iDisplayLength = intval($_REQUEST['length']);
  77. $iDisplayLength = $iDisplayLength < 0 ? $iTotalRecords : $iDisplayLength;
  78. $iDisplayStart = intval($_REQUEST['start']);
  79. $sEcho = intval($_REQUEST['draw']);
  80. $records = array();
  81. $records["data"] = array();
  82. $end = $iDisplayStart + $iDisplayLength;
  83. $end = $end > $iTotalRecords ? $iTotalRecords : $end;
  84. $no = $iDisplayStart;
  85. foreach ($list as $r) {
  86. $no++;
  87. $btn_action = '<div class="btn-group btn-group-xs btn-group-solid">
  88. <button type="button" class="btn btn-xs blue btn-outline btn-agenda tooltips" data-container="body" data-placement="top" data-original-title="Tooltip in top" data-id="'.$r->id.'"><i class="fa fa-search"></i></button>
  89. <button type="button" class="btn btn-xs yellow btn-outline btn-edit tooltips" data-container="body" data-placement="top" data-original-title="Tooltip in top" data-id="'.$r->id.'"><i class="fa fa-edit"></i></button>
  90. <button class="btn btn-xs btn-outline red btn-update-status" data-id="'.$r->id.'" data-toggle="confirmation" data-placement="top" data-btn-ok-label="Yes" data-btn-ok-icon="icon-user-following" data-btn-ok-class="btn-success" data-btn-cancel-label="No" data-btn-cancel-icon="icon-user-unfollow" data-btn-cancel-class="btn-danger"><i class="fa fa-trash"></i></button>
  91. <button type="button" class="btn btn-xs blue btn-outline btn-reservation tooltips" data-container="body" data-placement="top" data-original-title="Tooltip in top" data-id="'.$r->id.'"><i class="fa fa-hotel"></i></button>
  92. </div>';
  93. $hotel_makkah = $this->M_group_movement->hotel($r->id_hotel_makkah);
  94. $hotel_madinah = $this->M_group_movement->hotel($r->id_hotel_madinah);
  95. $records["data"][] = array(
  96. $no,
  97. $btn_action,
  98. // $r->nm_jadwal,
  99. $r->tour_code,
  100. $r->arrival_date,
  101. $r->departure_date,
  102. $r->carrier,
  103. $r->person_in_charge,
  104. $r->contact_no,
  105. $r->email_addres,
  106. $hotel_madinah->hotel,
  107. $hotel_makkah->hotel,
  108. $r->land_transport,
  109. $r->total_passengers,
  110. $r->guide_request,
  111. );
  112. }
  113. if (isset($_REQUEST["customActionType"]) && $_REQUEST["customActionType"] == "group_action") {
  114. $records["customActionStatus"] = "OK"; // pass custom message(useful for getting status of group actions)
  115. $records["customActionMessage"] = "Group action successfully has been completed. Well done!"; // pass custom message(useful for getting status of group actions)
  116. }
  117. $records["draw"] = $sEcho;
  118. $records["recordsTotal"] = $iTotalRecords;
  119. $records["recordsFiltered"] = $iTotalRecords;
  120. echo json_encode($records);
  121. }
  122. public function load_detail()
  123. {
  124. $id = $this->input->get('id');
  125. $data['main'] = $this->m_customer->get_where(array('id' => $id ))->row();
  126. return response($this->load->view('detail', $data, TRUE), 'html');
  127. }
  128. public function load_add_form($id)
  129. {
  130. $data['id_jadwal'] = $id;
  131. $data['hotel'] = Modules::run('hotel/get_hotel_where', array('hotel.active' => '1'))->result();
  132. return response($this->load->view('add_', $data, TRUE), 'html');
  133. }
  134. public function add()
  135. {
  136. $this->validateInput();
  137. $arrhotel_makkah = $this->input->post('id_hotel_makkah');
  138. foreach($arrhotel_makkah as $val)
  139. {
  140. $hotel_makkaharr = @$hotel_makkaharr . $val. ",";
  141. }
  142. $arrhotel_madinah = $this->input->post('id_hotel_madinah');
  143. foreach($arrhotel_madinah as $val)
  144. {
  145. $hotel_madinaharr = @$hotel_madinaharr . $val. ",";
  146. }
  147. $data = array(
  148. 'id_jadwal' => $this->input->post('id_jadwal',TRUE),
  149. 'tour_code' => $this->input->post('tour_code',TRUE),
  150. 'arrival_date' => $this->input->post('arrival_date',TRUE),
  151. 'departure_date' => $this->input->post('departure_date',TRUE),
  152. 'carrier' => $this->input->post('carrier',TRUE),
  153. 'person_in_charge' => $this->input->post('person_in_charge',TRUE),
  154. 'contact_no' => $this->input->post('contact_no',TRUE),
  155. 'email_addres' => $this->input->post('email_addres',TRUE),
  156. 'id_hotel_makkah' => substr(trim($hotel_makkaharr), 0, -1),
  157. 'id_hotel_madinah' => substr(trim($hotel_madinaharr), 0, -1),
  158. 'land_transport' => $this->input->post('land_transport',TRUE),
  159. 'total_passengers' => $this->input->post('total_passengers',TRUE),
  160. 'guide_request' => $this->input->post('guide_request',TRUE),
  161. 'active' => '1',
  162. 'id_user' => $this->currentUser->id,
  163. );
  164. $query = $this->M_group_movement->_insert($data);
  165. // Check if query was success
  166. if ($query) {
  167. $response = array('status' => true, 'action' => 'Success', 'message' => 'Data berhasil ditambahkan');
  168. } else {
  169. $response = array('status' => false, 'action' => 'Failed', 'message' => 'Data gagal ditambahkan');
  170. }
  171. return response($response, 'json');
  172. }
  173. public function load_edit_form()
  174. {
  175. $id = $this->input->get('id');
  176. $data['main'] = $this->M_group_movement->get_where(array('id' => $id))->row();
  177. $data['hotel'] = Modules::run('hotel/get_hotel_where', array('hotel.active' => '1'))->result();
  178. return response($this->load->view('edit_', $data, TRUE), 'html');
  179. }
  180. public function edit()
  181. {
  182. // Check if ajax request
  183. $this->ajaxRequest();
  184. // Validate the submitted data
  185. $id = $this->input->post('id');
  186. $arrhotel_makkah = $this->input->post('id_hotel_makkah');
  187. foreach($arrhotel_makkah as $val)
  188. {
  189. $hotel_makkaharr = @$hotel_makkaharr . $val. ",";
  190. }
  191. $arrhotel_madinah = $this->input->post('id_hotel_madinah');
  192. foreach($arrhotel_madinah as $val)
  193. {
  194. $hotel_madinaharr = @$hotel_madinaharr . $val. ",";
  195. }
  196. $data = array(
  197. 'tour_code' => $this->input->post('tour_code',TRUE),
  198. 'arrival_date' => $this->input->post('arrival_date',TRUE),
  199. 'departure_date' => $this->input->post('departure_date',TRUE),
  200. 'carrier' => $this->input->post('carrier',TRUE),
  201. 'person_in_charge' => $this->input->post('person_in_charge',TRUE),
  202. 'contact_no' => $this->input->post('contact_no',TRUE),
  203. 'email_addres' => $this->input->post('email_addres',TRUE),
  204. 'id_hotel_makkah' => substr(trim($hotel_makkaharr), 0, -1),
  205. 'id_hotel_madinah' => substr(trim($hotel_madinaharr), 0, -1),
  206. 'land_transport' => $this->input->post('land_transport',TRUE),
  207. 'total_passengers' => $this->input->post('total_passengers',TRUE),
  208. 'guide_request' => $this->input->post('guide_request',TRUE),
  209. 'active' => '1',
  210. 'user_update' => $this->currentUser->id,
  211. );
  212. $query = $this->M_group_movement->_update(array('id' => $id), $data);
  213. // Check if query was success
  214. if ($query) {
  215. $results = array('status' => true, 'action' => 'Success', 'message' => 'updated successfully');
  216. } else {
  217. $results = array('status' => false, 'action' => 'Failed', 'message' => 'Failed to update');
  218. }
  219. // Return the result to the view
  220. return response($results);
  221. }
  222. public function delete()
  223. {
  224. $id = $this->input->post('id');
  225. $data = array(
  226. 'active' => '0',
  227. 'user_update' => $this->currentUser->id,
  228. );
  229. // die(print_r($data));
  230. $query = $this->M_group_movement->_update(array('id' => $id), $data);
  231. // Check if query was success
  232. if ($query) {
  233. $results = array('status' => true, 'action' => 'Success', 'message' => 'berhasil');
  234. } else {
  235. $results = array('status' => false, 'action' => 'Failed', 'message' => 'Gagal');
  236. }
  237. // Return the result to the view
  238. return response($results, 'json');
  239. }
  240. public function validateInput()
  241. {
  242. // Load form validation library
  243. $this->load->library('form_validation');
  244. $this->form_validation->set_rules('tour_code', 'tour code', 'trim|required');
  245. $this->form_validation->set_rules('arrival_date', 'arrival date', 'trim|required');
  246. $this->form_validation->set_rules('departure_date', 'departure date', 'trim|required');
  247. $this->form_validation->set_rules('carrier', 'carrier', 'trim|required');
  248. $this->form_validation->set_rules('email_addres', 'email addres', 'trim|required');
  249. $this->form_validation->set_rules('land_transport', 'land transport', 'trim|required');
  250. $this->form_validation->set_rules('total_passengers', 'total passengers', 'trim|required');
  251. $this->form_validation->set_rules('guide_request', 'guide request', 'trim|required');
  252. // Run the validation
  253. if ($this->form_validation->run() === false) {
  254. $response = array(
  255. 'status' => false,
  256. 'action' => 'Failed',
  257. 'message' => $this->form_validation->error_string('<h5>', '</h5>')
  258. );
  259. return response($response, 'json');
  260. }
  261. }
  262. }
  263. ?>