XOOPS
2.6.0
Main Page
Related Pages
Classes
Files
Examples
File List
File Members
page_dbsettings.php
Go to the documentation of this file.
1
<?php
2
/*
3
You may not change or alter any portion of this comment or credits
4
of supporting developers from this source code or any supporting source code
5
which is considered copyrighted (c) material of the original comment or credit authors.
6
7
This program is distributed in the hope that it will be useful,
8
but WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10
*/
11
27
require_once __DIR__ .
'/include/common.inc.php'
;
28
29
/* @var $wizard XoopsInstallWizard */
30
$wizard
=
$_SESSION
[
'wizard'
];
31
32
$settings
=
$_SESSION
[
'settings'
];
33
34
if
(
$_SERVER
[
'REQUEST_METHOD'
] ==
'POST'
) {
35
$params = array(
'DB_NAME'
);
36
foreach
($params as
$name
) {
37
$settings
[
$name
] = isset($_POST[$name]) ? $_POST[
$name
] :
""
;
38
}
39
$settings
[
'DB_PARAMETERS'
] = serialize(
getDbConnectionParams
());
40
$_SESSION
[
'settings'
] =
$settings
;
41
}
42
43
$platform
=
false
;
44
$error
=
''
;
45
$availableDatabases
= array();
46
47
$tried_create
=
false
;
48
$connection
= null;
49
$connection
=
getDbConnection
(
$error
);
50
// if we specified the dbname and failed, try again without it
51
// we will try and create it later
52
if
(!
$connection
&& !empty(
$settings
[
'DB_NAME'
])) {
53
$hold_name=
$settings
[
'DB_NAME'
];
54
unset(
$settings
[
'DB_NAME'
]);
55
$_SESSION
[
'settings'
] =
$settings
;
56
$hold_error =
$error
;
57
$error
=
''
;
58
$connection
=
getDbConnection
(
$error
);
59
$settings
[
'DB_NAME'
] = $hold_name;
60
$_SESSION
[
'settings'
] =
$settings
;
61
if
(
$connection
) {
62
// we have a database name and did not connect
63
if
(!empty(
$settings
[
'DB_NAME'
]) && !
$tried_create
) {
64
$platform
=
$connection
->getDatabasePlatform();
65
$canCreate =
$platform
->supportsCreateDropDatabase();
66
if
($canCreate) {
67
$tried_create
=
true
;
68
try
{
69
$sql
=
$platform
->getCreateDatabaseSQL(
$connection
->quoteIdentifier(
$settings
[
'DB_NAME'
]));
70
$result
=
$connection
->exec(
$sql
);
71
if
(
$result
) {
72
// try to reconnect with the database specified
73
$connection
= null;
74
$connection
=
getDbConnection
(
$error
);
75
}
else
{
76
$error
=
ERR_NO_DATABASE
;
77
}
78
}
catch
(Exception $e) {
79
$error
= $e->getMessage();
80
}
81
}
else
{
82
$error
=
ERR_NO_CREATEDB
;
83
}
84
}
85
}
else
{
// keep original error
86
$error
= $hold_error;
87
}
88
}
89
90
// leave if we are already connected to a database from earlier input
91
if
(
$connection
&& empty(
$error
)) {
92
$currentDb =
$connection
->getDatabase();
93
if
(!empty($currentDb)) {
94
$settings
[
'DB_PARAMETERS'
] = serialize(
getDbConnectionParams
());
95
$_SESSION
[
'settings'
] =
$settings
;
96
$wizard
->redirectToPage(
'+1'
);
97
exit
();
98
}
99
}
100
101
if
(
$connection
) {
102
$platform
=
$connection
->getDatabasePlatform();
103
try
{
104
$sql
=
$platform
->getListDatabasesSQL();
105
$dbResults =
$connection
->fetchAll(
$sql
);
106
}
catch
(Exception $e) {
107
$dbResults =
false
;
108
}
109
110
$dbIgnored =
$wizard
->configs[
'db_types'
][
$settings
[
'DB_DRIVER'
]][
'ignoredb'
];
111
if
($dbResults) {
112
foreach
($dbResults as $dbrow) {
113
if
(is_array($dbrow)) {
114
$dbase = reset($dbrow);
// get first value in array
115
}
else
{
116
$dbase = $dbrow;
117
}
118
if
(!in_array($dbase, $dbIgnored)) {
119
$availableDatabases
[] = $dbase;
120
}
121
}
122
}
123
}
124
125
if
(is_array(
$availableDatabases
) && count(
$availableDatabases
)==1) {
126
if
(empty(
$settings
[
'DB_NAME'
])) {
127
$settings
[
'DB_NAME'
] =
$availableDatabases
[0];
128
}
129
}
130
131
$_SESSION
[
'settings'
] =
$settings
;
132
133
ob_start();
134
?>
135
<?php
136
if
(!empty(
$error
)) {
137
echo
'<div class="x2-note errorMsg">'
.
$error
.
"</div>\n"
;
138
}
139
?>
140
<script type=
"text/javascript"
>
141
function
updateDbName(){
142
var e = document.getElementById(
"DB_AVAILABLE"
);
143
var dbSelected = e.options[e.selectedIndex].text;
144
145
document.getElementById(
"DB_NAME"
).value=dbSelected;
146
}
147
</script>
148
<fieldset>
149
<?php
150
if
(!empty(
$availableDatabases
)) {
151
echo
'<legend>'
.
LEGEND_DATABASE
.
'</legend>'
;
152
echo
'<div class="xoform-help">'
.
DB_AVAILABLE_HELP
.
'</div>'
;
153
echo
'<label class="xolabel" for="DB_DATABASE_LABEL" class="center">'
;
154
echo
DB_AVAILABLE_LABEL
;
155
echo
' <select size="1" name="DB_AVAILABLE" id="DB_AVAILABLE" onchange="updateDbName();">'
;
156
$selected = (
$settings
[
'DB_NAME'
] ==
''
) ?
'selected'
:
''
;
157
echo
'<option value="" {$selected}>-----------</option>'
;
158
foreach
(
$availableDatabases
as $dbase) {
159
$selected = (
$settings
[
'DB_NAME'
] == $dbase) ?
'selected'
:
''
;
160
echo
"<option value=\"{$dbase}\" {$selected}>{$dbase}</option>"
;
161
}
162
}
163
?>
164
</select>
165
</label>
166
167
<?php echo
xoFormField
(
'DB_NAME'
,
$settings
[
'DB_NAME'
],
DB_NAME_LABEL
,
DB_NAME_HELP
); ?>
168
</fieldset>
169
170
<?php
171
$content
= ob_get_contents();
172
ob_end_clean();
173
174
$_SESSION
[
'pageHasHelp'
] =
true
;
175
$_SESSION
[
'pageHasForm'
] =
true
;
176
$_SESSION
[
'content'
] =
$content
;
177
$_SESSION
[
'settings'
] =
$settings
;
178
include
XOOPS_INSTALL_PATH
.
'/include/install_tpl.php'
;
ERR_NO_DATABASE
const ERR_NO_DATABASE
Definition:
install.php:152
$settings
$settings
Definition:
page_dbsettings.php:32
$wizard
$wizard
Definition:
page_dbsettings.php:30
$result
$result
Definition:
pda.php:33
$_SERVER
$_SERVER['REQUEST_URI']
Definition:
comment_delete.php:23
$tried_create
$tried_create
Definition:
page_dbsettings.php:47
LEGEND_DATABASE
const LEGEND_DATABASE
Definition:
install.php:85
$availableDatabases
$availableDatabases
Definition:
page_dbsettings.php:45
$content
$content
Definition:
page_dbsettings.php:171
exit
exit
Definition:
browse.php:104
$platform
if($_SERVER['REQUEST_METHOD']== 'POST') $platform
Definition:
page_dbsettings.php:43
$_SESSION
if(!$connection &&!empty($settings['DB_NAME'])) if($connection &&empty($error)) if($connection) if(is_array($availableDatabases)&&count($availableDatabases)==1) $_SESSION['settings']
Definition:
page_dbsettings.php:131
ERR_NO_CREATEDB
const ERR_NO_CREATEDB
Definition:
install.php:155
XOOPS_INSTALL_PATH
const XOOPS_INSTALL_PATH
Definition:
common.inc.php:33
DB_AVAILABLE_HELP
const DB_AVAILABLE_HELP
Definition:
install.php:119
xoFormField
xoFormField($name, $value, $label, $help= '')
Definition:
functions.php:76
$connection
$connection
Definition:
page_dbsettings.php:48
DB_AVAILABLE_LABEL
const DB_AVAILABLE_LABEL
Definition:
install.php:118
include
DB_NAME_HELP
const DB_NAME_HELP
Definition:
install.php:94
$sql
$sql
Definition:
pda.php:32
getDbConnection
getDbConnection(&$error)
Definition:
functions.php:502
$name
$name
Definition:
force_download.php:15
DB_NAME_LABEL
const DB_NAME_LABEL
Definition:
install.php:93
getDbConnectionParams
getDbConnectionParams()
Definition:
functions.php:472
$error
$error
Definition:
page_dbsettings.php:44
usr64
htdocs
install
page_dbsettings.php
Generated on Fri May 22 2015 03:07:02 for XOOPS by
1.8.9.1