Revision [5462]

This is an old revision of WikkaMail made by GmBowen on 2005-02-02 03:35:56.

 

Wikka Mail

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.

The table prefixes should be set to match the prefix used in your wiki.
CREATE TABLE `wakka_mail` (
  `UserTo` tinytext NOT NULL,
  `folder` tinytext NOT NULL,
  `UserFrom` tinytext NOT NULL,
  `Subject` mediumtext NOT NULL,
  `Message` longtext NOT NULL,
  `status` text NOT NULL,
  `SentDate` text NOT 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
// 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.
// 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 added to the header after <h2> in php tags 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); // if no thread name specified, sets to pagename (but made to lower case)
$link = $this->config["base_url"].$this->MiniHref($method, $tag);
$userfrom = $this->GetUserName();
$username = $userfrom;
$folder=$_GET['folder'];
$which=$_REQUEST['whichfolder'];

$str = "SELECT DISTINCT info FROM ".$this->config["table_prefix"]."mailinfo WHERE type='folder' and owner='$username' ORDER BY info ASC";
$resultdrop = mysql_query($str);
?>

<table><tr><td>|</td><td> <a href="<?php echo $link; ?>&amp;action=inbox">Inbox</a> </td><td>|</td><td> <a href="<?php echo $link; ?>&amp;action=compose">Compose</a> </td><td>|</td><td>
<?php
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; ?>&amp;action=sent">Sent</a> </td><td>|</td><td> Manage <a href="<?php echo $link; ?>&amp;action=folders">Folders</a> / <a href="<?php echo $link; ?>&amp;action=contacts">Contacts</a> </td><td>| </td><td><a href="<?php echo $link; ?>&amp;action=users">Users</a> |</tr></table>

<?php
if ($_GET['action']=="compose" || $_GET['action']=="forward" || $_GET['action']=="contacts" || $_GET['action']=="folders" || $_GET['action']=="users"){echo "";
    } else {
    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>&nbsp;&nbsp;".$which;
}

$subject=$_GET[subject];
$action=$_GET['action'];
$mail_id=$_GET['mail_id'];
$id=$_GET['id'];
$to=$_GET['to'];

if($action==compose) {
$subject2=$_GET[subject];
echo "<table width='675'><tr><td>";
echo "<form action=".$link."&amp;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."&amp;action=compose&amp;to=".urlencode($row[info]).">".$row['info']."</a><br />";
       }
echo "</td></tr></table>";
}

if($action==forward && $mail_id!="") {
$username = $this->GetUserName();
echo "<table width='675'><tr><td>";
echo "<form action=".$link."&amp;action=compose2 method='post'>";
echo "<br /><table>";
$subject2 = "FWD:&nbsp;".$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="&nbsp;\n&nbsp;\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."&amp;action=forward&amp;to=$row[info]&amp;mail_id=$mail_id&amp;subject=".urlencode($subject).">".$row['info']."</a><br />";
       }
echo "</td></tr></table>";
}

// enters message from compose window (original or forward) into database
 if ($user = $this->GetUser()){
 if($action==compose2) {
 $to=$_POST['to'];
 $to=addslashes($to);
 $subject=$_POST['subject'];
 $subject=addslashes($subject);
 $message=$_POST['message'];
 $message=addslashes($message);
 $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, 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.";
     }
   }
 }
  }else{
  echo "You must be registered & logged in to use this Private Messaging System.<br />";
}

// code for moving messages to folders
$move2folder = $_REQUEST[move2folder];
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 "<strong>Message moved to ".$move2folder." folder.</strong>";
        } else {
        echo "The message wasn't moved.";
    }
}

// shows inbox
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'>";
       //needed for pagination of sent box
       $record_per_page=10;
    $total_records=mysql_num_rows($result);
       $scroll=3;
    $page=new Page(); //creating new instance of Class Page
    $link2=$link."&amp;action=inbox";
    $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='4' align='center'>";
    if ($total_records>$record_per_page) {echo $page->get_page_nav();}
    echo "</td></tr>";
  echo  "<tr bgcolor=#dddddd>\n";
  echo  "<td>&nbsp;Message Topic:</td>\n";
  echo  "<td width='85'>&nbsp;Sender:</td>\n";
  echo  "<td width='155'>&nbsp;Move to Folder:</td>\n";
  echo  "<td width='60'>&nbsp;Delete:</td>\n";
  echo  "</tr>\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."&nbsp;&nbsp;".$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&nbsp;<a href=".$link."&amp;action=view&amp;mail_id=$row[mail_id]>".strip_tags($row[Subject])."</a><small>&nbsp;(".$datetime.")</small></td><td>".$this->Format($row[UserFrom])."<small>&nbsp;[<a href=".$link."&amp;action=contacts&amp;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&amp;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."&amp;action=delete&amp;id=".$row[mail_id]."' }\">Delete</a>]<br /></td></tr>";
    }
echo "</table>";
}

// show sent box
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'>";
       //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."&amp;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>&nbsp;Message Topic:</td>\n";
  echo  "<td width='85'>&nbsp;Sent to:</td>\n";
  echo  "<td width='75'>&nbsp;Read?</td>\n";
  echo  "</tr>\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."&nbsp;&nbsp;".$month."-".$day."-".$year;
echo "<tr><td><a href=".$link."&amp;action=view2&amp;mail_id=$row[mail_id]>".strip_tags($row[Subject])."</a><small>&nbsp;(".$datetime.")</small></td><td>".$this->Format($row[UserTo])."<small>&nbsp;[<a href=".$link."&amp;action=contacts&amp;cntct=".$row[UserTo].">-></a>]</small></td><td width=50>&nbsp;$row[status]<br></td></tr>";
    }
echo "</table>";
}

// Code to show folders according to selection
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");
 echo "<table cellpadding='2' cellspacing='3' width='750' valign='top'>";
 $numrows=mysql_num_rows($result);
  if ($numrows==0) {echo "<br /><em>There are no messages currently stored in this folder.</em><br /><br />";
    } else {
   echo  "<tr bgcolor=#dddddd>\n";
   echo  "<td>&nbsp;Message Topic:</td>\n";
   echo  "<td width='85'>&nbsp;Sender:</td>\n";
   echo  "<td width='175'>&nbsp;Move to Folder:</td>\n";
   echo  "<td width='75'>&nbsp;Delete:</td>\n";
   echo  "</tr>\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."&nbsp;&nbsp;".$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&nbsp;<a href=".$link."&amp;action=view&amp;mail_id=$row[mail_id]&amp;folder=$which>".strip_tags($row[Subject])."</a>&nbsp;<small>(".$datetime.")</small></td><td width=125>".$this->Format($row[UserFrom])."<small>&nbsp;[<a href=".$link."&amp;action=contacts&amp;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&amp;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 width='50'> [<a href=\"javascript: if(confirm('Are you sure you want to delete this item?')){ window.self.location='".$link."&amp;action=delete&amp;id=".$row[mail_id]."' }\">Delete</a>]<br></td></tr>";
      }
   echo "</table>";
  }
}

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) {
    $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.");
    $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."&nbsp;&nbsp;".$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>&nbsp;[<a href=".$link."&amp;action=contacts&amp;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."&amp;action=compose&amp;to=$row[UserFrom]&amp;subject=RE:".urlencode($row[Subject]).">Reply</a> / <a href=".$link."&amp;action=forward&amp;mail_id=$row[mail_id]&amp;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."&amp;action=delete&amp;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'");
    } else {
    echo "<font face=verdana><b>This isn't your mail!";    
    }
}

// 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."&nbsp;&nbsp;".$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>&nbsp;".$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) {
    $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 Deleted.</font>";
        } else {
        echo "The message wasn't deleted.";
    }
}

// code to manage contact list
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()){
   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>&nbsp;</td>\n";
  echo  "</tr>\n";

// This is the entry boxes
  echo  "<form action=\"$link&amp;action=contacts\" method=\"post\">\n";
  echo  "<tr>\n";
  echo  "<input type='hidden' name='insert' value='1'></td>\n";
  echo  "<td><input type='text' size='15' 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>".$this->format(strip_tags($row[2]))."</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."&amp;action=contacts&amp;deletecnt=".$row[4]."' }\"><center>Delete</center></a></td>\n";
      echo  "</tr>\n";
      }
echo "</table>";
}

// code to manage folder list
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()){
  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'");
  // change files from being stored in deleted folder 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>&nbsp;</td>\n";
  echo  "</tr>\n";

// This is the entry boxes
  echo  "<form action=\"$link&amp;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>".$this->format(strip_tags($row[2]))."</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."&amp;action=folders&amp;deletefldr=".$row[4]."&amp;fldr=".$row[2]."' }\">
<center>Delete</center></a></td>\n"
;
      }
  echo "</table>";
}

// code to display user list
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 />";
  foreach($last_users as $user)
   {
    echo "<a href=".$link."&amp;action=contacts&amp;cntct=".$user["name"].">".$user["name"]."</a> ";
   }
  echo "</td></tr></table>";
}
echo "</table>";
?>


The following file should be saved as page.inc.php in a directory called scripts in the wikka root....
<?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 "&amp;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="««&nbsp;&nbsp;";
        if(!$this->is_first_page()&& $this->show_first_last)
            echo ' <a href="'.$this->page_name.'&amp;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="&nbsp;&nbsp;»»";
        if(!$this->is_last_page()&& $this->show_first_last)
            echo ' <a href="'.$this->page_name.'&amp;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.'&amp;page='.($this->page+1).$this->qry_str.'" '.$link_para.'>'.$user_link.'</a> ';
        elseif($this->show_prev_next && $this->show_disabled_links)
            echo $user_link."&nbsp;";
      }
      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.'&amp;page='.($this->page-1).$this->qry_str.'" '.$link_para.'>'.$user_link.'</a> ';
        elseif($this->show_prev_next && $this->show_disabled_links)
            echo "&nbsp;".$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.'&amp;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.'&amp;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.'&amp;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)...

http://gmbowen.educ.unb.ca/wikitest/inbox.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/compose.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/sentbox.jpg

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

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

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

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

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

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

This is the contents of a folder...

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

This is an example message...

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

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

http://gmbowen.educ.unb.ca/wikitest/forward.jpg
There are 7 comments on this page. [Show comments]
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki