<?php

class SBBUserranks {

  var $count = 0;
     
  function SBBUserranks() {
    global $board_config;
    $this->board_config = $board_config;
  }
  
  function RankList() {
    $ranks = array();
    $users = $this->UsersPerRank();
    $sql = "select * from `" . $this->board_config->prefix . "ranks` order by descr";
    $res = dbquery($sql);
    while ($row = mysql_fetch_object($res)) {
      $row->users = $users[$row->id];
      $ranks[] = $row;
    }
    $this->count = mysql_num_rows($res);
    return $ranks;
  }
  
  function UsersPerRank() {
    $sql = "select count(id) as cnt, rank_id from `" . $this->board_config->prefix . "users` group by rank_id";
    $res = dbquery($sql);
    while ($row = mysql_fetch_object($res)) {
      $users[$row->rank_id] = $row->cnt;
    }
    return $users;
  }
  
  function GetRank($id) {
    if (!$id) return false;
    $sql = "select * from `" . $this->board_config->prefix . "ranks` where id = '$id'";
    $res = dbquery($sql);
    if (!mysql_num_rows($res)) return false;
    else return mysql_fetch_object($res);
  }
  
  //for the allover usage
  function GetRankList() {
    $rank = array();
    $sql = "select * from `" . $this->board_config->prefix . "ranks` order by descr";
    $res = dbquery($sql);
    while ($row = mysql_fetch_object($res)) {
      $rank[$row->id] = $row;
    }
    return $rank;
  }
  
  
}

?>