<?php

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

class Maintenance extends MY_Controller {

    function __construct() {
        parent::__construct();
    }

    function index() {

        $this->load->view('settings/header');
        $this->load->view('settings/maintenance_view', null);
        $this->load->view('settings/footer');
    }

    // ONLINE BACKUP
    public function partialbackup() {
      $this->load->dbutil();

        $result = $this->dbutil->optimize_database();

if ($result !== FALSE)
{
       // Load the DB utility class

 $this->load->model('settings/appsettings_model');
                $TABLES =$this->appsettings_model->getappsettings('backuptables');
                var_dump($TABLES);
$prefs = array(
                'tables'      => array('CATEGORIES','PRODUCTS','PEOPLE'),  // Array of tables to backup.
                'ignore'      => array(),           // List of tables to omit from the backup
                'format'      => 'zip',             // gzip, zip, txt
                'filename'    => 'Saleculator.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('C:\Users\Hussain\Desktop\Saleculator.gz', $backup);

// Load the download helper and send the file to your desktop
//$data['printdate'] = date('d-m-Y');
$date=date('d-m-Y');
$this->load->helper('download');
force_download('Saleculator(Partial)-' .$date .'.gz', $backup);
}
   
    }

     public function completebackup() {
      $this->load->dbutil();

        $result = $this->dbutil->optimize_database();

if ($result !== FALSE)
{
       // Load the DB utility class



$prefs = array(
                'database'      => array('SALECULATOR'),  // Array of tables to backup.
                'ignore'      => array(),           // List of tables to omit from the backup
                'format'      => 'zip',             // gzip, zip, txt
                'filename'    => 'Saleculator.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('C:\Users\Hussain\Desktop\Saleculator.gz', $backup);

// Load the download helper and send the file to your desktop
$date=date('d-m-Y');
$this->load->helper('download');
force_download('Saleculator(Complete)-' .$date .'.gz', $backup);
}

    }

}