remove old readme
[atutor.git] / mods / _core / backups / admin / restore.php
1 <?php
2 /****************************************************************************/
3 /* ATutor                                                                                                                                       */
4 /****************************************************************************/
5 /* Copyright (c) 2002-2010                                                  */
6 /* Inclusive Design Institute                                               */
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 admin_authenticate(AT_ADMIN_PRIV_BACKUPS);
18
19 require_once(AT_INCLUDE_PATH.'../mods/_core/file_manager/filemanager.inc.php');
20 require(AT_INCLUDE_PATH.'../mods/_core/backups/classes/Backup.class.php');
21
22 $page = 'backups';
23 $_user_location = 'admin';
24
25 if (!isset($_REQUEST['backup_id'])) {
26         header('Location: index.php');
27         exit;
28 }
29
30 if (isset($_POST['cancel'])) {
31         $msg->addFeedback('CANCELLED');
32         header('Location: index.php');
33         exit;
34 } else if (isset($_POST['submit'])) {
35         if (!$_POST['material']) {
36                 $msg->addError(array('EMPTY_FIELDS', _AT('material')));
37         }
38
39         if (!$msg->containsErrors()) {
40                 $Backup = new Backup($db, $_POST['in_course']);
41                 $Backup->restore($_POST['material'], $_POST['action'], $_POST['backup_id'], $_POST['course']);
42
43                 $msg->addFeedBack('ACTION_COMPLETED_SUCCESSFULLY');
44                 header('Location: index.php');
45                 exit;
46         }
47
48
49 require(AT_INCLUDE_PATH.'header.inc.php');
50
51 $Backup = new Backup($db, $_REQUEST['course']);
52
53 $row = $Backup->getRow($_REQUEST['backup_id']);
54
55 ?>
56
57 <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" name="form">
58         <input type="hidden" name="course" value="<?php echo $_REQUEST['course']; ?>" />
59         <input type="hidden" name="backup_id" value="<?php echo $_REQUEST['backup_id']; ?>" />
60
61 <div class="input-form">
62         <div class="row">
63                 <p><?php echo _AT('restore_backup_about'); ?></p>
64         </div>
65         <div class="row">
66                 <span class="required" title="<?php echo _AT('required_field'); ?>">*</span><?php echo _AT('material'); ?><br />
67         
68                 <input type="checkbox" value="1" name="all" id="all" onclick="javascript:selectAll();" /><label for="all"><?php echo _AT('material_select_all'); ?></label><br /><br />
69
70                 <?php
71                 $modules = $moduleFactory->getModules(AT_MODULE_STATUS_ENABLED | AT_MODULE_STATUS_DISABLED, 0, TRUE);
72                 $keys = array_keys($modules);
73                 $i = 0;
74                 ?>
75                 <?php foreach($keys as $module_name): ?>
76                         <?php $module =& $modules[$module_name]; ?>
77                         <?php if ($module->isBackupable()): ?>
78                                 <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 />
79                         <?php endif; ?>
80                 <?php endforeach; ?>
81
82         </div>
83
84         <div class="row">
85                 <span class="required" title="<?php echo _AT('required_field'); ?>">*</span><label for="course"><?php echo _AT('course'); ?></label><br />
86                 
87                         <select name="in_course" id="course"><?php
88                                         foreach ($system_courses as $id => $course) {
89                                                 echo '<option value="'.$id.'">'.$course['title'].'</option>';
90                                         }
91                         ?></select>
92         </div>
93
94         <div class="row">
95                 <?php echo _AT('action'); ?><br />
96                 <input type="radio" checked="checked" name="action" value="append" id="append" /><label for="append"><?php echo _AT('append_content'); ?></label><br />
97                 
98                 <input type="radio" name="action" value="overwrite" id="overwrite" /><label for="overwrite"><?php echo _AT('overwite_content'); ?></label><br />
99                 <br />
100         </div>
101
102         <div class="row buttons">
103                 <input type="submit" name="submit" value="<?php echo _AT('restore'); ?>" /> <input type="submit" name="cancel" value="<?php echo _AT('cancel'); ?>" />
104         </div>
105 </div>
106 </form>
107 <?php $i=0; ?>
108 <script language="javascript" type="text/javascript">
109         
110         function selectAll() {
111                 if (document.form.all.checked == true) {
112                         <?php foreach($keys as $module_name): $module =& $modules[$module_name]; if ($module->isBackupable()): ?>
113                                 document.form.m<?php echo ++$i; ?>.checked = true;
114                         <?php endif; endforeach; ?>
115                 } else {
116                         <?php $i=0;?>
117                         <?php foreach($keys as $module_name): $module =& $modules[$module_name]; if ($module->isBackupable()): ?>
118                                 document.form.m<?php echo ++$i; ?>.checked = false;
119                         <?php endif; endforeach; ?>
120
121                 }
122         }
123 </script>
124 <?php require (AT_INCLUDE_PATH.'footer.inc.php');  ?>