let main_panel_buffer = null; function show(file) { if (main_panel_buffer == null) main_panel_buffer = document.getElementById("main_panel").innerHTML; $.ajax ({ url: "./res/forum/" + file + "/" + file + ".html", dataType: "html", success: function(data) { $("#main_panel").html(main_panel_buffer + data); } }); } 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)); } }) }); } async function inject_info(id, username, postfix) { let am_i_admin = await is_admin(); $.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 = ((am_i_admin) ? `Uživatelské jméno:
` : ``) + `Přezdívka:
` + ((am_i_admin) ? `Admin: ${admin_select}
` : ``) + `Pohlaví: ${sex_select}
Bio:
`; $(id).html(output + postfix); } }); } async function update_user(old_username, username, nickname, admin, sex, bio, refresh) { let am_i_admin = await is_admin(); $.ajax ({ url: "./res/forum/api/update_user.php" + "?old_username=" + old_username + "&nickname=" + nickname + "&sex=" + sex + "&bio=" + bio + ((am_i_admin) ? "&username=" + username + "&admin=" + admin : ""), success: function(result) { show(refresh); } }); } function is_admin() { return new Promise(function(resolve) { $.ajax ({ url: "./res/forum/api/is_admin.php", success: function(result) { resolve(result.admin); } }) }); } function show_upload_popup() { $("#upload_popup").css("display", "flex"); } function upload() { let formData = new FormData(); formData.append('file_upload', $('#file_upload')[0].files[0]); 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()); $.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: alert("Neplatný formát!"); break; } } }); }