覆盖了父辈orderAction方法,提供了WATER项目自己的申请协议

This commit is contained in:
wlx 2010-11-04 14:12:31 +00:00
parent e1d0a3fada
commit fa2c1c9311
1 changed files with 218 additions and 0 deletions

View File

@ -287,6 +287,224 @@ class WaterController extends DataController
//提供全部分类列表 //提供全部分类列表
} }
} }
/*
* 离线申请(可以包括在线数据),在无数据参数时,则显示已有列表
*/
function orderAction()
{
$uuid=$this->_request->getParam('uuid');
$del = $this->_request->getParam('del');
$apply = $this->_request->getParam('apply');
$finish = $this->_request->getParam('finish');
$cancel = $this->_request->getParam('cancel');
$pdf = $this->_request->getParam('pdf');
//if (empty($uuid)) $this->_redirect('/data');
$userid=Zend_Auth::getInstance()->getIdentity()->id;
if ($uuid)
{
//处理数据入库
//离线申请的数据不应该重复因此需要在数据库限制还是在WEB端限制
//在数据库中控制只保证uuid,userid,status唯一就可以?
//存在历史遗留问题,原来的数据并不能保证唯一
//status: 1 开始进入离线申请申请程序中
// 2 填写并提交离线申请表
// 3 邮寄离线申请表
// 4 收到离线申请表
// 5 处理离线申请表
// 10:离线申请完成?
// -1: 取消了在线下载进程
//首先判断离线申请的数据数量是否超过系统限制
$sql="select count(*) as datacount from dataorder where (ts_approved is null) and userid=? and status>0 and status<6";
$r=$this->db->fetchRow($sql,array($userid));
//保证添加的离线数据申请未申请
$sql="select count(*) as datacount from dataorder where (ts_approved is null) and userid=? and uuid=? and status=1";
$r1=$this->db->fetchRow($sql,array($userid,$uuid));
if ($r['datacount']<$this->view->config->download->max && $r1['datacount']<1) {
$sql="insert into dataorder (uuid,ts_created,userid,status) values(?,now(),?,?)";
$this->db->query($sql,array($uuid,$userid,1));
//成功信息提示
$sql=$this->db->quoteInto("select title,uuid from metadata where uuid=?",$uuid);
$this->view->md=$this->db->fetchRow($sql);
} else {
if ($r1['datacount']>=1)
$this->view->msg="错误:您申请的数据已经在数据蓝中!";
else
$this->view->msg="错误:您正在进行的离线申请的数据数已经超过系统允许的最大值,请在完成本次离线申请后再进行操作!";
}
} elseif ($del) {
//删除数据申请
$sql=$this->db->quoteInto("delete from dataorder where id=?",$del);
$this->db->query($sql);
$this->_redirect('/data/order');
} elseif ($apply) {
if ($apply=='all') {
$sql=$this->db->quoteInto("update dataorder set status=2 where status=1 and userid=?",$userid);
$this->db->query($sql);
} else {
$sql="update dataorder set status=2 where status=1 and userid=? and id=?";
$this->db->query($sql,array($userid,(int)$apply));
}
} elseif ($finish) {
if ($finish=='all') {
$sql=$this->db->quoteInto("update dataorder set ts_approved=now() where status=0 and userid=?",$userid);
$this->db->query($sql);
$sql="update ftpuser set datacount=0 where userid=?";
$this->db->query($sql,array($userid));
} else {
$sql="update dataorder set ts_approved=now() where status=0 and userid=? and id=?";
$this->db->query($sql,array($userid,(int)$finish));
$sql="update ftpuser set datacount=datacount-1 where userid=?";
$this->db->query($sql,array($userid));
}
} elseif ($cancel) {
if ($cancel=='all') {
$sql=$this->db->quoteInto("update dataorder set ts_approved=now(),status=-1 where status=0 and userid=?",$userid);
$this->db->query($sql);
$sql="update ftpuser set datacount=0 where userid=?";
$this->db->query($sql,array($userid));
} else {
$sql="update dataorder set ts_approved=now(),status=-1 where status=0 and userid=? and id=?";
$this->db->query($sql,array($userid,(int)$cancel));
$sql="update ftpuser set datacount=datacount-1 where userid=?";
$this->db->query($sql,array($userid));
}
} elseif ($pdf) {
//生成PDF离线申请文件
//用户信息可以从SESSION中读取离线申请信息
//$sql="select * from users where id=?";
$sql="select m.title||'('||m.filesize::text||'MB)' as title from dataorder d left join metadata m on d.uuid=m.uuid where d.status=2 and d.userid=? order by d.ts_created desc";
$rows=$this->db->fetchAll($sql,array($userid));
if ($rows) {
$this->view->data2=$rows;
$this->view->form=new OfflinePdfForm();
$this->_helper->viewRenderer('pdf');
if ($this->_request->isPost()) {
$formData = $this->_request->getPost();
$datalist='';
foreach($rows as $i=>$row) $datalist.=($i+1).". ".$row['title'].";";
$formData['datalist']=$datalist;
if ($this->view->form->isValid($formData)) {
if (@$formData['save']) {
//保存
//根据pdflink字段以判断是否已经提交
//在数据库中创建rules在更新offlineapp表时同时更新users表中对应的信息
$sql="select id from offlineapp where userid=? and (pdflink is null or pdflink='') and (ts_approved is null)";
$row=$this->db->fetchRow($sql,array($userid));
if ($row) {
$sql="update offlineapp set username=?,email=?,phone=?,address=?,postcode=?,project=?,unit=?,datalist=?,ts_created=now() where id=?";
$this->db->query($sql,array($formData['realname'],$formData['email'],$formData['phone'],$formData['address'],$formData['postcode'],$formData['project'],$formData['unit'],$datalist,$row['id']));
} else {
$sql="insert into offlineapp (userid,username,email,phone,address,postcode,project,unit,datalist) values(?,?,?,?,?,?,?,?,?)";
$this->db->query($sql,array($userid,$formData['realname'],$formData['email'],$formData['phone'],$formData['address'],$formData['postcode'],$formData['project'],$formData['unit'],$datalist));
}
$this->_helper->layout->disableLayout();
$this->_helper->viewRenderer->setNoRender();
//生成PDF
$pdf = new ApplicantWaterPDF();
$pdf->template=$this->view->config->offline->water_template;
$pdf->data = $formData;
$pdf->drawWestdc();
header("Content-Disposition: inline; filename=result.pdf");
header("Content-Type:application/pdf");
//header("Content-Length: " . strlen($pdfstring));
echo $pdf->Output('westdc-data-apply.pdf','S');
die();
//exit;
} elseif ($formData['submit']) {
//提交
//生成PDF
$pdf = new ApplicantWaterPDF();
$pdf->template=$this->view->config->offline->water_template;
$pdf->data = $formData;
$pdf->drawWestdc();
$fn=$formData['realname'].date('YmdHis').".pdf";
$pdf->Output($this->view->config->offline->savepath."/".$fn, 'F');
//保存到数据库
$sql="select id from offlineapp where userid=? and pdflink is null and (ts_approved is null)";
$row=$this->db->fetchRow($sql,array($userid));
if ($row) {
$sql="update offlineapp set username=?,email=?,phone=?,address=?,postcode=?,project=?,unit=?,datalist=?,ts_created=now(),pdflink=? where id=?";
$this->db->query($sql,array($formData['realname'],$formData['email'],$formData['phone'],$formData['address'],$formData['postcode'],$formData['project'],$formData['unit'],$datalist,$fn,$row['id']));
} else {
$sql="insert into offlineapp (userid,username,email,phone,address,postcode,project,unit,datalist,pdflink) values(?,?,?,?,?,?,?,?,?,?)";
$this->db->query($sql,array($userid,$formData['realname'],$formData['email'],$formData['phone'],$formData['address'],$formData['postcode'],$formData['project'],$formData['unit'],$datalist,$fn));
}
$sql="update dataorder set status=3 where status=2 and userid=?";
$this->db->query($sql,array($userid));
//发送用户邮件进行信息提示和说明
//$mail = new Zend_Mail('utf-8');
$mail = new WestdcMailer($this->view->config->smtp);
$body=file_get_contents($this->view->config->offline->email->template);
$body=str_replace("[username]",$formData['realname'],$body);
$body=str_replace("[datalist]",str_replace(";","\n",$datalist),$body);
$mail->setBodyText($body);
$mail->addTo($formData['email']);
$mail->setSubject('您在西部数据中心进行的离线申请');
$mail->addHeader('Reply-To', $this->view->config->service->email);
$mail->setFrom($this->view->config->service->email,'西部数据中心服务组');
$attach=$mail->createAttachment($pdf->Output('applicant','S'));
$attach->filename='数据申请-'.$formData['realname'].'.pdf';
/*$tr=new Zend_Mail_Transport_Smtp($this->view->config->smtp->host,
array('ssl' => $this->view->config->smtp->ssl,
'auth'=>$this->view->config->smtp->auth,
'username'=>$this->view->config->smtp->username,
'password'=>$this->view->config->smtp->password));
$mail->send($tr);*/
$mail->send();
//跳转到/data/order并提示帮助信息告知用户已经发送EMAIL
$this->messenger->addMessage('提示信息:您的离线申请已经提交,系统已经发送一封邮件给您,请打印出申请表并签字后邮寄给西部数据中心服务组,具体信息请参考邮件说明。');
$this->_redirect('/data/order');
}
}
} else {
$sql="select u.*,o.postcode from users u left join offlineapp o on u.id=o.userid where u.id=?";
$row=$this->db->fetchRow($sql,array($userid));
/*$row=$ut->fetchRow('id='.$userid);
$formData['email']=$row->email;
$formData['phone']=$row->phone;
$formData['realname']=$row->realname;
$formData['unit']=$row->unit;
$formData['address']=$row->address;
$formData['purpose']=$row->project;
$formData['id']=$row->id;*/
$this->view->form->populate($row);
}
} else
$this->view->msg="错误:您还没有提交任何离线申请的数据,或您的数据申请已经正式提交(等待处理过程中)!";
}
//显示已经申请的数据,包括已经提交的申请和未提交的申请,还有已经处理完成的申请,正在进行的在线数据下载
$sql="select d.*,m.title,m.datatype from dataorder d left join metadata m on d.uuid=m.uuid where (d.status>0 or (d.status=0 and (d.ts_approved is null))) and d.userid=? order by d.status,d.ts_created desc";
$rows=$this->db->fetchAll($sql,array($userid));
foreach($rows as $row) {
switch ($row['status']){
case 0:
$dataorder0[]=$row;
break;
case 1:
$dataorder1[]=$row;
break;
case 2:
case 3:
case 4:
case 5:
$dataorder2[]=$row;
break;
default:
$dataorder3[]=$row;
break;
}
}
@$this->view->dataorder0=$dataorder0;
@$this->view->dataorder1=$dataorder1;
@$this->view->dataorder2=$dataorder2;
@$this->view->dataorder3=$dataorder3;
}
private function getmd($keyword,$type='place') private function getmd($keyword,$type='place')
{ {
$page=(int)$this->_request->getParam('page'); $page=(int)$this->_request->getParam('page');