982 lines
40 KiB
PHP
982 lines
40 KiB
PHP
<?php
|
||
class Admin_DownController extends Zend_Controller_Action
|
||
{
|
||
function preDispatch()
|
||
{
|
||
$this->db=Zend_Registry::get('db');
|
||
$this->view->config = Zend_Registry::get('config');
|
||
$this->messenger=$this->_helper->getHelper('FlashMessenger');
|
||
$this->view->messages = $this->messenger->getMessages();
|
||
}
|
||
function postDispatch()
|
||
{
|
||
$this->view->messages = $this->messenger->getMessages();
|
||
}
|
||
function indexAction()
|
||
{
|
||
//其他连接
|
||
}
|
||
|
||
//离线数据申请管理
|
||
function offlineappAction()
|
||
{
|
||
$view =(int)$this->_getParam('view');
|
||
$start =(int)$this->_getParam('start');
|
||
$finish =(int)$this->_getParam('finish');
|
||
$cancel =(int)$this->_getParam('cancel');
|
||
$deny =(int)$this->_getParam('deny');
|
||
$page =(int)$this->_getParam('page');
|
||
$reset =(int)$this->_getParam('reset');
|
||
$status =(int)$this->_getParam('status');
|
||
|
||
if (!$page) $page=1;
|
||
if ($view) {
|
||
//查看此次申请的pdf
|
||
$sql="select * from offlineapp where id=?";
|
||
$row=$this->db->fetchRow($sql,array($view));
|
||
$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
|
||
} elseif ($start) {
|
||
$sql="update dataorder set status=4 where offlineappid=?";
|
||
$this->db->query($sql,array($start));
|
||
$sql="select * from offlineapp where id=?";
|
||
$row=$this->db->fetchRow($sql,array($start));
|
||
$username=$row['username'];
|
||
//发送用户邮件进行信息提示和说明
|
||
$mail = new WestdcMailer($this->view->config->smtp);
|
||
$datalist=str_replace(";","\n",$row['datalist']);
|
||
$mailtp=new EmailText($this->db,'offline-start',array('user'=>$username,'datalist'=>$datalist));
|
||
$mail->setBodyText($mailtp->getBody());
|
||
$mail->setSubject($mailtp->getSubject());
|
||
$mail->addTo($row['email']);
|
||
$mail->setFrom($this->view->config->service->email,'西部数据中心服务组');
|
||
$mail->send();
|
||
|
||
$sql="select pdflink from offlineapp where id=?";
|
||
$row=$this->db->fetchRow($sql,array($start));
|
||
$filecontent=file_get_contents($this->view->config->offline->savepath."/".$row['pdflink']);
|
||
|
||
//对每条数据的管理员用户发送相应的邮件通知,同一用户的邮件需要合并
|
||
//需要取出对应数据的标题、uuid,以及对应的作者的email(一条数据可能有多个作者,一次申请可能有多条数据对应同一个作者)
|
||
//邮件中应提示用户可以选择是否委托给数据中心进行管理(这样以后就不接受相应的管理邮件,但用户仍然可以自主取消此选择)
|
||
$uuid_done="";
|
||
// 0. 处理专题数据集
|
||
$sql="select s.email,m.title,d.uuid,s.title as sourcetitle from dataorder d left join datasource ds on d.uuid=ds.uuid
|
||
left join source s on ds.sourceid=s.id left join metadata m on d.uuid=m.uuid
|
||
where d.offlineappid=? and s.admin_status=1 and d.uuid<>all(s.exclude_data)
|
||
order by s.email,m.title";
|
||
$rows=$this->db->fetchAll($this->db->quoteInto($sql,$start));
|
||
$tmp_email='';
|
||
$data='';
|
||
$source='';
|
||
foreach($rows as $row)
|
||
{
|
||
if ($tmp_email!=$row['email'])
|
||
{
|
||
if (!empty($data))
|
||
{
|
||
//发送之前的用户申请审核邮件
|
||
unset($mail);
|
||
$mail = new WestdcMailer($this->view->config->smtp);
|
||
$mailtp=new EmailText($this->db,'offline-start-subject',array('user'=>$username,'datalist'=>$data,'source'=>$source));
|
||
$mail->setFrom($this->view->config->service->email,'西部数据中心服务组');
|
||
$mail->setBodyText($mailtp->getBody());
|
||
$mail->setSubject($mailtp->getSubject());
|
||
$mail_addrs=explode(",",substr($tmp_email,1,-1));
|
||
$mail->addTo($mail_addrs);
|
||
$mail->addCc($this->view->config->service->email,'西部数据中心服务组');
|
||
$mail->createAttachment($filecontent,'application/octet-stream',Zend_Mime::DISPOSITION_ATTACHMENT, Zend_Mime::ENCODING_BASE64, 'offlineapp.pdf');
|
||
$mail->send();
|
||
$data="";
|
||
$source="";
|
||
}
|
||
$tmp_email=$row['email'];
|
||
$source=$row['sourcetitle'];
|
||
}
|
||
$data.=" 数据名称:".$row['title']."\n";
|
||
$data.=" \t数据地址:http://westdc.westgis.ac.cn/data/".$row['uuid']."\n\n";
|
||
$uuid_done.="'".$row['uuid']."',"
|
||
}
|
||
//发送最后一封邮件
|
||
if (!empty($data))
|
||
{
|
||
unset($mail);
|
||
$mail = new WestdcMailer($this->view->config->smtp);
|
||
$mailtp=new EmailText($this->db,'offline-start-author',array('user'=>$username,'datalist'=>$data,'source'=>$source));
|
||
$mail->setFrom($this->view->config->service->email,'西部数据中心服务组');
|
||
$mail->setBodyText($mailtp->getBody());
|
||
$mail->setSubject($mailtp->getSubject());
|
||
$mail_addrs=explode(",",substr($tmp_email,1,-1));
|
||
$mail->addTo($mail_addrs);
|
||
$mail->addCc($this->view->config->service->email,'西部数据中心服务组');
|
||
$mail->createAttachment($filecontent,'application/octet-stream',Zend_Mime::DISPOSITION_ATTACHMENT, Zend_Mime::ENCODING_BASE64, 'offlineapp.pdf');
|
||
$mail->send();
|
||
}
|
||
|
||
// 1. 处理有数据作者且自行管理的数据并且未被0处理过的
|
||
$sql="select u.email,m.title,d.uuid,a.activation from dataorder d left join mdstatus s on d.uuid=s.uuid left join users u on s.userid=u.id
|
||
left join metadata m on m.uuid=d.uuid left join mdauthor a on a.uuid=d.uuid
|
||
where d.offlineappid=? and s.status=6 and a.userid=s.userid and d.uuid not in (".substr($uuid_done,0,-1).")
|
||
order by u.email,m.title";
|
||
$rows=$this->db->fetchAll($this->db->quoteInto($sql,$start));
|
||
$tmp_email='';
|
||
$data='';
|
||
foreach($rows as $row)
|
||
{
|
||
if ($tmp_email!=$row['email'])
|
||
{
|
||
if (!empty($data))
|
||
{
|
||
//发送之前的用户申请审核邮件
|
||
unset($mail);
|
||
$mail = new WestdcMailer($this->view->config->smtp);
|
||
$mailtp=new EmailText($this->db,'offline-start-author',array('user'=>$username,'datalist'=>$data));
|
||
$mail->setFrom($this->view->config->service->email,'西部数据中心服务组');
|
||
$mail->setBodyText($mailtp->getBody());
|
||
$mail->setSubject($mailtp->getSubject());
|
||
$mail->addTo($tmp_email);
|
||
$mail->addCc($this->view->config->service->email,'西部数据中心服务组');
|
||
$mail->createAttachment($filecontent,'application/octet-stream',Zend_Mime::DISPOSITION_ATTACHMENT, Zend_Mime::ENCODING_BASE64, 'offlineapp.pdf');
|
||
$mail->send();
|
||
$data="";
|
||
}
|
||
$tmp_email=$row['email'];
|
||
}
|
||
$data.=" 数据名称:".$row['title']."\n";
|
||
$data.=" \t数据地址:http://westdc.westgis.ac.cn/data/".$row['uuid']."\n";
|
||
$data.=" \t如您不想收到此类数据申请审核的邮件,您可以将该数据委托给数据中心代为审核,委托后您也可以随时撤销此委托以便继续自行管理。\n";
|
||
$data.=" \t如想委托给数据中心,请访问此网址:http://westdc.westgis.ac.cn/author/delegate/uuid/".$row['uuid']."\n";
|
||
$data.=" \t撤销委托方法:进入数据中心->数据作者->我的数据,在该数据条上撤销委托。\n\n";
|
||
$uuid_done.="'".$row['uuid']."',";
|
||
}
|
||
//发送最后一封邮件
|
||
if (!empty($data))
|
||
{
|
||
unset($mail);
|
||
$mail = new WestdcMailer($this->view->config->smtp);
|
||
$mailtp=new EmailText($this->db,'offline-start-author',array('user'=>$username,'datalist'=>$data));
|
||
$mail->setFrom($this->view->config->service->email,'西部数据中心服务组');
|
||
$mail->setBodyText($mailtp->getBody());
|
||
$mail->setSubject($mailtp->getSubject());
|
||
$mail->addTo($tmp_email);
|
||
$mail->addCc($this->view->config->service->email,'西部数据中心服务组');
|
||
$mail->createAttachment($filecontent,'application/octet-stream',Zend_Mime::DISPOSITION_ATTACHMENT, Zend_Mime::ENCODING_BASE64, 'offlineapp.pdf');
|
||
$mail->send();
|
||
}
|
||
|
||
// 2. 处理委托数据中心进行管理的数据
|
||
$sql="select m.title,d.uuid from dataorder d left join mdstatus s on d.uuid=s.uuid left join metadata m on m.uuid=d.uuid
|
||
left join datasource ds on ds.uuid=d.uuid left join source on ds.sourceid=source.id
|
||
where d.offlineappid=? and (s.status=7 or source.admin_status=2) and d.uuid not in (".substr($uuid_done,0,-1).") order by m.title";
|
||
$rows=$this->db->fetchAll($this->db->quoteInto($sql,$start));
|
||
$data="";
|
||
foreach($rows as $row)
|
||
{
|
||
$data.=" 数据名称:".$row['title']."\n";
|
||
$data.=" \t数据地址:http://westdc.westgis.ac.cn/data/".$row['uuid']."\n\n";
|
||
$uuid_done.="'".$row['uuid']."',";
|
||
}
|
||
if (!empty($data))
|
||
{
|
||
unset($mail);
|
||
$mail = new WestdcMailer($this->view->config->smtp);
|
||
$mailtp=new EmailText($this->db,'offline-start-dcadmin',array('user'=>$username,'datalist'=>$data));
|
||
$mail->setFrom($this->view->config->service->email,'西部数据中心服务组');
|
||
$mail->setBodyText($mailtp->getBody());
|
||
$mail->setSubject($mailtp->getSubject());
|
||
$addrs=array();
|
||
$addrs[] = 'nztong@lzb.ac.cn';
|
||
$addrs[] = 'wjian@lzb.ac.cn';
|
||
$addrs[] = 'lixin@lzb.ac.cn';
|
||
$mail->addTo($addrs);
|
||
$mail->addCc($this->view->config->service->email,'西部数据中心服务组');
|
||
$mail->createAttachment($filecontent,'application/octet-stream',Zend_Mime::DISPOSITION_ATTACHMENT, Zend_Mime::ENCODING_BASE64, 'offlineapp.pdf');
|
||
$mail->send();
|
||
}
|
||
|
||
// 3. 未认证的数据,即无明确的数据管理者,从元数据提取对应管理者的email信息进行管理
|
||
//无数据作者的数据,根据元数据中的联系人信息发送相应的管理邮件,发送策略是多发还是少发?
|
||
//发送管理邮件同时建议用户认证为数据的作者,可以有更多的管理选择,同时邮件中应该有详细的说明为什么会收到此邮件
|
||
$sql="select distinct res.email,d.uuid,m.title,role.role from dataorder d left join role on d.uuid=role.uuid left join responsible res on role.resid=res.id
|
||
left join metadata m on d.uuid=m.uuid where length(res.email)>4 and d.offlineappid=?
|
||
and role.role in ('pointOfContact','custodian','resourceProvider','owner','distributor','publisher','author')
|
||
and d.uuid not in (".substr($uuid_done,0,-1).")
|
||
order by m.title,res.email";
|
||
$rows=$this->db->fetchAll($this->db->quoteInto($sql,$start));
|
||
unset($addrs);
|
||
$md=array();
|
||
$tmp_title='';
|
||
$role=array();
|
||
$role['pointOfContact']=array();
|
||
$role['custodian']=array();
|
||
$role['resourceProvider']=array();
|
||
$role['owner']=array();
|
||
$role['distributor']=array();
|
||
$role['publisher']=array();
|
||
$role['author']=array();
|
||
$single=array();
|
||
foreach($rows as $row)
|
||
{
|
||
if ($tmp_title!=$row['title'])
|
||
{
|
||
if (count($role))
|
||
{
|
||
$single['role']=$role;
|
||
$md[]=$single;
|
||
}
|
||
|
||
$single['title']=$row['title'];
|
||
$single['uuid']=$row['uuid'];
|
||
|
||
$tmp_title=$row['title'];
|
||
$role=array();
|
||
$role['pointOfContact']=array();
|
||
$role['custodian']=array();
|
||
$role['resourceProvider']=array();
|
||
$role['owner']=array();
|
||
$role['distributor']=array();
|
||
$role['publisher']=array();
|
||
$role['author']=array();
|
||
}
|
||
if ($row['role']=='resourceProvider')
|
||
{
|
||
$role['resourceProvider'][]=$row['email'];
|
||
} elseif ($row['role']=='custodian') {
|
||
$role['custodian'][]=$row['email'];
|
||
} elseif ($row['role']=='pointOfContact') {
|
||
$role['pointOfContact'][]=$row['email'];
|
||
} elseif ($row['role']=='owner') {
|
||
$role['owner'][]=$row['email'];
|
||
} elseif ($row['role']=='distributor') {
|
||
$role['distributor'][]=$row['email'];
|
||
} elseif ($row['role']=='publisher') {
|
||
$role['publisher'][]=$row['email'];
|
||
} elseif ($row['role']=='author') {
|
||
$role['author'][]=$row['email'];
|
||
}
|
||
}
|
||
if (count($role))
|
||
{
|
||
$single['role']=$role;
|
||
$md[]=$single;
|
||
}
|
||
//再循环一次,提取最高权限email组,并发送管理邮件
|
||
$newmd=array();
|
||
$single=array();
|
||
foreach($md as $row)
|
||
{
|
||
if (count($row['role']))
|
||
{
|
||
$addrs=array();
|
||
if (count($row['role']['pointOfContact']))
|
||
{
|
||
$addrs=$row['role']['pointOfContact'];
|
||
} elseif (count($row['role']['custodian'])) {
|
||
$addrs=$row['role']['custodian'];
|
||
} elseif (count($row['role']['resourceProvider'])) {
|
||
$addrs=$row['role']['resourceProvider'];
|
||
} elseif (count($row['role']['owner'])) {
|
||
$addrs=$row['role']['owner'];
|
||
} elseif (count($row['role']['distributor'])) {
|
||
$addrs=$row['role']['distributor'];
|
||
} elseif (count($row['role']['publisher'])) {
|
||
$addrs=$row['role']['publisher'];
|
||
} elseif (count($row['role']['author'])) {
|
||
$addrs=$row['role']['author'];
|
||
}
|
||
$single['uuid']=$row['uuid'];
|
||
$single['title']=$row['title'];
|
||
foreach($addrs as $email)
|
||
{
|
||
$single['email']=$email;
|
||
//$newmd[]=$single;
|
||
$newmd['uuid'][]=$row['uuid'];
|
||
$newmd['title'][]=$row['title'];
|
||
$newmd['email'][]=$email;
|
||
}
|
||
}
|
||
}
|
||
//按照email排序
|
||
array_multisort($newmd['email'],$newmd['uuid'],$newmd['title']);
|
||
$tmp_email='';
|
||
$data='';
|
||
foreach($newmd['email'] as $k=>$row)
|
||
{
|
||
if ($tmp_email!=$row)
|
||
{
|
||
if (!empty($data))
|
||
{
|
||
unset($mail);
|
||
$mail = new WestdcMailer($this->view->config->smtp);
|
||
$mailtp=new EmailText($this->db,'offline-start-mdadmin',array('user'=>$username,'datalist'=>$data));
|
||
$mail->setFrom($this->view->config->service->email,'西部数据中心服务组');
|
||
$mail->setBodyText($mailtp->getBody());
|
||
$mail->setSubject($mailtp->getSubject());
|
||
$mail->addTo($tmp_email);
|
||
$mail->addCc($this->view->config->service->email,'西部数据中心服务组');
|
||
$mail->createAttachment($filecontent,'application/octet-stream',Zend_Mime::DISPOSITION_ATTACHMENT, Zend_Mime::ENCODING_BASE64, 'offlineapp.pdf');
|
||
$mail->send();
|
||
$data='';
|
||
}
|
||
$tmp_email=$row;
|
||
}
|
||
$data.=" 数据名称:".$newmd['title'][$k]."\n";
|
||
$data.=" \t数据地址:http://westdc.westgis.ac.cn/data/".$newmd['uuid'][$k]."\n";
|
||
$data.=" \t如您不想收到此类数据申请审核的邮件,您可以在按如下操作办法进行处理:1. 申请成为该数据作者;2. 将该数据委托给数据中心代为审核,委托后您也可以随时撤销此委托以便继续自行管理。\n";
|
||
$data.=" \t如要申请成为该数据作者:进入数据中心->数据作者->数据认证,查找到对应的数据后,在其下方点击申请认证即可。\n\n";
|
||
}
|
||
if (!empty($data))
|
||
{
|
||
unset($mail);
|
||
$mail = new WestdcMailer($this->view->config->smtp);
|
||
$mailtp=new EmailText($this->db,'offline-start-mdadmin',array('user'=>$username,'datalist'=>$data));
|
||
$mail->setFrom($this->view->config->service->email,'西部数据中心服务组');
|
||
$mail->setBodyText($mailtp->getBody());
|
||
$mail->setSubject($mailtp->getSubject());
|
||
$mail->addTo($tmp_email);
|
||
$mail->addCc($this->view->config->service->email,'西部数据中心服务组');
|
||
$mail->createAttachment($filecontent,'application/octet-stream',Zend_Mime::DISPOSITION_ATTACHMENT, Zend_Mime::ENCODING_BASE64, 'offlineapp.pdf');
|
||
$mail->send();
|
||
}
|
||
|
||
//提示信息
|
||
$this->messenger->addMessage('提示信息:该离线数据已经开始处理,并发送邮件给申请人以及数据管理委员会,请在处理完成后点击“完成”。');
|
||
$this->_redirect('/admin/down/offlineapp/'.$page);
|
||
} elseif ($finish) {
|
||
try {
|
||
$sql = "SELECT authorpermitted FROM dataorder WHERE offlineappid=?";
|
||
$sth = $this->db->prepare($sql);
|
||
$sth->execute(array($finish));
|
||
$row = $sth->fetch();
|
||
if($row['authorpermitted'] <0)
|
||
{
|
||
$this->messenger->addMessage('提示信息:数据作者明确反对该下载申请,所以不能进行进一步通过');
|
||
$this->_redirect('/admin/down/offlineapp/'.$page);
|
||
}
|
||
|
||
$sql="update dataorder set status=5,ts_approved=now() where offlineappid=?";
|
||
$this->db->query($sql,array($finish));
|
||
$sql="update offlineapp set ts_approved=now() where id=? and ts_approved is null";
|
||
$this->db->query($sql,array($finish));
|
||
$sql="select * from offlineapp where id=?";
|
||
$row=$this->db->fetchRow($sql,array($finish));
|
||
$sql="select * from dataorder left join dataset on dataset.uuid=dataorder.uuid where dataorder.offlineappid=?";
|
||
$rs=$this->db->fetchAll($sql,array($finish));
|
||
$has_ftp1=false;
|
||
foreach($rs as $data) {
|
||
if ($data['host']=='ftp1.westgis.ac.cn')
|
||
$has_ftp1=true;
|
||
// deal with ftp.westgis.ac.cn, use g6 to add path
|
||
// todo ...
|
||
}
|
||
//deal with ftp1 account
|
||
if ($has_ftp1) {
|
||
$user=(object)array("id"=>$row['userid'],
|
||
"username"=>"westdc_".$row['userid'],
|
||
"password"=>md5('westdc'.$row['userid'].rand(1000,9999)),
|
||
"time"=>date('Y-m-d H:i:s', strtotime('+2 week')),
|
||
//"path"=>$path,
|
||
"maxdata"=>$this->view->config->download->max,
|
||
"datacount"=>1 //represent one offline application
|
||
);
|
||
$proftp=new Proftp();
|
||
$proftp->db=$this->db;
|
||
if ($proftp->createuser($user))
|
||
{
|
||
$user->datacount=0; //force this offline to be true
|
||
$proftp->createuser($user);
|
||
$this->messenger->addMessage('提示信息:该用户申请的数据过多,请检查该用户之前已完成的申请。');
|
||
}
|
||
//发送用户邮件进行信息提示和说明
|
||
$mail = new WestdcMailer($this->view->config->smtp);
|
||
//实例化EmailText
|
||
$mailtp=new EmailText($this->db,'offline-finish',
|
||
array('user'=>$row['username'],'datalist'=>str_replace(";","\n",$row['datalist']),
|
||
'ftpuser'=>$user->username,'ftppwd'=>$proftp->pwd,'ftptime'=>$proftp->time));
|
||
$mail->setBodyText($mailtp->getBody());
|
||
$mail->setFrom($this->view->config->service->email,'西部数据中心服务组');
|
||
$mail->addTo($row['email']);
|
||
$mail->setSubject($mailtp->getSubject());
|
||
$mail->send();
|
||
} //ftp1 deal
|
||
$this->messenger->addMessage('提示信息:该离线数据已经处理完成。');
|
||
} catch (Exception $e) {
|
||
//提示信息
|
||
$this->messenger->addMessage($e->getMessage());
|
||
$this->messenger->addMessage('提示信息:该数据有可能还没有收到纸质申请表。');
|
||
}
|
||
$this->_redirect('/admin/down/offlineapp/'.$page);
|
||
} elseif ($cancel) {
|
||
//取消=删除?
|
||
//用户提出申请的取消操作
|
||
//$sql="update dataorder set status=-1 where (status=3 or status=4) and userid=?";
|
||
$sql="delete from dataorder where offlineappid=? and (status=3 or status=4)";
|
||
$this->db->query($sql,array($cancel));
|
||
$sql="delete from offlineapp where id=?";
|
||
$this->db->query($sql,array($cancel));
|
||
$this->messenger->addMessage('提示信息:已删除该用户离线申请。');
|
||
$this->_redirect('/admin/down/offlineapp/'.$page);
|
||
} elseif ($deny) {
|
||
$sql="update dataorder set status=-1 where offlineappid=? and (status=3 or status=4)";
|
||
$this->db->query($sql,array($deny));
|
||
$sql="update offlineapp set ts_approved=now(),status=-1 where id=? and ts_approved is null";
|
||
$this->db->query($sql,array($deny));
|
||
$this->messenger->addMessage('提示信息:已拒绝该用户离线申请。');
|
||
$this->_redirect('/admin/down/offlineapp/'.$page);
|
||
} else if($reset){
|
||
|
||
if($reset < 0)
|
||
{
|
||
|
||
$fortime = date('Y-m-d',(time()-24*3600*365));
|
||
$sql="update dataorder set status=1 where status=3 and ts_created < '$fortime'";
|
||
if($this->db->exec($sql)>0)
|
||
{
|
||
$this->messenger->addMessage('已经成功重置了 '.$fortime.' 前的所有申请');
|
||
$this->_redirect('/admin/down/offlineapp/');
|
||
}
|
||
|
||
}
|
||
else if($reset > 0)
|
||
{
|
||
$sql="update dataorder set status='1' where status='3' and offlineappid='$reset'";
|
||
if($this->db->exec($sql)>0)
|
||
{
|
||
$this->messenger->addMessage('已经成功对该申请重置');
|
||
$this->_redirect('/admin/down/offlineapp/');
|
||
}
|
||
else {
|
||
$this->messenger->addMessage('没有找到对应数据,无法进行重置,可能是旧记录没有匹配数据造成的');
|
||
$this->_redirect('/admin/down/offlineapp/');
|
||
}
|
||
}//elseif
|
||
//if
|
||
}//reset
|
||
|
||
$select="select distinct(o.*),d.status as datastatus from offlineapp o
|
||
left join dataorder d on o.id=d.offlineappid";
|
||
if ($status==4)
|
||
$select.=" where o.ts_approved is null
|
||
and o.pdflink is not null and d.status=4";
|
||
elseif ($status==-1)
|
||
$select.=" where o.pdflink is not null and o.status=-1";
|
||
else
|
||
$select.=" where o.ts_approved is null
|
||
and o.pdflink is not null and d.status in (3,4)";
|
||
$select.=" order by o.ts_created desc";
|
||
$rs=$this->db->query($select);
|
||
$rows=$rs->fetchAll();
|
||
$paginator = Zend_Paginator::factory($rows);
|
||
$paginator->setCurrentPageNumber($page);
|
||
$paginator->setItemCountPerPage($this->view->config->page->max);
|
||
$paginator->setView($this->view);
|
||
Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination.phtml');
|
||
$this->view->paginator=$paginator;
|
||
}
|
||
//离线数据服务记录
|
||
function offlineAction()
|
||
{
|
||
$add=(int)$this->_getParam('add');
|
||
$edit=(int)$this->_getParam('edit');
|
||
$delete=(int)$this->_getParam('delete');
|
||
$down=(int)$this->_getParam('down');
|
||
$update=$this->_getParam('update');
|
||
$show=$this->_getParam('show');
|
||
$undelete=$this->_getParam('undelete');
|
||
$emaillist=$this->_getParam('emaillist');
|
||
|
||
if ($add) {
|
||
$form=new OfflinelogForm();
|
||
$form->pdf->setDestination($this->view->config->offline->savepath);
|
||
if ($this->_request->isPost()) {
|
||
$formdata=$this->_request->getPost();
|
||
if ($form->isValid($formdata)) {
|
||
$uploadedData = $form->getValues();
|
||
$pdf = basename($form->pdf->getFileName());
|
||
$sql="insert into offlineapp (username,email,unit,phone,address,postcode,project,pdflink,datalist,ts_created,ts_approved) values(?,?,?,?,?,?,?,?,?,?,now())";
|
||
$this->db->query($sql,array($formdata['username'],$formdata['email'],$formdata['unit'],$formdata['phone'],$formdata['address'],$formdata['postcode'],$formdata['project'],$pdf,$formdata['datalist'],$formdata['ts_approved']));
|
||
$this->messenger->addMessage('提示信息:您已经成功添加该离线服务记录。');
|
||
$this->_redirect('/admin/down/offline');
|
||
} else {
|
||
$form->populate($formdata);
|
||
}
|
||
}
|
||
$this->view->form=$form;
|
||
$this->_helper->viewRenderer('offlineadd');
|
||
} //添加服务记录
|
||
|
||
elseif ($edit){
|
||
$form=new OfflinelogForm();
|
||
$form->pdf->setRequired(false);
|
||
if ($this->_request->isPost()) {
|
||
$formdata=$this->_request->getPost();
|
||
if ($form->isValid($formdata)) {
|
||
$uploadedData = $form->getValues();
|
||
$pdf = basename($form->pdf->getFileName());
|
||
$sql="update offlineapp set username=?,email=?,unit=?,phone=?,address=?,postcode=?,project=?,";
|
||
if ($form->pdf->isUploaded()) $sql.="pdflink=?,";
|
||
$sql.="datalist=?,ts_approved=? where id=?";
|
||
$param=array($formdata['username'],$formdata['email'],$formdata['unit'],$formdata['phone'],$formdata['address'],$formdata['postcode'],$formdata['project']);
|
||
if ($form->pdf->isUploaded()) $param[]=$pdf;
|
||
$param[]=$formdata['datalist'];
|
||
$param[]=$formdata['ts_approved'];
|
||
$param[]=$edit;
|
||
$this->db->query($sql,$param);
|
||
$this->messenger->addMessage('提示信息:您已经编辑添加该记录。');
|
||
$page = $this->_getParam('page');
|
||
if(!empty($page))
|
||
$this->_redirect('/admin/down/offline/page/'.$page);
|
||
else
|
||
$this->_redirect('/admin/down/offline/');
|
||
} else {
|
||
$form->populate($formdata);
|
||
}
|
||
} else {
|
||
$sql="select * from offlineapp where id=?";
|
||
$formdata=$this->db->fetchRow($sql,array($edit));
|
||
$form->submit->setLabel('保存');
|
||
$form->populate($formdata);
|
||
}
|
||
$this->view->form=$form;
|
||
$this->_helper->viewRenderer('offlineadd');
|
||
|
||
} //编辑
|
||
|
||
elseif ($delete) {
|
||
$sql="delete from offlineapp where id='$delete'";
|
||
$sql2="delete from dataorder where offlineappid='$delete'";
|
||
|
||
if($this->db->exec($sql)>0)
|
||
{
|
||
if($this->db->exec($sql2)>0)
|
||
{
|
||
$this->messenger->addMessage('成功删除了数据服务记录,并且删除了关联的申请记录');
|
||
$this->_redirect("/admin/down/offline");
|
||
}
|
||
else
|
||
{
|
||
$this->messenger->addMessage('成功删除了数据服务记录,但并未找到关联的申请记录');
|
||
$this->_redirect("/admin/down/offline");
|
||
}
|
||
}
|
||
else {
|
||
$this->messenger->addMessage('删除失败');
|
||
$this->_redirect("/admin/down/offline");
|
||
}
|
||
}//删除服务记录
|
||
|
||
else if ($down) {
|
||
$this->_helper->layout->disableLayout();
|
||
$this->_helper->viewRenderer->setNoRender();
|
||
$sql="select * from offlineapp where ts_approved is not null and pdflink is not null order by ts_created desc";
|
||
$rows=$this->db->fetchAll($sql);
|
||
foreach($rows as $row){
|
||
$content.='"'.$row['username'].'","'.$row['unit'].'","'.$row['phone'].'","'.$row['address'].'","'.$row['postcoe'].'","'.str_replace("\"","'",$row['project']).'","'.str_replace("\"","'",$row['datalist']).'","'.$row['email'].'",'.$row['ts_created']."\n";
|
||
}
|
||
$this->getResponse()->setHeader('Content-Type', 'application/octet-stream')
|
||
->setHeader('Content-Disposition','attachment; filename="offlineapp.csv"')
|
||
->setHeader('Content-Length', strlen($content))
|
||
->setHeader('Content-Type','application/force-download')
|
||
->setHeader('Content-Type','application/download')
|
||
->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);
|
||
|
||
} //下载离线服务记录
|
||
|
||
else if ($update) {
|
||
|
||
$sql = 'select o.id as oid,o.userid,o.username as un,u.email as uemail,o.email,u.realname as rn,u.id as uid from offlineapp o
|
||
right join users u on o.email=u.email
|
||
where o.userid is null and o.ts_approved is not null and o.email is not null';
|
||
$re = $this->db->query($sql);
|
||
$row = $re->fetchAll();
|
||
$s=0;
|
||
foreach ($row as $k=>$v)
|
||
{
|
||
if (empty($v['userid']))
|
||
{
|
||
$sql="update offlineapp set userid='{$v['uid']}' where id='{$v['oid']}'";
|
||
if ($this->db->exec($sql)) $s++;
|
||
}
|
||
}
|
||
$this->messenger->addMessage('提示信息:已有 '.$s.' 条记录被更改');
|
||
|
||
$this->_redirect('/admin/down/offline');
|
||
|
||
}//同步用户账户与离线申请记录
|
||
|
||
else if($show){
|
||
|
||
$sql="select * from offlineapp where id='$show'";
|
||
|
||
$rs = $this->db->query($sql);
|
||
|
||
$row= $rs->fetch();
|
||
|
||
$this->view->infos=$row;
|
||
|
||
$this->_helper->viewRenderer('offlineshow');
|
||
|
||
}//查看单条记录
|
||
|
||
else if($emaillist)
|
||
{
|
||
$sql = "select distinct(t.*) from
|
||
(
|
||
select u.email from dataorder d left join users u on d.userid=u.id where (d.status=0 or d.status=5)
|
||
union
|
||
select o.email from offlineapp o where o.userid is null and o.email is not null
|
||
) as t";
|
||
$re = $this->db->query($sql);
|
||
$rows = $re->fetchAll();
|
||
$filecontent = "";
|
||
foreach($rows as $row){
|
||
$filecontent.=$row['email']."\r\n";
|
||
}
|
||
|
||
$this->_helper->layout->disableLayout();
|
||
$this->_helper->viewRenderer->setNoRender();
|
||
$this->getResponse()->setHeader('Content-Type', 'application/octet-stream')
|
||
->setHeader('Content-Disposition','attachment; filename="emails.txt"')
|
||
->setHeader('Content-Length', strlen($filecontent))
|
||
->setHeader('Content-Type','application/force-download')
|
||
->setHeader('Content-Type','application/download')
|
||
->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($filecontent);
|
||
|
||
}//下载邮箱地址列表
|
||
|
||
$select=$this->db->select();
|
||
$select->from('offlineapp')->where('ts_approved is not null')->where('pdflink is not null')->where('status=0')->order('ts_created desc');
|
||
$paginator = Zend_Paginator::factory($select);
|
||
$paginator->setCurrentPageNumber($this->_getParam('page'));
|
||
$paginator->setItemCountPerPage($this->view->config->page->max);
|
||
$paginator->setView($this->view);
|
||
Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination.phtml');
|
||
$this->view->paginator=$paginator;
|
||
|
||
$this->view->page = $this->_getParam('page');
|
||
}
|
||
//在线数据下载情况,仅针对onlineapp表,自2011-9-8开始记录。
|
||
function onlineAction()
|
||
{
|
||
$show=(int)$this->_getParam('show');
|
||
$delete=(int)$this->_getParam('delete');
|
||
|
||
if(empty($show) && empty($delete))
|
||
{
|
||
$select=$this->db->select();
|
||
$select->from('onlineapp as o',array('id','userid','unit','username','ts_created','project'))
|
||
->join('metadata as m', 'o.uuid = m.uuid', array('title','uuid'))
|
||
->where('o.id in (select distinct(onlineappid) from dataorder)')
|
||
->order('o.id desc');
|
||
$paginator = Zend_Paginator::factory($select);
|
||
$paginator->setCurrentPageNumber($this->_getParam('page'));
|
||
$paginator->setItemCountPerPage($this->view->config->page->max);
|
||
$paginator->setView($this->view);
|
||
Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination.phtml');
|
||
$this->view->paginator=$paginator;
|
||
|
||
$count = count($this->db->fetchAll($select));
|
||
$this->view->count=$count;
|
||
}//列表
|
||
|
||
elseif($delete)
|
||
{
|
||
try {
|
||
$sql="delete from onlineapp where id=?";
|
||
$this->db->query($sql,array($delete));
|
||
$sql="delete from dataorder where onlineappid=?";
|
||
$this->db->query($sql,array($delete));
|
||
$this->messenger->addMessage('该记录已删除');
|
||
} catch (Exception $e) {
|
||
$this->messenger->addMessage($e->getMessage());
|
||
}
|
||
$this->_redirect("/admin/down/online/");
|
||
}//删除
|
||
|
||
elseif($show)
|
||
{
|
||
$sql ="select o.*,u.username as uname,u.id as uid,m.title,m.uuid
|
||
from onlineapp as o
|
||
left join users as u on u.id = o.userid
|
||
left join metadata as m on o.uuid = m.uuid
|
||
where o.id=?";
|
||
$result =$this->db->query($sql,$show);
|
||
$rows = $result->fetch();
|
||
$this->view->infos=$rows;
|
||
|
||
$this->_helper->viewRenderer('onlineshow');
|
||
}//查看详细
|
||
}//onlineAction
|
||
|
||
function userAction()
|
||
{
|
||
$show =(int)$this->_getParam('show');
|
||
$search = $this->_getParam('search');
|
||
$keyword = $this->view->keyword = $this->_getParam('keyword');
|
||
|
||
if(empty($show))
|
||
{
|
||
$select=$this->db->select();
|
||
$select->from('dataorder as o','count(o.id) as num')
|
||
->join('users as u', 'u.id = o.userid', array('realname','id as uid','unit'))
|
||
->where('o.status=0 or o.status=5')
|
||
->where('o.userid = u.id');
|
||
if(!empty($search) && !empty($keyword))
|
||
{
|
||
$select ->Where('u.realname like ? or u.unit like ? ','%'.$keyword.'%');
|
||
$this->view->title='“'.$keyword.'”的搜索结果 :';
|
||
}
|
||
$select ->group('uid')
|
||
->group('realname')
|
||
->group('unit')
|
||
->order('num desc');
|
||
$paginator = Zend_Paginator::factory($select);
|
||
$paginator->setCurrentPageNumber($this->_getParam('page'));
|
||
$paginator->setItemCountPerPage($this->view->config->page->max);
|
||
$paginator->setView($this->view);
|
||
Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination_param.phtml');
|
||
$this->view->paginator=$paginator;
|
||
|
||
$count = count($this->db->fetchAll($select));
|
||
$this->view->count=$count;
|
||
}//列表
|
||
|
||
elseif($show)
|
||
{
|
||
$select=$this->db->select();
|
||
$select->from('dataorder as o',array('id','ts_created','userid','offlineappid','onlineappid'))
|
||
->joinLeft('metadata as m', 'o.uuid = m.uuid', array('title','uuid','filesize'))
|
||
->joinLeft('users as u','u.id=o.userid',array('realname as username'))
|
||
->where('o.userid = ?', $show)
|
||
->where('o.status=0 or o.status=5')
|
||
->order('o.id desc');
|
||
$paginator = Zend_Paginator::factory($select);
|
||
$paginator->setCurrentPageNumber($this->_getParam('page'));
|
||
$paginator->setItemCountPerPage($this->view->config->page->max);
|
||
$paginator->setView($this->view);
|
||
Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination.phtml');
|
||
$this->view->paginator=$paginator;
|
||
|
||
$sql="select username,realname from users where id='$show'";
|
||
$re=$this->db->query($sql);
|
||
$t=$re->fetch();
|
||
$this->view->infos=$t;
|
||
|
||
$this->_helper->viewRenderer('showuser');
|
||
}//查看单个用户的下载记录
|
||
|
||
}//userAction 用户下载情况
|
||
|
||
function dataAction()
|
||
{
|
||
$show = $this->_getParam('show');
|
||
$search = $this->_getParam('search');
|
||
$keyword = $this->view->keyword = $this->_getParam('keyword');
|
||
|
||
if(empty($show))
|
||
{
|
||
$select=$this->db->select();
|
||
$select->from('dataorder as o','count(o.id) as num')
|
||
->join('metadata as m', 'o.uuid = m.uuid', array('title','uuid'))
|
||
->where('o.uuid = m.uuid and (o.status=0 or o.status=5)');
|
||
if(!empty($search) && !empty($keyword))
|
||
{
|
||
$select ->Where('m.title like ? or m.title_en like ?','%'.$keyword.'%');
|
||
$this->view->title='“'.$keyword.'”的搜索结果 :';
|
||
}
|
||
$select ->group('m.title')
|
||
->group('m.uuid')
|
||
->order('num desc');
|
||
$paginator = Zend_Paginator::factory($select);
|
||
$paginator->setCurrentPageNumber($this->_getParam('page'));
|
||
$paginator->setItemCountPerPage(20);
|
||
$paginator->setView($this->view);
|
||
Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination_param.phtml');
|
||
$this->view->paginator=$paginator;
|
||
|
||
$count = count($this->db->fetchAll($select));
|
||
$this->view->count=$count;
|
||
|
||
}//数据下载情况列表
|
||
|
||
elseif($show)
|
||
{
|
||
$select=$this->db->select();
|
||
$select->from('dataorder as o',array('ts_created','ts_created','offlineappid','onlineappid'))
|
||
->join('metadata as m', 'o.uuid = m.uuid', array('title','uuid'))
|
||
->join('users as u', 'o.userid=u.id',array('id as userid','username','realname'))
|
||
->where('m.uuid = ? and (o.status=0 or o.status=5)', $show)
|
||
->order('o.id desc');
|
||
$paginator = Zend_Paginator::factory($select);
|
||
$paginator->setCurrentPageNumber($this->_getParam('page'));
|
||
$paginator->setItemCountPerPage($this->view->config->page->max);
|
||
$paginator->setView($this->view);
|
||
Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination.phtml');
|
||
$this->view->paginator=$paginator;
|
||
|
||
$sql="select title,uuid from metadata where uuid='$show'";
|
||
$re=$this->db->query($sql);
|
||
$t=$re->fetch();
|
||
$this->view->infos=$t;
|
||
|
||
$this->_helper->viewRenderer('showdata');
|
||
}//查看单个数据下载情况
|
||
|
||
}//dataAction 数据下载情况
|
||
|
||
function searchAction()
|
||
{
|
||
$search = $this->_getParam('search');
|
||
$keyword = $this->view->keyword = $this->_getParam('keyword');
|
||
|
||
$select=$this->db->select();
|
||
|
||
if(!empty($search) && !empty($keyword))
|
||
{
|
||
|
||
$select ->from('onlineapp as o',array('id','userid','unit','username','ts_created','project'))
|
||
->Where('o.username like ? ','%'.$keyword.'%')
|
||
->orWhere('o.unit like ? ','%'.$keyword.'%')
|
||
->orWhere('o.project like ? ','%'.$keyword.'%')
|
||
->orWhere('m.title like ? ','%'.$keyword.'%')
|
||
->join('metadata as m', 'o.uuid = m.uuid', array('title','uuid'))
|
||
->order('o.id desc');
|
||
|
||
$paginator = Zend_Paginator::factory($select);
|
||
$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('online');
|
||
|
||
$count = count($this->db->fetchAll($select));
|
||
$this->view->count=$count;
|
||
$this->view->title='搜索结果 :';
|
||
}
|
||
else {
|
||
$this->_redirect("/admin/down/online");
|
||
}
|
||
|
||
}//searchAction 搜索
|
||
|
||
function updateAction(){
|
||
|
||
/*$select=$this->db->select();
|
||
$select ->from('offlineapp as o',array('username as un','email'))
|
||
->join('users as u','u.email=o.email')
|
||
->where('o.userid is null and o.ts_approved is not null and o.email is not null');*/
|
||
|
||
$sql = 'select o.id as oid,o.userid,o.username as un,u.email as uemail,o.email,u.realname as rn,u.id as uid from offlineapp o
|
||
right join users u on o.email=u.email
|
||
where o.userid is null and o.ts_approved is not null and o.email is not null';
|
||
$re = $this->db->query($sql);
|
||
$row = $re->fetchAll();
|
||
|
||
foreach ($row as $k=>$v)
|
||
{
|
||
if (empty($v['userid']))
|
||
{
|
||
$sql="update offlineapp set userid='{$v['uid']}' where id='{$v['oid']}'";
|
||
$row[$k]['sql']=$sql;
|
||
//$re=$this->db-exec($sql);
|
||
}
|
||
}
|
||
|
||
$paginator = Zend_Paginator::factory($row);
|
||
$paginator->setCurrentPageNumber($this->_getParam('page'));
|
||
$paginator->setItemCountPerPage(20);
|
||
$paginator->setView($this->view);
|
||
Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination_param.phtml');
|
||
$this->view->paginator=$paginator;
|
||
|
||
$count = count($row);
|
||
$this->view->count=$count;
|
||
|
||
$this->_helper->viewRenderer('update');
|
||
|
||
}
|
||
function fixofflineAction(){
|
||
|
||
$fix = $this->_getParam('fix');
|
||
$orders = $this->_getParam('orders');
|
||
$nouserid= $this->_getParam('nouserid');
|
||
|
||
if($fix)
|
||
{
|
||
if(!empty($orders))
|
||
{
|
||
$num=0;
|
||
foreach ($orders as $k=>$v)
|
||
{
|
||
$ex=split(',',$v);
|
||
$sql="update offlineapp set userid='{$ex[0]}' where id='{$ex[1]}'";
|
||
if($this->db->exec($sql))
|
||
$num++;
|
||
}
|
||
$this->messenger->addMessage('已经匹配了'.$num.'条记录');
|
||
$this->_redirect("/admin/down/fixoffline");
|
||
}
|
||
else {
|
||
$this->messenger->addMessage('请选择要匹配的条目');
|
||
$this->_redirect("/admin/down/fixoffline");
|
||
}
|
||
}
|
||
|
||
|
||
if($nouserid)
|
||
{
|
||
$sql = "select * from offlineapp where userid is null";
|
||
$re = $this->db->query($sql);
|
||
$row = $re->fetchAll();
|
||
|
||
$paginator = Zend_Paginator::factory($row);
|
||
$paginator->setCurrentPageNumber($this->_getParam('page'));
|
||
$paginator->setItemCountPerPage(20);
|
||
$paginator->setView($this->view);
|
||
Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination_param.phtml');
|
||
$this->view->paginator=$paginator;
|
||
|
||
$count = count($row);
|
||
$this->view->count=$count;
|
||
|
||
$this->_helper->viewRenderer('nouserid');
|
||
}
|
||
else{
|
||
$sql = "select o.id as oid,o.username as un,o.unit as uu,u.username,u.realname rn,u.unit,u.id as uid
|
||
from offlineapp o right join users u on trim(o.username)=trim(u.realname)
|
||
where o.userid is null and o.id>0
|
||
order by o.id";
|
||
|
||
$re = $this->db->query($sql);
|
||
$row = $re->fetchAll();
|
||
|
||
$paginator = Zend_Paginator::factory($row);
|
||
$paginator->setCurrentPageNumber($this->_getParam('page'));
|
||
$paginator->setItemCountPerPage(20);
|
||
$paginator->setView($this->view);
|
||
Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination_param.phtml');
|
||
$this->view->paginator=$paginator;
|
||
|
||
$count = count($row);
|
||
$this->view->count=$count;
|
||
}
|
||
|
||
|
||
}//fixofflineAction 用户匹配
|
||
}
|
||
|