<?
/**
* This file contains classes used to form the todo plugin for Emailr
*
* This file provides classes used to form the todo plugin for Emailr, which
* allows users to create lists of todo bullet point items via email submissions.
* @package Emailr
* @subpackage Plugins
* @author Jon Herron
* @version 0.1
* @since 03.09.2008
*/
require_once realpath(dirname(__file__) . "/../common/Environment.inc");
require_once realpath(dirname(__file__) . "/../common/BaseClasses.inc");
require_once realpath(dirname(__file__) . "/../common/dbconn.inc");
/**
* Class used to provide todo list functionality for Emailr
*
* This class will provide methods to manage email submissions from a user to
* supply the Emailr application with lists of todos. This lists will be parsed
* and grouped by subject line, one todo per line. The plain text version of the
* email will be used whenever possible.
* @author Jon Herron
* @package Emailr
* @subpackage Plugins
* @version 0.1
* @since 03.09.2008
*/
class todo extends EmailrPluginBase
{
/**
* Public constructor for todo
*
* This public constructor will create a new instance of the todo class.
* @access public
* @author Jon Herron
* @returns todo class instance
* @version 0.0.0.1
* @since 02.24.2008
*/
public function todo()
{
parent::EmailrPluginBase();
$this->_logger->Debug("Inside todo constructor, logger created.");
$this->_logger->Debug("Leaving todo constructor");
}
/**
* Public function to parse a given mail id
*
* This public function will parse the email found in the database using the passed in mail id
* @access public
* @author Jon Herron
* @param int $mailid id of the mail in the database
* @version 0.1
* @since 03.09.2008
*/
public function Parse($mailid)
{
$this->_logger->Debug("Inside Parse, mailid is $mailid");
// get the list of sections for the passed in mail id
$sections = $this->GetSectionsForMailID($mailid);
$this->_logger->Debug("Got sections for mail id");
//find the appropriate section to parse
$sectionID = $this->GetSectionIDToParse($sections);
$this->_logger->Debug("Got section id to parse");
// read the file from the parsed folder
$contents = $this->GetSectionContents($sectionID);
$this->_logger->Debug("Got contents");
// split on line breaks
$todos = explode("\n", $contents);
$this->_logger->Debug("Split contents on line breaks");
$saveTodo = true;
// save each line as a new todo
foreach($todos as $todo)
{
if($saveTodo)
{
if(trim($todo) == "")
{
$saveTodo = false;
$this->_logger->Debug("Blank line found, todo saving aborting for this mail");
}
else
{
$this->SaveTodo($mailid, $todo);
$this->_logger->Debug("Saved todo");
}
}
}
$this->_logger->Debug("Leaving Parse");
}
/**
* Private function to find appropriate section to parse for todos
*
* This public function will parse the email found in the database using the passed in mail id
* @access private
* @author Jon Herron
* @param array $sections array of section ids to subtypes
* @version 0.1.5
* @since 03.15.2008
*/
private function GetSectionIDToParse($sections)
{
$this->_logger->Debug("Inside GetSectionIDToParse");
$sectionID = -1;
foreach($sections as $id=>$subtype)
{
$this->_logger->Debug("Found id of $id, subtype of $subtype");
if($subtype == "PLAIN")
{
$sectionID = $id;
$this->_logger->Debug("Using this section");
}
}
$this->_logger->Debug("Leaving GetSectionIDToParse, sectionID is $sectionID");
return($sectionID);
}
/**
* Private function to save the passed in todo for the given mailid
*
* This public function will save the passed in todo and associate with the passed in mailid
* @access private
* @author Jon Herron
* @param $mailid int id of the mail being parsed
* @param $todo string todo to save
* @version 0.1.5
* @since 03.15.2008
*/
private function SaveTodo($mailid, $todo)
{
$this->_logger->Debug("Inside SaveTodo, mailid is $mailid, todo is $todo");
$todo = mysql_real_escape_string($todo, GetMyConnection());
$sql = "INSERT INTO emailr_todo_list
(mailid, todo, completed, enabled, dateadded, lastmodified)
values
($mailid, '$todo', 0, 1, now(), now())";
$this->_logger->Debug("SQL is $sql");
$result = mysql_query($sql, GetMyConnection());
if(!$result)
{
$this->_logger->Error(mysql_error());
}
$this->_logger->Debug("Leaving SaveTodo");
}
}
?>