display only todays date and entries.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
carnuke
Forum Newbie
Posts: 4
Joined: Tue Sep 27, 2005 12:03 pm

display only todays date and entries.

Post by carnuke »

feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]


I have a calendar script (see below) which prints a monthly list of entries see sample [url]http://houseofstrauss.co.uk/demos/calendar3/months.php[/url] 

What I want is to display only todays date and the events associated with today and not the rest of the month. This will change each day, according to the date. ie "01 Oct 2005 	full moon test"

Can someone please help me ammend the script to do this?

TIA

calendar script

Code: Select all

<?php 
extract ($HTTP_GET_VARS);
extract ($HTTP_POST_VARS);
$PHP_SELF = $HTTP_SERVER_VARS['PHP_SELF'];
$data_dir = "";
//error_reporting (E_ALL);
?>

<html>
<head>
<title>Calendar</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="list.css" rel="stylesheet" type="text/css">
</head>

<body bgcolor="#FFFFFF">
    <?php
//-----------------------------------------------------------------------------
// 
//-----------------------------------------------------------------------------



// add up to 9 priories here
$priority_array[0] = "Waxcres";
$priority_array[1] = "Firstqtr";
$priority_array[2] = "Waxgib";
$priority_array[3] = "Full";
$priority_array[4] = "Wanegib";
$priority_array[5] = "Lastqtr";
$priority_array[6] = "Wancres";
$priority_array[7] = "";
$priority_array[8] = "";
$priority_array[9] = "";




//

define ("DEBUG_ON", true);

//----------------------------------------------------------------------------
//debugging function
//----------------------------------------------------------------------------
function  DebugDie ( $file  ,$line, $msg = "")
{
    if (DEBUG_ON)
       die ("Error file : $file, line : $line $msg<br>\n");
    else
      die ("Failed to run script");

}

?>
    <?php



//----------------------------------------------------------------------------
class MyCalendar
{

   var $daysInMonth = array
    (1=>31,
     2=>28,
     3=>31,
     4=>30,
     5=>31,
     6=>30,
     7=>31,
     8=>31,
     9=>30,
    10=>31,
    11=>30,
    12=>31);


   var $monthName = array
    (1=>"January",
     2=>"February",
     3=>"March",
     4=>"April",
     5=>"May",
     6=>"June",
     7=>"July",
     8=>"August",
     9=>"September",
    10=>"October",
    11=>"November",
    12=>"December");

//----------------------------------------------------------------------------
// returns boolean result of test for leap year
//----------------------------------------------------------------------------
    function isLeap($yr)
    {
      return  date("L", mktime(0,0,0,1,1,$yr));
    }

//----------------------------------------------------------------------------
// Shows the colour codes
//----------------------------------------------------------------------------
function show_colour_codes ()
{
    global  $priority_array;

    echo "<table align ='center' class='colorCodeTable'>\n";
    echo "<tr>";
    for($j = 0; $j <count ($priority_array); $j++)
    {

        if (strlen ($priority_array[$j]))
        {
            
            echo "<td class ='filledColor$j'>$priority_array[$j]</td>\n";

        }
    }
    echo "</tr>\n";
    echo "</table>\n";
}


//----------------------------------------------------------------------------
// Returns the month name given the month as an integer
//----------------------------------------------------------------------------
    function getMonthName ($mn)
    {
       $mn = intval ($mn);
       return $this->monthName[$mn];
    }

//----------------------------------------------------------------------------
// returns current month as integer
//----------------------------------------------------------------------------
    function  getCurrentMonth()
    {
        return intval(Date("m"));
    }

//----------------------------------------------------------------------------
// returns current year as integer
//----------------------------------------------------------------------------
    function  getCurrentYear ()
    {
       return intval(Date("Y"));
    }


//----------------------------------------------------------------------------

// lists all the events for the current month in a table
//----------------------------------------------------------------------------
function month_events($yr, $mn)
{
global $data_dir;

    echo "<br>";

    $f_array = array();

    if (strlen ($mn) <2)
    {
       $mn = "0".$mn;
    }


     if ((!file_exists($data_dir."todo$yr$mn.txt"))|| (!filesize ($data_dir."todo$yr$mn.txt")))
     {
       echo "<center>No events listed for ".$this->getMonthName($mn)." $yr<br>\n";
       return;

     }
   

    $f_array = file ($data_dir."todo$yr$mn.txt") or DebugDie (__FILE__, __LINE__, "Failed to open file for reading $data_dir/todo$yr$mn.txt");

     if (count($f_array) ==0 )
     {
       echo "<center>No events listed for this month</center><br>\n";
       return;
     }

    sort ($f_array);

    echo "<table align='center'  class='monthEvents'>\n";
    for ($row = 0; $row < count ($f_array); $row++)
    {
        $line = trim($f_array[$row]);
        $last_char_pos = strlen($line)-1;
        //get priority in last char
        $last_char = $line[$last_char_pos];
        
        echo "<tr>\n";
        echo "<td width='25%'>\n";
                        
        $mn_date = substr($f_array[$row], 0, 10);
        $mn_array = explode ("-", $mn_date);
        $mn_name = substr($this->getMonthName($mn_array[1]),0,3) ;
        
        $mn_date  = "$mn_array[2] $mn_name $mn_array[0]";
        
        echo "<font class='filledColor$last_char'>$mn_date</font>";
        
        echo "</td>\n";
        echo "<td>\n";
        $retStr = substr ($f_array[$row], 11, strlen ($f_array[$row]) -13);
        
        
        echo $retStr;
        echo "</td>\n";
        echo "</tr>\n";
        
    }
    echo "</table>\n";
    
}
//----------------------------------------------------------------------------
// gets the entries in the calendar for the given month and year
// returns an array of days that have entries in the calendar.
//----------------------------------------------------------------------------

   function getEntryArray($yr, $mn, &$day_array, &$priority_array)
   {
	    global $data_dir;
		 
       if (strlen ($mn) <2)
       {
          $mn = "0".$mn;
       }     

      $entryArray = array();

      if ((!file_exists($data_dir."todo$yr$mn.txt")) || (!filesize($data_dir."todo$yr$mn.txt")))
      {
          return $entryArray;
      }


      $this->getDateRange ($mn, $yr, $start_date, $end_date);

      $fp = fopen ($data_dir."todo$yr$mn.txt", "r") or DebugDie (__FILE__, __LINE__);
      flock ($fp, 1);
      while (!feof($fp))
      {

          $str = fgets ($fp, 1024);
          if (strlen ($str) > 10)
          {
             $date_entry =  substr($str, 0, 10);
             if ($date_entry  >= $start_date && $date_entry <=$end_date);
             $day = explode ("-",$date_entry);
             $day_array[] = $day[2];
             $temp = trim ($str);
             $priority_array[] = $temp[strlen($temp)-1];
          }
       }
      flock ($fp, 3);
      fclose ($fp);
      clearstatcache();

   }




//-----------------------------------------------------------------------------
// draws the month and year selection boxes 
//-----------------------------------------------------------------------------
 function drawSelectionBox ($yearSelect,$monthSelect)
 {
    global  $PHP_SELF;



    // output the form to select month and year

    echo "<form method='post' action='$PHP_SELF'>";
    echo "<div align='center'>";
    // draw a select box for months. Set the default value shown to the one previously
    // selected e.g if user selects April then submits, the select box will
    // default to April for selected value
    echo "<select name='monthSelect'>";
    for ($m = 1; $m<13; $m++)
    {
        $str = "<option value=$m";
        if ($m == $monthSelect)
        {
            $str = $str." selected>".$this->getMonthName($m)."</option>";
        }
        else
        {
            $str = $str.">".$this->getMonthName($m)."</option>";
        }
        echo $str."\n";
    }
    echo "  </select>";

    // draw a select box for years.
    echo "<select name='yearSelect'>";
    for ($yr = 2001; $yr<2006; $yr++)
    {
        $str = "<option value=$yr";
        if ($yr == $yearSelect)
        {
            $str = $str." selected>".$yr."</option>";
        }
        else
        {
            $str = $str.">".$yr."</option>";
        }
        echo $str."\n";
    }
    echo "</select>";

    echo "<input type='submit' name='drawCal' value='Change'>";
    echo "</div>";
    echo "</form>\n";
  //  echo "<center><a href = '$PHP_SELF?month_events=1&yearSelect=$yearSelect&monthSelect=$monthSelect'>month event view</a></center>\n";
    
   }


}// end calendar class
//-----------------------------------------------------------------------------

//instantiate calendar
if ( !isset ($c))
{
    $c = new MyCalendar();

}


// if year and month not selected give default
if (!isset ($monthSelect))
{
   $monthSelect=$c->getCurrentMonth();
}
if (! isset($yearSelect))
{
    $yearSelect=$c->getCurrentYear();
}
$c->show_colour_codes();
$c->drawSelectionBox($yearSelect,$monthSelect);
$c->month_events($yearSelect, $monthSelect);

?>
  </p>
  <p>&nbsp;</p></div>
<p>&nbsp;</p><p>&nbsp;</p></body>
</html>

feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

What does getEntryArray() give you? It looks like you've got the functionality to see what days have events, and therefore you can see what events are on a given day. So, just check what events are on a given day (that day being the current day).
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
carnuke
Forum Newbie
Posts: 4
Joined: Tue Sep 27, 2005 12:03 pm

Post by carnuke »

Thanks pickle, but could you show me the code I need to change for doing this? :)
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

Write something similar to month_events(), but do an additional check for the day of the month? That's how I'd do it I think.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply