1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12:
13:
14: 15: 16: 17: 18: 19: 20: 21: 22: 23:
24: class IMP_Basic_Contacts extends IMP_Basic_Base
25: {
26: 27: 28: 29: 30: 31: 32: 33: 34:
35: protected function _init()
36: {
37: global $injector, $page_output, $prefs, $registry;
38:
39:
40: if (!$registry->hasMethod('contacts/search')) {
41: $e = new IMP_Exception('Addressbook not available on this system.');
42: $e->logged = true;
43: throw $e;
44: }
45:
46:
47: $contacts = $injector->getInstance('IMP_Contacts');
48: $source_list = $contacts->source_list;
49:
50: 51:
52: if (!isset($this->vars->source) ||
53: !isset($source_list[$this->vars->source])) {
54: reset($source_list);
55: $this->vars->source = key($source_list);
56: }
57:
58: if ($this->vars->searched || $prefs->getValue('display_contact')) {
59: $a_list = iterator_to_array($contacts->searchEmail($this->vars->get('search', ''), array(
60: 'sources' => array($this->vars->source)
61: )));
62: } else {
63: $a_list = array();
64: }
65:
66: 67:
68: $selected_addresses = array();
69: foreach (explode('|', $this->vars->sa) as $addr) {
70: if (strlen(trim($addr))) {
71: $selected_addresses[] = $addr;
72: }
73: }
74:
75:
76: $view = new Horde_View(array(
77: 'templatePath' => IMP_TEMPLATES . '/contacts'
78: ));
79: $view->addHelper('FormTag');
80: $view->addHelper('Tag');
81:
82: $view->a_list = $a_list;
83: $view->action = self::url();
84: $view->sa = $selected_addresses;
85: $view->search = $this->vars->search;
86: $view->to_only = intval($this->vars->to_only);
87:
88: if (count($source_list) > 1) {
89: $s_list = array();
90: foreach ($source_list as $key => $select) {
91: $s_list[] = array(
92: 'label' => $select,
93: 'selected' => ($key == $this->vars->source),
94: 'val' => $key
95: );
96: }
97: $view->source_list = $s_list;
98: } else {
99: $view->source_list = key($source_list);
100: }
101:
102:
103: $page_output->addScriptFile('hordecore.js', 'horde');
104: $page_output->addScriptFile('contacts.js');
105: $page_output->addInlineJsVars(array(
106: 'ImpContacts.text' => array(
107: 'closed' => _("The message being composed has been closed."),
108: 'select' => _("You must select an address first.")
109: )
110: ));
111:
112: $page_output->topbar = $page_output->sidebar = false;
113:
114: $this->header = _("Address Book");
115: $this->output = $view->render('contacts');
116: }
117:
118: 119:
120: public static function url(array $opts = array())
121: {
122: return Horde::url('basic.php', !empty($opts['full']))->add('page', 'contacts')->unique();
123: }
124:
125: }
126: