1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14:
15: class IMP_Ajax_Imple_ContactAutoCompleter extends Horde_Core_Ajax_Imple_AutoCompleter
16: {
17: 18: 19: 20: 21:
22: static protected $_listOutput = false;
23:
24: 25: 26:
27: protected function _attach($js_params)
28: {
29: $js_params['indicator'] = $this->_params['triggerId'] . '_loading_img';
30:
31: $ret = array(
32: 'params' => $js_params,
33: 'raw_params' => array(
34: 'onSelect' => 'function (v) { if (!v.endsWith(";")) { v += ","; } return v + " "; }',
35: 'onType' => 'function (e) { return e.include("<") ? "" : e; }'
36: )
37: );
38:
39: $ac_browser = empty($GLOBALS['conf']['compose']['ac_browser'])
40: ? 0
41: : $GLOBALS['conf']['compose']['ac_browser'];
42:
43: if ($ac_browser && !$GLOBALS['session']->get('imp', 'ac_ajax')) {
44: $success = $use_ajax = true;
45: $sparams = IMP::getAddressbookSearchParams();
46: foreach ($sparams['fields'] as $val) {
47: array_map('strtolower', $val);
48: sort($val);
49: if ($val != array('email', 'name')) {
50: $success = false;
51: break;
52: }
53: }
54: if ($success) {
55: $addrlist_count = IMP_Compose::getAddressList('', false, true);
56: $use_ajax = $addrlist_count > $ac_browser;
57: }
58: $GLOBALS['session']->set('imp', 'ac_ajax', $use_ajax);
59: }
60:
61: if (!$ac_browser || $GLOBALS['session']->get('imp', 'ac_ajax')) {
62: $ret['ajax'] = 'ContactAutoCompleter';
63: $ret['params']['minChars'] = intval($GLOBALS['conf']['compose']['ac_threshold'] ? $GLOBALS['conf']['compose']['ac_threshold'] : 1);
64: } else {
65: if (!self::$_listOutput) {
66: $addrlist = IMP_Compose::getAddressList();
67: Horde::addInlineScript(array_merge(array(
68: 'if (!window.IMP) window.IMP = {}'
69: ), Horde::addInlineJsVars(array(
70: 'IMP.ac_list' => $addrlist
71: ), array('ret_vars' => true))));
72: self::$_listOutput = true;
73: }
74:
75: $ret['browser'] = 'IMP.ac_list';
76: }
77:
78: return $ret;
79: }
80:
81: 82: 83: 84: 85: 86: 87:
88: public function handle($args, $post)
89: {
90:
91: if (empty($args['input']) ||
92: !($input = Horde_Util::getPost($args['input']))) {
93: return array();
94: }
95:
96: return IMP_Compose::expandAddresses($input, array('levenshtein' => true));
97: }
98:
99: }
100: