<?php
if( !defined('ISDVBBS') ){
	header('HTTP/1.0 404 Not Found');
	exit;
}
if( !empty($dbResult) && is_array($dbResult) ){
	if( $GLOBALS['action'] == 'new' || $GLOBALS['action'] == 'edit' ){
		$touser = $dbResult['sender'];
	}
	$incept = $dbResult['incept'];
	$sender = $dbResult['sender'];
	$sendtime = is_numeric($dbResult['sendtime']) ? gmdate('Y-m-d H:i:s', $dbResult['sendtime']+getUserTimeZoneOffset()) : $dbResult['sendtime'];
	$title = $title.$dbResult['title'];
	$content = $dbResult['content'];
	$temptxt = str_replace('{$sendtime}',$sendtime,$temptxt);
	$temptxt = str_replace('{$sender}',$sender,$temptxt);
	$temptxt = str_replace('{$br}','<br>',$temptxt);
	if( $GLOBALS['action'] == 'new' || $GLOBALS['action'] == 'fw' ){
		$textarea = $temptxt.$content.'<br>======================================<br>';
	} else{
		$textarea = $content;
	}
	$postdata = get_cookie('postdata');
	if( $postdata != '' ){
		$textarea = htmlspecialchars($postdata);
	} else{
		$textarea = htmlspecialchars($textarea);
	}
} else{
	$postdata = get_cookie('postdata');
	if( $postdata != '' ){
		$textarea = htmlspecialchars($postdata);
	} else{
		$textarea = htmlspecialchars($textarea);
	}
}

if( !empty($dbResults) && is_array($dbResults) ){
	foreach( $dbResults as $val ){
		$val['sendtime'] = gmdate('Y-m-d H:i:s', $val['sendtime']+getUserTimeZoneOffset());
		$chatloglist .= '<tr><td height=25 colspan=3>';
		if( trim($val['sender']) == $membername ){
			$temp_chat1 = str_replace('{$sendtime}',$val['sendtime'],$lang['template.strings59']);
			$temp_chat1 = str_replace('{$incept}',htmlspecialchars($val['incept']),$temp_chat1);
			$chatloglist .= $temp_chat1;
		} else{
			$temp_chat2 = str_replace('{$sendtime}',$val['sendtime'],$lang['template.strings60']);
			$temp_chat3 = str_replace('{$senduser}',htmlspecialchars($val['sender']),$temp_chat2);
			$chatloglist .= $temp_chat2;
		}
		$chatloglist .= '</td></tr><tr><td valign=top align=left colspan=3><b>';
		$chatloglist .= $lang['template.Strings61'].htmlspecialchars($val['title']);
		$chatloglist .= '</b><hr size=1>';
		$chatloglist .= '</td></tr>';
	}
} else{
	$chatloglist = "<tr><td colspan=3>{$lang['template.strings58']}</td></tr>";
}

if( !empty($Friend_options) && is_array($Friend_options) ){
	foreach( $Friend_options as $val ){
		$Friend_option .= "<option value=\"{$val['f_friend']}\">{$val['f_friend']}</option>";;
	}
} else{
	$Friend_option = '';
}


if( $groupsetting[63] != 0 ){
	$smslimited = intval($groupsetting[63]) - intval($UserToday[1]);
} else{
	$smslimited = 9999;
}
print <<<EOT
<tr>
<td valign=middle width="15%"><b>{$lang['tpl.smsg.str1']}</b></td>
<td valign=middle width="85%" align="left"><input type=text name="touser" value="{$touser}" size=50>
<SELECT name=friend onchange="DoTitle(this.options[this.selectedIndex].value)">
<OPTION selected value="">{$lang['tpl.smsg.str2']}</OPTION>
{$Friend_option}
</SELECT></td></tr>
<tr>
<td ><b>{$lang['tpl.smsg.str3']}</b></td>
<td valign=middle align="left"><input type=text name="title" size=70 maxlength=80 {$title} ></td>
</tr>
EOT;
if( $fsetting['msggetcode'] != 0 ){
	$getcodehtml=get_cercode(100,24);
	print <<<EOT
<!--{$getcode}-->
<td ><b>{$lang['tpl.smsg.str4']}</b></td>
<td valign=middle>{$getcodehtml}</td>
</tr>
EOT;
}
	$lang['tpl.smsg.str6']=str_replace(array('{$Sms_senduser}','{$Sms_maxbody}','{$smslimited}'),array($Sms_senduser,$Sms_maxbody,$smslimited),$lang['tpl.smsg.str6']);
print <<<EOT
{$mo_send}
<tr>
<td><b>{$lang['tpl.smsg.str5']}</b><INPUT TYPE="hidden" id="message" name="message" value="{$textarea}"></td>
<td align="left">
<table height="160" class="mainbox tableborder" cellpadding=0 cellspacing=0 border=0>
<tr><td height="100%">
<iframe class="Dvbbs_Reply" ID="Dvbbs_Composition" MARGINHEIGHT="5" MARGINWIDTH="5" width="100%" height="100%" ></iframe>
</td></tr></table>
</td></tr>
<tr>
<td colspan=2 align="left">
{$lang['tpl.smsg.str6']}
</td></tr>
<tr>
<td valign=middle colspan=2 align=center>
<INPUT TYPE="hidden" NAME="sms_act" value="" >
<button type="Submit" name="Submit" onMousemove="button_move(this)" onMouseout="button_out(this)" onclick="this.form.sms_act.value='Sms_Issend'">{$lang['tpl.smsg.str7']}</button>&nbsp;
<button type="Submit" name="Submit" onMousemove="button_move(this)" onMouseout="button_out(this)"  onclick="this.form.sms_act.value='Sms_Issave'">{$lang['tpl.smsg.str8']}</button>&nbsp;&nbsp;
<button type="reset" name="Clear" onMousemove="button_move(this)" onMouseout="button_out(this)" >{$lang['tpl.smsg.str9']}</button>&nbsp;
<SCRIPT LANGUAGE="JavaScript">
<!--
var Dvbbs_bIsIE5=document.all
if (Dvbbs_bIsIE5)
{var IframeID=frames["Dvbbs_Composition"];}
else
{
var IframeID=document.getElementById("Dvbbs_Composition").contentWindow;
}


var reaction='{$reaction}';
var action='{$action}';
if (action=='new')
{
if (reaction=='chatlog')
{
document.write ('<button type=button onMousemove="button_move(this)" onMouseout="button_out(this)" name="chatlog" onclick="location.href=\'?action=new&id={$sms_id}&touser={$touser}\'">{$lang['tpl.smsg.str10']}</button>');
}
else{
document.write ('<button type=button onMousemove="button_move(this)" onMouseout="button_out(this)" name="chatlog" onclick="location.href=\'?action=new&id={$sms_id}&touser={$touser}&reaction=chatlog\'">{$lang['tpl.smsg.str11']}</button>');
}
}

Dvbbs_InitDocument('message','gb2312')

//-->
</SCRIPT>
&nbsp;<button type="button" name="close" onMousemove="button_move(this)" onMouseout="button_out(this)" onclick="window.close()">{$lang['tpl.smsg.str12']}</button>
</td></tr>
<SCRIPT LANGUAGE="JavaScript">
<!--
var reaction='{$reaction}';
var chatloglist='{$chatloglist}';
var myname='{$myname}';
var action='{$action}';
if (action=='new')
{
if (reaction=='chatlog')
{
	document.write ('<tr>');
	document.write ('{$lang['tpl.smsg.str13']}{$touser}{$lang['tpl.smsg.str14']}</th>');
	document.write ('</tr>');
	if (myname=='{$touser}')
	{
		document.write ('<tr>');
		document.write ('<td colspan=3>{$lang['tpl.smsg.str15']}</td>');
		document.write ('</tr>');
	}
	else{
		document.write (chatloglist);
	}
}
}
//-->
</SCRIPT>
</form>
</div>
<script language="javascript"> 
var aaaa;
aaaa="";
function send_xiaoyue() {
	if(Dvform.mo_send.checked == false)
	{
		document.Dvform.action="messanger.php?action=send";
		document.Dvform.title.disabled=false;
		document.Dvform.title.value=aaaa;
	} else 
	{
		document.Dvform.action="challenge_msg.php?action=submessage";
		document.Dvform.title.disabled=true;
		aaaa = document.Dvform.title.value;
		document.Dvform.title.value= "{$lang['tpl.smsg.str16']}";
	}
}


function ctlent()
{
	if(event.ctrlKey && window.event.keyCode==13)
	{
		Dvbbs_CopyData('message');
		document.Dvform.sms_act.value='Sms_Issend';
		this.document.Dvform.submit();
	}
	
}


function DoTitle(addTitle) {  
 var revisedTitle;  
 var currentTitle = document.Dvform.touser.value;
 if(currentTitle=="") revisedTitle = addTitle; 
 else { 
  var arr = currentTitle.split(","); 
  for (var i=0; i < arr.length; i++) { 
   if( addTitle.indexOf(arr[i]) >=0 && arr[i].length==addTitle.length ) return; 
  } 
  revisedTitle = currentTitle+","+addTitle; 
 } 

 document.Dvform.touser.value=revisedTitle;  
 document.Dvform.touser.focus(); 
 return; 
} 
</script>
	</table>
</div>
EOT;
?>