<style>
  .c-table { border-collapse: collapse; text-align: center;}
    .c-table th { height:30px; background:gray; color:white; font-size:15px;}
  .c-table td { height:22px; border:1px solid gray; font-size:13px; }
</style>


<?php
session_start();

  $level= $_SESSION["level"];
if(!isset($_SESSION["level"]) || $level>5) {
         /*   alert("관리자 승인이 필요합니다."); */
        sleep(2);
        header ("Location:/login/logout.php");
        exit;
  }
  
header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header ("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header ("Pragma: no-cache"); // HTTP/1.0
header("Expires: 0"); // rfc2616 - Section 14.21   
//header("Refresh:0");  // reload refresh   
?>
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" href="../css/common.css">
<link rel="stylesheet" type="text/css" href="../css/aslist.css">

<title> 주일기업 통합정보시스템 </title> 
</head>
        <script>
       window.history.forward(0);
       history.navigationMode = 'compatible'; // 오페라, 사파리 뒤로가기 막기
       function _no_Back(){
       window.history.forward(0);
       }
       </script>
<?php
 if(isset($_REQUEST["search"]))   //목록표에 제목,이름 등 나오는 부분
    $search=$_REQUEST["search"];
  if(isset($_REQUEST["list"]))   //목록표에 제목,이름 등 나오는 부분
    $list=$_REQUEST["list"];
   else
         $list=0;
     
 require_once("../lib/mydb.php");
 $pdo = db_connect(); 
// $find="firstord";      //검색할때 고정시킬 부분 저장 ex) 전체/공사담당/건설사 등
if(isset($_REQUEST["page"])) // $_REQUEST["page"]값이 없을 때에는 1로 지정 
{
   $page=$_REQUEST["page"];  // 페이지 번호
}
 else
 {
   $page=1;  
 }

 $scale = 50;       // 한 페이지에 보여질 게시글 수
 $page_scale = 10;   // 한 페이지당 표시될 페이지 수  10페이지
 $first_num = ($page-1) * $scale;  // 리스트에 표시되는 게시글의 첫 순번.
    
 if(isset($_REQUEST["mode"]))
    $mode=$_REQUEST["mode"];
 else 
    $mode="";     

$cursort=$_REQUEST["cursort"];    // 현재 정렬모드 지정
if(isset($_REQUEST["sortof"]))
   {
    $sortof=$_REQUEST["sortof"];  // 클릭해서 넘겨준 값
   if($sortof==1) {
       
    if($cursort!=1)
       $cursort=1;
     else
        $cursort=2;
       } 
   if($sortof==2) {     //처리예정일이 클릭되었을때
       
    if($cursort!=3)
       $cursort=3;
     else
        $cursort=4;     
      }
   if($sortof==3) {     //세팅예정일 클릭
       
    if($cursort!=5)
       $cursort=5;
     else
        $cursort=6;     
      }    
   }   
 else 
 {
    $sortof=0;     
    $cursort=0;
 }


  if(isset($_REQUEST["find"]))   //목록표에 제목,이름 등 나오는 부분
    $find=$_REQUEST["find"];

if(isset($_REQUEST["asprocess"]))   //공사진행현황에 대한 내용
    $asprocess=$_REQUEST["asprocess"];   
         else 
             $asprocess="전체"; 
         
 if(isset($_REQUEST["year"]))
    $year=$_REQUEST["year"];   

if($year=="") $year="전체"; 

$process="전체";  // 기본 전체로 정한다.

$a="  (as_check = '1') or (asday <> '0000-00-00') order by num desc limit $first_num, $scale";  
$b="  (as_check = '1') or (asday <> '0000-00-00') order by num desc";
 
if($year=="전체" )   // 기존 검색방법으로 검색  년도 선택이 없을때  as_check=""일때만 나오기
 if($mode=="search" || $list==1){
         if($search==""){
                 if($asprocess=="전체")
                       {
                            $sql="select * from chandj.work where " . $a;           
                            $sqlcon = "select * from chandj.work where " . $b;   // 전체 레코드수를 파악하기 위함.
                       }
                     elseif($asprocess=="미접수")
                       {
                            $sql="select * from chandj.work where (as_state like '%$asprocess%') and (as_check = '1') order by num desc limit $first_num, $scale";
                            $sqlcon = "select * from chandj.work where (as_state like '%$asprocess%')  and (as_check = '1') order by num desc";   // 전체 레코드수를 파악하기 위함.                                               
                       }              
                    else
                      {
                            $sql="select * from chandj.work where (as_state like '%$asprocess%') order by num desc limit $first_num, $scale";
                            $sqlcon = "select * from chandj.work where (as_state like '%$asprocess%') order by num desc";                                                                          
                      }
                   
                  }
            elseif($find!="all"&&$search=="")
               {
                     if($asprocess=="전체")
                       {
                            $sql="select * from chandj.work where ($find like '%$search%') and" . $a;           
                            $sqlcon = "select * from chandj.work where ($find like '%$search%') and" . $b;   // 전체 레코드수를 파악하기 위함.
                       }
                    else
                      {
                            $sql="select * from chandj.work where (as_state like '%$asprocess%') and ($find like '%$search%') order by num desc limit $first_num, $scale";
                            $sqlcon = "select * from chandj.work where (as_state like '%$asprocess%') and ($find like '%$search%') order by num desc";                                                                         
                      }                                           
                }
            elseif($search!="") { // 각 필드별로 검색어가 있는지 쿼리주는 부분
                       if($asprocess=="전체")
                       {
                             $sql ="select * from chandj.work where ((condate like '%$search%' ) or (workplacename like '%$search%' ) or (chargedperson like '%$search%' )";
                             $sql .="or (firstord like '%$search%' ) or (secondord like '%$search%' ) or (worker like '%$search%' ) or (cablestaff like '%$search%' ) or ";
                             $sql .=" (address like '%$search%' )) and (asday <> '0000-00-00')  order by num desc limit $first_num, $scale ";
                             
                             $sqlcon ="select * from chandj.work where ((condate like '%$search%' ) or (workplacename like '%$search%' ) or (chargedperson like '%$search%' )";
                             $sqlcon .="or (firstord like '%$search%' ) or (secondord like '%$search%' ) or (worker like '%$search%' ) or (cablestaff like '%$search%' ) or ";
                             $sqlcon .=" (address like '%$search%' )) and (asday <> '0000-00-00')  order by num desc";
                       }
                     else
                       {
                             $sql ="select * from chandj.work where ((condate like '%$search%' ) or (workplacename like '%$search%' ) or (chargedperson like '%$search%' )";
                             $sql .="or (firstord like '%$search%' ) or (secondord like '%$search%' ) or (worker like '%$search%' ) or (cablestaff like '%$search%' ) or ";
                             $sql .=" (address like '%$search%' )) and ($find like '%$search%') and (asday <> '0000-00-00')  and (as_state like '%$asprocess%') order by num desc limit $first_num, $scale ";
                             
                             $sqlcon ="select * from chandj.work where ((condate like '%$search%' ) or (workplacename like '%$search%' ) or (chargedperson like '%$search%' )";
                             $sqlcon .="or (firstord like '%$search%' ) or (secondord like '%$search%' ) or (worker like '%$search%' ) or (cablestaff like '%$search%' ) or ";
                             $sqlcon .=" (address like '%$search%')) and ($find like '%$search%') and (asday <> '0000-00-00')  and (as_state like '%$asprocess%') order by num desc";
                       }    
              }
          }
    else
    {
                              $sql="select * from chandj.work where " . $a;
                              $sqlcon="select * from chandj.work where" . $b;
  }         

$a="  (condate <> '0000-00-00') order by num desc limit $first_num, $scale";  
$b="  (condate <> '0000-00-00') order by num desc";

$temp1=$year."-01-01";
//$temp1=date("Y-m-d", strtotime( $temp1) );
$temp2=$year+1 . "-01-01";
//$temp2=date("Y-m-d", strtotime( $temp2) );

if($year!="전체" )   // 년도 선택을 했을때 검색조건 2019,2018 등
{

 if($mode=="search" || $list==1){
         if($search==""){
                if($process=="전체")
                   {
                    $sql="select * from chandj.work where (endworkday between date('$temp1') and date('$temp2')+1) and " . $a;          
                     $sqlcon = "select * from chandj.work  where (endworkday between date('$temp1') and date('$temp2')+1) and" . $b;   // 전체 레코드수를 파악하기 위함.
                   }
                    else   // 진행현황이 다를때 처리구문
                    {
                     $sql="select * from chandj.work where (work_state like '%$process%') and (endworkday between date('$temp1') and date('$temp2')+1) and" . $a;
                     $sqlcon = "select * from chandj.work where (work_state like '%$process%') and (endworkday between date('$temp1') and date('$temp2')+1) and" . $b;
                    }
                  }
            elseif($search!=""&&$find!="all")
               {
                    $sql="select * from chandj.work where ($find like '%$search%')  and (endworkday between date('$temp1') and date('$temp2')+1) and" . $a;           
                    $sqlcon="select * from chandj.work where ($find like '%$search%')  and (endworkday between date('$temp1') and date('$temp2')+1) and" . $b;            
                }
            elseif($search!=""&&$find!="all"&&$process!="전체")    // 진행현황에 대한 처리 추가
               {
                    $sql="select * from chandj.work where ($find like '%$search%') and (work_state like '%$process%')  and (endworkday between date('$temp1') and date('$temp2')+1) and" . $a ;           
                    $sqlcon="select * from chandj.work where ($find like '%$search%') and (work_state like '%$process%')  and (endworkday between date('$temp1') and date('$temp2')+1) and" . $b ;            
                }                
            elseif($search!="") { // 각 필드별로 검색어가 있는지 쿼리주는 부분
              if($process=="전체") 
              {   
                     $sql ="select * from chandj.work where ((condate like '%$search%' ) or (workplacename like '%$search%' ) or (chargedperson like '%$search%' )";
                     $sql .="or (firstord like '%$search%' ) or (secondord like '%$search%' ) or (worker like '%$search%' ) or (cablestaff like '%$search%' ) or (address like '%$search%' )) and (endworkday between date('$temp1') and date('$temp2')+1)  and" . $a;
                     
                     $sqlcon ="select * from chandj.work where ((condate like '%$search%' ) or (workplacename like '%$search%' ) or (chargedperson like '%$search%' )";
                     $sqlcon .="or (firstord like '%$search%' ) or (secondord like '%$search%' ) or (worker like '%$search%' ) or (cablestaff like '%$search%' ) or (address like '%$search%')) and (endworkday between date('$temp1') and date('$temp2')+1)  and" . $b;
              //limit를 사용해 레코드 개수를 한 페이지당 출력하는 수로 제한         
                   }    
                   else
                   {
                     $sql ="select * from chandj.work where ((condate like '%$search%' ) or (workplacename like '%$search%' ) or (chargedperson like '%$search%' )";
                     $sql .="or (firstord like '%$search%' ) or (secondord like '%$search%' ) or (worker like '%$search%' ) or (cablestaff like '%$search%' ) or (address like '%$search%' )) and (work_state like '%$process%')   and (endworkday between date('$temp1') and date('$temp2')+1) and" . $a;
                     
                     $sqlcon ="select * from chandj.work where ((condate like '%$search%' ) or (workplacename like '%$search%' ) or (chargedperson like '%$search%' )";
                     $sqlcon .="or (firstord like '%$search%' ) or (secondord like '%$search%' ) or (worker like '%$search%' ) or (cablestaff like '%$search%' ) or (address like '%$search%')) and (work_state like '%$process%')  and (endworkday between date('$temp1') and date('$temp2')+1) and" . $b;
              //limit를 사용해 레코드 개수를 한 페이지당 출력하는 수로 제한
                   }               
              }
          }
    else
    {
                              $sql="select * from chandj.work   where (endworkday between date('$temp1') and date('$temp2')+1) and" . $a;          
                              $sqlcon="select * from chandj.work  where (endworkday between date('$temp1') and date('$temp2')+1) and" . $b;  
  }     
}      
  
if($asprocess=="결선대기")
{ 
                    $sql="select * from chandj.work where (work_state like '%$asprocess%')" . " order by num desc limit $first_num, $scale";
                     $sqlcon = "select * from chandj.work where (work_state like '%$asprocess%') order by num desc " ;   
}

if($cursort==1)
{ 
                              $sql="select * from chandj.work where (as_check = '1') or (asday <> '0000-00-00') order by asday asc limit $first_num, $scale";          
                              $sqlcon="select * from chandj.work where (as_check = '1') or (asday <> '0000-00-00') order by asday asc";          
}   
if($cursort==2)
{ 
                              $sql="select * from chandj.work where (as_check = '1') or (asday <> '0000-00-00') order by asday desc limit $first_num, $scale";          
                              $sqlcon="select * from chandj.work where (as_check = '1') or (asday <> '0000-00-00') order by asday desc";          
}  
if($cursort==3)
{ 
                              $sql="select * from chandj.work where (as_check = '1') or (asday <> '0000-00-00') order by asproday asc limit $first_num, $scale";          
                              $sqlcon="select * from chandj.work where (as_check = '1') or (asday <> '0000-00-00') order by asproday asc";          
}   
if($cursort==4)
{ 
                              $sql="select * from chandj.work where (as_check = '1') or (asday <> '0000-00-00') order by asproday desc limit $first_num, $scale";          
                              $sqlcon="select * from chandj.work where (as_check = '1') or (asday <> '0000-00-00') order by asproday desc";          
}     
if($cursort==5)
{ 
                              $sql="select * from chandj.work where (as_check = '1') or (asday <> '0000-00-00') order by setdate asc limit $first_num, $scale";          
                              $sqlcon="select * from chandj.work where (as_check = '1') or (asday <> '0000-00-00') order by setdate asc";          
}   
if($cursort==6)
{ 
                              $sql="select * from chandj.work where (as_check = '1') or (asday <> '0000-00-00') order by setdate desc limit $first_num, $scale";          
                              $sqlcon="select * from chandj.work where (as_check = '1') or (asday <> '0000-00-00') order by setdate desc";          
}   
  
    try{  
     $allstmh = $pdo->query($sqlcon);         // 검색 조건에 맞는 쿼리 전체 개수
     $temp2=$allstmh->rowCount();  
     $stmh = $pdo->query($sql);            // 검색조건에 맞는글 stmh
     $temp1=$stmh->rowCount();
         
               $total_row = $temp2;     // 전체 글수   
        
                             
        $total_page = ceil($total_row / $scale); // 검색 전체 페이지 블록 수
        $current_page = ceil($page/$page_scale); //현재 페이지 블록 위치계산      
     //   print "$page&nbsp;$total_page&nbsp;$current_page&nbsp;$search&nbsp;$mode";
            
           ?>
        
<body onload="_no_Back();" onpageshow="if(event.persisted)_no_Back();">
  
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.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">  
        
        <DIV id="col2"> 

            <HEADER>
            <form name="board_form" method="post" action="list.php?mode=search&search=<?=$search?>&find=<?=$find?>&asprocess=<?=$asprocess?>&yearcheckbox=<?=$yearcheckbox?>&year=<?=$year?>" style="text-align:center">
                    <div id="title"><img src="../img/title_as.png"> <span> (총 <?= $total_row ?> 개의 자료 파일이 있습니다.)</span></div>  

                    <div id="">
                        <?php
                        if($asprocess=="전체") {
                                ?>
                            <div id="">
              &nbsp;&nbsp; 전체 <input type="radio" checked name="asprocess" value="전체">
                            &nbsp;&nbsp;   결선대기 <input type="radio" name="asprocess" value="결선대기">
                            &nbsp;&nbsp;   미접수 <input type="radio" name="asprocess" value="미접수">
                            &nbsp;&nbsp;   접수완료<input type="radio" name="asprocess" value="접수완료">
                            &nbsp;&nbsp;   처리예약<input type="radio" name="asprocess" value="처리예약">
                            &nbsp;&nbsp;   세팅예약<input type="radio" name="asprocess" value="세팅예약">
                            &nbsp;&nbsp;   처리완료<input type="radio" name="asprocess" value="처리완료">       
                            </div>
                            <?php
                                        }    ?>  
                        <?php
                        if($asprocess=="결선대기") {
                                ?>
                            <div id="">&nbsp;&nbsp; 전체 <input type="radio" name="asprocess" value="전체">
                            &nbsp;&nbsp;   결선대기 <input type="radio" checked name="asprocess" value="결선대기">
                            &nbsp;&nbsp;   미접수 <input type="radio" name="asprocess" value="미접수">
                            &nbsp;&nbsp;   접수완료<input type="radio" name="asprocess" value="접수완료">
                            &nbsp;&nbsp;   처리예약<input type="radio" name="asprocess" value="처리예약">
                            &nbsp;&nbsp;   세팅예약<input type="radio" name="asprocess" value="세팅예약">
                            &nbsp;&nbsp;   처리완료<input type="radio" name="asprocess" value="처리완료">       
                            </div>
                            <?php
                                        }    ?>           
                        <?php
                        if($asprocess=="미접수") {
                                ?>
                            <div id="">&nbsp;&nbsp; 전체 <input type="radio"  name="asprocess" value="전체">
                            &nbsp;&nbsp;   결선대기 <input type="radio" name="asprocess" value="결선대기">
                            &nbsp;&nbsp;   미접수 <input type="radio" checked name="asprocess" value="미접수">
                            &nbsp;&nbsp;   접수완료<input type="radio" name="asprocess" value="접수완료">
                            &nbsp;&nbsp;   처리예약<input type="radio" name="asprocess" value="처리예약">
                            &nbsp;&nbsp;   세팅예약<input type="radio" name="asprocess" value="세팅예약">
                            &nbsp;&nbsp;   처리완료<input type="radio" name="asprocess" value="처리완료">       
                            </div>
                            <?php
                                        }    ?>           
                        <?php
                        if($asprocess=="접수완료") {
                                ?>
                            <div id="">&nbsp;&nbsp; 전체 <input type="radio" name="asprocess" value="전체">      
                            &nbsp;&nbsp;   결선대기 <input type="radio" name="asprocess" value="결선대기">
                            &nbsp;&nbsp;   미접수 <input type="radio" name="asprocess" value="미접수">
                            &nbsp;&nbsp;   접수완료<input type="radio" checked name="asprocess" value="접수완료">
                            &nbsp;&nbsp;   처리예약<input type="radio" name="asprocess" value="처리예약">
                            &nbsp;&nbsp;   세팅예약<input type="radio" name="asprocess" value="세팅예약">
                            &nbsp;&nbsp;   처리완료<input type="radio" name="asprocess" value="처리완료">           
                            </div>
                            <?php
                                        }    ?>
                        <?php
                        if($asprocess=="처리예약") {
                                ?>
                            <div id="">&nbsp;&nbsp; 전체 <input type="radio" name="asprocess" value="전체">      
                            &nbsp;&nbsp;   결선대기 <input type="radio" name="asprocess" value="결선대기">
                            &nbsp;&nbsp;   미접수 <input type="radio" name="asprocess" value="미접수">
                            &nbsp;&nbsp;   접수완료<input type="radio" name="asprocess" value="접수완료">
                            &nbsp;&nbsp;   처리예약<input type="radio" checked name="asprocess" value="처리예약">
                            &nbsp;&nbsp;   세팅예약<input type="radio" name="asprocess" value="세팅예약">
                            &nbsp;&nbsp;   처리완료<input type="radio" name="asprocess" value="처리완료">             
                            </div>
                            <?php
                                        }    ?>
                        <?php
                        if($asprocess=="세팅예약") {
                                ?>
                            <div id="">&nbsp;&nbsp; 전체 <input type="radio" name="asprocess" value="전체">      
                            &nbsp;&nbsp;   결선대기 <input type="radio" name="asprocess" value="결선대기">
                            &nbsp;&nbsp;   미접수 <input type="radio" name="asprocess" value="미접수">
                            &nbsp;&nbsp;   접수완료<input type="radio" name="asprocess" value="접수완료">
                            &nbsp;&nbsp;   처리예약<input type="radio"  name="asprocess" value="처리예약">
                            &nbsp;&nbsp;   세팅예약<input type="radio" checked name="asprocess" value="세팅예약">
                            &nbsp;&nbsp;   처리완료<input type="radio" name="asprocess" value="처리완료">             
                            </div>
                            <?php
                                        }    ?>         
                        <?php
                        if($asprocess=="처리완료") {
                                ?>
                            <div id="">&nbsp;&nbsp; 전체 <input type="radio" name="asprocess" value="전체">      
                            &nbsp;&nbsp;   결선대기 <input type="radio" name="asprocess" value="결선대기">
                            &nbsp;&nbsp;   미접수 <input type="radio" name="asprocess" value="미접수">
                            &nbsp;&nbsp;   접수완료<input type="radio" name="asprocess" value="접수완료">
                            &nbsp;&nbsp;   처리예약<input type="radio" name="asprocess" value="처리예약">
                            &nbsp;&nbsp;   세팅예약<input type="radio" name="asprocess" value="세팅예약">
                            &nbsp;&nbsp;   처리완료<input type="radio" checked name="asprocess" value="처리완료">         
                            </div>
                            <?php
                                        }    ?>         
                            
                        
                    </div> 

                <div id="list_search">
                    <div id="list_search111"> 
                                    <?php
                                    if($yearcheckbox=="check") {
                                            ?>
                                            <input type="checkbox" name=yearcheckbox checked value="check" > 시공완료년도  
                                        <?php    
                                                }
                                            else
                                            {               
                                            ?>
                                            <input type="checkbox" name=yearcheckbox value="check" > 시공완료년도  
                                        <?php
                                                }    ?>       
                                                
                    </div>                
                    
                    <div id="list_search11"> 
                        <select name="year">
                        <?php     
                            if($year=="전체"||$year=="")
                            {     ?>    
                        <option value='전체' selected >전체</option>
                        <option value='2019'>2019</option>
                        <option value='2018'>2018</option>
                        <option value='2017'>2017</option>
                        <option value='2016'>2016</option>
                        <option value='2015'>2015</option>
                        <option value='2014'>2014</option>
                        <option value='2013'>2013</option>
                        <option value='2012'>2012</option>
                        <?php
                            } ?>               
                        <?php     
                            if($year=="2019")
                            {     ?>    
                        <option value='전체' >전체</option>     
                        <option value='2019' selected >2019</option>
                        <option value='2018'>2018</option>
                        <option value='2017'>2017</option>
                        <option value='2016'>2016</option>
                        <option value='2015'>2015</option>
                        <option value='2014'>2014</option>
                        <option value='2013'>2013</option>
                        <option value='2012'>2012</option>
                        <?php
                            } ?>                      
                        <?php     
                            if($year=="2018")
                            {     ?>    
                        <option value='전체' >전체</option>           
                        <option value='2019'>2019</option>
                        <option value='2018' selected >2018</option>
                        <option value='2017'>2017</option>
                        <option value='2016'>2016</option>
                        <option value='2015'>2015</option>
                        <option value='2014'>2014</option>
                        <option value='2013'>2013</option>
                        <option value='2012'>2012</option>
                        <?php
                            } ?>                           
                        <?php     
                            if($year=="2017")
                            {     ?>    
                        <option value='전체' >전체</option>           
                        <option value='2019'>2019</option>
                        <option value='2018'>2018</option>
                        <option value='2017' selected >2017</option>
                        <option value='2016'>2016</option>
                        <option value='2015'>2015</option>
                        <option value='2014'>2014</option>
                        <option value='2013'>2013</option>
                        <option value='2012'>2012</option>
                        <?php
                            } ?>  
                        <?php     
                            if($year=="2016")
                            {     ?>    
                        <option value='전체' >전체</option>           
                        <option value='2019'>2019</option>
                        <option value='2018'>2018</option>
                        <option value='2017'>2017</option>
                        <option value='2016' selected >2016</option>
                        <option value='2015'>2015</option>
                        <option value='2014'>2014</option>
                        <option value='2013'>2013</option>
                        <option value='2012'>2012</option>
                        <?php
                            } ?>          
                        <?php     
                            if($year=="2015")
                            {     ?>    
                        <option value='전체' >전체</option>           
                        <option value='2019'>2019</option>
                        <option value='2018'>2018</option>
                        <option value='2017'>2017</option>
                        <option value='2016'>2016</option>
                        <option value='2015' selected >2015</option>
                        <option value='2014'>2014</option>
                        <option value='2013'>2013</option>
                        <option value='2012'>2012</option>
                        <?php
                            } ?>                     
                        <?php     
                            if($year=="2014")
                            {     ?>    
                        <option value='전체' >전체</option>           
                        <option value='2019'>2019</option>
                        <option value='2018'>2018</option>
                        <option value='2017'>2017</option>
                        <option value='2016'>2016</option>
                        <option value='2015'>2015</option>
                        <option value='2014' selected >2014</option>
                        <option value='2013'>2013</option>
                        <option value='2012'>2012</option>
                        <?php
                            } ?>           
                        <?php     
                            if($year=="2013")
                            {     ?>   
                        <option value='전체' >전체</option>     
                        <option value='2019'>2019</option>
                        <option value='2018'>2018</option>
                        <option value='2017'>2017</option>
                        <option value='2016'>2016</option>
                        <option value='2015'>2015</option>
                        <option value='2014'>2014</option>
                        <option value='2013' selected >2013</option>
                        <option value='2012'>2012</option>
                        <?php
                            } ?>             
                        <?php     
                            if($year=="2012")
                            {     ?>    
                        <option value='전체' >전체</option>           
                        <option value='2019'>2019</option>
                        <option value='2018'>2018</option>
                        <option value='2017'>2017</option>
                        <option value='2016'>2016</option>
                        <option value='2015'>2015</option>
                        <option value='2014'>2014</option>
                        <option value='2013'  >2013</option>
                        <option value='2012'selected >2012</option>
                        <?php
                            } ?>                    
                    </select>
                    </div>  

                    <div id="list_search2"> <img src="../img/select_search.gif"></div>
                    
                    <div id="list_search3">
                    <select name="find">
                        <?php     
                            if($find=="")
                            {     ?>    
                        <option value='all'>전체</option>
                        <option value='workplacename'>현장명</option>
                        <option value='firstord'>발주처</option>
                        <option value='chargedperson'>공사담당</option>
                        <option value='firstord'>건설사</option>
                        <option value='secondord'>발주처</option>
                        <option value='worker'>시공팀</option>
                        <option value='cablestaff'>결선팀</option>
                        <?php
                            } ?>    
                        <?php     
                            if($find=="all")
                            {     ?>    
                        <option value='all' selected>전체</option>
                        <option value='workplacename'>현장명</option>
                        <option value='firstord'>발주처</option>
                        <option value='chargedperson'>공사담당</option>
                        <option value='firstord'>건설사</option>
                        <option value='secondord'>발주처</option>
                        <option value='worker'>시공팀</option>
                        <option value='cablestaff'>결선팀</option>
                        <?php
                            } ?>
                        <?php
                            if($find=="workplacename")
                            {     ?>    
                        <option value='all' >전체</option>
                        <option value='workplacename' selected>현장명</option>
                        <option value='firstord'>발주처</option>
                        <option value='chargedperson'>공사담당</option>
                        <option value='firstord'>건설사</option>
                        <option value='secondord'>발주처</option>
                        <option value='worker'>시공팀</option>
                        <option value='cablestaff'>결선팀</option>
                        <?php
                            } ?>        
                        <?php
                            if($find=="firstord")
                            {     ?>    
                        <option value='all'>전체</option>
                        <option value='workplacename'>현장명</option>
                        <option value='firstord' selected>발주처</option>
                        <option value='chargedperson'>공사담당</option>
                        <option value='firstord'>건설사</option>
                        <option value='secondord'>발주처</option>
                        <option value='worker'>시공팀</option>
                        <option value='cablestaff'>결선팀</option>
                        <?php
                            } ?>        
                        <?php
                            if($find=="chargedperson")
                            {     ?>    
                        <option value='all'>전체</option>
                        <option value='workplacename'>현장명</option>
                        <option value='firstord'>발주처</option>
                        <option value='chargedperson' selected>공사담당</option>
                        <option value='firstord'>건설사</option>
                        <option value='secondord'>발주처</option>
                        <option value='worker'>시공팀</option>
                        <option value='cablestaff'>결선팀</option>
                        <?php
                            } ?>            
                        <?php
                            if($find=="firstord")
                            {     ?>    
                        <option value='all'>전체</option>
                        <option value='workplacename'>현장명</option>
                        <option value='firstord'>발주처</option>
                        <option value='chargedperson' >공사담당</option>
                        <option value='firstord' selected>건설사</option>
                        <option value='secondord'>발주처</option>
                        <option value='worker'>시공팀</option>
                        <option value='cablestaff'>결선팀</option>
                        <?php
                            } ?>          
                            <?php
                        if($find=="secondord")
                            {     ?>    
                        <option value='all'>전체</option>
                        <option value='workplacename'>현장명</option>
                        <option value='firstord'>발주처</option>
                        <option value='chargedperson' >공사담당</option>
                        <option value='firstord'>건설사</option>
                        <option value='secondord' selected>발주처</option>
                        <option value='worker'>시공팀</option>
                        <option value='cablestaff'>결선팀</option>
                        <?php
                            } ?>    
                            <?php       
                        if($find=="worker")
                            {     ?>    
                        <option value='all'>전체</option>
                        <option value='workplacename'>현장명</option>
                        <option value='firstord'>발주처</option>
                        <option value='chargedperson' >공사담당</option>
                        <option value='firstord'>건설사</option>
                        <option value='secondord' >발주처</option>
                        <option value='worker' selected>시공팀</option>
                        <option value='cablestaff'>결선팀</option>
                        <?php
                            } ?>  
                            <?php       
                        if($find=="cablestaff")
                            {     ?>    
                        <option value='all'>전체</option>
                        <option value='workplacename'>현장명</option>
                        <option value='firstord'>발주처</option>
                        <option value='chargedperson' >공사담당</option>
                        <option value='firstord'>건설사</option>
                        <option value='secondord' >발주처</option>
                        <option value='worker' >시공팀</option>
                        <option value='cablestaff' selected>결선팀</option>
                        <?php
                            } ?>          
                    </select>
                            
                    </div> <!-- end of list_search3 -->



                    <?php
                        ?>
                    <div id="list_search4"><input type="text" name="search" value="<?=$search?>"></div>                    
                    <div id="list_search5"><input type="image" src="../img/list_search_button.gif"></div>
                    <!-- end of list_search -->
                </div>
            </HEADER>




                    
                    
                    <div class="clear"></div>




                <SECTION>              

                  
                    
                    <TABLE class="c-table" style="width:100%">
                        <tr>
                            <th>번호</th>
                            <th>현장명</th>
                            <th>발주처</th>
                            <th>AS접수일</th>
                            <th>요청사항</th>
                            <th>처리예정일</th>
                            <th>세팅예정일</th>
                            <th>AS담당</th>
                            <th>공사단계</th>
                            <th>AS처리현황</th>
                            <th>무/유상 금액</th>
                        </tr>
               
                        <?php  
                        if ($page<=1)  
                        $start_num=$total_row;    // 페이지당 표시되는 첫번째 글순번
                        else 
                        $start_num=$total_row-($page-1) * $scale;
                    
                        while($row = $stmh->fetch(PDO::FETCH_ASSOC)) 
                        {
                        ?>
                        <tr>
                        <?
                            $item_num=$row["num"];
                            $item_id=$row["id"];
                            $item_name=$row["chargedperson"];
                            $item_nick=$row["nick"];
                            $item_hit=$row["hit"];
                            $item_man=$row["chargedperson"];
                            $item_date=$row["regist_day"];
                            $item_date=substr($item_date, 0, 10);
                            $item_orderco=$row["secondord"];
                            $item_orderman=$row["secondordman"];
                            $asday=$row["asday"];
                            $asproday=$row["asproday"];
                            $asman=$row["asman"];
                            $asfee=$row["asfee"];
                            $asfee_estimate=$row["asfee_estimate"];
                            $aswriter=$row["aswriter"];
                            $setdate=$row["setdate"];
                            $as_step=$row["as_step"];
                            $as_checkboxvalue1=$row["as_checkboxvalue1"];
                            $as_checkboxvalue2=$row["as_checkboxvalue2"];
                            $as_checkboxvalue3=$row["as_checkboxvalue3"];
                            $as_checkboxvalue4=$row["as_checkboxvalue4"];     
                            
                            
                            if($asfee=="1")
                                    if($asfee_estimate>0)
                                    $as_amount=$asfee_estimate;
                                    else 
                                    $as_amount="유상(금액미정)";
                                else
                                    $as_amount="";

                            // $item_subject=str_replace(" ", "&nbsp;", $row["workplacename"]);
                            $item_subject=$row["workplacename"];
                    //         if(strlen($item_subject)>=60)
                //            $item_subject=substr($item_subject,0,58) . "..";   // 글자수가 초과하면 ...으로 표기됨       
                            
                            
                            $state_work=0;
                            if($row["checkbox"]==0) $state_work=1;
                            if(substr($row["workday"],0,2)=="20") $state_work=2;
                            if(substr($row["endworkday"],0,2)=="20") $state_work=3;
                            if(substr($row["cableday"],0,2)=="20") $state_work=4;
                            if(substr($row["endcableday"],0,2)=="20") $state_work=5;
                                        
                            $font="black";
                            switch ($state_work) {
                                        case 1: $state_str="착공전"; $font="black";break;          
                                        case 2: $state_str="시공중"; $font="blue"; break;
                                        case 3: $state_str="결선대기"; $font="brown"; break;
                                        case 4: $state_str="결선중"; $font="purple"; break;
                                        case 5: $state_str="결선완료"; $font="red";break;             
                                        default: $font="grey"; $state_str="계약전"; 
                                    }

                            $state_as=0;    // AS 색상 등 표현하는 계산 
                            if(substr($row["asday"],0,2)=="20") $state_as=1;
                            if(substr($row["asproday"],0,2)=="20") $state_as=2;
                            if(substr($row["setdate"],0,2)=="20") $state_as=3;
                            if(substr($row["asendday"],0,2)=="20") $state_as=4; 

                        $font_as_step="black";
                        $as_tmp="";       
                        if($as_checkboxvalue1==null && $as_checkboxvalue2==null && $as_checkboxvalue3==null && $as_checkboxvalue4==null)
                                $as_tmp=$as_step;
                            else {
                            if($as_checkboxvalue1=='Y')
                                    $as_tmp .= "AS  ";
                            if($as_checkboxvalue2=='Y')
                                    $as_tmp .= "결선  ";
                            if($as_checkboxvalue3=='Y')
                                    $as_tmp .= "입결선  ";
                            if($as_checkboxvalue4=='Y')
                                    $as_tmp .= "셔터시공";
                            }
                            
                            
                            /*
                            switch ($as_step) {
                                        case "AS" : $font_as_step="blue";break;         
                                        case "결선" : $font_as_step="brown"; break;
                                        case "입결선" : $font_as_step="purple"; break;
                                        case "셔터시공": $font_as_step="red"; break;  
                                        default: $font_as_step="grey";
                                    }       
                            if($as_step=="없음") $as_step=""; 
                            
                            */
                            
                            if($asday=='0000-00-00') $asday="";         
                            if($asproday=='0000-00-00') $asproday="";         
                            if($setdate=='0000-00-00') $setdate="";         
                            
                            $font_as="black";
                            switch ($state_as) {
                                        case 1: $state_astext="접수완료"; $font_as="blue"; break;
                                        case 2: $state_astext="처리예약"; $font_as="grey"; break;
                                        case 3: $state_astext="세팅예약"; $font_as="green"; break;
                                        case 4: $state_astext="처리완료"; $font_as="red"; break;              
                                        default: $state_astext="미접수"; 
                                    }
                                    
                            $sql="select * from chandj.work_ripple where parent=$item_num";
                            $allstmh = $pdo->query($sql); 
                            $num_ripple=$allstmh->rowCount(); 
                            
                            
                            ?>
                        
                            <td id="assubject_item1"><?= $start_num ?></td>
                            <td id="assubject_item2"> <a href="view.php?num=<?=$item_num?>&page=<?=$page?>&find=<?=$find?>&search=<?=$search?>&process=<?=$process?>&asprocess=<?=$asprocess?>&yearcheckbox=<?=$yearcheckbox?>&year=<?=$year?>" style="font-size:13px" ><?= iconv_substr($item_subject,0,26,"utf-8") ?>&nbsp;</a>
                        <?php   
                                if($num_ripple)
                                print "[<font color=red><b>$num_ripple</b></font>]";
                            ?>
                            </td>   

                            <td id="assubject_item3"><?=iconv_substr($item_orderco,0,9, "utf-8")?>&nbsp;</td>
                            <td id="assubject_item4"><?=substr($asday,0,25)?>&nbsp;</td>
                            <td id="assubject_item10" style="color:blue;"> <?= $as_tmp?>&nbsp;</td>
                            <td id="assubject_item5"><?=substr($asproday,0,25)?>&nbsp;</td>
                            <td id="assubject_item11"><?=substr($setdate,0,25)?>&nbsp;</td>
                            <td id="assubject_item6"><?=substr($asman,0,25)?>&nbsp;</td>
                            <td id="assubject_item7" style="color:<?=$font?>;"><?= $state_str?>&nbsp;</td>

                            <td id="assubject_item8" style="color:<?=$font_as?>;">
                        <?php           
                            if($state_astext=="접수완료")
                                {
                                    ?>        
                        
                                    <?php
                                    }
                                ?>
                            <?= $state_astext?>&nbsp;</td>
                            <?php       
                            if($state_astext=="접수완료")
                                {
                                    ?>        
                                        </td>
                                    <?php
                                    }
                                ?>        
                            <td id="assubject_item9" style="color:red"><?= $as_amount?>&nbsp;</td>
                          

                        </tr>               
                        <?php
                        $start_num--;
                        } //WHILE_END

                } catch (PDOException $Exception) {
                print "오류: ".$Exception->getMessage();
                }  
                // 페이지 구분 블럭의 첫 페이지 수 계산 ($start_page)
                    $start_page = ($current_page - 1) * $page_scale + 1;
                // 페이지 구분 블럭의 마지막 페이지 수 계산 ($end_page)
                    $end_page = $start_page + $page_scale - 1;  
                ?>
                   
                </TABLE>    
                </SECTION>  


                <div id="page_button">
                <div id="page_num">  
                <?php
                    if($page!=1 && $page>$page_scale)
                    {
                    $prev_page = $page - $page_scale;    
                    // 이전 페이지값은 해당 페이지 수에서 리스트에 표시될 페이지수 만큼 감소
                    if($prev_page <= 0) 
                        $prev_page = 1;  // 만약 감소한 값이 0보다 작거나 같으면 1로 고정
                    print "<a href=list.php?page=$prev_page&search=$search&find=$find&list=1&process=$process&asprocess=$asprocess&yearcheckbox=$yearcheckbox&year=$year>◀ </a>";
                    }
                for($i=$start_page; $i<=$end_page && $i<= $total_page; $i++) 
                    {        // [1][2][3] 페이지 번호 목록 출력
                    if($page==$i) // 현재 위치한 페이지는 링크 출력을 하지 않도록 설정.
                        print "<font color=red><b>[$i]</b></font>"; 
                    else 
                        print "<a href=list.php?page=$i&search=$search&find=$find&list=1&process=$process&asprocess=$asprocess&yearcheckbox=$yearcheckbox&year=$year>[$i]</a>";
                }

                    if($page<$total_page)
                    {
                    $next_page = $page + $page_scale;
                    if($next_page > $total_page) 
                        $next_page = $total_page;
                    // netx_page 값이 전체 페이지수 보다 크면 맨 뒤 페이지로 이동시킴
                    print "<a href=list.php?page=$next_page&search=$search&find=$find&list=1&process=$process&asprocess=$asprocess&yearcheckbox=$yearcheckbox&year=$year> ▶</a><p>";
                    }
                ?>      
                    </div>
                    </div>

                <div id="write_button">
                <a href="list.php?&page=<?=$page?>&search=<?=$search?>&find=<?=$find?>&list=1&process=<?=$process?>&asprocess=<?=$asprocess?>&yearcheckbox=<?=$yearcheckbox?>&year=<?=$year?>"><img src="../img/list.png"></a>&nbsp;
                <?php
                if(isset($_SESSION["userid"]))
                {
                ?>
                <a href="write_form.php?num=<?=$num?>&page=<?=$page?>&search=<?=$search?>&find=<?=$find?>&process=<?=$process?>&asprocess=<?=$asprocess?>&yearcheckbox=<?=$yearcheckbox?>&year=<?=$year?>"> <img src="../img/write.png"></a>
                <?php
                }
                ?>
                    </div>
                    </DIV>
            </form>
        </DIV> <!-- end of col2 -->
    </DIV> <!-- end of content -->
</DIV> <!-- end of wrap -->









<script>
function blinker() {
   $('.blinking').fadeOut(500);
   $('.blinking').fadeIn(500);
}
setInterval(blinker, 1000);

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