Add Amarildo to the barber page and gate workers by service
New barber Amarildo Champimpi is introduced on the barber page in all three
languages, and workers can now be restricted to a subset of the services in
their category.
Amarildo cannot perform beard colouring, any waxing, or the all-in package, and
he is a barber only - but category 1 "Kozmetika" holds 19 barber AND 27 beauty
services, so the category-derived vertical wrongly made him beauty-capable.
Because the worker picker is only ever fetched AFTER services are ticked, one
per-service capability filter solves both problems: excluding him from every
beauty service removes him from that vertical entirely.
worker_services(worker_id, service_id) is an allow-list where an EMPTY set means
UNRESTRICTED. That default is deliberate: a missing migration degrades to the
previous behaviour instead of hiding every worker from the booking flow, and
existing workers keep working untouched. Ticking every box in the admin grid
stores nothing at all, so an unrestricted worker also picks up services added
later; unticking even one makes the worker restricted, and new services must
then be granted explicitly.
Enforcement is in three places. The picker offers only workers who can perform
EVERY selected service, and both booking paths re-check server-side, since the
picker is only a UI affordance - a crafted POST now gets service_not_offered/403
rather than a booking the worker cannot honour.
Fixed alongside, all found while building the above:
- getWorkersByCategorySlug() never filtered is_active, so marking a worker
inactive had NO effect on the public booking flow. Both of its callers are
guest-facing. The sibling fallback getActiveWorkers() had always filtered it.
- Worker profile picture uploads failed SILENTLY above PHP's upload_max_filesize.
Both upload blocks gated on tmp_name alone, which cannot distinguish a rejected
upload from "no file chosen" - PHP empties tmp_name in both cases - so the
worker was saved with an empty worker_profile_img and no error shown. The
upload error code is now read and reported, and a separate guard catches
post_max_size overflow, where $_POST and $_FILES both arrive empty and the form
silently did nothing at all.
- createWorker() omitted is_active from its INSERT, so the column default (1)
always won and a worker created as inactive silently came back active.
Migration - the table MUST be created before this code is deployed, because the
picker query subselects it whenever service ids are passed:
CREATE TABLE worker_services (
worker_id INT NOT NULL,
service_id INT NOT NULL,
PRIMARY KEY (worker_id, service_id),
KEY idx_worker_services_worker (worker_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
Already applied on test, dev and prod. Server-side, upload_max_filesize/
post_max_size were raised to 8M/12M on all three environments (php.ini on test,
.user.ini on the shared-host dev and prod docroots) - not carried by this commit.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TYGSbK1erKv7VG1pvdPEjG
This commit is contained in:
@@ -547,6 +547,13 @@ class Admin extends CI_Controller {
|
||||
$data['selectedItem'] = $this->Service_model->getWorkerById($worker_id);
|
||||
// Verticals are derived from the worker's service category, not stored.
|
||||
$data['workerVerticals'] = $this->Service_model->getVerticalsForWorker($worker_id);
|
||||
|
||||
// Capability grid: which of the category's services this worker performs.
|
||||
// An empty stored set means unrestricted, which the view renders as
|
||||
// everything ticked - see the note in the form.
|
||||
$data['categoryServices'] = $this->Service_model->getServicesByCategoryId($data['selectedItem']->service_category_id);
|
||||
$data['workerServiceIds'] = $this->Service_model->getWorkerServiceIds($worker_id);
|
||||
|
||||
$this->load->view('admin/update-worker', $data);
|
||||
}
|
||||
else{
|
||||
@@ -554,6 +561,48 @@ class Admin extends CI_Controller {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Translate the PHP upload error code for the worker profile picture into
|
||||
* an admin-facing message.
|
||||
*
|
||||
* The upload blocks below used to gate on tmp_name alone, which made a
|
||||
* REJECTED upload indistinguishable from "no file chosen": PHP empties
|
||||
* tmp_name in both cases, so an oversized photo was skipped in silence and
|
||||
* the worker was saved with an empty worker_profile_img. Reading the error
|
||||
* code is the only way to tell the two apart.
|
||||
*
|
||||
* @return string '' when there is nothing to report (no file chosen, or a
|
||||
* file that arrived intact), otherwise the message to show.
|
||||
*/
|
||||
private function _workerImgUploadError(){
|
||||
// No file part at all - nothing was submitted, nothing to report.
|
||||
if(!isset($_FILES['worker_img']) || !isset($_FILES['worker_img']['error'])){
|
||||
return '';
|
||||
}
|
||||
|
||||
switch($_FILES['worker_img']['error']){
|
||||
case UPLOAD_ERR_OK:
|
||||
case UPLOAD_ERR_NO_FILE:
|
||||
// Intact, or the admin simply left the field empty.
|
||||
return '';
|
||||
|
||||
case UPLOAD_ERR_INI_SIZE:
|
||||
case UPLOAD_ERR_FORM_SIZE:
|
||||
return 'A kép túl nagy! A megengedett legnagyobb méret: '.ini_get('upload_max_filesize').'.';
|
||||
|
||||
case UPLOAD_ERR_PARTIAL:
|
||||
return 'A kép csak részben töltődött fel. Kérlek próbáld újra!';
|
||||
|
||||
case UPLOAD_ERR_NO_TMP_DIR:
|
||||
case UPLOAD_ERR_CANT_WRITE:
|
||||
case UPLOAD_ERR_EXTENSION:
|
||||
return 'A kép feltöltése szerverhiba miatt nem sikerült. Szólj az üzemeltetőnek!';
|
||||
|
||||
default:
|
||||
return 'Ismeretlen hiba a kép feltöltése közben.';
|
||||
}
|
||||
}
|
||||
|
||||
public function worker_process(){
|
||||
$this->load->helper('url');
|
||||
$this->load->model('User_model');
|
||||
@@ -565,7 +614,16 @@ class Admin extends CI_Controller {
|
||||
$data['pageTitle'] = '';
|
||||
$data['message'] = '';
|
||||
$data['message_class'] = '';
|
||||
|
||||
|
||||
// A POST body larger than post_max_size is discarded WHOLESALE by PHP:
|
||||
// $_POST and $_FILES both arrive empty, so none of the branches below
|
||||
// fire and the form appears to do nothing at all. CONTENT_LENGTH still
|
||||
// reports the real size, which is the only surviving evidence.
|
||||
if($_SERVER['REQUEST_METHOD'] === 'POST' && empty($_POST) && !empty($_SERVER['CONTENT_LENGTH'])){
|
||||
$data['message'] = 'A beküldött adat túl nagy volt, ezért a mentés nem történt meg. A kép legfeljebb '.ini_get('upload_max_filesize').' lehet.';
|
||||
$data['message_class'] = 'errorMessage';
|
||||
}
|
||||
|
||||
if(isset($_GET['delete-worker'])){
|
||||
$selected_worker = $this->Service_model->getWorkerById($_GET['delete-worker']);
|
||||
$workerArray = array(
|
||||
@@ -581,7 +639,12 @@ class Admin extends CI_Controller {
|
||||
|
||||
$data['worker_img'] = '';
|
||||
|
||||
if($_FILES["worker_img"]["tmp_name"] != ''){
|
||||
$workerImgError = $this->_workerImgUploadError();
|
||||
|
||||
if($workerImgError !== ''){
|
||||
$data['message'] = $workerImgError;
|
||||
$data['message_class'] = 'errorMessage';
|
||||
} elseif($_FILES["worker_img"]["tmp_name"] != ''){
|
||||
$target_dir = getcwd()."/assets/img/";
|
||||
$target_file = $target_dir . 'worker_'.str_replace(' ','_', $_POST['worker_name']);
|
||||
$imageFileType = strtolower(pathinfo(basename($_FILES["worker_img"]["name"]),PATHINFO_EXTENSION));
|
||||
@@ -632,7 +695,44 @@ class Admin extends CI_Controller {
|
||||
$this->Service_model->updateWorker($_POST['worker_id'], $workerArray);
|
||||
$this->Log_model->addLog('workers', $data['currentUser']->username.' módosította a(z) '.$_POST['worker_name'].' nevű dolgozót ('.implode(',',$workerArray).')', $data['currentUser']->username);
|
||||
|
||||
if($_FILES["worker_img"]["tmp_name"] != ''){
|
||||
// Capability set. The grid posts the ticked service ids; anything not
|
||||
// belonging to the worker's (possibly just-changed) category is dropped
|
||||
// so a category switch cannot leave orphaned rows behind.
|
||||
$postedServiceIds = isset($_POST['worker_services']) && is_array($_POST['worker_services'])
|
||||
? $_POST['worker_services']
|
||||
: array();
|
||||
|
||||
$categoryServices = $this->Service_model->getServicesByCategoryId($_POST['service_category_id']);
|
||||
$categoryServiceIds = array();
|
||||
if(is_array($categoryServices)){
|
||||
foreach($categoryServices as $svc){
|
||||
$categoryServiceIds[] = (int)$svc->service_id;
|
||||
}
|
||||
}
|
||||
|
||||
$allowedServiceIds = array();
|
||||
foreach($postedServiceIds as $postedId){
|
||||
if(in_array((int)$postedId, $categoryServiceIds, TRUE)){
|
||||
$allowedServiceIds[] = (int)$postedId;
|
||||
}
|
||||
}
|
||||
|
||||
// Every service ticked means "no restriction": store nothing, so the
|
||||
// worker keeps performing services added in the future too. Storing the
|
||||
// full set instead would silently freeze them out of every new service.
|
||||
if(count($allowedServiceIds) === count($categoryServiceIds)){
|
||||
$allowedServiceIds = array();
|
||||
}
|
||||
|
||||
$this->Service_model->setWorkerServiceIds($_POST['worker_id'], $allowedServiceIds);
|
||||
$this->Log_model->addLog('workers', $data['currentUser']->username.' beállította a(z) '.$_POST['worker_name'].' nevű dolgozó végezhető szolgáltatásait ('.(empty($allowedServiceIds) ? 'nincs korlátozás' : implode(',', $allowedServiceIds)).')', $data['currentUser']->username);
|
||||
|
||||
$workerImgError = $this->_workerImgUploadError();
|
||||
|
||||
if($workerImgError !== ''){
|
||||
$data['message'] = $workerImgError;
|
||||
$data['message_class'] = 'errorMessage';
|
||||
} elseif($_FILES["worker_img"]["tmp_name"] != ''){
|
||||
$target_dir = getcwd()."/assets/img/";
|
||||
$target_file = $target_dir . 'worker_'.str_replace(' ','_', $_POST['worker_name']);
|
||||
$imageFileType = strtolower(pathinfo(basename($_FILES["worker_img"]["name"]),PATHINFO_EXTENSION));
|
||||
|
||||
@@ -137,7 +137,15 @@ class Pages extends CI_Controller {
|
||||
$data['pageTitle'] = '';
|
||||
|
||||
if(isset($_POST['action']) && $_POST['action'] == 'getAvailableWorkersByServiceCategory' && isset($_POST['serv_cat_slug'])){
|
||||
$workers = $this->Service_model->getWorkersByCategorySlug($_POST['serv_cat_slug']);
|
||||
// The picker must only offer workers who can perform EVERY service the
|
||||
// guest has ticked. service_ids is supplied by the booking form; when it
|
||||
// is absent (older cached JS) the call degrades to the category-only
|
||||
// behaviour rather than returning nobody.
|
||||
$requestedServiceIds = isset($_POST['service_ids']) && is_array($_POST['service_ids'])
|
||||
? $_POST['service_ids']
|
||||
: array();
|
||||
|
||||
$workers = $this->Service_model->getWorkersByCategorySlug($_POST['serv_cat_slug'], $requestedServiceIds);
|
||||
$returnedWorkers = '';
|
||||
$workerIndex = 0;
|
||||
$workerListShow = '';
|
||||
@@ -445,6 +453,15 @@ class Pages extends CI_Controller {
|
||||
}
|
||||
}
|
||||
|
||||
// Per-worker capability. The category check above only proves the
|
||||
// services belong to the worker's category - not that this particular
|
||||
// worker performs them. The picker already hides incapable workers, but
|
||||
// that is a UI affordance, so re-check before the booking is written.
|
||||
if (!$this->Service_model->workerCanPerformServices($bookingArray['worker_id'], $selectedServiceArray)) {
|
||||
$this->_booking_error('service_not_offered', 403);
|
||||
return;
|
||||
}
|
||||
|
||||
// Single-service verticals: the client disables the other checkboxes,
|
||||
// but that is a UI affordance only. The vertical is derived from the
|
||||
// services themselves rather than $_POST['subpage'], which is
|
||||
@@ -883,7 +900,7 @@ class Pages extends CI_Controller {
|
||||
}
|
||||
}
|
||||
if($categorySlug !== ''){
|
||||
$data['workers'] = $this->Service_model->getWorkersByCategorySlug($categorySlug);
|
||||
$data['workers'] = $this->Service_model->getWorkersByCategorySlug($categorySlug, is_array($serviceIds) ? $serviceIds : array());
|
||||
} else {
|
||||
$data['workers'] = $this->Service_model->getActiveWorkers($subpage);
|
||||
}
|
||||
@@ -952,6 +969,15 @@ class Pages extends CI_Controller {
|
||||
}
|
||||
}
|
||||
|
||||
// Per-worker capability, same reasoning as booking_process(): the
|
||||
// category check proves only that the services belong to the worker's
|
||||
// category, not that this worker performs them.
|
||||
if(!$this->Service_model->workerCanPerformServices($newWorkerId, $selectedServiceArray)){
|
||||
$this->output->set_status_header(403)->set_content_type('application/json')
|
||||
->set_output(json_encode(['error' => 'Selected worker does not perform the chosen services.']));
|
||||
return;
|
||||
}
|
||||
|
||||
// Schedule check
|
||||
$schedule = $this->Service_model->getWorkerScheduleForDate($newWorkerId, $newBookingDate);
|
||||
if(!$schedule){
|
||||
|
||||
Reference in New Issue
Block a user