'.$clang->gT('Welcome to the ComfortUpdate').'

'; $output.=$clang->gT('The LimeSurvey ComfortUpdate is an easy procedure to quickly update to the latest version of LimeSurvey.').'
'; $output.=$clang->gT('The following steps will be done by this update:').'
'; $output.='

'.$clang->gT('Checking basic requirements...').'

'; if ($updatekey==''){ $output.=$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.'); $output.="
'; $output.='
'; } else { $output.="

'.$clang->gT('Change log').'

'; 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); $output.=''; } else { print( $httperror ); } } if ($error) { $output.='

'.$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.'); $output.="

"; } else { $output.='

'.$clang->gT('Everything looks alright. Please proceed to the next step.'); $output.="

"; } $output.='
'; return $output; } 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'); $output='
'.$clang->gT('ComfortUpdate Step 2').'

'; $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'])) { $output.=$clang->gT('On requesting the update information from limesurvey.org there has been an error:').'
'; if ($updateinfo['error']==1) { setGlobalSetting('updatekey',''); $output.=$clang->gT('Your update key is invalid and was removed. ').'
'; } else $output.=$clang->gT('On requesting the update information from limesurvey.org there has been an error:').'
'; } // 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'])) { $output.="
".$clang->gT('Update server busy')."

".$clang->gT('The update server seems to be currently busy . This happens most likely if the necessary update files for a new version are prepared.')."
".$clang->gT('Please be patient and try again in about 10 minutes.')."

"; } 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; } } $output.='

'.$clang->gT('Checking existing LimeSurvey files...').'

'; if (count($readonlyfiles)>0) { $output.=''.$clang->gT('Warning: The following files/directories need to be updated but their permissions are set to read-only.').'
'; $output.=$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.').'
'; $output.='
'; } if (count($existingfiles)>0) { $output.=$clang->gT('The following files would be added by the update but already exist. This is very unusual and may be co-incidental.').'
'; $output.=$clang->gT('We recommend that these files should be replaced by the update procedure.').'
'; $output.=''; } if (count($modifiedfiles)>0) { $output.=$clang->gT('The following files will be modified or deleted but were already modified by someone else.').'
'; $output.=$clang->gT('We recommend that these files should be replaced by the update procedure.').'
'; $output.=''; } if (count($readonlyfiles)>0) { $output.='
'.$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.'); $output.="

"; } else { $output.=$clang->gT('Please check any problems above and then proceed to the next step.').'
'; $output.="

"; } } $_SESSION['updateinfo']=$updateinfo; $_SESSION['updatesession']=$site_cookies; return $output; } function UpdateStep3() { global $clang, $scriptname, $homedir, $buildnumber, $updatebuild, $debug, $rootdir, $publicdir, $tempdir, $database_exists, $databasetype, $action, $demoModeOnly; $output='
'.$clang->gT('ComfortUpdate Step 3').'
'; $output.='

'.$clang->gT('Creating DB & file backup').'

'; if (!isset( $_SESSION['updateinfo'])) { $output.=$clang->gT('On requesting the update information from limesurvey.org there has been an error:').'
'; if ($updateinfo['error']==1) { setGlobalSetting('updatekey',''); $output.=$clang->gT('Your update key is invalid and was removed. ').'
'; } else $output.=$clang->gT('On requesting the update information from limesurvey.org there has been an error:').'
'; } 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); $output.=$clang->gT('Creating file backup... ').'
'; if ($v_list == 0) { die("Error : ".$archive->errorInfo(true)); } else { $output.="".$clang->gT('File backup created:').' '.htmlspecialchars($tempdir.DIRECTORY_SEPARATOR.'files-'.$basefilename.'.zip').'

'; } require_once("dumpdb.php"); if ($databasetype=='mysql' || $databasetype=='mysqli') { $output.=$clang->gT('Creating database backup... ').'
'; $byteswritten=file_put_contents($tempdir.DIRECTORY_SEPARATOR.'db-'.$basefilename.'.sql',completedump()); if ($byteswritten>5000) { $output.="".$clang->gT('DB backup created:')." ".htmlspecialchars($tempdir.DIRECTORY_SEPARATOR.'db-'.$basefilename.'.sql').'

'; } } else { $output.="".$clang->gT('No DB backup created:').'
'.$clang->gT('Database backup functionality is currently not available for your database type. Before proceeding please backup your database using a backup tool!').'


'; } $output.=$clang->gT('Please check any problems above and then proceed to the final step.'); $output.="

"; $output.='
'; return $output; } function UpdateStep4() { global $clang, $scriptname, $homedir, $buildnumber, $updatebuild, $debug, $rootdir, $publicdir, $tempdir, $database_exists, $databasetype, $action, $demoModeOnly; $output='
'.$clang->gT('ComfortUpdate Step 4').'

'; if (!isset( $_SESSION['updateinfo'])) { $output.=$clang->gT('On requesting the update information from limesurvey.org there has been an error:').'
'; if ($updateinfo['error']==1) { setGlobalSetting('updatekey',''); $output.=$clang->gT('Your update key is invalid and was removed. ').'
'; } else $output.=$clang->gT('On requesting the update information from limesurvey.org there has been an error:').'
'; } 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=='') { $fHandle=fopen($tempdir.'/update.zip','w'); $body=''; $full_body=''; for(;;){ $error = $http->ReadReplyBody($body,100000); if($error != "" || strlen($body)==0) break; fwrite($fHandle,$body); } fclose($fHandle); } 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']); } $output.=sprintf($clang->gT('File deleted: %s'),$afile['file']).'
'; } } //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 { $output.=$clang->gT('New files were successfully installed.').'
'; unlink($tempdir.'/update.zip'); } } else { $output.=$clang->gT('There was a problem downloading the update file. Please try to restart the update process.').'
'; $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); $output.=sprintf($clang->gT('Buildnumber was successfully updated to %s.'),$_SESSION['updateinfo']['toversion']).'
'; $output.=$clang->gT('Please check any problems above - update was done.').'
'; } $output.="

"; $output.='
'; setGlobalSetting('updatelastcheck','1980-01-01 00:00'); setGlobalSetting('updateavailable','0'); return $output; } /** * 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; $adminoutput=''; $currentDBVersion=GetGlobalSetting('DBVersion'); if (intval($dbversionnumber)>intval($currentDBVersion)) { $upgradedbtype=$databasetype; if ($upgradedbtype=='mssql_n' || $upgradedbtype=='odbc_mssql' || $upgradedbtype=='odbtp') $upgradedbtype='mssql'; if ($upgradedbtype=='mysqli') $upgradedbtype='mysql'; include ('upgrade-'.$upgradedbtype.'.php'); $tables = $connect->MetaTables(); db_upgrade(intval($currentDBVersion)); $adminoutput="
".sprintf($clang->gT("Database has been successfully upgraded to version %s"),$dbversionnumber); } return $adminoutput; } ?>