<?php
/*
会员列表区块
参数1：会员数，默认10，可用参数：大于0整数（显示最新注册会员）
参数2：排序字段，默认uid，可用参数：uid（会员ID序号），views（访问数），follows（关注数），tops（粉丝数），score（积分数），money（资产数）
参数3：是否有头像，默认0，可用参数：0（全部会员），1（有头像会员）
*/
class blockuserlist extends saxueblock {
		public $template = "block_userlist.html";
		public $exevars = array( 'listnum' => 10, 'field' => 'uid', 'avatar' => 0 );
		public function blockuserlist( &$_vars ) {
				$this -> saxueblock( $_vars );
				if ( !empty( $this -> blockvars['vars'] ) ) {
						$_fieldarr = explode( ",", trim( $this -> blockvars['vars'] ) );
						$_fieldcount = count( $_fieldarr );
						if ( 0 < $_fieldcount ) {
								$_fieldarr[0] = trim( $_fieldarr[0] );
								if ( is_numeric( $_fieldarr[0] ) && 0 < $_fieldarr[0] ) {
										$this -> exevars['listnum'] = intval( $_fieldarr[0] );
								} 
						}
						if ( 1 < $_fieldcount ) {
								$_fieldarr[1] = trim( $_fieldarr[1] );
								if ( in_array( $_fieldarr[1], array( "uid", "score", "money", "views", "follows", "fans" ) ) ) {
										$this -> exevars['field'] = $_fieldarr[1];
								} 
						} 
						if ( 2 < $_fieldcount ) {
								$_fieldarr[2] = trim( $_fieldarr[2] );
								if ( in_array( $_fieldarr[2], array( "0", "1" ) ) ) {
										$this -> exevars['avatar'] = $_fieldarr[2];
								} 
						} 
				} 
				$this -> blockvars['cacheid'] = md5( serialize( $this -> exevars ) . "|" . $this -> blockvars['template'] );
		} 
		public function setcontent( $isreturn = false ) {
				global $saxueTpl;
				global $users_handler;
				if ( !is_object( $users_handler ) ) {
						include_once SAXUE_ROOT_PATH . "/model/member_users.php";
						$users_handler = &saxuememberusershandler :: getinstance( "saxuememberusershandler" );
				}
				$sql = 'SELECT * FROM ' . saxue_dbprefix( "member_users" ) . ' WHERE status=1';
				if ( !empty( $this -> exevars['avatar'] ) ) {
						$sql .= " AND avatar=1";
				}
				$sql .= ' ORDER BY ' . $this -> exevars['field'] . ' DESC LIMIT 0, ' . $this -> exevars['listnum'];
				$res = $users_handler -> db -> query( $sql );
				$rows = array();
				$k = 0;
				while ( $v = $users_handler -> getobject( $res ) ) {
						$rows[$k] = $v -> getvars( 'n' );
						$rows[$k]['uhome'] = saxue_geturl( "user_home", $rows[$k]['uid'] );
						$rows[$k]['uavatar'] = saxue_geturl( "user_avatar", $rows[$k]['uid'], 'l', $rows[$k]['avatar'] );
						$rows[$k]['uavatar_s'] = saxue_geturl( "user_avatar", $rows[$k]['uid'], 's', $rows[$k]['avatar'] );
						$rows[$k]['uavatar_i'] = saxue_geturl( "user_avatar", $rows[$k]['uid'], 'i', $rows[$k]['avatar'] );
						++$k;
				} 
				if ( $isreturn ) {
						return $rows;
				}
				$saxueTpl -> assign_by_ref( "rows", $rows );
		} 
} 
