diff --git a/application/default/controllers/AuthorController.php b/application/default/controllers/AuthorController.php
index 86611a5a..9b20bc91 100644
--- a/application/default/controllers/AuthorController.php
+++ b/application/default/controllers/AuthorController.php
@@ -375,10 +375,11 @@ class AuthorController extends Zend_Controller_Action
//列表
if(empty($ac) || $ac=='list' || $ac=='search'){
- $sql = "SELECT a.*,m.title,m.description,g.id as gid FROM normalmetadata m
+ $sql = "SELECT a.*,m.title,m.description,g.id as gid,mds.status as mdstatus FROM normalmetadata m
LEFT JOIN mdauthor a ON m.uuid=a.uuid
- left join geonetworkmetadata g on m.uuid=g.uuid
- WHERE a.userid=? AND status>=0";
+ LEFT JOIN geonetworkmetadata g on m.uuid=g.uuid
+ LEFT JOIN mdstatus mds ON m.uuid=mds.uuid
+ WHERE a.userid=? AND a.status>=0";
if ($ac=='search')
{
$key = trim($this->_request->getParam('q'));
@@ -387,7 +388,7 @@ class AuthorController extends Zend_Controller_Action
$where=$search->sql_expr(array("m.title","m.description"));
$sql.=' and '.$where;
}
- $sql.="ORDER BY status DESC,a.id DESC";
+ $sql.="ORDER BY a.status DESC,a.id DESC";
$sth = $this->db->prepare($sql);
$sth->execute(array($u_id));
@@ -1468,6 +1469,11 @@ class AuthorController extends Zend_Controller_Action
}
}
+ /*
+ * versionAction() 版本控制
+ *
+ *
+ */
function versionAction()
{
$ac = $this->_request->getParam('ac');
@@ -1617,8 +1623,8 @@ class AuthorController extends Zend_Controller_Action
$data = array("error"=>"参数错误");
$this->jsonexit($data);
return true;
- }
-
+ }
+
$this->wdb=Zend_Db::factory($this->view->config->geonetwork);
$sql = "SELECT v.xml,v.uuid FROM mdversion v
LEFT JOIN mdauthor a ON a.uuid=v.uuid
@@ -1634,7 +1640,7 @@ class AuthorController extends Zend_Controller_Action
if($row['xml']==$row_geo['data'])
{
- $data = array("error"=>$this->alertbox('warning','无须恢复,元数据相同'));
+ $data = array("error"=>$this->alertbox('warning','无须恢复,元数据相同'));
$this->jsonexit($data);
return true;
}
@@ -1677,301 +1683,301 @@ class AuthorController extends Zend_Controller_Action
$data = array("error"=>"参数错误");
$this->jsonexit($data);
return true;
- }
-
+ }
+
$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))
- {
+ }
+
+ // 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));
-
+ return true;
+ }
+ // 2. 保存变化记录 save changelog & userid
+ $sql = "UPDATE mdversion SET changelog=?,userid=? WHERE id=?";
+ $this->db->query($sql,array($changelog,$u_id,$id));
+
// 3. 获取数据评审状态
- $sql = "SELECT s.*,v.xml,m.title FROM mdstatus s left join mdversion v on s.uuid=v.uuid
+ $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=?";
$sth = $this->db->prepare($sql);
$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,6,? 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;
- }
- }
- else if ($row['id']==-1 || $row['id']==0 || $row['id']==1) //取消发布的数据,初始状态,已接收
- {
- //同步元数据
- $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;
- }
- else if ($row['id']==2 || $row['id']==3 || $row['id']==4)//已发送过外审邮件,需由编辑告知变化信息
- {
- //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;
- }
- 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;
+ $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,6,? 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;
+ }
+ }
+ else if ($row['id']==-1 || $row['id']==0 || $row['id']==1) //取消发布的数据,初始状态,已接收
+ {
+ //同步元数据
+ $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;
+ }
+ else if ($row['id']==2 || $row['id']==3 || $row['id']==4)//已发送过外审邮件,需由编辑告知变化信息
+ {
+ //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;
+ }
+ 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;
}
}catch(Exception $e) {
$msg = "提交失败,请确认权限后重试";
@@ -2024,13 +2030,13 @@ class AuthorController extends Zend_Controller_Action
}
- }// versionAction() 数据版本管理
-
- //新建元数据
- function newdataAction()
- {
+ }// versionAction() 数据版本管理
+
+ //新建元数据
+ function newdataAction()
+ {
$ac = $this->_request->getParam('ac');
- $id = $this->_request->getParam('id');
+ $id = $this->_request->getParam('id');
$this->wdb=Zend_Db::factory($this->view->config->geonetwork);
$auth = Zend_Auth::getInstance();
@@ -2042,10 +2048,10 @@ class AuthorController extends Zend_Controller_Action
//在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')
{
@@ -2064,190 +2070,191 @@ class AuthorController extends Zend_Controller_Action
$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-by-template")
- {
- $keywords = $this->_request->getParam('q');
- $sql="select id,(regexp_matches(data,'(.*)'))[1] as title,(owner-$u_id) as isowner from metadata where istemplate='y' and schemaid='iso19115'";
- if(!empty($keywords))
- {
- $this->view->q = $keywords;
- $search=new Search($keywords);
- $where=$search->sql_expr(array("data"));
- $sql.=' and '.$where;
- }
- $sql.=" order by changedate desc";
- $sth = $this->wdb->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;
+ {
+ $keywords = $this->_request->getParam('q');
+ $sql="select id,(regexp_matches(data,'(.*)'))[1] as title,(owner-$u_id) as isowner from metadata where istemplate='y' and schemaid='iso19115'";
+ if(!empty($keywords))
+ {
+ $this->view->q = $keywords;
+ $search=new Search($keywords);
+ $where=$search->sql_expr(array("data"));
+ $sql.=' and '.$where;
+ }
+ $sql.=" order by changedate desc";
+ $sth = $this->wdb->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;
$this->_helper->viewRenderer('newdata-add');
- }
-
- else if($ac=="add-by-data")
- {
- $keywords = $this->_request->getParam('q');
- $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";
- if(!empty($keywords))
- {
- $this->view->q = $keywords;
- $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;
- $this->_helper->viewRenderer('newdata-add-bydata');
- }
- //提交数据
- 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);
- return true;
- }
-
- $changelog = $this->_request->getParam('changelog');
- if(empty($changelog))
- {
- $data = array("error"=>$this->alertbox('warning','请输入变更信息'));
- $this->jsonexit($data);
- return true;
- }
-
- // 1. 权限认定:当前用户必须和其owner相同
- // 数据应当没有评审状态,没有作者信息
- $sql="select gn.id from geonetworkmetadata gn
- left join mdstatus s on gn.uuid=s.uuid
- left join mdauthor a on s.uuid=a.uuid
- where s.id is not null and a.id is not null and gn.id=?";
- $sth=$this->db->prepare($sql);
- $sth->execute(array($id));
- $row=$sth->fetch();
- if (!emtpy($row))
- {
- $data = array("error"=>'错误的入口');
- $this->jsonexit($data);
- return true;
- }
-
- $sql="select uuid from metadata where id=? and owner=?";
- $sth=$this->wdb->prepare($sql);
- $sth->execute(array($id,$u_id));
- $row=$sth->fetch();
- if (empty($row))
- {
- $data = array("error"=>'无权限修改数据');
- $this->jsonexit($data);
- return true;
- }
- // 保存数据作者信息
- $sql="insert into mdauthor (uuid,userid,ts_activated,status) values(?,?,now(),1)";
- $sth=$this->db->query($sql,array($row['uuid'],$u_id));
-
- // 2. 保存变化记录 save changelog & userid for the latest version
- $sql = "UPDATE mdversion SET changelog=?,userid=? WHERE id in (select id from mdversion where uuid=? order by ts_created desc limit 1)";
- $this->db->query($sql,array($changelog,$u_id,$row['uuid']));
-
- // 3. 保存数据评审状态
- //导入元数据
- $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;
- }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=="add-by-data")
+ {
+ $keywords = $this->_request->getParam('q');
+ $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";
+ if(!empty($keywords))
+ {
+ $this->view->q = $keywords;
+ $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;
+ $this->_helper->viewRenderer('newdata-add-bydata');
+ }
+ //提交数据
+ 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);
+ return true;
+ }
+
+ $changelog = $this->_request->getParam('changelog');
+ if(empty($changelog))
+ {
+ $data = array("error"=>$this->alertbox('warning','请输入变更信息'));
+ $this->jsonexit($data);
+ return true;
+ }
+
+ // 1. 权限认定:当前用户必须和其owner相同
+ // 数据应当没有评审状态,没有作者信息
+ $sql="select gn.id from geonetworkmetadata gn
+ left join mdstatus s on gn.uuid=s.uuid
+ left join mdauthor a on s.uuid=a.uuid
+ where s.id is not null and a.id is not null and gn.id=?";
+ $sth=$this->db->prepare($sql);
+ $sth->execute(array($id));
+ $row=$sth->fetch();
+ if (!emtpy($row))
+ {
+ $data = array("error"=>'错误的入口');
+ $this->jsonexit($data);
+ return true;
+ }
+
+ $sql="select uuid from metadata where id=? and owner=?";
+ $sth=$this->wdb->prepare($sql);
+ $sth->execute(array($id,$u_id));
+ $row=$sth->fetch();
+ if (empty($row))
+ {
+ $data = array("error"=>'无权限修改数据');
+ $this->jsonexit($data);
+ return true;
+ }
+ // 保存数据作者信息
+ $sql="insert into mdauthor (uuid,userid,ts_activated,status) values(?,?,now(),1)";
+ $sth=$this->db->query($sql,array($row['uuid'],$u_id));
+
+ // 2. 保存变化记录 save changelog & userid for the latest version
+ $sql = "UPDATE mdversion SET changelog=?,userid=? WHERE id in (select id from mdversion where uuid=? order by ts_created desc limit 1)";
+ $this->db->query($sql,array($changelog,$u_id,$row['uuid']));
+
+ // 3. 保存数据评审状态
+ //导入元数据
+ $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;
+ }catch(Exception $e) {
+ $msg = "提交失败,请确认权限后重试";
+ if($this->debug>0)
+ {$msg .= $e->getMessage();}
+ $data = array("error"=>$this->alertbox('error',$msg));
+ $this->jsonexit($data);
+ return true;
+ }
+ }
}
-
+ //新建元数据
+
//文献管理
- function literatureAction()
- {
+ function literatureAction()
+ {
$ac = $this->_request->getParam('ac');
$uuid = $this->_request->getParam('uuid');
$id = $this->_request->getParam('id');
@@ -2282,7 +2289,7 @@ class AuthorController extends Zend_Controller_Action
$this->view->paginator=$paginator;
$this->_helper->viewRenderer('literature-viewdata');
}
-
+
//查看单条文献的所有数据
if (!empty($id) && empty($ac))
{
@@ -2305,7 +2312,7 @@ class AuthorController extends Zend_Controller_Action
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))
@@ -2347,7 +2354,7 @@ class AuthorController extends Zend_Controller_Action
$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
+ 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))
@@ -2380,7 +2387,7 @@ class AuthorController extends Zend_Controller_Action
$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 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))
@@ -2403,9 +2410,9 @@ class AuthorController extends Zend_Controller_Action
$this->view->paginator=$paginator;
$this->_helper->viewRenderer('literature-bydata');
- }
-
- //添加文献信息
+ }
+
+ //添加文献信息
else if($ac == "add")
{
$this->_helper->layout->disableLayout();
@@ -2413,43 +2420,43 @@ class AuthorController extends Zend_Controller_Action
$data = "";
try{
- $uuid = $this->_request->getParam('uuid');
- $ref=$this->_request->getParam('ref');
+ $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";
+ }
+
+ $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))
+ if (empty($row))
{
$data = array("error"=>$this->alertbox('warning','您不是该数据作者,无法添加对应文献信息。'));
$this->jsonexit($data);
return true;
}
-
- $sql="select id from reference where reference=?";
+
+ $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);
+ $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)));
+ $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);
+ $sql="insert into mdref (uuid,refid,reftype) values(?,?,?)";
+ $sth = $this->db->prepare($sql);
$ex=$sth->execute(array($uuid,$row['id'],$reftype));
if($ex)
@@ -2470,8 +2477,8 @@ class AuthorController extends Zend_Controller_Action
$this->jsonexit($data);
return true;
}
- }//添加文献
-
+ }//添加文献
+
//删除某个文献
else if($ac=="delete")
{
@@ -2480,7 +2487,7 @@ class AuthorController extends Zend_Controller_Action
$data = "";
- $id = $this->_request->getParam('id');
+ $id = $this->_request->getParam('id');
$uuid = $this->_request->getParam('uuid');
if(empty($uuid) || !is_numeric($id))
{
@@ -2513,253 +2520,367 @@ class AuthorController extends Zend_Controller_Action
$this->jsonexit($data);
return true;
}
- }
+ }
}
-
- //文档管理
- function documentAction(){
-
- $ac = $this->_request->getParam('ac');
-
- $auth = Zend_Auth::getInstance();
- if($auth->hasIdentity())
- {
- $user = $auth->getIdentity();
- $u_id = $user->id;
- }
-
- if(empty($ac) || $ac == 'list' || $ac=='search')
- {
-
- $wheresql = "";
-
- $keyword = $this->_request->getParam('q');
-
- if($ac=='search' && !empty($keyword))
- {
- $this->view->q = $keyword;
- $search = new Search($keyword);
- $wheresql = $search->sql_expr(array("md.title"));
- }
- if(!empty($wheresql))
- {
- $wheresql = " AND ".$wheresql;
- }
-
-
- $sql = "select count(att.id) as aid,md.title,md.uuid from metadata md
- LEFT JOIN mdauthor a ON a.uuid=md.uuid
- LEFT JOIN mdattach att ON att.uuid=md.uuid
- WHERE a.status>=1 AND a.userid=? $wheresql
- 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(10);
- $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(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))
- {
- $this->view->error = "参数有误!";
- return true;
- }
-
- $sql = "SELECT att.*,md.title,md.uuid FROM mdattach mda
- LEFT JOIN attachments att ON mda.id=att.id
- LEFT JOIN metadata md ON mda.uuid=md.uuid
- LEFT JOIN users u ON att.userid=u.id";
-
- $sth = $this->db->prepare($sql);
- $sth->execute(array());
- $rows = $sth->fetchAll();
-
- $this->view->info=$rows;
-
- $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('document-view');
- }
-
- if($ac == 'del')
- {
-
- $this->_helper->layout()->disableLayout();
- $this->_helper->viewRenderer->setNoRender();
-
- (int)$id = $this->_request->getParam('id');
- $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))
- {
- exit();
- }
-
- $info = $this->getFileinfo($id);
- $filepath = $dataFilePath.$info['filename'];
- try{
- $auth = Zend_Auth::getInstance();
- if($auth->hasIdentity())
- {
- $user = $auth->getIdentity();
- $userid = $user->id;
- $sql_mdattach = "delete from mdattach where uuid='$uuid' and id='$id'";
- $sql = "delete from attachments where id='$id' and userid='$userid'";
- if($this->db->exec($sql_mdattach)>0 && $this->db->exec($sql)>0)
- {
- @unlink($filepath);
- echo "ok";
- }
- }
-
- }catch(Exception $e){}
- //不输出任何错误
-
- }//删除
-
- if($ac=='upload')
- {
- $submit = $this->_request->getParam('submit');
- if(empty($submit))
- {
- $uuid = $this->_request->getParam('uuid');
- $this->view->uuid=$uuid;
- $this->_helper->layout->disableLayout();
- $this->_helper->viewRenderer('document-upload');
- return true;
- }
- else
- {
- $this->_helper->layout()->disableLayout();
- $this->_helper->viewRenderer->setNoRender();
-
- $uuid = $this->_getParam('uuid');
-
- try{
-
- $files=new files();
- $msg = $files -> upload($this->view->config->upload,$_FILES['Filedata'],'md');
-
- if(empty($msg['error']))
- {
- $msg['error']="";
- $filename = $msg['db_path'];
- $filesize = $msg['file_size'];
- $filedesc = $this->_request->getParam('filedesc');
- $filetype = $msg['file_type'];
- $realname = $msg['realname'];
-
-
- $sql = "insert into attachments (filename,filetype,filedesc,userid,filesize,realname) values ('$filename','$filetype','$filedesc','$u_id','$filesize','$realname') RETURNING id";
- $sth = $this->db->prepare($sql);
- $sth->execute();
- $att = $sth->fetch(PDO::FETCH_ASSOC);
- $msg['attid'] = $attid = $att['id'];
-
- $sql = "insert into mdattach (uuid,id) values ('$uuid','$attid')";
- if($this->db->exec($sql))
- {
- $msg['html'] = $realname.'['. round($filesize/1024,2) .' kb]
';
- echo Zend_Json::encode($msg);
- exit();
- }else{
- $msg['error'] = '附件上传失败:写入附件表出错';
- @unlink($filename);
- echo Zend_Json::encode($msg);
- exit();
- }
-
-
- }else{
- $msg['error'] = '附件上传失败:'.$msg['error'];
- @unlink($filename);
- echo Zend_Json::encode($msg);
- exit();
- }
-
- }catch(Exception $e){
- $msg['error'] = "错误:".$e->getMessage();
- echo Zend_Json::encode($msg);
- exit();
- }
- }
- }//文件上传
-
- if($ac == 'download')
- {
- (int)$id = $this->_request->getParam('id');
-
- $sql = "select * from attachments where id='$id'";
-
- $re = $this->db->query($sql);
-
- $row = $re->fetch();
-
- $file = new files();
-
- $fullPath = $this->view->config->upload.$row['filename'];
-
-
- // Parse Info / Get Extension
- $fsize = filesize($fullPath);
- $path_parts = pathinfo($fullPath);
- $ext = strtolower($path_parts["extension"]);
-
- // Determine Content Type
- switch ($ext) {
- case "pdf": $ctype="application/pdf"; break;
- case "exe": $ctype="application/octet-stream"; break;
- case "zip": $ctype="application/zip"; break;
- case "doc": $ctype="application/msword"; break;
- case "xls": $ctype="application/vnd.ms-excel"; break;
- case "ppt": $ctype="application/vnd.ms-powerpoint"; break;
- case "gif": $ctype="image/gif"; break;
- case "png": $ctype="image/png"; break;
- case "jpeg":
- case "jpg": $ctype="image/jpg"; break;
- default: $ctype="application/force-download";
- }
-
- $content=file_get_contents($fullPath);
- $this->_helper->layout->disableLayout();
- $this->_helper->viewRenderer->setNoRender();
- $this->getResponse()->setHeader('Content-Type', 'application/octet-stream')
- ->setHeader('Content-Disposition','attachment; filename="'.basename($fullPath).'"')
- ->setHeader('Content-Length', $fsize)
- ->setHeader('Content-Type','application/force-download')
- ->setHeader('Content-Type','application/download')
- ->setHeader('Content-Type',$ctype)
- ->setHeader('Content-Description','File Transfer')
- ->setHeader('Content-Transfer-Encoding','binary')
- ->setHeader('Expires',0)
- ->setHeader('Cache-Control','must-revalidate, post-check=0, pre-check=0')
- ->setHeader('Pragma','public')
- ->setBody($content);
- }//文件下载
-
- }//文档管理
-
- public function getFileinfo($id){
- $sql = "select * from attachments where id='$id'";
- $re= $this->db->query($sql);
- $row= $re->fetch();
- return $row;
- }
+
+ //文档管理
+ function documentAction(){
+
+ $ac = $this->_request->getParam('ac');
+
+ $auth = Zend_Auth::getInstance();
+ if($auth->hasIdentity())
+ {
+ $user = $auth->getIdentity();
+ $u_id = $user->id;
+ }
+
+ if(empty($ac) || $ac == 'list' || $ac=='search')
+ {
+
+ $wheresql = "";
+
+ $keyword = $this->_request->getParam('q');
+
+ if($ac=='search' && !empty($keyword))
+ {
+ $this->view->q = $keyword;
+ $search = new Search($keyword);
+ $wheresql = $search->sql_expr(array("md.title"));
+ }
+ if(!empty($wheresql))
+ {
+ $wheresql = " AND ".$wheresql;
+ }
+
+
+ $sql = "select count(att.id) as aid,md.title,md.uuid from metadata md
+ LEFT JOIN mdauthor a ON a.uuid=md.uuid
+ LEFT JOIN mdattach att ON att.uuid=md.uuid
+ WHERE a.status>=1 AND a.userid=? $wheresql
+ 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(10);
+ $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(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))
+ {
+ $this->view->error = "参数有误!";
+ return true;
+ }
+
+ $sql = "SELECT att.*,md.title,md.uuid FROM mdattach mda
+ LEFT JOIN attachments att ON mda.id=att.id
+ LEFT JOIN metadata md ON mda.uuid=md.uuid
+ LEFT JOIN users u ON att.userid=u.id";
+
+ $sth = $this->db->prepare($sql);
+ $sth->execute(array());
+ $rows = $sth->fetchAll();
+
+ $this->view->info=$rows;
+
+ $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('document-view');
+ }
+
+ if($ac == 'del')
+ {
+
+ $this->_helper->layout()->disableLayout();
+ $this->_helper->viewRenderer->setNoRender();
+
+ (int)$id = $this->_request->getParam('id');
+ $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))
+ {
+ exit();
+ }
+
+ $info = $this->getFileinfo($id);
+ $filepath = $dataFilePath.$info['filename'];
+ try{
+ $auth = Zend_Auth::getInstance();
+ if($auth->hasIdentity())
+ {
+ $user = $auth->getIdentity();
+ $userid = $user->id;
+ $sql_mdattach = "delete from mdattach where uuid='$uuid' and id='$id'";
+ $sql = "delete from attachments where id='$id' and userid='$userid'";
+ if($this->db->exec($sql_mdattach)>0 && $this->db->exec($sql)>0)
+ {
+ @unlink($filepath);
+ echo "ok";
+ }
+ }
+
+ }catch(Exception $e){}
+ //不输出任何错误
+
+ }//删除
+
+ if($ac=='upload')
+ {
+ $submit = $this->_request->getParam('submit');
+ if(empty($submit))
+ {
+ $uuid = $this->_request->getParam('uuid');
+ $this->view->uuid=$uuid;
+ $this->_helper->layout->disableLayout();
+ $this->_helper->viewRenderer('document-upload');
+ return true;
+ }
+ else
+ {
+ $this->_helper->layout()->disableLayout();
+ $this->_helper->viewRenderer->setNoRender();
+
+ $uuid = $this->_getParam('uuid');
+
+ try{
+
+ $files=new files();
+ $msg = $files -> upload($this->view->config->upload,$_FILES['Filedata'],'md');
+
+ if(empty($msg['error']))
+ {
+ $msg['error']="";
+ $filename = $msg['db_path'];
+ $filesize = $msg['file_size'];
+ $filedesc = $this->_request->getParam('filedesc');
+ $filetype = $msg['file_type'];
+ $realname = $msg['realname'];
+
+
+ $sql = "insert into attachments (filename,filetype,filedesc,userid,filesize,realname) values ('$filename','$filetype','$filedesc','$u_id','$filesize','$realname') RETURNING id";
+ $sth = $this->db->prepare($sql);
+ $sth->execute();
+ $att = $sth->fetch(PDO::FETCH_ASSOC);
+ $msg['attid'] = $attid = $att['id'];
+
+ $sql = "insert into mdattach (uuid,id) values ('$uuid','$attid')";
+ if($this->db->exec($sql))
+ {
+ $msg['html'] = $realname.'['. round($filesize/1024,2) .' kb] ';
+ echo Zend_Json::encode($msg);
+ exit();
+ }else{
+ $msg['error'] = '附件上传失败:写入附件表出错';
+ @unlink($filename);
+ echo Zend_Json::encode($msg);
+ exit();
+ }
+
+
+ }else{
+ $msg['error'] = '附件上传失败:'.$msg['error'];
+ @unlink($filename);
+ echo Zend_Json::encode($msg);
+ exit();
+ }
+
+ }catch(Exception $e){
+ $msg['error'] = "错误:".$e->getMessage();
+ echo Zend_Json::encode($msg);
+ exit();
+ }
+ }
+ }//文件上传
+
+ if($ac == 'download')
+ {
+ (int)$id = $this->_request->getParam('id');
+
+ $sql = "select * from attachments where id='$id'";
+
+ $re = $this->db->query($sql);
+
+ $row = $re->fetch();
+
+ $file = new files();
+
+ $fullPath = $this->view->config->upload.$row['filename'];
+
+
+ // Parse Info / Get Extension
+ $fsize = filesize($fullPath);
+ $path_parts = pathinfo($fullPath);
+ $ext = strtolower($path_parts["extension"]);
+
+ // Determine Content Type
+ switch ($ext) {
+ case "pdf": $ctype="application/pdf"; break;
+ case "exe": $ctype="application/octet-stream"; break;
+ case "zip": $ctype="application/zip"; break;
+ case "doc": $ctype="application/msword"; break;
+ case "xls": $ctype="application/vnd.ms-excel"; break;
+ case "ppt": $ctype="application/vnd.ms-powerpoint"; break;
+ case "gif": $ctype="image/gif"; break;
+ case "png": $ctype="image/png"; break;
+ case "jpeg":
+ case "jpg": $ctype="image/jpg"; break;
+ default: $ctype="application/force-download";
+ }
+
+ $content=file_get_contents($fullPath);
+ $this->_helper->layout->disableLayout();
+ $this->_helper->viewRenderer->setNoRender();
+ $this->getResponse()->setHeader('Content-Type', 'application/octet-stream')
+ ->setHeader('Content-Disposition','attachment; filename="'.basename($fullPath).'"')
+ ->setHeader('Content-Length', $fsize)
+ ->setHeader('Content-Type','application/force-download')
+ ->setHeader('Content-Type','application/download')
+ ->setHeader('Content-Type',$ctype)
+ ->setHeader('Content-Description','File Transfer')
+ ->setHeader('Content-Transfer-Encoding','binary')
+ ->setHeader('Expires',0)
+ ->setHeader('Cache-Control','must-revalidate, post-check=0, pre-check=0')
+ ->setHeader('Pragma','public')
+ ->setBody($content);
+ }//文件下载
+
+ }//文档管理
+
+ /*
+ * delegateAction() 委托
+ *
+ *
+ */
+ public function delegateAction(){
+
+ $ac = $this->_request->getParam('ac');
+ $uuid = $this->_request->getParam('uuid');
+
+ if($ac == '' && !empty($uuid))
+ {
+
+ $auth = Zend_Auth::getInstance();
+ if($auth->hasIdentity())
+ {
+ $user = $auth->getIdentity();
+ $uid = $user->id;
+ }
+
+ 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))
+ {
+ $this->view->info = "参数错误";
+ return true;
+ }
+
+ $sql = "SELECT * FROM metadata WHERE uuid=?";
+ $sth = $this->db->prepare($sql);
+ $sth ->execute(array($uuid));
+ $row = $sth->fetch();
+
+ $this->view->metadata = $row;
+
+ //确认一下用户有权限,如果直接使用update语句无法得到已更改过的状态
+
+ $sql = "SELECT * FROM mdstatus
+ WHERE uuid=? AND userid=? AND (status=? OR status=?)";
+
+ $sth = $this->db->prepare($sql);
+ $sth->execute(array($uuid,$uid,5,6));
+ $mds = $sth->fetch();
+
+ if(!empty($mds['id']))
+ {
+ $sql = "UPDATE mdstatus SET status=7,ts_changed='now()' WHERE uuid='$uuid' AND userid=$uid";
+ if($this->db->exec($sql))
+ {
+ $this->view->info = "委托成功!";
+ return true;
+ }
+ else
+ {
+ $this->view->info = "委托失败!";
+ return true;
+ }
+ }else{
+ $this->view->info = "该数据无法委托,请确定数据状态已经可以进行委托,或数据尚未进行委托";
+ }
+ }
+
+ if($ac == 'cancel')
+ {
+
+ $auth = Zend_Auth::getInstance();
+ if($auth->hasIdentity())
+ {
+ $user = $auth->getIdentity();
+ $uid = $user->id;
+ }
+
+ 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))
+ {
+ $this->view->info = "参数错误";
+ return true;
+ }
+
+ $sql = "SELECT * FROM metadata WHERE uuid=?";
+ $sth = $this->db->prepare($sql);
+ $sth ->execute(array($uuid));
+ $row = $sth->fetch();
+
+ $this->view->metadata = $row;
+
+ $sql = "SELECT * FROM mdstatus
+ WHERE uuid=? AND userid=? AND status=?";
+
+ $sth = $this->db->prepare($sql);
+ $sth->execute(array($uuid,$uid,7));
+ $mds = $sth->fetch();
+
+ if(!empty($mds['id']))
+ {
+ $sql = "UPDATE mdstatus SET status=6,ts_changed='now()' WHERE uuid='$uuid' AND userid=$uid";
+ if($this->db->exec($sql))
+ {
+ $this->view->info = "取消委托成功!";
+ return true;
+ }
+ else
+ {
+ $this->view->info = "取消委托失败!";
+ return true;
+ }
+ }else{
+ $this->view->info = "操作失败!该数据尚未进行委托";
+ }
+
+
+ }
+
+
+ }//委托
+
+
+ public function getFileinfo($id){
+ $sql = "select * from attachments where id='$id'";
+ $re= $this->db->query($sql);
+ $row= $re->fetch();
+ return $row;
+ }
//成为作者后的后继处理工作
private function author_first($uuid,$author)
diff --git a/application/default/views/scripts/author/accept.phtml b/application/default/views/scripts/author/accept.phtml
index ddf33e60..de8cc1dc 100644
--- a/application/default/views/scripts/author/accept.phtml
+++ b/application/default/views/scripts/author/accept.phtml
@@ -34,16 +34,22 @@ $this->breadcrumb()->setSeparator(' > ');
- 【操作:
- 申请管理 |
- 反馈 |
- 文档 |
- 文献 |
- 修改元数据 |
- 版本 |
- QA |
- 新闻 |
- 所有作者 】
+ 【操作:
+ 申请管理 |
+ 反馈 |
+ 文档 |
+ 文献 |
+ 修改元数据 |
+ 版本 |
+ QA |
+ 新闻 |
+ 所有作者
+
+ | 委托
+
+ | 取消委托
+
+ 】
400?$this->escape(mb_substr($item['description'],0,400,'UTF-8').'...'):$this->escape($item['description']); ?>
@@ -66,30 +72,4 @@ $this->breadcrumb()->setSeparator(' > ');
\ No newline at end of file
diff --git a/application/default/views/scripts/author/delegate.phtml b/application/default/views/scripts/author/delegate.phtml
new file mode 100644
index 00000000..cf5f62d5
--- /dev/null
+++ b/application/default/views/scripts/author/delegate.phtml
@@ -0,0 +1,36 @@
+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('首页');
+$this->breadcrumb('数据作者');
+$this->breadcrumb('我的数据');
+$this->breadcrumb('数据委托');
+$this->breadcrumb()->setSeparator(' > ');
+?>
+
+
+
+
+
+
+
+
\ No newline at end of file