<div id="primary_header">
	<h1><?php print $this->translate('Service Provider settings')?></h1>
	<div id="back_button">
		<a href="#">
			<span class="stronglastword"><?php echo $this->translate('Save Settings') ?></span>
		</a>
	</div>
</div>

<div id="primary_content">
	<div id="primary_content_inner">

	<?php if( $this->formEnabled ): ?>
		<div id="Flash" class="flash_notice"><?php print $this->translate('The settings have been updated') ?></div>
	<?php else: ?>
	<div id="licence-error">
		<img src="<?php echo $this->siteBaseUrl; ?>/images/icons/error.png" class="regerror">

		<?php if( !$this->hasLicenseWithVOIP ): ?>
		<span>You need to purchase a UC license to use this feature.</span>
		<?php endif; ?>

	</div>	
	<?php endif; ?>

		<form id="settingsForm" method="post" action="<?php echo $this->moduleBaseUrl ?>/services/serviceproviderssave">
			<input type="hidden" name="save" value="1" />
			<table class="settings">
				<tr>
					<td class="label"><?php print $this->translate('Enable Service Providers')?></td>
					<td>
						<input name="fields[serviceProviders]" type='hidden' value="0"/>
						<input name="fields[serviceProviders]" type="checkbox" class="iphoneStyle affectsOthers" <?php if(!$this->formEnabled) echo 'disabled="disabled" '; ?> baseclassname="serviceProviders" value="1" <?php echo ($this->global['serviceProviders'] == '1' && $this->formEnabled) ? 'checked' : '' ?> />
						<small><?php print $this->translate('Enables/ Disables All Service Providers.')?></small>
					</td>
				</tr>
			</table>

			<div class="divider"></div>
			<table class="settings">
				<tr>
					<td class="label sip-label"><?php print $this->translate('SIP')?></td>
					<td>
						<input name="fields[SIPEnabled]" type='hidden' value="0"/>
						<input name="fields[SIPEnabled]" type="checkbox" class="iphoneStyle serviceProvidersDependant affectsOthers" baseclassname="serviceProvidersSIP" value="1" <?php echo ($this->global['SIPEnabled'] == '1') ? 'checked' : '' ?> />
						<small><?php print $this->translate('Enables/ Disables All SIP Services.')?></small>
					</td>
				</tr>
				<?php /* 
				<tr>
					<td class="label"><?php print $this->translate('SIP Gateway')?></td>
					<td>
						<input name="fields[enableFacebookFriendsAutoImport]" type='hidden' value="0"/>
						<input name="fields[enableFacebookFriendsAutoImport]" type="checkbox" class="iphoneStyle serviceProvidersFacebookDependant" value="1" <?php echo ($this->global['enableFacebookFriendsAutoImport'] == '1') ? 'checked' : '' ?> />
						<small><?php print $this->translate('Select the SIP gateway being used.')?></small>
					</td>
				</tr>
				*/ ?>
				<input type="hidden" name="fields[SIPgwMode]" value="flashphoner" />
				<tr>
					<td class="label"><?php print $this->translate('VOIP Gateway address')?></td>
					<td>
						<input name="fields[SIPgwAddress]" class="serviceProvidersSIPDependant" value="<?php echo $this->global['SIPgwAddress'] ?>" />
						<small><?php print $this->translate('The IP address or hostname of the Atmail VOIP gateway being used (N.B. Atmail VOIP Gateway, not the endpoint SIP server).')?></small>
					</td>
				</tr>

				<tr>
					<td class="label"><?php print $this->translate('SIP Server address')?></td>
					<td>
						<input name="fields[SIPServerAddress]" class="serviceProvidersSIPDependant" value="<?php echo $this->global['SIPServerAddress'] ?>" />
						<small><?php print $this->translate('The IP address or hostname of the SIP Server being used (N.B. Not the Atmail VOIP Gateway address.')?></small>
					</td>
				</tr>

				<tr>
					<td class="label"><?php print $this->translate('SIP Service Type')?></td>
					<td>
						<input type="radio" name="fields[SIPType]" class="serviceProvidersSIPDependant" value="SAMSUNG" <?php echo $this->global['SIPType']=="SAMSUNG"? 'checked' : '' ?> style="margin-right: 4px;" />SAMSUNG(IMS)&nbsp;&nbsp;&nbsp;&nbsp;
						<input type="radio" name="fields[SIPType]" class="serviceProvidersSIPDependant" value="SIP" <?php echo $this->global['SIPType']=="SIP"? 'checked' : '' ?> style="margin-right: 4px;" />Generic SIP
						<small><?php print $this->translate('Select a SIP Type')?></small>
					</td>
				</tr>

				<tr>
					<td class="label"><?php print $this->translate('Auto-create SIP Account when creating Webmail user')?></td>
					<td>
						<input name="fields[SIPAutoCreateUser]" class="serviceProvidersSIPDependant" type='hidden' value="0"/>
						<input name="fields[SIPAutoCreateUser]" class="serviceProvidersSIPDependant iphoneStyle" type="checkbox" baseclassname="serviceProvidersSIP" value="1" <?php echo ($this->global['SIPAutoCreateUser'] == '1') ? 'checked' : '' ?> />
						<small><?php print $this->translate('When a new Webmail user account is created, automatically create a matching generic SIP account.')?></small>
					</td>
				</tr>

				<tr>
					<td class="label"><?php print $this->translate('Allow User to Change SIP Settings')?></td>
					<td>
						<input name="fields[UserSIPGwEnabled]" class="serviceProvidersSIPDependant" type='hidden' value="0"/>
						<input name="fields[UserSIPGwEnabled]" class="serviceProvidersSIPDependant iphoneStyle" type="checkbox" baseclassname="serviceProvidersSIP" value="1" <?php echo ($this->global['UserSIPGwEnabled'] == '1') ? 'checked' : '' ?> />
						<small><?php print $this->translate('Enabling this will allow users to change their SIP account Settings.')?></small>
					</td>
				</tr>

				<tr>
					<td class="label"><?php print $this->translate('Overwrite SIP Password')?></td>
					<td>
						<input name="fields[SIPPswdOverwrite]" class="serviceProvidersSIPDependant" type='hidden' value="0"/>
						<input name="fields[SIPPswdOverwrite]" class="serviceProvidersSIPDependant iphoneStyle" type="checkbox" baseclassname="serviceProvidersSIP" value="1" <?php echo ($this->global['SIPPswdOverwrite'] == '1') ? 'checked' : '' ?> />
						<small><?php print $this->translate('Enabling this will overwrite the SIP password when a user changes their webmail password.')?></small>
					</td>
				</tr> 

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

				<tr>
					<td class="label"><?php print $this->translate('UCDB Support')?></td>
					<td>
						<input name="fields[UCDBEnabled]" class="serviceProvidersSIPDependant" type='hidden' value="0"/>
						<input name="fields[UCDBEnabled]" class="serviceProvidersSIPDependant iphoneStyle" type="checkbox"  baseclassname="serviceProvidersSIP" value="1" <?php echo ($this->global['UCDBEnabled'] == '1') ? 'checked' : '' ?> />
						<small><?php print $this->translate('Display SIP/ SMS Folders.')?></small>
					</td>
				</tr>

			</table>

		</form>
	</div>
</div>

<script type="text/javascript">
$( function(){

	$(".iphoneStyle", "#serviceproviders").iphoneStyle();
	$('.stronglastword', "#serviceproviders").each( function() { $(this).stronglastword() });

	$('input.affectsOthers', '#serviceproviders').bind("change", function()
	{

		var baseclassname = $(this).attr("baseclassname")

		if( $(this).attr("checked") == true && ($(this).attr("disabled") === undefined || $(this).attr("disabled") === "" || $(this).attr("disabled") == false )  )
		{
			$('input.' + baseclassname + 'Dependant', '#serviceproviders').each( function()
			{
				$(this).parent().parent().fadeTo("slow", 1);
				$(this).removeAttr("disabled");
				if( $(this).attr("baseclassname") !== undefined )
				{
					$(this).trigger("change")
				}
			})

			$('.sip-label').parent().fadeTo('slow', 1)
		}
		else
		{

			$('input.' + baseclassname + 'Dependant', '#serviceproviders').each( function()
			{
				$(this).parent().parent().fadeTo("fast", 0.5);
				$(this).attr("disabled","disabled");
				if( $(this).attr("baseclassname") !== undefined )
				{
					$(this).trigger("change")
				}
			})

			$('.sip-label').parent().fadeTo('fast',0.5)
		}

	})


	$('#back_button a', '#serviceproviders').bind("click", function() { $("#Flash", '#serviceproviders').hide(); return $('#settingsForm', '#serviceproviders').submit()})

	// bind to the form's submit event and cancel legacy submit
	$('#settingsForm', '#serviceproviders').submit(function()
	{

		$.php($("#settingsForm", '#serviceproviders').attr("action"),$("#settingsForm", '#serviceproviders').serializeArray());
		return false;

	});
	$('input.affectsOthers:first', '#serviceproviders').trigger("change")

});

</script>