2 /*********************************************************************************
3 * SugarCRM Community Edition 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 require_once ('modules/ModuleBuilder/MB/AjaxCompose.php') ;
39 require_once ('modules/ModuleBuilder/parsers/views/History.php') ;
40 require_once ('modules/ModuleBuilder/parsers/ParserFactory.php') ;
42 class ViewHistory extends SugarView
47 * @see SugarView::_getModuleTitleParams()
49 protected function _getModuleTitleParams($browserTitle = false)
54 translate('LBL_MODULE_NAME','Administration'),
55 ModuleBuilderController::getModuleTitle(),
61 $this->layout = strtolower ( $_REQUEST [ 'view' ] ) ;
63 $subpanelName = null ;
64 if ((strtolower ( $this->layout ) == 'listview') && (!empty ( $_REQUEST [ 'subpanel' ] )))
66 $subpanelName = $_REQUEST [ 'subpanel' ] ;
70 $packageName = (isset ( $_REQUEST [ 'view_package' ] ) && (strtolower ( $_REQUEST [ 'view_package' ] ) != 'studio')) ? $_REQUEST [ 'view_package' ] : null ;
71 $this->module = $_REQUEST [ 'view_module' ] ;
73 $this->parser = ParserFactory::getParser ( $this->layout, $this->module, $packageName, $subpanelName ) ;
74 $this->history = $this->parser->getHistory () ;
75 $action = ! empty ( $_REQUEST [ 'histAction' ] ) ? $_REQUEST [ 'histAction' ] : 'browse' ;
76 $GLOBALS['log']->debug( get_class($this)."->display(): performing History action {$action}" ) ;
82 $smarty = new Sugar_Smarty ( ) ;
84 $smarty->assign ( 'mod_strings', $mod_strings ) ;
85 $smarty->assign ( 'view_module', $this->module ) ;
86 $smarty->assign ( 'view', $this->layout ) ;
88 if (! empty ( $_REQUEST [ 'subpanel' ] ))
90 $smarty->assign ( 'subpanel', $_REQUEST [ 'subpanel' ] ) ;
94 $userFormat = $timedate->get_date_time_format () ;
95 $page = ! empty ( $_REQUEST [ 'page' ] ) ? $_REQUEST [ 'page' ] : 0 ;
96 $count = $this->history->getCount();
97 $ts = $this->history->getNth ( $page * $this->pageSize ) ;
98 $snapshots = array ( ) ;
99 for ( $i = 0 ; $i <= $this->pageSize && $ts > 0 ; $i ++ )
101 $dbDate = $timedate->fromTimestamp($ts)->asDb();
102 $displayTS = $timedate->to_display_date_time ( $dbDate ) ;
103 if ($page * $this->pageSize + $i + 1 == $count)
104 $displayTS = translate("LBL_MB_DEFAULT_LAYOUT");
105 $snapshots [ $ts ] = $displayTS ;
106 $ts = $this->history->getNext () ;
108 if (count ( $snapshots ) > $this->pageSize)
110 $smarty->assign ( 'nextPage', true ) ;
112 $snapshots = array_slice ( $snapshots, 0, $this->pageSize, true ) ;
113 $smarty->assign ( 'currentPage', $page ) ;
114 $smarty->assign ( 'snapshots', $snapshots ) ;
116 $html = $smarty->fetch ( 'modules/ModuleBuilder/tpls/history.tpl' ) ;
122 global $mod_strings ;
123 if (! isset ( $_REQUEST [ 'sid' ] ))
125 die ( 'SID Required' ) ;
127 $sid = $_REQUEST [ 'sid' ] ;
129 if (! empty ( $_REQUEST [ 'subpanel' ] ))
131 $subpanel = ',"' . $_REQUEST [ 'subpanel' ] . '"' ;
133 echo "<input type='button' name='close$sid' value='". translate ( 'LBL_BTN_CLOSE' )."' " .
134 "class='button' onclick='ModuleBuilder.tabPanel.removeTab(ModuleBuilder.tabPanel.get(\"activeTab\"));' style='margin:5px;'>" .
135 "<input type='button' name='restore$sid' value='" . translate ( 'LBL_MB_RESTORE' ) . "' " .
136 "class='button' onclick='ModuleBuilder.history.revert(\"$this->module\",\"{$this->layout}\",\"$sid\"$subpanel);' style='margin:5px;'>" ;
137 $this->history->restoreByTimestamp ( $sid ) ;
139 if ($this->layout == 'listview')
141 require_once ("modules/ModuleBuilder/views/view.listview.php") ;
142 $view = new ViewListView ( ) ;
143 } else if ($this->layout == 'basic_search' || $this->layout == 'advanced_search')
145 require_once ("modules/ModuleBuilder/views/view.searchview.php") ;
146 $view = new ViewSearchView ( ) ;
147 } else if ($this->layout == 'dashlet' || $this->layout == 'dashletsearch')
149 require_once ("modules/ModuleBuilder/views/view.dashlet.php") ;
150 $view = new ViewDashlet ( ) ;
151 } else if ($this->layout == 'popuplist' || $this->layout == 'popupsearch')
153 require_once ("modules/ModuleBuilder/views/view.popupview.php") ;
154 $view = new ViewPopupview ( ) ;
157 require_once ("modules/ModuleBuilder/views/view.layoutview.php") ;
158 $view = new ViewLayoutView ( ) ;
161 $view->display ( true ) ;
162 $this->history->undoRestore () ;
167 if (! isset ( $_REQUEST [ 'sid' ] ))
169 die ( 'SID Required' ) ;
171 $sid = $_REQUEST [ 'sid' ] ;
172 $this->history->restoreByTimestamp ( $sid ) ;
176 * Restores a layout to its current customized state.
177 * Called when leaving a restored layout without saving.
181 $this->history->undoRestore () ;