diff --git a/code/web/private_php/ams/autoload/ticket.php b/code/web/private_php/ams/autoload/ticket.php index 5ce9887ed..013dad842 100644 --- a/code/web/private_php/ams/autoload/ticket.php +++ b/code/web/private_php/ams/autoload/ticket.php @@ -203,7 +203,24 @@ class Ticket{ return $reply; } - + /** + * return the attachments list + * @param $ticket_id the id of the ticket. + * @return a ticket_reply object. + */ + public static function getAttachments( $ticket_id) { + $dbl = new DBLayer("lib"); + $statement = $dbl->select("`ticket_attachments`",array('ticket_TId' => $ticket_id), "`ticket_TId` =:ticket_TId ORDER BY Timestamp DESC"); + $fetchall = $statement->fetchall(); + $base = 0; + foreach ($fetchall as &$value) { + $webUser = new WebUsers($value['Uploader']); + $fetchall[$base]['Username'] = $webUser->getUsername(); + $base++; + } + return $fetchall; + } + /** * create a new reply for a ticket. * A reply will only be added if the content isn't empty and if the ticket isn't closed. @@ -571,4 +588,33 @@ class Ticket{ $this->priority = $p; } + /** + * function that creates a ticket Attachment. + */ + public static function add_Attachment($TId,$filename,$author,$tempFile){ + + global $FILE_STORAGE_PATH; + $length = 20; + $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_'; + $randomString = ''; + for ($i = 0; $i < $length; $i++) { + $randomString .= $characters[rand(0, strlen($characters) - 1)]; + } + $targetFile = $FILE_STORAGE_PATH . $randomString . "/" . $filename; + + $ticket = new Ticket(); + $ticket->load_With_TId($TId); + + //create the attachment! + $dbl = new DBLayer("lib"); + $dbl->insert("`ticket_attachments`", Array('ticket_TId' => $TId, 'Filename' => $filename, 'Filesize' => filesize($tempFile), 'Uploader' => $author, 'Path' => $randomString . "/" . $filename)); + mkdir($FILE_STORAGE_PATH . $randomString); + move_uploaded_file($tempFile,$targetFile); + + //write a log entry + Ticket_Log::createLogEntry( $TId, $author, 10); + + return true; + } + } diff --git a/code/web/private_php/ams/autoload/ticket_log.php b/code/web/private_php/ams/autoload/ticket_log.php index c6d88959b..6ca354d3e 100644 --- a/code/web/private_php/ams/autoload/ticket_log.php +++ b/code/web/private_php/ams/autoload/ticket_log.php @@ -13,6 +13,7 @@ * -# assigned to the ticket * -# forwarded ticket to support group arg * -# unassigned to the ticket +* -# added attachment to the ticket * * @author Daan Janssens, mentored by Matthew Lagoe */ @@ -36,6 +37,7 @@ class Ticket_Log{ * 7: assigned to the ticket * 8: Forwarded ticket to support group arg * 9: unassigned to the ticket + *10: added attachment to the ticket * ****************************************/ diff --git a/code/web/private_php/ams/translations/en.ini b/code/web/private_php/ams/translations/en.ini index f2a21d2ab..ca199831c 100644 --- a/code/web/private_php/ams/translations/en.ini +++ b/code/web/private_php/ams/translations/en.ini @@ -154,6 +154,7 @@ group_size_error = "The name has to be between 4-20 chars and the tag between 2- 7 = "assigned to the ticket" 8 = "forwarded the ticket to the support group: " 9 = "unassigned from the ticket" +10= "added attachment" [error] title404 = "Not
Found!" diff --git a/code/web/private_php/setup/sql/nel_ams_lib_00002.sql b/code/web/private_php/setup/sql/nel_ams_lib_00002.sql index 101858db2..99700c532 100644 --- a/code/web/private_php/setup/sql/nel_ams_lib_00002.sql +++ b/code/web/private_php/setup/sql/nel_ams_lib_00002.sql @@ -32,7 +32,8 @@ CREATE TABLE IF NOT EXISTS `ticket_attachments` ( `Filename` varchar(45) COLLATE utf8_unicode_ci NOT NULL, `Timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `Filesize` int(10) NOT NULL, - `Uploader` int(10) unsigned NOT NULL + `Uploader` int(10) unsigned NOT NULL, + `Path` VARCHAR(128) NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; -- diff --git a/code/web/public_php/ams/func/upload.php b/code/web/public_php/ams/func/upload.php index 921f24e03..fdf9f6fd7 100644 --- a/code/web/public_php/ams/func/upload.php +++ b/code/web/public_php/ams/func/upload.php @@ -6,8 +6,6 @@ $id = $_POST['PHPSESSID']; session_id($id); session_start(); -global $FILE_STORAGE_PATH; - // Set permission if ( isset( $_SESSION['ticket_user'] ) ) { $return['permission'] = unserialize( $_SESSION['ticket_user'] ) -> getPermission(); @@ -27,10 +25,9 @@ global $FILE_STORAGE_PATH; if (!empty($_FILES)) { $tempFile = $_FILES['Filedata']['tmp_name']; - $targetFile = $FILE_STORAGE_PATH . $_FILES['Filedata']['name']; $fileParts = pathinfo($_FILES['Filedata']['name']); - move_uploaded_file($tempFile,$targetFile); + Ticket::add_Attachment($_GET['id'],$_FILES['Filedata']['name'],$_SESSION['id'],$tempFile); } } } diff --git a/code/web/public_php/ams/inc/show_ticket.php b/code/web/public_php/ams/inc/show_ticket.php index e8d010461..b472686d2 100644 --- a/code/web/public_php/ams/inc/show_ticket.php +++ b/code/web/public_php/ams/inc/show_ticket.php @@ -64,6 +64,10 @@ function show_ticket(){ $result['ticket_assignedTo'] = Assigned::getUserAssignedToTicket($result['ticket_tId']); $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; + global $FILE_WEB_PATH; + $result['FILE_WEB_PATH'] = $FILE_WEB_PATH; + global $BASE_WEBPATH; + $result['BASE_WEBPATH'] = $BASE_WEBPATH; foreach( $result['ticket_replies'] as $reply){ $webReplyUser = new WebUsers($reply['authorExtern']); $result['ticket_replies'][$i]['author'] = $webReplyUser->getUsername(); @@ -77,6 +81,8 @@ function show_ticket(){ $result['hasInfo'] = $target_ticket->hasInfo(); global $INGAME_WEBPATH; $result['ingame_webpath'] = $INGAME_WEBPATH; + //get attachments + $result['ticket_attachments'] = Ticket::getAttachments($result['ticket_id']); return $result; }else{ diff --git a/code/web/public_php/ams/templates/show_ticket.tpl b/code/web/public_php/ams/templates/show_ticket.tpl index 9b659b795..19d35b98d 100644 --- a/code/web/public_php/ams/templates/show_ticket.tpl +++ b/code/web/public_php/ams/templates/show_ticket.tpl @@ -30,11 +30,27 @@ + + - - - + + + + + {foreach from=$ticket_attachments item=array} + + + + + + + {/foreach}
Assigned To: {if $ticket_assignedTo neq ""} {$ticket_assignedToText} {else} {$not_assigned} {/if}Filename: Uploaded: Filesize: Uploaded by:
{$array['Filename']}{$array['Timestamp']}{$array['Filesize']} Bytes{if $permission > 1} + {$array['Username']} + {else} + {$array['Username']} + {/if} +