<!------------------------------------------
 #프로그램명	: 사용자>제품정보>MSDS검색
 #날     짜	: 2019-02-25
 #업  체  명	: 컨설트인사이드
 #담  당  자	: 최재원(kkggan3@daum.net)
 #홈페이지주소	: http://www.duksan.kr
 #화면의 용도	: 검색어를 입력 받으면 해당 검색어로 조회한 리스트를 뿌려주고, 검색어가 없는 첫 화면은 각 업체의 MSDS 조회 페이지를 안내하는 페이지
 #수 정 사 항	: (2019-03-04::최재원) 영문페이지(/en/page/03/msds.php)의 경우 영문자료만 리스트에 보이도록 내용 수정
                  2019-03-06:김연수 : 조회조건을 duksan_TDAMSDSItem, MSDSItemName으로 변경.  
				  2020-01-21:김연수 : 영문msds, 혼합물msds PDF내려받는 로직 추가
------------------------------------------->

<?php

/** (M)SDS 검색 리스트 페이지 **/

    include $_SERVER["DOCUMENT_ROOT"]."/include/header.php";
    $msds = new Msds\Msds_Class();
?>

<style>
    .contents table, th, td {
        border:none
    }
</style>
	<div class="contents" id="msds" style="margin-top:160px">
	
		<div class="visual">
			<!-- 
			<div class="title_box wrapper">
				<p class="s_tit">PRODUCTS INFORMATION</p>
				<p class="b_tit">제품 정보</p>
				<p class="prev_Btn"><a href="product.php"><img src="../../images/sub/prev_arrow.png" alt="이전단계"></a></p>
        		<p class="next_Btn"><a href="report.php"><img src="../../images/sub/next_arrow.png" alt="다음단계"></a></p>
			</div>
			 -->
			
			<ul  class="s_menu">
				<li><a href="/page/03/product.php">제품 검색</a></li>
    			<li class="on"><a href="/page/03/msds.php">(M)SDS 검색</a></li>
    			<li><a href="/page/03/report.php">성적서 검색</a></li>
    			<li><a href="/page/03/specificatio.php">규격서 검색</a></li>
			</ul>
			
		</div>	
		
		<!-- 푸른 띠 내비게이션 부분 -->
		<div class="search_result">
           <p><img src="../../images/sub/home.png" alt="홈" > &nbsp; > &nbsp; 제품 정보 &nbsp; > &nbsp; <span>(M)SDS 검색</span></p>   
		</div>
			
		<p class="ps wrapper"><span><b style="color:red; opacity:0.7">* </b>상품의 제조사를 확인하신 후 이용해 주시길 바랍니다.</span></p>

        <h2><img src="../../images/sub/sub3_tit2.png" alt="MSDS 검색" style="padding-bottom:13px;"></h2>

		<!-- 검색 -->
		<form name="frm" id="frm" action="" method="get">
			<div class="search_frm">
				<div>
					<img src="../../images/sub/duksan.png" alt="덕산" style="padding-left:68px; position: relative; top: 15px;">
					<select name="s_type" id="s_type">
						<option value="B.MSDSItemName" <?php echo ($_GET[s_type] == "B.MSDSItemName") ? "selected" : ""; ?>>명칭</option>
						<!--<option value="item_code" <?php echo ($_GET[s_type] == "item_code") ? "selected" : ""; ?>>제품번호</option>-->
						<option value="A.msds_prod1_Cas" <?php echo ($_GET[s_type] == "A.msds_prod1_Cas") ? "selected" : ""; ?>>CAS No.</option>
					</select>
					<input type="text" name="keyword" id="keyword" value="<?php echo $keyword; ?>" />
					<button class="search_btn">SEARCH</button>
				</div>
				<a href="/page/02/view.php?bo_idx=619&bo_category=notice&page=" target= "_blank" style="underline"> &nbsp; &nbsp; <u>PDF파일로 출력하는 방법 </u></a>
			</div>	
		</form>
		<!-- End // 검색 -->
		
		<!-- 리스트 = 검색 키워드가 존재하는 경우 -->
		<?php if($keyword) { ?>
		<table class="brand_table">
		
			<colgroup>
				<col style="width: 10%;">
				<col style="width: 40%;">
				<col style="width: 40%;">
				<col style="width: 10%;">
			</colgroup>
			
			<tr>
				<th>Cas No.</th>
				<th>제품명 (영문)</th>
				<th>제품명 (한글)</th>
				<th>Print</th>
			</tr>
			
			<?php 
			
			$index = 0;
			
		    $res = $msds->msds_search($conn, $_GET[s_type], $_GET[keyword]);
		    while ($row = sqlsrv_fetch_array($res)) {
			/** 
				MSDS_PROD1_CAS : CAS No. 
				MSDSItemName : MSDS명 구)190306이전 msds_1prod : 품명(ENG)
				msds_prod1_hform : 품명(KOR)
				MSDSSeq : MSDS 문서 조회용 시퀀스
			**/
		    ?>
			<tr>
				<td><?php echo $row[MSDS_PROD1_CAS] != "" ? $row[MSDS_PROD1_CAS] : "-"?></td>
				<td><?php echo $row[MSDSItemName] != "" ? $row[MSDSItemName] : "-"?></td>
				<td><?php echo $row[msds_prod1_hform] != "" ? $row[msds_prod1_hform] : "-"?></td>
				<td>
			<?php //혼합물 로직 삽입20200120
				$msds_mixed = "../../uploads/msds_mixed/".$row[MSDSItemName]."_mixed.pdf";			
				if(file_exists($msds_mixed) == false) {?>			
				<img src="../../images/sub/print.png" alt="인쇄" onclick="mdsd_popup('<?php echo $row[MSDSSeq]?>')" style="cursor:pointer;">
				<?php } else { ?>	
				<a href="<?php echo $msds_mixed; ?>" target="_blank"><img src="../../images/sub/print.png"></a>
			<?php } ?>				

			<?php 
			    //pdf용 20200526 김계장
				//$msds_sql = "SELECT TOP 1 MSDSItemSeq FROM duksan_TDAMSDS WHERE MSDSSeq = '{$row[MSDSSeq]}' AND SMLanKind = 1000764001";
				//$result_R = sqlsrv_fetch_array(sqlsrv_query($conn, $msds_sql));
				//$PDF_MSDSItemSeq = $result_R["MSDSItemSeq"];
				
				$dir = opendir("../../uploads/msds_eng/"); //파일 디렉토리 경로
				$file_now; //원래의 파일명

				while (($file = readdir($dir)) !== false)
				{
					$file_now = $file; //파일명 저장(다음 프로세스에서 그대로 실행하기 위해 변수에 저장)
					$file = substr($file, 0, stripos($file, "e_")); //stripos "e_"의 길이 가져오고, substr은 길이만큼 잘라서 가져옴.
					
					if($file == $row[MSDSItemSeq]) //파일명과 msds아이템시퀀스가 동일하면
					{
						if($file_now > 0) //파일명이 비어있지 않다면
						{
							$file_now = "../../uploads/msds_eng/".$file_now;
							if(file_exists($file_now) == true) {?>
							<a href="<?php echo $file_now; ?>" target="_blank"><img src="../../images/sub/print_e.png"></a>
							<?php }	
							
							break;
						}
					}
				}
				closedir($dir);
				
				//구로직
				/*
				//영문msds로직 삽입20200120
				$msds_eng = "../../uploads/msds_eng/".$row[MSDSItemName]."_Eng.pdf";
				if(file_exists($msds_eng) == true) {?>
				<!--<img src="../../images/sub/print_e.png" alt="인쇄" onclick="mdsd_popup_e('<?php //echo $row[MSDSSeq]?>')" style="cursor:pointer;"></td>-->
				<a href="<?php echo $msds_eng; ?>" target="_blank"><img src="../../images/sub/print_e.png"></a>
				<?php }
				*/
			?>
				</td>
			</tr>
		<?php $index++; } ?>
		<?php if($index == 0) { ?>
			<tr>
				<td colspan="4">
					<div class="empty_board">
						<p>검색 결과가 없습니다.</p>
					</div>
				</td>
			</tr>
		<?php } ?>
		</table>
		<?php } ?>
		<!-- End // 리스트 = 검색 키워드가 존재하는 경우 -->
			
        <!-- 제조사 리스트 = 검색 키워드가 없는 경우 -->
        <?php if($keyword == "") { ?>
		  <div class="brand">
            <ul>
               <li>
			       <p><img src="../../images/brand/jk_logo.png" alt="jk scientific"></p>
				   <a href="https://www.jk-scientific.com/Search?type=document" target="_blank"><button class="brand1">바로 가기</button></a>
			   </li>
			   <li>
			       <p><img src="../../images/brand/merck_logo.png" alt="merck"></p>
				    <a href="https://www.sigmaaldrich.com/catalog/AdvancedSearchPage.do" target="_blank"><button class="brand2">바로 가기</button></a>
			   </li>
			   <li>
			       <p><img src="../../images/brand/kirsch_pharma_logo.png" alt="kirsch_pharma" style="position:relative; top:40px"></p>
				    <!--a href="https://www.fishersci.com/us/en/catalog/search/sdshome.html" target="_blank"><button class="brand6">바로 가기</button></a-->
					<p style="margin:28px auto; width: 140px; height: 40px;">&nbsp;</p>
			   </li>

			   <li>
			       <p><img src="../../images/brand/cfl_logo.png" alt="cfl" style="position:relative; top:40px"></p>
				    <!--a href="https://www.fishersci.com/us/en/catalog/search/sdshome.html" target="_blank"><button class="brand6">바로 가기</button></a-->
					<p style="margin:28px auto; width: 140px; height: 40px;">&nbsp;</p>
			   </li>
			   <li>
			       <p><img src="../../images/brand/PanReac_logo.png" alt="PabReac"></p>
				    <a href="https://www.itwreagents.com/rest-of-world/en/home-rw" target="_blank"><button class="brand8">바로 가기</button></a>
			   </li>
			   <li>
			       <p><img src="../../images/brand/SRL_logo.png" alt="srl"></p>
				    <a href="http://www.srlchem.com/products/coa_msds.php" target="_blank"><button class="brand7">바로 가기</button></a>
			   </li>				   
			   				   				   
			   <!-- 
			   <li>
			       <p><img src="../../images/brand/mpbio_logo.png" alt="mpbio"></p>
				    <a href="https://www.mpbio.com/advanced_search.php" target="_blank"><button class="brand3">바로 가기</button></a>
			   </li>
			    -->
			   <li>
			       <p><img src="../../images/brand/jinsel_logo.png" alt="jinsel"></p>
				    <a href="https://www.junsei.co.jp/productsearch/search_e.asp" target="_blank"><button class="brand7">바로 가기</button></a>
			   </li>				    
			   <li>
			       <p><img src="../../images/brand/acros_logo.png" alt="acros"></p>
				    <a href="https://www.acros.com/portal/alias__Rainbow/lang__en/tabID__41/DesktopDefault.aspx" target="_blank"><button class="brand4">바로 가기</button></a>
			   </li>

			   <li>
			       <p><img src="../../images/brand/alfa_logo.png" alt="alfa aesar"></p>
				    <a href="http://www.alfa.co.kr/AlfaAesarApp/faces/adf.task-flow?adf.tfId=ProductSearchTF&adf.tfDoc=/WEB-INF/ProductSearchTF.xml&_afrLoop=2220490051442253&_afrWindowMode=0&_adf.ctrl-state=u0ilggrg8_4" target="_blank"><button class="brand5">바로 가기</button></a>
			   </li>
			   
			   <li>
			       <p><img src="../../images/brand/fisher_logo.png" alt="fisher"></p>
				    <a href="https://www.fishersci.com/us/en/catalog/search/sdshome.html" target="_blank"><button class="brand6">바로 가기</button></a>
			   </li>
				<li>
			       <p><img src="../../images/brand/J.T_Baker_logo.png" alt="Avantor"></p>
				    <a href="https://www.avantorinc.com/search.aspx?searchtype=msds" target="_blank"><button class="brand9">바로 가기</button></a>
			   </li>
            </ul>
		</div>
		<?php } ?>
	</div>
	
<!-- top_btn -->
<?php include $_SERVER["DOCUMENT_ROOT"]."/include/top.php" ?>
	
<!-- footer -->
<?php include $_SERVER["DOCUMENT_ROOT"]."/include/footer.php" ?> 
	
	
<script type="text/javascript">
	function mdsd_popup(v) {

		var code = v;

		var option= "resizable=no, scrollbars=yes, status=no,width=800, height=980";
		window.open("msds_erpcheck.php" , "msds", option);
		
		var form = document.createElement("form");
		form.setAttribute("method", "POST");
		form.setAttribute("name", "msds_frm");
		form.setAttribute("id", "msds_frm");
		form.setAttribute("action", "msds_erpcheck.php");
		form.setAttribute("target", "msds");

		var msds_code = document.createElement("input");
		msds_code.setAttribute("type", "hidden");
		msds_code.setAttribute("name", "msds_code");
		msds_code.setAttribute("value", code);
		form.appendChild(msds_code);
		document.body.appendChild(form);
		form.submit();

		$("#msds_frm").remove();;
	}
	
		function mdsd_popup_e(v) {

		var code = v;

		var option= "resizable=no, scrollbars=yes, status=no,width=800, height=980";
		window.open("msds_erpcheck_e.php" , "msds", option);
		
		var form = document.createElement("form");
		form.setAttribute("method", "POST");
		form.setAttribute("name", "msds_frm");
		form.setAttribute("id", "msds_frm");
		form.setAttribute("action", "msds_erpcheck.php");
		form.setAttribute("target", "msds");

		var msds_code = document.createElement("input");
		msds_code.setAttribute("type", "hidden");
		msds_code.setAttribute("name", "msds_code");
		msds_code.setAttribute("value", code);
		form.appendChild(msds_code);
		document.body.appendChild(form);
		form.submit();

		$("#msds_frm").remove();;
	}
	
</script>
		
