Skip to content
Snippets Groups Projects
filter.inc.php 18.6 KiB
Newer Older
Jared Hancock's avatar
Jared Hancock committed
<?php
if(!defined('OSTADMININC') || !$thisstaff || !$thisstaff->isAdmin()) die('Access Denied');
$matches=Filter::getSupportedMatches();
$match_types=Filter::getSupportedMatchTypes();
Peter Rotich's avatar
Peter Rotich committed
$info = $qs = array();
Jared Hancock's avatar
Jared Hancock committed
if($filter && $_REQUEST['a']!='add'){
    $title=__('Update Filter');
Jared Hancock's avatar
Jared Hancock committed
    $action='update';
    $submit_text=__('Save Changes');
Jared Hancock's avatar
Jared Hancock committed
    $info=array_merge($filter->getInfo(),$filter->getFlatRules());
    $info['id']=$filter->getId();
Peter Rotich's avatar
Peter Rotich committed
    $qs += array('id' => $filter->getId());
Jared Hancock's avatar
Jared Hancock committed
}else {
    $title=__('Add New Filter');
Jared Hancock's avatar
Jared Hancock committed
    $action='add';
    $submit_text=__('Add Filter');
Jared Hancock's avatar
Jared Hancock committed
    $info['isactive']=isset($info['isactive'])?$info['isactive']:0;
Peter Rotich's avatar
Peter Rotich committed
    $qs += array('a' => $_REQUEST['a']);
Jared Hancock's avatar
Jared Hancock committed
}
$info=Format::htmlchars(($errors && $_POST)?$_POST:$info);
?>
Peter Rotich's avatar
Peter Rotich committed
<form action="filters.php?<?php echo Http::build_query($qs); ?>" method="post" id="save">
 <?php csrf_token(); ?>
Jared Hancock's avatar
Jared Hancock committed
 <input type="hidden" name="do" value="<?php echo $action; ?>">
 <input type="hidden" name="a" value="<?php echo Format::htmlchars($_REQUEST['a']); ?>">
 <input type="hidden" name="id" value="<?php echo $info['id']; ?>">
 <h2><?php echo __('Ticket Filter');?></h2>
Jared Hancock's avatar
Jared Hancock committed
 <table class="form_table" width="940" border="0" cellspacing="0" cellpadding="2">
    <thead>
        <tr>
            <th colspan="2">
                <h4><?php echo $title; ?></h4>
                <em><?php echo __('Filters are executed based on execution order. Filter can target specific ticket source.');?></em>
Jared Hancock's avatar
Jared Hancock committed
            </th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td width="180" class="required">
              <?php echo __('Filter Name');?>:
Jared Hancock's avatar
Jared Hancock committed
            </td>
            <td>
                <input type="text" size="30" name="name" value="<?php echo $info['name']; ?>">
                &nbsp;<span class="error">*&nbsp;<?php echo $errors['name']; ?></span>
            </td>
        </tr>
        <tr>
            <td width="180" class="required">
              <?php echo __('Execution Order');?>:
Jared Hancock's avatar
Jared Hancock committed
            </td>
            <td>
                <input type="text" size="6" name="execorder" value="<?php echo $info['execorder']; ?>">
                <em>(1...99)</em>
Jared Hancock's avatar
Jared Hancock committed
                &nbsp;<span class="error">*&nbsp;<?php echo $errors['execorder']; ?></span>
                &nbsp;&nbsp;&nbsp;
                <input type="checkbox" name="stop_onmatch" value="1" <?php echo $info['stop_onmatch']?'checked="checked"':''; ?> >
                <?php echo __('<strong>Stop</strong> processing further on match!');?>
                &nbsp;<i class="help-tip icon-question-sign" href="#execution_order"></i>
Jared Hancock's avatar
Jared Hancock committed
            </td>
        </tr>
        <tr>
            <td width="180" class="required">
                <?php echo __('Filter Status');?>:
Jared Hancock's avatar
Jared Hancock committed
            </td>
            <td>
Peter Rotich's avatar
Peter Rotich committed
                <input type="radio" name="isactive" value="1" <?php echo
                $info['isactive']?'checked="checked"':''; ?>> <?php echo __('Active'); ?>
                <input type="radio" name="isactive" value="0" <?php echo !$info['isactive']?'checked="checked"':''; ?>
                > <?php echo __('Disabled'); ?>
Jared Hancock's avatar
Jared Hancock committed
                &nbsp;<span class="error">*&nbsp;</span>
            </td>
        </tr>
        <tr>
            <td width="180" class="required">
                <?php echo __('Target Channel');?>:
Jared Hancock's avatar
Jared Hancock committed
            </td>
            <td>
                <select name="target">
                   <option value="">&mdash; <?php echo __('Select a Channel');?> &mdash;</option>
                   <?php
                   foreach(Filter::getTargets() as $k => $v) {
                       echo sprintf('<option value="%s" %s>%s</option>',
                               $k, (($k==$info['target'])?'selected="selected"':''), $v);
                    }
Jared Hancock's avatar
Jared Hancock committed
                    $sql='SELECT email_id,email,name FROM '.EMAIL_TABLE.' email ORDER by name';
                    if(($res=db_query($sql)) && db_num_rows($res)) {
                        echo sprintf('<OPTGROUP label="%s">', __('System Emails'));
                        while(list($id,$email,$name)=db_fetch_row($res)) {
Jared Hancock's avatar
Jared Hancock committed
                            $selected=($info['email_id'] && $id==$info['email_id'])?'selected="selected"':'';
                            if($name)
                                $email=Format::htmlchars("$name <$email>");
                            echo sprintf('<option value="%d" %s>%s</option>',$id,$selected,$email);
                        }
                        echo '</OPTGROUP>';
Jared Hancock's avatar
Jared Hancock committed
                    }
                    ?>
                </select>
                &nbsp;
Peter Rotich's avatar
Peter Rotich committed
                <span class="error">*&nbsp;<?php echo $errors['target']; ?></span>&nbsp;
                <i class="help-tip icon-question-sign" href="#target_channel"></i>
Jared Hancock's avatar
Jared Hancock committed
            </td>
        </tr>
        <tr>
            <th colspan="2">
                <em><strong><?php echo __('Filter Rules');?></strong>: <?php
                echo __('Rules are applied based on the criteria.');?>&nbsp;<span class="error">*&nbsp;<?php echo
Peter Rotich's avatar
Peter Rotich committed
                $errors['rules']; ?></span></em>
Jared Hancock's avatar
Jared Hancock committed
            </th>
        </tr>
        <tr>
            <td colspan=2>
               <em><?php echo __('Rules Matching Criteria');?>:</em>
Jared Hancock's avatar
Jared Hancock committed
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                <input type="radio" name="match_all_rules" value="1" <?php echo $info['match_all_rules']?'checked="checked"':''; ?>><?php echo __('Match All');?>
Jared Hancock's avatar
Jared Hancock committed
                &nbsp;&nbsp;&nbsp;
                <input type="radio" name="match_all_rules" value="0" <?php echo !$info['match_all_rules']?'checked="checked"':''; ?>><?php echo __('Match Any');?>
Jared Hancock's avatar
Jared Hancock committed
                &nbsp;<span class="error">*&nbsp;</span>
                <em>(<?php echo __('case-insensitive comparison');?>)</em>
                &nbsp;<i class="help-tip icon-question-sign" href="#rules_matching_criteria"></i>
Jared Hancock's avatar
Jared Hancock committed
            </td>
        </tr>
        <?php
        $n=($filter?$filter->getNumRules():0)+2; //2 extra rules of unlimited.
        for($i=1; $i<=$n; $i++){ ?>
        <tr id="r<?php echo $i; ?>">
            <td colspan="2">
                    <select style="max-width: 200px;" name="rule_w<?php echo $i; ?>">
                        <option value="">&mdash; <?php echo __('Select One');?> &mdash;</option>
Jared Hancock's avatar
Jared Hancock committed
                        <?php
                        foreach ($matches as $group=>$ms) { ?>
                            <optgroup label="<?php echo __($group); ?>"><?php
                            foreach ($ms as $k=>$v) {
                                $sel=($info["rule_w$i"]==$k)?'selected="selected"':'';
                                echo sprintf('<option value="%s" %s>%s</option>',
                                    $k,$sel,__($v));
                            } ?>
                        </optgroup>
                        <?php } ?>
Jared Hancock's avatar
Jared Hancock committed
                    </select>
                    <select name="rule_h<?php echo $i; ?>">
Michael's avatar
Michael committed
                        <option value="0">&mdash; <?php echo __('Select One');?> &mdash;</option>
Jared Hancock's avatar
Jared Hancock committed
                        <?php
                        foreach($match_types as $k=>$v){
                            $sel=($info["rule_h$i"]==$k)?'selected="selected"':'';
                            echo sprintf('<option value="%s" %s>%s</option>',
Peter Rotich's avatar
Peter Rotich committed
                    </select>&nbsp;
                    <input class="ltr" type="text" size="60" name="rule_v<?php echo $i; ?>" value="<?php echo $info["rule_v$i"]; ?>">
Jared Hancock's avatar
Jared Hancock committed
                    &nbsp;<span class="error">&nbsp;<?php echo $errors["rule_$i"]; ?></span>
Jared Hancock's avatar
Jared Hancock committed
                if($info["rule_w$i"] || $info["rule_h$i"] || $info["rule_v$i"]){ ?>
                <div class="pull-right" style="padding-right:20px;"><a href="#" class="clearrule">(<?php echo __('clear');?>)</a></div>
Jared Hancock's avatar
Jared Hancock committed
                <?php
                } ?>
Jared Hancock's avatar
Jared Hancock committed
            </td>
        </tr>
        <?php
            if($i>=25) //Hardcoded limit of 25 rules...also see class.filter.php
               break;
        } ?>
        <tr>
            <th colspan="2">
                <em><strong><?php echo __('Filter Actions');?></strong>: <?php
                echo __('Can be overwridden by other filters depending on processing order.');?>&nbsp;</em>
Jared Hancock's avatar
Jared Hancock committed
            </th>
        </tr>
        <tr>
            <td width="180">
                <?php echo __('Reject Ticket');?>:
Jared Hancock's avatar
Jared Hancock committed
            </td>
            <td>
                <input type="checkbox" name="reject_ticket" value="1" <?php echo $info['reject_ticket']?'checked="checked"':''; ?> >
                    <strong><font class="error"><?php echo __('Reject Ticket');?></font></strong>
                    &nbsp;<i class="help-tip icon-question-sign" href="#reject_ticket"></i>
Jared Hancock's avatar
Jared Hancock committed
            </td>
        </tr>
        <tr>
            <td width="180">
                <?php echo __('Reply-To Email');?>:
Jared Hancock's avatar
Jared Hancock committed
            </td>
            <td>
                <input type="checkbox" name="use_replyto_email" value="1" <?php echo $info['use_replyto_email']?'checked="checked"':''; ?> >
                    <?php echo __('<strong>Use</strong> Reply-To Email');?> <em>(<?php echo __('if available');?>)</em>
                    &nbsp;<i class="help-tip icon-question-sign" href="#reply_to_email"></i></em>
Jared Hancock's avatar
Jared Hancock committed
            </td>
        </tr>
        <tr>
            <td width="180">
                <?php echo __('Ticket auto-response');?>:
Jared Hancock's avatar
Jared Hancock committed
            </td>
            <td>
                <input type="checkbox" name="disable_autoresponder" value="1" <?php echo $info['disable_autoresponder']?'checked="checked"':''; ?> >
                    <?php echo __('<strong>Disable</strong> auto-response.');?>
                    &nbsp;<i class="help-tip icon-question-sign" href="#ticket_auto_response"></i>
Jared Hancock's avatar
Jared Hancock committed
            </td>
        </tr>
        <tr>
            <td width="180">
                <?php echo __('Canned Response');?>:
                <select name="canned_response_id">
                    <option value="">&mdash; <?php echo __('None');?> &mdash;</option>
Peter Rotich's avatar
Peter Rotich committed
                    $sql='SELECT canned_id, title, isenabled FROM '.CANNED_TABLE .' ORDER by title';
                    if ($res=db_query($sql)) {
Peter Rotich's avatar
Peter Rotich committed
                        while (list($id, $title, $isenabled)=db_fetch_row($res)) {
                            $selected=($info['canned_response_id'] &&
                                    $id==$info['canned_response_id'])
                                ? 'selected="selected"' : '';
Peter Rotich's avatar
Peter Rotich committed

                            if (!$isenabled)
                                $title .= ' ' . __('(disabled)');
Peter Rotich's avatar
Peter Rotich committed

                            echo sprintf('<option value="%d" %s>%s</option>',
                                $id, $selected, $title);
                        }
                    }
                    ?>
                </select>
Josh Eldridge's avatar
Josh Eldridge committed
                &nbsp;<i class="help-tip icon-question-sign" href="#canned_response"></i>
Jared Hancock's avatar
Jared Hancock committed
        <tr>
            <td width="180">
                <?php echo __('Department');?>:
Jared Hancock's avatar
Jared Hancock committed
            </td>
            <td>
                <select name="dept_id">
                    <option value="">&mdash; <?php echo __('Default');?> &mdash;</option>
Jared Hancock's avatar
Jared Hancock committed
                    <?php
                    $sql='SELECT dept_id,dept_name FROM '.DEPT_TABLE.' dept ORDER by dept_name';
                    if(($res=db_query($sql)) && db_num_rows($res)){
                        while(list($id,$name)=db_fetch_row($res)){
                            $selected=($info['dept_id'] && $id==$info['dept_id'])?'selected="selected"':'';
                            echo sprintf('<option value="%d" %s>%s</option>',$id,$selected,$name);
                        }
                    }
                    ?>
                </select>
Josh Eldridge's avatar
Josh Eldridge committed
                &nbsp;<span class="error">*&nbsp;<?php echo $errors['dept_id']; ?></span>&nbsp;<i class="help-tip icon-question-sign" href="#department"></i>
Jared Hancock's avatar
Jared Hancock committed
            </td>
        </tr>
        <tr>
            <td width="180">
                <?php echo __('Status'); ?>:
            </td>
            <td>
                <span>
                <select name="status_id">
                    <option value="">&mdash; <?php echo __('Default'); ?> &mdash;</option>
                    foreach (TicketStatusList::getStatuses() as $status) {
                        $name = $status->getName();
                        if (!($isenabled = $status->isEnabled()))
                            $name.=' '.__('(disabled)');

                        echo sprintf('<option value="%d" %s %s>%s</option>',
                                $status->getId(),
                                ($info['status_id'] == $status->getId())
                                 ? 'selected="selected"' : '',
                                 $isenabled ? '' : 'disabled="disabled"',
                                 $name
                                );
                    }
                    ?>
                </select>
                &nbsp;
                <span class="error"><?php echo $errors['status_id']; ?></span>
                <i class="help-tip icon-question-sign" href="#status"></i>
                </span>
            </td>
        </tr>
Jared Hancock's avatar
Jared Hancock committed
        <tr>
            <td width="180">
                <?php echo __('Priority');?>:
Jared Hancock's avatar
Jared Hancock committed
            </td>
            <td>
                <select name="priority_id">
                    <option value="">&mdash; <?php echo __('Default');?> &mdash;</option>
Jared Hancock's avatar
Jared Hancock committed
                    <?php
                    $sql='SELECT priority_id,priority_desc FROM '.PRIORITY_TABLE.' pri ORDER by priority_urgency DESC';
                    if(($res=db_query($sql)) && db_num_rows($res)){
                        while(list($id,$name)=db_fetch_row($res)){
                            $selected=($info['priority_id'] && $id==$info['priority_id'])?'selected="selected"':'';
                            echo sprintf('<option value="%d" %s>%s</option>',$id,$selected,$name);
                        }
                    }
                    ?>
                </select>
                &nbsp;<span class="error">*&nbsp;<?php echo $errors['priority_id']; ?></span>
Josh Eldridge's avatar
Josh Eldridge committed
                &nbsp;<i class="help-tip icon-question-sign" href="#priority"></i>
Jared Hancock's avatar
Jared Hancock committed
            </td>
        </tr>
        <tr>
            <td width="180">
                <?php echo __('SLA Plan');?>:
Jared Hancock's avatar
Jared Hancock committed
            </td>
            <td>
                <select name="sla_id">
                    <option value="0">&mdash; <?php echo __('System Default');?> &mdash;</option>
Jared Hancock's avatar
Jared Hancock committed
                    <?php
                    if($slas=SLA::getSLAs()) {
                        foreach($slas as $id =>$name) {
                            echo sprintf('<option value="%d" %s>%s</option>',
                                    $id, ($info['sla_id']==$id)?'selected="selected"':'',$name);
Jared Hancock's avatar
Jared Hancock committed
                        }
                    }
                    ?>
                </select>
                &nbsp;<span class="error">&nbsp;<?php echo $errors['sla_id']; ?></span>
Josh Eldridge's avatar
Josh Eldridge committed
                &nbsp;<i class="help-tip icon-question-sign" href="#sla_plan"></i>
Jared Hancock's avatar
Jared Hancock committed
            </td>
        </tr>
        <tr>
            <td width="180">
                <?php echo __('Auto-assign To');?>:
Jared Hancock's avatar
Jared Hancock committed
            </td>
            <td>
                <select name="assign">
                    <option value="0">&mdash; <?php echo __('Unassigned');?> &mdash;</option>
Jared Hancock's avatar
Jared Hancock committed
                    <?php
                    if (($users=Staff::getStaffMembers())) {
                        echo '<OPTGROUP label="'.__('Agents').'">';
                        foreach($users as $id => $name) {
                            $name = new PersonsName($name);
Jared Hancock's avatar
Jared Hancock committed
                            $k="s$id";
                            $selected = ($info['assign']==$k || $info['staff_id']==$id)?'selected="selected"':'';
                            ?>
                            <option value="<?php echo $k; ?>"<?php echo $selected; ?>><?php echo $name; ?></option>
Jared Hancock's avatar
Jared Hancock committed
                        echo '</OPTGROUP>';
                    }
Peter Rotich's avatar
Peter Rotich committed
                    $sql='SELECT team_id, isenabled, name FROM '.TEAM_TABLE .' ORDER BY name';
Jared Hancock's avatar
Jared Hancock committed
                    if(($res=db_query($sql)) && db_num_rows($res)){
                        echo '<OPTGROUP label="'.__('Teams').'">';
Peter Rotich's avatar
Peter Rotich committed
                        while (list($id, $isenabled, $name) = db_fetch_row($res)){
Jared Hancock's avatar
Jared Hancock committed
                            $k="t$id";
                            $selected = ($info['assign']==$k || $info['team_id']==$id)?'selected="selected"':'';
Peter Rotich's avatar
Peter Rotich committed
                            if (!$isenabled)
                                $name .= ' (disabled)';
Jared Hancock's avatar
Jared Hancock committed
                            ?>
                            <option value="<?php echo $k; ?>"<?php echo $selected; ?>><?php echo $name; ?></option>
                        <?php
                        }
                        echo '</OPTGROUP>';
                    }
                    ?>
                </select>
Peter Rotich's avatar
Peter Rotich committed
                &nbsp;<span class="error">&nbsp;<?php echo
                $errors['assign']; ?></span><i class="help-tip icon-question-sign" href="#auto_assign"></i>
Jared Hancock's avatar
Jared Hancock committed
            </td>
        </tr>
        <tr>
            <td width="180">
                <?php echo __('Help Topic'); ?>
            </td>
            <td>
                <select name="topic_id">
                    <option value="0" selected="selected">&mdash; <?php
                        echo __('Unchanged'); ?> &mdash;</option>
                    <?php
                    $sql='SELECT topic_id, topic FROM '.TOPIC_TABLE.' T ORDER by topic';
                    if(($res=db_query($sql)) && db_num_rows($res)){
                        while(list($id,$name)=db_fetch_row($res)){
                            $selected=($info['topic_id'] && $id==$info['topic_id'])?'selected="selected"':'';
                            echo sprintf('<option value="%d" %s>%s</option>',$id,$selected,$name);
                        }
                    }
                    ?>
                </select>
Josh Eldridge's avatar
Josh Eldridge committed
                &nbsp;<span class="error"><?php echo $errors['topic_id']; ?></span><i class="help-tip icon-question-sign" href="#help_topic"></i>
Jared Hancock's avatar
Jared Hancock committed
        <tr>
            <th colspan="2">
                <em><strong><?php echo __('Internal Notes');?></strong>: <?php
                    echo __("be liberal, they're internal");?></em>
Jared Hancock's avatar
Jared Hancock committed
            </th>
        </tr>
        <tr>
            <td colspan=2>
                <textarea class="richtext no-bar" name="notes" cols="21"
                    rows="8" style="width: 80%;"><?php echo $info['notes']; ?></textarea>
Jared Hancock's avatar
Jared Hancock committed
            </td>
        </tr>
    </tbody>
</table>
<p style="text-align:center;">
Jared Hancock's avatar
Jared Hancock committed
    <input type="submit" name="submit" value="<?php echo $submit_text; ?>">
    <input type="reset"  name="reset"  value="<?php echo __('Reset');?>">
    <input type="button" name="cancel" value="<?php echo __('Cancel');?>" onclick='window.location.href="filters.php"'>
Jared Hancock's avatar
Jared Hancock committed
</p>
</form>