Compare commits
3 Commits
main
...
794e2447c0
| Author | SHA1 | Date | |
|---|---|---|---|
| 794e2447c0 | |||
| ff437d082c | |||
| 22e3776892 |
@@ -16,6 +16,6 @@
|
||||
- change `base` in `vite.config.ts`
|
||||
- change `API_BASE_URL` and `CLIENT_FRONTEND_URL` in `src/App.jsx`
|
||||
- **backend !!**
|
||||
- change `ADMIN_PASS` and `API_PATH` in `admin_api.php`
|
||||
- change `ADMIN_PASS` in `admin_api.php`
|
||||
- change `$password` in `adm/phpliteadmin.config.php`
|
||||
- **block http requests to `data.db`!!!**
|
||||
@@ -1,8 +1,9 @@
|
||||
<?php
|
||||
include 'k-api.php';
|
||||
|
||||
|
||||
// CHANGE THIS
|
||||
const ADMIN_PASS = "superdengipassword4";
|
||||
|
||||
const API_PATH = "./";
|
||||
|
||||
function db()
|
||||
|
||||
+24
-47
@@ -112,8 +112,8 @@ CreateApi(function ($api) {
|
||||
$classId = substr(strtoupper($req->data['classId']), 0, 10);
|
||||
// according docs (UPPERCASE, MIN 3 MAX 10)
|
||||
$db = db();
|
||||
$results = FastDBReq($db, "SELECT * FROM classes WHERE classid = ?", [$classId]);
|
||||
$db = null;
|
||||
$results = FastDBReq($db, "SELECT classid FROM classes WHERE classid = ?", [$classId]);
|
||||
|
||||
if (count($results) != 0) {
|
||||
return $results[0];
|
||||
} else {
|
||||
@@ -130,7 +130,7 @@ CreateApi(function ($api) {
|
||||
// according docs (UPPERCASE, MIN 3 MAX 10)
|
||||
$db = db();
|
||||
$results = FastDBReq($db, "SELECT userclassname FROM classes WHERE classid = ?", [$classId]);
|
||||
$db = null;
|
||||
|
||||
|
||||
if (count($results) != 0) {
|
||||
return $results[0];
|
||||
@@ -147,7 +147,7 @@ CreateApi(function ($api) {
|
||||
$adminId = $req->data['adminId'];
|
||||
$db = db();
|
||||
$results = FastDBReq($db, "SELECT adminName FROM admins where adminid = ?", [$adminId]);
|
||||
$db = null;
|
||||
|
||||
|
||||
if (count($results) != 0) {
|
||||
return $results[0];
|
||||
@@ -164,7 +164,7 @@ CreateApi(function ($api) {
|
||||
$adminId = $req->data['adminId'];
|
||||
$db = db();
|
||||
$results = FastDBReq($db, "SELECT adminPrems FROM admins where adminid = ?", [$adminId]);
|
||||
$db = null;
|
||||
|
||||
|
||||
if (count($results) != 0) {
|
||||
return $results[0];
|
||||
@@ -180,8 +180,8 @@ CreateApi(function ($api) {
|
||||
}
|
||||
$adminId = $req->data['adminId'];
|
||||
$db = db();
|
||||
$results = FastDBReq($db, "SELECT * FROM admins WHERE adminid = ?", [$adminId]);
|
||||
$db = null;
|
||||
$results = FastDBReq($db, "SELECT adminId FROM admins WHERE adminid = ?", [$adminId]);
|
||||
|
||||
|
||||
if (count($results) != 0) {
|
||||
return $results[0];
|
||||
@@ -203,7 +203,7 @@ CreateApi(function ($api) {
|
||||
if (!preg_match('/\d{1,2}-\d{1,2}-(\d{2}|\d{4})$/', $day)) return "wrong date format";
|
||||
|
||||
$db = db();
|
||||
$results = FastDBReq($db, "SELECT * FROM changes WHERE classId = ? AND forDay = ?", [$classId, $day]);
|
||||
$results = FastDBReq($db, "SELECT content FROM changes WHERE classId = ? AND forDay = ?", [$classId, $day]);
|
||||
|
||||
|
||||
if (count($results) > 0) {
|
||||
@@ -218,37 +218,33 @@ CreateApi(function ($api) {
|
||||
}
|
||||
}
|
||||
if ($has_full_rings) {
|
||||
$db = null;
|
||||
// with rings
|
||||
return ['data' => $content, 'type' => 2];
|
||||
} else {
|
||||
// without rings
|
||||
$results = FastDBReq($db, "SELECT * FROM RINGS WHERE classId = ?", [$classId]);
|
||||
$results = FastDBReq($db, "SELECT content, fromDate FROM RINGS WHERE classId = ?", [$classId]);
|
||||
$rings = json_decode(findClosestDateSort($results, $day)['content'], true);
|
||||
$out = $content;
|
||||
if ($rings !== null) {
|
||||
$out = joinArraysByKey($content, $rings, true);
|
||||
}
|
||||
$db = null;
|
||||
return ['data' => $out, 'type' => 1];
|
||||
}
|
||||
} else {
|
||||
// return shedules + calls
|
||||
$dayOfWeek = getDayOfWeek($day);
|
||||
$results = FastDBReq($db, "SELECT * FROM schedules WHERE classId = ? AND dayOfWeek = ?", [$classId, $dayOfWeek]);
|
||||
$results = FastDBReq($db, "SELECT content, fromDate FROM schedules WHERE classId = ? AND dayOfWeek = ?", [$classId, $dayOfWeek]);
|
||||
if (count($results) > 0) {
|
||||
$out = [];
|
||||
$schedule = json_decode(findClosestDateSort($results, $day)['content'], true);
|
||||
$results = FastDBReq($db, "SELECT * FROM RINGS WHERE classId = ?", [$classId]);
|
||||
$results = FastDBReq($db, "SELECT content, fromDate FROM RINGS WHERE classId = ?", [$classId]);
|
||||
$rings = json_decode(findClosestDateSort($results, $day)['content'], true);
|
||||
$out = $schedule;
|
||||
if ($rings !== null) {
|
||||
$out = joinArraysByKey($schedule, $rings);
|
||||
}
|
||||
$db = null;
|
||||
return ['data' => $out, 'type' => 0];
|
||||
} else {
|
||||
$db = null;
|
||||
return ['data' => []];
|
||||
}
|
||||
}
|
||||
@@ -260,9 +256,8 @@ CreateApi(function ($api) {
|
||||
}
|
||||
$adminId = $req->data['adminId'];
|
||||
$db = db();
|
||||
$results = FastDBReq($db, "SELECT * FROM admins WHERE adminId=?", [$adminId]);
|
||||
$results = FastDBReq($db, "SELECT adminClass FROM admins WHERE adminId=?", [$adminId]);
|
||||
if (count($results) == 0) {
|
||||
$db = null;
|
||||
$req->res->code(400);
|
||||
return "админ не найден";
|
||||
# end
|
||||
@@ -277,23 +272,22 @@ CreateApi(function ($api) {
|
||||
|
||||
if ($tab != 2) {
|
||||
if ($tab == 0) {
|
||||
$results = FastDBReq($db, "SELECT * FROM changes WHERE classId = ? AND forDay = ?", [$classId, $day]);
|
||||
$results = FastDBReq($db, "SELECT content FROM changes WHERE classId = ? AND forDay = ?", [$classId, $day]);
|
||||
if (count($results) > 0) {
|
||||
$changes = json_decode($results[0]['content'], true);
|
||||
}
|
||||
}
|
||||
$dayOfWeek = getDayOfWeek($day);
|
||||
$results = FastDBReq($db, "SELECT * FROM schedules WHERE classId = ? AND dayOfWeek = ?", [$classId, $dayOfWeek]);
|
||||
$results = FastDBReq($db, "SELECT content, fromDate FROM schedules WHERE classId = ? AND dayOfWeek = ?", [$classId, $dayOfWeek]);
|
||||
if (count($results) > 0) {
|
||||
$schedule = json_decode(findClosestDateSort($results, $day)['content'], true);
|
||||
}
|
||||
} else {
|
||||
$results = FastDBReq($db, "SELECT * FROM RINGS WHERE classId = ?", [$classId]);
|
||||
$results = FastDBReq($db, "SELECT content, fromDate FROM RINGS WHERE classId = ?", [$classId]);
|
||||
if (count($results) > 0) {
|
||||
$rings = json_decode(findClosestDateSort($results, $day)['content'], true);
|
||||
}
|
||||
}
|
||||
$db = null;
|
||||
|
||||
switch ($tab) {
|
||||
case 0:
|
||||
@@ -321,9 +315,8 @@ CreateApi(function ($api) {
|
||||
}
|
||||
$adminId = $req->data['adminId'];
|
||||
$db = db();
|
||||
$results = FastDBReq($db, "SELECT * FROM admins WHERE adminId=?", [$adminId]);
|
||||
$results = FastDBReq($db, "SELECT adminClass FROM admins WHERE adminId=?", [$adminId]);
|
||||
if (count($results) == 0) {
|
||||
$db = null;
|
||||
$req->res->code(400);
|
||||
return "админ не найден";
|
||||
# end
|
||||
@@ -334,7 +327,6 @@ CreateApi(function ($api) {
|
||||
$newDataRaw = $req->data['newData'];
|
||||
$newData = json_decode($newDataRaw, true);
|
||||
|
||||
// im too lazy to close db
|
||||
|
||||
switch ($tab) {
|
||||
case 0: // changes
|
||||
@@ -342,7 +334,7 @@ CreateApi(function ($api) {
|
||||
// if no chnages skip, else publish
|
||||
|
||||
$dayOfWeek = getDayOfWeek($day);
|
||||
$results = FastDBReq($db, "SELECT * FROM schedules WHERE classId = ? AND dayOfWeek = ?", [$classId, $dayOfWeek]);
|
||||
$results = FastDBReq($db, "SELECT fromDate, content FROM schedules WHERE classId = ? AND dayOfWeek = ?", [$classId, $dayOfWeek]);
|
||||
$publish = true;
|
||||
if (count($results) > 0) {
|
||||
$schedule = json_decode(findClosestDateSort($results, $day)['content'], true);
|
||||
@@ -352,7 +344,7 @@ CreateApi(function ($api) {
|
||||
}
|
||||
if ($publish) {
|
||||
// removing changes for today if they are exists
|
||||
$results = FastDBReq($db, "SELECT * FROM changes WHERE classId = ? AND forDay = ?", [$classId, $day]);
|
||||
$results = FastDBReq($db, "SELECT content FROM changes WHERE classId = ? AND forDay = ?", [$classId, $day]);
|
||||
if (count($results) > 0) {
|
||||
$changes = json_decode($results[0]['content'], true);
|
||||
if ($newData === $changes) {
|
||||
@@ -395,9 +387,8 @@ CreateApi(function ($api) {
|
||||
}
|
||||
$adminId = $req->data['adminId'];
|
||||
$db = db();
|
||||
$results = FastDBReq($db, "SELECT * FROM admins WHERE adminId=?", [$adminId]);
|
||||
$results = FastDBReq($db, "SELECT adminClass FROM admins WHERE adminId=?", [$adminId]);
|
||||
if (count($results) == 0) {
|
||||
$db = null;
|
||||
$req->res->code(400);
|
||||
return "админ не найден";
|
||||
# end
|
||||
@@ -417,10 +408,8 @@ CreateApi(function ($api) {
|
||||
FastDBReq($db, 'DELETE FROM rings WHERE classId=? AND fromDate=?', [$classId, $day]);
|
||||
break;
|
||||
default:
|
||||
$db = null;
|
||||
return "you saved your live because you didn't know what tabs are here";
|
||||
}
|
||||
$db = null;
|
||||
return true;
|
||||
});
|
||||
$api->on('/update_admin', "POST", function ($req) {
|
||||
@@ -436,14 +425,12 @@ CreateApi(function ($api) {
|
||||
}
|
||||
$adminId = $req->data['adminId'];
|
||||
$db = db();
|
||||
$results = FastDBReq($db, "SELECT * FROM admins WHERE adminId=?", [$adminId]);
|
||||
$results = FastDBReq($db, "SELECT adminPrems FROM admins WHERE adminId=?", [$adminId]);
|
||||
if (count($results) == 0) {
|
||||
$db = null;
|
||||
$req->res->code(400);
|
||||
return "админ не найден";
|
||||
}
|
||||
if (!$withSelf && !in_array($results[0]['adminPrems'], [-1, 2])) {
|
||||
$db = null;
|
||||
$req->res->code(400);
|
||||
return 'нету прав';
|
||||
}
|
||||
@@ -462,7 +449,6 @@ CreateApi(function ($api) {
|
||||
try {
|
||||
FastDBReq($db, 'UPDATE admins SET adminName = ? WHERE adminId = ?', [$value, $adminId]);
|
||||
} catch (PDOException) {
|
||||
$db = null;
|
||||
return "egor";
|
||||
}
|
||||
break;
|
||||
@@ -483,16 +469,13 @@ CreateApi(function ($api) {
|
||||
try {
|
||||
FastDBReq($db, 'UPDATE admins SET adminName = ? WHERE adminId = ?', [$value, $person]);
|
||||
} catch (PDOException) {
|
||||
$db = null;
|
||||
return "egor";
|
||||
}
|
||||
break;
|
||||
default:
|
||||
$db = null;
|
||||
return "?";
|
||||
}
|
||||
}
|
||||
$db = null;
|
||||
return true;
|
||||
});
|
||||
|
||||
@@ -503,29 +486,26 @@ CreateApi(function ($api) {
|
||||
}
|
||||
$adminId = $req->data['adminId'];
|
||||
$db = db();
|
||||
$results = FastDBReq($db, "SELECT * FROM admins WHERE adminId=?", [$adminId]);
|
||||
$results = FastDBReq($db, "SELECT adminPrems, adminClass FROM admins WHERE adminId=?", [$adminId]);
|
||||
if (count($results) == 0) {
|
||||
$db = null;
|
||||
$req->res->code(400);
|
||||
return "админ не найден";
|
||||
}
|
||||
if (!in_array($results[0]['adminPrems'], [-1, 2])) {
|
||||
$db = null;
|
||||
$req->res->code(400);
|
||||
return "недостаточно прав";
|
||||
}
|
||||
|
||||
$classId = $results[0]['adminClass'];
|
||||
|
||||
$results = FastDBReq($db, "SELECT * FROM classes WHERE classId=?", [$classId]);
|
||||
$results = FastDBReq($db, "SELECT classid FROM classes WHERE classid=?", [$classId]);
|
||||
if (count($results) == 0) {
|
||||
$db = null;
|
||||
$req->res->code(400);
|
||||
return "класса не существует";
|
||||
}
|
||||
$classData = $results[0];
|
||||
$adminsData = FastDBReq($db, "SELECT * FROM admins WHERE adminClass=?", [$classId]);
|
||||
$db = null;
|
||||
|
||||
|
||||
return ["status" => 1, "class" => $classData, "admins" => $adminsData];
|
||||
});
|
||||
@@ -537,14 +517,12 @@ CreateApi(function ($api) {
|
||||
}
|
||||
$adminId = $req->data['adminId'];
|
||||
$db = db();
|
||||
$results = FastDBReq($db, "SELECT * FROM admins WHERE adminId=?", [$adminId]);
|
||||
$results = FastDBReq($db, "SELECT adminPrems, adminClass FROM admins WHERE adminId=?", [$adminId]);
|
||||
if (count($results) == 0) {
|
||||
$db = null;
|
||||
$req->res->code(400);
|
||||
return "админ не найден";
|
||||
}
|
||||
if (!in_array($results[0]['adminPrems'], [-1, 2])) {
|
||||
$db = null;
|
||||
$req->res->code(400);
|
||||
return "недостаточно прав";
|
||||
}
|
||||
@@ -610,7 +588,6 @@ CreateApi(function ($api) {
|
||||
FastDBReq($db, "DELETE FROM admins WHERE adminId=?", [$person]);
|
||||
return true;
|
||||
default:
|
||||
$db = null;
|
||||
return "?";
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1,11 +1,8 @@
|
||||
// CHANGE TO YOUR API DESTINATION
|
||||
export const API_BASE_URL = "http://localhost:8321/admin_api.php";
|
||||
// export const API_BASE_URL = "http://192.168.3.10:8321/admin_api.php";
|
||||
// export const API_BASE_URL = "http://x90620bx.beget.tech/dx4back/admin_api.php"
|
||||
|
||||
// TYPE: url/dx4/
|
||||
export const CLIENT_FRONTEND_URL = "http://localhost:5173/dx4/";
|
||||
// export const CLIENT_FRONTEND_URL = "http://x90620bx.beget.tech/dx4/";
|
||||
export const CLIENT_FRONTEND_URL = "http://localhost:5173/";
|
||||
|
||||
import { atom, useAtom } from "jotai";
|
||||
import { atomWithStorage } from "jotai/utils";
|
||||
|
||||
@@ -11,5 +11,5 @@ export default defineConfig({
|
||||
}),
|
||||
tailwindcss(),
|
||||
],
|
||||
base: "/dx4dashboard",
|
||||
base: "/",
|
||||
});
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
// CHANGE TO YOUR API DESTINATION
|
||||
export const API_BASE_URL = "http://localhost:8321/api.php";
|
||||
// export const API_BASE_URL = "http://192.168.3.10:8321/api.php";
|
||||
// export const API_BASE_URL = "http://x90620bx.beget.tech/dx4back/api.php"
|
||||
|
||||
import { atom, useAtom } from "jotai";
|
||||
import { atomWithStorage } from "jotai/utils";
|
||||
|
||||
+4
-4
@@ -5,7 +5,7 @@ import { VitePWA } from "vite-plugin-pwa";
|
||||
|
||||
// https://vite.dev/config/
|
||||
export default defineConfig({
|
||||
base: "/dx4/",
|
||||
base: "/",
|
||||
plugins: [
|
||||
react({
|
||||
babel: {
|
||||
@@ -19,11 +19,11 @@ export default defineConfig({
|
||||
name: "dx 4",
|
||||
short_name: "dx4",
|
||||
description: "dnevnik-x app",
|
||||
theme_color: "#eee",
|
||||
theme_color: "#000",
|
||||
background_color: "#000",
|
||||
display: "standalone",
|
||||
scope: "/dx4/",
|
||||
start_url: "/dx4/",
|
||||
scope: "/",
|
||||
start_url: "/",
|
||||
icons: [
|
||||
{
|
||||
src: "icons/windows11/SmallTile.scale-100.png",
|
||||
|
||||
Reference in New Issue
Block a user