X7ROOT File Manager
Current Path:
/home/hamdjcne/app.hamdalillahitravel.com/app/Controllers
home
/
hamdjcne
/
app.hamdalillahitravel.com
/
app
/
Controllers
/
ðŸ“
..
📄
.DS_Store
(6 KB)
📄
Accounts.php
(52.25 KB)
📄
Activity.php
(4.49 KB)
📄
Analytics.php
(12.22 KB)
📄
Api.php
(41.41 KB)
📄
Auth.php
(34.64 KB)
📄
BaseController.php
(1.77 KB)
📄
Dashboard.php
(42.95 KB)
📄
Notification.php
(6.22 KB)
📄
Order.php
(118.16 KB)
📄
Service.php
(61.77 KB)
📄
Settings.php
(40.13 KB)
📄
Staff.php
(67.17 KB)
📄
Tour.php
(32.09 KB)
📄
Wallets.php
(43.15 KB)
📄
Webhook.php
(5.14 KB)
Editing: Dashboard.php
<?php namespace App\Controllers; class Dashboard extends BaseController { public function index($param1='', $param2='', $param3='', $param4='') { // check login $log_id = $this->session->get('hdt_id'); if(empty($log_id)) return redirect()->to(site_url('auth')); $mod = 'dashboard'; $role_id = $this->Crud->read_field('id', $log_id, 'user', 'role_id'); $role = strtolower($this->Crud->read_field('id', $role_id, 'access_role', 'name')); if($role == 'member'){ $name = $this->Crud->read_field('id', $log_id, 'user', 'company_name'); } else{ $name = $this->Crud->read_field('id', $log_id, 'user', 'fullname'); } $role_c = $this->Crud->module($role_id, $mod, 'create'); $role_r = $this->Crud->module($role_id, $mod, 'read'); $role_u = $this->Crud->module($role_id, $mod, 'update'); $role_d = $this->Crud->module($role_id, $mod, 'delete'); if($role_r == 0){ // return redirect()->to(site_url('profile')); } $data['log_id'] = $log_id; $data['role'] = $role; $data['name'] = $name; $data['role_c'] = $role_c; $form_link = site_url($mod); if($param1){$form_link .= '/'.$param1;} if($param2){$form_link .= '/'.$param2.'/';} if($param3){$form_link .= '/'.$param3.'/';} if($param4){$form_link .= $param4;} // pass parameters to view $data['param1'] = $param1; $data['param2'] = $param2; $data['param3'] = $param3; $data['param4'] = $param4; $data['form_link'] = rtrim($form_link, '/'); if($param1 == 'manage'){ if ($param2 == 'view' && $param3) { $tour = $this->Crud->read_single('id', $param3, 'tours'); if (!empty($tour)) { $itineraries = $this->Crud->read_single_order('tour_id', $param3, 'itinerary', 'day_number', 'asc'); $prices = $this->Crud->read_single_order('tour_id', $param3, 'tour_prices', 'amount', 'asc'); $data['tour'] = $tour[0]; $data['itineraries'] = $itineraries; $data['prices'] = $prices; } } } // record listing if($param1 == 'activity_load') { $limit = $param2; $offset = $param3; $count = 0; $rec_limit = 7; $item = ''; if($limit == '') {$limit = $rec_limit;} if($offset == '') {$offset = 0;} $search = $this->request->getVar('search'); if(!empty($this->request->getPost('start_date'))) { $start_date = $this->request->getPost('start_date'); } else { $start_date = ''; } if(!empty($this->request->getPost('end_date'))) { $end_date = $this->request->getPost('end_date'); } else { $end_date = ''; } if(!$log_id) { $item = '<div class="text-center text-muted">Session Timeout! - Please login again</div>'; } else { $query = $this->Crud->filter_activity($limit, $offset, $log_id, $search, $start_date, $end_date); $all_rec = $this->Crud->filter_activity('', '', $log_id, $search, $start_date, $end_date); if(!empty($all_rec)) { $counts = count($all_rec); } else { $counts = 0; } $a =0; if(!empty($query)) { foreach($query as $q) { $id = $q->id; $type = $q->item; $type_id = $q->item_id; $action = $q->action; $reg_date = date('M d, Y h:i A', strtotime($q->reg_date)); $timespan = $this->Crud->timespan(strtotime($q->reg_date)); $icon = 'solution'; if($type != 'voucher' && $type != 'wallet')continue; if($a>5)break; $item .= ' <tr> <td> <div class="symbol symbol-40px"> <span class="symbol-label bg-light-info"> <i class="ki-duotone ki-abstract-24 fs-2x text-info"><span class="path1"></span><span class="path2"></span></i> </span> </div> </td> <td class="ps-0"> <a href="javacript:;" class="text-gray-900 fw-bold text-hover-success mb-1 fs-6">'.$action.'</a> </td> <td> <span class="text-gray-900 fw-bold d-block fs-6">'.$timespan.'</span> </td> </tr> '; $a++; } } } if(empty($item)) { $resp['item'] = '<tr><td colspan="8"> <div class="text-center text-muted"> <br/><br/><br/><br/> <i class="ki-duotone ki-scroll fs-5x"><span class="path1"></span><span class="path2"></span><span class="path3"></span></i><br/><br/>No Activity Returned </div></td></tr> '; } else { $resp['item'] = $item; } $resp['count'] = $counts; $more_record = $counts - ($offset + $rec_limit); $resp['left'] = $more_record; if($counts > ($offset + $rec_limit)) { // for load more records $resp['limit'] = $rec_limit; $resp['offset'] = $offset + $limit; } else { $resp['limit'] = 0; $resp['offset'] = 0; } $wallets = $this->Crud->read_single('user_id', $log_id, 'wallet'); $wallet = 0; if(!empty($wallets)){ foreach($wallets as $wall){ if($wall->type == 'credit'){ $wallet += (float)$wall->amount; } if($wall->type == 'debit'){ $wallet -= (float)$wall->amount; } } } $resp['wallet'] = curr.number_format($wallet,2); $overview = 0; $approved = 0; $approval_pending = 0; $profile_pending = 0; $accountz = $this->Crud->read_single('is_member', 1,'user'); if(!empty($accountz)){ foreach($accountz as $acc){ $overview++; if($acc->approval == 1)$approved++; if($acc->approval == 0)$approval_pending++; if($acc->profile_status == 0)$profile_pending++; } } $resp['overview'] = number_format($overview); $resp['approved'] = number_format($approved); $resp['approval_pending'] = number_format($approval_pending); $resp['profile_pending'] = number_format($profile_pending); echo json_encode($resp); die; } if($param1 == 'invoice_load') { $limit = $param2; $offset = $param3; $count = 0; $rec_limit = 7; $item = ''; if($limit == '') {$limit = $rec_limit;} if($offset == '') {$offset = 0;} if(!$log_id) { $item = '<div class="text-center text-muted">Session Timeout! - Please login again</div>'; } else { $query = $this->Crud->filter_invoices($limit, $offset, $log_id, 'all', '', '', ''); $all_rec = $this->Crud->filter_invoices('', '', $log_id, 'all', '', '', ''); if(!empty($all_rec)) { $counts = count($all_rec); } else { $counts = 0; } $a =0; if(!empty($query)) { foreach ($query as $q) { $invoice_number = $q->invoice_number ?? ''; $amount = number_format($q->amount, 2); $currency = $q->currency ?: 'NGN'; $payment_method = $q->payment_method ? ucfirst($q->payment_method) : 'Not Set'; $payment_status = ucfirst($q->payment_status ?? 'Pending'); $reg_date = date('M d, Y h:i A', strtotime($q->reg_date)); $due_date = $q->due_date ? date('M d, Y', strtotime($q->due_date)) : 'No Due Date'; $timespan = $this->Crud->timespan(strtotime($q->reg_date)); $remark = $q->remark ?? ''; if ($a > 5) break; $item .= ' <tr> <!-- Icon --> <td> <div class="symbol symbol-40px"> <span class="symbol-label bg-light-info"> <i class="ki-duotone ki-abstract-24 fs-2x text-info"><span class="path1"></span><span class="path2"></span></i> </span> </div> </td> <!-- Invoice Number --> <td> <span class="fw-bold text-dark">#' . $invoice_number . '</span> </td> <!-- Amount + Currency --> <td> <span>' . $currency . ' ' . $amount . '</span> </td> <!-- Payment Method --> <td> <span>' . $payment_method . '</span> </td> <!-- Payment Status --> <td> <span class="badge badge-light-' . ($payment_status === 'Paid' ? 'success' : ($payment_status === 'Pending' ? 'warning' : 'danger')) . '">' . $payment_status . '</span> </td> <!-- Due Date --> <td> <span>' . $due_date . '</span> </td> <!-- Remark --> <td> <span>' . $remark . '</span> </td> <!-- Time Info --> <td> <span class="fw-bold">' . $timespan . '</span><br> <small class="text-muted">' . $reg_date . '</small> </td> </tr>'; $a++; } } } if(empty($item)) { $resp['item'] = '<tr><td colspan="8"> <div class="text-center text-muted"> <br/><br/><br/><br/> <i class="ki-duotone ki-scroll fs-5x"><span class="path1"></span><span class="path2"></span><span class="path3"></span></i><br/><br/>No Invoice Returned </div></td></tr> '; } else { $resp['item'] = $item; } $resp['count'] = $counts; $more_record = $counts - ($offset + $rec_limit); $resp['left'] = $more_record; if($counts > ($offset + $rec_limit)) { // for load more records $resp['limit'] = $rec_limit; $resp['offset'] = $offset + $limit; } else { $resp['limit'] = 0; $resp['offset'] = 0; } echo json_encode($resp); die; } // record listing if($param1 == 'announcement_load') { $limit = $param2; $offset = $param3; $rec_limit = 7; $item = ''; if(empty($limit)) {$limit = $rec_limit;} if(empty($offset)) {$offset = 0;} if(!empty($this->request->getPost('status'))) { $status = $this->request->getPost('status'); } else { $status = ''; } $search = $this->request->getPost('search'); if (!empty($this->request->getPost('start_date'))) { $start_date = $this->request->getPost('start_date'); $this->session->set('start_date', $start_date); } else { $start_date = ''; } if (!empty($this->request->getPost('end_date'))) { $end_date = $this->request->getPost('end_date'); $this->session->set('end_date', $end_date); } else { $end_date = ''; } $items = ' '; //echo $status; $log_id = $this->session->get('hdt_id'); if(!$log_id) { $item = '<div class="text-center text-muted">Session Timeout! - Please login again</div>'; } else { $query = $this->Crud->filter_announcement($limit, $offset, $log_id, '', '', ''); $all_rec = $this->Crud->filter_announcement('', '', $log_id, '', '', ''); if(!empty($all_rec)) { $counts = count($all_rec); } else { $counts = 0; } $data['count'] = $counts; if(!empty($query)) { foreach($query as $q) { $id = $q->id; $title = $q->title; $content = $q->content; $to_id = $q->to_id; $user_i = $q->from_id; $reg_date = date('M d, Y h:i A', strtotime($q->reg_date)); $user = $this->Crud->read_field('id', $user_i, 'user', 'fullname'); if(empty($user)){ $user = $this->Crud->read_field('id', $user_i, 'user', 'company_name'); } $st = ''; $all_btn = ' <a href="javascript:;" class="pop me-2 btn btn-icon btn-primary btn-active-color-light btn-sm" data-bs-toggle="tooltip" data-bs-placement="top" title="View Announcement" pageTitle="View Announcement '.$title.'" pageName="'.site_url('accounts/announcement/manage/view/'.$id).'"> <i class="ki-duotone ki-eye fs-2"><span class="path1"></span><span class="path2"></span><span class="path3"></span><span class="path4"></span><span class="path5"></span></i> </a>'; $item .= ' <tr> <td><span class="text-muted small">' . $reg_date . '</span></td> <td>' . ucwords($title) . '</td> <td class="text-right"> <div class="d-flex justify-content-end flex-shrink-0">' . $all_btn . '</div> </td> </tr>'; } } } if(empty($item)) { $resp['item'] = $items.' <tr><td colspan="8"><div class="text-center text-muted"> <br/><br/><br/><br/> <i class="ki-outline ki-notification-bing" style="font-size:150px;"> </i><br/><br/>No Annoucement Returned </div></td></tr> '; } else { $resp['item'] = $items . $item; } $resp['count'] = $counts; $more_record = $counts - ($offset + $rec_limit); $resp['left'] = $more_record; if($counts > ($offset + $rec_limit)) { // for load more records $resp['limit'] = $rec_limit; $resp['offset'] = $offset + $limit; } else { $resp['limit'] = 0; $resp['offset'] = 0; } echo json_encode($resp); die; } // record listing if($param1 == 'load_event') { $limit = $param2; $offset = $param3; $rec_limit = 7; $item = ''; if(empty($limit)) {$limit = $rec_limit;} if(empty($offset)) {$offset = 0;} if(!empty($this->request->getPost('status'))) { $status = $this->request->getPost('status'); } else { $status = ''; } $search = $this->request->getPost('search'); //echo $status; $log_id = $this->session->get('hdt_id'); if(!$log_id) { $item = '<div class="text-center text-muted">Session Timeout! - Please login again</div>'; } else { $all_rec = $this->Crud->filter_events('', '', $log_id, $status, $search); if(!empty($all_rec)) { $counts = count($all_rec); } else { $counts = 0; } $query = $this->Crud->filter_events($limit, $offset, $log_id, $status, $search); if(!empty($query)) { foreach($query as $q) { $id = $q->id; $reg_date = date('M d, Y h:i A', strtotime($q->reg_date)); $title = $q->title; $img = $q->image; $description = $q->description; $start_date = $q->start_date; $end_date = $q->end_date; $entry_type = $q->entry_type; $status = $q->status; $images = ''; if(!empty($img))$images = '<img src="' . site_url($img) . '" height="40px" width="40px" class="img-responsive">'; //$approve = ''; if($status == 1) { $colors = 'success'; $approve_text = 'Approved'; $approved = '<span class="text-primary"><i class="ri-check-circle-line"></i></span> '; } else { $colors = 'danger'; $approve_text = 'Not Approved'; } $all_btn = ' <a href="javascript:;" class="pop me-2 btn btn-icon btn-primary btn-active-color-light btn-sm" data-bs-toggle="tooltip" data-bs-placement="top" title="View Events" pageTitle="View Events '.$title.'" pageName="'.site_url('events/index/manage/view/'.$id).'"> <i class="ki-duotone ki-eye fs-2"><span class="path1"></span><span class="path2"></span><span class="path3"></span><span class="path4"></span><span class="path5"></span></i> </a> '; // add manage buttons if($role_u != 1) { $all_btn .= ''; } else { $all_btn .= ' <a href="javascript:;" class="pop btn btn-icon btn-success btn-active-color-light btn-sm me-2" pageTitle="Edit Events '.$title.'" pagesize="modal-md" data-bs-toggle="tooltip" data-bs-placement="top" title="Edit Events" pageName="'.site_url($mod.'/index/manage/edit/'.$id).'"> <i class="ki-duotone ki-pencil fs-2"><span class="path1"></span><span class="path2"></span></i> </a> <a href="javascript:;" class="pop me-2 btn btn-icon btn-danger btn-active-color-light btn-sm" data-bs-toggle="tooltip" data-bs-placement="top" title="Delete Events" pageTitle="Delete Events '.$title.'" pageName="'.site_url($mod.'/index/manage/delete/'.$id).'"> <i class="ki-duotone ki-trash fs-2"><span class="path1"></span><span class="path2"></span><span class="path3"></span><span class="path4"></span><span class="path5"></span></i> </a> '; } $type = '<span class="text-success small">Free</span>'; if($entry_type > 0){ $type = '<span class="text-success small">Paid</span>'; } $start = date('Y-m-d H:iA', strtotime($q->start_date)); $end = date('Y-m-d H:i', strtotime($q->start_date)); $item .= ' <tr> <td> <div class="user-card"> <div class="user-name"> <span class="tb-lead">' . ucwords($title) . '</span><br> '.$type.' </div> </div> </td> <td><span class=" text">'.$start.'</span></td> <td> <div class="d-flex justify-content-end flex-shrink-0"> ' . $all_btn . '</div> </td> </tr> '; } } } if(empty($item)) { $resp['item'] = ' <tr><td colspan="8"><div class="text-center text-muted"> <br/><br/><br/> <i class="ki-outline ki-calendar" style="font-size:150px;"></i><br/><br/>'.translate_phrase('No Events Returned').' </div></td></tr> '; } else { $resp['item'] = $item; if($offset >= 25){ $resp['item'] = $item; } } $resp['count'] = $counts; $more_record = $counts - ($offset + $rec_limit); $resp['left'] = $more_record; if($counts > ($offset + $rec_limit)) { // for load more records $resp['limit'] = $rec_limit; $resp['offset'] = $offset + $limit; } else { $resp['limit'] = 0; $resp['offset'] = 0; } echo json_encode($resp); die; } if($param1 == 'manage') { // view for form data posting return view('dashboard_form', $data); } else { $data['title'] = 'Dashboard - '.app_name; $data['page_active'] = $mod; return view('dashboard', $data); } } public function profile_update(){ $log_id = $this->session->get('hdt_id'); if(empty($log_id)) return redirect()->to(site_url('auth')); if ($this->request->getMethod() !== 'post') { return $this->response->setJSON(['success' => false, 'message' => 'Invalid request method.']); } $validation = \Config\Services::validation(); // Define validation rules $rules = [ 'fullname' => 'required|min_length[3]|max_length[100]', 'address' => 'required|min_length[5]', 'rc_no' => 'required|min_length[3]', 'proof_of_payment' => 'uploaded[proof_of_payment]|max_size[proof_of_payment,2048]|ext_in[proof_of_payment,pdf,jpg,png]', 'cac_certificate' => 'uploaded[cac_certificate]|max_size[cac_certificate,2048]|ext_in[cac_certificate,pdf,jpg,png]', ]; // Validate request if (!$this->validate($rules)) { return $this->response->setJSON(['success' => false, 'message' => implode(", ", $validation->getErrors())]); } // Process file uploads $uploadPath = 'assets/images/member/'.$log_id.'/'; $proofPaymentFile = $this->request->getFile('proof_of_payment'); $proofPaymentName = $proofPaymentFile->getRandomName(); $proofPaymentFile->move($uploadPath, $proofPaymentName); $cacCertificateFile = $this->request->getFile('cac_certificate'); $cacCertificateName = $cacCertificateFile->getRandomName(); $cacCertificateFile->move($uploadPath, $cacCertificateName); $cac2_7Name = null; if ($this->request->getFile('cac_2_7')->isValid()) { $cac2_7File = $this->request->getFile('cac_2_7'); $cac2_7Name = $cac2_7File->getRandomName(); $cac2_7File->move($uploadPath, $cac2_7Name); } // Process optional fields $iataNumber = ($this->request->getPost('iata_member') == 'Yes') ? $this->request->getPost('iata_number') : null; $nahconLicense = ($this->request->getPost('nahcon_registered') == 'Yes') ? $this->request->getPost('nahcon_license') : null; $website = ($this->request->getPost('has_website') == 'Yes') ? $this->request->getPost('website') : null; // Save to database $data = [ 'fullname' => $this->request->getPost('fullname'), 'address' => $this->request->getPost('address'), 'zone' => $this->request->getPost('zone'), 'rc_no' => $this->request->getPost('rc_no'), 'proof_of_payment' => $uploadPath.''.$proofPaymentName, 'cac_certificate' => $uploadPath.''.$cacCertificateName, 'cac_2_7' => $uploadPath.''.$cac2_7Name, 'iata_number' => $iataNumber, 'nahcon_license' => $nahconLicense, 'website' => $website, 'profile_status' => 1, ]; if ($this->Crud->updates('id', $log_id, 'user', $data)) { return $this->response->setJSON(['success' => true, 'message' => 'Transaction successfully saved! Pending Approval!']); } else { return $this->response->setJSON(['success' => false, 'message' => 'Database error, please try again.']); } } public function service($param1 = '') { if ($param1 == 'flight') { if ($this->request->getMethod() !== 'post') { return $this->response->setJSON(['status' => 'error', 'message' => 'Invalid request method.']); } $data = [ 'user_id' => $this->session->get('hdt_id') ?? 0, // adjust based on auth logic 'trip_type' => trim($this->request->getPost('trip_type')), 'travel_class' => trim($this->request->getPost('travel_class')), 'from_city' => trim($this->request->getPost('from_city')), 'to_city' => trim($this->request->getPost('to_city')), 'departure_date' => trim($this->request->getPost('departure_date')), 'return_date' => trim($this->request->getPost('return_date')), 'adults' => (int) $this->request->getPost('adults'), 'children' => (int) $this->request->getPost('children'), 'infants' => (int) $this->request->getPost('infants'), 'booking_status' => 'Pending', 'reg_date' => date('Y-m-d H:i:s'), 'updated_date' => date('Y-m-d H:i:s') ]; $data['passenger_count'] = $data['adults'] + $data['children'] + $data['infants']; // Validation logic (same as earlier) $errors = []; if (empty($data['from_city']) || empty($data['to_city']) || empty($data['departure_date']) || $data['adults'] < 1) { $errors[] = 'All required fields must be filled correctly.'; } if ($data['trip_type'] === 'Round Trip' && empty($data['return_date'])) { $errors[] = 'Return date is required for round trip.'; } if (!empty($data['return_date']) && strtotime($data['return_date']) < strtotime($data['departure_date'])) { $errors[] = 'Return date must be after departure date.'; } if (!empty($errors)) { return $this->response->setJSON(['status' => 'error', 'message' => implode('<br>', $errors)]); } $ins_rec = $this->Crud->create('flight_request', $data); if ($ins_rec > 0) { // ✅ Step 2: Create general request $gen_req = [ 'user_id' => $data['user_id'], 'service_type' => 'flight', 'service_id' => $ins_rec, 'status' => 'pending', 'request_date' => date('Y-m-d H:i:s'), 'reg_date' => date('Y-m-d H:i:s') ]; $this->Crud->create('service_request', $gen_req); // ✅ Step 3: Notify admin $this->_send_flight_notification($data); // You already have this method return $this->response->setJSON([ 'status' => 'success', 'message' => 'Flight request submitted successfully!' ]); } else { return $this->response->setJSON([ 'status' => 'error', 'message' => 'Try Again Later' ]); } } if($param1 == 'hotel'){ $user_id = $this->session->get('hdt_id'); $country_id = $this->request->getPost('country_id'); $city_id = $this->request->getPost('city_id'); // Validate Country $country = $this->Crud->read_field('id', $country_id, 'country', 'name'); if (!$country) { return $this->response->setJSON(['status' => 'error', 'message' => 'Invalid country selected.']); } // Validate City and confirm it belongs to the country $city = $this->Crud->read_field('id', $city_id, 'city', 'name'); $city_country_id = $this->Crud->read_field('id', $city_id, 'city', 'country_id'); if (!$city || $city_country_id != $country_id) { return $this->response->setJSON(['status' => 'error', 'message' => 'Invalid city for selected country.']); } $data = [ 'user_id' => $user_id, 'country' => $this->Crud->read_field('id', $this->request->getPost('country_id'), 'country', 'name'), 'city' => $this->Crud->read_field('id', $this->request->getPost('city_id'), 'city', 'name'), 'check_in_date' => $this->request->getPost('check_in'), 'check_out_date' => $this->request->getPost('check_out'), 'rooms' => $this->request->getPost('rooms'), 'adults' => $this->request->getPost('adults'), 'children' => $this->request->getPost('children'), 'infants' => $this->request->getPost('infants'), 'special_requests'=> $this->request->getPost('special_requests'), 'booking_status' => 'Pending', 'reg_date' => date('Y-m-d H:i:s'), 'updated_at' => date('Y-m-d H:i:s') ]; if (!$data['check_in_date'] || !$data['check_out_date']) { return $this->response->setJSON(['status' => 'error', 'message' => 'Dates are required']); } // Validate key fields if (!$data['check_in_date'] || !$data['check_out_date']) { return $this->response->setJSON(['status' => 'error', 'message' => 'Dates are required']); } $hotel_id = $this->Crud->create('hotel_request', $data); if ($hotel_id) { // Create entry in service_request table $service_request = [ 'user_id' => $user_id, 'service_type' => 'hotel', 'service_id' => $hotel_id, 'status' => 'pending', 'request_date' => date('Y-m-d H:i:s'), 'reg_date' => date('Y-m-d H:i:s') ]; $this->Crud->create('service_request', $service_request); // Optional: send notification to admin $this->notify_admins("New Hotel Booking Request Submitted"); return $this->response->setJSON(['status' => 'success', 'message' => 'Hotel request submitted successfully!']); } else { return $this->response->setJSON(['status' => 'error', 'message' => 'Try again later']); } } if($param1 == 'hajj') { $user_id = session('hdt_id'); helper(['form']); $rules = [ 'travel_type' => 'required|in_list[hajj,umrah]', 'preferred_package' => 'required|in_list[economy,standard,premium]', 'departure_city' => 'required', 'travel_date' => 'required|valid_date', 'passport_number' => 'required', 'passport_photo' => 'uploaded[passport_photo]|max_size[passport_photo,2048]|is_image[passport_photo]', 'nationality' => 'required', 'emergency_contact_name' => 'required', 'emergency_contact_phone' => 'required', 'emergency_contact_relationship' => 'required' ]; if (!$this->validate($rules)) { return $this->response->setJSON(['status' => 'error', 'message' => 'Please complete all required fields.']); } // Upload passport photo $passport_file = $this->request->getFile('passport_photo'); $filename = $passport_file->getRandomName(); $passport_file->move('uploads/passports/', $filename); $data = [ 'travel_type' => $this->request->getPost('travel_type'), 'preferred_package' => $this->request->getPost('preferred_package'), 'departure_city' => $this->request->getPost('departure_city'), 'travel_date' => $this->request->getPost('travel_date'), 'passport_number' => $this->request->getPost('passport_number'), 'passport_photo' => 'uploads/passports/' . $filename, 'nationality' => $this->request->getPost('nationality'), 'emergency_contact_name' => $this->request->getPost('emergency_contact_name'), 'emergency_contact_phone' => $this->request->getPost('emergency_contact_phone'), 'emergency_contact_relationship' => $this->request->getPost('emergency_contact_relationship'), 'medical_conditions' => $this->request->getPost('medical_conditions'), 'special_assistance' => $this->request->getPost('special_assistance'), 'reg_date' => date('Y-m-d H:i:s') ]; $hajj_id = $this->Crud->create('hajj_request', $data); if ($hajj_id) { $this->Crud->create('service_request', [ 'user_id' => $user_id, 'service_type' => 'hajj', 'service_id' => $hajj_id, 'status' => 'pending', 'request_date' => date('Y-m-d H:i:s'), 'reg_date' => date('Y-m-d H:i:s') ]); $this->notify_admins("New Hajj/Umrah application received.", 'hajj_request', $hajj_id); return $this->response->setJSON(['status' => 'success', 'message' => 'Your application was submitted successfully!']); } return $this->response->setJSON(['status' => 'error', 'message' => 'Unable to process request.']); } if($param1 == 'tour'){ $tour_id = $this->request->getPost('tour_id'); $travel_date = $this->request->getPost('start_date'); $adults = (int) $this->request->getPost('adults'); $children = (int) $this->request->getPost('children'); $notes = trim($this->request->getPost('special_requests')); $user_id = $this->session->get('hdt_id'); // Assuming user is logged in $number_of_travelers = $adults + $children; // Validate inputs if (!$tour_id || !$travel_date || $number_of_travelers < 1) { return $this->response->setJSON([ 'status' => 'error', 'message' => 'Missing required booking details.' ]); } // Save to bookings table $bookingData = [ 'user_id' => $user_id, 'travel_date' => $travel_date, 'number_of_travelers' => $number_of_travelers, 'tour_id' => $tour_id, 'notes' => $notes, ]; $ins_rec = $this->Crud->create('tour_request', $bookingData); // your booking table name may vary // Save to service request table (optional) $serviceData = [ 'user_id' => $user_id, 'service_type' => 'tour', 'service_id' => $tour_id, 'status' => 'pending', 'request_date' => date('Y-m-d H:i:s'), 'reg_date' => date('Y-m-d H:i:s') ]; $this->Crud->create('service_request', $serviceData); // Notify admin $admin_email = 'admin@example.com'; // change this $subject = "New Tour Booking Request"; $message = " <h3>New Tour Booking Submitted</h3> <p><strong>User ID:</strong> $user_id</p> <p><strong>Tour ID:</strong> $tour_id</p> <p><strong>Date:</strong> $travel_date</p> <p><strong>Travelers:</strong> $number_of_travelers (Adults: $adults, Children: $children)</p> <p><strong>Note:</strong> " . nl2br($notes) . "</p> "; $this->notify_admins("New Tour Booking Request.", 'tour_request', $tour_id); return $this->response->setJSON([ 'status' => 'success', 'message' => 'Your booking request has been submitted successfully.' ]); } } private function _send_flight_notification($data) { $to = app_email; $subject = '🚨 New Flight Request Submitted'; $message = " <h3>New Flight Request</h3> <p><strong>User:</strong> {$this->Crud->read_field('id', $data['user_id'], 'user', 'fullname')}</p> <p><strong>Trip:</strong> {$data['from_city']} → {$data['to_city']}</p> <p><strong>Dates:</strong> {$data['departure_date']}" . (!empty($data['return_date']) ? " → {$data['return_date']}" : "") . "</p> <p><strong>Passengers:</strong> Adults: {$data['adults']}, Children: {$data['children']}, Infants: {$data['infants']}</p> "; $this->Crud->send_email($to, $subject, $message); } public function notify_admins($message, $item = 'hotel_request', $item_id = 0) { $admin_roles = $this->Crud->read_field('name', 'Administrator', 'access_role', 'id'); $from_id = session('hdt_id'); $admins = $this->Crud->read_single('role_id', $admin_roles, 'user'); foreach ($admins as $admin) { // 1. Save to notify table $this->Crud->create('notify', [ 'from_id' => $from_id, 'to_id' => $admin->id, 'content' => $message, 'item' => $item, 'item_id' => $item_id, 'new' => 1, 'reg_date' => date('Y-m-d H:i:s') ]); // 2. Send email if email exists if (!empty($admin->email)) { $subject = "New Admin Notification from Travel Platform"; $body = " <p>Dear {$admin->fullname},</p> <p>{$message}</p> <br> <p><small>This is an automated notification from the platform.</small></p> "; $this->Crud->send_email($admin->email, $subject, $body); } } } public function records($param1 = '') { if ($param1 == 'airport') { $query = $this->request->getPost('query'); $source = $this->request->getPost('source'); // optional: from/to to identify caller if (!empty($query)) { $db = db_connect(); $builder = $db->table('airports'); $builder->groupStart() ->like('airport_name', $query) ->orLike('iata_code', $query) ->orLike('city', $query) ->groupEnd(); $builder->limit(10); $airports = $builder->get()->getResult(); if (!empty($airports)) { foreach ($airports as $airport) { $class = ($source === 'from') ? 'from-airport-item' : 'to-airport-item'; $name_line = htmlspecialchars($airport->airport_name . " (" . $airport->iata_code . ")", ENT_QUOTES, 'UTF-8'); $location_line = htmlspecialchars($airport->city . ', ' . $airport->country, ENT_QUOTES, 'UTF-8'); echo '<a href="javascript:void(0);" class="list-group-item list-group-item-action ' . $class . '">' . '<div class="fw-bold">' . $name_line . '</div>' . '<small class="text-muted">' . $location_line . '</small>' . '</a>'; } } else { echo '<div class="list-group-item">No airports found.</div>'; } } } if($param1 == 'load_cities'){ $country_id = $this->request->getPost('country_id'); $cities = $this->Crud->read_single_order('country_id', $country_id, 'city', 'name', 'asc'); if (!empty($cities)) { echo '<option value="">Select City</option>'; foreach ($cities as $c) { echo "<option value='{$c->id}'>{$c->name}</option>"; } } else { echo '<option value="">No cities found</option>'; } die; } if($param1 == 'tour'){ $location = $this->request->getPost('location'); $date = $this->request->getPost('date'); $db = db_connect(); $builder = $db->table('tours'); // Your tour packages table $builder->where('status', '0'); if (!empty($location)) { $builder->like('location', $location); } if (!empty($date)) { $builder->where('start_date <=', $date); $builder->where('end_date >=', $date); } $tours = $builder->get()->getResult(); if (empty($tours)) { echo '<div class="text-center p-5">No tours found matching your criteria.</div>'; return; } foreach ($tours as $tour) { $duration = $this->Crud->date_diff($tour->start_date, $tour->end_date); echo ' <div class="tour-card card h-100 d-flex flex-column justify-content-between shadow-sm rounded-4 p-3 m-2"> <div class="text-center position-relative"> <img src="' . base_url('uploads/tours/thumbnails/' . $tour->thumbnail_url) . '" alt="' . esc($tour->title) . '" class="img-fluid rounded-3 mb-3 tour-image" onerror="this.src=\'' . base_url('assets/img/default-image.jpg') . '\';"> </div> <div class="mb-2"> <div class="text-muted small"> <i class="fas fa-map-marker-alt me-1"></i>' . esc($tour->location) . ' </div> <h6 class="fw-bold text-dark text-uppercase text-truncate">' . esc($tour->title) . '</h6> </div> <div class="d-flex justify-content-between align-items-center text-muted mb-3"> <div> <i class="fas fa-clock me-1"></i>' . ($duration ? esc($duration) . ' Days' : 'N/A') . ' </div> <div class="fw-bold"> ' . ($tour->starting_price > 0 ? ''.curr. number_format($tour->starting_price) : 'Contact') . ' </div> </div> <div class="d-flex justify-content-between gap-2 mt-auto"> <a href="javascript:;" class="btn btn-outline-primary btn-sm w-50 pop" pageSize="modal-lg" pageTitle="View Tour" pageName="' . site_url('dashboard/index/manage/view/' . $tour->id) . '"> <i class="fas fa-eye me-1"></i> View </a> <a href="javascript:;" class="btn btn-primary btn-sm w-50 show-booking-form" data-tour-id="' . $tour->id . '"> <i class="fas fa-plane-departure me-1"></i> Book </a> </div> </div>'; } } } }
Upload File
Create Folder