Location: PHPKode > projects > ACollab > inbox/index.php
<?php
/****************************************************************************************/
/* ACollab                                                                              */
/****************************************************************************************/
/* Copyright (c) 2002-2004  Adaptive Technology Resource Centre / University of Toronto */
/*                                                                                      */
/* http://atutor.ca/acollab                                                             */
/*                                                                                      */
/* This program is free software. You may 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.                                               */
/*                                                                                      */
/* 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.                                 */
/*                                                                                      */
/* You may access the GNU General Public License at:                                    */
/* http://www.opensource.org/licenses/gpl-license.php                                   */
/*                                                                                      */
/* You may contact the Adaptive Technology Resource Centre at                           */
/* Robarts Library, University of Toronto                                               */
/* 130 St. George Street, Toronto, Ontario, Canada M5S 1A5                              */
/* Further contact information is available at http://www.utoronto.ca/atrc/             */
/****************************************************************************************/
/* Programmer:                                                                          */
/* Joel Kronenberg - ATRC                                                               */
/****************************************************************************************/
// $Id: index.php 384 2005-02-09 21:32:17Z shozubq $

define('AC_INCLUDE_PATH', '../include/');

require(AC_INCLUDE_PATH.'vitals.inc.php');
require(AC_INCLUDE_PATH.'lib/forum_codes.inc.php');
authenticate(USER_CLIENT, USER_GROUP_ADMIN, USER_ADMIN);

$_SECTION[0][0] = _AC('home');
$_SECTION[0][1] = 'home.php';
$_SECTION[1][0] = _AC('inbox');
$_SECTION[1][1] = 'inbox/';

if (isset($_GET['view'])) {
	$_GET['view'] = intval($_GET['view']);
	mysql_query("UPDATE ".TABLE_PREFIX."messages SET new=0 WHERE to_member_id=$_SESSION[member_id] AND message_id=$_GET[view]",$db);
}

require(AC_INCLUDE_PATH.'header.inc.php');


if (isset($_GET['delete'])) {
	$_GET['delete'] = intval($_GET['delete']);

	if($result = mysql_query("DELETE FROM ".TABLE_PREFIX."messages WHERE to_member_id=$_SESSION[member_id] AND message_id=$_GET[delete]",$db)){
		$f[] = F_MSG_DELETED;
		print_feedback($f);
	}
	unset($_GET['delete']);
}

if (isset($_GET['f'])) {
	print_feedback($_GET['f']);
}

?>

<p align="center"><a href="inbox/send_message.php" onfocus="this.className='highlight'" onblur="this.className=''"><strong>ยป <?php echo _AC('compose_new_message'); ?></strong></a></p>
<?php

if (isset($_GET['view'])) {

	$sql	= "SELECT * FROM ".TABLE_PREFIX."messages WHERE message_id=$_GET[view] AND to_member_id=$_SESSION[member_id]";
	$result = mysql_query($sql, $db);

	if ($row = mysql_fetch_assoc($result)) {
?>
	<table border="0" cellpadding="2" cellspacing="0" align="center" width="95%" class="box" summary="">
	<tr>
		<th valign="top" class="box" align="left"><small><?php
			echo $row['subject'];
		?></small></th>
	</tr>
	<tr bgcolor="white">
		<td class="row1"><?php
			$from = get_login($row['from_member_id']);

			echo '<small class="bigspacer">'._AC('from').' <a href="profile.php?id='.$row['from_member_id'].'" onfocus="this.className=\'highlight\'" onblur="this.className=\'\'"><b>'.$from.'</b></a> '._AC('posted_on').' ';
			echo AT_date(_AC('inbox_date_format'), $row['date_sent'], AT_DATE_MYSQL_DATETIME);

			echo '</small>';
			echo '<p><small>';
			echo format_final_output(' '.$row['body'].' ');
			echo '</small></p>';
		?></td>
	</tr>
	<tr bgcolor="white">
		<td><small><a href="inbox/send_message.php?reply=<?php echo $_GET['view']; ?>" accesskey="r" onfocus="this.className='highlight'" onblur="this.className=''"><b><?php echo _AC('reply_r'); ?></b></a> |  <a href="<?php echo $_SERVER['PHP_SELF']; ?>?delete=<?php echo $_GET['view']; ?>" accesskey="x" onfocus="this.className='highlight'" onblur="this.className=''"><b><?php echo _AC('delete_x'); ?></b></a></small></td>
	</tr>
	</table>
	<br />
	<?php
	}
}

$course_groups[] = 0;
$sql = "SELECT group_id FROM ".TABLE_PREFIX."groups_members WHERE member_id=$_SESSION[member_id]";
$result = mysql_query($sql, $db);
echo '<form method="post" name="show_group" action="'.$_SERVER['PHP_SELF'].'"><select name="show">';
echo '<option value="all">'._AC('show_all').'</option>';

while ($row = mysql_fetch_array($result)) {
	$course_groups[] = $row['group_id'];
	echo '<option value="'.$row['group_id'];
	if ($row['group_id'] == $_POST['show']) {
		echo ' selected="selected" ';
	}

	$my_group = get_group($row['group_id']);
	echo  '">' . $my_group['title'].'</option>';
}
echo '</select> <input type="submit" class="submit" value='._AC('submit').' /></form><br />';

$show = ' ';
if (isset($_POST['show']) && $_POST['show'] != "all") {
	$show = "AND group_id=".$_POST['show'];
}

$sub	= implode(",", $course_groups);

$sql	= "SELECT * FROM ".TABLE_PREFIX."messages WHERE group_id IN ($sub) AND to_member_id=$_SESSION[member_id] ".$show." ORDER BY date_sent DESC";
$result = mysql_query($sql,$db);

echo '<table cellspacing="0" cellpadding="2" border="0" bgcolor="white" width="99%" align="center" summary="" class="box2">
<tr>
	<th scope="col" class="box" align="left"><small>'._AC('status').'</small></th>
	<th scope="col" width="100" class="box" align="left"><small>'._AC('from').'</small></th>
	<th scope="col" width="75%" align="left" class="box"><small>'._AC('subject').'</small></th>
	<th scope="col" width="150" align="right" class="box"><small>'._AC('date').'</small></th>
	<th scope="col" class="box"><img src="images/clr.gif" height="1" width="10" alt="" /></th>
</tr>';

$counter = 0;
$total = mysql_num_rows($result);

while ($row = mysql_fetch_assoc($result)) {

	$counter++;
	$col = ($counter-1)%2;

	echo '<tr>';
	
	echo '<td valign="middle" width="10" align="left" class="row'.$col.'"><small>';
	if ($row['new'] == 1)	{
		echo '<strong>'._AC('new').'</strong>';
	} else if ($row['replied'] == 1) {
		echo _AC('replied');
	} else {
		echo _AC('read');
	}
	echo '</small></td>';

	$name = get_login($row['from_member_id']);

	echo '<td align="left" class="row'.$col.'"><small><a href="profile.php?id='.$row['from_member_id'].'" onfocus="this.className=\'highlight\'" onblur="this.className=\'\'">';

	if ($_GET['view'] != $row['message_id']) {
		echo $name;
	} else {
		echo '<b>'.$name.'</b>';
	}
	echo '</a></small></td>';

	echo '<td valign="top" class="row'.$col.'"><small>';
	if ($_GET['view'] != $row['message_id']) {
		echo '<a href="'.$_SERVER['PHP_SELF'].'?view='.$row['message_id'].'" onfocus="this.className=\'highlight\'" onblur="this.className=\'\'">'.$row['subject'].'</a>';
	} else {
		echo '<strong>'.$row['subject'].'</strong>';
	}
	echo '</small></td>';

	echo '<td valign="top" align="right" class="row'.$col.'" nowrap="nowrap"><small>';
	echo AT_date(_AC('inbox_date_format'),
				$row['date_sent'],
				AT_DATE_MYSQL_DATETIME);
	echo '</small></td>';

	echo '<td class="row'.$col.'" align="right"><small><a href="'.$_SERVER['PHP_SELF'].'?delete='.$row['message_id'].'" onfocus="this.className=\'highlight\'" onblur="this.className=\'\'">'._AC('delete').'</a></small></td>';
	
	echo '</tr>';

}
echo '</table>';

	require(AC_INCLUDE_PATH.'footer.inc.php');
?>
Return current item: ACollab