| 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 | * Returns meta data that is interpreted by parent |
| 31 | class<br> |
| 32 | *<br> |
| 33 | * @return array array with meta data<br> |
| 34 | */<br> |
| 35 | <span style="font-weight: bold;">function</span> |
| 36 | get_metaData() {<br> |
| 37 | $return = array();<br> |
| 38 | // manages host accounts<br> |
| 39 | |
| 40 | $return["account_types"] = array("host");<br> |
| 41 | // upload fields<br> |
| 42 | <span style="color: rgb(255, 0, 0);"> |
| 43 | $return['upload_columns'] = array(</span><br style="color: rgb(255, 0, 0);"> |
| 44 | <span style="color: rgb(255, 0, 0);"> |
| 45 | array(</span><br style="color: rgb(255, 0, 0);"> |
| 46 | <span style="color: rgb(255, 0, 0);"> |
| 47 | 'name' => |
| 48 | 'ieee802Device_mac',</span><br style="color: rgb(255, 0, 0);"> |
| 49 | <span style="color: rgb(255, 0, 0);"> |
| 50 | 'description' |
| 51 | => _('MAC address'),</span><br style="color: rgb(255, 0, 0);"> |
| 52 | <span style="color: rgb(255, 0, 0);"> |
| 53 | 'help' => |
| 54 | 'mac',</span><br style="color: rgb(255, 0, 0);"> |
| 55 | <span style="color: rgb(255, 0, 0);"> |
| 56 | 'example' |
| 57 | => '00:01:02:DE:EF:18'</span><br style="color: rgb(255, 0, 0);"> |
| 58 | <span style="color: rgb(255, 0, 0);"> |
| 59 | )</span><br style="color: rgb(255, 0, 0);"> |
| 60 | <span style="color: rgb(255, 0, 0);"> |
| 61 | );</span><br> |
| 62 | return $return;<br> |
| 63 | }<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 | * In this function the LDAP account is built up.<br> |
| 85 | *<br> |
| 86 | * @param array $rawAccounts list of hash arrays |
| 87 | (name => value) from user input<br> |
| 88 | * @param array $partialAccounts list of hash arrays |
| 89 | (name => value) which are later added to LDAP<br> |
| 90 | * @param array $ids list of IDs for column position |
| 91 | (e.g. "posixAccount_uid" => 5)<br> * @param array $selectedModules list of selected account modules<br> |
| 92 | * @return array list of error messages if any<br> |
| 93 | */<br> |
| 94 | <span style="font-weight: bold;">function</span> <span style="color: rgb(255, 0, 0);">build_uploadAccounts</span>($rawAccounts, |
| 95 | $ids, &$partialAccounts, $selectedModules) {<br> |
| 96 | $messages = array();<br> |
| 97 | for ($i = 0; $i < |
| 98 | sizeof($rawAccounts); $i++) {<br> |
| 99 | // add object |
| 100 | class<br> |
| 101 | if |
| 102 | (!in_array("ieee802Device", $partialAccounts[$i]['objectClass'])) |
| 103 | $partialAccounts[$i]['objectClass'][] = "ieee802Device";<br> |
| 104 | // add MACs<br> |
| 105 | if |
| 106 | ($rawAccounts[$i][$ids['ieee802Device_mac']] != "") {<br> |
| 107 | |
| 108 | $macs = explode(',', |
| 109 | $rawAccounts[$i][$ids['ieee802Device_mac']]);<br> |
| 110 | |
| 111 | // check format<br> |
| 112 | |
| 113 | for ($m = 0; $m < sizeof($macs); $m++) {<br> |
| 114 | |
| 115 | if (get_preg($macs[$m], |
| 116 | 'macAddress')) {<br> |
| 117 | |
| 118 | |
| 119 | $partialAccounts[$i]['macAddress'][] = $macs[$m];<br> |
| 120 | |
| 121 | }<br> |
| 122 | |
| 123 | else {<br> |
| 124 | |
| 125 | $errMsg = |
| 126 | $this->messages['mac'][1];<br> |
| 127 | |
| 128 | |
| 129 | array_push($errMsg, array($i));<br> |
| 130 | |
| 131 | $messages[] = |
| 132 | $errMsg;<br> |
| 133 | |
| 134 | }<br> |
| 135 | |
| 136 | }<br> |
| 137 | }<br> |
| 138 | }<br> |
| 139 | return $messages;<br> |
| 140 | }<br> |
| 141 | </div> |
| 142 | <br> |
| 143 | <br> |
| 144 | <br> |
| 145 | <br> |
| 146 | </div> |
| 147 | </div> |
| 148 | </body></html> |