diff --git views_savedsearches.info views_savedsearches.info index aba78ad..18820d4 100644 --- views_savedsearches.info +++ views_savedsearches.info @@ -3,10 +3,14 @@ name = Saved searches description = Allows users to save their current configuration of exposed filters for later use. dependencies[] = views package = Views -core = 6.x +core = 7.x + +files[] = views_savedsearches.install +files[] = views_savedsearches.module + ; Information added by drupal.org packaging script on 2010-01-18 -version = "6.x-1.0-beta3" -core = "6.x" +version = "7.x-1.0-dev" +core = "7.x" project = "views_savedsearches" datestamp = "1263825607" diff --git views_savedsearches.install views_savedsearches.install index 005596b..5722967 100644 --- views_savedsearches.install +++ views_savedsearches.install @@ -2,13 +2,21 @@ // $Id: views_savedsearches.install,v 1.4 2010/01/14 13:48:24 aronnovak Exp $ /** + * @file + * This module allows you to save your current configuration of exposed + * filters for later use. This can be especially useful for Views with a lot + * of exposed filters. + * + */ + +/** * Implementation of hook_schema(). */ function views_savedsearches_schema() { $schema['views_savedsearches'] = array( 'fields' => array( 'sid' => array( - 'type' => 'int', + 'type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE, ), @@ -22,6 +30,12 @@ function views_savedsearches_schema() { 'unsigned' => TRUE, 'not null' => TRUE, ), + 'view_name' => array( + 'type' => 'varchar', + 'length' => '32', + 'default' => '', + 'not null' => FALSE, + ), 'display' => array( 'type' => 'varchar', 'length' => '32', @@ -53,7 +67,7 @@ function views_savedsearches_update_6101() { * Implementation of hook_install(). */ function views_savedsearches_install() { - drupal_install_schema('views_savedsearches'); + // drupal_install_schema('views_savedsearches'); } /** diff --git views_savedsearches.js views_savedsearches.js index 0280fc2..7485f4a 100644 --- views_savedsearches.js +++ views_savedsearches.js @@ -1,90 +1,94 @@ // $Id: views_savedsearches.js,v 1.5 2009/12/18 15:28:45 aronnovak Exp $ -var ViewsSavedSearches = ViewsSavedSearches || {}; +(function ($) { + var ViewsSavedSearches = ViewsSavedSearches || {}; -ViewsSavedSearches.baseContext = function() { - var $baseContext; + ViewsSavedSearches.baseContext = function() { + var $baseContext; - if (undefined === $baseContext) { - $baseContext = $("div.views-savedsearches-container"); - } - return $baseContext; -}; + if (undefined === $baseContext) { + $baseContext = $("div.views-savedsearches-container"); + } + return $baseContext; + }; -ViewsSavedSearches.attachBindings = function() { - var view_name; - var i; + ViewsSavedSearches.attachBindings = function() { + var view_name; + var i; - for (i = 0; i < Drupal.settings.views_savedsearches.view_names.length; i++) { - view_name = Drupal.settings.views_savedsearches.view_names[i]; + for (i = 0; i < Drupal.settings.views_savedsearches.view_names.length; i++) { + view_name = Drupal.settings.views_savedsearches.view_names[i]; - // Attach the bindings. - ViewsSavedSearches.bindings(view_name); - } -} - -ViewsSavedSearches.bindings = function(view_name) { - function ahahDeleteBeforeSubmit(formData, jqForm, options) { - // Validate checkboxes: at least one must be checked. - if ($('div#view-'+ view_name +'-savedsearches-container div.views-savedsearches-list-ahah form:first :checkbox[@checked]').length == 0) { - alert("You must select at least one saved search to be deleted!"); - return false; + // Attach the bindings. + ViewsSavedSearches.bindings(view_name); } - - // The form is validated, it will be submitted. Now let's add the form - // data of the views filters form, to be able to check if we should - // display the save form. - formData.push({ name: 'views_filters_form', value: $('form#views-filters').formSerialize() }); - - return true; } - function ahahSaveBeforeSubmit(formData, jqForm, options) { - var $name = $('div#view-'+ view_name +'-savedsearches-container div.views-savedsearches-save-ahah form:first input#edit-name'); + ViewsSavedSearches.bindings = function(view_name) { + function ahahDeleteBeforeSubmit(formData, jqForm, options) { + // Validate checkboxes: at least one must be checked. + if ($('div#view-'+ view_name +'-savedsearches-container div.views-savedsearches-list-ahah form:first :checkbox[@checked]').length == 0) { + alert(Drupal.t("You must select at least one saved search to be deleted!")); + return false; + } - // Validate the name field. - if ($name.fieldValue()[0].length == 0 || $name.fieldValue()[0].length > 30 ) { - alert("You must enter a name for this saved search (maximum 30 characters)!"); - return false; + // The form is validated, it will be submitted. Now let's add the form + // data of the views filters form, to be able to check if we should + // display the save form. + formData.push({ name: 'views_filters_form', value: $('form#views-filters').formSerialize() }); + + return true; } - // The form is validated, it will be submitted. Now let's add the form - // data of the views filters form, to save it. - formData.push({ name: 'views_filters_form', value: $('.view-'+ view_name+ ' .view-filters form').formSerialize() }); + function ahahSaveBeforeSubmit(formData, jqForm, options) { + var $name = $('div#view-'+ view_name +'-savedsearches-container div.views-savedsearches-save-ahah form:first input#edit-name'); - return true; - } + // Validate the name field. + if ($name.fieldValue()[0].length == 0 || $name.fieldValue()[0].length > 30 ) { + alert(Drupal.t("You must enter a name for this saved search (maximum 30 characters)!")); + return false; + } - // The target container that will receive the updated filter.. - var container = $('div#view-'+ view_name +'-savedsearches-container').get(0); + // The form is validated, it will be submitted. Now let's add the form + // data of the views filters form, to save it. + formData.push({ name: 'views_filters_form', value: $('.view-'+ view_name+ ' .view-filters form').formSerialize() }); - // List (with delete saved search form). - var deleteOptions = { - url: Drupal.settings.views_savedsearches.paths.deletePath, - beforeSubmit: ahahDeleteBeforeSubmit, - target: container, - success: function(response, status) { - Drupal.attachBehaviors(container); + return true; } - }; - $('div#view-'+ view_name +'-savedsearches-container div.views-savedsearches-list-ahah form:first', ViewsSavedSearches.baseContext) - .ajaxForm(deleteOptions); + // The target container that will receive the updated filter.. + var container = $('div#view-'+ view_name +'-savedsearches-container').get(0); + + // List (with delete saved search form). + var deleteOptions = { + url: Drupal.settings.views_savedsearches.paths.deletePath, + beforeSubmit: ahahDeleteBeforeSubmit, + target: container, + success: function(response, status) { + Drupal.attachBehaviors(container); + } + }; + + $('div#view-'+ view_name +'-savedsearches-container div.views-savedsearches-list-ahah form:first', ViewsSavedSearches.baseContext) + .ajaxForm(deleteOptions); + + // Save search form. + var saveOptions = { + url: Drupal.settings.views_savedsearches.paths.savePath, + beforeSubmit: ahahSaveBeforeSubmit, + target: container, + success: function(response, status) { + Drupal.attachBehaviors(container); + } + }; + var saveForm = $('div#view-'+ view_name +'-savedsearches-container div.views-savedsearches-save-ahah form:first', ViewsSavedSearches.baseContext); + $('div#view-'+ view_name +'-savedsearches-container div.views-savedsearches-save-ahah form:first', ViewsSavedSearches.baseContext) + .ajaxForm(saveOptions); + } - // Save search form. - var saveOptions = { - url: Drupal.settings.views_savedsearches.paths.savePath, - beforeSubmit: ahahSaveBeforeSubmit, - target: container, - success: function(response, status) { - Drupal.attachBehaviors(container); + Drupal.behaviors.viewsSavedSearches = { + attach: function(context) { + ViewsSavedSearches.attachBindings(); } - }; - var saveForm = $('div#view-'+ view_name +'-savedsearches-container div.views-savedsearches-save-ahah form:first', ViewsSavedSearches.baseContext); - $('div#view-'+ view_name +'-savedsearches-container div.views-savedsearches-save-ahah form:first', ViewsSavedSearches.baseContext) - .ajaxForm(saveOptions); -} - -Drupal.behaviors.viewsSavedSearches = function(context) { - ViewsSavedSearches.attachBindings(); -} + } +})(jQuery); \ No newline at end of file diff --git views_savedsearches.module views_savedsearches.module index 6ed2fc8..cd3535d 100644 --- views_savedsearches.module +++ views_savedsearches.module @@ -34,10 +34,10 @@ function views_savedsearches_help($path, $arg) { switch ($path) { case 'admin/help#views_savedsearches': - $output = '

'. t("The Views Saved Searches module allows users to save their current configuration of exposed filters for later use.") .'

'; + $output = '

' . t("The Views Saved Searches module allows users to save their current configuration of exposed filters for later use.") . '

'; break; case 'admin/build/views/tools/saved-searches': - $output = '

'. t('Note: Apologies for the bizarre location of this settings form. We\'re working to place the options for saving exposed filter searches in the main view configuration screen.') .'

'; + $output = '

' . t('Note: Apologies for the bizarre location of this settings form. We\'re working to place the options for saving exposed filter searches in the main view configuration screen.') . '

'; break; } @@ -61,9 +61,9 @@ function views_savedsearches_menu() { 'access arguments' => array('access content'), 'type' => MENU_CALLBACK, ); - $items['admin/build/views/tools/saved-searches'] = array( - 'title' => t('Saved Searches'), - 'description' => t('Configure which views support the saved searches functionality.'), + $items['admin/structure/views/saved-searches'] = array( + 'title' => 'Saved Searches', + 'description' => 'Configure which views support the saved searches functionality.', 'page callback' => 'drupal_get_form', 'page arguments' => array('views_savedsearches_settings'), 'access arguments' => array('administer site configuration'), @@ -91,8 +91,17 @@ function views_savedsearches_theme() { /** * Implementation of hook_perm(). */ -function views_savedsearches_perm() { - return array('use views savedsearch'); +function views_savedsearches_permission() { + return array( + 'use views savedsearch' => array( + 'title' => t('Use views saved searches'), + 'description' => t('User is allowed to use saved searches.'), + ), + 'use all savedsearches' => array( + 'title' => t('Use all saved searches'), + 'description' => t('User is allowed to use and see other users\' saved searches'), + ), + ); } /** @@ -141,7 +150,7 @@ function views_savedsearches_settings() { /** * Implementation of hook_form_alter(). */ -function views_savedsearches_form_alter(&$form, $form_state, $form_id) { +function views_savedsearches_form_alter(&$form, &$form_state, $form_id) { // Delete all saved searches whenever an edited View is saved. if ($form_id == 'views_edit_view') { $form['#submit'] = '_views_savedsearches_views_edit_form_submit'; @@ -149,44 +158,49 @@ function views_savedsearches_form_alter(&$form, $form_state, $form_id) { } /** - * Implementation of hook_block(). +* Implements hook_block_info(). +*/ +function views_savedsearches_block_info() { + // List blocks. + $blocks = array(); + $blocks['views-savedsearches-per-user'] = array( + 'info' => t('My views saved searches'), + ); + + return $blocks; +} + +/** + * Implementation of hook_block_view(). */ -function views_savedsearches_block($op = 'list', $delta = 0, $edit = array()) { +function views_savedsearches_block_view($delta = '') { global $user; + $block = array(); - if ('list' == $op) { - $blocks = array(); - $blocks['views-savedsearches-per-user'] = array( - 'info' => t('My views saved searches'), - ); - return $blocks; - } - elseif ('view' == $op) { - $block = array(); - switch ($delta) { - case 'views-savedsearches-per-user': - $uid = (arg(0) == 'user' && is_numeric(arg(1))) ? arg(1) : $user->uid; - $saved_searches = views_savedsearches_load_multiple($uid, 1); - foreach ($saved_searches as $sid => $saved_search) { - if (!empty($saved_search->display)) { - $query = _views_savedsearches_filters_to_params($saved_search->filters); - $view = views_get_view($saved_search->vid); - if (isset($view->display[$saved_search->display]->display_options['path'])) { - $path = $view->display[$saved_search->display]->display_options['path']; - if (!empty($path)) { - $items[] = l($saved_search->name, $path, array('query' => $query)); - } + switch ($delta) { + case 'views-savedsearches-per-user': + $uid = (arg(0) == 'user' && is_numeric(arg(1))) ? arg(1) : $user->uid; + $saved_searches = views_savedsearches_load_multiple($uid, 1); + $items = array(); + foreach ($saved_searches as $sid => $saved_search) { + if (!empty($saved_search->display)) { + $query = _views_savedsearches_filters_to_params($saved_search->filters); + $view = views_get_view($saved_search->vid); + if (isset($view->display[$saved_search->display]->display_options['path'])) { + $path = $view->display[$saved_search->display]->display_options['path']; + if (!empty($path)) { + $items[] = l($saved_search->name, $path, array('query' => $query)); } } } - if (count($items) > 0) { - $block = array('subject' => 'My saved searches', 'content' => theme('item_list', $items)); - } + } + if (count($items) > 0) { + $block = array('subject' => 'My saved searches', 'content' => theme('item_list', $items)); + } - break; - } - return $block; + break; } + return $block; } //---------------------------------------------------------------------------- @@ -203,8 +217,8 @@ function views_savedsearches_views_pre_view(&$view) { } $output = ''; - $output .= '
'; - $output .= theme('views_savedsearches_container', drupal_clone($view), $_GET); + $output .= '
'; + $output .= theme('views_savedsearches_container', array('view' => $view, 'views_filters_form_values' => $_GET)); $output .= '
'; if (!variable_get('clean_url', FALSE)) { @@ -222,10 +236,11 @@ function views_savedsearches_views_pre_view(&$view) { /** * Form building callback; the form used to save a search. */ -function views_savedsearches_save_search_form($form_state, $view) { +function views_savedsearches_save_search_form($form, $form_state, $view) { // Save some properties about the current view. $form['variables']['#tree'] = TRUE; - $form['variables']['vid'] = array('#type' => 'hidden', '#value' => $view->vid); + $form['variables']['vid'] = array('#type' => 'hidden', '#value' => ($view->vid > 0 ? $view->vid : 0)); + $form['variables']['view_name'] = array('#type' => 'hidden', '#value' => $view->name); $form['variables']['display'] = array('#type' => 'hidden', '#value' => $view->current_display); // This is needed for the non-AHAH form submit. $form['variables']['exposed_filters'] = array('#type' => 'value', '#value' => serialize(_views_savedsearches_params_to_filters($view, $_GET))); @@ -252,9 +267,9 @@ function views_savedsearches_save_search_form($form_state, $view) { ); $params = $_GET; unset($params['q']); - foreach($params as $k => $v) { + foreach ($params as $k => $v) { if (!empty($k) && !empty($v)) { - $query[] = $k .'='. $v; + $query[] = $k . '=' . $v; } else { $query[]= $v; @@ -288,6 +303,7 @@ function views_savedsearches_save_search_form_submit($form, &$form_state) { $saved_search->sid = 'new'; $saved_search->uid = $user->uid; $saved_search->vid = $form_state['values']['variables']['vid']; + $saved_search->view_name = $form_state['values']['variables']['view_name']; $saved_search->display = $form_state['values']['variables']['display']; $saved_search->name = $form_state['values']['name']; $saved_search->filters = $form_state['values']['variables']['exposed_filters']; @@ -295,12 +311,13 @@ function views_savedsearches_save_search_form_submit($form, &$form_state) { views_savedsearches_save($saved_search); drupal_set_message(t("Your %name search was saved!", array('%name' => $saved_search->name))); + } /** * Form building callback; the form to delete a search. */ -function views_savedsearches_delete_search_form($form_state, $view, $options) { +function views_savedsearches_delete_search_form($form, $form_state, $view, $options) { // Save some properties about the current view. $form['variables']['#tree'] = TRUE; $form['variables']['vid'] = array('#type' => 'hidden', '#value' => $view->vid); @@ -315,7 +332,7 @@ function views_savedsearches_delete_search_form($form_state, $view, $options) { '#type' => 'checkboxes', '#options' => $options, '#attributes' => array( - 'class' => 'form-checkboxes-horizontal', + 'class' => array('form-checkboxes-horizontal'), ), ); @@ -354,6 +371,7 @@ function views_savedsearches_delete_search_form_submit($form, &$form_state) { */ function views_savedsearches_ahah($action) { $vid = $_POST['variables']['vid']; + $view_name = $_POST['variables']['view_name']; $views_filters_form_values = array(); parse_str($_POST['views_filters_form'], $views_filters_form_values); @@ -381,7 +399,7 @@ function views_savedsearches_ahah($action) { $output = ''; $output .= theme('status_messages'); - $output .= theme('views_savedsearches_container', $view, $views_filters_form_values); + $output .= theme('views_savedsearches_container', array('view' => $view, 'views_filters_form_values' => $views_filters_form_values)); print $output; exit; @@ -403,8 +421,13 @@ function views_savedsearches_load($sid) { $saved_search = new StdClass(); $saved_search->sid = $sid; - $result = db_query("SELECT * FROM {views_savedsearches} WHERE sid = %d", $sid); - $obj = db_fetch_object($result); + $result = db_select('views_savedsearches', 'vss') + ->fields('vss', array('sid', 'uid', 'vid', 'view_name', 'display', 'name', 'filters')) + ->condition('sid', $sid) + ->orderBy('name', 'DESC') + ->execute(); + + $obj = $result->fetchObject(); if (is_object($obj)) { $saved_search = $obj; $saved_search->filters = unserialize($saved_search->filters); @@ -422,26 +445,31 @@ function views_savedsearches_load($sid) { * @return * An array of saved search objects. */ -function views_savedsearches_load_multiple($uid = NULL, $vid = NULL) { +function views_savedsearches_load_multiple($uid = NULL, $vid = NULL, $view_name = '') { $saved_searches = array(); - $query = 'SELECT sid FROM {views_savedsearches} '; - $sort = ' ORDER BY name'; + $query = db_select('views_savedsearches', 'vss') + ->fields('vss', array('sid')) + ->orderBy('name', 'DESC'); if ($uid > 0 && $vid > 0) { - $result = db_query("$query WHERE uid = %d AND vid = %d $sort", $uid, $vid); + $query->condition('uid', $uid); + $query->condition('vid', $vid); } elseif ($uid > 0) { - $result = db_query("$query WHERE uid = %d $sort", $uid); + $query->condition('uid', $uid); } elseif ($vid > 0) { - $result = db_query("$query WHERE vid = %d $sort", $vid); + $query->condition('vid', $vid); } - else { - $result = db_query($query . $sort); + + if (isset($view_name) && $view_name != '') { + $query->condition('view_name', $view_name); } - while ($row = db_fetch_object($result)) { + $result = $query->execute(); + + foreach ($result as $row) { $saved_searches[$row->sid] = views_savedsearches_load($row->sid); } return $saved_searches; @@ -486,10 +514,16 @@ function views_savedsearches_count($uid = NULL, $vid = NULL) { function views_savedsearches_delete($sid) { if (function_exists('notifications_delete_subscriptions') && module_exists('notifications_views_savedsearches')) { notifications_delete_subscriptions(array('type' => 'savedsearch'), array('sid' => $sid)); - db_query("DELETE FROM {notifications_views_savedsearches} WHERE sid = %d", $sid); - db_query("DELETE FROM {notifications_views_savedsearches_seen} WHERE sid = %d", $sid); - } - db_query("DELETE FROM {views_savedsearches} WHERE sid = %d", $sid); + db_delete('notifications_views_savedsearches') + ->condition('sid', $sid) + ->execute(); + db_delete('notifications_views_savedsearches_seen') + ->condition('sid', $sid) + ->execute(); + } + db_delete('views_savedsearches') + ->condition('sid', $sid) + ->execute(); } /** @@ -500,25 +534,34 @@ function views_savedsearches_delete($sid) { * @return * A saved search id. */ + + // TODO: Werkt niet met views in code! + function views_savedsearches_save($saved_search) { if ($saved_search->sid && $saved_search->sid != 'new') { - db_query("UPDATE {views_savedsearches} SET uid = %d, vid = %d, name = '%s', filters = '%s' WHERE sid = %d", - $saved_search->uid, - $saved_search->vid, - $saved_search->name, - $saved_search->sid - ); + db_update('views_savedsearches') + ->fields(array( + 'uid' => $saved_search->uid, + 'vid' => $saved_search->vid, + 'view_name' => $saved_search->view_name, + 'name' => $saved_search->name, + 'filters' => $saved_search->filters, + )) + ->condition('sid', $saved_search->sid) + ->execute(); } else { - $saved_search->sid = db_result(db_query('select MAX(sid) + 1 from {views_savedsearches}')); - db_query("INSERT INTO {views_savedsearches} (sid, uid, vid, display, name, filters) VALUES(%d, %d, %d, '%s', '%s', '%s')", - $saved_search->sid, - $saved_search->uid, - $saved_search->vid, - $saved_search->display, - $saved_search->name, - $saved_search->filters - ); + $saved_search->sid = + db_insert('views_savedsearches') + ->fields(array( + 'uid' => $saved_search->uid, + 'vid' => $saved_search->vid, + 'view_name' => $saved_search->view_name, + 'display' => $saved_search->display, + 'name' => $saved_search->name, + 'filters' => $saved_search->filters, + )) + ->execute(); } return $saved_search->sid; } @@ -535,7 +578,16 @@ function views_savedsearches_sid_by_filters($filters) { $sid = FALSE; if (count($filters)) { - $sid = db_result(db_query("SELECT sid FROM {views_savedsearches} WHERE filters = '%s'", serialize($filters))); + $result = db_select('views_savedsearches', 'vss') + ->fields('vss', array('sid')) + ->condition('filters', serialize($filters)) + ->range(0, 1) + ->execute(); + + foreach ($result as $row) { + $sid = $row->sid; + } + } return ($sid === FALSE ? -1 : $sid); } @@ -548,7 +600,6 @@ function views_savedsearches_sid_by_filters($filters) { * Form submission callback; for the views_edit_view form. */ function _views_savedsearches_views_edit_form_submit(&$form, &$form_values) { - dsm($form_values); db_query("DELETE FROM {views_savedsearches} WHERE vid = %d", $form_values['vid']); } @@ -562,46 +613,18 @@ function _views_savedsearches_views_edit_form_submit(&$form, &$form_values) { * A GET query. */ function _views_savedsearches_filters_to_params($filters) { - $query = ''; + $query = array(); if (is_array($filters)) { foreach ($filters as $filter_name => $filter_value) { - // Distinction between multiple-value filters and single-value filters. - if (is_array($filter_value)) { - foreach ($filter_value as $key => $value) { - if (strlen($query) > 0) { - $query .= '&'; - } - if (!is_array($value)) { - $query .= drupal_urlencode($filter_name) . drupal_urlencode('[]') .'='. drupal_urlencode($value); - } - else { - // Date-style parameter, like date_filter[value][date]=2009-05-11 in the URL encoded - $arr = drupal_urlencode('['. $key .']'); - $open = drupal_urlencode('['); - $close = drupal_urlencode(']'); - foreach ($value as $k => $v) { - if (strlen($query) > 0) { - $query .= '&'; - } - $query .= $filter_name . $arr . $open . $k . $close . '=' . $v; - } - } - } - } - else { - if (strlen($query) > 0) { - $query .= '&'; - } - $query .= drupal_urlencode($filter_name) .'='. drupal_urlencode($filter_value); - } + $query[$filter_name] = $filter_value; } } return $query; } /** - * Helper function; deconstructs a params string from to an array of filters. + * Helper function; deconstructs a params string to an array of filters. * * @param $params * Am array of current parameters in the query string. @@ -637,7 +660,7 @@ function _views_savedsearches_configure_ahah($view_name) { if (!isset($required_things_added)) { drupal_add_js('misc/jquery.form.js'); drupal_add_js('misc/collapse.js', 'theme'); - drupal_add_js(drupal_get_path('module', 'views_savedsearches') .'/views_savedsearches.js', 'module'); + drupal_add_js(drupal_get_path('module', 'views_savedsearches') . '/views_savedsearches.js', 'module'); drupal_add_js( array( 'views_savedsearches' => array( @@ -689,7 +712,7 @@ function _views_savedsearches_saved_searches_to_form_options($saved_searches, $v // If this saved search is active, mark it with a class. $class = ($sid == $current_view_matches_sid) ? 'views-savedsearches-is-active' : ''; - $options[$sid] = l($saved_search->name, $view_url, array('attributes' => array('class' => $class), 'query' => $query)); + $options[$sid] = l($saved_search->name, $view_url, array('attributes' => array('class' => array($class)), 'query' => $query)); } } return $options; @@ -710,26 +733,28 @@ function _views_savedsearches_saved_searches_to_form_options($saved_searches, $v * found in $_GET (normal forms) or in $_POST['views_filters_form'] (AHAH * forms). */ -function theme_views_savedsearches_container($view, $views_filters_form_values) { +function theme_views_savedsearches_container($variables) { + $view = $variables['view']; + $views_filters_form_values = $variables['views_filters_form_values']; $output = ''; // Add JS necessary for adding AHAH. _views_savedsearches_configure_ahah($view->name); // Add the CSS and see if the current view matches a sid. - drupal_add_css(drupal_get_path('module', 'views_savedsearches') .'/views_savedsearches.css', 'module'); + drupal_add_css(drupal_get_path('module', 'views_savedsearches') . '/views_savedsearches.css', 'module'); $view_filters = _views_savedsearches_params_to_filters($view, $views_filters_form_values); $current_view_matches_sid = views_savedsearches_sid_by_filters($view_filters); // The list (also delete saved search form). $output .= '
'; - $output .= theme('views_savedsearches_list', $view, $current_view_matches_sid); + $output .= theme('views_savedsearches_list', array('view' => $view, 'current_view_matches_sid' => $current_view_matches_sid)); $output .= '
'; // The save search form. $output .= '
'; if ($current_view_matches_sid == -1 && count($view_filters)) { - $output .= drupal_get_form('views_savedsearches_save_search_form', $view); + $output .= drupal_render(drupal_get_form('views_savedsearches_save_search_form', $view)); } $output .= '
'; @@ -744,22 +769,28 @@ function theme_views_savedsearches_container($view, $views_filters_form_values) * @param $current_view_matches_sid * The saved search id that matches the current view. */ -function theme_views_savedsearches_list($view, $current_view_matches_sid) { +function theme_views_savedsearches_list($variables) { global $user; - + $view = $variables['view']; + $current_view_matches_sid = $variables['current_view_matches_sid']; $output = ''; // Load saved searches for the current user, to use them as form options. - $saved_searches = views_savedsearches_load_multiple($user->uid, $view->vid); + if(user_access('use all savedsearches')){ + $saved_searches = views_savedsearches_load_multiple(NULL, $view->vid, $view->name); + } + else{ + $saved_searches = views_savedsearches_load_multiple($user->uid, $view->vid, $view->name); + } $options = _views_savedsearches_saved_searches_to_form_options($saved_searches, $view->get_path(), $current_view_matches_sid); // Display a list of saved searches (if there are any) and allow the user to // delete any of them. if (count($options)) { - $output .= drupal_get_form('views_savedsearches_delete_search_form', $view, $options, $current_view_matches_sid); + $output .= drupal_render(drupal_get_form('views_savedsearches_delete_search_form', $view, $options, $current_view_matches_sid)); } else { - $output .= '

'. t('No saved searches found for this view.') .'

'; + $output .= '

' . t('No saved searches found for this view.') . '

'; } return $output;