All pastes #400125 Raw Edit

Unnamed

public text v1 · immutable
·published 2007-03-18 14:19 UTC
rendered paste body
<?php

class sendMessage {
	var $send_to;
	var $come_from;
	var $time_sent;
	var $subject;
	var $message;
	var $privatem;
	var $connection;
	
	function sendMessage() {
		$this->connection=new DataBase();
		$this->send_to = $this->strip_code($_POST['username']);
		$this->come_from = $_SESSION['username'];
		$this->time_sent = "";
		$this->subject = $this->strip_code($_POST['subject']);
		$this->message = $this->strip_code($_POST['message']);	
		$this->privatem = $this->strip_code($_POST['private']);
		$this->time_sent = date('Y-m-d H:i:s');
		if($this->message && strlen($this->message)>6) {
			if($this->subject) {
				if($this->come_from) {
					if($this->send_to) {
						if($this->privatem) {
							$this->send(); 
						} else {
							$this->privatem = "n";
							$this->send();
						}
					} else { echo("I don't know who to send this message to!"); }
				} else { echo("Please Login"); }
			} else { echo("Please enter a subject"); }
		} else { echo("Message too short."); }
	}	
	
	function send() {
		if($this->send_to!=$this->come_from) {
			$this->connection->Query("SELECT username FROM users WHERE username='$this->send_to'");
			if($this->connection->TotalRows()>0) {
				$this->connection->Query("INSERT INTO user_pm (to_id, from_id, time_sent, subject, message, opened, private) VALUES ('$this->send_to', '$this->come_from', '$this->time_sent', '$this->subject', '$this->message', 'n', '$this->privatem')");
			    echo("Message has been sent to <b><a href=\"profile.php?username=". $this->send_to ."\">". $this->send_to . "</a></b>");	
				$this->connection->Close();
			} else { echo("The username does not exist"); }		
		} else { echo("You can not send a message to yourself"); }
	}
	
	function strip_code($value){
    	if (get_magic_quotes_gpc()) {
    		$value = stripslashes($value);
			$value = htmlspecialchars($value);
    	   	$value = mysql_real_escape_string($value);
		} 
			return $value;
	}
}
?>