00001 <?php
00006 include_once("core/config/IConfigBackend.class.php");
00007 include_once("core/db/dbjames.class.php");
00008
00009 define(CONFIG_INC_PATH, "inc/");
00010 define(CONFIG_INC_PREFIX, "config");
00011
00015 class ConfigIncBackend extends IConfigBackend
00016 {
00017 var $idM;
00018 var $idG;
00019 var $idU;
00020
00021 var $fileName;
00022 var $realFileName;
00023
00028 function ConfigIncBackend($petition)
00029 {
00030 $this->idM = $petition->GetModule();
00031 $this->idG = $petition->GetGroup();
00032 $this->idU= $petition->GetUser();
00033
00034
00035 $name = CONFIG_INC_PREFIX."-";
00036 if ($this->idM == null)
00037 $name .= "system";
00038 else
00039 {
00040 $modules =& Modules::GetInstance();
00041 $mod = $modules->GetModule($this->idM);
00042 $name .= $mod->GetName();
00043 }
00044
00045 if ($this->idG != null)
00046 {
00047 $name .= "-group_".$this->idG;
00048 }
00049
00050 if ($this->idU != null)
00051 {
00052 $name .= "-user_".$this->idU;
00053 }
00054 $name .= ".php";
00055
00056
00057 $this->realFileName = JSystem::GetConfig("JamesDir");
00058 $this->realFileName .= "/".CONFIG_PATH.CONFIG_INC_PATH;
00059 if (!file_exists($this->realFileName))
00060 {
00061 mkdir($this->realFileName,0700);
00062 }
00063 $this->realFileName .= $name;
00064
00065
00066 $this->fileName = CONFIG_PATH.CONFIG_INC_PATH.$name;
00067 }
00068
00074 function GetConfig()
00075 {
00076 @include($this->fileName);
00077 return $config;
00078 }
00079
00084 function SetConfig($keys)
00085 {
00086 if (count($keys) > 0)
00087 {
00088 $cont = $this->_MakeContent($keys);
00089 $this->_WriteFile($cont, $this->realFileName);
00090 }
00091 }
00092
00098 function _MakeContent($keys)
00099 {
00100 $content = "<?php\n";
00101
00102 $config = $this->GetConfig();
00103
00104 $result = array_merge($config, $keys);
00105
00106 if (count($result)>0)
00107 {
00108 foreach ($result as $key => $value)
00109 {
00110 if ($value === true)
00111 $prv = "true";
00112 else if ($value === false)
00113 $prv = "false";
00114 else if (is_numeric($value))
00115 $prv = $value;
00116 else
00117 $prv = "\"".$value."\"";
00118
00119 $content .= "\$config[".$key."] = ".$prv.";\n";
00120 }
00121 }
00122
00123 $content .= "?>\n";
00124 return $content;
00125 }
00126
00132 function _WriteFile($content, $file)
00133 {
00134 if (file_exists($file))
00135 {
00136 unlink($file);
00137 }
00138 $fileHandler = fopen ($file, "w");
00139 fwrite ($fileHandler, $content);
00140 fclose ($fileHandler);
00141 }
00142 }
00143 ?>