<?php
/**
 * @version        1.14.0
 * @package        Joomla
 * @subpackage     Edocman
 * @author         Tuan Pham Ngoc
 * @copyright      Copyright (C) 2011 - 2025 Ossolution Team
 * @license        GNU/GPL, see LICENSE.php
 */

defined('_JEXEC') or die;

use Joomla\CMS\Language\Text;
use Joomla\CMS\Router\Route;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Session\Session;

HTMLHelper::_('bootstrap.framework');
?>

<div class="row">
    <div class="col-md-12" style="padding-top:20px;">
        <h1><i class="fas fa-upload"></i> <?php echo Text::_('EDOCMAN_IMPORT_DATA'); ?></h1>
        <p class="lead"><?php echo Text::_('EDOCMAN_IMPORT_DATA_DESC'); ?></p>
    </div>
</div>

<div class="row">
    <div class="col-md-8">
        <div class="card">
            <div class="card-header">
                <h5><i class="fas fa-upload"></i> <?php echo Text::_('EDOCMAN_UPLOAD_SQL_FILE'); ?></h5>
            </div>
            <div class="card-body">
                <form method="post" action="<?php echo Route::_('index.php?option=com_edocman&task=importdb.upload'); ?>" 
                      enctype="multipart/form-data" id="importForm">
                    <?php echo HTMLHelper::_('form.token'); ?>
                    
                    <div class="mb-3">
                        <label for="import_file" class="form-label"><?php echo Text::_('EDOCMAN_SELECT_SQL_FILE'); ?>:</label>
                        <input type="file" class="form-control" id="import_file" name="jform[import_file]" 
                               accept=".sql" required>
                        <div class="form-text">
                            <?php echo Text::_('EDOCMAN_SQL_FILE_ONLY'); ?>
                        </div>
                    </div>
                    
                    <div class="mb-3">
                        <div class="form-check">
                            <input class="form-check-input" type="checkbox" id="clear_existing" 
                                   name="clear_existing" value="1">
                            <label class="form-check-label" for="clear_existing">
                                <?php echo Text::_('EDOCMAN_CLEAR_EXISTING_DATA'); ?>
                            </label>
                            <div class="form-text text-danger">
                                <?php echo Text::_('EDOCMAN_CLEAR_EXISTING_WARNING'); ?>
                            </div>
                        </div>
                    </div>
                    
                    <div class="mb-3">
                        <div class="form-check">
                            <input class="form-check-input" type="checkbox" id="update_existing" 
                                   name="update_existing" value="1">
                            <label class="form-check-label" for="update_existing">
                                <?php echo Text::_('EDOCMAN_UPDATE_EXISTING_RECORDS'); ?>
                            </label>
                        </div>
                    </div>
                    
                    <div class="mb-3">
                        <div class="form-check">
                            <input class="form-check-input" type="checkbox" id="import_files" 
                                   name="import_files" value="1">
                            <label class="form-check-label" for="import_files">
                                <?php echo Text::_('EDOCMAN_IMPORT_FILES'); ?>
                            </label>
                            <div class="form-text">
                                <?php echo Text::_('EDOCMAN_IMPORT_FILES_DESC'); ?>
                            </div>
                        </div>
                    </div>
                    
                    <div class="mb-3">
                        <div class="form-check">
                            <input class="form-check-input" type="checkbox" id="backup_confirm" required>
                            <label class="form-check-label text-danger" for="backup_confirm">
                                <strong><?php echo Text::_('EDOCMAN_BACKUP_CONFIRM'); ?></strong>
                            </label>
                        </div>
                    </div>
                    
                    <div class="d-grid">
                        <button type="submit" class="btn btn-primary btn-lg" id="importBtn">
                            <i class="fas fa-upload"></i> <?php echo Text::_('EDOCMAN_IMPORT_NOW'); ?>
                        </button>
                    </div>
                </form>
            </div>
        </div>
        
        <div class="card mt-3">
            <div class="card-header">
                <h5><i class="fas fa-terminal"></i> <?php echo Text::_('EDOCMAN_IMPORT_PROGRESS'); ?></h5>
            </div>
            <div class="card-body">
                <div class="progress mb-3" style="display: none;" id="progressBar">
                    <div class="progress-bar" role="progressbar" style="width: 0%"></div>
                </div>
                <div id="importLog" class="bg-light p-3 rounded" style="display: none; max-height: 300px; overflow-y: auto;">
                    <pre id="logContent"></pre>
                </div>
            </div>
        </div>
    </div>
    
    <div class="col-md-4">
        <div class="card">
            <div class="card-header">
                <h5><i class="fas fa-database"></i> <?php echo Text::_('EDOCMAN_CURRENT_DATABASE'); ?></h5>
            </div>
            <div class="card-body">
                <h6><?php echo Text::_('EDOCMAN_CURRENT_STATISTICS'); ?>:</h6>
                <ul class="list-unstyled">
                    <li><i class="fas fa-folder text-primary"></i> <?php echo Text::_('EDOCMAN_CATEGORIES'); ?>: <strong><?php echo $this->stats['categories']; ?></strong></li>
                    <li><i class="fas fa-file text-success"></i> <?php echo Text::_('EDOCMAN_DOCUMENTS'); ?>: <strong><?php echo $this->stats['documents']; ?></strong></li>
                    <li><i class="fas fa-tags text-warning"></i> <?php echo Text::_('EDOCMAN_TAGS'); ?>: <strong><?php echo $this->stats['tags']; ?></strong></li>
                    <li><i class="fas fa-link text-info"></i> <?php echo Text::_('EDOCMAN_RELATIONS'); ?>: <strong><?php echo $this->stats['document_categories']; ?></strong></li>
                </ul>
            </div>
        </div>
        
        <div class="card mt-3">
            <div class="card-header bg-warning">
                <h5><i class="fas fa-exclamation-triangle"></i> <?php echo Text::_('EDOCMAN_IMPORTANT_WARNING'); ?></h5>
            </div>
            <div class="card-body">
                <div class="alert alert-warning">
                    <strong><?php echo Text::_('EDOCMAN_BACKUP_FIRST'); ?></strong>
                    <p class="mb-0 small"><?php echo Text::_('EDOCMAN_BACKUP_FIRST_DESC'); ?></p>
                </div>
                
                <h6><?php echo Text::_('EDOCMAN_IMPORT_PROCESS'); ?>:</h6>
                <ol class="small">
                    <li><?php echo Text::_('EDOCMAN_IMPORT_STEP_1'); ?></li>
                    <li><?php echo Text::_('EDOCMAN_IMPORT_STEP_2'); ?></li>
                    <li><?php echo Text::_('EDOCMAN_IMPORT_STEP_3'); ?></li>
                    <li><?php echo Text::_('EDOCMAN_IMPORT_STEP_4'); ?></li>
                </ol>
            </div>
        </div>
        
        <div class="card mt-3">
            <div class="card-header">
                <h5><i class="fas fa-question-circle"></i> <?php echo Text::_('EDOCMAN_SUPPORTED_FORMATS'); ?></h5>
            </div>
            <div class="card-body">
                <ul class="small">
                    <li><?php echo Text::_('EDOCMAN_MYSQL_SQL_DUMPS'); ?></li>
                    <li><?php echo Text::_('EDOCMAN_PHPMYADMIN_EXPORTS'); ?></li>
                    <li><?php echo Text::_('EDOCMAN_STANDARD_SQL_INSERTS'); ?></li>
                    <li><?php echo Text::_('EDOCMAN_CREATE_TABLE_STATEMENTS'); ?></li>
                </ul>
            </div>
        </div>
    </div>
</div>

