2 /**************************************************************************
3 ** (c) Copyright 2002, Andromeda Technology & Automation
4 ** This is free software; you can redistribute it and/or modify it under the
5 ** terms of the GNU General Public License, see the file COPYING.
6 ***************************************************************************/
10 ///////////////////////////////////////////////////////////////////////////
11 // NAME : configuration
17 // DESCRIPTION : Handle configurational parameters for the application.
18 // Many applications need some permanently stored configurational
19 // data. The information is usually stored in two places: A system-
20 // wide configuration file and a configuration file per user.
21 // The content of the configuration file is in XML format.
22 // The configuration base class takes care of finding the configuration
23 // files, e.g. in /etc/app.conf or in /usr/loca/etc/app.conf
24 // The config files are parsed with the gnome XML parser and a
25 // framework is provided to find configurational items.
29 // LAST MODIFIED : Jul 29, 2002
30 ///////////////////////////////////////////////////////////////////////////
38 function configuration()
44 function xmlFindTag($node, $tag)
49 while (!$element && $i < sizeof($node))
51 if ($node[$i]->type == XML_ELEMENT_NODE && $node[$i]->tagname == $tag)
61 function read($app_name)
63 $filename = "/etc/" . $app_name . ".conf";
64 $this->system = xmldocfile($filename);
68 $filename = "/usr/local/etc/" . $app_name . ".conf";
69 $this->system = xmldocfile($filename);
74 $root = $this->system->root();
76 if ($root->tagname != $app_name)
78 print("Configuration error: Wrong configuration file.<br>");
79 $this->system = false;
84 print("Configuration error: Configuration file for $app_name not found.<br>");
88 function find_parameter($section, $parameter)
94 $root_node = $this->system->root();
95 $section_node = $this->xmlFindTag($root_node->children(), $section);
98 $param_node = $this->xmlFindTag($section_node->children(), $parameter);
101 $param_node = $param_node->children();
103 if ($param_node && $param_node[0]->type == XML_TEXT_NODE)
105 $param_value = $param_node[0]->content;