<?php
	include "../../conf/conn.php";
	
	if(isset($_GET['del']) and $_GET['del'] == 'delete')
	{
		$queryfile = mysql_query("SELECT no_id, name_file FROM spy_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 spy_file");
		mysql_query("TRUNCATE TABLE spy_grh");
		mysql_query("TRUNCATE TABLE spy_grt");
		mysql_query("TRUNCATE TABLE spy_hdr");
		mysql_query("TRUNCATE TABLE spy_nwr");
		mysql_query("TRUNCATE TABLE spy_opu");
		mysql_query("TRUNCATE TABLE spy_orn");
		mysql_query("TRUNCATE TABLE spy_owr");
		mysql_query("TRUNCATE TABLE spy_alt");
		mysql_query("TRUNCATE TABLE spy_per");
		mysql_query("TRUNCATE TABLE spy_pwr");
		mysql_query("TRUNCATE TABLE spy_rec");
		mysql_query("TRUNCATE TABLE spy_sequence");
		mysql_query("TRUNCATE TABLE spy_spt");
		mysql_query("TRUNCATE TABLE spy_spu");
		mysql_query("TRUNCATE TABLE spy_swr");
		mysql_query("TRUNCATE TABLE spy_swt");
		mysql_query("TRUNCATE TABLE spy_trl");
		
		//header('location:index.php');
		
		echo '<script>alert("Database Berhasil Dikosongkan !!!");
		window.location.href="../../index.php?page=spotify_1_cwr"</script>';	
	}
	elseif(isset($_GET['deldoc']) and $_GET['deldoc'] == 'deletedoc')
	{
		mysql_query("DELETE FROM spy_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>';
	}
?>