2013-05-06 09:01:14 +00:00
< ? php
/*
@ version $Id : AuthorController . php 2012 - 2 - 29 15 : 01 Z
@ package author
@ copyright Copyright ( c ) 2012 , CAREERI .
@ license http ://
@ link http ://
*/
2013-09-05 04:00:07 +00:00
use data\DataService ;
2014-05-24 09:21:04 +00:00
use Helpers\View as view ;
use Reference\Reference ;
use Reference\Ris ;
2013-06-24 08:58:21 +00:00
include_once ( " data/Author.php " );
2013-05-06 09:01:14 +00:00
class AuthorController extends Zend_Controller_Action
{
private $limit = 10 ;
//调试模式
// 调试模式中将显示全部错误细节,电子邮件将发往调试邮箱
// 1 为开启
// 0 为关闭
public $debug = 0 ;
//调试模式邮箱地址
public $debug_email = " wangliangxu@lzb.ac.cn " ;
function preDispatch ()
{
$this -> view -> config = Zend_Registry :: get ( 'config' );
$this -> db = Zend_Registry :: get ( 'db' );
$this -> messenger = $this -> _helper -> getHelper ( 'FlashMessenger' );
$this -> view -> messages = $this -> messenger -> getMessages ();
$this -> view -> theme = new Theme ();
$this -> view -> pageID = " author- " . $this -> _request -> getActionName ();
}
function indexAction ()
{
$this -> view -> pageID = " author-index " ;
2013-05-17 01:52:01 +00:00
$archives = new Archive ( $this -> db );
$this -> view -> item = $archives -> getOneArchive ( '数据作者介绍' , 'help' );
2013-05-06 09:01:14 +00:00
}
/*
* helpAction () 帮助文档
*
*/
function helpAction (){
$this -> view -> pageID = " author-help " ;
} //helpAction()帮助文档
/*
* inauthorAction () 数据申请管理
*
* param string $ac
* param string $keywords
* param string $pr //对离线数据申请的操作
* param string $uuid
*
* return view | ajax - responds
*/
function inauthorAction ()
{
$ac = $this -> _request -> getParam ( " ac " );
$auth = Zend_Auth :: getInstance ();
if ( $auth -> hasIdentity ())
{
$user = $auth -> getIdentity ();
$u_id = $user -> id ;
$u_email = $user -> email ;
}
if ( empty ( $ac ) || $ac == " online " || $ac == " searchonline " )
{
$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 " )
{
$keywords = $this -> _request -> getParam ( 'q' );
if ( ! empty ( $keywords ))
$this -> view -> q = $keywords ;
$search = new SimpleSearch ( $keywords );
$where = $search -> sql_expr ( array ( " m.title " , " m.description " ));
$sql .= ' and ' . $where ;
}
$sql .= " ORDER BY o.id desc " ;
$sth = $this -> db -> prepare ( $sql );
$sth -> execute ( array ( $u_id ));
$rows = $sth -> fetchAll ();
$paginator = Zend_Paginator :: factory ( $rows );
$paginator -> setCurrentPageNumber ( $this -> _getParam ( 'page' ));
$paginator -> setItemCountPerPage ( 10 );
$paginator -> setView ( $this -> view );
Zend_View_Helper_PaginationControl :: setDefaultViewPartial ( 'pagination_param.phtml' );
$this -> view -> paginator = $paginator ;
} //在线申请记录
if ( $ac == " offline " || $ac == " searchoffline " )
{
$pr = $this -> _request -> getParam ( 'pr' );
$oid = $this -> _request -> getParam ( 'oid' );
$pdf = $this -> _request -> getParam ( 'pdf' );
if ( ! empty ( $pr ))
{
try {
$this -> _helper -> layout -> disableLayout ();
$this -> _helper -> viewRenderer -> setNoRender ();
$uuid = $this -> _request -> getParam ( 'uuid' );
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 ))
{
echo " 参数有误! " ; exit ();
}
//如果用户已经下载过了,就无法在更改对数据申请的意见
$sql = " select md.title,d.uuid,d.status as datastatus,d.authorpermitted from dataorder d
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
and d . uuid = ? and a . userid = ? and d . id = ? AND a . status = 1
order by o . ts_created desc " ;
$sth = $this -> db -> prepare ( $sql );
$sth -> execute ( array ( $uuid , $u_id , $oid ));
$row = $sth -> fetch ();
if ( $row [ 'datastatus' ] > 4 )
{
echo " 该申请已经通过并且发放数据 " ;
exit ();
}
else if ( empty ( $row ) || $row [ 'datastatus' ] != 4 )
{
echo " 该数据申请存在问题,请联系数据中心! " ;
exit ();
}
//同意用户下载
if ( $pr == " confirm " )
{
$sql = " UPDATE dataorder SET authorpermitted=1 WHERE uuid=? and id=? " ;
$sth = $this -> db -> prepare ( $sql );
if ( $sth -> execute ( array ( $uuid , $oid )))
{
//发送相关邮件给数据中心服务人员
$sql = " select m.title,a.username from dataorder o left join metadata m on o.uuid=m.uuid left join offlineapp a on o.offlineappid=a.id where o.id=? " ;
$sth = $this -> db -> prepare ( $sql );
$sth -> execute ( array ( $oid ));
$row = $sth -> fetch ();
$mail = new WestdcMailer ( $this -> view -> config -> smtp );
$mailtp = new EmailText ( $this -> db , 'offline-author-yes' , array ( 'user' => $row [ 'username' ], 'data' => $row [ 'title' ], 'email' => $u_email ));
$mail -> setFrom ( $this -> view -> config -> service -> email , '西部数据中心服务组' );
$mail -> setBodyText ( $mailtp -> getBody ());
$mail -> setSubject ( $mailtp -> getSubject ());
$mail -> addTo ( $this -> view -> config -> service -> email , '西部数据中心服务组' );
$mail -> send ();
$btn = $this -> createOfflineCtBtn ( $uuid , 'c' , $oid );
echo '' . $btn . '<script>alert("您已经同意用户的离线数据申请");</script>' ;
exit ();
} else {
echo " <script>alert('处理过程中遇到错误,请刷新页面');</script> " ;
exit ();
}
}
//反对用户下载
if ( $pr == " objection " )
{
$sql = " UPDATE dataorder SET authorpermitted=-1 WHERE uuid=? AND id=? " ;
$sth = $this -> db -> prepare ( $sql );
if ( $sth -> execute ( array ( $uuid , $oid )))
{
$btn = $this -> createOfflineCtBtn ( $uuid , 'o' , $oid );
echo '' . $btn . '<script>alert("您已经拒绝该用户的此次离线数据申请");</script>' ;
exit ();
} else {
echo " <script>alert('处理过程中遇到错误,请刷新页面');</script> " ;
exit ();
}
}
} catch ( Exception $e )
{
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 = ? " ;
$sth = $this -> db -> prepare ( $sql );
$sth -> execute ( array ( $pdf , $u_id ));
$row = $sth -> fetch ();
$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
}
else
{
$this -> _helper -> viewRenderer ( 'inauthor-offline' );
$select = " select distinct(o.*),md.title,d.id as doid,d.uuid,d.status as datastatus,d.authorpermitted from offlineapp o
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 " )
{
$keywords = $this -> _request -> getParam ( 'q' );
if ( ! empty ( $keywords ))
$this -> view -> q = $keywords ;
$search = new SimpleSearch ( $keywords );
$where = $search -> sql_expr ( array ( " md.title " , " md.description " ));
$select .= ' and ' . $where ;
}
$select .= " order by o.ts_created desc " ;
$sth = $this -> db -> prepare ( $select );
$sth -> execute ( array ( $u_id ));
$rows = $sth -> fetchAll ();
foreach ( $rows as $k => $v )
{
if ( $v [ 'authorpermitted' ] == 0 )
{ $rows [ $k ][ 'btns' ] = $this -> createOfflineCtBtn ( $v [ 'uuid' ], '' , $v [ 'doid' ]);}
if ( $v [ 'authorpermitted' ] > 0 )
{ $rows [ $k ][ 'btns' ] = $this -> createOfflineCtBtn ( $v [ 'uuid' ], 'c' , $v [ 'doid' ]);}
if ( $v [ 'authorpermitted' ] < 0 )
{ $rows [ $k ][ 'btns' ] = $this -> createOfflineCtBtn ( $v [ 'uuid' ], 'o' , $v [ 'doid' ]);}
}
$paginator = Zend_Paginator :: factory ( $rows );
$paginator -> setCurrentPageNumber ( $this -> _getParam ( 'page' ));
$paginator -> setItemCountPerPage ( 10 );
$paginator -> setView ( $this -> view );
Zend_View_Helper_PaginationControl :: setDefaultViewPartial ( 'pagination_param.phtml' );
$this -> view -> paginator = $paginator ;
}
} //离线申请
//按数据显示
if ( $ac == 'datalist' || $ac == " searchdata " )
{
$uuid = $this -> _request -> getParam ( 'uuid' );
if ( ! empty ( $uuid ))
{
$this -> _helper -> viewRenderer ( 'view-dataoreder' );
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 md.title,d.id as doid,d.uuid,d.authorpermitted,d.status
, offa . id as offa_id , offa . username as offa_name , offa . unit as offa_unit , offa . email as offa_email , offa . project as offa_project , date ( offa . ts_created ) as offa_tscreated
, ona . id as ona_id , ona . username as ona_name , ona . unit as ona_unit , ona . email as ona_email , ona . project as ona_project , date ( ona . ts_created ) as ona_tscreated
from dataorder d
left join metadata md on md . uuid = d . uuid
left join mdauthor a on a . uuid = d . uuid
LEFT JOIN offlineapp offa on offa . id = d . offlineappid
LEFT JOIN onlineapp ona on ona . id = d . onlineappid
WHERE ( offa . id IS NOT NULL OR ona . id IS NOT NULL ) AND a . status = 1 and d . status >= 0
AND d . uuid = ? AND a . userid = ?
ORDER BY d . ts_created DESC " ;
$sth = $this -> db -> prepare ( $sql );
$sth -> execute ( array ( $uuid , $u_id ));
$rows = $sth -> fetchAll ();
@ $this -> view -> mdtitle = $rows [ 0 ][ 'title' ];
foreach ( $rows as $k => $v )
{
if ( $v [ 'authorpermitted' ] == 0 )
{ $rows [ $k ][ 'btns' ] = $this -> createOfflineCtBtn ( $v [ 'uuid' ], '' , $v [ 'doid' ]);}
if ( $v [ 'authorpermitted' ] > 0 )
{ $rows [ $k ][ 'btns' ] = $this -> createOfflineCtBtn ( $v [ 'uuid' ], 'c' , $v [ 'doid' ]);}
if ( $v [ 'authorpermitted' ] < 0 )
{ $rows [ $k ][ 'btns' ] = $this -> createOfflineCtBtn ( $v [ 'uuid' ], 'o' , $v [ 'doid' ]);}
}
$paginator = Zend_Paginator :: factory ( $rows );
$paginator -> setCurrentPageNumber ( $this -> _getParam ( 'page' ));
$paginator -> setItemCountPerPage ( 10 );
$paginator -> setView ( $this -> view );
Zend_View_Helper_PaginationControl :: setDefaultViewPartial ( 'pagination_param.phtml' );
$this -> view -> paginator = $paginator ;
} else {
$this -> view -> error = " 参数有误 " ;
}
} else {
$this -> _helper -> viewRenderer ( 'inauthor-datalist' );
$sql = " select md.title,d.uuid,count(md.id) as c from dataorder d
left join metadata md on md . uuid = d . uuid
left join mdauthor a on a . uuid = d . uuid
where a . status = 1 AND a . userid = ? " ;
if ( $ac == " searchdata " )
{
$keywords = $this -> _request -> getParam ( 'q' );
if ( ! empty ( $keywords ))
$this -> view -> q = $keywords ;
$search = new SimpleSearch ( $keywords );
$where = $search -> sql_expr ( array ( " md.title " , " md.description " ));
$sql .= ' and ' . $where ;
}
$sql .= " GROUP BY md.title,d.uuid " ;
$sth = $this -> db -> prepare ( $sql );
$sth -> execute ( array ( $u_id ));
$rows = $sth -> fetchAll ();
$paginator = Zend_Paginator :: factory ( $rows );
$paginator -> setCurrentPageNumber ( $this -> _getParam ( 'page' ));
$paginator -> setItemCountPerPage ( 10 );
$paginator -> setView ( $this -> view );
Zend_View_Helper_PaginationControl :: setDefaultViewPartial ( 'pagination_param.phtml' );
$this -> view -> paginator = $paginator ;
}
} //按数据显示
} // inauthorAction() 数据申请管理
/*
* createOfflineCtBtn () 创建离线申请记录的操作按钮
*
*/
function createOfflineCtBtn ( $uuid , $type = " " , $oid ){
$urlHref = 'href="javascript:;"' ;
$baseStyle = " btn box-shadow " ;
$selectedStyle = " disabled " ;
$confrimText = " 同意 " ;
$confrimFunc = 'onclick="confirm(\'' . $uuid . '\',\'' . $oid . '\')"' ;
$objectionText = " 反对 " ;
$objectionFunc = 'onclick="objection(\'' . $uuid . '\',\'' . $oid . '\')"' ;
$btns = '' ;
if ( empty ( $type ))
{
$confrimBtn = " <a $urlHref class= \" $baseStyle\ " $confrimFunc > $confrimText </ a > " ;
$objectionBtn = " <a $urlHref class= \" $baseStyle\ " $objectionFunc > $objectionText </ a > " ;
$btns = $confrimBtn . $objectionBtn ;
}
if ( $type == 'c' )
{
$confrimBtn = " <a class= \" $baseStyle $selectedStyle\ " > $confrimText </ a > " ;
$objectionBtn = " <a $urlHref class= \" $baseStyle\ " $objectionFunc > $objectionText </ a > " ;
$btns = $confrimBtn . $objectionBtn ;
}
if ( $type == 'o' )
{
$confrimBtn = " <a $urlHref class= \" $baseStyle\ " $confrimFunc > $confrimText </ a > " ;
$objectionBtn = " <a class= \" $baseStyle $selectedStyle\ " > $objectionText </ a > " ;
$btns = $confrimBtn . $objectionBtn ;
}
return $btns ;
} //createOfflineCtBtn()
/*
* acceptAction () 我的数据
*
* param string $ac // list|search
* param string $keyword
*
* return view
*/
function acceptAction ()
{
$ac = $this -> _request -> getParam ( " ac " );
$auth = Zend_Auth :: getInstance ();
if ( $auth -> hasIdentity ())
{
$user = $auth -> getIdentity ();
$u_id = $user -> id ;
$u_email = $user -> email ;
}
//列表
if ( empty ( $ac ) || $ac == 'list' || $ac == 'search' ){
$sql = " SELECT a.*,m.title,m.description,g.id as gid,mds.status as mdstatus FROM normalmetadata m
LEFT JOIN mdauthor a ON m . uuid = a . uuid
LEFT JOIN geonetworkmetadata g on m . uuid = g . uuid
LEFT JOIN mdstatus mds ON m . uuid = mds . uuid
WHERE a . userid = ? AND a . status >= 0 " ;
if ( $ac == 'search' )
{
$key = trim ( $this -> _request -> getParam ( 'q' ));
$this -> view -> q = $key ;
$search = new SimpleSearch ( $key );
$where = $search -> sql_expr ( array ( " m.title " , " m.description " ));
$sql .= ' and ' . $where ;
}
$sql .= " ORDER BY a.status DESC,a.id DESC " ;
$sth = $this -> db -> prepare ( $sql );
$sth -> execute ( array ( $u_id ));
$rows = $sth -> fetchAll ();
$paginator = Zend_Paginator :: factory ( $rows );
$paginator -> setCurrentPageNumber ( $this -> _getParam ( 'page' ));
$paginator -> setItemCountPerPage ( 5 );
$paginator -> setView ( $this -> view );
Zend_View_Helper_PaginationControl :: setDefaultViewPartial ( 'pagination_param.phtml' );
$this -> view -> paginator = $paginator ;
} //list
//激活数据作者
if ( $ac == " active " )
{
$this -> _helper -> viewRenderer ( 'accept-active' );
$vdcode = $this -> _request -> getParam ( 'v' );
$this -> view -> v = $vdcode ;
try {
$sql = " SELECT a.id,a.activation,a.ts_created,a.ts_activated,md.title,a.uuid,u.id as userid,u.realname,u.email FROM mdauthor a
LEFT JOIN metadata md ON a . uuid = md . uuid
LEFT JOIN users u ON a . userid = u . id
WHERE a . activation = ? " ;
$sth = $this -> db -> prepare ( $sql );
$sth -> execute ( array ( $vdcode ));
$row = $sth -> fetch ();
if ( empty ( $row [ 'id' ]))
{
$this -> view -> info = '此激活码无效' ;
} else {
if ( empty ( $row [ 'ts_activated' ]))
{
$sql = " UPDATE mdauthor SET ts_activated=?,status=? WHERE activation=? " ;
$sth = $this -> db -> prepare ( $sql );
$ex = $sth -> execute ( array ( 'now()' , 1 , $vdcode ));
if ( $ex )
{
include_once ( " EmailText.php " );
$this -> author_first ( $row [ 'uuid' ], $row [ 'userid' ]);
$mail = new WestdcMailer ( $this -> view -> config -> smtp );
$mail -> setFrom ( $this -> view -> config -> service -> email , '西部数据中心服务组' );
$mailtp = new EmailText ( $this -> db , " author-new " , array (
'user' => $row [ 'realname' ],
'uuid' => $row [ 'uuid' ],
'title' => $row [ 'title' ],
'email' => $row [ 'email' ],
));
$mail -> setBodyText ( $mailtp -> getBody ());
$mail -> setSubject ( $mailtp -> getSubject ());
if ( $this -> debug == 0 )
{
//获得元数据作者email
/* 不需要给这些人发通知邮件
$info = $this -> getEmail ( $uuid , 1 );
$address = $info [ 'addrs' ];
foreach ( $address as $v )
{
$mail -> addTo ( $v );
} */
$mail -> addTo ( $row [ 'email' ]);
$mail -> addCc ( $this -> view -> config -> service -> email ); //管理员
} else {
$mail -> addTo ( $this -> debug_email );
}
$mail -> send ();
$this -> view -> info = '激活成功<br /><a href="/author/accept">点击这里</a>进入我的数据页面查看' ;
} else
{
$this -> view -> info = " 激活中遇到问题,请重试 " ;
}
} else
{
$this -> view -> info = '此激活码已经失效' ;
}
}
} catch ( Exception $e ){
if ( $this -> debug == 0 )
{
$this -> view -> info = " 处理中遇到错误,请重新尝试 " ;
} else {
$this -> view -> info = $e -> getMessage ();
}
}
} //激活数据作者
//拒绝激活
if ( $ac == " lock " )
{
$this -> _helper -> viewRenderer ( 'accept-active' );
$vdcode = $this -> _request -> getParam ( 'v' );
$this -> view -> v = $vdcode ;
try {
$sql = " SELECT a.id,a.activation,a.ts_created,a.ts_activated,md.title,a.uuid,u.realname,u.email FROM mdauthor a
LEFT JOIN metadata md ON a . uuid = md . uuid
LEFT JOIN users u ON a . userid = u . id
WHERE a . activation = ? " ;
$sth = $this -> db -> prepare ( $sql );
$sth -> execute ( array ( $vdcode ));
$row = $sth -> fetch ();
if ( empty ( $row [ 'id' ]))
{
$this -> view -> info = '此激活码无效' ;
} else {
if ( empty ( $row [ 'ts_activated' ]))
{
$sql = " UPDATE mdauthor SET ts_activated=?,status=? WHERE activation=? " ;
$sth = $this -> db -> prepare ( $sql );
$ex = $sth -> execute ( array ( 'now()' , - 1 , $vdcode ));
if ( $ex )
{
include_once ( " EmailText.php " );
$mail = new WestdcMailer ( $this -> view -> config -> smtp );
$mail -> setFrom ( $this -> view -> config -> service -> email , '西部数据中心服务组' );
$mailtp = new EmailText ( $this -> db , " author-deny " , array (
'user' => $row [ 'realname' ],
'uuid' => $row [ 'uuid' ],
'title' => $row [ 'title' ],
'email' => $row [ 'email' ],
));
$mail -> setBodyText ( $mailtp -> getBody ());
$mail -> setSubject ( $mailtp -> getSubject ());
if ( $this -> debug == 0 )
{
$mail -> addTo ( $row [ 'email' ]);
$mail -> addCc ( $this -> view -> config -> service -> email );
} else {
$mail -> addTo ( $this -> debug_email );
}
$mail -> send ();
$this -> view -> info = '该申请已被拒绝,<a href="/author/accept">点击这里</a>进入我的数据页面查看' ;
} else
{
$this -> view -> info = " 激活中遇到问题,请重试 " ;
}
} else
{
$this -> view -> info = '此激活码已经失效' ;
}
}
} catch ( Exception $e ){
if ( $this -> debug == 0 )
{
$this -> view -> info = " 处理中遇到错误,请重新尝试 " ;
} else {
$this -> view -> info = $e -> getMessage ();
}
}
} //否认激活
} //acceptAction() 我的数据
/*
*
* getEmail () 获取数据所有者电子邮箱地址
*
* param string $uuid //UUID
* param int $level //输出信息等级
* 0 => 输出所有Email地址
* 1 => 输出数据权限等级最高的Email地址 ( def )
*
* return array ()
*/
function getEmail ( $uuid , $level = 1 )
{
//需要定义角色,防止程序流程出错
$addrs = array ();
$addrs [ 'resourceProvider' ] = array ();
$addrs [ 'owner' ] = array ();
$addrs [ 'pointOfContact' ] = array ();
$addrs [ 'author' ] = array ();
$addrs [ " publisher " ] = array ();
$sql = ' select r . uuid , p . email , md . title , r . role from normalmetadata md
LEFT JOIN role r ON md . uuid = r . uuid
left join responsible p on r . resid = p . id
WHERE r . uuid = ? AND p . email IS NOT NULL AND p . email != ?
GROUP BY r . uuid , p . email , md . title , r . role ' ;
$sth = $this -> db -> prepare ( $sql );
$sth -> execute ( array ( $uuid , '' ));
$rows = $sth -> fetchAll ();
$addrs [ 'title' ] = $rows [ 0 ][ 'title' ];
foreach ( $rows as $k => $v )
{
//数据资源提供者resourceProvider
if ( $v [ 'role' ] == 'resourceProvider' )
{
$addrs [ 'resourceProvider' ][] = $v [ 'email' ];
}
//数据资源所有者owner
if ( $v [ 'role' ] == 'owner' )
{
$addrs [ 'owner' ][] = $v [ 'email' ];
}
//数据联系人pointOfContact
if ( $v [ 'role' ] == 'pointOfContact' )
{
$addrs [ 'pointOfContact' ][] = $v [ 'email' ];
}
//元数据作者author
if ( $v [ 'role' ] == 'author' )
{
$addrs [ 'author' ][] = $v [ 'email' ];
}
if ( $v [ " role " ] == " " )
{
$addrs [ " publisher " ][] = $v [ 'email' ];
}
}
//输出所有email (多维数组)
/*
$addrs [ 'resourceProvider' ]
$addrs [ 'owner' ]
$addrs [ 'pointOfContact' ]
$addrs [ 'author' ]
*/
if ( $level == 0 )
{
return $addrs ;
}
//输出最高优先级的Email
//$addrs['addrs']
if ( $level == 1 )
{
//如果有 数据资源提供者 resourceProvider 就输出他的地址 以此类推
if ( count ( $addrs [ 'resourceProvider' ]) > 0 )
{
$addrs [ 'addrs' ][] = $addrs [ 'resourceProvider' ];
return $addrs ;
}
if ( count ( $addrs [ 'owner' ]) > 0 )
{
$addrs [ 'addrs' ][] = $addrs [ 'owner' ];
return $addrs ;
}
if ( count ( $addrs [ 'pointOfContact' ]) > 0 )
{
$addrs [ 'addrs' ][] = $addrs [ 'pointOfContact' ];
return $addrs ;
}
if ( count ( $addrs [ 'author' ]) > 0 )
{
$addrs [ 'addrs' ][] = $addrs [ 'author' ];
return $addrs ;
}
if ( count ( $addrs [ " publisher " ]) > 0 )
{
$addrs [ 'addrs' ][] = $addrs [ " publisher " ];
return $addrs ;
}
}
} //getEmail 获取数据作者email地址
/*
* applyAction () 申请成为元数据作者
*
* param string $ac //动作 search|apply
* param string $q //搜索关键词
* param string $uuid //数据的UUID
*
* return view | ajax | json
*
* 调试搜索结果 :
* / author / apply ? ac = apply & uuid = 816 ecd28 - ba88 - 464 b - a83a - 341440 f536ef
*/
function applyAction ()
{
2013-06-24 08:58:21 +00:00
$ac = $this -> _request -> getParam ( 'ac' );
include_once ( 'helper/view.php' );
2013-06-09 04:26:41 +00:00
$this -> view -> id = view :: User ( 'id' );
2013-05-29 07:36:44 +00:00
if ( $ac == " mydata " )
{
$this -> _helper -> layout -> disableLayout ();
$this -> _helper -> viewRenderer -> setNoRender ();
$email = view :: User ( 'email' );
2013-06-24 08:58:21 +00:00
$realname = view :: User ( 'realname' );
2013-06-09 04:26:41 +00:00
2013-05-29 07:36:44 +00:00
2013-05-30 00:14:54 +00:00
$sql = " SELECT distinct m.uuid,m.title,m.description,a.status,a.userid FROM normalmetadata m
2013-05-29 07:36:44 +00:00
LEFT JOIN mdauthor a ON m . uuid = a . uuid
LEFT JOIN role r ON r . uuid = m . uuid
LEFT JOIN responsible re ON r . resid = re . id
2013-06-09 04:26:41 +00:00
WHERE r . role in ( 'originator' , 'resourceProvider' , 'pointOfContact' , 'owner' ) and ( re . email LIKE '%$email%' or re . individual = '$realname' ) " ;
2013-05-29 07:36:44 +00:00
$rs = $this -> db -> query ( $sql );
$this -> jsonexit ( $rs -> fetchAll ());
return true ;
} //首页
2013-05-06 09:01:14 +00:00
//搜索动作
if ( $ac == " search " )
{
$this -> _helper -> layout -> disableLayout ();
$this -> _helper -> viewRenderer -> setNoRender ();
$data = " " ;
//防止通过其它方式访问,先判断是否是登录用户,如果不是,抛出消息后强制用户退出
$auth = Zend_Auth :: getInstance ();
if ( $auth -> hasIdentity ())
{
$user = $auth -> getIdentity ();
$u_id = $user -> id ;
} else {
$data = array ( " error " => " 请先登录 " );
$this -> getResponse ()
-> setHeader ( 'Content-Type' , 'application/json' )
-> appendBody ( Zend_Json :: encode ( $data ));
return true ;
}
//数据处理代码 EOH<<<<<<<<<<<<<<<<
try {
$keyword = trim ( $this -> _request -> getParam ( 'q' ));
if ( strlen ( trim ( $keyword )) < 3 )
$data = array ( 'error' => '搜索关键字过短' );
else if ( ! preg_match_all ( " /^[ \ x { 4e00}- \ x { 9fa5}A-Za-z0-9 \ s_]+ $ /u " , $keyword , $matchs ))
{
$data = array ( 'error' => '搜索关键字中只能包含汉字、英文、数字' );
}
else
{
//搜索标题和描述两个字段
$sql = " SELECT m.uuid,m.title,m.description,a.status,a.userid FROM normalmetadata m
LEFT JOIN mdauthor a ON m . uuid = a . uuid
WHERE " ;
$search = new SimpleSearch ( $keyword );
$where = $search -> sql_expr ( array ( " m.title " , " m.description " ));
$sql .= $where ;
$sth = $this -> db -> prepare ( $sql );
$sth -> execute ();
$rows = $sth -> fetchAll ();
if ( is_array ( $rows ) && count ( $rows ) > 0 )
$data = $rows ;
else
$data = " " ;
}
} catch ( Exception $e ){
2013-05-29 07:36:44 +00:00
2013-05-06 09:01:14 +00:00
if ( empty ( $data [ 'error' ]))
{
if ( $this -> debug == 0 )
{
$data = array ( " error " => " 处理过程中遇到错误,请重新尝试 " );
} else {
$data = array ( " error " => $e -> getMessage ());
}
}
}
2013-05-29 07:36:44 +00:00
2013-05-06 09:01:14 +00:00
2013-05-29 07:36:44 +00:00
$this -> jsonexit ( $data );
return true ;
2013-05-06 09:01:14 +00:00
} // search
/****************
申请动作
****************/
if ( $ac == " apply " )
{
$this -> _helper -> layout -> disableLayout ();
$this -> _helper -> viewRenderer -> setNoRender ();
$data = " " ;
$auth = Zend_Auth :: getInstance ();
if ( $auth -> hasIdentity ())
{
$user = $auth -> getIdentity ();
$u_id = $user -> id ;
$u_email = $user -> email ;
}
//处理部分<<<<<<<<<<
try {
$uuid = $this -> _request -> getParam ( 'uuid' );
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 id,status FROM mdauthor WHERE uuid=? AND userid=? " ;
$sth = $this -> db -> prepare ( $sql );
$sth -> execute ( array ( $uuid , $u_id ));
$row = $sth -> fetch ();
//如果已经是元数据作者,从流程中直接退出程序
if ( ! empty ( $row [ 'id' ]) && $row [ 'status' ] == 1 )
{
$data = array ( " error " => " 您目前已经是该数据作者,不需要再申请 " );
}
//如果已经遭到明确拒绝,则不允许用户再次申请
if ( ! empty ( $row [ 'id' ]) && $row [ 'status' ] ==- 1 )
{
$data = array ( " error " => " 您的申请已经遭到拒绝,不能再申请,有疑问请联系数据中心 " );
}
//如果已经存在申请,但是没有激活的,返回激活信息
if ( $row [ 'status' ] == 0 ){
if ( ! empty ( $row [ 'id' ]) && empty ( $m ))
{
$data = array (
" error " => '您已经申请过了,如果长时间没有收到回应请联系数据中心' ,
" post " => " activa " ,
" uid " => $u_id ,
" uemail " => $u_email ,
" uuid " => $uuid ,
);
} //if
else {
$info = $this -> getEmail ( $uuid , 1 );
$address = $info [ 'addrs' ];
$mdtitle = $info [ 'title' ];
//如果当前用户的email包含在元数据作者email列表中, 则直接使其成为元数据作者
if ( in_array ( $u_email , $address ))
{
$sql = " INSERT INTO mdauthor (uuid,userid,activation,ts_activated,status) VALUES (?,?,?,?,?) " ;
$sth = $this -> db -> prepare ( $sql );
$ex = $sth -> execute ( array ( $uuid , $u_id , '' , 'now()' , 1 ));
if ( $ex )
{
$data = array ( " error " => " 您的身份符合申请条件,已经自动成为该元数据作者 " );
$this -> author_first ( $uuid , $u_id );
include_once ( " EmailText.php " );
$mail = new WestdcMailer ( $this -> view -> config -> smtp );
$mail -> setFrom ( $this -> view -> config -> service -> email , '西部数据中心服务组' );
$mailtp = new EmailText ( $this -> db , " author-new " , array (
'user' => $user -> realname ,
'uuid' => $uuid ,
'title' => $mdtitle ,
'email' => $u_email ,
));
$mail -> setBodyText ( $mailtp -> getBody ());
$mail -> setSubject ( $mailtp -> getSubject ());
if ( $this -> debug == 0 )
{
foreach ( $address as $dist )
{ $mail -> addTo ( $dist );} //元数据作者
$mail -> addTo ( $u_email );
$mail -> addCc ( $this -> view -> config -> service -> email ); //管理员
} else {
$mail -> addTo ( $this -> debug_email );
}
$mail -> send ();
}
else
{
$data = array ( " error " => " 处理中出现错误,请重新尝试 " );
}
}
//如果不包含在当前元数据作者的email列表中
//给数据拥有者发送邮件,使其决定是否同意新加入作者
else
{
//生成激活码
$ssid = session_id ();
$vdcode = md5 ( $uuid . $ssid . $u_id . time ());
//激活链接
// /author/accept/?ac=active&vdcode=$vdcode
$sql = " INSERT INTO mdauthor (uuid,userid,activation) VALUES (?,?,?) " ;
$sth = $this -> db -> prepare ( $sql );
$ex = $sth -> execute ( array ( $uuid , $u_id , $vdcode ));
if ( $ex )
{
//给申请者发送邮件
include_once ( " EmailText.php " );
@ $mail = new WestdcMailer ( $this -> view -> config -> smtp );
@ $mail -> setFrom ( $this -> view -> config -> service -> email , '西部数据中心服务组' );
@ $mailtp = new EmailText ( $this -> db , " author-apply " , array (
'user' => $user -> username ,
'uuid' => $uuid ,
'email' => $user -> email ,
//元数据标题
'title' => $mdtitle ,
));
@ $mail -> setBodyText ( $mailtp -> getBody ());
@ $mail -> setSubject ( $mailtp -> getSubject ());
if ( $this -> debug == 0 )
{
@ $mail -> addTo ( $user -> email );
} else {
@ $mail -> addTo ( $this -> debug_email );
}
@ $mail -> send ();
unset ( $mail );
unset ( $mailtp );
//给元数据作者以及管理员发送邮件
@ $mail = new WestdcMailer ( $this -> view -> config -> smtp );
@ $mail -> setFrom ( $this -> view -> config -> service -> email , '西部数据中心服务组' );
@ $mailtp = new EmailText ( $this -> db , " author-apply-confirm " , array (
'user' => $user -> username ,
'uuid' => $uuid ,
'email' => $u_email ,
'title' => $mdtitle ,
'link' => " http:// " . $_SERVER [ 'SERVER_NAME' ] . " /data/ $uuid " ,
//验证码
'vdcode' => $vdcode ,
//激活链接
'active' => " http:// " . $_SERVER [ 'SERVER_NAME' ] . " /author/accept/?ac=active&v= $vdcode " ,
//不同意激活的链接
'lock' => " http:// " . $_SERVER [ 'SERVER_NAME' ] . " /author/accept/?ac=lock&v= $vdcode " ,
));
@ $mail -> setBodyText ( $mailtp -> getBody ());
@ $mail -> setSubject ( $mailtp -> getSubject ());
if ( $this -> debug == 0 )
{
$sql = " SELECT u.email FROM mdauthor a
LEFT JOIN users u ON u . id = a . userid
WHERE a . uuid = ? " ;
$sth = $this -> db -> prepare ( $sql );
$sth -> execute ( array ( $uuid ));
$mlist = $sth -> fetchAll ();
if ( count ( $mlist ) > 0 )
{
foreach ( $mlist as $v )
{
$mail -> addTo ( $v [ 'email' ]);
}
} //mdauthor中已经注册的用户
else {
foreach ( $address as $dist )
{
$mail -> addTo ( $dist );
}
} //元数据作者
$mail -> addCc ( $this -> view -> config -> service -> email ); //管理员
} else {
@ $mail -> addTo ( $this -> debug_email );
}
@ $mail -> send ();
$data = array ( " error " => " 您的申请已收到,请耐心等待回应 " );
} else {
$data = array ( " error " => " 服务器可能在忙,请重试。 " );
} //激活码记录
} //不是确认的元数据作者
} //empty($row['id'])
} // status == 0
//调试输出结果
//$data = array('addr'=>$address,'uemail'=>$u_email);
}
else
{
$data = array ( 'error' => '参数出错,请按照正确的访问方式申请' );
}
} catch ( Exception $e ){
if ( empty ( $data [ 'error' ]))
{
if ( $this -> debug == 0 )
{
$data = array ( " error " => " 处理过程中遇到错误,请重新尝试 " );
} else {
$data = array ( " error " => $e -> getMessage ());
}
}
}
// >>>>>>>>>>>>
$this -> getResponse ()
-> setHeader ( 'Content-Type' , 'application/json' )
-> appendBody ( Zend_Json :: encode ( $data ));
} // ac = apply 申请处理
} //applyAction() 申请成为元数据作者
/*
* commentAction () 数据反馈
*
* param string $ac 动作
* param string $uuid 元数据UUID
* param int $page 页数
*
* return view
*/
function commentAction ()
{
$ac = $this -> _request -> getParam ( 'ac' );
$uuid = $this -> _getParam ( 'uuid' );
$reply = $this -> _getParam ( 'reply' );
$replylist = $this -> _getParam ( 'replylist' );
$auth = Zend_Auth :: getInstance ();
if ( $auth -> hasIdentity ())
{
$user = $auth -> getIdentity ();
$u_id = $user -> id ;
}
if ( empty ( $ac ) || $ac == 'list' )
{
$sql = " SELECT md.title,md.uuid,count(c.id) as c FROM comments c
LEFT JOIN metadata md ON md . uuid = c . uuid
LEFT JOIN mdauthor a ON md . uuid = a . uuid
WHERE md . title IS NOT NULL AND a . userid = ? AND a . status = 1 AND c . reply = 0
GROUP BY md . title , md . uuid
" ;
$sth = $this -> db -> prepare ( $sql );
$sth -> execute ( array ( $u_id ));
$rows = $sth -> fetchAll ();
$paginator = Zend_Paginator :: factory ( $rows );
$paginator -> setCurrentPageNumber ( $this -> _getParam ( 'page' ));
$paginator -> setItemCountPerPage ( 15 );
$paginator -> setView ( $this -> view );
Zend_View_Helper_PaginationControl :: setDefaultViewPartial ( 'pagination_param.phtml' );
$this -> view -> paginator = $paginator ;
}
if ( $ac == " view " )
{
$uuid = $this -> _request -> getParam ( 'uuid' );
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.id,c.author,c.email,c.url,c.ts_created,c.content,m.title,c.uuid FROM comments c
LEFT JOIN mdauthor a ON a . uuid = c . uuid
left join metadata m on m . uuid = c . uuid
WHERE c . uuid = ? AND a . userid = ? AND a . status = 1 AND c . reply = 0
ORDER BY ts_created DESC " ;
$sth = $this -> db -> prepare ( $sql );
$sth -> execute ( array ( $uuid , $u_id ));
$rows = $sth -> fetchAll ();
@ $this -> view -> mdtitle = $rows [ 0 ][ 'title' ];
$paginator = Zend_Paginator :: factory ( $rows );
$paginator -> setCurrentPageNumber ( $this -> _getParam ( 'page' ));
$paginator -> setItemCountPerPage ( 10 );
$paginator -> setView ( $this -> view );
Zend_View_Helper_PaginationControl :: setDefaultViewPartial ( 'pagination_param.phtml' );
$this -> view -> paginator = $paginator ;
}
$this -> _helper -> viewRenderer ( 'comment-list' );
}
if ( $ac == " listall " )
{
$sql = " SELECT md.title,c.author,c.email,c.url,c.ts_created,c.content FROM comments c
LEFT JOIN mdauthor a ON a . uuid = c . uuid
LEFT JOIN normalmetadata md ON md . uuid = c . uuid
WHERE a . userid = ? AND a . status = 1 AND c . reply = 0
ORDER BY ts_created DESC " ;
$sth = $this -> db -> prepare ( $sql );
$sth -> execute ( array ( $u_id ));
$rows = $sth -> fetchAll ();
$paginator = Zend_Paginator :: factory ( $rows );
$paginator -> setCurrentPageNumber ( $this -> _getParam ( 'page' ));
$paginator -> setItemCountPerPage ( 10 );
$paginator -> setView ( $this -> view );
Zend_View_Helper_PaginationControl :: setDefaultViewPartial ( 'pagination_param.phtml' );
$this -> view -> paginator = $paginator ;
$this -> _helper -> viewRenderer ( 'comment-listall' );
}
if ( $reply )
{
$this -> _helper -> layout -> disableLayout ();
$this -> _helper -> viewRenderer -> setNoRender ();
$body = $this -> _getParam ( 'content' );
if ( empty ( $body ))
{
$data = array ( 'error' => " 请输入回复内容 " );
$this -> jsonexit ( $data );
return true ;
}
$auth = Zend_Auth :: getInstance ();
if ( $auth -> hasIdentity ())
{
$user = $auth -> getIdentity ();
$uid = $user -> id ;
$email = $user -> email ;
}
$sql = " SELECT md.title,c.id,c.author,c.email,c.url,c.ts_created,c.content FROM comments c
LEFT JOIN mdauthor a ON a . uuid = c . uuid
LEFT JOIN normalmetadata md ON md . uuid = c . uuid
WHERE a . userid = ? AND a . status = 1 AND c . reply = 0 AND c . id = ?
ORDER BY ts_created DESC " ;
$sth = $this -> db -> prepare ( $sql );
$sth -> execute ( array ( $u_id , $reply ));
$row = $sth -> fetch ();
if ( empty ( $row [ 'id' ]))
{
$data = array ( 'error' => " 回复失败,您没有权限进行此操作 " );
$this -> jsonexit ( $data );
return true ;
}
$ipaddr = $_SERVER [ 'REMOTE_ADDR' ];
$sql = " INSERT INTO comments (uuid,author,reply,userid,content,email,ip) VALUES (?,?,?,?,?,?,?) " ;
$sth = $this -> db -> prepare ( $sql );
$rs = $sth -> execute ( array ( $uuid , $user -> username , $reply , $uid , $body , $email , $ipaddr ));
if ( $rs )
{
$data = array ( 'status' => 1 , 'msg' => '回复成功!' );
$this -> jsonexit ( $data );
return true ;
} else {
$data = array ( 'error' => " 回复失败,请重试 " );
$this -> jsonexit ( $data );
return true ;
}
return true ;
}
if ( $replylist )
{
$this -> _helper -> layout -> disableLayout ();
$this -> _helper -> viewRenderer -> setNoRender ();
$sql = " SELECT cr.id,cr.content as body,cr.reply,u.username,cr.ts_created FROM comments cr
LEFT JOIN users u ON cr . userid = u . id WHERE cr . reply = ? " ;
$sth = $this -> db -> prepare ( $sql );
$sth -> execute ( array ( $replylist ));
$rows = $sth -> fetchAll ();
$this -> jsonexit ( $rows );
return true ;
}
} // commentAction() 数据反馈
/*
* newsAction () 数据新闻
*
* param string $ac
*
*
*/
function newsAction (){
$ac = $this -> _request -> getParam ( 'ac' );
$auth = Zend_Auth :: getInstance ();
if ( $auth -> hasIdentity ())
{
$user = $auth -> getIdentity ();
$u_id = $user -> id ;
}
$News = new Archive ( $this -> db );
$category = new ArchiveCategory ( $this -> db );
//新闻列表
if ( empty ( $ac ) || $ac == " list " )
{
$keyword = $this -> _request -> getParam ( 'q' );
$uuid = $this -> _request -> getParam ( 'uuid' );
$wheresql = array ();
$join = " " ;
if ( ! empty ( $keyword ))
{
$this -> view -> q = $keyword ;
$search = new SimpleSearch ( $keyword );
$wheresql [] = $search -> sql_expr ( array ( " arc.title " , " arc.description " ));
}
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 ))
{
$wheresql [] = " ct.uuid=' $uuid ' " ;
}
$wheresql [] = " c.code=' " . $category -> DataNewsCode . " ' " ;
$wheresql [] = " ct.uuid IS NOT NULL " ;
$wheresql [] = " arc.userid= $u_id " ;
if ( count ( $wheresql ) > 0 )
{
$wheresql = " WHERE " . join ( " AND " , $wheresql );
}
$sql = " SELECT arc.id,arc.title,arc.description,arc.ts_published
, c . id as cid , u . realname
, count ( arc . id ) as datacount
FROM " . $News->tbl_archives . " arc
LEFT JOIN " . $News->tbl_catalog . " ct ON arc . id = ct . aid
LEFT JOIN " . $News->tbl_categorys . " c ON ct . cid = c . id
LEFT JOIN users u ON arc . userid = u . id
$wheresql
GROUP BY arc . id , c . id , u . realname
ORDER BY arc . ts_published DESC " ;
$sth = $this -> db -> prepare ( $sql );
$sth -> execute ();
$rows = $sth -> fetchAll ();
foreach ( $rows as $k => $v )
{
$arcinfo = $News -> getArchiveUrlByCid ( $v [ 'id' ], $v [ 'cid' ]);
$rows [ $k ][ 'url' ] = $arcinfo [ 'archive_url' ];
}
$paginator = Zend_Paginator :: factory ( $rows );
$paginator -> setCurrentPageNumber ( $this -> _getParam ( 'page' ));
$paginator -> setItemCountPerPage ( 10 );
$paginator -> setView ( $this -> view );
Zend_View_Helper_PaginationControl :: setDefaultViewPartial ( 'pagination_param.phtml' );
$this -> view -> paginator = $paginator ;
}
//新闻发布
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 = ? AND a . status = 1
" ;
$sth = $this -> db -> prepare ( $sql );
$sth -> execute ( array ( $u_id ));
$rows = $sth -> fetchAll ();
$this -> view -> md = $rows ;
} // $ac == add
//新闻编辑
if ( $ac == " edit " )
{
$this -> _helper -> viewRenderer ( 'news-edit' );
$aid = ( int ) $this -> _request -> getParam ( 'aid' );
if ( empty ( $aid ) || ! is_numeric ( $aid ))
{
$this -> _redirect ( '/error/error' );
}
$sql = " SELECT arc.* FROM " . $News -> tbl_archives . " arc
WHERE id = ? " ;
$sth = $this -> db -> prepare ( $sql );
$sth -> execute ( array ( $aid ));
$row = $sth -> fetch ();
$keywords = $News -> GetTags ( $aid );
$row [ 'keywords' ] = join ( " , " , $keywords );
$this -> view -> info = $row ;
$sql = " SELECT md.title,md.uuid FROM metadata md
LEFT JOIN mdauthor a ON a . uuid = md . uuid
WHERE a . userid = ? AND a . status = 1
" ;
$sth = $this -> db -> prepare ( $sql );
$sth -> execute ( array ( $u_id ));
$rows = $sth -> fetchAll ();
$this -> view -> md = $rows ;
$sql = " SELECT md.uuid,md.title FROM ar_catalog ct
LEFT JOIN metadata md ON ct . uuid = md . uuid
WHERE ct . aid = $aid " ;
$sth = $this -> db -> query ( $sql );
$rows = $sth -> fetchAll ();
$this -> view -> thismd = $rows ;
} //$ac == "edit"
//新闻发布的ajax动作
if ( $ac == " addnews " )
{
try {
$this -> _helper -> layout -> disableLayout ();
$this -> _helper -> viewRenderer -> setNoRender ();
$data = array ();
$aid = $this -> _request -> getParam ( 'aid' );
$data [ 'title' ] = trim ( $this -> _request -> getParam ( 'title' ));
$data [ 'keyword' ] = trim ( $this -> _request -> getParam ( 'keyword' ));
$data [ 'body' ] = trim ( $this -> _request -> getParam ( 'body' ));
$uuid = $this -> _request -> getParam ( 'uuid' );
//对参数进行预处理
foreach ( $data as $k => $v )
{
$data [ $k ] = preg_replace ( " #<a([^>]*)>(.*)</a>#i " , " " , $v );
$data [ $k ] = preg_replace ( " #<script([^>]*)>(.*)</script>#i " , " " , $v );
$data [ $k ] = preg_replace ( " #<iframe([^>]*)>(.*)</iframe>#i " , " " , $v );
$data [ $k ] = str_replace ( " \" " , " “ " , $v );
$data [ $k ] = str_replace ( " \ ' " , " ‘ " , $v );
}
$msg = array ();
// 合法性判断
if ( mb_strlen ( $data [ 'title' ], " utf-8 " ) < 3 )
{
$msg [ 'status' ] = 0 ;
$msg [ 'error' ] = '标题太短,请重新填写' ;
$this -> getResponse () -> setHeader ( 'Content-Type' , 'application/json' ) -> appendBody ( Zend_Json :: encode ( $msg ));
return true ;
}
if ( mb_strlen ( $data [ 'title' ], " utf-8 " ) > 60 )
{
$msg [ 'status' ] = 0 ;
$msg [ 'error' ] = '标题太长,请重新填写' ;
$this -> getResponse () -> setHeader ( 'Content-Type' , 'application/json' ) -> appendBody ( Zend_Json :: encode ( $msg ));
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 ;
$msg [ 'error' ] = '关键词太短,请重新填写' ;
$this -> getResponse () -> setHeader ( 'Content-Type' , 'application/json' ) -> appendBody ( Zend_Json :: encode ( $msg ));
return true ;
}
if ( mb_strlen ( $data [ 'keyword' ], " utf-8 " ) > 40 )
{
$msg [ 'status' ] = 0 ;
$msg [ 'error' ] = '关键词太长,请重新填写' ;
$this -> getResponse () -> setHeader ( 'Content-Type' , 'application/json' ) -> appendBody ( Zend_Json :: encode ( $msg ));
return true ;
}
if ( mb_strlen ( $data [ 'body' ], " utf-8 " ) < 40 )
{
$msg [ 'status' ] = 0 ;
$msg [ 'error' ] = '新闻内容太短,请重新填写' ;
$this -> getResponse () -> setHeader ( 'Content-Type' , 'application/json' ) -> appendBody ( Zend_Json :: encode ( $msg ));
return true ;
}
if ( is_array ( $uuid ))
{
if ( count ( $uuid ) < 1 )
{
$msg [ 'status' ] = 0 ;
$msg [ 'error' ] = '参数错误,请重试' ;
$this -> getResponse () -> setHeader ( 'Content-Type' , 'application/json' ) -> appendBody ( Zend_Json :: encode ( $msg ));
return true ;
}
foreach ( $uuid as $v )
{
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} $ / " , $v ))
{
$msg [ 'status' ] = 0 ;
$msg [ 'error' ] = '参数错误,请重试' ;
$this -> getResponse () -> setHeader ( 'Content-Type' , 'application/json' ) -> appendBody ( Zend_Json :: encode ( $msg ));
return true ;
}
}
}
else 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 " );
//默认填充数据
$data [ 'source' ] = " 西部数据中心 " ;
$data [ 'userid' ] = $u_id ;
$keyword = str_replace ( " , " , " , " , $data [ 'keyword' ]);
$data [ 'ts_published' ] = date ( " Y-m-d H:i:s " , time ());
$data [ 'is_pub' ] = true ;
$data [ 'image' ] = " " ;
unset ( $data [ 'keyword' ]);
$dataNewsCategory = $category -> GetOne ( 'datanews' );
$dataNewsCategoryID = $dataNewsCategory [ 'id' ];
//新闻添加
if ( empty ( $aid ))
{
$newAid = $News -> addArchive ( $data , $dataNewsCategoryID , $keyword , $uuid );
//添加成功
if ( $newAid > 0 )
{
$msg [ 'status' ] = 1 ;
$msg [ 'outstring' ] = " 新闻添加成功 " ;
$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
{
if ( $u_id != $News -> getArchiveField ( $aid , " userid " ))
{
$msg [ 'status' ] = 0 ;
$msg [ 'outstring' ] = " 新闻编辑失败,您没有权限 " ;
$this -> getResponse () -> setHeader ( 'Content-Type' , 'application/json' ) -> appendBody ( Zend_Json :: encode ( $msg ));
return true ;
}
$updated = $News -> updateArchive ( $aid , $data , $dataNewsCategoryID , $keyword , $uuid );
if ( $updated )
{
$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 -->
} catch ( Exception $e ){
if ( $this -> debug == 0 )
{
$msg [ 'status' ] = 0 ;
if ( empty ( $aid ))
{ $msg [ 'error' ] = " 新闻添加失败,请重试 " ;}
else
{ $msg [ 'error' ] = " 新闻编辑失败,请重试 " ;}
$this -> getResponse () -> setHeader ( 'Content-Type' , 'application/json' ) -> appendBody ( Zend_Json :: encode ( $msg ));
return true ;
} else {
$msg [ 'status' ] = 0 ;
$msg [ 'error' ] = " 新闻添加/编辑失败,请重试: " . $e -> getMessage ();
$this -> getResponse () -> setHeader ( 'Content-Type' , 'application/json' ) -> appendBody ( Zend_Json :: encode ( $msg ));
return true ;
}
} //catch end
} //$ac = 'newsadd' endif;
if ( $ac == " del " )
{
$this -> _helper -> layout -> disableLayout ();
$this -> _helper -> viewRenderer -> setNoRender ();
$aid = $this -> _getParam ( 'aid' );
if ( ! is_numeric ( $aid ))
{
$this -> jsonexit ( array ( " error " => " 参数错误 " ));
return true ;
}
$News = new Archive ( $this -> db );
if ( $u_id != $News -> getArchiveField ( $aid , " userid " ))
{
$this -> jsonexit ( array ( " error " => " 您没有权限 " ));
return true ;
}
if ( $News -> DeleteArchives ( $aid ))
{
$this -> jsonexit ( array ( " deleted " => $aid ));
return true ;
} else {
$this -> jsonexit ( array ( " error " => " 删除失败 " , 'aid' => $aid ));
return true ;
}
}
} //newsAction() 数据新闻
function viewauthorsAction (){
$this -> _helper -> viewRenderer ( 'view-authors' );
$uuid = $this -> _request -> getParam ( 'uuid' );
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 u.realname,u.unit,u.email,m.title,m.description FROM normalmetadata m
LEFT JOIN mdauthor a ON m . uuid = a . uuid
LEFT JOIN users u ON u . id = a . userid
WHERE status >= 0 AND m . uuid = ? AND a . status = 1
ORDER BY status DESC , a . id DESC " ;
$sth = $this -> db -> prepare ( $sql );
$sth -> execute ( array ( $uuid ));
$rows = $sth -> fetchAll ( PDO :: FETCH_BOTH );
include_once ( " helper/view.php " );
view :: addPaginator ( $rows , $this -> view , $this -> _request );
$this -> view -> datas = $rows ;
} else {
$this -> view -> error = " 参数有误 " ;
}
}
/*
* versionAction () 版本控制
*
*
*/
function versionAction ()
{
$ac = $this -> _request -> getParam ( 'ac' );
$uuid = $this -> _request -> getParam ( 'uuid' );
$auth = Zend_Auth :: getInstance ();
if ( $auth -> hasIdentity ())
{
$user = $auth -> getIdentity ();
$u_id = $user -> id ;
}
//查看单条数据的所有版本
if ( ! empty ( $uuid ) && empty ( $ac ))
{
//view the versions of the data
$sql = " SELECT md.title,md.uuid,v.ts_created,v.changelog,v.userid,v.id,u.username,u.realname FROM mdversion v
LEFT JOIN metadata md ON md . uuid = v . uuid
LEFT JOIN mdauthor a ON md . uuid = a . uuid
left join users u on v . userid = u . id
WHERE md . title IS NOT NULL AND a . userid = ? and v . uuid = ? AND a . status = 1
order by v . ts_created desc
" ;
$sth = $this -> db -> prepare ( $sql );
$sth -> execute ( array ( $u_id , $uuid ));
$rows = $sth -> fetchAll ();
@ $this -> view -> mdtitle = $rows [ 0 ][ 'title' ];
$paginator = Zend_Paginator :: factory ( $rows );
$paginator -> setCurrentPageNumber ( $this -> _getParam ( 'page' ));
$paginator -> setItemCountPerPage ( 15 );
$paginator -> setView ( $this -> view );
Zend_View_Helper_PaginationControl :: setDefaultViewPartial ( 'pagination_param.phtml' );
$this -> view -> paginator = $paginator ;
}
//查看所有版本列表
else if (( empty ( $ac ) && empty ( $uuid )) || $ac == 'list' )
{
$sql = " SELECT md.title,md.uuid,v.ts_created,v.changelog,v.userid,v.id,u.username,u.realname FROM mdversion v
LEFT JOIN metadata md ON md . uuid = v . uuid
LEFT JOIN mdauthor a ON md . uuid = a . uuid
left join users u on v . userid = u . id
WHERE md . title IS NOT NULL AND a . userid = ? AND a . status = 1
order by v . ts_created desc
" ;
$sth = $this -> db -> prepare ( $sql );
$sth -> execute ( array ( $u_id ));
$rows = $sth -> fetchAll ();
$paginator = Zend_Paginator :: factory ( $rows );
$paginator -> setCurrentPageNumber ( $this -> _getParam ( 'page' ));
$paginator -> setItemCountPerPage ( 15 );
$paginator -> setView ( $this -> view );
Zend_View_Helper_PaginationControl :: setDefaultViewPartial ( 'pagination_param.phtml' );
$this -> view -> paginator = $paginator ;
}
//按数据浏览
else if ( $ac == " bydata " )
{
$keywords = $this -> _request -> getParam ( 'q' );
if ( ! empty ( $keywords ))
$this -> view -> q = $keywords ;
$sql = " SELECT md.title,md.uuid,count(v.id) as c FROM mdversion v
LEFT JOIN metadata md ON md . uuid = v . uuid
LEFT JOIN mdauthor a ON md . uuid = a . uuid
WHERE md . title IS NOT NULL AND a . userid = ? AND a . status = 1 " ;
if ( ! empty ( $keywords ))
{
$search = new SimpleSearch ( $keywords );
$where = $search -> sql_expr ( array ( " md.title " , " md.description " ));
$sql .= ' and ' . $where ;
}
$sql .= " group by md.uuid,md.title " ;
$sth = $this -> db -> prepare ( $sql );
$sth -> execute ( array ( $u_id ));
$rows = $sth -> fetchAll ();
$paginator = Zend_Paginator :: factory ( $rows );
$paginator -> setCurrentPageNumber ( $this -> _getParam ( 'page' ));
$paginator -> setItemCountPerPage ( 10 );
$paginator -> setView ( $this -> view );
Zend_View_Helper_PaginationControl :: setDefaultViewPartial ( 'pagination_param.phtml' );
$this -> view -> paginator = $paginator ;
$this -> _helper -> viewRenderer ( 'version-bydata' );
}
//删除某个版本
else if ( $ac == " delete " )
{
$this -> _helper -> layout -> disableLayout ();
$this -> _helper -> viewRenderer -> setNoRender ();
$data = " " ;
try {
$id = $this -> _request -> getParam ( 'id' );
if ( empty ( $id ) || ! is_numeric ( $id ))
{
$data = array ( " error " => " 参数错误 " );
$this -> jsonexit ( $data );
return true ;
}
$sql = " DELETE FROM mdversion v
USING mdauthor a
WHERE v . uuid = a . uuid and v . id = ? AND a . userid = ? AND a . status = 1 " ;
$sth = $this -> db -> prepare ( $sql );
$ex = $sth -> execute ( array ( $id , $u_id ));
if ( $ex )
{
$data = array ( " deleted " => $id , " error " => $this -> alertbox ( 'ok' , '删除成功' ));
$this -> jsonexit ( $data );
return true ;
} else {
$data = array ( " error " => $this -> alertbox ( 'error' , '删除失败,请确认权限后重试' ));
$this -> jsonexit ( $data );
return true ;
}
} catch ( Exception $e ) {
$msg = " 删除失败,请确认权限后重试 " ;
if ( $this -> debug > 0 )
{ $msg .= $e -> getMessage ();}
$data = array ( " error " => $this -> alertbox ( 'error' , $msg ));
$this -> jsonexit ( $data );
return true ;
}
}
//恢复到geonetwork
else if ( $ac == " restore " )
{
$this -> _helper -> layout -> disableLayout ();
$this -> _helper -> viewRenderer -> setNoRender ();
$data = " " ;
try {
$id = $this -> _request -> getParam ( 'id' );
if ( empty ( $id ) || ! is_numeric ( $id ))
{
$data = array ( " error " => " 参数错误 " );
$this -> jsonexit ( $data );
return true ;
}
$this -> wdb = Zend_Db :: factory ( $this -> view -> config -> geonetwork );
$sql = " SELECT v.xml,v.uuid FROM mdversion v
LEFT JOIN mdauthor a ON a . uuid = v . uuid
WHERE v . id = ? AND a . userid = ? AND a . status = 1 " ;
$sth = $this -> db -> prepare ( $sql );
$sth -> execute ( array ( $id , $u_id ));
$row = $sth -> fetch ();
$sql = " SELECT data FROM metadata WHERE uuid=? " ;
$sth = $this -> wdb -> prepare ( $sql );
$sth -> execute ( array ( $row [ 'uuid' ]));
$row_geo = $sth -> fetch ();
if ( $row [ 'xml' ] == $row_geo [ 'data' ])
{
$data = array ( " error " => $this -> alertbox ( 'warning' , '无须恢复,元数据相同' ));
$this -> jsonexit ( $data );
return true ;
}
$sql = " UPDATE metadata SET data=? WHERE uuid=? " ;
$sth = $this -> wdb -> prepare ( $sql );
$ex = $sth -> execute ( array ( $row [ 'xml' ], $row [ 'uuid' ]));
if ( $ex )
{
$data = array ( " error " => $this -> alertbox ( 'ok' , '恢复成功' ));
$this -> jsonexit ( $data );
return true ;
} else {
$data = array ( " error " => $this -> alertbox ( 'error' , '恢复失败,请确认权限后重试' ));
$this -> jsonexit ( $data );
return true ;
}
} catch ( Exception $e ) {
$msg = " 恢复失败,请确认权限后重试 " ;
if ( $this -> debug > 0 )
{ $msg .= $e -> getMessage ();}
$data = array ( " error " => $this -> alertbox ( 'error' , $msg ));
$this -> jsonexit ( $data );
return true ;
}
}
//发布到评审
else if ( $ac == " commit " )
{
$this -> _helper -> layout -> disableLayout ();
$this -> _helper -> viewRenderer -> setNoRender ();
$data = " " ;
try {
$id = $this -> _request -> getParam ( 'id' );
if ( empty ( $id ) || ! is_numeric ( $id ))
{
$data = array ( " error " => " 参数错误 " );
$this -> jsonexit ( $data );
return true ;
}
$changelog = $this -> _request -> getParam ( 'changelog' );
if ( empty ( $changelog ))
{
$data = array ( " error " => $this -> alertbox ( 'warning' , '请输入变更信息' ));
$this -> jsonexit ( $data );
return true ;
}
// 1. 权限认定
$sql = " select a.* from mdauthor a left join mdversion v on a.uuid=v.uuid
where a . status = 1 and a . userid = ? and v . id = ? " ;
$sth = $this -> db -> prepare ( $sql );
$sth -> execute ( array ( $u_id , $id ));
$row = $sth -> fetch ();
if ( empty ( $row ))
{
$data = array ( " error " => '无权限修改数据' );
$this -> jsonexit ( $data );
return true ;
}
// 2. 保存变化记录 save changelog & userid
$sql = " UPDATE mdversion SET changelog=?,userid=? WHERE id=? " ;
$this -> db -> query ( $sql , array ( $changelog , $u_id , $id ));
// 3. 获取数据评审状态
$sql = " SELECT s.*,v.xml,m.title FROM mdstatus s left join mdversion v on s.uuid=v.uuid
left join metadata m on s . uuid = m . uuid WHERE v . id = ? " ;
$sth = $this -> db -> prepare ( $sql );
$sth -> execute ( array ( $id ));
$row = $sth -> fetch ();
//update search document
$search = new Search ();
//create search view in xunsearch
//$sql="select m.uuid,m.title,m.description,x.data,array_to_string(ARRAY( SELECT keyword.keyword FROM keyword WHERE keyword.id = m.id), ', '::text) AS keyword from normalmetadata m left join xml x on m.id=x.id where m.uuid=?";
$sql = " select * from xunsearch where uuid=? " ;
$sth = $this -> db -> prepare ( $sql );
$sth -> execute ( array ( $row [ 'uuid' ]));
$data = $sth -> fetch ();
$search -> update ( $data );
if ( empty ( $row )) //无对应记录
{
$sql = " select m.id from metadata m left join mdversion v on m.uuid=v.uuid where v.id=? " ;
$sth = $this -> db -> prepare ( $sql );
$sth -> execute ( array ( $id ));
$mrow = $sth -> fetch ();
if ( empty ( $mrow )) //说明是新数据
{
//导入元数据
$iso = new ISO19115 ();
@ $iso -> loadXML ( $row [ 'xml' ]);
if ( $iso -> validate ())
{
$data = array ( " error " => " 元数据导入过程中发现错误。<br /> " . implode ( " <br /> " , $iso -> error ));
$this -> jsonexit ( $data );
return true ;
}
@ $iso -> saveDB ( $this -> db );
//进入评审库
$sql = " insert into mdstatus (uuid,status,userid) select uuid,0,? from mdversion where id=? " ;
$this -> db -> query ( $sql , array ( $u_id , $id ));
//email to admin
$mail = new WestdcMailer ( $this -> view -> config -> smtp );
$mail -> setFrom ( $this -> view -> config -> service -> email , '西部数据中心服务组' );
$mailtp = new EmailText ( $this -> db , " metadata-new-admin " , array (
'user' => $user -> username ,
'uuid' => $iso -> uuid ,
'email' => $user -> email ,
//元数据标题
'title' => $iso -> resTitle ,
));
$mail -> setBodyText ( $mailtp -> getBody ());
$mail -> setSubject ( $mailtp -> getSubject ());
if ( $this -> debug == 0 )
{
$mail -> addTo ( $this -> view -> config -> service -> email );
} else {
$mail -> addTo ( $this -> debug_email );
}
$mail -> send ();
unset ( $mail );
unset ( $mailtp );
//email to author
$mail = new WestdcMailer ( $this -> view -> config -> smtp );
$mail -> setFrom ( $this -> view -> config -> service -> email , '西部数据中心服务组' );
$mailtp = new EmailText ( $this -> db , " metadata-new-author " , array (
'user' => $user -> username ,
'uuid' => $iso -> uuid ,
'email' => $user -> email ,
//元数据标题
'title' => $iso -> resTitle ,
));
$mail -> setBodyText ( $mailtp -> getBody ());
$mail -> setSubject ( $mailtp -> getSubject ());
if ( $this -> debug == 0 )
{
$mail -> addTo ( $user -> email );
$mail -> addCc ( $this -> view -> config -> service -> email );
} else {
$mail -> addTo ( $this -> debug_email );
}
@ $mail -> send ();
$data = array ( " commited " => 1 , " error " => $this -> alertbox ( 'ok' , '该版本已经成功提交,请等待数据中心进一步处理!' ));
$this -> jsonexit ( $data );
return true ;
} else { //说明是已发布的数据且数据不存在评审信息
//同步元数据
$iso = new ISO19115 ();
@ $iso -> loadXML ( $row [ 'xml' ]);
if ( $iso -> validate ())
{
$data = array ( " error " => " 元数据导入过程中发现错误。<br /> " . implode ( " <br /> " , $iso -> error ));
$this -> jsonexit ( $data );
return true ;
}
@ $iso -> saveDB ( $this -> db );
//移除中间版本
$sql = " delete from mdversion where uuid in (select uuid from mdversion where id=?) and changelog is null " ;
$this -> db -> query ( $sql , array ( $id ));
//修改评审状态为发布,且由其提交的用户进行管理
$sql = " insert into mdstatus (uuid,status,userid) select uuid,6,? from mdversion where id=? " ;
$this -> db -> query ( $sql , array ( $u_id , $id ));
//email to admin & author
$mail = new WestdcMailer ( $this -> view -> config -> smtp );
$mail -> setFrom ( $this -> view -> config -> service -> email , '西部数据中心服务组' );
$mailtp = new EmailText ( $this -> db , " metadata-release " , array (
'user' => $user -> username ,
'uuid' => $row [ 'uuid' ],
'email' => $user -> email ,
//元数据标题
'title' => $row [ 'title' ],
'changelog' => $changelog ,
));
$mail -> setBodyText ( $mailtp -> getBody ());
$mail -> setSubject ( $mailtp -> getSubject ());
if ( $this -> debug == 0 )
{
$mail -> addTo ( $this -> view -> config -> service -> email );
//$mail->addCc($this->view->config->service->email);
} else {
$mail -> addTo ( $this -> debug_email );
}
@ $mail -> send ();
$data = array ( " commited " => 1 , " error " => $this -> alertbox ( 'ok' , '该版本已经成功发布!' ));
$this -> jsonexit ( $data );
return true ;
}
}
else if ( $row [ 'status' ] ==- 1 || $row [ 'status' ] == 0 || $row [ 'status' ] == 1 ) //取消发布的数据,初始状态,已接收
{
//同步元数据
$iso = new ISO19115 ();
@ $iso -> loadXML ( $row [ 'xml' ]);
if ( $iso -> validate ())
{
$data = array ( " error " => " 元数据导入过程中发现错误。<br /> " . implode ( " <br /> " , $iso -> error ));
$this -> jsonexit ( $data );
return true ;
}
@ $iso -> saveDB ( $this -> db );
//email to admin
$mail = new WestdcMailer ( $this -> view -> config -> smtp );
$mail -> setFrom ( $this -> view -> config -> service -> email , '西部数据中心服务组' );
$mailtp = new EmailText ( $this -> db , " version-commit-admin " , array (
'user' => $user -> username ,
'uuid' => $row [ 'uuid' ],
'email' => $user -> email ,
//元数据标题
'title' => $row [ 'title' ],
'changelog' => $changelog ,
));
$mail -> setBodyText ( $mailtp -> getBody ());
$mail -> setSubject ( $mailtp -> getSubject ());
if ( $this -> debug == 0 )
{
$mail -> addTo ( $this -> view -> config -> service -> email );
} else {
$mail -> addTo ( $this -> debug_email );
}
$mail -> send ();
unset ( $mail );
unset ( $mailtp );
//email to author
$mail = new WestdcMailer ( $this -> view -> config -> smtp );
$mail -> setFrom ( $this -> view -> config -> service -> email , '西部数据中心服务组' );
$mailtp = new EmailText ( $this -> db , " version-commit-author " , array (
'user' => $user -> username ,
'uuid' => $row [ 'uuid' ],
'email' => $user -> email ,
//元数据标题
'title' => $row [ 'title' ],
));
$mail -> setBodyText ( $mailtp -> getBody ());
$mail -> setSubject ( $mailtp -> getSubject ());
if ( $this -> debug == 0 )
{
$mail -> addTo ( $user -> email );
$mail -> addCc ( $this -> view -> config -> service -> email );
} else {
$mail -> addTo ( $this -> debug_email );
}
@ $mail -> send ();
$data = array ( " commited " => 1 , " error " => $this -> alertbox ( 'ok' , '该版本已经成功提交并同步,请等待数据中心进一步处理!' ));
$this -> jsonexit ( $data );
return true ;
}
else if ( $row [ 'status' ] == 2 || $row [ 'status' ] == 3 || $row [ 'status' ] == 4 ) //已发送过外审邮件,需由编辑告知变化信息
{
//同步元数据
$iso = new ISO19115 ();
@ $iso -> loadXML ( $row [ 'xml' ]);
//email to admin
$mail = new WestdcMailer ( $this -> view -> config -> smtp );
$mail -> setFrom ( $this -> view -> config -> service -> email , '西部数据中心服务组' );
$mailtp = new EmailText ( $this -> db , " version-commit-admin " , array (
'user' => $user -> username ,
'uuid' => $row [ 'uuid' ],
'email' => $user -> email ,
//元数据标题
'title' => $row [ 'title' ],
'changelog' => $changelog ,
));
$mail -> setBodyText ( $mailtp -> getBody ());
$mail -> setSubject ( $mailtp -> getSubject ());
if ( $this -> debug == 0 )
{
$mail -> addTo ( $this -> view -> config -> service -> email );
} else {
$mail -> addTo ( $this -> debug_email );
}
$mail -> send ();
unset ( $mail );
unset ( $mailtp );
//email to author
$mail = new WestdcMailer ( $this -> view -> config -> smtp );
$mail -> setFrom ( $this -> view -> config -> service -> email , '西部数据中心服务组' );
$mailtp = new EmailText ( $this -> db , " version-commit-author " , array (
'user' => $user -> username ,
'uuid' => $row [ 'uuid' ],
'email' => $user -> email ,
//元数据标题
'title' => $row [ 'title' ],
));
$mail -> setBodyText ( $mailtp -> getBody ());
$mail -> setSubject ( $mailtp -> getSubject ());
if ( $this -> debug == 0 )
{
$mail -> addTo ( $user -> email );
$mail -> addCc ( $this -> view -> config -> service -> email );
} else {
$mail -> addTo ( $this -> debug_email );
}
@ $mail -> send ();
//email to experts
$sql = " select u.username,u.email from mdexpertreview e left join users u on e.id=u.id where e.status in (0,1) and e.uuid=? " ;
$sth = $this -> db -> prepare ( $sql );
$sth -> execute ( array ( $row [ 'uuid' ]));
$experts = $sth -> fetchAll ();
unset ( $mail );
unset ( $mailtp );
$mail = new WestdcMailer ( $this -> view -> config -> smtp );
$mail -> setFrom ( $this -> view -> config -> service -> email , '西部数据中心服务组' );
$mailtp = new EmailText ( $this -> db , " version-commit-expert " , array (
'user' => $user -> username ,
'uuid' => $row [ 'uuid' ],
'email' => $user -> email ,
//元数据标题
'title' => $row [ 'title' ],
));
$mail -> setBodyText ( $mailtp -> getBody ());
$mail -> setSubject ( $mailtp -> getSubject ());
2013-06-11 07:23:54 +00:00
$filecontent = file_get_contents ( " http:// " . $_SERVER [ 'HTTP_HOST' ] . '/service/doc/uuid/' . $row [ 'uuid' ]);
2013-05-06 09:01:14 +00:00
$mail -> createAttachment ( $filecontent , 'application/octet-stream' , Zend_Mime :: DISPOSITION_ATTACHMENT , Zend_Mime :: ENCODING_BASE64 , $row [ 'title' ] . '.doc' );
2013-06-11 07:23:54 +00:00
$filecontent = file_get_contents ( " http:// " . $_SERVER [ 'HTTP_HOST' ] . '/service/pdf/uuid/' . $row [ 'uuid' ]);
2013-05-06 09:01:14 +00:00
$mail -> createAttachment ( $filecontent , 'application/octet-stream' , Zend_Mime :: DISPOSITION_ATTACHMENT , Zend_Mime :: ENCODING_BASE64 , $row [ 'title' ] . '.pdf' );
if ( $this -> debug == 0 )
{
foreach ( $experts as $expert ) $mail -> addTo ( $expert [ 'email' ]);
$mail -> addCc ( $this -> view -> config -> service -> email );
} else {
$mail -> addTo ( $this -> debug_email );
}
@ $mail -> send ();
$data = array ( " commited " => 1 , " error " => $this -> alertbox ( 'ok' , '该版本已经成功提交,请等待数据中心进一步处理!' ));
$this -> jsonexit ( $data );
return true ;
}
else if ( $row [ 'status' ] >= 5 ) //数据已经发布,再次修改后将只通知管理员,保留发布状态
{
//同步元数据
$iso = new ISO19115 ();
@ $iso -> loadXML ( $row [ 'xml' ]);
if ( $iso -> validate ())
{
$data = array ( " error " => " 元数据导入过程中发现错误。<br /> " . implode ( " <br /> " , $iso -> error ));
$this -> jsonexit ( $data );
return true ;
}
@ $iso -> saveDB ( $this -> db );
//移除中间版本
$sql = " delete from mdversion where uuid in (select uuid from mdversion where id=?) and changelog is null " ;
$this -> db -> query ( $sql , array ( $id ));
//email to admin & author
$mail = new WestdcMailer ( $this -> view -> config -> smtp );
$mail -> setFrom ( $this -> view -> config -> service -> email , '西部数据中心服务组' );
$mailtp = new EmailText ( $this -> db , " metadata-release " , array (
'user' => $user -> username ,
'uuid' => $row [ 'uuid' ],
'email' => $user -> email ,
//元数据标题
'title' => $row [ 'title' ],
'changelog' => $changelog ,
));
$mail -> setBodyText ( $mailtp -> getBody ());
$mail -> setSubject ( $mailtp -> getSubject ());
if ( $this -> debug == 0 )
{
$mail -> addTo ( $this -> view -> config -> service -> email );
//$mail->addCc($this->view->config->service->email);
} else {
$mail -> addTo ( $this -> debug_email );
}
@ $mail -> send ();
$data = array ( " commited " => 1 , " error " => $this -> alertbox ( 'ok' , '该版本已经成功发布!' ));
$this -> jsonexit ( $data );
return true ;
}
} catch ( Exception $e ) {
$msg = " 提交失败,请确认权限后重试 " ;
if ( $this -> debug > 0 )
{ $msg .= $e -> getMessage ();}
$data = array ( " error " => $this -> alertbox ( 'error' , $msg ));
$this -> jsonexit ( $data );
return true ;
}
} //发布到评审
//与前一个版本对比
else if ( $ac == " diff " )
{
$this -> _helper -> viewRenderer ( 'version-diff' );
$id = $this -> _request -> getParam ( 'id' );
if ( empty ( $id ) || ! is_numeric ( $id ))
{
$this -> view -> error = " 参数错误 " ;
return true ;
}
$sql = " SELECT v.uuid,md.title FROM mdversion v
LEFT JOIN mdauthor a ON a . uuid = v . uuid
LEFT JOIN metadata md ON v . uuid = md . uuid
WHERE v . id = ? AND a . userid = ? AND a . status = 1 " ;
$sth = $this -> db -> prepare ( $sql );
$sth -> execute ( array ( $id , $u_id ));
$row = $sth -> fetch ();
$sql = " SELECT v.* FROM mdversion v
WHERE v . uuid = ? AND v . id <= ?
ORDER BY v . ts_created DESC
LIMIT ? " ;
$sth = $this -> db -> prepare ( $sql );
$sth -> execute ( array ( $row [ 'uuid' ], $id , 2 ));
$rows = $sth -> fetchAll ();
if ( count ( $rows ) < 2 )
{
$this -> view -> error = " 对比失败:之前没有版本可以对比 " ;
return true ;
}
$this -> view -> info = $row ;
$this -> view -> data = $rows ;
}
} // versionAction() 数据版本管理
//新建元数据
function newdataAction ()
{
$ac = $this -> _request -> getParam ( 'ac' );
$id = $this -> _request -> getParam ( 'id' );
$this -> wdb = Zend_Db :: factory ( $this -> view -> config -> geonetwork );
$auth = Zend_Auth :: getInstance ();
if ( $auth -> hasIdentity ())
{
$user = $auth -> getIdentity ();
$u_id = $user -> id ;
}
//在geonetwork中查看单条数据
if ( ! empty ( $id ) && empty ( $ac ))
{
$this -> view -> url = 'metadata.show?id=' . $id ;
$this -> _helper -> viewRenderer ( 'newdata-view' );
}
//查看属于自己的所有的未提交数据列表
else if (( empty ( $ac ) && empty ( $uuid )) || $ac == 'list' )
{
$sql = " SELECT (regexp_matches(gn.data,'<resTitle>(.*)</resTitle>'))[1] as title,gn.id,gn.uuid FROM geonetworkmetadata gn
WHERE gn . uuid not in ( select uuid from metadata ) and gn . owner = ?
order by gn . id desc
" ;
$sth = $this -> db -> prepare ( $sql );
$sth -> execute ( array ( $u_id ));
$rows = $sth -> fetchAll ();
$paginator = Zend_Paginator :: factory ( $rows );
$paginator -> setCurrentPageNumber ( $this -> _getParam ( 'page' ));
$paginator -> setItemCountPerPage ( 15 );
$paginator -> setView ( $this -> view );
Zend_View_Helper_PaginationControl :: setDefaultViewPartial ( 'pagination_param.phtml' );
$this -> view -> paginator = $paginator ;
}
//元数据导入
else if ( $ac == " import " )
{
$this -> _helper -> viewRenderer ( 'newdata-import' );
}
//从模板新建元数据
else if ( $ac == " add-by-template " )
{
$keywords = $this -> _request -> getParam ( 'q' );
$sql = " select id,(regexp_matches(data,'<resTitle>(.*)</resTitle>'))[1] as title,(owner- $u_id ) as isowner from metadata where istemplate='y' and schemaid='iso19115' " ;
if ( ! empty ( $keywords ))
{
$this -> view -> q = $keywords ;
$search = new SimpleSearch ( $keywords );
$where = $search -> sql_expr ( array ( " data " ));
$sql .= ' and ' . $where ;
}
$sql .= " order by changedate desc " ;
$sth = $this -> wdb -> prepare ( $sql );
$sth -> execute ();
$rows = $sth -> fetchAll ();
$paginator = Zend_Paginator :: factory ( $rows );
$paginator -> setCurrentPageNumber ( $this -> _getParam ( 'page' ));
$paginator -> setItemCountPerPage ( 10 );
$paginator -> setView ( $this -> view );
Zend_View_Helper_PaginationControl :: setDefaultViewPartial ( 'pagination_param.phtml' );
$this -> view -> paginator = $paginator ;
$this -> _helper -> viewRenderer ( 'newdata-add' );
}
else if ( $ac == " add-by-data " )
{
$keywords = $this -> _request -> getParam ( 'q' );
$sql = " SELECT md.title,md.uuid,md.description,gn.id as gid FROM normalmetadata md
left join geonetworkmetadata gn on md . uuid = gn . uuid
WHERE gn . id is not null " ;
if ( ! empty ( $keywords ))
{
$this -> view -> q = $keywords ;
$search = new SimpleSearch ( $keywords );
$where = $search -> sql_expr ( array ( " md.title " , " md.description " ));
$sql .= ' and ' . $where ;
}
$sql .= " order by md.ts_created desc " ;
$sth = $this -> db -> prepare ( $sql );
$sth -> execute ();
$rows = $sth -> fetchAll ();
$paginator = Zend_Paginator :: factory ( $rows );
$paginator -> setCurrentPageNumber ( $this -> _getParam ( 'page' ));
$paginator -> setItemCountPerPage ( 10 );
$paginator -> setView ( $this -> view );
Zend_View_Helper_PaginationControl :: setDefaultViewPartial ( 'pagination_param.phtml' );
$this -> view -> paginator = $paginator ;
$this -> _helper -> viewRenderer ( 'newdata-add-bydata' );
}
//提交数据
else if ( $ac == " commit " )
{
$this -> _helper -> layout -> disableLayout ();
$this -> _helper -> viewRenderer -> setNoRender ();
$data = " " ;
try {
$id = $this -> _request -> getParam ( 'id' );
if ( empty ( $id ) || ! is_numeric ( $id ))
{
$data = array ( " error " => " 参数错误 " );
$this -> jsonexit ( $data );
return true ;
}
$changelog = $this -> _request -> getParam ( 'changelog' );
if ( empty ( $changelog ))
{
$data = array ( " error " => $this -> alertbox ( 'warning' , '请输入变更信息' ));
$this -> jsonexit ( $data );
return true ;
}
// 1. 权限认定: 当前用户必须和其owner相同
// 数据应当没有评审状态,没有作者信息
$sql = " select gn.id from geonetworkmetadata gn
left join mdstatus s on gn . uuid = s . uuid
left join mdauthor a on s . uuid = a . uuid
where s . id is not null and a . id is not null and gn . id = ? " ;
$sth = $this -> db -> prepare ( $sql );
$sth -> execute ( array ( $id ));
$row = $sth -> fetch ();
if ( ! empty ( $row ))
{
$data = array ( " error " => '错误的入口' );
$this -> jsonexit ( $data );
return true ;
}
$sql = " select uuid,data from metadata where id=? and owner=? " ;
$sth = $this -> wdb -> prepare ( $sql );
$sth -> execute ( array ( $id , $u_id ));
$row = $sth -> fetch ();
if ( empty ( $row ))
{
$data = array ( " error " => '无权限修改数据' );
$this -> jsonexit ( $data );
return true ;
}
//首先检查元数据错误
$iso = new ISO19115 ();
@ $iso -> loadXML ( $row [ 'data' ]);
if ( $iso -> validate ())
{
$data = array ( " error " => " 元数据导入过程中发现错误。<br /> " . implode ( " <br /> " , $iso -> error ));
$this -> jsonexit ( $data );
return true ;
}
// 保存数据作者信息
$sql = " insert into mdauthor (uuid,userid,ts_activated,status) values(?,?,now(),1) " ;
$this -> db -> query ( $sql , array ( $row [ 'uuid' ], $u_id ));
// 2. 保存变化记录 save changelog & userid for the latest version
$sql = " UPDATE mdversion SET changelog=?,userid=? WHERE id in (select id from mdversion where uuid=? order by ts_created desc limit 1) " ;
$this -> db -> query ( $sql , array ( $changelog , $u_id , $row [ 'uuid' ]));
2013-05-24 09:02:54 +00:00
file_get_contents ( " http://ftp2.westgis.ac.cn/proftp_upload.php?uuid= " . $row [ 'uuid' ] . " &filelist=1 " );
2013-05-06 09:01:14 +00:00
// 3. 保存数据评审状态
//导入元数据
@ $iso -> saveDB ( $this -> db );
//进入评审库
$sql = " insert into mdstatus (uuid,status,userid) select uuid,0,? from geonetworkmetadata where id=? " ;
$this -> db -> query ( $sql , array ( $u_id , $id ));
//email to admin
$mail = new WestdcMailer ( $this -> view -> config -> smtp );
$mail -> setFrom ( $this -> view -> config -> service -> email , '西部数据中心服务组' );
$mailtp = new EmailText ( $this -> db , " metadata-new-admin " , array (
'user' => $user -> username ,
'uuid' => $iso -> uuid ,
'email' => $user -> email ,
//元数据标题
'title' => $iso -> resTitle ,
));
$mail -> setBodyText ( $mailtp -> getBody ());
$mail -> setSubject ( $mailtp -> getSubject ());
if ( $this -> debug == 0 )
{
$mail -> addTo ( $this -> view -> config -> service -> email );
} else {
$mail -> addTo ( $this -> debug_email );
}
$mail -> send ();
unset ( $mail );
unset ( $mailtp );
//email to author
$mail = new WestdcMailer ( $this -> view -> config -> smtp );
$mail -> setFrom ( $this -> view -> config -> service -> email , '西部数据中心服务组' );
$mailtp = new EmailText ( $this -> db , " metadata-new-author " , array (
'user' => $user -> username ,
'uuid' => $iso -> uuid ,
'email' => $user -> email ,
//元数据标题
'title' => $iso -> resTitle ,
));
$mail -> setBodyText ( $mailtp -> getBody ());
$mail -> setSubject ( $mailtp -> getSubject ());
if ( $this -> debug == 0 )
{
$mail -> addTo ( $user -> email );
$mail -> addCc ( $this -> view -> config -> service -> email );
} else {
$mail -> addTo ( $this -> debug_email );
}
@ $mail -> send ();
$data = array ( " commited " => 1 , " error " => $this -> alertbox ( 'ok' , '该版本已经成功提交,请等待数据中心进一步处理!' ));
$this -> jsonexit ( $data );
return true ;
} catch ( Exception $e ) {
$msg = " 提交失败,请确认权限后重试 " ;
if ( $this -> debug > 0 )
{ $msg .= $e -> getMessage ();}
$data = array ( " error " => $this -> alertbox ( 'error' , $msg ));
$this -> jsonexit ( $data );
return true ;
}
}
//FTP
else if ( $ac == " ftp " )
{
$this -> _helper -> layout -> disableLayout ();
$this -> _helper -> viewRenderer -> setNoRender ();
$uuid = $this -> _getParam ( 'uuid' );
$this -> view -> uuid = $uuid ;
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 ))
{
$data = array (
'error' => " 参数错误 "
);
$this -> jsonexit ( $data );
return true ;
}
//安全检查: uuid必须是当前用户且为新建数据
$sql = " select * from geonetworkmetadata where uuid=? and uuid not in (select uuid from metadata) and owner=? " ;
$sth = $this -> db -> prepare ( $sql );
$sth -> execute ( array ( $uuid , $u_id ));
$row = $sth -> fetch ();
if ( empty ( $row ))
{
$data = array (
'error' => " 参数错误 "
);
$this -> jsonexit ( $data );
return true ;
}
//ftp 用户名
$uname = 'westdc' . $u_id . 'upload' ;
//ftp路径
$homedir = " /disk1/WestDC/upload/ " . $uuid . " / " ;
2013-05-27 02:35:41 +00:00
//ftp用户表
$ftptable = ' pureftp ' ; //ftp2.westgis.ac.cn
2013-05-24 09:02:54 +00:00
$uid = 1002 ;
$gid = 1002 ;
2013-05-06 09:01:14 +00:00
2013-05-24 09:02:54 +00:00
$sql = " SELECT * FROM $ftptable WHERE userid=' $uname ' ORDER BY pkid DESC " ;
2013-05-06 09:01:14 +00:00
$sth = $this -> db -> prepare ( $sql );
$sth -> execute ();
$row = $sth -> fetch ();
//create directory for upload
//server is not localhost, so we need a trick
//$old=umask(0);
//@mkdir($homedir,0777);
//umask($old);
2013-05-24 09:02:54 +00:00
$page = file_get_contents ( 'http://ftp2.westgis.ac.cn/proftp_upload.php?uuid=' . $uuid );
2013-05-06 09:01:14 +00:00
if ( ! empty ( $page )) die ( $page ); //there are errors in visit ftp page
if ( ! empty ( $row [ 'pkid' ]))
{
if ( preg_match ( " /.* " . $uuid . " .*/ " , $row [ 'homedir' ]))
{
$data = array (
'statu' => 1 ,
'user' => $row [ 'userid' ],
'passwd' => $row [ 'passwd' ]
);
$this -> jsonexit ( $data );
return true ;
} else {
$passwd = $this -> genRandomString ( 16 );
//$sql = "UPDATE proftpusers SET passwd=?,uid=?,gid=?,homedir=? WHERE userid=?";
//$sth = $this->db->prepare($sql);
//$rs = $sth->execute(array($passwd,$uid,$gid,$homedir,$uname));
2013-05-24 09:02:54 +00:00
$sql = " update " . $ftptable . " SET passwd=' " . $passwd . " ',uid= " . $uid . " ,gid= " . $gid . " ,homedir=' " . $homedir . " ' WHERE userid=' " . $uname . " ' " ;
2013-05-06 09:01:14 +00:00
$rs = $this -> db -> query ( $sql );
if ( $rs )
{
$data = array (
'statu' => 1 ,
'user' => $uname ,
'passwd' => $passwd
);
$this -> jsonexit ( $data );
return true ;
} else {
$data = array (
'error' => " FTP信息更新失败, 请重试 "
);
$this -> jsonexit ( $data );
return true ;
}
}
}
else {
$passwd = $this -> genRandomString ( 16 );
//$sql = "INSERT INTO proftpusers (userid,passwd,uid,gid,homedir) VALUES (?,?,?,?,?)";
//$sth = $this->db->prepare($sql);
//$rs = $sth->execute(array($uname,$passwd,$uid,$gid,$homedir));
2013-05-24 09:02:54 +00:00
$sql = " insert into " . $ftptable . " (userid,passwd,uid,gid,homedir) values(' " . $uname . " ',' " . $passwd . " ', " . $uid . " , " . $gid . " ,' " . $homedir . " ') " ;
2013-05-06 09:01:14 +00:00
$rs = $this -> db -> query ( $sql );
if ( $rs )
{
$data = array (
'statu' => 1 ,
'user' => $uname ,
'passwd' => $passwd
);
$this -> jsonexit ( $data );
return true ;
} else {
$data = array (
'error' => " FTP信息更新失败, 请重试 "
);
$this -> jsonexit ( $data );
return true ;
}
} //end if
} //ftp
}
//新建元数据
2014-05-24 09:21:04 +00:00
//文献管理
function literatureAction ()
{
$this -> view -> ac = $ac = $this -> _request -> getParam ( 'ac' );
2013-06-27 06:27:59 +00:00
$this -> view -> uuid = $uuid = $this -> _request -> getParam ( 'uuid' );
2014-05-24 09:21:04 +00:00
$id = ( int ) $this -> _request -> getParam ( 'id' );
$keyword = $this -> view -> q = trim ( $this -> _getParam ( 'q' ));
2013-05-06 09:01:14 +00:00
$auth = Zend_Auth :: getInstance ();
if ( $auth -> hasIdentity ())
{
$user = $auth -> getIdentity ();
$u_id = $user -> id ;
}
2014-05-24 09:21:04 +00:00
//安全考虑
if ( ! empty ( $uuid ) && ! view :: isUuid ( $uuid )) die ();
//include_once("helper/view.php");
2013-05-06 09:01:14 +00:00
include_once ( " data/Author.php " );
2014-05-24 09:21:04 +00:00
$reference = new Reference ();
if ( ! empty ( $keyword ))
{
$reference -> keyword = $keyword ;
}
$this -> view -> reference = $reference ;
$this -> view -> page = $this -> _getParam ( 'page' );
$this -> view -> pagelimit = 10 ;
//文献首页:逐数据浏览
if ( empty ( $ac ) && empty ( $uuid ))
{
$this -> view -> referenceType = $reference -> referenceType ();
view :: addPaginator ( $reference -> getReferencesByAuthor ( $u_id ), $this , $this -> view -> pagelimit );
return true ;
}
//逐文献浏览
else if ( $ac == " byliter " )
{
$this -> _helper -> viewRenderer ( 'literature-byliter' );
view :: addPaginator ( $reference -> getReferencesByAuthor ( $u_id , 1 , 0 ), $this , $this -> view -> pagelimit );
return true ;
}
//浏览数据的文献
else if ( ! empty ( $uuid ) && empty ( $ac ))
{
$this -> view -> referenceType = $reference -> referenceType ();
if ( empty ( $keyword ))
{
$this -> _helper -> viewRenderer ( 'literature-viewdata' );
view :: addPaginator ( $reference -> getReferencesByAuthorUUID ( $u_id , $uuid , 0 ), $this , $this -> view -> pagelimit );
} else {
$this -> _helper -> viewRenderer ( 'literature-refsearch' );
$sql = " select title from metadata where uuid=' $uuid ' " ;
$rs = $this -> db -> fetchRow ( $sql );
$this -> view -> mdtitle = $rs [ 'title' ];
view :: addPaginator ( $reference -> fetchReferencesWithUUID ( $uuid ), $this , $this -> view -> pagelimit );
}
return true ;
}
//浏览作者的所有施引文献
else if ( $ac == " cited " )
{
$this -> view -> referenceType = $reference -> referenceType ();
$this -> _helper -> viewRenderer ( 'literature-cited' );
view :: addPaginator ( $reference -> getReferencesByAuthor ( $u_id , 1 , 1 ), $this , $this -> view -> pagelimit );
return true ;
}
//修改排序
else if ( $ac == " order " )
{
2013-05-06 09:01:14 +00:00
$this -> _helper -> layout -> disableLayout ();
$this -> _helper -> viewRenderer -> setNoRender ();
2014-05-24 09:21:04 +00:00
$order = ( int ) $this -> _getParam ( 'order' );
2013-05-06 09:01:14 +00:00
2014-05-24 09:21:04 +00:00
if ( empty ( $id ))
2013-05-06 09:01:14 +00:00
{
$this -> jsonexit ( array ( 'error' => '参数错误' ));
return true ;
}
2014-05-24 09:21:04 +00:00
if ( empty ( $order ))
2013-06-27 06:27:59 +00:00
{
2014-05-24 09:21:04 +00:00
$this -> jsonexit ( array ( 'error' => '请输入排序数字, 除0以外' ));
2013-06-27 06:27:59 +00:00
return true ;
}
2014-05-24 09:21:04 +00:00
$s = $reference -> changeOrderByAuthor ( $u_id , $id , $order );
2013-05-06 09:01:14 +00:00
if ( $s !== true )
{
$this -> jsonexit ( array ( 'error' => '出现错误' ));
return true ;
} else {
$this -> jsonexit ( array ( 'success' => '修改成功!' ));
return true ;
}
2014-05-24 09:21:04 +00:00
}
2013-05-06 09:01:14 +00:00
2014-05-24 09:21:04 +00:00
//移除文献对应关系
else if ( $ac == " remove " )
{
$this -> _helper -> layout -> disableLayout ();
$this -> _helper -> viewRenderer -> setNoRender ();
if ( empty ( $uuid ) || ! is_numeric ( $id ))
{
$this -> jsonexit ( array ( " error " => " 参数错误 " ));
return true ;
}
$ex = $reference -> removeReferenceByAuthor ( $u_id , $id );
if ( $ex )
{
$this -> jsonexit ( array ( " remove " => $id . $uuidå ));
return true ;
} else {
$this -> jsonexit ( array ( " error " => $this -> alertbox ( 'error' , '移除失败,请确认权限后重试' )));
return true ;
}
}
//添加数据文献对应关系
else if ( $ac == " insert " )
{
2013-05-06 09:01:14 +00:00
$this -> _helper -> layout -> disableLayout ();
$this -> _helper -> viewRenderer -> setNoRender ();
$order = ( int ) $this -> _getParam ( 'order' );
if ( empty ( $id ))
{
$this -> jsonexit ( array ( 'error' => '参数错误' ));
return true ;
}
if ( empty ( $order ))
{
$this -> jsonexit ( array ( 'error' => '请输入排序数字, 除0以外' ));
return true ;
}
2014-05-24 09:21:04 +00:00
$s = $reference -> insertMdrefByAuthor ( $u_id , $id , $uuid , $order );
2013-05-06 09:01:14 +00:00
if ( $s !== true )
{
$this -> jsonexit ( array ( 'error' => '出现错误' ));
return true ;
} else {
$this -> jsonexit ( array ( 'success' => '修改成功!' ));
return true ;
}
2014-05-24 09:21:04 +00:00
}
//添加文献信息
else if ( $ac == " add " )
{
2013-06-24 08:58:21 +00:00
$submit = $this -> _request -> getParam ( 'submit' );
if ( ! empty ( $submit ))
{
$this -> _helper -> layout -> disableLayout ();
$this -> _helper -> viewRenderer -> setNoRender ();
$data = " " ;
try {
2014-05-24 09:21:04 +00:00
$ref = $this -> _request -> getParam ( 'ref' );
$reftype = ( int ) $this -> _request -> getParam ( 'reftype' );
$url = $this -> _request -> getParam ( 'url' );
$attid = ( int ) $this -> _request -> getParam ( 'attid' );
$order = ( int ) $this -> _request -> getParam ( 'order_input' );
2013-06-24 08:58:21 +00:00
2014-05-24 09:21:04 +00:00
if ( empty ( $uuid ) || empty ( $ref ) || ! is_numeric ( $reftype ))
{
$data = array ( " error " => " 参数错误 " );
$this -> jsonexit ( $data );
return true ;
}
$sql = " select * from mdauthor where status=1 and userid= $u_id and uuid=' $uuid ' " ;
$rs = $this -> db -> fetchRow ( $sql );
if ( ! $rs )
{
$data = array ( " error " => $this -> alertbox ( 'warning' , '您不是该数据作者,无法添加对应文献信息。' ));
$this -> jsonexit ( $data );
return true ;
}
2013-05-06 09:01:14 +00:00
$sql = " select id from reference where reference=? " ;
$sth = $this -> db -> prepare ( $sql );
$sth -> execute ( array ( trim ( $ref )));
$row = $sth -> fetch ();
2013-06-24 08:58:21 +00:00
2014-05-24 09:21:04 +00:00
if ( empty ( $row [ 'id' ]))
{
$sql = " insert into reference (reference,attid) values(?,?) " ;
$sth = $this -> db -> prepare ( $sql );
$sth -> execute ( array ( trim ( $ref ), $attid ));
$sql = " select id from reference where reference=? " ;
$sth = $this -> db -> prepare ( $sql );
$sth -> execute ( array ( trim ( $ref )));
$row = $sth -> fetch ();
}
$sql = " insert into mdref (uuid,refid,reftype,place) values(?,?,?,?) " ;
$sth = $this -> db -> prepare ( $sql );
$ex = $sth -> execute ( array ( $uuid , $row [ 'id' ], 0 , $order ));
if ( $ex )
{
$data = array ( " commited " => 1 , " error " => $this -> alertbox ( 'ok' , '成功添加文献!' ));
$this -> jsonexit ( $data );
return true ;
} else {
$data = array ( " error " => $this -> alertbox ( 'error' , '提交失败,请确认权限后重试' ));
$this -> jsonexit ( $data );
return true ;
}
} catch ( Exception $e ) {
$msg = " 提交失败,您提交的数据可能已经存在 " ;
if ( $this -> debug > 0 )
{ $msg .= $e -> getMessage ();}
$data = array ( " error " => $this -> alertbox ( 'error' , $msg ));
$this -> jsonexit ( $data );
return true ;
}
} else {
$this -> _helper -> layout -> disableLayout ();
2013-05-06 09:01:14 +00:00
$this -> _helper -> viewRenderer ( 'literature-add' );
$this -> view -> uuid = $this -> _request -> getParam ( 'uuid' );
2014-05-24 09:21:04 +00:00
}
} //添加文献
2013-05-06 09:01:14 +00:00
2014-05-24 09:21:04 +00:00
//文献附件上传
else if ( $ac == 'upload' )
{
$this -> _helper -> layout () -> disableLayout ();
$this -> _helper -> viewRenderer -> setNoRender ();
2013-05-06 09:01:14 +00:00
2014-05-24 09:21:04 +00:00
try {
$files = new files ();
$msg = $files -> upload ( $this -> view -> config -> upload , $_FILES [ 'Filedata' ], 'literature' );
2013-05-06 09:01:14 +00:00
2014-05-24 09:21:04 +00:00
if ( empty ( $msg [ 'error' ]))
{
$msg [ 'error' ] = " " ;
$filename = $msg [ 'db_path' ];
$filesize = $msg [ 'file_size' ];
$filedesc = $this -> _request -> getParam ( 'filedesc' );
$filetype = $msg [ 'file_type' ];
$realname = $msg [ 'realname' ];
2013-05-06 09:01:14 +00:00
2014-05-24 09:21:04 +00:00
$sql = " insert into attachments (filename,filetype,filedesc,userid,filesize,realname) values (' $filename ',' $filetype ',' $filedesc ',' $u_id ',' $filesize ',' $realname ') RETURNING id " ;
$sth = $this -> db -> prepare ( $sql );
$sth -> execute ();
$att = $sth -> fetch ( PDO :: FETCH_ASSOC );
$msg [ 'attid' ] = $attid = $att [ 'id' ];
2013-05-06 09:01:14 +00:00
2014-05-24 09:21:04 +00:00
$msg [ 'html' ] = $realname . '[' . round ( $filesize / 1024 , 2 ) . ' kb]<input type="hidden" name="attid" value="' . $attid . '" /><input type="hidden" name="url" value="/service/attach/id/' . $attid . '" /><div class="cancel"><a href="javascript:;" id="deletebtn_' . $attid . '" title="删除该文件"><img border="0" src="/static/js/uploadify/cancel.png" /></a></div>' ;
echo Zend_Json :: encode ( $msg );
exit ();
} else {
$msg [ 'error' ] = '附件上传失败:' . $msg [ 'error' ];
@ unlink ( $filename );
2013-05-06 09:01:14 +00:00
echo Zend_Json :: encode ( $msg );
exit ();
}
2014-05-24 09:21:04 +00:00
} catch ( Exception $e ){
$msg [ 'error' ] = " 错误: " . $e -> getMessage ();
echo Zend_Json :: encode ( $msg );
exit ();
}
} //文件上传
2013-05-06 09:01:14 +00:00
2014-05-24 09:21:04 +00:00
} //文献管理
2013-05-06 09:01:14 +00:00
//文档管理
function documentAction (){
$ac = $this -> _request -> getParam ( 'ac' );
$auth = Zend_Auth :: getInstance ();
if ( $auth -> hasIdentity ())
{
$user = $auth -> getIdentity ();
$u_id = $user -> id ;
}
if ( empty ( $ac ) || $ac == 'list' || $ac == 'search' )
{
$wheresql = " " ;
$keyword = $this -> _request -> getParam ( 'q' );
if ( $ac == 'search' && ! empty ( $keyword ))
{
$this -> view -> q = $keyword ;
$search = new SimpleSearch ( $keyword );
$wheresql = $search -> sql_expr ( array ( " md.title " ));
}
if ( ! empty ( $wheresql ))
{
$wheresql = " AND " . $wheresql ;
}
$sql = " select count(att.id) as aid,md.title,md.uuid from metadata md
LEFT JOIN mdauthor a ON a . uuid = md . uuid
LEFT JOIN mdattach att ON att . uuid = md . uuid
WHERE a . status >= 1 AND a . userid = ? $wheresql
GROUP BY md . title , md . uuid " ;
$sth = $this -> db -> prepare ( $sql );
$sth -> execute ( array ( $u_id ));
$rows = $sth -> fetchAll ();
$paginator = Zend_Paginator :: factory ( $rows );
$paginator -> setCurrentPageNumber ( $this -> _getParam ( 'page' ));
$paginator -> setItemCountPerPage ( 10 );
$paginator -> setView ( $this -> view );
Zend_View_Helper_PaginationControl :: setDefaultViewPartial ( 'pagination_param.phtml' );
$this -> view -> paginator = $paginator ;
}
if ( $ac == 'view' )
{
$uuid = $this -> _request -> getParam ( 'uuid' );
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 ))
{
$this -> view -> error = " 参数有误! " ;
return true ;
}
$sql = " SELECT title FROM metadata WHERE uuid=? " ;
$sth = $this -> db -> prepare ( $sql );
$sth -> execute ( array ( $uuid ));
$row = $sth -> fetch ();
$this -> view -> title = $row [ 'title' ];
$sql = " SELECT att.*,md.title,md.uuid FROM mdattach mda
LEFT JOIN attachments att ON mda . id = att . id
LEFT JOIN metadata md ON mda . uuid = md . uuid
LEFT JOIN users u ON att . userid = u . id
WHERE md . uuid = ?
" ;
$sth = $this -> db -> prepare ( $sql );
$sth -> execute ( array ( $uuid ));
$rows = $sth -> fetchAll ();
$this -> view -> info = $rows ;
$paginator = Zend_Paginator :: factory ( $rows );
$paginator -> setCurrentPageNumber ( $this -> _getParam ( 'page' ));
$paginator -> setItemCountPerPage ( 10 );
$paginator -> setView ( $this -> view );
Zend_View_Helper_PaginationControl :: setDefaultViewPartial ( 'pagination_param.phtml' );
$this -> view -> paginator = $paginator ;
$this -> _helper -> viewRenderer ( 'document-view' );
}
if ( $ac == 'del' )
{
$this -> _helper -> layout () -> disableLayout ();
$this -> _helper -> viewRenderer -> setNoRender ();
( int ) $id = $this -> _request -> getParam ( 'id' );
$uuid = $this -> _request -> getParam ( 'uuid' );
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 ))
{
exit ();
}
$info = $this -> getFileinfo ( $id );
$filepath = $dataFilePath . $info [ 'filename' ];
try {
$auth = Zend_Auth :: getInstance ();
if ( $auth -> hasIdentity ())
{
$user = $auth -> getIdentity ();
$userid = $user -> id ;
$sql_mdattach = " delete from mdattach where uuid=' $uuid ' and id=' $id ' " ;
$sql = " delete from attachments where id=' $id ' and userid=' $userid ' " ;
if ( $this -> db -> exec ( $sql_mdattach ) > 0 && $this -> db -> exec ( $sql ) > 0 )
{
@ unlink ( $filepath );
echo " ok " ;
}
}
} catch ( Exception $e ){}
//不输出任何错误
} //删除
if ( $ac == 'upload' )
{
$submit = $this -> _request -> getParam ( 'submit' );
if ( empty ( $submit ))
{
$uuid = $this -> _request -> getParam ( 'uuid' );
$this -> view -> uuid = $uuid ;
$this -> _helper -> layout -> disableLayout ();
$this -> _helper -> viewRenderer ( 'document-upload' );
return true ;
}
else
{
$this -> _helper -> layout () -> disableLayout ();
$this -> _helper -> viewRenderer -> setNoRender ();
$uuid = $this -> _getParam ( 'uuid' );
try {
$files = new files ();
$msg = $files -> upload ( $this -> view -> config -> upload , $_FILES [ 'Filedata' ], 'document' );
if ( empty ( $msg [ 'error' ]))
{
$msg [ 'error' ] = " " ;
$filename = $msg [ 'db_path' ];
$filesize = $msg [ 'file_size' ];
$filedesc = $this -> _request -> getParam ( 'filedesc' );
$filetype = $msg [ 'file_type' ];
$realname = $msg [ 'realname' ];
$sql = " insert into attachments (filename,filetype,filedesc,userid,filesize,realname) values (' $filename ',' $filetype ',' $filedesc ',' $u_id ',' $filesize ',' $realname ') RETURNING id " ;
$sth = $this -> db -> prepare ( $sql );
$sth -> execute ();
$att = $sth -> fetch ( PDO :: FETCH_ASSOC );
$msg [ 'attid' ] = $attid = $att [ 'id' ];
$sql = " insert into mdattach (uuid,id) values (' $uuid ',' $attid ') " ;
if ( $this -> db -> exec ( $sql ))
{
$msg [ 'html' ] = $realname . '[' . round ( $filesize / 1024 , 2 ) . ' kb]<input type="hidden" name="atts[]" value="' . $attid . '" /><div class="cancel"><a href="javascript:;" id="deletebtn_' . $attid . '"><img border="0" src="/static/js/uploadify/cancel.png" /></a></div>' ;
echo Zend_Json :: encode ( $msg );
exit ();
} else {
$msg [ 'error' ] = '附件上传失败:写入附件表出错' ;
@ unlink ( $filename );
echo Zend_Json :: encode ( $msg );
exit ();
}
} else {
$msg [ 'error' ] = '附件上传失败:' . $msg [ 'error' ];
@ unlink ( $filename );
echo Zend_Json :: encode ( $msg );
exit ();
}
} catch ( Exception $e ){
$msg [ 'error' ] = " 错误: " . $e -> getMessage ();
echo Zend_Json :: encode ( $msg );
exit ();
}
}
} //文件上传
if ( $ac == 'download' )
{
( int ) $id = $this -> _request -> getParam ( 'id' );
$sql = " select * from attachments where id=' $id ' " ;
$re = $this -> db -> query ( $sql );
$row = $re -> fetch ();
$file = new files ();
$fullPath = $this -> view -> config -> upload . $row [ 'filename' ];
// Parse Info / Get Extension
$fsize = filesize ( $fullPath );
$path_parts = pathinfo ( $fullPath );
$ext = strtolower ( $path_parts [ " extension " ]);
// Determine Content Type
switch ( $ext ) {
case " pdf " : $ctype = " application/pdf " ; break ;
case " exe " : $ctype = " application/octet-stream " ; break ;
case " zip " : $ctype = " application/zip " ; break ;
case " doc " : $ctype = " application/msword " ; break ;
case " xls " : $ctype = " application/vnd.ms-excel " ; break ;
case " ppt " : $ctype = " application/vnd.ms-powerpoint " ; break ;
case " gif " : $ctype = " image/gif " ; break ;
case " png " : $ctype = " image/png " ; break ;
case " jpeg " :
case " jpg " : $ctype = " image/jpg " ; break ;
default : $ctype = " application/force-download " ;
}
$content = file_get_contents ( $fullPath );
$this -> _helper -> layout -> disableLayout ();
$this -> _helper -> viewRenderer -> setNoRender ();
$this -> getResponse () -> setHeader ( 'Content-Type' , 'application/octet-stream' )
-> setHeader ( 'Content-Disposition' , 'attachment; filename="' . $row [ 'realname' ] . '"' )
-> setHeader ( 'Content-Length' , $fsize )
-> setHeader ( 'Content-Type' , 'application/force-download' )
-> setHeader ( 'Content-Type' , 'application/download' )
-> setHeader ( 'Content-Type' , $ctype )
-> 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 );
} //文件下载
} //文档管理
/*
* delegateAction () 委托
*
*
*/
public function delegateAction (){
$ac = $this -> _request -> getParam ( 'ac' );
$uuid = $this -> _request -> getParam ( 'uuid' );
if ( $ac == '' && ! empty ( $uuid ))
{
$auth = Zend_Auth :: getInstance ();
if ( $auth -> hasIdentity ())
{
$user = $auth -> getIdentity ();
$uid = $user -> id ;
}
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 ))
{
$this -> view -> info = " 参数错误 " ;
return true ;
}
$sql = " SELECT * FROM metadata WHERE uuid=? " ;
$sth = $this -> db -> prepare ( $sql );
$sth -> execute ( array ( $uuid ));
$row = $sth -> fetch ();
$this -> view -> metadata = $row ;
//确认一下用户有权限, 如果直接使用update语句无法得到已更改过的状态
//只要是认证后的数据作者,都可以修改数据的委托状态
$sql = " SELECT * FROM mdstatus
WHERE uuid = ? AND userid in ( select userid from mdauthor where status = 1 and uuid = ? ) AND status = ? " ;
$sth = $this -> db -> prepare ( $sql );
$sth -> execute ( array ( $uuid , $uuid , 6 ));
$mds = $sth -> fetch ();
if ( ! empty ( $mds [ 'id' ]))
{
$sql = " UPDATE mdstatus SET status=7,ts_changed='now()',userid= $uid WHERE uuid=' $uuid ' " ;
if ( $this -> db -> exec ( $sql ))
{
$this -> view -> info = " 委托成功! " ;
return true ;
}
else
{
$this -> view -> info = " 委托失败! " ;
return true ;
}
} else {
$this -> view -> info = " 该数据无法委托,请确定数据状态已经可以进行委托,或数据尚未进行委托 " ;
}
}
if ( $ac == 'cancel' )
{
$auth = Zend_Auth :: getInstance ();
if ( $auth -> hasIdentity ())
{
$user = $auth -> getIdentity ();
$uid = $user -> id ;
}
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 ))
{
$this -> view -> info = " 参数错误 " ;
return true ;
}
$sql = " SELECT * FROM metadata WHERE uuid=? " ;
$sth = $this -> db -> prepare ( $sql );
$sth -> execute ( array ( $uuid ));
$row = $sth -> fetch ();
$this -> view -> metadata = $row ;
$sql = " SELECT * FROM mdstatus
WHERE uuid = ? AND userid in ( select userid from mdauthor where status = 1 and uuid = ? ) AND status = ? " ;
$sth = $this -> db -> prepare ( $sql );
$sth -> execute ( array ( $uuid , $uuid , 7 ));
$mds = $sth -> fetch ();
if ( ! empty ( $mds [ 'id' ]))
{
$sql = " UPDATE mdstatus SET status=6,ts_changed='now()',userid= $uid WHERE uuid=' $uuid ' " ;
if ( $this -> db -> exec ( $sql ))
{
$this -> view -> info = " 取消委托成功! " ;
return true ;
}
else
{
$this -> view -> info = " 取消委托失败! " ;
return true ;
}
} else {
$this -> view -> info = " 操作失败!该数据尚未进行委托 " ;
}
}
} //委托
/*
* sendmailAction () 邮件通知
*
* Param uuid $uuid //元数据UUID
*
* return Ajax - response
*
* 传入元数据UUID, 判断是否为当前用户的数据, 如果是, 即可向已经下载过该数据的所有用户发送电子邮件
*/
public function sendmailAction ()
{
$uuid = $this -> _getParam ( 'uuid' );
$ac = $this -> _getParam ( 'ac' );
$auth = Zend_Auth :: getInstance ();
if ( $auth -> hasIdentity ())
{
$user = $auth -> getIdentity ();
$uid = $user -> id ;
}
if ( empty ( $uuid ) || empty ( $uid ))
{
$this -> view -> error = " 参数错误 " ;
return true ;
}
$sql = " SELECT a.*,m.title,m.description,g.id as gid,mds.status as mdstatus,m.uuid FROM normalmetadata m
LEFT JOIN mdauthor a ON m . uuid = a . uuid
LEFT JOIN geonetworkmetadata g on m . uuid = g . uuid
LEFT JOIN mdstatus mds ON m . uuid = mds . uuid
WHERE a . userid = ? AND a . status >= 0 AND m . uuid = ? " ;
$sth = $this -> db -> prepare ( $sql );
$sth -> execute ( array ( $uid , $uuid ));
$metadata = $sth -> fetch ();
if ( empty ( $metadata [ 'uuid' ]))
{
$this -> view -> error = " 数据不存在或者您可能没有该数据的管理权限 " ;
return true ;
}
$this -> view -> metadata = $metadata ;
$sql = " select u.email
from dataorder d
LEFT JOIN users u on d . userid = u . id
WHERE u . email IS NOT NULL
AND d . uuid = ?
GROUP BY u . email " ;
$sth = $this -> db -> prepare ( $sql );
$sth -> execute ( array ( $uuid ));
$mails = $sth -> fetchAll ();
$this -> view -> mailinfo = count ( $mails );
if ( $ac == " send " )
{
$this -> _helper -> layout -> disableLayout ();
$this -> _helper -> viewRenderer -> setNoRender ();
$title = $this -> _getParam ( 'title' );
$body = $this -> _getParam ( 'body' );
foreach ( $mails as $k => $v )
{
$mail = new WestdcMailer ( $this -> view -> config -> smtp );
$mail -> setFrom ( $this -> view -> config -> service -> email , '西部数据中心服务组' );
$mail -> setBodyText ( $body );
$mail -> setSubject ( $title );
if ( $this -> debug == 0 )
{
$mail -> addTo ( $v [ 'email' ]);
} else {
$mail -> addTo ( $debug_email );
}
if ( $mail -> send ())
{
echo $v [ 'email' ] . " ...发送成功!<br /> " ;
} else {
echo $v [ 'email' ] . " ...发送失败!<br /> " ;
}
}
}
}
/*
* staticsAction () 数据统计
*
*
*/
public function staticsAction (){
$ac = $this -> _getParam ( 'ac' );
if ( empty ( $ac ))
{
$this -> view -> alldata = $this -> getClick ();
}
if ( $ac == " md " )
{
$this -> _helper -> viewRenderer ( 'statics-md' );
$this -> view -> allorder = $this -> getStatic ( " allorder " );
$this -> view -> offlineorder = $this -> getStatic ( " offline " );
$this -> view -> onlineorder = $this -> getStatic ( " online " );
}
if ( $ac == " time " )
{
$this -> _helper -> viewRenderer ( 'statics-time' );
$this -> view -> datas = $this -> getStaticByYear ();
}
} //staticsAction() 数据统计
public function getClick (){
$auth = Zend_Auth :: getInstance ();
if ( $auth -> hasIdentity ())
{
$user = $auth -> getIdentity ();
$uid = $user -> id ;
}
$sql = " SELECT md.title,md.uuid,s.viewed,count(o.id) as down FROM metadata md
LEFT JOIN mdstat s ON md . uuid = s . uuid
LEFT JOIN mdauthor a ON md . uuid = a . uuid
LEFT JOIN dataorder o ON md . uuid = o . uuid
WHERE a . userid = ? and a . status = 1 and ( o . status = 0 or o . status = 5 )
GROUP BY md . title , md . uuid , s . viewed " ;
$sth = $this -> db -> prepare ( $sql );
$sth -> execute ( array ( $uid ));
$rows = $sth -> fetchAll ();
return $rows ;
}
/*
* getStaticByYear按月份获取统计数据
*/
public function getStaticByYear ( $year = 0 )
{
$uid = Zend_Auth :: getInstance () -> getIdentity () -> id ;
$sql = " select to_char(o.ts_created, 'YYYY-MM') as d , count(o.id) as c from dataorder o
where o . status in ( 0 , 5 ) and o . uuid in ( select uuid from mdauthor where status = 1 and userid = " . $uid . " ) " ;
if ( $year > 0 )
$sql .= " and o.ts_created between ' $year -01-01' and ' $year -12-31' " ;
$sql .= " group by d order by d desc " ;
$sth = $this -> db -> prepare ( $sql );
$sth -> execute ();
$rows = $sth -> fetchAll ();
return $rows ;
}
public function getStatic ( $ac ){
$auth = Zend_Auth :: getInstance ();
if ( $auth -> hasIdentity ())
{
$user = $auth -> getIdentity ();
$uid = $user -> id ;
}
if ( empty ( $uid )){
return false ;
}
if ( $ac == " allorder " ){
$sql = " SELECT count(o.id) as c FROM metadata md
LEFT JOIN dataorder o ON md . uuid = o . uuid
LEFT JOIN mdauthor a ON md . uuid = a . uuid
WHERE a . userid = ? AND a . status > 0 " ;
$sth = $this -> db -> prepare ( $sql );
$sth -> execute ( array ( $uid ));
$row = $sth -> fetch ();
return $row [ 'c' ];
}
if ( $ac == " offline " ){
$sql = " SELECT count(o.id) as c FROM metadata md
LEFT JOIN dataorder o ON md . uuid = o . uuid
LEFT JOIN mdauthor a ON md . uuid = a . uuid
WHERE o . offlineappid > 0 AND a . userid = ? AND a . status > 0 " ;
$sth = $this -> db -> prepare ( $sql );
$sth -> execute ( array ( $uid ));
$row = $sth -> fetch ();
return $row [ 'c' ];
}
if ( $ac == " online " ){
$sql = " SELECT count(o.id) as c FROM metadata md
LEFT JOIN dataorder o ON md . uuid = o . uuid
LEFT JOIN mdauthor a ON md . uuid = a . uuid
WHERE o . onlineappid > 0 AND a . userid = ? AND a . status > 0 " ;
$sth = $this -> db -> prepare ( $sql );
$sth -> execute ( array ( $uid ));
$row = $sth -> fetch ();
return $row [ 'c' ];
}
}
public function getFileinfo ( $id ){
$sql = " select * from attachments where id=' $id ' " ;
$re = $this -> db -> query ( $sql );
$row = $re -> fetch ();
return $row ;
}
//成为作者后的后继处理工作
private function author_first ( $uuid , $author )
{
$sql = " insert into mdversion (xml,ts_created,uuid,changelog,userid)
select x . data , m . ts_created , ? , ? , ? from metadata m left join xml x on m . id = x . id
left join mdversion v on m . uuid = v . uuid
where m . uuid = ? and v . changelog is null and m . uuid not in ( select uuid from mdversion where changelog is not null )
order by v . ts_created ASC LIMIT 1 " ;
$sth = $this -> db -> prepare ( $sql );
try
{
$sth -> execute ( array ( $uuid , '初始版本 version 1.0' , $author , $uuid ));
} catch ( Exception $e ){
// do nothing here.
// 说明之前已经有对应数据
}
$this -> wdb = Zend_Db :: factory ( $this -> view -> config -> geonetwork );
$sql = " update metadata set owner=? where uuid=? " ;
$sth = $this -> wdb -> prepare ( $sql );
$sth -> execute ( array ( $author , $uuid ));
}
/*
* metadata () 新建元数据
*
*
*
*/
public function metadataAction ()
{
$auth = Zend_Auth :: getInstance ();
if ( $auth -> hasIdentity ())
{
$user = $auth -> getIdentity ();
$uid = $user -> id ;
}
$ac = $this -> _getParam ( 'ac' );
if ( empty ( $ac ))
{
include_once ( " MetaData.php " );
$md = new Metadata ( $this -> db );
$this -> view -> Field = $md -> MetadataFields ;
$MDList = $md -> getRecord ( $uid );
if ( ! empty ( $MDList ))
{
foreach ( $MDList as $k => $v )
{
$MDList [ $k ][ 'content' ] = json_decode ( $v [ 'content' ]);
}
$this -> view -> MDList = $MDList ;
}
}
if ( $ac == " new " )
{
$this -> _helper -> viewRenderer ( 'metadata-new' );
include_once ( " MetaData.php " );
$md = new Metadata ( $this -> db );
$this -> view -> Field = $md -> MetadataFields ;
$uuid = $this -> _getParam ( 'uuid' );
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 ))
{
$this -> view -> error = " 参数错误 " ;
return true ;
}
else {
$this -> view -> uuid = $uuid ;
if ( ! empty ( $uuid )){
$datas = $md -> getRecord ( $uid , $uuid );
$data = json_decode ( $datas [ 'content' ]);
$this -> view -> data = $data ;
return true ;
}
}
} //创建元数据页面
if ( $ac == " del " )
{
$this -> _helper -> layout -> disableLayout ();
$this -> _helper -> viewRenderer -> setNoRender ();
$uuid = $this -> _getParam ( 'uuid' );
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 ))
{
$this -> jsonexit ( array ( 'error' => " 参数错误 " ));
return true ;
}
$sql = " DELETE FROM metadata_temp WHERE userid=? AND uuid=? " ;
$sth = $this -> db -> prepare ( $sql );
$rs = $sth -> execute ( array ( $uid , $uuid ));
if ( $rs > 0 )
{
$this -> jsonexit ( array ( 'msg' => " 删除成功 " , 'deleted' => 1 ));
return true ;
} else {
$this -> jsonexit ( array ( 'error' => " 删除失败,请刷新页面后查看 " ));
return true ;
}
return true ;
} //删除
if ( $ac == " save " )
{
$this -> _helper -> layout -> disableLayout ();
$this -> _helper -> viewRenderer -> setNoRender ();
include_once ( " MetaData.php " );
$md = new Metadata ( $this -> db );
$uuid = $this -> _getParam ( 'uuid' );
$commit = $this -> _getParam ( 'commit' );
$data = array ();
foreach ( $md -> MetadataFields as $k => $v )
{
$data [ $v [ 'FieldName_temp' ]] = $this -> _getParam ( $v [ 'FieldName' ]);
if ( ! empty ( $commit ))
{
if ( isset ( $v [ 'Required' ]) && $v [ 'Required' ] == true )
{
if ( $v [ 'Type' ] == 'varchar' || $v [ 'Type' ] == 'text' )
{
if ( empty ( $data [ $v [ 'FieldName_temp' ]]))
{
$this -> jsonexit ( array ( " error " => $v [ 'Title' ] . " 必须填写 " ));
return true ;
}
} // 文本数据
if ( $v [ 'Type' ] == 'array' )
{
if ( ! is_array ( $data [ $v [ 'FieldName_temp' ]]) || count ( $data [ $v [ 'FieldName_temp' ]]) < 1 )
{
$this -> jsonexit ( array ( " error " => $v [ 'Title' ] . " 信息不完整 " ));
return true ;
} //数组没有值
foreach ( $data [ $v [ 'FieldName_temp' ]] as $sk => $sv )
{
if ( empty ( $sv ))
{
unset ( $data [ $v [ 'FieldName_temp' ]][ $sk ]);
}
if ( is_array ( $sv ))
{
$error_cu = 0 ;
foreach ( $sv as $sub_val )
{
if ( empty ( $sub_val ))
{
$error_cu ++ ;
}
}
if ( $error_cu >= count ( $sv ))
{
unset ( $data [ $v [ 'FieldName_temp' ]][ $sk ]);
$error_cu = 0 ;
}
if ( $error_cu > 0 && $error_cu < count ( $sv )){
$this -> jsonexit ( array ( " error " => $v [ 'Title' ] . " 信息不完整 " ));
return true ;
}
}
}
if ( count ( $data [ $v [ 'FieldName_temp' ]]) < 1 )
{
$this -> jsonexit ( array ( " error " => $v [ 'Title' ] . " 必须填写 " ));
return true ;
}
} // 数组数据
} // 是否必填
} // empty($commit)
} // end foreach
if ( empty ( $data [ 'title' ]))
{
$this -> jsonexit ( array ( " error " => " 元数据标题必须填写 " ));
return true ;
}
if ( ! empty ( $commit ))
{
$status = 1 ;
} else {
$status = 0 ;
}
if ( ! empty ( $uuid ))
{
$rs = $md -> Record ( $uid , $data , $status , $uuid );
} else {
$rs = $md -> Record ( $uid , $data , $status );
}
if ( $rs !== false )
{
if ( ! empty ( $commit ))
{
$data = array ( " uuid " => $rs , " complete " => $commit );
} else {
$data = array ( " uuid " => $rs , 'saved' => 1 );
}
$this -> jsonexit ( $data );
return true ;
} else {
$this -> jsonexit ( array ( " error " => '保存失败' ));
return false ;
}
} // 新元数据保存
if ( $ac == " autoinput " )
{
$this -> _helper -> layout -> disableLayout ();
$this -> _helper -> viewRenderer -> setNoRender ();
$name = $this -> _getParam ( 'k' );
$name = strip_tags ( trim ( $name ));
if ( ! empty ( $name ))
{
$sql = " SELECT realname,email FROM users WHERE realname LIKE ? OR email LIKE ? " ;
$sth = $this -> db -> prepare ( $sql );
$sth -> execute ( array ( '%' . $name . '%' , '%' . $name . '%' ));
$rows = $sth -> fetchAll ();
$this -> jsonexit ( $rows );
}
}
if ( $ac == " process " )
{
$this -> _helper -> layout -> disableLayout ();
$this -> _helper -> viewRenderer -> setNoRender ();
$uuid = $this -> _getParam ( 'uuid' );
$sql = " SELECT * FROM metadata_temp WHERE uuid=? AND userid=? " ;
$sth = $this -> db -> prepare ( $sql );
$sth -> execute ( array ( $uuid , $uid ));
$row = $sth -> fetch ();
$body = json_decode ( $row [ 'content' ]);
echo " <pre> " ;
print_r ( $body );
echo " </pre> " ;
return true ;
} // 元数据处理
} //metadata()
public function fundAction ()
{
//$this->_helper->layout->setLayout('administry');
$ac = $this -> _getParam ( 'ac' );
$submit = $this -> _getParam ( 'submit' );
include_once ( " data/Fund.php " );
2013-05-21 23:26:17 +00:00
include_once ( " helper/view.php " );
2013-05-06 09:01:14 +00:00
$fund = new Fund ( $this -> db );
$auth = Zend_Auth :: getInstance ();
if ( $auth -> hasIdentity ())
{
$user = $auth -> getIdentity ();
$uid = $user -> id ;
} else {
exit ( " 请重新登录 " );
}
if ( $ac == 'index' || empty ( $ac ))
{
2013-05-29 07:36:44 +00:00
$uuid = $this -> _getParam ( 'uuid' );
2013-05-28 05:36:26 +00:00
$this -> view -> q = $this -> _getParam ( 'q' );
2013-05-06 09:01:14 +00:00
if ( empty ( $uuid ))
{
2013-05-28 05:36:26 +00:00
$rows = $fund -> fetch ( " " , true , 0 , $this -> _getParam ( 'q' ));
2013-05-21 23:26:17 +00:00
view :: addPaginator ( $rows , $this -> view , $this -> _request );
2013-05-06 09:01:14 +00:00
} else {
include ( 'data/Metadata.php' );
$md = new Metadata ( $this -> db );
$this -> view -> md = $md -> view ( $uuid );
$rows = $fund -> fetch ( $uuid );
2013-05-21 23:26:17 +00:00
view :: addPaginator ( $rows , $this -> view , $this -> _request );
2013-05-06 09:01:14 +00:00
}
return true ;
}
2013-05-22 07:06:30 +00:00
if ( $ac == 'data' )
{
$this -> _helper -> viewRenderer ( 'fund-data' );
$this -> view -> q = $q = $this -> _getParam ( 'q' );
2013-05-28 05:36:26 +00:00
$rows = $fund -> fetchFromData ( true , $uid , $q );
2013-05-22 09:13:50 +00:00
view :: addPaginator ( $rows , $this -> view , $this -> _request );
return true ;
}
if ( $ac == 'dataview' )
{
$this -> _helper -> viewRenderer ( 'fund-data-view' );
$this -> view -> q = $q = $this -> _getParam ( 'q' );
$id = $this -> _getParam ( 'id' );
$this -> view -> fund = $fund -> view ( $id );
2013-05-28 05:36:26 +00:00
$rows = $fund -> fetchFromData ( $id , $uid , $q );
2013-05-22 09:13:50 +00:00
view :: addPaginator ( $rows , $this -> view , $this -> _request );
2013-05-22 07:06:30 +00:00
return true ;
}
2013-05-06 09:01:14 +00:00
if ( $ac == " add " )
{
$this -> _helper -> viewRenderer ( 'fund-add' );
2013-05-31 02:48:56 +00:00
$uuid = $this -> _getParam ( 'uuid' );
if ( ! empty ( $uuid ))
{
include ( 'data/Metadata.php' );
$md = new Metadata ( $this -> db );
$this -> view -> md = $md -> view ( $uuid );
}
2013-05-06 09:01:14 +00:00
if ( ! empty ( $submit ))
{
$data = $fund -> _getParams ( $this -> _request );
$data [ 'userid' ] = $uid ;
2013-05-31 02:48:56 +00:00
if ( empty ( $uuid ))
{
$s = $fund -> add ( $data );
} else {
$s = $fund -> add ( $data , $uuid );
}
if ( $s == true )
2013-05-06 09:01:14 +00:00
{
$this -> view -> AlertType = " alert-success " ;
$this -> view -> msg = " 添加成功! " ;
$this -> view -> jump_url = " /author/fund/ " ;
return true ;
} else {
$this -> view -> data = $data ;
$this -> view -> error = " 添加失败,请重试 " ;
return true ;
}
}
return true ;
} //add
if ( $ac == " edit " )
{
$this -> _helper -> viewRenderer ( 'fund-add' );
$id = $this -> _getParam ( 'id' );
if ( empty ( $id ))
{
$this -> view -> AlertType = " alert-error " ;
$this -> view -> msg = " 参数错误 " ;
$this -> view -> jump_url = " /author/fund/ " ;
}
if ( ! empty ( $submit ))
{
$data = $fund -> _getParams ( $this -> _request );
$data [ 'userid' ] = $uid ;
$state = $fund -> update ( $data , $id , $uid );
if ( $state == true )
{
$this -> view -> AlertType = " alert-success " ;
$this -> view -> msg = " 修改成功! " ;
$this -> view -> jump_url = " /author/fund/ " ;
return true ;
} else {
$this -> view -> data = $data ;
if ( is_string ( $state ))
{
$this -> view -> error = $state ;
} else {
$this -> view -> error = " 修改失败,请重试 " ;
}
return true ;
}
} else {
$this -> view -> data = $fund -> view ( $id );
}
return true ;
} //edit
if ( $ac == " del " )
{
$this -> _helper -> layout -> disableLayout ();
$this -> _helper -> viewRenderer -> setNoRender ();
$id = $this -> _getParam ( 'id' );
if ( empty ( $id ))
{
$this -> jsonexit ( array ( 'error' => '参数错误' ));
return true ;
}
if ( $fund -> delete ( $id , $uid ) == true )
{
$this -> jsonexit ( array ( 'success' => $id ));
return true ;
} else {
$this -> jsonexit ( array ( 'error' => '删除失败' ));
return true ;
}
} //del
if ( $ac == " formd " )
{
$uuid = $this -> _getParam ( 'uuid' );
if ( empty ( $uuid ))
{
$this -> view -> AlertType = " alert-error " ;
$this -> view -> msg = " 参数错误 " ;
$this -> view -> jump_url = " /admin/data/fund/ " ;
}
$id = $this -> _getParam ( 'id' );
$order = $this -> _getParam ( 'order' );
if ( ! empty ( $id ))
{
if ( $fund -> addToMdfund ( $uuid , $id , $order ))
{
$this -> view -> AlertType = " alert-success " ;
$this -> view -> error = " 添加成功!可以继续选择并添加 " ;
} else {
$this -> view -> AlertType = " alert-error " ;
$this -> view -> error = " 添加失败!该数据可能已被添加 " ;
}
}
2013-05-29 07:36:44 +00:00
$mfid = $this -> _getParam ( 'mfid' );
2013-05-28 05:36:26 +00:00
$this -> view -> q = $this -> _getParam ( 'q' );
2013-05-06 09:01:14 +00:00
if ( ! empty ( $mfid ))
{
if ( $fund -> changeorder ( $mfid , $order ))
{
$this -> view -> AlertType = " alert-success " ;
$this -> view -> error = " 排序修改成功! " ;
} else {
$this -> view -> AlertType = " alert-error " ;
$this -> view -> error = " 排序修改失败! " ;
}
2013-05-28 05:36:26 +00:00
$rows = $fund -> fetch ( $uuid , true , 0 );
2013-05-06 09:01:14 +00:00
} else {
2013-05-29 07:36:44 +00:00
$this -> view -> ct = " ct " ;
2013-05-28 05:36:26 +00:00
$rows = $fund -> fetch ( $uuid , false , 0 , $this -> _getParam ( 'q' ));
2013-05-06 09:01:14 +00:00
}
include ( 'data/Metadata.php' );
$md = new Metadata ( $this -> db );
$this -> view -> md = $md -> view ( $uuid );
2013-05-21 23:27:58 +00:00
view :: addPaginator ( $rows , $this -> view , $this -> _request );
2013-05-06 09:01:14 +00:00
return true ;
} //formd
if ( $ac == " mdfunddel " )
{
$this -> _helper -> layout -> disableLayout ();
$this -> _helper -> viewRenderer -> setNoRender ();
$id = $this -> _getParam ( 'id' );
if ( empty ( $id ))
{
$this -> jsonexit ( array ( 'error' => '参数错误' ));
return true ;
}
if ( $fund -> mfdelete ( $id ) == true )
{
$this -> jsonexit ( array ( 'success' => $id ));
return true ;
} else {
$this -> jsonexit ( array ( 'error' => '删除失败' ));
return true ;
}
} //mdfunddel
} //fund
public function doiAction ()
{
//$this->_helper->layout->setLayout('administry');
$ac = $this -> _getParam ( 'ac' );
$submit = $this -> _getParam ( 'submit' );
$uuid = $this -> _getParam ( 'uuid' );
include_once ( " data/Doi.php " );
$doi = new Doi ( $this -> db );
include_once ( " helper/view.php " );
if ( empty ( $ac ) || $ac == " index " )
{
$uid = view :: User ( 'id' );
if ( empty ( $uuid ))
{
$rows = $doi -> fetch ( $uid );
view :: addPaginator ( $rows , $this -> view , $this -> _request );
} else {
$this -> _redirect ( '/author/doi/ac/edit/?uuid=' . $uuid );
return true ;
}
return true ;
} //index
if ( $ac == " edit " )
{
$this -> _helper -> viewRenderer ( 'doi-add' );
$id = $this -> _getParam ( 'id' );
if ( empty ( $uuid ) && empty ( $id ))
{
view :: Msg ( 'alert-error' , " 参数错误 " , - 1 );
return false ;
}
if ( empty ( $submit )){
if ( ! empty ( $uuid ))
{
$this -> view -> uuid = $uuid ;
$this -> view -> data = $doi -> view ( $uuid );
if ( empty ( $this -> view -> data ))
{
include ( 'data/Metadata.php' );
$md = new Metadata ( $this -> db );
$metadata = $md -> view ( $uuid );
$this -> view -> data = array (
'uuid' => $uuid ,
'title' => $metadata [ 'title' ],
'doi' => $metadata [ 'doi' ],
'url' => " http:// " . $_SERVER [ 'HTTP_HOST' ] . '/data/' . $uuid ,
'publisher' => '寒区旱区科学数据中心' ,
2013-05-06 09:22:26 +00:00
'title_en' => $metadata [ 'title_en' ],
'publisher_en' => 'Cold and Arid Regions Science Data Center at Lanzhou' ,
2013-05-06 09:01:14 +00:00
);
} else {
$this -> view -> data [ 'info' ] = $doi -> data_process_out ( $this -> view -> data );
}
} else {
$this -> view -> data = $doi -> view ( $uuid );
$this -> view -> data [ 'info' ] = $doi -> data_process_out ( $this -> view -> data );
}
} else {
$data = $doi -> _getParams ( $this -> _request );
$this -> view -> data = $data ;
$info = $doi -> checkinfo ( $data [ 'info' ]);
if ( ! is_array ( $info )){
2013-05-09 03:53:27 +00:00
$this -> view -> error = view :: Error ( $info );
2013-05-06 09:01:14 +00:00
return true ;
} else {
$data [ 'info' ] = $info ;
2013-05-09 03:53:27 +00:00
$data [ 'info' ] = $doi -> sksort ( $data [ 'info' ], " order " , SORT_ASC );
2013-05-06 09:01:14 +00:00
}
$uid = view :: User ( 'id' );
$state = $doi -> update ( $data , $uuid , $uid );
if ( $state )
{
$this -> view -> msg = view :: Msg ( 'alert-success' , " 修改成功! " , '/author/doi/uuid/' . $uuid );
return false ;
} else {
2013-05-09 03:53:27 +00:00
$this -> view -> error = view :: Error ( " 修改失败 " );
2013-05-06 09:01:14 +00:00
return false ;
}
}
} //edit
if ( $ac == " del " )
{
$this -> _helper -> layout -> disableLayout ();
$this -> _helper -> viewRenderer -> setNoRender ();
$id = $this -> _getParam ( 'id' );
if ( empty ( $id ))
{
$this -> jsonexit ( array ( 'error' => '参数错误' ));
return true ;
}
if ( $doi -> delete ( $id ) == true )
{
$this -> jsonexit ( array ( 'success' => $id ));
return true ;
} else {
$this -> jsonexit ( array ( 'error' => '删除失败' ));
return true ;
}
} //del
} //doi
/*
* jsonexit () 退出并返回json数据
*
* param array $data 要返回的JSON数据, 可以是任意数组
*
* return JSON - response
*/
public function jsonexit ( $data ){
$this -> getResponse () -> setHeader ( 'Content-Type' , 'application/json' ) -> appendBody ( Zend_Json :: encode ( $data ));
return true ;
} //jsonexit() 退出并返回json数据
private function genRandomString ( $len )
{
$chars = array (
" a " , " b " , " c " , " d " , " e " , " f " , " g " , " h " , " i " , " j " , " k " ,
" l " , " m " , " n " , " o " , " p " , " q " , " r " , " s " , " t " , " u " , " v " ,
" w " , " x " , " y " , " z " , " A " , " B " , " C " , " D " , " E " , " F " , " G " ,
" H " , " I " , " J " , " K " , " L " , " M " , " N " , " O " , " P " , " Q " , " R " ,
" S " , " T " , " U " , " V " , " W " , " X " , " Y " , " Z " , " 0 " , " 1 " , " 2 " ,
" 3 " , " 4 " , " 5 " , " 6 " , " 7 " , " 8 " , " 9 "
);
$charsLen = count ( $chars ) - 1 ;
shuffle ( $chars ); // 将数组打乱
$output = " " ;
for ( $i = 0 ; $i < $len ; $i ++ )
{
$output .= $chars [ mt_rand ( 0 , $charsLen )];
}
return $output ;
}
//ajax 提示框
public function alertbox ( $type = '' , $body ){
if ( $type == " error " )
{
$img = '<img src="/images/alert_big_error.png" />' ;
$text = '<h4>' . $body . '</h4>' ;
return $img . $text ;
}
if ( $type == " ok " )
{
$img = '<img src="/images/alert_big_ok.png" />' ;
$text = '<h4>' . $body . '</h4>' ;
return $img . $text ;
}
if ( $type == " warning " )
{
$img = '<img src="/images/alert_big_warning.png" />' ;
$text = '<h4>' . $body . '</h4>' ;
return $img . $text ;
}
if ( empty ( $type ))
{
$text = '<h4>' . $body . '</h4>' ;
return $text ;
}
}
}