aboutsummaryrefslogtreecommitdiff
path: root/Neutron-trunk/cms-special/admin/language/index.php
blob: 4c16e04dfc937157d17ca4523caf551656e48506 (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
<?php require_once "../../../resources/private/relative.php"; getRelativeDetails("cms-special"); ?>
<?php $pageConfig = [ "domName" => "Langue et région", "headerName" => "Langue et région" ]; require_once $_SERVER['DOCUMENT_ROOT'] . "/cms-special/admin/\$resources/precontent.php"; ?>
<div style="text-align: center;"><select id="langselect">
    <?php

    $langs = scandir($_SERVER['DOCUMENT_ROOT'] . "/resources/i18n");
    foreach ($langs as $language) {
        if ($language != "." && $language != ".." && $language != ".htaccess") {
            if (file_exists($_SERVER['DOCUMENT_ROOT'] . "/resources/i18n/" . $language . "/\$metadata.json")) {
                echo("<option value=\"" . $language . "\">");
                echo(json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/resources/i18n/" . $language . "/\$metadata.json"))->localized_name . " — " . json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/resources/i18n/" . $language . "/\$metadata.json"))->name);
                echo("</option>");
            }
        }
    }

    ?>
</select>
</p>
<input id="langselect-confirm" type="button" value="OK" onclick="changeLanguage()"></div>
<?php require_once $_SERVER['DOCUMENT_ROOT'] . "/cms-special/admin/\$resources/postcontent.php"; ?>

<script>

function changeLanguage() {
    document.getElementById('langselect').disabled = true;
    document.getElementById('langselect-confirm').disabled = true;
    var formData = new FormData();
    formData.append("lang", document.getElementById('langselect').value);
    $.ajax({
        type: "POST",
        dataType: 'html',
        url: "<?= $GLOBALS["SYSTEM_ROOT"] ?>/api/admin/instant_language_change.php",
        success: function (data) {
            if (data == "ok") {
                document.getElementById('langselect').disabled = false;
                document.getElementById('langselect-confirm').disabled = false;
                ajaxPageReload();
            } else {
                alert("<?= $lang["admin-errors"]["errorprefix"] ?>" + data);
                document.getElementById('langselect').disabled = false;
                document.getElementById('langselect-confirm').disabled = false;
            }
        },
        error: function (error) {
            alert("<?= $lang["admin-errors"]["connerror"] ?>\n\n<?= $lang["admin-errors"]["housekeeping"][1] ?>")
            document.getElementById('langselect').disabled = false;
            document.getElementById('langselect-confirm').disabled = false;
        },
        data: formData,
        cache: false,
        contentType: false,
        processData: false
    });
}

</script>