<?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">DİL AYARLARI</a> </div>
  <h1>DİL AYARLARI</h1>
</div>
<div class="container-fluid">
  <hr>
  <div class="row-fluid">
  <? if (isset($_GET['f'])){?>
	<? $dizin="images/languages";?>
    <? 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 languages (title, short_title, image) values ('".addslashes($_POST['title'])."','".addslashes($_POST['short_title'])."', '".$src."')");?>
            <div class="alert green">
                <p><strong>Kayıt Başarılı!</strong> Yeni kayıt başarıyla eklenmiştir.</p>
                <a href="#" class="close">close</a>
            </div>
            <script type="text/javascript" language="JavaScript">window.location.href="languages.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 languages set image='".$src."' where id='".$_POST['id']."'");
                }
            }?>
            <? mysql_query("Update languages set title='".addslashes($_POST['title'])."',short_title='".addslashes($_POST['short_title'])."' where id='".$_POST['id']."'");?>
            <div class="alert orange">
                <p><strong>Düzenleme Başarılı!</strong> Kayıt başarıyla güncellenmiştir.</p>
                <a href="#" class="close">close</a>
            </div>
            <script type="text/javascript" language="JavaScript">window.location.href="languages.php"</script>
        <? }?>	
        <? if ($_GET['f']=='delete'){?>
            <? mysql_query("Delete from languages where id='".$_POST['id']."'");?>
            <div class="alert red">
                <p><strong>Silme Başarılı!</strong> Kayıt başarıyla silinmiştir.</p>
                <a href="#" class="close">close</a>
            </div>
            <script type="text/javascript" language="JavaScript">window.location.href="languages.php"</script>
        <? }?>	
    <? }?>
  	<? if(($_GET['f']=='edit')&&(!isset($_POST['form_submit']))){?>
    <? $data=mysql_fetch_assoc(mysql_query("Select * from languages 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="languages.php?f=edit" method="post" enctype="multipart/form-data" class="form-horizontal">
            <div class="control-group">
              <label class="control-label">Dil :</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">Kısaltma :</label>
              <div class="controls">
                <input type="text" class="span11" value="<?=stripslashes($data['short_title'])?>" name="short_title" />
              </div>
            </div>
            <div class="control-group">
              <label class="control-label">Bayrak : <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 languages 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="languages.php?f=delete" method="post" enctype="multipart/form-data" class="form-horizontal">
            <div class="control-group">
              <label class="control-label">Dil :</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">Kaydet</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="languages.php?f=add" method="post" enctype="multipart/form-data" class="form-horizontal">
            <div class="control-group">
              <label class="control-label">Dil :</label>
              <div class="controls">
                <input type="text" class="span11" value="" name="title" />
              </div>
            </div>
            <div class="control-group">
              <label class="control-label">Kısaltma :</label>
              <div class="controls">
                <input type="text" class="span11" value="" name="short_title" />
              </div>
            </div>
            <div class="control-group">
              <label class="control-label">Bayrak : </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>Data table</h5>
            <div style="margin:0 20px 0; padding:0 0 0; float:right;">
                	
                <div class="btn-group">
                    <button class="btn btn-danger">İşlemler</button>
                    <button data-toggle="dropdown" class="btn btn-danger dropdown-toggle"><span class="caret"></span></button>
                    <ul class="dropdown-menu">
                        <li><a href="javascript:void(0)" id="show_language">Sitede Göster</a></li>
                        <li><a href="javascript:void(0)" id="hide_language">Sitede Gösterme</a></li>
                        <li><a href="javascript:void(0)" id="delete_language">Seçilileri Sil</a></li>
                    </ul>
               </div>
            </div>
          </div>
          <div class="widget-content nopadding">
            <table class="table table-bordered data-table">
              <thead>
                <tr>
                    <th>Sıra</th>
                    <th width="30%">Dil</th>
                    <th>Kısaltma</th>
                    <th class="sorting_disabled">Bayrak</th>
                    <th>İşlem</th>
                    <th>Sitede</th>
                    <th>/</th>                                      
                </tr>
            </thead>
            <tbody>
            <? $query=mysql_query("Select * from languages ")?>
            <? while ($data=mysql_fetch_assoc($query)){?>
                <tr id="record_<?=stripslashes($data['id'])?>">
                    <td><?=stripslashes($data['priority'])?></td>  
                    <td><?=stripslashes($data['title'])?></td>
                    <td><?=stripslashes($data['short_title'])?></td>
                    <td><img src="../<?=$data['image']?>" alt="thumb" width="30" /></td> 
                    <td>
                        <a href="languages.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="languages.php?f=delete&id=<?=stripslashes($data['id'])?>" class="tt btn btn-small" title="Kaydı Sil"><i class="isw-cancel"></i>Sil</a>
                    </td> 
                    <td id="language_<?=stripslashes($data['id'])?>"><? if ($data['status']==0){?><span class="label label-success">Var</span><? }else{?><span class="label label-inverse">Yok</span><? }?></td>
                    <td><input type="checkbox" rel="<?=stripslashes($data['id'])?>" p_code="<?=stripslashes($data['id'])?>" /></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> 
<script>
$("#delete_language").click(function() {
	$("input[type='checkbox']").each(function() {
		if($(this).prop('checked')){
			var language= $( this ).attr("rel");
			$.ajax({
				type: "POST",
				url: "ajaxfunctions.php",
				data: { 
					f: "delete_language",
					language: language
				},
				success: function(){
					$("#record_"+language).remove();
				}
			})
		}
	});
}); 
</script>
<script>
$("#show_language").click(function() {
	$("input[type='checkbox']").each(function() {
		if($(this).prop('checked')){
			var language= $( this ).attr("rel");
			$.ajax({
				type: "POST",
				url: "ajaxfunctions.php",
				data: { 
					islem: "show_language",
					language: language
				},
				success: function(){
					$("#language_"+language).html('<span class="label label-success">Eklendi</span>');
				}
			})
		}
	});
}); 
</script>
<script>
$("#hide_language").click(function() {
	$("input[type='checkbox']").each(function() {
		if($(this).prop('checked')){
			var language= $( this ).attr("rel");
			$.ajax({
				type: "POST",
				url: "ajaxfunctions.php",
				data: { 
					islem: "hide_language",
					language: language
				},
				success: function(){
					$("#language_"+language).html('<span class="label label-inverse">Kaldırıldı</span>');
				}
			})
		}
	});
}); 
</script>
</body>
</html>





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