Floating problems with perfect months

Found a bug?
Let me know so I can sort it out

Floating problems with perfect months

Postby fairchic » Mon Feb 13, 2012 8:49 am

Hi all, don't know if it's a bug or just my misunderstanding:
I've embedded and customised a calendar on my web page on the test server.
I choose "Next 6 Months" until I get to 2013.
April doesn't span the necessary 6 rows, like the other months do, as the 1st falls on a Monday and subsequently May appears directly beneath it, I'm guessing because of a "float: left" somewhere which is slotting it into the free space available.
Can anyone tell me if there's a way of forcing the month to take six rows or have I done something wrong?
Thanks
Example attached
Attachments
floatgonemad.png
Screenshot
floatgonemad.png (45.12 KiB) Viewed 4124 times
fairchic
 
Posts: 2
Joined: Mon Feb 13, 2012 8:43 am

Re: Floating problems with perfect months

Postby chris » Mon Feb 13, 2012 10:59 am

Hi, There is a slight problem with the PHP code that for some reason is not adding the extra row to this month.
However in "normal" conditions this isn't noticeable as all the month blocks should be the same height.
However you have modified the CSS extensively so now the dates are "too" high (and your half-date states are not showing correctly) and therefore forcing the months to be too high too. The simple solution would be to adjust the CSS. Alternatively you will need to modify the PHP code in an attempt to add the extra row.

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

Re: Floating problems with perfect months

Postby chris » Mon Feb 13, 2012 11:12 am

Now for a more complete answer...

Open ac-includes/functions.inc.php file

Find and replace the complete draw_cal() function with this revised function:

Code: Select all
function draw_cal($id_item,$month,$year,$manage_type="avail"){
   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);
   
   //   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 = mb_substr($lang["day_".$k.""],0,1,'UTF-8');
         $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
   
   
   $row_counter=0;
   
   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;
         
         if($day_counter_tot % 7==1) ++$row_counter;
      }
   }
   $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.'" data-date="'.$date_format.'">'.$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;
      if($day_counter_tot % 7==1) ++$row_counter;
   }
   //   add empty days till end of row
   $next_month_day=1;

   while($row_counter<6){
      //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
         
      if($day_counter_tot % 7==1) ++$row_counter;
      }
      $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;
}


Let me know if that resolves the issue.
I am going to try to push out a revised version of the code with this modification and a couple of other minor fixes.

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

Re: Floating problems with perfect months

Postby fairchic » Mon Feb 13, 2012 3:10 pm

Thanks Chris - that's fixed it. :D
fairchic
 
Posts: 2
Joined: Mon Feb 13, 2012 8:43 am

Re: Floating problems with perfect months

Postby chris » Mon Feb 13, 2012 3:16 pm

OK, good news :)
I'm trying to put together a new version with that fix and a couple of other minor bugs. Hopefully it will be ready today or tomorrow. You won't need to upgrade though as the other changes really are minor.

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


Return to Bugs

Who is online

Users browsing this forum: No registered users and 1 guest

cron