| 1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> |
| 2 | <html lang="en"><head><title>Module HowTo - Configuration options</title> |
| 3 | |
| 4 | |
| 5 | <link rel="stylesheet" type="text/css" href="style/layout.css"> |
| 6 | <link rel="shortcut icon" type="image/x-icon" href="images/favicon.ico"></head><body> |
| 7 | <h1>Module HowTo - Configuration options<br> |
| 8 | </h1> |
| 9 | <div style="text-align: left;"><br> |
| 10 | There might be situations where you want to give the user the |
| 11 | possibility to make general settings which are not useful to place on |
| 12 | the account detail pages or profile editor.<br> |
| 13 | Therefore LAM allows the modules to define their own configuration |
| 14 | options. E.g. the <span style="font-style: italic;">posixAccount</span> |
| 15 | module uses this to define the ranges for the UIDs.<br> |
| 16 | LAM will display your configuration options only if the user also |
| 17 | selected your module.<br> |
| 18 | </div> |
| 19 | <div style="text-align: left;"><br> |
| 20 | <h2>1. Defining configuration options<br> |
| 21 | </h2> |
| 22 | First you have to define what options you want to offer the user. LAM |
| 23 | will display all options in one fieldset for each module. Please notice |
| 24 | that there will be no separation on account types if you module is |
| 25 | suitable for different account types.<br> |
| 26 | <br> |
| 27 | The configuration options are specified with <span style="font-weight: bold;">get_configOptions()</span> |
| 28 | or <span style="font-weight: bold;">meta['config_options']</span>.<br> |
| 29 | <br> |
| 30 | <span style="font-weight: bold; text-decoration: underline;">Example:</span><br style="font-weight: bold; text-decoration: underline;"> |
| 31 | <br> |
| 32 | The <span style="font-style: italic;">posixGroup</span> module offers several configuration options including the min/maximum values for GIDs.<br> |
| 33 | <br> |
| 34 | <div class="mod-code"> |
| 35 | * Returns meta data that is interpreted by parent |
| 36 | class<br> |
| 37 | *<br> |
| 38 | * @return array array with meta data<br> |
| 39 | */<br> |
| 40 | <span style="font-weight: bold;"> function</span> |
| 41 | get_metaData() {<br> |
| 42 | $return = array();<br> |
| 43 | // configuration options<br> |
| 44 | $configContainer = new htmlTable();<br> |
| 45 | $configContainer->addElement(new htmlSubTitle(_("Groups")), true);<br> |
| 46 | $minGidInput = new |
| 47 | htmlTableExtendedInputField(_('Minimum GID number'), |
| 48 | 'posixGroup_minGID', null, 'minMaxGID');<br> |
| 49 | $minGidInput->setRequired(true);<br> |
| 50 | $configContainer->addElement($minGidInput, true);<br> |
| 51 | $maxGidInput = new |
| 52 | htmlTableExtendedInputField(_('Maximum GID number'), |
| 53 | 'posixGroup_maxGID', null, 'minMaxGID');<br> |
| 54 | $maxGidInput->setRequired(true);<br> |
| 55 | $configContainer->addElement($maxGidInput, true);<br> |
| 56 | $return[<span style="color: red;">'config_options'</span>][<span style="color: red;">'group'</span>] = $configContainer;<br> |
| 57 | [...]<br> |
| 58 | </div> |
| 59 | <br> |
| 60 | The min/maximum GID numbers are defined with simple text boxes.<br><br> |
| 61 | <h2>2. Checking user input</h2> |
| 62 | Probably you also want to check if the input data is syntactically |
| 63 | correct.<br> |
| 64 | The <span style="font-style: italic;">baseModule</span> already |
| 65 | provides different checks which can be activated with <span style="font-style: italic;">meta data</span>. However you can also do |
| 66 | the checking in the module.<br> |
| 67 | Implementing the function <span style="font-weight: bold;">check_configOptions()</span> |
| 68 | in your module will allow you to do the checks yourself. Basic checks |
| 69 | can be defined with <span style="font-weight: bold;">meta['config_checks']</span>.<br> |
| 70 | <br> |
| 71 | <span style="font-weight: bold; text-decoration: underline;">Example:</span><br style="font-weight: bold; text-decoration: underline;"> |
| 72 | <br> |
| 73 | The <span style="font-style: italic;">posixGroup</span> module only |
| 74 | needs to check if the GID numbers are correct. The password hash type |
| 75 | needs not to be checked as it is a selection.<br> |
| 76 | <br> |
| 77 | <div class="mod-code"> |
| 78 | * Returns meta data that is interpreted by parent |
| 79 | class<br> |
| 80 | *<br> |
| 81 | * @return array array with meta data<br> |
| 82 | */<br> |
| 83 | <span style="font-weight: bold;"> function</span> |
| 84 | get_metaData() {<br> |
| 85 | $return = array();<br> |
| 86 | // configuration checks<br> |
| 87 | $return[<span style="color: rgb(255, 0, 0);">'config_checks'</span>][<span style="color: rgb(255, 0, 0);">'group'</span>]['posixGroup_minGID'] = |
| 88 | array (<br> |
| 89 | 'type' => |
| 90 | 'ext_preg',<br> |
| 91 | 'regex' => |
| 92 | 'digit',<br> |
| 93 | 'required' |
| 94 | => true,<br> |
| 95 | |
| 96 | 'required_message' => $this->messages['gidNumber'][5],<br> |
| 97 | |
| 98 | 'error_message' => $this->messages['gidNumber'][5]);<br> |
| 99 | $return[<span style="color: rgb(255, 0, 0);">'config_checks'</span>][<span style="color: rgb(255, 0, 0);">'group'</span>]['posixGroup_maxGID'] = |
| 100 | array (<br> |
| 101 | 'type' => |
| 102 | 'ext_preg',<br> |
| 103 | 'regex' => |
| 104 | 'digit',<br> |
| 105 | 'required' |
| 106 | => true,<br> |
| 107 | |
| 108 | 'required_message' => $this->messages['gidNumber'][6],<br> |
| 109 | |
| 110 | 'error_message' => $this->messages['gidNumber'][6]);<br> |
| 111 | $return[<span style="color: rgb(255, 0, 0);">'config_checks'</span>][<span style="color: rgb(255, 0, 0);">'group'</span>]['cmpGID'] = array (<br> |
| 112 | 'type' => |
| 113 | 'int_greater',<br> |
| 114 | 'cmp_name1' |
| 115 | => 'posixGroup_maxGID',<br> |
| 116 | 'cmp_name2' |
| 117 | => 'posixGroup_minGID',<br> |
| 118 | |
| 119 | 'error_message' => $this->messages['gidNumber'][7]);<br> |
| 120 | [...]<br> |
| 121 | </div> |
| 122 | <br> |
| 123 | The type <span style="font-weight: bold;">"ext_preg"</span> means that |
| 124 | the <span style="font-style: italic;">baseModule</span> will use the <span style="font-style: italic;">get_preg()</span> function in <span style="font-style: italic;">lib/account.inc</span> for the syntax |
| 125 | check. This function already contains regular expressions for the most |
| 126 | common cases.<br> |
| 127 | To check if the minimum GID is smaller than the maximum GID we define a |
| 128 | check for the nonexistent option "cmpGID" and define it as optional. |
| 129 | This will do the comparison check.<br> |
| 130 | <br> |
| 131 | <br> |
| 132 | </div> |
| 133 | </body></html> |