| 1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> |
| 2 | <html lang="en"><head><title>Module HowTo - Account profiles</title> |
| 3 | |
| 4 | |
| 5 | <link rel="stylesheet" type="text/css" href="style/layout.css"><link rel="shortcut icon" type="image/x-icon" href="images/favicon.ico"></head><body> |
| 6 | <div style="text-align: center;"> |
| 7 | <h1>Module HowTo - Account profiles<br> |
| 8 | </h1> |
| 9 | <div style="text-align: left;"><br> |
| 10 | Account profiles make it easy to set default values for new accounts |
| 11 | and even to reset an existing account to default values.<br> |
| 12 | Your module should provide the possibility to define default values for |
| 13 | all attributes which do not differ for each account.<br> |
| 14 | </div> |
| 15 | <div style="text-align: left;"><br> |
| 16 | <h2>1. Defining possible profile options<br> |
| 17 | </h2> |
| 18 | The first step to account profiles is defining the attributes for which |
| 19 | the user can set default values. You will also have to define the type |
| 20 | (text, checkbox, ...) of the profile options.<br> |
| 21 | The profile editor then will display a fieldset for each module |
| 22 | containing its profile options.<br> |
| 23 | <br> |
| 24 | The profile options are specified with <span style="font-weight: bold;">get_profileOptions()</span> |
| 25 | or <span style="font-weight: bold;">meta['profile_options']</span>.<br> |
| 26 | <br> |
| 27 | <span style="font-weight: bold; text-decoration: underline;">Example:</span><br style="font-weight: bold; text-decoration: underline;"> |
| 28 | <br> |
| 29 | The <span style="font-style: italic;">inetOrgPerson</span> |
| 30 | module has only two attributes which may be set to a default value: job |
| 31 | title and employee type.<br> |
| 32 | The other attributes are account specific and not useful as profile |
| 33 | options.<br> |
| 34 | <br> |
| 35 | <div class="mod-code"> |
| 36 | * Returns meta data that is interpreted by parent |
| 37 | class<br> |
| 38 | *<br> |
| 39 | * @return array array with meta data<br> |
| 40 | */<br> |
| 41 | <span style="font-weight: bold;">function</span> |
| 42 | get_metaData() {<br> |
| 43 | $return = array();<br> |
| 44 | // profile elements<br> |
| 45 | $return[<span style="color: rgb(255, 0, 0);">'profile_options'</span>] = array(<br> |
| 46 | new |
| 47 | htmlTableExtendedInputField(_('Job title'), 'inetOrgPerson_title', |
| 48 | null, 'title'),<br> |
| 49 | new htmlTableExtendedInputField(_('Employee type'), 'inetOrgPerson_employeeType', null, 'employeeType')<br> |
| 50 | );<br> |
| 51 | [...]<br> |
| 52 | </div> |
| 53 | <br> |
| 54 | This defines two text boxes in the profile editor, one for the job |
| 55 | title and one for the employee type.<br> |
| 56 | Your profile options should also provide a help link because the description |
| 57 | of the input element might be not enough.<br> |
| 58 | <br> |
| 59 | <br> |
| 60 | <h2>2. Checking user input</h2> |
| 61 | Probably you also want to check if the input data is syntactically |
| 62 | correct.<br> |
| 63 | The <span style="font-style: italic;">baseModule</span> already |
| 64 | provides different checks which can be activated with <span style="font-style: italic;">meta data</span>. However you can also do |
| 65 | the checking in the module.<br> |
| 66 | Implementing the function <span style="font-weight: bold;">check_profileOptions()</span> |
| 67 | in your module will allow you to do the checks yourself. Basic checks |
| 68 | can be defined with <span style="font-weight: bold;">meta['profile_checks']</span>.<br> |
| 69 | <br> |
| 70 | <span style="font-weight: bold; text-decoration: underline;">Example:</span><br style="font-weight: bold; text-decoration: underline;"> |
| 71 | <br> |
| 72 | The <span style="font-style: italic;">inetOrgPerson</span> module only |
| 73 | needs some regular expression checks on the input. This can be done by |
| 74 | the <span style="font-style: italic;">baseModule</span>.<br> |
| 75 | <br> |
| 76 | <div class="mod-code"> |
| 77 | * Returns meta data that is interpreted by parent |
| 78 | class<br> |
| 79 | *<br> |
| 80 | * @return array array with meta data<br> |
| 81 | */<br> |
| 82 | <span style="font-weight: bold;">function</span> |
| 83 | get_metaData() {<br> |
| 84 | $return = array();<br> |
| 85 | // profile checks<br> |
| 86 | $return[<span style="color: rgb(255, 0, 0);">'profile_checks'</span>][<span style="color: rgb(255, 0, 0);">'inetOrgPerson_title'</span>] = array(<br> |
| 87 | 'type' => |
| 88 | 'ext_preg',<br> |
| 89 | 'regex' => |
| 90 | 'title',<br> |
| 91 | |
| 92 | 'error_message' => $this->messages['title'][0]);<br> |
| 93 | $return[<span style="color: rgb(255, 0, 0);">'profile_checks'</span>][<span style="color: rgb(255, 0, 0);">'inetOrgPerson_employeeType'</span>] = |
| 94 | array(<br> |
| 95 | 'type' => |
| 96 | 'ext_preg',<br> |
| 97 | 'regex' => |
| 98 | 'employeeType',<br> |
| 99 | |
| 100 | 'error_message' => $this->messages['employeeType'][0]);<br> |
| 101 | [...]<br> |
| 102 | </div> |
| 103 | <br> |
| 104 | The type <span style="font-weight: bold;">"ext_preg"</span> means that |
| 105 | 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 |
| 106 | check. This function already contains regular expressions for the most |
| 107 | common cases.<br> |
| 108 | <br> |
| 109 | <br> |
| 110 | <h2>3. Loading an account profile</h2> |
| 111 | When an account profile is loaded the modules have to check what values |
| 112 | they need for their internal data structures.<br> |
| 113 | The <span style="font-style: italic;">baseModule</span> already |
| 114 | provides the possibility to store profile values directly as LDAP |
| 115 | attributes in <span style="font-style: italic;">$this->attributes</span>. |
| 116 | This is done by defining profile-attribute mappings in <span style="font-weight: bold;">meta['profile_mappings']</span>.<br> |
| 117 | If you have other values than LDAP attributes or need some post |
| 118 | processing you can implement the function <span style="font-weight: bold;">load_profile()</span> in your module.<br> |
| 119 | <br> |
| 120 | <span style="font-weight: bold; text-decoration: underline;">Example:</span><br style="font-weight: bold; text-decoration: underline;"> |
| 121 | <br> |
| 122 | The <span style="font-style: italic;">inetLocalMailRecipient</span> |
| 123 | module only |
| 124 | needs a static mapping. This can be done by |
| 125 | the <span style="font-style: italic;">baseModule</span>.<br> |
| 126 | <br> |
| 127 | <div class="mod-code"> |
| 128 | * Returns meta data that is interpreted by parent |
| 129 | class<br> |
| 130 | *<br> |
| 131 | * @return array array with meta data<br> |
| 132 | */<br> |
| 133 | <span style="font-weight: bold;">function</span> |
| 134 | get_metaData() {<br> |
| 135 | $return = array();<br> |
| 136 | // profile mappings<br> |
| 137 | $return[<span style="color: rgb(255, 0, 0);">'profile_mappings'</span>] = array(<br> |
| 138 | |
| 139 | 'inetLocalMailRecipient_host' => 'mailHost'<br> |
| 140 | );<br> |
| 141 | [...]<br> |
| 142 | </div> |
| 143 | <br> |
| 144 | In this example the profile option "inetLocalMailRecipient_host" is |
| 145 | stored as LDAP attribute "mailHost".<br> |
| 146 | <br> |
| 147 | <br> |
| 148 | </div> |
| 149 | </div> |
| 150 | </body></html> |