<?php
/**
* @author moufer<moufer@163.com>
* @copyright www.modoer.com
* @version $Id 2 2008-08-24 17:08 $
*/
!defined('IN_MUDDER') && exit('Access Denied');

//»áÔ±ÁÐ±í
function query_members($callid,$params) {
    global $db, $dbpre, $_config, $_modules, $timestamp;

    $params = parseGlobal($params);
    if(empty($params)) return array();
    extract($params, EXTR_OVERWRITE);

    $cachename = sprintf("%d_%s", $callid,cacheIdentifier($params));
    $cachefile = MUDDER_ROOT.$_config['datacall_dir'].'cache_'.$cachename.'.php';

    if(file_exists($cachefile) && check_cache($cachefile, $cachetime)) {
        return read_cache($cachefile);
    }

    $result = $where = array();

    $where[] = "1=1";
    if($active==1) {
        $from = "{$dbpre}activity a LEFT JOIN {$dbpre}members m ON(a.uid=m.uid)";
        $year = (empty($year) || !is_numeric($year)) ? date('Y', $timestamp) : $year;
        $month = (empty($month) || !is_numeric($month)) ? date('Y', $timestamp) : $month;
        $where[] = "a.reviews>0";
        $where[] = "a.year='$year'";
        $where[] = "a.month='$month'";
    } else {
        $from = "{$dbpre}members m";
    }
    $select = "m.uid,m.username,m.reviews,m.face,m.point,m.coin,m.addshops,m.reviews,m.responds,m.flowers,m.groupid";

    is_numeric($point) && $where[] = "m.point>='$point'";
    is_numeric($coin) && $where[] = "m.coin>='$coin'";
    is_numeric($addshops) && $where[] = "m.addshops>='$addshops'";
    is_numeric($reviews) && $where[] = "m.reviews>='$reviews'";
    is_numeric($responds) && $where[] = "m.responds>='$responds'";
    is_numeric($flowers) && $where[] = "m.flowers>='$flowers'";
    is_numeric($groupid) && $where[] = "m.groupid='$groupid'";

    $where = implode(" AND ", $where);
    $order = strip_order($order);
    $orderby = $order ? "ORDER BY $order" : '';
    $limit = ($row=intval($row)) ? "LIMIT 0,$row" : 'LIMIT 0,10';

    $query = $db->query("SELECT * FROM $from WHERE $where $orderby $limit");
    if(!function_exists('memberToArray')) {
        require_once(MUDDER_ROOT.$_modules['member']['directory'].'/include/fun_member.php');
    }
    while($row=$db->fetch_array($query)) {
        $result[] = memberToArray($row);
    }

    if($cachetime > 0) {
        write_cache($cachename, arrayeval($result), '', 'return', $_config['datacall_dir']);
    }

   return $result;
}

?>