Fatal error after installation of Availability Calendar

Help with installation and general calendar setttings

Fatal error after installation of Availability Calendar

Postby kirstyjay » Tue Mar 16, 2010 10:32 pm

I have just installed the availability calendar for a friend on his site, as he wants to start renting out his apartment, however when I view the calendar I get the following error where the months should be :

Fatal error: Call to undefined function cal_days_in_month() in [path]/calendar/ac-includes/functions.inc.php on line 22


When I open the include functions.inc.php there is the following on line 22 :

Code: Select all
$days_in_this_month = cal_days_in_month(CAL_GREGORIAN,$month,$year);   #   define number of days in week


I cannot for the life of me see what is wrong, so would appreciate any help you can give me. You can see the calendar HERE.

By the way... fantastic script! I shall definitely be giving you kudos on hotscripts for it. :)
kirstyjay
 
Posts: 8
Joined: Tue Mar 16, 2010 10:21 pm
Location: Tenerife, Spain

Re: Fatal error after installation of Availability Calendar

Postby chris » Wed Mar 17, 2010 3:08 pm

Hi, yes, it seems that some servers have a problem with the php function cal_days_in_month() Apparantly the php needs to be complied with --enable-calendar .

I posted this link on the Google Group just yesterday (too many forums to keep track of at the moment)
http://www.php.net/manual/en/calendar.installation.php

Can you check if you have this enabled? ( adding echo phpinfo() in
your file should give you the info as to how your php is configured)

If you find that it isn't enabled, take a look at this url:
http://www.webmasterworld.com/forum88/10544.htm

That link gives 2 alternative functions:

Code: Select all
function days_in_month($month, $year) {
if(checkdate($month, 31, $year)) return 31;
if(checkdate($month, 30, $year)) return 30;
if(checkdate($month, 29, $year)) return 29;
if(checkdate($month, 28, $year)) return 28;
return 0; // error
}

and
Code: Select all
function days_in_month($month, $year) {
 return date('t', mktime(0, 0, 0, $month+1, 0, $year));
}


I haven't had a chance to test either of those alternative functions but both look like they should work.

Thanks for the comments by the way :)

Chris
User avatar
chris
Site Admin
 
Posts: 1088
Joined: Mon Dec 17, 2007 7:42 pm
Location: Málaga, Spain

Re: Fatal error after installation of Availability Calendar

Postby kirstyjay » Wed Mar 17, 2010 3:48 pm

Thnaks, I have replied in the Google group with a link to the phpinfo file so you can have a look, but I don't think it is enabled and the host says it will not change configuration, as it is a shared server. Is there any other type of workaround?

PS: I see you are in Malaga. I have friends I work with there and some of us will be coming over for the Tenerife v Malaga game in a few weeks :D
kirstyjay
 
Posts: 8
Joined: Tue Mar 16, 2010 10:21 pm
Location: Tenerife, Spain

Re: Fatal error after installation of Availability Calendar

Postby chris » Wed Mar 17, 2010 4:07 pm

Ah, I didn't spot that you where the same Kisrty ;)

Have you tried either of the functions that I posted earlier from that url?
I have just tested this one:
Code: Select all
function days_in_month($month, $year) {
return date('t', mktime(0, 0, 0, $month+1, 0, $year));
}

and it seems to work correctly.

Seeing as this appears to be a common problem, I will probably add something like this to the next version:

Code: Select all
if(!function_exists('cal_days_in_month')){
    function cal_days_in_month($cal_type="",$month, $year) {
       return date('t', mktime(0, 0, 0, $month+1, 0, $year));
    }
}

This creates the function, only if the function doesn't already exist on the server. Feel free to add those lines to the "ac-includes" > "functions.inc.php" file :)

PS: I see you are in Malaga. I have friends I work with there and some of us will be coming over for the Tenerife v Malaga game in a few weeks :D

Yes, I am in Malaga (though from the UK) - judging by the way Malaga has been playing recently Tenerife will probably win :(

Chris
User avatar
chris
Site Admin
 
Posts: 1088
Joined: Mon Dec 17, 2007 7:42 pm
Location: Málaga, Spain

Re: Fatal error after installation of Availability Calendar

Postby jmmunoz » Wed Mar 17, 2010 4:29 pm

chris wrote:Yes, I am in Malaga (though from the UK) - judging by the way Malaga has been playing recently Tenerife will probably win :(

OFF-TOPIC: I hope you're wrong!! :D
jmmunoz
 
Posts: 13
Joined: Sat Mar 06, 2010 2:27 am
Location: Málaga, Spain

Re: Fatal error after installation of Availability Calendar

Postby kirstyjay » Wed Mar 17, 2010 11:27 pm

chris wrote:Ah, I didn't spot that you where the same Kirsty ;)

Have you tried either of the functions that I posted earlier from that url?


I hadn't, but I just have and it's working fine now :)

You truly are a special individual :D

jmmunoz wrote:OFF-TOPIC: I hope you're wrong!! :D
'Scuse my French, but Bollocks! Tenerife have had enough bad luck recently... we need the points too! :( Hopefully we will get 3 next week (a 6 pointer in reality) against Xerez and then another 3 at home against Villareal and then we will once again be in fighting position.

I am travelling to the Ath. Madrid v CDT match and I was in Getafe for the away game earlier this season, but I cannot afford to go to Malaga too, but many of my mates are.

To be honest, I would love both our teams to stay up, as our fanclub, Peña Armada Sur, have close connections with the Peña Internationale Malagüistas, who have come over and drank copious amounts of alcol with us in our local bar :D. One of the websites I do is http://www.armadasur.com. ;)

Me gusta tus deseños, Chris. Estoy una artista. Hecho Bellas Artes en Universidad... Pero tenemos muchos deseñador@s malos en Tenerife y España en el internet....¿Verdad?

¡Vamos Tenerife! :D

PS: I know my Spanish is Shit ;)
kirstyjay
 
Posts: 8
Joined: Tue Mar 16, 2010 10:21 pm
Location: Tenerife, Spain

Re: Fatal error after installation of Availability Calendar

Postby kirstyjay » Thu Mar 18, 2010 12:29 am

Just to help anyone else that is having the same problems, here is the contents of the functions.inc.php. Just copy and past into your own. :)

Code: Select all
<?php
/*
script:   Ajax availability calendar
author: Chris Bolson

file:    functions.inc.php
use:    common functions for all pages
inst:   
*/


//    create calendar for given month

if(!function_exists('cal_days_in_month')){
   function cal_days_in_month($cal_type="",$month, $year) {
       return date('t', mktime(0, 0, 0, $month+1, 0, $year));
    }
}
function draw_cal($id_item,$month,$year){
   global $lang;
   
   
   $month=sprintf("%02s",$month);
   //   define vars
   $today_timestamp   =   mktime(0,0,0,date('m'),date('d'),date('Y'));   #    current timestamp - used to check if date is in past
   $this_month       =    getDate(mktime(0, 0, 0, $month, 1, $year));      #    convert month to timestamp
   $first_week_day    = $this_month["wday"];                        #    define first weekday (0-6) 
    $days_in_this_month = cal_days_in_month(CAL_GREGORIAN,$month,$year);   #   define number of days in week

   $day_counter_tot   =   0; #   count total number of days showin INCLUDING previous and next months - use to get 6th row of dates
   
   //   get num days in previous month - used to add dates to "empty" cells
   $month_last   = $month-1;
   $year_last   = $year;
   if($month_last<1){
      $month_last=12;
      $year_last=$year-1;   
   }
   $days_in_last_month = cal_days_in_month(CAL_GREGORIAN,$month_last,$year_last);
   
   //   CREATE THE CALENDAR
   
   //   day column titles - using first letter of each day
   if($show_week_num)   $list_day_titles='<li class="weeknum_spacer"></li>';
   
   if(AC_START_DAY=="sun"){
      //$cal_row_counter=0;
      
      for($k=0; $k<7; $k++){
         $weekday = substr($lang["day_".$k.""],0,1);
         $list_day_titles.='<li class="cal_weekday"> '.$weekday.'</li>';
      }
   }else{
      //$cal_row_counter=1;
      if ($first_week_day == 0)   $first_week_day =7;
      for($k=1; $k<=7; $k++){
         //echo "<br>".$k;
         if($k==7)    $weekday = substr($lang["day_0"][0],0,1);
         else      $weekday = substr($lang["day_".$k.""],0,1);
         $list_day_titles.='<li title="'.$lang["day_".$k.""].'"> '.$weekday.'</li>';
      }
   }
   
   
   //   Fill the first week of the month with the appropriate number of blanks.       
   $j=1;
   if(AC_START_DAY=="sun")   $first_week_day_start   =   $first_week_day;   # start sunday
   else                  $first_week_day         =   $first_week_day-1;   # start monday
   
   if($first_week_day!=7){
      if($show_week_num)   $list_days.='<li class="weeknum">-</li>';
      $last_month_start_num=$days_in_last_month-$first_week_day+1;
      for($week_day = 0; $week_day < $first_week_day; $week_day++){
         $list_days.='<li class="cal_empty">'.$last_month_start_num.'</li>';   
         ++$last_month_start_num;
         ++$j;
         ++$day_counter_tot;
      }
   }
   $week_day=$j;
   
   
   
   //   get bookings for this month and item from database
   $booked_days=array();
   $sql = "
   SELECT
      t1.the_date,
      t2.class,
      t2.desc_".LANG." AS the_state
   FROM
      ".T_BOOKINGS." AS t1
      LEFT JOIN ".T_BOOKING_STATES." AS t2 ON t2.id=t1.id_state
   WHERE
      t1.id_item=".$id_item."
      AND MONTH(t1.the_date)=".$month."
      AND YEAR(t1.the_date)=".$year."
   ";
   if(!$res=mysql_query($sql))   die("ERROR checking id item availability dates<br>".mysql_error());
   while($row=mysql_fetch_assoc($res)){
      $booked_days[$row["the_date"]]=array("class"=>$row["class"],"state"=>$row["the_state"]);
   }
   
   
   
   //   loop thorugh days (til max in month) to draw calendar
   for($day_counter = 1; $day_counter <= $days_in_this_month; $day_counter++){
      
      
      
      
      //   reset xtra classes for each day
      //   note - these classes acumulate for each day according to state, current and clickable
      $day_classes    =   "";
      $day_title_state=   " - ".$lang["available"];
      
      //   set all dates to clickable for now.... need to control this for admin OR for user side booking      
      $day_classes.=' clickable';
      
      
      //   turn date into timestamp for comparison with current timestamp (defined above)
      $date_timestamp =   mktime(0,0,0, $month,($day_counter),$year);
      
      //   get week number
      $week_num=date("W",$date_timestamp);
      if($week_num!=$last_week_num){
         //   new week
         //$list_days .= '<li>-</li>';
      }
      //   highlight current day
      if($date_timestamp==$today_timestamp)   $day_classes.=' today';
      
      //   format date for db modifying - the date is passed via ajax
      $date_db      =   $year."-".sprintf("%02s",$month)."-".sprintf("%02s",$day_counter);
       
        //   format date for display only
        if(AC_DATE_DISPLAY_FORMAT=="us")   $date_format   =   $month."/".$day_counter."/".$year;
        else                           $date_format   =   $day_counter."/".$month."/".$year;
       
      //   check if day is available
      if(array_key_exists($date_db,$booked_days)){
         $day_classes.=" ".$booked_days[$date_db]["class"];
         $day_title_state=" - ".$booked_days[$date_db]["state"];
      }
               
      
      //   check if date is past         
      if( $date_timestamp<$today_timestamp){
         $day_classes.=" past";   #add "past" class to be modified via mootools if required
         //   overwrite clickable state if CLICKABLE_PAST is off
         if(AC_ACTIVE_PAST_DATES=="off"){
            //   date is previous - strip out "clickable" from classes
            $day_classes=str_replace(' clickable','',$day_classes);
         }
      }
      
      //   add weekend class - used in javascript to alter class or set opacity
      $getdate=getdate($date_timestamp);
      $day_num=$getdate["wday"]+1;
      if ($day_num % 7 == 1)      $day_classes.=' weekend';
      elseif ($day_num % 6 == 1)   $day_classes.=' weekend';
      
      //'.$lang["day_".$getdate["wday"].""].'
      $list_days .= '
      <li class="'.$day_classes.' "  id="'.$date_db.'" title="'.$date_format.$day_title_state.'">'.$day_counter.'</li>';
      
      //   reset weekday counter if 7 (6)
      $week_day %= 7;         #   reset weekday to 0
      ++$week_day;         #   increase weekday counter
      ++$day_counter_tot;      #   add 1 to total days shown
      //echo "<br>".$week_day;
      if($show_week_num){
         if ($week_day==1) $list_days .= '<li class="weeknum">'.$week_num.'</li>';
      }
      $last_week_num=$week_num;
   }
   //   add empty days till end of row
   $next_month_day=1;
   /*
   if($week_day > 1){
      for($till_day = $week_day; $till_day <=7; $till_day++){
         $list_days .= '<li class="cal_empty">'.$next_month_day.'</li>';
         ++$next_month_day; 
         ++$day_counter_tot;      #   add 1 to total days shown
      }
   }
   */
   /*
   echo $day_counter_tot % 6;
   //   now check that we have the full six rows...
   if ($day_counter_tot % 6 !=0){
      //   add empty row
      for($till_day = 1; $till_day <=7; $till_day++){
         $list_days .= '<li class="cal_empty">'.$next_month_day.'</li>';
         ++$next_month_day;
         ++$day_counter_tot;      #   add 1 to total days shown
      }
   }
   */
   //   add more rows untill we get to 6
   while($day_counter_tot % 6 !=0){
      //add days until it does :)
      for($till_day = $week_day; $till_day <=7; $till_day++){
         $list_days .= '<li class="cal_empty">'.$next_month_day.'</li>';
         ++$next_month_day; 
         ++$day_counter_tot;      #   add 1 to total days shown
      }
      $week_day=1;

   }
   //   add empty dates (with next month numbers) until we get to 7
   if($week_day > 1){
      for($till_day = $week_day; $till_day <=7; $till_day++){
         $list_days .= '<li class="cal_empty">'.$next_month_day.'</li>';
         ++$next_month_day; 
         ++$day_counter_tot;      #   add 1 to total days shown
      }
   }
   
   
   //   put it all together (parent div defined in parent file)
   $the_cal='
   <div id="'.$month.'_'.$year.'" class="cal_title">'.$lang["month_".$month.""].' '.$year.'</div>
   <ul class="cal_weekday">
      '.$list_day_titles.'
   </ul>
   <ul>
      '.$list_days.'
   </ul>
   <div class="clear"></div>
   ';
   return $the_cal;
}


function get_cal_update_date($id_item){
   if(AC_DATE_DISPLAY_FORMAT=="us")   $date_format   = "%m-%d-%Y";
   else                         $date_format   = "%d-%m-%Y";
   
   $sql="SELECT DATE_FORMAT(date_mod, '".$date_format."') as date_mod FROM `".T_BOOKING_UPDATE."` WHERE id=".$id_item."";
   $res=mysql_query($sql) or die("error getting last calendar update date");
   $row=mysql_fetch_assoc($res);
   return $row["date_mod"];
}
//   get calendar items for select list
function sel_list_items($id_item_current){
   $list_items="";
   $sql="SELECT id, desc_".LANG." as the_item FROM ".T_BOOKINGS_ITEMS." WHERE state=1 ORDER BY list_order";
   $res=mysql_query($sql) or die("Error checking items");
   while($row=mysql_fetch_assoc($res)){
      $list_items.='<option value="'.$row["id"].'"';
      if($row["id"]==$id_item_current) $list_items.=' selected="selected"';
      $list_items.='>'.$row["the_item"].'</option>';
   }
   return $list_items;
}

function list_numbers($start,$end,$num){
   $list_numbers='';
   for($k=$start;$k<=$end;$k++){
      $list_numbers.='<option value="'.$k.'"';
      if($k==$num) $list_numbers.=' selected="selected"';
      $list_numbers.='>'.$k.'</option>';
   }
   return $list_numbers;
}
//   get item title
function itemTitle($id){
   $sql="SELECT desc_".LANG." as item_title FROM ".T_BOOKINGS_ITEMS." WHERE id=".$id."";
   $res=mysql_query($sql) or die("Error getting item name");
   $row=mysql_fetch_assoc($res);
   return $row["item_title"];
}
?>
kirstyjay
 
Posts: 8
Joined: Tue Mar 16, 2010 10:21 pm
Location: Tenerife, Spain


Return to Support

Who is online

Users browsing this forum: Bing [Bot] and 1 guest

cron