Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add : General Settings School #125

Merged
merged 15 commits into from
Jul 27, 2024
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,10 @@ phpunit
vendor/

# uploads
public/uploads
public/uploads/*
!public/uploads/index.html
!public/uploads/logo/index.html
!public/uploads/tmp/index.html

#-------------------------
# IDE / Development Files
Expand Down
248 changes: 248 additions & 0 deletions app/Common.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,251 @@
*
* @see: https://codeigniter4.github.io/CodeIgniter4/
*/


//clean string
if (!function_exists('cleanStr')) {
function cleanStr($str)
{
$str = strTrim($str);
$str = removeSpecialCharacters($str);
return esc($str);
}
}

//clean number
if (!function_exists('cleanNumber')) {
function cleanNumber($num)
{
$num = strTrim($num);
$num = esc($num);
if (empty($num)) {
return 0;
}
return intval($num);
}
}

//clean number
if (!function_exists('clrQuotes')) {
function clrQuotes($str)
{
$str = strReplace('"', '', $str);
$str = strReplace("'", '', $str);
return $str;
}
}

/**
* Get validation rules
*
* @return Rules
*/
if (!function_exists('getValRules')) {
function getValRules($val)
{
$rules = $val->getRules();
$newRules = array();
if (!empty($rules)) {
foreach ($rules as $key => $rule) {
$newRules[$key] = [
'label' => $rule['label'],
'rules' => $rule['rules'],
'errors' => [
'required' => lang("Validation.form_validation_required"),
'min_length' => lang("Validation.form_validation_min_length"),
'max_length' => lang("Validation.form_validation_max_length"),
'matches' => lang("Validation.form_validation_matches"),
'is_unique' => lang("Validation.form_validation_is_unique")
]
];
}
}
return $newRules;
}
}

/**
* STR TRIM
*
* TRIM string
*
* @return string
*/
if (!function_exists('strTrim')) {
function strTrim($str)
{
if (!empty($str)) {
return trim($str);
}
}
}

/**
* STR Replace
*
* Replace string
*
* @return string
*/
if (!function_exists('strReplace')) {
function strReplace($search, $replace, $str)
{
if (!empty($str)) {
return str_replace($search, $replace, $str);
}
}
}

/**
* POST Request
*
* Sanitaze Input Post
*
* @return string
*/
if (!function_exists('inputPost')) {
function inputPost($input_name, $removeForbidden = false)
{
$input = \Config\Services::request()->getPost($input_name);
if (!is_array($input)) {
$input = strTrim($input);
}
if ($removeForbidden) {
$input = removeForbiddenCharacters($input);
}
return $input;
}
}

/**
* GET Request
*
* Sanitaze Input GET
*
* @return string
*/
if (!function_exists('inputGet')) {
function inputGet($input_name, $removeForbidden = false)
{
$input = \Config\Services::request()->getGet($input_name);
if (!is_array($input)) {
$input = strTrim($input);
}
if ($removeForbidden) {
$input = removeForbiddenCharacters($input);
}
return $input;
}
}

/**
* remove forbidden characters
*
*
* @return string
*/
if (!function_exists('removeForbiddenCharacters')) {
function removeForbiddenCharacters($str)
{
$str = strTrim($str);
$str = strReplace(';', '', $str);
$str = strReplace('"', '', $str);
$str = strReplace('$', '', $str);
$str = strReplace('%', '', $str);
$str = strReplace('*', '', $str);
$str = strReplace('/', '', $str);
$str = strReplace('\'', '', $str);
$str = strReplace('<', '', $str);
$str = strReplace('>', '', $str);
$str = strReplace('=', '', $str);
$str = strReplace('?', '', $str);
$str = strReplace('[', '', $str);
$str = strReplace(']', '', $str);
$str = strReplace('\\', '', $str);
$str = strReplace('^', '', $str);
$str = strReplace('`', '', $str);
$str = strReplace('{', '', $str);
$str = strReplace('}', '', $str);
$str = strReplace('|', '', $str);
$str = strReplace('~', '', $str);
$str = strReplace('+', '', $str);
return $str;
}
}

/**
* remove special characters
*
*
* @return string
*/
if (!function_exists('removeSpecialCharacters')) {
function removeSpecialCharacters($str, $removeQuotes = false)
{
$str = removeForbiddenCharacters($str);
$str = strReplace('#', '', $str);
$str = strReplace('!', '', $str);
$str = strReplace('(', '', $str);
$str = strReplace(')', '', $str);
if ($removeQuotes) {
$str = clrQuotes($str);
}
return $str;
}
}

/**
* Get Logo
*
* @return string
*/
if (!function_exists('getLogo')) {
function getLogo()
{
$schoolConfigurations = new \Config\School();
$generalSettings = $schoolConfigurations::$generalSettings;
if (!empty($generalSettings)) {
if (!empty($generalSettings->logo) && file_exists(FCPATH . $generalSettings->logo)) {
return base_url($generalSettings->logo);
}
return base_url("assets/img/logo_sekolah.jpg");
}
return base_url("assets/img/logo_sekolah.jpg");
}
}

/**
* Invalid Feedback
*
* @return
*/
if (!function_exists('invalidFeedback')) {
function invalidFeedback($input)
{
$session = session();
if ($session->getFlashdata('errors')) {
$errors = $session->getFlashdata('errors');
if (!empty($errors[$input])) {
return esc($errors[$input]);
}

return null;
}

return null;
}
}

//generate unique id
if (!function_exists('generateToken')) {
function generateToken($short = false)
{
$token = uniqid('', true);
$token = strReplace('.', '-', $token);
if ($short == false) {
$token = $token . '-' . rand(10000000, 99999999);
}
return $token;
}
}
4 changes: 3 additions & 1 deletion app/Config/Autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ class Autoload extends AutoloadConfig
*
* @var array<string, string>
*/
public $classmap = [];
public $classmap = [
'School' => APPPATH . 'Config/School.php'
];

/**
* -------------------------------------------------------------------
Expand Down
6 changes: 6 additions & 0 deletions app/Config/Routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,12 @@
$routes->post('petugas/edit', 'Admin\DataPetugas::updatePetugas');
// superadmin hapus data petugas
$routes->delete('petugas/delete/(:any)', 'Admin\DataPetugas::delete/$1');

// Settings
$routes->group('general-settings', ['namespace' => 'App\Controllers\Admin'], function ($routes) {
$routes->get('/', 'GeneralSettings::index');
$routes->post('update', 'GeneralSettings::generalSettingsPost');
});
});


Expand Down
26 changes: 26 additions & 0 deletions app/Config/School.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

/* Don't change or add any new config in this file */

namespace Config;

use CodeIgniter\Config\BaseConfig;

class School extends BaseConfig
{
private $db;

public static $generalSettings;

public function __construct()
{
$this->db = \Config\Database::connect();
$this->setGlobalConfigurations();
}

private function setGlobalConfigurations()
{
// Get General Settings
self::$generalSettings = $this->db->table('general_settings')->where('id', 1)->get()->getRow();
}
}
45 changes: 45 additions & 0 deletions app/Controllers/Admin/GeneralSettings.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

namespace App\Controllers\Admin;

use App\Controllers\BaseController;
use App\Models\GeneralSettingsModel;

class GeneralSettings extends BaseController
{
protected $generalSettingsModel;

public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger)
{
parent::initController($request, $response, $logger);
$this->generalSettingsModel = new GeneralSettingsModel();
}

public function index()
{
$data['title'] = 'Pengaturan Utama';
$data['ctx'] = 'general_settings';

return view('admin/general-settings/index', $data);
}

public function generalSettingsPost()
{
$val = \Config\Services::validation();
$val->setRule('school_name', 'Nama Sekolah', 'required|max_length[200]');
$val->setRule('school_year', 'Tahun Ajaran', 'required|max_length[200]');
$val->setRule('copyright', 'copyright', 'max_length[200]');

if (!$this->validate(getValRules($val))) {
$this->session->setFlashdata('errors', $val->getErrors());
return redirect()->to('admin/general-settings')->withInput();
} else {
if ($this->generalSettingsModel->updateSettings()) {
$this->session->setFlashdata('success', 'Data berhasil diubah');
} else {
$this->session->setFlashdata('error', 'Error data!');
}
}
return redirect()->to('admin/general-settings');
}
}
10 changes: 0 additions & 10 deletions app/Controllers/Admin/GenerateLaporan.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ class GenerateLaporan extends BaseController
protected PresensiSiswaModel $presensiSiswaModel;
protected PresensiGuruModel $presensiGuruModel;

protected string $namaSekolah;
protected string $tahunAjaran;

public function __construct()
{
$this->siswaModel = new SiswaModel();
Expand All @@ -37,9 +34,6 @@ public function __construct()

$this->presensiSiswaModel = new PresensiSiswaModel();
$this->presensiGuruModel = new PresensiGuruModel();

$this->namaSekolah = ConfigAbsensiSekolah::SCHOOL_NAME;
$this->tahunAjaran = ConfigAbsensiSekolah::SCHOOL_YEAR;
}

public function index()
Expand Down Expand Up @@ -130,8 +124,6 @@ public function generateLaporanSiswa()
],
'kelas' => $kelas,
'grup' => "kelas " . $kelas['kelas'] . " " . $kelas['jurusan'],
'namaSekolah' => $this->namaSekolah,
'tahunAjaran' => $this->tahunAjaran
];

if ($type == 'doc') {
Expand Down Expand Up @@ -207,8 +199,6 @@ public function generateLaporanGuru()
'perempuan' => count($guru) - $laki
],
'grup' => 'guru',
'namaSekolah' => $this->namaSekolah,
'tahunAjaran' => $this->tahunAjaran
];

if ($type == 'doc') {
Expand Down
Loading