Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
page_calendar_events_search_edit_fns.inc
1 <?php
18 require_once SQ_PACKAGES_PATH.'/search/search_page/search_page_edit_fns.inc';
19 
29 {
30 
31 
36  function __construct()
37  {
38  parent::__construct();
39  $this->static_screens['details']['force_unlock'] = 0;
40 
41  }//end constructor
42 
43 
54  function paintEventsDateFilters(&$asset, &$o, $prefix)
55  {
56  $write_access = $asset->writeAccess('all');
57  $filters = $asset->attr('events_filters');
58 
59  $query_types = Array(
60  'none' => '-- '.ucfirst(translate('page_events_search_filter_select_options').' --'),
61  'single_date' => ucfirst(translate('page_events_search_filter_select_options_single_date')),
62  'date_range' => ucfirst(translate('page_events_search_filter_select_options_date_range')),
63  'fuzzy_dropdown' => ucfirst(translate('page_events_search_filter_select_options_fuzzy_dropdown')),
64  'fuzzy_checkboxes' => ucfirst(translate('page_events_search_filter_select_options_fuzzy_checkboxes')),
65  );
66 
67  $fuzzy_options = Array();
68  $default_fuzzy_options = Array();
69  foreach($asset->fuzzy_date_types as $fuzzy_opt => $default) {
70  $fuzzy_options[$fuzzy_opt] = ucfirst($fuzzy_opt);
71 
72  if ($default) {
73  $default_fuzzy_options[] = $fuzzy_opt;
74  }
75  }//end foreach
76 
77  ?>
78  <table class ="sq-backend-table" border="1" style="margin-bottom: 7px">
79  <tr>
80  <th>Name</th>
81  <th>Filter</th>
82  <?php
83  if ($write_access) {
84  echo "<th>Delete</th>";
85  } ?>
86  </tr>
87 
88  <?php
89  $input_box_extra = $write_access ? '' : 'disabled';
90  foreach ($filters as $filter_name => $filter_data) {
91  echo "<tr>";
92  echo "<td>$filter_name</td>";
93 
94  echo "<td>";
95  if (isset($filter_data['type'])) {
96  echo ucwords(str_replace('_', ' ', $filter_data['type']));
97 
98  switch($filter_data['type']) {
99  case 'single_date':
100  case 'date_range':
101  echo "<br />";
102  check_box($prefix.'_filters['.$filter_name.'][use_picker]', 1, array_get_index($filter_data, 'use_picker', TRUE), '', $input_box_extra);
103  echo "Include date picker";
104  break;
105 
106  case 'fuzzy_dropdown':
107  case 'fuzzy_checkboxes':
108  $selected_fuzzy_options = array_get_index($filter_data, 'fuzzy_options', $default_fuzzy_options);
109  echo "<br /><br />";
110  combo_box($prefix.'_filters['.$filter_name.'][fuzzy_options]', $fuzzy_options, TRUE, $selected_fuzzy_options, 8, $input_box_extra);
111  break;
112  }//end switch
113  echo "<br /><br>";
114  }
115  if ($write_access) {
116  combo_box($prefix.'_filters['.$filter_name.'][type]', $query_types, FALSE, 'none');
117  }
118 
119  echo "</td>";
120 
121  if ($write_access) {
122  echo "<td>";
123  check_box($prefix.'_filters['.$filter_name.'][delete]');
124  echo "</td>";
125  }
126 
127  }//end foreach
128  ?>
129  </tr>
130 
131  </table>
132  <?php
133  if ($write_access) {
134  label("New events date filter", $prefix.'_new_events_date_filter_name');
135  echo '&nbsp;';
136  text_box($prefix.'_new_events_date_filter_name', '', 15);
137  }
138  return TRUE;
139 
140  }//end paintFields()
141 
142 
153  function processEventsDateFilters(&$asset, &$o, $prefix)
154  {
155  $old_filters = $asset->attr('events_filters');
156 
157  $new_filters = Array();
158 
159  if (isset($_POST[$prefix.'_filters'])) {
160  foreach ($_POST[$prefix.'_filters'] as $filter_name => $filter) {
161  if (!isset($filter['delete'])) {
162  $new_filters[$filter_name]['name'] = $old_filters[$filter_name]['name'];
163 
164  if (isset($filter['type']) && $filter['type'] != 'none') {
165  $new_filters[$filter_name]['type'] = $filter['type'];
166  unset($new_filters[$filter_name]['fuzzy_options']);
167  } else {
168  if (isset($old_filters[$filter_name]['type'])) {
169  $new_filters[$filter_name]['type'] = $old_filters[$filter_name]['type'];
170  if (isset($filter['fuzzy_options'])) {
171  $new_filters[$filter_name]['fuzzy_options'] = $filter['fuzzy_options'];
172  }
173  }//end if
174  }
175  $new_filters[$filter_name]['use_picker'] = isset($filter['use_picker']) ? TRUE : FALSE;
176 
177  }//end if
178  }//end foreach
179  }//end if
180 
181  if (!empty($_POST[$prefix.'_new_events_date_filter_name'])) {
182  $safe_name = strtolower(str_replace(' ', '_', $_POST[$prefix.'_new_events_date_filter_name']));
183 
184  // If filter already exists, don't overwrite it
185  if (!isset($old_filters[$safe_name])) {
186  $new_filters[$safe_name]['name'] = $_POST[$prefix.'_new_events_date_filter_name'];
187  $new_filters[$safe_name]['use_picker'] = TRUE;
188  }
189  }
190 
191  return $asset->setAttrValue('events_filters', $new_filters);
192 
193  }//end processFields()
194 
195 
196 //-- SAVED SEARCH --//
197 
198 
209  function paintSavedSearch(&$asset, &$o, $prefix)
210  {
211  // Not much extra functionality here, just need to add the search fields to the _params
212  // of parameter map, then show the results
213  $wa = $asset->writeAccess('attributes');
214  $pmap = $asset->getAttribute('stored_query_session');
215  $current_params = $pmap->_params;
216  // Add in the search fields
217  $fields = $asset->attr('fields');
218  foreach ($fields as $fieldname => $fieldvalue) {
219  $current_params['parameters'][$fieldname] = 'Search Field: '.$fieldname;
220  }
221  // Add in the date filters
222  $fields = $asset->attr('events_filters');
223  foreach ($fields as $fieldname => $fieldvalue) {
224  $current_params['parameters']['f:'.$fieldname] = 'Date Filter: '.$fieldname;
225  }
226  $pmap->_params = $current_params;
227  if ($wa) {
228  $pmap->paint($prefix);
229  } else {
230  $pmap->paint($prefix, TRUE);
231  }
232 
233  }//end paintSavedSearch()
234 
235 
236 }//end class
237 ?>