Viewing file: resort_calendar.php (6.51 KB) -rw-r--r-- Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?php
include('cal_func.php');
include("header.php");
?>
<style type="text/css">
<!--
.style3 {font-size: 12px}
.style5 {font-size: 12px; font-weight: bold; }
-->
</style>
<!-- xxxxxxxxxxx เริ่มต้นสร้างส่วนของ Main Content xxxxxxxxxxx-->
<div align="center"><table width="100%" >
<div class="menu" align="center"></div>
<td width="84%">
<div class="header2" align="center">ปฏิทินเหตุการณ์<br>
<br>
</div>
<table width="40%" border="1" align="center" cellpadding="0" cellspacing="2">
<tr>
<td><table width="100%" border="0" cellpadding="0" cellspacing="0" class="calendar">
<tr class="title" bgcolor="#004080">
<td width="22%"><div align="left"><a href="<?php echo "$PHP_SELF?Y=$cal_prev_year&m=$cal_prev_month&d=$cal_day" ?>"><<</a></div></td>
<td width="53%"><?php echo $_month_name[$cal_month]." - ".($cal_year+543);?> </td>
<td width="25%"><div align="right"><a href="<?php echo "$PHP_SELF?Y=$cal_next_year&m=$cal_next_month&d=$cal_day" ?>">>></a></div></td>
</tr>
</table>
<table class="calendar" width="100%" border="0" cellpadding="0" cellspacing="2">
<tr class="overview">
<td class="dayname"><div align="center">จ</div></td>
<td class="dayname"><div align="center">อ</div></td>
<td class="dayname"><div align="center">พ</div></td>
<td class="dayname"><div align="center">พฤ</div></td>
<td class="dayname"><div align="center">ศ</div></td>
<td class="dayname"><div align="center">ส</div></td>
<td class="dayname"><div align="center">อา</div></td>
</tr>
<?php
require_once('Connections/connresort.php');
mysql_select_db($database_connresort, $connresort);
$query_rsCal = "select start,end from mycalendar ";
$rsCal = mysql_query($query_rsCal, $connresort) or die(mysql_error());
$row_rsCal = mysql_fetch_assoc($rsCal);
//เอาวันเริมและสิ้นสุดมาเก็บใน array เพื่อใช้ในการเปรียบเทียบ
$st=array();$ed=array();
$i=0;
do{
$st[$i]=$row_rsCal['start'];
$ed[$i]=$row_rsCal['end'];
$i++;} while ($row_rsCal = mysql_fetch_assoc($rsCal));
for($i=0;$i<count($st);$i++)
{
$ed[$i]=substr($ed[$i],0,4).substr($ed[$i],5,2).substr($ed[$i],8,2);
$st[$i]=substr($st[$i],0,4).substr($st[$i],5,2).substr($st[$i],8,2);
}
if ( ( $cal_year == $cur_year ) && ( $cal_month == $cur_month ) )
//แยกได้เป็น 2 กรณีคือ run ครั้งแรก หรือเป็นวันปัจจุบัน
{
$today_day = $cur_day;//ดังนั้นจึงกำหนดให้ $today เก็บค่าของ $cur_day ซึ่งเป็นวันปัจจุบันเพื่อจะได้ hilight
} else $today_day = 0;//ถ้าไม่ใช่ให้เท่ากับ 0
$days_last_month = num_days( $cal_prev_year, $cal_prev_month );//จำนวนวันในเดือนที่แล้ว
$days_this_month = num_days( $cal_year, $cal_month );//จำนวนวันในเดือนนี้
// หาวันแรกของเดือนนี้
$first_day_pos = date( "w", mktime( 0,0,0,$cal_month,1,$cal_year) );
if ( $first_day_pos == 0 ) $first_day_pos = 7; // convert to Mo=1 to Su=7
$day_num = $days_last_month - ($first_day_pos-2);
$class="last_month";
$p=array();
for ( $y=1; $y<=6; $y++ )
{
echo '<tr class="overview" align="right">';
for ( $x=1; $x<=7; $x++ )
{
if ( ($y==1) && ($x==$first_day_pos) )
{
$day_num = 1; $class="";
}
if ( ($y >1) && ($day_num==$days_this_month+1) )
{
$day_num = 1; $class="next_month";
}
if ( ($class=="") && ($day_num == $today_day) )
{
$id="today";
} else $id="";
if ( ( $id!="today") && ($class=="") && ($day_num == $cal_day ) )
{
$id="selected";
}
if ( $class != "" ){
$ap1 = ""; $ap2 = "";
}else{
if($cal_month<=9)
$mm="0".$cal_month;
else $mm=$cal_month;
if($day_num<=9)
$dd="0".$day_num;
else $dd=$day_num;
$times=$cal_year."-".$mm."-".$dd;
$ap1 = '<a href="'.$PHP_SELF."?Y=$cal_year&m=$cal_month&d=$day_num&now_stamp=$times".'">';
$ap2 = '</a>'; }
$cur_day=$cal_year.$mm.$dd;
for($i=0;$i<count($st);$i++){
if(($cur_day>=$st[$i])&&($cur_day<=$ed[$i])){
$p[$day_num]=1;
}
}
if($p[$day_num]==1&&$class=="")
echo '<td class="'.$class.'" id="'.$id.'" bgcolor=#E9FFE9><div align="center">'.$ap1.$day_num.$ap2.'</div></td>';
else echo '<td class="'.$class.'" id="'.$id.'" bgcolor=#E9E9E9><div align="center">'.$day_num.'</div></td>';
$day_num++;
}
echo '</tr>';
}
?>
</table></td>
</tr>
</table>
<p align="center" class="header2">ตารางแสดงเหตุการณ์</p>
<div align="center">
<table width="95%" border="1" align="center" cellpadding="0" cellspacing="2" bordercolor="#CCCCCC">
<tr bgcolor="#FFCCFF">
<td width="12%"><div align="center" class="style3">
<div align="center"><strong>วันที่เริ่มต้น</strong></div>
</div></td>
<td width="12%"><div align="center"><span class="style5">วันที่สิ้นสุด</span></div></td>
<td width="25%"><div align="center" class="style3">
<div align="left"><strong>หัวข้อเหตุการณ์</strong></div>
</div></td>
<td width="31%"><span class="style5">รายละเอียด</span></td>
</tr>
<?php
$now_stamp=$HTTP_GET_VARS['now_stamp'];
if (isset($now_stamp))
{
mysql_select_db($database_connresort, $connresort);
$query_rsMycalendar = "SELECT * FROM mycalendar WHERE '$now_stamp' BETWEEN start AND end";
$rsMycalendar = mysql_query($query_rsMycalendar, $connresort) or die(mysql_error());
$row_rsMycalendar = mysql_fetch_assoc($rsMycalendar);
$totalRows_rsMycalendar = mysql_num_rows($rsMycalendar);
unset($now_stamp);
}else {
echo "<tr><td colspan='3' align='center'>ไม่พบเหตุการณ์ใด ๆ ในวันนี้</td><tr><br></table>";
exit;
}
?>
<!--repeat region-->
<?php do { ?>
<tr>
<td height="20" class="list">
<div align="left" class="style3">
<div align="center"><?php echo $row_rsMycalendar['start']; ?></div>
</div> </td>
<td height="20" class="list">
<div align="center" class="style3">
<div align="center"><?php echo $row_rsMycalendar['end']; ?></div>
</div></td>
<td >
<div align="left" class="style3"><?php echo $row_rsMycalendar['title']; ?> </div></td>
<td ><span class="style3"><?php echo $row_rsMycalendar['description']; ?></span></td>
</tr>
<?php } while ($row_rsMycalendar = mysql_fetch_assoc($rsMycalendar)); ?>
</table>
<div align="center"></div>
</div>
</td>
</tr>
</table>
</body>
</html>
<?php
mysql_free_result($rsMycalendar);
mysql_free_result($rsCal);
?>
|