<?php
// Xinfeng Chen, 2002.11.04

class CForumBaseEx extends CForumBase {
 function _createDir($a_dirName){
  if(!file_exists($a_dirName)){
   $code=mkdir($a_dirName, 0777) ? 1 : 2;
  }else{
   $code=0;
  }
  return $code;
 }

 function _createFile($a_fileName){
  if(!file_exists($a_fileName)){
   if($TMP=fopen($a_fileName,"w")){
    fclose($TMP);
    chmod($a_fileName, 0666);
    $code=1;
   }else{
    $code=2;
   }
  }else{
   $code=0;
  }
  return $code;
 }

 function createFileBase(){
  $path=CForumBase::getFilePath();
  $dirList=array(
	"$path",		"$path/usr",	"$path/bbs",
	"$path/sys",	"$path/msg",	"$path/etc",
	"$path/bbs/recycle", "$path/backup"
  );
  $fileList=array(
   "$path/bbs/blist.dat"
  );

  foreach($dirList as $tmpDirName) {
   $code=CForumBaseEx::_createDir($tmpDirName);
   switch ($code) {
	case 0: $msg="already exists!"; break;
	case 1: $msg="created!"; break;
	case 2: $msg="FAILED to create!"; break;
   }
   print "[Dir ]$tmpDirName: $msg<br>\n";
   if($code>=2){return false;}
  }
  foreach($fileList as $tmpFileName) {
   $code=CForumBaseEx::_createFile($tmpFileName);
   switch ($code) {
	case 0: $msg="already exists!"; break;
	case 1: $msg="created!"; break;
	case 2: $msg="FAILED to create!"; break;
   }
   print "[File]$tmpFileName: $msg<br>\n";
   if($code>=2){return false;}
  }

  return true;
 } // end of createFileBase()

 function createBoardDir($a_bid){
  $path=dirname(CForumBase::getFilePath('BOARD',$a_bid));
  return (CForumBaseEx::_createDir($path)==1);
 }

}

?>