2 /*********************************************************************************
3 * SugarCRM is a customer relationship management program developed by
4 * SugarCRM, Inc. Copyright (C) 2004-2011 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 ********************************************************************************/
38 * Created on Jul 24, 2007
40 * To change the template for this generated file go to
41 * Window - Preferences - PHPeclipse - PHP - Code Templates
43 define('VCREND', '50');
44 define('VCRSTART', '10');
48 * records the query in the session for later retrieval
50 function store($module, $query){
51 $_SESSION[$module .'2_QUERY'] = $query;
55 * This function retrieves a query from the session
57 function retrieve($module){
58 return (!empty($_SESSION[$module .'2_QUERY']) ? $_SESSION[$module .'2_QUERY'] : '');
62 * return the start, prev, next, end
64 function play($module, $offset){
65 //given some global offset try to determine if we have this
68 if(!empty($_SESSION[$module.'QUERY_ARRAY']))
69 $ids = $_SESSION[$module.'QUERY_ARRAY'];
70 if(empty($ids[$offset]) || empty($ids[$offset+1]) || empty($ids[$offset-1]))
71 $ids = SugarVCR::record($module, $offset);
73 if(!empty($ids[$offset])){
74 //return the control given this id
75 $menu['PREV'] = ($offset > 1) ? $ids[$offset-1] : '';
76 $menu['CURRENT'] = $ids[$offset];
77 $menu['NEXT'] = !empty($ids[$offset+1]) ? $ids[$offset+1] : '';
82 function menu($module, $offset, $isAuditEnabled, $saveAndContinue = false ){
87 //this check if require in cases when you visit the edit view before visiting that modules list view.
88 //you can do this easily either from home or activies or sitemap.
89 $stored_vcr_query=SugarVCR::retrieve($module);
90 if(!empty($_REQUEST['record']) and !empty($stored_vcr_query) and isset($_REQUEST['offset']) and (empty($_REQUEST['isDuplicate']) or $_REQUEST['isDuplicate'] == 'false')){ // bug 15893 - only show VCR if called as an element in a set of records
91 //syncing with display offset;
93 $action = (!empty($_REQUEST['action']) ? $_REQUEST['action'] : 'EditView');
94 //$html_text .= "<tr class='pagination'>\n";
95 //$html_text .= "<td COLSPAN=\"20\" style='padding: 0px;'>\n";
96 $html_text .= "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\"><tr>\n";
98 $list_URL = 'index.php?action=index&module='.$module;
99 $current_page = floor($offset / 20) * 20;
100 $list_URL .= '&offset='.$current_page;
102 $menu = SugarVCR::play($module, $offset);
103 if($saveAndContinue){
104 if(!empty($menu['NEXT'])){
105 $return_action = 'EditView';
106 $return_id = $menu['NEXT'];
107 $list_URL = 'index.php?action=EditView&module='.$module.'&record='.$return_id.'&offset='.($offset+1);
108 $list_link = "<button type='button' id='save_and_continue' class='button' title='{$GLOBALS['app_strings']['LBL_SAVE_AND_CONTINUE']}' onClick='this.form.action.value=\"Save\";if(check_form(\"EditView\")){sendAndRedirect(\"EditView\", \"{$GLOBALS['app_strings']['LBL_SAVING']} {$module}...\", \"$list_URL\");}'>".$GLOBALS['app_strings']['LBL_SAVE_AND_CONTINUE']."</button>";
116 if(!empty($menu['PREV'])) {
117 //$previous_link = "<a href='index.php?module=$module&action=$action&offset=".($offset-1)."&record=".$menu['PREV']."' >".SugarThemeRegistry::current()->getImage("previous","alt='".$GLOBALS['app_strings']['LNK_LIST_PREVIOUS']."' border='0' align='absmiddle'").' '.$GLOBALS['app_strings']['LNK_LIST_PREVIOUS']."</a>";
118 $href = "index.php?module=$module&action=$action&offset=".($offset-1)."&record=".$menu['PREV'];
119 $previous_link = "<button type='button' class='button' title='{$GLOBALS['app_strings']['LNK_LIST_PREVIOUS']}' onClick='document.location.href=\"$href\";'>".SugarThemeRegistry::current()->getImage("previous","alt='".$GLOBALS['app_strings']['LNK_LIST_PREVIOUS']."' border='0' align='absmiddle'")."</button>";
122 $previous_link = "<button type='button' class='button' title='{$GLOBALS['app_strings']['LNK_LIST_PREVIOUS']}' disabled>".SugarThemeRegistry::current()->getImage("previous_off","alt='".$GLOBALS['app_strings']['LNK_LIST_PREVIOUS']."' border='0' align='absmiddle'")."</button>";
124 if(!empty($menu['NEXT'])) {
125 //$next_link = "<a href='index.php?module=$module&action=$action&offset=".($offset+1)."&record=".$menu['NEXT']."' >".$GLOBALS['app_strings']['LNK_LIST_NEXT'].' '.SugarThemeRegistry::current()->getImage("next","alt='".$GLOBALS['app_strings']['LNK_LIST_NEXT']."' border='0' align='absmiddle'")."</a>";
126 $href = "index.php?module=$module&action=$action&offset=".($offset+1)."&record=".$menu['NEXT'];
127 $next_link = "<button type='button' class='button' title='{$GLOBALS['app_strings']['LNK_LIST_NEXT']}' onClick='document.location.href=\"$href\";'>".SugarThemeRegistry::current()->getImage("next","alt='".$GLOBALS['app_strings']['LNK_LIST_NEXT']."' border='0' align='absmiddle'")."</button>";
130 $next_link = "<button type='button' class='button' title='{$GLOBALS['app_strings']['LNK_LIST_NEXT']}' disabled>".SugarThemeRegistry::current()->getImage("next_off","alt='".$GLOBALS['app_strings']['LNK_LIST_NEXT']."' border='0' align='absmiddle'")."</button>";
132 if(!empty($_SESSION[$module. 'total'])){
133 $count = $offset .' '. $GLOBALS['app_strings']['LBL_LIST_OF'] . ' ' . $_SESSION[$module. 'total'];
134 if(!empty($GLOBALS['sugar_config']['disable_count_query'])
135 && ( ($_SESSION[$module. 'total']-1) % $GLOBALS['sugar_config']['list_max_entries_per_page'] == 0 ) ) {
141 $html_text .= "<td nowrap align='right' >".$list_link." <span class='pagination'>".$previous_link." (".$count.") ".$next_link."</span> </td>";
145 $html_text .= "</tr></table>";//</td></tr>";
150 function record($module, $offset){
151 $GLOBALS['log']->debug('SUGARVCR is recording more records');
152 $start = max(0, $offset - VCRSTART);
154 $db = DBManagerFactory::getInstance();
156 $result = $db->limitQuery(SugarVCR::retrieve($module),$start,($offset+VCREND),false);
160 while(($row = $db->fetchByAssoc($result)) != null){
161 $ids[$index] = $row['id'];
164 //now that we have the array of ids, store this in the session
165 $_SESSION[$module.'QUERY_ARRAY'] = $ids;
169 function recordIDs($module, $rids, $offset, $totalCount){
173 foreach($rids as $id){
177 //now that we have the array of ids, store this in the session
178 $_SESSION[$module.'QUERY_ARRAY'] = $ids;
179 $_SESSION[$module.'total'] = $totalCount;
182 function erase($module){
183 unset($_SESSION[$module. 'QUERY_ARRAY']);