<?php
/*
 **************************************************************************************************
 *    Copyright (c) 2010-2012 Just Another Video script
 *
 * 	  This file is part of Just Another Video Script.
 *    Version 1.4.3
 *    info@justanothervideoscript.com
 **************************************************************************************************
 *    Come to website for support or buying additional plugins/modules.
 *    http://justanothervideoscript.com/
 **************************************************************************************************
 *    By using this software you agree that you have read and acknowledged our End-User License
 *    Agreement available at http://justanothervideoscript.com/license and can be bound by it.
 **********************************************************************************
 */
global $db ;
if (!$loggedIn) {
	$haltMessage = "<h2>You must log in</h2>" ;
} 
else {
	$msgto = quote_smart($_GET['subpage']) ;
	$db->query("SELECT username FROM member WHERE id = '".$msgto."'") ;
	$res = $db->fetch() ;
	$msgusername = $res['username'] ;
	if (isset($msgusername )) {
		if (isset($_POST['submit'])) { 	
			$msgto = quote_smart($_GET['subpage']) ;
			$msgbody = quote_smart($_POST['msgbody']) ;
			$username = quote_smart($_SESSION['session_username']);
			$db->query("SELECT id FROM member WHERE username = '".$username."'") ;
			$res2 = $db->fetch() ;
			$msgfrom = $res2['id'] ;
			$db->query("INSERT INTO message (fromid, toid, body, sentdate, msgread) VALUES (".$msgfrom.",".$msgto.",'".$msgbody."',".time().",0)") ;
 			echo "Your Message has been sent." ;
 			
 			//send mail to receiving user				
 				if (getSetting("mail_friend_pm", $db) == '1') {		
					$msg = getEmailformat("email_friend_pm") ;
					$msg = str_replace(array('[POSTER]', '[SITEURL]'), array($username, $sitepath), $msg);
					
					$db->query("SELECT email, username FROM member WHERE USERNAME = '".$msgto."' LIMIT 1") ;
					$mailinfo = $db->fetch() ;
					
					sendmail(array(array("email"=>$mailinfo['email'], "name"=>$mailinfo['username'])), 'You have a new message from'.$username, $msg, 'no') ;
				}		
 			
 			
 			
		}
	}

}

?>
