<?

// Level 6 이하만 사용 가능
$func->checkLevelModal(7);



//////////////////////////////////
// EXPORT - OIL HISTORY
//////////////////////////////////

$oil_cnt = 1;
$oilSTR .= "<tr>";
foreach ($oilhistoryArray AS $key=>$value)
{
	//echo "[$key][$value]";   => [0][Waiting][1][Confirmed][E][Declined]...
	
	if ($oil_cnt%4 == 0) $divideSTR = "</tr><tr>";
	else $divideSTR = "";
	
	if ($key == "c_accountno" || $key == "d_inputdate" || $key == "d_quantity") $disableTAG = "disabled";
	else $disableTAG = "";
	
	$oilSTR .= "
                  <td>
                  <label class=\"container-chk\">".$value."
                    <input type=\"checkbox\" name=\"export_oil[]\" id='oil_".$key."' value=\"".$key."\" checked=\"checked\" $disableTAG>
                    <span class=\"checkmark\"></span>
                  </label>
                  </td>".$divideSTR;
	$oil_cnt++;
}
$oilSTR .= "</tr>";


$todayDate = date("Y-m-d");
$thisMonth = date("Y-m")."-01";

?>


<script type="text/javascript">
$(document).ready(function(){

    $('input[name="columnPreset"]').change(function(){

        let type = $(this).val();

        $('#checkboxoil input:checkbox:not(:disabled)').prop('checked', false);

        if(type == "ACC"){
            presetACC.forEach(col => $('#oil_'+col).prop('checked', true));
        }

        if(type == "MKT"){
            presetMKT.forEach(col => $('#oil_'+col).prop('checked', true));
        }

        if(type == "ALL"){
            $('#checkboxoil input:checkbox:not(:disabled)').prop('checked', true);
        }

        if(type == "CLEAR"){
            $('#checkboxoil input:checkbox:not(:disabled)').prop('checked', false);
        }

    });

    $('#checkboxoil input[type=checkbox]').change(function(){
        $('input[name="columnPreset"]').prop('checked', false);
    });

		$('#oil_period_from, #oil_period_to').datepicker({ 

						dateFormat: 'yy-mm-dd',
										//minDate: "-10D", 
										//maxDate: "+1M",
										//maxDate: "+1M +10D",
			              //showOn: "button",
			              //yearRange: '-50:+5',
			              buttonImage: "/images/cal_red.png",
			              //beforeShowDay: $.datepicker.noWeekends,
			              buttonImageOnly: true,
			              //showOn: "both",
			              changeMonth: true,
			              changeYear: true,
			              firstDay: 7              
		});


		$("#exportoil").submit(function() {
		    $("input").removeAttr("disabled");
		});
});

const presetACC = <?=json_encode(array_keys($oilhistoryArray_acc))?>;
const presetMKT = <?=json_encode(array_keys($oilhistoryArray_mkt))?>;
</script>



  <main id="main" class="main">

    <!-- ======= Breadcrumbs ======= -->
    <div class="breadcrumbs">
      <div class="container">

        <div class="d-flex justify-content-between align-items-center">
          <h2>EXPORT</h2>
          <ol>
            <li><a href="index.html">HOME</a></li>
            <li>CONFIGURATION</li>
            <li>EXPORT</li>
          </ol>
        </div>

      </div>
    </div><!-- End Breadcrumbs -->

		<section class="page">
			
      <div class="container" data-aos="fade-up">

        <div class="h3-title-section"> 
             <br><h3><span style="color:var(--color-primary);">OIL HISTORY</span> Data</h3>
        </div>

				<FORM NAME=exportoil id=exportoil class="form-config-search" METHOD=POST ACTION=/doc/export_process.php >
				<input type=hidden name=mode value="export">
				<input type=hidden name=actionStr value="OILHISTORY">
				
          <table id="checkboxoil" class="td-search checkboxoilclass">
            <tr>
              <td>
                <span class="txt-period" >Period</span>
                <input class="txt-first-period-input" type="text" id="oil_period_from" name="oil_period_from" value="<?=$thisMonth?>" placeholder="2023-04-01" readonly> ~ 
                <input type="text" id="oil_period_to" name="oil_period_to" value="<?=$todayDate?>" placeholder="2023-04-31" readonly>
              </td>
              <td>
                <div class="radio-segment" style="margin:4px;">
                  <label><input type="radio" name="columnPreset" value="ACC"><span>ACC</span></label>
                  <label><input type="radio" name="columnPreset" value="MKT"><span>MKT</span></label>
                  <label><input type="radio" name="columnPreset" value="ALL" checked><span>ALL</span></label>
                  <label><input type="radio" name="columnPreset" value="CLEAR"><span>Clear</span></label>
                </div>
              </td>
              <td>
                <div class="text-center" style="margin:4px;"><button class="btn-sub" type="submit" name="downloadType" value="daily">Daily DOWNLOAD</button></div>
              </td>
              <td>
              	<div class="text-center" style="margin:4px;"><button class="btn-sub" type="submit" name="downloadType" value="calendar">Calendar DOWNLOAD</button></div>
              </td>
            </tr>

<?=$oilSTR?>
          </table>
          

        </FORM>

    </div><!--container Ends-->





        

    </section>

  </main><!-- End #main -->