1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12:
13:
14: 15: 16: 17: 18: 19: 20: 21: 22:
23: class IMP_Prefs_Special_Searches implements Horde_Core_Prefs_Ui_Special
24: {
25: 26:
27: public function init(Horde_Core_Prefs_Ui $ui)
28: {
29: }
30:
31: 32:
33: public function display(Horde_Core_Prefs_Ui $ui)
34: {
35: global $injector, $page_output, $prefs;
36:
37: $page_output->addScriptFile('hordecore.js', 'horde');
38: $page_output->addScriptFile('searchesprefs.js');
39:
40: $imp_search = $injector->getInstance('IMP_Search');
41: $fout = $vout = array();
42:
43: $view = new Horde_View(array(
44: 'templatePath' => IMP_TEMPLATES . '/prefs'
45: ));
46: $view->addHelper('FormTag');
47: $view->addHelper('Tag');
48: $view->addHelper('Text');
49:
50: $vfolder_locked = $prefs->isLocked('vfolder');
51: $iterator = IMP_Search_IteratorFilter::create(
52: IMP_Search_IteratorFilter::DISABLED |
53: IMP_Search_IteratorFilter::VFOLDER
54: );
55:
56: foreach ($iterator as $val) {
57: if (!$val->prefDisplay) {
58: continue;
59: }
60:
61: $editable = !$vfolder_locked && $imp_search->isVFolder($val, true);
62: $m_url = $val->enabled
63: ? $val->mbox_ob->url('mailbox')->link()
64: : null;
65:
66: $vout[] = array(
67: 'description' => Horde_String::truncate($val->querytext, 200),
68: 'edit' => ($editable ? $imp_search->editUrl($val) : null),
69: 'enabled' => $val->enabled,
70: 'enabled_locked' => $vfolder_locked,
71: 'key' => $val->id,
72: 'label' => $val->label,
73: 'm_url' => $m_url
74: );
75: }
76: $view->vfolders = $vout;
77:
78: $filter_locked = $prefs->isLocked('filter');
79: $iterator = IMP_Search_IteratorFilter::create(
80: IMP_Search_IteratorFilter::DISABLED |
81: IMP_Search_IteratorFilter::FILTER
82: );
83:
84: foreach ($iterator as $val) {
85: if (!$val->prefDisplay) {
86: continue;
87: }
88:
89: $editable = !$filter_locked && $imp_search->isFilter($val, true);
90:
91: $fout[] = array(
92: 'description' => Horde_String::truncate($val->querytext, 200),
93: 'edit' => ($editable ? $imp_search->editUrl($val) : null),
94: 'enabled' => $val->enabled,
95: 'enabled_locked' => $filter_locked,
96: 'key' => $val->id,
97: 'label' => $val->label
98: );
99: }
100: $view->filters = $fout;
101:
102: if (empty($fout) && empty($vout)) {
103: $view->nosearches = true;
104: } else {
105: $GLOBALS['page_output']->addInlineJsVars(array(
106: 'ImpSearchesPrefs.confirm_delete_filter' => _("Are you sure you want to delete this filter?"),
107: 'ImpSearchesPrefs.confirm_delete_vfolder' => _("Are you sure you want to delete this virtual folder?")
108: ));
109: }
110:
111: return $view->render('searches');
112: }
113:
114: 115:
116: public function update(Horde_Core_Prefs_Ui $ui)
117: {
118: global $injector, $notification;
119:
120: $imp_search = $injector->getInstance('IMP_Search');
121:
122: switch ($ui->vars->searches_action) {
123: case 'delete':
124:
125: $key = substr($ui->vars->searches_data, 7);
126: if ($ob = $imp_search[$key]) {
127: if ($imp_search->isVFolder($ob)) {
128: $notification->push(sprintf(_("Virtual Folder \"%s\" deleted."), $ob->label), 'horde.success');
129: } elseif ($imp_search->isFilter($ob)) {
130: $notification->push(sprintf(_("Filter \"%s\" deleted."), $ob->label), 'horde.success');
131: }
132: unset($imp_search[$key]);
133: }
134: break;
135:
136: default:
137:
138: $iterator = IMP_Search_IteratorFilter::create(
139: IMP_Search_IteratorFilter::DISABLED |
140: IMP_Search_IteratorFilter::VFOLDER
141: );
142: $vfolders = array();
143:
144: foreach ($iterator as $val) {
145: $form_key = 'enable_' . $val->id;
146:
147: 148:
149: if ($val->prefDisplay) {
150: $val->enabled = !empty($ui->vars->$form_key);
151: $vfolders[$val->id] = $val;
152: }
153: }
154: $imp_search->setVFolders($vfolders);
155:
156:
157: $iterator = IMP_Search_IteratorFilter::create(
158: IMP_Search_IteratorFilter::DISABLED |
159: IMP_Search_IteratorFilter::FILTER
160: );
161: $filters = array();
162:
163: foreach ($iterator as $val) {
164: $form_key = 'enable_' . $val->id;
165: $val->enabled = !empty($ui->vars->$form_key);
166: $filters[$val->id] = $val;
167: }
168: $imp_search->setFilters($filters);
169: break;
170: }
171:
172: return false;
173: }
174:
175: }
176: