 <?php
  session_start(); 
  
 $level= $_SESSION["level"];
 if(!isset($_SESSION["level"]) || $level>=8) {
         echo "<script> alert('관리자 승인이 필요합니다.') </script>";
		 sleep(2);
         header ("Location:/login/logout.php");
         exit;
   }   
  
  if(isset($_REQUEST["mode"]))  //수정 버튼을 클릭해서 호출했는지 체크
   $mode=$_REQUEST["mode"];
  else
   $mode="";
  
  if(isset($_REQUEST["num"]))  //수정 버튼을 클릭해서 호출했는지 체크
   $num=$_REQUEST["num"];
  else
   $num="";

   if(isset($_REQUEST["page"]))  //수정 버튼을 클릭해서 호출했는지 체크
   $page=$_REQUEST["page"];
  else
   $page=1;   

  if(isset($_REQUEST["search"]))  //수정 버튼을 클릭해서 호출했는지 체크
   $search=$_REQUEST["search"];
  else
   $search="";
  
  if(isset($_REQUEST["find"]))  //수정 버튼을 클릭해서 호출했는지 체크
   $find=$_REQUEST["find"];
  else
   $find="";

  if(isset($_REQUEST["process"]))  //수정 버튼을 클릭해서 호출했는지 체크
   $process=$_REQUEST["process"];
  else
   $process="전체";

$fromdate=$_REQUEST["fromdate"];	 
$todate=$_REQUEST["todate"];

  if(isset($_REQUEST["regist_state"]))  // 등록하면 1로 설정 접수상태
   $regist_state=$_REQUEST["regist_state"];
  else
   $regist_state="1";

 $year=$_REQUEST["year"];   // 년도 체크박스
      
  require_once("../lib/mydb.php");
  $pdo = db_connect();

     try{
      $sql = "select * from chandj.motor where num = ? ";
      $stmh = $pdo->prepare($sql); 

      $stmh->bindValue(1,$num,PDO::PARAM_STR); 
      $stmh->execute();
      $count = $stmh->rowCount();            
	  $row = $stmh->fetch(PDO::FETCH_ASSOC);  // $row 배열로 DB 정보를 불러온다.
    if($count<1){  
      print "검색결과가 없습니다.<br>";
     }else{


 			  $con_num=$row["con_num"];
 			  $outdate=$row["outdate"];
			  $indate=$row["indate"];
			  $outworkplace=$row["outworkplace"];
			  $orderman=$row["orderman"];			  
			  $outputplace=$row["outputplace"];
			  $receiver=$row["receiver"];			  
			  $phone=$row["phone"];
			  $comment=$row["comment"];
			  $root=$row["root"];	  
			  $delivery=$row["delivery"];	 
			  $regist_state=$row["regist_state"];	 	 
			  $out_control=$row["out_control"];	 
			  $in_control=$row["in_control"];	 
			  $inbox=$row["inbox"];	 
			  $casecover=$row["casecover"];	 
			  $switchset=$row["switchset"];	 
			  $which=$row["which"];	 
			  
			  $motor220v_150k=$row["motor220v_150k"];	
			  $motor220v_300k=$row["motor220v_300k"];	
			  $motor220v_400k=$row["motor220v_400k"];	
			  $motor220v_500k=$row["motor220v_500k"];	
			  $motor220v_600k=$row["motor220v_600k"];	
			  $motor220v_800k=$row["motor220v_800k"];	
			  $motor220v_1000k=$row["motor220v_1000k"];	
			  $motor220v_1500k=$row["motor220v_1500k"];	
			  $motor220v_2000k=$row["motor220v_2000k"];	

			  $motor380v_150k=$row["motor380v_150k"];	
			  $motor380v_300k=$row["motor380v_300k"];	
			  $motor380v_400k=$row["motor380v_400k"];	
			  $motor380v_500k=$row["motor380v_500k"];	
			  $motor380v_600k=$row["motor380v_600k"];	
			  $motor380v_800k=$row["motor380v_800k"];	
			  $motor380v_1000k=$row["motor380v_1000k"];	
			  $motor380v_1500k=$row["motor380v_1500k"];	
			  $motor380v_2000k=$row["motor380v_2000k"];	
			  
			  $bracket_150k=$row["bracket_150k"];	
			  $bracket_screen300k=$row["bracket_screen300k"];	
			  $bracket_300k=$row["bracket_300k"];	
			  $bracket_500k=$row["bracket_500k"];	
			  $bracket_800k=$row["bracket_800k"];	
			  $bracket_1500k=$row["bracket_1500k"];	
			  $bracket_2000k=$row["bracket_2000k"];	  
	  
	  
			 if($indate!="0000-00-00") $indate = date("Y-m-d", strtotime( $indate) );
					else $indate="";	 
			 if($outdate!="0000-00-00") $outdate = date("Y-m-d", strtotime( $outdate) );
					else $outdate="";	 					
			  
      }
     }catch (PDOException $Exception) {
       print "오류: ".$Exception->getMessage();
     }


?>

   <!DOCTYPE HTML>
   <html>
   <head> 
   <title> 주일기업 통합정보시스템 </title>
   <meta charset="utf-8">
   <link  rel="stylesheet" type="text/css" href="../css/common.css"> 
   <link  rel="stylesheet" type="text/css" href="../css/motor.css"> 
   <link  rel="stylesheet" type="text/css" href="../css/radio.css"> 
   </head>
 
   <body>

	<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
    <script src="/order/order.js"></script>
   
   <div id="wrap">
	   <?php
    if($mode=="modify"){
  ?>
	<form  name="board_form" method="post" onkeydown="return captureReturnKey(event)"  action="insert.php?mode=modify&num=<?=$num?>&page=<?=$page?>&search=<?=$search?>&find=<?=$find?>&year=<?=$year?>&search=<?=$search?>&process=<?=$process?>&asprocess=<?=$asprocess?>&fromdate=<?=$fromdate?>&todate=<?=$todate?>&separate_date=<?=$separate_date?>" > 
  <?php  } else {
  ?>
	<form  name="board_form" method="post" onkeydown="return captureReturnKey(event)" action="insert.php?mode=not&search=<?=$search?>&find=<?=$find?>&page=<?=$page?>&year=<?=$year?>&search=<?=$search?>&process=<?=$process?>&asprocess=<?=$asprocess?>&fromdate=<?=$fromdate?>&todate=<?=$todate?>&separate_date=<?=$separate_date?>"> 
  <?php
	}
  ?>	   
   <div id="header">
   <?php include "../lib/top_login2.php"; ?>
   </div>  
   <div id="menu">
   <?php include "../lib/top_menu2.php"; ?>
    </div>  
    <div id="content">
    <br><br>
     <div id="work_col3"> <div id=top_title > <h3> &nbsp; &nbsp; 모터 입출고 조회 화면 </h3> </div>
  	
	      <div class="clear"></div>	
	 <div id="sero1"> 입출고일 :  </div>	 
	 <div id="sero2"> <input type="date" id="outdate" name="outdate" value="<?=$outdate?>" size="14" placeholder="출 고 일" disabled > </div> 

	 <div id="sero3"> 접 수 일 :  </div>
	 <div id="sero4"> <input type="date" id="indate" name="indate" value="<?=$indate?>" size="14" placeholder="접수일" disabled> </div> 
	      <div class="clear"></div>	
		  
   <div id="sero_new1"> &nbsp; &nbsp;   회사구분 :  &nbsp; &nbsp; </div> 
   
	 <div id="sero_new2"> 
	  <?php
	    if($root==Null) 			 
			$root="주일";
			   ?>	  
	 <?php
	    if($root=="주일") {
			 ?>
			주일               <input type="radio" checked name=root id=root value="주일" disabled >
			&nbsp;   경동<input type="radio" name=root  id=root value="경동"  disabled>	  
			<?php
             		}    ?>
	 <?php
	    if($root=="경동") {
			 ?>
			주일               <input type="radio"  name=root id=root value="주일" disabled >
			&nbsp;   경동<input type="radio" checked name=root id=root value="경동" disabled >	  
			<?php
             		}    ?>					
	              </div>

	 <div id="sero3_1"> 현 장 명 :  </div>
	 <div id="sero5"> <input type="text" id="outworkplace" name="outworkplace" onkeydown="JavaScript:Enter_Check();" value="<?=$outworkplace?>" size="40" placeholder="주일은 현장명 경동은 업체명" disabled> 	 
     <button type="button" id="searchplace" class="button button2" > 검색 </button> 	 	 
	 </div> <div id="sero555" style="color:red"> (주일/경동 선택 후 주일공사 현장 또는 경동 발주처 현장명) </div>
	 <div id="displaysearch" style="display:none"> 
	 
	 </div>	 
     <div class="clear"></div>	 
	 
	 <input type="hidden" id="con_num" name="con_num" value="<?=$con_num?>" >

	 <div id="sero31"> 발주자 :  </div>	 
	 <div id="sero6"> <input type="text"  id="orderman" name="orderman" value="<?=$orderman?>" size="14" placeholder="발주자(주일/경동 직원)" disabled> </div> 
    
	 <div id="sero32"> 수신처(작업반장 or 업체) :  </div>	 
	 <div id="sero7"> <input type="text" id="receiver"  name="receiver" value="<?=$receiver?>" size="20" placeholder="수신처 (작업반장 or 업체)" onkeydown="JavaScript:Enter_CheckTel();" disabled> 
     <button type="button" id="searchtel" class="button button2" > 전화번호검색 </button> 	 	 	 
	 </div>      
	 
	 <div id="displaysearchworker" style="display:none"> 	 
	 </div>	 
	 <div class="clear"></div>
	 <div id="sero3_5"> 수신처주소 :  </div>
	 <div id="sero8"> <input type="text" id="outputplace" name="outputplace" value="<?=$outputplace?>" size="60" placeholder="현장주소 또는 납품처 주소 or 화물 영업소" disabled> </div> 
	  
	 <div id="sero3_2"> 연락처 : </div>
	 <div id="sero9"> <input type="text" id="phone" name="phone" value="<?=$phone?>" size="20" placeholder="작업반장 또는 업체 연락처" disabled> </div> 
     <div class="clear"></div>
	 <div id="sero3"> 비 고 :  </div>
	 <div id="sero100"> <textarea rows="1" cols="54" name="comment" placeholder="코멘트 남겨주세요." disabled
                ><?=$item_comment?></textarea></div>
     <div class="clear"></div>    

  	 <div id="order15">  </div>	 
	 
	 <div id="sero1000"> <h2> 발주사항(입출고 현황) </h2></div>
     <div class="clear"></div>   
	 
 <?php	 
	 //   if($_SESSION["name"] =="김보곤" && $regist_state=="1") 	 // 김보곤일때는 접수로 자동 체크
	 //      $regist_state="2";
		  
	 		 $aryreg=array();
	     switch ($which) {
			case   "1"             : $aryreg[0] = "checked" ; break;
			case   "2"             :$aryreg[1] =  "checked" ; break;
			default: break;
		}		 
			
		 if($_SESSION["name"] =="김보곤"||$_SESSION["name"] =="황규선"||$_SESSION["name"] =="서재호"||$_SESSION["name"] =="노영재") 	 
		 {	 
	   ?>
	   	   <div id="which">   
	            <div id="which_1">  구분 :  </div>   <div id=which_a > 입고        <input  type="radio" <?=$aryreg[0]?> name=which value="1" disabled> </div>  
			    &nbsp;   <div id=which_b > 출고         <input  type="radio" <?=$aryreg[1]?>  name=which value="2" disabled>  </div>  
	         </div>  
	 <?php
		 }
		 ?>
     <div class="clear"></div> 		   
<div id=display_board class=background name=display_board > 
 <div id="list_search">
        <div id="list_search1"> </div>
        <div id="list_search1_1"> 			 
       </div>		
       
        <div id="list_search5"></div>

      </div> <!-- end of list_search -->
 
	<!--  <div id="sero1000"> <h3> 경동모터 전체 재고현황 </h3></div>  -->

     

     <div class="clear"></div>		 
	 	<!--   <div id="order11"> 수량 : </div>	   -->
 <div id="order2">
   <input type="text" id=motor220v_150k name=motor220v_150k value="<?=$motor220v_150k?>" size="6" disabled   >
   <input type="text" id=motor220v_300k name=motor220v_300k value="<?=$motor220v_300k?>" size="6" disabled   >
   <input type="text" id=motor220v_400k name=motor220v_400k value="<?=$motor220v_400k?>" size="6" disabled   >
   <input type="text" id=motor220v_500k name=motor220v_500k value="<?=$motor220v_500k?>" size="6" disabled   >
   <input type="text" id=motor220v_600k name=motor220v_600k value="<?=$motor220v_600k?>" size="6" disabled   >
   <input type="text" id=motor220v_800k name=motor220v_800k value="<?=$motor220v_800k?>" size="6" disabled   >
   <input type="text" id=motor220v_1000k name=motor220v_1000k value="<?=$motor220v_1000k?>" size="6" disabled   >
   <input type="text" id=motor220v_1500k name=motor220v_1500k value="<?=$motor220v_1500k?>" size="6" disabled   >
   <input type="text" id=motor220v_2000k name=motor220v_2000k value="<?=$motor220v_2000k?>" size="6" disabled   >	 
 
	 </div>	 		 
   <div class="clear"></div>	

     <div class="clear"></div>		
	<!--   <div id="order11"> 수량 : </div> -->
  <div id="order2">
   <input type="text" id=motor380v_150k name=motor380v_150k value="<?=$motor380v_150k?>" size="6" disabled   >
   <input type="text" id=motor380v_300k name=motor380v_300k value="<?=$motor380v_300k?>" size="6" disabled   >
   <input type="text" id=motor380v_400k name=motor380v_400k value="<?=$motor380v_400k?>" size="6" disabled   >
   <input type="text" id=motor380v_500k name=motor380v_500k value="<?=$motor380v_500k?>" size="6" disabled   >
   <input type="text" id=motor380v_600k name=motor380v_600k value="<?=$motor380v_600k?>" size="6" disabled   >
   <input type="text" id=motor380v_800k name=motor380v_800k value="<?=$motor380v_800k?>" size="6" disabled   >
   <input type="text" id=motor380v_1000k name=motor380v_1000k value="<?=$motor380v_1000k?>" size="6" disabled   >
   <input type="text" id=motor380v_1500k name=motor380v_1500k value="<?=$motor380v_1500k?>" size="6" disabled  >
   <input type="text" id=motor380v_2000k name=motor380v_2000k value="<?=$motor380v_2000k?>" size="6" disabled   >	 		
  
	 </div> 

     <div class="clear"></div>
   	<!-- 	 
 <div id="order5"> 브라켓(Bracket) :  </div>	
 <div id="order14">  스크린150K </div>
 <div id="order14">  스크린300~400K </div>
 <div id="order14">  일반300~400K </div>
 <div id="order14">  일반500~600K </div>
 <div id="order14">  일반800~1000K </div>
 <div id="order14">  일반1500K </div>
 <div id="order14">  일반2000K </div> -->

    <div class="clear"></div>	 
   	<!--   <div id="order5"> 수량 :  </div>		 --> 	 
   <div id="order2">
   <input type="text" id=bracket_150k name=bracket_150k value="<?=$bracket_150k?>" size="6" disabled   >
   <input type="text" id=bracket_screen300k name=bracket_screen300k value="<?=$bracket_screen300k?>" size="6" disabled   >
   <input type="text" id=bracket_300k name=bracket_300k value="<?=$bracket_300k?>" size="6" disabled   >
   <input type="text" id=bracket_500k name=bracket_500k value="<?=$bracket_500k?>" size="6" disabled   >
   <input type="text" id=bracket_800k name=bracket_800k value="<?=$bracket_800k?>" size="6" disabled   >
   <input type="text" id=bracket_1500k name=bracket_1500k value="<?=$bracket_1500k?>" size="6" disabled   >
   <input type="text" id=bracket_2000k name=bracket_2000k value="<?=$bracket_2000k?>" size="6" disabled   >
	 </div> 
   	<!--  	 <div id="order15">  </div>	   --> 				  
	 <div class="clear"></div> 
   	<!-- 	 <div id="order5">  노출제어기 :  </div>	  --> 
	 <div id="order6_1">  <input type="text" id="out_control" name="out_control" class=textalign value="<?=$out_control?>" size="6" disabled  > </div>  
	   	<!--  <div id="order5">  매립제어기 :  </div>	 -->  
	 <div id="order6_1">  <input type="text" id="in_control" name="in_control" class=textalign value="<?=$in_control?>" size="6" disabled   > </div>  
 
	   	<!-- <div id="order5">  방범스위치 :  </div>	 -->  
	 <div id="order6_1">  <input type="text" id="switchset" name="switchset"  class=textalign value="<?=$switchset?>" size="6" disabled  > </div>  
	   	<!-- <div id="order9">  방범스위치 케이스 :  </div>	  --> 
	 <div id="order10">  <input type="text" id="casecover" name="casecover"  class=textalign value="<?=$casecover?>" size="6" disabled  > </div>  
	   	<!-- <div id="order5">  뒷박스 :  </div>	 -->  
	 <div id="order6_1">  <input type="text" id="inbox" name="inbox"  class=textalign value="<?=$inbox?>" size="6" disabled  > </div>    	 
	<div class="clear"></div> 	 
   
   </div>  
	<div class="clear"></div> 	 
	 
<br><br><br><br><br>
  <div id="write_button_renew2">    
						   <a href="list.php?&mode=search&page=<?=$page?>&search=<?=$search?>&find=<?=$find?>&list=1&asprocess=<?=$asprocess?>&year=<?=$year?>&fromdate=<?=$fromdate?>&todate=<?=$todate?>&separate_date=<?=$separate_date?>"> <img src="../img/list.png"></a>&nbsp;   

						<a href="write_form.php?mode=modify&num=<?=$num?>&page=<?=$page?>&search=<?=$search?>&find=<?=$find?>&year=<?=$year?>&search=<?=$search?>&process=<?=$process?>&asprocess=<?=$asprocess?>&fromdate=<?=$fromdate?>&todate=<?=$todate?>&separate_date=<?=$separate_date?>"><img src="../img/modify.png"></a>&nbsp;
						<a href="javascript:del('delete.php?num=<?=$num?>&page=<?=$page?>')"><img src="../img/delete.png"></a>&nbsp;

						<a href="write_form.php"><img src="../img/write.png"></a>&nbsp;
						 
						</div>	
	 
	  </div> 
	   </div>  
		
	</form>
 </div>

<script>
$(function () {
            $("fromdate").datepicker({ dateFormat: 'yy-mm-dd'});
            $("#todate").datepicker({ dateFormat: 'yy-mm-dd'});
			
});

    function inputNumberFormat(obj) { 
    obj.value = comma(uncomma(obj.value)); 
} 
function comma(str) { 
    str = String(str); 
    return str.replace(/(\d)(?=(?:\d{3})+(?!\d))/g, '$1,'); 
} 
function uncomma(str) { 
    str = String(str); 
    return str.replace(/[^\d]+/g, ''); 
}


function date_mask(formd, textid) {

/*
input onkeyup에서
formd == this.form.name
textid == this.name
*/

var form = eval("document."+formd);
var text = eval("form."+textid);

var textlength = text.value.length;

if (textlength == 4) {
text.value = text.value + "-";
} else if (textlength == 7) {
text.value = text.value + "-";
} else if (textlength > 9) {
//날짜 수동 입력 Validation 체크
var chk_date = checkdate(text);

if (chk_date == false) {
return;
}
}
}
function del(href) 
     {
        if(confirm("한번 삭제한 자료는 복구할 방법이 없습니다.\n\n정말 삭제하시겠습니까?")) {
           document.location.href = href;
          }
     }
function checkdate(input) {
   var validformat = /^\d{4}\-\d{2}\-\d{2}$/; //Basic check for format validity 
   var returnval = false;

   if (!validformat.test(input.value)) {
    alert("날짜 형식이 올바르지 않습니다. YYYY-MM-DD");
   } else { //Detailed check for valid date ranges 
    var yearfield = input.value.split("-")[0];
    var monthfield = input.value.split("-")[1];
    var dayfield = input.value.split("-")[2];
    var dayobj = new Date(yearfield, monthfield - 1, dayfield);
   }

   if ((dayobj.getMonth() + 1 != monthfield)
     || (dayobj.getDate() != dayfield)
     || (dayobj.getFullYear() != yearfield)) {
    alert("날짜 형식이 올바르지 않습니다. YYYY-MM-DD");
   } else {
    //alert ('Correct date'); 
    returnval = true;
   }
   if (returnval == false) {
    input.select();
   }
   return returnval;
  }
  
function input_Text(){
    document.getElementById("test").value = comma(Math.floor(uncomma(document.getElementById("test").value)*1.1));   // 콤마를 계산해 주고 다시 붙여주고
  var copyText = document.getElementById("test");   // 클립보드 복사 
  copyText.select();
  document.execCommand("Copy");
}  

function captureReturnKey(e) {
    if(e.keyCode==13 && e.srcElement.type != 'textarea')
    return false;
}

function recaptureReturnKey(e) {
    if (e.keyCode==13)
        exe_search();
}
function Enter_Check(){
        // 엔터키의 코드는 13입니다.
    if(event.keyCode == 13){
      exe_search();  // 실행할 이벤트
    }
}
function Enter_CheckTel(){
        // 엔터키의 코드는 13입니다.
    if(event.keyCode == 13){
      exe_searchTel();  // 실행할 이벤트
    }
}

/* function exe_search()
{
	  var ua = window.navigator.userAgent;
      var postData; 	 
	  var text1= document.getElementById("outworkplace").value;
	
	     if (ua.indexOf('MSIE') > 0 || ua.indexOf('Trident') > 0) {
                postData = encodeURI(text1);
            } else {
                postData = text1;
            }

      $("#displaysearch").show();
      $("#displaysearch").load("./search.php?mode=search&search=" + postData);
} */

function exe_search()
{
      var postData = changeUri(document.getElementById("outworkplace").value);
      var sendData = $(":input:radio[name=root]:checked").val();

      $("#displaysearch").show();
	 if(sendData=='주일')
         $("#displaysearch").load("./search.php?mode=search&search=" + postData);
	 if(sendData=='경동') 
         $("#displaysearch").load("./searchkd.php?mode=search&search=" + postData);	  
}
function exe_searchTel()
{
	  var postData =  changeUri(document.getElementById("receiver").value);
      $("#displaysearchworker").show();
      $("#displaysearchworker").load("./workerlist.php?mode=search&search=" + postData);
}
</script> 
	</body>
 </html>
