<div class="usvn_info">
	<h1><?php echo T_("Configuration"); ?></h1>
</div>

<form class="usvn_form" method="post" action="<?php echo $this->url(array('action' => 'save')); ?>">

<div>
	<div class="usvn_subinfo">
		<h2><?= T_("General settings"); ?></h2>
	</div>
	<table>
		<tr>
			<td><label><?php echo T_("Default language");?>:</label></td>
			<td>
				<select name="language">
					<?php
						foreach (USVN_Translation::listTranslation() as $language)
						{
							$locale = new Zend_Locale($language);
							$lang_name = $this->locale->getLanguageTranslation($locale->getLanguage());
							if ($language == USVN_Translation::getLanguage())
								echo "<option value=\"$language\" selected=\"selected\">$lang_name</option>";
							else
								echo "<option value=\"$language\">$lang_name</option>";
						}
					?>
				</select>
			</td>
		</tr>
		<tr>
			<td><label><?php echo T_("Default timezone");?>:</label></td>
			<td>
				<select name="timezone">
					<?php
						$timezones = Zend_Locale_Data::getList("en", "WindowsToTimezone");
						ksort($timezones);
						foreach ($timezones as $timezone => $city)
						{
							if ($timezone == date_default_timezone_get())
								echo "<option selected=\"selected\">$timezone</option>";
							else
								echo "<option>$timezone</option>";
						}
					?>
				</select>
			</td>
		</tr>
		<tr>
			<td><label><?php echo T_("Default template");?>:</label></td>
			<td>
				<select name="template">
					<?php
						foreach (USVN_Template::listTemplate() as $template) {
							if ($template == USVN_Template::getTemplate())
								echo "<option selected=\"selected\">$template</option>";
							else
								echo "<option>$template</option>";
						}
					?>
				</select>
			</td>
		</tr>
		<tr>
			<td><label><?php echo T_("Check for update");?>:</label></td>
			<td>
				<select name="checkforupdate">
					<?php
						if ($this->config->update->checkforupdate)
						{
							echo '<option value="1" selected>' . T_("Yes"). '</option>';
							echo '<option value="0">' . T_("No"). '</option>';
						}
						else
						{
							echo '<option value="1">' . T_("Yes"). '</option>';
							echo '<option value="0" selected>' . T_("No"). '</option>';
						}
					?>
				</select>
			</td>
		</tr>
	</table>
</div>

<br />

<div>
	<div class="usvn_subinfo">
		<h2><?php echo T_("Site's information"); ?></h2>
	</div>
	<table>
		<tr>
			<td><label><?php echo T_("Title"); ?>:</label></td>
			<td>
				<?php echo $this->formText('siteTitle', $this->config->site->title, array('size' => 70)); ?>
			</td>
		</tr>
		<tr>
			<td><label><?php echo T_("Icone"); ?>:</label></td>
			<td>
				<?php echo $this->formText('siteIco', $this->config->site->ico, array('size' => 70)); ?>
			</td>
		</tr>
		<tr>
			<td><label><?php echo T_("Logo"); ?>:</label></td>
			<td>
				<?php echo $this->formText('siteLogo', $this->config->site->logo, array('size' => 70)); ?>
			</td>
		</tr>
	</table>
</div>

<br />

<div>
	<div class="usvn_subinfo">
		<h2><?php echo T_("Authentication Settings"); ?></h2>
	</div>
	<table width="100%">
		<tr>
			<td><label><?php echo T_("Authentication method"); ?>:</label></td>
			<td>
				<select name="authAdapterMethod" onChange="
				  if (this.value == 'ldap')
					{
						document.getElementById('ldap').style.display='';
				  }
					else
					{
						document.getElementById('ldap').style.display='none';
					}">
					<?php
						if ($this->config->authAdapterMethod == 'ldap')
						{
							echo '<option value="database">' . T_("Database"). '</option>';
							echo '<option value="ldap" selected>' . T_("LDAP"). '</option>';
						}
						else
						{
							echo '<option value="database" selected>' . T_("Database"). '</option>';
							echo '<option value="ldap">' . T_("LDAP"). '</option>';
						}
					?>
				</select>
			</td>
		</tr>
		<tr>
			<td><label><?php echo T_("Always use database for login"); ?>:</label></td>
			<td>
				<?php echo $this->formText('alwaysUseDatabaseForLogin', $this->config->alwaysUseDatabaseForLogin ? $this->config->alwaysUseDatabaseForLogin : "admin", array('size' => 54)); ?>
			</td>
		</tr>
	</table>
</div>

<br />

<div id="ldap" <?php if ($this->config->authAdapterMethod != 'ldap') { echo 'style="display: none;"'; } ?>>
	<div class="usvn_subinfo">
		<h2><?php echo T_("LDAP Settings"); ?></h2>
	</div>
	<table width="100%">
		<tr>
			<td>
				<?php echo T_('These settings are based on Zend LDAP settings. You can find their meaning on <a target="_blank" href="http://framework.zend.com/manual/en/zend.ldap.html">Zend\'s website</a>') ?>
			</td>
		</tr>
	</table>
	<hr style="margin: 10px;" />
	<table>
		<tr>
			<td><label><?php echo T_("Create DB user from LDAP on login"); ?>:</label></td>
			<td>
				<select name="ldap[createUserInDBOnLogin]">
					<?php
						if ($this->config->ldap->createUserInDBOnLogin) {
							echo '<option value="1" selected>' . T_("Yes"). '</option>';
							echo '<option value="0">' . T_("No"). '</option>';
						}
						else {
							echo '<option value="1">' . T_("Yes"). '</option>';
							echo '<option value="0" selected>' . T_("No"). '</option>';
						}
					?>
				<select>
			</td>
		</tr>
		<tr>
			<td><label><?php echo T_("Also create a group for this user"); ?>:</label></td>
			<td>
				<select name="ldap[createGroupForUserInDB]">
					<?php
						if ($this->config->ldap->createGroupForUserInDB) {
							echo '<option value="1" selected>' . T_("Yes"). '</option>';
							echo '<option value="0">' . T_("No"). '</option>';
						}
						else {
							echo '<option value="1">' . T_("Yes"). '</option>';
							echo '<option value="0" selected>' . T_("No"). '</option>';
						}
					?>
				<select>
			</td>
		</tr>
	</table>
	<hr style="margin: 10px;" />
	<table width="100%">
		<tr>
			<td><label><?php echo T_("Host"); ?>:</label></td>
			<td>
				<?php echo $this->formText('ldap[host]', $this->config->ldap->options->host, array('style' => 'width:100%;')); ?>
			</td>
		</tr>
		<tr>
			<td><label><?php echo T_("Port"); ?>:</label></td>
			<td>
				<?php echo $this->formText('ldap[port]', $this->config->ldap->options->port, array('style' => 'width:100%;')); ?>
			</td>
		</tr>
		<tr>
			<td><label><?php echo T_("Encryption method"); ?>:</label></td>
			<td>
				<select name="LDAPEncryptionMethod">
					<?php
						$selectTLS = $this->config->ldap->options->useStartTls ? 'selected' : '';
						$selectSSL = $this->config->ldap->options->useSsl ? 'selected' : '';
						$selectNone = (empty($selectTLS) && empty($selectSSL)) ? 'selected' : '';
						echo '<option value="tls" ' . $selectTLS . '>' . T_("TLS (SSLv2)"). '</option>';
						echo '<option value="ssl" ' . $selectSSL . '>' . T_("SSL"). '</option>';
						echo '<option ' . $selectNone . '>' . T_("None") . '</option>';
					?>
				</select>
			</td>
		</tr>
		<tr>
			<td><label><?php echo T_("Username"); ?>:</label></td>
			<td>
				<?php echo $this->formText('ldap[username]', $this->config->ldap->options->username, array('style' => 'width:100%;')); ?>
			</td>
		</tr>
		<tr>
			<td><label><?php echo T_("Password"); ?>:</label></td>
			<td>
				<?php echo $this->formPassword('ldap[password]', '', array('style' => 'width:100%;')); ?>
			</td>
		</tr>
		<tr>
			<td><label><?php echo T_("Bind requires DN"); ?>:</label></td>
			<td>
				<select name="ldap[bindRequiresDn]">
					<?php
						if ($this->config->ldap->options->bindRequiresDn) {
							echo '<option value="1" selected>' . T_("Yes"). '</option>';
							echo '<option value="0">' . T_("No"). '</option>';
						}
						else {
							echo '<option value="1">' . T_("Yes"). '</option>';
							echo '<option value="0" selected>' . T_("No"). '</option>';
						}
					?>
				</select>
			</td>
		</tr>
		<tr>
			<td><label><?php echo T_("Bind DN format"); ?>:</label></td>
			<td>
				<?php echo $this->formText('ldap[bindDnFormat]', $this->config->ldap->options->bindDnFormat, array('style' => 'width:100%;')); ?>
			</td>
		</tr>
		<tr>
			<td><label><?php echo T_("Base DN"); ?>:</label></td>
			<td>
				<?php echo $this->formText('ldap[baseDn]', $this->config->ldap->options->baseDn, array('style' => 'width:100%;')); ?>
			</td>
		</tr>
		<tr>
			<td><label><?php echo T_("Account canonical form"); ?>:</label></td>
			<td>
				<select name="ldap[accountCanonicalForm]">
					<?php
						$form = $this->config->ldap->options->accountCanonicalForm;
						echo '<option value="0" ' . ($form == 0 ? 'selected' : '') . '>' . T_("Default"). '</option>';
						echo '<option value="1" ' . ($form == 1 ? 'selected' : '') . '>' . T_("Domain name") . ' (CN=Alice Baker,CN=Users,DC=example,DC=com)")</option>';
						echo '<option value="2" ' . ($form == 2 ? 'selected' : '') . '>' . T_("Username") . '  (abaker)</option>';
						echo '<option value="3" ' . ($form == 3 ? 'selected' : '') . '>' . T_('Backslash'). ' (EXAMPLE\abaker)</option>';
						echo '<option value="4" ' . ($form == 4 ? 'selected' : '') . '>' . T_("Principal"). ' (abaker@example.com)</option>';
					?>
				</select>
			</td>
		</tr>
		<tr>
			<td><label><?php echo T_("Account domain name"); ?>:</label></td>
			<td>
				<?php echo $this->formText('ldap[accountDomainName]', $this->config->ldap->options->accountDomainName, array('style' => 'width:100%;')); ?>
			</td>
		</tr>
		<tr>
			<td><label><?php echo T_("Short account domain name"); ?>:</label></td>
			<td>
				<?php echo $this->formText('ldap[accountDomainNameShort]', $this->config->ldap->options->accountDomainNameShort, array('style' => 'width:100%;')); ?>
			</td>
		</tr>
		<tr>
			<td><label><?php echo T_("Account filter format"); ?>:</label></td>
			<td>
				<?php echo $this->formText('ldap[accountFilterFormat]', $this->config->ldap->options->accountFilterFormat, array('style' => 'width:100%;')); ?>
			</td>
		</tr>
		<tr>
			<td><label><?php echo T_("Allow empty password"); ?>:</label></td>
			<td>
				<select name="ldap[allowEmptyPassword]">
					<?php
						if ($this->config->ldap->options->allowEmptyPassword)
						{
							echo '<option value="1" selected>' . T_("Yes"). '</option>';
							echo '<option value="0">' . T_("No"). '</option>';
						}
						else
						{
							echo '<option value="1">' . T_("Yes"). '</option>';
							echo '<option value="0" selected>' . T_("No"). '</option>';
						}
					?>
				</select>
			</td>
		</tr>
		<tr>
			<td><label><?php echo T_("Follow referrals"); ?>:</label></td>
			<td>
				<select name="ldap[optReferrals]">
					<?php
						if ($this->config->ldap->options->optReferrals)
						{
							echo '<option value="1" selected>' . T_("Yes"). '</option>';
							echo '<option value="0">' . T_("No"). '</option>';
						}
						else
						{
							echo '<option value="1">' . T_("Yes"). '</option>';
							echo '<option value="0" selected>' . T_("No"). '</option>';
						}
					?>
				</select>
			</td>
		</tr>
	</table>
</div>
<p>
	<input type="submit" value="<?php echo T_("Save");?>" />
</p>
</form>
