<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Db_backup extends CI_Controller {
	// Session Authoriesed
	public function __construct() {
		parent::__construct();
		
		$this->load->helper('url');
        $this->load->helper('file');
        $this->load->helper('download');
        $this->load->library('zip');
		
		$admin = $this->session->userdata('admin');
		$column['id'] = $admin['id'];
		$table = 'tbl_user';
		
	    // loading common model
	    $this->load->model('Common_model');
		$result = $this->Common_model->Result($column,$table);
		if($result['password'] == $admin['password']){
		    $login = true;
		} else {
		    $login = false;
		}
		
		if (empty($admin) || $login==false) {
			$this->session->set_flashdata('msg','Your Session Has Been Expired');
			redirect(base_url().'master/login/index');
		}
	}

	public function index()
	{
	    $this->load->dbutil();
        $db_format=array('format'=>'zip','filename'=>'db_backup_'.date('Y-m-d H:i:s').'.sql');
        $backup=& $this->dbutil->backup($db_format);
        $dbname='my_db_backup_'.date('Y-m-d H:i:s').'.zip';
        $save='db_backup/'.$dbname;
        write_file($save,$backup);
        force_download($dbname,$backup);
	}
	
}

/* End of file DB_BACKUP.php */
/* Location: ./application/controllers/master/DB_BACKUP.php */