fixed upper info bar when showing ticket: which contains the initial time, the time passed since latest update, the status, the category and the priority.

DB got updated, ticket has an extra priority field now, to make it easier for admins to make a distinction between tickets! Also made it possible for admins to change the status/priority when replying.

--HG--
branch : quitta-gsoc-2013
This commit is contained in:
Quitta 2013-07-11 20:31:34 +02:00
parent 24b08104f9
commit bc238fba7a
7 changed files with 271 additions and 29 deletions

View file

@ -43,4 +43,37 @@ class Gui_Elements{
} }
return $result; return $result;
} }
public static function time_elapsed_string($ptime){
$ttime = new DateTime($ptime);
$ptime = $ttime->getTimestamp();
$etime = time() - $ptime;
if ($etime < 1)
{
return '0 seconds';
}
$a = array( 12 * 30 * 24 * 60 * 60 => 'year',
30 * 24 * 60 * 60 => 'month',
24 * 60 * 60 => 'day',
60 * 60 => 'hour',
60 => 'minute',
1 => 'second'
);
foreach ($a as $secs => $str)
{
$d = $etime / $secs;
if ($d >= 1)
{
$r = round($d);
return $r . ' ' . $str . ($r > 1 ? 's' : '') . ' ago';
}
}
}
} }

View file

@ -8,21 +8,31 @@ class Ticket{
private $queue; private $queue;
private $ticket_category; private $ticket_category;
private $author; private $author;
private $priority;
////////////////////////////////////////////Functions//////////////////////////////////////////////////// ////////////////////////////////////////////Functions////////////////////////////////////////////////////
/*FUNCTION: getStatusArray /*FUNCTION: getStatusArray
* returns all possible statusses * returns all possible statusses
* *
*/ */
public static function getStatusArray() { public static function getStatusArray() {
return Array("Waiting on user reply","Waiting on support","Waiting on Dev reply","Closed"); return Array("Waiting on user reply","Waiting on support","Waiting on Dev reply","Closed");
} }
/*FUNCTION: getEntireTicket /*FUNCTION: getPriorityArray
* return all ticket of the given author's id. * returns all possible statusses
* *
*/ */
public static function getPriorityArray() {
return Array("Low","Normal","High","Super Dupa High");
}
/*FUNCTION: getEntireTicket
* return all ticket of the given author's id.
*
*/
public static function getEntireTicket($id) { public static function getEntireTicket($id) {
$ticket = new Ticket(); $ticket = new Ticket();
$ticket->load_With_TId($id); $ticket->load_With_TId($id);
@ -62,14 +72,25 @@ class Ticket{
public static function create_Ticket( $title, $content, $category, $author) { public static function create_Ticket( $title, $content, $category, $author) {
$ticket = new Ticket(); $ticket = new Ticket();
$ticket->set($title,1,0,$category,$author); $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);
return $ticket_id; return $ticket_id;
} }
//return constructed element based on TCategoryId
public static function getLatestReply( $ticket_id) {
$dbl = new DBLayer("lib");
$statement = $dbl->execute("SELECT * FROM ticket_reply WHERE Ticket =:id ORDER BY TReplyId DESC LIMIT 1 ", array('id' => $ticket_id));
$reply = new Ticket_Reply();
$reply->set($statement->fetch());
return $reply;
}
////////////////////////////////////////////Methods//////////////////////////////////////////////////// ////////////////////////////////////////////Methods////////////////////////////////////////////////////
public function __construct() { public function __construct() {
@ -77,19 +98,20 @@ class Ticket{
//Set ticket object //Set ticket object
public function set($t,$s,$q,$t_c,$a){ public function set($t,$s,$q,$t_c,$a,$p){
$this->title = $t; $this->title = $t;
$this->status = $s; $this->status = $s;
$this->queue = $q; $this->queue = $q;
$this->ticket_category = $t_c; $this->ticket_category = $t_c;
$this->author = $a; $this->author = $a;
$this->priority = $p;
} }
//create ticket by writing private data to DB. //create ticket by writing private data to DB.
public function create(){ public function create(){
$dbl = new DBLayer("lib"); $dbl = new DBLayer("lib");
$query = "INSERT INTO ticket (Timestamp, Title, Status, Queue, Ticket_Category, Author) VALUES (now(), :title, :status, :queue, :tcat, :author)"; $query = "INSERT INTO ticket (Timestamp, Title, Status, Queue, Ticket_Category, Author, Priority) VALUES (now(), :title, :status, :queue, :tcat, :author, :priority)";
$values = Array('title' => $this->title, 'status' => $this->status, 'queue' => $this->queue, 'tcat' => $this->ticket_category, 'author' => $this->author); $values = Array('title' => $this->title, 'status' => $this->status, 'queue' => $this->queue, 'tcat' => $this->ticket_category, 'author' => $this->author, 'priority' => $this->priority);
$this->tId = $dbl->executeReturnId($query, $values); ; $this->tId = $dbl->executeReturnId($query, $values); ;
} }
@ -105,18 +127,24 @@ class Ticket{
$this->queue = $row['Queue']; $this->queue = $row['Queue'];
$this->ticket_category = $row['Ticket_Category']; $this->ticket_category = $row['Ticket_Category'];
$this->author = $row['Author']; $this->author = $row['Author'];
$this->priority = $row['Priority'];
} }
//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 SET Timestamp = :timestamp, Title = :title, Status = :status, Queue = :queue, Ticket_Category = :tcat, Author = :author WHERE TId=:id"; $query = "UPDATE ticket SET Timestamp = :timestamp, Title = :title, Status = :status, Queue = :queue, Ticket_Category = :tcat, Author = :author, Priority = :priority WHERE TId=:id";
$values = Array('id' => $this->tId, 'timestamp' => $this->timestamp, 'title' => $this->title, 'status' => $this->status, 'queue' => $this->queue, 'tcat' => $this->ticket_category, 'author' => $this->author); $values = Array('id' => $this->tId, 'timestamp' => $this->timestamp, 'title' => $this->title, 'status' => $this->status, 'queue' => $this->queue, 'tcat' => $this->ticket_category, 'author' => $this->author, 'priority' => $this->priority);
$statement = $dbl->execute($query, $values); $statement = $dbl->execute($query, $values);
} }
/*FUNCTION: postreply
* returns all possible statusses
*
*
public function postReply() {
return Array("Waiting on user reply","Waiting on support","Waiting on Dev reply","Closed");
}*/
////////////////////////////////////////////Getters//////////////////////////////////////////////////// ////////////////////////////////////////////Getters////////////////////////////////////////////////////
public function getTId(){ public function getTId(){
@ -157,6 +185,15 @@ class Ticket{
return $this->author; return $this->author;
} }
public function getPriority(){
return $this->priority;
}
public function getPriorityText(){
$priorityArray = Ticket::getPriorityArray();
return $priorityArray[$this->getPriority()];
}
////////////////////////////////////////////Setters//////////////////////////////////////////////////// ////////////////////////////////////////////Setters////////////////////////////////////////////////////
public function setTId($id){ public function setTId($id){
@ -187,4 +224,8 @@ class Ticket{
$this->author = $a; $this->author = $a;
} }
public function setPriority($p){
$this->priority = $p;
}
} }

View file

@ -16,6 +16,7 @@ class Ticket_Reply{
return $instance; return $instance;
} }
//return constructed element based on TCategoryId //return constructed element based on TCategoryId
public static function getRepliesOfTicket( $ticket_id) { public static function getRepliesOfTicket( $ticket_id) {
$dbl = new DBLayer("lib"); $dbl = new DBLayer("lib");
@ -50,7 +51,7 @@ class Ticket_Reply{
$content_id = $ticket_content->getTContentId(); $content_id = $ticket_content->getTContentId();
$ticket_reply = new Ticket_Reply(); $ticket_reply = new Ticket_Reply();
$ticket_reply->set($ticket_id, $content_id, $author); $ticket_reply->set(Array('Ticket' => $ticket_id,'Content' => $content_id,'Author' => $author));
$ticket_reply->create(); $ticket_reply->create();
} }
@ -61,10 +62,13 @@ class Ticket_Reply{
//Set ticket_reply object //Set ticket_reply object
public function set($t,$c,$a){ public function set($values){
$this->setTicket($t); $this->setTicket($values['Ticket']);
$this->setContent($c); $this->setContent($values['Content']);
$this->setAuthor($a); $this->setAuthor($values['Author']);
if(isset($values['Timestamp'])){
$this->setTimestamp($values['Timestamp']);
}
} }
//create ticket by writing private data to DB. //create ticket by writing private data to DB.

View file

@ -17,11 +17,13 @@ function reply_on_ticket(){
$author = $_SESSION['ticket_user']->getTUserId(); $author = $_SESSION['ticket_user']->getTUserId();
Ticket_Reply::createReply($content, $author, $ticket_id); Ticket_Reply::createReply($content, $author, $ticket_id);
if(isset($_POST['ChangeStatus']) && 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);
$ticket = new Ticket(); $ticket = new Ticket();
$ticket->load_With_TId($ticket_id); $ticket->load_With_TId($ticket_id);
$ticket->setStatus($newStatus); $ticket->setStatus($newStatus);
$ticket->setPriority($newPriority);
$ticket->update(); $ticket->update();
} }
header("Location: index.php?page=show_ticket&id=".$ticket_id); header("Location: index.php?page=show_ticket&id=".$ticket_id);

View file

@ -13,6 +13,14 @@ function show_ticket(){
$entire_ticket = Ticket::getEntireTicket( $result['ticket_id']); $entire_ticket = Ticket::getEntireTicket( $result['ticket_id']);
$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_status'] = $entire_ticket['ticket_obj']->getStatus();
$result['ticket_prioritytext'] = $entire_ticket['ticket_obj']->getPriorityText();
$result['ticket_priorities'] = Ticket::getPriorityArray();
$result['ticket_priority'] = $entire_ticket['ticket_obj']->getPriority();
$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"), Array("tReplyId","replyContent","timestamp","authorExtern","permission"));
$i = 0; $i = 0;
foreach( $result['ticket_replies'] as $reply){ foreach( $result['ticket_replies'] as $reply){

View file

@ -83,6 +83,7 @@
`Title` VARCHAR(120) NOT NULL , `Title` VARCHAR(120) NOT NULL ,
`Status` INT NULL DEFAULT 0 , `Status` INT NULL DEFAULT 0 ,
`Queue` INT NULL DEFAULT 0 , `Queue` INT NULL DEFAULT 0 ,
`Priority` INT NULL DEFAULT 0 ,
`Ticket_Category` INT NOT NULL , `Ticket_Category` INT NOT NULL ,
`Author` INT NOT NULL , `Author` INT NOT NULL ,
PRIMARY KEY (`TId`) , PRIMARY KEY (`TId`) ,

View file

@ -2,7 +2,7 @@
<div class="row-fluid sortable ui-sortable"> <div class="row-fluid sortable ui-sortable">
<div class="box span9"> <div class="box span9">
<div class="box-header well" data-original-title=""> <div class="box-header well" data-original-title="">
<h2><i class="icon-tags"></i> {$t_title}[ID#{$ticket_tId}] </h2> <h2><i class="icon-tag"></i>{$t_title} #{$ticket_tId} </h2>
<div class="box-icon"> <div class="box-icon">
<a href="#" class="btn btn-minimize btn-round"><i class="icon-chevron-up"></i></a> <a href="#" class="btn btn-minimize btn-round"><i class="icon-chevron-up"></i></a>
<a href="#" class="btn btn-close btn-round"><i class="icon-remove"></i></a> <a href="#" class="btn btn-close btn-round"><i class="icon-remove"></i></a>
@ -11,12 +11,29 @@
<div class="box-content"> <div class="box-content">
<div class="row-fluid"> <div class="row-fluid">
<legend>{$title}: {$ticket_title} </legend> <legend>{$title}: {$ticket_title} </legend>
<table class="table" >
<form id="changeTicket" class="form-vertical" method="post" action="index.php">
<table class="table table-bordered table-condensed ">
<tr>
<td><strong>Original Submitted: </strong>{$ticket_timestamp}</td>
<td><strong>Last Updated: </strong>{$ticket_lastupdate}</td>
<td><strong>Status: </strong>{if $ticket_status neq 3}<span class="label label-success">Open</span>{/if} <span class="label {if $ticket_status eq 0}label-success{else if $ticket_status eq 1}label-warning{else if $ticket_status eq 2}label-important{/if}"><strong>{$ticket_statustext}</strong></span></td>
</tr>
<tr>
<td><strong>Category: </strong>{$ticket_category}</td>
<td><strong>Priority: </strong>{$ticket_prioritytext}</td>
<td><strong>Associated: </strong><span class="label label-info">Ticket#33</span></td>
</tr>
</table>
<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 {if $reply.permission eq '2'} style="background-color:rgb(242, 222, 222);{/if}">
<td> <td>
<p><span class="label label-info"><i class="icon-tag icon-white"></i> [ID#{$reply.tReplyId}] {$reply.timestamp}</span> <p><span class="label label-info"> {$reply.timestamp}</span>
{if $reply.permission eq '1'} {if $reply.permission eq '1'}
<!-- <span class="label label-important"><strong></i>[User]:</strong></span>--> <!-- <span class="label label-important"><strong></i>[User]:</strong></span>-->
{else if $reply.permission eq '2'} {else if $reply.permission eq '2'}
@ -41,8 +58,8 @@
</div> </div>
</div> </div>
{if isset($isAdmin) and $isAdmin eq "TRUE"} {if isset($isAdmin) and $isAdmin eq "TRUE"}
<div class="control-group"> <div class="control-group" style="display: inline-block;">
<label class="control-label">Change Status to</label> <label class="control-label">Change status to</label>
<div class="controls"> <div class="controls">
<select name="ChangeStatus"> <select name="ChangeStatus">
{foreach from=$statusList key=k item=v} {foreach from=$statusList key=k item=v}
@ -51,6 +68,16 @@
</select> </select>
</div> </div>
</div> </div>
<div class="control-group" style="display: inline-block; margin-left:10px;"">
<label class="control-label">Change priority to</label>
<div class="controls">
<select name="ChangePriority">
{foreach from=$ticket_priorities key=k item=v}
<option value="{$k}" {if $k eq $ticket_priority}selected="selected"{/if}>{$v}</option>
{/foreach}
</select>
</div>
</div>
{/if} {/if}
<input type="hidden" name="function" value="reply_on_ticket"> <input type="hidden" name="function" value="reply_on_ticket">
<input type="hidden" name="ticket_id" value="{$ticket_id}"> <input type="hidden" name="ticket_id" value="{$ticket_id}">
@ -68,6 +95,132 @@
</div> </div>
</div> </div>
</div><!--/span--> </div><!--/span-->
<div class="box span3">
<div class="box-header well" data-original-title="">
<h2><i class="icon-th"></i>Tags</h2>
<div class="box-icon">
<a href="#" class="btn btn-minimize btn-round"><i class="icon-chevron-up"></i></a>
<a href="#" class="btn btn-close btn-round"><i class="icon-remove"></i></a>
</div>
</div>
<div class="box-content">
<div class="row-fluid">
<form id="addTag" class="form-vertical" method="post" action="index.php">
<legend>Tags</legend>
<div class="control-group">
<label class="control-label">Current Tags</label>
<div class="controls">
<div class="input-prepend">
<div id="checkbox1" class="checker"><span class="checked"><input style="opacity: 0;" id="inlineCheckbox2" value="option2" checked="checked" type="checkbox"></span></div> Hacked
<div id="checkbox1" class="checker"><span class="checked"><input style="opacity: 0;" id="inlineCheckbox2" value="option2" checked="checked" type="checkbox"></span></div> Botanic
<div id="checkbox1" class="checker"><span class="checked"><input style="opacity: 0;" id="inlineCheckbox2" value="option2" checked="checked" type="checkbox"></span></div> evilwebsite.comz
<div id="checkbox1" class="checker"><span class="checked"><input style="opacity: 0;" id="inlineCheckbox2" value="option2" checked="checked" type="checkbox"></span></div> keylogger
</div>
</div>
</div>
<div class="control-group">
<label class="control-label">New Tag</label>
<div class="controls">
<div class="input-prepend">
<input type="text" class="span8" id="newTag" name="newTag">
</div>
</div>
</div>
<div class="control-group">
<label class="control-label"></label>
<div class="controls">
<button type="submit" class="btn btn-primary" >Update</button>
</div>
</div>
</form>
</div>
</div>
</div>
<div class="box span3">
<div class="box-header well" data-original-title="">
<h2><i class="icon-th"></i>Groups</h2>
<div class="box-icon">
<a href="#" class="btn btn-minimize btn-round"><i class="icon-chevron-up"></i></a>
<a href="#" class="btn btn-close btn-round"><i class="icon-remove"></i></a>
</div>
</div>
<div class="box-content">
<div class="row-fluid">
<form id="addTag" class="form-vertical" method="post" action="index.php">
<legend>Groups</legend>
<div class="control-group">
<label class="control-label">Current Groups</label>
<div class="controls">
<div class="input-prepend">
<div id="checkbox1" class="checker"><span class="checked"><input style="opacity: 0;" id="inlineCheckbox2" value="option2" checked="checked" type="checkbox"></span></div> Hacked accounts
</div>
</div>
</div>
<div class="control-group">
<label class="control-label">New Group</label>
<div class="controls">
<div class="input-prepend">
<input type="text" class="span8" id="newTag" name="newTag">
</div>
</div>
</div>
<div class="control-group">
<label class="control-label"></label>
<div class="controls">
<button type="submit" class="btn btn-primary" >Update</button>
</div>
</div>
</form>
</div>
</div>
</div>
<div class="box span3">
<div class="box-header well" data-original-title="">
<h2><i class="icon-th"></i>Associations</h2>
<div class="box-icon">
<a href="#" class="btn btn-minimize btn-round"><i class="icon-chevron-up"></i></a>
<a href="#" class="btn btn-close btn-round"><i class="icon-remove"></i></a>
</div>
</div>
<div class="box-content">
<div class="row-fluid">
<form id="addTag" class="form-vertical" method="post" action="index.php">
<legend>Associations</legend>
<div class="control-group">
<label class="control-label">Current Associations</label>
<div class="controls">
<div class="input-prepend">
<div id="checkbox1" class="checker"><span class="checked"><input style="opacity: 0;" id="inlineCheckbox2" value="option2" checked="checked" type="checkbox"></span></div> Ticket #33
</div>
</div>
</div>
<div class="control-group">
<label class="control-label">New Association</label>
<div class="controls">
<div class="input-prepend">
<input type="text" class="span8" id="newTag" name="newTag">
</div>
</div>
</div>
<div class="control-group">
<label class="control-label"></label>
<div class="controls">
<button type="submit" class="btn btn-primary" >Update</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div><!--/row--> </div><!--/row-->
{/block} {/block}