Php Script for Calendar

This calendar script automates the task of displaying scheduled events on a web site. It adds a calendar icon next to each date in a given month and provides links on mouse-over that display all events for the given day. The script includes an override to disable this functionality and uses PEAR Date package.

We’re proud to announce this brand new website. Beside beautiful design and top modern technologies like PHP 7.1, CodeIgniter 3 and others, our main goal is to share the knowledge and experience with the open source community. Please visit Github repo for newest updates and great features.

Bestselling: BookingWizz—Booking System

BookingWizz - Booking System

BookingWizz is an easy-to-use, easy-to-set-up booking script that will help you set up a reservation system in minutes. This fully responsive PHP calendar reservation system works with any device or screen. 

Standout features include: 

  • SMS reminders
  • PDF schedules 
  • easy integration with PayPal, Stripe, and multiple payment gateways
  • easy integration with WordPress websites
  • various display settings, including time zone support 
  • and more 

How the PHP Calendar script works?

This Script will use php built in functions. This calendar opens in a small window with dropdown listbox to select month and year. We will set the variables to select range of years to appear as option in dropdown listbox. Here they are

$start_year=2000; // Starting year for dropdown list box
$end_year=2020; // Ending year for dropdown list box

We have two JavaScript functions inside our script. One is used to pass the selected date value from calendar window to main calling page. Other one is used to reload the page by taking selected value from month and year dropdown list box. Function post_value() receives three parameters , month ,date and year from the calendar cell and posted the same value to parent window. You can read more on passing value to parent window here.

function post_value(mm,dt,yy){
opener.document.f1.p_name.value = mm + "/" + dt + "/" + yy;
/// cheange the above line for different date format
self.close(); }

Function reload(form) collects month and year value from the dropdown list box and using that it prepare the query string. With the query string the page is reloaded.

function reload(form){
var month_val=document.getElementById('month').value; // collect month value
var year_val=document.getElementById('year').value; // collect year value
self.location='cal2.php?month=' + month_val + '&year=' + year_val ; // reload the page
}

There is a style associated with the page, you can change the style to change the display style of calendar.

We will collect month and year from query string and pass the value to script.

@$month=$_GET['month'];
@$year=$_GET['year'];

Calendar script always requires two variables, one is month and other one is year. If these values are not available (from query string as selected by users) then we will use present month and year as default value.

if(!($month <13 and $month >0)){
$month =date("m");  // Current month as default month
}

if(!($year <=$end_year and $year >=$start_year)){
$year =date("Y");  // Set current year as default year 
}

After getting date about year and month we have to find out the number of days present in the month. There is a built in function cal_days_in_month available to get this.

$no_of_days = cal_days_in_month(CAL_GREGORIAN, $month, $year);//calculate number of days in a month

Booking Core: Ultimate Booking System

Booking Core - Ultimate Booking System

Booking Core is a responsive and SEO-friendly booking system based on Laravel. It’s designed for travel websites and marketplaces, travel agencies, tour operators, bed and breakfasts, villa rental, resort rental, and more. 

Some features of this PHP booking system include:

  • auto-optimized images
  • powerful booking engine
  • template and menu builder
  • payment gateways like PayPal, Stripe, and more

Week day of first day of the month.

Calendar with blank cells

We are displaying calendar as a matrix with multiple rows starting from Sunday at left side first column. If our first day of the month starts from Friday then we have to start adding day numbers from 6th cell by leaving blank the first five cells.

$j= date('w',mktime(0,0,0,$month,1,$year)); // This will calculate the week day of the first day of the month

Monday as starting day of the week

This calendar script is developed with starting day of the week as Sunday. To change this to Monday we have to adjust the $j value which holds the weekday value of the first day of the month. The value changes from 0 for Sunday and to 6 for Saturday. We have to add these two lines to make the week began from Monday

$j= date('w',mktime(0,0,0,$month,1,$year)); // This will calculate the week day of the first day of the month
//echo $j;// Sunday=0 , Saturday =6
//// if starting day of the week is Monday then add following two lines ///
$j=$j-1;  
if($j<0){$j=6;}  // if it is Sunday //
//// end of if starting day of the week is Monday ////

In addition to this Top row of the table to be changed to display week day name starting from Monday and ending on Sunday.

//echo "<tr><th>Sun</th><th>Mon</th><th>Tue</th><th>Wed</th><th>Thu</th><th>Fri</th><th>Sat</th></tr><tr>";
echo "<tr><th>Mon</th><th>Tue</th><th>Wed</th><th>Thu</th><th>Fri</th><th>Sat</th><th>Sun</th></tr><tr>";

Inside your zip file ( download at the end of this page ) cal3.php file is included which shows calendar where week starts from Monday

Similarly after last date of the month we have to blank the days left in the calendar matrix. For this we will use php string function str_repeat to multiply the blank cells number of times decided by starting day of the month and ending date of the month.

$adj=str_repeat("<td bgcolor='#ffff00'>*&nbsp;</td>",$j);  // Blank starting cells of the calendar 
$blank_at_end=42-$j-$no_of_days; // Days left after the last day of the month
if($blank_at_end >= 7){$blank_at_end = $blank_at_end - 7 ;} 
$adj2=str_repeat("<td bgcolor='#ffff00'>*&nbsp;</td>",$blank_at_end); // Blank ending cells of the calendar

Here the number 42 ( 7 x 6 ) is the maximum number of cells of the calendar full filling any year – months requirement.

Cleanto

Cleanto Online bookings management system for maid services and cleaning companies

Cleanto is ideal for many different types of service companies looking for a reliable way to provide clients with full-featured online booking.

Standout features of this PHP calendar script download include:

  • PayPal, Authorize.net, and Stripe payment methods
  • email reminders
  • auto-confirm bookings
  • ability to add breaks in the schedule
  • and more

Displaying Month and Year Dropdown list

We will display month selection dropdown list with month name as Text and month number as option. So we will use for loop to display numbers staring from 1 to 12 ( total 12 months ). By using incremental value of variable inside for loop we will display Month name and month number.

<select name=month value='' onchange="reload(this.form)" id="month">
<option value=''>Select Month</option>";
for($p=1;$p<=12;$p++){

$dateObject   = DateTime::createFromFormat('!m', $p);
$monthName = $dateObject->format('F');
if($month==$p){
echo "<option value=$p selected>$monthName</option>";
}else{
echo "<option value=$p>$monthName</option>";
}
}
echo "</select>

In the above code we used createFromFormat function to create date object.
Similarly to display year list we will use for loop. At the staring of the script we asked for two variables to set. Based on these variables $start_year and $end_year we will use for loop to display the year dropdown list.

<select name=year value='' onchange="reload(this.form)" id="year">Select Year</option>
";
for($i=$start_year;$i<=$end_year;$i++){
if($year==$i){
echo "<option value='$i' selected>$i</option>";
}else{
echo "<option value='$i'>$i</option>";
}
}
echo "</select>

Both our dropdown lists will use onChange event handler to trigger JavaScript function reload() to refresh the page when ever user changes its selection of month or year.

Conclusion

Designing the calendar will become easy. The calendar can be viewed in the browser and on your Iphone, Android phones and all mobile phones using any browser. We offer customization(extra cost) for each month of the year. It is also possible to view this calendar in different languages! For example, you can view the calendar in Dutch, Polish, German and many more! It is also possible to add or remove holidays/vacation days. If you like our product, please rate us on google play store.

0 Comments

No Comment.