<?php
	session_start();
	include "../../conf/conn.php";
	
	if(isset($_GET['del']) and $_GET['del'] == 'delete')
	{
		$queryfile = mysql_query("SELECT no_id, name_file FROM ttk_file ORDER BY no_id");
		while($file=mysql_fetch_array($queryfile))
		{
			$target_file = 'hasilGenerate'.'/'.$file['name_file'];
			if(file_exists($target_file))
			{
				unlink($target_file);	
			}
			
		}
		

		mysql_query("TRUNCATE TABLE ttk_file");
		mysql_query("TRUNCATE TABLE ttk_grh");
		mysql_query("TRUNCATE TABLE ttk_grt");
		mysql_query("TRUNCATE TABLE ttk_hdr");
		mysql_query("TRUNCATE TABLE ttk_nwr");
		mysql_query("TRUNCATE TABLE ttk_opu");
		mysql_query("TRUNCATE TABLE ttk_orn");
		mysql_query("TRUNCATE TABLE ttk_owr");
		mysql_query("TRUNCATE TABLE ttk_alt");
		mysql_query("TRUNCATE TABLE ttk_per");
		mysql_query("TRUNCATE TABLE ttk_pwr");
		mysql_query("TRUNCATE TABLE ttk_rec");
		mysql_query("TRUNCATE TABLE ttk_sequence");
		mysql_query("TRUNCATE TABLE ttk_spt");
		mysql_query("TRUNCATE TABLE ttk_spu");
		mysql_query("TRUNCATE TABLE ttk_swr");
		mysql_query("TRUNCATE TABLE ttk_swt");
		mysql_query("TRUNCATE TABLE ttk_trl");
		mysql_query("TRUNCATE TABLE ttk_tmp");
		
		//header('location:index.php');
		
		/*
		echo '<script>alert("Database Berhasil Dikosongkan !!!");
		window.location.href="../../index.php?page=spotify_1_cwr"</script>';
		*/

		//sebelum redirect, daftarkan session pesan
		$_SESSION['sukses'] = 'Database Berhasil Dikosongkan !!!';
		echo '<META HTTP-EQUIV="Refresh" Content="0; URL=../../index.php?page=tiktok_cwr">';
		exit;

	}
	elseif(isset($_GET['deldoc']) and $_GET['deldoc'] == 'deletedoc')
	{
		mysql_query("DELETE FROM ttk_document WHERE name_file = '$_GET[filename]'");
		$target_file = 'docFile'.'/'.$_GET['filename'];
		if(file_exists($target_file))
		{
			unlink($target_file);	
		}
		

		/*
		echo '<script>alert("File CWR Berhasil Dihapus !!!");
		window.location.href="../../index.php?page=spotify_2_cwr"</script>';
		*/

		//sebelum redirect, daftarkan session pesan
		$_SESSION['sukses'] = 'File CWR Berhasil Dihapus !!!';
		echo '<META HTTP-EQUIV="Refresh" Content="0; URL=../../index.php?page=tiktok_doc">';
		exit;
	}
?>