<?php
if(!isset($_SESSION)) {
session_start();
}
require_once '../dbconnect.php';
require_once '../phpclass/dbClass.php';
require_once '../phpclass/bbsClass.php';
require_once '../phpclass/adminClass.php';
$a = new adminClass();
$b = new bbsClass();
$c = new MySQLDbClass();
// 설문 테이블 상태 변경 체크
$a->surveyDBupdate();
$url = $_SERVER['PHP_SELF']; // 현재 실행중인 파일명 가져오기
$page = isset($_GET['page'])? trim($_GET['page']):1;//페이지 변수 설정
$rowsPage = 10; // 한 화면에 표시되는 게시글 수
$curPage = isset($_GET['p']) ? $_GET['p'] : 1;
$bd_name = isset($_GET['bd_name']) ? $_GET['bd_name'] :'';
$mode = isset($_GET['mode']) ? $_GET['mode'] :'list';
$sel = isset($_GET['sel'])? $_GET['sel'] : '';
$flddata ="*";// 화면에 출력할 칼럼 발췌
$where = isset($_GET['where']) ? $_GET['where']: '';
$keyword = isset($_GET['keyword']) ? $_GET['keyword']: '';
$xorderby= isset($xorderby) ? $xorderby : 'uid DESC';
if($where && $keyword) {
if($where == 'title') $sql = "title LIKE '%".$keyword."%' ";
if($where == 'content') $sql = "content LIKE '%".$keyword."%' ";
if($where == 'unify') {
$sql = "(title LIKE '%".$keyword."%' OR content LIKE '%".$keyword."%') ";
}
} else {
$sql ='';
}
if(!empty($sel)){
if($keyword){
$sql .= " and status = ".$sel;
} else {
$sql = " status = ".$sel;
}
}
//echo $sql.'<br />';
$link_url=($bd_name?'bd_name='.$bd_name.'&':'').($mode?'mode='.$mode.'&':'').($sel?'sel='.$sel.'&':'').($where?'where='.$where.'&':'').($keyword?'keyword='.urlencode(stripslashes($keyword)).'&':'');
$g['bbs_reset'] = $url; // 초기화
$table ='poll_admin';
$rows= $c->getDbArray($table,$sql,$flddata,$xorderby,$rowsPage,$curPage);
$NUM = $c->getDbRows($table,$sql); // 전체 게시글수
$TPG = $b->getTotalPage($NUM,$rowsPage);
?>
<!DOCTYPE html>
<head>
<title><?php echo $title;?></title>
<meta charset="utf-8">
<meta name="robots" content="noindex,nofollow"/>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="../vendor/bootstrap/css/bootstrap.min.css">
<link href="vendor/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" type="text/css" href="../css/survey.css" />
<script src="../vendor/jquery/jquery.min.js"></script>
<script src="../vendor/bootstrap/js/bootstrap.min.js"></script>
<script src="../js/modal.js"></script>
</head>
<body>
<div class="container">
<table class="table table-bordered">
<tr>
<td align=center><font class='title'><b>설문조사<br><br>
<div class="pull-left info bmargin">
<select name='sel' onchange='document.searchf.sel.value=this.value;document.searchf.submit();'>
<option value=''>전체목록보기</option>
<option value='1' <?php if("1"==$sel):?> selected<?php endif?>>진행중목록</option>
<option value='2' <?php if("2"==$sel):?> selected<?php endif?>>종료 목록</option>");
</select>
</div>
<div class="pull-right info bmargin">
<a href='survey_admin.php'><button class="w3-button w3-blue-grey w3-tiny">관리</button></a>
<a href='add_form.php?mode=new'><button class="w3-button w3-blue-grey w3-tiny">등록</button></a>
</div>
<!-- 설문 내용 -->
<table class='w3-table w3-bordered'>
<thead>
<tr class="w3-blue-grey">
<th width="8%">No</th>
<th width="43%">설문 제목</th>
<th width="11%">총응답</th>
<th width="13%">시작일</th>
<th width="13%">종료일</th>
<th width="10%">상 태</th>
</tr>
</thead>
<tbody>
<?php $i=1;foreach($rows as $R):?>
<tr>
<td><?php echo $i;?></td>
<td>
<?php
$memo=" <a href='survey_memo.php?bd_name=".$R['bd_name']."&mode=list&sel=".$sel."'><img src='./image/memo.gif' border='0' alt='메모보기'></a>";
if($R['enddate'] < date("Y-m-d")){
echo "<a href='survey_res.php?bd_name=".$R['bd_name']."&sel=".$sel."'> ".$R['title']."</a>$memo</td>";
$status = "종 료";
} else {
if($R['startdate'] > date("Y-m-d")) $status = "준비중";
else $status = "진행중</td>";
echo "<a href='survey.php?bd_name=".$R['bd_name']."&sel=".$sel."'> ".$R['title']."</a>$memo</td>";
}
?>
</td>
<td><?php echo $R['totalcnt'];?></td>
<td><?php echo $R['startdate'];?></td>
<td><?php echo $R['enddate'];?></td>
<td><?php echo $status;?></td>
</tr>
<?php $i++;endforeach;?>
</tbody>
</table>
<div><br></div>
<div class='searchbox'>
<form name="searchf" class="form-inline" action="<?php echo $url.'?'.$link_url;?>">
<input type="hidden" name="mode" value="<?php echo $mode?>" />
<input type="hidden" name="sel" value="<?php echo $sel?>" />
<input type="hidden" name="p" value="1" />
<select name="where" class="form-control input-sm">
<option value="unify">통합</option>
<option value="title">제목</option>
<option value="content">설명</option>
</select>
<div class="input-group input-group-sm">
<input type="text" name="keyword" value="" class="form-control input-search" placeholder="검색어">
<span class="input-group-btn">
<button type="button" class="btn btn-default" onclick="this.form.where.value='title';this.form.keyword.value='',this.form.submit();" title="리셋"><i class="glyphicon glyphicon-repeat"></i></button>
<button type="submit" class="btn btn-info" title="검색"><i class="glyphicon glyphicon-search"></i></button>
</span>
</div>
</form>
</div>
<div class="pull-right info">
<a href="<?php echo $g['bbs_reset']?>" class="btn btn-default btn-sm pull-right">처음목록</a>
</div>
<?php $b->PageLinkView($url,$NUM,$rowsPage,$curPage,$link_url);?>
</td>
</tr>
</table>
</div>
</body>
</html>
<?php mysqli_close($db);?>