]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/ModuleBuilder/views/view.history.php
Release 6.5.0
[Github/sugarcrm.git] / modules / ModuleBuilder / views / view.history.php
1 <?php
2 /*********************************************************************************
3  * SugarCRM Community Edition is a customer relationship management program developed by
4  * SugarCRM, Inc. Copyright (C) 2004-2012 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
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') ;
41
42 class ViewHistory extends SugarView
43 {
44     var $pageSize = 10 ;
45
46     /**
47          * @see SugarView::_getModuleTitleParams()
48          */
49         protected function _getModuleTitleParams($browserTitle = false)
50         {
51             global $mod_strings;
52             
53         return array(
54            translate('LBL_MODULE_NAME','Administration'),
55            ModuleBuilderController::getModuleTitle(),
56            );
57     }
58
59         function display ()
60     {
61         $this->layout = strtolower ( $_REQUEST [ 'view' ] ) ;
62         
63         $subpanelName = null ;
64         if ((strtolower ( $this->layout ) == 'listview') && (!empty ( $_REQUEST [ 'subpanel' ] )))
65         {
66             $subpanelName = $_REQUEST [ 'subpanel' ] ;
67             
68         }
69         
70         $packageName = (isset ( $_REQUEST [ 'view_package' ] ) && (strtolower ( $_REQUEST [ 'view_package' ] ) != 'studio')) ? $_REQUEST [ 'view_package' ] : null ;
71         $this->module = $_REQUEST [ 'view_module' ] ;
72         
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}" ) ;
77         $this->$action () ;
78     }
79
80     function browse ()
81     {
82         $smarty = new Sugar_Smarty ( ) ;
83         global $mod_strings ;
84         $smarty->assign ( 'mod_strings', $mod_strings ) ;
85         $smarty->assign ( 'view_module', $this->module ) ;
86         $smarty->assign ( 'view', $this->layout ) ;
87         
88         if (! empty ( $_REQUEST [ 'subpanel' ] ))
89         {
90             $smarty->assign ( 'subpanel', $_REQUEST [ 'subpanel' ] ) ;
91         }
92         $stamps = array ( ) ;
93         global $timedate ;
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 ++ )
100         {
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 () ;
107         }
108         if (count ( $snapshots ) > $this->pageSize)
109         {
110             $smarty->assign ( 'nextPage', true ) ;
111         }
112         $snapshots = array_slice ( $snapshots, 0, $this->pageSize, true ) ;
113         $smarty->assign ( 'currentPage', $page ) ;
114         $smarty->assign ( 'snapshots', $snapshots ) ;
115         
116         $html = $smarty->fetch ( 'modules/ModuleBuilder/tpls/history.tpl' ) ;
117         echo $html ;
118     }
119
120     function preview ()
121     {
122         global $mod_strings ;
123         if (! isset ( $_REQUEST [ 'sid' ] ))
124         {
125             die ( 'SID Required' ) ;
126         }
127         $sid = $_REQUEST [ 'sid' ] ;
128         $subpanel = '';
129         if (! empty ( $_REQUEST [ 'subpanel' ] ))
130         {
131             $subpanel = ',"' . $_REQUEST [ 'subpanel' ] . '"' ;
132         }
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 ) ;
138         $view ;
139         if ($this->layout == 'listview')
140         {
141             require_once ("modules/ModuleBuilder/views/view.listview.php") ;
142             $view = new ViewListView ( ) ;
143         } else if ($this->layout == 'basic_search' || $this->layout == 'advanced_search')
144         {
145             require_once ("modules/ModuleBuilder/views/view.searchview.php") ;
146             $view = new ViewSearchView ( ) ;
147         } else if ($this->layout == 'dashlet' || $this->layout == 'dashletsearch')
148         {
149                 require_once ("modules/ModuleBuilder/views/view.dashlet.php") ;
150                 $view = new ViewDashlet ( ) ;
151         }  else if ($this->layout == 'popuplist' || $this->layout == 'popupsearch')
152         {
153                 require_once ("modules/ModuleBuilder/views/view.popupview.php") ;
154                 $view = new ViewPopupview ( ) ;
155         } else
156         {
157             require_once ("modules/ModuleBuilder/views/view.layoutview.php") ;
158             $view = new ViewLayoutView ( ) ;
159         }
160         
161         $view->display ( true ) ;
162         $this->history->undoRestore () ;
163     }
164
165     function restore ()
166     {
167         if (! isset ( $_REQUEST [ 'sid' ] ))
168         {
169             die ( 'SID Required' ) ;
170         }
171         $sid = $_REQUEST [ 'sid' ] ;
172         $this->history->restoreByTimestamp ( $sid ) ;
173     }
174
175         /**
176          * Restores a layout to its current customized state. 
177          * Called when leaving a restored layout without saving.
178          */
179     function unrestore() 
180     {
181         $this->history->undoRestore () ;
182     }
183 }