<?php
session_start();
include "../../conf/conn.php";
error_reporting(E_ALL ^ E_NOTICE); 
require_once '../../conf/excel_reader2.php';

//jika tombol import ditekan 
if(isset($_POST['submit']))
{
	$target = basename($_FILES['filemetadata']['name']) ;
    move_uploaded_file($_FILES['filemetadata']['tmp_name'], $target);
    $data = new Spreadsheet_Excel_Reader($_FILES['filemetadata']['name'],false);

 
	//-------- import HDR dari sheet 0 ----------
	// baca jumlah baris dalam sheet 0
	$jmlbaris_hdr = $data->rowcount(0);
	
	//import data excel mulai baris ke-2 (karena tabel xls ada header pada baris 1)
    for ($i=2; $i<=$jmlbaris_hdr; $i++)
    {
	  //membaca data (kolom ke-1 sd terakhir)
      $hdr_record_type		    			= $data->val($i, 1, 0);
	  $hdr_sender_type         				= $data->val($i, 2, 0);
      $hdr_sender_id		 				= $data->val($i, 3, 0);
      $hdr_sender_name  					= $data->val($i, 4, 0);
	  $hdr_edi_standar_version_number 		= $data->val($i, 5, 0);
	  $hdr_creation_date 					= $data->val($i, 6, 0);
	  $hdr_creation_time 					= $data->val($i, 7, 0);
	  $hdr_transmission_date				= $data->val($i, 8, 0);
	  $hdr_character_set					= $data->val($i, 9, 0);
	  $hdr_status_download					= '';
	  

	  //setelah data dibaca, masukkan ke tabel hdr sql
      $query_hdr = "INSERT ttk_hdr (record_type,
	  sender_type,
	  sender_id,
	  sender_name,
	  edi_standar_version_number, 
	  creation_date,
	  creation_time,
	  transmission_date,
	  character_set,
	  status_download)values('$hdr_record_type',
	  '$hdr_sender_type',
	  '$hdr_sender_id',
	  '".str_replace("'"," ",$hdr_sender_name)."',
	  '$hdr_edi_standar_version_number', 
	  '$hdr_creation_date',
	  '$hdr_creation_time',
	  '$hdr_transmission_date',
	  '$hdr_character_set',
	  '$hdr_status_download')";
      mysql_query($query_hdr);
	  
    }
	//-------- import HDR dari sheet 0 ----------
	
	
	
	//-------- import GRH dari sheet 1 ----------
	// baca jumlah baris dalam sheet 1
	$jmlbaris_grh = $data->rowcount(1);
 	
	//import data excel mulai baris ke-2 (karena tabel xls ada header pada baris 1)
    for ($i=2; $i<=$jmlbaris_grh; $i++)
    {
	  //membaca data (kolom ke-1 sd terakhir)
      $grh_record_type		    = $data->val($i, 1, 1);
	  $grh_transaction_type     = $data->val($i, 2, 1);
      $grh_group_id 			= $data->val($i, 3, 1);
      $grh_version_number  		= $data->val($i, 4, 1);
	  $grh_batch_request 		= $data->val($i, 5, 1);
	  $grh_sub_distro_type 		= $data->val($i, 6, 1);

        
	  //setelah data dibaca, masukkan ke tabel grh sql
	  $query_grh = "INSERT INTO ttk_grh (record_type,
      transaction_type,
      group_id,
      version_number,
      batch_request,
	  sub_distro_type)values('$grh_record_type',
      '$grh_transaction_type',
      '$grh_group_id',
      '$grh_version_number',
      '$grh_batch_request',
	  '$grh_sub_distro_type')";
      mysql_query($query_grh);
    }
	//-------- akhir import GRH dari sheet 1 ----------


	
	
	//-------- import NWR dari sheet 2 ----------
	// baca jumlah baris dalam sheet 2
	$jmlbaris_nwr = $data->rowcount(2);
 	
	//    import data excel mulai baris ke-2 (karena tabel xls ada header pada baris 1)
    for ($i=2; $i<=$jmlbaris_nwr; $i++)
    {
	  //membaca data (kolom ke-1 sd terakhir)
      $nwr_record_type		         				= $data->val($i, 1, 2);
	  $nwr_transaction_sequence         			= $data->val($i, 2, 2);
      $nwr_record_sequence 							= $data->val($i, 3, 2);
      $nwr_work_title  								= $data->val($i, 4, 2);
	  $nwr_language_code 							= $data->val($i, 5, 2);
	  $nwr_submitter_work_number 					= $data->val($i, 6, 2);
	  $nwr_iswc 									= $data->val($i, 7, 2);
	  $nwr_copy_right_date							= $data->val($i, 8, 2);
	  $nwr_copyright_number							= $data->val($i, 9, 2);
	  $nwr_musical_work_distribution				= $data->val($i, 10, 2);
	  $nwr_duration									= $data->val($i, 11, 2);
	  $nwr_recorded_indicator						= $data->val($i, 12, 2);	
	  $nwr_text_music_relationship					= $data->val($i, 13, 2);
	  $nwr_composite_type							= $data->val($i, 14, 2);
	  $nwr_version_type								= $data->val($i, 15, 2);
	  $nwr_excerpt_type								= $data->val($i, 16, 2);
	  $nwr_music_arrangement						= $data->val($i, 17, 2); 	
	  $nwr_lyric_adaptation							= $data->val($i, 18, 2);
	  $nwr_contact_name								= $data->val($i, 19, 2);
	  $nwr_contact_id								= $data->val($i, 20, 2);
	  $nwr_cwr_work_type							= $data->val($i, 21, 2);
	  $nwr_grand_right_indicator					= $data->val($i, 22, 2);
	  $nwr_composite_component_count				= $data->val($i, 23, 2); 
	  $nwr_date_of_publication_of_printed_edition	= $data->val($i, 24, 2);
	  $nwr_exceptional_clause						= $data->val($i, 25, 2);
	  $nwr_opus_number								= $data->val($i, 26, 2);
	  $nwr_catalogue_number							= $data->val($i, 27, 2);
	  $nwr_priority_flag							= $data->val($i, 28, 2);
	  
	  
	    
	  //setelah data dibaca, masukkan ke tabel nwr sql
	  $query_nwr = "INSERT INTO ttk_nwr (record_type,
      transaction_sequence,
      record_sequence,
      work_title,
      language_code, 
	  submitter_work_number,
	  iswc,
	  copy_right_date,
	  copyright_number,
	  musical_work_distribution,
	  duration,
	  recorded_indicator,
	  text_music_relationship,
	  composite_type,
	  version_type,
	  excerpt_type,
	  music_arrangement,
	  lyric_adaptation,
	  contact_name,
	  contact_id,
	  cwr_work_type,
	  grand_right_indicator,
	  composite_component_count,
	  date_of_publication_of_printed_edition,
	  exceptional_clause,
	  opus_number,
	  catalogue_number,
	  priority_flag)values('$nwr_record_type',
      '$nwr_transaction_sequence',
      '$nwr_record_sequence',
      '".str_replace("'"," ",$nwr_work_title)."',
      '$nwr_language_code', 
	  '$nwr_submitter_work_number',
	  '$nwr_iswc',
	  '$nwr_copy_right_date',
	  '$nwr_copyright_number',
	  '$nwr_musical_work_distribution',
	  '$nwr_duration',
	  '$nwr_recorded_indicator',
	  '$nwr_text_music_relationship',
	  '$nwr_composite_type',
	  '$nwr_version_type',
	  '$nwr_excerpt_type',
	  '$nwr_music_arrangement',
	  '$nwr_lyric_adaptation',
	  '$nwr_contact_name',
	  '$nwr_contact_id',
	  '$nwr_cwr_work_type',
	  '$nwr_grand_right_indicator',
	  '$nwr_composite_component_count',
	  '$nwr_date_of_publication_of_printed_edition',
	  '$nwr_exceptional_clause',
	  '$nwr_opus_number',
	  '$nwr_catalogue_number',
	  '$nwr_priority_flag')";
      mysql_query($query_nwr);
    }
	//-------- akhir import NWR dari sheet 2 ----------
	


	//-------- import SPU dari sheet 3 ----------
	// baca jumlah baris dalam sheet 3
	$jmlbaris_spu = $data->rowcount(3);
	
	//import data excel mulai baris ke-2 (karena tabel xls ada header pada baris 1)
    for ($i=2; $i<=$jmlbaris_spu; $i++)
    {
	  //membaca data (kolom ke-1 sd terakhir)
      $spu_record_type		         			= $data->val($i, 1, 3);
	  $spu_transaction_sequence         		= $data->val($i, 2, 3);
      $spu_seq_spu 								= $data->val($i, 3, 3);
      $spu_publisher_sequence_number  			= $data->val($i, 4, 3);
	  $spu_interested_party_number 				= $data->val($i, 5, 3);
	  $spu_publisher_name 						= $data->val($i, 6, 3);
	  $spu_publisher_unknown_indicator 			= $data->val($i, 7, 3);
	  $spu_publisher_type						= $data->val($i, 8, 3);
	  $spu_tax_id_number						= $data->val($i, 9, 3);
	  $spu_publisher_ipi_name_number			= $data->val($i, 10, 3);
	  $spu_submitter_agreement_number			= $data->val($i, 11, 3);
	  $spu_pr_affiliation_society				= $data->val($i, 12, 3);
	  $spu_pr_share								= $data->val($i, 13, 3);
	  $spu_mr_affiliation_society				= $data->val($i, 14, 3);
	  $spu_mr_share								= $data->val($i, 15, 3);
	  $spu_sr_affiliation_society				= $data->val($i, 16, 3);
	  $spu_sr_share								= $data->val($i, 17, 3);
	  $spu_special_agreements_indicator			= $data->val($i, 18, 3);
	  $spu_first_recording_refusal_indicator	= $data->val($i, 19, 3);
	  $spu_filler								= $data->val($i, 20, 3);
	  $spu_publisher_ipi_base_number			= $data->val($i, 21, 3);
	  $spu_isac									= $data->val($i, 22, 3);
	  $spu_saan									= $data->val($i, 23, 3);
	  $spu_agreement_type						= $data->val($i, 24, 3);
	  $spu_usa_license_indicator				= $data->val($i, 25, 3);
	  	
	    
	  //setelah data dibaca, masukkan ke tabel spu sql
	  $query_spu = "INSERT INTO ttk_spu (record_type,
      transaction_sequence,
      seq_spu,
      publisher_sequence_number,
      interested_party_number, 
	  publisher_name,
	  publisher_unknown_indicator,
	  publisher_type,
	  tax_id_number,
	  publisher_ipi_name_number,
	  submitter_agreement_number,
	  pr_affiliation_society,
	  pr_share,
	  mr_affiliation_society,
	  mr_share,
	  sr_affiliation_society,
	  sr_share,
	  special_agreements_indicator,
	  first_recording_refusal_indicator,
	  filler,
	  publisher_ipi_base_number,
	  isac,
	  saan,
	  agreement_type,
	  usa_license_indicator)values('$spu_record_type',
      '$spu_transaction_sequence',
      '$spu_seq_spu',
      '$spu_publisher_sequence_number',
      '$spu_interested_party_number', 
	  '".str_replace("'"," ",$spu_publisher_name)."',
	  '$spu_publisher_unknown_indicator',
	  '$spu_publisher_type',
	  '$spu_tax_id_number',
	  '$spu_publisher_ipi_name_number',
	  '$spu_submitter_agreement_number',
	  '$spu_pr_affiliation_society',
	  '$spu_pr_share',
	  '$spu_mr_affiliation_society',
	  '$spu_mr_share',
	  '$spu_sr_affiliation_society',
	  '$spu_sr_share',
	  '$spu_special_agreements_indicator',
	  '$spu_first_recording_refusal_indicator',
	  '$spu_filler',
	  '$spu_publisher_ipi_base_number',
	  '$spu_isac',
	  '$spu_saan',
	  '$spu_agreement_type',
	  '$spu_usa_license_indicator')";
      mysql_query($query_spu);
    }
	//-------- akhir import SPU dari sheet 3 ----------
	
	
	
	//-------- import SPT dari sheet 4 ----------
	// baca jumlah baris dalam sheet 4
	$jmlbaris_spt = $data->rowcount(4);
	
	//import data excel mulai baris ke-2 (karena tabel xls ada header pada baris 1)
    for ($i=2; $i<=$jmlbaris_spt; $i++)
    {
	  //membaca data (kolom ke-1 sd terakhir)
	  $spt_record_type		         		= $data->val($i, 1, 4);
      $spt_transaction_sequence         	= $data->val($i, 2, 4);
      $spt_seq_spt 							= $data->val($i, 3, 4);
      $spt_interested_party_number  		= $data->val($i, 4, 4);
	  $spt_constant 						= $data->val($i, 5, 4);
	  $spt_pr_share 						= $data->val($i, 6, 4);
	  $spt_mr_share 						= $data->val($i, 7, 4);
	  $spt_sr_share							= $data->val($i, 8, 4);
	  $spt_inclusion_exclusion_indicator	= $data->val($i, 9, 4);
	  $spt_tis_numeric_code					= $data->val($i, 10, 4);
	  $spt_shares_change					= $data->val($i, 11, 4);	
	  $spt_sequence_number					= $data->val($i, 12, 4);
      
	  
	  //setelah data dibaca, masukkan ke tabel spt sql
	  $query_spt = "INSERT INTO ttk_spt (record_type,
      transaction_sequence,
      seq_spt,
      interested_party_number, 
	  constant,
	  pr_share,
	  mr_share,
	  sr_share,
	  inclusion_exclusion_indicator,
	  tis_numeric_code,
	  shares_change,
	  sequence_number)values('$spt_record_type',
      '$spt_transaction_sequence',
      '$spt_seq_spt',
      '$spt_interested_party_number',
      '$spt_constant', 
	  '$spt_pr_share',
	  '$spt_mr_share',
	  '$spt_sr_share',
	  '$spt_inclusion_exclusion_indicator',
	  '$spt_tis_numeric_code',
	  '$spt_shares_change',
	  '$spt_sequence_number')";
      mysql_query($query_spt);
    }
	//-------- akhir import SPT dari sheet 4 ----------
	
	
	
	//-------- import SWR dari sheet 5 ----------
	// baca jumlah baris dalam sheet 5
	$jmlbaris_swr = $data->rowcount(5);
	
	//import data excel mulai baris ke-2 (karena tabel xls ada header pada baris 1)
    for ($i=2; $i<=$jmlbaris_swr; $i++)
    {
	  //membaca data (kolom ke-1 sd terakhir)
	  $swr_record_type		         			= $data->val($i, 1, 5);
      $swr_transaction_sequence         		= $data->val($i, 2, 5);
      $swr_seq_swr 								= $data->val($i, 3, 5);
      $swr_interested_party_number  			= $data->val($i, 4, 5);
	  $swr_writer_last_name 					= $data->val($i, 5, 5);
	  $swr_writer_first_name 					= $data->val($i, 6, 5);
	  $swr_writer_unknown_indicator 			= $data->val($i, 7, 5);
	  $swr_writer_designation_code				= $data->val($i, 8, 5);
	  $swr_tax_id_number						= $data->val($i, 9, 5);
	  $swr_writer_ipi_name_number				= $data->val($i, 10, 5);
	  $swr_pr_affiliation_society				= $data->val($i, 11, 5);
	  $swr_pr_share								= $data->val($i, 12, 5);
	  $swr_mr_affiliation_society				= $data->val($i, 13, 5);
	  $swr_mr_share								= $data->val($i, 14, 5);
	  $swr_sr_affiliation_society				= $data->val($i, 15, 5);
	  $swr_sr_share								= $data->val($i, 16, 5);
	  $swr_reversionary_indicator				= $data->val($i, 17, 5);
	  $swr_first_recording_refusal_indicator	= $data->val($i, 18, 5);
	  $swr_work_for_hire_indicator				= $data->val($i, 19, 5);
	  $swr_filler								= $data->val($i, 20, 5);
	  $swr_writer_ipi_base_number				= $data->val($i, 21, 5);
	  $swr_personal_number						= $data->val($i, 22, 5);
	  $swr_usa_licence_indicator				= $data->val($i, 23, 5);
	  
	    
	  //setelah data dibaca, masukkan ke tabel swr sql
	  $query_swr = "INSERT INTO ttk_swr (record_type,
      transaction_sequence,
      seq_swr,
	  interested_party_number,
	  writer_last_name,
	  writer_first_name,
	  writer_unknown_indicator,
	  writer_designation_code,
	  tax_id_number,
	  writer_ipi_name_number,
	  pr_affiliation_society,
	  pr_share,
	  mr_affiliation_society,
	  mr_share,
	  sr_affiliation_society,
	  sr_share,
	  reversionary_indicator,
	  first_recording_refusal_indicator,
	  work_for_hire_indicator,
	  filler,
	  writer_ipi_base_number,
	  personal_number,
	  usa_licence_indicator)values('$swr_record_type',
      '$swr_transaction_sequence',
      '$swr_seq_swr',
	  '$swr_interested_party_number',
	  '".str_replace("'"," ",$swr_writer_last_name)."',
	  '".str_replace("'"," ",$swr_writer_first_name)."',
	  '$swr_writer_unknown_indicator',
	  '$swr_writer_designation_code',
	  '$swr_tax_id_number',
	  '$swr_writer_ipi_name_number',
	  '$swr_pr_affiliation_society',
	  '$swr_pr_share',
	  '$swr_mr_affiliation_society',
	  '$swr_mr_share',
      '$swr_sr_affiliation_society',
      '$swr_sr_share', 
	  '$swr_reversionary_indicator',
	  '$swr_first_recording_refusal_indicator',
	  '$swr_work_for_hire_indicator',
	  '$swr_filler',
	  '$swr_writer_ipi_base_number',
	  '$swr_personal_number',
	  '$swr_usa_licence_indicator')";
      mysql_query($query_swr);
    }
	//-------- akhir import SWR dari sheet 5 ----------
	
	
	
	//-------- import SWT dari sheet 6 ----------
	// baca jumlah baris dalam sheet 6
	$jmlbaris_swt = $data->rowcount(6);
	
	//import data excel mulai baris ke-2 (karena tabel xls ada header pada baris 1)
    for ($i=2; $i<=$jmlbaris_swt; $i++)
    {
	  //membaca data (kolom ke-1 sd terakhir)
      $swt_record_type		         		= $data->val($i, 1, 6);
	  $swt_transaction_sequence         	= $data->val($i, 2, 6);
      $swt_seq_swt 							= $data->val($i, 3, 6);
      $swt_interested_party_number  		= $data->val($i, 4, 6);
	  $swt_pr_share 						= $data->val($i, 5, 6);
	  $swt_mr_share 						= $data->val($i, 6, 6);
	  $swt_sr_share 						= $data->val($i, 7, 6);
	  $swt_inclusion_exclusion_indicator	= $data->val($i, 8, 6);
	  $swt_tis_numeric_code					= $data->val($i, 9, 6);
	  $swt_shares_change					= $data->val($i, 10, 6);
	  $swt_sequence_number					= $data->val($i, 11, 6);	

	    
	  //setelah data dibaca, masukkan ke tabel swt sql
	  $query_swt = "INSERT INTO ttk_swt (record_type,
      transaction_sequence,
      seq_swt,
	  interested_party_number,
	  pr_share,
	  mr_share,
	  sr_share,
	  inclusion_exclusion_indicator,
	  tis_numeric_code,
	  shares_change,
	  sequence_number)values('$swt_record_type',
      '$swt_transaction_sequence',
      '$swt_seq_swt',
	  '$swt_interested_party_number',
	  '$swt_pr_share',
	  '$swt_mr_share',
	  '$swt_sr_share',
	  '$swt_inclusion_exclusion_indicator',
	  '$swt_tis_numeric_code',
	  '$swt_shares_change',
	  '$swt_sequence_number')";
      mysql_query($query_swt);
    }
	//-------- akihir import SWT dari sheet 6 ----------
	
	
	
	
	//-------- import PWR dari sheet 7 ----------
	// baca jumlah baris dalam sheet 7
	$jmlbaris_pwr = $data->rowcount(7);
	
	//import data excel mulai baris ke-2 (karena tabel xls ada header pada baris 1)
    for ($i=2; $i<=$jmlbaris_pwr; $i++)
    {
	  //membaca data (kolom ke-1 sd terakhir)
      $pwr_record_type		         			= $data->val($i, 1, 7);
	  $pwr_transaction_sequence         		= $data->val($i, 2, 7);
      $pwr_seq_pwr 								= $data->val($i, 3, 7);
      $pwr_publisher_interested_party_number	= $data->val($i, 4, 7);
	  $pwr_publisher_name 						= $data->val($i, 5, 7);
	  $pwr_submitter_agreement_number 			= $data->val($i, 6, 7);
	  $pwr_saan 								= $data->val($i, 7, 7);
	  $pwr_writer_interested_party_number		= $data->val($i, 8, 7);

	    
	  //setelah data dibaca, masukkan ke tabel pwr sql
	  $query_pwr = "INSERT INTO ttk_pwr (record_type,
      transaction_sequence,
      seq_pwr,
	  publisher_interested_party_number,
	  publisher_name,
	  submitter_agreement_number,
	  saan,
	  writer_interested_party_number)values('$pwr_record_type',
      '$pwr_transaction_sequence',
      '$pwr_seq_pwr',
	  '$pwr_publisher_interested_party_number',
	  '".str_replace("'"," ",$pwr_publisher_name)."',
	  '$pwr_submitter_agreement_number',
	  '$pwr_saan',
	  '$pwr_writer_interested_party_number')";
      mysql_query($query_pwr);
    }
	//-------- akhir import PWR dari sheet 7 ----------
	
	
	
	
	//-------- import OWR dari sheet 8 ----------
	// baca jumlah baris dalam sheet 8
	$jmlbaris_owr = $data->rowcount(8);
	
	//import data excel mulai baris ke-2 (karena tabel xls ada header pada baris 1)
    for ($i=2; $i<=$jmlbaris_owr; $i++)
    {
	  //membaca data (kolom ke-1 sd terakhir)
	  $owr_record_type         					= $data->val($i, 1, 8);
      $owr_transaction_sequence         		= $data->val($i, 2, 8);
      $owr_seq_owr 								= $data->val($i, 3, 8);
      $owr_interested_party_number  			= $data->val($i, 4, 8);
	  $owr_writer_last_name 					= $data->val($i, 5, 8);
	  $owr_writer_first_name 					= $data->val($i, 6, 8);
	  $owr_writer_unknown_indicator				= $data->val($i, 7, 8);
	  $owr_writer_designation_code 				= $data->val($i, 8, 8);
	  $owr_tax_id_number						= $data->val($i, 9, 8);
	  $owr_writer_ipi_name_number				= $data->val($i, 10, 8);
	  $owr_pr_affiliation_society				= $data->val($i, 11, 8);
	  $owr_pr_share								= $data->val($i, 12, 8);
	  $owr_mr_affiliation_society				= $data->val($i, 13, 8);
	  $owr_mr_share								= $data->val($i, 14, 8);
	  $owr_sr_affiliation_society				= $data->val($i, 15, 8);
	  $owr_sr_share								= $data->val($i, 16, 8);
	  $owr_reversionary_indicator				= $data->val($i, 17, 8);
	  $owr_first_recording_refusal_indicator	= $data->val($i, 18, 8);
	  $owr_work_for_hire_indicator				= $data->val($i, 19, 8);
	  $owr_filler								= $data->val($i, 20, 8);
	  $owr_writer_ipi_base_number				= $data->val($i, 21, 8);
	  $owr_personal_number						= $data->val($i, 22, 8);
	  $owr_usa_licence_indicator				= $data->val($i, 23, 8);

	    
	  //setelah data dibaca, masukkan ke tabel owr sql
	  $query_owr = "INSERT INTO ttk_owr (record_type,
      transaction_sequence,
      seq_owr,
	  interested_party_number,
	  writer_last_name,
	  writer_first_name, 
	  writer_unknown_indicator,
	  writer_designation_code,
	  tax_id_number,
	  writer_ipi_name_number,
	  pr_affiliation_society,
	  pr_share,
	  mr_affiliation_society,
	  mr_share,
	  sr_affiliation_society,
	  sr_share,
	  reversionary_indicator,
	  first_recording_refusal_indicator,
	  work_for_hire_indicator,
	  filler,
	  writer_ipi_base_number,
	  personal_number,
	  usa_licence_indicator)values('$owr_record_type',
      '$owr_transaction_sequence',
      '$owr_seq_owr',
	  '$owr_interested_party_number',
	  '".str_replace("'"," ",$owr_writer_last_name)."',
	  '".str_replace("'"," ",$owr_writer_first_name)."', 
	  '$owr_writer_unknown_indicator',
	  '$owr_writer_designation_code',
	  '$owr_tax_id_number',
	  '$owr_writer_ipi_name_number',
	  '$owr_pr_affiliation_society',
	  '$owr_pr_share',
	  '$owr_mr_affiliation_society',
	  '$owr_mr_share',
	  '$owr_sr_affiliation_society',
	  '$owr_sr_share',
	  '$owr_reversionary_indicator',
	  '$owr_first_recording_refusal_indicator',
	  '$owr_work_for_hire_indicator',
	  '$owr_filler',
	  '$owr_writer_ipi_base_number',
	  '$owr_personal_number',
	  '$owr_usa_licence_indicator')";
      mysql_query($query_owr);
    }
	//-------- akhir import OWR dari sheet 8 ----------
	
	
	
	
	//-------- import GRT dari sheet 9 ----------
	// baca jumlah baris dalam sheet 9
	$jmlbaris_grt = $data->rowcount(9);
 	
	//    import data excel mulai baris ke-2 (karena tabel xls ada header pada baris 1)
    for ($i=2; $i<=$jmlbaris_grt; $i++)
    {
	  //membaca data (kolom ke-1 sd terakhir)
	  $grt_record_type         	= $data->val($i, 1, 9);
      $grt_group_id         	= $data->val($i, 2, 9);
      $grt_transaction_count 	= $data->val($i, 3, 9);
      $grt_record_count  		= $data->val($i, 4, 9);
	  $grt_currency_indicator 	= $data->val($i, 5, 9);
	  $grt_total_monetary_value = $data->val($i, 6, 9);

	    
	  //setelah data dibaca, masukkan ke tabel grt sql
	  $query_grt = "INSERT INTO ttk_grt (record_type,
      group_id,
      transaction_count,
	  record_count,
	  currency_indicator,
	  total_monetary_value)values('$grt_record_type',
      '$grt_group_id',
      '$grt_transaction_count',
	  '$grt_record_count',
	  '$grt_currency_indicator',
	  '$grt_total_monetary_value')";
      mysql_query($query_grt);
    }
	//-------- akhir import GRT dari sheet 9 ----------
	
	
	
	//-------- import TRL dari sheet 10 ----------
	// baca jumlah baris dalam sheet 10
	$jmlbaris_trl = $data->rowcount(10);
 	
	//import data excel mulai baris ke-2 (karena tabel xls ada header pada baris 1)
    for ($i=2; $i<=$jmlbaris_trl; $i++)
    {
	  //membaca data (kolom ke-1 sd terakhir)
	  $trl_record_type         	= $data->val($i, 1, 10);
      $trl_group_id         	= $data->val($i, 2, 10);
      $trl_transaction_count 	= $data->val($i, 3, 10);
      $trl_record_count  		= $data->val($i, 4, 10);

      
	  //setelah data dibaca, masukkan ke tabel trl sql
	  $query_trl = "INSERT INTO ttk_trl (record_type,
      group_count,
      transaction_count,
	  record_count)values('$trl_record_type',
      '$trl_group_id',
      '$trl_transaction_count',
	  '$trl_record_count')";
      mysql_query($query_trl);
    }
	//-------- akhir import TRL dari sheet 10 ----------
	
	

	//-------- import SEQUENCE dari sheet 11 ----------
	// baca jumlah baris dalam sheet 11
	$jmlbaris_sequence = $data->rowcount(11);
 	
	//import data excel mulai baris ke-2 (karena tabel xls ada header pada baris 1)
    for ($i=2; $i<=$jmlbaris_sequence; $i++)
    {
	  //membaca data (kolom ke-1 sd terakhir)
	  $sequence_group_id         		= $data->val($i, 1, 11); 
	  $sequence_record_type         	= $data->val($i, 2, 11);
      $sequence_transaction_sequence    = $data->val($i, 3, 11);
	  $sequence_seq_record_type    		= $data->val($i, 4, 11);
      $sequence_record_sequence 		= $data->val($i, 5, 11);

      
	  //setelah data dibaca, masukkan ke tabel sequence sql
	  $query_sequence = "INSERT INTO ttk_sequence (group_id, 
	  record_type,
      transaction_sequence, 
	  seq_record_type, 
	  record_sequence)values('$sequence_group_id', 
	  '$sequence_record_type',
      '$sequence_transaction_sequence', 
	  '$sequence_seq_record_type', 
	  '$sequence_record_sequence')";
      mysql_query($query_sequence);
    }
	//-------- akhir import SEQUENCE dari sheet 11 ----------
	
	
	
	//hapus file xls yang udah dibaca
  	unlink($_FILES['filemetadata']['name']);
	
	echo '<script>alert("Proses import selesai !!!");
	window.location.href="../../index.php?page=tiktok_cwr"</script>';

}
else
{
	
	echo '<script>alert("Proses import gagal !!!");
	window.location.href="../../index.php?page=tiktok_cwr"</script>';

}
 
?>