Jump to content

make the calendar box highlighted if it is a public holiday


phpabcd

Recommended Posts

<?

for ($i = 1; $i <= $first_day_of_month-1; $i++) {

$days_so_far = $days_so_far + 1;

$count_boxes = $count_boxes + 1;

echo "<td width=\"125\" height=\"100\" class=\"beforedayboxes\"></td>\n";

}

for ($i = 1; $i <= $days_in_month; $i++) {

  $days_so_far = $days_so_far + 1;

    $count_boxes = $count_boxes + 1;

IF($_GET['month'] == $todays_month+1){

IF($todays_date == $day){

$class = "publicholidayhighlightedboxes";

} ELSE {

$class = "dayboxes";

}

}

ELSE {

IF($i == $todays_date){

$class = "highlighteddayboxes";

} ELSE {

$class = "dayboxes";

}

}

The problem is I can only display one highlighted box in one month. For example, in November, there are two public holidays, but only 1 public holiday box is highlighted. Would appreciate if someone can help me out asap. Thank you

Link to comment
Share on other sites

I don't think you've provided enough code in your example for me to accurately help you but I'm guessing this part of the code is the bit that highlights a public holiday and the problematic code:

	IF($todays_date == $day){
	   $class = "publicholidayhighlightedboxes";
	} ELSE {
	   $class = "dayboxes";
	}

 

What is the value of $day? I would have thought if you were looping through a calendar and had multiple days then $day would actually be an array of dates that are public holidays and you would test it by doing

 

// List of holidays
$array_of_holiday_dates = array(1,6,;
// Loop through dates
loop{
// If todays date is in the array of holiday dates then highlight it
if (in_array($todays_date, $array_of_holiday_dates)){
   $class = "publicholidayhighlightedboxes";
} else {
   $class = "dayboxes";
}
}

As shown here: http://php.net/manual/en/function.in-array.php

Link to comment
Share on other sites

I'm not quite sure what you mean, I'm guessing $info contains a list of the holidays....

 

I just mean that it looks like you're setting $day to a single value so if you're looping through loads of days, it could only ever be true once...

 

$day = 5;

// Loop through each and put a box around if number == day

1,2,3,4,[5],5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31

 

but if $day is an array of multiple items, it could highlight multiple things like:

 

$day = array(5,7,21);

// Loop through each and put a box around if number is in the day array

1,2,3,4,[5],5,6,[7],8,9,10,11,12,13,14,15,16,17,18,19,20,[21],22,23,24,25,26,27,28,29,30,31

Link to comment
Share on other sites

IF(!isset($_GET['year'])){

    $_GET['year'] = date("Y");

}

IF(!isset($_GET['month'])){

    $_GET['month'] = date("n")+1;

}

 

$month = addslashes($_GET['month'] - 1);

$year = addslashes($_GET['year']);

 

$query = "SELECT ph_date, ph_id, ph_type

FROM Public_Holiday

WHERE ph_month ='$month'

AND ph_year = '$year'";

//this is the query for publicholiday

$query_result = mysql_query($query, $conn);

while ($info = mysql_fetch_row($query_result))

{

$day = $info['0'];

$event_id = $info['1'];

    $events[$day][] = $info['1'];

    $event_info[$event_id]['0'] = substr($info['2'], 0, 20);

}

//this is to insert the value into the calendar by running the query

 

$todays_date = date("j");

$todays_month = date("n");

 

$days_in_month = date ("t", mktime(0,0,0,$_GET['month'],0,$_GET['year']));

$first_day_of_month = date ("w", mktime(0,0,0,$_GET['month']-1,1,$_GET['year']));

$first_day_of_month = $first_day_of_month + 1;

$count_boxes = 0;

$days_so_far = 0;

 

IF($_GET['month'] == 13){

    $next_month = 2;

    $next_year = $_GET['year'] + 1;

} ELSE {

    $next_month = $_GET['month'] + 1;

    $next_year = $_GET['year'];

}

 

IF($_GET['month'] == 2){

    $prev_month = 13;

    $prev_year = $_GET['year'] - 1;

} ELSE {

    $prev_month = $_GET['month'] - 1;

    $prev_year = $_GET['year'];

}

?>

<br />

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Welcome to Department of Anaesthesiology</title>

<link href="calendarstyle.css" rel="stylesheet" type="text/css" />

<script language="JavaScript" type="text/JavaScript">

<!--

function MM_jumpMenu(targ,selObj,restore){ //v3.0

  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");

  if (restore) selObj.selectedIndex=0;

}

function MM_openBrWindow(theURL,winName,features) { //v2.0

  window.open(theURL,winName,features);

}

//-->

</script>

<link href="calendarstyle.css" rel="stylesheet" type="text/css">

</head>

 

<br />

<body>

<div align="center"><font color="#00CC99" size="+2" face="Verdana, Arial, Helvetica, sans-serif">Overall Day-Duty Roster</font></div>

<br />

<div align="center"><font size="4">Departmental duties for the month:</font></div>

<div align="center">

<div align="center"><span class="currentdate"><? echo date ("F Y", mktime(0,0,0,$_GET['month']-1,1,$_GET['year'])); ?></span><br>

  <br>

</div>

<div align="center"><br>

  <table width="700" border="0" cellspacing="0" cellpadding="0">

    <tr>

      <td><div align="right"><a href="<? echo "monthlyoverallroster2.php?month=$prev_month&year=$prev_year"; ?>"><<</a></div></td>

      <td width="300"><div align="center">

           

          <select name="month" id="month" onChange="MM_jumpMenu('parent',this,0)">

            <?

for ($i = 1; $i <= 12; $i++) {

$link = $i+1;

IF($_GET['month'] == $link){

$selected = "selected";

} ELSE {

$selected = "";

}

echo "<option value=\"monthlyoverallroster2.php?month=$link&year=$_GET[year]\" $selected>" . date ("F", mktime(0,0,0,$i,1,$_GET['year'])) . "</option>\n";

}

?>

          </select>

          <select name="year" id="year" onChange="MM_jumpMenu('parent',this,0)">

  <?

  //Define parameters

  $startdate= 2000;

  $enddate= date("Y");

    $dated = getdate();

$year = $dated['year'];

  //for loop for the dropdown list(year)

  for ($year = $startdate; $year<=$enddate; $year++) {

  IF($year == $_GET['year']){

$selected = "selected";

} ELSE {

$selected = "";

}

  echo "<option value=\"monthlyoverallroster2.php?month=$_GET[month]&year=$year\" $selected>$year</option>\n";

  }

  ?>

          </select>

        </div></td>

      <td><div align="left"><a href="<? echo "monthlyoverallroster2.php?month=$next_month&year=$next_year"; ?>">>></a></div></td>

    </tr>

  </table>

  <br>

</div>

<table width="875" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#000000">

  <tr>

    <td><table width="100%" border="0" cellpadding="0" cellspacing="1">

        <tr class="topdays">

        <td><div align="center">Sunday</div></td>

        <td><div align="center">Monday</div></td>

        <td><div align="center">Tuesday</div></td>

        <td><div align="center">Wednesday</div></td>

        <td><div align="center">Thursday</div></td>

        <td><div align="center">Friday</div></td>

        <td><div align="center">Saturday</div></td>

        </tr>

<tr valign="top" bgcolor="FFFFFF">

<?

for ($i = 1; $i <= $first_day_of_month-1; $i++) {

$days_so_far = $days_so_far + 1;

$count_boxes = $count_boxes + 1;

echo "<td width=\"125\" height=\"100\" class=\"beforedayboxes\"></td>\n";

}

for ($i = 1; $i <= $days_in_month; $i++) {

  $days_so_far = $days_so_far + 1;

    $count_boxes = $count_boxes + 1;

IF($_GET['month'] == $todays_month+1){

IF($todays_date == $day){

$class = "publicholidayhighlightedboxes";

} ELSE {

$class = "dayboxes";

}

}

ELSE {

IF($i == $todays_date){

$class = "highlighteddayboxes";

} ELSE {

$class = "dayboxes";

}

}

echo "<td width=\"125\" height=\"100\" class=\"$class\">\n";

$link_month = $_GET['month'] - 1;

echo "<div align=\"right\"><span class=\"toprightnumber\">\n<a href=\"javascript:MM_openBrWindow('event_add.php?day=$i&month=$link_month&year=$_GET[year]','','width=500,height=300');\">$i</a> </span></div>\n";

IF(isset($events[$i])){

echo "<div align=\"left\"><span class=\"eventinbox\">\n";

while (list($key, $value) = each ($events[$i])) {

echo " <a href=\"javascript:MM_openBrWindow('event.php?id=$value','','width=500,height=200');\">" . $event_info[$value]['1'] . " " . $event_info[$value]['0']  . "</a>\n<br>\n";

}

echo "</span></div>\n";

}

echo "</td>\n";

IF(($count_boxes == 7) AND ($days_so_far != (($first_day_of_month-1) + $days_in_month))){

$count_boxes = 0;

echo "</TR><TR valign=\"top\">\n";

}

}

$extra_boxes = 7 - $count_boxes;

for ($i = 1; $i <= $extra_boxes; $i++) {

echo "<td width=\"125\" height=\"100\" class=\"afterdayboxes\"></td>\n";

}

$time_end = getmicrotime();

$time = round($time_end - $time_start, 3);

?>

Link to comment
Share on other sites

I didn't test your code but I could immediately tell it was the problem I mentioned earlier... Here is the code that should fix it

<?php
IF(!isset($_GET['year'])){
    $_GET['year'] = date("Y");
}
IF(!isset($_GET['month'])){
    $_GET['month'] = date("n")+1;
}

$month = addslashes($_GET['month'] - 1);
$year = addslashes($_GET['year']);
$day = array();

$query = "SELECT ph_date, ph_id, ph_type
FROM Public_Holiday
WHERE ph_month ='$month'
AND ph_year = '$year'";
//this is the query for publicholiday
$query_result = mysql_query($query, $conn);
while ($info = mysql_fetch_row($query_result))
{
   $day[] = $info['0'];
   $event_id = $info['1'];
    $events[$day][] = $info['1'];
    $event_info[$event_id]['0'] = substr($info['2'], 0, 20);   
}
//this is to insert the value into the calendar by running the query

$todays_date = date("j");
$todays_month = date("n");

$days_in_month = date ("t", mktime(0,0,0,$_GET['month'],0,$_GET['year']));
$first_day_of_month = date ("w", mktime(0,0,0,$_GET['month']-1,1,$_GET['year']));
$first_day_of_month = $first_day_of_month + 1;
$count_boxes = 0;
$days_so_far = 0;

IF($_GET['month'] == 13){
    $next_month = 2;
    $next_year = $_GET['year'] + 1;
} ELSE {
    $next_month = $_GET['month'] + 1;
    $next_year = $_GET['year'];
}

IF($_GET['month'] == 2){
    $prev_month = 13;
    $prev_year = $_GET['year'] - 1;
} ELSE {
    $prev_month = $_GET['month'] - 1;
    $prev_year = $_GET['year'];
}
?>
<br />
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Welcome to Department of Anaesthesiology</title>
<link href="calendarstyle.css" rel="stylesheet" type="text/css" />
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
//-->
</script>
<link href="calendarstyle.css" rel="stylesheet" type="text/css">
</head>

<br />
<body>
<div align="center"><font color="#00CC99" size="+2" face="Verdana, Arial, Helvetica, sans-serif">Overall Day-Duty Roster</font></div>
<br />
<div align="center"><font size="4">Departmental duties for the month:</font></div>
<div align="center">   
<div align="center"><span class="currentdate"><? echo date ("F Y", mktime(0,0,0,$_GET['month']-1,1,$_GET['year'])); ?></span><br>
  <br>
</div>
<div align="center"><br>
  <table width="700" border="0" cellspacing="0" cellpadding="0">
    <tr> 
      <td><div align="right"><a href="<? echo "monthlyoverallroster2.php?month=$prev_month&year=$prev_year"; ?>"><<</a></div></td>
      <td width="300"><div align="center">
            
          <select name="month" id="month" onChange="MM_jumpMenu('parent',this,0)">
            <?
         for ($i = 1; $i <= 12; $i++) {
            $link = $i+1;
            IF($_GET['month'] == $link){
               $selected = "selected";
            } ELSE {
               $selected = "";
            }
            echo "<option value=\"monthlyoverallroster2.php?month=$link&year=$_GET[year]\" $selected>" . date ("F", mktime(0,0,0,$i,1,$_GET['year'])) . "</option>\n";
         }
         ?>
          </select>
          <select name="year" id="year" onChange="MM_jumpMenu('parent',this,0)">
        <?
        //Define parameters
            $startdate= 2000; 
            $enddate= date("Y");
          $dated = getdate();
         $year = $dated['year'];
        //for loop for the dropdown list(year)
        for ($year = $startdate; $year<=$enddate; $year++) {
           IF($year == $_GET['year']){
            $selected = "selected";
         } ELSE {
            $selected = "";
         }
           echo "<option value=\"monthlyoverallroster2.php?month=$_GET[month]&year=$year\" $selected>$year</option>\n";
        }
        ?>
          </select>
        </div></td>
      <td><div align="left"><a href="<? echo "monthlyoverallroster2.php?month=$next_month&year=$next_year"; ?>">>></a></div></td>
    </tr>
  </table>
  <br>
</div>
<table width="875" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#000000">
  <tr>
    <td><table width="100%" border="0" cellpadding="0" cellspacing="1">
        <tr class="topdays"> 
         <td><div align="center">Sunday</div></td>
         <td><div align="center">Monday</div></td>
         <td><div align="center">Tuesday</div></td>
         <td><div align="center">Wednesday</div></td>
         <td><div align="center">Thursday</div></td>
         <td><div align="center">Friday</div></td>
         <td><div align="center">Saturday</div></td>
        </tr>
      <tr valign="top" bgcolor="FFFFFF"> 
      <?
      for ($i = 1; $i <= $first_day_of_month-1; $i++) {
         $days_so_far = $days_so_far + 1;
         $count_boxes = $count_boxes + 1;
         echo "<td width=\"125\" height=\"100\" class=\"beforedayboxes\"></td>\n";
      }
      for ($i = 1; $i <= $days_in_month; $i++) {
            $days_so_far = $days_so_far + 1;
             $count_boxes = $count_boxes + 1;
         IF($_GET['month'] == $todays_month+1){
            IF(in_array($todays_date,$day)){
               $class = "publicholidayhighlightedboxes";
            } ELSE {
               $class = "dayboxes";
            }
         }
          ELSE {
            IF($i == $todays_date){
               $class = "highlighteddayboxes";
            } ELSE {
               $class = "dayboxes";
            }
         }
         echo "<td width=\"125\" height=\"100\" class=\"$class\">\n";
         $link_month = $_GET['month'] - 1;
         echo "<div align=\"right\"><span class=\"toprightnumber\">\n<a href=\"javascript:MM_openBrWindow('event_add.php?day=$i&month=$link_month&year=$_GET[year]','','width=500,height=300');\">$i</a> </span></div>\n";
         IF(isset($events[$i])){
            echo "<div align=\"left\"><span class=\"eventinbox\">\n";
            while (list($key, $value) = each ($events[$i])) {
               echo " <a href=\"javascript:MM_openBrWindow('event.php?id=$value','','width=500,height=200');\">" . $event_info[$value]['1'] . " " . $event_info[$value]['0']  . "</a>\n<br>\n";
            }
            echo "</span></div>\n";
         }
         echo "</td>\n";
         IF(($count_boxes == 7) AND ($days_so_far != (($first_day_of_month-1) + $days_in_month))){
            $count_boxes = 0;
            echo "</TR><TR valign=\"top\">\n";
         }
      }
      $extra_boxes = 7 - $count_boxes;
      for ($i = 1; $i <= $extra_boxes; $i++) {
         echo "<td width=\"125\" height=\"100\" class=\"afterdayboxes\"></td>\n";
      }
      $time_end = getmicrotime();
      $time = round($time_end - $time_start, 3);
      ?>

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.