<?php

if (session_status() == PHP_SESSION_NONE) {
  session_start();
}

if (!isset($_SESSION['username_monit']) || !isset($_SESSION['password_monit']) || !isset($_SESSION['tahun']) || !isset($_SESSION['level_monit'])) {
  echo "<script>window.location='../../'</script>";
};


$servroot = $_SERVER['DOCUMENT_ROOT'];
$servweb = $_SERVER['HTTP_HOST'];
$iduser = $_SESSION['id_monit'];
$username = $_SESSION['username_monit'];
$level = $_SESSION['level_monit'];

if (isset($_POST['settahun'])) {
  $direct = new toast();
  echo  $direct->redirect('toast', 'settahun', 'beranda');
  $tahun = $_SESSION['tahun'] = $_POST['settahun'];
  $clsMigrasi = new migrasi;
  $installDB = $clsMigrasi->install($tahun);
} else {
  $tahun = $_SESSION['tahun'];
};

$csrf = new csrf;
$pandu = new pandu;
$format = new format;
$modal = new modal;
//$val = new sxxn;
$cekDB = new database();
$clasSekolah = new sekolah;
$clsWhatsapp = new whatsapp;
$payment = new payment;
$simreport = new simakom_laporan;
$simtran = new simakom_transaksi;
$crud = new crudData();
$time = new time;
$lembaga = new lembaga();
$classTabungan = new tabungan;

//Cek Database
$cekDB = $cekDB->cekDatabase();
$sekolah_id = $clasSekolah->dataSekolah('id');
$whatsapp_id = $clsWhatsapp->data('id');
$payment_id = $payment->data('id');
$simtran->simReport();

//Data USer
$user_name = $crud->getValue('user', "where username='$username'", 'nama');
$user_level = $crud->getValue('user', "where username='$username'", 'level');
$user_id = $crud->getValue('user', "where username='$username'", 'id');

$tahun1 = substr($tahun, 0, 4);
$tahun2 = substr($tahun, 5, 4);
$tahun_tabel = substr($tahun, 2, 2) . substr($tahun, 7, 2);

$tb_siswa = "tb_siswa" . $tahun_tabel;
$tb_transaksi = "db_transaksi" . $tahun_tabel;
$tb_detailakun = "detail_akun" . $tahun_tabel;
$tb_setor = "db_setor" .  $tahun_tabel;
$payment_list = "payment_list" . $tahun_tabel;

//SIMAKOM
$tb_komponen = "simakom_komponen" . $tahun_tabel;
$tb_kegiatan = "simakom_kegiatan" . $tahun_tabel;
$tb_akun = "simakom_akun" . $tahun_tabel;
$tb_detail = "simakom_detail" . $tahun_tabel;
$tb_revisi = "simakom_revisi" . $tahun_tabel;
$tb_transaksi_simakom = "simakom_transaksi" . $tahun_tabel;

//Tabungan
$tabungan_siswa = "tabungan_siswa" .  $tahun_tabel;
$tabungan_transaksi = "tabungan_transaksi" .  $tahun_tabel;

if (file_exists($servroot . "/asset/dokumen/foto/" . $user_id . ".png") || file_exists("../../asset/dokumen/foto/" . $user_id . ".png")) {
  $user_foto = "<img src='../../asset/dokumen/foto/" . $user_id . ".png' width='45' height='45' class='img-circle user-image'/>";
} elseif (file_exists($servroot . "/asset/dokumen/foto/" . $user_id . ".jpg") || file_exists("../../asset/dokumen/foto/" . $user_id . ".jpg")) {
  $user_foto = "<img src='../../asset/dokumen/foto/" . $user_id . ".jpg' width='45' height='45' class='img-circle user-image'/>";
} elseif (file_exists($servroot . "/asset/dokumen/foto/" . $user_id . ".gif") || file_exists("../../asset/dokumen/foto/" . $user_id . ".gif")) {
  $user_foto = "<img src='../../asset/dokumen/foto/" . $user_id . ".gif' width='45' height='45' class='img-circle user-image'/>";
} else {
  $user_foto = "<img src='../../asset/dokumen/foto/no_photo.png' width='45' height='45' class='img-circle user-image'/>";
};
