]> git.mjollnir.org Git - moodle.git/commitdiff
Initial checkin for import course content functionality (uses backup/restore). Probab...
authormjollnir_ <mjollnir_>
Thu, 27 Jan 2005 02:35:10 +0000 (02:35 +0000)
committermjollnir_ <mjollnir_>
Thu, 27 Jan 2005 02:35:10 +0000 (02:35 +0000)
backup/backup.php
backup/backup_check.html
backup/backup_execute.html
backup/backup_form.html
backup/restore.php
backup/restore_execute.html
backup/restore_precheck.html
backup/restorelib.php
blocks/admin/block_admin.php
lang/en/moodle.php

index fb3efb91186a2de3754222a867796e6c9a62cb0f..49f46bcc14ad8f30fb4baf5f3ed5fc1413275651 100644 (file)
@@ -9,6 +9,7 @@
     require_once ("$CFG->libdir/blocklib.php");
 
     optional_variable($id);       // course id
+    optional_variable($to); // id of course to import into afterwards.
     optional_variable($cancel);
     optional_variable($launch);
 
 
     if (!empty($id)) {
         if (!isteacheredit($id)) {
-            error("You need to be a teacher or admin user to use this page.", "$CFG->wwwroot/login/index.php");
+            if (empty($to)) {
+                error("You need to be a teacher or admin user to use this page.", "$CFG->wwwroot/login/index.php");
+            } else {
+                if (!isteacheredit($to)) {
+                    error("You need to be a teacher or admin user to use this page.", "$CFG->wwwroot/login/index.php");
+                }
+            }
         }
     } else {
         if (!isadmin()) {
     
     //Check backup_version
     if ($id) {
-        $linkto = "backup.php?id=".$id;
+        $linkto = "backup.php?id=".$id.((!empty($to)) ? '&to='.$to : '');
     } else {
         $linkto = "backup.php";
     }
     upgrade_backup_db($linkto);
 
     //Get strings
-    $strcoursebackup = get_string("coursebackup");
+    if (empty($to)) {
+        $strcoursebackup = get_string("coursebackup");
+    }
+    else {
+        $strcoursebackup = get_string('importdata');
+    }
     $stradministration = get_string("administration");
 
     //If no course has been selected or cancel button pressed
index d4a5cea2435ee87bf6536b9b0fff422d06095d91..acf1d437a66445d8c0fc07249ddfc1d44eeb663d 100644 (file)
@@ -6,7 +6,13 @@
 
     if (!empty($course->id)) {
         if (!isteacheredit($course->id)) {
-            error("You need to be a teacher or admin user to use this page.", "$CFG->wwwroot/login/index.php");
+            if (empty($to)) {
+                error("You need to be a teacher or admin user to use this page.", "$CFG->wwwroot/login/index.php");
+            } else {
+                if (!isteacheredit($to)) {
+                    error("You need to be a teacher or admin user to use this page.", "$CFG->wwwroot/login/index.php");
+                }
+            }
         }
     } else {
         if (!isadmin()) {
 <table cellpadding="5">
 <?php
 
-    //Now print the Backup Name tr
-    echo "<tr>";
-    echo "<td align=\"right\"><p><b>";
-    echo get_string("name").":";
-    echo "</b></td><td>";
     //Calculate the backup string
 
     //Calculate the backup word
     //And finally, clean everything
     $backup_name = clean_filename($backup_name);
 
-    //Add as text field
-    echo "<input type=\"text\" name=\"backup_name\" size=\"40\" value=\"".$backup_name."\">";
-    echo "</td></tr>";
-
     //Calculate the backup unique code to allow simultaneus backups (to define
     //the temp-directory name and records in backup temp tables
     $backup_unique_code = time();
     //Add as hidden name
     echo "<input type=\"hidden\" name=\"backup_unique_code\" value=\"".$backup_unique_code."\">";
+
+    if (empty($to)) {
+        //Now print the Backup Name tr
+        echo "<tr>";
+        echo "<td align=\"right\"><P><B>";
+        echo get_string("name").":";
+        echo "</B></td><td>";
+        //Add as text field
+        echo "<input type=\"text\" name=\"backup_name\" size=\"40\" value=\"".$backup_name."\">";
+        echo "</td></tr>";
     
-    //Line
-    echo "<tr><td colspan=\"2\"><hr noshade size=\"1\"></td></tr>";
+        //Line
+        echo "<tr><td colspan=\"2\"><hr noshade size=\"1\"></td></tr>";
+        
+        //Now print the To Do list
+        echo "<tr>";    
+        echo "<td colspan=\"2\" align=\"center\"><p><b>";
+
+    } else {
+        echo '<input type="hidden" name="backup_name" value="'.$backup_name.'" />';
+    }
 
-    //Now print the To Do list
-    echo "<tr>";    
-    echo "<td colspan=\"2\" align=\"center\"><p><b>";
 
     //Here we check if backup_users = None. Then, we switch off every module
     //user info, user_files, logs and exercises and workshop backups. A Warning is showed to
         echo "<hr noshade size=\"1\">";
     }
 
-    echo get_string("backupdetails").":";
-    echo "</td></tr>";
+    if (empty($to)) {
+        echo get_string("backupdetails").":";
+        echo "</td></tr>";
+    }
 
     //This is tha align to every ingo table                
     $table->align = array ("left","right");
                 }
             }
         }
-        //Line
-        echo "<tr><td colspan=\"2\"><hr noshade size=\"1\"></td></tr>";
-
-        //Now print the Users tr
-        echo "<tr>";
-        echo "<td colspan=\"2\"><p><b>";
-        $user_options[0] = get_string("includeallusers");
-        $user_options[1] = get_string("includecourseusers");
-        $user_options[2] = get_string("includenoneusers");
-        echo "<li>".$user_options[$backup_users]."<p>";
+        
+        if (empty($to)) {
+            //Line
+            echo "<tr><td colspan=\"2\"><hr noshade size=\"1\"></td></tr>";
+            
+            //Now print the Users tr
+            echo "<tr>";
+            echo "<td colspan=\"2\"><p><b>";
+            $user_options[0] = get_string("includeallusers");
+            $user_options[1] = get_string("includecourseusers");
+            $user_options[2] = get_string("includenoneusers");
+            echo "<li>".$user_options[$backup_users]."<p>";
+            //Print info
+            $table->data = user_check_backup($id,$backup_unique_code,$backup_users);  
+            print_table($table); 
+            echo "</td></tr>";
+            
+        }
         //Add as hidden name
         echo "<input type=\"hidden\" name=\"backup_users\" value=\"".$backup_users."\">";
-        //Print info
-        $table->data = user_check_backup($id,$backup_unique_code,$backup_users);  
-        print_table($table); 
-        echo "</td></tr>";
-
+        
         //Now print the Logs tr conditionally
-        if ($backup_logs) {
+        if ($backup_logs && empty($to)) {
             echo "<tr>";
             echo "<td colspan=\"2\"><p><b>";
             echo "<li>".get_string("includelogentries")."<p>";
 </table>
 <br />
 <center>
-<input type="hidden" name="id"     value="<?php  p($id) ?>">
-<input type="hidden" name="launch" value="execute">
-<input type="submit" value="<?php  print_string("continue") ?>">
-<input type="submit" name="cancel" value="<?php  print_string("cancel") ?>">
+<input type="hidden" name="to"     value="<?php p($to) ?>" />
+<input type="hidden" name="id"     value="<?php  p($id) ?>" />
+<input type="hidden" name="launch" value="execute" />
+<input type="submit" value="<?php  print_string("continue") ?>" />
+<input type="submit" name="cancel" value="<?php  print_string("cancel") ?>" />
 </center>
 </form>
index 0fe00113d215ae4c167f8259f54292a739f2218a..fad9a5c018409142d92ec114a0d76b93ba0eb6b4 100644 (file)
@@ -6,7 +6,13 @@
 
     if (!empty($course->id)) {
         if (!isteacheredit($course->id)) {
-            error("You need to be a teacher or admin user to use this page.", "$CFG->wwwroot/login/index.php");
+            if (empty($to)) {
+                error("You need to be a teacher or admin user to use this page.", "$CFG->wwwroot/login/index.php");
+            } else {
+                if (!isteacheredit($to)) {
+                    error("You need to be a teacher or admin user to use this page.", "$CFG->wwwroot/login/index.php");
+                }
+            }
         }
     } else {
         if (!isadmin()) {
         notice("No backupable modules are installed!");
     }
 
-    //Start the main table
-    echo "<table cellpadding=5>";
-
-    //Now print the Backup Name tr
-    echo "<tr>";
-    echo "<td align=\"right\"><p><b>";
-    echo get_string("name").":";
-    echo "</b></td><td>";
-    echo $preferences->backup_name;
-    echo "</td></tr>";
-    
-    //Start the main tr, where all the backup progress is done
-    echo "<tr>";
-    echo "<td colspan=\"2\">";
-    
-    //Start the main ul
-    echo "<ul>";
 
+    if (empty($to)) {
+        //Start the main table
+        echo "<table cellpadding=5>";
+        
+        //Now print the Backup Name tr
+        echo "<tr>";
+        echo "<td align=\"right\"><p><b>";
+        echo get_string("name").":";
+        echo "</b></td><td>";
+        echo $preferences->backup_name;
+        echo "</td></tr>";
+        
+        //Start the main tr, where all the backup progress is done
+        echo "<tr>";
+        echo "<td colspan=\"2\">";
+        
+        //Start the main ul
+        echo "<ul>";
+    }
     //Check for temp and backup and backup_unique_code directory
     //Create them as needed
     echo "<li>".get_string("creatingtemporarystructures");
         //End course contents (close ul)
         echo "</ul>";
 
-        echo "<li>".get_string("writinguserinfo");
         //User info
-        if ($status) {
+        if ($status && $preferences->backup_users) {
+            echo "<li>".get_string("writinguserinfo");
             if (!$status = backup_user_info($backup_file,$preferences)) {
                 notify("An error occurred while backing up user info");
             }
                "$CFG->wwwroot/course/view.php?id=$course->id");
     }
 
-    //Print final message
-    print_simple_box(get_string("backupfinished"),"center");
-    print_continue("$CFG->wwwroot/files/index.php?id=".$preferences->backup_course."&wdir=/backupdata");    
-
+    if (empty($to)) {
+        //Print final message
+        print_simple_box(get_string("backupfinished"),"center");
+        print_continue("$CFG->wwwroot/files/index.php?id=".$preferences->backup_course."&wdir=/backupdata");    
+    } else {
+        print_simple_box(get_string('importdataexported'),"CENTER");
+        if (!empty($preferences->backup_destination)) {
+            $filename = $preferences->backup_destination."/".$preferences->backup_name;
+        } else {
+            $filename = $preferences->backup_course."/backupdata/".$preferences->backup_name;
+        }
+        error_log($filename);
+        $SESSION->import_preferences = $preferences;
+        print_continue($CFG->wwwroot.'/course/import.php?id='.$to.'&fromcourse='.$id.'&filename='.$filename);
+    }
 ?>
index 8e48b24bb78eca512b559c7c103258cbdcf4f6c4..7c542858b8305bc129cd00a12cea1cef0f0b9b86 100644 (file)
@@ -6,7 +6,13 @@
 
     if (!empty($course->id)) {
         if (!isteacheredit($course->id)) {
-            error("You need to be a teacher or admin user to use this page.", "$CFG->wwwroot/login/index.php");
+            if (empty($to)) {
+                error("You need to be a teacher or admin user to use this page.", "$CFG->wwwroot/login/index.php");
+            } else {
+                if (!isteacheredit($to)) {
+                    error("You need to be a teacher or admin user to use this page.", "$CFG->wwwroot/login/index.php");
+                }
+            }
         }
     } else {
         if (!isadmin()) {
                 $backup_options[1] = get_string("yes");
                 $var = "backup_".$modname;
                 choose_from_menu($backup_options, $var, $$var, "");
-                $backup_user_options[0] = get_string("withoutuserdata"); 
-                $backup_user_options[1] = get_string("withuserdata");
                 $var = "backup_user_info_".$modname;
-                choose_from_menu($backup_user_options, $var, $$var, "");
-                echo "</td></tr>";
+                if (empty($to)) {
+                    $backup_user_options[0] = get_string("withoutuserdata"); 
+                    $backup_user_options[1] = get_string("withuserdata");
+                    choose_from_menu($backup_user_options, $var, $$var, "");
+                }
+                else {
+                    echo '<input type="hidden" name="'.$var.'" value="0" />';
+                }
+                echo "</td></tr>"; 
             }
         }
         //Line
         echo "<tr><td colspan=\"2\"><hr noshade size=\"1\"></td></tr>";
-
-        //Now print the Users tr
-        echo "<tr>";
-        echo "<td align=\"right\"><p><b>";
-        echo get_string("users").":";
-        echo "</td><td>";
-        $user_options[0] = get_string("all");
-        $user_options[1] = get_string("course");
-        $user_options[2] = get_string("none");
-        choose_from_menu($user_options, "backup_users", $backup_users, "");
-        echo "</td></tr>";
-
-        //Now print the Logs tr
-        echo "<tr>";
-        echo "<td align=\"right\"><p><b>";
-        echo get_string("logs").":";                                               
-        echo "</td><td>";
-        $log_options[0] = get_string("no");
-        $log_options[1] = get_string("yes"); 
-        choose_from_menu($log_options, "backup_logs", $backup_logs, ""); 
-        echo "</td></tr>";
-
-        //Now print the User Files tr
-        echo "<tr>";
-        echo "<td align=\"right\"><p><b>";
-        echo get_string ("userfiles").":";
-        echo "</td><td>";
-        $user_file_options[0] = get_string("no"); 
-        $user_file_options[1] = get_string("yes"); 
-        choose_from_menu($user_file_options, "backup_user_files", $backup_user_files, "");
-        echo "</td></tr>";
-
+        
+        if (empty($to)) {
+            //Now print the Users tr
+            echo "<tr>";
+            echo "<td align=\"right\"><P><B>";
+            echo get_string("users").":";
+            echo "</td><td>";
+            $user_options[0] = get_string("all");
+            $user_options[1] = get_string("course");
+            $user_options[2] = get_string("none");
+            choose_from_menu($user_options, "backup_users", $backup_users, "");
+            echo "</td></tr>";
+        }
+        else {
+            echo '<input type="hidden" name="backup_users" value="0" />';
+        }
+        
+        if (empty($to)) {
+            //Now print the Logs tr
+            echo "<tr>";
+            echo "<td align=\"right\"><P><B>";
+            echo get_string("logs").":";                                               
+            echo "</td><td>";
+            $log_options[0] = get_string("no");
+            $log_options[1] = get_string("yes"); 
+            choose_from_menu($log_options, "backup_logs", $backup_logs, ""); 
+            echo "</td></tr>";
+        }
+        else {
+            echo '<input type="hidden" name="backup_logs" value="0" />';
+        }
+           
+        if (empty($to)) {
+            //Now print the User Files tr
+            echo "<tr>";
+            echo "<td align=\"right\"><P><B>";
+            echo get_string ("userfiles").":";
+            echo "</td><td>";
+            $user_file_options[0] = get_string("no"); 
+            $user_file_options[1] = get_string("yes"); 
+            choose_from_menu($user_file_options, "backup_user_files", $backup_user_files, "");
+            echo "</td></tr>";
+        }
+        else {
+            echo '<input type="hidden" name="backup_user_files" value="0" />';
+        }
         //Now print the Course Files tr
         echo "<tr>";
-        echo "<td align=\"right\"><p><b>";
+        echo "<td align=\"right\"><P><B>";
         echo get_string ("coursefiles").":";
         echo "</td><td>";
         $course_file_options[0] = get_string("no");
 </table>
 <br />
 <center>
-<input type="hidden" name="id"     value="<?php  p($id) ?>">
-<input type="hidden" name="launch" value="check">
-<input type="submit" value="<?php  print_string("continue") ?>">
-<input type="submit" name="cancel" value="<?php  print_string("cancel") ?>">
+<input type="hidden" name="id"     value="<?php  p($id) ?>" />
+<input type="hidden" name="to"     value="<?php p($to) ?>" />
+<input type="hidden" name="launch" value="check" />
+<input type="submit" value="<?php  print_string("continue") ?>" />
+<input type="submit" name="cancel" value="<?php  print_string("cancel") ?>" />
 </center>
 </form>
index 0a2c0111001ea5d096d65adc8bdfcbb9aba61a3c..dda9e1cf9584a41b5c244b46d7a6cb3340dad1f5 100644 (file)
     optional_variable($file);
     optional_variable($cancel);
     optional_variable($launch);
+    optional_variable($to);
 
     //Check login       
     require_login();
 
+    if (!$to && isset($SESSION->restore->restoreto) && isset($SESSION->restore->importing) && isset($SESSION->restore->course_id)) {
+        $to = $SESSION->restore->course_id;
+    }
+
     if (!empty($id)) {
         if (!isteacheredit($id)) {
-            error("You need to be a teacher or admin user to use this page.", "$CFG->wwwroot/login/index.php");
+            if (empty($to)) {
+                error("You need to be a teacher or admin user to use this page.", "$CFG->wwwroot/login/index.php");
+            } else {
+                if (!isteacheredit($to)) {
+                    error("You need to be a teacher or admin user to use this page.", "$CFG->wwwroot/login/index.php");
+                }
+            }
         }
     } else {
         if (!isadmin()) {
     upgrade_backup_db($linkto);
 
     //Get strings
-    $strcourserestore = get_string("courserestore");
+    if (empty($to)) {
+        $strcourserestore = get_string("courserestore");
+    } else {
+        $strcourserestore = get_string("importdata");
+    }
     $stradministration = get_string("administration");
 
     //If no file has been selected from the FileManager, inform and end
                      $strcourserestore");
     }
     //Print form
-    print_heading("$strcourserestore: ".basename($file));
+    print_heading("$strcourserestore".((empty($to) ? ': '.basename($file) : '')));
     print_simple_box_start("center", "", "$THEME->cellheading");
     
     //Adjust some php variables to the execution of this script
     raise_memory_limit("memory_limit","128M");
 
     //Call the form, depending the step we are
+
+
     if (!$launch) {
         include_once("restore_precheck.html");
     } else if ($launch == "form") {
-        include_once("restore_form.html");
+        if ($SESSION->restore->importing) {
+            // set up all the config stuff and skip asking the user about it.
+            restore_setup_for_check($SESSION->restore,$backup_unique_code);
+            include_once("restore_execute.html");
+        } else {
+            include_once("restore_form.html");
+        }
     } else if ($launch == "check") {
         include_once("restore_check.html");
     } else if ($launch == "execute") {
index 35242c776cdc070c60b5d4c9f9084f39012bbd52..e3c7b057cb1c6c59c388593d905b601eef21d9ee 100644 (file)
     //Check admin
     if (!empty($id)) {
         if (!isteacheredit($id)) {
-            error("You need to be a teacher or admin user to use this page.", "$CFG->wwwroot/login/index.php");
+            if (empty($to)) {
+                error("You need to be a teacher or admin user to use this page.", "$CFG->wwwroot/login/index.php");
+            } else {
+                if (!isteacheredit($to)) {
+                    error("You need to be a teacher or admin user to use this page.", "$CFG->wwwroot/login/index.php");
+                }
+            }
         }
     } else {
         if (!isadmin()) {
         error ("An error has occurred and the restore could not be completed!");
     }
 
-    //Print final message
-    print_simple_box(get_string("restorefinished"),"center");
+    if (!$restore->importing) {
+        echo $output;
+        //Print final message
+        print_simple_box(get_string("restorefinished"),"CENTER");
+    } else {
+        print_simple_box(get_string("importdatafinished"),"CENTER");
+        unset($SESSION->restore);
+    }
     print_continue("$CFG->wwwroot/course/view.php?id=".$restore->course_id);
 
 ?>
index f046a025f8f806c864e1470d00f07e8d4588ff6f..02e820044691027a4377300f370bb28819c84262 100644 (file)
     //Check admin
     if (!empty($id)) {
         if (!isteacheredit($id)) {
-            error("You need to be a teacher or admin user to use this page.", "$CFG->wwwroot/login/index.php");
+            if (empty($to)) {
+                error("You need to be a teacher or admin user to use this page.", "$CFG->wwwroot/login/index.php");
+            } else {
+                if (!isteacheredit($to)) {
+                    error("You need to be a teacher or admin user to use this page.", "$CFG->wwwroot/login/index.php");
+                }
+            }
         }
     } else {
         if (!isadmin()) {
         error("Site not found!");
     }
 
-    //Prepend dataroot to variable to have the absolute path
-    $file = $CFG->dataroot."/".$file;
-
-    //Start the main table
-    echo "<table cellpadding=\"5\">";
-    echo "<tr><td>";
-    
-    //Start the mail ul
-    echo "<ul>";
-
-    //Check the file exists 
-    if (!is_file($file)) {
-        error ("File not exists ($file)");
-    }
-
-    //Check the file name ends with .zip
-    if (!substr($file,-4) == ".zip") {
-        error ("File has an incorrect extension");
-    }
-
-    //Now calculate the unique_code for this restore
-    $backup_unique_code = time();
-    
-    //Now check and create the backup dir (if it doesn't exist)
-    echo "<li>".get_string("creatingtemporarystructures");
-    $status = check_and_create_backup_dir($backup_unique_code);
-    //Empty dir
-    if ($status) {
-        $status = clear_backup_dir($backup_unique_code);
-    }
-
-    //Now delete old data and directories under dataroot/temp/backup
-    if ($status) {   
-        echo "<li>".get_string("deletingolddata");
-        $status = backup_delete_old_data();
-    }
-  
-    //Now copy he zip file to dataroot/temp/backup/backup_unique_code
-    if ($status) {
-        echo "<li>".get_string("copyingzipfile");
-        if (! $status = backup_copy_file($file,$CFG->dataroot."/temp/backup/".$backup_unique_code."/".basename($file))) {
-            notify("Error copying backup file. Invalid name or bad perms.");
-        }
-    }
-
-    //Now unzip the file
-    if ($status) {
-        echo "<li>".get_string("unzippingbackup");
-        if (! $status = restore_unzip ($CFG->dataroot."/temp/backup/".$backup_unique_code."/".basename($file))) {
-            notify("Error unzipping backup file. Invalid zip file.");
-        }
-    }
-
-    //Now check for the moodle.xml file
-    if ($status) {
-        $xml_file  = $CFG->dataroot."/temp/backup/".$backup_unique_code."/moodle.xml";
-        echo "<li>".get_string("checkingbackup");
-        if (! $status = restore_check_moodle_file ($xml_file)) {
-            notify("Error checking backup file. Invalid or corrupted.");
-        }
-    }
-
-    $info = "";
-    $course_header = "";
-
-    //Now read the info tag (all)
-    if ($status) {
-        echo "<li>".get_string("readinginfofrombackup");
-        //Reading info from file
-        $info = restore_read_xml_info ($xml_file);
-        //Reading course_header from file
-        $course_header = restore_read_xml_course_header ($xml_file);
-    }
-
-    //End the main ul
-    echo "</ul>";
-
-    //End the main table
-    echo "</tr></td>";
-    echo "</table>";
-
-    //We compare Moodle's versions
-    if ($CFG->version < $info->backup_moodle_version && $status) {
-        $message->serverversion = $CFG->version;
-        $message->serverrelease = $CFG->release;
-        $message->backupversion = $info->backup_moodle_version;
-        $message->backuprelease = $info->backup_moodle_release;
-        print_simple_box(get_string('noticenewerbackup','',$message), "center", "70%", "$THEME->cellheading2", "20", "noticebox");
-
-    }
-
-    //Now we print in other table, the backup and the course it contains info
-    if ($info and $course_header and $status) {
-        //First, the course info
-        $status = restore_print_course_header($course_header);
-        //Now, the backup info
-        if ($status) {
-            $status = restore_print_info($info);
-        }
-    }
-
-    //Save course header and info into php session
-    if ($status) {
-        $SESSION->info = $info;
-        $SESSION->course_header = $course_header;
-    }
-
-    //Finally, a little form to continue
-    //with some hidden fields
-    if ($status) {
-        echo "<br /><center>";
-        $hidden["backup_unique_code"] = $backup_unique_code;
-        $hidden["launch"]             = "form";
-        $hidden["file"]               =  $file;
-        $hidden["id"]                 =  $id;
-        print_single_button("restore.php", $hidden, get_string("continue"),"post");
-        echo "</center>";
-    }
-  
+    $status = restore_precheck($id,$file,!empty($SESSION->restore->importing));
     if (!$status) {
-        error ("An error has ocurred");
+        error("An error occured");
     }
 
 ?>
index 0c367c14a68b4bd792c2e41e83c31d9c571878cf..c4845451f91cea1185843ab7ec190a59bf084915 100644 (file)
             return $status;
         }
     }
+
+    function restore_precheck($id,$file,$silent=false) {
+        
+        global $CFG;
+
+        //Prepend dataroot to variable to have the absolute path
+        $file = $CFG->dataroot."/".$file;
+        
+        if (empty($silent)) {
+            //Start the main table
+            echo "<table cellpadding=\"5\">";
+            echo "<tr><td>";
+            
+            //Start the mail ul
+            echo "<ul>";
+        }
+
+        //Check the file exists 
+        if (!is_file($file)) {
+            error ("File not exists ($file)");
+        }
+        
+        //Check the file name ends with .zip
+        if (!substr($file,-4) == ".zip") {
+            error ("File has an incorrect extension");
+        }
+        
+        //Now calculate the unique_code for this restore
+        $backup_unique_code = time();
+        
+        //Now check and create the backup dir (if it doesn't exist)
+        if (empty($silent)) {
+            echo "<li>".get_string("creatingtemporarystructures");
+        }
+        $status = check_and_create_backup_dir($backup_unique_code);
+        //Empty dir
+        if ($status) {
+            $status = clear_backup_dir($backup_unique_code);
+        }
+        
+        //Now delete old data and directories under dataroot/temp/backup
+        if ($status) {   
+            if (empty($silent)) {
+                echo "<li>".get_string("deletingolddata");
+            }
+            $status = backup_delete_old_data();
+        }
+        
+        //Now copy he zip file to dataroot/temp/backup/backup_unique_code
+        if ($status) {
+            if (empty($silent)) {
+                echo "<li>".get_string("copyingzipfile");
+            }
+            if (! $status = backup_copy_file($file,$CFG->dataroot."/temp/backup/".$backup_unique_code."/".basename($file))) {
+                notify("Error copying backup file. Invalid name or bad perms.");
+            }
+        }
+        
+        //Now unzip the file
+        if ($status) {
+            if (empty($silent)) {
+                echo "<li>".get_string("unzippingbackup");
+            }
+            if (! $status = restore_unzip ($CFG->dataroot."/temp/backup/".$backup_unique_code."/".basename($file))) {
+                notify("Error unzipping backup file. Invalid zip file.");
+            }
+        }
+        
+        //Now check for the moodle.xml file
+        if ($status) {
+            $xml_file  = $CFG->dataroot."/temp/backup/".$backup_unique_code."/moodle.xml";
+            if (empty($silent)) {
+                echo "<li>".get_string("checkingbackup");
+            }
+            if (! $status = restore_check_moodle_file ($xml_file)) {
+                notify("Error checking backup file. Invalid or corrupted.");
+            }
+        }
+        
+        $info = "";
+        $course_header = "";
+        
+        //Now read the info tag (all)
+        if ($status) {
+            if (empty($silent)) {
+                echo "<li>".get_string("readinginfofrombackup");
+            }
+            //Reading info from file
+            $info = restore_read_xml_info ($xml_file);
+            //Reading course_header from file
+            $course_header = restore_read_xml_course_header ($xml_file);
+        }
+        
+        if (empty($silent)) {
+            //End the main ul
+            echo "</ul>";
+            
+            //End the main table
+            echo "</tr></td>";
+            echo "</table>";
+        }
+        
+        //We compare Moodle's versions
+        if ($CFG->version < $info->backup_moodle_version && $status) {
+            $message->serverversion = $CFG->version;
+            $message->serverrelease = $CFG->release;
+            $message->backupversion = $info->backup_moodle_version;
+            $message->backuprelease = $info->backup_moodle_release;
+            print_simple_box(get_string('noticenewerbackup','',$message), "center", "70%", "$THEME->cellheading2", "20", "noticebox");
+            
+        }
+        
+        //Now we print in other table, the backup and the course it contains info
+        if ($info and $course_header and $status) {
+            //First, the course info
+            $status = restore_print_course_header($course_header);
+            //Now, the backup info
+            if ($status) {
+                $status = restore_print_info($info);
+            }
+        }
+        
+        //Save course header and info into php session
+        if ($status) {
+            $SESSION->info = $info;
+            $SESSION->course_header = $course_header;
+        }
+        
+        //Finally, a little form to continue
+        //with some hidden fields
+        if ($status) {
+            if (empty($silent)) {
+                echo "<br /><center>";
+                $hidden["backup_unique_code"] = $backup_unique_code;
+                $hidden["launch"]             = "form";
+                $hidden["file"]               =  $file;
+                $hidden["id"]                 =  $id;
+                print_single_button("restore.php", $hidden, get_string("continue"),"post");
+                echo "</center>";
+            }
+            else {
+                redirect($CFG->wwwroot.'/backup/restore.php?backup_unique_code='.$backup_unique_code.'&launch=form&file='.$file.'&id='.$id);
+            }
+        }
+        
+        if (!$status) {
+            error ("An error has ocurred");
+        }
+        return true;
+    }
+
+    function restore_setup_for_check(&$restore,$backup_unique_code) {
+        global $SESSION;
+        $restore->backup_unique_code=$backup_unique_code;
+        $restore->users = 2; // yuk
+        if ($allmods = get_records("modules")) {
+            foreach ($allmods as $mod) {
+                $modname = $mod->name;
+                $var = "restore_".$modname;
+                //Now check that we have that module info in the backup file
+                if (isset($SESSION->info->mods[$modname]) && $SESSION->info->mods[$modname]->backup == "true") {
+                    $restore->$var = 1; 
+                }
+            }
+        }
+    }
+
+    function backup_to_restore_array($backup,$k=0) {
+        if (is_array($backup) ) {
+            foreach ($backup as $key => $value) {
+                $newkey = str_replace('backup','restore',$key);
+                $restore[$newkey] = backup_to_restore_array($value,$key);
+            }
+        }
+        else if (is_object($backup)) { 
+            $tmp = get_object_vars($backup);
+            foreach ($tmp as $key => $value) {
+                $newkey = str_replace('backup','restore',$key);
+                $restore->$newkey = backup_to_restore_array($value,$key);   
+            }
+        }
+        else {
+            $newkey = str_replace('backup','restore',$k);
+            $restore = $backup;
+        }
+        return $restore;
+    }
+
 ?>
index 986f338b815a184e17d2105b0e1ec2d1db566973..eb0a96c9fa5962f695f776bde3b88778538751ba 100644 (file)
@@ -117,6 +117,10 @@ class block_admin extends block_base {
 
                 $this->content->items[]='<a href="'.$CFG->wwwroot.'/files/index.php?id='.$this->instance->pageid.'&amp;wdir=/backupdata">'.get_string('restore').'...</a>';
                 $this->content->icons[]='<img src="'.$CFG->pixpath.'/i/restore.gif" height="16" width="16" alt="" />';
+
+                $this->content->items[]='<a href="'.$CFG->wwwroot.'/course/import.php?id='.$this->instance->pageid.'">'.get_string('importdata').'</a>';
+                $this->content->icons[]='<img src="'.$CFG->pixpath.'/i/restore.gif" height="16" width="16" alt="" />';
+
                 $this->content->items[]='<a href="scales.php?id='.$this->instance->pageid.'">'.get_string('scales').'...</a>';
                 $this->content->icons[]='<img src="'.$CFG->pixpath.'/i/scales.gif" height="16" width="16" alt="" />';
             }
index fc20a90a6f96f82d8963aaf79cf244af8679c96c..da4ab08f47a05279ee46b812eebf36fc8e223681 100644 (file)
@@ -254,6 +254,8 @@ $string['coursegrades'] = 'Course grades';
 $string['courseinfo'] = 'Course info';
 $string['courserestore'] = 'Course restore';
 $string['courses'] = 'Courses';
+$string['coursestaught'] = 'Courses I have taught';
+$string['coursescategory'] = 'Courses in the same category';
 $string['courseupdates'] = 'Course updates';
 $string['courseuploadlimit'] = 'Course upload limit';
 $string['create'] = 'Create';
@@ -590,6 +592,10 @@ $string['htmleditordisabledbrowser'] = 'The HTML editor is unavailable because y
 $string['htmlformat'] = 'Pretty HTML format';
 $string['icqnumber'] = 'ICQ number';
 $string['idnumber'] = 'ID number';
+$string['importdata'] = 'Import course data';
+$string['importdatafrom'] = 'Find a course to import data from:';
+$string['importdataexported'] = 'Exported data from \'from\' course successfully.<br /> Continue to import into your \'to\' course.';
+$string['importdatafinished'] = 'Import complete! Continue to your course';
 $string['importmetacoursenote'] = 'Use this form to add courses to your meta course (this will import the enrolments)';
 $string['inactive'] = 'Inactive';
 $string['include'] = 'Include';
@@ -797,6 +803,7 @@ $string['nopotentialadmins'] = 'No potential admins';
 $string['nopotentialcreators'] = 'No potential course creators';
 $string['nopotentialstudents'] = 'No potential students';
 $string['nopotentialteachers'] = 'No potential teachers';
+$string['noresults'] = 'No results';
 $string['normal'] = 'Normal';
 $string['normalfilter'] = 'Normal search';
 $string['nostudentsfound'] = 'No $a found';
@@ -1093,6 +1100,7 @@ $string['userprofilefor'] = 'User profile for $a';
 $string['users'] = 'Users';
 $string['usersnew'] = 'New users';
 $string['userzones'] = 'User zones';
+$string['usethiscourse'] = 'Use this course';
 $string['usingexistingcourse'] = 'Using existing course';
 $string['version'] = 'Version';
 $string['view'] = 'View';