172 lines
		
	
	
		
			7.2 KiB
		
	
	
	
		
			HTML
		
	
	
	
		
		
			
		
	
	
			172 lines
		
	
	
		
			7.2 KiB
		
	
	
	
		
			HTML
		
	
	
	
|  | <!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;">    /**<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> | ||
|  |         // manages host accounts<br> | ||
|  |     | ||
|  |     $return["account_types"] = array("host");<br> | ||
|  |         // upload fields<br> | ||
|  |       <span style="color: rgb(255, 0, 0);">    | ||
|  |     $return['upload_columns'] = array(</span><br | ||
|  |  style="color: rgb(255, 0, 0);"> | ||
|  |       <span style="color: rgb(255, 0, 0);">    | ||
|  |         array(</span><br | ||
|  |  style="color: rgb(255, 0, 0);"> | ||
|  |       <span style="color: rgb(255, 0, 0);">    | ||
|  |             'name' => | ||
|  | 'ieee802Device_mac',</span><br style="color: rgb(255, 0, 0);"> | ||
|  |       <span style="color: rgb(255, 0, 0);">    | ||
|  |             'description' | ||
|  | => _('MAC address'),</span><br style="color: rgb(255, 0, 0);"> | ||
|  |       <span style="color: rgb(255, 0, 0);">    | ||
|  |             'help' => | ||
|  | 'mac',</span><br style="color: rgb(255, 0, 0);"> | ||
|  |       <span style="color: rgb(255, 0, 0);">    | ||
|  |             'example' | ||
|  | => '00:01:02:DE:EF:18'</span><br style="color: rgb(255, 0, 0);"> | ||
|  |       <span style="color: rgb(255, 0, 0);">    | ||
|  |         )</span><br | ||
|  |  style="color: rgb(255, 0, 0);"> | ||
|  |       <span style="color: rgb(255, 0, 0);">     | ||
|  |    );</span><br> | ||
|  |         return $return;<br> | ||
|  |     }<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;">    /**<br> | ||
|  |     * In this function the LDAP account is built up.<br> | ||
|  |     *<br> | ||
|  |     * @param array $rawAccounts list of hash arrays | ||
|  | (name => value) from user input<br> | ||
|  |     * @param array $partialAccounts list of hash arrays | ||
|  | (name => value) which are later added to LDAP<br> | ||
|  |     * @param array $ids list of IDs for column position | ||
|  | (e.g. "posixAccount_uid" => 5)<br> | ||
|  |     * @return array list of error messages if any<br> | ||
|  |     */<br> | ||
|  |     <span style="font-weight: bold;">function</span> <span | ||
|  |  style="color: rgb(255, 0, 0);">build_uploadAccounts</span>($rawAccounts, | ||
|  | $ids, &$partialAccounts) {<br> | ||
|  |         $messages = array();<br> | ||
|  |         for ($i = 0; $i < | ||
|  | sizeof($rawAccounts); $i++) {<br> | ||
|  |             // add object | ||
|  | class<br> | ||
|  |             if | ||
|  | (!in_array("ieee802Device", $partialAccounts[$i]['objectClass'])) | ||
|  | $partialAccounts[$i]['objectClass'][] = "ieee802Device";<br> | ||
|  |             // add MACs<br> | ||
|  |             if | ||
|  | ($rawAccounts[$i][$ids['ieee802Device_mac']] != "") {<br> | ||
|  |             | ||
|  |     $macs = explode(',', | ||
|  | $rawAccounts[$i][$ids['ieee802Device_mac']]);<br> | ||
|  |             | ||
|  |     // check format<br> | ||
|  |             | ||
|  |     for ($m = 0; $m < sizeof($macs); $m++) {<br> | ||
|  |             | ||
|  |         if (get_preg($macs[$m], | ||
|  | 'macAddress')) {<br> | ||
|  |             | ||
|  |             | ||
|  | $partialAccounts[$i]['macAddress'][] = $macs[$m];<br> | ||
|  |             | ||
|  |         }<br> | ||
|  |             | ||
|  |         else {<br> | ||
|  |             | ||
|  |             $errMsg = | ||
|  | $this->messages['mac'][1];<br> | ||
|  |             | ||
|  |             | ||
|  | array_push($errMsg, array($i));<br> | ||
|  |             | ||
|  |             $messages[] = | ||
|  | $errMsg;<br> | ||
|  |             | ||
|  |         }<br> | ||
|  |             | ||
|  |     }<br> | ||
|  |             }<br> | ||
|  |         }<br> | ||
|  |         return $messages;<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> |