]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/Administration/views/view.backups.php
Release 6.5.1
[Github/sugarcrm.git] / modules / Administration / views / view.backups.php
1 <?php
2 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
3 /*********************************************************************************
4  * SugarCRM Community Edition is a customer relationship management program developed by
5  * SugarCRM, Inc. Copyright (C) 2004-2012 SugarCRM Inc.
6  * 
7  * This program is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU Affero General Public License version 3 as published by the
9  * Free Software Foundation with the addition of the following permission added
10  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
11  * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
12  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
13  * 
14  * This program is distributed in the hope that it will be useful, but WITHOUT
15  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16  * FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
17  * details.
18  * 
19  * You should have received a copy of the GNU Affero General Public License along with
20  * this program; if not, see http://www.gnu.org/licenses or write to the Free
21  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22  * 02110-1301 USA.
23  * 
24  * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
25  * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
26  * 
27  * The interactive user interfaces in modified source and object code versions
28  * of this program must display Appropriate Legal Notices, as required under
29  * Section 5 of the GNU Affero General Public License version 3.
30  * 
31  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
32  * these Appropriate Legal Notices must retain the display of the "Powered by
33  * SugarCRM" logo. If the display of the logo is not reasonably feasible for
34  * technical reasons, the Appropriate Legal Notices must display the words
35  * "Powered by SugarCRM".
36  ********************************************************************************/
37
38
39 class ViewBackups extends SugarView
40 {
41     /**
42          * @see SugarView::_getModuleTitleParams()
43          */
44         protected function _getModuleTitleParams($browserTitle = false)
45         {
46             global $mod_strings;
47             
48         return array(
49            "<a href='index.php?module=Administration&action=index'>".$mod_strings['LBL_MODULE_NAME']."</a>",
50            $mod_strings['LBL_BACKUPS_TITLE']
51            );
52     }
53     
54     /**
55          * @see SugarView::preDisplay()
56          */
57         public function preDisplay()
58         {
59             global $current_user;
60         
61             if (!is_admin($current_user)) {
62                 sugar_die("Unauthorized access to administration.");
63         }
64         if (isset($GLOBALS['sugar_config']['hide_admin_backup']) && $GLOBALS['sugar_config']['hide_admin_backup'])
65         {
66             sugar_die("Unauthorized access to backups.");
67         }
68         }
69     
70     /**
71          * @see SugarView::display()
72          */
73         public function display()
74         {
75         require_once('include/utils/zip_utils.php');
76
77         $form_action = "index.php?module=Administration&action=Backups";
78         
79         $backup_dir = "";
80         $backup_zip = "";
81         $run        = "confirm";
82         $input_disabled = "";
83         global $mod_strings;
84         $errors = array();
85         
86         // process "run" commands
87         if( isset( $_REQUEST['run'] ) && ($_REQUEST['run'] != "") ){
88             $run = $_REQUEST['run'];
89         
90             $backup_dir = $_REQUEST['backup_dir'];
91             $backup_zip = $_REQUEST['backup_zip'];
92         
93             if( $run == "confirm" ){
94                 if( $backup_dir == "" ){
95                     $errors[] = $mod_strings['LBL_BACKUP_DIRECTORY_ERROR'];
96                 }
97                 if( $backup_zip == "" ){
98                     $errors[] = $mod_strings['LBL_BACKUP_FILENAME_ERROR'];
99                 }
100         
101                 if( sizeof($errors) > 0 ){
102                     return( $errors );
103                 }
104         
105                 if( !is_dir( $backup_dir ) ){
106                     if( !mkdir_recursive( $backup_dir ) ){
107                         $errors[] = $mod_strings['LBL_BACKUP_DIRECTORY_EXISTS'];
108                     }
109                 }
110         
111                 if( !is_writable( $backup_dir ) ){
112                     $errors[] = $mod_strings['LBL_BACKUP_DIRECTORY_NOT_WRITABLE'];
113                 }
114         
115                 if( is_file( "$backup_dir/$backup_zip" ) ){
116                     $errors[] = $mod_strings['LBL_BACKUP_FILE_EXISTS'];
117                 }
118                 if( is_dir( "$backup_dir/$backup_zip" ) ){
119                     $errors[] = $mod_strings['LBL_BACKUP_FILE_AS_SUB'];
120                 }
121                 if( sizeof( $errors ) == 0 ){
122                     $run = "confirmed";
123                     $input_disabled = "readonly";
124                 }
125             }
126             else if( $run == "confirmed" ){
127                 ini_set( "memory_limit", "-1" );
128                 ini_set( "max_execution_time", "0" );
129                 zip_dir( ".", "$backup_dir/$backup_zip" );
130                 $run = "done";
131             }
132         }
133         if( sizeof($errors) > 0 ){
134             foreach( $errors as $error ){
135                 print( "<font color=\"red\">$error</font><br>" );
136             }
137         }
138         if( $run == "done" ){
139             $size = filesize( "$backup_dir/$backup_zip" );
140             print( $mod_strings['LBL_BACKUP_FILE_STORED'] . " $backup_dir/$backup_zip ($size bytes).<br>\n" );
141             print( "<a href=\"index.php?module=Administration&action=index\">" . $mod_strings['LBL_BACKUP_BACK_HOME']. "</a>\n" );
142         }
143         else{
144         ?>
145         
146             <?php 
147             echo getClassicModuleTitle(
148                 "Administration", 
149                 array(
150                     "<a href='index.php?module=Administration&action=index'>".translate('LBL_MODULE_NAME','Administration')."</a>",
151                    $mod_strings['LBL_BACKUPS_TITLE'],
152                    ), 
153                 false
154                 );
155             echo $mod_strings['LBL_BACKUP_INSTRUCTIONS_1']; ?>
156             <br>
157             <?php echo $mod_strings['LBL_BACKUP_INSTRUCTIONS_2']; ?><br>
158             <form action="<?php print( $form_action );?>" method="post">
159             <table>
160             <tr>
161                 <td><?php echo $mod_strings['LBL_BACKUP_DIRECTORY']; ?><br><i><?php echo $mod_strings['LBL_BACKUP_DIRECTORY_WRITABLE']; ?></i></td>
162                 <td><input size="100" type="input" name="backup_dir" <?php print( $input_disabled );?> value="<?php print( $backup_dir );?>"/></td>
163             </tr>
164             <tr>
165                 <td><?php echo $mod_strings['LBL_BACKUP_FILENAME']; ?></td>
166                 <td><input type="input" name="backup_zip" <?php print( $input_disabled );?> value="<?php print( $backup_zip );?>"/></td>
167             </tr>
168             </table>
169             <input type=hidden name="run" value="<?php print( $run );?>" />
170         
171         <?php
172             switch( $run ){
173                 case "confirm":
174         ?>
175                     <input type="submit" value="<?php echo $mod_strings['LBL_BACKUP_CONFIRM']; ?>" />
176         <?php
177                     break;
178                 case "confirmed":
179         ?>
180                     <?php echo $mod_strings['LBL_BACKUP_CONFIRMED']; ?><br>
181                     <input type="submit" value="<?php echo $mod_strings['LBL_BACKUP_RUN_BACKUP']; ?>" />
182         <?php
183                     break;
184             }
185         ?>
186         
187             </form>
188         
189         <?php
190         }   // end if/else of $run options
191         $GLOBALS['log']->info( "Backups" );
192     }
193 }