#308 修改了数据新闻部分的添加和列表
This commit is contained in:
parent
5a4bd79d26
commit
a48f10b8a0
|
@ -76,16 +76,16 @@ class AuthorController extends Zend_Controller_Action
|
|||
$sql = "SELECT o.id,o.userid,o.unit,o.username,o.ts_created,o.project,m.title,m.uuid FROM onlineapp as o
|
||||
LEFT JOIN metadata as m ON o.uuid=m.uuid
|
||||
LEFT JOIN mdauthor as a ON a.uuid=o.uuid
|
||||
WHERE (o.id in (SELECT distinct(onlineappid) from dataorder where status>=0)) AND a.userid = ? AND a.status=1 ";
|
||||
if ($ac=="searchonline")
|
||||
WHERE (o.id in (SELECT distinct(onlineappid) from dataorder where status>=0)) AND a.userid = ? AND a.status=1 ";
|
||||
if ($ac=="searchonline")
|
||||
{
|
||||
$keywords = $this->_request->getParam('q');
|
||||
if(!empty($keywords))
|
||||
$this->view->q = $keywords;
|
||||
$search=new Search($keywords);
|
||||
$where=$search->sql_expr(array("m.title","m.description"));
|
||||
$sql.=' and '.$where;
|
||||
}
|
||||
$search=new Search($keywords);
|
||||
$where=$search->sql_expr(array("m.title","m.description"));
|
||||
$sql.=' and '.$where;
|
||||
}
|
||||
$sql.=" ORDER BY o.id desc";
|
||||
|
||||
$sth = $this->db->prepare($sql);
|
||||
|
@ -103,7 +103,7 @@ class AuthorController extends Zend_Controller_Action
|
|||
if($ac == "offline" || $ac=="searchoffline")
|
||||
{
|
||||
$pr = $this->_request->getParam('pr');
|
||||
$oid = $this->_request->getParam('oid');
|
||||
$oid = $this->_request->getParam('oid');
|
||||
$pdf = $this->_request->getParam('pdf');
|
||||
|
||||
if(!empty($pr))
|
||||
|
@ -124,7 +124,7 @@ class AuthorController extends Zend_Controller_Action
|
|||
left join offlineapp o on o.id=d.offlineappid
|
||||
left join metadata md on md.uuid=d.uuid
|
||||
left join mdauthor a on a.uuid=d.uuid
|
||||
where o.ts_approved is null and o.pdflink is not null
|
||||
where o.ts_approved is null and o.pdflink is not null
|
||||
and d.uuid=? and a.userid=? and d.id=? AND a.status=1
|
||||
order by o.ts_created desc";
|
||||
|
||||
|
@ -136,11 +136,11 @@ class AuthorController extends Zend_Controller_Action
|
|||
{
|
||||
echo "该申请已经通过并且发放数据";
|
||||
exit();
|
||||
}
|
||||
else if (empty($row) || $row['datastatus']!=4)
|
||||
{
|
||||
echo "该数据申请存在问题,请联系数据中心!";
|
||||
exit();
|
||||
}
|
||||
else if (empty($row) || $row['datastatus']!=4)
|
||||
{
|
||||
echo "该数据申请存在问题,请联系数据中心!";
|
||||
exit();
|
||||
}
|
||||
|
||||
//同意用户下载
|
||||
|
@ -179,12 +179,12 @@ class AuthorController extends Zend_Controller_Action
|
|||
echo "处理中遇到错误,请刷新页面后重试";
|
||||
exit();
|
||||
}
|
||||
}
|
||||
else if (!empty($pdf))
|
||||
{
|
||||
$sql="select o.pdflink from dataorder d left join offlineapp o on d.offlineappid=o.id
|
||||
left join mdauthor m on d.uuid=m.uuid
|
||||
where d.id=? and m.userid=?";
|
||||
}
|
||||
else if (!empty($pdf))
|
||||
{
|
||||
$sql="select o.pdflink from dataorder d left join offlineapp o on d.offlineappid=o.id
|
||||
left join mdauthor m on d.uuid=m.uuid
|
||||
where d.id=? and m.userid=?";
|
||||
$sth = $this->db->prepare($sql);
|
||||
$sth->execute(array($pdf,$u_id));
|
||||
$row = $sth->fetch();
|
||||
|
@ -202,15 +202,15 @@ class AuthorController extends Zend_Controller_Action
|
|||
left join dataorder d on o.id=d.offlineappid
|
||||
left join metadata md on md.uuid=d.uuid
|
||||
left join mdauthor a on a.uuid=d.uuid
|
||||
where o.ts_approved is null and o.pdflink is not null and d.status=4 and a.userid=? AND a.status=1 ";
|
||||
if($ac == "searchoffline")
|
||||
{
|
||||
where o.ts_approved is null and o.pdflink is not null and d.status=4 and a.userid=? AND a.status=1 ";
|
||||
if($ac == "searchoffline")
|
||||
{
|
||||
$keywords = $this->_request->getParam('q');
|
||||
if(!empty($keywords))
|
||||
$this->view->q = $keywords;
|
||||
$search=new Search($keywords);
|
||||
$where=$search->sql_expr(array("md.title","md.description"));
|
||||
$select.=' and '.$where;
|
||||
$this->view->q = $keywords;
|
||||
$search=new Search($keywords);
|
||||
$where=$search->sql_expr(array("md.title","md.description"));
|
||||
$select.=' and '.$where;
|
||||
}
|
||||
$select.=" order by o.ts_created desc";
|
||||
|
||||
|
@ -262,7 +262,7 @@ class AuthorController extends Zend_Controller_Action
|
|||
|
||||
$sth = $this->db->prepare($sql);
|
||||
$sth->execute(array($uuid,$u_id));
|
||||
$rows = $sth->fetchAll();
|
||||
$rows = $sth->fetchAll();
|
||||
@$this->view->mdtitle=$rows[0]['title'];
|
||||
|
||||
foreach ($rows as $k=>$v)
|
||||
|
@ -295,9 +295,9 @@ class AuthorController extends Zend_Controller_Action
|
|||
$keywords = $this->_request->getParam('q');
|
||||
if(!empty($keywords))
|
||||
$this->view->q = $keywords;
|
||||
$search=new Search($keywords);
|
||||
$where=$search->sql_expr(array("md.title","md.description"));
|
||||
$sql.=' and '.$where;
|
||||
$search=new Search($keywords);
|
||||
$where=$search->sql_expr(array("md.title","md.description"));
|
||||
$sql.=' and '.$where;
|
||||
}
|
||||
$sql.=" GROUP BY md.title,d.uuid";
|
||||
|
||||
|
@ -1087,14 +1087,14 @@ class AuthorController extends Zend_Controller_Action
|
|||
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))
|
||||
{
|
||||
$sql = "SELECT c.author,c.email,c.url,c.ts_created,c.content,m.title FROM comments c
|
||||
LEFT JOIN mdauthor a ON a.uuid=c.uuid
|
||||
LEFT JOIN mdauthor a ON a.uuid=c.uuid
|
||||
left join metadata m on m.uuid=c.uuid
|
||||
WHERE c.uuid=? AND a.userid=?
|
||||
ORDER BY ts_created DESC";
|
||||
|
||||
$sth = $this->db->prepare($sql);
|
||||
$sth->execute(array($uuid,$u_id));
|
||||
$rows = $sth->fetchAll();
|
||||
$rows = $sth->fetchAll();
|
||||
@$this->view->mdtitle=$rows[0]['title'];
|
||||
|
||||
$paginator = Zend_Paginator::factory($rows);
|
||||
|
@ -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() 数据新闻
|
||||
|
|
|
@ -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>
|
||||
|
|
Loading…
Reference in New Issue