Skip to content

Commit

Permalink
An empty user-created database is now recognized and handled/filled a…
Browse files Browse the repository at this point in the history
…ccordingly.

git-svn-id: file:///Users/Shitiz/Downloads/lssvn/source/phpsurveyor@1932 b72ed6b6-b9f8-46b5-92b4-906544132732
  • Loading branch information
c-schmitz committed Aug 16, 2006
1 parent 35b1519 commit 369ef51
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 1,685 deletions.
17 changes: 16 additions & 1 deletion admin/admin.php
Expand Up @@ -90,8 +90,23 @@
."</body>\n</html>\n";
exit;
}
else
elseif ($dbexistsbutempty && !(returnglobal('createdbstep2')==_("Populate Database")))
{
$connect->database = $databasename;
$connect->Execute("USE DATABASE `$databasename`");
echo "<table width='350' align='center' style='border: 1px solid #555555' cellpadding='1' cellspacing='0'>\n"
."\t<tr bgcolor='#555555'><td colspan='2' height='4'><font size='1' face='verdana' color='white'><strong>"
._("PHPSurveyor Setup")."</strong></td></tr>\n"
."\t<tr bgcolor='#CCCCCC'><td align='center'>$setfont\n";
echo "<br />$setfont<strong><font color='green'>\n";
echo sprintf(_('A database named "%s" does already exist.'),$databasename)."</font></strong></font><br /><br />\n";
echo _("Do you want to populate that database now by creating the necessary tables?")."<br /><br />\n";
echo "<form method='post' action='createdb.php'>";
echo "<input type='submit' name='createdbstep2' value='"._("Populate Database")."'></form>";
exit;
}
else
{
//DB EXISTS, CHECK FOR APPROPRIATE UPGRADES
checkforupgrades();
}
Expand Down
20 changes: 11 additions & 9 deletions admin/createdb.php
Expand Up @@ -49,15 +49,16 @@
// In Step2 fill the database with data
if (returnglobal('createdbstep2')==_("Populate Database"))
{
if (modify_database(dirname(__FILE__).'/install/create-'.$databasetype.'.sql'))
{
echo _("Database has been successfully populated.")."</font></strong></font><br /><br />\n";
echo "<input type='submit' value='"._("Main Admin Screen")."' onClick='location.href=\"$scriptname\"'>";
}
else
{
echo"Error";
}
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";
}

}

Expand All @@ -70,6 +71,7 @@
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??
Expand Down
25 changes: 18 additions & 7 deletions admin/install/create-odbc_mssql.sql
@@ -1,10 +1,3 @@
-- SQL Manager 2005 Lite for SQL Server (2.4.0.1)
-- ---------------------------------------
-- Host : nobodys
-- Database : phpsurveyor
-- Version: : Microsoft SQL Server 8.00.760


--
-- Structure for table answers :
--
Expand Down Expand Up @@ -106,6 +99,15 @@ CREATE TABLE [dbo].[prefix_question_attributes] (
ON [PRIMARY]
;


CREATE TABLE [dbo].[prefix_settings_global] (
[stg_name] nvarchar(50) NOT NULL,
[stg_value] nvarchar(255) NULL
)
ON [PRIMARY]
;


--
-- Structure for table questions :
--
Expand Down Expand Up @@ -257,3 +259,12 @@ ALTER TABLE [dbo].[prefix_surveys]
ADD CONSTRAINT [PK_surveys]
PRIMARY KEY CLUSTERED ([sid])
ON [PRIMARY];

ALTER TABLE [dbo].[prefix_settings_global]
ADD CONSTRAINT [PK_settings_global]
PRIMARY KEY CLUSTERED ([stg_name])
ON [PRIMARY];

-- if you change the database scheme then change this version too and implement the changes in the upgrade_*.php too

INSERT INTO [prefix_settings_global] values('DBVersion','108');
11 changes: 11 additions & 0 deletions common.php
Expand Up @@ -151,6 +151,7 @@
$connect->Connect($dbport, $databaseuser, $databasepass);
}

$dbexistsbutempty=(checkifemptydb() && $database_exists);

// The following line is for mysql debug purposes
//$tmpresult=@mysql_query("SET SESSION SQL_MODE='STRICT_ALL_TABLES'");
Expand Down Expand Up @@ -785,6 +786,16 @@ function checksecurity()
}



function checkifemptydb()
{
global $connect;
$tablelist = $connect->MetaTables('TABLES');
if (count($tablelist)==0) {Return(true);}
else {Return(false);}
}


// This functions checks if the databaseversion in the settings table is the same one as required
// If no settings table does exists it is a upgrade from <=1.0 (mysql only)
// Then the old checker script is run prior to the standard upgrade
Expand Down

0 comments on commit 369ef51

Please sign in to comment.