建立了专门的申请处理模块

This commit is contained in:
wlx 2010-11-08 02:15:39 +00:00
parent 84c5528da4
commit 455911951d
8 changed files with 397 additions and 47 deletions

View File

@ -116,53 +116,6 @@ class Admin_DataController extends Zend_Controller_Action
$this->view->msg='已成功同步管理员帐号!';
}
}
//离线数据申请管理
function offlineappAction()
{
$view=(int)$this->_getParam('view');
$start=(int)$this->_getParam('start');
$finish=(int)$this->_getParam('finish');
$cancel=(int)$this->_getParam('cancel');
if ($view) {
//查看此次申请的具体内容,包括指向的地址
} elseif ($start) {
$sql="update dataorder set status=4 where status=3 and userid=?";
$this->db->query($sql,array($start));
//提示信息
$this->messenger->addMessage('提示信息:该离线数据已经开始处理,请在处理完成后点击“完成”。');
$this->_redirect('/admin/data/offlineapp');
} elseif ($finish) {
try {
$sql="update dataorder set status=5,ts_approved=now() where status=4 and userid=?";
$this->db->query($sql,array($finish));
$sql="update offlineapp set ts_approved=now() where userid=? and ts_approved is null";
$this->db->query($sql,array($finish));
$this->messenger->addMessage('提示信息:该离线数据已经处理完成。');
} catch (Exception $e) {
//提示信息
$this->messenger->addMessage($e->getMessage());
$this->messenger->addMessage('提示信息:该数据有可能还没有开始处理,请先开始。');
}
$this->_redirect('/admin/data/offlineapp');
} elseif ($cancel) {
//取消=删除?
//需谨慎操作
$sql="update dataorder set status=-1 where (status=3 or status=4) and userid=?";
$this->db->query($sql,array($cancel));
$sql="delete from offlineapp where id=?";
$this->db->query($sql,array($cancel));
$this->messenger->addMessage('提示信息:已取消该用户离线申请。');
$this->_redirect('/admin/data/offlineapp');
}
$select=$this->db->select();
$select->from('offlineapp')->where('ts_approved is null')->where('pdflink is not null')->order('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;
}
//离线数据服务记录
function offlineAction()
{

View File

@ -0,0 +1,236 @@
<?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');
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));
//发送用户邮件进行信息提示和说明
$mail = new WestdcMailer($this->view->config->smtp);
$body=file_get_contents($this->view->config->offline->email->start_template);
$body=str_replace("[username]",$row['username'],$body);
$body=str_replace("[datalist]",str_replace(";","\n",$row['datalist']),$body);
$mail->setBodyText($body);
$mail->addTo($row['email']);
$mail->setSubject('西部数据中心已收到您的纸质离线申请');
$mail->addHeader('Reply-To', $this->view->config->service->email);
$mail->setFrom($this->view->config->service->email,'西部数据中心服务组');
$mail->send();
//提示信息
$this->messenger->addMessage('提示信息:该离线数据已经开始处理,请在处理完成后点击“完成”。');
$this->_redirect('/admin/down/offlineapp/'.$page);
} elseif ($finish) {
try {
$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);
$body=file_get_contents($this->view->config->offline->email->finish_template);
$body=str_replace("[username]",$row['username'],$body);
$body=str_replace("[datalist]",str_replace(";","\n",$row['datalist']),$body);
$body=str_replace("[ftpuser]",$user->username,$body);
$body=str_replace("[ftppwd]",$proftp->pwd,$body);
$body=str_replace("[ftptime]",$proftp->time,$body);
$mail->setBodyText($body);
$mail->addTo($row['email']);
$mail->setSubject('西部数据中心已开通了您的离线申请');
$mail->addHeader('Reply-To', $this->view->config->service->email);
$mail->setFrom($this->view->config->service->email,'西部数据中心服务组');
$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) {
//todo
}
$select=$this->db->select();
$select->from('offlineapp')->where('ts_approved is null')->where('pdflink is not null')->order('ts_created desc');
$paginator = Zend_Paginator::factory($select);
$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');
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('提示信息:您已经编辑添加该记录。');
$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=?";
try {
$this->db->query($sql,array($delete));
$this->messenger->addMessage('提示信息:您已经成功删除该服务记录。');
} catch (Exception $e) {
$this->messenger->addMessage($e->getMessage());
}
$this->_redirect("/admin/down/offline");
} elseif ($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'].'","'.$row['project'].'","'.$row['datalist'].'","'.$row['email'].'",'.$row['ts_approved']."\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);
}
$select=$this->db->select();
$select->from('offlineapp')->where('ts_approved is not null')->where('pdflink is not null')->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;
}
}

View File

@ -0,0 +1,18 @@
<?php
$this->headTitle($this->config->title->site);
$this->headTitle('后台管理');
$this->headTitle()->setSeparator(' - ');
$this->headLink()->appendStylesheet('/css/admin.css');
$this->breadcrumb('<a href="/">首页</a>');
$this->breadcrumb('<a href="/admin">后台首页</a>');
$this->breadcrumb('申请管理');
$this->breadcrumb()->setSeparator(' > ');
?>
<div id="divContent">
<div id="leftPanel">
<?= $this->partial('down/left.phtml'); ?>
</div>
<div id="rightPanel">
</div>
</div>

View File

@ -0,0 +1,5 @@
<ul>
<li><a href="/admin/data/comment">数据反馈管理</a></li>
<li><a href="/admin/down/offlineapp">离线数据申请管理</a></li>
<li><a href="/admin/down/offline">离线数据服务记录</a></li>
</ul>

View File

@ -0,0 +1,54 @@
<?php
$this->headTitle($this->config->title->site);
$this->headTitle('后台管理');
$this->headTitle()->setSeparator(' - ');
$this->headLink()->appendStylesheet('/css/admin.css');
$this->breadcrumb('<a href="/">首页</a>');
$this->breadcrumb('<a href="/admin">后台首页</a>');
$this->breadcrumb('<a href="/admin/down">申请管理</a>');
$this->breadcrumb('离线数据申请管理</a>');
$this->breadcrumb()->setSeparator(' > ');
?>
<div id="leftPanel">
<?= $this->partial('down/left.phtml'); ?>
</div>
<div id="rightPanel">
<?php if ($this->msg or $this->messages) :?>
<div id="message">
<?php if ($this->msg) : ?>
<p><?php echo $this->msg; ?></p>
<?php endif; if ($this->messages): foreach($this->messages as $msg): ?>
<p><?php echo $msg; ?></p>
<?php endforeach;endif; ?>
</div>
<?php endif; ?>
<a href="/admin/down/offline/add/1">添加新的离线服务记录</a> | <a href="/admin/down/offline/down/1">下载所有离线服务记录</a>
<?= $this->paginator; ?>
<?php if (count($this->paginator)): ?>
<table class="offline" cellspacing=0>
<thead><tr>
<th id="name">姓名</th>
<th id="unit">单位</th>
<th id="addr">地址</th>
<th id="postcode">邮编</th>
<th id="project">用途</th>
<th id="datalist">数据清单</th>
<th id="ts">申请时间</th>
<th id="name">操作</th>
</tr></thead>
<tbody>
<?php foreach ($this->paginator as $item): ?>
<tr><td class="name"><?= $item['username']; ?></td>
<td class="unit"><?= $item['unit']; ?></td>
<td class="addr"><?= $item['address']; ?></td>
<td class="postcode"><?= $item['postcode']; ?></td>
<td class="project"><?= $item['project']; ?></td>
<td><?= $item['datalist']; ?></td>
<td class="ts"><?= date('Y-m-d',strtotime($item['ts_created'])); ?></td>
<td class="action">
<a href="/admin/down/offline/edit/<?= $item['id']; ?>">编辑</a> | <a href="/admin/down/offline/delete/<?= $item['id']; ?>">删除</a></td>
</tr>
<?php endforeach; ?>
</tbody></table>
<?php endif; ?>
</div>

View File

@ -0,0 +1,27 @@
<?php
$this->headTitle($this->config->title->site);
$this->headTitle('后台管理');
$this->headTitle()->setSeparator(' - ');
$this->headLink()->appendStylesheet('/css/admin.css');
$this->breadcrumb('<a href="/">首页</a>');
$this->breadcrumb('<a href="/admin">后台首页</a>');
$this->breadcrumb('<a href="/admin/down">申请管理</a>');
$this->breadcrumb('离线数据服务记录管理</a>');
$this->breadcrumb()->setSeparator(' > ');
?>
<div id="leftPanel">
<?= $this->partial('down/left.phtml'); ?>
</div>
<div id="rightPanel">
<?php if ($this->msg or $this->messages) :?>
<div id="message">
<?php if ($this->msg) : ?>
<p><?php echo $this->msg; ?></p>
<?php endif; if ($this->messages): foreach($this->messages as $msg): ?>
<p><?php echo $msg; ?></p>
<?php endforeach;endif; ?>
</div>
<?php endif; ?>
<a href="/admin/down/offline/add/1">添加新的离线服务记录</a>
<?= $this->form; ?>
</div>

View File

@ -0,0 +1,56 @@
<?php
$this->headTitle($this->config->title->site);
$this->headTitle('后台管理');
$this->headTitle()->setSeparator(' - ');
$this->headLink()->appendStylesheet('/css/admin.css');
$this->breadcrumb('<a href="/">首页</a>');
$this->breadcrumb('<a href="/admin">后台首页</a>');
$this->breadcrumb('<a href="/admin/down">申请管理</a>');
$this->breadcrumb('离线数据申请管理</a>');
$this->breadcrumb()->setSeparator(' > ');
?>
<div id="leftPanel">
<?= $this->partial('down/left.phtml'); ?>
</div>
<div id="rightPanel">
<?= $this->paginator; ?>
<?php if ($this->msg or $this->messages) :?>
<div id="message">
<?php if ($this->msg) : ?>
<p><?php echo $this->msg; ?></p>
<?php endif; if ($this->messages): foreach($this->messages as $msg): ?>
<p><?php echo $msg; ?></p>
<?php endforeach;endif; ?>
</div>
<?php endif; ?>
<?php if (count($this->paginator)): ?>
<table class="offline" cellspacing=0>
<thead><tr>
<th id="name">姓名</th>
<th id="unit">单位</th>
<th id="addr">地址</th>
<th id="postcode">邮编</th>
<th id="project">用途</th>
<th id="datalist">数据清单</th>
<th id="ts">申请时间</th>
<th id="name">操作</th>
</tr></thead>
<tbody>
<?php foreach ($this->paginator as $item): ?>
<tr><td class="name"><a href="/admin/down/offlineapp/view/<?= $item['id']; ?>"><?= $item['username']; ?></a></td>
<td class="unit"><?= $item['unit']; ?></td>
<td class="addr"><?= $item['address']; ?></td>
<td class="postcode"><?= $item['postcode']; ?></td>
<td class="project"><?= $item['project']; ?></td>
<td><?= $item['datalist']; ?></td>
<td class="ts"><?= date('Y-m-d',strtotime($item['ts_created'])); ?></td>
<td class="action">
<a href="/admin/down/offlineapp/start/<?= $item['id']; ?>">收到</a>
<a href="/admin/down/offlineapp/finish/<?= $item['id']; ?>">通过</a>
<a href="/admin/down/offlineapp/cancel/<?= $item['id']; ?>">取消</a>
<a href="/admin/down/offlineapp/deny/<?= $item['id']; ?>">未通过</a></td>
</tr>
<?php endforeach; ?>
</tbody></table>
<?php endif; ?>
</div>

View File

@ -7,6 +7,7 @@
<li><a href="/"><span>网站首页</span></a></li>
<li><a href="/admin"><span>后台首页</span></a></li>
<li><a href="/admin/data"><span>数据管理</span></a></li>
<li><a href="/admin/down"><span>申请管理</span></a></li>
<li><a href="/admin/account"><span>用户管理</span></a></li>
<li><a href="/admin/stat"><span>统计数据</span></a></li>