<div id="primary_header">
  <h1><?php print $this->translate('Anti-Spam Settings')?></h1>

</div>

<div id="primary_content">
  <div id="primary_content_inner">
	
  <?php if( !empty($this->licenseExpired)) :?>
<div id="licence-error"><img class="regerror" src="<?php echo $this->siteBaseUrl; ?>images/icons/error.png"/><span><?php echo $this->licenseExpired ?></span></div>	
  <?php endif ?>

  <div id="Flash" class="flash_notice"><?php print $this->translate('The settings have been updated') ?></div>

  <form id="settingsForm" method="post" action="<?php echo $this->moduleBaseUrl ?>/services/spamsave">

    <input type="hidden" name="save" value="1" />

	<?php if ($this->global['install_type'] == 'server'): ?>

	<table class="settings">
      <tr>
        <td class="label"><?php print $this->translate('Enable SpamAssassin')?></td>
        <td>
			<input name="fields[filter_sa_enable]" type='hidden' value='0'/>
			<input name="fields[filter_sa_enable]" type="checkbox" class="iphoneStyle" id="filter_sa_enable" value="1" <?php echo ($this->exim['filter_sa_enable']) ? 'checked' : '' ?>>
			<small><?php print $this->translate('Enable SpamAssassin. SpamAssassin filters emails for spam, and automatically sets rules depending on what users allow or deny.')?></small></td>
      </tr>

      <tr>
        <td class="label"><?php print $this->translate('Enable Auto-Updates')?></td>
        <td>
			<input name="fields[spam_autoupdate]" type='hidden' value='0'/>
			<input name="fields[spam_autoupdate]" type="checkbox" class="iphoneStyle" id="spam_autoupdate" value="1" <?php echo ($this->exim['spam_autoupdate']) ? 'checked' : '' ?>>
			<small><?php print $this->translate('Enable auto-updates of Anti-Spam signatures on a daily basis. Protect user mailboxes with the latest Spam signatures.')?></small></td>
      </tr>

	</table>
	
	<div class="divider"></div>
	<table class="settings">

      <tr>
        <td class="label"><?php print $this->translate('Max Message Scan Size')?></td>
        <td>
			<input name="fields[filter_max_bodysize]" class="small" type="text" id="filter_max_bodysize" value="<?php echo $this->exim['filter_max_bodysize'] ?>">
			<small><?php print $this->translate('Specify the maximum email body size for scanning messages for Spam. Generally, spam messages are smaller in size, to avoid extra CPU cycles scanning larger messages a maximum size of 50kb is recommended. The server will discard scanning messages largest then the specified value.')?></small></td>
      </tr>

      <tr>
        <td class="label"><?php print $this->translate('Spam Points')?></td>
        <td>
			<fieldset class="slider">
				<select name="slider_required_hits" id="slider_required_hits" style="display:none;" disabled>
					<option value='1'>1</option>
					<option value='2'>2</option>
					<option value='3'>3</option>
					<option value='4'>4</option>
					<option value='5'>5</option>
					<option value='6'>6</option>
					<option value='7'>7</option>
					<option value='8'>8</option>
					<option value='9'>9</option>
					<option value='10'>10</option>
					<option value='11'>11</option>
					<option value='12'>12</option>
					<option value='13'>13</option>
					<option value='14'>14</option>
					<option value='15'>15</option>
					<option value='16'>16</option>
					<option value='17'>17</option>
					<option value='18'>18</option>
					<option value='19'>19</option>
					<option value='20'>20</option>
				</select>
				<select name="fields[filter_required_hits]" id="filter_required_hits" style="display:none;">
					<option value='1'>1</option>
					<option value='2'>2</option>
					<option value='3'>3</option>
					<option value='4'>4</option>
					<option value='5'>5</option>
					<option value='6'>6</option>
					<option value='7'>7</option>
					<option value='8'>8</option>
					<option value='9'>9</option>
					<option value='10'>10</option>
					<option value='11'>11</option>
					<option value='12'>12</option>
					<option value='13'>13</option>
					<option value='14'>14</option>
					<option value='15'>15</option>
					<option value='16'>16</option>
					<option value='17'>17</option>
					<option value='18'>18</option>
					<option value='19'>19</option>
					<option value='20'>20</option>
				</select>
			</fieldset>

			<div id='filter_required_hits_div'></div>
			<small><?php print $this->translate('Specify the number of points required to classify a message as Spam. Recommended value is 5.')?></small></td>
      </tr>

      <tr>
        <td class="label"><?php print $this->translate('Reject Spam Points')?></td>
        <td>
	
			<fieldset class="slider">
				<select name="slider_required_hits_reject" id="slider_required_hits_reject" style="display:none;">
					<option value='1'>1</option>
					<option value='2'>2</option>
					<option value='3'>3</option>
					<option value='4'>4</option>
					<option value='5'>5</option>
					<option value='6'>6</option>
					<option value='7'>7</option>
					<option value='8'>8</option>
					<option value='9'>9</option>
					<option value='10'>10</option>
					<option value='11'>11</option>
					<option value='12'>12</option>
					<option value='13'>13</option>
					<option value='14'>14</option>
					<option value='15'>15</option>
					<option value='16'>16</option>
					<option value='17'>17</option>
					<option value='18'>18</option>
					<option value='19'>19</option>
					<option value='20'>20</option>
				</select>
				<select name="fields[filter_required_hits_reject]" id="filter_required_hits_reject" style="display:none;">
					<option value='1'>1</option>
					<option value='2'>2</option>
					<option value='3'>3</option>
					<option value='4'>4</option>
					<option value='5'>5</option>
					<option value='6'>6</option>
					<option value='7'>7</option>
					<option value='8'>8</option>
					<option value='9'>9</option>
					<option value='10'>10</option>
					<option value='11'>11</option>
					<option value='12'>12</option>
					<option value='13'>13</option>
					<option value='14'>14</option>
					<option value='15'>15</option>
					<option value='16'>16</option>
					<option value='17'>17</option>
					<option value='18'>18</option>
					<option value='19'>19</option>
					<option value='20'>20</option>
				</select>
			</fieldset>
			
			<div id='filter_required_hits_reject_div'></div>
			
			<small><?php print $this->translate('Optionally for very high-scoring Spam messages, the email can be rejected at SMTP time to avoid wasting disk space and server resources. Specify which level to reject messages that match the score below. This setting will overwrite any user-level Spam preferences.')?></small></td>
      </tr>

     <tr>
        <td class="label"><?php print $this->translate('Spam Tag')?></td>
        <td>                        <input type="text" class="medium" name="fields[filter_subject_tag]" id="filter_subject_tag" value="<?php echo $this->exim['filter_subject_tag'] ?>" size="14" />
                        <small><?php print $this->translate('If a message is marked as Spam rewrite the header to include the following text.') . ' ' . $this->translate('Only applies to new users.') ?></small></td>
      </tr>

     <tr>
        <td class="label"><?php print $this->translate('Spam Treatment')?></td>
        <td style="padding-right: 8px !important;">       
			<div class="styled-select">
			        <span class="arrow"></span>                 
		<select name='fields[filter_spam_treatment]' id='filter_spam_treatment'>	
			<option value="mark">Mark as SPAM (default)</option>
			<option value="trash">Move to Spam folder</option>
			<option value="delete">Purge Message</option>
		</select>
		</div>
                        <small><?php print $this->translate('If a message is classified as Spam, select how the message will be treated for delivery.') . ' ' . $this->translate('Only applies to new users.') ?></small></td>
      </tr>

    <tr>
        <td class="label"><?php print $this->translate('Trusted Networks')?></td>
        <td>                        <input type="text" class="medium" name="fields[filter_trusted_networks]" id="filter_trusted_networks" value="<?php echo $this->exim['filter_trusted_networks'] ?>" size="30" />                        <small><?php print $this->translate('Optionally specify which networks are automatically trusted for not sending Spam. If the recipients IP address is contained in the IP range, the message will be trusted. By default the localhost and private IP ranges are included. Specify multiple IP with a comma.')?></small></td>
      </tr>

      <tr>
        <td class="label"><?php print $this->translate('Skip Trusted Networks')?></td>
        <td>
                        <input name="fields[filter_skip_trusted]" type='hidden' value='0'/>
                        <input name="fields[filter_skip_trusted]" type="checkbox" class="iphoneStyle" id="filter_skip_trusted" value="1" <?php echo ($this->exim['filter_skip_trusted']) ? 'checked' : '' ?>>
                        <small><?php print $this->translate('Optionally skip filtering outbound/inbound messages from users who have authenticated using SMTP, or if the users IP matches the Mail-relay table. This is used to avoid scanning trusted hosts for Spam messages, and reduces the load for outbound mail.')?></small></td>
      </tr>

	</table>

	<div class="divider"></div>
	<table class="settings">

      <tr>
        <td class="label"><?php print $this->translate('Enable Attachment Check')?></td>
        <td>
                        <input name="fields[filter_attach_check]" type='hidden' value='0'/>
                        <input name="fields[filter_attach_check]" type="checkbox" class="iphoneStyle" id="filter_attach_check" value="1" <?php echo ($this->exim['filter_attach_check']) ? 'checked' : '' ?>>                        <small><?php print $this->translate('Optionally you can block incoming messages that contain a specified file-extension. This will prevent the most common attachments infected with a virus from reaching user accounts.')?></small></td>      </tr>


    <tr>
        <td class="label"><label class="settings_label"><?php print $this->translate('Blocked Attachments')?></label></td>
        <td>
        	<input type="text" class="medium" name="fields[filter_blocked_attachments]" id="filter_blocked_attachments" value="<?php echo $this->exim['filter_blocked_attachments'] ?>" size="40" />
        	<small><?php print $this->translate('Specify attachment extensions to be blocked. Separate multiple entries with commas.')?></small>
        </td>
      </tr>

	</table>

	<div class="divider"></div>
	
	<table class="settings">

      <tr>        <td class="label"><?php print $this->translate('Enable DNSBL Support')?></td>
        <td>
                        <input name="fields[filter_rbl_support]" type='hidden' value='0'/>
                        <input name="fields[filter_rbl_support]" type="checkbox" class="iphoneStyle"  id="filter_rbl_support" value="1" <?php echo ($this->exim['filter_rbl_support']) ? 'checked' : '' ?>>
                        <small><?php print $this->translate('Check the box to enable support for Realtime Black List updating. Add additional servers to the DNSBL field with a comma.')?></small></td>
      </tr>

      <tr>
        <td class="label"><label class="settings_label"><?php print $this->translate('DNSBL Servers')?></label></td>
        <td>
                        <input type="text" class="medium" name="fields[filter_rbl_servers]" id="filter_rbl_servers" value="<?php echo $this->exim['filter_rbl_servers'] ?>" />
                        <small><?php print $this->translate('Specify RBL servers to use. Separate multiple entries with commas.')?></small></td>
      </tr>


    </table>

	<div class="divider"></div>
	
	<table class="settings">
      <tr>
        <td class="label"><?php print $this->translate('Enable URI-DNSBL Support')?></td>
        <td>
			<input name="fields[filter_uridns_support]" type='hidden' value='0'/>
			<input name="fields[filter_uridns_support]" type="checkbox" class="iphoneStyle" id="filter_uridns_support" value="1" <?php echo ($this->exim['filter_uridns_support']) ? 'checked' : '' ?>>
			<small><?php print $this->translate('URI-DNS Blacklist - Each URL contained in an email can be optionally cross checked against an RBL server - If a URL is found to be Spam, the score of the message will increase.')?></small></td>
      </tr>

      <tr>
        <td class="label"><label class="settings_label"><?php print $this->translate('URI-DNSBL Servers')?></label></td>
        <td>
                        <input type="text" class="medium" name="fields[filter_uridnsbl_servers]" id="filter_uridnsbl_servers" value="<?php echo $this->exim['filter_uridnsbl_servers'] ?>" />
                        <small><?php print $this->translate('Specify URI-DNSBL servers to use. Separate multiple entries with commas.')?></small></td>
      </tr>

	</table>

	<div class="divider"></div>	
	
	<table class="settings">
      <tr>
        <td class="label"><?php print $this->translate('Enable SPF Support')?></td>
        <td>
			<input name="fields[filter_spf_support]" type='hidden' value='0'/>
			<input name="fields[filter_spf_support]" type="checkbox" class="iphoneStyle" id="filter_spf_support" value="1" <?php echo ($this->exim['filter_spf_support']) ? 'checked' : '' ?>>
			<small><?php print $this->translate('SPF Module - Incoming messages are checked against DNS if the recipient domain has an SPF record, and if so, if the senders IP address is trusted. This module can avoid abuse from Spammers faking the senders domain.')?></small></td>
      </tr>

	</table>
	
	<div class="divider"></div>	

	<table class="settings">	
      <tr>
        <td class="label"><?php print $this->translate('Enable AWL Support')?></td>
        <td>
                        <input name="fields[filter_awl_support]" type='hidden' value='0'/>
                        <input name="fields[filter_awl_support]" type="checkbox" class="iphoneStyle" id="filter_awl_support" value="1" <?php echo ($this->exim['filter_awl_support']) ? 'checked' : '' ?>>                        <small><?php print $this->translate('Auto-White-List (AWL) - Each message scanned can be optionally recorded to a database indexed by the senders email address. This is helpful in training the Spam-filter to distinguish between legitimate email messages from specific senders, and helps reduce real emails been marked as Spam.')?></small></td>
      </tr>

      <tr>
        <td class="label"><?php print $this->translate('Database Statistics for AWL')?></td>
        <td>
			Loaded database records for AWL
			<small>
			<?php echo $this->awlTokens ?> <?php print $this->translate('Email entries') ?>
			</small>
		</td>
      </tr>

	  <tr>
        <td class="label">
			<label class="settings_label"><?php print $this->translate('AWL purge threshold ')?></label>
		</td>
        <td>
                        <input name="fields[filter_awl_purge_threshold]" type="text" id="filter_awl_purge_threshold" value="<?php echo $this->exim['filter_awl_purge_threshold']?>" size="4" />
                        <small><?php print $this->translate('Specify the maximum number of AWL entries before data will be automatically purged. Recommended value is 5000.')?></small></td>
      </tr>
      
	</table>
	
	<div class="divider"></div>
	
	<table class="settings">

      <tr>
        <td class="label"><?php print $this->translate('Enable Bayes Filtering')?></td>
        <td>
                        <input name="fields[filter_use_bayes]" type='hidden' value='0'/>
                        <input name="fields[filter_use_bayes]" type="checkbox" class="iphoneStyle" id="filter_use_bayes" value="1" <?php echo ($this->exim['filter_use_bayes']) ? 'checked' : '' ?>>
                        <small><?php print $this->translate('Check to enable Bayesian filtering for incoming messages. If enabled Atmail will automatically feed high-scoring emails ( or low-scoring for non-spam) into its learning systems. This enables the mail-server to adapt and block incoming Spam messages that match the filter.')?></small></td>
      </tr>

      <tr>
        <td class="label"><?php print $this->translate('Database Statistics for Bayes')?></td>
        <td>
			Loaded database tokens for bayesian filter
			<small>
			<?php echo $this->spamTokens ?> <?php print $this->translate('Spam Tokens') ?>
			-
			<?php echo $this->nonspamTokens ?> <?php echo $this->translate('Non-spam Tokens')?>
			</small>
		</td>
      </tr>

      <tr>
        <td class="label"><label class="settings_label"><?php print $this->translate('Auto-Learn Non-Spam Score')?></label></td>
        <td>
			<input type="text" class="small" name="fields[filter_bayes_auto_learn_threshold_nonspam]" id="filter_bayes_auto_learn_threshold_nonspam" value="<?php echo $this->exim['filter_bayes_auto_learn_threshold_nonspam'] ?>" />
			<small><?php print $this->translate('The non-Spam score threshold below, is what a mail has to score, to be fed into Bayesian learning systems.')?></small></td>
      </tr>

      <tr>
        <td class="label"><label class="settings_label"><?php print $this->translate('Auto-Learn Spam Score')?></label></td>
        <td>
			<input type="text" class="small" name="fields[filter_bayes_auto_learn_threshold_spam]" id="filter_bayes_auto_learn_threshold_spam" value="<?php echo $this->exim['filter_bayes_auto_learn_threshold_spam'] ?>" />
			<small><?php print $this->translate('The Spam score threshold below, is what a mail has to score, to be fed into Bayesian learning systems.')?></small></td>
      </tr>

      <tr>
        <td class="label"><label class="settings_label"><?php print $this->translate('Learning Threshold')?></label></td>
        <td>
			<input type="text" class="small" name="fields[filter_bayes_min_ham_num]" id="filter_bayes_min_ham_num" value="<?php echo $this->exim['filter_bayes_min_ham_num'] ?>" />
			<small><?php print $this->translate('To be accurate, the Bayes system does not activate until a certain number of non-spam and spam have been learned. The default is 200 of each, but you can optionally tune the setting below.')?></small></td>
      </tr>

    </table>

	 <div class='divider'/>
	
	 <table class='settings'>

      <tr>
        <td class="label"><?php print $this->translate('Whitelist senders')?></td>
        <td>
          <textarea name="whitelist_from" id="whitelist_from"><?php echo $this->spamSettings['whitelist_from'] ?></textarea>
          <small><?php print $this->translate('Specify a list of email addresses and domains to whitelist. Each entry must be on its own line. Any email or domain that matches will automatically be flagged as trusted without being classified as Spam.')?></small>
        </td>
      </tr>

      <tr>
        <td class="label"><?php print $this->translate('Blacklist senders')?></td>
        <td>
          <textarea name="blacklist_from" id="blacklist_from"><?php echo $this->spamSettings['blacklist_from'] ?></textarea>
          <small><?php print $this->translate('Specify a list of email addresses and domains to blacklist. Each entry must be on its own line. Any email or domain that matches will automatically be classified as Spam.')?></small>
        </td>
      </tr>

    </table>

  </div>
  
  <?php else: ?>
  <table class="settings">
      <tr>
        <td class="label"><?php print $this->translate('Enable Spam Reporting')?></td>
        <td>
			<input name="fields[enableSpamReporting]" type='hidden' value='0'/>
			<input name="fields[enableSpamReporting]" type="checkbox" class="iphoneStyle" id="enableSpamReporting" value="1" <?php echo ($this->global['enableSpamReporting']) ? 'checked' : '' ?>>
			<small><?php print $this->translate('With this option enabled users can report emails as "spam" or "not spam" and the emails will be forwarded to the addresses specified below. A third party anti-spam solution should be in place that monitors those addresses and processes the emails.'); ?></small>
        </td>
      </tr>
      <tr>
        <td class="label"><?php print $this->translate('Spam Address')?></td>
        <td>
			<input name="fields[reportSpamAddress]" type="text" id="reportSpamAddress" value="<?php echo $this->global['reportSpamAddress'] ?>">
			<small><?php print $this->translate('Define the email address that mail reported as spam will be forwarded to.')?></small>
		</td>
      </tr>
      <tr>
        <td class="label"><?php print $this->translate('Not-Spam Address')?></td>
        <td>
			<input name="fields[reportNotSpamAddress]" type="text" id="reportNotSpamAddress" value="<?php echo $this->global['reportNotSpamAddress'] ?>">
			<small><?php print $this->translate('Define the email address that mail reported as NOT spam will be forwarded to.')?></small>
		</td>
      </tr>
      <tr>
        <td class="label"><?php print $this->translate('SMTP Server')?></td>
        <td>
			<input name="fields[reportSpamSmtpServer]" type="text" id="reportSpamSmtpServer" value="<?php echo $this->global['reportSpamSmtpServer'] ?>">
			<small><?php print $this->translate('Define an alternate SMTP server to be used for sending the spam reports (must allow mail relaying from this server). If this is empty the default SMTP server settings will be used')?></small>
		</td>
      </tr>
	</table>
  <?php endif; ?>

  </form>
	<div id="back_button">
		<a href="#">
			<span class="stronglastword"><?php echo $this->translate('Save Settings') ?></span>
		</a>
	</div>
</div>

<script type="text/javascript">

$( function(){
	var tabId = "#Anti-Spam";

	<?php if ($this->global['install_type'] == 'server'): ?>

	$('#settingsForm', tabId).submit(function()
	{
		// Ensure, reject spam points > spam points ( won't work otherwise! )
		if( parseInt($("#filter_required_hits", tabId).val()) > parseInt($("#filter_required_hits_reject", tabId).val()) )
		{
			alert('<?php echo $this->translate("Spam points must be lower then Reject Spam points, please click the slider and change the desired value"); ?>');
			return false;
		}
		<?php if( file_exists("/usr/local/atmail/mailserver/bin/atmail-services-restart") ) //is appliance
		echo '$.simpleFlash( "' . addslashes($this->translate('Saving, please wait while appliance services are restarted.')) . '", "important");';
		?>

		return false;
	});
	
	<?php  endif; ?>
	perform_service_common_binds(tabId);

	<?php if ($this->global['install_type'] == 'server'): ?>
	$("#max_msg_size", tabId).numeric();
	$("#filter_required_hits", tabId).numeric();
	$("#filter_required_hits_reject", tabId).numeric();
	$("#filter_trusted_networks", tabId).numeric({allow:"./,"});
	$("#filter_blocked_attachments", tabId).alphanumeric({allow:".,"});
	$("#filter_bayes_auto_learn_threshold_nonspam", tabId).numeric({allow:"."});
	$("#filter_bayes_auto_learn_threshold_spam", tabId).numeric({allow:"."});
	$("#filter_bayes_min_ham_num", tabId).numeric();
	$("#filter_rbl_serbers", tabId).alphanumeric({allow:".,"});
	$("#filter_awl_purge_threshold", tabId).numeric({allow:"."});
	$("#filter_spam_treatment option", tabId).removeAttr('selected');
	$("#filter_spam_treatment option[value=<?php echo $this->exim['filter_spam_treatment'] ?>]", tabId).attr('selected', 'true');
	$("#filter_use_bayes", tabId).change( function() { enableSettingsBox($("#filter_use_bayes")); });
	$("#filter_rbl_support", tabId).change( function() { enableSettingsBox($("#filter_rbl_support")); });
	$("#filter_attach_check", tabId).change( function() { enableSettingsBox($("#filter_attach_check")); });
	$("#filter_uridns_support", tabId).change( function() { enableSettingsBox($("#filter_uridns_support")); });
	$("#filter_awl_support", tabId).change( function() { enableSettingsBox($("#filter_awl_support")); });

	enableSettingsBox($("#filter_use_bayes", tabId));
	enableSettingsBox($("#filter_rbl_support", tabId));
	enableSettingsBox($("#filter_attach_check", tabId));
	enableSettingsBox($("#filter_uridns_support", tabId));
	enableSettingsBox($("#filter_awl_support", tabId));

	//Spam Points Slider
	$('option[value=<?php echo $this->exim["filter_required_hits"] ?>]', '#filter_required_hits').attr('selected', true); 
	$('option[value=<?php echo $this->exim["filter_required_hits_reject"] ?>]', '#filter_required_hits_reject').attr('selected', true); 
	var options = {
	    sliderOptions: { range: false }
	};
	$('select#filter_required_hits, select#slider_required_hits', tabId).selectToUISlider(options);
	$('select#filter_required_hits_reject, select#slider_required_hits_reject', tabId).selectToUISlider(options);
	
	// Specifically hide the hidden slider
	$("#handle_slider_required_hits", tabId).css('display', 'none');
	$("#handle_slider_required_hits_reject", tabId).css('display', 'none');
	<?php endif; ?>
});
</script>
