实现了版本提交中的流程处理,其中给专家发信部分还未实现

This commit is contained in:
wlx 2012-04-01 15:07:40 +00:00
parent 7dccdbf83e
commit 6f0e10ee60
1 changed files with 256 additions and 64 deletions

View File

@ -1706,91 +1706,283 @@ class AuthorController extends Zend_Controller_Action
$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));
// 2. 获取数据评审状态
$sql = "SELECT s.* FROM mdstatus s left join mdversion v on s.uuid=v.uuid WHERE v.id=?";
// 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=?";
$sth = $this->db->prepare($sql);
$sth->execute(array($id));
$row = $sth->fetch();
if (empty($row)) //无对应记录
{
// do
$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'],
));
$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) //取消发布的数据
else if ($row['id']==-1 || $row['id']==0 || $row['id']==1) //取消发布的数据,初始状态,已接收
{
//do something.
//同步元数据
$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'],
));
$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']==0) //初始状态
else if ($row['id']==2 || $row['id']==3 || $row['id']==4)//已发送过外审邮件,需由编辑告知变化信息
{
//do
}
else if ($row['id']==1)//接收
{
//
}
else if ($row['id']==2)//已发送过外审邮件,需由编辑告知变化信息
{
//do
}
else if ($row['id']==3 || $row['id']==4)//专家在审理中
{
//do
//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'],
));
$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)//数据已经发布,再次修改后将只通知管理员,保留发布状态
{
//do
//同步元数据
$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'],
));
$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;
}
if(!empty($row['id']))
{
$data = array("error"=>$this->alertbox('warning','该数据已经在评审中,请勿重复提交'));
$this->jsonexit($data);
return true;
}
$sql = "UPDATE mdversion SET changelog=?,userid=? WHERE id=?";
$sth = $this->db->prepare($sql);
$ex_changelog = $sth->execute(array($changelog,$u_id,$id));
if($ex_changelog){
$sql = "SELECT v.uuid FROM mdversion v
LEFT JOIN mdauthor a ON a.uuid=v.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 = "INSERT INTO mdstatus (uuid,status,userid) VALUES (?,?,?)";
$sth = $this->db->prepare($sql);
$ex = $sth->execute(array($row['uuid'],1,$u_id));
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;
}
}else{
$data = array("error"=>$this->alertbox('error','提交失败,刷新后重试'));
$this->jsonexit($data);
return true;
}
}catch(Exception $e) {
}catch(Exception $e) {
$msg = "提交失败,请确认权限后重试";
if($this->debug>0)
{$msg .= $e->getMessage();}
$data = array("error"=>$this->alertbox('error',$msg));
$this->jsonexit($data);
return true;
}
}
}//发布到评审
//与前一个版本对比