5 ///////////////////////////////////////////////////////////////////////////
6 // NAME : configuration
12 // DESCRIPTION : Handle configurational parameters for the application.
13 // Many applications need some permanently stored configurational
14 // data. The information is usually stored in two places: A system-
15 // wide configuration file and a configuration file per user.
16 // The content of the configuration file is in XML format.
17 // The configuration base class takes care of finding the configuration
18 // files, e.g. in /etc/app.conf or in /usr/loca/etc/app.conf
19 // The config files are parsed with the gnome XML parser and a
20 // framework is provided to find configurational items.
24 // LAST MODIFIED : Jul 29, 2002
25 ///////////////////////////////////////////////////////////////////////////
33 function configuration()
39 function xmlFindTag($node, $tag)
44 while (!$element && $i < sizeof($node))
46 if ($node[$i]->type == XML_ELEMENT_NODE && $node[$i]->tagname == $tag)
56 function read($app_name)
58 $filename = "/etc/" . $app_name . ".conf";
59 $this->system = xmldocfile($filename);
63 $filename = "/usr/local/etc/" . $app_name . ".conf";
64 $this->system = xmldocfile($filename);
69 $root = $this->system->root();
71 if ($root->tagname != $app_name)
73 print("Configuration error: Wrong configuration file.<br>");
74 $this->system = false;
79 print("Configuration error: Configuration file for $app_name not found.<br>");
83 function find_parameter($section, $parameter)
89 $root_node = $this->system->root();
90 $section_node = $this->xmlFindTag($root_node->children(), $section);
93 $param_node = $this->xmlFindTag($section_node->children(), $parameter);
96 $param_node = $param_node->children();
98 if ($param_node && $param_node[0]->type == XML_TEXT_NODE)
100 $param_value = $param_node[0]->content;