westdc-zf1/application/default/controllers/AuthorController.php

2446 lines
76 KiB
PHP
Raw Normal View History

2012-02-22 12:21:22 +00:00
<?php
/*
@version $Id: AuthorController.php 2012-2-29 15:01 Z
@package author
@copyright Copyright (c) 2012, CAREERI.
@license http://
@link http://
@update 2012-3-1 15:06 李建轩
@update 2012-3-9 17:01 李建轩
@update 2012-3-12 16:16 李建轩
2012-03-20 09:34:44 +00:00
@update 2012-3-14 18:01 李建轩
@update 2012-3-21 10:58 李建轩
*/
2012-02-22 12:21:22 +00:00
class AuthorController extends Zend_Controller_Action
{
private $limit=10;
//调试模式
// 调试模式中将显示全部错误细节,电子邮件将发往调试邮箱
// 1 为开启
// 0 为关闭
public $debug = 1;
//调试模式邮箱地址
public $debug_email = "la5c@qq.com";
2012-02-22 12:21:22 +00:00
function preDispatch()
{
$this->view->config = Zend_Registry::get('config');
$this->db=Zend_Registry::get('db');
$this->messenger=$this->_helper->getHelper('FlashMessenger');
$this->view->messages = $this->messenger->getMessages();
}
function indexAction()
{
}
/*
* helpAction() 帮助文档
*
*/
function helpAction(){
}//helpAction()帮助文档
/*
* inauthorAction() 数据申请管理
*
* param string $ac
* param string $keywords
* param string $pr //对离线数据申请的操作
* param string $uuid
*
* return view|ajax-responds
*/
function inauthorAction()
2012-02-22 12:21:22 +00:00
{
$ac = $this->_request->getParam("ac");
$auth = Zend_Auth::getInstance();
if($auth->hasIdentity())
{
$user = $auth->getIdentity();
$u_id = $user->id;
$u_email = $user->email;
}
if(empty($ac) || $ac=="online" || $ac == "searchonline")
{
$sql = "SELECT o.id,o.userid,o.unit,o.username,o.ts_created,o.project,m.title,m.uuid FROM onlineapp as o
LEFT JOIN metadata as m ON o.uuid=m.uuid
LEFT JOIN mdauthor as a ON a.uuid=o.uuid
WHERE (o.id in (SELECT distinct(onlineappid) from dataorder where status>=0)) AND a.userid = ? AND a.status=1";
if ($ac=="searchonline")
{
$keywords = $this->_request->getParam('q');
if(!empty($keywords))
$this->view->q = $keywords;
$search=new Search($keywords);
$where=$search->sql_expr(array("m.title","m.description"));
$sql.=' and '.$where;
}
$sql.=" ORDER BY o.id desc";
$sth = $this->db->prepare($sql);
$sth->execute(array($u_id));
$rows = $sth->fetchAll();
$paginator = Zend_Paginator::factory($rows);
$paginator->setCurrentPageNumber($this->_getParam('page'));
$paginator->setItemCountPerPage(10);
$paginator->setView($this->view);
Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination_param.phtml');
$this->view->paginator=$paginator;
}//在线申请记录
if($ac == "offline" || $ac=="searchoffline")
{
$pr = $this->_request->getParam('pr');
$oid = $this->_request->getParam('oid');
$pdf = $this->_request->getParam('pdf');
if(!empty($pr))
{
try{
$this->_helper->layout->disableLayout();
$this->_helper->viewRenderer->setNoRender();
$uuid = $this->_request->getParam('uuid');
if(!preg_match("/^[0-9A-Za-z]{8}-[0-9A-Za-z]{4}-[0-9A-Za-z]{4}-[0-9A-Za-z]{4}-[0-9A-Za-z]{12}$/",$uuid))
{
echo "参数有误!";exit();
}
//如果用户已经下载过了,就无法在更改对数据申请的意见
$sql = "select md.title,d.uuid,d.status as datastatus,d.authorpermitted from dataorder d
left join offlineapp o on o.id=d.offlineappid
left join metadata md on md.uuid=d.uuid
left join mdauthor a on a.uuid=d.uuid
where o.ts_approved is null and o.pdflink is not null
and d.uuid=? and a.userid=? and d.id=? AND a.status=1
order by o.ts_created desc";
$sth = $this->db->prepare($sql);
$sth->execute(array($uuid,$u_id,$oid));
$row = $sth->fetch();
if($row['datastatus']>4)
{
echo "该申请已经通过并且发放数据";
exit();
}
else if (empty($row) || $row['datastatus']!=4)
{
echo "该数据申请存在问题,请联系数据中心!";
exit();
}
//同意用户下载
if($pr=="confirm")
{
$sql = "UPDATE dataorder SET authorpermitted=1 WHERE uuid=? and id=?";
$sth = $this->db->prepare($sql);
if($sth->execute(array($uuid,$oid)))
{
$btn = $this->createOfflineCtBtn($uuid,'c',$oid);
echo ''.$btn.'<script>alert("您已经同意用户的离线数据申请");</script>';
exit();
}else{
echo "<script>alert('处理过程中遇到错误,请刷新页面');</script>";
exit();
}
}
//反对用户下载
if($pr == "objection")
{
$sql = "UPDATE dataorder SET authorpermitted=-1 WHERE uuid=? AND id=?";
$sth = $this->db->prepare($sql);
if($sth->execute(array($uuid,$oid)))
{
$btn = $this->createOfflineCtBtn($uuid,'o',$oid);
echo ''.$btn.'<script>alert("您已经拒绝该用户的此次离线数据申请");</script>';
exit();
}else{
echo "<script>alert('处理过程中遇到错误,请刷新页面');</script>";
exit();
}
}
}catch(Exception $e)
{
echo "处理中遇到错误,请刷新页面后重试";
exit();
}
}
else if (!empty($pdf))
{
$sql="select o.pdflink from dataorder d left join offlineapp o on d.offlineappid=o.id
left join mdauthor m on d.uuid=m.uuid
where d.id=? and m.userid=?";
$sth = $this->db->prepare($sql);
$sth->execute(array($pdf,$u_id));
$row = $sth->fetch();
$content=file_get_contents($this->view->config->offline->savepath."/".$row['pdflink']);
header("Content-Disposition: inline; filename=".$row['pdflink']);
header("Content-Type:application/pdf");
echo $content;
die(); // do not change current html output
}
else
{
$this->_helper->viewRenderer('inauthor-offline');
$select="select distinct(o.*),md.title,d.id as doid,d.uuid,d.status as datastatus,d.authorpermitted from offlineapp o
left join dataorder d on o.id=d.offlineappid
left join metadata md on md.uuid=d.uuid
left join mdauthor a on a.uuid=d.uuid
where o.ts_approved is null and o.pdflink is not null and d.status=4 and a.userid=? AND a.status=1 ";
if($ac == "searchoffline")
{
$keywords = $this->_request->getParam('q');
if(!empty($keywords))
$this->view->q = $keywords;
$search=new Search($keywords);
$where=$search->sql_expr(array("md.title","md.description"));
$select.=' and '.$where;
}
$select.=" order by o.ts_created desc";
$sth = $this->db->prepare($select);
$sth->execute(array($u_id));
$rows = $sth->fetchAll();
foreach ($rows as $k=>$v)
{
if($v['authorpermitted']==0)
{$rows[$k]['btns']=$this->createOfflineCtBtn($v['uuid'],'',$v['doid']);}
if($v['authorpermitted']>0)
{$rows[$k]['btns']=$this->createOfflineCtBtn($v['uuid'],'c',$v['doid']);}
if($v['authorpermitted']<0)
{$rows[$k]['btns']=$this->createOfflineCtBtn($v['uuid'],'o',$v['doid']);}
}
$paginator = Zend_Paginator::factory($rows);
$paginator->setCurrentPageNumber($this->_getParam('page'));
$paginator->setItemCountPerPage(10);
$paginator->setView($this->view);
Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination_param.phtml');
$this->view->paginator=$paginator;
}
}//离线申请
//按数据显示
if($ac == 'datalist' || $ac == "searchdata")
{
$uuid = $this->_request->getParam('uuid');
if(!empty($uuid))
{
$this->_helper->viewRenderer('view-dataoreder');
if(preg_match("/^[0-9A-Za-z]{8}-[0-9A-Za-z]{4}-[0-9A-Za-z]{4}-[0-9A-Za-z]{4}-[0-9A-Za-z]{12}$/",$uuid))
{
$sql = "select md.title,d.id as doid,d.uuid,d.authorpermitted,d.status
,offa.id as offa_id,offa.username as offa_name,offa.unit as offa_unit,offa.email as offa_email,offa.project as offa_project
,ona.id as ona_id,ona.username as ona_name,ona.unit as ona_unit,ona.email as ona_email,ona.project as ona_project
from dataorder d
left join metadata md on md.uuid=d.uuid
left join mdauthor a on a.uuid=d.uuid
LEFT JOIN offlineapp offa on offa.id=d.offlineappid
LEFT JOIN onlineapp ona on ona.id=d.onlineappid
WHERE (offa.id IS NOT NULL OR ona.id IS NOT NULL) AND a.status=1 and d.status>=0
AND d.uuid=? AND a.userid=?
ORDER BY d.ts_created DESC";
$sth = $this->db->prepare($sql);
$sth->execute(array($uuid,$u_id));
$rows = $sth->fetchAll();
@$this->view->mdtitle=$rows[0]['title'];
foreach ($rows as $k=>$v)
{
if($v['authorpermitted']==0)
{$rows[$k]['btns']=$this->createOfflineCtBtn($v['uuid'],'',$v['doid']);}
if($v['authorpermitted']>0)
{$rows[$k]['btns']=$this->createOfflineCtBtn($v['uuid'],'c',$v['doid']);}
if($v['authorpermitted']<0)
{$rows[$k]['btns']=$this->createOfflineCtBtn($v['uuid'],'o',$v['doid']);}
}
$paginator = Zend_Paginator::factory($rows);
$paginator->setCurrentPageNumber($this->_getParam('page'));
$paginator->setItemCountPerPage(10);
$paginator->setView($this->view);
Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination_param.phtml');
$this->view->paginator=$paginator;
}else{
$this->view->error = "参数有误";
}
}else{
$this->_helper->viewRenderer('inauthor-datalist');
$sql = "select md.title,d.uuid,count(md.id) as c from dataorder d
left join metadata md on md.uuid=d.uuid
left join mdauthor a on a.uuid=d.uuid
where a.status=1 AND a.userid=? ";
if($ac == "searchdata")
{
$keywords = $this->_request->getParam('q');
if(!empty($keywords))
$this->view->q = $keywords;
$search=new Search($keywords);
$where=$search->sql_expr(array("md.title","md.description"));
$sql.=' and '.$where;
}
$sql.=" GROUP BY md.title,d.uuid";
$sth = $this->db->prepare($sql);
$sth->execute(array($u_id));
$rows = $sth->fetchAll();
$paginator = Zend_Paginator::factory($rows);
$paginator->setCurrentPageNumber($this->_getParam('page'));
$paginator->setItemCountPerPage(10);
$paginator->setView($this->view);
Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination_param.phtml');
$this->view->paginator=$paginator;
}
}//按数据显示
} // inauthorAction() 数据申请管理
/*
* createOfflineCtBtn() 创建离线申请记录的操作按钮
*
*/
function createOfflineCtBtn($uuid, $type="",$oid){
$urlHref = 'href="javascript:;"';
$baseStyle = "offline-ct-btns box-shadow";
$selectedStyle = "offline-select";
$confrimText = "同意";
$confrimFunc = 'onclick="confirm(\''.$uuid.'\',\''.$oid.'\')"';
$objectionText = "反对";
$objectionFunc = 'onclick="objection(\''.$uuid.'\',\''.$oid.'\')"';
$btns='';
if(empty($type))
{
$confrimBtn = "<a $urlHref class=\"$baseStyle\" $confrimFunc>$confrimText</a>";
$objectionBtn = "<a $urlHref class=\"$baseStyle\" $objectionFunc>$objectionText</a>";
$btns = $confrimBtn.$objectionBtn;
}
if($type=='c')
{
$confrimBtn = "<a class=\"$baseStyle $selectedStyle\">$confrimText</a>";
$objectionBtn = "<a $urlHref class=\"$baseStyle\" $objectionFunc>$objectionText</a>";
$btns = $confrimBtn.$objectionBtn;
}
if($type=='o')
{
$confrimBtn = "<a $urlHref class=\"$baseStyle\" $confrimFunc>$confrimText</a>";
$objectionBtn = "<a class=\"$baseStyle $selectedStyle\">$objectionText</a>";
$btns = $confrimBtn.$objectionBtn;
}
return $btns;
} //createOfflineCtBtn()
2012-02-22 12:21:22 +00:00
/*
* acceptAction() 我的数据
*
* param string $ac // list|search
* param string $keyword
*
* return view
*/
function acceptAction()
{
$ac = $this->_request->getParam("ac");
$auth = Zend_Auth::getInstance();
if($auth->hasIdentity())
{
$user = $auth->getIdentity();
$u_id = $user->id;
$u_email = $user->email;
}
//列表
if(empty($ac) || $ac=='list' || $ac=='search'){
$sql = "SELECT a.*,m.title,m.description,g.id as gid FROM normalmetadata m
2012-03-23 07:39:52 +00:00
LEFT JOIN mdauthor a ON m.uuid=a.uuid
left join geonetworkmetadata g on m.uuid=g.uuid
2012-03-23 09:53:07 +00:00
WHERE a.userid=? AND status>=0";
if ($ac=='search')
{
$key = trim($this->_request->getParam('q'));
$this->view->q = $key;
$search=new Search($key);
2012-03-23 09:53:07 +00:00
$where=$search->sql_expr(array("m.title","m.description"));
$sql.=' and '.$where;
}
$sql.="ORDER BY status DESC,a.id DESC";
$sth = $this->db->prepare($sql);
$sth->execute(array($u_id));
$rows = $sth->fetchAll();
$paginator = Zend_Paginator::factory($rows);
$paginator->setCurrentPageNumber($this->_getParam('page'));
$paginator->setItemCountPerPage(5);
$paginator->setView($this->view);
Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination_param.phtml');
$this->view->paginator=$paginator;
}//list
2012-03-20 09:34:44 +00:00
//激活数据作者
if($ac == "active")
{
$this->_helper->viewRenderer('accept-active');
$vdcode = $this->_request->getParam('v');
$this->view->v = $vdcode;
try{
$sql = "SELECT a.id,a.activation,a.ts_created,a.ts_activated,md.title,a.uuid,u.id as userid,u.realname,u.email FROM mdauthor a
LEFT JOIN metadata md ON a.uuid=md.uuid
LEFT JOIN users u ON a.userid=u.id
2012-03-20 09:34:44 +00:00
WHERE a.activation=?";
$sth = $this->db->prepare($sql);
2012-03-20 09:34:44 +00:00
$sth->execute(array($vdcode));
$row = $sth->fetch();
2012-03-20 09:34:44 +00:00
if(empty($row['id']))
{
2012-03-20 09:34:44 +00:00
$this->view->info='此激活码无效';
}else{
if(empty($row['ts_activated']))
{
$sql = "UPDATE mdauthor SET ts_activated=?,status=? WHERE activation=?";
$sth = $this->db->prepare($sql);
$ex = $sth->execute(array('now()',1,$vdcode));
if($ex)
{
2012-03-27 10:17:51 +00:00
include_once("EmailText.php");
$this->author_first($row['uuid'],$row['userid']);
$mail=new WestdcMailer($this->view->config->smtp);
$mail->setFrom($this->view->config->service->email,'西部数据中心服务组');
2012-03-21 02:56:50 +00:00
$mailtp=new EmailText($this->db,"author-new",array(
'user' => $row['realname'],
'uuid' => $row['uuid'],
'title'=> $row['title'],
'email'=> $row['email'],
));
$mail->setBodyText($mailtp->getBody());
$mail->setSubject($mailtp->getSubject());
if($this->debug==0)
{
//获得元数据作者email
2012-03-21 02:56:50 +00:00
/* 不需要给这些人发通知邮件
2012-03-20 09:34:44 +00:00
$info = $this->getEmail($uuid,1);
$address = $info['addrs'];
foreach($address as $v)
{
2012-03-20 09:34:44 +00:00
$mail->addTo($v);
2012-03-21 02:56:50 +00:00
}*/
$mail->addTo($row['email']);
$mail->addCc($this->view->config->service->email); //管理员
}else{
$mail->addTo($this->debug_email);
}
$mail->send();
$this->view->info = '激活成功<br /><a href="/author/accept">点击这里</a>进入我的数据页面查看';
}else
{
$this->view->info = "激活中遇到问题,请重试";
}
}else
{
2012-03-20 09:34:44 +00:00
$this->view->info='此激活码已经失效';
}
}
}catch(Exception $e){
if($this->debug==0)
{
$this->view->info = "处理中遇到错误,请重新尝试";
}else{
$this->view->info = $e->getMessage();
}
}
2012-03-20 09:34:44 +00:00
}//激活数据作者
//拒绝激活
2012-03-20 09:34:44 +00:00
if($ac == "lock")
{
$this->_helper->viewRenderer('accept-active');
$vdcode = $this->_request->getParam('v');
$this->view->v = $vdcode;
try{
$sql = "SELECT a.id,a.activation,a.ts_created,a.ts_activated,md.title,a.uuid,u.realname,u.email FROM mdauthor a
LEFT JOIN metadata md ON a.uuid=md.uuid
LEFT JOIN users u ON a.userid=u.id
WHERE a.activation=?";
$sth = $this->db->prepare($sql);
$sth->execute(array($vdcode));
$row = $sth->fetch();
if(empty($row['id']))
{
$this->view->info='此激活码无效';
}else{
if(empty($row['ts_activated']))
{
$sql = "UPDATE mdauthor SET ts_activated=?,status=? WHERE activation=?";
$sth = $this->db->prepare($sql);
$ex = $sth->execute(array('now()',-1,$vdcode));
if($ex)
{
include_once("EmailText.php");
$mail=new WestdcMailer($this->view->config->smtp);
$mail->setFrom($this->view->config->service->email,'西部数据中心服务组');
$mailtp=new EmailText($this->db,"author-deny",array(
'user' => $row['realname'],
'uuid' => $row['uuid'],
'title'=> $row['title'],
'email'=> $row['email'],
));
$mail->setBodyText($mailtp->getBody());
$mail->setSubject($mailtp->getSubject());
if($this->debug==0)
{
$mail->addTo($row['email']);
2012-03-21 02:56:50 +00:00
$mail->addCc($this->view->config->service->email);
2012-03-20 09:34:44 +00:00
}else{
$mail->addTo($this->debug_email);
}
$mail->send();
$this->view->info = '该申请已被拒绝,<a href="/author/accept">点击这里</a>进入我的数据页面查看';
}else
{
$this->view->info = "激活中遇到问题,请重试";
}
}else
{
$this->view->info='此激活码已经失效';
}
}
}catch(Exception $e){
if($this->debug==0)
{
$this->view->info = "处理中遇到错误,请重新尝试";
}else{
$this->view->info = $e->getMessage();
}
}
}//否认激活
}//acceptAction() 我的数据
2012-03-20 09:34:44 +00:00
/*
*
* getEmail() 获取数据所有者电子邮箱地址
*
* param string $uuid //UUID
* param int $level //输出信息等级
* 0 => 输出所有Email地址
* 1 => 输出数据权限等级最高的Email地址 (def)
*
* return array()
*/
function getEmail($uuid,$level=1)
{
//需要定义角色,防止程序流程出错
$addrs = array();
$addrs['resourceProvider'] = array();
$addrs['owner'] = array();
$addrs['pointOfContact'] = array();
$addrs['author'] = array();
$addrs["publisher"] = array();
2012-03-21 02:56:50 +00:00
$sql = 'select r.uuid,p.email,md.title,r.role from normalmetadata md
2012-03-20 09:34:44 +00:00
LEFT JOIN role r ON md.uuid=r.uuid
left join responsible p on r.resid=p.id
WHERE r.uuid=? AND p.email IS NOT NULL AND p.email!=?
GROUP BY r.uuid,p.email,md.title,r.role';
$sth = $this->db->prepare($sql);
$sth->execute(array($uuid,''));
$rows = $sth->fetchAll();
$addrs['title'] = $rows[0]['title'];
foreach($rows as $k=>$v)
{
//数据资源提供者resourceProvider
if($v['role']=='resourceProvider')
{
$addrs['resourceProvider'][]=$v['email'];
}
//数据资源所有者owner
if($v['role']=='owner')
{
$addrs['owner'][]=$v['email'];
}
//数据联系人pointOfContact
if($v['role']=='pointOfContact')
{
$addrs['pointOfContact'][]=$v['email'];
}
//元数据作者author
if($v['role']== 'author' )
{
$addrs['author'][] = $v['email'];
}
if($v["role"] =="")
{
$addrs["publisher"][] = $v['email'];
}
}
2012-03-21 02:56:50 +00:00
//输出所有email (多维数组)
2012-03-20 09:34:44 +00:00
/*
$addrs['resourceProvider']
$addrs['owner']
$addrs['pointOfContact']
$addrs['author']
*/
if($level == 0)
{
return $addrs;
}
//输出最高优先级的Email
//$addrs['addrs']
if($level == 1)
{
//如果有 数据资源提供者 resourceProvider 就输出他的地址 以此类推
if(count($addrs['resourceProvider'])>0)
{
$addrs['addrs'][] = $addrs['resourceProvider'];
return $addrs;
}
if(count($addrs['owner'])>0)
{
$addrs['addrs'][] = $addrs['owner'];
return $addrs;
}
if(count($addrs['pointOfContact'])>0)
{
$addrs['addrs'][] = $addrs['pointOfContact'];
return $addrs;
}
if(count($addrs['author'])>0)
{
$addrs['addrs'][] = $addrs['author'];
return $addrs;
}
if(count($addrs["publisher"])>0)
{
$addrs['addrs'][] = $addrs["publisher"];
return $addrs;
}
}
}//getEmail 获取数据作者email地址
/*
* applyAction() 申请成为元数据作者
*
* param string $ac //动作 search|apply
* param string $q //搜索关键词
* param string $uuid //数据的UUID
*
* return view|ajax|json
*
* 调试搜索结果:
* /author/apply?ac=apply&uuid=816ecd28-ba88-464b-a83a-341440f536ef
*/
function applyAction()
{
$ac = $this->_request->getParam('ac');
//搜索动作
if($ac == "search")
{
$this->_helper->layout->disableLayout();
$this->_helper->viewRenderer->setNoRender();
//要输出的Json对象
//过程中如果没有处理,则不包含任何返回信息,由前台定义提示信息,如:
/*
$.ajax({
'type':"POST",
'url':'/author/apply',
'data':'ac=search&q='+$('#keyword').val(),
'success':function(data){
if (typeof(data)=='object') //如果服务器端的响应为Json对象
{
if(typeof(data.error)!='undefined') //服务器端响应的错误消息
{
alert(data.error);
}else{ //服务器端无错误消息则为成功的响应
alert(data.length);
}
}else{ //服务器端响应了非JSON对象或者为空
alert('无搜索结果');
}
},
'beforeSend':function(){
//请求发送前
}
});
错误消息的键名必须为error不包含JS脚本,如:
$data['error'] = '服务器忙!';
*/
$data = "";
//防止通过其它方式访问,先判断是否是登录用户,如果不是,抛出消息后强制用户退出
$auth = Zend_Auth::getInstance();
if($auth->hasIdentity())
{
$user = $auth->getIdentity();
$u_id = $user->id;
}else{
$data = array("error"=>"请先登录");
$this ->getResponse()
->setHeader('Content-Type', 'application/json')
->appendBody(Zend_Json::encode($data));
2012-03-27 10:17:51 +00:00
return true;
}
//数据处理代码 EOH<<<<<<<<<<<<<<<<
try{
2012-03-23 09:53:07 +00:00
$keyword = trim($this->_request->getParam('q'));
if (strlen(trim($keyword))<3)
2012-03-23 09:16:06 +00:00
$data = array('error'=>'搜索关键字过短');
else if (!preg_match_all("/^[\x{4e00}-\x{9fa5}A-Za-z0-9\s_]+$/u",$keyword,$matchs))
{
$data = array('error'=>'搜索关键字中只能包含汉字、英文、数字');
}
else
{
//搜索标题和描述两个字段
2012-03-19 09:06:00 +00:00
$sql = "SELECT m.uuid,m.title,m.description,a.status,a.userid FROM normalmetadata m
LEFT JOIN mdauthor a ON m.uuid=a.uuid
2012-03-23 09:53:07 +00:00
WHERE ";
2012-03-23 09:16:06 +00:00
$search=new Search($keyword);
2012-03-23 09:53:07 +00:00
$where=$search->sql_expr(array("m.title","m.description"));
2012-03-23 09:16:06 +00:00
$sql.=$where;
$sth = $this->db->prepare($sql);
2012-03-23 09:16:06 +00:00
$sth->execute();
$rows = $sth->fetchAll();
if(is_array($rows) && count($rows)>0)
$data = $rows;
else
$data = "";
}
}catch(Exception $e){
//如果上面的程序已经发送出提示,就不发送抛出的错误
if(empty($data['error']))
{
if($this->debug==0)
{
$data = array("error"=>"处理过程中遇到错误,请重新尝试");
}else{
$data = array("error"=>$e->getMessage());
}
}
}
// >>>>>>>>>>> F
//截获响应对象,并修改头部和内容
//不管有没有数据存在都将返回Json数据前台有判断机制来分析数据
$this ->getResponse()
->setHeader('Content-Type', 'application/json')
->appendBody(Zend_Json::encode($data));
}// search
/****************
申请动作
****************/
if($ac == "apply")
{
$this->_helper->layout->disableLayout();
$this->_helper->viewRenderer->setNoRender();
$data = "";
$auth = Zend_Auth::getInstance();
if($auth->hasIdentity())
{
$user = $auth->getIdentity();
$u_id = $user->id;
$u_email = $user->email;
}
//处理部分<<<<<<<<<<
try{
$uuid = $this->_request->getParam('uuid');
if(preg_match("/^[0-9A-Za-z]{8}-[0-9A-Za-z]{4}-[0-9A-Za-z]{4}-[0-9A-Za-z]{4}-[0-9A-Za-z]{12}$/",$uuid))
{
//判断该用户是否已经申请过或者是否已经是该元数据作者
$sql="SELECT id,status FROM mdauthor WHERE uuid=? AND userid=?";
$sth = $this->db->prepare($sql);
$sth->execute(array($uuid,$u_id));
$row = $sth->fetch();
//如果已经是元数据作者,从流程中直接退出程序
if(!empty($row['id']) && $row['status']==1)
{
$data = array("error"=>"您目前已经是该数据作者,不需要再申请");
}
2012-03-20 09:34:44 +00:00
//如果已经遭到明确拒绝,则不允许用户再次申请
if(!empty($row['id']) && $row['status']==-1)
{
$data = array("error"=>"您的申请已经遭到拒绝,不能再申请,有疑问请联系数据中心");
}
//如果已经存在申请,但是没有激活的,返回激活信息
if($row['status']==0){
if(!empty($row['id']) && empty($m))
{
$data = array(
2012-03-20 09:34:44 +00:00
"error"=>'您已经申请过了,如果长时间没有收到回应请联系数据中心',
"post"=>"activa",
"uid"=>$u_id,
"uemail"=>$u_email,
"uuid"=>$uuid,
);
}//if
else{
2012-03-20 09:34:44 +00:00
$info = $this->getEmail($uuid,1);
$address = $info['addrs'];
$mdtitle = $info['title'];
//如果当前用户的email包含在元数据作者email列表中则直接使其成为元数据作者
if(in_array($u_email,$address))
{
$sql = "INSERT INTO mdauthor (uuid,userid,activation,ts_activated,status) VALUES (?,?,?,?,?)";
$sth = $this->db->prepare($sql);
$ex = $sth->execute(array($uuid,$u_id,'','now()',1));
if($ex)
{
2012-03-27 10:17:51 +00:00
$data = array("error"=>"您的身份符合申请条件,已经自动成为该元数据作者");
$this->author_first($uuid,$u_id);
include_once("EmailText.php");
$mail=new WestdcMailer($this->view->config->smtp);
$mail->setFrom($this->view->config->service->email,'西部数据中心服务组');
2012-03-21 02:56:50 +00:00
$mailtp=new EmailText($this->db,"author-new",array(
'user' => $user->realname,
'uuid' => $uuid,
'title'=> $mdtitle,
'email'=> $u_email,
));
$mail->setBodyText($mailtp->getBody());
$mail->setSubject($mailtp->getSubject());
2012-03-21 02:56:50 +00:00
if($this->debug==0)
{
foreach ($address as $dist)
{$mail->addTo($dist);} //元数据作者
$mail->addTo($u_email);
$mail->addCc($this->view->config->service->email); //管理员
}else{
$mail->addTo($this->debug_email);
}
$mail->send();
}
else
{
$data = array("error"=>"处理中出现错误,请重新尝试");
}
}
//如果不包含在当前元数据作者的email列表中
2012-03-20 09:34:44 +00:00
//给数据拥有者发送邮件,使其决定是否同意新加入作者
else
{
//生成激活码
$ssid = session_id();
$vdcode = md5($uuid.$ssid.$u_id.time());
//激活链接
// /author/accept/?ac=active&vdcode=$vdcode
$sql = "INSERT INTO mdauthor (uuid,userid,activation) VALUES (?,?,?)";
$sth = $this->db->prepare($sql);
$ex = $sth->execute(array($uuid,$u_id,$vdcode));
if($ex)
{
2012-03-21 02:56:50 +00:00
//给申请者发送邮件
include_once("EmailText.php");
@$mail=new WestdcMailer($this->view->config->smtp);
@$mail->setFrom($this->view->config->service->email,'西部数据中心服务组');
2012-03-19 09:06:00 +00:00
@$mailtp=new EmailText($this->db,"author-apply",array(
'user' => $user->username,
'uuid' => $uuid,
'email'=> $user->email,
2012-03-20 09:34:44 +00:00
//元数据标题
'title'=> $mdtitle,
));
@$mail->setBodyText($mailtp->getBody());
@$mail->setSubject($mailtp->getSubject());
if($this->debug==0)
{
2012-03-20 09:34:44 +00:00
@$mail->addTo($user->email);
}else{
@$mail->addTo($this->debug_email);
}
@$mail->send();
unset($mail);
unset($mailtp);
2012-03-21 02:56:50 +00:00
//给元数据作者以及管理员发送邮件
@$mail=new WestdcMailer($this->view->config->smtp);
@$mail->setFrom($this->view->config->service->email,'西部数据中心服务组');
2012-03-19 09:06:00 +00:00
@$mailtp=new EmailText($this->db,"author-apply-confirm",array(
'user' => $user->username,
'uuid' => $uuid,
'email'=> $u_email,
'title'=> $mdtitle,
'link'=>"http://".$_SERVER['SERVER_NAME']."/data/$uuid",
2012-03-20 09:34:44 +00:00
//验证码
'vdcode' => $vdcode,
//激活链接
'active'=>"http://".$_SERVER['SERVER_NAME']."/author/accept/?ac=active&v=$vdcode",
//不同意激活的链接
'lock'=>"http://".$_SERVER['SERVER_NAME']."/author/accept/?ac=lock&v=$vdcode",
));
@$mail->setBodyText($mailtp->getBody());
@$mail->setSubject($mailtp->getSubject());
2012-03-21 02:56:50 +00:00
if($this->debug==0)
{
$sql = "SELECT u.email FROM mdauthor a
LEFT JOIN users u ON u.id=a.userid
WHERE a.uuid=?";
$sth = $this->db->prepare($sql);
$sth->execute(array($uuid));
$mlist = $sth->fetchAll();
if(count($mlist)>0)
{
foreach($mlist as $v)
{
$mail->addTo($v['email']);
}
}//mdauthor中已经注册的用户
else{
foreach ($address as $dist)
{
$mail->addTo($dist);
}
}//元数据作者
2012-03-21 02:56:50 +00:00
$mail->addCc($this->view->config->service->email); //管理员
}else{
@$mail->addTo($this->debug_email);
}
2012-03-20 09:34:44 +00:00
@$mail->send();
2012-03-20 09:34:44 +00:00
$data = array("error"=>"您的申请已收到,请耐心等待回应");
}else{
$data = array("error"=>"服务器可能在忙,请重试。");
}//激活码记录
}//不是确认的元数据作者
}//empty($row['id'])
}// status == 0
//调试输出结果
//$data = array('addr'=>$address,'uemail'=>$u_email);
}
else
{
$data = array('error'=>'参数出错,请按照正确的访问方式申请');
}
}catch(Exception $e){
if(empty($data['error']))
{
if($this->debug==0)
{
$data = array("error"=>"处理过程中遇到错误,请重新尝试");
}else{
$data = array("error"=>$e->getMessage());
}
}
}
// >>>>>>>>>>>>
$this ->getResponse()
->setHeader('Content-Type', 'application/json')
->appendBody(Zend_Json::encode($data));
}// ac = apply 申请处理
}//applyAction() 申请成为元数据作者
/*
* commentAction() 数据反馈
*
2012-03-20 09:34:44 +00:00
* param string $ac 动作
* param string $uuid 元数据UUID
* param int $page 页数
*
2012-03-20 09:34:44 +00:00
* return view
*/
function commentAction()
{
$ac = $this->_request->getParam('ac');
$auth = Zend_Auth::getInstance();
if($auth->hasIdentity())
{
$user = $auth->getIdentity();
$u_id = $user->id;
}
if(empty($ac)|| $ac=='list')
{
$sql = "SELECT md.title,md.uuid,count(c.id) as c FROM comments c
LEFT JOIN metadata md ON md.uuid=c.uuid
LEFT JOIN mdauthor a ON md.uuid=a.uuid
WHERE md.title IS NOT NULL AND a.userid=? AND a.status=1
GROUP BY md.title,md.uuid
";
$sth = $this->db->prepare($sql);
$sth->execute(array($u_id));
$rows = $sth->fetchAll();
$paginator = Zend_Paginator::factory($rows);
$paginator->setCurrentPageNumber($this->_getParam('page'));
$paginator->setItemCountPerPage(15);
$paginator->setView($this->view);
Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination_param.phtml');
$this->view->paginator=$paginator;
}
if($ac=="view")
{
$uuid = $this->_request->getParam('uuid');
if(preg_match("/^[0-9A-Za-z]{8}-[0-9A-Za-z]{4}-[0-9A-Za-z]{4}-[0-9A-Za-z]{4}-[0-9A-Za-z]{12}$/",$uuid))
{
2012-03-23 14:41:51 +00:00
$sql = "SELECT c.author,c.email,c.url,c.ts_created,c.content,m.title FROM comments c
LEFT JOIN mdauthor a ON a.uuid=c.uuid
2012-03-23 14:41:51 +00:00
left join metadata m on m.uuid=c.uuid
WHERE c.uuid=? AND a.userid=? AND a.status=1
ORDER BY ts_created DESC";
$sth = $this->db->prepare($sql);
$sth->execute(array($uuid,$u_id));
$rows = $sth->fetchAll();
2012-03-23 14:41:51 +00:00
@$this->view->mdtitle=$rows[0]['title'];
$paginator = Zend_Paginator::factory($rows);
$paginator->setCurrentPageNumber($this->_getParam('page'));
$paginator->setItemCountPerPage(10);
$paginator->setView($this->view);
Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination_param.phtml');
$this->view->paginator=$paginator;
}
$this->_helper->viewRenderer('comment-list');
}
if($ac == "listall")
{
$sql = "SELECT md.title,c.author,c.email,c.url,c.ts_created,c.content FROM comments c
LEFT JOIN mdauthor a ON a.uuid=c.uuid
LEFT JOIN normalmetadata md ON md.uuid=c.uuid
WHERE a.userid=? AND a.status=1
ORDER BY ts_created DESC";
$sth = $this->db->prepare($sql);
$sth->execute(array($u_id));
$rows = $sth->fetchAll();
$paginator = Zend_Paginator::factory($rows);
$paginator->setCurrentPageNumber($this->_getParam('page'));
$paginator->setItemCountPerPage(10);
$paginator->setView($this->view);
Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination_param.phtml');
$this->view->paginator=$paginator;
$this->_helper->viewRenderer('comment-listall');
}
}// commentAction() 数据反馈
2012-03-20 09:34:44 +00:00
/*
* newsAction() 数据新闻
*
* param string $ac
*
*
*/
function newsAction(){
$ac = $this->_request->getParam('ac');
$auth = Zend_Auth::getInstance();
if($auth->hasIdentity())
{
$user = $auth->getIdentity();
$u_id = $user->id;
}
2012-03-23 07:39:52 +00:00
//新闻列表
if(empty($ac) || $ac=="list")
{
2012-03-23 09:53:07 +00:00
$keyword = $this->_request->getParam('q');
$uuid = $this->_request->getParam('uuid');
2012-03-23 09:53:07 +00:00
$wheresql = "";
$join = "";
2012-03-23 09:53:07 +00:00
if(!empty($keyword))
{
$this->view->q = $keyword;
$search = new Search($keyword);
$wheresql = $search->sql_expr(array("arc.title","arc.description"));
}
if(!empty($wheresql))
{
$wheresql = " AND ".$wheresql;
}
if(!empty($uuid) && preg_match("/^[0-9A-Za-z]{8}-[0-9A-Za-z]{4}-[0-9A-Za-z]{4}-[0-9A-Za-z]{4}-[0-9A-Za-z]{12}$/",$uuid))
{
$join = "LEFT JOIN news_mdnews mdnews ON mdnews.aid=arc.id";
$wheresql .= " AND mdnews.uuid='$uuid'";
2012-03-23 09:53:07 +00:00
}
$sql = "SELECT arc.id,arc.title,arc.ts_published,arc.description,u.realname FROM news_archives arc
2012-03-23 09:53:07 +00:00
LEFT JOIN users u ON arc.userid=u.id
$join
WHERE arc.is_pub>0 AND arc.ts_published<'now()' $wheresql
ORDER BY arc.ts_published";
2012-03-23 09:53:07 +00:00
2012-03-23 09:53:07 +00:00
$sth = $this->db->prepare($sql);
$sth->execute();
$rows = $sth->fetchAll();
$paginator = Zend_Paginator::factory($rows);
$paginator->setCurrentPageNumber($this->_getParam('page'));
$paginator->setItemCountPerPage(10);
$paginator->setView($this->view);
Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination_param.phtml');
$this->view->paginator=$paginator;
}
if($ac == "view")
{
$this->_helper->viewRenderer('news-view');
$aid = (int)$this->_request->getParam('aid');
if(empty($aid) || !is_numeric($aid))
{
$this->_redirect('/error/error');
}
else
{
$this->db->exec("UPDATE news_archives arc SET click=click+1 WHERE arc.id=$aid");
$sql = "SELECT arc.*,u.realname FROM news_archives arc
LEFT JOIN users u ON u.id=arc.userid
WHERE arc.id=?";
$sth = $this->db->prepare($sql);
$sth -> execute(array($aid));
$row = $sth->fetch();
$this->view->info = $row;
}
2012-03-23 07:39:52 +00:00
}
2012-03-20 09:34:44 +00:00
//新闻发布
if($ac == "add")
{
$this->_helper->viewRenderer('news-add');
$sql = "SELECT md.title,md.uuid FROM metadata md
LEFT JOIN mdauthor a ON a.uuid = md.uuid
WHERE a.userid=? AND a.status=1
";
$sth = $this->db->prepare($sql);
$sth->execute(array($u_id));
$rows = $sth->fetchAll();
$this->view->md = $rows;
2012-03-20 09:34:44 +00:00
}// $ac == add
2012-03-23 09:53:07 +00:00
//新闻编辑
if($ac == "edit")
{
$this->_helper->viewRenderer('news-edit');
$aid = (int)$this->_request->getParam('aid');
if(empty($aid) || !is_numeric($aid))
{
$this->_redirect('/error/error');
}
$sql = "SELECT arc.*,mdarc.uuid FROM news_archives arc
LEFT JOIN news_mdnews mdarc ON mdarc.aid = arc.id
WHERE id=?";
2012-03-23 09:53:07 +00:00
$sth = $this->db->prepare($sql);
$sth->execute(array($aid));
$row = $sth->fetch();
$this->view->info = $row;
}//$ac == "edit"
2012-03-23 09:53:07 +00:00
2012-03-20 09:34:44 +00:00
//新闻发布的ajax动作
if($ac =="addnews")
{
2012-03-23 07:39:52 +00:00
try{
$this->_helper->layout->disableLayout();
$this->_helper->viewRenderer->setNoRender();
$data = array();
2012-03-23 09:53:07 +00:00
$aid = $this->_request->getParam('aid');
$data['title'] = trim($this->_request->getParam('title'));
$data['keyword'] = trim($this->_request->getParam('keyword'));
$data['body'] = trim($this->_request->getParam('body'));
$uuid = trim($this->_request->getParam('uuid'));
2012-03-23 07:39:52 +00:00
//对参数进行预处理
foreach($data as $k=>$v)
{
$data[$k]=preg_replace("#<a([^>]*)>(.*)</a>#i","",$v);
$data[$k]=preg_replace("#<script([^>]*)>(.*)</script>#i","",$v);
$data[$k]=preg_replace("#<iframe([^>]*)>(.*)</iframe>#i","",$v);
$data[$k]=str_replace("\"","",$v);
$data[$k]=str_replace("\'","",$v);
}
$msg = array();
// 合法性判断
if(mb_strlen($data['title'],"utf-8")<3)
{
$msg['status'] = 0;
$msg['error'] = '标题太短,请重新填写';
$this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(Zend_Json::encode($msg));
return true;
}
if(mb_strlen($data['title'],"utf-8")>60)
{
$msg['status'] = 0;
$msg['error'] = '标题太长,请重新填写';
$this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(Zend_Json::encode($msg));
return true;
}
if(empty($uuid))
{
$msg['status'] = 0;
$msg['error'] = '请选择对应数据';
$this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(Zend_Json::encode($msg));
return true;
}
2012-03-23 07:39:52 +00:00
if(mb_strlen($data['keyword'],"utf-8")<4)
{
$msg['status'] = 0;
$msg['error'] = '关键词太短,请重新填写';
$this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(Zend_Json::encode($msg));
return true;
}
if(mb_strlen($data['keyword'],"utf-8")>40)
{
$msg['status'] = 0;
$msg['error'] = '关键词太长,请重新填写';
$this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(Zend_Json::encode($msg));
return true;
}
if(mb_strlen($data['body'],"utf-8")<40)
{
$msg['status'] = 0;
$msg['error'] = '新闻内容太短,请重新填写';
$this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(Zend_Json::encode($msg));
return true;
}
if(!preg_match("/^[0-9A-Za-z]{8}-[0-9A-Za-z]{4}-[0-9A-Za-z]{4}-[0-9A-Za-z]{4}-[0-9A-Za-z]{12}$/",$uuid))
{
$msg['status'] = 0;
$msg['error'] = '参数错误,请重试';
$this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(Zend_Json::encode($msg));
return true;
}
2012-03-23 07:39:52 +00:00
//获得描述
//删除段落及html标记
$data['description'] = mb_substr(preg_replace(array("/<(.*)>|<(.*) \/>/i","/\s/i"),array(""," "),$data['body']),0,450,"UTF-8");
//默认填充数据
$data['source'] = "西部数据中心";
$data['typeid'] = 0;
$data['userid'] = $u_id;
2012-03-23 09:53:07 +00:00
$data['keyword'] = str_replace("",",",$data['keyword']);
//新闻添加
2012-03-23 09:53:07 +00:00
if(empty($aid))
{
$sql = "INSERT INTO news_archives
(userid,title,keywords,description,image,source,ts_published,is_pub,body)
2012-03-23 09:53:07 +00:00
VALUES
(?,?,?,?,?,?,?,?,?)
RETURNING id
2012-03-23 09:53:07 +00:00
";
$sth = $this->db->prepare($sql);
$ex = $sth -> execute(array($data['userid'],$data['title'],$data['keyword'],$data['description'],'',$data['source'],'now()',1,$data['body']));
//添加成功
if($ex)
{
//写入文章ID对应UUID的表
$archive = $sth->fetch(PDO::FETCH_ASSOC);
$aid = $archive['id'];
$sql = "INSERT INTO news_mdnews (aid,uuid) VALUES (?,?)";
$sth = $this->db->prepare($sql);
$uuidex = $sth->execute(array($aid,$uuid));
if($uuidex)
{
$msg['status'] = 1;
$msg['outstring'] = "新闻添加成功";
$this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(Zend_Json::encode($msg));
return true;
}else{
$sql = "DELETE FROM news_archives WHERE id=$aid";
@$this->db->exec($sql); //如果新闻添加失败就删除原新闻,否则产生重复错误
$msg['status'] = 0;
$msg['error'] = "新闻添加失败,请重试";
$this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(Zend_Json::encode($msg));
return true;
}
//添加失败
}else{
$msg['status'] = 0;
$msg['error'] = "新闻添加失败,请重试";
$this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(Zend_Json::encode($msg));
return true;
}
}//新闻添加 end -->
//新闻修改
2012-03-23 09:53:07 +00:00
else
{
$sql = "UPDATE news_archives SET title=?,keywords=?,description=?,body=? WHERE id=? AND userid=?";
$sth = $this->db->prepare($sql);
$ex = $sth -> execute(array($data['title'],$data['keyword'],$data['description'],$data['body'],$aid,$data['userid']));
if($ex)
{
$msg['status'] = 1;
$msg['outstring'] = "新闻编辑成功";
$this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(Zend_Json::encode($msg));
return true;
}else{
$msg['status'] = 0;
$msg['outstring'] = "新闻编辑失败,请重试";
$this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(Zend_Json::encode($msg));
return true;
}
}//新闻修改 end -->
2012-03-23 07:39:52 +00:00
}catch(Exception $e){
if($this->debug==0)
{
$msg['status'] = 0;
2012-03-23 09:53:07 +00:00
if(empty($aid))
{$msg['error'] = "新闻添加失败,请重试";}
else
{$msg['error'] = "新闻编辑失败,请重试";}
2012-03-23 07:39:52 +00:00
$this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(Zend_Json::encode($msg));
return true;
}else{
$msg['status'] = 0;
2012-03-23 09:53:07 +00:00
$msg['error'] = "新闻添加/编辑失败,请重试:".$e->getMessage();
2012-03-23 07:39:52 +00:00
$this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(Zend_Json::encode($msg));
return true;
}
}//catch end
}//$ac = 'newsadd' endif;
2012-03-20 09:34:44 +00:00
}//newsAction() 数据新闻
function viewauthorsAction(){
$this->_helper->viewRenderer('view-authors');
$uuid = $this->_request->getParam('uuid');
if(preg_match("/^[0-9A-Za-z]{8}-[0-9A-Za-z]{4}-[0-9A-Za-z]{4}-[0-9A-Za-z]{4}-[0-9A-Za-z]{12}$/",$uuid))
{
$sql = "SELECT u.realname,u.unit,u.email,m.title,m.description FROM normalmetadata m
LEFT JOIN mdauthor a ON m.uuid=a.uuid
LEFT JOIN users u ON u.id=a.userid
WHERE status>=0 AND m.uuid=? AND a.status=1
ORDER BY status DESC,a.id DESC";
$sth = $this->db->prepare($sql);
$sth->execute(array($uuid));
$rows = $sth->fetchAll();
$paginator = Zend_Paginator::factory($rows);
$paginator->setCurrentPageNumber($this->_getParam('page'));
$paginator->setItemCountPerPage(10);
$paginator->setView($this->view);
Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination_param.phtml');
$this->view->paginator=$paginator;
}else{
$this->view->error = "参数有误";
}
}
function versionAction()
{
2012-03-27 10:17:51 +00:00
$ac = $this->_request->getParam('ac');
$uuid = $this->_request->getParam('uuid');
$auth = Zend_Auth::getInstance();
if($auth->hasIdentity())
{
$user = $auth->getIdentity();
$u_id = $user->id;
}
2012-03-27 10:17:51 +00:00
//查看单条数据的所有版本
if (!empty($uuid) && empty($ac))
{
//view the versions of the data
$sql = "SELECT md.title,md.uuid,v.ts_created,v.changelog,v.userid,v.id,u.username,u.realname FROM mdversion v
LEFT JOIN metadata md ON md.uuid=v.uuid
2012-03-27 10:17:51 +00:00
LEFT JOIN mdauthor a ON md.uuid=a.uuid
left join users u on v.userid=u.id
WHERE md.title IS NOT NULL AND a.userid=? and v.uuid=? AND a.status=1
order by v.ts_created desc
";
$sth = $this->db->prepare($sql);
$sth->execute(array($u_id,$uuid));
2012-03-27 10:17:51 +00:00
$rows = $sth->fetchAll();
@$this->view->mdtitle=$rows[0]['title'];
$paginator = Zend_Paginator::factory($rows);
$paginator->setCurrentPageNumber($this->_getParam('page'));
$paginator->setItemCountPerPage(15);
$paginator->setView($this->view);
Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination_param.phtml');
2012-03-27 10:17:51 +00:00
$this->view->paginator=$paginator;
}
2012-03-27 10:17:51 +00:00
//查看所有版本列表
else if((empty($ac) && empty($uuid))|| $ac=='list')
{
$sql = "SELECT md.title,md.uuid,v.ts_created,v.changelog,v.userid,v.id,u.username,u.realname FROM mdversion v
LEFT JOIN metadata md ON md.uuid=v.uuid
2012-03-27 10:17:51 +00:00
LEFT JOIN mdauthor a ON md.uuid=a.uuid
left join users u on v.userid=u.id
WHERE md.title IS NOT NULL AND a.userid=? AND a.status=1
order by v.ts_created desc
";
$sth = $this->db->prepare($sql);
$sth->execute(array($u_id));
$rows = $sth->fetchAll();
$paginator = Zend_Paginator::factory($rows);
$paginator->setCurrentPageNumber($this->_getParam('page'));
$paginator->setItemCountPerPage(15);
$paginator->setView($this->view);
Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination_param.phtml');
$this->view->paginator=$paginator;
}
2012-03-27 10:17:51 +00:00
//按数据浏览
else if($ac=="bydata")
2012-03-27 10:17:51 +00:00
{
$keywords = $this->_request->getParam('q');
if(!empty($keywords))
$this->view->q = $keywords;
$sql = "SELECT md.title,md.uuid,count(v.id) as c FROM mdversion v
LEFT JOIN metadata md ON md.uuid=v.uuid
LEFT JOIN mdauthor a ON md.uuid=a.uuid
WHERE md.title IS NOT NULL AND a.userid=? AND a.status=1";
if(!empty($keywords))
{
2012-03-27 10:17:51 +00:00
$search=new Search($keywords);
$where=$search->sql_expr(array("md.title","md.description"));
$sql.=' and '.$where;
}
$sql.=" group by md.uuid,md.title";
2012-03-27 10:17:51 +00:00
$sth = $this->db->prepare($sql);
$sth->execute(array($u_id));
$rows = $sth->fetchAll();
$paginator = Zend_Paginator::factory($rows);
$paginator->setCurrentPageNumber($this->_getParam('page'));
$paginator->setItemCountPerPage(10);
$paginator->setView($this->view);
Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination_param.phtml');
$this->view->paginator=$paginator;
$this->_helper->viewRenderer('version-bydata');
}
2012-03-27 10:17:51 +00:00
//删除某个版本
else if($ac=="delete")
{
$this->_helper->layout->disableLayout();
$this->_helper->viewRenderer->setNoRender();
$data = "";
try{
$id = $this->_request->getParam('id');
if(empty($id) || !is_numeric($id))
{
$data = array("error"=>"参数错误");
$this->jsonexit($data);
2012-03-27 10:17:51 +00:00
return true;
}
$sql = "DELETE FROM mdversion v
USING mdauthor a
2012-03-29 15:12:37 +00:00
WHERE v.uuid=a.uuid and v.id=? AND a.userid=? AND a.status=1";
2012-03-27 10:17:51 +00:00
$sth = $this->db->prepare($sql);
$ex = $sth -> execute(array($id,$u_id));
if($ex)
{
$data = array("deleted"=>$id,"error"=>$this->alertbox('ok','删除成功'));
$this->jsonexit($data);
return true;
2012-03-27 10:17:51 +00:00
}else{
$data = array("error"=>$this->alertbox('error','删除失败,请确认权限后重试'));
$this->jsonexit($data);
return true;
2012-03-27 10:17:51 +00:00
}
}catch(Exception $e) {
$msg = "删除失败,请确认权限后重试";
if($this->debug>0)
{$msg .= $e->getMessage();}
$data = array("error"=>$this->alertbox('error',$msg));
$this->jsonexit($data);
return true;
2012-03-27 10:17:51 +00:00
}
}
//恢复到geonetwork
else if($ac == "restore")
{
$this->_helper->layout->disableLayout();
$this->_helper->viewRenderer->setNoRender();
$data = "";
try{
$id = $this->_request->getParam('id');
if(empty($id) || !is_numeric($id))
{
$data = array("error"=>"参数错误");
$this->jsonexit($data);
2012-03-27 10:17:51 +00:00
return true;
2012-03-29 15:12:37 +00:00
}
$this->wdb=Zend_Db::factory($this->view->config->geonetwork);
2012-03-27 10:17:51 +00:00
$sql = "SELECT v.xml,v.uuid FROM mdversion v
LEFT JOIN mdauthor a ON a.uuid=v.uuid
WHERE v.id=? AND a.userid=? AND a.status=1";
2012-03-27 10:17:51 +00:00
$sth = $this->db->prepare($sql);
$sth ->execute(array($id,$u_id));
$row = $sth->fetch();
$sql = "SELECT data FROM metadata WHERE uuid=?";
2012-03-29 15:12:37 +00:00
$sth = $this->wdb->prepare($sql);
2012-03-27 10:17:51 +00:00
$sth ->execute(array($row['uuid']));
$row_geo = $sth->fetch();
if($row['xml']==$row_geo['data'])
{
2012-03-29 15:12:37 +00:00
$data = array("error"=>$this->alertbox('warning','无须恢复,元数据相同'));
$this->jsonexit($data);
return true;
2012-03-27 10:17:51 +00:00
}
$sql = "UPDATE metadata SET data=? WHERE uuid=?";
2012-03-29 15:12:37 +00:00
$sth = $this->wdb->prepare($sql);
2012-03-27 10:17:51 +00:00
$ex = $sth ->execute(array($row['xml'],$row['uuid']));
if($ex)
2012-03-29 15:12:37 +00:00
{
$data = array("error"=>$this->alertbox('ok','恢复成功'));
$this->jsonexit($data);
return true;
2012-03-29 15:12:37 +00:00
}else{
$data = array("error"=>$this->alertbox('error','恢复失败,请确认权限后重试'));
$this->jsonexit($data);
return true;
2012-03-29 15:12:37 +00:00
}
2012-03-27 10:17:51 +00:00
}catch(Exception $e) {
$msg = "恢复失败,请确认权限后重试";
if($this->debug>0)
{$msg .= $e->getMessage();}
$data = array("error"=>$this->alertbox('error',$msg));
$this->jsonexit($data);
return true;
2012-03-27 10:17:51 +00:00
}
}
//发布到评审
else if($ac == "commit")
{
$this->_helper->layout->disableLayout();
$this->_helper->viewRenderer->setNoRender();
$data = "";
try{
$id = $this->_request->getParam('id');
if(empty($id) || !is_numeric($id))
{
$data = array("error"=>"参数错误");
$this->jsonexit($data);
2012-03-27 10:17:51 +00:00
return true;
2012-03-29 15:12:37 +00:00
}
$changelog = $this->_request->getParam('changelog');
if(empty($changelog))
{
$data = array("error"=>$this->alertbox('warning','请输入变更信息'));
$this->jsonexit($data);
return true;
}
// 1. 权限认定
$sql="select a.* from mdauthor a left join mdversion v on a.uuid=v.uuid
where a.status=1 and a.userid=? and v.id=?";
$sth=$this->db->prepare($sql);
$sth->execute(array($u_id,$id));
$row=$sth->fetch();
if (empty($row))
{
$data = array("error"=>'无权限修改数据');
$this->jsonexit($data);
return true;
}
// 2. 保存变化记录 save changelog & userid
$sql = "UPDATE mdversion SET changelog=?,userid=? WHERE id=?";
$this->db->query($sql,array($changelog,$u_id,$id));
2012-03-29 15:12:37 +00:00
// 3. 获取数据评审状态
$sql = "SELECT s.*,v.xml,m.title FROM mdstatus s left join mdversion v on s.uuid=v.uuid
left join metadata m on s.uuid=m.uuid WHERE v.id=?";
2012-03-27 10:17:51 +00:00
$sth = $this->db->prepare($sql);
2012-03-29 15:12:37 +00:00
$sth->execute(array($id));
$row = $sth->fetch();
if (empty($row)) //无对应记录
{
$sql="select m.id from metadata m left join mdversion v on m.uuid=v.uuid where v.id=?";
$sth=$this->db->prepare($sql);
$sth->execute(array($id));
$mrow=$sth->fetch();
if (empty($mrow)) //说明是新数据
{
//导入元数据
$iso=new ISO19115();
$iso->saveDB($this->db,$row['xml']);
//进入评审库
$sql="insert into mdstatus (uuid,status,userid) select uuid,0,? from mdversion where id=?";
$this->db->query($sql,array($u_id,$id));
//email to admin
$mail=new WestdcMailer($this->view->config->smtp);
$mail->setFrom($this->view->config->service->email,'西部数据中心服务组');
$mailtp=new EmailText($this->db,"metadata-new-admin",array(
'user' => $user->username,
'uuid' => $iso->uuid,
'email'=> $user->email,
//元数据标题
'title'=> $iso->resTitle,
));
$mail->setBodyText($mailtp->getBody());
$mail->setSubject($mailtp->getSubject());
if($this->debug==0)
{
$mail->addTo($this->view->config->service->email);
}else{
$mail->addTo($this->debug_email);
}
$mail->send();
unset($mail);
unset($mailtp);
//email to author
$mail=new WestdcMailer($this->view->config->smtp);
$mail->setFrom($this->view->config->service->email,'西部数据中心服务组');
$mailtp=new EmailText($this->db,"metadata-new-author",array(
'user' => $user->username,
'uuid' => $iso->uuid,
'email'=> $user->email,
//元数据标题
'title'=> $iso->resTitle,
));
$mail->setBodyText($mailtp->getBody());
$mail->setSubject($mailtp->getSubject());
if($this->debug==0)
{
$mail->addTo($user->email);
$mail->addCc($this->view->config->service->email);
}else{
$mail->addTo($this->debug_email);
}
@$mail->send();
$data = array("commited"=>1,"error"=>$this->alertbox('ok','该版本已经成功提交,请等待数据中心进一步处理!'));
$this->jsonexit($data);
return true;
} else { //说明是已发布的数据
//同步元数据
$iso=new ISO19115();
$iso->saveDB($this->db,$row['xml']);
//移除中间版本
$sql="delete from mdversion where uuid in (select uuid from mdversion where v.id=?) and char_length(changelog)<3";
$this->db->query($sql,array($id));
//修改评审状态为发布
$sql="insert into mdstatus (uuid,status,userid) select uuid,5,? from mdversion where id=?";
$this->db->query($sql,array($u_id,$id));
//email to admin & author
$mail=new WestdcMailer($this->view->config->smtp);
$mail->setFrom($this->view->config->service->email,'西部数据中心服务组');
$mailtp=new EmailText($this->db,"metadata-release",array(
'user' => $user->username,
'uuid' => $row['uuid'],
'email'=> $user->email,
//元数据标题
'title'=> $row['title'],
'changelog'=>$changelog,
));
$mail->setBodyText($mailtp->getBody());
$mail->setSubject($mailtp->getSubject());
if($this->debug==0)
{
$mail->addTo($this->view->config->service->email);
$mail->addCc($this->view->config->service->email);
}else{
$mail->addTo($this->debug_email);
}
@$mail->send();
$data = array("commited"=>1,"error"=>$this->alertbox('ok','该版本已经成功发布!'));
$this->jsonexit($data);
return true;
}
2012-03-29 15:12:37 +00:00
}
else if ($row['id']==-1 || $row['id']==0 || $row['id']==1) //取消发布的数据,初始状态,已接收
2012-03-29 15:12:37 +00:00
{
//同步元数据
$iso=new ISO19115();
$iso->saveDB($this->db,$row['xml']);
//email to admin
$mail=new WestdcMailer($this->view->config->smtp);
$mail->setFrom($this->view->config->service->email,'西部数据中心服务组');
$mailtp=new EmailText($this->db,"version-commit-admin",array(
'user' => $user->username,
'uuid' => $row['uuid'],
'email'=> $user->email,
//元数据标题
'title'=> $row['title'],
'changelog'=>$changelog,
));
$mail->setBodyText($mailtp->getBody());
$mail->setSubject($mailtp->getSubject());
if($this->debug==0)
{
$mail->addTo($this->view->config->service->email);
}else{
$mail->addTo($this->debug_email);
}
$mail->send();
unset($mail);
unset($mailtp);
//email to author
$mail=new WestdcMailer($this->view->config->smtp);
$mail->setFrom($this->view->config->service->email,'西部数据中心服务组');
$mailtp=new EmailText($this->db,"version-commit-author",array(
'user' => $user->username,
'uuid' => $row['uuid'],
'email'=> $user->email,
//元数据标题
'title'=> $row['title'],
));
$mail->setBodyText($mailtp->getBody());
$mail->setSubject($mailtp->getSubject());
if($this->debug==0)
{
$mail->addTo($user->email);
$mail->addCc($this->view->config->service->email);
}else{
$mail->addTo($this->debug_email);
}
@$mail->send();
$data = array("commited"=>1,"error"=>$this->alertbox('ok','该版本已经成功提交并同步,请等待数据中心进一步处理!'));
$this->jsonexit($data);
return true;
2012-03-29 15:12:37 +00:00
}
else if ($row['id']==2 || $row['id']==3 || $row['id']==4)//已发送过外审邮件,需由编辑告知变化信息
2012-03-29 15:12:37 +00:00
{
//email to admin
$mail=new WestdcMailer($this->view->config->smtp);
$mail->setFrom($this->view->config->service->email,'西部数据中心服务组');
$mailtp=new EmailText($this->db,"version-commit-admin",array(
'user' => $user->username,
'uuid' => $row['uuid'],
'email'=> $user->email,
//元数据标题
'title'=> $row['title'],
'changelog'=>$changelog,
));
$mail->setBodyText($mailtp->getBody());
$mail->setSubject($mailtp->getSubject());
if($this->debug==0)
{
$mail->addTo($this->view->config->service->email);
}else{
$mail->addTo($this->debug_email);
}
$mail->send();
unset($mail);
unset($mailtp);
//email to author
$mail=new WestdcMailer($this->view->config->smtp);
$mail->setFrom($this->view->config->service->email,'西部数据中心服务组');
$mailtp=new EmailText($this->db,"version-commit-author",array(
'user' => $user->username,
'uuid' => $row['uuid'],
'email'=> $user->email,
//元数据标题
'title'=> $row['title'],
));
$mail->setBodyText($mailtp->getBody());
$mail->setSubject($mailtp->getSubject());
if($this->debug==0)
{
$mail->addTo($user->email);
$mail->addCc($this->view->config->service->email);
}else{
$mail->addTo($this->debug_email);
}
@$mail->send();
//email to experts, sync to database?
//todo!!!
//should generate new pdf? or user could not commit a new version when it is in the reviewing process?
/*
unset($mail);
unset($mailtp);
$mail=new WestdcMailer($this->view->config->smtp);
$mail->setFrom($this->view->config->service->email,'西部数据中心服务组');
$mailtp=new EmailText($this->db,"version-commit-expert",array(
'user' => $user->username,
'uuid' => $row['uuid'],
'email'=> $user->email,
//元数据标题
'title'=> $row['title'],
));
$mail->setBodyText($mailtp->getBody());
$mail->setSubject($mailtp->getSubject());
if($this->debug==0)
{
$mail->addTo($user->email);
$mail->addCc($this->view->config->service->email);
}else{
$mail->addTo($this->debug_email);
}
@$mail->send();
*/
$data = array("commited"=>1,"error"=>$this->alertbox('ok','该版本已经成功提交,请等待数据中心进一步处理!'));
$this->jsonexit($data);
return true;
2012-03-29 15:12:37 +00:00
}
else if ($row['id']==5)//数据已经发布,再次修改后将只通知管理员,保留发布状态
{
//同步元数据
$iso=new ISO19115();
$iso->saveDB($this->db,$row['xml']);
//移除中间版本
$sql="delete from mdversion where uuid in (select uuid from mdversion where v.id=?) and char_length(changelog)<3";
$this->db->query($sql,array($id));
//email to admin & author
$mail=new WestdcMailer($this->view->config->smtp);
$mail->setFrom($this->view->config->service->email,'西部数据中心服务组');
$mailtp=new EmailText($this->db,"metadata-release",array(
'user' => $user->username,
'uuid' => $row['uuid'],
'email'=> $user->email,
//元数据标题
'title'=> $row['title'],
'changelog'=>$changelog,
));
$mail->setBodyText($mailtp->getBody());
$mail->setSubject($mailtp->getSubject());
if($this->debug==0)
{
$mail->addTo($this->view->config->service->email);
$mail->addCc($this->view->config->service->email);
}else{
$mail->addTo($this->debug_email);
}
@$mail->send();
$data = array("commited"=>1,"error"=>$this->alertbox('ok','该版本已经成功发布!'));
$this->jsonexit($data);
return true;
2012-03-29 15:12:37 +00:00
}
}catch(Exception $e) {
2012-03-27 10:17:51 +00:00
$msg = "提交失败,请确认权限后重试";
if($this->debug>0)
{$msg .= $e->getMessage();}
$data = array("error"=>$this->alertbox('error',$msg));
$this->jsonexit($data);
return true;
}
}//发布到评审
2012-03-27 10:17:51 +00:00
//与前一个版本对比
else if($ac == "diff")
{
$this->_helper->viewRenderer('version-diff');
$id = $this->_request->getParam('id');
if(empty($id) || !is_numeric($id))
{
$this->view->error = "参数错误";
return true;
}
$sql = "SELECT v.uuid,md.title FROM mdversion v
LEFT JOIN mdauthor a ON a.uuid=v.uuid
LEFT JOIN metadata md ON v.uuid=md.uuid
WHERE v.id=? AND a.userid=? AND a.status=1";
$sth = $this->db->prepare($sql);
$sth -> execute(array($id,$u_id));
$row = $sth->fetch();
$sql = "SELECT v.* FROM mdversion v
WHERE v.uuid=? AND v.id<=?
ORDER BY v.ts_created DESC
LIMIT ?";
$sth = $this->db->prepare($sql);
$sth -> execute(array($row['uuid'],$id,2));
$rows = $sth->fetchAll();
if(count($rows)<2)
{
$this->view->error = "对比失败:之前没有版本可以对比";
return true;
}
$this->view->info = $row;
$this->view->data = $rows;
}
}// versionAction() 数据版本管理
//新建元数据
function newdataAction()
{
$ac = $this->_request->getParam('ac');
$id = $this->_request->getParam('id');
$this->wdb=Zend_Db::factory($this->view->config->geonetwork);
$auth = Zend_Auth::getInstance();
if($auth->hasIdentity())
{
$user = $auth->getIdentity();
$u_id = $user->id;
}
//在geonetwork中查看单条数据
if (!empty($id) && empty($ac))
{
$this->view->url='metadata.show?id='.$id;
$this->_helper->viewRenderer('newdata-view');
}
//查看属于自己的所有的未提交数据列表
else if((empty($ac) && empty($uuid))|| $ac=='list')
{
$sql = "SELECT (regexp_matches(gn.data,'<resTitle>(.*)</resTitle>'))[1] as title,gn.id,gn.uuid FROM geonetworkmetadata gn
WHERE gn.uuid not in (select uuid from metadata) and gn.owner=?
order by gn.id desc
";
$sth = $this->db->prepare($sql);
$sth->execute(array($u_id));
$rows = $sth->fetchAll();
$paginator = Zend_Paginator::factory($rows);
$paginator->setCurrentPageNumber($this->_getParam('page'));
$paginator->setItemCountPerPage(15);
$paginator->setView($this->view);
Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination_param.phtml');
$this->view->paginator=$paginator;
}
//元数据导入
else if($ac=="import")
{
$this->_helper->viewRenderer('newdata-import');
}
//从模板新建元数据
else if($ac=="add")
{
$keywords = $this->_request->getParam('q');
if(!empty($keywords))
{
$this->view->q = $keywords;
$sql = "SELECT md.title,md.uuid,md.description,gn.id as gid FROM normalmetadata md
left join geonetworkmetadata gn on md.uuid=gn.uuid
WHERE gn.id is not null";
$search=new Search($keywords);
$where=$search->sql_expr(array("md.title","md.description"));
$sql.=' and '.$where;
$sql.=" order by md.ts_created desc";
$sth = $this->db->prepare($sql);
$sth->execute();
$rows = $sth->fetchAll();
$paginator = Zend_Paginator::factory($rows);
$paginator->setCurrentPageNumber($this->_getParam('page'));
$paginator->setItemCountPerPage(10);
$paginator->setView($this->view);
Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination_param.phtml');
$this->view->paginator=$paginator;
}
2012-04-02 15:35:16 +00:00
$sql="select id,(regexp_matches(data,'<resTitle>(.*)</resTitle>'))[1] as title from metadata where istemplate='y' and schemaid='iso19115'";
$sth=$this->wdb->prepare($sql);
$sth->execute();
$this->view->templates=$sth->fetchAll();
$this->_helper->viewRenderer('newdata-add');
}
}
//文献管理
function literatureAction()
{
$ac = $this->_request->getParam('ac');
$uuid = $this->_request->getParam('uuid');
$id = $this->_request->getParam('id');
$auth = Zend_Auth::getInstance();
if($auth->hasIdentity())
{
$user = $auth->getIdentity();
$u_id = $user->id;
}
//查看单条数据的所有文献
if (!empty($uuid) && empty($ac))
{
$sql = "SELECT md.title,md.uuid,r.id,r.reference,r.link FROM mdref mr
LEFT JOIN metadata md ON md.uuid=mr.uuid
LEFT JOIN mdauthor a ON md.uuid=a.uuid
left join reference r on mr.refid=r.id
WHERE md.title IS NOT NULL AND a.userid=? and mr.uuid=? AND a.status=1
order by md.ts_created desc
";
$sth = $this->db->prepare($sql);
$sth->execute(array($u_id,$uuid));
$rows = $sth->fetchAll();
@$this->view->mdtitle=$rows[0]['title'];
$paginator = Zend_Paginator::factory($rows);
$paginator->setCurrentPageNumber($this->_getParam('page'));
$paginator->setItemCountPerPage(15);
$paginator->setView($this->view);
Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination_param.phtml');
$this->view->paginator=$paginator;
$this->_helper->viewRenderer('literature-viewdata');
}
//查看单条文献的所有数据
if (!empty($id) && empty($ac))
{
$sql = "SELECT md.title,md.uuid,r.id,r.reference,r.link,(a.userid-?) as isauthor FROM mdref mr
LEFT JOIN metadata md ON md.uuid=mr.uuid
LEFT JOIN mdauthor a ON md.uuid=a.uuid
left join reference r on mr.refid=r.id
WHERE md.title IS NOT NULL AND mr.refid=? AND a.status=1
order by md.ts_created desc
";
$sth = $this->db->prepare($sql);
$sth->execute(array($u_id,$id));
$rows = $sth->fetchAll();
@$this->view->mdtitle=$rows[0]['reference'];
$paginator = Zend_Paginator::factory($rows);
$paginator->setCurrentPageNumber($this->_getParam('page'));
$paginator->setItemCountPerPage(15);
$paginator->setView($this->view);
Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination_param.phtml');
$this->view->paginator=$paginator;
$this->_helper->viewRenderer('literature-viewliter');
}
//查看所有文献列表
else if((empty($ac) && empty($uuid)) && empty($id))
{
$keywords = $this->_request->getParam('q');
$sql = "SELECT md.title,md.uuid,r.reference,r.id,mr.id as mrid FROM mdref mr
LEFT JOIN metadata md ON md.uuid=mr.uuid
LEFT JOIN mdauthor a ON md.uuid=a.uuid
left join reference r on mr.refid=r.id
WHERE md.title IS NOT NULL AND a.userid=? AND a.status=1";
if(!empty($keywords))
$this->view->q = $keywords;
if(!empty($keywords))
{
$search=new Search($keywords);
$where=$search->sql_expr(array("r.reference","md.title","md.description"));
$sql.=' and '.$where;
}
$sql.=" order by md.ts_created desc";
$sth = $this->db->prepare($sql);
$sth->execute(array($u_id));
$rows = $sth->fetchAll();
$paginator = Zend_Paginator::factory($rows);
$paginator->setCurrentPageNumber($this->_getParam('page'));
$paginator->setItemCountPerPage(15);
$paginator->setView($this->view);
Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination_param.phtml');
$this->view->paginator=$paginator;
}
//按文献浏览
else if($ac=="byliter")
{
$keywords = $this->_request->getParam('q');
if(!empty($keywords))
$this->view->q = $keywords;
$sql = "SELECT count(md.uuid) as c,r.reference,r.id FROM reference r
left join mdref mr on r.id=mr.refid
LEFT JOIN metadata md ON md.uuid=mr.uuid
LEFT JOIN mdauthor a ON md.uuid=a.uuid
WHERE md.title IS NOT NULL AND a.userid=? AND a.status=1";
if(!empty($keywords))
{
$search=new Search($keywords);
$where=$search->sql_expr(array("r.reference"));
$sql.=' and '.$where;
}
$sql.=" group by r.reference,r.id";
$sth = $this->db->prepare($sql);
$sth->execute(array($u_id));
$rows = $sth->fetchAll();
$paginator = Zend_Paginator::factory($rows);
$paginator->setCurrentPageNumber($this->_getParam('page'));
$paginator->setItemCountPerPage(10);
$paginator->setView($this->view);
Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination_param.phtml');
$this->view->paginator=$paginator;
$this->_helper->viewRenderer('literature-byliter');
}
//按数据浏览
else if($ac=="bydata")
{
$keywords = $this->_request->getParam('q');
if(!empty($keywords))
$this->view->q = $keywords;
$sql = "SELECT md.title,md.uuid,count(mr.id) as c FROM metadata md
LEFT JOIN mdref mr ON md.uuid=mr.uuid
LEFT JOIN mdauthor a ON md.uuid=a.uuid
left join reference r on mr.refid=r.id
WHERE md.title IS NOT NULL AND a.userid=? AND a.status=1";
if(!empty($keywords))
{
$search=new Search($keywords);
$where=$search->sql_expr(array("md.title","md.description"));
$sql.=' and '.$where;
}
$sql.=" group by md.uuid,md.title";
$sth = $this->db->prepare($sql);
$sth->execute(array($u_id));
$rows = $sth->fetchAll();
$paginator = Zend_Paginator::factory($rows);
$paginator->setCurrentPageNumber($this->_getParam('page'));
$paginator->setItemCountPerPage(10);
$paginator->setView($this->view);
Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination_param.phtml');
$this->view->paginator=$paginator;
$this->_helper->viewRenderer('literature-bydata');
}
//添加文献信息
else if($ac == "add")
{
$this->_helper->layout->disableLayout();
$this->_helper->viewRenderer->setNoRender();
$data = "";
try{
$uuid = $this->_request->getParam('uuid');
$ref=$this->_request->getParam('ref');
$reftype=$this->_request->getParam('reftype');
if(empty($uuid) || empty($ref) || !is_numeric($reftype))
{
$data = array("error"=>"参数错误");
$this->jsonexit($data);
return true;
}
$sql="select * from mdauthor where userid=? and uuid=? and status=1";
$sth = $this->db->prepare($sql);
$sth->execute(array($u_id,$uuid));
$row = $sth->fetch();
if (empty($row))
{
$data = array("error"=>$this->alertbox('warning','您不是该数据作者,无法添加对应文献信息。'));
$this->jsonexit($data);
return true;
}
$sql="select id from reference where reference=?";
$sth = $this->db->prepare($sql);
$sth->execute(array($ref));
$row = $sth->fetch();
if (!$row)
{
$sql="insert into reference (reference,link) values(?,?)";
$sth = $this->db->prepare($sql);
$sth->execute(array(trim($ref),''));
$sql="select id from reference where reference=?";
$sth = $this->db->prepare($sql);
$sth->execute(array(trim($ref)));
$row = $sth->fetch();
}
$sql="insert into mdref (uuid,refid,reftype) values(?,?,?)";
$sth = $this->db->prepare($sql);
$ex=$sth->execute(array($uuid,$row['id'],$reftype));
if($ex)
{
$data = array("commited"=>1,"error"=>$this->alertbox('ok','成功添加文献!'));
$this->jsonexit($data);
return true;
}else{
$data = array("error"=>$this->alertbox('error','提交失败,请确认权限后重试'));
$this->jsonexit($data);
return true;
}
}catch(Exception $e) {
$msg = "提交失败,请确认权限后重试";
if($this->debug>0)
{$msg .= $e->getMessage();}
$data = array("error"=>$this->alertbox('error',$msg));
$this->jsonexit($data);
return true;
}
}//添加文献
//删除某个文献
else if($ac=="delete")
{
$this->_helper->layout->disableLayout();
$this->_helper->viewRenderer->setNoRender();
$data = "";
$id = $this->_request->getParam('id');
$uuid = $this->_request->getParam('uuid');
if(empty($uuid) || !is_numeric($id))
{
$data = array("error"=>"参数错误");
$this->jsonexit($data);
return true;
}
try{
$sql = "DELETE FROM mdref r
USING mdauthor a
WHERE r.uuid=a.uuid and r.refid=? and r.uuid=? AND a.userid=? AND a.status=1";
$sth = $this->db->prepare($sql);
$ex = $sth -> execute(array($id,$uuid,$u_id));
if($ex)
{
$data = array("deleted"=>$id.$uuid,"error"=>$this->alertbox('ok','删除成功'));
$this->jsonexit($data);
return true;
}else{
$data = array("error"=>$this->alertbox('error','删除失败,请确认权限后重试'));
$this->jsonexit($data);
return true;
}
}catch(Exception $e) {
$msg = "删除失败,请确认权限后重试";
if($this->debug>0)
{$msg .= $e->getMessage();}
$data = array("error"=>$this->alertbox('error',$msg));
$this->jsonexit($data);
return true;
}
}
}
2012-03-27 10:17:51 +00:00
//成为作者后的后继处理工作
private function author_first($uuid,$author)
{
$sql="insert into mdversion (xml,ts_created,uuid,changelog,userid)
select x.data,m.ts_created,?,?,? from metadata m left join xml x on m.id=x.id
left join mdversion v on m.uuid=v.uuid
where m.uuid=? and v.changelog is null";
$sth=$this->db->prepare($sql);
try
{
$sth->execute(array($uuid,'初始版本 version 1.0',$author,$uuid));
} catch(Exception $e){
// do nothing here.
// 说明之前已经有对应数据
}
$this->wdb=Zend_Db::factory($this->view->config->geonetwork);
$sql="update metadata set owner=? where uuid=?";
$sth=$this->wdb->prepare($sql);
$sth->execute(array($author,$uuid));
}
2012-03-27 10:17:51 +00:00
/*
* jsonexit() 退出并返回json数据
*
* param array $data 要返回的JSON数据可以是任意数组
*
* return JSON-response
*/
public function jsonexit($data){
$this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(Zend_Json::encode($data));
return true;
}//jsonexit() 退出并返回json数据
//ajax 提示框
2012-03-27 10:17:51 +00:00
public function alertbox($type='',$body){
if($type == "error")
{
$img = '<img src="/images/alert_big_error.png" />';
$text = '<h4>'.$body.'</h4>';
return $img.$text;
}
if($type == "ok")
{
$img = '<img src="/images/alert_big_ok.png" />';
$text = '<h4>'.$body.'</h4>';
return $img.$text;
}
if($type == "warning")
{
$img = '<img src="/images/alert_big_warning.png" />';
$text = '<h4>'.$body.'</h4>';
return $img.$text;
}
if(empty($type))
{
$text = '<h4>'.$body.'</h4>';
return $text;
}
}
2012-02-22 12:21:22 +00:00
}