Commit c11f9074b96d45f98e8a02a0230f79175ec72449
1 parent
72821696
#3497 changes to support listing comments by thread and indenting appropriately
git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@2801 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
4 changed files
with
199 additions
and
220 deletions
presentation/lookAndFeel/knowledgeTree/discussions/addCommentBL.php
| ... | ... | @@ -43,105 +43,98 @@ require_once("$default->fileSystemRoot/presentation/Html.inc"); |
| 43 | 43 | if(checkSession()) { |
| 44 | 44 | $oPatternCustom = & new PatternCustom(); |
| 45 | 45 | require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc"); |
| 46 | - if (isset($fAddComment)) { // User wishes to add a comment | |
| 47 | - if ($fDocumentID > 0) { // The document ID is positive | |
| 46 | + // input validation | |
| 47 | + if (isset($fAddComment)) { | |
| 48 | + if (isset($fDocumentID)) { | |
| 48 | 49 | $main->setFormAction($_SERVER['PHP_SELF'] . "?fAddCommentSubmit=1&iDocumentID=$fDocumentID"); |
| 49 | 50 | $oPatternCustom->setHtml(getAddComment($fDocumentID,$sSubject,$sBody, $fCommentID, 1)); |
| 51 | + } else { | |
| 52 | + $main->setErrorMessage("You did not specify a document to add a comment to."); | |
| 50 | 53 | } |
| 51 | - else { // And invalid Document ID was sent | |
| 52 | - $main->setErrorMessage("The Document id cannot be lss than 0. ID is invalid."); | |
| 53 | - } | |
| 54 | - | |
| 55 | - } else if (isset($fViewComment)){ // User wishes to view a comment | |
| 56 | - | |
| 54 | + // User wishes to view a comment | |
| 55 | + } else if (isset($fViewComment)) { | |
| 57 | 56 | if (isset($iCommentID)) { |
| 58 | 57 | $oComment = DiscussionComment::get($iCommentID); |
| 59 | 58 | $oUser = User::get($oComment->getUserID()); |
| 60 | - | |
| 61 | - $oPatternCustom->setHtml(getCommentBody($oComment->getBody(), $oComment->getSubject(),$oComment->getDate(),$iDocumentID,$oUser->getUserName())) ; | |
| 59 | + $oPatternCustom->setHtml(getCommentBody($oComment->getBody(), $oComment->getSubject(), $oComment->getDate(), $iDocumentID,$oUser->getUserName())) ; | |
| 62 | 60 | } |
| 63 | - | |
| 64 | - } else if (isset($fAddCommentSubmit)) { | |
| 65 | - if ($_POST["NewComment"] != "" && $_POST["NewCommentSubject"] != "") { | |
| 66 | - | |
| 67 | - if (isset($fNewThread)){ // Create a New Thread for this document as it doesn't exist | |
| 68 | - | |
| 69 | - // Create the thread Object | |
| 70 | - $oThread = & new DiscussionThread(-1,$iDocumentID, $_SESSION["userID"]); | |
| 71 | - $oThread->create(); | |
| 72 | - $iThreadID = $oThread->getID(); | |
| 73 | - } | |
| 74 | - else { // Update the existing thread | |
| 75 | - $iThreadID = DiscussionThread::getThreadIDforDoc($iDocumentID); | |
| 76 | - } | |
| 77 | - | |
| 78 | - if ($iThreadID > 0){ | |
| 79 | - // Create the new comment | |
| 80 | - $oComment = & new DiscussionComment($_POST["NewComment"], $_POST["NewCommentSubject"],$_SESSION["userID"],$iDocumentID); | |
| 81 | - $oComment->setThreadID($iThreadID); | |
| 82 | - $oComment->create(); | |
| 83 | - | |
| 84 | - if($oComment->getID() > 0) { | |
| 85 | - | |
| 86 | - $oThread = DiscussionThread::get($iThreadID); | |
| 87 | - $oThread->setLastCommentID($oComment->getID()); | |
| 88 | - if ($oThread->getFirstCommentID() == -1){ // if it is a new Thread | |
| 89 | - | |
| 90 | - $oThread->setFirstCommentID($oComment->getID()); | |
| 91 | - } | |
| 92 | - if($_SESSION['Discussion' . $iDocumentID][0]->bViews != true ){ // Session variable is set to true if user views the thread | |
| 93 | - | |
| 94 | - $oThread->setNumberOfViews(); | |
| 95 | - $_SESSION['Discussion' . $iDocumentID][0]->bViews = true; | |
| 96 | - } | |
| 97 | - $oThread->setNumberOfReplies(); | |
| 98 | - | |
| 99 | - if ($oThread->Update()) { // | |
| 100 | - controllerRedirect("viewDiscussion", "fForDiscussion=1&fDocumentID=$iDocumentID"); | |
| 101 | - //$oPatternCustom->addHtml(getSubmitSuccessPage($iDocumentID)); | |
| 102 | - }else { | |
| 103 | - $main->setErrorMessage("Thread Object failed to update"); | |
| 104 | - } | |
| 61 | + } else if (isset($fAddCommentSubmit)) { | |
| 62 | + $default->log->info("adding comment: subject=$fSubject; comment=$fComment"); | |
| 63 | + if ( (strlen($fSubject) > 0) && (strlen($fComment) > 0) ) { | |
| 64 | + // create a new thread, unless we're replying | |
| 65 | + if (isset($fNewComment)) { | |
| 66 | + $oThread = & new DiscussionThread(-1, $iDocumentID, $_SESSION["userID"]); | |
| 67 | + $oThread->create(); | |
| 68 | + $iThreadID = $oThread->getID(); | |
| 69 | + // if this is a new thread, then set inReplyTo to -1 | |
| 70 | + $fInReplyTo = -1; | |
| 71 | + } else { | |
| 72 | + // retrieve the thread id | |
| 73 | + $iThreadID = DiscussionThread::getThreadIDforDoc($fDocumentID); | |
| 74 | + } | |
| 75 | + if ($iThreadID) { | |
| 76 | + $default->log->info("addComment fInReplyTo=$fInReplyTo"); | |
| 77 | + // Create the new comment | |
| 78 | + $oComment = & new DiscussionComment($fComment, $fSubject, $_SESSION["userID"], $iThreadID, $fInReplyTo); | |
| 79 | + $oComment->setThreadID($iThreadID); | |
| 80 | + $oComment->create(); | |
| 81 | + | |
| 82 | + if($oComment->getID() > 0) { | |
| 83 | + $oThread = DiscussionThread::get($iThreadID); | |
| 84 | + $oThread->setLastCommentID($oComment->getID()); | |
| 85 | + if ($oThread->getFirstCommentID() == -1){ // if it is a new Thread | |
| 86 | + $oThread->setFirstCommentID($oComment->getID()); | |
| 87 | + } | |
| 88 | + // Session variable is set to true if user views the thread | |
| 89 | + if ($_SESSION['Discussion' . $iDocumentID][0]->bViews != true ){ | |
| 90 | + $oThread->incrementNumberOfViews(); | |
| 91 | + $_SESSION['Discussion' . $iDocumentID][0]->bViews = true; | |
| 92 | + } | |
| 93 | + $oThread->incrementNumberOfReplies(); | |
| 105 | 94 | |
| 106 | - }else { | |
| 107 | - $main->setErrorMessage("Comment Object failed in creation"); | |
| 95 | + if ($oThread->Update()) { // | |
| 96 | + controllerRedirect("viewDiscussion", "fForDiscussion=1&fDocumentID=$iDocumentID"); | |
| 97 | + //$oPatternCustom->addHtml(getSubmitSuccessPage($iDocumentID)); | |
| 98 | + } else { | |
| 99 | + $main->setErrorMessage("Thread Object failed to update"); | |
| 108 | 100 | } |
| 109 | - | |
| 110 | - }else{ // There is no thread id for this document | |
| 111 | - $main->setErrorMessage("No threadID($iThreadID) exists for this document"); | |
| 112 | - }// End Of if for THREAD ID test | |
| 113 | - | |
| 114 | - }else { // the user has not entered BOTH a subject and a text body | |
| 101 | + } else { | |
| 102 | + $main->setErrorMessage("Comment Object failed in creation"); | |
| 103 | + } | |
| 104 | + } else { | |
| 105 | + $main->setErrorMessage("Could not create a new discussion thread."); | |
| 106 | + } | |
| 107 | + } else { // the user has not entered BOTH a subject and a text body | |
| 115 | 108 | $main->setErrorMessage("The subject line and/or body should not be empty."); |
| 116 | 109 | $main->setFormAction($_SERVER['PHP_SELF'] . "?fAddCommentSubmit=1&iDocumentID=$fDocumentID"); |
| 117 | - $oPatternCustom->addHtml(getAddComment($fDocumentID,$_POST["NewCommentSubject"],$_POST["NewComment"], $fCommentID, 1)); | |
| 110 | + $oPatternCustom->addHtml(getAddComment($fDocumentID, $fSubject, $fComment, $fCommentID, 1)); | |
| 118 | 111 | } // end of IF for Subject and Body test |
| 119 | - | |
| 120 | 112 | } else if (isset($fReplyComment)){ // if user is replying to existing comment |
| 121 | 113 | $main->setFormAction($_SERVER['PHP_SELF'] . "?fAddCommentSubmit=1&iDocumentID=$fDocumentID"); |
| 122 | 114 | |
| 123 | 115 | $oComment = DiscussionComment::get($fCommentID); |
| 124 | 116 | $oUser = User::get($oComment->getUserID()); |
| 125 | 117 | |
| 126 | - $sReplyBody = $oComment->getBody(); | |
| 127 | - | |
| 128 | - $sReplyBodyHeader .= "\n\n>------ Original Message ------"; | |
| 129 | - $sReplyBodyHeader .= "\n>User: " . $oUser->getName(); | |
| 130 | - $sReplyBodyHeader .= "\n>Date: " . $oComment->getDate(); | |
| 131 | - $sReplyBodyHeader .= "\n>Subject: " . $oComment->getSubject(); | |
| 132 | - $sReplyBodyHeader .= "\n>---------------------------------------"; | |
| 118 | + $sReplyBody = $oComment->getBody(); | |
| 133 | 119 | |
| 134 | - $sReplyBody = $sReplyBodyHeader . "\n>" . str_replace("%0D%0A" ,"%0D%0A>", $sReplyBody); // Put in ">" as indentation for the reply | |
| 120 | + $sReplyBodyHeader .= "\n\n> ------ Original Message ------"; | |
| 121 | + $sReplyBodyHeader .= "\n> User: " . $oUser->getName(); | |
| 122 | + $sReplyBodyHeader .= "\n> Date: " . $oComment->getDate(); | |
| 123 | + $sReplyBodyHeader .= "\n> Subject: " . $oComment->getSubject(); | |
| 124 | + $sReplyBodyHeader .= "\n> ---------------------------------------"; | |
| 125 | + $default->log->info("replyBody before=$sReplyBody; replyBodyAfter=" . str_replace("%0D%0A" ,"%0D%0A>", $sReplyBody)); | |
| 126 | + $sReplyBody = $sReplyBodyHeader . "\n>" . str_replace(">" ,"> >", $sReplyBody); // Put in ">" as indentation for the reply | |
| 127 | + //$sReplyBody = $sReplyBodyHeader . "\n>" . str_replace("%0D%0A" ,"%0D%0A>", $sReplyBody); // Put in ">" as indentation for the reply | |
| 135 | 128 | |
| 136 | 129 | if (strpos($oComment->getSubject(), "Re:") != " "){ |
| 137 | 130 | $sReply = "Re: "; |
| 138 | - }else { $sReply = ""; } | |
| 131 | + } else { $sReply = ""; } | |
| 139 | 132 | |
| 140 | 133 | $oPatternCustom->addHtml(getAddComment($fDocumentID, $sReply . $oComment->getSubject() , urldecode($sReplyBody), $fCommentID, "-1" )); |
| 141 | 134 | |
| 142 | 135 | } else if (isset($fNewThread)){ // Start adding a new Thread |
| 143 | 136 | $main->setFormAction($_SERVER['PHP_SELF'] . "?fAddCommentSubmit=1&iDocumentID=$fDocumentID&fNewThread=1"); |
| 144 | - $oPatternCustom->addHtml(getAddComment($fDocumentID, $CommentSubject , $Comment, $fCommentID, "1")); | |
| 137 | + $oPatternCustom->addHtml(getAddComment($fDocumentID, $CommentSubject ,$Comment, $fCommentID, "1")); | |
| 145 | 138 | |
| 146 | 139 | } else { // If no discussion exists |
| 147 | 140 | $main->setErrorMessage("Error: No discussion thread available"); | ... | ... |
presentation/lookAndFeel/knowledgeTree/discussions/addCommentUI.inc
| ... | ... | @@ -48,7 +48,7 @@ function getSubmitSuccessPage($iDocumentID){ |
| 48 | 48 | function getAddComment($fDocumentID, $sSubject, $sBody, $iCommentID, $fNewComment = null) { |
| 49 | 49 | global $default; |
| 50 | 50 | |
| 51 | - $sHeading = "Add a Comment"; | |
| 51 | + $sHeading = "Add a Comment"; | |
| 52 | 52 | $sToRender .= renderHeading($sHeading); |
| 53 | 53 | $sToRender .= displayDocumentPath($fDocumentID); |
| 54 | 54 | $sToRender .= "<table width=\"100%\" border=\"0\" cellpadding=0 ><tr><td></td>\n"; |
| ... | ... | @@ -56,14 +56,16 @@ function getAddComment($fDocumentID, $sSubject, $sBody, $iCommentID, $fNewCommen |
| 56 | 56 | $sToRender .= " "; |
| 57 | 57 | $sToRender .= " "; |
| 58 | 58 | $sToRender .= "<input onmouseover=\"this.style.cursor='hand'\" type=\"image\" src=\"$default->graphicsUrl/widgets/submit.gif\" border=0></td>"; |
| 59 | - if($fNewComment>0){ // If user is creating a new comment | |
| 59 | + if ($fNewComment>0) { // If user is creating a new comment | |
| 60 | 60 | $sToRender .= "<td width=\"10\" valign=top><a href=\"" . generateControllerLink("viewDiscussion", "fForDiscussion=1&fDocumentID=$fDocumentID") . "\"><img src=\"$default->graphicsUrl/widgets/cancel.gif\" border=0 ></a></td></tr>\n"; |
| 61 | - }else { // If the user is replying to a comment | |
| 62 | - $sToRender .= "<td width=\"10\" valign=top><a href=\"" . generateControllerLink("viewDiscussion", "fViewComment=1&iDocumentID=$fDocumentID&iCommentID=$iCommentID") . "\"><img src=\"$default->graphicsUrl/widgets/cancel.gif\" border=0 ></a></td></tr>\n"; | |
| 61 | + $sToRender .= "<input type=\"hidden\" name=\"fNewComment\" value=\"1\"/>"; | |
| 62 | + } else { // If the user is replying to a comment | |
| 63 | + $sToRender .= "<input type=\"hidden\" name=\"fInReplyTo\" value=\"$iCommentID\"/>"; | |
| 64 | + $sToRender .= "<td width=\"10\" valign=top><a href=\"" . generateControllerLink("viewComment", "fViewComment=1&iDocumentID=$fDocumentID&iCommentID=$iCommentID") . "\"><img src=\"$default->graphicsUrl/widgets/cancel.gif\" border=0 ></a></td></tr>\n"; | |
| 63 | 65 | } |
| 64 | 66 | $sToRender .= "<br><tr><td valign=\"top\" width=10><b>Subject</b></td><td colspan=2>\n"; |
| 65 | - $sToRender .= "<input type=\"text\" style=\"width:385\" name=\"NewCommentSubject\" id=\"NewCommentSubject\" value=\"$sSubject\"></td></tr>\n"; | |
| 66 | - $sToRender .= "<tr><td valign=\"top\"><b>Body</b></td><td colspan=2><textarea cols=60 rows=\"21\" name=\"NewComment\" id=\"NewComment\" wrap=\"physical\" >$sBody</textarea></td></tr></table>\n"; | |
| 67 | + $sToRender .= "<input type=\"text\" style=\"width:385\" name=\"fSubject\" value=\"$sSubject\"></td></tr>\n"; | |
| 68 | + $sToRender .= "<tr><td valign=\"top\"><b>Body</b></td><td colspan=2><textarea cols=60 rows=\"18\" name=\"fComment\" wrap=\"physical\">$sBody</textarea></td></tr></table>\n"; | |
| 67 | 69 | return $sToRender; |
| 68 | 70 | } |
| 69 | 71 | ... | ... |
presentation/lookAndFeel/knowledgeTree/discussions/viewDiscussionBL.php
| ... | ... | @@ -44,61 +44,48 @@ if (checkSession()) { |
| 44 | 44 | require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc"); |
| 45 | 45 | $oPatternCustom = & new PatternCustom(); |
| 46 | 46 | if (isset($fForDiscussion)) { |
| 47 | - if ($fDocumentID > 0) { | |
| 48 | - $iThreadID = DiscussionThread::getThreadIDforDoc($fDocumentID); | |
| 49 | - if ($iThreadID) {// if thread ID does exist | |
| 50 | - $oThread = DiscussionThread::get($iThreadID); | |
| 51 | - if($oThread) { // if thread object exists | |
| 52 | - // Iterate through the number of comments | |
| 53 | - $sAllCommentID = $oThread->getAllCommentID(); | |
| 54 | - $arrAllCommentID = explode(",", $sAllCommentID); | |
| 55 | - $iNumMax = $oThread->getNumberOfReplies(); | |
| 56 | - | |
| 57 | - $sQuery = "SELECT 1 as ForView, subject, username, date, discussion_comments.id as com_id, discussion_threads.document_id as doc_id " . | |
| 58 | - "FROM (discussion_comments INNER JOIN users ON discussion_comments.user_id = users.id) " . | |
| 59 | - "INNER JOIN discussion_threads ON discussion_threads.id = discussion_comments.thread_id " . | |
| 60 | - "WHERE discussion_threads.id = " . $iThreadID . | |
| 61 | - " ORDER BY discussion_comments.thread_id ASC"; | |
| 62 | - | |
| 63 | - $aColumns = array("subject", "username", "date"); | |
| 64 | - $aColumnNames = array("<font color=white>Subject </font>", "<font color=white>User</font>", "<font color=white>Date</font>"); | |
| 65 | - $aColumnTypes = array(3,1,1); | |
| 66 | - $aQueryStringVars = array("fViewComment", "iCommentID", "iDocumentID"); | |
| 67 | - $aQueryStringCols = array("ForView", "com_id", "doc_id"); | |
| 68 | - | |
| 69 | - for ($i = 0; $i < $iNumMax; $i++) { | |
| 70 | - $aHyperLinkURL[$i] = $_SERVER['PHP_SELF'] ; | |
| 71 | - } | |
| 72 | - | |
| 73 | - $oSearchResults = & new PatternTableSqlQuery ($sQuery, $aColumns, $aColumnTypes, $aColumnNames, "100%", $aHyperLinkURL, $aQueryStringCols, $aQueryStringVars); | |
| 74 | - $sToRender .= renderHeading("Document Discussion Thread"); | |
| 75 | - $sToRender .= displayDocumentPath($oThread->getDocumentID()); | |
| 76 | - $oPatternCustom->addHtml($sToRender); | |
| 77 | - $oPatternCustom->addHtml(getPageButtons($oThread)); | |
| 78 | - $oPatternCustom->addHtml($oSearchResults->render()); | |
| 47 | + if (isset($fDocumentID)) { | |
| 48 | + $aDocumentThreads = DiscussionThread::getList("document_id=$fDocumentID ORDER BY id"); | |
| 49 | + if (count($aDocumentThreads) > 0) { | |
| 50 | + // call the ui function to display the comments | |
| 51 | + $oPatternCustom->setHtml(getPage($fDocumentID, $aDocumentThreads)); | |
| 79 | 52 | |
| 53 | +// $sQuery = "SELECT 1 as ForView, dc.subject AS subject, username, date, dc.id AS commentID, dt.document_id AS documentID " . | |
| 54 | +// "FROM discussion_comments AS dc " . | |
| 55 | +// "INNER JOIN users AS u ON dc.user_id = u.id " . | |
| 56 | +// "INNER JOIN discussion_threads AS dt ON dt.id = dc.thread_id " . | |
| 57 | +// "WHERE dt.id in ( " . implode(",", $aDocumentThreads) . ") " . | |
| 58 | +// "ORDER BY dc.thread_id, dc.id, date ASC"; | |
| 59 | +// | |
| 60 | +// $aColumns = array("subject", "username", "date"); | |
| 61 | +// $aColumnNames = array("<font color=white>Subject </font>", "<font color=white>User</font>", "<font color=white>Date</font>"); | |
| 62 | +// $aColumnTypes = array(3,1,1); | |
| 63 | +// $aQueryStringVars = array("fViewComment", "iCommentID", "iDocumentID"); | |
| 64 | +// $aQueryStringCols = array("ForView", "commentID", "documentID"); | |
| 65 | +// | |
| 66 | +// for ($i = 0; $i < $iNumMax; $i++) { | |
| 67 | +// $aHyperLinkURL[$i] = $_SERVER['PHP_SELF'] ; | |
| 68 | +// } | |
| 69 | +// | |
| 70 | +// $oSearchResults = & new PatternTableSqlQuery ($sQuery, $aColumns, $aColumnTypes, $aColumnNames, "100%", $aHyperLinkURL, $aQueryStringCols, $aQueryStringVars); | |
| 71 | +// $sToRender .= renderHeading("Document Discussion Thread"); | |
| 72 | +// $sToRender .= displayDocumentPath($fDocumentID); | |
| 73 | +// $oPatternCustom->addHtml($sToRender); | |
| 74 | +// $oPatternCustom->addHtml(getPageButtons($fDocumentID)); | |
| 75 | +// $oPatternCustom->addHtml($oSearchResults->render()); | |
| 76 | +// | |
| 80 | 77 | // On opening, increment the number of views of current thread & update database |
| 81 | - if($_SESSION['Discussion' . $fDocumentID][0]->bViews !=true ){ | |
| 82 | - $oThread->setNumberOfViews(); | |
| 83 | - if($oThread->Update() == false) $oPatternCustom->addHtml("Failed to update. Please Contact Database Administrator in this regard") ; | |
| 84 | - $_SESSION['Discussion' . $fDocumentID][0]->bViews = true; | |
| 85 | - } | |
| 86 | - } else { | |
| 87 | - $main->setErrorMessage("Error creating discussion thread object"); | |
| 88 | - } | |
| 78 | +// if($_SESSION['Discussion' . $fDocumentID][0]->bViews !=true ){ | |
| 79 | +// $oThread->incrementNumberOfViews(); | |
| 80 | +// if($oThread->Update() == false) $oPatternCustom->addHtml("Failed to update. Please Contact Database Administrator in this regard") ; | |
| 81 | +// $_SESSION['Discussion' . $fDocumentID][0]->bViews = true; | |
| 82 | +// } | |
| 89 | 83 | } else { // No current thread, option to create one |
| 90 | 84 | $main->setErrorMessage("No discussion thread is currently available"); |
| 91 | 85 | $oPatternCustom->addHtml(getNewThreadOption($fDocumentID)); |
| 92 | 86 | } |
| 93 | 87 | } else { // Doument id is negative |
| 94 | - $main->setErrorMessage("Invalid Document ID. ID may not be negative."); | |
| 95 | - } | |
| 96 | - } else if (isset($fViewComment)){ // User wants to view a comment | |
| 97 | - if (isset($iCommentID)) { // Check if a comment ID exists | |
| 98 | - $oComment = DiscussionComment::get($iCommentID); | |
| 99 | - $oUser = User::get($oComment->getUserID()); | |
| 100 | - $main->setFormAction("$default->rootUrl/presentation/lookAndFeel/knowledgeTree/discussions/addCommentBL.php?fDocumentID=$iDocumentID&fCommentID=$iCommentID&fReplyComment=1"); | |
| 101 | - $oPatternCustom->setHtml(getCommentBody($oComment,$iDocumentID,$oUser)) ; | |
| 88 | + $main->setErrorMessage("You did not specify a document."); | |
| 102 | 89 | } |
| 103 | 90 | } else { // If no discussion exists |
| 104 | 91 | $main->setErrorMessage("Invalid function. No such functionality exists for this page."); | ... | ... |
presentation/lookAndFeel/knowledgeTree/discussions/viewDiscussionUI.inc
| ... | ... | @@ -25,28 +25,23 @@ |
| 25 | 25 | * @package discussions |
| 26 | 26 | */ |
| 27 | 27 | |
| 28 | -function getPageButtons($oThread){ | |
| 28 | +function getPageButtons($iDocumentID){ | |
| 29 | 29 | global $default; |
| 30 | - | |
| 31 | 30 | $sToRender .= "<table width=100%><tr>\n"; |
| 32 | - $sToRender .= "<td align=right width=100%><a href=\"" . generateControllerLink("addComment", "fDocumentID=" . $oThread->getDocumentID() . "&fAddComment=1&fNewComment=1") . "\"><img src=\"$default->graphicsUrl/widgets/addcomment.gif\" border=\"0\" /></a></td>\n"; | |
| 33 | - $sToRender .= "<td align=right width=10><a href=\"" . generateControllerLink("viewDocument", "fDocumentID=" . $oThread->getDocumentID() . "&fAddComment=1") . "\"><img src=\"$default->graphicsUrl/widgets/back.gif\" border=\"0\" /></a></td>\n"; | |
| 34 | - | |
| 31 | + $sToRender .= "<td align=right width=100%><a href=\"" . generateControllerLink("addComment", "fDocumentID=$iDocumentID&fAddComment=1&fNewComment=1") . "\"><img src=\"$default->graphicsUrl/widgets/addcomment.gif\" border=\"0\" /></a></td>\n"; | |
| 32 | + $sToRender .= "<td align=right width=10><a href=\"" . generateControllerLink("viewDocument", "fDocumentID=$iDocumentID&fAddComment=1") . "\"><img src=\"$default->graphicsUrl/widgets/back.gif\" border=\"0\" /></a></td>\n"; | |
| 35 | 33 | $sToRender .= "</tr></table>\n"; |
| 36 | - | |
| 37 | - return $sToRender ; | |
| 34 | + return $sToRender; | |
| 38 | 35 | } |
| 39 | 36 | |
| 40 | 37 | // If there are no threads to view for a document |
| 41 | -function getViewFailPage($sMessage) | |
| 42 | -{ | |
| 38 | +function getViewFailPage($sMessage) { | |
| 43 | 39 | global $default; |
| 44 | - | |
| 45 | - if (strlen($sMessage)>0){ | |
| 40 | + if ( strlen($sMessage)>0 ) { | |
| 46 | 41 | $sToRender = $sMessage; |
| 42 | + } else { | |
| 43 | + $sToRender = "Current document has no discussion. Press the ADD button to start a discussion."; | |
| 47 | 44 | } |
| 48 | - else $sToRender = "Current document has no discussion. Press the ADD button to start a discussion."; | |
| 49 | - | |
| 50 | 45 | return $sToRender; |
| 51 | 46 | } |
| 52 | 47 | |
| ... | ... | @@ -56,14 +51,12 @@ function getViewFailPage($sMessage) |
| 56 | 51 | * @param $fDocumentID -> a valid document ID |
| 57 | 52 | */ |
| 58 | 53 | function getNewThreadOption($fDocumentID) { |
| 59 | - global $default; | |
| 60 | - | |
| 61 | - $sToRender .= "Would you like to create a new Discussion thread for this document?"; | |
| 62 | - $sToRender .= " "; | |
| 63 | - $sToRender .= "<a href=\"" . generateControllerLink("addComment", "fDocumentID=" . $fDocumentID . "&fNewThread=1") . "\"><img src=\"$default->graphicsUrl/widgets/new.gif\" border=\"0\"></a>"; | |
| 64 | - $sToRender .= "<a href=\"" . generateControllerLink("viewDocument", "fDocumentID=" . $fDocumentID) . "\"><img src=\"$default->graphicsUrl/widgets/cancel.gif\" border=\"0\"></a>"; | |
| 65 | - | |
| 66 | - return $sToRender; | |
| 54 | + global $default; | |
| 55 | + $sToRender .= "Would you like to create a new Discussion thread for this document?"; | |
| 56 | + $sToRender .= " "; | |
| 57 | + $sToRender .= "<a href=\"" . generateControllerLink("addComment", "fDocumentID=" . $fDocumentID . "&fNewThread=1") . "\"><img src=\"$default->graphicsUrl/widgets/new.gif\" border=\"0\"></a>"; | |
| 58 | + $sToRender .= "<a href=\"" . generateControllerLink("viewDocument", "fDocumentID=" . $fDocumentID) . "\"><img src=\"$default->graphicsUrl/widgets/cancel.gif\" border=\"0\"></a>"; | |
| 59 | + return $sToRender; | |
| 67 | 60 | } |
| 68 | 61 | |
| 69 | 62 | /** |
| ... | ... | @@ -74,9 +67,8 @@ function getNewThreadOption($fDocumentID) { |
| 74 | 67 | * @param $iNum -> its the iterative index of the current comment |
| 75 | 68 | * @param $iThread -> a valid Thread Object |
| 76 | 69 | * @param $oComment -> a valid Comment Object |
| 77 | - * @param $oUser -> a valid User Object (Logged in user) | |
| 78 | 70 | */ |
| 79 | -function getViewComment($iNum,$oThread,$oComment,$oUser) { | |
| 71 | +function getViewComment($iNum, $oThread, $oComment, $sIndent) { | |
| 80 | 72 | global $default; |
| 81 | 73 | |
| 82 | 74 | $iSubjectChars = 59; |
| ... | ... | @@ -84,85 +76,90 @@ function getViewComment($iNum,$oThread,$oComment,$oUser) { |
| 84 | 76 | if (($iNum%2) == 1) $BGcolor = "#F5F6EE"; |
| 85 | 77 | if (($iNum%2) == 0) $UserBGcolor = "#F5F6EE"; |
| 86 | 78 | |
| 87 | - // If the Subject string is too long | |
| 88 | - if (strlen($oComment->getSubject())>$iSubjectChars ) $dotdot = " ..."; | |
| 89 | - if (strlen($oUser->getUserName())> 13 ) $Userdotdot = " ..."; | |
| 90 | - | |
| 91 | - // If this is the first Subject line then create a table | |
| 92 | - if ($iNum == 1) { | |
| 93 | - $sHeading = "Document Discussion Comments"; | |
| 94 | - | |
| 95 | - $sToRender .= renderHeading($sHeading ); | |
| 96 | - $sToRender .= displayDocumentPath($oThread->getDocumentID()); | |
| 97 | - $sToRender .= "<table border=0 width=100%><tr>"; | |
| 98 | - $sToRender .= "<td width=100><b>Views: </b> " . $oThread->getNumberOfViews() . "</td>"; | |
| 99 | - $sToRender .= "<td width=20></td>"; | |
| 100 | - $sToRender .= "<td><b>Replies: </b> " . $oThread->getNumberOfReplies() . "</td>"; | |
| 101 | - $sToRender .= "<td align=right><a href=\"" . generateControllerLink("addComment", "fDocumentID=" . $oThread->getDocumentID() . "&fAddComment=1&fCommentID=" . $oComment->getID()) . "\"><img src=\"$default->graphicsUrl/widgets/addcomment.gif\" border=\"0\" /></a>"; | |
| 102 | - $sToRender .= "<img src=\"$default->graphicsUrl/widgets/back.gif\" onmouseover=\"this.style.cursor='hand'\" onclick=\"javascript: history.go(-1);\" ></td>"; | |
| 103 | - $sToRender .= "</tr></table><br>\n"; | |
| 104 | - $sToRender .= "<table border=\"0\" width=\"100%\">\n"; | |
| 105 | - $sToRender .= "<tr><td></td>\n"; | |
| 106 | - $sToRender .= "<td><b>Subject</b></td>\n"; | |
| 107 | - $sToRender .= "<td><b>Author</b></td>\n"; | |
| 108 | - $sToRender .= "<td><b>Date</b></td>\n"; | |
| 109 | - $sToRender .= "</tr>\n"; | |
| 79 | + $sUserName = ""; | |
| 80 | + $oUser = User::get($oComment->getUserID()); | |
| 81 | + if ($oUser) { | |
| 82 | + $sUserName = $oUser->getName(); | |
| 110 | 83 | } |
| 111 | - | |
| 112 | - $sToRender .= "<tr><td>$iNum </td><td style=\"background-color:$BGcolor\" width=450><a style=\"width:94%\" href=\"" . $_SERVER['PHP_SELF'] . "?fViewComment=1&iCommentID=" . $oComment->getID() . "&iDocumentID=" . $oThread->getDocumentID() . "\" title=\"" . $oComment->getSubject() . "\">" . substr($oComment->getSubject(),0,$iSubjectChars ) . $dotdot . "</a></td>\n"; | |
| 113 | - $sToRender .= "<td style=\"background-color:$UserBGcolor\" width=\"100\" title=\"$oUser->getUserName()\">" . substr($oUser->getUserName(),0,10) . $Userdotdot . "</td>\n"; | |
| 114 | - $sToRender .= "<td style=\"background-color:$BGcolor\" width=\"80\">" . $oComment->getDate() . "<td></tr>\n"; | |
| 115 | - | |
| 116 | - // If this is the last subject line then close the table | |
| 117 | - if ($iNum == ($oThread->getNumberOfReplies())) { $sToRender .= "\n</table>\n\n";} | |
| 84 | + // If the Subject string is too long | |
| 85 | + if (strlen($oComment->getSubject())>$iSubjectChars ) $dotdot = " ..."; | |
| 86 | + | |
| 87 | + $sToRender .= "<tr>\n"; | |
| 88 | + $sToRender .= "\t<td style=\"background-color:$BGcolor\" width=450>\n"; | |
| 89 | + $sToRender .= "\t\t$sIndent<a href=\"" . generateControllerLink("viewComment", "iCommentID=" . $oComment->getID() . "&iDocumentID=" . $oThread->getDocumentID()) . "\" title=\"" . $oComment->getSubject() . "\">\n"; | |
| 90 | + $sToRender .= substr($oComment->getSubject(),0,$iSubjectChars ) . $dotdot . "</a></td>\n"; | |
| 91 | + $sToRender .= "\t<td style=\"background-color:$UserBGcolor\" width=\"100\" title=\"$sUserName\">\n"; | |
| 92 | + $sToRender .= "\t\t$sUserName</td>\n"; | |
| 93 | + $sToRender .= "\t<td style=\"background-color:$BGcolor\" width=\"80\">" . $oComment->getDate() . "<td></tr>\n"; | |
| 94 | + | |
| 118 | 95 | return $sToRender; |
| 119 | 96 | } |
| 120 | 97 | |
| 121 | -/** | |
| 122 | - * Views a single thread comment with its text body | |
| 123 | - * | |
| 124 | - * @param $iDocumentID -> a valid Document ID | |
| 125 | - * @param $oComment -> a valid Comment Object | |
| 126 | - * @param $oUser -> a valid User Object (Logged in user) | |
| 98 | +/** | |
| 99 | + * Prints out the list of discussion comments | |
| 127 | 100 | */ |
| 128 | -function getCommentBody($oComment, $iDocumentID, $oUser) { | |
| 101 | +function getPage($iDocumentID, $aDocumentThreads) { | |
| 129 | 102 | global $default; |
| 130 | 103 | |
| 131 | - $sHeading = "Document Comment"; | |
| 132 | - | |
| 133 | - $sToRender .= renderHeading($sHeading); | |
| 134 | - $sToRender .= displayDocumentPath($iDocumentID); | |
| 135 | - $aBody = explode("\n",$oComment->getBody()); | |
| 136 | - $sBody = ""; | |
| 137 | - $numChars = 160; // number of chars in a line | |
| 104 | + $sToRender .= renderHeading("Document Discussion Comments"); | |
| 105 | + $sToRender .= displayDocumentPath($iDocumentID); | |
| 106 | + $sToRender .= "<table border=0 width=100%><tr>"; | |
| 107 | + $sToRender .= "<td align=right>\n"; | |
| 108 | + $sToRender .= "<a href=\"" . generateControllerLink("addComment", "fDocumentID=$iDocumentID") . "\"><img src=\"$default->graphicsUrl/widgets/addcomment.gif\" border=\"0\" /></a>\n"; | |
| 109 | + $sToRender .= "<img src=\"$default->graphicsUrl/widgets/back.gif\" onmouseover=\"this.style.cursor='hand'\" onclick=\"javascript: history.go(-1);\">\n</td>"; | |
| 110 | + $sToRender .= "</tr></table><br>\n"; | |
| 111 | + $sToRender .= "<table border=\"0\" width=\"100%\">\n"; | |
| 112 | + $sToRender .= "<tr>\n"; | |
| 113 | + $sToRender .= "<td><b>Subject</b></td>\n"; | |
| 114 | + $sToRender .= "<td><b>Author</b></td>\n"; | |
| 115 | + $sToRender .= "<td><b>Date</b></td>\n"; | |
| 116 | + $sToRender .= "</tr>\n"; | |
| 138 | 117 | |
| 139 | - // Used for wrapping text that may be too long on one any line | |
| 140 | - for ($i=0; $i <= sizeof($aBody) ;$i++) { | |
| 141 | - if (strlen($aBody[$i]) >$numChars){ | |
| 142 | - $loop = (strlen($aBody[$i]) - (strlen($aBody[$i])) % $numChars)/$numChars +1; | |
| 143 | - | |
| 144 | - $j=$numChars; | |
| 145 | - for($j=0; $j < $loop; $j++ ) { | |
| 146 | - $sBody .= "<br>" . substr($aBody[$i],($j*$numChars), $numChars) . ""; | |
| 147 | - } | |
| 148 | - } else { $sBody .= "<br>" . $aBody[$i]; } | |
| 149 | - } | |
| 150 | - | |
| 151 | - $sToRender .= "<br><table width=100% border=0><tr ><td colspan=2><b>Author: </b>" . $oUser->getUserName() . "</td>\n"; | |
| 152 | - $sToRender .= "<td align=right>\n"; | |
| 153 | - $sToRender .= "<a href=\"" . generateControllerLink("addComment", "fDocumentID=" . $iDocumentID . "&fReplyComment=1&fCommentID=" . $oComment->getID()) . "\"><img src=\"$default->graphicsUrl/widgets/reply.gif\" border=\"0\" /></a>"; | |
| 154 | - $sToRender .= "</td><td width=30><a href=\"" . generateControllerLink("viewDiscussion", "fForDiscussion=1&fDocumentID=$iDocumentID") . "\"><img src=\"$default->graphicsUrl/widgets/back.gif\" border=0 ><a></td></tr>\n"; | |
| 155 | - $sToRender .= "<tr><td width=\"1\" style=\"background-color:#F5F6EE;\" ><b>Subject: </b></td><td width=405 style=\"background-color:#F5F6EE;\">"; | |
| 156 | - $sToRender .= $oComment->getSubject(); | |
| 157 | - $sToRender .= "</td><td colspan=2 nowrap style=\"background-color:#F5F6EE;\"><b>Date: </b><font color=\"#056DCE\">" . $oComment->getDate() . "</font> </td></tr><tr><td colspan=4 valign=top>"; | |
| 158 | - $sToRender .= "<table border=0><tr><td>"; | |
| 159 | - $sToRender .= $sBody; | |
| 160 | - $sToRender .= "</td></tr></table>"; | |
| 161 | - $sToRender .= "</td>\n"; | |
| 162 | - | |
| 163 | - $sToRender .= "</tr></table> "; | |
| 164 | - | |
| 165 | - return $sToRender; | |
| 118 | + $iCount = 0; | |
| 119 | + // for each thread, retrieve all comments | |
| 120 | + for ($i=0; $i<count($aDocumentThreads); $i++) { | |
| 121 | + if ($aDocumentThreads[$i]) { | |
| 122 | + // get comment tree | |
| 123 | + $aCommentTree = getCommentTree($aDocumentThreads[$i]->getID(), -1); | |
| 124 | + // now loop through the comments, and indent comments that have the same reply_to at the same level .... ?? | |
| 125 | + for ($j=0; $j<count($aCommentTree); $j++) { | |
| 126 | + $default->log->info("commentTree[$j][comment]=" . $aCommentTree[$j]["comment"]); | |
| 127 | + $sToRender .= getViewComment($iCount++, $aDocumentThreads[$i], $aCommentTree[$j]["comment"], getIndent($aCommentTree[$j]["level"])); | |
| 128 | + } | |
| 129 | + } | |
| 130 | + } | |
| 131 | + $sToRender .= "\n</table>\n\n"; | |
| 132 | + return $sToRender; | |
| 133 | +} | |
| 134 | +/** | |
| 135 | + * Returns the comments for a particular thread | |
| 136 | + */ | |
| 137 | +function getCommentTree($iThreadID, $iReplyTo, $iLevel = 0) { | |
| 138 | + global $default; | |
| 139 | + // find all comments for the specified thread and reply | |
| 140 | + $aComments = DiscussionComment::getList("thread_id = $iThreadID AND in_reply_to = $iReplyTo ORDER BY id"); | |
| 141 | + // loop through these and find their children | |
| 142 | + for ($i=0; $i<count($aComments); $i++) { | |
| 143 | + $aTree[] = array( "comment" => $aComments[$i], "level" => $iLevel); | |
| 144 | + $aChildren = getCommentTree($iThreadID, $aComments[$i]->getID(), $iLevel+1); | |
| 145 | + if (count($aChildren) > 0) { | |
| 146 | + $aTree = array_merge($aTree, $aChildren); | |
| 147 | + } | |
| 148 | + } | |
| 149 | + $default->log->debug("getCommentTree($iThreadID, $iReplyTo, $iLevel), returning " . arrayToString($aTree)); | |
| 150 | + return $aTree; | |
| 166 | 151 | } |
| 167 | 152 | |
| 153 | +/** | |
| 154 | + * Returns an indent string of appropriate length for the specified comment level | |
| 155 | + */ | |
| 156 | +function getIndent($iLevel) { | |
| 157 | + global $default; | |
| 158 | + $sToRender = ""; | |
| 159 | + for ($i=0; $i<$iLevel; $i++) { | |
| 160 | + $sToRender .= " "; | |
| 161 | + } | |
| 162 | + $default->log->info("indent($iLevel) = " . $sToRender); | |
| 163 | + return $sToRender; | |
| 164 | +} | |
| 168 | 165 | ?> |
| 169 | 166 | \ No newline at end of file | ... | ... |