<? include ("./header.php"); 

include $_SERVER[DOCUMENT_ROOT] . "/module/shop/shop.lib.php";
include $_SERVER[DOCUMENT_ROOT] . "/module/member/member.lib.php";
include $_SERVER[DOCUMENT_ROOT] . "/module/shop/review/review.lib.php";
include $_SERVER[DOCUMENT_ROOT] . "/module/board/board.lib.php";
include $_SERVER[DOCUMENT_ROOT] . "/module/log/log.lib.php";
include $_SERVER[DOCUMENT_ROOT] . "/module/one_to_one/one_to_one.lib.php";

//DB연결
$dblink = SetConn($_conf_db["main_db"]);

$yesterday = date("Y-m-d",mktime(0,0,0,date("m"),date("d")-1,date("Y")));
$yesterday6 = date("Y-m-d",mktime(0,0,0,date("m"),date("d")-6,date("Y")));
$monthFirst = date("Y-m")."-01";

$_REQUEST[sh_date] = "order_date";
$_REQUEST[pay_opt]="A";

$arrList = getArticleList($_conf_tbl["board_info"], $scale, $_REQUEST[offset], "");
//$arrBoardNoticeList = getBoardListBaseNMemoCnt("notice", "", "", "", "4", 0);	//공지사항

/*
$arrOneList = getOneToOneListAll("", "", "4", 0); //1:1문의
$arrBoardAfterList = getBoardListBaseNMemoCnt("after", "", "", "", "4", 0); //이용후기
$arrBoardQnaList = getBoardListBaseNMemoCnt("qna", "", "", "", "4", 0);	//상품문의

//1:1 미답변 시작
$arrOneMiList = getOneToOneListAll("st", "N", "4", 0); 
if($arrOneMiList['list']['total'] > 0):
for ($i=0;$i<$arrOneMiList['list']['total'];$i++) {
	$sql = "insert into tbl_board_admin_tmp values ('one', '/backoffice/module/one_to_one/one_to_one_info.php?idx=','".$arrOneMiList['list'][$i]['idx']."','".$arrOneMiList['list'][$i]['subject']."','".$arrOneMiList['list'][$i]['wdate']."');";
	$rs = mysql_query($sql, $GLOBALS[dblink]);
}
endif;
//1:1 미답변 끝

//qna 미답변 시작
$arrQnaMiList = getBoardListMiQna("qna", "", "", "", "4", 0); 
if($arrQnaMiList['list']['total'] > 0):
for ($i=0;$i<$arrQnaMiList['list']['total'];$i++) {
	$sql = "insert into tbl_board_admin_tmp values ('qna', '/backoffice/module/board/board_view.php?boardid=qna&mode=view&idx=','".$arrQnaMiList['list'][$i]['idx']."','".$arrQnaMiList['list'][$i]['subject']."','".$arrQnaMiList['list'][$i]['wdate']."');";
	$rs = mysql_query($sql, $GLOBALS[dblink]);
}
endif;
//qna 미답변 끝


$arrMiList = getListByTbl("tbl_board_admin_tmp", " order by wdate desc"); //미답변게시판
*/

if(!$_REQUEST[cal_date]){
	$cal_date = date("Y-m-d");
}else{
	$cal_date = $_REQUEST[cal_date];
}
//날짜를 - 구분자로 배열로 만듬
$arrDate = explode("-",$cal_date);

$arrSolarCalendar = getDiarySet(intval($arrDate[0]), intval($arrDate[1]), intval($arrDate[2]));
$arrBoardList = getBoardListSchedule("schedule", $arrSolarCalendar[first_before], $arrSolarCalendar[last_after]);

//DB해제
//SetDisConn($dblink);
?>
<script>
function addTestBoardArticle(updatemode){
	document.frmLogInfo.evnMode.value=updatemode;
	document.frmLogInfo.submit();
}
</script>
<form name="frmLogInfo" method="post" action="/backoffice/module/admin/admin_evn.php">
<input type="hidden" name="evnMode" value="">
<input type="hidden" name="rt_url" value="<?=$_SERVER[PHP_SELF]?>">
</form>

<link href="/css/board.css" rel="stylesheet" type="text/css" />


<div id="admin-container">
	<div class="admin-snb">
		<div class="admin-snb-group">
			<div class="snb-title"><h2>기본설정</h2></div>
			<ul class="snb-menu">
				<li><a href="/backoffice/module/admin/admin.php">기본정보 설정</a></li>
			</ul>
		</div>
		<!-- <div class="admin-snb-group">
			<div class="snb-title"><h2>상품관리</h2></div>
			<ul class="snb-menu">
				<li><a href="/backoffice/module/shop/good.php">상품 관리</a></li>
				<li><a href="/backoffice/module/shop/good_add.php">상품 등록</a></li>
				<li><a href="/backoffice/module/category/category.php">분류 관리</a></li>
			</ul>
		</div> -->
		<div class="admin-snb-group">
			<div class="snb-title"><h2>게시판</h2></div>
			<ul class="snb-menu">
				<li><a href="/backoffice/module/board/board.php">게시판 관리</a></li>
				<?if($siteip_chk==true){?>
				<li><a href="javascript:addTestBoardArticle('addBoardAddTest');">전체게시판 테스트게시글 등록</a></li>
				<?}?>
				<!-- <li><a href="/backoffice/module/board/comment_list.php">댓글 등록</a></li> -->
			</ul>
		</div>
		<!-- <div class="admin-snb-group">
			<div class="snb-title"><h2>메일/문자 발송</h2></div>
			<ul class="snb-menu">
				<li><a href="/backoffice/mailsms1.php">문자/메일 충전</a></li>
				<li><a href="/backoffice/mailsms2.php">문자/메일 발송</a></li>
				<li><a href="/backoffice/mailsms3.php">충전결과</a></li>
			</ul>
		</div> -->
		<? include "admin_info.php"; ?>
	</div>
<script>
function viewCount(gb) {
	if(gb == "1") {
		document.getElementById("tcounter").src="iframe_count1.php";
	} else if(gb == "2") {
		document.getElementById("tcounter").src="iframe_count2.php";
	} else if(gb == "3") {
		document.getElementById("tcounter").src="iframe_count3.php";
	}
	
}
</script>
	<div id="admin-content">
		<!--// content -->
		<h2 class="admin-title">관리자메인</h2>

		<div class="admin-top">
			<!-- 그래프 -->
			<div id="tabs" class="admin-graph">
				<div class="admin-tab">
					<ul class="tabe">
						<li><a href="#tab1" onclick="viewCount(1)">접속현황</a></li>
						<? if(in_array("shop_accounts_manage", $arrayMyMenu) && (in_array("shop_accounts_manage",$_SESSION[$_SITE["DOMAIN"]]["ADMIN"]["AUTH"]) || $_SESSION[$_SITE["DOMAIN"]]["ADMIN"]["GRADE"]=="ROOT")){?>
						<li><a href="#tab2" onclick="viewCount(2)">매출현황</a></li>
						<?}?>
						<? if(in_array("member_manage", $arrayMyMenu) && (in_array("member_manage",$_SESSION[$_SITE["DOMAIN"]]["ADMIN"]["AUTH"]) || $_SESSION[$_SITE["DOMAIN"]]["ADMIN"]["GRADE"]=="ROOT")){?>
						<li><a href="#tab3" onclick="viewCount(3)">회원현황</a></li>
						<?}?>
					</ul>
				</div>
				
				<iframe name="tcounter" id="tcounter" src="iframe_count1.php" frameborder="0" marginheight="0" marginwidth="0" scrolling="no" width="1050" height="200"></iframe>
			</div>
		
			<!-- 일정달력 -->
			<script type="text/javascript">
				jQuery(function(){
					<?
					//DB연결
					$dblink = SetConn($_conf_db["main_db"]);

					for($i=1; $i<32; $i++){
							if($i<10) $i="0".$i;

							$cdate = $arrDate[0]."-".$arrDate[1]."-".$i;
							$week = date("w", mktime(0, 0, 0, $arrDate[1], $i, $arrDate[0]));
							$arrInfo[$i] = getBoardArticleSchedule("schedule", $cdate);
					?>
					jQuery('.calendar-table .date<?=$i?>').click(function(){
						jQuery('.calendar-layer').show();
						document.getElementById('ndateID').innerHTML = "<?=$arrDate[0]?>년 <?=$arrDate[1]?>월 <?=$i?>일 (<?=$_SITE["SHOP"]["WEEK"][$week]?>)";
						document.getElementById('schedule_date').value = "<?=$cdate?>";
						document.getElementById('idx').value = "<?=$arrInfo[$i]["list"][0][idx]?>";
						document.getElementById('idx2').value = "<?=$arrInfo[$i]["list"][0][idx]?>";
						document.getElementById('subject').value = "<?=$arrInfo[$i]["list"][0][subject]?>";
						document.getElementById('contents').value = "<?=str_replace("\r\n", "<br>",$arrInfo[$i]["list"][0][contents])?>";
						document.getElementById('contents').value = document.getElementById('contents').value.replace(/<br>/g, "\r\n"); 
					<?if($arrInfo[$i]["list"][0][idx]) {?>
						document.getElementById('evnMode').value = "modify";
						<?}else{?>
						document.getElementById('evnMode').value = "write";
						<?}?>
					});
					<?}?>
					jQuery('.calendar-layer .close').click(function(){
						jQuery('.calendar-layer').hide();
					});
				});

				function delSchedule() {
					var cfm;
					cfm =false;
					cfm = confirm("해당 삭제 하시겠습니까?");
					if(cfm==true){
						document.sfrm2.submit();
					}
				}
			</script>
			<div class="admin-calendar">
				<!-- 스케쥴등록 -->
				<div class="calendar-layer">
					<form name="sfrm"  method="post" action="/module/board/board_evn.php">
					<input type="hidden" name="boardid" value="schedule">
					<input type="hidden" name="idx" id="idx" value="">
					<input type="hidden" name="schedule_date" id="schedule_date" value="">
					<input type="hidden" name="evnMode" id="evnMode" value="write">
					<input type="hidden" name="usehtml" value="N">
					<input type="hidden" name="returnURL" value="/backoffice">
						<div class="contents">
							<p>
								<strong>일정등록</strong>
								<span class="ndateID" id="ndateID">2014년 07월 10일 (목)</span>
							</p>
							<fieldset>
								<legend>일정 등록 폼</legend>
								<table>
								  <colgroup>
								    <col width="18%" />
									<col />
								  </colgroup>
								  <tbody>
								    <tr>
									  <th scope="row">제목</th>
									  <td><input type="text" name="subject" id="subject" class="input" style="width:250px;" /></td>
									</tr>
									<tr>
									  <th scope="row">내용</th>
									  <td><textarea name="contents1" id="contents" cols="18" rows="5" class="textarea" style="width:248px;height:84px;"></textarea></td>
									</tr>
								  </tbody>
								</table>
							</fieldset>
							<div class="admin-buttons">
								<div class="cen">
									<span class="btn_pack medium"><input type="submit" value="등록" /></span>
									<span class="btn_pack medium"><a href="javascript:delSchedule();">삭제</a></span>
								</div>
							</div>
							<button title="닫기" class="close" type="button">닫기</button>
						</div>
					</form>
					<form name="sfrm2"  method="post" action="/module/board/board_evn.php">
					<input type="hidden" name="boardid" value="schedule">
					<input type="hidden" name="evnMode" value="delete">
					<input type="hidden" name="idx" id="idx2" value="">
					<input type="hidden" name="returnURL" value="/backoffice">
					</form>
				</div>
				<!-- 달력 -->
				<div class="calendar-table">
					<div class="year">
						<!-- <button title="이전년도" class="year prev" type="button">이전년도</button> -->
						<strong><?=$arrDate[0]?></strong>
						<!-- <button title="다음년도" class="year next" type="button">다음년도</button> -->
					</div>
					<div class="month">
						<a href="<?=$_SERVER[PHP_SELF]?>?cal_date=<?=$arrSolarCalendar[prev_month]?>"><button title="이전달" class="month prev" type="button">이전달</button></a>
						<strong><?=$arrDate[1]?></strong>
						<a href="<?=$_SERVER[PHP_SELF]?>?cal_date=<?=$arrSolarCalendar[next_month]?>"><button title="다음달" class="month next" type="button">다음달</button></a>
					</div>
					<table summary="달력에서 일정 등록 및 확인이 가능합니다.">
					  <thead>
					    <tr>
						  <th class="sun" scope="col">SUN</th>
						  <th scope="col">MON</th>
						  <th scope="col">TUE</th>
						  <th scope="col">WED</th>
						  <th scope="col">THU</th>
						  <th scope="col">FRI</th>
						  <th class="sat" scope="col">SAT</th>
						</tr>
					  </thead>
					  <tbody>
					    <?for($i=0;$i<count($arrSolarCalendar["box"]);$i++){?>
						<tr>
						  <?for($j=0;$j<7;$j++){
							//국경일, 법정공휴일, 일요일의 경우
							if($arrLunarCalendar[$arrSolarCalendar["box"][$i][$j]][holiday]=="1" || $j==0){
								$bgcolor = "sun";
							//토요일의 경우
							}else if($j==6){
								$bgcolor = "sat";
							}else{
								$bgcolor = "weekdays";
							}

							if($arrSolarCalendar["box"][$i][$j]==date("Y-m-d")) {
								$tdclass[$i][$j] .= "today";
							} else {
								$tdclass[$i][$j] .= "";
							}

							if(is_array($arrBoardList["list"][$arrSolarCalendar["box"][$i][$j]])){
								foreach($arrBoardList["list"][$arrSolarCalendar["box"][$i][$j]] AS $key => $val){
									$tdclass[$i][$j] .=" schedule-on";
								}
							} else {
								$tdclass[$i][$j] .="";
							}
						  ?>
						  <td class="<?=$tdclass[$i][$j]?>"><? if($arrDate[1]==substr($arrSolarCalendar["box"][$i][$j],5,2)) {?><a class="date<?=substr($arrSolarCalendar["box"][$i][$j],-2)?> <?=$bgcolor?>" style="cursor:pointer;"><?=substr($arrSolarCalendar["box"][$i][$j],-2)?></a><?}?></td>
						  <?}?>
					  </tr>
					  <?}?>
					  </tbody>
					</table>
				</div>
			</div>
		</div>
		<br />
		<br />
		<? if(in_array("shop_accounts_manage", $arrayMyMenu) && (in_array("shop_accounts_manage",$_SESSION[$_SITE["DOMAIN"]]["ADMIN"]["AUTH"]) || $_SESSION[$_SITE["DOMAIN"]]["ADMIN"]["GRADE"]=="ROOT")){?>
		<h3 class="admin-title-middle">쇼핑몰 현황</h3>
		<table class="admin-table-main">
		  <colgroup>
		    <col width="*" />
			<col width="14%" span="6" />
		  </colgroup>
		  <thead>
		    <tr>
			  <th scope="col">날짜</th>
			  <th scope="col">매출액</th>
			  <th scope="col">주문건수</th>
			  <th scope="col">입금대기</th>
			  <th scope="col">입금확인</th>
			  <th scope="col">배송중</th>
			  <th scope="col">거래완료</th>
			</tr>
		  </thead>
		  <tbody>
		    <? for($i=0; $i<7; $i++) {
					$j = 6-$i;
					$ldate[$i] = date("Y-m-d", mktime(0, 0, 0, date("m"), date("d")-$j,  date("Y")));
		
					$arrMoney[$i] = getAccountStatus($ldate[$i], $ldate[$i]);
					$totalMoney += $arrMoney[$i]['list_sum'][pay_amount];
		
					$arrOrder[$i] = getOrderListAdmin("", "", $ldate[$i], $ldate[$i], "", 0, 0);
					$totalOrder += $arrOrder[$i][total];
		
					$arrOrder1[$i] = getOrderListAdmin("", "", $ldate[$i], $ldate[$i], "1", 0, 0);
					$totalOrder1 += $arrOrder1[$i][total];
		
					$arrOrder6[$i] = getOrderListAdmin("", "", $ldate[$i], $ldate[$i], "6", 0, 0);
					$totalOrder6 += $arrOrder6[$i][total];
		
					$arrOrder8[$i] = getOrderListAdmin("", "", $ldate[$i], $ldate[$i], "8", 0, 0);
					$totalOrder8 += $arrOrder8[$i][total];
					
					$arrOrder9[$i] = getOrderListAdmin("", "", $ldate[$i], $ldate[$i], "9", 0, 0);
					$totalOrder9 += $arrOrder9[$i][total];
			?>
			<tr<?=$i=="6"?" class='today'":""?>>
			  <th><?=str_replace("-","월 ",substr($ldate[$i],5,5))?>일 <?=$i=="6"?" (금일)":""?></th>
			  <td><?=number_format($arrMoney[$i]['list_sum'][pay_amount])?>원</td>
			  <td><?=number_format($arrOrder[$i][total])?>건</td>
			  <td><?=number_format($arrOrder1[$i][total])?>건</td>
			  <td><?=number_format($arrOrder6[$i][total])?>건</td>
			  <td><?=number_format($arrOrder8[$i][total])?>건</td>
			  <td><?=number_format($arrOrder9[$i][total])?>건</td>
			</tr>
			<?}
			//DB해제
			SetDisConn($dblink);
			?>
			<tr class="total">
			  <th>합계</th>
			  <td><?=number_format($totalMoney)?>원</td>
			  <td><?=number_format($totalOrder)?>건</td>
			  <td><?=number_format($totalOrder1)?>건</td>
			  <td><?=number_format($totalOrder6)?>건</td>
			  <td><?=number_format($totalOrder8)?>건</td>
			  <td><?=number_format($totalOrder9)?>건</td>
			</tr>
		  </tbody>
		</table>
		<br />
		<?}?>

		<!-- 커뮤니티
		<div class="admin-comm">
			<div class="column2 first">
				<div class="admin-board">
					<h3>미답변 게시물</h3>
					<ul>
						<?
						if($arrMiList["total"] > 0){
							for($i=0; $i < $arrMiList["total"]; $i++){
						?>
						<li>[<?=$arrMiList["list"][$i][boardid]=="one"?"1:1게시판":"상품문의"?>] <a href="<?=$arrMiList["list"][$i][linkurl]?><?=$arrMiList["list"][$i][b_idx]?>"><?=text_cut($arrMiList["list"][$i][subject],30)?></a> <span><?=substr($arrMiList["list"][$i][wdate],0,10)?></span></li>
						<?}}?>
					</ul>
				</div>
			</div>
			<div class="column1">
				<div class="admin-board">
					<h3><a href="/backoffice/module/one_to_one/one_to_one.php">1:1문의</a></h3>
					<ul>
						<?if($arrOneList['list']['total'] > 0):?>
						<?for ($i=0;$i<$arrOneList['list']['total'];$i++) {?>
						<li><a href="/backoffice/module/one_to_one/one_to_one_info.php?idx=<?=$arrOneList['list'][$i]['idx']?>"><?=stripslashes($arrOneList['list'][$i]['subject'])?></a></li>
						<?} endif; ?>
					</ul>
				</div>
			</div>
			<div class="column1">
				<div class="admin-board">
					<h3><a href="/backoffice/module/board/board_view.php?boardid=qna">상품문의</a></h3>
					<ul>
						<?
						if($arrBoardQnaList["list"]["total"] > 0){
						for($i=0; $i < $arrBoardQnaList["list"]["total"]; $i++){
						?>
						<li><a href="/backoffice/module/board/board_view.php?boardid=qna&mode=view&idx=<?=$arrBoardQnaList["list"][$i][idx]?>&offset=<?=$_GET[offset]?>"><?=text_cut(stripslashes($arrBoardQnaList["list"][$i][subject]),40)?></a></li>
						<?}}?>
					</ul>
				</div>
			</div>
			<div class="column1 last">
				<div class="admin-board">
					<h3><a href="/backoffice/module/board/board_view.php?boardid=after">상품후기</a></h3>
					<ul>
						<?
						if($arrBoardAfterList["list"]["total"] > 0){
						for($i=0; $i < $arrBoardAfterList["list"]["total"]; $i++){
						?>
						<li><a href="/backoffice/module/board/board_view.php?boardid=after&mode=view&idx=<?=$arrBoardAfterList["list"][$i][idx]?>&offset=<?=$_GET[offset]?>"><?=text_cut(stripslashes($arrBoardAfterList["list"][$i][subject]),40)?></a></li>
						<?}}?>
					</ul>
				</div>
			</div>
		</div>
        <!-- content //-->
		<br /><br />
		
		<div class="admin-comm">
			<?
			//DB연결
			$dblink = SetConn($_conf_db["main_db"]);
			if($arrList['list']['total'] > 0){
			for ($i=0;$i<$arrList['list']['total'];$i++) {
				$arrBoardList = getBoardListBase($arrList['list'][$i]['boardid'], "", "", "", "4", 0);	//공지사항
			?>
			<div class="column1 first">
				<div class="admin-board">
					<h3><?=$arrList['list'][$i]['boardname']?></h3>
					<ul>
						<?
						if($arrBoardList["list"]["total"] > 0){
						for($a=0; $a < $arrBoardList["list"]["total"]; $a++){
						?>
						<li><a href="/backoffice/module/board/board_view.php?boardid=<?=$arrList["list"][$i][boardid]?>&mode=view&idx=<?=$arrBoardList["list"][$a][idx]?>&offset=<?=$_GET[offset]?>"><?=text_cut(stripslashes($arrBoardList["list"][$a][subject]),40)?></a></li>
						<?}}?>
					</ul>
				</div>
			</div>
			<?
				if(($i+1)%4==0){
					echo "</div> </br><div class='admin-comm'>";
				}
			}}
			?>
		</div>
		
    </div>
</div>

<?
//DB연결
$dblink = SetConn($_conf_db["main_db"]);
$sql = "delete from tbl_board_admin_tmp";
$rs = mysql_query($sql, $GLOBALS[dblink]);
//DB해제
SetDisConn($dblink);

include ("./footer.php"); ?>