2024-05-16 21:17:40 +02:00
|
|
|
let main_panel_buffer = null;
|
|
|
|
|
2024-05-16 21:07:07 +02:00
|
|
|
function show(file)
|
|
|
|
{
|
2024-05-16 21:17:40 +02:00
|
|
|
if (main_panel_buffer == null) main_panel_buffer = document.getElementById("main_panel").innerHTML;
|
|
|
|
|
2024-05-16 21:07:07 +02:00
|
|
|
$.ajax
|
|
|
|
({
|
2024-05-22 16:18:18 +02:00
|
|
|
url: "./res/forum/" + file + "/" + file + ".html",
|
2024-05-16 21:07:07 +02:00
|
|
|
dataType: "html",
|
|
|
|
success: function(data)
|
|
|
|
{
|
2024-05-16 21:17:40 +02:00
|
|
|
$("#main_panel").html(main_panel_buffer + data);
|
2024-05-16 21:07:07 +02:00
|
|
|
}
|
|
|
|
});
|
2024-05-22 18:19:19 +02:00
|
|
|
}
|
|
|
|
|
2024-05-22 18:25:45 +02:00
|
|
|
function selection(type, value)
|
|
|
|
{
|
|
|
|
return new Promise(function(resolve)
|
|
|
|
{
|
|
|
|
$.ajax
|
|
|
|
({
|
|
|
|
url: "./res/forum/admin/" + type + "_selection.html",
|
|
|
|
dataType: "html",
|
|
|
|
success: function(result)
|
|
|
|
{
|
|
|
|
resolve(result.replace("value=\"" + value, "selected value=\"" + value));
|
|
|
|
}
|
|
|
|
})
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2024-05-22 21:20:46 +02:00
|
|
|
async function inject_info(id, username, postfix)
|
2024-05-22 18:19:19 +02:00
|
|
|
{
|
2024-05-22 21:20:46 +02:00
|
|
|
let am_i_admin = await is_admin();
|
|
|
|
|
2024-05-22 18:19:19 +02:00
|
|
|
$.ajax
|
|
|
|
({
|
|
|
|
url: "./res/forum/api/user_info.php?username=" + username,
|
|
|
|
success: async function(result)
|
|
|
|
{
|
|
|
|
let admin_select = await selection("admin", result.admin);
|
|
|
|
let sex_select = await selection("sex", result.sex);
|
|
|
|
|
|
|
|
let output =
|
2024-05-22 21:20:46 +02:00
|
|
|
((am_i_admin) ? `Uživatelské jméno: <input id="username" class="editable" type="text" value="${result.username}"><br>` : ``) +
|
|
|
|
`Přezdívka: <input id="nickname" class="editable" type="text" value="${result.nickname}"><br>` +
|
|
|
|
((am_i_admin) ? `Admin: ${admin_select}<br>` : ``) +
|
|
|
|
`Pohlaví: ${sex_select}<br>
|
2024-05-22 18:19:19 +02:00
|
|
|
Bio: <input id="bio" class="editable" type="text" value="${result.bio}"><br>`;
|
|
|
|
|
|
|
|
$(id).html(output + postfix);
|
|
|
|
}
|
|
|
|
});
|
2024-05-22 18:40:36 +02:00
|
|
|
}
|
|
|
|
|
2024-05-22 21:15:38 +02:00
|
|
|
async function update_user(old_username, username, nickname, admin, sex, bio, refresh)
|
2024-05-22 18:40:36 +02:00
|
|
|
{
|
2024-05-22 21:15:38 +02:00
|
|
|
let am_i_admin = await is_admin();
|
|
|
|
|
2024-05-22 18:40:36 +02:00
|
|
|
$.ajax
|
|
|
|
({
|
|
|
|
url: "./res/forum/api/update_user.php" +
|
|
|
|
"?old_username=" + old_username +
|
|
|
|
"&nickname=" + nickname +
|
|
|
|
"&sex=" + sex +
|
2024-05-22 21:15:38 +02:00
|
|
|
"&bio=" + bio +
|
|
|
|
((am_i_admin) ? "&username=" + username +
|
|
|
|
"&admin=" + admin : ""),
|
2024-05-22 18:40:36 +02:00
|
|
|
success: function(result)
|
|
|
|
{
|
|
|
|
show(refresh);
|
|
|
|
}
|
|
|
|
});
|
2024-05-22 21:15:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function is_admin()
|
|
|
|
{
|
|
|
|
return new Promise(function(resolve)
|
|
|
|
{
|
|
|
|
$.ajax
|
|
|
|
({
|
|
|
|
url: "./res/forum/api/is_admin.php",
|
|
|
|
success: function(result)
|
|
|
|
{
|
|
|
|
resolve(result.admin);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
});
|
2024-05-24 16:32:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function show_upload_popup()
|
|
|
|
{
|
|
|
|
$("#upload_popup").css("display", "flex");
|
|
|
|
}
|
|
|
|
|
|
|
|
function upload()
|
|
|
|
{
|
|
|
|
let formData = new FormData();
|
2024-05-24 17:00:06 +02:00
|
|
|
|
2024-05-24 16:32:36 +02:00
|
|
|
formData.append('file_upload', $('#file_upload')[0].files[0]);
|
2024-05-24 17:00:06 +02:00
|
|
|
if ($('input[name="name"]').val().trim() != "") formData.append('name', $('input[name="name"]').val());
|
|
|
|
if ($('input[name="desc"]').val().trim() != "") formData.append('desc', $('input[name="desc"]').val());
|
2024-05-24 16:32:36 +02:00
|
|
|
|
|
|
|
$.ajax
|
|
|
|
({
|
|
|
|
url : './res/forum/api/upload_picture.php',
|
|
|
|
type : 'POST',
|
|
|
|
data : formData,
|
|
|
|
processData: false,
|
|
|
|
contentType: false,
|
|
|
|
success : function(result)
|
|
|
|
{
|
|
|
|
switch (result.status)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
show("home");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
alert("Nebyl nahrán soubor!");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
alert("Nebyl vyplněn název příspěvku!");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 3:
|
2024-05-24 17:00:06 +02:00
|
|
|
alert("Neplatný formát!");
|
2024-05-24 16:32:36 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2024-05-16 21:07:07 +02:00
|
|
|
}
|