From b54d74ea814d9f8449cc334fddf4c651156aeda3 Mon Sep 17 00:00:00 2001 From: Quitta Date: Fri, 19 Jul 2013 15:59:39 +0200 Subject: [PATCH] Admins/Mods can post hidden replies! --- .../ryzom_ams/ams_lib/autoload/ticket.php | 10 +-- .../ams_lib/autoload/ticket_reply.php | 64 +++++++++++-------- .../www/html/func/reply_on_ticket.php | 6 +- .../ryzom_ams/www/html/inc/show_reply.php | 5 +- .../ryzom_ams/www/html/inc/show_ticket.php | 8 ++- .../www/html/templates/show_reply.tpl | 4 +- .../www/html/templates/show_ticket.tpl | 40 ++++++++---- 7 files changed, 86 insertions(+), 51 deletions(-) diff --git a/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/ticket.php b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/ticket.php index bd78bc241..cb25794ae 100644 --- a/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/ticket.php +++ b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/ticket.php @@ -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 } diff --git a/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/ticket_reply.php b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/ticket_reply.php index d61eff3c7..9726531dc 100644 --- a/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/ticket_reply.php +++ b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/ticket_reply.php @@ -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']); - - $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; + 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']); + + $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); } @@ -91,14 +97,15 @@ class Ticket_Reply{ $this->ticket = $row['Ticket']; $this->content = $row['Content']; $this->author = $row['Author']; - $this->timestamp = $row['Timestamp']; + $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); } @@ -125,7 +132,10 @@ class Ticket_Reply{ public function getTReplyId(){ 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; + } } \ No newline at end of file diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/func/reply_on_ticket.php b/code/ryzom/tools/server/ryzom_ams/www/html/func/reply_on_ticket.php index c3010d01c..f79ffabf9 100644 --- a/code/ryzom/tools/server/ryzom_ams/www/html/func/reply_on_ticket.php +++ b/code/ryzom/tools/server/ryzom_ams/www/html/func/reply_on_ticket.php @@ -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); diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/inc/show_reply.php b/code/ryzom/tools/server/ryzom_ams/www/html/inc/show_reply.php index c387e3cc4..d158107b2 100644 --- a/code/ryzom/tools/server/ryzom_ams/www/html/inc/show_reply.php +++ b/code/ryzom/tools/server/ryzom_ams/www/html/inc/show_reply.php @@ -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(); diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/inc/show_ticket.php b/code/ryzom/tools/server/ryzom_ams/www/html/inc/show_ticket.php index 3e6f13d18..699311781 100644 --- a/code/ryzom/tools/server/ryzom_ams/www/html/inc/show_ticket.php +++ b/code/ryzom/tools/server/ryzom_ams/www/html/inc/show_ticket.php @@ -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']); diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/templates/show_reply.tpl b/code/ryzom/tools/server/ryzom_ams/www/html/templates/show_reply.tpl index eafad703c..886153d5a 100644 --- a/code/ryzom/tools/server/ryzom_ams/www/html/templates/show_reply.tpl +++ b/code/ryzom/tools/server/ryzom_ams/www/html/templates/show_reply.tpl @@ -20,8 +20,8 @@ {else if $author_permission gt '1'} {if isset($isMod) and $isMod eq "TRUE"} {$authorName}{else} {$authorName} {/if}

{/if} - -

{$reply_content}

+

{if $hidden eq 1}{/if}{$reply_content}{if $hidden eq 1}{/if}

+ diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/templates/show_ticket.tpl b/code/ryzom/tools/server/ryzom_ams/www/html/templates/show_ticket.tpl index 0ee7f5548..d91aeeb15 100644 --- a/code/ryzom/tools/server/ryzom_ams/www/html/templates/show_ticket.tpl +++ b/code/ryzom/tools/server/ryzom_ams/www/html/templates/show_ticket.tpl @@ -33,13 +33,15 @@ {foreach from=$ticket_replies item=reply} -

{$reply.timestamp} - {if $reply.permission eq '1'} - {if isset($isMod) and $isMod eq "TRUE"} {$reply.author}{else} {$reply.author} {/if}

- {else if $reply.permission gt '1'} - {if isset($isMod) and $isMod eq "TRUE"} {$reply.author}{else} {$reply.author} {/if}

- {/if} -

{$reply.replyContent}

+

+ {$reply.timestamp} + {if $reply.permission eq '1'} + {if isset($isMod) and $isMod eq "TRUE"} {$reply.author}{else} {$reply.author} {/if} + {else if $reply.permission gt '1'} + {if isset($isMod) and $isMod eq "TRUE"} {$reply.author}{else} {$reply.author} {/if} + {/if} +

+

{if $reply.hidden eq 1}{/if}{$reply.replyContent}{if $reply.hidden eq 1}{/if}

{/foreach} @@ -56,15 +58,25 @@
{if $ticket_status neq 3} - {$t_reply}: -
- -
-
- + {$t_reply}: +
+ +
+
+ +
-
+ {if isset($isMod) and $isMod eq "TRUE"} +
+ +
+
+ Hide reply for user. +
+
+
+ {/if} {/if} {if isset($isMod) and $isMod eq "TRUE"}