]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/Administration/views/view.backups.php
Release 6.5.0
[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         }
65     
66     /**
67          * @see SugarView::display()
68          */
69         public function display()
70         {
71         require_once('include/utils/zip_utils.php');
72
73         $form_action = "index.php?module=Administration&action=Backups";
74         
75         $backup_dir = "";
76         $backup_zip = "";
77         $run        = "confirm";
78         $input_disabled = "";
79         global $mod_strings;
80         $errors = array();
81         
82         // process "run" commands
83         if( isset( $_REQUEST['run'] ) && ($_REQUEST['run'] != "") ){
84             $run = $_REQUEST['run'];
85         
86             $backup_dir = $_REQUEST['backup_dir'];
87             $backup_zip = $_REQUEST['backup_zip'];
88         
89             if( $run == "confirm" ){
90                 if( $backup_dir == "" ){
91                     $errors[] = $mod_strings['LBL_BACKUP_DIRECTORY_ERROR'];
92                 }
93                 if( $backup_zip == "" ){
94                     $errors[] = $mod_strings['LBL_BACKUP_FILENAME_ERROR'];
95                 }
96         
97                 if( sizeof($errors) > 0 ){
98                     return( $errors );
99                 }
100         
101                 if( !is_dir( $backup_dir ) ){
102                     if( !mkdir_recursive( $backup_dir ) ){
103                         $errors[] = $mod_strings['LBL_BACKUP_DIRECTORY_EXISTS'];
104                     }
105                 }
106         
107                 if( !is_writable( $backup_dir ) ){
108                     $errors[] = $mod_strings['LBL_BACKUP_DIRECTORY_NOT_WRITABLE'];
109                 }
110         
111                 if( is_file( "$backup_dir/$backup_zip" ) ){
112                     $errors[] = $mod_strings['LBL_BACKUP_FILE_EXISTS'];
113                 }
114                 if( is_dir( "$backup_dir/$backup_zip" ) ){
115                     $errors[] = $mod_strings['LBL_BACKUP_FILE_AS_SUB'];
116                 }
117                 if( sizeof( $errors ) == 0 ){
118                     $run = "confirmed";
119                     $input_disabled = "readonly";
120                 }
121             }
122             else if( $run == "confirmed" ){
123                 ini_set( "memory_limit", "-1" );
124                 ini_set( "max_execution_time", "0" );
125                 zip_dir( ".", "$backup_dir/$backup_zip" );
126                 $run = "done";
127             }
128         }
129         if( sizeof($errors) > 0 ){
130             foreach( $errors as $error ){
131                 print( "<font color=\"red\">$error</font><br>" );
132             }
133         }
134         if( $run == "done" ){
135             $size = filesize( "$backup_dir/$backup_zip" );
136             print( $mod_strings['LBL_BACKUP_FILE_STORED'] . " $backup_dir/$backup_zip ($size bytes).<br>\n" );
137             print( "<a href=\"index.php?module=Administration&action=index\">" . $mod_strings['LBL_BACKUP_BACK_HOME']. "</a>\n" );
138         }
139         else{
140         ?>
141         
142             <?php 
143             echo getClassicModuleTitle(
144                 "Administration", 
145                 array(
146                     "<a href='index.php?module=Administration&action=index'>".translate('LBL_MODULE_NAME','Administration')."</a>",
147                    $mod_strings['LBL_BACKUPS_TITLE'],
148                    ), 
149                 false
150                 );
151             echo $mod_strings['LBL_BACKUP_INSTRUCTIONS_1']; ?>
152             <br>
153             <?php echo $mod_strings['LBL_BACKUP_INSTRUCTIONS_2']; ?><br>
154             <form action="<?php print( $form_action );?>" method="post">
155             <table>
156             <tr>
157                 <td><?php echo $mod_strings['LBL_BACKUP_DIRECTORY']; ?><br><i><?php echo $mod_strings['LBL_BACKUP_DIRECTORY_WRITABLE']; ?></i></td>
158                 <td><input size="100" type="input" name="backup_dir" <?php print( $input_disabled );?> value="<?php print( $backup_dir );?>"/></td>
159             </tr>
160             <tr>
161                 <td><?php echo $mod_strings['LBL_BACKUP_FILENAME']; ?></td>
162                 <td><input type="input" name="backup_zip" <?php print( $input_disabled );?> value="<?php print( $backup_zip );?>"/></td>
163             </tr>
164             </table>
165             <input type=hidden name="run" value="<?php print( $run );?>" />
166         
167         <?php
168             switch( $run ){
169                 case "confirm":
170         ?>
171                     <input type="submit" value="<?php echo $mod_strings['LBL_BACKUP_CONFIRM']; ?>" />
172         <?php
173                     break;
174                 case "confirmed":
175         ?>
176                     <?php echo $mod_strings['LBL_BACKUP_CONFIRMED']; ?><br>
177                     <input type="submit" value="<?php echo $mod_strings['LBL_BACKUP_RUN_BACKUP']; ?>" />
178         <?php
179                     break;
180             }
181         ?>
182         
183             </form>
184         
185         <?php
186         }   // end if/else of $run options
187         $GLOBALS['log']->info( "Backups" );
188     }
189 }