Source for file dftk_ldap_entrie.php
Documentation is available at dftk_ldap_entrie.php
1 <?php 2 /* 3 4 Copyright (c)2003 DuckCorp(tm) and RtpNet(tm) 5 6 7 8 This file is part of DFTK. 9 10 DFTK is free software; you can redistribute it and/or modify 11 it under the terms of the GNU General Public License as published by 12 the Free Software Foundation; either version 2 of the License, or 13 (at your option) any later version. 14 15 DFTK is distributed in the hope that it will be useful, 16 but WITHOUT ANY WARRANTY; without even the implied warranty of 17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 GNU General Public License for more details. 19 20 You should have received a copy of the GNU General Public License 21 along with DFTK; if not, write to the Free Software 22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 23 */ 24 25 26 /** 27 * @package dftk 28 * @author Duck <duck@DuckCorp.org> 29 * @author Rtp <rtp@rtp-net.org> 30 * @copyright Copyright (c)2003 DuckCorp(tm) and RtpNet(tm) 31 * @license http://www.gnu.org/licenses/gpl.html GNU General Public License 32 * @version 0.4.0 33 */ 34 35 36 /** 37 * DFTK LDAP Entries Class 38 * 39 * @package dftk 40 * @subpackage dftk-ldap 41 * @author Duck <duck@DuckCorp.org> 42 * 43 * @access public 44 */ 45 class DftkLdapEntries extends DftkLdapBase 46 { 47 /** 48 * LDAP Result 49 * 50 * @access private 51 * @var array 52 */ 53 var $_tab; 54 /** 55 * Number of results 56 * 57 * @access private 58 * @var integer 59 */ 60 var $_nb; 61 /** 62 * DN for each result 63 * 64 * @access private 65 * @var array 66 */ 67 var $_dn; 68 69 /** 70 * Constructor 71 * 72 * @access public 73 * @param object DftkDaLanguageManager $tracemgr Language Manager 74 */ 75 function DftkLdapEntries(&$tracemgr) 76 { 77 DftkLdapBase::DftkLdapBase(&$tracemgr); 78 79 $this->clear(); 80 81 register_shutdown_function(array(&$this, "_DftkLdapEntries")); 82 } 83 84 /** 85 * Destructor 86 * 87 * @access private 88 */ 89 function _DftkLdapEntries() 90 { 91 } 92 93 /** 94 * Destroy results 95 * 96 * @access public 97 * @return object DftkDaTrace $r Trace 98 */ 99 function &clear() 100 { 101 $r =& $this->_tracemgr->create_trace(); 102 103 $this->_tab = array(); 104 $this->_nb = 0; 105 $this->_dn = array(); 106 107 return $r; 108 } 109 110 /** 111 * Put LDAP result into object 112 * 113 * @access private 114 * @param array $tab Array containing LDAP results 115 * @param integer $nb Number of LDAP results 116 */ 117 function _put_tab($tab, $nb) 118 { 119 $this->clear(); 120 $this->_tab = $tab; 121 $this->_nb = $nb; 122 $this->_process_entries_read(); 123 } 124 125 /** 126 * Export LDAP entries for writing into Database 127 * 128 * @access private 129 * @param integer $i Number of the entry wanted 130 * @param array $attr_list List of Attributs to export (all if empty) 131 * @return array $tab Array containing LDAP entry ready to be written 132 */ 133 function _export_entry($i, $attr_list = array()) 134 { 135 $tab = $this->_tab[$i]; 136 137 foreach ($tab as $key1 => $elem1) 138 { 139 if (is_integer($key1) || (count($attr_list)!=0 && !in_array($key1, $attr_list))) 140 { 141 unset($tab[$key1]); 142 } 143 else if (is_array($elem1)) 144 foreach ($elem1 as $key2 => $elem2) 145 { 146 if (is_string($elem2)) 147 $tab[$key1][$key2] = utf8_encode($elem2); 148 } 149 } 150 151 return $tab; 152 } 153 154 /** 155 * Give Nuber of entries 156 * 157 * @access public 158 * @return object DftkDaTrace $r Trace 159 */ 160 function &get_count() 161 { 162 $r =& $this->_tracemgr->create_trace(); 163 164 $r->set_result('count', $this->_nb); 165 166 return $r; 167 } 168 169 /** 170 * Give a reference on an array containing one particular entry 171 * 172 * @access public 173 * @param integer $i Number of the entry wanted 174 * @return object DftkDaTrace $r Trace 175 */ 176 function &get_entry($i) 177 { 178 $r =& $this->_tracemgr->create_trace(); 179 180 //return $this->_tab[$i]; 181 $r->set_result('entry', &$this->_tab[$i]); 182 183 return $r; 184 } 185 186 /** 187 * Give the DN of a particular result 188 * 189 * @access public 190 * @param integer $i Number of the entry wanted 191 * @return object DftkDaTrace $r Trace 192 */ 193 function &get_dn($i) 194 { 195 $r =& $this->_tracemgr->create_trace(); 196 197 $r->set_result('dn', $this->_dn[$i]); 198 199 return $r; 200 } 201 202 /** 203 * Set the DN of a particular result (for rename remembering purpose) 204 * 205 * @access public 206 * @param integer $i Number of the entry wanted 207 * @return object DftkDaTrace $r Trace 208 */ 209 function &set_dn($i, $new_dn) 210 { 211 $r =& $this->_tracemgr->create_trace(); 212 213 $this->_dn[$i] = $new_dn; 214 215 return $r; 216 } 217 218 /** 219 * Change one entry 220 * 221 * @access public 222 * @param integer $i Number of the entry to change 223 * @param array $entry Array containing the data of the entry to change 224 * @return object DftkDaTrace $r Trace 225 */ 226 function &set_entry($i, $entry) 227 { 228 $r =& $this->_tracemgr->create_trace(); 229 230 if (is_array($entry)) 231 $this->_tab[$i] = $entry; 232 else 233 $r->add_event('dftk-ldap_setentbade', $i); 234 235 return $r; 236 } 237 238 /** 239 * Sort entries using one or two attributs 240 * 241 * @access public 242 * @param string $attr1 Key for the first attribut 243 * @param string $attr2 Key for the second attribut or null if unused 244 * @return object DftkDaTrace $r Trace 245 */ 246 function &sort_entries_by_attr($attr1, $attr2 = null) 247 { 248 $r =& $this->_tracemgr->create_trace(); 249 250 $temp_sort1 = array(); 251 if ($attr2!=null) 252 $temp_sort2 = array(); 253 for ($i=0; $i<count($this->_tab); $i++) 254 { 255 $temp_sort1[$i] = $this->_tab[$i][$attr1][0]; 256 if ($attr2!=null) 257 $temp_sort2[$i] = $this->_tab[$i][$attr2][0]; 258 } 259 if ($attr2!=null) 260 array_multisort($temp_sort1, $temp_sort2, $this->_tab); 261 else 262 array_multisort($temp_sort1, $this->_tab); 263 264 return $r; 265 } 266 267 /** 268 * Process entries for use from LDAP 269 * 270 * @access private 271 */ 272 function _process_entries_read() 273 { 274 unset($this->_tab['count']); 275 foreach ($this->_tab as $key1 => $elem1) 276 { 277 unset($this->_tab[$key1]['count']); 278 $this->_dn[$key1] = $this->_tab[$key1]['dn']; 279 unset($this->_tab[$key1]['dn']); 280 foreach ($this->_tab[$key1] as $key2 => $elem2) 281 { 282 unset($this->_tab[$key1][$key2]['count']); 283 if (is_array($this->_tab[$key1][$key2])) 284 foreach ($this->_tab[$key1][$key2] as $key3 => $elem3) 285 { 286 if (is_string($elem3)) 287 $this->_tab[$key1][$key2][$key3] = utf8_decode($elem3); 288 } 289 } 290 } 291 } 292 293 /** 294 * Display Entries (for debugging purpose) 295 * 296 * @access public 297 * @return object DftkDaTrace $r Trace 298 */ 299 function &display_entries() 300 { 301 $r =& $this->_tracemgr->create_trace(); 302 303 $this->display_array($this->_tab); 304 305 return $r; 306 } 307 308 } 309 310 ?>
|