annotate plugins/advanced_search/advanced_search.php @ 38:ac106d4c8961 default tip

flip /etc/roundcube to point here
author Charlie Root
date Sat, 29 Dec 2018 05:39:53 -0500
parents 50ac5484d514
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
34
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
1 <?php
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
2 /**
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
3 * Processing an advanced search over an E-Mail Account
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
4 *
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
5 * @version 2.1.5
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
6 * @licence GNU GPLv3+
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
7 * @author Wilwert Claude
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
8 * @author Ludovicy Steve
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
9 * @author Chris Moules
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
10 * @website http://www.gms.lu
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
11 *
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
12 * Updated by Alex S Grebenschikov (www.poralix.com)
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
13 * to make it compatible with RoundCube 1.3.0
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
14 * Last modified: Tue Aug 1 06:41:46 CEST 2017
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
15 *
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
16 */
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
17
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
18 class advanced_search extends rcube_plugin
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
19 {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
20
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
21 /**
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
22 * Instance of rcmail
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
23 *
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
24 * @var object
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
25 * @access private
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
26 */
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
27 private $rc;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
28
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
29 public $task = 'mail|settings';
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
30
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
31 /**
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
32 * Plugin config
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
33 *
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
34 * @var array
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
35 * @access private
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
36 */
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
37 private $config;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
38
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
39 /**
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
40 * Localization strings
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
41 *
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
42 * @var array
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
43 * @access private
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
44 */
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
45 private $i18n_strings = array();
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
46
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
47 /**
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
48 * Initialisation of the plugin
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
49 *
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
50 * @access public
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
51 * @return null
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
52 */
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
53 public function init()
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
54 {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
55 $this->rc = rcmail::get_instance();
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
56 $this->load_config("config-default.inc.php");
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
57 $this->load_config();
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
58 $this->config = $this->rc->config->get('advanced_search_plugin');
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
59 $this->register_action('plugin.display_advanced_search', array($this, 'display_advanced_search'));
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
60 $this->register_action('plugin.trigger_search', array($this, 'trigger_search'));
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
61 $this->register_action('plugin.trigger_search_pagination', array($this, 'trigger_search_pagination'));
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
62 $this->register_action('plugin.save_search', array($this, 'save_search'));
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
63 $this->register_action('plugin.delete_search', array($this, 'delete_search'));
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
64 $this->register_action('plugin.get_saved_search', array($this, 'get_saved_search'));
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
65
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
66 $this->skin = $this->rc->config->get('skin');
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
67 $this->add_texts('localization', true);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
68 $this->populate_i18n();
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
69 if(isset($this->config['criteria'])) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
70 foreach($this->config['criteria'] as $key => $translation) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
71 $this->config['criteria'][$key] = $this->gettext($key);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
72 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
73 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
74 $this->include_script('advanced_search.js');
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
75
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
76 if ($this->rc->task == 'mail') {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
77 $file = 'skins/' . $this->skin . '/advanced_search.css';
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
78
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
79 if (file_exists($this->home . '/' . $file)) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
80 $this->include_stylesheet($file);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
81 } else {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
82 $this->include_stylesheet('skins/default/advanced_search.css');
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
83 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
84
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
85 if (empty($this->rc->action)) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
86 $this->add_menu_entry();
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
87 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
88 } elseif ($this->rc->task == 'settings') {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
89 $this->add_hook('preferences_list', array($this, 'preferences_list'));
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
90 $this->add_hook('preferences_save', array($this, 'preferences_save'));
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
91 $this->add_hook('preferences_sections_list', array($this, 'preferences_section'));
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
92 $file = 'skins/' . $this->skin . '/advanced_search.css';
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
93 if (file_exists($this->home . '/' . $file)) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
94 $this->include_stylesheet($file);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
95 } else {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
96 $this->include_stylesheet('skins/default/advanced_search.css');
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
97 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
98 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
99
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
100 $this->add_hook('startup', array($this, 'startup'));
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
101 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
102
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
103
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
104 public function startup($args)
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
105 {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
106 $search = rcube_utils::get_input_value('_search', rcube_utils::INPUT_GET);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
107 if (!isset($search)) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
108 $search = rcube_utils::get_input_value('_search', rcube_utils::INPUT_POST);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
109 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
110 $rsearch = $search == 'advanced_search_active';
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
111 $uid = rcube_utils::get_input_value('_uid', rcube_utils::INPUT_GET);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
112 $draft_uid = rcube_utils::get_input_value('_draft_uid', rcube_utils::INPUT_GET);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
113 $mbox = rcube_utils::get_input_value('_mbox', rcube_utils::INPUT_GET);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
114 $page = rcube_utils::get_input_value('_page', rcube_utils::INPUT_GET);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
115 $sort = rcube_utils::get_input_value('_sort', rcube_utils::INPUT_GET);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
116
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
117 if (!empty($uid)) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
118 $parts = explode('__MB__', $uid);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
119 if (count($parts) == 2) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
120 $search = 'advanced_search_active';
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
121 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
122 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
123 if (!empty($draft_uid)) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
124 $parts = explode('__MB__', $draft_uid);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
125 if (count($parts) == 2) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
126 $search = 'advanced_search_active';
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
127 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
128 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
129
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
130 if ($search == 'advanced_search_active') {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
131 if ($args['action'] == 'show' && !empty($uid)) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
132 $parts = explode('__MB__', $uid);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
133 $uid = $parts[0];
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
134 $this->rc->output->redirect(array('_task' => 'mail', '_action' => $args['action'], '_mbox' => $mbox, '_uid' => $uid));
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
135 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
136 if ($args['action'] == 'compose') {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
137 $draft_uid = rcube_utils::get_input_value('_draft_uid', rcube_utils::INPUT_GET);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
138 $parts = explode('__MB__', $draft_uid);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
139 $draft_uid = $parts[0];
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
140 if (!empty($draft_uid)) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
141 $this->rc->output->redirect(array('_task' => 'mail', '_action' => $args['action'], '_mbox' => $mbox, '_draft_uid' => $draft_uid));
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
142 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
143 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
144 if ($args['action'] == 'list' && $rsearch) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
145 $this->rc->output->command('advanced_search_active', '_page=' . $page . '&_sort=' . $sort);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
146 $this->rc->output->send();
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
147 $args['abort'] = true;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
148 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
149 if ($args['action'] == 'mark') {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
150 $flag = rcube_utils::get_input_value('_flag', rcube_utils::INPUT_POST);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
151 $uid = rcube_utils::get_input_value('_uid', rcube_utils::INPUT_POST);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
152
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
153 $post_str = '_flag=' . $flag . '&_uid=' . $uid;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
154 if ($quiet = rcube_utils::get_input_value('_quiet', rcube_utils::INPUT_POST)) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
155 $post_str .= '&_quiet=' . $quiet;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
156 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
157 if ($from = rcube_utils::get_input_value('_from', rcube_utils::INPUT_POST)) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
158 $post_str .= '&_from=' . $from;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
159 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
160 if ($count = rcube_utils::get_input_value('_count', rcube_utils::INPUT_POST)) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
161 $post_str .= '&_count=' . $count;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
162 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
163 if ($ruid = rcube_utils::get_input_value('_ruid', rcube_utils::INPUT_POST)) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
164 $post_str .= '&_ruid=' . $ruid;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
165 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
166 $this->rc->output->command('label_mark', $post_str);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
167 $this->rc->output->send();
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
168 $args['abort'] = true;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
169 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
170
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
171 } else {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
172 if ($args['action'] != 'plugin.get_saved_search' && $args['action'] != 'plugin.save_search' && $args['action'] != 'plugin.delete_search') {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
173 $this->rc->output->command('plugin.advanced_search_del_header', array());
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
174 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
175 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
176 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
177
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
178 /**
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
179 * This function populates an array with localization texts.
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
180 * This is needed as ew are using a lot of localizations from core.
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
181 * The core localizations are not avalable directly in JS
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
182 *
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
183 * @access private
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
184 * @return null
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
185 */
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
186 private function populate_i18n()
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
187 {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
188 $core = array('advsearch', 'search', 'resetsearch', 'addfield', 'delete', 'cancel');
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
189
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
190 foreach ($core as $label) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
191 $this->i18n_strings[$label] = $this->rc->gettext($label);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
192 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
193
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
194 $local = array('in', 'and', 'or', 'not', 'where', 'exclude', 'andsubfolders', 'allfolders', 'save_the_search', 'has_been_saved', 'deletesearch', 'has_been_deleted');
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
195
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
196 foreach ($local as $label) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
197 $this->i18n_strings[$label] = $this->gettext($label);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
198 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
199 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
200
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
201 /**
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
202 * This adds a button into the configured menu to use the advanced search
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
203 *
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
204 * @access public
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
205 * @return null
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
206 */
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
207 public function add_menu_entry()
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
208 {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
209 $displayOptions = $this->rc->config->get('advanced_search_display_options', array());
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
210 $target_menu = (isset($displayOptions['target_menu']) && !empty($displayOptions['target_menu'])) ? $displayOptions['target_menu'] : $this->config['target_menu'];
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
211 if ($target_menu != 'toolbar') {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
212 $this->api->add_content(
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
213 html::tag(
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
214 'li',
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
215 null,
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
216 $this->api->output->button(
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
217 array(
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
218 'command' => 'plugin.advanced_search',
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
219 'label' => 'advsearch',
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
220 'type' => 'link',
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
221 'classact' => 'icon advanced-search active',
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
222 'class' => 'icon advanced-search',
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
223 'innerclass' => 'icon advanced-search'
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
224 )
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
225 )
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
226 ),
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
227 $target_menu
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
228 );
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
229 } else {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
230 $this->api->add_content(
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
231 $this->api->output->button(
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
232 array(
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
233 'command' => 'plugin.advanced_search',
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
234 'title' => 'advsearch',
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
235 'label' => 'search',
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
236 'type' => 'link',
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
237 'classact' => 'button advanced-search active',
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
238 'class' => 'button advanced-search',
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
239 'innerclass' => 'button advanced-search',
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
240 )
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
241 ),
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
242 $target_menu
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
243 );
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
244 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
245 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
246
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
247 /**
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
248 * This function quotes some specific values based on their data type
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
249 *
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
250 * @param mixed $input The value to get quoted
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
251 * @access public
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
252 * @return The quoted value
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
253 */
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
254 public function quote($value)
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
255 {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
256 if (getType($value) == 'string') {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
257 if (!preg_match('/"/', $value)) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
258 $value = preg_replace('/^"/', '', $value);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
259 $value = preg_replace('/"$/', '', $value);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
260 $value = preg_replace('/"/', '\\"', $value);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
261 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
262
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
263 $value = '"' . $value . '"';
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
264 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
265
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
266 return $value;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
267 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
268
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
269 /**
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
270 * This function generates the IMAP compatible search query based on the request data (by javascript)
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
271 *
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
272 * @param array $input The raw criteria data sent by javascript
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
273 * @access private
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
274 * @return string or int
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
275 */
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
276 private function process_search_part($search_part)
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
277 {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
278 $command_str = '';
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
279 $flag = false;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
280
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
281 // Check for valid input
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
282 if (!array_key_exists($search_part['filter'], $this->config['criteria'])) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
283 $this->rc->output->show_message($this->gettext('internalerror'), 'error');
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
284
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
285 return 0;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
286 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
287 if (in_array($search_part['filter'], $this->config['flag_criteria'])) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
288 $flag = true;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
289 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
290 if (!$flag && !(isset($search_part['filter-val']) && $search_part['filter-val'] != '')) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
291 return 1;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
292 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
293
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
294 // Negate part
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
295 if ($search_part['not'] == 'true') {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
296 $command_str .= 'NOT ';
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
297 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
298
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
299 $command_str .= $search_part['filter'];
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
300
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
301 if (!$flag) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
302 if (in_array($search_part['filter'], $this->config['date_criteria'])) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
303 // Take date format from user environment
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
304 $date_format = $this->rc->config->get('date_format', 'Y-m-d');
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
305 // Try to use PHP5.2+ DateTime but fallback to ugly old method
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
306 if (class_exists('DateTime')) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
307 $date = DateTime::createFromFormat($date_format, $search_part['filter-val']);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
308 $command_str .= ' ' . $this->quote($date->format("d-M-Y"));
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
309 } else {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
310 $date_format = preg_replace('/(\w)/', '%$1', $date_format);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
311 $date_array = strptime($search_part['filter-val'], $date_format);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
312 $unix_ts = mktime($date_array['tm_hour'], $date_array['tm_min'], $date_array['tm_sec'], $date_array['tm_mon']+1, $date_array['tm_mday'], $date_array['tm_year']+1900);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
313 $command_str .= ' ' . $this->quote(date("d-M-Y", $unix_ts));
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
314 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
315 } elseif (in_array($search_part['filter'], $this->config['email_criteria'])) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
316 // Strip possible ',' added by autocomplete
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
317 $command_str .= ' ' . $this->quote(trim($search_part['filter-val'], " \t,"));
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
318 } else {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
319 // Don't try to use a value for a binary flag object
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
320 $command_str .= ' ' . $this->quote($search_part['filter-val']);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
321 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
322 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
323
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
324 return $command_str;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
325 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
326
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
327 /**
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
328 * This function generates the IMAP compatible search query based on the request data (by javascript)
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
329 *
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
330 * @param array $input The raw criteria data sent by javascript
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
331 * @access public
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
332 * @return The final search command
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
333 */
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
334 public function get_search_query($input)
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
335 {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
336 $command = array();
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
337
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
338 foreach ($input as $search_part) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
339 // Skip excluded parts
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
340 if ($search_part['excluded'] == 'true') {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
341 continue;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
342 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
343 if (! $part_command = $this->process_search_part($search_part)) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
344 return 0;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
345 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
346 // Skip invalid parts
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
347 if ($part_command === 1) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
348 continue;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
349 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
350
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
351 $command[] = array('method' => isset($search_part['method']) ? $search_part['method'] : 'and',
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
352 'command' => $part_command);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
353 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
354
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
355 $command_string = $this->build_search_string($command);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
356
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
357 return $command_string;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
358 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
359
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
360 /**
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
361 * This function converts the preconfigured query parts (as array) into an IMAP compatible string
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
362 *
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
363 * @param array $command_array An array containing the advanced search criteria
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
364 * @access public
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
365 * @return The command string
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
366 */
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
367 private function build_search_string($command_array)
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
368 {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
369 $command = array();
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
370 $paranthesis = 0;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
371 $prev_method = null;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
372 $next_method = null;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
373 $cnt = count($command_array);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
374
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
375 foreach ($command_array as $k => $v) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
376 $part = '';
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
377 $next_method = 'unknown';
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
378
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
379 // Lookup next method
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
380 if ($k < $cnt-1) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
381 $next_method = $command_array[$k+1]['method'];
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
382 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
383
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
384 // If previous option was OR, close any open brakets
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
385 if ($paranthesis > 0 && $prev_method == 'or' && $v['method'] != 'or') {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
386 for (; $paranthesis > 0; $paranthesis--) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
387 $part .= ')';
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
388 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
389 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
390
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
391 // If there are two consecutive ORs, add brakets
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
392 // If the next option is a new OR, add the prefix here
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
393 // If the next option is _not_ an OR, and the current option is AND, prefix ALL
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
394 if ($next_method == 'or') {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
395 if ($v['method'] == 'or') {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
396 $part .= ' (';
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
397 $paranthesis++;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
398 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
399 $part .= 'OR ';
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
400 } elseif ($v['method'] == 'and') {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
401 $part .= 'ALL ';
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
402 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
403
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
404 $part .= $v['command'];
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
405
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
406 // If this is the end of the query, and we have open brakets, close them
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
407 if ($k == $cnt-1 && $paranthesis > 0) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
408 for (; $paranthesis > 0; $paranthesis--) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
409 $part .= ')';
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
410 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
411 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
412
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
413 $prev_method = $v['method'];
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
414 $command[] = $part;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
415 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
416
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
417 $command = implode(' ', $command);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
418
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
419 return $command;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
420 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
421
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
422 /**
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
423 * This functions sends the initial data to the client side where a form (in dialog) is built for the advanced search
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
424 *
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
425 * @access public
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
426 * @return null
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
427 */
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
428 public function display_advanced_search()
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
429 {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
430 $ret = array('html' => $this->generate_searchbox(),
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
431 'row' => $this->add_row(),
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
432 'saved_searches' => $this->get_saved_search_names(),
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
433 'title' => $this->i18n_strings['advsearch'],
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
434 'date_criteria' => $this->config['date_criteria'],
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
435 'flag_criteria' => $this->config['flag_criteria'],
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
436 'email_criteria' => $this->config['email_criteria']);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
437
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
438 $this->rc->output->command('plugin.show', $ret);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
439 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
440
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
441 public function generate_searchbox()
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
442 {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
443 $search_button = new html_inputfield(array('type' => 'submit', 'name' => 'search', 'class' => 'button mainaction', 'value' => $this->i18n_strings['search']));
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
444 $reset_button = new html_inputfield(array('type' => 'reset', 'name' => 'reset', 'class' => 'button reset', 'value' => $this->i18n_strings['resetsearch']));
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
445 $save_button = html::tag('input', array('type' => 'submit', 'name' => 'save_the_search', id=> 'save_the_search', 'class' => 'button save_search', 'value' => $this->i18n_strings['save_the_search']));
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
446 $delete_button = new html_inputfield(array('type' => 'submit', 'name' => 'delete', 'style' => 'display: none;', 'class' => 'button delete_search', 'value' => $this->i18n_strings['deletesearch']));
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
447
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
448 $layout_table = new html_table();
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
449 $layout_table->add(null, $search_button->show());
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
450 $folderConfig = array('name' => 'folder');
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
451 $layout_table->add(
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
452 null,
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
453 $this->i18n_strings['in'] . ': ' .
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
454 $this->folder_selector($folderConfig)->show($this->rc->storage->get_folder()) .
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
455 html::span(
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
456 array('class' => 'sub-folders'),
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
457 $this->i18n_strings['andsubfolders'] . ': ' .
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
458 html::tag(
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
459 'input',
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
460 array('type' => 'checkbox', 'name' => 'subfolder'),
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
461 null
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
462 )
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
463 ) .
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
464 $this->i19n_strings['where']
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
465 );
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
466 $first_row = $this->add_row(true);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
467 $layout_table->add_row();
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
468 $layout_table->add(array('class' => 'adv-search-and-or'), null);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
469 $layout_table->add(null, $first_row);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
470 $layout_table->add_row();
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
471 $layout_table->add(null, $search_button->show());
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
472 $layout_table->add(null, $save_button . ' ' . $reset_button->show() . ' ' . $delete_button->show());
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
473
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
474 return html::tag(
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
475 'div',
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
476 array('id' => 'adsearch-popup'),
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
477 html::tag(
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
478 'form',
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
479 array('method' => 'post', 'action' => '#'),
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
480 $layout_table->show()
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
481 )
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
482 );
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
483 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
484
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
485 /**
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
486 * This function is used to render the html of the advanced search form and also
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
487 * the later following rows are created by this function
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
488 *
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
489 * @param array $folders Array of folders
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
490 * @param boolean $first True if form gets created, False to create a new row
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
491 * @access public
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
492 * @return string The final html
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
493 */
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
494 public function add_row($first = false)
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
495 {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
496 $row_html = '';
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
497 $optgroups = '';
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
498
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
499 $criteria = $this->config['criteria'];
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
500 $all_criteria = array(
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
501 $this->gettext('Common') => $this->config['prefered_criteria'],
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
502 $this->gettext('Addresses') => $this->config['email_criteria'],
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
503 $this->gettext('Dates') => $this->config['date_criteria'],
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
504 $this->gettext('Flags') => $this->config['flag_criteria'],
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
505 $this->gettext('Other') => $this->config['other_criteria'],
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
506 );
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
507
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
508 foreach ($all_criteria as $label => $specific_criteria) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
509 $options = '';
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
510
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
511 foreach ($specific_criteria as $value) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
512 $options .= html::tag('option', array('value' => $value), $criteria[$value]);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
513 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
514
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
515 $optgroups .= html::tag('optgroup', array('label' => $label), $options);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
516 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
517
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
518 $tmp = html::tag('select', array('name' => 'filter'), $optgroups);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
519 $tmp .= $this->i18n_strings['not'] . ':' . html::tag('input', array('type' => 'checkbox', 'name' => 'not'), null);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
520 $tmp .= html::tag('input', array('type' => 'text', 'name' => 'filter-val'));
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
521 $tmp .= $this->i18n_strings['exclude'] . ':' . html::tag('input', array('type' => 'checkbox', 'name' => 'filter-exclude'), null);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
522 $tmp .= html::tag('button', array('name' => 'add', 'class' => 'add'), $this->i18n_strings['addfield']);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
523
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
524 if ($first) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
525 $row_html = $tmp;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
526 } else {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
527 $and_or_select = new html_select(array('name' => 'method'));
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
528 $and_or_select->add($this->i18n_strings['and'], 'and');
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
529 $and_or_select->add($this->i18n_strings['or'], 'or');
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
530 $tmp .= html::tag('button', array('name' => 'delete', 'class' => 'delete'), $this->i18n_strings['delete']);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
531 $row_html = html::tag(
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
532 'tr',
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
533 null,
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
534 html::tag(
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
535 'td',
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
536 array('class' => 'adv-search-and-or'),
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
537 $and_or_select->show()
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
538 ) .
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
539 html::tag(
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
540 'td',
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
541 null,
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
542 $tmp
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
543 )
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
544 );
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
545 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
546
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
547 return $row_html;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
548 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
549
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
550 /**
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
551 * Return folders list as html_select object
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
552 *
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
553 * This is a copy of the core function and adapted to fit
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
554 * the needs of the advanced_search function
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
555 *
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
556 * @param array $p Named parameters
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
557 *
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
558 * @return html_select HTML drop-down object
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
559 */
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
560 public function folder_selector($p = array())
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
561 {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
562 $p += array('maxlength' => 100, 'realnames' => false, 'is_escaped' => true);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
563 $a_mailboxes = array();
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
564 $storage = $this->rc->get_storage();
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
565
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
566 $list = $storage->list_folders_subscribed();
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
567 $delimiter = $storage->get_hierarchy_delimiter();
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
568
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
569 foreach ($list as $folder) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
570 $this->rc->build_folder_tree($a_mailboxes, $folder, $delimiter);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
571 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
572
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
573 $select = new html_select($p);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
574 $select->add($this->i18n_strings['allfolders'], "all");
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
575
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
576 $this->rc->render_folder_tree_select($a_mailboxes, $mbox, $p['maxlength'], $select, $p['realnames'], 0, $p);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
577
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
578 return $select;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
579 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
580
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
581 public function trigger_search_pagination($param)
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
582 {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
583 $_GET['search'] = $_SESSION['av_search'];
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
584 $_GET['folder'] = $_SESSION['av_folder'];
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
585 $_GET['sub_folders'] = $_SESSION['av_sub_folders'];
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
586 $this->trigger_search(true);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
587 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
588
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
589 /**
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
590 * Here is where the actual query is fired to the imap server and the result is evaluated and sent back to the client side
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
591 *
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
592 * @access public
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
593 * @return null
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
594 */
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
595 public function trigger_search($inPagination = false)
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
596 {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
597 $search = rcube_utils::get_input_value('search', rcube_utils::INPUT_GPC);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
598 // reset list_page and old search results
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
599 $this->rc->storage->set_page(1);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
600 $this->rc->storage->set_search_set(null);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
601 $page = rcube_utils::get_input_value('_page', rcube_utils::INPUT_GPC);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
602 $page = $page ? $page : 1;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
603 $pagesize = $this->rc->storage->get_pagesize();
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
604
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
605 if (!empty($search)) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
606 $mbox = rcube_utils::get_input_value('folder', rcube_utils::INPUT_GPC);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
607 $imap_charset = RCMAIL_CHARSET;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
608 $sort_column = rcmail_sort_column();
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
609 $search_str = $this->get_search_query($search);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
610 $sub_folders = rcube_utils::get_input_value('sub_folders', rcube_utils::INPUT_GPC) == 'true';
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
611 $folders = array();
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
612 $result_h = array();
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
613 $count = 0;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
614 $new_id = 1;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
615 $current_mbox = $this->rc->storage->get_folder();
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
616 $uid_list = array();
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
617 //Store information in session for pagination
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
618 $_SESSION['av_search'] = $search;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
619 $_SESSION['av_folder'] = $mbox;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
620 $_SESSION['av_sub_folders'] = rcube_utils::get_input_value('sub_folders', rcube_utils::INPUT_GPC);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
621 $nosub = $sub_folders;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
622 $folders = $this->rc->get_storage()->list_folders_subscribed();
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
623 if (empty($folders) || ($sub_folders === false && $mbox !== 'all')) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
624 $folders = array($mbox);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
625 } elseif ($mbox !== 'all') {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
626 if ($sub_folders === false) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
627 $folders = array($mbox);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
628 } else {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
629 $folders = $this->rc->get_storage()->list_folders_subscribed_direct($mbox);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
630 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
631 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
632 $md5folders = array();
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
633 foreach ($folders as $folder) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
634 $md5folders[md5($folder)] = $folder;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
635 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
636 $this->rc->output->set_env('as_md5_folders', $md5folders);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
637
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
638 if ($search_str) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
639 $res = $this->perform_search($search_str, $folders, $page);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
640 $count = $res['count'];
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
641 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
642
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
643
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
644 if ($count > 0) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
645 $_SESSION['advanced_search']['uid_list'] = $uid_list;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
646 if ($search_str && $inPagination == false) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
647 $this->rc->output->show_message('searchsuccessful', 'confirmation', array('nr' => $count));
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
648 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
649 } elseif ($err_code = $this->rc->storage->get_error_code()) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
650 rcmail_display_server_error();
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
651 } else {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
652 $this->rc->output->show_message('searchnomatch', 'notice');
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
653 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
654
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
655 $current_folder = rcube_utils::get_input_value('current_folder', rcube_utils::INPUT_GPC);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
656
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
657 $this->rc->output->set_env('search_request', 'advanced_search_active');
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
658 $this->rc->output->set_env('messagecount', $count);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
659 $this->rc->output->set_env('pagecount', ceil($count / $pagesize));
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
660 $this->rc->output->set_env('exists', $this->rc->storage->count($current_folder, 'EXISTS'));
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
661 $this->rc->output->command('set_rowcount', rcmail_get_messagecount_text($count, $page));
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
662 $this->rc->output->command('plugin.search_complete');
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
663 $this->rc->output->send();
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
664 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
665 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
666
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
667 /**
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
668 * return javascript commands to add rows to the message list
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
669 */
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
670 public function rcmail_js_message_list($a_headers, $insert_top = false, $a_show_cols = null, $avmbox = false, $avcols = array(), $showMboxColumn = false)
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
671 {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
672 global $CONFIG, $RCMAIL, $OUTPUT;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
673 $uid_mboxes = array();
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
674
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
675 if (empty($a_show_cols)) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
676 if (!empty($_SESSION['list_attrib']['columns'])) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
677 $a_show_cols = $_SESSION['list_attrib']['columns'];
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
678 } else {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
679 $a_show_cols = is_array($CONFIG['list_cols']) ? $CONFIG['list_cols'] : array('subject');
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
680 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
681 } else {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
682 if (!is_array($a_show_cols)) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
683 $a_show_cols = preg_split('/[\s,;]+/', strip_quotes($a_show_cols));
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
684 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
685 $head_replace = true;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
686 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
687
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
688 $mbox = $RCMAIL->storage->get_folder();
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
689
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
690 // make sure 'threads' and 'subject' columns are present
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
691 if (!in_array('subject', $a_show_cols)) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
692 array_unshift($a_show_cols, 'subject');
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
693 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
694 if (!in_array('threads', $a_show_cols)) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
695 array_unshift($a_show_cols, 'threads');
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
696 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
697 $_SESSION['list_attrib']['columns'] = $a_show_cols;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
698
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
699 // Make sure there are no duplicated columns (#1486999)
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
700 $a_show_cols = array_merge($a_show_cols, $avcols);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
701 $a_show_cols = array_unique($a_show_cols);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
702
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
703 // Plugins may set header's list_cols/list_flags and other rcube_message_header variables
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
704 // and list columns
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
705 $plugin = $RCMAIL->plugins->exec_hook(
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
706 'messages_list',
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
707 array('messages' => $a_headers, 'cols' => $a_show_cols)
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
708 );
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
709 $a_show_cols = $plugin['cols'];
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
710 $a_headers = $plugin['messages'];
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
711 $thead = $head_replace ? rcmail_message_list_head($_SESSION['list_attrib'], $a_show_cols) : null;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
712
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
713 // get name of smart From/To column in folder context
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
714 if (($f = array_search('fromto', $a_show_cols)) !== false) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
715 $smart_col = rcmail_message_list_smart_column_name();
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
716 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
717 if ($this->coltypesSet == false) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
718 $OUTPUT->command('set_message_coltypes', $a_show_cols, $thead, $smart_col);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
719 if ($showMboxColumn === true) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
720 $OUTPUT->command('plugin.advanced_search_add_header', array());
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
721 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
722 $this->coltypesSet = true;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
723 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
724
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
725 if (empty($a_headers)) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
726 return;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
727 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
728
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
729 // remove 'threads', 'attachment', 'flag', 'status' columns, we don't need them here
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
730 foreach (array('threads', 'attachment', 'flag', 'status', 'priority') as $col) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
731 if (($key = array_search($col, $a_show_cols)) !== false) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
732 unset($a_show_cols[$key]);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
733 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
734 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
735
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
736 // loop through message headers
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
737 foreach ($a_headers as $n => $header) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
738 if (empty($header)) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
739 continue;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
740 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
741 $a_msg_cols = array();
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
742 $a_msg_flags = array();
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
743 // format each col; similar as in rcmail_message_list()
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
744 foreach ($a_show_cols as $col) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
745 $col_name = $col == 'fromto' ? $smart_col : $col;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
746
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
747 if (in_array($col_name, array('from', 'to', 'cc', 'replyto'))) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
748 $cont = rcmail_address_string($header->$col_name, 3, false, null, $header->charset);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
749 } elseif ($col == 'subject') {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
750 $cont = trim(rcube_mime::decode_header($header->$col, $header->charset));
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
751 if (!$cont) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
752 $cont = $this->gettext('nosubject');
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
753 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
754 $cont = rcube::Q($cont);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
755 } elseif ($col == 'size') {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
756 $cont = $this->rc->show_bytes($header->$col);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
757 } elseif ($col == 'date') {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
758 $cont = rcube_utils::format_datestr($header->date,$date_format);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
759 } else {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
760 $cont = rcube::Q($header->$col);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
761 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
762 $a_msg_cols[$col] = $cont;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
763 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
764
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
765 $a_msg_flags = array_change_key_case(array_map('intval', (array) $header->flags));
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
766 if ($header->depth) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
767 $a_msg_flags['depth'] = $header->depth;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
768 } elseif ($header->has_children) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
769 $roots[] = $header->uid;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
770 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
771 if ($header->parent_uid) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
772 $a_msg_flags['parent_uid'] = $header->parent_uid;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
773 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
774 if ($header->has_children) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
775 $a_msg_flags['has_children'] = $header->has_children;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
776 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
777 if ($header->unread_children) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
778 $a_msg_flags['unread_children'] = $header->unread_children;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
779 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
780 if ($header->others['list-post']) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
781 $a_msg_flags['ml'] = 1;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
782 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
783 if ($header->priority) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
784 $a_msg_flags['prio'] = (int) $header->priority;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
785 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
786 $a_msg_flags['ctype'] = rcube::Q($header->ctype);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
787 $a_msg_flags['mbox'] = $mbox;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
788 if (!empty($header->list_flags) && is_array($header->list_flags)) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
789 $a_msg_flags = array_merge($a_msg_flags, $header->list_flags);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
790 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
791 if (!empty($header->list_cols) && is_array($header->list_cols)) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
792 $a_msg_cols = array_merge($a_msg_cols, $header->list_cols);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
793 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
794 if ($showMboxColumn === true) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
795 $a_msg_flags['avmbox'] = $avmbox;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
796 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
797
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
798 $OUTPUT->command(
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
799 'add_message_row',
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
800 $header->uid . '__MB__' . md5($mbox),
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
801 $a_msg_cols,
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
802 $a_msg_flags,
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
803 $insert_top
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
804 );
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
805 $id = $header->uid . '__MB__' . md5($mbox);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
806 $uid_mboxes[$id] = array('uid' => $header->uid, 'mbox' => $mbox, 'md5mbox' => md5($mbox));
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
807 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
808
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
809 if ($RCMAIL->storage->get_threading()) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
810 $OUTPUT->command('init_threads', (array) $roots, $mbox);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
811 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
812
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
813 return $uid_mboxes;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
814 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
815
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
816
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
817 private function do_pagination($folders, $onPage)
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
818 {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
819 $perPage = $this->rc->storage->get_pagesize();
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
820 $from = $perPage * $onPage - $perPage + 1;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
821 $to = $from + $perPage - 1;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
822 $got = 0;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
823 $pos = 0;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
824 $cbox = "";
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
825 $boxStart = 0;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
826 $boxStop = 0;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
827 $fetch = array();
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
828 foreach ($folders as $box => $num) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
829 $i = $num;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
830 if ($box != $cbox) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
831 $boxStart = 0;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
832 $boxStop = 0;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
833 $cbox = $box;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
834 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
835 while ($i--) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
836 $pos++;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
837 $boxStart++;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
838 if ($pos >= $from && $pos <= $to) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
839 if (!isset($fetch[$box])) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
840 $fetch[$box] = array("from" => $boxStart);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
841 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
842 $fetch[$box]['to'] = $boxStart;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
843 $got++;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
844 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
845 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
846 if ($got >= $perPage) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
847 break;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
848 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
849 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
850
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
851 return $fetch;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
852 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
853
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
854 /**
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
855 * Save advanced search preferences
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
856 *
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
857 * @access public
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
858 */
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
859 public function preferences_save($args)
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
860 {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
861 if ($args['section'] != 'advancedsearch') {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
862 return;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
863 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
864 $rcmail = rcmail::get_instance();
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
865
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
866 $displayOptions = array();
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
867 $displayOptions['_show_message_label_header'] = rcube_utils::get_input_value('_show_message_label_header', rcube_utils::INPUT_POST) == 1 ? true : false;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
868 $displayOptions['_show_message_mbox_info'] = rcube_utils::get_input_value('_show_message_mbox_info', rcube_utils::INPUT_POST) == 1 ? true : false;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
869 $displayOptions['target_menu'] = rcube_utils::get_input_value('button_display_option', rcube_utils::INPUT_POST);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
870
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
871 $args['prefs']['advanced_search_display_options'] = $displayOptions;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
872
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
873 return($args);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
874 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
875
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
876 /**
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
877 * Add a section advanced search to the preferences section list
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
878 *
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
879 * @access public
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
880 */
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
881 public function preferences_section($args)
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
882 {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
883 $args['list']['advancedsearch'] = array(
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
884 'id' => 'advancedsearch',
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
885 'section' => rcube::Q($this->gettext('advancedsearch'))
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
886 );
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
887
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
888 return($args);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
889 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
890
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
891 /**
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
892 * Display advanced search configuration in user preferences tab
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
893 *
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
894 * @access public
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
895 */
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
896 public function preferences_list($args)
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
897 {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
898 if ($args['section'] == 'advancedsearch') {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
899
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
900 $this->rc = rcmail::get_instance();
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
901 $args['blocks']['label_display_options'] = array('options' => array(), 'name' => rcube::Q($this->gettext('label_display_options')));
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
902
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
903 $displayOptions = $this->rc->config->get('advanced_search_display_options', array());
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
904 $target_menu = (isset($displayOptions['target_menu']) && !empty($displayOptions['target_menu'])) ? $displayOptions['target_menu'] : $this->config['target_menu'];
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
905 $options = '';
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
906 $optarg = array('value' => 'messagemenu');
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
907 if ($target_menu == 'messagemenu') {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
908 $optarg['selected'] = 'selected';
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
909 $target_image = 'menu_location_a.jpg';
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
910 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
911 $options .= html::tag('option', $optarg, rcube::Q($this->gettext('display_in_messagemenu')));
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
912 $optarg = array('value' => 'toolbar');
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
913 if ($target_menu == 'toolbar') {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
914 $optarg['selected'] = 'selected';
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
915 $target_image = 'menu_location_b.jpg';
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
916 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
917 $options .= html::tag('option', $optarg,rcube::Q($this->gettext('display_in_toolbar')));
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
918 $select = html::tag('select', array('name' => 'button_display_option', 'id' => 'button_display_option'), $options);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
919
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
920 $label1 = html::label('_show_message_label_header', rcube::Q($this->gettext('mailbox_headers_in_results')));
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
921 $label2 = html::label('_show_message_mbox_info', rcube::Q($this->gettext('mailbox_info_in_results')));
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
922 $label3 = html::label('button_display_option', rcube::Q($this->gettext('show_advanced_search')));
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
923
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
924 $arg1 = array('name' => '_show_message_label_header', 'id' => '_show_message_label_header', 'type' => 'checkbox', 'title' => "", 'class' => 'watermark linput', 'value' => 1);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
925 if (isset($displayOptions['_show_message_label_header']) && $displayOptions['_show_message_label_header'] === true) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
926 $arg1['checked'] = 'checked';
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
927 $img1class = 'enabled';
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
928 } else {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
929 $img1class = 'disabled';
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
930 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
931 $check1 = html::tag('input', $arg1);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
932 $arg2 = array('name' => '_show_message_mbox_info', 'id' => '_show_message_mbox_info', 'type' => 'checkbox', 'title' => "", 'class' => 'watermark linput', 'value' => 1);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
933 if (isset($displayOptions['_show_message_mbox_info']) && $displayOptions['_show_message_mbox_info'] === true) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
934 $arg2['checked'] = 'checked';
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
935 $img2class = 'enabled';
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
936 } else {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
937 $img2class = 'disabled';
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
938 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
939
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
940 $img1 = html::img(array('src' => $this->url('skins/larry/images/show_mbox_row.jpg'), 'class' => $img1class));
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
941 $img2 = html::img(array('src' => $this->url('skins/larry/images/show_mbox_col.jpg'), 'class' => $img2class));
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
942 $img3 = html::img(array('src' => $this->url('skins/larry/images/' . $target_image)));
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
943
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
944 $check2 = html::tag('input', $arg2);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
945 $args['blocks']['label_display_options']['options'][0] = array('title' => '', 'content' => '<p class="avsearchpref"><span>' . $check1 . ' ' . $label1 . '</span> ' . $img1 . '</p>');
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
946 $args['blocks']['label_display_options']['options'][1] = array('title' => '', 'content' => '<p class="avsearchpref"><span>' . $check2 . ' ' . $label2 . '</span> ' . $img2 . '</p>');
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
947 $args['blocks']['label_display_options']['options'][2] = array('title' => '', 'content' => '<p class="avsearchpref"><span>' . $label3 . ' ' . $select . '</span> ' . $img3 . '</p>');
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
948 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
949
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
950 return($args);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
951 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
952
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
953 private function perform_search($search_string, $folders, $page = 1)
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
954 {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
955 // Search all folders and build a final set
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
956 if ($folders[0] == 'all' || empty($folders)) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
957 $folders_search = $this->rc->imap->list_folders_subscribed();
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
958 } else {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
959 $folders_search = $folders;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
960 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
961 $count = 0;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
962 $folder_count = array();
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
963 foreach ($folders_search as $mbox) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
964 $this->rc->storage->set_folder($mbox);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
965 $this->rc->storage->search($mbox, $search_string, RCMAIL_CHARSET, $_SESSION['sort_col']);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
966 $result = array();
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
967 $fcount = $this->rc->storage->count($mbox, 'ALL', !empty($_REQUEST['_refresh']));
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
968 $count += $fcount;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
969 $folder_count[$mbox] = $fcount;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
970 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
971 foreach ($folder_count as $k => $v) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
972 if ($v == 0) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
973 unset($folder_count[$k]);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
974 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
975 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
976 $fetch = $this->do_pagination($folder_count, $page);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
977 $mails = array();
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
978 $currentMailbox = "";
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
979 $displayOptions = $this->rc->config->get('advanced_search_display_options', array());
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
980 $showMboxColumn = isset($displayOptions['_show_message_mbox_info']) && $displayOptions['_show_message_mbox_info'] ? true : false;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
981 $uid_mboxes = array();
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
982 foreach ($fetch as $mailbox => $data) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
983 if ($currentMailbox != $mailbox) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
984 $currentMailbox = $mailbox;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
985 if (isset($displayOptions['_show_message_label_header']) && $displayOptions['_show_message_label_header'] === true) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
986 $this->rc->output->command('advanced_search_add_mbox', $mailbox, $folder_count[$mailbox], $showMboxColumn);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
987 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
988 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
989 $uid_mboxes = array_merge($uid_mboxes, $this->getMails($mailbox, $data, $search_string, $showMboxColumn));
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
990 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
991
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
992 return array('result' => array(), 'count' => $count, 'uid_mboxes' => $uid_mboxes);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
993 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
994
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
995 private function getMails($mailbox, $data, $search_string, $showMboxColumn)
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
996 {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
997 $pageSize = $this->rc->storage->get_pagesize();
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
998 $msgNum = $data['from'];
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
999 $startPage = ceil($msgNum/$pageSize);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
1000 $msgMod = $msgNum % $pageSize;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
1001 $multiPage = "false";
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
1002 $firstArrayElement = $msgMod == 0 ? ($pageSize-1) : ($msgMod-1);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
1003 $quantity = $data['to'] - $data['from'];
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
1004 if ($data['from'] + $quantity > $pageSize) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
1005 $multiPage = "true";
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
1006 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
1007 $this->rc->storage->set_folder($mailbox);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
1008 $this->rc->storage->search($mailbox, $search_string, RCMAIL_CHARSET, $_SESSION['sort_col']);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
1009 $messages = $this->rc->storage->list_messages('', $startPage);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
1010 if ($multiPage) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
1011 $messages = array_merge($messages, $this->rc->storage->list_messages('', $startPage+1));
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
1012 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
1013 //FIRST: 0 QUANTITY: 2
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
1014 $sliceTo = $quantity + 1;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
1015 $mslice = array_slice($messages, $firstArrayElement, $sliceTo, true);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
1016 $messages = $mslice;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
1017 $avbox = array();
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
1018 $showAvmbox = false;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
1019 foreach ($messages as $set_flag) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
1020 $set_flag->flags['skip_mbox_check'] = true;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
1021 if ($showMboxColumn === true) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
1022 $set_flag->avmbox = $mailbox;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
1023 $avbox[] = 'avmbox';
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
1024 $showAvmbox = true;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
1025 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
1026 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
1027 $uid_mboxes = $this->rcmail_js_message_list($messages, false, null, $showAvmbox, $avbox, $showMboxColumn);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
1028
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
1029 return $uid_mboxes;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
1030 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
1031
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
1032 public function save_search()
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
1033 {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
1034 $search_name = rcube_utils::get_input_value('search_name', rcube_utils::INPUT_GPC);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
1035 if ($search_name) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
1036 $search = array();
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
1037 $search['search'] = rcube_utils::get_input_value('search', rcube_utils::INPUT_GPC);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
1038 $search['search_name'] = $search_name;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
1039 $search['folder'] = rcube_utils::get_input_value('folder', rcube_utils::INPUT_GPC);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
1040 $search['sub_folders'] = rcube_utils::get_input_value('sub_folders', rcube_utils::INPUT_GPC);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
1041 $prefs = (array)$this->rc->user->get_prefs();
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
1042 if (!isset($prefs['advanced_search'])) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
1043 $prefs['advanced_search'] = array();
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
1044 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
1045 $prefs['advanced_search'][$search_name] = $search;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
1046 $this->rc->user->save_prefs(array('advanced_search' => $prefs['advanced_search']));
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
1047 $this->rc->output->show_message('"<i>' . $search_name . '</i>" ' . $this->i18n_strings['has_been_saved'], 'confirmation');
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
1048 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
1049 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
1050
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
1051 public function delete_search()
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
1052 {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
1053 $search_name = rcube_utils::get_input_value('search_name', rcube_utils::INPUT_GPC);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
1054 if ($search_name) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
1055 $prefs = (array)$this->rc->user->get_prefs();
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
1056 unset($prefs['advanced_search'][$search_name]);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
1057 $this->rc->user->save_prefs(array('advanced_search' => $prefs['advanced_search']));
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
1058 $this->rc->output->show_message('"<i>' . $search_name . '</i>" ' . $this->i18n_strings['has_been_deleted'], 'notice');
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
1059 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
1060 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
1061
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
1062 public function get_saved_search()
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
1063 {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
1064 $search_name = rcube_utils::get_input_value('search_name', rcube_utils::INPUT_GPC);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
1065 $prefs = (array)$this->rc->user->get_prefs();
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
1066 if (!isset($prefs['advanced_search'])) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
1067 $prefs['advanced_search'] = array();
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
1068 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
1069
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
1070 $search = isset($prefs['advanced_search'][$search_name]) ? $prefs['advanced_search'][$search_name] : false;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
1071 $this->rc->output->command('plugin.load_saved_search', $search);
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
1072 $this->rc->output->send();
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
1073 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
1074
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
1075 private function get_saved_search_names()
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
1076 {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
1077 $prefs = (array)$this->rc->user->get_prefs();
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
1078 if (!isset($prefs['advanced_search'])) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
1079 $prefs['advanced_search'] = array();
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
1080 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
1081 $names = array();
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
1082 foreach($prefs['advanced_search'] as $name => $search) {
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
1083 $names[] = $name;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
1084 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
1085
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
1086 return $names;
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
1087 }
50ac5484d514 one fix to distro
Charlie Root
parents:
diff changeset
1088 }