XOOPS 2.5.6  Final
 All Classes Namespaces Files Functions Variables Pages
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 */
29 require_once './include/common.inc.php';
30 defined('XOOPS_INSTALL') or die('XOOPS Installation wizard die');
31 
33 $pageHasHelp = true;
34 
35 $vars =& $_SESSION['settings'];
36 
37 $func_connect = empty( $vars['DB_PCONNECT'] ) ? "mysql_connect" : "mysql_pconnect";
38 if (!($link = @$func_connect( $vars['DB_HOST'], $vars['DB_USER'], $vars['DB_PASS'], true))) {
40  $wizard->redirectToPage('-1', $error);
41  exit();
42 }
43 
44 if ($_SERVER['REQUEST_METHOD'] == 'GET' && isset($_GET['charset']) && @$_GET['action'] == 'updateCollation') {
45  echo xoFormFieldCollation('DB_COLLATION', $vars['DB_COLLATION'], DB_COLLATION_LABEL, DB_COLLATION_HELP, $link, $_GET['charset']);
46  exit();
47 }
48 
49 if ($_SERVER['REQUEST_METHOD'] == 'POST') {
50  $params = array( 'DB_NAME', 'DB_CHARSET', 'DB_COLLATION', 'DB_PREFIX' );
51  foreach ($params as $name) {
52  $vars[$name] = isset($_POST[$name]) ? $_POST[$name] : "";
53  }
54 }
55 
56 $error = '';
57 if ($_SERVER['REQUEST_METHOD'] == 'POST' && !empty($vars['DB_NAME'])) {
58  $error = validateDbCharset($link, $vars['DB_CHARSET'], $vars['DB_COLLATION']);
59  $db_exist = true;
60  if (empty($error)) {
61  if (!@mysql_select_db( $vars['DB_NAME'], $link)) {
62  // Database not here: try to create it
63  $result = mysql_query( "CREATE DATABASE `" . $vars['DB_NAME'] . '`' );
64  if (!$result) {
66  $db_exist = false;
67  }
68  }
69  if ($db_exist && $vars['DB_CHARSET']) {
70  $sql = "ALTER DATABASE `" . $vars['DB_NAME'] . "` DEFAULT CHARACTER SET " . mysql_real_escape_string($vars['DB_CHARSET']) .
71  ($vars['DB_COLLATION'] ? " COLLATE " . mysql_real_escape_string($vars['DB_COLLATION']) : "");
72  if (!mysql_query($sql)) {
74  }
75  }
76  }
77  if (empty($error)) {
78  $wizard->redirectToPage('+1');
79  exit();
80  }
81 }
82 
83 if (@empty($vars['DB_NAME'])) {
84  // Fill with default values
85  $vars = array_merge( $vars,
86  array('DB_NAME' => 'xoops',
87  'DB_CHARSET' => 'utf8',
88  'DB_COLLATION' => '',
89  'DB_PREFIX' => 'x' . substr(md5(time()), 0, 3),
90  )
91  );
92 }
93 
94 ob_start();
95 ?>
96 <?php if (!empty($error)) echo '<div class="x2-note errorMsg">' . $error . "</div>\n"; ?>
97 
98 <script type="text/javascript">
99 function setFormFieldCollation(id, val)
100 {
101  var display = (val == '') ? 'none' : '';
102  $(id).style.display = display;
103  new Ajax.Updater(
104  id, '<?php echo $_SERVER['PHP_SELF']; ?>',
105  { method:'get',parameters:'action=updateCollation&charset='+val }
106  );
107 }
108 </script>
109 
110 <fieldset>
111  <legend><?php echo LEGEND_DATABASE; ?></legend>
112  <?php echo xoFormField('DB_NAME', $vars['DB_NAME'], DB_NAME_LABEL, DB_NAME_HELP); ?>
113  <?php echo xoFormField('DB_PREFIX', $vars['DB_PREFIX'], DB_PREFIX_LABEL, DB_PREFIX_HELP); ?>
114  <?php echo xoFormFieldCharset('DB_CHARSET', $vars['DB_CHARSET'], DB_CHARSET_LABEL, DB_CHARSET_HELP, $link); ?>
115  <?php echo xoFormBlockCollation('DB_COLLATION', $vars['DB_COLLATION'], DB_COLLATION_LABEL, DB_COLLATION_HELP, $link, $vars['DB_CHARSET']); ?>
116 </fieldset>
117 
118 <?php
119 $content = ob_get_contents();
120 ob_end_clean();
121 include './include/install_tpl.php';
122 ?>