Skip to content
Snippets Groups Projects
ticket-open.inc.php 19 KiB
Newer Older
  • Learn to ignore specific revisions
  • Jared Hancock's avatar
    Jared Hancock committed
    <?php
    
    if (!defined('OSTSCPINC') || !$thisstaff
    
            || !$thisstaff->hasPerm(TicketModel::PERM_CREATE, false))
    
            die('Access Denied');
    
    
    Jared Hancock's avatar
    Jared Hancock committed
    $info=array();
    $info=Format::htmlchars(($errors && $_POST)?$_POST:$info);
    
    if (!$info['topicId'])
        $info['topicId'] = $cfg->getDefaultTopicId();
    
    
    if ($info['topicId'] && ($topic=Topic::lookup($info['topicId']))) {
    
        foreach ($topic->getForms() as $F) {
    
            if (!$F->hasAnyVisibleFields())
                continue;
    
            if ($_POST) {
                $F = $F->instanciate();
                $F->isValidForClient();
            }
            $forms[] = $F;
    
        $info['duedate'] = Format::date(strtotime($info['duedate']), false, false, 'UTC');
    
    Jared Hancock's avatar
    Jared Hancock committed
    ?>
    
    Kevin Thorne's avatar
    Kevin Thorne committed
    <form action="tickets.php?a=open" method="post" class="save"  enctype="multipart/form-data">
    
     <?php csrf_token(); ?>
    
    Jared Hancock's avatar
    Jared Hancock committed
     <input type="hidden" name="do" value="create">
     <input type="hidden" name="a" value="open">
    
    <div style="margin-bottom:20px; padding-top:5px;">
        <div class="pull-left flush-left">
            <h2><?php echo __('Open a New Ticket');?></h2>
        </div>
    </div>
    
     <table class="form_table fixed" width="940" border="0" cellspacing="0" cellpadding="2">
    
    Jared Hancock's avatar
    Jared Hancock committed
        <thead>
    
        <!-- This looks empty - but beware, with fixed table layout, the user
             agent will usually only consult the cells in the first row to
             construct the column widths of the entire toable. Therefore, the
             first row needs to have two cells -->
    
            <tr><td style="padding:0;"></td><td style="padding:0;"></td></tr>
    
    Jared Hancock's avatar
    Jared Hancock committed
        </thead>
        <tbody>
    
            <tr>
                <th colspan="2">
    
                    <em><strong><?php echo __('User Information'); ?></strong>: </em>
    
                    <div class="error"><?php echo $errors['user']; ?></div>
    
                </th>
            </tr>
            <?php
            if ($user) { ?>
    
            <tr><td><?php echo __('User'); ?>:</td><td>
    
                    <input type="hidden" name="uid" id="uid" value="<?php echo $user->getId(); ?>" />
    
                <a href="#" onclick="javascript:
                    $.userLookup('ajax.php/users/<?php echo $user->getId(); ?>/edit',
                            function (user) {
    
                                $('#user-name').text(user.name);
                                $('#user-email').text(user.email);
    
                            });
                    return false;
                    "><i class="icon-user"></i>
    
                    <span id="user-name"><?php echo Format::htmlchars($user->getName()); ?></span>
    
                    &lt;<span id="user-email"><?php echo $user->getEmail(); ?></span>&gt;
    
                    <a class="inline button" style="overflow:inherit" href="#"
    
                        onclick="javascript:
    
                            $.userLookup('ajax.php/users/select/'+$('input#uid').val(),
    
                                function(user) {
                                    $('input#uid').val(user.id);
    
                                    $('#user-name').text(user.name);
                                    $('#user-email').text('<'+user.email+'>');
    
                            });
                            return false;
    
                        "><i class="icon-retweet"></i> <?php echo __('Change'); ?></a>
    
                </div>
            </td></tr>
            <?php
            } else { //Fallback: Just ask for email and name
                ?>
            <tr>
    
                <td width="160" class="required"> <?php echo __('Email Address'); ?>: </td>
    
                    <div class="attached input">
                        <input type="text" size=45 name="email" id="user-email" class="attached"
    
                            autocomplete="off" autocorrect="off" value="<?php echo $info['email']; ?>" /> </span>
    
                    <a href="?a=open&amp;uid={id}" data-dialog="ajax.php/users/lookup/form"
                        class="attached button"><i class="icon-search"></i></a>
                    </div>
    
                    <span class="error">*</span>
                    <div class="error"><?php echo $errors['email']; ?></div>
    
                <td width="160" class="required"> <?php echo __('Full Name'); ?>: </td>
    
                <td>
                    <span style="display:inline-block;">
                        <input type="text" size=45 name="name" id="user-name" value="<?php echo $info['name']; ?>" /> </span>
    
                    <span class="error">*</span>
                    <div class="error"><?php echo $errors['name']; ?></div>
    
            <?php
            if($cfg->notifyONNewStaffTicket()) {  ?>
    
    Jared Hancock's avatar
    Jared Hancock committed
            <tr>
    
                <td width="160"><?php echo __('Ticket Notice'); ?>:</td>
    
    Jared Hancock's avatar
    Jared Hancock committed
                <td>
    
                <input type="checkbox" name="alertuser" <?php echo (!$errors || $info['alertuser'])? 'checked="checked"': ''; ?>><?php
                    echo __('Send alert to user.'); ?>
    
    Jared Hancock's avatar
    Jared Hancock committed
                </td>
            </tr>
    
            <?php
            } ?>
        </tbody>
        <tbody>
    
    Jared Hancock's avatar
    Jared Hancock committed
            <tr>
                <th colspan="2">
    
                    <em><strong><?php echo __('Ticket Information and Options');?></strong>:</em>
    
    Jared Hancock's avatar
    Jared Hancock committed
                </th>
            </tr>
            <tr>
                <td width="160" class="required">
    
                    <?php echo __('Ticket Source');?>:
    
    Jared Hancock's avatar
    Jared Hancock committed
                </td>
                <td>
                    <select name="source">
    
    Peter Rotich's avatar
    Peter Rotich committed
                        <?php
                        $source = $info['source'] ?: 'Phone';
    
    Peter Rotich's avatar
    Peter Rotich committed
                        $sources = Ticket::getSources();
                        unset($sources['Web'], $sources['API']);
                        foreach ($sources as $k => $v)
    
    Peter Rotich's avatar
    Peter Rotich committed
                            echo sprintf('<option value="%s" %s>%s</option>',
                                    $k,
                                    ($source == $k ) ? 'selected="selected"' : '',
                                    $v);
                        ?>
    
    Jared Hancock's avatar
    Jared Hancock committed
                    </select>
    
                    &nbsp;<font class="error"><b>*</b>&nbsp;<?php echo $errors['source']; ?></font>
    
    Jared Hancock's avatar
    Jared Hancock committed
                </td>
            </tr>
            <tr>
                <td width="160" class="required">
    
                    <?php echo __('Help Topic'); ?>:
    
    Jared Hancock's avatar
    Jared Hancock committed
                </td>
                <td>
    
                    <select name="topicId" onchange="javascript:
    
                            var data = $(':input[name]', '#dynamic-form').serialize();
    
                            $.ajax(
                              'ajax.php/form/help-topic/' + this.value,
                              {
                                data: data,
                                dataType: 'json',
                                success: function(json) {
                                  $('#dynamic-form').empty().append(json.html);
                                  $(document.head).append(json.media);
                                }
                              });">
    
    Jared Hancock's avatar
    Jared Hancock committed
                        <?php
    
                        if ($topics=Topic::getHelpTopics(false, false, true)) {
    
                            if (count($topics) == 1)
                                $selected = 'selected="selected"';
                            else { ?>
    
                            <option value="" selected >&mdash; <?php echo __('Select Help Topic'); ?> &mdash;</option>
    
                            foreach($topics as $id =>$name) {
    
                                echo sprintf('<option value="%d" %s %s>%s</option>',
                                    $id, ($info['topicId']==$id)?'selected="selected"':'',
                                    $selected, $name);
                            }
    
                            if (count($topics) == 1 && !$forms) {
    
                                if (($T = Topic::lookup($id)))
    
                                    $forms =  $T->getForms();
    
    Jared Hancock's avatar
    Jared Hancock committed
                            }
                        }
                        ?>
                    </select>
    
                    &nbsp;<font class="error"><b>*</b>&nbsp;<?php echo $errors['topicId']; ?></font>
    
    Jared Hancock's avatar
    Jared Hancock committed
                </td>
            </tr>
            <tr>
    
                <td width="160">
    
                    <?php echo __('Department'); ?>:
    
    Jared Hancock's avatar
    Jared Hancock committed
                </td>
                <td>
    
                    <select name="deptId">
    
                        <option value="" selected >&mdash; <?php echo __('Select Department'); ?>&mdash;</option>
    
    Jared Hancock's avatar
    Jared Hancock committed
                        <?php
    
                        if($depts=Dept::getPublicDepartments()) {
    
                            foreach($depts as $id =>$name) {
    
                                if (!($role = $thisstaff->getRole($id))
                                    || !$role->hasPerm(Ticket::PERM_CREATE)
                                ) {
                                    // No access to create tickets in this dept
                                    continue;
                                }
    
    Jared Hancock's avatar
    Jared Hancock committed
                                echo sprintf('<option value="%d" %s>%s</option>',
    
                                        $id, ($info['deptId']==$id)?'selected="selected"':'',$name);
    
    Jared Hancock's avatar
    Jared Hancock committed
                            }
                        }
                        ?>
                    </select>
    
                    &nbsp;<font class="error"><?php echo $errors['deptId']; ?></font>
    
    Jared Hancock's avatar
    Jared Hancock committed
                </td>
            </tr>
    
    Peter Rotich's avatar
    Peter Rotich committed
             <tr>
                <td width="160">
    
                    <?php echo __('SLA Plan');?>:
    
    Jared Hancock's avatar
    Jared Hancock committed
                </td>
    
    Peter Rotich's avatar
    Peter Rotich committed
                <td>
                    <select name="slaId">
    
                        <option value="0" selected="selected" >&mdash; <?php echo __('System Default');?> &mdash;</option>
    
    Jared Hancock's avatar
    Jared Hancock committed
                        <?php
    
    Peter Rotich's avatar
    Peter Rotich committed
                        if($slas=SLA::getSLAs()) {
                            foreach($slas as $id =>$name) {
                                echo sprintf('<option value="%d" %s>%s</option>',
                                        $id, ($info['slaId']==$id)?'selected="selected"':'',$name);
    
    Peter Rotich's avatar
    Peter Rotich committed
                    </select>
                    &nbsp;<font class="error">&nbsp;<?php echo $errors['slaId']; ?></font>
    
    Jared Hancock's avatar
    Jared Hancock committed
                </td>
    
    Peter Rotich's avatar
    Peter Rotich committed
             </tr>
    
    Peter Rotich's avatar
    Peter Rotich committed
             <tr>
    
    Jared Hancock's avatar
    Jared Hancock committed
                <td width="160">
    
                    <?php echo __('Due Date');?>:
    
    Jared Hancock's avatar
    Jared Hancock committed
                </td>
                <td>
    
    Peter Rotich's avatar
    Peter Rotich committed
                    <input class="dp" id="duedate" name="duedate" value="<?php echo Format::htmlchars($info['duedate']); ?>" size="12" autocomplete=OFF>
    
    Jared Hancock's avatar
    Jared Hancock committed
                    &nbsp;&nbsp;
                    <?php
                    $min=$hr=null;
                    if($info['time'])
    
    Peter Rotich's avatar
    Peter Rotich committed
                        list($hr, $min)=explode(':', $info['time']);
    
    Peter Rotich's avatar
    Peter Rotich committed
                    echo Misc::timeDropdown($hr, $min, 'time');
    
                    &nbsp;<font class="error">&nbsp;<?php echo $errors['duedate']; ?> &nbsp; <?php echo $errors['time']; ?></font>
    
                    <em><?php echo __('Time is based on your time zone');?> (GMT <?php echo Format::date(false, false, 'ZZZ'); ?>)</em>
    
    Jared Hancock's avatar
    Jared Hancock committed
                </td>
            </tr>
    
    Jared Hancock's avatar
    Jared Hancock committed
            <?php
    
            if($thisstaff->hasPerm(TicketModel::PERM_ASSIGN, false)) { ?>
    
    Jared Hancock's avatar
    Jared Hancock committed
            <tr>
    
                <td width="160"><?php echo __('Assign To');?>:</td>
    
    Jared Hancock's avatar
    Jared Hancock committed
                <td>
                    <select id="assignId" name="assignId">
    
                        <option value="0" selected="selected">&mdash; <?php echo __('Select an Agent OR a Team');?> &mdash;</option>
    
    Jared Hancock's avatar
    Jared Hancock committed
                        <?php
                        if(($users=Staff::getAvailableStaffMembers())) {
    
                            echo '<OPTGROUP label="'.sprintf(__('Agents (%d)'), count($users)).'">';
    
    Jared Hancock's avatar
    Jared Hancock committed
                            foreach($users as $id => $name) {
                                $k="s$id";
                                echo sprintf('<option value="%s" %s>%s</option>',
                                            $k,(($info['assignId']==$k)?'selected="selected"':''),$name);
                            }
                            echo '</OPTGROUP>';
                        }
    
    Jared Hancock's avatar
    Jared Hancock committed
                        if(($teams=Team::getActiveTeams())) {
    
                            echo '<OPTGROUP label="'.sprintf(__('Teams (%d)'), count($teams)).'">';
    
    Jared Hancock's avatar
    Jared Hancock committed
                            foreach($teams as $id => $name) {
                                $k="t$id";
                                echo sprintf('<option value="%s" %s>%s</option>',
                                            $k,(($info['assignId']==$k)?'selected="selected"':''),$name);
                            }
                            echo '</OPTGROUP>';
                        }
                        ?>
                    </select>&nbsp;<span class='error'>&nbsp;<?php echo $errors['assignId']; ?></span>
                </td>
            </tr>
    
    Jared Hancock's avatar
    Jared Hancock committed
            </tbody>
            <tbody id="dynamic-form">
    
                foreach ($forms as $form) {
    
                    print $form->getForm()->getMedia();
    
                    include(STAFFINC_DIR .  'templates/dynamic-form.tmpl.php');
                }
    
    Jared Hancock's avatar
    Jared Hancock committed
            </tbody>
            <tbody>
    
            <?php
            //is the user allowed to post replies??
    
            if ($thisstaff->getRole()->hasPerm(TicketModel::PERM_REPLY)) { ?>
    
    Jared Hancock's avatar
    Jared Hancock committed
            <tr>
    
    Peter Rotich's avatar
    Peter Rotich committed
                <th colspan="2">
    
                    <em><strong><?php echo __('Response');?></strong>: <?php echo __('Optional response to the above issue.');?></em>
    
    Peter Rotich's avatar
    Peter Rotich committed
                </th>
            </tr>
            <tr>
                <td colspan=2>
                <?php
                if(($cannedResponses=Canned::getCannedResponses())) {
    
                    <div style="margin-top:0.3em;margin-bottom:0.5em">
    
                        <?php echo __('Canned Response');?>:&nbsp;
    
    Peter Rotich's avatar
    Peter Rotich committed
                        <select id="cannedResp" name="cannedResp">
    
                            <option value="0" selected="selected">&mdash; <?php echo __('Select a canned response');?> &mdash;</option>
    
    Peter Rotich's avatar
    Peter Rotich committed
                            <?php
                            foreach($cannedResponses as $id =>$title) {
                                echo sprintf('<option value="%d">%s</option>',$id,$title);
                            }
                            ?>
                        </select>
    
                        &nbsp;&nbsp;
                        <label class="checkbox inline"><input type='checkbox' value='1' name="append" id="append" checked="checked"><?php echo __('Append');?></label>
    
    Peter Rotich's avatar
    Peter Rotich committed
                    </div>
                <?php
    
                }
                    $signature = '';
                    if ($thisstaff->getDefaultSignatureType() == 'mine')
                        $signature = $thisstaff->getSignature(); ?>
    
                        class="<?php if ($cfg->isRichTextEnabled()) echo 'richtext';
    
                            ?> draft draft-delete" data-signature="<?php
    
                            echo Format::htmlchars(Format::viewableImages($signature)); ?>"
                        data-signature-field="signature" data-dept-field="deptId"
    
                        placeholder="<?php echo __('Initial response for the ticket'); ?>"
    
                        name="response" id="response" cols="21" rows="8"
    
                        style="width:80%;" <?php
        list($draft, $attrs) = Draft::getDraftAndDataAttrs('ticket.staff.response', false, $info['response']);
    
        echo $attrs; ?>><?php echo $_POST ? $info['response'] : $draft;
    
                        <div class="attachments">
    
    <?php
    print $response_form->getField('attachments')->render();
    ?>
    
                    <table border="0" cellspacing="0" cellpadding="2" width="100%">
    
                <tr>
                    <td width="100"><?php echo __('Ticket Status');?>:</td>
                    <td>
                        <select name="statusId">
                        <?php
                        $statusId = $info['statusId'] ?: $cfg->getDefaultTicketStatusId();
                        $states = array('open');
    
                        if ($thisstaff->hasPerm(TicketModel::PERM_CLOSE, false))
    
    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</option>',
                                    $s->getId(),
                                    $selected
                                     ? 'selected="selected"' : '',
                                    __($s->getName()));
                        }
                        ?>
                        </select>
                    </td>
                </tr>
    
    Peter Rotich's avatar
    Peter Rotich committed
                 <tr>
    
                    <td width="100"><?php echo __('Signature');?>:</td>
    
    Peter Rotich's avatar
    Peter Rotich committed
                    <td>
                        <?php
                        $info['signature']=$info['signature']?$info['signature']:$thisstaff->getDefaultSignatureType();
                        ?>
    
                        <label><input type="radio" name="signature" value="none" checked="checked"> <?php echo __('None');?></label>
    
    Peter Rotich's avatar
    Peter Rotich committed
                        <?php
                        if($thisstaff->getSignature()) { ?>
                            <label><input type="radio" name="signature" value="mine"
    
                                <?php echo ($info['signature']=='mine')?'checked="checked"':''; ?>> <?php echo __('My Signature');?></label>
    
    Peter Rotich's avatar
    Peter Rotich committed
                        <?php
                        } ?>
                        <label><input type="radio" name="signature" value="dept"
    
                            <?php echo ($info['signature']=='dept')?'checked="checked"':''; ?>> <?php echo sprintf(__('Department Signature (%s)'), __('if set')); ?></label>
    
    Peter Rotich's avatar
    Peter Rotich committed
                    </td>
                 </tr>
                </table>
                </td>
            </tr>
    
    Peter Rotich's avatar
    Peter Rotich committed
            <tr>
                <th colspan="2">
    
                    <em><strong><?php echo __('Internal Note');?></strong>
    
                    <font class="error">&nbsp;<?php echo $errors['note']; ?></font></em>
    
    Peter Rotich's avatar
    Peter Rotich committed
                </th>
            </tr>
            <tr>
                <td colspan=2>
    
                        class="<?php if ($cfg->isRichTextEnabled()) echo 'richtext';
    
                            ?> draft draft-delete"
    
                        placeholder="<?php echo __('Optional internal note (recommended on assignment)'); ?>"
    
                        name="note" cols="21" rows="6" style="width:80%;" <?php
        list($draft, $attrs) = Draft::getDraftAndDataAttrs('ticket.staff.note', false, $info['note']);
    
        echo $attrs; ?>><?php echo $_POST ? $info['note'] : $draft;
    
    Jared Hancock's avatar
    Jared Hancock committed
                </td>
            </tr>
        </tbody>
    </table>
    
    <p style="text-align:center;">
    
        <input type="submit" name="submit" value="<?php echo _P('action-button', 'Open');?>">
    
        <input type="reset"  name="reset"  value="<?php echo __('Reset');?>">
        <input type="button" name="cancel" value="<?php echo __('Cancel');?>" onclick="javascript:
    
            $('.richtext').each(function() {
                var redactor = $(this).data('redactor');
                if (redactor && redactor.opts.draftDelete)
                    redactor.deleteDraft();
            });
            window.location.href='tickets.php';
        ">
    
    Jared Hancock's avatar
    Jared Hancock committed
    </p>
    </form>
    
    <script type="text/javascript">
    $(function() {
        $('input#user-email').typeahead({
            source: function (typeahead, query) {
                $.ajax({
                    url: "ajax.php/users?q="+query,
                    dataType: 'json',
                    success: function (data) {
                        typeahead.process(data);
                    }
                });
            },
            onselect: function (obj) {
                $('#uid').val(obj.id);
                $('#user-name').val(obj.name);
                $('#user-email').val(obj.email);
            },
            property: "/bin/true"
        });
    
    
       <?php
        // Popup user lookup on the initial page load (not post) if we don't have a
        // user selected
        if (!$_POST && !$user) {?>
    
        setTimeout(function() {
          $.userLookup('ajax.php/users/lookup/form', function (user) {
    
            window.location.href = window.location.href+'&uid='+user.id;