<?PHP

if(!defined('DATALIFEENGINE'))
{
  die("Hacking attempt!");
}
require_once (ROOT_DIR . '/system/data/chat.config.php');
require_once ROOT_DIR.'/language/'.$config['langs'].'/chat.lng';

include(SYSTEM_DIR.'/classes/parse.class.php');

$parse = new ParseFilter(Array(), Array(), 1, 1);


function reset_url($url) {
  $value = str_replace("http://", "", $url);
  $value = str_replace("www.", "",    $value);
  $value = explode("/", $value);
  $value = reset($value);
  return $value;
 }

function showmcRow($title="", $description="", $field="") {
global $chatconfig;
        echo"<tr>
        <td style=\"padding:4px\" class=\"option\">
        <b>$title</b><br /><span class=small>$description</span>
        <td width=394 align=middle >
        $field
        </tr><tr><td background=\"system/skins/images/mline.gif\" height=1 colspan=2></td></tr>";
        $bg = ""; $i++;
    }

function makemcDropDown($options, $name, $selected) {
        $output = "<select name=\"$name\">\r\n";
        foreach($options as $value=>$description)
        {
          $output .= "<option value=\"$value\"";
          if($selected == $value){ $output .= " selected "; }
          $output .= ">$description</option>\n";
        }
        $output .= "</select>";
        return $output;
    }

function chatmenu () {
global $lang_mc;
echo <<<HTML
<div style="padding-top:5px;padding-bottom:2px;"><table width="100%">
<tr><td width="4"><img src="system/skins/images/tl_lo.gif" width="4" height="4" border="0"></td>
<td background="system/skins/images/tl_oo.gif"><img src="system/skins/images/tl_oo.gif" width="1" height="4" border="0"></td>
<td width="6"><img src="system/skins/images/tl_ro.gif" width="6" height="4" border="0"></td></tr>
<tr><td background="system/skins/images/tl_lb.gif"><img src="system/skins/images/tl_lb.gif" width="4" height="1" border="0"></td>
<td style="padding:5px;" bgcolor="#FFFFFF">
<table width="100%"><tr><td bgcolor="#EFEFEF" height="29" style="padding-left:10px;"><div class="navigation">{$lang_mc['mchatc']}</div></td></tr>
</table><div class="unterline"></div>
<table width="100%"><tr><td style="padding:2px;">
<table style="text-align:center;" width="100%" height="35px">
<tr style="vertical-align:middle;" >
<td class=tableborder><a href="$PHP_SELF?mod=chat">Главная</a></td>
<td class=tableborder><a href="$PHP_SELF?mod=chat&action=configs">Настройки</a></td>
<td class=tableborder><a href="$PHP_SELF?mod=chat&action=trun">Чистка чата</a></td>
<td class=tableborder><a href="$PHP_SELF?mod=chat&action=color">Color Ника</a></td>
</tr></table></td></tr></table></td>
<td background="system/skins/images/tl_rb.gif"><img src="system/skins/images/tl_rb.gif" width="6" height="1" border="0"></td></tr>
<tr><td><img src="system/skins/images/tl_lu.gif" width="4" height="6" border="0"></td>
<td background="system/skins/images/tl_ub.gif"><img src="system/skins/images/tl_ub.gif" width="1" height="6" border="0"></td>
<td><img src="system/skins/images/tl_ru.gif" width="6" height="6" border="0"></td>
</tr></table></div>
HTML;
}

if (isset($url)) {
	$url = rawurldecode($_GET['url']);
	$url = @base64_decode($url);
	$url = str_replace("&amp;" , "&", $url);

	$_SERVER['HTTP_REFERER'] = reset_url($_SERVER['HTTP_REFERER']);
	$_SERVER['HTTP_HOST'] = reset_url($_SERVER['HTTP_HOST']);

	if (($_SERVER['HTTP_HOST'] != $_SERVER['HTTP_REFERER']) OR $url == "") {  @header('Location: /index.php'); die ("Access denied!!!<br /><br />Please visit <a href=\"/index.php\">{$_SERVER['HTTP_HOST']}</a>"); }
	@header('Location: '.$url);
	die ("Link Redirect:<br /><br />Please click <a href=\"{$url}\">here.</a>");
}

if ($action == ""){
echoheader("chat", $lang['opt_mchatc']);
chatmenu ();
if(!intval($chat_per_page)){ $chat_per_page = 30; }

if (!isset($start_from)) $start_from = 0;

if(!$user_group[$member_db[1]]['allow_all_edit'] AND $member_db[1] != 1) $author = $member_db[2];

$sql = "SELECT * FROM " . PREFIX . "_chat ORDER BY date DESC LIMIT $start_from,$chat_per_page";
$db->query($sql);
    if($start_from == "0"){ $start_from = ""; }
    $i = $start_from;
    $entries_showed = 0;
$entries = "";
while($row = $db->get_array()){ $i++;

$itemdate = date($chatconfig['timestampa'],strtotime($row['date']));
$row['message'] = $parse->BB_Parse($parse->process(urldecode(stripcslashes($row['message']))));

$entries .= "<tr><td class=\"list\" style=\"padding:4px;\">$itemdate - ";
$entries .= "<a title='$lang[edit_act]' class=\"list\" href=\"$PHP_SELF?mod=chat&action=messedit&id=$row[0]\">".$row['message']."</a>";
$entries .= "<td class=\"list\"><a class=list href=\"?mod=editusers&action=list&search=yes&search_name=".$row['name']."\">".$row['name']."</a>
             <td align=center><input name=\"selected_mess[]\" value=\"{$row['id']}\" type='checkbox'></tr>
             <tr><td background=\"system/skins/images/mline.gif\" height=1 colspan=6></td></tr>";
$entries_showed ++;
if($i >= $chat_per_page + $start_from){ break; }
}
$query_count = "SELECT COUNT(*) as count from " . PREFIX . "_chat";
$result_count = $db->super_query($query_count);
$all_count = $result_count['count'];

echo <<<JSCRIPT
<script language='JavaScript' type="text/javascript">
<!--
function ckeck_uncheck_all() {
    var frm = document.editnews;
    for (var i=0;i<frm.elements.length;i++) {
        var elmnt = frm.elements[i];
        if (elmnt.type=='checkbox') {
            if(frm.master_box.checked == true){ elmnt.checked=false; }
            else{ elmnt.checked=true; }
        }
    }
    if(frm.master_box.checked == true){ frm.master_box.checked = false; }
    else{ frm.master_box.checked = true; }
}
-->
</script>
JSCRIPT;

echo<<<HTML
<form action="" method="post" name="editnews">
<div style="padding-top:5px;padding-bottom:2px;">
<table width="100%"><tr>
<td width="4"><img src="system/skins/images/tl_lo.gif" width="4" height="4" border="0"></td>
<td background="system/skins/images/tl_oo.gif"><img src="system/skins/images/tl_oo.gif" width="1" height="4" border="0"></td>
<td width="6"><img src="system/skins/images/tl_ro.gif" width="6" height="4" border="0"></td></tr>
<tr><td background="system/skins/images/tl_lb.gif"><img src="system/skins/images/tl_lb.gif" width="4" height="1" border="0"></td>
<td style="padding:5px;" bgcolor="#FFFFFF"><table width="100%"><tr>
<td bgcolor="#EFEFEF" height="29" style="padding-left:10px;"><div class="navigation">{$lang_mc['mc_main']}</div></td>
</tr></table><div class="unterline"></div>
<table width="100%"><tr><td><table width=100%><tr>
    <td>&nbsp;&nbsp;Сообщение
    <td width=70>{$lang['edit_autor']}
    <td width=10 align="center"><input type="checkbox" name="master_box" title="{$lang['edit_selall']}" onclick="javascript:ckeck_uncheck_all()">
</tr><tr><td colspan="6"><div class="hr_line"></div></td></tr>
{$entries}
<tr><td colspan="6"><div class="hr_line"></div></td></tr>
HTML;

$npp_nav ="";

if($start_from > 0)
{
	$previous = $start_from - $chat_per_page;
	$npp_nav .= "<a href=\"$PHP_SELF?mod=chat&amp;start_from=$previous&amp;chat_per_page=$chat_per_page\">&lt;&lt; $lang[edit_prev]</a>";
}
if($all_count > $chat_per_page){
	$npp_nav .= " [ ";
    $enpages_count = @ceil($all_count/$chat_per_page);
    $enpages_start_from = 0;
    $enpages = "";
    for($j=1;$j<=$enpages_count;$j++){
            if($enpages_start_from != $start_from){ $enpages .= "<a class=maintitle href=\"$PHP_SELF?mod=chat&amp;start_from=$enpages_start_from&amp;chat_per_page=$chat_per_page\">$j</a> "; }
		else{ $enpages .= "<span class=navigation> $j </span>"; }
        $enpages_start_from += $chat_per_page;
	}
	$npp_nav .= $enpages;
	$npp_nav .= " ] ";
	}
if($all_count > $i)
{
	$how_next = $all_count - $i;
        if($how_next > $chat_per_page){ $how_next = $chat_per_page; }
        $npp_nav .= "<a href=\"$PHP_SELF?mod=chat&amp;start_from=$i&amp;chat_per_page=$chat_per_page\">$lang[edit_next] $how_next &gt;&gt;</a>";
}
if($entries_showed != 0){
echo<<<HTML
<tr><td>$npp_nav</td><td colspan=5 align="right" valign="top">
<select name=action>
<option value="">{$lang['edit_selact']}</option>
<option value="mess_del">{$lang['edit_seldel']}</option>
</select>
<input type=hidden name=mod value="chat">
<input class="buttons" type="submit" value="{$lang['b_start']}">
</tr>
HTML;
}

echo<<<HTML
</table></td>
</tr></table></td>
<td background="system/skins/images/tl_rb.gif"><img src="system/skins/images/tl_rb.gif" width="6" height="1" border="0"></td></tr><tr>
<td><img src="system/skins/images/tl_lu.gif" width="4" height="6" border="0"></td>
<td background="system/skins/images/tl_ub.gif"><img src="system/skins/images/tl_ub.gif" width="1" height="6" border="0"></td>
<td><img src="system/skins/images/tl_ru.gif" width="6" height="6" border="0"></td></tr>
</table></div></form>
HTML;

echo <<<HTML
<form action="$PHP_SELF?mod=chat" method="post" name="options_bar">
<div style="padding-top:5px;padding-bottom:2px;">
<table width="100%"><tr>
<td width="4"><img src="system/skins/images/tl_lo.gif" width="4" height="4" border="0"></td>
<td background="system/skins/images/tl_oo.gif"><img src="system/skins/images/tl_oo.gif" width="1" height="4" border="0"></td>
<td width="6"><img src="system/skins/images/tl_ro.gif" width="6" height="4" border="0"></td></tr>
<tr><td background="system/skins/images/tl_lb.gif"><img src="system/skins/images/tl_lb.gif" width="4" height="1" border="0"></td>
<td style="padding:5px;" bgcolor="#FFFFFF"><table width="100%">
<tr><td bgcolor="#EFEFEF" height="29" style="padding-left:10px;"><div class="navigation">{$lang_mc['mc_stat']} <b>{$entries_showed}</b> {$lang_mc['mc_stat1']} <b>{$all_count}</b></div></td>
</tr></table><div class="unterline"></div>
<table width="100%"><tr><td width="150" style="padding:5px;">{$lang_mc['mc_mess_page']}</td>
<td ><input class="edit" style="text-align: center" name="chat_per_page" value="{$chat_per_page}" type="text" size="3"></td>
</tr></table></td><td background="system/skins/images/tl_rb.gif"><img src="system/skins/images/tl_rb.gif" width="6" height="1" border="0"></td>
</tr><tr><td><img src="system/skins/images/tl_lu.gif" width="4" height="6" border="0"></td>
<td background="system/skins/images/tl_ub.gif"><img src="system/skins/images/tl_ub.gif" width="1" height="6" border="0"></td>
<td><img src="system/skins/images/tl_ru.gif" width="6" height="6" border="0"></td></tr></table>
</div></form>
HTML;
echofooter();
///--- Настройка скрипта ---///
}elseif ($action == "configs"){
echoheader("chat", $lang_mc['mc_conf']);
chatmenu ();
echo <<<HTML
<form action="" method="post">
<div style="padding-top:5px;padding-bottom:2px;">
<table width="100%"><tr>
<td width="4"><img src="system/skins/images/tl_lo.gif" width="4" height="4" border="0"></td>
<td background="system/skins/images/tl_oo.gif"><img src="system/skins/images/tl_oo.gif" width="1" height="4" border="0"></td>
<td width="6"><img src="system/skins/images/tl_ro.gif" width="6" height="4" border="0"></td>
</tr><tr>
<td background="system/skins/images/tl_lb.gif"><img src="system/skins/images/tl_lb.gif" width="4" height="1" border="0"></td>
<td style="padding:5px;" bgcolor="#FFFFFF">
<table width="100%"><tr>
<td bgcolor="#EFEFEF" height="29" style="padding-left:10px;"><div class="navigation">{$lang_mc['mc_conf']}</div></td>
</tr></table>
<div class="unterline"></div>
<table width="100%">
HTML;

    showmcRow($lang_mc['mc_guest'], $lang_mc['mc_guestc'], makemcDropDown(array("yes"=>$lang['opt_sys_yes'],"no"=>$lang['opt_sys_no']), "save_con[guest]", "{$chatconfig['guest']}"));
    showmcRow($lang_mc['mc_showdate'], $lang_mc['mc_showdatec'], makemcDropDown(array("yes"=>$lang['opt_sys_yes'],"no"=>$lang['opt_sys_no']), "save_con[show_date]", "{$chatconfig['show_date']}"));
    showmcRow($lang_mc['mc_limitb'], $lang_mc['mc_limitbc'], "<input class=edit type=text style=\"text-align: center;\"  name='save_con[limit]' value=\"{$chatconfig['limit']}\" size=10>");
    showmcRow($lang_mc['mc_limit'], $lang_mc['mc_limitc'], "<input class=edit type=text style=\"text-align: center;\"  name='save_con[messlimit]' value=\"{$chatconfig['messlimit']}\" size=10>");
    showmcRow($lang_mc['mc_sc'], $lang_mc['mc_sc'], "<input class=edit type=text style=\"text-align: center;\"  name='save_con[smiles_columns]' value=\"{$chatconfig['smiles_columns']}\" size=10>");
    showmcRow($lang_mc['mc_timestamp'], "<a onClick=\"javascript:Help('date')\" class=main href=\"#\">$lang[opt_sys_and]</a>", "<input class=edit type=text style=\"text-align: center;\"  name='save_con[timestamp]' value='{$chatconfig['timestamp']}' size=40>");
    showmcRow($lang_mc['mc_timestampa'], "<a onClick=\"javascript:Help('date')\" class=main href=\"#\">$lang[opt_sys_and]</a>", "<input class=edit type=text style=\"text-align: center;\"  name='save_con[timestampa]' value='{$chatconfig['timestampa']}' size=40>");
    showmcRow($lang_mc['mc_smail'], $lang_mc['mc_smailb'], "<input class=edit type=text style=\"text-align: center;\"  name='save_con[smilep]' value=\"{$chatconfig['smilep']}\" size=40>");
    showmcRow($lang_mc['mc_refresh'], $lang_mc['mc_refreshc'], "<input class=edit type=text style=\"text-align: center;\"  name='save_con[refresh]' value=\"{$chatconfig['refresh']}\" size=10>");
    showmcRow($lang['opt_sys_aw'], $lang['opt_sys_awd'], "<input class=edit type=text style=\"text-align: center;\"  name='save_con[auto_wrap]' value=\"{$chatconfig['auto_wrap']}\" size=10>");
    showmcRow($lang_mc['mc_colornik'], $lang_mc['mc_colornikc'], makemcDropDown(array("yes"=>$lang['opt_sys_yes'],"no"=>$lang['opt_sys_no']), "save_con[color_nik]", "{$chatconfig['color_nik']}"));
   
echo <<<HTML
<tr><td style="padding-top:10px; padding-bottom:10px;padding-right:10px;">
<input type=hidden name=mod value=chat>
<input type=hidden name=action value=dosaveconfigs>
<input type="submit" class="buttons" value="{$lang['user_save']}"></td>
</tr></table></td>
<td background="system/skins/images/tl_rb.gif"><img src="system/skins/images/tl_rb.gif" width="6" height="1" border="0"></td>
</tr><tr>
<td><img src="system/skins/images/tl_lu.gif" width="4" height="6" border="0"></td>
<td background="system/skins/images/tl_ub.gif"><img src="system/skins/images/tl_ub.gif" width="1" height="6" border="0"></td>
<td><img src="system/skins/images/tl_ru.gif" width="6" height="6" border="0"></td>
</tr></table></div></form>
HTML;
echofooter();
///--- Настройка скрипта end ---///

///--- Чистка чата ---///
}elseif ($action == "trun"){
echoheader("chat", $lang_mc['mc_trunс']);
chatmenu ();
echo <<<HTML
<form action="" method="post">
<div style="padding-top:5px;padding-bottom:2px;">
<table width="100%"><tr>
<td width="4"><img src="system/skins/images/tl_lo.gif" width="4" height="4" border="0"></td>
<td background="system/skins/images/tl_oo.gif"><img src="system/skins/images/tl_oo.gif" width="1" height="4" border="0"></td>
<td width="6"><img src="system/skins/images/tl_ro.gif" width="6" height="4" border="0"></td>
</tr><tr>
<td background="system/skins/images/tl_lb.gif"><img src="system/skins/images/tl_lb.gif" width="4" height="1" border="0"></td>
<td style="padding:5px;" bgcolor="#FFFFFF">
<table width="100%"><tr>
<td bgcolor="#EFEFEF" height="29" style="padding-left:10px;"><div class="navigation">{$lang_mc['mc_trunс']}</div></td>
</tr></table>
<div class="unterline"></div>
<table width="100%">
<tr align="center">
<td style="padding-top:10px; padding-bottom:10px;padding-right:10px;">{$lang_mc['mc_trun']}</td></tr>
<tr align="center">
<td style="padding-top:10px; padding-bottom:10px;padding-right:10px;">
<input class=bbcodes type=submit value="   $lang[mass_yes]   "> &nbsp; <input type=button class=bbcodes value="  $lang[mass_no]  " onclick="javascript:document.location='$PHP_SELF?mod=chat'">
<input type=hidden name=action value=dotrun>
<input type=hidden name=mod value=chat></td>
</tr></table></td>
<td background="system/skins/images/tl_rb.gif"><img src="system/skins/images/tl_rb.gif" width="6" height="1" border="0"></td>
</tr><tr>
<td><img src="system/skins/images/tl_lu.gif" width="4" height="6" border="0"></td>
<td background="system/skins/images/tl_ub.gif"><img src="system/skins/images/tl_ub.gif" width="1" height="6" border="0"></td>
<td><img src="system/skins/images/tl_ru.gif" width="6" height="6" border="0"></td>
</tr></table></div></form>
HTML;
echofooter();
}
///--- Чистка чата end ---///

elseif($action == "mess_del"){
echoheader("chat", $lang_mc['chatc']);
echo <<<HTML
<form action="{$PHP_SELF}" method="post">
<div style="padding-top:5px;padding-bottom:2px;">
<table width="100%"><tr>
<td width="4"><img src="system/skins/images/tl_lo.gif" width="4" height="4" border="0"></td>
<td background="system/skins/images/tl_oo.gif"><img src="system/skins/images/tl_oo.gif" width="1" height="4" border="0"></td>
<td width="6"><img src="system/skins/images/tl_ro.gif" width="6" height="4" border="0"></td>
</tr><tr><td background="system/skins/images/tl_lb.gif"><img src="system/skins/images/tl_lb.gif" width="4" height="1" border="0"></td>
<td style="padding:5px;" bgcolor="#FFFFFF"><table width="100%">
<tr><td bgcolor="#EFEFEF" height="29" style="padding-left:10px;"><div class="navigation">{$lang['mass_head']}</div></td>
</tr></table><div class="unterline"></div>
<table width="100%"><tr><td style="padding:2px;" height="100" align="center">{$lang_mc['mass_confirm']}
HTML;

echo "(<b>".count($selected_mess)."</b>) сообщения<br><br>
<input class=bbcodes type=submit value=\"   $lang[mass_yes]   \"> &nbsp; <input type=button class=bbcodes value=\"  $lang[mass_no]  \" onclick=\"javascript:document.location='$PHP_SELF?mod=chat'\">
<input type=hidden name=action value=\"do_mess_del\">
<input type=hidden name=mod value=\"chat\">";
foreach($selected_mess as $id){
echo "<input type=hidden name=selected_mess[] value=\"$id\">\n";
}

echo <<<HTML
</tr></table></td>
<td background="system/skins/images/tl_rb.gif"><img src="system/skins/images/tl_rb.gif" width="6" height="1" border="0"></td></tr>
<tr><td><img src="system/skins/images/tl_lu.gif" width="4" height="6" border="0"></td>
<td background="system/skins/images/tl_ub.gif"><img src="system/skins/images/tl_ub.gif" width="1" height="6" border="0"></td>
<td><img src="system/skins/images/tl_ru.gif" width="6" height="6" border="0"></td>
</tr></table></div></form>
HTML;
echofooter();
exit;
///--- Add Message end ---///
}elseif($action == "messedit"){
echoheader("chat", $lang_mc['chatc']);
chatmenu ();
$row = $db->super_query("SELECT * FROM " . PREFIX . "_chat WHERE id = '$id'");
$messtext = $parse->decodeBBCodes($row['message']);
echo <<<HTML
<form action="" method="post">
<div style="padding-top:5px;padding-bottom:2px;"><table width="100%"><tr>
<td width="4"><img src="system/skins/images/tl_lo.gif" width="4" height="4" border="0"></td>
<td background="system/skins/images/tl_oo.gif"><img src="system/skins/images/tl_oo.gif" width="1" height="4" border="0"></td>
<td width="6"><img src="system/skins/images/tl_ro.gif" width="6" height="4" border="0"></td></tr>
<tr><td background="system/skins/images/tl_lb.gif"><img src="system/skins/images/tl_lb.gif" width="4" height="1" border="0"></td>
<td style="padding:5px;" bgcolor="#FFFFFF"><table width="100%"><tr>
<td bgcolor="#EFEFEF" height="29" style="padding-left:10px;"><div class="navigation">{$lang_mc['mc_addmssa']}</div></td>
</tr></table><div class="unterline"></div><table width="100%">
HTML;

include(SYSTEM_DIR.'/inc/include/inserttag.php');

echo <<<HTML
<tr><td style="padding-left:2px;">{$bb_code}<textarea style="width:98%; height:100px;" name="aeditmess" id="aeditmess" onclick=setFieldName(this.name)>{$messtext}</textarea><script type=text/javascript>var selField  = "template";</script></td></tr>
HTML;

echo <<<HTML
<tr><td colspan="2"><div class="hr_line"></div></td></tr><tr><td>
<input type="submit" value="{$lang['user_save']}" class="buttons">
<input type=hidden name=action value=do_mess_edit>
<input type=hidden name=mod value=chat>
<br><br></td></tr></table>
</td><td background="system/skins/images/tl_rb.gif"><img src="system/skins/images/tl_rb.gif" width="6" height="1" border="0"></td></tr><tr>
<td><img src="system/skins/images/tl_lu.gif" width="4" height="6" border="0"></td>
<td background="system/skins/images/tl_ub.gif"><img src="system/skins/images/tl_ub.gif" width="1" height="6" border="0"></td>
<td><img src="system/skins/images/tl_ru.gif" width="6" height="6" border="0"></td>
</tr></table></div></form>
HTML;
echofooter();
}elseif($action == "color"){
echoheader("chat", $lang_mc['chatc']);
chatmenu ();
echo <<<HTML
<form action="" method="post">
<div style="padding-top:5px;padding-bottom:2px;">
<table width="100%"><tr>
<td width="4"><img src="system/skins/images/tl_lo.gif" width="4" height="4" border="0"></td>
<td background="system/skins/images/tl_oo.gif"><img src="system/skins/images/tl_oo.gif" width="1" height="4" border="0"></td>
<td width="6"><img src="system/skins/images/tl_ro.gif" width="6" height="4" border="0"></td>
</tr><tr>
<td background="system/skins/images/tl_lb.gif"><img src="system/skins/images/tl_lb.gif" width="4" height="1" border="0"></td>
<td style="padding:5px;" bgcolor="#FFFFFF">
<table width="100%"><tr>
<td bgcolor="#EFEFEF" height="29" style="padding-left:10px;"><div class="navigation">Color Ника</div></td>
</tr></table>
<div class="unterline"></div>
<table width="100%">
HTML;

  showmcRow('1:', $lang_mc['mc_color1'], "<input type=text style='text-align: center;' size=10 class=edit name='save_con[color1]' value='{$chatconfig['color1']}'>", "");
  showmcRow('2:', $lang_mc['mc_color2'], "<input type=text style='text-align: center;' size=10 class=edit name='save_con[color2]' value='{$chatconfig['color2']}'>", "");
  showmcRow('3:', $lang_mc['mc_color3'], "<input type=text style='text-align: center;' size=10 class=edit name='save_con[color3]' value='{$chatconfig['color3']}'>", "");

echo <<<HTML
<tr><td style="padding-top:10px; padding-bottom:10px;padding-right:10px;">

<input type=hidden name=mod value=chat>
<input type=hidden name=action value=dosaveconfigs>
<input type="submit" class="buttons" value="{$lang['user_save']}"></td>
</tr></table></td>
<td background="system/skins/images/tl_rb.gif"><img src="system/skins/images/tl_rb.gif" width="6" height="1" border="0"></td>
</tr><tr>
<td><img src="system/skins/images/tl_lu.gif" width="4" height="6" border="0"></td>
<td background="system/skins/images/tl_ub.gif"><img src="system/skins/images/tl_ub.gif" width="1" height="6" border="0"></td>
<td><img src="system/skins/images/tl_ru.gif" width="6" height="6" border="0"></td>
</tr></table></div></form>
HTML;
echofooter();
}elseif($action == "do_mess_edit"){
$aeditmess = $db->safesql($parse->BB_Parse(parse_mcsmiles($parse->process($_POST['aeditmess']))));
$result = $db->query("UPDATE " . PREFIX . "_chat SET message='$aeditmess' WHERE id='$id'");
@header("Location: $PHP_SELF?mod=chat");
}elseif($action == "do_mess_del"){
$deleted_message = 0;
foreach ($selected_mess as $id){
$id = intval($id);
$db->query("DELETE FROM " . PREFIX . "_chat WHERE id='$id'");
$deleted_message ++;
$db->free(); }
if(count($selected_mess) == $deleted_message){ msg("info", $lang['word_ldel'], $lang_mc['mc_mess_delok'], "$PHP_SELF?mod=chat"); }
else{ msg("error", $lang_mc['mc_mess_notok'], "$deleted_message $lang[mass_i] ".count($selected_mess)." $lang[mass_notok_1]", "$PHP_SELF?mod=chat"); }
}elseif($action == "doaddmess") {
$amess = $db->safesql($parse->BB_Parse(parse_mcsmiles($parse->process($_POST['amess']))));
$name  = "Admin";
$ip = $db->safesql($_SERVER['REMOTE_ADDR']);
$date = date ("Y-m-d H:i:s", time()+($config['date_adjust']*60));

if ($amess == "") msg("error",$lang['static_err'],$lang['static_err_1'], "javascript:history.go(-1)");

$db->query("INSERT INTO ".PREFIX."_chat (name, message, date, ip, `mgroup`, user_id) VALUES ('$name', '$amess', '$date', '$ip', '', '')");
header("Location: $PHP_SELF?mod=chat&action=doaddmessok");
}elseif($action == "doaddmessok"){
msg("info", $lang_mc['mc_addmssok'], "$lang[mc_addmssok]<br /><br /><a href=$PHP_SELF?mod=chat>$lang[db_prev]</a>");
}elseif($action == "dotrun") {
$db->query("TRUNCATE " . PREFIX . "_chat");
header("Location: $PHP_SELF?mod=chat");
}elseif($action == "dosaveconfigs")
{
        	$find[] 	= "'\r'";
			$replace[] 	= "";
        	$find[] 	= "'\n'";
			$replace[] 	= "";

	$save_con = $save_con + $chatconfig;

    if($member_id['user_group'] != 1){ msg("error", $lang_p['opt_denied'], $lang_p['opt_denied']); }
    $handler = fopen(SYSTEM_DIR.'/data/chat.config.php', "w");
    fwrite($handler, "<?PHP \n\n//Chat Configurations\n\n\$chatconfig = array (\n\n");
    foreach($save_con as $name => $value)
    {
	$value=trim(stripslashes ($value));
	$value=htmlspecialchars ($value, ENT_QUOTES);
	$value = preg_replace($find,$replace,$value);
    fwrite($handler, "'{$name}' => \"{$value}\",\n\n");
    }
    fwrite($handler, ");\n\n?>");
    fclose($handler);

    $cache->clear();
    msg("info", $lang['opt_sysok'], "$lang[opt_sysok_1]<br /><br /><a href=$PHP_SELF?mod=chat&action=configs>$lang[db_prev]</a>");
}
?>
