 <?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["page"]))
    $page=$_REQUEST["page"];
  else 
    $page=1;   // 1로 설정해야 함
 if(isset($_REQUEST["mode"]))  //modify_form에서 호출할 경우
    $mode=$_REQUEST["mode"];
 else 
    $mode="";
 
 if(isset($_REQUEST["num"]))
    $num=$_REQUEST["num"];
 else 
    $num="";

  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"];

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

			  $motor380v_150k=$_REQUEST["motor380v_150k"];	
			  $motor380v_300k=$_REQUEST["motor380v_300k"];	
			  $motor380v_400k=$_REQUEST["motor380v_400k"];	
			  $motor380v_500k=$_REQUEST["motor380v_500k"];	
			  $motor380v_600k=$_REQUEST["motor380v_600k"];	
			  $motor380v_800k=$_REQUEST["motor380v_800k"];	
			  $motor380v_1000k=$_REQUEST["motor380v_1000k"];	
			  $motor380v_1500k=$_REQUEST["motor380v_1500k"];	
			  $motor380v_2000k=$_REQUEST["motor380v_2000k"];	
			  
			  $bracket_150k=$_REQUEST["bracket_150k"];	
			  $bracket_screen300k=$_REQUEST["bracket_screen300k"];	
			  $bracket_300k=$_REQUEST["bracket_300k"];	
			  $bracket_500k=$_REQUEST["bracket_500k"];	
			  $bracket_800k=$_REQUEST["bracket_800k"];	
			  $bracket_1500k=$_REQUEST["bracket_1500k"];	
			  $bracket_2000k=$_REQUEST["bracket_2000k"];	


 require_once("../lib/mydb.php");
 $pdo = db_connect();
     
 if ($mode=="modify"){
      
     try{
        $sql = "select * from chandj.motor where num=?";  // get target record
        $stmh = $pdo->prepare($sql); 
        $stmh->bindValue(1,$num,PDO::PARAM_STR); 
        $stmh->execute(); 
        $row = $stmh->fetch(PDO::FETCH_ASSOC);
     } catch (PDOException $Exception) {
        $pdo->rollBack();
        print "오류: ".$Exception->getMessage();
     } 
       
	    
			  
/* 	print "접속완료"	  ; */

     try{
        $pdo->beginTransaction();   
        $sql = "update chandj.motor set con_num=?, outdate=?, indate=?, outworkplace=?, orderman=?, outputplace=?, receiver=?, phone=?, comment=?, root=?, delivery=?, regist_state=?,";
        $sql .= " motor220v_150k=?,  motor220v_300k=?,  motor220v_400k=?,  motor220v_500k=?,  motor220v_600k=?,  motor220v_800k=?,  motor220v_1000k=?,  motor220v_1500k=?,  motor220v_2000k=?, ";		
        $sql .= " motor380v_150k=?,  motor380v_300k=?,  motor380v_400k=?,  motor380v_500k=?,  motor380v_600k=?,  motor380v_800k=?,  motor380v_1000k=?,  motor380v_1500k=?,  motor380v_2000k=?, ";		
        $sql .= " bracket_150k=?, bracket_screen300k=?,  bracket_300k=?,  bracket_500k=?,  bracket_800k=?,  bracket_1500k=?,  bracket_2000k=?, ";		
        $sql .= " out_control=?, in_control=?, inbox=?, casecover=?, switchset=?, which=?, outputnum=? where num=?  LIMIT 1";		
	   
     $stmh = $pdo->prepare($sql); 
     $stmh->bindValue(1, $con_num, PDO::PARAM_STR);  
     $stmh->bindValue(2, $outdate, PDO::PARAM_STR);  
     $stmh->bindValue(3, $indate, PDO::PARAM_STR);  
     $stmh->bindValue(4, $outworkplace, PDO::PARAM_STR);  
     $stmh->bindValue(5, $orderman, PDO::PARAM_STR);  
     $stmh->bindValue(6, $outputplace, PDO::PARAM_STR);  
     $stmh->bindValue(7, $receiver, PDO::PARAM_STR);  
     $stmh->bindValue(8, $phone, PDO::PARAM_STR);  
     $stmh->bindValue(9, $comment, PDO::PARAM_STR);  
     $stmh->bindValue(10, $root, PDO::PARAM_STR);  
     $stmh->bindValue(11, $delivery, PDO::PARAM_STR);  
     $stmh->bindValue(12, $regist_state, PDO::PARAM_STR);  
     $stmh->bindValue(13, $motor220v_150k, PDO::PARAM_STR);  
     $stmh->bindValue(14, $motor220v_300k, PDO::PARAM_STR);  
     $stmh->bindValue(15, $motor220v_400k, PDO::PARAM_STR);  
     $stmh->bindValue(16, $motor220v_500k, PDO::PARAM_STR);  
     $stmh->bindValue(17, $motor220v_600k, PDO::PARAM_STR);  
     $stmh->bindValue(18, $motor220v_800k, PDO::PARAM_STR);  
     $stmh->bindValue(19, $motor220v_1000k, PDO::PARAM_STR);  
     $stmh->bindValue(20, $motor220v_1500k, PDO::PARAM_STR);  
     $stmh->bindValue(21, $motor220v_2000k, PDO::PARAM_STR);  
     $stmh->bindValue(22, $motor380v_150k, PDO::PARAM_STR);  
     $stmh->bindValue(23, $motor380v_300k, PDO::PARAM_STR);  
     $stmh->bindValue(24, $motor380v_400k, PDO::PARAM_STR);  
     $stmh->bindValue(25, $motor380v_500k, PDO::PARAM_STR);  
     $stmh->bindValue(26, $motor380v_600k, PDO::PARAM_STR);  
     $stmh->bindValue(27, $motor380v_800k, PDO::PARAM_STR);  
     $stmh->bindValue(28, $motor380v_1000k, PDO::PARAM_STR);  
     $stmh->bindValue(29, $motor380v_1500k, PDO::PARAM_STR);  
     $stmh->bindValue(30, $motor380v_2000k, PDO::PARAM_STR);  
	 
     $stmh->bindValue(31, $bracket_150k, PDO::PARAM_STR);  
     $stmh->bindValue(32, $bracket_screen300k, PDO::PARAM_STR);  
     $stmh->bindValue(33, $bracket_300k, PDO::PARAM_STR);  
     $stmh->bindValue(34, $bracket_500k, PDO::PARAM_STR);  
     $stmh->bindValue(35, $bracket_800k, PDO::PARAM_STR);  
     $stmh->bindValue(36, $bracket_1500k, PDO::PARAM_STR);  
     $stmh->bindValue(37, $bracket_2000k, PDO::PARAM_STR);  	 
	 
     $stmh->bindValue(38, $out_control, PDO::PARAM_STR);  
     $stmh->bindValue(39, $in_control, PDO::PARAM_STR);  
     $stmh->bindValue(40, $inbox, PDO::PARAM_STR);  
     $stmh->bindValue(41, $casecover, PDO::PARAM_STR);  
     $stmh->bindValue(42, $switchset, PDO::PARAM_STR);  
     $stmh->bindValue(43, $which, PDO::PARAM_STR);  
     $stmh->bindValue(44, $outputnum, PDO::PARAM_STR);  
     $stmh->bindValue(45, $num, PDO::PARAM_STR);           //고유키값이 같나?의 의미로 ?로 num으로 맞춰야 합니다. where 구문 
	 
	 $stmh->execute();
     $pdo->commit(); 
        } catch (PDOException $Exception) {
           $pdo->rollBack();
           print "오류: ".$Exception->getMessage();
       }                         
       
 } else	{
	 
	 // 데이터 신규 등록하는 구간
	 
   try{
     $pdo->beginTransaction();
  	 
     $sql = "insert into chandj.motor(con_num, outdate, indate, outworkplace, orderman, outputplace, receiver, phone, comment, root, delivery, regist_state, ";
     $sql .= " motor220v_150k,  motor220v_300k,  motor220v_400k,  motor220v_500k,  motor220v_600k,  motor220v_800k,  motor220v_1000k,  motor220v_1500k,  motor220v_2000k, ";		
     $sql .= " motor380v_150k,  motor380v_300k,  motor380v_400k,  motor380v_500k,  motor380v_600k,  motor380v_800k,  motor380v_1000k,  motor380v_1500k,  motor380v_2000k, ";		
     $sql .= " bracket_150k, bracket_screen300k,  bracket_300k,  bracket_500k,  bracket_800k,  bracket_1500k,  bracket_2000k, ";		
     $sql .= " out_control, in_control, inbox, casecover, switchset, which, outputnum)";
	 

     $sql .= "values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?,"; // 43개 데이터 자료  num 제외 신규등록시 자동으로 생성되는 번호
     $sql .= "       ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,";
     $sql .= "       ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,";
     $sql .= "       ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,";
     $sql .= "       ?, ?, ?, ?)";
	   
     $stmh = $pdo->prepare($sql); 
     $stmh->bindValue(1, $con_num, PDO::PARAM_STR);  
     $stmh->bindValue(2, $outdate, PDO::PARAM_STR);  
     $stmh->bindValue(3, $indate, PDO::PARAM_STR);  
     $stmh->bindValue(4, $outworkplace, PDO::PARAM_STR);  
     $stmh->bindValue(5, $orderman, PDO::PARAM_STR);  
     $stmh->bindValue(6, $outputplace, PDO::PARAM_STR);  
     $stmh->bindValue(7, $receiver, PDO::PARAM_STR);  
     $stmh->bindValue(8, $phone, PDO::PARAM_STR);  
     $stmh->bindValue(9, $comment, PDO::PARAM_STR);  
     $stmh->bindValue(10, $root, PDO::PARAM_STR);  
     $stmh->bindValue(11, $delivery, PDO::PARAM_STR);  
     $stmh->bindValue(12, $regist_state, PDO::PARAM_STR);  
     $stmh->bindValue(13, $motor220v_150k, PDO::PARAM_STR);  
     $stmh->bindValue(14, $motor220v_300k, PDO::PARAM_STR);  
     $stmh->bindValue(15, $motor220v_400k, PDO::PARAM_STR);  
     $stmh->bindValue(16, $motor220v_500k, PDO::PARAM_STR);  
     $stmh->bindValue(17, $motor220v_600k, PDO::PARAM_STR);  
     $stmh->bindValue(18, $motor220v_800k, PDO::PARAM_STR);  
     $stmh->bindValue(19, $motor220v_1000k, PDO::PARAM_STR);  
     $stmh->bindValue(20, $motor220v_1500k, PDO::PARAM_STR);  
     $stmh->bindValue(21, $motor220v_2000k, PDO::PARAM_STR);  
     $stmh->bindValue(22, $motor380v_150k, PDO::PARAM_STR);  
     $stmh->bindValue(23, $motor380v_300k, PDO::PARAM_STR);  
     $stmh->bindValue(24, $motor380v_400k, PDO::PARAM_STR);  
     $stmh->bindValue(25, $motor380v_500k, PDO::PARAM_STR);  
     $stmh->bindValue(26, $motor380v_600k, PDO::PARAM_STR);  
     $stmh->bindValue(27, $motor380v_800k, PDO::PARAM_STR);  
     $stmh->bindValue(28, $motor380v_1000k, PDO::PARAM_STR);  
     $stmh->bindValue(29, $motor380v_1500k, PDO::PARAM_STR);  
     $stmh->bindValue(30, $motor380v_2000k, PDO::PARAM_STR);  
	 
     $stmh->bindValue(31, $bracket_150k, PDO::PARAM_STR);  
     $stmh->bindValue(32, $bracket_screen300k, PDO::PARAM_STR);  
     $stmh->bindValue(33, $bracket_300k, PDO::PARAM_STR);  
     $stmh->bindValue(34, $bracket_500k, PDO::PARAM_STR);  
     $stmh->bindValue(35, $bracket_800k, PDO::PARAM_STR);  
     $stmh->bindValue(36, $bracket_1500k, PDO::PARAM_STR);  
     $stmh->bindValue(37, $bracket_2000k, PDO::PARAM_STR);  	 
	 
     $stmh->bindValue(38, $out_control, PDO::PARAM_STR);  
     $stmh->bindValue(39, $in_control, PDO::PARAM_STR);  
     $stmh->bindValue(40, $inbox, PDO::PARAM_STR);  
     $stmh->bindValue(41, $casecover, PDO::PARAM_STR);  
     $stmh->bindValue(42, $switchset, PDO::PARAM_STR);  
     $stmh->bindValue(43, $which, PDO::PARAM_STR);       
     $stmh->bindValue(44, $outputnum, PDO::PARAM_STR);       
	 
     $stmh->execute();
     $pdo->commit(); 
     } catch (PDOException $Exception) {
          $pdo->rollBack();
       print "오류: ".$Exception->getMessage();
     }   
   }
    ?>
  <script>
        alert('자료등록/수정 완료');      
  </script>
  
  
  
 <?php
  if($mode=="not")
	   header("Location:/motor/read_DB.php?num=$num&outputnum=$outputnum&page=$page&search=$search&find=$find&process=$process&yearcheckbox=$yearcheckbox&year=$year&fromdate=$fromdate&todate=$todate&separate_date=$separate_date");    // 신규가입일때는 리스트로 이동
	 else		 
     header("Location:/motor/view.php?num=$num&outputnum=$outputnum&page=$page&search=$search&find=$find&process=$process&yearcheckbox=$yearcheckbox&year=$year&fromdate=$fromdate&todate=$todate&separate_date=$separate_date");  
 ?>