loadLangs(array("admin", "kundenkarte@kundenkarte")); // Access control if (!$user->admin && !$user->hasRight('kundenkarte', 'admin')) { accessforbidden(); } // Parameters $action = GETPOST('action', 'aZ09'); $confirm = GETPOST('confirm', 'alpha'); $form = new Form($db); $backup = new AnlageBackup($db); /* * Actions */ // Create backup if ($action == 'create_backup') { $includeFiles = GETPOSTINT('include_files'); $result = $backup->createBackup($includeFiles); if ($result) { setEventMessages($langs->trans('BackupCreatedSuccess', basename($result)), null, 'mesgs'); } else { setEventMessages($langs->trans('BackupCreatedError').': '.$backup->error, null, 'errors'); } header('Location: '.$_SERVER['PHP_SELF']); exit; } // Download backup if ($action == 'download') { $filename = GETPOST('file', 'alpha'); $filepath = $conf->kundenkarte->dir_output.'/backups/'.basename($filename); if (file_exists($filepath) && strpos($filename, 'kundenkarte_backup_') === 0) { header('Content-Type: application/zip'); header('Content-Disposition: attachment; filename="'.basename($filepath).'"'); header('Content-Length: '.filesize($filepath)); readfile($filepath); exit; } else { setEventMessages($langs->trans('FileNotFound'), null, 'errors'); } } // Delete backup if ($action == 'confirm_delete' && $confirm == 'yes') { $filename = GETPOST('file', 'alpha'); if ($backup->deleteBackup($filename)) { setEventMessages($langs->trans('BackupDeleted'), null, 'mesgs'); } else { setEventMessages($langs->trans('Error'), null, 'errors'); } header('Location: '.$_SERVER['PHP_SELF']); exit; } // Restore backup if ($action == 'confirm_restore' && $confirm == 'yes') { $filename = GETPOST('file', 'alpha'); $clearExisting = GETPOSTINT('clear_existing'); $filepath = $conf->kundenkarte->dir_output.'/backups/'.basename($filename); if ($backup->restoreBackup($filepath, $clearExisting)) { setEventMessages($langs->trans('RestoreSuccess'), null, 'mesgs'); } else { setEventMessages($langs->trans('RestoreError').': '.$backup->error, null, 'errors'); } header('Location: '.$_SERVER['PHP_SELF']); exit; } // Upload backup if ($action == 'upload_backup' && !empty($_FILES['backupfile']['name'])) { $backupDir = $conf->kundenkarte->dir_output.'/backups'; if (!is_dir($backupDir)) { dol_mkdir($backupDir); } $filename = $_FILES['backupfile']['name']; // Validate filename format if (!preg_match('/^kundenkarte_backup_\d{4}-\d{2}-\d{2}_\d{2}-\d{2}-\d{2}\.zip$/', $filename)) { setEventMessages($langs->trans('InvalidBackupFile'), null, 'errors'); } elseif ($_FILES['backupfile']['error'] !== UPLOAD_ERR_OK) { setEventMessages($langs->trans('ErrorUploadFailed'), null, 'errors'); } else { $targetPath = $backupDir.'/'.$filename; if (move_uploaded_file($_FILES['backupfile']['tmp_name'], $targetPath)) { setEventMessages($langs->trans('BackupUploaded'), null, 'mesgs'); } else { setEventMessages($langs->trans('ErrorUploadFailed'), null, 'errors'); } } header('Location: '.$_SERVER['PHP_SELF']); exit; } /* * View */ $title = $langs->trans("BackupRestore"); llxHeader('', $title); // Subheader $linkback = ''.$langs->trans("BackToModuleList").''; print load_fiche_titre($title, $linkback, 'title_setup'); // Configuration header $head = kundenkarteAdminPrepareHead(); print dol_get_fiche_head($head, 'backup', $langs->trans('ModuleKundenKarteName'), -1, "fa-address-card"); // Confirmation dialogs if ($action == 'delete') { $filename = GETPOST('file', 'alpha'); print $form->formconfirm( $_SERVER['PHP_SELF'].'?file='.urlencode($filename), $langs->trans('DeleteBackup'), $langs->trans('ConfirmDeleteBackup', $filename), 'confirm_delete', '', 'yes', 1 ); } if ($action == 'restore') { $filename = GETPOST('file', 'alpha'); $formquestion = array( array( 'type' => 'checkbox', 'name' => 'clear_existing', 'label' => $langs->trans('ClearExistingData'), 'value' => 0 ) ); print $form->formconfirm( $_SERVER['PHP_SELF'].'?file='.urlencode($filename), $langs->trans('RestoreBackup'), $langs->trans('ConfirmRestoreBackup', $filename), 'confirm_restore', $formquestion, 'yes', 1 ); } // Statistics $stats = $backup->getStatistics(); print '
'; // Stats cards print '
'; print '
'; print ''; print '
'; print ''.$langs->trans('TotalElements').''; print ''.$stats['total_anlagen'].''; print '
'; print '
'; print '
'; print ''; print '
'; print ''.$langs->trans('TotalFiles').''; print ''.$stats['total_files'].''; print '
'; print '
'; print '
'; print ''; print '
'; print ''.$langs->trans('TotalConnections').''; print ''.$stats['total_connections'].''; print '
'; print '
'; print '
'; print ''; print '
'; print ''.$langs->trans('CustomersWithAnlagen').''; print ''.$stats['total_customers'].''; print '
'; print '
'; print '
'; print ''; print '
'; print ''.$langs->trans('FilesStorageSize').''; print ''.dol_print_size($stats['files_size']).''; print '
'; print '
'; print '
'; // Create Backup Section print '
'.$langs->trans("CreateBackup").'
'; print '

'; print '
'; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print '
'.$langs->trans("BackupOptions").'
'.$langs->trans("IncludeUploadedFiles").''; print ' '; print ''.$langs->trans("IncludeFilesHelp").''; print '
'; print '
'; print '
'; print ''; print '
'; print '
'; // Upload Backup Section print '

'; print '
'.$langs->trans("UploadBackup").'
'; print '

'; print '
'; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print '
'.$langs->trans("UploadBackupFile").'
'.$langs->trans("SelectBackupFile").''; print ''; print ' '; print '
'; print '
'; // Existing Backups Section print '

'; print '
'.$langs->trans("ExistingBackups").'
'; print '

'; $backups = $backup->getBackupList(); print ''; print ''; print ''; print ''; print ''; print ''; print ''; if (empty($backups)) { print ''; print ''; print ''; } else { foreach ($backups as $bk) { print ''; print ''; print ''; print ''; print ''; print ''; } } print '
'.$langs->trans("Filename").''.$langs->trans("Date").''.$langs->trans("Size").''.$langs->trans("Actions").'
'.$langs->trans("NoBackupsFound").'
'.dol_escape_htmltag($bk['filename']).''.dol_print_date(strtotime($bk['date']), 'dayhour').''.dol_print_size($bk['size']).''; // Download button print ''; print ''; print ' '; // Restore button print ''; print ''; print ' '; // Delete button print ''; print ''; print ''; print '
'; // Info section print '
'; print '
'; print ' '.$langs->trans("BackupInfo").':
'; print '• '.$langs->trans("BackupInfoContent").'
'; print '• '.$langs->trans("BackupInfoFiles").'
'; print '• '.$langs->trans("BackupInfoRestore").'
'; print '
'; print '
'; print dol_get_fiche_end(); llxFooter(); $db->close();