diff --git a/public/userarea/finances.php b/public/userarea/finances.php
new file mode 100644
index 0000000..381e76c
--- /dev/null
+++ b/public/userarea/finances.php
@@ -0,0 +1,332 @@
+getConnection();
+
+$stmt = $pdo->prepare("SELECT id, name FROM schools WHERE owner_id = ?");
+$stmt->execute([$iduserlogin]);
+$school = $stmt->fetch();
+if (!$school) die("Scuola non trovata.");
+$school_id = $school['id'];
+
+// === FILTRI ===
+$year = $_GET['year'] ?? date('Y');
+$month = $_GET['month'] ?? null;
+$start_date = $month ? "$year-$month-01" : "$year-01-01";
+$end_date = $month ? date('Y-m-t', strtotime($start_date)) : "$year-12-31";
+
+$where_date = "AND o.created_at BETWEEN ? AND ?";
+$params = [$school_id, $start_date . ' 00:00:00', $end_date . ' 23:59:59'];
+
+// === STATISTICHE FILTRATE ===
+$stmt = $pdo->prepare("
+ SELECT
+ COUNT(*) as total_orders,
+ SUM(price) as total_revenue,
+ SUM(CASE WHEN payment_method = 'stripe' THEN price ELSE 0 END) as stripe_revenue,
+ SUM(CASE WHEN payment_method = 'paypal' THEN price ELSE 0 END) as paypal_revenue,
+ SUM(CASE WHEN payment_method = 'manual' THEN price ELSE 0 END) as manual_revenue
+ FROM orders o
+ WHERE o.school_id = ? AND o.status = 'completed' $where_date
+");
+$stmt->execute($params);
+$stats = $stmt->fetch();
+
+// === RICAVI MENSILI (per grafico) ===
+$monthly = [];
+$start = new DateTime($month ? $start_date : "$year-01-01");
+$end = new DateTime($end_date);
+$interval = new DateInterval('P1M');
+$period = new DatePeriod($start, $interval, $end->modify('+1 month'));
+
+foreach ($period as $dt) {
+ $m = $dt->format('Y-m');
+ $label = $dt->format('M Y');
+
+ $stmt = $pdo->prepare("
+ SELECT COALESCE(SUM(price), 0) as revenue
+ FROM orders
+ WHERE school_id = ? AND status = 'completed'
+ AND DATE_FORMAT(created_at, '%Y-%m') = ?
+ ");
+ $stmt->execute([$school_id, $m]);
+ $monthly[] = ['label' => $label, 'revenue' => (float)$stmt->fetchColumn()];
+}
+
+// === DISTRIBUZIONE METODI PAGAMENTO (per torta) ===
+$payment_data = [
+ 'Stripe' => $stats['stripe_revenue'] ?? 0,
+ 'PayPal' => $stats['paypal_revenue'] ?? 0,
+ 'Manuale' => $stats['manual_revenue'] ?? 0
+];
+
+// === TOP 5 PRODOTTI ===
+$stmt = $pdo->prepare("
+ SELECT p.name, pv.name as variation, COUNT(*) as vendite, SUM(o.price) as incasso
+ FROM orders o
+ JOIN products p ON o.product_id = p.id
+ LEFT JOIN product_variations pv ON o.variation_id = pv.id
+ WHERE o.school_id = ? AND o.status = 'completed' $where_date
+ GROUP BY o.product_id, o.variation_id
+ ORDER BY incasso DESC LIMIT 5
+");
+$stmt->execute($params);
+$top_products = $stmt->fetchAll();
+
+// === ULTIMI ORDINI ===
+$stmt = $pdo->prepare("
+ SELECT o.*, u.first_name, u.last_name, u.email, p.name as product_name, pv.name as variation_name
+ FROM orders o
+ JOIN auth_users u ON o.user_id = u.id
+ JOIN products p ON o.product_id = p.id
+ LEFT JOIN product_variations pv ON o.variation_id = pv.id
+ WHERE o.school_id = ? $where_date
+ ORDER BY o.created_at DESC
+");
+$stmt->execute($params);
+$recent_orders = $stmt->fetchAll();
+?>
+
+
+
+
+
+
+
+ Finanze -
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Finanze
+
+ €
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ |
+
+ €
+ |
+
+
+
+
+ | Nessun dato |
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ | Data |
+ Ordine |
+ Cliente |
+ Prodotto |
+ Importo |
+ Metodo |
+
+
+
+
+
+ |
+ # |
+ |
+ |
+ € |
+
+
+
+
+ |
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/public/userarea/include/headscript.php b/public/userarea/include/headscript.php
index ce74be8..169d203 100644
--- a/public/userarea/include/headscript.php
+++ b/public/userarea/include/headscript.php
@@ -6,55 +6,60 @@ $db = DBHandlerSelect::getInstance()->getConnection();
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL | E_STRICT);
-// This should be equal to: PATH_TO_VANGUARD_FOLDER/extra/auth.php
-include('../../extra/auth.php');
-//require_once __DIR__ . '/extra/auth.php';
-// Here we just check if user is not
-// logged in, and in that case we redirect
-// the user to vanguard login page.
+include('../../extra/auth.php');
if (! Auth::check()) {
-
redirectTo('../../public/login');
}
$user = Auth::user();
-$iduserlogin = $user->present()->id;
-$nameuser = $user->present()->first_name;
-$surnameuser = $user->present()->last_name;
-$emailuser = $user->present()->email;
-$avatar = $user->present()->avatar;
+$iduserlogin = $user->present()->id;
+$nameuser = $user->present()->first_name;
+$surnameuser = $user->present()->last_name;
+$emailuser = $user->present()->email;
+$avatar = $user->present()->avatar;
+$kindofrole = $user->present()->role_id; // <-- Questo è il ruolo (es. 1=admin, 2=teacher, 3=student, ecc.)
-$kindofrole = $user->present()->role_id;
-
-
-
-//$user = "1";
-//$iduserlogin="1";
-//$nameuser="Claudio";
-//$emailuser="info@claudiosironi.com";
-?>
-prepare("SELECT id FROM students WHERE user_id = ? LIMIT 1");
+ $stmt->execute([$iduserlogin]);
+ $student_exists = $stmt->fetch();
+
+ if (!$student_exists) {
+ // Non ha completato il profilo → reindirizza
+ $_SESSION['student_profile_pending'] = true;
+ header("Location: student_profile.php");
+ exit;
+ } else {
+ // Ha già completato → segna per non controllare più
+ $_SESSION['student_profile_completed'] = true;
+ }
+}
+// --- FINE: Reindirizzamento intelligente ---
+
+$_SESSION["iduserlogin"] = $iduserlogin;
+$_SESSION["nameuser"] = $nameuser;
+$_SESSION["surnameuser"] = $surnameuser;
+$_SESSION["emailuser"] = $emailuser;
+$_SESSION["photouser"] = $avatar;
+
$photouser = $_SESSION["photouser"];
-?>
-
-
-
diff --git a/public/userarea/include/navbar.php b/public/userarea/include/navbar.php
index 4574757..2fc13d4 100644
--- a/public/userarea/include/navbar.php
+++ b/public/userarea/include/navbar.php
@@ -51,7 +51,7 @@
-
+
diff --git a/public/userarea/include/topbar.php b/public/userarea/include/topbar.php
index 8a23a48..058b18f 100644
--- a/public/userarea/include/topbar.php
+++ b/public/userarea/include/topbar.php
@@ -329,7 +329,7 @@ $cart_count = array_sum(array_column($_SESSION['cart'], 'quantity'));