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

class Backup extends CI_Controller
{
   
  // backup files in directory
  function files()
  {
     $opt = array(
       'src' => '../www', // dir name to backup
       'dst' => 'backup/files' // dir name backup output destination
     );
     
     // Codeigniter v3x
     $this->load->library('recurseZip_lib', $opt);
     $download = $this->recursezip_lib->compress();
     
     /* Codeigniter v2x
     $zip    = $this->load->library('recurseZip_lib', $opt);     
     $download = $zip->compress();
     */
     
     redirect(base_url($download));
  }
   
  // backup database.sql
  public function db()
  {
      

       $folder_path = "backup"; 
       $files = glob($folder_path.'/*');  

       foreach($files as $file) { 


         if(is_file($file))  


           unlink($file);  


       } 
     $this->load->dbutil();
   
     $prefs = array(
       'format' => 'zip',
       'filename' => 'my_db_backup.sql'
     );
   
     $backup =& $this->dbutil->backup($prefs);
   
     $db_name = 'backup-on-' . date("Y-m-d-H-i-s") . '.zip'; // file name
     $save  = 'backup/' . $db_name; // dir name backup output destination
   
     $this->load->helper('file');
     write_file($save, $backup);
   
     $this->load->helper('download');
     force_download($db_name, $backup);
  }
  public function reset()
  {
              // $del1 = "DELETE from tb_barang  ";
              // $d1 = $this->db->query($del1);

              $del2 = "DELETE from tb_cetak_barcode  ";
              $d2 = $this->db->query($del2);

              $del3 = "DELETE from tb_faktur  ";
              $d3 = $this->db->query($del3);

              $del4 = "DELETE from tb_faktur_detail  ";
              $d4 = $this->db->query($del4);

              $del5 = "DELETE from tb_faktur_detail_keranjang  ";
              $d5= $this->db->query($del5);

              $del6 = "DELETE from tb_history_barang_expired  ";
              $d6 = $this->db->query($del6);

              $del7 = "DELETE from tb_history_barang_in_out  ";
              $d7 = $this->db->query($del7);

              $del7 = "DELETE from tb_history_point_member  ";
              $d7= $this->db->query($del7);

              $del8 = "DELETE from tb_info_expired  ";
              $d8 = $this->db->query($del8);

              $del9 = "DELETE from tb_jual_detail  ";
              $d9 = $this->db->query($del9);

               $del10 = "DELETE from tb_jual_detail_retur  ";
              $d10 = $this->db->query($del10);

               $del11= "DELETE from tb_jual_kasir  ";
              $d11 = $this->db->query($del11);

               $del12 = "DELETE from tb_kasir  ";
              $d12 = $this->db->query($del12);

               $del13 = "DELETE from tb_label  ";
              $d13 = $this->db->query($del13);

               $del14 = "DELETE from tb_log  ";
              $d14 = $this->db->query($del14);


               $del16 = "DELETE from tb_pengeluaran  ";
              $d16 = $this->db->query($del16);

                $del17 = "DELETE from tb_retur_barang  ";
              $d17 = $this->db->query($del17);

                $del18 = "DELETE from tb_stok  ";
              $d18 = $this->db->query($del18);

                $del19 = "DELETE from tb_stok_opname  ";
              $d19 = $this->db->query($del19);

                $del20 = "DELETE from tb_stok_opname_detail  ";
              $d20 = $this->db->query($del20);

                $del21 = "DELETE from tb_stok_opname_detail_keranjang  ";
              $d21 = $this->db->query($del21);

                $del22 = "DELETE from tb_transaksi  ";
              $d22 = $this->db->query($del22);

                $del23 = "DELETE from tb_transaksi_retur  ";
              $d23 = $this->db->query($del23);


              $this->session->set_flashdata('msg','success');


         redirect('transaksi');
      
  }
   
}