2022-11-18 21:25:40 +01:00
|
|
|
|
|
|
|
function send()
|
|
|
|
{
|
|
|
|
let me = document.getElementById("btnSend");
|
|
|
|
if (me.classList.contains("btn-disabled")) return;
|
|
|
|
|
|
|
|
me.innerHTML = "<div class=\"spinnerbox\"><div class=\"spinner primary\"></div></div>";
|
|
|
|
|
|
|
|
me.classList.add("btn-disabled");
|
|
|
|
|
|
|
|
let uid = document.getElementById("uid");
|
|
|
|
let key = document.getElementById("ukey");
|
2022-11-21 22:52:44 +01:00
|
|
|
let tit = document.getElementById("tit");
|
|
|
|
let cnt = document.getElementById("cnt");
|
2022-11-18 21:25:40 +01:00
|
|
|
let pio = document.getElementById("prio");
|
2022-11-21 22:52:44 +01:00
|
|
|
let cha = document.getElementById("chan");
|
2022-11-18 21:25:40 +01:00
|
|
|
|
|
|
|
uid.classList.remove('input-invalid');
|
|
|
|
key.classList.remove('input-invalid');
|
|
|
|
msg.classList.remove('input-invalid');
|
2022-11-21 22:52:44 +01:00
|
|
|
cnt.classList.remove('input-invalid');
|
2022-11-18 21:25:40 +01:00
|
|
|
pio.classList.remove('input-invalid');
|
|
|
|
|
|
|
|
let data = new FormData();
|
|
|
|
data.append('user_id', uid.value);
|
|
|
|
data.append('user_key', key.value);
|
2022-11-21 22:52:44 +01:00
|
|
|
if (tit.value !== '') data.append('title', tit.value);
|
|
|
|
if (cnt.value !== '') data.append('content', cnt.value);
|
|
|
|
if (pio.value !== '') data.append('priority', pio.value);
|
|
|
|
if (cha.value !== '') data.append('channel', cha.value);
|
2022-11-18 21:25:40 +01:00
|
|
|
|
|
|
|
let xhr = new XMLHttpRequest();
|
2022-11-20 03:06:08 +01:00
|
|
|
xhr.open('POST', '/send.php', true);
|
2022-11-18 21:25:40 +01:00
|
|
|
xhr.onreadystatechange = function ()
|
|
|
|
{
|
|
|
|
if (xhr.readyState !== 4) return;
|
|
|
|
|
|
|
|
console.log('Status: ' + xhr.status);
|
|
|
|
if (xhr.status === 200 || xhr.status === 401 || xhr.status === 403 || xhr.status === 412)
|
|
|
|
{
|
|
|
|
let resp = JSON.parse(xhr.responseText);
|
|
|
|
if (!resp.success || xhr.status !== 200)
|
|
|
|
{
|
|
|
|
if (resp.errhighlight === 101) uid.classList.add('input-invalid');
|
|
|
|
if (resp.errhighlight === 102) key.classList.add('input-invalid');
|
2022-11-21 22:52:44 +01:00
|
|
|
if (resp.errhighlight === 103) tit.classList.add('input-invalid');
|
|
|
|
if (resp.errhighlight === 104) cnt.classList.add('input-invalid');
|
2022-11-18 21:25:40 +01:00
|
|
|
if (resp.errhighlight === 105) pio.classList.add('input-invalid');
|
2022-11-21 22:52:44 +01:00
|
|
|
if (resp.errhighlight === 106) cha.classList.add('input-invalid');
|
2022-11-18 21:25:40 +01:00
|
|
|
|
|
|
|
Toastify({
|
|
|
|
text: resp.message,
|
|
|
|
gravity: "top",
|
|
|
|
positionLeft: false,
|
|
|
|
backgroundColor: "#D32F2F",
|
|
|
|
}).showToast();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
window.location.href =
|
|
|
|
'/message_sent' +
|
|
|
|
'?ok=' + 1 +
|
|
|
|
'&message_count=' + resp.messagecount +
|
|
|
|
'"a=' + resp.quota +
|
|
|
|
'"a_remain=' + (resp.quota_max-resp.quota) +
|
|
|
|
'"a_max=' + resp.quota_max +
|
|
|
|
'&preset_user_id=' + uid.value +
|
2022-11-21 22:52:44 +01:00
|
|
|
'&preset_user_key=' + key.value +
|
|
|
|
'&preset_channel=' + cha.value;
|
2022-11-18 21:25:40 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Toastify({
|
|
|
|
text: 'Request failed: Statuscode=' + xhr.status,
|
|
|
|
gravity: "top",
|
|
|
|
positionLeft: false,
|
|
|
|
backgroundColor: "#D32F2F",
|
|
|
|
}).showToast();
|
|
|
|
}
|
|
|
|
|
|
|
|
me.classList.remove("btn-disabled");
|
|
|
|
me.innerHTML = "Send";
|
|
|
|
};
|
|
|
|
xhr.send(data);
|
|
|
|
}
|
|
|
|
|
2022-11-20 03:06:08 +01:00
|
|
|
window.addEventListener("load", function ()
|
2022-11-18 21:25:40 +01:00
|
|
|
{
|
2022-11-20 03:06:08 +01:00
|
|
|
const qp = new URLSearchParams(window.location.search);
|
2022-11-18 21:25:40 +01:00
|
|
|
|
2022-11-21 22:52:44 +01:00
|
|
|
let btn = document.getElementById("btnSend");
|
|
|
|
let uid = document.getElementById("uid");
|
|
|
|
let key = document.getElementById("ukey");
|
|
|
|
let tit = document.getElementById("tit");
|
|
|
|
let cnt = document.getElementById("cnt");
|
|
|
|
let pio = document.getElementById("prio");
|
|
|
|
let cha = document.getElementById("chan");
|
2022-11-20 03:06:08 +01:00
|
|
|
|
2022-11-21 22:52:44 +01:00
|
|
|
btn.onclick = function () { send(); return false; };
|
2022-11-20 03:06:08 +01:00
|
|
|
|
2022-11-21 22:52:44 +01:00
|
|
|
if (qp.has('preset_priority')) pio.selectedIndex = parseInt(qp.get("preset_priority"));
|
|
|
|
if (qp.has('preset_user_key')) key.value = qp.get("preset_user_key");
|
|
|
|
if (qp.has('preset_user_id')) uid.value = qp.get("preset_user_id");
|
|
|
|
if (qp.has('preset_title')) tit.value = qp.get("preset_title");
|
|
|
|
if (qp.has('preset_content')) cnt.value = qp.get("preset_content");
|
|
|
|
if (qp.has('preset_channel')) cha.value = qp.get("preset_channel");
|
2022-11-20 03:06:08 +01:00
|
|
|
|
|
|
|
}, false);
|