Merge branch 'master' of github.com:easysoft/zentaopms
This commit is contained in:
+102
-48
@@ -90,56 +90,44 @@ class misc extends control
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function downloadClient($os = '', $confirm = 'no', $send = 'no')
|
||||
public function downloadClient($action = 'selectPackage', $os = '', $uid = '')
|
||||
{
|
||||
if($_POST) die(js::locate($this->createLink('misc', 'downloadClient', "os={$this->post->os}&confirm=yes"), 'parent'));
|
||||
|
||||
if($send == 'yes')
|
||||
if($_POST)
|
||||
{
|
||||
$clientDir = $this->app->getBasePath() . 'tmp/cache/client/tmp/';
|
||||
$os = $this->post->os;
|
||||
die(js::locate($this->createLink('misc', 'downloadClient', "action=getPackage&os=$os"), 'parent'));
|
||||
}
|
||||
|
||||
if($action == 'getPackage')
|
||||
{
|
||||
$this->view->os = $os;
|
||||
$this->view->uid = uniqid();
|
||||
}
|
||||
|
||||
if($action == 'downloadPackage')
|
||||
{
|
||||
$clientDir = $this->app->getBasePath() . 'tmp/cache/client/' . "$uid/";
|
||||
if(!is_dir($clientDir)) mkdir($clientDir, 0755, true);
|
||||
|
||||
/* write login info into config file. */
|
||||
$defaultUser = new stdclass();
|
||||
$defaultUser->server = common::getSysURL();
|
||||
$defaultUser->account = $this->app->user->account;
|
||||
|
||||
$loginInfo = new stdclass();
|
||||
$loginInfo->ui = $defaultUser;
|
||||
$loginInfo = json_encode($loginInfo);
|
||||
|
||||
$loginFile = $clientDir . 'config.json';
|
||||
file_put_contents($loginFile, $loginInfo);
|
||||
|
||||
define('PCLZIP_TEMPORARY_DIR', $clientDir);
|
||||
$this->app->loadClass('pclzip', true);
|
||||
$clientFile = $clientDir . 'zentaoClient.zip';
|
||||
$archive = new pclzip($clientFile);
|
||||
|
||||
if($os == 'mac')
|
||||
$zipContent = file_get_contents($clientFile);
|
||||
if(is_dir($clientDir))
|
||||
{
|
||||
$result = $archive->add($loginFile, PCLZIP_OPT_REMOVE_ALL_PATH, PCLZIP_OPT_ADD_PATH, 'xuanxuan.app/Contents/Resouces');
|
||||
$zfile = $this->app->loadClass('zfile');
|
||||
$zfile->removeDir($clientDir);
|
||||
}
|
||||
else
|
||||
{
|
||||
$result = $archive->add($loginFile, PCLZIP_OPT_REMOVE_ALL_PATH, PCLZIP_OPT_ADD_PATH, 'resources/build-in');
|
||||
}
|
||||
|
||||
if($result == 0) die("Error : " . $archive->errorInfo(true));
|
||||
|
||||
unlink($clientDir);
|
||||
|
||||
$this->fetch('file', 'sendDownHeader', array('fileName' => 'client.zip', 'zip', $zipContent));
|
||||
}
|
||||
|
||||
$this->view->os = $os;
|
||||
$this->view->confirm = $confirm;
|
||||
$this->view->action = $action;
|
||||
$this->display();
|
||||
}
|
||||
|
||||
public function ajaxGetClient($os)
|
||||
public function ajaxGetClient($os = '', $uid = '')
|
||||
{
|
||||
set_time_limit (0);
|
||||
session_write_close();
|
||||
|
||||
$clientDir = $this->app->getBasePath() . 'tmp/cache/client/';
|
||||
if(!is_dir($clientDir)) mkdir($clientDir, 0755, true);
|
||||
@@ -150,36 +138,41 @@ class misc extends control
|
||||
if($os == 'linux32') $clientName = "xuanxuan.linux.ia32.zip";
|
||||
if($os == 'mac') $clientName = "xuanxuan.mac.zip";
|
||||
|
||||
$tmpDir = $clientDir . '/tmp/';
|
||||
$tmpDir = $clientDir . "/$uid/";
|
||||
if(!is_dir($tmpDir)) mkdir($tmpDir, 0755, true);
|
||||
|
||||
$needCache = false;
|
||||
$packageFile = $clientDir . $clientName;
|
||||
if(!file_exists($packageFile))
|
||||
{
|
||||
$handle = "http://dl.pts.com/xuanxuan/xuanxuan.win64.zip";
|
||||
$url = "http://dl.pts.com/xuanxuan/";
|
||||
$xxFile = $url . $clientName;
|
||||
$needCache = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
$handle = $packageFile;
|
||||
$xxFile = $packageFile;
|
||||
}
|
||||
|
||||
$client = $tmpDir . 'zentaoClient.zip';
|
||||
$clientFile = $tmpDir . 'zentaoClient.zip';
|
||||
|
||||
$clientHd = fopen($handle, "rb");
|
||||
if($clientHd)
|
||||
$xxHd= fopen($xxFile, "rb");
|
||||
if($xxHd)
|
||||
{
|
||||
$newf = fopen($client, "wb");
|
||||
if($newf)
|
||||
$clientHd = fopen($clientFile, "wb");
|
||||
if($clientHd)
|
||||
{
|
||||
while(!feof($clientHd))
|
||||
while(!feof($xxHd))
|
||||
{
|
||||
fwrite($newf, fread($clientHd, 1024 * 8 ), 1024 * 8 );
|
||||
fwrite($clientHd, fread($xxHd, 1024 * 8 ), 1024 * 8 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($clientHd) fclose($clientHd);
|
||||
if ($newf) fclose($newf);
|
||||
if($xxHd) fclose($xxHd);
|
||||
if($clientHd) fclose($clientHd);
|
||||
|
||||
if($needCache) file_put_contents($packageFile, file_get_contents($clientFile));
|
||||
|
||||
$response = array();
|
||||
$response['result'] = 'success';
|
||||
@@ -187,10 +180,71 @@ class misc extends control
|
||||
$this->send($response);
|
||||
}
|
||||
|
||||
public function ajaxGetDownProgress($os = '')
|
||||
public function ajaxSetClientConfig($os = '', $uid = '')
|
||||
{
|
||||
$response['result'] = 'success';
|
||||
|
||||
$clientDir = $this->app->getBasePath() . 'tmp/cache/client/' . "$uid/";
|
||||
if(!is_dir($clientDir)) mkdir($clientDir, 0755, true);
|
||||
|
||||
/* write login info into config file. */
|
||||
$defaultUser = new stdclass();
|
||||
$defaultUser->server = common::getSysURL();
|
||||
$defaultUser->account = $this->app->user->account;
|
||||
|
||||
$loginInfo = new stdclass();
|
||||
$loginInfo->ui = $defaultUser;
|
||||
$loginInfo = json_encode($loginInfo);
|
||||
|
||||
$loginFile = $clientDir . 'config.json';
|
||||
file_put_contents($loginFile, $loginInfo);
|
||||
|
||||
define('PCLZIP_TEMPORARY_DIR', $clientDir);
|
||||
$this->app->loadClass('pclzip', true);
|
||||
$clientFile = $clientDir . 'zentaoClient.zip';
|
||||
$archive = new pclzip($clientFile);
|
||||
|
||||
if($os == 'mac')
|
||||
{
|
||||
$result = $archive->add($loginFile, PCLZIP_OPT_REMOVE_ALL_PATH, PCLZIP_OPT_ADD_PATH, 'xuanxuan.app/Contents/Resouces');
|
||||
}
|
||||
else
|
||||
{
|
||||
$result = $archive->add($loginFile, PCLZIP_OPT_REMOVE_ALL_PATH, PCLZIP_OPT_ADD_PATH, 'resources/build-in');
|
||||
}
|
||||
|
||||
$zipContent = file_get_contents($clientFile);
|
||||
|
||||
if($result == 0)
|
||||
{
|
||||
$response['result'] = 'fail';
|
||||
$response['message'] = $archive->errorInfo(true);
|
||||
|
||||
if(is_dir($clientDir))
|
||||
{
|
||||
$zfile = $this->app->loadClass('zfile');
|
||||
$zfile->removeDir($clientDir);
|
||||
}
|
||||
$this->send($response);
|
||||
}
|
||||
|
||||
$this->send($response);
|
||||
}
|
||||
|
||||
public function ajaxGetDownProgress($os = '', $uid = '')
|
||||
{
|
||||
$packageFile = $this->app->getBasePath() . 'tmp/cache/client/' . $uid . '/zentaoClient.zip';
|
||||
|
||||
$size = 0;
|
||||
if(file_exists($packageFile))
|
||||
{
|
||||
$size = filesize($packageFile);
|
||||
$size = $size ? round($size / 1048576, 2) : 0;
|
||||
}
|
||||
|
||||
$response = array();
|
||||
$response['result'] = 'unfinished';
|
||||
$response['result'] = 'success';
|
||||
$response['size'] = $size;
|
||||
|
||||
$this->send($response);
|
||||
}
|
||||
|
||||
@@ -16,7 +16,10 @@ $lang->misc->api = 'https://api.zentao.net';
|
||||
$lang->misc->enApi = 'http://api.zentao.pm';
|
||||
|
||||
$lang->misc->client = new stdclass();
|
||||
$lang->misc->client->download = '下载';
|
||||
$lang->misc->client->download = '下载';
|
||||
$lang->misc->client->downloading = '正在获取安装包:';
|
||||
$lang->misc->client->downloaded = '成功获取安装包';
|
||||
$lang->misc->client->setConfig = '成功设置配置信息';
|
||||
|
||||
$lang->misc->client->osList['windows64'] = 'Windows 64位';
|
||||
$lang->misc->client->osList['windows32'] = 'Windows 32位';
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<div class='main-header'>
|
||||
<h2><?php echo $lang->downloadClient;?></h2>
|
||||
</div>
|
||||
<?php if($confirm == 'no'):?>
|
||||
<?php if($action == 'selectPackage'):?>
|
||||
<form method='post' target='hiddenwin'>
|
||||
<table class='w-p100'>
|
||||
<tr>
|
||||
@@ -13,31 +13,55 @@
|
||||
</tr>
|
||||
<tr class='text-center'>
|
||||
<td>
|
||||
<?php echo html::submitButton($lang->misc->client->download, '', 'btn btn-primary');?>
|
||||
<?php echo html::submitButton($lang->select, '', 'btn btn-primary');?>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</form>
|
||||
<?php endif;?>
|
||||
<?php if($confirm == 'yes'):?>
|
||||
|
||||
<?php if($action == 'getPackage'):?>
|
||||
<?php js::set('os', $os);?>
|
||||
<div>
|
||||
<?php js::set('uid', $uid);?>
|
||||
<div class='main'>
|
||||
<ul>
|
||||
<li id='downloading'><?php echo $lang->misc->client->downloading;?><span>0</span>M</li>
|
||||
<li id='downloaded' class='hidden'><?php echo $lang->misc->client->downloaded;?></li>
|
||||
<li id='setConfig' class='hidden'><?php echo $lang->misc->client->setConfig;?></li>
|
||||
<li id='hasError' class='hidden'><?php echo $lang->misc->client->downloaded;?></li>
|
||||
</ul>
|
||||
</div>
|
||||
<script>
|
||||
$(document).ready(function()
|
||||
{
|
||||
getClient();
|
||||
setInterval("showDownloadProgress()", 2000);
|
||||
progress = setInterval("showProgress()", 2000);
|
||||
})
|
||||
|
||||
function getClient()
|
||||
{
|
||||
var link = createLink('misc', 'ajaxGetClient', 'os=' + os);
|
||||
var link = createLink('misc', 'ajaxGetClient', 'os=' + os + '&uid=' + uid);
|
||||
$.getJSON(link, function(response)
|
||||
{
|
||||
if(response.result == 'success')
|
||||
{
|
||||
downloadClient();
|
||||
clearInterval(progress);
|
||||
$('#downloading').addClass('hidden');
|
||||
$('#downloaded').removeClass('hidden');
|
||||
|
||||
var link = createLink('misc', 'ajaxSetClientConfig', 'os=' + os + '&uid=' + uid);
|
||||
$.getJSON(link, function(response)
|
||||
{
|
||||
if(response.result == 'success')
|
||||
{
|
||||
$('#setConfig').removeClass('hidden');
|
||||
downloadClient();
|
||||
}
|
||||
else
|
||||
{
|
||||
$('#hasError').text(response.message);
|
||||
}
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -48,13 +72,13 @@
|
||||
|
||||
function downloadClient()
|
||||
{
|
||||
var link = createLink('misc', 'downloadClient', "os=" + os + "&confirm=yes" + "&send=yes");
|
||||
var link = createLink('misc', 'downloadClient', "action=downloadPackage" + '&os=' + os + '&uid=' + uid);
|
||||
location.href = link;
|
||||
}
|
||||
|
||||
function showDownloadProgress()
|
||||
function showProgress()
|
||||
{
|
||||
var link = createLink('misc', 'ajaxGetDownProgress', 'file=' + os);
|
||||
var link = createLink('misc', 'ajaxGetDownProgress', 'os=' + os + '&uid=' + uid);
|
||||
$.getJSON(link, function(response)
|
||||
{
|
||||
if(response.result == 'finished')
|
||||
@@ -62,7 +86,7 @@
|
||||
}
|
||||
else
|
||||
{
|
||||
console.log('i');
|
||||
$('#downloading span').text(response.size);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user