<?
if (!defined('_GNUBOARD_')) exit;

//-- 팝업 공지사항 --------------------------------------------------------------------------------
function zm_popup_notice() {
	global $g4, $zmb, $config, $zm_config, $member;

	$content	= "";
	$now		= date("Y-m-d H:i:s", $g4[server_time]);

	//-- 시작일이 되었고 종료일이 지나지 않은 공지사항
	$mb_level	= $member[mb_level];
	if(!$member[mb_level])	$mb_level	= 1;

	if(!$is_admin)	$s_where	= "and db_target_level<='$mb_level'";
	$sql	= "select * from $zmb[table_popup_notice] where 1 and (db_start_datetime <= '$now' or db_end_datetime >= '$now') $s_where order by db_recno desc";
	$rs		= sql_query($sql);

	while($rd = sql_fetch_array($rs)) {
		if($rd[db_winstyle] == "3")
			$popup_skin_path = "$g4[path]/skin.mobile/popup/$rd[db_skin]";
		else
			$popup_skin_path = "$g4[path]/skin/popup/$rd[db_skin]";

		$recno		= $rd[db_recno];
		$ncode		= base64_encode($rd[db_recno]);
		$today		= date("Y-m-d", $g4[server_time]);

		$tmp_size	= explode("x", $rd[db_winsize]);
		$win_width	= $tmp_size[0];
		$win_height	= $tmp_size[1];
		$tmp_pos	= explode("x", $rd[db_winpos]);
		$win_top	= $tmp_pos[0];
		$win_left	= $tmp_pos[1];

		$sw_notice_path		= 1;
		$cook_popup_name	= "cook_popup_name_" . $recno;				//-- 이 레코드의 쿠키 이름
		
		if($_COOKIE[$cook_popup_name] && ($_COOKIE[$cook_popup_name] == $today))	$sw_notice_path = 0;			//-- 쿠키 날짜가 오늘 날짜이면 팝업 띄우지 않는다.

		if($sw_notice_path) {
			//-- 새창 일 때 -------------------------
			if($rd[db_winstyle] == "1") {
				$content	.= "<script language='javascript'>";
				$content	.= "window.open('$popup_skin_path/popup.skin.php?ncode=$ncode', 'popup_$recno', 'width=$win_width, height=$win_height, top=$win_top, left=$win_left, toolbar=0, scrollbars=0, resizable=0');";
				$content	.= "</script>";
			}elseif($rd[db_winstyle] == "2"){
			//-- 레이어 스타일 ----------------------
				$content	.= "<style type='text/css'>";
				$content	.= "#div_popup_$recno	{ position:absolute; top:".$win_top."px; left:".$win_left."px; padding:20px 0 0 0; z-index:100; }";
				$content	.= "#div_movement_$recno	{ display:none; cursor:move; }";
				$content	.= "#frm_popup_$recno	{ border:0px; background-color:#ffffff; }";
				$content	.= "</style>";
				$content	.= "<script language='javascript' src='$g4[path]/zm.extend/js/jquery.easydrag.js'></script>";
				$content	.= "<div id='div_popup_$recno' class='div_popup'>";
				$content	.= "	<div style='height:26px;'><div id='div_movement_$recno'><img src='$popup_skin_path/img/btn_winclose.gif'></div></div>";
				$content	.= "	<iframe id='frm_popup_$recno' name='frm_popup_$recno' src='$popup_skin_path/popup.skin.php?ncode=$ncode' frameborder='0' width='$win_width' height='$win_height' marginwidth='0' marginheight='0' scrolling='no'></iframe>";
				$content	.= "</div>";
				$content	.= "<script language='javascript'>";
				$content	.= "$(function() {";
				$content	.= "	$('#div_popup_$recno').easydrag();";
				$content	.= "});";

				$content	.= "$('#div_popup_$recno').mouseover(function() {";
				$content	.= "	$('#div_movement_$recno').css('display', 'block');";
				$content	.= "}).mouseout(function() {";
				$content	.= "	$('#div_movement_$recno').css('display', 'none');";
				$content	.= "});";
				$content	.= "</script>";
			}
			if($rd[db_winstyle] == "3" && ZM_IS_MOBILE){
			//-- 모바일 일 때
				ob_start(); ?>
				<style>
					#div_popup_<?=$recno?>	{ position:absolute; top:0px; left:0px; z-index:1000; background:#ffffff; }
				</style>
				<div id='div_popup_<?=$recno?>' class='div_popup'>
					<iframe id='frm_popup_<?=$recno?>' name='frm_popup_<?=$recno?>' src='<?=$popup_skin_path?>/popup.skin.php?ncode=<?=$ncode?>' frameborder='0' marginwidth='0' marginheight='0' scrolling='no' width="100%" style="height:100%;"></iframe>
				</div>
				<script>
				$(function(){
					$("body, html").scrollTop(0);

					var w = $(window).width();
					var h = $(window).height();
					var dh = $(document).height();	//-- 문서 높이
					$("#div_popup_<?=$recno?>").css("height", dh+"px");

					$("#frm_popup_<?=$recno?>").css("width", w+"px");
					$("#frm_popup_<?=$recno?>").css("height", h+"px");
				});
				</script>
<?				$content	.= ob_get_contents();
				ob_end_clean();
			}
		} //-- $sw_notice_path
	} 

	return $content;
}
?>