LDAPAccountManager/lam/docs/devel/mod_upload.htm

172 lines
7.2 KiB
HTML
Raw Normal View History

2004-11-01 13:56:54 +00:00
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Module HowTo - File upload</title>
<link rel="stylesheet" type="text/css" href="style/layout.css">
</head>
<body>
<div style="text-align: center;">
<h1>Module HowTo - File upload<br>
</h1>
<br>
<br>
<div style="text-align: left;"><br>
<h2>1. Defining upload columns<br>
</h2>
If you want to support account creation via file upload you have to
define columns in the CSV file.<br>
Each column has an non-translated identifier, a description, help entry
and several other values.<br>
<br>
The upload columns are specified with <span style="font-weight: bold;">get_uploadColumns()</span>
or <span style="font-weight: bold;">meta['upload_columns']</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 column: 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;">&nbsp;&nbsp;&nbsp; /**<br>
&nbsp;&nbsp;&nbsp; * Returns meta data that is interpreted by parent
class<br>
&nbsp;&nbsp;&nbsp; *<br>
&nbsp;&nbsp;&nbsp; * @return array array with meta data<br>
&nbsp;&nbsp;&nbsp; */<br>
&nbsp;&nbsp;&nbsp; <span style="font-weight: bold;">function</span>
get_metaData() {<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; $return = array();<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // manages host accounts<br>
&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp; $return["account_types"] = array("host");<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // upload fields<br>
<span style="color: rgb(255, 0, 0);">&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp; $return['upload_columns'] = array(</span><br
style="color: rgb(255, 0, 0);">
<span style="color: rgb(255, 0, 0);">&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;array(</span><br
style="color: rgb(255, 0, 0);">
<span style="color: rgb(255, 0, 0);">&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;'name' =&gt;
'ieee802Device_mac',</span><br style="color: rgb(255, 0, 0);">
<span style="color: rgb(255, 0, 0);">&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;'description'
=&gt; _('MAC address'),</span><br style="color: rgb(255, 0, 0);">
<span style="color: rgb(255, 0, 0);">&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;'help' =&gt;
'mac',</span><br style="color: rgb(255, 0, 0);">
<span style="color: rgb(255, 0, 0);">&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;'example'
=&gt; '00:01:02:DE:EF:18'</span><br style="color: rgb(255, 0, 0);">
<span style="color: rgb(255, 0, 0);">&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; )</span><br
style="color: rgb(255, 0, 0);">
<span style="color: rgb(255, 0, 0);">&nbsp;&nbsp; &nbsp;
&nbsp;&nbsp; );</span><br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return $return;<br>
&nbsp;&nbsp;&nbsp; }<br>
</td>
</tr>
</tbody>
</table>
<br>
<br>
<h2>2. Building the accounts<br>
</h2>
When the user has uploaded the CSV file the modules have to transform
the input data to LDAP accounts.<br>
<br>
This is done with <span style="font-weight: bold;">build_uploadAccounts()</span>.
The function gets the input data and a list of LDAP accounts as
parameter.<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 LDAP attribute - <span style="font-style: italic;">'macAddress'</span>
- and the <span style="font-style: italic;">'ieee802Device'</span>
objectClass which is added to all accounts.<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;">&nbsp;&nbsp;&nbsp; /**<br>
&nbsp;&nbsp;&nbsp; * In this function the LDAP account is built up.<br>
&nbsp;&nbsp;&nbsp; *<br>
&nbsp;&nbsp;&nbsp; * @param array $rawAccounts list of hash arrays
(name =&gt; value) from user input<br>
&nbsp;&nbsp;&nbsp; * @param array $partialAccounts list of hash arrays
(name =&gt; value) which are later added to LDAP<br>
&nbsp;&nbsp;&nbsp; * @param array $ids list of IDs for column position
(e.g. "posixAccount_uid" =&gt; 5)<br>
&nbsp;&nbsp;&nbsp; * @return array list of error messages if any<br>
&nbsp;&nbsp;&nbsp; */<br>
&nbsp;&nbsp;&nbsp; <span style="font-weight: bold;">function</span> <span
style="color: rgb(255, 0, 0);">build_uploadAccounts</span>($rawAccounts,
$ids, &amp;$partialAccounts) {<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; $messages = array();<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for ($i = 0; $i &lt;
sizeof($rawAccounts); $i++) {<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // add object
class<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if
(!in_array("ieee802Device", $partialAccounts[$i]['objectClass']))
$partialAccounts[$i]['objectClass'][] = "ieee802Device";<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // add MACs<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if
($rawAccounts[$i][$ids['ieee802Device_mac']] != "") {<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp; $macs = explode(',',
$rawAccounts[$i][$ids['ieee802Device_mac']]);<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp; // check format<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp; for ($m = 0; $m &lt; sizeof($macs); $m++) {<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (get_preg($macs[$m],
'macAddress')) {<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
$partialAccounts[$i]['macAddress'][] = $macs[$m];<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; else {<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; $errMsg =
$this-&gt;messages['mac'][1];<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
array_push($errMsg, array($i));<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; $messages[] =
$errMsg;<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return $messages;<br>
&nbsp;&nbsp;&nbsp; }<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>