/
createdb.php
113 lines (103 loc) · 5.09 KB
/
createdb.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<?php
/*
* LimeSurvey
* Copyright (C) 2007 The LimeSurvey Project Team / Carsten Schmitz
* All rights reserved.
* License: http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
* LimeSurvey is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*
* $Id: createdb.php 9622 2010-12-10 21:38:02Z c_schmitz $
*/
//Ensure script is not run directly, avoid path disclosure
if (isset($_REQUEST['rootdir'])) {die('You cannot start this script directly');}
require_once(dirname(__FILE__).'/../../config-defaults.php');
require_once(dirname(__FILE__).'/../../common.php');
require_once($rootdir.'/classes/core/language.php');
require_once(dirname(__FILE__).'/../admin_functions.php');
$clang = new limesurvey_lang("en");
$dbname = $databasename;
sendcacheheaders();
echo getAdminHeader();
echo "<div class='messagebox ui-corner-all'><div class='header ui-widget-header' >"
.$clang->gT("Create Database")."</div><p>\n";
echo $clang->gT("Creating tables. This might take a moment...")."<p> \n";
// In Step2 fill the database with data
if (returnglobal('createdbstep2')==$clang->gT("Populate Database"))
{
$createdbtype=$databasetype;
if ($databasetype=='mysql' || $databasetype=='mysqli') {
@$connect->Execute("ALTER DATABASE `$dbname` DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;");
$createdbtype='mysql';
}
if ($createdbtype=='mssql_n' || $createdbtype=='odbc_mssql' || $createdbtype=='odbtp') $createdbtype='mssql';
if($createdbtype=='postgres' && version_compare($connect->pgVersion, '9') >= 0)
{
$result=$connect->execute("ALTER DATABASE {$dbname} SET bytea_output='escape';");
if ($result==false){
die ('Database creation failed. Some database settings could not be set.<br>You need to be owner of the Postgres database. Please adjust your permissions and try again.');
}
}
if($createdbtype=='mssqlnative') $createdbtype='mssqlnative';
if (modify_database(dirname(__FILE__).'/create-'.$createdbtype.'.sql'))
{
echo "<br /><div class='successtitle'>\n";
echo sprintf($clang->gT("Database `%s` has been successfully populated."),$dbname)."</div><p> \n";
echo "<input type='submit' value='".$clang->gT("Main Admin Screen")."' onclick='location.href=\"../$scriptname\"' /></div>";
exit;
}
else
{
echo $modifyoutput;
echo"Error";
}
}
if (!$dbname)
{
echo "<br /><strong>$setfont<font color='red'>".$clang->gT("Error")."</font></strong><br />\n";
echo $clang->gT("Database Information not provided. This script must be run from admin.php only.");
echo "<br /><br />\n";
echo "<input type='submit' value='".$clang->gT("Main Admin Screen")."' onclick='location.href=\"../$scriptname\"' />";
exit;
}
if (!$database_exists) //Database named in config-defaults.php does not exist
{
// TODO SQL: Portable to other databases??
switch ($databasetype)
{
case 'mysqli':
case 'mysql': $createDb=$connect->Execute("CREATE DATABASE `$dbname` DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci");
break;
case 'mssql_n':
case 'odbc_mssql':
case 'mssqlnative':
case 'odbtp': $createDb=$connect->Execute("CREATE DATABASE [$dbname];");
break;
case 'postgres': $createDb=$connect->Execute("CREATE DATABASE \"$dbname\" ENCODING 'UTF8'");
break;
default: $createDb=$connect->Execute("CREATE DATABASE $dbname");
}
if ($createDb) //Database has been successfully created
{
$connect->database = $dbname;
$connect->Execute("USE DATABASE `$dbname`");
echo "<br />$setfont<strong><font class='successtitle'>\n";
echo $clang->gT("Database has been created.")."</font></strong></font><br /><br />\n";
echo $clang->gT("Please click below to populate the database")."<br /><br />\n";
echo "<form method='post'>";
echo "<input type='submit' name='createdbstep2' value='".$clang->gT("Populate Database")."' onclick='location.href=\"createdb.php\"' /></form>";
}
else
{
echo "<strong>$setfont<font color='red'>".$clang->gT("Error")."</font></strong></font><br />\n";
echo $clang->gT("Could not create database")." ($dbname)<br /><font size='1'>\n";
echo $connect->ErrorMsg();
echo "</font><br /><br />\n";
echo "<input type='submit' value='".$clang->gT("Main Admin Screen")."' onclick='location.href=\"../$scriptname\"'>";
}
}
echo "</td></tr></table>\n";
?>