<?php


ob_start();
session_start();
require_once "../../../system/baglan.php";
require_once "../../../system/fonk.php";
require_once "../../../language/dil_" . $_SESSION["k_dil"] . ".php";
if ($_POST) {
    $ilaveID = $_POST["ilaveID"];
    $AracID = $_POST["AracID"];
    $fiyat = $_POST["fiyat"];
    $elm = $_POST["elm"];
    $ilkfiyat = $_SESSION["f"];
    $seciliarac = $db->query("SELECT * FROM araclar WHERE id = '" . $AracID . "' AND dil = '" . $_SESSION["k_dil"] . "'")->fetch(PDO::FETCH_ASSOC);
    $array["d"] = (int) $fiyat;
    $array["exfiyat"] = 0;
    if (is_array($_POST["ekstra"])) {
        foreach ($_POST["ekstra"] as $k => $v) {
            $seciliextra = $db->query("SELECT * FROM ekstra WHERE id = '" . $k . "'")->fetch(PDO::FETCH_ASSOC);
            $exsorgu = $db->prepare("SELECT * FROM ekstra WHERE durum = ? AND dil = ? ORDER BY id ASC");
            $exsorgu->execute(["1", $_SESSION["k_dil"]]);
            $exislem = $exsorgu->fetchALL(PDO::FETCH_ASSOC);
            if (is_array($seciliextra)) {
                $array["exfiyat"] += $seciliextra["fiyat"] * (int) $v;
                $array["d"] += $seciliextra["fiyat"] * (int) $v;
                $_SESSION["arac_" . $AracID][$k] = (int) $v;
            }
        }
    }
    $_SESSION["genel_fiyat"] = $array["d"];
    $_SESSION["exfiyat"] = $array["exfiyat"];
    echo json_encode($array);
}

?>