diff --git a/app/Http/Controllers/Web/Auth/LoginController.php b/app/Http/Controllers/Web/Auth/LoginController.php index cc7361d..cf40d2c 100644 --- a/app/Http/Controllers/Web/Auth/LoginController.php +++ b/app/Http/Controllers/Web/Auth/LoginController.php @@ -102,7 +102,7 @@ class LoginController extends Controller } elseif ($user->hasRole('teacher')) { return redirect()->to('userarea/teacher.php'); } elseif ($user->hasRole('school_owner')) { - return redirect()->to('userarea/school.php'); + return redirect()->to('userarea/school_dashboard.php'); } // Fallback nel caso il ruolo non corrisponda diff --git a/public/userarea/get_product_classes.php b/public/userarea/get_product_classes.php index f67eec5..ffaf8b1 100644 --- a/public/userarea/get_product_classes.php +++ b/public/userarea/get_product_classes.php @@ -1,14 +1,14 @@ getConnection(); // Verifica che iduserlogin sia definito if (!isset($iduserlogin)) { - die("Errore: ID utente non definito."); + http_response_code(400); + echo json_encode(['error' => 'ID utente non definito']); + exit; } // Recupera i dati della scuola in base all'utente loggato @@ -20,22 +20,80 @@ $stmt = $pdo->prepare(" $stmt->execute([$iduserlogin]); $school = $stmt->fetch(); if (!$school) { - die("Errore: Nessuna scuola trovata per l'utente loggato."); + http_response_code(404); + echo json_encode(['error' => 'Nessuna scuola trovata per l\'utente loggato']); + exit; } $school_id = $school['id']; $product_id = $_GET['product_id'] ?? 0; +$variation_id = $_GET['variation_id'] ?? 0; -// Verifica che il prodotto appartenga alla scuola -$stmt = $pdo->prepare("SELECT id FROM products WHERE id = ? AND school_id = ?"); -$stmt->execute([$product_id, $school_id]); -if (!$stmt->fetch()) { - die("Errore: Prodotto non trovato o non autorizzato."); +if ($product_id <= 0) { + http_response_code(400); + echo json_encode(['error' => 'ID prodotto non valido']); + exit; +} + +// Recupera i dettagli del prodotto (inclusi is_full_access e auto_propagate_to_order) +$stmt = $pdo->prepare(" + SELECT id, is_full_access, auto_propagate_to_order + FROM products + WHERE id = ? AND school_id = ? +"); +$stmt->execute([$product_id, $school_id]); +$product = $stmt->fetch(PDO::FETCH_ASSOC); +if (!$product) { + http_response_code(404); + echo json_encode(['error' => 'Prodotto non trovato o non autorizzato']); + exit; +} + +// Inizializza l'array di risposta con i dettagli del prodotto +$response = [ + 'is_full_access' => $product['is_full_access'], + 'auto_propagate_to_order' => $product['auto_propagate_to_order'], + 'class_types' => [] +]; + +// Se variation_id è specificato, recupera i dettagli della variazione +if ($variation_id > 0) { + $stmt = $pdo->prepare(" + SELECT id, auto_propagate_to_order + FROM product_variations + WHERE id = ? AND product_id = ? + "); + $stmt->execute([$variation_id, $product_id]); + $variation = $stmt->fetch(PDO::FETCH_ASSOC); + if (!$variation) { + http_response_code(404); + echo json_encode(['error' => 'Variazione non trovata o non autorizzata']); + exit; + } + // Sovrascrivi auto_propagate_to_order con il valore della variazione + $response['auto_propagate_to_order'] = $variation['auto_propagate_to_order']; +} + +// Recupera le classi associate +if ($variation_id > 0) { + $stmt = $pdo->prepare(" + SELECT class_type_id + FROM product_class_types + WHERE product_id = ? AND variation_id = ? + "); + $stmt->execute([$product_id, $variation_id]); +} else { + $stmt = $pdo->prepare(" + SELECT class_type_id + FROM product_class_types + WHERE product_id = ? AND variation_id IS NULL + "); + $stmt->execute([$product_id]); } -$stmt = $pdo->prepare("SELECT class_type_id FROM product_class_types WHERE product_id = ?"); -$stmt->execute([$product_id]); $class_types = $stmt->fetchAll(PDO::FETCH_COLUMN); +$response['class_types'] = $class_types; header('Content-Type: application/json'); -echo json_encode($class_types); +echo json_encode($response); +exit; diff --git a/public/userarea/photoclass/1-1744291511-Screenshot 2023-11-01 184252.png b/public/userarea/photoclass/1-1744291511-Screenshot 2023-11-01 184252.png new file mode 100644 index 0000000..d680be5 Binary files /dev/null and b/public/userarea/photoclass/1-1744291511-Screenshot 2023-11-01 184252.png differ diff --git a/public/userarea/product_detail.php b/public/userarea/product_detail.php new file mode 100644 index 0000000..799b110 --- /dev/null +++ b/public/userarea/product_detail.php @@ -0,0 +1,149 @@ +getConnection(); + +$product_id = $_GET['product_id'] ?? 0; + +// Recupera i dettagli del prodotto +$stmt = $pdo->prepare(" + SELECT p.id, p.name AS product_name, + c.name AS class_name, c.description AS class_description, c.photo AS class_photo + FROM products p + LEFT JOIN product_class_types pct ON p.id = pct.product_id AND pct.variation_id IS NULL + LEFT JOIN class_types ct ON pct.class_type_id = ct.id + LEFT JOIN classes c ON ct.class_id = c.id + WHERE p.id = ? + GROUP BY p.id +"); +$stmt->execute([$product_id]); +$product = $stmt->fetch(PDO::FETCH_ASSOC); + +if (!$product) { + die("Prodotto non trovato."); +} + +// Recupera le variazioni del prodotto +$stmt = $pdo->prepare(" + SELECT id, name, price + FROM product_variations + WHERE product_id = ? AND status = 'active' +"); +$stmt->execute([$product_id]); +$variations = $stmt->fetchAll(PDO::FETCH_ASSOC); + +// Recupera le variazioni delle classi associate al prodotto +$stmt = $pdo->prepare(" + SELECT ct.id, ct.level, ct.day_of_week + FROM product_class_types pct + JOIN class_types ct ON pct.class_type_id = ct.id + WHERE pct.product_id = ? AND pct.variation_id IS NULL +"); +$stmt->execute([$product_id]); +$class_types = $stmt->fetchAll(PDO::FETCH_ASSOC); +?> + + + + +
+ + +
+ | Nome | +Variazione | +Tipo | +Prezzo | +Durata (giorni) | +Ingressi | +Inventario | +Accesso Completo | +Classi Associate | +Azioni | +||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Nome | -Tipo | -Prezzo | -Durata (giorni) | -Ingressi | -Inventario | -Classi Associate | -Azioni | +Nessun prodotto trovato. | |||||||||
| Nessun prodotto trovato. | ++ | - | ++ 'Carnet', + 'subscription' => 'Abbonamento', + 'drop_in' => 'Lezione Singola' + ]; + echo $type_labels[$product['type']] ?? $product['type']; + ?> + | +- | +- | +- | +- | ++ | + ' . htmlspecialchars($variation_names) . ''; + } + } else { + echo 'Nessuna classe associata'; + } + ?> + | ++ + + + | |||||||
| + + + | |||||||||||||||||
| + | 'Carnet', - 'subscription' => 'Abbonamento', - 'drop_in' => 'Lezione Singola' - ]; echo $type_labels[$product['type']] ?? $product['type']; ?> | -€ | -- | + | € | ++ | + | ' . htmlspecialchars($variation_names) . ''; @@ -328,124 +626,242 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { - | |||||||||