<?php
include("config/connection.php");
include("config/session.php");

$jumlahtiket = $_POST['jumlahtiket'];
$id_operator = $_SESSION['id'];
$id_jadwal = $_POST['id_jadwal'];
$nama = $_POST['nama'];
$nama = str_replace("'", "", $nama);
$no_identitas = $_POST['no_identitas'];

$nama1 = $_POST['nama1'];
$nama1 = $nama1/27300;

$nama2 = $_POST['nama2'];
$nama2 = $nama2/22300;

$nama3 = $_POST['nama3'];
$nama3 = $nama3/13650;

$nama4 = $_POST['nama4'];
$nama4 = $nama4/39000;

$nama5 = $_POST['nama5'];
$nama5 = $nama5/46500;

$nama6 = $_POST['nama6'];
$nama6 = $nama6/277800;

$nama7 = $_POST['nama7'];
$nama7 = $nama7/200200;

$nama8 = $_POST['nama8'];
$nama8 = $nama8/468200;

$nama9 = $_POST['nama9'];
$nama9 = $nama9/355300;

$nama10 = $_POST['nama10'];
$nama10 = $nama10/805200;

$nama11 = $_POST['nama11'];
$nama11 = $nama11/580000;

$nama12 = $_POST['nama12'];
$nama12 = $nama12/927750;

$nama13 = $_POST['nama13'];
$nama13 = $nama13/1688900;

		
				include("config/connection.php");
				$sqlmaster = "select id_master from tb_tiket group by id_master desc";
				$querymaster =mysql_query($sqlmaster);
				$rowmaster = mysql_fetch_row($querymaster);
				$jumlahmaster = $rowmaster[0];

				$idmaster = $jumlahmaster + 1;		
		
		if($nama1 > 0){
			//BUAT NO TIKET
			for ($i = 1; $i <= $nama1; $i++) {
				include("config/connection.php");
				$tgl = date("Y-m-d");
				$sql1 = "select count(id) from tb_tiket where date(tanggal) = '".$tgl."'";
				$query1 =mysql_query($sql1);
				$row = mysql_fetch_row($query1);
				$jumlah = $row[0];
				$bk=$jumlah + 1;
				$dp = date("dmy");
				$notiket = $dp.$bk;
				$namact = '';
				
				if($nama1 > 1){
					$namact = $nama." Dewasa -".$i;
				}else{
					$namact = $nama;
				}
			
			//SIMPAN DATA
			include("config/connection.php");
				
				$sql="insert into tb_tiket (id_jadwal, id_angkutan, harga, nama, no_identitas, tanggal, no_tiket, id_operator, id_master) values ('".$id_jadwal."', '1', '27300', '".$namact."', '".$no_identitas."', now(), '".$notiket."', '".$id_operator."', '".$idmaster."')";
				if (!mysql_query($sql,$test)){
				die('Error: ' . mysql_error());
				}
				
			include("config/connection.php");
				
				$sql="update tb_jadwal set Sisa = Sisa -1 where Id_Jadwal = '".$id_jadwal."'";
				if (!mysql_query($sql,$test)){
				die('Error: ' . mysql_error());
				}
			?>
			<?php	
			
			}
		}



		if($nama2 > 0){
			//BUAT NO TIKET
			for ($i = 1; $i <= $nama2; $i++) {
				include("config/connection.php");
				$tgl = date("Y-m-d");
				$sql1 = "select count(id) from tb_tiket where date(tanggal) = '".$tgl."'";
				$query1 =mysql_query($sql1);
				$row = mysql_fetch_row($query1);
				$jumlah = $row[0];
				$bk=$jumlah + 1;
				$dp = date("dmy");
				$notiket = $dp.$bk;
				$namact = '';
				
				if($nama2 > 1){
					$namact = $nama." ANAK-ANAK -".$i;
				}else{
					$namact = $nama." ANAK-ANAK";
				}
			
			//SIMPAN DATA
			include("config/connection.php");
				
				$sql="insert into tb_tiket (id_jadwal, id_angkutan, harga, nama, no_identitas, tanggal, no_tiket, id_operator, id_master) values ('".$id_jadwal."', '2', '22300', '".$namact."', '".$no_identitas."', now(), '".$notiket."', '".$id_operator."', '".$idmaster."')";
				if (!mysql_query($sql,$test)){
				die('Error: ' . mysql_error());
				}
				
			include("config/connection.php");
				
				$sql="update tb_jadwal set Sisa = Sisa -1 where Id_Jadwal = '".$id_jadwal."'";
				if (!mysql_query($sql,$test)){
				die('Error: ' . mysql_error());
				}
			?>
			<?php	
			
			}
		}



		if($nama3 > 0){
			//BUAT NO TIKET
			for ($i = 1; $i <= $nama3; $i++) {
				include("config/connection.php");
				$tgl = date("Y-m-d");
				$sql1 = "select count(id) from tb_tiket where date(tanggal) = '".$tgl."'";
				$query1 =mysql_query($sql1);
				$row = mysql_fetch_row($query1);
				$jumlah = $row[0];
				$bk=$jumlah + 1;
				$dp = date("dmy");
				$notiket = $dp.$bk;
				$namact = '';
				
				if($nama3 > 1){
					$namact = $nama." Golongan I -".$i;
				}else{
					$namact = $nama." Golongan I";
				}
			
			//SIMPAN DATA
			include("config/connection.php");
				
				$sql="insert into tb_tiket (id_jadwal, id_angkutan, harga, nama, no_identitas, tanggal, no_tiket, id_operator, id_master) values ('".$id_jadwal."', '3', '13650', '".$namact."', '".$no_identitas."', now(), '".$notiket."', '".$id_operator."', '".$idmaster."')";
				if (!mysql_query($sql,$test)){
				die('Error: ' . mysql_error());
				}
				
			include("config/connection.php");
				
				$sql="update tb_jadwal set Sisa = Sisa -1 where Id_Jadwal = '".$id_jadwal."'";
				if (!mysql_query($sql,$test)){
				die('Error: ' . mysql_error());
				}
			?>
			<?php	
			
			}
		}



		if($nama4 > 0){
			//BUAT NO TIKET
			for ($i = 1; $i <= $nama4; $i++) {
				include("config/connection.php");
				$tgl = date("Y-m-d");
				$sql1 = "select count(id) from tb_tiket where date(tanggal) = '".$tgl."'";
				$query1 =mysql_query($sql1);
				$row = mysql_fetch_row($query1);
				$jumlah = $row[0];
				$bk=$jumlah + 1;
				$dp = date("dmy");
				$notiket = $dp.$bk;
				$namact = '';
				
				if($nama4 > 1){
					$namact = $nama." Golongan II -".$i;
				}else{
					$namact = $nama." Golongan II";
				}
			
			//SIMPAN DATA
			include("config/connection.php");


				
				$sql="insert into tb_tiket (id_jadwal, id_angkutan, harga, nama, no_identitas, tanggal, no_tiket, id_operator, id_master) values ('".$id_jadwal."', '4', '39000', '".$namact."', '".$no_identitas."', now(), '".$notiket."', '".$id_operator."', '".$idmaster."')";
				if (!mysql_query($sql,$test)){
				die('Error: ' . mysql_error());
				}
				
			include("config/connection.php");
				
				$sql="update tb_jadwal set Sisa = Sisa -1 where Id_Jadwal = '".$id_jadwal."'";
				if (!mysql_query($sql,$test)){
				die('Error: ' . mysql_error());
				}
			?>
			<?php	
			
			}
		}



		if($nama5 > 0){
			//BUAT NO TIKET
			for ($i = 1; $i <= $nama5; $i++) {
				include("config/connection.php");
				$tgl = date("Y-m-d");
				$sql1 = "select count(id) from tb_tiket where date(tanggal) = '".$tgl."'";
				$query1 =mysql_query($sql1);
				$row = mysql_fetch_row($query1);
				$jumlah = $row[0];
				$bk=$jumlah + 1;
				$dp = date("dmy");
				$notiket = $dp.$bk;
				$namact = '';
				
				if($nama5 > 1){
					$namact = $nama." Golongan III -".$i;
				}else{
					$namact = $nama." Golongan III";
				}
			
			//SIMPAN DATA
			include("config/connection.php");
				
				$sql="insert into tb_tiket (id_jadwal, id_angkutan, harga, nama, no_identitas, tanggal, no_tiket, id_operator, id_master) values ('".$id_jadwal."', '5', '46500', '".$namact."', '".$no_identitas."', now(), '".$notiket."', '".$id_operator."', '".$idmaster."')";
				if (!mysql_query($sql,$test)){
				die('Error: ' . mysql_error());
				}
				
			include("config/connection.php");
				
				$sql="update tb_jadwal set Sisa = Sisa -1 where Id_Jadwal = '".$id_jadwal."'";
				if (!mysql_query($sql,$test)){
				die('Error: ' . mysql_error());
				}
			?>
			<?php	
			
			}
		}



		if($nama6 > 0){
			//BUAT NO TIKET
			for ($i = 1; $i <= $nama6; $i++) {
				include("config/connection.php");
				$tgl = date("Y-m-d");
				$sql1 = "select count(id) from tb_tiket where date(tanggal) = '".$tgl."'";
				$query1 =mysql_query($sql1);
				$row = mysql_fetch_row($query1);
				$jumlah = $row[0];
				$bk=$jumlah + 1;
				$dp = date("dmy");
				$notiket = $dp.$bk;
				$namact = '';
				
				if($nama6 > 1){
					$namact = $nama." Golongan IV A -".$i;
				}else{
					$namact = $nama." Golongan IV A";
				}
			
			//SIMPAN DATA
			include("config/connection.php");
				
				$sql="insert into tb_tiket (id_jadwal, id_angkutan, harga, nama, no_identitas, tanggal, no_tiket, id_operator, id_master) values ('".$id_jadwal."', '6', '277800', '".$namact."', '".$no_identitas."', now(), '".$notiket."', '".$id_operator."', '".$idmaster."')";
				if (!mysql_query($sql,$test)){
				die('Error: ' . mysql_error());
				}
				
			include("config/connection.php");
				
				$sql="update tb_jadwal set Sisa = Sisa -1 where Id_Jadwal = '".$id_jadwal."'";
				if (!mysql_query($sql,$test)){
				die('Error: ' . mysql_error());
				}
			?>
			<?php	
			
			}
		}




		if($nama7 > 0){
			//BUAT NO TIKET
			for ($i = 1; $i <= $nama7; $i++) {
				include("config/connection.php");
				$tgl = date("Y-m-d");
				$sql1 = "select count(id) from tb_tiket where date(tanggal) = '".$tgl."'";
				$query1 =mysql_query($sql1);
				$row = mysql_fetch_row($query1);
				$jumlah = $row[0];
				$bk=$jumlah + 1;
				$dp = date("dmy");
				$notiket = $dp.$bk;
				$namact = '';
				
				if($nama7 > 1){
					$namact = $nama." Golongan IV B -".$i;
				}else{
					$namact = $nama." Golongan IV B";
				}
			
			//SIMPAN DATA
			include("config/connection.php");
				
				$sql="insert into tb_tiket (id_jadwal, id_angkutan, harga, nama, no_identitas, tanggal, no_tiket, id_operator, id_master) values ('".$id_jadwal."', '7', '200200', '".$namact."', '".$no_identitas."', now(), '".$notiket."', '".$id_operator."', '".$idmaster."')";
				if (!mysql_query($sql,$test)){
				die('Error: ' . mysql_error());
				}
				
			include("config/connection.php");
				
				$sql="update tb_jadwal set Sisa = Sisa -1 where Id_Jadwal = '".$id_jadwal."'";
				if (!mysql_query($sql,$test)){
				die('Error: ' . mysql_error());
				}
			?>
			<?php	

			
			}
		}



		if($nama8 > 0){
			//BUAT NO TIKET
			for ($i = 1; $i <= $nama8; $i++) {
				include("config/connection.php");
				$tgl = date("Y-m-d");
				$sql1 = "select count(id) from tb_tiket where date(tanggal) = '".$tgl."'";
				$query1 =mysql_query($sql1);
				$row = mysql_fetch_row($query1);
				$jumlah = $row[0];
				$bk=$jumlah + 1;
				$dp = date("dmy");
				$notiket = $dp.$bk;
				$namact = '';
				
				if($nama8 > 1){
					$namact = $nama." Golongan V A -".$i;
				}else{
					$namact = $nama." Golongan V A";
				}
			
			//SIMPAN DATA
			include("config/connection.php");
				
				$sql="insert into tb_tiket (id_jadwal, id_angkutan, harga, nama, no_identitas, tanggal, no_tiket, id_operator, id_master) values ('".$id_jadwal."', '8', '468200', '".$namact."', '".$no_identitas."', now(), '".$notiket."', '".$id_operator."', '".$idmaster."')";
				if (!mysql_query($sql,$test)){
				die('Error: ' . mysql_error());
				}
				
			include("config/connection.php");
				
				$sql="update tb_jadwal set Sisa = Sisa -1 where Id_Jadwal = '".$id_jadwal."'";
				if (!mysql_query($sql,$test)){
				die('Error: ' . mysql_error());
				}
			?>
			<?php	
			
			}
		}



		if($nama9 > 0){
			//BUAT NO TIKET
			for ($i = 1; $i <= $nama9; $i++) {
				include("config/connection.php");
				$tgl = date("Y-m-d");
				$sql1 = "select count(id) from tb_tiket where date(tanggal) = '".$tgl."'";
				$query1 =mysql_query($sql1);
				$row = mysql_fetch_row($query1);
				$jumlah = $row[0];
				$bk=$jumlah + 1;
				$dp = date("dmy");
				$notiket = $dp.$bk;
				$namact = '';
				
				if($nama9 > 1){
					$namact = $nama." Golongan V B -".$i;
				}else{
					$namact = $nama." Golongan V B";
				}
			
			//SIMPAN DATA
			include("config/connection.php");
				
				$sql="insert into tb_tiket (id_jadwal, id_angkutan, harga, nama, no_identitas, tanggal, no_tiket, id_operator, id_master) values ('".$id_jadwal."', '9', '355300', '".$namact."', '".$no_identitas."', now(), '".$notiket."', '".$id_operator."', '".$idmaster."')";
				if (!mysql_query($sql,$test)){
				die('Error: ' . mysql_error());
				}
				
			include("config/connection.php");
				
				$sql="update tb_jadwal set Sisa = Sisa -1 where Id_Jadwal = '".$id_jadwal."'";
				if (!mysql_query($sql,$test)){
				die('Error: ' . mysql_error());
				}
			?>
			<?php	
			
			}
		}



		if($nama10 > 0){
			//BUAT NO TIKET
			for ($i = 1; $i <= $nama10; $i++) {
				include("config/connection.php");
				$tgl = date("Y-m-d");
				$sql1 = "select count(id) from tb_tiket where date(tanggal) = '".$tgl."'";
				$query1 =mysql_query($sql1);
				$row = mysql_fetch_row($query1);
				$jumlah = $row[0];
				$bk=$jumlah + 1;
				$dp = date("dmy");
				$notiket = $dp.$bk;
				$namact = '';
				
				if($nama10 > 1){
					$namact = $nama." Golongan VI A -".$i;
				}else{
					$namact = $nama." Golongan VI A";
				}
			
			//SIMPAN DATA
			include("config/connection.php");
				
				$sql="insert into tb_tiket (id_jadwal, id_angkutan, harga, nama, no_identitas, tanggal, no_tiket, id_operator, id_master) values ('".$id_jadwal."', '10', '805200', '".$namact."', '".$no_identitas."', now(), '".$notiket."', '".$id_operator."', '".$idmaster."')";
				if (!mysql_query($sql,$test)){
				die('Error: ' . mysql_error());
				}
				
			include("config/connection.php");
				
				$sql="update tb_jadwal set Sisa = Sisa -1 where Id_Jadwal = '".$id_jadwal."'";
				if (!mysql_query($sql,$test)){
				die('Error: ' . mysql_error());
				}
			?>
			<?php	
			
			}
		}



		if($nama11 > 0){
			//BUAT NO TIKET
			for ($i = 1; $i <= $nama11; $i++) {
				include("config/connection.php");
				$tgl = date("Y-m-d");
				$sql1 = "select count(id) from tb_tiket where date(tanggal) = '".$tgl."'";
				$query1 =mysql_query($sql1);
				$row = mysql_fetch_row($query1);
				$jumlah = $row[0];
				$bk=$jumlah + 1;
				$dp = date("dmy");
				$notiket = $dp.$bk;
				$namact = '';
				
				if($nama11 > 1){
					$namact = $nama." Golongan VI B -".$i;
				}else{
					$namact = $nama." Golongan VI B";
				}
			
			//SIMPAN DATA
			include("config/connection.php");
				
				$sql="insert into tb_tiket (id_jadwal, id_angkutan, harga, nama, no_identitas, tanggal, no_tiket, id_operator, id_master) values ('".$id_jadwal."', '11', '580000', '".$namact."', '".$no_identitas."', now(), '".$notiket."', '".$id_operator."', '".$idmaster."')";
				if (!mysql_query($sql,$test)){
				die('Error: ' . mysql_error());
				}
				
			include("config/connection.php");
				
				$sql="update tb_jadwal set Sisa = Sisa -1 where Id_Jadwal = '".$id_jadwal."'";
				if (!mysql_query($sql,$test)){
				die('Error: ' . mysql_error());
				}
			?>
			<?php	
			
			}
		}



		if($nama12 > 0){
			//BUAT NO TIKET
			for ($i = 1; $i <= $nama12; $i++) {
				include("config/connection.php");
				$tgl = date("Y-m-d");
				$sql1 = "select count(id) from tb_tiket where date(tanggal) = '".$tgl."'";
				$query1 =mysql_query($sql1);
				$row = mysql_fetch_row($query1);
				$jumlah = $row[0];
				$bk=$jumlah + 1;
				$dp = date("dmy");
				$notiket = $dp.$bk;
				$namact = '';
				
				if($nama12 > 1){
					$namact = $nama." Golongan VII -".$i;
				}else{
					$namact = $nama." Golongan VII";
				}
			
			//SIMPAN DATA
			include("config/connection.php");
				
				$sql="insert into tb_tiket (id_jadwal, id_angkutan, harga, nama, no_identitas, tanggal, no_tiket, id_operator, id_master) values ('".$id_jadwal."', '12', '927750', '".$namact."', '".$no_identitas."', now(), '".$notiket."', '".$id_operator."', '".$idmaster."')";
				if (!mysql_query($sql,$test)){
				die('Error: ' . mysql_error());
				}
				
			include("config/connection.php");
				
				$sql="update tb_jadwal set Sisa = Sisa -1 where Id_Jadwal = '".$id_jadwal."'";
				if (!mysql_query($sql,$test)){
				die('Error: ' . mysql_error());
				}
			?>
			<?php	
			
			}
		}



		if($nama13 > 0){
			//BUAT NO TIKET
			for ($i = 1; $i <= $nama13; $i++) {
				include("config/connection.php");
				$tgl = date("Y-m-d");
				$sql1 = "select count(id) from tb_tiket where date(tanggal) = '".$tgl."'";
				$query1 =mysql_query($sql1);
				$row = mysql_fetch_row($query1);
				$jumlah = $row[0];
				$bk=$jumlah + 1;
				$dp = date("dmy");
				$notiket = $dp.$bk;
				$namact = '';
				
				if($nama13 > 1){
					$namact = $nama." Golongan VIII -".$i;
				}else{
					$namact = $nama." Golongan VIII";
				}
			
			//SIMPAN DATA
			include("config/connection.php");
				
				$sql="insert into tb_tiket (id_jadwal, id_angkutan, harga, nama, no_identitas, tanggal, no_tiket, id_operator, id_master) values ('".$id_jadwal."', '13', '1688900', '".$namact."', '".$no_identitas."', now(), '".$notiket."', '".$id_operator."', '".$idmaster."')";
				if (!mysql_query($sql,$test)){
				die('Error: ' . mysql_error());
				}
				
			include("config/connection.php");
				
				$sql="update tb_jadwal set Sisa = Sisa -1 where Id_Jadwal = '".$id_jadwal."'";
				if (!mysql_query($sql,$test)){
				die('Error: ' . mysql_error());
				}
			?>
			<?php	
			
			}
		}
?>
<script>window.location = "<?php echo $base?>print-tiket.php?id=<?php echo $idmaster?>", "_blank"</script>
