Skip to content
Snippets Groups Projects
ticket-view.inc.php 59.3 KiB
Newer Older
  • Learn to ignore specific revisions
  • <?php
    //Note that ticket obj is initiated in tickets.php.
    if(!defined('OSTSCPINC') || !$thisstaff || !is_object($ticket) || !$ticket->getId()) die('Invalid path');
    
    //Make sure the staff is allowed to access the page.
    
    if(!@$thisstaff->isStaff() || !$ticket->checkStaffPerm($thisstaff)) die('Access Denied');
    
    
    //Re-use the post info on error...savekeyboards.org (Why keyboard? -> some people care about objects than users!!)
    $info=($_POST && $errors)?Format::input($_POST):array();
    
    //Get the goodies.
    $dept  = $ticket->getDept();  //Dept
    
    $role  = $ticket->getRole($thisstaff);
    
    $staff = $ticket->getStaff(); //Assigned or closed by..
    
    Peter Rotich's avatar
    Peter Rotich committed
    $user  = $ticket->getOwner(); //Ticket User (EndUser)
    
    $team  = $ticket->getTeam();  //Assigned team.
    
    $sla   = $ticket->getSLA();
    
    $lock  = $ticket->getLock();  //Ticket lock obj
    
    if (!$lock && $cfg->getTicketLockMode() == Lock::MODE_ON_VIEW)
        $lock = $ticket->acquireLock($thisstaff->getId());
    
    $mylock = ($lock && $lock->getStaffId() == $thisstaff->getId()) ? $lock : null;
    
    $id    = $ticket->getId();    //Ticket ID.
    
    //Useful warnings and errors the user might want to know!
    
    if ($ticket->isClosed() && !$ticket->isReopenable())
        $warn = sprintf(
                __('Current ticket status (%s) does not allow the end user to reply.'),
                $ticket->getStatus());
    elseif ($ticket->isAssigned()
            && (($staff && $staff->getId()!=$thisstaff->getId())
                || ($team && !$team->hasMember($thisstaff))
    
    Peter Rotich's avatar
    Peter Rotich committed
        $warn.= sprintf('&nbsp;&nbsp;<span class="Icon assignedTicket">%s</span>',
    
                sprintf(__('Ticket is assigned to %s'),
                    implode('/', $ticket->getAssignees())
                    ));
    
    if (!$errors['err']) {
    
        if ($lock && $lock->getStaffId()!=$thisstaff->getId())
    
            $errors['err'] = sprintf(__('%s is currently locked by %s'),
                    __('This ticket'),
    
                    $lock->getStaffName());
    
        elseif (($emailBanned=Banlist::isBanned($ticket->getEmail())))
    
            $errors['err'] = __('Email is in banlist! Must be removed before any reply/response');
    
        elseif (!Validator::is_valid_email($ticket->getEmail()))
            $errors['err'] = __('EndUser email address is not valid! Consider updating it before responding');
    
    
    $unbannable=($emailBanned) ? BanList::includes($ticket->getEmail()) : false;
    
    if($ticket->isOverdue())
    
        $warn.='&nbsp;&nbsp;<span class="Icon overdueTicket">'.__('Marked overdue!').'</span>';
    
        <div class="sticky bar">
           <div class="content">
            <div class="pull-right flush-right">
    
                if ($thisstaff->hasPerm(Email::PERM_BANLIST)
    
                        || $role->hasPerm(Ticket::PERM_EDIT)
    
                        || ($dept && $dept->isManager($thisstaff))) { ?>
    
                <span class="action-button pull-right" data-placement="bottom" data-dropdown="#action-dropdown-more" data-toggle="tooltip" title="<?php echo __('More');?>">
    
                    <i class="icon-caret-down pull-right"></i>
    
                    <span ><i class="icon-cog"></i></span>
    
                if ($role->hasPerm(Ticket::PERM_EDIT)) { ?>
    
                    <span class="action-button pull-right"><a data-placement="bottom" data-toggle="tooltip" title="<?php echo __('Edit'); ?>" href="tickets.php?id=<?php echo $ticket->getId(); ?>&a=edit"><i class="icon-edit"></i></a></span>
    
    Peter Rotich's avatar
    Peter Rotich committed
                } ?>
    
                <span class="action-button pull-right" data-placement="bottom" data-dropdown="#action-dropdown-print" data-toggle="tooltip" title="<?php echo __('Print'); ?>">
                    <i class="icon-caret-down pull-right"></i>
                    <a id="ticket-print" href="tickets.php?id=<?php echo $ticket->getId(); ?>&a=print"><i class="icon-print"></i></a>
                </span>
                <div id="action-dropdown-print" class="action-dropdown anchor-right">
                  <ul>
                     <li><a class="no-pjax" target="_blank" href="tickets.php?id=<?php echo $ticket->getId(); ?>&a=print&notes=0"><i
                     class="icon-file-alt"></i> <?php echo __('Ticket Thread'); ?></a>
                     <li><a class="no-pjax" target="_blank" href="tickets.php?id=<?php echo $ticket->getId(); ?>&a=print&notes=1"><i
                     class="icon-file-text-alt"></i> <?php echo __('Thread + Internal Notes'); ?></a>
                  </ul>
                </div>
    
    Peter Rotich's avatar
    Peter Rotich committed
                <?php
                // Transfer
    
                if ($role->hasPerm(Ticket::PERM_TRANSFER)) {?>
    
                <span class="action-button pull-right">
                <a class="ticket-action" id="ticket-transfer" data-placement="bottom" data-toggle="tooltip" title="<?php echo __('Transfer'); ?>"
    
                    data-redirect="tickets.php"
    
                    href="#tickets/<?php echo $ticket->getId(); ?>/transfer"><i class="icon-share"></i></a>
                </span>
    
    Peter Rotich's avatar
    Peter Rotich committed
                <?php
                } ?>
    
    Peter Rotich's avatar
    Peter Rotich committed
                // Assign
    
                if ($ticket->isOpen() && $role->hasPerm(Ticket::PERM_ASSIGN)) {?>
    
                <span class="action-button pull-right"
                    data-dropdown="#action-dropdown-assign"
                    data-placement="bottom"
                    data-toggle="tooltip"
    
                    title=" <?php echo $ticket->isAssigned() ? __('Assign') : __('Reassign'); ?>"
    
    Peter Rotich's avatar
    Peter Rotich committed
                    <i class="icon-caret-down pull-right"></i>
    
                    <a class="ticket-action" id="ticket-assign"
                        data-redirect="tickets.php"
    
                        href="#tickets/<?php echo $ticket->getId(); ?>/assign"><i class="icon-user"></i></a>
    
    Peter Rotich's avatar
    Peter Rotich committed
                </span>
                <div id="action-dropdown-assign" class="action-dropdown anchor-right">
                  <ul>
    
    Peter Rotich's avatar
    Peter Rotich committed
                    <?php
                    // Agent can claim team assigned ticket
    
                    if (!$ticket->getStaff()
                            && (!$dept->assignMembersOnly()
                                || $dept->isMember($thisstaff))
                            ) { ?>
    
                     <li><a class="no-pjax ticket-action"
                        data-redirect="tickets.php"
    
    Peter Rotich's avatar
    Peter Rotich committed
                        href="#tickets/<?php echo $ticket->getId(); ?>/claim"><i
    
    Peter Rotich's avatar
    Peter Rotich committed
                        class="icon-chevron-sign-down"></i> <?php echo __('Claim'); ?></a>
    
    Peter Rotich's avatar
    Peter Rotich committed
                    <?php
                    } ?>
    
                     <li><a class="no-pjax ticket-action"
                        data-redirect="tickets.php"
                        href="#tickets/<?php echo $ticket->getId(); ?>/assign/agents"><i
    
    Peter Rotich's avatar
    Peter Rotich committed
                        class="icon-user"></i> <?php echo __('Agent'); ?></a>
    
                     <li><a class="no-pjax ticket-action"
                        data-redirect="tickets.php"
                        href="#tickets/<?php echo $ticket->getId(); ?>/assign/teams"><i
    
    Peter Rotich's avatar
    Peter Rotich committed
                        class="icon-group"></i> <?php echo __('Team'); ?></a>
                  </ul>
                </div>
                <?php
                } ?>
    
                <div id="action-dropdown-more" class="action-dropdown anchor-right">
                  <ul>
    
                    <?php
    
                     if ($role->hasPerm(Ticket::PERM_EDIT)) { ?>
    
                        <li><a class="change-user" href="#tickets/<?php
                        echo $ticket->getId(); ?>/change-user"><i class="icon-user"></i> <?php
    
    Peter Rotich's avatar
    Peter Rotich committed
                        echo __('Change Owner'); ?></a></li>
                    <?php
                     }
    
    Peter Rotich's avatar
    Peter Rotich committed
    
                     if($ticket->isOpen() && ($dept && $dept->isManager($thisstaff))) {
    
                            <li><a  class="confirm-action" id="ticket-release" href="#release"><i class="icon-user"></i> <?php
                                echo __('Release (unassign) Ticket'); ?></a></li>
    
                            <li><a class="confirm-action" id="ticket-overdue" href="#overdue"><i class="icon-bell"></i> <?php
                                echo __('Mark as Overdue'); ?></a></li>
    
                        <li><a class="confirm-action" id="ticket-unanswered" href="#unanswered"><i class="icon-circle-arrow-left"></i> <?php
                                echo __('Mark as Unanswered'); ?></a></li>
    
                        <li><a class="confirm-action" id="ticket-answered" href="#answered"><i class="icon-circle-arrow-right"></i> <?php
                                echo __('Mark as Answered'); ?></a></li>
    
    
                    <?php
                    if ($role->hasPerm(Ticket::PERM_TRANSFER)) { ?>
                    <li><a href="#tickets/<?php echo $ticket->getId();
                        ?>/referrals" class="ticket-action"
                         data-redirect="tickets.php?id=<?php echo $ticket->getId(); ?>" >
                           <i class="icon-exchange"></i> <?php echo __('Manage Referrals'); ?></a></li>
                    <?php
                    } ?>
    
                    <?php
                    if ($role->hasPerm(Ticket::PERM_EDIT)) { ?>
    
                    <li><a href="#ajax.php/tickets/<?php echo $ticket->getId();
                        ?>/forms/manage" onclick="javascript:
                        $.dialog($(this).attr('href').substr(1), 201);
                        return false"
    
                        ><i class="icon-paste"></i> <?php echo __('Manage Forms'); ?></a></li>
    
                    if ($role->hasPerm(Ticket::PERM_REPLY)) {
                        ?>
    
                    <li>
    
                        <?php
                        $recipients = __(' Manage Collaborators');
    
                        echo sprintf('<a class="collaborators manage-collaborators"
                                href="#thread/%d/collaborators"><i class="icon-group"></i>%s</a>',
                                $ticket->getThreadId(),
                                $recipients);
                       ?>
                    </li>
    
    <?php           if ($thisstaff->hasPerm(Email::PERM_BANLIST)
                        && $role->hasPerm(Ticket::PERM_REPLY)) {
    
                            <li><a class="confirm-action" id="ticket-banemail"
    
                                href="#banemail"><i class="icon-ban-circle"></i> <?php echo sprintf(
    
                                    Format::htmlchars(__('Ban Email <%s>')),
                                    $ticket->getEmail()); ?></a></li>
    
                    <?php
    
                            <li><a  class="confirm-action" id="ticket-banemail"
    
                                href="#unbanemail"><i class="icon-undo"></i> <?php echo sprintf(
    
                                    Format::htmlchars(__('Unban Email <%s>')),
                                    $ticket->getEmail()); ?></a></li>
    
                      if ($role->hasPerm(Ticket::PERM_DELETE)) {
    
    Peter Rotich's avatar
    Peter Rotich committed
                         ?>
                        <li class="danger"><a class="ticket-action" href="#tickets/<?php
                        echo $ticket->getId(); ?>/status/delete"
    
                        data-redirect="tickets.php"><i class="icon-trash"></i> <?php
    
    Peter Rotich's avatar
    Peter Rotich committed
                        echo __('Delete Ticket'); ?></a></li>
                    <?php
                     }
                    ?>
    
                    if ($role->hasPerm(Ticket::PERM_REPLY)) { ?>
    
                    <a href="#post-reply" class="post-response action-button"
                    data-placement="bottom" data-toggle="tooltip"
                    title="<?php echo __('Post Reply'); ?>"><i class="icon-mail-reply"></i></a>
                    <?php
                    } ?>
                    <a href="#post-note" id="post-note" class="post-response action-button"
                    data-placement="bottom" data-toggle="tooltip"
                    title="<?php echo __('Post Internal Note'); ?>"><i class="icon-file-text"></i></a>
                    <?php // Status change options
                    echo TicketStatus::status_options();
                    ?>
    
            <div class="flush-left">
                 <h2><a href="tickets.php?id=<?php echo $ticket->getId(); ?>"
                 title="<?php echo __('Reload'); ?>"><i class="icon-refresh"></i>
    
                 <?php echo sprintf(__('Ticket #%s'), $ticket->getNumber()); ?></a>
                </h2>
    
    <div class="clear tixTitle has_bottom_border">
        <h3>
    
        <?php $subject_field = TicketForm::getInstance()->getField('subject');
            echo $subject_field->display($ticket->getSubject()); ?>
    
    <table class="ticket_info" cellspacing="0" cellpadding="0" width="940" border="0">
        <tr>
    
    Peter Rotich's avatar
    Peter Rotich committed
            <td width="50%">
    
                <table border="0" cellspacing="" cellpadding="4" width="100%">
                    <tr>
    
                        <th width="100"><?php echo __('Status');?>:</th>
    
                        <?php
                             if ($role->hasPerm(Ticket::PERM_CLOSE)) {?>
                        <td>
                          <a class="tickets-action" data-dropdown="#action-dropdown-statuses" data-placement="bottom" data-toggle="tooltip" title="<?php echo __('Change Status'); ?>"
                              data-redirect="tickets.php?id=<?php echo $ticket->getId(); ?>"
                              href="#statuses">
                              <?php echo $ticket->getStatus(); ?>
                          </a>
                        </td>
                          <?php } else { ?>
                              <td><?php echo ($S = $ticket->getStatus()) ? $S->display() : ''; ?></td>
                          <?php } ?>
    
                        <th><?php echo __('Priority');?>:</th>
    
    Peter Rotich's avatar
    Peter Rotich committed
                          <?php
                             if ($role->hasPerm(Ticket::PERM_EDIT)) {?>
                               <td>
                                 <a class="ticket-action" id="inline-update" data-placement="bottom" data-toggle="tooltip" title="<?php echo __('Update'); ?>"
                                     data-redirect="tickets.php?id=<?php echo $ticket->getId(); ?>"
                                     href="#tickets/<?php echo $ticket->getId(); ?>/field/priority/edit">
                                     <?php echo $ticket->getPriority(); ?>
                                 </a>
                               </td>
                          <?php } else { ?>
                               <td><?php echo $ticket->getPriority(); ?></td>
                          <?php } ?>
    
                        <th><?php echo __('Department');?>:</th>
    
    Peter Rotich's avatar
    Peter Rotich committed
                        <?php
                        if ($role->hasPerm(Ticket::PERM_TRANSFER)) {?>
                          <td>
                            <a class="ticket-action" id="ticket-transfer" data-placement="bottom" data-toggle="tooltip" title="<?php echo __('Transfer'); ?>"
                              data-redirect="tickets.php?id=<?php echo $ticket->getId(); ?>"
                              href="#tickets/<?php echo $ticket->getId(); ?>/transfer"><?php echo Format::htmlchars($ticket->getDeptName()); ?>
                            </a>
                          </td>
                        <?php
                      }else {?>
    
                        <td><?php echo Format::htmlchars($ticket->getDeptName()); ?></td>
    
    Peter Rotich's avatar
    Peter Rotich committed
                      <?php } ?>
    
                        <th><?php echo __('Create Date');?>:</th>
    
                        <td><?php echo Format::datetime($ticket->getCreateDate()); ?></td>
    
            <td width="50%" style="vertical-align:top">
    
                <table border="0" cellspacing="" cellpadding="4" width="100%">
                    <tr>
    
                        <th width="100"><?php echo __('User'); ?>:</th>
    
                        <td><a href="#tickets/<?php echo $ticket->getId(); ?>/user"
    
                            onclick="javascript:
    
                                $.userLookup('ajax.php/tickets/<?php echo $ticket->getId(); ?>/user',
                                        function (user) {
                                            $('#user-'+user.id+'-name').text(user.name);
                                            $('#user-'+user.id+'-email').text(user.email);
    
                                            $('#user-'+user.id+'-phone').text(user.phone);
    
                                            $('select#emailreply option[value=1]').text(user.name+' <'+user.email+'>');
    
                                "><i class="icon-user"></i> <span id="user-<?php echo $ticket->getOwnerId(); ?>-name"
                                ><?php echo Format::htmlchars($ticket->getName());
                            ?></span></a>
    
                            if ($user) { ?>
                                <a href="tickets.php?<?php echo Http::build_query(array(
                                    'status'=>'open', 'a'=>'search', 'uid'=> $user->getId()
                                )); ?>" title="<?php echo __('Related Tickets'); ?>"
                                data-dropdown="#action-dropdown-stats">
                                (<b><?php echo $user->getNumTickets(); ?></b>)
                                </a>
    
                                <div id="action-dropdown-stats" class="action-dropdown anchor-right">
                                    <ul>
                                        <?php
    
    Peter Rotich's avatar
    Peter Rotich committed
                                        if(($open=$user->getNumOpenTickets()))
    
                                            echo sprintf('<li><a href="tickets.php?a=search&status=open&uid=%s"><i class="icon-folder-open-alt icon-fixed-width"></i> %s</a></li>',
    
                                                    $user->getId(), sprintf(_N('%d Open Ticket', '%d Open Tickets', $open), $open));
    
    Peter Rotich's avatar
    Peter Rotich committed
                                        if(($closed=$user->getNumClosedTickets()))
    
                                            echo sprintf('<li><a href="tickets.php?a=search&status=closed&uid=%d"><i
    
                                                    class="icon-folder-close-alt icon-fixed-width"></i> %s</a></li>',
    
                                                    $user->getId(), sprintf(_N('%d Closed Ticket', '%d Closed Tickets', $closed), $closed));
    
                                        <li><a href="tickets.php?a=search&uid=<?php echo $ticket->getOwnerId(); ?>"><i class="icon-double-angle-right icon-fixed-width"></i> <?php echo __('All Tickets'); ?></a></li>
    
    Jared Hancock's avatar
    Jared Hancock committed
    <?php   if ($thisstaff->hasPerm(User::PERM_DIRECTORY)) { ?>
    
    Peter Rotich's avatar
    Peter Rotich committed
                                        <li><a href="users.php?id=<?php echo
                                        $user->getId(); ?>"><i class="icon-user
    
                                        icon-fixed-width"></i> <?php echo __('Manage User'); ?></a></li>
    
    <?php   } ?>
                                    </ul>
                                </div>
    
    Peter Rotich's avatar
    Peter Rotich committed
                                if ($role->hasPerm(Ticket::PERM_EDIT)) {
    
                                $numCollaborators = $ticket->getThread()->getNumCollaborators();
                                 if ($ticket->getThread()->getNumCollaborators())
                                    $recipients = sprintf(__('%d'),
                                            $numCollaborators);
                                else
                                  $recipients = 0;
    
                                 echo sprintf('<span><a class="collaborators preview"
                                        href="#thread/%d/collaborators"><span id="t%d-recipients"><i class="icon-group"></i> (%s)</span></a></span>',
                                        $ticket->getThreadId(),
                                        $ticket->getThreadId(),
                                        $recipients);
                                 }?>
    
    <?php                   } # end if ($user) ?>
                        </td>
                    </tr>
                    <tr>
                        <th><?php echo __('Email'); ?>:</th>
                        <td>
                            <span id="user-<?php echo $ticket->getOwnerId(); ?>-email"><?php echo $ticket->getEmail(); ?></span>
                        </td>
                    </tr>
    
    <?php   if ($user->getOrganization()) { ?>
    
                    <tr>
                        <th><?php echo __('Organization'); ?>:</th>
                        <td><i class="icon-building"></i>
    
                        <?php echo Format::htmlchars($user->getOrganization()->getName()); ?>
                            <a href="tickets.php?<?php echo Http::build_query(array(
                                'status'=>'open', 'a'=>'search', 'orgid'=> $user->getOrgId()
                            )); ?>" title="<?php echo __('Related Tickets'); ?>"
                            data-dropdown="#action-dropdown-org-stats">
                            (<b><?php echo $user->getNumOrganizationTickets(); ?></b>)
                            </a>
                                <div id="action-dropdown-org-stats" class="action-dropdown anchor-right">
                                    <ul>
    <?php   if ($open = $user->getNumOpenOrganizationTickets()) { ?>
                                        <li><a href="tickets.php?<?php echo Http::build_query(array(
                                            'a' => 'search', 'status' => 'open', 'orgid' => $user->getOrgId()
                                        )); ?>"><i class="icon-folder-open-alt icon-fixed-width"></i>
                                        <?php echo sprintf(_N('%d Open Ticket', '%d Open Tickets', $open), $open); ?>
                                        </a></li>
    <?php   }
            if ($closed = $user->getNumClosedOrganizationTickets()) { ?>
                                        <li><a href="tickets.php?<?php echo Http::build_query(array(
                                            'a' => 'search', 'status' => 'closed', 'orgid' => $user->getOrgId()
                                        )); ?>"><i class="icon-folder-close-alt icon-fixed-width"></i>
                                        <?php echo sprintf(_N('%d Closed Ticket', '%d Closed Tickets', $closed), $closed); ?>
                                        </a></li>
                                        <li><a href="tickets.php?<?php echo Http::build_query(array(
                                            'a' => 'search', 'orgid' => $user->getOrgId()
                                        )); ?>"><i class="icon-double-angle-right icon-fixed-width"></i> <?php echo __('All Tickets'); ?></a></li>
    <?php   }
    
    Jared Hancock's avatar
    Jared Hancock committed
            if ($thisstaff->hasPerm(User::PERM_DIRECTORY)) { ?>
    
                                        <li><a href="orgs.php?id=<?php echo $user->getOrgId(); ?>"><i
                                            class="icon-building icon-fixed-width"></i> <?php
                                            echo __('Manage Organization'); ?></a></li>
    
    Jared Hancock's avatar
    Jared Hancock committed
                                    </ul>
    
                            </td>
                        </tr>
    <?php   } # end if (user->org) ?>
    
    Peter Rotich's avatar
    Peter Rotich committed
                      <th><?php echo __('Source'); ?>:</th>
                      <td>
                      <?php
                             if ($role->hasPerm(Ticket::PERM_EDIT)) {?>
                        <a class="ticket-action" id="inline-update" data-placement="bottom" data-toggle="tooltip" title="<?php echo __('Update'); ?>"
                            data-redirect="tickets.php?id=<?php echo $ticket->getId(); ?>"
    
    Peter Rotich's avatar
    Peter Rotich committed
                            href="#tickets/<?php echo $ticket->getId(); ?>/field/source/edit">
                            <?php echo Format::htmlchars($ticket->getSource());
    
    Peter Rotich's avatar
    Peter Rotich committed
                        </a>
                          <?php
                             } else {
                                echo Format::htmlchars($ticket->getSource());
                            }
    
                        if (!strcasecmp($ticket->getSource(), 'Web') && $ticket->getIP())
                            echo '&nbsp;&nbsp; <span class="faded">('.Format::htmlchars($ticket->getIP()).')</span>';
                        ?>
                     </td>
    
                    </tr>
                </table>
            </td>
        </tr>
    </table>
    <br>
    <table class="ticket_info" cellspacing="0" cellpadding="0" width="940" border="0">
        <tr>
            <td width="50%">
                <table cellspacing="0" cellpadding="4" width="100%" border="0">
                    <?php
                    if($ticket->isOpen()) { ?>
                    <tr>
    
                        <th width="100"><?php echo __('Assigned To');?>:</th>
    
    Peter Rotich's avatar
    Peter Rotich committed
                        <?php
                        if ($role->hasPerm(Ticket::PERM_ASSIGN)) {?>
    
    Peter Rotich's avatar
    Peter Rotich committed
                                                        <a class="ticket-action" id="ticket-assign"
                                data-redirect="tickets.php?id=<?php echo $ticket->getId(); ?>"
                                href="#tickets/<?php echo $ticket->getId(); ?>/assign">
                                <?php
                                    if($ticket->isAssigned())
                                        echo Format::htmlchars(implode('/', $ticket->getAssignees()));
                                    else
                                        echo '<span class="faded">&mdash; '.__('Unassigned').' &mdash;</span>';
                                ?>
                            </a>
    
    Peter Rotich's avatar
    Peter Rotich committed
                        <?php
                        } else { ?>
                        <td>
                          <?php
                          if($ticket->isAssigned())
                              echo Format::htmlchars(implode('/', $ticket->getAssignees()));
                          else
                              echo '<span class="faded">&mdash; '.__('Unassigned').' &mdash;</span>';
                          ?>
                        </td>
                        <?php
                        } ?>
    
                        <th width="100"><?php echo __('Closed By');?>:</th>
    
                        <td>
                            <?php
                            if(($staff = $ticket->getStaff()))
                                echo Format::htmlchars($staff->getName());
                            else
    
                                echo '<span class="faded">&mdash; '.__('Unknown').' &mdash;</span>';
    
                        <th><?php echo __('SLA Plan');?>:</th>
    
    Peter Rotich's avatar
    Peter Rotich committed
                        <td>
                        <?php
                             if ($role->hasPerm(Ticket::PERM_EDIT)) {?>
                          <a class="ticket-action" id="inline-update" data-placement="bottom" data-toggle="tooltip" title="<?php echo __('Update'); ?>"
                              data-redirect="tickets.php?id=<?php echo $ticket->getId(); ?>"
    
                              href="#tickets/<?php echo $ticket->getId(); ?>/field/sla/edit">
                              <?php echo $sla?Format::htmlchars($sla->getName()):'<span class="faded">&mdash; '.__('None').' &mdash;</span>'; ?>
                          </a>
                          <?php } else { ?>
                            <?php echo $sla?Format::htmlchars($sla->getName()):'<span class="faded">&mdash; '.__('None').' &mdash;</span>'; ?>
                          <?php } ?>
                        </td>
    
                        <th><?php echo __('Due Date');?>:</th>
    
    Peter Rotich's avatar
    Peter Rotich committed
                        <?php
                             if ($role->hasPerm(Ticket::PERM_EDIT)) {?>
                               <td>
                          <a class="ticket-action" id="inline-update" data-placement="bottom" data-toggle="tooltip" title="<?php echo __('Update'); ?>"
                              data-redirect="tickets.php?id=<?php echo $ticket->getId(); ?>"
    
                              href="#tickets/<?php echo $ticket->getId();
                               ?>/field/duedate/edit">
                              <?php echo Format::datetime($ticket->getEstDueDate()); ?>
                          </a>
                        <td>
                          <?php } else { ?>
                               <td><?php echo Format::datetime($ticket->getEstDueDate()); ?></td>
                          <?php } ?>
    
                        <th><?php echo __('Close Date');?>:</th>
    
                        <td><?php echo Format::datetime($ticket->getCloseDate()); ?></td>
    
                    </tr>
                    <?php
                    }
                    ?>
                </table>
            </td>
            <td width="50%">
                <table cellspacing="0" cellpadding="4" width="100%" border="0">
                    <tr>
    
                        <th width="100"><?php echo __('Help Topic');?>:</th>
    
    Peter Rotich's avatar
    Peter Rotich committed
                          <?php
                               if ($role->hasPerm(Ticket::PERM_EDIT)) {?>
                                 <td>
                            <a class="ticket-action" id="inline-update" data-placement="bottom"
                                data-toggle="tooltip" title="<?php echo __('Update'); ?>"
                                data-redirect="tickets.php?id=<?php echo $ticket->getId(); ?>"
                                href="#tickets/<?php echo $ticket->getId(); ?>/field/topic/edit">
                                <?php echo $ticket->getHelpTopic() ?: __('None'); ?>
                            </a>
                          </td>
                            <?php } else { ?>
                                 <td><?php echo Format::htmlchars($ticket->getHelpTopic()); ?></td>
                            <?php } ?>
    
                        <th nowrap><?php echo __('Last Message');?>:</th>
    
                        <td><?php echo Format::datetime($ticket->getLastMsgDate()); ?></td>
    
                        <th nowrap><?php echo __('Last Response');?>:</th>
    
                        <td><?php echo Format::datetime($ticket->getLastRespDate()); ?></td>
    
    Jared Hancock's avatar
    Jared Hancock committed
    <br>
    <?php
    foreach (DynamicFormEntry::forTicket($ticket->getId()) as $form) {
    
        //Find fields to exclude if disabled by help topic
        $disabled = Ticket::getMissingRequiredFields($ticket, true);
    
    
    Jared Hancock's avatar
    Jared Hancock committed
        // Skip core fields shown earlier in the ticket view
        // TODO: Rewrite getAnswers() so that one could write
        //       ->getAnswers()->filter(not(array('field__name__in'=>
        //           array('email', ...))));
    
        $answers = $form->getAnswers()->exclude(Q::any(array(
            'field__flags__hasbit' => DynamicFormField::FLAG_EXT_STORED,
    
            'field__name__in' => array('subject', 'priority'),
            'field__id__in' => $disabled,
    
        $displayed = array();
        foreach($answers as $a) {
    
            $displayed[] = array($a->getLocal('label'), $a->display() ?: '<span class="faded">&mdash;' . __('Empty') . '&mdash; </span>', $a->getLocal('id'));
    
    Jared Hancock's avatar
    Jared Hancock committed
            continue;
        ?>
    
        <table class="ticket_info custom-data" cellspacing="0" cellpadding="0" width="940" border="0">
        <thead>
            <th colspan="2"><?php echo Format::htmlchars($form->getTitle()); ?></th>
        </thead>
        <tbody>
    <?php
        foreach ($displayed as $stuff) {
    
    Jared Hancock's avatar
    Jared Hancock committed
            <tr>
    
    Peter Rotich's avatar
    Peter Rotich committed
                <td width="200"><?php echo Format::htmlchars($label); ?>:</td>
                <td>
                <?php if ($role->hasPerm(Ticket::PERM_EDIT)) {?>
                  <a class="ticket-action" id="inline-update" data-placement="bottom" data-toggle="tooltip" title="<?php echo __('Update'); ?>"
                      data-redirect="tickets.php?id=<?php echo $ticket->getId(); ?>"
                      href="#tickets/<?php echo $ticket->getId(); ?>/field/<?php echo $id; ?>/edit">
    
                      <?php
                        if (strlen($v) > 200) {
                          echo Format::truncate($v, 200);
                          echo "<br><i class=\"icon-edit\"></i>";
                        }
                        else
                          echo $v;
                      ?>
    
    Peter Rotich's avatar
    Peter Rotich committed
                  </a>
                <?php } else {
                    echo $v;
                } ?>
                </td>
    
    Jared Hancock's avatar
    Jared Hancock committed
            </tr>
    
    <div class="clear"></div>
    
    $tcount = $ticket->getThreadEntries($types)->count();
    
    <ul  class="tabs clean threads" id="ticket_tabs" >
    
        <li class="active"><a id="ticket-thread-tab" href="#ticket_thread"><?php
            echo sprintf(__('Ticket Thread (%d)'), $tcount); ?></a></li>
    
    Peter Rotich's avatar
    Peter Rotich committed
        <li><a id="ticket-tasks-tab" href="#tasks"
    
                data-url="<?php
    
            echo sprintf('#tickets/%d/tasks', $ticket->getId()); ?>"><?php
            echo __('Tasks');
            if ($ticket->getNumTasks())
    
    Peter Rotich's avatar
    Peter Rotich committed
                echo sprintf('&nbsp;(<span id="ticket-tasks-count">%d</span>)', $ticket->getNumTasks());
    
            ?></a></li>
    
    Jared Hancock's avatar
    Jared Hancock committed
    <div id="ticket_tabs_container">
    
    <div id="ticket_thread" class="tab_content">
    
    <?php
        // Render ticket thread
        $ticket->getThread()->render(
                array('M', 'R', 'N'),
                array(
    
    Peter Rotich's avatar
    Peter Rotich committed
                    'html-id'   => 'ticketThread',
                    'mode'      => Thread::MODE_STAFF,
                    'sort'      => $thisstaff->thread_view_order
                    )
    
    <div class="clear"></div>
    
    <?php
    if ($errors['err'] && isset($_POST['a'])) {
        // Reflect errors back to the tab.
        $errors[$_POST['a']] = $errors['err'];
    } elseif($msg) { ?>
    
        <div id="msg_notice"><?php echo $msg; ?></div>
    
    <?php
    } elseif($warn) { ?>
    
        <div id="msg_warning"><?php echo $warn; ?></div>
    
    <div class="sticky bar stop actions" id="response_options"
    >
    
        <ul class="tabs" id="response-tabs">
    
            if ($role->hasPerm(Ticket::PERM_REPLY)) { ?>
    
            <li class="active <?php
                echo isset($errors['reply']) ? 'error' : ''; ?>"><a
                href="#reply" id="post-reply-tab"><?php echo __('Post Reply');?></a></li>
    
            <li><a href="#note" <?php
                echo isset($errors['postnote']) ?  'class="error"' : ''; ?>
                id="post-note-tab"><?php echo __('Post Internal Note');?></a></li>
    
        if ($role->hasPerm(Ticket::PERM_REPLY)) { ?>
    
    jdelhome3578's avatar
    jdelhome3578 committed
        <form id="reply" class="tab_content spellcheck exclusive save"
    
            data-lock-object-id="ticket/<?php echo $ticket->getId(); ?>"
    
            data-lock-id="<?php echo $mylock ? $mylock->getId() : ''; ?>"
    
            action="tickets.php?id=<?php
    
            echo $ticket->getId(); ?>#reply" name="reply" method="post" enctype="multipart/form-data">
    
            <?php csrf_token(); ?>
            <input type="hidden" name="id" value="<?php echo $ticket->getId(); ?>">
            <input type="hidden" name="msgId" value="<?php echo $msgId; ?>">
            <input type="hidden" name="a" value="reply">
    
            <input type="hidden" name="lockCode" value="<?php echo $mylock ? $mylock->getCode() : ''; ?>">
    
            <table style="width:100%" border="0" cellspacing="0" cellpadding="3">
    
                <?php
                if ($errors['reply']) {?>
                <tr><td width="120">&nbsp;</td><td class="error"><?php echo $errors['reply']; ?>&nbsp;</td></tr>
                <?php
                }?>
    
               <?php
               # XXX: Add user-to-name and user-to-email HTML ID#s
               if ($addresses = Email::getAddresses(array('smtp' => true))){
               ?>
    
               <tr>
                   <td width="120">
                       <label><strong><?php echo __('From'); ?>:</strong></label>
                   </td>
                   <td>
                       <select id="from_name" name="from_name">
                         <?php
                         $sql=' SELECT email_id, email, name, smtp_host '
                             .' FROM '.EMAIL_TABLE.' WHERE smtp_active = 1';
                         if(($res=db_query($sql)) && db_num_rows($res)) {
                             while (list($id, $email, $name, $host) = db_fetch_row($res)){
                                 $email=$name?"$name &lt;$email&gt;":$email;
                                 ?>
                                 <option value="<?php echo $id; ?>"<?php echo ($dept->getEmail()->email_id==$id)?'selected="selected"':''; ?>><?php echo $email; ?></option>
                             <?php
                             }
                         } ?>
                       </select>
                   </td>
               </tr>
    
                    <td width="120">
    
                        <label><strong><?php echo __('To'); ?>:</strong></label>
    
    Peter Rotich's avatar
    Peter Rotich committed
                        <?php
    
                        # XXX: Add user-to-name and user-to-email HTML ID#s
    
                        $to =sprintf('%s &lt;%s&gt;',
                                Format::htmlchars($ticket->getName()),
                                $ticket->getReplyToEmail());
    
                        $emailReply = (!isset($info['emailreply']) || $info['emailreply']);
    
    Peter Rotich's avatar
    Peter Rotich committed
                        ?>
    
                        <select id="emailreply" name="emailreply">
                            <option value="1" <?php echo $emailReply ?  'selected="selected"' : ''; ?>><?php echo $to; ?></option>
                            <option value="0" <?php echo !$emailReply ? 'selected="selected"' : ''; ?>
    
                            >&mdash; <?php echo __('Do Not Email Reply'); ?> &mdash;</option>
    
    Peter Rotich's avatar
    Peter Rotich committed
                if(1) { //Make CC optional feature? NO, for now.
                    ?>
    
                <tbody id="cc_sec"
                    style="display:<?php echo $emailReply?  'table-row-group':'none'; ?>;">
                 <tr>
    
    Peter Rotich's avatar
    Peter Rotich committed
                    <td width="120">
    
                        <label><strong><?php echo __('Collaborators'); ?>:</strong></label>
    
    Peter Rotich's avatar
    Peter Rotich committed
                    </td>
                    <td>
    
                        <input type='checkbox' value='1' name="emailcollab"
                        id="t<?php echo $ticket->getThreadId(); ?>-emailcollab"
    
                            <?php echo ((!$info['emailcollab'] && !$errors) || isset($info['emailcollab']))?'checked="checked"':''; ?>
    
                            style="display:<?php echo $ticket->getThread()->getNumCollaborators() ? 'inline-block': 'none'; ?>;"
    
    Peter Rotich's avatar
    Peter Rotich committed
                        <?php
                       ?>
                    </td>
    
                 <?php $collaborators = $ticket->getThread()->getCollaborators();
                 $cc_cids = array();
                 $bcc_cids = array();
                 foreach ($collaborators as $c) {
                   if ($c->flags & Collaborator::FLAG_CC && $c->flags & Collaborator::FLAG_ACTIVE)
                      $cc_cids[] = $c->user_id;
                    elseif (!($c->flags & Collaborator::FLAG_CC) && $c->flags & Collaborator::FLAG_ACTIVE) {
                      $bcc_cids[] = $c->user_id;
                    }
                 }
                ?>
                 <tr>
                     <td width="160"><b><?php echo __('Cc'); ?>:</b></td>
                     <td>
    
    aydreeihn's avatar
    aydreeihn committed
                         <select class="collabSelections" name="ccs[]" id="cc_users" multiple="multiple"
    
                             data-placeholder="<?php echo __('Select Contacts'); ?>">
                             <?php
    
    aydreeihn's avatar
    aydreeihn committed
                             foreach ($cc_cids as $u) {
                               if($u != $ticket->user_id && !in_array($u, $bcc_cids)) {
                                 ?>
                                 <option value="<?php echo $u; ?>" <?php
                                 if (in_array($u, $cc_cids))
                                 echo 'selected="selected"'; ?>><?php echo User::lookup($u); ?>
                               </option>
                             <?php } } ?>
    
                             ?>
                         </select>
                         <br/><span class="error"><?php echo $errors['ccs']; ?></span>
                     </td>
                 </tr>
                 <tr>
                   <td width="160"><b><?php echo __('Bcc'); ?>:</b></td>
                   <td>
    
    aydreeihn's avatar
    aydreeihn committed
                       <select class="collabSelections" name="bccs[]" id="bcc_users" multiple="multiple"
    
                           data-placeholder="<?php echo __('Select Contacts'); ?>">
                           <?php
    
    aydreeihn's avatar
    aydreeihn committed
                           foreach ($bcc_cids as $u) {
                             if($u != $ticket->user_id && !in_array($u, $cc_cids)) {
                               ?>
                               <option value="<?php echo $u; ?>" <?php
                               if (in_array($u, $bcc_cids))
                               echo 'selected="selected"'; ?>><?php echo User::lookup($u); ?>
                             </option>
                           <?php } } ?>
    
                           ?>
                       </select>
                       <br/><span class="error"><?php echo $errors['bccs']; ?></span>
                   </td>
                 </tr>
    
    Peter Rotich's avatar
    Peter Rotich committed
                </tbody>
                <?php
                } ?>
                <tbody id="resp_sec">
                <?php
    
    Peter Rotich's avatar
    Peter Rotich committed
                if($errors['response']) {?>
    
                <tr><td width="120">&nbsp;</td><td class="error"><?php echo $errors['response']; ?>&nbsp;</td></tr>
    
    Peter Rotich's avatar
    Peter Rotich committed
                <?php
    
                    <td width="120" style="vertical-align:top">
    
                        <label><strong><?php echo __('Response');?>:</strong></label>
    
    <?php if ($cfg->isCannedResponseEnabled()) { ?>
    
                        <select id="cannedResp" name="cannedResp">
    
                            <option value="0" selected="selected"><?php echo __('Select a canned response');?></option>
    
                            <option value='original'><?php echo __('Original Message'); ?></option>
                            <option value='lastmessage'><?php echo __('Last Message'); ?></option>
    
                            <?php
                            if(($cannedResponses=Canned::responsesByDeptId($ticket->getDeptId()))) {
                                echo '<option value="0" disabled="disabled">
    
                                    ------------- '.__('Premade Replies').' ------------- </option>';
    
                                foreach($cannedResponses as $id =>$title)
    
    Peter Rotich's avatar
    Peter Rotich committed
                                    echo sprintf('<option value="%d">%s</option>',$id,$title);
    
    <?php } # endif (canned-resonse-enabled)
    
                        $signature = '';
                        switch ($thisstaff->getDefaultSignatureType()) {
                        case 'dept':
                            if ($dept && $dept->canAppendSignature())
                               $signature = $dept->getSignature();
                           break;
                        case 'mine':
                            $signature = $thisstaff->getSignature();
                            break;
                        } ?>
    
                        <input type="hidden" name="draft_id" value=""/>
                        <textarea name="response" id="response" cols="50"
    
                            data-signature-field="signature" data-dept-id="<?php echo $dept->getId(); ?>"
                            data-signature="<?php
                                echo Format::htmlchars(Format::viewableImages($signature)); ?>"
    
                            placeholder="<?php echo __(
                            'Start writing your response here. Use canned responses from the drop-down above'
                            ); ?>"
    
                            class="<?php if ($cfg->isRichTextEnabled()) echo 'richtext';
    
                                ?> draft draft-delete" <?php
        list($draft, $attrs) = Draft::getDraftAndDataAttrs('ticket.response', $ticket->getId(), $info['response']);
    
        echo $attrs; ?>><?php echo $_POST ? $info['response'] : $draft;
    
                    <div id="reply_form_attachments" class="attachments">
    
                    <?php
                        print $response_form->getField('attachments')->render();
                    ?>
    
                    <td width="120">
    
                        <label for="signature" class="left"><?php echo __('Signature');?>:</label>
    
                        <?php
                        $info['signature']=$info['signature']?$info['signature']:$thisstaff->getDefaultSignatureType();
                        ?>
    
                        <label><input type="radio" name="signature" value="none" checked="checked"> <?php echo __('None');?></label>
    
                        <?php
                        if($thisstaff->getSignature()) {?>
                        <label><input type="radio" name="signature" value="mine"
    
                            <?php echo ($info['signature']=='mine')?'checked="checked"':''; ?>> <?php echo __('My Signature');?></label>
    
                        <?php
                        } ?>
                        <?php
                        if($dept && $dept->canAppendSignature()) { ?>
                        <label><input type="radio" name="signature" value="dept"
                            <?php echo ($info['signature']=='dept')?'checked="checked"':''; ?>>
    
                            <?php echo sprintf(__('Department Signature (%s)'), Format::htmlchars($dept->getName())); ?></label>
    
                    <td width="120" style="vertical-align:top">
    
                        <label><strong><?php echo __('Ticket Status');?>:</strong></label>
    
                        $outstanding = false;
    
                        if ($role->hasPerm(Ticket::PERM_CLOSE)
    
    Peter Rotich's avatar
    Peter Rotich committed
                                && is_string($warning=$ticket->isCloseable())) {
    
                            $outstanding =  true;
                            echo sprintf('<div class="warning-banner">%s</div>', $warning);
                        } ?>
    
                        <select name="reply_status_id">
    
                        $statusId = $info['reply_status_id'] ?: $ticket->getStatusId();
    
                        $states = array('open');
    
                        if ($role->hasPerm(Ticket::PERM_CLOSE) && !$outstanding)
    
    Peter Rotich's avatar
    Peter Rotich committed
                            $states = array_merge($states, array('closed'));
    
                        foreach (TicketStatusList::getStatuses(
                                    array('states' => $states)) as $s) {
    
                            if (!$s->isEnabled()) continue;
    
                            $selected = ($statusId == $s->getId());
                            echo sprintf('<option value="%d" %s>%s%s</option>',
    
                                    $s->getId(),
    
                                     ? 'selected="selected"' : '',
    
                                    __($s->getName()),
    
                                    $selected
                                    ? (' ('.__('current').')') : ''
    
    Peter Rotich's avatar
    Peter Rotich committed
             </tbody>
    
                <input class="save pending" type="submit" value="<?php echo __('Post Reply');?>">
                <input class="" type="reset" value="<?php echo __('Reset');?>">
    
    jdelhome3578's avatar
    jdelhome3578 committed
        <form id="note" class="hidden tab_content spellcheck exclusive save"
    
            data-lock-object-id="ticket/<?php echo $ticket->getId(); ?>"
            data-lock-id="<?php echo $mylock ? $mylock->getId() : ''; ?>"
            action="tickets.php?id=<?php echo $ticket->getId(); ?>#note"
            name="note" method="post" enctype="multipart/form-data">
    
            <?php csrf_token(); ?>
            <input type="hidden" name="id" value="<?php echo $ticket->getId(); ?>">
    
            <input type="hidden" name="locktime" value="<?php echo $cfg->getLockTime() * 60; ?>">
    
            <input type="hidden" name="a" value="postnote">
    
            <input type="hidden" name="lockCode" value="<?php echo $mylock ? $mylock->getCode() : ''; ?>">
    
            <table width="100%" border="0" cellspacing="0" cellpadding="3">
    
                <?php
    
                if($errors['postnote']) {?>
    
                    <td width="120">&nbsp;</td>
    
    Peter Rotich's avatar
    Peter Rotich committed
                    <td class="error"><?php echo $errors['postnote']; ?></td>
    
    Peter Rotich's avatar
    Peter Rotich committed
                <?php
                } ?>
    
                    <td width="120" style="vertical-align:top">
    
                        <label><strong><?php echo __('Internal Note'); ?>:</strong><span class='error'>&nbsp;*</span></label>
    
                            <div class="faded" style="padding-left:0.15em"><?php
                            echo __('Note title - summary of the note (optional)'); ?></div>
    
                            <input type="text" name="title" id="title" size="60" value="<?php echo $info['title']; ?>" >
                            <br/>
    
    Jared Hancock's avatar
    Jared Hancock committed
                            <span class="error">&nbsp;<?php echo $errors['title']; ?></span>
    
                        <div class="error"><?php echo $errors['note']; ?></div>
    
                        <textarea name="note" id="internal_note" cols="80"
    
                            placeholder="<?php echo __('Note details'); ?>"
    
                            class="<?php if ($cfg->isRichTextEnabled()) echo 'richtext';
    
                                ?> draft draft-delete" <?php
        list($draft, $attrs) = Draft::getDraftAndDataAttrs('ticket.note', $ticket->getId(), $info['note']);
    
        echo $attrs; ?>><?php echo $_POST ? $info['note'] : $draft;
    
                            ?></textarea>
    
                    <div class="attachments">
    
                    <?php
                        print $note_form->getField('attachments')->render();