Файл mchat.php:
Свернутый текст
<H2>Мини-чат</H2>
<div id="chat">
<?php
$sql = "
SELECT
c.`id`, c.`message`, c.`user`, c.user_id,
DATE_FORMAT(c.`time`, '%H:%i') AS time,
u.avatar, u.login, u.name, u.group, u.email, u.regdate
FROM
`chat` AS c
LEFT JOIN
`users` AS u ON u.id = c.user_id
ORDER BY `id` DESC
";
$Result = mysqli_query($CONNECT, $sql) or die( mysqli_error($CONNECT) );
while ($Row = mysqli_fetch_assoc($Result)) {
$Avatar = (empty($Row['avatar'])) ? 0 : $Row['avatar'].'/'.$Row['user_id'];
if ($_SESSION['USER_GROUP'] == 2) $EDIT = '<!-- Меню ред.материала --><ul id="edit"><li id="su"><a href><div style="padding:5px 5px 10px 10px;background-size:15px;"></div></a><ul style="height:17px"><li style="right:64px"><a href="/chat/control/com_delete/'.$Row['id'].'"><span id="edit-del" style="margin-top:-5px"></span></a><a href="/chat/control/action/edit/id/'.$Row['id'].'"><span id="edit-red" style="margin-top:-5px"></span></a></li></ul></li></ul& gt;';
// Настройка редактирования комментариев.
if ($Row['id'] == $_SESSION['COMMENTS_EDIT'])
$Row['message'] = '<form method="POST" action="/chat/control">
<textarea name="text" placeholder="Текст сообщения" maxlength="350" style="width:154px;margin:2px" id="textarea" required>'.$Row['message'].'</textarea>
<br/><center><input type="submit" name="save" value="Сохранить" /> <input type="submit" name="cancel" value="Отменить" /></center></form>';
$Prof = '<div id="spoiler" tabindex="1"><img src="/images/img/profile.png" style="vertical-align: -3px" /><a style="font-size:7pt"> Профиль</a>
<div class="spoiler">
<div><b>Группа:</b> ('.UserGroup($Row['group']).')
<br/><b>Имя:</b> '.$Row['name'].'
<br/><b>E-mail:</b> '.HideEmail($Row['email']).'
<br/><b>Дата регистрации:</b> '.$Row['regdate'].'</div>
<a href="" style="position:relative;top:-83px;left:293px" id="close"></a>
</div></div>';
if ($_SESSION['USER_ID'] == $Row['user_id'] OR $_SESSION['group'] == 2) $Prof = '<a href="/profile" style="font-size:7pt"><img src="/images/img/profile.png" style="vertical-align: -3px" /> Профиль</a><br/>';
$Name = (empty($Row['name'])) ? '<h8>Аноним</h8><br/><br/>' : $Prof.'<a href="javascript:void(`Apply to`)" onclick="parent.window.document.getElementById(`textarea`).focus();parent.window.document.getEle mentById(`textarea`).value+=`'.$Row['name'].', `;return false;"><h8>'.$Row['name'].'</h8></a>';
echo '
<div id="mess">
<img src="/resource/avatar/'.$Avatar.'.jpg" width="29" height="30" alt="Аватар" align="left" id="avatar" />
<span>'.$Row['time'].$EDIT.'</span>'.$Name.''.$Admin.'<p>'.$Row['message'].'</p></div>';
}
echo '</div><div id="form_mess"><form method="POST" action="/chat/add" name="forma"><textarea name="text" id="comment" maxlength="350" required></textarea>
<br>
<a href="javascript:%20x()" onclick="DoSmilie(` :-) `);"><img src="/images/img/smail/big_grin.png" alt="Радуется"></a>
<a href="javascript:%20x()" onclick="DoSmilie(` :-| `);"><img src="/images/img/smail/dumbfounded.png" alt="Грустный"></a>
<a href="javascript:%20x()" onclick="DoSmilie(` 8-P `);"><img src="/images/img/smail/crazy.png" alt="Класно"></a>
<a href="javascript:%20x()" onclick="DoSmilie(` :-( `);"><img src="/images/img/smail/evil.png" alt="Недоволен"></a>
<br><br>
<br/><input type="submit" name="enter" id="chbutton" value="GO">
<input type="hidden" name="user_id" value="'.$_SESSION['USER_ID'].'">
</form>
<a href="" rel="nofollow" onclick="document.location.reload()" title="Обновить"><img alt="" style="vertical-align:middle;width: 17px;height: 17px;border:0;" src="/resource/chat/Replay.png" /></a>
<a href="SMILES_URI" title="Смайлики"><img alt="" style="vertical-align:middle;width: 17px;height: 17px;border:0;" src="/resource/chat/Friendster.png" /></a>
<a href="BBCODES_URI" title="ББ-коды"><img alt="" style="vertical-align:middle;width: 17px;height: 17px;border:0;" src="/resource/chat/Blogger.png" /></a>
<a href="MSGCTRL_URI" title="Модерация"><img alt="" style="vertical-align:middle;width: 17px;height: 17px;border:0;" src="/resource/chat/Tools.png" /></a>
</div>';
?>
<script type="text/javascript" src="/images/img/smail/smail.js"></script>
<style>
#chat {overflow-x: hidden !important;overflow-x:hidden;height:300px;overflow-x:scroll;overflow-y:scroll}
#mess {margin:5px 0 0 18px;max-width:160px;background:#050D05;border:1px dotted #142106}
#mess p {padding:5px;background:#050A05}
#mess span {margin-right:3px;font-size:7pt;font-weight:bold;color:#666;text-shadow:1px 1px 2px #487550;float:right}
#form_mess {margin:30px;padding:3px;width:132px;border:1px dotted #444}
#textarea {width:130px;height:40px;color:#999;background:#050A05;resize:none;border:1px solid #29352c}
#chbutton {background-image:url(/resource/chat/Button1.png);float:right;margin-top:-2px;width:40px;height:20px;border-radius:15px;border:2px solid grey;outline:0;cursor:pointer}
#chbutton:hover {-webkit-filter: brightness(140%);box-shadow: 0 0 10px #6e0d20}
html, body {scrollbar-3dlight-color:070D08;
scrollbar-arrow-color:070D08;
scrollbar-highlight-color:070D08;
scrollbar-face-color:070D08;
scrollbar-shadow-color:070D08;
scrollbar-darkshadow-color:070D08;
scrollbar-track-color: 070D08;}
body {
overflow-x: hidden !important;
}
body {overflow-x:hidden;}
#body{}
::-webkit-scrollbar {width: 0px;height: 5px; }
/*Кнопка Мини-чата */
.button {background-image: url(/images/mini-chat/Button1.png); color: black; width: 40px; margin-top: -1px; height: 20px; border-radius: 15px; border: 2px solid grey; outline: 0; cursor: pointer}
.button:hover {filter: progid: DXImageTransform.Microsoft.Alpha(opacity=85); -moz-opacity: 0.7; opacity: 0.7; filter: alpha(opacity=85);}
/*--------- Кнопка Мини-чата */
/* Mini-Chat */
#mchatIfm2 {width: 100% !important; height: 300px !important}
.cBlock1 {margin: 0 0 4px 0; }
.cBlock2 {margin: 0 0 4px 0;}
.cBlock1 .f-block {background: url('/images/mini-chat/trans-high.png')}
.cBlock2 .f-block {background: url('/images/mini-chat/trans-light.png')}
.a-block {height: 21px; width: 24px; float: left; margin: 0 6px 0 0}
/* Аватар */
.a-block img {width: 20px; height: 28px; padding:3px}
/* ---------- Аватар */
.u-block {padding: 3px}
/* Nick-name */
.u-block a {font-size: 8pt; font-weight: bold; color: #788e68; text-shadow: 1px 1px 2px #0b751e; text-decoration: none}
/* ----------- Nick-name */
/* Clock */
.d-block {margin-right: 3px; font-size: 7pt; font-weight: bold; color: #666666; text-shadow: 1px 1px 2px #487550; float: right}
/* ------------ Clock */
/*Прокручиваемый блок чата*/
.cMessage {font-size: 10pt; color: #999; text-align: left; max-width:120px;}
.cMessage a.link {text-decoration:none !important;}
.cBlock1 .f-block, .cBlock2 .f-block, .cMessage {margin-left: 11px; width:132px; min-height: 58px; -height: 58px; height:auto !important; height: 58px}
/*----------------Прокручиваемый блок чата */
/*Рамка добавления материала*/
#form_block {width: 130px; margin: 9px 0px 0px 12px; border: 1px dotted #444}
#mess_block {margin: 2px}
/* --------------- Рамка добавления материала*/
/* Окно добавления материала */
.mess {margin: 2px; width: 117px; color: #999; background: url(/images/mini-chat/trans-med.png) repeat; resize:none; border: 1px solid #29352c}
/*--------------- Окно добавления материала */
#funct_block {width: auto; margin: 3px 4px 5px}
#ent_block {display: block; float: right}
</style>
Файл Add.php:
Свернутый текст
<?php
if ($_POST['enter'] and $_POST['text']) {
if(isset($_POST['text'])) {$Row['message'] = $_POST['text'];}
if(isset($_POST['submit'])) {$submit = $_POST['submit'];}
$smail = array(":-)", ":-|", "8-P", ":-(");
$grafic = array("<img src='/images/img/smail/big_grin.png' alt='Радуется' align='middle'>",
"<img src='/images/img/smail/dumbfounded.png' alt='Грустный' align='middle'>",
"<img src='/images/img/smail/crazy.png' alt='Класно' align='middle'>",
"<img src='/images/img/smail/evil.png' alt='Недоволен' align='middle'>");
$newtext = str_replace($smail, $grafic, $Row['message']);
echo "$newtext";
$_POST['text'] = $_POST['text'];
$Row = mysqli_fetch_assoc(mysqli_query($CONNECT, 'SELECT `id` FROM `'.$Table.'` WHERE `id` = '.$Param['id']));
$sql = "
INSERT INTO
`chat`
SET
`message` = '".$_POST['text']."',
`user` = '".$_SESSION[USER_LOGIN]."',
`time` = NOW(),
`user_id` = '".(int)$_POST['user_id']."'
";
mysqli_query($CONNECT, $sql) or die( mysqli_error($CONNECT) );
MessageSend(3, 'Комментарий добавлен.', '/');
}
?>
[/spoiler]
Прикручен в index.php:
[spoiler]
//модуль Мини-чат
case 'chat':
switch ($Module){
case 'mchat':
include('module/chat/mchat.php');
break;
case 'add':
include('module/chat/add.php');
break;
case 'control':
include('module/chat/control.php');
break;
}
break;
include('module/chat/mchat.php')
База данных phpmyadmin:
Свернутый текст
id - int
message - text
user - varchar
time - datetime
user_id - int