save module name for each option

This commit is contained in:
Roland Gruber 2004-02-12 15:58:04 +00:00
parent a95afff139
commit bc94fb6563
1 changed files with 51 additions and 21 deletions

View File

@ -97,8 +97,15 @@ function loadUserProfile($profile) {
// search keywords // search keywords
$parts = array(); $parts = array();
$parts = split(": ", $line); $parts = split(": ", $line);
if (sizeof($parts) != 2) continue; // ignore malformed settings if (sizeof($parts) < 3) continue; // ignore malformed settings
else $settings[$parts[0]] = chop($parts[1]); else {
$module = array_shift($parts);
$option = array_shift($parts);
$values = $parts;
// remove line ends
for ($i = 0; $i < sizeof($values); $i++) $values[$i] = chop($values[$i]);
$settings[$module][$option] = $values;
}
} }
fclose($file); fclose($file);
} }
@ -128,8 +135,15 @@ function loadGroupProfile($profile) {
// search keywords // search keywords
$parts = array(); $parts = array();
$parts = split(": ", $line); $parts = split(": ", $line);
if (sizeof($parts) != 2) continue; // ignore malformed settings if (sizeof($parts) < 3) continue; // ignore malformed settings
else $settings[$parts[0]] = chop($parts[1]); else {
$module = array_shift($parts);
$option = array_shift($parts);
$values = $parts;
// remove line ends
for ($i = 0; $i < sizeof($values); $i++) $values[$i] = chop($values[$i]);
$settings[$module][$option] = $values;
}
} }
fclose($file); fclose($file);
} }
@ -159,8 +173,15 @@ function loadHostProfile($profile) {
// search keywords // search keywords
$parts = array(); $parts = array();
$parts = split(": ", $line); $parts = split(": ", $line);
if (sizeof($parts) != 2) continue; // ignore malformed settings if (sizeof($parts) < 3) continue; // ignore malformed settings
else $settings[$parts[0]] = chop($parts[1]); else {
$module = array_shift($parts);
$option = array_shift($parts);
$values = $parts;
// remove line ends
for ($i = 0; $i < sizeof($values); $i++) $values[$i] = chop($values[$i]);
$settings[$module][$option] = $values;
}
} }
fclose($file); fclose($file);
} }
@ -177,7 +198,7 @@ function loadHostProfile($profile) {
// saves an hash array (attribute => value) to an user profile // saves an hash array (attribute => value) to an user profile
// file is created, if needed // file is created, if needed
// $profile: name of the user profile (without .pru) // $profile: name of the user profile (without .pru)
// $attributes: hash array (attribute => value) // $attributes: hash array(module => array(attribute => value))
function saveUserProfile($attributes, $profile) { function saveUserProfile($attributes, $profile) {
if (!$_SESSION['loggedIn'] == true) return false; if (!$_SESSION['loggedIn'] == true) return false;
// check profile name // check profile name
@ -189,10 +210,13 @@ function saveUserProfile($attributes, $profile) {
$file = @fopen($path, "w"); $file = @fopen($path, "w");
if ($file) { if ($file) {
// write attributes // write attributes
$keys = array_keys($attributes); $modules = array_keys($attributes);
for ($i = 0; $i < sizeof($keys); $i++) { for ($m = 0; $m < sizeof($modules); $m++) {
$line = $keys[$i] . ": " . $attributes[$keys[$i]] . "\n"; $keys = array_keys($attributes[$modules[$m]]);
fputs($file, $line); for ($i = 0; $i < sizeof($keys); $i++) {
$line = $modules[$m] . ": " . $keys[$i] . ": " . $attributes[$modules[$m]][$keys[$i]] . "\n";
fputs($file, $line);
}
} }
// close file // close file
fclose($file); fclose($file);
@ -207,7 +231,7 @@ function saveUserProfile($attributes, $profile) {
// saves an hash array (attribute => value) to an group profile // saves an hash array (attribute => value) to an group profile
// file is created, if needed // file is created, if needed
// $profile: name of the group profile (without .prg) // $profile: name of the group profile (without .prg)
// $attributes: hash array (attribute => value) // $attributes: hash array(module => array(attribute => value))
function saveGroupProfile($attributes, $profile) { function saveGroupProfile($attributes, $profile) {
if (!$_SESSION['loggedIn'] == true) return false; if (!$_SESSION['loggedIn'] == true) return false;
// check profile name // check profile name
@ -219,10 +243,13 @@ function saveGroupProfile($attributes, $profile) {
$file = @fopen($path, "w"); $file = @fopen($path, "w");
if ($file) { if ($file) {
// write attributes // write attributes
$keys = array_keys($attributes); $modules = array_keys($attributes);
for ($i = 0; $i < sizeof($keys); $i++) { for ($m = 0; $m < sizeof($modules); $m++) {
$line = $keys[$i] . ": " . $attributes[$keys[$i]] . "\n"; $keys = array_keys($attributes[$modules[$m]]);
fputs($file, $line); for ($i = 0; $i < sizeof($keys); $i++) {
$line = $modules[$m] . ": " . $keys[$i] . ": " . $attributes[$modules[$m]][$keys[$i]] . "\n";
fputs($file, $line);
}
} }
// close file // close file
fclose($file); fclose($file);
@ -237,7 +264,7 @@ function saveGroupProfile($attributes, $profile) {
// saves an hash array (attribute => value) to an host profile // saves an hash array (attribute => value) to an host profile
// file is created, if needed // file is created, if needed
// $profile: name of the host profile (without .prh) // $profile: name of the host profile (without .prh)
// $attributes: hash array (attribute => value) // $attributes: hash array(module => array(attribute => value))
function saveHostProfile($attributes, $profile) { function saveHostProfile($attributes, $profile) {
if (!$_SESSION['loggedIn'] == true) return false; if (!$_SESSION['loggedIn'] == true) return false;
// check profile name // check profile name
@ -249,10 +276,13 @@ function saveHostProfile($attributes, $profile) {
$file = @fopen($path, "w"); $file = @fopen($path, "w");
if ($file) { if ($file) {
// write attributes // write attributes
$keys = array_keys($attributes); $modules = array_keys($attributes);
for ($i = 0; $i < sizeof($keys); $i++) { for ($m = 0; $m < sizeof($modules); $m++) {
$line = $keys[$i] . ": " . $attributes[$keys[$i]] . "\n"; $keys = array_keys($attributes[$modules[$m]]);
fputs($file, $line); for ($i = 0; $i < sizeof($keys); $i++) {
$line = $modules[$m] . ": " . $keys[$i] . ": " . $attributes[$modules[$m]][$keys[$i]] . "\n";
fputs($file, $line);
}
} }
// close file // close file
fclose($file); fclose($file);