ticketview.php
上传用户:gzy2002
上传日期:2010-02-11
资源大小:1785k
文件大小:40k
- <?php
- // +-------------------------------------------------------------+
- // | DeskPRO v [2.0.1 Production]
- // | Copyright (C) 2001 - 2004 Headstart Solutions Limited
- // | Supplied by WTN-WDYL
- // | Nullified by WTN-WDYL
- // | Distribution via WebForum, ForumRU and associated file dumps
- // +-------------------------------------------------------------+
- // | DESKPRO IS NOT FREE SOFTWARE
- // +-------------------------------------------------------------+
- // | License ID : Full Enterprise License =) ...
- // | License Owner : WTN-WDYL Team
- // +-------------------------------------------------------------+
- // | $RCSfile: ticketview.php,v $
- // | $Date: 2004/02/10 01:34:31 $
- // | $Revision: 1.201 $
- // +-------------------------------------------------------------+
- // | File Details:
- // | - Ticket details and history viewer.
- // +-------------------------------------------------------------+
- error_reporting(E_ALL ^ E_NOTICE);
- // start file
- require("./../global.php");
- // globalise variables
- $global = array (
- array('id')
- );
- rg($global);
- if (!$id) {
- mistake("No ticket was specified");
- exit();
- }
- ############################### GET TICKET DATA ###############################
- $id = mysql_escape_string($id);
- $query = "
- SELECT
- ticket.*,
- tech.username AS techusername,
- ticket_cat.name AS catname,
- tech.id AS techid,
- ticket_pri.name AS priname,
- user.id AS userid,
- user.email AS email
- FROM ticket
- LEFT JOIN ticket_cat ON (ticket.category = ticket_cat.id)
- LEFT JOIN ticket_pri ON (ticket.priority = ticket_pri.id)
- LEFT JOIN user ON (ticket.userid = user.id)
- LEFT JOIN tech ON (ticket.tech = tech.id)
- ";
- $ticket = $db->query_return($query . " WHERE ticket.id = '$id'");
- if (!$db->num_rows()) {
- $ticket = $db->query_return($query . " WHERE ticket.ref = '$id'");
- if (is_array($ticket)) {
- $id = $ticket['id'];
- }
- }
- if (!$db->num_rows()) { // Try checking in ticket_merge too
- $ticket = $db->query_return("SELECT * FROM ticket_merge WHERE old_id = '$id'");
- if (!$db->num_rows()) {
- $ticket = $db->query_return("SELECT * FROM ticket_merge WHERE old_ref = '$id'");
- }
- }
- if ($ticket['new_id']) {
- $ticket = $db->query_return($query . " WHERE ticket.id = '$ticket[new_id]'");
- $id = $ticket['id'];
- }
- ############################### PERMISSIONS ###############################
- if (!$db->num_rows()) {
- mistake("Ticket Not Found. Either an invalid ID or REF ('$id') was specified, or the ticket has been deleted");
- }
- tech_nav('Tickets', 'View Ticket');
- if ($_REQUEST['do'] == 'delnote' AND $_REQUEST['noteid']) {
- if (p_ticket('edit')) {
- $note = $db->query_return("SELECT * FROM ticket_notes WHERE id = '$_REQUEST[noteid]'");
- ticketlog($id, 'note_deleted', 0, 0, $note['note'], NULL, NULL);
- $db->query("DELETE FROM ticket_notes WHERE techid = '$user[id]' AND id = '$_REQUEST[noteid]'");
- }
- }
- // permission to view
- if (!p_ticket('view')) {
- nopermission('to view this ticket');
- }
- // locked?
- if (($ticket[is_locked]) && ($ticket[lock_id] != $user[id])) {
- $lock_html = '<table cellpadding="3" cellspacing="0"><tr><td>' . html_image('tech/bul074.gif') . "</td><td><b>THIS TICKED IS CURRENTLY LOCKED</b></td><td>" . html_image('tech/bul074.gif') . "</td></tr></table><br /> (since " . our_date($ticket[date_locked]);
-
- if (p_ticket('edit')) {
- $lock_html .= "<br /><a href="ticketactions.php?do=unlock&id=$id"><b>Remove lock status</b></a></center>";
- } else {
- $lock_html .= "<br />You cannot make changes to this ticket until the technician assigned to it has unlocked it.</center>";
- }
-
- echo table_border($lock_html);
- }
- ############################### CACHE SOME DATA ###############################
- $techname[0] = 'Unassigned';
- $priority[0] = '';
- $category[0] = '';
- // techs
- $db->query("SELECT id, username FROM tech");
- while ($tech = $db->row_array()) {
- $techname[$tech[id]] = $tech['username'];
- $techlist[$tech[id]] = $tech['username']; // This list doesn't include "Unassigned"
- }
- // categories
- $db->query("SELECT id, name FROM ticket_cat");
- while ($cat = $db->row_array()) {
- $category[$cat[id]] = $cat[name];
- }
- // priorities
- $db->query("SELECT id, name FROM ticket_pri");
- while ($pri = $db->row_array()) {
- $priority[$pri[id]] = $pri[name];
- }
- #################### TECHNICIANS SAVED TICKETS ##########################
- $db->query("SELECT ticketid FROM tech_ticket_save WHERE techid = '$user[id]'");
- while ($save = $db->row_array()) {
- $saved[] = $save[ticketid];
- }
- ############################### TICKET ACTIONS ###############################
- if (p_ticket('edit')) {
- // lock
- if ($ticket[is_locked] != '1') {
- $top_links[] = jprompt(
- 'This will lock the ticket, preventing other techs from changing or replying to it.',
- "ticketactions.php?do=lock&id=$id",
- "Lock Ticket"
- ) . ' ' . thelp('Tickets - Viewing and Responding', 'Lock/Unlock Ticket');
- }
- if ($ticket[is_locked] == '1') {
- $top_links[] = jprompt(
- 'This will unlock the ticket, there may already be a tech working on this ticket',
- "ticketactions.php?do=unlock&id=$id",
- "Unlock Ticket"
- ) . ' ' . thelp('Tickets - Viewing and Responding', 'Lock/Unlock Ticket');
- }
- // awaiting user
- if ($ticket[awaiting_tech] == "1" AND $ticket[is_open] == "1") {
- $top_links[] = jprompt(
- "This will mark the ticket Awaiting User Response.",
- "ticketactions.php?do=awaiting_user&id=$id",
- "Mark Awaiting User Response"
- ) . ' ' . thelp('Tickets - Viewing and Responding', 'Awaiting Status');
- }
- // awaiting tech
- if ($ticket[awaiting_tech] == "0" AND $ticket[is_open] == "1") {
- $top_links[] = jprompt(
- "This will mark the ticket Awaiting Technician Response.",
- "ticketactions.php?do=awaiting_tech&id=$id",
- "Mark Awaiting Tech Response"
- ) . ' ' . thelp('Tickets - Viewing and Responding', 'Awaiting Status');
- }
- // remove ownership
- if ($ticket[tech] == $user[id]) {
- $top_links[] = jprompt(
- "This will remove your ownership and mark the ticket Unassigned.",
- "ticketactions.php?do=remove_ownership&id=$id",
- 'Remove Your Ownership'
- ) . ' ' . thelp('Tickets - Viewing and Responding', 'Ticket Ownership');
- // take ownership
- } elseif (p_ticket('edit')) {
- $top_links[] = "<a href="ticketactions.php?do=take_ownership&id=$id">Take Ticket Ownership</a>";
- }
- if ($ticket['nodisplay'] == 1) {
- $top_links[] = jprompt(
- 'This will mark the ticket as non-spam. It will appear in normal ticket lists.',
- "ticketactions.php?do=nospam&id=$id",
- 'Mark as Non-Spam'
- ) . ' ' . thelp('Tickets - Viewing and Responding', 'Handling "Spam"');
- } else {
- $top_links[] = jprompt(
- 'This will mark the ticket as spam. It will not appear in normal ticket lists (but you can still search for it in Ticket Search).',
- "ticketactions.php?do=spam&id=$id",
- 'Mark as Spam'
- ) . ' ' . thelp('Tickets - Viewing and Responding', 'Handling "Spam"');
- }
- }
- // delete
- if (p_ticket('delete')) {
- $top_links[] = jprompt(
- 'This will delete the ticket.',
- "ticketactions.php?do=delete&id=$id",
- "Delete Ticket"
- ) . ' ' . thelp('Tickets - Viewing and Responding', 'Deleting a Ticket');
- }
- // close // reopen
- if (p_ticket('close')) {
- if ($ticket[is_open] == "1") {
- $top_links[] = jprompt_multi(
- 'This will close the ticket.',
- 'Select [OK] to send an e-mail notification to the user, or [CANCEL] to close the ticket without mailing notification.',
- "ticketactions.php?do=close&id=$id&email=1",
- "ticketactions.php?do=close&id=$id",
- "Close"
- ) . ' ' . thelp('Tickets - Viewing and Responding', 'Closing a Ticket');
- } else {
- $top_links[] = jprompt_multi(
- 'This will re-open the ticket.',
- 'Select [OK] to send an e-mail notification to the user, or [CANCEL] to re-open the ticket without mailing notification.',
- "ticketactions.php?do=open&id=$id&email=1",
- "ticketactions.php?do=open&id=$id",
- "Re-open"
- ) . ' ' . thelp('Tickets - Viewing and Responding', 'Re-opening a Ticket');
- }
- }
- if (@in_array($id, $saved)) {
- $top_links[] = "<A HREF="ticketactions.php?do=unstore&id=$id">Remove Ticket from Saved Tickets</A>" . ' ' . thelp('Tickets - Viewing and Responding', 'Saving Tickets');
- } else {
- $top_links[] = "<A HREF="ticketactions.php?do=store&id=$id">Add Ticket to Saved Tickets</A> (<A HREF="javascript:openWindow('popupactions.php?do=store&id=$id', '', '')">pick cat</A>)" . ' ' . thelp('Tickets - Viewing and Responding', 'Saving Tickets');
- }
- if ($user['p_delete_users']) {
- $top_links[] = jprompt('This will prevent tickets being submitted by ' .
- htmlspecialchars($ticket['email']). '!',
- "ticketactions.php?id=$id&do=banmail&email=".urlencode($ticket['email']),
- 'Ban this e-mail address'
- ) . ' ' . thelp('Tickets - Viewing and Responding', 'Handling "Spam"');
- $top_links[] = jprompt('This will delete this user, all tickets created by this user, and ban the e-mail address ' .
- htmlspecialchars($ticket['email']) . '!',
- "ticketactions.php?id=$id&do=nuke",
- 'Ban user/delete user & tickets'
- ) . ' ' . thelp('Tickets - Viewing and Responding', 'Handling "Spam"');
- }
- foreach ($top_links AS $key => $var) {
- $top_links_html .= "<tr><td>" . html_image('tech/blue.gif', 4, 4) . "</td><td>$var</td></tr>";
- }
- $top_links = "<table cellpadding="2" cellspacing="0">$top_links_html</table>";
- ############################### TICKET STATUS ###############################
- $ticket_status = "<table>";
- // open / closed
- if ($ticket[is_open] == 1) {
- $message = 'Ticket is Open';
- } else {
- $message = 'Ticket is Closed';
- }
- $ticket_status .= "<tr><td>" . html_image('tech/bul070.gif') . '</td><td>' . table_thelp($message, 'Tickets - Viewing and Responding', 'Open/Closed') . '</td></tr>';
- // awaiting user/tech
- if ($ticket[awaiting_tech] == 1) {
- $message = 'Ticket is awaiting Tech';
- } else {
- $message = 'Ticket is awaiting User';
- }
- $ticket_status .= "<tr><td>" . html_image('tech/bul072.gif') . '</td><td>' . table_thelp($message, 'Tickets - Viewing and Responding', 'Awaiting Status') . '</td></tr>';
- // ticket locked
- if ($ticket[is_locked] == 1) {
- $ticket_status .= "<tr><td>" . html_image('tech/bul074.gif') . '</td><td>' . table_thelp('Ticket is Locked', 'Tickets - Viewing and Responding', 'Locked') . '</td></tr>';
- }
- // who is ticket owned by
- if ($ticket[tech] == $user[id]) {
- $message = 'Ticket is assigned to you';
- } elseif ($ticket[tech] == 0) {
- $message = "Ticket is unassigned";
- } else {
- $message = "Ticket is assigned to <a href="./../teamwork/techs.php">$ticket[techusername]</a>";
- }
- $ticket_status .= "<tr><td>" . html_image('tech/bul077.gif') . '</td><td>' . table_thelp($message, 'Tickets - Viewing and Responding', 'Ticket Ownership') . '</td></tr>';
- $ticket_status .= "</table>";
- ############################### TICKET FIELDS ###############################
- // Admin fields
- $fields = unserialize($user['fielddisplay']);
- $sql = array2sql($fields['admin']);
- if ($sql) {
- $db->query("SELECT * FROM ticket_fielddisplay WHERE id IN $sql");
- while ($fielddisplay = $db->row_array()) {
- $admincols[$fielddisplay['name']] = $fielddisplay['code'];
- }
- }
- // Calculate time-since-started and show it
- if ($ticket[is_open]) {
- $since_started = mktime() - $ticket[date_opened];
- } else {
- $since_started = $ticket[date_closed] - $ticket[date_opened];
- }
- $since_started = clean_time($since_started);
- // generic
- give_default($ticket['techusername'], '<i>Unassigned</i>');
- give_default($ticket['catname'], '<i>None</i>');
- give_default($ticket['priname'], '<i>None</i>');
- if ($ticket[is_open]) {
- $table_ticket_fields[] = array(table_thelp('<b>Time Since Opened</B>', 'Tickets - Viewing and Responding', 'Time Since Opened'), $since_started);
- if ((($ticket[date_lastreply] > $ticket[date_lastreply_tech]) OR !$ticket[date_lastreply_tech]) AND $ticket[awaiting_tech]) {
- if (!$ticket[date_awaiting_toggled]) {
- $tmp_time = mktime() - $ticket[date_opened];
- } else {
- $tmp_time = mktime() - $ticket[date_awaiting_toggled];
- }
- $table_ticket_fields[] = array(table_thelp('<b>Time Since User Response</b>', 'Tickets - Viewing and Responding', 'Time Since User Response'), clean_time($tmp_time));
- }
- } else {
- $table_ticket_fields[] = array(table_thelp('<b>Time to Close</B>', 'Tickets - Viewing and Responding', 'Time to Close'), $since_started);
- }
- $table_ticket_fields[] = array('<b>Ticket Subject</b>', $ticket['subject']);
- $table_ticket_fields[] = array('<b>Tech Owner</b>', $ticket['techusername']);
- $table_ticket_fields[] = array('<b>Category</b>', $ticket['catname']);
- $table_ticket_fields[] = array('<b>Priority</b>', $ticket['priname']);
- // custom fields
- $db->query("
- SELECT *
- FROM ticket_def
- WHERE tech_viewable
- ORDER by displayorder
- ");
- while ($ticket_data = $db->row_array()) {
- $ticket_data[display_name] = unserialize($ticket_data[display_name]);
- $ticket_data[display_name] = $ticket_data[display_name][$settings[default_language]];
- $ticket_data[description] = unserialize($ticket_data[description]);
- $ticket_data[description] = $ticket_data[description][$settings[default_language]];
- $ticket_custom[$ticket_data[name]] = field_display($ticket_data, $ticket[$ticket_data[name]], 1);
- // normal display
- if ($ticket[$ticket_data[name]]) {
- $table_ticket_fields[] = array("<B>$ticket_data[display_name]</B>", $ticket_custom[$ticket_data[name]]);
- }
- // edit display
- if ($ticket_data['tech_editable']) {
- $table_ticket_fields2[] = array("
- <b>$ticket_data[display_name]</b><br />$ticket_data[description]",
- field_def(
- $ticket_data,
- 'edit',
- '',
- '',
- $ticket[$ticket_data[name]])
- );
- } else {
- $table_ticket_fields2[] = array("
- <b>$ticket_data[display_name]</b><br />$ticket_data[description]",
- $ticket_custom[$ticket_data[name]]
- );
- }
- }
- ############################### EDIT FIELDS (displayed after a click) ###############################
- if (!(($ticket[tech] != $user[id]) && ($ticket[tech] != "0") && ($user[p_tech_edit] != "1"))) {
- $bit = form_input('subject', $ticket['subject']);
- $table_temp[] = array('<b>Subject</b>', $bit);
- $bit = form_select('category', $category, '', $ticket['category']);
- $table_temp[] = array("<b>Category</b>", $bit);
- $bit = form_select('priority', $priority, '', $ticket['priority']);
- $table_temp[] = array('<b>Priority</b>', $bit);
- $bit = form_select('tech', $techname, '', $ticket['techid']);
- if (!$ticket['awaiting_tech']) {
- $bit = "<table><tr><td>$bit</td><td>" . form_checkbox_single('awaiting_tech', 1, 1) . ' Mark ticket "Awaiting Tech Response"</td></tr></table>';
- }
- $table_temp[] = array('<b>Tech</b>', $bit);
- $table_ticket_fields2 = array_merge($table_temp, $table_ticket_fields2);
- }
- ############################### CALENDAR FUNCTIONS ###############################
- $table_calendar[0] .= "<table cellpadding="0" cellspacing="0"><tr>";
- $table_calendar[0] .= form_hidden('do', 'reminder');
- $table_calendar[0] .= form_hidden('id', $ticket[id]);
- $table_calendar[0] .= "<td><b>Remind</b> ";
- $table_calendar[0] .= form_select('tech', $techlist, NULL, $user['id']);
- $table_calendar[0] .= "<select name="days">
- <option value="1">1</option>
- <option value="7">7</option>
- <option value="14">14</option>
- <option value="21">21</option>
- <option value="28">28</option>
- </select>";
- $table_calendar[0] .= " <b>days</b> <input type="submit" name="remind1" value="Remind"> " . thelp('Tickets - Viewing and Responding', 'Remind After Interval');
- $table_calendar[0] .= "</td></tr>";
- $table_calendar[0] .= "</table>";
- $table_calendar[1] .= "<table cellpadding="0" cellspacing="0"><tr>";
- $table_calendar[1] .= "<td><b>Remind</b> ";
- $table_calendar[1] .= form_select('tech2', $techlist, NULL, $user['id']);
- $table_calendar[1] .= form_date('date', '', '', '1');
- $table_calendar[1] .= " <input type="submit" name="remind2" value="Remind"> " . thelp('Tickets - Viewing and Responding', 'Remind On Date');
- $table_calendar[1] .= "</td></tr>";
- $table_calendar[1] .= "</table>";
- $watches = $db->query_return_array("SELECT * FROM tech_ticket_watch WHERE ticketid = '$id' AND techid = '$user[id]'");
- if (is_array($watches)) {
- $table_calendar[2] = table_midheader('Reminders');
- $table_calendar[3] .= "<TABLE><TR>
- <TD ALIGN="center"><B>Added</B></TD><TD> </TD>
- <TD ALIGN="center"><B>Due</B></TD><TD> </TD>
- <TD ALIGN="center"><B>Done?</B></TD></TR>";
- foreach ($watches AS $watch) {
- $watch['datetodo_exp'] = explode('-', $watch['datetodo']);
- $link = "<A HREF="ticketedit.php?do=remindertoggle&id=$id&watchid=$watch[id]">";
- $table_calendar[3] .= "<TR><TD>" . our_date($watch['created']) . "</TD><TD> </TD><TD>"
- . our_date(strtotime($watch['datetodo'])) . "</TD><TD> </TD><TD>" .
- iff($watch['completed'], "$link Yes</A>", "$link No</A>") . "</TD></TR>";
- }
- $table_calendar[3] .= "</TABLE>";
- }
- ############################### PAYMENT FUNCTIONS ################################
- $table_payment[] .= "<input type="hidden" name="id" value="$id"><input type="hidden" name="do" value="charge">Charge this user: <input type="text" name="charge" size="5" value="0.00"> <input type="submit" name="charge1" value="Charge"> " . thelp('Tickets - Viewing and Responding', 'Charge Amount');
- $table_payment[] .= "<input type="hidden" name="id" value="$id"><input type="hidden" name="userid" value="$ticket[userid]">Add time charge: <input type="text" name="hours" size="2"> h <input type="text" name="minutes" size="2"> m <input type="text" name="seconds" size="2"> s <input type="submit" name="charge2" value="Charge"> " . thelp('Tickets - Viewing and Responding', 'Charge Time');
- $table_payment[] .= "<input type="button" name="remind1" value="Start Timer" onClick="timer_Start(); return true"> <input type="button" name="remind1" value="Stop Timer" onClick="timer_Stop();"> <input type="button" name="remind1" value="Stop/Reset Timer" onClick="timer_Reset(); timer_Stop(); return true;"> " . thelp('Tickets - Viewing and Responding', 'Timer');
- ############################### BILLING DETAILS ################################
- $db->query("SELECT user_bill.*, tech.username AS techname
- FROM user_bill
- LEFT JOIN tech ON tech.id = user_bill.techid
- WHERE ticketid = '$ticket[id]'
- ORDER BY stamp");
- $help = thelp('Tickets - Viewing and Responding', 'Billing Details and Actions');
- $table_billing_cols = array('Billing Tech', 'Time', 'Charge', "Paid $help", "Billable $help", 'Date', "Delete $help");
- while ($bill = $db->row_array()) {
- if ($bill['paid']) {
- $bill['paid'] = "<A HREF="ticketedit.php?do=updatebillingpaid&id=$id&billid=$bill[id]&paid=0">Y</A>";
- } else {
- $bill['paid'] = "<A HREF="ticketedit.php?do=updatebillingpaid&id=$id&billid=$bill[id]&paid=1">N</A>";
- }
- if ($bill['billable']) {
- $bill['billable'] = "<A HREF="ticketedit.php?do=updatebillingbillable&id=$id&billid=$bill[id]&billable=0">Y</A>";
- } else {
- $bill['billable'] = "<A HREF="ticketedit.php?do=updatebillingbillable&id=$id&billid=$bill[id]&billable=1">N</A>";
- }
- $table_billing[] = array(
- $bill['techname'],
- clean_time($bill['time']),
- number_format($bill['charge'], 2),
- $bill['paid'],
- $bill['billable'],
- our_date($bill['stamp']),
- "<A HREF="ticketedit.php?do=deletebilling&id=$id&billid=$bill[id]">Delete</A>"
- );
- }
- if (!count($table_billing)) {
- $table_billing[] = array('No billing events.');
- $billing = 0;
- } else {
- $billing = 1;
- }
- ############################### USER DATA ###############################
- $banned = unserialize(get_data('email_ban'));
- if (@in_array($ticket['email'], $banned)) {
- $banned = ' <I>Banned</I>';
- } else {
- $banned = '';
- }
- $ticket_user = $db->query_return("SELECT * FROM user WHERE id = '$ticket[userid]'");
- if (!$ticket_user['email']) {
- $ticket_user['email'] = '<I>None</I>';
- } else {
- $ticket_user['email'] = "<A HREF="mailto:$ticket_user[email]">$ticket_user[email]</A>";
- }
- $table_user[] = array("<b>Name:</b>", iff($ticket_user[name], $ticket_username['name'], 'n/a'));
- $table_user[] = array("<b>Username</b>", $ticket_user['username'] . " <A HREF="newticket.php?oldusername=$ticket_user[username]">(new ticket)</A>");
- $table_user[] = array("<b>Email</b>", "$ticket_user[email] $banned");
- if ($ticket_user['autoresponds']) {
- $autoresp = "<A HREF="ticketactions.php?do=autoresp&id=$id&userid=$ticket_user[id]&val=0"><B>Yes</B></A>";
- } else {
- $autoresp = "<A HREF="ticketactions.php?do=autoresp&id=$id&userid=$ticket_user[id]&val=1">No</A>";
- }
- $table_user[] = array(table_thelp('<B>Autoresponds?</B>', 'Users', 'Edit: Has Autoresponder?'), $autoresp);
- $db->query("
- SELECT * FROM user_def WHERE tech_viewable ORDER by displayorder
- ");
- while ($user_data = $db->row_array()) {
-
- $user_data['display_name'] = unserialize($user_data[display_name]);
- $user_data['display_name'] = $user_data[display_name][$settings[default_language]];
-
- $table_user[] = array("<B>$user_data[display_name]</B>", field_display($user_data, $ticket_user[$user_data['name']]));
- }
- ############################### ADMIN FIELDS ###############################
- if (is_array($admincols)) {
- foreach($admincols AS $name => $val) {
- $val = addslashes($val);
- eval("$val = "$val";");
- $table_ticket_fields[] = array("<B>$name</B>", $val);
- }
- }
- ############################### USER TICKETS ###############################
- if ($_REQUEST['do'] == 'viewall') {
- $term = '';
- } else {
- $term = 'LIMIT 0,10';
- }
- $db->query("
- SELECT id,subject,is_open,awaiting_tech
- FROM ticket
- WHERE userid = '$ticket[userid]'
- AND id != '$ticket[id]'
- ORDER BY is_open desc, awaiting_tech desc, date_lastreply $term
- ");
- while ($user_tickets = $db->row_array()) {
- if ($user_tickets[is_open]) {
- $isopen = "Open";
- } else {
- $isopen = "Closed";
- }
- $table_user_tickets[] = array(
- "<a href="ticketview.php?id=$user_tickets[id]">$user_tickets[subject]</a>",
- $isopen,
- iff($user_tickets['awaiting_tech'], 'Tech', 'User'),
- jprompt("This will merge ticket #$user_tickets[id] into the ticket being viewed (#$ticket[id]).\n Note that any fields set for ticket #$user_tickets[id] will be lost if you proceed.",
- "ticketactions.php?do=merge&fromticket=$user_tickets[id]&toticket=$ticket[id]",
- 'Merge'
- )
- );
- }
- if ($_REQUEST['do'] == 'viewall') {
- $table_user_tickets_header = "Showing user's $count[total] other ticket(s)";
- $table_user_tickets_footer = redirect_button('Show only recent tickets', "./../tickets/ticketview.php?id=$ticket[id]");
-
- } else {
- // need to get total
- $count = $db->query_return("
- SELECT COUNT(*) AS total
- FROM ticket
- WHERE userid = '$ticket[userid]'
- AND id != '$ticket[id]'
- ");
- if ($count[total] > 10) {
- $table_user_tickets_header = "Showing last 10 of $count[total] other tickets";
- $table_user_tickets_footer = redirect_button('Show all tickets', "./../tickets/ticketview.php?do=viewall&id=$ticket[id]");
- } else {
- $table_user_tickets_header = "Showing user's $count[total] other ticket(s)";
- $table_user_tickets_footer = '';
- }
- }
- ############################### ATTACHMENTS ###############################
- $db->query("SELECT filesize, id, filename FROM ticket_attachments WHERE ticketid = '$id'");
- if ($db->num_rows() > 0) {
-
- $is_attachment = 1;
- $cols = array(
- 'Name',
- 'Size',
- 'Uploaded By',
- 'Download',
- 'Delete'
- );
-
- while ($attachment = $db->row_array()) {
- $attachment['filesize'] = number_format($attachment[filesize] / 1024, 2);
- $table_attachments[] = array(
- $attachment['filename'],
- $attachment['filesize'] . " kb",
- "<a href="attachment.php?id=$attachment[id]">download</a>",
- jprompt(
- 'This will delete the attachment.',
- "attachment.php?do=delete&id=$attachment[id]",
- "Delete"
- )
- );
- }
- }
- ############################### MESSAGES ###############################
- function quotemessage($message) {
- $message = preg_replace("/(rn|n|r)/", "n> ", $message);
- $message = addslashes_js($message);
- $message = '\r\n> ' . $message;
- return $message;
- }
- $table_messages[0] = '';
- $table_message_count = 0;
- $total_messages = $db->query_return("SELECT count(*) AS total FROM ticket_message WHERE ticketid = '$id'");
- $total_messages = $total_messages['total'];
- if ($_REQUEST[messages] == 'all') {
- $table_message_start = 0;
- $limit = '';
- } else {
- $table_message_start = $total_messages - 10;
- if ($table_message_start < 0) {
- $table_message_start = 0;
- }
- $limit = "LIMIT $table_message_start,10";
- }
- $db->query("
- SELECT ticket_message.*, tech.username AS t_username, user.username AS u_username
- FROM ticket_message
- LEFT JOIN tech ON ticket_message.techid = tech.id
- LEFT JOIN user ON ticket_message.userid = user.id
- WHERE ticket_message.ticketid = '$id'
- ORDER by ticket_message.date
- $limit
- ");
- $timerjs = "
- <script language="JavaScript">
- var timerID = 0;
- var tStart = null;
- function timer_UpdateTimer() {
- if(timerID) {
- clearTimeout(timerID);
- timerID = 0;
- }
- if(!tStart) {
- tStart = new Date();
- }
- var tDate = new Date();
- var tDiff = (tDate.getTime() - tStart.getTime()) + 1000;
- tDiff = tDiff / 1000;
- var tHours = parseInt(tDiff / 3600);
- tDiff = tDiff - (tHours * 3600);
- var tMinutes = parseInt(tDiff / 60);
- tDiff = tDiff - (tMinutes * 60);
- var tSeconds = parseInt(tDiff);
-
- document.payment.hours.value = tHours;
- document.payment.minutes.value = tMinutes;
- document.payment.seconds.value = tSeconds;
- timerID = setTimeout("timer_UpdateTimer()", 1000);
- }
- function validate() {
- if (document.dpreply.reply.value == '') {
- alert('Please enter a message.');
- return false;
- } else {
- return true;
- }
- }
- function timer_Start() {
- tStart = new Date();
- document.payment.hours.value = "0";
- document.payment.minutes.value = "0";
- document.payment.seconds.value = "0";
- timerID = setTimeout("timer_UpdateTimer()", 1000);
- }
- function timer_Stop() {
- if(timerID) {
- clearTimeout(timerID);
- timerID = 0;
- }
- tStart = null;
- }
- function timer_Reset() {
- tStart = null;
- document.payment.hours.value = "0";
- document.payment.minutes.value = "0";
- document.payment.seconds.value = "0";
- }
- timer_Stop();
- </script>
- ";
- $js = "
- <SCRIPT LANGUAGE="JavaScript">
- function quote(id) {
- var data = new Array();
- ";
- $i = $table_message_start;
- while ($reply = $db->row_array()) {
- $reply['message'] = wordwrap(trim($reply['message']), 78, "n");
- $i++;
- $js .= "data[$reply[id]] = "" . quotemessage($reply[message]) . "";
- ";
-
- // just in case two messages on same second
- if (@in_array($reply[date], $time_array)) {
- $reply[date]++;
- }
- $time_array[] = $reply[date];
-
- $date = our_date($reply[date]);
- if ($reply['techid']) {
- $reply['username'] = $reply['t_username'];
- $by = "<b>$reply[username] (tech) </b>";
- } elseif ($reply['userid']) {
- $reply['username'] = $reply['u_username'];
- $by = "<b>$ticket[email] </b>";
- if ($reply['ipaddress']) {
- $by .= " [ip address = $reply[ipaddress]] ";
- } elseif ($reply['sourceid']) {
- $by .= " [sent by email] ";
- } else {
- $by .= " [entered by technician]";
- }
- } else {
- $by = "<b>System (DeskPRO)</b>";
- }
-
- $bit = "<table width="100%" cellpadding="0" cellspacing="0">";
- $bit .= "<tr><td><table width="100%" cellspacing="0" cellpadding="0"><a name="$i"/><tr><td><U><b>#$i</b> Message by $by on $date</U></td><td align="right">";
-
- $bit .= "<table cellpadding="2" cellspacing="0"><tr><td valign="middle">" . html_image('tech/bul087.gif') . "</td><td valign="middle"><a href="javascript:openWindow('popupactions.php?do=raw&id=$reply[id]', '', '')">View Raw</a></td>";
- // quote
- $bit .= "<td valign="middle">" . html_image('tech/bul106.gif') . "</td><td valign="middle"><a href="javascript:quote('$reply[id]')">Quote</a></td>";
-
- // edit
- $bit .= "<td valign="middle">" . html_image('tech/bul108.gif') . "</td><td valign="middle"><a href="javascript:openWindow('popupactions.php?do=editmessage&id=$reply[id]&num=$i', '', '')">Edit Message</a></td>";
-
- if ($reply[sourceid]) {
- $bit .= "<td valign="middle">" . html_image('tech/bul109.gif') . "</td><td valign="middle"><a href="JavaScript:openWindow('popupactions.php?do=view_source&id=$reply[id]', '', '')">View Email Source</a></td>";
- }
-
- $bit .= "</td></tr></table></td></tr></table></td></tr>";
- $bit .= "<tr><td colspan="2"><div name="reply_$reply[id]">" . dp_code($reply['message']) . "</div></td></tr></table>";
- $table_messages[$reply[date]] = $bit;
- $table_message_count++;
- }
- $table_message_start++;
- if ($_REQUEST[messages] == 'all') {
- if ($table_message_count) {
- $message_total = "($total_messages total)";
- } else {
- $message_total = "(no messages)";
- }
- $table_messages[0] = "<center>Showing all messages $message_total.
- <A HREF="ticketview.php?id=$id">Show Newest</A>.</center>";
- } else {
- if ($table_message_count) {
- if ((($table_message_count - 1) + $table_message_start) == 1) {
- $message_total = "(1 message total)";
- } else {
- $message_total = "(#$table_message_start to #$i; $total_messages messages total)";
- }
- } else {
- $message_total = "(no messages)";
- }
- if ($total_messages > 10) {
- $table_messages[0] = "<center>Showing up to the last 10 messages $message_total.
- <a href="ticketview.php?id=$id&messages=all">Show All</a>.";
- } else {
- $table_messages[0] = "<center>Showing $table_message_count message(s) $message_total.</center>";
- }
- }
- $js .= "
- top.center.document.dpreply.reply.value += data[id] + ' ';
- top.center.document.dpreply.reply.focus();
- }
- </script>
- ";
- echo $js;
- ############################### TICKET NOTES ###############################
- $db->query("
- SELECT ticket_notes.*, tech.username
- FROM ticket_notes
- LEFT JOIN tech ON ticket_notes.techid = tech.id
- WHERE ticket_notes.ticketid = '$id'
- ORDER BY id
- ");
- while ($result = $db->row_array()) {
- if (!$result['username']) {
- $result['username'] = 'system';
- }
- $table_notes[] = array(our_date($result['date']) . iff(($result['techid'] == $user['id']),
- " <A HREF="ticketview.php?do=delnote&id=$id¬eid=$result[id]">Delete</A>"), $result['username']);
- $table_notes_message[] = $result[note];
- // in case message and note same second
- if (@in_array($result['date'], $time_array)) {
- $result['date']++;
- }
- $bit = "<U>Note by <B>$result[username]</B> (" . our_date($result['date']) . ")</U><BR>" . dp_code($result['note']);
- while (@in_array($result['date'], $time_array)) {
- $result['date']++;
- }
-
- $table_messages[$result['date']] = $bit;
- }
- ksort($table_messages);
- ############################### REPLY FORM ###############################
- ?>
- <script language="javascript">
- function isnote() {
- var yesno;
-
- if (document.dpreply.is_note.checked == true) {
- yesno = 1;
- }
- if (yesno == '1') {
- document.dpreply.emailuser.checked = false;
- document.dpreply.emailuser.disabled = true;
- document.dpreply.makefaq.checked = false;
- document.dpreply.makefaq.disabled = true;
- document.dpreply.close.checked = false;
- document.dpreply.close.disabled = true;
- document.dpreply.awaitinguser.checked = false;
- document.dpreply.awaitinguser.disabled = true;
- } else {
- document.dpreply.emailuser.disabled = false;
- document.dpreply.makefaq.disabled = false;
- document.dpreply.close.disabled = false;
- document.dpreply.awaitinguser.disabled = false;
- }
- }
- </script>
- <?php
-
- if ($user['signature']) {
- $user['signature'] = "nn--n$user[signature]";
- }
- $help = thelp('Tickets - Viewing and Responding', 'Reply Actions and Options');
- $table_reply[] = "
- <table cellpadding="3" width="00%" cellspacing="1"><tr valign="top">
- <td valign="top"><br />
- <table cellpadding="2" cellspacing="0">
- <tr><td align="center">" . html_image('tech/bul098.gif') . "</td><td><a href="javascript:openWindow('./faqpop.php', 700, 600, 'faq')">FAQ</a></td></tr>
- <tr><td align="center"><br />" . html_image('tech/bul087.gif') . "</td><td><br /><a href="javascript:openWindow('./popupactions.php?do=largeedit', 700, 600, 'big')">Large Edit</a></td></tr>
- <tr><td align="center"><br />" . html_image('tech/bul099.gif') . "</td><td><br />
- <DIV ID="newattachments">
- <a href="javascript:openWindow('./addattachments.php?id=$ticket[id]', 350, 300, 'attachment')">Add Attach</a>
- </DIV></td></tr></table>
- </td><td>" .
-
- form_hidden('viewed', mktime()) . "
- <TEXTAREA NAME="reply" ROWS="10" COLS="70"
- ONSELECT="top.empty.storeCaret(this);"
- ONCLICK="top.empty.storeCaret(this);"
- ONKEYUP="top.empty.storeCaret(this);">$user[signature]
- </TEXTAREA>
-
- </td><td><br />".
- form_checkbox_single('mail_cc', 'cc', 0) . " Cc: only this reply <BR>" .
- form_checkbox_single('mail_digest', 'digest', 0) . " Mail a digest of this ticket <BR>" .
- '<table><tr><td>To:</td><td>'. form_input('cc', NULL, '20') . '</td></tr><td colspan="2"><br></td></tr></table>
- <center>'.thelp('Tickets - Viewing and Responding', "Cc's and Digests") . '</center>
- </td><td rowspan="2"><center>
- <select name="drop" style="width:150" onchange="top.empty.showdata(dpreply.drop.value)"></select><br /><br />
- <select size="10" name="list3" style="width:150"></select>
- <input type="hidden" name="category" value="1"><br /><br />
- <input type="button" onClick="top.empty.godeep(dpreply.list3.value,dpreply.category.value)" value="Insert into Reply"><br /><br />
- ' . thelp('Quick Replies', 'Inserting into Tickets') . '
- </center></td></tr>
- <tr>
- <td><center>'.$help.'</center></td>
- <td colspan="2">
- <table><tr>' . "
- <td>" . form_checkbox_single('makefaq', '1', '') . " Create FAQ article from this ticket</td>
- <td>" . form_checkbox_single('close', '1', '') . " Close the ticket</td></tr><tr>
- <td>" . form_checkbox_single('emailuser', '1', '1') . " E-mail this reply to the user</td>
- <td>" . form_checkbox_single('awaitinguser', '1', '1') . " Set 'awaiting a user response'</td></tr><tr>
- <td><input type="checkbox" name="is_note" value="1" onclick="javascript:isnote()"> Message is a note (hidden from users)</td>
- <td>" .
- iff ($ticket[tech] != $user[id], form_checkbox_single('ownership', 1, 1) . " Claim ownership of this ticket") . "</td></tr>" .
- iff ($settings['autostart_billing_timer'] AND feature_check('payments', 1) AND $settings['payments'], "<tr><td colspan="2">" . form_checkbox_single('ignorebilling', 1) . " Don't automatically apply billing timer to the ticket for this response.</td></tr>") . "
- </table></td></tr></table>" .
- form_hidden('charge', '') .
- form_hidden('hours', '') .
- form_hidden('minutes', '') .
- form_hidden('seconds', '') .
- form_hidden('userid', $ticket['userid']);
- ############################### DISPLAY PAGE ###############################
- echo "<table width="100%"><tr><td valign="top"><form method="post" action="ticketedit.php">" . form_hidden('id', $id);
- $ticket_title = "(Ticket ID: $id, Ticket REF: $ticket[ref])";
- table_header("Ticket Information $ticket_title");
- table_content('', $table_ticket_fields);
- if (p_ticket('edit')) {
- table_footer('', '', "<input type="button" value="Edit Ticket Data" onclick="oc('Ticket Information $ticket_title'); oc('Edit Fields $ticket_title'); return true">", 1);
- } else {
- table_footer();
- }
- if (p_ticket('edit')) {
-
- echo form_hidden('searchid', $_REQUEST['searchid']);
- echo form_hidden('num', $_REQUEST['num']);
- table_header("Edit Fields $ticket_title");
- table_content('', $table_ticket_fields2);
- table_footer('', '', "<input type="submit" name="Update Fields" value="Update Fields">" . " <input type="button" value="View Ticket Fields" onclick="oc('Ticket Information $ticket_title'); oc('Edit Fields $ticket_title'); return true">", 1);
- echo "<SCRIPT>oc('Edit Fields $ticket_title');</SCRIPT>";
- }
- echo "<br />";
- table_header("Ticket Owner Details (User ID: $ticket_user[id])");
- table_content('', $table_user);
- if ($ticket['userid']) {
- table_footer('', '', redirect_button('View / Edit User', "./../users/view.php?id=$ticket_user[id]"));
- }
- echo "<br />";
- echo "</td></form><td valign="top" align="right">";
- outline_table('Ticket Status', $ticket_status, '95%');
- echo "<br />";
- outline_table('Ticket Operations', $top_links, '95%');
- echo "</td></tr></table>";
- table_header($table_user_tickets_header);
- if (is_array($table_user_tickets)) {
- table_content(array('Ticket Subject', 'Status', 'Awaiting','Merge ' . thelp('Tickets - Viewing and Responding', 'Merging Tickets')), $table_user_tickets);
- } else {
- table_content('', array('User has no other tickets.'));
- }
- table_footer('', '', $table_user_tickets_footer);
- echo "<table width="100%"><tr><td valign="top">";
- table_header('Ticket Notes');
- table_content(array('Date Written', 'Tech Writer'), $table_notes, '', '', '', $table_notes_message);
- table_footer('', '', form_button('Add New Note', "onclick="openWindow('./popupactions.php?do=note&id=$ticket[id]', 450, 300, 'attachment')""));
- echo "</td><td valign="top">";
- table_header('Ticket Attachments');
- table_content(array('Filename', 'Size', 'Download', 'Delete'), $table_attachments);
- table_footer('', '', form_button('Add New Attachment(s)', "onclick="openWindow('./addattachments.php?id=$ticket[id]', 350, 300, 'attachment')""));
- echo "</td></tr></table>";
- echo "<table width="100%"><tr>";
- if ($settings['payments'] AND feature_check('payments', 1)) {
- echo "<form method="post" action="ticketedit.php" name="payment" id="payment"><td valign="top">";
- table_header('Payment Functions', '', '', !$settings['autostart_billing_timer']);
- table_content('', $table_payment, '', '');
- table_footer();
- }
- echo $timerjs;
- echo "</td></form><form method="post" action="ticketedit.php" name="calendar" id="calendar"><td valign="top">";
- if (count($table_calendar) > 2) {
- table_header('Calendar Functions', '', '', 0);
- table_content('', $table_calendar);
- table_footer();
- } else {
- table_header('Calendar Functions', '', '', 1);
- table_content('', $table_calendar);
- table_footer();
- }
- echo "</td></form><td valign="top">";
- echo "</td></tr></table>";
- if ($settings['payments'] AND feature_check('payments', 1)) {
- table_header(iff($billing, 'Billing Details', 'Billing Details (no items)'), '', '', (!$billing));
- table_content($table_billing_cols, $table_billing);
- table_footer();
- $copybilling = "copyBilling();";
- } else {
- $copybilling = NULL;
- }
- table_header('Ticket Messages');
- table_content('', $table_messages);
- table_footer();
- if (p_ticket('edit') AND $ticket['is_open']) {
- table_header("Reply to Ticket (#$ticket[id], Ref #$ticket[ref])", 'ticketreply.php', array('do' => 'reply', 'id' => $id, 'searchid' => $_REQUEST['searchid'], 'num' => $_REQUEST['num']), '', 'dpreply', 1);
- table_content('', $table_reply);
- table_footer('Send Reply', '', spellcheck_button('dpreply', 'reply'), '', iff($user['copy_to_clipboard'], "onClick="copyText(document.dpreply.reply); $copybilling; return validate();"", NULL), 'Submit');
- }
- $ticketlog_data = generate_ticketlog($id);
- $cols = array('Date', 'Action', 'Tech/User');
- table_header('Ticket Log', '', '', '');
- table_content($cols, $ticketlog_data[0], '', '', '', $ticketlog_data[1]);
- table_footer();
- ############################### END PAGE ###############################
- if ($settings['autostart_billing_timer'] AND $settings['payments'] AND feature_check('payments', 1)) {
- ?>
- <SCRIPT language="JavaScript">
- timer_Start();
- </SCRIPT>
- <?php
- }
- if ($ticket['is_open'] AND p_ticket('edit')) {
- ?>
- <SCRIPT language="javascript">
- top.empty.buildselect();
- top.empty.showdata('0');
- function copyText(text) {
- var agt=navigator.userAgent.toLowerCase();
- var is_ie = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
- if (is_ie) {
- copied = text.createTextRange();
- copied.execCommand("Copy");
- }
- }
- function copyBilling() {
- document.dpreply.charge.value = document.payment.charge.value;
- document.dpreply.hours.value = document.payment.hours.value;
- document.dpreply.minutes.value = document.payment.minutes.value;
- document.dpreply.seconds.value = document.payment.seconds.value;
- }
- </SCRIPT>
- <?php
- };
- tech_footer();
- ?>