From c92674a95a27d91812a407f970f2838ed6977eed Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Thu, 1 Jul 2004 15:54:33 +0000 Subject: [PATCH] removed $scope from profile functions, added meta data for profile options and checks --- lam/docs/modules-specification.htm | 85 +++++++++++++++++++++++---- lam/lib/baseModule.inc | 41 +++++++++++++ lam/lib/modules.inc | 28 +++++++-- lam/lib/modules/account.inc | 11 ---- lam/lib/modules/inetOrgPerson.inc | 34 ++++++----- lam/lib/modules/posixAccount.inc | 2 +- lam/lib/modules/posixGroup.inc | 2 +- lam/lib/modules/quota.inc | 2 +- lam/lib/modules/sambaAccount.inc | 2 +- lam/lib/modules/sambaGroupMapping.inc | 2 +- lam/lib/modules/sambaSamAccount.inc | 2 +- lam/lib/modules/shadowAccount.inc | 2 +- 12 files changed, 164 insertions(+), 49 deletions(-) diff --git a/lam/docs/modules-specification.htm b/lam/docs/modules-specification.htm index 3ae271e4..c94d5b3f 100644 --- a/lam/docs/modules-specification.htm +++ b/lam/docs/modules-specification.htm @@ -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".

-

2.2.5. get_profileOptions

+

2.2.5. get_profileOptions*


@@ -279,7 +279,7 @@ section 4. "Help entry syntax".
@@ -288,10 +288,8 @@ section 4. "Help entry syntax".
This function defines what attributes will be used in the account profiles and their appearance in the profile editor.

-$scope is the account type -("user", "group", "host" at this time).
-The return value is an array that contains meta HTML code.
+The return value is an array +that contains meta HTML code.

The type "fieldset" is not allowed here.
The name 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.

-

2.2.6. check_profileOptions

+

2.2.6. check_profileOptions*


function get_profileOptions($scope)
+ style="font-weight: bold;">function get_profileOptions()
@@ -307,8 +305,7 @@ naming confilcts.
@@ -576,8 +573,74 @@ array("user", "host")
style="font-weight: bold; font-style: italic;">"depends" => array("posixAccount", array("qmail", "sendmail")), "conflicts" => array("exim"))
+ style="font-style: italic; font-weight: bold;">)
+

+

6.5 get_profileOptions()
+

+    "profile_options" => array
+
+   Syntax for array is the same as for the +return value of get_profileOptions().
+
+
+

6.6 check_profileOptions()
+

+    "profile_checks" => array
+
+   The keys of the array are +the names of the option identifiers.
+   Each array element is an array containing these values:
+
+ + diff --git a/lam/lib/baseModule.inc b/lam/lib/baseModule.inc index 2ea84091..864c1920 100644 --- a/lam/lib/baseModule.inc +++ b/lam/lib/baseModule.inc @@ -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 } diff --git a/lam/lib/modules.inc b/lam/lib/modules.inc index eba10beb..28b3b1bf 100644 --- a/lam/lib/modules.inc +++ b/lam/lib/modules.inc @@ -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(); diff --git a/lam/lib/modules/account.inc b/lam/lib/modules/account.inc index 59615212..5328c867 100644 --- a/lam/lib/modules/account.inc +++ b/lam/lib/modules/account.inc @@ -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'); } diff --git a/lam/lib/modules/inetOrgPerson.inc b/lam/lib/modules/inetOrgPerson.inc index bac6c07d..46050806 100644 --- a/lam/lib/modules/inetOrgPerson.inc +++ b/lam/lib/modules/inetOrgPerson.inc @@ -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', diff --git a/lam/lib/modules/posixAccount.inc b/lam/lib/modules/posixAccount.inc index 24f4b4b7..4d0c66fa 100644 --- a/lam/lib/modules/posixAccount.inc +++ b/lam/lib/modules/posixAccount.inc @@ -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(); } diff --git a/lam/lib/modules/posixGroup.inc b/lam/lib/modules/posixGroup.inc index be24b147..37db5a81 100644 --- a/lam/lib/modules/posixGroup.inc +++ b/lam/lib/modules/posixGroup.inc @@ -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(); } diff --git a/lam/lib/modules/quota.inc b/lam/lib/modules/quota.inc index 5df7fc7e..890600c0 100644 --- a/lam/lib/modules/quota.inc +++ b/lam/lib/modules/quota.inc @@ -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(); } diff --git a/lam/lib/modules/sambaAccount.inc b/lam/lib/modules/sambaAccount.inc index de857b51..83399b7c 100644 --- a/lam/lib/modules/sambaAccount.inc +++ b/lam/lib/modules/sambaAccount.inc @@ -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(); } diff --git a/lam/lib/modules/sambaGroupMapping.inc b/lam/lib/modules/sambaGroupMapping.inc index 7353ac87..8d12e58a 100644 --- a/lam/lib/modules/sambaGroupMapping.inc +++ b/lam/lib/modules/sambaGroupMapping.inc @@ -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(); } diff --git a/lam/lib/modules/sambaSamAccount.inc b/lam/lib/modules/sambaSamAccount.inc index 0fe61a26..88210ffd 100644 --- a/lam/lib/modules/sambaSamAccount.inc +++ b/lam/lib/modules/sambaSamAccount.inc @@ -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(); } diff --git a/lam/lib/modules/shadowAccount.inc b/lam/lib/modules/shadowAccount.inc index 83c1a200..a7287f60 100644 --- a/lam/lib/modules/shadowAccount.inc +++ b/lam/lib/modules/shadowAccount.inc @@ -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(); }
function check_profileOptions($scope, -$options)
+ style="font-weight: bold;">function check_profileOptions($options)