<?php
	### 공통
	require_once($_SERVER['DOCUMENT_ROOT']."/common/common.php");



	if (!$argu['p']) $argu['p'] = 1;
	$_LIST_NUM = 20;
	$argu['d_gubun'] = "G"; // "펌웨어" 로 고정함



	$addwhere = "";
	if( $argu['s_string'] ) $argu['s_case'] = "all";

	$query_old = "
		select
			sql_calc_found_rows
			p.p_no,
			pc.c_id,
			d.*
		from
			product p,
			product_category pc,
			product_download pd,
			download d
		where
			p.p_no = pd.p_no
			and p.p_status = 'Y'
			and p.p_no = pc.p_no
			and d.d_no = pd.d_no
			and
				case
					when length(trim('$argu[s_case]')) = 0 then 1
					else
						case '$argu[s_case]'
							when 'all'     then d.d_title
							when 'd_type'  then d.d_type
							when 'd_title' then d.d_title
							when 'd_lang'  then d.d_lang
							when 'd_ver'   then d.d_ver
						end
						like ?
				end
			and d.d_status = 'Y'
			and d.d_gubun = ?
			{$addwhere}
		group by
			d.d_no
		order by
			-- d.d_order asc, d.d_no asc
			d.d_no desc
		limit ".(($argu['p']-1)*$_LIST_NUM).",".$_LIST_NUM;

	$query = "
		select
			sql_calc_found_rows
			d.*
		from
			download d
		where
				case
					when length(trim('{$argu['s_case']}')) = 0 then 1
					else
						case '{$argu['s_case']}'
							when 'all'     then d.d_title
							when 'd_type'  then d.d_type
							when 'd_title' then d.d_title
							when 'd_lang'  then d.d_lang
							when 'd_ver'   then d.d_ver
						end
						like ?
				end
			and d.d_status = 'Y'
			and d.d_gubun = ?
			{$addwhere}
		group by
			d.d_no
		order by
			-- d.d_order asc, d.d_no asc
			d.d_no desc
		limit ".(($argu['p']-1)*$_LIST_NUM).",".$_LIST_NUM;



	$res = $_list =& $_DB->getAll($query, array("%{$argu[s_string]}%",$argu['d_gubun']), DB_FETCHMODE_ASSOC);
	if (DB::isError($res)) {
		//debug($res);
		die($res->getMessage());
	}


	$query = "select found_rows()";
	$total = $_DB->getOne($query);
	if(count($_list) < 1 && $argu['p'] > 1) go_url("?mode=LIST_FORM&p=1".$default_querystring,"");

	/*
	$_tmp_list = $_list;
	$_clist = array();
	for( $i = 0 ; $i < count($_tmp_list) ; $i++ ){
		$_clist[$_tmp_list[$i]['c_id']][] = $_tmp_list[$i];
	}
	*/


	if(is_array($argu)) array_walk ($argu, "htmlspecialcharsAll");

	require_once($_SERVER['DOCUMENT_ROOT']."/include/sub_header.html");
?>
<?//include"../include/sub_header.html"?>

<div class="sub_visual sub_visual4 ac">
	<p class="st1">자료실</p>
	<p class="st2">HOME   >   자료실   >   드라이버 & 펌웨어</p>
</div>
<div class="sub_wp">
	<div class="clfix sub_in">
		<?include"left_menu.html"?>
		<script>
			$(document).ready(function(){
			  $(".left_bx>ul>li:nth-child(4)").addClass("on");
			});
		</script>
		<div class="fl right_bx">
			<p class="sub_title">드라이버 & 펌웨어</p>



			<div class="search_bar search_bar2 notice_bar clfix mt40">

				<p>Total : <?php echo number_format($total); ?>,  [<?php echo number_format($argu['p']) ?>/<?php echo number_format( ceil( $total / $_LIST_NUM ) ); ?>] Page</p>

				<form name="fsearch" method="get">
				<div class="fr">
					<div class="notice_search">
						<input type="text" name="s_string" value="<?php echo $argu['s_string'];?>" required="required" maxlength="20">
						<button type="submit" class="btnSch">Search</button>
					</div>
				</div>
				</form>
			</div>


			<table class="table_st2 mt40 notice_wrap">
				<colgroup>
					<col width="*">
					<col width="24%">
					<col width="12%">
					<col width="10%">
				</colgroup>
				<tbody>
					<tr>
						<th>제목</th>
						<th>다운로드</th>
						<th>언어</th>
						<th>버전</th>
					</tr>



				<?php
				if( count($_list) > 0 ){ // 리스트가 있을경우
					for( $i = 0 ; $i < count($_list) ; $i++ ){
				?>

					<tr>
						<td class="al">
						<?php
						$filepath = "download/".$_list[$i]['d_no']."_s";
						if(file_exists(_PDS.$filepath) && $_list[$i]['d_file']){
							$filesize = filesize(_PDS.$filepath);
							$path_parts = pathinfo($_list[$i]['d_file']);
						?>
							<a href="/common/download.php?c_id=<?php echo $_list[$i]['c_id'];?>&p_no=<?php echo $_list[$i]['p_no'];?>&fullpath=<?php echo $filepath?>" target="hiddenframe" class=""  style="color:#242e61">
							<?php if( strtoupper($path_parts['extension'])=="PDF" ){ ?> <img src="/image/sub/ic1.png"> <?php } ?>
						<?php
						}else{
						?>
							<a href="#none">

						<?php
						}
						?>
							<?php echo $_list[$i]['d_title']?>
							</a>
						</td>
						<td class="st2">
						<?php
						$filepath = "download/".$_list[$i]['d_no']."_s";
						if(file_exists(_PDS.$filepath) && $_list[$i]['d_file']){
							$filesize = filesize(_PDS.$filepath);
							$path_parts = pathinfo($_list[$i]['d_file']);
						?>
							<a href="/common/download.php?c_id=<?php echo $_list[$i]['c_id'];?>&p_no=<?php echo $_list[$i]['p_no'];?>&fullpath=<?php echo $filepath?>" target="hiddenframe" class=""  style="color:#242e61">
								Download <?php echo strtoupper($path_parts['extension']); ?>

								[<?php echo file_size($filesize)?>]

							</a>
						<?php
						}
						?>
						</td>
						<td nowrap><?php echo $_list[$i]['d_lang']?></td>
						<td nowrap><?php echo $_list[$i]['d_ver']?></td>
					</tr>

				<?php
					}
				}else{
				?>
					<tr>
						<td colspan="4" style="text-align:center;">
							자료가 없습니다.
						</td>
					</tr>
				<?php
				}
				?>



				</tbody>
			</table>


			<div class="paging mt50">
				<?php echo page_design2021($total,$argu['p'],preg_replace(array("/^p=(\d+)/","/&p=(\d+)/","/&p=/i","/&amp;p=(\d+)/","/&amp;p=/i"),"",$_SERVER["QUERY_STRING"]),$_LIST_NUM,$scale=10,"/image/sub/btn_first.png","/image/sub/btn_last.png","/image/sub/btn_prev.png","/image/sub/btn_next.png","N");?>
			</div>


		</div>
	</div>
</div>

<?include"../include/footer.html"?>