Revision history for WikkaMail


Revision [19323]

Last edited on 2008-01-28 00:15:15 by BrianKoontz [Modified links pointing to docs server]

No Differences

Revision [17346]

Edited on 2007-08-06 10:51:02 by BrianKoontz [Removed dead links, added new mods]
Additions:
===Action to display number of new messages waiting===
Deletions:
===Action to display number of new message===


Revision [17345]

Edited on 2007-08-06 10:49:56 by BrianKoontz [Removed dead links, added new mods]
Additions:
===Action to display number of new message===
Deletions:
===Action to display number of new message


Revision [17344]

Edited on 2007-08-06 10:48:43 by BrianKoontz [Removed dead links, added new mods]
Additions:
extract ($row);
if($_REQUEST[whichfolder] == $info)
echo "<option value=\"$info\">$info</option>";
echo "<option value=\"$info\">$info</option>";
}
$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 />");
mysql_query("UPDATE ".$this->config["table_prefix"]."mail SET repliedto='1' WHERE mail_id='$replyto' AND UserTo='$username'");
echo "The recipient name entered was not a registered user. <br />You might check the upper/lower case of the spelling.";
extract ($row2);
echo "<option value=\"$info\">$info</option>";
echo "Error #".mysql_errno(). " (".mysql_error(). ")<br>";
echo "<td>".strip_tags($row[3])."</td>\n";
echo "<td>".strip_tags($row[3])."</td>\n";
===Action to display number of new message
// This newmail.php (Version 0.1a) is an addon to mail.php. Released under GPL.
// Use: {{newmail}} (no parameters). Needs: Needs: MySQL database tables (2).
$pagename = $this->MiniHref($method, $tag);
$link = $this->config["base_url"].$this->MiniHref($method, $tag);
$username = $this->GetUserName();
$query="SELECT * FROM ".$this->config["table_prefix"]."mail where UserTo='".$username."' and status='unread'";
$result=mysql_query($query) or die ("cant do it");
$num_rows = mysql_num_rows($result);
echo "(".$num_rows.")";
I've then put this action in my wikka.config.php on the logged_in_navigation_links;
:: {{image alt="Private Messages" title="Private Messages" url="images/email.gif" link="PrivateMessages"}} {{newmail}} ::
--DaveFullard
Deletions:
extract ($row);
if($_REQUEST[whichfolder] == $info)
echo "<option value=\"$info\">$info</option>";
echo "<option value=\"$info\">$info</option>";
}
$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 />");
mysql_query("UPDATE ".$this->config["table_prefix"]."mail SET repliedto='1' WHERE mail_id='$replyto' AND UserTo='$username'");
echo "The recipient name entered was not a registered user. <br />You might check the upper/lower case of the spelling.";
}
extract ($row2);
echo "<option value=\"$info\">$info</option>";
echo "Error #".mysql_errno(). " (".mysql_error(). ")<br>";
echo "<td>".strip_tags($row[3])."</td>\n";
echo "<td>".strip_tags($row[3])."</td>\n";
This is the inbox (note the * indicator in the header that there is unread mail, + indicator for answered mail, and the marker/filter system)...
http://gmbowen.educ.unb.ca/wikitest/pms1.jpg
This is the "compose" box (note the contact list...clicking on a name enters it into the "to" box)...
http://gmbowen.educ.unb.ca/wikitest/pms2.jpg
This is a listing of "sent" files (note the indicator of whether they'd been read or not)...
http://gmbowen.educ.unb.ca/wikitest/pms3.jpg
This is the contents of a folder...
http://gmbowen.educ.unb.ca/wikitest/pms4.jpg
This is a listing of the contacts & where they are managed...
http://gmbowen.educ.unb.ca/wikitest/pms5.jpg
This is a list of the registered users....
http://gmbowen.educ.unb.ca/wikitest/pms6.jpg
This is a listing of the folders & where they are managed....
http://gmbowen.educ.unb.ca/wikitest/pms7.jpg
This is an example message...
http://gmbowen.educ.unb.ca/wikitest/pms8.jpg
This demonstrates a "compose" form after "forward" has been clicked....
http://gmbowen.educ.unb.ca/wikitest/pms9.jpg
This image is a "reply" message (you cannot change the "to" or the "subject" block)
http://gmbowen.educ.unb.ca/wikitest/pms10.jpg


Revision [5910]

Edited on 2005-02-11 16:01:22 by GmBowen [minor code update to address upper case characters]
Additions:
====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.
%%(sql)
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)
<?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["table_prefix"]."mailinfo";
$field1 = "info";
$field1_label = "Contact Names";
$field2 = "notes";
$field2_label = "Notes";
$deletecnt = $_GET['deletecnt'];
$field1_value=$_POST['field1_value'];
if ($field1_value) {$insert="1";} else {$insert="";}
$field2_value=$_POST['field2_value'];
$category="contact";

if ($user = $this->GetUser()){
if ($insert) {
if($this->LoadUser($field1_value)) {
mysql_query( "INSERT into $table ($field1, $field2, owner, type) values (\"$field1_value\",\"$field2_value\",\"$username\",\"$category\")");
}
}
if ($deletecnt) {
mysql_query( "DELETE from $table WHERE id=$deletecnt AND owner='$username'");
}
if (mysql_errno()!=0) {
switch (mysql_errno()) {
default:
echo "Error #".mysql_errno(). " (".mysql_error(). ")<br>";
}
}
}
$query = "SELECT * from $table WHERE owner='$username' AND type='$category' ORDER BY info ASC";
$result = mysql_query($query);
$rows = mysql_num_rows($result);
echo "<strong><em>Contact Management</em></strong>";
echo "<table border='1' cellspacing='0'>\n";
echo "<tr>\n";
echo "<td><strong>$field1_label</strong></td>\n";
echo "<td><strong>$field2_label</strong></td>\n";
echo "<td> </td>\n";
echo "</tr>\n";
// This is the entry boxes
echo "<form action=\"$link&action=contacts\" method=\"post\">\n";
echo "<tr>\n";
echo "<input type='hidden' name='insert' value='1'></td>\n";
echo "<td><input type='text' size='20' maxlength='65' name='field1_value' value='$addcontact'></td>\n";
echo "<td><input type='text' size='35' maxlength='65' name='field2_value'></td>\n";
echo "<td colspan=2 align=center>";
echo "<input type='submit' value=\" Add \"></td>\n";
echo "</tr>\n";
echo "</form>\n";
// This is the data under the entry boxes
while ($row = mysql_fetch_row($result)) {
echo "<tr>\n";
echo "<td><a href=".$link."&action=compose&to=".$row[2].">".$row[2]."</a><small>  [<a href=".$this->config["base_url"].$row[2].">Home Page</a>]</small></td>\n";
echo "<td>".strip_tags($row[3])."</td>\n";
echo "<td><a href=\"javascript: if(confirm('Are you sure you want to delete this item?')){ window.self.location='".$link."&action=contacts&deletecnt=".$row[4]."' }\"><center>Delete</center></a></td>\n";
echo "</tr>\n";
}
echo "</table>";
echo "<small>Clicking on the contact name will take you to message entry screen.</small>";
}

// code to manage folder list
elseif ($action==folders){
$table = $this->config["table_prefix"]."mailinfo";
$field1 = "info";
$field1_label = "Folder List";
$field2 = "notes";
$field2_label = "Notes";
$deletefldr = $_GET['deletefldr'];
$fldr = $_GET['fldr'];
$field1_value=$_POST['field1_value'];
if ($field1_value) {$insert="1";} else {$insert="";}
$field2_value=$_POST['field2_value'];
$category="folder";

if ($user = $this->GetUser()){
if ($insert) {
mysql_query( "INSERT into $table ($field1, $field2, owner, type) values (\"$field1_value\",\"$field2_value\",\"$username\",\"$category\")");
}

if ($deletefldr) {
// delete folder name from mailinfo
mysql_query("DELETE from $table WHERE id='$deletefldr' AND owner='$username' AND type='folder'");
// change files from being stored in folder being deleted to being stored in inbox
mysql_query("UPDATE ".$this->config["table_prefix"]."mail SET folder='inbox' WHERE folder='$fldr' AND UserTo='$username'");
}

if (mysql_errno()!=0) {
switch (mysql_errno()) {
default:
echo "Error #".mysql_errno(). " (".mysql_error(). ")<br>";
}
}
}
$query = "SELECT * from $table WHERE owner='$username' AND type='$category' ORDER BY info ASC";
$result = mysql_query($query);
$rows = mysql_num_rows($result);
echo "<strong><em>Folder Management</em></strong>";
echo "<table border='1' cellspacing='0'>\n";
echo "<tr>\n";
echo "<td><strong>$field1_label</strong></td>\n";
echo "<td><strong>$field2_label</strong></td>\n";
echo "<td> </td>\n";
echo "</tr>\n";

// This is the entry boxes
echo "<form action=\"$link&action=folders\" method=\"post\">\n";
echo "<tr>\n";
echo "<input type='hidden' name='insert' value='1'></td>\n";
echo "<td><input type='text' size='25' maxlength='65' name='field1_value'></td>\n";
echo "<td><input type='text' size='35' maxlength='65' name='field2_value'></td>\n";
echo "<td colspan='2' align='center'>";
echo "<input type='submit' value=\" Add \"></td>\n";
echo "</tr>\n";
echo "</form>\n";
// This is the data under the entry boxes
while ($row = mysql_fetch_row($result)) {
echo "<tr>\n";
echo "<td><a href=".$link."&folder=".strip_tags($row[2]).">".strip_tags($row[2])."</a></td>\n";
echo "<td>".strip_tags($row[3])."</td>\n";
echo "<td><a href=\"javascript: if(confirm('Are you sure you want to delete this item?')){ window.self.location='".$link."&action=folders&deletefldr=".$row[4]."&fldr=".$row[2]."' }\">
<center>Delete</center></a></td>\n";
}
echo "</table>";
echo "<small>Clicking on the folder name will take you to that folder.</small>";
}

// code to display user list
elseif ($action==users){
echo "<table width='650'><tr><td>";
$last_users = $this->LoadAll("select name from ".$this->config["table_prefix"]."users order by name ASC");
echo "<strong><em>User List.</em></strong> Click on the name to add it to the contact list.<br />";
foreach($last_users as $user)
{
echo "<a href=".$link."&action=contacts&cntct=".$user["name"].">".$user["name"]."</a> ";
}
echo "</td></tr></table>";
}

//code to show brief instructions for using filters
elseif ($action==help){
echo "<table width='700'><tr><td>";
echo "<p><strong>An introduction to sending messages in Wikka...</strong></p>";
echo "There are two brief parts to this help file. The first is how to interpret the output screen. The second is a description of how filters work.<br /><br />";
echo "     <strong><em>Introduction to the output...</em></strong><br /><br />";
echo "Below is a typical output line in the In-Box, Folder lists or the Sent message area.<br /><br />";
echo "<table border='0' width='800'>";
echo "<tr><td valign='middle'>";
echo "<P> <font color='#FF0000'><strong>!* </strong></font><A>Science Class tomorrow</A><font color='#000000'><strong><a title='You have answered this email.'> </a></strong><small>(05Feb05 2:08 pm)</small></font><font color='#FF0000'><strong>*</strong></font><font color='#000000'>  </font><font color='#008000'><strong>*</strong></font></P>";
echo "</td><td align='center' width='140' valign='middle'>";
echo "<P><a title='Sender'>GmBowen</a><small> [<a title='Put into contact list.'>-></a>]</small></P>";
echo "</td>";
echo "<td width='150' valign='middle'>";
echo "<P><form>";
echo "<P><select name=move2folder>";
echo "<option value=ColeBowen>ColeBowen";
echo "<option value=GmBowen>GmBowen";
echo "<option value=Personal>Personal";
echo "<option value=Work>Work";
echo "</select><input type='button' name='Submit' value='Move'>";
echo "</form></P>";
echo "</td>";
echo "<td align='center' valign='middle' width='60'>";
echo "<P align='center'>[<a>Delete</a>]</P>";
echo "</td>";
echo "<td width='53'>";
echo "<P> <A title='Mark message with a RED star.'></A><font color='#FF0000'><strong>*</strong></font>|<A title='Mark message with a BLUE star.'></A><font color='#0000FF'><strong>*</strong></font>|<A title='Mark message with a GREEN star.'></A><font color='#008000'><strong>*</strong></font><BR>";
echo "</P>";
echo "</td>";
echo "</tr>";
echo "</table>";
echo "</font><font color='#000000'><br />Here is how to interpret the output....</font></P>";
echo "<UL>";
echo "<LI><font color='#000000'>The exclamation mark (</font><font color='#FF0000'><strong>!</strong></font><font color='#000000'>) tells you that the sender marked the message <strong>urgent</strong>.</font></LI>";
echo "<LI><font color='#000000'>The first red star (</font><font color='#FF0000'>*</font><font color='#000000'>) tells you that you have not read the message yet. </font></LI>";
echo "<LI><font color='#000000'>'Science Class tomorrow' is the topic of the message.</font></LI>";
echo "<LI><font color='#000000'>If there were a plus sign (<strong>+</strong>) immediately after the topic you would know that you had replied to the message. </font></LI>";
echo "<LI><font color='#000000'>The date/time after the message lets you know when the message was sent. </font></LI>";
echo "<LI><font color='#000000'>The coloured stars after the date/time (</font><font color='#FF0000'>* </font><font color='#000000'> </font><font color='#00FF00'>*</font><font color='#000000'>) indicate that you've applied those two markers to your message (see below). </font></LI>";
echo "<LI><font color='#000000'>'GmBowen' is the sender of the message.</font></LI>";
echo "<LI><font color='#000000'>The [->] allows you to put the senders name into your contact list. </font></LI>";
echo "<LI><font color='#000000'>The dropdown menu (starting with 'ColeBowen') is a list of folders that you can file the message into. </font></LI>";
echo "<LI><font color='#000000'>The [</font><font color='#0000FF'>Delete</font><font color='#000000'>] button allows you to delete the message (even though it does stay in the database). </font></LI>";
echo "<LI><font color='#000000'>Clicking on the three coloured stars (</font><font color='#FF0000'>*</font><font color='#000000'>|</font><font color='#0000FF'>*</font><font color='#000000'>|</font><font color='#00CC00'>*</font><font color='#000000'>) allow you to set markers on your messages.</font></LI>";
echo "</UL>";
echo "<br /><br />";
echo "     <strong><em>Introduction to filters...</em></strong><br /><br />";
echo "<P>'Filters' are a simple-to-use tool that can help you organize your\n";
echo "messages.</P>\n";
echo "\n";
echo "<P>When you're in the in-box or any of the folders, on the top right\n";
echo "of the title bar you'll see a +/- with\n";
echo "<font color='#FF0000'>*</font>|<font color='#0000FF'>*</font>|<font color='#008000'>*\n";
echo "</font>underneath it (and to the right of each message). By clicking\n";
echo "on these three coloured stars you can place or remove coloured stars\n";
echo "from beside the message title. A similar feature is found inside each\n";
echo "individual message box (seen when you're reading your messages).</P>\n";
echo "\n";
echo "<P>The different colours can mean anything you want them to. Red\n";
echo "might mean 'really important' and green might mean 'Ignore for now'.\n";
echo "It's really up to you. They can mean different things to you in your\n";
echo "in-box versus your different folders as well</P>\n";
echo "\n";
echo "<P><table>\n";
echo "<tr bgcolor='#DDDDDD'>\n";
echo "<td width='400'>\n";
echo "<P><table border='0' cellspacing='0' cellpadding='0' width='100%'>\n";
echo "<tr>\n";
echo "<td>\n";
echo "<P> Message Topic:</P>\n";
echo "</td>\n";
echo "<td align=right>\n";
echo "<P><strong>A</strong> <strong>N</strong> <font color='#FF0000'><strong>*</strong></font> <font color='#0000FF'><strong>*</strong></font> <strong>*</strong></P>\n";
echo "</td>\n";
echo "</tr>\n";
echo "</table>\n";
echo "</P>\n";
echo "</td>\n";
echo "<td width='85'>\n";
echo "<P> Sender:</P>\n";
echo "</td>\n";
echo "<td width='155'>\n";
echo "<P> Move to Folder:</P>\n";
echo "</td>\n";
echo "<td>\n";
echo "<P> Delete:</P>\n";
echo "</td>\n";
echo "<td width='45'>\n";
echo "<P>  <strong>+</strong>/<strong>-</strong></P>\n";
echo "</td>\n";
echo "</tr>\n";
echo "</table>\n";
echo "</P>\n";
echo "\n";
echo "<P>On the grey title bar to the right of 'Message Topic:' you can see\n";
echo " <strong>A</strong> <strong>N</strong> \n";
echo "<font color='#FF0000'>*</font> <font color='#0000FF'>*</font> <font color='#008000'>*</font></P>\n";
echo "\n";
echo "<P>By clicking on the '<strong>A</strong>' you'll see all of the messages,\n";
echo "on the '<strong>N</strong>' you'll see the messages that don't have any markers\n";
echo "beside them, and if you click on any of the coloured stars you'll see\n";
echo "the messages that have those coloured markers beside them.</P>\n";
echo "\n";
echo "<P>Easy eh? </P>\n";
echo "</td></tr></table>";
}
?>
%%

The following file should be saved as ##page.inc.php## in a directory called ##scripts## in the wikka root....
%%(php)
<?php


/*
###############################################
#### ####
#### Author : Harish Chauhan ####
#### Date : 27 Sep,2004 ####
#### Updated: ####
#### ####
###############################################

*/
// Original class script obtained from http://www.phpclasses.org/browse/package/2012.html distributed as "Freeware"
// Modifications (Ver 1.0b) by GmBowen so that script useable with wikka wiki to support a "mail" action developed for the wiki.
// Throughout this class "?page" was changed to "&page" as well as other minor modifications throughout the script.

class Page
{
var $total_records=1; ///Total Records returned by sql query
var $records_per_page=1; ///how many records would be displayed at a time
var $page_name=""; ///page name on which the class is called
var $start=0;
var $page=0;
var $total_page=0;
var $current_page;
var $remain_page;
var $show_prev_next=true;
var $show_scroll_prev_next=false;
var $show_first_last=false;
var $show_disabled_links=true;
var $scroll_page=0;
var $qry_str="";
var $link_para="&";

/* returns boolean value if it is last page or not*/
function is_last_page()
{
return $this->page>=$this->total_page-1?true:false;
}
/* param : Void
returns boolean value if it is first page or not*/
function is_first_page()
{
return $this->page==0?true:false;
}
function current_page()
{
return $this->page+1;
}
function total_page()
{
return $this->total_page==0?1:$this->total_page;
}

//@param : $show = if you want to show disabled links on navigation links.
//
function show_disabled_links($show=TRUE)
{
$this->show_disabled_links=$show;
}
//@param : $link_para = if you want to pass any parameter to link
//
function set_link_parameter($link_para)
{
$this->link_para=$link_para;
}
function set_page_name($page_name)
{
$this->page_name=$page_name;
}
//@param : str= query string you want to pass to links.
function set_qry_string($str="")
{
$this->qry_str="&".$str;
}
function set_scroll_page($scroll_num=0)
{
if($scroll_num!=0)
$this->scroll_page=$scroll_num;
else
$this->scroll_page=$this->total_records;

}
function set_total_records($total_records)
{
if($total_records<0)
$total_records=0;
$this->total_records=$total_records;
}
function set_records_per_page($records_per_page)
{
if($records_per_page<=0)
$records_per_page=$this->total_records;
$this->records_per_page=$records_per_page;
}
/* @params
* $page_name = Page name on which class is integrated. i.e. $_SERVER['PHP_SELF']
* $total_records=Total records returnd by sql query.
* $records_per_page=How many projects would be displayed at a time
* $scroll_num= How many pages scrolled if we click on scroll page link.
* i.e if we want to scroll 6 pages at a time then pass argument 6.
* $show_prev_next= boolean(true/false) to show prev Next Link
* $show_scroll_prev_next= boolean(true/false) to show scrolled prev Next Link
* $show_first_last= boolean(true/false) to show first last Link to move first and last page.
*/

function set_page_data($page_name,$total_records,$records_per_page=1,$scroll_num=0,$show_prev_next=true,$show_scroll_prev_next=false,$show_first_last=false)
{
$this->set_total_records($total_records);
$this->set_records_per_page($records_per_page);
$this->set_scroll_page($scroll_num);
$this->set_page_name($page_name);
$this->show_prev_next=$show_prev_next;
$this->show_scroll_prev_next=$show_scroll_prev_next;
$this->show_first_last=$show_first_last;
}
/* @params
* $user_link= if you want to display your link i.e if you want to user '>>' instead of [first] link then use
Page::get_first_page_nav(">>") OR for image
Page::get_first_page_nav("<img src='' alt='first'>")
$link_para: link parameters i.e if you want ot use another parameters such as class.
Page::get_first_page_nav(">>","class=myStyleSheetClass")
*/
function get_first_page_nav($user_link="",$link_para="")
{
if($this->total_page<=1)
return;
if(trim($user_link)=="")
$user_link="««  ";
if(!$this->is_first_page()&& $this->show_first_last)
echo ' <a href="'.$this->page_name.'&page=0'.$this->qry_str.'" '.$link_para.'>'.$user_link.'</a> ';
elseif($this->show_first_last && $this->show_disabled_links)
echo $user_link;
}
function get_last_page_nav($user_link="",$link_para="")
{
if($this->total_page<=1)
return;
if(trim($user_link)=="")
$user_link="  Â»Â»";
if(!$this->is_last_page()&& $this->show_first_last)
echo ' <a href="'.$this->page_name.'&page='.($this->total_page-1).$this->qry_str.'" '.$link_para.'>'.$user_link.'</a> ';
elseif($this->show_first_last && $this->show_disabled_links)
echo $user_link;
}
function get_next_page_nav($user_link="",$link_para="")
{
if($this->total_page<=1)
return;
if(trim($user_link)=="")
$user_link=" »";
if(!$this->is_last_page()&& $this->show_prev_next)
echo ' <a href="'.$this->page_name.'&page='.($this->page+1).$this->qry_str.'" '.$link_para.'>'.$user_link.'</a> ';
elseif($this->show_prev_next && $this->show_disabled_links)
echo $user_link." ";
}
function get_prev_page_nav($user_link="",$link_para="")
{
if($this->total_page<=1)
return;
if(trim($user_link)=="")
$user_link="« ";
if(!$this->is_first_page()&& $this->show_prev_next)
echo ' <a href="'.$this->page_name.'&page='.($this->page-1).$this->qry_str.'" '.$link_para.'>'.$user_link.'</a> ';
elseif($this->show_prev_next && $this->show_disabled_links)
echo " ".$user_link;
}
function get_scroll_prev_page_nav($user_link="",$link_para="")
{

if($this->scroll_page>=$this->total_page)
return;
if(trim($user_link)=="")
$user_link="[-$this->scroll_page]";
if($this->page>$this->scroll_page &&$this->show_scroll_prev_next)
echo ' <a href="'.$this->page_name.'&page='.($this->page-$this->scroll_page).$this->qry_str.'" '.$link_para.'>'.$user_link.'</a> ';
elseif($this->show_scroll_prev_next && $this->show_disabled_links)
echo $user_link;
}
function get_scroll_next_page_nav($user_link="",$link_para="")
{
if($this->scroll_page>=$this->total_page)
return;
if(trim($user_link)=="")
$user_link="[+$this->scroll_page]";
if($this->total_page>$this->page+$this->scroll_page &&$this->show_scroll_prev_next)
echo ' <a href="'.$this->page_name.'&page='.($this->page+$this->scroll_page).$this->qry_str.'" '.$link_para.'>'.$user_link.'</a> ';
elseif($this->show_scroll_prev_next && $this->show_disabled_links)
echo $user_link;
}

function get_number_page_nav($link_para="")
{
$j=0;
$scroll_page=$this->scroll_page;
if($this->page>($scroll_page/2))
$j=$this->page-intval($scroll_page/2);
if($j+$scroll_page>$this->total_page)
$j=$this->total_page-$scroll_page;

if($j<0)
$i=0;
else
$i=$j;

for(;$i<$j+$scroll_page && $i<$this->total_records;$i++)
{
if($i==$this->page)
echo ($i+1);
else
echo ' <a href="'.$this->page_name.'&page='.$i.$this->qry_str.'" '.$link_para.'>'.($i+1).'</a> ';
}
}

function get_page_nav()
{
if($this->total_records<=0)
{
//echo "No Records Found";
// return false;
}
$this->calculate();
$this->get_first_page_nav("",$this->link_para);
$this->get_scroll_prev_page_nav("",$this->link_para);
$this->get_prev_page_nav("",$this->link_para);
$this->get_number_page_nav($this->link_para);
$this->get_next_page_nav("",$this->link_para);
$this->get_scroll_next_page_nav("",$this->link_para);
$this->get_last_page_nav("",$this->link_para);
// return true;
}
function calculate()
{
$this->page=$_REQUEST['page'];
if(!is_numeric($this->page))
$this->page=0;
$this->start=$this->page*$this->records_per_page;
$this->total_page=@intval($this->total_records/$this->records_per_page);
if($this->total_records%$this->records_per_page!=0)
$this->total_page++;
}
function get_limit_query($qry="")
{
$this->calculate();
return $qry." LIMIT $this->start,$this->records_per_page";
}
}
?>
%%

This is the inbox (note the * indicator in the header that there is unread mail, + indicator for answered mail, and the marker/filter system)...

http://gmbowen.educ.unb.ca/wikitest/pms1.jpg

This is the "compose" box (note the contact list...clicking on a name enters it into the "to" box)...

http://gmbowen.educ.unb.ca/wikitest/pms2.jpg

This is a listing of "sent" files (note the indicator of whether they'd been read or not)...

http://gmbowen.educ.unb.ca/wikitest/pms3.jpg

This is the contents of a folder...

http://gmbowen.educ.unb.ca/wikitest/pms4.jpg

This is a listing of the contacts & where they are managed...

http://gmbowen.educ.unb.ca/wikitest/pms5.jpg

This is a list of the registered users....

http://gmbowen.educ.unb.ca/wikitest/pms6.jpg

This is a listing of the folders & where they are managed....

http://gmbowen.educ.unb.ca/wikitest/pms7.jpg

This is an example message...

http://gmbowen.educ.unb.ca/wikitest/pms8.jpg

This demonstrates a "compose" form after "forward" has been clicked....

http://gmbowen.educ.unb.ca/wikitest/pms9.jpg

This image is a "reply" message (you cannot change the "to" or the "subject" block)

http://gmbowen.educ.unb.ca/wikitest/pms10.jpg

----
**To upgrade your mail.php from version 1.0 to 1.5 do the following.....**

1) Use the following mysql statements (in your fvaourite mysql administration program, or at the command line if you know how) to update the table structure in your wikki database. Make sure you change "WAKKAPREFIX" to the prefix you use in your wikka.

ALTER TABLE `WAKKAPREFIX_mail`
ADD `repliedto` TINYINT (1) DEFAULT '0' AFTER `Message` ,
ADD `urgent` TINYINT (1) DEFAULT NULL AFTER `repliedto` ,
ADD `fltr1` TINYINT (1) DEFAULT '0' NOT NULL AFTER `urgent` ,
ADD `fltr2` TINYINT (1) DEFAULT '0' NOT NULL AFTER `fltr1` ,
ADD `fltr3` TINYINT (1) DEFAULT '0' NOT NULL AFTER `fltr2` ,
ADD `DateSent` DATETIME NOT NULL AFTER `fltr3`

2) THEN RUN THE PHP SCRIPT mailupdate.php as an ACTION (you can only do this as a designated administrator). Save the php code below as mailupdate.php, insert on a page, and then click on the visible link. This will alter the date code from a text string to a mysql DATETIME string (makes it easier to display date & time).

%%(php)
if ($this->IsAdmin()) {
$link = $this->config["base_url"].$this->MiniHref($method, $tag);
echo "<a href=".$link."&action=update>Update database for mail.php from version 1.0 to version 1.5</a>";
$action=$_GET['action'];
if($action==update){
$query="SELECT SentDate,DateSent FROM ".$this->config["table_prefix"]."mail";
$result=mysql_query($query) or die ("cant do it");
while ($row=mysql_fetch_array($result)) {
$newdate=$row[SentDate];
mysql_query("UPDATE ".$this->config["table_prefix"]."mail SET DateSent=$newdate WHERE SentDate=$newdate");
}
if ($_GET['action']) {echo "Database update complete.";}
}
}
%%

Erase the update file from you actions directory.

3) Then install the new mail.php file. (erase the old one, replace with the new one.) You may or may want to put your wiki into "administrative mode" so that others cannot use it while you do this. (See these [[http://wikka.jsnx.com/UpgradeNotes notes]] for upgrading wikka.)

4) Finally, remove the ""SentDate"" field from the mysql table WAKKAPREFIX_mail using the following command. (Make sure you change "WAKKAPREFIX" to the prefix you use in your wikka.)

ALTER TABLE `WAKKAPREFIX_mail` DROP `SentDate`

That's it. This upgrade sequence has been tested on two sites and worked without a problem.

----
Deletions:
====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.
%%(sql)
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)
<?php
// This mail.php (Version 1.5c) 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><b>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["table_prefix"]."mailinfo";
$field1 = "info";
$field1_label = "Contact Names";
$field2 = "notes";
$field2_label = "Notes";
$deletecnt = $_GET['deletecnt'];
$field1_value=$_POST['field1_value'];
if ($field1_value) {$insert="1";} else {$insert="";}
$field2_value=$_POST['field2_value'];
$category="contact";

if ($user = $this->GetUser()){
if ($insert) {
if($this->LoadUser($field1_value)) {
mysql_query( "INSERT into $table ($field1, $field2, owner, type) values (\"$field1_value\",\"$field2_value\",\"$username\",\"$category\")");
}
}
if ($deletecnt) {
mysql_query( "DELETE from $table WHERE id=$deletecnt AND owner='$username'");
}
if (mysql_errno()!=0) {
switch (mysql_errno()) {
default:
echo "Error #".mysql_errno(). " (".mysql_error(). ")<br>";
}
}
}
$query = "SELECT * from $table WHERE owner='$username' AND type='$category' ORDER BY info ASC";
$result = mysql_query($query);
$rows = mysql_num_rows($result);
echo "<strong><em>Contact Management</em></strong>";
echo "<table border='1' cellspacing='0'>\n";
echo "<tr>\n";
echo "<td><strong>$field1_label</strong></td>\n";
echo "<td><strong>$field2_label</strong></td>\n";
echo "<td> </td>\n";
echo "</tr>\n";
// This is the entry boxes
echo "<form action=\"$link&action=contacts\" method=\"post\">\n";
echo "<tr>\n";
echo "<input type='hidden' name='insert' value='1'></td>\n";
echo "<td><input type='text' size='20' maxlength='65' name='field1_value' value='$addcontact'></td>\n";
echo "<td><input type='text' size='35' maxlength='65' name='field2_value'></td>\n";
echo "<td colspan=2 align=center>";
echo "<input type='submit' value=\" Add \"></td>\n";
echo "</tr>\n";
echo "</form>\n";
// This is the data under the entry boxes
while ($row = mysql_fetch_row($result)) {
echo "<tr>\n";
echo "<td><a href=".$link."&action=compose&to=".$row[2].">".$row[2]."</a><small>  [<a href=".$this->config["base_url"].$row[2].">Home Page</a>]</small></td>\n";
echo "<td>".strip_tags($row[3])."</td>\n";
echo "<td><a href=\"javascript: if(confirm('Are you sure you want to delete this item?')){ window.self.location='".$link."&action=contacts&deletecnt=".$row[4]."' }\"><center>Delete</center></a></td>\n";
echo "</tr>\n";
}
echo "</table>";
echo "<small>Clicking on the contact name will take you to message entry screen.</small>";
}

// code to manage folder list
elseif ($action==folders){
$table = $this->config["table_prefix"]."mailinfo";
$field1 = "info";
$field1_label = "Folder List";
$field2 = "notes";
$field2_label = "Notes";
$deletefldr = $_GET['deletefldr'];
$fldr = $_GET['fldr'];
$field1_value=$_POST['field1_value'];
if ($field1_value) {$insert="1";} else {$insert="";}
$field2_value=$_POST['field2_value'];
$category="folder";

if ($user = $this->GetUser()){
if ($insert) {
mysql_query( "INSERT into $table ($field1, $field2, owner, type) values (\"$field1_value\",\"$field2_value\",\"$username\",\"$category\")");
}

if ($deletefldr) {
// delete folder name from mailinfo
mysql_query("DELETE from $table WHERE id='$deletefldr' AND owner='$username' AND type='folder'");
// change files from being stored in folder being deleted to being stored in inbox
mysql_query("UPDATE ".$this->config["table_prefix"]."mail SET folder='inbox' WHERE folder='$fldr' AND UserTo='$username'");
}

if (mysql_errno()!=0) {
switch (mysql_errno()) {
default:
echo "Error #".mysql_errno(). " (".mysql_error(). ")<br>";
}
}
}
$query = "SELECT * from $table WHERE owner='$username' AND type='$category' ORDER BY info ASC";
$result = mysql_query($query);
$rows = mysql_num_rows($result);
echo "<strong><em>Folder Management</em></strong>";
echo "<table border='1' cellspacing='0'>\n";
echo "<tr>\n";
echo "<td><strong>$field1_label</strong></td>\n";
echo "<td><strong>$field2_label</strong></td>\n";
echo "<td> </td>\n";
echo "</tr>\n";

// This is the entry boxes
echo "<form action=\"$link&action=folders\" method=\"post\">\n";
echo "<tr>\n";
echo "<input type='hidden' name='insert' value='1'></td>\n";
echo "<td><input type='text' size='25' maxlength='65' name='field1_value'></td>\n";
echo "<td><input type='text' size='35' maxlength='65' name='field2_value'></td>\n";
echo "<td colspan='2' align='center'>";
echo "<input type='submit' value=\" Add \"></td>\n";
echo "</tr>\n";
echo "</form>\n";
// This is the data under the entry boxes
while ($row = mysql_fetch_row($result)) {
echo "<tr>\n";
echo "<td><a href=".$link."&folder=".strip_tags($row[2]).">".strip_tags($row[2])."</a></td>\n";
echo "<td>".strip_tags($row[3])."</td>\n";
echo "<td><a href=\"javascript: if(confirm('Are you sure you want to delete this item?')){ window.self.location='".$link."&action=folders&deletefldr=".$row[4]."&fldr=".$row[2]."' }\">
<center>Delete</center></a></td>\n";
}
echo "</table>";
echo "<small>Clicking on the folder name will take you to that folder.</small>";
}

// code to display user list
elseif ($action==users){
echo "<table width='650'><tr><td>";
$last_users = $this->LoadAll("select name from ".$this->config["table_prefix"]."users order by name ASC");
echo "<strong><em>User List.</em></strong> Click on the name to add it to the contact list.<br />";
foreach($last_users as $user)
{
echo "<a href=".$link."&action=contacts&cntct=".$user["name"].">".$user["name"]."</a> ";
}
echo "</td></tr></table>";
}

//code to show brief instructions for using filters
elseif ($action==help){
echo "<table width='700'><tr><td>";
echo "<p><strong>An introduction to sending messages in Wikka...</strong></p>";
echo "There are two brief parts to this help file. The first is how to interpret the output screen. The second is a description of how filters work.<br /><br />";
echo "     <strong><em>Introduction to the output...</em></strong><br /><br />";
echo "Below is a typical output line in the In-Box, Folder lists or the Sent message area.<br /><br />";
echo "<table border='0' width='800'>";
echo "<tr><td valign='middle'>";
echo "<P> <font color='#FF0000'><strong>!* </strong></font><A>Science Class tomorrow</A><font color='#000000'><strong><a title='You have answered this email.'> </a></strong><small>(05Feb05 2:08 pm)</small></FONT><FONT COLOR='#FF0000'><STRONG>*</STRONG></FONT><FONT COLOR='#000000'>  </FONT><FONT COLOR='#008000'><STRONG>*</STRONG></FONT></P>";
echo "</td><td align='center' width='140' valign='middle'>";
echo "<P><a title='Sender'>GmBowen</a><small> [<a title='Put into contact list.'>-></a>]</small></P>";
echo "</td>";
echo "<td width='150' valign='middle'>";
echo "<P><form>";
echo "<P><select name=move2folder>";
echo "<option value=ColeBowen>ColeBowen";
echo "<option value=GmBowen>GmBowen";
echo "<option value=Personal>Personal";
echo "<option value=Work>Work";
echo "</select><input type='button' name='Submit' value='Move'>";
echo "</form></P>";
echo "</td>";
echo "<td align='center' valign='middle' width='60'>";
echo "<P align='center'>[<a>Delete</a>]</P>";
echo "</td>";
echo "<td width='53'>";
echo "<P> <A title='Mark message with a RED star.'></A><FONT COLOR='#FF0000'><STRONG>*</STRONG></FONT>|<A title='Mark message with a BLUE star.'></A><FONT COLOR='#0000FF'><STRONG>*</STRONG></FONT>|<A title='Mark message with a GREEN star.'></A><FONT COLOR='#008000'><STRONG>*</STRONG></FONT><BR>";
echo "</P>";
echo "</TD>";
echo "</TR>";
echo "</TABLE>";
echo "</FONT><FONT COLOR='#000000'><br />Here is how to interpret the output....</FONT></P>";
echo "<UL>";
echo "<LI><FONT COLOR='#000000'>The exclamation mark (</FONT><FONT COLOR='#FF0000'><B>!</B></FONT><FONT COLOR='#000000'>) tells you that the sender marked the message <B>urgent</B>.</FONT></LI>";
echo "<LI><FONT COLOR='#000000'>The first red star (</FONT><FONT COLOR='#FF0000'>*</FONT><FONT COLOR='#000000'>) tells you that you have not read the message yet. </FONT></LI>";
echo "<LI><FONT COLOR='#000000'>'Science Class tomorrow' is the topic of the message.</FONT></LI>";
echo "<LI><FONT COLOR='#000000'>If there were a plus sign (<B>+</B>) immediately after the topic you would know that you had replied to the message. </FONT></LI>";
echo "<LI><FONT COLOR='#000000'>The date/time after the message lets you know when the message was sent. </FONT></LI>";
echo "<LI><FONT COLOR='#000000'>The coloured stars after the date/time (</FONT><FONT COLOR='#FF0000'>* </FONT><FONT COLOR='#000000'> </FONT><FONT COLOR='#00FF00'>*</FONT><FONT COLOR='#000000'>) indicate that you've applied those two markers to your message (see below). </FONT></LI>";
echo "<LI><FONT COLOR='#000000'>'GmBowen' is the sender of the message.</FONT></LI>";
echo "<LI><FONT COLOR='#000000'>The [->] allows you to put the senders name into your contact list. </FONT></LI>";
echo "<LI><FONT COLOR='#000000'>The dropdown menu (starting with 'ColeBowen') is a list of folders that you can file the message into. </FONT></LI>";
echo "<LI><FONT COLOR='#000000'>The [</FONT><FONT COLOR='#0000FF'>Delete</FONT><FONT COLOR='#000000'>] button allows you to delete the message (even though it does stay in the database). </FONT></LI>";
echo "<LI><FONT COLOR='#000000'>Clicking on the three coloured stars (</FONT><FONT COLOR='#FF0000'>*</FONT><FONT COLOR='#000000'>|</FONT><FONT COLOR='#0000FF'>*</FONT><FONT COLOR='#000000'>|</FONT><FONT COLOR='#00CC00'>*</FONT><FONT COLOR='#000000'>) allow you to set markers on your messages.</FONT></LI>";
echo "</UL>";
echo "<br /><br />";
echo "     <strong><em>Introduction to filters...</em></strong><br /><br />";
echo "<P>'Filters' are a simple-to-use tool that can help you organize your\n";
echo "messages.</P>\n";
echo "\n";
echo "<P>When you're in the in-box or any of the folders, on the top right\n";
echo "of the title bar you'll see a +/- with\n";
echo "<FONT COLOR='#FF0000'>*</FONT>|<FONT COLOR='#0000FF'>*</FONT>|<FONT COLOR='#008000'>*\n";
echo "</FONT>underneath it (and to the right of each message). By clicking\n";
echo "on these three coloured stars you can place or remove coloured stars\n";
echo "from beside the message title. A similar feature is found inside each\n";
echo "individual message box (seen when you're reading your messages).</P>\n";
echo "\n";
echo "<P>The different colours can mean anything you want them to. Red\n";
echo "might mean 'really important' and green might mean 'Ignore for now'.\n";
echo "It's really up to you. They can mean different things to you in your\n";
echo "in-box versus your different folders as well</P>\n";
echo "\n";
echo "<P><TABLE>\n";
echo "<TR BGCOLOR='#DDDDDD'>\n";
echo "<TD WIDTH=400>\n";
echo "<P><TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH='100%'>\n";
echo "<TR>\n";
echo "<TD>\n";
echo "<P> Message Topic:</P>\n";
echo "</TD>\n";
echo "<TD ALIGN=right>\n";
echo "<P><STRONG>A</STRONG> <STRONG>N</STRONG> <FONT COLOR='#FF0000'><STRONG>*</STRONG></FONT> <FONT COLOR='#0000FF'><STRONG>*</STRONG></FONT> <STRONG>*</STRONG></P>\n";
echo "</TD>\n";
echo "</TR>\n";
echo "</TABLE>\n";
echo "</P>\n";
echo "</TD>\n";
echo "<TD WIDTH=85>\n";
echo "<P> Sender:</P>\n";
echo "</TD>\n";
echo "<TD WIDTH=155>\n";
echo "<P> Move to Folder:</P>\n";
echo "</TD>\n";
echo "<TD>\n";
echo "<P> Delete:</P>\n";
echo "</TD>\n";
echo "<TD WIDTH=45>\n";
echo "<P>  <STRONG>+</STRONG>/<STRONG>-</STRONG></P>\n";
echo "</TD>\n";
echo "</TR>\n";
echo "</TABLE>\n";
echo "</P>\n";
echo "\n";
echo "<P>On the grey title bar to the right of 'Message Topic:' you can see\n";
echo " <B>A</B> <B>N</B> \n";
echo "<FONT COLOR='#FF0000'>*</FONT> <FONT COLOR='#0000FF'>*</FONT> <FONT COLOR='#008000'>*</FONT></P>\n";
echo "\n";
echo "<P>By clicking on the '<B>A</B>' you'll see all of the messages,\n";
echo "on the '<B>N</B>' you'll see the messages that don't have any markers\n";
echo "beside them, and if you click on any of the coloured stars you'll see\n";
echo "the messages that have those coloured markers beside them.</P>\n";
echo "\n";
echo "<P>Easy eh? </P>\n";
echo "</td></tr></table>";
}
?>
%%

The following file should be saved as ##page.inc.php## in a directory called ##scripts## in the wikka root....
%%(php)
<?php


/*
###############################################
#### ####
#### Author : Harish Chauhan ####
#### Date : 27 Sep,2004 ####
#### Updated: ####
#### ####
###############################################

*/
// Original class script obtained from http://www.phpclasses.org/browse/package/2012.html distributed as "Freeware"
// Modifications (Ver 1.0b) by GmBowen so that script useable with wikka wiki to support a "mail" action developed for the wiki.
// Throughout this class "?page" was changed to "&page" as well as other minor modifications throughout the script.

class Page
{
var $total_records=1; ///Total Records returned by sql query
var $records_per_page=1; ///how many records would be displayed at a time
var $page_name=""; ///page name on which the class is called
var $start=0;
var $page=0;
var $total_page=0;
var $current_page;
var $remain_page;
var $show_prev_next=true;
var $show_scroll_prev_next=false;
var $show_first_last=false;
var $show_disabled_links=true;
var $scroll_page=0;
var $qry_str="";
var $link_para="&";

/* returns boolean value if it is last page or not*/
function is_last_page()
{
return $this->page>=$this->total_page-1?true:false;
}
/* param : Void
returns boolean value if it is first page or not*/
function is_first_page()
{
return $this->page==0?true:false;
}
function current_page()
{
return $this->page+1;
}
function total_page()
{
return $this->total_page==0?1:$this->total_page;
}

//@param : $show = if you want to show disabled links on navigation links.
//
function show_disabled_links($show=TRUE)
{
$this->show_disabled_links=$show;
}
//@param : $link_para = if you want to pass any parameter to link
//
function set_link_parameter($link_para)
{
$this->link_para=$link_para;
}
function set_page_name($page_name)
{
$this->page_name=$page_name;
}
//@param : str= query string you want to pass to links.
function set_qry_string($str="")
{
$this->qry_str="&".$str;
}
function set_scroll_page($scroll_num=0)
{
if($scroll_num!=0)
$this->scroll_page=$scroll_num;
else
$this->scroll_page=$this->total_records;

}
function set_total_records($total_records)
{
if($total_records<0)
$total_records=0;
$this->total_records=$total_records;
}
function set_records_per_page($records_per_page)
{
if($records_per_page<=0)
$records_per_page=$this->total_records;
$this->records_per_page=$records_per_page;
}
/* @params
* $page_name = Page name on which class is integrated. i.e. $_SERVER['PHP_SELF']
* $total_records=Total records returnd by sql query.
* $records_per_page=How many projects would be displayed at a time
* $scroll_num= How many pages scrolled if we click on scroll page link.
* i.e if we want to scroll 6 pages at a time then pass argument 6.
* $show_prev_next= boolean(true/false) to show prev Next Link
* $show_scroll_prev_next= boolean(true/false) to show scrolled prev Next Link
* $show_first_last= boolean(true/false) to show first last Link to move first and last page.
*/

function set_page_data($page_name,$total_records,$records_per_page=1,$scroll_num=0,$show_prev_next=true,$show_scroll_prev_next=false,$show_first_last=false)
{
$this->set_total_records($total_records);
$this->set_records_per_page($records_per_page);
$this->set_scroll_page($scroll_num);
$this->set_page_name($page_name);
$this->show_prev_next=$show_prev_next;
$this->show_scroll_prev_next=$show_scroll_prev_next;
$this->show_first_last=$show_first_last;
}
/* @params
* $user_link= if you want to display your link i.e if you want to user '>>' instead of [first] link then use
Page::get_first_page_nav(">>") OR for image
Page::get_first_page_nav("<img src='' alt='first'>")
$link_para: link parameters i.e if you want ot use another parameters such as class.
Page::get_first_page_nav(">>","class=myStyleSheetClass")
*/
function get_first_page_nav($user_link="",$link_para="")
{
if($this->total_page<=1)
return;
if(trim($user_link)=="")
$user_link="««  ";
if(!$this->is_first_page()&& $this->show_first_last)
echo ' <a href="'.$this->page_name.'&page=0'.$this->qry_str.'" '.$link_para.'>'.$user_link.'</a> ';
elseif($this->show_first_last && $this->show_disabled_links)
echo $user_link;
}
function get_last_page_nav($user_link="",$link_para="")
{
if($this->total_page<=1)
return;
if(trim($user_link)=="")
$user_link="  Â»Â»";
if(!$this->is_last_page()&& $this->show_first_last)
echo ' <a href="'.$this->page_name.'&page='.($this->total_page-1).$this->qry_str.'" '.$link_para.'>'.$user_link.'</a> ';
elseif($this->show_first_last && $this->show_disabled_links)
echo $user_link;
}
function get_next_page_nav($user_link="",$link_para="")
{
if($this->total_page<=1)
return;
if(trim($user_link)=="")
$user_link=" »";
if(!$this->is_last_page()&& $this->show_prev_next)
echo ' <a href="'.$this->page_name.'&page='.($this->page+1).$this->qry_str.'" '.$link_para.'>'.$user_link.'</a> ';
elseif($this->show_prev_next && $this->show_disabled_links)
echo $user_link." ";
}
function get_prev_page_nav($user_link="",$link_para="")
{
if($this->total_page<=1)
return;
if(trim($user_link)=="")
$user_link="« ";
if(!$this->is_first_page()&& $this->show_prev_next)
echo ' <a href="'.$this->page_name.'&page='.($this->page-1).$this->qry_str.'" '.$link_para.'>'.$user_link.'</a> ';
elseif($this->show_prev_next && $this->show_disabled_links)
echo " ".$user_link;
}
function get_scroll_prev_page_nav($user_link="",$link_para="")
{

if($this->scroll_page>=$this->total_page)
return;
if(trim($user_link)=="")
$user_link="[-$this->scroll_page]";
if($this->page>$this->scroll_page &&$this->show_scroll_prev_next)
echo ' <a href="'.$this->page_name.'&page='.($this->page-$this->scroll_page).$this->qry_str.'" '.$link_para.'>'.$user_link.'</a> ';
elseif($this->show_scroll_prev_next && $this->show_disabled_links)
echo $user_link;
}
function get_scroll_next_page_nav($user_link="",$link_para="")
{
if($this->scroll_page>=$this->total_page)
return;
if(trim($user_link)=="")
$user_link="[+$this->scroll_page]";
if($this->total_page>$this->page+$this->scroll_page &&$this->show_scroll_prev_next)
echo ' <a href="'.$this->page_name.'&page='.($this->page+$this->scroll_page).$this->qry_str.'" '.$link_para.'>'.$user_link.'</a> ';
elseif($this->show_scroll_prev_next && $this->show_disabled_links)
echo $user_link;
}

function get_number_page_nav($link_para="")
{
$j=0;
$scroll_page=$this->scroll_page;
if($this->page>($scroll_page/2))
$j=$this->page-intval($scroll_page/2);
if($j+$scroll_page>$this->total_page)
$j=$this->total_page-$scroll_page;

if($j<0)
$i=0;
else
$i=$j;

for(;$i<$j+$scroll_page && $i<$this->total_records;$i++)
{
if($i==$this->page)
echo ($i+1);
else
echo ' <a href="'.$this->page_name.'&page='.$i.$this->qry_str.'" '.$link_para.'>'.($i+1).'</a> ';
}
}

function get_page_nav()
{
if($this->total_records<=0)
{
//echo "No Records Found";
// return false;
}
$this->calculate();
$this->get_first_page_nav("",$this->link_para);
$this->get_scroll_prev_page_nav("",$this->link_para);
$this->get_prev_page_nav("",$this->link_para);
$this->get_number_page_nav($this->link_para);
$this->get_next_page_nav("",$this->link_para);
$this->get_scroll_next_page_nav("",$this->link_para);
$this->get_last_page_nav("",$this->link_para);
// return true;
}
function calculate()
{
$this->page=$_REQUEST['page'];
if(!is_numeric($this->page))
$this->page=0;
$this->start=$this->page*$this->records_per_page;
$this->total_page=@intval($this->total_records/$this->records_per_page);
if($this->total_records%$this->records_per_page!=0)
$this->total_page++;
}
function get_limit_query($qry="")
{
$this->calculate();
return $qry." LIMIT $this->start,$this->records_per_page";
}
}
?>
%%

This is the inbox (note the * indicator in the header that there is unread mail, + indicator for answered mail, and the marker/filter system)...

http://gmbowen.educ.unb.ca/wikitest/pms1.jpg

This is the "compose" box (note the contact list...clicking on a name enters it into the "to" box)...

http://gmbowen.educ.unb.ca/wikitest/pms2.jpg

This is a listing of "sent" files (note the indicator of whether they'd been read or not)...

http://gmbowen.educ.unb.ca/wikitest/pms3.jpg

This is the contents of a folder...

http://gmbowen.educ.unb.ca/wikitest/pms4.jpg

This is a listing of the contacts & where they are managed...

http://gmbowen.educ.unb.ca/wikitest/pms5.jpg

This is a list of the registered users....

http://gmbowen.educ.unb.ca/wikitest/pms6.jpg

This is a listing of the folders & where they are managed....

http://gmbowen.educ.unb.ca/wikitest/pms7.jpg

This is an example message...

http://gmbowen.educ.unb.ca/wikitest/pms8.jpg

This demonstrates a "compose" form after "forward" has been clicked....

http://gmbowen.educ.unb.ca/wikitest/pms9.jpg

This image is a "reply" message (you cannot change the "to" or the "subject" block)

http://gmbowen.educ.unb.ca/wikitest/pms10.jpg

----
**To upgrade your mail.php from version 1.0 to 1.5 do the following.....**

1) Use the following mysql statements (in your fvaourite mysql administration program, or at the command line if you know how) to update the table structure in your wikki database. Make sure you change "WAKKAPREFIX" to the prefix you use in your wikka.

ALTER TABLE `WAKKAPREFIX_mail`
ADD `repliedto` TINYINT (1) DEFAULT '0' AFTER `Message` ,
ADD `urgent` TINYINT (1) DEFAULT NULL AFTER `repliedto` ,
ADD `fltr1` TINYINT (1) DEFAULT '0' NOT NULL AFTER `urgent` ,
ADD `fltr2` TINYINT (1) DEFAULT '0' NOT NULL AFTER `fltr1` ,
ADD `fltr3` TINYINT (1) DEFAULT '0' NOT NULL AFTER `fltr2` ,
ADD `DateSent` DATETIME NOT NULL AFTER `fltr3`

2) THEN RUN THE PHP SCRIPT mailupdate.php as an ACTION (you can only do this as a designated administrator). Save the php code below as mailupdate.php, insert on a page, and then click on the visible link. This will alter the date code from a text string to a mysql DATETIME string (makes it easier to display date & time).

%%(php)
if ($this->IsAdmin()) {
$link = $this->config["base_url"].$this->MiniHref($method, $tag);
echo "<a href=".$link."&action=update>Update database for mail.php from version 1.0 to version 1.5</a>";
$action=$_GET['action'];
if($action==update){
$query="SELECT SentDate,DateSent FROM ".$this->config["table_prefix"]."mail";
$result=mysql_query($query) or die ("cant do it");
while ($row=mysql_fetch_array($result)) {
$newdate=$row[SentDate];
mysql_query("UPDATE ".$this->config["table_prefix"]."mail SET DateSent=$newdate WHERE SentDate=$newdate");
}
if ($_GET['action']) {echo "Database update complete.";}
}
}
%%

Erase the update file from you actions directory.

3) Then install the new mail.php file. (erase the old one, replace with the new one.) You may or may want to put your wiki into "administrative mode" so that others cannot use it while you do this. (See these [[http://wikka.jsnx.com/UpgradeNotes notes]] for upgrading wikka.)

4) Finally, remove the ""SentDate"" field from the mysql table WAKKAPREFIX_mail using the following command. (Make sure you change "WAKKAPREFIX" to the prefix you use in your wikka.)

ALTER TABLE `WAKKAPREFIX_mail` DROP `SentDate`

That's it. This upgrade sequence has been tested on two sites and worked without a problem.

----


Revision [5889]

Edited on 2005-02-10 19:36:41 by NilsLindenberg [(modified by JsnX)]
Additions:
====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.
%%(sql)
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)
<?php
// This mail.php (Version 1.5c) 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><b>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["table_prefix"]."mailinfo";
$field1 = "info";
$field1_label = "Contact Names";
$field2 = "notes";
$field2_label = "Notes";
$deletecnt = $_GET['deletecnt'];
$field1_value=$_POST['field1_value'];
if ($field1_value) {$insert="1";} else {$insert="";}
$field2_value=$_POST['field2_value'];
$category="contact";

if ($user = $this->GetUser()){
if ($insert) {
if($this->LoadUser($field1_value)) {
mysql_query( "INSERT into $table ($field1, $field2, owner, type) values (\"$field1_value\",\"$field2_value\",\"$username\",\"$category\")");
}
}
if ($deletecnt) {
mysql_query( "DELETE from $table WHERE id=$deletecnt AND owner='$username'");
}
if (mysql_errno()!=0) {
switch (mysql_errno()) {
default:
echo "Error #".mysql_errno(). " (".mysql_error(). ")<br>";
}
}
}
$query = "SELECT * from $table WHERE owner='$username' AND type='$category' ORDER BY info ASC";
$result = mysql_query($query);
$rows = mysql_num_rows($result);
echo "<strong><em>Contact Management</em></strong>";
echo "<table border='1' cellspacing='0'>\n";
echo "<tr>\n";
echo "<td><strong>$field1_label</strong></td>\n";
echo "<td><strong>$field2_label</strong></td>\n";
echo "<td> </td>\n";
echo "</tr>\n";
// This is the entry boxes
echo "<form action=\"$link&action=contacts\" method=\"post\">\n";
echo "<tr>\n";
echo "<input type='hidden' name='insert' value='1'></td>\n";
echo "<td><input type='text' size='20' maxlength='65' name='field1_value' value='$addcontact'></td>\n";
echo "<td><input type='text' size='35' maxlength='65' name='field2_value'></td>\n";
echo "<td colspan=2 align=center>";
echo "<input type='submit' value=\" Add \"></td>\n";
echo "</tr>\n";
echo "</form>\n";
// This is the data under the entry boxes
while ($row = mysql_fetch_row($result)) {
echo "<tr>\n";
echo "<td><a href=".$link."&action=compose&to=".$row[2].">".$row[2]."</a><small>  [<a href=".$this->config["base_url"].$row[2].">Home Page</a>]</small></td>\n";
echo "<td>".strip_tags($row[3])."</td>\n";
echo "<td><a href=\"javascript: if(confirm('Are you sure you want to delete this item?')){ window.self.location='".$link."&action=contacts&deletecnt=".$row[4]."' }\"><center>Delete</center></a></td>\n";
echo "</tr>\n";
}
echo "</table>";
echo "<small>Clicking on the contact name will take you to message entry screen.</small>";
}

// code to manage folder list
elseif ($action==folders){
$table = $this->config["table_prefix"]."mailinfo";
$field1 = "info";
$field1_label = "Folder List";
$field2 = "notes";
$field2_label = "Notes";
$deletefldr = $_GET['deletefldr'];
$fldr = $_GET['fldr'];
$field1_value=$_POST['field1_value'];
if ($field1_value) {$insert="1";} else {$insert="";}
$field2_value=$_POST['field2_value'];
$category="folder";

if ($user = $this->GetUser()){
if ($insert) {
mysql_query( "INSERT into $table ($field1, $field2, owner, type) values (\"$field1_value\",\"$field2_value\",\"$username\",\"$category\")");
}

if ($deletefldr) {
// delete folder name from mailinfo
mysql_query("DELETE from $table WHERE id='$deletefldr' AND owner='$username' AND type='folder'");
// change files from being stored in folder being deleted to being stored in inbox
mysql_query("UPDATE ".$this->config["table_prefix"]."mail SET folder='inbox' WHERE folder='$fldr' AND UserTo='$username'");
}

if (mysql_errno()!=0) {
switch (mysql_errno()) {
default:
echo "Error #".mysql_errno(). " (".mysql_error(). ")<br>";
}
}
}
$query = "SELECT * from $table WHERE owner='$username' AND type='$category' ORDER BY info ASC";
$result = mysql_query($query);
$rows = mysql_num_rows($result);
echo "<strong><em>Folder Management</em></strong>";
echo "<table border='1' cellspacing='0'>\n";
echo "<tr>\n";
echo "<td><strong>$field1_label</strong></td>\n";
echo "<td><strong>$field2_label</strong></td>\n";
echo "<td> </td>\n";
echo "</tr>\n";

// This is the entry boxes
echo "<form action=\"$link&action=folders\" method=\"post\">\n";
echo "<tr>\n";
echo "<input type='hidden' name='insert' value='1'></td>\n";
echo "<td><input type='text' size='25' maxlength='65' name='field1_value'></td>\n";
echo "<td><input type='text' size='35' maxlength='65' name='field2_value'></td>\n";
echo "<td colspan='2' align='center'>";
echo "<input type='submit' value=\" Add \"></td>\n";
echo "</tr>\n";
echo "</form>\n";
// This is the data under the entry boxes
while ($row = mysql_fetch_row($result)) {
echo "<tr>\n";
echo "<td><a href=".$link."&folder=".strip_tags($row[2]).">".strip_tags($row[2])."</a></td>\n";
echo "<td>".strip_tags($row[3])."</td>\n";
echo "<td><a href=\"javascript: if(confirm('Are you sure you want to delete this item?')){ window.self.location='".$link."&action=folders&deletefldr=".$row[4]."&fldr=".$row[2]."' }\">
<center>Delete</center></a></td>\n";
}
echo "</table>";
echo "<small>Clicking on the folder name will take you to that folder.</small>";
}

// code to display user list
elseif ($action==users){
echo "<table width='650'><tr><td>";
$last_users = $this->LoadAll("select name from ".$this->config["table_prefix"]."users order by name ASC");
echo "<strong><em>User List.</em></strong> Click on the name to add it to the contact list.<br />";
foreach($last_users as $user)
{
echo "<a href=".$link."&action=contacts&cntct=".$user["name"].">".$user["name"]."</a> ";
}
echo "</td></tr></table>";
}

//code to show brief instructions for using filters
elseif ($action==help){
echo "<table width='700'><tr><td>";
echo "<p><strong>An introduction to sending messages in Wikka...</strong></p>";
echo "There are two brief parts to this help file. The first is how to interpret the output screen. The second is a description of how filters work.<br /><br />";
echo "     <strong><em>Introduction to the output...</em></strong><br /><br />";
echo "Below is a typical output line in the In-Box, Folder lists or the Sent message area.<br /><br />";
echo "<table border='0' width='800'>";
echo "<tr><td valign='middle'>";
echo "<P> <font color='#FF0000'><strong>!* </strong></font><A>Science Class tomorrow</A><font color='#000000'><strong><a title='You have answered this email.'> </a></strong><small>(05Feb05 2:08 pm)</small></FONT><FONT COLOR='#FF0000'><STRONG>*</STRONG></FONT><FONT COLOR='#000000'>  </FONT><FONT COLOR='#008000'><STRONG>*</STRONG></FONT></P>";
echo "</td><td align='center' width='140' valign='middle'>";
echo "<P><a title='Sender'>GmBowen</a><small> [<a title='Put into contact list.'>-></a>]</small></P>";
echo "</td>";
echo "<td width='150' valign='middle'>";
echo "<P><form>";
echo "<P><select name=move2folder>";
echo "<option value=ColeBowen>ColeBowen";
echo "<option value=GmBowen>GmBowen";
echo "<option value=Personal>Personal";
echo "<option value=Work>Work";
echo "</select><input type='button' name='Submit' value='Move'>";
echo "</form></P>";
echo "</td>";
echo "<td align='center' valign='middle' width='60'>";
echo "<P align='center'>[<a>Delete</a>]</P>";
echo "</td>";
echo "<td width='53'>";
echo "<P> <A title='Mark message with a RED star.'></A><FONT COLOR='#FF0000'><STRONG>*</STRONG></FONT>|<A title='Mark message with a BLUE star.'></A><FONT COLOR='#0000FF'><STRONG>*</STRONG></FONT>|<A title='Mark message with a GREEN star.'></A><FONT COLOR='#008000'><STRONG>*</STRONG></FONT><BR>";
echo "</P>";
echo "</TD>";
echo "</TR>";
echo "</TABLE>";
echo "</FONT><FONT COLOR='#000000'><br />Here is how to interpret the output....</FONT></P>";
echo "<UL>";
echo "<LI><FONT COLOR='#000000'>The exclamation mark (</FONT><FONT COLOR='#FF0000'><B>!</B></FONT><FONT COLOR='#000000'>) tells you that the sender marked the message <B>urgent</B>.</FONT></LI>";
echo "<LI><FONT COLOR='#000000'>The first red star (</FONT><FONT COLOR='#FF0000'>*</FONT><FONT COLOR='#000000'>) tells you that you have not read the message yet. </FONT></LI>";
echo "<LI><FONT COLOR='#000000'>'Science Class tomorrow' is the topic of the message.</FONT></LI>";
echo "<LI><FONT COLOR='#000000'>If there were a plus sign (<B>+</B>) immediately after the topic you would know that you had replied to the message. </FONT></LI>";
echo "<LI><FONT COLOR='#000000'>The date/time after the message lets you know when the message was sent. </FONT></LI>";
echo "<LI><FONT COLOR='#000000'>The coloured stars after the date/time (</FONT><FONT COLOR='#FF0000'>* </FONT><FONT COLOR='#000000'> </FONT><FONT COLOR='#00FF00'>*</FONT><FONT COLOR='#000000'>) indicate that you've applied those two markers to your message (see below). </FONT></LI>";
echo "<LI><FONT COLOR='#000000'>'GmBowen' is the sender of the message.</FONT></LI>";
echo "<LI><FONT COLOR='#000000'>The [->] allows you to put the senders name into your contact list. </FONT></LI>";
echo "<LI><FONT COLOR='#000000'>The dropdown menu (starting with 'ColeBowen') is a list of folders that you can file the message into. </FONT></LI>";
echo "<LI><FONT COLOR='#000000'>The [</FONT><FONT COLOR='#0000FF'>Delete</FONT><FONT COLOR='#000000'>] button allows you to delete the message (even though it does stay in the database). </FONT></LI>";
echo "<LI><FONT COLOR='#000000'>Clicking on the three coloured stars (</FONT><FONT COLOR='#FF0000'>*</FONT><FONT COLOR='#000000'>|</FONT><FONT COLOR='#0000FF'>*</FONT><FONT COLOR='#000000'>|</FONT><FONT COLOR='#00CC00'>*</FONT><FONT COLOR='#000000'>) allow you to set markers on your messages.</FONT></LI>";
echo "</UL>";
echo "<br /><br />";
echo "     <strong><em>Introduction to filters...</em></strong><br /><br />";
echo "<P>'Filters' are a simple-to-use tool that can help you organize your\n";
echo "messages.</P>\n";
echo "\n";
echo "<P>When you're in the in-box or any of the folders, on the top right\n";
echo "of the title bar you'll see a +/- with\n";
echo "<FONT COLOR='#FF0000'>*</FONT>|<FONT COLOR='#0000FF'>*</FONT>|<FONT COLOR='#008000'>*\n";
echo "</FONT>underneath it (and to the right of each message). By clicking\n";
echo "on these three coloured stars you can place or remove coloured stars\n";
echo "from beside the message title. A similar feature is found inside each\n";
echo "individual message box (seen when you're reading your messages).</P>\n";
echo "\n";
echo "<P>The different colours can mean anything you want them to. Red\n";
echo "might mean 'really important' and green might mean 'Ignore for now'.\n";
echo "It's really up to you. They can mean different things to you in your\n";
echo "in-box versus your different folders as well</P>\n";
echo "\n";
echo "<P><TABLE>\n";
echo "<TR BGCOLOR='#DDDDDD'>\n";
echo "<TD WIDTH=400>\n";
echo "<P><TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH='100%'>\n";
echo "<TR>\n";
echo "<TD>\n";
echo "<P> Message Topic:</P>\n";
echo "</TD>\n";
echo "<TD ALIGN=right>\n";
echo "<P><STRONG>A</STRONG> <STRONG>N</STRONG> <FONT COLOR='#FF0000'><STRONG>*</STRONG></FONT> <FONT COLOR='#0000FF'><STRONG>*</STRONG></FONT> <STRONG>*</STRONG></P>\n";
echo "</TD>\n";
echo "</TR>\n";
echo "</TABLE>\n";
echo "</P>\n";
echo "</TD>\n";
echo "<TD WIDTH=85>\n";
echo "<P> Sender:</P>\n";
echo "</TD>\n";
echo "<TD WIDTH=155>\n";
echo "<P> Move to Folder:</P>\n";
echo "</TD>\n";
echo "<TD>\n";
echo "<P> Delete:</P>\n";
echo "</TD>\n";
echo "<TD WIDTH=45>\n";
echo "<P>  <STRONG>+</STRONG>/<STRONG>-</STRONG></P>\n";
echo "</TD>\n";
echo "</TR>\n";
echo "</TABLE>\n";
echo "</P>\n";
echo "\n";
echo "<P>On the grey title bar to the right of 'Message Topic:' you can see\n";
echo " <B>A</B> <B>N</B> \n";
echo "<FONT COLOR='#FF0000'>*</FONT> <FONT COLOR='#0000FF'>*</FONT> <FONT COLOR='#008000'>*</FONT></P>\n";
echo "\n";
echo "<P>By clicking on the '<B>A</B>' you'll see all of the messages,\n";
echo "on the '<B>N</B>' you'll see the messages that don't have any markers\n";
echo "beside them, and if you click on any of the coloured stars you'll see\n";
echo "the messages that have those coloured markers beside them.</P>\n";
echo "\n";
echo "<P>Easy eh? </P>\n";
echo "</td></tr></table>";
}
?>
%%

The following file should be saved as ##page.inc.php## in a directory called ##scripts## in the wikka root....
%%(php)
<?php


/*
###############################################
#### ####
#### Author : Harish Chauhan ####
#### Date : 27 Sep,2004 ####
#### Updated: ####
#### ####
###############################################

*/
// Original class script obtained from http://www.phpclasses.org/browse/package/2012.html distributed as "Freeware"
// Modifications (Ver 1.0b) by GmBowen so that script useable with wikka wiki to support a "mail" action developed for the wiki.
// Throughout this class "?page" was changed to "&page" as well as other minor modifications throughout the script.

class Page
{
var $total_records=1; ///Total Records returned by sql query
var $records_per_page=1; ///how many records would be displayed at a time
var $page_name=""; ///page name on which the class is called
var $start=0;
var $page=0;
var $total_page=0;
var $current_page;
var $remain_page;
var $show_prev_next=true;
var $show_scroll_prev_next=false;
var $show_first_last=false;
var $show_disabled_links=true;
var $scroll_page=0;
var $qry_str="";
var $link_para="&";

/* returns boolean value if it is last page or not*/
function is_last_page()
{
return $this->page>=$this->total_page-1?true:false;
}
/* param : Void
returns boolean value if it is first page or not*/
function is_first_page()
{
return $this->page==0?true:false;
}
function current_page()
{
return $this->page+1;
}
function total_page()
{
return $this->total_page==0?1:$this->total_page;
}

//@param : $show = if you want to show disabled links on navigation links.
//
function show_disabled_links($show=TRUE)
{
$this->show_disabled_links=$show;
}
//@param : $link_para = if you want to pass any parameter to link
//
function set_link_parameter($link_para)
{
$this->link_para=$link_para;
}
function set_page_name($page_name)
{
$this->page_name=$page_name;
}
//@param : str= query string you want to pass to links.
function set_qry_string($str="")
{
$this->qry_str="&".$str;
}
function set_scroll_page($scroll_num=0)
{
if($scroll_num!=0)
$this->scroll_page=$scroll_num;
else
$this->scroll_page=$this->total_records;

}
function set_total_records($total_records)
{
if($total_records<0)
$total_records=0;
$this->total_records=$total_records;
}
function set_records_per_page($records_per_page)
{
if($records_per_page<=0)
$records_per_page=$this->total_records;
$this->records_per_page=$records_per_page;
}
/* @params
* $page_name = Page name on which class is integrated. i.e. $_SERVER['PHP_SELF']
* $total_records=Total records returnd by sql query.
* $records_per_page=How many projects would be displayed at a time
* $scroll_num= How many pages scrolled if we click on scroll page link.
* i.e if we want to scroll 6 pages at a time then pass argument 6.
* $show_prev_next= boolean(true/false) to show prev Next Link
* $show_scroll_prev_next= boolean(true/false) to show scrolled prev Next Link
* $show_first_last= boolean(true/false) to show first last Link to move first and last page.
*/

function set_page_data($page_name,$total_records,$records_per_page=1,$scroll_num=0,$show_prev_next=true,$show_scroll_prev_next=false,$show_first_last=false)
{
$this->set_total_records($total_records);
$this->set_records_per_page($records_per_page);
$this->set_scroll_page($scroll_num);
$this->set_page_name($page_name);
$this->show_prev_next=$show_prev_next;
$this->show_scroll_prev_next=$show_scroll_prev_next;
$this->show_first_last=$show_first_last;
}
/* @params
* $user_link= if you want to display your link i.e if you want to user '>>' instead of [first] link then use
Page::get_first_page_nav(">>") OR for image
Page::get_first_page_nav("<img src='' alt='first'>")
$link_para: link parameters i.e if you want ot use another parameters such as class.
Page::get_first_page_nav(">>","class=myStyleSheetClass")
*/
function get_first_page_nav($user_link="",$link_para="")
{
if($this->total_page<=1)
return;
if(trim($user_link)=="")
$user_link="««  ";
if(!$this->is_first_page()&& $this->show_first_last)
echo ' <a href="'.$this->page_name.'&page=0'.$this->qry_str.'" '.$link_para.'>'.$user_link.'</a> ';
elseif($this->show_first_last && $this->show_disabled_links)
echo $user_link;
}
function get_last_page_nav($user_link="",$link_para="")
{
if($this->total_page<=1)
return;
if(trim($user_link)=="")
$user_link="  Â»Â»";
if(!$this->is_last_page()&& $this->show_first_last)
echo ' <a href="'.$this->page_name.'&page='.($this->total_page-1).$this->qry_str.'" '.$link_para.'>'.$user_link.'</a> ';
elseif($this->show_first_last && $this->show_disabled_links)
echo $user_link;
}
function get_next_page_nav($user_link="",$link_para="")
{
if($this->total_page<=1)
return;
if(trim($user_link)=="")
$user_link=" »";
if(!$this->is_last_page()&& $this->show_prev_next)
echo ' <a href="'.$this->page_name.'&page='.($this->page+1).$this->qry_str.'" '.$link_para.'>'.$user_link.'</a> ';
elseif($this->show_prev_next && $this->show_disabled_links)
echo $user_link." ";
}
function get_prev_page_nav($user_link="",$link_para="")
{
if($this->total_page<=1)
return;
if(trim($user_link)=="")
$user_link="« ";
if(!$this->is_first_page()&& $this->show_prev_next)
echo ' <a href="'.$this->page_name.'&page='.($this->page-1).$this->qry_str.'" '.$link_para.'>'.$user_link.'</a> ';
elseif($this->show_prev_next && $this->show_disabled_links)
echo " ".$user_link;
}
function get_scroll_prev_page_nav($user_link="",$link_para="")
{

if($this->scroll_page>=$this->total_page)
return;
if(trim($user_link)=="")
$user_link="[-$this->scroll_page]";
if($this->page>$this->scroll_page &&$this->show_scroll_prev_next)
echo ' <a href="'.$this->page_name.'&page='.($this->page-$this->scroll_page).$this->qry_str.'" '.$link_para.'>'.$user_link.'</a> ';
elseif($this->show_scroll_prev_next && $this->show_disabled_links)
echo $user_link;
}
function get_scroll_next_page_nav($user_link="",$link_para="")
{
if($this->scroll_page>=$this->total_page)
return;
if(trim($user_link)=="")
$user_link="[+$this->scroll_page]";
if($this->total_page>$this->page+$this->scroll_page &&$this->show_scroll_prev_next)
echo ' <a href="'.$this->page_name.'&page='.($this->page+$this->scroll_page).$this->qry_str.'" '.$link_para.'>'.$user_link.'</a> ';
elseif($this->show_scroll_prev_next && $this->show_disabled_links)
echo $user_link;
}

function get_number_page_nav($link_para="")
{
$j=0;
$scroll_page=$this->scroll_page;
if($this->page>($scroll_page/2))
$j=$this->page-intval($scroll_page/2);
if($j+$scroll_page>$this->total_page)
$j=$this->total_page-$scroll_page;

if($j<0)
$i=0;
else
$i=$j;

for(;$i<$j+$scroll_page && $i<$this->total_records;$i++)
{
if($i==$this->page)
echo ($i+1);
else
echo ' <a href="'.$this->page_name.'&page='.$i.$this->qry_str.'" '.$link_para.'>'.($i+1).'</a> ';
}
}

function get_page_nav()
{
if($this->total_records<=0)
{
//echo "No Records Found";
// return false;
}
$this->calculate();
$this->get_first_page_nav("",$this->link_para);
$this->get_scroll_prev_page_nav("",$this->link_para);
$this->get_prev_page_nav("",$this->link_para);
$this->get_number_page_nav($this->link_para);
$this->get_next_page_nav("",$this->link_para);
$this->get_scroll_next_page_nav("",$this->link_para);
$this->get_last_page_nav("",$this->link_para);
// return true;
}
function calculate()
{
$this->page=$_REQUEST['page'];
if(!is_numeric($this->page))
$this->page=0;
$this->start=$this->page*$this->records_per_page;
$this->total_page=@intval($this->total_records/$this->records_per_page);
if($this->total_records%$this->records_per_page!=0)
$this->total_page++;
}
function get_limit_query($qry="")
{
$this->calculate();
return $qry." LIMIT $this->start,$this->records_per_page";
}
}
?>
%%

This is the inbox (note the * indicator in the header that there is unread mail, + indicator for answered mail, and the marker/filter system)...

http://gmbowen.educ.unb.ca/wikitest/pms1.jpg

This is the "compose" box (note the contact list...clicking on a name enters it into the "to" box)...

http://gmbowen.educ.unb.ca/wikitest/pms2.jpg

This is a listing of "sent" files (note the indicator of whether they'd been read or not)...

http://gmbowen.educ.unb.ca/wikitest/pms3.jpg

This is the contents of a folder...

http://gmbowen.educ.unb.ca/wikitest/pms4.jpg

This is a listing of the contacts & where they are managed...

http://gmbowen.educ.unb.ca/wikitest/pms5.jpg

This is a list of the registered users....

http://gmbowen.educ.unb.ca/wikitest/pms6.jpg

This is a listing of the folders & where they are managed....

http://gmbowen.educ.unb.ca/wikitest/pms7.jpg

This is an example message...

http://gmbowen.educ.unb.ca/wikitest/pms8.jpg

This demonstrates a "compose" form after "forward" has been clicked....

http://gmbowen.educ.unb.ca/wikitest/pms9.jpg

This image is a "reply" message (you cannot change the "to" or the "subject" block)

http://gmbowen.educ.unb.ca/wikitest/pms10.jpg

----
**To upgrade your mail.php from version 1.0 to 1.5 do the following.....**

1) Use the following mysql statements (in your fvaourite mysql administration program, or at the command line if you know how) to update the table structure in your wikki database. Make sure you change "WAKKAPREFIX" to the prefix you use in your wikka.

ALTER TABLE `WAKKAPREFIX_mail`
ADD `repliedto` TINYINT (1) DEFAULT '0' AFTER `Message` ,
ADD `urgent` TINYINT (1) DEFAULT NULL AFTER `repliedto` ,
ADD `fltr1` TINYINT (1) DEFAULT '0' NOT NULL AFTER `urgent` ,
ADD `fltr2` TINYINT (1) DEFAULT '0' NOT NULL AFTER `fltr1` ,
ADD `fltr3` TINYINT (1) DEFAULT '0' NOT NULL AFTER `fltr2` ,
ADD `DateSent` DATETIME NOT NULL AFTER `fltr3`

2) THEN RUN THE PHP SCRIPT mailupdate.php as an ACTION (you can only do this as a designated administrator). Save the php code below as mailupdate.php, insert on a page, and then click on the visible link. This will alter the date code from a text string to a mysql DATETIME string (makes it easier to display date & time).

%%(php)
if ($this->IsAdmin()) {
$link = $this->config["base_url"].$this->MiniHref($method, $tag);
echo "<a href=".$link."&action=update>Update database for mail.php from version 1.0 to version 1.5</a>";
$action=$_GET['action'];
if($action==update){
$query="SELECT SentDate,DateSent FROM ".$this->config["table_prefix"]."mail";
$result=mysql_query($query) or die ("cant do it");
while ($row=mysql_fetch_array($result)) {
$newdate=$row[SentDate];
mysql_query("UPDATE ".$this->config["table_prefix"]."mail SET DateSent=$newdate WHERE SentDate=$newdate");
}
if ($_GET['action']) {echo "Database update complete.";}
}
}
%%

Erase the update file from you actions directory.

3) Then install the new mail.php file. (erase the old one, replace with the new one.) You may or may want to put your wiki into "administrative mode" so that others cannot use it while you do this. (See these [[http://wikka.jsnx.com/UpgradeNotes notes]] for upgrading wikka.)

4) Finally, remove the ""SentDate"" field from the mysql table WAKKAPREFIX_mail using the following command. (Make sure you change "WAKKAPREFIX" to the prefix you use in your wikka.)

ALTER TABLE `WAKKAPREFIX_mail` DROP `SentDate`

That's it. This upgrade sequence has been tested on two sites and worked without a problem.

----
Deletions:
====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.
%%(sql)
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)
<?php
<?php
// This mail.php (Version 1.5c) 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><b>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["table_prefix"]."mailinfo";
$field1 = "info";
$field1_label = "Contact Names";
$field2 = "notes";
$field2_label = "Notes";
$deletecnt = $_GET['deletecnt'];
$field1_value=$_POST['field1_value'];
if ($field1_value) {$insert="1";} else {$insert="";}
$field2_value=$_POST['field2_value'];
$category="contact";

if ($user = $this->GetUser()){
if ($insert) {
if($this->LoadUser($field1_value)) {
mysql_query( "INSERT into $table ($field1, $field2, owner, type) values (\"$field1_value\",\"$field2_value\",\"$username\",\"$category\")");
}
}
if ($deletecnt) {
mysql_query( "DELETE from $table WHERE id=$deletecnt AND owner='$username'");
}
if (mysql_errno()!=0) {
switch (mysql_errno()) {
default:
echo "Error #".mysql_errno(). " (".mysql_error(). ")<br>";
}
}
}
$query = "SELECT * from $table WHERE owner='$username' AND type='$category' ORDER BY info ASC";
$result = mysql_query($query);
$rows = mysql_num_rows($result);
echo "<strong><em>Contact Management</em></strong>";
echo "<table border='1' cellspacing='0'>\n";
echo "<tr>\n";
echo "<td><strong>$field1_label</strong></td>\n";
echo "<td><strong>$field2_label</strong></td>\n";
echo "<td> </td>\n";
echo "</tr>\n";
// This is the entry boxes
echo "<form action=\"$link&action=contacts\" method=\"post\">\n";
echo "<tr>\n";
echo "<input type='hidden' name='insert' value='1'></td>\n";
echo "<td><input type='text' size='20' maxlength='65' name='field1_value' value='$addcontact'></td>\n";
echo "<td><input type='text' size='35' maxlength='65' name='field2_value'></td>\n";
echo "<td colspan=2 align=center>";
echo "<input type='submit' value=\" Add \"></td>\n";
echo "</tr>\n";
echo "</form>\n";
// This is the data under the entry boxes
while ($row = mysql_fetch_row($result)) {
echo "<tr>\n";
echo "<td><a href=".$link."&action=compose&to=".$row[2].">".$row[2]."</a><small>  [<a href=".$this->config["base_url"].$row[2].">Home Page</a>]</small></td>\n";
echo "<td>".strip_tags($row[3])."</td>\n";
echo "<td><a href=\"javascript: if(confirm('Are you sure you want to delete this item?')){ window.self.location='".$link."&action=contacts&deletecnt=".$row[4]."' }\"><center>Delete</center></a></td>\n";
echo "</tr>\n";
}
echo "</table>";
echo "<small>Clicking on the contact name will take you to message entry screen.</small>";
}

// code to manage folder list
elseif ($action==folders){
$table = $this->config["table_prefix"]."mailinfo";
$field1 = "info";
$field1_label = "Folder List";
$field2 = "notes";
$field2_label = "Notes";
$deletefldr = $_GET['deletefldr'];
$fldr = $_GET['fldr'];
$field1_value=$_POST['field1_value'];
if ($field1_value) {$insert="1";} else {$insert="";}
$field2_value=$_POST['field2_value'];
$category="folder";

if ($user = $this->GetUser()){
if ($insert) {
mysql_query( "INSERT into $table ($field1, $field2, owner, type) values (\"$field1_value\",\"$field2_value\",\"$username\",\"$category\")");
}

if ($deletefldr) {
// delete folder name from mailinfo
mysql_query("DELETE from $table WHERE id='$deletefldr' AND owner='$username' AND type='folder'");
// change files from being stored in folder being deleted to being stored in inbox
mysql_query("UPDATE ".$this->config["table_prefix"]."mail SET folder='inbox' WHERE folder='$fldr' AND UserTo='$username'");
}

if (mysql_errno()!=0) {
switch (mysql_errno()) {
default:
echo "Error #".mysql_errno(). " (".mysql_error(). ")<br>";
}
}
}
$query = "SELECT * from $table WHERE owner='$username' AND type='$category' ORDER BY info ASC";
$result = mysql_query($query);
$rows = mysql_num_rows($result);
echo "<strong><em>Folder Management</em></strong>";
echo "<table border='1' cellspacing='0'>\n";
echo "<tr>\n";
echo "<td><strong>$field1_label</strong></td>\n";
echo "<td><strong>$field2_label</strong></td>\n";
echo "<td> </td>\n";
echo "</tr>\n";

// This is the entry boxes
echo "<form action=\"$link&action=folders\" method=\"post\">\n";
echo "<tr>\n";
echo "<input type='hidden' name='insert' value='1'></td>\n";
echo "<td><input type='text' size='25' maxlength='65' name='field1_value'></td>\n";
echo "<td><input type='text' size='35' maxlength='65' name='field2_value'></td>\n";
echo "<td colspan='2' align='center'>";
echo "<input type='submit' value=\" Add \"></td>\n";
echo "</tr>\n";
echo "</form>\n";
// This is the data under the entry boxes
while ($row = mysql_fetch_row($result)) {
echo "<tr>\n";
echo "<td><a href=".$link."&folder=".strip_tags($row[2]).">".strip_tags($row[2])."</a></td>\n";
echo "<td>".strip_tags($row[3])."</td>\n";
echo "<td><a href=\"javascript: if(confirm('Are you sure you want to delete this item?')){ window.self.location='".$link."&action=folders&deletefldr=".$row[4]."&fldr=".$row[2]."' }\">
<center>Delete</center></a></td>\n";
}
echo "</table>";
echo "<small>Clicking on the folder name will take you to that folder.</small>";
}

// code to display user list
elseif ($action==users){
echo "<table width='650'><tr><td>";
$last_users = $this->LoadAll("select name from ".$this->config["table_prefix"]."users order by name ASC");
echo "<strong><em>User List.</em></strong> Click on the name to add it to the contact list.<br />";
foreach($last_users as $user)
{
echo "<a href=".$link."&action=contacts&cntct=".$user["name"].">".$user["name"]."</a> ";
}
echo "</td></tr></table>";
}

//code to show brief instructions for using filters
elseif ($action==help){
echo "<table width='700'><tr><td>";
echo "<p><strong>An introduction to sending messages in Wikka...</strong></p>";
echo "There are two brief parts to this help file. The first is how to interpret the output screen. The second is a description of how filters work.<br /><br />";
echo "     <strong><em>Introduction to the output...</em></strong><br /><br />";
echo "Below is a typical output line in the In-Box, Folder lists or the Sent message area.<br /><br />";
echo "<table border='0' width='800'>";
echo "<tr><td valign='middle'>";
echo "<P> <font color='#FF0000'><strong>!* </strong></font><A>Science Class tomorrow</A><font color='#000000'><strong><a title='You have answered this email.'> </a></strong><small>(05Feb05 2:08 pm)</small></FONT><FONT COLOR='#FF0000'><STRONG>*</STRONG></FONT><FONT COLOR='#000000'>  </FONT><FONT COLOR='#008000'><STRONG>*</STRONG></FONT></P>";
echo "</td><td align='center' width='140' valign='middle'>";
echo "<P><a title='Sender'>GmBowen</a><small> [<a title='Put into contact list.'>-></a>]</small></P>";
echo "</td>";
echo "<td width='150' valign='middle'>";
echo "<P><form>";
echo "<P><select name=move2folder>";
echo "<option value=ColeBowen>ColeBowen";
echo "<option value=GmBowen>GmBowen";
echo "<option value=Personal>Personal";
echo "<option value=Work>Work";
echo "</select><input type='button' name='Submit' value='Move'>";
echo "</form></P>";
echo "</td>";
echo "<td align='center' valign='middle' width='60'>";
echo "<P align='center'>[<a>Delete</a>]</P>";
echo "</td>";
echo "<td width='53'>";
echo "<P> <A title='Mark message with a RED star.'></A><FONT COLOR='#FF0000'><STRONG>*</STRONG></FONT>|<A title='Mark message with a BLUE star.'></A><FONT COLOR='#0000FF'><STRONG>*</STRONG></FONT>|<A title='Mark message with a GREEN star.'></A><FONT COLOR='#008000'><STRONG>*</STRONG></FONT><BR>";
echo "</P>";
echo "</TD>";
echo "</TR>";
echo "</TABLE>";
echo "</FONT><FONT COLOR='#000000'><br />Here is how to interpret the output....</FONT></P>";
echo "<UL>";
echo "<LI><FONT COLOR='#000000'>The exclamation mark (</FONT><FONT COLOR='#FF0000'><B>!</B></FONT><FONT COLOR='#000000'>) tells you that the sender marked the message <B>urgent</B>.</FONT></LI>";
echo "<LI><FONT COLOR='#000000'>The first red star (</FONT><FONT COLOR='#FF0000'>*</FONT><FONT COLOR='#000000'>) tells you that you have not read the message yet. </FONT></LI>";
echo "<LI><FONT COLOR='#000000'>'Science Class tomorrow' is the topic of the message.</FONT></LI>";
echo "<LI><FONT COLOR='#000000'>If there were a plus sign (<B>+</B>) immediately after the topic you would know that you had replied to the message. </FONT></LI>";
echo "<LI><FONT COLOR='#000000'>The date/time after the message lets you know when the message was sent. </FONT></LI>";
echo "<LI><FONT COLOR='#000000'>The coloured stars after the date/time (</FONT><FONT COLOR='#FF0000'>* </FONT><FONT COLOR='#000000'> </FONT><FONT COLOR='#00FF00'>*</FONT><FONT COLOR='#000000'>) indicate that you've applied those two markers to your message (see below). </FONT></LI>";
echo "<LI><FONT COLOR='#000000'>'GmBowen' is the sender of the message.</FONT></LI>";
echo "<LI><FONT COLOR='#000000'>The [->] allows you to put the senders name into your contact list. </FONT></LI>";
echo "<LI><FONT COLOR='#000000'>The dropdown menu (starting with 'ColeBowen') is a list of folders that you can file the message into. </FONT></LI>";
echo "<LI><FONT COLOR='#000000'>The [</FONT><FONT COLOR='#0000FF'>Delete</FONT><FONT COLOR='#000000'>] button allows you to delete the message (even though it does stay in the database). </FONT></LI>";
echo "<LI><FONT COLOR='#000000'>Clicking on the three coloured stars (</FONT><FONT COLOR='#FF0000'>*</FONT><FONT COLOR='#000000'>|</FONT><FONT COLOR='#0000FF'>*</FONT><FONT COLOR='#000000'>|</FONT><FONT COLOR='#00CC00'>*</FONT><FONT COLOR='#000000'>) allow you to set markers on your messages.</FONT></LI>";
echo "</UL>";
echo "<br /><br />";
echo "     <strong><em>Introduction to filters...</em></strong><br /><br />";
echo "<P>'Filters' are a simple-to-use tool that can help you organize your\n";
echo "messages.</P>\n";
echo "\n";
echo "<P>When you're in the in-box or any of the folders, on the top right\n";
echo "of the title bar you'll see a +/- with\n";
echo "<FONT COLOR='#FF0000'>*</FONT>|<FONT COLOR='#0000FF'>*</FONT>|<FONT COLOR='#008000'>*\n";
echo "</FONT>underneath it (and to the right of each message). By clicking\n";
echo "on these three coloured stars you can place or remove coloured stars\n";
echo "from beside the message title. A similar feature is found inside each\n";
echo "individual message box (seen when you're reading your messages).</P>\n";
echo "\n";
echo "<P>The different colours can mean anything you want them to. Red\n";
echo "might mean 'really important' and green might mean 'Ignore for now'.\n";
echo "It's really up to you. They can mean different things to you in your\n";
echo "in-box versus your different folders as well</P>\n";
echo "\n";
echo "<P><TABLE>\n";
echo "<TR BGCOLOR='#DDDDDD'>\n";
echo "<TD WIDTH=400>\n";
echo "<P><TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH='100%'>\n";
echo "<TR>\n";
echo "<TD>\n";
echo "<P> Message Topic:</P>\n";
echo "</TD>\n";
echo "<TD ALIGN=right>\n";
echo "<P><STRONG>A</STRONG> <STRONG>N</STRONG> <FONT COLOR='#FF0000'><STRONG>*</STRONG></FONT> <FONT COLOR='#0000FF'><STRONG>*</STRONG></FONT> <STRONG>*</STRONG></P>\n";
echo "</TD>\n";
echo "</TR>\n";
echo "</TABLE>\n";
echo "</P>\n";
echo "</TD>\n";
echo "<TD WIDTH=85>\n";
echo "<P> Sender:</P>\n";
echo "</TD>\n";
echo "<TD WIDTH=155>\n";
echo "<P> Move to Folder:</P>\n";
echo "</TD>\n";
echo "<TD>\n";
echo "<P> Delete:</P>\n";
echo "</TD>\n";
echo "<TD WIDTH=45>\n";
echo "<P>  <STRONG>+</STRONG>/<STRONG>-</STRONG></P>\n";
echo "</TD>\n";
echo "</TR>\n";
echo "</TABLE>\n";
echo "</P>\n";
echo "\n";
echo "<P>On the grey title bar to the right of 'Message Topic:' you can see\n";
echo " <B>A</B> <B>N</B> \n";
echo "<FONT COLOR='#FF0000'>*</FONT> <FONT COLOR='#0000FF'>*</FONT> <FONT COLOR='#008000'>*</FONT></P>\n";
echo "\n";
echo "<P>By clicking on the '<B>A</B>' you'll see all of the messages,\n";
echo "on the '<B>N</B>' you'll see the messages that don't have any markers\n";
echo "beside them, and if you click on any of the coloured stars you'll see\n";
echo "the messages that have those coloured markers beside them.</P>\n";
echo "\n";
echo "<P>Easy eh? </P>\n";
echo "</td></tr></table>";
}
?>
%%

The following file should be saved as ##page.inc.php## in a directory called ##scripts## in the wikka root....
%%(php)
<?php


/*
###############################################
#### ####
#### Author : Harish Chauhan ####
#### Date : 27 Sep,2004 ####
#### Updated: ####
#### ####
###############################################

*/
// Original class script obtained from http://www.phpclasses.org/browse/package/2012.html distributed as "Freeware"
// Modifications (Ver 1.0b) by GmBowen so that script useable with wikka wiki to support a "mail" action developed for the wiki.
// Throughout this class "?page" was changed to "&page" as well as other minor modifications throughout the script.

class Page
{
var $total_records=1; ///Total Records returned by sql query
var $records_per_page=1; ///how many records would be displayed at a time
var $page_name=""; ///page name on which the class is called
var $start=0;
var $page=0;
var $total_page=0;
var $current_page;
var $remain_page;
var $show_prev_next=true;
var $show_scroll_prev_next=false;
var $show_first_last=false;
var $show_disabled_links=true;
var $scroll_page=0;
var $qry_str="";
var $link_para="&";

/* returns boolean value if it is last page or not*/
function is_last_page()
{
return $this->page>=$this->total_page-1?true:false;
}
/* param : Void
returns boolean value if it is first page or not*/
function is_first_page()
{
return $this->page==0?true:false;
}
function current_page()
{
return $this->page+1;
}
function total_page()
{
return $this->total_page==0?1:$this->total_page;
}

//@param : $show = if you want to show disabled links on navigation links.
//
function show_disabled_links($show=TRUE)
{
$this->show_disabled_links=$show;
}
//@param : $link_para = if you want to pass any parameter to link
//
function set_link_parameter($link_para)
{
$this->link_para=$link_para;
}
function set_page_name($page_name)
{
$this->page_name=$page_name;
}
//@param : str= query string you want to pass to links.
function set_qry_string($str="")
{
$this->qry_str="&".$str;
}
function set_scroll_page($scroll_num=0)
{
if($scroll_num!=0)
$this->scroll_page=$scroll_num;
else
$this->scroll_page=$this->total_records;

}
function set_total_records($total_records)
{
if($total_records<0)
$total_records=0;
$this->total_records=$total_records;
}
function set_records_per_page($records_per_page)
{
if($records_per_page<=0)
$records_per_page=$this->total_records;
$this->records_per_page=$records_per_page;
}
/* @params
* $page_name = Page name on which class is integrated. i.e. $_SERVER['PHP_SELF']
* $total_records=Total records returnd by sql query.
* $records_per_page=How many projects would be displayed at a time
* $scroll_num= How many pages scrolled if we click on scroll page link.
* i.e if we want to scroll 6 pages at a time then pass argument 6.
* $show_prev_next= boolean(true/false) to show prev Next Link
* $show_scroll_prev_next= boolean(true/false) to show scrolled prev Next Link
* $show_first_last= boolean(true/false) to show first last Link to move first and last page.
*/

function set_page_data($page_name,$total_records,$records_per_page=1,$scroll_num=0,$show_prev_next=true,$show_scroll_prev_next=false,$show_first_last=false)
{
$this->set_total_records($total_records);
$this->set_records_per_page($records_per_page);
$this->set_scroll_page($scroll_num);
$this->set_page_name($page_name);
$this->show_prev_next=$show_prev_next;
$this->show_scroll_prev_next=$show_scroll_prev_next;
$this->show_first_last=$show_first_last;
}
/* @params
* $user_link= if you want to display your link i.e if you want to user '>>' instead of [first] link then use
Page::get_first_page_nav(">>") OR for image
Page::get_first_page_nav("<img src='' alt='first'>")
$link_para: link parameters i.e if you want ot use another parameters such as class.
Page::get_first_page_nav(">>","class=myStyleSheetClass")
*/
function get_first_page_nav($user_link="",$link_para="")
{
if($this->total_page<=1)
return;
if(trim($user_link)=="")
$user_link="««  ";
if(!$this->is_first_page()&& $this->show_first_last)
echo ' <a href="'.$this->page_name.'&page=0'.$this->qry_str.'" '.$link_para.'>'.$user_link.'</a> ';
elseif($this->show_first_last && $this->show_disabled_links)
echo $user_link;
}
function get_last_page_nav($user_link="",$link_para="")
{
if($this->total_page<=1)
return;
if(trim($user_link)=="")
$user_link="  Â»Â»";
if(!$this->is_last_page()&& $this->show_first_last)
echo ' <a href="'.$this->page_name.'&page='.($this->total_page-1).$this->qry_str.'" '.$link_para.'>'.$user_link.'</a> ';
elseif($this->show_first_last && $this->show_disabled_links)
echo $user_link;
}
function get_next_page_nav($user_link="",$link_para="")
{
if($this->total_page<=1)
return;
if(trim($user_link)=="")
$user_link=" »";
if(!$this->is_last_page()&& $this->show_prev_next)
echo ' <a href="'.$this->page_name.'&page='.($this->page+1).$this->qry_str.'" '.$link_para.'>'.$user_link.'</a> ';
elseif($this->show_prev_next && $this->show_disabled_links)
echo $user_link." ";
}
function get_prev_page_nav($user_link="",$link_para="")
{
if($this->total_page<=1)
return;
if(trim($user_link)=="")
$user_link="« ";
if(!$this->is_first_page()&& $this->show_prev_next)
echo ' <a href="'.$this->page_name.'&page='.($this->page-1).$this->qry_str.'" '.$link_para.'>'.$user_link.'</a> ';
elseif($this->show_prev_next && $this->show_disabled_links)
echo " ".$user_link;
}
function get_scroll_prev_page_nav($user_link="",$link_para="")
{

if($this->scroll_page>=$this->total_page)
return;
if(trim($user_link)=="")
$user_link="[-$this->scroll_page]";
if($this->page>$this->scroll_page &&$this->show_scroll_prev_next)
echo ' <a href="'.$this->page_name.'&page='.($this->page-$this->scroll_page).$this->qry_str.'" '.$link_para.'>'.$user_link.'</a> ';
elseif($this->show_scroll_prev_next && $this->show_disabled_links)
echo $user_link;
}
function get_scroll_next_page_nav($user_link="",$link_para="")
{
if($this->scroll_page>=$this->total_page)
return;
if(trim($user_link)=="")
$user_link="[+$this->scroll_page]";
if($this->total_page>$this->page+$this->scroll_page &&$this->show_scroll_prev_next)
echo ' <a href="'.$this->page_name.'&page='.($this->page+$this->scroll_page).$this->qry_str.'" '.$link_para.'>'.$user_link.'</a> ';
elseif($this->show_scroll_prev_next && $this->show_disabled_links)
echo $user_link;
}

function get_number_page_nav($link_para="")
{
$j=0;
$scroll_page=$this->scroll_page;
if($this->page>($scroll_page/2))
$j=$this->page-intval($scroll_page/2);
if($j+$scroll_page>$this->total_page)
$j=$this->total_page-$scroll_page;

if($j<0)
$i=0;
else
$i=$j;

for(;$i<$j+$scroll_page && $i<$this->total_records;$i++)
{
if($i==$this->page)
echo ($i+1);
else
echo ' <a href="'.$this->page_name.'&page='.$i.$this->qry_str.'" '.$link_para.'>'.($i+1).'</a> ';
}
}

function get_page_nav()
{
if($this->total_records<=0)
{
//echo "No Records Found";
// return false;
}
$this->calculate();
$this->get_first_page_nav("",$this->link_para);
$this->get_scroll_prev_page_nav("",$this->link_para);
$this->get_prev_page_nav("",$this->link_para);
$this->get_number_page_nav($this->link_para);
$this->get_next_page_nav("",$this->link_para);
$this->get_scroll_next_page_nav("",$this->link_para);
$this->get_last_page_nav("",$this->link_para);
// return true;
}
function calculate()
{
$this->page=$_REQUEST['page'];
if(!is_numeric($this->page))
$this->page=0;
$this->start=$this->page*$this->records_per_page;
$this->total_page=@intval($this->total_records/$this->records_per_page);
if($this->total_records%$this->records_per_page!=0)
$this->total_page++;
}
function get_limit_query($qry="")
{
$this->calculate();
return $qry." LIMIT $this->start,$this->records_per_page";
}
}
?>
%%

This is the inbox (note the * indicator in the header that there is unread mail, + indicator for answered mail, and the marker/filter system)...

http://gmbowen.educ.unb.ca/wikitest/pms1.jpg

This is the "compose" box (note the contact list...clicking on a name enters it into the "to" box)...

http://gmbowen.educ.unb.ca/wikitest/pms2.jpg

This is a listing of "sent" files (note the indicator of whether they'd been read or not)...

http://gmbowen.educ.unb.ca/wikitest/pms3.jpg

This is the contents of a folder...

http://gmbowen.educ.unb.ca/wikitest/pms4.jpg

This is a listing of the contacts & where they are managed...

http://gmbowen.educ.unb.ca/wikitest/pms5.jpg

This is a list of the registered users....

http://gmbowen.educ.unb.ca/wikitest/pms6.jpg

This is a listing of the folders & where they are managed....

http://gmbowen.educ.unb.ca/wikitest/pms7.jpg

This is an example message...

http://gmbowen.educ.unb.ca/wikitest/pms8.jpg

This demonstrates a "compose" form after "forward" has been clicked....

http://gmbowen.educ.unb.ca/wikitest/pms9.jpg

This image is a "reply" message (you cannot change the "to" or the "subject" block)

http://gmbowen.educ.unb.ca/wikitest/pms10.jpg

----
**To upgrade your mail.php from version 1.0 to 1.5 do the following.....**

1) Use the following mysql statements (in your fvaourite mysql administration program, or at the command line if you know how) to update the table structure in your wikki database. Make sure you change "WAKKAPREFIX" to the prefix you use in your wikka.

ALTER TABLE `WAKKAPREFIX_mail`
ADD `repliedto` TINYINT (1) DEFAULT '0' AFTER `Message` ,
ADD `urgent` TINYINT (1) DEFAULT NULL AFTER `repliedto` ,
ADD `fltr1` TINYINT (1) DEFAULT '0' NOT NULL AFTER `urgent` ,
ADD `fltr2` TINYINT (1) DEFAULT '0' NOT NULL AFTER `fltr1` ,
ADD `fltr3` TINYINT (1) DEFAULT '0' NOT NULL AFTER `fltr2` ,
ADD `DateSent` DATETIME NOT NULL AFTER `fltr3`

2) THEN RUN THE PHP SCRIPT mailupdate.php as an ACTION (you can only do this as a designated administrator). Save the php code below as mailupdate.php, insert on a page, and then click on the visible link. This will alter the date code from a text string to a mysql DATETIME string (makes it easier to display date & time).

%%(php)
if ($this->IsAdmin()) {
$link = $this->config["base_url"].$this->MiniHref($method, $tag);
echo "<a href=".$link."&action=update>Update database for mail.php from version 1.0 to version 1.5</a>";
$action=$_GET['action'];
if($action==update){
$query="SELECT SentDate,DateSent FROM ".$this->config["table_prefix"]."mail";
$result=mysql_query($query) or die ("cant do it");
while ($row=mysql_fetch_array($result)) {
$newdate=$row[SentDate];
mysql_query("UPDATE ".$this->config["table_prefix"]."mail SET DateSent=$newdate WHERE SentDate=$newdate");
}
if ($_GET['action']) {echo "Database update complete.";}
}
}
%%

Erase the update file from you actions directory.

3) Then install the new mail.php file. (erase the old one, replace with the new one.) You may or may want to put your wiki into "administrative mode" so that others cannot use it while you do this. (See these [[http://wikka.jsnx.com/UpgradeNotes notes]] for upgrading wikka.)

4) Finally, remove the ""SentDate"" field from the mysql table WAKKAPREFIX_mail using the following command. (Make sure you change "WAKKAPREFIX" to the prefix you use in your wikka.)

ALTER TABLE `WAKKAPREFIX_mail` DROP `SentDate`

That's it. This upgrade sequence has been tested on two sites and worked without a problem.

----


Revision [5818]

Edited on 2005-02-09 05:37:32 by GmBowen [improve filter in folders view - minor code update]
Additions:
====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.
%%(sql)
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)
<?php
<?php
// This mail.php (Version 1.5c) 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><b>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["table_prefix"]."mailinfo";
$field1 = "info";
$field1_label = "Contact Names";
$field2 = "notes";
$field2_label = "Notes";
$deletecnt = $_GET['deletecnt'];
$field1_value=$_POST['field1_value'];
if ($field1_value) {$insert="1";} else {$insert="";}
$field2_value=$_POST['field2_value'];
$category="contact";

if ($user = $this->GetUser()){
if ($insert) {
if($this->LoadUser($field1_value)) {
mysql_query( "INSERT into $table ($field1, $field2, owner, type) values (\"$field1_value\",\"$field2_value\",\"$username\",\"$category\")");
}
}
if ($deletecnt) {
mysql_query( "DELETE from $table WHERE id=$deletecnt AND owner='$username'");
}
if (mysql_errno()!=0) {
switch (mysql_errno()) {
default:
echo "Error #".mysql_errno(). " (".mysql_error(). ")<br>";
}
}
}
$query = "SELECT * from $table WHERE owner='$username' AND type='$category' ORDER BY info ASC";
$result = mysql_query($query);
$rows = mysql_num_rows($result);
echo "<strong><em>Contact Management</em></strong>";
echo "<table border='1' cellspacing='0'>\n";
echo "<tr>\n";
echo "<td><strong>$field1_label</strong></td>\n";
echo "<td><strong>$field2_label</strong></td>\n";
echo "<td> </td>\n";
echo "</tr>\n";
// This is the entry boxes
echo "<form action=\"$link&action=contacts\" method=\"post\">\n";
echo "<tr>\n";
echo "<input type='hidden' name='insert' value='1'></td>\n";
echo "<td><input type='text' size='20' maxlength='65' name='field1_value' value='$addcontact'></td>\n";
echo "<td><input type='text' size='35' maxlength='65' name='field2_value'></td>\n";
echo "<td colspan=2 align=center>";
echo "<input type='submit' value=\" Add \"></td>\n";
echo "</tr>\n";
echo "</form>\n";
// This is the data under the entry boxes
while ($row = mysql_fetch_row($result)) {
echo "<tr>\n";
echo "<td><a href=".$link."&action=compose&to=".$row[2].">".$row[2]."</a><small>  [<a href=".$this->config["base_url"].$row[2].">Home Page</a>]</small></td>\n";
echo "<td>".strip_tags($row[3])."</td>\n";
echo "<td><a href=\"javascript: if(confirm('Are you sure you want to delete this item?')){ window.self.location='".$link."&action=contacts&deletecnt=".$row[4]."' }\"><center>Delete</center></a></td>\n";
echo "</tr>\n";
}
echo "</table>";
echo "<small>Clicking on the contact name will take you to message entry screen.</small>";
}

// code to manage folder list
elseif ($action==folders){
$table = $this->config["table_prefix"]."mailinfo";
$field1 = "info";
$field1_label = "Folder List";
$field2 = "notes";
$field2_label = "Notes";
$deletefldr = $_GET['deletefldr'];
$fldr = $_GET['fldr'];
$field1_value=$_POST['field1_value'];
if ($field1_value) {$insert="1";} else {$insert="";}
$field2_value=$_POST['field2_value'];
$category="folder";

if ($user = $this->GetUser()){
if ($insert) {
mysql_query( "INSERT into $table ($field1, $field2, owner, type) values (\"$field1_value\",\"$field2_value\",\"$username\",\"$category\")");
}

if ($deletefldr) {
// delete folder name from mailinfo
mysql_query("DELETE from $table WHERE id='$deletefldr' AND owner='$username' AND type='folder'");
// change files from being stored in folder being deleted to being stored in inbox
mysql_query("UPDATE ".$this->config["table_prefix"]."mail SET folder='inbox' WHERE folder='$fldr' AND UserTo='$username'");
}

if (mysql_errno()!=0) {
switch (mysql_errno()) {
default:
echo "Error #".mysql_errno(). " (".mysql_error(). ")<br>";
}
}
}
$query = "SELECT * from $table WHERE owner='$username' AND type='$category' ORDER BY info ASC";
$result = mysql_query($query);
$rows = mysql_num_rows($result);
echo "<strong><em>Folder Management</em></strong>";
echo "<table border='1' cellspacing='0'>\n";
echo "<tr>\n";
echo "<td><strong>$field1_label</strong></td>\n";
echo "<td><strong>$field2_label</strong></td>\n";
echo "<td> </td>\n";
echo "</tr>\n";

// This is the entry boxes
echo "<form action=\"$link&action=folders\" method=\"post\">\n";
echo "<tr>\n";
echo "<input type='hidden' name='insert' value='1'></td>\n";
echo "<td><input type='text' size='25' maxlength='65' name='field1_value'></td>\n";
echo "<td><input type='text' size='35' maxlength='65' name='field2_value'></td>\n";
echo "<td colspan='2' align='center'>";
echo "<input type='submit' value=\" Add \"></td>\n";
echo "</tr>\n";
echo "</form>\n";
// This is the data under the entry boxes
while ($row = mysql_fetch_row($result)) {
echo "<tr>\n";
echo "<td><a href=".$link."&folder=".strip_tags($row[2]).">".strip_tags($row[2])."</a></td>\n";
echo "<td>".strip_tags($row[3])."</td>\n";
echo "<td><a href=\"javascript: if(confirm('Are you sure you want to delete this item?')){ window.self.location='".$link."&action=folders&deletefldr=".$row[4]."&fldr=".$row[2]."' }\">
<center>Delete</center></a></td>\n";
}
echo "</table>";
echo "<small>Clicking on the folder name will take you to that folder.</small>";
}

// code to display user list
elseif ($action==users){
echo "<table width='650'><tr><td>";
$last_users = $this->LoadAll("select name from ".$this->config["table_prefix"]."users order by name ASC");
echo "<strong><em>User List.</em></strong> Click on the name to add it to the contact list.<br />";
foreach($last_users as $user)
{
echo "<a href=".$link."&action=contacts&cntct=".$user["name"].">".$user["name"]."</a> ";
}
echo "</td></tr></table>";
}

//code to show brief instructions for using filters
elseif ($action==help){
echo "<table width='700'><tr><td>";
echo "<p><strong>An introduction to sending messages in Wikka...</strong></p>";
echo "There are two brief parts to this help file. The first is how to interpret the output screen. The second is a description of how filters work.<br /><br />";
echo "     <strong><em>Introduction to the output...</em></strong><br /><br />";
echo "Below is a typical output line in the In-Box, Folder lists or the Sent message area.<br /><br />";
echo "<table border='0' width='800'>";
echo "<tr><td valign='middle'>";
echo "<P> <font color='#FF0000'><strong>!* </strong></font><A>Science Class tomorrow</A><font color='#000000'><strong><a title='You have answered this email.'> </a></strong><small>(05Feb05 2:08 pm)</small></FONT><FONT COLOR='#FF0000'><STRONG>*</STRONG></FONT><FONT COLOR='#000000'>  </FONT><FONT COLOR='#008000'><STRONG>*</STRONG></FONT></P>";
echo "</td><td align='center' width='140' valign='middle'>";
echo "<P><a title='Sender'>GmBowen</a><small> [<a title='Put into contact list.'>-></a>]</small></P>";
echo "</td>";
echo "<td width='150' valign='middle'>";
echo "<P><form>";
echo "<P><select name=move2folder>";
echo "<option value=ColeBowen>ColeBowen";
echo "<option value=GmBowen>GmBowen";
echo "<option value=Personal>Personal";
echo "<option value=Work>Work";
echo "</select><input type='button' name='Submit' value='Move'>";
echo "</form></P>";
echo "</td>";
echo "<td align='center' valign='middle' width='60'>";
echo "<P align='center'>[<a>Delete</a>]</P>";
echo "</td>";
echo "<td width='53'>";
echo "<P> <A title='Mark message with a RED star.'></A><FONT COLOR='#FF0000'><STRONG>*</STRONG></FONT>|<A title='Mark message with a BLUE star.'></A><FONT COLOR='#0000FF'><STRONG>*</STRONG></FONT>|<A title='Mark message with a GREEN star.'></A><FONT COLOR='#008000'><STRONG>*</STRONG></FONT><BR>";
echo "</P>";
echo "</TD>";
echo "</TR>";
echo "</TABLE>";
echo "</FONT><FONT COLOR='#000000'><br />Here is how to interpret the output....</FONT></P>";
echo "<UL>";
echo "<LI><FONT COLOR='#000000'>The exclamation mark (</FONT><FONT COLOR='#FF0000'><B>!</B></FONT><FONT COLOR='#000000'>) tells you that the sender marked the message <B>urgent</B>.</FONT></LI>";
echo "<LI><FONT COLOR='#000000'>The first red star (</FONT><FONT COLOR='#FF0000'>*</FONT><FONT COLOR='#000000'>) tells you that you have not read the message yet. </FONT></LI>";
echo "<LI><FONT COLOR='#000000'>'Science Class tomorrow' is the topic of the message.</FONT></LI>";
echo "<LI><FONT COLOR='#000000'>If there were a plus sign (<B>+</B>) immediately after the topic you would know that you had replied to the message. </FONT></LI>";
echo "<LI><FONT COLOR='#000000'>The date/time after the message lets you know when the message was sent. </FONT></LI>";
echo "<LI><FONT COLOR='#000000'>The coloured stars after the date/time (</FONT><FONT COLOR='#FF0000'>* </FONT><FONT COLOR='#000000'> </FONT><FONT COLOR='#00FF00'>*</FONT><FONT COLOR='#000000'>) indicate that you've applied those two markers to your message (see below). </FONT></LI>";
echo "<LI><FONT COLOR='#000000'>'GmBowen' is the sender of the message.</FONT></LI>";
echo "<LI><FONT COLOR='#000000'>The [->] allows you to put the senders name into your contact list. </FONT></LI>";
echo "<LI><FONT COLOR='#000000'>The dropdown menu (starting with 'ColeBowen') is a list of folders that you can file the message into. </FONT></LI>";
echo "<LI><FONT COLOR='#000000'>The [</FONT><FONT COLOR='#0000FF'>Delete</FONT><FONT COLOR='#000000'>] button allows you to delete the message (even though it does stay in the database). </FONT></LI>";
echo "<LI><FONT COLOR='#000000'>Clicking on the three coloured stars (</FONT><FONT COLOR='#FF0000'>*</FONT><FONT COLOR='#000000'>|</FONT><FONT COLOR='#0000FF'>*</FONT><FONT COLOR='#000000'>|</FONT><FONT COLOR='#00CC00'>*</FONT><FONT COLOR='#000000'>) allow you to set markers on your messages.</FONT></LI>";
echo "</UL>";
echo "<br /><br />";
echo "     <strong><em>Introduction to filters...</em></strong><br /><br />";
echo "<P>'Filters' are a simple-to-use tool that can help you organize your\n";
echo "messages.</P>\n";
echo "\n";
echo "<P>When you're in the in-box or any of the folders, on the top right\n";
echo "of the title bar you'll see a +/- with\n";
echo "<FONT COLOR='#FF0000'>*</FONT>|<FONT COLOR='#0000FF'>*</FONT>|<FONT COLOR='#008000'>*\n";
echo "</FONT>underneath it (and to the right of each message). By clicking\n";
echo "on these three coloured stars you can place or remove coloured stars\n";
echo "from beside the message title. A similar feature is found inside each\n";
echo "individual message box (seen when you're reading your messages).</P>\n";
echo "\n";
echo "<P>The different colours can mean anything you want them to. Red\n";
echo "might mean 'really important' and green might mean 'Ignore for now'.\n";
echo "It's really up to you. They can mean different things to you in your\n";
echo "in-box versus your different folders as well</P>\n";
echo "\n";
echo "<P><TABLE>\n";
echo "<TR BGCOLOR='#DDDDDD'>\n";
echo "<TD WIDTH=400>\n";
echo "<P><TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH='100%'>\n";
echo "<TR>\n";
echo "<TD>\n";
echo "<P> Message Topic:</P>\n";
echo "</TD>\n";
echo "<TD ALIGN=right>\n";
echo "<P><STRONG>A</STRONG> <STRONG>N</STRONG> <FONT COLOR='#FF0000'><STRONG>*</STRONG></FONT> <FONT COLOR='#0000FF'><STRONG>*</STRONG></FONT> <STRONG>*</STRONG></P>\n";
echo "</TD>\n";
echo "</TR>\n";
echo "</TABLE>\n";
echo "</P>\n";
echo "</TD>\n";
echo "<TD WIDTH=85>\n";
echo "<P> Sender:</P>\n";
echo "</TD>\n";
echo "<TD WIDTH=155>\n";
echo "<P> Move to Folder:</P>\n";
echo "</TD>\n";
echo "<TD>\n";
echo "<P> Delete:</P>\n";
echo "</TD>\n";
echo "<TD WIDTH=45>\n";
echo "<P>  <STRONG>+</STRONG>/<STRONG>-</STRONG></P>\n";
echo "</TD>\n";
echo "</TR>\n";
echo "</TABLE>\n";
echo "</P>\n";
echo "\n";
echo "<P>On the grey title bar to the right of 'Message Topic:' you can see\n";
echo " <B>A</B> <B>N</B> \n";
echo "<FONT COLOR='#FF0000'>*</FONT> <FONT COLOR='#0000FF'>*</FONT> <FONT COLOR='#008000'>*</FONT></P>\n";
echo "\n";
echo "<P>By clicking on the '<B>A</B>' you'll see all of the messages,\n";
echo "on the '<B>N</B>' you'll see the messages that don't have any markers\n";
echo "beside them, and if you click on any of the coloured stars you'll see\n";
echo "the messages that have those coloured markers beside them.</P>\n";
echo "\n";
echo "<P>Easy eh? </P>\n";
echo "</td></tr></table>";
}
?>
%%

The following file should be saved as ##page.inc.php## in a directory called ##scripts## in the wikka root....
%%(php)
<?php


/*
###############################################
#### ####
#### Author : Harish Chauhan ####
#### Date : 27 Sep,2004 ####
#### Updated: ####
#### ####
###############################################

*/
// Original class script obtained from http://www.phpclasses.org/browse/package/2012.html distributed as "Freeware"
// Modifications (Ver 1.0b) by GmBowen so that script useable with wikka wiki to support a "mail" action developed for the wiki.
// Throughout this class "?page" was changed to "&page" as well as other minor modifications throughout the script.

class Page
{
var $total_records=1; ///Total Records returned by sql query
var $records_per_page=1; ///how many records would be displayed at a time
var $page_name=""; ///page name on which the class is called
var $start=0;
var $page=0;
var $total_page=0;
var $current_page;
var $remain_page;
var $show_prev_next=true;
var $show_scroll_prev_next=false;
var $show_first_last=false;
var $show_disabled_links=true;
var $scroll_page=0;
var $qry_str="";
var $link_para="&";

/* returns boolean value if it is last page or not*/
function is_last_page()
{
return $this->page>=$this->total_page-1?true:false;
}
/* param : Void
returns boolean value if it is first page or not*/
function is_first_page()
{
return $this->page==0?true:false;
}
function current_page()
{
return $this->page+1;
}
function total_page()
{
return $this->total_page==0?1:$this->total_page;
}

//@param : $show = if you want to show disabled links on navigation links.
//
function show_disabled_links($show=TRUE)
{
$this->show_disabled_links=$show;
}
//@param : $link_para = if you want to pass any parameter to link
//
function set_link_parameter($link_para)
{
$this->link_para=$link_para;
}
function set_page_name($page_name)
{
$this->page_name=$page_name;
}
//@param : str= query string you want to pass to links.
function set_qry_string($str="")
{
$this->qry_str="&".$str;
}
function set_scroll_page($scroll_num=0)
{
if($scroll_num!=0)
$this->scroll_page=$scroll_num;
else
$this->scroll_page=$this->total_records;

}
function set_total_records($total_records)
{
if($total_records<0)
$total_records=0;
$this->total_records=$total_records;
}
function set_records_per_page($records_per_page)
{
if($records_per_page<=0)
$records_per_page=$this->total_records;
$this->records_per_page=$records_per_page;
}
/* @params
* $page_name = Page name on which class is integrated. i.e. $_SERVER['PHP_SELF']
* $total_records=Total records returnd by sql query.
* $records_per_page=How many projects would be displayed at a time
* $scroll_num= How many pages scrolled if we click on scroll page link.
* i.e if we want to scroll 6 pages at a time then pass argument 6.
* $show_prev_next= boolean(true/false) to show prev Next Link
* $show_scroll_prev_next= boolean(true/false) to show scrolled prev Next Link
* $show_first_last= boolean(true/false) to show first last Link to move first and last page.
*/

function set_page_data($page_name,$total_records,$records_per_page=1,$scroll_num=0,$show_prev_next=true,$show_scroll_prev_next=false,$show_first_last=false)
{
$this->set_total_records($total_records);
$this->set_records_per_page($records_per_page);
$this->set_scroll_page($scroll_num);
$this->set_page_name($page_name);
$this->show_prev_next=$show_prev_next;
$this->show_scroll_prev_next=$show_scroll_prev_next;
$this->show_first_last=$show_first_last;
}
/* @params
* $user_link= if you want to display your link i.e if you want to user '>>' instead of [first] link then use
Page::get_first_page_nav(">>") OR for image
Page::get_first_page_nav("<img src='' alt='first'>")
$link_para: link parameters i.e if you want ot use another parameters such as class.
Page::get_first_page_nav(">>","class=myStyleSheetClass")
*/
function get_first_page_nav($user_link="",$link_para="")
{
if($this->total_page<=1)
return;
if(trim($user_link)=="")
$user_link="««  ";
if(!$this->is_first_page()&& $this->show_first_last)
echo ' <a href="'.$this->page_name.'&page=0'.$this->qry_str.'" '.$link_para.'>'.$user_link.'</a> ';
elseif($this->show_first_last && $this->show_disabled_links)
echo $user_link;
}
function get_last_page_nav($user_link="",$link_para="")
{
if($this->total_page<=1)
return;
if(trim($user_link)=="")
$user_link="  Â»Â»";
if(!$this->is_last_page()&& $this->show_first_last)
echo ' <a href="'.$this->page_name.'&page='.($this->total_page-1).$this->qry_str.'" '.$link_para.'>'.$user_link.'</a> ';
elseif($this->show_first_last && $this->show_disabled_links)
echo $user_link;
}
function get_next_page_nav($user_link="",$link_para="")
{
if($this->total_page<=1)
return;
if(trim($user_link)=="")
$user_link=" »";
if(!$this->is_last_page()&& $this->show_prev_next)
echo ' <a href="'.$this->page_name.'&page='.($this->page+1).$this->qry_str.'" '.$link_para.'>'.$user_link.'</a> ';
elseif($this->show_prev_next && $this->show_disabled_links)
echo $user_link." ";
}
function get_prev_page_nav($user_link="",$link_para="")
{
if($this->total_page<=1)
return;
if(trim($user_link)=="")
$user_link="« ";
if(!$this->is_first_page()&& $this->show_prev_next)
echo ' <a href="'.$this->page_name.'&page='.($this->page-1).$this->qry_str.'" '.$link_para.'>'.$user_link.'</a> ';
elseif($this->show_prev_next && $this->show_disabled_links)
echo " ".$user_link;
}
function get_scroll_prev_page_nav($user_link="",$link_para="")
{

if($this->scroll_page>=$this->total_page)
return;
if(trim($user_link)=="")
$user_link="[-$this->scroll_page]";
if($this->page>$this->scroll_page &&$this->show_scroll_prev_next)
echo ' <a href="'.$this->page_name.'&page='.($this->page-$this->scroll_page).$this->qry_str.'" '.$link_para.'>'.$user_link.'</a> ';
elseif($this->show_scroll_prev_next && $this->show_disabled_links)
echo $user_link;
}
function get_scroll_next_page_nav($user_link="",$link_para="")
{
if($this->scroll_page>=$this->total_page)
return;
if(trim($user_link)=="")
$user_link="[+$this->scroll_page]";
if($this->total_page>$this->page+$this->scroll_page &&$this->show_scroll_prev_next)
echo ' <a href="'.$this->page_name.'&page='.($this->page+$this->scroll_page).$this->qry_str.'" '.$link_para.'>'.$user_link.'</a> ';
elseif($this->show_scroll_prev_next && $this->show_disabled_links)
echo $user_link;
}

function get_number_page_nav($link_para="")
{
$j=0;
$scroll_page=$this->scroll_page;
if($this->page>($scroll_page/2))
$j=$this->page-intval($scroll_page/2);
if($j+$scroll_page>$this->total_page)
$j=$this->total_page-$scroll_page;

if($j<0)
$i=0;
else
$i=$j;

for(;$i<$j+$scroll_page && $i<$this->total_records;$i++)
{
if($i==$this->page)
echo ($i+1);
else
echo ' <a href="'.$this->page_name.'&page='.$i.$this->qry_str.'" '.$link_para.'>'.($i+1).'</a> ';
}
}

function get_page_nav()
{
if($this->total_records<=0)
{
//echo "No Records Found";
// return false;
}
$this->calculate();
$this->get_first_page_nav("",$this->link_para);
$this->get_scroll_prev_page_nav("",$this->link_para);
$this->get_prev_page_nav("",$this->link_para);
$this->get_number_page_nav($this->link_para);
$this->get_next_page_nav("",$this->link_para);
$this->get_scroll_next_page_nav("",$this->link_para);
$this->get_last_page_nav("",$this->link_para);
// return true;
}
function calculate()
{
$this->page=$_REQUEST['page'];
if(!is_numeric($this->page))
$this->page=0;
$this->start=$this->page*$this->records_per_page;
$this->total_page=@intval($this->total_records/$this->records_per_page);
if($this->total_records%$this->records_per_page!=0)
$this->total_page++;
}
function get_limit_query($qry="")
{
$this->calculate();
return $qry." LIMIT $this->start,$this->records_per_page";
}
}
?>
%%

This is the inbox (note the * indicator in the header that there is unread mail, + indicator for answered mail, and the marker/filter system)...

http://gmbowen.educ.unb.ca/wikitest/pms1.jpg

This is the "compose" box (note the contact list...clicking on a name enters it into the "to" box)...

http://gmbowen.educ.unb.ca/wikitest/pms2.jpg

This is a listing of "sent" files (note the indicator of whether they'd been read or not)...

http://gmbowen.educ.unb.ca/wikitest/pms3.jpg

This is the contents of a folder...

http://gmbowen.educ.unb.ca/wikitest/pms4.jpg

This is a listing of the contacts & where they are managed...

http://gmbowen.educ.unb.ca/wikitest/pms5.jpg

This is a list of the registered users....

http://gmbowen.educ.unb.ca/wikitest/pms6.jpg

This is a listing of the folders & where they are managed....

http://gmbowen.educ.unb.ca/wikitest/pms7.jpg

This is an example message...

http://gmbowen.educ.unb.ca/wikitest/pms8.jpg

This demonstrates a "compose" form after "forward" has been clicked....

http://gmbowen.educ.unb.ca/wikitest/pms9.jpg

This image is a "reply" message (you cannot change the "to" or the "subject" block)

http://gmbowen.educ.unb.ca/wikitest/pms10.jpg

----
**To upgrade your mail.php from version 1.0 to 1.5 do the following.....**

1) Use the following mysql statements (in your fvaourite mysql administration program, or at the command line if you know how) to update the table structure in your wikki database. Make sure you change "WAKKAPREFIX" to the prefix you use in your wikka.

ALTER TABLE `WAKKAPREFIX_mail`
ADD `repliedto` TINYINT (1) DEFAULT '0' AFTER `Message` ,
ADD `urgent` TINYINT (1) DEFAULT NULL AFTER `repliedto` ,
ADD `fltr1` TINYINT (1) DEFAULT '0' NOT NULL AFTER `urgent` ,
ADD `fltr2` TINYINT (1) DEFAULT '0' NOT NULL AFTER `fltr1` ,
ADD `fltr3` TINYINT (1) DEFAULT '0' NOT NULL AFTER `fltr2` ,
ADD `DateSent` DATETIME NOT NULL AFTER `fltr3`

2) THEN RUN THE PHP SCRIPT mailupdate.php as an ACTION (you can only do this as a designated administrator). Save the php code below as mailupdate.php, insert on a page, and then click on the visible link. This will alter the date code from a text string to a mysql DATETIME string (makes it easier to display date & time).

%%(php)
if ($this->IsAdmin()) {
$link = $this->config["base_url"].$this->MiniHref($method, $tag);
echo "<a href=".$link."&action=update>Update database for mail.php from version 1.0 to version 1.5</a>";
$action=$_GET['action'];
if($action==update){
$query="SELECT SentDate,DateSent FROM ".$this->config["table_prefix"]."mail";
$result=mysql_query($query) or die ("cant do it");
while ($row=mysql_fetch_array($result)) {
$newdate=$row[SentDate];
mysql_query("UPDATE ".$this->config["table_prefix"]."mail SET DateSent=$newdate WHERE SentDate=$newdate");
}
if ($_GET['action']) {echo "Database update complete.";}
}
}
%%

Erase the update file from you actions directory.

3) Then install the new mail.php file. (erase the old one, replace with the new one.) You may or may want to put your wiki into "administrative mode" so that others cannot use it while you do this. (See these [[http://wikka.jsnx.com/UpgradeNotes notes]] for upgrading wikka.)

4) Finally, remove the ""SentDate"" field from the mysql table WAKKAPREFIX_mail using the following command. (Make sure you change "WAKKAPREFIX" to the prefix you use in your wikka.)

ALTER TABLE `WAKKAPREFIX_mail` DROP `SentDate`

That's it. This upgrade sequence has been tested on two sites and worked without a problem.

----
Deletions:
====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.
%%(sql)
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)
<?php
// This mail.php (Version 1.5b) 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."><font color='red'><strong>*</strong></font></a>|<a href=".$link."&fltrset=2&mail_id=".$row[mail_id]."&folder=".$which."><font color='blue'><strong>*</strong></font></a>|<a href=".$link."&fltrset=3&mail_id=".$row[mail_id]."&folder=".$which."><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><b>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["table_prefix"]."mailinfo";
$field1 = "info";
$field1_label = "Contact Names";
$field2 = "notes";
$field2_label = "Notes";
$deletecnt = $_GET['deletecnt'];
$field1_value=$_POST['field1_value'];
if ($field1_value) {$insert="1";} else {$insert="";}
$field2_value=$_POST['field2_value'];
$category="contact";

if ($user = $this->GetUser()){
if ($insert) {
if($this->LoadUser($field1_value)) {
mysql_query( "INSERT into $table ($field1, $field2, owner, type) values (\"$field1_value\",\"$field2_value\",\"$username\",\"$category\")");
}
}
if ($deletecnt) {
mysql_query( "DELETE from $table WHERE id=$deletecnt AND owner='$username'");
}
if (mysql_errno()!=0) {
switch (mysql_errno()) {
default:
echo "Error #".mysql_errno(). " (".mysql_error(). ")<br>";
}
}
}
$query = "SELECT * from $table WHERE owner='$username' AND type='$category' ORDER BY info ASC";
$result = mysql_query($query);
$rows = mysql_num_rows($result);
echo "<strong><em>Contact Management</em></strong>";
echo "<table border='1' cellspacing='0'>\n";
echo "<tr>\n";
echo "<td><strong>$field1_label</strong></td>\n";
echo "<td><strong>$field2_label</strong></td>\n";
echo "<td> </td>\n";
echo "</tr>\n";
// This is the entry boxes
echo "<form action=\"$link&action=contacts\" method=\"post\">\n";
echo "<tr>\n";
echo "<input type='hidden' name='insert' value='1'></td>\n";
echo "<td><input type='text' size='20' maxlength='65' name='field1_value' value='$addcontact'></td>\n";
echo "<td><input type='text' size='35' maxlength='65' name='field2_value'></td>\n";
echo "<td colspan=2 align=center>";
echo "<input type='submit' value=\" Add \"></td>\n";
echo "</tr>\n";
echo "</form>\n";
// This is the data under the entry boxes
while ($row = mysql_fetch_row($result)) {
echo "<tr>\n";
echo "<td><a href=".$link."&action=compose&to=".$row[2].">".$row[2]."</a><small>  [<a href=".$this->config["base_url"].$row[2].">Home Page</a>]</small></td>\n";
echo "<td>".strip_tags($row[3])."</td>\n";
echo "<td><a href=\"javascript: if(confirm('Are you sure you want to delete this item?')){ window.self.location='".$link."&action=contacts&deletecnt=".$row[4]."' }\"><center>Delete</center></a></td>\n";
echo "</tr>\n";
}
echo "</table>";
echo "<small>Clicking on the contact name will take you to message entry screen.</small>";
}

// code to manage folder list
elseif ($action==folders){
$table = $this->config["table_prefix"]."mailinfo";
$field1 = "info";
$field1_label = "Folder List";
$field2 = "notes";
$field2_label = "Notes";
$deletefldr = $_GET['deletefldr'];
$fldr = $_GET['fldr'];
$field1_value=$_POST['field1_value'];
if ($field1_value) {$insert="1";} else {$insert="";}
$field2_value=$_POST['field2_value'];
$category="folder";

if ($user = $this->GetUser()){
if ($insert) {
mysql_query( "INSERT into $table ($field1, $field2, owner, type) values (\"$field1_value\",\"$field2_value\",\"$username\",\"$category\")");
}

if ($deletefldr) {
// delete folder name from mailinfo
mysql_query("DELETE from $table WHERE id='$deletefldr' AND owner='$username' AND type='folder'");
// change files from being stored in folder being deleted to being stored in inbox
mysql_query("UPDATE ".$this->config["table_prefix"]."mail SET folder='inbox' WHERE folder='$fldr' AND UserTo='$username'");
}

if (mysql_errno()!=0) {
switch (mysql_errno()) {
default:
echo "Error #".mysql_errno(). " (".mysql_error(). ")<br>";
}
}
}
$query = "SELECT * from $table WHERE owner='$username' AND type='$category' ORDER BY info ASC";
$result = mysql_query($query);
$rows = mysql_num_rows($result);
echo "<strong><em>Folder Management</em></strong>";
echo "<table border='1' cellspacing='0'>\n";
echo "<tr>\n";
echo "<td><strong>$field1_label</strong></td>\n";
echo "<td><strong>$field2_label</strong></td>\n";
echo "<td> </td>\n";
echo "</tr>\n";

// This is the entry boxes
echo "<form action=\"$link&action=folders\" method=\"post\">\n";
echo "<tr>\n";
echo "<input type='hidden' name='insert' value='1'></td>\n";
echo "<td><input type='text' size='25' maxlength='65' name='field1_value'></td>\n";
echo "<td><input type='text' size='35' maxlength='65' name='field2_value'></td>\n";
echo "<td colspan='2' align='center'>";
echo "<input type='submit' value=\" Add \"></td>\n";
echo "</tr>\n";
echo "</form>\n";
// This is the data under the entry boxes
while ($row = mysql_fetch_row($result)) {
echo "<tr>\n";
echo "<td><a href=".$link."&folder=".strip_tags($row[2]).">".strip_tags($row[2])."</a></td>\n";
echo "<td>".strip_tags($row[3])."</td>\n";
echo "<td><a href=\"javascript: if(confirm('Are you sure you want to delete this item?')){ window.self.location='".$link."&action=folders&deletefldr=".$row[4]."&fldr=".$row[2]."' }\">
<center>Delete</center></a></td>\n";
}
echo "</table>";
echo "<small>Clicking on the folder name will take you to that folder.</small>";
}

// code to display user list
elseif ($action==users){
echo "<table width='650'><tr><td>";
$last_users = $this->LoadAll("select name from ".$this->config["table_prefix"]."users order by name ASC");
echo "<strong><em>User List.</em></strong> Click on the name to add it to the contact list.<br />";
foreach($last_users as $user)
{
echo "<a href=".$link."&action=contacts&cntct=".$user["name"].">".$user["name"]."</a> ";
}
echo "</td></tr></table>";
}

//code to show brief instructions for using filters
elseif ($action==help){
echo "<table width='700'><tr><td>";
echo "<p><strong>An introduction to sending messages in Wikka...</strong></p>";
echo "There are two brief parts to this help file. The first is how to interpret the output screen. The second is a description of how filters work.<br /><br />";
echo "     <strong><em>Introduction to the output...</em></strong><br /><br />";
echo "Below is a typical output line in the In-Box, Folder lists or the Sent message area.<br /><br />";
echo "<table border='0' width='800'>";
echo "<tr><td valign='middle'>";
echo "<P> <font color='#FF0000'><strong>!* </strong></font><A>Science Class tomorrow</A><font color='#000000'><strong><a title='You have answered this email.'> </a></strong><small>(05Feb05 2:08 pm)</small></FONT><FONT COLOR='#FF0000'><STRONG>*</STRONG></FONT><FONT COLOR='#000000'>  </FONT><FONT COLOR='#008000'><STRONG>*</STRONG></FONT></P>";
echo "</td><td align='center' width='140' valign='middle'>";
echo "<P><a title='Sender'>GmBowen</a><small> [<a title='Put into contact list.'>-></a>]</small></P>";
echo "</td>";
echo "<td width='150' valign='middle'>";
echo "<P><form>";
echo "<P><select name=move2folder>";
echo "<option value=ColeBowen>ColeBowen";
echo "<option value=GmBowen>GmBowen";
echo "<option value=Personal>Personal";
echo "<option value=Work>Work";
echo "</select><input type='button' name='Submit' value='Move'>";
echo "</form></P>";
echo "</td>";
echo "<td align='center' valign='middle' width='60'>";
echo "<P align='center'>[<a>Delete</a>]</P>";
echo "</td>";
echo "<td width='53'>";
echo "<P> <A title='Mark message with a RED star.'></A><FONT COLOR='#FF0000'><STRONG>*</STRONG></FONT>|<A title='Mark message with a BLUE star.'></A><FONT COLOR='#0000FF'><STRONG>*</STRONG></FONT>|<A title='Mark message with a GREEN star.'></A><FONT COLOR='#008000'><STRONG>*</STRONG></FONT><BR>";
echo "</P>";
echo "</TD>";
echo "</TR>";
echo "</TABLE>";
echo "</FONT><FONT COLOR='#000000'><br />Here is how to interpret the output....</FONT></P>";
echo "<UL>";
echo "<LI><FONT COLOR='#000000'>The exclamation mark (</FONT><FONT COLOR='#FF0000'><B>!</B></FONT><FONT COLOR='#000000'>) tells you that the sender marked the message <B>urgent</B>.</FONT></LI>";
echo "<LI><FONT COLOR='#000000'>The first red star (</FONT><FONT COLOR='#FF0000'>*</FONT><FONT COLOR='#000000'>) tells you that you have not read the message yet. </FONT></LI>";
echo "<LI><FONT COLOR='#000000'>'Science Class tomorrow' is the topic of the message.</FONT></LI>";
echo "<LI><FONT COLOR='#000000'>If there were a plus sign (<B>+</B>) immediately after the topic you would know that you had replied to the message. </FONT></LI>";
echo "<LI><FONT COLOR='#000000'>The date/time after the message lets you know when the message was sent. </FONT></LI>";
echo "<LI><FONT COLOR='#000000'>The coloured stars after the date/time (</FONT><FONT COLOR='#FF0000'>* </FONT><FONT COLOR='#000000'> </FONT><FONT COLOR='#00FF00'>*</FONT><FONT COLOR='#000000'>) indicate that you've applied those two markers to your message (see below). </FONT></LI>";
echo "<LI><FONT COLOR='#000000'>'GmBowen' is the sender of the message.</FONT></LI>";
echo "<LI><FONT COLOR='#000000'>The [->] allows you to put the senders name into your contact list. </FONT></LI>";
echo "<LI><FONT COLOR='#000000'>The dropdown menu (starting with 'ColeBowen') is a list of folders that you can file the message into. </FONT></LI>";
echo "<LI><FONT COLOR='#000000'>The [</FONT><FONT COLOR='#0000FF'>Delete</FONT><FONT COLOR='#000000'>] button allows you to delete the message (even though it does stay in the database). </FONT></LI>";
echo "<LI><FONT COLOR='#000000'>Clicking on the three coloured stars (</FONT><FONT COLOR='#FF0000'>*</FONT><FONT COLOR='#000000'>|</FONT><FONT COLOR='#0000FF'>*</FONT><FONT COLOR='#000000'>|</FONT><FONT COLOR='#00CC00'>*</FONT><FONT COLOR='#000000'>) allow you to set markers on your messages.</FONT></LI>";
echo "</UL>";
echo "<br /><br />";
echo "     <strong><em>Introduction to filters...</em></strong><br /><br />";
echo "<P>'Filters' are a simple-to-use tool that can help you organize your\n";
echo "messages.</P>\n";
echo "\n";
echo "<P>When you're in the in-box or any of the folders, on the top right\n";
echo "of the title bar you'll see a +/- with\n";
echo "<FONT COLOR='#FF0000'>*</FONT>|<FONT COLOR='#0000FF'>*</FONT>|<FONT COLOR='#008000'>*\n";
echo "</FONT>underneath it (and to the right of each message). By clicking\n";
echo "on these three coloured stars you can place or remove coloured stars\n";
echo "from beside the message title. A similar feature is found inside each\n";
echo "individual message box (seen when you're reading your messages).</P>\n";
echo "\n";
echo "<P>The different colours can mean anything you want them to. Red\n";
echo "might mean 'really important' and green might mean 'Ignore for now'.\n";
echo "It's really up to you. They can mean different things to you in your\n";
echo "in-box versus your different folders as well</P>\n";
echo "\n";
echo "<P><TABLE>\n";
echo "<TR BGCOLOR='#DDDDDD'>\n";
echo "<TD WIDTH=400>\n";
echo "<P><TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH='100%'>\n";
echo "<TR>\n";
echo "<TD>\n";
echo "<P> Message Topic:</P>\n";
echo "</TD>\n";
echo "<TD ALIGN=right>\n";
echo "<P><STRONG>A</STRONG> <STRONG>N</STRONG> <FONT COLOR='#FF0000'><STRONG>*</STRONG></FONT> <FONT COLOR='#0000FF'><STRONG>*</STRONG></FONT> <STRONG>*</STRONG></P>\n";
echo "</TD>\n";
echo "</TR>\n";
echo "</TABLE>\n";
echo "</P>\n";
echo "</TD>\n";
echo "<TD WIDTH=85>\n";
echo "<P> Sender:</P>\n";
echo "</TD>\n";
echo "<TD WIDTH=155>\n";
echo "<P> Move to Folder:</P>\n";
echo "</TD>\n";
echo "<TD>\n";
echo "<P> Delete:</P>\n";
echo "</TD>\n";
echo "<TD WIDTH=45>\n";
echo "<P>  <STRONG>+</STRONG>/<STRONG>-</STRONG></P>\n";
echo "</TD>\n";
echo "</TR>\n";
echo "</TABLE>\n";
echo "</P>\n";
echo "\n";
echo "<P>On the grey title bar to the right of 'Message Topic:' you can see\n";
echo " <B>A</B> <B>N</B> \n";
echo "<FONT COLOR='#FF0000'>*</FONT> <FONT COLOR='#0000FF'>*</FONT> <FONT COLOR='#008000'>*</FONT></P>\n";
echo "\n";
echo "<P>By clicking on the '<B>A</B>' you'll see all of the messages,\n";
echo "on the '<B>N</B>' you'll see the messages that don't have any markers\n";
echo "beside them, and if you click on any of the coloured stars you'll see\n";
echo "the messages that have those coloured markers beside them.</P>\n";
echo "\n";
echo "<P>Easy eh? </P>\n";
echo "</td></tr></table>";
}
?>
%%

The following file should be saved as ##page.inc.php## in a directory called ##scripts## in the wikka root....
%%(php)
<?php


/*
###############################################
#### ####
#### Author : Harish Chauhan ####
#### Date : 27 Sep,2004 ####
#### Updated: ####
#### ####
###############################################

*/
// Original class script obtained from http://www.phpclasses.org/browse/package/2012.html distributed as "Freeware"
// Modifications (Ver 1.0b) by GmBowen so that script useable with wikka wiki to support a "mail" action developed for the wiki.
// Throughout this class "?page" was changed to "&page" as well as other minor modifications throughout the script.

class Page
{
var $total_records=1; ///Total Records returned by sql query
var $records_per_page=1; ///how many records would be displayed at a time
var $page_name=""; ///page name on which the class is called
var $start=0;
var $page=0;
var $total_page=0;
var $current_page;
var $remain_page;
var $show_prev_next=true;
var $show_scroll_prev_next=false;
var $show_first_last=false;
var $show_disabled_links=true;
var $scroll_page=0;
var $qry_str="";
var $link_para="&";

/* returns boolean value if it is last page or not*/
function is_last_page()
{
return $this->page>=$this->total_page-1?true:false;
}
/* param : Void
returns boolean value if it is first page or not*/
function is_first_page()
{
return $this->page==0?true:false;
}
function current_page()
{
return $this->page+1;
}
function total_page()
{
return $this->total_page==0?1:$this->total_page;
}

//@param : $show = if you want to show disabled links on navigation links.
//
function show_disabled_links($show=TRUE)
{
$this->show_disabled_links=$show;
}
//@param : $link_para = if you want to pass any parameter to link
//
function set_link_parameter($link_para)
{
$this->link_para=$link_para;
}
function set_page_name($page_name)
{
$this->page_name=$page_name;
}
//@param : str= query string you want to pass to links.
function set_qry_string($str="")
{
$this->qry_str="&".$str;
}
function set_scroll_page($scroll_num=0)
{
if($scroll_num!=0)
$this->scroll_page=$scroll_num;
else
$this->scroll_page=$this->total_records;

}
function set_total_records($total_records)
{
if($total_records<0)
$total_records=0;
$this->total_records=$total_records;
}
function set_records_per_page($records_per_page)
{
if($records_per_page<=0)
$records_per_page=$this->total_records;
$this->records_per_page=$records_per_page;
}
/* @params
* $page_name = Page name on which class is integrated. i.e. $_SERVER['PHP_SELF']
* $total_records=Total records returnd by sql query.
* $records_per_page=How many projects would be displayed at a time
* $scroll_num= How many pages scrolled if we click on scroll page link.
* i.e if we want to scroll 6 pages at a time then pass argument 6.
* $show_prev_next= boolean(true/false) to show prev Next Link
* $show_scroll_prev_next= boolean(true/false) to show scrolled prev Next Link
* $show_first_last= boolean(true/false) to show first last Link to move first and last page.
*/

function set_page_data($page_name,$total_records,$records_per_page=1,$scroll_num=0,$show_prev_next=true,$show_scroll_prev_next=false,$show_first_last=false)
{
$this->set_total_records($total_records);
$this->set_records_per_page($records_per_page);
$this->set_scroll_page($scroll_num);
$this->set_page_name($page_name);
$this->show_prev_next=$show_prev_next;
$this->show_scroll_prev_next=$show_scroll_prev_next;
$this->show_first_last=$show_first_last;
}
/* @params
* $user_link= if you want to display your link i.e if you want to user '>>' instead of [first] link then use
Page::get_first_page_nav(">>") OR for image
Page::get_first_page_nav("<img src='' alt='first'>")
$link_para: link parameters i.e if you want ot use another parameters such as class.
Page::get_first_page_nav(">>","class=myStyleSheetClass")
*/
function get_first_page_nav($user_link="",$link_para="")
{
if($this->total_page<=1)
return;
if(trim($user_link)=="")
$user_link="««  ";
if(!$this->is_first_page()&& $this->show_first_last)
echo ' <a href="'.$this->page_name.'&page=0'.$this->qry_str.'" '.$link_para.'>'.$user_link.'</a> ';
elseif($this->show_first_last && $this->show_disabled_links)
echo $user_link;
}
function get_last_page_nav($user_link="",$link_para="")
{
if($this->total_page<=1)
return;
if(trim($user_link)=="")
$user_link="  Â»Â»";
if(!$this->is_last_page()&& $this->show_first_last)
echo ' <a href="'.$this->page_name.'&page='.($this->total_page-1).$this->qry_str.'" '.$link_para.'>'.$user_link.'</a> ';
elseif($this->show_first_last && $this->show_disabled_links)
echo $user_link;
}
function get_next_page_nav($user_link="",$link_para="")
{
if($this->total_page<=1)
return;
if(trim($user_link)=="")
$user_link=" »";
if(!$this->is_last_page()&& $this->show_prev_next)
echo ' <a href="'.$this->page_name.'&page='.($this->page+1).$this->qry_str.'" '.$link_para.'>'.$user_link.'</a> ';
elseif($this->show_prev_next && $this->show_disabled_links)
echo $user_link." ";
}
function get_prev_page_nav($user_link="",$link_para="")
{
if($this->total_page<=1)
return;
if(trim($user_link)=="")
$user_link="« ";
if(!$this->is_first_page()&& $this->show_prev_next)
echo ' <a href="'.$this->page_name.'&page='.($this->page-1).$this->qry_str.'" '.$link_para.'>'.$user_link.'</a> ';
elseif($this->show_prev_next && $this->show_disabled_links)
echo " ".$user_link;
}
function get_scroll_prev_page_nav($user_link="",$link_para="")
{

if($this->scroll_page>=$this->total_page)
return;
if(trim($user_link)=="")
$user_link="[-$this->scroll_page]";
if($this->page>$this->scroll_page &&$this->show_scroll_prev_next)
echo ' <a href="'.$this->page_name.'&page='.($this->page-$this->scroll_page).$this->qry_str.'" '.$link_para.'>'.$user_link.'</a> ';
elseif($this->show_scroll_prev_next && $this->show_disabled_links)
echo $user_link;
}
function get_scroll_next_page_nav($user_link="",$link_para="")
{
if($this->scroll_page>=$this->total_page)
return;
if(trim($user_link)=="")
$user_link="[+$this->scroll_page]";
if($this->total_page>$this->page+$this->scroll_page &&$this->show_scroll_prev_next)
echo ' <a href="'.$this->page_name.'&page='.($this->page+$this->scroll_page).$this->qry_str.'" '.$link_para.'>'.$user_link.'</a> ';
elseif($this->show_scroll_prev_next && $this->show_disabled_links)
echo $user_link;
}

function get_number_page_nav($link_para="")
{
$j=0;
$scroll_page=$this->scroll_page;
if($this->page>($scroll_page/2))
$j=$this->page-intval($scroll_page/2);
if($j+$scroll_page>$this->total_page)
$j=$this->total_page-$scroll_page;

if($j<0)
$i=0;
else
$i=$j;

for(;$i<$j+$scroll_page && $i<$this->total_records;$i++)
{
if($i==$this->page)
echo ($i+1);
else
echo ' <a href="'.$this->page_name.'&page='.$i.$this->qry_str.'" '.$link_para.'>'.($i+1).'</a> ';
}
}

function get_page_nav()
{
if($this->total_records<=0)
{
//echo "No Records Found";
// return false;
}
$this->calculate();
$this->get_first_page_nav("",$this->link_para);
$this->get_scroll_prev_page_nav("",$this->link_para);
$this->get_prev_page_nav("",$this->link_para);
$this->get_number_page_nav($this->link_para);
$this->get_next_page_nav("",$this->link_para);
$this->get_scroll_next_page_nav("",$this->link_para);
$this->get_last_page_nav("",$this->link_para);
// return true;
}
function calculate()
{
$this->page=$_REQUEST['page'];
if(!is_numeric($this->page))
$this->page=0;
$this->start=$this->page*$this->records_per_page;
$this->total_page=@intval($this->total_records/$this->records_per_page);
if($this->total_records%$this->records_per_page!=0)
$this->total_page++;
}
function get_limit_query($qry="")
{
$this->calculate();
return $qry." LIMIT $this->start,$this->records_per_page";
}
}
?>
%%

This is the inbox (note the * indicator in the header that there is unread mail, + indicator for answered mail, and the marker/filter system)...

http://gmbowen.educ.unb.ca/wikitest/pms1.jpg

This is the "compose" box (note the contact list...clicking on a name enters it into the "to" box)...

http://gmbowen.educ.unb.ca/wikitest/pms2.jpg

This is a listing of "sent" files (note the indicator of whether they'd been read or not)...

http://gmbowen.educ.unb.ca/wikitest/pms3.jpg

This is the contents of a folder...

http://gmbowen.educ.unb.ca/wikitest/pms4.jpg

This is a listing of the contacts & where they are managed...

http://gmbowen.educ.unb.ca/wikitest/pms5.jpg

This is a list of the registered users....

http://gmbowen.educ.unb.ca/wikitest/pms6.jpg

This is a listing of the folders & where they are managed....

http://gmbowen.educ.unb.ca/wikitest/pms7.jpg

This is an example message...

http://gmbowen.educ.unb.ca/wikitest/pms8.jpg

This demonstrates a "compose" form after "forward" has been clicked....

http://gmbowen.educ.unb.ca/wikitest/pms9.jpg

This image is a "reply" message (you cannot change the "to" or the "subject" block)

http://gmbowen.educ.unb.ca/wikitest/pms10.jpg

----
**To upgrade your mail.php from version 1.0 to 1.5 do the following.....**

1) Use the following mysql statements (in your fvaourite mysql administration program, or at the command line if you know how) to update the table structure in your wikki database. Make sure you change "WAKKAPREFIX" to the prefix you use in your wikka.

ALTER TABLE `WAKKAPREFIX_mail`
ADD `repliedto` TINYINT (1) DEFAULT '0' AFTER `Message` ,
ADD `urgent` TINYINT (1) DEFAULT NULL AFTER `repliedto` ,
ADD `fltr1` TINYINT (1) DEFAULT '0' NOT NULL AFTER `urgent` ,
ADD `fltr2` TINYINT (1) DEFAULT '0' NOT NULL AFTER `fltr1` ,
ADD `fltr3` TINYINT (1) DEFAULT '0' NOT NULL AFTER `fltr2` ,
ADD `DateSent` DATETIME NOT NULL AFTER `fltr3`

2) THEN RUN THE PHP SCRIPT mailupdate.php as an ACTION (you can only do this as a designated administrator). Save the php code below as mailupdate.php, insert on a page, and then click on the visible link. This will alter the date code from a text string to a mysql DATETIME string (makes it easier to display date & time).

%%(php)
if ($this->IsAdmin()) {
$link = $this->config["base_url"].$this->MiniHref($method, $tag);
echo "<a href=".$link."&action=update>Update database for mail.php from version 1.0 to version 1.5</a>";
$action=$_GET['action'];
if($action==update){
$query="SELECT SentDate,DateSent FROM ".$this->config["table_prefix"]."mail";
$result=mysql_query($query) or die ("cant do it");
while ($row=mysql_fetch_array($result)) {
$newdate=$row[SentDate];
mysql_query("UPDATE ".$this->config["table_prefix"]."mail SET DateSent=$newdate WHERE SentDate=$newdate");
}
if ($_GET['action']) {echo "Database update complete.";}
}
}
%%

Erase the update file from you actions directory.

3) Then install the new mail.php file. (erase the old one, replace with the new one.) You may or may want to put your wiki into "administrative mode" so that others cannot use it while you do this. (See these [[http://wikka.jsnx.com/UpgradeNotes notes]] for upgrading wikka.)

4) Finally, remove the ""SentDate"" field from the mysql table WAKKAPREFIX_mail using the following command. (Make sure you change "WAKKAPREFIX" to the prefix you use in your wikka.)

ALTER TABLE `WAKKAPREFIX_mail` DROP `SentDate`

That's it. This upgrade sequence has been tested on two sites and worked without a problem.

----


Revision [5691]

Edited on 2005-02-06 18:10:26 by GmBowen [code/feature update]
Additions:
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.
`repliedto` tinyint(1) default '0',
`urgent` tinyint(1) default NULL,
`fltr1` tinyint(1) default '0',
`fltr2` tinyint(1) default '0',
`fltr3` tinyint(1) default '0',
`DateSent` datetime default NULL,
// This mail.php (Version 1.5b) 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.
// 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.
$pagename = $this->MiniHref($method, $tag);
$pagenum=$_GET['page'];
if (!$folder) {$folder=$which;}
$fltrset=$_GET['fltrset'];
$msg_id=$_GET['mail_id'];
$filter=$_GET['fltr'];
$mail_id=$msg_id;
<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>
echo "<form method='post' action=\"$link\"><select name=\"whichfolder\">";
extract ($row);
if($_REQUEST[whichfolder] == $info)
echo "<option value=\"$info\">$info</option>";
</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>
if ($action=="compose" || $action=="forward" || $action=="contacts" || $action=="folders" || $action=="users" || $action=="help" || $action=="reply" || $action=="delete" || $action=="compose2"){echo "";
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;
$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.";
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'>";
// to paginate the "inbox" page messages
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 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> Delete:</td>\n";
echo "<td>  <strong>+</strong>/<strong>-</strong></td>\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>";
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);
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.";
}
echo "<br />You must be both <strong>registered</strong> <u>and</u> <strong>logged</strong> in to use this Private Messaging System.<br />";
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 "<td width='400'> Message Topic:</td>\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>";
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 "<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";
$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");
$datetime=date("dMy g:i a",strtotime($row['DateSent']));
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>";
echo "<form method=post action=\"$link&mail_id=$row[mail_id]&folder=$which\"><select name=\"move2folder\">";
extract ($row2);
echo "<option value=\"$info\">$info</option>";
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."><font color='red'><strong>*</strong></font></a>|<a href=".$link."&fltrset=2&mail_id=".$row[mail_id]."&folder=".$which."><font color='blue'><strong>*</strong></font></a>|<a href=".$link."&fltrset=3&mail_id=".$row[mail_id]."&folder=".$which."><font color='green'><strong>*</strong></font></a><br /></td></tr>";
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) {
$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'");
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) {
echo "<font face=verdana>Message was deleted.<br /><br /><br /><br /><br /><br /><br /></font>";
echo "The message was not deleted.";
elseif ($action==contacts){
$addcontact=$_GET['cntct'];
$table = $this->config["table_prefix"]."mailinfo";
$field1 = "info";
$field1_label = "Contact Names";
$field2 = "notes";
$field2_label = "Notes";
$deletecnt = $_GET['deletecnt'];
$field1_value=$_POST['field1_value'];
if ($field1_value) {$insert="1";} else {$insert="";}
$field2_value=$_POST['field2_value'];
$category="contact";
echo "Error #".mysql_errno(). " (".mysql_error(). ")<br>";
// This is the entry boxes
echo "<td><input type='text' size='20' maxlength='65' name='field1_value' value='$addcontact'></td>\n";
echo "<input type='submit' value=\" Add \"></td>\n";
// This is the data under the entry boxes
echo "<td><a href=".$link."&action=compose&to=".$row[2].">".$row[2]."</a><small>  [<a href=".$this->config["base_url"].$row[2].">Home Page</a>]</small></td>\n";
echo "<td>".strip_tags($row[3])."</td>\n";
echo "<small>Clicking on the contact name will take you to message entry screen.</small>";
elseif ($action==folders){
$table = $this->config["table_prefix"]."mailinfo";
$field1 = "info";
$field1_label = "Folder List";
$field2 = "notes";
$field2_label = "Notes";
$deletefldr = $_GET['deletefldr'];
$fldr = $_GET['fldr'];
$field1_value=$_POST['field1_value'];
if ($field1_value) {$insert="1";} else {$insert="";}
$field2_value=$_POST['field2_value'];
$category="folder";
mysql_query("DELETE from $table WHERE id='$deletefldr' AND owner='$username' AND type='folder'");
// change files from being stored in folder being deleted to being stored in inbox
// This is the entry boxes
echo "<input type='submit' value=\" Add \"></td>\n";
// This is the data under the entry boxes
echo "<td><a href=".$link."&folder=".strip_tags($row[2]).">".strip_tags($row[2])."</a></td>\n";
echo "<td>".strip_tags($row[3])."</td>\n";
<center>Delete</center></a></td>\n";
echo "<small>Clicking on the folder name will take you to that folder.</small>";
elseif ($action==users){
echo "<table width='650'><tr><td>";
$last_users = $this->LoadAll("select name from ".$this->config["table_prefix"]."users order by name ASC");
echo "<strong><em>User List.</em></strong> Click on the name to add it to the contact list.<br />";
//code to show brief instructions for using filters
elseif ($action==help){
echo "<table width='700'><tr><td>";
echo "<p><strong>An introduction to sending messages in Wikka...</strong></p>";
echo "There are two brief parts to this help file. The first is how to interpret the output screen. The second is a description of how filters work.<br /><br />";
echo "     <strong><em>Introduction to the output...</em></strong><br /><br />";
echo "Below is a typical output line in the In-Box, Folder lists or the Sent message area.<br /><br />";
echo "<table border='0' width='800'>";
echo "<tr><td valign='middle'>";
echo "<P> <font color='#FF0000'><strong>!* </strong></font><A>Science Class tomorrow</A><font color='#000000'><strong><a title='You have answered this email.'> </a></strong><small>(05Feb05 2:08 pm)</small></FONT><FONT COLOR='#FF0000'><STRONG>*</STRONG></FONT><FONT COLOR='#000000'>  </FONT><FONT COLOR='#008000'><STRONG>*</STRONG></FONT></P>";
echo "</td><td align='center' width='140' valign='middle'>";
echo "<P><a title='Sender'>GmBowen</a><small> [<a title='Put into contact list.'>-></a>]</small></P>";
echo "</td>";
echo "<td width='150' valign='middle'>";
echo "<P><form>";
echo "<P><select name=move2folder>";
echo "<option value=ColeBowen>ColeBowen";
echo "<option value=GmBowen>GmBowen";
echo "<option value=Personal>Personal";
echo "<option value=Work>Work";
echo "</select><input type='button' name='Submit' value='Move'>";
echo "</form></P>";
echo "</td>";
echo "<td align='center' valign='middle' width='60'>";
echo "<P align='center'>[<a>Delete</a>]</P>";
echo "</td>";
echo "<td width='53'>";
echo "<P> <A title='Mark message with a RED star.'></A><FONT COLOR='#FF0000'><STRONG>*</STRONG></FONT>|<A title='Mark message with a BLUE star.'></A><FONT COLOR='#0000FF'><STRONG>*</STRONG></FONT>|<A title='Mark message with a GREEN star.'></A><FONT COLOR='#008000'><STRONG>*</STRONG></FONT><BR>";
echo "</P>";
echo "</TD>";
echo "</TR>";
echo "</TABLE>";
echo "</FONT><FONT COLOR='#000000'><br />Here is how to interpret the output....</FONT></P>";
echo "<UL>";
echo "<LI><FONT COLOR='#000000'>The exclamation mark (</FONT><FONT COLOR='#FF0000'><B>!</B></FONT><FONT COLOR='#000000'>) tells you that the sender marked the message <B>urgent</B>.</FONT></LI>";
echo "<LI><FONT COLOR='#000000'>The first red star (</FONT><FONT COLOR='#FF0000'>*</FONT><FONT COLOR='#000000'>) tells you that you have not read the message yet. </FONT></LI>";
echo "<LI><FONT COLOR='#000000'>'Science Class tomorrow' is the topic of the message.</FONT></LI>";
echo "<LI><FONT COLOR='#000000'>If there were a plus sign (<B>+</B>) immediately after the topic you would know that you had replied to the message. </FONT></LI>";
echo "<LI><FONT COLOR='#000000'>The date/time after the message lets you know when the message was sent. </FONT></LI>";
echo "<LI><FONT COLOR='#000000'>The coloured stars after the date/time (</FONT><FONT COLOR='#FF0000'>* </FONT><FONT COLOR='#000000'> </FONT><FONT COLOR='#00FF00'>*</FONT><FONT COLOR='#000000'>) indicate that you've applied those two markers to your message (see below). </FONT></LI>";
echo "<LI><FONT COLOR='#000000'>'GmBowen' is the sender of the message.</FONT></LI>";
echo "<LI><FONT COLOR='#000000'>The [->] allows you to put the senders name into your contact list. </FONT></LI>";
echo "<LI><FONT COLOR='#000000'>The dropdown menu (starting with 'ColeBowen') is a list of folders that you can file the message into. </FONT></LI>";
echo "<LI><FONT COLOR='#000000'>The [</FONT><FONT COLOR='#0000FF'>Delete</FONT><FONT COLOR='#000000'>] button allows you to delete the message (even though it does stay in the database). </FONT></LI>";
echo "<LI><FONT COLOR='#000000'>Clicking on the three coloured stars (</FONT><FONT COLOR='#FF0000'>*</FONT><FONT COLOR='#000000'>|</FONT><FONT COLOR='#0000FF'>*</FONT><FONT COLOR='#000000'>|</FONT><FONT COLOR='#00CC00'>*</FONT><FONT COLOR='#000000'>) allow you to set markers on your messages.</FONT></LI>";
echo "</UL>";
echo "<br /><br />";
echo "     <strong><em>Introduction to filters...</em></strong><br /><br />";
echo "<P>'Filters' are a simple-to-use tool that can help you organize your\n";
echo "messages.</P>\n";
echo "\n";
echo "<P>When you're in the in-box or any of the folders, on the top right\n";
echo "of the title bar you'll see a +/- with\n";
echo "<FONT COLOR='#FF0000'>*</FONT>|<FONT COLOR='#0000FF'>*</FONT>|<FONT COLOR='#008000'>*\n";
echo "</FONT>underneath it (and to the right of each message). By clicking\n";
echo "on these three coloured stars you can place or remove coloured stars\n";
echo "from beside the message title. A similar feature is found inside each\n";
echo "individual message box (seen when you're reading your messages).</P>\n";
echo "\n";
echo "<P>The different colours can mean anything you want them to. Red\n";
echo "might mean 'really important' and green might mean 'Ignore for now'.\n";
echo "It's really up to you. They can mean different things to you in your\n";
echo "in-box versus your different folders as well</P>\n";
echo "\n";
echo "<P><TABLE>\n";
echo "<TR BGCOLOR='#DDDDDD'>\n";
echo "<TD WIDTH=400>\n";
echo "<P><TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH='100%'>\n";
echo "<TR>\n";
echo "<TD>\n";
echo "<P> Message Topic:</P>\n";
echo "</TD>\n";
echo "<TD ALIGN=right>\n";
echo "<P><STRONG>A</STRONG> <STRONG>N</STRONG> <FONT COLOR='#FF0000'><STRONG>*</STRONG></FONT> <FONT COLOR='#0000FF'><STRONG>*</STRONG></FONT> <STRONG>*</STRONG></P>\n";
echo "</TD>\n";
echo "</TR>\n";
echo "</TABLE>\n";
echo "</P>\n";
echo "</TD>\n";
echo "<TD WIDTH=85>\n";
echo "<P> Sender:</P>\n";
echo "</TD>\n";
echo "<TD WIDTH=155>\n";
echo "<P> Move to Folder:</P>\n";
echo "</TD>\n";
echo "<TD>\n";
echo "<P> Delete:</P>\n";
echo "</TD>\n";
echo "<TD WIDTH=45>\n";
echo "<P>  <STRONG>+</STRONG>/<STRONG>-</STRONG></P>\n";
echo "</TD>\n";
echo "</TR>\n";
echo "</TABLE>\n";
echo "</P>\n";
echo "\n";
echo "<P>On the grey title bar to the right of 'Message Topic:' you can see\n";
echo " <B>A</B> <B>N</B> \n";
echo "<FONT COLOR='#FF0000'>*</FONT> <FONT COLOR='#0000FF'>*</FONT> <FONT COLOR='#008000'>*</FONT></P>\n";
echo "\n";
echo "<P>By clicking on the '<B>A</B>' you'll see all of the messages,\n";
echo "on the '<B>N</B>' you'll see the messages that don't have any markers\n";
echo "beside them, and if you click on any of the coloured stars you'll see\n";
echo "the messages that have those coloured markers beside them.</P>\n";
echo "\n";
echo "<P>Easy eh? </P>\n";
#### ####
#### Author : Harish Chauhan ####
#### Date : 27 Sep,2004 ####
#### Updated: ####
#### ####
var $records_per_page=1; ///how many records would be displayed at a time
if($scroll_num!=0)
$total_records=0;
if($records_per_page<=0)
$records_per_page=$this->total_records;
$this->records_per_page=$records_per_page;
if(!$this->is_first_page()&& $this->show_first_last)
echo ' <a href="'.$this->page_name.'&page=0'.$this->qry_str.'" '.$link_para.'>'.$user_link.'</a> ';
elseif($this->show_first_last && $this->show_disabled_links)
echo $user_link;
if(!$this->is_last_page()&& $this->show_first_last)
echo ' <a href="'.$this->page_name.'&page='.($this->total_page-1).$this->qry_str.'" '.$link_para.'>'.$user_link.'</a> ';
elseif($this->show_first_last && $this->show_disabled_links)
echo $user_link;
if(!$this->is_last_page()&& $this->show_prev_next)
echo ' <a href="'.$this->page_name.'&page='.($this->page+1).$this->qry_str.'" '.$link_para.'>'.$user_link.'</a> ';
elseif($this->show_prev_next && $this->show_disabled_links)
echo $user_link." ";
if(!$this->is_first_page()&& $this->show_prev_next)
echo ' <a href="'.$this->page_name.'&page='.($this->page-1).$this->qry_str.'" '.$link_para.'>'.$user_link.'</a> ';
elseif($this->show_prev_next && $this->show_disabled_links)
echo " ".$user_link;
if($this->page>$this->scroll_page &&$this->show_scroll_prev_next)
echo ' <a href="'.$this->page_name.'&page='.($this->page-$this->scroll_page).$this->qry_str.'" '.$link_para.'>'.$user_link.'</a> ';
elseif($this->show_scroll_prev_next && $this->show_disabled_links)
echo $user_link;
if($this->total_page>$this->page+$this->scroll_page &&$this->show_scroll_prev_next)
echo ' <a href="'.$this->page_name.'&page='.($this->page+$this->scroll_page).$this->qry_str.'" '.$link_para.'>'.$user_link.'</a> ';
elseif($this->show_scroll_prev_next && $this->show_disabled_links)
echo $user_link;
$j=0;
if($this->page>($scroll_page/2))
$j=$this->page-intval($scroll_page/2);
if($j+$scroll_page>$this->total_page)
$j=$this->total_page-$scroll_page;
if($j<0)
for(;$i<$j+$scroll_page && $i<$this->total_records;$i++)
if($i==$this->page)
echo ($i+1);
else
echo ' <a href="'.$this->page_name.'&page='.$i.$this->qry_str.'" '.$link_para.'>'.($i+1).'</a> ';
}
$this->page=$_REQUEST['page'];
if(!is_numeric($this->page))
$this->page=0;
$this->start=$this->page*$this->records_per_page;
$this->total_page=@intval($this->total_records/$this->records_per_page);
if($this->total_records%$this->records_per_page!=0)
$this->total_page++;
$this->calculate();
return $qry." LIMIT $this->start,$this->records_per_page";
This is the inbox (note the * indicator in the header that there is unread mail, + indicator for answered mail, and the marker/filter system)...
http://gmbowen.educ.unb.ca/wikitest/pms1.jpg
http://gmbowen.educ.unb.ca/wikitest/pms2.jpg
http://gmbowen.educ.unb.ca/wikitest/pms3.jpg
http://gmbowen.educ.unb.ca/wikitest/pms4.jpg
http://gmbowen.educ.unb.ca/wikitest/pms5.jpg
http://gmbowen.educ.unb.ca/wikitest/pms6.jpg
http://gmbowen.educ.unb.ca/wikitest/pms7.jpg
http://gmbowen.educ.unb.ca/wikitest/pms8.jpg
http://gmbowen.educ.unb.ca/wikitest/pms9.jpg
This image is a "reply" message (you cannot change the "to" or the "subject" block)
http://gmbowen.educ.unb.ca/wikitest/pms10.jpg
**To upgrade your mail.php from version 1.0 to 1.5 do the following.....**
1) Use the following mysql statements (in your fvaourite mysql administration program, or at the command line if you know how) to update the table structure in your wikki database. Make sure you change "WAKKAPREFIX" to the prefix you use in your wikka.
ALTER TABLE `WAKKAPREFIX_mail`
ADD `repliedto` TINYINT (1) DEFAULT '0' AFTER `Message` ,
ADD `urgent` TINYINT (1) DEFAULT NULL AFTER `repliedto` ,
ADD `fltr1` TINYINT (1) DEFAULT '0' NOT NULL AFTER `urgent` ,
ADD `fltr2` TINYINT (1) DEFAULT '0' NOT NULL AFTER `fltr1` ,
ADD `fltr3` TINYINT (1) DEFAULT '0' NOT NULL AFTER `fltr2` ,
ADD `DateSent` DATETIME NOT NULL AFTER `fltr3`
2) THEN RUN THE PHP SCRIPT mailupdate.php as an ACTION (you can only do this as a designated administrator). Save the php code below as mailupdate.php, insert on a page, and then click on the visible link. This will alter the date code from a text string to a mysql DATETIME string (makes it easier to display date & time).
if ($this->IsAdmin()) {
echo "<a href=".$link."&action=update>Update database for mail.php from version 1.0 to version 1.5</a>";
if($action==update){
$query="SELECT SentDate,DateSent FROM ".$this->config["table_prefix"]."mail";
$result=mysql_query($query) or die ("cant do it");
while ($row=mysql_fetch_array($result)) {
$newdate=$row[SentDate];
mysql_query("UPDATE ".$this->config["table_prefix"]."mail SET DateSent=$newdate WHERE SentDate=$newdate");
if ($_GET['action']) {echo "Database update complete.";}
}
Erase the update file from you actions directory.
3) Then install the new mail.php file. (erase the old one, replace with the new one.) You may or may want to put your wiki into "administrative mode" so that others cannot use it while you do this. (See these [[http://wikka.jsnx.com/UpgradeNotes notes]] for upgrading wikka.)
4) Finally, remove the ""SentDate"" field from the mysql table WAKKAPREFIX_mail using the following command. (Make sure you change "WAKKAPREFIX" to the prefix you use in your wikka.)
ALTER TABLE `WAKKAPREFIX_mail` DROP `SentDate`
That's it. This upgrade sequence has been tested on two sites and worked without a problem.
Deletions:
**Note:** There will be a feature update coming in the next day (colored tab filters for organizing, "urgent" indicator, changes in links found in folder/contact tables)....which involve database changes. If you're thinking of using this you might want to wait for the new code (it'll be easier to install than upgrade which will involve adding fields to the database).
Below is code to put a private messaging system into 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 can be added to the header.php file so that a visual indicator can be used 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.
`SentDate` text NOT NULL,
// Base mail.php 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
// Version 1.0 - Modifications & additions by GmBowen released under GPL.
// directory "scripts" in wikka root
// the line below can be added to the header after <h2> in php tags to provide an indication in the header of when there's mail.
$pagename = $this->MiniHref($method, $tag); // if no thread name specified, sets to pagename (but made to lower case)
echo "<form method=post action=\"$link\"><select name=\"whichfolder\">";
extract ($row);
if($_REQUEST[whichfolder] == $info)
echo "<option value=\"$info\">$info</option>";
</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> |</tr></table>
if ($_GET['action']=="compose" || $_GET['action']=="forward" || $_GET['action']=="contacts" || $_GET['action']=="folders" || $_GET['action']=="users"){echo "";
if ($_GET['action']=="inbox" || (($_GET['action']=="" || $_GET['action']=="view") && $_REQUEST['whichfolder']=="" && $folder=="")) {$which="In-box";}
elseif ($_GET['action']=="sent" || $_GET['action']=="view2") {$which="Sent Mail";} elseif (!$folder=="") {$which=$folder;}
echo "<strong>Folder:</strong>  ".$which;
$mail_id=$_GET['mail_id'];
if($action==compose) {
$subject2=$_GET[subject];
echo "<table width='675'><tr><td>";
echo "<form action=".$link."&action=compose2 method='post'>";
echo "<br /><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'></textarea></td></tr>";
echo "<tr><td><button type='submit'>Send Mail!</button></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 />";
if($action==forward && $mail_id!="") {
$username = $this->GetUserName();
echo "<table width='675'><tr><td>";
echo "<form action=".$link."&action=compose2 method='post'>";
echo "<br /><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'>$origmsg</textarea></td></tr>";
echo "<tr><td><button type=submit>Send Mail!</button></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 />";
// enters message from compose window (original or forward) into database
if($action==compose2) {
$to=$_POST['to'];
$to=addslashes($to);
$subject=$_POST['subject'];
$subject=addslashes($subject);
$message=$_POST['message'];
$message=addslashes($message);
$date = date(YmdHis);
if($subject=="" || $message=="" || $to==""){
echo "One of the fields was left blank.";
if($this->LoadUser($to)) {
$create = "INSERT INTO ".$this->config["table_prefix"]."mail (UserTo, folder, UserFrom, Subject, Message, SentDate, status)
VALUES ('$to','inbox','$username','$subject','$message','$date','unread')";
$create2 = mysql_query($create) or die("A letter could not be sent to $to!");
echo("Message Sent to $to!");
} else {
echo "The recipient name entered was not a registered user. <br />You might check the upper/lower case of the spelling.";
echo "You must be registered & logged in to use this Private Messaging System.<br />";
$query="UPDATE ".$this->config["table_prefix"]."mail SET folder='$move2folder' WHERE UserTo='$username' AND mail_id='$mail_id'";
$rs = mysql_query("UPDATE ".$this->config["table_prefix"]."mail SET folder='$move2folder' WHERE mail_id='$mail_id' AND UserTo='$username'");
echo "<strong>Message moved to ".$move2folder." folder.</strong>";
echo "The message wasn't moved.";
if(($action=='' || $action=='inbox') && $_REQUEST['whichfolder']=='') {
$query="SELECT * FROM ".$this->config["table_prefix"]."mail where UserTo='$username' and folder='inbox' and viewrecipient='Y' ORDER BY SentDate DESC";
$result=mysql_query($query) or die ("cant do it");
echo "<table cellpadding='2' cellspacing='3' width='750' valign='top'>";
echo "<td> Message Topic:</td>\n";
echo "<td width='60'> Delete:</td>\n";
while ($row=mysql_fetch_array($result)) {
$mysqltime=$row[SentDate];
$hour = substr($mysqltime, 8, 2)*1;
if (strlen($hour)==1) {$hour="0".$hour;}
$min = substr($mysqltime, 10, 2)*1;
if (strlen($min)==1) {$min="0".$min;}
$sec = substr($mysqltime, 12, 2)*1;
if (strlen($sec)==1) {$sec="0".$sec;}
$month = substr($mysqltime, 4, 2)*1;
$day = substr($mysqltime, 6, 2)*1;
$year = substr($mysqltime, 0, 4);
$datetime=$hour.":".$min.":".$sec."  ".$month."-".$day."-".$year;
if ($row[status]=="unread") {$status="<a title='This message has not been read yet!'><font color=Red>*</font></a>";} else {$status="";}
echo "<tr><td>$status <a href=".$link."&action=view&mail_id=$row[mail_id]>".strip_tags($row[Subject])."</a><small> (".$datetime.")</small></td><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\">";
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></tr>";
echo "</table>";
if($action=='sent') {
$query="SELECT * from ".$this->config["table_prefix"]."mail where UserFrom='$username' ORDER BY SentDate DESC";
$result=mysql_query($query) or die ("cant do it");
echo "<table cellpadding='2' cellspacing='3' width='750' valign='top'>";
echo "<td> Message Topic:</td>\n";
while ($row=mysql_fetch_array($result)) {
$mysqltime=$row[SentDate];
$hour = substr($mysqltime, 8, 2)*1;
if (strlen($hour)==1) {$hour="0".$hour;}
$min = substr($mysqltime, 10, 2)*1;
if (strlen($min)==1) {$min="0".$min;}
$sec = substr($mysqltime, 12, 2)*1;
if (strlen($sec)==1) {$sec="0".$sec;}
$month = substr($mysqltime, 4, 2)*1;
$day = substr($mysqltime, 6, 2)*1;
$year = substr($mysqltime, 0, 4);
$datetime=$hour.":".$min.":".$sec."  ".$month."-".$day."-".$year;
echo "<tr><td><a href=".$link."&action=view2&mail_id=$row[mail_id]>".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>";
if($_REQUEST['whichfolder']!='') {
$showfolder = $_REQUEST['whichfolder'];
$result=mysql_query("SELECT * from ".$this->config["table_prefix"]."mail where UserTo='$username' AND folder='$showfolder' ORDER BY SentDate DESC") or die ("cant do it");
if ($numrows==0) {echo "<br /><em>There are no messages currently stored in this folder.</em><br /><br />";
} else {
echo "<td> Message Topic:</td>\n";
echo "<td width='85'> Sender:</td>\n";
echo "<td width='175'> Move to Folder:</td>\n";
echo "<td width='75'> Delete:</td>\n";
$mysqltime=$row[SentDate];
$hour = substr($mysqltime, 8, 2)*1;
if (strlen($hour)==1) {$hour="0".$hour;}
$min = substr($mysqltime, 10, 2)*1;
if (strlen($min)==1) {$min="0".$min;}
$sec = substr($mysqltime, 12, 2)*1;
if (strlen($sec)==1) {$sec="0".$sec;}
$month = substr($mysqltime, 4, 2)*1;
$day = substr($mysqltime, 6, 2)*1;
$year = substr($mysqltime, 0, 4);
$datetime=$hour.":".$min.":".$sec."  ".$month."-".$day."-".$year;
echo "<tr><td>$status <a href=".$link."&action=view&mail_id=$row[mail_id]&folder=$which>".strip_tags($row[Subject])."</a> <small>(".$datetime.")</small></td><td width=125>".$this->Format($row[UserFrom])."<small> [<a href=".$link."&action=contacts&cntct=".$row[UserFrom].">-></a>]</small></td><td>";
echo "<form method=post action=\"$link&mail_id=$row[mail_id]\"><select name=\"move2folder\">";
extract ($row2);
echo "<option value=\"$info\">$info</option>";
echo "<td width='50'> [<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></tr>";
if($action==view) {
$mail_id=$_GET['mail_id'];
$result=mysql_query("select * from ".$this->config["table_prefix"]."mail where UserTo='$username' and mail_id=$mail_id") or die ("cant do it");
$row=mysql_fetch_array($result);
$username=strtolower($username);
$row[UserTo]=strtolower($row[UserTo]);
if($row[UserTo]==$username) {
$mysqltime=$row[SentDate];
$hour = substr($mysqltime, 8, 2)*1;
if (strlen($hour)==1) {$hour="0".$hour;}
$min = substr($mysqltime, 10, 2)*1;
if (strlen($min)==1) {$min="0".$min;}
$sec = substr($mysqltime, 12, 2)*1;
if (strlen($sec)==1) {$sec="0".$sec;}
$month = substr($mysqltime, 4, 2)*1;
$day = substr($mysqltime, 6, 2)*1;
$year = substr($mysqltime, 0, 4);
$datetime=$hour.":".$min.":".$sec."  ".$month."-".$day."-".$year;
echo "<table border='1' bordercolor='black' width='600'><tr><td><strong>Subject: </strong>".strip_tags($row[Subject])."</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='2'><strong>Message: </strong>".strip_tags($row[Message])."</td></tr><tr><td><a href=".$link."&action=compose&to=$row[UserFrom]&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><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='$mail_id'");
// added filter for viewing "sent" mail
if($action==view2) {
$mail_id=$_GET['mail_id'];
$result=mysql_query("SELECT * from ".$this->config["table_prefix"]."mail where UserFrom='$username' and mail_id='$mail_id'") or die ("cant do it");
$row=mysql_fetch_array($result);
$username=strtolower($username);
$row[UserFrom]=strtolower($row[UserFrom]);
if($row[UserFrom]==$username) {
$mysqltime=$row[SentDate];
$hour = substr($mysqltime, 8, 2)*1;
if (strlen($hour)==1) {$hour="0".$hour;}
$min = substr($mysqltime, 10, 2)*1;
if (strlen($min)==1) {$min="0".$min;}
$sec = substr($mysqltime, 12, 2)*1;
if (strlen($sec)==1) {$sec="0".$sec;}
$month = substr($mysqltime, 4, 2)*1;
$day = substr($mysqltime, 6, 2)*1;
$year = substr($mysqltime, 0, 4);
$datetime=$hour.":".$min.":".$sec."  ".$month."-".$day."-".$year;
echo "<table border = '1' bordercolor = 'black' width = '600'><tr><td colspan='2' valign='top'><strong>Subject:</strong> ".strip_tags($row[Subject])."</td></tr><tr><td><strong>Sender:</strong> ".$this->Format($this->GetUserName())."<br /></td>";
echo "<td><strong>Recipient:</strong> ".$this->Format($row[UserTo])."</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>";
// DELETE code (now updates table to non-viewing instead of deleting)
if($action==delete) {
echo "<font face=verdana>Message Deleted.</font>";
echo "The message wasn't deleted.";
if ($action==contacts){
$addcontact=$_GET['cntct'];
$table = $this->config["table_prefix"]."mailinfo";
$field1 = "info";
$field1_label = "Contact Names";
$field2 = "notes";
$field2_label = "Notes";
$deletecnt = $_GET['deletecnt'];
$field1_value=$_POST['field1_value'];
if ($field1_value) {$insert="1";} else {$insert="";}
$field2_value=$_POST['field2_value'];
$category="contact";
if ($user = $this->GetUser()){
echo "Error #".mysql_errno(). " (".mysql_error(). ")<br>";
// This is the entry boxes
echo "<td><input type='text' size='15' maxlength='65' name='field1_value' value='$addcontact'></td>\n";
echo "<input type='submit' value=\" Add \"></td>\n";
// This is the data under the entry boxes
echo "<td>".$this->format(strip_tags($row[2]))."</td>\n";
echo "<td>".strip_tags($row[3])."</td>\n";
echo "</table>";
if ($action==folders){
$table = $this->config["table_prefix"]."mailinfo";
$field1 = "info";
$field1_label = "Folder List";
$field2 = "notes";
$field2_label = "Notes";
$deletefldr = $_GET['deletefldr'];
$fldr = $_GET['fldr'];
$field1_value=$_POST['field1_value'];
if ($field1_value) {$insert="1";} else {$insert="";}
$field2_value=$_POST['field2_value'];
$category="folder";
if ($user = $this->GetUser()){
mysql_query("DELETE from $table WHERE id='$deletefldr' AND owner='$username'");
// change files from being stored in deleted folder to being stored in inbox
// This is the entry boxes
echo "<input type='submit' value=\" Add \"></td>\n";
// This is the data under the entry boxes
echo "<td>".$this->format(strip_tags($row[2]))."</td>\n";
echo "<td>".strip_tags($row[3])."</td>\n";
<center>Delete</center></a></td>\n";
echo "<table width='650'><tr><td>";
if ($action==users){
$last_users = $this->LoadAll("select name from ".$this->config["table_prefix"]."users order by name ASC");
// $htmlout = "<strong><em>User List.</em></strong> Click on the name to add it to the contact list.<br />";
echo "<strong><em>User List.</em></strong> Click on the name to add it to the contact list.<br />";
echo "</table>";
#### ####
#### Author : Harish Chauhan ####
#### Date : 27 Sep,2004 ####
#### Updated: ####
#### ####
var $records_per_page=1; ///how many records would be displayed at a time
if($scroll_num!=0)
$total_records=0;
if($records_per_page<=0)
$records_per_page=$this->total_records;
$this->records_per_page=$records_per_page;
if(!$this->is_first_page()&& $this->show_first_last)
echo ' <a href="'.$this->page_name.'&page=0'.$this->qry_str.'" '.$link_para.'>'.$user_link.'</a> ';
elseif($this->show_first_last && $this->show_disabled_links)
echo $user_link;
if(!$this->is_last_page()&& $this->show_first_last)
echo ' <a href="'.$this->page_name.'&page='.($this->total_page-1).$this->qry_str.'" '.$link_para.'>'.$user_link.'</a> ';
elseif($this->show_first_last && $this->show_disabled_links)
echo $user_link;
if(!$this->is_last_page()&& $this->show_prev_next)
echo ' <a href="'.$this->page_name.'&page='.($this->page+1).$this->qry_str.'" '.$link_para.'>'.$user_link.'</a> ';
elseif($this->show_prev_next && $this->show_disabled_links)
echo $user_link." ";
if(!$this->is_first_page()&& $this->show_prev_next)
echo ' <a href="'.$this->page_name.'&page='.($this->page-1).$this->qry_str.'" '.$link_para.'>'.$user_link.'</a> ';
elseif($this->show_prev_next && $this->show_disabled_links)
echo " ".$user_link;
if($this->page>$this->scroll_page &&$this->show_scroll_prev_next)
echo ' <a href="'.$this->page_name.'&page='.($this->page-$this->scroll_page).$this->qry_str.'" '.$link_para.'>'.$user_link.'</a> ';
elseif($this->show_scroll_prev_next && $this->show_disabled_links)
echo $user_link;
if($this->total_page>$this->page+$this->scroll_page &&$this->show_scroll_prev_next)
echo ' <a href="'.$this->page_name.'&page='.($this->page+$this->scroll_page).$this->qry_str.'" '.$link_para.'>'.$user_link.'</a> ';
elseif($this->show_scroll_prev_next && $this->show_disabled_links)
echo $user_link;
$j=0;
if($this->page>($scroll_page/2))
$j=$this->page-intval($scroll_page/2);
if($j+$scroll_page>$this->total_page)
$j=$this->total_page-$scroll_page;
if($j<0)
for(;$i<$j+$scroll_page && $i<$this->total_records;$i++)
{
if($i==$this->page)
echo ($i+1);
else
echo ' <a href="'.$this->page_name.'&page='.$i.$this->qry_str.'" '.$link_para.'>'.($i+1).'</a> ';
}
$this->page=$_REQUEST['page'];
if(!is_numeric($this->page))
$this->page=0;
$this->start=$this->page*$this->records_per_page;
$this->total_page=@intval($this->total_records/$this->records_per_page);
if($this->total_records%$this->records_per_page!=0)
$this->total_page++;
$this->calculate();
return $qry." LIMIT $this->start,$this->records_per_page";
This is the inbox (note the * indicator in the header that there is unread mail)...
http://gmbowen.educ.unb.ca/wikitest/inbox.jpg
http://gmbowen.educ.unb.ca/wikitest/compose.jpg
http://gmbowen.educ.unb.ca/wikitest/sentbox.jpg
http://gmbowen.educ.unb.ca/wikitest/folderlist.jpg
http://gmbowen.educ.unb.ca/wikitest/contactlist.jpg
http://gmbowen.educ.unb.ca/wikitest/userlist.jpg
http://gmbowen.educ.unb.ca/wikitest/foldermsg.jpg
http://gmbowen.educ.unb.ca/wikitest/message.jpg
http://gmbowen.educ.unb.ca/wikitest/forward.jpg


Revision [5624]

Edited on 2005-02-04 18:22:21 by NilsLindenberg [cat. added]
Additions:
http://gmbowen.educ.unb.ca/wikitest/forward.jpg
----
CategoryUserContributions
Deletions:
http://gmbowen.educ.unb.ca/wikitest/forward.jpg


Revision [5621]

Edited on 2005-02-04 16:38:04 by GmBowen [notification of upcoming revision]
Additions:
**Note:** There will be a feature update coming in the next day (colored tab filters for organizing, "urgent" indicator, changes in links found in folder/contact tables)....which involve database changes. If you're thinking of using this you might want to wait for the new code (it'll be easier to install than upgrade which will involve adding fields to the database).


Revision [5462]

Edited on 2005-02-02 03:35:56 by GmBowen [initial release of private messaging system (minor code update)]
Additions:
$to=addslashes($to);
$subject=addslashes($subject);
$message=addslashes($message);
echo "<td width='155'> Move to Folder:</td>\n";
echo "<td width='60'> Delete:</td>\n";
echo "<tr><td>$status <a href=".$link."&action=view&mail_id=$row[mail_id]>".strip_tags($row[Subject])."</a><small> (".$datetime.")</small></td><td>".$this->Format($row[UserFrom])."<small> [<a href=".$link."&action=contacts&cntct=".$row[UserFrom].">-></a>]</small></td><td align='left' width='155'>";
Deletions:
echo "<form action=".$link."&action=compose2 method=post>";
echo "<td width='175'> Move to Folder:</td>\n";
echo "<td width='75'> Delete:</td>\n";
echo "<tr><td>$status <a href=".$link."&action=view&mail_id=$row[mail_id]>".strip_tags($row[Subject])."</a><small> (".$datetime.")</small></td><td>".$this->Format($row[UserFrom])."<small> [<a href=".$link."&action=contacts&cntct=".$row[UserFrom].">-></a>]</small></td><td align=left width=175>";


Revision [5459]

The oldest known version of this page was created on 2005-02-02 02:41:38 by GmBowen [initial release of private messaging system (minor code update)]
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki