Просмотр файла messages.php

Размер файла: 9.59Kb
<?php
/**********************************************/
/* Автор скрипта: Александр Есин              */
/* E-Mail: [email protected] ([email protected]) */
/* ICQ: 6464729                               */
/* Site: http://ticlove.ru                    */
/**********************************************/
?>
<?php define ('SECURED', true); ?>
<?php require (dirname(__FILE__).'/_inc/sql.php'); ?>
<?php require (dirname(__FILE__).'/_inc/config.php'); ?>
<?php require (dirname(__FILE__).'/_inc/function.php'); ?>
<?php
$page = isset($_GET['page']) ? $_GET['page'] : NULL;
if ($page == 'chat') {
$title_page = 'Переписка';
$description_page = 'Переписка';
$keywords_page = 'Переписка';
}
else
{
$title_page = 'Мои сообщения';
$description_page = 'Мои сообщения';
$keywords_page = 'Мои сообщения';
}
?>
<?php
if (!isset($_SESSION['auth_id']))
{
header('Location: /');
exit;
}
?>
<?php include (dirname(__FILE__).'/include/header.php'); ?>
<div id="block_left">
<?php include (dirname(__FILE__).'/include/lider.php'); ?>
</div>
<div id="block_center">
<h3><?php echo $title_page; ?></h3>
<?php
switch($page)
{
case 'chat':
$user_uid = intval($_GET['user_uid']);
$sql = mysql_query("SELECT * FROM `q_users` WHERE `id_user` = '".$user_uid."' LIMIT 1;");
if (mysql_num_rows($sql) == 0) {
?>
<script type="text/javascript">
location="/";
</script>
<?php
}
$user_array = mysql_fetch_array($sql);
?>
<script type="text/javascript">
$(document).ready(function() {
   $.ajax({
      type: "POST",
      url: "/moduls/mess_chat.php?mode=userinfo",
      data: { user_id: <? echo $_SESSION['auth_id']; ?>, user_uid: <? echo $user_uid; ?> },
      beforeSend: function() {
         $('#userinfo').html('<img src="/images/ajax.gif" alt="" />');
	 $("#userChat").html('Пожалуйста подождте. Идёт загрузка сообщений...');
      },
      success: function(data) {
         $("#userinfo").html(data);
      }
   });
});

setInterval(function() {
   $(document).ready(function() {
      $.ajax({
      type: "POST",
      url: "/moduls/mess_chat.php?mode=online",
      data: { user_id: <? echo $_SESSION['auth_id']; ?>, user_uid: <? echo $user_uid; ?> },
      success: function(data) {
         $("#online").html(data);
      }
      });
   });
}, 180 * 1000);


function messLoad() {
   $(document).ready(function() {
      $.ajax({
      type: "POST",
      url: "/moduls/mess_chat.php",
      data: { user_id: <?php echo $_SESSION['auth_id']; ?>, user_uid: <?php echo $user_uid; ?> },
      success: function(data) {
         $("#userChat").html(data);
      },
      error: function() {
         $("#userChat").html('<span style="color: #ff0000;">Произошла неизвестная ошибка.' + '<br/>' + 'Возможно, проблемы с подключением к интернету.</span>');
      }
      });
   });
}
messLoad();
setInterval(function() { messLoad(); }, 20 * 1000);
</script>
<div style="padding: 0 0 5px 0;" id="userinfo"></div>
<div style="margin: 10px; overflow: auto; width: 100%;  height: 370px;">
<div id="userChat"></div>
</div>
<div style="background-color: #eee; padding: 20px 10px;">
<div id="MessChatStatus" style="text-align: center;"></div>
<form action="javascript:void(0)" name="forma">
<div style="padding: 5px 0;">
<script type="text/javascript">
$(document).ready(function() {
	$('#add').click(function() {
		$("#MessChatStatus").fadeIn(0);
		$.ajax({
		type: "POST",
		url: "/moduls/send_message.php?page=send",
		data: { user_id: <? echo $_SESSION['auth_id']; ?>, user_uid: <? echo $user_uid; ?>, msg: $('#msg').val() },
		beforeSend: function() {
		     $("#MessChatStatus").html('<span class="green">Сообщение отправляется, подождите...</span>');
		},
		success: function(data) {
		     $("#MessChatStatus").html(data);
		     document.getElementById('msg').value = '';
		     setTimeout(function() {
		        $("#MessChatStatus").fadeOut(500);
		     }, 1000);
		     $(".msgcolor").css("background-color", "#eeeeee");
		     messLoad();
		}
		});
	});
});	
</script>
<script type="text/javascript">
var ie=document.all?1:0;
var ns=document.getElementById&&!document.all?1:0;

function InsertSmile(SmileId)
{
	      if(ie)
	      {
	           document.all.message.focus();
	           document.all.message.value+=" "+SmileId+" ";
	      }
	      else if(ns)
	      {
	           document.forms['forma'].elements['message'].focus();
	           document.forms['forma'].elements['message'].value+=" "+SmileId+" ";
	      }
	      else alert("Ваш браузер не поддерживается!");
}
</script>
<script type="text/javascript">
function smiles() {
$(document).ready(function() {
     $.arcticmodal({
     type: 'ajax',
     url: '/moduls/smiles.php',
     ajax: {
          type: 'POST',
          data: { user_id: <?php echo $_SESSION['auth_id']; ?> },
          dataType: 'html',
          success: function(data, el, responce) {
               var h = $(responce);
               $('B', h).html(responce.title);
               $('P:last', h).html(responce.text);
               data.body.html(h);
          }
     }
});
});
};
</script>
<script type="text/javascript">
jQuery.fn.maxlength = function(options) {
		   var settings = jQuery.extend({
		   maxChars: 1000, // максимальное колличество символов
		   leftChars: "символов" // текст в конце строки информера
		   }, options);
		   return this.each(function() {
		   var me = $(this);
		   var l = settings.maxChars;
		   me.bind('keydown keypress keyup',function(e) {
		   if(me.val().length>settings.maxChars) me.val(me.val().substr(0,settings.maxChars));
		   l = settings.maxChars - me.val().length;
		   me.next('span').html(l + ' ' + settings.leftChars);
		   });
		   me.after('Осталось <span class="maxlen">' + settings.maxChars + ' ' + settings.leftChars + '</span>');
		   });
};
</script>
<script type="text/javascript">
$(document).ready(function(){
$("#msg").maxlength();
});
</script>
<textarea style="width:95%; max-width:95%; min-width:95%; padding: 5px;" name="message" id="msg" rows="4" cols="20"></textarea>
</div>
<input type="submit" class="submit" id="add" value="Отправить сообщение" /> <input type="submit" class="submit" onclick="javascript:smiles()" value="Смайлики" />
</form>
</div>
<?php
break;


default:
$col = 5;
if (isset($_GET['start'])) $start = abs(intval($_GET['start']));
else $start = 0;
$count_p = mysql_result(mysql_query("SELECT COUNT(DISTINCT(`user_id`)) FROM `q_messages` WHERE `user_uid` = '".$_SESSION['auth_id']."' AND `n` = '0';"), 0);
if ($count_p > 0)
{
if ($start >= $count_p) $start = 0;
$q = mysql_query("SELECT `q_messages`.*, `q_users`.* FROM `q_messages`, `q_users` WHERE `q_messages`.`user_id` = `q_users`.`id_user` AND `q_messages`.`user_uid` = '".$_SESSION['auth_id']."' AND `q_messages`.`n` = '0' GROUP BY `q_messages`.`user_id` ORDER BY MAX(`q_messages`.`id`) DESC LIMIT ".$start.", ".$col);

$i = 1;
while ($array = mysql_fetch_array($q)) { ?>
<table width="100%" cellspacing="5" cellpadding="0">
<tr>
<td width="60" valign="top">
<a href="user.php?id=<?php echo $array['id_user']; ?>">
<?php if (!empty($array['avatar'])) { ?>
<img class="<?php echo ($array['vip_status'] == 1 ? 'photo_bor_vip' : 'photo_bor'); ?>" src="<?php echo DIR_PHOTOS; ?>/<?php echo $array['id_user']; ?>/<?php echo $array['avatar']; ?>" alt="" />
<?php } else { ?>
<img class="<?php echo ($array['vip_status'] == 1 ? 'photo_bor_vip' : 'photo_bor'); ?>" src="/images/no_photo_small.png" alt="" />
<?php } ?>
</a>
</td>
<td valign="top">
<?php if ($array['vip_status'] == 1) { ?><img src="/images/vip.gif" alt="" width="16" height="16" title="VIP-пользователь" /> <?php } ?>
<a class="<?php echo ($array['pol'] == 1 ? 'm_color' : 'zh_color'); ?>" href="/user.php?id=<?php echo $array['id_user']; ?>"><?php echo htmlspecialchars($array['name'], ENT_QUOTES); ?></a>, <span class="vozrast"><?php echo function_vozrast_n($array['god'].'-'.$array['mes'].'-'.$array['day']); ?></span>
<?php if (function_online($array['online']) == TRUE) { ?> <img src="/images/on.gif" alt="Онлайн" title="Онлайн" /><?php } ?>
<?php $new_mess = mysql_result(mysql_query("SELECT COUNT(*) FROM `q_messages` WHERE `user_id` = '".$array['id_user']."' AND `user_uid` = '".$_SESSION['auth_id']."' AND `new` = '0' AND `n` = '0';"), 0); ?>
<?php if ($new_mess > 0) echo ' <span style="color: #ff0000;">+ '.$new_mess.' new!</span>'; ?>
<br/>
<span class="city"><?php echo htmlspecialchars($array['city'], ENT_QUOTES); ?>, <?php echo htmlspecialchars($array['country'], ENT_QUOTES); ?></span><br/>
<?php $msg = mysql_fetch_array(mysql_query("SELECT `msg` FROM `q_messages` WHERE `user_id` = '".$array['id_user']."' AND `user_uid` = '".$_SESSION['auth_id']."' ORDER BY `id` DESC LIMIT 1;")); ?>
<?php echo function_smile(htmlspecialchars(function_bigword($msg['msg'], 45), ENT_QUOTES)); ?><br/>
<a href="/messages.php?page=chat&amp;user_uid=<?php echo $array['id_user']; ?>">Смотреть</a>
</td>
</tr>
</table>
<?php
$i++;
}
function_page($_SERVER['PHP_SELF'].'?', $col, $start, $count_p);
} else echo 'У вас пока нет сообщений';
?>
<?php
break;
}
?>
</div>
<div id="block_right">
<?php include (dirname(__FILE__).'/include/chat.php'); ?>
</div>
<div class="clear"></div>
<?php include (dirname(__FILE__).'/include/footer.php'); ?>