removed $scope from profile functions,

added meta data for profile options and checks
This commit is contained in:
Roland Gruber 2004-07-01 15:54:33 +00:00
parent a7862e4dab
commit c92674a95a
12 changed files with 164 additions and 49 deletions

View File

@ -271,7 +271,7 @@ It must return the help entry as array for the submitted help
identifier. The format of the array to be returned is described in
section 4. "Help entry syntax".<br>
<br>
<h3>2.2.5. get_profileOptions</h3>
<h3>2.2.5. get_profileOptions*</h3>
<br>
<table cellpadding="2" cellspacing="2" border="0"
style="text-align: left; width: 300px; height: 30px;">
@ -279,7 +279,7 @@ section 4. "Help entry syntax".<br>
<tr>
<td
style="vertical-align: top; background-color: rgb(204, 204, 204); text-align: center;"><span
style="font-weight: bold;">function get_profileOptions($scope)</span><br>
style="font-weight: bold;">function get_profileOptions()</span><br>
</td>
</tr>
</tbody>
@ -288,10 +288,8 @@ section 4. "Help entry syntax".<br>
This function defines what attributes will be used in the account
profiles and their appearance in the profile editor.<br>
<br>
<span style="font-weight: bold;">$scope</span> is the account type
("user", "group", "host" at this time).<br>
The return value is an array that contains <span
style="font-weight: bold;">meta HTML code</span>.<br>
<span style="font-weight: bold;"></span>The return value is an array
that contains <span style="font-weight: bold;">meta HTML code</span>.<br>
<br>
The type "fieldset" is not allowed here.<br>
The <span style="font-style: italic;">name</span> attributes are used
@ -299,7 +297,7 @@ as keywords to load and save profiles. We recommend to use the module
name as prefix for them (e.g. posixAccount_homeDirectory) to avoid
naming confilcts.<br>
<br>
<h3>2.2.6. check_profileOptions</h3>
<h3>2.2.6. check_profileOptions*</h3>
<br>
<table style="text-align: left; width: 400px; height: 30px;" border="0"
cellspacing="2" cellpadding="2">
@ -307,8 +305,7 @@ naming confilcts.<br>
<tr>
<td
style="vertical-align: top; background-color: rgb(204, 204, 204); text-align: center;"><span
style="font-weight: bold;">function check_profileOptions($scope,
$options)</span><br>
style="font-weight: bold;">function check_profileOptions($options)</span><br>
</td>
</tr>
</tbody>
@ -576,8 +573,74 @@ array("user", "host")</span><br style="font-weight: bold;">
style="font-weight: bold; font-style: italic;">"depends"
=&gt; array("posixAccount", array("qmail", "sendmail")), "conflicts"
=&gt; array("exim")</span></span><span
style="font-style: italic; font-weight: bold;">)</span><span
style="font-style: italic; font-weight: bold;"><br>
style="font-style: italic; font-weight: bold;">)<br>
</span><br>
<h3>6.5 get_profileOptions()<br>
</h3>
&nbsp;&nbsp;&nbsp; "profile_options" =&gt; array<br>
<br>
<span style="font-weight: bold;">&nbsp;&nbsp; <span
style="font-style: italic;">Syntax for array is the same as for the
return value of get_profileOptions().<br>
<br>
</span></span>
<h3>6.6 check_profileOptions()<br>
</h3>
&nbsp;&nbsp;&nbsp; "profile_checks" =&gt; array<br>
<br>
<span style="font-weight: bold;">&nbsp;&nbsp; The keys of the array are
the names of the option identifiers.<br>
&nbsp;&nbsp; Each array element is an array containing these values:<br>
<br>
</span>
<ul>
<li style="font-weight: bold;">type:<span style="font-weight: normal;">
determines how to check input</span></li>
<ul>
<li style="font-weight: bold;">regex:<span
style="font-weight: normal;"> check with regular expression from <span
style="font-style: italic;">regex</span> variable, case sensitive</span></li>
<li style="font-weight: bold;">regex_i:<span
style="font-weight: normal;"> check with regular expression from <span
style="font-style: italic;">regex</span> variable, case insensitive</span></li>
</ul>
<li style="font-weight: bold;">error_message:<span
style="font-weight: normal;"> message that is displayed if input value
was syntactically incorrect</span></li>
<ul>
<li style="font-weight: bold;"><span style="font-weight: normal;">array
to build StatusMessages (0 =&gt; message type, 1 =&gt; message
head, 2 =&gt; message text, 3 =&gt; additional variables)</span><span
style="font-weight: normal;"></span></li>
</ul>
<li style="font-weight: bold;">regex:<span
style="font-weight: normal;"> regular expression string (only if <span
style="font-style: italic;">type</span> is <span
style="font-style: italic;">regex</span>/<span
style="font-style: italic;">regex_i</span>)</span><br>
</li>
<li><span style="font-weight: bold;">required:</span> <span
style="font-style: italic;">true</span> or <span
style="font-style: italic;">false</span>, if this input field must be
filled set to true (optional)<span style="font-weight: bold;"><br>
</span></li>
<li><span style="font-weight: bold;">required_message:</span> message<span
style="font-weight: normal;"> that is displayed if no input value was
given</span><span style="font-weight: normal;"> (only if <span
style="font-style: italic;">required</span> == true)</span><span
style="font-weight: bold;"></span></li>
<ul>
<li>&nbsp;array to build StatusMessages (0 =&gt; message type, 1
=&gt; message
head, 2 =&gt; message text, 3 =&gt; additional variables)<span
style="font-weight: bold;"><br>
</span></li>
</ul>
</ul>
<span style="font-weight: bold;"></span><span style="font-weight: bold;"><span
style="font-style: italic;"></span></span><span
style="font-style: italic; font-weight: bold;"></span><span
style="font-style: italic; font-weight: bold;"></span><span
style="font-style: italic; font-weight: bold;"></span>
</body>
</html>

View File

@ -128,6 +128,47 @@ class baseModule {
else return array('depends' => array(), 'conflicts' => array());
}
/**
* Returns a list of elements for the account profiles.
*
* @return profile elements
*/
function get_profileOptions() {
if (isset($this->meta['profile_options'])) return $this->meta['profile_options'];
else return array();
}
/**
* Checks input values of account profiles.
*
* @return profile elements
*/
function check_profileOptions($options) {
$messages = array();
if (is_array($this->meta['profile_checks'])) {
$identifiers = array_keys($this->meta['profile_checks']);
for ($i = 0; $i < sizeof($identifiers); $i++) {
// check if option is required
if ($this->meta['profile_checks'][$identifiers[$i]]['required'] && ($options[$identifiers[$i]][0] == '')) {
$messages[] = $this->meta['profile_checks'][$identifiers[$i]]['required_message'];
}
// check by regular expression (case insensitive)
if ($this->meta['profile_checks'][$identifiers[$i]]['type'] == 'regex_i') {
if (! eregi($this->meta['profile_checks'][$identifiers[$i]]['regex'], $options[$identifiers[$i]][0])) {
$messages[] = $this->meta['profile_checks'][$identifiers[$i]]['error_message'];
}
}
// check by regular expression (case sensitive)
elseif ($this->meta['profile_checks'][$identifiers[$i]]['type'] == 'regex') {
if (! ereg($this->meta['profile_checks'][$identifiers[$i]]['regex'], $options[$identifiers[$i]][0])) {
$messages[] = $this->meta['profile_checks'][$identifiers[$i]]['error_message'];
}
}
}
}
return $messages;
}
// TODO implement missing interface
}

View File

@ -240,13 +240,13 @@ function getProfileOptions($scope) {
* @return array list of error messages
*/
function checkProfileOptions($scope, $options) {
$return = array();
$modules = getAvailableModules($scope);
for ($i = 0; $i < sizeof($modules); $i++) {
$errors = call_user_func(array($modules[$i], "check_profileOptions"), $scope, $options);
$return = array_merge($return, $errors);
// create new account container if needed
if (! isset($_SESSION["profile_account_$scope"])) {
$_SESSION["profile_account_$scope"] = new accountContainer($scope, "profile_account_$scope");
$_SESSION["profile_account_$scope"]->new_account();
}
return $return;
// get options
return $_SESSION["profile_account_$scope"]->checkProfileOptions($options);
}
/**
@ -808,6 +808,22 @@ class accountContainer {
return $return;
}
/**
* Checks the input values of an account profile.
*
* @param array $options list of input values
* @return array list of error messages
*/
function checkProfileOptions($options) {
$return = array();
$modules = array_keys($this->module);
foreach ($modules as $singlemodule) {
$temp = $this->module[$singlemodule]->check_profileOptions($options);
$return = array_merge($return, $temp);
}
return $return;
}
// TODO remove this function?
function proccess_profile($post) {
$return = array();

View File

@ -196,17 +196,6 @@ class account extends baseModule {
return 0;
}
function get_profileOptions() {
return array();
}
// checks if the values of a new or modified profile are valid
// $scope: the account type (user, group, host, ...)
// $options: a hash array (name => value) containing the options
function check_profileOptions($scope, $options) {
return array();
}
function get_pdfFields($account_type="user") {
return array( 'description');
}

View File

@ -42,7 +42,6 @@ class inetOrgPerson extends baseModule {
* Creates a new inetOrgPerson object.
*/
function inetOrgPerson($scope) {
parent::baseModule($scope);
// error messages for input checks
$this->messages['host'] = array('ERROR', _('Unix workstations'), _('Unix workstations is invalid.'));
$this->messages['givenName'] = array('ERROR', _('Given name'), _('Given name contains invalid characters'));
@ -56,6 +55,8 @@ class inetOrgPerson extends baseModule {
$this->messages['postalCode'] = array('ERROR', _('Postal code'), _('Please enter a valid postal code!'));
$this->messages['title'] = array('ERROR', _('Title'), _('Please enter a valid title!'));
$this->messages['employeeType'] = array('ERROR', _('Employee type'), _('Please enter a valid employee type!'));
// call parent constructor
parent::baseModule($scope);
}
/**
@ -71,6 +72,22 @@ class inetOrgPerson extends baseModule {
$return["alias"] = _('Personal');
// module dependencies
$return['dependencies'] = array('depends' => array('posixAccount'), 'conflicts' => array('account'));
// profile elements
$return['profile_options'] = array(
array(
0 => array('kind' => 'text', 'text' => _('Job title') . ":"),
1 => array('kind' => 'input', 'name' => 'inetOrgPerson_title', 'type' => 'text', 'size' => '30', 'maxlength' => '255'),
2 => array('kind' => 'help', 'value' => 'TODO')),
array(
0 => array('kind' => 'text', 'text' => _('Employee type') . ":"),
1 => array('kind' => 'input', 'name' => 'inetOrgPerson_employeeType', 'type' => 'text', 'size' => '30', 'maxlength' => '255'),
2 => array('kind' => 'help', 'value' => 'TODO'))
);
// profile checks
$return['profile_checks']['inetOrgPerson_title'] = array('type' => 'regex_i', 'regex' => $this->regex_title,
'error_message' => $this->messages['title']);
$return['profile_checks']['inetOrgPerson_employeeType'] = array('type' => 'regex_i',
'regex' => $this->regex_employeeType, 'error_message' => $this->messages['employeeType']);
return $return;
}
@ -277,9 +294,9 @@ class inetOrgPerson extends baseModule {
'maxlength' => '255', 'value' => $hostvalues ),
2 => array ('kind' => 'help', 'value' => 'host'));
}
$return[] = array ( 0 => array ( 'kind' => 'text', 'text' => _('Title') ),
$return[] = array ( 0 => array ( 'kind' => 'text', 'text' => _('Job title') ),
1 => array ( 'kind' => 'input', 'name' => 'title', 'type' => 'text', 'size' => '10',
'maxlength' => '10', 'value' => $this->attributes['title'][0] ),
'value' => $this->attributes['title'][0] ),
2 => array ('kind' => 'help', 'value' => 'title'));
if (!$profile) {
$return[] = array ( 0 => array ( 'kind' => 'text', 'text' => _('First name').'*' ),
@ -332,17 +349,6 @@ class inetOrgPerson extends baseModule {
return 0;
}
function get_profileOptions() {
return array();
}
// checks if the values of a new or modified profile are valid
// $scope: the account type (user, group, host, ...)
// $options: a hash array (name => value) containing the options
function check_profileOptions($scope, $options) {
return array();
}
function get_pdfFields($account_type = "user") {
return array( 'description',
'host',

View File

@ -707,7 +707,7 @@ class posixAccount extends baseModule {
// checks if the values of a new or modified profile are valid
// $scope: the account type (user, group, host, ...)
// $options: a hash array (name => value) containing the options
function check_profileOptions($scope, $options) {
function check_profileOptions($options) {
return array();
}

View File

@ -591,7 +591,7 @@ class posixGroup extends baseModule {
// checks if the values of a new or modified profile are valid
// $scope: the account type (user, group, host, ...)
// $options: a hash array (name => value) containing the options
function check_profileOptions($scope, $options) {
function check_profileOptions($options) {
return array();
}

View File

@ -335,7 +335,7 @@ class quota extends baseModule {
// checks if the values of a new or modified profile are valid
// $scope: the account type (user, group, host, ...)
// $options: a hash array (name => value) containing the options
function check_profileOptions($scope, $options) {
function check_profileOptions($options) {
return array();
}

View File

@ -687,7 +687,7 @@ class sambaAccount extends baseModule {
// checks if the values of a new or modified profile are valid
// $scope: the account type (user, group, host, ...)
// $options: a hash array (name => value) containing the options
function check_profileOptions($scope, $options) {
function check_profileOptions($options) {
return array();
}

View File

@ -323,7 +323,7 @@ class sambaGroupMapping extends baseModule {
// checks if the values of a new or modified profile are valid
// $scope: the account type (user, group, host, ...)
// $options: a hash array (name => value) containing the options
function check_profileOptions($scope, $options) {
function check_profileOptions($options) {
return array();
}

View File

@ -713,7 +713,7 @@ class sambaSamAccount extends baseModule {
// checks if the values of a new or modified profile are valid
// $scope: the account type (user, group, host, ...)
// $options: a hash array (name => value) containing the options
function check_profileOptions($scope, $options) {
function check_profileOptions($options) {
return array();
}

View File

@ -296,7 +296,7 @@ class shadowAccount extends baseModule {
// checks if the values of a new or modified profile are valid
// $scope: the account type (user, group, host, ...)
// $options: a hash array (name => value) containing the options
function check_profileOptions($scope, $options) {
function check_profileOptions($options) {
return array();
}