<?php
/*
 ########################################################################
#                                                                        #
#           Version 4       /                        /   /               #
#          -----------__---/__---__------__----__---/---/-               #
#           | /| /  /___) /   ) (_ `   /   ) /___) /   /                 #
#          _|/_|/__(___ _(___/_(__)___/___/_(___ _/___/___               #
#                       Free Content / Management System                 #
#                                   /                                    #
#                                                                        #
#                                                                        #
#   Copyright 2005-2006 by webspell.org                                  #
#                                                                        #
#   visit webSPELL.org, webspell.info to get webSPELL for free           #
#   - Script runs under the GNU GENERAL PUBLIC LICENSE                   #
#   - It's NOT allowed to remove this copyright-tag                      #
#   -- http://www.fsf.org/licensing/licenses/gpl.html                    #
#                                                                        #
#   Code based on WebSPELL Clanpackage (Michael Gruber - webspell.at),   #
#   Far Development by Development Team - webspell.org                   #
#                                                                        #
#   visit webspell.org                                                   #
#                                                                        #
 ########################################################################
*/

function getnewmessages($userID) {
	$anz=mysql_num_rows(safe_query("SELECT messageID FROM `".PREFIX."messenger` WHERE touser='$userID' AND userID='$userID' AND viewed='0'"));
	return $anz;
}

function sendmessage($touser,$title,$message,$from='0') {

 global $hp_url;

 $systemmail = false;
 if(!$from) { $systemmail = true; $from = '1'; }

 if(!$systemmail) {
  safe_query("INSERT INTO ".PREFIX."messenger (userID, date, fromuser, touser, title, message, viewed) values('$from', '".time()."', '$from', '$touser', '$title', '".mysql_escape_string($message)."', '0')");  // eintrag für sender
  safe_query("UPDATE ".PREFIX."user SET pmsent=pmsent+1 WHERE userID='$from'"); //pmsent++
 }
 if(!isignored($touser, $from) OR $systemmail) {
  safe_query("INSERT INTO ".PREFIX."messenger (userID, date, fromuser, touser, title, message, viewed) VALUES ('$touser', '".time()."', '$from', '$touser', '$title', '".mysql_escape_string($message)."', '0')");  // eintrag für empfänger
  safe_query("UPDATE ".PREFIX."user SET pmgot=pmgot+1 WHERE userID='$touser'"); //pmgot++
  if(wantmail($touser) AND !isonline($touser)) {
   $ds=mysql_fetch_array(safe_query("SELECT email FROM ".PREFIX."user WHERE userID='$touser'"));
   mail($ds[email], PAGETITLE.': You got new PM', '<b>Hello '.getnickname($touser).'!</b><br><br>You got a new message at '.PAGETITLE.' ('.$hp_url.').<br>Click <a href="http://'.$hp_url.'?site=messenger">here</a> to read the PM.<br><br>(C) webSPELL.org','Content-Type: text/html');
  }
 }
}

?>