<div id="primary_header">
	<h1><?php print $this->translate('SubAdmin Edit')?></h1>
	<!--<div id="back_button">
		<a href="#">
			<span class="stronglastword"><?php echo $this->translate('Back to results') ?></span>
		</a>
	</div> -->
</div>

<div id="primary_content">
<div id="back_button" style="float: right; margin: -8px 26px 0px 0px;">
    <a href="#">
        <span class="stronglastword"><?php echo $this->translate('Back to results') ?></span>
    </a>
</div>

	<div id="primary_content_inner">
		<div id="Flash" class="flash_notice"></div>
		<form id="subadminEditForm" method="post" action="<?php echo $this->moduleBaseUrl ?>/security/subadminupdate">

			<input type="hidden" name="save" value="1" />
			<input type="hidden" name="subadminid" value="<?php echo $this->subadmin['id'] ?>" />
			<input type="hidden" name="Username" value="<?php echo $this->subadmin['Username'] ?>" />
			<!-- Specify default settings not available to edit -->
			
			<table class="settings">
		
				<tr>
					<td class="label"><?php print $this->translate('WebAdmin User')?></td>
					<td><strong><b><?php echo $this->subadmin['Username'] ?></b></strong></td>
				</tr>
				
				<tr class="admin-divider">
					<td colspan="2"><span></span></td>
				</tr>

				<tr>
					<td class="label"><?php print $this->translate('WebAdmin Password')?></td>
					<td>
						<input type="password" id="Password" name="Password" value="unchanged" />
						<small><?php print $this->translate('Webadmin Password')?></small>
					</td>
				</tr>

				<tr>
					<td class="label"><?php print $this->translate('Verify Password')?></td>
					<td>
					<input type="password" name="PasswordVerify" value="unchanged" />
					<small><?php print $this->translate('Verify Password')?></small>
					</td>
				</tr>
				
				<tr class="admin-divider">
				        <td colspan="2"><span></span></td>
				    </tr>

				<tr>
					<td class="label"><?php print $this->translate('Administrator Full Name')?></td>
					<td>
					<input type="text" name="Fullname" value="<?php echo $this->subadmin['Fullname'] ?>" />
					<small><?php print $this->translate('Administrator Full Name')?></small>
					</td>
				</tr>

				<tr>
					<td class="label"><?php print $this->translate('Email Address')?></td>
					<td>
						<input type="text" name="EmailAddress" value="<?php echo $this->subadmin['EmailAddress'] ?>" />
						<small><?php print $this->translate('Administrator Email Address')?></small>
					</td>
				</tr>

				<tr>
					<td class="label"><?php print $this->translate('Company Name')?></td>
					<td>
						<input type="text" name="Company" value="<?php echo $this->subadmin['Company'] ?>" />
						<small><?php print $this->translate('Company Name')?></small>
					</td>
				</tr>

			</table>

			<div class="divider"/>
	
			<table class="settings">
				<?php /* ?>
				<tr>
				<td class="label"><?php print $this->translate('Group')?></td>
					<td>
					<select id="Ugroup" class="option" multiple="" size="5" name="Ugroup">
					<option value="">-- None </option>
					<option value="Default">Default</option>
					<option value="nopop">nopop</option>
					<option value="All Users">All Users</option>
					</select>
						<small><?php print $this->translate('Group')?></small>
					</td>
				</tr>
				<?php */ ?>
				<tr>
					<td class="label"><?php print $this->translate('Domain') ?></td>
					<td class="tdstyle">
						<select id="Domains" class="option" multiple="" size="5" style="height:auto;" name="Domains[]">
							<option value="">-- None </option>
<?php 		foreach( $this->domains as $domain ) : 
					$selected = in_array($domain['DomainName'], $this->subadmin['Domains'])?' selected':'' ?>
							<option value="<?php echo $domain['DomainName'] ?>" <?php echo $selected ?>><?php echo $domain['DomainName'] ?></option>
<?php 		endforeach ?>
						</select>
				
						<small><?php print $this->translate('Specify which domains the Subadmin will control.')?></small>
					</td>
				</tr>

				<tr>
					<td class="label"><?php print $this->translate('No. Accounts Allowed') ?></td>
					<td class="tdstyle">
						<div class="styled-select">
						        <span class="arrow"></span>
						<select class="option" name="NumUsersA">
							<option value="">-- <?php echo $this->translate('Select') ?></option>
							<option value="16777215" <?php echo ($this->subadmin['NumUsers'] == '16777215') ? 'selected' : ''; ?>><?php echo $this->translate('Unlimited') ?></option>
							<option value="10">10</option>
							<option value="20">20</option>
							<option value="50">50</option>
							<option value="100">100</option>
							<option value="200">200</option>
							<option value="500">500</option>
							<option value="1000">1000</option>
							<option value="5000">5000</option>
						</select>
						</div>
						Or:
						<input class="option" type="text" size="20" name="NumUsersB" value="<?php if($this->subadmin['NumUsers'] != '16777215') echo $this->subadmin['NumUsers'] ?>" />
						<small><?php print $this->translate('No. Accounts Allowed')?></small>
					</td>
				</tr>

				<tr>
				<td class="label"><?php print $this->translate('Total Disk Quota')?></td>
					<td class='tdstyle'>
						<div class="styled-select">
						        <span class="arrow"></span>
						<select class="option" name="NumQuotaA">
							<option value="">-- <?php echo $this->translate('Select') ?></option>
							<option value="0" <?php echo ($this->subadmin['NumQuota'] == '0') ? 'selected' : ''; ?>><?php echo $this->translate('Unlimited') ?></option>
							<option value="250">250 MB</option>
							<option value="500">500 MB</option>
							<option value="1024">1 GB</option>
							<option value="5120">5 GB</option>
							<option value="10240">10 GB</option>
							<option value="20480">20 GB</option>
							<option value="30720">30 GB</option>
							<option value="40960">40 GB</option>
							<option value="51200">50 GB</option>
							<option value="61440">60 GB</option>
							<option value="71680">70 GB</option>
							<option value="81920">80 GB</option>
							<option value="92160">90 GB</option>
							<option value="102400">100 GB</option>
							<option value="204800">200 GB</option>
							<option value="512000">500 GB</option>
							<option value="1024000">1 TB</option>
							<option value="2048000">2 TB</option>
						</select>
						</div>
						<span>
							Or:
							<input class="option" type="text" value="<?php if($this->subadmin['NumQuota'] > 0) echo $this->subadmin['NumQuota'] ?>" size="20" name="NumQuotaB"/> <?php echo $this->translate('MB') ?>
						</span>
						<small><?php print $this->translate('Specify the total disk quota allocated for users the Subadmin controls. No additional users can be created if the Subadmin exceeds the quota.')?></small>
					</td>
				</tr>

			</table>
	
	
			<div class="divider"/>
	
			<table class="settings">
		
				<tr>
					<td class="label"><?php print $this->translate('Add Accounts')?></td>
					<td>
						<input type="checkbox" name="UAdd" id="UAdd" class="iphonestyle" value="1" <?php if($this->subadmin['UAdd'] == 1) echo ' checked'; ?> />
						<small><?php print $this->translate('Add Accounts')?></small>
					</td>
				</tr>

				<tr>
					<td class="label"><?php print $this->translate('Delete Accounts')?></td>
					<td>
						<input type="checkbox" name="UDelete" id="UDelete" class="iphonestyle" value="1" <?php if($this->subadmin['UDelete'] == 1) echo ' checked'; ?> />
						<small><?php print $this->translate('Delete Accounts')?></small>
					</td>
				</tr>

				<tr>
					<td class="label"><?php print $this->translate('Modify Users')?></td>
					<td>
						<input type="checkbox" name="UModify" id="UModify" class="iphonestyle" value="1" <?php if($this->subadmin['UModify'] == 1) echo ' checked'; ?> />
						<small><?php print $this->translate('Modify Users')?></small>
					</td>
				</tr>
				<?php /* ?>
				<tr>
				<td class="label"><?php print $this->translate('Purge Users')?></td>
					<td>
					<input type="checkbox" name="UPurge" value="1" <?php if($this->subadmin['UPurge'] == 1) echo ' checked'; ?> />
					<small><?php print $this->translate('Purge Users')?></small>
					</td>
				</tr>
				<?php */ ?>
				<tr>
					<td class="label"><?php print $this->translate('Search Users')?></td>
					<td>
						<input type="checkbox" name="USearch" id="USearch" class="iphonestyle" value="1" <?php if($this->subadmin['USearch'] == 1) echo ' checked'; ?> />
						<small><?php print $this->translate('Search Users')?></small>
					</td>
				</tr>

				<tr>
					<td class="label"><?php print $this->translate('Email Aliases')?></td>
					<td>
						<input type="checkbox" name="UAlias" id="UAlias" class="iphonestyle" value="1" <?php if($this->subadmin['UAlias'] == 1) echo ' checked'; ?> />
						<small><?php print $this->translate('Email Aliases')?></small>
					</td>
				</tr>

				<tr>
					<td class="label"><?php print $this->translate('Show Account Logs')?></td>
					<td>
						<input type="checkbox" name="ULogs" id="ULogs" class="iphonestyle" value="1" <?php if($this->subadmin['ULogs'] == 1) echo ' checked'; ?> />
						<small><?php print $this->translate('Show Account Logs')?></small>
					</td>
				</tr>

				<tr>
					<td class="label"><?php print $this->translate('ArchiveVault')?></td>
					<td>
						<input type="checkbox" name="UArchiveVault" id="UArchiveVault" class="iphonestyle" value="1" <?php if($this->subadmin['UArchiveVault'] == 1) echo ' checked'; ?><?php echo ($this->archiveVaultAPIEnabled?'':' disabled') ?> />
						<small><?php print $this->translate('Access to ArchiveVault interface for the domains selected above. <a href="http://atmail.com/archivevault/" target="_blank">Learn More</a>')?></small>
					</td>
				</tr>

			</table>


			<table class='settings' id='' style="margin-top: 5px;">
				<tr>
					<td class="label"></td>
					<td>
						<div id="back_button_add_alias" class="">
							<a href="">
								<span class="stronglastword"><?php echo $this->translate('Save') ?></span>
							</a>
						</div>
					</td>
				</tr>
			</table>
		</form>
	</div>
</div>

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

	$('#back_button_add_alias a', '#subadminEditForm').bind('click', function() { 
		
		//validate password
		if( $(':input[name=Password]', '#subadminEditForm').attr('value') != $(':input[name=PasswordVerify]', '#subadminEditForm').attr('value') ) {
		
			$.simpleFlash('Passwords don\'t match', 'error')
			$(':input[name=Password]', '#subadminEditForm').attr('value','')
			$(':input[name=PasswordVerify]', '#subadminEditForm').attr('value','')
			$(':input[name=Password]', '#subadminEditForm').focus()
			return false
		
		}
		$(this).parent().fadeTo('slow', 0.5)
		$(this).parent().addClass('disabled')
		
		//check if at least one domain selected
		domainSelected = false
		$("#Domains option:selected", '#subadminAddForm').each(function (i) 
		{
			if( $(this).attr('value') != '' )
				domainSelected = true
		})
		$("#Domains option:selected", '#subadminEditForm').each(function (i) 
		{
			if( $(this).attr('value') != '' )
				domainSelected = true
		})

		if( !domainSelected )
			alert('Notice: updating subadmin without any domains selected.')
		
		$.php( $('#subadminEditForm').attr('action'), $('#subadminEditForm').serializeArray() )
		return false
		 
	})
	
	$('#back_button a').unbind('click');
	$('#back_button a').click( function() { $('#secondary', '#Security').tabs('load',0); return false;});

	$('.iphonestyle', '#subadminEditForm').iphoneStyle();
	$('.stronglastword').each( function() { $(this).stronglastword() });	

});

</script>
