mirror of
https://github.com/ACSPRI/queXS
synced 2024-04-02 12:12:16 +00:00
Merging the Limesurvey 1.91+ branch of queXS in to the trunk
This commit is contained in:
664
include/limesurvey/admin/update/updater.php
Normal file
664
include/limesurvey/admin/update/updater.php
Normal file
@@ -0,0 +1,664 @@
|
||||
<?php
|
||||
/*
|
||||
* LimeSurvey
|
||||
* Copyright (C) 2007 The LimeSurvey Project Team / Carsten Schmitz
|
||||
* All rights reserved.
|
||||
* License: GNU/GPL License v2 or later, 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: updater.php 8987 2010-07-27 12:59:34Z c_schmitz $
|
||||
*/
|
||||
list(,$updaterversion)=explode(' ','$Rev: 10925 $'); // this is updated by subversion so don't change this string
|
||||
|
||||
if (isset($_REQUEST['update'])) die();
|
||||
|
||||
if ($action!=='update') return;
|
||||
|
||||
ob_start();
|
||||
switch ($subaction)
|
||||
{
|
||||
case 'step2':
|
||||
case 'step3':
|
||||
case 'step4':
|
||||
$updatefunction = 'Update'.ucfirst($subaction);
|
||||
break;
|
||||
default:
|
||||
$updatefunction = 'UpdateStep1';
|
||||
RunUpdaterUpdate();
|
||||
}
|
||||
|
||||
$buffer = $updatefunction();
|
||||
if ($buffer) echo $buffer;
|
||||
$adminoutput = ob_get_clean();
|
||||
|
||||
return;
|
||||
|
||||
function RunUpdaterUpdate()
|
||||
{
|
||||
global $homedir, $debug, $updaterversion, $versionnumber, $tempdir, $clang;
|
||||
require_once($homedir."/classes/http/http.php");
|
||||
|
||||
$http=new http_class;
|
||||
|
||||
/* Connection timeout */
|
||||
$http->timeout=0;
|
||||
/* Data transfer timeout */
|
||||
$http->data_timeout=0;
|
||||
$http->user_agent="Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)";
|
||||
$http->GetRequestArguments("http://update.limesurvey.org?updaterbuild=$updaterversion",$arguments);
|
||||
|
||||
$updateinfo=false;
|
||||
$error=$http->Open($arguments);
|
||||
$error=$http->SendRequest($arguments);
|
||||
|
||||
$http->ReadReplyHeaders($headers);
|
||||
|
||||
|
||||
if($error=="") {
|
||||
$body=''; $full_body='';
|
||||
for(;;){
|
||||
$error = $http->ReadReplyBody($body,10000);
|
||||
if($error != "" || strlen($body)==0) break;
|
||||
$full_body .= $body;
|
||||
}
|
||||
$updateinfo=json_decode($full_body,true);
|
||||
if ($http->response_status!='200')
|
||||
{
|
||||
$updateinfo['errorcode']=$http->response_status;
|
||||
$updateinfo['errorhtml']=$full_body;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$updateinfo['errorcode']=$error;
|
||||
$updateinfo['errorhtml']=$error;
|
||||
}
|
||||
unset( $http );
|
||||
if ((int)$updateinfo['UpdaterRevision']<=$updaterversion)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!is_writable($tempdir))
|
||||
{
|
||||
echo "<li class='errortitle'>".sprintf($clang->gT("Tempdir %s is not writable"),$tempdir)."<li>";
|
||||
$error=true;
|
||||
}
|
||||
if (!is_writable($homedir.DIRECTORY_SEPARATOR.'update'.DIRECTORY_SEPARATOR.'updater.php'))
|
||||
{
|
||||
echo "<li class='errortitle'>".sprintf($clang->gT("Updater file is not writable (%s). Please set according file permissions."),$homedir.DIRECTORY_SEPARATOR.'update'.DIRECTORY_SEPARATOR.'updater.php')."</li>";
|
||||
$error=true;
|
||||
}
|
||||
|
||||
// Download the zip file, unpack it and replace the updater file accordingly
|
||||
// Create DB and file backups now
|
||||
require_once("classes/pclzip/pclzip.lib.php");
|
||||
|
||||
// require_once('classes/pclzip/pcltrace.lib.php');
|
||||
// require_once('classes/pclzip/pclzip-trace.lib.php');
|
||||
// PclTraceOn(2);
|
||||
|
||||
require_once($homedir."/classes/http/http.php");
|
||||
|
||||
$downloaderror=false;
|
||||
$http=new http_class;
|
||||
|
||||
// Allow redirects
|
||||
$http->follow_redirect=1;
|
||||
/* Connection timeout */
|
||||
$http->timeout=0;
|
||||
/* Data transfer timeout */
|
||||
$http->data_timeout=0;
|
||||
$http->user_agent="Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)";
|
||||
$http->GetRequestArguments("http://update.limesurvey.org/updates/downloadupdater/$updaterversion",$arguments);
|
||||
|
||||
$httperror=$http->Open($arguments);
|
||||
$httperror=$http->SendRequest($arguments);
|
||||
$http->ReadReplyHeaders($headers);
|
||||
if ($headers['content-type']=='text/html')
|
||||
{
|
||||
@unlink($tempdir.'/updater.zip');
|
||||
}
|
||||
elseif($httperror=='') {
|
||||
$body=''; $full_body='';
|
||||
for(;;){
|
||||
$httperror = $http->ReadReplyBody($body,100000);
|
||||
if($httperror != "" || strlen($body)==0) break;
|
||||
$full_body .= $body;
|
||||
}
|
||||
file_put_contents($tempdir.'/updater.zip',$full_body);
|
||||
}
|
||||
else
|
||||
{
|
||||
print( $httperror );
|
||||
}
|
||||
|
||||
//Now unzip the new updater over the existing ones.
|
||||
if (file_exists($tempdir.'/updater.zip')){
|
||||
$archive = new PclZip($tempdir.'/updater.zip');
|
||||
if ($archive->extract(PCLZIP_OPT_PATH, $homedir.'/update/', PCLZIP_OPT_REPLACE_NEWER)== 0) {
|
||||
die("Error : ".$archive->errorInfo(true));
|
||||
}
|
||||
else
|
||||
{
|
||||
unlink($tempdir.'/updater.zip');
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
echo $clang->gT('There was a problem downloading the updater file. Please try to restart the update process.').'<br />';
|
||||
$error=true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
function UpdateStep1()
|
||||
{
|
||||
global $clang, $scriptname, $updatekey, $subaction, $updatebuild, $homedir, $buildnumber, $tempdir, $rootdir;
|
||||
|
||||
|
||||
if ($subaction=='keyupdate')
|
||||
{
|
||||
setGlobalSetting('updatekey',sanitize_paranoid_string($_POST['updatekey']));
|
||||
}
|
||||
$error=false;
|
||||
echo '<div class="header ui-widget-header">'.$clang->gT('Welcome to the ComfortUpdate').'</div><div class="updater-background"><br />';
|
||||
echo $clang->gT('The LimeSurvey ComfortUpdate is an easy procedure to quickly update to the latest version of LimeSurvey.').'<br />';
|
||||
echo $clang->gT('The following steps will be done by this update:').'<br /><ul>';
|
||||
echo '<li>'.$clang->gT('Your LimeSurvey installation is checked if the update can be run successfully.').'</li>';
|
||||
echo '<li>'.$clang->gT('Your DB and any changed files will be backed up.').'</li>';
|
||||
echo '<li>'.$clang->gT('New files will be downloaded and installed.').'</li>';
|
||||
echo '<li>'.$clang->gT('If necessary the database will be updated.').'</li></ul>';
|
||||
echo '<h3>'.$clang->gT('Checking basic requirements...').'</h3>';
|
||||
if ($updatekey==''){
|
||||
echo $clang->gT('You need an update key to run the comfort update. During the beta test of this update feature the key "LIMESURVEYUPDATE" can be used.');
|
||||
echo "<br /><form id='keyupdate' method='post' action='$scriptname?action=update&subaction=keyupdate'><label for='updatekey'>".$clang->gT('Please enter a valid update-key:').'</label>';
|
||||
echo '<input id="updatekey" name="updatekey" type="text" value="LIMESURVEYUPDATE" /> <input type="submit" value="'.$clang->gT('Save update key').'" /></form>';
|
||||
}
|
||||
else {
|
||||
echo "<ul><li class='successtitle'>".$clang->gT('Update key: Valid')."</li>";
|
||||
|
||||
if (!is_writable($tempdir))
|
||||
{
|
||||
echo "<li class='errortitle'>".sprintf($clang->gT("Tempdir %s is not writable"),$tempdir)."<li>";
|
||||
$error=true;
|
||||
}
|
||||
if (!is_writable($rootdir.DIRECTORY_SEPARATOR.'version.php'))
|
||||
{
|
||||
echo "<li class='errortitle'>".sprintf($clang->gT("Version file is not writable (%s). Please set according file permissions."),$rootdir.DIRECTORY_SEPARATOR.'version.php')."</li>";
|
||||
$error=true;
|
||||
}
|
||||
echo '</ul><h3>'.$clang->gT('Change log').'</h3>';
|
||||
require_once($homedir."/classes/http/http.php");
|
||||
$updatekey=getGlobalSetting('updatekey');
|
||||
|
||||
$http=new http_class;
|
||||
/* Connection timeout */
|
||||
$http->timeout=0;
|
||||
/* Data transfer timeout */
|
||||
$http->data_timeout=0;
|
||||
$http->user_agent="Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)";
|
||||
$http->GetRequestArguments("http://update.limesurvey.org/updates/changelog/$buildnumber/$updatebuild/$updatekey",$arguments);
|
||||
|
||||
$updateinfo=false;
|
||||
$httperror=$http->Open($arguments);
|
||||
$httperror=$http->SendRequest($arguments);
|
||||
|
||||
if($httperror=="") {
|
||||
$body=''; $full_body='';
|
||||
for(;;){
|
||||
$httperror = $http->ReadReplyBody($body,10000);
|
||||
if($httperror != "" || strlen($body)==0) break;
|
||||
$full_body .= $body;
|
||||
}
|
||||
$changelog=json_decode($full_body,true);
|
||||
echo '<textarea class="updater-changelog" readonly="readonly">'.htmlspecialchars($changelog['changelog']).'</textarea>';
|
||||
}
|
||||
else
|
||||
{
|
||||
print( $httperror );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ($error)
|
||||
{
|
||||
echo '<br /><br />'.$clang->gT('When checking your installation we found one or more problems. Please check for any error messages above and fix these before you can proceed.');
|
||||
echo "<p><button onclick=\"window.open('$scriptname?action=update&subaction=step1', '_self')\"";
|
||||
echo ">".$clang->gT('Check again')."</button></p>";
|
||||
}
|
||||
else
|
||||
{
|
||||
echo '<br /><br />'.$clang->gT('Everything looks alright. Please proceed to the next step.');
|
||||
echo "<p><button onclick=\"window.open('$scriptname?action=update&subaction=step2', '_self')\"";
|
||||
if ($updatekey==''){ echo "disabled='disabled'"; }
|
||||
echo ">".sprintf($clang->gT('Proceed to step %s'),'2')."</button></p>";
|
||||
}
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
|
||||
function UpdateStep2()
|
||||
{
|
||||
global $clang, $scriptname, $homedir, $buildnumber, $updatebuild, $debug, $rootdir;
|
||||
|
||||
// Request the list with changed files from the server
|
||||
|
||||
require_once($homedir."/classes/http/http.php");
|
||||
$updatekey=getGlobalSetting('updatekey');
|
||||
|
||||
echo '<div class="header ui-widget-header">'.sprintf($clang->gT('ComfortUpdate step %s'),'2').'</div><div class="updater-background"><br />';
|
||||
|
||||
$http=new http_class;
|
||||
/* Connection timeout */
|
||||
$http->timeout=0;
|
||||
/* Data transfer timeout */
|
||||
$http->data_timeout=0;
|
||||
$http->user_agent="Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)";
|
||||
$http->GetRequestArguments("http://update.limesurvey.org/updates/update/$buildnumber/$updatebuild/$updatekey",$arguments);
|
||||
|
||||
$updateinfo=false;
|
||||
$error=$http->Open($arguments);
|
||||
$error=$http->SendRequest($arguments);
|
||||
|
||||
if($error=="") {
|
||||
$body=''; $full_body='';
|
||||
for(;;){
|
||||
$error = $http->ReadReplyBody($body,10000);
|
||||
if($error != "" || strlen($body)==0) break;
|
||||
$full_body .= $body;
|
||||
}
|
||||
$updateinfo=json_decode($full_body,true);
|
||||
$http->SaveCookies($site_cookies);
|
||||
}
|
||||
else
|
||||
{
|
||||
print( $error );
|
||||
}
|
||||
|
||||
if (isset($updateinfo['error']))
|
||||
{
|
||||
echo $clang->gT('On requesting the update information from limesurvey.org there has been an error:').'<br />';
|
||||
|
||||
if ($updateinfo['error']==1)
|
||||
{
|
||||
setGlobalSetting('updatekey','');
|
||||
echo $clang->gT('Your update key is invalid and was removed. ').'<br />';
|
||||
}
|
||||
else
|
||||
echo $clang->gT('On requesting the update information from limesurvey.org there has been an error:').'<br />';
|
||||
}
|
||||
// okay, updateinfo now contains all necessary updateinformation
|
||||
// Now check if the existing files have the mentioned checksum
|
||||
$existingfiles=array();
|
||||
$modifiedfiles=array();
|
||||
$readonlyfiles=array();
|
||||
if (!isset($updateinfo['files']))
|
||||
{
|
||||
echo "<div class='messagebox ui-corner-all'>
|
||||
<div class='warningheader'>".$clang->gT('Update server busy')."</div>
|
||||
<p>".$clang->gT('The update server is currently busy. This usually happens when the update files for a new version are being prepared.')."<br /><br />
|
||||
".$clang->gT('Please be patient and try again in about 10 minutes.')."</p></div>
|
||||
<p><button onclick=\"window.open('$scriptname?action=globalsettings', '_self')\">".sprintf($clang->gT('Back to global settings'),'4')."</button></p>";
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
foreach ($updateinfo['files'] as $afile)
|
||||
{
|
||||
if ($afile['type']=='A' && !file_exists($rootdir.$afile['file']))
|
||||
{
|
||||
$searchpath=$rootdir.$afile['file'];
|
||||
$is_writable=is_writable(dirname($searchpath));
|
||||
while (!$is_writable && strlen($searchpath)>strlen($rootdir))
|
||||
{
|
||||
$searchpath=dirname($searchpath);
|
||||
if (file_exists($searchpath))
|
||||
{
|
||||
$is_writable=is_writable($searchpath);
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
if (!$is_writable)
|
||||
{
|
||||
$readonlyfiles[]=$searchpath;
|
||||
}
|
||||
}
|
||||
elseif (file_exists($rootdir.$afile['file']) && !is_writable($rootdir.$afile['file'])) {
|
||||
$readonlyfiles[]=$rootdir.$afile['file'];
|
||||
}
|
||||
|
||||
|
||||
if ($afile['type']=='A' && file_exists($rootdir.$afile['file']))
|
||||
{
|
||||
//A new file, check if this already exists
|
||||
$existingfiles[]=$afile;
|
||||
}
|
||||
elseif (($afile['type']=='D' || $afile['type']=='M') && is_file($rootdir.$afile['file']) && sha1_file($rootdir.$afile['file'])!=$afile['checksum']) // A deleted or modified file - check if it is unmodified
|
||||
{
|
||||
$modifiedfiles[]=$afile;
|
||||
}
|
||||
}
|
||||
|
||||
echo '<h3>'.$clang->gT('Checking existing LimeSurvey files...').'</h3>';
|
||||
if (count($readonlyfiles)>0)
|
||||
{
|
||||
echo '<span class="warningtitle">'.$clang->gT('Warning: The following files/directories need to be updated but their permissions are set to read-only.').'<br />';
|
||||
echo $clang->gT('You must set according write permissions on these filese before you can proceed. If you are unsure what to do please contact your system administrator for advice.').'<br />';
|
||||
echo '</span><ul>';
|
||||
$readonlyfiles=array_unique($readonlyfiles);
|
||||
sort($readonlyfiles);
|
||||
foreach ($readonlyfiles as $readonlyfile)
|
||||
{
|
||||
echo '<li>'.htmlspecialchars($readonlyfile).'</li>';
|
||||
}
|
||||
echo '</ul>';
|
||||
}
|
||||
if (count($existingfiles)>0)
|
||||
{
|
||||
echo $clang->gT('The following files would be added by the update but already exist. This is very unusual and may be co-incidental.').'<br />';
|
||||
echo $clang->gT('We recommend that these files should be replaced by the update procedure.').'<br />';
|
||||
echo '<ul>';
|
||||
sort($existingfiles);
|
||||
foreach ($existingfiles as $existingfile)
|
||||
{
|
||||
echo '<li>'.htmlspecialchars($existingfile['file']).'</li>';
|
||||
}
|
||||
echo '</ul>';
|
||||
}
|
||||
|
||||
if (count($modifiedfiles)>0)
|
||||
{
|
||||
echo $clang->gT('The following files will be modified or deleted but were already modified by someone else.').'<br />';
|
||||
echo $clang->gT('We recommend that these files should be replaced by the update procedure.').'<br />';
|
||||
echo '<ul>';
|
||||
sort($modifiedfiles);
|
||||
foreach ($modifiedfiles as $modifiedfile)
|
||||
{
|
||||
echo '<li>'.htmlspecialchars($modifiedfile['file']).'</li>';
|
||||
}
|
||||
echo '</ul>';
|
||||
}
|
||||
|
||||
if (count($readonlyfiles)>0)
|
||||
{
|
||||
echo '<br />'.$clang->gT('When checking your file permissions we found one or more problems. Please check for any error messages above and fix these before you can proceed.');
|
||||
echo "<p><button onclick=\"window.open('$scriptname?action=update&subaction=step2', '_self')\"";
|
||||
echo ">".$clang->gT('Check again')."</button></p>";
|
||||
}
|
||||
else
|
||||
{
|
||||
echo $clang->gT('Please check any problems above and then proceed to the next step.').'<br />';
|
||||
echo "<p><button onclick=\"window.open('$scriptname?action=update&subaction=step3', '_self')\" ";
|
||||
echo ">".sprintf($clang->gT('Proceed to step %s'),'3')."</button></p>";
|
||||
|
||||
}
|
||||
}
|
||||
$_SESSION['updateinfo']=$updateinfo;
|
||||
$_SESSION['updatesession']=$site_cookies;
|
||||
}
|
||||
|
||||
|
||||
function UpdateStep3()
|
||||
{
|
||||
global $clang, $scriptname, $homedir, $buildnumber, $updatebuild, $debug, $rootdir, $publicdir, $tempdir, $database_exists, $databasetype, $action, $demoModeOnly;
|
||||
|
||||
echo '<div class="header ui-widget-header">'.sprintf($clang->gT('ComfortUpdate step %s'),'3').'</div><div class="updater-background">';
|
||||
echo '<h3>'.$clang->gT('Creating DB & file backup').'</h3>';
|
||||
if (!isset( $_SESSION['updateinfo']))
|
||||
{
|
||||
echo $clang->gT('On requesting the update information from limesurvey.org there has been an error:').'<br />';
|
||||
|
||||
if ($updateinfo['error']==1)
|
||||
{
|
||||
setGlobalSetting('updatekey','');
|
||||
echo $clang->gT('Your update key is invalid and was removed. ').'<br />';
|
||||
}
|
||||
else
|
||||
echo $clang->gT('On requesting the update information from limesurvey.org there has been an error:').'<br />';
|
||||
}
|
||||
else
|
||||
{
|
||||
$updateinfo=$_SESSION['updateinfo'];
|
||||
}
|
||||
|
||||
// okay, updateinfo now contains all necessary updateinformation
|
||||
// Create DB and file backups now
|
||||
|
||||
$basefilename = date("YmdHis-").md5(uniqid(rand(), true));
|
||||
//Now create a backup of the files to be delete or modified
|
||||
|
||||
Foreach ($updateinfo['files'] as $file)
|
||||
{
|
||||
if (is_file($publicdir.$file['file'])===true) // Sort out directories
|
||||
{
|
||||
$filestozip[]=$publicdir.$file['file'];
|
||||
}
|
||||
}
|
||||
|
||||
require_once("classes/pclzip/pclzip.lib.php");
|
||||
// require_once('classes/pclzip/pcltrace.lib.php');
|
||||
// require_once('classes/pclzip/pclzip-trace.lib.php');
|
||||
|
||||
//PclTraceOn(1);
|
||||
|
||||
$archive = new PclZip($tempdir.DIRECTORY_SEPARATOR.'files-'.$basefilename.'.zip');
|
||||
|
||||
|
||||
$v_list = $archive->add($filestozip, PCLZIP_OPT_REMOVE_PATH, $publicdir);
|
||||
|
||||
echo $clang->gT('Creating file backup... ').'<br />';
|
||||
|
||||
if ($v_list == 0) {
|
||||
die("Error : ".$archive->errorInfo(true));
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "<span class='successtitle'>".$clang->gT('File backup created:').' '.htmlspecialchars($tempdir.DIRECTORY_SEPARATOR.'files-'.$basefilename.'.zip').'</span><br /><br />';
|
||||
|
||||
}
|
||||
|
||||
require_once("dumpdb.php");
|
||||
|
||||
if ($databasetype=='mysql' || $databasetype=='mysqli')
|
||||
{
|
||||
echo $clang->gT('Creating database backup... ').'<br />';
|
||||
$byteswritten=file_put_contents($tempdir.DIRECTORY_SEPARATOR.'db-'.$basefilename.'.sql',completedump());
|
||||
if ($byteswritten>5000)
|
||||
{
|
||||
echo "<span class='successtitle'>".$clang->gT('DB backup created:')." ".htmlspecialchars($tempdir.DIRECTORY_SEPARATOR.'db-'.$basefilename.'.sql').'</span><br /><br />';
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "<span class='warningtitle'>".$clang->gT('No DB backup created:').'<br />'.$clang->gT('Database backup functionality is currently not available for your database type. Before proceeding please backup your database using a backup tool!').'</span><br /><br />';
|
||||
}
|
||||
|
||||
echo $clang->gT('Please check any problems above and then proceed to the final step.');
|
||||
echo "<p><button onclick=\"window.open('$scriptname?action=update&subaction=step4', '_self')\" ";
|
||||
echo ">".sprintf($clang->gT('Proceed to step %s'),'4')."</button></p>";
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
|
||||
function UpdateStep4()
|
||||
{
|
||||
global $clang, $scriptname, $homedir, $buildnumber, $updatebuild, $debug, $rootdir, $publicdir, $tempdir, $database_exists, $databasetype, $action, $demoModeOnly;
|
||||
|
||||
echo '<div class="header ui-widget-header">'.sprintf($clang->gT('ComfortUpdate step %s'),'4').'</div><div class="updater-background"><br />';
|
||||
if (!isset( $_SESSION['updateinfo']))
|
||||
{
|
||||
echo $clang->gT('On requesting the update information from limesurvey.org there has been an error:').'<br />';
|
||||
|
||||
if ($updateinfo['error']==1)
|
||||
{
|
||||
setGlobalSetting('updatekey','');
|
||||
echo $clang->gT('Your update key is invalid and was removed. ').'<br />';
|
||||
}
|
||||
else
|
||||
echo $clang->gT('On requesting the update information from limesurvey.org there has been an error:').'<br />';
|
||||
}
|
||||
else
|
||||
{
|
||||
$updateinfo=$_SESSION['updateinfo'];
|
||||
}
|
||||
// this is the last step - Download the zip file, unpack it and replace files accordingly
|
||||
// Create DB and file backups now
|
||||
require_once("classes/pclzip/pclzip.lib.php");
|
||||
|
||||
// require_once('classes/pclzip/pcltrace.lib.php');
|
||||
// require_once('classes/pclzip/pclzip-trace.lib.php');
|
||||
|
||||
// PclTraceOn(2);
|
||||
require_once($homedir."/classes/http/http.php");
|
||||
|
||||
$downloaderror=false;
|
||||
$http=new http_class;
|
||||
|
||||
// Allow redirects
|
||||
$http->follow_redirect=1;
|
||||
/* Connection timeout */
|
||||
$http->timeout=0;
|
||||
/* Data transfer timeout */
|
||||
$http->data_timeout=0;
|
||||
$http->user_agent="Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)";
|
||||
$http->GetRequestArguments("http://update.limesurvey.org/updates/download/{$updateinfo['downloadid']}",$arguments);
|
||||
$http->RestoreCookies($_SESSION['updatesession']);
|
||||
|
||||
$error=$http->Open($arguments);
|
||||
$error=$http->SendRequest($arguments);
|
||||
$http->ReadReplyHeaders($headers);
|
||||
if ($headers['content-type']=='text/html')
|
||||
{
|
||||
@unlink($tempdir.'/update.zip');
|
||||
}
|
||||
elseif($error=='') {
|
||||
$body='';
|
||||
$pFile = fopen($tempdir.'/update.zip', 'w');
|
||||
for(;;){
|
||||
$error = $http->ReadReplyBody($body,100000);
|
||||
if($error != "" || strlen($body)==0) break;
|
||||
fwrite($pFile, $body);
|
||||
}
|
||||
fclose($pFile);
|
||||
}
|
||||
else
|
||||
{
|
||||
print( $error );
|
||||
}
|
||||
|
||||
// Now remove all files that are to be deleted according to update process
|
||||
foreach ($updateinfo['files'] as $afile)
|
||||
{
|
||||
if ($afile['type']=='D' && file_exists($rootdir.$afile['file']))
|
||||
{
|
||||
if (is_file($rootdir.$afile['file']))
|
||||
{
|
||||
unlink($rootdir.$afile['file']);
|
||||
}
|
||||
else{
|
||||
rmdirr($rootdir.$afile['file']);
|
||||
}
|
||||
echo sprintf($clang->gT('File deleted: %s'),$afile['file']).'<br />';
|
||||
}
|
||||
}
|
||||
|
||||
//Now unzip the new files over the existing ones.
|
||||
if (file_exists($tempdir.'/update.zip')){
|
||||
$archive = new PclZip($tempdir.'/update.zip');
|
||||
if ($archive->extract(PCLZIP_OPT_PATH, $rootdir.'/', PCLZIP_OPT_REPLACE_NEWER)== 0) {
|
||||
die("Error : ".$archive->errorInfo(true));
|
||||
}
|
||||
else
|
||||
{
|
||||
echo $clang->gT('New files were successfully installed.').'<br />';
|
||||
unlink($tempdir.'/update.zip');
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
echo $clang->gT('There was a problem downloading the update file. Please try to restart the update process.').'<br />';
|
||||
$downloaderror=true;
|
||||
}
|
||||
// PclTraceDisplay();
|
||||
|
||||
// Now we have to update version.php
|
||||
if (!$downloaderror)
|
||||
{
|
||||
@ini_set('auto_detect_line_endings', true);
|
||||
$versionlines=file($rootdir.'/version.php');
|
||||
$handle = fopen($rootdir.'/version.php', "w");
|
||||
foreach ($versionlines as $line)
|
||||
{
|
||||
if(strpos($line,'$buildnumber')!==false)
|
||||
{
|
||||
$line='$buildnumber'." = '{$_SESSION['updateinfo']['toversion']}';\r\n";
|
||||
}
|
||||
fwrite($handle,$line);
|
||||
}
|
||||
fclose($handle);
|
||||
echo sprintf($clang->gT('Buildnumber was successfully updated to %s.'),$_SESSION['updateinfo']['toversion']).'<br />';
|
||||
echo $clang->gT('Please check any problems above - update was done.').'<br />';
|
||||
}
|
||||
|
||||
|
||||
echo "<p><button onclick=\"window.open('$scriptname?action=globalsettings&subaction=updatecheck', '_self')\" >".$clang->gT('Back to main menu')."</button></p>";
|
||||
echo '</div>';
|
||||
setGlobalSetting('updatelastcheck','1980-01-01 00:00');
|
||||
setGlobalSetting('updateavailable','0');
|
||||
}
|
||||
|
||||
/**
|
||||
* This functions checks if the databaseversion in the settings table is the same one as required
|
||||
* If not then the necessary upgrade procedures are run
|
||||
*/
|
||||
function CheckForDBUpgrades()
|
||||
{
|
||||
global $connect, $databasetype, $dbprefix, $dbversionnumber, $clang;
|
||||
$currentDBVersion=GetGlobalSetting('DBVersion');
|
||||
if (intval($dbversionnumber)>intval($currentDBVersion))
|
||||
{
|
||||
if(isset($_GET['continue']) && $_GET['continue']==1)
|
||||
{
|
||||
echo "<div style='width:90%; padding:1% 10%;background-color:#eee;'>";
|
||||
$upgradedbtype=$databasetype;
|
||||
if ($upgradedbtype=='mssql_n' || $upgradedbtype=='odbc_mssql' || $upgradedbtype=='odbtp') $upgradedbtype='mssql';
|
||||
if ($upgradedbtype=='mssqlnative') $upgradedbtype = 'mssqlnative';
|
||||
if ($upgradedbtype=='mysqli') $upgradedbtype='mysql';
|
||||
include ('upgrade-'.$upgradedbtype.'.php');
|
||||
include ('upgrade-all.php');
|
||||
$tables = $connect->MetaTables();
|
||||
db_upgrade_all(intval($currentDBVersion));
|
||||
db_upgrade(intval($currentDBVersion));
|
||||
echo "<br />".sprintf($clang->gT("Database has been successfully upgraded to version %s"),$dbversionnumber);
|
||||
}
|
||||
else {
|
||||
ShowDBUpgradeNotice();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function ShowDBUpgradeNotice() {
|
||||
global $databasetype, $dbprefix, $databasename, $sitename, $rooturl,$clang;
|
||||
$error=false;
|
||||
echo "<div class='header'>".$clang->gT('Database upgrade').'</div><p>';
|
||||
echo $clang->gT('Please verify the following information before continuing with the database upgrade:').'<ul>';
|
||||
echo "<li><b>" .$clang->gT('Database type') . ":</b> " . $databasetype . "</li>";
|
||||
echo "<li><b>" .$clang->gT('Database name') . ":</b> " . $databasename . "</li>";
|
||||
echo "<li><b>" .$clang->gT('Table prefix') . ":</b> " . $dbprefix . "</li>";
|
||||
echo "<li><b>" .$clang->gT('Site name') . ":</b> " . $sitename . "</li>";
|
||||
echo "<li><b>" .$clang->gT('Root URL') . ":</b> " . $rooturl . "</li>";
|
||||
echo '</ul>';
|
||||
echo "<br />";
|
||||
echo "<a href='{$rooturl}/admin/admin.php?continue=1'>" . $clang->gT('Click here to continue') . "</a>";
|
||||
echo "<br />";
|
||||
}
|
||||
|
||||
?>
|
||||
204
include/limesurvey/admin/update/upgrade-all.php
Normal file
204
include/limesurvey/admin/update/upgrade-all.php
Normal file
@@ -0,0 +1,204 @@
|
||||
<?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 7556 2009-09-01 23:48:37Z 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_all($oldversion) {
|
||||
/// This function does anything necessary to upgrade
|
||||
/// older versions to match current functionality
|
||||
global $modifyoutput, $dbprefix, $usertemplaterootdir, $standardtemplaterootdir, $clang;
|
||||
echo str_pad($clang->gT('The LimeSurvey database is being upgraded').' ('.date('Y-m-d H:i:s').')',14096).".". $clang->gT('Please be patient...')."<br /><br />\n";
|
||||
|
||||
if ($oldversion < 143)
|
||||
{
|
||||
// Move all user templates to the new user template directory
|
||||
echo sprintf($clang->gT("Moving user templates to new location at %s..."),$usertemplaterootdir)."<br />";
|
||||
$myDirectory = opendir($standardtemplaterootdir);
|
||||
$aFailedTemplates=array();
|
||||
// get each entry
|
||||
while($entryName = readdir($myDirectory)) {
|
||||
if (!in_array($entryName,array('.','..','.svn')) && is_dir($standardtemplaterootdir.DIRECTORY_SEPARATOR.$entryName) && !isStandardTemplate($entryName))
|
||||
{
|
||||
if (!rename($standardtemplaterootdir.DIRECTORY_SEPARATOR.$entryName,$usertemplaterootdir.DIRECTORY_SEPARATOR.$entryName))
|
||||
{
|
||||
$aFailedTemplates[]=$entryName;
|
||||
};
|
||||
}
|
||||
}
|
||||
if (count($aFailedTemplates)>0)
|
||||
{
|
||||
echo "The following templates at {$standardtemplaterootdir} could not be moved to the new location at {$usertemplaterootdir}:<br /><ul>";
|
||||
foreach ($aFailedTemplates as $sFailedTemplate)
|
||||
{
|
||||
echo "<li>{$sFailedTemplate}</li>";
|
||||
}
|
||||
echo "</ul>Please move these templates manually after the upgrade has finished.<br />";
|
||||
}
|
||||
// close directory
|
||||
closedir($myDirectory);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
function upgrade_survey_table145()
|
||||
{
|
||||
global $modifyoutput, $connect;
|
||||
$sSurveyQuery = "SELECT * FROM ".db_table_name('surveys')." where notification<>'0'";
|
||||
$oSurveyResult = db_execute_assoc($sSurveyQuery);
|
||||
while ( $aSurveyRow = $oSurveyResult->FetchRow() )
|
||||
{
|
||||
if ($aSurveyRow['notification']=='1' && trim($aSurveyRow['adminemail'])!='')
|
||||
{
|
||||
$aEmailAddresses=explode(';',$aSurveyRow['adminemail']);
|
||||
$sAdminEmailAddress=$aEmailAddresses[0];
|
||||
$sEmailnNotificationAddresses=implode(';',$aEmailAddresses);
|
||||
$sSurveyUpdateQuery= "update ".db_table_name('surveys')." set adminemail='{$sAdminEmailAddress}', emailnotificationto='{$sEmailnNotificationAddresses}' where sid=".$aSurveyRow['sid'];
|
||||
$connect->execute($sSurveyUpdateQuery);
|
||||
}
|
||||
else
|
||||
{
|
||||
$aEmailAddresses=explode(';',$aSurveyRow['adminemail']);
|
||||
$sAdminEmailAddress=$aEmailAddresses[0];
|
||||
$sEmailDetailedNotificationAddresses=implode(';',$aEmailAddresses);
|
||||
if (trim($aSurveyRow['emailresponseto'])!='')
|
||||
{
|
||||
$sEmailDetailedNotificationAddresses=$sEmailDetailedNotificationAddresses.';'.trim($aSurveyRow['emailresponseto']);
|
||||
}
|
||||
$sSurveyUpdateQuery= "update ".db_table_name('surveys')." set adminemail='{$sAdminEmailAddress}', emailnotificationto='{$sEmailDetailedNotificationAddresses}' where sid=".$aSurveyRow['sid'];
|
||||
$connect->execute($sSurveyUpdateQuery);
|
||||
}
|
||||
}
|
||||
$sSurveyQuery = "SELECT * FROM ".db_table_name('surveys_languagesettings');
|
||||
$oSurveyResult = db_execute_assoc($sSurveyQuery);
|
||||
while ( $aSurveyRow = $oSurveyResult->FetchRow() )
|
||||
{
|
||||
$oLanguage = new limesurvey_lang($aSurveyRow['surveyls_language']);
|
||||
$aDefaultTexts=aTemplateDefaultTexts($oLanguage,'unescaped');
|
||||
unset($oLanguage);
|
||||
$aDefaultTexts['admin_detailed_notification_subject']=$aDefaultTexts['admin_detailed_notification'].$aDefaultTexts['admin_detailed_notification_css'];
|
||||
$aDefaultTexts=array_map('db_quoteall',$aDefaultTexts);
|
||||
$sSurveyUpdateQuery= "update ".db_table_name('surveys_languagesettings')." set
|
||||
email_admin_responses_subj={$aDefaultTexts['admin_detailed_notification_subject']},
|
||||
email_admin_responses={$aDefaultTexts['admin_detailed_notification']},
|
||||
email_admin_notification_subj={$aDefaultTexts['admin_notification_subject']},
|
||||
email_admin_notification={$aDefaultTexts['admin_notification']}
|
||||
where surveyls_survey_id=".$aSurveyRow['surveyls_survey_id'];
|
||||
$connect->execute($sSurveyUpdateQuery);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
function upgrade_surveypermissions_table145()
|
||||
{
|
||||
global $modifyoutput, $connect;
|
||||
$sPermissionQuery = "SELECT * FROM ".db_table_name('surveys_rights');
|
||||
$oPermissionResult = db_execute_assoc($sPermissionQuery);
|
||||
if (!$oPermissionResult) {return "Database Error";}
|
||||
else
|
||||
{
|
||||
$tablename=db_table_name_nq('survey_permissions');
|
||||
while ( $aPermissionRow = $oPermissionResult->FetchRow() )
|
||||
{
|
||||
|
||||
$sPermissionInsertQuery=$connect->GetInsertSQL($tablename,array('permission'=>'assessments',
|
||||
'create_p'=>$aPermissionRow['define_questions'],
|
||||
'read_p'=>$aPermissionRow['define_questions'],
|
||||
'update_p'=>$aPermissionRow['define_questions'],
|
||||
'delete_p'=>$aPermissionRow['define_questions'],
|
||||
'sid'=>$aPermissionRow['sid'],
|
||||
'uid'=>$aPermissionRow['uid']));
|
||||
modify_database("",$sPermissionInsertQuery); echo $modifyoutput; flush();ob_flush();
|
||||
|
||||
$sPermissionInsertQuery=$connect->GetInsertSQL($tablename,array('permission'=>'quotas',
|
||||
'create_p'=>$aPermissionRow['define_questions'],
|
||||
'read_p'=>$aPermissionRow['define_questions'],
|
||||
'update_p'=>$aPermissionRow['define_questions'],
|
||||
'delete_p'=>$aPermissionRow['define_questions'],
|
||||
'sid'=>$aPermissionRow['sid'],
|
||||
'uid'=>$aPermissionRow['uid']));
|
||||
modify_database("",$sPermissionInsertQuery); echo $modifyoutput; flush();ob_flush();
|
||||
|
||||
$sPermissionInsertQuery=$connect->GetInsertSQL($tablename,array('permission'=>'responses',
|
||||
'create_p'=>$aPermissionRow['browse_response'],
|
||||
'read_p'=>$aPermissionRow['browse_response'],
|
||||
'update_p'=>$aPermissionRow['browse_response'],
|
||||
'delete_p'=>$aPermissionRow['delete_survey'],
|
||||
'export_p'=>$aPermissionRow['export'],
|
||||
'import_p'=>$aPermissionRow['browse_response'],
|
||||
'sid'=>$aPermissionRow['sid'],
|
||||
'uid'=>$aPermissionRow['uid']));
|
||||
modify_database("",$sPermissionInsertQuery); echo $modifyoutput; flush();ob_flush();
|
||||
|
||||
$sPermissionInsertQuery=$connect->GetInsertSQL($tablename,array('permission'=>'statistics',
|
||||
'read_p'=>$aPermissionRow['browse_response'],
|
||||
'sid'=>$aPermissionRow['sid'],
|
||||
'uid'=>$aPermissionRow['uid']));
|
||||
modify_database("",$sPermissionInsertQuery); echo $modifyoutput; flush();ob_flush();
|
||||
|
||||
$sPermissionInsertQuery=$connect->GetInsertSQL($tablename,array('permission'=>'survey',
|
||||
'read_p'=>1,
|
||||
'delete_p'=>$aPermissionRow['delete_survey'],
|
||||
'sid'=>$aPermissionRow['sid'],
|
||||
'uid'=>$aPermissionRow['uid']));
|
||||
modify_database("",$sPermissionInsertQuery); echo $modifyoutput; flush();ob_flush();
|
||||
|
||||
$sPermissionInsertQuery=$connect->GetInsertSQL($tablename,array('permission'=>'surveyactivation',
|
||||
'update_p'=>$aPermissionRow['activate_survey'],
|
||||
'sid'=>$aPermissionRow['sid'],
|
||||
'uid'=>$aPermissionRow['uid']));
|
||||
modify_database("",$sPermissionInsertQuery); echo $modifyoutput; flush();ob_flush();
|
||||
|
||||
$sPermissionInsertQuery=$connect->GetInsertSQL($tablename,array('permission'=>'surveycontent',
|
||||
'create_p'=>$aPermissionRow['define_questions'],
|
||||
'read_p'=>$aPermissionRow['define_questions'],
|
||||
'update_p'=>$aPermissionRow['define_questions'],
|
||||
'delete_p'=>$aPermissionRow['define_questions'],
|
||||
'export_p'=>$aPermissionRow['export'],
|
||||
'import_p'=>$aPermissionRow['define_questions'],
|
||||
'sid'=>$aPermissionRow['sid'],
|
||||
'uid'=>$aPermissionRow['uid']));
|
||||
modify_database("",$sPermissionInsertQuery); echo $modifyoutput; flush();ob_flush();
|
||||
|
||||
$sPermissionInsertQuery=$connect->GetInsertSQL($tablename,array('permission'=>'surveylocale',
|
||||
'read_p'=>$aPermissionRow['edit_survey_property'],
|
||||
'update_p'=>$aPermissionRow['edit_survey_property'],
|
||||
'sid'=>$aPermissionRow['sid'],
|
||||
'uid'=>$aPermissionRow['uid']));
|
||||
modify_database("",$sPermissionInsertQuery); echo $modifyoutput; flush();ob_flush();
|
||||
|
||||
$sPermissionInsertQuery=$connect->GetInsertSQL($tablename,array('permission'=>'surveysettings',
|
||||
'read_p'=>$aPermissionRow['edit_survey_property'],
|
||||
'update_p'=>$aPermissionRow['edit_survey_property'],
|
||||
'sid'=>$aPermissionRow['sid'],
|
||||
'uid'=>$aPermissionRow['uid']));
|
||||
modify_database("",$sPermissionInsertQuery); echo $modifyoutput; flush();ob_flush();
|
||||
|
||||
$sPermissionInsertQuery=$connect->GetInsertSQL($tablename,array('permission'=>'tokens',
|
||||
'create_p'=>$aPermissionRow['activate_survey'],
|
||||
'read_p'=>$aPermissionRow['activate_survey'],
|
||||
'update_p'=>$aPermissionRow['activate_survey'],
|
||||
'delete_p'=>$aPermissionRow['activate_survey'],
|
||||
'export_p'=>$aPermissionRow['export'],
|
||||
'import_p'=>$aPermissionRow['activate_survey'],
|
||||
'sid'=>$aPermissionRow['sid'],
|
||||
'uid'=>$aPermissionRow['uid'])
|
||||
);
|
||||
modify_database("",$sPermissionInsertQuery); echo $modifyoutput; flush();ob_flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
815
include/limesurvey/admin/update/upgrade-mssql.php
Normal file
815
include/limesurvey/admin/update/upgrade-mssql.php
Normal file
@@ -0,0 +1,815 @@
|
||||
<?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 7556 2009-09-01 23:48:37Z 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, $clang;
|
||||
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();ob_flush();
|
||||
modify_database("","update [prefix_questions] set [language]='$newlang' where language='$oldlang'");echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","update [prefix_groups] set [language]='$newlang' where language='$oldlang'");echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","update [prefix_labels] set [language]='$newlang' where language='$oldlang'");echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","update [prefix_surveys] set [language]='$newlang' where language='$oldlang'");echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","update [prefix_surveys_languagesettings] set [surveyls_language]='$newlang' where surveyls_language='$oldlang'");echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","update [prefix_users] set [lang]='$newlang where lang='$oldlang'");echo $modifyoutput; flush();ob_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();ob_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();ob_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();ob_flush();
|
||||
modify_database("","update [prefix_settings_global] set [stg_value]='112' where stg_name='DBVersion'"); echo $modifyoutput; flush();ob_flush();
|
||||
}
|
||||
|
||||
if ($oldversion < 113) {
|
||||
//No action needed
|
||||
modify_database("","update [prefix_settings_global] set [stg_value]='113' where stg_name='DBVersion'"); echo $modifyoutput; flush();ob_flush();
|
||||
}
|
||||
|
||||
if ($oldversion < 114) {
|
||||
modify_database("","ALTER TABLE [prefix_saved_control] ALTER COLUMN [email] VARCHAR(320) NOT NULL"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","ALTER TABLE [prefix_surveys] ALTER COLUMN [adminemail] VARCHAR(320) NOT NULL"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","ALTER TABLE [prefix_users] ALTER COLUMN [email] VARCHAR(320) NOT NULL"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("",'INSERT INTO [prefix_settings_global] VALUES (\'SessionName\', \'$sessionname\');');echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","update [prefix_settings_global] set [stg_value]='114' where stg_name='DBVersion'"); echo $modifyoutput; flush();ob_flush();
|
||||
}
|
||||
|
||||
if ($oldversion < 126) {
|
||||
modify_database("","ALTER TABLE [prefix_surveys] ADD [printanswers] CHAR(1) DEFAULT 'N'"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","ALTER TABLE [prefix_surveys] ADD [listpublic] CHAR(1) DEFAULT 'N'"); echo $modifyoutput; flush();ob_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();ob_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();ob_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();ob_flush();
|
||||
modify_database("","update [prefix_questions] set [language]='$newlang' where [language]='$oldlang'");echo $modifyoutput;flush();ob_flush();
|
||||
modify_database("","update [prefix_groups] set [language]='$newlang' where [language]='$oldlang'");echo $modifyoutput;flush();ob_flush();
|
||||
modify_database("","update [prefix_labels] set [language]='$newlang' where [language]='$oldlang'");echo $modifyoutput;flush();ob_flush();
|
||||
modify_database("","update [prefix_surveys] set [language]='$newlang' where [language]='$oldlang'");echo $modifyoutput;flush();ob_flush();
|
||||
modify_database("","update [prefix_surveys_languagesettings] set [surveyls_language]='$newlang' where surveyls_language='$oldlang'");echo $modifyoutput;flush();ob_flush();
|
||||
modify_database("","update [prefix_users] set [lang]='$newlang' where lang='$oldlang'");echo $modifyoutput;flush();ob_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();ob_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();ob_flush();}
|
||||
}
|
||||
|
||||
modify_database("","ALTER TABLE [prefix_surveys] ADD [htmlemail] CHAR(1) DEFAULT 'N'"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","ALTER TABLE [prefix_surveys] ADD [usecaptcha] CHAR(1) DEFAULT 'N'"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","ALTER TABLE [prefix_surveys] ADD [tokenanswerspersistence] CHAR(1) DEFAULT 'N'"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","ALTER TABLE [prefix_users] ADD [htmleditormode] CHAR(7) DEFAULT 'default'"); echo $modifyoutput; flush();ob_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();ob_flush();
|
||||
modify_database("","CREATE TABLE [prefix_templates] (
|
||||
[folder] varchar(255) NOT NULL,
|
||||
[creator] int NOT NULL,
|
||||
PRIMARY KEY ([folder])
|
||||
);");echo $modifyoutput; flush();ob_flush();
|
||||
//123
|
||||
modify_database("","ALTER TABLE [prefix_conditions] ALTER COLUMN [value] VARCHAR(255)"); echo $modifyoutput; flush();ob_flush();
|
||||
mssql_drop_constraint('title','labels');
|
||||
modify_database("","ALTER TABLE [prefix_labels] ALTER COLUMN [title] varchar(4000)"); echo $modifyoutput; flush();ob_flush();
|
||||
//124
|
||||
modify_database("","ALTER TABLE [prefix_surveys] ADD [bounce_email] text"); echo $modifyoutput; flush();ob_flush();
|
||||
//125
|
||||
upgrade_token_tables125();
|
||||
modify_database("","EXEC sp_rename 'prefix_users.move_user','superadmin'"); echo $modifyoutput; flush();ob_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();ob_flush();
|
||||
//126
|
||||
modify_database("","ALTER TABLE [prefix_questions] ADD [lid1] int NOT NULL DEFAULT '0'"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","UPDATE [prefix_conditions] SET [method]='==' where ( [method] is null) or [method]='' or [method]='0'"); echo $modifyoutput; flush();ob_flush();
|
||||
|
||||
modify_database("","update [prefix_settings_global] set [stg_value]='126' where stg_name='DBVersion'"); echo $modifyoutput; flush();ob_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();ob_flush();
|
||||
}
|
||||
|
||||
if ($oldversion < 128) {
|
||||
upgrade_token_tables128();
|
||||
modify_database("","update [prefix_settings_global] set [stg_value]='128' where stg_name='DBVersion'"); echo $modifyoutput; flush();ob_flush();
|
||||
}
|
||||
|
||||
if ($oldversion < 129) {
|
||||
//128
|
||||
modify_database("","ALTER TABLE [prefix_surveys] ADD [startdate] DATETIME"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","ALTER TABLE [prefix_surveys] ADD [usestartdate] char(1) NOT NULL default 'N'"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","update [prefix_settings_global] set [stg_value]='129' where stg_name='DBVersion'"); echo $modifyoutput; flush();ob_flush();
|
||||
}
|
||||
if ($oldversion < 130)
|
||||
{
|
||||
modify_database("","ALTER TABLE [prefix_conditions] ADD [scenario] int NOT NULL DEFAULT '1'"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","UPDATE [prefix_conditions] SET [scenario]=1 where ( [scenario] is null) or [scenario]='' or [scenario]=0"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","update [prefix_settings_global] set [stg_value]='130' where stg_name='DBVersion'"); echo $modifyoutput; flush();ob_flush();
|
||||
}
|
||||
if ($oldversion < 131)
|
||||
{
|
||||
modify_database("","ALTER TABLE [prefix_surveys] ADD [publicstatistics] char(1) NOT NULL default 'N'"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","update [prefix_settings_global] set [stg_value]='131' where stg_name='DBVersion'"); echo $modifyoutput; flush();ob_flush();
|
||||
}
|
||||
if ($oldversion < 132)
|
||||
{
|
||||
modify_database("","ALTER TABLE [prefix_surveys] ADD [publicgraphs] char(1) NOT NULL default 'N'"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","update [prefix_settings_global] set [stg_value]='132' where stg_name='DBVersion'"); echo $modifyoutput; flush();ob_flush();
|
||||
}
|
||||
|
||||
if ($oldversion < 133)
|
||||
{
|
||||
modify_database("","ALTER TABLE [prefix_users] ADD [one_time_pw] text"); echo $modifyoutput; flush();ob_flush();
|
||||
// Add new assessment setting
|
||||
modify_database("","ALTER TABLE [prefix_surveys] ADD [assessments] char(1) NOT NULL default 'N'"); echo $modifyoutput; flush();ob_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();ob_flush();
|
||||
modify_database("","ALTER TABLE [prefix_labels] ADD [assessment_value] int NOT NULL default '0'"); echo $modifyoutput; flush();ob_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();ob_flush();
|
||||
// add language field to assessment table
|
||||
modify_database("","ALTER TABLE [prefix_assessments] ADD [language] varchar(20) NOT NULL default 'en'"); echo $modifyoutput; flush();ob_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();ob_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();ob_flush();
|
||||
// drop the old link field
|
||||
modify_database("","ALTER TABLE [prefix_assessments] DROP COLUMN [link]"); echo $modifyoutput; flush();ob_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();ob_flush();
|
||||
modify_database("","ALTER TABLE [prefix_surveys_languagesettings] ADD [surveyls_endtext] text"); echo $modifyoutput; flush();ob_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();ob_flush();
|
||||
// drop old URL field
|
||||
mssql_drop_constraint('url','surveys');
|
||||
modify_database("","ALTER TABLE [prefix_surveys] DROP COLUMN [url]"); echo $modifyoutput; flush();ob_flush();
|
||||
|
||||
modify_database("","update [prefix_settings_global] set [stg_value]='133' where stg_name='DBVersion'"); echo $modifyoutput; flush();ob_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();ob_flush();
|
||||
mssql_drop_constraint('attribute1','surveys');
|
||||
mssql_drop_constraint('attribute2','surveys');
|
||||
modify_database("", "ALTER TABLE [prefix_surveys] ADD [attributedescriptions] TEXT;"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","ALTER TABLE [prefix_surveys] DROP COLUMN [attribute1]"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","ALTER TABLE [prefix_surveys] DROP COLUMN [attribute2]"); echo $modifyoutput; flush();ob_flush();
|
||||
upgrade_token_tables134();
|
||||
modify_database("","update [prefix_settings_global] set [stg_value]='134' where stg_name='DBVersion'"); echo $modifyoutput; flush();ob_flush();
|
||||
}
|
||||
if ($oldversion < 135)
|
||||
{
|
||||
mssql_drop_constraint('value','question_attributes');
|
||||
modify_database("","ALTER TABLE [prefix_question_attributes] ALTER COLUMN [value] text"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","ALTER TABLE [prefix_answers] ALTER COLUMN [answer] varchar(8000)"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","update [prefix_settings_global] set [stg_value]='135' where stg_name='DBVersion'"); echo $modifyoutput; flush();ob_flush();
|
||||
}
|
||||
if ($oldversion < 136) //New quota functions
|
||||
{
|
||||
modify_database("", "ALTER TABLE[prefix_quota] ADD [autoload_url] int NOT NULL default '0'"); echo $modifyoutput; flush();ob_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();ob_flush();
|
||||
modify_database("","update [prefix_settings_global] set [stg_value]='136' where stg_name='DBVersion'"); echo $modifyoutput; flush();ob_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();ob_flush();
|
||||
modify_database("", "ALTER TABLE [prefix_users] ADD [dateformat] int NOT NULL default '1'"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "update [prefix_surveys] set startdate=null where usestartdate='N'"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "update [prefix_surveys] set expires=null where useexpiry='N'"); echo $modifyoutput; flush();ob_flush();
|
||||
mssql_drop_constraint('usestartdate','surveys');
|
||||
mssql_drop_constraint('useexpiry','surveys');
|
||||
modify_database("", "ALTER TABLE [prefix_surveys] DROP COLUMN usestartdate"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "ALTER TABLE [prefix_surveys] DROP COLUMN useexpiry"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","update [prefix_settings_global] set [stg_value]='137' where stg_name='DBVersion'"); echo $modifyoutput; flush();ob_flush();
|
||||
}
|
||||
|
||||
if ($oldversion < 138) //Modify quota field
|
||||
{
|
||||
modify_database("", "ALTER TABLE [prefix_quota_members] ALTER COLUMN [code] VARCHAR(11) NULL"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "UPDATE [prefix_settings_global] SET [stg_value]='138' WHERE stg_name='DBVersion'"); echo $modifyoutput; flush();ob_flush();
|
||||
}
|
||||
|
||||
if ($oldversion < 139) //Modify quota field
|
||||
{
|
||||
upgrade_survey_tables139();
|
||||
modify_database("", "UPDATE [prefix_settings_global] SET [stg_value]='139' WHERE stg_name='DBVersion'"); echo $modifyoutput; flush();ob_flush();
|
||||
}
|
||||
|
||||
if ($oldversion < 140) //Modify surveys table
|
||||
{
|
||||
modify_database("", "ALTER TABLE [prefix_surveys] ADD [emailresponseto] text"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "UPDATE [prefix_settings_global] SET [stg_value]='140' WHERE stg_name='DBVersion'"); echo $modifyoutput; flush();ob_flush();
|
||||
}
|
||||
|
||||
if ($oldversion < 141) //Modify surveys table
|
||||
{
|
||||
modify_database("", "ALTER TABLE [prefix_surveys] ADD [tokenlength] tinyint NOT NULL default '15'"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "UPDATE [prefix_settings_global] SET [stg_value]='141' WHERE stg_name='DBVersion'"); echo $modifyoutput; flush();ob_flush();
|
||||
}
|
||||
|
||||
if ($oldversion < 142) //Modify surveys table
|
||||
{
|
||||
upgrade_question_attributes142();
|
||||
modify_database("", "ALTER TABLE [prefix_surveys] ALTER COLUMN [startdate] datetime NULL"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "ALTER TABLE [prefix_surveys] ALTER COLUMN [expires] datetime NULL"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "UPDATE [prefix_question_attributes] SET [value]='0' WHERE cast([value] as varchar)='false'"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "UPDATE [prefix_question_attributes] SET [value]='1' WHERE cast([value] as varchar)='true'"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "UPDATE [prefix_settings_global] SET [stg_value]='142' WHERE stg_name='DBVersion'"); echo $modifyoutput; flush();ob_flush();
|
||||
}
|
||||
|
||||
if ($oldversion < 143) //Modify surveys table
|
||||
{
|
||||
modify_database("", "ALTER TABLE [prefix_questions] ADD parent_qid integer NOT NULL default '0'"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "ALTER TABLE [prefix_answers] ADD scale_id tinyint NOT NULL default '0'"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "ALTER TABLE [prefix_questions] ADD scale_id tinyint NOT NULL default '0'"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "ALTER TABLE [prefix_questions] ADD same_default tinyint NOT NULL default '0'"); echo $modifyoutput; flush();ob_flush();
|
||||
mssql_drop_primary_index('answers');
|
||||
modify_database("","ALTER TABLE [prefix_answers] ADD CONSTRAINT pk_answers_qcls PRIMARY KEY ([qid],[code],[language],[scale_id])"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "CREATE TABLE [prefix_defaultvalues] (
|
||||
[qid] integer NOT NULL default '0',
|
||||
[scale_id] tinyint NOT NULL default '0',
|
||||
[sqid] integer NOT NULL default '0',
|
||||
[language] varchar(20) NOT NULL,
|
||||
[specialtype] varchar(20) NOT NULL default '',
|
||||
[defaultvalue] text,
|
||||
CONSTRAINT pk_defaultvalues_qlss PRIMARY KEY ([qid] , [scale_id], [language], [specialtype], [sqid]))"); echo $modifyoutput; flush();ob_flush();
|
||||
|
||||
// -Move all 'answers' that are subquestions to the questions table
|
||||
// -Move all 'labels' that are answers to the answers table
|
||||
// -Transscribe the default values where applicable
|
||||
// -Move default values from answers to questions
|
||||
upgrade_tables143();
|
||||
|
||||
mssql_drop_constraint('default_value','answers');
|
||||
modify_database("", "ALTER TABLE [prefix_answers] DROP COLUMN [default_value]"); echo $modifyoutput; flush();ob_flush();
|
||||
mssql_drop_constraint('lid','questions');
|
||||
modify_database("", "ALTER TABLE [prefix_questions] DROP COLUMN lid"); echo $modifyoutput; flush();ob_flush();
|
||||
mssql_drop_constraint('lid1','questions');
|
||||
modify_database("", "ALTER TABLE [prefix_questions] DROP COLUMN lid1"); echo $modifyoutput; flush();ob_flush();
|
||||
// add field for timings and table for extended conditions
|
||||
modify_database("", "ALTER TABLE [prefix_surveys] ADD savetimings char(1) default 'N'"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "CREATE TABLE prefix_sessions(
|
||||
sesskey VARCHAR( 64 ) NOT NULL DEFAULT '',
|
||||
expiry DATETIME NOT NULL ,
|
||||
expireref VARCHAR( 250 ) DEFAULT '',
|
||||
created DATETIME NOT NULL ,
|
||||
modified DATETIME NOT NULL ,
|
||||
sessdata text,
|
||||
CONSTRAINT pk_sessions_sesskey PRIMARY KEY ( [sesskey] ))"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "create index [idx_expiry] on [prefix_sessions] ([expiry])"); echo $modifyoutput;
|
||||
modify_database("", "create index [idx_expireref] on [prefix_sessions] ([expireref])"); echo $modifyoutput;
|
||||
modify_database("", "UPDATE [prefix_settings_global] SET stg_value='143' WHERE stg_name='DBVersion'"); echo $modifyoutput; flush();ob_flush();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
if ($oldversion < 145) //Modify surveys table
|
||||
{
|
||||
modify_database("", "ALTER TABLE [prefix_surveys] ADD showXquestions CHAR(1) NULL default 'Y'"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "ALTER TABLE [prefix_surveys] ADD showgroupinfo CHAR(1) NULL default 'B'"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "ALTER TABLE [prefix_surveys] ADD shownoanswer CHAR(1) NULL default 'Y'"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "ALTER TABLE [prefix_surveys] ADD showqnumcode CHAR(1) NULL default 'X'"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "ALTER TABLE [prefix_surveys] ADD bouncetime BIGINT NULL"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "ALTER TABLE [prefix_surveys] ADD bounceprocessing VARCHAR(1) NULL default 'N'"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "ALTER TABLE [prefix_surveys] ADD bounceaccounttype VARCHAR(4) NULL"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "ALTER TABLE [prefix_surveys] ADD bounceaccounthost VARCHAR(200) NULL "); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "ALTER TABLE [prefix_surveys] ADD bounceaccountpass VARCHAR(100) NULL"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "ALTER TABLE [prefix_surveys] ADD bounceaccountencryption VARCHAR(3) NULL"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "ALTER TABLE [prefix_surveys] ADD bounceaccountuser VARCHAR(200) NULL"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "ALTER TABLE [prefix_surveys] ADD showwelcome CHAR(1) NULL default 'Y'"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "ALTER TABLE [prefix_surveys] ADD showprogress CHAR(1) NULL default 'Y'"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "ALTER TABLE [prefix_surveys] ADD allowjumps CHAR(1) NULL default 'N'"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "ALTER TABLE [prefix_surveys] ADD navigationdelay tinyint NOT NULL default '0'"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "ALTER TABLE [prefix_surveys] ADD nokeyboard CHAR(1) NULL default 'N'"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "ALTER TABLE [prefix_surveys] ADD alloweditaftercompletion CHAR(1) NULL default 'N'"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "CREATE TABLE [prefix_survey_permissions] (
|
||||
[sid] INT NOT NULL,
|
||||
[uid] INT NOT NULL,
|
||||
[permission] VARCHAR(20) NOT NULL,
|
||||
[create_p] TINYINT NOT NULL default '0',
|
||||
[read_p] TINYINT NOT NULL default '0',
|
||||
[update_p] TINYINT NOT NULL default '0',
|
||||
[delete_p] TINYINT NOT NULL default '0',
|
||||
[import_p] TINYINT NOT NULL default '0',
|
||||
[export_p] TINYINT NOT NULL default '0',
|
||||
PRIMARY KEY ([sid], [uid],[permission])
|
||||
);"); echo $modifyoutput; flush();ob_flush();
|
||||
upgrade_surveypermissions_table145();
|
||||
modify_database("", "DROP TABLE [prefix_surveys_rights]"); echo $modifyoutput; flush();ob_flush();
|
||||
|
||||
// Add new fields for email templates
|
||||
modify_database("", "ALTER TABLE prefix_surveys_languagesettings ADD
|
||||
email_admin_notification_subj VARCHAR(255) NULL,
|
||||
email_admin_notification TEXT NULL,
|
||||
email_admin_responses_subj VARCHAR(255) NULL,
|
||||
email_admin_responses TEXT NULL");
|
||||
|
||||
//Add index to questions table to speed up subquestions
|
||||
modify_database("", "create index [parent_qid_idx] on [prefix_questions] ([parent_qid])"); echo $modifyoutput; flush();ob_flush();
|
||||
|
||||
modify_database("", "ALTER TABLE prefix_surveys ADD emailnotificationto text DEFAULT NULL"); echo $modifyoutput; flush();ob_flush();
|
||||
upgrade_survey_table145();
|
||||
mssql_drop_constraint('notification','surveys');
|
||||
modify_database("", "ALTER TABLE [prefix_surveys] DROP COLUMN [notification]"); echo $modifyoutput; flush();ob_flush();
|
||||
|
||||
// modify length of method in conditions
|
||||
modify_database("","ALTER TABLE [prefix_conditions] ALTER COLUMN [method] CHAR( 5 ) NOT NULL"); echo $modifyoutput; flush();ob_flush();
|
||||
|
||||
//Add index to questions table to speed up subquestions
|
||||
modify_database("", "create index [parent_qid] on [prefix_questions] ([parent_qid])"); echo $modifyoutput; flush();ob_flush();
|
||||
|
||||
modify_database("","UPDATE prefix_surveys set [private]='N' where [private] is NULL;"); echo $modifyoutput; flush();ob_flush();
|
||||
|
||||
modify_database("","EXEC sp_rename 'prefix_surveys.private','anonymized'"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","ALTER TABLE [prefix_surveys] ALTER COLUMN [anonymized] char(1) NOT NULL;"); echo $modifyoutput; flush();ob_flush();
|
||||
mssql_drop_constraint('anonymized','surveys');
|
||||
modify_database("","ALTER TABLE [prefix_surveys] ADD CONSTRAINT DF_surveys_anonymized DEFAULT 'N' FOR [anonymized];"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "CREATE TABLE [prefix_failed_login_attempts] (
|
||||
[id] INT NOT NULL IDENTITY (1,1) PRIMARY KEY,
|
||||
[ip] varchar(37) NOT NULL,
|
||||
[last_attempt] varchar(20) NOT NULL,
|
||||
[number_attempts] int NOT NULL );"); echo $modifyoutput; flush();ob_flush();
|
||||
|
||||
modify_database("", "ALTER TABLE [prefix_surveys_languagesettings] ADD [surveyls_numberformat] INT default 0 NOT NULL"); echo $modifyoutput; flush();ob_flush();
|
||||
|
||||
upgrade_token_tables145();
|
||||
modify_database("", "UPDATE [prefix_settings_global] SET stg_value='145' WHERE stg_name='DBVersion'"); echo $modifyoutput; flush();ob_flush();
|
||||
|
||||
|
||||
}
|
||||
if ($oldversion < 146) //Modify surveys table
|
||||
{
|
||||
upgrade_timing_tables146();
|
||||
modify_database("", "UPDATE [prefix_settings_global] SET stg_value='146' WHERE stg_name='DBVersion'"); echo $modifyoutput; flush();ob_flush();
|
||||
}
|
||||
|
||||
|
||||
echo '<br /><br />'.sprintf($clang->gT('Database update finished (%s)'),date('Y-m-d H:i:s')).'<br />';
|
||||
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();ob_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();ob_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();ob_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();ob_flush();
|
||||
modify_database("","ALTER TABLE ".$sv." ADD [remindercount] int DEFAULT '0'"); echo $modifyoutput; flush();ob_flush();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function upgrade_survey_tables133a()
|
||||
{
|
||||
global $dbprefix, $connect, $modifyoutput;
|
||||
mssql_drop_primary_index('assessments');
|
||||
// add the new primary key
|
||||
modify_database("","ALTER TABLE [prefix_assessments] ADD CONSTRAINT pk_assessments_id_lang PRIMARY KEY ([id],[language])"); echo $modifyoutput; flush();ob_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();ob_flush();
|
||||
modify_database("","ALTER TABLE ".$sv." ADD [validuntil] DATETIME"); echo $modifyoutput; flush();ob_flush();
|
||||
}
|
||||
}
|
||||
|
||||
// Add the usesleft field to all existing token tables
|
||||
function upgrade_token_tables145()
|
||||
{
|
||||
global $modifyoutput, $dbprefix, $connect;
|
||||
$surveyidquery = db_select_tables_like($dbprefix."tokens%");
|
||||
$surveyidresult = db_execute_num($surveyidquery);
|
||||
$tokentables=$connect->MetaTables('TABLES',false, $dbprefix."tokens%");
|
||||
foreach ($tokentables as $sv) {
|
||||
modify_database("","ALTER TABLE ".$sv." ADD [usesleft] int NOT NULL DEFAULT '1'"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","UPDATE ".$sv." SET usesleft=0 WHERE completed<>'N'"); echo $modifyoutput; flush();ob_flush();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function mssql_drop_primary_index($tablename)
|
||||
{
|
||||
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}{$tablename}') AND (CONSTRAINT_TYPE = 'PRIMARY KEY')";
|
||||
|
||||
$primarykey=$connect->GetOne($pkquery);
|
||||
if ($primarykey!=false)
|
||||
{
|
||||
modify_database("","ALTER TABLE [prefix_{$tablename}] DROP CONSTRAINT {$primarykey}"); echo $modifyoutput; flush();ob_flush();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function mssql_drop_constraint($fieldname, $tablename)
|
||||
{
|
||||
global $dbprefix, $connect, $modifyoutput;
|
||||
$connect->SetFetchMode(ADODB_FETCH_ASSOC);
|
||||
|
||||
// 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?
|
||||
$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['constraint_name']}"); echo $modifyoutput; flush();ob_flush();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
function upgrade_survey_tables139()
|
||||
{
|
||||
global $modifyoutput,$dbprefix;
|
||||
$surveyidquery = db_select_tables_like($dbprefix."survey\_%");
|
||||
$surveyidresult = db_execute_num($surveyidquery);
|
||||
if (!$surveyidresult) {return "Database Error";}
|
||||
else
|
||||
{
|
||||
while ( $sv = $surveyidresult->FetchRow() )
|
||||
{
|
||||
modify_database("","ALTER TABLE ".$sv[0]." ADD [lastpage] int"); echo $modifyoutput; flush();ob_flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function upgrade_question_attributes142()
|
||||
{
|
||||
global $modifyoutput,$dbprefix, $connect;
|
||||
$attributequery="Select qid from {$dbprefix}question_attributes where attribute='exclude_all_other' group by qid having count(qid)>1 ";
|
||||
$questionids = db_select_column($attributequery);
|
||||
foreach ($questionids as $questionid)
|
||||
{
|
||||
//Select all affected question attributes
|
||||
$attributevalues=db_select_column("SELECT value from {$dbprefix}question_attributes where attribute='exclude_all_other' and qid=".$questionid);
|
||||
modify_database("","delete from {$dbprefix}question_attributes where attribute='exclude_all_other' and qid=".$questionid); echo $modifyoutput; flush();ob_flush();
|
||||
$record['value']=implode(';',$attributevalues);
|
||||
$record['attribute']='exclude_all_other';
|
||||
$record['qid']=$questionid;
|
||||
$connect->AutoExecute("{$dbprefix}question_attributes", $record, 'INSERT');
|
||||
}
|
||||
}
|
||||
|
||||
function upgrade_tables143()
|
||||
{
|
||||
global $modifyoutput,$dbprefix, $connect;
|
||||
|
||||
|
||||
$aQIDReplacements=array();
|
||||
$answerquery = "select a.*, q.sid, q.gid from {$dbprefix}answers a,{$dbprefix}questions q where a.qid=q.qid and q.type in ('L','O','!') and a.default_value='Y'";
|
||||
$answerresult = db_execute_assoc($answerquery);
|
||||
if (!$answerresult) {return "Database Error";}
|
||||
else
|
||||
{
|
||||
while ( $row = $answerresult->FetchRow() )
|
||||
{
|
||||
modify_database("","INSERT INTO {$dbprefix}defaultvalues (qid, scale_id,language,specialtype,defaultvalue) VALUES ({$row['qid']},0,".db_quoteall($row['language']).",'',".db_quoteall($row['code']).")"); echo $modifyoutput; flush();ob_flush();
|
||||
}
|
||||
}
|
||||
|
||||
// Convert answers to subquestions
|
||||
|
||||
$answerquery = "select a.*, q.sid, q.gid, q.type from {$dbprefix}answers a,{$dbprefix}questions q where a.qid=q.qid and a.language=q.language and q.type in ('1','A','B','C','E','F','H','K',';',':','M','P','Q')";
|
||||
$answerresult = db_execute_assoc($answerquery);
|
||||
if (!$answerresult) {return "Database Error";}
|
||||
else
|
||||
{
|
||||
while ( $row = $answerresult->FetchRow() )
|
||||
{
|
||||
|
||||
$insertarray=array();
|
||||
if (isset($aQIDReplacements[$row['qid'].'_'.$row['code']]))
|
||||
{
|
||||
$insertarray['qid']=$aQIDReplacements[$row['qid'].'_'.$row['code']];
|
||||
db_switchIDInsert('questions',true);
|
||||
}
|
||||
$insertarray['sid']=$row['sid'];
|
||||
$insertarray['gid']=$row['gid'];
|
||||
$insertarray['parent_qid']=$row['qid'];
|
||||
$insertarray['type']=$row['type'];
|
||||
$insertarray['title']=$row['code'];
|
||||
$insertarray['question']=$row['answer'];
|
||||
$insertarray['question_order']=$row['sortorder'];
|
||||
$insertarray['language']=$row['language'];
|
||||
$tablename="{$dbprefix}questions";
|
||||
$query=$connect->GetInsertSQL($tablename,$insertarray);
|
||||
modify_database("",$query); echo $modifyoutput; flush();ob_flush();
|
||||
if (!isset($insertarray['qid']))
|
||||
{
|
||||
$aQIDReplacements[$row['qid'].'_'.$row['code']]=$connect->Insert_ID("{$dbprefix}questions","qid");
|
||||
$iSaveSQID=$aQIDReplacements[$row['qid'].'_'.$row['code']];
|
||||
}
|
||||
else
|
||||
{
|
||||
$iSaveSQID=$insertarray['qid'];
|
||||
db_switchIDInsert('questions',false);
|
||||
}
|
||||
if (($row['type']=='M' || $row['type']=='P') && $row['default_value']=='Y')
|
||||
{
|
||||
modify_database("","INSERT INTO {$dbprefix}defaultvalues (qid, sqid, scale_id,language,specialtype,defaultvalue) VALUES ({$row['qid']},{$iSaveSQID},0,".db_quoteall($row['language']).",'','Y')"); echo $modifyoutput; flush();ob_flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
modify_database("","delete {$dbprefix}answers from {$dbprefix}answers LEFT join {$dbprefix}questions ON {$dbprefix}answers.qid={$dbprefix}questions.qid where {$dbprefix}questions.type in ('1','F','H','M','P','W','Z')"); echo $modifyoutput; flush();ob_flush();
|
||||
|
||||
// Convert labels to answers
|
||||
$answerquery = "select qid ,type ,lid ,lid1, language from {$dbprefix}questions where parent_qid=0 and type in ('1','F','H','M','P','W','Z')";
|
||||
$answerresult = db_execute_assoc($answerquery);
|
||||
if (!$answerresult)
|
||||
{
|
||||
return "Database Error";
|
||||
}
|
||||
else
|
||||
{
|
||||
while ( $row = $answerresult->FetchRow() )
|
||||
{
|
||||
$labelquery="Select * from {$dbprefix}labels where lid={$row['lid']} and language=".db_quoteall($row['language']);
|
||||
$labelresult = db_execute_assoc($labelquery);
|
||||
while ( $lrow = $labelresult->FetchRow() )
|
||||
{
|
||||
modify_database("","INSERT INTO {$dbprefix}answers (qid, code, answer, sortorder, language, assessment_value) VALUES ({$row['qid']},".db_quoteall($lrow['code']).",".db_quoteall($lrow['title']).",{$lrow['sortorder']},".db_quoteall($lrow['language']).",{$lrow['assessment_value']})"); echo $modifyoutput; flush();ob_flush();
|
||||
//$labelids[]
|
||||
}
|
||||
if ($row['type']=='1')
|
||||
{
|
||||
$labelquery="Select * from {$dbprefix}labels where lid={$row['lid1']} and language=".db_quoteall($row['language']);
|
||||
$labelresult = db_execute_assoc($labelquery);
|
||||
while ( $lrow = $labelresult->FetchRow() )
|
||||
{
|
||||
modify_database("","INSERT INTO {$dbprefix}answers (qid, code, answer, sortorder, language, scale_id, assessment_value) VALUES ({$row['qid']},".db_quoteall($lrow['code']).",".db_quoteall($lrow['title']).",{$lrow['sortorder']},".db_quoteall($lrow['language']).",1,{$lrow['assessment_value']})"); echo $modifyoutput; flush();ob_flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Convert labels to subquestions
|
||||
$answerquery = "select * from {$dbprefix}questions where parent_qid=0 and type in (';',':')";
|
||||
$answerresult = db_execute_assoc($answerquery);
|
||||
if (!$answerresult)
|
||||
{
|
||||
return "Database Error";
|
||||
}
|
||||
else
|
||||
{
|
||||
while ( $row = $answerresult->FetchRow() )
|
||||
{
|
||||
$labelquery="Select * from {$dbprefix}labels where lid={$row['lid']} and language=".db_quoteall($row['language']);
|
||||
$labelresult = db_execute_assoc($labelquery);
|
||||
while ( $lrow = $labelresult->FetchRow() )
|
||||
{
|
||||
$insertarray=array();
|
||||
if (isset($aQIDReplacements[$row['qid'].'_'.$lrow['code'].'_1']))
|
||||
{
|
||||
$insertarray['qid']=$aQIDReplacements[$row['qid'].'_'.$lrow['code'].'_1'];
|
||||
db_switchIDInsert('questions',true);
|
||||
|
||||
}
|
||||
$insertarray['sid']=$row['sid'];
|
||||
$insertarray['gid']=$row['gid'];
|
||||
$insertarray['type']=$row['type'];
|
||||
$insertarray['parent_qid']=$row['qid'];
|
||||
$insertarray['title']=$lrow['code'];
|
||||
$insertarray['question']=$lrow['title'];
|
||||
$insertarray['question_order']=$lrow['sortorder'];
|
||||
$insertarray['language']=$lrow['language'];
|
||||
$insertarray['scale_id']=1;
|
||||
$tablename="{$dbprefix}questions";
|
||||
$query=$connect->GetInsertSQL($tablename,$insertarray);
|
||||
modify_database("",$query); echo $modifyoutput; flush();ob_flush();
|
||||
if (isset($insertarray['qid']))
|
||||
{
|
||||
$aQIDReplacements[$row['qid'].'_'.$lrow['code'].'_1']=$connect->Insert_ID("{$dbprefix}questions","qid");
|
||||
db_switchIDInsert('questions',false);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$updatequery = "update {$dbprefix}questions set type='!' where type='W'";
|
||||
modify_database("",$updatequery); echo $modifyoutput; flush();ob_flush();
|
||||
$updatequery = "update {$dbprefix}questions set type='L' where type='Z'";
|
||||
modify_database("",$updatequery); echo $modifyoutput; flush();ob_flush();
|
||||
|
||||
// Now move all non-standard templates to the /upload dir
|
||||
global $usertemplaterootdir, $standardtemplates,$standardtemplaterootdir;
|
||||
|
||||
if (!$usertemplaterootdir) {die("gettemplatelist() no template directory");}
|
||||
if ($handle = opendir($standardtemplaterootdir))
|
||||
{
|
||||
while (false !== ($file = readdir($handle)))
|
||||
{
|
||||
if (!is_file("$standardtemplaterootdir/$file") && $file != "." && $file != ".." && $file!=".svn" && !isStandardTemplate($file))
|
||||
{
|
||||
if (!rename($standardtemplaterootdir.DIRECTORY_SEPARATOR.$file,$usertemplaterootdir.DIRECTORY_SEPARATOR.$file))
|
||||
{
|
||||
echo "There was a problem moving directory '".$standardtemplaterootdir.DIRECTORY_SEPARATOR.$file."' to '".$usertemplaterootdir.DIRECTORY_SEPARATOR.$file."' due to missing permissions. Please do this manually.<br />";
|
||||
};
|
||||
}
|
||||
}
|
||||
closedir($handle);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function upgrade_timing_tables146()
|
||||
{
|
||||
global $modifyoutput,$dbprefix, $connect;
|
||||
$aTimingTables=$connect->MetaTables('TABLES',false, "%timings");
|
||||
foreach ($aTimingTables as $sTable) {
|
||||
modify_database("","EXEC sp_rename '{$sTable}.interviewTime','interviewtime'"); echo $modifyoutput; flush(); ob_flush();
|
||||
}
|
||||
}
|
||||
815
include/limesurvey/admin/update/upgrade-mssqlnative.php
Normal file
815
include/limesurvey/admin/update/upgrade-mssqlnative.php
Normal file
@@ -0,0 +1,815 @@
|
||||
<?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 7556 2009-09-01 23:48:37Z 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, $clang;
|
||||
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();ob_flush();
|
||||
modify_database("","update [prefix_questions] set [language]='$newlang' where language='$oldlang'");echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","update [prefix_groups] set [language]='$newlang' where language='$oldlang'");echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","update [prefix_labels] set [language]='$newlang' where language='$oldlang'");echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","update [prefix_surveys] set [language]='$newlang' where language='$oldlang'");echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","update [prefix_surveys_languagesettings] set [surveyls_language]='$newlang' where surveyls_language='$oldlang'");echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","update [prefix_users] set [lang]='$newlang where lang='$oldlang'");echo $modifyoutput; flush();ob_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();ob_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();ob_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();ob_flush();
|
||||
modify_database("","update [prefix_settings_global] set [stg_value]='112' where stg_name='DBVersion'"); echo $modifyoutput; flush();ob_flush();
|
||||
}
|
||||
|
||||
if ($oldversion < 113) {
|
||||
//No action needed
|
||||
modify_database("","update [prefix_settings_global] set [stg_value]='113' where stg_name='DBVersion'"); echo $modifyoutput; flush();ob_flush();
|
||||
}
|
||||
|
||||
if ($oldversion < 114) {
|
||||
modify_database("","ALTER TABLE [prefix_saved_control] ALTER COLUMN [email] VARCHAR(320) NOT NULL"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","ALTER TABLE [prefix_surveys] ALTER COLUMN [adminemail] VARCHAR(320) NOT NULL"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","ALTER TABLE [prefix_users] ALTER COLUMN [email] VARCHAR(320) NOT NULL"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("",'INSERT INTO [prefix_settings_global] VALUES (\'SessionName\', \'$sessionname\');');echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","update [prefix_settings_global] set [stg_value]='114' where stg_name='DBVersion'"); echo $modifyoutput; flush();ob_flush();
|
||||
}
|
||||
|
||||
if ($oldversion < 126) {
|
||||
modify_database("","ALTER TABLE [prefix_surveys] ADD [printanswers] CHAR(1) DEFAULT 'N'"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","ALTER TABLE [prefix_surveys] ADD [listpublic] CHAR(1) DEFAULT 'N'"); echo $modifyoutput; flush();ob_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();ob_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();ob_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();ob_flush();
|
||||
modify_database("","update [prefix_questions] set [language]='$newlang' where [language]='$oldlang'");echo $modifyoutput;flush();ob_flush();
|
||||
modify_database("","update [prefix_groups] set [language]='$newlang' where [language]='$oldlang'");echo $modifyoutput;flush();ob_flush();
|
||||
modify_database("","update [prefix_labels] set [language]='$newlang' where [language]='$oldlang'");echo $modifyoutput;flush();ob_flush();
|
||||
modify_database("","update [prefix_surveys] set [language]='$newlang' where [language]='$oldlang'");echo $modifyoutput;flush();ob_flush();
|
||||
modify_database("","update [prefix_surveys_languagesettings] set [surveyls_language]='$newlang' where surveyls_language='$oldlang'");echo $modifyoutput;flush();ob_flush();
|
||||
modify_database("","update [prefix_users] set [lang]='$newlang' where lang='$oldlang'");echo $modifyoutput;flush();ob_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();ob_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();ob_flush();}
|
||||
}
|
||||
|
||||
modify_database("","ALTER TABLE [prefix_surveys] ADD [htmlemail] CHAR(1) DEFAULT 'N'"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","ALTER TABLE [prefix_surveys] ADD [usecaptcha] CHAR(1) DEFAULT 'N'"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","ALTER TABLE [prefix_surveys] ADD [tokenanswerspersistence] CHAR(1) DEFAULT 'N'"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","ALTER TABLE [prefix_users] ADD [htmleditormode] CHAR(7) DEFAULT 'default'"); echo $modifyoutput; flush();ob_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();ob_flush();
|
||||
modify_database("","CREATE TABLE [prefix_templates] (
|
||||
[folder] varchar(255) NOT NULL,
|
||||
[creator] int NOT NULL,
|
||||
PRIMARY KEY ([folder])
|
||||
);");echo $modifyoutput; flush();ob_flush();
|
||||
//123
|
||||
modify_database("","ALTER TABLE [prefix_conditions] ALTER COLUMN [value] VARCHAR(255)"); echo $modifyoutput; flush();ob_flush();
|
||||
mssql_drop_constraint('title','labels');
|
||||
modify_database("","ALTER TABLE [prefix_labels] ALTER COLUMN [title] varchar(4000)"); echo $modifyoutput; flush();ob_flush();
|
||||
//124
|
||||
modify_database("","ALTER TABLE [prefix_surveys] ADD [bounce_email] varchar(max)"); echo $modifyoutput; flush();ob_flush();
|
||||
//125
|
||||
upgrade_token_tables125();
|
||||
modify_database("","EXEC sp_rename 'prefix_users.move_user','superadmin'"); echo $modifyoutput; flush();ob_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();ob_flush();
|
||||
//126
|
||||
modify_database("","ALTER TABLE [prefix_questions] ADD [lid1] int NOT NULL DEFAULT '0'"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","UPDATE [prefix_conditions] SET [method]='==' where ( [method] is null) or [method]='' or [method]='0'"); echo $modifyoutput; flush();ob_flush();
|
||||
|
||||
modify_database("","update [prefix_settings_global] set [stg_value]='126' where stg_name='DBVersion'"); echo $modifyoutput; flush();ob_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();ob_flush();
|
||||
}
|
||||
|
||||
if ($oldversion < 128) {
|
||||
upgrade_token_tables128();
|
||||
modify_database("","update [prefix_settings_global] set [stg_value]='128' where stg_name='DBVersion'"); echo $modifyoutput; flush();ob_flush();
|
||||
}
|
||||
|
||||
if ($oldversion < 129) {
|
||||
//128
|
||||
modify_database("","ALTER TABLE [prefix_surveys] ADD [startdate] DATETIME"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","ALTER TABLE [prefix_surveys] ADD [usestartdate] char(1) NOT NULL default 'N'"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","update [prefix_settings_global] set [stg_value]='129' where stg_name='DBVersion'"); echo $modifyoutput; flush();ob_flush();
|
||||
}
|
||||
if ($oldversion < 130)
|
||||
{
|
||||
modify_database("","ALTER TABLE [prefix_conditions] ADD [scenario] int NOT NULL DEFAULT '1'"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","UPDATE [prefix_conditions] SET [scenario]=1 where ( [scenario] is null) or [scenario]='' or [scenario]=0"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","update [prefix_settings_global] set [stg_value]='130' where stg_name='DBVersion'"); echo $modifyoutput; flush();ob_flush();
|
||||
}
|
||||
if ($oldversion < 131)
|
||||
{
|
||||
modify_database("","ALTER TABLE [prefix_surveys] ADD [publicstatistics] char(1) NOT NULL default 'N'"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","update [prefix_settings_global] set [stg_value]='131' where stg_name='DBVersion'"); echo $modifyoutput; flush();ob_flush();
|
||||
}
|
||||
if ($oldversion < 132)
|
||||
{
|
||||
modify_database("","ALTER TABLE [prefix_surveys] ADD [publicgraphs] char(1) NOT NULL default 'N'"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","update [prefix_settings_global] set [stg_value]='132' where stg_name='DBVersion'"); echo $modifyoutput; flush();ob_flush();
|
||||
}
|
||||
|
||||
if ($oldversion < 133)
|
||||
{
|
||||
modify_database("","ALTER TABLE [prefix_users] ADD [one_time_pw] varchar(max)"); echo $modifyoutput; flush();ob_flush();
|
||||
// Add new assessment setting
|
||||
modify_database("","ALTER TABLE [prefix_surveys] ADD [assessments] char(1) NOT NULL default 'N'"); echo $modifyoutput; flush();ob_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();ob_flush();
|
||||
modify_database("","ALTER TABLE [prefix_labels] ADD [assessment_value] int NOT NULL default '0'"); echo $modifyoutput; flush();ob_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();ob_flush();
|
||||
// add language field to assessment table
|
||||
modify_database("","ALTER TABLE [prefix_assessments] ADD [language] varchar(20) NOT NULL default 'en'"); echo $modifyoutput; flush();ob_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();ob_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();ob_flush();
|
||||
// drop the old link field
|
||||
modify_database("","ALTER TABLE [prefix_assessments] DROP COLUMN [link]"); echo $modifyoutput; flush();ob_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();ob_flush();
|
||||
modify_database("","ALTER TABLE [prefix_surveys_languagesettings] ADD [surveyls_endtext] varchar(max)"); echo $modifyoutput; flush();ob_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();ob_flush();
|
||||
// drop old URL field
|
||||
mssql_drop_constraint('url','surveys');
|
||||
modify_database("","ALTER TABLE [prefix_surveys] DROP COLUMN [url]"); echo $modifyoutput; flush();ob_flush();
|
||||
|
||||
modify_database("","update [prefix_settings_global] set [stg_value]='133' where stg_name='DBVersion'"); echo $modifyoutput; flush();ob_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();ob_flush();
|
||||
mssql_drop_constraint('attribute1','surveys');
|
||||
mssql_drop_constraint('attribute2','surveys');
|
||||
modify_database("", "ALTER TABLE [prefix_surveys] ADD [attributedescriptions] varchar(max);"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","ALTER TABLE [prefix_surveys] DROP COLUMN [attribute1]"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","ALTER TABLE [prefix_surveys] DROP COLUMN [attribute2]"); echo $modifyoutput; flush();ob_flush();
|
||||
upgrade_token_tables134();
|
||||
modify_database("","update [prefix_settings_global] set [stg_value]='134' where stg_name='DBVersion'"); echo $modifyoutput; flush();ob_flush();
|
||||
}
|
||||
if ($oldversion < 135)
|
||||
{
|
||||
mssql_drop_constraint('value','question_attributes');
|
||||
modify_database("","ALTER TABLE [prefix_question_attributes] ALTER COLUMN [value] varchar(max)"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","ALTER TABLE [prefix_answers] ALTER COLUMN [answer] varchar(8000)"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","update [prefix_settings_global] set [stg_value]='135' where stg_name='DBVersion'"); echo $modifyoutput; flush();ob_flush();
|
||||
}
|
||||
if ($oldversion < 136) //New quota functions
|
||||
{
|
||||
modify_database("", "ALTER TABLE[prefix_quota] ADD [autoload_url] int NOT NULL default '0'"); echo $modifyoutput; flush();ob_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] varchar(max),
|
||||
[quotals_url] varchar(255),
|
||||
[quotals_urldescrip] varchar(255),
|
||||
PRIMARY KEY ([quotals_id])
|
||||
);");echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","update [prefix_settings_global] set [stg_value]='136' where stg_name='DBVersion'"); echo $modifyoutput; flush();ob_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();ob_flush();
|
||||
modify_database("", "ALTER TABLE [prefix_users] ADD [dateformat] int NOT NULL default '1'"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "update [prefix_surveys] set startdate=null where usestartdate='N'"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "update [prefix_surveys] set expires=null where useexpiry='N'"); echo $modifyoutput; flush();ob_flush();
|
||||
mssql_drop_constraint('usestartdate','surveys');
|
||||
mssql_drop_constraint('useexpiry','surveys');
|
||||
modify_database("", "ALTER TABLE [prefix_surveys] DROP COLUMN usestartdate"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "ALTER TABLE [prefix_surveys] DROP COLUMN useexpiry"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","update [prefix_settings_global] set [stg_value]='137' where stg_name='DBVersion'"); echo $modifyoutput; flush();ob_flush();
|
||||
}
|
||||
|
||||
if ($oldversion < 138) //Modify quota field
|
||||
{
|
||||
modify_database("", "ALTER TABLE [prefix_quota_members] ALTER COLUMN [code] VARCHAR(11) NULL"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "UPDATE [prefix_settings_global] SET [stg_value]='138' WHERE stg_name='DBVersion'"); echo $modifyoutput; flush();ob_flush();
|
||||
}
|
||||
|
||||
if ($oldversion < 139) //Modify quota field
|
||||
{
|
||||
upgrade_survey_tables139();
|
||||
modify_database("", "UPDATE [prefix_settings_global] SET [stg_value]='139' WHERE stg_name='DBVersion'"); echo $modifyoutput; flush();ob_flush();
|
||||
}
|
||||
|
||||
if ($oldversion < 140) //Modify surveys table
|
||||
{
|
||||
modify_database("", "ALTER TABLE [prefix_surveys] ADD [emailresponseto] varchar(max)"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "UPDATE [prefix_settings_global] SET [stg_value]='140' WHERE stg_name='DBVersion'"); echo $modifyoutput; flush();ob_flush();
|
||||
}
|
||||
|
||||
if ($oldversion < 141) //Modify surveys table
|
||||
{
|
||||
modify_database("", "ALTER TABLE [prefix_surveys] ADD [tokenlength] tinyint NOT NULL default '15'"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "UPDATE [prefix_settings_global] SET [stg_value]='141' WHERE stg_name='DBVersion'"); echo $modifyoutput; flush();ob_flush();
|
||||
}
|
||||
|
||||
if ($oldversion < 142) //Modify surveys table
|
||||
{
|
||||
upgrade_question_attributes142();
|
||||
modify_database("", "ALTER TABLE [prefix_surveys] ALTER COLUMN [startdate] datetime NULL"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "ALTER TABLE [prefix_surveys] ALTER COLUMN [expires] datetime NULL"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "UPDATE [prefix_question_attributes] SET [value]='0' WHERE cast([value] as varchar)='false'"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "UPDATE [prefix_question_attributes] SET [value]='1' WHERE cast([value] as varchar)='true'"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "UPDATE [prefix_settings_global] SET [stg_value]='142' WHERE stg_name='DBVersion'"); echo $modifyoutput; flush();ob_flush();
|
||||
}
|
||||
|
||||
if ($oldversion < 143) //Modify surveys table
|
||||
{
|
||||
modify_database("", "ALTER TABLE [prefix_questions] ADD parent_qid integer NOT NULL default '0'"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "ALTER TABLE [prefix_answers] ADD scale_id tinyint NOT NULL default '0'"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "ALTER TABLE [prefix_questions] ADD scale_id tinyint NOT NULL default '0'"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "ALTER TABLE [prefix_questions] ADD same_default tinyint NOT NULL default '0'"); echo $modifyoutput; flush();ob_flush();
|
||||
mssql_drop_primary_index('answers');
|
||||
modify_database("","ALTER TABLE [prefix_answers] ADD CONSTRAINT pk_answers_qcls PRIMARY KEY ([qid],[code],[language],[scale_id])"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "CREATE TABLE [prefix_defaultvalues] (
|
||||
[qid] integer NOT NULL default '0',
|
||||
[scale_id] tinyint NOT NULL default '0',
|
||||
[sqid] integer NOT NULL default '0',
|
||||
[language] varchar(20) NOT NULL,
|
||||
[specialtype] varchar(20) NOT NULL default '',
|
||||
[defaultvalue] varchar(max),
|
||||
CONSTRAINT pk_defaultvalues_qlss PRIMARY KEY ([qid] , [scale_id], [language], [specialtype], [sqid]))"); echo $modifyoutput; flush();ob_flush();
|
||||
|
||||
// -Move all 'answers' that are subquestions to the questions table
|
||||
// -Move all 'labels' that are answers to the answers table
|
||||
// -Transscribe the default values where applicable
|
||||
// -Move default values from answers to questions
|
||||
upgrade_tables143();
|
||||
|
||||
mssql_drop_constraint('default_value','answers');
|
||||
modify_database("", "ALTER TABLE [prefix_answers] DROP COLUMN [default_value]"); echo $modifyoutput; flush();ob_flush();
|
||||
mssql_drop_constraint('lid','questions');
|
||||
modify_database("", "ALTER TABLE [prefix_questions] DROP COLUMN lid"); echo $modifyoutput; flush();ob_flush();
|
||||
mssql_drop_constraint('lid1','questions');
|
||||
modify_database("", "ALTER TABLE [prefix_questions] DROP COLUMN lid1"); echo $modifyoutput; flush();ob_flush();
|
||||
// add field for timings and table for extended conditions
|
||||
modify_database("", "ALTER TABLE [prefix_surveys] ADD savetimings char(1) default 'N'"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "CREATE TABLE prefix_sessions(
|
||||
sesskey VARCHAR( 64 ) NOT NULL DEFAULT '',
|
||||
expiry DATETIME NOT NULL ,
|
||||
expireref VARCHAR( 250 ) DEFAULT '',
|
||||
created DATETIME NOT NULL ,
|
||||
modified DATETIME NOT NULL ,
|
||||
sessdata varchar(max),
|
||||
CONSTRAINT pk_sessions_sesskey PRIMARY KEY ( [sesskey] ))"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "create index [idx_expiry] on [prefix_sessions] ([expiry])"); echo $modifyoutput;
|
||||
modify_database("", "create index [idx_expireref] on [prefix_sessions] ([expireref])"); echo $modifyoutput;
|
||||
modify_database("", "UPDATE [prefix_settings_global] SET stg_value='143' WHERE stg_name='DBVersion'"); echo $modifyoutput; flush();ob_flush();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
if ($oldversion < 145) //Modify surveys table
|
||||
{
|
||||
modify_database("", "ALTER TABLE [prefix_surveys] ADD showXquestions CHAR(1) NULL default 'Y'"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "ALTER TABLE [prefix_surveys] ADD showgroupinfo CHAR(1) NULL default 'B' "); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "ALTER TABLE [prefix_surveys] ADD shownoanswer CHAR(1) NULL default 'Y' "); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "ALTER TABLE [prefix_surveys] ADD showqnumcode CHAR(1) NULL default 'X'"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "ALTER TABLE [prefix_surveys] ADD bouncetime BIGINT NULL"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "ALTER TABLE [prefix_surveys] ADD bounceprocessing VARCHAR(1) NULL default 'N'"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "ALTER TABLE [prefix_surveys] ADD bounceaccounttype VARCHAR(4) NULL "); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "ALTER TABLE [prefix_surveys] ADD bounceaccounthost VARCHAR(200) NULL "); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "ALTER TABLE [prefix_surveys] ADD bounceaccountpass VARCHAR(100) NULL "); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "ALTER TABLE [prefix_surveys] ADD bounceaccountencryption VARCHAR(3) NULL "); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "ALTER TABLE [prefix_surveys] ADD bounceaccountuser VARCHAR(200) NULL "); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "ALTER TABLE [prefix_surveys] ADD showwelcome CHAR(1) NULL default 'Y' "); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "ALTER TABLE [prefix_surveys] ADD showprogress CHAR(1) NULL default 'Y'"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "ALTER TABLE [prefix_surveys] ADD allowjumps CHAR(1) NULL default 'N'"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "ALTER TABLE [prefix_surveys] ADD navigationdelay tinyint NOT NULL default '0'"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "ALTER TABLE [prefix_surveys] ADD nokeyboard CHAR(1) NULL default 'N'"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "ALTER TABLE [prefix_surveys] ADD alloweditaftercompletion CHAR(1) NULL default 'N'"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "CREATE TABLE [prefix_survey_permissions] (
|
||||
[sid] INT NOT NULL,
|
||||
[uid] INT NOT NULL,
|
||||
[permission] VARCHAR(20) NOT NULL,
|
||||
[create_p] TINYINT NOT NULL default '0',
|
||||
[read_p] TINYINT NOT NULL default '0',
|
||||
[update_p] TINYINT NOT NULL default '0',
|
||||
[delete_p] TINYINT NOT NULL default '0',
|
||||
[import_p] TINYINT NOT NULL default '0',
|
||||
[export_p] TINYINT NOT NULL default '0',
|
||||
PRIMARY KEY ([sid], [uid],[permission])
|
||||
);"); echo $modifyoutput; flush();ob_flush();
|
||||
upgrade_surveypermissions_table145();
|
||||
modify_database("", "DROP TABLE [prefix_surveys_rights]"); echo $modifyoutput; flush();ob_flush();
|
||||
|
||||
// Add new fields for email templates
|
||||
modify_database("", "ALTER TABLE prefix_surveys_languagesettings ADD
|
||||
email_admin_notification_subj VARCHAR(255) NULL,
|
||||
email_admin_notification varchar(max) NULL,
|
||||
email_admin_responses_subj VARCHAR(255) NULL,
|
||||
email_admin_responses varchar(max) NULL");
|
||||
|
||||
//Add index to questions table to speed up subquestions
|
||||
modify_database("", "create index [parent_qid_idx] on [prefix_questions] ([parent_qid])"); echo $modifyoutput; flush();ob_flush();
|
||||
|
||||
modify_database("", "ALTER TABLE prefix_surveys ADD emailnotificationto text DEFAULT NULL"); echo $modifyoutput; flush();ob_flush();
|
||||
upgrade_survey_table145();
|
||||
mssql_drop_constraint('notification','surveys');
|
||||
modify_database("", "ALTER TABLE [prefix_surveys] DROP COLUMN [notification]"); echo $modifyoutput; flush();ob_flush();
|
||||
|
||||
// modify length of method in conditions
|
||||
modify_database("","ALTER TABLE [prefix_conditions] ALTER COLUMN [method] CHAR(5) NOT NULL"); echo $modifyoutput; flush();ob_flush();
|
||||
|
||||
//Add index to questions table to speed up subquestions
|
||||
modify_database("", "create index [parent_qid] on [prefix_questions] ([parent_qid])"); echo $modifyoutput; flush();ob_flush();
|
||||
|
||||
modify_database("","UPDATE prefix_surveys set [private]='N' where [private] is NULL;"); echo $modifyoutput; flush();ob_flush();
|
||||
|
||||
modify_database("","EXEC sp_rename 'prefix_surveys.private','anonymized'"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","ALTER TABLE [prefix_surveys] ALTER COLUMN [anonymized] char(1) NOT NULL;"); echo $modifyoutput; flush();ob_flush();
|
||||
mssql_drop_constraint('anonymized','surveys');
|
||||
modify_database("","ALTER TABLE [prefix_surveys] ADD CONSTRAINT DF_surveys_anonymized DEFAULT 'N' FOR [anonymized];"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "CREATE TABLE [prefix_failed_login_attempts] (
|
||||
[id] INT NOT NULL IDENTITY (1,1) PRIMARY KEY,
|
||||
[ip] varchar(37) NOT NULL,
|
||||
[last_attempt] varchar(20) NOT NULL,
|
||||
[number_attempts] int NOT NULL );"); echo $modifyoutput; flush();ob_flush();
|
||||
|
||||
modify_database("", "ALTER TABLE [prefix_surveys_languagesettings] ADD [surveyls_numberformat] INT default 0 NOT NULL"); echo $modifyoutput; flush();ob_flush();
|
||||
|
||||
upgrade_token_tables145();
|
||||
modify_database("", "UPDATE [prefix_settings_global] SET stg_value='145' WHERE stg_name='DBVersion'"); echo $modifyoutput; flush();ob_flush();
|
||||
|
||||
|
||||
}
|
||||
if ($oldversion < 146) //Modify surveys table
|
||||
{
|
||||
upgrade_timing_tables146();
|
||||
modify_database("", "UPDATE [prefix_settings_global] SET stg_value='146' WHERE stg_name='DBVersion'"); echo $modifyoutput; flush();ob_flush();
|
||||
}
|
||||
|
||||
|
||||
echo '<br /><br />'.sprintf($clang->gT('Database update finished (%s)'),date('Y-m-d H:i:s')).'<br />';
|
||||
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();ob_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();ob_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();ob_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();ob_flush();
|
||||
modify_database("","ALTER TABLE ".$sv." ADD [remindercount] int DEFAULT '0'"); echo $modifyoutput; flush();ob_flush();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function upgrade_survey_tables133a()
|
||||
{
|
||||
global $dbprefix, $connect, $modifyoutput;
|
||||
mssql_drop_primary_index('assessments');
|
||||
// add the new primary key
|
||||
modify_database("","ALTER TABLE [prefix_assessments] ADD CONSTRAINT pk_assessments_id_lang PRIMARY KEY ([id],[language])"); echo $modifyoutput; flush();ob_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();ob_flush();
|
||||
modify_database("","ALTER TABLE ".$sv." ADD [validuntil] DATETIME"); echo $modifyoutput; flush();ob_flush();
|
||||
}
|
||||
}
|
||||
|
||||
// Add the usesleft field to all existing token tables
|
||||
function upgrade_token_tables145()
|
||||
{
|
||||
global $modifyoutput, $dbprefix, $connect;
|
||||
$surveyidquery = db_select_tables_like($dbprefix."tokens%");
|
||||
$surveyidresult = db_execute_num($surveyidquery);
|
||||
$tokentables=$connect->MetaTables('TABLES',false,$dbprefix."tokens%");
|
||||
foreach ($tokentables as $sv) {
|
||||
modify_database("","ALTER TABLE ".$sv." ADD [usesleft] int NOT NULL DEFAULT '1'"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","UPDATE ".$sv." SET usesleft=0 WHERE completed<>'N'"); echo $modifyoutput; flush();ob_flush();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function mssql_drop_primary_index($tablename)
|
||||
{
|
||||
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}{$tablename}') AND (CONSTRAINT_TYPE = 'PRIMARY KEY')";
|
||||
|
||||
$primarykey=$connect->GetOne($pkquery);
|
||||
if ($primarykey!=false)
|
||||
{
|
||||
modify_database("","ALTER TABLE [prefix_{$tablename}] DROP CONSTRAINT {$primarykey}"); echo $modifyoutput; flush();ob_flush();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function mssql_drop_constraint($fieldname, $tablename)
|
||||
{
|
||||
global $dbprefix, $connect, $modifyoutput;
|
||||
$connect->SetFetchMode(ADODB_FETCH_ASSOC);
|
||||
|
||||
// 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?
|
||||
$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['constraint_name']}"); echo $modifyoutput; flush();ob_flush();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
function upgrade_survey_tables139()
|
||||
{
|
||||
global $modifyoutput,$dbprefix;
|
||||
$surveyidquery = db_select_tables_like($dbprefix."survey\_%");
|
||||
$surveyidresult = db_execute_num($surveyidquery);
|
||||
if (!$surveyidresult) {return "Database Error";}
|
||||
else
|
||||
{
|
||||
while ( $sv = $surveyidresult->FetchRow() )
|
||||
{
|
||||
modify_database("","ALTER TABLE ".$sv[0]." ADD [lastpage] int"); echo $modifyoutput; flush();ob_flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function upgrade_question_attributes142()
|
||||
{
|
||||
global $modifyoutput,$dbprefix, $connect;
|
||||
$attributequery="Select qid from {$dbprefix}question_attributes where attribute='exclude_all_other' group by qid having count(qid)>1 ";
|
||||
$questionids = db_select_column($attributequery);
|
||||
foreach ($questionids as $questionid)
|
||||
{
|
||||
//Select all affected question attributes
|
||||
$attributevalues=db_select_column("SELECT value from {$dbprefix}question_attributes where attribute='exclude_all_other' and qid=".$questionid);
|
||||
modify_database("","delete from {$dbprefix}question_attributes where attribute='exclude_all_other' and qid=".$questionid); echo $modifyoutput; flush();ob_flush();
|
||||
$record['value']=implode(';',$attributevalues);
|
||||
$record['attribute']='exclude_all_other';
|
||||
$record['qid']=$questionid;
|
||||
$connect->AutoExecute("{$dbprefix}question_attributes", $record, 'INSERT');
|
||||
}
|
||||
}
|
||||
|
||||
function upgrade_tables143()
|
||||
{
|
||||
global $modifyoutput,$dbprefix, $connect;
|
||||
|
||||
|
||||
$aQIDReplacements=array();
|
||||
$answerquery = "select a.*, q.sid, q.gid from {$dbprefix}answers a,{$dbprefix}questions q where a.qid=q.qid and q.type in ('L','O','!') and a.default_value='Y'";
|
||||
$answerresult = db_execute_assoc($answerquery);
|
||||
if (!$answerresult) {return "Database Error";}
|
||||
else
|
||||
{
|
||||
while ( $row = $answerresult->FetchRow() )
|
||||
{
|
||||
modify_database("","INSERT INTO {$dbprefix}defaultvalues (qid, scale_id,language,specialtype,defaultvalue) VALUES ({$row['qid']},0,".db_quoteall($row['language']).",'',".db_quoteall($row['code']).")"); echo $modifyoutput; flush();ob_flush();
|
||||
}
|
||||
}
|
||||
|
||||
// Convert answers to subquestions
|
||||
|
||||
$answerquery = "select a.*, q.sid, q.gid, q.type from {$dbprefix}answers a,{$dbprefix}questions q where a.qid=q.qid and a.language=q.language and q.type in ('1','A','B','C','E','F','H','K',';',':','M','P','Q')";
|
||||
$answerresult = db_execute_assoc($answerquery);
|
||||
if (!$answerresult) {return "Database Error";}
|
||||
else
|
||||
{
|
||||
while ( $row = $answerresult->FetchRow() )
|
||||
{
|
||||
|
||||
$insertarray=array();
|
||||
if (isset($aQIDReplacements[$row['qid'].'_'.$row['code']]))
|
||||
{
|
||||
$insertarray['qid']=$aQIDReplacements[$row['qid'].'_'.$row['code']];
|
||||
db_switchIDInsert('questions',true);
|
||||
}
|
||||
$insertarray['sid']=$row['sid'];
|
||||
$insertarray['gid']=$row['gid'];
|
||||
$insertarray['parent_qid']=$row['qid'];
|
||||
$insertarray['type']=$row['type'];
|
||||
$insertarray['title']=$row['code'];
|
||||
$insertarray['question']=$row['answer'];
|
||||
$insertarray['question_order']=$row['sortorder'];
|
||||
$insertarray['language']=$row['language'];
|
||||
$tablename="{$dbprefix}questions";
|
||||
$query=$connect->GetInsertSQL($tablename,$insertarray);
|
||||
modify_database("",$query); echo $modifyoutput; flush();ob_flush();
|
||||
if (!isset($insertarray['qid']))
|
||||
{
|
||||
$aQIDReplacements[$row['qid'].'_'.$row['code']]=$connect->Insert_ID("{$dbprefix}questions","qid");
|
||||
$iSaveSQID=$aQIDReplacements[$row['qid'].'_'.$row['code']];
|
||||
}
|
||||
else
|
||||
{
|
||||
$iSaveSQID=$insertarray['qid'];
|
||||
db_switchIDInsert('questions',false);
|
||||
}
|
||||
if (($row['type']=='M' || $row['type']=='P') && $row['default_value']=='Y')
|
||||
{
|
||||
modify_database("","INSERT INTO {$dbprefix}defaultvalues (qid, sqid, scale_id,language,specialtype,defaultvalue) VALUES ({$row['qid']},{$iSaveSQID},0,".db_quoteall($row['language']).",'','Y')"); echo $modifyoutput; flush();ob_flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
modify_database("","delete {$dbprefix}answers from {$dbprefix}answers LEFT join {$dbprefix}questions ON {$dbprefix}answers.qid={$dbprefix}questions.qid where {$dbprefix}questions.type in ('1','F','H','M','P','W','Z')"); echo $modifyoutput; flush();ob_flush();
|
||||
|
||||
// Convert labels to answers
|
||||
$answerquery = "select qid ,type ,lid ,lid1, language from {$dbprefix}questions where parent_qid=0 and type in ('1','F','H','M','P','W','Z')";
|
||||
$answerresult = db_execute_assoc($answerquery);
|
||||
if (!$answerresult)
|
||||
{
|
||||
return "Database Error";
|
||||
}
|
||||
else
|
||||
{
|
||||
while ( $row = $answerresult->FetchRow() )
|
||||
{
|
||||
$labelquery="Select * from {$dbprefix}labels where lid={$row['lid']} and language=".db_quoteall($row['language']);
|
||||
$labelresult = db_execute_assoc($labelquery);
|
||||
while ( $lrow = $labelresult->FetchRow() )
|
||||
{
|
||||
modify_database("","INSERT INTO {$dbprefix}answers (qid, code, answer, sortorder, language, assessment_value) VALUES ({$row['qid']},".db_quoteall($lrow['code']).",".db_quoteall($lrow['title']).",{$lrow['sortorder']},".db_quoteall($lrow['language']).",{$lrow['assessment_value']})"); echo $modifyoutput; flush();ob_flush();
|
||||
//$labelids[]
|
||||
}
|
||||
if ($row['type']=='1')
|
||||
{
|
||||
$labelquery="Select * from {$dbprefix}labels where lid={$row['lid1']} and language=".db_quoteall($row['language']);
|
||||
$labelresult = db_execute_assoc($labelquery);
|
||||
while ( $lrow = $labelresult->FetchRow() )
|
||||
{
|
||||
modify_database("","INSERT INTO {$dbprefix}answers (qid, code, answer, sortorder, language, scale_id, assessment_value) VALUES ({$row['qid']},".db_quoteall($lrow['code']).",".db_quoteall($lrow['title']).",{$lrow['sortorder']},".db_quoteall($lrow['language']).",1,{$lrow['assessment_value']})"); echo $modifyoutput; flush();ob_flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Convert labels to subquestions
|
||||
$answerquery = "select * from {$dbprefix}questions where parent_qid=0 and type in (';',':')";
|
||||
$answerresult = db_execute_assoc($answerquery);
|
||||
if (!$answerresult)
|
||||
{
|
||||
return "Database Error";
|
||||
}
|
||||
else
|
||||
{
|
||||
while ( $row = $answerresult->FetchRow() )
|
||||
{
|
||||
$labelquery="Select * from {$dbprefix}labels where lid={$row['lid']} and language=".db_quoteall($row['language']);
|
||||
$labelresult = db_execute_assoc($labelquery);
|
||||
while ( $lrow = $labelresult->FetchRow() )
|
||||
{
|
||||
$insertarray=array();
|
||||
if (isset($aQIDReplacements[$row['qid'].'_'.$lrow['code'].'_1']))
|
||||
{
|
||||
$insertarray['qid']=$aQIDReplacements[$row['qid'].'_'.$lrow['code'].'_1'];
|
||||
db_switchIDInsert('questions',true);
|
||||
|
||||
}
|
||||
$insertarray['sid']=$row['sid'];
|
||||
$insertarray['gid']=$row['gid'];
|
||||
$insertarray['type']=$row['type'];
|
||||
$insertarray['parent_qid']=$row['qid'];
|
||||
$insertarray['title']=$lrow['code'];
|
||||
$insertarray['question']=$lrow['title'];
|
||||
$insertarray['question_order']=$lrow['sortorder'];
|
||||
$insertarray['language']=$lrow['language'];
|
||||
$insertarray['scale_id']=1;
|
||||
$tablename="{$dbprefix}questions";
|
||||
$query=$connect->GetInsertSQL($tablename,$insertarray);
|
||||
modify_database("",$query); echo $modifyoutput; flush();ob_flush();
|
||||
if (isset($insertarray['qid']))
|
||||
{
|
||||
$aQIDReplacements[$row['qid'].'_'.$lrow['code'].'_1']=$connect->Insert_ID("{$dbprefix}questions","qid");
|
||||
db_switchIDInsert('questions',false);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$updatequery = "update {$dbprefix}questions set type='!' where type='W'";
|
||||
modify_database("",$updatequery); echo $modifyoutput; flush();ob_flush();
|
||||
$updatequery = "update {$dbprefix}questions set type='L' where type='Z'";
|
||||
modify_database("",$updatequery); echo $modifyoutput; flush();ob_flush();
|
||||
|
||||
// Now move all non-standard templates to the /upload dir
|
||||
global $usertemplaterootdir, $standardtemplates,$standardtemplaterootdir;
|
||||
|
||||
if (!$usertemplaterootdir) {die("gettemplatelist() no template directory");}
|
||||
if ($handle = opendir($standardtemplaterootdir))
|
||||
{
|
||||
while (false !== ($file = readdir($handle)))
|
||||
{
|
||||
if (!is_file("$standardtemplaterootdir/$file") && $file != "." && $file != ".." && $file!=".svn" && !isStandardTemplate($file))
|
||||
{
|
||||
if (!rename($standardtemplaterootdir.DIRECTORY_SEPARATOR.$file,$usertemplaterootdir.DIRECTORY_SEPARATOR.$file))
|
||||
{
|
||||
echo "There was a problem moving directory '".$standardtemplaterootdir.DIRECTORY_SEPARATOR.$file."' to '".$usertemplaterootdir.DIRECTORY_SEPARATOR.$file."' due to missing permissions. Please do this manually.<br />";
|
||||
};
|
||||
}
|
||||
}
|
||||
closedir($handle);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function upgrade_timing_tables146()
|
||||
{
|
||||
global $modifyoutput,$dbprefix, $connect;
|
||||
$aTimingTables=$connect->MetaTables('TABLES',false, "%timings");
|
||||
foreach ($aTimingTables as $sTable) {
|
||||
modify_database("","EXEC sp_rename '{$sTable}.interviewTime','interviewtime'"); echo $modifyoutput; flush(); ob_flush();
|
||||
}
|
||||
}
|
||||
954
include/limesurvey/admin/update/upgrade-mysql.php
Normal file
954
include/limesurvey/admin/update/upgrade-mysql.php
Normal file
@@ -0,0 +1,954 @@
|
||||
<?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-mysql.php 7108 2009-06-15 05:43:21Z jcleeland $
|
||||
*/
|
||||
|
||||
// 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, $databasename, $databasetabletype, $connect, $clang;
|
||||
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();ob_flush();
|
||||
modify_database("","update `prefix_questions` set `language`='$newlang' where language='$oldlang'");echo $modifyoutput;flush();ob_flush();
|
||||
modify_database("","update `prefix_groups` set `language`='$newlang' where language='$oldlang'");echo $modifyoutput;flush();ob_flush();
|
||||
modify_database("","update `prefix_labels` set `language`='$newlang' where language='$oldlang'");echo $modifyoutput;flush();ob_flush();
|
||||
modify_database("","update `prefix_surveys` set `language`='$newlang' where language='$oldlang'");echo $modifyoutput;flush();ob_flush();
|
||||
modify_database("","update `prefix_surveys_languagesettings` set `surveyls_language`='$newlang' where surveyls_language='$oldlang'");echo $modifyoutput;flush();ob_flush();
|
||||
modify_database("","update `prefix_users` set `lang`='$newlang' where lang='$oldlang'");echo $modifyoutput;flush();ob_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();ob_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();ob_flush();
|
||||
}
|
||||
modify_database("","update `prefix_settings_global` set `stg_value`='111' where stg_name='DBVersion'"); echo $modifyoutput; flush();ob_flush();
|
||||
|
||||
}
|
||||
|
||||
|
||||
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` CHANGE `users_name` `users_name` VARCHAR( 64 ) NOT NULL"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","update `prefix_settings_global` set `stg_value`='112' where stg_name='DBVersion'"); echo $modifyoutput; flush();ob_flush();
|
||||
}
|
||||
|
||||
if ($oldversion < 113) {
|
||||
//Fixes the collation for the complete DB, tables and columns
|
||||
echo "<strong>Attention:</strong>The following upgrades will update your MySQL Database collations. This may take some time.<br />If for any reason you should get a timeout just re-run the upgrade procedure. The updating will continue where it left off.<br /><br />"; flush();ob_flush();
|
||||
fix_mysql_collation();
|
||||
modify_database("","ALTER DATABASE `$databasename` DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;");echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","update `prefix_settings_global` set `stg_value`='113' where stg_name='DBVersion'"); echo $modifyoutput; flush();ob_flush();
|
||||
}
|
||||
|
||||
if ($oldversion < 114) {
|
||||
modify_database("","ALTER TABLE `prefix_saved_control` CHANGE `email` `email` VARCHAR(320) NOT NULL"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","ALTER TABLE `prefix_surveys` CHANGE `adminemail` `adminemail` VARCHAR(320) NOT NULL"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","ALTER TABLE `prefix_users` CHANGE `email` `email` VARCHAR(320) NOT NULL"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("",'INSERT INTO `prefix_settings_global` VALUES (\'SessionName\', \'$sessionname\');');echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","update `prefix_settings_global` set `stg_value`='114' where stg_name='DBVersion'"); echo $modifyoutput; flush();ob_flush();
|
||||
}
|
||||
|
||||
if ($oldversion < 126) {
|
||||
//Adds new "public" field
|
||||
modify_database("","ALTER TABLE `prefix_surveys` ADD `printanswers` CHAR(1) default 'N' AFTER allowsave"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","ALTER TABLE `prefix_surveys` ADD `listpublic` CHAR(1) default 'N' AFTER `datecreated`"); echo $modifyoutput; flush();ob_flush();
|
||||
upgrade_survey_tables117();
|
||||
upgrade_survey_tables118();
|
||||
// 119
|
||||
modify_database("","CREATE TABLE `prefix_quota` (
|
||||
`id` int(11) NOT NULL auto_increment,
|
||||
`sid` int(11) 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`)
|
||||
) ENGINE=$databasetabletype CHARACTER SET utf8 COLLATE utf8_unicode_ci;"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","CREATE TABLE `prefix_quota_members` (
|
||||
`id` int(11) NOT NULL auto_increment,
|
||||
`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,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `sid` (`sid`,`qid`,`quota_id`,`code`)
|
||||
) ENGINE=$databasetabletype CHARACTER SET utf8 COLLATE utf8_unicode_ci;"); echo $modifyoutput; flush();ob_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();ob_flush();
|
||||
modify_database("","update `prefix_questions` set `language`='$newlang' where language='$oldlang'");echo $modifyoutput;flush();ob_flush();
|
||||
modify_database("","update `prefix_groups` set `language`='$newlang' where language='$oldlang'");echo $modifyoutput;flush();ob_flush();
|
||||
modify_database("","update `prefix_labels` set `language`='$newlang' where language='$oldlang'");echo $modifyoutput;flush();ob_flush();
|
||||
modify_database("","update `prefix_surveys` set `language`='$newlang' where language='$oldlang'");echo $modifyoutput;flush();ob_flush();
|
||||
modify_database("","update `prefix_surveys_languagesettings` set `surveyls_language`='$newlang' where surveyls_language='$oldlang'");echo $modifyoutput;flush();ob_flush();
|
||||
modify_database("","update `prefix_users` set `lang`='$newlang' where lang='$oldlang'");echo $modifyoutput;flush();ob_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();ob_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();ob_flush();}
|
||||
}
|
||||
|
||||
|
||||
modify_database("","ALTER TABLE `prefix_surveys` ADD `htmlemail` CHAR(1) default 'N'"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","ALTER TABLE `prefix_surveys` ADD `tokenanswerspersistence` CHAR(1) default 'N'"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","ALTER TABLE `prefix_surveys` ADD `usecaptcha` CHAR(1) default 'N'"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","ALTER TABLE `prefix_users` ADD `htmleditormode` CHAR(7) default 'default'"); echo $modifyoutput; flush();ob_flush();
|
||||
//122
|
||||
modify_database("","CREATE TABLE `prefix_templates_rights` (
|
||||
`uid` int(11) NOT NULL,
|
||||
`folder` varchar(255) NOT NULL,
|
||||
`use` int(1) NOT NULL,
|
||||
PRIMARY KEY (`uid`,`folder`)
|
||||
) ENGINE=$databasetabletype CHARACTER SET utf8 COLLATE utf8_unicode_ci;"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","CREATE TABLE `prefix_templates` (
|
||||
`folder` varchar(255) NOT NULL,
|
||||
`creator` int(11) NOT NULL,
|
||||
PRIMARY KEY (`folder`)
|
||||
) ENGINE=$databasetabletype CHARACTER SET utf8 COLLATE utf8_unicode_ci;"); echo $modifyoutput; flush();ob_flush();
|
||||
|
||||
//123
|
||||
modify_database("","ALTER TABLE `prefix_conditions` CHANGE `value` `value` VARCHAR(255) NOT NULL default ''"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","ALTER TABLE `prefix_labels` CHANGE `title` `title` text"); echo $modifyoutput; flush();ob_flush();
|
||||
//124
|
||||
modify_database("","ALTER TABLE `prefix_surveys` ADD `bounce_email` text"); echo $modifyoutput; flush();ob_flush();
|
||||
//125
|
||||
upgrade_token_tables125();
|
||||
modify_database("","ALTER TABLE `prefix_users` ADD `superadmin` tinyint(1) NOT NULL default '0'"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","UPDATE `prefix_users` SET `superadmin`=1 where (create_survey=1 AND create_user=1 AND move_user=1 AND delete_user=1 AND configurator=1)"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","ALTER TABLE `prefix_users` DROP COLUMN `move_user`"); echo $modifyoutput; flush();ob_flush();
|
||||
//126
|
||||
modify_database("","ALTER TABLE `prefix_questions` ADD `lid1` integer NOT NULL default '0'"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","UPDATE `prefix_conditions` SET `method`='==' where (`method` is null) or `method`='' or `method`='0'"); echo $modifyoutput; flush();ob_flush();
|
||||
|
||||
modify_database("","update `prefix_settings_global` set `stg_value`='126' where stg_name='DBVersion'"); echo $modifyoutput; flush();ob_flush();
|
||||
}
|
||||
|
||||
if ($oldversion < 127) {
|
||||
modify_database("","create index `assessments_idx2` on `prefix_assessments` (`sid`)"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","create index `assessments_idx3` on `prefix_assessments` (`gid`)"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","create index `conditions_idx2` on `prefix_conditions` (`qid`)"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","create index `groups_idx2` on `prefix_groups` (`sid`)"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","create index `questions_idx2` on `prefix_questions` (`sid`)"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","create index `questions_idx3` on `prefix_questions` (`gid`)"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","create index `question_attributes_idx2` on `prefix_question_attributes` (`qid`)"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","create index `quota_idx2` on `prefix_quota` (`sid`)"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","create index `saved_control_idx2` on `prefix_saved_control` (`sid`)"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","create index `user_in_groups_idx1` on `prefix_user_in_groups` (`ugid`, `uid`)"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","create index `answers_idx2` on `prefix_answers` (`sortorder`)"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","create index `conditions_idx3` on `prefix_conditions` (`cqid`)"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","create index `questions_idx4` on `prefix_questions` (`type`)"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","update `prefix_settings_global` set `stg_value`='127' where stg_name='DBVersion'"); echo $modifyoutput; flush();ob_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();ob_flush();
|
||||
}
|
||||
if ($oldversion < 129) {
|
||||
//129
|
||||
modify_database("","ALTER TABLE `prefix_surveys` ADD `startdate` DATETIME"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","ALTER TABLE `prefix_surveys` ADD `usestartdate` varchar(1) NOT NULL default 'N'"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","update `prefix_settings_global` set `stg_value`='129' where stg_name='DBVersion'"); echo $modifyoutput; flush();ob_flush();
|
||||
}
|
||||
if ($oldversion < 130)
|
||||
{
|
||||
modify_database("","ALTER TABLE `prefix_conditions` ADD `scenario` integer NOT NULL default '1' AFTER `qid`"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","UPDATE `prefix_conditions` SET `scenario`=1 where (`scenario` is null) or `scenario`='' or `scenario`=0"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","update `prefix_settings_global` set `stg_value`='130' where stg_name='DBVersion'"); echo $modifyoutput; flush();ob_flush();
|
||||
}
|
||||
if ($oldversion < 131)
|
||||
{
|
||||
modify_database("","ALTER TABLE `prefix_surveys` ADD `publicstatistics` varchar(1) NOT NULL default 'N'"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","update `prefix_settings_global` set `stg_value`='131' where stg_name='DBVersion'"); echo $modifyoutput; flush();ob_flush();
|
||||
}
|
||||
if ($oldversion < 132)
|
||||
{
|
||||
modify_database("","ALTER TABLE `prefix_surveys` ADD `publicgraphs` varchar(1) NOT NULL default 'N'"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","update `prefix_settings_global` set `stg_value`='132' where stg_name='DBVersion'"); echo $modifyoutput; flush();ob_flush();
|
||||
}
|
||||
|
||||
if ($oldversion < 133)
|
||||
{
|
||||
modify_database("","ALTER TABLE `prefix_users` ADD `one_time_pw` blob"); echo $modifyoutput; flush();ob_flush();
|
||||
// Add new assessment setting
|
||||
modify_database("","ALTER TABLE `prefix_surveys` ADD `assessments` varchar(1) NOT NULL default 'N'"); echo $modifyoutput; flush();ob_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();ob_flush();
|
||||
modify_database("","ALTER TABLE `prefix_labels` ADD `assessment_value` int(11) NOT NULL default '0'"); echo $modifyoutput; flush();ob_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();ob_flush();
|
||||
modify_database("","update `prefix_labels` set `assessment_value`=CAST(`code` as SIGNED) where `code` REGEXP '^-?[0-9]+$'");echo $modifyoutput; flush();ob_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();ob_flush();
|
||||
// add language field to assessment table
|
||||
modify_database("","ALTER TABLE `prefix_assessments` ADD `language` varchar(20) NOT NULL default 'en'"); echo $modifyoutput; flush();ob_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();ob_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();ob_flush();
|
||||
// drop the old link field
|
||||
modify_database("","ALTER TABLE `prefix_assessments` DROP COLUMN `link`"); echo $modifyoutput; flush();ob_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();ob_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();ob_flush();
|
||||
modify_database("","ALTER TABLE `prefix_surveys_languagesettings` ADD `surveyls_endtext` text"); echo $modifyoutput; flush();ob_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();ob_flush();
|
||||
// drop old URL field
|
||||
modify_database("","ALTER TABLE `prefix_surveys` DROP COLUMN `url`"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","update `prefix_settings_global` set `stg_value`='133' where stg_name='DBVersion'"); echo $modifyoutput; flush();ob_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();ob_flush();
|
||||
modify_database("","ALTER TABLE `prefix_surveys` ADD `attributedescriptions` TEXT;"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","ALTER TABLE `prefix_surveys` DROP COLUMN `attribute1`"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","ALTER TABLE `prefix_surveys` DROP COLUMN `attribute2`"); echo $modifyoutput; flush();ob_flush();
|
||||
upgrade_token_tables134();
|
||||
modify_database("","update `prefix_settings_global` set `stg_value`='134' where stg_name='DBVersion'"); echo $modifyoutput; flush();ob_flush();
|
||||
}
|
||||
if ($oldversion < 135)
|
||||
{
|
||||
modify_database("","ALTER TABLE `prefix_question_attributes` MODIFY `value` text"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","UPDATE `prefix_settings_global` SET `stg_value`='135' WHERE stg_name='DBVersion'"); echo $modifyoutput; flush();ob_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();ob_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();ob_flush();
|
||||
modify_database("","UPDATE `prefix_settings_global` SET `stg_value`='136' WHERE stg_name='DBVersion'"); echo $modifyoutput; flush();ob_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();ob_flush();
|
||||
modify_database("", "ALTER TABLE `prefix_users` ADD `dateformat` int(1) NOT NULL default '1'"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "UPDATE `prefix_surveys` set `startdate`=null where `usestartdate`='N'"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "UPDATE `prefix_surveys` set `expires`=null where `useexpiry`='N'"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "ALTER TABLE `prefix_surveys` DROP COLUMN `useexpiry`"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "ALTER TABLE `prefix_surveys` DROP COLUMN `usestartdate`"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "UPDATE `prefix_settings_global` SET `stg_value`='137' WHERE stg_name='DBVersion'"); echo $modifyoutput; flush();ob_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();ob_flush();
|
||||
modify_database("", "UPDATE `prefix_settings_global` SET `stg_value`='138' WHERE stg_name='DBVersion'"); echo $modifyoutput; flush();ob_flush();
|
||||
}
|
||||
|
||||
if ($oldversion < 139) //Modify quota field
|
||||
{
|
||||
upgrade_survey_tables139();
|
||||
modify_database("", "UPDATE `prefix_settings_global` SET `stg_value`='139' WHERE stg_name='DBVersion'"); echo $modifyoutput; flush();ob_flush();
|
||||
}
|
||||
|
||||
if ($oldversion < 140) //Modify surveys table
|
||||
{
|
||||
modify_database("", "ALTER TABLE `prefix_surveys` ADD `emailresponseto` text DEFAULT NULL"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "UPDATE `prefix_settings_global` SET `stg_value`='140' WHERE stg_name='DBVersion'"); echo $modifyoutput; flush();ob_flush();
|
||||
}
|
||||
|
||||
if ($oldversion < 141) //Modify surveys table
|
||||
{
|
||||
modify_database("", "ALTER TABLE `prefix_surveys` ADD `tokenlength` tinyint(2) NOT NULL default '15'"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "UPDATE `prefix_settings_global` SET `stg_value`='141' WHERE stg_name='DBVersion'"); echo $modifyoutput; flush();ob_flush();
|
||||
}
|
||||
|
||||
if ($oldversion < 142) //Modify surveys table
|
||||
{
|
||||
upgrade_question_attributes142();
|
||||
modify_database("","ALTER TABLE `prefix_surveys` CHANGE `expires` `expires` datetime"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","ALTER TABLE `prefix_surveys` CHANGE `startdate` `startdate` datetime"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "UPDATE `prefix_question_attributes` SET `value`='0' WHERE `value`='false'"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "UPDATE `prefix_question_attributes` SET `value`='1' WHERE `value`='true'"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "UPDATE `prefix_settings_global` SET `stg_value`='142' WHERE stg_name='DBVersion'"); echo $modifyoutput; flush();ob_flush();
|
||||
}
|
||||
|
||||
if ($oldversion < 143) //Modify surveys table
|
||||
{
|
||||
modify_database("", "ALTER TABLE `prefix_questions` ADD `parent_qid` integer NOT NULL default '0'"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "ALTER TABLE `prefix_answers` ADD `scale_id` tinyint NOT NULL default '0'"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "ALTER TABLE `prefix_questions` ADD `scale_id` tinyint NOT NULL default '0'"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "ALTER TABLE `prefix_questions` ADD `same_default` tinyint NOT NULL default '0' COMMENT 'Saves if user set to use the same default value across languages in default options dialog'"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "ALTER TABLE `prefix_answers` DROP PRIMARY KEY, ADD PRIMARY KEY (`qid`,`code`,`language`,`scale_id`)"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "CREATE TABLE `prefix_defaultvalues` (
|
||||
`qid` int(11) NOT NULL default '0',
|
||||
`scale_id` int(11) NOT NULL default '0',
|
||||
`sqid` int(11) NOT NULL default '0',
|
||||
`language` varchar(20) NOT NULL,
|
||||
`specialtype` varchar(20) NOT NULL default '',
|
||||
`defaultvalue` text,
|
||||
PRIMARY KEY (`qid` , `scale_id`, `language`, `specialtype`, `sqid` )
|
||||
) ENGINE=$databasetabletype CHARACTER SET utf8 COLLATE utf8_unicode_ci;"); echo $modifyoutput; flush();ob_flush();
|
||||
|
||||
// -Move all 'answers' that are subquestions to the questions table
|
||||
// -Move all 'labels' that are answers to the answers table
|
||||
// -Transscribe the default values where applicable
|
||||
// -Move default values from answers to questions
|
||||
upgrade_tables143();
|
||||
|
||||
modify_database("", "ALTER TABLE `prefix_answers` DROP COLUMN `default_value`"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "ALTER TABLE `prefix_questions` DROP COLUMN `lid`"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "ALTER TABLE `prefix_questions` DROP COLUMN `lid1`"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "CREATE TABLE prefix_sessions(
|
||||
sesskey VARCHAR( 64 ) NOT NULL DEFAULT '',
|
||||
expiry DATETIME NOT NULL ,
|
||||
expireref VARCHAR( 250 ) DEFAULT '',
|
||||
created DATETIME NOT NULL ,
|
||||
modified DATETIME NOT NULL ,
|
||||
sessdata LONGTEXT,
|
||||
PRIMARY KEY ( sesskey ) ,
|
||||
INDEX sess2_expiry( expiry ),
|
||||
INDEX sess2_expireref( expireref )) ENGINE=$databasetabletype CHARACTER SET utf8 COLLATE utf8_unicode_ci;"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "UPDATE `prefix_settings_global` SET `stg_value`='143' WHERE stg_name='DBVersion'"); echo $modifyoutput; flush();ob_flush();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
if ($oldversion < 145)
|
||||
{
|
||||
modify_database("", "ALTER TABLE `prefix_surveys` ADD `savetimings` CHAR(1) NULL default 'N' AFTER `format`"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "ALTER TABLE `prefix_surveys` ADD `showXquestions` CHAR(1) NULL default 'Y'"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "ALTER TABLE `prefix_surveys` ADD `showgroupinfo` CHAR(1) NULL default 'B'"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "ALTER TABLE `prefix_surveys` ADD `shownoanswer` CHAR(1) NULL default 'Y'"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "ALTER TABLE `prefix_surveys` ADD `showqnumcode` CHAR(1) NULL default 'X'"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "ALTER TABLE `prefix_surveys` ADD `bouncetime` BIGINT(20) NULL "); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "ALTER TABLE `prefix_surveys` ADD `bounceprocessing` VARCHAR(1) NULL default 'N'"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "ALTER TABLE `prefix_surveys` ADD `bounceaccounttype` VARCHAR(4) NULL"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "ALTER TABLE `prefix_surveys` ADD `bounceaccounthost` VARCHAR(200) NULL"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "ALTER TABLE `prefix_surveys` ADD `bounceaccountpass` VARCHAR(100) NULL"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "ALTER TABLE `prefix_surveys` ADD `bounceaccountencryption` VARCHAR(3) NULL"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "ALTER TABLE `prefix_surveys` ADD `bounceaccountuser` VARCHAR(200) NULL"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "ALTER TABLE `prefix_surveys` ADD `showwelcome` CHAR(1) NULL default 'Y'"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "ALTER TABLE `prefix_surveys` ADD `showprogress` char(1) default 'Y'"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "ALTER TABLE `prefix_surveys` ADD `allowjumps` char(1) default 'N'"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "ALTER TABLE `prefix_surveys` ADD `navigationdelay` tinyint(2) default '0'"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "ALTER TABLE `prefix_surveys` ADD `nokeyboard` char(1) default 'N'"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "ALTER TABLE `prefix_surveys` ADD `alloweditaftercompletion` char(1) default 'N'"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "CREATE TABLE `prefix_survey_permissions` (
|
||||
`sid` int(10) unsigned NOT NULL,
|
||||
`uid` int(10) unsigned NOT NULL,
|
||||
`permission` varchar(20) NOT NULL,
|
||||
`create_p` tinyint(1) NOT NULL default '0',
|
||||
`read_p` tinyint(1) NOT NULL default '0',
|
||||
`update_p` tinyint(1) NOT NULL default '0',
|
||||
`delete_p` tinyint(1) NOT NULL default '0',
|
||||
`import_p` tinyint(1) NOT NULL default '0',
|
||||
`export_p` tinyint(1) NOT NULL default '0',
|
||||
PRIMARY KEY (sid, uid, permission)
|
||||
) ENGINE=$databasetabletype CHARACTER SET utf8 COLLATE utf8_unicode_ci;"); echo $modifyoutput; flush();ob_flush();
|
||||
|
||||
upgrade_surveypermissions_table145();
|
||||
|
||||
// drop the old survey rights table
|
||||
modify_database("", "DROP TABLE `prefix_surveys_rights`"); echo $modifyoutput; flush();ob_flush();
|
||||
|
||||
// Add new fields for email templates
|
||||
modify_database("", "ALTER TABLE `prefix_surveys_languagesettings` ADD
|
||||
(`email_admin_notification_subj` VARCHAR(255) NULL,
|
||||
`email_admin_notification` TEXT NULL,
|
||||
`email_admin_responses_subj` VARCHAR(255) NULL,
|
||||
`email_admin_responses` TEXT NULL)");
|
||||
|
||||
//Add index to questions table to speed up subquestions
|
||||
modify_database("", "create INDEX parent_qid_idx on prefix_questions( parent_qid );"); echo $modifyoutput; flush();ob_flush();
|
||||
|
||||
|
||||
modify_database("", "ALTER TABLE `prefix_surveys` ADD `emailnotificationto` text DEFAULT NULL AFTER `emailresponseto`"); echo $modifyoutput; flush();ob_flush();
|
||||
upgrade_survey_table145();
|
||||
modify_database("", "ALTER TABLE `prefix_surveys` DROP COLUMN `notification`"); echo $modifyoutput; flush();ob_flush();
|
||||
|
||||
modify_database("","ALTER TABLE `prefix_conditions` CHANGE `method` `method` CHAR( 5 ) NOT NULL default '';"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","UPDATE `prefix_surveys` set `private`='N' where `private` is NULL;"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","ALTER TABLE `prefix_surveys` CHANGE `private` `anonymized` char(1) collate utf8_unicode_ci NOT NULL default 'N';"); echo $modifyoutput; flush();ob_flush();
|
||||
|
||||
|
||||
//now we clean up things that were not properly set in previous DB upgrades
|
||||
|
||||
modify_database("","UPDATE `prefix_answers` SET `answer`='' where `answer` is null;"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","ALTER TABLE `prefix_answers` CHANGE `answer` `answer` text collate utf8_unicode_ci NOT NULL;"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","ALTER TABLE `prefix_answers` CHANGE `assessment_value` `assessment_value` int(11) NOT NULL default '0' AFTER `answer`;"); echo $modifyoutput; flush();ob_flush();
|
||||
|
||||
modify_database("","UPDATE `prefix_assessments` SET `scope`='' where `scope` is null;"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","ALTER TABLE `prefix_assessments` CHANGE `scope` `scope` varchar(5) collate utf8_unicode_ci NOT NULL default '';"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","UPDATE `prefix_assessments` SET `name`='' where `name` is null;"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","ALTER TABLE `prefix_assessments` CHANGE `name` `name` text collate utf8_unicode_ci NOT NULL;"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","UPDATE `prefix_assessments` SET `message`='' where `message` is null;"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","ALTER TABLE `prefix_assessments` CHANGE `message` `message` text collate utf8_unicode_ci NOT NULL;"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","UPDATE `prefix_assessments` SET `minimum`='' where `minimum` is null;"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","ALTER TABLE `prefix_assessments` CHANGE `minimum` `minimum` varchar(50) collate utf8_unicode_ci NOT NULL default '';"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","UPDATE `prefix_assessments` SET `maximum`='' where `maximum` is null;"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","ALTER TABLE `prefix_assessments` CHANGE `maximum` `maximum` varchar(50) collate utf8_unicode_ci NOT NULL default '';"); echo $modifyoutput; flush();ob_flush();
|
||||
|
||||
modify_database("","ALTER TABLE `prefix_assessments` CHANGE `id` `id` int(11) NOT NULL;"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","ALTER TABLE `prefix_assessments` DROP PRIMARY KEY;"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","ALTER TABLE `prefix_assessments` ADD PRIMARY KEY (`id`,`language`);"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","ALTER TABLE `prefix_assessments` CHANGE `id` `id` int(11) NOT NULL auto_increment;"); echo $modifyoutput; flush();ob_flush();
|
||||
|
||||
modify_database("","ALTER TABLE `prefix_conditions` CHANGE `cfieldname` `cfieldname` varchar(50) collate utf8_unicode_ci NOT NULL default '';"); echo $modifyoutput; flush();ob_flush();
|
||||
|
||||
modify_database("","ALTER TABLE `prefix_defaultvalues` CHANGE `specialtype` `specialtype` varchar(20) collate utf8_unicode_ci NOT NULL default '' AFTER `qid`;"); echo $modifyoutput; flush();ob_flush();
|
||||
|
||||
modify_database("","UPDATE `prefix_groups` SET `group_name`='' where `group_name` is null;"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","ALTER TABLE `prefix_groups` CHANGE `group_name` `group_name` varchar(100) collate utf8_unicode_ci NOT NULL default '';"); echo $modifyoutput; flush();ob_flush();
|
||||
|
||||
modify_database("","UPDATE `prefix_labels` SET `code`='' where `code` is null;"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","ALTER TABLE `prefix_labels` CHANGE `code` `code` varchar(5) collate utf8_unicode_ci NOT NULL default '';"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","ALTER TABLE `prefix_labels` CHANGE `language` `language` varchar(20) collate utf8_unicode_ci NOT NULL default 'en' AFTER `assessment_value`;"); echo $modifyoutput; flush();ob_flush();
|
||||
|
||||
modify_database("","UPDATE `prefix_labelsets` SET `label_name`='' WHERE `label_name` is null;"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","ALTER TABLE `prefix_labelsets` CHANGE `label_name` `label_name` varchar(100) collate utf8_unicode_ci NOT NULL default '';"); echo $modifyoutput; flush();ob_flush();
|
||||
|
||||
modify_database("","ALTER TABLE `prefix_questions` CHANGE `parent_qid` `parent_qid` int(11) NOT NULL default '0' AFTER `qid`;"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","UPDATE `prefix_questions` SET `type`='T' where `type` is null;"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","ALTER TABLE `prefix_questions` CHANGE `type` `type` char(1) collate utf8_unicode_ci NOT NULL default 'T';"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","UPDATE `prefix_questions` SET `title`='' where `type` is null;"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","ALTER TABLE `prefix_questions` CHANGE `title` `title` varchar(20) collate utf8_unicode_ci NOT NULL default '';"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","UPDATE `prefix_questions` SET `question`='' where `question` is null;"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","ALTER TABLE `prefix_questions` CHANGE `question` `question` text collate utf8_unicode_ci NOT NULL;"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","UPDATE `prefix_questions` SET `other`='N' where `other` is null;"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","ALTER TABLE `prefix_questions` CHANGE `other` `other` char(1) collate utf8_unicode_ci NOT NULL default 'N';"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","ALTER TABLE `prefix_questions` CHANGE `mandatory` `mandatory` char(1) collate utf8_unicode_ci default NULL;"); echo $modifyoutput; flush();ob_flush();
|
||||
|
||||
modify_database("","ALTER TABLE `prefix_question_attributes` CHANGE `attribute` `attribute` varchar(50) collate utf8_unicode_ci default NULL;"); echo $modifyoutput; flush();ob_flush();
|
||||
|
||||
modify_database("","ALTER TABLE `prefix_quota` CHANGE `qlimit` `qlimit` int(8) default NULL AFTER `name`;"); echo $modifyoutput; flush();ob_flush();
|
||||
|
||||
modify_database("","UPDATE `prefix_saved_control` SET `identifier`='' where `identifier` is null;"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","ALTER TABLE `prefix_saved_control` CHANGE `identifier` `identifier` text collate utf8_unicode_ci NOT NULL;"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","UPDATE `prefix_saved_control` SET `access_code`='' where `access_code` is null;"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","ALTER TABLE `prefix_saved_control` CHANGE `access_code` `access_code` text collate utf8_unicode_ci NOT NULL;"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","ALTER TABLE `prefix_saved_control` CHANGE `email` `email` varchar(320) collate utf8_unicode_ci default NULL;"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","UPDATE `prefix_saved_control` SET `ip`='' where `ip` is null;"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","ALTER TABLE `prefix_saved_control` CHANGE `ip` `ip` text collate utf8_unicode_ci NOT NULL;"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","UPDATE `prefix_saved_control` SET `saved_thisstep`='' where `access_code` is null;"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","ALTER TABLE `prefix_saved_control` CHANGE `saved_thisstep` `saved_thisstep` text collate utf8_unicode_ci NOT NULL;"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","UPDATE `prefix_saved_control` SET `status`='' where `access_code` is null;"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","ALTER TABLE `prefix_saved_control` CHANGE `status` `status` char(1) collate utf8_unicode_ci NOT NULL default '';"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","UPDATE `prefix_saved_control` SET `saved_date`='0000-00-00 00:00:00' where `saved_date` is null;"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","ALTER TABLE `prefix_saved_control` CHANGE `saved_date` `saved_date` datetime NOT NULL;"); echo $modifyoutput; flush();ob_flush();
|
||||
|
||||
modify_database("","UPDATE `prefix_settings_global` SET `stg_value`='' where `stg_value` is null;"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","ALTER TABLE `prefix_settings_global` CHANGE `stg_value` `stg_value` varchar(255) collate utf8_unicode_ci NOT NULL default ''"); echo $modifyoutput; flush();ob_flush();
|
||||
|
||||
modify_database("","ALTER TABLE `prefix_surveys` CHANGE `admin` `admin` varchar(50) collate utf8_unicode_ci default NULL"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","UPDATE `prefix_surveys` SET `active`='N' where `active` is null;"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","ALTER TABLE `prefix_surveys` CHANGE `active` `active` char(1) collate utf8_unicode_ci NOT NULL default 'N';"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","ALTER TABLE `prefix_surveys` CHANGE `startdate` `startdate` datetime default NULL AFTER `expires`"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","ALTER TABLE `prefix_surveys` CHANGE `adminemail` `adminemail` varchar(320) collate utf8_unicode_ci default NULL"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","ALTER TABLE `prefix_surveys` CHANGE `anonymized` `anonymized` char(1) collate utf8_unicode_ci NOT NULL default 'N'"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","ALTER TABLE `prefix_surveys` CHANGE `faxto` `faxto` varchar(20) collate utf8_unicode_ci default NULL"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","ALTER TABLE `prefix_surveys` CHANGE `format` `format` char(1) collate utf8_unicode_ci default NULL"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","ALTER TABLE `prefix_surveys` CHANGE `language` `language` varchar(50) collate utf8_unicode_ci default NULL"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","ALTER TABLE `prefix_surveys` CHANGE `additional_languages` `additional_languages` varchar(255) collate utf8_unicode_ci default NULL"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","ALTER TABLE `prefix_surveys` CHANGE `printanswers` `printanswers` char(1) collate utf8_unicode_ci default 'N' AFTER `allowprev`"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","ALTER TABLE `prefix_surveys` CHANGE `publicstatistics` `publicstatistics` char(1) collate utf8_unicode_ci default 'N' after `datecreated`"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","ALTER TABLE `prefix_surveys` CHANGE `publicgraphs` `publicgraphs` char(1) collate utf8_unicode_ci default 'N' AFTER `publicstatistics`"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","ALTER TABLE `prefix_surveys` CHANGE `assessments` `assessments` char(1) collate utf8_unicode_ci default 'N' AFTER `tokenanswerspersistence`"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","ALTER TABLE `prefix_surveys` CHANGE `usetokens` `usetokens` char(1) collate utf8_unicode_ci default 'N' AFTER `usecaptcha`"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","ALTER TABLE `prefix_surveys` CHANGE `bounce_email` `bounce_email` varchar(320) collate utf8_unicode_ci default NULL"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","ALTER TABLE `prefix_surveys` CHANGE `tokenlength` `tokenlength` tinyint(2) default '15'"); echo $modifyoutput; flush();ob_flush();
|
||||
|
||||
modify_database("","UPDATE `prefix_surveys_languagesettings` SET `surveyls_title`='' where `surveyls_title` is null;"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","ALTER TABLE `prefix_surveys_languagesettings` CHANGE `surveyls_title` `surveyls_title` varchar(200) collate utf8_unicode_ci NOT NULL"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","ALTER TABLE `prefix_surveys_languagesettings` CHANGE `surveyls_endtext` `surveyls_endtext` text collate utf8_unicode_ci AFTER `surveyls_welcometext`"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","ALTER TABLE `prefix_surveys_languagesettings` CHANGE `surveyls_url` `surveyls_url` varchar(255) collate utf8_unicode_ci default NULL AFTER `surveyls_endtext`"); echo $modifyoutput; flush();ob_flush();
|
||||
|
||||
modify_database("","ALTER TABLE `prefix_surveys_languagesettings` CHANGE `surveyls_urldescription` `surveyls_urldescription` varchar(255) collate utf8_unicode_ci default NULL"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","ALTER TABLE `prefix_surveys_languagesettings` CHANGE `surveyls_email_invite_subj` `surveyls_email_invite_subj` varchar(255) collate utf8_unicode_ci default NULL"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","ALTER TABLE `prefix_surveys_languagesettings` CHANGE `surveyls_email_remind_subj` `surveyls_email_remind_subj` varchar(255) collate utf8_unicode_ci default NULL"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","ALTER TABLE `prefix_surveys_languagesettings` CHANGE `surveyls_email_register_subj` `surveyls_email_register_subj` varchar(255) collate utf8_unicode_ci default NULL"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","ALTER TABLE `prefix_surveys_languagesettings` CHANGE `surveyls_email_confirm_subj` `surveyls_email_confirm_subj` varchar(255) collate utf8_unicode_ci default NULL"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","ALTER TABLE `prefix_surveys_languagesettings` CHANGE `surveyls_dateformat` `surveyls_dateformat` int(10) unsigned NOT NULL default '1'"); echo $modifyoutput; flush();ob_flush();
|
||||
|
||||
modify_database("","UPDATE `prefix_users` SET `users_name`='' where `users_name` is null;"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","ALTER TABLE `prefix_users` CHANGE `users_name` `users_name` varchar(64) collate utf8_unicode_ci NOT NULL default ''"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","UPDATE `prefix_users` SET `full_name`='' where `full_name` is null;"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","ALTER TABLE `prefix_users` CHANGE `full_name` `full_name` varchar(50) collate utf8_unicode_ci NOT NULL"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","ALTER TABLE `prefix_users` CHANGE `lang` `lang` varchar(20) collate utf8_unicode_ci default NULL"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","ALTER TABLE `prefix_users` CHANGE `email` `email` varchar(320) collate utf8_unicode_ci default NULL"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","ALTER TABLE `prefix_users` CHANGE `superadmin` `superadmin` tinyint(1) NOT NULL default '0' AFTER `delete_user`"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","ALTER TABLE `prefix_users` CHANGE `htmleditormode` `htmleditormode` varchar(7) collate utf8_unicode_ci default 'default'"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","ALTER TABLE `prefix_users` CHANGE `dateformat` `dateformat` int(10) unsigned NOT NULL default '1'"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","ALTER TABLE `prefix_users` DROP INDEX `email`;");
|
||||
|
||||
modify_database("","UPDATE `prefix_user_groups` SET `name`='' where `name` is null;"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","ALTER TABLE `prefix_user_groups` CHANGE `name` `name` varchar(20) collate utf8_unicode_ci NOT NULL"); echo $modifyoutput; flush();ob_flush();
|
||||
|
||||
modify_database("","UPDATE `prefix_user_groups` SET `description`='' where `description` is null;"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","ALTER TABLE `prefix_user_groups` CHANGE `description` `description` text collate utf8_unicode_ci NOT NULL"); echo $modifyoutput; flush();ob_flush();
|
||||
|
||||
modify_database("","ALTER TABLE `prefix_user_in_groups` DROP INDEX `user_in_groups_idx1`"); // Don't show output because this key might not exist
|
||||
modify_database("","ALTER TABLE `prefix_user_in_groups` ADD PRIMARY KEY (`ugid`, `uid`)"); // Don't show output because this might already be set
|
||||
modify_database("", "ALTER TABLE `prefix_surveys_languagesettings` ADD `surveyls_numberformat` int(11) NOT NULL DEFAULT 0 AFTER `surveyls_dateformat`"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "CREATE TABLE `prefix_failed_login_attempts` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`ip` varchar(37) NOT NULL,
|
||||
`last_attempt` varchar(20) NOT NULL,
|
||||
`number_attempts` int(11) NOT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=$databasetabletype CHARACTER SET utf8 COLLATE utf8_unicode_ci;"); echo $modifyoutput; flush();ob_flush();
|
||||
upgrade_token_tables145();
|
||||
modify_database("", "UPDATE `prefix_settings_global` SET `stg_value`='145' WHERE stg_name='DBVersion'"); echo $modifyoutput; flush();ob_flush();
|
||||
}
|
||||
|
||||
if ($oldversion < 146) //Modify surveys table
|
||||
{
|
||||
upgrade_timing_tables146();
|
||||
modify_database("", "UPDATE `prefix_settings_global` SET `stg_value`='146' WHERE stg_name='DBVersion'"); echo $modifyoutput; flush();ob_flush();
|
||||
}
|
||||
|
||||
|
||||
echo '<br /><br />'.sprintf($clang->gT('Database update finished (%s)'),date('Y-m-d H:i:s')).'<br />';
|
||||
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 AFTER `datestamp`"); echo $modifyoutput; flush();ob_flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function upgrade_survey_tables118()
|
||||
{
|
||||
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]." CHANGE `token` `token` VARCHAR(15)"); echo $modifyoutput; flush();ob_flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function upgrade_token_tables125()
|
||||
{
|
||||
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 `emailstatus` varchar(300) NOT NULL DEFAULT 'OK'"); echo $modifyoutput; flush();ob_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();ob_flush();
|
||||
modify_database("","ALTER TABLE ".$sv[0]." ADD `remindercount` INT(11) DEFAULT 0"); echo $modifyoutput; flush();ob_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();ob_flush();
|
||||
modify_database("","ALTER TABLE ".$sv[0]." ADD `validuntil` Datetime"); echo $modifyoutput; flush();ob_flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Add the usesleft field to all existing token tables
|
||||
function upgrade_token_tables145()
|
||||
{
|
||||
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 `usesleft` int(11) NOT NULL default '1'"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","UPDATE ".$sv[0]." SET `usesleft`='0' WHERE completed<>'N'"); echo $modifyoutput; flush();ob_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';
|
||||
}
|
||||
|
||||
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();ob_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();ob_flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function upgrade_survey_tables139()
|
||||
{
|
||||
global $modifyoutput,$dbprefix;
|
||||
$surveyidquery = db_select_tables_like($dbprefix."survey\_%");
|
||||
$surveyidresult = db_execute_num($surveyidquery);
|
||||
if (!$surveyidresult) {return "Database Error";}
|
||||
else
|
||||
{
|
||||
while ( $sv = $surveyidresult->FetchRow() )
|
||||
{
|
||||
if (strpos($sv[0],$dbprefix."survey_")!==false)
|
||||
{
|
||||
modify_database("","ALTER TABLE ".$sv[0]." ADD `lastpage` integer"); echo $modifyoutput; flush();ob_flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function upgrade_question_attributes142()
|
||||
{
|
||||
global $modifyoutput,$dbprefix, $connect;
|
||||
$attributequery="Select qid from {$dbprefix}question_attributes where attribute='exclude_all_other' group by qid having count(qid)>1 ";
|
||||
$questionids = db_select_column($attributequery);
|
||||
foreach ($questionids as $questionid)
|
||||
{
|
||||
//Select all affected question attributes
|
||||
$attributevalues=db_select_column("SELECT value from {$dbprefix}question_attributes where attribute='exclude_all_other' and qid=".$questionid);
|
||||
modify_database("","delete from {$dbprefix}question_attributes where attribute='exclude_all_other' and qid=".$questionid); echo $modifyoutput; flush();ob_flush();
|
||||
$record['value']=implode(';',$attributevalues);
|
||||
$record['attribute']='exclude_all_other';
|
||||
$record['qid']=$questionid;
|
||||
$connect->AutoExecute("{$dbprefix}question_attributes", $record, 'INSERT');
|
||||
}
|
||||
}
|
||||
|
||||
function upgrade_tables143()
|
||||
{
|
||||
global $modifyoutput,$dbprefix, $connect;
|
||||
|
||||
|
||||
$aQIDReplacements=array();
|
||||
$answerquery = "select a.*, q.sid, q.gid from {$dbprefix}answers a,{$dbprefix}questions q where a.qid=q.qid and q.type in ('L','O','!') and a.default_value='Y'";
|
||||
$answerresult = db_execute_assoc($answerquery);
|
||||
if (!$answerresult) {return "Database Error";}
|
||||
else
|
||||
{
|
||||
while ( $row = $answerresult->FetchRow() )
|
||||
{
|
||||
modify_database("","INSERT INTO {$dbprefix}defaultvalues (qid, scale_id,language,specialtype,defaultvalue) VALUES ({$row['qid']},0,".db_quoteall($row['language']).",'',".db_quoteall($row['code']).")"); echo $modifyoutput; flush();ob_flush();
|
||||
}
|
||||
}
|
||||
|
||||
// Convert answers to subquestions
|
||||
|
||||
$answerquery = "select a.*, q.sid, q.gid, q.type from {$dbprefix}answers a,{$dbprefix}questions q where a.qid=q.qid and a.language=q.language and q.type in ('1','A','B','C','E','F','H','K',';',':','M','P','Q')";
|
||||
$answerresult = db_execute_assoc($answerquery);
|
||||
if (!$answerresult) {return "Database Error";}
|
||||
else
|
||||
{
|
||||
while ( $row = $answerresult->FetchRow() )
|
||||
{
|
||||
|
||||
$insertarray=array();
|
||||
if (isset($aQIDReplacements[$row['qid'].'_'.$row['code']]))
|
||||
{
|
||||
$insertarray['qid']=$aQIDReplacements[$row['qid'].'_'.$row['code']];
|
||||
}
|
||||
$insertarray['sid']=$row['sid'];
|
||||
$insertarray['gid']=$row['gid'];
|
||||
$insertarray['parent_qid']=$row['qid'];
|
||||
$insertarray['type']=$row['type'];
|
||||
$insertarray['title']=$row['code'];
|
||||
$insertarray['question']=$row['answer'];
|
||||
$insertarray['question_order']=$row['sortorder'];
|
||||
$insertarray['language']=$row['language'];
|
||||
$tablename="{$dbprefix}questions";
|
||||
$query=$connect->GetInsertSQL($tablename,$insertarray);
|
||||
modify_database("",$query); echo $modifyoutput; flush();ob_flush();
|
||||
if (!isset($insertarray['qid']))
|
||||
{
|
||||
$aQIDReplacements[$row['qid'].'_'.$row['code']]=$connect->Insert_ID("{$dbprefix}questions","qid");
|
||||
$iSaveSQID=$aQIDReplacements[$row['qid'].'_'.$row['code']];
|
||||
}
|
||||
else
|
||||
{
|
||||
$iSaveSQID=$insertarray['qid'];
|
||||
}
|
||||
if (($row['type']=='M' || $row['type']=='P') && $row['default_value']=='Y')
|
||||
{
|
||||
modify_database("","INSERT INTO {$dbprefix}defaultvalues (qid, sqid, scale_id,language,specialtype,defaultvalue) VALUES ({$row['qid']},{$iSaveSQID},0,".db_quoteall($row['language']).",'','Y')"); echo $modifyoutput; flush();ob_flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
// Sanitize data
|
||||
modify_database("","delete {$dbprefix}answers from {$dbprefix}answers LEFT join {$dbprefix}questions ON {$dbprefix}answers.qid={$dbprefix}questions.qid where {$dbprefix}questions.type in ('1','F','H','M','P','W','Z')"); echo $modifyoutput; flush();ob_flush();
|
||||
|
||||
// Convert labels to answers
|
||||
$answerquery = "select qid ,type ,lid ,lid1, language from {$dbprefix}questions where parent_qid=0 and type in ('1','F','H','M','P','W','Z')";
|
||||
$answerresult = db_execute_assoc($answerquery);
|
||||
if (!$answerresult)
|
||||
{
|
||||
return "Database Error";
|
||||
}
|
||||
else
|
||||
{
|
||||
while ( $row = $answerresult->FetchRow() )
|
||||
{
|
||||
$labelquery="Select * from {$dbprefix}labels where lid={$row['lid']} and language=".db_quoteall($row['language']);
|
||||
$labelresult = db_execute_assoc($labelquery);
|
||||
while ( $lrow = $labelresult->FetchRow() )
|
||||
{
|
||||
modify_database("","INSERT INTO {$dbprefix}answers (qid, code, answer, sortorder, language, assessment_value) VALUES ({$row['qid']},".db_quoteall($lrow['code']).",".db_quoteall($lrow['title']).",{$lrow['sortorder']},".db_quoteall($lrow['language']).",{$lrow['assessment_value']})"); echo $modifyoutput; flush();ob_flush();
|
||||
//$labelids[]
|
||||
}
|
||||
if ($row['type']=='1')
|
||||
{
|
||||
$labelquery="Select * from {$dbprefix}labels where lid={$row['lid1']} and language=".db_quoteall($row['language']);
|
||||
$labelresult = db_execute_assoc($labelquery);
|
||||
while ( $lrow = $labelresult->FetchRow() )
|
||||
{
|
||||
modify_database("","INSERT INTO {$dbprefix}answers (qid, code, answer, sortorder, language, scale_id, assessment_value) VALUES ({$row['qid']},".db_quoteall($lrow['code']).",".db_quoteall($lrow['title']).",{$lrow['sortorder']},".db_quoteall($lrow['language']).",1,{$lrow['assessment_value']})"); echo $modifyoutput; flush();ob_flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Convert labels to subquestions
|
||||
$answerquery = "select * from {$dbprefix}questions where parent_qid=0 and type in (';',':')";
|
||||
$answerresult = db_execute_assoc($answerquery);
|
||||
if (!$answerresult)
|
||||
{
|
||||
return "Database Error";
|
||||
}
|
||||
else
|
||||
{
|
||||
while ( $row = $answerresult->FetchRow() )
|
||||
{
|
||||
$labelquery="Select * from {$dbprefix}labels where lid={$row['lid']} and language=".db_quoteall($row['language']);
|
||||
$labelresult = db_execute_assoc($labelquery);
|
||||
while ( $lrow = $labelresult->FetchRow() )
|
||||
{
|
||||
$insertarray=array();
|
||||
if (isset($aQIDReplacements[$row['qid'].'_'.$lrow['code'].'_1']))
|
||||
{
|
||||
$insertarray['qid']=$aQIDReplacements[$row['qid'].'_'.$lrow['code'].'_1'];
|
||||
}
|
||||
$insertarray['sid']=$row['sid'];
|
||||
$insertarray['gid']=$row['gid'];
|
||||
$insertarray['parent_qid']=$row['qid'];
|
||||
$insertarray['type']=$row['type'];
|
||||
$insertarray['title']=$lrow['code'];
|
||||
$insertarray['question']=$lrow['title'];
|
||||
$insertarray['question_order']=$lrow['sortorder'];
|
||||
$insertarray['language']=$lrow['language'];
|
||||
$insertarray['scale_id']=1;
|
||||
$tablename="{$dbprefix}questions";
|
||||
$query=$connect->GetInsertSQL($tablename,$insertarray);
|
||||
modify_database("",$query); echo $modifyoutput; flush();ob_flush();
|
||||
if (isset($insertarray['qid']))
|
||||
{
|
||||
$aQIDReplacements[$row['qid'].'_'.$lrow['code'].'_1']=$connect->Insert_ID("{$dbprefix}questions","qid");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
$updatequery = "update {$dbprefix}questions set type='!' where type='W'";
|
||||
modify_database("",$updatequery); echo $modifyoutput; flush();ob_flush();
|
||||
$updatequery = "update {$dbprefix}questions set type='L' where type='Z'";
|
||||
modify_database("",$updatequery); echo $modifyoutput; flush();ob_flush();
|
||||
|
||||
// Now move all non-standard templates to the /upload dir
|
||||
global $usertemplaterootdir, $standardtemplates,$standardtemplaterootdir;
|
||||
|
||||
if (!$usertemplaterootdir) {die("gettemplatelist() no template directory");}
|
||||
if ($handle = opendir($standardtemplaterootdir))
|
||||
{
|
||||
while (false !== ($file = readdir($handle)))
|
||||
{
|
||||
if (!is_file("$standardtemplaterootdir/$file") && $file != "." && $file != ".." && $file!=".svn" && !isStandardTemplate($file))
|
||||
{
|
||||
if (!rename($standardtemplaterootdir.DIRECTORY_SEPARATOR.$file,$usertemplaterootdir.DIRECTORY_SEPARATOR.$file))
|
||||
{
|
||||
echo "There was a problem moving directory '".$standardtemplaterootdir.DIRECTORY_SEPARATOR.$file."' to '".$usertemplaterootdir.DIRECTORY_SEPARATOR.$file."' due to missing permissions. Please do this manually.<br />";
|
||||
};
|
||||
}
|
||||
}
|
||||
closedir($handle);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function upgrade_timing_tables146()
|
||||
{
|
||||
global $modifyoutput,$dbprefix, $connect;
|
||||
$aTimingTables=$connect->MetaTables('TABLES',false, "%timings");
|
||||
foreach ($aTimingTables as $sTable) {
|
||||
modify_database("","ALTER TABLE {$sTable} CHANGE `interviewTime` `interviewtime` DOUBLE NULL default 0;"); echo $modifyoutput; flush();ob_flush();
|
||||
}
|
||||
}
|
||||
571
include/limesurvey/admin/update/upgrade-postgres.php
Normal file
571
include/limesurvey/admin/update/upgrade-postgres.php
Normal file
@@ -0,0 +1,571 @@
|
||||
<?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 3631 2007-11-12 18:13:06Z 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) {
|
||||
global $modifyoutput, $databasename, $databasetabletype, $clang;
|
||||
|
||||
|
||||
if ($oldversion < 127) {
|
||||
modify_database("","create index answers_idx2 on prefix_answers (sortorder)"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","create index assessments_idx2 on prefix_assessments (sid)"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","create index assessments_idx on prefix_assessments (gid)"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","create index conditions_idx2 on prefix_conditions (qid)"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","create index conditions_idx3 on prefix_conditions (cqid)"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","create index groups_idx2 on prefix_groups (sid)"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","create index question_attributes_idx2 on prefix_question_attributes (qid)"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","create index questions_idx2 on prefix_questions (sid)"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","create index questions_idx3 on prefix_questions (gid)"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","create index questions_idx4 on prefix_questions (type)"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","create index quota_idx2 on prefix_quota (sid)"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","create index saved_control_idx2 on prefix_saved_control (sid)"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","create index user_in_groups_idx1 on prefix_user_in_groups (ugid, uid)"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","update prefix_settings_global set stg_value='127' where stg_name='DBVersion'"); echo $modifyoutput; flush();ob_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();ob_flush();
|
||||
}
|
||||
|
||||
if ($oldversion < 129) {
|
||||
//129
|
||||
modify_database("","ALTER TABLE prefix_surveys ADD startdate date"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","ALTER TABLE prefix_surveys ADD usestartdate char(1) NOT NULL default 'N'"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","update prefix_settings_global set stg_value='129' where stg_name='DBVersion'"); echo $modifyoutput; flush();ob_flush();
|
||||
}
|
||||
|
||||
if ($oldversion < 130)
|
||||
{
|
||||
modify_database("","ALTER TABLE prefix_conditions ADD scenario integer NOT NULL default '1'"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","UPDATE prefix_conditions SET scenario=1 where (scenario is null) or scenario=0"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","update prefix_settings_global set stg_value='130' where stg_name='DBVersion'"); echo $modifyoutput; flush();ob_flush();
|
||||
}
|
||||
if ($oldversion < 131)
|
||||
{
|
||||
modify_database("","ALTER TABLE prefix_surveys ADD publicstatistics char(1) NOT NULL default 'N'"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","update prefix_settings_global set stg_value='131' where stg_name='DBVersion'"); echo $modifyoutput; flush();ob_flush();
|
||||
}
|
||||
if ($oldversion < 132)
|
||||
{
|
||||
modify_database("","ALTER TABLE prefix_surveys ADD publicgraphs char(1) NOT NULL default 'N'"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","update prefix_settings_global set stg_value='132' where stg_name='DBVersion'"); echo $modifyoutput; flush();ob_flush();
|
||||
}
|
||||
if ($oldversion < 133)
|
||||
{
|
||||
modify_database("","ALTER TABLE prefix_users ADD one_time_pw bytea"); echo $modifyoutput; flush();ob_flush();
|
||||
|
||||
// Add new assessment setting
|
||||
modify_database("","ALTER TABLE prefix_surveys ADD assessments char(1) NOT NULL default 'N'"); echo $modifyoutput; flush();ob_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();ob_flush();
|
||||
modify_database("","ALTER TABLE prefix_labels ADD assessment_value integer NOT NULL default '0'"); echo $modifyoutput; flush();ob_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();ob_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();ob_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();ob_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();ob_flush();
|
||||
// drop the old link field
|
||||
modify_database("","ALTER TABLE prefix_assessments DROP COLUMN link"); echo $modifyoutput; flush();ob_flush();
|
||||
// change the primary index to include language
|
||||
modify_database("","ALTER TABLE prefix_assessments DROP CONSTRAINT prefix_assessments_pkey"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","ALTER TABLE prefix_assessments ADD CONSTRAINT prefix_assessments_pkey PRIMARY KEY (id,language)"); echo $modifyoutput; flush();ob_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();ob_flush();
|
||||
modify_database("","ALTER TABLE prefix_surveys_languagesettings ADD surveyls_endtext text"); echo $modifyoutput; flush();ob_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();ob_flush();
|
||||
// drop old URL field
|
||||
modify_database("","ALTER TABLE prefix_surveys DROP COLUMN url"); echo $modifyoutput; flush();ob_flush();
|
||||
|
||||
modify_database("","update prefix_settings_global set stg_value='133' where stg_name='DBVersion'"); echo $modifyoutput; flush();ob_flush();
|
||||
}
|
||||
|
||||
if ($oldversion < 134)
|
||||
{
|
||||
modify_database("","ALTER TABLE prefix_surveys ADD usetokens char(1) NOT NULL default 'N'"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","ALTER TABLE prefix_surveys ADD attributedescriptions TEXT;"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","ALTER TABLE prefix_surveys DROP COLUMN attribute1"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","ALTER TABLE prefix_surveys DROP COLUMN attribute2"); echo $modifyoutput; flush();ob_flush();
|
||||
upgrade_token_tables134();
|
||||
modify_database("","update prefix_settings_global set stg_value='134' where stg_name='DBVersion'"); echo $modifyoutput; flush();ob_flush();
|
||||
|
||||
}
|
||||
if ($oldversion < 135)
|
||||
{
|
||||
modify_database("","ALTER TABLE prefix_question_attributes ALTER COLUMN value TYPE text"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","update prefix_settings_global set stg_value='135' where stg_name='DBVersion'"); echo $modifyoutput; flush();ob_flush();
|
||||
}
|
||||
if ($oldversion < 136)
|
||||
{
|
||||
modify_database("","ALTER TABLE prefix_quota ADD autoload_url integer NOT NULL DEFAULT 0"); echo $modifyoutput; flush();ob_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();ob_flush();
|
||||
modify_database("","ALTER TABLE ONLY prefix_quota_languagesettings
|
||||
ADD CONSTRAINT prefix_quota_languagesettings_pkey PRIMARY KEY (quotals_id);"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","ALTER TABLE ONLY prefix_users ADD CONSTRAINT prefix_users_pkey PRIMARY KEY (uid)"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","ALTER TABLE ONLY prefix_users ADD CONSTRAINT prefix_user_name_key UNIQUE (users_name)"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","update prefix_settings_global set stg_value='136' where stg_name='DBVersion'"); echo $modifyoutput; flush();ob_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();ob_flush();
|
||||
modify_database("", "ALTER TABLE prefix_users ADD \"dateformat\" integer NOT NULL default 1"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "update prefix_surveys set startdate=null where usestartdate='N'"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "update prefix_surveys set expires=null where useexpiry='N'"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "ALTER TABLE prefix_surveys DROP COLUMN usestartdate"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "ALTER TABLE prefix_surveys DROP COLUMN useexpiry"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "update prefix_settings_global set stg_value='137' where stg_name='DBVersion'"); echo $modifyoutput; flush();ob_flush();
|
||||
}
|
||||
|
||||
if ($oldversion < 138) //Modify quota field
|
||||
{
|
||||
modify_database("", "ALTER TABLE prefix_quota_members ALTER COLUMN code TYPE character varying(11)"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "UPDATE prefix_settings_global SET stg_value='138' WHERE stg_name='DBVersion'"); echo $modifyoutput; flush();ob_flush();
|
||||
}
|
||||
|
||||
if ($oldversion < 139) //Modify quota field
|
||||
{
|
||||
upgrade_survey_tables139();
|
||||
modify_database("", "UPDATE prefix_settings_global SET stg_value='139' WHERE stg_name='DBVersion'"); echo $modifyoutput; flush();ob_flush();
|
||||
}
|
||||
|
||||
if ($oldversion < 140) //Modify surveys table
|
||||
{
|
||||
modify_database("", "ALTER TABLE prefix_surveys ADD \"emailresponseto\" TEXT"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "UPDATE prefix_settings_global SET stg_value='140' WHERE stg_name='DBVersion'"); echo $modifyoutput; flush();ob_flush();
|
||||
}
|
||||
|
||||
if ($oldversion < 141) //Modify surveys table
|
||||
{
|
||||
modify_database("", "ALTER TABLE prefix_surveys ADD \"tokenlength\" smallint NOT NULL DEFAULT '15'"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "UPDATE prefix_settings_global SET stg_value='141' WHERE stg_name='DBVersion'"); echo $modifyoutput; flush();ob_flush();
|
||||
}
|
||||
|
||||
if ($oldversion < 142) //Modify surveys table
|
||||
{
|
||||
upgrade_question_attributes142();
|
||||
modify_database("", "ALTER TABLE prefix_surveys ALTER COLUMN \"startdate\" TYPE timestamp"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "ALTER TABLE prefix_surveys ALTER COLUMN \"expires\" TYPE timestamp"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "UPDATE prefix_question_attributes SET value='0' WHERE value='false'"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "UPDATE prefix_question_attributes SET value='1' WHERE value='true'"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "UPDATE prefix_settings_global SET stg_value='142' WHERE stg_name='DBVersion'"); echo $modifyoutput; flush();ob_flush();
|
||||
}
|
||||
if ($oldversion < 143) //Modify surveys table
|
||||
{
|
||||
modify_database("", "ALTER TABLE prefix_questions ADD parent_qid integer NOT NULL default '0'"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "ALTER TABLE prefix_answers ADD scale_id smallint NOT NULL default '0'"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "ALTER TABLE prefix_questions ADD scale_id smallint NOT NULL default '0'"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "ALTER TABLE prefix_questions ADD same_default smallint NOT NULL default '0'"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "ALTER TABLE prefix_answers DROP CONSTRAINT prefix_answers_pkey"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "ALTER TABLE prefix_answers ADD CONSTRAINT prefix_answers_pkey PRIMARY KEY (qid,code,language,scale_id)"); echo $modifyoutput; flush();ob_flush();
|
||||
|
||||
modify_database("", "CREATE TABLE prefix_defaultvalues (
|
||||
qid integer NOT NULL default '0',
|
||||
scale_id integer NOT NULL default '0',
|
||||
sqid integer NOT NULL default '0',
|
||||
language character varying(20) NOT NULL,
|
||||
specialtype character varying(20) NOT NULL default '',
|
||||
defaultvalue text)"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","ALTER TABLE prefix_defaultvalues ADD CONSTRAINT prefix_defaultvalues_pkey PRIMARY KEY (qid , scale_id, language, specialtype, sqid)"); echo $modifyoutput; flush();ob_flush();
|
||||
|
||||
// -Move all 'answers' that are subquestions to the questions table
|
||||
// -Move all 'labels' that are answers to the answers table
|
||||
// -Transscribe the default values where applicable
|
||||
// -Move default values from answers to questions
|
||||
upgrade_tables143();
|
||||
|
||||
modify_database("", "ALTER TABLE prefix_answers DROP COLUMN default_value"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "ALTER TABLE prefix_questions DROP COLUMN lid"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "ALTER TABLE prefix_questions DROP COLUMN lid1"); echo $modifyoutput; flush();ob_flush();
|
||||
// add field for timings and table for extended conditions
|
||||
modify_database("", "ALTER TABLE prefix_surveys ADD savetimings char(1) default 'N'"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "CREATE TABLE prefix_sessions(
|
||||
sesskey VARCHAR( 64 ) NOT NULL DEFAULT '',
|
||||
expiry TIMESTAMP NOT NULL ,
|
||||
expireref VARCHAR( 250 ) DEFAULT '',
|
||||
created TIMESTAMP NOT NULL ,
|
||||
modified TIMESTAMP NOT NULL ,
|
||||
sessdata TEXT DEFAULT '',
|
||||
PRIMARY KEY ( sesskey )
|
||||
);"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "create INDEX sess2_expiry on prefix_sessions( expiry );"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "create INDEX sess2_expireref on prefix_sessions ( expireref );"); echo $modifyoutput; flush();ob_flush();
|
||||
|
||||
modify_database("", "UPDATE prefix_settings_global SET stg_value='143' WHERE stg_name='DBVersion'"); echo $modifyoutput; flush();ob_flush();
|
||||
|
||||
|
||||
|
||||
}
|
||||
if ($oldversion < 145)
|
||||
{
|
||||
modify_database("", "ALTER TABLE prefix_surveys ADD savetimings CHAR(1) NULL default 'N'"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "ALTER TABLE prefix_surveys ADD showXquestions CHAR(1) NULL default 'Y'"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "ALTER TABLE prefix_surveys ADD showgroupinfo CHAR(1) NULL default 'B'"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "ALTER TABLE prefix_surveys ADD shownoanswer CHAR(1) NULL default 'Y'"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "ALTER TABLE prefix_surveys ADD showqnumcode CHAR(1) NULL default 'X'"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "ALTER TABLE prefix_surveys ADD bouncetime bigint NULL"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "ALTER TABLE prefix_surveys ADD bounceprocessing character varying(1) NULL default 'N'"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "ALTER TABLE prefix_surveys ADD bounceaccounttype character varying(4) NULL"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "ALTER TABLE prefix_surveys ADD bounceaccounthost character varying(200) NULL"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "ALTER TABLE prefix_surveys ADD bounceaccountpass character varying(100) NULL"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "ALTER TABLE prefix_surveys ADD bounceaccountencryption character varying(3) NULL"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "ALTER TABLE prefix_surveys ADD bounceaccountuser character varying(200) NULL"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "ALTER TABLE prefix_surveys ADD showwelcome CHAR(1) NULL default 'Y'"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "ALTER TABLE prefix_surveys ADD showprogress CHAR(1) NULL default 'Y'"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "ALTER TABLE prefix_surveys ADD allowjumps CHAR(1) NULL default 'N'"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "ALTER TABLE prefix_surveys ADD navigationdelay smallint NOT NULL default '0'"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "ALTER TABLE prefix_surveys ADD nokeyboard char(1) default 'N'"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "ALTER TABLE prefix_surveys ADD alloweditaftercompletion char(1) default 'N'"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "CREATE TABLE prefix_survey_permissions (
|
||||
sid integer DEFAULT 0 NOT NULL,
|
||||
uid integer DEFAULT 0 NOT NULL,
|
||||
permission character varying(20) NOT NULL,
|
||||
create_p integer DEFAULT 0 NOT NULL,
|
||||
read_p integer DEFAULT 0 NOT NULL,
|
||||
update_p integer DEFAULT 0 NOT NULL,
|
||||
delete_p integer DEFAULT 0 NOT NULL,
|
||||
import_p integer DEFAULT 0 NOT NULL,
|
||||
export_p integer DEFAULT 0 NOT NULL
|
||||
);"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "ALTER TABLE ONLY prefix_survey_permissions ADD CONSTRAINT prefix_survey_permissions_pkey PRIMARY KEY (sid,uid,permission);"); echo $modifyoutput; flush();ob_flush();
|
||||
upgrade_surveypermissions_table145();
|
||||
|
||||
// drop the old survey rights table
|
||||
modify_database("", "DROP TABLE prefix_surveys_rights"); echo $modifyoutput; flush();ob_flush();
|
||||
|
||||
// Add new fields for email templates
|
||||
modify_database("", "ALTER TABLE prefix_surveys_languagesettings ADD email_admin_notification_subj character varying(255)");
|
||||
modify_database("", "ALTER TABLE prefix_surveys_languagesettings ADD email_admin_responses_subj character varying(255)");
|
||||
modify_database("", "ALTER TABLE prefix_surveys_languagesettings ADD email_admin_notification text");
|
||||
modify_database("", "ALTER TABLE prefix_surveys_languagesettings ADD email_admin_responses text");
|
||||
|
||||
//Add index to questions table to speed up subquestions
|
||||
modify_database("", "create INDEX parent_qid_idx on prefix_questions( parent_qid );"); echo $modifyoutput; flush();ob_flush();
|
||||
|
||||
modify_database("", "ALTER TABLE prefix_surveys ADD emailnotificationto text DEFAULT NULL"); echo $modifyoutput; flush();ob_flush();
|
||||
upgrade_survey_table145();
|
||||
modify_database("", "ALTER TABLE prefix_surveys DROP COLUMN notification"); echo $modifyoutput; flush();ob_flush();
|
||||
|
||||
modify_database("","ALTER TABLE prefix_conditions ALTER COLUMN method TYPE CHAR(5)"); echo $modifyoutput; flush();ob_flush();
|
||||
|
||||
modify_database("","UPDATE prefix_surveys set private='N' where private is NULL;"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","ALTER TABLE prefix_surveys RENAME COLUMN private TO anonymized;"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","ALTER TABLE prefix_surveys ALTER COLUMN anonymized TYPE char(1);"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","ALTER TABLE prefix_surveys ALTER COLUMN anonymized SET DEFAULT 'N';"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","ALTER TABLE prefix_surveys ALTER COLUMN anonymized SET NOT NULL ;"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "CREATE TABLE prefix_failed_login_attempts (
|
||||
id serial PRIMARY KEY NOT NULL,
|
||||
ip character varying(37) NOT NULL,
|
||||
last_attempt character varying(20) NOT NULL,
|
||||
number_attempts integer NOT NULL
|
||||
);"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("", "ALTER TABLE prefix_surveys_languagesettings ADD surveyls_numberformat integer default 0 NOT NULL"); echo $modifyoutput; flush();ob_flush();
|
||||
upgrade_token_tables145();
|
||||
modify_database("", "UPDATE prefix_settings_global SET stg_value='145' WHERE stg_name='DBVersion'"); echo $modifyoutput; flush();ob_flush();
|
||||
}
|
||||
|
||||
if ($oldversion < 146) //Modify surveys table
|
||||
{
|
||||
upgrade_timing_tables146();
|
||||
modify_database("", "UPDATE prefix_settings_global SET stg_value='146' WHERE stg_name='DBVersion'"); echo $modifyoutput; flush();ob_flush();
|
||||
}
|
||||
|
||||
|
||||
echo '<br /><br />'.sprintf($clang->gT('Database update finished (%s)'),date('Y-m-d H:i:s')).'<br />';
|
||||
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 ".$sv['0']." ADD remindersent character varying(17) DEFAULT 'N'"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","ALTER TABLE ".$sv['0']." ADD remindercount INTEGER DEFAULT 0"); echo $modifyoutput; flush();ob_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();ob_flush();
|
||||
modify_database("","ALTER TABLE ".$sv[0]." ADD validuntil timestamp"); echo $modifyoutput; flush();ob_flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
// Add the usesleft field to all existing token tables
|
||||
function upgrade_token_tables145()
|
||||
{
|
||||
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 usesleft integer DEFAULT 1 NOT NULL"); echo $modifyoutput; flush();ob_flush();
|
||||
modify_database("","UPDATE ".$sv[0]." SET usesleft=0 WHERE completed<>'N'"); echo $modifyoutput; flush();ob_flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function upgrade_survey_tables139()
|
||||
{
|
||||
global $modifyoutput,$dbprefix;
|
||||
$surveyidquery = db_select_tables_like($dbprefix."survey\_%");
|
||||
$surveyidresult = db_execute_num($surveyidquery);
|
||||
if (!$surveyidresult) {return "Database Error";}
|
||||
else
|
||||
{
|
||||
while ( $sv = $surveyidresult->FetchRow() )
|
||||
{
|
||||
modify_database("","ALTER TABLE ".$sv[0]." ADD lastpage integer"); echo $modifyoutput; flush();ob_flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function upgrade_question_attributes142()
|
||||
{
|
||||
global $modifyoutput,$dbprefix, $connect;
|
||||
$attributequery="Select qid from {$dbprefix}question_attributes where attribute='exclude_all_other' group by qid having count(qid)>1 ";
|
||||
$questionids = db_select_column($attributequery);
|
||||
foreach ($questionids as $questionid)
|
||||
{
|
||||
//Select all affected question attributes
|
||||
$attributevalues=db_select_column("SELECT value from {$dbprefix}question_attributes where attribute='exclude_all_other' and qid=".$questionid);
|
||||
modify_database("","delete from {$dbprefix}question_attributes where attribute='exclude_all_other' and qid=".$questionid); echo $modifyoutput; flush();ob_flush();
|
||||
$record['value']=implode(';',$attributevalues);
|
||||
$record['attribute']='exclude_all_other';
|
||||
$record['qid']=$questionid;
|
||||
$connect->AutoExecute("{$dbprefix}question_attributes", $record, 'INSERT');
|
||||
}
|
||||
}
|
||||
|
||||
function upgrade_tables143()
|
||||
{
|
||||
global $modifyoutput,$dbprefix, $connect;
|
||||
|
||||
|
||||
$aQIDReplacements=array();
|
||||
$answerquery = "select a.*, q.sid, q.gid from {$dbprefix}answers a,{$dbprefix}questions q where a.qid=q.qid and q.type in ('L','O','!') and a.default_value='Y'";
|
||||
$answerresult = db_execute_assoc($answerquery);
|
||||
if (!$answerresult) {return "Database Error";}
|
||||
else
|
||||
{
|
||||
while ( $row = $answerresult->FetchRow() )
|
||||
{
|
||||
modify_database("","INSERT INTO {$dbprefix}defaultvalues (qid, scale_id,language,specialtype,defaultvalue) VALUES ({$row['qid']},0,".db_quoteall($row['language']).",'',".db_quoteall($row['code']).")"); echo $modifyoutput; flush();ob_flush();
|
||||
}
|
||||
}
|
||||
|
||||
// Convert answers to subquestions
|
||||
|
||||
$answerquery = "select a.*, q.sid, q.gid, q.type from {$dbprefix}answers a,{$dbprefix}questions q where a.qid=q.qid and a.language=q.language and q.type in ('1','A','B','C','E','F','H','K',';',':','M','P','Q')";
|
||||
$answerresult = db_execute_assoc($answerquery);
|
||||
if (!$answerresult) {return "Database Error";}
|
||||
else
|
||||
{
|
||||
while ( $row = $answerresult->FetchRow() )
|
||||
{
|
||||
|
||||
$insertarray=array();
|
||||
if (isset($aQIDReplacements[$row['qid'].'_'.$row['code']]))
|
||||
{
|
||||
$insertarray['qid']=$aQIDReplacements[$row['qid'].'_'.$row['code']];
|
||||
}
|
||||
$insertarray['sid']=$row['sid'];
|
||||
$insertarray['gid']=$row['gid'];
|
||||
$insertarray['type']=$row['type'];
|
||||
$insertarray['parent_qid']=$row['qid'];
|
||||
$insertarray['title']=$row['code'];
|
||||
$insertarray['question']=$row['answer'];
|
||||
$insertarray['question_order']=$row['sortorder'];
|
||||
$insertarray['language']=$row['language'];
|
||||
$tablename="{$dbprefix}questions";
|
||||
$query=$connect->GetInsertSQL($tablename,$insertarray);
|
||||
modify_database("",$query); echo $modifyoutput; flush();ob_flush();
|
||||
if (!isset($insertarray['qid']))
|
||||
{
|
||||
$aQIDReplacements[$row['qid'].'_'.$row['code']]=$connect->Insert_ID("{$dbprefix}questions","qid");
|
||||
$iSaveSQID=$aQIDReplacements[$row['qid'].'_'.$row['code']];
|
||||
}
|
||||
else
|
||||
{
|
||||
$iSaveSQID=$insertarray['qid'];
|
||||
}
|
||||
if (($row['type']=='M' || $row['type']=='P') && $row['default_value']=='Y')
|
||||
{
|
||||
modify_database("","INSERT INTO {$dbprefix}defaultvalues (qid, sqid, scale_id,language,specialtype,defaultvalue) VALUES ({$row['qid']},{$iSaveSQID},0,".db_quoteall($row['language']).",'','Y')"); echo $modifyoutput; flush();ob_flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
modify_database("","delete from {$dbprefix}answers using {$dbprefix}questions where {$dbprefix}answers.qid={$dbprefix}questions.qid and {$dbprefix}questions.type in ('1','A','B','C','E','F','H',';',':')"); echo $modifyoutput; flush();ob_flush();
|
||||
|
||||
// Convert labels to answers
|
||||
$answerquery = "select qid ,type ,lid ,lid1, language from {$dbprefix}questions where parent_qid=0 and type in ('1','F','H','M','P','W','Z')";
|
||||
$answerresult = db_execute_assoc($answerquery);
|
||||
if (!$answerresult)
|
||||
{
|
||||
return "Database Error";
|
||||
}
|
||||
else
|
||||
{
|
||||
while ( $row = $answerresult->FetchRow() )
|
||||
{
|
||||
$labelquery="Select * from {$dbprefix}labels where lid={$row['lid']} and language=".db_quoteall($row['language']);
|
||||
$labelresult = db_execute_assoc($labelquery);
|
||||
while ( $lrow = $labelresult->FetchRow() )
|
||||
{
|
||||
modify_database("","INSERT INTO {$dbprefix}answers (qid, code, answer, sortorder, language, assessment_value) VALUES ({$row['qid']},".db_quoteall($lrow['code']).",".db_quoteall($lrow['title']).",{$lrow['sortorder']},".db_quoteall($lrow['language']).",{$lrow['assessment_value']})"); echo $modifyoutput; flush();ob_flush();
|
||||
//$labelids[]
|
||||
}
|
||||
if ($row['type']=='1')
|
||||
{
|
||||
$labelquery="Select * from {$dbprefix}labels where lid={$row['lid1']} and language=".db_quoteall($row['language']);
|
||||
$labelresult = db_execute_assoc($labelquery);
|
||||
while ( $lrow = $labelresult->FetchRow() )
|
||||
{
|
||||
modify_database("","INSERT INTO {$dbprefix}answers (qid, code, answer, sortorder, language, scale_id, assessment_value) VALUES ({$row['qid']},".db_quoteall($lrow['code']).",".db_quoteall($lrow['title']).",{$lrow['sortorder']},".db_quoteall($lrow['language']).",1,{$lrow['assessment_value']})"); echo $modifyoutput; flush();ob_flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Convert labels to subquestions
|
||||
$answerquery = "select * from {$dbprefix}questions where parent_qid=0 and type in (';',':')";
|
||||
$answerresult = db_execute_assoc($answerquery);
|
||||
if (!$answerresult)
|
||||
{
|
||||
return "Database Error";
|
||||
}
|
||||
else
|
||||
{
|
||||
while ( $row = $answerresult->FetchRow() )
|
||||
{
|
||||
$labelquery="Select * from {$dbprefix}labels where lid={$row['lid']} and language=".db_quoteall($row['language']);
|
||||
$labelresult = db_execute_assoc($labelquery);
|
||||
while ( $lrow = $labelresult->FetchRow() )
|
||||
{
|
||||
$insertarray=array();
|
||||
if (isset($aQIDReplacements[$row['qid'].'_'.$lrow['code'].'_1']))
|
||||
{
|
||||
$insertarray['qid']=$aQIDReplacements[$row['qid'].'_'.$lrow['code'].'_1'];
|
||||
}
|
||||
$insertarray['sid']=$row['sid'];
|
||||
$insertarray['type']=$row['type'];
|
||||
$insertarray['gid']=$row['gid'];
|
||||
$insertarray['parent_qid']=$row['qid'];
|
||||
$insertarray['title']=$lrow['code'];
|
||||
$insertarray['question']=$lrow['title'];
|
||||
$insertarray['question_order']=$lrow['sortorder'];
|
||||
$insertarray['language']=$lrow['language'];
|
||||
$insertarray['scale_id']=1;
|
||||
$tablename="{$dbprefix}questions";
|
||||
$query=$connect->GetInsertSQL($tablename,$insertarray);
|
||||
modify_database("",$query); echo $modifyoutput; flush();ob_flush();
|
||||
if (isset($insertarray['qid']))
|
||||
{
|
||||
$aQIDReplacements[$row['qid'].'_'.$lrow['code'].'_1']=$connect->Insert_ID("{$dbprefix}questions","qid");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
$updatequery = "update {$dbprefix}questions set type='!' where type='W'";
|
||||
modify_database("",$updatequery); echo $modifyoutput; flush();ob_flush();
|
||||
$updatequery = "update {$dbprefix}questions set type='L' where type='Z'";
|
||||
modify_database("",$updatequery); echo $modifyoutput; flush();ob_flush();
|
||||
|
||||
// Now move all non-standard templates to the /upload dir
|
||||
global $usertemplaterootdir, $standardtemplates,$standardtemplaterootdir;
|
||||
|
||||
if (!$usertemplaterootdir) {die("gettemplatelist() no template directory");}
|
||||
if ($handle = opendir($standardtemplaterootdir))
|
||||
{
|
||||
while (false !== ($file = readdir($handle)))
|
||||
{
|
||||
if (!is_file("$standardtemplaterootdir/$file") && $file != "." && $file != ".." && $file!=".svn" && !isStandardTemplate($file))
|
||||
{
|
||||
if (!rename($standardtemplaterootdir.DIRECTORY_SEPARATOR.$file,$usertemplaterootdir.DIRECTORY_SEPARATOR.$file))
|
||||
{
|
||||
echo "There was a problem moving directory '".$standardtemplaterootdir.DIRECTORY_SEPARATOR.$file."' to '".$usertemplaterootdir.DIRECTORY_SEPARATOR.$file."' due to missing permissions. Please do this manually.<br />";
|
||||
};
|
||||
}
|
||||
}
|
||||
closedir($handle);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function upgrade_timing_tables146()
|
||||
{
|
||||
global $modifyoutput,$dbprefix, $connect;
|
||||
$aTimingTables=$connect->MetaTables('TABLES',false, "%timings");
|
||||
foreach ($aTimingTables as $sTable) {
|
||||
modify_database("","ALTER TABLE {$sTable} RENAME COLUMN \"interviewTime\" TO interviewtime;"); echo $modifyoutput; flush();ob_flush();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user