<?php

///////////////////////////////////////////////////////////////////////////////
// Tool Configuration
///////////////////////////////////////////////////////////////////////////////

define('THIS_TOOL_NAME', 'add-domains');
define('ADD_DOMAINS_CONFIG_KEY', str_replace('-', '_', THIS_TOOL_NAME) . '_tool');

///////////////////////////////////////////////////////////////////////////////

include "includes/base-init.php";

?><!DOCTYPE HTML>
<html lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <base href="<?php echo $baseUrl; ?>">
    <link rel="shortcut icon" type="image/x-icon" href="lib/layouts/images/favicon.ico">
    <meta name="author" content="">
    <title>Watch My Domains Server Edition v6</title>
    <meta name="description" content="">
    <meta name="keywords" content="">
    <meta name="dcterms.rightsHolder" content="Softnik Technologies">

    <link rel="preload" as="font" href="lib/layouts/fonts/Quicksand/quicksand-v28-latin-regular.woff2" type="font/woff2" crossorigin="anonymous">
    <link rel="preload" as="font" href="lib/layouts/fonts/Roboto-Slab/roboto-slab-v22-latin-regular.woff2" type="font/woff2" crossorigin="anonymous">
    <link rel="preload" as="font" href="lib/layouts/fonts/Josefin-Sans/josefin-sans-v23-latin-regular.woff2" type="font/woff2" crossorigin="anonymous">
    <link rel="preload" as="font" href="lib/layouts/fonts/Quicksand/quicksand-v28-latin-700.woff2" type="font/woff2" crossorigin="anonymous">
    <link rel="preload" as="font" href="lib/layouts/fonts/Roboto-Slab/roboto-slab-v22-latin-700.woff2" type="font/woff2" crossorigin="anonymous">
    <link rel="preload" as="font" href="lib/layouts/fonts/Josefin-Sans/josefin-sans-v23-latin-600.woff2" type="font/woff2" crossorigin="anonymous">
    <link rel="preload" as="font" href="lib/layouts/fonts/Open-Sans/open-sans-v40-greek_hebrew_latin_vietnamese-regular.woff2" type="font/woff2" crossorigin="anonymous">
    <link rel="preload" as="font" href="lib/layouts/fonts/Open-Sans/open-sans-v40-greek_hebrew_latin_vietnamese-700.woff2" type="font/woff2" crossorigin="anonymous">

    <link href="lib/layouts/fonts/Quicksand/fonts.css" rel="stylesheet">
    <link href="lib/layouts/fonts/Roboto-Slab/fonts.css" rel="stylesheet">
    <link href="lib/layouts/fonts/Josefin-Sans/fonts.css" rel="stylesheet">
    <link href="lib/layouts/fonts/Open-Sans/fonts.css" rel="stylesheet">
    <link href="lib/layouts/css/min/common.min.css" rel="stylesheet">
    <link href="lib/layouts/modules/common/css/min/common.min.css" rel="stylesheet">

    <script src="api.php?c=js&file=data.js&loc=modules/toolbox" type="text/javascript"></script>

    <link rel="stylesheet" type="text/css" href="lib/layouts/colors/light/light.css" id="theme-mode-css">
    <link rel="stylesheet" type="text/css" href="lib/layouts/colors/light/themes/Default/default.css" id="theme-default-css">
    <link rel="stylesheet" type="text/css" href="lib/layouts/colors/light/themes/Default/styles.css" id="theme-styles-css">
    <link rel="stylesheet" type="text/css" href="lib/php/styles.php" id="theme-bg-css">

    <link href="tools/css/common.css" rel="stylesheet">
    <link href="tools/css/common-dark.css" rel="stylesheet">
    <link href="tools/css/toggle.css" rel="stylesheet">
    <link href="tools/css/add-domains.css" rel="stylesheet">
</head>
<body>

<div class="theme-select theme-bg" id="themechange"></div>
<div class="menu-select theme-bg" id="menuselect"></div>

<div id="contentwrap">

	<?php include "includes/head-logo-toolbar.php" ?>

    <div id="content">

        <div id="menucontrol">
            <?php include "includes/add-domains-sidebar.php"; ?>
        </div>

        <div id="maincontent">
            <div id="domaindata">
                <div class="add-domain-panel">

                    <div class="panel-header">
                        <h1>Add Domains</h1>
                    </div>

                    <!-- Mode Tabs -->
                    <div class="mode-tabs">
                        <button type="button" class="mode-tab active" data-mode="single">Single Domain</button>
                        <button type="button" class="mode-tab" data-mode="bulk">Bulk CSV</button>
                    </div>

                    <!-- ==================== SINGLE ADD ==================== -->
                    <div id="single-add-container" class="add-block">

                        <form id="add-domain-form" method="post" action="">
                            <input type="hidden" name="action" value="add_domain">
                            <input type="hidden" name="extra_columns" id="extra_columns" value="">

                            <div class="field-row">
                                <label for="domain">Domain</label>
                                <input type="text" name="domain" id="domain"
                                       placeholder="example.com or sub.domain.com"
                                       autocomplete="off"
                                       value="">
                            </div>

                            <div id="extra-fields-container"></div>

                            <div class="category-section">
                                <label for="category_id">Category</label>
                                <select name="category_id" id="category_id">
                                    <option value="">No category</option>
                                </select>
                                <div class="help-text">
                                    Only one category can be selected.
                                </div>
                            </div>

                            <div class="form-actions-section">
                                <div id="single-domain-add-status" class="submit-status-text"></div>
                                <button type="button" class="btn btn-secondary" id="clear-form-btn">Clear</button>
                                <button type="submit" class="btn btn-primary">Add Domain</button>
                            </div>
                        </form>

                    </div>

                    <!-- ==================== BULK ADD ==================== -->
                    <div id="bulk-add-container" class="add-block" style="display:none;">

                        <form id="bulk-add-form" method="post" action="">
                            <input type="hidden" name="action" value="add_bulk">
                            <input type="hidden" name="bulk_extra_columns" id="bulk_extra_columns" value="">

                            <div class="bulk-help-block">
                                <p class="help-text">
                                    Enter one domain per line in CSV format. Do <strong>not</strong> include a header row — only data rows.
                                    Values must follow the column order shown below:
                                </p>
                                <div id="bulk-column-order" class="bulk-column-order">
                                    <!-- Populated by JS -->
                                </div>
                            </div>

                            <div class="field-row">
                                <textarea
                                    name="bulk_csv"
                                    id="bulk_csv"
                                    rows="12"
                                    placeholder="Loading column info…"></textarea>
                            </div>

                            <div class="category-section">
                                <label for="bulk_category_id">Category</label>
                                <select name="bulk_category_id" id="bulk_category_id">
                                    <option value="">No category</option>
                                </select>
                                <div class="help-text">
                                    All imported domains will be assigned to this category.
                                </div>
                            </div>

                            <div class="form-actions-section">
                                <div id="bulk-domain-add-status" class="submit-status-text"></div>
                                <button type="submit" class="btn btn-primary">Import Domains</button>
                            </div>
                        </form>

                    </div>
                    <!-- end bulk -->

                </div>
                <!-- end add-domain-panel -->
            </div>
        </div>
        <!-- end maincontent -->

    </div>
    <!-- end content -->

</div>
<!-- end contentwrap -->

<?php
$jsApiBaseUrl      = htmlspecialchars($apiBaseUrl, ENT_QUOTES, 'UTF-8');
$jsExcludedColumns = json_encode($excludedColumns);
$jsPostedDynamic   = json_encode($postedDynamic);
?>

<script>
var baseurl                = "<?php echo $baseUrl; ?>";
var API_BASE_URL           = <?php echo json_encode($jsApiBaseUrl); ?>;
var EXCLUDED_COLUMNS       = <?php echo $jsExcludedColumns; ?>;
var POSTED_VALUES          = <?php echo $jsPostedDynamic; ?>;
var IS_ADMIN               = <?php echo $isAdmin ? 'true' : 'false'; ?>;
var CURRENT_USER           = <?php echo json_encode($currentUserName); ?>;
var ADD_DOMAINS_CONFIG_KEY = "<?php echo ADD_DOMAINS_CONFIG_KEY; ?>";
var CONFIG_CREATED_AT      = <?php echo time(); ?>;
var USE_JS_ADD_HANDLER     = true;
</script>

<script type="text/javascript" src="tools/js/common.js"></script>
<script type="text/javascript" src="tools/js/domain-add.js"></script>

<script>
setTheme();
</script>

</body>
</html>