修复在线下载问题

This commit is contained in:
wlx 2013-11-11 06:45:07 +00:00
parent 3bf1e7015b
commit 1a394fe8ef
1 changed files with 9 additions and 160 deletions

View File

@ -818,7 +818,7 @@ class DataController extends Zend_Controller_Action
);
@$mail=new WestdcMailer($this->view->config->smtp);
@$mail->setBodyText($mailtp->getBody());
@$mail->setFrom($this->view->config->service->email,'西部数据中心服务组');
@$mail->setFrom($this->view->config->service->email,'CARD data service');
@$mail->addTo($this->view->config->service->email);
if(is_array($rows) && count($rows)>0)
{
@ -953,165 +953,14 @@ class DataController extends Zend_Controller_Action
if($this->db->insert('onlineapp',$data)) { $select = "select id from onlineapp where userid='$userid' order by id desc"; $re=$this->db->query($select); $row=$re->fetch(); $this->view->AlertType = "alert-success"; $this->view->jump_url = '/data/download/uuid/'.$uuid.'/onlineappid/'.$row['id']; $this->view->msg = "You are successful submit your online data download information, just wait a moment to auto jump to the download url.<a href=\"".$this->view->jump_url."\"> Or click here to visit the download url.</a>"; $msg = "用户{$data['username']} 填写了在线数据申请表 <a href=\"/admin/down/online/show/{$row['id']}\">查看详细</a>"; $title = "用户 {$data['username']} 申请了在线下载数据"; include_once("message.php"); message::post($this->db,0,-1,$title,$msg);
return true; }else { $this->view->AlertType = "alert-error"; $this->view->error = "Failure."; $this->view->info = $data; return true; } return true; }else{ $testsql="select * from onlineapp where userid='$userid' and uuid='$uuid' order by id desc"; $result=$this->db->query($testsql); $rows = $result->fetch(); if (empty($rows['id'])) { include_once("Users.php"); $usr = new Users($this->db); $this->view->info = $usr->getUserInfo($userid); return true; }else{ $datas['realname'] = $rows['username']; $datas['unit'] = $rows['unit']; $datas['phone'] = $rows['phone']; $datas['address'] = $rows['address']; $datas['postcode'] = $rows['postcode']; $datas['email'] = $rows['email']; $datas['project'] = $rows['project']; $datas['project_id'] = $rows['project_id']; $datas['project_type'] = $rows['project_type']; $datas['project_title'] = $rows['project_title']; $datas['project_leader'] = $rows['project_leader']; $this->view->info = $datas; return true; } } return true; }
/*
* 数据下载根据UUID进行判断
* 一次只下载一个数据(一个元数据项)
*/
function downloadAction()
{
$uuid=$this->_request->getParam('uuid');
$onlineappid=$this->_request->getParam('onlineappid');
$this->view->pageID = "account-dataorder";
if (empty($uuid)) $this->_redirect('/data');
$auth = Zend_Auth::getInstance();
if($auth->hasIdentity())
{
$user = $auth->getIdentity();
$userid = $user->id;
}
$testsql="select id,has_send_mail from onlineapp where userid='$userid' and uuid='$uuid' order by id desc";
$result=$this->db->query($testsql);
$rows = $result->fetch();
$has_send_mail=$rows['has_send_mail'];
if (empty($rows['id']))
{
$this->_redirect('/data/'.$uuid);
}
else
{
$sql="select onlineappid,id from dataorder where status=0 and userid='$userid' and uuid='$uuid' order by id desc";
$re=$this->db->query($sql);
$row=$re->fetch();
if(empty($row['onlineappid']))
{
$data = array(
'userid' => $userid,
'uuid' => $uuid,
'onlineappid'=> $onlineappid,
'ts_approved'=>'now()',
);
try {$this->db->insert('dataorder',$data);} catch (Exception $e) {}
}else
{
$sql="update dataorder set onlineappid='$onlineappid',ts_approved=now() where id='{$row['id']}'";
try {$this->db->exec($sql);} catch (Exception $e) {}
}
}
$sql=$this->db->quoteInto("select * from dataset o left join metadata m on o.uuid=m.uuid left join mdstatus s on m.uuid=s.uuid where s.status>4 and m.datatype=0 and m.uuid=?",$uuid);
$data=$this->db->fetchRow($sql);
$updateftp=$updateftp1=false;
$this->view->md=$data;
$this->view->userpass=md5('westdc'.rand(1000,9999));
$this->view->ftptime=date('Y-m-d H:i:s', strtotime('+1 week'));
$sql=$this->db->quoteInto("select * from ftpuser where userid=?",$userid);
$row=$this->db->fetchRow($sql);
$datacount=$row['datacount'];
if ($data['host']=='ftp.westgis.ac.cn')
{
//添加FTP帐号信息以及时间控制信息
$updateftp=true;
$g6=new G6ftp();
$g6->db=$this->db;
//不进行判断,每个元数据中的下载地址都对应一个虚拟路径
$path[]=$data['path'];
$this->view->username='westdc'.$userid;
$uu=(object)array("id"=>$userid,
"username"=>$this->view->username,
"password"=>$this->view->userpass,
"path"=>$path,
"maxdata"=>$this->view->config->download->max,
"time"=>$this->view->ftptime,
"datacount"=>$datacount);
if ($g6->createuser($uu)) {
$this->view->userpass=$g6->pwd;
$this->view->ftptime=$g6->time;
} else {
$this->messenger->addMessage('错误:您正在进行下载的在线数据数已经超过系统允许的最大值,请在下面点击“完成”或“取消”对应的在线数据下载!');
$this->_redirect('/data/order');
}
} elseif ($data['host']=='ftp1.westgis.ac.cn')
{
//添加FTP1帐号信息以及时间控制信息
$proftp=new Proftp();
$proftp->db=$this->db;
//proftp离线用户名和g6的用户名稍有不同
$this->view->username='westdc_'.$userid;
$uu=(object)array("id"=>$userid,
"username"=>$this->view->username,
"password"=>$this->view->userpass,
"host"=>'ftp1.westgis.ac.cn',
"param"=>"onlineappid=".$onlineappid,
"maxdata"=>$this->view->config->download->max,
"time"=>$this->view->ftptime,
"datacount"=>$datacount);
if ($proftp->createuser($uu))
{
$this->view->userpass=$proftp->pwd;
$this->view->ftptime=$proftp->time;
}
} elseif ($data['host']=='ftp2.westgis.ac.cn')
{
//添加FTP2帐号信息以及时间控制信息
$proftp=new Pureftp();
$proftp->db=$this->db;
$this->view->username='westdc_'.$userid;
$uu=(object)array("id"=>$userid,
"username"=>$this->view->username,
"password"=>$this->view->userpass,
"host"=>'ftp2.westgis.ac.cn',
"param"=>"onlineappid=".$onlineappid,
"maxdata"=>$this->view->config->download->max,
"time"=>$this->view->ftptime,
"datacount"=>$datacount);
if ($proftp->createuser($uu))
{
$this->view->userpass=$proftp->pwd;
$this->view->ftptime=$proftp->time;
}
}
$ftpurl='ftp://'.$this->view->username.'@'.$data['host'];
if ($data['host']=='ftp.westgis.ac.cn') $ftpurl.=$data['path'];
//设置输出
//if ($updateftp || $updateftp1) $this->view->userpass=$password;
$this->view->ftpurl=$ftpurl;
//更新下载记录
//todo: 尝试添加一个RULE若有对应数据存在则不插入 userid,uuid,status=0,ts_approved:null)
/*$sql="select * from dataorder where userid=? and uuid=? and status=0 and (ts_approved is null)";
$u=$this->db->fetchRow($sql,array($userid,$uuid));
if (empty($u)) {
$sql="insert into dataorder (userid,uuid,ts_created) values(?,?,now())";
$this->db->query($sql,array($userid,$uuid));
}*/
if (!empty($ftpurl) && !$has_send_mail)
{
$data = array(
"uuid"=>$uuid,
"title"=>$this->view->md['title']."(".$this->view->md['filesize']."MB)",
"user"=>$user->username,
"ftpuser"=>$this->view->username,
"ftppwd"=>$this->view->userpass,
"ftptime"=>$this->view->ftptime,
"ftpurl"=>$this->view->ftpurl,
"note"=>$updateftp?'BTW请注意登陆后要手工进入对应的目录':''
);
$mailtp=new EmailText($this->db,'online-download-en',$data);
$mail=new WestdcMailer($this->view->config->smtp);
$mail->setBodyText($mailtp->getBody());
$mail->setFrom($this->view->config->service->email,'西部数据中心服务组');
$mail->addTo($user->email);
$mail->setSubject($mailtp->getSubject());
@$mail->send();
$sql="update onlineapp set has_send_mail=true where id=?";
$sth=$this->db->prepare($sql);
$sth->execute(array($onlineappid));
}
}
/* * 数据下载根据UUID进行判断 * 一次只下载一个数据(一个元数据项) */ function downloadAction() { $uuid=$this->_request->getParam('uuid'); $onlineappid=$this->_request->getParam('onlineappid'); $this->view->pageID = "account-dataorder"; if (empty($uuid)) $this->_redirect('/data'); $auth = Zend_Auth::getInstance(); if($auth->hasIdentity()) { $user = $auth->getIdentity(); $userid = $user->id; } $testsql="select id,has_send_mail from onlineapp where userid='$userid' and uuid='$uuid' order by id desc"; $result=$this->db->query($testsql); $rows = $result->fetch(); $has_send_mail=$rows['has_send_mail'];
if (empty($rows['id'])) { $this->_redirect('/data/'.$uuid); }else{ $sql="select onlineappid,id from dataorder where status=0 and userid='$userid' and uuid='$uuid' order by id desc"; $re=$this->db->query($sql); $row=$re->fetch(); if(empty($row['onlineappid'])) { $data = array( 'userid' => $userid, 'uuid' => $uuid, 'onlineappid'=> $onlineappid, 'ts_approved'=>'now()', ); try {$this->db->insert('dataorder',$data);} catch (Exception $e) {} }else{ $sql="update dataorder set onlineappid='$onlineappid',ts_approved=now() where id='{$row['id']}'"; try {$this->db->exec($sql);} catch (Exception $e) {} } } $sql=$this->db->quoteInto("select * from dataset o left join en.metadata m on o.uuid=m.uuid left join en.mdstatus s on m.uuid=s.uuid where s.status>4 and m.datatype=0 and m.uuid=?",$uuid); $data=$this->db->fetchRow($sql); $updateftp=$updateftp1=false; $this->view->md=$data; $this->view->userpass=md5('westdc'.rand(1000,9999)); $this->view->ftptime=date('Y-m-d H:i:s', strtotime('+1 week')); $sql=$this->db->quoteInto("select * from ftpuser where userid=?",$userid); $row=$this->db->fetchRow($sql); $datacount=$row['datacount']; if ($data['host']=='ftp.westgis.ac.cn') { //添加FTP帐号信息以及时间控制信息 $updateftp=true; $g6=new G6ftp(); $g6->db=$this->db; //不进行判断,每个元数据中的下载地址都对应一个虚拟路径 $path[]=$data['path']; $this->view->username='westdc'.$userid; $uu=(object)array("id"=>$userid, "username"=>$this->view->username, "password"=>$this->view->userpass, "path"=>$path, "maxdata"=>$this->view->config->download->max, "time"=>$this->view->ftptime, "datacount"=>$datacount); if ($g6->createuser($uu)) { $this->view->userpass=$g6->pwd; $this->view->ftptime=$g6->time; } else { $this->messenger->addMessage('Error: You are downloading too much data now.'); $this->_redirect('/data/order'); } } elseif ($data['host']=='ftp1.westgis.ac.cn') { //添加FTP1帐号信息以及时间控制信息 $proftp=new Proftp(); $proftp->db=$this->db; //proftp离线用户名和g6的用户名稍有不同 $this->view->username='westdc_'.$userid; $uu=(object)array("id"=>$userid, "username"=>$this->view->username, "password"=>$this->view->userpass, "host"=>'ftp1.westgis.ac.cn', "param"=>"onlineappid=".$onlineappid, "maxdata"=>$this->view->config->download->max, "time"=>$this->view->ftptime, "datacount"=>$datacount); if ($proftp->createuser($uu)) { $this->view->userpass=$proftp->pwd; $this->view->ftptime=$proftp->time; } } elseif ($data['host']=='ftp2.westgis.ac.cn'){ //添加FTP2帐号信息以及时间控制信息 $proftp=new Pureftp(); $proftp->db=$this->db; $this->view->username='westdc_'.$userid; $uu=(object)array("id"=>$userid, "username"=>$this->view->username, "password"=>$this->view->userpass, "host"=>'ftp2.westgis.ac.cn', "param"=>"onlineappid=".$onlineappid, "maxdata"=>$this->view->config->download->max, "time"=>$this->view->ftptime, "datacount"=>$datacount); if ($proftp->createuser($uu)) { $this->view->userpass=$proftp->pwd; $this->view->ftptime=$proftp->time; } } $ftpurl='ftp://'.$this->view->username.'@'.$data['host']; if ($data['host']=='ftp.westgis.ac.cn') $ftpurl.=$data['path'];
//设置输出 //if ($updateftp || $updateftp1) $this->view->userpass=$password; $this->view->ftpurl=$ftpurl; //更新下载记录 //todo: 尝试添加一个RULE若有对应数据存在则不插入 userid,uuid,status=0,ts_approved:null) /*$sql="select * from dataorder where userid=? and uuid=? and status=0 and (ts_approved is null)"; $u=$this->db->fetchRow($sql,array($userid,$uuid));
if (empty($u)) { $sql="insert into dataorder (userid,uuid,ts_created) values(?,?,now())"; $this->db->query($sql,array($userid,$uuid)); }*/
if (!empty($ftpurl) && !$has_send_mail) { $data = array( "uuid"=>$uuid, "title"=>$this->view->md['title']."(".$this->view->md['filesize']."MB)", "user"=>$user->username, "ftpuser"=>$this->view->username, "ftppwd"=>$this->view->userpass, "ftptime"=>$this->view->ftptime, "ftpurl"=>$this->view->ftpurl, "note"=>$updateftp?'BTW: You need to enter the path mannually.':'' );
$mailtp=new EmailText($this->db,'online-download-en',$data); $mail=new WestdcMailer($this->view->config->smtp); $mail->setBodyText($mailtp->getBody()); $mail->setFrom($this->view->config->service->email,'CARD data service'); $mail->addTo($user->email); $mail->setSubject($mailtp->getSubject()); @$mail->send();
$sql="update onlineapp set has_send_mail=true where id=?"; $sth=$this->db->prepare($sql); $sth->execute(array($onlineappid)); } }
/*
* 离线申请(可以包括在线数据),在无数据参数时,则显示已有列表
*/