add doi actions

This commit is contained in:
Li Jianxuan 2013-04-24 11:07:25 +00:00
parent bb4eacce87
commit a8cdafb719
5 changed files with 4075 additions and 4001 deletions

File diff suppressed because it is too large Load Diff

View File

@ -19,9 +19,7 @@ $this->theme->AppendPlus($this,'colorbox');
<li><a href="/admin/data/doi">浏览所有</a></li> <li><a href="/admin/data/doi">浏览所有</a></li>
<?php if(!empty($this->uuid)) {?> <?php if(!empty($this->uuid)) {?>
<li class="active"><a href="javascript:void(0);">编辑DOI</a></li> <li class="active"><a href="javascript:void(0);">编辑DOI</a></li>
<?php }else{ ?> <?php }?>
<li class="active"><a href="/admin/data/doi/ac/add">添加新DOI</a></li>
<?php } ?>
</ul> </ul>
</div> </div>
<div class=""> <div class="">
@ -62,7 +60,7 @@ $this->theme->AppendPlus($this,'colorbox');
<input type="text" id="title" name="title" value="<?= isset($this->data['title']) ? $this->data['title']:"" ?>" /> <input type="text" id="title" name="title" value="<?= isset($this->data['title']) ? $this->data['title']:"" ?>" />
</div> </div>
</div> </div>
<?php if(empty($this->data['info'])) {?> <?php if(empty($this->data['info']) || !is_array($this->data['info'])) {?>
<div class="control-group infocontrol" id="info1"> <div class="control-group infocontrol" id="info1">
<label class="control-label" for="">info</label> <label class="control-label" for="">info</label>
<div class="controls"> <div class="controls">
@ -72,7 +70,23 @@ $this->theme->AppendPlus($this,'colorbox');
</div> </div>
</div> </div>
<?php }else{ ?> <?php }else{ ?>
<?php
$index = 0;
foreach($this->data['info'] as $k=>$v){
$index ++;
?>
<div class="control-group infocontrol">
<label class="control-label">info</label>
<div class="controls">
<input type="text" name="info[<?= $k ?>][author]" value="<?= $v['author'] ?>" placeholder="作者" />
<input type="text" name="info[<?= $k ?>][organization]" value="<?= $v['organization'] ?>" placeholder="单位" />
<input type="text" name="info[<?= $k ?>][order]" value="<?= $v['order'] ?>" placeholder="排序" />
<?php if($index>1){ ?>
<a href="javascript:void(0);" onclick="RmInput(this)"> -删除</a>
<?php }?>
</div>
</div>
<?php } ?>
<?php } ?> <?php } ?>
<div class="control-group"> <div class="control-group">
<div class="controls"> <div class="controls">

View File

@ -1,80 +1,79 @@
<?php <?php
$this->headTitle($this->config->title->site); $this->headTitle($this->config->title->site);
$this->headTitle($this->config->title->author); $this->headTitle($this->config->title->author);
$this->headTitle()->setSeparator(' - '); $this->headTitle()->setSeparator(' - ');
$this->breadcrumb('<a href="/">首页</a>'); $this->breadcrumb('<a href="/">首页</a>');
$this->breadcrumb('<a href="/admin/data">数据管理</a>'); $this->breadcrumb('<a href="/admin/data">数据管理</a>');
$this->breadcrumb('DOI'); $this->breadcrumb('DOI');
$this->breadcrumb()->setSeparator(' > '); $this->breadcrumb()->setSeparator(' > ');
$this->theme->AppendPlus($this,'colorbox'); $this->theme->AppendPlus($this,'colorbox');
$this->theme->AppendPlus($this,'admin_plugin'); $this->theme->AppendPlus($this,'admin_plugin');
?> ?>
<style> <style>
table thead tr th {background:#EBF2F6;} table thead tr th {background:#EBF2F6;}
</style> </style>
<div class="row-fluid"> <div class="row-fluid">
<div class="span2"> <div class="span2">
<?= $this->partial('data/left.phtml'); ?> <?= $this->partial('data/left.phtml'); ?>
</div> </div>
<div class="span10"> <div class="span10">
<div> <div>
<ul class="nav nav-tabs"> <ul class="nav nav-tabs">
<li class="active"><a href="/admin/data/doi">浏览所有</a></li> <li class="active"><a href="/admin/data/doi">浏览所有</a></li>
<li><a href="/admin/data/doi/ac/add">添加新DOI</a></li> </ul>
</ul> </div>
</div> <div>
<div> <div class="input-append">
<div class="input-append"> <form id="datasearch" class="search_form" action="">
<form id="datasearch" class="search_form" action=""> <input type="text" id="keyword" name="q" value="<?php if(!empty($this->q)) echo $this->q; ?>" />
<input type="text" id="keyword" name="q" value="<?php if(!empty($this->q)) echo $this->q; ?>" /> <button type="submit" class="btn" id="search_btn">搜索</button>
<button type="submit" class="btn" id="search_btn">搜索</button> </form>
</form> </div>
</div> </div>
</div> <?php if(!empty($this->error)) { ?>
<?php if(!empty($this->error)) { ?> <?= $this->error ?>
<?= $this->error ?> <?php } ?>
<?php } ?> <?php if(!empty($this->msg)) { ?>
<?php if(!empty($this->msg)) { ?> <?= $this->msg ?>
<?= $this->msg ?> <?php } else{ ?>
<?php } else{ ?> <div id="datalist">
<div id="datalist"> <?php if (count($this->paginator)): ?>
<?php if (count($this->paginator)): ?> <table class="table table-bordered table-striped">
<table class="table table-bordered table-striped"> <thead>
<thead> <tr>
<tr> <th>UUID</th>
<th>UUID</th> <th>元数据</th>
<th>元数据</th> <th>DOI</th>
<th>DOI</th> <th width="70">操作</th>
<th width="70">操作</th> </tr>
</tr> </thead>
</thead> <tbody>
<tbody> <?php $autoindex=0;
<?php $autoindex=0; foreach ($this->paginator as $item):
foreach ($this->paginator as $item): $autoindex++;?>
$autoindex++;?> <tr id="DataLine_<?= $item['id']?>">
<tr id="DataLine_<?= $item['id']?>"> <td><?= $item['uuid'] ?></td>
<td><?= $item['uuid'] ?></td> <td><?= $item['title'] ?></td>
<td><?= $item['title'] ?></td> <td><?= $item['doi'] ?></td>
<td><?= $item['doi'] ?></td> <td>
<td> <a href="/admin/data/doi/ac/edit/uuid/<?= $item['uuid']?>">编辑</a>
<a href="/admin/data/fund/ac/edit/id/<?= $item['id']?>">编辑</a> <a href="javascript:void(0);" onclick="onedel(<?= $item['id']?>)" id="delbtn_<?= $item['id']?>">删除</a>
<a href="javascript:void(0);" onclick="onedel(<?= $item['id']?>)" id="delbtn_<?= $item['id']?>">删除</a> </td>
</td> </tr>
</tr> <?php endforeach; ?>
<?php endforeach; ?> </tbody>
</tbody> </table>
</table> <?php endif; ?>
<?php endif; ?> <div class="pagenavi"><?= $this->paginator; ?></div>
<div class="pagenavi"><?= $this->paginator; ?></div> </div>
</div> <?php } ?>
<?php } ?> </div>
</div> </div>
</div> <!-- //页面内容 -->
<!-- //页面内容 --> <script>
<script> var info = {
var info = { btn_prefix : "delbtn_",
btn_prefix : "delbtn_", item_prefix : "DataLine_",
item_prefix : "DataLine_", url : "/admin/data/doi/ac/del"
url : "/admin/data/doi/ac/del" }
} </script>
</script>

View File

@ -1,153 +1,179 @@
<?php <?php
class Doi extends Zend_Controller_Plugin_Abstract class Doi extends Zend_Controller_Plugin_Abstract
{ {
private $db; //传入PDO对象. private $db; //传入PDO对象.
private $auth = NULL; //Zend_Auth 对象 private $auth = NULL; //Zend_Auth 对象
//使用到的公共变量 //使用到的公共变量
public $tbl_doi = "datadoi"; public $tbl_doi = "datadoi";
function __construct($db) function __construct($db)
{ {
$this->db = $db; $this->db = $db;
} }
function fetch() function fetch()
{ {
$sql = "SELECT * FROM ".$this->tbl_doi." ORDER BY id DESC"; $sql = "SELECT * FROM ".$this->tbl_doi." ORDER BY id DESC";
$rs = $this->db->query($sql); $rs = $this->db->query($sql);
$rows = $rs->fetchAll(); $rows = $rs->fetchAll();
return $rows; return $rows;
} }
function add($data){ function add($data){
include_once("helper/dbh.php"); include_once("helper/dbh.php");
$dbh = new dbh($this->db); $dbh = new dbh($this->db);
$this->data_process_in($data); $this->data_process_in($data);
include_once("helper/view.php"); //include_once("helper/view.php");
view::Dump($data); //view::Dump($data);
return $dbh->insert($this->tbl_doi,$data); return $dbh->insert($this->tbl_doi,$data);
} }
function update($data,$uuid){ function update($data,$uuid){
$doi_info = $this->view($uuid); $doi_info = $this->view($uuid);
if(!$doi_info) if($doi_info == false)
{ {
$this->data_process_in($data); return $this->add($data);
include_once("helper/view.php"); }else {
view::Dump($data); $this->data_process_in($data);
include_once("helper/dbh.php"); //include_once("helper/view.php");
$dbh = new dbh($this->db); //view::Dump($data);
if(is_numeric($uuid)) include_once("helper/dbh.php");
{ $dbh = new dbh($this->db);
$condition = " id=$uuid "; if(is_numeric($uuid))
}else{ {
$condition = " uuid='$uuid' "; $condition = " id=$uuid ";
} }else{
$state = $dbh->update($this->tbl_doi,$data,$condition,true); $condition = " uuid='$uuid' ";
}
if( $state == true) $state = $dbh->update($this->tbl_doi,$data,$condition,true);
{
return true; if( $state == true)
}else{ {
return $state; return true;
} }else{
}else{ return $state;
$this->add($data); }
} }
} }
function data_process_in(&$data){ function data_process_in(&$data){
$authors = array(); $authors = array();
$orgs = array(); $orgs = array();
foreach($data['info'] as $k=>$v) foreach($data['info'] as $k=>$v)
{ {
$authors[$v['order']] = $v['author']; $authors[$v['order']] = $v['author'];
$orgs[$v['order']] = $v['organization']; $orgs[$v['order']] = $v['organization'];
} }
$authors = "{".join(",",$authors)."}"; $authors = "{".join(",",$authors)."}";
$orgs = "{".join(",",$orgs)."}"; $orgs = "{".join(",",$orgs)."}";
$data['authors'] = $authors; $data['authors'] = $authors;
$data['organization'] = $orgs; $data['organization'] = $orgs;
unset($data['info']); unset($data['info']);
} }
function view($id) function data_process_out(&$data){
{ $authors = str_replace("{",'',$data['authors']);
if(is_numeric($id)) $authors = str_replace("}",'',$authors);
{ $authors = split(",",$authors);
$sql = "SELECT * FROM ".$this->tbl_doi." WHERE id=$id"; $orgs = str_replace("{",'',$data['organization']);
}else{ $orgs = str_replace("}",'',$orgs);
$sql = "SELECT * FROM ".$this->tbl_doi." WHERE uuid='$id'"; $orgs = split(",",$orgs);
} $info = array();
$rs = $this->db->query($sql); foreach($authors as $k=>$v)
$row = $rs->fetch(); {
return $row; $info[$k] = array(
} 'author'=>$authors[$k],
'organization'=>$orgs[$k],
function _getParams(Zend_Controller_Request_Abstract $request) 'order'=>0
{ );
$data = array( }
'doi' => trim($request->getParam('doi')), //include_once("helper/view.php");
'uuid' => trim($request->getParam('uuid')), //view::Dump($info);
'publisher' => trim($request->getParam('publisher')), return $info;
'url' => trim($request->getParam('url')), }
'title' => trim($request->getParam('title')),
'info'=>$this->checkinfo($_POST['info']) function view($id)
); {
if(!is_array($data['info'])){ if(is_numeric($id))
return $data['info']; {
}else{ $sql = "SELECT * FROM ".$this->tbl_doi." WHERE id=$id";
$data['info'] = $this->sksort($data['info'],"order",SORT_DESC); }else{
} $sql = "SELECT * FROM ".$this->tbl_doi." WHERE uuid='$id'";
return $data; }
} $rs = $this->db->query($sql);
$row = $rs->fetch();
function checkinfo($info){ return $row;
if(!is_array($info)){ }
return NULL;
} function delete($id){
foreach($info as $k=>$v) if(!is_numeric($id))
{ {
if(empty($v['author']) && empty($v['organization']) && empty($v['order'])) return "参数错误";
{ }
unset($info[$k]); $condition = " id=$id ";
}else{ $sql = "DELETE FROM ".$this->tbl_doi." WHERE $condition";
if(empty($v['author'])) return $this->db->exec($sql);
{ }
return "请输入 $k 中的作者";
} function _getParams(Zend_Controller_Request_Abstract $request)
if(empty($v['organization'])) {
{ $data = array(
return "请输入 $k 中的单位"; 'doi' => trim($request->getParam('doi')),
} 'uuid' => trim($request->getParam('uuid')),
if(empty($v['order'])) 'publisher' => trim($request->getParam('publisher')),
{ 'url' => trim($request->getParam('url')),
return "请输入 $k 中的排序"; 'title' => trim($request->getParam('title')),
} 'info'=>$_POST['info']
} );
} return $data;
return $info; }
}
function checkinfo($info){
function sksort($array,$key,$type=SORT_DESC) { if(!is_array($info)){
$sortArray = array(); return NULL;
}
foreach($array as $v){ foreach($info as $k=>$v)
foreach($v as $key=>$value){ {
if(!isset($sortArray[$key])){ if(empty($v['author']) && empty($v['organization']) && empty($v['order']))
$sortArray[$key] = array(); {
} unset($info[$k]);
$sortArray[$key][] = $value; }else{
} if(empty($v['author']))
} {
return "请输入 $k 中的作者";
if(array_multisort($sortArray[$key],$type,$array)) }
{ if(empty($v['organization']))
return $array; {
}else{ return "请输入 $k 中的单位";
return $array; }
} if(empty($v['order']))
} {
return "请输入 $k 中的排序";
} }
}
}
return $info;
}
function sksort($array,$key,$type=SORT_DESC) {
$sortArray = array();
foreach($array as $v){
foreach($v as $key=>$value){
if(!isset($sortArray[$key])){
$sortArray[$key] = array();
}
$sortArray[$key][] = $value;
}
}
if(array_multisort($sortArray[$key],$type,$array))
{
return $array;
}else{
return $array;
}
}
}

View File

@ -1,82 +1,83 @@
<?php <?php
class view extends Zend_Controller_Plugin_Abstract class view extends Zend_Controller_Plugin_Abstract
{ {
private $db; //传入PDO对象. private $db; //传入PDO对象.
private $product = 0; //产品环境 private $product = 0; //产品环境
function __construct($db='') function __construct($db='')
{ {
$this->db = $db; $this->db = $db;
} }
static function addPaginator($data,$ctl,Zend_Controller_Request_Abstract $request) static function addPaginator($data,$ctl,Zend_Controller_Request_Abstract $request)
{ {
$page = $request->getParam('page'); $page = $request->getParam('page');
$paginator = Zend_Paginator::factory($data); $paginator = Zend_Paginator::factory($data);
$paginator->setCurrentPageNumber($page); $paginator->setCurrentPageNumber($page);
$paginator->setItemCountPerPage(12); $paginator->setItemCountPerPage(12);
$paginator->setView($ctl); $paginator->setView($ctl);
Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination_param.phtml'); Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination_param.phtml');
$ctl->paginator = $paginator; $ctl->paginator = $paginator;
} }
static function Msg($type,$content,$url=''){ static function Msg($type,$content,$url=''){
$html = '<div class="alert '.$type.'">'."\r\n"; $html = '<div class="alert '.$type.'">'."\r\n";
$html.= '<a data-dismiss="alert" class="close">×</a>'."\r\n"; $html.= '<a data-dismiss="alert" class="close">×</a>'."\r\n";
$html.= $content."\r\n"; $html.= $content."\r\n";
$html.= '</div>'."\r\n"; $html.= '</div>'."\r\n";
if(!empty($url)) if(!empty($url))
{ {
if($url == -1){ if($url == -1){
$html.= '<script language="javascript">setTimeout("window.history.back(-1);",3000);</script>'."\r\n"; $html.= '<script language="javascript">setTimeout("window.history.back(-1);",3000);</script>'."\r\n";
}else{ }else{
$html.= '<script language="javascript">setTimeout("self.location=\''.$url.'\'",3000);</script>'."\r\n"; $html.= '<script language="javascript">setTimeout("self.location=\''.$url.'\'",3000);</script>'."\r\n";
} }
} }
return $html; return $html;
} }
static function Error($type,$content,$url=''){ static function Error($type,$content,$url=''){
if(empty($type)) if(empty($type))
{ {
$AlertType = "alert-error"; $AlertType = "alert-error";
}else{ }else{
$AlertType = $type; $AlertType = $type;
} }
$html = '<div class="alert alert-block fade in '.$AlertType.'" id="Alert-error-box">'."\r\n"; $html = '<div class="alert alert-block fade in '.$AlertType.'" id="Alert-error-box">'."\r\n";
$html.= '<a class="close" data-dismiss="alert" href="#">×</a>'."\r\n"; $html.= '<a class="close" data-dismiss="alert" href="#">×</a>'."\r\n";
if(!is_array($content)) { if(!is_array($content)) {
$html.= '<h4 class="alert-heading">'.$content.'</h4>'."\r\n"; $html.= '<h4 class="alert-heading">'.$content.'</h4>'."\r\n";
}else{ }else{
$html.= '<ul>'."\r\n"; $html.= '<ul>'."\r\n";
foreach($content as $v) { foreach($content as $v) {
$html.='<li>'.$v.'</li>'."\r\n"; $html.='<li>'.$v.'</li>'."\r\n";
} }
$html.= '</ul>'."\r\n"; $html.= '</ul>'."\r\n";
} }
$html.= '</div>'."\r\n"; $html.= '</div>'."\r\n";
return $html; return $html;
} }
static function User($param){ static function User($param){
$auth = Zend_Auth::getInstance(); $auth = Zend_Auth::getInstance();
if($auth->hasIdentity()) if($auth->hasIdentity())
{ {
$user = $auth->getIdentity(); $user = $auth->getIdentity();
return $user->$param; return $user->$param;
}else{ }else{
return false; return false;
} }
} }
static function Dump($data,$exit = true){ static function Dump($data,$exit = true){
echo "<pre>"; echo "<pre>";
var_dump($data); var_dump($data);
echo "</pre>"; echo "</pre>";
if($exit) if($exit)
{ {
exit(); exit();
} }
} }
} }