Skip to content

Commit

Permalink
Several checks to make sure that
Browse files Browse the repository at this point in the history
- the database is up to date
- mbstring library is installed
- PHPVersion meets minimum requirement
. MySQL version meets minimum requirement
- Installation dir is deleted (Check can be switched of by setting $debug to 1)


git-svn-id: file:///Users/Shitiz/Downloads/lssvn/source/phpsurveyor@2849 b72ed6b6-b9f8-46b5-92b4-906544132732
  • Loading branch information
c-schmitz committed May 6, 2007
1 parent 465c572 commit 78b6e79
Show file tree
Hide file tree
Showing 6 changed files with 314 additions and 190 deletions.
2 changes: 1 addition & 1 deletion admin/admin.php
Expand Up @@ -386,4 +386,4 @@ function helpscreen()



?>
?>
191 changes: 110 additions & 81 deletions admin/install/index.php
@@ -1,81 +1,110 @@
<?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 Version 2 as published by the Free #
# Software Foundation. #
# #
# #
# 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. #
#############################################################
*/

require_once(dirname(__FILE__).'/../../config.php'); // config.php itself includes common.php
$adminoutput=''; // Alle future output is written into this and then outputted at the end of file
// SET THE LANGUAGE???? -> DEFAULT SET TO EN FOR NOW
require_once($rootdir.'/classes/core/language.php');
$clang = new phpsurveyor_lang("en");

if (!$database_exists)
{
$adminoutput.= "<br />\n"
."<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>"
.$clang->gT("PHPSurveyor Setup")."</strong></td></tr>\n"
."\t<tr bgcolor='#CCCCCC'><td align='center'>\n"
."<strong>".$clang->gT("Welcome to PHPSurveyor Setup!")."</strong><br /><br />\n"
.$clang->gT("The database defined in config.php does not exist.")."<br />\n"
.$clang->gT("PHPSurveyor can attempt to create this database for you.")."<br /><br />\n"
.$clang->gT("Your selected database name is:")."<strong> $databasename</strong><br />\n"
."<br /><input type='submit' value='"
.$clang->gT("Create Database")."' onclick='location.href=\"createdb.php\"' /></center>\n"
."</td></tr></table>\n"
."</body>\n</html>\n";
}
elseif ($dbexistsbutempty && !(returnglobal('createdbstep2')==$clang->gT("Populate Database")))
{
$connect->database = $databasename;
$connect->Execute("USE DATABASE `$databasename`");
$adminoutput.= "<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>"
.$clang->gT("PHPSurveyor Setup")."</strong></td></tr>\n"
."\t<tr bgcolor='#CCCCCC'><td align='center'>\n";
$adminoutput.= "<br /><strong><font color='green'>\n";
$adminoutput.= sprintf($clang->gT('A database named "%s" does already exist.'),$databasename)."</font></strong></font><br /><br />\n";
$adminoutput.= $clang->gT("Do you want to populate that database now by creating the necessary tables?")."<br /><br />\n";
$adminoutput.= "<form method='post' action='createdb.php'>";
$adminoutput.= "<input type='submit' name='createdbstep2' value='".$clang->gT("Populate Database")."'></form>";
}
else
{
//DB EXISTS, CHECK FOR APPROPRIATE UPGRADES
checkforupgrades();
}
sendcacheheaders();
echo $adminoutput;

?>
<?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 Version 2 as published by the Free #
# Software Foundation. #
# #
# #
# 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. #
#############################################################
*/

require_once(dirname(__FILE__).'/../../config.php'); // config.php itself includes common.php
$adminoutput=''; // Alle future output is written into this and then outputted at the end of file
// SET THE LANGUAGE???? -> DEFAULT SET TO EN FOR NOW
require_once($rootdir.'/classes/core/language.php');
$clang = new phpsurveyor_lang("en");
ob_implicit_flush(true);
sendcacheheaders();

if (!$database_exists)
{
$adminoutput.= "<br />\n"
."<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>"
.$clang->gT("PHPSurveyor Setup")."</strong></td></tr>\n"
."\t<tr bgcolor='#CCCCCC'><td align='center'>\n"
."<strong>".$clang->gT("Welcome to PHPSurveyor Setup!")."</strong><br /><br />\n"
.$clang->gT("The database defined in config.php does not exist.")."<br />\n"
.$clang->gT("PHPSurveyor can attempt to create this database for you.")."<br /><br />\n"
.$clang->gT("Your selected database name is:")."<strong> $databasename</strong><br />\n"
."<br /><input type='submit' value='"
.$clang->gT("Create Database")."' onclick='location.href=\"createdb.php\"' /></center>\n"
."</td></tr></table>\n"
."</body>\n</html>\n";
}
elseif ($dbexistsbutempty && !(returnglobal('createdbstep2')==$clang->gT("Populate Database")))
{
$connect->database = $databasename;
$connect->Execute("USE DATABASE `$databasename`");
$adminoutput.= "<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>"
.$clang->gT("PHPSurveyor Setup")."</strong></td></tr>\n"
."\t<tr bgcolor='#CCCCCC'><td align='center'>\n";
$adminoutput.= "<br /><strong><font color='green'>\n";
$adminoutput.= sprintf($clang->gT('A database named "%s" does already exist.'),$databasename)."</font></strong></font><br /><br />\n";
$adminoutput.= $clang->gT("Do you want to populate that database now by creating the necessary tables?")."<br /><br />\n";
$adminoutput.= "<form method='post' action='createdb.php'>";
$adminoutput.= "<input type='submit' name='createdbstep2' value='".$clang->gT("Populate Database")."'></form>";
}
else
{
//DB EXISTS, CHECK FOR APPROPRIATE UPGRADES
$connect->database = $databasename;
$connect->Execute("USE DATABASE `$databasename`");
$output=checkforupgrades();
if (!isset($ouput)) {$adminoutput.='<br />PHPSurveyor Database is up to date. No action needed';}
else {$adminoutput.=$output;}
$adminoutput.="<br />Please <a href='$homeurl/$scriptname'>log in.</a>";

}
echo $adminoutput;


// This functions checks if the databaseversion in the settings table is the same one as required
function checkforupgrades()
{
global $connect, $databasetype, $dbprefix, $dbversionnumber, $clang;
$adminoutput='';
include ('upgrade-'.$databasetype.'.php');
$tables = $connect->MetaTables();

$usquery = "SELECT stg_value FROM ".db_table_name("settings_global")." where stg_name='DBVersion'";
$usresult = db_execute_assoc($usquery);
$usrow = $usresult->FetchRow();
if (intval($usrow['stg_value'])<$dbversionnumber)
{
db_upgrade(intval($usrow['stg_value']));
$adminoutput="<br />".$clang->gT("Database has been successfully upgraded to version ".$dbversionnumber);
}

return $adminoutput;
}


?>
113 changes: 76 additions & 37 deletions admin/install/upgrade-mysql.php
@@ -1,37 +1,76 @@
<?PHP

// There will be a file for each database (accordingly named to the dbADO scheme)
// where based on the current database version the database is upgraded
// For this there will be a settings table which holds the last time the database was upgraded

function db_upgrade($oldversion) {
/// This function does anything necessary to upgrade
/// older versions to match current functionality

if ($oldversion < 112) {
// modify_database("","ALTER TABLE `prefix_answers` ADD `language` varchar(20) default 'en'");
// modify_database("","ALTER TABLE `prefix_questions` ADD `language` varchar(20) default 'en'");
}



return true;
}

















?>
<?PHP

// There will be a file for each database (accordingly named to the dbADO scheme)
// where based on the current database version the database is upgraded
// For this there will be a settings table which holds the last time the database was upgraded

function db_upgrade($oldversion) {
/// This function does anything necessary to upgrade
/// older versions to match current functionality
global $modifyoutput;
echo str_pad('Loading... ',4096)."<br />\n";
if ($oldversion < 111) {
// Language upgrades from version 110 to 111 since the language names did change

$oldnewlanguages=array('german_informal'=>'german-informal',
'cns'=>'cn-Hans',
'cnt'=>'cn-Hant',
'pt_br'=>'pt-BR',
'gr'=>'el',
'jp'=>'ja',
'si'=>'sl',
'se'=>'sv',
'vn'=>'vi');

foreach ($oldnewlanguages as $oldlang=>$newlang)
{
modify_database("","update `prefix_answers` set `language`='$newlang' where language='$oldlang'"); echo $modifyoutput; flush();
modify_database("","update `prefix_questions` set `language`='$newlang' where language='$oldlang'");echo $modifyoutput;flush();
modify_database("","update `prefix_groups` set `language`='$newlang' where language='$oldlang'");echo $modifyoutput;flush();
modify_database("","update `prefix_labels` set `language`='$newlang' where language='$oldlang'");echo $modifyoutput;flush();
modify_database("","update `prefix_surveys` set `language`='$newlang' where language='$oldlang'");echo $modifyoutput;flush();
modify_database("","update `prefix_surveys_languagesettings` set `surveyls_language`='$newlang' where surveyls_language='$oldlang'");echo $modifyoutput;flush();
modify_database("","update `prefix_users` set `lang`='$newlang' where lang='$oldlang'");echo $modifyoutput;flush();
}



$resultdata=db_execute_assoc("select * from ".db_table_name("labelsets"));
while ($datarow = $resultdata->FetchRow()){
$toreplace=$datarow['languages'];
$toreplace=str_replace('german_informal','german-informal',$toreplace);
$toreplace=str_replace('cns','cn-Hans',$toreplace);
$toreplace=str_replace('cnt','cn-Hant',$toreplace);
$toreplace=str_replace('pt_br','pt-BR',$toreplace);
$toreplace=str_replace('gr','el',$toreplace);
$toreplace=str_replace('jp','ja',$toreplace);
$toreplace=str_replace('si','sl',$toreplace);
$toreplace=str_replace('se','sv',$toreplace);
$toreplace=str_replace('vn','vi',$toreplace);
modify_database("","update `prefix_labelsets` set `languages`='$toreplace' where lid=".$datarow['lid']);echo $modifyoutput;flush();
}


$resultdata=db_execute_assoc("select * from ".db_table_name("surveys"));
while ($datarow = $resultdata->FetchRow()){
$toreplace=$datarow['additional_languages'];
$toreplace=str_replace('german_informal','german-informal',$toreplace);
$toreplace=str_replace('cns','cn-Hans',$toreplace);
$toreplace=str_replace('cnt','cn-Hant',$toreplace);
$toreplace=str_replace('pt_br','pt-BR',$toreplace);
$toreplace=str_replace('gr','el',$toreplace);
$toreplace=str_replace('jp','ja',$toreplace);
$toreplace=str_replace('si','sl',$toreplace);
$toreplace=str_replace('se','sv',$toreplace);
$toreplace=str_replace('vn','vi',$toreplace);
modify_database("","update `prefix_surveys` set `additional_languages`='$toreplace' where sid=".$datarow['sid']);echo $modifyoutput;flush();
}
modify_database("","update `prefix_settings_global` set `stg_value`='111' where stg_name='DBVersion'"); echo $modifyoutput;

}


return true;
}

?>

0 comments on commit 78b6e79

Please sign in to comment.