]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - include/EditView/SugarVCR.php
Release 6.4.0
[Github/sugarcrm.git] / include / EditView / SugarVCR.php
1 <?php
2 /*********************************************************************************
3  * SugarCRM Community Edition is a customer relationship management program developed by
4  * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
5  * 
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.
12  * 
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
16  * details.
17  * 
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
21  * 02110-1301 USA.
22  * 
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.
25  * 
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.
29  * 
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  ********************************************************************************/
36
37  define('VCREND', '50');
38  define('VCRSTART', '10');
39  /**
40   * @api
41   */
42  class SugarVCR{
43
44         /**
45          * records the query in the session for later retrieval
46          */
47         function store($module, $query){
48                 $_SESSION[$module .'2_QUERY'] = $query;
49         }
50
51         /**
52          * This function retrieves a query from the session
53          */
54         function retrieve($module){
55                 return (!empty($_SESSION[$module .'2_QUERY']) ? $_SESSION[$module .'2_QUERY'] : '');
56         }
57
58         /**
59          * return the start, prev, next, end
60          */
61         function play($module, $offset){
62                 //given some global offset try to determine if we have this
63                 //in our array.
64                 $ids = array();
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);
69                 $menu = array();
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] : '';
75                 }
76                 return $menu;
77         }
78
79         function menu($module, $offset, $isAuditEnabled, $saveAndContinue = false ){
80                 $html_text = "";
81                 if($offset < 0) {
82                         $offset = 0;
83                 }
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;
89                         $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";
94
95                         $list_URL = 'index.php?action=index&module='.$module;
96                         $current_page = floor($offset / 20) * 20;
97                         $list_URL .= '&offset='.$current_page;
98
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>";
106                                 }else
107                                         $list_link = "";
108                         }else
109                                 $list_link = "";
110
111                         $previous_link = "";
112                         $next_link = "";
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']).'&nbsp;'.$GLOBALS['app_strings']['LNK_LIST_PREVIOUS']."</a>";
115
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>";
118
119                         }
120                         else
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>";
122
123
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'].'&nbsp;'.SugarThemeRegistry::current()->getImage("next","border='0' align='absmiddle'",null,null,'.gif',$GLOBALS['app_strings']['LNK_LIST_NEXT'])."</a>";
126
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>";
129
130                         }
131                         else
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>";
133
134
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 ) ) {
139                     $count .= '+';
140                 }
141                         }else{
142                                 $count = $offset;
143                         }
144                         $html_text .= "<td nowrap align='right' >".$list_link."&nbsp;&nbsp;&nbsp;&nbsp;<span class='pagination'>".$previous_link."&nbsp;&nbsp;(".$count.")&nbsp;&nbsp;".$next_link."</span>&nbsp;&nbsp;</td>";
145
146
147
148                         $html_text .= "</tr></table>";//</td></tr>";
149                 }
150                 return $html_text;
151         }
152
153         function record($module, $offset){
154                 $GLOBALS['log']->debug('SUGARVCR is recording more records');
155                 $start = max(0, $offset - VCRSTART);
156                 $index = $start;
157             $db = DBManagerFactory::getInstance();
158
159                 $result = $db->limitQuery(SugarVCR::retrieve($module),$start,($offset+VCREND),false);
160                 $index++;
161
162                 $ids = array();
163                 while(($row = $db->fetchByAssoc($result)) != null){
164                         $ids[$index] = $row['id'];
165                         $index++;
166                 }
167                 //now that we have the array of ids, store this in the session
168                 $_SESSION[$module.'QUERY_ARRAY'] = $ids;
169                 return $ids;
170         }
171
172         function recordIDs($module, $rids, $offset, $totalCount){
173                 $index = $offset;
174                 $index++;
175                 $ids = array();
176                 foreach($rids as $id){
177                         $ids[$index] = $id;
178                         $index++;
179                 }
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;
183         }
184
185         function erase($module){
186                 unset($_SESSION[$module. 'QUERY_ARRAY']);
187         }
188
189  }
190 ?>