made a copy
[atutor.git] / tools / backup / restore.php
1 <?php
2 /****************************************************************************/
3 /* ATutor                                                                                                                                       */
4 /****************************************************************************/
5 /* Copyright (c) 2002-2008 by Greg Gay, Joel Kronenberg & Heidi Hazelton        */
6 /* Adaptive Technology Resource Centre / University of Toronto                          */
7 /* http://atutor.ca                                                                                                                     */
8 /*                                                                                                                                                      */
9 /* This program is free software. You can redistribute it and/or                        */
10 /* modify it under the terms of the GNU General Public License                          */
11 /* as published by the Free Software Foundation.                                                        */
12 /****************************************************************************/
13 // $Id$
14
15 define('AT_INCLUDE_PATH', '../../include/');
16 require(AT_INCLUDE_PATH.'vitals.inc.php');
17
18 authenticate(AT_PRIV_ADMIN); 
19 require(AT_INCLUDE_PATH.'classes/Backup/Backup.class.php');
20 require(AT_INCLUDE_PATH.'lib/filemanager.inc.php');
21
22 $Backup =& new Backup($db, $_SESSION['course_id']);
23
24 if (!isset($_REQUEST['backup_id'])) {
25         header('Location: index.php');
26         exit;
27 }
28
29 if (isset($_POST['cancel'])) {
30         $msg->addFeedback('CANCELLED');
31         header('Location: index.php');
32         exit;
33 } else if (isset($_POST['submit'])) {
34         if (!$_POST['material']) {
35                 $msg->addError(array('EMPTY_FIELDS', _AT('material')));
36         } else {
37                 $Backup->restore($_POST['material'], $_POST['action'], $_POST['backup_id']);
38
39                 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
40                 header('Location: index.php');
41                 exit;
42         }
43 }
44
45 require(AT_INCLUDE_PATH.'header.inc.php');
46
47 $row = $Backup->getRow($_REQUEST['backup_id']);
48
49 ?>
50
51 <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" name="form">
52 <input type="hidden" name="backup_id" value="<?php echo $_REQUEST['backup_id']; ?>" />
53
54 <div class="input-form">
55         <div class="row">
56                 <div class="required" title="<?php echo _AT('required_field'); ?>">*</div><?php echo _AT('material'); ?><br />
57
58                 <input type="checkbox" value="1" name="all" id="all" onclick="javascript:selectAll();" /><label for="all"><?php echo _AT('material_select_all'); ?></label><br /><br />
59
60                 <input type="checkbox" value="1" name='material[properties]' id='m0' /><label for='m0'><?php echo _AT('banner'); ?></label><br />
61                 <?php
62                 $i=0;
63                 $modules = $moduleFactory->getModules(AT_MODULE_STATUS_ENABLED, 0, TRUE);
64                 $keys = array_keys($modules);
65                 ?>
66                 <?php foreach($keys as $module_name): ?>
67                         <?php $module =& $modules[$module_name]; ?>
68                         <?php if ($module->isBackupable()): ?>
69                                 <input type="checkbox" value="1" name="material[<?php echo $module_name; ?>]" id="m<?php echo ++$i; ?>" /><label for="m<?php echo $i; ?>"><?php echo $module->getName(); ?></label><br />
70                         <?php endif; ?>
71                 <?php endforeach; ?>
72         </div>
73
74         <div class="row">
75                 <?php echo _AT('action'); ?><br />
76                 <input type="radio" checked="checked" name="action" value="append" id="append" /><label for="append"><?php echo _AT('append_content'); ?></label><br />
77                 
78                 <input type="radio" name="action" value="overwrite" id="overwrite" /><label for="overwrite"><?php echo _AT('overwite_content'); ?></label><br />
79         </div>
80
81         <div class="row buttons">
82                 <input type="submit" name="submit" value="<?php echo _AT('restore'); ?>" /> 
83                 <input type="submit" name="cancel" value="<?php echo _AT('cancel'); ?>" />
84         </div>
85 </div>
86 </form>
87 <?php $i=0; ?>
88 <script language="javascript" type="text/javascript">
89         
90         function selectAll() {
91                 if (document.form.all.checked == true) {
92                         document.form.m0.checked = true;
93                         <?php foreach($keys as $module_name): $module =& $modules[$module_name]; if ($module->isBackupable()): ?>
94                                 document.form.m<?php echo ++$i; ?>.checked = true;
95                         <?php endif; endforeach; ?>
96                 } else {
97                         document.form.m0.checked = false;
98                         <?php $i=0;?>
99                         <?php foreach($keys as $module_name): $module =& $modules[$module_name]; if ($module->isBackupable()): ?>
100                                 document.form.m<?php echo ++$i; ?>.checked = false;
101                         <?php endif; endforeach; ?>
102
103                 }
104         }
105 </script>
106
107 <?php require (AT_INCLUDE_PATH.'footer.inc.php');  ?>