<?
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 '$now' between db_start_datetime and db_end_datetime $s_where order by db_recno desc";
	$rs		= sql_query($sql);

	while($rd = sql_fetch_array($rs)) {
		$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>";
			}else{
			//-- 레이어 스타일 ----------------------
				$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>";
			}
		}
	}

	return $content;
}
?>