Ticket #301 增加了用户申请成为元数据作者的功能,增加了申请页面视图

This commit is contained in:
Li Jianxuan 2012-03-06 08:06:54 +00:00
parent eb793d82a1
commit 0d25c86523
2 changed files with 459 additions and 0 deletions

View File

@ -1,4 +1,15 @@
<?php <?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 李建轩
*/
class AuthorController extends Zend_Controller_Action class AuthorController extends Zend_Controller_Action
{ {
private $limit=10; private $limit=10;
@ -18,5 +29,364 @@ class AuthorController extends Zend_Controller_Action
{ {
} }
/*
* acceptAction() 我的数据
*
*
*
*
*/
function acceptAction()
{
$auth = Zend_Auth::getInstance();
if($auth->hasIdentity())
{
$user = $auth->getIdentity();
$u_id = $user->id;
}
$sql = "SELECT a.* FROM mdauthor a
LEFT JOIN metadata m ON m.uuid=a.uuid";
}//acceptAction() 我的数据
/*
* 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));
exit();
}
//数据处理代码 EOH<<<<<<<<<<<<<<<<
try{
$keyword = trim($this->_request->getParam('q'));
if (!preg_match_all("/^[\x{4e00}-\x{9fa5}A-Za-z0-9_]+$/u",$keyword,$matchs))
{
$data = array('error'=>'搜索关键字中只能包含汉字、英文、数字');
}
else
{
//搜索标题和描述两个字段
$sql = "SELECT m.uuid,m.title,m.description,a.status,a.userid FROM metadata m
LEFT JOIN mdauthor a ON m.uuid=a.uuid
WHERE m.title like ? OR m.description like ?";
$sth = $this->db->prepare($sql);
$sth->execute(array("%$keyword%","%$keyword%"));
$rows = $sth->fetchAll();
if(is_array($rows) && count($rows)>0)
$data = $rows;
else
$data = "";
}
}catch(Exception $e){
//如果上面的程序已经发送出提示,就不发送抛出的错误
if(empty($data['error']))
{
//产品模式
$data = array("error"=>"处理过程中遇到错误,请重新尝试");
//调试模式
//$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']))
{
//如果已经是元数据作者,从流程中直接退出程序
if($row['status']==1)
{
$data = array("error"=>"您目前已经是该数据作者,不需要再申请");
}
//如果已经存在申请,但是没有激活的,返回激活信息
else{
$data = array(
"error"=>'您已经申请过了,请在<我的数据>中进行激活操作',
"post"=>"activa",
"uid"=>$u_id,
"uemail"=>$u_email,
"uuid"=>$uuid,
);
}
}
else{
//获得元数据作者email
$sql="select p.email,md.title from role r
left join responsible p on r.resid=p.id
left join metadata md on md.uuid=r.uuid
where r.uuid=? order by r.role,r.id";
$sth = $this->db->prepare($sql);
$sth->execute(array($uuid));
$rows = $sth->fetchAll();
$address = array();
foreach($rows as $v)
{
$address[] = $v['email'];
}
$mdtitle = $rows[0]['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)
{
$data = array("error"=>"您的身份符合申请条件,已经自动成为该元数据作者");
include_once("EmailText.php");
$mail=new WestdcMailer($this->view->config->smtp);
$mail->setFrom($this->view->config->service->email,'西部数据中心服务组');
$mailtp=new EmailText($this->db,"md-author-newmember",array(
'user' => $user->realname,
'uuid' => $uuid,
'title'=> $mdtitle,
'email'=> $u_email,
));
$mail->setBodyText($mailtp->getBody());
$mail->setSubject($mailtp->getSubject());
/*
mail=>元数据有新作者加入
id=>md-author-newmember
body=>
您好:
  {user} ({email}) 已经申请成为元数据《{title}》的作者,如果有疑问请联系该作者或者数据中心服务组
                    中国西部环境与生态科学数据中心
*/
/*
foreach ($address as $dist)
{$mail->addTo($dist);} //元数据作者
$mail->addTo($u_email);
$mail->addCc($this->view->config->service->email); //管理员
*/
$mail->addTo("la5c@qq.com");
$mail->send();
}
else
{
$data = array("error"=>"处理中出现错误,请重新尝试");
}
}
//如果不包含在当前元数据作者的email列表中
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)
{
//给新申请的用户发送邮件
include_once("EmailText.php");
@$mail=new WestdcMailer($this->view->config->smtp);
@$mail->setFrom($this->view->config->service->email,'西部数据中心服务组');
@$mailtp=new EmailText($this->db,"md-author-applynew",array(
'user' => $user->username,
'uuid' => $uuid,
'title'=> $mdtitle,
'vdcode' => $vdcode,
'link'=>"http://".$_SERVER['SERVER_NAME']."/author/accept/?ac=active&v=$vdcode",
));
@$mail->setBodyText($mailtp->getBody());
@$mail->setSubject($mailtp->getSubject());
/*
mail=>元数据作者激活邮件
id=>md-author-applynew
body=>
您好,{user}:
  您申请成为元数据《{title}》的作者,这需要您首先激活您的作者身份,请访问以下链接进行激活:
  {link}
  此链接有效期为3天请在3天时间内激活
                      中国西部环境与生态科学数据中心
*/
//@$mail->addTo($u_email);
@$mail->addTo("la5c@qq.com"); //Test line...
@$mail->send();
unset($mail);
unset($mailtp);
//给原来的元数据作者以及管理员发送邮件
@$mail=new WestdcMailer($this->view->config->smtp);
@$mail->setFrom($this->view->config->service->email,'西部数据中心服务组');
@$mailtp=new EmailText($this->db,"md-author-apply-confirm",array(
'user' => $user->username,
'uuid' => $uuid,
'email'=> $u_email,
'title'=> $mdtitle,
'link'=>"http://".$_SERVER['SERVER_NAME']."/data/$uuid",
));
@$mail->setBodyText($mailtp->getBody());
@$mail->setSubject($mailtp->getSubject());
/*
mail=>元数据作者激活
id=>md-author-apply-confirm
body=>
您好:
  元数据《{title}》有新用户 {user} (Email:{email})申请成为作者,如果有疑问请联系该用户或者数据中心服务组.
元数据访问地址:{link}
                    中国西部环境与生态科学数据中心 
*/
/*
foreach ($address as $dist)
{$mail->addTo($dist);} //元数据作者
$mail->addCc($this->view->config->service->email); //管理员
*/
@$mail->addTo("la5c@qq.com");
@$mail->send();
$data = array("error"=>"我们给您的邮箱中发送了激活链接,请按邮件提示进行激活操作。");
}else{
$data = array("error"=>"服务器可能在忙,请重试。");
}//激活码记录
}//不是确认的元数据作者
}//empty($row['id'])
//调试输出结果
//$data = array('addr'=>$address,'uemail'=>$u_email);
}
else
{
$data = array('error'=>'参数出错,请按照正确的访问方式申请');
}
}catch(Exception $e){
if(empty($data['error']))
{
//产品模式
$data = array("error"=>"处理过程中遇到错误,请重新尝试");
//调试模式
//$data = array("error"=>$e->getMessage());
}
}
// >>>>>>>>>>>>
$this ->getResponse()
->setHeader('Content-Type', 'application/json')
->appendBody(Zend_Json::encode($data));
}// ac = apply 申请处理
}//applyAction() 申请成为元数据作者
} }

View File

@ -0,0 +1,89 @@
<?php
$this->headTitle($this->config->title->site);
$this->headTitle($this->config->title->author);
$this->headTitle()->setSeparator(' - ');
$this->headScript()->appendFile('/js/jquery-1.7.min.js');
$this->headLink()->appendStylesheet('/css/author.css');
$this->breadcrumb('<a href="/">首页</a>');
$this->breadcrumb('<a href="/author">数据作者</a>');
$this->breadcrumb('申请成为元数据作者');
$this->breadcrumb()->setSeparator(' > ');
?>
<!-- 左侧导航 -->
<div id='sidebar'>
<div id='leftnavi'>
<?= $this->partial('author/navi.phtml'); ?>
</div>
</div>
<!-- //左侧导航 -->
<!-- 页面内容 -->
<div id="wapper">
<p>请输入元数据标题关键字进行搜索</p>
<form id="datasearch" class="search_form">
<input type="text" id="keyword" name="keyword" />
<button type="button" class="btn" id="search_btn" onclick="doSearch()">搜索</button>
</form>
<div id="datalist">
</div>
</div>
<!-- //页面内容 -->
<script>
$('#wapper').width($('body').width()-300);
function doSearch(){
$.ajax({
'type':"POST",
'url':'/author/apply',
'data':'ac=search&q='+$('#keyword').val(),
'success':function(data){
if (isObject(data))
{
if(typeof(data.error)!='undefined')
{
alert(data.error);
}else{
var result = new Array();
for(i=0;i<data.length;i++)
{
if(data[i].status==1) var ct='<img src="/images/list_links.gif" />您是此元数据的作者';
else if (data[i].status==0) var ct='<img src="/images/list_extensions.gif" />您已经申请成为该元数据作者,请前往 <a href="/author/accept">我的数据</a> 查看<span id="data_'+data[i].uuid+'"></span>';
else var ct='<a href="javascript:;" onclick="apply(\'' +data[i].uuid+ '\')"><img src="/images/list_keys.gif" />申请成为此数据的作者</a><span id="data_'+data[i].uuid+'"></span>';
result.push('<li><a href="/data/'+data[i].uuid+'" target="_blank">'+data[i].title+'</a><p>'+data[i].description+'</p><p>'+ct+'</p></li>');
}
$('#datalist').html('<ul id="datas">'+result.join('')+'</ul>');
}
}else{
alert('无搜索结果');
}
$('#search_btn').html('搜索');
},
'beforeSend':function(){
$('#search_btn').html('<img src="/images/ajax-load-small.gif" />Searching...');
}
});
}
function apply(uuid){
$.ajax({
'type':"POST",
'url':'/author/apply',
'data':'ac=apply&uuid='+uuid,
'success':function(data){
if (isObject(data))
{
if(typeof(data.error)!='undefined')
{alert(data.error);}
else{
alert(data.error);
}
}
else{ alert('出现错误,请稍候');}
$('#data_'+uuid).html('');
},
'beforeSend':function(){
$('#data_'+uuid).html('<img src="/images/ajax-load-small.gif" />正在处理...');
}
});
}
function isObject(obj){if(typeof(obj)=='object'){return true;}else if(typeof(obj)!='object'){return false;}else{return false;}}
</script>