19 require_once(BASE.
"wcmf/lib/presentation/class.Controller.php");
20 require_once(BASE.
"wcmf/lib/persistence/class.PersistenceFacade.php");
21 require_once(BASE.
"wcmf/lib/model/class.Node.php");
22 require_once(BASE.
"wcmf/lib/util/class.InifileParser.php");
23 require_once(BASE.
"wcmf/lib/util/class.ArrayUtil.php");
67 if (strlen($request->getContext()) == 0)
69 $request->setContext(
'config');
70 $response->setContext(
'config');
73 parent::initialize($request, $response);
80 if(in_array($this->_request->getAction(), array(
'editconfig',
'save')))
82 if(strlen($this->_request->getValue(
'oid')) == 0)
88 if($this->_request->getAction() ==
'delconfig')
90 if(strlen($this->_request->getValue(
'deleteoids')) == 0)
92 $this->
setErrorMsg(
"No 'deleteoids' given in data.");
103 if ($this->_request->getAction() ==
'delconfig')
116 global $CONFIG_PATH, $CONFIG_EXTENSION, $MAIN_CONFIG_FILE;
118 $configFilename = $this->_request->getValue(
'oid');
120 $configFilename = str_replace($CONFIG_PATH,
'', $configFilename);
121 $configFilenameNoExtension = str_replace(
'.'.$CONFIG_EXTENSION,
'', $configFilename);
126 if($this->_request->getAction() ==
'delconfig')
128 $deleteOIDs = split(
',', $this->_request->getValue(
'deleteoids'));
129 foreach($deleteOIDs as $oid)
133 $this->_response->setAction(
'ok');
138 if($this->_request->getAction() ==
'newconfig')
140 $newNode =
new Node(
'config');
141 $newConfigFilename =
'config'.md5(microtime()).
'.'.$CONFIG_EXTENSION;
142 $fh = fopen($CONFIG_PATH.$newConfigFilename,
'w');
144 $configFilename = $newConfigFilename;
145 $configFilenameNoExtension = preg_replace(
'/\.'.$CONFIG_EXTENSION.
'/',
'', $configFilename);
148 $this->_request->setAction(
'editconfig');
153 if (in_array($this->_request->getAction(), array(
'editconfig',
'save')) || in_array($this->_request->getContext(), array(
'config')))
157 $configFile->parseIniFile($CONFIG_PATH.$configFilename,
false);
160 if ($this->_request->getAction() ==
'save')
162 $data = &$this->_request->getData();
163 foreach($data as $control => $value)
166 $value = str_replace(
"\\\"",
"\"", $value);
169 if ($key[
'type'] ==
'section')
172 if ($key[
'section'] != $value)
174 if ($configFile->renameSection($key[
'section'], $value) ===
false)
180 elseif ($key[
'type'] ==
'option')
183 if ($key[
'option'] != $value)
185 if ($configFile->renameKey($key[
'option'], $value, $key[
'section']) ===
false)
190 $internalLink = $key[
'section'].
'_'.$value;
194 elseif ($key[
'type'] ==
'value')
197 if ($configFile->getValue($key[
'option'], $key[
'section']) != $value)
199 if ($configFile->setValue($key[
'option'], $value, $key[
'section'],
false) ===
false)
202 $internalLink = $key[
'section'].
'_'.$key[
'option'];
205 if ($control ==
'name' && $value != $configFilenameNoExtension)
207 $newConfigFilename = $value.
'.'.$CONFIG_EXTENSION;
208 if (!file_exists($CONFIG_PATH.$newConfigFilename))
210 rename($CONFIG_PATH.$configFilename, $CONFIG_PATH.$newConfigFilename);
211 $configFilename = $newConfigFilename;
212 $configFilenameNoExtension = preg_replace(
'/\.'.$CONFIG_EXTENSION.
'/',
'', $configFilename);
220 if($this->_request->getAction() ==
'newsection')
222 $newNode =
new Node(
'section');
223 $sectionName = substr($newNode->getOID(), 0, 20);
224 $configFile->createSection($sectionName);
227 if($this->_request->getAction() ==
'newoption')
229 $newNode =
new Node(
'option');
230 $sectionName = $this->_request->getValue(
'poid');
231 $optionName = substr($newNode->getOID(), 0, 20);
232 $configFile->setValue($optionName,
'', $sectionName);
233 $internalLink = $sectionName.
'_'.$optionName;
236 if($this->_request->getAction() ==
'delsection')
238 $deleteOIDs = split(
',', $this->_request->getValue(
'deleteoids'));
239 foreach($deleteOIDs as $oid)
242 $configFile->removeSection($key[
'section']);
246 if($this->_request->getAction() ==
'deloption')
248 $deleteOIDs = split(
',', $this->_request->getValue(
'deleteoids'));
249 foreach($deleteOIDs as $oid)
252 $configFile->removeKey($key[
'option'], $key[
'section']);
254 $internalLink = $key[
'section'];
257 if ($configFile->isModified())
258 $configFile->writeIniFile($CONFIG_PATH.$configFilename);
262 $configFile->parseIniFile($CONFIG_PATH.$configFilename,
false);
265 $this->_response->setValue(
'oid', $configFilename);
266 $this->_response->setValue(
'configfile', $configFile);
267 $this->_response->setValue(
'ismainconfigfile', $MAIN_CONFIG_FILE == $configFilename);
268 $this->_response->setValue(
'configFilenameNoExtension', $configFilenameNoExtension);
269 $this->_response->setValue(
'internallink', $internalLink);
273 $this->_response->setAction(
'ok');
284 preg_match(
"/^type_(.+?)_section_(.+?)(_option_(.+?))*$/", $controlname, $matches);
285 return array(
'type' => $matches[1],
'section' => $matches[2],
'option' => $matches[4]);
294 $controlName =
'type_'.$key[
'type'].
'_section_'.$key[
'section'];
295 if ($key[
'type'] ==
'option' || $key[
'type'] ==
'value')
296 $controlName .=
'_option_'.$key[
'option'];
306 $data = &$this->_request->getData();
307 foreach(array_keys($data) as $oldControlName)
310 if ($key[$key[
'type']] == $oldKey[$key[
'type']])
313 $newKey[$key[
'type']] = $value;
get($message, $parameters=null, $domain='', $lang='')
Node is the basic component for building trees (although a Node can have one than more parents)...
getKeyFromControlName($controlname)
renameControlNames($key, $value)
initialize(&$request, &$response)
key_array_rename(&$input, $oldname, $newname)
makeControlNameFromKey($key)
Controller is the base class of all controllers. If a Controller has a view it is expected to reside ...
InifileParser provides basic services for parsing a ini file from the file system.
ConfigController is used to edit configuration files. The controller uses the global variable CONFIG_...