<?php
session_start();
include "../../inc/config.php";

require_once '../../lib/Writer.php';


       if (isset($_POST['status'])) {


           if ($_POST['status']=='all') {
          $status = '';
        } else {
          $status = "and status_error='".$_POST['status']."'";
        }

        }


        $filter_kelas = "where id is not null $status";




$writer = new XLSXWriter();
$style =
        array (
                      array(
              'border' => array(
                'style' => 'thin',
                'color' => '000000'
                ),
            'allfilleddata' => true
            ),
            array(
                'fill' => array(
                    'color' => 'ff0000'
                    ),
                'cells' => array(
                    'A1',
                    'B1',
                    ),
                'border' => array(
                    'style' => 'thin',
                    'color' => '000000'
                    ),
                'verticalAlign' => 'center',
                'horizontalAlign' => 'center',
            ),
                        array(
                'fill' => array(
                    'color' => '00ff00'
                    ),
                'cells' => array(
                      'C1',
                    ),
                'border' => array(
                    'style' => 'thin',
                    'color' => '000000'
                    ),
                'verticalAlign' => 'center',
                'horizontalAlign' => 'center',
                )
            );

//column width
$col_width = array(
  1 => 16,
  2 => 40,
  3 => 40,
  );
$writer->setColWidth($col_width);

$header = array(
  'Nama Kelas Baru'=>'string',
  'ID Kelas NEO FEEDER'=>'string',
  'Keterangan'=>'string'
);

$no=1;
$index = 2;

$data_rec = array();


    
        $temp_rec = $db->fetch_custom("select * from kelas_kuliah_update $filter_kelas");
                    foreach ($temp_rec as $key) {
        
                if ($key->status_error==0) {
                      $ket = "Belum diproses";
                    } elseif ($key->status_error==1) {
                      $ket = "Sukses";
                    } else {
                      $ket = $key->keterangan;
                    }

                      $data_rec[] = array(
                                      $key->nama_kelas,
                                      $key->id_neo_feeder,
                                      $ket
                        );

             $no++;
             $index++;

            }


$comments = array(
'A1' => 'Nama Kelas Baru, 
info : Wajib disi',
'B1' => 'ID KElas NEO FEEDER
download kelasnya di menu tool, data downloader, download kelas. 
Info : Wajib Diisi'
);
$writer->setComment($comments);


$filename = 'data_kelas_update.xlsx';
header('Content-disposition: attachment; filename="'.XLSXWriter::sanitize_filename($filename).'"');
header("Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
header('Content-Transfer-Encoding: binary');
header('Cache-Control: must-revalidate');
header('Pragma: public');

$writer->writeSheet($data_rec,'Data Kelas Update', $header, $style);
$writer->writeToStdOut();
exit(0);
?>