#308 修改了数据新闻部分的添加和列表

This commit is contained in:
Li Jianxuan 2012-03-26 07:53:08 +00:00
parent 5a4bd79d26
commit a48f10b8a0
2 changed files with 150 additions and 68 deletions

View File

@ -1154,7 +1154,11 @@ class AuthorController extends Zend_Controller_Action
if(empty($ac) || $ac=="list")
{
$keyword = $this->_request->getParam('q');
$uuid = $this->_request->getParam('uuid');
$wheresql = "";
$join = "";
if(!empty($keyword))
{
$this->view->q = $keyword;
@ -1164,18 +1168,24 @@ class AuthorController extends Zend_Controller_Action
if(!empty($wheresql))
{
$wheresql = " WHERE ".$wheresql;
$wheresql = " AND ".$wheresql;
}
if(!empty($uuid) && preg_match("/^[0-9A-Za-z]{8}-[0-9A-Za-z]{4}-[0-9A-Za-z]{4}-[0-9A-Za-z]{4}-[0-9A-Za-z]{12}$/",$uuid))
{
$join = "LEFT JOIN news_mdnews mdnews ON mdnews.aid=arc.id";
$wheresql .= " AND mdnews.uuid='$uuid'";
}
$sql = "SELECT arc.id,arc.title,arc.ts_publish,arc.description,u.realname FROM news_archives arc
LEFT JOIN users u ON arc.userid=u.id
$wheresql
$join
WHERE arc.is_pub>0 AND arc.ts_publish<'now()' $wheresql
ORDER BY arc.ts_publish";
$sth = $this->db->prepare($sql);
$sth->execute();
$rows = $sth->fetchAll();
$paginator = Zend_Paginator::factory($rows);
@ -1217,6 +1227,16 @@ class AuthorController extends Zend_Controller_Action
if($ac == "add")
{
$this->_helper->viewRenderer('news-add');
$sql = "SELECT md.title,md.uuid FROM metadata md
LEFT JOIN mdauthor a ON a.uuid = md.uuid
WHERE a.userid=?
";
$sth = $this->db->prepare($sql);
$sth->execute(array($u_id));
$rows = $sth->fetchAll();
$this->view->md = $rows;
}// $ac == add
//新闻编辑
@ -1231,14 +1251,16 @@ class AuthorController extends Zend_Controller_Action
$this->_redirect('/error/error');
}
$sql = "SELECT * FROM news_archives WHERE id=?";
$sql = "SELECT arc.*,mdarc.uuid FROM news_archives arc
LEFT JOIN news_mdnews mdarc ON mdarc.aid = arc.id
WHERE id=?";
$sth = $this->db->prepare($sql);
$sth->execute(array($aid));
$row = $sth->fetch();
$this->view->info = $row;
}
}//$ac == "edit"
//新闻发布的ajax动作
if($ac =="addnews")
@ -1253,6 +1275,7 @@ class AuthorController extends Zend_Controller_Action
$data['title'] = trim($this->_request->getParam('title'));
$data['keyword'] = trim($this->_request->getParam('keyword'));
$data['body'] = trim($this->_request->getParam('body'));
$uuid = trim($this->_request->getParam('uuid'));
//对参数进行预处理
foreach($data as $k=>$v)
@ -1283,6 +1306,14 @@ class AuthorController extends Zend_Controller_Action
return true;
}
if(empty($uuid))
{
$msg['status'] = 0;
$msg['error'] = '请选择对应数据';
$this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(Zend_Json::encode($msg));
return true;
}
if(mb_strlen($data['keyword'],"utf-8")<4)
{
$msg['status'] = 0;
@ -1307,6 +1338,14 @@ class AuthorController extends Zend_Controller_Action
return true;
}
if(!preg_match("/^[0-9A-Za-z]{8}-[0-9A-Za-z]{4}-[0-9A-Za-z]{4}-[0-9A-Za-z]{4}-[0-9A-Za-z]{12}$/",$uuid))
{
$msg['status'] = 0;
$msg['error'] = '参数错误,请重试';
$this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(Zend_Json::encode($msg));
return true;
}
//获得描述
//删除段落及html标记
$data['description'] = mb_substr(preg_replace(array("/<(.*)>|<(.*) \/>/i","/\s/i"),array(""," "),$data['body']),0,450,"UTF-8");
@ -1317,43 +1356,73 @@ class AuthorController extends Zend_Controller_Action
$data['userid'] = $u_id;
$data['keyword'] = str_replace("",",",$data['keyword']);
//新闻添加
if(empty($aid))
{
$sql = "INSERT INTO news_archives
(userid,title,keywords,description,image,source,ts_publish,is_pub,body)
VALUES
(?,?,?,?,?,?,?,?,?)
RETURNING id
";
$sth = $this->db->prepare($sql);
$ex = $sth -> execute(array($data['userid'],$data['title'],$data['keyword'],$data['description'],'',$data['source'],'now()',1,$data['body']));
}
//添加成功
if($ex)
{
//写入文章ID对应UUID的表
$archive = $sth->fetch(PDO::FETCH_ASSOC);
$aid = $archive['id'];
$sql = "INSERT INTO news_mdnews (aid,uuid) VALUES (?,?)";
$sth = $this->db->prepare($sql);
$uuidex = $sth->execute(array($aid,$uuid));
if($uuidex)
{
$msg['status'] = 1;
$msg['outstring'] = "新闻添加成功";
$this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(Zend_Json::encode($msg));
return true;
}else{
$sql = "DELETE FROM news_archives WHERE id=$aid";
@$this->db->exec($sql); //如果新闻添加失败就删除原新闻,否则产生重复错误
$msg['status'] = 0;
$msg['error'] = "新闻添加失败,请重试";
$this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(Zend_Json::encode($msg));
return true;
}
//添加失败
}else{
$msg['status'] = 0;
$msg['error'] = "新闻添加失败,请重试";
$this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(Zend_Json::encode($msg));
return true;
}
}//新闻添加 end -->
//新闻修改
else
{
$sql = "UPDATE news_archives SET title=?,keywords=?,description=?,body=? WHERE id=? AND userid=?";
$sth = $this->db->prepare($sql);
$ex = $sth -> execute(array($data['title'],$data['keyword'],$data['description'],$data['body'],$aid,$data['userid']));
}
if($ex)
{
$msg['status'] = 1;
$msg['outstring'] = "新闻编辑成功";
$this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(Zend_Json::encode($msg));
return true;
}else{
$msg['status'] = 0;
$msg['outstring'] = "新闻编辑失败,请重试";
$this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(Zend_Json::encode($msg));
return true;
}
}//新闻修改 end -->
if($ex)
{
$msg['status'] = 1;
if(empty($aid))
{$msg['outstring'] = "新闻添加成功";}
else
{$msg['outstring'] = "新闻编辑成功";}
$this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(Zend_Json::encode($msg));
return true;
}else{
$msg['status'] = 0;
if(empty($aid))
{$msg['error'] = "新闻添加失败,请重试";}
else
{$msg['outstring'] = "新闻编辑失败,请重试";}
$this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(Zend_Json::encode($msg));
return true;
}
}catch(Exception $e){
if($this->debug==0)
{
@ -1370,10 +1439,8 @@ class AuthorController extends Zend_Controller_Action
$this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(Zend_Json::encode($msg));
return true;
}
}
}
}//catch end
}//$ac = 'newsadd' endif;
}//newsAction() 数据新闻

View File

@ -36,12 +36,28 @@ $this->breadcrumb()->setSeparator(' > ');
<legend>新闻信息</legend>
<input type="hidden" id="image" class="half title" value="" name="image"/>
<p>
<label class="required" for="producttitle">标题</label><br/>
<input type="text" id="producttitle" class="half" value="" name="title" maxlength="100"/>
<label class="required" for="archivetitle">标题</label><br/>
<input type="text" id="archivetitle" class="half" value="" name="title" maxlength="100"/>
<small>请准确概况新闻内容</small>
</p>
<p>
<label class="required" for="producttitle">标签</label><br/>
<label class="required" for="data">相关数据</label><br/>
<select id="data" name="uuid">
<option value="0">请选择相关数据</option>
<?php
if(!empty($this->md))
{
foreach($this->md as $v)
{
echo '<option value="'.$v['uuid'].'">'.$v['title'].'</option>';
}
}
?>
</select>
<small>从数据中选择一条</small>
</p>
<p>
<label class="required" for="tag">标签</label><br/>
<input type="text" id="keyword" class="half" value="" name="keyword"/>
<small>使用半角逗号“,”隔开,如 (冻土,冰川)</small>
</p>
@ -49,7 +65,6 @@ $this->breadcrumb()->setSeparator(' > ');
<label for="body">新闻内容</label><br/>
<textarea id="body" class="large full" name="body"></textarea>
</p>
<p class="box"><input type="button" onclick="addon();" id="submit" class="btn btn-green big" value="提交"/> or <input type="reset" class="btn" value="重置" onclick="return confirm('确实要抛弃已经填写内容?');"/></p>
<div id="return"></div>
</fieldset>