Debian Codegraph @

docs/devel/mod_upload.htm

raw symbols SCIP
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2 <html lang="en"><head><title>Module HowTo - File upload</title>
3
4
5
6 <link rel="stylesheet" type="text/css" href="style/layout.css">
7 <link rel="shortcut icon" type="image/x-icon" href="images/favicon.ico"></head><body>
8 <div style="text-align: center;">
9 <h1>Module HowTo - File upload<br>
10 </h1>
11 <br>
12 <br>
13 <div style="text-align: left;"><br>
14 <h2>1. Defining upload columns<br>
15 </h2>
16 If you want to support account creation via file upload you have to
17 define columns in the CSV file.<br>
18 Each column has an non-translated identifier, a description, help entry
19 and several other values.<br>
20 <br>
21 The upload columns are specified with <span style="font-weight: bold;">get_uploadColumns()</span>
22 or <span style="font-weight: bold;">meta['upload_columns']</span>.<br>
23 <br>
24 <span style="font-weight: bold; text-decoration: underline;">Example:</span><br style="font-weight: bold; text-decoration: underline;">
25 <br>
26 The <span style="font-style: italic;">ieee802Device</span>
27 module has only one attribute and therefore one column: the MAC address.<br>
28 <br>
29 <div class="mod-code">
30 &nbsp;&nbsp;&nbsp; * Returns meta data that is interpreted by parent
31 class<br>
32 &nbsp;&nbsp;&nbsp; *<br>
33 &nbsp;&nbsp;&nbsp; * @return array array with meta data<br>
34 &nbsp;&nbsp;&nbsp; */<br>
35 &nbsp;&nbsp;&nbsp; <span style="font-weight: bold;">function</span>
36 get_metaData() {<br>
37 &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; $return = array();<br>
38 &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // manages host accounts<br>
39 &nbsp;&nbsp;&nbsp;
40 &nbsp;&nbsp;&nbsp; $return["account_types"] = array("host");<br>
41 &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // upload fields<br>
42 <span style="color: rgb(255, 0, 0);">&nbsp;&nbsp;&nbsp;
43 &nbsp;&nbsp;&nbsp; $return['upload_columns'] = array(</span><br style="color: rgb(255, 0, 0);">
44 <span style="color: rgb(255, 0, 0);">&nbsp;&nbsp;&nbsp;
45 &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;array(</span><br style="color: rgb(255, 0, 0);">
46 <span style="color: rgb(255, 0, 0);">&nbsp;&nbsp;&nbsp;
47 &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;'name' =&gt;
48 'ieee802Device_mac',</span><br style="color: rgb(255, 0, 0);">
49 <span style="color: rgb(255, 0, 0);">&nbsp;&nbsp;&nbsp;
50 &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;'description'
51 =&gt; _('MAC address'),</span><br style="color: rgb(255, 0, 0);">
52 <span style="color: rgb(255, 0, 0);">&nbsp;&nbsp;&nbsp;
53 &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;'help' =&gt;
54 'mac',</span><br style="color: rgb(255, 0, 0);">
55 <span style="color: rgb(255, 0, 0);">&nbsp;&nbsp;&nbsp;
56 &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;'example'
57 =&gt; '00:01:02:DE:EF:18'</span><br style="color: rgb(255, 0, 0);">
58 <span style="color: rgb(255, 0, 0);">&nbsp;&nbsp;&nbsp;
59 &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; )</span><br style="color: rgb(255, 0, 0);">
60 <span style="color: rgb(255, 0, 0);">&nbsp;&nbsp; &nbsp;
61 &nbsp;&nbsp; );</span><br>
62 &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return $return;<br>
63 &nbsp;&nbsp;&nbsp; }<br>
64 </div>
65 <br>
66 <br>
67 <h2>2. Building the accounts<br>
68 </h2>
69 When the user has uploaded the CSV file the modules have to transform
70 the input data to LDAP accounts.<br>
71 <br>
72 This is done with <span style="font-weight: bold;">build_uploadAccounts()</span>.
73 The function gets the input data and a list of LDAP accounts as
74 parameter.<br>
75 <br>
76 <span style="font-weight: bold; text-decoration: underline;">Example:</span><br style="font-weight: bold; text-decoration: underline;">
77 <br>
78 The <span style="font-style: italic;">ieee802Device</span>
79 module has only one LDAP attribute - <span style="font-style: italic;">'macAddress'</span>
80 - and the <span style="font-style: italic;">'ieee802Device'</span>
81 objectClass which is added to all accounts.<br>
82 <br>
83 <div class="mod-code">
84 &nbsp;&nbsp;&nbsp; * In this function the LDAP account is built up.<br>
85 &nbsp;&nbsp;&nbsp; *<br>
86 &nbsp;&nbsp;&nbsp; * @param array $rawAccounts list of hash arrays
87 (name =&gt; value) from user input<br>
88 &nbsp;&nbsp;&nbsp; * @param array $partialAccounts list of hash arrays
89 (name =&gt; value) which are later added to LDAP<br>
90 &nbsp;&nbsp;&nbsp; * @param array $ids list of IDs for column position
91 (e.g. "posixAccount_uid" =&gt; 5)<br>&nbsp; &nbsp; * @param array $selectedModules list of selected account modules<br>
92 &nbsp;&nbsp;&nbsp; * @return array list of error messages if any<br>
93 &nbsp;&nbsp;&nbsp; */<br>
94 &nbsp;&nbsp;&nbsp; <span style="font-weight: bold;">function</span> <span style="color: rgb(255, 0, 0);">build_uploadAccounts</span>($rawAccounts,
95 $ids, &amp;$partialAccounts, $selectedModules) {<br>
96 &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; $messages = array();<br>
97 &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for ($i = 0; $i &lt;
98 sizeof($rawAccounts); $i++) {<br>
99 &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // add object
100 class<br>
101 &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if
102 (!in_array("ieee802Device", $partialAccounts[$i]['objectClass']))
103 $partialAccounts[$i]['objectClass'][] = "ieee802Device";<br>
104 &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // add MACs<br>
105 &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if
106 ($rawAccounts[$i][$ids['ieee802Device_mac']] != "") {<br>
107 &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
108 &nbsp;&nbsp;&nbsp; $macs = explode(',',
109 $rawAccounts[$i][$ids['ieee802Device_mac']]);<br>
110 &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
111 &nbsp;&nbsp;&nbsp; // check format<br>
112 &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
113 &nbsp;&nbsp;&nbsp; for ($m = 0; $m &lt; sizeof($macs); $m++) {<br>
114 &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
115 &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (get_preg($macs[$m],
116 'macAddress')) {<br>
117 &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
118 &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
119 $partialAccounts[$i]['macAddress'][] = $macs[$m];<br>
120 &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
121 &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>
122 &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
123 &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; else {<br>
124 &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
125 &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; $errMsg =
126 $this-&gt;messages['mac'][1];<br>
127 &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
128 &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
129 array_push($errMsg, array($i));<br>
130 &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
131 &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; $messages[] =
132 $errMsg;<br>
133 &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
134 &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>
135 &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
136 &nbsp;&nbsp;&nbsp; }<br>
137 &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>
138 &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>
139 &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return $messages;<br>
140 &nbsp;&nbsp;&nbsp; }<br>
141 </div>
142 <br>
143 <br>
144 <br>
145 <br>
146 </div>
147 </div>
148 </body></html>