\n";
// delete message button, for admins
if ($this->canEdit())
{
echo "
";
echo "
\n";
echo "
";
}
echo "
\n";
echo html_frame_end();
}
function display()
{
$this->output_comment();
}
/**
* grab single comment for commentId
*/
function grab_comment($iCommentId)
{
$iCommentId = query_escape_string($iCommentId);
if($iCommentId)
{
$sQuery = "SELECT from_unixtime(unix_timestamp(appComments.time), \"%W %M %D %Y, %k:%i\") as time, ".
"appComments.commentId, appComments.parentId, appComments.versionId, appComments.userId, appComments.subject, appComments.body, appVersion.appId ".
"FROM appComments, appVersion WHERE appComments.commentId = '$iCommentId'";
$hResult = query_appdb($sQuery);
return $hResult;
}
return null;
}
/**
* grab comments for appId / versionId
* if parentId is not -1 only comments for that thread are returned
*/
function grab_comments($iVersionId, $iParentId = null)
{
/* TODO: remove the logging when we figure out where the */
/* invalid $iVersionId is coming */
/* if $iVersionId is invalid we should log where we came from */
/* so we can debug the problem */
if($iVersionId == "")
{
error_log::logBackTrace("logging iVersionId oddity");
return NULL;
}
/* escape input so we can use query_appdb() without concern */
$iVersionId = query_escape_string($iVersionId);
$iParentId = query_escape_string($iParentId);
/* NOTE: we must compare against NULL here because $iParentId of 0 is valid */
if($iParentId)
{
$sExtra = "AND parentId = '".$iParentId."' ";
$sOrderingMode = "ASC";
} else
{
$sExtra = "AND parentId = '0'";
$sOrderingMode = "DESC";
}
$sQuery = "SELECT from_unixtime(unix_timestamp(appComments.time), \"%W %M %D %Y, %k:%i\") as time, ".
"appComments.commentId, appComments.parentId, appComments.versionId, appComments.userId, appComments.subject, appComments.body, appVersion.appId ".
"FROM appComments, appVersion WHERE appComments.versionId = appVersion.versionId AND appComments.versionId = '".$iVersionId."' ".
$sExtra.
"ORDER BY appComments.time $sOrderingMode";
$hResult = query_appdb($sQuery);
return $hResult;
}
/**
* display nested comments
* handle is a db result set
*/
function do_display_comments_nested($hResult)
{
while($oRow = query_fetch_object($hResult))
{
Comment::view_app_comment($oRow);
$hResult2 = Comment::grab_comments($oRow->versionId, $oRow->commentId);
if($hResult && query_num_rows($hResult2))
{
echo "
\n";
}
}
}
function display_comments_nested($versionId, $threadId)
{
$hResult = Comment::grab_comments($versionId, $threadId);
Comment::do_display_comments_nested($hResult);
}
/**
* Generates the link to show the comment.
*/
function comment_link($oRow)
{
$sLink = "commentview.php?iAppId={$oRow->appId}&iVersionId=".
"{$oRow->versionId}&iThreadId={$oRow->parentId}";
$sOnClick = "showComment('{$oRow->commentId}');";
/**
* The return false line in the onClick is used to handle javascript
* being disabled so we can fail gracefully to the old style.
*/
return "
$oRow->subject".
' by '.forum_lookup_user($oRow->userId)." on
{$oRow->time}
commentId}\">
\n";
}
/**
* display threaded comments
* handle is a db result set
*/
function do_display_comments_threaded($hResult, $is_main)
{
if (!$is_main)
echo "
\n";
while ($oRow = query_fetch_object($hResult))
{
if ($is_main)
{
Comment::view_app_comment($oRow);
} else
{
$link = Comment::comment_link($oRow);
echo "$link";
}
$hResult2 = Comment::grab_comments($oRow->versionId, $oRow->commentId);
if ($hResult2 && query_num_rows($hResult2))
{
echo "
\n";
}
function canEdit()
{
if($_SESSION['current']->hasPriv("admin"))
return TRUE;
$oVersion = new version($this->iVersionId);
return $oVersion->canEdit();
}
function objectGetId()
{
return $this->iCommentId;
}
function objectGetSubmitterId()
{
return $this->oOwner->iUserId;
}
function objectGetMailOptions($sAction, $bMailSubmitter, $bParentAction)
{
$oOptions = new mailOptions();
if($sAction == "delete" && $bParentAction)
$oOptions->bMailOnce = TRUE;
return $oOptions;
}
function objectGetMail($sAction, $bMailSubmitter, $bParentAction)
{
$sSubject = "";
$sMessage = "";
$aRecipients = null;
$oVersion = new version($this->iVersionId);
$sVerName = version::fullName($this->iVersionId);
if($bMailSubmitter)
{
switch($sAction)
{
case "delete":
if($bParentAction)
{
$sSubject = "Comments for $sVerName deleted";
$sMessage = "Your comments for $sVerName were deleted because the";
$sMessage .= "version was removed from the database";
} else
{
$sSubject = "Comment for $sVerName deleted";
$sMessage = $oVersion->objectMakeUrl()."\n";
$sMessage .= "\n";
$sMessage .= "This comment was made on ".substr($this->sDateCreated,0,10)."\n";
$sMessage .= "\n";
$sMessage .= "Subject: ".$this->sSubject."\r\n";
$sMessage .= "\n";
$sMessage .= $this->sBody."\r\n";
}
break;
}
} else
{
switch($sAction)
{
case "delete":
if(!$bParentAction)
{
$sSubject = "Comment for $sVerName deleted";
$sMessage = $oVersion->objectMakeUrl()."\n";
$sMessage .= "\n";
$sMessage .= "This comment was made on ".substr($this->sDateCreated,0,10)." by ".$this->oOwner->sRealname."\n";
$sMessage .= "\n";
$sMessage .= "Subject: ".$this->sSubject."\r\n";
$sMessage .= "\n";
$sMessage .= $this->sBody."\r\n";
}
break;
}
$aRecipients = User::get_notify_email_address_list($this->iAppId, $this->iVersionId);
}
return array($sSubject, $sMessage, $aRecipients);
}
public function objectGetParent($sClass = '')
{
switch($sClass)
{
case 'version':
return new version($this->iVersionId);
case 'comment':
return new comment($this->iParentId);
}
}
public function objectSetParent($iNewId, $sClass = '')
{
switch($sClass)
{
case 'version':
$this->iVersionId = $iNewId;
break;
case 'comment':
$this->iParentId = $iNewId;
break;
}
}
function objectGetChildren($bIncludeDeleted = false)
{
$aObjects = array();
$hResult = comment::grab_comments($this->iVersionId, $this->iCommentId);
if(!$hResult)
return $aObjects;
while($oRow = mysql_fetch_object($hResult))
{
$oComment = new comment(null, $oRow);
$aObjects += $oComment->objectGetChildren();
$aObjects[] = $oComment;
}
return $aObjects;
}
function display_comments_threaded($versionId, $threadId = 0)
{
$hResult = Comment::grab_comments($versionId, $threadId);
Comment::do_display_comments_threaded($hResult, 1);
}
/**
* display flat comments
*/
function display_comments_flat($versionId)
{
$hResult = Comment::grab_comments($versionId);
if ($hResult)
{
while($oRow = query_fetch_object($hResult))
{
Comment::view_app_comment($oRow);
}
}
}
function view_app_comments($versionId, $threadId = 0)
{
global $aClean;
// count posts
$hResult = query_parameters("SELECT commentId FROM appComments WHERE versionId = '?'", $versionId);
$messageCount = query_num_rows($hResult);
//start comment format table
echo html_frame_start("","98%",'',0);
echo '
',"\n";
echo '
',"\n";
$oVersion = new version($versionId);
// message display mode changer
if ($_SESSION['current']->isLoggedIn())
{
// FIXME we need to change this so not logged in users can change current view as well
if (!empty($aClean['sCmode']))
$_SESSION['current']->setPref("comments:mode", $aClean['sCmode']);
$sel[$_SESSION['current']->getPref("comments:mode", "threaded")] = 'selected';
echo '
',"\n";
}
// blank space
echo '
',"\n";
$oM = new objectManager("comment", "Add comment");
$oM->setReturnTo($oVersion->objectMakeUrl());
// post new message button
echo '