Free Form Calendar Application

By the looks of your directory setup it seems the html page is what runs and then you try to include the php file which won’t work.

Your html file actually needs to have the extension php in order to work the php code. PHP files can have html in them so don’t worry about that issue. But HTML files will not read PHP code properly so you can’t go both ways.

If you still have issues, post the the code to the page that displays the calendar.

Thank you for your quick reply.

I’m afraid I seem to be creating more problems for myself. Below is the code for my PHP file. I can’t get the Next and Previous months links to show, the Options don’t function and September 1st is showing on Monday instead of Tuesday.

Any ideas where I went wrong? http://www.caddee.com/calendar/test.php

Thank you again for your help.

Jim

<?php

include(&quot;calendar.php&quot;);


&#036;month = (isset(&#036;_POST['month'])) ? &#036;_POST['month'] : &#036;_GET['month'];


&#036;year = (isset(&#036;_POST['year'])) ? &#036;_POST['year'] : &#036;_GET['year']

?>

<?php $calendar = new Calendar(); ?>

<!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>

&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot; /&gt;


&lt;title&gt;Sample Calendar Application - Designed as an OOP Class&lt;/title&gt;


&lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;calendar.css&quot;&gt;

</head>

<body>

&lt;center&gt;


	&lt;h2 align=&quot;center&quot;&gt;&lt;?php echo &#036;calendar-&gt;title; ?&gt;&lt;/h2&gt;


	&lt;?php echo &#036;calendar-&gt;printStartForm(); ?&gt;


	&lt;?php echo &#036;calendar-&gt;storePreviousLink; ?&gt;


	.::


	&lt;?php echo &#036;calendar-&gt;printControlMenu();?&gt;


	::.


	&lt;?php echo &#036;calendar-&gt;storeNextLink; ?&gt;


	&lt;?php echo &#036;calendar-&gt;printCloseForm(); ?&gt;


	&lt;?php echo &#036;calendar-&gt;printCalendar(); ?&gt;


&lt;/center&gt;

</body>

</html>

Ok so that explains it ;) you’re using (which makes sense because you’re on this forum haha) the Yii framework version of the application. I designed the calendar with muli-functionality.

If you haven’t already I would highly suggest you take a look at the calendar.php file with the calendar class in it so you can see how you can customize the calendar for yourself.

But on a simplicity level, here’s what my code is for just free form php (not for the framework).




<?php 


include("calendar.php");


/*

 * If the user selected the month and year via drop down then it's set

 * via post - otherwise they clicked a link, which means it's set by get.

 * If the next / previous month links were clicked the get value will be filled

 * otherwise it will be NULL (like clicking the calendar link in main menu) and the

 * class will account for this and set the default current month and year.

 */

$month = (isset($_POST['month'])) ? $_POST['month'] : $_GET['month'];

$year = (isset($_POST['year'])) ? $_POST['year'] : $_GET['year'];




// If the get requests don't have anything, NULL values will be assigned

$calendar=new Calendar($month,$year);


?>


<!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>Sample Calendar Application - Designed as an OOP Class</title>

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

</head>

<body>


<h2 align="center"><?php echo $calendar->title; ?></h2>

<?php echo $calendar->printStartForm(); ?>

<?php echo $calendar->printControlMenu();?>

<?php echo $calendar->printCloseForm(); ?>

<?php echo $calendar->printCalendar(); ?>

</body>

</html>



That’s it, now I also swapped inside the calendar.php file the calendar class information for the control menu. If you open up the calendar.php file and go to line: 212 you should see some documentation that looks like this:




/* "next month" control and "previous month" control */

        // For plain old PHP

        $this->nextMonth = '<a href="?month='.($this->month != 12 ? $this->month + 1 : 1).

        '&year='.($this->month != 12 ? $this->year : $this->year + 1).'" class="control">Next Month >></a>';

        $this->previousMonth = '<a href="?month='.($this->month != 1 ? $this->month - 1 : 12).

        '&year='.($this->month != 1 ? $this->year : $this->year - 1).'" class="control"><<     Previous Month</a>'; 

        

        /* For Yii Framework

        $this->nextMonth = ($this->month != 12 ? $this->month + 1 : 1);

        $this->yearNextMonth = ($this->month != 12 ? $this->year : $this->year + 1);

        $this->previousMonth = ($this->month != 1 ? $this->month - 1 : 12);

        $this->yearPreviousMonth = ($this->month != 1 ? $this->year : $this->year - 1);    */



Because this was placed on the Yii framework forum, that was the first choice, so in your calendar.php file it’s probably set to use the Yii framework setup for the control menu. All you do is comment that out and uncomment the one for the plain php and it should work :).

Sweet! It’s working now.

There are a couple of things that happened that I didn’t expect and I was wondering if you are experiencing the same.

When I first go to my test calendar, September is the current month but the first day of the month is on Monday instead of Tuesday and if I go to the next month and then back it’s correct. I get the same result on your demo page http://www.sterlingsavvy.com/tutorials/calendar/.

The other thing I did not expect, is when switching to the next or previous month, the current-day number is highlighted for that month too. I personally would prefer to have only the current day for the current month highlighted and I think it would go something like this (?)…

     /* keep going with days.... */


     for(&#036;list_day = 1; &#036;list_day &lt;= &#036;days_in_month; &#036;list_day++):


         if((&#036;list_day == date(&quot;j&quot;,mktime(0,0,0,&#036;this-&gt;month))) &amp;&amp; (date(&quot;F&quot;) == date(&quot;F&quot;,mktime(0,0,0,&#036;this-&gt;month)))) [b]&lt;&lt;&lt;&lt;&lt; - I added another condition to compare the current month with this-&gt;month.[/b]


         {    


             &#036;this-&gt;calendar.= '&lt;td class=&quot;'. &#036;this-&gt;style .'-current-day&quot;&gt;';


         }


         else            


         {…

This seems to work but I’m not really sure if I accomplished my goal in the best way.

Thanks again for all your help.

Jim

PS. I Just realized I should test for the year too. So I changed the conditional test to…

if(($list_day == date("j",mktime(0,0,0,$this->month))) &&

(date("F") == date("F",mktime(0,0,0,$this->month))) &&

(date("Y") == date("Y",mktime(0,0,0,$this->month,$list_day,$this->year))))

{

Well of course feel free to modify and manipulate it - that’s the purpose of making it a class so it can be reused and modified effectively without destroying all the other code in your site.

As for the day of the month issue, could just be a bug with September. It wasn’t doing that sort of nonsense in August but I haven’t touched it much since I made it so it’s quite possible there’s a serious bug that needs to be fixed. In which case I’ll check next month and if it does the same thing then I’ll look into it.

But no please feel free to modify or make any additions and even share them here on the forum as it only adds to the community in what people can do and have ready to go for them to manipulate. I just turned a simple calendar with some average features into a class setup to be reused, by all means is it not perfect and of course can be improved or customized for each individual purpose :)

Hope it serves you well however. Give it another week and then I’ll get back here if the month issue occurs with October. Thanks for the notice of the issue however. It was something I noticed on rare occasions but only for September (when I was switching from August to September) and could not always replicate it so never figured it an issue with the code but it’s quite possible.

First time I’ve tried posting so hope it works. I think the day of the month issue is caused by this code.


 

/* We need to take the month value and turn it into one without a leading 0 */

         if((substr($this->month, 0, 1)) == 0)

         {

             // if value is between 01 - 09, drop the 0

             $tempMonth = substr($this->month, 2); //The 2 should be 1 if you want the second character.

             $this->month = $tempMonth;

         }



I didn’t try it so its not tested.

That was it. Thank you!

Jim

Just out of curiosity, what did you changed. I’ll investigate and update all the posts and applications for it :)

Thanks for the debugging guys ;)

Change

$tempMonth = substr($this->month, 2);

To

$tempMonth = substr($this->month, 1);

[size="7"]OK EVERYONE!![/size]

i am making this calendar for just plain php, and i noticed some of you are good with colors and styling!

i have the calendar working and stuff… hopefully.

i just need 2 color schemes, and wanted to know if someone could make them for me…

ok so i need a blueish color scheme(its going on a site that uses blues), and a pastel color scheme(my boss/webmaster said pastels go well with the scheme for the site, im just a worker). it would be great if someone could make one or both.

[size="7"]THANK YOU ALL!!![/size][size="5"]… in advance[/size]

and just some colors that are used on the site:

#97c4e3

#00ffff

#33ffcc

i can get more, but thats just a few.

Thanks for posting this class. It has been a real time saver for a project I’m working on. I’ll preface my question by letting you know that I’m very much a novice at this, but if anyone can help with the bug(?) I’m seeing, I’d greatly appreciate it.

I noticed when using this class on my own site, that if you display a month (such at July 2010) that has the last day of the month on a Saturday, that there is an extra (blank) row added to the table. I tried it at the demo site listed above and witnessed the same behavior. I’ve looked at the logic that is drawing the table and can’t figure out what is causing the problem. Anyone have any ideas?

Thanks again.

Works sweet! Thanks for this!

Just added some modifications and it fits my needs…

One thing filling the empty days in the last row:


         

         /* finish the rest of the days in the week */

         if($days_in_this_week < <img src='http://www.yiiframework.com/forum/public/style_emoticons/default/cool.gif' class='bbc_emoticon' alt='8)' /> :

             for($x = 1; $x <= (8 - $days_in_this_week); $x++):

                 $this->calendar.= '<td class="'. $this->style .'-day-np">&nbsp;</td>';

             endfor;

         endif;



if $days_in_this_week equals 1 (i.e. 2010 July) you get a complete empty last row, maybe it’s not what you really want, so change to this and voila:




         /* finish the rest of the days in the week */

         if($days_in_this_week < 8 && $days_in_this_week > 1) : // <--- here

             for($x = 1; $x <= (8 - $days_in_this_week); $x++):

                 $this->calendar.= '<td class="'. $this->style .'-day-np">&nbsp;</td>';

             endfor;

         endif;



And it would be nice if I could start the week on monday. I suck in PHP dates, so if anyone have a clue it would be great.

Thanks again!

this code is great but can someone please make include the getting of events in the database like on david walsh calendar tut… i tried but i failed dunno what to do… thanks in advance…

btw i use mysql and php…thanks

hi all! I’m a new using yii framework. I don’t know how to use jquery with yii framework like calendar and popup box. hope all of you will help me… :)

Is there a easy way in the script to translate the name of the months to other languages as there was for the week days ?

I know this whole post is kind of old, but my small contribution to this would be this:

Wouldn’t changing these two lines of code to use $_REQUEST be much shorter?

$month = (isset($_POST[‘month’])) ? $_POST[‘month’] : $_GET[‘month’];

$year = (isset($_POST[‘year’])) ? $_POST[‘year’] : $_GET[‘year’];

The result would be this…

$month = $_REQUEST[‘month’];

$year = $_REQUEST[‘year’];

One more thing to comment on is this piece of code:

/* We need to take the month value and turn it into one without a leading 0 */

if((substr($this->month, 0, 1)) == 0)

{

// if value is between 01 - 09, drop the 0


&#036;tempMonth = substr(&#036;this-&gt;month, 1);                                                                                              


&#036;this-&gt;month = &#036;tempMonth;

}

Why would you not just change how you define $this->month earlier in the code?

You have:

$this->month = date("m");

Why not use:

$this->month = date("n");

"m" is the numeric representation of the month with the leading zero. "n" is the numeric representation of the month WITHOUT the leading zero.

Making this change would take out some of the overhead in the code.

Could anyone tell me how to get the date value in the place where we list the events in calender




/** You can query the database for an entry for this day if you like or print out a message on each day.Uncomment these two lines.  **/

                                

$this->calendar.= '<div class="'. $this->style .'-text"><a href="">'.$date.'</a></div><br/><br/>';

$this->calendar.= str_repeat('<p> </p>',2);



I wanna get the date value in this block and by which i have to get the event list from the database.

Hi, i facing trouble to view out the calender,I follow the steps,i place the class on component, i put the controller on the site controller and view file on the site/. But seem outcome is undefined variable:month on which the error from the site controller


$calendar=new Calendar($month,$year,$style);

I hope someone can help out.I worry i miss out any steps.

Hi. I’m new to yii and PHP. I’m trying to use this event calendar in a yii1.1 project.

I added the class as an yii component.

It gives me the following PHP notice.

Undefined variable: style

in the following line:


$this->calendar.= '<tr class="'. $style .'-row">';

If I don’t use &style, it works fine. The calendar is displayed without css styles.

Please help me to identify the problem.

Thank you.