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 ){
84 //this check if require in cases when you visit the edit view before visiting that modules list view.
85 //you can do this easily either from home or activies or sitemap.
86 $stored_vcr_query=SugarVCR::retrieve($module);
87 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
88 //syncing with display offset;
90 $action = (!empty($_REQUEST['action']) ? $_REQUEST['action'] : 'EditView');
91 //$html_text .= "<tr class='pagination'>\n";
92 //$html_text .= "<td COLSPAN=\"20\" style='padding: 0px;'>\n";
93 $html_text .= "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\"><tr>\n";
95 $list_URL = 'index.php?action=index&module='.$module;
96 $current_page = floor($offset / 20) * 20;
97 $list_URL .= '&offset='.$current_page;
99 $menu = SugarVCR::play($module, $offset);
100 if($saveAndContinue){
101 if(!empty($menu['NEXT'])){
102 $return_action = 'EditView';
103 $return_id = $menu['NEXT'];
104 $list_URL = ajaxLink('index.php?action=EditView&module='.$module.'&record='.$return_id.'&offset='.($offset+1));
105 $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>";
113 if(!empty($menu['PREV'])) {
114 //$previous_link = "<a href='index.php?module=$module&action=$action&offset=".($offset-1)."&record=".$menu['PREV']."' >".SugarThemeRegistry::current()->getImage("previous","border='0' align='absmiddle'",null,null,'.gif',$GLOBALS['app_strings']['LNK_LIST_PREVIOUS']).' '.$GLOBALS['app_strings']['LNK_LIST_PREVIOUS']."</a>";
116 $href = ajaxLink("index.php?module=$module&action=$action&offset=".($offset-1)."&record=".$menu['PREV']);
117 $previous_link = "<button type='button' class='button' title='{$GLOBALS['app_strings']['LNK_LIST_PREVIOUS']}' onClick='document.location.href=\"$href\";'>".SugarThemeRegistry::current()->getImage("previous","border='0' align='absmiddle'",null,null,'.gif',$GLOBALS['app_strings']['LNK_LIST_PREVIOUS'])."</button>";
121 $previous_link = "<button type='button' class='button' title='{$GLOBALS['app_strings']['LNK_LIST_PREVIOUS']}' disabled>".SugarThemeRegistry::current()->getImage("previous_off","border='0' align='absmiddle'",null,null,'.gif',$GLOBALS['app_strings']['LNK_LIST_PREVIOUS'])."</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","border='0' align='absmiddle'",null,null,'.gif',$GLOBALS['app_strings']['LNK_LIST_NEXT'])."</a>";
127 $href = ajaxLink("index.php?module=$module&action=$action&offset=".($offset+1)."&record=".$menu['NEXT']);
128 $next_link = "<button type='button' class='button' title='{$GLOBALS['app_strings']['LNK_LIST_NEXT']}' onClick='document.location.href=\"$href\";'>".SugarThemeRegistry::current()->getImage("next","border='0' align='absmiddle'",null,null,'.gif',$GLOBALS['app_strings']['LNK_LIST_NEXT'])."</button>";
132 $next_link = "<button type='button' class='button' title='{$GLOBALS['app_strings']['LNK_LIST_NEXT']}' disabled>".SugarThemeRegistry::current()->getImage("next_off","border='0' align='absmiddle'",null,null,'.gif',$GLOBALS['app_strings']['LNK_LIST_NEXT'])."</button>";
135 if(!empty($_SESSION[$module. 'total'])){
136 $count = $offset .' '. $GLOBALS['app_strings']['LBL_LIST_OF'] . ' ' . $_SESSION[$module. 'total'];
137 if(!empty($GLOBALS['sugar_config']['disable_count_query'])
138 && ( ($_SESSION[$module. 'total']-1) % $GLOBALS['sugar_config']['list_max_entries_per_page'] == 0 ) ) {
144 $html_text .= "<td nowrap align='right' >".$list_link." <span class='pagination'>".$previous_link." (".$count.") ".$next_link."</span> </td>";
148 $html_text .= "</tr></table>";//</td></tr>";
153 function record($module, $offset){
154 $GLOBALS['log']->debug('SUGARVCR is recording more records');
155 $start = max(0, $offset - VCRSTART);
157 $db = DBManagerFactory::getInstance();
159 $result = $db->limitQuery(SugarVCR::retrieve($module),$start,($offset+VCREND),false);
163 while(($row = $db->fetchByAssoc($result)) != null){
164 $ids[$index] = $row['id'];
167 //now that we have the array of ids, store this in the session
168 $_SESSION[$module.'QUERY_ARRAY'] = $ids;
172 function recordIDs($module, $rids, $offset, $totalCount){
176 foreach($rids as $id){
180 //now that we have the array of ids, store this in the session
181 $_SESSION[$module.'QUERY_ARRAY'] = $ids;
182 $_SESSION[$module.'total'] = $totalCount;
185 function erase($module){
186 unset($_SESSION[$module. 'QUERY_ARRAY']);