1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14:
15: class IMP_Tree_Flist extends Horde_Tree_Select
16: {
17: 18: 19: 20: 21:
22: protected $_allowed = array(
23: 'container',
24: 'orig_label',
25: 'selected',
26: 'vfolder'
27: );
28:
29: 30: 31: 32: 33:
34: protected $_filter = array();
35:
36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63:
64: public function __construct($name, array $params = array())
65: {
66: $params = array_merge(array(
67: 'abbrev' => 30
68: ), $params);
69:
70: parent::__construct($name, $params);
71: }
72:
73: 74: 75:
76: public function getTree($static = false)
77: {
78: global $conf, $injector, $registry;
79:
80: $this->_buildIndents($this->_root_nodes);
81:
82: $filter = $injector->createInstance('Horde_Text_Filter');
83: $t = $injector->createInstance('Horde_Template');
84: $t->setOption('gettext', true);
85:
86:
87: if ($customhtml = $this->getOption('customhtml')) {
88: $t->set('customhtml', $customhtml);
89: }
90:
91:
92: if (($heading = $this->getOption('heading')) &&
93: (strlen($heading) > 0)) {
94: $t->set('heading', $heading);
95: }
96:
97:
98: if ($this->getOption('new_folder') &&
99: ($injector->getInstance('Horde_Core_Perms')->hasAppPermission('create_folders') &&
100: $injector->getInstance('Horde_Core_Perms')->hasAppPermission('max_folders'))) {
101: $t->set('new_mbox', true);
102: }
103:
104:
105: if ($this->getOption('inc_vfolder')) {
106: $imp_search = $injector->getInstance('IMP_Search');
107: $vfolder_list = array();
108:
109: $imp_search->setIteratorFilter(IMP_Search::LIST_VFOLDER);
110: foreach ($imp_search as $val) {
111: $form_to = IMP_Mailbox::formTo($val);
112: $vfolder_list[] = array(
113: 'l' => $filter->filter($val->label, 'space2html', array('encode' => true)),
114: 'sel' => !empty($this->_nodes[$form_to]['selected']),
115: 'v' => $form_to
116: );
117: }
118:
119: if (!empty($vfolder_list)) {
120: $t->set('vfolder', $vfolder_list);
121: }
122: }
123:
124:
125: if ($this->getOption('inc_tasklists') &&
126: $GLOBALS['session']->get('imp', 'tasklistavail')) {
127: try {
128: $tasklists = $registry->call('tasks/listTasklists', array(false, Horde_Perms::EDIT));
129:
130: if (count($tasklists)) {
131: $tasklist_list = array();
132: foreach ($tasklists as $id => $tasklist) {
133: $tasklist_list[] = array(
134: 'l' => $filter->filter($tasklist->get('name'), 'space2html', array('encode' => true)),
135: 'v' => IMP_Mailbox::formTo(IMP::TASKLIST_EDIT . $id)
136: );
137: }
138: $t->set('tasklist', $tasklist_list);
139: }
140: } catch (Horde_Exception $e) {}
141: }
142:
143:
144: if ($this->getOption('inc_notepads') &&
145: $GLOBALS['session']->get('imp', 'notepadavail')) {
146: try {
147: $notepads = $registry->call('notes/listNotepads', array(false, Horde_Perms::EDIT));
148:
149: if (count($notepads)) {
150: foreach ($notepads as $id => $notepad) {
151: $notepad_list[] = array(
152: 'l' => $filter->filter($notepad->get('name'), 'space2html', array('encode' => true)),
153: 'v' => IMP_Mailbox::formTo(IMP::NOTEPAD_EDIT . $id)
154: );
155: }
156: $t->set('notepad', $notepad_list);
157: }
158: } catch (Horde_Exception $e) {}
159: }
160:
161:
162: $this->_filter = ($filter = $this->getOption('filter'))
163: ? array_flip($filter)
164: : array();
165:
166: $tree = '';
167: foreach ($this->_root_nodes as $node_id) {
168: $tree .= $this->_buildTree($node_id);
169: }
170: $t->set('tree', $tree);
171:
172: return $t->fetch(IMP_TEMPLATES . '/imp/flist/flist.html');
173: }
174:
175: 176:
177: protected function _buildTree($node_id)
178: {
179: if (isset($this->_filter[$node_id])) {
180: return '';
181: }
182:
183: $node = &$this->_nodes[$node_id];
184:
185: if ($abbrev = $this->getOption('abbrev')) {
186: $orig_label = $node['label'];
187: $node['label'] = Horde_String::abbreviate($node['orig_label'], $abbrev - ($node['indent'] * 2));
188: } else {
189: $orig_label = null;
190: }
191:
192:
193: if (!$this->getOption('container_select') &&
194: !empty($node['container'])) {
195: if (!empty($node['vfolder'])) {
196: return '';
197: }
198: $node_id = '';
199: $this->_nodes[$node_id] = $node;
200: }
201:
202: $out = parent::_buildTree($node_id);
203:
204: if ($orig_label) {
205: $node['label'] = $orig_label;
206: }
207:
208: return $out;
209: }
210:
211: }
212: