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

<div id="primary_content">
  <div id="primary_content_inner">
  <div id="Flash" class="flash_notice"></div>
  <div id="excluded" href='<?php echo $this->moduleBaseUrl ?>/users/excludedlink'></div>

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

    <input type="hidden" name="save" value="1" />
	<!-- Specify default settings not available to edit -->

    <table class="settings">

		<tr>
			<td class="label"><?php print $this->translate('Groups default POP3 state')?></td>
			<td>
				<input name="fields[POP3Support]" type='hidden' value='0'/>
				<input name="fields[POP3Support]" type="checkbox" class="iphoneStyle" value="1" <?php echo ($this->groupDefault['POP3Support']==1 ? 'checked' : '') ?>>
				<small><?php print $this->translate('Default state for new groups. Allow POP3 connections. This allows group users to connect to your server via any standard mail-client using POP3')?></small>
			</td>
		</tr>
		<tr>
			<td class="label"><?php print $this->translate('Groups default IMAP state')?></td>
			<td>
				<input name="fields[IMAPSupport]" type='hidden' value='0'/>
				<input name="fields[IMAPSupport]" type="checkbox" class="iphoneStyle" value="1" <?php echo ($this->groupDefault['IMAPSupport']==1 ? 'checked' : '') ?>>
				<small><?php print $this->translate('Default state for new groups. Allow IMAP connections. This allows group users to connect to your server via any standard mail-client using IMAP')?></small>
			</td>
		</tr>
	
	</table>
	
	<div class="divider"></div>
	
	<table class="settings">

      <tr>
        <td class="label"><?php print $this->translate('Enable SSL POP3/IMAP')?></td>
        <td>
			<input name="fields[imapssl_enable]" type='hidden' value='0'/>
			<input name="fields[imapssl_enable]" type="checkbox" id="imapssl_enable" class="iphoneStyle" value="1" <?php echo ($this->dovecot['imapssl_enable']) ? 'checked' : '' ?>>
			<small><?php print $this->translate('Allow SSL for POP3 and IMAP connections. This allows users to connect to your server securely via POP3 and IMAP.')?></small>
		</td>
      </tr>

      <tr id='sslCertPath'>
        <td class='label'><label class='settings_label'><?php print $this->translate('SSL Certificate Path')?></label></td>
        <td>
			<input type="text" class="large" name="fields[imapssl_cert]" id="imapssl_cert" value="<?php echo $this->dovecot['imapssl_cert'] ?>" />
			<small><?php print $this->translate('Specify the path to your SSL Certificate file.')?></small>
		</td>
      </tr>

      <tr id='sslKeyPath'>
        <td class='label'><label class='settings_label'><?php print $this->translate('SSL Key Path')?></label></td>
        <td>
			<input type="text" class="large" name="fields[imapssl_key]" id="imapssl_key" value="<?php echo $this->dovecot['imapssl_key'] ?>" />
			<small><?php print $this->translate('Specify the path to your SSL Key file.')?></small>
		</td>
      </tr>

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

	<table class="settings">

      <tr>
		<td class="label"><?php print $this->translate('Default Domain')?></td>
        <td>
            <input type="text" class="large" name="fields[default_domain]" id="default_domain" value="<?php echo $this->dovecot['default_domain'] ?>" />
            <small><?php print $this->translate('Specify the default domain to use when authenticating via POP or IMAP, this is used when users do not specify a domain-name during authentication.')?></small>
		</td>
      </tr>

      <tr>
		<td class="label"><?php print $this->translate('Maximum POP3/IMAP processes')?></td>
        <td>
            <input type="text" class="small" name="fields[dovecot_max]" id="dovecot_max" value="<?php echo $this->dovecot['dovecot_max'] ?>" />
			<small><?php print $this->translate('Set the maximum POP3/IMAP processes to allow simultaneously.')?></small>
		</td>
      </tr>

      <tr>
		<td class="label"><?php print $this->translate('Maximum connections per IP')?></td>
        <td>
            <input type="text" class="small" name="fields[dovecot_maxperip]" id="dovecot_maxperip" value="<?php echo $this->dovecot['dovecot_maxperip'] ?>" />
			<small><?php print $this->translate('Set the maximum number of connections allowed per user/IP. Useful for preventing abuse and throttling connections from high-load.')?></small>
		</td>
      </tr>

	</table>

  </div>
  </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 = "#POP3IMAP";
	// bind to the form's submit event and cancel legacy submit
	$('#settingsForm', tabId).submit(function()
	{

	<?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;

	});
	perform_service_common_binds(tabId);

	$("#default_domain", tabId).alphanumeric({allow:".-"});
	$("#dovecot_max", tabId).numeric();
	$("#dovecot_maxperip", tabId).numeric();
	$("#imapssl_cert", tabId).alphanumeric({allow:".-/"});
	$("#imapssl_key", tabId).alphanumeric({allow:".-/"});
	//$("#imapssl_enable", tabId).bind('click', function() { enablessl(); });


	
	$("#imapssl_enable", tabId).change( function() { enableSettingsBox($("#imapssl_enable", tabId)); });
	enableSettingsBox($("#imapssl_enable", tabId));

});
</script>