<?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'>
<script src="js/jquery.min.js"></script> 
<? include 'tiny_script.php';?>
</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 Git" class="tip-bottom"><i class="icon-home"></i>ANASAYFA</a><a href="#" class="current">DOSYALAR</a> </div>
  <h1>DOSYALAR</h1>
</div>
<div class="container-fluid">
  <hr>
  <div class="row-fluid">
  <? if (isset($_GET['f'])){?>
	<? $dizin="images/gallery_files";?>
	<? 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
                }
            }?>
            <? 
            $file='';
            if ($_FILES["file"]["error"]== 0)
            {
                $file=turkcekarakter($_FILES['file']['name']);
                $random=rand(1,99999);
                $filesrc="$dizin/".$random.$file;
                $file="../$dizin/".$random.$file;
                move_uploaded_file($_FILES['file']['tmp_name'],$file); // yükleme işlemi
            }?>
            <? 
            mysql_query("Insert into gallery_files (title, file, image, gallery) values ('".addslashes($_POST['title'])."','".$filesrc."','".$src."','".$_GET['gallery']."')");?>
            <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="gallery_files.php?gallery=<?=$_GET['gallery']?>"</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 gallery_files set image='".$src."' where id='".$_POST['id']."'");
                }
            }?>
            <? 
            $file='';
            if ($_FILES["file"]["error"]== 0)
            {
                $file=turkcekarakter($_FILES['file']['name']);
                $random=rand(1,99999);
                $filesrc="$dizin/".$random.$file;
                $file="../$dizin/".$random.$file;
                move_uploaded_file($_FILES['file']['tmp_name'],$file); // yükleme işlemi
                mysql_query("Update gallery_files set file='".$filesrc."' where id='".$_POST['id']."'");
            }?>
            <? mysql_query("Update gallery_files set title='".addslashes($_POST['title'])."'  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="gallery_files.php?gallery=<?=$_GET['gallery']?>"</script>
        <? }?>	
        <? if ($_GET['f']=='delete'){?>
            <? mysql_query("Delete from gallery_files 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="gallery_files.php?gallery=<?=$_GET['gallery']?>"</script>
        <? }?>	
    <? }?>
  	<? if(($_GET['f']=='edit')&&(!isset($_POST['form_submit']))){?>
    <? $data=mysql_fetch_assoc(mysql_query("Select * from gallery_files 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="gallery_files.php?f=edit&gallery=<?=$_GET['gallery']?>" 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">Resim : <img src="../<?=$data['image']?>" alt="thumb" width="30" /></label>
              <div class="controls">
                <input type="file" name="image"/>
              </div>
            </div>
            <div class="control-group">
              <label class="control-label">Dosya : <?=$data['file']?></label>
              <div class="controls">
                <input type="file" name="file" />
              </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 gallery_files where id='".$_GET['id']."'"))?>
    <div class="span12">
      <div class="widget-box">
        <div class="widget-title"> <span class="icon"> <i qclass="icon-align-justify"></i> </span>
          <h5>Kayıt Sil</h5>
        </div>
        <div class="widget-content nopadding">
          <form action="gallery_files.php?f=delete&gallery=<?=$_GET['gallery']?>" 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="gallery_files.php?f=add&gallery=<?=$_GET['gallery']?>" 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">Resim :</label>
              <div class="controls">
                <input type="file" name="image"/>
              </div>
            </div>
            <div class="control-group">
              <label class="control-label">Dosya :</label>
              <div class="controls">
                <input type="file" name="file"/>
              </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>Başlık</th> 
                        <? $q=mysql_query("Select * from languages order by id asc")?>
						<? while ($d=mysql_fetch_assoc($q)){?>
                        <th>İçerik(<?=stripslashes($d['title'])?>)</th>
                        <? }?>
                        <th class="sorting_disabled">Görsel</th>
                        <th>İşlem</th>                                      
                    </tr>
                </thead>
                <tbody>
                <? $query=mysql_query("Select * from gallery_files where gallery='".$_GET['gallery']."'")?>
                <? while ($data=mysql_fetch_assoc($query)){?>
                    <tr>
                        <td><?=stripslashes($data['id'])?></td>  
                        <td><?=stripslashes($data['title'])?></td>
                        <? $q=mysql_query("Select * from languages order by id asc")?>
						<? while ($d=mysql_fetch_assoc($q)){?>
                        <? $cont=mysql_query("Select * from l_gallery_files where gallery_file='".$data['id']."' and language='".$d['id']."'")?>
                        <td>
                            <? if (mysql_num_rows($cont)==0){?>
                            <a href="gallery_files_content.php?f=add&gallery_file=<?=$data['id']?>&language=<?=$d['id']?>&gallery=<?=$_GET['gallery']?>" class="label label-important">Ekle</a>
                            <? }else{?>
                            <a href="gallery_files_content.php?f=edit&gallery_file=<?=$data['id']?>&language=<?=$d['id']?>&gallery=<?=$_GET['gallery']?>" class="label label-warning">Düzenle</a>
                            <? }?>
                        </td>
                        <? }?>
                        <td><?=$data['file']?></td> 
                        <td>
                            <a href="gallery_files.php?f=edit&id=<?=stripslashes($data['id'])?>&gallery=<?=$_GET['gallery']?>" class="tt btn btn-small" title="Kaydı Düzenle"><i class="isw-edit"></i>Düzenle</a> 
                            <a href="gallery_files.php?f=delete&id=<?=stripslashes($data['id'])?>&gallery=<?=$_GET['gallery']?>" 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.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');}?>