<?php
ob_start();
session_start();
include 'connect.php';
if (isset($_POST['loggin'])) {
$admin_kadi = htmlspecialchars($_POST['username']);
$admin_sifre = md5(htmlspecialchars($_POST['password']));
if (empty($admin_kadi) || empty($admin_sifre)) {
header("Location:../login.php?durum=null");
}
else{
$varmi = $db->prepare("SELECT * from yonetim where username=? && password=? ");
$varmi->execute(array(
$admin_kadi,
$admin_sifre
));
if($varmi->rowCount()>0)
{
$dizi = $varmi->fetch(PDO::FETCH_ASSOC);
$_SESSION["num"] = $dizi["username"];
$_SESSION["start_time"] = time();
header("Location: ../index.php?durum=basarili");
exit;
}
else{
header("Location:../login.php?durum=no");
exit;
}
}
}
if (isset($_POST['user-update'])) {
$query = $db->prepare("SELECT * FROM yonetim WHERE id=?");
$query->execute(array(1));
$ayarcek = $query->fetch();
$admin_kadi = htmlspecialchars(trim($_POST['username']));
if ($_POST["old-pass"] && $_POST["new-pass"] > 0 ) {
$oldpass= md5($_POST["old-pass"]);
$paswords= md5(htmlspecialchars($_POST["new-pass"]));
if ($oldpass==$ayarcek["password"]) {
$sil=$db->prepare("UPDATE yonetim SET username=:username, password=:password where id=:pimg_id");
$kontrol=$sil->execute(array(
'username' => $admin_kadi,
'password' => $paswords,
'pimg_id' => 1
));
if ($kontrol) {
$_SESSION["num"] = $_POST["username"];
Header("Location:../user.php?durum=okk");
} else {
Header("Location:../user.php?durum=noo");
}
}else{
echo "hatalı şifre";
}
}else{
$sil=$db->prepare("UPDATE yonetim SET username=:username where id=:pimg_id");
$kontrol=$sil->execute(array(
'username' => $admin_kadi,
'pimg_id' => 1
));
if ($kontrol) {
$_SESSION["num"] = $_POST["username"];
Header("Location:../user.php?durum=ok");
} else {
Header("Location:../user.php?durum=no");
}
}
}
//----------------------------urun ekle-------------------------------
if (isset($_POST['urun_ekle'])) {
$ayarkaydet=$db->prepare("INSERT INTO urun SET
tur=:urunid,
baslik=:urun_ad,
detay=:urun_detay,
fiyat=:urun_fiyat
");
$update=$ayarkaydet->execute(array(
'urunid' => $_POST['urun_tur'],
'urun_ad' => $_POST['urun_ad'],
'urun_detay' => $_POST['urun_detay'],
'urun_fiyat' => $_POST['urun_fiyat']
));
if ($update) {
header("Location:../urun.php?durum=ok");
}else {
header("Location:../urun.php?durum=no");
}
}
//----------------------------ürün resmi ekle-------------------------------
//----------------------------urun duzenle-------------------------------
if (isset($_POST['urun_duzenle'])) {
$ayarkaydet=$db->prepare("UPDATE urun SET
tur=:uruntur,
baslik=:urun_ad,
detay=:urun_detay,
fiyat=:urun_fiyat
WHERE id=:id");
$update=$ayarkaydet->execute(array(
'uruntur' => $_POST['urun_tur'],
'urun_ad' => $_POST['urun_ad'],
'urun_detay' => $_POST['urun_detay'],
'urun_fiyat' => $_POST['urun_fiyat'],
'id' => $_POST["urunid"]
));
if ($update) {
header("Location:../urun_duzenle.php?durum=ok&urun=".$_POST["urunid"]);
}else {
header("Location:../urun_duzenle.php?durum=no&urun=".$_POST["urunid"]);
}
}
//----------------------------kategori ekle-------------------------------
if (isset($_POST['kategori_ekle'])) {
$ayarkaydet=$db->prepare("INSERT INTO kategori SET
ad=:katad,
sira=:katsira
");
$update=$ayarkaydet->execute(array(
'katad' => $_POST['kategori_ad'],
'katsira' => $_POST['kategori_sira']
));
if ($update) {
Header("location:../kategoriler.php?durum=ok");
}else {
Header("location:../kategoriler.php?durum=no");
}
}
//----------------------------kategori duzenle-------------------------------
if (isset($_POST['kategori_duzenle'])) {
$kaydet=$db->prepare(" UPDATE kategori SET
ad=:katad,
sira=:katsira
WHERE id=:urunid");
$update=$kaydet->execute(array(
'katad' => $_POST['kategori_ad'],
'katsira' => $_POST['kategori_sira'],
'urunid' => $_POST['id']
));
if ($update) {
Header("location:../kategoriler.php?durum=uok&urun_id=$urun_id");
}else {
Header("location:../kategoriler.php?durum=uno&urun_id=$urun_id");
}
}
//----------------------------site ayar -------------------------------
if (isset($_POST['siteayarkaydet'])) {
$id=0;
$uzantim="../../";
if ($_FILES["resim_url"]["size"]>0){
if ($_FILES["resim_url"]["size"]<5024*5024){//Dosya boyutu 1Mb tan az olsun
if ($_FILES["resim_url"]["type"]=="image/png"){ //dosya tipi jpeg olsun
$dosya_adi = $_FILES["resim_url"]["name"];
//Resimi kayıt ederken yeni bir isim oluşturalım
$uret=array("as","rt","ty","yu","fg");
$uzanti=substr($dosya_adi,-4,4);
$sayi_tut=rand(1,10000);
$yeni_ad="img/".$uret[rand(0,4)].$sayi_tut.$uzanti;
//Dosya yeni adıyla uploadklasorune kaydedilecek
if (move_uploaded_file($_FILES["resim_url"]["tmp_name"],$uzantim.$yeni_ad)){
echo 'Dosya başarıyla yüklendi.';
$bul = $db->prepare("SELECT * from siteayar where id=?");
$bul->execute(array(1));
$v = $bul->fetch();
unlink($uzantim.$v["logo"]);
//Bilgileri veritabanına kayıt ediyoruz..
$ayarkaydet=$db->prepare("UPDATE siteayar SET
logo=:op_logo,
telefon=:telefon,
mail=:mail,
twitter=:twitter,
facebook=:facebook,
linkedin=:linkedin,
copyright=:copyright
WHERE id=:op_id");
$update=$ayarkaydet->execute(array(
'op_id' => 1,
'op_logo' => $yeni_ad,
'telefon' => $_POST['telefon'],
'mail' => $_POST['mail'],
'twitter' => $_POST['twitter'],
'facebook' => $_POST['facebook'],
'linkedin' => $_POST['linkedin'],
'copyright' => $_POST['copyright']
));
if ($update) {
header("Location:../ayar.php?durum=ok");
}else {
header("Location:../ayar.php?durum=no");
}
}else{
header("Location:../ayar.php?durum=yuklenemedi");
}
}else{
header("Location:../ayar.php?durum=jpeg");
}
}else{
header("Location:../ayar.php?durum=boyut");
}
}
else{
$ayarkaydet=$db->prepare("UPDATE siteayar SET
telefon=:telefon,
mail=:mail,
twitter=:twitter,
facebook=:facebook,
linkedin=:linkedin,
copyright=:copyright
WHERE id=1");
$update=$ayarkaydet->execute(array(
'telefon' => $_POST['telefon'],
'mail' => $_POST['mail'],
'twitter' => $_POST['twitter'],
'facebook' => $_POST['facebook'],
'linkedin' => $_POST['linkedin'],
'copyright' => $_POST['copyright']
));
if ($update) {
header("Location:../ayar.php?durum=ok");
}else {
header("Location:../ayar.php?durum=no");
}
}
}
//----------------------------urun sil onaylı------------------------------
if(isset($_POST['urun_sil'])) {
deleteConfirmed($_POST['urunid']);
}
function deleteConfirmed($icerik_id){
global $db;
$sil=$db->prepare("DELETE from urun where id=:pimg_id");
$kontrol=$sil->execute(array(
'pimg_id' => $icerik_id
));
if ($kontrol) {
Header("Location:../urun.php?icerik_id=$icerik_id&durum=silok");
} else {
Header("Location:../urun.php?icerik_id=$icerik_id&durum=silno");
}
}
//----------------------------kategori sil onaylı------------------------------
if(isset($_POST['kategori_sil'])) {
deleteConfirmedd($_POST['id']);
}
function deleteConfirmedd($icerik_id){
global $db;
// Delete the entry
$bul = $db->prepare("SELECT * from kategori where id=?");
$bul->execute(array($icerik_id));
$v = $bul->fetch();
$bull = $db->prepare("SELECT * from urun where tur=?");
$bull->execute(array($v["ad"]));
$v2 = $bull->fetch();
if($v2["tur"]==$v["ad"]) {
Header("Location:../kategoriler.php?durum=icerikvar");
}else{
$sil=$db->prepare("DELETE from kategori where id=:pimg_id");
$kontrol=$sil->execute(array(
'pimg_id' => $icerik_id
));
if ($kontrol) {
Header("Location:../kategoriler.php?icerik_id=$icerik_id&durum=silok");
} else {
Header("Location:../kategoriler.php?icerik_id=$icerik_id&durum=silno");
}
}
}