| | |
| | | $abook->set_group($gid); |
| | | $abook->set_pagesize(1000); // TODO: limit number of group members by config |
| | | $result = $abook->list_records(array('email','name')); |
| | | while ($result && ($sql_arr = $result->iterate())) |
| | | $members[] = format_email_recipient($sql_arr['email'], $sql_arr['name']); |
| | | while ($result && ($sql_arr = $result->iterate())) { |
| | | foreach ((array)$sql_arr['email'] as $email) |
| | | $members[] = format_email_recipient($email, $sql_arr['name']); |
| | | } |
| | | |
| | | $OUTPUT->command('replace_group_recipients', $gid, join(', ', $members)); |
| | | } |
| | |
| | | |
| | | if ($result = $abook->search(array('email','name'), $search, false, true, true, 'email')) { |
| | | while ($sql_arr = $result->iterate()) { |
| | | $contact = format_email_recipient($sql_arr['email'], $sql_arr['name']); |
| | | // when we've got more than one book, we need to skip duplicates |
| | | if ($books_num == 1 || !in_array($contact, $contacts)) { |
| | | $contacts[] = $contact; |
| | | if (count($contacts) >= $MAXNUM) |
| | | break 2; |
| | | // Contact can have more than one e-mail address |
| | | $email_arr = (array)$abook->get_col_values('email', $sql_arr, true); |
| | | $email_cnt = count($email_arr); |
| | | foreach ($email_arr as $email) { |
| | | if (empty($email)) |
| | | continue; |
| | | $contact = format_email_recipient($email, $sql_arr['name']); |
| | | // skip entries that don't match |
| | | if ($email_cnt > 1 && stripos($contact, $search) === false) { |
| | | continue; |
| | | } |
| | | // when we've got more than one book, we need to skip duplicates |
| | | if ($books_num == 1 || !in_array($contact, $contacts)) { |
| | | $contacts[] = $contact; |
| | | if (count($contacts) >= $MAXNUM) |
| | | break 2; |
| | | } |
| | | } |
| | | } |
| | | } |