2
0
mirror of https://github.com/ACSPRI/queXS synced 2024-04-02 12:12:16 +00:00

Merged from McMasterReports branch

This commit is contained in:
azammitdcarf
2010-01-14 07:45:37 +00:00
parent 18dbb16138
commit d1b139d315
1884 changed files with 555891 additions and 364768 deletions

View File

@@ -0,0 +1,185 @@
<?php
/*
* LimeSurvey
* Copyright (C) 2007 The LimeSurvey Project Team / Nicolas Barcet
* 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: index.php 4729 2008-05-31 21:32:02Z nijaba $
*/
$cmd_install=true;
if (isset($argv[1]) && ($argv[1]=='install'|| $argv[1]=='upgrade') && isset($argv[2]) && isset($argv[3]))
{
require_once($argv[2]);
require_once($argv[3]);
}
else
{
require_once(dirname(__FILE__).'/../../config-defaults.php');
require_once(dirname(__FILE__).'/../../common.php');
}
// SET THE LANGUAGE???? -> DEFAULT SET TO EN FOR NOW
require_once($rootdir.'/classes/core/language.php');
$clang = new limesurvey_lang("en");
ob_implicit_flush(true);
if (isset($argv[1]) && $argv[1]=='install')
{
print("trying to create and populate $databasename on $databaselocation:$databaseport ($databasetype) \n");
if (!$database_exists) //Database named in config.php does not exist
{
if($connect->Execute("CREATE DATABASE $databasename;"))
{
print("\nDatabase $databasename on $databasetype CREATED \n");
}
else
{
print("\nDatabase $databasename on $databasetype COULD NOT BE CREATED \n");
print("\n".$connect->ErrorMsg());
return 1;
}
}
else
{
if ($databasetype=='mysql' || $databasetype=='mysqli') {$connect->Execute("ALTER DATABASE `$databasename` DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;");} //Set the collation also for manually created DBs
print("\nDatabase $databasename on $databasetype EXISTS, not created \n");
}
// Connect to the database we created a sec ago or to the existing db.
if(!$connect->Connect($databaselocation,$databaseuser,$databasepass,$databasename))
{
print("\n".$connect->ErrorMsg());
return 1;
}
require_once($homedir."/classes/core/sha256.php");
$success = 0; // Let's be optimistic
$createdbtype=$databasetype;
if ($createdbtype=='mssql_n' || $createdbtype=='odbc_mssql' || $createdbtype=='odbtp') $createdbtype='mssql';
$sqlfile = dirname(__FILE__).'/create-'.$createdbtype.'.sql' ;
if (!empty($sqlfile)) {
if (!is_readable($sqlfile)) {
$success = false;
print "\nTried to populate database, but '". $sqlfile ."' doesn't exist!\n";
return $success;
} else {
$lines = file($sqlfile);
}
} else {
$sqlstring = trim($sqlstring);
if ($sqlstring{strlen($sqlstring)-1} != ";") {
$sqlstring .= ";"; // add it in if it's not there.
}
$lines[] = $sqlstring;
}
$command = '';
$connect->SetFetchMode(ADODB_FETCH_NUM);
foreach ($lines as $line) {
$line = rtrim($line);
$length = strlen($line);
if ($length and $line[0] <> '#' and substr($line,0,2) <> '--') {
if (substr($line, $length-1, 1) == ';') {
$line = substr($line, 0, $length-1); // strip ;
$command .= $line;
$command = str_replace('prefix_', $dbprefix, $command); // Table prefixes
$command = str_replace('$defaultuser', $defaultuser, $command); // variables By Moses
$command = str_replace('$defaultpass', SHA256::hashing($defaultpass), $command); // variables By Moses
$command = str_replace('$siteadminname', $siteadminname, $command);
$command = str_replace('$siteadminemail', $siteadminemail, $command); // variables By Moses
$command = str_replace('$defaultlang', $defaultlang, $command); // variables By Moses
$command = str_replace('$sessionname', 'ls'.getRandomID().getRandomID().getRandomID().getRandomID(), $command); // variables By Moses
$command = str_replace('$databasetabletype', $databasetabletype, $command);
if(!$connect->Execute($command,false))
{
print ("\n".$clang->gT("Executing").".....".$command."...".$clang->gT('Failed! Reason:')."\n".$connect->ErrorMsg()."\n\n");
$success=1;
}
$command = '';
} else {
$command .= $line;
}
}
}
$connect->SetFetchMode(ADODB_FETCH_ASSOC);
if($success == 0)
{
print("Database $databasename on $databasetype POPULATED");
print("\n\neverything went fine");
return $success;
}
else
{
print("\n\nSomething is strange");
print("\nplease check you Database and Settings");
return $success;
}
// if (modify_database(dirname(__FILE__).'\create-'.$databasetype.'.sql'))
// {
// print("\nDatabase $databasename on $databasetype POPULATED \n");
// return 0;
// } else {
// print("Could not populate $databasename on $databasetype\n");
// return 1;
// }
}
elseif (isset($argv[1]) && $argv[1]=='upgrade')
{
$upgradedbtype=$databasetype;
if ($upgradedbtype=='mssql_n' || $upgradedbtype=='odbc_mssql' || $upgradedbtype=='odbtp') $upgradedbtype='mssql';
include ('upgrade-'.$upgradedbtype.'.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)
{
print("Upgrading db to $dbversionnumber\n");
db_upgrade(intval($usrow['stg_value']));
} else {
print("Already at db version $dbversionnumber\n");
}
return 0;
}
else
{
print("LimeSurvey Commandline Install\n");
print("Usage: cmd_install <option> < <<path1>> <<path2>> >\n");
print("<option> - 'install' or 'upgrade' \n");
print("<<path1>> - Full path including filename to a custom config-defaults.php\n");
print("<<path2>> - Full path including filename to a custom common.php\n");
print("Paths are optional. If used both paths must be set.\n");
return 2;
}
?>

View File

@@ -1,4 +1,4 @@
-- phpSurveyor MS SQL Server 2000 database schema
-- LimeSurvey MS SQL Server 2000 database schema
-- --------------------------------------------------------
@@ -9,11 +9,21 @@ CREATE TABLE [prefix_quota] (
[qlimit] int ,
[action] int ,
[active] int NOT NULL default '1',
[autoload_url] int NOT NULL default '0',
PRIMARY KEY ([id])
);
CREATE TABLE [prefix_quota_languagesettings] (
[quotals_id] int NOT NULL IDENTITY (1,1),
[quotals_quota_id] int,
[quotals_language] varchar(45) NOT NULL default 'en',
[quotals_name] varchar(255),
[quotals_message] text,
[quotals_url] varchar(255),
[quotals_urldescrip] varchar(255),
PRIMARY KEY ([quotals_id])
);
CREATE TABLE [prefix_quota_members] (
@@ -21,7 +31,7 @@ CREATE TABLE [prefix_quota_members] (
[sid] int ,
[qid] int ,
[quota_id] int ,
[code] varchar(5) ,
[code] varchar(11) ,
PRIMARY KEY ([id])
);
@@ -35,9 +45,10 @@ CREATE TABLE [prefix_quota_members] (
CREATE TABLE [prefix_answers] (
[qid] INT NOT NULL default '0',
[code] VARCHAR(5) NOT NULL default '',
[answer] varchar(255) NOT NULL,
[answer] varchar(8000) NOT NULL,
[default_value] char(1) NOT NULL default 'N',
[sortorder] INT NOT NULL,
[assessment_value] INT NOT NULL default '0',
[language] VARCHAR(20) default 'en',
PRIMARY KEY ([qid],[code],[language])
)
@@ -58,8 +69,8 @@ CREATE TABLE [prefix_assessments] (
[minimum] VARCHAR(50) NOT NULL default '',
[maximum] VARCHAR(50) NOT NULL default '',
[message] text NOT NULL,
[link] text NOT NULL,
PRIMARY KEY ([id])
[language] VARCHAR(20) NOT NULL default 'en',
PRIMARY KEY ([id],[language])
)
;
@@ -72,6 +83,7 @@ CREATE TABLE [prefix_assessments] (
CREATE TABLE [prefix_conditions] (
[cid] INT NOT NULL IDENTITY (1,1),
[qid] INT NOT NULL default '0',
[scenario] INT NOT NULL default '1',
[cqid] INT NOT NULL default '0',
[cfieldname] VARCHAR(50) NOT NULL default '',
[method] char(2) NOT NULL default '',
@@ -107,6 +119,7 @@ CREATE TABLE [prefix_labels] (
[title] VARCHAR(4000),
[sortorder] INT NOT NULL,
[language] VARCHAR(20) default 'en',
[assessment_value] INT NOT NULL default '0',
PRIMARY KEY ([lid],[sortorder],[language]),
)
;
@@ -139,7 +152,7 @@ CREATE TABLE [prefix_question_attributes] (
[qaid] INT NOT NULL IDENTITY (1,1),
[qid] INT NOT NULL default '0',
[attribute] VARCHAR(50) default NULL,
[value] VARCHAR(20) default NULL,
[value] TEXT default NULL,
PRIMARY KEY ([qaid])
)
;
@@ -203,35 +216,38 @@ CREATE TABLE [prefix_surveys] (
[owner_id] INT NOT NULL,
[admin] VARCHAR(50) default NULL,
[active] char(1) NOT NULL default 'N',
[startdate] DATETIME default NULL,
[expires] DATETIME default NULL,
[adminemail] VARCHAR(320) default NULL,
[private] char(1) default NULL,
[faxto] VARCHAR(20) default NULL,
[format] char(1) default NULL,
[template] VARCHAR(100) default 'default',
[url] VARCHAR(255) default NULL,
[language] VARCHAR(50) default NULL,
[additional_languages] VARCHAR(255) default NULL,
[datestamp] char(1) default 'N',
[usecookie] char(1) default 'N',
[notification] char(1) default '0',
[allowregister] char(1) default 'N',
[attribute1] VARCHAR(255) default NULL,
[attribute2] VARCHAR(255) default NULL,
[allowsave] char(1) default 'Y',
[autonumber_start] bigINT default '0',
[autoredirect] char(1) default 'N',
[allowprev] char(1) default 'Y',
[printanswers] char(1) default 'N',
[ipaddr] char(1) default 'N',
[useexpiry] char(1) NOT NULL default 'N',
[refurl] char(1) default 'N',
[datecreated] DATETIME default NULL,
[listpublic] char(1) default 'N',
[publicstatistics] char(1) default 'N',
[publicgraphs] char(1) default 'N',
[htmlemail] char(1) default 'N',
[tokenanswerspersistence] char(1) default 'N',
[assessments] char(1) default 'N',
[usecaptcha] char(1) default 'N',
[usetokens] char(1) default 'N',
[bounce_email] VARCHAR(320) default NULL,
[attributedescriptions] text,
PRIMARY KEY ([sid])
)
;
@@ -249,6 +265,8 @@ CREATE TABLE [prefix_surveys_languagesettings] (
[surveyls_title] VARCHAR(200) NOT NULL,
[surveyls_description] TEXT NULL,
[surveyls_welcometext] TEXT NULL,
[surveyls_endtext] TEXT NULL,
[surveyls_url] VARCHAR(255) NULL,
[surveyls_urldescription] VARCHAR(255) NULL,
[surveyls_email_invite_subj] VARCHAR(255) NULL,
[surveyls_email_invite] TEXT NULL,
@@ -258,6 +276,7 @@ CREATE TABLE [prefix_surveys_languagesettings] (
[surveyls_email_register] TEXT NULL,
[surveyls_email_confirm_subj] VARCHAR(255) NULL,
[surveyls_email_confirm] TEXT NULL,
[surveyls_dateformat] INT NOT NULL DEFAULT 1,
PRIMARY KEY ([surveyls_survey_id],[surveyls_language])
)
;
@@ -269,7 +288,7 @@ CREATE TABLE [prefix_surveys_languagesettings] (
CREATE TABLE [prefix_users] (
[uid] INT NOT NULL IDENTITY (1,1) PRIMARY KEY,
[users_name] VARCHAR(64) NOT NULL UNIQUE default '',
[password] TEXT NOT NULL default '',
[password] varchar(8000) NOT NULL default '',
[full_name] VARCHAR(50) NOT NULL,
[parent_id] INT NOT NULL,
[lang] VARCHAR(20),
@@ -281,9 +300,11 @@ CREATE TABLE [prefix_users] (
[configurator] TINYINT NOT NULL default '0',
[manage_template] TINYINT NOT NULL default '0',
[manage_label] TINYINT NOT NULL default '0',
[htmleditormode] char(7) default 'default'
)
;
[htmleditormode] char(7) default 'default',
[one_time_pw] TEXT,
[dateformat] INT NOT NULL DEFAULT 1
);
--
-- Table structure for table [surveys_rights]
@@ -352,12 +373,30 @@ CREATE TABLE [prefix_templates] (
-- Table [settings_global]
--
INSERT INTO [prefix_settings_global] VALUES ('DBVersion', '126');
INSERT INTO [prefix_settings_global] VALUES ('DBVersion', '138');
INSERT INTO [prefix_settings_global] VALUES ('SessionName', '$sessionname');
--
-- Table [users]
-- indexes
--
create index [answers_idx2] on [prefix_answers] ([sortorder]);
create index [assessments_idx2] on [prefix_assessments] ([sid]);
create index [assessments_idx3] on [prefix_assessments] ([gid]);
create index [conditions_idx2] on [prefix_conditions] ([qid]);
create index [conditions_idx3] on [prefix_conditions] ([cqid]);
create index [groups_idx2] on [prefix_groups] ([sid]);
create index [questions_idx2] on [prefix_questions] ([sid]);
create index [questions_idx3] on [prefix_questions] ([gid]);
create index [questions_idx4] on [prefix_questions] ([type]);
create index [question_attributes_idx2] on [prefix_question_attributes] ([qid]);
create index [quota_idx2] on [prefix_quota] ([sid]);
create index [saved_control_idx2] on [prefix_saved_control] ([sid]);
create index [user_in_groups_idx1] on [prefix_user_in_groups] ([ugid], [uid]);
--
-- Create the admin user
--
INSERT INTO [prefix_users] VALUES ('$defaultuser', '$defaultpass', '$siteadminname', 0, '$defaultlang', '$siteadminemail', 1,1,1,1,1,1,1,'default');
INSERT INTO [prefix_users] ([users_name], [password], [full_name], [parent_id], [lang] ,[email], [create_survey], [create_user] ,[delete_user] ,[superadmin] ,[configurator] ,[manage_template] , [manage_label]) VALUES ('$defaultuser', '$defaultpass', '$siteadminname', 0, '$defaultlang', '$siteadminemail', 1,1,1,1,1,1,1);

View File

@@ -1,17 +1,3 @@
-- phpMyAdmin SQL Dump
-- version 2.8.0.2
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Jul 23, 2006 at 07:56 PM
-- Server version: 5.0.20
-- PHP Version: 5.1.4
--
-- Database: `limesurvey-development`
--
--
-- Table structure for table `answers`
--
@@ -21,10 +7,11 @@ CREATE TABLE `prefix_answers` (
`code` varchar(5) NOT NULL default '',
`answer` text NOT NULL,
`default_value` char(1) NOT NULL default 'N',
`assessment_value` int(11) NOT NULL default '0',
`sortorder` int(11) NOT NULL,
`language` varchar(20) default 'en',
PRIMARY KEY (`qid`,`code`,`language`)
) TYPE=$databasetabletype CHARACTER SET utf8 COLLATE utf8_unicode_ci;
) ENGINE=$databasetabletype CHARACTER SET utf8 COLLATE utf8_unicode_ci;
-- --------------------------------------------------------
@@ -41,9 +28,9 @@ CREATE TABLE `prefix_assessments` (
`minimum` varchar(50) NOT NULL default '',
`maximum` varchar(50) NOT NULL default '',
`message` text NOT NULL,
`link` text NOT NULL,
PRIMARY KEY (`id`)
) TYPE=$databasetabletype AUTO_INCREMENT=1 CHARACTER SET utf8 COLLATE utf8_unicode_ci;
`language` varchar(20) NOT NULL default 'en',
PRIMARY KEY (`id`,`language`)
) ENGINE=$databasetabletype AUTO_INCREMENT=1 CHARACTER SET utf8 COLLATE utf8_unicode_ci;
-- --------------------------------------------------------
@@ -54,12 +41,13 @@ CREATE TABLE `prefix_assessments` (
CREATE TABLE `prefix_conditions` (
`cid` int(11) NOT NULL auto_increment,
`qid` int(11) NOT NULL default '0',
`scenario` int(11) NOT NULL default '1',
`cqid` int(11) NOT NULL default '0',
`cfieldname` varchar(50) NOT NULL default '',
`method` char(2) NOT NULL default '',
`value` varchar(255) NOT NULL default '',
PRIMARY KEY (`cid`)
) TYPE=$databasetabletype AUTO_INCREMENT=1 CHARACTER SET utf8 COLLATE utf8_unicode_ci;
) ENGINE=$databasetabletype AUTO_INCREMENT=1 CHARACTER SET utf8 COLLATE utf8_unicode_ci;
--
@@ -74,7 +62,7 @@ CREATE TABLE `prefix_groups` (
`description` text,
`language` varchar(20) default 'en',
PRIMARY KEY (`gid`,`language`)
) TYPE=$databasetabletype AUTO_INCREMENT=1 CHARACTER SET utf8 COLLATE utf8_unicode_ci;
) ENGINE=$databasetabletype AUTO_INCREMENT=1 CHARACTER SET utf8 COLLATE utf8_unicode_ci;
-- --------------------------------------------------------
@@ -87,10 +75,11 @@ CREATE TABLE `prefix_labels` (
`code` varchar(5) NOT NULL default '',
`title` text,
`sortorder` int(11) NOT NULL,
`assessment_value` int(11) NOT NULL default '0',
`language` varchar(20) default 'en',
PRIMARY KEY (`lid`,`sortorder`,`language`),
KEY `ixcode` (`code`)
) TYPE=$databasetabletype CHARACTER SET utf8 COLLATE utf8_unicode_ci;
) ENGINE=$databasetabletype CHARACTER SET utf8 COLLATE utf8_unicode_ci;
-- --------------------------------------------------------
@@ -103,7 +92,7 @@ CREATE TABLE `prefix_labelsets` (
`label_name` varchar(100) NOT NULL default '',
`languages` varchar(200) default 'en',
PRIMARY KEY (`lid`)
) TYPE=$databasetabletype AUTO_INCREMENT=1 CHARACTER SET utf8 COLLATE utf8_unicode_ci;
) ENGINE=$databasetabletype AUTO_INCREMENT=1 CHARACTER SET utf8 COLLATE utf8_unicode_ci;
-- --------------------------------------------------------
@@ -115,9 +104,9 @@ CREATE TABLE `prefix_question_attributes` (
`qaid` int(11) NOT NULL auto_increment,
`qid` int(11) NOT NULL default '0',
`attribute` varchar(50) default NULL,
`value` varchar(20) default NULL,
`value` text default NULL,
PRIMARY KEY (`qaid`)
) TYPE=$databasetabletype AUTO_INCREMENT=1 CHARACTER SET utf8 COLLATE utf8_unicode_ci;
) ENGINE=$databasetabletype AUTO_INCREMENT=1 CHARACTER SET utf8 COLLATE utf8_unicode_ci;
-- --------------------------------------------------------
@@ -129,10 +118,25 @@ CREATE TABLE `prefix_quota` (
`qlimit` int(8) default NULL,
`action` int(2) default NULL,
`active` int(1) NOT NULL default '1',
`autoload_url` int(1) NOT NULL default '0',
PRIMARY KEY (`id`)
) TYPE=$databasetabletype CHARACTER SET utf8 COLLATE utf8_unicode_ci;
) ENGINE=$databasetabletype CHARACTER SET utf8 COLLATE utf8_unicode_ci;
--
-- Table Structure for table quota_languagesettings
--
CREATE TABLE `prefix_quota_languagesettings` (
`quotals_id` int(11) NOT NULL auto_increment,
`quotals_quota_id` int(11) NOT NULL default '0',
`quotals_language` varchar(45) NOT NULL default 'en',
`quotals_name` varchar(255) collate utf8_unicode_ci default NULL,
`quotals_message` text NOT NULL,
`quotals_url` varchar(255),
`quotals_urldescrip` varchar(255),
PRIMARY KEY (`quotals_id`)
) ENGINE=$databasetabletype CHARACTER SET utf8 COLLATE utf8_unicode_ci;
@@ -141,10 +145,10 @@ CREATE TABLE `prefix_quota_members` (
`sid` int(11) default NULL,
`qid` int(11) default NULL,
`quota_id` int(11) default NULL,
`code` varchar(5) collate utf8_unicode_ci default NULL,
`code` varchar(11) collate utf8_unicode_ci default NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `sid` (`sid`,`qid`,`quota_id`,`code`)
) TYPE=$databasetabletype CHARACTER SET utf8 COLLATE utf8_unicode_ci;
) ENGINE=$databasetabletype CHARACTER SET utf8 COLLATE utf8_unicode_ci;
--
@@ -167,7 +171,7 @@ CREATE TABLE `prefix_questions` (
`question_order` int(11) NOT NULL,
`language` varchar(20) default 'en',
PRIMARY KEY (`qid`,`language`)
) TYPE=$databasetabletype AUTO_INCREMENT=1 CHARACTER SET utf8 COLLATE utf8_unicode_ci;
) ENGINE=$databasetabletype AUTO_INCREMENT=1 CHARACTER SET utf8 COLLATE utf8_unicode_ci;
-- --------------------------------------------------------
@@ -189,7 +193,7 @@ CREATE TABLE `prefix_saved_control` (
`saved_date` datetime NOT NULL,
`refurl` text,
PRIMARY KEY (`scid`)
) TYPE=$databasetabletype AUTO_INCREMENT=1 CHARACTER SET utf8 COLLATE utf8_unicode_ci;
) ENGINE=$databasetabletype AUTO_INCREMENT=1 CHARACTER SET utf8 COLLATE utf8_unicode_ci;
-- --------------------------------------------------------
@@ -201,7 +205,7 @@ CREATE TABLE `prefix_settings_global` (
`stg_name` varchar(50) NOT NULL default '',
`stg_value` varchar(255) NOT NULL default '',
PRIMARY KEY (`stg_name`)
) TYPE=$databasetabletype CHARACTER SET utf8 COLLATE utf8_unicode_ci;
) ENGINE=$databasetabletype CHARACTER SET utf8 COLLATE utf8_unicode_ci;
--
@@ -214,36 +218,38 @@ CREATE TABLE `prefix_surveys` (
`admin` varchar(50) default NULL,
`active` char(1) NOT NULL default 'N',
`expires` date default NULL,
`startdate` date default NULL,
`adminemail` varchar(320) default NULL,
`private` char(1) default NULL,
`faxto` varchar(20) default NULL,
`format` char(1) default NULL,
`template` varchar(100) default 'default',
`url` varchar(255) default NULL,
`language` varchar(50) default NULL,
`additional_languages` varchar(255) default NULL,
`datestamp` char(1) default 'N',
`usecookie` char(1) default 'N',
`notification` char(1) default '0',
`allowregister` char(1) default 'N',
`attribute1` varchar(255) default NULL,
`attribute2` varchar(255) default NULL,
`allowsave` char(1) default 'Y',
`autonumber_start` bigint(11) default '0',
`autoredirect` char(1) default 'N',
`allowprev` char(1) default 'Y',
`printanswers` char(1) default 'N',
`ipaddr` char(1) default 'N',
`useexpiry` char(1) NOT NULL default 'N',
`refurl` char(1) default 'N',
`datecreated` date default NULL,
`publicstatistics` char(1) default 'N',
`publicgraphs` char(1) default 'N',
`listpublic` char(1) default 'N',
`htmlemail` char(1) default 'N',
`tokenanswerspersistence` char(1) default 'N',
`assessments` char(1) default 'N',
`usecaptcha` char(1) default 'N',
`usetokens` char(1) default 'N',
`bounce_email` varchar(320) default NULL,
`attributedescriptions` text,
PRIMARY KEY (`sid`)
) TYPE=$databasetabletype CHARACTER SET utf8 COLLATE utf8_unicode_ci;
) ENGINE=$databasetabletype CHARACTER SET utf8 COLLATE utf8_unicode_ci;
--
@@ -258,6 +264,8 @@ CREATE TABLE `prefix_surveys_languagesettings` (
`surveyls_title` VARCHAR(200) NOT NULL,
`surveyls_description` TEXT NULL,
`surveyls_welcometext` TEXT NULL,
`surveyls_endtext` TEXT NULL,
`surveyls_url` VARCHAR(255) NULL,
`surveyls_urldescription` VARCHAR(255) NULL,
`surveyls_email_invite_subj` VARCHAR(255) NULL,
`surveyls_email_invite` TEXT NULL,
@@ -267,6 +275,8 @@ CREATE TABLE `prefix_surveys_languagesettings` (
`surveyls_email_register` TEXT NULL,
`surveyls_email_confirm_subj` VARCHAR(255) NULL,
`surveyls_email_confirm` TEXT NULL,
`surveyls_dateformat` INT UNSIGNED NOT NULL DEFAULT 1,
PRIMARY KEY (`surveyls_survey_id`, `surveyls_language`)
)
TYPE = $databasetabletype CHARACTER SET utf8 COLLATE utf8_unicode_ci;
@@ -286,7 +296,7 @@ CREATE TABLE `prefix_surveys_rights` (
`delete_survey` tinyint(1) NOT NULL default '0',
`activate_survey` tinyint(1) NOT NULL default '0',
PRIMARY KEY (sid, uid)
) TYPE=$databasetabletype CHARACTER SET utf8 COLLATE utf8_unicode_ci;
) ENGINE=$databasetabletype CHARACTER SET utf8 COLLATE utf8_unicode_ci;
@@ -295,14 +305,14 @@ CREATE TABLE `prefix_user_groups` (
`name` varchar(20) NOT NULL UNIQUE,
`description` TEXT NOT NULL,
`owner_id` int(10) unsigned NOT NULL
) TYPE=$databasetabletype CHARACTER SET utf8 COLLATE utf8_unicode_ci;
) ENGINE=$databasetabletype CHARACTER SET utf8 COLLATE utf8_unicode_ci;
CREATE TABLE `prefix_user_in_groups` (
`ugid` int(10) unsigned NOT NULL,
`uid` int(10) unsigned NOT NULL
) TYPE=$databasetabletype CHARACTER SET utf8 COLLATE utf8_unicode_ci;
) ENGINE=$databasetabletype CHARACTER SET utf8 COLLATE utf8_unicode_ci;
--
-- Table structure for table `users`
@@ -323,8 +333,11 @@ CREATE TABLE `prefix_users` (
`configurator` tinyint(1) NOT NULL default '0',
`manage_template` tinyint(1) NOT NULL default '0',
`manage_label` tinyint(1) NOT NULL default '0',
`htmleditormode` varchar(7) default 'default'
) TYPE=$databasetabletype CHARACTER SET utf8 COLLATE utf8_unicode_ci;
`htmleditormode` varchar(7) default 'default',
`one_time_pw` BLOB,
`dateformat` INT UNSIGNED NOT NULL DEFAULT 1
) ENGINE=$databasetabletype CHARACTER SET utf8 COLLATE utf8_unicode_ci;
@@ -334,25 +347,44 @@ CREATE TABLE `prefix_templates_rights` (
`folder` varchar(255) NOT NULL,
`use` int(1) NOT NULL,
PRIMARY KEY (`uid`,`folder`)
) TYPE=$databasetabletype CHARACTER SET utf8 COLLATE utf8_unicode_ci;
) ENGINE=$databasetabletype CHARACTER SET utf8 COLLATE utf8_unicode_ci;
CREATE TABLE `prefix_templates` (
`folder` varchar(255) NOT NULL,
`creator` int(11) NOT NULL,
PRIMARY KEY (`folder`)
) TYPE=$databasetabletype CHARACTER SET utf8 COLLATE utf8_unicode_ci;
) ENGINE=$databasetabletype CHARACTER SET utf8 COLLATE utf8_unicode_ci;
--
-- Table `settings_global`
--
INSERT INTO `prefix_settings_global` VALUES ('DBVersion', '126');
INSERT INTO `prefix_settings_global` VALUES ('DBVersion', '138');
INSERT INTO `prefix_settings_global` VALUES ('SessionName', '$sessionname');
--
-- Table `users`
--
INSERT INTO `prefix_users` VALUES (NULL, '$defaultuser', '$defaultpass', '$siteadminname', 0, '$defaultlang', '$siteadminemail', 1,1,1,1,1,1,1,'default');
INSERT INTO `prefix_users` (`users_name`, `password`, `full_name`, `parent_id`, `lang` ,`email`, `create_survey`,`create_user` ,`delete_user` ,`superadmin` ,`configurator` ,`manage_template` , `manage_label`) VALUES ('$defaultuser', '$defaultpass', '$siteadminname', 0, '$defaultlang', '$siteadminemail', 1,1,1,1,1,1,1);
--
-- indexes
--
create index `answers_idx2` on `prefix_answers` (`sortorder`);
create index `assessments_idx2` on `prefix_assessments` (`sid`);
create index `assessments_idx3` on `prefix_assessments` (`gid`);
create index `conditions_idx2` on `prefix_conditions` (`qid`);
create index `conditions_idx3` on `prefix_conditions` (`cqid`);
create index `groups_idx2` on `prefix_groups` (`sid`);
create index `question_attributes_idx2` on `prefix_question_attributes` (`qid`);
create index `questions_idx2` on `prefix_questions` (`sid`);
create index `questions_idx3` on `prefix_questions` (`gid`);
create index `questions_idx4` on `prefix_questions` (`type`);
create index `quota_idx2` on `prefix_quota` (`sid`);
create index `saved_control_idx2` on `prefix_saved_control` (`sid`);
create index `user_in_groups_idx1` on `prefix_user_in_groups` (`ugid`, `uid`);

View File

@@ -22,6 +22,7 @@ CREATE TABLE prefix_answers (
answer text NOT NULL,
default_value character(1) DEFAULT 'N'::bpchar NOT NULL,
sortorder integer NOT NULL,
assessment_value integer DEFAULT 0 NOT NULL,
"language" character varying(20) DEFAULT 'en'::character varying NOT NULL
);
@@ -41,7 +42,7 @@ CREATE TABLE prefix_assessments (
minimum character varying(50) DEFAULT ''::character varying NOT NULL,
maximum character varying(50) DEFAULT ''::character varying NOT NULL,
message text NOT NULL,
link text NOT NULL
language character(20) DEFAULT 'en'::bpchar NOT NULL
);
@@ -54,6 +55,7 @@ CREATE TABLE prefix_assessments (
CREATE TABLE prefix_conditions (
cid serial,
qid integer DEFAULT 0 NOT NULL,
scenario integer DEFAULT 1 NOT NULL,
cqid integer DEFAULT 0 NOT NULL,
cfieldname character varying(50) DEFAULT ''::character varying NOT NULL,
method character(2) DEFAULT ''::bpchar NOT NULL,
@@ -87,6 +89,7 @@ CREATE TABLE prefix_labels (
code character varying(5) DEFAULT ''::character varying NOT NULL,
title text,
sortorder integer NOT NULL,
assessment_value integer DEFAULT 0 NOT NULL,
"language" character varying(20) DEFAULT 'en'::character varying NOT NULL
);
@@ -115,7 +118,7 @@ CREATE TABLE prefix_question_attributes (
qaid serial NOT NULL,
qid integer DEFAULT 0 NOT NULL,
attribute character varying(50),
value character varying(20)
value text NULL
);
--
@@ -128,20 +131,33 @@ CREATE TABLE prefix_quota (
name character varying(255),
qlimit integer,
"action" integer,
"active" integer NOT NULL default '1'
"active" integer NOT NULL default '1',
autoload_url integer NOT NULL DEFAULT 0
);
ALTER TABLE ONLY prefix_quota
ADD CONSTRAINT prefix_quota_pkey PRIMARY KEY (id);
CREATE TABLE prefix_quota_languagesettings
(
quotals_id serial NOT NULL,
quotals_quota_id integer NOT NULL DEFAULT 0,
quotals_language character varying(45) NOT NULL DEFAULT 'en'::character varying,
quotals_name character varying(200),
quotals_message text NOT NULL,
quotals_url character varying(255),
quotals_urldescrip character varying(255)
);
ALTER TABLE ONLY prefix_quota_languagesettings
ADD CONSTRAINT prefix_quota_languagesettings_pkey PRIMARY KEY (quotals_id);
CREATE TABLE prefix_quota_members (
id serial,
sid integer,
qid integer,
quota_id integer,
code character varying(5)
code character varying(11)
);
ALTER TABLE ONLY prefix_quota_members
@@ -213,36 +229,37 @@ CREATE TABLE prefix_surveys (
owner_id integer NOT NULL,
"admin" character varying(50),
active character(1) DEFAULT 'N'::bpchar NOT NULL,
startdate date,
expires date,
adminemail character varying(320) NOT NULL,
private character(1),
faxto character varying(20),
format character(1),
"template" character varying(100) DEFAULT 'default'::character varying,
url character varying(255),
"language" character varying(50),
additional_languages character varying(255),
datestamp character(1) DEFAULT 'N'::bpchar,
usecookie character(1) DEFAULT 'N'::bpchar,
notification character(1) DEFAULT '0'::bpchar,
allowregister character(1) DEFAULT 'N'::bpchar,
attribute1 character varying(255),
attribute2 character varying(255),
allowsave character(1) DEFAULT 'Y'::bpchar,
printanswers character(1) DEFAULT 'N'::bpchar,
autonumber_start integer DEFAULT 0,
autoredirect character(1) DEFAULT 'N'::bpchar,
allowprev character(1) DEFAULT 'Y'::bpchar,
ipaddr character(1) DEFAULT 'N'::bpchar,
useexpiry character(1) DEFAULT 'N'::bpchar NOT NULL,
refurl character(1) DEFAULT 'N'::bpchar,
datecreated date,
listpublic character(1) DEFAULT 'N'::bpchar,
publicstatistics character(1) DEFAULT 'N'::bpchar,
publicgraphs character(1) DEFAULT 'N'::bpchar,
htmlemail character(1) DEFAULT 'N'::bpchar,
tokenanswerspersistence character(1) DEFAULT 'N'::bpchar,
assessments character(1) DEFAULT 'N'::bpchar,
usecaptcha character(1) DEFAULT 'N'::bpchar,
"bounce_email" character varying(320) NOT NULL
usetokens character(1) DEFAULT 'N'::bpchar,
"bounce_email" character varying(320) NOT NULL,
attributedescriptions text
);
@@ -258,7 +275,9 @@ CREATE TABLE prefix_surveys_languagesettings (
surveyls_title character varying(200) NOT NULL,
surveyls_description text,
surveyls_welcometext text,
surveyls_url character varying(255),
surveyls_urldescription character varying(255),
surveyls_endtext text,
surveyls_email_invite_subj character varying(255),
surveyls_email_invite text,
surveyls_email_remind_subj character varying(255),
@@ -266,7 +285,8 @@ CREATE TABLE prefix_surveys_languagesettings (
surveyls_email_register_subj character varying(255),
surveyls_email_register text,
surveyls_email_confirm_subj character varying(255),
surveyls_email_confirm text
surveyls_email_confirm text,
surveyls_dateformat integer DEFAULT 1 NOT NULL
);
@@ -310,8 +330,8 @@ CREATE TABLE prefix_user_in_groups (
--
CREATE TABLE prefix_users (
uid serial NOT NULL,
users_name character varying(64) DEFAULT ''::character varying NOT NULL,
uid serial PRIMARY KEY NOT NULL,
users_name character varying(64) DEFAULT ''::character varying UNIQUE NOT NULL,
"password" bytea NOT NULL,
full_name character varying(50) NOT NULL,
parent_id integer NOT NULL,
@@ -324,10 +344,11 @@ CREATE TABLE prefix_users (
configurator integer DEFAULT 0 NOT NULL,
manage_template integer DEFAULT 0 NOT NULL,
manage_label integer DEFAULT 0 NOT NULL,
htmleditormode character(7) DEFAULT 'default'::bpchar
htmleditormode character(7) DEFAULT 'default'::bpchar,
one_time_pw bytea,
"dateformat" integer DEFAULT 1 NOT NULL
);
CREATE TABLE prefix_templates_rights (
"uid" integer NOT NULL,
"folder" character varying(255) NOT NULL,
@@ -364,7 +385,7 @@ ALTER TABLE ONLY prefix_answers
--
ALTER TABLE ONLY prefix_assessments
ADD CONSTRAINT prefix_assessments_pkey PRIMARY KEY (id);
ADD CONSTRAINT prefix_assessments_pkey PRIMARY KEY (id,language);
--
@@ -489,11 +510,29 @@ CREATE INDEX prefix_labels_ixcode_idx ON prefix_labels USING btree (code);
-- Table `settings_global`
--
INSERT INTO prefix_settings_global VALUES ('DBVersion', '126');
INSERT INTO prefix_settings_global VALUES ('DBVersion', '138');
INSERT INTO prefix_settings_global VALUES ('SessionName', '$sessionname');
--
-- Table `users`
-- indexes
--
create index assessments_idx2 on prefix_assessments (sid);
create index assessments_idx3 on prefix_assessments (gid);
create index conditions_idx2 on prefix_conditions (qid);
create index groups_idx2 on prefix_groups (sid);
create index question_attributes_idx2 on prefix_question_attributes (qid);
create index questions_idx2 on prefix_questions (sid);
create index questions_idx3 on prefix_questions (gid);
create index quota_idx2 on prefix_quota (sid);
create index saved_control_idx2 on prefix_saved_control (sid);
create index user_in_groups_idx1 on prefix_user_in_groups (ugid, uid);
--
-- Create admin user
--
INSERT INTO prefix_users(
@@ -502,3 +541,7 @@ INSERT INTO prefix_users(
manage_template, manage_label,htmleditormode)
VALUES ('$defaultuser', '$defaultpass', '$siteadminname', 0, '$defaultlang', '$siteadminemail',1,1,1,1,1,1,1,'default');

View File

@@ -10,7 +10,7 @@
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*
* $Id: createdb.php 4333 2008-02-25 13:19:12Z c_schmitz $
* $Id: createdb.php 7053 2009-06-10 10:43:43Z c_schmitz $
*/
//Ensure script is not run directly, avoid path disclosure
@@ -32,8 +32,13 @@ echo "\t<tr bgcolor='#CCCCCC'><td align='center'>$setfont\n";
// In Step2 fill the database with data
if (returnglobal('createdbstep2')==$clang->gT("Populate Database"))
{
if ($databasetype=='mysql') {@$connect->Execute("ALTER DATABASE `$dbname` DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;");} //Set the collation also for manually created DBs
if (modify_database(dirname(__FILE__).'/create-'.$databasetype.'.sql'))
$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 (modify_database(dirname(__FILE__).'/create-'.$createdbtype.'.sql'))
{
echo sprintf($clang->gT("Database `%s` has been successfully populated."),$dbname)."</font></strong></font><br /><br />\n";
echo "<input type='submit' value='".$clang->gT("Main Admin Screen")."' onclick='location.href=\"../$scriptname\"'>";
@@ -62,10 +67,12 @@ 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 'mssql': $createDb=$connect->Execute("CREATE DATABASE [$dbname];");
case 'odbtp': $createDb=$connect->Execute("CREATE DATABASE [$dbname];");
break;
default: $createDb=$connect->Execute("CREATE DATABASE $dbname");
}

View File

@@ -1,34 +0,0 @@
<?php
/*
* LimeSurvey
* Copyright (C) 2007 The LimeSurvey Project Team / Nicolas Barcet
* 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: index.php 4729 2008-05-31 21:32:02Z nijaba $
*/
require_once(dirname(__FILE__).'/../../config-defaults.php');
require_once(dirname(__FILE__).'/../../common.php');
// SET THE LANGUAGE???? -> DEFAULT SET TO EN FOR NOW
require_once($rootdir.'/classes/core/language.php');
$clang = new limesurvey_lang("en");
ob_implicit_flush(true);
if ($databasetype=='mysql') {@$connect->Execute("ALTER DATABASE `$dbname` DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;");} //Set the collation also for manually created DBs
if (modify_database(dirname(__FILE__).'/create-'.$databasetype.'.sql'))
{
print("Creating $dbname on $databasetype\n");
return 0;
} else {
print("Could not create $dbname on $databasetype\n");
return 1;
}
?>

View File

@@ -1,41 +0,0 @@
<?php
/*
* LimeSurvey
* Copyright (C) 2007 The LimeSurvey Project Team / Nicolas Barcet
* 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: index.php 4729 2008-05-31 21:32:02Z nijaba $
*/
require_once(dirname(__FILE__).'/../../config-defaults.php');
require_once(dirname(__FILE__).'/../../common.php');
// SET THE LANGUAGE???? -> DEFAULT SET TO EN FOR NOW
require_once($rootdir.'/classes/core/language.php');
$clang = new limesurvey_lang("en");
ob_implicit_flush(true);
global $connect, $databasetype, $dbprefix, $dbversionnumber, $clang;
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)
{
print("Upgrading db to $dbversionnumber\n");
db_upgrade(intval($usrow['stg_value']));
} else {
print("Already at db version $dbversionnumber\n");
}
return 0;
?>

View File

@@ -10,7 +10,7 @@
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*
* $Id: index.php 4346 2008-02-25 21:32:02Z c_schmitz $
* $Id: index.php 6952 2009-05-27 09:40:07Z c_schmitz $
*/
@@ -60,7 +60,7 @@ else
$connect->database = $databasename;
$connect->Execute("USE DATABASE `$databasename`");
$output=checkforupgrades();
if (!isset($ouput)) {$adminoutput.='<br />LimeSurvey Database is up to date. No action needed';}
if ($output== '') {$adminoutput.='<br />LimeSurvey Database is up to date. No action needed';}
else {$adminoutput.=$output;}
$adminoutput.="<br />Please <a href='$homeurl/$scriptname'>log in.</a>";
@@ -73,7 +73,10 @@ function checkforupgrades()
{
global $connect, $databasetype, $dbprefix, $dbversionnumber, $clang;
$adminoutput='';
include ('upgrade-'.$databasetype.'.php');
$upgradedbtype=$databasetype;
if ($upgradedbtype=='mssql_n' || $upgradedbtype=='odbc_mssql' || $upgradedbtype=='odbtp') $upgradedbtype='mssql';
if ($upgradedbtype=='mysqli') $upgradedbtype='mysql';
include ('upgrade-'.$upgradedbtype.'.php');
$tables = $connect->MetaTables();
$usquery = "SELECT stg_value FROM ".db_table_name("settings_global")." where stg_name='DBVersion'";

View File

@@ -22,14 +22,17 @@ sendcacheheaders();
switch ($databasetype)
{
case 'mysql': modify_database("",'UPDATE `prefix_users` set password=\'$defaultpass\' where uid=1;');
echo $modifyoutput; flush();
break;
case 'odbc_mssql':modify_database("",'UPDATE [prefix_users] set password=\'$defaultpass\' where uid=1;');
echo $modifyoutput; flush();
break;
case 'postgres':modify_database("",'UPDATE prefix_users set \"password\"=\'$defaultpass\' where uid=1;');
echo $modifyoutput; flush();
break;
case 'mysqli':
case 'mysql' : modify_database("",'UPDATE `prefix_users` set password=\'$defaultpass\' where uid=1;');
echo $modifyoutput; flush();
break;
case 'odbtp':
case 'mssql_n':
case 'odbc_mssql':modify_database("",'UPDATE [prefix_users] set password=\'$defaultpass\' where uid=1;');
echo $modifyoutput; flush();
break;
case 'postgres':modify_database("",'UPDATE prefix_users set \"password\"=\'$defaultpass\' where uid=1;');
echo $modifyoutput; flush();
break;
}
?>

View File

@@ -0,0 +1,445 @@
<?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: upgrade-mssql.php 7122 2009-06-16 13:42:29Z c_schmitz $
*/
// 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, $dbprefix;
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;
}
if ($oldversion < 112) {
//The size of the users_name field is now 64 char (20 char before version 112)
modify_database("","ALTER TABLE [prefix_users] ALTER COLUMN [users_name] VARCHAR( 64 ) NOT NULL"); echo $modifyoutput; flush();
modify_database("","update [prefix_settings_global] set [stg_value]='112' where stg_name='DBVersion'"); echo $modifyoutput; flush();
}
if ($oldversion < 113) {
//No action needed
modify_database("","update [prefix_settings_global] set [stg_value]='113' where stg_name='DBVersion'"); echo $modifyoutput; flush();
}
if ($oldversion < 114) {
modify_database("","ALTER TABLE [prefix_saved_control] ALTER COLUMN [email] VARCHAR(320) NOT NULL"); echo $modifyoutput; flush();
modify_database("","ALTER TABLE [prefix_surveys] ALTER COLUMN [adminemail] VARCHAR(320) NOT NULL"); echo $modifyoutput; flush();
modify_database("","ALTER TABLE [prefix_users] ALTER COLUMN [email] VARCHAR(320) NOT NULL"); echo $modifyoutput; flush();
modify_database("",'INSERT INTO [prefix_settings_global] VALUES (\'SessionName\', \'$sessionname\');');echo $modifyoutput; flush();
modify_database("","update [prefix_settings_global] set [stg_value]='114' where stg_name='DBVersion'"); echo $modifyoutput; flush();
}
if ($oldversion < 126) {
modify_database("","ALTER TABLE [prefix_surveys] ADD [printanswers] CHAR(1) DEFAULT 'N'"); echo $modifyoutput; flush();
modify_database("","ALTER TABLE [prefix_surveys] ADD [listpublic] CHAR(1) DEFAULT 'N'"); echo $modifyoutput; flush();
upgrade_survey_tables117();
upgrade_survey_tables118();
//119
modify_database("","CREATE TABLE [prefix_quota] (
[id] int NOT NULL IDENTITY (1,1),
[sid] int,
[name] varchar(255) ,
[qlimit] int ,
[action] int ,
[active] int NOT NULL default '1',
PRIMARY KEY ([id])
);");echo $modifyoutput; flush();
modify_database("","CREATE TABLE [prefix_quota_members] (
[id] int NOT NULL IDENTITY (1,1),
[sid] int ,
[qid] int ,
[quota_id] int ,
[code] varchar(5) ,
PRIMARY KEY ([id])
);");echo $modifyoutput; flush();
// Rename Norwegian language code from NO to NB
$oldnewlanguages=array('no'=>'nb');
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'];
$toreplace2=str_replace('no','nb',$toreplace);
if ($toreplace2!=$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'];
$toreplace2=str_replace('no','nb',$toreplace);
if ($toreplace2!=$toreplace) {modify_database("","update [prefix_surveys] set [additional_languages]='$toreplace' where sid=".$datarow['sid']);echo $modifyoutput;flush();}
}
modify_database("","ALTER TABLE [prefix_surveys] ADD [htmlemail] CHAR(1) DEFAULT 'N'"); echo $modifyoutput; flush();
modify_database("","ALTER TABLE [prefix_surveys] ADD [usecaptcha] CHAR(1) DEFAULT 'N'"); echo $modifyoutput; flush();
modify_database("","ALTER TABLE [prefix_surveys] ADD [tokenanswerspersistence] CHAR(1) DEFAULT 'N'"); echo $modifyoutput; flush();
modify_database("","ALTER TABLE [prefix_users] ADD [htmleditormode] CHAR(7) DEFAULT 'default'"); echo $modifyoutput; flush();
modify_database("","CREATE TABLE [prefix_templates_rights] (
[uid] int NOT NULL,
[folder] varchar(255) NOT NULL,
[use] int NOT NULL,
PRIMARY KEY ([uid],[folder])
);");echo $modifyoutput; flush();
modify_database("","CREATE TABLE [prefix_templates] (
[folder] varchar(255) NOT NULL,
[creator] int NOT NULL,
PRIMARY KEY ([folder])
);");echo $modifyoutput; flush();
//123
modify_database("","ALTER TABLE [prefix_conditions] ALTER COLUMN [value] VARCHAR(255)"); echo $modifyoutput; flush();
// There is no other way to remove the previous default value
/*modify_database("","DECLARE @STR VARCHAR(100)
SET @STR = (
SELECT NAME
FROM SYSOBJECTS SO
JOIN SYSCONSTRAINTS SC ON SO.ID = SC.CONSTID
WHERE OBJECT_NAME(SO.PARENT_OBJ) = 'lime_labels'
AND SO.XTYPE = 'D' AND SC.COLID =
(SELECT COLID FROM SYSCOLUMNS WHERE ID = OBJECT_ID('lime_labels') AND NAME = 'title'))
SET @STR = 'ALTER TABLE lime_labels DROP CONSTRAINT ' + @STR
exec (@STR);"); echo $modifyoutput; flush(); */
modify_database("","ALTER TABLE [prefix_labels] ALTER COLUMN [title] varchar(4000)"); echo $modifyoutput; flush();
//124
modify_database("","ALTER TABLE [prefix_surveys] ADD [bounce_email] text"); echo $modifyoutput; flush();
//125
upgrade_token_tables125();
modify_database("","EXEC sp_rename 'prefix_users.move_user','superadmin'"); echo $modifyoutput; flush();
modify_database("","UPDATE [prefix_users] SET [superadmin]=1 where ([create_survey]=1 AND [create_user]=1 AND [delete_user]=1 AND [configurator]=1)"); echo $modifyoutput; flush();
//126
modify_database("","ALTER TABLE [prefix_questions] ADD [lid1] int NOT NULL DEFAULT '0'"); echo $modifyoutput; flush();
modify_database("","UPDATE [prefix_conditions] SET [method]='==' where ( [method] is null) or [method]='' or [method]='0'"); echo $modifyoutput; flush();
modify_database("","update [prefix_settings_global] set [stg_value]='126' where stg_name='DBVersion'"); echo $modifyoutput; flush();
}
if ($oldversion < 127) {
modify_database("","create index [answers_idx2] on [prefix_answers] ([sortorder])"); echo $modifyoutput;
modify_database("","create index [assessments_idx2] on [prefix_assessments] ([sid])"); echo $modifyoutput;
modify_database("","create index [assessments_idx3] on [prefix_assessments] ([gid])"); echo $modifyoutput;
modify_database("","create index [conditions_idx2] on [prefix_conditions] ([qid])"); echo $modifyoutput;
modify_database("","create index [conditions_idx3] on [prefix_conditions] ([cqid])"); echo $modifyoutput;
modify_database("","create index [groups_idx2] on [prefix_groups] ([sid])"); echo $modifyoutput;
modify_database("","create index [question_attributes_idx2] on [prefix_question_attributes] ([qid])"); echo $modifyoutput;
modify_database("","create index [questions_idx2] on [prefix_questions] ([sid])"); echo $modifyoutput;
modify_database("","create index [questions_idx3] on [prefix_questions] ([gid])"); echo $modifyoutput;
modify_database("","create index [questions_idx4] on [prefix_questions] ([type])"); echo $modifyoutput;
modify_database("","create index [quota_idx2] on [prefix_quota] ([sid])"); echo $modifyoutput;
modify_database("","create index [saved_control_idx2] on [prefix_saved_control] ([sid])"); echo $modifyoutput;
modify_database("","create index [user_in_groups_idx1] on [prefix_user_in_groups] ([ugid], [uid])"); echo $modifyoutput;
modify_database("","update [prefix_settings_global] set [stg_value]='127' where stg_name='DBVersion'"); echo $modifyoutput; flush();
}
if ($oldversion < 128) {
upgrade_token_tables128();
modify_database("","update [prefix_settings_global] set [stg_value]='128' where stg_name='DBVersion'"); echo $modifyoutput; flush();
}
if ($oldversion < 129) {
//128
modify_database("","ALTER TABLE [prefix_surveys] ADD [startdate] DATETIME"); echo $modifyoutput; flush();
modify_database("","ALTER TABLE [prefix_surveys] ADD [usestartdate] char(1) NOT NULL default 'N'"); echo $modifyoutput; flush();
modify_database("","update [prefix_settings_global] set [stg_value]='129' where stg_name='DBVersion'"); echo $modifyoutput; flush();
}
if ($oldversion < 130)
{
modify_database("","ALTER TABLE [prefix_conditions] ADD [scenario] int NOT NULL DEFAULT '1'"); echo $modifyoutput; flush();
modify_database("","UPDATE [prefix_conditions] SET [scenario]=1 where ( [scenario] is null) or [scenario]='' or [scenario]=0"); echo $modifyoutput; flush();
modify_database("","update [prefix_settings_global] set [stg_value]='130' where stg_name='DBVersion'"); echo $modifyoutput; flush();
}
if ($oldversion < 131)
{
modify_database("","ALTER TABLE [prefix_surveys] ADD [publicstatistics] char(1) NOT NULL default 'N'"); echo $modifyoutput; flush();
modify_database("","update [prefix_settings_global] set [stg_value]='131' where stg_name='DBVersion'"); echo $modifyoutput; flush();
}
if ($oldversion < 132)
{
modify_database("","ALTER TABLE [prefix_surveys] ADD [publicgraphs] char(1) NOT NULL default 'N'"); echo $modifyoutput; flush();
modify_database("","update [prefix_settings_global] set [stg_value]='132' where stg_name='DBVersion'"); echo $modifyoutput; flush();
}
if ($oldversion < 133)
{
modify_database("","ALTER TABLE [prefix_users] ADD [one_time_pw] text"); echo $modifyoutput; flush();
// Add new assessment setting
modify_database("","ALTER TABLE [prefix_surveys] ADD [assessments] char(1) NOT NULL default 'N'"); echo $modifyoutput; flush();
// add new assessment value fields to answers & labels
modify_database("","ALTER TABLE [prefix_answers] ADD [assessment_value] int NOT NULL default '0'"); echo $modifyoutput; flush();
modify_database("","ALTER TABLE [prefix_labels] ADD [assessment_value] int NOT NULL default '0'"); echo $modifyoutput; flush();
// copy any valid codes from code field to assessment field
modify_database("","update [prefix_answers] set [assessment_value]=CAST([code] as int)");// no output here is intended
modify_database("","update [prefix_labels] set [assessment_value]=CAST([code] as int)");// no output here is intended
// activate assessment where assesment rules exist
modify_database("","update [prefix_surveys] set [assessments]='Y' where [sid] in (SELECT [sid] FROM [prefix_assessments] group by [sid])"); echo $modifyoutput; flush();
// add language field to assessment table
modify_database("","ALTER TABLE [prefix_assessments] ADD [language] varchar(20) NOT NULL default 'en'"); echo $modifyoutput; flush();
// update language field with default language of that particular survey
modify_database("","update [prefix_assessments] set [language]=(select [language] from [prefix_surveys] where [sid]=[prefix_assessments].[sid])"); echo $modifyoutput; flush();
// copy assessment link to message since from now on we will have HTML assignment messages
modify_database("","update [prefix_assessments] set [message]=cast([message] as varchar) +'<br /><a href=\"'+[link]+'\">'+[link]+'</a>'"); echo $modifyoutput; flush();
// drop the old link field
modify_database("","ALTER TABLE [prefix_assessments] DROP COLUMN [link]"); echo $modifyoutput; flush();
// change the primary index to include language
// and fix missing translations for assessments
upgrade_survey_tables133a();
// Add new fields to survey language settings
modify_database("","ALTER TABLE [prefix_surveys_languagesettings] ADD [surveyls_url] varchar(255)"); echo $modifyoutput; flush();
modify_database("","ALTER TABLE [prefix_surveys_languagesettings] ADD [surveyls_endtext] text"); echo $modifyoutput; flush();
// copy old URL fields ot language specific entries
modify_database("","update [prefix_surveys_languagesettings] set [surveyls_url]=(select [url] from [prefix_surveys] where [sid]=[prefix_surveys_languagesettings].[surveyls_survey_id])"); echo $modifyoutput; flush();
// drop old URL field
mssql_drop_constraint('url','surveys');
modify_database("","ALTER TABLE [prefix_surveys] DROP COLUMN [url]"); echo $modifyoutput; flush();
modify_database("","update [prefix_settings_global] set [stg_value]='133' where stg_name='DBVersion'"); echo $modifyoutput; flush();
}
if ($oldversion < 134)
{
// Add new assessment setting
modify_database("","ALTER TABLE [prefix_surveys] ADD [usetokens] char(1) NOT NULL default 'N'"); echo $modifyoutput; flush();
mssql_drop_constraint('attribute1','surveys');
mssql_drop_constraint('attribute2','surveys');
modify_database("", "ALTER TABLE [prefix_surveys] ADD [attributedescriptions] TEXT;"); echo $modifyoutput; flush();
modify_database("","ALTER TABLE [prefix_surveys] DROP COLUMN [attribute1]"); echo $modifyoutput; flush();
modify_database("","ALTER TABLE [prefix_surveys] DROP COLUMN [attribute2]"); echo $modifyoutput; flush();
upgrade_token_tables134();
modify_database("","update [prefix_settings_global] set [stg_value]='134' where stg_name='DBVersion'"); echo $modifyoutput; flush();
}
if ($oldversion < 135)
{
mssql_drop_constraint('value','question_attributes');
modify_database("","ALTER TABLE [prefix_question_attributes] ALTER COLUMN [value] text"); echo $modifyoutput; flush();
modify_database("","ALTER TABLE [prefix_answers] ALTER COLUMN [answer] varchar(8000)"); echo $modifyoutput; flush();
modify_database("","update [prefix_settings_global] set [stg_value]='135' where stg_name='DBVersion'"); echo $modifyoutput; flush();
}
if ($oldversion < 136) //New quota functions
{
modify_database("", "ALTER TABLE[prefix_quota] ADD [autoload_url] int NOT NULL default '0'"); echo $modifyoutput; flush();
modify_database("","CREATE TABLE [prefix_quota_languagesettings] (
[quotals_id] int NOT NULL IDENTITY (1,1),
[quotals_quota_id] int,
[quotals_language] varchar(45) NOT NULL default 'en',
[quotals_name] varchar(255),
[quotals_message] text,
[quotals_url] varchar(255),
[quotals_urldescrip] varchar(255),
PRIMARY KEY ([quotals_id])
);");echo $modifyoutput; flush();
modify_database("","update [prefix_settings_global] set [stg_value]='136' where stg_name='DBVersion'"); echo $modifyoutput; flush();
}
if ($oldversion < 137) //New date format specs
{
modify_database("", "ALTER TABLE [prefix_surveys_languagesettings] ADD [surveyls_dateformat] int NOT NULL default '1'"); echo $modifyoutput; flush();
modify_database("", "ALTER TABLE [prefix_users] ADD [dateformat] int NOT NULL default '1'"); echo $modifyoutput; flush();
modify_database("", "update [prefix_surveys] set startdate=null where usestartdate='N'"); echo $modifyoutput; flush();
modify_database("", "update [prefix_surveys] set expires=null where useexpiry='N'"); echo $modifyoutput; flush();
mssql_drop_constraint('usestartdate','surveys');
mssql_drop_constraint('useexpiry','surveys');
modify_database("", "ALTER TABLE [prefix_surveys] DROP COLUMN usestartdate"); echo $modifyoutput; flush();
modify_database("", "ALTER TABLE [prefix_surveys] DROP COLUMN useexpiry"); echo $modifyoutput; flush();
modify_database("","update [prefix_settings_global] set [stg_value]='137' where stg_name='DBVersion'"); echo $modifyoutput; flush();
}
if ($oldversion < 138) //Modify quota field
{
modify_database("", "ALTER TABLE [prefix_quota_members] ALTER COLUMN [code] VARCHAR(11) NULL"); echo $modifyoutput; flush();
modify_database("", "UPDATE [prefix_settings_global] SET [stg_value]='138' WHERE stg_name='DBVersion'"); echo $modifyoutput; flush();
}
return true;
}
function upgrade_survey_tables117()
{
global $modifyoutput;
$surveyidquery = "SELECT sid FROM ".db_table_name('surveys')." WHERE active='Y' and datestamp='Y'";
$surveyidresult = db_execute_num($surveyidquery);
if (!$surveyidresult) {return "Database Error";}
else
{
while ( $sv = $surveyidresult->FetchRow() )
{
modify_database("","ALTER TABLE ".db_table_name('survey_'.$sv[0])." ADD [startdate] datetime"); echo $modifyoutput; flush();
}
}
}
function upgrade_survey_tables118()
{
global $connect,$modifyoutput,$dbprefix;
$tokentables=$connect->MetaTables('TABLES',false,$dbprefix."tokens%");
foreach ($tokentables as $sv)
{
modify_database("","ALTER TABLE ".$sv." ALTER COLUMN [token] VARCHAR(36)"); echo $modifyoutput; flush();
}
}
function upgrade_token_tables125()
{
global $connect,$modifyoutput,$dbprefix;
$tokentables=$connect->MetaTables('TABLES',false,$dbprefix."tokens%");
foreach ($tokentables as $sv)
{
modify_database("","ALTER TABLE ".$sv." ADD [emailstatus] VARCHAR(300) DEFAULT 'OK'"); echo $modifyoutput; flush();
}
}
function upgrade_token_tables128()
{
global $connect,$modifyoutput,$dbprefix;
$tokentables=$connect->MetaTables('TABLES',false,$dbprefix."tokens%");
foreach ($tokentables as $sv)
{
modify_database("","ALTER TABLE ".$sv." ADD [remindersent] VARCHAR(17) DEFAULT 'OK'"); echo $modifyoutput; flush();
modify_database("","ALTER TABLE ".$sv." ADD [remindercount] int DEFAULT '0'"); echo $modifyoutput; flush();
}
}
function upgrade_survey_tables133a()
{
global $dbprefix, $connect, $modifyoutput;
// find out the constraint name of the old primary key
$pkquery = " SELECT CONSTRAINT_NAME "
."FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS "
."WHERE (TABLE_NAME = '{$dbprefix}assessments') AND (CONSTRAINT_TYPE = 'PRIMARY KEY')";
$primarykey=$connect->GetRow($pkquery);
if ($primarykey!=false)
{
modify_database("","ALTER TABLE [prefix_assessments] DROP CONSTRAINT {$primarykey[0]}"); echo $modifyoutput; flush();
}
// add the new primary key
modify_database("","ALTER TABLE [prefix_assessments] ADD CONSTRAINT pk_assessments_id_lang PRIMARY KEY ([id],[language])"); echo $modifyoutput; flush();
$surveyidquery = "SELECT sid,additional_languages FROM ".db_table_name('surveys');
$surveyidresult = db_execute_num($surveyidquery);
while ( $sv = $surveyidresult->FetchRow() )
{
FixLanguageConsistency($sv[0],$sv[1]);
}
}
function upgrade_token_tables134()
{
global $connect,$modifyoutput,$dbprefix;
$tokentables=$connect->MetaTables('TABLES',false,$dbprefix."tokens%");
foreach ($tokentables as $sv)
{
modify_database("","ALTER TABLE ".$sv." ADD [validfrom] DATETIME"); echo $modifyoutput; flush();
modify_database("","ALTER TABLE ".$sv." ADD [validuntil] DATETIME"); echo $modifyoutput; flush();
}
}
function mssql_drop_constraint($fieldname, $tablename)
{
global $dbprefix, $connect, $modifyoutput;
// find out the name of the default constraint
// Did I already mention that this is the most suckiest thing I have ever seen in MSSQL database?
// It proves how badly designer some Microsoft software is!
$dfquery ="SELECT c_obj.name AS constraint_name
FROM sys.sysobjects AS c_obj INNER JOIN
sys.sysobjects AS t_obj ON c_obj.parent_obj = t_obj.id INNER JOIN
sys.sysconstraints AS con ON c_obj.id = con.constid INNER JOIN
sys.syscolumns AS col ON t_obj.id = col.id AND con.colid = col.colid
WHERE (c_obj.xtype = 'D') AND (col.name = '$fieldname') AND (t_obj.name='$dbprefix$tablename')";
$defaultname=$connect->GetRow($dfquery);
if ($defaultname!=false)
{
modify_database("","ALTER TABLE [prefix_$tablename] DROP CONSTRAINT {$defaultname[0]}"); echo $modifyoutput; flush();
}
}
?>

View File

@@ -10,7 +10,7 @@
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*
* $Id: upgrade-mysql.php 4467 2008-03-16 21:19:53Z c_schmitz $
* $Id: upgrade-mysql.php 7108 2009-06-15 05:43:21Z jcleeland $
*/
// There will be a file for each database (accordingly named to the dbADO scheme)
@@ -115,12 +115,12 @@ echo str_pad('Loading... ',4096)."<br />\n";
modify_database("","CREATE TABLE `prefix_quota` (
`id` int(11) NOT NULL auto_increment,
`sid` int(11) default NULL,
`name` varchar(255) collate utf8_unicode_ci default NULL,
`qlimit` int(8) default NULL,
`name` varchar(255) collate utf8_unicode_ci default NULL,
`action` int(2) default NULL,
`active` int(1) NOT NULL default '1',
PRIMARY KEY (`id`)
) TYPE=$databasetabletype CHARACTER SET utf8 COLLATE utf8_unicode_ci;"); echo $modifyoutput; flush();
) ENGINE=$databasetabletype CHARACTER SET utf8 COLLATE utf8_unicode_ci;"); echo $modifyoutput; flush();
modify_database("","CREATE TABLE `prefix_quota_members` (
`id` int(11) NOT NULL auto_increment,
`sid` int(11) default NULL,
@@ -129,7 +129,7 @@ echo str_pad('Loading... ',4096)."<br />\n";
`code` varchar(5) collate utf8_unicode_ci default NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `sid` (`sid`,`qid`,`quota_id`,`code`)
) TYPE=$databasetabletype CHARACTER SET utf8 COLLATE utf8_unicode_ci;"); echo $modifyoutput; flush();
) ENGINE=$databasetabletype CHARACTER SET utf8 COLLATE utf8_unicode_ci;"); echo $modifyoutput; flush();
// Rename Norwegian language code from NO to NB
$oldnewlanguages=array('no'=>'nb');
@@ -169,12 +169,12 @@ echo str_pad('Loading... ',4096)."<br />\n";
`folder` varchar(255) NOT NULL,
`use` int(1) NOT NULL,
PRIMARY KEY (`uid`,`folder`)
) TYPE=$databasetabletype CHARACTER SET utf8 COLLATE utf8_unicode_ci;"); echo $modifyoutput; flush();
) ENGINE=$databasetabletype CHARACTER SET utf8 COLLATE utf8_unicode_ci;"); echo $modifyoutput; flush();
modify_database("","CREATE TABLE `prefix_templates` (
`folder` varchar(255) NOT NULL,
`creator` int(11) NOT NULL,
PRIMARY KEY (`folder`)
) TYPE=$databasetabletype CHARACTER SET utf8 COLLATE utf8_unicode_ci;"); echo $modifyoutput; flush();
) ENGINE=$databasetabletype CHARACTER SET utf8 COLLATE utf8_unicode_ci;"); echo $modifyoutput; flush();
//123
modify_database("","ALTER TABLE `prefix_conditions` CHANGE `value` `value` VARCHAR(255) NOT NULL default ''"); echo $modifyoutput; flush();
@@ -188,16 +188,140 @@ echo str_pad('Loading... ',4096)."<br />\n";
modify_database("","ALTER TABLE `prefix_users` DROP COLUMN `move_user`"); echo $modifyoutput; flush();
//126
modify_database("","ALTER TABLE `prefix_questions` ADD `lid1` integer NOT NULL default '0'"); echo $modifyoutput; flush();
modify_database("","UPDATE `prefix_conditions` SET `method`='==' where (`method` is null) or `method`=''"); echo $modifyoutput; flush();
modify_database("","UPDATE `prefix_conditions` SET `method`='==' where (`method` is null) or `method`='' or `method`='0'"); echo $modifyoutput; flush();
modify_database("","update `prefix_settings_global` set `stg_value`='126' where stg_name='DBVersion'"); echo $modifyoutput; flush();
}
if ($oldversion < 127) {
modify_database("","create index `assessments_idx2` on `prefix_assessments` (`sid`)"); echo $modifyoutput; flush();
modify_database("","create index `assessments_idx3` on `prefix_assessments` (`gid`)"); echo $modifyoutput; flush();
modify_database("","create index `conditions_idx2` on `prefix_conditions` (`qid`)"); echo $modifyoutput; flush();
modify_database("","create index `groups_idx2` on `prefix_groups` (`sid`)"); echo $modifyoutput; flush();
modify_database("","create index `questions_idx2` on `prefix_questions` (`sid`)"); echo $modifyoutput; flush();
modify_database("","create index `questions_idx3` on `prefix_questions` (`gid`)"); echo $modifyoutput; flush();
modify_database("","create index `question_attributes_idx2` on `prefix_question_attributes` (`qid`)"); echo $modifyoutput; flush();
modify_database("","create index `quota_idx2` on `prefix_quota` (`sid`)"); echo $modifyoutput; flush();
modify_database("","create index `saved_control_idx2` on `prefix_saved_control` (`sid`)"); echo $modifyoutput; flush();
modify_database("","create index `user_in_groups_idx1` on `prefix_user_in_groups` (`ugid`, `uid`)"); echo $modifyoutput; flush();
modify_database("","create index `answers_idx2` on `prefix_answers` (`sortorder`)"); echo $modifyoutput; flush();
modify_database("","create index `conditions_idx3` on `prefix_conditions` (`cqid`)"); echo $modifyoutput; flush();
modify_database("","create index `questions_idx4` on `prefix_questions` (`type`)"); echo $modifyoutput; flush();
modify_database("","update `prefix_settings_global` set `stg_value`='127' where stg_name='DBVersion'"); echo $modifyoutput; flush();
}
if ($oldversion < 128) {
//128
upgrade_token_tables128();
modify_database("","update `prefix_settings_global` set `stg_value`='128' where stg_name='DBVersion'"); echo $modifyoutput; flush();
}
if ($oldversion < 129) {
//129
modify_database("","ALTER TABLE `prefix_surveys` ADD `startdate` DATETIME"); echo $modifyoutput; flush();
modify_database("","ALTER TABLE `prefix_surveys` ADD `usestartdate` varchar(1) NOT NULL default 'N'"); echo $modifyoutput; flush();
modify_database("","update `prefix_settings_global` set `stg_value`='129' where stg_name='DBVersion'"); echo $modifyoutput; flush();
}
if ($oldversion < 130)
{
modify_database("","ALTER TABLE `prefix_conditions` ADD `scenario` integer NOT NULL default '1' AFTER `qid`"); echo $modifyoutput; flush();
modify_database("","UPDATE `prefix_conditions` SET `scenario`=1 where (`scenario` is null) or `scenario`='' or `scenario`=0"); echo $modifyoutput; flush();
modify_database("","update `prefix_settings_global` set `stg_value`='130' where stg_name='DBVersion'"); echo $modifyoutput; flush();
}
if ($oldversion < 131)
{
modify_database("","ALTER TABLE `prefix_surveys` ADD `publicstatistics` varchar(1) NOT NULL default 'N'"); echo $modifyoutput; flush();
modify_database("","update `prefix_settings_global` set `stg_value`='131' where stg_name='DBVersion'"); echo $modifyoutput; flush();
}
if ($oldversion < 132)
{
modify_database("","ALTER TABLE `prefix_surveys` ADD `publicgraphs` varchar(1) NOT NULL default 'N'"); echo $modifyoutput; flush();
modify_database("","update `prefix_settings_global` set `stg_value`='132' where stg_name='DBVersion'"); echo $modifyoutput; flush();
}
if ($oldversion < 133)
{
modify_database("","ALTER TABLE `prefix_users` ADD `one_time_pw` blob"); echo $modifyoutput; flush();
// Add new assessment setting
modify_database("","ALTER TABLE `prefix_surveys` ADD `assessments` varchar(1) NOT NULL default 'N'"); echo $modifyoutput; flush();
// add new assessment value fields to answers & labels
modify_database("","ALTER TABLE `prefix_answers` ADD `assessment_value` int(11) NOT NULL default '0'"); echo $modifyoutput; flush();
modify_database("","ALTER TABLE `prefix_labels` ADD `assessment_value` int(11) NOT NULL default '0'"); echo $modifyoutput; flush();
// copy any valid codes from code field to assessment field
modify_database("","update `prefix_answers` set `assessment_value`=CAST(`code` as SIGNED) where `code` REGEXP '^-?[0-9]+$'");echo $modifyoutput; flush();
modify_database("","update `prefix_labels` set `assessment_value`=CAST(`code` as SIGNED) where `code` REGEXP '^-?[0-9]+$'");echo $modifyoutput; flush();
// activate assessment where assesment rules exist
modify_database("","update `prefix_surveys` set `assessments`='Y' where `sid` in (SELECT `sid` FROM `prefix_assessments` group by `sid`)"); echo $modifyoutput; flush();
// add language field to assessment table
modify_database("","ALTER TABLE `prefix_assessments` ADD `language` varchar(20) NOT NULL default 'en'"); echo $modifyoutput; flush();
// update language field with default language of that particular survey
modify_database("","update `prefix_assessments` set `language`=(select `language` from `prefix_surveys` where `sid`=`prefix_assessments`.`sid`)"); echo $modifyoutput; flush();
// copy assessment link to message since from now on we will have HTML assignment messages
modify_database("","update `prefix_assessments` set `message`=concat(replace(`message`,'/''',''''),'<br /><a href=\"',`link`,'\">',`link`,'</a>')"); echo $modifyoutput; flush();
// drop the old link field
modify_database("","ALTER TABLE `prefix_assessments` DROP COLUMN `link`"); echo $modifyoutput; flush();
// change the primary index to include language
modify_database("","ALTER TABLE `prefix_assessments` DROP PRIMARY KEY, ADD PRIMARY KEY USING BTREE(`id`, `language`)"); echo $modifyoutput; flush();
//finally fix missing translations for assessments
upgrade_survey_tables133();
// Add new fields to survey language settings
modify_database("","ALTER TABLE `prefix_surveys_languagesettings` ADD `surveyls_url` varchar(255)"); echo $modifyoutput; flush();
modify_database("","ALTER TABLE `prefix_surveys_languagesettings` ADD `surveyls_endtext` text"); echo $modifyoutput; flush();
// copy old URL fields ot language specific entries
modify_database("","update `prefix_surveys_languagesettings` set `surveyls_url`=(select `url` from `prefix_surveys` where `sid`=`prefix_surveys_languagesettings`.`surveyls_survey_id`)"); echo $modifyoutput; flush();
// drop old URL field
modify_database("","ALTER TABLE `prefix_surveys` DROP COLUMN `url`"); echo $modifyoutput; flush();
modify_database("","update `prefix_settings_global` set `stg_value`='133' where stg_name='DBVersion'"); echo $modifyoutput; flush();
}
if ($oldversion < 134)
{
// Add new tokens setting
modify_database("","ALTER TABLE `prefix_surveys` ADD `usetokens` varchar(1) NOT NULL default 'N'"); echo $modifyoutput; flush();
modify_database("","ALTER TABLE `prefix_surveys` ADD `attributedescriptions` TEXT;"); echo $modifyoutput; flush();
modify_database("","ALTER TABLE `prefix_surveys` DROP COLUMN `attribute1`"); echo $modifyoutput; flush();
modify_database("","ALTER TABLE `prefix_surveys` DROP COLUMN `attribute2`"); echo $modifyoutput; flush();
upgrade_token_tables134();
modify_database("","update `prefix_settings_global` set `stg_value`='134' where stg_name='DBVersion'"); echo $modifyoutput; flush();
}
if ($oldversion < 135)
{
modify_database("","ALTER TABLE `prefix_question_attributes` MODIFY `value` text"); echo $modifyoutput; flush();
modify_database("","UPDATE `prefix_settings_global` SET `stg_value`='135' WHERE stg_name='DBVersion'"); echo $modifyoutput; flush();
}
if ($oldversion < 136) //New Quota Functions
{
modify_database("","ALTER TABLE `prefix_quota` ADD `autoload_url` int(1) NOT NULL default '0'"); echo $modifyoutput; flush();
modify_database("","CREATE TABLE `prefix_quota_languagesettings` (
`quotals_id` int(11) NOT NULL auto_increment,
`quotals_quota_id` int(11) NOT NULL default '0',
`quotals_language` varchar(45) NOT NULL default 'en',
`quotals_name` varchar(255) collate utf8_unicode_ci default NULL,
`quotals_message` text NOT NULL,
`quotals_url` varchar(255),
`quotals_urldescrip` varchar(255),
PRIMARY KEY (`quotals_id`)
) ENGINE=$databasetabletype CHARACTER SET utf8 COLLATE utf8_unicode_ci;"); echo $modifyoutput; flush();
modify_database("","UPDATE `prefix_settings_global` SET `stg_value`='136' WHERE stg_name='DBVersion'"); echo $modifyoutput; flush();
}
if ($oldversion < 137) //New Quota Functions
{
modify_database("", "ALTER TABLE `prefix_surveys_languagesettings` ADD `surveyls_dateformat` int(1) NOT NULL default '1'"); echo $modifyoutput; flush();
modify_database("", "ALTER TABLE `prefix_users` ADD `dateformat` int(1) NOT NULL default '1'"); echo $modifyoutput; flush();
modify_database("", "UPDATE `prefix_surveys` set `startdate`=null where `usestartdate`='N'"); echo $modifyoutput; flush();
modify_database("", "UPDATE `prefix_surveys` set `expires`=null where `useexpiry`='N'"); echo $modifyoutput; flush();
modify_database("", "ALTER TABLE `prefix_surveys` DROP COLUMN `useexpiry`"); echo $modifyoutput; flush();
modify_database("", "ALTER TABLE `prefix_surveys` DROP COLUMN `usestartdate`"); echo $modifyoutput; flush();
modify_database("", "UPDATE `prefix_settings_global` SET `stg_value`='137' WHERE stg_name='DBVersion'"); echo $modifyoutput; flush();
}
if ($oldversion < 138) //Modify quota field
{
modify_database("", "ALTER TABLE `prefix_quota_members` CHANGE `code` `code` VARCHAR(11) collate utf8_unicode_ci default NULL"); echo $modifyoutput; flush();
modify_database("", "UPDATE `prefix_settings_global` SET `stg_value`='138' WHERE stg_name='DBVersion'"); echo $modifyoutput; flush();
}
return true;
}
function upgrade_survey_tables117()
{
global $modifyoutput;
@@ -205,12 +329,12 @@ function upgrade_survey_tables117()
$surveyidresult = db_execute_num($surveyidquery);
if (!$surveyidresult) {return "Database Error";}
else
{
{
while ( $sv = $surveyidresult->FetchRow() )
{
{
modify_database("","ALTER TABLE ".db_table_name('survey_'.$sv[0])." ADD `startdate` datetime AFTER `datestamp`"); echo $modifyoutput; flush();
}
}
}
}
function upgrade_survey_tables118()
@@ -238,61 +362,105 @@ function upgrade_token_tables125()
{
while ( $sv = $surveyidresult->FetchRow() )
{
modify_database("","ALTER TABLE ".$sv[0]." ADD `emailstatus` varchar(255) NOT NULL DEFAULT 'OK'"); echo $modifyoutput; flush();
modify_database("","ALTER TABLE ".$sv[0]." ADD `emailstatus` varchar(300) NOT NULL DEFAULT 'OK'"); echo $modifyoutput; flush();
}
}
}
// Add the reminders tracking fields
function upgrade_token_tables128()
{
global $modifyoutput,$dbprefix;
$surveyidquery = "SHOW TABLES LIKE '".$dbprefix."tokens%'";
$surveyidresult = db_execute_num($surveyidquery);
if (!$surveyidresult) {return "Database Error";}
else
{
while ( $sv = $surveyidresult->FetchRow() )
{
modify_database("","ALTER TABLE ".$sv[0]." ADD `remindersent` VARCHAR(17) DEFAULT 'N'"); echo $modifyoutput; flush();
modify_database("","ALTER TABLE ".$sv[0]." ADD `remindercount` INT(11) DEFAULT 0"); echo $modifyoutput; flush();
}
}
}
function upgrade_survey_tables133()
{
$surveyidquery = "SELECT sid,additional_languages FROM ".db_table_name('surveys');
$surveyidresult = db_execute_num($surveyidquery);
while ( $sv = $surveyidresult->FetchRow() )
{
FixLanguageConsistency($sv[0],$sv[1]);
}
}
// Add the reminders tracking fields
function upgrade_token_tables134()
{
global $modifyoutput,$dbprefix;
$surveyidquery = "SHOW TABLES LIKE '".$dbprefix."tokens%'";
$surveyidresult = db_execute_num($surveyidquery);
if (!$surveyidresult) {return "Database Error";}
else
{
while ( $sv = $surveyidresult->FetchRow() )
{
modify_database("","ALTER TABLE ".$sv[0]." ADD `validfrom` Datetime"); echo $modifyoutput; flush();
modify_database("","ALTER TABLE ".$sv[0]." ADD `validuntil` Datetime"); echo $modifyoutput; flush();
}
}
}
function fix_mysql_collation()
{
global $connect, $modifyoutput, $dbprefix;
$sql = 'SHOW TABLE STATUS';
$result = db_execute_assoc($sql);
if (!$result) {
$modifyoutput .= 'SHOW TABLE - SQL Error';
global $connect, $modifyoutput, $dbprefix;
$sql = 'SHOW TABLE STATUS';
$result = db_execute_assoc($sql);
if (!$result) {
$modifyoutput .= 'SHOW TABLE - SQL Error';
}
while ( $tables = $result->FetchRow() ) {
// Loop through all tables in this database
$table = $tables['Name'];
$tablecollation=$tables['Collation'];
if (strpos($table,'old_')===false && ($dbprefix=='' || ($dbprefix!='' && strpos($table,$dbprefix)!==false)))
{
if ($tablecollation!='utf8_unicode_ci')
{
modify_database("","ALTER TABLE $table COLLATE utf8_unicode_ci");
echo $modifyoutput; flush();
}
# Now loop through all the fields within this table
$result2 = db_execute_assoc("SHOW FULL COLUMNS FROM ".$table);
while ( $column = $result2->FetchRow())
{
if ($column['Collation']!= 'utf8_unicode_ci' )
{
$field_name = $column['Field'];
$field_type = $column['Type'];
$field_default = $column['Default'];
if ($field_default!='NULL') {$field_default="'".$field_default."'";}
# Change text based fields
$skipped_field_types = array('char', 'text', 'enum', 'set');
foreach ( $skipped_field_types as $type )
{
if ( strpos($field_type, $type) !== false )
{
$modstatement="ALTER TABLE $table CHANGE `$field_name` `$field_name` $field_type CHARACTER SET utf8 COLLATE utf8_unicode_ci";
if ($type!='text') {$modstatement.=" DEFAULT $field_default";}
modify_database("",$modstatement);
echo $modifyoutput; flush();
}
}
}
}
}
}
while ( $tables = $result->FetchRow() ) {
// Loop through all tables in this database
$table = $tables['Name'];
$tablecollation=$tables['Collation'];
if (strpos($table,'old_')===false && ($dbprefix=='' || ($dbprefix!='' && strpos($table,$dbprefix)!==false)))
{
if ($tablecollation!='utf8_unicode_ci')
{
modify_database("","ALTER TABLE $table COLLATE utf8_unicode_ci");
echo $modifyoutput; flush();
}
# Now loop through all the fields within this table
$result2 = db_execute_assoc("SHOW FULL COLUMNS FROM ".$table);
while ( $column = $result2->FetchRow())
{
if ($column['Collation']!= 'utf8_unicode_ci' )
{
$field_name = $column['Field'];
$field_type = $column['Type'];
$field_default = $column['Default'];
if ($field_default!='NULL') {$field_default="'".$field_default."'";}
# Change text based fields
$skipped_field_types = array('char', 'text', 'enum', 'set');
foreach ( $skipped_field_types as $type )
{
if ( strpos($field_type, $type) !== false )
{
$modstatement="ALTER TABLE $table CHANGE `$field_name` `$field_name` $field_type CHARACTER SET utf8 COLLATE utf8_unicode_ci";
if ($type!='text') {$modstatement.=" DEFAULT $field_default";}
modify_database("",$modstatement);
echo $modifyoutput; flush();
}
}
}
}
}
}
}
?>

View File

@@ -1,240 +0,0 @@
<?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: upgrade-odbc_mssql.php 4453 2008-03-13 22:41:44Z c_schmitz $
*/
// 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;
}
if ($oldversion < 112) {
//The size of the users_name field is now 64 char (20 char before version 112)
modify_database("","ALTER TABLE [prefix_users] ALTER COLUMN [users_name] VARCHAR( 64 ) NOT NULL"); echo $modifyoutput; flush();
modify_database("","update [prefix_settings_global] set [stg_value`='112' where stg_name='DBVersion'"); echo $modifyoutput; flush();
}
if ($oldversion < 113) {
//No action needed
modify_database("","update [prefix_settings_global] set [stg_value]='113' where stg_name='DBVersion'"); echo $modifyoutput; flush();
}
if ($oldversion < 114) {
modify_database("","ALTER TABLE [prefix_saved_control] ALTER COLUMN [email] VARCHAR(320) NOT NULL"); echo $modifyoutput; flush();
modify_database("","ALTER TABLE [prefix_surveys] ALTER COLUMN [adminemail] VARCHAR(320) NOT NULL"); echo $modifyoutput; flush();
modify_database("","ALTER TABLE [prefix_users] ALTER COLUMN [email] VARCHAR(320) NOT NULL"); echo $modifyoutput; flush();
modify_database("",'INSERT INTO [prefix_settings_global] VALUES (\'SessionName\', \'$sessionname\');');echo $modifyoutput; flush();
modify_database("","update [prefix_settings_global] set [stg_value]='114' where stg_name='DBVersion'"); echo $modifyoutput; flush();
}
if ($oldversion < 126) {
modify_database("","ALTER TABLE [prefix_surveys] ADD [printanswers] CHAR(1) DEFAULT 'N'"); echo $modifyoutput; flush();
modify_database("","ALTER TABLE [prefix_surveys] ADD [listpublic] CHAR(1) DEFAULT 'N'"); echo $modifyoutput; flush();
upgrade_survey_tables117();
upgrade_survey_tables118();
//119
modify_database("","CREATE TABLE [prefix_quota] (
[id] int NOT NULL IDENTITY (1,1),
[sid] int,
[name] varchar(255) ,
[qlimit] int ,
[action] int ,
[active] int NOT NULL default '1',
PRIMARY KEY ([id])
);");echo $modifyoutput; flush();
modify_database("","CREATE TABLE [prefix_quota_members] (
[id] int NOT NULL IDENTITY (1,1),
[sid] int ,
[qid] int ,
[quota_id] int ,
[code] varchar(5) ,
PRIMARY KEY ([id])
);");echo $modifyoutput; flush();
// Rename Norwegian language code from NO to NB
$oldnewlanguages=array('no'=>'nb');
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'];
$toreplace2=str_replace('no','nb',$toreplace);
if ($toreplace2!=$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'];
$toreplace2=str_replace('no','nb',$toreplace);
if ($toreplace2!=$toreplace) {modify_database("","update [prefix_surveys] set [additional_languages]='$toreplace' where sid=".$datarow['sid']);echo $modifyoutput;flush();}
}
modify_database("","ALTER TABLE [prefix_surveys] ADD [htmlemail] CHAR(1) DEFAULT 'N'"); echo $modifyoutput; flush();
modify_database("","ALTER TABLE [prefix_surveys] ADD [usecaptcha] CHAR(1) DEFAULT 'N'"); echo $modifyoutput; flush();
modify_database("","ALTER TABLE [prefix_surveys] ADD [tokenanswerspersistence] CHAR(1) DEFAULT 'N'"); echo $modifyoutput; flush();
modify_database("","ALTER TABLE [prefix_users] ADD [htmleditormode] CHAR(7) DEFAULT 'default'"); echo $modifyoutput; flush();
modify_database("","CREATE TABLE [prefix_templates_rights] (
[uid] int NOT NULL,
[folder] varchar(255) NOT NULL,
[use] int NOT NULL,
PRIMARY KEY ([uid],[folder])
);");echo $modifyoutput; flush();
modify_database("","CREATE TABLE [prefix_templates] (
[folder] varchar(255) NOT NULL,
[creator] int NOT NULL,
PRIMARY KEY ([folder])
);");echo $modifyoutput; flush();
//123
modify_database("","ALTER TABLE [prefix_conditions] ALTER COLUMN [value] VARCHAR(255)"); echo $modifyoutput; flush();
// There is no other way to remove the previous default value
/*modify_database("","DECLARE @STR VARCHAR(100)
SET @STR = (
SELECT NAME
FROM SYSOBJECTS SO
JOIN SYSCONSTRAINTS SC ON SO.ID = SC.CONSTID
WHERE OBJECT_NAME(SO.PARENT_OBJ) = 'lime_labels'
AND SO.XTYPE = 'D' AND SC.COLID =
(SELECT COLID FROM SYSCOLUMNS WHERE ID = OBJECT_ID('lime_labels') AND NAME = 'title'))
SET @STR = 'ALTER TABLE lime_labels DROP CONSTRAINT ' + @STR
exec (@STR);"); echo $modifyoutput; flush(); */
modify_database("","ALTER TABLE [prefix_labels] ALTER COLUMN [title] varchar(4000)"); echo $modifyoutput; flush();
//124
modify_database("","ALTER TABLE [prefix_surveys] ADD [bounce_email] text"); echo $modifyoutput; flush();
//125
upgrade_token_tables125();
modify_database("","EXEC sp_rename 'prefix_users.move_user','superadmin'"); echo $modifyoutput; flush();
modify_database("","UPDATE [prefix_users] SET [superadmin]=1 where ([create_survey]=1 AND [create_user]=1 AND [delete_user]=1 AND [configurator]=1)"); echo $modifyoutput; flush();
//126
modify_database("","ALTER TABLE [prefix_questions] ADD [lid1] int NOT NULL DEFAULT '0'"); echo $modifyoutput; flush();
modify_database("","UPDATE [prefix_conditions] SET [method]='==' where ( [method] is null) or [method]=''"); echo $modifyoutput; flush();
modify_database("","update [prefix_settings_global] set [stg_value]='126' where stg_name='DBVersion'"); echo $modifyoutput; flush();
}
return true;
}
function upgrade_survey_tables117()
{
global $modifyoutput;
$surveyidquery = "SELECT sid FROM ".db_table_name('surveys')." WHERE active='Y' and datestamp='Y'";
$surveyidresult = db_execute_num($surveyidquery);
if (!$surveyidresult) {return "Database Error";}
else
{
while ( $sv = $surveyidresult->FetchRow() )
{
modify_database("","ALTER TABLE ".db_table_name('survey_'.$sv[0])." ADD [startdate] datetime"); echo $modifyoutput; flush();
}
}
}
function upgrade_survey_tables118()
{
global $connect,$modifyoutput,$dbprefix;
$tokentables=$connect->MetaTables('TABLES',false,$dbprefix."tokens%");
foreach ($tokentables as $sv)
{
modify_database("","ALTER TABLE ".$sv." ALTER COLUMN [token] VARCHAR(36)"); echo $modifyoutput; flush();
}
}
function upgrade_token_tables125()
{
global $connect,$modifyoutput,$dbprefix;
$tokentables=$connect->MetaTables('TABLES',false,$dbprefix."tokens%");
foreach ($tokentables as $sv)
{
modify_database("","ALTER TABLE ".$sv." ADD COLUMN [emailstatus ] VARCHAR(300) DEFAULT 'OK'"); echo $modifyoutput; flush();
}
}
?>

View File

@@ -18,14 +18,190 @@
// For this there will be a settings table which holds the last time the database was upgraded
function db_upgrade($oldversion) {
global $modifyoutput;
if ($oldversion < 125) {
if ($oldversion < 127) {
modify_database("","create index answers_idx2 on prefix_answers (sortorder)"); echo $modifyoutput; flush();
modify_database("","create index assessments_idx2 on prefix_assessments (sid)"); echo $modifyoutput; flush();
modify_database("","create index assessments_idx on prefix_assessments (gid)"); echo $modifyoutput; flush();
modify_database("","create index conditions_idx2 on prefix_conditions (qid)"); echo $modifyoutput; flush();
modify_database("","create index conditions_idx3 on prefix_conditions (cqid)"); echo $modifyoutput; flush();
modify_database("","create index groups_idx2 on prefix_groups (sid)"); echo $modifyoutput; flush();
modify_database("","create index question_attributes_idx2 on prefix_question_attributes (qid)"); echo $modifyoutput; flush();
modify_database("","create index questions_idx2 on prefix_questions (sid)"); echo $modifyoutput; flush();
modify_database("","create index questions_idx3 on prefix_questions (gid)"); echo $modifyoutput; flush();
modify_database("","create index questions_idx4 on prefix_questions (type)"); echo $modifyoutput; flush();
modify_database("","create index quota_idx2 on prefix_quota (sid)"); echo $modifyoutput; flush();
modify_database("","create index saved_control_idx2 on prefix_saved_control (sid)"); echo $modifyoutput; flush();
modify_database("","create index user_in_groups_idx1 on prefix_user_in_groups (ugid, uid)"); echo $modifyoutput; flush();
modify_database("","update prefix_settings_global set stg_value='127' where stg_name='DBVersion'"); echo $modifyoutput; flush();
}
if ($oldversion < 128) {
//128
upgrade_token_tables128();
modify_database("","update prefix_settings_global set stg_value='128' where stg_name='DBVersion'"); echo $modifyoutput; flush();
}
if ($oldversion < 129) {
//129
modify_database("","ALTER TABLE prefix_surveys ADD startdate date"); echo $modifyoutput; flush();
modify_database("","ALTER TABLE prefix_surveys ADD usestartdate char(1) NOT NULL default 'N'"); echo $modifyoutput; flush();
modify_database("","update prefix_settings_global set stg_value='129' where stg_name='DBVersion'"); echo $modifyoutput; flush();
}
if ($oldversion < 130)
{
modify_database("","ALTER TABLE prefix_conditions ADD scenario integer NOT NULL default '1'"); echo $modifyoutput; flush();
modify_database("","UPDATE prefix_conditions SET scenario=1 where (scenario is null) or scenario=0"); echo $modifyoutput; flush();
modify_database("","update prefix_settings_global set stg_value='130' where stg_name='DBVersion'"); echo $modifyoutput; flush();
}
if ($oldversion < 131)
{
modify_database("","ALTER TABLE prefix_surveys ADD publicstatistics char(1) NOT NULL default 'N'"); echo $modifyoutput; flush();
modify_database("","update prefix_settings_global set stg_value='131' where stg_name='DBVersion'"); echo $modifyoutput; flush();
}
if ($oldversion < 132)
{
modify_database("","ALTER TABLE prefix_surveys ADD publicgraphs char(1) NOT NULL default 'N'"); echo $modifyoutput; flush();
modify_database("","update prefix_settings_global set stg_value='132' where stg_name='DBVersion'"); echo $modifyoutput; flush();
}
if ($oldversion < 133)
{
modify_database("","ALTER TABLE prefix_users ADD one_time_pw bytea"); echo $modifyoutput; flush();
// Add new assessment setting
modify_database("","ALTER TABLE prefix_surveys ADD assessments char(1) NOT NULL default 'N'"); echo $modifyoutput; flush();
// add new assessment value fields to answers & labels
modify_database("","ALTER TABLE prefix_answers ADD assessment_value integer NOT NULL default '0'"); echo $modifyoutput; flush();
modify_database("","ALTER TABLE prefix_labels ADD assessment_value integer NOT NULL default '0'"); echo $modifyoutput; flush();
// copy any valid codes from code field to assessment field
modify_database("","update [prefix_answers set assessment_value=CAST(code as integer)");// no output here is intended
modify_database("","update prefix_labels set assessment_value=CAST(code as integer)");// no output here is intended
// activate assessment where assesment rules exist
modify_database("","update prefix_surveys set assessments='Y' where sid in (SELECT sid FROM prefix_assessments group by sid)"); echo $modifyoutput; flush();
// add language field to assessment table
modify_database("","ALTER TABLE prefix_assessments ADD language character varying(20) NOT NULL default 'en'"); echo $modifyoutput; flush();
// update language field with default language of that particular survey
modify_database("","update prefix_assessments set language=(select language from prefix_surveys where sid=prefix_assessments.sid)"); echo $modifyoutput; flush();
// copy assessment link to message since from now on we will have HTML assignment messages
modify_database("","update prefix_assessments set message=cast(message as character) ||'<br /><a href=\"'||link||'\">'||link||'</a>'"); echo $modifyoutput; flush();
// drop the old link field
modify_database("","ALTER TABLE prefix_assessments DROP COLUMN link"); echo $modifyoutput; flush();
// change the primary index to include language
modify_database("","ALTER TABLE prefix_assessments DROP CONSTRAINT prefix_assessments_pkey"); echo $modifyoutput; flush();
modify_database("","ALTER TABLE prefix_assessments ADD CONSTRAINT prefix_assessments_pkey PRIMARY KEY (id,language)"); echo $modifyoutput; flush();
// and fix missing translations for assessments
upgrade_survey_tables133();
// Add new fields to survey language settings
modify_database("","ALTER TABLE prefix_surveys_languagesettings ADD surveyls_url character varying(255)"); echo $modifyoutput; flush();
modify_database("","ALTER TABLE prefix_surveys_languagesettings ADD surveyls_endtext text"); echo $modifyoutput; flush();
// copy old URL fields ot language specific entries
modify_database("","update prefix_surveys_languagesettings set surveyls_url=(select url from prefix_surveys where sid=prefix_surveys_languagesettings.surveyls_survey_id)"); echo $modifyoutput; flush();
// drop old URL field
modify_database("","ALTER TABLE prefix_surveys DROP COLUMN url"); echo $modifyoutput; flush();
modify_database("","update prefix_settings_global set stg_value='133' where stg_name='DBVersion'"); echo $modifyoutput; flush();
}
if ($oldversion < 134)
{
modify_database("","ALTER TABLE prefix_surveys ADD usetokens char(1) NOT NULL default 'N'"); echo $modifyoutput; flush();
modify_database("","ALTER TABLE prefix_surveys ADD attributedescriptions TEXT;"); echo $modifyoutput; flush();
modify_database("","ALTER TABLE prefix_surveys DROP COLUMN attribute1"); echo $modifyoutput; flush();
modify_database("","ALTER TABLE prefix_surveys DROP COLUMN attribute2"); echo $modifyoutput; flush();
upgrade_token_tables134();
modify_database("","update prefix_settings_global set stg_value='134' where stg_name='DBVersion'"); echo $modifyoutput; flush();
}
if ($oldversion < 135)
{
modify_database("","ALTER TABLE prefix_question_attributes ALTER COLUMN value TYPE text"); echo $modifyoutput; flush();
modify_database("","update prefix_settings_global set stg_value='135' where stg_name='DBVersion'"); echo $modifyoutput; flush();
}
if ($oldversion < 136)
{
modify_database("", "ALTER TABLE prefix_quota ADD autoload_url integer NOT NULL DEFAULT 0"); echo $modifyoutput; flush();
modify_database("", "CREATE TABLE prefix_quota_languagesettings (
quotals_id serial NOT NULL,
quotals_quota_id integer NOT NULL DEFAULT 0,
quotals_language character varying(45) NOT NULL DEFAULT 'en'::character varying,
quotals_name character varying(200),
quotals_message text NOT NULL,
quotals_url character varying(255),
quotals_urldescrip character varying(255));"); echo $modifyoutput; flush();
modify_database("", "ALTER TABLE ONLY prefix_quota_languagesettings
ADD CONSTRAINT prefix_quota_languagesettings_pkey PRIMARY KEY (quotals_id);"); echo $modifyoutput; flush();
modify_database("", "ALTER TABLE ONLY prefix_users ADD CONSTRAINT prefix_users_pkey PRIMARY KEY (uid)"); echo $modifyoutput; flush();
modify_database("", "ALTER TABLE ONLY prefix_users ADD CONSTRAINT prefix_user_name_key UNIQUE (users_name)"); echo $modifyoutput; flush();
modify_database("", "update prefix_settings_global set stg_value='136' where stg_name='DBVersion'"); echo $modifyoutput; flush();
}
if ($oldversion < 137) //New date format specs
{
modify_database("", "ALTER TABLE prefix_surveys_languagesettings ADD surveyls_dateformat integer NOT NULL default 1"); echo $modifyoutput; flush();
modify_database("", "ALTER TABLE prefix_users ADD \"dateformat\" integer NOT NULL default 1"); echo $modifyoutput; flush();
modify_database("", "update prefix_surveys set startdate=null where usestartdate='N'"); echo $modifyoutput; flush();
modify_database("", "update prefix_surveys set expires=null where useexpiry='N'"); echo $modifyoutput; flush();
modify_database("", "ALTER TABLE prefix_surveys DROP COLUMN usestartdate"); echo $modifyoutput; flush();
modify_database("", "ALTER TABLE prefix_surveys DROP COLUMN useexpiry"); echo $modifyoutput; flush();
modify_database("", "update prefix_settings_global set stg_value='137' where stg_name='DBVersion'"); echo $modifyoutput; flush();
}
if ($oldversion < 138) //Modify quota field
{
modify_database("", "ALTER TABLE prefix_quota_members ALTER COLUMN code TYPE character varying(11)"); echo $modifyoutput; flush();
modify_database("", "UPDATE prefix_settings_global SET stg_value='138' WHERE stg_name='DBVersion'"); echo $modifyoutput; flush();
}
return true;
}
function upgrade_token_tables128()
{
global $modifyoutput,$dbprefix;
$surveyidquery = db_select_tables_like($dbprefix."tokens%");
$surveyidresult = db_execute_num($surveyidquery);
if (!$surveyidresult) {return "Database Error";}
else
{
while ( $sv = $surveyidresult->FetchRow() )
{
modify_database("","ALTER TABLE ".$sv0." ADD remindersent character varying(17) DEFAULT 'N'"); echo $modifyoutput; flush();
modify_database("","ALTER TABLE ".$sv0." ADD remindercount INTEGER DEFAULT 0"); echo $modifyoutput; flush();
}
}
}
function upgrade_survey_tables133()
{
global $modifyoutput;
$surveyidquery = "SELECT sid, additional_languages FROM ".db_table_name('surveys');
$surveyidresult = db_execute_num($surveyidquery);
while ( $sv = $surveyidresult->FetchRow() )
{
FixLanguageConsistency($sv['0'],$sv['1']);
}
}
function upgrade_token_tables134()
{
global $modifyoutput,$dbprefix;
$surveyidquery = db_select_tables_like($dbprefix."tokens%");
$surveyidresult = db_execute_num($surveyidquery);
if (!$surveyidresult) {return "Database Error";}
else
{
while ( $sv = $surveyidresult->FetchRow() )
{
modify_database("","ALTER TABLE ".$sv[0]." ADD validfrom timestamp"); echo $modifyoutput; flush();
modify_database("","ALTER TABLE ".$sv[0]." ADD validuntil timestamp"); echo $modifyoutput; flush();
}
}
}
?>