<?php
date_default_timezone_set('Asia/Jakarta'); 
defined('BASEPATH') OR exit('No direct script access allowed');
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;

class Jadwal extends CI_Controller {

	public function index()
	{
        $this->load->view('jadwal/jadwal');


//         $curl = curl_init();

//         curl_setopt_array($curl, array(
//             CURLOPT_URL => '103.255.241.124:1111/api/d_reg_online/tampil_jadwal_operasi',
//             CURLOPT_RETURNTRANSFER => true,
//             CURLOPT_ENCODING => '', 
//             CURLOPT_MAXREDIRS => 10,
//             CURLOPT_TIMEOUT => 0,
//             CURLOPT_FOLLOWLOCATION => true,
//             CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
//             CURLOPT_CUSTOMREQUEST => 'POST',

//           ));

// $response = curl_exec($curl);

// curl_close($curl);
//         $json =  str_replace('\r\n     ', "---0", $response);
// 		$json =  str_replace('\r\n', "---", $json);
// 		$json = json_decode($json);
//         $data["fitur"]				    = $json;
//         $this->load->view('jadwal/header', $data);
// 		$this->load->view('jadwal/jadwal', $data);
//         $this->load->view('jadwal/footer', $data);
	}

 public function jadwal()
    {
        $this->load->view('jadwal/jadwal1');
        // $curl = curl_init();

    //     curl_setopt_array($curl, array(
    //         CURLOPT_URL => '103.255.241.124:1111/api/d_reg_online/tampil_jadwal_operasi',
    //         CURLOPT_RETURNTRANSFER => true,
    //         CURLOPT_ENCODING => '', 
    //         CURLOPT_MAXREDIRS => 10,
    //         CURLOPT_TIMEOUT => 0,
    //         CURLOPT_FOLLOWLOCATION => true,
    //         CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
    //         CURLOPT_CUSTOMREQUEST => 'POST',

    //       ));

    //     $response = curl_exec($curl);

    //     curl_close($curl);

    //     $json =  str_replace('\r\n     ', "---0", $response);
    //     $json =  str_replace('\r\n', "---", $json);
    //     $json = json_decode($json);

    //     $data["title"]                    = "Data Jadwal IKBS";
    //     $data["fitur"]                = $json;


    //     $mobil = $json;
    //     $spreadsheet = new Spreadsheet();
    //     // tulis header/nama kolom 
    //     $spreadsheet->setActiveSheetIndex(0)
    //         ->setCellValue('A1', 'Nomor Operasi')
    //         ->setCellValue('B1', 'Tanggal')
    //         ->setCellValue('C1', 'Kode Rekam Medis')
    //         ->setCellValue('D1', 'Nama Pasien')
    //         ->setCellValue('E1', 'Dokter Operasi')
    //         ->setCellValue('F1', 'Nama Tindakan')
    //         ->setCellValue('G1', 'Ruang')
    //         ->setCellValue('H1', 'Keterangan')
    //         ->setCellValue('I1', 'Catatan')
    //         ->setCellValue('J1', 'Jam Mulai')
    //         ->setCellValue('K1', 'Jam Selesai');

    //     $column = 2;
    //     $tglsekarang= date("Y-m-d");
    //     // tulis data mobil ke cell
    //     foreach ($mobil->response as $row) {
    //         if($row->tgl_op>=$tglsekarang){
    //         $spreadsheet->setActiveSheetIndex(0)
    //             ->setCellValue('A' . $column, $row->no_index_op )
    //             ->setCellValue('B' . $column, $row->tgl_op)
    //             ->setCellValue('C' . $column, $row->kd_rekam_medis)
    //             ->setCellValue('D' . $column, $row->nm_pasien)
    //             ->setCellValue('E' . $column, $row->dokter_op)
    //             ->setCellValue('F' . $column, $row->nm_tindakan)
    //             ->setCellValue('G' . $column, $row->nm_ruang_op)
    //             ->setCellValue('H' . $column, $row->keterangan)
    //             ->setCellValue('I' . $column, $row->catatan)
    //             ->setCellValue('J' . $column, $row->jam_mulai)
    //             ->setCellValue('K' . $column, $row->jam_selesai);
    //         $column++;
    //         }
    //     }
    //     // tulis dalam format .xlsx
    //     $writer = new Xlsx($spreadsheet);
    //     $fileName = 'Data Jadwal IKBS';

    //     // Redirect hasil generate xlsx ke web client
    //     header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
    //     header('Content-Disposition: attachment;filename=' . $fileName . '.xlsx');
    //     header('Cache-Control: max-age=0');

    //     $writer->save('php://output');
     }

     public function jadwal1() {
      $this->load->view('jadwal/jadwal2');
     }
      public function jadwal2() {
      $this->load->view('jadwal/jadwal3');
     }
 
 
 
}
