<?php
if ( !defined( "SAXUE_CORE_INCLUDE" ) ) {
		include "../../core.php";
} 
saxue_checkpower( 'message' );
include SAXUE_ROOT_PATH . "/model/member_message.php";
$message_handler = &saxuemembermessagehandler :: getinstance( "saxuemembermessagehandler" );
if ( !empty( $_REQUEST['action'] ) && $_REQUEST['action'] == 'delete' && !empty( $_REQUEST['ids'] ) && is_array( $_REQUEST['ids'] ) && count( $_REQUEST['ids'] ) > 0 ) {
		$message_handler -> db -> query( "DELETE FROM " . saxue_dbprefix( "member_message" ) . " WHERE messageid IN(" . implode( ',', $_REQUEST['ids'] ) . ")" );
		if ( empty( $_REQUEST['jumpurl'] ) ) {
				saxue_jumppage( 'message.php', LANG_DO_SUCCESS );
		} else {
				saxue_jumppage( $_REQUEST['jumpurl'], LANG_DO_SUCCESS );
		}
}
saxue_loadlang( "message" );
if ( empty( $_REQUEST['pagesize'] ) || !is_numeric( $_REQUEST['pagesize'] ) || !in_array( $_REQUEST['pagesize'], array( '10', '30', '50', '100' ) ) ) $_REQUEST['pagesize'] = 30;
if ( empty( $_REQUEST['page'] ) || !is_numeric( $_REQUEST['page'] ) ) $GLOBALS['_REQUEST']['page'] = 1;
include_once( SAXUE_ADMIN_PATH . "/header.php" );
$rows = array();
$criteria = new criteriacompo();
if ( !empty( $_REQUEST['issystem'] ) ) {
		$criteria -> add( new criteria( 'fromid', 0 ) );
}
if ( !empty( $_REQUEST['keyword'] ) && !empty( $_REQUEST['keytype'] ) ) {
		$criteria -> add( new criteria( $_REQUEST['keytype'], "%" . $_REQUEST['keyword'] . "%", "LIKE" ) );
} 
$criteria -> setsort( "messageid" );
$criteria -> setorder( "DESC" );
$criteria -> setlimit( $_REQUEST['pagesize'] );
$criteria -> setstart( ( $_REQUEST['page'] - 1 ) * $_REQUEST['pagesize'] );
$message_handler -> queryobjects( $criteria );
$k = 0;
while ( $v = $message_handler -> getobject() ) {
		$rows[$k] = $v -> getvars( "n" );
		++$k;
} 
$saxueTpl -> assign_by_ref( "rows", $rows );
include_once( SAXUE_ROOT_PATH . "/lib/util/page.php" );
$jumppage = new saxuepage( $message_handler -> getcount( $criteria ), $_REQUEST['pagesize'], $_REQUEST['page'] );
$saxueTpl -> assign( "url_jumppage", $jumppage -> whole_bar() );
$saxueTpl -> setcaching( 0 );
$saxueTset['saxue_contents_template'] = SAXUE_WEB_PATH . "/member/templates/message.html";
include_once( SAXUE_ADMIN_PATH . "/footer.php" );
