| 
									
										
										
										
											2004-11-01 13:56:54 +00:00
										 |  |  | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> | 
					
						
							| 
									
										
										
										
											2010-10-24 13:52:51 +00:00
										 |  |  | <html><head><title>Module HowTo - File upload</title> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |    | 
					
						
							| 
									
										
										
										
											2004-11-01 13:56:54 +00:00
										 |  |  |   <link rel="stylesheet" type="text/css" href="style/layout.css"> | 
					
						
							| 
									
										
										
										
											2010-10-24 13:52:51 +00:00
										 |  |  | 	<link rel="shortcut icon" type="image/x-icon" href="images/favicon.ico"></head><body> | 
					
						
							| 
									
										
										
										
											2004-11-01 13:56:54 +00:00
										 |  |  | <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> | 
					
						
							| 
									
										
										
										
											2010-10-24 13:52:51 +00:00
										 |  |  | <span style="font-weight: bold; text-decoration: underline;">Example:</span><br style="font-weight: bold; text-decoration: underline;"> | 
					
						
							| 
									
										
										
										
											2004-11-01 13:56:54 +00:00
										 |  |  | <br> | 
					
						
							|  |  |  | The <span style="font-style: italic;">ieee802Device</span> | 
					
						
							|  |  |  | module has only one attribute and therefore one column: the MAC address.<br> | 
					
						
							|  |  |  | <br> | 
					
						
							| 
									
										
										
										
											2010-10-24 13:52:51 +00:00
										 |  |  | <table style="width: 100%; text-align: left;" class="mod-code" border="0" cellpadding="2" cellspacing="2"> | 
					
						
							| 
									
										
										
										
											2004-11-01 13:56:54 +00:00
										 |  |  |   <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);">    | 
					
						
							| 
									
										
										
										
											2010-10-24 13:52:51 +00:00
										 |  |  |     $return['upload_columns'] = array(</span><br style="color: rgb(255, 0, 0);"> | 
					
						
							| 
									
										
										
										
											2004-11-01 13:56:54 +00:00
										 |  |  |       <span style="color: rgb(255, 0, 0);">    | 
					
						
							| 
									
										
										
										
											2010-10-24 13:52:51 +00:00
										 |  |  |         array(</span><br style="color: rgb(255, 0, 0);"> | 
					
						
							| 
									
										
										
										
											2004-11-01 13:56:54 +00:00
										 |  |  |       <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);">    | 
					
						
							| 
									
										
										
										
											2010-10-24 13:52:51 +00:00
										 |  |  |         )</span><br style="color: rgb(255, 0, 0);"> | 
					
						
							| 
									
										
										
										
											2004-11-01 13:56:54 +00:00
										 |  |  |       <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> | 
					
						
							| 
									
										
										
										
											2010-10-24 13:52:51 +00:00
										 |  |  | <span style="font-weight: bold; text-decoration: underline;">Example:</span><br style="font-weight: bold; text-decoration: underline;"> | 
					
						
							| 
									
										
										
										
											2004-11-01 13:56:54 +00:00
										 |  |  | <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> | 
					
						
							| 
									
										
										
										
											2010-10-24 13:52:51 +00:00
										 |  |  | <table style="width: 100%; text-align: left;" class="mod-code" border="0" cellpadding="2" cellspacing="2"> | 
					
						
							| 
									
										
										
										
											2004-11-01 13:56:54 +00:00
										 |  |  |   <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 | 
					
						
							| 
									
										
										
										
											2010-10-24 13:52:51 +00:00
										 |  |  | (e.g. "posixAccount_uid" => 5)<br>    * @param array $selectedModules list of selected account modules<br> | 
					
						
							| 
									
										
										
										
											2004-11-01 13:56:54 +00:00
										 |  |  |     * @return array list of error messages if any<br> | 
					
						
							|  |  |  |     */<br> | 
					
						
							| 
									
										
										
										
											2010-10-24 13:52:51 +00:00
										 |  |  |     <span style="font-weight: bold;">function</span> <span style="color: rgb(255, 0, 0);">build_uploadAccounts</span>($rawAccounts, | 
					
						
							| 
									
										
										
										
											2010-02-15 20:21:44 +00:00
										 |  |  | $ids, &$partialAccounts, $selectedModules) {<br> | 
					
						
							| 
									
										
										
										
											2004-11-01 13:56:54 +00:00
										 |  |  |         $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> | 
					
						
							| 
									
										
										
										
											2010-10-24 13:52:51 +00:00
										 |  |  | </body></html> |