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

if((int)$num>=1)
 {
  require_once("../lib/mydb.php");
  $pdo = db_connect();
											  
								 try{  
							  $sql = "select * from chandj.atbending where num = ? ";
							  $stmh = $pdo->prepare($sql); 

							  $stmh->bindValue(1,$num,PDO::PARAM_STR); 
							  $stmh->execute();
							  $counter = $stmh->rowCount();            
							  $row = $stmh->fetch(PDO::FETCH_ASSOC);  // $row 배열로 DB 정보를 불러온다.

	                              if($counter>=1) {
									  	 $mode="modify";  //수정모드로 전환
										 $num=$row["num"];
										// print "번호를 찾았습니다.<br>" . $num;
								  }
									      
							  } catch (PDOException $Exception) {
							  print "오류: ".$Exception->getMessage();
							  }  
 }				  
	  else
	  {
				  if(isset($_REQUEST["num"]))  //수정 버튼을 클릭해서 호출했는지 체크 출고현황에서 부르지 않았을때 
				   $num=$_REQUEST["num"];
				  else
				       $num=0;
  
	  }


   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="전체";

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

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

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

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

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

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

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

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

  if(isset($_REQUEST["item_comment"]))  
   $item_comment=$_REQUEST["item_comment"];
  else
   $item_comment="";

  if(isset($_REQUEST["delivery"])) 
   $item_delivery=$_REQUEST["delivery"];
  else
   $item_delivery="";

$modify="0";  // 정렬모드 초기화

$fromdate=$_REQUEST["fromdate"];	 
$todate=$_REQUEST["todate"];
$outputnumint=(int)$outputnum;
     
  require_once("../lib/mydb.php");
  $pdo = db_connect();

  if ($mode=="modify"){
    try{
      $sql = "select * from chandj.atbending 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{


$steeltype=$row["steeltype"];
$steel_alias=$row["steel_alias"];	
$copy_steeltype=$row["steeltype"];
	  
$copied_file_name=$row["copied_file_name"]; 
$uploaded_file=$row["uploaded_file"]; 


$a1=$row["a1"];
$a2=$row["a2"];
$a3=$row["a3"];
$a4=$row["a4"];
$a5=$row["a5"];
$a6=$row["a6"];
$a7=$row["a7"];
$a8=$row["a8"];
$a9=$row["a9"];
$a10=$row["a10"];
$a11=$row["a11"];
$a12=$row["a12"];
$a13=$row["a13"];
$a14=$row["a14"];
$a15=$row["a15"];
$a16=$row["a16"];
$a17=$row["a17"];
$a18=$row["a18"];
$a19=$row["a19"];
$a20=$row["a20"];
$a21=$row["a21"];
$a22=$row["a22"];
$a23=$row["a23"];
$a24=$row["a24"];
$a25=$row["a25"];
$b1=$row["b1"];
$b2=$row["b2"];
$b3=$row["b3"];
$b4=$row["b4"];
$b5=$row["b5"];
$b6=$row["b6"];
$b7=$row["b7"];
$b8=$row["b8"];
$b9=$row["b9"];
$b10=$row["b10"];
$b11=$row["b11"];
$b12=$row["b12"];
$b13=$row["b13"];
$b14=$row["b14"];
$b15=$row["b15"];
$b16=$row["b16"];
$b17=$row["b17"];
$b18=$row["b18"];
$b19=$row["b19"];
$b20=$row["b20"];
$b21=$row["b21"];
$b22=$row["b22"];
$b23=$row["b23"];
$b24=$row["b24"];
$b25=$row["b25"];
$c1=$row["c1"];
$c2=$row["c2"];
$c3=$row["c3"];
$c4=$row["c4"];
$c5=$row["c5"];
$c6=$row["c6"];
$c7=$row["c7"];
$c8=$row["c8"];
$c9=$row["c9"];
$c10=$row["c10"];
$c11=$row["c11"];
$c12=$row["c12"];
$c13=$row["c13"];
$c14=$row["c14"];
$c15=$row["c15"];
$c16=$row["c16"];
$c17=$row["c17"];
$c18=$row["c18"];
$c19=$row["c19"];
$c20=$row["c20"];
$c21=$row["c21"];
$c22=$row["c22"];
$c23=$row["c23"];
$c24=$row["c24"];
$c25=$row["c25"];
$d1=$row["d1"];
$d2=$row["d2"];
$d3=$row["d3"];
$d4=$row["d4"];
$d5=$row["d5"];
$d6=$row["d6"];
$d7=$row["d7"];
$d8=$row["d8"];
$d9=$row["d9"];
$d10=$row["d10"];
$d11=$row["d11"];
$d12=$row["d12"];
$d13=$row["d13"];
$d14=$row["d14"];
$d15=$row["d15"];
$d16=$row["d16"];
$d17=$row["d17"];
$d18=$row["d18"];
$d19=$row["d19"];
$d20=$row["d20"];
$d21=$row["d21"];
$d22=$row["d22"];
$d23=$row["d23"];
$d24=$row["d24"];
$d25=$row["d25"];
$e1=$row["e1"];
$e2=$row["e2"];
$e3=$row["e3"];
$e4=$row["e4"];
$e5=$row["e5"];
$e6=$row["e6"];
$e7=$row["e7"];
$e8=$row["e8"];
$e9=$row["e9"];
$e10=$row["e10"];
$e11=$row["e11"];
$e12=$row["e12"];
$e13=$row["e13"];
$e14=$row["e14"];
$e15=$row["e15"];
$e16=$row["e16"];
$e17=$row["e17"];
$e18=$row["e18"];
$e19=$row["e19"];
$e20=$row["e20"];
$e21=$row["e21"];
$e22=$row["e22"];
$e23=$row["e23"];
$e24=$row["e24"];
$e25=$row["e25"];
$f1=$row["f1"];
$f2=$row["f2"];
$f3=$row["f3"];
$f4=$row["f4"];
$f5=$row["f5"];
$f6=$row["f6"];
$f7=$row["f7"];
$f8=$row["f8"];
$f9=$row["f9"];
$f10=$row["f10"];
$f11=$row["f11"];
$f12=$row["f12"];
$f13=$row["f13"];
$f14=$row["f14"];
$f15=$row["f15"];
$f16=$row["f16"];
$f17=$row["f17"];
$f18=$row["f18"];
$f19=$row["f19"];
$f20=$row["f20"];
$f21=$row["f21"];
$f22=$row["f22"];
$f23=$row["f23"];
$f24=$row["f24"];
$f25=$row["f25"];
$g1=$row["g1"];
$g2=$row["g2"];
$g3=$row["g3"];
$g4=$row["g4"];
$g5=$row["g5"];
$g6=$row["g6"];
$g7=$row["g7"];
$g8=$row["g8"];
$g9=$row["g9"];
$g10=$row["g10"];
$g11=$row["g11"];
$g12=$row["g12"];
$g13=$row["g13"];
$g14=$row["g14"];
$g15=$row["g15"];
$g16=$row["g16"];
$g17=$row["g17"];
$g18=$row["g18"];
$g19=$row["g19"];
$g20=$row["g20"];
$g21=$row["g21"];
$g22=$row["g22"];
$g23=$row["g23"];
$g24=$row["g24"];
$g25=$row["g25"];
$h1=$row["h1"];
$h2=$row["h2"];
$h3=$row["h3"];
$h4=$row["h4"];
$h5=$row["h5"];
$h6=$row["h6"];
$h7=$row["h7"];
$h8=$row["h8"];
$h9=$row["h9"];
$h10=$row["h10"];
$h11=$row["h11"];
$h12=$row["h12"];
$h13=$row["h13"];
$h14=$row["h14"];
$h15=$row["h15"];
$h16=$row["h16"];
$h17=$row["h17"];
$h18=$row["h18"];
$h19=$row["h19"];
$h20=$row["h20"];
$h21=$row["h21"];
$h22=$row["h22"];
$h23=$row["h23"];
$h24=$row["h24"];
$h25=$row["h25"];
	 
			  
      }
     }catch (PDOException $Exception) {
       print "오류: ".$Exception->getMessage();
     }
  }

if ($mode=="not"){    // 수정모드가 아닐때 신규 자료일때는 변수 초기화 한다.
          
			  $outdate=date("Y-m-d");
			  $outputnum=null;
			  $item_indate=date("Y-m-d");
			  $item_orderman=$_SESSION["name"];
			  $item_outworkplace=null;
			  $item_outputplace=null;
			  $item_receiver=null;
			  $item_phone=null;
			  $item_comment=null;
			  $item_delivery=null;
  }
 
?>


   <!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/radio.css"> 
   <link  rel="stylesheet" type="text/css" href="../css/bending_write.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">
	  
   <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>
	 <?php
    if($mode=="modify"){
  ?>
	<form  name="board_form" method="post"   action="bendingdata_insert.php?mode=modify&num=<?=$num?>&search=<?=$search?>&find=<?=$find?>&year=<?=$year?>&search=<?=$search?>&process=<?=$process?>&asprocess=<?=$asprocess?>&fromdate=<?=$fromdate?>&todate=<?=$todate?>&separate_date=<?=$separate_date?>&upnum=<?=$upnum?>&parentnum=<?=$upnum?>" enctype="multipart/form-data"> 
  <?php  } 
else  {
  ?>
	<form  name="board_form" method="post" action="bendingdata_insert.php?mode=not&search=<?=$search?>&find=<?=$find?>&year=<?=$year?>&process=<?=$process?>&asprocess=<?=$asprocess?>&fromdate=<?=$fromdate?>&todate=<?=$todate?>&separate_date=<?=$separate_date?>&upnum=<?=$upnum?>&parentnum=<?=$upnum?>&callback=1" enctype="multipart/form-data"> 
  <?php
	}
  ?>	   
    <div id="work_col3"> <h2> &nbsp; &nbsp; 절곡데이터 등록/수정  &nbsp; &nbsp;  데이터 고유번호:&nbsp; <?=$num?> </h2>

	      <div class="clear"></div>	
	 <div id="sero1"> 절곡구분 :  </div>	 
	 <div id="sero2"> 
	          <select name="steeltype" id="steeltype">
			  <option value=""></option> 
	    <?php 		
		  $options = array(); 
		  $options[1] = '가이드레일'; 
		  $options[2] = '포스트'; 
		  $options[3] = '셔터박스'; 
		  $options[4] = '마구리'; 
		  $options[5] = '린텔'; 
		  $options[6] = '절단판'; 
		  $options[7] = '알몰딩'; 
		  $options[8] = '알케이스'; 
		  $options[9] = '보강'; 
		  $options[10] = '삼각쫄대'; 
		  $options[11]= '짜부가스켓'; 
		  $options[12] = '하장바'; 
		  $options[13] = '엘바'; 
		  $options[14] = '평철'; 
		  $options[15] = '갈바앵글'; 
		  $options[16] = '기타절곡물'; 
		
	
  if (! empty($options)) { 
foreach ($options as $key => $val) { 
$sel="";
if($copy_steeltype==$val)
	$sel="selected";
?> 
<option value="<?php echo $val;?>" <?php echo $sel;?> > <?php echo $val;?></option> 
<?php 
} 
} 
?> 
</select> 

	 </div> 
	 <div id="sero7"> <input type="text" id="steel_alias" name="steel_alias" size="45" value="<?=$steel_alias?>" > </div>
	 	 
	 <div id="sero3"> 이미지등록 :  </div>
	 <div id="sero4">  
	 
	 	 <?php
	   if($mode=="modify"&& $copied_file_name!="") {
		
	   }
	     else
		 {
		   print '<input type="file" name="upfile" class="inp-img" accept=".gif, .jpg, .png"> <span class="btn-delete">삭제</span>';
		 }
	 ?>

<?php 	if ($mode=="modify" && $copied_file_name)
							 {
				  ?>
						<div class="delete_ok">
							<a href="<?=$uploaded_file?>" onclick="window.open(this.href,'파일보기',width=800,height=600); return false;" style="color:blue;"> <b> <?=$copied_file_name?> </b> </a>
							등록
							<input type="checkbox" name="del_file[]" value="1"> 삭제 </div>
				  <?php  	} ?>	 
	 </div>				  
	 	 <div class="clear"></div> 
 <div id="work_col_left">	 
	 <div id="preview">
	 <?php
	   if($mode=="modify") {
		   print '<img src="' . $uploaded_file . '">';
	   }
	 ?>
	 
	 </div>
 </div>
<script type="text/javascript">
          
// 등록 이미지 등록 미리보기
function readInputFile(input) {
    if(input.files && input.files[0]) {
        var reader = new FileReader();
        reader.onload = function (e) {
            $('#preview').html("<img src="+ e.target.result +">");
        }
        reader.readAsDataURL(input.files[0]);
    }
}
 
$(".inp-img").on('change', function(){
    readInputFile(this);
});
 
 
// 등록 이미지 삭제 ( input file reset )
function resetInputFile($input, $preview) {
    var agent = navigator.userAgent.toLowerCase();
    if((navigator.appName == 'Netscape' && navigator.userAgent.search('Trident') != -1) || (agent.indexOf("msie") != -1)) {
        // ie 일때
        $input.replaceWith($input.clone(true));
        $preview.empty();
    } else {
        //other
        $input.val("");
        $preview.empty();
    }       
}
 
$(".btn-delete").click(function(event) {
    var $input = $(".inp-img");
    var $preview = $('#preview');
    resetInputFile($input, $preview);
});
</script>

	 <div id="work_col_right">	 
	 <br><br>
	 <?php 
	 for($j=0;$j<=7;$j++) {
		 switch ($j) {
			 case 0:
			   $str='A';
			   break;
			 case 1:
			   $str='B';
			   break;			   
			 case 2:
			   $str='C';
			   break;			   
			 case 3:
			   $str='D';
			   break;			   
			 case 4:
			   $str='E';
			   break;			   
			 case 5:
			   $str='F';
			   break;			   
			 case 6:
			   $str='G';
			   break;			   
			 case 7:
			   $str='H';	
			   break;			   
		 }
	 $str=strtolower($str);	 
     $arr=compact($str."1",$str."2",$str."3",$str."4",$str."5",$str."6",$str."7",$str."8",$str."9",$str."10",$str."11",$str."12",$str."13",$str."14",$str."15",$str."16",$str."17",$str."18",$str."19",$str."20",$str."21",$str."21",$str."22",$str."23",$str."24",$str."25");
	 print '<div class="a_col"> </div>';  // 첫 타이틀
	    for($i=1;$i<=25;$i++) {
			print '<div class="a_col">' . $str . $i . '</div>';
		}
		    print ' <div class="clear"></div> ';
			print '<div class="a_col">' .  ($j+1) . '행</div>';	
	    for($i=0;$i<25;$i++) {
		    $temp= $str . ($i+1);
			if((int)$arr[$temp]>0)
				   $altertmp=$arr[$temp];
			   else
				   $altertmp="";
			   
			print '<input type="text"  name="' . $str . ($i+1) . '" id="'  . $str . ($i+1) .'" style="width:36px;height:15px;color:blue;font-size:17px;" value="' . $altertmp . '">';
		}		
	       print ' <div class="clear"></div> ';	
	 }
?>		
  
		<input type="hidden" id="copied_file_name" name="copied_file_name" value="<?=$copied_file_name?>" size="5" > 		
		<input type="hidden" id="uploaded_file" name="uploaded_file" value="<?=$uploaded_file?>" size="5" > 		
		<input type="hidden" id="mode" name="mode" value="<?=$mode?>" size="5" > 	
	
     <div class="clear"></div> 
	 </div>	
  			</form>       
		
<br><br>
 <div id="write_button">
      <button > <img src="../img/savefile.png"></button>&nbsp;&nbsp;&nbsp;&nbsp;
	 
    <a href="bendingdatalist.php?mode=search&search=<?=$search?>&find=<?=$find?>&year=<?=$year?>&search=<?=$search?>&process=<?=$process?>&asprocess=<?=$asprocess?>&fromdate=<?=$fromdate?>&todate=<?=$todate?>&separate_date=<?=$separate_date?>"><img src="../img/list.png"></a>
				</div> <br>
				</div>
 
	  </div> 

 

         </div>	 <!-- end of col3 -->  
	   </div>   <!-- end of wrap -->   
	   
<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 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 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);
}
function del(href) 
     {
        if(confirm("한번 삭제한 자료는 복구할 방법이 없습니다.\n\n정말 삭제하시겠습니까?")) {
           document.location.href = href;
          }
}

function sortall(){
 var sort;
 sort=$("#sort").val();		
 if(sort=='1')
     $("#sort").val("2");
   else
	   $("#sort").val("1");
 $("#modify").val("1");			// 소팅할 것
 document.getElementById('board_form').submit();  // form의 검색버튼 누른 효과    
}

function saveit() {
// $("#modify").val("1");			// 이전화면 유지
 document.getElementById('board_form').submit();  // form의 검색버튼 누른 효과    	
}

var tmp=$("#mode").val();
var type_tmp=$("#steeltype").val();
if(tmp=='modify')
	   $("#steeltype").val(type_tmp).prop("selected", true);   // 선택사항 변경

</script> 
	</body>
 </html>
