'.lang('entry has been deleted sucessfully').': '.$file."
\n";
}
}
else
{
$setup_tpl->set_var('error_msg',$f);
}
}
$setup_tpl->set_var('backup_now_button','');
$setup_tpl->set_var('upload',' '.
'');
$setup_tpl->set_var('backup_mincount','');
$setup_tpl->set_var('backup_files','backup_files ? ' checked="true"':'').
// do NOT allow to change "backup files" outside of setup
($is_setup ? '' : ' disabled="true" title="'.htmlspecialchars(lang('Can only be change via Setup!')).'"').'/>');
$setup_tpl->set_var('backup_save_settings','');
if ($_POST['upload'] && is_array($_FILES['uploaded']) && !$_FILES['uploaded']['error'] &&
is_uploaded_file($_FILES['uploaded']['tmp_name']))
{
move_uploaded_file($_FILES['uploaded']['tmp_name'],$db_backup->backup_dir.'/'.$_FILES['uploaded']['name']);
if (function_exists('md5_file')) // php4.2+
{
$md5 = ', md5='.md5_file($db_backup->backup_dir.'/'.$_FILES['uploaded']['name']);
}
$setup_tpl->set_var('error_msg',lang("succesfully uploaded file %1",$_FILES['uploaded']['name'].', '.
sprintf('%3.1lf MB (%d)',$_FILES['uploaded']['size']/(1024*1024),$_FILES['uploaded']['size']).$md5));
}
// delete a backup
if ($_POST['delete'])
{
list($file) = each($_POST['delete']);
$file = $db_backup->backup_dir.'/'.basename($file); // basename to not allow to change the dir
if (unlink($file)) $setup_tpl->set_var('error_msg',lang("backup '%1' deleted",$file));
}
// rename a backup
if ($_POST['rename'])
{
list($file) = each($_POST['rename']);
$new_name = $_POST['new_name'][$file];
if (!empty($new_name))
{
list($ending) = array_reverse(explode('.', $file));
list($new_ending, $has_ending) = array_reverse(explode('.', $new_name));
if(!$has_ending || $new_ending != $ending) $new_name .= '.'.$ending;
$file = $db_backup->backup_dir.'/'.basename($file); // basename to not allow to change the dir
$ext = preg_match('/(\.gz|\.bz2)+$/i',$file,$matches) ? $matches[1] : '';
$new_file = $db_backup->backup_dir.'/'.preg_replace('/(\.gz|\.bz2)+$/i','',basename($new_name)).$ext;
if (rename($file,$new_file)) $setup_tpl->set_var('error_msg',lang("backup '%1' renamed to '%2'",basename($file),basename($new_file)));
}
}
// restore a backup
if ($_POST['restore'])
{
list($file) = each($_POST['restore']);
$file = $db_backup->backup_dir.'/'.basename($file); // basename to not allow to change the dir
if (is_resource($f = $db_backup->fopen_backup($file,true)))
{
echo '
'.lang('restore started, this might take a few minutes ...')."
\n".str_repeat(' ',4096);
$db_backup->restore($f, true, $file); // allways convert to current system charset on restore
$setup_tpl->set_var('error_msg',lang("backup '%1' restored",$file));
if ($run_in_egw)
{
// updating the backup
$cmd = new setup_cmd_update($GLOBALS['egw']->session->account_domain,
$GLOBALS['egw_info']['server']['header_admin_user']='admin',
$GLOBALS['egw_info']['server']['header_admin_password']=uniqid('pw',true),false,true);
echo $cmd->run()."\n";
echo '
'.lang('You should %1log out%2 and in again, to update your current session!','','')."
\n";
}
}
else
{
$setup_tpl->set_var('error_msg',$f);
}
}
// create a new scheduled backup
if ($_POST['schedule'])
{
$asyncservice->set_timer($_POST['times'],'db_backup-'.implode(':',$_POST['times']),'admin.admin_db_backup.do_backup','');
}
// cancel a scheduled backup
if (is_array($_POST['cancel']))
{
list($id) = each($_POST['cancel']);
$asyncservice->cancel_timer($id);
}
// list scheduled backups
if (($jobs = $asyncservice->read('db_backup-%')))
{
foreach($jobs as $job)
{
$setup_tpl->set_var($job['times']);
$setup_tpl->set_var('next_run',date('Y-m-d H:i',$job['next']));
$setup_tpl->set_var('actions','');
$setup_tpl->parse('schedule_rows','schedule_row',true);
}
}
// input-fields to create a new scheduled backup
foreach($times=array('year'=>'*','month'=>'*','day'=>'*','dow'=>'2-6','hour'=>3,'min'=>0) as $name => $default)
{
$setup_tpl->set_var($name,'');
}
$setup_tpl->set_var('next_run',' ');
$setup_tpl->set_var('actions','');
$setup_tpl->parse('schedule_rows','schedule_row',true);
// listing the availible backup sets
$setup_tpl->set_var('backup_dir',$db_backup->backup_dir);
$setup_tpl->set_var('set_rows','');
$handle = @opendir($db_backup->backup_dir);
$files = array();
while($handle && ($file = readdir($handle)))
{
if ($file != '.' && $file != '..')
{
$files[$file] = filectime($db_backup->backup_dir.'/'.$file);
}
}
if ($handle) closedir($handle);
arsort($files);
foreach($files as $file => $ctime)
{
$size = filesize($db_backup->backup_dir.'/'.$file);
$setup_tpl->set_var(array(
'filename' => $file,
'mod' => date('Y-m-d H:i',$ctime),
'size' => sprintf('%3.1lf MB (%d)',$size/(1024*1024),$size),
'actions' => ' '."\n".
' '."\n".
' '."\n".
'',
));
$setup_tpl->parse('set_rows','set_row',true);
}
$setup_tpl->set_var(array(
'lang_scheduled_backups'=> lang('scheduled backups'),
'lang_year' => lang('year'),
'lang_month' => lang('month'),
'lang_day' => lang('day'),
'lang_dow' => lang('day of week (0-6, 0=sunday)'),
'lang_hour' => lang('hour (0-24)'),
'lang_minute' => lang('minute'),
'lang_next_run' => lang('next run'),
'lang_actions' => lang('actions'),
'lang_backup_sets' => lang('backup sets'),
'lang_backup_cleanup' => lang('backup housekeeping'),
'lang_backup_mincount' => lang('min backup count'),
'lang_backup_files_info' => lang('backup files (needs ZipArchive)'),
'lang_backup_files' => lang('check to backup and restore the files directory (may use a lot of space, make sure to configure housekeeping accordingly)'),
'lang_filename' => lang('filename'),
'lang_date' => lang('created'),
'lang_mod' => lang('modified'),
'lang_size' => lang('size'),
));
$setup_tpl->set_var('self',$self);
$setup_tpl->pparse('out','T_db_backup');
if ($run_in_egw)
{
common::egw_footer();
}
else
{
$GLOBALS['egw_setup']->html->show_footer();
}