add data import page

This commit is contained in:
Li Jianxuan 2015-01-26 09:48:40 +00:00
parent b1253df618
commit 3cda4c0b7b
6 changed files with 271 additions and 13 deletions

View File

@ -7,6 +7,7 @@ use Helpers\dbh;
use \Files\Files;
use Westdc\Visual;
use Westdc\Metadata;
use Westdc\Dataimport;
class Admin_DataController extends Zend_Controller_Action
{
@ -1584,7 +1585,7 @@ class Admin_DataController extends Zend_Controller_Action
/*
* 导入本地元数据
*/
function importAction()
function Gction()
{
$md=new MetadataTable();
$thumb=new ThumbnailTable();
@ -4143,6 +4144,46 @@ class Admin_DataController extends Zend_Controller_Action
view::addPaginator($visual->getVisualMetadata(),$this,10);
return;
}
/**
* 數據導入
*/
public function dataimportAction()
{
$this->view->ac = $ac = $this->_getParam('ac');
//文件上傳
if($ac == "upload") {
$upload = new Dataimport\Upload;
$file = $upload($_FILES['FileData']);
$this->_helper->json($file);
}
//預處理
//判斷文件類型,初步識別文件內容
if($ac == "preprocess"){
$this->_helper->viewRenderer('dataimport-preprocess');
$file = $this->_getParam('file');
if(empty($file))
$this->view->error = "参数错误";
if(!file_exists($file))
$this->view->error = "要导入的文件已不存在,请返回上一步重新上传";
if(isset($this->view->error))
return;
$this->view->file = $file;
}
}//dataimportAction()
public function doiAction()
{

View File

@ -0,0 +1,18 @@
<?php
$this->headTitle($this->config->title->site);
$this->headTitle('后台管理');
$this->headTitle()->setSeparator(' - ');
?>
<div class="row-fluid">
<div class="span2">
<?= $this->partial('data/left.phtml'); ?>
</div>
<div class="span10">
<h3>數據導入<small>文件預處理</small></h3>
<hr />
處理文件:<?= $this->file ?>
</div>
</div>

View File

@ -0,0 +1,90 @@
<?php
$this->headTitle($this->config->title->site);
$this->headTitle('后台管理');
$this->headTitle()->setSeparator(' - ');
$theme = new Theme;
$theme->AppendPlus($this,"jquery-fileupload");
?>
<div class="row-fluid">
<div class="span2">
<?= $this->partial('data/left.phtml'); ?>
</div>
<div class="span10">
<h3>數據導入</h3>
<hr />
<label>上傳文件,請選擇Excel文件進行上傳</label>
<span class="btn btn-success fileinput-button file-upload-ctls">上傳文件<input id="fileupload" type="file" name="FileData"></span>
<div class="progress" id="pdf-upload-progress" style="display: none;">
<div class="progress-bar progress-bar-striped active" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width: 0%">
</div>
</div>
<div id="uploadedFile"></div>
</div>
</div>
<script>
$(function () {
'use strict';
var jqXHR = $('#fileupload').fileupload({
url: '/admin/data/dataimport/ac/upload',
dataType: 'json',
done: function (e, data) {
if(typeof(data.result.error) != 'undefined' && data.result.error != 0)
{
alert(data.result.error);
return false;
}
if($('#uploadedFile').html() == "")
$('#uploadedFile').html(upload.makeFileHtml(data.result));
else
$('#uploadedFile').append(upload.makeFileHtml(data.result));
return true;
},
stop : function (e) {
$('#pdf-upload-progress').hide();
$('.file-upload-ctls').show();
},//stop
start : function (e) {
$('.file-upload-ctls').hide();
$('#pdf-upload-progress .progress-bar').css('width', 0 + '%');
$('#pdf-upload-progress').show();
},//start
progressall: function (e, data) {
var progress = parseInt(data.loaded / data.total * 100, 10);
$('#pdf-upload-progress .progress-bar').css(
'width',
progress + '%'
);
},//progressall
add: function (e, data) {
if($('input[name=attid]').length >= 1)
{
upload.deleteFile($('input[name=attid]').val());
$('file-alert').alert('close')
}
data.process().done(function () {
data.submit();
});
}//add
}).prop('disabled', !$.support.fileInput)
.parent().addClass($.support.fileInput ? undefined : 'disabled');
});
var upload = {
makeFileHtml : function(data){
return '<div class="alert alert-success">'
+ data.file
+ ' <a href="/admin/data/dataimport/ac/preprocess/?file='+ encodeURI(data.file) +'">導入數據</a>'
+ "</div>";
}
};
</script>

View File

@ -1,16 +1,17 @@
<div class="well" style="padding:8px 0">
<ul class="nav nav-list">
<li class="nav-header"><h4>数据管理</h4></li>
<li class="divider"></li>
<li><a href="/admin/data/">元数据概况</a></li>
<li><a href="/admin/data/md">元数据管理</a></li>
<li><a href="/admin/data/newdata">新建元数据</a></li>
<li><a href="/admin/data/author">数据作者管理</a></li>
<li><a href="/admin/data/version">数据版本管理</a></li>
<li><a href="/admin/data/comment">数据反馈管理</a></li>
<li><a href="/admin/data/attachments">数据附件管理</a></li>
<li><a href="/admin/data/source">专题管理</a></li>
<li><a href="/admin/data/visual">数据可视化</a></li>
<li><a href="/admin/data/doi">DOI注册</a></li>
<li class="nav-header"><h4>数据管理</h4></li>
<li class="divider"></li>
<li><a href="/admin/data/">元数据概况</a></li>
<li><a href="/admin/data/md">元数据管理</a></li>
<li><a href="/admin/data/newdata">新建元数据</a></li>
<li><a href="/admin/data/author">数据作者管理</a></li>
<li><a href="/admin/data/version">数据版本管理</a></li>
<li><a href="/admin/data/comment">数据反馈管理</a></li>
<li><a href="/admin/data/attachments">数据附件管理</a></li>
<li><a href="/admin/data/source">专题管理</a></li>
<li><a href="/admin/data/doi">DOI注册</a></li>
<li><a href="/admin/data/visual">数据可视化</a></li>
<li><a href="/admin/data/dataimport">数据导入</a></li>
</ul>
</div>

View File

@ -143,6 +143,17 @@ class Theme
'/js/lib/highcharts/highcharts-more.js'
)
),
'jquery-fileupload' => array(
$this->ScriptKey => array(
'/js/lib/jquery.fileupload/vendor/jquery.ui.widget.js',
'/js/lib/jquery.fileupload/jquery.iframe-transport.js',
'/js/lib/jquery.fileupload/jquery.fileupload.js',
),
$this->CSSKey => array(
'/js/lib/jquery.fileupload/css/jquery.fileupload.css',
)
),
/*********谷歌地图*********/

View File

@ -0,0 +1,97 @@
<?php
namespace Westdc\Dataimport;
class Upload{
private $config;
function __construct($db = NULL)
{
$this->config = \Zend_Registry::get('config');
}
//上传數據
public function __invoke($file)
{
try{
if (empty($file) !== false) {
return array("error"=>"请选择要上传的文件");
}
if (@is_uploaded_file($file['tmp_name']) === false) {
return array("error"=>"文件上传失败,请重新上传");
}
if($file['size'] > 20 * 1024 * 1024)
{
return array('error'=>"文件大小超出限制");
}
$ext = $this->getFileTextExt($file['name']);
$filename = $this->gen_uuid().".".$ext;
if(!preg_match("/(\\/|\\\)$/",$this->config->dataimport->path))
$save_path = $this->config->dataimport->path . DIRECTORY_SEPARATOR;
else
$save_path = $this->config->dataimport->path;
$new_filepath = $save_path.$filename;
if (move_uploaded_file($file['tmp_name'], $new_filepath) === false) {
return array("error"=>"上传失败,请重试");
}
return array(
"success" => 1,
"file"=>$new_filepath
);
}catch(Exception $e)
{
return array("error"=>$e->getMessage());
}
}
//获取文件扩展名
public function getFileTextExt($file_name)
{
$temp_arr = explode(".", $file_name);
$file_ext = array_pop($temp_arr);
$file_ext = trim($file_ext);
$file_ext = strtolower($file_ext);
return $file_ext;
}
//获取文件Mime通过finfo扩展
public function getFileMime($file_name)
{
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$filetype = finfo_file($finfo, $file_name) ; //文件mime类型
finfo_close($finfo);
return $filetype;
}
//文件名uuid
public function gen_uuid() {
return sprintf( '%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
// 32 bits for "time_low"
mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ),
// 16 bits for "time_mid"
mt_rand( 0, 0xffff ),
// 16 bits for "time_hi_and_version",
// four most significant bits holds version number 4
mt_rand( 0, 0x0fff ) | 0x4000,
// 16 bits, 8 bits for "clk_seq_hi_res",
// 8 bits for "clk_seq_low",
// two most significant bits holds zero and one for variant DCE1.1
mt_rand( 0, 0x3fff ) | 0x8000,
// 48 bits for "node"
mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff )
);
}
}