实现了ticket #62的功能:对离线服务记录的手工添加、编辑和删除功能。

修复数据库中offlineapp表id不自动增长的问题:select 
setval('offlineapp_id_seq',max(id)) from offlineapp;
This commit is contained in:
wlx 2009-03-10 08:31:01 +00:00
parent 1ad1451c4d
commit 231f334acd
5 changed files with 140 additions and 3 deletions

View File

@ -107,6 +107,68 @@ class Admin_DataController extends Zend_Controller_Action
//离线数据服务记录
function offlineAction()
{
$add=(int)$this->_getParam('add');
$edit=(int)$this->_getParam('edit');
$delete=(int)$this->_getParam('delete');
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_approved) values(?,?,?,?,?,?,?,?,?,?)";
$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/data/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/data/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/data/offline");
}
$select=$this->db->select();
$select->from('offlineapp')->where('ts_approved is not null')->where('pdflink is not null')->order('id desc');
$paginator = Zend_Paginator::factory($select);

View File

@ -22,7 +22,7 @@
<?php endforeach;endif; ?>
</div>
<?php endif; ?>
<?= $this->paginator; ?><a href="/admin/data/datasetcd/add/1">添加新的特色数据集</a>
<a href="/admin/data/datasetcd/add/1">添加新的特色数据集</a><?= $this->paginator; ?>
<?php if (count($this->paginator)): ?>
<div id="datasetcd">
<?php foreach ($this->paginator as $item): ?>

View File

@ -13,7 +13,6 @@
<?= $this->partial('data/left.phtml'); ?>
</div>
<div id="rightPanel">
<?= $this->paginator; ?>
<?php if ($this->msg or $this->messages) :?>
<div id="message">
<?php if ($this->msg) : ?>
@ -23,6 +22,8 @@
<?php endforeach;endif; ?>
</div>
<?php endif; ?>
<a href="/admin/data/offline/add/1">添加新的离线服务记录</a>
<?= $this->paginator; ?>
<?php if (count($this->paginator)): ?>
<table class="offline" cellspacing=0>
<thead><tr>
@ -45,7 +46,7 @@
<td><?= $item['datalist']; ?></td>
<td class="ts"><?= date('Y-m-d',strtotime($item['ts_created'])); ?></td>
<td class="action">
<a href="/admin/data/offline/view/<?= $item['userid']; ?>">查看</a></td>
<a href="/admin/data/offline/edit/<?= $item['id']; ?>">编辑</a> | <a href="/admin/data/offline/delete/<?= $item['id']; ?>">删除</a></td>
</tr>
<?php endforeach; ?>
</tbody></table>

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/data">数据管理</a>');
$this->breadcrumb('离线数据服务记录管理</a>');
$this->breadcrumb()->setSeparator(' > ');
?>
<div id="leftPanel">
<?= $this->partial('data/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/data/offline/add/1">添加新的离线服务记录</a>
<?= $this->form; ?>
</div>

View File

@ -0,0 +1,47 @@
<?php
class OfflinelogForm extends Zend_Form
{
public function __construct($options = null)
{
parent::__construct($options);
$this->setName('OfflinePdf');
$email=new Zend_Form_Element_Text('email');
$email->setLabel('E-Mail')
->addFilter('StringTrim')
->addValidator('NotEmpty')
->addValidator('EmailAddress');
$username=new Zend_Form_Element_Text('username');
$username->setLabel('真实姓名')->setRequired(true);
$phone=new Zend_Form_Element_Text('phone');
$phone->setLabel('电话')->setRequired(true);
$unit=new Zend_Form_Element_Text('unit');
$unit->setLabel('单位')->setRequired(true);
$postcode=new Zend_Form_Element_Text('postcode');
$postcode->setLabel('邮编')->setRequired(true);
$address=new Zend_Form_Element_Text('address');
$address->setLabel('联系地址')->setRequired(true);
$project=new Zend_Form_Element_Textarea('project');
$project->setLabel('用途')->setRequired(true)->setAttrib('rows',2);
$datalist=new Zend_Form_Element_Textarea('datalist');
$datalist->setLabel('数据清单')->setRequired(true)->setAttrib('rows',2);
$pdf=new Zend_Form_Element_File('pdf');
$pdf->setLabel('离线服务记录PDF')
->setRequired(true)
//->setDestination('../data/offlineapp')
->addValidator('Count', false, 1) // ensure only 1 file
->addValidator('Size', false, 1024000) // limit to 1M
->addValidator('Extension', false, 'pdf,doc'); // only JPEG, PNG, and GIFs
$ts_approved=new Zend_Form_Element_Text('ts_approved');
$ts_approved->setLabel('申请时间(格式2008-12-20)')->setRequired(true);
$id = new Zend_Form_Element_Hidden('id');
$submit = new Zend_Form_Element_Submit('submit');
$submit->setAttrib('id', 'submitbutton')->setLabel('添加');
$this->setAttrib('enctype', 'multipart/form-data');
$this->addElements(array($username,$email,$phone,$unit,$address,$postcode,$pdf,$ts_approved,$project,$datalist,$id,$submit));
}
}