updated module HowTo
This commit is contained in:
parent
23f9128d43
commit
d73da87f8c
|
@ -11,7 +11,75 @@
|
||||||
<br>
|
<br>
|
||||||
<br>
|
<br>
|
||||||
<div style="text-align: left;"><br>
|
<div style="text-align: left;"><br>
|
||||||
<h2>1. Defining pages<br>
|
<h2>1. Loading the LDAP attributes<br>
|
||||||
|
</h2>
|
||||||
|
Every time the user selects an existing account to modify LAM will load
|
||||||
|
the complete LDAP entry of it. Your module then should select the
|
||||||
|
attributes which are useful for it.<br>
|
||||||
|
There are two variables in <span style="font-style: italic;">baseModule</span>
|
||||||
|
which should be used to store the attributes. The <span
|
||||||
|
style="font-weight: bold;">$attributes</span> variable stores the
|
||||||
|
current attributes including changes the user made. The <span
|
||||||
|
style="font-weight: bold;">$orig</span> variable stores the attributes
|
||||||
|
as they were originally when the account was loaded. This allows you to
|
||||||
|
see what changes were made.<br>
|
||||||
|
<br>
|
||||||
|
The <span style="font-weight: bold;">load_attributes()</span> function
|
||||||
|
in your module gets the complete attribute list from LDAP.<br>
|
||||||
|
<br>
|
||||||
|
<span style="font-weight: bold; text-decoration: underline;">Example:</span><br
|
||||||
|
style="font-weight: bold; text-decoration: underline;">
|
||||||
|
<br>
|
||||||
|
The <span style="font-style: italic;">ieee802Device</span> uses an
|
||||||
|
object class and the <span style="font-style: italic;">'macAddress'</span>
|
||||||
|
attribute. Therefore we will save this two values.<br>
|
||||||
|
<br>
|
||||||
|
<table style="width: 100%; text-align: left;" class="mod-code"
|
||||||
|
border="0" cellpadding="2" cellspacing="2">
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td style="vertical-align: top;"> /**<br>
|
||||||
|
* This function loads all needed attributes into the
|
||||||
|
object.<br>
|
||||||
|
*<br>
|
||||||
|
* @param array $attr an array as it is retured from
|
||||||
|
ldap_get_attributes<br>
|
||||||
|
*/<br>
|
||||||
|
<span style="font-weight: bold;">function</span> <span
|
||||||
|
style="color: rgb(255, 0, 0);">load_attributes</span>($attr) {<br>
|
||||||
|
|
||||||
|
$this->attributes['objectClass'] = array();<br>
|
||||||
|
|
||||||
|
$this->attributes['macAddress'] = array();<br>
|
||||||
|
$this->orig['objectClass'] =
|
||||||
|
array();<br>
|
||||||
|
$this->orig['macAddress'] =
|
||||||
|
array();<br>
|
||||||
|
if (isset($attr['objectClass'])) {<br>
|
||||||
|
|
||||||
|
unset($attr['objectClass']['count']);<br>
|
||||||
|
|
||||||
|
$this->attributes['objectClass'] = $attr['objectClass'];<br>
|
||||||
|
|
||||||
|
$this->orig['objectClass'] = $attr['objectClass'];<br>
|
||||||
|
}<br>
|
||||||
|
if (isset($attr['macAddress'])) {<br>
|
||||||
|
|
||||||
|
unset($attr['macAddress']['count']);<br>
|
||||||
|
|
||||||
|
$this->attributes['macAddress'] = $attr['macAddress'];<br>
|
||||||
|
|
||||||
|
$this->orig['macAddress'] = $attr['macAddress'];<br>
|
||||||
|
}<br>
|
||||||
|
return 0;<br>
|
||||||
|
}<br>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<br>
|
||||||
|
<br>
|
||||||
|
<h2>2. Defining pages<br>
|
||||||
</h2>
|
</h2>
|
||||||
You can define multiple subpages for your account page. Usually one
|
You can define multiple subpages for your account page. Usually one
|
||||||
page is enough but you may display certain attribute settings on an
|
page is enough but you may display certain attribute settings on an
|
||||||
|
@ -46,7 +114,7 @@ in this module.<br>
|
||||||
</table>
|
</table>
|
||||||
<br>
|
<br>
|
||||||
<br>
|
<br>
|
||||||
<h2>2. Page display</h2>
|
<h2>3. Page display</h2>
|
||||||
Now that you have defined your subpages you will need one function for
|
Now that you have defined your subpages you will need one function for
|
||||||
each page to display it. The function must return <span
|
each page to display it. The function must return <span
|
||||||
style="font-style: italic;">meta HTML code</span> as defined in the <span
|
style="font-style: italic;">meta HTML code</span> as defined in the <span
|
||||||
|
@ -65,7 +133,7 @@ module has only one subpage called <span style="font-style: italic;">'attributes
|
||||||
The first half of the code displays the existing MAC addresses and the
|
The first half of the code displays the existing MAC addresses and the
|
||||||
second an input field for new values.<br>
|
second an input field for new values.<br>
|
||||||
The variable <span style="font-style: italic;">$this->attributes</span>
|
The variable <span style="font-style: italic;">$this->attributes</span>
|
||||||
contains all LDAP attributes of an account.<br>
|
contains the LDAP attributes which are useful for this module.<br>
|
||||||
<br>
|
<br>
|
||||||
<table style="width: 100%; text-align: left;" class="mod-code"
|
<table style="width: 100%; text-align: left;" class="mod-code"
|
||||||
border="0" cellpadding="2" cellspacing="2">
|
border="0" cellpadding="2" cellspacing="2">
|
||||||
|
@ -122,7 +190,7 @@ sizeof($this->attributes['macAddress']), 'name' => 'mac_number'));<br>
|
||||||
</table>
|
</table>
|
||||||
<br>
|
<br>
|
||||||
<br>
|
<br>
|
||||||
<h2>3. Processing input data<br>
|
<h2>4. Processing input data<br>
|
||||||
</h2>
|
</h2>
|
||||||
Every time the user clicks on a submit button while your page is
|
Every time the user clicks on a submit button while your page is
|
||||||
displayed LAM will call a function in your module.<br>
|
displayed LAM will call a function in your module.<br>
|
||||||
|
@ -234,7 +302,7 @@ $this->inputCorrect = true;<br>
|
||||||
</table>
|
</table>
|
||||||
<br>
|
<br>
|
||||||
<br>
|
<br>
|
||||||
<h2>4. Defining that your module is ready for LDAP add/modify</h2>
|
<h2>5. Defining that your module is ready for LDAP add/modify</h2>
|
||||||
Before a new account can be created or modified all modules are asked
|
Before a new account can be created or modified all modules are asked
|
||||||
if they are ready.<br>
|
if they are ready.<br>
|
||||||
There are two functions which control the module status. The <span
|
There are two functions which control the module status. The <span
|
||||||
|
@ -263,13 +331,15 @@ because the MAC address is optional.<br>
|
||||||
<tr>
|
<tr>
|
||||||
<td style="vertical-align: top;"> /** used for
|
<td style="vertical-align: top;"> /** used for
|
||||||
account pages, true if input data is correct */<br>
|
account pages, true if input data is correct */<br>
|
||||||
var $inputCorrect = true;<br>
|
<span style="font-weight: bold;">var</span>
|
||||||
|
$inputCorrect = true;<br>
|
||||||
<br>
|
<br>
|
||||||
/**<br>
|
/**<br>
|
||||||
* This function returns true if all needed settings
|
* This function returns true if all needed settings
|
||||||
are done.<br>
|
are done.<br>
|
||||||
*/<br>
|
*/<br>
|
||||||
function module_complete() {<br>
|
<span style="font-weight: bold;">function</span> <span
|
||||||
|
style="color: rgb(255, 0, 0);">module_complete</span>() {<br>
|
||||||
return $this->inputCorrect;<br>
|
return $this->inputCorrect;<br>
|
||||||
}<br>
|
}<br>
|
||||||
<br>
|
<br>
|
||||||
|
@ -277,7 +347,8 @@ are done.<br>
|
||||||
* Returns true if all settings on module page are
|
* Returns true if all settings on module page are
|
||||||
correct.<br>
|
correct.<br>
|
||||||
*/<br>
|
*/<br>
|
||||||
function module_ready() {<br>
|
<span style="font-weight: bold;">function</span> <span
|
||||||
|
style="color: rgb(255, 0, 0);">module_ready</span>() {<br>
|
||||||
return $this->inputCorrect;<br>
|
return $this->inputCorrect;<br>
|
||||||
}<br>
|
}<br>
|
||||||
</td>
|
</td>
|
||||||
|
@ -286,20 +357,55 @@ correct.<br>
|
||||||
</table>
|
</table>
|
||||||
<br>
|
<br>
|
||||||
<br>
|
<br>
|
||||||
<h2>5. Saving the LDAP attributes<br>
|
<h2>6. Saving the LDAP attributes<br>
|
||||||
</h2>
|
</h2>
|
||||||
<br>
|
When all modules report that they are ready for LDAP add/modify and the
|
||||||
|
user clicks on the add/modify button your module will be asked what
|
||||||
|
changes have to be made.<br>
|
||||||
|
This is done in the function <span style="font-weight: bold;">save_attributes()</span>
|
||||||
|
which must be implemented by your module.<br>
|
||||||
<br>
|
<br>
|
||||||
<span style="font-weight: bold; text-decoration: underline;">Example:</span><br
|
<span style="font-weight: bold; text-decoration: underline;">Example:</span><br
|
||||||
style="font-weight: bold; text-decoration: underline;">
|
style="font-weight: bold; text-decoration: underline;">
|
||||||
<br>
|
<br>
|
||||||
<br>
|
The <span style="font-style: italic;">ieee802Device</span>
|
||||||
|
module saves the attribute states in <span style="font-style: italic;">$attributes</span>
|
||||||
|
and <span style="font-style: italic;">$orig</span> and there are no
|
||||||
|
other DNs which may be modified. Therefore we can use the <span
|
||||||
|
style="font-weight: bold;">save_module_attributes()</span> function in
|
||||||
|
<span style="font-weight: bold;">accountContainer</span>. You can
|
||||||
|
always access the current <span style="font-weight: bold;">accountContainer</span>
|
||||||
|
with <span style="font-weight: bold;">$_SESSION[$this->base]</span>.<br>
|
||||||
<br>
|
<br>
|
||||||
<table style="width: 100%; text-align: left;" class="mod-code"
|
<table style="width: 100%; text-align: left;" class="mod-code"
|
||||||
border="0" cellpadding="2" cellspacing="2">
|
border="0" cellpadding="2" cellspacing="2">
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr>
|
<tr>
|
||||||
<td style="vertical-align: top;"> <br>
|
<td style="vertical-align: top;"> /**<br>
|
||||||
|
* Returns a list of modifications which have to be
|
||||||
|
made to the LDAP account.<br>
|
||||||
|
*<br>
|
||||||
|
* @return array list of modifications<br>
|
||||||
|
* <br>This function returns an array with 3
|
||||||
|
entries:<br>
|
||||||
|
* <br>array( DN1 ('add' => array($attr),
|
||||||
|
'remove' => array($attr), 'modify' => array($attr)), DN2 .... )<br>
|
||||||
|
* <br>DN is the DN to change. It may be
|
||||||
|
possible to change several DNs (e.g. create a new user and add him to
|
||||||
|
some groups via attribute memberUid)<br>
|
||||||
|
* <br>"add" are attributes which have to be
|
||||||
|
added to LDAP entry<br>
|
||||||
|
* <br>"remove" are attributes which have to be
|
||||||
|
removed from LDAP entry<br>
|
||||||
|
* <br>"modify" are attributes which have to
|
||||||
|
been modified in LDAP entry<br>
|
||||||
|
*/<br>
|
||||||
|
<span style="font-weight: bold;">function</span> <span
|
||||||
|
style="color: rgb(255, 0, 0);">save_attributes</span>() {<br>
|
||||||
|
return
|
||||||
|
$_SESSION[$this->base]->save_module_attributes($this->attributes,
|
||||||
|
$this->orig);<br>
|
||||||
|
}<br>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|
|
@ -0,0 +1,107 @@
|
||||||
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Module HowTo - PDF output</title>
|
||||||
|
<link rel="stylesheet" type="text/css" href="style/layout.css">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div style="text-align: center;">
|
||||||
|
<h1>Module HowTo - PDF output<br>
|
||||||
|
</h1>
|
||||||
|
<br>
|
||||||
|
<br>
|
||||||
|
<div style="text-align: left;"><br>
|
||||||
|
<h2>1. Defining possible PDF values<br>
|
||||||
|
</h2>
|
||||||
|
The first step to PDF output is defining what values your module
|
||||||
|
provides. This is needed for the PDF editor, otherwise the user will
|
||||||
|
not be able to select values from your module.<br>
|
||||||
|
<br>
|
||||||
|
The PDF values are specified with <span style="font-weight: bold;">get_pdfFields()</span>
|
||||||
|
or <span style="font-weight: bold;">meta['PDF_fields']</span>.<br>
|
||||||
|
<br>
|
||||||
|
<span style="font-weight: bold; text-decoration: underline;">Example:</span><br
|
||||||
|
style="font-weight: bold; text-decoration: underline;">
|
||||||
|
<br>
|
||||||
|
The <span style="font-style: italic;">ieee802Device</span>
|
||||||
|
module has only one attribute and therefore one PDF value: the MAC
|
||||||
|
address.<br>
|
||||||
|
<br>
|
||||||
|
<table style="width: 100%; text-align: left;" class="mod-code"
|
||||||
|
border="0" cellpadding="2" cellspacing="2">
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td style="vertical-align: top;">
|
||||||
|
/**<br>
|
||||||
|
* Returns meta data that is interpreted by parent
|
||||||
|
class<br>
|
||||||
|
*<br>
|
||||||
|
* @return array array with meta data<br>
|
||||||
|
*/<br>
|
||||||
|
<span style="font-weight: bold;">function</span>
|
||||||
|
get_metaData() {<br>
|
||||||
|
$return = array();<br>
|
||||||
|
[...]<br>
|
||||||
|
// available PDF fields<br>
|
||||||
|
<span style="color: rgb(255, 0, 0);">
|
||||||
|
$return['PDF_fields'] = array(</span><br
|
||||||
|
style="color: rgb(255, 0, 0);">
|
||||||
|
<span style="color: rgb(255, 0, 0);">
|
||||||
|
'macAddress'</span><br
|
||||||
|
style="color: rgb(255, 0, 0);">
|
||||||
|
<span style="color: rgb(255, 0, 0);">
|
||||||
|
);</span><br style="color: rgb(255, 0, 0);">
|
||||||
|
return $return;<br>
|
||||||
|
}<br>
|
||||||
|
<br>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<br>
|
||||||
|
<br>
|
||||||
|
<h2>2. Providing data to put into the PDF file<br>
|
||||||
|
</h2>
|
||||||
|
When the user wants to create a PDF file the LDAP account is loaded and
|
||||||
|
you module is asked for data to put into the PDF file.<br>
|
||||||
|
<br>
|
||||||
|
This is done with <span style="font-weight: bold;">get_pdfEntries()</span>.<br>
|
||||||
|
<br>
|
||||||
|
<span style="font-weight: bold; text-decoration: underline;">Example:</span><br
|
||||||
|
style="font-weight: bold; text-decoration: underline;">
|
||||||
|
<br>
|
||||||
|
The <span style="font-style: italic;">ieee802Device</span>
|
||||||
|
module will return the MAC address list of the account.<br>
|
||||||
|
<br>
|
||||||
|
<table style="width: 100%; text-align: left;" class="mod-code"
|
||||||
|
border="0" cellpadding="2" cellspacing="2">
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td style="vertical-align: top;"> /**<br>
|
||||||
|
* Returns a list of PDF entries<br>
|
||||||
|
*/<br>
|
||||||
|
function get_pdfEntries() {<br>
|
||||||
|
$return = array();<br>
|
||||||
|
if
|
||||||
|
(sizeof($this->attributes['macAddress']) > 0) {<br>
|
||||||
|
|
||||||
|
$return['ieee802Device_macAddress'] = '<block><key>' .
|
||||||
|
_('MAC address list') . '</key><value>' . implode(', ',
|
||||||
|
$this->attributes['macAddress']) . '</value></block>';<br>
|
||||||
|
}<br>
|
||||||
|
return $return;<br>
|
||||||
|
}<br>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<br>
|
||||||
|
<br>
|
||||||
|
<br>
|
||||||
|
<br>
|
||||||
|
<span style="font-weight: bold;"></span>
|
||||||
|
<h2><span style="font-weight: bold;"></span></h2>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
Loading…
Reference in New Issue