<?php
session_start();	
?>
<?php
include_once 'ayarlar.php';
$mysql_baglanti= new yonetici(); 
$mysql_baglanti->mysql_baglan();
error_reporting(E_ALL ^ E_NOTICE);
ini_set('error_reporting', E_ALL ^ E_NOTICE); 
?>
<? 
if (isset($_SESSION['adminuser'])){
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title><?=$site_name?></title>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="css/bootstrap.min.css" />
<link rel="stylesheet" href="css/bootstrap-responsive.min.css" />
<link rel="stylesheet" href="css/colorpicker.css" />
<link rel="stylesheet" href="css/datepicker.css" />
<link rel="stylesheet" href="css/uniform.css" />
<link rel="stylesheet" href="css/select2.css" />
<link rel="stylesheet" href="css/matrix-style.css" />
<link rel="stylesheet" href="css/matrix-media.css" />
<link rel="stylesheet" href="css/bootstrap-wysihtml5.css" />
<link href="font-awesome/css/font-awesome.css" rel="stylesheet" />
<link href='http://fonts.googleapis.com/css?family=Open+Sans:400,700,800' rel='stylesheet' type='text/css'>
</head>
<body>
<? include 'inc_header.php'?>
<? include 'inc_leftmenu.php'?>
<div id="content">
<div id="content-header">
  <div id="breadcrumb"> <a href="index.php" title="Anasayfaya Gİt" class="tip-bottom"><i class="icon-home"></i>ANASAYFA</a><a href="#" class="current">POPUP</a> </div>
  <h1>POPUP</h1>
</div>
<div class="container-fluid">
  <hr>
  <div class="row-fluid">
  <? if (isset($_GET['f'])){?>
	<? $dizin="images/popup";?>
	<? if (isset($_POST['form_submit'])&&($_POST['form_submit']==1)){?>
        <? if ($_GET['f']=='add'){?>
            <? 
            $image='';
            if ($_FILES["image"]["error"]== 0)
            {
            $uzanti=array('image/jpeg','image/jpg','image/png','image/x-png','image/gif'); 
                if(in_array(strtolower($_FILES['image']['type']),$uzanti)){
                $image=turkcekarakter($_FILES['image']['name']);
                $random=rand(1,99999);
                $src="$dizin/".$random.$image;
                $image="../$dizin/".$random.$image;
                move_uploaded_file($_FILES['image']['tmp_name'],$image); // yükleme işlemi
                }
            }?>
            <? 
            mysql_query("Insert into popup (title, link, image) values ('".addslashes($_POST['title'])."','".addslashes($_POST['link'])."','".$src."')");?>
            
            <div class="alert alert-success">
              <button class="close" data-dismiss="alert">×</button>
              <strong>Kayıt Başarılı!</strong> Yeni kayıt başarıyla eklenmiştir.
            </div>
            <script type="text/javascript" language="JavaScript">window.location.href="popup.php"</script>
        <? }?>	
        <? if ($_GET['f']=='edit'){?>
            <? 
            $image='';
            if ($_FILES["image"]["error"]== 0)
            {
            $uzanti=array('image/jpeg','image/jpg','image/png','image/x-png','image/gif'); 
                if(in_array(strtolower($_FILES['image']['type']),$uzanti)){
                $image=turkcekarakter($_FILES['image']['name']);
                $random=rand(1,99999);
                $src="$dizin/".$random.$image;
                $image="../$dizin/".$random.$image;
                move_uploaded_file($_FILES['image']['tmp_name'],$image); // yükleme işlemi
                mysql_query("Update popup set image='".$src."' where id='".$_POST['id']."'");
                }
            }?>
            <? mysql_query("Update popup set title='".addslashes($_POST['title'])."', link='".addslashes($_POST['link'])."' where id='".$_POST['id']."'");?>
            <div class="alert alert-success">
              <button class="close" data-dismiss="alert">×</button>
              <strong>Düzenleme Başarılı!</strong> Yeni kayıt başarıyla güncellenmiştir.
            </div>
            <script type="text/javascript" language="JavaScript">window.location.href="popup.php"</script>
        <? }?>	
        <? if ($_GET['f']=='delete'){?>
            <? mysql_query("Delete from popup where id='".$_POST['id']."'");?>
            <div class="alert alert-success">
              <button class="close" data-dismiss="alert">×</button>
              <strong>Silme Başarılı!</strong> Kayıt başarıyla silinmiştir.
            </div>
            <script type="text/javascript" language="JavaScript">window.location.href="popup.php"</script>
        <? }?>	
    <? }?>
  	<? if(($_GET['f']=='edit')&&(!isset($_POST['form_submit']))){?>
    <? $data=mysql_fetch_assoc(mysql_query("Select * from popup where id='".$_GET['id']."'"))?>
    <div class="span12">
      <div class="widget-box">
        <div class="widget-title"> <span class="icon"> <i class="icon-align-justify"></i> </span>
          <h5>Kayıt Düzenle</h5>
        </div>
        <div class="widget-content nopadding">
          <form action="popup.php?f=edit" method="post" enctype="multipart/form-data" class="form-horizontal">
            <div class="control-group">
              <label class="control-label">Başlık :</label>
              <div class="controls">
                <input type="text" class="span11" value="<?=stripslashes($data['title'])?>" name="title" />
              </div>
            </div>
            <div class="control-group">
              <label class="control-label">Link :</label>
              <div class="controls">
                <input type="text" class="span11" value="<?=stripslashes($data['link'])?>" name="link" />
              </div>
            </div>
            <div class="control-group">
              <label class="control-label">Resim : <img src="../<?=$data['image']?>" alt="thumb" width="30" /></label>
              <div class="controls">
                <input type="file" name="image"/>
              </div>
            </div>
            <div class="form-actions">
                <input type="hidden" name="id" value="<?=$data['id']?>" />
                <input type="hidden" name="form_submit" value="1" />
              <button type="submit" class="btn btn-success">Kaydet</button>
            </div>
          </form>
        </div>
      </div>
    </div>
    <? }?>
	<? if(($_GET['f']=='delete')&&(!isset($_POST['form_submit']))){?>
    <? $data=mysql_fetch_assoc(mysql_query("Select * from popup where id='".$_GET['id']."'"))?>
    <div class="span12">
      <div class="widget-box">
        <div class="widget-title"> <span class="icon"> <i class="icon-align-justify"></i> </span>
          <h5>Kayıt Sil</h5>
        </div>
        <div class="widget-content nopadding">
          <form action="popup.php?f=delete" method="post" enctype="multipart/form-data" class="form-horizontal">
            <div class="control-group">
              <label class="control-label">Başlık :</label>
              <div class="controls">
                <input type="text" class="span11" value="<?=stripslashes($data['title'])?>" name="title" />
              </div>
            </div>
            <div class="form-actions">
                <input type="hidden" name="id" value="<?=$data['id']?>" />
                <input type="hidden" name="form_submit" value="1" />
              <button type="submit" class="btn btn-success">Kaydı Sil</button>
            </div>
          </form>
        </div>
      </div>
    </div>
    <? }?>
    <? }else{?>
    <div class="span12">
      <div class="widget-box">
        <div class="widget-title"> <span class="icon"> <i class="icon-align-justify"></i> </span>
          <h5>Kayıt Ekle</h5>
        </div>
        <div class="widget-content nopadding">
          <form action="popup.php?f=add" method="post" enctype="multipart/form-data" class="form-horizontal">
            <div class="control-group">
              <label class="control-label">Başlık :</label>
              <div class="controls">
                <input type="text" class="span11" value="" name="title" />
              </div>
            </div>
          <div class="control-group">
              <label class="control-label">Link :</label>
              <div class="controls">
                <input type="text" class="span11" value="" name="link" />
              </div>
            </div>
            <div class="control-group">
              <label class="control-label">Kapak Resmi :</label>
              <div class="controls">
                <input type="file" name="image"/>
              </div>
            </div>
            <div class="form-actions">
            	<input type="hidden" name="form_submit" value="1" />
              <button type="submit" class="btn btn-success">Kaydet</button>
            </div>
          </form>
        </div>
      </div>
      <div class="widget-box">
          <div class="widget-title"> <span class="icon"><i class="icon-th"></i></span>
            <h5>Kayıtlar</h5>
            

          </div>
          <div class="widget-content nopadding">
            <table class="table table-bordered data-table">
              <thead>
                	<tr>
                        <th>ID</th>
                        <th width="30%">Başlık</th>
                       
                        <th class="sorting_disabled">Görsel</th>
                        <th>İşlem</th>
                    </tr>
                </thead>
                <tbody>
                <? $query=mysql_query("Select * from popup")?>
                <? while ($data=mysql_fetch_assoc($query)){?>
                <? $language=mysql_fetch_assoc(mysql_query("Select * from languages where id='".$data['language']."'"))?>
                    <tr id="record_<?=stripslashes($data['id'])?>">
                        <td><?=stripslashes($data['id'])?></td>  
                        <td><?=stripslashes($data['title'])?></td>
                        
                        <td><img src="../<?=$data['image']?>" alt="thumb" width="90" /></td> 
                        <td>
                            <a href="popup.php?f=edit&id=<?=stripslashes($data['id'])?>" class="tt btn btn-small" title="Kaydı Düzenle"><i class="isw-edit"></i>Düzenle</a> 
                            <a href="popup.php?f=delete&id=<?=stripslashes($data['id'])?>" class="tt btn btn-small" title="Kaydı Sil"><i class="isw-cancel"></i>Sil</a>
                        </td>
                                                     
                    </tr>
                <? }?>
              </tbody>
            </table>
          </div>
        </div>
    </div>
    <? }?>
  </div>
</div></div>
<script src="js/jquery.min.js"></script> 
<script src="js/jquery.ui.custom.js"></script> 
<script src="js/bootstrap.min.js"></script> 
<script src="js/bootstrap-colorpicker.js"></script> 
<script src="js/bootstrap-datepicker.js"></script> 
<script src="js/jquery.toggle.buttons.html"></script> 
<script src="js/masked.js"></script> 
<script src="js/jquery.uniform.js"></script> 
<script src="js/select2.min.js"></script> 
<script src="js/matrix.js"></script> 
<script src="js/matrix.form_common.js"></script> 
<script src="js/wysihtml5-0.3.0.js"></script> 
<script src="js/jquery.peity.min.js"></script> 

</body>
</html>
<? } else { header('location:login.php');}?>