DRY for database type radiolist

This commit is contained in:
Bart Visscher 2014-01-31 17:31:19 +01:00
parent 12a900de25
commit d8ec7e2701
2 changed files with 25 additions and 54 deletions

View File

@ -85,6 +85,22 @@ class Controller {
$hasPostgreSQL = is_callable('pg_connect');
$hasOracle = is_callable('oci_connect');
$hasMSSQL = is_callable('sqlsrv_connect');
$databases = array();
if ($hasSQLite) {
$databases['sqlite'] = 'SQLite';
}
if ($hasMySQL) {
$databases['mysql'] = 'MySQL';
}
if ($hasPostgreSQL) {
$databases['pgsql'] = 'PostgreSQL';
}
if ($hasOracle) {
$databases['oci'] = 'Oracle';
}
if ($hasMSSQL) {
$databases['mssql'] = 'MS SQL';
}
$datadir = \OC_Config::getValue('datadirectory', \OC::$SERVERROOT.'/data');
$vulnerableToNullByte = false;
if(@file_exists(__FILE__."\0Nullbyte")) { // Check if the used PHP version is vulnerable to the NULL Byte attack (CVE-2006-7243)
@ -111,6 +127,7 @@ class Controller {
'hasPostgreSQL' => $hasPostgreSQL,
'hasOracle' => $hasOracle,
'hasMSSQL' => $hasMSSQL,
'databases' => $databases,
'directory' => $datadir,
'secureRNG' => \OC_Util::secureRNGAvailable(),
'htaccessWorking' => $htaccessWorking,

View File

@ -86,62 +86,16 @@
$hasOtherDB = true; else $hasOtherDB =false; //other than SQLite ?>
<legend><?php p($l->t( 'Configure the database' )); ?></legend>
<div id="selectDbType">
<?php if($_['hasSQLite']): ?>
<input type='hidden' id='hasSQLite' value="true" />
<?php if(!$hasOtherDB): ?>
<p>SQLite <?php p($l->t( 'will be used' )); ?>.</p>
<input type="hidden" id="dbtype" name="dbtype" value="sqlite" />
<?php foreach($_['databases'] as $type => $label): ?>
<?php if(count($_['databases']) == 1): ?>
<p><?php p($label . $l->t( 'will be used' )); ?>.</p>
<input type="hidden" id="dbtype" name="dbtype" value="<?php p($type) ?>" />
<?php else: ?>
<input type="radio" name="dbtype" value="sqlite" id="sqlite"
<?php OC_Helper::init_radio('dbtype', 'sqlite', 'sqlite'); ?>/>
<label class="sqlite" for="sqlite">SQLite</label>
<?php endif; ?>
<?php endif; ?>
<?php if($_['hasMySQL']): ?>
<input type='hidden' id='hasMySQL' value='true'/>
<?php if(!$_['hasSQLite'] and !$_['hasPostgreSQL'] and !$_['hasOracle'] and !$_['hasMSSQL']): ?>
<p>MySQL <?php p($l->t( 'will be used' )); ?>.</p>
<input type="hidden" id="dbtype" name="dbtype" value="mysql" />
<?php else: ?>
<input type="radio" name="dbtype" value="mysql" id="mysql"
<?php OC_Helper::init_radio('dbtype', 'mysql', 'sqlite'); ?>/>
<label class="mysql" for="mysql">MySQL</label>
<?php endif; ?>
<?php endif; ?>
<?php if($_['hasPostgreSQL']): ?>
<?php if(!$_['hasSQLite'] and !$_['hasMySQL'] and !$_['hasOracle'] and !$_['hasMSSQL']): ?>
<p>PostgreSQL <?php p($l->t( 'will be used' )); ?>.</p>
<input type="hidden" id="dbtype" name="dbtype" value="pgsql" />
<?php else: ?>
<label class="pgsql" for="pgsql">PostgreSQL</label>
<input type="radio" name="dbtype" value='pgsql' id="pgsql"
<?php OC_Helper::init_radio('dbtype', 'pgsql', 'sqlite'); ?>/>
<?php endif; ?>
<?php endif; ?>
<?php if($_['hasOracle']): ?>
<?php if(!$_['hasSQLite'] and !$_['hasMySQL'] and !$_['hasPostgreSQL'] and !$_['hasMSSQL']): ?>
<p>Oracle <?php p($l->t( 'will be used' )); ?>.</p>
<input type="hidden" id="dbtype" name="dbtype" value="oci" />
<?php else: ?>
<label class="oci" for="oci">Oracle</label>
<input type="radio" name="dbtype" value='oci' id="oci"
<?php OC_Helper::init_radio('dbtype', 'oci', 'sqlite'); ?>/>
<?php endif; ?>
<?php endif; ?>
<?php if($_['hasMSSQL']): ?>
<input type='hidden' id='hasMSSQL' value='true'/>
<?php if(!$_['hasSQLite'] and !$_['hasMySQL'] and !$_['hasPostgreSQL'] and !$_['hasOracle']): ?>
<p>MS SQL <?php p($l->t( 'will be used' )); ?>.</p>
<input type="hidden" id="dbtype" name="dbtype" value="mssql" />
<?php else: ?>
<label class="mssql" for="mssql">MS SQL</label>
<input type="radio" name="dbtype" value='mssql' id="mssql" <?php OC_Helper::init_radio('dbtype', 'mssql', 'sqlite'); ?>/>
<?php endif; ?>
<input type="radio" name="dbtype" value="<?php p($type) ?>" id="<?php p($type) ?>"
<?php p($_['dbtype'] === $type ? 'checked="checked" ' : '') ?>/>
<label class="<?php p($type) ?>" for="<?php p($type) ?>"><?php p($label) ?></label>
<?php endif; ?>
<?php endforeach; ?>
</div>
<?php if($hasOtherDB): ?>