Ejemplo n.º 1
0
 public function handleDelete($id)
 {
     $savedSearch = new SavedSearch();
     $savedSearch->handleDelete($id);
     $result = $savedSearch->retrieve($id);
     $this->assertEquals(null, $result);
 }
Ejemplo n.º 2
0
 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");
 }
Ejemplo n.º 3
0
 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
 }
Ejemplo n.º 4
0
 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');
     }
 }
Ejemplo n.º 5
0
 /**
  * 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");
 }
Ejemplo n.º 6
0
 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');
 }
 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');
 }