added log system, added ticketupdateStatusandPriority(), using JSON for keeping action etc

This commit is contained in:
Quitta 2013-07-12 19:43:33 +02:00
parent 1f8ed0b845
commit f310f87658
8 changed files with 138 additions and 49 deletions

View file

@ -69,18 +69,43 @@ class Ticket{
* creates a ticket + first initial reply and fills in the content of it! * creates a ticket + first initial reply and fills in the content of it!
* *
*/ */
public static function create_Ticket( $title, $content, $category, $author) { public static function create_Ticket( $title, $content, $category, $author, $real_author) {
$ticket = new Ticket(); $ticket = new Ticket();
$ticket->set($title,1,0,$category,$author,0); $ticket->set($title,1,0,$category,$author,0);
$ticket->create(); $ticket->create();
$ticket_id = $ticket->getTId(); $ticket_id = $ticket->getTId();
Ticket_Reply::createReply($content, $author, $ticket_id); Ticket_Reply::createReply($content, $author, $ticket_id);
if ( $author == $real_author){
Ticket_Log::createLogEntry( $ticket_id, $author, 1);
}else{
Ticket_Log::createLogEntry( $ticket_id, $real_author, 2, $author);
}
return $ticket_id; return $ticket_id;
} }
/*FUNCTION: updateTicketStatusAndPriority()
* creates a ticket + first initial reply and fills in the content of it!
*
*/
public static function updateTicketStatusAndPriority( $ticket_id, $newStatus, $newPriority, $author) {
$ticket = new Ticket();
$ticket->load_With_TId($ticket_id);
if ($ticket->getStatus() != $newStatus){
$ticket->setStatus($newStatus);
Ticket_Log::createLogEntry( $ticket_id, $author, 5, $newStatus);
}
if ($ticket->getPriority() != $newPriority){
$ticket->setPriority($newPriority);
Ticket_Log::createLogEntry( $ticket_id, $author, 6, $newPriority);
}
$ticket->update();
}
//return constructed element based on TCategoryId //return constructed element based on TCategoryId
public static function getLatestReply( $ticket_id) { public static function getLatestReply( $ticket_id) {
$dbl = new DBLayer("lib"); $dbl = new DBLayer("lib");

View file

@ -2,39 +2,55 @@
class Ticket_Log{ class Ticket_Log{
private $tCategoryId; private $tLogId;
private $name; private $timestamp;
private $query;
private $author;
private $ticket;
/****************************************
*Action ID's:
* 1: User X Created Ticket
* 2: Admin X created ticket for arg
* 3: Read Ticket
* 4: Added Reply ID: arg to ticket
* 5: Changed status to arg
* 6: Changed Priority to arg
*
****************************************/
////////////////////////////////////////////Functions//////////////////////////////////////////////////// ////////////////////////////////////////////Functions////////////////////////////////////////////////////
//Creates a ticket_Catergory in the DB //Creates a log entry
public static function createTicketCategory( $name) { public static function createLogEntry( $ticket_id, $author_id, $action, $arg = -1) {
$dbl = new DBLayer("lib"); global $TICKET_LOGGING;
$query = "INSERT INTO ticket_category (Name) VALUES (:name)"; if($TICKET_LOGGING){
$values = Array('name' => $name); $dbl = new DBLayer("lib");
$dbl->execute($query, $values); $query = "INSERT INTO ticket_log (Timestamp, Query, Ticket, Author) VALUES (now(), :query, :ticket, :author )";
$values = Array('ticket' => $ticket_id, 'author' => $author_id, 'query' => json_encode(array($action,$arg)));
$dbl->execute($query, $values);
}
} }
//return constructed element based on TCategoryId //return constructed element based on TLogId
public static function constr_TCategoryId( $id) { public static function constr_TLogId( $id) {
$instance = new self(); $instance = new self();
$instance->setTCategoryId($id); $instance->setTLogId($id);
return $instance; return $instance;
} }
//returns list of all category objects //returns list of all logs of a ticket
public static function getAllCategories() { public static function getAllLogs($ticket_id) {
$dbl = new DBLayer("lib"); $dbl = new DBLayer("lib");
$statement = $dbl->executeWithoutParams("SELECT * FROM ticket_category"); $statement = $dbl->execute("SELECT * FROM ticket_log INNER JOIN ticket_user ON ticket_log.Author = ticket_user.TUserId and ticket_log.Ticket=:id", array('id' => $ticket_id));
$row = $statement->fetchAll(); $row = $statement->fetchAll();
$result = Array(); $result = Array();
foreach($row as $category){ foreach($row as $log){
$instance = new self(); $instance = new self();
$instance->tCategoryId = $category['TCategoryId']; $instance->set($log);
$instance->name = $category['Name'];
$result[] = $instance; $result[] = $instance;
} }
return $result; return $result;
@ -45,48 +61,85 @@ class Ticket_Log{
public function __construct() { public function __construct() {
} }
//set values
public function set($values) {
$this->setTLogId($values['TLogId']);
$this->setTimestamp($values['Timestamp']);
$this->setQuery($values['Query']);
$this->setTicket($values['Ticket']);
$this->setAuthor($values['Author']);
}
//return constructed element based on TCategoryId //Load with tlogId
public function load_With_TCategoryId( $id) { public function load_With_TLogId( $id) {
$dbl = new DBLayer("lib"); $dbl = new DBLayer("lib");
$statement = $dbl->execute("SELECT * FROM ticket_category WHERE TCategoryId=:id", array('id' => $id)); $statement = $dbl->execute("SELECT * FROM ticket_log WHERE TLogId=:id", array('id' => $id));
$row = $statement->fetch(); $row = $statement->fetch();
$this->tCategoryId = $row['TCategoryId']; $this->set($row);
$this->name = $row['Name'];
} }
//update private data to DB. //update private data to DB.
public function update(){ public function update(){
$dbl = new DBLayer("lib"); $dbl = new DBLayer("lib");
$query = "UPDATE ticket_category SET Name = :name WHERE TCategoryId=:id"; $query = "UPDATE ticket_log SET Timestamp = :timestamp, Query = :query, Author = :author, Ticket = :ticket WHERE TLogId=:id";
$values = Array('id' => $this->tCategoryId, 'name' => $this->name); $values = Array('id' => $this->getTLogId(), 'timestamp' => $this->getTimestamp(), 'query' => $this->getQuery(), 'author' => $this->getAuthor(), 'ticket' => $this->getTicket() );
$statement = $dbl->execute($query, $values); $statement = $dbl->execute($query, $values);
} }
////////////////////////////////////////////Getters//////////////////////////////////////////////////// ////////////////////////////////////////////Getters////////////////////////////////////////////////////
public function getName(){ public function getTLogId(){
if ($this->name == ""){ return $this->tLogId;
$this->load_With_TCategoryId($this->tCategoryId);
}
return $this->name;
} }
public function getTimestamp(){
public function getTCategoryId(){ return $this->timestamp;
return $this->tCategoryId;
} }
public function getQuery(){
return $this->query;
}
public function getAuthor(){
return $this->author;
}
public function getTicket(){
return $this->ticket;
}
public function getAcion(){
$decodedQuery = json_decode($this->ticket);
return $decodedQuery[0];
}
public function getArgument(){
$decodedQuery = json_decode($this->ticket);
return $decodedQuery[1];
}
////////////////////////////////////////////Setters//////////////////////////////////////////////////// ////////////////////////////////////////////Setters////////////////////////////////////////////////////
public function setName($n){ public function setTLogId($id){
$this->name = $n; $this->tLogId = $id;
} }
public function setTCategoryId($id){ public function setTimestamp($t){
$this->tCategoryId = $id; $this->timestamp = $t;
}
public function setQuery($q){
$this->query = $q;
}
public function setAuthor($a){
$this->author = $a;
}
public function setTicket($t){
$this->ticket = $t;
} }

View file

@ -53,6 +53,9 @@ class Ticket_Reply{
$ticket_reply = new Ticket_Reply(); $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));
$ticket_reply->create(); $ticket_reply->create();
$reply_id = $ticket_reply->getTReplyId();
Ticket_Log::createLogEntry( $ticket_id, $author, 4, $reply_id);
} }
////////////////////////////////////////////Methods//////////////////////////////////////////////////// ////////////////////////////////////////////Methods////////////////////////////////////////////////////
@ -76,7 +79,7 @@ class Ticket_Reply{
$dbl = new DBLayer("lib"); $dbl = new DBLayer("lib");
$query = "INSERT INTO ticket_reply (Ticket, Content, Author, Timestamp) VALUES (:ticket, :content, :author, now())"; $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); $values = Array('ticket' => $this->ticket, 'content' => $this->content, 'author' => $this->author);
$dbl->execute($query, $values); $this->tReplyId = $dbl->executeReturnId($query, $values);
} }
//return constructed element based on TId //return constructed element based on TId

View file

@ -40,3 +40,5 @@ $AMS_CACHEDIR = $AMS_LIB . '/cache';
$DEFAULT_LANGUAGE = 'en'; $DEFAULT_LANGUAGE = 'en';
$SITEBASE = dirname( __FILE__ ) . '/html/' ; $SITEBASE = dirname( __FILE__ ) . '/html/' ;
$TICKET_LOGGING = true;

View file

@ -18,7 +18,7 @@ function create_ticket(){
}else{ }else{
$author= Ticket_User::constr_ExternId($_POST['target_id'])->getTUserId(); $author= Ticket_User::constr_ExternId($_POST['target_id'])->getTUserId();
} }
$ticket_id = Ticket::create_Ticket($title, $content, $category, $author); $ticket_id = Ticket::create_Ticket($title, $content, $category, $author, $_SESSION['ticket_user']->getTUserId());
header("Location: index.php?page=show_ticket&id=".$ticket_id); header("Location: index.php?page=show_ticket&id=".$ticket_id);
exit; exit;

View file

@ -12,19 +12,15 @@ function reply_on_ticket(){
if(($target_ticket->getAuthor() == $_SESSION['ticket_user']->getTUserId()) || WebUsers::isAdmin() ){ if(($target_ticket->getAuthor() == $_SESSION['ticket_user']->getTUserId()) || WebUsers::isAdmin() ){
try{ try{
$author = $_SESSION['ticket_user']->getTUserId();
if(isset($_POST['ChangeStatus']) && $_POST['Content'] != ""){ if(isset($_POST['ChangeStatus']) && $_POST['Content'] != ""){
$content = filter_var($_POST['Content'], FILTER_SANITIZE_STRING); $content = filter_var($_POST['Content'], FILTER_SANITIZE_STRING);
$author = $_SESSION['ticket_user']->getTUserId();
Ticket_Reply::createReply($content, $author, $ticket_id); Ticket_Reply::createReply($content, $author, $ticket_id);
} }
if(isset($_POST['ChangeStatus']) && isset($_POST['ChangePriority']) && WebUsers::isAdmin()){ if(isset($_POST['ChangeStatus']) && isset($_POST['ChangePriority']) && WebUsers::isAdmin()){
$newStatus = filter_var($_POST['ChangeStatus'], FILTER_SANITIZE_NUMBER_INT); $newStatus = filter_var($_POST['ChangeStatus'], FILTER_SANITIZE_NUMBER_INT);
$newPriority = filter_var($_POST['ChangePriority'], FILTER_SANITIZE_NUMBER_INT); $newPriority = filter_var($_POST['ChangePriority'], FILTER_SANITIZE_NUMBER_INT);
$ticket = new Ticket(); Ticket::updateTicketStatusAndPriority($ticket_id,$newStatus, $newPriority, $author);
$ticket->load_With_TId($ticket_id);
$ticket->setStatus($newStatus);
$ticket->setPriority($newPriority);
$ticket->update();
} }
header("Location: index.php?page=show_ticket&id=".$ticket_id); header("Location: index.php?page=show_ticket&id=".$ticket_id);
exit; exit;

View file

@ -11,6 +11,7 @@ function show_ticket(){
if(($target_ticket->getAuthor() == $_SESSION['ticket_user']->getTUserId()) || WebUsers::isAdmin() ){ if(($target_ticket->getAuthor() == $_SESSION['ticket_user']->getTUserId()) || WebUsers::isAdmin() ){
$entire_ticket = Ticket::getEntireTicket( $result['ticket_id']); $entire_ticket = Ticket::getEntireTicket( $result['ticket_id']);
Ticket_Log::createLogEntry($result['ticket_id'],$_SESSION['ticket_user']->getTUserId(), 3);
$result['ticket_tId'] = $entire_ticket['ticket_obj']->getTId(); $result['ticket_tId'] = $entire_ticket['ticket_obj']->getTId();
$result['ticket_title'] = $entire_ticket['ticket_obj']->getTitle(); $result['ticket_title'] = $entire_ticket['ticket_obj']->getTitle();
$result['ticket_timestamp'] = $entire_ticket['ticket_obj']->getTimestamp(); $result['ticket_timestamp'] = $entire_ticket['ticket_obj']->getTimestamp();

View file

@ -31,7 +31,7 @@
<table class="table table-bordered" > <table class="table table-bordered" >
<tbody> <tbody>
{foreach from=$ticket_replies item=reply} {foreach from=$ticket_replies item=reply}
<tr {if $reply.permission eq '2'} style="background-color:rgb(242, 222, 222);{/if}"> <tr>
<td> <td>
<p><span class="label label-info"> {$reply.timestamp}</span> <p><span class="label label-info"> {$reply.timestamp}</span>
{if $reply.permission eq '1'} {if $reply.permission eq '1'}
@ -41,10 +41,19 @@
{/if} {/if}
<span class="label label-warning"><strong><i class="icon-user icon-white"></i>{if isset($isAdmin) and $isAdmin 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> <span class="label label-warning"><strong><i class="icon-user icon-white"></i>{if isset($isAdmin) and $isAdmin 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>
<p><pre>{$reply.replyContent}</pre></p> <p><pre{if $reply.permission eq '2'} style="background-color:rgb(248, 200, 200);"{/if}>{$reply.replyContent}</pre></p>
</td> </td>
</tr> </tr>
{/foreach} {/foreach}
{if $ticket_status eq 3}
<tr>
<td>
<p><pre style="background-color:rgb(255, 230, 153);">Ticket is closed.</pre></p>
</td>
</tr>
{/if}
<tr> <tr>
<td> <td>
<form id="reply" class="form-vertical" method="post" action="index.php"> <form id="reply" class="form-vertical" method="post" action="index.php">