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

	//- get the db object
	global $db;
//-get the active id from url	
if(isset($_REQUEST['id'])&& intval($_REQUEST['id']))
{
	$active_id =$_REQUEST['id'];
}else
{
	if (isset($_SESSION['user_info']['member_id'])) 
	{
		$active = get_default_active_of_class($_SESSION['user_info']['member_id']);
		$active_id = $active['active_id'];
	}else 
	{
		$sql = 'select id from manufacturers order by id DESC';
		if($result = $db->sql_query($sql))
		{	
			$actives = $db->sql_fetchrow($result);
			$active_id = $actives['id'];
		}
	}
}

//-get the actives of class by member
if (isset($_SESSION['user_info']['member_id'])) {
	$memeber_id = intval($_SESSION['user_info']['member_id']);
	$mclass_actives = get_actives_of_class($memeber_id);		
}
	$query = array(
				'SELECT' 	=> '*',
				'FROM'		=> array('products' => 'p'),
				'WHERE'		=> 'p.manu_id = \''.$active_id.'\'',
				'ORDER_BY'	=>	'p.id ASC',
				);
				
	if (isset($_SESSION['user_info']['member_id'])) {
		if (!isset($_REQUEST['id'])) 
		{
			$query['WHERE'] =  'p.cactive_id = \''.$active_id.'\'';
		}else if ('class' == $_REQUEST['atype']) {
			$query['WHERE'] =  'p.cactive_id = \''.$active_id.'\'';
		}
	}
	
	if($result = $db->sql_query($db->sql_build_query('SELECT',$query)))
	{	
	 	$images_result = $db->sql_fetchrowset($result);			
	}else 
	{
		$images_result = false;
	}
	
	//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']);
	}
	
	//get all the act by year & month
	$query_active = array(
				'SELECT' 	=> '*',
				'FROM'		=> array('manufacturers' => 'm'),
				'WHERE'		=> 'm.id = \''.$active_id.'\''
				);	
	
	if($result = $db->sql_query($db->sql_build_query('SELECT',$query_active)))
	{	
	 	$active_result = $db->sql_fetchrow($result);			
	}else 
	{
		$active_result = false;
	}
		
	//-get the active year & month
	if ($active_result) {
		//-for the class active
		if ((isset($_REQUEST['atype'])&&'class' !=$_REQUEST['atype'])||isset($_SESSION['user_info']['member_id'])) 
		{
			$active_year = '0';
			$active_month = '0';
		}else 
		{
			//-for the school active
			$active_year = $active_result['year_id'];
			$active_month =  $active_result['year_id'].'_'.$active_result['month_id'];
			//print_r($active_result);
		}
	}
?>
<!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];}}
}
//-->
</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 gallery script
window.addEvent('domready', function(){
	    var data = {
	    	<?php 
	    		if ($images_result) 
	    		{
		    		foreach ($images_result as $key=>$value)
		    		{
		    			$data_array[] = " '".$value['the_image'].".png': { caption: '".$value['name']."' }";	
		    		}
		    		echo implode(',',$data_array);	    			
	    		}
	    	?>
	    };
	    var myShow = new Slideshow.KenBurns('show', data, { captions: true, controller: true, height: 375, hu: 'img_photo/', delay: 5000, duration: 2000, thumbnails: true, width: 500 });
		});		

//end of the gallery script 

//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;
			
			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
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>
</head>

<body onLoad="MM_preloadImages('img_button/button_N1_1.gif','img_button/button_N2_1.gif','img_button/button_N3_1.gif','img_button/button_N4_1.gif','img_button/button_N5_1.gif','img_button/button_N6_1.gif','img_button/button_N7_1.gif','img_button/button_N8_1.gif')">
<table width="1100" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td><img src="img/bar01.jpg" width="1100" height="70"></td>
  </tr>
</table>
<table width="1100" height="70" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#0099FF">
  <tr>
    <td width="15">&nbsp;</td>
    <td width="70"><a href="index.html" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image13','','img_button/button_N1_1.gif',1)"><img src="img_button/button_N1.gif" name="Image13" width="70" height="70" border="0"></a></td>
    <td width="145"><a href="about.html" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image12','','img_button/button_N2_1.gif',1)"><img src="img_button/button_N2.gif" name="Image12" width="145" height="70" border="0"></a></td>
    <td width="145"><a href="environment.html" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image11','','img_button/button_N3_1.gif',1)"><img src="img_button/button_N3.gif" name="Image11" width="145" height="70" border="0"></a></td>
    <td width="145"><a href="academics_eng1.html" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image10','','img_button/button_N4_1.gif',1)"><img src="img_button/button_N4.gif" name="Image10" width="145" height="70" border="0"></a></td>
    <td width="145"><a href="academics-1.html" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image9','','img_button/button_N5_1.gif',1)"><img src="img_button/button_N5.gif" name="Image9" width="145" height="70" border="0"></a></td>
    <td width="145"><a href="photo.php" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image8','','img_button/button_N6_1.gif',1)"><img src="img_button/button_N6.gif" name="Image8" width="145" height="70" border="0"></a></td>
    <td width="145"><a href="enroll.html" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image7','','img_button/button_N7_1.gif',1)"><img src="img_button/button_N7.gif" name="Image7" width="145" height="70" border="0"></a></td>
    <td width="145"><a href="video.html" target="_blank" onMouseOver="MM_swapImage('Image6','','img_button/button_N8_1.gif',1)" onMouseOut="MM_swapImgRestore()"><img src="img_button/button_N8.gif" name="Image6" width="145" height="70" border="0"></a></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://218.32.77.182/wesleykids/photoset/">班級活動</a></p>
          <?php
	         if ($mclass_actives) {
		         ?>
		         <ul style="height:250px;overflow-y:scroll;">
		         <?php
	         	foreach ($mclass_actives as $class_active)
	         	{
         		?>
         		 <li><a href="photo.php?atype=class&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
		        	}
	        	}
        	?>
	    <!--     <p id="2010" class="year" onClick="click_value('2010')">2010</p>
	         <p id="2010_1" class="month" onclick="check_month('2010_1')">1月January</p>
	         <ul id="2010_1_act">
		         <li><a href="#">學校活動列表</a></li>
		         <li><a href="#">學校活動列表</a></li>
	         </ul>-->
    
         </div>
        
        
        <!-- //bak of the orginal style
        <div id="item-word">
         <p class="year" id="2000"><a href="#" id="2000_a">2000年</a></p>     
         <p class="month" id="2000_8">8月August</p>         
         <p class="list" id="2000_8_act"><a href="#">開幕</a><br>
           <a href="#">慶生會</a></p>
        </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">
        <?php 
			if (isset($_SESSION['user_info']['member_id'])) {
		?>
				 <img src="img_photo/title.gif" width="780" height="36"><a style="float:right; position:absolute; vertical-align:middle; text-align:center; color:#FF0000; font-weight:bold; line-height:36px; background:#faec00; width:60px;" href="login.php?logout=1">[登出]</a>
		<?php
			}else 
			{
		?>
        	<img src="img_photo/title.gif" width="840" height="36">
        <?php
        	}
		?>
        </td>
      </tr>
      <tr>
        <td width="840" height="534" style="overflow:hidden;">
        <!--/bof the gallery -->
			<center>
			  <div id="wrapper">  
			  	<!-- bof slideshow -->
			    <div id="show" class="slideshow">
			      <div class="slideshow-images">
			      	<?php
			      		foreach ($images_result as $current_image)
			      		{
			      			$the_width = rand(600, 800);
			      			$the_height = rand(600, 800);
			      			?>
			      		<a rel="lightbox" target="_blank" href="img_photo/<?php echo $current_image['the_image'];?>.png"><img id="slide-1" src="img_photo/<?php echo $current_image['the_image'];?>.png" width="<?php echo $the_width;?>" height="<?php echo $the_height;?>" alt="<?php echo $current_image['name'];?>" /></a>	
			      			<?
			      		}
			      	?>
			      </div>
			      <?php 
			      	if ($images_result) 
			      	{
			      ?>
				      <div class="slideshow-thumbnails">
				        <ul>
				      	<?php
				      		foreach ($images_result as $current_image)
				      		{	
				      			$i++;
				      			$the_width = rand(400, 600);
				      			$the_height = rand(400, 600);
				      			?>
				      			<li><a href="#slide-<?php echo $i;?>"><img src="img_photo/<?php echo $current_image['the_image'];?>t.jpg" width="50" height="40" alt="Slide thumbnail" /></a></li>
				      			<?
				      		}
				      	?>
				        </ul>
				      </div>
			      <?php 
			      	}
			      ?>
			    </div>
				<!-- eof slideshow  -->
			    <h3 class="colophon" style="display:none"><a>Colophon</a></h3>
			  </div>
		 </center>        
        <!--/eof the gallery -->
        </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>




