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', '_top')\" >".$clang->gT('Back to main menu')."</button></p>"; echo '</div>'; setGlobalSetting('updatelastcheck','1980-01-01 00:00'); setGlobalSetting('updateavailable','0'); }
for (;;) { $error = $http->ReadReplyBody($body, 1000); if ($error != "" || strlen($body) == 0) { break; } } flush(); } } $http->Close(); } if (strlen($error) == 0) { echo "<H2><LI>Test saving and restoring cookies...</LI</H2>\n"; flush(); $http->SaveCookies($site_cookies); if (strlen($error = $http->RestoreCookies($site_cookies, 1)) == 0) { $http->SaveCookies($saved_cookies); if (strcmp(serialize($saved_cookies), serialize($site_cookies))) { echo "<H2>FAILED: the saved cookies do not match the restored cookies.</H2>\n"; } else { echo "<H2>OK: the saved cookies match the restored cookies.</H2>\n"; } } } if (strlen($error)) { echo "<CENTER><H2>Error: ", $error, "</H2><CENTER>\n"; } ?> </UL> <HR> </BODY>