<?php
/**
*
*
* @version $Id$
* @copyright 2003
**/
class Configer{
var $iniFile = "";
var $ar = array();
var $sections = false;
function Configer($iniFile = null, $sections = false, $new = null){
if ($iniFile != null) {
$this->iniFile = $iniFile;
} else {
$this->iniFile = dirname(dirname(__FILE__))."/config/scrubs.ini";
}
$this->sections = $sections;
if($new == null) {
$this->ar = parse_ini_file($this->iniFile, $this->sections);
} else {
$this->create();
}
}
function create() {
$fp = fopen($this->iniFile, "w");
fclose($fp);
}
function reload(){
$this->ar = parse_ini_file($this->iniFile, $this->sections);
}
function getResources(){
return $this->ar;
}
function getSection($section) {
if ($this->sections == true) {
return $this->ar[$section];
} else {
return false;
}
}
function getSectionValue($section, $key){
if ($this->sections == true) {
return $this->ar[$section][$key];
} else {
return false;
}
}
function setValue($key, $value){
if ($this->sections == false) {
$this->ar[$key] = $value;
} else {
return false;
}
}
function setSectionValue($section, $key, $value){
if ($this->sections == true) {
$this->ar[$section][$key] = $value;
} else {
return false;
}
}
function deleteResource($resource){
if ($this->sections == false) {
unset($this->ar[$resource]);
} else {
return false;
}
}
function deleteSection($section){
if ($this->sections == true) {
unset($this->ar[$section]);
} else {
return false;
}
}
function deleteSectionResource($section, $resource){
if ($this->sections == true) {
unset($this->ar[$section][$resource]);
} else {
return false;
}
}
function save(){
$iniString = "";
$fp = fopen($this->iniFile, "w");
flock($fp, LOCK_EX);
if ($this->sections == true) {
foreach ($this->ar as $section => $resources) {
$iniString .= "[$section]\n";
foreach ($resources as $resource => $value){
$iniString .= "$resource=$value\n";
}
$iniString .= "\n";
}
} else {
foreach ($this->ar as $resource => $value){
$iniString .= "$resource=$value\n";
}
}
fwrite($fp, $iniString);
flock($fp, LOCK_UN);
fclose($fp);
}
}
?>