Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function sb_print_filters($filter, $translate_book = FALSE) {
- global $wpdb, $sermon_domain, $more_applied, $filter_options;
- $hide_filter = FALSE;
- if ($filter['filterhide'] == 'hide') {
- $hide_filter = TRUE;
- $js_hide = "
- var filter_visible = false;
- jQuery('#mainfilter').hide();
- jQuery('#show_hide_filter').text('[ SHOW ]');
- jQuery('#show_hide_filter').click(function() {
- jQuery('#mainfilter:visible').slideUp('slow');
- jQuery('#mainfilter:hidden').slideDown('slow');
- if (filter_visible) {
- jQuery('#show_hide_filter').text('[ SHOW ]');
- filter_visible = false;
- } else {
- jQuery('#show_hide_filter').text('[ HIDE ]');
- filter_visible = true;
- }
- return false;
- });";
- $js_hide = str_replace ('SHOW', __('Show filter', $sermon_domain), $js_hide);
- $js_hide = str_replace ('HIDE', __('Hide filter', $sermon_domain), $js_hide);
- }
- if ($filter['filter'] == 'oneclick') {
- // One click filter
- $hide_custom_podcast = true;
- $filter_options = array ('preacher', 'book', 'service', 'series', 'date', 'enddate', 'title');
- $output = '';
- foreach ($filter_options AS $filter_option)
- if (isset($_REQUEST[$filter_option])) {
- if ($filter_option != 'enddate') {
- if ($output != '')
- $output .= "\r, ";
- if ($filter_option == 'date') {
- $output .= '<strong>Date</strong>: ';
- if (substr($_REQUEST['date'],0,4) == substr($_REQUEST['enddate'],0,4))
- $output .= substr($_REQUEST['date'],0,4).' (<a href="'.sb_url_minus_parameter('date', 'enddate').'">x</a>)';
- if (substr($_REQUEST['date'],5,2) == substr($_REQUEST['enddate'],5,2))
- $output .= ', '.strftime('%B', strtotime($_REQUEST['date'])).' (<a href="'.sb_build_url(Array ('date' => substr($_REQUEST['date'],0,4).'-01-01', 'enddate' => substr($_REQUEST['date'],0,4).'-12-31')).'">x</a>)';
- } else {
- $output .= '<strong>'.ucwords($filter_option).'</strong>: *'.$filter_option.'*';
- $output .= ' (<a href="'.sb_url_minus_parameter($filter_option).'">x</a>)';
- }
- }
- $hide_custom_podcast = FALSE;
- }
- $hide_empty = sb_get_option('hide_no_attachments');
- $sermons=sb_get_sermons($filter, array(), 1, 99999, $hide_empty);
- $ids = array();
- foreach ($sermons as $sermon)
- $ids[] = $sermon->id;
- $ids = "('".implode ("', '", $ids)."')";
- $preachers = $wpdb->get_results("SELECT p.*, count(p.id) AS count FROM {$wpdb->prefix}sb_preachers AS p JOIN {$wpdb->prefix}sb_sermons AS sermons ON p.id = sermons.preacher_id WHERE sermons.id IN {$ids} GROUP BY p.id ORDER BY count DESC, sermons.datetime DESC");
- $series = $wpdb->get_results("SELECT ss.*, count(ss.id) AS count FROM {$wpdb->prefix}sb_series AS ss JOIN {$wpdb->prefix}sb_sermons AS sermons ON ss.id = sermons.series_id WHERE sermons.id IN {$ids} GROUP BY ss.id ORDER BY sermons.datetime DESC");
- $services = $wpdb->get_results("SELECT s.*, count(s.id) AS count FROM {$wpdb->prefix}sb_services AS s JOIN {$wpdb->prefix}sb_sermons AS sermons ON s.id = sermons.service_id WHERE sermons.id IN {$ids} GROUP BY s.id ORDER BY count DESC");
- $book_count = $wpdb->get_results("SELECT bs.book_name AS name, count(distinct bs.sermon_id) AS count FROM {$wpdb->prefix}sb_books_sermons AS bs JOIN {$wpdb->prefix}sb_books as b ON bs.book_name=b.name AND bs.sermon_id IN {$ids} GROUP BY b.id");
- $dates = $wpdb->get_results("SELECT YEAR(datetime) as year, MONTH (datetime) as month, DAY(datetime) as day FROM {$wpdb->prefix}sb_sermons WHERE id IN {$ids} ORDER BY datetime ASC");
- $more_applied = array();
- $output = str_replace ('*preacher*', isset($preachers[0]->name) ? $preachers[0]->name : '', $output);
- $output = str_replace ('*book*', isset($_REQUEST['book']) ? htmlentities($_REQUEST['book']) : '', $output);
- $output = str_replace ('*service*', isset($services[0]->name) ? $services[0]->name : '', $output);
- $output = str_replace ('*series*', isset($series[0]->name) ? $series[0]->name : '', $output);
- echo "<span class=\"inline_controls\"><a href=\"#\" id=\"show_hide_filter\"></a></span>";
- if ($output != '')
- echo '<div class="filtered">'.__('Active filter', $sermon_domain).': '.$output."</div>\r";
- echo '<div id="mainfilter">';
- if (count($preachers) > 1)
- sb_print_filter_line ('preacher', $preachers, 'id', 'name', 7);
- if (count($book_count) > 1)
- sb_print_filter_line ('book', $book_count, 'name', 'name', 10, $translate_book);
- if (count($series) > 1)
- sb_print_filter_line ('series', $series, 'id', 'name', 10);
- if (count($services) > 1)
- sb_print_filter_line ('service', $services, 'id', 'name', 10);
- sb_print_date_filter_line ($dates);
- echo "</div>\r";
- if (count($more_applied) > 0 | $output != '' | $hide_custom_podcast === TRUE | $hide_filter === TRUE) {
- echo "<script type=\"text/javascript\">\r";
- echo "\tjQuery(document).ready(function() {\r";
- if ($hide_filter === TRUE)
- echo $js_hide."\r";
- if ($hide_custom_podcast === TRUE)
- echo "\t\tjQuery('.podcastcustom').hide();\r";
- if (count($more_applied) > 0) {
- foreach ($more_applied as $element_id) {
- echo "\t\tjQuery('#{$element_id}-more').hide();\r";
- echo "\t\tjQuery('#{$element_id}-more-link').show();\r";
- echo "\t\tjQuery('a#{$element_id}-toggle').click(function() {\r";
- echo "\t\t\tjQuery('#{$element_id}-more').show();\r";
- echo "\t\t\tjQuery('#{$element_id}-more-link').hide();\r";
- echo "\t\t\treturn false;\r";
- echo "\t\t});\r";
- }
- }
- echo "\t});\r";
- echo "</script>\r";
- }
- } elseif ($filter['filter'] == 'dropdown') {
- // Drop-down filter
- if ($translate_book) {
- $translated_books = array_combine(sb_get_default('eng_bible_books'), sb_get_default('bible_books'));
- }
- $preachers = $wpdb->get_results("SELECT p.*, count(p.id) AS count FROM {$wpdb->prefix}sb_preachers AS p JOIN {$wpdb->prefix}sb_sermons AS s ON p.id = s.preacher_id GROUP BY p.id ORDER BY count DESC, s.datetime DESC");
- $series = $wpdb->get_results("SELECT ss.*, count(ss.id) AS count FROM {$wpdb->prefix}sb_series AS ss JOIN {$wpdb->prefix}sb_sermons AS sermons ON ss.id = sermons.series_id GROUP BY ss.id ORDER BY sermons.datetime DESC");
- $services = $wpdb->get_results("SELECT s.*, count(s.id) AS count FROM {$wpdb->prefix}sb_services AS s JOIN {$wpdb->prefix}sb_sermons AS sermons ON s.id = sermons.service_id GROUP BY s.id ORDER BY count DESC");
- $book_count = $wpdb->get_results("SELECT bs.book_name AS name, count(distinct bs.sermon_id) AS count FROM {$wpdb->prefix}sb_books_sermons AS bs JOIN {$wpdb->prefix}sb_books AS b ON bs.book_name = b.name GROUP BY b.id");
- $sb = array(
- 'Title' => 'm.title',
- 'Preacher' => 'preacher',
- 'Date' => 'm.datetime',
- 'Passage' => 'b.id',
- );
- $di = array(
- 'Ascending' => 'asc',
- 'Descending' => 'desc',
- );
- $csb = isset($_REQUEST['sortby']) ? $_REQUEST['sortby'] : 'm.datetime';
- $cd = isset($_REQUEST['dir']) ? $_REQUEST['dir'] : 'desc';
- ?>
- <span class="inline_controls"><a href="#" id="show_hide_filter"></a></span>
- <div id="mainfilter">
- <form method="post" id="sermon-filter" action="<?php echo sb_display_url(); ?>">
- <div style="clear:both">
- <table class="sermonbrowser">
- <tr>
- <td class="fieldname"><?php _e('Preacher', $sermon_domain) ?></td>
- <td class="field"><select name="preacher" id="preacher">
- <option value="0" <?php echo (isset($_REQUEST['preacher']) && $_REQUEST['preacher'] != 0) ? '' : 'selected="selected"' ?>><?php _e('[All]', $sermon_domain) ?></option>
- <?php foreach ($preachers as $preacher): ?>
- <option value="<?php echo $preacher->id ?>" <?php echo isset($_REQUEST['preacher']) && $_REQUEST['preacher'] == $preacher->id ? 'selected="selected"' : '' ?>><?php echo stripslashes($preacher->name).' ('.$preacher->count.')' ?></option>
- <?php endforeach ?>
- </select>
- </td>
- <td class="fieldname rightcolumn"><?php _e('Services', $sermon_domain) ?></td>
- <td class="field"><select name="service" id="service">
- <option value="0" <?php echo isset($_REQUEST['service']) && $_REQUEST['service'] != 0 ? '' : 'selected="selected"' ?>><?php _e('[All]', $sermon_domain) ?></option>
- <?php foreach ($services as $service): ?>
- <option value="<?php echo $service->id ?>" <?php echo isset($_REQUEST['service']) && $_REQUEST['service'] == $service->id ? 'selected="selected"' : '' ?>><?php echo stripslashes($service->name).' ('.$service->count.')' ?></option>
- <?php endforeach ?>
- </select>
- </td>
- </tr>
- <tr>
- <td class="fieldname"><?php _e('Book', $sermon_domain) ?></td>
- <td class="field"><select name="book">
- <option value=""><?php _e('[All]', $sermon_domain) ?></option>
- <?php if ($translate_book) { ?>
- <?php foreach ($book_count as $book): ?>
- <option value="<?php echo $book->name ?>" <?php echo isset($_REQUEST['book']) && $_REQUEST['book'] == $book->name ? 'selected=selected' : '' ?>><?php echo $translated_books[stripslashes($book->name)]. ' ('.$book->count.')' ?></option>
- <?php endforeach ?>
- <?php }
- else { ?>
- <?php foreach ($book_count as $book): ?>
- <option value="<?php echo $book->name ?>" <?php echo isset($_REQUEST['book']) && $_REQUEST['book'] == $book->name ? 'selected=selected' : '' ?>><?php echo stripslashes($book->name). ' ('.$book->count.')' ?></option>
- <?php endforeach ?>
- <?php } ?>
- </select>
- </td>
- <td class="fieldname rightcolumn"><?php _e('Series', $sermon_domain) ?></td>
- <td class="field"><select name="series" id="series">
- <option value="0" <?php echo (isset($_REQUEST['series']) && $_REQUEST['series'] != 0) ? '' : 'selected="selected"' ?>><?php _e('[All]', $sermon_domain) ?></option>
- <?php foreach ($series as $item): ?>
- <option value="<?php echo $item->id ?>" <?php echo isset($_REQUEST['series']) && $_REQUEST['series'] == $item->id ? 'selected="selected"' : '' ?>><?php echo stripslashes($item->name).' ('.$item->count.')' ?></option>
- <?php endforeach ?>
- </select>
- </td>
- </tr>
- <tr>
- <td class="fieldname"><?php _e('Start date', $sermon_domain) ?></td>
- <td class="field"><input type="text" name="date" id="date" value="<?php echo isset($_REQUEST['date']) ? mysql_real_escape_string($_REQUEST['date']) : '' ?>" /></td>
- <td class="fieldname rightcolumn"><?php _e('End date', $sermon_domain) ?></td>
- <td class="field"><input type="text" name="enddate" id="enddate" value="<?php echo isset($_REQUEST['enddate']) ? mysql_real_escape_string($_REQUEST['enddate']) : '' ?>" /></td>
- </tr>
- <tr>
- <td class="fieldname"><?php _e('Keywords', $sermon_domain) ?></td>
- <td class="field" colspan="3"><input style="width: 98.5%" type="text" id="title" name="title" value="<?php echo isset($_REQUEST['title']) ? mysql_real_escape_string($_REQUEST['title']) : '' ?>" /></td>
- </tr>
- <tr>
- <td class="fieldname"><?php _e('Sort by', $sermon_domain) ?></td>
- <td class="field"><select name="sortby" id="sortby">
- <?php foreach ($sb as $k => $v): ?>
- <option value="<?php echo $v ?>" <?php echo $csb == $v ? 'selected="selected"' : '' ?>><?php _e($k, $sermon_domain) ?></option>
- <?php endforeach ?>
- </select>
- </td>
- <td class="fieldname rightcolumn"><?php _e('Direction', $sermon_domain) ?></td>
- <td class="field"><select name="dir" id="dir">
- <?php foreach ($di as $k => $v): ?>
- <option value="<?php echo $v ?>" <?php echo $cd == $v ? 'selected="selected"' : '' ?>><?php _e($k, $sermon_domain) ?></option>
- <?php endforeach ?>
- </select>
- </td>
- </tr>
- <tr>
- <td colspan="3"> </td>
- <td class="field"><input type="submit" class="filter" value="<?php _e('Filter »', $sermon_domain) ?>"> </td>
- </tr>
- </table>
- <input type="hidden" name="page" value="1">
- </div>
- </form>
- </div>
- <script type="text/javascript">
- jQuery.datePicker.setDateFormat('ymd','-');
- jQuery('#date').datePicker({startDate:'01/01/1970'});
- jQuery('#enddate').datePicker({startDate:'01/01/1970'});
- <?php if ($hide_filter === TRUE) { ?>
- jQuery(document).ready(function() {
- <?php echo $js_hide; ?>
- });
- <?php } ?>
- </script>
- <?php
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement