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

class backup extends MY_Controller{
	function __construct(){
        parent::__construct();
        
        // if($this->data['userid']==''){
        //     redirect($this->data['base_url'] . 'home');   
        //     exit;
        // }
    }
    function index(){
        $this->load->dbutil();
        $prefs = array(
                'format'      => 'txt',             // gzip, zip, txt
                'filename'    => 'mybackup_'.date("d-m-Y").'.sql',    // File name - NEEDED ONLY WITH ZIP FILES
                'add_drop'    => TRUE,              // Whether to add DROP TABLE statements to backup file
                'add_insert'  => TRUE,              // Whether to add INSERT data to backup file
                'newline'     => "\n"               // Newline character used in backup file
              );
        // Backup your entire database and assign it to a variable
        $backup = $this->dbutil->backup($prefs);

        // Load the file helper and write the file to your server
        $this->load->helper('file');
        write_file('backup_software/mybackup_'.date("d-m-Y").'.sql', $backup);

        // // Load the download helper and send the file to your desktop
        // $this->load->helper('download');
        // force_download('mybackup_'.date("d-m-Y").'.sql', $backup);
        
        echo "<script language='javascript' type='text/javascript'>alert('Software Backup Done');</script>";
        echo "<script language='javascript' type='text/javascript'>document.location='".base_url()."/dashbord'; </script>";   
        exit;  
    } 
     
}
