Changeset 522 in subversion
- Timestamp:
- Mar 27, 2007 10:06:49 AM (6 years ago)
- Location:
- branches/devel-addressbook/program
- Files:
-
- 4 edited
-
include/rcube_ldap.inc (modified) (14 diffs)
-
js/app.js (modified) (8 diffs)
-
js/editor.js (modified) (1 diff)
-
steps/addressbook/func.inc (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
branches/devel-addressbook/program/include/rcube_ldap.inc
r499 r522 24 24 var $conn; 25 25 var $prop = array(); 26 27 var $filter = '1'; 26 var $fieldmap = array(); 27 28 var $filter = ''; 29 var $idmap = array(); 28 30 var $result = null; 29 var $ search_fields;30 var $s earch_string;31 var $ldap_result = null; 32 var $sort_col = ''; 31 33 32 34 /** public properties */ … … 47 49 { 48 50 $this->prop = $p; 51 52 foreach ($p as $prop => $value) 53 if (preg_match('/^(.+)_field$/', $prop, $matches)) 54 $this->fieldmap[$matches[1]] = $value; 55 56 // $this->filter = "(dn=*)"; 49 57 $this->connect(); 50 58 } … … 55 63 * @see rcube_ldap::__construct 56 64 */ 57 function rcube_ contacts($p)65 function rcube_ldap($p) 58 66 { 59 67 $this->__construct($p); … … 67 75 { 68 76 if (!function_exists('ldap_connect')) 69 raise_error(array('type' => "ldap", 70 'message' => "No ldap support in this installation of PHP"), 71 true); 77 raise_error(array('type' => 'ldap', 'message' => "No ldap support in this installation of PHP"), true); 72 78 73 79 if (is_resource($this->conn)) … … 81 87 if ($lc = @ldap_connect($host, $this->prop['port'])) 82 88 { 83 @ldap_set_option($lc, LDAP_OPT_PROTOCOL_VERSION, $this->prop['port']);89 ldap_set_option($lc, LDAP_OPT_PROTOCOL_VERSION, $this->prop['port']); 84 90 $this->prop['host'] = $host; 85 91 $this->conn = $lc; … … 91 97 $this->ready = true; 92 98 else 93 raise_error(array('type' => "ldap", 94 'message' => "Could not connect to any LDAP server, tried $host:{$this->prop[port]} last"), 95 true); 96 } 99 raise_error(array('type' => 'ldap', 'message' => "Could not connect to any LDAP server, tried $host:{$this->prop[port]} last"), true); 100 } 101 102 103 /** 104 * Merge with connect()? 105 */ 106 function bind($dn=null, $pass=null) 107 { 108 if ($this->conn) 109 { 110 if ($dn) 111 { 112 if (@ldap_bind($this->conn, $dn, $pass)) 113 return true; 114 else 115 raise_error(array('code' => ldap_errno($this->conn), 116 'type' => 'ldap', 117 'message' => "Bind failed for dn=$dn: ".ldap_error($this->conn)), 118 true); 119 } 120 else 121 { 122 if (@ldap_bind($this->conn)) 123 return true; 124 else 125 raise_error(array('code' => ldap_errno($this->conn), 126 'type' => 'ldap', 127 'message' => "Anonymous bind failed: ".ldap_error($this->conn)), 128 true); 129 } 130 } 131 else 132 raise_error(array('type' => 'ldap', 'message' => "Attempted bind on nonexistent connection"), true); 133 134 return false; 135 } 97 136 98 137 … … 136 175 * @param string ?? 137 176 */ 138 function set_search_set($filter) 139 { 140 // TODO 177 function set_search_set($p) 178 { 179 $this->filter = $p['filter']; 180 $this->idmap = $p['ids']; 141 181 } 142 182 … … 149 189 function get_search_set() 150 190 { 151 // TODO191 return array('filter' => $this->filter, 'ids' => $this->idmap); 152 192 } 153 193 … … 158 198 function reset() 159 199 { 160 // TODO161 200 $this->result = null; 162 $this-> filter = '1';163 $this-> search_fields = null;164 $this-> search_string = null;201 $this->ldap_result = null; 202 $this->filter = ''; 203 $this->idmap = array(); 165 204 } 166 205 … … 174 213 function list_records($cols=null, $subset=0) 175 214 { 215 // exec LDAP search if no result resource is stored 216 if ($this->conn && !$this->ldap_result) 217 $this->_exec_search(); 218 176 219 // count contacts for this user 177 220 $this->result = $this->count(); 178 179 // TODO 221 222 // we have a search result resource 223 if ($this->ldap_result && $this->result->count > 0) 224 { 225 if ($this->sort_col && $this->prop['scope'] !== "base") 226 @ldap_sort($this->conn, $this->ldap_result, $this->sort_col); 227 228 $entries = ldap_get_entries($this->conn, $this->ldap_result); 229 for ($i = $this->result->first; $i < min($entries['count'], $this->result->first + $this->page_size); $i++) 230 $this->result->add($this->_ldap2result($entries[$i])); 231 } 180 232 181 233 return $this->result; … … 193 245 function search($fields, $value, $select=true) 194 246 { 195 // TODO 196 197 //$this->set_search_set(); 247 // special treatment for ID-based search 248 if ($fields == 'ID' || $fields == $this->primary_key) 249 { 250 $ids = explode(',', $value); 251 $this->result = new rcube_result_set(); 252 foreach ($ids as $id) 253 if ($rec = $this->get_record($id, true)) 254 { 255 $this->result->add($rec); 256 $this->result->count++; 257 } 258 259 return $this->result; 260 } 261 262 $filter = '(|'; 263 foreach ((array)$fields as $field) 264 if ($f = $this->_map_field($field)) 265 $filter .= "($f=*" . rcube_ldap::quote_string($value) . "*)"; 266 $filter .= ')'; 267 268 // set filter string and execute search 269 $this->filter = $filter; 270 $this->_exec_search(); 271 198 272 if ($select) 199 273 $this->list_records(); … … 213 287 { 214 288 $count = 0; 215 // TODO 216 return new rcube_result_set($count, ($this->list_page-1) * $this->page_size);; 289 if ($this->conn && $this->ldap_result) 290 $count = ldap_count_entries($this->conn, $this->ldap_result); 291 292 return new rcube_result_set($count, ($this->list_page-1) * $this->page_size); 217 293 } 218 294 … … 237 313 function get_record($id, $assoc=false) 238 314 { 239 // TODO 240 241 return $assoc && $sql_arr ? $sql_arr : $this->result; 315 $res = null; 316 if ($this->conn && ($dn = $this->idmap[$id])) 317 { 318 $this->ldap_result = @ldap_read($this->conn, $dn, "(objectclass=*)", array_values($this->fieldmap)); 319 $entry = @ldap_first_entry($this->conn, $this->ldap_result); 320 321 if ($entry && ($rec = ldap_get_attributes($this->conn, $entry))) 322 { 323 $res = $this->_ldap2result($rec); 324 $this->result = new rcube_result_set(1); 325 $this->result->add($res); 326 } 327 } 328 329 return $assoc && $res ? $res : $this->result; 242 330 } 243 331 … … 281 369 } 282 370 371 372 /** 373 * Execute the LDAP search based on the stored credentials 374 * 375 * @private 376 */ 377 function _exec_search() 378 { 379 if ($this->conn && $this->filter) 380 { 381 $limit = $this->page_size * $this->list_page; 382 $function = $this->prop['scope'] == 'sub' ? 'ldap_search' : ($this->prop['scope'] == 'base' ? 'ldap_read' : 'ldap_list'); 383 384 $this->ldap_result = @$function($this->conn, $this->prop['base_dn'], $this->filter, array_values($this->fieldmap), 0, $limit); 385 return true; 386 } 387 else 388 return false; 389 } 390 391 392 /** 393 * @private 394 */ 395 function _ldap2result($rec) 396 { 397 $out = array(); 398 $id = count($this->idmap) + 1; 399 400 if ($rec['dn']) 401 { 402 $dn_hash = $id++; // md5($rec['dn']); 403 $out[$this->primary_key] = $dn_hash; 404 $this->idmap[$dn_hash] = $rec['dn']; 405 } 406 407 foreach ($this->fieldmap as $rf => $lf) 408 { 409 if ($rec[$lf]['count']) 410 { 411 unset($rec[$lf]['count']); 412 $out[$rf] = join(' ', $rec[$lf]); 413 } 414 } 415 416 return $out; 417 } 418 419 420 /** 421 * @private 422 */ 423 function _map_field($field) 424 { 425 return $this->fieldmap[$field]; 426 } 427 428 429 /** 430 * @static 431 */ 432 function quote_string($str) 433 { 434 return strtr($str, array('*'=>'\2a', '('=>'\28', ')'=>'\29', '\\'=>'\5c')); 435 } 436 437 283 438 } 284 439 -
branches/devel-addressbook/program/js/app.js
r499 r522 1239 1239 } 1240 1240 1241 this.select_folder(mbox, this.env.mailbox); 1242 this.env.mailbox = mbox; 1243 1244 // load message list remotely 1245 if (this.gui_objects.messagelist) 1246 { 1247 this.list_mailbox_remote(mbox, page, add_url); 1248 return; 1249 } 1250 1251 if (this.env.contentframe && window.frames && window.frames[this.env.contentframe]) 1252 { 1253 target = window.frames[this.env.contentframe]; 1254 add_url += '&_framed=1'; 1255 } 1256 1241 1257 // also send search request to get the right messages 1242 1258 if (this.env.search_request) 1243 1259 add_url += '&_search='+this.env.search_request; 1244 1245 this.select_folder(mbox, this.env.mailbox);1246 this.env.mailbox = mbox;1247 1248 // load message list remotely1249 if (this.gui_objects.messagelist)1250 {1251 this.list_mailbox_remote(mbox, page, add_url);1252 return;1253 }1254 1255 if (this.env.contentframe && window.frames && window.frames[this.env.contentframe])1256 {1257 target = window.frames[this.env.contentframe];1258 add_url += '&_framed=1';1259 }1260 1260 1261 1261 // load message list to target frame/window … … 1420 1420 this.message_list.select_next(); 1421 1421 } 1422 1423 // also send search request to get the right messages1424 if (this.env.search_request)1425 add_url += '&_search='+this.env.search_request;1426 1422 1427 1423 // send request to server … … 2255 2251 this.env.source = src; 2256 2252 2257 // also send search request to get the correct listing2258 if (this.env.search_request)2259 url += '&_search='+this.env.search_request;2260 2261 2253 this.set_busy(true, 'loading'); 2262 2254 this.http_request('list', url, true); … … 2277 2269 else if (framed) 2278 2270 return false; 2271 2272 if (this.env.search_request) 2273 add_url += '&_search='+this.env.search_request; 2279 2274 2280 2275 if (action && (cid || action=='add') && !this.drag_active) … … 3167 3162 querystring += '&_ts='+(new Date().getTime()); 3168 3163 3164 // also send search request to get the right messages 3165 if (this.env.search_request) 3166 querystring += '&_search='+this.env.search_request; 3167 3169 3168 // send request 3170 3169 if (request_obj) 3171 3170 { 3172 console ('HTTP request: '+this.env.comm_path+'&_action='+action+'&'+querystring);3171 console.log('HTTP request: '+this.env.comm_path+'&_action='+action+'&'+querystring); 3173 3172 3174 3173 if (lock) … … 3193 3192 postdata += (postdata ? '&' : '') + '_remote=1'; 3194 3193 3194 if (this.env.search_request) 3195 postdata += '&_search='+this.env.search_request; 3196 3195 3197 // send request 3196 3198 if (request_obj = this.get_request_obj()) 3197 3199 { 3198 console ('HTTP POST: '+this.env.comm_path+'&_action='+action);3200 console.log('HTTP POST: '+this.env.comm_path+'&_action='+action); 3199 3201 3200 3202 if (lock) … … 3222 3224 this.set_busy(false); 3223 3225 3224 console(request_obj.get_text());3226 console.log(request_obj.get_text()); 3225 3227 3226 3228 // if we get javascript code from server -> execute it … … 3528 3530 } 3529 3531 3530 function console(str) 3532 3533 function rcube_console() 3534 { 3535 this.box = rcube_find_object('console'); 3536 3537 this.log = function(msg) 3531 3538 { 3532 if (document.debugform && document.debugform.console) 3533 document.debugform.console.value += str+'\n--------------------------------------\n'; 3534 } 3535 3539 if (this.box) 3540 this.box.value += str+'\n--------------------------------------\n'; 3541 }; 3542 3543 this.reset = function() 3544 { 3545 if (this.box) 3546 this.box.value = ''; 3547 }; 3548 } 3549 3550 if (!window.console) 3551 console = new rcube_console(); -
branches/devel-addressbook/program/js/editor.js
r458 r522 101 101 http_request.oncomplete = function(o) { rcmail_set_text_value(o); }; 102 102 var url = rcmail.env.bin_path+'html2text.php'; 103 console ('HTTP request: ' + url);103 console.log('HTTP request: ' + url); 104 104 http_request.POST(url, htmlText, 'application/octet-stream'); 105 105 } -
branches/devel-addressbook/program/steps/addressbook/func.inc
r499 r522 41 41 42 42 // set message set for search result 43 if (!empty($_ GET['_search']) && isset($_SESSION['search'][$_GET['_search']]))44 $CONTACTS->set_search_set($_SESSION['search'][$_ GET['_search']]);43 if (!empty($_REQUEST['_search']) && isset($_SESSION['search'][$_REQUEST['_search']])) 44 $CONTACTS->set_search_set($_SESSION['search'][$_REQUEST['_search']]); 45 45 46 46 // set data source env
Note: See TracChangeset
for help on using the changeset viewer.
