<?php
session_start();
if (!defined('YEE_ROOT'))
	define('YEE_ROOT', './admin/');
	
	require_once YEE_ROOT.'include/essentials.php';

	//- get the db object
	global $db;
	//print_r($_SESSION);
	$logout = isset($_REQUEST['logout'])?intval($_REQUEST['logout']):0;
	if (1 == $logout) 
	{
		unset($_SESSION['user_info']);
		unset($_SESSION['login']);
		header('Location: photo.php');
	}
	
	if(isset($_SESSION['user_info'])) 
	{
		header('Location: photo.php');
	}
	
	if (isset($_POST['username'])&& isset($_POST['password'])) 
	{
		$username =  addslashes($_POST['username']);
		$password = $_POST['password'];
		
		$query = array(
				'SELECT' 	=> '*',
				'FROM'		=> array('members' => 'm'),
				'WHERE'		=> 'm.member_name = \''.$username.'\'',
				);
				
		if($result = $db->sql_query($db->sql_build_query('SELECT',$query)))
		{
			$user_info = $db->sql_fetchrow($result);
			if (md5($password) == $user_info['password']) 
			{
				header('Location: photo.php');
				$_SESSION['user_info'] = $user_info;
				$_SESSION['login'] = 1 ;
			}
		}
	}
	
	if (isset($_SESSION['user_info']['member_id'])) {
		$memeber_id = intval($_SESSION['user_info']['member_id']);
		$member_actives = get_actives_of_class($memeber_id);		
	}
	
	//get all the act by year & month
	$query_acts = array(
				'SELECT' 	=> '*',
				'FROM'		=> array('manufacturers' => 'm'),
				'ORDER_BY'	=>	'm.year_id,m.month_id ASC',
				);	
	
	if($result = $db->sql_query($db->sql_build_query('SELECT',$query_acts)))
	{	
	 	$acts_result = $db->sql_fetchrowset($result);			
	}else 
	{
		$acts_result = false;
	}

	foreach ($acts_result as $act)
	{
		$act_by_date[$act['year_id']][$act['month_id']][] = array('id'=>$act['id'],'name'=> $act['name']);
	}	
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>衛斯理幼稚園</title>
<link rel=stylesheet type="text/css" href="style.css"/>
<style type="text/css">
<!--
body {
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
}
-->
</style>
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->
</script>

<link rel="stylesheet" type="text/css" href="gallery_css/slideshow.css" media="screen" />
<link rel="stylesheet" type="text/css" href="gallery_css/demo.css" media="screen" />
<link rel="stylesheet" type="text/css" href="gallery_css/lightbox.css" media="screen" />
<script type="text/javascript" src="js/mootools.js"></script>
<script type="text/javascript" src="js/lightbox.js"></script>
<script type="text/javascript" src="js/slideshow.js"></script>
<script type="text/javascript" src="js/slideshow.kenburns.js"></script>
<script type="text/javascript">
//bof the menu
window.addEvent('domready', function() {
	$$('p.year').addEvent('click', function(event){
		event = new Event(event);
		
		var parent_p_id = $('clicked_value').get('value');
		var parent_p = $(parent_p_id);
		//alert(event.target.get('id'));
		$$('p.year').each(function(el)
		{		
			var cur_year = el.get('id');
			var cur_month;
			//var the_last_month = 1;
			if(el != parent_p)
			{
				for(var i=1;i<=12;i++)
				{
					cur_month = i.toString();
					if($chk($(cur_year+'_'+cur_month)))
					{
						$(cur_year+'_'+cur_month).setStyle('display','none');
						$(cur_year+'_'+cur_month+'_act').setStyle('display','none');
					}
				}
			}else
			{
				for(var i=1;i<=12;i++)
				{
					cur_month = i.toString();
					if($chk($(cur_year+'_'+cur_month)))
					{
						//alert(cur_year+'_'+cur_month);
						$(cur_year+'_'+cur_month).setStyle('display','block');
						$(cur_year+'_'+cur_month+'_act').setStyle('display','block');
					}
				}
			}
		});	
	});
});

//eof the menu

//bof the click value
function click_value(the_year)
{
	$('clicked_value').setProperty('value', the_year);	
}
//eof the click value
//-bof check_month
function check_month(the_month)
{
	if($(the_month+'_act').getStyle('display') == 'block')
	{
		$(the_month+'_act').setStyle('display','none');
	}else
	{
		$(the_month+'_act').setStyle('display','block');
	}
}
//-eof check_month
</script>
</head>

<body onLoad="MM_preloadImages('img_button/button2_2.gif','img_button/button2_3.gif','img_button/button2_4.gif','img_button/button2_5.gif','img_button/button2_6.gif','img_button/button2_7.gif')">
<table width="1100" height="110" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td><img src="img_button/button_1.gif" width="200" height="110"></td>
    <td><a href="about.html" onMouseOver="MM_swapImage('b01','','img_button/button2_2.gif',1)" onMouseOut="MM_swapImgRestore()"><img src="img_button/button_2.gif" name="b01" width="145" height="110" border="0" id="b01"></a></td>
    <td><a href="environment.html" onMouseOver="MM_swapImage('b02','','img_button/button2_3.gif',1)" onMouseOut="MM_swapImgRestore()"><img src="img_button/button_3.gif" name="b02" width="145" height="110" border="0" id="b02"></a></td>
    <td><a href="academics.html" onMouseOver="MM_swapImage('b03','','img_button/button2_4.gif',1)" onMouseOut="MM_swapImgRestore()"><img src="img_button/button_4.gif" name="b03" width="145" height="110" border="0" id="b03"></a></td>
    <td><a href="photo.php" onMouseOver="MM_swapImage('b04','','img_button/button2_5.gif',1)" onMouseOut="MM_swapImgRestore()"><img src="img_button/button_5.gif" name="b04" width="145" height="110" border="0" id="b04"></a></td>
    <td><a href="enroll.html" onMouseOver="MM_swapImage('b05','','img_button/button2_6.gif',1)" onMouseOut="MM_swapImgRestore()"><img src="img_button/button_6.gif" name="b05" width="145" height="110" border="0" id="b05"></a></td>
    <td><a href="index.php" onMouseOver="MM_swapImage('b06','','img_button/button2_7.gif',1)" onMouseOut="MM_swapImgRestore()"><img src="img_button/button_7.gif" name="b06" width="145" height="110" border="0" id="b06"></a></td>
    <td><img src="img_button/button_8.gif" width="30" height="110"></td>
  </tr>
</table><table width="1100" border="0" align="center" cellpadding="0" cellspacing="0" id="content">
  <tr>
    <td width="230" align="center"><table width="170" height="600" border="0" cellpadding="0" cellspacing="0" background="img_photo/background-item.gif">
      <tr>
        <td align="left" valign="top"><div id=photolist>
        	<input type="hidden" id="clicked_value" value="" />
			<p><a target="_blank" href="http://60.251.188.219:8080/cgi-bin/Qmultimedia/index.cgi">班級活動</a></p>
		         <?php
		         if ($mclass_actives) {
			         ?>
			         <ul>
			         <?php
		         	foreach ($mclass_actives as $class_active)
		         	{
	         		?>
	         		 <li><a href="photo.php?id=<?php echo $class_active['active_id'];?>"><?php echo $class_active['active_name'];?></a></li>
	         		<?php
		         	}
		         	?>
		         	 </ul>
		         	<?php	
		         }
		         ?>
		         <p><a href="photo.php">學校活動</a></p>
		       <?php
		        	foreach ($act_by_date as $year_id=>$year)
		        	{
		        		if($active_year == $year_id)
		        		{
		        			$display_str = 'block';
		        		}else 
		        		{
		        			$display_str = 'none';
		        		}
		        		?>
		        		 <p id="<?php echo $year_id;?>" class="year" onClick="click_value('<?php echo $year_id;?>')"><?php echo $year_id;?></p>
		        		<?php
		        		foreach ($year as $month_id=>$month)
			        	{
			        		$cur_month_id = $year_id.'_'.$month_id;
			        		
			        		if ($active_month == $cur_month_id) {
			        			$display_month_str = 'block';
			        		}else 
			        		{
			        			$display_month_str = 'none';
			        		}
			        		?>
			        		 <p class="month" style="display:<?php echo $display_str;?>" onclick="check_month('<?php echo $cur_month_id;?>')" id="<?php echo $cur_month_id;?>"><?=$month_id?>月<?php echo date("F", mktime(0, 0, 0, $month_id,1, $year_id));?></p>
			        		<ul class="list" style="display:<?php echo $display_month_str;?>" id="<?php echo $cur_month_id;?>_act">
			        		 <?php
			        		foreach ($month as $act_me)
				        	{
			        		?>
			        		 <li><a href="photo.php?id=<?= $act_me['id']?>"><?= $act_me['name']?></a></li>
			        		<?php
				        	}
			        		 ?>
			        		 </ul>
			        		 <?php
			        	}
		        	}
	        	?>
         </div>
         </td>
      </tr>
    </table></td>
    <td valign="bottom"><table width="840" height="570" border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
      <tr>
        <td height="36"><img src="img_photo/title.gif" width="840" height="36"></td>
      </tr>
      <tr>
        <td height="534"><div id=login>
          <form name="class" method="post" action="login.php" >
            <strong>請輸入帳號密碼</strong><br>
                    帳號：
                    <input type="text" name="username" id="username">
                    <br>
          密碼：
          <input type="password" name="password" id="password">
          <center><input type="submit" value="登錄" /></center>
          </form>
          </div></td>
      </tr>
    </table></td>
  </tr>
</table>
<table width="1100" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td><img src="img_photo/footer.gif" width="1100" height="90"></td>
  </tr>
</table>
</body>
</html>




