#308 修改了数据新闻部分的添加和列表
This commit is contained in:
parent
5a4bd79d26
commit
a48f10b8a0
|
@ -1154,7 +1154,11 @@ class AuthorController extends Zend_Controller_Action
|
||||||
if(empty($ac) || $ac=="list")
|
if(empty($ac) || $ac=="list")
|
||||||
{
|
{
|
||||||
$keyword = $this->_request->getParam('q');
|
$keyword = $this->_request->getParam('q');
|
||||||
|
$uuid = $this->_request->getParam('uuid');
|
||||||
|
|
||||||
$wheresql = "";
|
$wheresql = "";
|
||||||
|
$join = "";
|
||||||
|
|
||||||
if(!empty($keyword))
|
if(!empty($keyword))
|
||||||
{
|
{
|
||||||
$this->view->q = $keyword;
|
$this->view->q = $keyword;
|
||||||
|
@ -1164,18 +1168,24 @@ class AuthorController extends Zend_Controller_Action
|
||||||
|
|
||||||
if(!empty($wheresql))
|
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
|
$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
|
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";
|
ORDER BY arc.ts_publish";
|
||||||
|
|
||||||
|
|
||||||
$sth = $this->db->prepare($sql);
|
$sth = $this->db->prepare($sql);
|
||||||
$sth->execute();
|
$sth->execute();
|
||||||
|
|
||||||
$rows = $sth->fetchAll();
|
$rows = $sth->fetchAll();
|
||||||
|
|
||||||
$paginator = Zend_Paginator::factory($rows);
|
$paginator = Zend_Paginator::factory($rows);
|
||||||
|
@ -1217,6 +1227,16 @@ class AuthorController extends Zend_Controller_Action
|
||||||
if($ac == "add")
|
if($ac == "add")
|
||||||
{
|
{
|
||||||
$this->_helper->viewRenderer('news-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
|
}// $ac == add
|
||||||
|
|
||||||
//新闻编辑
|
//新闻编辑
|
||||||
|
@ -1231,14 +1251,16 @@ class AuthorController extends Zend_Controller_Action
|
||||||
$this->_redirect('/error/error');
|
$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 = $this->db->prepare($sql);
|
||||||
$sth->execute(array($aid));
|
$sth->execute(array($aid));
|
||||||
$row = $sth->fetch();
|
$row = $sth->fetch();
|
||||||
|
|
||||||
$this->view->info = $row;
|
$this->view->info = $row;
|
||||||
|
|
||||||
}
|
}//$ac == "edit"
|
||||||
|
|
||||||
//新闻发布的ajax动作
|
//新闻发布的ajax动作
|
||||||
if($ac =="addnews")
|
if($ac =="addnews")
|
||||||
|
@ -1253,6 +1275,7 @@ class AuthorController extends Zend_Controller_Action
|
||||||
$data['title'] = trim($this->_request->getParam('title'));
|
$data['title'] = trim($this->_request->getParam('title'));
|
||||||
$data['keyword'] = trim($this->_request->getParam('keyword'));
|
$data['keyword'] = trim($this->_request->getParam('keyword'));
|
||||||
$data['body'] = trim($this->_request->getParam('body'));
|
$data['body'] = trim($this->_request->getParam('body'));
|
||||||
|
$uuid = trim($this->_request->getParam('uuid'));
|
||||||
|
|
||||||
//对参数进行预处理
|
//对参数进行预处理
|
||||||
foreach($data as $k=>$v)
|
foreach($data as $k=>$v)
|
||||||
|
@ -1283,6 +1306,14 @@ class AuthorController extends Zend_Controller_Action
|
||||||
return true;
|
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)
|
if(mb_strlen($data['keyword'],"utf-8")<4)
|
||||||
{
|
{
|
||||||
$msg['status'] = 0;
|
$msg['status'] = 0;
|
||||||
|
@ -1307,6 +1338,14 @@ class AuthorController extends Zend_Controller_Action
|
||||||
return true;
|
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标记
|
//删除段落及html标记
|
||||||
$data['description'] = mb_substr(preg_replace(array("/<(.*)>|<(.*) \/>/i","/\s/i"),array(""," "),$data['body']),0,450,"UTF-8");
|
$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['userid'] = $u_id;
|
||||||
$data['keyword'] = str_replace(",",",",$data['keyword']);
|
$data['keyword'] = str_replace(",",",",$data['keyword']);
|
||||||
|
|
||||||
|
//新闻添加
|
||||||
if(empty($aid))
|
if(empty($aid))
|
||||||
{
|
{
|
||||||
$sql = "INSERT INTO news_archives
|
$sql = "INSERT INTO news_archives
|
||||||
(userid,title,keywords,description,image,source,ts_publish,is_pub,body)
|
(userid,title,keywords,description,image,source,ts_publish,is_pub,body)
|
||||||
VALUES
|
VALUES
|
||||||
(?,?,?,?,?,?,?,?,?)
|
(?,?,?,?,?,?,?,?,?)
|
||||||
|
RETURNING id
|
||||||
";
|
";
|
||||||
$sth = $this->db->prepare($sql);
|
$sth = $this->db->prepare($sql);
|
||||||
$ex = $sth -> execute(array($data['userid'],$data['title'],$data['keyword'],$data['description'],'',$data['source'],'now()',1,$data['body']));
|
$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
|
else
|
||||||
{
|
{
|
||||||
$sql = "UPDATE news_archives SET title=?,keywords=?,description=?,body=? WHERE id=? AND userid=?";
|
$sql = "UPDATE news_archives SET title=?,keywords=?,description=?,body=? WHERE id=? AND userid=?";
|
||||||
$sth = $this->db->prepare($sql);
|
$sth = $this->db->prepare($sql);
|
||||||
$ex = $sth -> execute(array($data['title'],$data['keyword'],$data['description'],$data['body'],$aid,$data['userid']));
|
$ex = $sth -> execute(array($data['title'],$data['keyword'],$data['description'],$data['body'],$aid,$data['userid']));
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if($ex)
|
if($ex)
|
||||||
{
|
{
|
||||||
$msg['status'] = 1;
|
$msg['status'] = 1;
|
||||||
if(empty($aid))
|
$msg['outstring'] = "新闻编辑成功";
|
||||||
{$msg['outstring'] = "新闻添加成功";}
|
|
||||||
else
|
|
||||||
{$msg['outstring'] = "新闻编辑成功";}
|
|
||||||
$this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(Zend_Json::encode($msg));
|
$this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(Zend_Json::encode($msg));
|
||||||
return true;
|
return true;
|
||||||
}else{
|
}else{
|
||||||
$msg['status'] = 0;
|
$msg['status'] = 0;
|
||||||
if(empty($aid))
|
$msg['outstring'] = "新闻编辑失败,请重试";
|
||||||
{$msg['error'] = "新闻添加失败,请重试";}
|
|
||||||
else
|
|
||||||
{$msg['outstring'] = "新闻编辑失败,请重试";}
|
|
||||||
$this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(Zend_Json::encode($msg));
|
$this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(Zend_Json::encode($msg));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
}//新闻修改 end -->
|
||||||
|
|
||||||
}catch(Exception $e){
|
}catch(Exception $e){
|
||||||
if($this->debug==0)
|
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));
|
$this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(Zend_Json::encode($msg));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}//catch end
|
||||||
|
}//$ac = 'newsadd' endif;
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}//newsAction() 数据新闻
|
}//newsAction() 数据新闻
|
||||||
|
|
|
@ -36,12 +36,28 @@ $this->breadcrumb()->setSeparator(' > ');
|
||||||
<legend>新闻信息</legend>
|
<legend>新闻信息</legend>
|
||||||
<input type="hidden" id="image" class="half title" value="" name="image"/>
|
<input type="hidden" id="image" class="half title" value="" name="image"/>
|
||||||
<p>
|
<p>
|
||||||
<label class="required" for="producttitle">标题</label><br/>
|
<label class="required" for="archivetitle">标题</label><br/>
|
||||||
<input type="text" id="producttitle" class="half" value="" name="title" maxlength="100"/>
|
<input type="text" id="archivetitle" class="half" value="" name="title" maxlength="100"/>
|
||||||
<small>请准确概况新闻内容</small>
|
<small>请准确概况新闻内容</small>
|
||||||
</p>
|
</p>
|
||||||
<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"/>
|
<input type="text" id="keyword" class="half" value="" name="keyword"/>
|
||||||
<small>使用半角逗号“,”隔开,如 (冻土,冰川)</small>
|
<small>使用半角逗号“,”隔开,如 (冻土,冰川)</small>
|
||||||
</p>
|
</p>
|
||||||
|
@ -49,7 +65,6 @@ $this->breadcrumb()->setSeparator(' > ');
|
||||||
<label for="body">新闻内容</label><br/>
|
<label for="body">新闻内容</label><br/>
|
||||||
<textarea id="body" class="large full" name="body"></textarea>
|
<textarea id="body" class="large full" name="body"></textarea>
|
||||||
</p>
|
</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>
|
<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>
|
<div id="return"></div>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
|
Loading…
Reference in New Issue