diff --git a/presentation/lookAndFeel/knowledgeTree/discussions/addCommentBL.php b/presentation/lookAndFeel/knowledgeTree/discussions/addCommentBL.php
new file mode 100644
index 0000000..581b848
--- /dev/null
+++ b/presentation/lookAndFeel/knowledgeTree/discussions/addCommentBL.php
@@ -0,0 +1,99 @@
+fileSystemRoot/lib/visualpatterns/PatternListBox.inc");
+ require_once("$default->fileSystemRoot/lib/visualpatterns/PatternCreate.inc");
+ require_once("$default->fileSystemRoot/lib/visualpatterns/PatternMainPage.inc");
+ //require_once("addUnitUI.inc");
+ //require_once("../adminUI.inc");
+ require_once("addCommentUI.inc"); //###
+
+ require_once("$default->fileSystemRoot/presentation/lookAndFeel/knowledgeTree/foldermanagement/folderUI.inc");
+ require_once("$default->fileSystemRoot/lib/documentmanagement/Document.inc");
+ require_once("$default->fileSystemRoot/lib/foldermanagement/Folder.inc");
+ require_once("$default->fileSystemRoot/lib/users/User.inc");
+ //require_once("../viewDiscussionUI.inc"); //###
+ //require_once("$default->fileSystemRoot/lib/unitmanagement/Unit.inc");
+ //require_once("$default->fileSystemRoot/lib/unitmanagement/UnitOrganisationLink.inc");
+ require_once("$default->fileSystemRoot/lib/security/permission.inc");
+ require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc");
+ require_once("$default->fileSystemRoot/lib/visualpatterns/PatternCustom.inc");
+ require_once("$default->fileSystemRoot/lib/discussions/DiscussionThread.inc"); //###
+ require_once("$default->fileSystemRoot/lib/discussions/DiscussionComment.inc"); //###
+ //require_once("$default->fileSystemRoot/lib/foldermanagement/Folder.inc");
+ //require_once("$default->fileSystemRoot/presentation/lookAndFeel/knowledgeTree/foldermanagement/folderUI.inc");
+ require_once("$default->fileSystemRoot/presentation/Html.inc");
+
+ $oPatternCustom = & new PatternCustom();
+
+ if(checksession) {
+ if (isset($fAddComment)) {
+ if ($fDocumentID > 0) {
+ $main->setFormAction($_SERVER['PHP_SELF'] . "?fAddCommentSubmit=1&iDocumentID=$fDocumentID");
+ $oPatternCustom->setHtml(getAddComment($fDocumentID,$sSubject,$sBody));
+ }
+ else {
+ //nothing
+ }
+ } else if (isset($fViewComment)){
+ if (isset($iCommentID)) {
+ $oComment = DiscussionComment::get($iCommentID);
+ $oUser = User::get($oComment->getUserID());
+
+ $oPatternCustom->setHtml(getCommentBody($oComment->getBody(), $oComment->getSubject(),$oComment->getDate(),$iDocumentID,$oUser->getUserName())) ;
+ }
+ } else if (isset($fAddCommentSubmit)) {
+ $iThreadID = DiscussionThread::getThreadIDforDoc($iDocumentID);
+
+ if ($iThreadID > 0){
+ if ($_POST["NewComment"] != "" and $_POST["NewCommentSubject"] != "")
+ {
+ // Create the new comment
+ $oComment = & new DiscussionComment(urlencode($_POST["NewComment"]),$_POST["NewCommentSubject"],$_SESSION["userID"],$iDocumentID);
+ $oComment->setThreadID($iThreadID);
+ $oComment->create();
+
+ if($oComment->getID() > 0) {
+ $oThread = DiscussionThread::get($iThreadID);
+ $oThread->setLastCommentID($oComment->getID());
+ $oThread->setNumberOfReplies();
+ if ($oThread->Update()) {
+ $oPatternCustom->addHtml(getSubmitSuccessPage($iDocumentID));
+ }else {
+ $oPatternCustom->addHtml(getViewFailPage("Thread Object failed to update."));
+ }
+ }else {
+ $oPatternCustom->addHtml(getViewFailPage("Comment Object failed in creation.") );
+ }
+ }else {
+ $oPatternCustom->addHtml(getViewFailPage("The subject line and/or body may be empty.") );
+ $main->setFormAction($_SERVER['PHP_SELF'] . "?fAddCommentSubmit=1&iDocumentID=$fDocumentID");
+ $oPatternCustom->addHtml(getAddComment($fDocumentID,$_POST["NewCommentSubject"],$_POST["NewComment"]));
+ }
+ }else{
+ $oPatternCustom->addHtml(getViewFailPage("No threadID($iThreadID) exists for this document"));
+ }
+
+ } else if (isset($fReplyComment)){ // if user is replying to existing comment
+ $main->setFormAction($_SERVER['PHP_SELF'] . "?fAddCommentSubmit=1&iDocumentID=$fDocumentID");
+ $oPatternCustom->addHtml(getAddComment($fDocumentID,"Re: " . $CommentSubject , "\n\n\n[Start Text Body]\n\n" . $Comment . "\n\n[End Text Body]"));
+
+ }else { // If no discussion exists
+ $oPatternCustom->setHtml(getViewFailPage("No discussions exist"));
+ }
+
+ } // end of if checksession
+
+ $main->setCentralPayload($oPatternCustom);
+ $main->render();
+}
+?>
diff --git a/presentation/lookAndFeel/knowledgeTree/discussions/addCommentUI.inc b/presentation/lookAndFeel/knowledgeTree/discussions/addCommentUI.inc
new file mode 100644
index 0000000..9bba5fa
--- /dev/null
+++ b/presentation/lookAndFeel/knowledgeTree/discussions/addCommentUI.inc
@@ -0,0 +1,103 @@
+
graphicsUrl/widgets/back.gif\" border=\"0\" />";
+// $sToRender .= "";
+// $sToRender .= "";
+
+ return $sToRender;
+}
+
+// If there are no threads to view for a document
+function getViewFailPage($sMessage)
+{
+ global $default;
+
+ if (strlen($sMessage)>0){
+ $sToRender = $sMessage;
+ }
+ else $sToRender = "Current document has no discussion. Press the ADD button to start a discussion.";
+
+ return $sToRender;
+}
+
+function renderHeading($sHeading) {
+ global $default;
+
+ $sSectionName = $default->siteMap->getSectionName(substr($_SERVER["PHP_SELF"], strlen($default->rootUrl), strlen($_SERVER["PHP_SELF"])));
+ $sColor = $default->siteMap->getSectionColour($sSectionName, "th");
+ $sToRender = "
\n";
+ $sToRender .= "| $sHeading |
\n";
+ $sToRender .= "
\n";
+ $sToRender .= "
\n";
+ $sToRender .= "
\n";
+ return $sToRender;
+}
+
+function renderDocumentPath($iDocumentID) {
+ global $default;
+
+ $oDocument = & Document::get($iDocumentID);
+ $sSectionName = $default->siteMap->getSectionName(substr($_SERVER["PHP_SELF"], strlen($default->rootUrl), strlen($_SERVER["PHP_SELF"])));
+ $sTDBGColour = $default->siteMap->getSectionColour($sSectionName, "td");
+ $sDocumentPath = displayFolderPathLink(Folder::getFolderPathAsArray($oDocument->getFolderID()), Folder::getFolderPathNamesAsArray($oDocument->getFolderID()), "$default->rootUrl/control.php?action=browse") . " > ";
+ $sDocumentPath .= "rootUrl/presentation/lookAndFeel/knowledgeTree/documentmanagement/viewBL.php?fDocumentID=" . $oDocument->getID() . "&fForInlineView=1\">" . $oDocument->getName() . "";
+ return "\n";
+}
+
+
+function getAddComment($fDocumentID, $sSubject, $sBody) {
+ global $default;
+
+ $iThreadID = DiscussionThread::getThreadIDforDoc($fDocumentID);
+ $oThread = DiscussionThread::get($iThreadID);
+ if($oThread) { // if thread object exists
+ $sHeading = "Add a Comment";
+
+ $sToRender .= renderHeading($sHeading);
+ $sToRender .= renderDocumentPath($oThread->getDocumentID());
+ $sToRender .= "\n";
+ $sToRender .= "";
+ }
+ return $sToRender;
+
+}
+
+function getCommentBody($sCommentBody, $sCommentSubject,$dDate,$iDocumentID, $sUserName) {
+ global $default;
+
+ $sHeading = "Document Comment";
+
+ $sToRender .= renderHeading($sHeading);
+ $sToRender .= renderDocumentPath($iDocumentID);
+ $sToRender .= "
Author: $sUserName";
+ $sToRender .= "";
+ $sToRender .= "| Subject: | $sCommentSubject | ";
+ $sToRender .= "Date: $dDate |
$sCommentBody | ";
+ $sToRender .= "
";
+ return $sToRender;
+}
+
+function viewDiscussionPage() {
+ global $default;
+
+ $sToRender = "";
+ return $sToRender;
+}
+?>
\ No newline at end of file
diff --git a/presentation/lookAndFeel/knowledgeTree/discussions/viewDiscussionBL.php b/presentation/lookAndFeel/knowledgeTree/discussions/viewDiscussionBL.php
new file mode 100644
index 0000000..7bcd8f8
--- /dev/null
+++ b/presentation/lookAndFeel/knowledgeTree/discussions/viewDiscussionBL.php
@@ -0,0 +1,85 @@
+fileSystemRoot/lib/visualpatterns/PatternListBox.inc");
+ require_once("$default->fileSystemRoot/lib/visualpatterns/PatternCreate.inc");
+ //require_once("addUnitUI.inc");
+ //require_once("../adminUI.inc");
+ require_once("viewDiscussionUI.inc"); //###
+
+ require_once("$default->fileSystemRoot/presentation/lookAndFeel/knowledgeTree/foldermanagement/folderUI.inc");
+ require_once("$default->fileSystemRoot/lib/documentmanagement/Document.inc");
+ require_once("$default->fileSystemRoot/lib/foldermanagement/Folder.inc");
+ require_once("$default->fileSystemRoot/lib/users/User.inc");
+ //require_once("../viewDiscussionUI.inc"); //###
+ //require_once("$default->fileSystemRoot/lib/unitmanagement/Unit.inc");
+ //require_once("$default->fileSystemRoot/lib/unitmanagement/UnitOrganisationLink.inc");
+ require_once("$default->fileSystemRoot/lib/security/permission.inc");
+ require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc");
+ require_once("$default->fileSystemRoot/lib/visualpatterns/PatternCustom.inc");
+ require_once("$default->fileSystemRoot/lib/discussions/DiscussionThread.inc"); //###
+ require_once("$default->fileSystemRoot/lib/discussions/DiscussionComment.inc"); //###
+ //require_once("$default->fileSystemRoot/lib/foldermanagement/Folder.inc");
+ //require_once("$default->fileSystemRoot/presentation/lookAndFeel/knowledgeTree/foldermanagement/folderUI.inc");
+ require_once("$default->fileSystemRoot/presentation/Html.inc");
+
+ $oPatternCustom = & new PatternCustom();
+
+if(checksession) {
+ if (isset($fForDiscussion)) {
+ if ($fDocumentID > 0) {
+ $iThreadID = DiscussionThread::getThreadIDforDoc($fDocumentID);
+ if ($iThreadID) {// if thread ID does exist
+ $oThread = DiscussionThread::get($iThreadID);
+ if($oThread) { // if thread object exists
+ // Iterate through the number of comments
+ $sAllCommentID = $oThread->getAllCommentID();
+ $arrAllCommentID = explode(",", $sAllCommentID);
+ $iNumMax = $oThread->getNumberOfReplies();
+ for ($i = 0; $i < $iNumMax; $i++) {
+ $iCommentID = $arrAllCommentID[$i];
+ $oComment = DiscussionComment::get($iCommentID);
+ $oUser = User::get($oComment->getUserID());
+ $oPatternCustom->addHtml(getViewComment($i+1,$oThread,$oComment,$oUser));
+ }
+ // On opening, increment the number of views of current thread & update database
+ if($_SESSION['Discussion'][0]->bViews !=true ){
+ $oThread->setNumberOfViews();
+ if($oThread->Update() == false) $oPatternCustom->addHtml("Failed to update. Please Contact Database Administrator in this regard") ;
+ $_SESSION['Discussion'][0]->bViews = true;
+ }
+ } else { $oPatternCustom->setHtml(getViewFailPage("")) ;}
+ } else { $oPatternCustom->addHtml(getViewFailPage("No threadID for this document.")); }
+ } else { }
+ } else if (isset($fViewComment)){
+ if (isset($iCommentID)) {
+ $oComment = DiscussionComment::get($iCommentID);
+ $oUser = User::get($oComment->getUserID());
+
+ //$main->setFormAction(generateControllerLink("addComment", "fDocumentID=$iDocumentID&fCommentID=$iCommentID&fReplyComment=1"));
+ $main->setFormAction("/presentation/lookAndFeel/knowledgeTree/discussions/addCommentBL.php?fDocumentID=$iDocumentID&fCommentID=$iCommentID&fReplyComment=1");
+ //$main->setFormAction($_SERVER['PHP_SELF'] . "?fReplyComment=1");
+ $oPatternCustom->setHtml(getCommentBody($oComment,$iDocumentID,$oUser)) ;
+ }
+ } else if (isset($fReplyComment)){
+ $oPatternCustom->setHtml("###" . count($_POST) . "###" . $Comment . "###" . $CommentSubject);
+ } else { // If no discussion exists
+ }
+
+ } // end of if checksession
+
+ $main->setCentralPayload($oPatternCustom);
+ $main->render();
+
+}
+?>
diff --git a/presentation/lookAndFeel/knowledgeTree/discussions/viewDiscussionUI.inc b/presentation/lookAndFeel/knowledgeTree/discussions/viewDiscussionUI.inc
new file mode 100644
index 0000000..3e15ff4
--- /dev/null
+++ b/presentation/lookAndFeel/knowledgeTree/discussions/viewDiscussionUI.inc
@@ -0,0 +1,120 @@
+0){
+ $sToRender = $sMessage;
+ }
+ else $sToRender = "Current document has no discussion. Press the ADD button to start a discussion.";
+
+ return $sToRender;
+}
+
+function renderHeading($sHeading) {
+ global $default;
+
+ $sSectionName = $default->siteMap->getSectionName(substr($_SERVER["PHP_SELF"], strlen($default->rootUrl), strlen($_SERVER["PHP_SELF"])));
+ $sColor = $default->siteMap->getSectionColour($sSectionName, "th");
+ $sToRender = "\n";
+ $sToRender .= "| $sHeading |
\n";
+ $sToRender .= "
\n";
+ $sToRender .= "
\n";
+ $sToRender .= "
\n";
+ return $sToRender;
+}
+
+function renderDocumentPath($iDocumentID) {
+ global $default;
+
+ $oDocument = & Document::get($iDocumentID);
+ $sSectionName = $default->siteMap->getSectionName(substr($_SERVER["PHP_SELF"], strlen($default->rootUrl), strlen($_SERVER["PHP_SELF"])));
+ $sTDBGColour = $default->siteMap->getSectionColour($sSectionName, "td");
+ $sDocumentPath = displayFolderPathLink(Folder::getFolderPathAsArray($oDocument->getFolderID()), Folder::getFolderPathNamesAsArray($oDocument->getFolderID()), "$default->rootUrl/control.php?action=browse") . " > ";
+ $sDocumentPath .= "rootUrl/presentation/lookAndFeel/knowledgeTree/documentmanagement/viewBL.php?fDocumentID=" . $oDocument->getID() . "&fForInlineView=1\">" . $oDocument->getName() . "";
+ return "\n";
+}
+
+function getViewComment($iNum,$oThread,$oComment,$oUser) {
+ global $default;
+
+ $iSubjectChars = 59;
+ // If iNum is odd then highlight it
+ if (($iNum%2) == 1) $BGcolor = "#F5F6EE";
+ if (($iNum%2) == 0) $UserBGcolor = "#F5F6EE";
+
+ // If the Subject string is too long
+ if (strlen($oComment->getSubject())>$iSubjectChars ) $dotdot = " ...";
+ if (strlen($oUser->getUserName())> 13 ) $Userdotdot = " ...";
+
+ // If this is the first Subject line then create a table
+ if ($iNum == 1) {
+ $sHeading = "Document Discussion Comments";
+
+ $sToRender .= renderHeading($sHeading );
+ $sToRender .= renderDocumentPath($oThread->getDocumentID());
+ $sToRender .= "";
+ $sToRender .= "| Views: " . $oThread->getNumberOfViews() . " | ";
+ $sToRender .= " | ";
+ $sToRender .= "Replies: " . $oThread->getNumberOfReplies() . " | ";
+ $sToRender .= "
\n";
+ $sToRender .= "\n";
+ $sToRender .= "\n\n";}
+ return $sToRender;
+}
+
+//function getCommentBody($sCommentBody, $sCommentSubject,$dDate,$iDocumentID, $sUserName) {
+function getCommentBody($oComment, $iDocumentID, $oUser) {
+ global $default;
+
+ $sHeading = "Document Comment";
+
+ $sToRender .= renderHeading($sHeading);
+ $sToRender .= renderDocumentPath($iDocumentID);
+
+ $sToRender .= "
";
+
+
+ return $sToRender;
+}
+
+function viewDiscussionPage() {
+ global $default;
+
+ $sToRender = "";
+ return $sToRender;
+}
+?>
\ No newline at end of file