<?php
if ($c['level'] == "superadmin") {

	if (isset($_POST['upload'])) {

		$id = $_POST['id'];

		$ekstensi_diperbolehkan = array('png','jpg','jpeg');
		$nama      = $_FILES['file']['name'];
		$x         = explode('.', $nama);
		$ekstensi  = strtolower(end($x));
		$ukuran    = $_FILES['file']['size'];
		$file_tmp = $_FILES['file']['tmp_name'];

		$judul        = $_POST['judul'];
		$deskripsi    = $_POST['deskripsi'];
		$minimal_depo = $_POST['minimal_depo'];
		$bonus        = $_POST['bonus'];
		$to           = $_POST['to'];
		$persen       = $_POST['persen'];
		$status       = $_POST['status'];
		$type_bonus   = $_POST['type_bonus'];

		// === TANPA GANTI GAMBAR ===
		if ($nama == "") {

			$query = mysqli_query($koneksi, "
				UPDATE tb_promosi SET
					type_bonus       = '$type_bonus',
					judul            = '$judul',
					`text`           = '$deskripsi',
					minimal_deposit  = '$minimal_depo',
					bonus            = '$bonus',
					turnover         = '$to',
					persen           = '$persen',
					status           = '$status'
				WHERE id = '$id'
			");

			if ($query) {
				echo "<script>alert('Data Promosi Berhasil Diubah');window.location='?page=promosi';</script>";
			}

		// === DENGAN GANTI GAMBAR ===
		} else {

			if (in_array($ekstensi, $ekstensi_diperbolehkan)) {

				if ($ukuran < 1044070) {

					move_uploaded_file($file_tmp, '../../uploads/fotopromosi/'.$nama);

					$query = mysqli_query($koneksi, "
						UPDATE tb_promosi SET
							gambar           = '$nama',
							type_bonus       = '$type_bonus',
							judul            = '$judul',
							`text`           = '$deskripsi',
							minimal_deposit  = '$minimal_depo',
							bonus            = '$bonus',
							turnover         = '$to',
							persen           = '$persen',
							status           = '$status'
						WHERE id = '$id'
					");

					if ($query) {
						echo "<script>alert('Data Promosi Berhasil Diubah');window.location='?page=promosi';</script>";
					}

				} else {
					echo "<script>alert('Ukuran gambar terlalu besar');</script>";
				}

			} else {
				echo "<script>alert('Ekstensi gambar tidak valid');</script>";
			}
		}
	}

} else {
	echo "<script>window.location='?page=dashboard';</script>";
}
?><?php
if ($c['level'] == "superadmin") {

	if (isset($_POST['upload'])) {

		$id = $_POST['id'];

		$ekstensi_diperbolehkan = array('png','jpg','jpeg');
		$nama      = $_FILES['file']['name'];
		$x         = explode('.', $nama);
		$ekstensi  = strtolower(end($x));
		$ukuran    = $_FILES['file']['size'];
		$file_tmp = $_FILES['file']['tmp_name'];

		$judul        = $_POST['judul'];
		$deskripsi    = $_POST['deskripsi'];
		$minimal_depo = $_POST['minimal_depo'];
		$bonus        = $_POST['bonus'];
		$to           = $_POST['to'];
		$persen       = $_POST['persen'];
		$status       = $_POST['status'];
		$type_bonus   = $_POST['type_bonus'];

		// === TANPA GANTI GAMBAR ===
		if ($nama == "") {

			$query = mysqli_query($koneksi, "
				UPDATE tb_promosi SET
					type_bonus       = '$type_bonus',
					judul            = '$judul',
					`text`           = '$deskripsi',
					minimal_deposit  = '$minimal_depo',
					bonus            = '$bonus',
					turnover         = '$to',
					persen           = '$persen',
					status           = '$status'
				WHERE id = '$id'
			");

			if ($query) {
				echo "<script>alert('Data Promosi Berhasil Diubah');window.location='?page=promosi';</script>";
			}

		// === DENGAN GANTI GAMBAR ===
		} else {

			if (in_array($ekstensi, $ekstensi_diperbolehkan)) {

				if ($ukuran < 1044070) {

					move_uploaded_file($file_tmp, '../../uploads/fotopromosi/'.$nama);

					$query = mysqli_query($koneksi, "
						UPDATE tb_promosi SET
							gambar           = '$nama',
							type_bonus       = '$type_bonus',
							judul            = '$judul',
							`text`           = '$deskripsi',
							minimal_deposit  = '$minimal_depo',
							bonus            = '$bonus',
							turnover         = '$to',
							persen           = '$persen',
							status           = '$status'
						WHERE id = '$id'
					");

					if ($query) {
						echo "<script>alert('Data Promosi Berhasil Diubah');window.location='?page=promosi';</script>";
					}

				} else {
					echo "<script>alert('Ukuran gambar terlalu besar');</script>";
				}

			} else {
				echo "<script>alert('Ekstensi gambar tidak valid');</script>";
			}
		}
	}

} else {
	echo "<script>window.location='?page=dashboard';</script>";
}
?>