limitName = 'list_max_entries_per_page'; $this->db = &DBManagerFactory::getInstance ( 'listviews' ); } /** * checks the request for the order by and if that is not set then it checks the session for it * * @return array containing the keys orderBy => field being ordered off of and sortOrder => the sort order of that field */ function getOrderBy($orderBy = '', $direction = '') { if (! empty ( $orderBy ) || ! empty ( $_REQUEST [$this->var_order_by] )) { if (! empty ( $_REQUEST [$this->var_order_by] )) { $direction = 'ASC'; $orderBy = $_REQUEST [$this->var_order_by]; if (! empty ( $_REQUEST ['lvso'] ) && (empty ( $_SESSION ['lvd'] ['last_ob'] ) || strcmp ( $orderBy, $_SESSION ['lvd'] ['last_ob'] ) == 0)) { $direction = $_REQUEST ['lvso']; $trackerManager = TrackerManager::getInstance (); if ($monitor = $trackerManager->getMonitor ( 'tracker' )) { $monitor->setValue ( 'module_name', $GLOBALS ['module'] ); $monitor->setValue ( 'item_summary', "lvso=" . $direction . "&" . $this->var_order_by . "=" . $_REQUEST [$this->var_order_by] ); $monitor->setValue ( 'action', 'listview' ); $monitor->setValue ( 'user_id', $GLOBALS ['current_user']->id ); $monitor->setValue ( 'date_modified', gmdate ( $GLOBALS ['timedate']->get_db_date_time_format () ) ); $monitor->save (); } } } $_SESSION [$this->var_order_by] = array ( 'orderBy' => $orderBy, 'direction' => $direction ); $_SESSION ['lvd'] ['last_ob'] = $orderBy; } else { if (! empty ( $_SESSION [$this->var_order_by] )) { $orderBy = $_SESSION [$this->var_order_by] ['orderBy']; $direction = $_SESSION [$this->var_order_by] ['direction']; } } return array ( 'orderBy' => $orderBy, 'sortOrder' => $direction ); } /** * gets the reverse of the sort order for use on links to reverse a sort order from what is currently used * * @param * STRING (ASC or DESC) $current_order * @return STRING (ASC or DESC) */ function getReverseSortOrder($current_order) { return (strcmp ( strtolower ( $current_order ), 'asc' ) == 0) ? 'DESC' : 'ASC'; } /** * gets the limit of how many rows to show per page * * @return INT (the limit) */ function getLimit() { return $GLOBALS ['sugar_config'] [$this->limitName]; } /** * returns the current offset * * @return INT (current offset) */ function getOffset() { return (! empty ( $_REQUEST [$this->var_offset] )) ? $_REQUEST [$this->var_offset] : 0; } /** * generates the base url without * any files in the block variables will not be part of the url * * * @return STRING (the base url) */ function getBaseURL() { global $beanList; if (empty ( $this->base_url )) { $blockVariables = array ( 'mass', 'uid', 'massupdate', 'delete', 'merge', 'selectCount', $this->var_order_by, $this->var_offset, 'lvso', 'sortOrder', 'orderBy', 'request_data', 'current_query_by_page' ); $base_url = 'index.php?'; foreach ( $beanList as $bean ) { $blockVariables [] = 'Home2_' . strtoupper ( $bean ) . '_ORDER_BY'; } $blockVariables [] = 'Home2_CASE_ORDER_BY'; $params = array (); if (isset ( $_POST ) && is_array ( $_POST )) { $params = array_merge ( $params, $_POST ); } if (isset ( $_GET ) && is_array ( $_GET )) { $params = array_merge ( $params, $_GET ); } foreach ( $params as $name => $value ) { if (! in_array ( $name, $blockVariables )) { if (is_array ( $value )) { foreach ( $value as $v ) { $base_url .= $name . urlencode ( '[]' ) . '=' . urlencode ( $v ) . '&'; } } else { $base_url .= $name . '=' . urlencode ( $value ) . '&'; } } } $this->base_url = $base_url; } return $this->base_url; } /** * based off of a base name it sets base, offset, and order by variable names to retrieve them from requests and sessions * * @param unknown_type $baseName */ function setVariableName($baseName, $where, $listviewName = null) { global $timedate; $module = (! empty ( $listviewName )) ? $listviewName : $_REQUEST ['module']; $this->var_name = $module . '2_' . strtoupper ( $baseName ); $this->var_order_by = $this->var_name . '_ORDER_BY'; $this->var_offset = $this->var_name . '_offset'; $timestamp = $timedate->get_microtime_string (); $this->stamp = $timestamp; $_SESSION [$module . '2_QUERY_QUERY'] = $where; $_SESSION [strtoupper ( $baseName ) . "_FROM_LIST_VIEW"] = $timestamp; $_SESSION [strtoupper ( $baseName ) . "_DETAIL_NAV_HISTORY"] = false; } function getTotalCount($main_query) { if (! empty ( $this->count_query )) { $count_query = $this->count_query; } else { $count_query = SugarBean::create_list_count_query ( $main_query ); } $result = $this->db->query ( $count_query ); if ($row = $this->db->fetchByAssoc ( $result )) { return $row ['c']; } return 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 */ function getListViewData($seed, $where, $offset = -1, $limit = -1, $filter_fields = array(), $params = array(), $id_field = 'id') { global $current_user; // add mz 2014-08-19 $where = str_replace ( "like '", "like '%", $where ); // end mz 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 (! 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 $ret_array = $seed->create_new_list_query ( $orderBy, $where, $filter_fields, $params, 0, '', true, $seed, true ); $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'] = ''; // add mz 2014-05-13 if (isset ( $_REQUEST ['custom_parent_id'] )) { $params ['custom_where'] = " AND parent_id='" . $_REQUEST ['custom_parent_id'] . "'"; $ret_array ['where'] = ' where ecmstockoperations.deleted=0'; } 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 ($_REQUEST ['parent_id'] != "") { if ($_REQUEST ['module'] == 'Documents') { $custom_join = " inner join documents_accounts on documents.id = documents_accounts.document_id "; $custom_where = " and documents_accounts.parent_id='" . $_REQUEST ['parent_id'] . "'"; $main_query = $ret_array ['select'] . $params ['custom_select'] . $ret_array ['from'] . $params ['custom_from'] . $ret_array ['inner_join'] . $custom_join . $ret_array ['where'] . $params ['custom_where'] . $custom_where . $ret_array ['order_by'] . $params ['custom_order_by']; } else { $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']; } } else { if($_REQUEST['module']=='EcmWorkCards'){ if($orderBy=='date asc'){ $innerString=' inner join ecmworkers on ecmworkers.id=ecmworkcards.worker_id'; $orderString=' order by ecmworkcards.date asc, ecmworkers.last_name asc,ecmworkcards.time_from asc'; } if($orderBy=='date desc'){ $innerString=' inner join ecmworkers on ecmworkers.id=ecmworkcards.worker_id'; $orderString=' order by ecmworkcards.date desc, ecmworkers.last_name desc,ecmworkcards.time_from desc'; } if($orderBy=='worker_name asc'){ $innerString=' inner join ecmworkers on ecmworkers.id=ecmworkcards.worker_id'; $orderString=' order by ecmworkers.last_name asc'; } if($orderBy=='worker_name desc'){ $innerString=' inner join ecmworkers on ecmworkers.id=ecmworkcards.worker_id'; $orderString=' order by ecmworkers.last_name desc'; } $main_query = $ret_array ['select'] . $params ['custom_select'] . $ret_array ['from'] . $params ['custom_from'] . $ret_array ['inner_join'] . $innerString . $ret_array ['where'] . $params ['custom_where'].$orderString; // echo $main_query; } else { $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']; } } if (empty ( $_REQUEST ['action'] ) || $_REQUEST ['action'] != 'Popup') { $_SESSION ['export_where'] = $ret_array ['where']; } if ($_REQUEST ['module'] == 'Accounts') { $lead_query = str_replace ( 'accounts', 'leads', $main_query ); $leads = $this->db->query ( $lead_query ); if ($leads->num_rows > 0) echo '
" : '');
$extra .= (! empty ( $results ['viewLink'] ) ? "
" : '') . "', DELAY, 200, STICKY, MOUSEOFF, 1000, WIDTH, " . (empty ( $results ['width'] ) ? '300' : $results ['width']) . ", CLOSETEXT, '
" : '');
$extra .= (! empty ( $results ['viewLink'] ) ? "
" : '') . "', DELAY, 200, STICKY, MOUSEOFF, 1000, WIDTH, " . (empty ( $results ['width'] ) ? '300' : $results ['width']) . ", CLOSETEXT, '->getImageURL ( 'close.gif' ) . )