Changeset c0297f4 in github
- Timestamp:
- Mar 31, 2010 11:23:22 AM (3 years ago)
- Branches:
- master, HEAD, courier-fix, dev-browser-capabilities, pdo, release-0.6, release-0.7, release-0.8
- Children:
- 64d855c
- Parents:
- 3baa72a
- Files:
-
- 6 edited
-
index.php (modified) (1 diff)
-
program/include/rcmail.php (modified) (2 diffs)
-
program/include/rcube_contacts.php (modified) (10 diffs)
-
program/include/rcube_mdb2.php (modified) (3 diffs)
-
program/js/app.js (modified) (2 diffs)
-
program/steps/mail/autocomplete.inc (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
index.php
r3baa72a rc0297f4 214 214 'display-attachment' => 'attachments.inc', 215 215 'upload' => 'attachments.inc', 216 'group-expand' => 'autocomplete.inc', 216 217 ), 217 218 -
program/include/rcmail.php
r59c216f rc0297f4 299 299 // We are using the DB address book 300 300 if ($abook_type != 'ldap') { 301 $contacts = new rcube_contacts($this->db, null); 301 302 $list['0'] = array( 302 303 'id' => 0, 303 304 'name' => rcube_label('personaladrbook'), 304 'groups' => true,305 'groups' => $contacts->groups, 305 306 'readonly' => false, 306 307 'autocomplete' => in_array('sql', $autocomplete) … … 325 326 foreach ($list as $idx => $item) { 326 327 if ($item['readonly']) { 327 unset($list[$idx]);328 unset($list[$idx]); 328 329 } 329 330 } -
program/include/rcube_contacts.php
r3baa72a rc0297f4 40 40 var $primary_key = 'contact_id'; 41 41 var $readonly = false; 42 var $groups = true;42 var $groups = false; 43 43 var $list_page = 1; 44 44 var $page_size = 10; … … 59 59 $this->user_id = $user; 60 60 $this->ready = $this->db && !$this->db->is_error(); 61 62 if (in_array('contactgroups', $this->db->list_tables())) 63 $this->groups = true; 61 64 } 62 65 … … 114 117 { 115 118 $results = array(); 119 120 if (!$this->groups) 121 return $results; 122 116 123 $sql_filter = $search ? "AND " . $this->db->ilike('name', '%'.$search.'%') : ''; 117 124 … … 135 142 * List the current set of contact records 136 143 * 137 * @param array List of cols to show 138 * @param int Only return this number of records, use negative values for tail 144 * @param array List of cols to show 145 * @param int Only return this number of records, use negative values for tail 146 * @param boolean True to skip the count query (select only) 139 147 * @return array Indexed list of contact records, each a hash array 140 148 */ 141 function list_records($cols=null, $subset=0 )149 function list_records($cols=null, $subset=0, $nocount=false) 142 150 { 143 151 // count contacts for this user 144 $this->result = $ this->count();152 $this->result = $nocount ? new rcube_result_set(1) : $this->count(); 145 153 $sql_result = NULL; 146 154 … … 149 157 { 150 158 if ($this->group_id) 151 $join = "LEFT JOIN ".get_table_name('contactgroupmembers')." AS rcmgrouplinks".152 " ON ( rcmgrouplinks.contact_id=rcmcontacts.".$this->primary_key.")";159 $join = "LEFT JOIN ".get_table_name('contactgroupmembers')." AS m". 160 " ON (m.contact_id=c.".$this->primary_key.")"; 153 161 154 162 $start_row = $subset < 0 ? $this->result->first + $this->page_size + $subset : $this->result->first; … … 156 164 157 165 $sql_result = $this->db->limitquery( 158 "SELECT * FROM ".$this->db_name." AS rcmcontacts".$join."159 WHERE rcmcontacts.del<>1160 AND rcmcontacts.user_id=?" .161 ($this->group_id ? " AND rcmgrouplinks.contactgroup_id=?" : "").166 "SELECT * FROM ".$this->db_name." AS c ".$join." 167 WHERE c.del<>1 168 AND c.user_id=?" . 169 ($this->group_id ? " AND m.contactgroup_id=?" : ""). 162 170 ($this->filter ? " AND (".$this->filter.")" : "") . 163 " ORDER BY rcmcontacts.name",171 " ORDER BY c.name", 164 172 $start_row, 165 173 $length, … … 177 185 } 178 186 187 if ($nocount) 188 $this->result->count = count($this->result->records); 189 179 190 return $this->result; 180 191 } … … 188 199 * @param boolean True for strict (=), False for partial (LIKE) matching 189 200 * @param boolean True if results are requested, False if count only 201 * @param boolean True to skip the count query (select only) 190 202 * @return Indexed list of contact records and 'count' value 191 203 */ 192 function search($fields, $value, $strict=false, $select=true )204 function search($fields, $value, $strict=false, $select=true, $nocount=false) 193 205 { 194 206 if (!is_array($fields)) … … 213 225 $this->set_search_set(join(' OR ', $add_where)); 214 226 if ($select) 215 $this->list_records( );227 $this->list_records(null, 0, $nocount); 216 228 else 217 229 $this->result = $this->count(); … … 230 242 { 231 243 if ($this->group_id) 232 $join = "LEFT JOIN ".get_table_name('contactgroupmembers')." AS rcmgrouplinks".233 " ON ( rcmgrouplinks.contact_id=rcmcontacts.".$this->primary_key.")";244 $join = "LEFT JOIN ".get_table_name('contactgroupmembers')." AS m". 245 " ON (m.contact_id=c.".$this->primary_key.")"; 234 246 235 247 // count contacts for this user 236 248 $sql_result = $this->db->query( 237 "SELECT COUNT( rcmcontacts.contact_id) AS rows238 FROM ".$this->db_name." AS rcmcontacts".$join."239 WHERE rcmcontacts.del<>1240 AND rcmcontacts.user_id=?".241 ($this->group_id ? " AND rcmgrouplinks.contactgroup_id=?" : "").249 "SELECT COUNT(c.contact_id) AS rows 250 FROM ".$this->db_name." AS c ".$join." 251 WHERE c.del<>1 252 AND c.user_id=?". 253 ($this->group_id ? " AND m.contactgroup_id=?" : ""). 242 254 ($this->filter ? " AND (".$this->filter.")" : ""), 243 255 $this->user_id, -
program/include/rcube_mdb2.php
re1ac217 rc0297f4 36 36 class rcube_mdb2 37 37 { 38 private static $tables; 39 38 40 var $db_dsnw; // DSN for write operations 39 41 var $db_dsnr; // DSN for read operations … … 268 270 269 271 raise_error(array('code' => 500, 'type' => 'db', 270 'line' => __LINE__, 'file' => __FILE__,272 'line' => __LINE__, 'file' => __FILE__, 271 273 'message' => $this->db_error_msg), TRUE, TRUE); 272 274 } … … 392 394 return $result->fetchRow($mode); 393 395 } 396 397 398 /** 399 * Wrapper for the SHOW TABLES command 400 * 401 * @return array List of all tables of the current database 402 */ 403 function list_tables() 404 { 405 // get tables if not cached 406 if (!self::$tables) { 407 self::$tables = array(); 408 409 switch ($this->db_provider) { 410 case 'sqlite': 411 $result = $this->db_handle->query("SELECT name FROM sqlite_master WHERE type='table'"); 412 break; 413 default: 414 $result = $this->db_handle->query("SHOW TABLES"); 415 } 416 417 if ($result !== false && !PEAR::isError($result)) 418 while ($rec = $result->fetchRow(MDB2_FETCHMODE_ORDERED)) 419 self::$tables[] = $rec[0]; 420 } 421 422 return self::$tables; 423 } 394 424 395 425 -
program/js/app.js
r3baa72a rc0297f4 3239 3239 3240 3240 // insert all members of a group 3241 if (typeof this.env.contacts[id] == 'object' && this.env.contacts[id].members) { 3242 for (var i=0; i < this.env.contacts[id].members.length; i++) 3243 insert += this.env.contacts[id].members[i] + ', '; 3241 if (typeof this.env.contacts[id] == 'object' && this.env.contacts[id].id) { 3242 insert += this.env.contacts[id].name + ', '; 3243 this.group2expand = $.extend({}, this.env.contacts[id]); 3244 this.group2expand.input = this.ksearch_input; 3245 this.http_request('group-expand', '_source='+urlencode(this.env.contacts[id].source)+'&_gid='+urlencode(this.env.contacts[id].id), false); 3244 3246 } 3245 3247 else if (typeof this.env.contacts[id] == 'string') … … 3252 3254 if (this.ksearch_input.setSelectionRange) 3253 3255 this.ksearch_input.setSelectionRange(cpos, cpos); 3256 }; 3257 3258 this.replace_group_recipients = function(id, recipients) 3259 { 3260 if (this.group2expand && this.group2expand.id == id) { 3261 this.group2expand.input.value = this.group2expand.input.value.replace(this.group2expand.name, recipients); 3262 this.group2expand = null; 3263 } 3254 3264 }; 3255 3265 -
program/steps/mail/autocomplete.inc
ra61bbb2 rc0297f4 21 21 22 22 $MAXNUM = 15; 23 $contacts = array();24 23 $book_types = (array) $RCMAIL->config->get('autocomplete_addressbooks', 'sql'); 25 24 26 if ($book_types && $search = get_input_value('_search', RCUBE_INPUT_GPC, true)) { 25 if ($RCMAIL->action == 'group-expand') { 26 $abook = $RCMAIL->get_address_book(get_input_value('_source', RCUBE_INPUT_GPC)); 27 if ($gid = get_input_value('_gid', RCUBE_INPUT_GPC)) { 28 $members = array(); 29 $abook->set_pagesize(1000); // TODO: limit number of group members by config 30 $result = $abook->list_records(array('email','name')); 31 while ($result && ($sql_arr = $result->iterate())) 32 $members[] = format_email_recipient($sql_arr['email'], $sql_arr['name']); 33 34 $OUTPUT->command('replace_group_recipients', $gid, join(', ', $members)); 35 } 36 } 37 else if ($book_types && $search = get_input_value('_search', RCUBE_INPUT_GPC, true)) { 38 $contacts = array(); 27 39 28 40 foreach ($book_types as $id) { … … 30 42 $abook->set_pagesize($MAXNUM); 31 43 32 if ($result = $abook->search(array('email','name'), $search )) {44 if ($result = $abook->search(array('email','name'), $search, false, true, true)) { 33 45 while ($sql_arr = $result->iterate()) { 34 46 $contacts[] = format_email_recipient($sql_arr['email'], $sql_arr['name']); … … 41 53 if ($abook->groups) { 42 54 foreach ($abook->list_groups($search) as $group) { 43 $members = array();44 55 $abook->reset(); 45 56 $abook->set_group($group['ID']); 46 $result = $abook->list_records(array('email','name')); 47 while ($result && ($sql_arr = $result->iterate())) 48 $members[] = format_email_recipient($sql_arr['email'], $sql_arr['name']); 57 $result = $abook->count(); 49 58 50 if ( count($members)) {51 $contacts[] = array('name' => $group['name'] . ' (' . rcube_label('group') . ')', 'members' => $members);59 if ($result->count) { 60 $contacts[] = array('name' => $group['name'] . ' (' . intval($result->count) . ')', 'id' => $group['ID'], 'source' => $id); 52 61 if (count($contacts) >= $MAXNUM) 53 62 break;
Note: See TracChangeset
for help on using the changeset viewer.
