<div class="container-fluid">
	<div class="row mb-2">
		<div class="col-sm-6 d-none d-md-block ">
			<h1 class="m-0 text-dark">{{ lang['images_title'] }}</h1>
		</div>
		<div class="col-sm-6">
			<ol class="breadcrumb float-sm-right">
				<li class="breadcrumb-item">
					<a href="{{ php_self }}">
						<i class="fa fa-home"></i>
					</a>
				</li>
				<li class="breadcrumb-item active" aria-current="page">{{ lang['images_title'] }}</li>
			</ol>
		</div>
	</div>
</div>
<div id="collapseImagesFilter" class="collapse">
	<div class="card mb-4">
		<div class="card-body">
			<form action="{{ php_self }}" method="get" name="options_bar">
				<input type="hidden" name="mod" value="images"/>
				<input type="hidden" name="action" value="list"/>
				<input type="hidden" name="area" value="{{ area }}"/>
				<div class="row">
					<div class="col-lg-3">
						<div class="form-group">
							<label>{{ lang['month'] }}</label>
							<select name="postdate" class="custom-select">
								<option selected value="">-
									{{ lang['all'] }}
									-</option>
								{{ dateslist|raw }}
							</select>
						</div>
					</div>
					<div class="col-lg-3">
						<div class="form-group">
							<label>{{ lang['category'] }}</label>
							{{ dirlistcat|raw }}
						</div>
					</div>
					<div class="col-lg-3">
						<div class="form-group">
							{% if status %}
								<label>{{ lang['author'] }}</label>
								<select name="author" class="custom-select">
									<option value="">-
										{{ lang['all'] }}
										-</option>
									{{ authorlist|raw }}
								</select>
							{% endif %}
						</div>
					</div>
					<div class="col-lg-3">
						<div class="form-group">
							<label>{{ lang['per_page'] }}</label>
							<input type="text" name="npp" value="{{ npp }}" class="form-control"/>
						</div>
						<div class="form-group mb-0 text-right">
							<button type="submit" class="btn btn-outline-primary">{{ lang['show'] }}</button>
						</div>
					</div>
				</div>
			</form>
		</div>
	</div>
</div>
<form id="delform" name="imagedelete" action="{{ php_self }}?mod=images" method="post">
	<input type="hidden" name="area" value="{{ area }}"/>
	<div class="card">
		<div class="card-header">
			<div class="d-flex">
				<div class="custom-control custom-switch py-2 mr-auto">
					<input id="entries" type="checkbox" class="custom-control-input" name="master_box" title="{{ lang['select_all'] }}" onclick="javascript:check_uncheck_all(imagedelete)"/>
					<label for="entries" class="custom-control-label">{{ lang['select_all_images']|default('Выделить все изображения') }}</label>
				</div>
				<button type="button" class="btn btn-outline-success ml-1" data-toggle="modal" data-target="#uploadImagesModal" data-backdrop="static">{{ lang['upload_img'] }}</button>
				{% if status %}
					<button type="button" class="btn btn-outline-primary ml-1" data-toggle="modal" data-target="#categoriesModal" data-backdrop="static" title="{{ lang['categories'] }}">
						<i class="fa fa-folder-open-o"></i>
					</button>
				{% endif %}
				<button type="button" class="btn btn-outline-primary ml-1" data-toggle="collapse" data-target="#collapseImagesFilter">
					<i class="fa fa-filter"></i>
				</button>
			</div>
		</div>
	<div class="row" id="entriesRow">
			<div class="col-md-12">
				<div class="panel-body">
					<div class="row">
						{{ entries|raw }}
					</div>
				</div>
			</div>
		</div>
		<div class="card-footer">
			<div class="row">
				<div class="col-lg-6 mb-2 mb-lg-0">{{ pagesss|raw }}</div>
				<div class="col-lg-6">
					{% if status %}
						<div class="input-group">
							<select name="subaction" class="custom-select">
								<option value="">--
									{{ lang['action'] }}
									--</option>
								<option value="delete">{{ lang['delete'] }}</option>
								<option value="move">{{ lang['move'] }}</option>
							</select>
							{{ dirlist|raw }}
							<div class="input-group-append">
								<button type="submit" class="btn btn-outline-warning">OK</button>
							</div>
						</div>
					{% endif %}
				</div>
			</div>
		</div>
	</div>
</form>
<div id="uploadImagesModal" class="modal fade" tabindex="-1" role="dialog">
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header">
				<h5 id="uploadImagesModalLabel" class="modal-title">{{ lang['upload_img'] }}</h5>
				<button type="button" class="close" data-dismiss="modal">
					<span>&times;</span>
				</button>
			</div>
			<ul class="nav nav-tabs" role="tablist">
				<li class="nav-item">
					<a class="nav-link active" id="upload-tab" data-toggle="tab" href="#uploadTab" role="tab">{{ lang['upload_img']|default('Загрузка файлов') }}</a>
				</li>
				<li class="nav-item">
					<a class="nav-link" id="url-tab" data-toggle="tab" href="#urlTab" role="tab">{{ lang['upload_img_url']|default('По ссылке') }}</a>
				</li>
			</ul>
			<div class="tab-content">
				<div class="tab-pane fade show active" id="uploadTab" role="tabpanel">
					<form id="uploadnew_form" action="{{ php_self }}?mod=images" method="post" enctype="multipart/form-data" name="sn">
				<input type="hidden" name="subaction" value="upload"/>
				<input type="hidden" name="area" value="{{ area }}"/>
				<div class="modal-body">
					<div class="form-group row">
						<label class="col-sm-4 col-form-label">{{ lang['category'] }}</label>
						<div class="col-sm-8">{{ dirlistS|raw }}</div>
					</div>
					<div class="form-group row">
						<div class="col-sm-8 offset-4">
							<label class="col-form-label d-block"><input id="flagReplace" type="checkbox" name="replace" value="1"/>
								{{ lang['do_replace'] }}</label>
							<label class="col-form-label d-block"><input id="flagRand" type="checkbox" name="rand" value="1"/>
								{{ lang['do_rand'] }}</label>
							<label class="col-form-label d-block"><input id="flagThumb" type="checkbox" name="thumb" value="1" {{ thumb_mode }} {{ thumb_checked }}/>
								{{ lang['do_preview'] }}</label>
							<label class="col-form-label d-block"><input id="flagStamp" type="checkbox" name="stamp" value="1" {{ stamp_mode }} {{ stamp_checked }}/>
								{{ lang['do_wmimage'] }}</label>
						</div>
					</div>
					<div class="table-responsive">
						<table id="imageup" class="table table-sm">
							<tbody>
								<tr id="row">
									<td width="10">1:</td>
									<td><input id="fileUploadInput" type="file" name="userfile[0]"/></td>
								</tr>
							</tbody>
						</table>
					</div>
					<div id="showRemoveAddButtoms" class="form-group text-right">
						<div class="btn-group btn-group-sm" role="group">
							<button type="button" onclick="AddImages();return false;" class="btn btn-outline-success">{{ lang['onemore'] }}</button>
							<button type="button" onclick="RemoveImages();return false;" class="btn btn-outline-danger">{{ lang['delone'] }}</button>
						</div>
					</div>
				</div>
						<div class="modal-footer text-right">
							<button type="submit" class="btn btn-outline-success">{{ lang['upload'] }}</button>
						</div>
					</form>
				</div>
				<div class="tab-pane fade" id="urlTab" role="tabpanel">
					<form action="{{ php_self }}?mod=images" method="post" name="snup">
				<input type="hidden" name="subaction" value="uploadurl"/>
				<input type="hidden" name="area" value="{{ area }}"/>
				<div class="modal-body">
					<div class="form-group row">
						<label class="col-sm-4 col-form-label">{{ lang['category'] }}</label>
						<div class="col-sm-8">{{ dirlistS|raw }}</div>
					</div>
					<div class="form-group row">
						<div class="col-sm-8 offset-sm-4">
							<label class="col-form-label d-block"><input id="replace2" type="checkbox" name="replace" value="1"/>
								{{ lang['do_replace'] }}</label>
							<label class="col-form-label d-block"><input id="rand2" type="checkbox" name="rand" value="1"/>
								{{ lang['do_rand'] }}</label>
							<label class="col-form-label d-block"><input id="thumb2" type="checkbox" name="thumb" value="1" {{ thumb_mode }} {{ thumb_checked }}/>
								{{ lang['do_preview'] }}</label>
							<label class="col-form-label d-block"><input id="stamp2" type="checkbox" name="stamp" value="1" {{ stamp_mode }} {{ stamp_checked }}/>
								{{ lang['do_wmimage'] }}</label>
						</div>
					</div>
					<div class="table-responsive">
						<table id="imageup2" class="table table-sm">
							<tbody>
								<tr id="row">
									<td width="10">1:</td>
									<td><input type="text" name="userurl[0]" class="form-control"/></td>
								</tr>
							</tbody>
						</table>
					</div>
					<div class="form-group text-right">
						<div class="btn-group btn-group-sm" role="group">
							<button type="button" onclick="AddImages2();return false;" class="btn btn-outline-success">{{ lang['onemore'] }}</button>
							<button type="button" onclick="RemoveImages2();return false;" class="btn btn-outline-danger">{{ lang['delone'] }}</button>
						</div>
					</div>
				</div>
					<div class="modal-footer text-right">
						<button type="submit" class="btn btn-outline-success">{{ lang['upload'] }}</button>
					</div>
				</form>
			</div>
		</div>
	</div>
</div>
</div>
{% if status %}
	<div id="categoriesModal" class="modal fade" tabindex="-1" role="dialog">
		<div class="modal-dialog">
			<div class="modal-content">
				<div class="modal-header">
					<h5 id="categoriesModalLabel" class="modal-title">{{ lang['categories'] }}</h5>
					<button type="button" class="close" data-dismiss="modal">
						<span>&times;</span>
					</button>
				</div>
				<div class="modal-body">
					<form action="{{ php_self }}?mod=images" method="post" name="newcat">
						<input type="hidden" name="subaction" value="newcat"/>
						<input type="hidden" name="area" value="{{ area }}"/>
						<div class="form-group row">
							<label class="col-sm-4 col-form-label">{{ lang['addnewcat'] }}</label>
							<div class="col-sm-8">
								<div class="input-group mb-3">
									<input type="text" name="newfolder" class="form-control"/>
									<div class="input-group-append">
										<button type="submit" class="btn btn-outline-success">OK</button>
									</div>
								</div>
							</div>
						</div>
					</form>
					<form action="{{ php_self }}?mod=images" method="post" name="delcat">
						<input type="hidden" name="subaction" value="delcat"/>
						<input type="hidden" name="area" value="{{ area }}"/>
						<div class="form-group row">
							<label class="col-sm-4 col-form-label">{{ lang['delcat'] }}</label>
							<div class="col-sm-8">
								<div class="input-group mb-3">
									{{ dirlist|raw }}
									<div class="input-group-append">
										<button type="submit" class="btn btn-outline-danger">OK</button>
									</div>
								</div>
							</div>
						</div>
					</form>
				</div>
			</div>
		</div>
	</div>
{% endif %}
<script type="text/javascript">
	function AddImages() {
var tbl = document.getElementById('imageup');
var lastRow = tbl.rows.length;
var iteration = lastRow + 1;
var row = tbl.insertRow(lastRow);
var cellRight = row.insertCell(0);
cellRight.innerHTML = '<span>' + iteration + ': </span>';
cellRight = row.insertCell(1);
var el = document.createElement('input');
el.setAttribute('type', 'file');
el.setAttribute('name', 'userfile[' + iteration + ']');
el.setAttribute('size', '60');
el.setAttribute('value', iteration);
cellRight.appendChild(el);
}
function RemoveImages() {
var tbl = document.getElementById('imageup');
var lastRow = tbl.rows.length;
if (lastRow > 1) {
tbl.deleteRow(lastRow - 1);
}
}
function AddImages2() {
var tbl = document.getElementById('imageup2');
var lastRow = tbl.rows.length;
var iteration = lastRow + 1;
var row = tbl.insertRow(lastRow);
var cellRight = row.insertCell(0);
cellRight.innerHTML = '<span>' + iteration + ': </span>';
cellRight = row.insertCell(1);
var el = document.createElement('input');
el.setAttribute('type', 'text');
el.setAttribute('name', 'userurl[' + iteration + ']');
el.setAttribute('size', '60');
el.setAttribute('class', 'form-control');
cellRight.appendChild(el);
}
function RemoveImages2() {
var tbl = document.getElementById('imageup2');
var lastRow = tbl.rows.length;
if (lastRow > 1) {
tbl.deleteRow(lastRow - 1);
}
}
</script>
<script type="text/javascript">
		$(document).ready(function () {
// Показ/скрытие селекта категории при выборе действия "Переместить"
$('#delform').on('change input', function () {
	var form = this;
	if (form && form.elements && form.elements.subaction) {
		var show = (form.elements.subaction.value === 'move');
		if (form.elements.category) {
			$(form.elements.category).toggle(show);
		}
	}
}).trigger('change');
$('#uploadnew_form').on('submit', function (e) {
e.preventDefault();
$('#uploadImagesModal').on('hidden.bs.modal', function () {
document.location = document.location;
});
$('#fileUploadInput').uploadifive('upload');
});
var fileCounter = 1;
var uploader = $('#fileUploadInput').uploadifive({
auto: false,
uploadScript:'{{ admin_url }}/rpc.php?methodName=admin.files.upload',
cancelImg:'{{ skins_url }}/images/up_cancel.png',
folder: '',
fileExt:'{{ listExt }}',
fileDesc:'{{ descExt }}',
sizeLimit:'{{ maxSize }}',
multi: true,
buttonText: 'Выбрать изображение ...',
width: 200,
onInit: function () {
$('#showRemoveAddButtoms').hide();
$('#flagThumb').prop('checked', true).prop('disabled', true).parent().hide();
},
onUpload: function (filesToUpload) {
var formData = {
ngAuthCookie:'{{ authcookie }}',
uploadType: 'image',
category: $('#categorySelect').val(),
rand: $('#flagRand').is(':checked') ? 1 : 0,
replace: $('#flagReplace').is(':checked') ? 1 : 0,
thumb: 1,
stamp: $('#flagStamp').is(':checked') ? 1 : 0,
forceRename: 1
};
$.each(this.fileQueue, function (index, file) {
if (file.newName) {
formData['newFilename_' + index] = file.newName;
}
});
uploader.data('uploadifive').settings.formData = formData;
},
onAdd: function (file) {
try {
var originalName = file.name;
var extension = originalName.split('.').pop().toLowerCase().substring(0, 4);
var newName = (fileCounter++).toString().padStart(3, '0') + '.' + extension;
if (newName.length > 22) {
newName = newName.substring(0, 22);
}
file.newName = newName;
file.name = newName;
return true;
} catch (e) {
console.error('Error renaming file:', e);
return true;
}
},
onUploadComplete: function (fileObj, data) {
try {
var response = JSON.parse(data);
fileObj.queueItem.find('.fileinfo').replaceWith(response.status ? '<div class="text-info">' + response.errorText + '</div>' : '<div class="text-danger">(' + response.errorCode + ') ' + response.errorText + ' ' + response.errorDescription + '</div>');
} catch (e) {
console.error('Error processing upload response:', e);
}
},
onError: function (errorType, file) {
console.error('Upload error:', errorType, file);
}
});
});
</script>
<!-- END: Init UPLOADIFY engine -->
