public function actionLoadSavedSearch($id, $redirectAction = 'list') { $savedSearch = SavedSearch::getById((int) $id); ControllerSecurityUtil::resolveAccessCanCurrentUserReadModel($savedSearch); $getParams = unserialize($savedSearch->serializedData); $getParams = array_merge($getParams, array('savedSearchId' => $id)); $url = Yii::app()->createUrl($this->getModule()->getId() . '/' . $this->getId() . '/' . $redirectAction, $getParams); $this->redirect($url); }
public function testGetByOwnerAndViewClassName() { $user = User::getByUsername('super'); $steven = User::getByUsername('steven'); $savedSearches = SavedSearch::getByOwnerAndViewClassName($user, 'someView'); $this->assertEquals(0, count($savedSearches)); $savedSearches = SavedSearch::getByOwnerAndViewClassName($steven, 'someView'); $this->assertEquals(0, count($savedSearches)); //create saved search for steven $savedSearch = new SavedSearch(); $savedSearch->owner = $steven; $savedSearch->name = 'Test Saved Search'; $savedSearch->serializedData = serialize(array('x', 'y')); $savedSearch->viewClassName = 'someView'; $this->assertTrue($savedSearch->save()); $savedSearches = SavedSearch::getByOwnerAndViewClassName($user, 'someView'); $this->assertEquals(0, count($savedSearches)); $savedSearches = SavedSearch::getByOwnerAndViewClassName($steven, 'someView'); $this->assertEquals(1, count($savedSearches)); $savedSearches = SavedSearch::getByOwnerAndViewClassName($steven, 'someView2'); $this->assertEquals(0, count($savedSearches)); }
protected function renderSavedSearchList() { $savedSearches = SavedSearch::getByOwnerAndViewClassName(Yii::app()->user->userModel, get_class($this)); $idOrName = static::getSavedSearchListDropDown(); $htmlOptions = array('id' => $idOrName, 'empty' => Zurmo::t('ZurmoModule', 'Load a saved search')); if (count($savedSearches) == 0) { $htmlOptions['style'] = "display:none;"; $htmlOptions['class'] = 'ignore-style'; $idOrName = static::getSavedSearchListDropDown(); $htmlOptions = array('id' => $idOrName, 'empty' => Zurmo::t('ZurmoModule', 'Load a saved search')); $content = ZurmoHtml::dropDownList($idOrName, $this->model->savedSearchId, self::resolveSavedSearchesToIdAndLabels($savedSearches), $htmlOptions); $this->renderSavedSearchDropDownOnChangeScript($idOrName, $this->model->loadSavedSearchUrl); return $content; } $content = ZurmoHtml::dropDownList($idOrName, $this->model->savedSearchId, self::resolveSavedSearchesToIdAndLabels($savedSearches), $htmlOptions); $this->renderSavedSearchDropDownOnChangeScript($idOrName, $this->model->loadSavedSearchUrl); return $content; }
public function testSaveNumericFields() { global $current_user; require_once 'modules/SavedSearch/SavedSearch.php'; $focus = new SavedSearch(); $focus->retrieve($this->saved_search_id); $_REQUEST = unserialize(base64_decode($focus->contents)); $_REQUEST['start_range_amount_advanced'] = '$9,500.00'; $_REQUEST['end_range_amount_advanced'] = '$49,500.00'; $mockBean = new Bug42915MockOpportunity(); $focus->handleSave('', false, '', $this->saved_search_id, $mockBean); //Now retrieve what we have saved and test $focus->retrieveSavedSearch($this->saved_search_id); $formatted_data = $focus->contents; $this->assertEquals(9500, $formatted_data['start_range_amount_advanced'], "Assert that value is unformatted value 9500"); $this->assertEquals(49500, $formatted_data['end_range_amount_advanced'], "Assert that value is unformatted value 49500"); $focus->populateRequest(); $this->assertEquals('$9,500.00', $_REQUEST['start_range_amount_advanced'], "Assert that value is formatted value \$9,500.00"); $this->assertEquals('$49,500.00', $_REQUEST['end_range_amount_advanced'], "Assert that value is formatted value \$49,500.00"); $current_user->setPreference('num_grp_sep', '.'); $current_user->setPreference('dec_sep', ','); $current_user->save(); //Force reset on dec_sep and num_grp_sep because the dec_sep and num_grp_sep values are stored as static variables get_number_seperators(true); $focus = new SavedSearch(); $focus->retrieveSavedSearch($this->saved_search_id); $focus->populateRequest(); $this->assertEquals('$9.500,00', $_REQUEST['start_range_amount_advanced'], "Assert that value is formatted value \$9,500.00"); $this->assertEquals('$49.500,00', $_REQUEST['end_range_amount_advanced'], "Assert that value is formatted value \$49,500.00"); //Okay so now what happens if they don't specify currency or separator or decimal values? $_REQUEST['start_range_amount_advanced'] = '9500'; $_REQUEST['end_range_amount_advanced'] = '49500'; //Well then the populated values should be unformatted! $focus->handleSave('', false, '', $this->saved_search_id, $mockBean); $focus->retrieveSavedSearch($this->saved_search_id); $focus->populateRequest(); $this->assertEquals(9500, $_REQUEST['start_range_amount_advanced'], "Assert that value is unformatted value 9500"); $this->assertEquals(49500, $_REQUEST['end_range_amount_advanced'], "Assert that value is unformatted value 49500"); }
public function testSuperUserAllDefaultControllerActions() { $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super'); $this->assertEquals(0, count(SavedSearch::getAll())); //Test a saved search that validates and passes //Test form that validates $this->setGetArray(array('viewClassName' => 'AccountsSearchView', 'modelClassName' => 'Account', 'formModelClassName' => 'AccountsSearchForm')); $this->setPostArray(array('ajax' => 'search-form', 'AccountsSearchForm' => array('savedSearchName' => 'a new name'), 'save' => 'saveSearch')); $this->runControllerWithExitExceptionAndGetContent('zurmo/default/validateDynamicSearch'); $savedSearches = SavedSearch::getAll(); $this->assertEquals(1, count($savedSearches)); $this->assertEquals('a new name', $savedSearches[0]->name); //Test loading saved search Yii::app()->user->setState('AccountsSearchView', null); $this->setGetArray(array('savedSearchId' => $savedSearches[0]->id)); $content = $this->runControllerWithNoExceptionsAndGetContent('accounts/default/list'); $id = $savedSearches[0]->id; $this->assertContains("<option value=\"{$id}\" selected=\"selected\">a new name</option>", $content); //Test deleting saved search $this->setGetArray(array('id' => $savedSearches[0]->id)); $this->resetPostArray(); $this->runControllerWithNoExceptionsAndGetContent('zurmo/default/deleteSavedSearch', true); $this->assertEquals(0, count(SavedSearch::getAll())); }
function handleSave($prefix, $redirect = true, $useRequired = false, $id = null, $searchModuleBean) { global $current_user, $timedate; $focus = new SavedSearch(); if ($id) { $focus->retrieve($id); } if ($useRequired && !checkRequired($prefix, array_keys($focus->required_fields))) { return null; } $ignored_inputs = array('PHPSESSID', 'module', 'action', 'saved_search_name', 'saved_search_select', 'advanced', 'Calls_divs', 'ACLRoles_divs'); $contents = $_REQUEST; if ($id == null) { $focus->name = $contents['saved_search_name']; } $focus->search_module = $contents['search_module']; foreach ($contents as $input => $value) { if (in_array($input, $ignored_inputs)) { unset($contents[$input]); continue; } //Filter date fields to ensure it is saved to DB format, but also avoid empty values if (!empty($value) && preg_match('/^(start_range_|end_range_|range_)?(.*?)(_advanced|_basic)$/', $input, $match)) { $field = $match[2]; if (isset($searchModuleBean->field_defs[$field]['type'])) { $type = $searchModuleBean->field_defs[$field]['type']; //Avoid macro values for the date types if (($type == 'date' || $type == 'datetime' || $type == 'datetimecombo') && !preg_match('/^\\[.*?\\]$/', $value)) { $db_format = $timedate->to_db_date($value, false); $contents[$input] = $db_format; } else { if ($type == 'int' || $type == 'currency' || $type == 'decimal' || $type == 'float') { if (preg_match('/[^\\d]/', $value)) { require_once 'modules/Currencies/Currency.php'; $contents[$input] = unformat_number($value); //Flag this value as having been unformatted $contents[$input . '_unformatted_number'] = true; //If the type is of currency and there was a currency symbol (non-digit), save the symbol if ($type == 'currency' && preg_match('/^([^\\d])/', $value, $match)) { $contents[$input . '_currency_symbol'] = $match[1]; } } else { //unset any flags if (isset($contents[$input . '_unformatted_number'])) { unset($contents[$input . '_unformatted_number']); } if (isset($contents[$input . '_currency_symbol'])) { unset($contents[$input . '_currency_symbol']); } } } } } } } $contents['advanced'] = true; $focus->contents = base64_encode(serialize($contents)); $focus->assigned_user_id = $current_user->id; $focus->new_schema = true; $saved_search_id = $focus->save(); $GLOBALS['log']->debug("Saved record with id of " . $focus->id); $orderBy = empty($contents['orderBy']) ? 'name' : $contents['orderBy']; $search_query = "&orderBy=" . $orderBy . "&sortOrder=" . $contents['sortOrder'] . "&query=" . $_REQUEST['query'] . "&searchFormTab=" . $_REQUEST['searchFormTab'] . '&showSSDIV=' . $contents['showSSDIV']; if ($redirect) { $this->handleRedirect($focus->search_module, $search_query, $saved_search_id, 'true'); } }
/** * This test captures the scenario for date_modified field where range search is not enabled */ public function testSaveDateFields() { require_once 'modules/SavedSearch/SavedSearch.php'; $focus = new SavedSearch(); $focus->retrieve($this->saved_search_id); $_REQUEST = unserialize(base64_decode($focus->contents)); unset($_REQUEST['start_range_date_modified_advanced']); unset($_REQUEST['end_range_date_modified_advanced']); unset($_REQUEST['range_date_modified_advanced']); $_REQUEST['date_modified_advanced'] = '07/03/2009'; //Special date :) $mockBean = new Bug42377MockOpportunity(); $focus->handleSave('', false, '', $this->saved_search_id, $mockBean); //Now retrieve what we have saved and test $focus = new SavedSearch(); $focus->retrieve($this->saved_search_id); $formatted_data = unserialize(base64_decode($focus->contents)); $this->assertEquals($formatted_data['date_modified_advanced'], '2009-07-03', "Assert that value is in db format ('2009-07-03')"); //Now test that when we populate the search form, we bring it back to user's date format $focus->retrieveSavedSearch($this->saved_search_id); $focus->populateRequest(); $this->assertEquals($_REQUEST['date_modified_advanced'], '07/03/2009', "Assert that dates in db format were converted back to user's date preference"); //Take this a step further, assume date format now changes, will date be populated correctly? global $current_user; $current_user->setPreference('datef', 'd/m/Y', 0, 'global'); $current_user->save(); //Now test that when we populate the search form, we bring it back to user's date format $focus->retrieveSavedSearch($this->saved_search_id); $focus->populateRequest(); $this->assertEquals($_REQUEST['date_modified_advanced'], '03/07/2009', "Assert that dates in db format were converted back to user's date preference"); }
/** * get the search buttons * * @return string html of contents */ function getButtons() { global $app_strings; $SAVED_SEARCHES_OPTIONS = ''; $savedSearch = new SavedSearch(); $SAVED_SEARCHES_OPTIONS = $savedSearch->getSelect($this->module); $str = "<input tabindex='2' title='{$app_strings['LBL_SEARCH_BUTTON_TITLE']}' accessKey='{$app_strings['LBL_SEARCH_BUTTON_KEY']}' onclick='SUGAR.savedViews.setChooser()' class='button' type='submit' name='button' value='{$app_strings['LBL_SEARCH_BUTTON_LABEL']}' id='search_form_submit'/> "; $str .= "<input tabindex='2' title='{$app_strings['LBL_CLEAR_BUTTON_TITLE']}' accessKey='{$app_strings['LBL_CLEAR_BUTTON_KEY']}' onclick='SUGAR.searchForm.clear_form(this.form); return false;' class='button' type='button' name='clear' value=' {$app_strings['LBL_CLEAR_BUTTON_LABEL']} ' id='search_form_clear'/>"; if (!empty($SAVED_SEARCHES_OPTIONS) && $this->showSavedSearchOptions) { $str .= " <span class='white-space'>\n | <b>{$app_strings['LBL_SAVED_SEARCH_SHORTCUT']}</b> \n {$SAVED_SEARCHES_OPTIONS}\n <span id='go_btn_span' style='display:none'><input tabindex='2' title='go_select' id='go_select' onclick='SUGAR.searchForm.clear_form(this.form);' class='button' type='button' name='go_select' value=' {$app_strings['LBL_GO_BUTTON_LABEL']} '/></span>\n </span>\n </form>"; } $str .= "\n <script>\n function toggleInlineSearch(){\n if (document.getElementById('inlineSavedSearch').style.display == 'none'){\n document.getElementById('showSSDIV').value = 'yes'\n document.getElementById('inlineSavedSearch').style.display = '';\n\n document.getElementById('up_down_img').src='" . SugarThemeRegistry::current()->getImageURL('basic_search.gif') . "';\n\n }else{\n\n document.getElementById('up_down_img').src='" . SugarThemeRegistry::current()->getImageURL('advanced_search.gif') . "';\n\n document.getElementById('showSSDIV').value = 'no';\n document.getElementById('inlineSavedSearch').style.display = 'none';\n }\n }\n\n\n </script>\n "; return $str; }
/** * @param array $stickyData * @param SavedDynamicSearchForm $model * @internal param $sourceData */ public static function resolveSearchFormByStickyDataAndModel($stickyData, SavedDynamicSearchForm $model) { assert('$stickyData != null && is_array($stickyData)'); if (isset($stickyData['savedSearchId']) && $stickyData['savedSearchId'] != '') { try { $savedSearch = SavedSearch::getById((int) $stickyData['savedSearchId']); $model->savedSearchName = $savedSearch->name; $model->savedSearchId = $savedSearch->id; } catch (NotFoundException $e) { } } if (isset($stickyData['anyMixedAttributes'])) { $model->anyMixedAttributes = $stickyData['anyMixedAttributes']; } if (isset($stickyData['anyMixedAttributesScope'])) { $model->setAnyMixedAttributesScope($stickyData['anyMixedAttributesScope']); } if (isset($stickyData['dynamicStructure'])) { $model->dynamicStructure = $stickyData['dynamicStructure']; } if (isset($stickyData['dynamicClauses'])) { $model->dynamicClauses = $stickyData['dynamicClauses']; } if (isset($stickyData[SearchForm::SELECTED_LIST_ATTRIBUTES]) && $model->getListAttributesSelector() != null) { $model->getListAttributesSelector()->setSelected($stickyData[SearchForm::SELECTED_LIST_ATTRIBUTES]); } if (isset($stickyData[KanbanBoard::GROUP_BY_ATTRIBUTE_VISIBLE_VALUES]) && $model->getKanbanBoard() != null && !$model->getKanbanBoard()->getClearSticky()) { $model->getKanbanBoard()->setIsActive(); $model->getKanbanBoard()->setGroupByAttributeVisibleValues($stickyData[KanbanBoard::GROUP_BY_ATTRIBUTE_VISIBLE_VALUES]); } if (isset($stickyData[KanbanBoard::SELECTED_THEME]) && $model->getKanbanBoard() != null && !$model->getKanbanBoard()->getClearSticky()) { $model->getKanbanBoard()->setSelectedTheme($stickyData[KanbanBoard::SELECTED_THEME]); } // If the sort attribute is not in get request but in sticky data, set it into get array $listModelClassName = get_class($model->getModel()); if (!isset($_GET[$listModelClassName . '_sort']) && isset($stickyData['sortAttribute'])) { if ($stickyData['sortAttribute'] != '') { $model->sortAttribute = $stickyData['sortAttribute']; } if (isset($stickyData['sortDescending'])) { if ($stickyData['sortDescending'] == true) { $model->sortDescending = ".desc"; } } } }
function displaySavedSearchSelect() { $savedSearch = new SavedSearch($this->listViewDefs[$this->module], $this->lv->data['pageData']['ordering']['orderBy'], $this->lv->data['pageData']['ordering']['sortOrder']); return $savedSearch->getSelect($this->module); }
private function getSearchDataForSort() { $savedSearch = new SavedSearch(); $savedSearch->name = 'something'; $savedSearch->viewClassName = 'view'; $savedSearch->serializedData = 'someString'; $saved = $savedSearch->save(); $searchModel = new AAASavedDynamicSearchFormTestModel(new AAA(false)); $listAttributesSelector = new ListAttributesSelector('AListView', 'TestModule'); $searchModel->setListAttributesSelector($listAttributesSelector); $searchModel->dynamicStructure = '1 and 5'; $searchModel->dynamicClauses = array('a', 'b'); $searchModel->anyMixedAttributes = 'abcdef'; $searchModel->savedSearchId = $savedSearch->id; $searchModel->setAnyMixedAttributesScope('xyz'); $searchModel->getListAttributesSelector()->setSelected(array('aaaMember', 'aaaMember2')); $dataCollection = new SavedSearchAttributesDataCollection($searchModel); return array('dataCollection' => $dataCollection, 'savedSearch' => $savedSearch); }
public function saveSearch() { $this->layout->body_class = 'user'; $title = Input::get('title', ''); $filter = Input::get('filter', ''); $location = Input::get('location', ''); $query = Input::get('query', ''); if (Auth::check()) { $search = new SavedSearch(); $search->title = $title; $search->filter = $filter; $search->location = $location; $search->query = $query; $search->user = Auth::user()->id; $search->datetime = date("Y-m-d H:i:s"); $search->save(); } }
function __construct() { $result = $GLOBALS['db']->query("SELECT id FROM saved_search"); while ($row = $GLOBALS['db']->fetchByAssoc($result)) { $focus = new SavedSearch(); $focus->retrieve($row['id']); $contents = unserialize(base64_decode($focus->contents)); $has_team_name_saved = isset($contents['team_name_advanced']) || isset($contents['team_name_basic']) ? true : false; //If $contents['searchFormTab'] is set then this is coming from a 4.x saved search if (isset($contents['searchFormTab']) && $contents['searchFormTab'] == 'saved_views') { $new_contents = array(); $module = $contents['search_module']; $advanced = !empty($contents['advanced']); $field_map = array(); if (file_exists("custom/modules/{$module}/metadata/searchdefs.php")) { require "custom/modules/{$module}/metadata/searchdefs.php"; $field_map = $advanced ? $searchdefs[$module]['layout']['advanced_search'] : $searchdefs[$module]['layout']['basic_search']; } else { if (file_exists("modules/{$module}/metadata/SearchFields.php")) { require "modules/{$module}/metadata/SearchFields.php"; $field_map = $searchFields[$module]; } else { $bean = loadBean($module); $field_map = $bean->field_name_map; } } //Special case for team_id field (from 4.5.x) if (isset($contents['team_id'])) { $contents['team_name'] = $contents['team_id']; unset($contents['team_id']); } foreach ($contents as $key => $value) { if (isset($field_map[$key])) { $new_key = $key . ($advanced ? '_advanced' : '_basic'); if (preg_match('/^team_name_(advanced|basic)$/', $new_key)) { if (!is_array($value)) { $temp_value = array(); $teap_value[] = $value; $value = $temp_value; } $team_results = $GLOBALS['db']->query("SELECT id, name FROM teams where id in ('" . implode("','", $value) . "')"); if (!empty($team_results)) { $count = 0; while ($team_row = $GLOBALS['db']->fetchByAssoc($team_results)) { $team_key = $new_key . '_collection_' . $count; $new_contents[$team_key] = $team_row['name']; $new_contents['id_' . $team_key] = $team_row['id']; $count++; } //while } //if //Unset the original key unset($new_contents[$key]); //Add the any switch $new_contents[$new_key . '_type'] = 'any'; } else { $new_contents[$new_key] = $value; } } else { $new_contents[$key] = $value; } } $new_contents['searchFormTab'] = $advanced ? 'advanced_search' : 'basic_search'; $content = base64_encode(serialize($new_contents)); $GLOBALS['db']->query("UPDATE saved_search SET contents = '{$content}' WHERE id = '{$row['id']}'"); } else { if ($has_team_name_saved) { //Otherwise, if the boolean has_team_name_saved is set to true, we also need to parse (coming from 5.x) if (isset($contents['team_name_advanced'])) { $team_results = $GLOBALS['db']->query("SELECT name FROM teams where id = '{$contents['team_name_advanced']}'"); if (!empty($team_results)) { $team_row = $GLOBALS['db']->fetchByAssoc($team_results); $contents['team_name_advanced_collection_0'] = $team_row['name']; $contents['id_team_name_advanced_collection_0'] = $contents['team_name_advanced']; $contents['team_name_advanced_type'] = 'any'; unset($contents['team_name_advanced']); $content = base64_encode(serialize($contents)); $GLOBALS['db']->query("UPDATE saved_search SET contents = '{$content}' WHERE id = '{$row['id']}'"); } } } } } //while }
function handleSave($prefix, $redirect = true, $useRequired = false, $id = null) { global $current_user; $focus = new SavedSearch(); if ($id) { $focus->retrieve($id); } if ($useRequired && !checkRequired($prefix, array_keys($focus->required_fields))) { return null; } $ignored_inputs = array('PHPSESSID', 'module', 'action', 'saved_search_name', 'saved_search_select', 'advanced', 'Calls_divs', 'ACLRoles_divs'); $contents = $_REQUEST; if ($id == null) { $focus->name = $contents['saved_search_name']; } $focus->search_module = $contents['search_module']; foreach ($contents as $input => $value) { if (in_array($input, $ignored_inputs)) { unset($contents[$input]); } } $contents['advanced'] = true; $focus->contents = base64_encode(serialize($contents)); $focus->assigned_user_id = $current_user->id; $focus->new_schema = true; $saved_search_id = $focus->save(); $GLOBALS['log']->debug("Saved record with id of " . $focus->id); $orderBy = empty($contents['orderBy']) ? 'name' : $contents['orderBy']; $search_query = "&orderBy=" . $orderBy . "&sortOrder=" . $contents['sortOrder'] . "&query=" . $_REQUEST['query'] . "&searchFormTab=" . $_REQUEST['searchFormTab'] . '&showSSDIV=' . $contents['showSSDIV']; $this->handleRedirect($focus->search_module, $search_query, $saved_search_id, 'true'); }
public function testpopulateRequest() { $savedSearch = new SavedSearch(); $savedSearch->contents = array('search_module' => 'Accounts', 'description' => 'test text', 'test_content' => 'some content', 'advanced' => true); $savedSearch->populateRequest(); //verify thhat Request parameters are set $this->assertEquals('Accounts', $_REQUEST['search_module']); $this->assertEquals('test text', $_REQUEST['description']); $this->assertEquals('some content', $_REQUEST['test_content']); }
$xtpl->assign('stat_action', $_REQUEST['stat_action']); } else { $xtpl->assign('stat_action', ''); } //Add Custom Fields require_once 'modules/DynamicFields/templates/Files/EditView.php'; global $current_user; if (is_admin($current_user) && $_REQUEST['module'] != 'DynamicLayout' && !empty($_SESSION['editinplace'])) { $record = ''; if (!empty($_REQUEST['record'])) { $record = $_REQUEST['record']; } $xtpl->assign("ADMIN_EDIT", "<a href='index.php?action=index&module=DynamicLayout&from_action=" . $_REQUEST['action'] . "&from_module=" . $_REQUEST['module'] . "&record=" . $record . "'>" . get_image($image_path . "EditLayout", "border='0' alt='Edit Layout' align='bottom'") . "</a>"); } $xtpl->parse("main.open_source"); $xtpl->parse("main"); $xtpl->out("main"); require_once 'include/javascript/javascript.php'; $javascript = new javascript(); $javascript->setFormName('EditView'); $javascript->setSugarBean($focus); $javascript->addAllFields(''); $javascript->addToValidateBinaryDependency('assigned_user_name', 'alpha', $app_strings['ERR_SQS_NO_MATCH_FIELD'] . $app_strings['LBL_ASSIGNED_TO'], 'false', '', 'assigned_user_id'); echo $javascript->getScript(); require_once 'modules/SavedSearch/SavedSearch.php'; $savedSearch = new SavedSearch(); $json = getJSONobj(); $savedSearchSelects = $json->encode(array($GLOBALS['app_strings']['LBL_SAVED_SEARCH_SHORTCUT'] . '<br>' . $savedSearch->getSelect('ComponentEstimateCalc'))); $str = "<script>\n\tYAHOO.util.Event.addListener(window, 'load', SUGAR.util.fillShortcuts, {$savedSearchSelects});\n\t</script>"; echo $str; }
public function actionDeleteSavedSearch($id) { $savedSearch = SavedSearch::GetById(intval($id)); ControllerSecurityUtil::resolveAccessCanCurrentUserDeleteModel($savedSearch); $savedSearch->delete(); }
function handleSave($prefix, $redirect = true, $useRequired = false, $id = null) { require_once 'log4php/LoggerManager.php'; global $current_user; $focus = new SavedSearch(); if ($id) { $focus->retrieve($id); } if ($useRequired && !checkRequired($prefix, array_keys($focus->required_fields))) { return null; } $ignored_inputs = array('PHPSESSID', 'module', 'action', 'saved_search_name', 'saved_search_select', 'advanced'); $contents = array_merge($_POST, $_GET); if ($id == null) { $focus->name = $contents['saved_search_name']; } $focus->search_module = $contents['search_module']; foreach ($contents as $input => $value) { if (in_array($input, $ignored_inputs)) { unset($contents[$input]); } } $contents['advanced'] = true; $focus->contents = base64_encode(serialize($contents)); $focus->assigned_user_id = $current_user->id; $focus->new_schema = true; $focus->search_module = $focus->search_module; $saved_search_id = $focus->save(); $GLOBALS['log']->debug("Saved record with id of " . $focus->id); $search_query = ''; foreach ($contents as $input => $value) { if (is_array($value)) { // handle multiselects foreach ($value as $v) { $search_query .= $input . '[]=' . $v . '&'; } } else { $search_query .= $input . '=' . $value . '&'; } } $this->handleRedirect($focus->search_module, $search_query, $saved_search_id, 'true'); }
break; case 'delete': // delete here $ss->handleDelete($_REQUEST['saved_search_select']); break; } } elseif (!empty($_REQUEST['saved_search_select'])) { // requesting a search here. if (!empty($_REQUEST['searchFormTab'])) { // where is the request from $searchFormTab = $_REQUEST['searchFormTab']; } else { $searchFormTab = 'saved_views'; } if ($_REQUEST['saved_search_select'] == '_none') { // none selected $_SESSION['LastSavedView'][$_REQUEST['search_module']] = ''; $current_user->setPreference('ListViewDisplayColumns', array(), 0, $_REQUEST['search_module']); header("Location: index.php?action=index&module={$_REQUEST['search_module']}&searchFormTab={$searchFormTab}&query=true&clear_query=true"); die; } else { $ss = new SavedSearch(); $show = 'no'; if (isset($_REQUEST['showSSDIV'])) { $show = $_REQUEST['showSSDIV']; } $ss->returnSavedSearch($_REQUEST['saved_search_select'], $searchFormTab, $show); } } else { include 'modules/SavedSearch/ListView.php'; }
/** * Called from process(). This method will display the search form on the left of the page. */ function displaySearch() { global $app_list_strings; $savedSearch = new SavedSearch(); $json = getJSONobj(); $savedSearchSelects = $json->encode(array($GLOBALS['app_strings']['LBL_SAVED_SEARCH_SHORTCUT'] . '<br>' . $savedSearch->getSelect($this->module))); $str = "<script>\n\t\tYAHOO.util.Event.addListener(window, 'load', SUGAR.util.fillShortcuts, {$savedSearchSelects});\n\t\t</script>"; echo $str; }
if (count($where_clauses) > 0) { $where = implode(' and ', $where_clauses); } $GLOBALS['log']->info("Here is the where clause for the list view: {$where}"); } // start display // which tab of search form to display if (!isset($_REQUEST['search_form']) || $_REQUEST['search_form'] != 'false') { $searchForm->setup(); if (isset($_REQUEST['searchFormTab']) && $_REQUEST['searchFormTab'] == 'advanced_search') { $searchForm->displayAdvanced(); } elseif (isset($_REQUEST['searchFormTab']) && $_REQUEST['searchFormTab'] == 'saved_views') { $searchForm->displaySavedViews($listViewDefs, $lv); } else { $searchForm->displayBasic(); } } echo $qsd->GetQSScripts(); $lv->setup($seedProducts, 'include/ListView/ListViewGeneric.tpl', $where, $params); $savedSearchName = empty($_REQUEST['saved_search_select_name']) ? '' : ' - ' . $_REQUEST['saved_search_select_name']; echo get_form_header($current_module_strings['LBL_LIST_FORM_TITLE'] . $savedSearchName, '', false); echo $lv->display(); $savedSearch = new SavedSearch(); $json = getJSONobj(); // fills in saved views select box on shortcut menu $savedSearchSelects = $json->encode(array($GLOBALS['app_strings']['LBL_SAVED_SEARCH_SHORTCUT'] . '<br>' . $savedSearch->getSelect('Products'))); $str = "<script>\nYAHOO.util.Event.addListener(window, 'load', SUGAR.util.fillShortcuts, {$savedSearchSelects});\n</script>"; echo $str; ?>
/** * displays the saved views form body * * @param bool $header display this with headers * @param bool $return echo or return the html * * @return string html of contents */ function displaySavedViews($listViewDefs, $lv, $header = true, $return = false) { global $current_user, $image_path; $savedSearch = new SavedSearch($listViewDefs[$this->module], $lv->data['pageData']['ordering']['orderBy'], $lv->data['pageData']['ordering']['sortOrder']); if ($header) { $this->displayWithHeaders('saved_views', $this->displayBasic(false, true), $this->displayAdvanced(false, true), $savedSearch->getForm($this->module)); echo '<script>SUGAR.savedViews.handleForm();</script>'; } else { echo $savedSearch->getForm($this->module, false); } }