<?php
// Xinfeng Chen, 2002.11.22
// require_once('base_memo_file.php');
// require_once('class_forum_base.php');

class CRank extends CBaseMemoFile {
 var $level=array();

 function _explodeRecord($a_line){
  $tmp=explode(SP, $a_line);
  $this->level=array();
  foreach($tmp as $item){
   list($val,$key)=explode(';',$item);
   if($key){$this->level[$key]=$val;}
  }
 }

 function _composeRecord($a_line){
  arsort(&$this->level); $a_line='';
  foreach($this->level as $key=>$val){
   if($val<-1 || $key=='')continue;
   if($a_line!=''){$a_line.=SP;}
   $a_line=$a_line.$val.';'.$key;
  }
 }

 function load(){
  $fname=CForumBase::getFilePath('RANK');
  return $this->readFile($fname);
 }

 function store(){
  $fname=CForumBase::getFilePath('RANK');
  return $this->writeFile($fname);
 }

 function addRank($a_name,$a_level){
  $this->level[$a_name]=$a_level;
 }

 function removeRank($a_name){
  $this->level[$a_name]=-2;
  return true;
 }

 function getRank($a_level){
  foreach($this->level as $key=>$val){
   if($a_level>=$val && $val>=0){return $key;}
  }
  return '';
 }

}
?>