Commit 92caa7e09d50c05f845923630f391e0b38bac042

Authored by Michael Joseph
1 parent ed2aa1f9

(#2977) corrected session checking and redirect to list page instead of bogus success page


git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@2698 c91229c3-7414-0410-bfa2-8a42b809f60b
presentation/lookAndFeel/knowledgeTree/discussions/addCommentBL.php
@@ -26,132 +26,127 @@ @@ -26,132 +26,127 @@
26 */ 26 */
27 27
28 require_once("../../../../config/dmsDefaults.php"); 28 require_once("../../../../config/dmsDefaults.php");
29 -  
30 -if (checkSession()) {  
31 -  
32 - require_once("$default->fileSystemRoot/lib/visualpatterns/PatternCreate.inc");  
33 - require_once("$default->fileSystemRoot/lib/visualpatterns/PatternMainPage.inc");  
34 - require_once("addCommentUI.inc"); //###  
35 - require_once("$default->fileSystemRoot/presentation/lookAndFeel/knowledgeTree/foldermanagement/folderUI.inc");  
36 - require_once("$default->fileSystemRoot/lib/documentmanagement/Document.inc");  
37 - require_once("$default->fileSystemRoot/lib/foldermanagement/Folder.inc");  
38 - require_once("$default->fileSystemRoot/lib/users/User.inc");  
39 - require_once("$default->fileSystemRoot/lib/security/Permission.inc");  
40 - require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc");  
41 - require_once("$default->fileSystemRoot/lib/visualpatterns/PatternCustom.inc");  
42 - require_once("$default->fileSystemRoot/lib/discussions/DiscussionThread.inc"); //###  
43 - require_once("$default->fileSystemRoot/lib/discussions/DiscussionComment.inc"); //###  
44 - require_once("$default->fileSystemRoot/presentation/Html.inc");  
45 -  
46 - $oPatternCustom = & new PatternCustom(); 29 +require_once("$default->fileSystemRoot/lib/visualpatterns/PatternCreate.inc");
  30 +require_once("$default->fileSystemRoot/lib/visualpatterns/PatternMainPage.inc");
  31 +require_once("addCommentUI.inc"); //###
  32 +require_once("$default->fileSystemRoot/presentation/lookAndFeel/knowledgeTree/foldermanagement/folderUI.inc");
  33 +require_once("$default->fileSystemRoot/lib/documentmanagement/Document.inc");
  34 +require_once("$default->fileSystemRoot/lib/foldermanagement/Folder.inc");
  35 +require_once("$default->fileSystemRoot/lib/users/User.inc");
  36 +require_once("$default->fileSystemRoot/lib/security/Permission.inc");
  37 +require_once("$default->fileSystemRoot/lib/visualpatterns/PatternCustom.inc");
  38 +require_once("$default->fileSystemRoot/lib/discussions/DiscussionThread.inc"); //###
  39 +require_once("$default->fileSystemRoot/lib/discussions/DiscussionComment.inc"); //###
  40 +require_once("$default->fileSystemRoot/presentation/Html.inc");
47 41
48 - if(checkSession()) {  
49 - if (isset($fAddComment)) { // User wishes to add a comment  
50 - if ($fDocumentID > 0) { // The document ID is positive  
51 - $main->setFormAction($_SERVER['PHP_SELF'] . "?fAddCommentSubmit=1&iDocumentID=$fDocumentID");  
52 - $oPatternCustom->setHtml(getAddComment($fDocumentID,$sSubject,$sBody, $fCommentID, 1));  
53 - }  
54 - else { // And invalid Document ID was sent  
55 - $main->setErrorMessage("The Document id cannot be lss than 0. ID is invalid.");  
56 - } 42 +if(checkSession()) {
  43 + $oPatternCustom = & new PatternCustom();
  44 + require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc");
  45 + if (isset($fAddComment)) { // User wishes to add a comment
  46 + if ($fDocumentID > 0) { // The document ID is positive
  47 + $main->setFormAction($_SERVER['PHP_SELF'] . "?fAddCommentSubmit=1&iDocumentID=$fDocumentID");
  48 + $oPatternCustom->setHtml(getAddComment($fDocumentID,$sSubject,$sBody, $fCommentID, 1));
  49 + }
  50 + else { // And invalid Document ID was sent
  51 + $main->setErrorMessage("The Document id cannot be lss than 0. ID is invalid.");
  52 + }
  53 +
  54 + } else if (isset($fViewComment)){ // User wishes to view a comment
  55 +
  56 + if (isset($iCommentID)) {
  57 + $oComment = DiscussionComment::get($iCommentID);
  58 + $oUser = User::get($oComment->getUserID());
  59 +
  60 + $oPatternCustom->setHtml(getCommentBody($oComment->getBody(), $oComment->getSubject(),$oComment->getDate(),$iDocumentID,$oUser->getUserName())) ;
  61 + }
  62 +
  63 + } else if (isset($fAddCommentSubmit)) {
  64 + if ($_POST["NewComment"] != "" && $_POST["NewCommentSubject"] != "") {
57 65
58 - } else if (isset($fViewComment)){ // User wishes to view a comment  
59 -  
60 - if (isset($iCommentID)) {  
61 - $oComment = DiscussionComment::get($iCommentID);  
62 - $oUser = User::get($oComment->getUserID());  
63 -  
64 - $oPatternCustom->setHtml(getCommentBody($oComment->getBody(), $oComment->getSubject(),$oComment->getDate(),$iDocumentID,$oUser->getUserName())) ; 66 + if (isset($fNewThread)){ // Create a New Thread for this document as it doesn't exist
  67 +
  68 + // Create the thread Object
  69 + $oThread = & new DiscussionThread(-1,$iDocumentID, $_SESSION["userID"]);
  70 + $oThread->create();
  71 + $iThreadID = $oThread->getID();
65 } 72 }
66 -  
67 - } else if (isset($fAddCommentSubmit)) {  
68 - if ($_POST["NewComment"] != "" && $_POST["NewCommentSubject"] != "") {  
69 -  
70 - if (isset($fNewThread)){ // Create a New Thread for this document as it doesn't exist  
71 -  
72 - // Create the thread Object  
73 - $oThread = & new DiscussionThread(-1,$iDocumentID, $_SESSION["userID"]);  
74 - $oThread->create();  
75 - $iThreadID = $oThread->getID();  
76 - }  
77 - else { // Update the existing thread  
78 - $iThreadID = DiscussionThread::getThreadIDforDoc($iDocumentID);  
79 - }  
80 -  
81 - if ($iThreadID > 0){  
82 - // Create the new comment  
83 - $oComment = & new DiscussionComment(urlencode($_POST["NewComment"]),$_POST["NewCommentSubject"],$_SESSION["userID"],$iDocumentID);  
84 - $oComment->setThreadID($iThreadID);  
85 - $oComment->create(); 73 + else { // Update the existing thread
  74 + $iThreadID = DiscussionThread::getThreadIDforDoc($iDocumentID);
  75 + }
  76 +
  77 + if ($iThreadID > 0){
  78 + // Create the new comment
  79 + $oComment = & new DiscussionComment(urlencode($_POST["NewComment"]),$_POST["NewCommentSubject"],$_SESSION["userID"],$iDocumentID);
  80 + $oComment->setThreadID($iThreadID);
  81 + $oComment->create();
  82 +
  83 + if($oComment->getID() > 0) {
86 84
87 - if($oComment->getID() > 0) { 85 + $oThread = DiscussionThread::get($iThreadID);
  86 + $oThread->setLastCommentID($oComment->getID());
  87 + if ($oThread->getFirstCommentID() == -1){ // if it is a new Thread
88 88
89 - $oThread = DiscussionThread::get($iThreadID);  
90 - $oThread->setLastCommentID($oComment->getID());  
91 - if ($oThread->getFirstCommentID() == -1){ // if it is a new Thread  
92 -  
93 - $oThread->setFirstCommentID($oComment->getID());  
94 - }  
95 - if($_SESSION['Discussion' . $iDocumentID][0]->bViews != true ){ // Session variable is set to true if user views the thread  
96 -  
97 - $oThread->setNumberOfViews();  
98 - $_SESSION['Discussion' . $iDocumentID][0]->bViews = true;  
99 - }  
100 - $oThread->setNumberOfReplies(); 89 + $oThread->setFirstCommentID($oComment->getID());
  90 + }
  91 + if($_SESSION['Discussion' . $iDocumentID][0]->bViews != true ){ // Session variable is set to true if user views the thread
101 92
102 - if ($oThread->Update()) { //  
103 -  
104 - $oPatternCustom->addHtml(getSubmitSuccessPage($iDocumentID));  
105 - }else {  
106 - $main->setErrorMessage("Thread Object failed to update");  
107 - } 93 + $oThread->setNumberOfViews();
  94 + $_SESSION['Discussion' . $iDocumentID][0]->bViews = true;
  95 + }
  96 + $oThread->setNumberOfReplies();
108 97
  98 + if ($oThread->Update()) { //
  99 + controllerRedirect("viewDiscussion", "fForDiscussion=1&fDocumentID=$iDocumentID");
  100 + //$oPatternCustom->addHtml(getSubmitSuccessPage($iDocumentID));
109 }else { 101 }else {
110 - $main->setErrorMessage("Comment Object failed in creation"); 102 + $main->setErrorMessage("Thread Object failed to update");
111 } 103 }
112 -  
113 - }else{ // There is no thread id for this document  
114 - $main->setErrorMessage("No threadID($iThreadID) exists for this document");  
115 - }// End Of if for THREAD ID test 104 +
  105 + }else {
  106 + $main->setErrorMessage("Comment Object failed in creation");
  107 + }
116 108
117 - }else { // the user has not entered BOTH a subject and a text body  
118 - $main->setErrorMessage("The subject line and/or body should not be empty.");  
119 - $main->setFormAction($_SERVER['PHP_SELF'] . "?fAddCommentSubmit=1&iDocumentID=$fDocumentID");  
120 - $oPatternCustom->addHtml(getAddComment($fDocumentID,$_POST["NewCommentSubject"],$_POST["NewComment"], $fCommentID, 1));  
121 - } // end of IF for Subject and Body test  
122 -  
123 - } else if (isset($fReplyComment)){ // if user is replying to existing comment 109 + }else{ // There is no thread id for this document
  110 + $main->setErrorMessage("No threadID($iThreadID) exists for this document");
  111 + }// End Of if for THREAD ID test
  112 +
  113 + }else { // the user has not entered BOTH a subject and a text body
  114 + $main->setErrorMessage("The subject line and/or body should not be empty.");
124 $main->setFormAction($_SERVER['PHP_SELF'] . "?fAddCommentSubmit=1&iDocumentID=$fDocumentID"); 115 $main->setFormAction($_SERVER['PHP_SELF'] . "?fAddCommentSubmit=1&iDocumentID=$fDocumentID");
  116 + $oPatternCustom->addHtml(getAddComment($fDocumentID,$_POST["NewCommentSubject"],$_POST["NewComment"], $fCommentID, 1));
  117 + } // end of IF for Subject and Body test
125 118
126 - $oComment = DiscussionComment::get($fCommentID);  
127 - $oUser = User::get($oComment->getUserID());  
128 -  
129 - $sReplyBody = $oComment->getBody();  
130 -  
131 - $sReplyBodyHeader .= "\n\n\n\n\n\n\n>------ Original Message ------";  
132 - $sReplyBodyHeader .= "\n>User: " . $oUser->getName();  
133 - $sReplyBodyHeader .= "\n>Date: " . $oComment->getDate();  
134 - $sReplyBodyHeader .= "\n>Subject: " . $oComment->getSubject();  
135 - $sReplyBodyHeader .= "\n>---------------------------------------";  
136 -  
137 - $sReplyBody = $sReplyBodyHeader . "\n>" . str_replace("%0D%0A" ,"%0D%0A>", $sReplyBody); // Put in ">" as indentation for the reply  
138 -  
139 - if (strpos($oComment->getSubject(), "Re:") != " "){  
140 - $sReply = "Re: ";  
141 - }else { $sReply = ""; }  
142 -  
143 - $oPatternCustom->addHtml(getAddComment($fDocumentID, $sReply . $oComment->getSubject() , urldecode($sReplyBody), $fCommentID, "-1" ));  
144 -  
145 - } else if (isset($fNewThread)){ // Start adding a new Thread  
146 - $main->setFormAction($_SERVER['PHP_SELF'] . "?fAddCommentSubmit=1&iDocumentID=$fDocumentID&fNewThread=1");  
147 - $oPatternCustom->addHtml(getAddComment($fDocumentID, $CommentSubject , $Comment, $fCommentID, "1"));  
148 -  
149 - } else { // If no discussion exists  
150 - $main->setErrorMessage("Error: No discussion thread available");  
151 - }  
152 - } // end of if checksession  
153 -  
154 - $main->setCentralPayload($oPatternCustom);  
155 - $main->render();  
156 -}  
157 -?> 119 + } else if (isset($fReplyComment)){ // if user is replying to existing comment
  120 + $main->setFormAction($_SERVER['PHP_SELF'] . "?fAddCommentSubmit=1&iDocumentID=$fDocumentID");
  121 +
  122 + $oComment = DiscussionComment::get($fCommentID);
  123 + $oUser = User::get($oComment->getUserID());
  124 +
  125 + $sReplyBody = $oComment->getBody();
  126 +
  127 + $sReplyBodyHeader .= "\n\n>------ Original Message ------";
  128 + $sReplyBodyHeader .= "\n>User: " . $oUser->getName();
  129 + $sReplyBodyHeader .= "\n>Date: " . $oComment->getDate();
  130 + $sReplyBodyHeader .= "\n>Subject: " . $oComment->getSubject();
  131 + $sReplyBodyHeader .= "\n>---------------------------------------";
  132 +
  133 + $sReplyBody = $sReplyBodyHeader . "\n>" . str_replace("%0D%0A" ,"%0D%0A>", $sReplyBody); // Put in ">" as indentation for the reply
  134 +
  135 + if (strpos($oComment->getSubject(), "Re:") != " "){
  136 + $sReply = "Re: ";
  137 + }else { $sReply = ""; }
  138 +
  139 + $oPatternCustom->addHtml(getAddComment($fDocumentID, $sReply . $oComment->getSubject() , urldecode($sReplyBody), $fCommentID, "-1" ));
  140 +
  141 + } else if (isset($fNewThread)){ // Start adding a new Thread
  142 + $main->setFormAction($_SERVER['PHP_SELF'] . "?fAddCommentSubmit=1&iDocumentID=$fDocumentID&fNewThread=1");
  143 + $oPatternCustom->addHtml(getAddComment($fDocumentID, $CommentSubject , $Comment, $fCommentID, "1"));
  144 +
  145 + } else { // If no discussion exists
  146 + $main->setErrorMessage("Error: No discussion thread available");
  147 + }
  148 +
  149 + $main->setCentralPayload($oPatternCustom);
  150 + $main->render();
  151 +} // end of if checksession
  152 +?>
158 \ No newline at end of file 153 \ No newline at end of file