| 1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> |
| 2 | <html lang="en"><head><title>Module HowTo - Self-service</title> |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | <link rel="stylesheet" type="text/css" href="style/layout.css"> |
| 8 | <link rel="shortcut icon" type="image/x-icon" href="images/favicon.ico"></head><body> |
| 9 | <div style="text-align: center;"> |
| 10 | <h1>Module HowTo - Self-service<br> |
| 11 | </h1> |
| 12 | <div style="text-align: left;"><br> |
| 13 | Self-service is a LAM Pro feature. It allows your users to manage their own data (e.g. telephone numbers).<br> |
| 14 | <br> |
| 15 | </div> |
| 16 | <div style="text-align: left;">First you need to implement the function <span style="font-weight: bold;">getSelfServiceFields()</span> or use <span style="font-weight: bold;">meta['selfServiceFieldSettings']</span>. Each field |
| 17 | has an ID and a descriptive name that will be displayed on the self |
| 18 | service page.<br> |
| 19 | Your input fields may also be defined as read-only in the self-service |
| 20 | profile editor. If your fields supports read-only then use |
| 21 | canSelfServiceFieldBeReadOnly() or <span style="font-weight: bold;">meta['selfServiceReadOnlyFields']</span>.<br> |
| 22 | <br> |
| 23 | <span style="font-weight: bold; text-decoration: underline;">Example:</span><br style="font-weight: bold; text-decoration: underline;"> |
| 24 | <br> |
| 25 | The <span style="font-style: italic;">inetOrgPerson</span> module |
| 26 | provides lots of possible input fields for the self-service.<br> |
| 27 | <br> |
| 28 | <div class="mod-code"> |
| 29 | * Returns meta data that is interpreted by parent |
| 30 | class<br> |
| 31 | *<br> |
| 32 | * @return array array with meta data<br> |
| 33 | */<br> |
| 34 | <span style="font-weight: bold;"> function</span> |
| 35 | get_metaData() {<br> |
| 36 | $return = array();<br> |
| 37 | $return['selfServiceFieldSettings'] = |
| 38 | array('firstName' => _('First name'), 'lastName' => _('Last |
| 39 | name'),<br> |
| 40 | 'mail' => |
| 41 | _('Email address'), 'telephoneNumber' => _('Telephone number'), |
| 42 | 'mobile' => _('Mobile number'),<br> |
| 43 | 'faxNumber' |
| 44 | => _('Fax number'), 'street' => _('Street'), 'postalAddress' |
| 45 | => _('Postal address'), 'registeredAddress' => _('Registered |
| 46 | address'),<br> |
| 47 | 'postalCode' |
| 48 | => _('Postal code'), 'postOfficeBox' => _('Post office box'), |
| 49 | 'jpegPhoto' => _('Photo'),<br> |
| 50 | 'homePhone' |
| 51 | => _('Home telephone number'), 'roomNumber' => _('Room number'), |
| 52 | 'carLicense' => _('Car license'),<br> |
| 53 | 'location' |
| 54 | => _('Location'), 'state' => _('State'), 'officeName' => |
| 55 | _('Office name'), 'businessCategory' => _('Business category'),<br> |
| 56 | |
| 57 | 'departmentNumber' => _('Department'), 'initials' => |
| 58 | _('Initials'), 'title' => _('Job title'), 'labeledURI' => _('Web |
| 59 | site'),<br> |
| 60 | 'userCertificate' => _('User certificates'));<br> |
| 61 | // possible self-service read-only fields<br> |
| 62 | |
| 63 | $return['selfServiceReadOnlyFields'] = array('firstName', |
| 64 | 'lastName', 'mail', 'telephoneNumber', 'mobile', 'faxNumber', 'street',<br> |
| 65 | |
| 66 | 'postalAddress', 'registeredAddress', 'postalCode', |
| 67 | 'postOfficeBox', 'jpegPhoto', 'homePhone', 'roomNumber', 'carLicense',<br> |
| 68 | 'location', |
| 69 | 'state', 'officeName', 'businessCategory', 'departmentNumber', |
| 70 | 'initials', 'title', 'labeledURI', 'userCertificate');<br> |
| 71 | [...]<br> |
| 72 | </div> |
| 73 | <br> |
| 74 | <br> |
| 75 | In very rare cases you need to specify self-service search attributes. |
| 76 | These are used to identify the user inside LDAP. Common examples are |
| 77 | "uid" or "mail".<br> |
| 78 | <br> |
| 79 | <span style="font-weight: bold; text-decoration: underline;">Example:</span><br style="font-weight: bold; text-decoration: underline;"> |
| 80 | |
| 81 | <br> |
| 82 | |
| 83 | The <span style="font-style: italic;">inetOrgPerson</span> module specifies several search attributes.<br> |
| 84 | |
| 85 | <br> |
| 86 | |
| 87 | <div class="mod-code"> |
| 88 | * Returns meta data that is interpreted by parent |
| 89 | class<br> |
| 90 | *<br> |
| 91 | * @return array array with meta data<br> |
| 92 | */<br> |
| 93 | <span style="font-weight: bold;"> function</span> |
| 94 | get_metaData() {<br> |
| 95 | $return = array();<br> // self-service search attributes<br> |
| 96 | |
| 97 | $return['selfServiceSearchAttributes'] = array('uid', 'mail', |
| 98 | 'cn', 'surname', 'givenName', 'employeeNumber');<br> |
| 99 | [...]<br> |
| 100 | </div> |
| 101 | |
| 102 | <br> |
| 103 | |
| 104 | <br> |
| 105 | |
| 106 | The HTML code for the user page is generated with the function <span style="font-weight: bold;">getSelfServiceOptions()</span>. It returns one table row for each input field.<br> |
| 107 | Please note that some fields may be defined as read-only |
| 108 | ($readOnlyFields). If $passwordChangeOnly is set then no input fields |
| 109 | other than the bind password should be displayed (you will not get any |
| 110 | attribute values).<br> |
| 111 | |
| 112 | |
| 113 | |
| 114 | <br> |
| 115 | <span style="font-weight: bold; text-decoration: underline;">Example:</span><br style="font-weight: bold; text-decoration: underline;"> |
| 116 | |
| 117 | |
| 118 | <br> |
| 119 | |
| 120 | |
| 121 | The <span style="font-style: italic;">windowsUser</span> module uses |
| 122 | the addSimpleSelfServiceTextField() function from baseModule to print |
| 123 | the text field. You may also build the table row yourself if the input |
| 124 | field is more complex.<br> |
| 125 | <br> |
| 126 | |
| 127 | |
| 128 | <div class="mod-code"> |
| 129 | * Returns the meta HTML code for each input field.<br> |
| 130 | * format: array(<field1> => array(<META HTML>), ...)<br> |
| 131 | * It is not possible to display help links.<br> |
| 132 | *<br> |
| 133 | * @param array $fields list of active fields<br> |
| 134 | * @param array $attributes attributes of LDAP account<br> |
| 135 | * @param boolean $passwordChangeOnly indicates |
| 136 | that the user is only allowed to change his password and no LDAP |
| 137 | content is readable<br> |
| 138 | * @param array $readOnlyFields list of read-only fields<br> |
| 139 | * @return array list of meta HTML elements (field name => htmlTableRow)<br> |
| 140 | */<br> |
| 141 | function getSelfServiceOptions($fields, $attributes, $passwordChangeOnly, $readOnlyFields) {<br> |
| 142 | $return = array();<br> |
| 143 | if ($passwordChangeOnly) {<br> |
| 144 | return |
| 145 | $return; // only password fields as long no LDAP content can be read<br> |
| 146 | }<br> |
| 147 | |
| 148 | $this->addSimpleSelfServiceTextField($return, |
| 149 | 'physicalDeliveryOfficeName', _('Office name'), $fields, $attributes, |
| 150 | $readOnlyFields);<br> |
| 151 | [...]<br> |
| 152 | </div> |
| 153 | |
| 154 | |
| 155 | <br> |
| 156 | |
| 157 | |
| 158 | <br> |
| 159 | Of course, the user input should also be validated before making any LDAP changes. This is done in <span style="font-weight: bold;">checkSelfServiceOptions()</span>.<br> |
| 160 | The return value includes any error messages to display and also all LDAP operations.<br> |
| 161 | Please note that some fields may be defined as read-only |
| 162 | ($readOnlyFields). If $passwordChangeOnly is set then no input fields |
| 163 | other than the bind |
| 164 | password should be displayed (you will not get any attribute values).<br> |
| 165 | |
| 166 | |
| 167 | |
| 168 | |
| 169 | <br> |
| 170 | <span style="font-weight: bold; text-decoration: underline;">Example:</span><br style="font-weight: bold; text-decoration: underline;"> |
| 171 | |
| 172 | |
| 173 | |
| 174 | <br> |
| 175 | The <span style="font-style: italic;">inetOrgPerson</span> module has a field for the user's first name.<br> |
| 176 | <br> |
| 177 | |
| 178 | |
| 179 | |
| 180 | <div class="mod-code"> |
| 181 | * Checks if all input values are correct and returns the LDAP attributes which should be changed.<br> |
| 182 | * <br>Return values:<br> |
| 183 | * <br>messages: array of parameters to create status messages<br> |
| 184 | * <br>add: array of attributes to add<br> |
| 185 | * <br>del: array of attributes to remove<br> |
| 186 | * <br>mod: array of attributes to modify<br> |
| 187 | * <br>info: array of values with |
| 188 | informational value (e.g. to be used later by pre/postModify actions)<br> |
| 189 | * <br> |
| 190 | * Calling this method does not require the existence of an enclosing {@link accountContainer}.<br> |
| 191 | *<br> |
| 192 | * @param string $fields input fields<br> |
| 193 | * @param array $attributes LDAP attributes<br> |
| 194 | * @param boolean $passwordChangeOnly indicates |
| 195 | that the user is only allowed to change his password and no LDAP |
| 196 | content is readable<br> |
| 197 | * @param array $readOnlyFields list of read-only fields<br> |
| 198 | * @return array messages and attributes |
| 199 | (array('messages' => array(), 'add' => array('mail' => |
| 200 | array('[email protected]')), 'del' => array(), 'mod' => array(), |
| 201 | 'info' => array()))<br> |
| 202 | */<br> |
| 203 | function checkSelfServiceOptions($fields, $attributes, $passwordChangeOnly, $readOnlyFields) {<br> |
| 204 | $return = array('messages' => |
| 205 | array(), 'add' => array(), 'del' => array(), 'mod' => array(), |
| 206 | 'info' => array());<br> |
| 207 | if ($passwordChangeOnly) {<br> |
| 208 | return $return; // skip processing if only a password change is done<br> |
| 209 | }<br> |
| 210 | $attributeNames = array(); // list of attributes which should be checked for modification<br> |
| 211 | $attributesNew = $attributes;<br> |
| 212 | // first name<br> |
| 213 | if (in_array('firstName', $fields) && !in_array('firstName', $readOnlyFields)) {<br> |
| 214 | $attributeNames[] = 'givenName';<br> |
| 215 | if |
| 216 | (isset($_POST['inetOrgPerson_firstName']) && |
| 217 | ($_POST['inetOrgPerson_firstName'] != '')) {<br> |
| 218 | |
| 219 | if (!get_preg($_POST['inetOrgPerson_firstName'], |
| 220 | 'realname')) $return['messages'][] = $this->messages['givenName'][0];<br> |
| 221 | |
| 222 | else $attributesNew['givenName'][0] = |
| 223 | $_POST['inetOrgPerson_firstName'];<br> |
| 224 | }<br> |
| 225 | elseif |
| 226 | (isset($attributes['givenName'])) unset($attributesNew['givenName']);<br> |
| 227 | }<br> |
| 228 | [...]<br> |
| 229 | </div> |
| 230 | <br> |
| 231 | <br> |
| 232 | The self-service also supports configuration settings for each module. See <span style="font-weight: bold;">getSelfServiceSettings() </span>or <span style="font-weight: bold;">meta['selfServiceSettings'] </span>to specify the options.<br> |
| 233 | You can validate the input with <span style="font-weight: bold;">checkSelfServiceSettings()</span>.<br> |
| 234 | Self-service configuration settings are displayed on a separate tab in the self-service profile editor.<br> |
| 235 | <br> |
| 236 | </div> |
| 237 | </div> |
| 238 | </body></html> |