<? require_once($_SERVER['DOCUMENT_ROOT'].'/admin/block/head.php'); 
mysql_query("truncate table `nano_tmp`") OR DIE(mysql_error());
$id_to = mysql_result(mysql_query("SELECT `id` FROM `nano_kat` ORDER BY `id` DESC"),0,0);
$id_kat = $id_to + '1';
?>

<div class="row">
<div class="col-md-9">
<div class="panel panel-primary">

<table class="table table-bordered">
<tr>
<th style="width: 30px"><center>№</center></th>
<th>Название категории</th>
<th style="width: 70px"><center>Операции</center></th>
</tr>

<?
$sql = mysql_query("SELECT `id`,`name` FROM `nano_kat`") or die(mysql_error());
if(mysql_num_rows($sql) > '0'){
while($row = mysql_fetch_assoc($sql)){
$id = $row["id"];
$name = $row["name"];
?>
<tr>
<td><center><b><?=$id;?></b></center></td>
<td><?=$name;?></td>
<td><center>
<a id="sample_<?=$id;?>" class='fa fa-pencil-square-o' style="padding-right: 5px; text-decoration: none; cursor: pointer;" data-toggle="tooltip" title='Редактировать'></a>
<a class='fa fa-trash-o' style="padding-right: 5px; text-decoration: none;" data-toggle="tooltip" title='Удалить' href='javascript:void(0);' onclick='del_<?=$id;?>();'></a>
</center></td>
</tr>
<script>
function del_<?=$id;?>() {
{
$.ajax({
type: "POST", 
url: "/admin/ajax/kat.php", 
data: { 'func' : 'del_kat', 'id' : <?=$id;?>},
beforeSend: function(){ progress = true;},
success: function(data) {
if(data == 1) { QBinfo('Поздравляем:','Категория <?=$name;?> удалена.',4000,'bottom-right');
setTimeout('location.replace("/admin/add_kat")', 2000);
}
progress = false;
}
});
}
}

$(document).ready(function(){
	$("#imgLoad").hide();
});

$('#sample_<?=$id;?>').click( function() {
$("#imgLoad").show();
$.ajax({
type: 'POST',
url: '/admin/ajax/kat.php?action=sample1',
data: {'id' : <?=$id;?>},
success: function(data) {
$('.results').html(data);
$("#imgLoad").hide();
}
});
});
</script>
<?}?>
</table>
<?}else{?>
<tr>
<td colspan="3">
<center>Категорий нет</center>
</td>
</tr>
</table>
<?}?>
</div>
</div>

<div class="col-md-3">
<div style="padding-bottom:5px;" id="imgLoad">
<div class="progress progress-xs progress-striped active" id="imgLoad">
<div class="progress-bar progress-bar-success" id="imgLoad" style="width: 100%"></div>
</div>                                   
</div>
<div class="results">
<div class="panel panel-primary">
<div class="panel-heading"><h3 class="panel-title">Добавить категорию</h3></div>
<div class="panel-body">
<form class="form-horizontal">
<div class="form-group">
<div class="col-md-12">                                            
<div class="input-group">
<span class="input-group-addon" data-toggle="tooltip" title="Введите название категории."><span class="fa fa-database"></span></span>
<input type="text" class="form-control" id="name_kat">
</div>
</div>
</div>
<div class="form-group">
<div class="col-md-12">                                            
<div class="input-group">
<span class="input-group-addon" data-toggle="tooltip" title="Введите описание категории."><span class="fa fa-database"></span></span>
<input type="text" class="form-control" id="text_kat">
</div>
</div>
</div>
</form>
</div>
<div class="panel-body">
<div class="photo">
<div id="files" ></div>
</div>
</div>

<div class="panel-footer">
<div class="form-group">
<div class="col-md-6"><button id="upload_1" class="btn btn-primary btn-block">Фото</button></div>
<div class="col-md-6"><button class="btn btn-success btn-block" href='javascript:void(0);' onclick='add_kat();'>Добавить</button></div>
</div>
</div>

</div>

</div>
</div>

</div>

<script>
$(function(){
var btnUpload=$('#upload_1');
var status=$('#status_1');
new AjaxUpload(btnUpload, {
action: '/admin/ajax/kat.php',
name: 'uploadfile',
onSubmit: function(file, ext){
if (! (ext && /^(jpg|png|jpeg|gif)$/.test(ext))){ 
status.text('Только JPG, PNG или GIF');
return false;
}
status.text('Идёт загрузка');
},
onComplete: function(file, response){
status.text('');
if(response==="1"){
$('<div></div>').appendTo('#files').html('<center>Фото загружено</center><br />').addClass('1');
} else{
$('<li></li>').appendTo('#files').text(file).addClass('2');
}
}
});
});

function add_kat() {
{
var name_kat = ($('#name_kat').val());
var text_kat = ($('#text_kat').val());
$.ajax({
type: "POST", 
url: "/admin/ajax/kat.php", 
data: { 'func' : 'add_kat', 'name_kat' : name_kat, 'text_kat' : text_kat},
beforeSend: function(){ progress = true;},
success: function(data) {
if(data == 1) { QBinfo('Поздравляем:','Новая категория добавлена на сайт.',4000,'bottom-right');
setTimeout('location.replace("/admin/add_kat")', 2000);
}
progress = false;
}
});
}
}
</script>

<? require_once($_SERVER['DOCUMENT_ROOT'].'/admin/block/foot.php'); ?>