<?php 
$_SESSION['judul']='TOP UP';
$_SESSION['client']='KOPERASI';
$_SESSION['clientAlamat']='-';
$_SESSION['clientPhone']='-';
$_SESSION['clientKota']='-';

if(isset($_GET['topup']))
{
    
    $koneksi_reg=open_connection2();
	$qry_cari0=mysqli_query($koneksi_reg,"SELECT * FROM `tbregistrasi` WHERE kat ='Teller' ");
	while($row0=mysqli_fetch_array($qry_cari0))
	{
		$koneksi=koneksi_tabungan($row0['npns']);
		$qry1=mysqli_query($koneksi,"SELECT * FROM `tb_rekening_koperasi`  ");
		$ada=mysqli_num_rows($qry1);
		if($ada==0)
		{  

 mysqli_query($koneksi,"INSERT INTO `tb_rekening_koperasi` (`id`, `idanggota`, `keterangan`, `in_out`, `nominal`, `saldo`, `reff`, `reff2`, `reff3`, `iduser`, `tgl`) VALUES ('1', '1101', 'Topup awal', 'in', '50000', '50000', '1', '1', '1', '110', current_timestamp());");  
		    
		}
    }
    
} 

if(isset($_GET['set']))
{
    
    $koneksi_reg=open_connection2();
	$qry_cari0=mysqli_query($koneksi_reg,"SELECT * FROM `tbregistrasi` WHERE kat IN ('Superadmin','Teller') ");
	while($row0=mysqli_fetch_array($qry_cari0))
	{
		$koneksi=koneksi_tabungan($row0['npns']);
		$qry1=mysqli_query($koneksi,"SELECT * FROM `tb_user` WHERE id='".$row0['nis']."' ");
		$ada=mysqli_num_rows($qry1);
		if($ada==0)
		{   $pin='123456';
		    $task="34567fghjkl;FGHJK09865fghjs12345@#$@#$!@#";
		    $pin=md5($pin);
			$pin=md5($pin.$task);
		    
		  mysqli_query($koneksi,"INSERT INTO `tb_user` (`id`, `kategori`, `nama`, `phone`, `email`, `password`, `pin`, `status`, `profile`, `tgl`) VALUES
('".$row0['nis']."', '".$row0['kat']."', '".$row0['nama_siswa']."', '08533', '".$row0['email']."', '".$row0['password']."', '".$pin."', 'OPEN', '', CURRENT_TIMESTAMP());
");  
		    
		}
    }
    
    
}

function koneksi_tabungan($npsn){
$koneksi_reg=open_connection2();
	$qry_cari=mysqli_query($koneksi_reg,"SELECT * FROM `tbregister_andro` WHERE (npsn='".$npsn."') and (kategori='tabungan') ");
				$N=mysqli_num_rows($qry_cari);
				if($N<>0)
					{
					$row=mysqli_fetch_array($qry_cari);
$host="localhost";

$koneksi=@mysqli_connect($host,$row['usercon'],$row['passcon'],$row['dbcon']);
return $koneksi; 
}
}

function open_connection2()
{
$host="localhost";
$username="insansej_user";
$password="xR~^E(@3F;r6";
$koneksi=@mysqli_connect($host,$username,$password,"insansej_cashless_dbregistrasi");
return $koneksi;
}

function koneksi_kantin($npsn){
$koneksi_reg=open_connection2();
	$qry_cari=mysqli_query($koneksi_reg,"SELECT * FROM `tbregister_andro` WHERE (npsn='".$npsn."') and (kategori='pos') ");
				$N=mysqli_num_rows($qry_cari);
				if($N<>0)
					{
					$row=mysqli_fetch_array($qry_cari);
$host="localhost";

$koneksi=@mysqli_connect($host,$row['usercon'],$row['passcon'],$row['dbcon']);
return $koneksi; 
}
}

function noninjection($koneksi,$data){
$filter_sql = addslashes(strip_tags(htmlspecialchars($data,ENT_QUOTES)));
return $filter_sql;
}
?>