
            <!-- Exportable Table -->
             <div class="container-fluid">
            <div class="block-header">
                <h2>
                     <ol class="breadcrumb breadcrumb-bg-teal">
                           <li><a href="index.php?home"><i class="material-icons">home</i> Home</a></li>
                           <li class="active"><i class="material-icons">person</i> Member</li>
                     </ol>
                </h2>
            </div>
<?php 
if(isset($_GET['del'])){
$del=noninjection($koneksi,$_GET['del']);
			$qry_del=mysqli_query($koneksi,"DELETE FROM `tb_anggota` WHERE idanggota='".$del."'");
				$koneksi_host=open_connection2();
			$res=mysqli_query($koneksi_host,"DELETE FROM tbregistrasi  WHERE (nis='".$del."') AND (npns='".$_SESSION['npsn']."')");
			if($qry_del){echo ' <div class="alert bg-green alert-dismissible" role="alert">
                                <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                                <strong>Well done!</strong> Hapus Data Sukses.
                            </div>';
							}else {
							echo '<div class="alert bg-pink alert-dismissible" role="alert">
                                <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                               <strong>Warning!</strong> Hapus Data Gagal.
                            </div>';
							}
}

	if(isset($_POST['token'])){
	$del=noninjection($koneksi,$_POST['token']);
	if($del=='HapusAQu')
	{
	    	$qry_del=mysqli_query($koneksi,"DELETE FROM `tb_anggota` ");
				$koneksi_host=open_connection2();
			$res=mysqli_query($koneksi_host,"DELETE FROM tbregistrasi  WHERE (nis='".$del."') AND (npns='".$_SESSION['npsn']."')");
			if($qry_del){echo ' <div class="alert bg-green alert-dismissible" role="alert">
                                <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                                <strong>Well done!</strong> Hapus Data Sukses.
                            </div>';
							}else {
							echo '<div class="alert bg-pink alert-dismissible" role="alert">
                                <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                               <strong>Warning!</strong> Hapus Data Gagal.
                            </div>';
							}
	
	}
	}
		if(isset($_POST['rfid_idanggota'])){
		    $host="localhost";
$username="insansej_user";
$password="xR~^E(@3F;r6";
$conn=@mysqli_connect($host,$username,$password,"insansej_cashless_dbregistrasi");
$npsn=	$_SESSION['npsn'];
//mysqli_query($conn,"DELETE FROM reg_rfid WHERE npsn='".$npsn."'");
		    
	$rfid_idanggota=noninjection($koneksi,$_POST['rfid_idanggota']);
	$rfid_nama=noninjection($koneksi,$_POST['rfid_nama']);

$r=mysqli_query($conn,"SELECT * FROM `rec` WHERE (npsn='".$npsn."') and (sts='0') order by id desc limit 1");
$row=mysqli_fetch_array($r);
$N=mysqli_num_rows($r);
if($N==1)
{
	$res=mysqli_query($koneksi,"UPDATE tb_anggota SET `rfid_new`='".$row['rfid']."' WHERE idanggota='".$rfid_idanggota."'");
//	$res=mysqli_query($conn,"UPDATE rec SET `sts`='1' WHERE (npsn='".$npsn."')");
	if($res)
	{
	    echo "<script>alert('Registrasi Sukses : ".$row['rfid']." an ".$rfid_nama." ');</script>";
	
	mysqli_query($conn,"DELETE FROM rec WHERE npsn='".$npsn."'");
	}
	
}
		}
	

	if(isset($_POST['submit'])){
			$kategori=noninjection($koneksi,$_POST['kategori']);
			$kategori=ucwords($kategori);
			$idmember=noninjection($koneksi,$_POST['idmember']);
			$nik=noninjection($koneksi,$_POST['nik']);
			$nama=noninjection($koneksi,$_POST['nama']);
			$alamat=noninjection($koneksi,$_POST['alamat']);
			$phone=noninjection($koneksi,$_POST['phone']);
			$status=noninjection($koneksi,$_POST['status']);
			$kelompok=noninjection($koneksi,$_POST['kelompok']);
				$rfid=noninjection($koneksi,$_POST['rfid']);
			$status=strtoupper($status);
			$email=noninjection($koneksi,$_POST['email']);
			$password=noninjection($koneksi,$_POST['password']);
			$password2=noninjection($koneksi,$_POST['password2']);
			
			$pin=noninjection($koneksi,$_POST['pin']);
			$pin2=noninjection($koneksi,$_POST['pin2']);
			$task="34567fghjkl;FGHJK09865fghjs12345@#$@#$!@#";
			
			 	if(!empty($_FILES["file"]["name"])) { 
        // File info 
				$uploadPath = "images/foto/"; 
       			 $fileName = basename($_FILES["file"]["name"]); 
        		$imageUploadPath = $uploadPath . $fileName; 
        		$fileType = pathinfo($imageUploadPath, PATHINFO_EXTENSION); 
         
        // Allow certain file formats 
         		$allowTypes = array('jpg','png','jpeg','JPG','PNG','JPEG'); 
				if(in_array($fileType, $allowTypes)){ 
            // Image temp source and size 
            		$imageTemp = $_FILES["file"]["tmp_name"]; 
            		$imageSize = $_FILES["file"]["size"]; 
             
            // Compress size and upload image 
           
             
				if (move_uploaded_file($_FILES["file"]["tmp_name"], $imageUploadPath)) 
				{ $filex="https://cashless.insansejahtera.my.id/koperasi/".$imageUploadPath;} else {$filex='-';}
			} else {$filex='-';}
			} else {$filex='-';}
		
			
				if(isset($_GET['edit']))
			{
			//edit data
				$koneksi_host=open_connection2();
			if(($idmember<>'') and ($nama<>'') and ($alamat<>'') and ($phone<>'') and ($kategori<>'') and ($status<>'')){
			$res=mysqli_query($koneksi,"UPDATE tb_anggota SET `nik`='".$nik."',`rfid`='".$rfid."', `nama`='".$nama."', `alamat`='".$alamat."', `phone`='".$phone."', `kelompok`='".$kelompok."', `kategori`='".$kategori."',`status`='".$status."', iduser='".$_SESSION['iduser']."' WHERE idanggota='".$idmember."'");
		
				$res=mysqli_query($koneksi_host,"UPDATE tbregistrasi SET nama_siswa='".$nama."',kat='".$kategori."' WHERE (nis='".$idmember."') AND (npns='".$_SESSION['npsn']."')");
					if($filex <>'-'){$res=mysqli_query($koneksi,"UPDATE tb_anggota SET `img`='".$filex."' WHERE idanggota='".$idmember."'"); }
			}
			
			if(($email<>'') and ($password<>'') and ($password2<>'')){
			$password=md5($password);
			$password=md5($password.$email.$task);
			$res=mysqli_query($koneksi,"UPDATE tb_anggota SET `email`='".$email."',`password`='".$password."' WHERE idanggota='".$idmember."'");
				$res=mysqli_query($koneksi_host,"UPDATE tbregistrasi SET `email`='".$email."',`password`='".$password."' WHERE (nis='".$idmember."') AND (npns='".$_SESSION['npsn']."')");
			}
			
			if(($pin<>'') and ($pin2<>'')){
			$pin=md5($pin);
			$pin=md5($pin.$task);
				$res=mysqli_query($koneksi,"UPDATE tb_anggota SET `pin`='".$pin."' WHERE idanggota='".$idmember."'");
			}
			
			if($res){echo ' <div class="alert bg-green alert-dismissible" role="alert">
                                <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                                <strong>Well done!</strong> Edit Data Sukses.
                            </div>';
							}else {
							echo '<div class="alert bg-pink alert-dismissible" role="alert">
                                <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                               <strong>Warning!</strong> Edit Data Gagal.
                            </div>';
							}
			
			} else{
			//tambah data
				$koneksi_host=open_connection2();
			if(($idmember<>'') and ($nama<>'')  and ($alamat<>'') and ($phone<>'') and ($kategori<>'') and ($status<>'') and ($pin<>'') and ($password<>''))
			{
				if($password==$password2)
				{
					if($pin==$pin2)
					{
					$password=md5($password);
					$password=md5($password.$email.$task);
					
					$pin=md5($pin);
					$pin=md5($pin.$task);
					
					$qry_cari=mysqli_query($koneksi,"SELECT * FROM `tb_anggota` WHERE idanggota='".$idmember."'");
					$N=mysqli_num_rows($qry_cari);
					if($N<>0)
					{
					$res=mysqli_query($koneksi,"UPDATE tb_anggota SET `nik`='".$nik."', ,`rfid`='".$rfid."' `nama`='".$nama."', `alamat`='".$alamat."', `phone`='".$phone."', `kategori`='".$kategori."', `kelompok`='".$kelompok."', `email`='".$email."', `password`='".$password."', `pin`='".$pin."', `status`='".$status."',iduser='".$_SESSION['iduser']."' WHERE idanggota='".$idmember."'");
					if($filex<>'-'){$res=mysqli_query($koneksi,"UPDATE tb_anggota SET `img`='".$filex."' WHERE idanggota='".$idmember."'"); }
					$res=mysqli_query($koneksi_host,"UPDATE tbregistrasi SET nama_siswa='".$nama."',kat='".$kategori."',`email`='".$email."',`password`='".$password."' WHERE (nis='".$_SESSION['iduser']."') AND (npns='".$_SESSION['npsn']."')");
			
					}else{
					$res=mysqli_query($koneksi,"INSERT INTO `tb_anggota` (`idanggota`, `nik`, `nama`, `alamat`, `phone`, `kategori`,`kelompok`, `email`, `password`, `pin`,rfid,img, `status`, iduser, `tgl`) VALUES ('".$idmember."', '".$nik."', '".$nama."', '".$alamat."', '".$phone."', '".$kategori."','".$kelompok."', '".$email."', '".$password."', '".$pin."','".$rfid."', '".$filex."', '".$status."', '".$_SESSION['iduser']."', current_timestamp());");
					$res=mysqli_query($koneksi_host,"INSERT INTO `tbregistrasi` ( `kat`, `npns`, `nama_sekolah`, `nisn`, `nama_siswa`, `nis`, `email`, `password`, `tgl`) VALUES
('".$kategori."', '".$_SESSION['npsn']."', '".$_SESSION['sekolah']."', '".$idmember."', '".$nama."', '".$idmember."', '".$email."', '".$password."',  current_timestamp());");
					}
					if($res){echo ' <div class="alert bg-green alert-dismissible" role="alert">
                                <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                                <strong>Well done!</strong> Simpan Data Sukses.
                            </div>';
							}else {
							echo '<div class="alert bg-pink alert-dismissible" role="alert">
                                <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                               <strong>Warning!</strong> Simpan Data Gagal.
                            </div>';
							}
					}else {echo '<div class="alert alert-warning alert-dismissible" role="alert">
                                <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                                 <strong>Warning!</strong> PIN tidak Sama.
                            </div>';} 
				
				}else {echo '<div class="alert alert-warning alert-dismissible" role="alert">
                                <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                                 <strong>Warning!</strong> Password tidak Sama.
                            </div>';}
			} else {echo '<div class="alert bg-pink alert-dismissible" role="alert">
                                <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                               <strong>Warning!</strong> Input Data dengan lengkap.
                            </div>';}
			}}
?>
            <!-- Exportable Table -->
            <div class="row clearfix">
                <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                    <div class="card">
                        <div class="header">
                            <h2>
                                DATA MEMBER
                            </h2>
                            <ul class="header-dropdown m-r--5">
                              
                                    <a href="index.php?anggota&mn=anggota_add" >
										<button type="button" class="btn bg-green btn-circle-lg waves-effect waves-circle waves-float"  data-toggle="tooltip"
                                            data-placement="left" title="Input Data Member">
                                    		<i class="material-icons">add_circle_outline</i> 
                               			</button>
                                    </a>
                                   
								    <a href="index.php?anggota&mn=anggota_upload" >
									<button type="button" class="btn bg-green btn-circle-lg waves-effect waves-circle waves-float" data-toggle="tooltip"
                                            data-placement="left" title="Upload Data Member Template Ms.Excel">
                                    	<i class="material-icons">file_upload</i> 
                                	</button>
                                    </a>
                                
                            </ul>
                        </div>
                       
                        <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#myModal">
   Clear?
  </button>
  
  <div class="modal" id="myModal">
  <div class="modal-dialog">
    <div class="modal-content">

      <!-- Modal Header -->
      <div class="modal-header">
        <h4 class="modal-title">Input Token</h4>
        <button type="button" class="close" data-dismiss="modal">&times;</button>
      </div>
  <form action="index.php?anggota&clear" method="post">  
      <!-- Modal body -->
      <div class="modal-body">
    
	  <input name="token" type="text" />
	 
      </div>

      <!-- Modal footer -->
      <div class="modal-footer">
            <button type="submit" name="submit_clear" class="btn btn-primary" >Clear</button>
        <button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
      </div>
 </form>
    </div>
  </div>
</div>

                       
                        <div class="body">
						
						 
   
						
                            <div class="table-responsive">
                                <table class="table table-bordered table-striped table-hover dataTable js-exportable">
                                    <thead>
                                        <tr>
                                           <th>IDMember</th>
											 <th>NIK</th>
                                            <th>Nama</th>
                                            <th>RFID lama</th>
                                             <th>RFID baru</th>
                                            <th>Phone</th>
                                            <th>Saldo</th>
                                            <th>Kategori</th>
                                            <th>Kelompok</th>
											 <th>Status</th>
											  <th></th>
                                        </tr>
                                    </thead>
                                    <tfoot>
                                        <tr>
                                           <th>IDMember</th>
											 <th>NIK</th>
                                            <th>Nama</th>
                                           <th>RFID lama</th>
                                             <th>RFID baru</th>
                                            <th>Phone</th>
                                            <th>Saldo</th>
                                            <th>Kategori</th>
                                             <th>Kelompok</th>
											 <th>Status</th>
											  <th></th>
                                        </tr>
                                    </tfoot>
                                    <tbody>
									<?php 
								function packi ($from, $to, $mw=null, $mh=null, $quality=null) {
  // (A) CHECKS
  // (A1) SOURCE IMAGE IS READABLE
  if (!is_readable($from)) { exit("Cannot read $from"); }

  // (A2) ALLOWED IMAGE FILE FORMATS
  $extFrom = strtolower(pathinfo($from, PATHINFO_EXTENSION));
  $extTo = strtolower(pathinfo($to, PATHINFO_EXTENSION));
  if (!in_array($extFrom, ["jpeg", "jpg", "gif", "png", "bmp", "webp"])) { exit("$from - Invalid file format"); }
  if (!in_array($extTo, ["jpeg", "jpg", "gif", "png", "webp"])) { exit("$from - Invalid file format"); }

  // (B) OPEN SOURCE IMAGE
  $fn = "imagecreatefrom" . ($extFrom=="jpg" ? "jpeg" : $extFrom);
  $img = $fn($from);

  // (C) RESIZE IMAGE
  if ($mw!=null || $mh!=null) {
    // (C1) SOURCE IMAGE DIMENSIONS
    $sw = imagesx($img);
    $sh = imagesy($img);

    // (C2) RESIZE RATIO
    if ($mw != null && $sw>$mw) { $rw = $mw / $sw; } else { $rw = 1; }
    if ($mh != null && $sh>$mh) { $rh = $mh / $sh; } else { $rh = 1; }

    // (C3) RESIZE USING THE SMALLER RATIO
    if ($rw!=1 || $rh!=1) {
      $rr = $rw<$rh ? $rw : $rh ;
      $img = imagescale($img, floor($rr * $sw), floor($rr * $sh));
    }
  }

  // (D) SAVE & COMPRESS IMAGE
  // jpg : 0 to 100
  // webp : -1 (default), 0 to 100
  // png : -1 (default), 0 (none) to 9
  // gif : na (no compression)
  if ($extTo=="gif") { imagegif($img, $to); }
  else {
    if ($extTo=="jpg" && ($quality==null || !is_numeric($quality) || $quality<0 || $quality>100)) { $quality = 30; }
    if ($extTo=="webp" && ($quality==null || !is_numeric($quality) || $quality<-1 || $quality>100)) { $quality = -1; }
    if ($extTo=="png" && ($quality==null || !is_numeric($quality) || $quality<-1 || $quality>9)) { $quality = -1; }
    $fn = "image" . ($extTo=="jpg" ? "jpeg" : $extTo);
    $fn($img, $to, $quality);
  }
  return true;
}
									$qry_cari=mysqli_query($koneksi,"SELECT * FROM `tb_anggota`  ");
									while($row=mysqli_fetch_array($qry_cari)){
									?>
                                        <tr>
										 <td align="center"><img src="<?php echo $row['img'];?>" width="70px;"><?php echo $row['idanggota'];?></td>
										 
										 <td><?php echo $row['nik'];?></td>
                                            <td><?php echo $row['nama'];?></td>
                                            <td><?php echo $row['rfid'];?></td>
                                             <td><?php echo $row['rfid_new'];?><br><button type="button" class="btn btn-outline-success  btn-sm" data-toggle="modal" data-target="#rfid" onclick="scanrfid(`<?php echo $_SESSION['npsn'];?>`,`<?php echo $row['idanggota'];?>`,`<?php echo $row['nama'];?>`)">Add RFID</button></td>
                                            <td><?php echo $row['phone'];?></td>
                                            <td align="right"><b><?php 
									$qry_rek=mysqli_query($koneksi,"SELECT * FROM `tb_rekening`  WHERE idanggota='".$row['idanggota']."' order by id desc limit 1");
									$row_rek=mysqli_fetch_array($qry_rek);
									if(mysqli_num_rows($qry_rek)<>0){
									echo number_format($row_rek['saldo'],0,",",".");
									} else {echo '0';}
									?> </b>IDR</td>
                                            <td><?php echo $row['kategori'];?></td>
                                             <td><?php echo $row['kelompok'];?></td>
                                            <td><?php echo $row['status'];?></td>
											<td>
								<div align="right">
								    	<a href="idcard.php?id=<?php echo $row['idanggota'];?>">
									<button type="button" class="btn bg-green btn-circle waves-effect waves-circle waves-float" data-toggle="tooltip" data-placement="left" title="Print IDCard">
                                    	<i class="material-icons">print</i>
                                	</button>
									</a>
									
									<a href="index.php?anggota&mn=anggota_edit&edit=<?php echo $row['idanggota'];?>">
									<button type="button" class="btn bg-green btn-circle waves-effect waves-circle waves-float" data-toggle="tooltip" data-placement="left" title="Edit Data">
                                    	<i class="material-icons">create</i>
                                	</button>
									</a>
									
									<a href="index.php?anggota&mn=anggota_view&id=<?php echo $row['idanggota'];?>">
								 	<button  type="button" data-toggle="modal" data-target="#defaultModal"  class="btn bg-light-blue btn-circle waves-effect waves-circle waves-float" data-placement="left" title="View Data">
                                    	<i class="material-icons">search</i>
                                	</button>
									</a>
									
									<a href="index.php?anggota&del=<?php echo $row['idanggota'];?>" onclick="return confirm('Yakin ingin Hapus data ini?');">
								  	<button type="button" class="btn bg-red btn-circle waves-effect waves-circle waves-float" data-toggle="tooltip" data-placement="left" title="Hapus Data">
                                    	<i class="material-icons">delete_sweep</i>
                                	</button>
									</a>
									<div style="font-size:12px; color:#003300;" align="right"><?php echo $row['tgl'];?></div>
								</div>
											</td>
                                        </tr>
                                      <?php }?>
                                    </tbody>
                                </table>
								
								
<div class="modal" id="rfid">
  <div class="modal-dialog">
    <div class="modal-content">

      <!-- Modal Header -->
      <div class="modal-header">
        <h4 class="modal-title">SCAN RFID</h4>
        <button type="button" class="close" data-dismiss="modal">&times;</button>
      </div>
  <form action="index.php?anggota&scan" method="post">  
      <!-- Modal body -->
      <div class="modal-body">
    
	  <input name="rfid_idanggota" type="text" id="rfid_idanggota" class="form-control" required />
	  <br>
	    <input name="rfid_nama" type="text" id="rfid_nama" class="form-control" required />
	    <br>
	  <div style="color:red">Scan RFID dulu dan klik Cek...</div><br>
      </div>

      <!-- Modal footer -->
      <div class="modal-footer">
         
            <button type="submit" name="submit_scan" class="btn btn-primary" >Cek</button>
        <button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
      </div>
 </form>
    </div>
  </div>
</div>					 
								
								
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <!-- #END# Exportable Table -->
<!-- Small Size -->
<script>
function scanrfid(npsn,idanggota,nama)
{
document.getElementById("rfid_idanggota").value = idanggota;
document.getElementById("rfid_nama").value = nama;


$.ajax({
    
            type : "GET",  //type of method
            url  : "https://cashless.insansejahtera.my.id/koperasi/api/rfidsend.php",  //your page
            data : { "npsn" : npsn, "id" : idanggota, "nama" : nama },// passing the values
            success: function(res){  
                                 //do what you want here...
                    }
        });

}
</script>

            