<?php
$sub_menu = "777200";
include_once('./_common.php');

include_once(AMINA_PATH.'/lib/admin.lib.php');

include_once(AMINA_PATH.'/lib/head.lib.php');

include(G5_PATH.'/head.sub.php');

?>
<link rel="stylesheet" href="<?=AMINA_URL?>/css/admin.css" />

<div style="padding:15px;">

	<b>■ 불당썸 썸네일 삭제하기</b>

	<? if($act) { ?>

		<?
			$arr = array();
			$arr1 = array();
			$arr2 = array();
			$arr3 = array();
			$arr4 = array();

			$dir = array('cheditor4','editor','file','video'); //data 폴더의 하위 폴더
			$dir1 = array();
			$dir2 = array();
			$dir3 = array();

			//그누보드
			for($i=0; $i < count($dir);$i++) {
				//data/file/
				$depth = G5_DATA_PATH.'/'.$dir[$i];
				if(is_dir($depth.'/')) {

					$handle = opendir($depth.'/');
				    while ($arr = readdir($handle)) {
				        if($arr == "."||$arr == "..") continue;
				        if (is_dir($depth.'/'.$arr.'/')) $dir1[] = $arr;
				    }
				    closedir($handle);

					for($k=0;$k < count($dir1); $k++) {
						//data/file/bo_table/_thumb
						$depth1 = $depth.'/'.$dir1[$k].'/_thumb';
						if(is_dir($depth1.'/')) {
							$handle1 = opendir($depth1.'/');
						    while ($arr1 = readdir($handle1)) {
								if($arr1 == "."||$arr1 == "..") continue;
								if (is_dir($depth1.'/'.$arr1.'/')) $dir2[] = $arr1;
						    }
						    closedir($handle1);

							for($n=0;$n < count($dir2); $n++) {
								//data/file/bo_table/_thumb/30x30/
								$depth2 = $depth1.'/'.$dir2[$n];
								if(is_dir($depth2.'/')) {
									$handle2 = opendir($depth2.'/');
								    while ($arr2 = readdir($handle2)) {
										if($arr2 == "."||$arr2 == "..") continue;
										@unlink($depth2.'/'.$arr2); //썸네일 삭제
									}
								    closedir($handle2);
									@rmdir($depth2.'/');
								}
							}

							@rmdir($depth1.'/');
						}
					}
				}
			}

			//영카트
			$depth3 = G5_DATA_PATH.'/item/_thumb';
			if(is_dir($depth3.'/')) {
				$handle3 = opendir($depth3.'/');
			    while ($arr3 = readdir($handle3)) {
					if($arr3 == "."||$arr3 == "..") continue;
					if (is_dir($depth3.'/'.$arr3.'/')) $dir3[] = $arr3;
			    }
			    closedir($handle3);

				for($z=0;$z < count($dir3); $z++) {
					//data/item/_thumb/30x30/
					$depth4 = $depth3.'/'.$dir3[$z];
					if(is_dir($depth4.'/')) {
						$handle4 = opendir($depth4.'/');
					    while ($arr4 = readdir($handle4)) {
							if($arr4 == "."||$arr4 == "..") continue;
							@unlink($depth4.'/'.$arr4); //썸네일 삭제
						}
					    closedir($handle4);
						@rmdir($depth4.'/');
					}
				}
				@rmdir($depth3.'/');
			}
		?>
		<script type="text/javascript"> 
			alert('불당썸 썸네일 삭제가 완료되었습니다.');
			window.close(); 
		</script>
	<? } else { ?>
		<ul style="line-height:1.8;">
			<li>불당썸으로 생성된 썸네일 중 data 폴더에 생성된 썸네일을 일괄삭제합니다.</li>
			<li>에디터(cheditor4, editor), 첨부이미지(file), 동영상(video), 영카트(item) 썸네일만 일괄삭제합니다.</li>
		</ul>
		<script type="text/javascript"> 
			function set_href(href) {
				document.getElementById('loading').style.display = "block";
				document.location.href = encodeURI(href);
			}
		</script>
		<p style="text-align:center;">
			<input type="button" value=" 썸네일 삭제하기 " onclick="set_href('<?=AMINA_URL?>/reset.thumb.php?bo_table=<?=$bo_table?>&act=on');" class="btn_blue">
		</p>
	<? } ?>
</div>
<div id="loading" style="display:none;margin-top:30px; text-align:center;">
		<img src="<?=AMINA_URL?>/img/loader.gif" />
		<p>삭제 중...</p>
</div>
<? include(G5_PATH.'/tail.sub.php'); ?>