<?php
include("mailler/class.phpmailer.php");

//-------> Logo Colors
function hexToRGBA($hex) {
    list($r, $g, $b) = sscanf("#" . $hex, "#%02x%02x%02x");
    return "rgba($r, $g, $b, 0.9)";
}

// Renk tanımları (Hata almamak için varsayılanlar eklendi, senin kodunda zaten geliyordur)
$mainColor = isset($colors[1]) ? "#" . $colors[1] : "#333333"; 

// Logo belirleme
$hmail = $_SESSION["logo"] ?? ($t45 ? $weburl . "/deppo/image/" . $t45 : $logo);

// Header ve Footer Veritabanı Kontrolü
$tsql = ($_SESSION["tID"] == "") ? " and s7=1" : " and id=" . mysqli_real_escape_string($conn, $_SESSION["tID"]);
$temp_header_content = "";
$temp_footer_content = "";

if ($tsql) {
    $sql_temp = mysqli_query($conn, "SELECT * FROM genel WHERE t2='tmail' $tsql");
    if (mysqli_num_rows($sql_temp) > 0) {
        $rs_temp = mysqli_fetch_assoc($sql_temp);
        $temp_header_content = $rs_temp["n7"]; // DB'den gelen özel header
        $temp_footer_content = $rs_temp["n6"]; // DB'den gelen özel footer
    }
}

// Varsayılan Header (Eğer DB'den gelmediyse)
if(empty($temp_header_content)){
    $temp_header_content = "
        <table width='100%' border='0' cellspacing='0' cellpadding='0'>
            <tr>
                <td align='left' valign='middle'>
                    <img src='".$hmail."' alt='Logo' style='max-height: 60px; max-width: 100%; display: block;' border='0'>
                </td>
                <td align='right' valign='middle' style='color: #999; font-size: 14px;'>
                    ".date("d.m.Y")."
                </td>
            </tr>
        </table>
        <div style='border-bottom: 2px solid ".$mainColor."; margin-top: 15px; margin-bottom: 15px;'></div>
    ";
}

// Varsayılan Footer
if(empty($temp_footer_content)){
    $temp_footer_content = "
        <div style='border-top: 1px solid #e5e5e5; margin-top: 20px; padding-top: 20px; text-align: center; color: #888; font-size: 12px;'>
            " . uri("domain") . "<br>" . tanim('email', 'n1', 0) . "<br>
            " . ($design_bottom_icons ?? '') . "
        </div>
    ";
}

// --- TASARIM BAŞLANGICI (DESIGN TOP) ---
$design_top = "
<!DOCTYPE html>
<html>
<head>
<meta charset='UTF-8'>
<meta name='viewport' content='width=device-width, initial-scale=1.0'>
<title>Bildirim</title>
<style>
    body { margin: 0; padding: 0; background-color: #f4f6f9; font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; }
    table { border-collapse: collapse; }
    .wrapper { width: 100%; table-layout: fixed; background-color: #f4f6f9; padding-bottom: 40px; }
    .main-table { background-color: #ffffff; margin: 0 auto; width: 100%; max-width: 600px; border-radius: 8px; overflow: hidden; box-shadow: 0 4px 6px rgba(0,0,0,0.05); }
    .content-cell { padding: 30px; }
    .data-row td { padding: 12px 10px; border-bottom: 1px solid #f0f0f0; font-size: 14px; color: #333; }
    .data-label { font-weight: 600; color: #555; width: 35%; }
    .data-value { color: #333; }
    
    /* Mobil Uyumluluk */
    @media screen and (max-width: 600px) {
        .content-cell { padding: 15px !important; }
        .data-label { display: block; width: 100% !important; margin-bottom: 5px; color: #888; font-size: 12px; text-transform: uppercase; letter-spacing: 1px; }
        .data-value { display: block; width: 100% !important; margin-bottom: 15px; font-size: 16px; font-weight: 500; }
        .img-responsive { max-width: 100% !important; height: auto !important; }
    }
</style>
</head>
<body>
    <table class='wrapper' role='presentation' border='0' cellpadding='0' cellspacing='0'>
        <tr>
            <td align='center' style='padding-top: 20px;'>
                
                <table class='main-table' role='presentation' border='0' cellpadding='0' cellspacing='0'>
                    <tr><td height='6' style='background-color: ".$mainColor."; font-size: 0; line-height: 0;'>&nbsp;</td></tr>
                    
                    <tr>
                        <td class='content-cell'>
                            $temp_header_content
                            
                            <table width='100%' border='0' cellpadding='0' cellspacing='0'>
                                <tr>
                                    <td>
";

// --- TASARIM BİTİŞİ (DESIGN BOTTOM) ---
$design_bottom = "
                                    </td>
                                </tr>
                            </table>
                            $temp_footer_content
                            
                            <div style='text-align:center; font-size: 11px; color: #aaa; margin-top: 20px;'>
                                ".translate("+#Bu Mail Bilgilendirme Amacı ile Gönderilmiştir")."<br>
                                <a href='".$pweb."' target='_blank' style='color: #aaa; text-decoration: none;'>".translate("+#By CrmPlus+")."</a>
                            </div>
                            
                            <div style='text-align:center; margin-top: 10px;'>
                                <a href='".$weburl."/unsubscribe/{malici}' style='color: #999; font-size: 11px;'>Listeden Çık</a>
                            </div>

                        </td>
                    </tr>
                </table>
                </td>
        </tr>
    </table>
</body>
</html>
";
?>