Admins/Mods can post hidden replies!

This commit is contained in:
Quitta 2013-07-19 15:59:39 +02:00
parent 5608185e1d
commit 19721376a7
7 changed files with 86 additions and 51 deletions

View file

@ -33,10 +33,10 @@ class Ticket{
* return all ticket of the given author's id.
*
*/
public static function getEntireTicket($id) {
public static function getEntireTicket($id,$view_as_admin) {
$ticket = new Ticket();
$ticket->load_With_TId($id);
$reply_array = Ticket_Reply::getRepliesOfTicket($id);
$reply_array = Ticket_Reply::getRepliesOfTicket($id, $view_as_admin);
return Array('ticket_obj' => $ticket,'reply_array' => $reply_array);
}
@ -81,7 +81,7 @@ class Ticket{
}else{
Ticket_Log::createLogEntry( $ticket_id, $real_author, 2, $author);
}
Ticket_Reply::createReply($content, $author, $ticket_id);
Ticket_Reply::createReply($content, $author, $ticket_id, 0);
return $ticket_id;
}
@ -115,13 +115,13 @@ class Ticket{
return $reply;
}
public static function createReply($content, $author, $ticket_id){
public static function createReply($content, $author, $ticket_id, $hidden){
if($content != ""){
$ticket = new Ticket();
$ticket->load_With_TId($ticket_id);
//if status is not closed
if($ticket->getStatus() != 3){
Ticket_Reply::createReply($content, $author, $ticket_id);
Ticket_Reply::createReply($content, $author, $ticket_id, $hidden);
}else{
//TODO: Show error message that ticket is closed
}

View file

@ -6,6 +6,7 @@ class Ticket_Reply{
private $content;
private $author;
private $timestamp;
private $hidden;
////////////////////////////////////////////Functions////////////////////////////////////////////////////
@ -18,40 +19,42 @@ class Ticket_Reply{
//return constructed element based on TCategoryId
public static function getRepliesOfTicket( $ticket_id) {
public static function getRepliesOfTicket( $ticket_id, $view_as_admin) {
$dbl = new DBLayer("lib");
$statement = $dbl->execute("SELECT * FROM ticket_reply INNER JOIN ticket_content INNER JOIN ticket_user ON ticket_reply.Content = ticket_content.TContentId and ticket_reply.Ticket=:id and ticket_user.TUserId = ticket_reply.Author ORDER BY ticket_reply.TReplyId ASC", array('id' => $ticket_id));
$row = $statement->fetchAll();
$result = Array();
foreach($row as $tReply){
$instanceAuthor = Ticket_User::constr_TUserId($tReply['Author']);
$instanceAuthor->setExternId($tReply['ExternId']);
$instanceAuthor->setPermission($tReply['Permission']);
if(! $tReply['Hidden'] || $view_as_admin){
$instanceAuthor = Ticket_User::constr_TUserId($tReply['Author']);
$instanceAuthor->setExternId($tReply['ExternId']);
$instanceAuthor->setPermission($tReply['Permission']);
$instanceContent = new Ticket_Content();
$instanceContent->setTContentId($tReply['TContentId']);
$instanceContent->setContent($tReply['Content']);
$instanceContent = new Ticket_Content();
$instanceContent->setTContentId($tReply['TContentId']);
$instanceContent->setContent($tReply['Content']);
$instanceReply = new self();
$instanceReply->setTReplyId($tReply['TReplyId']);
$instanceReply->setTimestamp($tReply['Timestamp']);
$instanceReply->setAuthor($instanceAuthor);
$instanceReply->setTicket($ticket_id);
$instanceReply->setContent($instanceContent);
$result[] = $instanceReply;
$instanceReply = new self();
$instanceReply->setTReplyId($tReply['TReplyId']);
$instanceReply->setTimestamp($tReply['Timestamp']);
$instanceReply->setAuthor($instanceAuthor);
$instanceReply->setTicket($ticket_id);
$instanceReply->setContent($instanceContent);
$instanceReply->setHidden($tReply['Hidden']);
$result[] = $instanceReply;
}
}
return $result;
}
public static function createReply($content, $author, $ticket_id){
public static function createReply($content, $author, $ticket_id , $hidden){
$ticket_content = new Ticket_Content();
$ticket_content->setContent($content);
$ticket_content->create();
$content_id = $ticket_content->getTContentId();
$ticket_reply = new Ticket_Reply();
$ticket_reply->set(Array('Ticket' => $ticket_id,'Content' => $content_id,'Author' => $author));
$ticket_reply->set(Array('Ticket' => $ticket_id,'Content' => $content_id,'Author' => $author, 'Hidden' => $hidden));
$ticket_reply->create();
$reply_id = $ticket_reply->getTReplyId();
@ -72,13 +75,16 @@ class Ticket_Reply{
if(isset($values['Timestamp'])){
$this->setTimestamp($values['Timestamp']);
}
if(isset($values['Hidden'])){
$this->setHidden($values['Hidden']);
}
}
//create ticket by writing private data to DB.
public function create(){
$dbl = new DBLayer("lib");
$query = "INSERT INTO ticket_reply (Ticket, Content, Author, Timestamp) VALUES (:ticket, :content, :author, now())";
$values = Array('ticket' => $this->ticket, 'content' => $this->content, 'author' => $this->author);
$query = "INSERT INTO ticket_reply (Ticket, Content, Author, Timestamp, Hidden) VALUES (:ticket, :content, :author, now(), :hidden)";
$values = Array('ticket' => $this->ticket, 'content' => $this->content, 'author' => $this->author, 'hidden' => $this->hidden);
$this->tReplyId = $dbl->executeReturnId($query, $values);
}
@ -92,13 +98,14 @@ class Ticket_Reply{
$this->content = $row['Content'];
$this->author = $row['Author'];
$this->timestamp = $row['Timestamp'];
$this->hidden = $row['Hidden'];
}
//update private data to DB.
public function update(){
$dbl = new DBLayer("lib");
$query = "UPDATE ticket SET Ticket = :ticket, Content = :content, Author = :author, Timestamp = :timestamp WHERE TReplyId=:id";
$values = Array('id' => $this->tReplyId, 'timestamp' => $this->timestamp, 'ticket' => $this->ticket, 'content' => $this->content, 'author' => $this->author);
$query = "UPDATE ticket SET Ticket = :ticket, Content = :content, Author = :author, Timestamp = :timestamp, Hidden = :hidden WHERE TReplyId=:id";
$values = Array('id' => $this->tReplyId, 'timestamp' => $this->timestamp, 'ticket' => $this->ticket, 'content' => $this->content, 'author' => $this->author, 'hidden' => $this->hidden);
$statement = $dbl->execute($query, $values);
}
@ -126,6 +133,9 @@ class Ticket_Reply{
return $this->tReplyId;
}
public function getHidden(){
return $this->hidden;
}
////////////////////////////////////////////Setters////////////////////////////////////////////////////
@ -150,4 +160,8 @@ class Ticket_Reply{
public function setTReplyId($i){
$this->tReplyId = $i;
}
public function setHidden($h){
$this->hidden = $h;
}
}

View file

@ -14,7 +14,11 @@ function reply_on_ticket(){
try{
$author = $_SESSION['ticket_user']->getTUserId();
$content = filter_var($_POST['Content'], FILTER_SANITIZE_STRING);
Ticket::createReply($content, $author, $ticket_id);
$hidden = 0;
if(isset($_POST['hidden']) && Ticket_User::isMod($_SESSION['ticket_user'])){
$hidden = 1;
}
Ticket::createReply($content, $author, $ticket_id, $hidden);
if(isset($_POST['ChangeStatus']) && isset($_POST['ChangePriority']) && Ticket_User::isMod($_SESSION['ticket_user'])){
$newStatus = filter_var($_POST['ChangeStatus'], FILTER_SANITIZE_NUMBER_INT);

View file

@ -8,17 +8,18 @@ function show_reply(){
$reply = new Ticket_Reply();
$reply->load_With_TReplyId($result['reply_id']);
$ticket = new Ticket();
$ticket->load_With_TId($reply->getTicket());
if(($ticket->getAuthor() == $_SESSION['ticket_user']->getTUserId()) || Ticket_User::isMod($_SESSION['ticket_user'] )){
if(( $ticket->getAuthor() == $_SESSION['ticket_user']->getTUserId() && ! $reply->getHidden()) || Ticket_User::isMod($_SESSION['ticket_user'] )){
$content = new Ticket_Content();
$content->load_With_TContentId($reply->getContent());
$author = new Ticket_User();
$author->load_With_TUserId($reply->getAuthor());
$result['hidden'] = $reply->getHidden();
$result['ticket_id'] = $reply->getTicket();
$result['reply_timestamp'] = $reply->getTimestamp();
$result['author_permission'] = $author->getPermission();

View file

@ -10,7 +10,11 @@ function show_ticket(){
if(($target_ticket->getAuthor() == $_SESSION['ticket_user']->getTUserId()) || Ticket_User::isMod($_SESSION['ticket_user'] )){
$entire_ticket = Ticket::getEntireTicket( $result['ticket_id']);
$show_as_admin = false;
if(Ticket_User::isMod($_SESSION['ticket_user'])){
$show_as_admin = true;
}
$entire_ticket = Ticket::getEntireTicket( $result['ticket_id'],$show_as_admin);
Ticket_Log::createLogEntry($result['ticket_id'],$_SESSION['ticket_user']->getTUserId(), 3);
$result['ticket_tId'] = $entire_ticket['ticket_obj']->getTId();
$result['ticket_title'] = $entire_ticket['ticket_obj']->getTitle();
@ -22,7 +26,7 @@ function show_ticket(){
$result['ticket_statustext'] = $entire_ticket['ticket_obj']->getStatusText();
$result['ticket_lastupdate'] = Gui_Elements::time_elapsed_string(Ticket::getLatestReply($result['ticket_id'])->getTimestamp());
$result['ticket_category'] = $entire_ticket['ticket_obj']->getCategoryName();
$result['ticket_replies'] = Gui_Elements::make_table($entire_ticket['reply_array'], Array("getTReplyId","getContent()->getContent","getTimestamp","getAuthor()->getExternId","getAuthor()->getPermission"), Array("tReplyId","replyContent","timestamp","authorExtern","permission"));
$result['ticket_replies'] = Gui_Elements::make_table($entire_ticket['reply_array'], Array("getTReplyId","getContent()->getContent","getTimestamp","getAuthor()->getExternId","getAuthor()->getPermission","getHidden"), Array("tReplyId","replyContent","timestamp","authorExtern","permission","hidden"));
$i = 0;
foreach( $result['ticket_replies'] as $reply){
$result['ticket_replies'][$i]['author'] = WebUsers::getUsername($reply['authorExtern']);

View file

@ -20,8 +20,8 @@
{else if $author_permission gt '1'}
<span class="label label-warning"><strong><i class="icon-star icon-white"></i>{if isset($isMod) and $isMod eq "TRUE"} <a href="index.php?page=show_user&id={$author}"><font color="white"> {$authorName}</font>{else} {$authorName} {/if}</a></strong></span></p>
{/if}
<p><pre{if $author_permission gt '1'} {if $hidden eq 0} style="background-color:rgb(248, 200, 200);"{else if $hidden eq 1}style="background-color:rgb(207, 254, 255);"{/if}{/if}> {if $hidden eq 1}<i>{/if}{$reply_content}{if $hidden eq 1}</i>{/if}</pre></p>
<p><pre{if $author_permission eq '2'} style="background-color:rgb(248, 200, 200);"{/if}>{$reply_content}</pre></p>
</td>
</tr>
</table>

View file

@ -33,13 +33,15 @@
{foreach from=$ticket_replies item=reply}
<tr>
<td>
<p><span class="label label-info"> {$reply.timestamp}</span>
{if $reply.permission eq '1'}
<span class="label label-success"><strong><i class="icon-user icon-white"></i>{if isset($isMod) and $isMod eq "TRUE"} <a href="index.php?page=show_user&id={$reply.authorExtern}"><font color="white"> {$reply.author}</font>{else} {$reply.author} {/if}</a></strong></span></p>
{else if $reply.permission gt '1'}
<span class="label label-warning"><strong><i class="icon-star icon-white"></i>{if isset($isMod) and $isMod eq "TRUE"} <a href="index.php?page=show_user&id={$reply.authorExtern}"><font color="white"> {$reply.author}</font>{else} {$reply.author} {/if}</a></strong></span></p>
{/if}
<p><pre{if $reply.permission gt '1'} style="background-color:rgb(248, 200, 200);"{/if}>{$reply.replyContent}</pre></p>
<p>
<span class="label label-info"> {$reply.timestamp}</span>
{if $reply.permission eq '1'}
<span class="label label-success"><strong><i class="icon-user icon-white"></i>{if isset($isMod) and $isMod eq "TRUE"} <a href="index.php?page=show_user&id={$reply.authorExtern}"><font color="white"> {$reply.author}</font>{else} {$reply.author} {/if}</a></strong></span>
{else if $reply.permission gt '1'}
<span class="label label-warning"><strong><i class="icon-star icon-white"></i>{if isset($isMod) and $isMod eq "TRUE"} <a href="index.php?page=show_user&id={$reply.authorExtern}"><font color="white"> {$reply.author}</font>{else} {$reply.author} {/if}</a></strong></span>
{/if}
</p>
<p><pre{if $reply.permission gt '1'} {if $reply.hidden eq 0} style="background-color:rgb(248, 200, 200);"{else if $reply.hidden eq 1}style="background-color:rgb(207, 254, 255);"{/if}{/if}> {if $reply.hidden eq 1}<i>{/if}{$reply.replyContent}{if $reply.hidden eq 1}</i>{/if}</pre></p>
</td>
</tr>
{/foreach}
@ -56,15 +58,25 @@
<td>
<form id="reply" class="form-vertical" method="post" action="index.php">
{if $ticket_status neq 3}
<legend>{$t_reply}:</legend>
<div class="control-group">
<label class="control-label">{$t_fill}</label>
<div class="controls">
<div class="input-prepend">
<textarea rows="6" class="span12" id="Content" name="Content"></textarea>
<legend>{$t_reply}:</legend>
<div class="control-group">
<label class="control-label">{$t_fill}</label>
<div class="controls">
<div class="input-prepend">
<textarea rows="6" class="span12" id="Content" name="Content"></textarea>
</div>
</div>
</div>
</div>
{if isset($isMod) and $isMod eq "TRUE"}
<div class="control-group">
<label class="control-label">Options</label>
<div class="controls">
<div class="input-prepend">
<input type="checkbox" name="hidden">Hide reply for user.
</div>
</div>
</div>
{/if}
{/if}
{if isset($isMod) and $isMod eq "TRUE"}
<div class="control-group" style="display: inline-block;">