2 /*********************************************************************************
3 * SugarCRM Community Edition is a customer relationship management program developed by
4 * SugarCRM, Inc. Copyright (C) 2004-2012 SugarCRM Inc.
6 * This program is free software; you can redistribute it and/or modify it under
7 * the terms of the GNU Affero General Public License version 3 as published by the
8 * Free Software Foundation with the addition of the following permission added
9 * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
10 * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
11 * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15 * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
18 * You should have received a copy of the GNU Affero General Public License along with
19 * this program; if not, see http://www.gnu.org/licenses or write to the Free
20 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23 * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
24 * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
26 * The interactive user interfaces in modified source and object code versions
27 * of this program must display Appropriate Legal Notices, as required under
28 * Section 5 of the GNU Affero General Public License version 3.
30 * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
31 * these Appropriate Legal Notices must retain the display of the "Powered by
32 * SugarCRM" logo. If the display of the logo is not reasonably feasible for
33 * technical reasons, the Appropriate Legal Notices must display the words
34 * "Powered by SugarCRM".
35 ********************************************************************************/
37 define('VCREND', '50');
38 define('VCRSTART', '10');
45 * records the query in the session for later retrieval
47 function store($module, $query){
48 $_SESSION[$module .'2_QUERY'] = $query;
52 * This function retrieves a query from the session
54 function retrieve($module){
55 return (!empty($_SESSION[$module .'2_QUERY']) ? $_SESSION[$module .'2_QUERY'] : '');
59 * return the start, prev, next, end
61 function play($module, $offset){
62 //given some global offset try to determine if we have this
65 if(!empty($_SESSION[$module.'QUERY_ARRAY']))
66 $ids = $_SESSION[$module.'QUERY_ARRAY'];
67 if(empty($ids[$offset]) || empty($ids[$offset+1]) || empty($ids[$offset-1]))
68 $ids = SugarVCR::record($module, $offset);
70 if(!empty($ids[$offset])){
71 //return the control given this id
72 $menu['PREV'] = ($offset > 1) ? $ids[$offset-1] : '';
73 $menu['CURRENT'] = $ids[$offset];
74 $menu['NEXT'] = !empty($ids[$offset+1]) ? $ids[$offset+1] : '';
79 function menu($module, $offset, $isAuditEnabled, $saveAndContinue = false ){
86 //this check if require in cases when you visit the edit view before visiting that modules list view.
87 //you can do this easily either from home, activities or sitemap.
88 $stored_vcr_query = SugarVCR::retrieve($module);
90 // bug 15893 - only show VCR if called as an element in a set of records
91 if (!empty($_REQUEST['record']) and !empty($stored_vcr_query) and isset($_REQUEST['offset']) and (empty($_REQUEST['isDuplicate']) or $_REQUEST['isDuplicate'] == 'false'))
93 //syncing with display offset;
95 $action = (!empty($_REQUEST['action']) ? $_REQUEST['action'] : 'EditView');
97 $menu = SugarVCR::play($module, $offset);
100 if ($saveAndContinue && !empty($menu['NEXT']))
102 $list_link = ajaxLink('index.php?action=' . $action . '&module=' . $module . '&record=' . $menu['NEXT'] . '&offset=' . ($offset + 1));
106 if (!empty($menu['PREV']))
108 $previous_link = ajaxLink('index.php?module=' . $module . '&action=' . $action . '&offset=' . ($offset - 1) . '&record=' . $menu['PREV']);
112 if (!empty($menu['NEXT']))
114 $next_link = ajaxLink('index.php?module=' . $module . '&action=' . $action . '&offset=' . ($offset + 1) . '&record=' . $menu['NEXT']);
117 $ss = new Sugar_Smarty();
118 $ss->assign('app_strings', $GLOBALS['app_strings']);
119 $ss->assign('module', $module);
120 $ss->assign('action', $action);
121 $ss->assign('menu', $menu);
122 $ss->assign('list_link', $list_link);
123 $ss->assign('previous_link', $previous_link);
124 $ss->assign('next_link', $next_link);
126 $ss->assign('offset', $offset);
127 $ss->assign('total', '');
128 $ss->assign('plus', '');
130 if (!empty($_SESSION[$module . 'total']))
132 $ss->assign('total', $_SESSION[$module . 'total']);
134 !empty($GLOBALS['sugar_config']['disable_count_query'])
135 && (($_SESSION[$module. 'total']-1) % $GLOBALS['sugar_config']['list_max_entries_per_page'] == 0)
138 $ss->assign('plus', '+');
142 if (is_file('custom/include/EditView/SugarVCR.tpl'))
144 $html_text .= $ss->fetch('custom/include/EditView/SugarVCR.tpl');
148 $html_text .= $ss->fetch('include/EditView/SugarVCR.tpl');
154 function record($module, $offset){
155 $GLOBALS['log']->debug('SUGARVCR is recording more records');
156 $start = max(0, $offset - VCRSTART);
158 $db = DBManagerFactory::getInstance();
160 $result = $db->limitQuery(SugarVCR::retrieve($module),$start,($offset+VCREND),false);
164 while(($row = $db->fetchByAssoc($result)) != null){
165 $ids[$index] = $row['id'];
168 //now that we have the array of ids, store this in the session
169 $_SESSION[$module.'QUERY_ARRAY'] = $ids;
173 function recordIDs($module, $rids, $offset, $totalCount){
177 foreach($rids as $id){
181 //now that we have the array of ids, store this in the session
182 $_SESSION[$module.'QUERY_ARRAY'] = $ids;
183 $_SESSION[$module.'total'] = $totalCount;
186 function erase($module){
187 unset($_SESSION[$module. 'QUERY_ARRAY']);