qa-db-messages.php 2.14 KB
Newer Older
Gideon Greenspan committed
1
<?php
Scott Vivian committed
2

Gideon Greenspan committed
3 4 5 6 7
/*
	Question2Answer (c) Gideon Greenspan

	http://www.question2answer.org/

Scott Vivian committed
8

Gideon Greenspan committed
9 10 11 12 13 14 15 16 17
	File: qa-include/qa-db-messages.php
	Version: See define()s at top of qa-include/qa-base.php
	Description: Database-level access to messages table for private message history


	This program is free software; you can redistribute it and/or
	modify it under the terms of the GNU General Public License
	as published by the Free Software Foundation; either version 2
	of the License, or (at your option) any later version.
Scott Vivian committed
18

Gideon Greenspan committed
19 20 21 22 23 24 25 26 27 28 29 30 31 32
	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	More about this license: http://www.question2answer.org/license.php
*/

	if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
		header('Location: ../');
		exit;
	}


Gideon Greenspan committed
33
	function qa_db_message_create($fromuserid, $touserid, $content, $format, $public=false)
Gideon Greenspan committed
34
/*
Gideon Greenspan committed
35 36
	Record a message sent from $fromuserid to $touserid with $content in $format in the database. $public sets whether
	public (on wall) or private. Return the messageid of the row created.
Gideon Greenspan committed
37 38 39
*/
	{
		qa_db_query_sub(
Gideon Greenspan committed
40 41
			'INSERT INTO ^messages (type, fromuserid, touserid, content, format, created) VALUES ($, #, #, $, $, NOW())',
			$public ? 'PUBLIC' : 'PRIVATE', $fromuserid, $touserid, $content, $format
Gideon Greenspan committed
42
		);
Scott Vivian committed
43

Gideon Greenspan committed
44 45
		return qa_db_last_insert_id();
	}
Scott Vivian committed
46

Gideon Greenspan committed
47 48

	function qa_db_message_delete($messageid)
Gideon Greenspan committed
49 50 51
/*
	Delete the message with $messageid from the database
*/
Gideon Greenspan committed
52 53 54 55 56 57
	{
		qa_db_query_sub(
			'DELETE FROM ^messages WHERE messageid=#',
			$messageid
		);
	}
Gideon Greenspan committed
58 59


Gideon Greenspan committed
60 61 62 63 64 65 66 67 68 69 70 71 72
	function qa_db_user_recount_posts($userid)
/*
	Recalculate the cached count of wall posts for user $userid in the database
*/
	{
		if (qa_should_update_counts())
			qa_db_query_sub(
				"UPDATE ^users AS x, (SELECT COUNT(*) AS wallposts FROM ^messages WHERE touserid=# AND type='PUBLIC') AS a SET x.wallposts=a.wallposts WHERE x.userid=#",
				$userid, $userid
			);
	}


Gideon Greenspan committed
73 74 75
/*
	Omit PHP closing tag to help avoid accidental output
*/