@section('header')
	@include('common.header')
@stop

@section('content')
	<div class="row" ng-controller="AdminLdapCtrl" ng-init="data = {{{ json_encode($settings) }}}" ng-cloak>
		<div class="col-sm-8">
			<div class="widget widget-classic">
				<div class="widget-content">

					<!-- Page title -->
					<p class="lead">
						LDAP Settings

						<!-- Enabled button -->
						<span ng-if="data.enabled" ng-click="disable()" class="btn pull-right" ng-class="{'btn-danger': show_disable_text, 'btn-success': !show_disable_text}" ng-mouseenter="show_disable_text = true" ng-mouseleave="show_disable_text = false"><i ng-class="{'fa fa-check': !show_disable_text}"></i> {[{ show_disable_text ? 'Click to disable' : 'Enabled' }]}</span>

						<!-- Disabled button -->
						<span ng-if="!data.enabled" ng-click="enable()" class="btn pull-right" ng-class="{'btn-success': show_enable_text, 'btn-danger': !show_enable_text}" ng-mouseenter="show_enable_text = true" ng-mouseleave="show_enable_text = false"><i ng-class="{'fa fa-times': !show_enable_text}"></i> {[{ show_enable_text ? 'Click to enable' : 'Disabled' }]}</span>
					</p>


					<!-- Alerts and error messages -->
					<div class="alert alert-success" ng-if="success">
						<i class="fa fa-check-circle"></i> Your changes were saved successfully.
					</div>
					<div class="alert alert-danger" ng-if="error_message">
						Ooops, something went wrong. {[{ error_message }]}
					</div>
					<div class="alert alert-success" ng-if="test_success">
						<i class="fa fa-check-circle"></i> <strong>LDAP Test Successful!</strong><br>
						<span ng-if="test_success_message">{[{ test_success_message }]}</span>
						<span ng-if="!test_success_message">Successfully connected to the LDAP server with the provided settings.</span>
					</div>
					<div class="alert alert-danger" ng-if="test_failed">
						<i class="fa fa-exclamation-triangle"></i> <strong>LDAP Test Failed!</strong><br>
						<span ng-if="test_failed_message">{[{ test_failed_message }]}</span>
						<span ng-if="!test_failed_message">Failed to connect to the LDAP server with the provided settings.</span>
					</div>

					<form name="SettingsForm" class="form-horizontal form-edit" ng-submit="save()">

						<!-- Include form fields -->
						<div class="form-group">
							<label class="col-sm-3 control-label label-required">Account Suffix:</label>
							<div class="col-sm-9">
								<input type="text" ng-model="data.account_suffix" name="account_suffix" class="form-control" placeholder="Example: @archangels.local" required>
							</div>
						</div>
						<div class="form-group">
							<label class="col-sm-3 control-label label-required">Base DN:</label>
							<div class="col-sm-9">
								<input type="text" ng-model="data.base_dn" name="base_dn" class="form-control" placeholder="Example: DC=archangels,DC=local" required>
							</div>
						</div>
						<div class="form-group">
							<label class="col-sm-3 control-label label-required">Domains Controller:</label>
							<div class="col-sm-9">
								<div ui-select2="{tags: [], placeholder: 'Example: 192.168.0.1'}" ng-model="data.domain_controllers" class="form-control"></div>
							</div>
						</div>
						<div class="form-group">
							<label class="col-sm-3 control-label label-required">Ldap Username:</label>
							<div class="col-sm-9">
								<input type="text" ng-model="data.admin_username" name="admin_username" class="form-control" required>
							</div>
						</div>
						<div class="form-group">
							<label class="col-sm-3 control-label label-required">Ldap Password:</label>
							<div class="col-sm-9">
								<input ng-attr-type="{[{ showPassword ? 'text' : 'password' }]}" ng-model="data.admin_password" name="admin_password" class="form-control" required>
								<div class="input-group-btn" style="margin-top: 5px;">
									<button type="button" class="btn btn-xs btn-default" ng-click="showPassword = !showPassword">
										<i class="fa" ng-class="{'fa-eye': !showPassword, 'fa-eye-slash': showPassword}"></i>
										{[{ showPassword ? 'Hide' : 'Show' }]}
									</button>
								</div>
							</div>
						</div>
						<div class="form-group">
							<label class="col-sm-3 control-label">Port:</label>
							<div class="col-sm-9">
								<input type="text" ng-model="data.ad_port" name="ad_port" class="form-control" placeholder="Default: 389">
							</div>
						</div>
						<div class="form-group">
							<label class="col-sm-3 control-label">Real Primary Group:</label>
							<div class="col-sm-9">
								<div class="checkbox">
									<label>
										<input type="checkbox" ng-model="data.real_primarygroup" name="real_primarygroup" value="1">
									</label>
								</div>
							</div>
						</div>
						<div class="form-group">
							<label class="col-sm-3 control-label">Use SSL:</label>
							<div class="col-sm-9">
								<div class="checkbox">
									<label>
										<input type="checkbox" ng-model="data.use_ssl" name="use_ssl" value="1">
									</label>
								</div>
							</div>
						</div>
						<div class="form-group">
							<label class="col-sm-3 control-label">Use TLS:</label>
							<div class="col-sm-9">
								<div class="checkbox">
									<label>
										<input type="checkbox" ng-model="data.use_tls" name="use_tls" value="1">
									</label>
								</div>
							</div>
						</div>
						<div class="form-group">
							<label class="col-sm-3 control-label">Recursive Groups:</label>
							<div class="col-sm-9">
								<div class="checkbox">
									<label>
										<input type="checkbox" ng-model="data.recursive_groups" name="recursive_groups" value="1">
									</label>
								</div>
							</div>
						</div>
						<div class="form-group">
							<label class="col-sm-3 control-label">SSO:</label>
							<div class="col-sm-9">
								<div class="checkbox">
									<label>
										<input type="checkbox" ng-model="data.sso" name="sso" value="1">
									</label>
								</div>
							</div>
						</div>

						<div class="text-right form-actions">
							<span ng-init="post_url = '{{ URL::route('admin.settings.ldap.store') }}'"></span>
							<button type="submit" class="btn btn-primary" ng-disabled="saving">
								<span ng-if="!saving"><i class="fa fa-save"></i> Save Changes</span>
								<span ng-if="saving"><i class="fa fa-spinner fa-spin"></i> Saving...</span>
							</button>
							<button type="button" class="btn btn-info" ng-click="test('{{ URL::route('admin.settings.ldap.test') }}')" ng-disabled="testing" tooltip="This allows you to test your current settings to see if it can connect to the server.">
								<span ng-if="!testing"><i class="fa fa-plug"></i> Test Settings</span>
								<span ng-if="testing"><i class="fa fa-spinner fa-spin"></i> Testing Connection...</span>
							</button>
							<a href="{{ URL::to('admin') }}" class="btn btn-default">Cancel</a>
						</div>
					</form>

				</div>
			</div>
		</div>
		<div class="col-sm-4">
			<div class="widget widget-classic">
				<div class="widget-content">
					<p class="lead"><i class="icon-info-sign"></i> Help</p>
					<p style="text-align: justify;">Here you can setup the LDAP configuration options. LDAP is used to authenticate the users against an Active Directory</p>
					<p>This module can be disabled completely if not required.</p>
				</div>
			</div>
		</div>
	</div>
@stop