[svn r11395] replace the form by a formvalidator and add a progress bar for backup import

skala
Julian Prud'homme 18 years ago
parent 56a1aa3bd9
commit 36b713c1e7
  1. 128
      main/coursecopy/import_backup.php

@ -1,4 +1,4 @@
<?php // $Id: import_backup.php 11374 2007-03-03 22:32:33Z yannoo $
<?php // $Id: import_backup.php 11395 2007-03-05 16:03:26Z elixir_julian $
/*
==============================================================================
Dokeos - elearning and course management software
@ -58,6 +58,7 @@ if( ! api_is_allowed_to_edit())
*/
if( (isset($_POST['action']) && $_POST['action'] == 'course_select_form' ) || (isset($_POST['import_option']) && $_POST['import_option'] == 'full_backup' ) )
{
$error=false;
if(isset($_POST['action']) && $_POST['action'] == 'course_select_form' )
{
$course = CourseSelectForm::get_posted_course();
@ -71,8 +72,13 @@ if( (isset($_POST['action']) && $_POST['action'] == 'course_select_form' ) || (
}
else
{
$filename = CourseArchiver::import_uploaded_file($_FILES['backup']['tmp_name']);
$delete_file = true;
if($_FILES['backup']['error']==0){
$filename = CourseArchiver::import_uploaded_file($_FILES['backup']['tmp_name']);
$delete_file = true;
}
else{
$error=true;
}
}
$course = CourseArchiver::read_course($filename,$delete_file);
}
@ -85,7 +91,12 @@ if( (isset($_POST['action']) && $_POST['action'] == 'course_select_form' ) || (
}
else
{
echo get_lang('NoResourcesInBackupFile');
if(!$error){
echo get_lang('NoResourcesInBackupFile');
}
else{
echo get_lang('UploadError');
}
}
CourseArchiver::clean_backup_dir();
echo '<p><a href="../course_home/course_home.php">&lt;&lt; '.get_lang('CourseHomepage').'</a></p>';
@ -118,68 +129,61 @@ else
$user = api_get_user_info();
$backups = CourseArchiver::get_available_backups($is_platformAdmin?null:$user['user_id']);
$backups_available = (count($backups)>0);
?>
<form method="post" action="import_backup.php" enctype="multipart/form-data" name="import_backup_form">
<input type="hidden" name="action" value="restore_backup"/>
<?php echo get_lang('SelectBackupFile') ?>
<br/><br/>
<input type="radio" class="checkbox" name="backup_type" id="bt_local" value="local" checked="checked" onClick="javascript:document.import_backup_form.backup_server.disabled=true;document.import_backup_form.backup.disabled=false;">
<label for="bt_local"><?php echo get_lang('LocalFile') ?></label>
<br/>
<blockquote>
<input type="file" name="backup"/> (*.zip)
</blockquote>
<?php
if( $backups_available )
{
?>
<input type="radio" class="checkbox" name="backup_type" id="bt_server" value="server" onClick="javascript:document.import_backup_form.backup_server.disabled=false;document.import_backup_form.backup.disabled=true;">
<label for="bt_server"><?php echo get_lang('ServerFile') ?></label>
<blockquote>
<select name="backup_server">
<option value="null">-</option>
<?php
// see line 117 $backups = CourseArchiver::get_available_backups($is_platformAdmin?null:$user['user_id']);
foreach($backups as $index => $backup)
{
echo '<option value="'.$backup['file'].'">'.$backup['course_code'].' ('.$backup['date'].')</option>';
}
?>
</select>
<script type="text/javascript">
document.import_backup_form.backup_server.disabled=true;
</script>
</blockquote>
<?php
echo get_lang('SelectBackupFile').'<br/><br/>';
include (api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php');
$form = new FormValidator('import_backup_form','POST','import_backup.php', '','multipart/form-data');
$renderer = $form->defaultRenderer();
$renderer->setElementTemplate('<div>{element}</div> ');
$form->addElement('hidden','action', 'restore_backup');
$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;"');
$form->addElement('file', 'backup', '', 'style="margin-left: 50px;"');
$form->addElement('html', '<br/>');
if( $backups_available ){
$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;"');
$options['null'] = '-';
foreach($backups as $index => $backup)
{
$options[$backup['file']]= $backup['course_code'].' ('.$backup['date'];
}
$form->addElement('select', 'backup_server', '', $options, 'style="margin-left: 50px;"');
$form->addElement('html','<script type="text/javascript">document.import_backup_form.backup_server.disabled=true;</script>');
}
else
{
echo '<input type="radio" disabled="true"/>';
echo '<i>'.get_lang('NoBackupsAvailable').'</i><br/><br/>';
$form->addElement('radio', '', '', '<i>'.get_lang('NoBackupsAvailable').'</i>', '', 'disabled="true"');
}
?>
<input type="radio" class="checkbox" id="import_option_1" name="import_option" value="full_backup" checked="checked"/>
<label for="import_option_1"><?php echo get_lang('ImportFullBackup') ?></label>
<br/>
<input type="radio" class="checkbox" id="import_option_2" name="import_option" value="select_items"/>
<label for="import_option_2"><?php echo get_lang('LetMeSelectItems') ?></label>
<br/>
<br/>
<?php echo get_lang('SameFilename') ?>
<blockquote>
<input type="radio" class="checkbox" id="same_file_name_option_1" name="same_file_name_option" value="<?php echo FILE_SKIP ?>"/>
<label for="same_file_name_option_1"><?php echo get_lang('SameFilenameSkip') ?></label>
<br/>
<input type="radio" class="checkbox" id="same_file_name_option_2" name="same_file_name_option" value="<?php echo FILE_RENAME ?>"/>
<label for="same_file_name_option_2"><?php echo get_lang('SameFilenameRename') ?></label>
<br/>
<input type="radio" class="checkbox" id="same_file_name_option_3" name="same_file_name_option" value="<?php echo FILE_OVERWRITE ?>" checked="checked"/>
<label for="same_file_name_option_3"><?php echo get_lang('SameFilenameOverwrite') ?></label>
</blockquote>
<br/>
<input type="submit" value="<?php echo get_lang('ImportBackup') ?>"/>
</form>
<?php
$form->addElement('html', '<br/><br/>');
$form->addElement('radio', 'import_option', '', get_lang('ImportFullBackup'), 'full_backup', 'id="import_option_1" class="checkbox"');
$form->addElement('radio', 'import_option', '', get_lang('LetMeSelectItems'), 'select_items', 'id="import_option_2" class="checkbox"');
$form->addElement('html', '<br/><br/>');
$form->addElement('html', get_lang('SameFilename'));
$form->addElement('html', '<br/><br/>');
$form->addElement('radio', 'same_file_name_option', '', get_lang('SameFilenameSkip'), FILE_SKIP, 'id="same_file_name_option_1" class="checkbox"');
$form->addElement('radio', 'same_file_name_option', '', get_lang('SameFilenameRename'), FILE_RENAME, 'id="same_file_name_option_2" class="checkbox"');
$form->addElement('radio', 'same_file_name_option', '', get_lang('SameFilenameOverwrite'), FILE_OVERWRITE, 'id="same_file_name_option_3" class="checkbox"');
$form->addElement('html', '<br/>');
$form->addElement('submit', null, get_lang('ImportBackup'));
$values['backup_type'] = 'local';
$values['import_option'] = 'full_backup';
$values['same_file_name_option'] = FILE_OVERWRITE;
$form->setDefaults($values);
$form->add_progress_bar();
$form->display();
}
/*
==============================================================================

Loading…
Cancel
Save