Add visual booking calendar (weekly Teams-style view)
- New weekly calendar at /bookings/calendar with time blocks per booking - Color-coded by worker, overlapping bookings shown side-by-side - Click booking to see details, edit or delete - Worker filter dropdown, week navigation (prev/next/today) - AJAX week loading for smooth navigation - Link between list view and calendar view Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.6
parent
a100acddec
commit
6abb90329d
@@ -695,6 +695,96 @@ class Admin extends CI_Controller {
|
||||
}
|
||||
}
|
||||
|
||||
public function booking_calendar(){
|
||||
$this->load->helper('url');
|
||||
$this->load->model('User_model');
|
||||
$this->load->model('Service_model');
|
||||
$this->load->model('Module_model');
|
||||
|
||||
if(isset($_SESSION['username'])){
|
||||
$data['currentUser'] = $this->User_model->getUserByUsername($_SESSION['username']);
|
||||
$data['pageTitle'] = 'Foglalási naptár';
|
||||
$data['message'] = '';
|
||||
$data['message_class'] = '';
|
||||
if($this->User_model->is_user_admin($_SESSION['username'])){
|
||||
$data['activeModules'] = $this->Module_model->getAllModule();
|
||||
} else {
|
||||
$data['activeModules'] = $this->Module_model->getUserModules($data['currentUser']->user_id);
|
||||
}
|
||||
|
||||
// Compute week bounds
|
||||
$weekParam = isset($_GET['week']) ? $_GET['week'] : date('Y-m-d');
|
||||
$monday = new DateTime($weekParam);
|
||||
$dow = (int)$monday->format('N'); // 1=Mon..7=Sun
|
||||
if ($dow > 1) $monday->modify('-'.($dow - 1).' days');
|
||||
$sunday = clone $monday;
|
||||
$sunday->modify('+6 days');
|
||||
|
||||
$data['weekStart'] = $monday->format('Y-m-d');
|
||||
$data['weekEnd'] = $sunday->format('Y-m-d');
|
||||
$data['workers'] = $this->Service_model->getActiveWorkers();
|
||||
|
||||
$workerId = isset($_GET['worker_id']) ? $_GET['worker_id'] : null;
|
||||
$data['bookings'] = $this->Service_model->getBookingsByDateRange($data['weekStart'], $data['weekEnd'], $workerId);
|
||||
|
||||
$this->load->view('admin/booking-calendar', $data);
|
||||
} else {
|
||||
header("Location:".SITEURL."login");
|
||||
}
|
||||
}
|
||||
|
||||
public function booking_calendar_data(){
|
||||
$this->load->helper('url');
|
||||
$this->load->model('User_model');
|
||||
$this->load->model('Service_model');
|
||||
|
||||
if(!isset($_SESSION['username'])){
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode(array('error' => 'unauthorized'));
|
||||
return;
|
||||
}
|
||||
|
||||
$weekParam = isset($_GET['week']) ? $_GET['week'] : date('Y-m-d');
|
||||
$monday = new DateTime($weekParam);
|
||||
$dow = (int)$monday->format('N');
|
||||
if ($dow > 1) $monday->modify('-'.($dow - 1).' days');
|
||||
$sunday = clone $monday;
|
||||
$sunday->modify('+6 days');
|
||||
|
||||
$workerId = isset($_GET['worker_id']) && $_GET['worker_id'] !== '' ? $_GET['worker_id'] : null;
|
||||
$bookings = $this->Service_model->getBookingsByDateRange($monday->format('Y-m-d'), $sunday->format('Y-m-d'), $workerId);
|
||||
|
||||
$result = array();
|
||||
foreach ($bookings as $b) {
|
||||
$services = array();
|
||||
if (is_array($b->services)) {
|
||||
foreach ($b->services as $s) {
|
||||
$services[] = array(
|
||||
'service_name' => $s->service_name,
|
||||
'service_price' => $s->service_price,
|
||||
'service_time' => $s->service_time
|
||||
);
|
||||
}
|
||||
}
|
||||
$result[] = array(
|
||||
'booking_id' => $b->booking_id,
|
||||
'guest_name' => $b->guest_name,
|
||||
'guest_email' => $b->guest_email,
|
||||
'guest_phone' => $b->guest_phone,
|
||||
'worker_id' => $b->worker_id,
|
||||
'worker_name' => $b->worker_name,
|
||||
'booking_date' => $b->booking_date,
|
||||
'booking_start_time' => $b->booking_start_time,
|
||||
'booking_finish_time' => $b->booking_finish_time,
|
||||
'services' => $services,
|
||||
'service_names_joined' => $b->service_names_joined
|
||||
);
|
||||
}
|
||||
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode($result);
|
||||
}
|
||||
|
||||
public function add_booking(){
|
||||
$this->load->helper('url');
|
||||
$this->load->model('User_model');
|
||||
|
||||
Reference in New Issue
Block a user