Контакты не критичны. Потом можно дописать.

This commit is contained in:
Igor Barkov (iwork) 2020-09-28 16:27:20 +03:00
parent 3ca33f38aa
commit 6133f50670
2 changed files with 0 additions and 159 deletions

View File

@ -1,158 +0,0 @@
<?php
ob_start("ob_gzhandler");
session_start();
if (empty($_SESSION['uid'])) {
header("Location: index.php");
}
require_once 'config.php';
$friendadd = $_POST['friendadd'] ?? null;
$friendremove = $_POST['friendremove'] ?? null;
$friendedit = $_POST['friendedit'] ?? null;
$comment = $_POST['comment'] ?? '';
if ($friendadd) {
$q = db::c()->query('SELECT `id` FROM `users` WHERE `login` = "?s"', $friendadd)->fetch_assoc();
$q2 = db::c()->query('SELECT 1 FROM `friends` WHERE `user` = ?i AND `friend` = ?i', $_SESSION['uid'], $q['id']);
if (!$q['id']) {
$status = 'Персонаж не найден.';
} elseif ($q['id'] == $_SESSION['uid']) {
$status = 'Себя добавить нельзя.';
} elseif ($q2->getNumRows()) {
$status = 'Персонаж уже есть в списке.';
} else {
db::c()->query('INSERT INTO `friends` (`user`, `friend`, `comment`) VALUES (?i,?i,"?s")', $_SESSION['uid'], $q['id'], $comment);
$status = 'Контакт добавлен.';
}
}
if ($friendremove) {
$q = db::c()->query('SELECT `id` FROM `users` WHERE `login` = "?s"', $friendremove)->fetch_assoc();
$q2 = db::c()->query('SELECT 1 FROM `friends` WHERE `user` = ?i AND `friend` = ?i', $_SESSION['uid'], $q['id']);
if (!$q['id'] || !$q2->getNumRows()) {
$status = 'Персонаж не найден.';
} else {
db::c()->query('DELETE FROM `friends` WHERE `user` = ?i AND `friend` = ?i', $_SESSION['uid'], $q['id']);
$status = 'Контакт удалён.';
}
}
if ($friendedit) {
$q = db::c()->query('SELECT `id` FROM `users` WHERE `login` = "?s"', $friendedit)->fetch_assoc();
$q2 = db::c()->query('SELECT 1 FROM `friends` WHERE `user` = ?i AND `friend` = ?i', $_SESSION['uid'], $q['id']);
if (!$q2['friend']) {
$status = 'Персонаж не найден.';
} else {
db::c()->query('UPDATE `friends` SET `comment` = "?s" WHERE `user` = ?i AND `friend` = ?i', $comment, $_SESSION['uid'], $q['id']);
$status = 'Контакт изменён.';
}
}
$admins_list = db::c()->query('SELECT `id` FROM `users` WHERE `admin` = 1 ORDER BY `login`', (time() - 60));
$contacts_list = db::c()->query('SELECT `friend`,`comment` FROM `friends` WHERE `friend` > 0 AND `user` = ?i', $_SESSION['uid']);
?>
<!doctype html>
<HTML>
<HEAD>
<meta charset="utf-8">
<link rel=stylesheet href="css/main.css">
</HEAD>
<body>
<div style="text-align: right">
<input type='button' value='Добавить контакт' onclick='addcontact()'>
<input type='button' value='Удалить контакт' onclick='removecontact()'>
<input type='button' value='Обновить' style='width: 75px'
onclick='location="/contacts.php?friends=<?= mt_rand() ?>"'>
<input TYPE='button' value='Вернуться' style='width: 75px' onclick='location="main.php"'>
</div>
<div id=hint4 class=ahint>
<?php if (isset($status)): ?>
<span style="color: darkred;"><?= $status ?></span>
<?php endif; ?>
</div>
<TABLE width="100%">
<TR>
<TD style="vertical-align: top; background: silver;">
<TABLE cellspacing=1 width="100%">
<tr>
<td colspan="3"><h3>Контакты</h3></td>
</tr>
<?php
while ($row = $contacts_list->fetch_assoc()):
$us = db::c()->query('SELECT `id`,`login`,`room`, `invis`, (select `id` from `online` WHERE `date` >= ?i AND `id` = `users`.`id`) as `online` FROM `users` WHERE `id` = ?i', (time() - 60), $row['friend'])->fetch_assoc();
?>
<TR valign="top">
<TD>
<?php
if ($us['online'] > 0 && !$us["invis"]) echo Nick::id($us['id'])->full() . " - <i>" . $us['room'] . "</i><br>";
else echo "<span style='color: grey'>" . Nick::id($us['id'])->full() . "</span><br>";
?>
</TD>
<TD style="background: darkgrey; width: 65%; padding: 0.2em 1em; border-radius: 2px;">
<small><?= $row['comment'] ?></small>
</TD>
<TD width="1%">
<input type='button' style="background: darkgrey; border: 1px solid grey; border-radius: 2px;" value="Редактировать" onclick='use("comment","wow")'>
<!-- editcontact("<?= $us['login'] ?>", "<?= $row['comment'] ?>") -->
</TD>
</TR>
<? endwhile; ?>
</TABLE>
</TD>
<TD style="width: 200px; vertical-align: top; background: whitesmoke;">
<h3>Администраторы</h3>
<?php while ($row = $admins_list->fetch_assoc()) echo Nick::id($row['id'])->full() . "<br>"; ?>
</TD>
</TR>
</TABLE>
<script>
function editcontact(login, comment) {
let s = '<table width=250 bgcolor=CCC3AA><tr><td align=center><b>Редактировать контакт</b></td><td width=20 align=right valign=top style="cursor: hand" onclick="closehint();"><b>x</td></tr><tr><td colspan=2>';
s += '<table width=100% align=center bgcolor=FFF6DD><form action="contacts.php" method=POST>';
s += '<tr><td><input type="hidden" name="friendedit" value="' + login + '">';
s += '<input name="comment" value="' + comment + '" placeholder="Комментарий" style="width: 105px"> ';
s += '<input type="submit" value="Сохранить"></td></tr></form></table>';
s += '</td></tr></table>';
document.getElementById("hint4").innerHTML = s;
document.getElementById("hint4").style.visibility = "visible";
document.getElementById("hint4").style.left = 100;
document.getElementById("hint4").style.top = document.body.scrollTop + 50;
document.getElementById("comment").focus();
Hint3Name = '';
}
function addcontact() {
let s = '<table width=250 bgcolor=CCC3AA><tr><td align=center><B>Добавить контакт</td><td width=20 align=right valign=top style="cursor: hand" onclick="closehint();"><b>x</td></tr><tr><td colspan=2>';
s += '<table width=100% bgcolor=FFF6DD align=center><form action="contacts.php" method=POST>';
s += '<tr><td><input name="friendadd" placeholder="Логин" style="width:105px"> ';
s += '<input name="comment" placeholder="Комментарий" style="width:105px"></td></tr>';
s += '<tr><td><input type="submit" value="Добавить запись"></td></tr></form></table>';
s += '</td></tr></table>';
document.getElementById("hint4").innerHTML = s;
document.getElementById("hint4").style.visibility = "visible";
document.getElementById("hint4").style.left = 100;
document.getElementById("hint4").style.top = document.body.scrollTop + 50;
document.getElementById(name).focus();
Hint3Name = name;
}
function removecontact() {
let s = '<table width=250 bgcolor=CCC3AA><tr><td align=center><b>Удалить контакт</b></td><td width=20 align=right valign=top style="cursor: hand" onclick="closehint();"><b>x</td></tr><tr><td colspan=2>';
s += '<table width=100% align=center bgcolor=FFF6DD><form action="contacts.php" method=POST>';
s += '<tr><td><input name="friendremove" placeholder="Логин" style="width: 105px"> ';
s += '<input type="submit" value="Удалить"></td></tr></form></table>';
s += '</td></tr></table>';
document.getElementById("hint4").innerHTML = s;
document.getElementById("hint4").style.visibility = "visible";
document.getElementById("hint4").style.left = 100;
document.getElementById("hint4").style.top = document.body.scrollTop + 50;
document.getElementById(name).focus();
Hint3Name = name;
}
function closehint() {
document.getElementById("hint4").style.visibility = "hidden";
Hint3Name = '';
}
function use(option, placeholder) {
document.getElementById(option).innerHTML = "<form method='post'><input placeholder='" + placeholder + "' name='" + option + "'><input value='Ок' type='submit'></form>";
}
</script>
</body>
</HTML>

View File

@ -14,7 +14,6 @@
<div class="button-container"> <div class="button-container">
<div class="button-group"> <div class="button-group">
<a class="button" href="/user_anketa.php" title="Анкета" target="gameframe">Анкета</a> <a class="button" href="/user_anketa.php" title="Анкета" target="gameframe">Анкета</a>
<a class="button" href="/contacts.php" title="Контакты" target="gameframe">Друзья</a>
<a class="button" href="/main.php?edit=1" title="Инвентарь" target="gameframe">Инвентарь</a> <a class="button" href="/main.php?edit=1" title="Инвентарь" target="gameframe">Инвентарь</a>
<a class="button" href="/clan.php" title="Клан" target="gameframe">Клан</a> <a class="button" href="/clan.php" title="Клан" target="gameframe">Клан</a>
<a class="button" href="/user_abilities.php" title="Особые умения" target="gameframe">Особые умения</a> <a class="button" href="/user_abilities.php" title="Особые умения" target="gameframe">Особые умения</a>