allow types to specify config options
This commit is contained in:
		
							parent
							
								
									0e170f56ff
								
							
						
					
					
						commit
						c40ce39bb8
					
				| 
						 | 
				
			
			@ -19,6 +19,7 @@
 | 
			
		|||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -40,7 +41,10 @@ This is a list of API changes for all LAM releases.
 | 
			
		|||
 | 
			
		||||
<br>
 | 
			
		||||
 | 
			
		||||
<h2>4.5 -> 4.6</h2>The valid account types for each module must now
 | 
			
		||||
<h2>4.6 -> 4.7</h2>Account types (e.g. user, group, host) may have config options now. See baseType::get_configOptions().<br>
 | 
			
		||||
<br>
 | 
			
		||||
<h2>4.5 -> 4.6</h2>
 | 
			
		||||
The valid account types for each module must now
 | 
			
		||||
be set in can_manage(). This function is abstract in base module.
 | 
			
		||||
Setting the account type via meta data is no longer supported.<br>
 | 
			
		||||
<br>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -3,7 +3,7 @@
 | 
			
		|||
$Id$
 | 
			
		||||
 | 
			
		||||
  This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
 | 
			
		||||
  Copyright (C) 2005 - 2012  Roland Gruber
 | 
			
		||||
  Copyright (C) 2005 - 2014  Roland Gruber
 | 
			
		||||
 | 
			
		||||
  This program is free software; you can redistribute it and/or modify
 | 
			
		||||
  it under the terms of the GNU General Public License as published by
 | 
			
		||||
| 
						 | 
				
			
			@ -186,6 +186,33 @@ class baseType {
 | 
			
		|||
		
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	/**
 | 
			
		||||
	* Returns a list of configuration options.
 | 
			
		||||
	* 
 | 
			
		||||
	* The field names are used as keywords to load and save settings.
 | 
			
		||||
	* We recommend to use the type name as prefix for them (e.g. user_someSetting) to avoid naming conflicts.
 | 
			
		||||
	*
 | 
			
		||||
	* @return mixed htmlElement or array of htmlElement
 | 
			
		||||
	* 
 | 
			
		||||
	* @see htmlElement
 | 
			
		||||
	*/
 | 
			
		||||
	public function get_configOptions() {
 | 
			
		||||
		return null;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	* Checks input values of config settings.
 | 
			
		||||
	* <br>
 | 
			
		||||
	* If the input data is invalid the return value is an array that contains subarrays to build StatusMessages ('message type', 'message head', 'message text').
 | 
			
		||||
	* <br>If no errors occured the function returns an empty array.
 | 
			
		||||
	*
 | 
			
		||||
	* @param array $options hash array (option name => value) that contains the input. The option values are all arrays containing one or more elements.
 | 
			
		||||
	* @return array list of error messages
 | 
			
		||||
	*/
 | 
			
		||||
	public function check_configOptions(&$options) {
 | 
			
		||||
		return array();
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
?>
 | 
			
		||||
| 
						 | 
				
			
			@ -201,6 +201,48 @@ function LAMVersion() {
 | 
			
		|||
	return '0.0.unknown';
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Extracts config options from HTTP POST data.
 | 
			
		||||
 * 
 | 
			
		||||
 * @param array $confTypes array (option name => type (e.g. multiselect))
 | 
			
		||||
 * @return array list of config options (name => array(values))
 | 
			
		||||
 */
 | 
			
		||||
function extractConfigOptionsFromPOST($confTypes) {
 | 
			
		||||
	$options = array();
 | 
			
		||||
	foreach ($confTypes as $element => $type) {
 | 
			
		||||
		// text fields
 | 
			
		||||
		if ($type == "text") {
 | 
			
		||||
			$options[$element] = array($_POST[$element]);
 | 
			
		||||
		}
 | 
			
		||||
		// text fields
 | 
			
		||||
		elseif ($type == "text_obfuscated") {
 | 
			
		||||
			$options[$element] = array(obfuscateText($_POST[$element]));
 | 
			
		||||
		}
 | 
			
		||||
		// hidden fields
 | 
			
		||||
		elseif ($type == "hidden") {
 | 
			
		||||
			$options[$element] = array($_POST[$element]);
 | 
			
		||||
		}
 | 
			
		||||
		// checkboxes
 | 
			
		||||
		elseif ($type == "checkbox") {
 | 
			
		||||
			if (isset($_POST[$element]) && ($_POST[$element] == "on")) $options[$element] = array('true');
 | 
			
		||||
			else $options[$element] = array('false');
 | 
			
		||||
		}
 | 
			
		||||
		// dropdownbox
 | 
			
		||||
		elseif ($type == "select") {
 | 
			
		||||
			$options[$element] = array($_POST[$element]);
 | 
			
		||||
		}
 | 
			
		||||
		// multiselect
 | 
			
		||||
		elseif ($type == "multiselect") {
 | 
			
		||||
			$options[$element] = $_POST[$element];  // value is already an array
 | 
			
		||||
		}
 | 
			
		||||
		// textarea
 | 
			
		||||
		elseif ($type == "textarea") {
 | 
			
		||||
			$options[$element] = explode("\r\n", $_POST[$element]);
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	return $options;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
* Prints a meta refresh page
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -227,6 +227,7 @@ if (sizeof($availableTypes) > 0) {
 | 
			
		|||
	$container->addElement($availableContainer, true);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
$_SESSION['conftypes_optionTypes'] = array();
 | 
			
		||||
// show active types
 | 
			
		||||
if (sizeof($activeTypes) > 0) {
 | 
			
		||||
	$container->addElement(new htmlSubTitle(_("Active account types")), true);
 | 
			
		||||
| 
						 | 
				
			
			@ -264,6 +265,20 @@ if (sizeof($activeTypes) > 0) {
 | 
			
		|||
		$attrsInput->setFieldSize(40);
 | 
			
		||||
		$activeContainer->addElement($attrsInput);
 | 
			
		||||
		$activeContainer->addNewLine();
 | 
			
		||||
		// type options
 | 
			
		||||
		$typeObj = new $activeTypes[$i];
 | 
			
		||||
		$typeConfigOptions = $typeObj->get_configOptions();
 | 
			
		||||
		if (!empty($typeConfigOptions)) {
 | 
			
		||||
			foreach ($typeConfigOptions as $typeConfigOption) {
 | 
			
		||||
				$activeContainer->addElement($typeConfigOption, true);
 | 
			
		||||
			}
 | 
			
		||||
			// save option types to session
 | 
			
		||||
			ob_start();
 | 
			
		||||
			$dummyIndex = 1;
 | 
			
		||||
			$typeConfigOptionTypes = parseHtml(null, $typeConfigOptions, array(), true, $dummyIndex, 'user');
 | 
			
		||||
			ob_end_clean();
 | 
			
		||||
			$_SESSION['conftypes_optionTypes'] = array_merge($_SESSION['conftypes_optionTypes'], $typeConfigOptionTypes);
 | 
			
		||||
		}
 | 
			
		||||
		// advanced options
 | 
			
		||||
		$advancedOptionsContent = new htmlTable();
 | 
			
		||||
		// LDAP filter
 | 
			
		||||
| 
						 | 
				
			
			@ -327,7 +342,13 @@ if (sizeof($activeTypes) > 0) {
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
$tabindex = 1;
 | 
			
		||||
parseHtml(null, $container, array(), false, $tabindex, 'user');
 | 
			
		||||
$dynamicTypeOptions = array();
 | 
			
		||||
foreach ($_SESSION['conftypes_optionTypes'] as $key => $value) {
 | 
			
		||||
	if (isset($typeSettings[$key])) {
 | 
			
		||||
		$dynamicTypeOptions[$key] = explode(LAMConfig::LINE_SEPARATOR, $typeSettings[$key]);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
parseHtml(null, $container, $dynamicTypeOptions, false, $tabindex, 'user');
 | 
			
		||||
 | 
			
		||||
echo "<input type=\"hidden\" name=\"postAvailable\" value=\"yes\">\n";
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -403,6 +424,7 @@ function checkInput() {
 | 
			
		|||
			$typeSettings[$key] = $_POST[$key];
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	$typeConfigOptions = extractConfigOptionsFromPOST($_SESSION['conftypes_optionTypes']);
 | 
			
		||||
	for ($i = 0; $i < sizeof($accountTypes); $i++) {
 | 
			
		||||
		// set hidden
 | 
			
		||||
		$key = "hidden_" . $accountTypes[$i];
 | 
			
		||||
| 
						 | 
				
			
			@ -418,6 +440,16 @@ function checkInput() {
 | 
			
		|||
			$key = "readOnly_" . $accountTypes[$i];
 | 
			
		||||
			$typeSettings[$key] = (isset($_POST[$key]) && ($_POST[$key] == 'on'));
 | 
			
		||||
		}
 | 
			
		||||
		// check dynamic type settings
 | 
			
		||||
		$typeObj = new $accountTypes[$i];
 | 
			
		||||
		$typeMessages = $typeObj->check_configOptions($typeConfigOptions);
 | 
			
		||||
		if (!empty($typeMessages)) {
 | 
			
		||||
			$errors = array_merge($errors, $typeMessages);
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	// add dynamic type settings
 | 
			
		||||
	foreach ($typeConfigOptions as $key => $value) {
 | 
			
		||||
		$typeSettings[$key] = implode(LAMConfig::LINE_SEPARATOR, $value);
 | 
			
		||||
	}
 | 
			
		||||
	// save input
 | 
			
		||||
	$conf->set_typeSettings($typeSettings);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -273,40 +273,7 @@ function checkInput() {
 | 
			
		|||
	
 | 
			
		||||
	// check module options
 | 
			
		||||
	// create option array to check and save
 | 
			
		||||
	$options = array();
 | 
			
		||||
	$opt_keys = array_keys($_SESSION['conf_types']);
 | 
			
		||||
	for ($i = 0; $i < sizeof($opt_keys); $i++) {
 | 
			
		||||
		$element = $opt_keys[$i];
 | 
			
		||||
		// text fields
 | 
			
		||||
		if ($_SESSION['conf_types'][$element] == "text") {
 | 
			
		||||
			$options[$element] = array($_POST[$element]);
 | 
			
		||||
		}
 | 
			
		||||
		// text fields
 | 
			
		||||
		elseif ($_SESSION['conf_types'][$element] == "text_obfuscated") {
 | 
			
		||||
			$options[$element] = array(obfuscateText($_POST[$element]));
 | 
			
		||||
		}
 | 
			
		||||
		// hidden fields
 | 
			
		||||
		elseif ($_SESSION['conf_types'][$element] == "hidden") {
 | 
			
		||||
			$options[$element] = array($_POST[$element]);
 | 
			
		||||
		}
 | 
			
		||||
		// checkboxes
 | 
			
		||||
		elseif ($_SESSION['conf_types'][$element] == "checkbox") {
 | 
			
		||||
			if (isset($_POST[$element]) && ($_POST[$element] == "on")) $options[$element] = array('true');
 | 
			
		||||
			else $options[$element] = array('false');
 | 
			
		||||
		}
 | 
			
		||||
		// dropdownbox
 | 
			
		||||
		elseif ($_SESSION['conf_types'][$element] == "select") {
 | 
			
		||||
			$options[$element] = array($_POST[$element]);
 | 
			
		||||
		}
 | 
			
		||||
		// multiselect
 | 
			
		||||
		elseif ($_SESSION['conf_types'][$element] == "multiselect") {
 | 
			
		||||
			$options[$element] = $_POST[$element];  // value is already an array
 | 
			
		||||
		}
 | 
			
		||||
		// textarea
 | 
			
		||||
		elseif ($_SESSION['conf_types'][$element] == "textarea") {
 | 
			
		||||
			$options[$element] = explode("\r\n", $_POST[$element]);
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	$options = extractConfigOptionsFromPOST($_SESSION['conf_types']);
 | 
			
		||||
 | 
			
		||||
	// get list of scopes of modules
 | 
			
		||||
	$scopes = array();
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue