Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Teacher restoring and admin restoring finished.

Allow restore into new course (only admins),
      restore into existing course deleting old and
      restore into existing course adding to old
Teachers are limited to "current course" while admins ca
select any course. :-)
  • Loading branch information...
commit be2a6fc6ca899ecf28b1b53197e4d6abb04f2c80 1 parent 35ea159
stronk7 authored
50 backup/restore_check.html
@@ -98,8 +98,14 @@
98 98 require_login();
99 99
100 100 //Check admin
101   - if (!isadmin()) {
102   - error("You need to be an admin user to use this page.", "$CFG->wwwroot/login/index.php");
  101 + if (!empty($id)) {
  102 + if (!isteacher($id)) {
  103 + error("You need to be a teacher or admin user to use this page.", "$CFG->wwwroot/login/index.php");
  104 + }
  105 + } else {
  106 + if (!isadmin()) {
  107 + error("You need to be an admin user to use this page.", "$CFG->wwwroot/login/index.php");
  108 + }
103 109 }
104 110
105 111 //Check site
@@ -108,16 +114,43 @@
108 114 }
109 115
110 116 //Depending the selected restoreto:
111   - // 0-Existing course: Select the destination course and launch the check again.
112   - // 1-New course: Create the restore object (checking everything) and launch the execute.
  117 + // If user is a teacher (and nor admin):
  118 + // 0-Current course, deleting: Put $restore->course_id and $restore->deleting (true), create the restore object
  119 + // 1-Current course, adding: Put $restore->course_id and $restore->deleting (false), create the restore object
  120 + // If the uses is an admin:
  121 + // 0-Existing course, deleting: Select the destination course and launch the check again, then
  122 + // put $restore->course_id and $restore->deleting (true), create the restore object.
  123 + // 1-Existing course, adding: Select the destination course and launch the check again, then
  124 + // put $restore->course_id and $restore->deleting (false), create the restore object.
  125 + // 2-New course: Create the restore object and launch the execute.
  126 +
  127 + //If the user is a teacher and not an admin
  128 + if (isteacher($id) and !isadmin()) {
  129 + $restore->course_id = $id;
  130 + if ($restore->restoreto == 0) {
  131 + $restore->deleting = true;
  132 + } else {
  133 + $restore->deleting = false;
  134 + }
  135 + }
  136 +
  137 + //If the user is an admin
  138 + if (isadmin()) {
  139 + //Set restore->deleting as needed
  140 + if ($restore->restoreto == 0) {
  141 + $restore->deleting = true;
  142 + } else {
  143 + $restore->deleting = false;
  144 + }
  145 + }
113 146
114   - //Select course
115   - if (($restore->restoreto == 0) and ($restore->course_id == 0)) {
  147 + //Now, select the course if needed
  148 + if (($restore->restoreto == 0 or $restore->restoreto == 1) and ($restore->course_id == 0) and (isadmin())) {
116 149 if ($courses = get_courses()) {
117 150 print_heading(get_string("choosecourse"));
118 151 print_simple_box_start("CENTER");
119 152 foreach ($courses as $course) {
120   - echo "<A HREF=\"restore.php?course_id=$course->id&launch=check&file=$file\">$course->fullname ($course->shortname)</A><BR>";
  153 + echo "<A HREF=\"restore.php?course_id=$course->id&launch=check&id=$id&file=$file\">$course->fullname ($course->shortname)</A><BR>";
121 154 }
122 155 print_simple_box_end();
123 156 } else {
@@ -125,7 +158,7 @@
125 158 print_continue("$CFG->wwwroot/$CFG->admin/index.php");
126 159 }
127 160 //Checks everything and execute restore
128   - } else if ((($restore->restoreto == 0) and ($restore->course_id != 0)) or ($restore->restoreto == 1)) {
  161 + } else if ((($restore->restoreto == 0 or $restore->restoreto == 1) and ($restore->course_id != 0)) or ($restore->restoreto == 2)) {
129 162 $show_continue_button = true;
130 163 //Check if we've selected any mod's user info and restore->users
131 164 //is set to none. Change it to course and inform.
@@ -151,6 +184,7 @@
151 184 echo "<CENTER>";
152 185 $hidden["launch"] = "execute";
153 186 $hidden["file"] = $file;
  187 + $hidden["id"] = $id;
154 188 print_single_button("restore.php", $hidden, get_string("restorecoursenow"),"post");
155 189 echo "</CENTER>";
156 190 } else {
39 backup/restore_execute.html
@@ -14,8 +14,14 @@
14 14 require_login();
15 15
16 16 //Check admin
17   - if (!isadmin()) {
18   - error("You need to be an admin user to use this page.", "$CFG->wwwroot/login/index.php");
  17 + if (!empty($id)) {
  18 + if (!isteacher($id)) {
  19 + error("You need to be a teacher or admin user to use this page.", "$CFG->wwwroot/login/index.php");
  20 + }
  21 + } else {
  22 + if (!isadmin()) {
  23 + error("You need to be an admin user to use this page.", "$CFG->wwwroot/login/index.php");
  24 + }
19 25 }
20 26
21 27 //Check site
@@ -52,7 +58,7 @@
52 58 //If we've selected to restore into new course
53 59 //create it (course)
54 60 //Saving conversion id variables into backup_tables
55   - if ($restore->restoreto ==1) {
  61 + if ($restore->restoreto == 2) {
56 62 echo "<li>".get_string("creatingnewcourse");
57 63 $status = restore_create_new_course($restore,$course_header);
58 64 //Print course fullname and shortname and category
@@ -71,18 +77,41 @@
71 77 echo "<ul>";
72 78 echo "<li>".get_string("from").": ".$course_header->course_fullname." (".$course_header->course_shortname.")";
73 79 echo "<li>".get_string("to").": ".$course->fullname." (".$course->shortname.")";
  80 + if (($restore->deleting)) {
  81 + echo "<li>".get_string("deletingexistingcoursedata");
  82 + } else {
  83 + echo "<li>".get_string("addingdatatoexisting");
  84 + }
74 85 echo "</ul>";
  86 + //If we have selected to restore deleting, we do it now.
  87 + if ($restore->deleting) {
  88 + echo "<li>".get_string("deletingcoursedata");
  89 + $status = remove_course_contents($restore->course_id,false) and
  90 + delete_dir_contents($CFG->dataroot."/".$restore->course_id,"backupdata");
  91 + if ($status) {
  92 + //Now , this situation is equivalent to the "restore to new course" one (we
  93 + //have a course record and nothing more), so define it as "to new course"
  94 + $restore->restoreto = 2;
  95 + } else {
  96 + notify("An error occurred while deleting some of the course contents.");
  97 + }
  98 + }
  99 + } else {
  100 + $status = false;
75 101 }
76 102 }
77 103
78 104 //Now create the course_sections and their associated course_modules
79 105 if ($status) {
80   - if ($restore->restoreto == 1) {
  106 + //Into new course
  107 + if ($restore->restoreto == 2) {
81 108 echo "<li>".get_string("creatingsections");
82 109 $status = restore_create_sections($restore,$xml_file);
83   - } else if ($restore->restoreto == 0) {
  110 + //Into existing course
  111 + } else if ($restore->restoreto == 0 or $restore->restoreto == 1) {
84 112 echo "<li>".get_string("checkingsections");
85 113 $status = restore_create_sections($restore,$xml_file);
  114 + //Error
86 115 } else {
87 116 $status = false;
88 117 }
18 backup/restore_form.html
@@ -84,7 +84,12 @@
84 84 }
85 85
86 86 if (!isset($restore_restoreto)) {
87   - $restore_restoreto = 1;
  87 + if (isteacher($id) and !isadmin()) {
  88 + $restore_restoreto = 1;
  89 + }
  90 + if (isadmin()) {
  91 + $restore_restoreto = 2;
  92 + }
88 93 }
89 94
90 95 if ($count == 0) {
@@ -103,8 +108,15 @@
103 108 echo "<td align=\"right\"><P><b>";
104 109 echo get_string("restoreto").":</b>";
105 110 echo "</td><td>";
106   - $restore_restoreto_options[0] = get_string("existingcourse");
107   - $restore_restoreto_options[1] = get_string("newcourse");
  111 + if (isteacher($id) and !isadmin()) {
  112 + $restore_restoreto_options[0] = get_string("currentcoursedeleting");
  113 + $restore_restoreto_options[1] = get_string("currentcourseadding");
  114 + }
  115 + if (isadmin()) {
  116 + $restore_restoreto_options[0] = get_string("existingcoursedeleting");
  117 + $restore_restoreto_options[1] = get_string("existingcourseadding");
  118 + $restore_restoreto_options[2] = get_string("newcourse");
  119 + }
108 120 choose_from_menu($restore_restoreto_options, "restore_restoreto", $restore_restoreto, "");
109 121 echo "</td></tr>";
110 122 //Line

0 comments on commit be2a6fc

Please sign in to comment.
Something went wrong with that request. Please try again.