เข้าสู่ระบบข้อมูลนักเรียน
กรุณาลงชื่อเข้าใช้งาน หรือลงทะเบียนเพื่อรอผู้ดูแลระบบอนุมัติ
กรุณาลงชื่อเข้าใช้งาน หรือลงทะเบียนเพื่อรอผู้ดูแลระบบอนุมัติ
Student Directory & Classroom Management
เริ่มต้นเพิ่มรายชื่อนักเรียนพร้อมรูปภาพ เพื่อจัดเก็บข้อมูลและออกรายงานได้ทันที
สร้างห้องเรียน เช่น ป.1/1 หรือ ม.3/2 เพื่อใช้จัดกลุ่มนักเรียนและกรองออกรายงานแยกห้อง
| ลำดับ | ชื่อห้องเรียน | รายละเอียด / หมายเหตุ | จัดการ |
|---|
เงื่อนไข: แสดงรายชื่อทั้งหมด
ไม่มีข้อมูลนักเรียนตามเงื่อนไขที่เลือกสำหรับออกรายงาน
เมื่อมีผู้ใช้ใหม่ลงทะเบียน รายชื่อจะปรากฏที่นี่เพื่อให้ Admin กดอนุมัติก่อนเข้าใช้งาน
| ชื่อ - นามสกุล | อีเมล | บทบาท | สถานะ | การอนุมัติและสิทธิ์ |
|---|
คุณต้องการลบรายชื่อของ - ใช่หรือไม่?
การดำเนินการนี้จะลบทั้งข้อมูลประวัตินักเรียนและไฟล์รูปภาพออกจากระบบอย่างถาวร ไม่สามารถกู้คืนได้
คุณต้องการลบห้องเรียน - ใช่หรือไม่?
ข้อมูลรายชื่อนักเรียนที่อยู่ในห้องนี้จะไม่ถูกลบ แต่จะถูกเปลี่ยนเป็นสถานะไม่ระบุห้องเรียนแทน
กรอกค่า Project URL และ Anon Key จากหน้าตั้งค่า API ของ Supabase เพื่อใช้งานฐานข้อมูลจริง ระบบลงทะเบียนรออนุมัติโดย Admin ระบบห้องเรียน และคลังรูปภาพ (หากเว้นว่าง ระบบจะทำงานในโหมดจำลองในเครื่อง)
-- 1. ตารางโปรไฟล์สมาชิกและระบบอนุมัติโดย Admin (profiles)
create table if not exists public.profiles (
id uuid primary key references auth.users(id) on delete cascade,
email text not null,
full_name text not null default '',
role text not null default 'member' check (role in ('admin', 'member')),
status text not null default 'pending' check (status in ('pending', 'approved', 'rejected')),
created_at timestamptz not null default now()
);
-- Trigger: ผู้ลงทะเบียนคนแรกของระบบได้รับสิทธิ์ Admin (approved) อัตโนมัติ คนถัดไปเป็น pending รออนุมัติ
create or replace function public.handle_new_user()
returns trigger
language plpgsql
security definer set search_path = public
as $$
declare
has_any_profile boolean;
begin
select exists(select 1 from public.profiles) into has_any_profile;
insert into public.profiles (id, email, full_name, role, status)
values (
new.id,
coalesce(new.email, ''),
coalesce(new.raw_user_meta_data->>'full_name', ''),
case when not has_any_profile then 'admin' else 'member' end,
case when not has_any_profile then 'approved' else 'pending' end
);
return new;
end;
$$;
drop trigger if exists on_auth_user_created on auth.users;
create trigger on_auth_user_created
after insert on auth.users
for each row execute procedure public.handle_new_user();
-- ฟังก์ชันตรวจสอบสิทธิ์ Admin และสมาชิกที่อนุมัติแล้ว
create or replace function public.is_approved_user()
returns boolean language sql security definer set search_path = public as $$
select exists(select 1 from public.profiles where id = auth.uid() and status = 'approved');
$$;
create or replace function public.is_admin_user()
returns boolean language sql security definer set search_path = public as $$
select exists(select 1 from public.profiles where id = auth.uid() and role = 'admin' and status = 'approved');
$$;
alter table public.profiles enable row level security;
create policy "Users can read own profile or admin reads all"
on public.profiles for select to authenticated
using (id = auth.uid() or public.is_admin_user());
create policy "Admins can update member profiles"
on public.profiles for update to authenticated
using (public.is_admin_user()) with check (public.is_admin_user());
-- 2. ตารางห้องเรียน (classrooms)
create table if not exists public.classrooms (
id uuid primary key default gen_random_uuid(),
name text not null unique,
note text default '',
created_at timestamptz not null default now(),
updated_at timestamptz not null default now()
);
alter table public.classrooms enable row level security;
create policy "Approved users manage classrooms"
on public.classrooms for all to authenticated
using (public.is_approved_user()) with check (public.is_approved_user());
-- 3. ตารางข้อมูลนักเรียน (students) เชื่อมโยงกับห้องเรียน
create table if not exists public.students (
id uuid primary key default gen_random_uuid(),
prefix text not null,
first_name text not null,
last_name text not null,
nickname text default '',
classroom_id uuid references public.classrooms(id) on delete set null,
photo_url text,
photo_path text,
created_at timestamptz not null default now(),
updated_at timestamptz not null default now()
);
alter table public.students add column if not exists classroom_id uuid references public.classrooms(id) on delete set null;
alter table public.students enable row level security;
create policy "Approved users manage students"
on public.students for all to authenticated
using (public.is_approved_user()) with check (public.is_approved_user());
-- 4. Storage Bucket สำหรับเก็บรูปภาพนักเรียน
insert into storage.buckets (id, name, public)
values ('student-photos', 'student-photos', true)
on conflict (id) do nothing;
create policy "Public read access for student photos"
on storage.objects for select to public using (bucket_id = 'student-photos');
create policy "Approved users upload student photos"
on storage.objects for insert to authenticated
with check (bucket_id = 'student-photos' and public.is_approved_user());
create policy "Approved users update student photos"
on storage.objects for update to authenticated
using (bucket_id = 'student-photos' and public.is_approved_user());
create policy "Approved users delete student photos"
on storage.objects for delete to authenticated
using (bucket_id = 'student-photos' and public.is_approved_user());
index.html (สามารถใส่ค่าเริ่มต้น DEFAULT_SUPABASE_URL และ DEFAULT_SUPABASE_ANON_KEY ในโค้ดได้)index.html เพื่อเปิดใช้งานออนไลน์ฟรีพร้อม SSLคำนำหน้า,ชื่อ,นามสกุล,ชื่อเล่น,ห้องเรียน
(หรือภาษาอังกฤษ prefix,first_name,last_name,nickname,classroom)| ลำดับ | คำนำหน้า | ชื่อ | นามสกุล | ชื่อเล่น | ห้องเรียน |
|---|