<div id="Flash" style="margin-left:0px;"></div>
<form id="groupeditform" action="<?php echo $this->moduleBaseUrl ?>/users/groupsave">
	<input type="hidden" name="fields[groupType]" value="<?php echo $this->groupType ?>" />
	<input type="hidden" name="fields[currentGroupName]" value="<?php echo $this->groupName ?>" />
	
	
	<table class="settings">
		<tbody>
<?php 	if( $this->groupType == 'user' ) : ?>
	        <tr>
				<td colspan="2" class="contact_field">
					<h2><?php echo $this->translate('Edit Group') ?></h2>
				</td>
			</tr>	
<?php 	elseif( $this->groupType == 'domain' ) : ?>
			<tr>
				<td colspan="2" class="contact_field">
					<h2><?php echo $this->translate('Edit Domain group') ?></h2>
					<small>
						<?php print $this->translate('Will only affect users that are still members of this domain group.')?>
					</small>
					<br>
				</td>
			</tr>	

            <tr>
                <td class="contact_field">
                    <label>
                        <?php print $this->translate('Enable domain')?>
                    </label>
                </td>

                <td>
                    <input name="fields[disable]" type='hidden' value='0' />
                    <input name="fields[disable]" type="checkbox" id="disable" class="iphoneStyle disableDomain" value="1" <?php echo ($this->domainEnabled) ? 'checked' : '' ?> />
                    <small>
                        <?php print $this->translate('Switch off to disable logins for this domain.')?>
                    </small>
                    <input type="hidden" name="fields[currentlyEnabled]" value=<?php echo ($this->domainEnabled) ? 'true' : '' ?>>
                </td>
            </tr>

			<tr>
				<td class="contact_field">
					<label>
						<?php print $this->translate('Inherit settings')?>
					</label>
				</td>

				<td>
					<input name="fields[inherit]" type='hidden' value='0' />
					<input name="fields[inherit]" type="checkbox" id="inherit" class="iphoneStyle disableDisablesChildren" value="1" <?php echo ($this->groupData['inherit']) ? 'checked' : '' ?> />
					<small>
						<?php print $this->translate('Switch on to inherit the main system settings, or specify custom settings.')?>
					</small>
				</td>
			</tr>
<?php 	elseif( false ) : // disabled, dependant on ATMAIL-1193 ?>
			<tr>
				<td class="contact_field">
					<label><?php echo $this->translate('Name') ?></label>
				</td>
				<td>
					<input name="fields[GroupName]" id="GroupName" value="<?php echo $this->groupData['GroupName'] ?>" />
					<small>
						<?php print $this->translate('The name of this group.')?>
					</small>
				</td>
			</tr>
<?php 	endif ?>
			<tr>
				<td class="contact_field" valign='top'>
					<label class="settings_label"><?php echo $this->translate('Group Description') ?></label>
				</td>
				<td>
					<input id="fieldsGroupDescription" name="fields[GroupDescription]" size="60" value="<?php echo $this->groupData['GroupDescription']?>" />
					<small><?php print $this->translate('Optionally give a description for this group.')?></small>
				</td>
			</tr>
          	<tr class="admin-divider">
				        <td colspan="2"><span></span></td>
				    </tr>
			<tr>
				
				<td class="contact_field"><label class="settings_label"><?php print $this->translate('License Type')?></label></td>
			
				<td>
				
					<div class="styled-select">
					        <span class="arrow"></span>
				<?php echo license::options($this->groupData); ?>
				</div>
				                <?php echo license::optionssmall('groups', $this->groupData); ?>
				</td>
			</tr>

			<tr class="space">
				<td class="contact_field">
					<label class="settings_label"><?php echo $this->translate('Webmail') ?></label>
				</td>
				<td>
					<input type="hidden" name="fields[Webmail]" value="0" />
					<input type="checkbox" class="iphoneStyle" name="fields[Webmail]" id="Webmail" value="1"<?php echo $this->groupData['Webmail']=='1'?' checked':'' ?> />
					<small><?php print $this->translate('Allow users to access webmail.')?></small>
				</td>
			</tr>
<?php 		if($this->global['install_type'] == 'server') : ?>
			<tr class="space">
				<td class="contact_field">
					<label class="settings_label"><?php echo $this->translate('External POP3') ?></label>
				</td>
				<td>
					<input type="hidden" name="fields[POP3Support]" value="0" />
					<input type="checkbox" class="iphoneStyle" name="fields[POP3Support]" id="POP3Support" value="1"<?php echo $this->groupData['POP3Support']=='1'?' checked':'' ?> />
					<small><?php print $this->translate('Allow POP3 and POP3 SSL access to the mail server.')?></small>
				</td>
			</tr>

			<tr class="space">
				<td class="contact_field">
					<label class="settings_label"><?php echo $this->translate('External IMAP') ?></label>
				</td>
				<td>
					<input type="hidden" name="fields[IMAPSupport]" value="0" />
					<input type="checkbox" class="iphoneStyle" name="fields[IMAPSupport]" id="IMAPSupport" value="1"<?php echo $this->groupData['IMAPSupport']=='1'?' checked':'' ?> />
					<small><?php print $this->translate('Allow IMAP and IMAP SSL access to the mail server.')?></small>
				</td>
			</tr>
<?php 		endif ?>

            <tr class="admin-divider">
				        <td colspan="2"><span></span></td>
				    </tr>
	
			<tr class="space<?php echo ($this->groupDataDefault['GroupwareZone']=='Off'?' globallyDisabled':'') ?>">
				<td class="contact_field">
					<label class="settings_label"><?php echo $this->translate('Groupware Zone') ?></label>
				</td>
				<td>
					<div class="styled-select">
					        <span class="arrow"></span>
					<select name="fields[GroupwareZone]" id="GroupwareZone" class="enabledByLic3 enabledByLic4 enabledByLic5<?php echo ($this->groupDataDefault['GroupwareZone']=='Off'?' selectGloballyDisabled"':'') ?>"<?php echo ($this->groupDataDefault['GroupwareZone']=='Off'?' disabled="disabled"':'') ?>>
						<?php $w4m70Yt0hYUduM2r2lrrIuY0bgKG4A3vvftl4NbzCWfW = ((Zend_Registry::get('w4m70Yt0hYUduM2r2lrrIuY0bgKG4A3vvftl4NbzCWfW') & LICENSE_FEATURE_BASIC_GROUPWARE) != 0); $dgz = $this->groupData['GroupwareZone']; ?>
						<option value="System"<?php echo ($w4m70Yt0hYUduM2r2lrrIuY0bgKG4A3vvftl4NbzCWfW?($dgz=='System'?' selected':''):' disabled="disabled" class="optionGloballyDisabled"') ?>>System</option>
						<option value="Domain"<?php echo ($w4m70Yt0hYUduM2r2lrrIuY0bgKG4A3vvftl4NbzCWfW?($dgz=='Domain'?' selected':''):' disabled="disabled" class="optionGloballyDisabled"') ?>>Domain</option>
						<option value="Off"<?php echo ( (!$w4m70Yt0hYUduM2r2lrrIuY0bgKG4A3vvftl4NbzCWfW || $dgz=='Off')?' selected':'') ?>>Off</option>
					</select>
					</div>
					<small><?php print $this->translate('Groupware Zone sets the level of access for Calendar and Addressbook sharing.')?></small>
				</td>
			</tr>

			<tr class="space<?php echo ($this->groupDataDefault['GroupwareZone']=='Off'?' globallyDisabled':'') ?>">
				<td class="contact_field">
					<label class="settings_label"><?php echo $this->translate('Addressbook sharing') ?></label>
				</td>
				<td>
					<input type="hidden" name="fields[SharedAbook]" value="0" />
					<input type="checkbox" class="iphoneStyle enabledByLic3 enabledByLic4 enabledByLic5" name="fields[SharedAbook]" id="SharedAbook" value="1"<?php echo $this->groupData['SharedAbook']=='1'?' checked':'' ?> />
					<small><?php print $this->translate('Allow users to see shared addressbook entries depending on the Groupware Zone and also share address book entries.')?></small>
				</td>
			</tr>

			<tr class="space<?php echo ($this->groupDataDefault['Calendar']!='1'?' globallyDisabled':'') ?>">
				<td class="contact_field">
					<label class="settings_label"><?php echo $this->translate('Calendar') ?></label>
				</td>
				<td>
					<input type="hidden" name="fields[Calendar]" value="0" />
					<input type="checkbox" class="iphoneStyle enabledByLic3 enabledByLic4 enabledByLic5" name="fields[Calendar]" id="Calendar" value="1"<?php echo $this->groupData['Calendar']=='1'?' checked':'' ?> />
					<small><?php print $this->translate('Enable or disable the WebMail Calendar access for users.')?></small>
				</td>
			</tr>

            <tr class="admin-divider">
				        <td colspan="2"><span></span></td>
				    </tr>

			<tr class="space<?php echo ($this->groupDataDefault['Calendar']!='1'?' globallyDisabled':'') ?>">
				<td class="contact_field">
					<label class="settings_label"><?php echo $this->translate('CalDAV Server') ?></label>
				</td>
				<td>
					<input type="hidden" name="fields[CalDAVServer]" value="0" />
					<input type="checkbox" class="iphoneStyle enabledByLic3  enabledByLic4 enabledByLic5" name="fields[CalDAVServer]" id="CalDAVServer" value="1"<?php echo $this->groupData['CalDAVServer']=='1'?' checked':'' ?> />
					<small><?php print $this->translate('Enable or disable CalDAV Server for users.')?></small>
				</td>
			</tr>
			<tr class="space<?php echo ($this->groupDataDefault['Calendar']!='1'?' globallyDisabled':'') ?>">
				<td class="contact_field">
					<label class="settings_label"><?php echo $this->translate('CardDAV Server') ?></label>
				</td>
				<td>
					<input type="hidden" name="fields[CardDAVServer]" value="0" />
					<input type="checkbox" class="iphoneStyle  enabledByLic3 enabledByLic4 enabledByLic5" name="fields[CardDAVServer]" id="CardDAVServer" value="1"<?php echo $this->groupData['CardDAVServer']=='1'?' checked':'' ?> />
					<small><?php print $this->translate('Enable or disable CardDAV Server for users.')?></small>
				</td>
			</tr>

            <tr class="admin-divider">
				        <td colspan="2"><span></span></td>
				    </tr>


			<tr class="space<?php echo ($this->groupDataDefault['PushSupport']!='1'?' globallyDisabled':'') ?>">
				<td class="contact_field">
					<label class="settings_label"><?php echo $this->translate('Push Enabled') ?></label>
				</td>
				<td>
					<input type="hidden" name="fields[PushSupport]" value="0" />
					<input type="checkbox" class="iphoneStyle enabledByLic4 enabledByLic5" name="fields[PushSupport]" id="Push" value="1"<?php echo $this->groupData['PushSupport']=='1'?' checked':'' ?> />
					<small><?php print $this->translate('Toggle the Microsoft&reg; Exchange ActiveSync&reg; feature. If enabled, users can use Microsoft&reg; Exchange ActiveSync&reg; to synchronise Address-books, Calendar events and Tasks with the server.')?></small>
				</td>
			</tr>

           	<tr class="admin-divider">
				        <td colspan="2"><span></span></td>
				    </tr>

			<tr class="space">
				<td class="contact_field">
					<label class="settings_label"><?php echo $this->translate('WebDav Service') ?></label>
				</td>
				<td>
					<input name="fields[WebDavEnabled]" type='hidden' value='0'/>
					<input name="fields[WebDavEnabled]" type="checkbox" class="iphoneStyle WebDavEnabled enabledByLic4 enabledByLic5" value="1"<?php echo ($this->groupData['WebDavEnabled']) ? ' checked' : '' ?>>
					<small><?php print $this->translate('Enable WebDav service so users can use 3rd party WebDav clients to access their Files Storage.')?></small>
				</td>
			</tr>
			<tr class="space">
				<td class="contact_field">
					<label class="settings_label">
						<?php echo $this->translate('Files Storage Tab') ?>
					</label>
				</td>
				<td>
					<input name="fields[StorageTabEnabled]" type="hidden" value="0" />
					<input name="fields[StorageTabEnabled]" type="checkbox" class="iphoneStyle dependsWebDavEnabled enabledByLic4 enabledByLic5" value="1"<?php echo ($this->groupData['StorageTabEnabled']) ? ' checked' : '' ?>>
					<small><?php print $this->translate('Enable user Files Storage.')?></small>
				</td>
			</tr>
			<tr class="space">
				<td class="contact_field">
					<label class="settings_label">
						<?php echo $this->translate('Files Sharing') ?>
					</label>
				</td>
				<td>
					<input name="fields[FileSharingEnabled]" type="hidden" value="0" />
					<input name="fields[FileSharingEnabled]" type="checkbox" class="iphoneStyle dependsWebDavEnabled enabledByLic4 enabledByLic5" value="1"<?php echo ($this->groupData['FileSharingEnabled']) ? ' checked' : '' ?>>
					<small><?php print $this->translate('Allow users to share files in their Files Storage via a URL.')?></small>
				</td>
			</tr>
	</table>

<?php 	if( $this->groupType == 'user' ) : ?>
    <div id="back_button" class='updategroup'><a href="#" class="stronglastword"><span><?php echo $this->translate('Update Group') ?></span></a></div>
<?php 	elseif( $this->groupType == 'domain' ) : ?>
    <div id="back_button" class='updategroup'><a href="#" class="stronglastword"><span><?php echo $this->translate('Update Domain') ?></span></a></div>
<?php	endif ?>


</form>
<script type="text/javascript" language="JavaScript">

$( function()
{

	$('.iphoneStyle').iphoneStyle();

	$(".disableDisablesChildren", "#Users").each( function()
	{
		
		
		$(this).change( function()
		{
               
			//if( !$(this).is(':checked') )
			//	$('#fieldsGroupDescription').attr('value', '');
			enableSettingsBox($(this), true );
			//TODO: reset the form back to default values if set to inherited, to avoid confusion with admins editing and then clicking inherit (it does not save those settings to default)
			
			//trigger license type click to set local lic limitations
			$("#licenseTypeSelectId", "#Users").trigger('change')

		})
		//initialize them
		enableSettingsBox($(this), true ) //N.B. enableBox is not generic, it is specific to this dom structure
		
	})
	
	//disable fields that can be and are globally disabled
	$('.globallyDisabled').each( function() 
	{
		
		$(this).find(".settings_label").fadeTo(0, 0.49) 
		$(this).find('INPUT').removeAttr('checked')
		$(this).find('INPUT, TEXTAREA, SELECT').attr('disabled', 'disabled').trigger("change")
		$(this).find('.iPhoneCheckContainer').addClass('iPhoneCheckDisabled')
		
	})

	$(".WebDavEnabled", "#Users").change( function() 
	{
		
		
		if( $(this).is(":checked") )
			$(".dependsWebDavEnabled", "#Users").removeAttr('disabled').parent().parent().parent().fadeTo("normal", 1.0);			
		else
			$(".dependsWebDavEnabled", "#Users").attr('disabled', 'disabled').parent().parent().parent().fadeTo("normal", 0.4);
		
		
	}).trigger("change")
	
	$("#licenseTypeSelectId", "#Users").change( function() 
	{

		//N.B. Don't further dim or enable globally disabled options
		//ignore change if disabled (for inherit state)
		if( $(this).attr("disabled") !== undefined && $(this).attr("disabled") )
			return
		
		var licenseTypeSelected = $('option:selected', this).attr('value')
		if( licenseTypeSelected == 1 || licenseTypeSelected == 4 ) // trial, enable everything
		{

			$(".enabledByLic2, .enabledByLic3, .enabledByLic4, .enabledByLic5", "#Users").each( function() {
				
				//enable all options except the globally disabled options
				if( $(this).hasClass('selectGloballyDisabled') )
					return true
				if( $(this).hasClass('iphoneStyle') )
				{
					if( !$(this).parent().parent().parent().hasClass("globallyDisabled") )
						$(this).removeAttr('disabled').parent().parent().parent().fadeTo("normal", 1.0);
				}
				else if( !$(this).parent().parent().hasClass("globallyDisabled") )
					$(this).removeAttr('disabled').parent().parent().fadeTo("normal", 1.0);
				
			})

		}
		else if( licenseTypeSelected == 2 ) //basic, disable all except enabledByLic2, and then enable enabledByLic2
		{

			$(".enabledByLic3, .enabledByLic4, .enabledByLic5", "#Users").each( function() {
				
				if( !$(this).hasClass(".enabledByLic2") )
				{

					if( $(this).hasClass('iphoneStyle') )
					{
						if( !$(this).parent().parent().parent().hasClass("globallyDisabled") )
							$(this).attr('disabled', 'disabled').parent().parent().parent().fadeTo("normal", 0.4);
					}
					else if( !$(this).parent().parent().hasClass("globallyDisabled") )
						$(this).attr('disabled', 'disabled').parent().parent().fadeTo("normal", 0.4);

						
				}
					
			})

		}
		else if( licenseTypeSelected == 3 )
		{

			$(".enabledByLic3", "#Users").each( function() {
				
				if( $(this).hasClass('iphoneStyle') && !$(this).parent().parent().parent().hasClass("globallyDisabled") )
					$(this).removeAttr('disabled').parent().parent().parent().fadeTo("normal", 1.0);
				else if( !$(this).parent().parent().hasClass("globallyDisabled") )
					$(this).removeAttr('disabled').parent().parent().fadeTo("normal", 1.0);

			})

			$(".enabledByLic4, .enabledByLic5", "#Users").each( function() {

				if( !$(this).hasClass(".enabledByLic3") )
				{

					if( $(this).hasClass('iphoneStyle') )
					{
						if( !$(this).parent().parent().parent().hasClass("globallyDisabled") )
							$(this).attr('disabled', 'disabled').parent().parent().parent().fadeTo("normal", 0.4);
					}
					else
					{
						if( !$(this).parent().parent().hasClass("globallyDisabled") )
							$(this).attr('disabled', 'disabled').parent().parent().fadeTo("normal", 0.4);
					}
						
				}

			})

		}
		
		$('#GroupwareZone option:not(:last)', '#Users').each( function() {
			
			if( licenseTypeSelected != 2 && !$(this).hasClass('optionGloballyDisabled') )
				$(this).removeAttr('disabled')
			else
			{
				$(this).attr('disabled', 'disabled')
				$(this).removeAttr('selected')
			}
			
		})

		//set groupware to off if lic 2 selected (not enabled)
		if( licenseTypeSelected == 2 )
		{
			$('#GroupwareZone option:last', '#Users').attr('selected', 'selected')
			$("#GroupwareZone", "#Users").trigger('change')
		}
		
		$(".iphoneStyle:not(#inherit)","#Users").trigger("change")

	}).trigger("change")

	$("#GroupwareZone", "#Users").change( function() 
	{
		
		var licenseTypeSelected = $("#licenseTypeSelectId option:selected", "#Users").attr('value')
		var Off = $('option:last', $(this)).attr('selected')
        //If license type is [Pro] and groupware settings set to System wide or Domain wide
		if( licenseTypeSelected != 2 && !Off )
			$("#SharedAbook", "#Users").removeAttr('disabled').parent().parent().parent().fadeTo("normal", 1.0);
		else
			$("#SharedAbook", "#Users").attr('disabled', 'disabled').parent().parent().parent().fadeTo("normal", 0.4);
			

	}).trigger("change")
	
	$('.stronglastword').each( function() { $(this).stronglastword() })

	// bind to the form's submit event and cancel legacy submit
	$('.updategroup').bind('click', function() { $("form#groupeditform").submit() })
	$("form#groupeditform").submit( function()
	{

		if( $("#contactform").attr("action") == false )
			alert('Form submission aborted: Action must be set')

		$.php( $(this).attr("action"),$(this).serializeArray() )
		return false

	})

	$('.disablemeworkaroundforiphonestyle').each( function()
	{
		
		$(this).attr('disabled', 'disabled');
		//$(this).trigger('change')
		
	})
	
})
</script>
