<?

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


//////////////////////////////////
// EXPORT - CUSTOMER INFO
//////////////////////////////////

$customer_cnt = 1;
$customerSTR = "<tr>";
foreach ($customerArray AS $key=>$value)
{
	//echo "[$key][$value]";   => [0][Waiting][1][Confirmed][E][Declined]...
	
	if ($customer_cnt%4 == 0) $divideSTR = "</tr><tr>";
	else $divideSTR = "";

	if ($key == "c_accountno" || $key == "d_inputdate" || $key == "d_quantity") $disableTAG = "disabled";
	else $disableTAG = "";
	
	$customerSTR .= "
                  <td>
                  <label class=\"container-chk\">".$value."
                    <input type=\"checkbox\" name=\"export_customer[]\" id='customer_".$key."' value=\"".$key."\" checked=\"checked\" $disableTAG>
                    <span class=\"checkmark\"></span>
                  </label>
                  </td>".$divideSTR;
	$customer_cnt++;
}
$customerSTR .= "</tr>";

?>


<script type="text/javascript">
$(document).ready(function(){
  $('input[name="columnPreset"]').change(function(){

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

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

      if(type == "CS"){
          presetCS.forEach(col => $('#customer_'+col).prop('checked', true));
      }

      if(type == "PL"){
          presetPL.forEach(col => $('#customer_'+col).prop('checked', true));
      }

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

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

  });

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

  $("#checkboxallcustomer").click(function () {
      $('#checkboxcustomer input:checkbox:not(:disabled)').not('this').prop('checked', this.checked);
  });

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

});

const presetCS = <?=json_encode(array_keys($customerArray_cs))?>;
const presetPL = <?=json_encode(array_keys($customerArray_pl))?>;
</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);">CUSTOMER</span> Data</h3>
        </div>

				<FORM NAME=exportcustomer id=exportcustomer class="form-config-search" METHOD=POST ACTION=/doc/export_process.php >
				<input type=hidden name=mode value="export">
				<input type=hidden name=actionStr value="CUSTOMER">
				
            <table id="checkboxcustomer" class="td-search">
              <tr>
                <td>
                  <div class="radio-segment" style="margin:4px;">
                    <label><input type="radio" name="columnPreset" value="CS"><span>CS</span></label>
                    <label><input type="radio" name="columnPreset" value="PL"><span>PL</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">CSV DOWNLOAD</button></div>
                </td>
              </tr>
<?=$customerSTR ?>
            </table>
            
  
          </form>

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

		</section>


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