<?php 

include "../config.php";
include "../fungsi.php";    

 if(isset($_POST["export"]))  { 
      $idgrup = $_POST["idgrup"];
      $data=mysqli_fetch_row(mysqli_query($con,"select * from grup where id=$idgrup"));
      header('Content-Type: text/csv; charset=utf-8'); 
      header('Content-Disposition: attachment; filename='.$data[1].'.csv'); 
      $output = fopen("php://output", "w"); 
      
      if(isset($_POST["c1"]) && isset($_POST["c2"]))  { 
          fputcsv($output, array('Nama', 'Email', 'HP', 'Tgl.Gabung', 'IP')); 
          $query = "select prospek.nama,prospek.email,prospek.hp,gtm.tgl_gabung,prospek.ip from gtm, prospek where gtm.id_member=prospek.ID and gtm.id_grup ='$idgrup' order by prospek.ID desc"; 
      }else{
          fputcsv($output, array('Nama', 'Email', 'HP')); 
          $query = "select prospek.nama,prospek.email,prospek.hp from gtm, prospek where gtm.id_member=prospek.ID and gtm.id_grup ='$idgrup' order by prospek.ID desc"; 
      }
      $result = mysqli_query($con, $query); 
      while($row = mysqli_fetch_assoc($result)) 
      { 
           fputcsv($output, $row); 
      } 
      fclose($output); 
 } 

 ?> 