annotate plugins/advanced_search/advanced_search.php.orig @ 34:50ac5484d514

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