-
Notifications
You must be signed in to change notification settings - Fork 988
/
createdb.php
108 lines (99 loc) · 4.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
<?php
/*
#############################################################
# >>> PHPSurveyor #
#############################################################
# > Author: Jason Cleeland #
# > E-mail: jason@cleeland.org #
# > Mail: Box 99, Trades Hall, 54 Victoria St, #
# > CARLTON SOUTH 3053, AUSTRALIA
# > Date: 20 February 2003 #
# #
# This set of scripts allows you to develop, publish and #
# perform data-entry on surveys. #
#############################################################
# #
# Copyright (C) 2003 Jason Cleeland #
# #
# This program is free software; you can redistribute #
# it and/or modify it under the terms of the GNU General #
# Public License as published by the Free Software #
# Foundation; either version 2 of the License, or (at your #
# option) any later version. #
# #
# This program is distributed in the hope that it will be #
# useful, but WITHOUT ANY WARRANTY; without even the #
# implied warranty of MERCHANTABILITY or FITNESS FOR A #
# PARTICULAR PURPOSE. See the GNU General Public License #
# for more details. #
# #
# You should have received a copy of the GNU General #
# Public License along with this program; if not, write to #
# the Free Software Foundation, Inc., 59 Temple Place - #
# Suite 330, Boston, MA 02111-1307, USA. #
#############################################################
*/
//Ensure script is not run directly, avoid path disclosure
require_once(dirname(__FILE__).'/../config.php');
$dbname = $databasename;
sendcacheheaders();
echo $htmlheader;
echo "<br />\n";
echo "<table width='350' align='center' style='border: 1px solid #555555' cellpadding='1' cellspacing='0'>\n";
echo "\t<tr bgcolor='#555555'><td colspan='2' height='4'><font size='1' face='verdana' color='white'><strong>"._("Create Database")."</strong></td></tr>\n";
echo "\t<tr bgcolor='#CCCCCC'><td align='center'>$setfont\n";
// In Step2 fill the database with data
if (returnglobal('createdbstep2')==_("Populate Database"))
{
if (modify_database(dirname(__FILE__).'/install/create-'.$databasetype.'.sql'))
{
echo sprintf(_("Database `%s` has been successfully populated."),$dbname)."</font></strong></font><br /><br />\n";
echo "<input type='submit' value='"._("Main Admin Screen")."' onClick='location.href=\"$scriptname\"'>";
exit;
}
else
{
echo"Error";
}
}
if (!$dbname)
{
echo "<br /><strong>$setfont<font color='red'>"._("Error")."</font></strong><br />\n";
echo _("Database Information not provided. This script must be run from admin.php only.");
echo "<br /><br />\n";
echo "<input type='submit' value='"._("Main Admin Screen")."' onClick='location.href=\"$scriptname\"'>";
exit;
}
if (!$database_exists) //Database named in config.php does not exist
{
// TODO SQL: Portable to other databases??
switch ($databasetype)
{
case 'mysql': $createDb=$connect->Execute("CREATE DATABASE `$dbname` DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci");
break;
case 'odbc_mssql':
case 'mssql': $createDb=$connect->Execute("CREATE DATABASE [$dbname];");
break;
default: $createDb=$connect->Execute("CREATE DATABASE $dbname");
}
if ($createDb) //Database has been succesfully created
{
$connect->database = $dbname;
$connect->Execute("USE DATABASE `$dbname`");
echo "<br />$setfont<strong><font color='green'>\n";
echo _("Database has been created.")."</font></strong></font><br /><br />\n";
echo _("Please click below to populate the database")."<br /><br />\n";
echo "<form method='post'>";
echo "<input type='submit' name='createdbstep2' value='"._("Populate Database")."' onClick='location.href=\"createdb.php\"'></form>";
}
else
{
echo "<strong>$setfont<font color='red'>"._("Error")."</font></strong></font><br />\n";
echo _("Could not create database")." ($dbname)<br /><font size='1'>\n";
echo $connect->ErrorMsg();
echo "</font><br /><br />\n";
echo "<input type='submit' value='"._("Main Admin Screen")."' onClick='location.href=\"$scriptname\"'>";
}
}
echo "</td></tr></table>\n";
?>