Wikka Mail
The version 1.5 release is a major feature release for wikka mail. Apart from the increase in functionality (including a category/filter system, an urgent indicator, limits on submitted length in the messages w/ a counter, a "replied to" indicator, etc) there was also a database change (the addition of 5 fields and the removal of one). If you are
upgrading from version 1.0 there are detailed instructions at the bottom of the page.
The code below implements a private messaging system in wikka. It allows messages to be sent between users, a contact list to be maintained, user-defined folders for filing the messages, forwarding & replying to messages, etc. The "in-box" and "sent" folder are paginated (because they often have a high number of entries). Most of the functionality of email, with the exception of attachments & multiple recipients, are present. Optional code is provided which can be added to the header.php file providing a visual indicator to show the presence of new, unread messages. Two mysql tables need to be added, one class file (also used in the
WikkaBlog2) for pagination placed in the directory "scripts" in the wikka root, and one file (mail.php) placed in the actions directory.
The table prefixes should be set to match the prefix used in your wiki.
CREATE TABLE `wakka_mail` (
`UserTo` tinytext NOT NULL,
`repliedto` tinyint(1) DEFAULT '0',
`folder` tinytext NOT NULL,
`UserFrom` tinytext NOT NULL,
`urgent` tinyint(1) DEFAULT NULL,
`Subject` mediumtext NOT NULL,
`Message` longtext NOT NULL,
`fltr1` tinyint(1) DEFAULT '0',
`fltr2` tinyint(1) DEFAULT '0',
`fltr3` tinyint(1) DEFAULT '0',
`status` text NOT NULL,
`DateSent` datetime DEFAULT NULL,
`viewrecipient` enum('Y','N') NOT NULL DEFAULT 'Y',
`mail_id` int(80) NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`mail_id`)
) TYPE=MyISAM;
CREATE TABLE `wakka_mailinfo` (
`owner` tinytext NOT NULL,
`type` tinytext NOT NULL,
`info` tinytext NOT NULL,
`notes` tinytext,
`id` int(80) NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`id`)
) TYPE=MyISAM;
This code is for
mail.php and should be inserted into the actions directory.
<?php
// This mail.php (Version 1.5d) code is a substantial modification of code originally released by cscartman (Cody Selzer) at www.codewalkers.com
// as freeware. The code has been considerably modified and extended for use in wikka wiki by GmBowen for a SSHRC research project.
// Modifications & additions by GmBowen released under GPL.
// Use: {{mail}} (no parameters). Needs: MySQL database tables (2) & class for pagination ("page.inc.php") placed in
// directory "scripts" in wikka root.
// The line below can be placed in php tags & added to the header after <h2> to provide an indication in the header of when there's mail.
// if (mysql_num_rows(mysql_query("SELECT status FROM ".$this->config["table_prefix"]."mail where UserTo='".$this->GetUserName()."' and folder='inbox' and status='unread' and viewrecipient='Y' LIMIT 1"))!=0) {echo "<a title='You have mail.'><font color=Red><strong>*</strong></font></a>";}
// includes functions for doing pagination of "sent" & "inbox" messages
include_once("scripts/page.inc.php");
$pagename =
$this->
MiniHref($method,
$tag);
$link =
$this->
config["base_url"].
$this->
MiniHref($method,
$tag);
$userfrom =
$this->
GetUserName();
$pagenum=
$_GET['page'];
$username =
$userfrom;
$folder=
$_GET['folder'];
$which=
$_REQUEST['whichfolder'];
if (!
$folder) {$folder=
$which;
}
$fltrset=
$_GET['fltrset'];
$msg_id=
$_GET['mail_id'];
$filter=
$_GET['fltr'];
$move2folder =
$_REQUEST[move2folder
];
$action=
$_GET['action'];
$subject=
$_GET[subject
];
$mail_id=
$msg_id;
$id=
$_GET['id'];
$to=
$_GET['to'];
?>
<SCRIPT LANGUAGE=
"JavaScript">
<!-- Begin
function textCounter
(field, countfield, maxlimit
) {
if (field.value.length > maxlimit
) // if too long...trim it!
field.value = field.value.substring
(0, maxlimit
);
// otherwise, update 'characters left' counter
else
countfield.value = maxlimit - field.value.length;
}
// End -->
</script>
<table><tr><td>|</td><td> <a href=
"<?php echo $link; ?>&action=inbox">Inbox</a> </td><td>|</td><td> <a href=
"<?php echo $link; ?>&action=compose">Compose</a> </td><td>|</td><td>
<?php
$str =
"SELECT DISTINCT info FROM ".
$this->
config["table_prefix"].
"mailinfo WHERE type='folder' and owner='$username' ORDER BY info ASC";
$resultdrop =
mysql_query($str);
echo "<form method='post' action=\"$link\"><select name=\"whichfolder\">";
while ($row =
mysql_fetch_array($resultdrop))
{
extract ($row);
if($_REQUEST[whichfolder
] ==
$info)
{
echo "<option selected value=\"$info\">$info</option>";
}else {
echo "<option value=\"$info\">$info</option>";
}
}
echo "</select><input type='submit' value='View'></form>";
?>
</td><td>|</td><td> <a href=
"<?php echo $link; ?>&action=sent">Sent</a> </td><td>|</td><td> Manage <a href=
"<?php echo $link; ?>&action=folders">Folders</a> / <a href=
"<?php echo $link; ?>&action=contacts">Contacts</a> </td><td>| </td><td><a href=
"<?php echo $link; ?>&action=users">Users</a> <td>| <a href=
"<?php echo $link; ?>&action=help">Help</a></td> <td>|</td></td></tr></table>
<?php
if ($action==
"compose" ||
$action==
"forward" ||
$action==
"contacts" ||
$action==
"folders" ||
$action==
"users" ||
$action==
"help" ||
$action==
"reply" ||
$action==
"delete" ||
$action==
"compose2"){echo "";
} else {
if ($action==
"inbox" ||
(($action==
"" ||
$action==
"view") &&
$_REQUEST['whichfolder']==
"" &&
$folder==
"")) {$which2=
"<a href=".
$link.
"&page=".
$pagenum.
">In-box</a>";
}
elseif ($action==
"sent" ||
$action==
"view2") {$which2=
"<a href=".
$link.
"&action=sent&page=".
$pagenum.
">Sent Mail</a>";
} elseif (folder!=
"") {$which=
$folder;
$which2=
"<a href=".
$link.
"&folder=".
$folder.
">".
$which.
"</a>";
}
echo "<strong>Folder:</strong> ".
$which2;
}
// code for moving messages to folders
if ($move2folder) {
$query=
"UPDATE ".
$this->
config["table_prefix"].
"mail SET folder='$move2folder' WHERE UserTo='$username' AND mail_id='$mail_id'";
$query or
die("An error occurred resulting that this message has not been marked read.");
$rs =
mysql_query("UPDATE ".
$this->
config["table_prefix"].
"mail SET folder='$move2folder' WHERE mail_id='$mail_id' AND UserTo='$username'");
if($query) {
echo "<br /><strong>Message moved to ".
$move2folder.
" folder.</strong>";
} else {
echo "The message wasn't moved.";
}
}
// shows inbox
elseif(($action==
'' ||
$action==
'inbox') &&
$_REQUEST['whichfolder']==
'' &&
(!
$folder)) {
if ($filter==
1) {$search=
"and fltr1='1' ";
} elseif ($filter==
2) {$search=
"and fltr2='1' ";
} elseif ($filter==
3) {$search=
"and fltr3='1' ";
} elseif ($filter==N
) {$search=
"and fltr1='0' and fltr2='0' and fltr3='0' ";
} else {$search=
"";
}
// setting the filter conditions into the database
$queryfil=
"SELECT fltr1,fltr2,fltr3,mail_id FROM ".
$this->
config["table_prefix"].
"mail where UserTo='$username' and folder='inbox' and viewrecipient='Y' ORDER BY DateSent DESC";
$resultfil=
mysql_query($queryfil) or
die ("cant do it");
while ($row=
mysql_fetch_array($resultfil)) {
// code to set filters in database
if (($fltrset) &&
($row[mail_id
]==
$msg_id)) {
// code to determine setting of filters on server
if ($row[fltr1
]!=
1) {$fltrvar1=
1;
} else {$fltrvar1=
0;
}
if ($row[fltr2
]!=
1) {$fltrvar2=
1;
} else {$fltrvar2=
0;
}
if ($row[fltr3
]!=
1) {$fltrvar3=
1;
} else {$fltrvar3=
0;
}
// code to set which filter is being set
if ($fltrset==
1) {$fltr=
"fltr1";
$set=
$fltrvar1;
} elseif ($fltrset==
2) {$fltr=
"fltr2";
$set=
$fltrvar2;
} elseif ($fltrset==
3) {$fltr=
"fltr3";
$set=
$fltrvar3;
}
mysql_query("UPDATE ".
$this->
config["table_prefix"].
"mail SET ".
$fltr.
"=".
$set.
" WHERE mail_id='$msg_id' AND UserTo='$username'");
}
}
$query=
"SELECT * FROM ".
$this->
config["table_prefix"].
"mail where UserTo='$username' ".
$search.
"and folder='inbox' and viewrecipient='Y' ORDER BY DateSent DESC";
$result=
mysql_query($query) or
die ("cant do it");
echo "<table cellpadding='2' cellspacing='3' width='850' valign='top'>";
//needed for pagination of sent box
$record_per_page=
10;
$scroll=
3;
$total_records=
mysql_num_rows($result);
$page=
new Page
();
//creating new instance of Class Page
$link2=
$link.
"&action=inbox";
// to paginate the "inbox" page messages
echo "<tr><td colspan='4' align='center'>";
if ($total_records>
$record_per_page) {
$page->
set_page_data($link2,
$total_records,
$record_per_page,
$scroll,
true,true,
true);
$result=
mysql_query($page->
get_limit_query($query));
echo $page->
get_page_nav();
}
echo "</td></tr>";
echo "<tr bgcolor=#dddddd>\n";
echo "<td width='420'><table border='0' cellpadding='0' cellspacing='0' width='100%'><tr><td> Message Topic:</td><td align='right'>";
// sets underline on filter if chosen
if ($filter==
1) {$red=
"<u>*</u>";
} else {$red=
"*";
}
if ($filter==
2) {$blue=
"<u>*</u>";
} else {$blue=
"*";
}
if ($filter==
3) {$green=
"<u>*</u>";
} else {$green=
"*";
}
if ($filter==
"N") {$none=
"<u>N</u>";
} else {$none=
"N";
}
echo "<a href=".
$link.
" title='Shows ALL of the messages.'><strong>A</strong></a> <a href=".
$link.
"&fltr=N title='Shows messages with NO star markers.'><strong>".
$none.
"</strong></a> <a href=".
$link.
"&fltr=1 title='Shows messages with a RED star marker.'><font color='red'><strong>".
$red.
"</strong></font></a> <a href=".
$link.
"&fltr=2 title='Shows messages with a BLUE star marker.'>";
echo "<font color='blue'><strong>".
$blue.
"</strong></font></a> <a href=".
$link.
"&fltr=3 title='Shows messages with a GREEN star marker.'><font color='green'><strong>".
$green.
"</strong></font></a></td></tr></table></td>\n";
echo "<td width='85'> Sender:</td>\n";
echo "<td width='155'> Move to Folder:</td>\n";
echo "<td> Delete:</td>\n";
echo "<td> <strong>+</strong>/<strong>-</strong></td>\n";
echo "</tr>\n";
while ($row=
mysql_fetch_array($result)) {
// Extracting & formatting date
$datetime=
date("dMy g:i a",
strtotime($row['DateSent']));
// put in red asterisk if unread & add coloured filters
if ($row[status
]==
"unread") {$status=
"<a title='This message has not been read yet!'><font color=Red>*</font></a>";
} else {$status=
"";
}
if ($row[urgent
]==
"1") {$urgentmkr=
"<a title='This is an urgent message!'><font color=Red><strong>!</strong></font></a>";
} else {$urgentmkr=
"";
}
if ($row[repliedto
]==
"1") {$replied=
"<a title='You have replied to this message!'><font color='black'><strong>+</strong></black></a>";
} else {$replied=
" ";
}
echo "<tr><td>$status$urgentmkr <a href=".
$link.
"&action=view&mail_id=".
$row[mail_id
].
"&page=".
$pagenum.
">".strip_tags
($row[Subject
]).
"</a><small>".
$replied.
"(".
$datetime.
")</small>";
// put in asterisks if indicated to do so in database
if ($row[fltr1
]==
1) {echo "<font color='red'><strong>*</strong></font>";
} else {echo " ";
}
if ($row[fltr2
]==
1) {echo "<font color='blue'><strong>*</strong></font>";
} else {echo " ";
}
if ($row[fltr3
]==
1) {echo "<font color='green'><strong>*</strong></font>";
} else {echo " ";
}
echo "</td>";
echo "<td>".
$this->
Format($row[UserFrom
]).
"<small> [<a href=".
$link.
"&action=contacts&cntct=".
$row[UserFrom
].
">-></a>]</small></td><td align='left' width='155'>";
// code to put in drop down box to move to a new folder
$str2 =
"SELECT DISTINCT info FROM ".
$this->
config["table_prefix"].
"mailinfo WHERE type='folder' and owner='$username' ORDER BY info ASC";
$resultdrop2 =
mysql_query($str2);
echo "<form method=post action=\"$link&mail_id=$row[mail_id]\"><select name=\"move2folder\">";
while ($row2 =
mysql_fetch_array($resultdrop2))
{
extract ($row2);
echo "<option value=\"$info\">$info</option>";
}
echo "</select><input type='submit' value='Move'></form>";
echo "</td><td> [<a href=\"javascript: if(confirm('Are you sure you want to delete this item?')){ window.self.location='".
$link.
"&action=delete&id=".
$row[mail_id
].
"' }\">Delete</a>]<br /></td>";
echo "</td><td> <a href=".
$link.
"&fltrset=1&mail_id=".
$row[mail_id
].
"&fltr=".
$filter.
"&page=".
$pagenum.
" title='Mark message with a RED star.'><font color='red'><strong>*</strong></font></a>|<a href=".
$link.
"&fltrset=2&mail_id=".
$row[mail_id
].
"&fltr=".
$filter.
"&page=".
$pagenum.
" title='Mark message with a BLUE star.'><font color='blue'><strong>*</strong></font></a>|<a href=".
$link.
"&fltrset=3&mail_id=".
$row[mail_id
].
"&fltr=".
$filter.
"&page=".
$pagenum.
" title='Mark message with a GREEN star.'><font color='green'><strong>*</strong></font></a><br /></td></tr>";
}
echo "</table>";
if ($total_records!=
0) {
echo "<small> Clicking on the right arrow indicator [->] will add the user's name to the \"contacts\" list.<br /> A \"+\" sign to the right of the message title indicates that you have replied to the message.</small>";
}else{
echo "<br /><em>There are no currently no messages in the in-box <br />(or, none meet the requirements of the applied filter).</em><br /><br />";
}
}
// send a new message to a user
elseif($action==compose
) {
$subject2=
$_GET[subject
];
echo "<em>Compose a message....</em>";
echo "<table width='675'><tr><td>";
echo "<form name='myform' action=".
$link.
"&action=compose2 method='post'>";
echo "<table>";
echo "<tr><td>Subject:</td><td><input type='text' name='subject' maxlength='65' size='30' value='$subject2'></td></tr>";
echo "<tr><td>To:</td><td><input type='text' name='to' maxlength='65' size='30' value='$to'></td></tr>";
echo "<tr><td>Message:</td><td><textarea rows='16' cols='45' name='message' onKeyDown=\"textCounter(this.form.message,this.form.remLen,2000);\" onKeyUp=\"textCounter(this.form.message,this.form.remLen,2000);\"></textarea><br /><input readonly type='text' name='remLen' size='4' maxlength='4' value='2000'> characters left.</td></tr>";
echo "<tr><td><button type='submit'>Send Mail!</button></td><td align='right'>Urgent? <INPUT TYPE='checkbox' NAME='urgent' VALUE='1'></td></tr>";
echo "<tr><td></td><td><small>All fields must have content.</small></td></tr></table>";
echo "</form>";
echo "</td><td width='200' valign='top'>";
echo "<strong>Contact List<br /></strong><small>(click on name to add to form)</small><br />";
$cntctresult =
mysql_query("SELECT info FROM ".
$this->
config["table_prefix"].
"mailinfo WHERE type='contact' and owner='$username' ORDER BY info ASC");
while ($row=
mysql_fetch_array($cntctresult)) {
echo "<a href=".
$link.
"&action=compose&to=".urlencode
($row[info
]).
">".
$row['info'].
"</a><br />";
}
echo "</td></tr></table>";
}
// send a reply to message sender
elseif($action==reply
) {
$subject2=
$_GET[subject
];
echo "<em>Reply to the message....</em>";
echo "<table width='400'><tr><td>";
echo "<form name='myform' action=".
$link.
"&action=compose2&replyto=".
$msg_id.
" method='post'>";
echo "<tr><td>Subject:</td><td><input readonly type='text' name='subject' maxlength='65' size='30' value='$subject2'></td></tr>";
echo "<tr><td>To:</td><td><input readonly type='text' name='to' maxlength='65' size='30' value='$to'></td></tr>";
$result=
mysql_query("SELECT * from ".
$this->
config["table_prefix"].
"mail WHERE UserTo='$username' AND mail_id=$mail_id") or
die ("cant do it");
$rowreply=
mysql_fetch_array($result);
$origmsg=
" \n \n++++++++++ Original Message ++++++++++\n".strip_tags
($rowreply[Message
]).
"\n+++++++++++++++++++++++++++++++++";
echo "<tr><td>Message:</td><td><textarea rows='16' cols='45' name='message' onKeyDown=\"textCounter(this.form.message,this.form.remLen,2000);\" onKeyUp=\"textCounter(this.form.message,this.form.remLen,2000);\">".
$origmsg.
"</textarea><br /><input readonly type='text' name='remLen' size='4' maxlength='4' value='2000'> characters left.</td></tr>";
echo "<tr><td><button type='submit'>Send Mail!</button></td><td align='right'>Urgent? <INPUT TYPE='checkbox' NAME='urgent' VALUE='1'></td></tr>";
echo "<tr><td></td><td><small>All fields must have content.</small></td></tr></table>";
echo "</form>";
}
// send a forwarded message
elseif($action==forward &&
$mail_id!=
"") {
$username =
$this->
GetUserName();
echo "<em>Add a message to the forwarded message....</em>";
echo "<table width='675'><tr><td>";
echo "<form name='myform' action=".
$link.
"&action=compose2 method='post'>";
echo "<table>";
$subject2 =
"FWD: ".
$subject;
echo "<tr><td>Subject:</td><td><input type='text' name='subject' maxlength='65' size='30' value='$subject2'></td></tr>";
echo "<tr><td>To:</td><td><input type='text' name='to' maxlength='65' size='30' value='$to'></td></tr>";
$result=
mysql_query("SELECT * from ".
$this->
config["table_prefix"].
"mail WHERE UserTo='$username' AND mail_id=$mail_id") or
die ("cant do it");
$rowfwd=
mysql_fetch_array($result);
$origmsg=
" \n \n++++++++++++ Forward ++++++++++++++\n".strip_tags
($rowfwd[Message
]).
"\n+++++++++++++++++++++++++++++++++";
echo "<tr><td>Message:</td><td><textarea rows='16' cols='45' name='message' onKeyDown=\"textCounter(this.form.message,this.form.remLen,2500);\" onKeyUp=\"textCounter(this.form.message,this.form.remLen,2500);\">$origmsg</textarea><br /><input readonly type='text' name='remLen' size='4' maxlength='4' value='2500'> characters left.</td></tr>";
echo "<tr><td><button type=submit>Send Mail!</button></td><td align='right'>Urgent? <INPUT TYPE='checkbox' NAME='urgent' VALUE='1'></td></tr>";
echo "<tr><td></td><td><small>All fields must have content.</small></td></tr></table>";
echo "</form>";
echo "</td><td width='200' valign='top'>";
echo "<strong>Contact List<br /></strong><small>(click on name to add to form)</small><br />";
$cntctresult =
mysql_query("SELECT info FROM ".
$this->
config["table_prefix"].
"mailinfo WHERE type='contact' and owner='$username' ORDER BY info ASC");
while ($row=
mysql_fetch_array($cntctresult)) {
echo "<a href=".
$link.
"&action=forward&to=$row[info]&mail_id=$mail_id&subject=".urlencode
($subject).
">".
$row['info'].
"</a><br />";
}
echo "</td></tr></table>";
}
// enters message from compose window (original or forward) into the database
if($action==compose2
) {
if ($user =
$this->
GetUser()){
$urgent=
$_POST['urgent'];
$to=
$_POST['to'];
$to=
addslashes($to);
$subject=
$_POST['subject'];
$subject=
addslashes($subject);
$message=
$_POST['message'];
$message=
strip_tags($message);
$message=
addslashes($message);
$replyto=
$_GET['replyto'];
$date =
date(YmdHis
);
// check if user exists & if so sends message
if($subject==
"" ||
$message==
"" ||
$to==
""){
echo "One of the fields was left blank.";
}else{
if($this->
LoadUser($to)) {
$create =
"INSERT INTO ".
$this->
config["table_prefix"].
"mail (UserTo, folder, UserFrom, Subject, Message, DateSent, status, urgent)
VALUES ('$to','inbox','$username','$subject','$message','$date','unread','$urgent')";
$create2 =
mysql_query($create) or
die("A letter could not be sent to $to!");
echo("Message Sent to $to!<br /><br /><br /><br /><br /><br /><br />");
//to set the database so that the message has been replied to
mysql_query("UPDATE ".
$this->
config["table_prefix"].
"mail SET repliedto='1' WHERE mail_id='$replyto' AND UserTo='$username'");
} else {
echo "The recipient name entered was not a registered user. <br />You might check the upper/lower case of the spelling.";
}
}
}else{
echo "<br />You must be both <strong>registered</strong> <u>and</u> <strong>logged</strong> in to use this Private Messaging System.<br />";
}
}
// show sent box
elseif($action==
'sent') {
$query=
"SELECT * from ".
$this->
config["table_prefix"].
"mail where UserFrom='$username' ORDER BY DateSent DESC";
$result=
mysql_query($query) or
die ("cant do it");
echo "<table cellpadding='2' cellspacing='3' width='750' valign='top'>";
//needed for pagination of sent box
$record_per_page=
12;
$total_records=
mysql_num_rows($result);
$scroll=
3;
$page=
new Page
();
//creating new instance of Class Page
$link2=
$link.
"&action=sent";
$page->
set_page_data($link2,
$total_records,
$record_per_page,
$scroll,
true,true,
true);
$result=
mysql_query($page->
get_limit_query($query));
// to paginate the "sent" page messages
echo "<tr><td colspan='3' align='center'>";
if ($total_records>
$record_per_page) {echo $page->
get_page_nav();
}
echo "</td></tr>";
echo "<tr bgcolor=#dddddd>\n";
echo "<td width='400'> Message Topic:</td>\n";
echo "<td width='85'> Sent to:</td>\n";
echo "<td width='75'> Read?</td>\n";
echo "</tr>\n";
while ($row=
mysql_fetch_array($result)) {
$datetime=
date("dMy g:i a",
strtotime($row['DateSent']));
echo "<tr><td><a href=".
$link.
"&action=view2&mail_id=".
$row[mail_id
].
"&page=".
$pagenum.
">".strip_tags
($row[Subject
]).
"</a><small> (".
$datetime.
")</small></td><td>".
$this->
Format($row[UserTo
]).
"<small> [<a href=".
$link.
"&action=contacts&cntct=".
$row[UserTo
].
">-></a>]</small></td><td width=50> $row[status]<br></td></tr>";
}
echo "</table>";
echo "<small> Clicking on the right arrow indicator [->] will add the user's name to the \"contacts\" list.</small>";
}
// Code to show folders according to selection
elseif((($_REQUEST['whichfolder']!=
'') ||
($folder)) &&
($action!=view
)) {
if ($filter==
1) {$search=
"and fltr1='1' ";
} elseif ($filter==
2) {$search=
"and fltr2='1' ";
} elseif ($filter==
3) {$search=
"and fltr3='1' ";
} elseif ($filter==N
) {$search=
"and fltr1='0' and fltr2='0' and fltr3='0' ";
} else {$search=
"";
}
if ($_REQUEST['whichfolder']!=
'') {$showfolder =
$_REQUEST['whichfolder'];
} else {$showfolder=
$folder;
}
echo "<table cellpadding='2' cellspacing='3' width='850' valign='top'>";
echo "<tr bgcolor=#dddddd>\n";
echo "<td><table border='0' cellpadding='0' cellspacing='0' width='100%'><tr><td> Message Topic:</td><td align='right'>";
if ($filter==
1) {$red=
"<u>*</u>";
} else {$red=
"*";
}
if ($filter==
2) {$blue=
"<u>*</u>";
} else {$blue=
"*";
}
if ($filter==
3) {$green=
"<u>*</u>";
} else {$green=
"*";
}
if ($filter==
"N") {$none=
"<u>N</u>";
} else {$none=
"N";
}
echo "<a href=".
$link.
"&folder=".
$which.
"><strong>A</strong></a> <a href=".
$link.
"&fltr=N&folder=".
$which.
"><strong>".
$none.
"</strong></a> <a href=".
$link.
"&fltr=1&folder=".
$which.
"><font color='red'><strong>".
$red.
"</strong></font></a> <a href=".
$link.
"&fltr=2&folder=".
$which.
">";
echo "<font color='blue'><strong>".
$blue.
"</strong></font></a> <a href=".
$link.
"&fltr=3&folder=".
$which.
"><font color='green'><strong>".
$green.
"</strong></font></a></td></tr></table></td>\n";
echo "<td width='65'> Sender:</td>\n";
echo "<td width='155'> Move to Folder:</td>\n";
echo "<td> Delete:</td>\n";
echo "<td> <strong>+</strong>/<strong>-</strong></td>\n";
echo "</tr>\n";
$query=
"SELECT fltr1,fltr2,fltr3,mail_id FROM ".
$this->
config["table_prefix"].
"mail where UserTo='$username' ".
$search.
"and folder='$folder' and viewrecipient='Y' ORDER BY DateSent DESC";
$result=
mysql_query($query) or
die ("cant do it");
while ($row=
mysql_fetch_array($result)) {
// code to set filters in database
if (($fltrset) &&
($row[mail_id
]==
$msg_id)) {
// code to determine setting of filters on server
if ($row[fltr1
]!=
1) {$fltrvar1=
1;
} else {$fltrvar1=
0;
}
if ($row[fltr2
]!=
1) {$fltrvar2=
1;
} else {$fltrvar2=
0;
}
if ($row[fltr3
]!=
1) {$fltrvar3=
1;
} else {$fltrvar3=
0;
}
// code to set which filter is being set
if ($fltrset==
1) {$fltr=
"fltr1";
$set=
$fltrvar1;
} elseif ($fltrset==
2) {$fltr=
"fltr2";
$set=
$fltrvar2;
} elseif ($fltrset==
3) {$fltr=
"fltr3";
$set=
$fltrvar3;
}
mysql_query("UPDATE ".
$this->
config["table_prefix"].
"mail SET ".
$fltr.
"=".
$set.
" WHERE mail_id='$msg_id' AND UserTo='$username'");
}
}
$result=
mysql_query("SELECT * from ".
$this->
config["table_prefix"].
"mail where UserTo='$username' ".
$search.
"AND folder='$showfolder' ORDER BY DateSent DESC") or
die ("cant do it");
$numrows=
mysql_num_rows($result);
while ($row=
mysql_fetch_array($result)) {
$datetime=
date("dMy g:i a",
strtotime($row['DateSent']));
if ($row[status
]==
"unread") {$status=
"<a title='This message has not been read yet!'><font color=Red>*</font></a>";
} else {$status=
"";
}
if ($row[urgent
]==
"1") {$urgentmkr=
"<a title='This is an urgent message!'><font color=Red><strong>!</strong></font></a>";
} else {$urgentmkr=
"";
}
if ($row[repliedto
]==
"1") {$replied=
"<a title='You have replied to this message!'><font color='black'><strong>+</strong></black></a>";
} else {$replied=
" ";
}
echo "<tr><td>$status$urgentmkr <a href=".
$link.
"&action=view&mail_id=$row[mail_id]&folder=".
$which.
">".strip_tags
($row[Subject
]).
"</a>".
$replied.
"<small>(".
$datetime.
")</small>";
// put in asterisks if indicated to do so in database
if ($row[fltr1
]==
1) {echo "<font color='red'><strong>*</strong></font>";
} else {echo " ";
}
if ($row[fltr2
]==
1) {echo "<font color='blue'><strong>*</strong></font>";
} else {echo " ";
}
if ($row[fltr3
]==
1) {echo "<font color='green'><strong>*</strong></font>";
} else {echo " ";
}
echo "</td><td width=125>".
$this->
Format($row[UserFrom
]).
"<small> [<a href=".
$link.
"&action=contacts&cntct=".
$row[UserFrom
].
">-></a>]</small></td><td>";
// code to put in drop down box to move to a new folder
$str2 =
"SELECT DISTINCT info FROM ".
$this->
config["table_prefix"].
"mailinfo WHERE type='folder' and owner='$username' ORDER BY info ASC";
$resultdrop2 =
mysql_query($str2);
echo "<form method=post action=\"$link&mail_id=$row[mail_id]&folder=$which\"><select name=\"move2folder\">";
while ($row2 =
mysql_fetch_array($resultdrop2))
{
extract ($row2);
echo "<option value=\"$info\">$info</option>";
}
echo "</select><input type='submit' value='Move'></form>";
echo "</td><td> [<a href=\"javascript: if(confirm('Are you sure you want to delete this item?')){ window.self.location='".
$link.
"&action=delete&id=".
$row[mail_id
].
"' }\">Delete</a>]<br /></td>";
echo "</td><td> <a href=".
$link.
"&fltrset=1&mail_id=".
$row[mail_id
].
"&folder=".
$which.
"&fltr=".
$filter.
"><font color='red'><strong>*</strong></font></a>|<a href=".
$link.
"&fltrset=2&mail_id=".
$row[mail_id
].
"&folder=".
$which.
"&fltr=".
$filter.
"><font color='blue'><strong>*</strong></font></a>|<a href=".
$link.
"&fltrset=3&mail_id=".
$row[mail_id
].
"&folder=".
$which.
"&fltr=".
$filter.
"><font color='green'><strong>*</strong></font></a><br /></td></tr>";
}
echo "</table>";
if ($numrows==
0) {echo "<br /><em>There are no messages currently stored <br />in this folder (or, with this filter).</em><br /><br />";
}
}
// view individual email messages
elseif($action==view
) {
$result=
mysql_query("select * from ".
$this->
config["table_prefix"].
"mail where UserTo='$username' and mail_id=$msg_id") or
die ("cant do it");
$row=
mysql_fetch_array($result);
if (($fltrset) &&
($row[mail_id
]==
$msg_id)) {
// code to determine setting of filters on server
if ($row[fltr1
]!=
1) {$fltrvar1=
1;
} else {$fltrvar1=
0;
}
if ($row[fltr2
]!=
1) {$fltrvar2=
1;
} else {$fltrvar2=
0;
}
if ($row[fltr3
]!=
1) {$fltrvar3=
1;
} else {$fltrvar3=
0;
}
// code to set which filter is being set
if ($fltrset==
1) {$fltr=
"fltr1";
$set=
$fltrvar1;
} elseif ($fltrset==
2) {$fltr=
"fltr2";
$set=
$fltrvar2;
} elseif ($fltrset==
3) {$fltr=
"fltr3";
$set=
$fltrvar3;
}
mysql_query("UPDATE ".
$this->
config["table_prefix"].
"mail SET ".
$fltr.
"=".
$set.
" WHERE mail_id='$msg_id' AND UserTo='$username'");
}
$result=
mysql_query("select * from ".
$this->
config["table_prefix"].
"mail where UserTo='$username' and mail_id=$msg_id") or
die ("cant do it");
$row=
mysql_fetch_array($result);
$username=
strtolower($username);
$row[UserTo
]=
strtolower($row[UserTo
]);
if ($row[repliedto
]==
"1") {$replied=
"<a title='You have replied to this message at least once!'><font color='black'><small>replied to<small></black></a>";
} else {$replied=
" ";
}
// code to set filters in database
if($row[UserTo
]==
$username) {
$query=
"UPDATE ".
$this->
config["table_prefix"].
"mail SET status='read' WHERE UserTo='$username' AND mail_id='$row[mail_id]'";
$query or
die("An error occurred resulting that this message has not been marked read.");
$datetime=
date("dMy g:i a",
strtotime($row['DateSent']));
echo "<table border='1' bordercolor='#666699' width='600'><tr><td width='350'><strong>Subject: </strong>".strip_tags
($row[Subject
]).
" ";
// put in asterisks if indicated to do so in database
if ($row[fltr1
]==
1) {echo "<font color='red'><strong>*</strong></font>";
} else {echo " ";
}
if ($row[fltr2
]==
1) {echo "<font color='blue'><strong>*</strong></font>";
} else {echo " ";
}
if ($row[fltr3
]==
1) {echo "<font color='green'><strong>*</strong></font>";
} else {echo " ";
}
echo "</td><td>";
echo " <a href=".
$link.
"&action=view&fltrset=1&mail_id=".
$row[mail_id
].
" title='Mark message with a RED star.'><font color='red'><strong>*</strong></font></a>|<a href=".
$link.
"&action=view&fltrset=2&mail_id=".
$row[mail_id
].
" title='Mark message with a BLUE star.'><font color='blue'><strong>*</strong></font></a>|<a href=".
$link.
"&action=view&fltrset=3&mail_id=".
$row[mail_id
].
" title='Mark message with a GREEN star.'><strong>*</strong></font></a>";
echo "</td><td><strong>From: </strong>".
$this->
Format($row[UserFrom
]).
"<small> [<a href=".
$link.
"&action=contacts&cntct=".
$row[UserFrom
].
">-></a>]</small></td></tr>";
echo "<tr><td colspan='3'><strong>Message: </strong>".strip_tags
($row[Message
]).
"</td></tr><tr><td><a href=".
$link.
"&action=reply&to=".
$row[UserFrom
].
"&mail_id=".
$row[mail_id
].
"&subject=RE:".urlencode
($row[Subject
]).
">Reply</a> / <a href=".
$link.
"&action=forward&mail_id=$row[mail_id]&subject=RE:".urlencode
($row[Subject
]).
">Forward</a>";
echo " / <a href=\"javascript: if(confirm('Are you sure you want to delete this item?')){ window.self.location='".
$link.
"&action=delete&id=".
$mail_id.
"' }\">Delete</a></td><td>".
$replied.
"</td><td><small><strong>Sent:</strong> $datetime</small></td></tr></table><br />";
$rs =
mysql_query("UPDATE ".
$this->
config["table_prefix"].
"mail SET status='read' WHERE mail_id='$msg_id'");
} else {
echo "<font face=verdana><strong>This isn't your mail!";
}
echo "<small> Clicking on the right arrow indicator [->] will add the sender's name to the \"contacts\" list.</small>";
}
// added filter for viewing "folder sorted" mail
elseif($action==view2
) {
$result=
mysql_query("SELECT * from ".
$this->
config["table_prefix"].
"mail where UserFrom='$username' and mail_id='$msg_id'") or
die ("cant do it");
$row=
mysql_fetch_array($result);
$username=
strtolower($username);
$userfrom=
strtolower($row[UserFrom
]);
if($userfrom==
$username) {
$datetime=
date("dMy g:i a",
strtotime($row['DateSent']));
echo "<table border = '1' bordercolor = 'black' width = '600'><tr><td colspan='2' valign='top'><strong>Subject:</strong> ".strip_tags
($row[Subject
]).
"</td></tr><tr>";
echo "<td colspan='2'><strong>Recipient:</strong> ".
$this->
Format($row[UserTo
]).
"<small> [<a href=".
$link.
"&action=contacts&cntct=".
$row[UserTo
].
">-></a>]</small></td></tr><tr><td colspan='2'><strong>Message: </strong>$row[Message]</td></tr><tr><td colspan='2'><small><strong>Sent: </strong>".
$datetime.
"</small></td></tr></table>";
}
echo "<small> Clicking on the right arrow indicator [->] will add the sender's name to the \"contacts\" list.</small>";
}
// DELETE code for messages (now updates so that message is not visible instead of deleting)
elseif($action==delete
) {
$query=
"UPDATE ".
$this->
config["table_prefix"].
"mail SET viewrecipient='N' WHERE UserTo='$username' AND mail_id='$id'";
$query or
die("An error occurred resulting that this message has not been marked read.");
$rs =
mysql_query("UPDATE ".
$this->
config["table_prefix"].
"mail SET viewrecipient='N' WHERE mail_id='$id'");
if($query) {
echo "<font face=verdana>Message was deleted.<br /><br /><br /><br /><br /><br /><br /></font>";
} else {
echo "The message was not deleted.";
}
}
// code to manage contact list
elseif ($action==contacts
){
$addcontact=
$_GET['cntct'];
$table =
$this->
config[