Location: PHPKode > scripts > Particle Gallery > includes/functions_messages.php
<?php
// for dealing with messaging system
function sendmessage($to, $from, $title, $message){
	global $db, $dbprefix;
	
	// standard validation
	if ($title == ""){ return "You did not enter a subject"; }
	if ($message == ""){ return "You did not entera message"; }
	
	// validate target
	$sql = "SELECT * FROM " . $dbprefix . "users WHERE userid = " . dbSecure(intval($to));
	$use = $db->execute($sql);
	if ($use->rows < 1){ return "The target user could not be found"; }
	
	// insert the message
	$sql  = "INSERT INTO " . $dbprefix . "messages (toid, fromid, postdate, title, message) VALUES (";
	$sql .= intval($use->fields["userid"]) . ", ";
	$sql .= dbSecure(intval($from)) . ", ";
	$sql .= time() . ", ";
	$sql .= "'" . dbSecure($title) . "', ";
	$sql .= "'" . dbSecure($message) . "')";
	$db->execute($sql);
	
	// and return
	return "Message send successfully!";
}

function deletemessage($messageid){
	global $db, $dbprefix, $usr;
	
	// standard validation
	$messageid = intval($messageid);
	$usr->Auth(1);
	
	// find the message
	$sql = "SELECT * FROM " . $dbprefix . "messages WHERE messageid = " . dbSecure($messageid) . " AND toid = " . dbSecure(intval($_SESSION["userid"]));
	$msg = $db->execute($sql);
	if ($msg->rows < 1){ return "The message could not be found"; }
	
	// ok, delete it
	$sql = "DELETE FROM " . $dbprefix . "messages WHERE messageid = " . $msg->fields["messageid"];
	$db->execute($sql);
	
	// and return
	return "Message deleted successfully!";
}

function managemessages($ids, $decision, $allids = ""){
	global $db, $dbprefix, $usr;
	
	// check user is signed in
	$usr->Auth(1);
	
	// work out the IDs array
	if ($decision == "Delete All"){
		// use the all IDs variable
		if ($allids == ""){ return "There are no messages to delete"; }
		$ids_t = split(",", $allids);
		$ids = Array();
		foreach($ids_t as $z){
			if ($z <> ""){ array_push($ids, $z); }
		}
	
	} else {
		// use the selected variables
		if (!(is_array($ids))){ return "You did not select any messages"; }
		if (count($ids) < 1){ return "You did not select any messages"; }
	}
	
	// now loop through each one
	foreach($ids as $id){
		$sql = "DELETE FROM " . $dbprefix . "messages WHERE messageid = " . dbSecure(intval($id)) . " AND toid = " . dbSecure(intval($_SESSION["userid"]));
		$db->execute($sql);
	}
	
	// and return
	return "Messages deleted successfully!";
}
?>
Return current item: Particle Gallery