diff --git a/presentation/lookAndFeel/knowledgeTree/discussions/addCommentBL.php b/presentation/lookAndFeel/knowledgeTree/discussions/addCommentBL.php
index 2453920..92fc931 100644
--- a/presentation/lookAndFeel/knowledgeTree/discussions/addCommentBL.php
+++ b/presentation/lookAndFeel/knowledgeTree/discussions/addCommentBL.php
@@ -43,105 +43,98 @@ require_once("$default->fileSystemRoot/presentation/Html.inc");
if(checkSession()) {
$oPatternCustom = & new PatternCustom();
require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc");
- if (isset($fAddComment)) { // User wishes to add a comment
- if ($fDocumentID > 0) { // The document ID is positive
+ // input validation
+ if (isset($fAddComment)) {
+ if (isset($fDocumentID)) {
$main->setFormAction($_SERVER['PHP_SELF'] . "?fAddCommentSubmit=1&iDocumentID=$fDocumentID");
$oPatternCustom->setHtml(getAddComment($fDocumentID,$sSubject,$sBody, $fCommentID, 1));
+ } else {
+ $main->setErrorMessage("You did not specify a document to add a comment to.");
}
- else { // And invalid Document ID was sent
- $main->setErrorMessage("The Document id cannot be lss than 0. ID is invalid.");
- }
-
- } else if (isset($fViewComment)){ // User wishes to view a comment
-
+ // User wishes to view a comment
+ } 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())) ;
+ $oPatternCustom->setHtml(getCommentBody($oComment->getBody(), $oComment->getSubject(), $oComment->getDate(), $iDocumentID,$oUser->getUserName())) ;
}
-
- } else if (isset($fAddCommentSubmit)) {
- if ($_POST["NewComment"] != "" && $_POST["NewCommentSubject"] != "") {
-
- if (isset($fNewThread)){ // Create a New Thread for this document as it doesn't exist
-
- // Create the thread Object
- $oThread = & new DiscussionThread(-1,$iDocumentID, $_SESSION["userID"]);
- $oThread->create();
- $iThreadID = $oThread->getID();
- }
- else { // Update the existing thread
- $iThreadID = DiscussionThread::getThreadIDforDoc($iDocumentID);
- }
-
- if ($iThreadID > 0){
- // Create the new comment
- $oComment = & new DiscussionComment($_POST["NewComment"], $_POST["NewCommentSubject"],$_SESSION["userID"],$iDocumentID);
- $oComment->setThreadID($iThreadID);
- $oComment->create();
-
- if($oComment->getID() > 0) {
-
- $oThread = DiscussionThread::get($iThreadID);
- $oThread->setLastCommentID($oComment->getID());
- if ($oThread->getFirstCommentID() == -1){ // if it is a new Thread
-
- $oThread->setFirstCommentID($oComment->getID());
- }
- if($_SESSION['Discussion' . $iDocumentID][0]->bViews != true ){ // Session variable is set to true if user views the thread
-
- $oThread->setNumberOfViews();
- $_SESSION['Discussion' . $iDocumentID][0]->bViews = true;
- }
- $oThread->setNumberOfReplies();
-
- if ($oThread->Update()) { //
- controllerRedirect("viewDiscussion", "fForDiscussion=1&fDocumentID=$iDocumentID");
- //$oPatternCustom->addHtml(getSubmitSuccessPage($iDocumentID));
- }else {
- $main->setErrorMessage("Thread Object failed to update");
- }
+ } else if (isset($fAddCommentSubmit)) {
+ $default->log->info("adding comment: subject=$fSubject; comment=$fComment");
+ if ( (strlen($fSubject) > 0) && (strlen($fComment) > 0) ) {
+ // create a new thread, unless we're replying
+ if (isset($fNewComment)) {
+ $oThread = & new DiscussionThread(-1, $iDocumentID, $_SESSION["userID"]);
+ $oThread->create();
+ $iThreadID = $oThread->getID();
+ // if this is a new thread, then set inReplyTo to -1
+ $fInReplyTo = -1;
+ } else {
+ // retrieve the thread id
+ $iThreadID = DiscussionThread::getThreadIDforDoc($fDocumentID);
+ }
+ if ($iThreadID) {
+ $default->log->info("addComment fInReplyTo=$fInReplyTo");
+ // Create the new comment
+ $oComment = & new DiscussionComment($fComment, $fSubject, $_SESSION["userID"], $iThreadID, $fInReplyTo);
+ $oComment->setThreadID($iThreadID);
+ $oComment->create();
+
+ if($oComment->getID() > 0) {
+ $oThread = DiscussionThread::get($iThreadID);
+ $oThread->setLastCommentID($oComment->getID());
+ if ($oThread->getFirstCommentID() == -1){ // if it is a new Thread
+ $oThread->setFirstCommentID($oComment->getID());
+ }
+ // Session variable is set to true if user views the thread
+ if ($_SESSION['Discussion' . $iDocumentID][0]->bViews != true ){
+ $oThread->incrementNumberOfViews();
+ $_SESSION['Discussion' . $iDocumentID][0]->bViews = true;
+ }
+ $oThread->incrementNumberOfReplies();
- }else {
- $main->setErrorMessage("Comment Object failed in creation");
+ if ($oThread->Update()) { //
+ controllerRedirect("viewDiscussion", "fForDiscussion=1&fDocumentID=$iDocumentID");
+ //$oPatternCustom->addHtml(getSubmitSuccessPage($iDocumentID));
+ } else {
+ $main->setErrorMessage("Thread Object failed to update");
}
-
- }else{ // There is no thread id for this document
- $main->setErrorMessage("No threadID($iThreadID) exists for this document");
- }// End Of if for THREAD ID test
-
- }else { // the user has not entered BOTH a subject and a text body
+ } else {
+ $main->setErrorMessage("Comment Object failed in creation");
+ }
+ } else {
+ $main->setErrorMessage("Could not create a new discussion thread.");
+ }
+ } else { // the user has not entered BOTH a subject and a text body
$main->setErrorMessage("The subject line and/or body should not be empty.");
$main->setFormAction($_SERVER['PHP_SELF'] . "?fAddCommentSubmit=1&iDocumentID=$fDocumentID");
- $oPatternCustom->addHtml(getAddComment($fDocumentID,$_POST["NewCommentSubject"],$_POST["NewComment"], $fCommentID, 1));
+ $oPatternCustom->addHtml(getAddComment($fDocumentID, $fSubject, $fComment, $fCommentID, 1));
} // end of IF for Subject and Body test
-
} else if (isset($fReplyComment)){ // if user is replying to existing comment
$main->setFormAction($_SERVER['PHP_SELF'] . "?fAddCommentSubmit=1&iDocumentID=$fDocumentID");
$oComment = DiscussionComment::get($fCommentID);
$oUser = User::get($oComment->getUserID());
- $sReplyBody = $oComment->getBody();
-
- $sReplyBodyHeader .= "\n\n>------ Original Message ------";
- $sReplyBodyHeader .= "\n>User: " . $oUser->getName();
- $sReplyBodyHeader .= "\n>Date: " . $oComment->getDate();
- $sReplyBodyHeader .= "\n>Subject: " . $oComment->getSubject();
- $sReplyBodyHeader .= "\n>---------------------------------------";
+ $sReplyBody = $oComment->getBody();
- $sReplyBody = $sReplyBodyHeader . "\n>" . str_replace("%0D%0A" ,"%0D%0A>", $sReplyBody); // Put in ">" as indentation for the reply
+ $sReplyBodyHeader .= "\n\n> ------ Original Message ------";
+ $sReplyBodyHeader .= "\n> User: " . $oUser->getName();
+ $sReplyBodyHeader .= "\n> Date: " . $oComment->getDate();
+ $sReplyBodyHeader .= "\n> Subject: " . $oComment->getSubject();
+ $sReplyBodyHeader .= "\n> ---------------------------------------";
+ $default->log->info("replyBody before=$sReplyBody; replyBodyAfter=" . str_replace("%0D%0A" ,"%0D%0A>", $sReplyBody));
+ $sReplyBody = $sReplyBodyHeader . "\n>" . str_replace(">" ,"> >", $sReplyBody); // Put in ">" as indentation for the reply
+ //$sReplyBody = $sReplyBodyHeader . "\n>" . str_replace("%0D%0A" ,"%0D%0A>", $sReplyBody); // Put in ">" as indentation for the reply
if (strpos($oComment->getSubject(), "Re:") != " "){
$sReply = "Re: ";
- }else { $sReply = ""; }
+ } else { $sReply = ""; }
$oPatternCustom->addHtml(getAddComment($fDocumentID, $sReply . $oComment->getSubject() , urldecode($sReplyBody), $fCommentID, "-1" ));
} else if (isset($fNewThread)){ // Start adding a new Thread
$main->setFormAction($_SERVER['PHP_SELF'] . "?fAddCommentSubmit=1&iDocumentID=$fDocumentID&fNewThread=1");
- $oPatternCustom->addHtml(getAddComment($fDocumentID, $CommentSubject , $Comment, $fCommentID, "1"));
+ $oPatternCustom->addHtml(getAddComment($fDocumentID, $CommentSubject ,$Comment, $fCommentID, "1"));
} else { // If no discussion exists
$main->setErrorMessage("Error: No discussion thread available");
diff --git a/presentation/lookAndFeel/knowledgeTree/discussions/addCommentUI.inc b/presentation/lookAndFeel/knowledgeTree/discussions/addCommentUI.inc
index bd46d7c..404f5be 100644
--- a/presentation/lookAndFeel/knowledgeTree/discussions/addCommentUI.inc
+++ b/presentation/lookAndFeel/knowledgeTree/discussions/addCommentUI.inc
@@ -48,7 +48,7 @@ function getSubmitSuccessPage($iDocumentID){
function getAddComment($fDocumentID, $sSubject, $sBody, $iCommentID, $fNewComment = null) {
global $default;
- $sHeading = "Add a Comment";
+ $sHeading = "Add a Comment";
$sToRender .= renderHeading($sHeading);
$sToRender .= displayDocumentPath($fDocumentID);
$sToRender .= "
\n";
@@ -56,14 +56,16 @@ function getAddComment($fDocumentID, $sSubject, $sBody, $iCommentID, $fNewCommen
$sToRender .= " ";
$sToRender .= " ";
$sToRender .= "graphicsUrl/widgets/submit.gif\" border=0>";
- if($fNewComment>0){ // If user is creating a new comment
+ if ($fNewComment>0) { // If user is creating a new comment
$sToRender .= "
\n";
-
- return $sToRender ;
+ return $sToRender;
}
// If there are no threads to view for a document
-function getViewFailPage($sMessage)
-{
+function getViewFailPage($sMessage) {
global $default;
-
- if (strlen($sMessage)>0){
+ if ( strlen($sMessage)>0 ) {
$sToRender = $sMessage;
+ } else {
+ $sToRender = "Current document has no discussion. Press the ADD button to start a discussion.";
}
- else $sToRender = "Current document has no discussion. Press the ADD button to start a discussion.";
-
return $sToRender;
}
@@ -56,14 +51,12 @@ function getViewFailPage($sMessage)
* @param $fDocumentID -> a valid document ID
*/
function getNewThreadOption($fDocumentID) {
- global $default;
-
- $sToRender .= "Would you like to create a new Discussion thread for this document?";
- $sToRender .= " ";
- $sToRender .= "graphicsUrl/widgets/new.gif\" border=\"0\">";
- $sToRender .= "graphicsUrl/widgets/cancel.gif\" border=\"0\">";
-
- return $sToRender;
+ global $default;
+ $sToRender .= "Would you like to create a new Discussion thread for this document?";
+ $sToRender .= " ";
+ $sToRender .= "graphicsUrl/widgets/new.gif\" border=\"0\">";
+ $sToRender .= "graphicsUrl/widgets/cancel.gif\" border=\"0\">";
+ return $sToRender;
}
/**
@@ -74,9 +67,8 @@ function getNewThreadOption($fDocumentID) {
* @param $iNum -> its the iterative index of the current comment
* @param $iThread -> a valid Thread Object
* @param $oComment -> a valid Comment Object
- * @param $oUser -> a valid User Object (Logged in user)
*/
-function getViewComment($iNum,$oThread,$oComment,$oUser) {
+function getViewComment($iNum, $oThread, $oComment, $sIndent) {
global $default;
$iSubjectChars = 59;
@@ -84,85 +76,90 @@ function getViewComment($iNum,$oThread,$oComment,$oUser) {
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 .= displayDocumentPath($oThread->getDocumentID());
- $sToRender .= "
";
-
- return $sToRender;
+ $iCount = 0;
+ // for each thread, retrieve all comments
+ for ($i=0; $igetID(), -1);
+ // now loop through the comments, and indent comments that have the same reply_to at the same level .... ??
+ for ($j=0; $jlog->info("commentTree[$j][comment]=" . $aCommentTree[$j]["comment"]);
+ $sToRender .= getViewComment($iCount++, $aDocumentThreads[$i], $aCommentTree[$j]["comment"], getIndent($aCommentTree[$j]["level"]));
+ }
+ }
+ }
+ $sToRender .= "\n
\n\n";
+ return $sToRender;
+}
+/**
+ * Returns the comments for a particular thread
+ */
+function getCommentTree($iThreadID, $iReplyTo, $iLevel = 0) {
+ global $default;
+ // find all comments for the specified thread and reply
+ $aComments = DiscussionComment::getList("thread_id = $iThreadID AND in_reply_to = $iReplyTo ORDER BY id");
+ // loop through these and find their children
+ for ($i=0; $i $aComments[$i], "level" => $iLevel);
+ $aChildren = getCommentTree($iThreadID, $aComments[$i]->getID(), $iLevel+1);
+ if (count($aChildren) > 0) {
+ $aTree = array_merge($aTree, $aChildren);
+ }
+ }
+ $default->log->debug("getCommentTree($iThreadID, $iReplyTo, $iLevel), returning " . arrayToString($aTree));
+ return $aTree;
}
+/**
+ * Returns an indent string of appropriate length for the specified comment level
+ */
+function getIndent($iLevel) {
+ global $default;
+ $sToRender = "";
+ for ($i=0; $i<$iLevel; $i++) {
+ $sToRender .= " ";
+ }
+ $default->log->info("indent($iLevel) = " . $sToRender);
+ return $sToRender;
+}
?>
\ No newline at end of file