实现文献数据文件导入 #261
This commit is contained in:
parent
53c323d1ca
commit
b431fa7f10
|
@ -553,6 +553,7 @@ class Admin_DataController extends Zend_Controller_Action
|
||||||
$uuid=$this->_getParam('uuid');
|
$uuid=$this->_getParam('uuid');
|
||||||
$search=$this->_getParam('search');
|
$search=$this->_getParam('search');
|
||||||
$keyword=$this->_getParam('keyword');
|
$keyword=$this->_getParam('keyword');
|
||||||
|
$import=(int)$this->_getParam('import');
|
||||||
|
|
||||||
if ($add) {
|
if ($add) {
|
||||||
$form=new ReferenceForm();
|
$form=new ReferenceForm();
|
||||||
|
@ -623,6 +624,31 @@ class Admin_DataController extends Zend_Controller_Action
|
||||||
$this->messenger->addMessage($e->getMessage());
|
$this->messenger->addMessage($e->getMessage());
|
||||||
}
|
}
|
||||||
$this->_redirect("/admin/data/reference");
|
$this->_redirect("/admin/data/reference");
|
||||||
|
} elseif ($import) {
|
||||||
|
if ($this->_request->isPost()) {
|
||||||
|
if ($_FILES["ref"]["error"] == UPLOAD_ERR_OK) {
|
||||||
|
$tmp_name = $_FILES["ref"]["tmp_name"];
|
||||||
|
$fp = fopen($tmp_name, "rb");
|
||||||
|
$ref=fread($fp, filesize($tmp_name));
|
||||||
|
fclose($fp);
|
||||||
|
$lines=explode("\n",$ref);
|
||||||
|
foreach($lines as $line)
|
||||||
|
{
|
||||||
|
$data=explode(";",$line);
|
||||||
|
$sql="insert into reference (reference) values(?)";
|
||||||
|
try {
|
||||||
|
$this->db->exec($this->db->quoteInto($sql,$data[1]));
|
||||||
|
} catch (Exception $e) {}
|
||||||
|
$sql="select id from reference where reference=?";
|
||||||
|
$row=$this->db->fetchRow($this->db->quoteInto($sql,$data[1]));
|
||||||
|
$sql="insert into mdref (uuid,refid) values(?,".$row['id'].")";
|
||||||
|
try {
|
||||||
|
$this->db->exec($this->db->quoteInto($sql,$data[0]));
|
||||||
|
} catch (Exception $e) {}
|
||||||
|
}
|
||||||
|
}//end if
|
||||||
|
}
|
||||||
|
$this->_helper->viewRenderer('referenceimport');
|
||||||
} else if($search){
|
} else if($search){
|
||||||
if(!empty($keyword))
|
if(!empty($keyword))
|
||||||
{
|
{
|
||||||
|
@ -711,7 +737,7 @@ class Admin_DataController extends Zend_Controller_Action
|
||||||
//move_uploaded_file($tmp_name, "../data/import/$name");
|
//move_uploaded_file($tmp_name, "../data/import/$name");
|
||||||
}//end if
|
}//end if
|
||||||
}//foreach
|
}//foreach
|
||||||
$this->_redirect('/metadata');
|
$this->_redirect('/data');
|
||||||
} else {
|
} else {
|
||||||
//do nothing now.
|
//do nothing now.
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,7 +37,7 @@
|
||||||
|
|
||||||
<div class="controlplan">
|
<div class="controlplan">
|
||||||
<a href="/admin/data/reference/add/1">添加新的数据文献</a>
|
<a href="/admin/data/reference/add/1">添加新的数据文献</a>
|
||||||
|
| <a href="/admin/data/reference/import/1">导入数据文献文件</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<?php if (count($this->paginator)): ?>
|
<?php if (count($this->paginator)): ?>
|
||||||
|
|
|
@ -23,5 +23,6 @@
|
||||||
</div>
|
</div>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
<a href="/admin/data/reference/add/1">添加新的数据文献</a>
|
<a href="/admin/data/reference/add/1">添加新的数据文献</a>
|
||||||
|
| <a href="/admin/data/reference/import/1">导入数据文献文件</a>
|
||||||
<?= $this->form; ?>
|
<?= $this->form; ?>
|
||||||
</div>
|
</div>
|
|
@ -0,0 +1,34 @@
|
||||||
|
<?php
|
||||||
|
$this->headTitle($this->config->title->site);
|
||||||
|
$this->headTitle('后台管理');
|
||||||
|
$this->headTitle()->setSeparator(' - ');
|
||||||
|
$this->headLink()->appendStylesheet('/css/admin.css');
|
||||||
|
$this->breadcrumb('<a href="/">首页</a>');
|
||||||
|
$this->breadcrumb('<a href="/admin">后台首页</a>');
|
||||||
|
$this->breadcrumb('<a href="/admin/data">数据管理</a>');
|
||||||
|
$this->breadcrumb('数据文献管理</a>');
|
||||||
|
$this->breadcrumb()->setSeparator(' > ');
|
||||||
|
?>
|
||||||
|
<div id="leftPanel">
|
||||||
|
<?= $this->partial('data/left.phtml'); ?>
|
||||||
|
</div>
|
||||||
|
<div id="rightPanel">
|
||||||
|
<?php if ($this->msg or $this->messages) :?>
|
||||||
|
<div id="message">
|
||||||
|
<?php if ($this->msg) : ?>
|
||||||
|
<p><?php echo $this->msg; ?></p>
|
||||||
|
<?php endif; if ($this->messages): foreach($this->messages as $msg): ?>
|
||||||
|
<p><?php echo $msg; ?></p>
|
||||||
|
<?php endforeach;endif; ?>
|
||||||
|
</div>
|
||||||
|
<?php endif; ?>
|
||||||
|
<a href="/admin/data/reference/add/1">添加新的数据文献</a> | <a href="/admin/data/reference/import/1">导入数据文献文件</a>
|
||||||
|
<form enctype="multipart/form-data" method="POST">
|
||||||
|
<!-- MAX_FILE_SIZE must precede the file input field -->
|
||||||
|
<input type="hidden" name="MAX_FILE_SIZE" value="3000000" />
|
||||||
|
<!-- Name of input element determines name in $_FILES array -->
|
||||||
|
上传数据文献文件: <br />
|
||||||
|
<input name="ref" type="file" /><br />
|
||||||
|
<input type="submit" value="导入" />
|
||||||
|
</form>
|
||||||
|
</div>
|
Loading…
Reference in New Issue