Debian Codegraph @

docs/devel/mod_profiles.htm

raw symbols SCIP
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 &nbsp;&nbsp;&nbsp; * Returns meta data that is interpreted by parent
37 class<br>
38 &nbsp;&nbsp;&nbsp; *<br>
39 &nbsp;&nbsp;&nbsp; * @return array array with meta data<br>
40 &nbsp;&nbsp;&nbsp; */<br>
41 &nbsp;&nbsp;&nbsp; <span style="font-weight: bold;">function</span>
42 get_metaData() {<br>
43 &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; $return = array();<br>
44 &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // profile elements<br>
45 &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; $return[<span style="color: rgb(255, 0, 0);">'profile_options'</span>] = array(<br>
46 &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; new
47 htmlTableExtendedInputField(_('Job title'), 'inetOrgPerson_title',
48 null, 'title'),<br>
49 &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; new htmlTableExtendedInputField(_('Employee type'), 'inetOrgPerson_employeeType', null, 'employeeType')<br>
50 &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; );<br>
51 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [...]<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 &nbsp;&nbsp;&nbsp; * Returns meta data that is interpreted by parent
78 class<br>
79 &nbsp;&nbsp;&nbsp; *<br>
80 &nbsp;&nbsp;&nbsp; * @return array array with meta data<br>
81 &nbsp;&nbsp;&nbsp; */<br>
82 &nbsp;&nbsp;&nbsp; <span style="font-weight: bold;">function</span>
83 get_metaData() {<br>
84 &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; $return = array();<br>
85 &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // profile checks<br>
86 &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;$return[<span style="color: rgb(255, 0, 0);">'profile_checks'</span>][<span style="color: rgb(255, 0, 0);">'inetOrgPerson_title'</span>] = array(<br>
87 &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;'type' =&gt;
88 'ext_preg',<br>
89 &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;'regex' =&gt;
90 'title',<br>
91 &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
92 &nbsp;'error_message' =&gt; $this-&gt;messages['title'][0]);<br>
93 &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;$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 &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;'type' =&gt;
96 'ext_preg',<br>
97 &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;'regex' =&gt;
98 'employeeType',<br>
99 &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
100 &nbsp;'error_message' =&gt; $this-&gt;messages['employeeType'][0]);<br>
101 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [...]<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-&gt;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 &nbsp;&nbsp;&nbsp; * Returns meta data that is interpreted by parent
129 class<br>
130 &nbsp;&nbsp;&nbsp; *<br>
131 &nbsp;&nbsp;&nbsp; * @return array array with meta data<br>
132 &nbsp;&nbsp;&nbsp; */<br>
133 &nbsp;&nbsp;&nbsp; <span style="font-weight: bold;">function</span>
134 get_metaData() {<br>
135 &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; $return = array();<br>
136 &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; // profile mappings<br>
137 &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;$return[<span style="color: rgb(255, 0, 0);">'profile_mappings'</span>] = array(<br>
138 &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
139 &nbsp;'inetLocalMailRecipient_host' =&gt; 'mailHost'<br>
140 &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;);<br>
141 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [...]<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>