dokeos-backup
[ class tree: dokeos-backup ] [ index: dokeos-backup ] [ all elements ]

Source for file import_backup.php

Documentation is available at import_backup.php

  1. <?php // $Id: import_backup.php 15430 2008-05-26 20:46:31Z yannoo $
  2. /*
  3. ============================================================================== 
  4.     Dokeos - elearning and course management software
  5.     
  6.     Copyright (c) 2004-2008 Dokeos SPRL
  7.     Copyright (c) 2003 Ghent University (UGent)
  8.     Copyright (c) 2001 Universite catholique de Louvain (UCL)
  9.     Copyright (c) Bart Mollet (bart.mollet@hogent.be)
  10.     
  11.     For a full list of contributors, see "credits.txt".
  12.     The full license can be read in "license.txt".
  13.     
  14.     This program is free software; you can redistribute it and/or
  15.     modify it under the terms of the GNU General Public License
  16.     as published by the Free Software Foundation; either version 2
  17.     of the License, or (at your option) any later version.
  18.     
  19.     See the GNU General Public License for more details.
  20.     
  21.     Contact address: Dokeos, rue du Corbeau, 108, B-1030 Brussels, Belgium
  22.     Mail: info@dokeos.com
  23. ============================================================================== 
  24. */
  25. /**
  26.  * ==============================================================================
  27.  * Import a backup.
  28.  * 
  29.  * @author Bart Mollet <bart.mollet@hogent.be>
  30.  * @package dokeos.backup
  31.  *  ==============================================================================
  32.  */
  33. /*
  34. ==============================================================================
  35.         INIT SECTION
  36. ==============================================================================
  37. */ 
  38. // name of the language file that needs to be included 
  39. $language_file array('coursebackup','admin');
  40.  
  41. // including the global file
  42. include ('../inc/global.inc.php');
  43.  
  44. // Check access rights (only teachers are allowed here)
  45. {
  46.     api_not_allowed(true);    
  47. }
  48.  
  49. //remove memory and time limits as much as possible as this might be a long process...
  50. if(function_exists('ini_set'))
  51. {
  52.     ini_set('memory_limit','256M');
  53.     ini_set('max_execution_time',1800);
  54. }
  55.  
  56. // section for the tabs
  57. $this_section=SECTION_COURSES;
  58.  
  59. // breadcrumbs
  60. $interbreadcrumb[array ("url" => "../course_info/maintenance.php""name" => get_lang('Maintenance'));
  61.  
  62. // Displaying the header
  63. $nameTools get_lang('ImportBackup');
  64. Display::display_header($nameTools);
  65.  
  66. // include additional libraries
  67. include_once(api_get_path(LIBRARY_PATH'fileManage.lib.php');
  68. require_once('classes/CourseBuilder.class.php');
  69. require_once('classes/CourseArchiver.class.php');
  70. require_once('classes/CourseRestorer.class.php');
  71. require_once('classes/CourseSelectForm.class.php');
  72.  
  73. // Display the tool title
  74.  
  75. /*
  76. ==============================================================================
  77.         MAIN CODE
  78. ==============================================================================
  79. */ 
  80. if(  (isset($_POST['action']&& $_POST['action'== 'course_select_form' || (isset($_POST['import_option']&& $_POST['import_option'== 'full_backup' ) )
  81. {
  82.     $error=false;    
  83.     if(isset($_POST['action']&& $_POST['action'== 'course_select_form' )
  84.     {
  85.         $course CourseSelectForm::get_posted_course();
  86.     }
  87.     else
  88.     {
  89.         if$_POST['backup_type'== 'server')
  90.         {
  91.             $filename $_POST['backup_server'];    
  92.             $delete_file false;
  93.         }
  94.         else
  95.         {
  96.             if($_FILES['backup']['error']==0){
  97.                 $filename CourseArchiver::import_uploaded_file($_FILES['backup']['tmp_name']);
  98.                 if ($filename === false)
  99.                 {
  100.                     $error true;
  101.                 }
  102.                 else
  103.                 {
  104.                     $delete_file true;
  105.                 }
  106.             }
  107.             else{
  108.                 $error=true;
  109.             }
  110.         }
  111.         if(!$error)
  112.         {
  113.           $course CourseArchiver::read_course($filename,$delete_file);
  114.         }
  115.     }
  116.     if(!$error && $course->has_resources())
  117.     {
  118.         $cr new CourseRestorer($course);
  119.         $cr->set_file_option($_POST['same_file_name_option']);
  120.         $cr->restore();
  121.         Display::display_normal_message(get_lang('ImportFinished').
  122.                 '<a class="bottom-link" href="../course_home/course_home.php?'.api_get_cidreq().'">&gt;&gt; '.get_lang('CourseHomepage').'</a>',false);
  123.     }
  124.     else
  125.     {
  126.         if(!$error){
  127.             Display::display_warning_message(get_lang('NoResourcesInBackupFile').
  128.                 '<a class="bottom-link" href="import_backup.php?'.api_get_cidreq().'">&gt;&gt; '.get_lang('TryAgain').'</a>',false);
  129.         }
  130.         elseif ($filename === false)
  131.         {
  132.             Display::display_error_message(get_lang('ArchivesDirectoryNotWriteableContactAdmin').
  133.                 '<a class="bottom-link" href="import_backup.php?'.api_get_cidreq().'">&gt;&gt; '.get_lang('TryAgain').'</a>',false);
  134.         }
  135.         else
  136.         {
  137.             Display::display_error_message(ucfirst(get_lang('UploadError')).
  138.                 '<a class="bottom-link" href="import_backup.php?'.api_get_cidreq().'">&gt;&gt; '.get_lang('TryAgain').'</a>',false);
  139.         }
  140.     }
  141. }
  142. elseif (isset($_POST['import_option']&& $_POST['import_option'== 'select_items')
  143. {
  144.     if$_POST['backup_type'== 'server')
  145.     {
  146.         $filename $_POST['backup_server'];
  147.         $delete_file false;    
  148.     }
  149.     else
  150.     {
  151.         $filename CourseArchiver::import_uploaded_file($_FILES['backup']['tmp_name']);
  152.         $delete_file true;
  153.     }
  154.     $course CourseArchiver::read_course($filename,$delete_file);
  155.     if ($course->has_resources(&& ($filename !== false))
  156.     {
  157.         CourseSelectForm::display_form($course,array('same_file_name_option'=>$_POST['same_file_name_option']));
  158.     }
  159.     elseif ($filename === false)
  160.     {
  161.         Display::display_error_message(get_lang('ArchivesDirectoryNotWriteableContactAdmin').
  162.                 '<a class="bottom-link" href="import_backup.php?'.api_get_cidreq().'">&gt;&gt; '.get_lang('TryAgain').'</a>',false);
  163.     }
  164.     else
  165.     {
  166.         Display::display_warning_message(get_lang('NoResourcesInBackupFile').    
  167.                 '<a class="bottom-link" href="import_backup.php?'.api_get_cidreq().'">&gt;&gt; '.get_lang('TryAgain').'</a>',false);
  168.     }
  169. }
  170. else
  171. {
  172.     $user api_get_user_info();
  173.     $backups CourseArchiver::get_available_backups($is_platformAdmin?null:$user['user_id']);
  174.     $backups_available (count($backups)>0);
  175.     
  176.     echo get_lang('SelectBackupFile').'<br /><br />';
  177.     
  178.     include (api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php');
  179.     $form new FormValidator('import_backup_form','POST','import_backup.php''','multipart/form-data');
  180.     
  181.     $renderer $form->defaultRenderer();
  182.     $renderer->setElementTemplate('<div>{element}</div> ');
  183.     
  184.     $form->addElement('hidden','action''restore_backup');
  185.     
  186.     $form->addElement('radio''backup_type'''get_lang('LocalFile')'local''id="bt_local" class="checkbox" onclick="javascript:document.import_backup_form.backup_server.disabled=true;document.import_backup_form.backup.disabled=false;"');
  187.     $form->addElement('file''backup''''style="margin-left: 50px;"');
  188.     $form->addElement('html''<br />');
  189.     
  190.     if$backups_available ){
  191.         $form->addElement('radio''backup_type'''get_lang('ServerFile')'server''id="bt_server" class="checkbox" onclick="javascript:document.import_backup_form.backup_server.disabled=false;document.import_backup_form.backup.disabled=true;"');
  192.         $options['null''-';
  193.         foreach($backups as $index => $backup)
  194.         {
  195.             $options[$backup['file']]$backup['course_code'].' ('.$backup['date'];
  196.         }
  197.         $form->addElement('select''backup_server'''$options'style="margin-left: 50px;"');
  198.         $form->addElement('html','<script type="text/javascript">document.import_backup_form.backup_server.disabled=true;</script>');
  199.     }
  200.     else
  201.     {
  202.         $form->addElement('radio''''''<i>'.get_lang('NoBackupsAvailable').'</i>''''disabled="true"');
  203.     }
  204.     
  205.     $form->addElement('html''<br /><br />');
  206.     
  207.     $form->addElement('radio''import_option'''get_lang('ImportFullBackup')'full_backup''id="import_option_1" class="checkbox"');
  208.     $form->addElement('radio''import_option'''get_lang('LetMeSelectItems')'select_items''id="import_option_2" class="checkbox"');
  209.     
  210.     $form->addElement('html''<br /><br />');
  211.     
  212.     $form->addElement('html'get_lang('SameFilename'));
  213.     $form->addElement('html''<br /><br />');
  214.     $form->addElement('radio''same_file_name_option'''get_lang('SameFilenameSkip')FILE_SKIP'id="same_file_name_option_1" class="checkbox"');
  215.     $form->addElement('radio''same_file_name_option'''get_lang('SameFilenameRename')FILE_RENAME'id="same_file_name_option_2" class="checkbox"');
  216.     $form->addElement('radio''same_file_name_option'''get_lang('SameFilenameOverwrite')FILE_OVERWRITE'id="same_file_name_option_3" class="checkbox"');
  217.     
  218.     $form->addElement('html''<br />');
  219.     $form->addElement('submit'nullget_lang('ImportBackup'));
  220.     
  221.     $values['backup_type''local';
  222.     $values['import_option''full_backup';
  223.     $values['same_file_name_option'FILE_OVERWRITE;
  224.     $form->setDefaults($values);
  225.     
  226.     $form->add_progress_bar();
  227.     
  228.     $form->display();
  229.         
  230. }
  231. /*
  232. ==============================================================================
  233.         FOOTER 
  234. ==============================================================================
  235. */ 
  236. ?>

Documentation generated on Thu, 12 Jun 2008 13:48:42 -0500 by phpDocumentor 1.4.1