<?php
session_start();
require 'db.php';

if (!isset($_SESSION['user_id'])) {
    header("Location: login.php");
    exit;
}

$user_id = $_SESSION['user_id'];

// Kullanıcı bilgilerini çek
$stmt = $pdo->prepare("SELECT fullname, email FROM users WHERE id = ?");
$stmt->execute([$user_id]);
$user = $stmt->fetch();

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $message = $_POST['message'] ?? null; // Opsiyonel mesaj
    $photoPath = null;
	$sale_amount = $_POST['sale_amount'] ?? 0;

    // Eğer fotoğraf yüklenmişse işle
    if (isset($_FILES['photo']) && $_FILES['photo']['error'] == 0) {
        $photo = $_FILES['photo'];
        $ext = pathinfo($photo['name'], PATHINFO_EXTENSION);
        $filename = uniqid() . ".$ext"; // Benzersiz bir dosya adı oluştur
        $photoPath = "uploads/$filename";
        move_uploaded_file($photo['tmp_name'], $photoPath);
    }

    // Veritabanına kaydet
    $stmt = $pdo->prepare("INSERT INTO sales_reports (user_id, fullname, email, photo_path, message, sale_amount) VALUES (?, ?, ?, ?, ?, ?)");
    $stmt->execute([$user_id, $user['fullname'], $user['email'], $photoPath, $message, $sale_amount]);

	if ($stmt) {
        $success_message = 'Satış bildiriminiz başarıyla kaydedildi.';
    }
    // Burada başarı mesajı atayabilirsiniz
    
}
?>
<!DOCTYPE html>
<html lang="tr">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
	 <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
    <title>Ana Sayfa</title>
    <style>
        body {
            margin: 0;
            font-family: 'Arial', sans-serif;
            background-color: #fff;
            color: #333;
        }
        header {
            background-color: #fff;
            color: #333;
            text-align: center;
            padding: 20px;
        }
        header h1 {
            margin: 0;
            font-size: 24px;
        }
		
		.top-right {
            position: absolute;
            right: 25px;
            top: 40px;
        }

        .material-icons {
            cursor: pointer;
			
        }
		
		.material-icons:active {
            cursor: pointer;
			color: #459D7A
        }
		
        .footer-menu {
            display: flex;
            justify-content: space-around;
            padding: 20px 0;
            background-color: #fff;
            position: fixed;
            bottom: 0;
            width: 100%;
            box-shadow: 0 -2px 10px rgba(0,0,0,0.1);
        }
		.active {
			font-weight:600;
            color: #459D7A !important;
			
        }
        .footer-menu a {
            text-align: center;
            flex-grow: 1;
            display: flex;
            flex-direction: column;
            align-items: center;
            text-decoration: none;
            color: #333;
        }
		
        .footer-menu a i {
            font-size: 24px; /* İkon boyutu */
        }
        .footer-menu a span {
            font-size: 12px;
            margin-top: 4px;
			
        }
		.menu {
    padding: 20px;
    background-color: #fff;
}

form {
    max-width: 500px;
    margin: auto;
}

form label {
    display: block;
    margin: 10px 0 5px;
}

form input[type="number"],
form select,
form textarea {
    width: 90%;
    padding: 8px;
    margin-bottom: 10px;
    border: 1px solid #ccc;
    border-radius: 4px;
}

form button {
    padding: 10px 15px;
    background-color: #459D7A;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}

form button:hover {
    background-color: #367b59;
}

.success-message {
    padding: 10px;
    background-color: #367b59; /* Yeşil arka plan rengi */
    color: white; /* Beyaz metin rengi */
    margin-top: 20px;
    text-align: center;
    border-radius: 4px;
}
		
    </style>

</head>
<body>

<header>
    <div class="top-right">
        <i class="material-icons">notifications</i>
    </div>
    <div>...</div> <!-- Diğer kullanıcı bilgileri ve bildirim simgesi için yer -->
</header>
<div class="menu">
    <h2>Satış Bildirimi</h2>
	<form action="sales_report.php" method="post" enctype="multipart/form-data">
	<label for="sale_amount">Satış Bedeli:</label>
    <input type="number" id="sale_amount" name="sale_amount" step="0.01" min="0" placeholder="0.00" required>
	<label for="photo">Dekont Yükle:</label>
    <input type="file" id="photo" name="photo">
    <label for="message">Mesaj (Opsiyonel):</label>
    <textarea id="message" name="message"></textarea>

    <button type="submit">Satış Bildirimi Yap</button>


		
		 <?php if (!empty($success_message)): ?>
        <div class="success-message"><?php echo $success_message; ?></div>
    <?php endif; ?>
    </form>
</div>


<div class="footer-menu">
    <a href="dashboard.php">
        <i class="material-icons">home</i>
        <span>Ana Sayfa</span>
    </a>
    <a href="sale_list.php">
        <i class="material-icons">monetization_on</i>
        <span>Satışlar</span>
    </a>
    <a href="profil.php">
        <i class="material-icons">person</i>
        <span>Profil</span>
    </a>
</div>

</body>
</html>
