Файл: html/admin/gift.php
Строк: 157
<?php
require_once ('../system/func.php');
require_once ('../system/header.php');
if (!isset($user) || $user['access'] < 3) {
?><script>showContent("/");</script><?php
exit(0);
}
if (isset($_GET['save']) && isset($_GET['id']) && isset($_GET['img']) && isset($_GET['plata']) && isset($_GET['name'])) {
if ($mc->query("UPDATE `shop_gift` SET "
. "`img` = '" . $_GET['img'] . "' ,"
. "`plata` = '" . $_GET['plata'] . "' ,"
. "`name` = '" . $_GET['name'] . "'"
. " WHERE `id` = '" . $_GET['id'] . "'")) {
message(urlencode("сохранено"));
} else {
message(urlencode("<font style='color:red'>не сохранено</font>"));
}
}
if (isset($_GET['dell']) && isset($_GET['id'])) {
if ($mc->query("DELETE FROM `shop_gift` WHERE `id` = '" . $_GET['id'] . "'")) {
message(urlencode("удалено"));
} else {
message(urlencode("<font style='color:red'>не удалено</font>"));
}
}
if (isset($_GET['add']) && isset($_GET['img']) && isset($_GET['plata']) && isset($_GET['name'])) {
if ($mc->query("INSERT INTO `shop_gift`("
. "`id`,"
. "`img`,"
. "`plata`,"
. "`name`"
. ") VALUES ("
. "NULL,"
. "'" . $_GET['img'] . "',"
. "'" . $_GET['plata'] . "',"
. "'" . $_GET['name'] . "'"
. ")")
) {
message(urlencode("создано"));
} else {
message(urlencode("<font style='color:red'>не создано</font>"));
}
}
$giftArrAll = $mc->query("SELECT * FROM `shop_gift` ORDER BY `plata` ASC")->fetch_all(MYSQLI_ASSOC);
?>
<center>
<h2>
<strong>-Редактор Подарков-</strong>
</h2>
</center>
<table style="width: 98%;margin: auto;">
<tr>
<td style="width:30%"><input type='text' id='img_new' style="width:100%;text-align: center" placeholder="имя картинки" value=""></td>
<td style="width:80px"><input type='number' id='plata_new' style="width:100%;text-align: center" placeholder="платина" value=""></td>
<td style="max-width:100%"><input type='text' id='name_new' style="width:100%;text-align: center" placeholder="название" value=""></td>
</tr>
</table>
<table style="width: 98%;margin: auto;">
<tr>
<td style="max-width:100%"><button onclick="showContent('/admin/gift.php?add&img=' + $('#img_new').val() + '&plata=' + $('#plata_new').val() + '&name=' + $('#name_new').val())" class="button" style="width:100%;text-align: center" >add new</button></td>
</tr>
</table>
<hr class="hr_01"/>
<table style="width: 98%;margin: auto;">
<tr>
<td style="width:30%;text-align: center">Картинка</td>
<td style="width:80px;text-align: center">Стоимость</td>
<td style="max-width:100%;text-align: center">Название</td>
</tr>
</table>
<hr class="hr_01"/>
<?php for ($i = 0; $i < count($giftArrAll); $i++) { ?>
<table style="width: 98%;margin: auto;">
<tr>
<td style="width: 40px">
<img style="width: 40px;height: 40px;" src="../images/gifts/<?= $giftArrAll[$i]['img']; ?>.png">
</td>
<td style="max-width: 100%">
<table style="width: 100%">
<tr>
<td><input type='text' id='id_<?= $i; ?>' value="<?= $giftArrAll[$i]['id']; ?>" hidden></td>
<td style="width:30%"><input type='text' id='img_<?= $i; ?>' style="width:100%;text-align: center" placeholder="имя картинки" value="<?= $giftArrAll[$i]['img']; ?>"></td>
<td style="width:80px"><input type='number' id='plata_<?= $i; ?>' style="width:100%;text-align: center" placeholder="платина" value="<?= $giftArrAll[$i]['plata']; ?>"></td>
<td style="max-width:100%"><input type='text' id='name_<?= $i; ?>' style="width:100%;text-align: center" placeholder="название" value="<?= $giftArrAll[$i]['name']; ?>"></td>
</tr>
</table>
<table style="width: 98%;margin: auto;">
<tr>
<td style="max-width:100%"><button onclick="showContent('/admin/gift.php?save&id=' + $('#id_<?= $i; ?>').val() + '&img=' + $('#img_<?= $i; ?>').val() + '&plata=' + $('#plata_<?= $i; ?>').val() + '&name=' + $('#name_<?= $i; ?>').val())" class="button" style="width:100%;text-align: center" >save</button></td>
<td style="width:80px" ><button onclick="showContent('/admin/gift.php?dell&id=' + $('#id_<?= $i; ?>').val())" class="button" style="width:100%;text-align: center" >delete</button></td>
</tr>
</table>
</td>
</tr>
</table>
<hr class="hr_01"/>
<?php } ?>
<table style="width: 98%;margin: auto;">
<tr>
<td id="images_all" style="width:100%"></td>
</tr>
<tr>
<td><br><br><br><br><br><br><br><br><br></td>
</tr>
</table>
<div >
</div>
<?php
$dir = "../images/gifts";
$files = scandir($dir);
$list = [];
foreach ($files as $file):
$list[] = $file;
endforeach;
?>
<script>
var list = <?= json_encode($list); ?>;
var i = 0;
list.sort(naturalCompare);
MyLib.setTimeid[100] = setTimeout(function () {
load();
}, 1000);
function load() {
if (i < list.length - 1) {
if (list[i] != "." && list[i] != "..") {
$("#images_all").append('<table align="left"><tr><td style="text-align: center;padding: 1px;border-style: solid;border-radius: 2px;border-width: 1px;margin: 1px;">' +
'<img onclick="$('#img_new').val(''+list[i].replace(/.png/g,"")+'');$(document).scrollTop(0)" style="width: 40px;height: 40px;" src="../images/gifts/' + list[i] + '">' +
'<br>' +
list[i] +
'</td></tr></table>'
);
}
i++;
load();
}
}
function naturalCompare(a, b) {
var ax = [], bx = [];
a.replace(/(d+)|(D+)/g, function (_, $1, $2) {
ax.push([$1 || Infinity, $2 || ""]);
});
b.replace(/(d+)|(D+)/g, function (_, $1, $2) {
bx.push([$1 || Infinity, $2 || ""]);
});
while (ax.length && bx.length) {
var an = ax.shift();
var bn = bx.shift();
var nn = (an[0] - bn[0]) || an[1].localeCompare(bn[1]);
if (nn)
return nn;
}
return ax.length - bx.length;
}
</script>
<?php
$footval = 'adminmoney';
include '../system/foot/foot.php';
?>