dbhost selector

This commit is contained in:
Serghey Rodin 2013-11-23 13:54:37 +02:00
commit bdac016e7a
2 changed files with 35 additions and 3 deletions

View file

@ -20,6 +20,7 @@ if (!empty($_POST['ok'])) {
if (empty($_POST['v_dbuser'])) $errors[] = __('username');
if (empty($_POST['v_password'])) $errors[] = __('password');
if (empty($_POST['v_type'])) $errors[] = __('type');
if (empty($_POST['v_host'])) $errors[] = __('host');
if (empty($_POST['v_charset'])) $errors[] = __('charset');
// Check for errors
@ -47,6 +48,7 @@ if (!empty($_POST['ok'])) {
$v_password = escapeshellarg($_POST['v_password']);
$v_type = $_POST['v_type'];
$v_charset = $_POST['v_charset'];
$v_host = $_POST['v_host'];
$v_db_email = $_POST['v_db_email'];
// Check password length
@ -59,8 +61,10 @@ if (!empty($_POST['ok'])) {
// Add Database
$v_type = escapeshellarg($_POST['v_type']);
$v_charset = escapeshellarg($_POST['v_charset']);
exec (VESTA_CMD."v-add-database ".$user." ".$v_database." ".$v_dbuser." ".$v_password." ".$v_type." 'default' ".$v_charset, $output, $return_var);
$v_host = escapeshellarg($_POST['v_host']);
exec (VESTA_CMD."v-add-database ".$user." ".$v_database." ".$v_dbuser." ".$v_password." ".$v_type." ".$v_host." ".$v_charset, $output, $return_var);
$v_type = $_POST['v_type'];
$v_host = $_POST['v_host'];
$v_charset = $_POST['v_charset'];
check_return_code($return_var,$output);
unset($output);
@ -90,6 +94,15 @@ exec (VESTA_CMD."v-list-database-types 'json'", $output, $return_var);
$db_types = json_decode(implode('', $output), true);
unset($output);
$db_hosts = array();
foreach ($db_types as $db_type ) {
exec (VESTA_CMD."v-list-database-hosts ".$db_type." 'json'", $output, $return_var);
$db_hosts_tmp = json_decode(implode('', $output), true);
$db_hosts = array_merge($db_hosts, $db_hosts_tmp);
unset($db_hosts_tmp);
unset($output);
}
include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/add_db.html');
unset($_SESSION['error_msg']);
unset($_SESSION['ok_msg']);

View file

@ -105,14 +105,33 @@
<select class="vst-list" name="v_type">
<?php
foreach ($db_types as $key => $value) {
echo "\t\t\t\t<option value=\"".$value."\"";
echo "\n\t\t\t\t\t\t\t\t\t\t<option value=\"".$value."\"";
if ((!empty($v_type)) && ( $value == $v_type )) echo ' selected';
echo ">".$value."</option>\n";
echo ">".$value."</option>";
}
?>
</select>
</td>
</tr>
<tr>
<td class="vst-text" style="padding: 10px 0 0 2px;">
<?php print __('Host');?>
</td>
</tr>
<tr>
<td>
<select class="vst-list" name="v_host">
<?php
foreach ($db_hosts as $key => $value) {
echo "\n\t\t\t\t\t\t\t\t\t\t<option value=\"".$key."\"";
if ((!empty($v_host)) && ( $key == $v_host )) echo ' selected';
echo ">".$key."</option>";
}
?>
</select>
</td>
</tr>
<tr>
<td class="vst-text" style="padding: 10px 0 0 2px;">
<?php print __('Charset');?>