<?php
require_once($_SERVER['DOCUMENT_ROOT'].'/system/App.php');
$id = isset($_GET['id']) && !empty($_GET['id']) ? intval($_GET['id']) : null;
$album = $albums->getById($id);
$title = !empty($album['name']) ? $album['name'] : 'Альбом';
require_once ROOT.'/system/header.php';
if(!empty($album))
{
$photos = $albums->photosByID($album['id'], 0, 20);
$author = (empty($album['user_id']) ? 'Гость' : '<a href="/id'.$album['user_id'].'">'.$user->infoByID($album['user_id'])['login'].'</a>');
}
else
{
$core->redirect('/');
}
?>
</div>
<div class="row">
<div class="col"></div>
<div class="col-sm-10">
<div class="card">
<a href="/add_ads" class="no-ads">Купить рекламу</a>
</div>
</div>
<div class="col"></div>
</div>
<div class="row">
<div class="col"></div>
<div class="col-sm-7">
<div id="alerts"></div>
<div class="card">
<script>
$(document).ready(function()
{
var removeB = $('#remove');
var data = $(removeB).attr('data-id');
$(removeB).on('click', function(e) {
e.preventDefault();
$.ajax({
url: '/AJAX/removeAlbum.php',
type: 'post',
data: {id:data},
dataType: 'json',
success: function(json) {
$('#alerts').show();
if(json['error'] == 1) {
$('#alerts').html('<div class="alert alert-danger">'+json['comment']+'</div>');
} else if(json['success'] == 1) {
$('#alerts').html('<div class="alert alert-success">'+json['comment']+'</div>');
location.href = json['url'];
}
setTimeout(function () {
$('#alerts').hide();
}, 2000);
},
error: function(xhr, ajaxOptions, thrownError) {
alert(thrownError + "\r\n" + xhr.statusText + "\r\n " + xhr.responseText);
}
});
});
$('#exampleModal').on('show.bs.modal', function (event) {
var button = $(event.relatedTarget) // Button that triggered the modal
var recipient = button.data('whatever') // Extract info from data-* attributes
// If necessary, you could initiate an AJAX request here (and then do the updating in a callback).
// Update the modal's content. We'll use jQuery here, but you could use a data binding library or other methods instead.
var modal = $(this)
modal.find('#photo-title').text(recipient)
// modal.find('#card-image').val(recipient)
$('#card-image').attr('src', recipient)
});
var qrcode = new QRCode("qrCodeLink", {
text: "<?=HOME?>/album/id<?=$album['id']?>",
width: 150,
height: 150,
colorDark : "#000",
colorLight : "#fff",
correctLevel : QRCode.CorrectLevel.H
});
$('.deletePhoto').on('click', function(e) {
e.preventDefault();
var data = $(this).attr('data-id');
var element = $('#photo' + data);
var alerts = $('#alerts');
$.ajax({
url: '/AJAX/deletePhoto.php',
type: 'post',
data: {id:data},
dataType: 'json',
success: function(json) {
if(json['error'] == 1) {
$(alerts).html('<div class="alert alert-danger">'+json['comment']+'</div>');
} else if(json['success'] == 1) {
$(alerts).html('<div class="alert alert-success">'+json['comment']+'</div>');
$(element).remove();
}
setTimeout(function () {
$(alerts).html('');
}, 2000);
},
error: function(xhr, ajaxOptions, thrownError) {
alert(thrownError + "\r\n" + xhr.statusText + "\r\n " + xhr.responseText);
}
});
});
});
</script>
<div class="card-header text-muted">
<h5 class="card-title"><?=$album['name']?></h5>
<?=$author?> в <?=$sys->time($album['time'])?>
<span class="float-right">
<div class="dropdown show">
<a class="badge badge-pill badge-danger dropdown toggle" href="#" role="button" id="dropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Действие
</a>
<div class="dropdown-menu dropdown-menu-right bg-theme-dark" aria-labelledby="dropdownMenuLink">
<?=($me['id'] == $album['user_id'] || $me['access'] > 0 ? '<a class="dropdown-item text-secondary" href="#" id="remove" data-id="'.$album['id'].'">Удалить</a><a class="dropdown-item text-secondary" href="/album/id'.$album['id'].'/edit">Редактировать</a>' : '')?>
<a class="dropdown-item text-secondary" href="#" data-toggle="modal" data-target="#exampleModalLong">Поделиться</a>
</div>
</div>
</span>
</div>
<div class="tz-gallery">
<div class="form-row">
<?php
if(!empty($photos))
{
foreach($photos as $photo)
{
?>
<div class="col-sm-12 col-md-12 col-lg-12 m-0 w-100" id="photo<?=$photo['id']?>">
<span class="holder-top text-small">
<?=HOME.'/uploads/'.$photo['name']?>
</span>
<?php
if($me['id'] == $photo['user_id'] || $me['access'] > 0)
{
?>
<span class="holder-bottom">
<input type="submit" id="del" class="btn btn-theme-link btn-sm deletePhoto" data-id="<?=$photo['id']?>" value="Удалить изображение">
</span>
<?php
}
?>
<a href="<?=HOME.'/uploads/'.$photo['name']?>" class="lightbox no-ajaxy">
<img class="w-100" src="<?=HOME.'/uploads/'.$photo['name']?>">
</a>
</div>
<?php
}
}
else
{
echo '<div class="card-body text-center text-muted">Альбом пуст</div>';
}
?>
</div>
</div>
</div>
</div>
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog modal-xl" role="document">
<div class="card bg-dark text-white">
<img class="card-img" src="" id="card-image" alt="Card image">
<div class="card-img-overlay">
<h5 class="card-title" id="photo-title"></h5>
</div>
</div>
</div>
</div>
<div class="col-sm-3">
<div class="card">
<ul class="list-group list-group-flush">
<a class="list-group-item text-secondary" href="#" data-toggle="modal" data-target="#getZipArchive">Скачать альбом</a>
</ul>
</div>
<div class="card">
<div class="card-header">Реклама</div>
<ul class="list-group list-group-flush">
<a class="list-group-item text-secondary" href="#ads">Рекламная ссылка</a>
</ul>
</div>
</div>
<div class="col"></div>
</div>
<!-- Поделиться -->
<div class="modal fade" id="exampleModalLong" tabindex="-1" role="dialog" aria-labelledby="exampleModalLongTitle" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content bg-theme-dark">
<div class="modal-header" style="border-bottom: 1px solid rgba(0,0,0,0.2)!important;">
<h5 class="modal-title" id="exampleModalLongTitle">Поделиться</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<div class="form-group">
<label for="exampleFormControlInput1">Ссылка</label>
<input type="url" class="form-control" id="exampleFormControlInput1" value="http://<?=$_SERVER['HTTP_HOST']?>/album/id<?=$album['id']?>">
</div>
<div class="form-group text-center">
<label for="exampleFormControlInput1" class="w-100">QR-код</label>
<style>
.qrcode {
margin: 5px;
text-align: center;
display: inline-block!important;
}
</style>
<span id="qrCodeLink" class="qrcode"></span>
</div>
</div>
<div class="modal-footer" style="border-top: 1px solid rgba(0,0,0,0.2)!important;">
<button type="button" class="btn btn-danger" data-dismiss="modal">Закрыть</button>
</div>
</div>
</div>
</div>
<!-- Скачать zip -->
<div class="modal fade" id="getZipArchive" tabindex="-1" role="dialog" aria-labelledby="getZipArchiveTitle" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content bg-theme-dark">
<div class="modal-header" style="border-bottom: 1px solid rgba(0,0,0,0.2)!important;">
<h5 class="modal-title" id="exampleModalLongTitle">Скачать альбом</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<script type="text/javascript">
$(document).ready(function () {
$('#getZipArchiveButton').on('click', function(e) {
e.preventDefault();
var formData = $('#getZipArchiveForm').serialize();
var alerts = $('#zipAlerts');
$.ajax({
url: $('#getZipArchiveForm').attr('action'),
type: $('#getZipArchiveForm').attr('method'),
data: formData, // можно строкой, а можно, например, так: $('input[type="text"], input[type="radio"]:checked, input[type="checkbox"]:checked, select, textarea')
dataType: 'json',
success: function(json) {
if(json['error'] == 1) {
$(alerts).html('<div class="alert alert-danger">'+json['comment']+'</div>');
} else if(json['success'] == 1) {
location.href = json['url'];
}
setTimeout(function () {
$(alerts).html('');
}, 2000);
},
error: function(xhr, ajaxOptions, thrownError) {
alert(thrownError + "\r\n" + xhr.statusText + "\r\n " + xhr.responseText);
}
});
});
});
</script>
<form action="/AJAX/createZipArchive.php" method="POST" id="getZipArchiveForm">
<div id="zipAlerts"></div>
<div class="form-group">
<label for="exampleFormControlInput1">Название архива</label>
<input type="hidden" id="album_id" name="album_id" value="<?=$album['id']?>">
<input type="text" name="zip_name" class="form-control" id="exampleFormControlInput1" value="<?=$album['url']?>">
</div>
</form>
</div>
<div class="modal-footer" style="border-top: 1px solid rgba(0,0,0,0.2)!important;">
<button type="button" class="btn btn-danger" data-dismiss="modal">Отмена</button>
<button type="button" class="btn btn-success" id="getZipArchiveButton">Скачать</button>
</div>
</div>
</div>
</div>
<script>
baguetteBox.run('.tz-gallery');
</script>
<div class="row">
<?php
require_once ROOT.'/system/footer.php';
?>