summaryrefslogtreecommitdiff
path: root/_upload/index.php
blob: 1e42f1d87d95f884f6ebc0ad14a1382fe68e51de (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<?php

require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/session.php"; global $_USER; global $_PROFILE;
require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/functions.php";

$id = array_values(array_filter(array_keys($_GET), function ($i) {
    return str_starts_with($i, "/") && strlen($i) > 1;
}))[0] ?? null;

if (isset($id)) {
    $id = substr($id, 1);
    if (!preg_match("/[a-zA-Z0-6]/m", $id)) {
        header("Location: /");
        die();
    }

    if (!file_exists($_SERVER['DOCUMENT_ROOT'] . "/includes/data/gallery/" . $id . ".json")) {
        header("Location: /");
        die();
    }

    if (file_exists($_SERVER['DOCUMENT_ROOT'] . "/includes/data/gallery/" . $id . ".json")) {
        $data = json_decode(pf_utf8_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/gallery/" . $id . ".json")), true);
        $title_pre = getNameFromId($id);
    } else {
        header("Location: /");
        die();
    }

    $title = "lang_upload_title";
} else {
    header("Location: /");
    die();
}

require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/header.php";
require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/navigation.php";

?>
<form method="post" action="/_upload/save/?id=<?= $id ?>" id="main-form" enctype="multipart/form-data">
    <div class="container">
        <br><br>
        <h1>
            <?php if ($id !== $_USER): ?>
            <span><?= getNameFromId($id) ?></span>
            <span style="float: right;"><a href="/gallery/<?= $id ?>" class="btn btn-outline-dark"><?= l("lang_edit_cancel") ?></a></span>
            <?php endif; ?>
        </span>
        </h1>

        <?php if (isset($_GET["success"])): ?>
            <div class="alert alert-success">
                <strong><?= l("lang_upload_success_0") ?></strong><?= l("lang_upload_success_1") ?> <a href="/upload/<?= $id ?>"><?= l("lang_upload_success_2") ?></a>
            </div>
        <?php else: ?>
            <?php if (isset($_GET['error'])): ?>
                <div class="alert alert-danger">
                    <strong><?= l("lang_upload_error") ?></strong><?= l("lang_upload_errors_" . $_GET['error']) ?>
                </div>
            <?php endif; ?>

            <div>
                <p><?= l("lang_upload_select") ?></p>
                <input type="file" name="file" style="width: 100%;">
                <script>
                    window.onload = () => {
                        document.getElementsByName("file")[0].value = "";
                    }

                    document.getElementsByName("file")[0].onchange = () => {
                        if (document.getElementsByName("file")[0].files[0] && document.getElementsByName("file")[0].files[0].type.startsWith("image/")) {
                            document.getElementById("preview").src = URL.createObjectURL(document.getElementsByName("file")[0].files[0]);
                            document.getElementById("preview").onload = () => URL.revokeObjectURL(document.getElementById("preview").src);
                            document.getElementById("form-btn").classList.remove("disabled");
                        } else {
                            document.getElementById("preview").src = "/icons/defaultpage.svg";
                            document.getElementById("form-btn").classList.add("disabled");
                        }
                    }
                </script>
            </div>

            <p>
                <img src="/icons/defaultpage.svg" style="width: 100%; max-width: 300px; margin-top: 20px; border-radius: 10px;" id="preview">
            </p>

            <a id="form-btn" class="btn btn-primary disabled"><?= l("lang_upload_confirm") ?></a>

            <script>
                document.getElementById("form-btn").onclick = (event) => {
                    new bootstrap.Modal(document.getElementById("confirm")).show()
                }
            </script>
        <?php endif; ?>

        <br><br>
    </div>

    <div class="modal fade" id="confirm">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <h4 class="modal-title"><?= l("lang_upload_dialog") ?></h4>
                    <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
                </div>

                <div class="modal-body">
                    <p><?= l("lang_upload_notice") ?></p>
                    <p>
                        <?= l("lang_upload_summary") ?><br>
                        <!--suppress HtmlFormInputWithoutLabel -->
                        <textarea class="form-control" name="summary"></textarea>
                    </p>
                    <p><?= l("lang_upload_followup") ?></p>
                    <button class="btn btn-primary"><?= l("lang_edit_confirm_button") ?></button>
                </div>
            </div>
        </div>
    </div>
</form>

<?php require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/footer.php"; ?>