<?php

if(!defined('DATALIFEENGINE')) {die("Hacking Attempt!"); }

class Chat extends db{

function GetContent($chatconfig, $member_id, $config){
    global $cache, $user_group;

		$moder = false;
		if ($member_id['user_group'] == 1) {
			$flag = true;
			$moder = true;
			$m_group = 1;
		}

		elseif ($member_id['user_group'] == 2) {
			$flag = true;
			$moder = true;
			$m_group = 2;
		}

		if (!$html = $cache->open('minichat')) $flag = true;
		elseif(!$moder) $flag = false;

		if ($flag){
			$html = "";
			require_once SYSTEM_DIR.'/classes/parse.class.php';
			$parse = new ParseFilter();
			$parse->safe_mode = true;

			$result = $this->query("SELECT id, name as gast_name, message, date, ip, user_id, mgroup FROM ".PREFIX."_chat m ORDER BY date DESC LIMIT 0,".$chatconfig['limit']."");

			if (!$moder){$m_group = 4;}

			$PHP_SELF = $config['http_home_url'];
			while ($row = $this->get_row($result)){

  $lang['mchat_mess'] = "Сообщение";
  $row['date'] = strtotime($row['date']);
  $row['name'] = stripslashes($row['gast_name']);

  $go_page = "href=\"".$config['http_home_url']."user/".urlencode($row['name'])."/\"";

  $go_page .= "onClick=\"return dropdownmenu(this, event, Chat_UserMenu('".htmlspecialchars($go_page)."', '".$row['user_id']."', ".$m_group.", '".$row['id']."', '".$row['name']."', '".$lang['mchat_mess']."'), '170px')\"";

  $color = $user_group[$row['mgroup']]['colour'];

  $author = "<a {$go_page} href=\"".$config['http_home_url']."user/".urlencode($row['name'])."/\"><strong style='color:$color'>".$row['name']."</strong></a>";

   $date = mcdate($chatconfig['timestamp'],$row['date']);

   $message = stripslashes($row['message']);

   $html .= "<div class=\"cmessage\"><b>".$author."</b><div style=\"float:right; color: #BBBBBB\">".$date."</div><br><span style=\"color:#2a2a2a\">".$message."</span></div>";
 }

 $this->free();
 if (!$moder) $cache->save('minichat', $html);
		}
		else $html = $cache->open('minichat');
		return $html;
	}
  }
?>
