XOOPS  2.6.0
page_dbconnection.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 // clear any old list
35 if (array_key_exists('DB_PARAMETERS', $settings)) {
36  unset($settings['DB_PARAMETERS']);
37 }
38 // get list of parameters the selected drive accepts
39 $driver_info = $wizard->configs['db_types'][$settings['DB_DRIVER']];
40 $driver_params=explode(',', $driver_info['params']);
41 $settings['DB_TYPE'] = $driver_info['type'];
42 
43 // get settings name and value (post, session or default) for each parameter
44 foreach ($driver_params as $param) {
45  $name=false;
46  if (!empty($wizard->configs['db_param_names'][$param])) {
47  $name=$wizard->configs['db_param_names'][$param];
48  $default = null;
49  switch ($param) {
50  case 'host':
51  $default = empty($settings[$name]) ? 'localhost' : $settings[$name];
52  break;
53  case 'user':
54  $default = empty($settings[$name]) ? '' : $settings[$name];
55  break;
56  case 'password':
57  $default = empty($settings[$name]) ? '' : $settings[$name];
58  break;
59  case 'port':
60  $default = empty($settings[$name]) ? '' : $settings[$name];
61  break;
62  case 'unix_socket':
63  $default = empty($settings[$name]) ? '' : $settings[$name];
64  break;
65  case 'path':
66  $default = empty($settings[$name]) ? '' : $settings[$name];
67  break;
68  case 'service':
69  $default = empty($settings[$name]) ? false : $settings[$name];
70  break;
71  case 'pooled':
72  $default = empty($settings[$name]) ? false : $settings[$name];
73  break;
74  case 'protocol':
75  $default = empty($settings[$name]) ? '' : $settings[$name];
76  break;
77  case 'dbname':
78  $default = empty($settings[$name]) ? '' : $settings[$name];
79  break;
80  }
81  $value = $default;
82  if ($_SERVER['REQUEST_METHOD'] == 'POST') {
83  $value = empty($_POST[$name]) ? $default : $_POST[$name];
84  }
85  $settings[$name]=$value;
86  }
87 }
88 
89 // if a POST, try to connect to the database using the parameters
90 $error = '';
91 if ($_SERVER['REQUEST_METHOD'] == 'POST') {
92  $instance = getDbConnection($error);
93  if ($instance && empty($error)) {
94  $_SESSION['settings'] = $settings;
95  $wizard->redirectToPage('+1');
96  exit();
97  }
98 }
99 
100 ob_start();
101 ?>
102 <?php if (!empty($error)) {
103  echo '<div class="x2-note errorMsg">' . $error . "</div>\n";
104 } ?>
105 <fieldset>
106  <legend><?php echo LEGEND_CONNECTION; ?>
107  <?php echo $wizard->configs['db_types'][$settings['DB_DRIVER']]['desc']; ?>
108  </legend>
109 <?php
110 foreach ($driver_params as $param) {
111  $name = $wizard->configs['db_param_names'][$param];
112  if ($wizard->configs['db_param_types'][$param]=='string') {
113  echo xoFormField(
114  $name,
115  $settings[$name],
116  constant($name . '_LABEL'),
117  constant($name . '_HELP')
118  );
119  } elseif ($wizard->configs['db_param_types'][$param]=='boolean') {
120  echo xoBoolField(
121  $name,
122  $settings[$name],
123  constant($name . '_LABEL'),
124  constant($name . '_HELP')
125  );
126  } elseif ($wizard->configs['db_param_types'][$param]=='password') {
127  echo xoPassField(
128  $name,
129  $settings[$name],
130  constant($name . '_LABEL'),
131  constant($name . '_HELP')
132  );
133  }
134 }
135 ?>
136 </fieldset>
137 
138 <?php
139 /*
140  <label class="xolabel" for="DB_PCONNECT" class="center">
141  <?php echo DB_PCONNECT_LABEL; ?>
142  <input class="checkbox" type="checkbox" name="DB_PCONNECT"
143  value="1" <?php echo $settings['DB_PCONNECT'] ? "'checked'" : ""; ?>/>
144 
145  <div class="xoform-help"><?php echo DB_PCONNECT_HELP; ?></div>
146  </label>
147 */
148 $content = ob_get_contents();
149 ob_end_clean();
150 
151 $_SESSION['pageHasHelp'] = true;
152 $_SESSION['pageHasForm'] = true;
153 $_SESSION['content'] = $content;
154 $_SESSION['settings'] = $settings;
155 include XOOPS_INSTALL_PATH . '/include/install_tpl.php';
if(array_key_exists('DB_PARAMETERS', $settings)) $driver_info
$_SERVER['REQUEST_URI']
xoPassField($name, $value, $label, $help= '')
Definition: functions.php:103
$_SESSION['pageHasHelp']
exit
Definition: browse.php:104
const LEGEND_CONNECTION
Definition: install.php:84
const XOOPS_INSTALL_PATH
Definition: common.inc.php:33
xoFormField($name, $value, $label, $help= '')
Definition: functions.php:76
foreach($driver_params as $param) $content
getDbConnection(&$error)
Definition: functions.php:502
xoBoolField($name, $value, $label, $help= '')
Definition: functions.php:131
foreach($driver_params as $param) $error
$driver_params