Esempio n. 1
0
 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;
 }
Esempio n. 2
0
 /**
 
 * @return void
 * @param unknown $seed
 * @param unknown $xTemplateSection
 * @param unknown $html_varName
 * @desc INTERNAL FUNCTION Handles List views using seeds that extend SugarBean
     $XTemplateSection is the section in the XTemplate file that should be parsed usually main
     $html_VarName is the variable name used in the XTemplateFile e.g. TASK
     $seed is a seed that extends SugarBean
     * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc..
     * All Rights Reserved..
     * Contributor(s): ______________________________________..
 */
 function processSugarBean($xtemplateSection, $html_varName, $seed)
 {
     global $list_view_row_count;
     $current_offset = $this->getOffset($html_varName);
     $response = array();
     //ADDING VCR CONTROL
     SugarVCR::erase($seed->module_dir);
     $params = array();
     //$filter = array('id', 'full_name');
     $filter = array();
     $ret_array = $seed->create_new_list_query($this->query_orderby, $this->query_where, $filter, $params, 0, '', true, $seed, true);
     if (!is_array($params)) {
         $params = array();
     }
     if (!isset($params['custom_select'])) {
         $params['custom_select'] = '';
     }
     if (!isset($params['custom_from'])) {
         $params['custom_from'] = '';
     }
     if (!isset($params['custom_where'])) {
         $params['custom_where'] = '';
     }
     if (!isset($params['custom_order_by'])) {
         $params['custom_order_by'] = '';
     }
     $main_query = $ret_array['select'] . $params['custom_select'] . $ret_array['from'] . $params['custom_from'] . $ret_array['where'] . $params['custom_where'] . $ret_array['order_by'] . $params['custom_order_by'];
     SugarVCR::store($seed->module_dir, $main_query);
     //ADDING VCR CONTROL
     if (empty($this->related_field_name)) {
         $response = $seed->get_list($this->query_orderby, $this->query_where, $current_offset, $this->query_limit);
     } else {
         $related_field_name = $this->related_field_name;
         $response = $seed->get_related_list($this->child_focus, $related_field_name, $this->query_orderby, $this->query_where, $current_offset, $this->query_limit);
     }
     $list = $response['list'];
     $row_count = $response['row_count'];
     $next_offset = $response['next_offset'];
     $previous_offset = $response['previous_offset'];
     if (!empty($response['current_offset'])) {
         $current_offset = $response['current_offset'];
     }
     $list_view_row_count = $row_count;
     $this->processListNavigation($xtemplateSection, $html_varName, $current_offset, $next_offset, $previous_offset, $row_count, null, null, empty($seed->column_fields) ? null : count($seed->column_fields));
     return $list;
 }
Esempio n. 3
0
 /**
 * takes in a seed and creates the list view query based off of that seed
 * if the $limit value is set to -1 then it will use the default limit and offset values
 *
 * it will return an array with two key values
 * 	1. 'data'=> this is an array of row data
 *  2. 'pageData'=> this is an array containg three values
 * 			a.'ordering'=> array('orderBy'=> the field being ordered by , 'sortOrder'=> 'ASC' or 'DESC')
 * 			b.'urls'=>array('baseURL'=>url used to generate other urls ,
 * 							'orderBy'=> the base url for order by
 * 							//the following may not be set (so check empty to see if they are set)
 * 							'nextPage'=> the url for the next group of results,
 * 							'prevPage'=> the url for the prev group of results,
 * 							'startPage'=> the url for the start of the group,
 * 							'endPage'=> the url for the last set of results in the group
 * 			c.'offsets'=>array(
 * 								'current'=>current offset
 * 								'next'=> next group offset
 * 								'prev'=> prev group offset
 * 								'end'=> the offset of the last group
 * 								'total'=> the total count (only accurate if totalCounted = true otherwise it is either the total count if less than the limit or the total count + 1 )
 * 								'totalCounted'=> if a count query was used to get the total count
 *
 * @param SugarBean $seed
 * @param string $where
 * @param int:0 $offset
 * @param int:-1 $limit
 * @param string[]:array() $filter_fields
 * @param array:array() $params
 * 	Potential $params are
 		$params['distinct'] = use distinct key word
 		$params['include_custom_fields'] = (on by default)
         $params['custom_XXXX'] = append custom statements to query
 * @param string:'id' $id_field
 * @return array('data'=> row data, 'pageData' => page data information, 'query' => original query string)
 */
 function getListViewData($seed, $where, $offset = -1, $limit = -1, $filter_fields = array(), $params = array(), $id_field = 'id', $singleSelect = true)
 {
     global $current_user;
     SugarVCR::erase($seed->module_dir);
     $this->seed =& $seed;
     $totalCounted = empty($GLOBALS['sugar_config']['disable_count_query']);
     $_SESSION['MAILMERGE_MODULE_FROM_LISTVIEW'] = $seed->module_dir;
     if (empty($_REQUEST['action']) || $_REQUEST['action'] != 'Popup') {
         $_SESSION['MAILMERGE_MODULE'] = $seed->module_dir;
     }
     $this->setVariableName($seed->object_name, $where, $this->listviewName);
     $this->seed->id = '[SELECT_ID_LIST]';
     // if $params tell us to override all ordering
     if (!empty($params['overrideOrder']) && !empty($params['orderBy'])) {
         $order = $this->getOrderBy(strtolower($params['orderBy']), empty($params['sortOrder']) ? '' : $params['sortOrder']);
         // retreive from $_REQUEST
     } else {
         $order = $this->getOrderBy();
         // retreive from $_REQUEST
     }
     // else use stored preference
     $userPreferenceOrder = $current_user->getPreference('listviewOrder', $this->var_name);
     if (empty($order['orderBy']) && !empty($userPreferenceOrder)) {
         $order = $userPreferenceOrder;
     }
     // still empty? try to use settings passed in $param
     if (empty($order['orderBy']) && !empty($params['orderBy'])) {
         $order['orderBy'] = $params['orderBy'];
         $order['sortOrder'] = empty($params['sortOrder']) ? '' : $params['sortOrder'];
     }
     //rrs - bug: 21788. Do not use Order by stmts with fields that are not in the query.
     // Bug 22740 - Tweak this check to strip off the table name off the order by parameter.
     // Samir Gandhi : Do not remove the report_cache.date_modified condition as the report list view is broken
     $orderby = $order['orderBy'];
     if (strpos($order['orderBy'], '.') && $order['orderBy'] != "report_cache.date_modified") {
         $orderby = substr($order['orderBy'], strpos($order['orderBy'], '.') + 1);
     }
     if ($orderby != 'date_entered' && !in_array($orderby, array_keys($filter_fields))) {
         $order['orderBy'] = '';
         $order['sortOrder'] = '';
     }
     if (empty($order['orderBy'])) {
         $orderBy = '';
     } else {
         $orderBy = $order['orderBy'] . ' ' . $order['sortOrder'];
         //wdong, Bug 25476, fix the sorting problem of Oracle.
         if (isset($params['custom_order_by_override']['ori_code']) && $order['orderBy'] == $params['custom_order_by_override']['ori_code']) {
             $orderBy = $params['custom_order_by_override']['custom_code'] . ' ' . $order['sortOrder'];
         }
     }
     if (empty($params['skipOrderSave'])) {
         // don't save preferences if told so
         $current_user->setPreference('listviewOrder', $order, 0, $this->var_name);
         // save preference
     }
     // If $params tells us to override for the special last_name, first_name sorting
     if (!empty($params['overrideLastNameOrder']) && $order['orderBy'] == 'last_name') {
         $orderBy = 'last_name ' . $order['sortOrder'] . ', first_name ' . $order['sortOrder'];
     }
     $ret_array = $seed->create_new_list_query($orderBy, $where, $filter_fields, $params, 0, '', true, $seed, $singleSelect);
     $ret_array['inner_join'] = '';
     if (!empty($this->seed->listview_inner_join)) {
         $ret_array['inner_join'] = ' ' . implode(' ', $this->seed->listview_inner_join) . ' ';
     }
     if (!is_array($params)) {
         $params = array();
     }
     if (!isset($params['custom_select'])) {
         $params['custom_select'] = '';
     }
     if (!isset($params['custom_from'])) {
         $params['custom_from'] = '';
     }
     if (!isset($params['custom_where'])) {
         $params['custom_where'] = '';
     }
     if (!isset($params['custom_order_by'])) {
         $params['custom_order_by'] = '';
     }
     $main_query = $ret_array['select'] . $params['custom_select'] . $ret_array['from'] . $params['custom_from'] . $ret_array['inner_join'] . $ret_array['where'] . $params['custom_where'] . $ret_array['order_by'] . $params['custom_order_by'];
     //C.L. - Fix for 23461
     if (empty($_REQUEST['action']) || $_REQUEST['action'] != 'Popup') {
         $_SESSION['export_where'] = $ret_array['where'];
     }
     if ($limit < -1) {
         $result = $this->db->query($main_query);
     } else {
         if ($limit == -1) {
             $limit = $this->getLimit();
         }
         $dyn_offset = $this->getOffset();
         if ($dyn_offset > 0 || !is_int($dyn_offset)) {
             $offset = $dyn_offset;
         }
         if (strcmp($offset, 'end') == 0) {
             $totalCount = $this->getTotalCount($main_query);
             $offset = floor(($totalCount - 1) / $limit) * $limit;
         }
         if ($this->seed->ACLAccess('ListView')) {
             $result = $this->db->limitQuery($main_query, $offset, $limit + 1);
         } else {
             $result = array();
         }
     }
     $data = array();
     $temp = clone $seed;
     $rows = array();
     $count = 0;
     $idIndex = array();
     $id_list = '';
     while (($row = $this->db->fetchByAssoc($result)) != null) {
         if ($count < $limit) {
             $id_list .= ',\'' . $row[$id_field] . '\'';
             $idIndex[$row[$id_field]][] = count($rows);
             $rows[] = $seed->convertRow($row);
         }
         $count++;
     }
     if (!empty($id_list)) {
         $id_list = '(' . substr($id_list, 1) . ')';
     }
     SugarVCR::store($this->seed->module_dir, $main_query);
     if ($count != 0) {
         //NOW HANDLE SECONDARY QUERIES
         if (!empty($ret_array['secondary_select'])) {
             $secondary_query = $ret_array['secondary_select'] . $ret_array['secondary_from'] . ' WHERE ' . $this->seed->table_name . '.id IN ' . $id_list;
             if (isset($ret_array['order_by'])) {
                 $secondary_query .= ' ' . $ret_array['order_by'];
             }
             $secondary_result = $this->db->query($secondary_query);
             $ref_id_count = array();
             while ($row = $this->db->fetchByAssoc($secondary_result)) {
                 $ref_id_count[$row['ref_id']][] = true;
                 foreach ($row as $name => $value) {
                     //add it to every row with the given id
                     foreach ($idIndex[$row['ref_id']] as $index) {
                         $rows[$index][$name] = $value;
                     }
                 }
             }
             $rows_keys = array_keys($rows);
             foreach ($rows_keys as $key) {
                 $rows[$key]['secondary_select_count'] = count($ref_id_count[$rows[$key]['ref_id']]);
             }
         }
         // retrieve parent names
         if (!empty($filter_fields['parent_name']) && !empty($filter_fields['parent_id']) && !empty($filter_fields['parent_type'])) {
             foreach ($idIndex as $id => $rowIndex) {
                 if (!isset($post_retrieve[$rows[$rowIndex[0]]['parent_type']])) {
                     $post_retrieve[$rows[$rowIndex[0]]['parent_type']] = array();
                 }
                 if (!empty($rows[$rowIndex[0]]['parent_id'])) {
                     $post_retrieve[$rows[$rowIndex[0]]['parent_type']][] = array('child_id' => $id, 'parent_id' => $rows[$rowIndex[0]]['parent_id'], 'parent_type' => $rows[$rowIndex[0]]['parent_type'], 'type' => 'parent');
                 }
             }
             if (isset($post_retrieve)) {
                 $parent_fields = $seed->retrieve_parent_fields($post_retrieve);
                 foreach ($parent_fields as $child_id => $parent_data) {
                     //add it to every row with the given id
                     foreach ($idIndex[$child_id] as $index) {
                         $rows[$index]['parent_name'] = $parent_data['parent_name'];
                     }
                 }
             }
         }
         $pageData = array();
         reset($rows);
         while ($row = current($rows)) {
             $temp = clone $seed;
             $dataIndex = count($data);
             $temp->setupCustomFields($temp->module_dir);
             $temp->loadFromRow($row);
             if (empty($this->seed->assigned_user_id) && !empty($temp->assigned_user_id)) {
                 $this->seed->assigned_user_id = $temp->assigned_user_id;
             }
             if ($idIndex[$row[$id_field]][0] == $dataIndex) {
                 $pageData['tag'][$dataIndex] = $temp->listviewACLHelper();
             } else {
                 $pageData['tag'][$dataIndex] = $pageData['tag'][$idIndex[$row[$id_field]][0]];
             }
             $data[$dataIndex] = $temp->get_list_view_data($filter_fields);
             $detailViewAccess = $temp->ACLAccess('DetailView');
             $editViewAccess = $temp->ACLAccess('EditView');
             $pageData['rowAccess'][$dataIndex] = array('view' => $detailViewAccess, 'edit' => $editViewAccess);
             $additionalDetailsAllow = $this->additionalDetails && $detailViewAccess && (file_exists('modules/' . $temp->module_dir . '/metadata/additionalDetails.php') || file_exists('custom/modules/' . $temp->module_dir . '/metadata/additionalDetails.php'));
             $additionalDetailsEdit = $editViewAccess;
             if ($additionalDetailsAllow) {
                 if ($this->additionalDetailsAjax) {
                     $ar = $this->getAdditionalDetailsAjax($data[$dataIndex]['ID']);
                 } else {
                     $additionalDetailsFile = 'modules/' . $this->seed->module_dir . '/metadata/additionalDetails.php';
                     if (file_exists('custom/modules/' . $this->seed->module_dir . '/metadata/additionalDetails.php')) {
                         $additionalDetailsFile = 'custom/modules/' . $this->seed->module_dir . '/metadata/additionalDetails.php';
                     }
                     require_once $additionalDetailsFile;
                     $ar = $this->getAdditionalDetails($data[$dataIndex], (empty($this->additionalDetailsFunction) ? 'additionalDetails' : $this->additionalDetailsFunction) . $this->seed->object_name, $additionalDetailsEdit);
                 }
                 $pageData['additionalDetails'][$dataIndex] = $ar['string'];
                 $pageData['additionalDetails']['fieldToAddTo'] = $ar['fieldToAddTo'];
             }
             next($rows);
         }
     }
     $nextOffset = -1;
     $prevOffset = -1;
     $endOffset = -1;
     if ($count > $limit) {
         $nextOffset = $offset + $limit;
     }
     if ($offset > 0) {
         $prevOffset = $offset - $limit;
         if ($prevOffset < 0) {
             $prevOffset = 0;
         }
     }
     $totalCount = $count + $offset;
     if ($count >= $limit && $totalCounted) {
         $totalCount = $this->getTotalCount($main_query);
     }
     SugarVCR::recordIDs($this->seed->module_dir, array_keys($idIndex), $offset, $totalCount);
     $module_names = array('Prospects' => 'Targets');
     $endOffset = floor(($totalCount - 1) / $limit) * $limit;
     $pageData['ordering'] = $order;
     $pageData['ordering']['sortOrder'] = $this->getReverseSortOrder($pageData['ordering']['sortOrder']);
     $pageData['urls'] = $this->generateURLS($pageData['ordering']['sortOrder'], $offset, $prevOffset, $nextOffset, $endOffset, $totalCounted);
     $pageData['offsets'] = array('current' => $offset, 'next' => $nextOffset, 'prev' => $prevOffset, 'end' => $endOffset, 'total' => $totalCount, 'totalCounted' => $totalCounted);
     $pageData['bean'] = array('objectName' => $seed->object_name, 'moduleDir' => $seed->module_dir, 'moduleName' => strtr($seed->module_dir, $module_names));
     $pageData['stamp'] = $this->stamp;
     $pageData['access'] = array('view' => $this->seed->ACLAccess('DetailView'), 'edit' => $this->seed->ACLAccess('EditView'));
     $pageData['idIndex'] = $idIndex;
     if (!$this->seed->ACLAccess('ListView')) {
         $pageData['error'] = 'ACL restricted access';
     }
     $queryString = '';
     if (isset($_REQUEST["searchFormTab"]) && $_REQUEST["searchFormTab"] == "advanced_search" || isset($_REQUEST["type_basic"]) && (count($_REQUEST["type_basic"] > 1) || $_REQUEST["type_basic"][0] != "") || isset($_REQUEST["module"]) && $_REQUEST["module"] == "MergeRecords") {
         $queryString = "-advanced_search";
     } else {
         if (isset($_REQUEST["searchFormTab"]) && $_REQUEST["searchFormTab"] == "basic_search") {
             if ($seed->module_dir == "Reports") {
                 $searchMetaData = SearchFormReports::retrieveReportsSearchDefs();
             } else {
                 $searchMetaData = SearchForm::retrieveSearchDefs($seed->module_dir);
             }
             $basicSearchFields = array();
             if (isset($searchMetaData['searchdefs']) && isset($searchMetaData['searchdefs'][$seed->module_dir]['layout']['basic_search'])) {
                 $basicSearchFields = $searchMetaData['searchdefs'][$seed->module_dir]['layout']['basic_search'];
             }
             foreach ($basicSearchFields as $basicSearchField) {
                 $field_name = is_array($basicSearchField) && isset($basicSearchField['name']) ? $basicSearchField['name'] : $basicSearchField;
                 $field_name .= "_basic";
                 if (isset($_REQUEST[$field_name]) && (!is_array($basicSearchField) || !isset($basicSearchField['type']) || $basicSearchField['type'] == 'text' || $basicSearchField['type'] == 'name')) {
                     $queryString = htmlentities($_REQUEST[$field_name]);
                     break;
                 }
             }
         }
     }
     return array('data' => $data, 'pageData' => $pageData, 'query' => $queryString);
 }
Esempio n. 4
0
 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;
 }
Esempio n. 5
0
 function process($checkFormName = false, $formName = '')
 {
     global $mod_strings, $sugar_config, $app_strings, $app_list_strings;
     //the retrieve already did this work;
     //$this->focus->fill_in_relationship_fields();
     if (!$this->th->checkTemplate($this->module, $this->view, $checkFormName, $formName)) {
         $this->render();
     }
     if (isset($_REQUEST['offset'])) {
         $this->offset = $_REQUEST['offset'] - 1;
     }
     if ($this->showVCRControl) {
         $this->th->ss->assign('PAGINATION', SugarVCR::menu($this->module, $this->offset, $this->focus->is_AuditEnabled(), $this->view == 'EditView'));
     }
     if (isset($_REQUEST['return_module'])) {
         $this->returnModule = $_REQUEST['return_module'];
     }
     if (isset($_REQUEST['return_action'])) {
         $this->returnAction = $_REQUEST['return_action'];
     }
     if (isset($_REQUEST['return_id'])) {
         $this->returnId = $_REQUEST['return_id'];
     }
     if (isset($_REQUEST['return_relationship'])) {
         $this->returnRelationship = $_REQUEST['return_relationship'];
     }
     if (isset($_REQUEST['return_name'])) {
         $this->returnName = $this->getValueFromRequest($_REQUEST, 'return_name');
     }
     // handle Create $module then Cancel
     if (empty($this->returnId)) {
         $this->returnAction = 'index';
     }
     $is_owner = $this->focus->isOwner($GLOBALS['current_user']->id);
     $this->fieldDefs = array();
     if ($this->focus) {
         global $current_user;
         if (!empty($this->focus->assigned_user_id)) {
             $this->focus->assigned_user_name = get_assigned_user_name($this->focus->assigned_user_id);
         }
         foreach ($this->focus->toArray() as $name => $value) {
             $valueFormatted = false;
             //if ($this->focus->field_defs[$name]['type']=='link')continue;
             $this->fieldDefs[$name] = !empty($this->fieldDefs[$name]) && !empty($this->fieldDefs[$name]['value']) ? array_merge($this->focus->field_defs[$name], $this->fieldDefs[$name]) : $this->focus->field_defs[$name];
             foreach (array("formula", "default", "comments", "help") as $toEscape) {
                 if (!empty($this->fieldDefs[$name][$toEscape])) {
                     $this->fieldDefs[$name][$toEscape] = htmlentities($this->fieldDefs[$name][$toEscape], ENT_QUOTES, 'UTF-8');
                 }
             }
             if (isset($this->fieldDefs[$name]['options']) && isset($app_list_strings[$this->fieldDefs[$name]['options']])) {
                 $this->fieldDefs[$name]['options'] = $app_list_strings[$this->fieldDefs[$name]['options']];
                 if (isset($GLOBALS['sugar_config']['enable_autocomplete']) && $GLOBALS['sugar_config']['enable_autocomplete'] == true) {
                     $this->fieldDefs[$name]['autocomplete'] = true;
                     $this->fieldDefs[$name]['autocomplete_options'] = $this->fieldDefs[$name]['options'];
                     // we need the name for autocomplete
                 } else {
                     $this->fieldDefs[$name]['autocomplete'] = false;
                 }
             }
             if (isset($this->fieldDefs[$name]['function'])) {
                 $function = $this->fieldDefs[$name]['function'];
                 $function = is_array($function) && isset($function['name']) ? $this->fieldDefs[$name]['function']['name'] : $this->fieldDefs[$name]['function'];
                 if (!empty($this->fieldDefs[$name]['function']['returns']) && $this->fieldDefs[$name]['function']['returns'] == 'html') {
                     if (!empty($this->fieldDefs[$name]['function']['include'])) {
                         require_once $this->fieldDefs[$name]['function']['include'];
                     }
                     $value = $function($this->focus, $name, $value, $this->view);
                     $valueFormatted = true;
                 } else {
                     $this->fieldDefs[$name]['options'] = $function($this->focus, $name, $value, $this->view);
                 }
             }
             if (isset($this->fieldDefs[$name]['function'])) {
                 $function = $this->fieldDefs[$name]['function'];
                 if (is_array($function) && isset($function['name'])) {
                     $function = $this->fieldDefs[$name]['function']['name'];
                 } else {
                     $function = $this->fieldDefs[$name]['function'];
                 }
                 if (!empty($this->fieldDefs[$name]['function']['returns']) && $this->fieldDefs[$name]['function']['returns'] == 'html') {
                     if (!empty($this->fieldDefs[$name]['function']['include'])) {
                         require_once $this->fieldDefs[$name]['function']['include'];
                     }
                     $value = $function($this->focus, $name, $value, $this->view);
                     $valueFormatted = true;
                 } else {
                     $this->fieldDefs[$name]['options'] = $function($this->focus, $name, $value, $this->view);
                 }
             }
             if (isset($this->fieldDefs[$name]['type']) && $this->fieldDefs[$name]['type'] == 'function' && isset($this->fieldDefs[$name]['function_name'])) {
                 $value = $this->callFunction($this->fieldDefs[$name]);
                 $valueFormatted = true;
             }
             if (!$valueFormatted) {
                 // $this->focus->format_field($this->focus->field_defs[$name]);
                 $value = isset($this->focus->{$name}) ? $this->focus->{$name} : '';
             }
             if (empty($this->fieldDefs[$name]['value'])) {
                 $this->fieldDefs[$name]['value'] = $value;
             }
             //This code is used for QuickCreates that go to Full Form view.  We want to overwrite the values from the bean
             //with values from the request if they are set
             if ($this->populateBean && (isset($_REQUEST['full_form']) || $_REQUEST['action'] == "SubpanelCreates" && empty($this->focus->id)) && (!isset($this->fieldDefs[$name]['function']['returns']) || $this->fieldDefs[$name]['function']['returns'] != 'html') && isset($_REQUEST[$name])) {
                 $this->fieldDefs[$name]['value'] = $this->getValueFromRequest($_REQUEST, $name);
             }
             /*
              * Populate any relate fields that are linked by a relationship to the calling module.
              * Clicking the create button on a subpanel for example will populate three values in the $_REQUEST:
              * 1. return_module => the name of the calling module
              * 2. return_id => the id of the record in the calling module that the user was viewing and that should be associated with this new record
              * 3. return_name => the display value of the return_id record - the value to show in any relate field in this EditView
              * Only do if this fieldDef does not already have a value; if it does it will have been explicitly set, and that should overrule this less specific mechanism
              */
             if (isset($this->returnModule) && isset($this->returnName) && empty($this->focus->id) && empty($this->fieldDefs['name']['value'])) {
                 if ($this->focus->field_defs[$name]['type'] == 'relate' && isset($this->focus->field_defs[$name]['module']) && $this->focus->field_defs[$name]['module'] == $this->returnModule) {
                     if (isset($this->fieldDefs[$name]['id_name']) && !empty($this->returnRelationship) && isset($this->focus->field_defs[$this->fieldDefs[$name]['id_name']]['relationship']) && $this->returnRelationship == $this->focus->field_defs[$this->fieldDefs[$name]['id_name']]['relationship']) {
                         $this->fieldDefs[$name]['value'] = $this->returnName;
                         // set the hidden id field for this relate field to the correct value i.e., return_id
                         $this->fieldDefs[$this->fieldDefs[$name]['id_name']]['value'] = $this->returnId;
                     }
                 }
             }
         }
     }
     if (isset($this->focus->additional_meta_fields)) {
         $this->fieldDefs = array_merge($this->fieldDefs, $this->focus->additional_meta_fields);
     }
     if ($this->isDuplicate) {
         foreach ($this->fieldDefs as $name => $defs) {
             if (!empty($defs['auto_increment'])) {
                 $this->fieldDefs[$name]['value'] = '';
             }
         }
     }
 }
Esempio n. 6
0
 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;
 }
Esempio n. 7
0
 function process($checkFormName = false, $formName = '')
 {
     global $mod_strings, $sugar_config, $app_strings, $app_list_strings;
     //the retrieve already did this work;
     //$this->focus->fill_in_relationship_fields();
     //Bug#53261: If quickeditview is loaded after editview.tpl is created,
     //           the th->checkTemplate will return true. So, the following
     //           code prevent avoid rendering popup editview container.
     if (!empty($this->formName)) {
         $formName = $this->formName;
         $checkFormName = true;
     }
     if (!$this->th->checkTemplate($this->module, $this->view, $checkFormName, $formName)) {
         $this->render();
     }
     if (isset($_REQUEST['offset'])) {
         $this->offset = $_REQUEST['offset'] - 1;
     }
     if ($this->showVCRControl) {
         $this->th->ss->assign('PAGINATION', SugarVCR::menu($this->module, $this->offset, $this->focus->is_AuditEnabled(), $this->view == 'EditView'));
     }
     if (isset($_REQUEST['return_module'])) {
         $this->returnModule = $_REQUEST['return_module'];
     }
     if (isset($_REQUEST['return_action'])) {
         $this->returnAction = $_REQUEST['return_action'];
     }
     if (isset($_REQUEST['return_id'])) {
         $this->returnId = $_REQUEST['return_id'];
     }
     if (isset($_REQUEST['return_relationship'])) {
         $this->returnRelationship = $_REQUEST['return_relationship'];
     }
     if (isset($_REQUEST['return_name'])) {
         $this->returnName = $this->getValueFromRequest($_REQUEST, 'return_name');
     }
     // handle Create $module then Cancel
     if (empty($this->returnId)) {
         $this->returnAction = 'index';
     }
     $is_owner = $this->focus->isOwner($GLOBALS['current_user']->id);
     $this->fieldDefs = array();
     if ($this->focus) {
         global $current_user;
         if (!empty($this->focus->job) && $this->focus->job_function == '') {
             $this->focus->job_function = $this->focus->job;
         }
         if (empty($this->focus->team_id)) {
             $this->focus->team_id = $current_user->default_team;
             $this->focus->team_name = $current_user->default_team_name;
         } else {
             if (empty($this->focus->team_name)) {
                 $this->focus->team_name = Team::getTeamName($this->focus->team_id);
             }
         }
         foreach ($this->focus->toArray() as $name => $value) {
             $valueFormatted = false;
             //if ($this->focus->field_defs[$name]['type']=='link')continue;
             $this->fieldDefs[$name] = !empty($this->fieldDefs[$name]) && !empty($this->fieldDefs[$name]['value']) ? array_merge($this->focus->field_defs[$name], $this->fieldDefs[$name]) : $this->focus->field_defs[$name];
             foreach (array("formula", "default", "comments", "help") as $toEscape) {
                 if (!empty($this->fieldDefs[$name][$toEscape])) {
                     $this->fieldDefs[$name][$toEscape] = htmlentities($this->fieldDefs[$name][$toEscape], ENT_QUOTES, 'UTF-8');
                 }
             }
             if (isset($this->fieldDefs[$name]['options']) && isset($app_list_strings[$this->fieldDefs[$name]['options']])) {
                 if (isset($GLOBALS['sugar_config']['enable_autocomplete']) && $GLOBALS['sugar_config']['enable_autocomplete'] == true) {
                     $this->fieldDefs[$name]['autocomplete'] = true;
                     $this->fieldDefs[$name]['autocomplete_options'] = $this->fieldDefs[$name]['options'];
                     // we need the name for autocomplete
                 } else {
                     $this->fieldDefs[$name]['autocomplete'] = false;
                 }
                 // Bug 57472 - $this->fieldDefs[$name]['autocomplete_options' was set too late, it didn't retrieve the list's name, but the list itself (the developper comment show us that developper expected to retrieve list's name and not the options array)
                 $this->fieldDefs[$name]['options'] = $app_list_strings[$this->fieldDefs[$name]['options']];
             }
             if (isset($this->fieldDefs[$name]['options']) && is_array($this->fieldDefs[$name]['options']) && isset($this->fieldDefs[$name]['default_empty']) && !isset($this->fieldDefs[$name]['options'][$this->fieldDefs[$name]['default_empty']])) {
                 $this->fieldDefs[$name]['options'] = array_merge(array($this->fieldDefs[$name]['default_empty'] => $this->fieldDefs[$name]['default_empty']), $this->fieldDefs[$name]['options']);
             }
             if (isset($this->fieldDefs[$name]['function'])) {
                 $functionBean = isset($this->fieldDefs[$name]['function_bean']) ? $this->fieldDefs[$name]['function_bean'] : null;
                 $function = $this->fieldDefs[$name]['function'];
                 $functionArgs = array($this->focus, $name, $value, $this->view);
                 // since we are on the old edit view, we need to revert to the old way to get the currency
                 // drop down and not the new fancy way that REST needs to get it.
                 $setValueFormatted = false;
                 if ($function == 'getCurrencies' && $functionBean == 'Currencies') {
                     $function = array('returns' => 'html', 'name' => 'getCurrencyDropDown');
                     $functionBean = array();
                     $setValueFormatted = true;
                 }
                 $value = getFunctionValue($functionBean, $function, $functionArgs);
                 if ($setValueFormatted || !empty($this->fieldDefs[$name]['function']['returns']) && $this->fieldDefs[$name]['function']['returns'] == 'html') {
                     $valueFormatted = true;
                 } else {
                     $this->fieldDefs[$name]['options'] = $value;
                 }
             }
             if (isset($this->fieldDefs[$name]['type']) && $this->fieldDefs[$name]['type'] == 'function' && isset($this->fieldDefs[$name]['function_name'])) {
                 $value = $this->callFunction($this->fieldDefs[$name]);
                 $valueFormatted = true;
             }
             if (!$valueFormatted) {
                 // $this->focus->format_field($this->focus->field_defs[$name]);
                 $value = isset($this->focus->{$name}) ? $this->focus->{$name} : '';
             }
             if (empty($this->fieldDefs[$name]['value'])) {
                 $this->fieldDefs[$name]['value'] = $value;
             }
             //This code is used for QuickCreates that go to Full Form view.  We want to overwrite the values from the bean
             //with values from the request if they are set and either the bean is brand new (such as a create from a subpanels) or the 'full form' button has been clicked
             if (($this->populateBean && empty($this->focus->id) || isset($_REQUEST['full_form'])) && (!isset($this->fieldDefs[$name]['function']['returns']) || $this->fieldDefs[$name]['function']['returns'] != 'html') && isset($_REQUEST[$name])) {
                 $this->fieldDefs[$name]['value'] = $this->getValueFromRequest($_REQUEST, $name);
             }
             /*
              * Populate any relate fields that are linked by a relationship to the calling module.
              * Clicking the create button on a subpanel for example will populate three values in the $_REQUEST:
              * 1. return_module => the name of the calling module
              * 2. return_id => the id of the record in the calling module that the user was viewing and that should be associated with this new record
              * 3. return_name => the display value of the return_id record - the value to show in any relate field in this EditView
              * Only do if this fieldDef does not already have a value; if it does it will have been explicitly set, and that should overrule this less specific mechanism
              */
             if (isset($this->returnModule) && isset($this->returnName) && empty($this->focus->id) && empty($this->fieldDefs['name']['value'])) {
                 if ($this->focus->field_defs[$name]['type'] == 'relate' && isset($this->focus->field_defs[$name]['module']) && $this->focus->field_defs[$name]['module'] == $this->returnModule) {
                     if (isset($this->fieldDefs[$name]['id_name']) && !empty($this->returnRelationship) && isset($this->focus->field_defs[$this->fieldDefs[$name]['id_name']]['relationship']) && $this->returnRelationship == $this->focus->field_defs[$this->fieldDefs[$name]['id_name']]['relationship'] || !empty($this->fieldDefs[$name]['custom_module']) && !empty($this->focus->module_dir) && $this->focus->module_dir == $this->fieldDefs[$name]['custom_module']) {
                         $this->fieldDefs[$name]['value'] = $this->returnName;
                         // set the hidden id field for this relate field to the correct value i.e., return_id
                         $this->fieldDefs[$this->fieldDefs[$name]['id_name']]['value'] = $this->returnId;
                     }
                 }
             }
         }
         $this->focus->ACLFilterFieldList($this->fieldDefs, array(), array("add_acl" => true));
     }
     if (isset($this->focus->additional_meta_fields)) {
         $this->fieldDefs = array_merge($this->fieldDefs, $this->focus->additional_meta_fields);
     }
     if ($this->isDuplicate) {
         foreach ($this->fieldDefs as $name => $defs) {
             if (!empty($defs['auto_increment'])) {
                 $this->fieldDefs[$name]['value'] = '';
             }
         }
     }
 }
} else {
    $search_form->parse('main');
    $search_form->out('main');
}
// CONSTRUCT WHERE STRING FROM WHERECLAUSE ARRAY
foreach ($whereClauses as $clause) {
    if ($where != "") {
        $where .= " AND ";
    }
    $where .= $clause;
}
//echo $where;
if (isset($_REQUEST['assigned_user_id']) && $_REQUEST['assigned_user_id'] != '' && $_REQUEST['type'] == 'inbound') {
    $ListView->xTemplateAssign('TAKE', $focus->pickOneButton());
    if ($current_user->hasPersonalEmail()) {
        $ListView->xTemplateAssign('CHECK_MAIL', $focus->checkInbox('personal'));
    }
}
if (isset($_REQUEST['show_error']) && $_REQUEST['show_error'] == 'true' && $_REQUEST['type'] == 'inbound') {
    $ListView->xTemplateAssign('TAKE_ERROR', $focus->takeError());
}
//echo $focus->quickCreateJS();
$ListView->setAdditionalDetails();
$ListView->xTemplateAssign('ATTACHMENT_HEADER', SugarThemeRegistry::current()->getImage('attachment', "", "", ""));
$ListView->xTemplateAssign('ERROR', $error);
$ListView->setHeaderTitle($display_title . $header_text);
$ListView->setQuery($where, "", "date_sent, date_entered DESC", "EMAIL");
$ListView->processListView($focus, "main", "EMAIL");
$queryToStore = $focus->create_new_list_query($ListView->query_orderby, $ListView->query_where);
SugarVCR::store($focus->module_dir, $queryToStore);