<div style="margin-top:-8px;margin-bottom:10px;"><i class="icon-level-up icon-flip-horizontal icon-back-to-parent-list"></i> <a href="index.php?fuse=admin&view=emailrouting&controller=settings&settings=support">Email Routing</a></div>
<form id="form-emailRule" name="emailRule">
<input type="hidden" name="id" value="<?php echo $this->id; ?>" />
<div class="inputBlock">
    <label for="input-name" class="bold"><?php echo $this->user->lang('Rule Name'); ?>:</label>
    <input class="input-xlarge" type="text" id="name" name="name" value="<?php echo $this->name; ?>" />
</div>
<ul class="nav nav-tabs nav-tight-bottom">
    <li class="active"><span data-toggle="tab" data-target="#div-ruleSource"><a href="#"><?php echo $this->user->lang('Source'); ?></a></span></li>
    <li><span data-toggle="tab" data-target="#div-ruleType"><a href="#"><?php echo $this->user->lang('User Type'); ?></a></span></li>
    <li><span data-toggle="tab" data-target="#div-ruleAction"><a href="#"><?php echo $this->user->lang('Action'); ?></a></span></li>
</ul>
<div class="tab-content tab-content-border">
    <div id="div-ruleSource" class="tab-pane active">
        <div class="row-fluid">
            <div class="span6">
                <label class="bold"for="select-routingType"><?php echo $this->user->lang('Request Source'); ?></label>
                <select name="routingType" id="select-routingType" class="routingType" style="width: 100%;">
                    <option value="1"<?php if ($this->routingType == 1) { echo ' SELECTED'; } ?>><?php echo $this->user->lang('Email pipe forwarding'); ?></option>
                    <option value="2"<?php if ($this->routingType == 2) { echo ' SELECTED'; } ?>><?php echo $this->user->lang('Email POP3 fetching'); ?></option>
                    <option value="3"<?php if ($this->routingType == 3) { echo ' SELECTED'; } ?>><?php echo $this->user->lang('Public Section'); ?></option>
                </select>
            </div>
        </div>
        <div id="div-publicSection" style="display: none;">
            <div class="alert alert-info">
                <p><?php echo $this->user->lang('By creating this rule, you will be giving access to submitting a ticket in the public section.'); ?></p>
                <p><?php echo $this->user->lang('If the type of client (Guest or Registered) that enters a request in the public section doesn’t have an associated routing rule, then his request will be silently ignored. Therefore we recommend to have rules for all client types, setting autoresponders with the appropriate messages for those you don’t wish to process.'); ?></p>
            </div>
        </div>
        <div id="div-emailPipeForwarding" style="display: none;">
            <div class="row-fluid">
                <div class="span6">
                    <div class="help-icon" data-toggle="tooltip" title="<?php echo $this->user->lang('You can use * to apply to all incoming emails'); ?>" data-placement="left"></div>
                    <label for="input-routingFieldPipingEmails" class="bold"><?php echo $this->user->lang('Emails'); ?>:</label>
                    <input type="hidden" id="input-pipingEmails" class="select2-large" style="width: 100%;" name="pipingEmails" value="<?php echo $this->piping_emails; ?>" />
                </div>
                <div class="span6">
                    <div class="alert alert-block" style="margin-top: 25px;">
                        <p><?php echo $this->user->lang('Have each of the above Email addresses forwarded to'); ?>:</p>
                        <p class="text-info monospace"><?php echo $this->pipeCommand; ?></p>
                    </div>
                </div>
            </div>
        </div>
        <div id="div-emailPOP3Fetching" style="display: none;">
            <div class="alert alert-block">
                <p><?php echo $this->user->lang('This works in tandem with the Tickets Generator automation service, so you need to have it enabled for this routing rule to work.'); ?></p>
                <p><?php echo $this->user->lang('Prefix the hostname with ssl:// for SSL connections.'); ?></p>
            </div>
            <div class="row-fluid">
                <div class="span6">
                    <label for="input-pop3Hostname" class="bold"><?php echo $this->user->lang('Email server hostname'); ?>:</label>
                    <input type="text" id="input-pop3Hostname" class="input-xlarge" name="pop3Hostname" value="<?php echo $this->pop3Hostname; ?>" />
                </div>
                <div class="span6">
                    <label for="input-pop3Username" class="bold"><?php echo $this->user->lang('Email account username'); ?>:</label>
                    <input type="text" id="input-pop3Username" class="input-xlarge" name="pop3Username" value="<?php echo $this->pop3Username; ?>" />
                </div>
            </div>
            <div class="row-fluid">
                <div class="span6">
                    <label for="input-pop3Port" class="bold"><?php echo $this->user->lang('Email server port'); ?>:</label>
                    <input type="text" id="input-pop3Port" class="input-xlarge" name="pop3Port" value="<?php echo $this->pop3Port; ?>" />
                </div>
                <div class="span6">
                    <label for="input-pop3Password" class="bold"><?php echo $this->user->lang('Email account password'); ?>:</label>
                    <input value="<?php echo $this->pop3Password; ?>" type="password" id="input-pop3Password" class="input-xlarge" name="pop3Password" />
                </div>
            </div>
            <div class="help-icon" data-toggle="tooltip" title="<?php echo $this->user->lang('You can use * to apply to all incoming emails'); ?>" data-tooltip-gravity="e"></div>
            <label for="input-pop3Emails" class="bold"><?php echo $this->user->lang('Emails'); ?>:</label>
            <input type="hidden" id="input-pop3Emails" class="select2-large" style="width: 100%;" name="pop3Emails" value="<?php echo $this->pop3_emails; ?>" />
            <?php /*
            <label for="input-pop3DeleteEmails" class="bold checkbox">
                <input type="checkbox" id="input-pop3DeleteEmails" class="checkbox" name="pop3DeleteEmails" <?php if ($this->pop3DeleteEmails == 1) { echo ' CHECKED'; } ?>/>
                <?php echo $this->user->lang('Delete emails on server after retrieval?')?>
            </label>
             */ ?>
        </div>
    </div>
    <div id="div-ruleType" class="tab-pane row-fluid">
        <div class="span6">
            <label class="bold" for="select-userType"><?php echo $this->user->lang('User Type'); ?></label>
            <select id="select-userType" name="userType" style="width: 100%">
                <option value="3"<?php if ($this->userType == '3') { echo ' SELECTED'; } ?>><?php echo $this->user->lang('Any (Guests & Registered)'); ?></option>
                <option value="2"<?php if ($this->userType == '2') { echo ' SELECTED'; } ?>><?php echo $this->user->lang('Guests'); ?></option>
                <option value="1"<?php if ($this->userType == '1') { echo ' SELECTED'; } ?>><?php echo $this->user->lang('Registered'); ?></option>
                <option value="5"<?php if ($this->userType == '5') { echo ' SELECTED'; } ?>><?php echo $this->user->lang('Registered, but not using support email'); ?></option>
                <option value="4"<?php if ($this->userType == '4') { echo ' SELECTED'; } ?>><?php echo $this->user->lang('Registered, from selected groups'); ?></option>
            </select>
            <div id="div-selectRegisteredGroups" style="display: none;">
                <label for="input-targetGroups" class="bold"><?php echo $this->user->lang('Select Groups'); ?></label>
                <input type="hidden" id="input-targetGroups" name="targetGroups" value="<?php echo $this->targetGroups; ?>" />
            </div>
        </div>
    </div>
    <div id="div-ruleAction" class="tab-pane">
        <div class="row-fluid" style="height: 220px;">
            <div class="span6">
                <label for="input-autoresponderTemplateId" class="bold"><?php echo $this->user->lang('Autoresponder Template'); ?></label>
                <input id="input-autoresponderTemplateId" style="width: 100%;" type="hidden" name="autoresponderTemplateId" value="<?php echo $this->autoresponderTemplateId; ?>" />
                <label for="input-sendCopyTo" class="bold"><?php echo $this->user->lang('Send copy to'); ?>:</label>
                <input id="input-sendCopyTo" class="select2-large" style="width: 100%;" type="hidden" name="sendCopyTo" value="<?php echo $this->copyDestinataries; ?>" />
            </div>
            <div class="span6">
                <label for="input-openTicket" class="bold checkbox">
                    <input type="checkbox" name="openTicket" id="input-openTicket" class="checkbox" <?php if ($this->openTicket == 1) { echo 'CHECKED '; } ?>/>
                    <?php echo $this->user->lang('Open Ticket?'); ?>
                </label>
                <div id="div-openTicketOptions" style="display: none;">
                    <label for="select-targetPriority" class="bold"><?php echo $this->user->lang('Set to priority'); ?>:</label>
                    <select id="select-targetPriority" style="width: 270px;" name="targetPriority" data-placeholder="<?php echo $this->user->lang('Select ticket priority'); ?>">
                        <option value="3"<?php if ($this->targetPriority == 3) { echo ' selected="selected"'; } ?>><?php echo $this->user->lang('Low'); ?></option>
                        <option value="2"<?php if ($this->targetPriority == 2) { echo ' selected="selected"'; } ?>><?php echo $this->user->lang('Medium'); ?></option>
                        <option value="1"<?php if ($this->targetPriority == 1) { echo ' selected="selected"'; } ?>><?php echo $this->user->lang('High'); ?></option>
                    </select>
                    <label for="input-targetType" class="bold"><?php echo $this->user->lang('Set to type')?>:</label>
                    <input id="input-targetType" style="width: 270px;" type="hidden" name="targetType" data-placeholder="<?php echo $this->user->lang('Select ticket type'); ?>" value="<?php echo $this->targetType; ?>"/>
                    <label for="input-targetAssignee" class="bold"><?php echo $this->user->lang('Assign to'); ?>:</label>
                    <input id="input-targetAssignee" style="width: 270px;" type="hidden" name="targetAssignee" data-placeholder="<?php echo $this->user->lang('Select Assignee'); ?>" value="<?php echo $this->assignee; ?>" />
                </div>
            </div>
        </div>
        <div class="alert alert-info">
            <p><?php echo $this->user->lang('If you assign tickets under routing rules to something different than the Ticket Type Default Assignee, then it will over rule the settings under Ticket Type where you may already have a different Assignee selected.'); ?></p>
            <p><?php echo $this->user->lang('If you assign tickets to an admin under routing rules (instead of Department), then it will over rule the settings under Departments where you may already have a different admin selected to assign the tickets to.'); ?></p>
        </div>
    </div>
</div>
<div class="form-actions">
    <div class="pull-right">
        <button id="button-saveChanges" class="btn btn-primary"><?php echo $this->user->lang('Save Changes'); ?></button>
    </div>
</div>
</form>
<script data-cfasync="false" type="text/javascript">
    emailRule = {
        initial: {
            autoresponderTemplate: <?php echo json_encode($this->initialTemplate); ?>,
            targetType: <?php echo json_encode($this->initialTicketType); ?>,
            targetGroups: <?php echo json_encode($this->initialTargetGroups); ?>
        }
    };
</script>
