| Server IP : 127.0.0.1 / Your IP : 192.168.99.1 Web Server : Apache/2.4.35 (Win64) OpenSSL/1.1.1b mod_fcgid/2.3.9 System : Windows NT WIN-JEJMB9EN0L0 10.0 build 14393 (Windows Server 2016) AMD64 User : Administrator ( 0) PHP Version : 7.4.33 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : D:/wamp/www/sipapbd_2019/application/modules/maintenance/controllers/ |
Upload File : |
<?php
class Maintenance extends Admin_Controller {
var $maintenance;
var $config_file;
public function __construct()
{
parent::__construct();
$this->modul_name = 'maintenance';
$this->modul_display = 'Maintenance';
$this->view_form = 'maintenance_view';
$this->config_file = APPPATH.'config/appconfig.php';
}
public function index()
{
$this->daftar();
}
public function daftar()
{
$data['breadcrumbs'] = 'Maintenance';
$data['modul'] = $this->modul_name;
$data['last_state'] = isset($this->app_config['maintenance']) ? $this->app_config['maintenance'] : '0';
$data['main_content'] = $this->view_form;
$this->load->view('layout/template_admin', $data);
}
function proses()
{
$response = (object) NULL;
$this->maintenance = $this->input->post('maintenance') == 'true' ? 1 : 0;
$result = $this->save_config();
$response->last_state = $this->app_config['maintenance'];
if ($result){
$response->isSuccess = TRUE;
if ($this->app_config['maintenance'] == $this->maintenance){
$response->message = "Tidak ada perubahan ...";
}
else {
if ($this->maintenance == 1){
$response->message = "Maintenance telah diaktifkan ...";
}
else {
$response->message = "Maintenance telah dihentikan ...";
}
$this->app_config['maintenance'] = $this->maintenance;
}
}
else {
$response->isSuccess = FALSE;
$response->message = "Maintenance gagal di proses ...";
}
$response->new_state = $this->app_config['maintenance'];
echo json_encode($response);
}
private function save_config(){
$config_file = @file_get_contents($this->config_file);
$config = array(
'maintenance' => $this->maintenance
);
foreach($config as $key => $val)
{
$val = '\''.$val.'\'';
$pattern = '%(config\[\''.$key.'\'\] = )(\'?.*\'?)(;)%';
$config_file = preg_replace($pattern, '${1}'.$val. '${3}', $config_file );
}
$ret = @file_put_contents($this->config_file, $config_file);
if ( !$ret)
{
return FALSE;
}
return TRUE;
}
}