function processSugarBean($html_varName, $seed, $offset) { global $row_count, $sugar_config; global $next_offset; global $previous_offset; global $list_view_row_count; global $current_offset; if (!empty($sugar_config['disable_vcr'])) { $seed->retrieve($_REQUEST['record']); return $seed; } $isfirstview = 0; $nav_history_set = false; $nav_history_array = array(); $nav_offset = ''; $nav_ids_visited = array(); $nav_stamp = ''; //get the session variable DETAIL_NAV_HISTORY, //the format of the variable stamp,offset, array of IDs visited. $nav_history = $this->getLocalSessionVariable($html_varName, "DETAIL_NAV_HISTORY"); if (!empty($nav_history)) { $nav_history_set = true; $nav_history_array = explode(":", $nav_history); $nav_stamp = $nav_history_array[0]; $nav_offset = $nav_history_array[1]; eval("\$nav_ids_visited= " . $nav_history_array[2] . ";"); } //from list offset is there but $bNavHistorySet is false. //from next,previous,start and end buttons offset and $bNavHistorySet is true. //from tracker offset is not there but $bNavHistorySet may or may not exist. if (isset($_REQUEST['offset']) && !empty($_REQUEST['offset'])) { //get offset values. $offset = $_REQUEST['offset']; if ($offset < 0) { $offset = 0; } //if the stamp has changed, ignore the offset and navigate to the record. //use case, search, navigate to detail, copy URL, search again, paste URL. if (!$this->isRequestFromListView($html_varName)) { $result = $seed->retrieve($_REQUEST['record']); return $result; } if ($nav_history_set) { if (isset($nav_ids_visited[$offset])) { unset($nav_ids_visited[$offset]); } } } else { if ($nav_history_set) { //try to locate the ID in the nav_history array. $key = array_search($_REQUEST['record'], $nav_ids_visited); if ($key === false) { //do not show the VCR buttons. $result = $seed->retrieve($_REQUEST['record']); return $result; } $offset = $key; $_REQUEST['offset'] = $offset; $_GET['offset'] = $offset; $_POST['offset'] = $offset; $_REQUEST['stamp'] = $nav_stamp; $_GET['stamp'] = $nav_stamp; $_POST['stamp'] = $nav_stamp; if (isset($nav_ids_visited[$offset])) { unset($nav_ids_visited[$offset]); } } else { if (!empty($seed->id)) { return $seed; } $result = $seed->retrieve($_REQUEST['record']); return $result; } } //Check if this is the first time we have viewed this record $var = $this->getLocalSessionVariable($html_varName, "IS_FIRST_VIEW"); if (!isset($var) || !$var) { $isFirstView = true; } else { $isFirstView = false; } //indicate that this is not the first time anymore $this->setLocalSessionVariable($html_varName, "IS_FIRST_VIEW", false); // All 3 databases require this because the limit query does a > db_offset comparison. $db_offset = $offset - 1; $this->populateQueryWhere($isFirstView, $html_varName); if (ACLController::requireOwner($seed->module_dir, 'view')) { global $current_user; $seed->getOwnerWhere($current_user->id); if (!empty($this->query_where)) { $this->query_where .= ' AND '; } $this->query_where .= $seed->getOwnerWhere($current_user->id); } /* BEGIN - SECURITY GROUPS */ if (ACLController::requireSecurityGroup($seed->module_dir, 'view')) { require_once 'modules/SecurityGroups/SecurityGroup.php'; global $current_user; $owner_where = $seed->getOwnerWhere($current_user->id); $group_where = SecurityGroup::getGroupWhere($seed->table_name, $seed->module_dir, $current_user->id); if (empty($this->query_where)) { $this->query_where = " (" . $owner_where . " or " . $group_where . ")"; } else { $this->query_where .= " AND (" . $owner_where . " or " . $group_where . ")"; } } /* END - SECURITY GROUPS */ $order = $this->getLocalSessionVariable($seed->module_dir . '2_' . $html_varName, "ORDER_BY"); $orderBy = ''; if (!empty($order['orderBy'])) { $orderBy = $order['orderBy']; } if (!empty($orderBy) && !empty($order['direction'])) { $orderBy .= ' ' . $order['direction']; } $this->query_orderby = $seed->process_order_by($orderBy, null); $current_offset = $_REQUEST['offset'] - 1; $response = $seed->process_detail_query(SugarVCR::retrieve($seed->module_dir), 0, -1, -1, '', $current_offset); //$response = $seed->get_detail(, $this->query_where, $db_offset); $object = $response['bean']; $row_count = $response['row_count']; $next_offset = $response['next_offset']; $previous_offset = $response['previous_offset']; $list_view_row_count = $row_count; $this->setListViewRowCount($row_count); //if the retrieved id is not same as the request ID then hide the VCR buttons. if (empty($object->id)) { $this->no_record_found = true; } if (empty($_REQUEST['InDetailNav']) and strcmp($_REQUEST['record'], $object->id) != 0) { $this->offset_key_mismatch = true; } if ($this->no_record_found or $this->offset_key_mismatch) { if ($nav_history_set) { $this->return_to_list_only = true; } $result = $seed->retrieve($_REQUEST['record']); return $result; } //update the request with correct value for the record attribute. //need only when using the VCR buttons. This is a workaround need to fix the values //set in the VCR links. $_REQUEST['record'] = $object->id; $_GET['record'] = $object->id; $_POST['record'] = $object->id; //set nav_history. if (empty($nav_stamp)) { $nav_stamp = $_GET['stamp']; } if (empty($nav_offset)) { $nav_offset = $offset; } //store a maximum of 20 entries in the nav_ids_visited array. //remove the oldest entry when this limit is reached. if (count($nav_ids_visited) >= 20) { reset($nav_ids_visited); unset($nav_ids_visited[key($nav_ids_visited)]); } $nav_ids_visited[$offset] = $object->id; $nav_history = sprintf("%s:%s:%s", $nav_stamp, $nav_offset, var_export($nav_ids_visited, true)); $this->setLocalSessionVariable($html_varName, "DETAIL_NAV_HISTORY", $nav_history); return $object; }
function record($module, $offset) { Log::debug('SUGARVCR is recording more records'); $start = max(0, $offset - VCRSTART); $index = $start; $db = DBManagerFactory::getInstance(); $result = $db->limitQuery(SugarVCR::retrieve($module), $start, $offset + VCREND, false); $index++; $ids = array(); while (($row = $db->fetchByAssoc($result)) != null) { $ids[$index] = $row['id']; $index++; } //now that we have the array of ids, store this in the session $_SESSION[$module . 'QUERY_ARRAY'] = $ids; return $ids; }
function record($module, $offset) { $GLOBALS['log']->debug('SUGARVCR is recording more records'); $page_length = $GLOBALS['sugar_config']['list_max_entries_per_page'] + 1; $start = max(0, $offset - $page_length); $index = $start; $db = DBManagerFactory::getInstance(); $result = $db->limitQuery(SugarVCR::retrieve($module), $start, $offset + $page_length, false); $index++; $ids = array(); while (($row = $db->fetchByAssoc($result)) != null) { $ids[$index] = $row['id']; $index++; } //get last index of ids end($ids); $_SESSION[$module . 'total'] = key($ids); reset($ids); //now that we have the array of ids, store this in the session $_SESSION[$module . 'QUERY_ARRAY'] = $ids; return $ids; }